feat(enterprise): add audit log archival with crash-safe state machine

This commit is contained in:
SnapOtter
2026-06-13 16:57:20 +08:00
parent d3f30a2f5d
commit c1dc27f248
3 changed files with 271 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
import { describe, expect, it } from "vitest";
describe("audit archival state machine", () => {
const validTransitions: Record<string, string> = {
PENDING: "EXPORTING",
EXPORTING: "EXPORTED",
EXPORTED: "PURGING",
PURGING: "COMPLETE",
};
it("state transitions are valid", () => {
for (const [from, to] of Object.entries(validTransitions)) {
expect(from).toBeTruthy();
expect(to).toBeDefined();
}
});
it("covers all non-terminal states", () => {
const states = ["PENDING", "EXPORTING", "EXPORTED", "PURGING", "COMPLETE"];
const nonTerminal = states.filter((s) => s !== "COMPLETE");
for (const state of nonTerminal) {
expect(validTransitions[state]).toBeDefined();
}
});
it("COMPLETE is terminal (no outgoing transition)", () => {
expect(validTransitions.COMPLETE).toBeUndefined();
});
it("has no cycles in the transition graph", () => {
const visited = new Set<string>();
let current = "PENDING";
while (current && !visited.has(current)) {
visited.add(current);
current = validTransitions[current];
}
// If we exited because current is undefined (end of chain), no cycle
expect(current).toBeUndefined();
});
});