test: guard core support mock calls · openclaw/openclaw@9d4081b
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -45,7 +45,11 @@ describe("createApprovalNativeRouteReporter", () => {
|
45 | 45 | }); |
46 | 46 | |
47 | 47 | expect(setTimeoutSpy).toHaveBeenCalledTimes(1); |
48 | | -const [cleanupCallback, cleanupDelayMs] = setTimeoutSpy.mock.calls[0]; |
| 48 | +const cleanupCall = setTimeoutSpy.mock.calls.at(0); |
| 49 | +if (cleanupCall === undefined) { |
| 50 | +throw new Error("expected cleanup timeout call"); |
| 51 | +} |
| 52 | +const [cleanupCallback, cleanupDelayMs] = cleanupCall; |
49 | 53 | expect(cleanupDelayMs).toBe(5 * 60_000); |
50 | 54 | expect(cleanupCallback).toBeTypeOf("function"); |
51 | 55 | } finally { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -369,7 +369,7 @@ describe("runHeartbeatOnce commitments", () => {
|
369 | 369 | runner.stop(); |
370 | 370 | |
371 | 371 | expect(runOnce).toHaveBeenCalledTimes(1); |
372 | | -const runOptions = runOnce.mock.calls[0]?.[0] as |
| 372 | +const runOptions = runOnce.mock.calls.at(0)?.[0] as |
373 | 373 | | { agentId?: string; heartbeat?: { target?: string }; sessionKey?: string } |
374 | 374 | | undefined; |
375 | 375 | expect(runOptions?.agentId).toBe("main"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -462,7 +462,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
462 | 462 | }); |
463 | 463 | |
464 | 464 | expect(sendTelegram).toHaveBeenCalledTimes(1); |
465 | | -const [chatId, text, options] = sendTelegram.mock.calls[0] ?? []; |
| 465 | +const [chatId, text, options] = sendTelegram.mock.calls.at(0) ?? []; |
466 | 466 | expect(chatId).toBe(TELEGRAM_GROUP); |
467 | 467 | expect(text).toBe("Hello from heartbeat"); |
468 | 468 | expect(options?.accountId).toBe(params.expectedAccountId); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -92,7 +92,11 @@ describe("installFromNpmSpecArchive", () => {
|
92 | 92 | expect(installFromArchive).not.toHaveBeenCalled(); |
93 | 93 | const withTempDirMock = vi.mocked(withTempDir); |
94 | 94 | expect(withTempDirMock).toHaveBeenCalledTimes(1); |
95 | | -const [tempDirPrefix, tempDirCallback] = withTempDirMock.mock.calls[0]; |
| 95 | +const tempDirCall = withTempDirMock.mock.calls.at(0); |
| 96 | +if (tempDirCall === undefined) { |
| 97 | +throw new Error("expected temp dir call"); |
| 98 | +} |
| 99 | +const [tempDirPrefix, tempDirCallback] = tempDirCall; |
96 | 100 | expect(tempDirPrefix).toBe("openclaw-test-"); |
97 | 101 | expect(tempDirCallback).toBeTypeOf("function"); |
98 | 102 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -171,7 +171,7 @@ describe("sendMessage channel normalization", () => {
|
171 | 171 | }, |
172 | 172 | assertDeps: (deps: { localchat?: ReturnType<typeof vi.fn> }) => { |
173 | 173 | expect(deps.localchat).toHaveBeenCalledTimes(1); |
174 | | -const [to, text, options] = deps.localchat?.mock.calls[0] ?? []; |
| 174 | +const [to, text, options] = deps.localchat?.mock.calls.at(0) ?? []; |
175 | 175 | expect(to).toBe("someone@example.com"); |
176 | 176 | expect(text).toBe("hi"); |
177 | 177 | expect(typeof options).toBe("object"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -126,7 +126,7 @@ function expectSingleCallFirstArg(
|
126 | 126 | label = "mock first argument", |
127 | 127 | ): Record<string, unknown> { |
128 | 128 | expect(mock.mock.calls).toHaveLength(1); |
129 | | -const [firstArg] = mock.mock.calls[0] ?? []; |
| 129 | +const [firstArg] = mock.mock.calls.at(0) ?? []; |
130 | 130 | return requireRecord(firstArg, label); |
131 | 131 | } |
132 | 132 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -316,7 +316,7 @@ export function describeGithubCopilotProviderDiscoveryContract(params: {
|
316 | 316 | }, |
317 | 317 | }); |
318 | 318 | const copilotCall = requireRecord( |
319 | | -resolveCopilotApiTokenMock.mock.calls[0]?.[0], |
| 319 | +resolveCopilotApiTokenMock.mock.calls.at(0)?.[0], |
320 | 320 | "copilot token params", |
321 | 321 | ); |
322 | 322 | expect(copilotCall.githubToken).toBe("github-env-token"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -566,7 +566,7 @@ describe("EmbeddedTuiBackend", () => {
|
566 | 566 | await flushMicrotasks(); |
567 | 567 | |
568 | 568 | expect(agentCommandFromIngressMock).toHaveBeenCalledTimes(1); |
569 | | -const ingressOptions = agentCommandFromIngressMock.mock.calls[0]?.[0] as |
| 569 | +const ingressOptions = agentCommandFromIngressMock.mock.calls.at(0)?.[0] as |
570 | 570 | | { timeout?: unknown } |
571 | 571 | | undefined; |
572 | 572 | expect(ingressOptions?.timeout).toBe("300"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -181,7 +181,7 @@ describe("custom theme import helpers", () => {
|
181 | 181 | expect(imported.label).toBe("Light Green"); |
182 | 182 | const fetchMock = vi.mocked(fetchImpl); |
183 | 183 | expect(fetchMock).toHaveBeenCalledTimes(1); |
184 | | -const [fetchUrl, fetchOptions] = fetchMock.mock.calls[0] as [ |
| 184 | +const [fetchUrl, fetchOptions] = fetchMock.mock.calls.at(0) as [ |
185 | 185 | string, |
186 | 186 | { headers?: unknown; redirect?: unknown; signal?: unknown }, |
187 | 187 | ]; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -297,7 +297,7 @@ describe("GoogleLiveRealtimeTalkTransport", () => {
|
297 | 297 | ]); |
298 | 298 | expect(onTranscript).toHaveBeenCalledWith({ role: "user", text: "hello", final: true }); |
299 | 299 | expect(onTranscript).toHaveBeenCalledWith({ role: "assistant", text: "hi", final: false }); |
300 | | -const audioEvent = onTalkEvent.mock.calls[2]?.[0]; |
| 300 | +const audioEvent = onTalkEvent.mock.calls.at(2)?.[0]; |
301 | 301 | expect(audioEvent?.payload).toStrictEqual({ byteLength: 4, mimeType: "audio/pcm;rate=24000" }); |
302 | 302 | expect(audioEvent?.sessionId).toBe("main:google:provider-websocket"); |
303 | 303 | expect(audioEvent?.transport).toBe("provider-websocket"); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。