mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 21:04:45 +00:00
test: dedupe cron session identity mock reads
This commit is contained in:
@@ -22,6 +22,31 @@ import {
|
||||
|
||||
setupRunCronIsolatedAgentTurnSuite();
|
||||
|
||||
function lastEmbeddedAgentCall(): {
|
||||
agentDir?: string;
|
||||
prompt?: string;
|
||||
sessionKey?: string;
|
||||
workspaceDir?: string;
|
||||
sessionFile?: string;
|
||||
} {
|
||||
const calls = runEmbeddedPiAgentMock.mock.calls;
|
||||
const call = calls[calls.length - 1];
|
||||
if (!call) {
|
||||
throw new Error("expected runEmbeddedPiAgent call");
|
||||
}
|
||||
const value = call[0];
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error("expected runEmbeddedPiAgent call payload");
|
||||
}
|
||||
return value as {
|
||||
agentDir?: string;
|
||||
prompt?: string;
|
||||
sessionKey?: string;
|
||||
workspaceDir?: string;
|
||||
sessionFile?: string;
|
||||
};
|
||||
}
|
||||
|
||||
describe("runCronIsolatedAgentTurn session identity", () => {
|
||||
beforeEach(() => {
|
||||
vi.spyOn(modelThinkingDefault, "resolveThinkingDefault").mockReturnValue("off");
|
||||
@@ -36,10 +61,8 @@ describe("runCronIsolatedAgentTurn session identity", () => {
|
||||
});
|
||||
|
||||
expect(res.status).toBe("ok");
|
||||
const call = runEmbeddedPiAgentMock.mock.calls.at(-1)?.[0] as {
|
||||
agentDir?: string;
|
||||
};
|
||||
expect(call?.agentDir).toBe(path.join(home, ".openclaw", "agents", "main", "agent"));
|
||||
const call = lastEmbeddedAgentCall();
|
||||
expect(call.agentDir).toBe(path.join(home, ".openclaw", "agents", "main", "agent"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,10 +72,8 @@ describe("runCronIsolatedAgentTurn session identity", () => {
|
||||
jobPayload: DEFAULT_AGENT_TURN_PAYLOAD,
|
||||
});
|
||||
|
||||
const call = runEmbeddedPiAgentMock.mock.calls.at(-1)?.[0] as {
|
||||
prompt?: string;
|
||||
};
|
||||
const lines = call?.prompt?.split("\n") ?? [];
|
||||
const call = lastEmbeddedAgentCall();
|
||||
const lines = (call.prompt ?? "").split("\n");
|
||||
expect(lines[0]).toContain("[cron:job-1");
|
||||
expect(lines[0]).toContain("do it");
|
||||
expect(lines[1]).toMatch(/^Current time: .+ \(.+\)$/);
|
||||
@@ -98,14 +119,10 @@ describe("runCronIsolatedAgentTurn session identity", () => {
|
||||
});
|
||||
|
||||
expect(res.status).toBe("ok");
|
||||
const call = runEmbeddedPiAgentMock.mock.calls.at(-1)?.[0] as {
|
||||
sessionKey?: string;
|
||||
workspaceDir?: string;
|
||||
sessionFile?: string;
|
||||
};
|
||||
expect(call?.sessionKey).toMatch(/^agent:ops:cron:job-ops:run:/);
|
||||
expect(call?.workspaceDir).toBe(opsWorkspace);
|
||||
expect(call?.sessionFile).toContain(path.join("agents", "ops"));
|
||||
const call = lastEmbeddedAgentCall();
|
||||
expect(call.sessionKey).toMatch(/^agent:ops:cron:job-ops:run:/);
|
||||
expect(call.workspaceDir).toBe(opsWorkspace);
|
||||
expect(call.sessionFile).toContain(path.join("agents", "ops"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -114,14 +131,12 @@ describe("runCronIsolatedAgentTurn session identity", () => {
|
||||
await runCronTurn(home, {
|
||||
jobPayload: DEFAULT_AGENT_TURN_PAYLOAD,
|
||||
});
|
||||
const call = runEmbeddedPiAgentMock.mock.calls.at(-1)?.[0] as {
|
||||
sessionFile?: string;
|
||||
};
|
||||
const call = lastEmbeddedAgentCall();
|
||||
|
||||
expect(call?.sessionFile).toContain(
|
||||
expect(call.sessionFile).toContain(
|
||||
path.join(home, ".openclaw", "agents", "main", "sessions"),
|
||||
);
|
||||
expect(call?.sessionFile?.endsWith(".jsonl")).toBe(true);
|
||||
expect(String(call.sessionFile).endsWith(".jsonl")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user