feat: implement sensitive operation audit retention (TASK-WP6-04)
Dada P0-A isolated Windows CI / validate-and-package (push) Failing after 59s

This commit is contained in:
suyx
2026-08-04 11:51:09 +08:00
parent c589b8bb4e
commit 1c46311e05
21 changed files with 1670 additions and 11 deletions
@@ -136,4 +136,45 @@ describe("TDD-WP5-CLN-001 sticker history cleanup", () => {
{ operation_type: "asset_cleanup_physical_completed", result: "succeeded" },
]);
});
it("records a redacted physical failure in the same transaction and leaves the request retryable", async () => {
const test = fixture();
const adminId = seedAdmin(test.database);
const files = await seedHistoricalPair(test);
const candidates = test.storage.listAssetCleanupCandidates();
const intent = test.storage.createAssetCleanupIntent({
actorId: adminId,
fileIds: [files.original.file_id, files.thumbnail.file_id],
idempotencyKey: `cleanup-${randomUUID()}-${randomUUID()}`,
snapshotVersion: candidates.candidate_snapshot_version,
});
test.storage.confirmAssetCleanupIntent({
actorId: adminId,
confirmationToken: intent.confirmation_token,
requestId: intent.request_id,
});
test.database.prepare(`
UPDATE file_cleanup_queue SET relative_path = '../outside-fixture'
WHERE managed_file_id = ?
`).run(files.original.file_id);
const worker = new ProjectPurgeCleanup({ dataRoot: test.dataRoot, databasePath: test.databasePath });
const result = worker.processFileCleanup();
worker.close();
expect(result).toEqual({ completed: 1, failed: 1 });
expect(test.database.prepare("SELECT status FROM asset_cleanup_requests WHERE request_id = ?").get(intent.request_id)).toEqual({ status: "queued" });
expect(test.database.prepare("SELECT status, last_error FROM file_cleanup_queue WHERE managed_file_id = ?").get(files.original.file_id))
.toEqual({ last_error: "physical_file_cleanup_failed", status: "failed" });
const failure = test.database.prepare(`
SELECT operation_type, result, before_summary, after_summary
FROM admin_operation_logs WHERE target_ref = ? AND operation_type = 'asset_cleanup_physical_failed'
`).get(intent.request_id) as { after_summary: string; before_summary: null; operation_type: string; result: string };
expect(failure).toEqual({
after_summary: JSON.stringify({ failed_count: 1, status: "retry_pending" }),
before_summary: null,
operation_type: "asset_cleanup_physical_failed",
result: "failed",
});
expect(JSON.stringify(failure)).not.toMatch(/outside-fixture|relative_path|absolute_path|image|prompt|secret/i);
});
});