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

Merge pull request #1051 from atomantic/feat/prune-legacy-migration-artifacts

[._.]/ Adam Eivydf9ddc756aa6
diff --cc server/services/backup.test.js
index 210e9274b4,819db5d97c..914e3cdb4b
--- a/server/services/backup.test.js
+++ b/server/services/backup.test.js
@@@ -156,69 -153,20 +156,81 @@@ describe('computeEffectiveExcludes', (
const result = computeEffectiveExcludes();
expect(result).toEqual(DEFAULT_EXCLUDES.map(e => e.path));
});
+
+ it('does NOT exclude legacy file→DB migration artifacts (they are the recovery source while a prune is blocked)', () => {
+ // The boot-time prune deletes these on disk once the DB is authoritative;
+ // excluding them from snapshots would strip the only recovery source during
+ // a blocked (wiped/partial-restore) prune, while pg_dump captures the
+ // incomplete DB. So none of these patterns may appear in the default set.
+ const mustNotExclude = ['/*.imported', '/*.bak-034', '/*.migrated.json', '/writers-room/works/*/manifest.imported.json'];
+ const paths = DEFAULT_EXCLUDES.map(e => e.path);
+ for (const p of mustNotExclude) {
+ expect(paths, `${p} must NOT be a default exclude`).not.toContain(p);
+ }
+ });
});
+describe('pickPgDump', () => {
+ const c = (major, binary = `pg_dump@${major}`) => ({ binary, major });
+
+ it('returns null when no candidates were discovered', () => {
+ expect(pickPgDump(17, [])).toBeNull();
+ expect(pickPgDump(17, undefined)).toBeNull();
+ });
+
+ it('picks the exact-major binary when one is installed', () => {
+ const chosen = pickPgDump(17, [c(15), c(17), c(16)]);
+ expect(chosen).toBe('pg_dump@17');
+ });
+
+ it('picks the closest binary that is >= the server (newer is fine, never older)', () => {
+ // server 16: 15 is too old, choose 17 (smallest qualifying), not 18.
+ expect(pickPgDump(16, [c(15), c(17), c(18)])).toBe('pg_dump@17');
+ });
+
+ it('falls back to the newest available when nothing is new enough (forces a clear mismatch error)', () => {
+ // This is the reported bug: server 17, only pg_dump 15 installed.
+ expect(pickPgDump(17, [c(15)])).toBe('pg_dump@15');
+ expect(pickPgDump(17, [c(14), c(15)])).toBe('pg_dump@15');
+ });
+
+ it('trusts the first (PATH) candidate when the server version is unknown', () => {
+ expect(pickPgDump(null, [c(15, 'pg_dump'), c(17)])).toBe('pg_dump');
+ expect(pickPgDump(NaN, [c(15, 'pg_dump'), c(17)])).toBe('pg_dump');
+ });
+});
+
+describe('listSnapshots', () => {
+ beforeEach(() => vi.clearAllMocks());
+ const dirent = (name, isDir) => ({ name, isDirectory: () => isDir });
+
+ it('skips non-directory entries like .DS_Store (iCloud/Finder droppings)', async () => {
+ // The backup target is commonly an iCloud folder; macOS drops a `.DS_Store`
+ // FILE into every dir. It must not be treated as a snapshot id (reading
+ // `<.DS_Store>/manifest.json` would throw ENOTDIR).
+ vi.spyOn(fs, 'readdir').mockResolvedValue([
+ dirent('.DS_Store', false),
+ dirent('2026-06-08T15-18-34', true),
+ dirent('2026-06-07T09-00-00', true),
+ ]);
+ vi.spyOn(fs, 'readFile').mockImplementation(async (p) => {
+ if (String(p).includes('.DS_Store')) throw new Error('ENOTDIR — .DS_Store should never be read');
+ return JSON.stringify({ generatedAt: '2026-06-08T00:00:00Z', fileCount: 10 });
+ });
+ const result = await listSnapshots('/dest');
+ const ids = result.map(s => s.id);
+ expect(ids).toHaveLength(2);
+ expect(ids).toContain('2026-06-08T15-18-34');
+ expect(ids).not.toContain('.DS_Store');
+ });
+
+ it('returns [] for a falsy destPath without touching the filesystem', async () => {
+ const readdirSpy = vi.spyOn(fs, 'readdir');
+ expect(await listSnapshots('')).toEqual([]);
+ expect(readdirSpy).not.toHaveBeenCalled();
+ });
+});
+
describe('dumpPostgres status classification', () => {
let dumpPostgres;
beforeEach(async () => {