Revert "fix(audit): keep source adoption schema first-use"

This reverts commit 4244630ccf.
This commit is contained in:
joshavant
2026-08-07 13:52:02 -05:00
committed by Josh Avant
parent 77fce5028b
commit 9dc4a358d3
3 changed files with 24 additions and 31 deletions
+17 -14
View File
@@ -9,20 +9,11 @@ import type { AuditEventInput } from "./audit-event-types.js";
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
const AUDIT_EVENT_RETENTION_MS_CONTRACT = 30 * 24 * 60 * 60_000;
const ADOPTION_TABLE_QUERY =
"SELECT 1 AS ok FROM sqlite_master WHERE type = 'table' AND name = 'audit_event_source_adoptions'";
function createDatabaseOptions() {
return { env: { OPENCLAW_STATE_DIR: tempDirs.make("openclaw-audit-adoption-") } };
}
function expectAdoptionTableAbsent(database: ReturnType<typeof createDatabaseOptions>): void {
expect(
openOpenClawStateDatabase(database).db.prepare(ADOPTION_TABLE_QUERY).get(),
).toBeUndefined();
closeOpenClawStateDatabaseForTest();
}
function auditInput(overrides: Partial<AuditEventInput> = {}): AuditEventInput {
const input = {
sourceSequence: 1,
@@ -61,7 +52,9 @@ describe("audit event source adoption", () => {
database,
),
).toBeDefined();
expectAdoptionTableAbsent(database);
const { db: legacyDb } = openOpenClawStateDatabase(database);
legacyDb.exec("DROP TABLE audit_event_source_adoptions");
closeOpenClawStateDatabaseForTest();
expect(
recordAuditEvent(
@@ -130,7 +123,9 @@ describe("audit event source adoption", () => {
toolCallId: "call-1",
});
expect(recordAuditEvent(legacyInput, database)).toBeDefined();
expectAdoptionTableAbsent(database);
const { db: legacyDb } = openOpenClawStateDatabase(database);
legacyDb.exec("DROP TABLE audit_event_source_adoptions");
closeOpenClawStateDatabaseForTest();
const replayInput = {
...legacyInput,
@@ -156,7 +151,9 @@ describe("audit event source adoption", () => {
database,
),
).toBeDefined();
expectAdoptionTableAbsent(database);
const { db: legacyDb } = openOpenClawStateDatabase(database);
legacyDb.exec("DROP TABLE audit_event_source_adoptions");
closeOpenClawStateDatabaseForTest();
const firstVersionedSourceId = `lifecycle:generation-1:${legacySourceId}`;
expect(
@@ -235,10 +232,16 @@ describe("audit event source adoption", () => {
it("does not materialize the lazy adoption table during cleanup", () => {
const database = createDatabaseOptions();
expectAdoptionTableAbsent(database);
const tableQuery =
"SELECT 1 AS ok FROM sqlite_master WHERE type = 'table' AND name = 'audit_event_source_adoptions'";
const { db } = openOpenClawStateDatabase(database);
db.exec("DROP TABLE audit_event_source_adoptions");
closeOpenClawStateDatabaseForTest();
expect(openOpenClawStateDatabase(database).db.prepare(tableQuery).get()).toBeUndefined();
closeOpenClawStateDatabaseForTest();
pruneExpiredAuditEvents({ database });
expectAdoptionTableAbsent(database);
expect(openOpenClawStateDatabase(database).db.prepare(tableQuery).get()).toBeUndefined();
});
});
+2 -4
View File
@@ -7,15 +7,13 @@ export const OPENCLAW_STATE_SCHEMA_VERSION = 6;
export const OPENCLAW_STATE_STRICT_SCHEMA_VERSION = 3;
// Privacy-sensitive feature tables remain absent even in fresh databases until
// their feature-local first write. The canonical SQL still owns their shape.
export const FIRST_USE_STATE_TABLES = [
"audit_event_source_adoptions",
"execution_identity_contexts",
] as const;
export const FIRST_USE_STATE_TABLES = ["execution_identity_contexts"] as const;
export const FIRST_USE_STATE_INDEXES = ["execution_identity_contexts_run_created_idx"] as const;
// Added after v6 shipped. These tables stay optional until their feature-local
// lazy ensures run; fold them into the next natural schema-version bump.
export const LAZY_ADDITIVE_STATE_TABLES = [
...FIRST_USE_STATE_TABLES,
"audit_event_source_adoptions",
"model_catalog_remote",
"sidebar_sections",
"skill_workshop_proposal_events",
+5 -13
View File
@@ -68,16 +68,6 @@ function createInitialStateSchemaShape() {
return shape;
}
function expectFirstUseStateTablesAbsent(database: DatabaseSync): void {
for (const tableName of FIRST_USE_STATE_TABLES) {
expect(
database
.prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = ?")
.get(tableName),
).toBeUndefined();
}
}
function expectStateSchemaMigrationRequired(
run: () => unknown,
expected: {
@@ -1101,7 +1091,11 @@ describe("openclaw state database", () => {
});
expect(collectSqliteSchemaShape(database.db)).toEqual(createInitialStateSchemaShape());
expectFirstUseStateTablesAbsent(database.db);
expect(
database.db
.prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = ?")
.get("execution_identity_contexts"),
).toBeUndefined();
expect(database.path).toBe(path.join(stateDir, "state", "openclaw.sqlite"));
expect(
database.db
@@ -3431,7 +3425,6 @@ INSERT INTO macos_port_guardian_records VALUES (4242, 18789, '/usr/bin/ssh', 're
requester_agent_id: "main",
});
expect(collectSqliteSchemaShape(db)).toEqual(expectedShape);
expectFirstUseStateTablesAbsent(db);
} finally {
db.close();
}
@@ -3457,7 +3450,6 @@ INSERT INTO macos_port_guardian_records VALUES (4242, 18789, '/usr/bin/ssh', 're
db.prepare("SELECT schema_version FROM schema_meta WHERE meta_key = 'primary'").get(),
).toEqual({ schema_version: OPENCLAW_STATE_SCHEMA_VERSION });
expect(collectSqliteSchemaShape(db)).toEqual(expectedShape);
expectFirstUseStateTablesAbsent(db);
} finally {
db.close();
}