From ac478b2c6a8fcabf66bf4e1c70458ddebfc72db4 Mon Sep 17 00:00:00 2001 From: Shakker Date: Mon, 11 May 2026 17:20:45 +0100 Subject: [PATCH] test: verify diagnostics and session callbacks --- src/commands/doctor-config-flow.include-warning.test.ts | 6 +++++- src/gateway/server-methods/config.test.ts | 4 +++- src/gateway/sessions-resolve.test.ts | 5 ++++- src/plugins/discovery.test.ts | 4 +--- src/plugins/hooks.correlation.test.ts | 4 +--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/commands/doctor-config-flow.include-warning.test.ts b/src/commands/doctor-config-flow.include-warning.test.ts index d076a3c38a3..240e84b58ca 100644 --- a/src/commands/doctor-config-flow.include-warning.test.ts +++ b/src/commands/doctor-config-flow.include-warning.test.ts @@ -20,7 +20,11 @@ describe("doctor include warning", () => { }); expect(noteSpy).toHaveBeenCalledWith( - expect.stringContaining("$include paths must stay under:"), + [ + "- $include paths must stay under: /tmp/openclaw-config", + '- Move shared include files under that directory and update to relative paths like "./shared/common.json".', + "- Error: Include path escapes config directory: /etc/passwd", + ].join("\n"), "Doctor warnings", ); }); diff --git a/src/gateway/server-methods/config.test.ts b/src/gateway/server-methods/config.test.ts index 2a0d0e3517f..741edea7ea2 100644 --- a/src/gateway/server-methods/config.test.ts +++ b/src/gateway/server-methods/config.test.ts @@ -104,6 +104,8 @@ describe("config.openFile", () => { }, undefined, ); - expect(logGateway.warn).toHaveBeenCalledWith(expect.stringContaining("spawn xdg-open ENOENT")); + expect(logGateway.warn).toHaveBeenCalledWith( + "config.openFile failed path=/tmp/config.json: spawn xdg-open ENOENT", + ); }); }); diff --git a/src/gateway/sessions-resolve.test.ts b/src/gateway/sessions-resolve.test.ts index 7f21200874e..472b6fd5ffa 100644 --- a/src/gateway/sessions-resolve.test.ts +++ b/src/gateway/sessions-resolve.test.ts @@ -117,7 +117,10 @@ describe("resolveSessionKeyFromResolveParams", () => { key: canonicalKey, }); - expect(hoisted.updateSessionStoreMock).toHaveBeenCalledWith(storePath, expect.any(Function)); + expect(hoisted.updateSessionStoreMock).toHaveBeenCalledTimes(1); + const updateSessionStoreCall = hoisted.updateSessionStoreMock.mock.calls[0]; + expect(updateSessionStoreCall?.[0]).toBe(storePath); + expect(typeof updateSessionStoreCall?.[1]).toBe("function"); expect(hoisted.listSessionsFromStoreMock).toHaveBeenCalledWith({ cfg: {}, storePath, diff --git a/src/plugins/discovery.test.ts b/src/plugins/discovery.test.ts index 10bbb13e2f1..c557f613543 100644 --- a/src/plugins/discovery.test.ts +++ b/src/plugins/discovery.test.ts @@ -626,9 +626,7 @@ describe("discoverOpenClawPlugins", () => { discoverOpenClawPlugins({ env: buildDiscoveryEnv(stateDir) }), ); - expect(result.diagnostics.map((entry) => entry.message)).not.toContainEqual( - expect.stringContaining("pnpm install"), - ); + expect(result.diagnostics.some((entry) => entry.message.includes("pnpm install"))).toBe(false); }); it("does not treat repo-level live or test files as plugin entrypoints", () => { diff --git a/src/plugins/hooks.correlation.test.ts b/src/plugins/hooks.correlation.test.ts index ba1e60fbd8b..5024b62d098 100644 --- a/src/plugins/hooks.correlation.test.ts +++ b/src/plugins/hooks.correlation.test.ts @@ -78,9 +78,7 @@ describe("hook correlation fields", () => { await expect(run).resolves.toBeUndefined(); expect(logger.error).toHaveBeenCalledWith( - expect.stringContaining( - "[hooks] agent_end handler from plugin-a failed: timed out after 5ms", - ), + "[hooks] agent_end handler from plugin-a failed: timed out after 5ms", ); } finally { vi.useRealTimers();