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
address review (codex): sanitize-first dedup so a blank-name row can't shadow a valid duplicate
[._.]/ Adam Eivy8b0f53cf5509
diff --git a/scripts/migrations/059-split-media-collections.js b/scripts/migrations/059-split-media-collections.jsindex 8690cdb28f..5a88613e73 100644--- a/scripts/migrations/059-split-media-collections.js+++ b/scripts/migrations/059-split-media-collections.js@@ -165,6 +165,18 @@ export default {console.warn(`⚠️ migration 059: skipping record with invalid id "${id}" (left in backup for manual recovery)`);continue;}+ // Mirror the rejections sanitizeCollection makes at read time (id + name)+ // BEFORE claiming the id below. The old monolithic listCollections+ // sanitized each row first and skipped unloadable ones, so a row the+ // service would drop on read (e.g. blank/missing name) must not shadow a+ // later valid duplicate of the same id — otherwise that collection+ // disappears post-upgrade. (Kept inline, not imported: a migration is a+ // frozen snapshot and must not shift when sanitizeCollection later evolves.)+ if (typeof record.name !== 'string' || !record.name.trim()) {+ invalid += 1;+ console.warn(`⚠️ migration 059: skipping record id "${id}" with missing/blank name (left in backup)`);+ continue;+ }if (existingIds.has(id)) {// Already split — either in a prior partial run (trust the on-disk// per-record file, which may hold fresher post-crash state) OR earlierdiff --git a/scripts/migrations/059-split-media-collections.test.js b/scripts/migrations/059-split-media-collections.test.jsindex 1369379e22..676abe78f7 100644--- a/scripts/migrations/059-split-media-collections.test.js+++ b/scripts/migrations/059-split-media-collections.test.js@@ -155,6 +155,23 @@ describe('migration 059 — split media-collections.json to per-record files', (expect(readJson(join(typeDir, id, 'index.json')).name).toBe('First (wins)');});+ it('duplicate ids: a leading unsanitizable row (blank name) does not shadow a later valid one', async () => {+ // sanitizeCollection drops a blank-name record on read, so the old reader+ // skipped it and surfaced the later valid duplicate. The split must mirror+ // that — otherwise the blank-name row claims the id and the collection+ // vanishes after upgrade.+ const id = '11111111-1111-1111-1111-111111111111';+ writeJson(legacyPath, {+ collections: [+ { id, name: ' ', items: [] }, // unsanitizable (blank name)+ collection(id, { name: 'Valid (surfaces)' }), // later valid duplicate+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result).toEqual({ ok: true, reason: 'split', written: 1, skipped: 0, invalid: 1 });+ expect(readJson(join(typeDir, id, 'index.json')).name).toBe('Valid (surfaces)');+ });+it('throws (does NOT mark applied) when the legacy file is corrupted, so a repaired file re-splits', async () => {// Throwing keeps the migration pending in run-migrations.js (which marks any// migration whose up() resolves as applied) — so the collections aren't