diff --git a/src/gateway/env-deprecation.test.ts b/src/gateway/env-deprecation.test.ts index c04bbad1af5..63afb7c40af 100644 --- a/src/gateway/env-deprecation.test.ts +++ b/src/gateway/env-deprecation.test.ts @@ -31,7 +31,7 @@ describe("warnLegacyOpenClawEnvVars", () => { }); expect(emitWarning).toHaveBeenCalledOnce(); - const [message, options] = emitWarning.mock.calls[0] as [ + const [message, options] = emitWarning.mock.calls.at(0) as [ string, { code: string; type: string }, ]; diff --git a/src/gateway/http-endpoint-helpers.test.ts b/src/gateway/http-endpoint-helpers.test.ts index 36d7c6b7ecf..cb66b1df7a6 100644 --- a/src/gateway/http-endpoint-helpers.test.ts +++ b/src/gateway/http-endpoint-helpers.test.ts @@ -157,7 +157,7 @@ describe("handleGatewayPostJsonEndpoint", () => { }, ); - const [, requestAuth] = (resolveOperatorScopes.mock.calls[0] as unknown as + const [, requestAuth] = (resolveOperatorScopes.mock.calls.at(0) as unknown as | [IncomingMessage, { authMethod?: string; trustDeclaredOperatorScopes: boolean }] | undefined) ?? [undefined, undefined]; expect(requestAuth?.authMethod).toBe("token"); diff --git a/src/gateway/mcp-http.test.ts b/src/gateway/mcp-http.test.ts index f79545298b5..ff758c64d8e 100644 --- a/src/gateway/mcp-http.test.ts +++ b/src/gateway/mcp-http.test.ts @@ -519,7 +519,7 @@ describe("mcp loopback server", () => { expect(response.status).toBe(200); expect(payload.result?.isError).toBe(false); expect(execute).toHaveBeenCalledTimes(1); - const [callId, params, signal] = execute.mock.calls[0] ?? []; + const [callId, params, signal] = execute.mock.calls.at(0) ?? []; expect(callId).toMatch(/^mcp-/); expect(params).toEqual({ body: "hello" }); expect(signal).toBeInstanceOf(AbortSignal); diff --git a/src/gateway/server-methods/cron.validation.test.ts b/src/gateway/server-methods/cron.validation.test.ts index a4f83c43097..5443e5284d0 100644 --- a/src/gateway/server-methods/cron.validation.test.ts +++ b/src/gateway/server-methods/cron.validation.test.ts @@ -183,7 +183,7 @@ function expectResponseError( respond: ReturnType, expected: { code?: string; messageIncludes?: string }, ) { - const call = respond.mock.calls[0]; + const call = respond.mock.calls.at(0); if (!call) { throw new Error("expected response call"); } diff --git a/src/gateway/server-methods/devices.test.ts b/src/gateway/server-methods/devices.test.ts index fae9405a8e8..b8c929d3d67 100644 --- a/src/gateway/server-methods/devices.test.ts +++ b/src/gateway/server-methods/devices.test.ts @@ -113,7 +113,7 @@ function mockRotateOperatorTokenSuccess(): void { function expectRespondedErrorMessage(opts: GatewayRequestHandlerOptions, message: string): void { const respond = opts.respond as ReturnType; expect(respond).toHaveBeenCalledTimes(1); - const call = respond.mock.calls[0] as unknown as [boolean, unknown, { message?: string }]; + const call = respond.mock.calls.at(0) as unknown as [boolean, unknown, { message?: string }]; expect(call[0]).toBe(false); expect(call[1]).toBeUndefined(); expect(call[2]?.message).toBe(message); diff --git a/src/gateway/server-methods/environments.test.ts b/src/gateway/server-methods/environments.test.ts index 04c7af49619..f66c93f91b4 100644 --- a/src/gateway/server-methods/environments.test.ts +++ b/src/gateway/server-methods/environments.test.ts @@ -40,7 +40,11 @@ async function callEnvironmentMethod( respond, context: mockContext(), } as never); - return respond.mock.calls[0]; + const call = respond.mock.calls.at(0); + if (call === undefined) { + throw new Error("expected environments handler to respond"); + } + return call; } beforeEach(() => { diff --git a/src/gateway/server-methods/models.test.ts b/src/gateway/server-methods/models.test.ts index 7e0adfedf96..aa95bffc01d 100644 --- a/src/gateway/server-methods/models.test.ts +++ b/src/gateway/server-methods/models.test.ts @@ -236,7 +236,7 @@ describe("models.list", () => { } as never, }); - const call = respond.mock.calls[0] as + const call = respond.mock.calls.at(0) as | [boolean, unknown, { code?: number; message?: string }] | undefined; expect(call?.[0]).toBe(false); diff --git a/src/gateway/server-methods/native-hook-relay.test.ts b/src/gateway/server-methods/native-hook-relay.test.ts index a4cc03917de..a546882dec5 100644 --- a/src/gateway/server-methods/native-hook-relay.test.ts +++ b/src/gateway/server-methods/native-hook-relay.test.ts @@ -55,7 +55,7 @@ describe("native hook relay gateway method", () => { context: {} as never, }); - const call = respond.mock.calls[0] as + const call = respond.mock.calls.at(0) as | [boolean, unknown, { code?: string; message?: string }] | undefined; expect(call?.[0]).toBe(false); diff --git a/src/gateway/server-methods/secrets.test.ts b/src/gateway/server-methods/secrets.test.ts index 91256527786..6b5cd983703 100644 --- a/src/gateway/server-methods/secrets.test.ts +++ b/src/gateway/server-methods/secrets.test.ts @@ -53,7 +53,7 @@ function expectRespondError( respond: ReturnType, expected: { code: string; message?: string }, ): void { - const call = respond.mock.calls[0]; + const call = respond.mock.calls.at(0); expect(call?.[0]).toBe(false); expect(call?.[1]).toBeUndefined(); const error = requireRecord(call?.[2]); diff --git a/src/gateway/server-methods/send.test.ts b/src/gateway/server-methods/send.test.ts index 3045e0aae15..6ef666bf769 100644 --- a/src/gateway/server-methods/send.test.ts +++ b/src/gateway/server-methods/send.test.ts @@ -1014,7 +1014,7 @@ describe("gateway send mirroring", () => { idempotencyKey: "idem-send-options", }); - const options = mocks.deliverOutboundPayloads.mock.calls[0]?.[0]; + const options = mocks.deliverOutboundPayloads.mock.calls.at(0)?.[0]; expect(options?.forceDocument).toBe(true); expect(options?.silent).toBe(true); expect(options?.formatting).toEqual({ parseMode: "HTML" }); diff --git a/src/gateway/server-methods/sessions.send-followup-status.test.ts b/src/gateway/server-methods/sessions.send-followup-status.test.ts index e098118b8d1..61fda04d964 100644 --- a/src/gateway/server-methods/sessions.send-followup-status.test.ts +++ b/src/gateway/server-methods/sessions.send-followup-status.test.ts @@ -110,7 +110,7 @@ describe("sessions.send completed subagent follow-up status", () => { isWebchatConnect: () => false, }); - const call = respondMock.mock.calls[0] as + const call = respondMock.mock.calls.at(0) as | [boolean, { runId?: string; status?: string; messageSeq?: number }, unknown?, unknown?] | undefined; expect(call?.[0]).toBe(true); diff --git a/src/gateway/server-methods/skills-upload.test.ts b/src/gateway/server-methods/skills-upload.test.ts index 07b57ac23c7..e2f77b9b277 100644 --- a/src/gateway/server-methods/skills-upload.test.ts +++ b/src/gateway/server-methods/skills-upload.test.ts @@ -141,7 +141,7 @@ function expectError(result: CallResult, code: string, message: string): void { } function firstCallArg(mock: { mock: { calls: unknown[][] } }, _type?: (value: T) => T): T { - const call = mock.mock.calls[0]; + const call = mock.mock.calls.at(0); if (!call) { throw new Error("Expected first mock call"); } diff --git a/src/gateway/server-methods/tts.test.ts b/src/gateway/server-methods/tts.test.ts index 5186f278a50..3b79b53f4d5 100644 --- a/src/gateway/server-methods/tts.test.ts +++ b/src/gateway/server-methods/tts.test.ts @@ -76,7 +76,7 @@ describe("ttsHandlers", () => { context: { getRuntimeConfig: mocks.getRuntimeConfig }, } as never); - const call = respond.mock.calls[0] as + const call = respond.mock.calls.at(0) as | [boolean, unknown, { code?: number; message?: string }] | undefined; expect(call?.[0]).toBe(false); diff --git a/src/gateway/server-methods/usage.test.ts b/src/gateway/server-methods/usage.test.ts index 8a9e9e6996c..d9b41a48ab0 100644 --- a/src/gateway/server-methods/usage.test.ts +++ b/src/gateway/server-methods/usage.test.ts @@ -157,7 +157,7 @@ describe("gateway usage helpers", () => { expect(a.totals.totalTokens).toBe(1); expect(b.totals.totalTokens).toBe(1); expect(vi.mocked(loadCostUsageSummaryFromCache)).toHaveBeenCalledTimes(1); - expect(vi.mocked(loadCostUsageSummaryFromCache).mock.calls[0]?.[0]?.refreshMode).toBe( + expect(vi.mocked(loadCostUsageSummaryFromCache).mock.calls.at(0)?.[0]?.refreshMode).toBe( "sync-when-empty", ); });