mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-13 10:11:20 +00:00
test: accept flattened config audit records
This commit is contained in:
@@ -201,4 +201,59 @@ describe("config io audit helpers", () => {
|
||||
nextHash: "next-hash",
|
||||
});
|
||||
});
|
||||
|
||||
it("also accepts flattened audit record params from legacy call sites", async () => {
|
||||
const home = await suiteRootTracker.make("append-flat");
|
||||
const record = finalizeConfigWriteAuditRecord({
|
||||
base: createConfigWriteAuditRecordBase({
|
||||
configPath: path.join(home, ".openclaw", "openclaw.json"),
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
existsBefore: true,
|
||||
previousHash: "prev-hash",
|
||||
nextHash: "next-hash",
|
||||
previousBytes: 12,
|
||||
nextBytes: 24,
|
||||
previousMetadata: {
|
||||
dev: "10",
|
||||
ino: "11",
|
||||
mode: 0o600,
|
||||
nlink: 1,
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
},
|
||||
changedPathCount: 1,
|
||||
hasMetaBefore: true,
|
||||
hasMetaAfter: true,
|
||||
gatewayModeBefore: "local",
|
||||
gatewayModeAfter: "local",
|
||||
suspicious: [],
|
||||
now: "2026-04-07T08:00:00.000Z",
|
||||
}),
|
||||
result: "rename",
|
||||
nextMetadata: {
|
||||
dev: "12",
|
||||
ino: "13",
|
||||
mode: 0o600,
|
||||
nlink: 1,
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
},
|
||||
});
|
||||
|
||||
await appendConfigAuditRecord({
|
||||
fs,
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
homedir: () => home,
|
||||
...record,
|
||||
});
|
||||
|
||||
const auditPath = path.join(home, ".openclaw", "logs", "config-audit.jsonl");
|
||||
const lines = fs.readFileSync(auditPath, "utf-8").trim().split("\n");
|
||||
expect(lines).toHaveLength(1);
|
||||
expect(JSON.parse(lines[0])).toMatchObject({
|
||||
event: "config.write",
|
||||
result: "rename",
|
||||
nextHash: "next-hash",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -143,6 +143,19 @@ type ConfigAuditFs = {
|
||||
): unknown;
|
||||
};
|
||||
|
||||
type ConfigAuditAppendParams =
|
||||
| {
|
||||
fs: ConfigAuditFs;
|
||||
env: NodeJS.ProcessEnv;
|
||||
homedir: () => string;
|
||||
record: ConfigAuditRecord;
|
||||
}
|
||||
| ({
|
||||
fs: ConfigAuditFs;
|
||||
env: NodeJS.ProcessEnv;
|
||||
homedir: () => string;
|
||||
} & ConfigAuditRecord);
|
||||
|
||||
function normalizeAuditLabel(value: string | undefined): string | null {
|
||||
if (typeof value !== "string") {
|
||||
return null;
|
||||
@@ -219,17 +232,11 @@ export function createConfigWriteAuditRecordBase(params: {
|
||||
previousBytes: params.previousBytes,
|
||||
nextBytes: params.nextBytes,
|
||||
previousDev: params.previousMetadata.dev,
|
||||
nextDev: null,
|
||||
previousIno: params.previousMetadata.ino,
|
||||
nextIno: null,
|
||||
previousMode: params.previousMetadata.mode,
|
||||
nextMode: null,
|
||||
previousNlink: params.previousMetadata.nlink,
|
||||
nextNlink: null,
|
||||
previousUid: params.previousMetadata.uid,
|
||||
nextUid: null,
|
||||
previousGid: params.previousMetadata.gid,
|
||||
nextGid: null,
|
||||
changedPathCount: typeof params.changedPathCount === "number" ? params.changedPathCount : null,
|
||||
hasMetaBefore: params.hasMetaBefore,
|
||||
hasMetaAfter: params.hasMetaAfter,
|
||||
|
||||
Reference in New Issue
Block a user