test: assert crestodian audit through sqlite

This commit is contained in:
Peter Steinberger
2026-05-08 16:15:38 +01:00
parent 5893ceb37c
commit ab0aa4e9b4
12 changed files with 54 additions and 26 deletions

View File

@@ -7,6 +7,7 @@ import path from "node:path";
import { runCli, shouldStartCrestodianForBareRoot } from "../../dist/cli/run-main.js";
import { clearConfigCache } from "../../dist/config/config.js";
import type { OpenClawConfig } from "../../dist/config/types.openclaw.js";
import { listCrestodianAuditEntriesForTests } from "../../dist/crestodian/audit.js";
import { runCrestodian } from "../../dist/crestodian/crestodian.js";
import type { RuntimeEnv } from "../../dist/runtime.js";
@@ -160,10 +161,10 @@ async function main() {
"Crestodian persisted the raw Discord token",
);
const auditPath = path.join(stateDir, "audit", "crestodian.jsonl");
const audit = (await fs.readFile(auditPath, "utf8")).trim();
const auditEntries = (await listCrestodianAuditEntriesForTests()).map((entry) => entry.value);
const auditOperations = auditEntries.map((entry) => entry.operation);
for (const operation of spec.auditOperations) {
assert(audit.includes(`"operation":"${operation}"`), `${operation} audit entry missing`);
assert(auditOperations.includes(operation), `${operation} audit entry missing`);
}
console.log("Crestodian first-run Docker E2E passed");

View File

@@ -114,10 +114,10 @@ async function main() {
"planned default model was not written",
);
const auditPath = path.join(stateDir, "audit", "crestodian.jsonl");
const audit = (await fs.readFile(auditPath, "utf8")).trim();
const { listCrestodianAuditEntriesForTests } = await import("../../dist/crestodian/audit.js");
const auditEntries = (await listCrestodianAuditEntriesForTests()).map((entry) => entry.value);
assert(
audit.includes('"operation":"config.setDefaultModel"'),
auditEntries.some((entry) => entry.operation === "config.setDefaultModel"),
"planned model update audit entry missing",
);

View File

@@ -7,6 +7,7 @@ import path from "node:path";
import { handleCrestodianCommand } from "../../dist/auto-reply/reply/commands-crestodian.js";
import { clearConfigCache } from "../../dist/config/config.js";
import type { OpenClawConfig } from "../../dist/config/types.openclaw.js";
import { listCrestodianAuditEntriesForTests } from "../../dist/crestodian/audit.js";
import { runCrestodianRescueMessage } from "../../dist/crestodian/rescue-message.js";
type CommandResult = Awaited<ReturnType<typeof handleCrestodianCommand>>;
@@ -226,10 +227,8 @@ async function main() {
"agent config was not updated",
);
const auditPath = path.join(stateDir, "audit", "crestodian.jsonl");
const auditLines = (await fs.readFile(auditPath, "utf8")).trim().split("\n");
assert(auditLines.length >= 2, "audit log did not record both operations");
const audits = auditLines.map((line) => JSON.parse(line));
const audits = (await listCrestodianAuditEntriesForTests()).map((entry) => entry.value);
assert(audits.length >= 2, "audit log did not record both operations");
assert(
audits.some((audit) => audit.operation === "config.setDefaultModel"),
"model audit operation missing",