test: guard gateway session mock calls · openclaw/openclaw@138421b
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -163,7 +163,7 @@ function createLog() {
|
163 | 163 | } |
164 | 164 | |
165 | 165 | function firstCallArg<T>(mock: { mock: { calls: unknown[][] } }, _type?: (value: T) => T): T { |
166 | | -const call = mock.mock.calls[0]; |
| 166 | +const call = mock.mock.calls.at(0); |
167 | 167 | if (!call) { |
168 | 168 | throw new Error("Expected first mock call"); |
169 | 169 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,7 @@ let shouldSkipStartupModelPrewarm: typeof import("./server-startup-post-attach.j
|
38 | 38 | |
39 | 39 | function expectModelsJsonPrewarmCall(cfg: OpenClawConfig) { |
40 | 40 | expect(ensureOpenClawModelsJsonMock).toHaveBeenCalledTimes(1); |
41 | | -const [calledConfig, agentDir, options] = ensureOpenClawModelsJsonMock.mock.calls[0] ?? []; |
| 41 | +const [calledConfig, agentDir, options] = ensureOpenClawModelsJsonMock.mock.calls.at(0) ?? []; |
42 | 42 | expect(calledConfig).toBe(cfg); |
43 | 43 | expect(agentDir).toBe("/tmp/agent"); |
44 | 44 | expect(options).toEqual({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -365,7 +365,7 @@ function expectFailureAnnounceCall(params: {
|
365 | 365 | message: string; |
366 | 366 | }) { |
367 | 367 | expect(sendFailureNotificationAnnounceMock).toHaveBeenCalledTimes(1); |
368 | | -const call = sendFailureNotificationAnnounceMock.mock.calls[0]; |
| 368 | +const call = sendFailureNotificationAnnounceMock.mock.calls.at(0); |
369 | 369 | if (!call) { |
370 | 370 | throw new Error("expected failure announcement call"); |
371 | 371 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -147,7 +147,7 @@ describe("sessions_send gateway loopback", () => {
|
147 | 147 | expect(details.reply).toBe("pong"); |
148 | 148 | expect(details.sessionKey).toBe("main"); |
149 | 149 | |
150 | | -const firstCall = spy.mock.calls[0]?.[0] as |
| 150 | +const firstCall = spy.mock.calls.at(0)?.[0] as |
151 | 151 | | { lane?: string; inputProvenance?: { kind?: string; sourceTool?: string } } |
152 | 152 | | undefined; |
153 | 153 | expect(firstCall?.lane).toMatch(/^nested(?::|$)/); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -262,7 +262,7 @@ test("sessions.compact without maxLines runs embedded manual compaction for chec
|
262 | 262 | expect(compacted.payload?.key).toBe("agent:main:main"); |
263 | 263 | expect(compacted.payload?.compacted).toBe(true); |
264 | 264 | expect(embeddedRunMock.compactEmbeddedPiSession).toHaveBeenCalledTimes(1); |
265 | | -const compactionCall = embeddedRunMock.compactEmbeddedPiSession.mock.calls[0]?.[0] as |
| 265 | +const compactionCall = embeddedRunMock.compactEmbeddedPiSession.mock.calls.at(0)?.[0] as |
266 | 266 | | { |
267 | 267 | agentHarnessId?: string; |
268 | 268 | allowGatewaySubagentBinding?: boolean; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -30,7 +30,7 @@ function requireRecord(value: unknown): Record<string, unknown> {
|
30 | 30 | } |
31 | 31 | |
32 | 32 | function requireFirstCallArg(mock: { mock: { calls: readonly (readonly unknown[])[] } }) { |
33 | | -const call = mock.mock.calls[0]; |
| 33 | +const call = mock.mock.calls.at(0); |
34 | 34 | if (!call) { |
35 | 35 | throw new Error("Expected first mock call"); |
36 | 36 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -173,7 +173,7 @@ test("sessions.reset closes ACP runtime handles for ACP sessions", async () => {
|
173 | 173 | expect(reset.ok).toBe(true); |
174 | 174 | expectResetAcpState(reset.payload?.entry.acp); |
175 | 175 | expect(acpManagerMocks.closeSession).toHaveBeenCalledTimes(1); |
176 | | -const closeSessionCall = acpManagerMocks.closeSession.mock.calls[0] as unknown as |
| 176 | +const closeSessionCall = acpManagerMocks.closeSession.mock.calls.at(0) as unknown as |
177 | 177 | | [ |
178 | 178 | { |
179 | 179 | allowBackendUnavailable?: boolean; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,7 @@ type HookEventRecord = Record<string, unknown> & {
|
26 | 26 | }; |
27 | 27 | |
28 | 28 | function firstHookCall(mock: { mock: { calls: unknown[][] } }): [HookEventRecord, HookEventRecord] { |
29 | | -const call = mock.mock.calls[0]; |
| 29 | +const call = mock.mock.calls.at(0); |
30 | 30 | if (!call) { |
31 | 31 | throw new Error("Expected hook call"); |
32 | 32 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -87,7 +87,7 @@ async function withAcmeSpeechProvider(
|
87 | 87 | |
88 | 88 | function expectSingleSynthesizeSpeechCall() { |
89 | 89 | expect(synthesizeSpeechMock).toHaveBeenCalledTimes(1); |
90 | | -const params = synthesizeSpeechMock.mock.calls[0]?.[0]; |
| 90 | +const params = synthesizeSpeechMock.mock.calls.at(0)?.[0]; |
91 | 91 | if (params === undefined) { |
92 | 92 | throw new Error("expected synthesizeSpeech call params"); |
93 | 93 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ describe("broadcastPresenceSnapshot", () => {
|
18 | 18 | expect(getHealthVersion).toHaveBeenCalledTimes(1); |
19 | 19 | expect(broadcast).toHaveBeenCalledTimes(1); |
20 | 20 | |
21 | | -const [event, payload, opts] = broadcast.mock.calls[0] as [ |
| 21 | +const [event, payload, opts] = broadcast.mock.calls.at(0) as [ |
22 | 22 | string, |
23 | 23 | unknown, |
24 | 24 | { dropIfSlow?: boolean; stateVersion?: { presence?: number; health?: number } } | undefined, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。