test: guard extension messaging mock calls · openclaw/openclaw@6a230a1
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -95,7 +95,7 @@ function registerProviderWithPluginConfig(pluginConfig: Record<string, unknown>)
|
95 | 95 | ); |
96 | 96 | |
97 | 97 | expect(registerProviderMock).toHaveBeenCalledTimes(1); |
98 | | -return registerProviderMock.mock.calls[0]?.[0]; |
| 98 | +return registerProviderMock.mock.calls.at(0)?.[0]; |
99 | 99 | } |
100 | 100 | |
101 | 101 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
@@ -106,7 +106,7 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
106 | 106 | } |
107 | 107 | |
108 | 108 | function requireConfiguredStreamParams(): Record<string, unknown> { |
109 | | -return requireRecord(createConfiguredOllamaStreamFnMock.mock.calls[0]?.[0], "stream params"); |
| 109 | +return requireRecord(createConfiguredOllamaStreamFnMock.mock.calls.at(0)?.[0], "stream params"); |
110 | 110 | } |
111 | 111 | |
112 | 112 | function captureWrappedOllamaPayload( |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1163,7 +1163,7 @@ describe("openai image generation provider", () => {
|
1163 | 1163 | ], |
1164 | 1164 | }); |
1165 | 1165 | |
1166 | | -const body = postJsonRequestMock.mock.calls[0]?.[0].body as { |
| 1166 | +const body = postJsonRequestMock.mock.calls.at(0)?.[0].body as { |
1167 | 1167 | input: Array<{ content: Array<Record<string, string>> }>; |
1168 | 1168 | }; |
1169 | 1169 | expect(body.input[0]?.content).toEqual([ |
@@ -1192,7 +1192,7 @@ describe("openai image generation provider", () => {
|
1192 | 1192 | }); |
1193 | 1193 | |
1194 | 1194 | expect(postJsonRequestMock).toHaveBeenCalledTimes(2); |
1195 | | -const firstBody = postJsonRequestMock.mock.calls[0]?.[0].body as { |
| 1195 | +const firstBody = postJsonRequestMock.mock.calls.at(0)?.[0].body as { |
1196 | 1196 | tools: Array<Record<string, unknown>>; |
1197 | 1197 | }; |
1198 | 1198 | expect(firstBody.tools[0]).toEqual({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -90,7 +90,7 @@ describe("runQaManualLane", () => {
|
90 | 90 | }); |
91 | 91 | |
92 | 92 | expect(startQaProviderServer).toHaveBeenCalledWith("mock-openai"); |
93 | | -const [gatewayOptions] = startQaGatewayChild.mock.calls[0] ?? []; |
| 93 | +const [gatewayOptions] = startQaGatewayChild.mock.calls.at(0) ?? []; |
94 | 94 | expect(gatewayOptions?.repoRoot).toBe("/tmp/openclaw-repo"); |
95 | 95 | expect(gatewayOptions?.providerMode).toBe("mock-openai"); |
96 | 96 | expect(gatewayOptions?.providerBaseUrl).toBe("http://127.0.0.1:44080/v1"); |
@@ -120,7 +120,7 @@ describe("runQaManualLane", () => {
|
120 | 120 | repoRoot: "/tmp/openclaw-repo", |
121 | 121 | embeddedGateway: "disabled", |
122 | 122 | }); |
123 | | -const [gatewayOptions] = startQaGatewayChild.mock.calls[0] ?? []; |
| 123 | +const [gatewayOptions] = startQaGatewayChild.mock.calls.at(0) ?? []; |
124 | 124 | expect(gatewayOptions?.providerMode).toBe("live-frontier"); |
125 | 125 | expect(gatewayOptions?.providerBaseUrl).toBeUndefined(); |
126 | 126 | expect(result.reply).toBe("Protocol note: mock reply."); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -51,7 +51,7 @@ describe("bridge/tools/remind", () => {
|
51 | 51 | time: "5m", |
52 | 52 | }); |
53 | 53 | |
54 | | -const addCall = callGatewayToolMock.mock.calls[0]; |
| 54 | +const addCall = callGatewayToolMock.mock.calls.at(0); |
55 | 55 | const addPayload = addCall?.[2] as CronAddToolPayload | undefined; |
56 | 56 | expect(addCall?.[0]).toBe("cron.add"); |
57 | 57 | expect(addCall?.[1]).toEqual({ timeoutMs: 60_000 }); |
@@ -103,7 +103,7 @@ describe("bridge/tools/remind", () => {
|
103 | 103 | time: "5m", |
104 | 104 | }); |
105 | 105 | |
106 | | -const cronParams = callCron.mock.calls[0]?.[0] as RemindCronAction | undefined; |
| 106 | +const cronParams = callCron.mock.calls.at(0)?.[0] as RemindCronAction | undefined; |
107 | 107 | expect(cronParams?.action).toBe("add"); |
108 | 108 | if (cronParams?.action !== "add") { |
109 | 109 | throw new Error("Expected add reminder cron params"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -50,7 +50,7 @@ describe("getImageSizeFromUrl", () => {
|
50 | 50 | await getImageSizeFromUrl("https://cdn.example.com/photo.png"); |
51 | 51 | |
52 | 52 | expect(adapterMocks.fetchMedia).toHaveBeenCalledOnce(); |
53 | | -const opts = adapterMocks.fetchMedia.mock.calls[0][0]; |
| 53 | +const opts = adapterMocks.fetchMedia.mock.calls.at(0)?.[0]; |
54 | 54 | |
55 | 55 | expect(opts.url).toBe("https://cdn.example.com/photo.png"); |
56 | 56 | expect(opts.maxBytes).toBe(65_536); |
@@ -70,7 +70,7 @@ describe("getImageSizeFromUrl", () => {
|
70 | 70 | |
71 | 71 | await getImageSizeFromUrl("https://cdn.example.com/img.png", 3000); |
72 | 72 | |
73 | | -const opts = adapterMocks.fetchMedia.mock.calls[0][0]; |
| 73 | +const opts = adapterMocks.fetchMedia.mock.calls.at(0)?.[0]; |
74 | 74 | expect(opts.requestInit.signal).toBeInstanceOf(AbortSignal); |
75 | 75 | }); |
76 | 76 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -73,7 +73,7 @@ describe("qwen video generation provider", () => {
|
73 | 73 | }); |
74 | 74 | |
75 | 75 | expect(postJsonRequestMock).toHaveBeenCalledTimes(1); |
76 | | -expectPostJsonRequest(postJsonRequestMock.mock.calls[0]?.[0], { |
| 76 | +expectPostJsonRequest(postJsonRequestMock.mock.calls.at(0)?.[0], { |
77 | 77 | url: "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis", |
78 | 78 | body: { |
79 | 79 | model: "wan2.6-r2v-flash", |
@@ -135,7 +135,7 @@ describe("qwen video generation provider", () => {
|
135 | 135 | }); |
136 | 136 | |
137 | 137 | expect(postJsonRequestMock).toHaveBeenCalledTimes(1); |
138 | | -expectPostJsonRequest(postJsonRequestMock.mock.calls[0]?.[0], { |
| 138 | +expectPostJsonRequest(postJsonRequestMock.mock.calls.at(0)?.[0], { |
139 | 139 | url: "https://coding-intl.dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis", |
140 | 140 | body: { |
141 | 141 | model: "wan2.6-t2v", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -140,7 +140,7 @@ describe("monitorSignalProvider tool results", () => {
|
140 | 140 | await vi.waitFor(() => { |
141 | 141 | expect(sendMock).toHaveBeenCalledTimes(1); |
142 | 142 | }); |
143 | | -expect(sendMock.mock.calls[0][1]).toBe("PFX final reply"); |
| 143 | +expect(sendMock.mock.calls.at(0)?.[1]).toBe("PFX final reply"); |
144 | 144 | }); |
145 | 145 | |
146 | 146 | it("replies with pairing code when dmPolicy is pairing and no allowFrom is set", async () => { |
@@ -165,7 +165,7 @@ describe("monitorSignalProvider tool results", () => {
|
165 | 165 | expect(replyMock).not.toHaveBeenCalled(); |
166 | 166 | expect(upsertPairingRequestMock).toHaveBeenCalled(); |
167 | 167 | expect(sendMock).toHaveBeenCalledTimes(1); |
168 | | -expectPairingReplyText(String(sendMock.mock.calls[0]?.[1] ?? ""), { |
| 168 | +expectPairingReplyText(String(sendMock.mock.calls.at(0)?.[1] ?? ""), { |
169 | 169 | channel: "signal", |
170 | 170 | idLine: "Your Signal number: +15550001111", |
171 | 171 | code: "PAIRCODE", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -221,7 +221,7 @@ describe("registerSlackMessageEvents", () => {
|
221 | 221 | }); |
222 | 222 | |
223 | 223 | expect(handleSlackMessage).toHaveBeenCalledTimes(1); |
224 | | -const call = handleSlackMessage.mock.calls[0] as unknown as |
| 224 | +const call = handleSlackMessage.mock.calls.at(0) as unknown as |
225 | 225 | | [{ subtype?: string; channel?: string; user?: string }, { source?: string }] |
226 | 226 | | undefined; |
227 | 227 | expect(call?.[0]?.subtype).toBe("thread_broadcast"); |
@@ -239,7 +239,7 @@ describe("registerSlackMessageEvents", () => {
|
239 | 239 | }); |
240 | 240 | |
241 | 241 | expect(handleSlackMessage).toHaveBeenCalledTimes(1); |
242 | | -const call = handleSlackMessage.mock.calls[0] as unknown as |
| 242 | +const call = handleSlackMessage.mock.calls.at(0) as unknown as |
243 | 243 | | [ |
244 | 244 | { |
245 | 245 | channel?: string; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -45,15 +45,15 @@ describe("tavily client X-Client-Source header", () => {
|
45 | 45 | await runTavilySearch({ query: "test query" }); |
46 | 46 | |
47 | 47 | expect(postTrustedWebToolsJson).toHaveBeenCalledOnce(); |
48 | | -const params = postTrustedWebToolsJson.mock.calls[0][0]; |
| 48 | +const params = postTrustedWebToolsJson.mock.calls.at(0)?.[0]; |
49 | 49 | expect(params.extraHeaders).toEqual({ "X-Client-Source": "openclaw" }); |
50 | 50 | }); |
51 | 51 | |
52 | 52 | it("runTavilyExtract sends X-Client-Source: openclaw", async () => { |
53 | 53 | await runTavilyExtract({ urls: ["https://example.com"] }); |
54 | 54 | |
55 | 55 | expect(postTrustedWebToolsJson).toHaveBeenCalledOnce(); |
56 | | -const params = postTrustedWebToolsJson.mock.calls[0][0]; |
| 56 | +const params = postTrustedWebToolsJson.mock.calls.at(0)?.[0]; |
57 | 57 | expect(params.extraHeaders).toEqual({ "X-Client-Source": "openclaw" }); |
58 | 58 | }); |
59 | 59 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -124,7 +124,7 @@ describe("telegram stickers", () => {
|
124 | 124 | expect(cachedSticker?.setName).toBe("NewSet"); |
125 | 125 | expect(media?.stickerMetadata?.fileId).toBe("new_file_id"); |
126 | 126 | expect(media?.stickerMetadata?.cachedDescription).toBe("Cached description"); |
127 | | -const [fetchUrl, fetchOptions] = proxyFetch.mock.calls[0] ?? []; |
| 127 | +const [fetchUrl, fetchOptions] = proxyFetch.mock.calls.at(0) ?? []; |
128 | 128 | expect(fetchUrl).toBe("https://api.telegram.org/file/bottok/stickers/sticker.webp"); |
129 | 129 | expect(fetchOptions?.redirect).toBe("manual"); |
130 | 130 | }, |
@@ -240,7 +240,7 @@ describe("telegram text fragments", () => {
|
240 | 240 | await flushScheduledTimerForDelay(setTimeoutSpy, TELEGRAM_TEST_TIMINGS.textFragmentGapMs); |
241 | 241 | |
242 | 242 | expect(replySpy).toHaveBeenCalledTimes(1); |
243 | | -const payload = replySpy.mock.calls[0][0] as { RawBody?: string }; |
| 243 | +const payload = replySpy.mock.calls.at(0)?.[0] as { RawBody?: string }; |
244 | 244 | expect(payload.RawBody).toContain(part1.slice(0, 32)); |
245 | 245 | expect(payload.RawBody).toContain(part2.slice(0, 32)); |
246 | 246 | } finally { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。