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

fix: migration 433 numbers a colliding quarantine name instead of aborting the runner (#12627)

[._.]/ Adam Eivy1649e1d98c1c
diff --git a/scripts/migrations/433-quarantine-media-manifests.js b/scripts/migrations/433-quarantine-media-manifests.js
index 6b6eb8de81..5a04cd7a31 100644
--- a/scripts/migrations/433-quarantine-media-manifests.js
+++ b/scripts/migrations/433-quarantine-media-manifests.js
@@ -39,14 +39,14 @@ async function quarantineDirectory(dir) {
} else if (entry.isFile() && !entry.name.endsWith('.quarantined')) {
const format = await manifestFormat(path);
if (!format) continue;
- const destination = `${path}.quarantined`;
- // Upgrade migrations are serialized; refuse an existing destination
- // rather than letting rename overwrite any previously preserved bytes.
- const exists = await lstat(destination).then(() => true, (err) => {
+ // A restored pre-433 snapshot puts the original beside an earlier
+ // quarantine. Throwing would abort the runner and block every later
+ // migration, so take the first free numbered name; never overwrite.
+ let destination = `${path}.quarantined`;
+ for (let n = 1; await lstat(destination).then(() => true, (err) => {
if (err.code === 'ENOENT') return false;
throw err;
- });
- if (exists) throw new Error('Media quarantine destination already exists; preserve both files before retrying');
+ }); n++) destination = `${path}.${n}.quarantined`;
await rename(path, destination);
quarantined++;
console.log(`📦 Quarantined ${format} media manifest`);
diff --git a/scripts/migrations/433-quarantine-media-manifests.test.js b/scripts/migrations/433-quarantine-media-manifests.test.js
index 669bc971f3..57e79b6529 100644
--- a/scripts/migrations/433-quarantine-media-manifests.test.js
+++ b/scripts/migrations/433-quarantine-media-manifests.test.js
@@ -63,14 +63,28 @@ describe('migration 433 — persisted media manifests', () => {
expect(await readFile(`${path}.quarantined`)).toEqual(Buffer.concat([tag, Buffer.from(playlist)]));
});
- it('does not overwrite an existing quarantine and tolerates missing stores', async () => {
+ it('never overwrites an existing quarantine: takes the next free numbered name and tolerates missing stores', async () => {
rootDir = await mkdtemp(join(tmpdir(), 'migration-433-'));
await expect(migration.up({ rootDir })).resolves.toEqual({ quarantined: 0 });
+ vi.spyOn(console, 'log').mockImplementation(() => {});
const path = await fixture('uploads', 'disguised.mp4', playlist);
await writeFile(`${path}.quarantined`, 'previous evidence');
- await expect(migration.up({ rootDir })).rejects.toThrow('destination already exists');
- expect(await readFile(path, 'utf8')).toBe(playlist);
+ await expect(migration.up({ rootDir })).resolves.toEqual({ quarantined: 1 });
expect(await readFile(`${path}.quarantined`, 'utf8')).toBe('previous evidence');
- expect((await readdir(join(rootDir, 'data', 'uploads'))).sort()).toEqual(['disguised.mp4', 'disguised.mp4.quarantined']);
+ expect(await readFile(`${path}.1.quarantined`, 'utf8')).toBe(playlist);
+ expect((await readdir(join(rootDir, 'data', 'uploads'))).sort()).toEqual(['disguised.mp4.1.quarantined', 'disguised.mp4.quarantined']);
+ await expect(migration.up({ rootDir })).resolves.toEqual({ quarantined: 0 });
+ });
+
+ it('survives the restore shape: same bytes present as both the original and its quarantine', async () => {
+ rootDir = await mkdtemp(join(tmpdir(), 'migration-433-'));
+ vi.spyOn(console, 'log').mockImplementation(() => {});
+ const path = await fixture('music', 'clip.mp3', playlist);
+ await writeFile(`${path}.quarantined`, playlist);
+ await writeFile(`${path}.1.quarantined`, 'earlier');
+ await expect(migration.up({ rootDir })).resolves.toEqual({ quarantined: 1 });
+ expect(await readFile(`${path}.2.quarantined`, 'utf8')).toBe(playlist);
+ expect(await readFile(`${path}.1.quarantined`, 'utf8')).toBe('earlier');
+ await expect(readFile(path)).rejects.toMatchObject({ code: 'ENOENT' });
});
});