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
/**
* Contract test for the prompt-drift sweep that scripts/setup-data.js uses to
* 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 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';
import { fileURLToPath } from 'url';
import { buildPromptDriftTables } from './migrations/_lib.js';
const migrationsDir = join(dirname(fileURLToPath(import.meta.url)), 'migrations');
// 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 = {
'cd-evaluate.md': ['c986613edbb595cece674403db0f069d'],
'pipeline-idea-expansion.md': ['1ee44cf95851ff8debf18729ebcd40b4', '1f3c5d077a5ef9a4b610335d5e3edd9c', '41facefbc0c0549d456bef9111f95ab9', '49a208628290543ba2607a5ed48fdc8c', '93e9552c6662811e597a97296f3776a4', 'aee25112b2c596f643b17c559b772c22', 'b5c47c94ffc74637983c95761ab0c66c', 'c50f016639d41cd8244f5ff13429f997', 'c5b2e719e232a281b3829a5348cb29c1', 'd6fa86a435f978336661dcabca67258f'],
'pipeline-prose.md': ['30ac30ec2b9d3e2a9eb869c181732cc6', '84523d531eeafa60959c65c553b2563f', 'bef1bc2767b78f585f2bd89f3d615130', 'bfea5aeeb471aae9749baee765b473a7', 'd1f8e3f1d214725b5aa67f309a81cd7d', '25e3d58c2741bd98acd5d08ba70d8a5e', '430d38ed2da59e0d4212e65edc499a74'],
'writers-room-continue.md': ['93bfe80543ceca39842201a78b8393fa', '67663696c97ebaeb23de25f7410cfdd4'],
'pipeline-comic-script.md': ['133d200d069c2e8173b7c129eea58f53', '1e0af305c27d0c80c4b482d2ebcb4a0d', '40e5fdc1a1e68a7419b7dad936366c1a', '7c05ecde539f04c9fa91e87543057204', '9fe2451b573fc60eb6c971e1b8808ef3', 'a4303016c34b65e4b0e641fe71252de3', 'beab031951859ca13579cdb9c4dbe769', 'dea7d497d1cb38e7574f236f4ff8e644', 'e530fc76b89cedaef848ad7ec99c934c', 'e9ee70bf18888492edada6633cd9928a'],
'pipeline-teleplay.md': ['1280ef6b1ad68fa44070ca7478ec2a5f', '2568e14beaa574d43f8018a5def51d04', '376f779f4687b598f1c92ca4e770fd5a', '3f6fecc25573ed054b47db392250034a', 'afa4215330bf856429d70d7e2f856605'],
'pipeline-season-episodes.md': ['6e349ad26bed8a0ccb042571f03f03eb', 'c4928e2a5f833358116b29d2d669888d', '50c68a29c3ebc275db3095d06bd87100', 'a88e8e78a949b7aaf500d03314e2ea0b', '7c24df53c097c2525a52bfb766239647'],
'pipeline-arc-overview.md': ['6a3ecab43d1f46b7ef9aab6c69ea0326', 'd34d72b8e49ba303d38607845dd87f1c', '0a1f6ffa6908522e3690c5e9e53a6ee0', '612f8b04950e2ff26dd350dd76a062fe', '74d6c26548660d85fc345b2099c63b6c', '648e11352cd1565aee490de1f662bef0', '5ed760caaf3cf88916ec28b220e2f590'],
'pipeline-arc-verify.md': ['4b60a322e35b536405d0fbf543580562', '52e31abc93e3105176236fcaa5d1575a', 'ff56d8387162017e08d5d0491060ddd6', '36aa70cdfc25d7549573a4d556e7702c', '83347e7d923580a3062033ab39b3c14b', '68f6956d7e09ebdb3870d8726b1b2a7a', '9f32e91bd33b97d30e1cbb2e697f4fc3', '90712f66ec68061ebed2147044e5baee', 'a397f158fd9c0dca1c8dbe62df253f70', 'f09e81655ec897c74a2fae68ad31b9c4'],
'importer-issue-proposal.md': ['a6838832f8289932836db84ee565b870'],
'pipeline-volume-verify.md': ['03f3c874cb80e1c98abcf03168fa7a92', 'c6ea28e972ad6e229bafb2d602b4dda3', '49458d36700cb94e34806d536ffe2940', '3e8a8f00d5faaee9d8e08a49d801b812', '9c0839d7fe1760c0891464afd4a3b8fd'],
'pipeline-arc-resolve.md': ['3f5ef41212890889811e4509a131c4e9', '122950b9f5ce84708ac1510ef13b1bce', '0611db539437083621e19bb88b005e8d', '0787128babf3c4c50e2f2cdb60214030', '5b340885c6e8f8afc63424d6b5bc7eb7', '87bc5c01f1a8a97b681727a38b05edc6', '8bb134554c122d1583c479ab3010e53d', '8e348f3d1894382889f9f0ee7d5c6792', '96f73a7e90526d65ef2bb100fb1cd4bf', 'a8677bbe1eb38f871fb152a5b0fec7c6', 'cc27b4da1d1a13c35e35d1c2d6183815', '31eca76b68f40de1b93734fe9bc9f4bb', '17fbb066d7957dc2e345df1795bb0d9d', 'ebd85d3a0b5949f16877c25ca498cce9', '2349bce80e9df8caafa391a6106327b6', 'aa2e463ebe0857859d79aa0c6ccb0256', '638b988c84b3e5599f7a2ce09fa149ce', '56926d795bd31f7e05e6bbbc646ecf9f'],
'pipeline-script-verify.md': ['cec35763c134fcac8bd4e9669ab5505a', 'ed6c8101644cfe56a100eb6bfe3587f3'],
'pipeline-extract-scenes.md': ['59fa5ee305ce53d91eb15224d8b546d3', 'c51fb208568d0d903eb43b437478b0ba'],
'writers-room-places.md': ['24a33628cc94d80fa5ca60831d973daf', '7f1f80eb63d67a21161994cde115045e', 'a7f68e51dd6b4421d20f5bd9d855d9b4'],
'writers-room-characters.md': ['cdd99c7a3ef92bf798f30fa2fb4465f1', '4b19f6538ff3a602007ef8e32c8e5047'],
'writers-room-objects.md': ['1115d2d7d2e52e1e10c38325b88a4d94'],
'catalog-ideas-scenes-concepts.md': ['243074821ebc58eec63e26d284101b29', '98aa063cec8ad5c0e017dbc7bc949054'],
'writers-room-evaluate.md': ['d3374472820df264731f435141e05270', 'd3b2b40bcabc9ca690fa67b69d64d628', '286e9498966187ed74126680da4a6a54'],
'universe-character-expand.md': ['ef109eb8e12ddb664c11c790271b5139', '67b6e73ed47f318451a730088b4cff14', '177b6e4e8bdf445308cf8ac423cd5ad8', '924fe8836f3014873d1789e98e997db2'],
'story-builder-idea-expand.md': ['778c86e2caa120856c36e4d5a4da3355', 'a23939626a226f7420cebfb45d47950c'],
'pipeline-editorial-analysis.md': ['14d9879697c66d51830cc798040d5369'],
'pipeline-manuscript-completeness.md': ['fd26f928c33803c12878a1bfb8561ece', '4f2b95778aed85f5fc461d71eb461b79', 'e6858c74ab2cead752d388e3f428406c', '1ee5ac936fbf1d365e0eaea99bcf1e77', 'cec8faeb75dfff74e41b8221145c2e92'],
'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee', '87c6e47030df07b37ace44d2a15372cf', 'c88a56304eb5e290ae0de9dadd20b310', '88199bf7b5b50155bd2e1624bd920ebd'],
'cos-agent-briefing.md': ['181b26838e526427173e4dccfc884d01', '3e1ca7f7b14b799f89a193c568003624', '699d053875472df455258724a0162bd5', '9bcd3a0167dd4aed7cfff7f404494dfb', 'af73fd50d6f29d561772474c12346e53', 'd761133753da290a0c02eca1c87709e4', 'dccb392a43cbd3dac900fee12c31619a'],
'pipeline-editorial-telling-emotion.md': ['2c5c33709732fe7ffa319d32b8755354'],
'pipeline-editorial-chekhov.md': ['21246b605f442f8c749fc2835bd293b5', 'bfacbf343ba2b9a3f6037bb45b94e1bb'],
'pipeline-editorial-on-the-nose.md': ['48182b49149e6b5829fbed71b3ffc242', '8d9038a2b197728f6edeedb84699f364'],
'pipeline-tv-script.md': ['3f6fecc25573ed054b47db392250034a'],
'cd-treatment.md': ['4da071646deff0001473502a7c4b5252', '1de973575a772db0544bbeda2ba5df77', '2ffa482e7bfb6fe8b7224505fedbf712', '16d0ef6a7fd2533719a846019122ebee', '95b7685690ecfee4f682b0293b790277', 'd940eadfb406ce584f0e244032f33382'],
'cd-plan.md': ['02354df62fe776704669d3ff06f346e4', '41a61590896d1327df2c6915557361de', '3ce871196a8fd04781b71b6780e89c86', '0768d6809645c2c1fe73cacae9740fe9', 'ef0d96f6ebde43af6c4579969d31cfb7'],
'pipeline-series-generate.md': ['bc72731124a2bd6304362f4402c6305d', '21352c21ed6d4edb7a4b7c32704eff55'],
'pipeline-character-foundation.md': ['f1c0b75a8161c0bc7f26752d148a5c1c', 'cda34127b40754ddbcc8544e3d82572b', 'd6c449c06de73a0868141c899b26e52c', '04419e382f3b46ed92bfaaa1d4f39e13', 'b7d2bac347e11171606f4c6acfcd32e1'],
'pipeline-judge-foundation.md': ['75714f0e41c77ff5c8b9623cb4fb0a25', '74c0244e641dcf7a73e9c83123ebdee9', '4c0bd349ff4d329048c9f4ac068745d4', 'edf7850d0c724c63761bc9fb667227d9', '02a8e9215ba534b333f3a29f11f3ac4f', 'e44b6c50d741bbd21fc86f481684c410'],
'pipeline-observer.md': ['f3dc51ac077050a887c2161ee7438181'],
'pipeline-self-improve.md': ['ed0b0df42e0690d515b8dd88911931e4'],
'fableloom-editorial-remediate.md': ['d73329e2341e7bea9935a96043ed045f', 'c0cce5cfe63ec4e94047415bbe83881b'],
'fableloom-weave-episode.md': ['1fea11b8c4269008561ac22a30494d46', '1b27f5b0073a304c21079aa6e2c71447', '4c9454d1537c4ebb3becbfa04fae3ed8', '18a442e39b973e4074a0d595928a665d', '990cdecf9e46fa049ae4aae27e3b172d', 'e0f8d864caa8746912b56cd567f1c09d', 'b4d363db94fd8a9928fa977745c76ff9', 'abea2442af2be2039b70deee4919c00e'],
'fableloom-branch-node.md': ['f558e4804b056a5961af1ea74fdef2ba', '6279b1c9912c300363a727245d22fe84', 'c14e2b9c435e43a8c3b134a62cd66d08', 'e5005826c4577623ba362a0292741c7c', 'ff5d40b3090c775fc9c1f48c2ea96bbd'],
'fableloom-play-turn.md': ['bb33dc9bc483668d88196ca972d5f364'],
'fableloom-feedback-episode.md': ['43d1525fcedce99b933ae5b003516a36', 'd09bb405478d24c294b0c658ef365cd1', '9ff21b47c4251585da9500c306d91a28'],
'fableloom-review.md': ['2802f269f246e00ec5a8937637d42de6'],
'fableloom-outline-episode.md': ['3f5144103b2ab6203fa071ff5026251b', '513b2b5b8fa98766852cdde7b87198c9', '820b8c157c1977b34eb317e44236519e', '2ff6fb72777ff0c6fc70f3afd0ddfd53'],
'fableloom-review-episode-outline.md': ['96d631104155ff11be08bcc5144cca1c', '8154b4c289b10268df8fd3c625bcdac2', '0f549ed25dea8566ce2d3c515968783b'],
'fableloom-review-series-plan.md': ['1c1ab552f6f6a4d9d51f1d3bacd89122', '588c82fafd733581490f24cb6fb4bfa7', 'd7d3b306c82cea4d7f13a78512a46948'],
'fableloom-feedback-series-plan.md': ['6c4f6c846acc6186eaa8da297080b9d9', '2d1b40041223baa02a1517a102f103c2', 'c56a3de3776cf7ef8ba16782f0691144'],
'fableloom-review-playthroughs.md': ['27843c9a77dc9dcfb8a9b12102253541'],
'fableloom-review-series-teleplay.md': ['fc87fe58f599be451d245ce4f26d9691'],
'fableloom-plan-shots.md': ['4cf0fb96d4e9a17a8ae8285ec134f37f'],
'fableloom-review-shots.md': ['699ba1189f67338728b74834269759a9'],
'fableloom-generate-series-plan.md': ['2591cf4ca6cc160765f029fcc497dc35', '27336d8c64e6193aecd1ba697f52315e'],
'manuscript-reformat.md': ['4df6381d5c685c683a518326b7908e18'],
'pipeline-editorial-appearance-continuity.md': ['25ccc731f1596a99d21600919896a8e3'],
'pipeline-editorial-endings-cliffhanger.md': ['3ef5e6fbc160f9f33902ab22d9284281'],
'pipeline-editorial-eyeline-match.md': ['5d0b8d0d4605225d208786165e26abb4'],
'pipeline-editorial-head-hopping.md': ['460e6449c4f1daec815b9ff0a6573f97'],
'pipeline-editorial-object-weight-proportionality.md': ['89f6f6c6856ebcf0183b7760d71a6898', 'c1b7b58e0255c86b6ba5cece4330ac48', 'f4f91a4ea55a9fd89eaebc70074a89ec'],
'pipeline-editorial-reaction-proportionality.md': ['38ca1b6edaa55c8989e22e7ffdbd76c7', '8787e6e40f8bb46067b8303b866c7ff8'],
'pipeline-editorial-timeline-contradiction.md': ['f39272a486d4cc031ebb7b3b8fc01ed3'],
'pipeline-editorial-unmodeled-names.md': ['2e562a414726b5b412537ad4ecbdbff5', '50029186d6009d50c3850f3f4b90a5d6', '9b9732f729c96dd7154175b77755fdd2', 'd34323ee9bf05fffc3584ad9d91146bd'],
'pipeline-editorial-world-cost-free-power.md': ['42db5691fa6e4b2db9a146a821ed1fe7'],
'pipeline-editorial-world-unforeshadowed-solution.md': ['9a23180e49fbac1699c846ced1625575'],
'pipeline-pov-rewrite.md': ['cd073c8dbca2bf25eea07b6103e27d81'],
'story-builder-reader-map-refine.md': ['befd154bb319c221f16ca357a23f1aa7'],
'story-builder-reader-map.md': ['af375710531a34b8fe265b425be42b3d'],
'pipeline-editorial-character-consistency.md': ['69bbee3a1bb126b2675d8b00f5aef48c'],
'pipeline-editorial-secondary-arc.md': ['6ad9eb7c4969d8baeb2c8c38d8f6695e', '8a96ce93f6592fed3d30e221497739a4'],
'pipeline-editorial-arc-transitions.md': ['4c297e92df472965be8641f8b9ce9853', '72e27707f0dc82eab84eed74e9707587'],
'pipeline-editorial-arc-regression.md': ['85b15c9e913fe8a436d407f1562a2b10'],
'pipeline-editorial-climax-agency.md': ['1bca84f9a0b7cde84e20e43702a12ffa', '55c25664b9904806146f92cc739d7208', 'f6611ff22e36d6738b3b4faa9c1310df'],
'pipeline-editorial-plot-structure.md': ['400d829dd291753a299fa08d6afbe561'],
};
const EXPECTED_STAGE_NEW = {
'cd-evaluate.md': 'a86de29e186581d3508662569c8acbf6',
'pipeline-idea-expansion.md': 'a032e4a724251ed3e3495d33c4dbab8e',
'pipeline-prose.md': '4cb3ef48309f3673570cf80e4d544b54',
'writers-room-continue.md': '458dc5ff4732befc1fb90890bdc885c2',
'pipeline-comic-script.md': '49af30c05f008b20f6998a0f113f7d87',
'pipeline-teleplay.md': '2ea9974ac3803658b2314db1f5818b77',
'pipeline-season-episodes.md': 'b3fc07d785599b5a4859af8bed3c1d4e',
'pipeline-arc-overview.md': '901557b9f146a2d279ce2e81bda24d73',
'pipeline-arc-verify.md': '090920d816beef8dfc12ee6152511456',
'importer-issue-proposal.md': '9ba2ff965fba61efb85a3568bb530055',
'pipeline-volume-verify.md': '6f9b4ba4d9dd9a51a1032c7f0ca90405',
'pipeline-arc-resolve.md': '5fb659e459a296b7d378d7711f4b78cd',
'pipeline-script-verify.md': '722c62462d05462603cf67ca0ed1dee8',
'pipeline-extract-scenes.md': '9f404b0c4721b23932a6d2dcfc1fba43',
'writers-room-places.md': '5d323f7aea4c2658e7e29afae2bdb7a4',
'writers-room-characters.md': '73ec5bbfdad5c62ec5d5c30f0940febf',
'writers-room-objects.md': '10efde7fbb46b28223db03f38e7043e4',
'catalog-ideas-scenes-concepts.md': 'e6cce39c76689ea9c5233f233cd0f153',
'writers-room-evaluate.md': '995cfd92061b55730b0e081998e96f84',
'cos-agent-briefing.md': 'a01c81d3a7f4ac0ca9e8d5137735c0e3',
'universe-character-expand.md': '961b73ba6e50df5d49f0cc76505e50bd',
'story-builder-idea-expand.md': 'c12d76fefaaded2838023065bfc94bb0',
'pipeline-editorial-analysis.md': 'daeb02bd54b0c099b21af659c6298cfe',
'pipeline-manuscript-completeness.md': 'a08a7aaea9b57dcf12311505150672cd',
'pipeline-manuscript-fix.md': 'e2baaf0f2f53c8aa1e934a428c0ca583',
'pipeline-editorial-telling-emotion.md': '871f7e8bea2a2d95f28875ab45a318e2',
'pipeline-editorial-chekhov.md': '1f8a1696b5e4f476051dc5b2e5737db9',
'pipeline-editorial-on-the-nose.md': 'e5786fb019e5bf19c7aa6ed0c8b35cda',
'pipeline-tv-script.md': '376f779f4687b598f1c92ca4e770fd5a',
'cd-treatment.md': '16c5ce4a199d8efbf80016424315beb6',
'cd-plan.md': '8dac4102dbbaee05f2f23f37c7e80782',
'pipeline-series-generate.md': '136a21435aba2b2b212883750040b986',
'pipeline-character-foundation.md': 'c606061954b23a9957c68dd068b54dc4',
'pipeline-judge-foundation.md': 'd4abf4ddafbf84a2903e6d70d14adea1',
'pipeline-observer.md': '29e0212d2252b1be3278f20e2959eb8e',
'pipeline-self-improve.md': '95b378832ff78e5976a6a63fcf328090',
'fableloom-editorial-remediate.md': '75f23d18fdf3b4ca3f329db8c61aec9d',
'fableloom-weave-episode.md': '94f22c0807924dadf151341c30720c71',
'fableloom-branch-node.md': '39a208c8cc593d0531af50760e3cf0da',
'fableloom-play-turn.md': 'e35ad91aae263e3adf28d1e047a46661',
'fableloom-feedback-episode.md': '1aaa6f17acad6a3215e48dcce14e8670',
'fableloom-review.md': 'c26a641f6d0530caef7d1186c3b09937',
'fableloom-outline-episode.md': '76f5211b851de7a0a23d9c11c5969b25',
'fableloom-review-episode-outline.md': '3e548d8de54dd23312a6f1024910fedc',
'fableloom-review-series-plan.md': 'd82ff6df1d41c3e53fb0cc7ea49f8dc5',
'fableloom-feedback-series-plan.md': 'ece17ecf3ee0d6018f3ca350794d8d52',
'fableloom-review-playthroughs.md': 'c24c3799c8ef9050c16a3fa4b56920e2',
'fableloom-review-series-teleplay.md': '10a3289dd0824539f7ccbcd4a579c865',
'fableloom-plan-shots.md': '9b1cd4b406ee327d6dc3fcbd57b48483',
'fableloom-review-shots.md': '8cf5fe685cc5f75537caddea1d272a00',
'fableloom-generate-series-plan.md': 'ab912a52879d8ce78e9998dec19ddaa8',
'manuscript-reformat.md': '1a02cf3ac59b5c253359357608c1c4ad',
'pipeline-editorial-appearance-continuity.md': '8ef03aa3ed15557febe85d7ee66b6cc6',
'pipeline-editorial-endings-cliffhanger.md': 'deaebfa026d40a6e576479ecc4f1e98b',
'pipeline-editorial-eyeline-match.md': '7c66926cbf8f7174ca17043e1f2e2251',
'pipeline-editorial-head-hopping.md': '00e596e9dea15b3154a6a9f3509e90a5',
'pipeline-editorial-object-weight-proportionality.md': '761890e3dcdc2cd828ec2be2a5f9cb82',
'pipeline-editorial-reaction-proportionality.md': 'b15471388a184d6f805e6dfac76fb164',
'pipeline-editorial-timeline-contradiction.md': '2d797a9fa3b55f4c9f85c22cc0baa547',
'pipeline-editorial-unmodeled-names.md': '6b35274e08ea9b5727c42f6ef6653cd5',
'pipeline-editorial-world-cost-free-power.md': '2b761163f63c2e4fbe8dc6d7f6e577f7',
'pipeline-editorial-world-unforeshadowed-solution.md': '09d5997e8c9ea77a5cf1bf446ef211f1',
'pipeline-pov-rewrite.md': 'eedcc03aaaf7e22e7726491f08d52974',
'story-builder-reader-map-refine.md': 'd8f02936a237a9e4e964d7250a118e17',
'story-builder-reader-map.md': '21929c9f7a7bd54c17c9dfdf00213987',
'pipeline-editorial-character-consistency.md': 'bbefd9b033cc7830752acf87722659a0',
'pipeline-editorial-secondary-arc.md': 'a9bd4dd9a06bc571f0363e0031d9a5d7',
'pipeline-editorial-arc-transitions.md': '46cb5444f41d05fb7bdbc219d62619b2',
'pipeline-editorial-arc-regression.md': '8e34b3a84cd7f948592a2a94b28caee4',
'pipeline-editorial-climax-agency.md': '255ad29214f48e6dd1c17adbb5887478',
'pipeline-editorial-plot-structure.md': '2a4fe67b7b5e128314c385bb458decf2',
};
const EXPECTED_PARTIAL_OLD = {
'bible-deference.md': ['218f0e85643609ed85a12b1ccc7b5a8d'],
'craft-anti-patterns.md': ['bd0149bf1a5c721e65e053dad8e536d3'],
};
const EXPECTED_PARTIAL_NEW = {
'bible-deference.md': 'a4681348c27776e414acf6e0be566a99',
'craft-anti-patterns.md': 'f34e75f19ac4e41aa0533a0abcb38a2a',
};
// 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()]));
// A deep-equal on 28 keys reports only "expected { …(28) } to deeply equal
// { …(28) }", which reads as an unrelated regression on whatever PR happens to
// inherit it — three PRs were triaged past this break before it was traced to
// `main`. Name the files and hashes that actually moved, and say what to do.
// Interpolating an array renders it comma-joined and indistinguishable from the
// single joined string it is NOT — the same collapse the filter avoids below.
const render = (value) => (value === undefined ? '(absent)' : JSON.stringify(value));
const describeDrift = (actual, expected) =>
[...new Set([...Object.keys(actual), ...Object.keys(expected)])]
.map((file) => ({ file, was: expected[file], now: actual[file] }))
// Structural, not stringified: String(['a', 'b']) === String('a,b'), so a
// hash list that lost its element boundaries would compare equal.
.filter(({ was, now }) => JSON.stringify(was) !== JSON.stringify(now))
.map(({ file, was, now }) => ` ${file}: baseline ${render(was)} -> migrations ship ${render(now)}`);
const expectMatchesBaseline = (actual, expected, label) => {
const drifted = describeDrift(actual, expected);
expect(
drifted.length === 0 ||
`${label} drifted from the baseline in scripts/setup-data-drift.test.js:\n${drifted.join('\n')}\n` +
'A prompt migration shipped a new body without carrying this baseline with it. ' +
'Point the baseline at the shipped hash and add the superseded hash to that file\'s accepted-old set.',
).toBe(true);
};
describe('buildPromptDriftTables', () => {
it('reproduces the full stage drift table the hand-mirror used to carry', async () => {
const { stages } = await buildPromptDriftTables(migrationsDir);
expectMatchesBaseline(stages.newMap, EXPECTED_STAGE_NEW, 'Current stage-prompt hashes');
expectMatchesBaseline(
sortValues(stages.oldMap),
sortValues(EXPECTED_STAGE_OLD),
'Accepted-old stage-prompt hashes',
);
expect(stages.files.sort()).toEqual(Object.keys(EXPECTED_STAGE_NEW).sort());
});
it('keys partial fragments under the _partials subdir, not stages', async () => {
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(_partials.newMap).toEqual(EXPECTED_PARTIAL_NEW);
expect(sortValues(_partials.oldMap)).toEqual(sortValues(EXPECTED_PARTIAL_OLD));
expect(stages.newMap['bible-deference.md']).toBeUndefined();
expect(stages.newMap['craft-anti-patterns.md']).toBeUndefined();
});
it('never lists the current hash among its own accepted-old set', async () => {
const tables = await buildPromptDriftTables(migrationsDir);
for (const table of [tables.stages, tables._partials]) {
for (const file of table.files) {
expect(table.oldMap[file]).not.toContain(table.newMap[file]);
}
}
});
});