test: guard agent model config mock calls · openclaw/openclaw@ac017fa
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -328,10 +328,12 @@ function mockPrimaryRunLoopRateLimitThenFallbackSuccess(errorMessage: string) {
|
328 | 328 | |
329 | 329 | function expectOpenAiThenGroqAttemptOrder(params?: { expectOpenAiAuthProfileId?: string }) { |
330 | 330 | expect(runEmbeddedAttemptMock).toHaveBeenCalledTimes(2); |
331 | | -const firstCall = runEmbeddedAttemptMock.mock.calls[0]?.[0] as |
| 331 | +const firstCall = runEmbeddedAttemptMock.mock.calls.at(0)?.[0] as |
332 | 332 | | { provider?: string; authProfileId?: string } |
333 | 333 | | undefined; |
334 | | -const secondCall = runEmbeddedAttemptMock.mock.calls[1]?.[0] as { provider?: string } | undefined; |
| 334 | +const secondCall = runEmbeddedAttemptMock.mock.calls.at(1)?.[0] as |
| 335 | +| { provider?: string } |
| 336 | +| undefined; |
335 | 337 | if (!firstCall || !secondCall) { |
336 | 338 | throw new Error("expected primary and fallback embedded run attempts"); |
337 | 339 | } |
@@ -702,7 +704,7 @@ describe("runWithModelFallback + runEmbeddedPiAgent failover behavior", () => {
|
702 | 704 | expect((thrown as Error).message).toBe("Operation aborted"); |
703 | 705 | |
704 | 706 | expect(runEmbeddedAttemptMock).toHaveBeenCalledTimes(1); |
705 | | -const firstCall = runEmbeddedAttemptMock.mock.calls[0]?.[0] as |
| 707 | +const firstCall = runEmbeddedAttemptMock.mock.calls.at(0)?.[0] as |
706 | 708 | | { provider?: string } |
707 | 709 | | undefined; |
708 | 710 | expect(firstCall?.provider).toBe("openai"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -87,9 +87,9 @@ describe("resolveImplicitProviders startup discovery scope", () => {
|
87 | 87 | providerDiscoveryTimeoutMs: 1234, |
88 | 88 | }); |
89 | 89 | |
90 | | -const [discoveryOptions] = mocks.resolveRuntimePluginDiscoveryProviders.mock.calls[0] ?? []; |
| 90 | +const [discoveryOptions] = mocks.resolveRuntimePluginDiscoveryProviders.mock.calls.at(0) ?? []; |
91 | 91 | expect(discoveryOptions?.onlyPluginIds).toEqual(["openai"]); |
92 | | -const [catalogOptions] = mocks.runProviderCatalog.mock.calls[0] ?? []; |
| 92 | +const [catalogOptions] = mocks.runProviderCatalog.mock.calls.at(0) ?? []; |
93 | 93 | expect(catalogOptions?.timeoutMs).toBe(1234); |
94 | 94 | }); |
95 | 95 | |
@@ -102,7 +102,7 @@ describe("resolveImplicitProviders startup discovery scope", () => {
|
102 | 102 | providerDiscoveryEntriesOnly: true, |
103 | 103 | }); |
104 | 104 | |
105 | | -const [discoveryOptions] = mocks.resolveRuntimePluginDiscoveryProviders.mock.calls[0] ?? []; |
| 105 | +const [discoveryOptions] = mocks.resolveRuntimePluginDiscoveryProviders.mock.calls.at(0) ?? []; |
106 | 106 | expect(discoveryOptions?.discoveryEntriesOnly).toBe(true); |
107 | 107 | }); |
108 | 108 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -138,7 +138,7 @@ describe("models-config write serialization", () => {
|
138 | 138 | |
139 | 139 | await ensureOpenClawModelsJson({}, agentDir); |
140 | 140 | |
141 | | -const params = planOpenClawModelsJsonMock.mock.calls[0]?.[0] as |
| 141 | +const params = planOpenClawModelsJsonMock.mock.calls.at(0)?.[0] as |
142 | 142 | | { pluginMetadataSnapshot?: PluginMetadataSnapshot } |
143 | 143 | | undefined; |
144 | 144 | expect(params?.pluginMetadataSnapshot).not.toBe(snapshot); |
@@ -154,7 +154,7 @@ describe("models-config write serialization", () => {
|
154 | 154 | |
155 | 155 | await ensureOpenClawModelsJson({}, agentDir, { workspaceDir }); |
156 | 156 | |
157 | | -const params = planOpenClawModelsJsonMock.mock.calls[0]?.[0] as |
| 157 | +const params = planOpenClawModelsJsonMock.mock.calls.at(0)?.[0] as |
158 | 158 | | { workspaceDir?: string; pluginMetadataSnapshot?: PluginMetadataSnapshot } |
159 | 159 | | undefined; |
160 | 160 | expect(params?.workspaceDir).toBe(workspaceDir); |
@@ -194,7 +194,7 @@ describe("models-config write serialization", () => {
|
194 | 194 | }); |
195 | 195 | |
196 | 196 | expect(planOpenClawModelsJsonMock).toHaveBeenCalledTimes(2); |
197 | | -const params = planOpenClawModelsJsonMock.mock.calls[1]?.[0] as |
| 197 | +const params = planOpenClawModelsJsonMock.mock.calls.at(1)?.[0] as |
198 | 198 | | { |
199 | 199 | providerDiscoveryProviderIds?: string[]; |
200 | 200 | providerDiscoveryTimeoutMs?: number; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -135,7 +135,9 @@ describe("createOpenClawTools browser plugin integration", () => {
|
135 | 135 | }); |
136 | 136 | |
137 | 137 | expect(hoisted.resolvePluginTools).toHaveBeenCalledTimes(1); |
138 | | -expect(hoisted.resolvePluginTools.mock.calls[0]?.[0]?.allowGatewaySubagentBinding).toBe(true); |
| 138 | +expect(hoisted.resolvePluginTools.mock.calls.at(0)?.[0]?.allowGatewaySubagentBinding).toBe( |
| 139 | +true, |
| 140 | +); |
139 | 141 | }); |
140 | 142 | |
141 | 143 | it("forwards auth profile helpers to plugin resolution and context", async () => { |
@@ -210,8 +212,8 @@ describe("createOpenClawTools browser plugin integration", () => {
|
210 | 212 | }); |
211 | 213 | |
212 | 214 | expect(hoisted.resolvePluginTools).toHaveBeenCalledTimes(1); |
213 | | -expect(hoisted.resolvePluginTools.mock.calls[0]?.[0]?.toolAllowlist).toEqual(["*"]); |
214 | | -expect(hoisted.resolvePluginTools.mock.calls[0]?.[0]?.toolDenylist).toEqual(["browser"]); |
| 215 | +expect(hoisted.resolvePluginTools.mock.calls.at(0)?.[0]?.toolAllowlist).toEqual(["*"]); |
| 216 | +expect(hoisted.resolvePluginTools.mock.calls.at(0)?.[0]?.toolDenylist).toEqual(["browser"]); |
215 | 217 | }); |
216 | 218 | |
217 | 219 | it("does not pass a stale active snapshot as plugin runtime config for a resolved run config", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -66,7 +66,7 @@ describe("spawnLspServerProcess Windows .cmd shim handling", () => {
|
66 | 66 | }); |
67 | 67 | |
68 | 68 | // Must use structured params so config.env entries are not dropped |
69 | | -const sanitizeParams = sanitizeHostExecEnvMock.mock.calls[0]?.[0] as |
| 69 | +const sanitizeParams = sanitizeHostExecEnvMock.mock.calls.at(0)?.[0] as |
70 | 70 | | { baseEnv?: NodeJS.ProcessEnv; overrides?: Record<string, string> } |
71 | 71 | | undefined; |
72 | 72 | expect(sanitizeParams?.baseEnv).toBe(process.env); |
@@ -87,7 +87,7 @@ describe("spawnLspServerProcess Windows .cmd shim handling", () => {
|
87 | 87 | |
88 | 88 | spawnLspServerProcess({ command: "typescript-language-server", args: ["--stdio"] }); |
89 | 89 | |
90 | | -const resolveParams = resolveWindowsSpawnProgramMock.mock.calls[0]?.[0] as |
| 90 | +const resolveParams = resolveWindowsSpawnProgramMock.mock.calls.at(0)?.[0] as |
91 | 91 | | { env?: Record<string, string>; allowShellFallback?: boolean } |
92 | 92 | | undefined; |
93 | 93 | expect(resolveParams?.env).toBe(sanitizedEnv); |
@@ -108,7 +108,7 @@ describe("spawnLspServerProcess Windows .cmd shim handling", () => {
|
108 | 108 | |
109 | 109 | spawnLspServerProcess({ command: "typescript-language-server", args: ["--stdio"] }); |
110 | 110 | |
111 | | -const spawnCall = spawnMock.mock.calls[0]; |
| 111 | +const spawnCall = spawnMock.mock.calls.at(0); |
112 | 112 | expect(spawnCall?.[0]).toBe("cmd.exe"); |
113 | 113 | expect(spawnCall?.[1]).toEqual(["/c", "typescript-language-server.cmd", "--stdio"]); |
114 | 114 | const spawnOptions = spawnCall?.[2] as |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。