diff --git a/docs/data-retention.md b/docs/data-retention.md index 30403690..fb2204a6 100644 --- a/docs/data-retention.md +++ b/docs/data-retention.md @@ -91,6 +91,7 @@ replaces it. npm run retention # dry run — reports, writes nothing npm run retention -- --apply # perform the purge npm run retention -- --only=auditLog # one target (repeatable) +npm run retention -- --days=60 # override every retention window for this run npm run retention -- --batch-size=200 # smaller statements npm run retention -- --help ``` @@ -112,6 +113,11 @@ Total affected: 628 Re-run with --apply to perform the purge. ``` +**Overriding the window.** `--days=` applies one retention period to every +target for that run, taking precedence over the per-target environment variables +and `DATA_RETENTION_DAYS`. It must be a whole number between 1 and 3650. Combine +it with `--only` to change a single table, e.g. +`npm run retention -- --only=webhookEvent --days=7 --apply`. ### Exit codes diff --git a/scripts/retention.test.ts b/scripts/retention.test.ts index a6b1835d..912cbe1c 100644 --- a/scripts/retention.test.ts +++ b/scripts/retention.test.ts @@ -225,9 +225,29 @@ describe("scripts/retention.ts - CLI and Data Deletion Boundaries (#1330)", () = expect(code).toBe(0); }); + it("never writes anything during a dry run", async () => { + const code = await runRetentionCli([], mockPrisma); + + expect(code).toBe(0); + expect(mockPrisma.finding.updateMany).not.toHaveBeenCalled(); + expect(mockPrisma.webhookEvent.deleteMany).not.toHaveBeenCalled(); + expect(mockPrisma.scanResult.deleteMany).not.toHaveBeenCalled(); + expect(mockPrisma.auditLog.deleteMany).not.toHaveBeenCalled(); + }); + + it("--only restricts the run to the named target", async () => { + const code = await runRetentionCli(["--only=auditLog", "--days=30"], mockPrisma); + + expect(code).toBe(0); + expect(mockPrisma.auditLog.findMany).toHaveBeenCalled(); + expect(mockPrisma.webhookEvent.findMany).not.toHaveBeenCalled(); + expect(mockPrisma.scanResult.findMany).not.toHaveBeenCalled(); + expect(mockPrisma.finding.findMany).not.toHaveBeenCalled(); + }); + it("returns exit code 0 on successful dry run with --days flag", async () => { const code = await runRetentionCli(["--days=30", "--only=webhookEvent"], mockPrisma); expect(code).toBe(0); }); }); -}); +}); \ No newline at end of file diff --git a/src/ai/flows/developer-receives-ai-security-explanations.ts b/src/ai/flows/developer-receives-ai-security-explanations.ts index f11c49be..b8d975b6 100644 --- a/src/ai/flows/developer-receives-ai-security-explanations.ts +++ b/src/ai/flows/developer-receives-ai-security-explanations.ts @@ -224,4 +224,4 @@ export async function developerReceivesAISecurityExplanations( } return output; -} +} \ No newline at end of file diff --git a/src/ai/flows/security-explanation-core.ts b/src/ai/flows/security-explanation-core.ts index 67c24b8e..688eefbe 100644 --- a/src/ai/flows/security-explanation-core.ts +++ b/src/ai/flows/security-explanation-core.ts @@ -222,4 +222,4 @@ export function toUserFacingError(error: unknown): string { } return error instanceof Error ? error.message : "AI generation failed."; -} +} \ No newline at end of file diff --git a/src/ai/flows/security-explanation-stream.ts b/src/ai/flows/security-explanation-stream.ts index e3642d0e..bb08dc40 100644 --- a/src/ai/flows/security-explanation-stream.ts +++ b/src/ai/flows/security-explanation-stream.ts @@ -280,4 +280,4 @@ export async function* streamDeveloperSecurityExplanations( message: toUserFacingError(err), }; } -} +} \ No newline at end of file