test: guard command call assertions · openclaw/openclaw@067e83d
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -360,7 +360,7 @@ describe("agentCommand ACP runtime routing", () => {
|
360 | 360 | message: " ping\n", |
361 | 361 | chunks: [" ACP_OK\n"], |
362 | 362 | }); |
363 | | -const runTurnInput = runTurn.mock.calls[0]?.[0] as |
| 363 | +const runTurnInput = runTurn.mock.calls.at(0)?.[0] as |
364 | 364 | | { mode?: string; sessionKey?: string; text?: string } |
365 | 365 | | undefined; |
366 | 366 | expect(runTurnInput?.sessionKey).toBe("agent:codex:acp:test"); |
@@ -489,7 +489,7 @@ describe("agentCommand ACP runtime routing", () => {
|
489 | 489 | |
490 | 490 | await agentCommand({ message: "ping", sessionKey: "agent:kimi:acp:test" }, runtime); |
491 | 491 | |
492 | | -const runTurnInput = runTurn.mock.calls[0]?.[0] as |
| 492 | +const runTurnInput = runTurn.mock.calls.at(0)?.[0] as |
493 | 493 | | { sessionKey?: string; text?: string } |
494 | 494 | | undefined; |
495 | 495 | expect(runTurnInput?.sessionKey).toBe("agent:kimi:acp:test"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -208,7 +208,7 @@ function expectSetupSnapshotDoesNotScopeToPlugin(params: {
|
208 | 208 | }); |
209 | 209 | |
210 | 210 | expect(loadOpenClawPlugins).toHaveBeenCalledTimes(1); |
211 | | -const firstLoadCall = vi.mocked(loadOpenClawPlugins).mock.calls[0]?.[0] as |
| 211 | +const firstLoadCall = vi.mocked(loadOpenClawPlugins).mock.calls.at(0)?.[0] as |
212 | 212 | | { onlyPluginIds?: string[] } |
213 | 213 | | undefined; |
214 | 214 | expect(firstLoadCall?.onlyPluginIds).toStrictEqual([]); |
@@ -300,7 +300,7 @@ async function runInitialValueForChannel(channel: "dev" | "beta") {
|
300 | 300 | runtime, |
301 | 301 | }); |
302 | 302 | |
303 | | -const call = select.mock.calls[0]; |
| 303 | +const call = select.mock.calls.at(0); |
304 | 304 | if (!call) { |
305 | 305 | throw new Error("Expected select call"); |
306 | 306 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -171,7 +171,7 @@ describe("channelsRemoveCommand", () => {
|
171 | 171 | |
172 | 172 | expect(ensureChannelSetupPluginInstalled).not.toHaveBeenCalled(); |
173 | 173 | expect(registryRefreshMocks.refreshPluginRegistryAfterConfigMutation).not.toHaveBeenCalled(); |
174 | | -const writtenConfig = configMocks.writeConfigFile.mock.calls[0]?.[0] as |
| 174 | +const writtenConfig = configMocks.writeConfigFile.mock.calls.at(0)?.[0] as |
175 | 175 | | { channels?: Record<string, unknown> } |
176 | 176 | | undefined; |
177 | 177 | expect(writtenConfig?.channels?.["external-chat"]).toBeUndefined(); |
@@ -237,7 +237,7 @@ describe("channelsRemoveCommand", () => {
|
237 | 237 | clientName: "gateway-client", |
238 | 238 | deviceIdentity: null, |
239 | 239 | }); |
240 | | -const writtenConfig = configMocks.writeConfigFile.mock.calls[0]?.[0] as |
| 240 | +const writtenConfig = configMocks.writeConfigFile.mock.calls.at(0)?.[0] as |
241 | 241 | | { channels?: Record<string, unknown> } |
242 | 242 | | undefined; |
243 | 243 | expect(writtenConfig?.channels?.["external-chat"]).toBeUndefined(); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,7 @@ describe("noteStartupOptimizationHints", () => {
|
27 | 27 | ); |
28 | 28 | |
29 | 29 | expect(noteFn).toHaveBeenCalledTimes(1); |
30 | | -const [message, title] = noteFn.mock.calls[0] ?? []; |
| 30 | +const [message, title] = noteFn.mock.calls.at(0) ?? []; |
31 | 31 | expect(title).toBe("Startup optimization"); |
32 | 32 | expect(message).toBe( |
33 | 33 | [ |
@@ -54,7 +54,7 @@ describe("noteStartupOptimizationHints", () => {
|
54 | 54 | ); |
55 | 55 | |
56 | 56 | expect(noteFn).toHaveBeenCalledTimes(1); |
57 | | -const [message] = noteFn.mock.calls[0] ?? []; |
| 57 | +const [message] = noteFn.mock.calls.at(0) ?? []; |
58 | 58 | expect(message).toBe( |
59 | 59 | [ |
60 | 60 | "- NODE_DISABLE_COMPILE_CACHE is set; startup compile cache is disabled.", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -86,7 +86,10 @@ describe("maybeRepairSandboxImages", () => {
|
86 | 86 | |
87 | 87 | // The warning should clearly indicate sandbox is enabled but won't work |
88 | 88 | expect(note).toHaveBeenCalled(); |
89 | | -const noteCall = note.mock.calls[0]; |
| 89 | +const noteCall = note.mock.calls.at(0); |
| 90 | +if (noteCall === undefined) { |
| 91 | +throw new Error("expected sandbox warning note"); |
| 92 | +} |
90 | 93 | const message = noteCall[0] as string; |
91 | 94 | |
92 | 95 | // The message should warn that sandbox mode won't function, not just "skipping checks" |
@@ -99,7 +102,10 @@ describe("maybeRepairSandboxImages", () => {
|
99 | 102 | await runSandboxRepair({ mode: "all", dockerAvailable: false }); |
100 | 103 | |
101 | 104 | expect(note).toHaveBeenCalled(); |
102 | | -const noteCall = note.mock.calls[0]; |
| 105 | +const noteCall = note.mock.calls.at(0); |
| 106 | +if (noteCall === undefined) { |
| 107 | +throw new Error("expected sandbox warning note"); |
| 108 | +} |
103 | 109 | const message = noteCall[0] as string; |
104 | 110 | |
105 | 111 | // Should warn about the impact on sandbox functionality |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -116,14 +116,14 @@ describe("root memory repair", () => {
|
116 | 116 | expect(canonical).toContain("# Legacy"); |
117 | 117 | await expectPathMissing(path.join(tmpDir, "memory.md")); |
118 | 118 | expect(note).toHaveBeenCalledTimes(1); |
119 | | -const repairMessage = String(note.mock.calls[0]?.[0] ?? ""); |
| 119 | +const repairMessage = String(note.mock.calls.at(0)?.[0] ?? ""); |
120 | 120 | const repairLines = repairMessage.split("\n"); |
121 | 121 | expect(repairLines[0]).toBe("Workspace memory root merged:"); |
122 | 122 | expect(repairLines).toContain(`- canonical: ${path.join(tmpDir, "MEMORY.md")}`); |
123 | 123 | expect(repairLines).toContain( |
124 | 124 | `- merged legacy content from: ${path.join(tmpDir, "memory.md")}`, |
125 | 125 | ); |
126 | 126 | expect(repairLines).toContain(`- removed legacy file: ${path.join(tmpDir, "memory.md")}`); |
127 | | -expect(note.mock.calls[0]?.[1]).toBe("Doctor changes"); |
| 127 | +expect(note.mock.calls.at(0)?.[1]).toBe("Doctor changes"); |
128 | 128 | }); |
129 | 129 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -128,7 +128,7 @@ describe("bundled channel legacy config migrations", () => {
|
128 | 128 | }); |
129 | 129 | |
130 | 130 | expect(applyPluginDoctorCompatibilityMigrations).toHaveBeenCalledOnce(); |
131 | | -const migrationCall = applyPluginDoctorCompatibilityMigrations.mock.calls[0]; |
| 131 | +const migrationCall = applyPluginDoctorCompatibilityMigrations.mock.calls.at(0); |
132 | 132 | expect(typeof migrationCall?.[0]).toBe("object"); |
133 | 133 | expect(migrationCall?.[1]?.config).toStrictEqual({ |
134 | 134 | channels: { |
@@ -198,7 +198,7 @@ describe("bundled channel legacy config migrations", () => {
|
198 | 198 | const result = applyChannelDoctorCompatibilityMigrations(config); |
199 | 199 | |
200 | 200 | expect(applyPluginDoctorCompatibilityMigrations).toHaveBeenCalledOnce(); |
201 | | -const migrationCall = applyPluginDoctorCompatibilityMigrations.mock.calls[0]; |
| 201 | +const migrationCall = applyPluginDoctorCompatibilityMigrations.mock.calls.at(0); |
202 | 202 | expect(typeof migrationCall?.[0]).toBe("object"); |
203 | 203 | expect(migrationCall?.[1]).toStrictEqual({ |
204 | 204 | config, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,7 @@ type RunMessageActionParams = {
|
17 | 17 | |
18 | 18 | function readOnlyMessageActionCall(): RunMessageActionParams { |
19 | 19 | expect(runMessageActionMock).toHaveBeenCalledOnce(); |
20 | | -const call = runMessageActionMock.mock.calls[0]?.[0]; |
| 20 | +const call = runMessageActionMock.mock.calls.at(0)?.[0]; |
21 | 21 | if (!call) { |
22 | 22 | throw new Error("Expected message action call"); |
23 | 23 | } |
@@ -208,7 +208,7 @@ describe("messageCommand", () => {
|
208 | 208 | expect(actionCall.gateway?.clientName).toBe("cli"); |
209 | 209 | expect(actionCall.gateway?.mode).toBe("cli"); |
210 | 210 | expect(actionCall.cfg).not.toBe(rawConfig); |
211 | | -const configResolutionCall = resolveCommandConfigWithSecrets.mock.calls[0]?.[0] as { |
| 211 | +const configResolutionCall = resolveCommandConfigWithSecrets.mock.calls.at(0)?.[0] as { |
212 | 212 | commandName?: string; |
213 | 213 | config?: unknown; |
214 | 214 | targetIds?: Set<string>; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -247,7 +247,7 @@ describe("sessionsCleanupCommand", () => {
|
247 | 247 | appliedCount: 1, |
248 | 248 | }); |
249 | 249 | expect(mocks.runSessionsCleanup).toHaveBeenCalledOnce(); |
250 | | -const cleanupCall = mocks.runSessionsCleanup.mock.calls[0]?.[0]; |
| 250 | +const cleanupCall = mocks.runSessionsCleanup.mock.calls.at(0)?.[0]; |
251 | 251 | expect(cleanupCall?.cfg).toEqual({ session: { store: "/cfg/sessions.json" } }); |
252 | 252 | expect(cleanupCall?.opts.enforce).toBe(true); |
253 | 253 | expect(cleanupCall?.opts.activeKey).toBe("agent:main:main"); |
@@ -284,7 +284,7 @@ describe("sessionsCleanupCommand", () => {
|
284 | 284 | ); |
285 | 285 | |
286 | 286 | expect(mocks.callGateway).toHaveBeenCalledOnce(); |
287 | | -const gatewayCall = mocks.callGateway.mock.calls[0]?.[0]; |
| 287 | +const gatewayCall = mocks.callGateway.mock.calls.at(0)?.[0]; |
288 | 288 | expect(gatewayCall?.method).toBe("sessions.cleanup"); |
289 | 289 | expect(gatewayCall?.params.enforce).toBe(true); |
290 | 290 | expect(gatewayCall?.requiredMethods).toEqual(["sessions.cleanup"]); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -105,7 +105,7 @@ describe("scanStatusJsonFast", () => {
|
105 | 105 | await scanStatusJsonFast({}, {} as never); |
106 | 106 | |
107 | 107 | expect(mocks.getStatusSummary).toHaveBeenCalledOnce(); |
108 | | -const summaryOptions = mocks.getStatusSummary.mock.calls[0]?.[0] as |
| 108 | +const summaryOptions = mocks.getStatusSummary.mock.calls.at(0)?.[0] as |
109 | 109 | | { includeChannelSummary?: unknown } |
110 | 110 | | undefined; |
111 | 111 | expect(summaryOptions?.includeChannelSummary).toBe(false); |
@@ -135,7 +135,7 @@ describe("scanStatusJsonFast", () => {
|
135 | 135 | }); |
136 | 136 | expect(mocks.resolveMemorySearchConfig).toHaveBeenCalled(); |
137 | 137 | expect(mocks.getMemorySearchManager).toHaveBeenCalledOnce(); |
138 | | -expect(mocks.getMemorySearchManager.mock.calls[0]?.[0]).toStrictEqual({ |
| 138 | +expect(mocks.getMemorySearchManager.mock.calls.at(0)?.[0]).toStrictEqual({ |
139 | 139 | cfg: createStatusMemorySearchConfig(), |
140 | 140 | agentId: "main", |
141 | 141 | purpose: "status", |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。