From 455918401e44d07e75705cdc05aa62a2cd4a784e Mon Sep 17 00:00:00 2001 From: le king fu Date: Mon, 26 Oct 2026 21:12:37 -0400 Subject: [PATCH] test(pg-backup-pull): reproduces #71, a failed pull leaves copies older than 30 days Co-Authored-By: Claude Opus 5.5 --- __tests__/agent-pg-backup-pull.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/__tests__/agent-pg-backup-pull.test.js b/__tests__/agent-pg-backup-pull.test.js index b0fada2..0cefda2 100644 --- a/__tests__/agent-pg-backup-pull.test.js +++ b/__tests__/agent-pg-backup-pull.test.js @@ -284,6 +284,30 @@ printf 204 }); describe("rotation", () => { + // Issue #71: the privacy policy promises backup copies kept 30 days at most. + // A failed pull (VPS silent, workstation back after a long shutdown) must + // still enforce that bound, counted from today, and still say pull_failed. + test("a failed pull still removes every dated directory older than 30 days, and reports pull_failed", () => { + const dest = path.join(tmp, "dest"); + const names = ["2026-09-10", "2026-09-11", "2026-09-12", "2026-02-30", "2026-13-45", "2099-01-01"]; + for (const d of names) { + fs.mkdirSync(path.join(dest, d), { recursive: true }); + fs.writeFileSync(path.join(dest, d, "a.age"), "x"); + } + const { status, output } = run({ envFile: writeEnv(), extraEnv: { FAKE_RSYNC_FAIL: "1" } }); + expect(status).toBe(2); + // 31 and 30 days before today go; 29 days, impossible and future names stay. + expect(fs.readdirSync(dest).sort()).toEqual(["2026-02-30", "2026-09-12", "2026-13-45", "2099-01-01"]); + expect(output).toContain("rotation: cap removed 2026-09-10"); + expect(output).toContain("rotation: cap removed 2026-09-11"); + expect(JSON.parse(read("curl.body"))).toEqual({ + pulledAt: expect.any(String), + files: 0, + ok: false, + error: "pull_failed", + }); + }); + test("keeps 30 dated directories, today included, and ignores other names", () => { const dest = path.join(tmp, "dest"); for (const d of ["2026-09-11", "2026-09-12", "notes"]) fs.mkdirSync(path.join(dest, d), { recursive: true });