From 15711cdcc0406a34f3f41d751e831f52c0dc3dff Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 10 May 2026 23:47:09 +0100 Subject: [PATCH] test: tighten dashboard link assertions --- src/commands/dashboard.links.test.ts | 44 ++++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/commands/dashboard.links.test.ts b/src/commands/dashboard.links.test.ts index d7f60d485cb..28d82fce4dc 100644 --- a/src/commands/dashboard.links.test.ts +++ b/src/commands/dashboard.links.test.ts @@ -42,6 +42,18 @@ function resetRuntime() { runtime.exit.mockClear(); } +function logMessages(): string[] { + return runtime.log.mock.calls.map(([message]) => String(message)); +} + +function expectLogWith(text: string): void { + expect(logMessages().some((message) => message.includes(text))).toBe(true); +} + +function expectNoLogWith(text: string): void { + expect(logMessages().some((message) => message.includes(text))).toBe(false); +} + function mockSnapshot(token: unknown = "abc") { readConfigFileSnapshotMock.mockResolvedValue({ path: "/tmp/openclaw.json", @@ -209,7 +221,7 @@ describe("dashboardCommand", () => { expect(runtime.log).not.toHaveBeenCalledWith( "Browser launch disabled (--no-open). Use the URL above.", ); - expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining("OPENCLAW_GATEWAY_TOKEN")); + expectLogWith("OPENCLAW_GATEWAY_TOKEN"); }); it("respects --no-open with plain URL hint when clipboard fails and no token is configured", async () => { @@ -237,15 +249,11 @@ describe("dashboardCommand", () => { await dashboardCommand(runtime); expect(copyToClipboardMock).toHaveBeenCalledWith("http://127.0.0.1:18789/"); - expect(runtime.log).toHaveBeenCalledWith( - expect.stringContaining("Token auto-auth unavailable"), + expectLogWith("Token auto-auth unavailable"); + expectLogWith( + "gateway.auth.token SecretRef is unresolved (env:default:MISSING_GATEWAY_TOKEN).", ); - expect(runtime.log).toHaveBeenCalledWith( - expect.stringContaining( - "gateway.auth.token SecretRef is unresolved (env:default:MISSING_GATEWAY_TOKEN).", - ), - ); - expect(runtime.log).not.toHaveBeenCalledWith(expect.stringContaining("missing env var")); + expectNoLogWith("missing env var"); }); it("keeps URL non-tokenized when token SecretRef is unresolved but env fallback exists", async () => { @@ -264,12 +272,8 @@ describe("dashboardCommand", () => { expect(copyToClipboardMock).toHaveBeenCalledWith("http://127.0.0.1:18789/"); expect(openUrlMock).toHaveBeenCalledWith("http://127.0.0.1:18789/"); - expect(runtime.log).toHaveBeenCalledWith( - expect.stringContaining("Token auto-auth is disabled for SecretRef-managed"), - ); - expect(runtime.log).not.toHaveBeenCalledWith( - expect.stringContaining("Token auto-auth unavailable"), - ); + expectLogWith("Token auto-auth is disabled for SecretRef-managed"); + expectNoLogWith("Token auto-auth unavailable"); }); it("keeps URL non-tokenized when env-template gateway.auth.token is unresolved", async () => { @@ -282,13 +286,9 @@ describe("dashboardCommand", () => { expect(copyToClipboardMock).toHaveBeenCalledWith("http://127.0.0.1:18789/"); expect(openUrlMock).toHaveBeenCalledWith("http://127.0.0.1:18789/"); - expect(runtime.log).toHaveBeenCalledWith( - expect.stringContaining( - "Token auto-auth unavailable: gateway.auth.token SecretRef is unresolved (env:default:CUSTOM_GATEWAY_TOKEN).", - ), - ); - expect(runtime.log).not.toHaveBeenCalledWith( - expect.stringContaining("Token auto-auth is disabled for SecretRef-managed"), + expectLogWith( + "Token auto-auth unavailable: gateway.auth.token SecretRef is unresolved (env:default:CUSTOM_GATEWAY_TOKEN).", ); + expectNoLogWith("Token auto-auth is disabled for SecretRef-managed"); }); });