Skip to content

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

test: pin the seed-migration object surface and freeze its stages list

[._.]/ Adam Eivydf351dfcae96
diff --git a/scripts/migrations/_seedStageHelpers.js b/scripts/migrations/_seedStageHelpers.js
index d884d68fd0..bf59b5c9a3 100644
--- a/scripts/migrations/_seedStageHelpers.js
+++ b/scripts/migrations/_seedStageHelpers.js
@@ -2,7 +2,7 @@
* Shared scaffolding for first-shipment "seed a pipeline stage" migrations (#1838).
*
* Companion to `./_lib.js` (hash-driven prompt-*replace*) — this one covers the
- * *seed-a-brand-new-stage* family: ~44 near-identical migrations (e.g.
+ * *seed-a-brand-new-stage* family: ~56 near-identical migrations (e.g.
* `130-editorial-character-consistency-stage.js`) that each
* 1) copy a `.md` template from `data.reference/prompts/stages/` into
* `data/prompts/stages/` when missing (never clobbering a customized file), and
@@ -75,7 +75,9 @@ export function normalizeStageSpec(spec) {
* @returns {{ up: (ctx: { rootDir: string }) => Promise<void>, stages: Array<{ stageKey: string, filename: string }> }}
*/
export function makeSeedMigrations(stageSpecs) {
- const stages = stageSpecs.map(normalizeStageSpec);
+ // Frozen because `up()` closes over this same array on an ESM module-cached
+ // singleton — a consumer mutating it would silently change what gets seeded.
+ const stages = Object.freeze(stageSpecs.map(normalizeStageSpec));
return {
stages,
async up({ rootDir }) {
diff --git a/scripts/migrations/_seedStageHelpers.test.js b/scripts/migrations/_seedStageHelpers.test.js
index 008ef470a8..c2ac5de50e 100644
--- a/scripts/migrations/_seedStageHelpers.test.js
+++ b/scripts/migrations/_seedStageHelpers.test.js
@@ -39,10 +39,20 @@ describe('makeSeedMigration', () => {
vi.restoreAllMocks();
});
- it('returns an object exposing only an async up() (no down — runner has no rollback)', () => {
+ it('returns an object exposing up() and the normalized stages list (no down — runner has no rollback)', () => {
const migration = makeSeedMigration(STAGE_KEY);
expect(typeof migration.up).toBe('function');
- expect(migration.down).toBeUndefined();
+ // Pin the whole surface rather than spot-checking `down`: this subsumes the
+ // no-rollback assertion and catches any future accidental addition.
+ expect(Object.keys(migration).sort()).toEqual(['stages', 'up']);
+ expect(migration.stages).toEqual([{ stageKey: STAGE_KEY, filename: FILENAME }]);
+ });
+
+ it('freezes the exposed stages so a consumer cannot mutate what up() seeds', () => {
+ // `stages` is the same array `up()` closes over on an ESM module-cached
+ // singleton — mutating it would silently change what the migration seeds.
+ const migration = makeSeedMigration(STAGE_KEY);
+ expect(Object.isFrozen(migration.stages)).toBe(true);
});
it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {
diff --git a/scripts/migrations/_seedStageTestHelpers.js b/scripts/migrations/_seedStageTestHelpers.js
index e5bee5069e..ffc22f4be0 100644
--- a/scripts/migrations/_seedStageTestHelpers.js
+++ b/scripts/migrations/_seedStageTestHelpers.js
@@ -145,7 +145,7 @@ export function runSeedStageMigrationTests({ migration, stages, prefix }) {
// Tuned entry preserved verbatim; the remaining entries still get added.
expect(installed.stages[specs[0].stageKey]).toEqual(tuned);
// Empty for a single-stage migration — the tuned-entry assertion above is the
- // whole point there. Most of the ~59 makeSeedMigration(s) migrations this
+ // whole point there. Most of the ~56 makeSeedMigration(s) migrations this
// helper could cover are single-stage, so don't read this loop as coverage.
for (const { stageKey } of specs.slice(1)) {
expect(config.stages[stageKey], `data.reference stage-config missing entry: ${stageKey}`).toBeTruthy();