test: tighten dashboard link assertions

This commit is contained in:
Peter Steinberger
2026-05-10 23:47:09 +01:00
parent c8f0d8911f
commit 15711cdcc0

View File

@@ -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");
});
});