test: normalize paths in OPENCLAW_HOME tests for cross-platform support (#12212)

* test: normalize paths in OPENCLAW_HOME tests for cross-platform support

* test: normalize paths in Nix integration tests for cross-platform support

* test: remove unnecessary Windows skip from pi-embedded-runner test

* test: fix nix integration tests for path.resolve behavior
This commit is contained in:
max
2026-02-08 17:21:31 -08:00
committed by GitHub
parent 456bd58740
commit 53a1ac36f5
4 changed files with 67 additions and 77 deletions
+9 -10
View File
@@ -208,22 +208,21 @@ describe("resolveAgentConfig", () => {
expect(result?.workspace).toBe("~/openclaw"); expect(result?.workspace).toBe("~/openclaw");
}); });
// Unix-style paths behave differently on Windows; skip there it("uses OPENCLAW_HOME for default agent workspace", () => {
it.skipIf(process.platform === "win32")("uses OPENCLAW_HOME for default agent workspace", () => { const home = path.join(path.sep, "srv", "openclaw-home");
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home"); vi.stubEnv("OPENCLAW_HOME", home);
const workspace = resolveAgentWorkspaceDir({} as OpenClawConfig, "main"); const workspace = resolveAgentWorkspaceDir({} as OpenClawConfig, "main");
expect(workspace).toBe(path.join(path.resolve("/srv/openclaw-home"), ".openclaw", "workspace")); expect(workspace).toBe(path.join(path.resolve(home), ".openclaw", "workspace"));
}); });
// Unix-style paths behave differently on Windows; skip there it("uses OPENCLAW_HOME for default agentDir", () => {
it.skipIf(process.platform === "win32")("uses OPENCLAW_HOME for default agentDir", () => { const home = path.join(path.sep, "srv", "openclaw-home");
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home"); vi.stubEnv("OPENCLAW_HOME", home);
// Clear state dir so it falls back to OPENCLAW_HOME
vi.stubEnv("OPENCLAW_STATE_DIR", ""); vi.stubEnv("OPENCLAW_STATE_DIR", "");
const agentDir = resolveAgentDir({} as OpenClawConfig, "main"); const agentDir = resolveAgentDir({} as OpenClawConfig, "main");
expect(agentDir).toBe( expect(agentDir).toBe(path.join(path.resolve(home), ".openclaw", "agents", "main", "agent"));
path.join(path.resolve("/srv/openclaw-home"), ".openclaw", "agents", "main", "agent"),
);
}); });
}); });
+27 -32
View File
@@ -173,7 +173,6 @@ const readSessionMessages = async (sessionFile: string) => {
}; };
describe("runEmbeddedPiAgent", () => { describe("runEmbeddedPiAgent", () => {
const itIfNotWin32 = process.platform === "win32" ? it.skip : it;
it("writes models.json into the provided agentDir", async () => { it("writes models.json into the provided agentDir", async () => {
const sessionFile = nextSessionFile(); const sessionFile = nextSessionFile();
@@ -288,39 +287,35 @@ describe("runEmbeddedPiAgent", () => {
).rejects.toThrow("Malformed agent session key"); ).rejects.toThrow("Malformed agent session key");
}); });
itIfNotWin32( it("persists the first user message before assistant output", { timeout: 120_000 }, async () => {
"persists the first user message before assistant output", const sessionFile = nextSessionFile();
{ timeout: 120_000 }, const cfg = makeOpenAiConfig(["mock-1"]);
async () => { await ensureModels(cfg);
const sessionFile = nextSessionFile();
const cfg = makeOpenAiConfig(["mock-1"]);
await ensureModels(cfg);
await runEmbeddedPiAgent({ await runEmbeddedPiAgent({
sessionId: "session:test", sessionId: "session:test",
sessionKey: testSessionKey, sessionKey: testSessionKey,
sessionFile, sessionFile,
workspaceDir, workspaceDir,
config: cfg, config: cfg,
prompt: "hello", prompt: "hello",
provider: "openai", provider: "openai",
model: "mock-1", model: "mock-1",
timeoutMs: 5_000, timeoutMs: 5_000,
agentDir, agentDir,
enqueue: immediateEnqueue, enqueue: immediateEnqueue,
}); });
const messages = await readSessionMessages(sessionFile); const messages = await readSessionMessages(sessionFile);
const firstUserIndex = messages.findIndex( const firstUserIndex = messages.findIndex(
(message) => message?.role === "user" && textFromContent(message.content) === "hello", (message) => message?.role === "user" && textFromContent(message.content) === "hello",
); );
const firstAssistantIndex = messages.findIndex((message) => message?.role === "assistant"); const firstAssistantIndex = messages.findIndex((message) => message?.role === "assistant");
expect(firstUserIndex).toBeGreaterThanOrEqual(0); expect(firstUserIndex).toBeGreaterThanOrEqual(0);
if (firstAssistantIndex !== -1) { if (firstAssistantIndex !== -1) {
expect(firstUserIndex).toBeLessThan(firstAssistantIndex); expect(firstUserIndex).toBeLessThan(firstAssistantIndex);
} }
}, });
);
it("persists the user message when prompt fails before assistant output", async () => { it("persists the user message when prompt fails before assistant output", async () => {
const sessionFile = nextSessionFile(); const sessionFile = nextSessionFile();
+5 -5
View File
@@ -7,15 +7,15 @@ afterEach(() => {
}); });
describe("DEFAULT_AGENT_WORKSPACE_DIR", () => { describe("DEFAULT_AGENT_WORKSPACE_DIR", () => {
// Unix-style paths behave differently on Windows; skip there it("uses OPENCLAW_HOME at module import time", async () => {
it.skipIf(process.platform === "win32")("uses OPENCLAW_HOME at module import time", async () => { const home = path.join(path.sep, "srv", "openclaw-home");
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home"); vi.stubEnv("OPENCLAW_HOME", home);
vi.stubEnv("HOME", "/home/other"); vi.stubEnv("HOME", path.join(path.sep, "home", "other"));
vi.resetModules(); vi.resetModules();
const mod = await import("./workspace.js"); const mod = await import("./workspace.js");
expect(mod.DEFAULT_AGENT_WORKSPACE_DIR).toBe( expect(mod.DEFAULT_AGENT_WORKSPACE_DIR).toBe(
path.join(path.resolve("/srv/openclaw-home"), ".openclaw", "workspace"), path.join(path.resolve(home), ".openclaw", "workspace"),
); );
}); });
}); });
@@ -49,37 +49,33 @@ describe("Nix integration (U3, U5, U9)", () => {
}); });
}); });
// Skip on Windows: these tests use Unix-style paths that only make sense on Nix/Unix it("STATE_DIR respects OPENCLAW_HOME when state override is unset", async () => {
it.skipIf(process.platform === "win32")( const customHome = path.join(path.sep, "custom", "home");
"STATE_DIR respects OPENCLAW_HOME when state override is unset", await withEnvOverride(
async () => { { OPENCLAW_HOME: customHome, OPENCLAW_STATE_DIR: undefined },
await withEnvOverride( async () => {
{ OPENCLAW_HOME: "/custom/home", OPENCLAW_STATE_DIR: undefined }, const { STATE_DIR } = await import("./config.js");
async () => { expect(STATE_DIR).toBe(path.join(path.resolve(customHome), ".openclaw"));
const { STATE_DIR } = await import("./config.js"); },
expect(STATE_DIR).toBe(path.resolve("/custom/home/.openclaw")); );
}, });
);
},
);
// Skip on Windows: these tests use Unix-style paths that only make sense on Nix/Unix it("CONFIG_PATH defaults to OPENCLAW_HOME/.openclaw/openclaw.json", async () => {
it.skipIf(process.platform === "win32")( const customHome = path.join(path.sep, "custom", "home");
"CONFIG_PATH defaults to OPENCLAW_HOME/.openclaw/openclaw.json", await withEnvOverride(
async () => { {
await withEnvOverride( OPENCLAW_HOME: customHome,
{ OPENCLAW_CONFIG_PATH: undefined,
OPENCLAW_HOME: "/custom/home", OPENCLAW_STATE_DIR: undefined,
OPENCLAW_CONFIG_PATH: undefined, },
OPENCLAW_STATE_DIR: undefined, async () => {
}, const { CONFIG_PATH } = await import("./config.js");
async () => { expect(CONFIG_PATH).toBe(
const { CONFIG_PATH } = await import("./config.js"); path.join(path.resolve(customHome), ".openclaw", "openclaw.json"),
expect(CONFIG_PATH).toBe(path.resolve("/custom/home/.openclaw/openclaw.json")); );
}, },
); );
}, });
);
it("CONFIG_PATH defaults to ~/.openclaw/openclaw.json when env not set", async () => { it("CONFIG_PATH defaults to ~/.openclaw/openclaw.json when env not set", async () => {
await withEnvOverride( await withEnvOverride(