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
feat([wardrobe-appearance-id-route-validation]): 400 on dangling characterAppearances ids
[._.]/ Adam Eivyc5574b53a033
diff --git a/server/services/pipeline/visualStages.js b/server/services/pipeline/visualStages.jsindex 773a3c2027..dccb4238fe 100644--- a/server/services/pipeline/visualStages.js+++ b/server/services/pipeline/visualStages.js@@ -779,6 +779,49 @@ export async function enqueueVisualComicPage(issueId, options = {}) {** Returns { jobId, mode, prompt }.*/+/**+ * Validate per-scene wardrobe picks at the request boundary. The generic+ * visual-image route accepts `characterAppearances` ([{ characterId,+ * wardrobeId? }]) threaded from the storyboards picker; the Zod schema only+ * checks shape (non-empty ids), so this is the first point that can confirm+ * the ids actually resolve to a canon character + one of its wardrobes.+ *+ * Throws a 400 ServerError on a dangling characterId/wardrobeId rather than+ * leaning on `buildScenePrompt`'s defensive read, which would silently drop+ * the pick. A dangling id is a client/state bug (stale picker, deleted+ * character) worth surfacing — not a no-op. A null/absent `wardrobeId` is+ * valid (the character renders on their canonical body description); only a+ * non-empty wardrobeId is resolved against the character's wardrobes.+ */+export function assertCharacterAppearancesResolve(characterAppearances, characters) {+ const picks = Array.isArray(characterAppearances) ? characterAppearances : [];+ if (!picks.length) return;+ const charById = new Map(+ (Array.isArray(characters) ? characters : [])+ .filter((c) => c && c.id)+ .map((c) => [c.id, c]),+ );+ for (const pick of picks) {+ if (!pick || !pick.characterId) continue;+ const character = charById.get(pick.characterId);+ if (!character) {+ throw new ServerError(+ `characterAppearances references unknown character id "${pick.characterId}"`,+ { status: 400, code: 'PIPELINE_VISUAL_BAD_CHARACTER' },+ );+ }+ if (pick.wardrobeId) {+ const wardrobe = (character.wardrobes || []).find((w) => w && w.id === pick.wardrobeId);+ if (!wardrobe) {+ throw new ServerError(+ `characterAppearances references unknown wardrobe id "${pick.wardrobeId}" for character "${character.name || pick.characterId}"`,+ { status: 400, code: 'PIPELINE_VISUAL_BAD_WARDROBE' },+ );+ }+ }+ }+}+export async function enqueueVisualImage(issueId, stageId, options = {}) {if (!VISUAL_STAGE_IDS.includes(stageId)) {throw new ServerError(`not a visual stage: ${stageId}`, {@@ -787,6 +830,10 @@ export async function enqueueVisualImage(issueId, stageId, options = {}) {}const { issue, settings, series, world, canon } = await loadBibleContext(issueId);assertStageUnlocked(issue, stageId);+ // Resolve wardrobe picks against canon at the request boundary — a dangling+ // characterId/wardrobeId is a client/state bug worth a 400, not the silent+ // drop buildScenePrompt would otherwise apply.+ assertCharacterAppearancesResolve(options.characterAppearances, canon.characters);const mode = resolveMode(options, settings);// Match on description + slugline so the featured-character set (and thus// which wardrobe picks apply) stays consistent with the scene-video / shotdiff --git a/server/services/pipeline/visualStages.test.js b/server/services/pipeline/visualStages.test.jsindex ccb1a2830d..d3f5af67b8 100644--- a/server/services/pipeline/visualStages.test.js+++ b/server/services/pipeline/visualStages.test.js@@ -81,6 +81,7 @@ const {enqueueStoryboardShotStartFrame,refineComicPanelPrompt,refineStoryboardScenePrompt,+ assertCharacterAppearancesResolve,} = await import('./visualStages.js');beforeEach(() => {@@ -850,3 +851,56 @@ describe('refineStoryboardScenePrompt', () => {}));});});++describe('assertCharacterAppearancesResolve', () => {+ const characters = [+ { id: 'char-aria', name: 'Aria', wardrobes: [{ id: 'wd-coat', name: 'Trench coat' }] },+ { id: 'char-kessa', name: 'Kessa', wardrobes: [] },+ ];++ it('is a no-op for absent / empty / non-array picks', () => {+ expect(() => assertCharacterAppearancesResolve(undefined, characters)).not.toThrow();+ expect(() => assertCharacterAppearancesResolve([], characters)).not.toThrow();+ expect(() => assertCharacterAppearancesResolve(null, characters)).not.toThrow();+ expect(() => assertCharacterAppearancesResolve('nope', characters)).not.toThrow();+ });++ it('accepts a resolvable character + wardrobe pick', () => {+ expect(() => assertCharacterAppearancesResolve(+ [{ characterId: 'char-aria', wardrobeId: 'wd-coat' }],+ characters,+ )).not.toThrow();+ });++ it('accepts a character pick with no wardrobeId (canonical body description)', () => {+ expect(() => assertCharacterAppearancesResolve([{ characterId: 'char-aria' }], characters)).not.toThrow();+ expect(() => assertCharacterAppearancesResolve([{ characterId: 'char-kessa', wardrobeId: null }], characters)).not.toThrow();+ });++ it('400s on a dangling characterId', () => {+ expect(() => assertCharacterAppearancesResolve([{ characterId: 'char-ghost' }], characters))+ .toThrow(expect.objectContaining({ status: 400, code: 'PIPELINE_VISUAL_BAD_CHARACTER' }));+ });++ it('400s on a wardrobeId that does not belong to the character', () => {+ expect(() => assertCharacterAppearancesResolve(+ [{ characterId: 'char-kessa', wardrobeId: 'wd-coat' }],+ characters,+ )).toThrow(expect.objectContaining({ status: 400, code: 'PIPELINE_VISUAL_BAD_WARDROBE' }));+ });++ it('validates every pick, not just the first', () => {+ expect(() => assertCharacterAppearancesResolve(+ [{ characterId: 'char-aria', wardrobeId: 'wd-coat' }, { characterId: 'char-ghost' }],+ characters,+ )).toThrow(expect.objectContaining({ code: 'PIPELINE_VISUAL_BAD_CHARACTER' }));+ });++ it('tolerates empty canon and malformed picks without a wardrobeId', () => {+ expect(() => assertCharacterAppearancesResolve([{ characterId: 'char-aria' }], []))+ .toThrow(expect.objectContaining({ code: 'PIPELINE_VISUAL_BAD_CHARACTER' }));+ // A pick missing characterId entirely is skipped (the Zod schema guarantees+ // it upstream; the helper just doesn't crash on it).+ expect(() => assertCharacterAppearancesResolve([{ wardrobeId: 'wd-coat' }], characters)).not.toThrow();+ });+});