From 941debaa5ef1066a2329c0d8f9236dfbccf06584 Mon Sep 17 00:00:00 2001 From: OpenClaw Contributor Date: Tue, 17 Mar 2026 16:14:44 +0000 Subject: [PATCH] test: fix Windows path normalization in bundle-mcp, plugin-hooks, and logger tests Resolve Windows 8.3 short filename (RUNNER~1 vs runneradmin) mismatches by applying fs.realpath on both sides of assertions. Fix backslash path separator in logger browser-import test expectations. Made-with: Cursor --- src/hooks/plugin-hooks.test.ts | 2 +- src/logging/logger.browser-import.test.ts | 12 ++++---- src/plugins/bundle-mcp.test.ts | 34 +++++++++++++++-------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/hooks/plugin-hooks.test.ts b/src/hooks/plugin-hooks.test.ts index 333c3a3cf39..60f12c41ac8 100644 --- a/src/hooks/plugin-hooks.test.ts +++ b/src/hooks/plugin-hooks.test.ts @@ -106,7 +106,7 @@ describe("bundle plugin hooks", () => { expect(entries[0]?.hook.name).toBe("bundle-hook"); expect(entries[0]?.hook.source).toBe("openclaw-plugin"); expect(entries[0]?.hook.pluginId).toBe("sample-bundle"); - expect(entries[0]?.hook.baseDir).toBe( + expect(fs.realpathSync.native(entries[0]?.hook.baseDir ?? "")).toBe( fs.realpathSync.native(path.join(bundleRoot, "hooks", "bundle-hook")), ); expect(entries[0]?.metadata?.events).toEqual(["command:new"]); diff --git a/src/logging/logger.browser-import.test.ts b/src/logging/logger.browser-import.test.ts index 5704770d3ed..0a0b020f204 100644 --- a/src/logging/logger.browser-import.test.ts +++ b/src/logging/logger.browser-import.test.ts @@ -52,17 +52,17 @@ describe("logging/logger browser-safe import", () => { const { module, resolvePreferredOpenClawTmpDir } = await importBrowserSafeLogger(); expect(resolvePreferredOpenClawTmpDir).not.toHaveBeenCalled(); - expect(module.DEFAULT_LOG_DIR).toBe("/tmp/openclaw"); - expect(module.DEFAULT_LOG_FILE).toBe("/tmp/openclaw/openclaw.log"); + const normSlash = (p: string) => p.replaceAll("\\", "/"); + expect(normSlash(module.DEFAULT_LOG_DIR)).toBe("/tmp/openclaw"); + expect(normSlash(module.DEFAULT_LOG_FILE)).toBe("/tmp/openclaw/openclaw.log"); }); it("disables file logging when imported in a browser-like environment", async () => { const { module, resolvePreferredOpenClawTmpDir } = await importBrowserSafeLogger(); - expect(module.getResolvedLoggerSettings()).toMatchObject({ - level: "silent", - file: "/tmp/openclaw/openclaw.log", - }); + const settings = module.getResolvedLoggerSettings(); + expect(settings.level).toBe("silent"); + expect((settings.file ?? "").replaceAll("\\", "/")).toBe("/tmp/openclaw/openclaw.log"); expect(module.isFileLogLevelEnabled("info")).toBe(false); expect(() => module.getLogger().info("browser-safe")).not.toThrow(); expect(resolvePreferredOpenClawTmpDir).not.toHaveBeenCalled(); diff --git a/src/plugins/bundle-mcp.test.ts b/src/plugins/bundle-mcp.test.ts index b9d5ca18cf3..affa98fdf8c 100644 --- a/src/plugins/bundle-mcp.test.ts +++ b/src/plugins/bundle-mcp.test.ts @@ -56,7 +56,9 @@ describe("loadEnabledBundleMcpConfig", () => { throw new Error("expected bundled MCP args to include the server path"); } expect(await fs.realpath(loadedServerPath)).toBe(resolvedServerPath); - expect(loadedServer.cwd).toBe(resolvedPluginRoot); + const loadedCwd = + isRecord(loadedServer) && typeof loadedServer.cwd === "string" ? loadedServer.cwd : ""; + expect(await fs.realpath(loadedCwd)).toBe(resolvedPluginRoot); } finally { env.restore(); } @@ -181,17 +183,25 @@ describe("loadEnabledBundleMcpConfig", () => { const resolvedPluginRoot = await fs.realpath(pluginRoot); expect(loaded.diagnostics).toEqual([]); - expect(loaded.config.mcpServers.inlineProbe).toEqual({ - command: path.join(resolvedPluginRoot, "bin", "server.sh"), - args: [ - path.join(resolvedPluginRoot, "servers", "probe.mjs"), - path.join(resolvedPluginRoot, "local-probe.mjs"), - ], - cwd: resolvedPluginRoot, - env: { - PLUGIN_ROOT: resolvedPluginRoot, - }, - }); + const probe = loaded.config.mcpServers.inlineProbe; + expect(isRecord(probe) ? await fs.realpath(String(probe.command)) : "").toBe( + path.join(resolvedPluginRoot, "bin", "server.sh"), + ); + const probeArgs = getServerArgs(probe); + expect(probeArgs).toHaveLength(2); + expect(await fs.realpath(String(probeArgs?.[0]))).toBe( + path.join(resolvedPluginRoot, "servers", "probe.mjs"), + ); + expect(await fs.realpath(String(probeArgs?.[1]))).toBe( + path.join(resolvedPluginRoot, "local-probe.mjs"), + ); + expect( + isRecord(probe) && typeof probe.cwd === "string" ? await fs.realpath(probe.cwd) : "", + ).toBe(resolvedPluginRoot); + const probeEnv = isRecord(probe) && isRecord(probe.env) ? probe.env : {}; + expect( + typeof probeEnv.PLUGIN_ROOT === "string" ? await fs.realpath(probeEnv.PLUGIN_ROOT) : "", + ).toBe(resolvedPluginRoot); } finally { env.restore(); }