mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
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:
@@ -208,22 +208,21 @@ describe("resolveAgentConfig", () => {
|
||||
expect(result?.workspace).toBe("~/openclaw");
|
||||
});
|
||||
|
||||
// Unix-style paths behave differently on Windows; skip there
|
||||
it.skipIf(process.platform === "win32")("uses OPENCLAW_HOME for default agent workspace", () => {
|
||||
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home");
|
||||
it("uses OPENCLAW_HOME for default agent workspace", () => {
|
||||
const home = path.join(path.sep, "srv", "openclaw-home");
|
||||
vi.stubEnv("OPENCLAW_HOME", home);
|
||||
|
||||
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.skipIf(process.platform === "win32")("uses OPENCLAW_HOME for default agentDir", () => {
|
||||
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home");
|
||||
it("uses OPENCLAW_HOME for default agentDir", () => {
|
||||
const home = path.join(path.sep, "srv", "openclaw-home");
|
||||
vi.stubEnv("OPENCLAW_HOME", home);
|
||||
// Clear state dir so it falls back to OPENCLAW_HOME
|
||||
vi.stubEnv("OPENCLAW_STATE_DIR", "");
|
||||
|
||||
const agentDir = resolveAgentDir({} as OpenClawConfig, "main");
|
||||
expect(agentDir).toBe(
|
||||
path.join(path.resolve("/srv/openclaw-home"), ".openclaw", "agents", "main", "agent"),
|
||||
);
|
||||
expect(agentDir).toBe(path.join(path.resolve(home), ".openclaw", "agents", "main", "agent"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -173,7 +173,6 @@ const readSessionMessages = async (sessionFile: string) => {
|
||||
};
|
||||
|
||||
describe("runEmbeddedPiAgent", () => {
|
||||
const itIfNotWin32 = process.platform === "win32" ? it.skip : it;
|
||||
it("writes models.json into the provided agentDir", async () => {
|
||||
const sessionFile = nextSessionFile();
|
||||
|
||||
@@ -288,39 +287,35 @@ describe("runEmbeddedPiAgent", () => {
|
||||
).rejects.toThrow("Malformed agent session key");
|
||||
});
|
||||
|
||||
itIfNotWin32(
|
||||
"persists the first user message before assistant output",
|
||||
{ timeout: 120_000 },
|
||||
async () => {
|
||||
const sessionFile = nextSessionFile();
|
||||
const cfg = makeOpenAiConfig(["mock-1"]);
|
||||
await ensureModels(cfg);
|
||||
it("persists the first user message before assistant output", { timeout: 120_000 }, async () => {
|
||||
const sessionFile = nextSessionFile();
|
||||
const cfg = makeOpenAiConfig(["mock-1"]);
|
||||
await ensureModels(cfg);
|
||||
|
||||
await runEmbeddedPiAgent({
|
||||
sessionId: "session:test",
|
||||
sessionKey: testSessionKey,
|
||||
sessionFile,
|
||||
workspaceDir,
|
||||
config: cfg,
|
||||
prompt: "hello",
|
||||
provider: "openai",
|
||||
model: "mock-1",
|
||||
timeoutMs: 5_000,
|
||||
agentDir,
|
||||
enqueue: immediateEnqueue,
|
||||
});
|
||||
await runEmbeddedPiAgent({
|
||||
sessionId: "session:test",
|
||||
sessionKey: testSessionKey,
|
||||
sessionFile,
|
||||
workspaceDir,
|
||||
config: cfg,
|
||||
prompt: "hello",
|
||||
provider: "openai",
|
||||
model: "mock-1",
|
||||
timeoutMs: 5_000,
|
||||
agentDir,
|
||||
enqueue: immediateEnqueue,
|
||||
});
|
||||
|
||||
const messages = await readSessionMessages(sessionFile);
|
||||
const firstUserIndex = messages.findIndex(
|
||||
(message) => message?.role === "user" && textFromContent(message.content) === "hello",
|
||||
);
|
||||
const firstAssistantIndex = messages.findIndex((message) => message?.role === "assistant");
|
||||
expect(firstUserIndex).toBeGreaterThanOrEqual(0);
|
||||
if (firstAssistantIndex !== -1) {
|
||||
expect(firstUserIndex).toBeLessThan(firstAssistantIndex);
|
||||
}
|
||||
},
|
||||
);
|
||||
const messages = await readSessionMessages(sessionFile);
|
||||
const firstUserIndex = messages.findIndex(
|
||||
(message) => message?.role === "user" && textFromContent(message.content) === "hello",
|
||||
);
|
||||
const firstAssistantIndex = messages.findIndex((message) => message?.role === "assistant");
|
||||
expect(firstUserIndex).toBeGreaterThanOrEqual(0);
|
||||
if (firstAssistantIndex !== -1) {
|
||||
expect(firstUserIndex).toBeLessThan(firstAssistantIndex);
|
||||
}
|
||||
});
|
||||
|
||||
it("persists the user message when prompt fails before assistant output", async () => {
|
||||
const sessionFile = nextSessionFile();
|
||||
|
||||
@@ -7,15 +7,15 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("DEFAULT_AGENT_WORKSPACE_DIR", () => {
|
||||
// Unix-style paths behave differently on Windows; skip there
|
||||
it.skipIf(process.platform === "win32")("uses OPENCLAW_HOME at module import time", async () => {
|
||||
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home");
|
||||
vi.stubEnv("HOME", "/home/other");
|
||||
it("uses OPENCLAW_HOME at module import time", async () => {
|
||||
const home = path.join(path.sep, "srv", "openclaw-home");
|
||||
vi.stubEnv("OPENCLAW_HOME", home);
|
||||
vi.stubEnv("HOME", path.join(path.sep, "home", "other"));
|
||||
vi.resetModules();
|
||||
|
||||
const mod = await import("./workspace.js");
|
||||
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.skipIf(process.platform === "win32")(
|
||||
"STATE_DIR respects OPENCLAW_HOME when state override is unset",
|
||||
async () => {
|
||||
await withEnvOverride(
|
||||
{ OPENCLAW_HOME: "/custom/home", OPENCLAW_STATE_DIR: undefined },
|
||||
async () => {
|
||||
const { STATE_DIR } = await import("./config.js");
|
||||
expect(STATE_DIR).toBe(path.resolve("/custom/home/.openclaw"));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
it("STATE_DIR respects OPENCLAW_HOME when state override is unset", async () => {
|
||||
const customHome = path.join(path.sep, "custom", "home");
|
||||
await withEnvOverride(
|
||||
{ OPENCLAW_HOME: customHome, OPENCLAW_STATE_DIR: undefined },
|
||||
async () => {
|
||||
const { STATE_DIR } = await import("./config.js");
|
||||
expect(STATE_DIR).toBe(path.join(path.resolve(customHome), ".openclaw"));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// Skip on Windows: these tests use Unix-style paths that only make sense on Nix/Unix
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"CONFIG_PATH defaults to OPENCLAW_HOME/.openclaw/openclaw.json",
|
||||
async () => {
|
||||
await withEnvOverride(
|
||||
{
|
||||
OPENCLAW_HOME: "/custom/home",
|
||||
OPENCLAW_CONFIG_PATH: undefined,
|
||||
OPENCLAW_STATE_DIR: undefined,
|
||||
},
|
||||
async () => {
|
||||
const { CONFIG_PATH } = await import("./config.js");
|
||||
expect(CONFIG_PATH).toBe(path.resolve("/custom/home/.openclaw/openclaw.json"));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
it("CONFIG_PATH defaults to OPENCLAW_HOME/.openclaw/openclaw.json", async () => {
|
||||
const customHome = path.join(path.sep, "custom", "home");
|
||||
await withEnvOverride(
|
||||
{
|
||||
OPENCLAW_HOME: customHome,
|
||||
OPENCLAW_CONFIG_PATH: undefined,
|
||||
OPENCLAW_STATE_DIR: undefined,
|
||||
},
|
||||
async () => {
|
||||
const { CONFIG_PATH } = await import("./config.js");
|
||||
expect(CONFIG_PATH).toBe(
|
||||
path.join(path.resolve(customHome), ".openclaw", "openclaw.json"),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("CONFIG_PATH defaults to ~/.openclaw/openclaw.json when env not set", async () => {
|
||||
await withEnvOverride(
|
||||
|
||||
Reference in New Issue
Block a user