mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
fix(admin): say what actually ages a stored account copy out
The backups page stated "Retention: 90 days", from a constant whose comment said it matched a backup-prune job. There is no such job: nothing deletes a stored copy by age. The weekly copy is replaced in place, one per account; the copy taken before "Delete all data" is deleted by the account-deletion purge when the grace window ends; an uploaded copy stays until its account is erased. The list now carries preWipeCopyDays (the grace window, 0 when no such copy is taken) instead of retentionDays, and the page says exactly the three facts above, in every language. Also drops a re-export of the JSON import row limit nothing imports.
This commit is contained in:
1 parent
459b5baa9d
commit
694befd635
17 files changed
+62
-37
No files matched your search
@@ -153,6 +153,16 @@ describe("GET /api/admin/backups — off-host freshness", () => {
|
||||
expect(byName.get("account-five")?.lastAttemptAt).toBeNull();
|
||||
});
|
||||
|
||||
it("states what ages a stored copy out, and invents no retention", async () => {
|
||||
configuredMock.mockReturnValue(false);
|
||||
findManyMock.mockResolvedValue([]);
|
||||
vi.stubEnv("ACCOUNT_DELETION_GRACE_DAYS", "21");
|
||||
const body = await read();
|
||||
vi.unstubAllEnvs();
|
||||
expect(body.preWipeCopyDays).toBe(21);
|
||||
expect(body).not.toHaveProperty("retentionDays");
|
||||
});
|
||||
|
||||
it("says so when neither the environment nor the ledger knows of any upload", async () => {
|
||||
configuredMock.mockReturnValue(false);
|
||||
findManyMock.mockResolvedValue([
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
import { OFFHOST_BACKUP_QUEUE } from "@/lib/jobs/offhost-backup-queue";
|
||||
import { offhostPurgeDue } from "@/lib/jobs/offhost-purge-queue";
|
||||
import { ACTIVE_ACCOUNT } from "@/lib/account-deletion/active-account";
|
||||
import { accountDeletionGraceDays } from "@/lib/account-deletion/grace";
|
||||
import {
|
||||
classifyOffhostBackup,
|
||||
OFFHOST_BACKUP_PERIOD_HOURS,
|
||||
@@ -213,9 +214,11 @@ export const GET = apiHandler(async () => {
|
||||
|
||||
const payload: BackupsList = {
|
||||
rows: list,
|
||||
// Matches the retention window the backup-prune job enforces so the
|
||||
// backups page states the same number the worker acts on.
|
||||
retentionDays: 90,
|
||||
// What ages these copies out, and nothing more: no job prunes stored
|
||||
// copies by age. The weekly copy is replaced in place, a pre-wipe copy
|
||||
// is deleted by the account-deletion purge when its window ends, and an
|
||||
// uploaded copy stays until its account is erased.
|
||||
preWipeCopyDays: accountDeletionGraceDays(),
|
||||
schedule: summariseBackupSchedule({
|
||||
scheduledCreatedAt: rows
|
||||
.filter((row) => row.type === SCHEDULED_BACKUP_TYPE)
|
||||
|
||||
@@ -49,7 +49,7 @@ vi.mock("@tanstack/react-query", () => ({
|
||||
createdAt: "2026-09-01T03:00:00.000Z",
|
||||
},
|
||||
],
|
||||
retentionDays: 30,
|
||||
preWipeCopyDays: 14,
|
||||
schedule: {
|
||||
lastSuccessAt: "2026-09-01T03:00:00.000Z",
|
||||
lastSuccessAgeDays: 2,
|
||||
|
||||
@@ -19,7 +19,7 @@ const healthySchedule = {
|
||||
const mocks = vi.hoisted(() => ({
|
||||
// Mutable so one file can render both a healthy schedule and a broken one;
|
||||
// the query mock reads it on every render.
|
||||
queryData: { rows: [], retentionDays: 30 } as Record<string, unknown>,
|
||||
queryData: { rows: [], preWipeCopyDays: 14 } as Record<string, unknown>,
|
||||
}));
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ primeLocales("de");
|
||||
function render(locale: "en" | "de" = "en") {
|
||||
mocks.queryData = {
|
||||
rows: [],
|
||||
retentionDays: 30,
|
||||
preWipeCopyDays: 14,
|
||||
schedule: healthySchedule,
|
||||
};
|
||||
return renderToStaticMarkup(
|
||||
@@ -159,7 +159,7 @@ describe("BackupsSection — empty state", () => {
|
||||
*/
|
||||
describe("BackupsSection — schedule health", () => {
|
||||
function withSchedule(schedule: Record<string, unknown>) {
|
||||
mocks.queryData = { rows: [], retentionDays: 30, schedule };
|
||||
mocks.queryData = { rows: [], preWipeCopyDays: 14, schedule };
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<BackupsSection />
|
||||
@@ -203,7 +203,7 @@ describe("BackupsSection — schedule health", () => {
|
||||
});
|
||||
|
||||
it("survives a response that predates the schedule field", () => {
|
||||
mocks.queryData = { rows: [], retentionDays: 30 };
|
||||
mocks.queryData = { rows: [], preWipeCopyDays: 14 };
|
||||
expect(() =>
|
||||
renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
|
||||
@@ -36,7 +36,7 @@ function render(data: BackupsList["offhost"] | null): string {
|
||||
? null
|
||||
: ({
|
||||
rows: [],
|
||||
retentionDays: 90,
|
||||
preWipeCopyDays: 14,
|
||||
schedule: null,
|
||||
offhost: data,
|
||||
} as unknown as BackupsList),
|
||||
|
||||
@@ -197,9 +197,11 @@ export function BackupsSection() {
|
||||
<BackupRowsCards rows={rows} {...rowActions} />
|
||||
|
||||
<p className="text-muted-foreground mt-2 text-xs">
|
||||
{t("admin.section.backups.retentionLabel", {
|
||||
days: data!.retentionDays,
|
||||
})}
|
||||
{data!.preWipeCopyDays > 0
|
||||
? t("admin.section.backups.retentionNote", {
|
||||
days: data!.preWipeCopyDays,
|
||||
})
|
||||
: t("admin.section.backups.retentionNoteNoGrace")}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -37,7 +37,7 @@ import { SLEEP_STAGE_NAMES } from "@/lib/validations/sleep-stage-entry";
|
||||
import { fallbackMoodDateStart } from "./mood-instant";
|
||||
|
||||
import { JSON_IMPORT_MAX_ROWS } from "./limits";
|
||||
export { JSON_IMPORT_MAX_BYTES, JSON_IMPORT_MAX_ROWS } from "./limits";
|
||||
export { JSON_IMPORT_MAX_BYTES } from "./limits";
|
||||
|
||||
// The type is the canonical enum, so every type the exporters write comes
|
||||
// back; a hand-kept subset once dropped four of eleven.
|
||||
|
||||
@@ -102,11 +102,12 @@ export interface BackupsList {
|
||||
*/
|
||||
offhost: OffhostBackupOverview;
|
||||
/**
|
||||
* Soft retention hint — the worker is configured for weekly backups
|
||||
* (see `DATA_BACKUP_CRON` in `src/lib/jobs/reminder-worker.ts`), and
|
||||
* the model upserts in-place per (userId, type), so each user has
|
||||
* exactly one current snapshot. The frontend uses this to label the
|
||||
* grid; no server-side enforcement.
|
||||
* How long a copy taken before "Delete all data" is kept: the deletion
|
||||
* grace window, after which the account-deletion purge deletes it. 0 when
|
||||
* there is no window and no such copy is taken. Nothing else ages a stored
|
||||
* copy out: the weekly copy is replaced in place, one per account, and an
|
||||
* uploaded copy stays until its account is erased. The page states exactly
|
||||
* that.
|
||||
*/
|
||||
retentionDays: number;
|
||||
preWipeCopyDays: number;
|
||||
}
|
||||
Reference in new issue
Block a user