mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat(enterprise): add audit log archival with crash-safe state machine
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user