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
This commit is contained in:
OpenClaw Contributor
2026-03-17 16:14:44 +00:00
parent f40583500e
commit 941debaa5e
3 changed files with 29 additions and 19 deletions

View File

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

View File

@@ -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();

View File

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