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
refactor([audit-remaining-getissue-prechecks-in-pipeline-routes]): drop redundant getIssue prechecks on music attach/delete
[._.]/ Adam Eivycc288052fee2
diff --git a/server/routes/pipeline.js b/server/routes/pipeline.jsindex 1847b2ef10..df46a199b5 100644--- a/server/routes/pipeline.js+++ b/server/routes/pipeline.js@@ -743,8 +743,8 @@ const musicUpload = uploadSingle('track', {// The audio stage status reflects whether the *VO line list* is ready, since// music alone doesn't make an episode renderable. So music-only mutations// leave status at 'empty' when no lines exist and bump to 'edited' otherwise.-const audioStatusAfterMusicChange = (issue) =>- ((issue.stages?.audio?.lines || []).length ? 'edited' : 'empty');+const audioStatusAfterMusicChange = (stage) =>+ (stage.lines?.length ? 'edited' : 'empty');router.get('/audio/music-library', asyncHandler(async (_req, res) => {res.json({ tracks: await listMusicLibrary() });@@ -756,16 +756,22 @@ router.post('/issues/:id/stages/audio/music/upload', musicUpload, asyncHandler(astatus: 400, code: 'PIPELINE_MUSIC_NO_FILE',});}- const issue = await issuesSvc.getIssue(req.params.id).catch((err) => { throw mapServiceError(err); });+ // Guard the filesystem write that follows — `updateStageWithLatest`'s 404+ // would otherwise orphan the imported file in the music library.+ await issuesSvc.getIssue(req.params.id).catch((err) => { throw mapServiceError(err); });const { filename, sizeBytes } = await importUploadedTrack(req.file.path, req.file.originalname);const label = typeof req.body?.label === 'string' && req.body.label.trim()? req.body.label.trim(): null;- const { issue: updatedIssue, stage } = await issuesSvc.updateStage(req.params.id, 'audio', {- status: audioStatusAfterMusicChange(issue),- music: { source: MUSIC_SOURCE.UPLOAD, trackFilename: filename, label },- errorMessage: '',- });+ const { issue: updatedIssue, stage } = await issuesSvc.updateStageWithLatest(+ req.params.id,+ 'audio',+ (current) => ({+ status: audioStatusAfterMusicChange(current),+ music: { source: MUSIC_SOURCE.UPLOAD, trackFilename: filename, label },+ errorMessage: '',+ }),+ ).catch((err) => { throw mapServiceError(err); });res.json({ issue: updatedIssue, stage, music: stage.music, sizeBytes });}));@@ -782,26 +788,32 @@ router.post('/issues/:id/stages/audio/music/attach', asyncHandler(async (req, restatus: 404, code: 'PIPELINE_MUSIC_NOT_FOUND',});}- const issue = await issuesSvc.getIssue(req.params.id).catch((err) => { throw mapServiceError(err); });- const { issue: updatedIssue, stage } = await issuesSvc.updateStage(req.params.id, 'audio', {- status: audioStatusAfterMusicChange(issue),- music: {- source: MUSIC_SOURCE.LIBRARY,- trackFilename: body.trackFilename,- label: body.label?.trim() || found.label,- },- errorMessage: '',- });+ const { issue: updatedIssue, stage } = await issuesSvc.updateStageWithLatest(+ req.params.id,+ 'audio',+ (current) => ({+ status: audioStatusAfterMusicChange(current),+ music: {+ source: MUSIC_SOURCE.LIBRARY,+ trackFilename: body.trackFilename,+ label: body.label?.trim() || found.label,+ },+ errorMessage: '',+ }),+ ).catch((err) => { throw mapServiceError(err); });res.json({ issue: updatedIssue, stage, music: stage.music });}));router.delete('/issues/:id/stages/audio/music', asyncHandler(async (req, res) => {- const issue = await issuesSvc.getIssue(req.params.id).catch((err) => { throw mapServiceError(err); });- const { issue: updatedIssue, stage } = await issuesSvc.updateStage(req.params.id, 'audio', {- status: audioStatusAfterMusicChange(issue),- music: null,- errorMessage: '',- });+ const { issue: updatedIssue, stage } = await issuesSvc.updateStageWithLatest(+ req.params.id,+ 'audio',+ (current) => ({+ status: audioStatusAfterMusicChange(current),+ music: null,+ errorMessage: '',+ }),+ ).catch((err) => { throw mapServiceError(err); });res.json({ issue: updatedIssue, stage });}));diff --git a/server/routes/pipeline.test.js b/server/routes/pipeline.test.jsindex f475459afe..c1a1d5895e 100644--- a/server/routes/pipeline.test.js+++ b/server/routes/pipeline.test.js@@ -1691,6 +1691,15 @@ describe('pipeline routes', () => {expect(r.status).toBe(400);});+ it('POST /audio/music/attach 404s when the issue does not exist', async () => {+ const app = makeApp();+ musicLibraryStore.set('shared.mp3', { filename: 'shared.mp3', label: 'shared', sizeBytes: 100, updatedAt: '2026-05-15T00:00:00.000Z' });+ const r = await request(app)+ .post('/api/pipeline/issues/iss-does-not-exist/stages/audio/music/attach')+ .send({ trackFilename: 'shared.mp3' });+ expect(r.status).toBe(404);+ });+it('DELETE /audio/music clears music from the issue without deleting the library entry', async () => {const app = makeApp();const iss = await seedIssue(app);@@ -1707,6 +1716,14 @@ describe('pipeline routes', () => {expect(musicLibraryStore.has('shared.mp3')).toBe(true);});+ it('DELETE /audio/music 404s when the issue does not exist', async () => {+ const app = makeApp();+ const r = await request(app)+ .delete('/api/pipeline/issues/iss-does-not-exist/stages/audio/music')+ .send();+ expect(r.status).toBe(404);+ });+it('DELETE /audio/music-library/:filename removes the file from the library', async () => {const app = makeApp();musicLibraryStore.set('doomed.mp3', { filename: 'doomed.mp3', label: 'doomed', sizeBytes: 1, updatedAt: '2026-05-15T00:00:00.000Z' });