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([setup-data-import-drift-tables-from-migrations]): pin full drift baseline + harden sort per CLI review

[._.]/ Adam Eivydda0de135657
diff --git a/scripts/migrations/_lib.js b/scripts/migrations/_lib.js
index 5884d6b705..1b7ea669dd 100644
--- a/scripts/migrations/_lib.js
+++ b/scripts/migrations/_lib.js
@@ -262,9 +262,12 @@ export async function writeLayoutsDoc(path, doc) {
* `'_partials'`, matching the shape `collectDrift` in setup-data.js consumes.
*/
export async function buildPromptDriftTables(migrationsDir) {
+ // Sort by the leading migration number, not lexicographically — so the
+ // `current` (latest) hash selection holds even if a future migration name
+ // isn't zero-padded (e.g. `7-foo.js` must order before `60-foo.js`).
const candidates = (await readdir(migrationsDir))
.filter((f) => /^\d.*\.js$/.test(f) && !f.endsWith('.test.js'))
- .sort();
+ .sort((a, b) => (parseInt(a, 10) - parseInt(b, 10)) || a.localeCompare(b));
// key = `${subdir}/${filename}` so stages + _partials never collide.
const merged = new Map();
diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.js
index 37d00bb1e1..6074c642d1 100644
--- a/scripts/setup-data-drift.test.js
+++ b/scripts/setup-data-drift.test.js
@@ -3,9 +3,11 @@
* warn about pending migrations. Before this, setup-data.js hand-mirrored every
* migration's ACCEPTED_OLD_MD5 / NEW_SHIPPED_MD5 hashes — the spot most likely
* to drift out of sync. `buildPromptDriftTables` now sweeps those constants
- * straight from the migration files, so this test pins the swept result against
- * the known-good baseline: if a migration ships a new prompt hash without
- * exporting it (or exports a wrong one), the baseline assertion fails loudly.
+ * straight from the migration files, so this test pins the FULL swept result
+ * (every file's old-hash set + current hash) against the known-good baseline —
+ * the exact tables setup-data.js used to carry by hand. If a migration ships a
+ * new prompt hash without exporting it, drops an accepted-old hash, or exports
+ * a wrong one, the baseline assertion fails loudly.
*/
import { describe, it, expect } from 'vitest';
import { dirname, join } from 'path';
@@ -15,9 +17,32 @@ import { buildPromptDriftTables } from './migrations/_lib.js';
const migrationsDir = join(dirname(fileURLToPath(import.meta.url)), 'migrations');
-// The current shipped baseline for every migration-managed prompt. This is the
-// single source of truth the sweep must reproduce — keep it in lockstep with
-// the latest NEW_SHIPPED_MD5 a migration exports for each file.
+// The complete, independent baseline — transcribed from the hand-maintained
+// SHIPPED_PROMPT_OLD_MD5 / SHIPPED_PROMPT_NEW_MD5 tables this sweep replaced.
+// `pipeline-tv-script.md` is the one addition: it's a retired prompt (renamed
+// to teleplay) that the sweep surfaces from migration 003 and setup-data.js's
+// sample-existence filter drops downstream — so its presence here documents
+// that the sweep itself is expected to carry it.
+const EXPECTED_STAGE_OLD = {
+ 'pipeline-idea-expansion.md': ['1ee44cf95851ff8debf18729ebcd40b4', '1f3c5d077a5ef9a4b610335d5e3edd9c', '41facefbc0c0549d456bef9111f95ab9', 'aee25112b2c596f643b17c559b772c22', 'b5c47c94ffc74637983c95761ab0c66c'],
+ 'pipeline-prose.md': ['30ac30ec2b9d3e2a9eb869c181732cc6', 'bef1bc2767b78f585f2bd89f3d615130', 'bfea5aeeb471aae9749baee765b473a7', 'd1f8e3f1d214725b5aa67f309a81cd7d'],
+ 'pipeline-comic-script.md': ['133d200d069c2e8173b7c129eea58f53', '1e0af305c27d0c80c4b482d2ebcb4a0d', '40e5fdc1a1e68a7419b7dad936366c1a', 'beab031951859ca13579cdb9c4dbe769', 'e530fc76b89cedaef848ad7ec99c934c'],
+ 'pipeline-teleplay.md': ['1280ef6b1ad68fa44070ca7478ec2a5f', '2568e14beaa574d43f8018a5def51d04', '376f779f4687b598f1c92ca4e770fd5a', '3f6fecc25573ed054b47db392250034a'],
+ 'pipeline-season-episodes.md': ['6e349ad26bed8a0ccb042571f03f03eb', 'c4928e2a5f833358116b29d2d669888d'],
+ 'pipeline-arc-overview.md': ['6a3ecab43d1f46b7ef9aab6c69ea0326', 'd34d72b8e49ba303d38607845dd87f1c'],
+ 'pipeline-arc-verify.md': ['52e31abc93e3105176236fcaa5d1575a', 'ff56d8387162017e08d5d0491060ddd6'],
+ 'pipeline-volume-verify.md': ['03f3c874cb80e1c98abcf03168fa7a92', 'c6ea28e972ad6e229bafb2d602b4dda3'],
+ 'pipeline-arc-resolve.md': ['87bc5c01f1a8a97b681727a38b05edc6', '8e348f3d1894382889f9f0ee7d5c6792', 'a8677bbe1eb38f871fb152a5b0fec7c6'],
+ 'pipeline-extract-scenes.md': ['59fa5ee305ce53d91eb15224d8b546d3'],
+ 'writers-room-places.md': ['24a33628cc94d80fa5ca60831d973daf', '7f1f80eb63d67a21161994cde115045e'],
+ 'universe-character-expand.md': ['ef109eb8e12ddb664c11c790271b5139'],
+ 'story-builder-idea-expand.md': ['778c86e2caa120856c36e4d5a4da3355', 'a23939626a226f7420cebfb45d47950c'],
+ 'pipeline-editorial-analysis.md': ['14d9879697c66d51830cc798040d5369'],
+ 'pipeline-manuscript-completeness.md': ['4f2b95778aed85f5fc461d71eb461b79', 'e6858c74ab2cead752d388e3f428406c'],
+ 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee'],
+ 'cos-agent-briefing.md': ['181b26838e526427173e4dccfc884d01', '3e1ca7f7b14b799f89a193c568003624', '699d053875472df455258724a0162bd5', '9bcd3a0167dd4aed7cfff7f404494dfb', 'af73fd50d6f29d561772474c12346e53', 'd761133753da290a0c02eca1c87709e4'],
+ 'pipeline-tv-script.md': ['3f6fecc25573ed054b47db392250034a'],
+};
const EXPECTED_STAGE_NEW = {
'pipeline-idea-expansion.md': '49a208628290543ba2607a5ed48fdc8c',
'pipeline-prose.md': '84523d531eeafa60959c65c553b2563f',
@@ -36,46 +61,34 @@ const EXPECTED_STAGE_NEW = {
'pipeline-editorial-analysis.md': 'daeb02bd54b0c099b21af659c6298cfe',
'pipeline-manuscript-completeness.md': '1ee5ac936fbf1d365e0eaea99bcf1e77',
'pipeline-manuscript-fix.md': 'c88a56304eb5e290ae0de9dadd20b310',
+ 'pipeline-tv-script.md': '376f779f4687b598f1c92ca4e770fd5a',
+};
+const EXPECTED_PARTIAL_OLD = {
+ 'bible-deference.md': ['218f0e85643609ed85a12b1ccc7b5a8d'],
+};
+const EXPECTED_PARTIAL_NEW = {
+ 'bible-deference.md': 'a4681348c27776e414acf6e0be566a99',
};
+// Compare a swept oldMap to a baseline with each hash list order-normalized.
+const sortValues = (map) =>
+ Object.fromEntries(Object.entries(map).map(([k, v]) => [k, [...v].sort()]));
+
describe('buildPromptDriftTables', () => {
- it('sweeps the current shipped hash for every migration-managed stage prompt', async () => {
+ it('reproduces the full stage drift table the hand-mirror used to carry', async () => {
const { stages } = await buildPromptDriftTables(migrationsDir);
- for (const [file, hash] of Object.entries(EXPECTED_STAGE_NEW)) {
- expect(stages.newMap[file], `${file} current hash`).toBe(hash);
- }
+ expect(stages.newMap).toEqual(EXPECTED_STAGE_NEW);
+ expect(sortValues(stages.oldMap)).toEqual(sortValues(EXPECTED_STAGE_OLD));
+ expect(stages.files.sort()).toEqual(Object.keys(EXPECTED_STAGE_NEW).sort());
});
it('keys partial fragments under the _partials subdir, not stages', async () => {
- const tables = await buildPromptDriftTables(migrationsDir);
+ const { stages, _partials } = await buildPromptDriftTables(migrationsDir);
// bible-deference.md is a _partials fragment (migration 022 declares it via
// DRIFT_SUBDIRS) — it must land in the partial table, never the stage table.
- expect(tables._partials.newMap['bible-deference.md']).toBe('a4681348c27776e414acf6e0be566a99');
- expect(tables._partials.oldMap['bible-deference.md']).toEqual(['218f0e85643609ed85a12b1ccc7b5a8d']);
- expect(tables.stages.newMap['bible-deference.md']).toBeUndefined();
- });
-
- it('unions the accepted-old hashes across a multi-migration lineage', async () => {
- const { stages } = await buildPromptDriftTables(migrationsDir);
- // pipeline-idea-expansion.md evolved through 003 → 004 → 025 → 054(+fence).
- // Every intermediate shipped hash must be auto-updatable to the latest.
- expect(stages.oldMap['pipeline-idea-expansion.md'].sort()).toEqual([
- '1ee44cf95851ff8debf18729ebcd40b4',
- '1f3c5d077a5ef9a4b610335d5e3edd9c',
- '41facefbc0c0549d456bef9111f95ab9',
- 'aee25112b2c596f643b17c559b772c22',
- 'b5c47c94ffc74637983c95761ab0c66c',
- ]);
- });
-
- it('covers a prompt whose lineage spans two custom-export migrations', async () => {
- const { stages } = await buildPromptDriftTables(migrationsDir);
- // writers-room-places.md's hashes come from migrations 007 + 022 — both of
- // which export the standard constants only because this feature required it.
- expect(stages.oldMap['writers-room-places.md'].sort()).toEqual([
- '24a33628cc94d80fa5ca60831d973daf',
- '7f1f80eb63d67a21161994cde115045e',
- ]);
+ expect(_partials.newMap).toEqual(EXPECTED_PARTIAL_NEW);
+ expect(sortValues(_partials.oldMap)).toEqual(sortValues(EXPECTED_PARTIAL_OLD));
+ expect(stages.newMap['bible-deference.md']).toBeUndefined();
});
it('never lists the current hash among its own accepted-old set', async () => {
diff --git a/scripts/setup-data.js b/scripts/setup-data.js
index 97a8a98229..811245b2d7 100644
--- a/scripts/setup-data.js
+++ b/scripts/setup-data.js
@@ -139,9 +139,9 @@ for (const { relPath, mergeKey } of JSON_MERGE_TARGETS) {
// managed by a migration are checked, so prompts with no migration counterpart
// (e.g. cd-evaluate.md) never produce misleading warnings.
const driftTables = await buildPromptDriftTables(join(__dirname, 'migrations'));
-const EMPTY_DRIFT_TABLE = { oldMap: {}, newMap: {}, files: [] };
-const stageTable = driftTables.stages || EMPTY_DRIFT_TABLE;
-const partialTable = driftTables._partials || EMPTY_DRIFT_TABLE;
+const emptyDriftTable = () => ({ oldMap: {}, newMap: {}, files: [] });
+const stageTable = driftTables.stages || emptyDriftTable();
+const partialTable = driftTables._partials || emptyDriftTable();
// Walk one directory's worth of shipped prompt files against a hash table
// and partition them into auto-updatable (still on a known old hash) vs.