test: guard extension provider mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 11:11:02 +01:00
parent 7bb2d20303
commit ea05be12b4
16 changed files with 33 additions and 32 deletions

View File

@@ -491,7 +491,7 @@ describe("fetchCopilotModelCatalog", () => {
});
expect(fetchImpl).toHaveBeenCalledTimes(1);
const [calledUrl, calledInit] = fetchImpl.mock.calls[0];
const [calledUrl, calledInit] = fetchImpl.mock.calls.at(0) ?? [];
expect(calledUrl).toBe("https://api.githubcopilot.com/models");
expect((calledInit as RequestInit).method).toBe("GET");
expect(((calledInit as RequestInit).headers as Record<string, string>).Authorization).toBe(
@@ -539,7 +539,7 @@ describe("fetchCopilotModelCatalog", () => {
fetchImpl: fetchImpl as unknown as typeof fetch,
});
expect(fetchImpl.mock.calls[0][0]).toBe("https://api.githubcopilot.com/models");
expect(fetchImpl.mock.calls.at(0)?.[0]).toBe("https://api.githubcopilot.com/models");
});
it("dedupes by id when API returns duplicates", async () => {

View File

@@ -811,7 +811,7 @@ describe("google-meet CLI", () => {
],
{ from: "user" },
);
const gatewayCall = callGatewayFromCli.mock.calls[0] as unknown as
const gatewayCall = callGatewayFromCli.mock.calls.at(0) as unknown as
| [
string,
{ json?: boolean; timeout?: unknown },
@@ -1144,7 +1144,7 @@ describe("google-meet CLI", () => {
expectFields(checks[0], { id: "oauth-config", ok: true });
expectFields(checks[1], { id: "oauth-token", ok: true });
expect(ensureRuntime).not.toHaveBeenCalled();
const body = fetchMock.mock.calls[0]?.[1]?.body as URLSearchParams;
const body = fetchMock.mock.calls.at(0)?.[1]?.body as URLSearchParams;
expect(body.get("grant_type")).toBe("refresh_token");
} finally {
stdout.restore();

View File

@@ -109,7 +109,7 @@ describe("monitorIMessageProvider watch.subscribe startup retry", () => {
{ timeoutMs: 10_000 },
);
expect(runtime.log).toHaveBeenCalledTimes(1);
expect(String(runtime.log.mock.calls[0][0])).toContain(
expect(String(runtime.log.mock.calls.at(0)?.[0])).toContain(
"imessage: watch.subscribe startup failed (attempt 1/3): Error: imsg rpc timeout (watch.subscribe); retrying",
);
expect(
@@ -141,7 +141,7 @@ describe("monitorIMessageProvider watch.subscribe startup retry", () => {
expect((monitorError as Error).message).toContain("imsg rpc timeout (watch.subscribe)");
expect(createIMessageRpcClientMock).toHaveBeenCalledTimes(3);
expect(runtime.error).toHaveBeenCalledTimes(1);
expect(String(runtime.error.mock.calls[0][0])).toContain(
expect(String(runtime.error.mock.calls.at(0)?.[0])).toContain(
"imessage: monitor failed: Error: imsg rpc timeout (watch.subscribe)",
);
});

View File

@@ -266,7 +266,7 @@ describe("uploadRichMenuImage", () => {
expect(MessagingApiBlobClientMock).toHaveBeenCalledWith({ channelAccessToken: "line-token" });
expect(setRichMenuImageMock).toHaveBeenCalledOnce();
const [richMenuId, blob] = setRichMenuImageMock.mock.calls[0] ?? [];
const [richMenuId, blob] = setRichMenuImageMock.mock.calls.at(0) ?? [];
expect(richMenuId).toBe("rich-menu-1");
expect(blob).toBeInstanceOf(Blob);
expect((blob as Blob).type).toBe("image/png");
@@ -306,7 +306,7 @@ describe("uploadRichMenuImage", () => {
});
expect(setRichMenuImageMock).toHaveBeenCalledOnce();
const blob = setRichMenuImageMock.mock.calls[0]?.[1] as Blob;
const blob = setRichMenuImageMock.mock.calls.at(0)?.[1] as Blob;
expect(blob.type).toBe("image/jpeg");
await expect(blob.arrayBuffer()).resolves.toEqual(
imageBytes.buffer.slice(imageBytes.byteOffset, imageBytes.byteOffset + imageBytes.byteLength),

View File

@@ -88,7 +88,7 @@ function resetRunnerMocks() {
async function executeEmbeddedRun(input: Record<string, unknown>) {
const tool = createLlmTaskTool(fakeApi());
await tool.execute("id", input);
return (runEmbeddedPiAgent as any).mock.calls[0]?.[0];
return (runEmbeddedPiAgent as any).mock.calls.at(0)?.[0];
}
describe("llm-task tool (json-only)", () => {
@@ -238,7 +238,7 @@ describe("llm-task tool (json-only)", () => {
await tool.execute("id", { prompt: "x", model: "gemini-flash" });
const call = (runEmbeddedPiAgent as any).mock.calls[0]?.[0];
const call = (runEmbeddedPiAgent as any).mock.calls.at(0)?.[0];
expect(call.provider).toBe("google");
expect(call.model).toBe("gemini-3-flash-preview");
});

View File

@@ -349,7 +349,7 @@ describe("createMatrixDraftStream", () => {
await stream.stop();
expect(sendMessageMock).toHaveBeenCalledTimes(1);
expect(sendMessageMock.mock.calls[0]?.[1]).toHaveProperty("org.matrix.msc4357.live");
expect(sendMessageMock.mock.calls.at(0)?.[1]).toHaveProperty("org.matrix.msc4357.live");
});
it("finalizeLive clears the live marker at most once", async () => {
@@ -367,7 +367,7 @@ describe("createMatrixDraftStream", () => {
await stream.finalizeLive();
expect(sendMessageMock).toHaveBeenCalledTimes(2);
expect(sendMessageMock.mock.calls[1]?.[1]).not.toHaveProperty("org.matrix.msc4357.live");
expect(sendMessageMock.mock.calls.at(1)?.[1]).not.toHaveProperty("org.matrix.msc4357.live");
});
it("marks live finalize failures for normal final delivery fallback", async () => {

View File

@@ -14,7 +14,7 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
}
function readFirstMockArg(fn: unknown): unknown {
return (fn as { mock: { calls: unknown[][] } }).mock.calls[0]?.[0];
return (fn as { mock: { calls: unknown[][] } }).mock.calls.at(0)?.[0];
}
describe("createMatrixRoomMessageHandler thread root media", () => {
@@ -79,7 +79,7 @@ describe("createMatrixRoomMessageHandler thread root media", () => {
expect(formatAgentEnvelope).toHaveBeenCalledTimes(1);
const envelope = requireRecord(
formatAgentEnvelope.mock.calls[0]?.[0],
formatAgentEnvelope.mock.calls.at(0)?.[0],
"format agent envelope params",
);
expect(String(envelope.body)).toContain("replying");

View File

@@ -1678,7 +1678,7 @@ describe("MatrixClient crypto bootstrapping", () => {
await client.start();
const startOpts = matrixJsClient.startClient.mock.calls[0]?.[0] as
const startOpts = matrixJsClient.startClient.mock.calls.at(0)?.[0] as
| { filter?: { getDefinition?: () => unknown } }
| undefined;
expect(startOpts?.filter?.getDefinition?.()).toEqual({
@@ -1703,7 +1703,7 @@ describe("MatrixClient crypto bootstrapping", () => {
await client.start();
expect(databasesSpy).toHaveBeenCalled();
const intervalCall = setIntervalSpy.mock.calls[0] as unknown[];
const intervalCall = setIntervalSpy.mock.calls.at(0) as unknown[];
expect(intervalCall[0]).toBeTypeOf("function");
expect(intervalCall[1]).toBe(60_000);
client.stop();

View File

@@ -414,7 +414,7 @@ describe("mattermost inbound user posts", () => {
expect(mockState.enqueueSystemEvent).not.toHaveBeenCalled();
expect(mockState.dispatchReplyFromConfig).toHaveBeenCalledTimes(1);
const ctx = mockState.dispatchReplyFromConfig.mock.calls[0]?.[0].ctx;
const ctx = mockState.dispatchReplyFromConfig.mock.calls.at(0)?.[0].ctx;
expect(ctx?.BodyForAgent).toBe("hello from mattermost");
expect(ctx?.ConversationLabel).toBe("Town Square id:chan-1");
expect(ctx?.MessageSid).toBe("post-1");
@@ -484,7 +484,7 @@ describe("mattermost inbound user posts", () => {
await monitor;
expect(runtimeCore.channel.session.recordInboundSession).toHaveBeenCalledTimes(1);
const [recordCall] = runtimeCore.channel.session.recordInboundSession.mock.calls[0] ?? [];
const [recordCall] = runtimeCore.channel.session.recordInboundSession.mock.calls.at(0) ?? [];
expect(recordCall?.storePath).toBe("/tmp/openclaw-test-sessions.json");
expect(recordCall?.sessionKey).toBe("mattermost:default:channel:chan-1");
const updateLastRoute = recordCall?.updateLastRoute;

View File

@@ -114,7 +114,7 @@ describe("mattermost mention gating", () => {
expect(decision.dropReason).toBeNull();
expect(decision.shouldRequireMention).toBe(false);
expect(resolver).toHaveBeenCalledTimes(1);
const [resolverCall] = resolver.mock.calls[0] ?? [];
const [resolverCall] = resolver.mock.calls.at(0) ?? [];
expect(resolverCall).toStrictEqual({
cfg,
channel: "mattermost",
@@ -493,7 +493,8 @@ describe("deliverMattermostReplyWithDraftPreview", () => {
});
expect(updateMattermostPostSpy).toHaveBeenCalledTimes(1);
const [updateClient, updatePostId, updateParams] = updateMattermostPostSpy.mock.calls[0] ?? [];
const [updateClient, updatePostId, updateParams] =
updateMattermostPostSpy.mock.calls.at(0) ?? [];
expect(updateClient).toBe(client);
expect(updatePostId).toBe("preview-post-1");
expect(updateParams).toStrictEqual({ message: "Final answer" });

View File

@@ -109,7 +109,7 @@ describe("memory cli", () => {
const inactiveMemorySecretDiagnostic = "agents.defaults.memorySearch.remote.apiKey inactive"; // pragma: allowlist secret
function expectCliSync(sync: ReturnType<typeof vi.fn>) {
const syncCall = sync.mock.calls[0]?.[0] as
const syncCall = sync.mock.calls.at(0)?.[0] as
| { reason?: unknown; force?: unknown; progress?: unknown }
| undefined;
expect(syncCall?.reason).toBe("cli");
@@ -353,7 +353,7 @@ describe("memory cli", () => {
await runMemoryCli(["status"]);
const secretRefsCall = resolveCommandSecretRefsViaGateway.mock.calls[0]?.[0] as
const secretRefsCall = resolveCommandSecretRefsViaGateway.mock.calls.at(0)?.[0] as
| { config?: unknown; commandName?: unknown; targetIds?: unknown }
| undefined;
expect(secretRefsCall?.config).toBe(config);

View File

@@ -2498,7 +2498,7 @@ describe("memory-core dreaming phases", () => {
});
expect(subagent.run).toHaveBeenCalledTimes(1);
const firstRun = subagent.run.mock.calls[0]?.[0];
const firstRun = subagent.run.mock.calls.at(0)?.[0];
expect(firstRun?.message).toContain("Move backups to S3 Glacier.");
expect(firstRun?.message).toContain("Keep retention at 365 days.");
expect(firstRun?.model).toBe("anthropic/claude-sonnet-4-6");
@@ -2561,7 +2561,7 @@ describe("memory-core dreaming phases", () => {
});
expect(subagent.run).toHaveBeenCalledTimes(1);
const firstRun = subagent.run.mock.calls[0]?.[0];
const firstRun = subagent.run.mock.calls.at(0)?.[0];
expect(firstRun?.message).toContain("Move backups to S3 Glacier.");
expect(firstRun?.message).toContain("Keep retention at 365 days.");
expect(firstRun?.model).toBe("xai/grok-4.1-fast");

View File

@@ -161,7 +161,7 @@ describe("memory watcher config", () => {
await expectWatcherManager(cfg);
expect(watchMock).toHaveBeenCalledTimes(1);
const [watchedPaths, options] = watchMock.mock.calls[0] as unknown as [
const [watchedPaths, options] = watchMock.mock.calls.at(0) as unknown as [
string[],
Record<string, unknown>,
];
@@ -217,7 +217,7 @@ describe("memory watcher config", () => {
await expectWatcherManager(cfg);
expect(watchMock).toHaveBeenCalledTimes(1);
const [watchedPaths, options] = watchMock.mock.calls[0] as unknown as [
const [watchedPaths, options] = watchMock.mock.calls.at(0) as unknown as [
string[],
Record<string, unknown>,
];

View File

@@ -457,7 +457,7 @@ describe("QmdMemoryManager", () => {
};
const initialUpdateCalls = spawnMock.mock.calls.filter((call) => call[1]?.[0] === "update");
expect(initialUpdateCalls).toHaveLength(0);
const [, watchOptions] = watchMock.mock.calls[0] as unknown as [
const [, watchOptions] = watchMock.mock.calls.at(0) as unknown as [
string[],
{ ignored?: (watchPath: string) => boolean },
];
@@ -3719,7 +3719,7 @@ describe("QmdMemoryManager", () => {
const firstSync = first.manager.sync({ reason: "manual", force: true });
await vi.advanceTimersByTimeAsync(0);
expect(embedChildren).toHaveLength(1);
const lockCall = withFileLockMock.mock.calls[0] as
const lockCall = withFileLockMock.mock.calls.at(0) as
| [
string,
{

View File

@@ -92,13 +92,13 @@ function readGatewayMethodOptions(
}
function readRespondPayload(respond: { mock: { calls: Array<Array<unknown>> } }): unknown {
const call = respond.mock.calls[0];
const call = respond.mock.calls.at(0);
expect(call?.[0]).toBe(true);
return call?.[1];
}
function readRespondError(respond: { mock: { calls: Array<Array<unknown>> } }): unknown {
const call = respond.mock.calls[0];
const call = respond.mock.calls.at(0);
expect(call?.[0]).toBe(false);
expect(call?.[1]).toBeUndefined();
return call?.[2];

View File

@@ -49,7 +49,7 @@ describe("minimax image-generation provider", () => {
function expectImageGenerationUrl(fetchMock: ReturnType<typeof vi.fn>, url: string) {
expect(fetchMock).toHaveBeenCalled();
const [actualUrl, init] = fetchMock.mock.calls[0] as [string, RequestInit | undefined];
const [actualUrl, init] = fetchMock.mock.calls.at(0) as [string, RequestInit | undefined];
expect(actualUrl).toBe(url);
expect(init?.method).toBe("POST");
}
@@ -83,7 +83,7 @@ describe("minimax image-generation provider", () => {
});
expect(fetchMock).toHaveBeenCalledOnce();
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
const [url, init] = fetchMock.mock.calls.at(0) as [string, RequestInit];
expect(url).toBe("https://api.minimax.io/v1/image_generation");
expect(init.method).toBe("POST");
expect(init.body).toBe(