test: guard gateway mock calls · openclaw/openclaw@a68b4a5
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,7 @@ describe("warnLegacyOpenClawEnvVars", () => {
|
31 | 31 | }); |
32 | 32 | |
33 | 33 | expect(emitWarning).toHaveBeenCalledOnce(); |
34 | | -const [message, options] = emitWarning.mock.calls[0] as [ |
| 34 | +const [message, options] = emitWarning.mock.calls.at(0) as [ |
35 | 35 | string, |
36 | 36 | { code: string; type: string }, |
37 | 37 | ]; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -157,7 +157,7 @@ describe("handleGatewayPostJsonEndpoint", () => {
|
157 | 157 | }, |
158 | 158 | ); |
159 | 159 | |
160 | | -const [, requestAuth] = (resolveOperatorScopes.mock.calls[0] as unknown as |
| 160 | +const [, requestAuth] = (resolveOperatorScopes.mock.calls.at(0) as unknown as |
161 | 161 | | [IncomingMessage, { authMethod?: string; trustDeclaredOperatorScopes: boolean }] |
162 | 162 | | undefined) ?? [undefined, undefined]; |
163 | 163 | expect(requestAuth?.authMethod).toBe("token"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -519,7 +519,7 @@ describe("mcp loopback server", () => {
|
519 | 519 | expect(response.status).toBe(200); |
520 | 520 | expect(payload.result?.isError).toBe(false); |
521 | 521 | expect(execute).toHaveBeenCalledTimes(1); |
522 | | -const [callId, params, signal] = execute.mock.calls[0] ?? []; |
| 522 | +const [callId, params, signal] = execute.mock.calls.at(0) ?? []; |
523 | 523 | expect(callId).toMatch(/^mcp-/); |
524 | 524 | expect(params).toEqual({ body: "hello" }); |
525 | 525 | expect(signal).toBeInstanceOf(AbortSignal); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -183,7 +183,7 @@ function expectResponseError(
|
183 | 183 | respond: ReturnType<typeof vi.fn>, |
184 | 184 | expected: { code?: string; messageIncludes?: string }, |
185 | 185 | ) { |
186 | | -const call = respond.mock.calls[0]; |
| 186 | +const call = respond.mock.calls.at(0); |
187 | 187 | if (!call) { |
188 | 188 | throw new Error("expected response call"); |
189 | 189 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -113,7 +113,7 @@ function mockRotateOperatorTokenSuccess(): void {
|
113 | 113 | function expectRespondedErrorMessage(opts: GatewayRequestHandlerOptions, message: string): void { |
114 | 114 | const respond = opts.respond as ReturnType<typeof vi.fn>; |
115 | 115 | expect(respond).toHaveBeenCalledTimes(1); |
116 | | -const call = respond.mock.calls[0] as unknown as [boolean, unknown, { message?: string }]; |
| 116 | +const call = respond.mock.calls.at(0) as unknown as [boolean, unknown, { message?: string }]; |
117 | 117 | expect(call[0]).toBe(false); |
118 | 118 | expect(call[1]).toBeUndefined(); |
119 | 119 | expect(call[2]?.message).toBe(message); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -40,7 +40,11 @@ async function callEnvironmentMethod(
|
40 | 40 | respond, |
41 | 41 | context: mockContext(), |
42 | 42 | } as never); |
43 | | -return respond.mock.calls[0]; |
| 43 | +const call = respond.mock.calls.at(0); |
| 44 | +if (call === undefined) { |
| 45 | +throw new Error("expected environments handler to respond"); |
| 46 | +} |
| 47 | +return call; |
44 | 48 | } |
45 | 49 | |
46 | 50 | beforeEach(() => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -236,7 +236,7 @@ describe("models.list", () => {
|
236 | 236 | } as never, |
237 | 237 | }); |
238 | 238 | |
239 | | -const call = respond.mock.calls[0] as |
| 239 | +const call = respond.mock.calls.at(0) as |
240 | 240 | | [boolean, unknown, { code?: number; message?: string }] |
241 | 241 | | undefined; |
242 | 242 | expect(call?.[0]).toBe(false); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -55,7 +55,7 @@ describe("native hook relay gateway method", () => {
|
55 | 55 | context: {} as never, |
56 | 56 | }); |
57 | 57 | |
58 | | -const call = respond.mock.calls[0] as |
| 58 | +const call = respond.mock.calls.at(0) as |
59 | 59 | | [boolean, unknown, { code?: string; message?: string }] |
60 | 60 | | undefined; |
61 | 61 | expect(call?.[0]).toBe(false); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -53,7 +53,7 @@ function expectRespondError(
|
53 | 53 | respond: ReturnType<typeof vi.fn>, |
54 | 54 | expected: { code: string; message?: string }, |
55 | 55 | ): void { |
56 | | -const call = respond.mock.calls[0]; |
| 56 | +const call = respond.mock.calls.at(0); |
57 | 57 | expect(call?.[0]).toBe(false); |
58 | 58 | expect(call?.[1]).toBeUndefined(); |
59 | 59 | const error = requireRecord(call?.[2]); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1014,7 +1014,7 @@ describe("gateway send mirroring", () => {
|
1014 | 1014 | idempotencyKey: "idem-send-options", |
1015 | 1015 | }); |
1016 | 1016 | |
1017 | | -const options = mocks.deliverOutboundPayloads.mock.calls[0]?.[0]; |
| 1017 | +const options = mocks.deliverOutboundPayloads.mock.calls.at(0)?.[0]; |
1018 | 1018 | expect(options?.forceDocument).toBe(true); |
1019 | 1019 | expect(options?.silent).toBe(true); |
1020 | 1020 | expect(options?.formatting).toEqual({ parseMode: "HTML" }); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。