From 281a88d6dfb8101a1a2f71cb1b5d7a85c3f1e094 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 15:07:54 +0100 Subject: [PATCH] test: tighten cli gateway assertions --- src/cli/command-secret-gateway.test.ts | 19 ++++++------- src/cli/config-cli.integration.test.ts | 14 ++++------ src/cli/daemon-cli/install.test.ts | 28 +++++++++++++------ src/cli/daemon-cli/shared.test.ts | 12 +++----- src/cli/gateway-cli.coverage.test.ts | 28 +++++++++---------- .../program/message/register.thread.test.ts | 28 +++++++------------ src/cli/qr-cli.test.ts | 11 ++++---- 7 files changed, 66 insertions(+), 74 deletions(-) diff --git a/src/cli/command-secret-gateway.test.ts b/src/cli/command-secret-gateway.test.ts index 10e00707766..7ca3415f4de 100644 --- a/src/cli/command-secret-gateway.test.ts +++ b/src/cli/command-secret-gateway.test.ts @@ -161,17 +161,14 @@ describe("resolveCommandSecretRefsViaGateway", () => { commandName: "memory status", targetIds: new Set(["talk.providers.*.apiKey"]), }); - expect(callGateway).toHaveBeenCalledWith( - expect.objectContaining({ - config, - method: "secrets.resolve", - requiredMethods: ["secrets.resolve"], - params: { - commandName: "memory status", - targetIds: ["talk.providers.*.apiKey"], - }, - }), - ); + const gatewayRequest = callGateway.mock.calls[0]?.[0]; + expect(gatewayRequest?.config).toBe(config); + expect(gatewayRequest?.method).toBe("secrets.resolve"); + expect(gatewayRequest?.requiredMethods).toEqual(["secrets.resolve"]); + expect(gatewayRequest?.params).toEqual({ + commandName: "memory status", + targetIds: ["talk.providers.*.apiKey"], + }); expect(readTalkProviderApiKey(result.resolvedConfig)).toBe("sk-live"); }); diff --git a/src/cli/config-cli.integration.test.ts b/src/cli/config-cli.integration.test.ts index 7314016e62a..bb4db6b3556 100644 --- a/src/cli/config-cli.integration.test.ts +++ b/src/cli/config-cli.integration.test.ts @@ -215,8 +215,8 @@ describe("config cli integration", () => { const afterDryRun = fs.readFileSync(configPath, "utf8"); expect(afterDryRun).toBe(before); expect(runtime.errors).toStrictEqual([]); - expect(runtime.logs).toEqual( - expect.arrayContaining([expect.stringContaining("Dry run successful: 2 update(s)")]), + expect(runtime.logs.some((line) => line.includes("Dry run successful: 2 update(s)"))).toBe( + true, ); await runConfigSet({ @@ -303,12 +303,10 @@ describe("config cli integration", () => { }; expect(payload.ok).toBe(false); expect(payload.checks?.resolvability).toBe(true); - expect(payload.errors).toEqual( - expect.arrayContaining([expect.objectContaining({ kind: "resolvability" })]), - ); - expect(payload.errors?.map((entry) => entry.ref ?? "")).toEqual( - expect.arrayContaining([expect.stringContaining("MISSING_TEST_SECRET")]), - ); + expect(payload.errors?.some((entry) => entry.kind === "resolvability")).toBe(true); + expect( + payload.errors?.some((entry) => (entry.ref ?? "").includes("MISSING_TEST_SECRET")), + ).toBe(true); } finally { envSnapshot.restore(); clearConfigCache(); diff --git a/src/cli/daemon-cli/install.test.ts b/src/cli/daemon-cli/install.test.ts index 75062d47d4d..ac58d93ad7b 100644 --- a/src/cli/daemon-cli/install.test.ts +++ b/src/cli/daemon-cli/install.test.ts @@ -323,16 +323,26 @@ describe("runDaemonInstall", () => { await runDaemonInstall({ json: true }); - expect(service.install).toHaveBeenCalledWith( - expect.objectContaining({ - environment: { - OPENROUTER_API_KEY: "or-operator-key", + const installCalls = service.install.mock.calls as unknown as Array< + [ + { + environment?: Record; + environmentValueSources?: Record; }, - environmentValueSources: { - OPENROUTER_API_KEY: "file", - }, - }), - ); + ] + >; + const installOptions = installCalls[0]?.[0] as + | { + environment?: Record; + environmentValueSources?: Record; + } + | undefined; + expect(installOptions?.environment).toEqual({ + OPENROUTER_API_KEY: "or-operator-key", + }); + expect(installOptions?.environmentValueSources).toEqual({ + OPENROUTER_API_KEY: "file", + }); }); it("does not treat env-template gateway.auth.token as plaintext during install", async () => { diff --git a/src/cli/daemon-cli/shared.test.ts b/src/cli/daemon-cli/shared.test.ts index 78cc58212ac..c7327584db2 100644 --- a/src/cli/daemon-cli/shared.test.ts +++ b/src/cli/daemon-cli/shared.test.ts @@ -39,10 +39,8 @@ describe("renderGatewayServiceStartHints", () => { renderGatewayServiceStartHints({ OPENCLAW_CONTAINER: "openclaw-demo-container", } as NodeJS.ProcessEnv), - ).toEqual( - expect.arrayContaining([ - "Restart the container or the service that manages it for openclaw-demo-container.", - ]), + ).toContain( + "Restart the container or the service that manages it for openclaw-demo-container.", ); }); @@ -51,10 +49,8 @@ describe("renderGatewayServiceStartHints", () => { renderGatewayServiceStartHints({ OPENCLAW_CONTAINER_HINT: "openclaw-demo-container", } as NodeJS.ProcessEnv), - ).toEqual( - expect.arrayContaining([ - "Restart the container or the service that manages it for openclaw-demo-container.", - ]), + ).toContain( + "Restart the container or the service that manages it for openclaw-demo-container.", ); }); }); diff --git a/src/cli/gateway-cli.coverage.test.ts b/src/cli/gateway-cli.coverage.test.ts index 764b2b1235e..54e56f8f21a 100644 --- a/src/cli/gateway-cli.coverage.test.ts +++ b/src/cli/gateway-cli.coverage.test.ts @@ -166,15 +166,14 @@ describe("gateway-cli coverage", () => { "--json", ]); - expect(callGateway).toHaveBeenCalledWith( - expect.objectContaining({ - method: "diagnostics.stability", - params: { - limit: 5, - type: "payload.large", - }, - }), - ); + const stabilityCall = callGateway.mock.calls[0]?.[0] as + | { method?: string; params?: unknown } + | undefined; + expect(stabilityCall?.method).toBe("diagnostics.stability"); + expect(stabilityCall?.params).toEqual({ + limit: 5, + type: "payload.large", + }); }); it("prints the latest stability bundle without calling Gateway", async () => { @@ -266,12 +265,11 @@ describe("gateway-cli coverage", () => { ); expect(callGateway).toHaveBeenCalledTimes(1); - expect(callGateway).toHaveBeenCalledWith( - expect.objectContaining({ - method: "health", - timeoutMs: 3000, - }), - ); + const healthCall = callGateway.mock.calls[0]?.[0] as + | { method?: string; timeoutMs?: number } + | undefined; + expect(healthCall?.method).toBe("health"); + expect(healthCall?.timeoutMs).toBe(3000); expect(fs.existsSync(outputPath)).toBe(true); const output = runtimeLogs.join("\n"); expect(output).toContain('"path"'); diff --git a/src/cli/program/message/register.thread.test.ts b/src/cli/program/message/register.thread.test.ts index 5cc3ffd564b..e67c9c166e1 100644 --- a/src/cli/program/message/register.thread.test.ts +++ b/src/cli/program/message/register.thread.test.ts @@ -83,16 +83,12 @@ describe("registerMessageThreadCommands", () => { { from: "user" }, ); - expect(runMessageAction).toHaveBeenCalledWith( - "topic-create", - expect.objectContaining({ - channel: " topic-chat ", - target: "room-1", - name: "Build Updates", - message: "hello", - }), - ); const remappedCall = runMessageAction.mock.calls.at(0); + expect(remappedCall?.[0]).toBe("topic-create"); + expect(remappedCall?.[1]?.channel).toBe(" topic-chat "); + expect(remappedCall?.[1]?.target).toBe("room-1"); + expect(remappedCall?.[1]?.name).toBe("Build Updates"); + expect(remappedCall?.[1]?.message).toBe("hello"); expect(remappedCall?.[1]).not.toHaveProperty("threadName"); }); @@ -116,16 +112,12 @@ describe("registerMessageThreadCommands", () => { { from: "user" }, ); - expect(runMessageAction).toHaveBeenCalledWith( - "thread-create", - expect.objectContaining({ - channel: "plain-chat", - target: "channel:123", - threadName: "Build Updates", - message: "hello", - }), - ); const defaultCall = runMessageAction.mock.calls.at(0); + expect(defaultCall?.[0]).toBe("thread-create"); + expect(defaultCall?.[1]?.channel).toBe("plain-chat"); + expect(defaultCall?.[1]?.target).toBe("channel:123"); + expect(defaultCall?.[1]?.threadName).toBe("Build Updates"); + expect(defaultCall?.[1]?.message).toBe("hello"); expect(defaultCall?.[1]).not.toHaveProperty("name"); }); }); diff --git a/src/cli/qr-cli.test.ts b/src/cli/qr-cli.test.ts index 7af28cd243e..b9e784210e5 100644 --- a/src/cli/qr-cli.test.ts +++ b/src/cli/qr-cli.test.ts @@ -405,11 +405,12 @@ describe("registerQrCli", () => { bootstrapToken: "bootstrap-123", }); expect(runtime.log).toHaveBeenCalledWith(expected); - expect(resolveCommandSecretRefsViaGateway).toHaveBeenCalledWith( - expect.objectContaining({ - commandName: "qr --remote", - targetIds: new Set(["gateway.remote.token", "gateway.remote.password"]), - }), + const request = resolveCommandSecretRefsViaGateway.mock.calls[0]?.[0] as + | { commandName?: string; targetIds?: Set } + | undefined; + expect(request?.commandName).toBe("qr --remote"); + expect(request?.targetIds).toEqual( + new Set(["gateway.remote.token", "gateway.remote.password"]), ); });