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: deep-freeze the seed-migration stages and fix two stale JSDoc claims

[._.]/ Adam Eivyd4e1228c5043
diff --git a/scripts/migrations/_seedStageHelpers.js b/scripts/migrations/_seedStageHelpers.js
index bf59b5c9a3..9a7086bd75 100644
--- a/scripts/migrations/_seedStageHelpers.js
+++ b/scripts/migrations/_seedStageHelpers.js
@@ -14,8 +14,8 @@
* leave a newly-shipped stage unseeded and the dependent check would throw
* "Stage not found" the first time it runs.
*
- * `makeSeedMigration(stageKey, { filename })` returns the `{ up }` object every
- * such migration exports as its default. The runner (`scripts/run-migrations.js`)
+ * `makeSeedMigration(stageKey, { filename })` returns the `{ up, stages }` object
+ * every such migration exports as its default. The runner (`scripts/run-migrations.js`)
* only ever calls `up()` and tracks applied migrations by filename — there is no
* rollback path, so no `down()` is emitted (it would be never-invoked dead code).
* The runner skips `_`-prefixed files, so this module is never imported as a
@@ -77,7 +77,9 @@ export function normalizeStageSpec(spec) {
export function makeSeedMigrations(stageSpecs) {
// 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));
+ // Deep: `up()` destructures `{ stageKey, filename }` out of the elements at
+ // call time, so freezing only the array would leave that mutable.
+ const stages = Object.freeze(stageSpecs.map((spec) => Object.freeze(normalizeStageSpec(spec))));
return {
stages,
async up({ rootDir }) {
@@ -154,7 +156,7 @@ export function makeSeedMigrations(stageSpecs) {
* Single-stage convenience wrapper over {@link makeSeedMigrations}.
* @param {string} stageKey - stage-config key, e.g. `pipeline-editorial-character-consistency`
* @param {{ filename?: string }} [opts] - template basename under `prompts/stages/` (defaults to `${stageKey}.md`)
- * @returns {{ up: (ctx: { rootDir: string }) => Promise<void> }}
+ * @returns {{ up: (ctx: { rootDir: string }) => Promise<void>, stages: ReadonlyArray<{ stageKey: string, filename: string }> }}
*/
export function makeSeedMigration(stageKey, { filename = `${stageKey}.md` } = {}) {
return makeSeedMigrations([{ stageKey, filename }]);
diff --git a/scripts/migrations/_seedStageHelpers.test.js b/scripts/migrations/_seedStageHelpers.test.js
index c2ac5de50e..6884720a64 100644
--- a/scripts/migrations/_seedStageHelpers.test.js
+++ b/scripts/migrations/_seedStageHelpers.test.js
@@ -48,11 +48,14 @@ describe('makeSeedMigration', () => {
expect(migration.stages).toEqual([{ stageKey: STAGE_KEY, filename: FILENAME }]);
});
- it('freezes the exposed stages so a consumer cannot mutate what up() seeds', () => {
+ it('deep-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.
+ // The freeze must reach the specs: up() destructures stageKey/filename out
+ // of them at call time, so a shallow freeze would leave that mutable.
const migration = makeSeedMigration(STAGE_KEY);
expect(Object.isFrozen(migration.stages)).toBe(true);
+ expect(Object.isFrozen(migration.stages[0])).toBe(true);
});
it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {