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([med-pipeline-server-routes-pipeline-js-1416-1452]): preserve cover.script when render body omits it
[._.]/ Adam Eivybc0a7037e2e0
diff --git a/server/routes/pipeline.js b/server/routes/pipeline.jsindex f4d7cc873f..e88ad821fd 100644--- a/server/routes/pipeline.js+++ b/server/routes/pipeline.js@@ -1137,18 +1137,19 @@ router.post('/series/:id/seasons/:seasonId/cover/render', asyncHandler(async (reslotKey, jobId: result.jobId, prompt: result.prompt,width: body.width, height: body.height, fromProof: result.fromProof,});+ // Only update `script` when the request body actually carried the field.+ // Blur-save (PATCH stages/.../cover) owns the script — render races against+ // it, so writing the *resolved* value (which falls back to the persisted+ // record's script when absent) would clobber a concurrent blur. Distinguish+ // absent (preserve) from empty string (intentional clear).const series = await seriesSvc.updateSeasonOnSeries(req.params.id,req.params.seasonId,(cur) => {const currentCover = cur?.cover || {};- return {- cover: {- ...currentCover,- script: result.coverScript || '',- [slotKey]: slotRecord,- },- };+ const nextCover = { ...currentCover, [slotKey]: slotRecord };+ if (typeof body.coverScript === 'string') nextCover.script = body.coverScript;+ return { cover: nextCover };},).catch((err) => { throw mapServiceError(err); });const season = (series.seasons || []).find((s) => s.id === req.params.seasonId);@@ -1170,13 +1171,9 @@ router.post('/series/:id/seasons/:seasonId/back-cover/render', asyncHandler(asynreq.params.seasonId,(cur) => {const currentBack = cur?.backCover || {};- return {- backCover: {- ...currentBack,- script: result.backCoverScript || '',- [slotKey]: slotRecord,- },- };+ const nextBack = { ...currentBack, [slotKey]: slotRecord };+ if (typeof body.backCoverScript === 'string') nextBack.script = body.backCoverScript;+ return { backCover: nextBack };},).catch((err) => { throw mapServiceError(err); });const season = (series.seasons || []).find((s) => s.id === req.params.seasonId);@@ -1542,18 +1539,17 @@ router.post('/issues/:id/stages/comicPages/cover/render', asyncHandler(async (reslotKey, jobId: result.jobId, prompt: result.prompt,width: body.width, height: body.height, fromProof: result.fromProof,});+ // Only update `script` when the request body actually carried the field —+ // blur-save (PATCH /issues/:id { stages.comicPages.cover.script }) owns the+ // field. See the equivalent gate on the volume route above for rationale.const { issue: updatedIssue, stage } = await issuesSvc.updateStageWithLatest(req.params.id,'comicPages',(currentStage) => {const currentCover = currentStage?.cover || {};- return {- cover: {- ...currentCover,- script: result.coverScript || '',- [slotKey]: slotRecord,- },- };+ const nextCover = { ...currentCover, [slotKey]: slotRecord };+ if (typeof body.coverScript === 'string') nextCover.script = body.coverScript;+ return { cover: nextCover };},).catch((err) => { throw mapServiceError(err); });res.json({ ...result, cover: stage.cover, issue: updatedIssue, stage });@@ -1579,13 +1575,9 @@ router.post('/issues/:id/stages/comicPages/back-cover/render', asyncHandler(asyn'comicPages',(currentStage) => {const currentBack = currentStage?.backCover || {};- return {- backCover: {- ...currentBack,- script: result.backCoverScript || '',- [slotKey]: slotRecord,- },- };+ const nextBack = { ...currentBack, [slotKey]: slotRecord };+ if (typeof body.backCoverScript === 'string') nextBack.script = body.backCoverScript;+ return { backCover: nextBack };},).catch((err) => { throw mapServiceError(err); });res.json({ ...result, backCover: stage.backCover, issue: updatedIssue, stage });diff --git a/server/routes/pipeline.test.js b/server/routes/pipeline.test.jsindex 9a0bae0478..8f5abafebf 100644--- a/server/routes/pipeline.test.js+++ b/server/routes/pipeline.test.js@@ -86,6 +86,35 @@ vi.mock('../services/pipeline/visualStages.js', () => ({variant: body?.target === 'final' ? 'final' : 'proof',fromProof: body?.target === 'final' && body?.useProofAsBase === true,})),+ // Back cover render — symmetric with front cover; the route's persist+ // logic differs only in field names (backCover slot + backCoverScript).+ enqueueComicBackCover: vi.fn(async (_issueId, body) => ({+ jobId: `backcover-job-${++uuidCounter}`,+ mode: 'local',+ prompt: 'back cover art prompt',+ backCoverScript: body?.backCoverScript ?? 'default back cover concept',+ variant: body?.target === 'final' ? 'final' : 'proof',+ fromProof: body?.target === 'final' && body?.useProofAsBase === true,+ })),+ // Volume (season) front + back cover. Route writes to series.seasons[].cover+ // / .backCover via seriesSvc.updateSeasonOnSeries, so the mock shape mirrors+ // the comic-cover mocks.+ enqueueVolumeCover: vi.fn(async (_seriesId, _seasonId, body) => ({+ jobId: `vol-cover-job-${++uuidCounter}`,+ mode: 'local',+ prompt: 'volume cover art prompt',+ coverScript: body?.coverScript ?? 'default volume cover concept',+ variant: body?.target === 'final' ? 'final' : 'proof',+ fromProof: body?.target === 'final' && body?.useProofAsBase === true,+ })),+ enqueueVolumeBackCover: vi.fn(async (_seriesId, _seasonId, body) => ({+ jobId: `vol-backcover-job-${++uuidCounter}`,+ mode: 'local',+ prompt: 'volume back cover art prompt',+ backCoverScript: body?.backCoverScript ?? 'default volume back cover concept',+ variant: body?.target === 'final' ? 'final' : 'proof',+ fromProof: body?.target === 'final' && body?.useProofAsBase === true,+ })),// Single-scene video render. Returns the shape the route forwards verbatim// to clients: { jobId, prompt, sceneIndex, issue, stage }.enqueueStoryboardSceneVideo: vi.fn(async (issueId, sceneIndex) => ({@@ -1098,6 +1127,95 @@ describe('pipeline routes', () => {expect(coverRes.status).toBe(400);});+ // ---- cover-script write semantics ----+ // The four cover render routes only write `script` when the request body+ // actually carried the script field. Blur-save owns the field; the render+ // route races against it, so writing the *resolved* value (which falls back+ // to the persisted record's script when absent) would clobber a concurrent+ // blur. Distinguish absent (preserve) from empty string (intentional clear).++ it('POST /issues/:id/stages/comicPages/cover/render preserves persisted cover.script when body omits coverScript', async () => {+ const app = makeApp();+ const ser = await request(app).post('/api/pipeline/series').send({ name: 'S' });+ const iss = await request(app).post(`/api/pipeline/series/${ser.body.id}/issues`).send({ title: 'I' });+ // Seed the script via a first render carrying it.+ const first = await request(app)+ .post(`/api/pipeline/issues/${iss.body.id}/stages/comicPages/cover/render`)+ .send({ coverScript: 'Hero stands atop the foundry' });+ expect(first.status).toBe(200);+ expect(first.body.cover.script).toBe('Hero stands atop the foundry');+ // Second render omits coverScript — the script must NOT be overwritten+ // with the service's fallback ('default cover concept' in the mock).+ const second = await request(app)+ .post(`/api/pipeline/issues/${iss.body.id}/stages/comicPages/cover/render`)+ .send({ target: 'final', useProofAsBase: true });+ expect(second.status).toBe(200);+ expect(second.body.cover.script).toBe('Hero stands atop the foundry');+ });++ it('POST /issues/:id/stages/comicPages/cover/render clears cover.script when body carries empty string', async () => {+ const app = makeApp();+ const ser = await request(app).post('/api/pipeline/series').send({ name: 'S' });+ const iss = await request(app).post(`/api/pipeline/series/${ser.body.id}/issues`).send({ title: 'I' });+ await request(app)+ .post(`/api/pipeline/issues/${iss.body.id}/stages/comicPages/cover/render`)+ .send({ coverScript: 'Hero stands atop the foundry' });+ // Explicit empty string is an intentional clear — distinct from absent.+ const cleared = await request(app)+ .post(`/api/pipeline/issues/${iss.body.id}/stages/comicPages/cover/render`)+ .send({ coverScript: '' });+ expect(cleared.status).toBe(200);+ expect(cleared.body.cover.script).toBe('');+ });++ it('POST /issues/:id/stages/comicPages/back-cover/render preserves persisted backCover.script when body omits backCoverScript', async () => {+ const app = makeApp();+ const ser = await request(app).post('/api/pipeline/series').send({ name: 'S' });+ const iss = await request(app).post(`/api/pipeline/series/${ser.body.id}/issues`).send({ title: 'I' });+ const first = await request(app)+ .post(`/api/pipeline/issues/${iss.body.id}/stages/comicPages/back-cover/render`)+ .send({ backCoverScript: 'Quiet rain over the empty market' });+ expect(first.status).toBe(200);+ expect(first.body.backCover.script).toBe('Quiet rain over the empty market');+ const second = await request(app)+ .post(`/api/pipeline/issues/${iss.body.id}/stages/comicPages/back-cover/render`)+ .send({ target: 'final', useProofAsBase: true });+ expect(second.status).toBe(200);+ expect(second.body.backCover.script).toBe('Quiet rain over the empty market');+ });++ it('POST /series/:id/seasons/:seasonId/cover/render preserves persisted cover.script when body omits coverScript', async () => {+ const app = makeApp();+ const ser = await request(app).post('/api/pipeline/series').send({ name: 'S' });+ const sea = await request(app).post(`/api/pipeline/series/${ser.body.id}/seasons`).send({ title: 'Vol 1' });+ const first = await request(app)+ .post(`/api/pipeline/series/${ser.body.id}/seasons/${sea.body.id}/cover/render`)+ .send({ coverScript: 'Collected arc hero shot' });+ expect(first.status).toBe(200);+ expect(first.body.season.cover.script).toBe('Collected arc hero shot');+ const second = await request(app)+ .post(`/api/pipeline/series/${ser.body.id}/seasons/${sea.body.id}/cover/render`)+ .send({ target: 'final', useProofAsBase: true });+ expect(second.status).toBe(200);+ expect(second.body.season.cover.script).toBe('Collected arc hero shot');+ });++ it('POST /series/:id/seasons/:seasonId/back-cover/render preserves persisted backCover.script when body omits backCoverScript', async () => {+ const app = makeApp();+ const ser = await request(app).post('/api/pipeline/series').send({ name: 'S' });+ const sea = await request(app).post(`/api/pipeline/series/${ser.body.id}/seasons`).send({ title: 'Vol 1' });+ const first = await request(app)+ .post(`/api/pipeline/series/${ser.body.id}/seasons/${sea.body.id}/back-cover/render`)+ .send({ backCoverScript: 'Atmospheric companion image' });+ expect(first.status).toBe(200);+ expect(first.body.season.backCover.script).toBe('Atmospheric companion image');+ const second = await request(app)+ .post(`/api/pipeline/series/${ser.body.id}/seasons/${sea.body.id}/back-cover/render`)+ .send({ target: 'final', useProofAsBase: true });+ expect(second.status).toBe(200);+ expect(second.body.season.backCover.script).toBe('Atmospheric companion image');+ });+// -----------------------// Season routes (Phase 2 of Story Arc Planning)// -----------------------