























@@ -42,6 +42,18 @@ function resetRuntime() {
4242runtime.exit.mockClear();
4343}
444445+function logMessages(): string[] {
46+return runtime.log.mock.calls.map(([message]) => String(message));
47+}
48+49+function expectLogWith(text: string): void {
50+expect(logMessages().some((message) => message.includes(text))).toBe(true);
51+}
52+53+function expectNoLogWith(text: string): void {
54+expect(logMessages().some((message) => message.includes(text))).toBe(false);
55+}
56+4557function mockSnapshot(token: unknown = "abc") {
4658readConfigFileSnapshotMock.mockResolvedValue({
4759path: "/tmp/openclaw.json",
@@ -209,7 +221,7 @@ describe("dashboardCommand", () => {
209221expect(runtime.log).not.toHaveBeenCalledWith(
210222"Browser launch disabled (--no-open). Use the URL above.",
211223);
212-expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining("OPENCLAW_GATEWAY_TOKEN"));
224+expectLogWith("OPENCLAW_GATEWAY_TOKEN");
213225});
214226215227it("respects --no-open with plain URL hint when clipboard fails and no token is configured", async () => {
@@ -237,15 +249,11 @@ describe("dashboardCommand", () => {
237249await dashboardCommand(runtime);
238250239251expect(copyToClipboardMock).toHaveBeenCalledWith("http://127.0.0.1:18789/");
240-expect(runtime.log).toHaveBeenCalledWith(
241-expect.stringContaining("Token auto-auth unavailable"),
242-);
243-expect(runtime.log).toHaveBeenCalledWith(
244-expect.stringContaining(
245-"gateway.auth.token SecretRef is unresolved (env:default:MISSING_GATEWAY_TOKEN).",
246-),
252+expectLogWith("Token auto-auth unavailable");
253+expectLogWith(
254+"gateway.auth.token SecretRef is unresolved (env:default:MISSING_GATEWAY_TOKEN).",
247255);
248-expect(runtime.log).not.toHaveBeenCalledWith(expect.stringContaining("missing env var"));
256+expectNoLogWith("missing env var");
249257});
250258251259it("keeps URL non-tokenized when token SecretRef is unresolved but env fallback exists", async () => {
@@ -264,12 +272,8 @@ describe("dashboardCommand", () => {
264272265273expect(copyToClipboardMock).toHaveBeenCalledWith("http://127.0.0.1:18789/");
266274expect(openUrlMock).toHaveBeenCalledWith("http://127.0.0.1:18789/");
267-expect(runtime.log).toHaveBeenCalledWith(
268-expect.stringContaining("Token auto-auth is disabled for SecretRef-managed"),
269-);
270-expect(runtime.log).not.toHaveBeenCalledWith(
271-expect.stringContaining("Token auto-auth unavailable"),
272-);
275+expectLogWith("Token auto-auth is disabled for SecretRef-managed");
276+expectNoLogWith("Token auto-auth unavailable");
273277});
274278275279it("keeps URL non-tokenized when env-template gateway.auth.token is unresolved", async () => {
@@ -282,13 +286,9 @@ describe("dashboardCommand", () => {
282286283287expect(copyToClipboardMock).toHaveBeenCalledWith("http://127.0.0.1:18789/");
284288expect(openUrlMock).toHaveBeenCalledWith("http://127.0.0.1:18789/");
285-expect(runtime.log).toHaveBeenCalledWith(
286-expect.stringContaining(
287-"Token auto-auth unavailable: gateway.auth.token SecretRef is unresolved (env:default:CUSTOM_GATEWAY_TOKEN).",
288-),
289-);
290-expect(runtime.log).not.toHaveBeenCalledWith(
291-expect.stringContaining("Token auto-auth is disabled for SecretRef-managed"),
289+expectLogWith(
290+"Token auto-auth unavailable: gateway.auth.token SecretRef is unresolved (env:default:CUSTOM_GATEWAY_TOKEN).",
292291);
292+expectNoLogWith("Token auto-auth is disabled for SecretRef-managed");
293293});
294294});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。