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
test: guard dry-run plan ↔ resolveNextStep parity in series autopilot (#1577)
Adam Eivy30a91509730b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 86b18e0c93..866d61006a 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -149,3 +149,4 @@- **[issue-1640] Extracted the duplicated gallery-image filename resolver into one shared `server/lib/localImageFilename.js` helper.** Four federated-record domains each carried a byte-identical copy of the "resolve a stored image reference to its bare `data/images/` filename (or null for empty/external-URL/non-image-path)" logic that the peer-sync asset pipeline relies on — `headshotImageFilename` (authors), `portraitImageFilename` (artists), `coverImageFilename` (albums), and `startingImageFilename` (Creative Director projects). They now all delegate to a single `localImageFilename(urlOrPath)` (barrelled + cataloged per the module-organization rule); each domain keeps its named export as a thin wrapper so the imports `peerSync.js` relies on are unchanged. Pure-function refactor, no behavior change; the new helper is unit-tested and each domain's existing `logic.test.js` still pins the wrapper behavior. (`server/lib/localImageFilename.js`, `server/services/{authors,artists,albums,creativeDirector}/`)- **[issue-1524] Renumbered the duplicate `121-comic-script-visible-text-prompt` migration to `126`.** A rebase had landed two migration files numbered 121 (`121-codex-tui-bypass-sandbox` and `121-comic-script-visible-text-prompt`) on main. Both still applied exactly once (migrations are keyed by full filename, not number), so this was cosmetic — but the duplicate number muddied log/sort order. Renamed the comic-script one to the next free number; it's an idempotent hash-driven prompt-replace, so installs that already applied it re-run it harmlessly as a no-op. (`scripts/migrations/126-comic-script-visible-text-prompt.js`)+- **[issue-1577] Added a drift guard tying the Series Autopilot dry-run plan to the resolver.** `buildDryRunPlan` (the steps the autopilot advertises it WILL run) is kept in sync with `resolveNextStep` (the steps execute actually runs) **by hand** — a future edit to the resolver could leave the plan advertising steps execute will skip, or vice-versa, with no test to catch it. A new parity test walks `resolveNextStep` the way the execute dispatch does (applying each completed step's effect and re-resolving) to collect the ordered step sequence, then asserts it matches `buildDryRunPlan`'s output across the comic+visual, text-only, editorial-rounds-0, and TV fixtures. Test-only; no behavior change. (`server/services/pipeline/seriesAutopilot.test.js`)diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.jsindex 1836311780..68fbbe4600 100644--- a/server/services/pipeline/seriesAutopilot.test.js+++ b/server/services/pipeline/seriesAutopilot.test.js@@ -468,6 +468,149 @@ describe('resolveNextStep (pure)', () => {});});+describe('dry-run plan ↔ resolveNextStep drift guard (#1577)', () => {+ // buildDryRunPlan is kept in sync with resolveNextStep BY HAND (see the comment+ // above buildDryRunPlan). This guard runs BOTH against the same fixtures and+ // asserts they enumerate the SAME step kinds in the SAME order — so a future+ // edit that adds/removes/reorders a step in one and forgets the other fails+ // here instead of silently advertising a plan execute won't follow.+ //+ // Fidelity note: the fixtures all have their issues already present (no empty+ // seasons), so no generation step CREATES new downstream work mid-walk. That's+ // the regime where the two are contractually identical — the dry-run plan is a+ // snapshot prediction of the CURRENT records, not a recursive expansion of+ // issues a generateEpisodes step would later add. generateArc / generateEpisodes+ // parity is covered separately by the dedicated cases above.++ const freshRunState = () => ({+ arcAttempted: false, arcVerified: false, beatContinuityChecked: false,+ editorialReviewed: false, reverseOutlineRefreshed: false,+ editorialChecksReviewed: false, editorialHealthReady: false, canonVerified: false,+ episodesAttempted: new Set(), beatsAttempted: new Set(), textAttempted: new Set(),+ scriptChecked: new Set(), visualDrafted: new Set(),+ });++ // Advance runState + fixture exactly as the execute dispatch would once the+ // given step "completes" — flipping the precise predicate each downstream gate+ // reads: runState marks for the boolean/set gates, and issue/season CONTENT for+ // the content gates (beats → idea.output, text → required scripts, visuals →+ // rendered pages) so the resolver actually advances past them.+ const completeStep = (step, issues, runState, edRounds) => {+ switch (step.kind) {+ case 'generateArc':+ runState.arcAttempted = true;+ break;+ case 'generateEpisodes':+ issues.push({ id: `auto-${step.seasonId}`, seasonId: step.seasonId, number: 99, arcPosition: 99, stages: {} });+ runState.episodesAttempted.add(step.seasonId);+ break;+ case 'verifyArc':+ runState.arcVerified = true;+ break;+ case 'beatSheet':+ issues.filter((i) => i.seasonId === step.seasonId)+ .forEach((i) => { i.stages = { ...i.stages, idea: ready() }; });+ runState.beatsAttempted.add(step.seasonId);+ break;+ case 'beatContinuity':+ runState.beatContinuityChecked = true;+ break;+ case 'textStages': {+ // Satisfy textReady for every script format (comic + tv) so the mutator+ // stays target-agnostic.+ const issue = issues.find((i) => i.id === step.issueId);+ issue.stages = { ...issue.stages, comicScript: ready(VALID_SCRIPT), teleplay: ready() };+ runState.textAttempted.add(step.issueId);+ break;+ }+ case 'scriptVerify':+ runState.scriptChecked.add(step.issueId);+ break;+ case 'editorialReview':+ runState.editorialReviewed = true;+ // Mirror runEditorial: maxEditorialRounds === 0 marks the whole editorial+ // gate (reverse-outline + checks + health) done in one shot, so the+ // resolver advances straight past them — matching the plan's omission.+ if (edRounds === 0) {+ runState.reverseOutlineRefreshed = true;+ runState.editorialChecksReviewed = true;+ runState.editorialHealthReady = true;+ }+ break;+ case 'reverseOutline':+ runState.reverseOutlineRefreshed = true;+ break;+ case 'editorialChecks':+ runState.editorialChecksReviewed = true;+ break;+ case 'editorialHealthGate':+ runState.editorialHealthReady = true;+ break;+ case 'canonVerify':+ runState.canonVerified = true;+ break;+ case 'visualDraft': {+ const issue = issues.find((i) => i.id === step.issueId);+ issue.stages = {+ ...issue.stages,+ comicPages: {+ cover: { proofImage: { jobId: 'c' } },+ backCover: { proofImage: { jobId: 'b' } },+ pages: [{ panels: [{ description: 'x' }], proofImage: { jobId: 'p' } }],+ },+ };+ runState.visualDrafted.add(step.issueId);+ break;+ }+ default:+ throw new Error(`drift guard: unhandled step kind "${step.kind}" — add a completeStep branch`);+ }+ };++ // Walk resolveNextStep the way execute does — apply each step's effect, re-resolve+ // — collecting the ordered, de-duplicated sequence of step kinds. Per-issue /+ // per-season steps repeat in the resolver but collapse to a single plan entry, so+ // consecutive duplicates are merged to match the plan's shape.+ const simulateExecuteKinds = (series, issues, options) => {+ const working = issues.map((i) => ({ ...i, stages: { ...i.stages } }));+ const runState = freshRunState();+ const edRounds = Number.isInteger(options?.maxEditorialRounds) ? options.maxEditorialRounds : undefined;+ const kinds = [];+ for (let guard = 0; guard < 200; guard += 1) {+ const step = resolveNextStep(series, working, runState, options);+ if (step.kind === 'done') return kinds;+ if (kinds[kinds.length - 1] !== step.kind) kinds.push(step.kind);+ completeStep(step, working, runState, edRounds);+ }+ throw new Error('drift guard: simulation did not converge to done within 200 steps');+ };++ const planKinds = (series, issues, options) =>+ autopilot.__testing.buildDryRunPlan(series, issues, options).map((p) => p.kind);++ const baseComic = () => ({ targetFormat: 'comic', arc: { logline: 'L', summary: 'S' }, seasons: [{ id: 'se1', number: 1 }] });+ const baseTv = () => ({ targetFormat: 'tv', arc: { logline: 'L', summary: 'S' }, seasons: [{ id: 'se1', number: 1 }] });+ const bareIssue = () => [{ id: 'iss1', seasonId: 'se1', number: 1, arcPosition: 1, stages: {} }];++ const cases = [+ { name: 'comic + visual (full pipeline)', series: baseComic(), issues: bareIssue(), options: {} },+ { name: 'comic, text-only target (no canon/visual)', series: baseComic(), issues: bareIssue(), options: { target: 'text' } },+ { name: 'comic, editorial rounds 0 (skips editorial gate)', series: baseComic(), issues: bareIssue(), options: { maxEditorialRounds: 0 } },+ { name: 'tv (no comic script / canon / visual)', series: baseTv(), issues: bareIssue(), options: {} },+ ];++ for (const c of cases) {+ it(`enumerates identical step kinds in identical order — ${c.name}`, () => {+ // buildDryRunPlan reads the records as-is; the simulation walks fresh copies,+ // so the two never share mutable state.+ const plan = planKinds(c.series, c.issues, c.options);+ const executed = simulateExecuteKinds(c.series, c.issues, c.options);+ expect(executed.length).toBeGreaterThan(0);+ expect(executed).toEqual(plan);+ });+ }+});+describe('requiredScriptStages / scriptStructurallyReady', () => {it('maps targetFormat to required scripts', () => {expect(requiredScriptStages({ targetFormat: 'comic' })).toEqual(['comicScript']);