test: guard agent tool call assertions

This commit is contained in:
Peter Steinberger
2026-05-12 08:32:40 +01:00
parent 8c22d5aaaf
commit 8ee024df39
3 changed files with 12 additions and 16 deletions

View File

@@ -105,7 +105,7 @@ describe("cron tool", () => {
},
});
const call = callGatewayMock.mock.calls[0]?.[0] as {
const call = callGatewayMock.mock.calls.at(0)?.[0] as {
params?: { delivery?: TestDelivery };
};
return call?.params?.delivery;
@@ -534,7 +534,7 @@ describe("cron tool", () => {
},
});
const call = callGatewayMock.mock.calls[0]?.[0] as {
const call = callGatewayMock.mock.calls.at(0)?.[0] as {
params?: { agentId?: unknown };
};
expect(call?.params?.agentId).toBeNull();
@@ -721,7 +721,7 @@ describe("cron tool", () => {
},
});
const call = callGatewayMock.mock.calls[0]?.[0] as {
const call = callGatewayMock.mock.calls.at(0)?.[0] as {
method?: string;
params?: { agentId?: string | null };
};
@@ -1066,7 +1066,7 @@ describe("cron tool", () => {
name: "flat-name-should-be-ignored",
});
const call = callGatewayMock.mock.calls[0]?.[0] as {
const call = callGatewayMock.mock.calls.at(0)?.[0] as {
params?: { name?: string; payload?: { text?: string } };
};
expect(call?.params?.name).toBe("nested-job");

View File

@@ -668,10 +668,8 @@ describe("sessions_spawn tool", () => {
expect(spawnArgs.task).toBe("resume prior work");
const spawnContext = mockCallArg(hoisted.spawnSubagentDirectMock, 0, 1, "spawnSubagentDirect");
expect(spawnContext.agentSessionKey).toBe("agent:main:main");
expect(hoisted.spawnSubagentDirectMock.mock.calls[0]?.[0]).not.toHaveProperty(
"resumeSessionId",
);
expect(hoisted.spawnSubagentDirectMock.mock.calls[0]?.[0]).not.toHaveProperty("streamTo");
expect(spawnArgs).not.toHaveProperty("resumeSessionId");
expect(spawnArgs).not.toHaveProperty("streamTo");
expect(hoisted.spawnAcpDirectMock).not.toHaveBeenCalled();
});
@@ -717,10 +715,8 @@ describe("sessions_spawn tool", () => {
expect(hoisted.spawnAcpDirectMock).not.toHaveBeenCalled();
const spawnArgs = mockCallArg(hoisted.spawnSubagentDirectMock, 0, 0, "spawnSubagentDirect");
expect(spawnArgs.task).toBe("analyze file");
expect(hoisted.spawnSubagentDirectMock.mock.calls[0]?.[0]).not.toHaveProperty(
"resumeSessionId",
);
expect(hoisted.spawnSubagentDirectMock.mock.calls[0]?.[0]).not.toHaveProperty("streamTo");
expect(spawnArgs).not.toHaveProperty("resumeSessionId");
expect(spawnArgs).not.toHaveProperty("streamTo");
});
it('treats model="default" as no explicit model override', async () => {

View File

@@ -156,7 +156,7 @@ function resultDetails(result: { details?: unknown }): Record<string, unknown> {
}
function firstMockCallArg(mock: { mock: { calls: unknown[][] } }): unknown {
const firstCall = mock.mock.calls[0];
const firstCall = mock.mock.calls.at(0);
if (!firstCall) {
throw new Error("Expected first mock call");
}
@@ -399,7 +399,7 @@ describe("createVideoGenerateTool", () => {
});
expect((firstMockCallArg(generateSpy) as { timeoutMs?: number }).timeoutMs).toBe(180_000);
expect((generateSpy.mock.calls[1]?.[0] as { timeoutMs?: number }).timeoutMs).toBe(12_345);
expect((generateSpy.mock.calls.at(1)?.[0] as { timeoutMs?: number }).timeoutMs).toBe(12_345);
expect(resultDetails(defaultResult).timeoutMs).toBe(180_000);
expect(resultDetails(overrideResult).timeoutMs).toBe(12_345);
});
@@ -1059,7 +1059,7 @@ describe("createVideoGenerateTool", () => {
});
expect(generateSpy).toHaveBeenCalledTimes(1);
const call = generateSpy.mock.calls[0]?.[0] as {
const call = generateSpy.mock.calls.at(0)?.[0] as {
inputImages?: Array<{ role?: string }>;
};
expect(call.inputImages).toHaveLength(2);
@@ -1096,7 +1096,7 @@ describe("createVideoGenerateTool", () => {
image: "/tmp/reference.png",
});
const loadCall = vi.mocked(webMedia.loadWebMedia).mock.calls[0];
const loadCall = vi.mocked(webMedia.loadWebMedia).mock.calls.at(0);
expect(loadCall?.[0]).toBe("/tmp/reference.png");
const loadOptions = loadCall?.[1] as { ssrfPolicy?: unknown } | undefined;
expect(loadOptions?.ssrfPolicy).toEqual({ allowRfc2544BenchmarkRange: true });