Skip to content

Commit ea05be1

Browse files
committed
test: guard extension provider mock calls
1 parent 7bb2d20 commit ea05be1

16 files changed

Lines changed: 33 additions & 32 deletions

File tree

‎extensions/github-copilot/models.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ describe("fetchCopilotModelCatalog", () => {
491491
});
492492

493493
expect(fetchImpl).toHaveBeenCalledTimes(1);
494-
const [calledUrl, calledInit] = fetchImpl.mock.calls[0];
494+
const [calledUrl, calledInit] = fetchImpl.mock.calls.at(0) ?? [];
495495
expect(calledUrl).toBe("https://api.githubcopilot.com/models");
496496
expect((calledInit as RequestInit).method).toBe("GET");
497497
expect(((calledInit as RequestInit).headers as Record<string, string>).Authorization).toBe(
@@ -539,7 +539,7 @@ describe("fetchCopilotModelCatalog", () => {
539539
fetchImpl: fetchImpl as unknown as typeof fetch,
540540
});
541541

542-
expect(fetchImpl.mock.calls[0][0]).toBe("https://api.githubcopilot.com/models");
542+
expect(fetchImpl.mock.calls.at(0)?.[0]).toBe("https://api.githubcopilot.com/models");
543543
});
544544

545545
it("dedupes by id when API returns duplicates", async () => {

‎extensions/google-meet/src/cli.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ describe("google-meet CLI", () => {
811811
],
812812
{ from: "user" },
813813
);
814-
const gatewayCall = callGatewayFromCli.mock.calls[0] as unknown as
814+
const gatewayCall = callGatewayFromCli.mock.calls.at(0) as unknown as
815815
| [
816816
string,
817817
{ json?: boolean; timeout?: unknown },
@@ -1144,7 +1144,7 @@ describe("google-meet CLI", () => {
11441144
expectFields(checks[0], { id: "oauth-config", ok: true });
11451145
expectFields(checks[1], { id: "oauth-token", ok: true });
11461146
expect(ensureRuntime).not.toHaveBeenCalled();
1147-
const body = fetchMock.mock.calls[0]?.[1]?.body as URLSearchParams;
1147+
const body = fetchMock.mock.calls.at(0)?.[1]?.body as URLSearchParams;
11481148
expect(body.get("grant_type")).toBe("refresh_token");
11491149
} finally {
11501150
stdout.restore();

‎extensions/imessage/src/monitor.watch-subscribe-retry.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe("monitorIMessageProvider watch.subscribe startup retry", () => {
109109
{ timeoutMs: 10_000 },
110110
);
111111
expect(runtime.log).toHaveBeenCalledTimes(1);
112-
expect(String(runtime.log.mock.calls[0][0])).toContain(
112+
expect(String(runtime.log.mock.calls.at(0)?.[0])).toContain(
113113
"imessage: watch.subscribe startup failed (attempt 1/3): Error: imsg rpc timeout (watch.subscribe); retrying",
114114
);
115115
expect(
@@ -141,7 +141,7 @@ describe("monitorIMessageProvider watch.subscribe startup retry", () => {
141141
expect((monitorError as Error).message).toContain("imsg rpc timeout (watch.subscribe)");
142142
expect(createIMessageRpcClientMock).toHaveBeenCalledTimes(3);
143143
expect(runtime.error).toHaveBeenCalledTimes(1);
144-
expect(String(runtime.error.mock.calls[0][0])).toContain(
144+
expect(String(runtime.error.mock.calls.at(0)?.[0])).toContain(
145145
"imessage: monitor failed: Error: imsg rpc timeout (watch.subscribe)",
146146
);
147147
});

‎extensions/line/src/rich-menu.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ describe("uploadRichMenuImage", () => {
266266

267267
expect(MessagingApiBlobClientMock).toHaveBeenCalledWith({ channelAccessToken: "line-token" });
268268
expect(setRichMenuImageMock).toHaveBeenCalledOnce();
269-
const [richMenuId, blob] = setRichMenuImageMock.mock.calls[0] ?? [];
269+
const [richMenuId, blob] = setRichMenuImageMock.mock.calls.at(0) ?? [];
270270
expect(richMenuId).toBe("rich-menu-1");
271271
expect(blob).toBeInstanceOf(Blob);
272272
expect((blob as Blob).type).toBe("image/png");
@@ -306,7 +306,7 @@ describe("uploadRichMenuImage", () => {
306306
});
307307

308308
expect(setRichMenuImageMock).toHaveBeenCalledOnce();
309-
const blob = setRichMenuImageMock.mock.calls[0]?.[1] as Blob;
309+
const blob = setRichMenuImageMock.mock.calls.at(0)?.[1] as Blob;
310310
expect(blob.type).toBe("image/jpeg");
311311
await expect(blob.arrayBuffer()).resolves.toEqual(
312312
imageBytes.buffer.slice(imageBytes.byteOffset, imageBytes.byteOffset + imageBytes.byteLength),

‎extensions/llm-task/src/llm-task-tool.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function resetRunnerMocks() {
8888
async function executeEmbeddedRun(input: Record<string, unknown>) {
8989
const tool = createLlmTaskTool(fakeApi());
9090
await tool.execute("id", input);
91-
return (runEmbeddedPiAgent as any).mock.calls[0]?.[0];
91+
return (runEmbeddedPiAgent as any).mock.calls.at(0)?.[0];
9292
}
9393

9494
describe("llm-task tool (json-only)", () => {
@@ -238,7 +238,7 @@ describe("llm-task tool (json-only)", () => {
238238

239239
await tool.execute("id", { prompt: "x", model: "gemini-flash" });
240240

241-
const call = (runEmbeddedPiAgent as any).mock.calls[0]?.[0];
241+
const call = (runEmbeddedPiAgent as any).mock.calls.at(0)?.[0];
242242
expect(call.provider).toBe("google");
243243
expect(call.model).toBe("gemini-3-flash-preview");
244244
});

‎extensions/matrix/src/matrix/draft-stream.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ describe("createMatrixDraftStream", () => {
349349
await stream.stop();
350350

351351
expect(sendMessageMock).toHaveBeenCalledTimes(1);
352-
expect(sendMessageMock.mock.calls[0]?.[1]).toHaveProperty("org.matrix.msc4357.live");
352+
expect(sendMessageMock.mock.calls.at(0)?.[1]).toHaveProperty("org.matrix.msc4357.live");
353353
});
354354

355355
it("finalizeLive clears the live marker at most once", async () => {
@@ -367,7 +367,7 @@ describe("createMatrixDraftStream", () => {
367367
await stream.finalizeLive();
368368

369369
expect(sendMessageMock).toHaveBeenCalledTimes(2);
370-
expect(sendMessageMock.mock.calls[1]?.[1]).not.toHaveProperty("org.matrix.msc4357.live");
370+
expect(sendMessageMock.mock.calls.at(1)?.[1]).not.toHaveProperty("org.matrix.msc4357.live");
371371
});
372372

373373
it("marks live finalize failures for normal final delivery fallback", async () => {

‎extensions/matrix/src/matrix/monitor/handler.thread-root-media.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
1414
}
1515

1616
function readFirstMockArg(fn: unknown): unknown {
17-
return (fn as { mock: { calls: unknown[][] } }).mock.calls[0]?.[0];
17+
return (fn as { mock: { calls: unknown[][] } }).mock.calls.at(0)?.[0];
1818
}
1919

2020
describe("createMatrixRoomMessageHandler thread root media", () => {
@@ -79,7 +79,7 @@ describe("createMatrixRoomMessageHandler thread root media", () => {
7979

8080
expect(formatAgentEnvelope).toHaveBeenCalledTimes(1);
8181
const envelope = requireRecord(
82-
formatAgentEnvelope.mock.calls[0]?.[0],
82+
formatAgentEnvelope.mock.calls.at(0)?.[0],
8383
"format agent envelope params",
8484
);
8585
expect(String(envelope.body)).toContain("replying");

‎extensions/matrix/src/matrix/sdk.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ describe("MatrixClient crypto bootstrapping", () => {
16781678

16791679
await client.start();
16801680

1681-
const startOpts = matrixJsClient.startClient.mock.calls[0]?.[0] as
1681+
const startOpts = matrixJsClient.startClient.mock.calls.at(0)?.[0] as
16821682
| { filter?: { getDefinition?: () => unknown } }
16831683
| undefined;
16841684
expect(startOpts?.filter?.getDefinition?.()).toEqual({
@@ -1703,7 +1703,7 @@ describe("MatrixClient crypto bootstrapping", () => {
17031703
await client.start();
17041704

17051705
expect(databasesSpy).toHaveBeenCalled();
1706-
const intervalCall = setIntervalSpy.mock.calls[0] as unknown[];
1706+
const intervalCall = setIntervalSpy.mock.calls.at(0) as unknown[];
17071707
expect(intervalCall[0]).toBeTypeOf("function");
17081708
expect(intervalCall[1]).toBe(60_000);
17091709
client.stop();

‎extensions/mattermost/src/mattermost/monitor.inbound-system-event.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ describe("mattermost inbound user posts", () => {
414414

415415
expect(mockState.enqueueSystemEvent).not.toHaveBeenCalled();
416416
expect(mockState.dispatchReplyFromConfig).toHaveBeenCalledTimes(1);
417-
const ctx = mockState.dispatchReplyFromConfig.mock.calls[0]?.[0].ctx;
417+
const ctx = mockState.dispatchReplyFromConfig.mock.calls.at(0)?.[0].ctx;
418418
expect(ctx?.BodyForAgent).toBe("hello from mattermost");
419419
expect(ctx?.ConversationLabel).toBe("Town Square id:chan-1");
420420
expect(ctx?.MessageSid).toBe("post-1");
@@ -484,7 +484,7 @@ describe("mattermost inbound user posts", () => {
484484
await monitor;
485485

486486
expect(runtimeCore.channel.session.recordInboundSession).toHaveBeenCalledTimes(1);
487-
const [recordCall] = runtimeCore.channel.session.recordInboundSession.mock.calls[0] ?? [];
487+
const [recordCall] = runtimeCore.channel.session.recordInboundSession.mock.calls.at(0) ?? [];
488488
expect(recordCall?.storePath).toBe("/tmp/openclaw-test-sessions.json");
489489
expect(recordCall?.sessionKey).toBe("mattermost:default:channel:chan-1");
490490
const updateLastRoute = recordCall?.updateLastRoute;

‎extensions/mattermost/src/mattermost/monitor.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe("mattermost mention gating", () => {
114114
expect(decision.dropReason).toBeNull();
115115
expect(decision.shouldRequireMention).toBe(false);
116116
expect(resolver).toHaveBeenCalledTimes(1);
117-
const [resolverCall] = resolver.mock.calls[0] ?? [];
117+
const [resolverCall] = resolver.mock.calls.at(0) ?? [];
118118
expect(resolverCall).toStrictEqual({
119119
cfg,
120120
channel: "mattermost",
@@ -493,7 +493,8 @@ describe("deliverMattermostReplyWithDraftPreview", () => {
493493
});
494494

495495
expect(updateMattermostPostSpy).toHaveBeenCalledTimes(1);
496-
const [updateClient, updatePostId, updateParams] = updateMattermostPostSpy.mock.calls[0] ?? [];
496+
const [updateClient, updatePostId, updateParams] =
497+
updateMattermostPostSpy.mock.calls.at(0) ?? [];
497498
expect(updateClient).toBe(client);
498499
expect(updatePostId).toBe("preview-post-1");
499500
expect(updateParams).toStrictEqual({ message: "Final answer" });

0 commit comments

Comments
 (0)