mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:31:23 +00:00
test: cover cron telemetry and typed fetch mocks
This commit is contained in:
@@ -97,4 +97,55 @@ describe("cron run log", () => {
|
||||
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("reads telemetry fields", async () => {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-cron-log-telemetry-"));
|
||||
const logPath = path.join(dir, "runs", "job-1.jsonl");
|
||||
|
||||
await appendCronRunLog(logPath, {
|
||||
ts: 1,
|
||||
jobId: "job-1",
|
||||
action: "finished",
|
||||
status: "ok",
|
||||
model: "gpt-5.2",
|
||||
provider: "openai",
|
||||
usage: {
|
||||
input_tokens: 10,
|
||||
output_tokens: 5,
|
||||
total_tokens: 15,
|
||||
cache_read_tokens: 2,
|
||||
cache_write_tokens: 1,
|
||||
},
|
||||
});
|
||||
|
||||
await fs.appendFile(
|
||||
logPath,
|
||||
`${JSON.stringify({
|
||||
ts: 2,
|
||||
jobId: "job-1",
|
||||
action: "finished",
|
||||
status: "ok",
|
||||
model: " ",
|
||||
provider: "",
|
||||
usage: { input_tokens: "oops" },
|
||||
})}\n`,
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const entries = await readCronRunLogEntries(logPath, { limit: 10, jobId: "job-1" });
|
||||
expect(entries[0]?.model).toBe("gpt-5.2");
|
||||
expect(entries[0]?.provider).toBe("openai");
|
||||
expect(entries[0]?.usage).toEqual({
|
||||
input_tokens: 10,
|
||||
output_tokens: 5,
|
||||
total_tokens: 15,
|
||||
cache_read_tokens: 2,
|
||||
cache_write_tokens: 1,
|
||||
});
|
||||
expect(entries[1]?.model).toBeUndefined();
|
||||
expect(entries[1]?.provider).toBeUndefined();
|
||||
expect(entries[1]?.usage?.input_tokens).toBeUndefined();
|
||||
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user