mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-28 00:17:57 +00:00
test: guard agent cli mock calls
This commit is contained in:
@@ -118,7 +118,7 @@ describe("runCliAgent cron before_agent_reply seam", () => {
|
||||
const result = await runCliAgent({ ...baseRunParams, trigger: "cron", jobId: "cron-job-123" });
|
||||
|
||||
expect(runBeforeAgentReplyMock).toHaveBeenCalledTimes(1);
|
||||
const [event, context] = runBeforeAgentReplyMock.mock.calls[0] ?? [];
|
||||
const [event, context] = runBeforeAgentReplyMock.mock.calls.at(0) ?? [];
|
||||
expect(event).toEqual({ cleanedBody: baseRunParams.prompt });
|
||||
const hookContext = context as Record<string, unknown> | undefined;
|
||||
expect(hookContext?.jobId).toBe("cron-job-123");
|
||||
|
||||
@@ -68,7 +68,7 @@ describe("loadPromptRefImages", () => {
|
||||
sandbox,
|
||||
});
|
||||
|
||||
const [ref, workspaceDir, options] = loadImageFromRefSpy.mock.calls[0] ?? [];
|
||||
const [ref, workspaceDir, options] = loadImageFromRefSpy.mock.calls.at(0) ?? [];
|
||||
expect(ref?.resolved).toBe("/tmp/photo.png");
|
||||
expect(ref?.type).toBe("path");
|
||||
expect(workspaceDir).toBe("/workspace");
|
||||
|
||||
@@ -290,7 +290,7 @@ describe("runCliAgent reliability", () => {
|
||||
).rejects.toThrow("produced no output");
|
||||
|
||||
expect(enqueueSystemEventMock).toHaveBeenCalledTimes(1);
|
||||
const [notice, opts] = enqueueSystemEventMock.mock.calls[0] ?? [];
|
||||
const [notice, opts] = enqueueSystemEventMock.mock.calls.at(0) ?? [];
|
||||
expect(String(notice)).toContain("produced no output");
|
||||
expect(String(notice)).toContain("interactive input or an approval prompt");
|
||||
expect(requireRecord(opts, "system event options").sessionKey).toBe("agent:main:main");
|
||||
|
||||
@@ -58,7 +58,7 @@ describe("compaction identifier-preservation instructions", () => {
|
||||
}
|
||||
|
||||
function firstSummaryInstructions() {
|
||||
return extractSummaryInstructions(mockGenerateSummary.mock.calls[0]);
|
||||
return extractSummaryInstructions(mockGenerateSummary.mock.calls.at(0));
|
||||
}
|
||||
|
||||
it("injects identifier-preservation guidance even without custom instructions", async () => {
|
||||
|
||||
@@ -299,13 +299,17 @@ describe("lookupContextTokens", () => {
|
||||
await flushAsyncWarmup();
|
||||
|
||||
expect(contextTestState.discoverModels).toHaveBeenCalledTimes(1);
|
||||
const discoverCall = contextTestState.discoverModels.mock.calls[0];
|
||||
expect(discoverCall?.[0]).toEqual({});
|
||||
expect(typeof discoverCall?.[1]).toBe("string");
|
||||
const discoverCall = contextTestState.discoverModels.mock.calls.at(0);
|
||||
if (!discoverCall) {
|
||||
throw new Error("expected discoverModels to be called");
|
||||
}
|
||||
const discoverAgentDir = discoverCall[1];
|
||||
expect(discoverCall[0]).toEqual({});
|
||||
expect(typeof discoverAgentDir).toBe("string");
|
||||
expect(
|
||||
path.normalize(discoverCall?.[1]).endsWith(path.join(".openclaw", "agents", "main", "agent")),
|
||||
path.normalize(discoverAgentDir).endsWith(path.join(".openclaw", "agents", "main", "agent")),
|
||||
).toBe(true);
|
||||
expect(discoverCall?.[2]).toEqual({ normalizeModels: false });
|
||||
expect(discoverCall[2]).toEqual({ normalizeModels: false });
|
||||
expect(lookupContextTokens("anthropic/claude-opus-4.7-20260219")).toBe(1_048_576);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user