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: collapse 36 hand-pasted seed-migration suites into runSeedStageMigrationTests (#12974) (#13050)
[._.]/b0324452885f
diff --git a/scripts/migrations/048-catalog-ideas-scenes-concepts-stage.test.js b/scripts/migrations/048-catalog-ideas-scenes-concepts-stage.test.jsindex b207de3158..b37b5fc7ee 100644--- a/scripts/migrations/048-catalog-ideas-scenes-concepts-stage.test.js+++ b/scripts/migrations/048-catalog-ideas-scenes-concepts-stage.test.js@@ -1,91 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join } from 'path';+import { describe } from 'vitest';import migration from './048-catalog-ideas-scenes-concepts-stage.js';--const STAGES = ['catalog-ideas-scenes-concepts'];-const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 048 — seed catalog ingest light-shape stage', () => {- let rootDir;- let installedStagesDir;- let installedConfigPath;- let refStagesDir;- let refConfigPath;-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-048-'));- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- mkdirSync(refStagesDir, { recursive: true });- for (const key of STAGES) {- writeFileSync(join(refStagesDir, `${key}.md`), `# ${key}\n\nbody for ${key}\n`);- }- const refConfig = { stages: {} };- for (const key of STAGES) {- refConfig.stages[key] = { name: key, model: 'default', returnsJson: true, variables: [] };- }- writeFileSync(refConfigPath, JSON.stringify(refConfig, null, 2) + '\n');-- installedStagesDir = join(rootDir, 'data', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the prompt file + stage-config entry on a fresh install', async () => {- await migration.up({ rootDir });- for (const key of STAGES) {- expect(existsSync(join(installedStagesDir, `${key}.md`))).toBe(true);- }- const config = readJson(installedConfigPath);- for (const key of STAGES) {- expect(config.stages[key]).toBeTruthy();- }- });-- it('merges into an existing stage-config without clobbering other stages', async () => {- mkdirSync(installedStagesDir, { recursive: true });- writeFileSync(installedConfigPath, JSON.stringify({ stages: { 'pipeline-prose': { name: 'Prose' }, [STAGES[0]]: { name: 'CUSTOM', model: 'my-model' } } }, null, 2) + '\n');- await migration.up({ rootDir });- const config = readJson(installedConfigPath);- expect(config.stages['pipeline-prose']).toEqual({ name: 'Prose' });- expect(config.stages[STAGES[0]]).toEqual({ name: 'CUSTOM', model: 'my-model' });- for (const key of STAGES.slice(1)) {- expect(config.stages[key]).toBeTruthy();- }- });-- it('is idempotent and preserves a user-customized installed prompt', async () => {- mkdirSync(installedStagesDir, { recursive: true });- const customPath = join(installedStagesDir, 'catalog-ideas-scenes-concepts.md');- writeFileSync(customPath, '# CUSTOM ideas/scenes/concepts\n');- await migration.up({ rootDir });- expect(readFileSync(customPath, 'utf-8')).toContain('CUSTOM');- // Second run is a clean no-op.- await migration.up({ rootDir });- expect(readFileSync(customPath, 'utf-8')).toContain('CUSTOM');- const config = readJson(installedConfigPath);- expect(Object.keys(config.stages).filter((k) => STAGES.includes(k))).toHaveLength(1);- });-- it('logs and skips when the data.reference template is missing (no crash)', async () => {- rmSync(join(refStagesDir, 'catalog-ideas-scenes-concepts.md'));- await migration.up({ rootDir });- // Stage-config merge still runs from refConfigPath, so the entry lands- // even without the .md (the runtime stageRunner will then throw at first- // use — but the migration itself stays non-fatal so boot succeeds).- expect(existsSync(join(installedStagesDir, 'catalog-ideas-scenes-concepts.md'))).toBe(false);- });-- it('logs and skips when the data.reference stage-config is missing (no crash)', async () => {- rmSync(refConfigPath);- await migration.up({ rootDir });- // .md still copies even when the config side is unavailable.- expect(existsSync(join(installedStagesDir, 'catalog-ideas-scenes-concepts.md'))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['catalog-ideas-scenes-concepts'], prefix: 'migration-048-' });});diff --git a/scripts/migrations/097-continuity-bible-stage.test.js b/scripts/migrations/097-continuity-bible-stage.test.jsindex 585081413f..0bb803f88f 100644--- a/scripts/migrations/097-continuity-bible-stage.test.js+++ b/scripts/migrations/097-continuity-bible-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './097-continuity-bible-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 093/095) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-continuity-bible.md';-const STAGE_KEY = 'pipeline-continuity-bible';-const BODY = '# Continuity bible\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 097 — seed continuity-bible stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'heavy', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-097-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-continuity-bible'], prefix: 'migration-097-' });});diff --git a/scripts/migrations/099-editorial-interiority-stage.test.js b/scripts/migrations/099-editorial-interiority-stage.test.jsindex ba70d51266..1b97f36dd4 100644--- a/scripts/migrations/099-editorial-interiority-stage.test.js+++ b/scripts/migrations/099-editorial-interiority-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './099-editorial-interiority-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 096/097) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-interiority.md';-const STAGE_KEY = 'pipeline-editorial-interiority';-const BODY = '# Protagonist interiority\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 099 — seed editorial-interiority stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-099-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-interiority'], prefix: 'migration-099-' });});diff --git a/scripts/migrations/100-editorial-chekhov-stage.test.js b/scripts/migrations/100-editorial-chekhov-stage.test.jsindex dd2f8b3b42..a3ed3332b0 100644--- a/scripts/migrations/100-editorial-chekhov-stage.test.js+++ b/scripts/migrations/100-editorial-chekhov-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './100-editorial-chekhov-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 099) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-chekhov.md';-const STAGE_KEY = 'pipeline-editorial-chekhov';-const BODY = "# Chekhov's guns\n\nshipped body\n";+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 100 — seed editorial-chekhov stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-100-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-chekhov'], prefix: 'migration-100-' });});diff --git a/scripts/migrations/101-editorial-dead-metaphor-stage.test.js b/scripts/migrations/101-editorial-dead-metaphor-stage.test.jsindex fddb5a9ba3..7f2da78e3f 100644--- a/scripts/migrations/101-editorial-dead-metaphor-stage.test.js+++ b/scripts/migrations/101-editorial-dead-metaphor-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './101-editorial-dead-metaphor-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 099) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-dead-metaphor.md';-const STAGE_KEY = 'pipeline-editorial-dead-metaphor';-const BODY = '# Dead / mixed metaphor\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 101 — seed editorial-dead-metaphor stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-101-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-dead-metaphor'], prefix: 'migration-101-' });});diff --git a/scripts/migrations/102-editorial-endings-cliffhanger-stage.test.js b/scripts/migrations/102-editorial-endings-cliffhanger-stage.test.jsindex ede9b3341f..cc1d0d9a5e 100644--- a/scripts/migrations/102-editorial-endings-cliffhanger-stage.test.js+++ b/scripts/migrations/102-editorial-endings-cliffhanger-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './102-editorial-endings-cliffhanger-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 100) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-endings-cliffhanger.md';-const STAGE_KEY = 'pipeline-editorial-endings-cliffhanger';-const BODY = '# Chapter-ending cliffhangers\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 102 — seed editorial-endings-cliffhanger stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-102-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-endings-cliffhanger'], prefix: 'migration-102-' });});diff --git a/scripts/migrations/103-editorial-opening-start-stage.test.js b/scripts/migrations/103-editorial-opening-start-stage.test.jsindex 8e57bbbb3c..a1ff7d396b 100644--- a/scripts/migrations/103-editorial-opening-start-stage.test.js+++ b/scripts/migrations/103-editorial-opening-start-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './103-editorial-opening-start-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 101) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-opening-start.md';-const STAGE_KEY = 'pipeline-editorial-opening-start';-const BODY = '# Weak opening\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 103 — seed editorial-opening-start stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-103-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-opening-start'], prefix: 'migration-103-' });});diff --git a/scripts/migrations/104-editorial-mirror-description-stage.test.js b/scripts/migrations/104-editorial-mirror-description-stage.test.jsindex 424a3e49be..d961edf72c 100644--- a/scripts/migrations/104-editorial-mirror-description-stage.test.js+++ b/scripts/migrations/104-editorial-mirror-description-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './104-editorial-mirror-description-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 101) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-mirror-description.md';-const STAGE_KEY = 'pipeline-editorial-mirror-description';-const BODY = '# Mirror self-description\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 104 — seed editorial-mirror-description stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-104-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-mirror-description'], prefix: 'migration-104-' });});diff --git a/scripts/migrations/105-editorial-dialogue-pleasantries-stage.test.js b/scripts/migrations/105-editorial-dialogue-pleasantries-stage.test.jsindex 3fd10a6196..889cca9db0 100644--- a/scripts/migrations/105-editorial-dialogue-pleasantries-stage.test.js+++ b/scripts/migrations/105-editorial-dialogue-pleasantries-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './105-editorial-dialogue-pleasantries-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 101) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-dialogue-pleasantries.md';-const STAGE_KEY = 'pipeline-editorial-dialogue-pleasantries';-const BODY = '# Empty greeting\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 105 — seed editorial-dialogue-pleasantries stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-105-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-dialogue-pleasantries'], prefix: 'migration-105-' });});diff --git a/scripts/migrations/106-editorial-kill-your-darlings-stage.test.js b/scripts/migrations/106-editorial-kill-your-darlings-stage.test.jsindex 5a0e412cbd..65f8810999 100644--- a/scripts/migrations/106-editorial-kill-your-darlings-stage.test.js+++ b/scripts/migrations/106-editorial-kill-your-darlings-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './106-editorial-kill-your-darlings-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 101) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-kill-your-darlings.md';-const STAGE_KEY = 'pipeline-editorial-kill-your-darlings';-const BODY = '# Kill your darlings\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 106 — seed editorial-kill-your-darlings stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-106-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-kill-your-darlings'], prefix: 'migration-106-' });});diff --git a/scripts/migrations/109-editorial-arc-transitions-stage.test.js b/scripts/migrations/109-editorial-arc-transitions-stage.test.jsindex 59b8162332..c698018e8c 100644--- a/scripts/migrations/109-editorial-arc-transitions-stage.test.js+++ b/scripts/migrations/109-editorial-arc-transitions-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './109-editorial-arc-transitions-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 099) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-arc-transitions.md';-const STAGE_KEY = 'pipeline-editorial-arc-transitions';-const BODY = '# Character-arc transitions\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 109 — seed editorial-arc-transitions stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-109-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-arc-transitions'], prefix: 'migration-109-' });});diff --git a/scripts/migrations/110-editorial-telling-emotion-stage.test.js b/scripts/migrations/110-editorial-telling-emotion-stage.test.jsindex 34e653fed4..0407fc810d 100644--- a/scripts/migrations/110-editorial-telling-emotion-stage.test.js+++ b/scripts/migrations/110-editorial-telling-emotion-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './110-editorial-telling-emotion-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 109) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-telling-emotion.md';-const STAGE_KEY = 'pipeline-editorial-telling-emotion';-const BODY = '# Telling-not-showing emotion\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 110 — seed editorial-telling-emotion stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-110-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-telling-emotion'], prefix: 'migration-110-' });});diff --git a/scripts/migrations/111-editorial-plot-structure-stage.test.js b/scripts/migrations/111-editorial-plot-structure-stage.test.jsindex 24dac9ee17..1e3125a47e 100644--- a/scripts/migrations/111-editorial-plot-structure-stage.test.js+++ b/scripts/migrations/111-editorial-plot-structure-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './111-editorial-plot-structure-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 109/110) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-plot-structure.md';-const STAGE_KEY = 'pipeline-editorial-plot-structure';-const BODY = '# Plot structure & momentum\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 111 — seed editorial-plot-structure stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-111-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-plot-structure'], prefix: 'migration-111-' });});diff --git a/scripts/migrations/112-editorial-on-the-nose-stage.test.js b/scripts/migrations/112-editorial-on-the-nose-stage.test.jsindex c737f9fd2c..c37b0fa603 100644--- a/scripts/migrations/112-editorial-on-the-nose-stage.test.js+++ b/scripts/migrations/112-editorial-on-the-nose-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './112-editorial-on-the-nose-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 110) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-on-the-nose.md';-const STAGE_KEY = 'pipeline-editorial-on-the-nose';-const BODY = '# On-the-nose dialogue\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 112 — seed editorial-on-the-nose stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-111-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-on-the-nose'], prefix: 'migration-112-' });});diff --git a/scripts/migrations/113-editorial-voice-distinctiveness-stage.test.js b/scripts/migrations/113-editorial-voice-distinctiveness-stage.test.jsindex 884cbda079..c0be1de6d5 100644--- a/scripts/migrations/113-editorial-voice-distinctiveness-stage.test.js+++ b/scripts/migrations/113-editorial-voice-distinctiveness-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './113-editorial-voice-distinctiveness-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 110/111) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-voice-distinctiveness.md';-const STAGE_KEY = 'pipeline-editorial-voice-distinctiveness';-const BODY = '# Voice distinctiveness\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 113 — seed editorial-voice-distinctiveness stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-112-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-voice-distinctiveness'], prefix: 'migration-113-' });});diff --git a/scripts/migrations/115-editorial-theme-coherence-stage.test.js b/scripts/migrations/115-editorial-theme-coherence-stage.test.jsindex 1f3cf265a4..50869551b2 100644--- a/scripts/migrations/115-editorial-theme-coherence-stage.test.js+++ b/scripts/migrations/115-editorial-theme-coherence-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './115-editorial-theme-coherence-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 111) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-theme-coherence.md';-const STAGE_KEY = 'pipeline-editorial-theme-coherence';-const BODY = '# Theme coherence / thematic throughline\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 115 — seed editorial-theme-coherence stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-115-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-theme-coherence'], prefix: 'migration-115-' });});diff --git a/scripts/migrations/116-editorial-unmodeled-names-stage.test.js b/scripts/migrations/116-editorial-unmodeled-names-stage.test.jsindex d7f072db0d..af482c56b6 100644--- a/scripts/migrations/116-editorial-unmodeled-names-stage.test.js+++ b/scripts/migrations/116-editorial-unmodeled-names-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './116-editorial-unmodeled-names-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 115) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-unmodeled-names.md';-const STAGE_KEY = 'pipeline-editorial-unmodeled-names';-const BODY = '# Unmodeled proper nouns used as character names\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 116 — seed editorial-unmodeled-names stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-116-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-unmodeled-names'], prefix: 'migration-116-' });});diff --git a/scripts/migrations/117-editorial-eyeline-match-stage.test.js b/scripts/migrations/117-editorial-eyeline-match-stage.test.jsindex 4540dd905a..11016f4edd 100644--- a/scripts/migrations/117-editorial-eyeline-match-stage.test.js+++ b/scripts/migrations/117-editorial-eyeline-match-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './117-editorial-eyeline-match-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 116) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-eyeline-match.md';-const STAGE_KEY = 'pipeline-editorial-eyeline-match';-const BODY = '# Pipeline — Editorial Check: Storyboard eyeline match\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 117 — seed editorial-eyeline-match stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-117-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-eyeline-match'], prefix: 'migration-117-' });});diff --git a/scripts/migrations/118-editorial-appearance-continuity-stage.test.js b/scripts/migrations/118-editorial-appearance-continuity-stage.test.jsindex d483759b81..5704f136aa 100644--- a/scripts/migrations/118-editorial-appearance-continuity-stage.test.js+++ b/scripts/migrations/118-editorial-appearance-continuity-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './118-editorial-appearance-continuity-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 117) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-appearance-continuity.md';-const STAGE_KEY = 'pipeline-editorial-appearance-continuity';-const BODY = '# Pipeline — Editorial Check: Storyboard appearance / prop continuity\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 118 — seed editorial-appearance-continuity stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-118-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-appearance-continuity'], prefix: 'migration-118-' });});diff --git a/scripts/migrations/119-editorial-comic-page-turn-stage.test.js b/scripts/migrations/119-editorial-comic-page-turn-stage.test.jsindex 1868a1f502..66f91d5bf8 100644--- a/scripts/migrations/119-editorial-comic-page-turn-stage.test.js+++ b/scripts/migrations/119-editorial-comic-page-turn-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './119-editorial-comic-page-turn-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 110–118) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-comic-page-turn.md';-const STAGE_KEY = 'pipeline-editorial-comic-page-turn';-const BODY = '# Comic page-turn beats\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 119 — seed editorial-comic-page-turn stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-119-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-comic-page-turn'], prefix: 'migration-119-' });});diff --git a/scripts/migrations/129-editorial-timeline-contradiction-stage.test.js b/scripts/migrations/129-editorial-timeline-contradiction-stage.test.jsindex 34b289d69f..32cccb6509 100644--- a/scripts/migrations/129-editorial-timeline-contradiction-stage.test.js+++ b/scripts/migrations/129-editorial-timeline-contradiction-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './129-editorial-timeline-contradiction-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 109) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-timeline-contradiction.md';-const STAGE_KEY = 'pipeline-editorial-timeline-contradiction';-const BODY = '# Timeline / canon contradiction\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 129 — seed editorial-timeline-contradiction stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-129-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-timeline-contradiction'], prefix: 'migration-129-' });});diff --git a/scripts/migrations/130-editorial-character-consistency-stage.test.js b/scripts/migrations/130-editorial-character-consistency-stage.test.jsindex 63ed86df57..165f39d1ce 100644--- a/scripts/migrations/130-editorial-character-consistency-stage.test.js+++ b/scripts/migrations/130-editorial-character-consistency-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './130-editorial-character-consistency-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 129) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-character-consistency.md';-const STAGE_KEY = 'pipeline-editorial-character-consistency';-const BODY = '# Character consistency (unearned personality shift)\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 130 — seed editorial-character-consistency stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-130-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-character-consistency'], prefix: 'migration-130-' });});diff --git a/scripts/migrations/131-editorial-climax-agency-stage.test.js b/scripts/migrations/131-editorial-climax-agency-stage.test.jsindex b9456a8a57..3e2d7f1f9f 100644--- a/scripts/migrations/131-editorial-climax-agency-stage.test.js+++ b/scripts/migrations/131-editorial-climax-agency-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './131-editorial-climax-agency-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 130) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-climax-agency.md';-const STAGE_KEY = 'pipeline-editorial-climax-agency';-const BODY = '# Climax / resolution power\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 131 — seed editorial-climax-agency stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-131-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-climax-agency'], prefix: 'migration-131-' });});diff --git a/scripts/migrations/132-editorial-reaction-proportionality-stage.test.js b/scripts/migrations/132-editorial-reaction-proportionality-stage.test.jsindex f359448fc6..5dd307757c 100644--- a/scripts/migrations/132-editorial-reaction-proportionality-stage.test.js+++ b/scripts/migrations/132-editorial-reaction-proportionality-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './132-editorial-reaction-proportionality-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 131) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-reaction-proportionality.md';-const STAGE_KEY = 'pipeline-editorial-reaction-proportionality';-const BODY = '# Emotional beat proportionality\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 132 — seed editorial-reaction-proportionality stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-132-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-reaction-proportionality'], prefix: 'migration-132-' });});diff --git a/scripts/migrations/133-editorial-secondary-arc-stage.test.js b/scripts/migrations/133-editorial-secondary-arc-stage.test.jsindex df8c6816ad..8d104562b0 100644--- a/scripts/migrations/133-editorial-secondary-arc-stage.test.js+++ b/scripts/migrations/133-editorial-secondary-arc-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './133-editorial-secondary-arc-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 132) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-secondary-arc.md';-const STAGE_KEY = 'pipeline-editorial-secondary-arc';-const BODY = '# Secondary-character arcs\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 133 — seed editorial-secondary-arc stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-133-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-secondary-arc'], prefix: 'migration-133-' });});diff --git a/scripts/migrations/134-editorial-voice-consistency-stage.test.js b/scripts/migrations/134-editorial-voice-consistency-stage.test.jsindex e5687cd87d..9cb1255ef0 100644--- a/scripts/migrations/134-editorial-voice-consistency-stage.test.js+++ b/scripts/migrations/134-editorial-voice-consistency-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './134-editorial-voice-consistency-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 133) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-voice-consistency.md';-const STAGE_KEY = 'pipeline-editorial-voice-consistency';-const BODY = '# Narrative voice / tone consistency\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 134 — seed editorial-voice-consistency stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-134-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-voice-consistency'], prefix: 'migration-134-' });});diff --git a/scripts/migrations/135-editorial-fact-accuracy-stage.test.js b/scripts/migrations/135-editorial-fact-accuracy-stage.test.jsindex 8f56ec8e4b..7e68d74899 100644--- a/scripts/migrations/135-editorial-fact-accuracy-stage.test.js+++ b/scripts/migrations/135-editorial-fact-accuracy-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './135-editorial-fact-accuracy-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 134) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-fact-accuracy.md';-const STAGE_KEY = 'pipeline-editorial-fact-accuracy';-const BODY = '# Research / fact accuracy\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 135 — seed editorial-fact-accuracy stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-135-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-fact-accuracy'], prefix: 'migration-135-' });});diff --git a/scripts/migrations/136-editorial-comic-prose-sync-stage.test.js b/scripts/migrations/136-editorial-comic-prose-sync-stage.test.jsindex 90280d4648..8d0b7712dd 100644--- a/scripts/migrations/136-editorial-comic-prose-sync-stage.test.js+++ b/scripts/migrations/136-editorial-comic-prose-sync-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './136-editorial-comic-prose-sync-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 134) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-comic-prose-sync.md';-const STAGE_KEY = 'pipeline-editorial-comic-prose-sync';-const BODY = '# Comic ↔ prose synchronization\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 136 — seed editorial-comic-prose-sync stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-136-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-comic-prose-sync'], prefix: 'migration-136-' });});diff --git a/scripts/migrations/140-editorial-pacing-escalation-stage.test.js b/scripts/migrations/140-editorial-pacing-escalation-stage.test.jsindex c28f2f8ca6..38e0a2b474 100644--- a/scripts/migrations/140-editorial-pacing-escalation-stage.test.js+++ b/scripts/migrations/140-editorial-pacing-escalation-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './140-editorial-pacing-escalation-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 111) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-pacing-escalation-curve.md';-const STAGE_KEY = 'pipeline-editorial-pacing-escalation-curve';-const BODY = '# Pacing / intensity escalation curve\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 140 — seed editorial-pacing-escalation-curve stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-140-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-pacing-escalation-curve'], prefix: 'migration-140-' });});diff --git a/scripts/migrations/141-editorial-arc-regression-stage.test.js b/scripts/migrations/141-editorial-arc-regression-stage.test.jsindex a4122e0ced..8cafb72446 100644--- a/scripts/migrations/141-editorial-arc-regression-stage.test.js+++ b/scripts/migrations/141-editorial-arc-regression-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './141-editorial-arc-regression-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 140) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-arc-regression.md';-const STAGE_KEY = 'pipeline-editorial-arc-regression';-const BODY = '# Character-arc regression / premature closure\n\nshipped body\n';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 141 — seed editorial-arc-regression stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-141-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-arc-regression'], prefix: 'migration-141-' });});diff --git a/scripts/migrations/142-editorial-interiority-balance-stage.test.js b/scripts/migrations/142-editorial-interiority-balance-stage.test.jsindex ec891da3d9..a9ba83205f 100644--- a/scripts/migrations/142-editorial-interiority-balance-stage.test.js+++ b/scripts/migrations/142-editorial-interiority-balance-stage.test.js@@ -1,101 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './142-editorial-interiority-balance-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 107's seed test) — no MD5 bookkeeping,-// so the seed/no-clobber behavior is asserted directly.--const FILES = [- { filename: 'pipeline-editorial-interiority-balance.md', stageKey: 'pipeline-editorial-interiority-balance', body: '# Interiority balance\n\nshipped body\n', returnsJson: true },-];+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 142 — seed interiority-balance editorial stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- for (const { filename, body } of FILES) {- writeFileSync(join(refStagesDir, filename), body);- }- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- const stages = {};- for (const { stageKey, returnsJson } of FILES) {- stages[stageKey] = { name: stageKey, description: `${stageKey} desc`, model: 'default', returnsJson, variables: [] };- }- writeFileSync(refConfigPath, JSON.stringify({ stages }, null, 2) + '\n');- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-142-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();-- await expect(migration.up({ rootDir })).resolves.not.toThrow();-- for (const { filename, body } of FILES) {- expect(readFileSync(join(stagesDir, filename), 'utf8')).toBe(body);- }- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages['pipeline-editorial-interiority-balance']).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- for (const { filename } of FILES) {- writeFileSync(join(stagesDir, filename), customBody);- }- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [FILES[0].stageKey]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- for (const { filename } of FILES) {- expect(readFileSync(join(stagesDir, filename), 'utf8')).toBe(customBody);- }- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[FILES[0].stageKey]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- for (const { filename } of FILES) {- expect(existsSync(join(stagesDir, filename))).toBe(false);- }- });-- it('matches the live shipped stage-config keys + prompt files (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- for (const { stageKey, filename, returnsJson } of FILES) {- expect(refConfig.stages[stageKey], `stage-config missing ${stageKey}`).toBeTruthy();- expect(refConfig.stages[stageKey].returnsJson).toBe(returnsJson);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', filename))).toBe(true);- }- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-interiority-balance'], prefix: 'migration-142-' });});diff --git a/scripts/migrations/143-editorial-object-weight-proportionality-stage.test.js b/scripts/migrations/143-editorial-object-weight-proportionality-stage.test.jsindex 44e35dacf1..8aca203889 100644--- a/scripts/migrations/143-editorial-object-weight-proportionality-stage.test.js+++ b/scripts/migrations/143-editorial-object-weight-proportionality-stage.test.js@@ -1,101 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './143-editorial-object-weight-proportionality-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 142's seed test) — no MD5 bookkeeping,-// so the seed/no-clobber behavior is asserted directly.--const FILES = [- { filename: 'pipeline-editorial-object-weight-proportionality.md', stageKey: 'pipeline-editorial-object-weight-proportionality', body: '# Object weight proportionality\n\nshipped body\n', returnsJson: true },-];+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 143 — seed object weight-proportionality editorial stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- for (const { filename, body } of FILES) {- writeFileSync(join(refStagesDir, filename), body);- }- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- const stages = {};- for (const { stageKey, returnsJson } of FILES) {- stages[stageKey] = { name: stageKey, description: `${stageKey} desc`, model: 'default', returnsJson, variables: [] };- }- writeFileSync(refConfigPath, JSON.stringify({ stages }, null, 2) + '\n');- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-143-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();-- await expect(migration.up({ rootDir })).resolves.not.toThrow();-- for (const { filename, body } of FILES) {- expect(readFileSync(join(stagesDir, filename), 'utf8')).toBe(body);- }- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages['pipeline-editorial-object-weight-proportionality']).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- for (const { filename } of FILES) {- writeFileSync(join(stagesDir, filename), customBody);- }- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [FILES[0].stageKey]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- for (const { filename } of FILES) {- expect(readFileSync(join(stagesDir, filename), 'utf8')).toBe(customBody);- }- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[FILES[0].stageKey]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- for (const { filename } of FILES) {- expect(existsSync(join(stagesDir, filename))).toBe(false);- }- });-- it('matches the live shipped stage-config keys + prompt files (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- for (const { stageKey, filename, returnsJson } of FILES) {- expect(refConfig.stages[stageKey], `stage-config missing ${stageKey}`).toBeTruthy();- expect(refConfig.stages[stageKey].returnsJson).toBe(returnsJson);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', filename))).toBe(true);- }- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-object-weight-proportionality'], prefix: 'migration-143-' });});diff --git a/scripts/migrations/150-seed-comic-page-refine-render-stage.test.js b/scripts/migrations/150-seed-comic-page-refine-render-stage.test.jsindex 0593965a0f..4fa7254fb0 100644--- a/scripts/migrations/150-seed-comic-page-refine-render-stage.test.js+++ b/scripts/migrations/150-seed-comic-page-refine-render-stage.test.js@@ -1,105 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './150-seed-comic-page-refine-render-stage.js';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';-// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 091) — no MD5 bookkeeping, so the-// seed/no-clobber behavior is asserted directly here.-const FILENAME = 'pipeline-comic-page-refine-render.md';-const STAGE_KEY = 'pipeline-comic-page-refine-render';-const SHIPPED_BODY = '# Comic page refine render\n\nshipped body\n';--describe('migration 100 — seed comic-page refine-render stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), SHIPPED_BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({- stages: {- [STAGE_KEY]: { name: STAGE_KEY, description: `${STAGE_KEY} desc`, model: 'default', returnsJson: true, variables: [] },- },- }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-100-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();-- await expect(migration.up({ rootDir })).resolves.not.toThrow();-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(SHIPPED_BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ name: STAGE_KEY, returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- // .md untouched; config entry preserved verbatim.- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('merges the stage-config entry alongside pre-existing unrelated stages', async () => {- seedReference();- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { 'some-other-stage': { name: 'other' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages['some-other-stage']).toEqual({ name: 'other' });- expect(installed.stages[STAGE_KEY]).toMatchObject({ name: STAGE_KEY });- });-- it('does not throw when the data.reference sample is missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+describe('migration 150 — seed comic-page refine-render stage', () => {+ runSeedStageMigrationTests({ migration, stages: ['pipeline-comic-page-refine-render'], prefix: 'migration-150-' });});diff --git a/scripts/migrations/151-editorial-head-hopping-stage.test.js b/scripts/migrations/151-editorial-head-hopping-stage.test.jsindex 4bf7c4a203..4dd34afe78 100644--- a/scripts/migrations/151-editorial-head-hopping-stage.test.js+++ b/scripts/migrations/151-editorial-head-hopping-stage.test.js@@ -1,86 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './151-editorial-head-hopping-stage.js';+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';-// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 110) — no MD5 bookkeeping, so the-// seed / no-clobber behavior is asserted directly.--const FILENAME = 'pipeline-editorial-head-hopping.md';-const STAGE_KEY = 'pipeline-editorial-head-hopping';-const BODY = '# Head-hopping / POV discipline\n\nshipped body\n';--describe('migration 112 — seed editorial-head-hopping stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- writeFileSync(join(refStagesDir, FILENAME), BODY);- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- writeFileSync(- refConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, description: 'desc', model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',- );- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-112-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- writeFileSync(join(stagesDir, FILENAME), customBody);- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- expect(existsSync(join(stagesDir, FILENAME))).toBe(false);- });-- it('matches the live shipped stage-config key + prompt file (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- expect(refConfig.stages[STAGE_KEY], `stage-config missing ${STAGE_KEY}`).toBeTruthy();- expect(refConfig.stages[STAGE_KEY].returnsJson).toBe(true);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', FILENAME))).toBe(true);- });+describe('migration 151 — seed editorial-head-hopping stage', () => {+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-head-hopping'], prefix: 'migration-151-' });});diff --git a/scripts/migrations/168-editorial-premature-reveal-stage.test.js b/scripts/migrations/168-editorial-premature-reveal-stage.test.jsindex 5b90bbaffb..6c22a325a0 100644--- a/scripts/migrations/168-editorial-premature-reveal-stage.test.js+++ b/scripts/migrations/168-editorial-premature-reveal-stage.test.js@@ -1,101 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join, dirname } from 'path';-import { fileURLToPath } from 'url';+import { describe } from 'vitest';import migration from './168-editorial-premature-reveal-stage.js';--// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).-const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');--// First-shipment seed migration (mirrors 143's seed test) — no MD5 bookkeeping,-// so the seed/no-clobber behavior is asserted directly.--const FILES = [- { filename: 'pipeline-editorial-premature-reveal.md', stageKey: 'pipeline-editorial-premature-reveal', body: '# Premature reveal\n\nshipped body\n', returnsJson: true },-];+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 168 — seed premature-reveal editorial stage', () => {- let rootDir;- let stagesDir;- let refStagesDir;- let installedConfigPath;-- const seedReference = ({ withConfig = true } = {}) => {- for (const { filename, body } of FILES) {- writeFileSync(join(refStagesDir, filename), body);- }- if (withConfig) {- const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- const stages = {};- for (const { stageKey, returnsJson } of FILES) {- stages[stageKey] = { name: stageKey, description: `${stageKey} desc`, model: 'default', returnsJson, variables: [] };- }- writeFileSync(refConfigPath, JSON.stringify({ stages }, null, 2) + '\n');- }- };-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-168-'));- stagesDir = join(rootDir, 'data', 'prompts', 'stages');- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- mkdirSync(stagesDir, { recursive: true });- mkdirSync(refStagesDir, { recursive: true });- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {- seedReference();-- await expect(migration.up({ rootDir })).resolves.not.toThrow();-- for (const { filename, body } of FILES) {- expect(readFileSync(join(stagesDir, filename), 'utf8')).toBe(body);- }- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages['pipeline-editorial-premature-reveal']).toMatchObject({ returnsJson: true });- });-- it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {- seedReference();- const customBody = '# CUSTOMIZED — do not overwrite\n';- for (const { filename } of FILES) {- writeFileSync(join(stagesDir, filename), customBody);- }- writeFileSync(- installedConfigPath,- JSON.stringify({ stages: { [FILES[0].stageKey]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',- );-- await migration.up({ rootDir });-- for (const { filename } of FILES) {- expect(readFileSync(join(stagesDir, filename), 'utf8')).toBe(customBody);- }- const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));- expect(installed.stages[FILES[0].stageKey]).toEqual({ name: 'user-tuned', model: 'custom' });- });-- it('does not throw when the data.reference samples are missing', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- for (const { filename } of FILES) {- expect(existsSync(join(stagesDir, filename))).toBe(false);- }- });-- it('matches the live shipped stage-config keys + prompt files (drift catch)', () => {- const refConfig = JSON.parse(- readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),- );- for (const { stageKey, filename, returnsJson } of FILES) {- expect(refConfig.stages[stageKey], `stage-config missing ${stageKey}`).toBeTruthy();- expect(refConfig.stages[stageKey].returnsJson).toBe(returnsJson);- expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', filename))).toBe(true);- }- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-editorial-premature-reveal'], prefix: 'migration-168-' });});diff --git a/scripts/migrations/174-series-voice-discover-stage.test.js b/scripts/migrations/174-series-voice-discover-stage.test.jsindex acf9120a81..284fe0b23a 100644--- a/scripts/migrations/174-series-voice-discover-stage.test.js+++ b/scripts/migrations/174-series-voice-discover-stage.test.js@@ -1,87 +1,8 @@-import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';-import { tmpdir } from 'os';-import { join } from 'path';+import { describe } from 'vitest';import migration from './174-series-voice-discover-stage.js';--const STAGES = ['pipeline-series-voice-discover'];-const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));+import { runSeedStageMigrationTests } from './_seedStageTestHelpers.js';describe('migration 174 — seed series voice-discovery stage', () => {- let rootDir;- let installedStagesDir;- let installedConfigPath;- let refStagesDir;- let refConfigPath;-- beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-174-'));- refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');- refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');- mkdirSync(refStagesDir, { recursive: true });- for (const key of STAGES) {- writeFileSync(join(refStagesDir, `${key}.md`), `# ${key}\n\nbody for ${key}\n`);- }- const refConfig = { stages: {} };- for (const key of STAGES) {- refConfig.stages[key] = { name: key, model: 'default', returnsJson: true, variables: [] };- }- writeFileSync(refConfigPath, JSON.stringify(refConfig, null, 2) + '\n');-- installedStagesDir = join(rootDir, 'data', 'prompts', 'stages');- installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');- });-- afterEach(() => {- rmSync(rootDir, { recursive: true, force: true });- });-- it('seeds the prompt file + stage-config entry on a fresh install', async () => {- await migration.up({ rootDir });- for (const key of STAGES) {- expect(existsSync(join(installedStagesDir, `${key}.md`))).toBe(true);- }- const config = readJson(installedConfigPath);- for (const key of STAGES) {- expect(config.stages[key]).toBeTruthy();- }- });-- it('merges into an existing stage-config without clobbering other stages', async () => {- mkdirSync(installedStagesDir, { recursive: true });- writeFileSync(installedConfigPath, JSON.stringify({ stages: { 'pipeline-prose': { name: 'Prose' }, [STAGES[0]]: { name: 'CUSTOM', model: 'my-model' } } }, null, 2) + '\n');- await migration.up({ rootDir });- const config = readJson(installedConfigPath);- expect(config.stages['pipeline-prose']).toEqual({ name: 'Prose' });- expect(config.stages[STAGES[0]]).toEqual({ name: 'CUSTOM', model: 'my-model' });- for (const key of STAGES.slice(1)) {- expect(config.stages[key]).toBeTruthy();- }- });-- it('is idempotent and preserves a user-customized installed prompt', async () => {- mkdirSync(installedStagesDir, { recursive: true });- const customPath = join(installedStagesDir, 'pipeline-series-voice-discover.md');- writeFileSync(customPath, '# CUSTOM voice discovery\n');- await migration.up({ rootDir });- expect(readFileSync(customPath, 'utf-8')).toContain('CUSTOM');- // Second run is a clean no-op.- await migration.up({ rootDir });- expect(readFileSync(customPath, 'utf-8')).toContain('CUSTOM');- const config = readJson(installedConfigPath);- expect(Object.keys(config.stages).filter((k) => STAGES.includes(k))).toHaveLength(1);- });-- it('logs and skips when the data.reference template is missing (no crash)', async () => {- rmSync(join(refStagesDir, 'pipeline-series-voice-discover.md'));- await migration.up({ rootDir });- expect(existsSync(join(installedStagesDir, 'pipeline-series-voice-discover.md'))).toBe(false);- });-- it('logs and skips when the data.reference stage-config is missing (no crash)', async () => {- rmSync(refConfigPath);- await migration.up({ rootDir });- expect(existsSync(join(installedStagesDir, 'pipeline-series-voice-discover.md'))).toBe(true);- });+ runSeedStageMigrationTests({ migration, stages: ['pipeline-series-voice-discover'], prefix: 'migration-174-' });});