Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/data-retention.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -112,6 +113,11 @@ Total affected: 628

Re-run with --apply to perform the purge.
```
**Overriding the window.** `--days=<n>` 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

Expand Down
22 changes: 21 additions & 1 deletion scripts/retention.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,4 @@ export async function developerReceivesAISecurityExplanations(
}

return output;
}
}
2 changes: 1 addition & 1 deletion src/ai/flows/security-explanation-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,4 @@ export function toUserFacingError(error: unknown): string {
}

return error instanceof Error ? error.message : "AI generation failed.";
}
}
2 changes: 1 addition & 1 deletion src/ai/flows/security-explanation-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,4 @@ export async function* streamDeveloperSecurityExplanations(
message: toUserFacingError(err),
};
}
}
}
Loading