Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: decide the Music Video overlay check's host control before responding (#13055)
[._.]/ Adam Eivyefd62c1d82db
diff --git a/server/routes/hostControlMusicVideoPreGuard.test.js b/server/routes/hostControlMusicVideoPreGuard.test.jsindex f217c869c5..ce2a435e92 100644--- a/server/routes/hostControlMusicVideoPreGuard.test.js+++ b/server/routes/hostControlMusicVideoPreGuard.test.js@@ -251,7 +251,8 @@ describe('Music Video pre-guard operator authority (#13055)', () => {}};await importAs('127.0.0.1');- await vi.waitFor(() => expect(effects.checkOverlayTextInBackground).toHaveBeenCalledTimes(2));+ // The check starts behind two lazy imports, which a cold CI worker loads slowly.+ await vi.waitFor(() => expect(effects.checkOverlayTextInBackground).toHaveBeenCalledTimes(2), { timeout: 10_000 });expect(effects.checkOverlayTextInBackground).toHaveBeenLastCalledWith('example-project');// The check starts behind a dynamic import of a now-cached module, so a@@ -259,7 +260,7 @@ describe('Music Video pre-guard operator authority (#13055)', () => {await importAs('192.0.2.10');for (const [, effect] of imports) expect(effect).toHaveBeenCalledTimes(2);await importAs('127.0.0.1');- await vi.waitFor(() => expect(effects.checkOverlayTextInBackground.mock.calls.length).toBeGreaterThanOrEqual(4));+ await vi.waitFor(() => expect(effects.checkOverlayTextInBackground.mock.calls.length).toBeGreaterThanOrEqual(4), { timeout: 10_000 });expect(effects.checkOverlayTextInBackground).toHaveBeenCalledTimes(4);});diff --git a/server/routes/musicVideo.js b/server/routes/musicVideo.jsindex 0bd1ae3d4b..75f5df48a5 100644--- a/server/routes/musicVideo.js+++ b/server/routes/musicVideo.js@@ -897,12 +897,18 @@ router.post('/:id/code/sections/:sectionId/regenerate', asyncHandler(async (req,// The check renders the document in the headless composition browser, so it// runs only for a caller with host control (#13055); anyone else gets the// import alone, and the gated production-review text check runs it later.-// authGate loads lazily: this router is reached by many suites that mock settings.-const checkOverlayTextAfterImport = (req, projectId) => {- import('../services/authGate.js')- .then(({ requestHasHostControl }) => requestHasHostControl(req)- && import('../services/musicVideo/overlayTextService.js')- .then(({ checkOverlayTextInBackground }) => checkOverlayTextInBackground(projectId)))+// Decide before responding: once the response ends the socket can close and+// lose the address that makes a caller local. authGate loads lazily because+// this router is reached by many suites that mock settings. Both deferred+// imports are memoized: overlapping first loads of one specifier can resolve+// past a test's module mock.+let authGateModule;+let overlayTextModule;+const checkOverlayTextAfterImport = async (req, projectId) => {+ const { requestHasHostControl } = await (authGateModule ??= import('../services/authGate.js'));+ if (!requestHasHostControl(req)) return;+ (overlayTextModule ??= import('../services/musicVideo/overlayTextService.js'))+ .then(({ checkOverlayTextInBackground }) => checkOverlayTextInBackground(projectId)).catch((err) => console.error(`❌ Overlay text check did not start: ${err.message}`));};@@ -921,8 +927,9 @@ router.get('/:id/composition/document', asyncHandler(async (req, res) => {router.post('/:id/composition/document/zip', documentZipUpload, asyncHandler(async (req, res) => {if (!req.file) throw new ServerError('No file uploaded (multipart field "file")', { status: 400, code: 'VALIDATION_ERROR' });try {- res.status(201).json(await importDocumentZip(req.params.id, req.file.path, req.file.originalname));- checkOverlayTextAfterImport(req, req.params.id);+ const imported = await importDocumentZip(req.params.id, req.file.path, req.file.originalname);+ await checkOverlayTextAfterImport(req, req.params.id);+ res.status(201).json(imported);} finally {await unlink(req.file.path).catch(() => {});}@@ -930,8 +937,9 @@ router.post('/:id/composition/document/zip', documentZipUpload, asyncHandler(asyrouter.post('/:id/composition/document/directory', asyncHandler(async (req, res) => {const { directory } = validateRequest(musicVideoDocumentDirectoryImportSchema, req.body || {});- res.status(201).json(await importDocumentDirectory(req.params.id, directory));- checkOverlayTextAfterImport(req, req.params.id);+ const imported = await importDocumentDirectory(req.params.id, directory);+ await checkOverlayTextAfterImport(req, req.params.id);+ res.status(201).json(imported);}));router.post('/:id/composition/document/template', asyncHandler(async (req, res) => {@@ -966,8 +974,9 @@ router.post('/:id/composition/document/sections/:sectionId/regenerate', asyncHanrouter.post('/:id/composition/document/accept', asyncHandler(async (req, res) => {const { directory } = validateRequest(musicVideoDocumentCandidateSchema, req.body || {});- res.json(await acceptMixedMediaDocument(req.params.id, directory));- checkOverlayTextAfterImport(req, req.params.id);+ const accepted = await acceptMixedMediaDocument(req.params.id, directory);+ await checkOverlayTextAfterImport(req, req.params.id);+ res.json(accepted);}));router.delete('/:id/composition/document/candidate', asyncHandler(async (req, res) => {