Make audit events immutable

This commit is contained in:
ZacharyZhang-NY committed 2026-05-23 22:35:35 -04:00
1 parent 20c8ef6ef3
commit 689fe861f1
4 files changed
+41 -1

No files matched your search

@@ -13,6 +13,28 @@ function createConnection(): DatabaseConnection {
}
describe("audit service", () => {
test("keeps core audit events immutable", () => {
const connection = createConnection();
const organization = new OrganizationService(connection.db);
let auditId = "";
connection.transaction(() => {
const orgId = organization.createOrganization({
organizationName: "Acme Operations",
employeeName: "Dana Lee",
mission: "Coordinate agents with auditable approvals.",
goal: "Ship a verified control plane.",
});
auditId = (connection.db.prepare("select id from audit_events where org_id = ? limit 1").get(orgId) as { id: string }).id;
});
expect(() => connection.db.prepare("update audit_events set action = ? where id = ?")
.run("changed", auditId)).toThrow("Audit events are immutable.");
expect(() => connection.db.prepare("delete from audit_events where id = ?")
.run(auditId)).toThrow("Audit events are immutable.");
connection.close();
});
test("creates thread scoped replay runs from immutable audit events", () => {
const connection = createConnection();
const organization = new OrganizationService(connection.db);
@@ -23,7 +23,7 @@ describe("domain services", () => {
const connection = createConnection();
const rows = connection.db.prepare("select version from schema_migrations order by version asc").all() as Array<{ version: number }>;
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]);
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]);
connection.close();
});