test: guard command mock calls · openclaw/openclaw@b37a71f
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -369,7 +369,7 @@ describe("deliverAgentCommandResult", () => {
|
369 | 369 | |
370 | 370 | expect(runtime.log).toHaveBeenCalledTimes(1); |
371 | 371 | expect( |
372 | | -JSON.parse(String((runtime.log as ReturnType<typeof vi.fn>).mock.calls[0]?.[0])), |
| 372 | +JSON.parse(String((runtime.log as ReturnType<typeof vi.fn>).mock.calls.at(0)?.[0])), |
373 | 373 | ).toEqual({ |
374 | 374 | payloads: [ |
375 | 375 | { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -381,7 +381,7 @@ describe("agentCommand", () => {
|
381 | 381 | ); |
382 | 382 | |
383 | 383 | expect(pluginRegistryMocks.ensurePluginRegistryLoaded).toHaveBeenCalledOnce(); |
384 | | -const registryLoad = pluginRegistryMocks.ensurePluginRegistryLoaded.mock.calls[0]?.[0]; |
| 384 | +const registryLoad = pluginRegistryMocks.ensurePluginRegistryLoaded.mock.calls.at(0)?.[0]; |
385 | 385 | expect(registryLoad?.scope).toBe("all"); |
386 | 386 | expect(registryLoad?.config).toBeTypeOf("object"); |
387 | 387 | expect(registryLoad?.activationSourceConfig).toBeTypeOf("object"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -128,7 +128,7 @@ describe("agents delete command", () => {
|
128 | 128 | await agentsDeleteCommand({ id: "ops", force: true, json: true }, runtime); |
129 | 129 | |
130 | 130 | expect(gatewayMocks.callGateway).toHaveBeenCalledOnce(); |
131 | | -const gatewayCall = gatewayMocks.callGateway.mock.calls[0]?.[0]; |
| 131 | +const gatewayCall = gatewayMocks.callGateway.mock.calls.at(0)?.[0]; |
132 | 132 | expect(gatewayCall?.method).toBe("agents.delete"); |
133 | 133 | expect(gatewayCall?.params).toEqual({ agentId: "ops", deleteFiles: true }); |
134 | 134 | expect(gatewayCall?.requiredMethods).toEqual(["agents.delete"]); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -43,7 +43,7 @@ async function writeIdentityFile(workspace: string, lines: string[]) {
|
43 | 43 | } |
44 | 44 | |
45 | 45 | function getWrittenMainIdentity() { |
46 | | -const [written] = configMocks.writeConfigFile.mock.calls[0] ?? []; |
| 46 | +const [written] = configMocks.writeConfigFile.mock.calls.at(0) ?? []; |
47 | 47 | if (!written) { |
48 | 48 | throw new Error("expected written agent config"); |
49 | 49 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -461,7 +461,10 @@ describe("applyAuthChoiceLoadedPluginProvider", () => {
|
461 | 461 | const result = await applyAuthChoiceLoadedPluginProvider(buildParams()); |
462 | 462 | |
463 | 463 | expect(ensureOnboardingPluginInstalled).toHaveBeenCalledOnce(); |
464 | | -const [installParams] = ensureOnboardingPluginInstalled.mock.calls[0]; |
| 464 | +const [installParams] = ensureOnboardingPluginInstalled.mock.calls.at(0) ?? []; |
| 465 | +if (installParams === undefined) { |
| 466 | +throw new Error("expected plugin install params"); |
| 467 | +} |
465 | 468 | expect(installParams.entry?.pluginId).toBe("local-provider-plugin"); |
466 | 469 | expect(installParams.entry?.label).toBe(LOCAL_PROVIDER_LABEL); |
467 | 470 | expect(installParams.workspaceDir).toBe("/tmp/workspace"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -45,7 +45,7 @@ describe("warnIfModelConfigLooksOff", () => {
|
45 | 45 | expect(loadModelCatalog).not.toHaveBeenCalled(); |
46 | 46 | expect(ensureAuthProfileStore).toHaveBeenCalledOnce(); |
47 | 47 | expect(listProfilesForProvider).toHaveBeenCalledOnce(); |
48 | | -const [profileStore, providerId] = listProfilesForProvider.mock.calls[0] as unknown as [ |
| 48 | +const [profileStore, providerId] = listProfilesForProvider.mock.calls.at(0) as unknown as [ |
49 | 49 | AuthProfileStore, |
50 | 50 | string, |
51 | 51 | ]; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -125,7 +125,7 @@ describe("resolvePreferredProviderForAuthChoice", () => {
|
125 | 125 | }), |
126 | 126 | ).resolves.toBe("demo-provider"); |
127 | 127 | expect(resolvePluginProviders).toHaveBeenCalledOnce(); |
128 | | -const [pluginProviderOptions] = resolvePluginProviders.mock.calls[0] as unknown as [ |
| 128 | +const [pluginProviderOptions] = resolvePluginProviders.mock.calls.at(0) as unknown as [ |
129 | 129 | ResolvePluginProvidersOptions, |
130 | 130 | ]; |
131 | 131 | expect(pluginProviderOptions?.mode).toBe("setup"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -339,7 +339,7 @@ describe("channels command", () => {
|
339 | 339 | // oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper lets assertions ascribe written config shape. |
340 | 340 | function getWrittenConfig<T>(): T { |
341 | 341 | expect(configMocks.writeConfigFile).toHaveBeenCalledTimes(1); |
342 | | -const [config] = configMocks.writeConfigFile.mock.calls[0] ?? []; |
| 342 | +const [config] = configMocks.writeConfigFile.mock.calls.at(0) ?? []; |
343 | 343 | if (config === undefined) { |
344 | 344 | throw new Error("expected written channel config"); |
345 | 345 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,7 @@ function logLine(params: { module: string; message: string }) {
|
38 | 38 | } |
39 | 39 | |
40 | 40 | function readJsonPayload() { |
41 | | -return JSON.parse(String(runtime.log.mock.calls[0]?.[0])) as { |
| 41 | +return JSON.parse(String(runtime.log.mock.calls.at(0)?.[0])) as { |
42 | 42 | file: string; |
43 | 43 | channel: string; |
44 | 44 | lines: Array<{ message: string }>; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -243,7 +243,7 @@ describe("channelsStatusCommand SecretRef fallback flow", () => {
|
243 | 243 | |
244 | 244 | expect(errors.join("\n")).toContain("Gateway not reachable"); |
245 | 245 | expect(mocks.resolveCommandConfigWithSecrets).toHaveBeenCalledOnce(); |
246 | | -const configResolutionRequest = mocks.resolveCommandConfigWithSecrets.mock.calls[0]?.[0]; |
| 246 | +const configResolutionRequest = mocks.resolveCommandConfigWithSecrets.mock.calls.at(0)?.[0]; |
247 | 247 | expect(configResolutionRequest?.commandName).toBe("channels status"); |
248 | 248 | expect(configResolutionRequest?.mode).toBe("read_only_status"); |
249 | 249 | expect( |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。