fix(ci): stabilize windows tests
This commit is contained in:
@@ -7,11 +7,33 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
async function withTempHome<T>(fn: (home: string) => Promise<T>): Promise<T> {
|
||||
const base = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-config-"));
|
||||
const previousHome = process.env.HOME;
|
||||
const previousUserProfile = process.env.USERPROFILE;
|
||||
const previousHomeDrive = process.env.HOMEDRIVE;
|
||||
const previousHomePath = process.env.HOMEPATH;
|
||||
process.env.HOME = base;
|
||||
process.env.USERPROFILE = base;
|
||||
if (process.platform === "win32") {
|
||||
const parsed = path.parse(base);
|
||||
process.env.HOMEDRIVE = parsed.root.replace(/\\$/, "");
|
||||
process.env.HOMEPATH = base.slice(Math.max(parsed.root.length - 1, 0));
|
||||
}
|
||||
try {
|
||||
return await fn(base);
|
||||
} finally {
|
||||
process.env.HOME = previousHome;
|
||||
process.env.USERPROFILE = previousUserProfile;
|
||||
if (process.platform === "win32") {
|
||||
if (previousHomeDrive === undefined) {
|
||||
delete process.env.HOMEDRIVE;
|
||||
} else {
|
||||
process.env.HOMEDRIVE = previousHomeDrive;
|
||||
}
|
||||
if (previousHomePath === undefined) {
|
||||
delete process.env.HOMEPATH;
|
||||
} else {
|
||||
process.env.HOMEPATH = previousHomePath;
|
||||
}
|
||||
}
|
||||
await fs.rm(base, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
@@ -402,7 +424,7 @@ describe("Nix integration (U3, U5, U9)", () => {
|
||||
{ CLAWDBOT_STATE_DIR: "/custom/state/dir" },
|
||||
async () => {
|
||||
const { STATE_DIR_CLAWDBOT } = await import("./config.js");
|
||||
expect(STATE_DIR_CLAWDBOT).toBe("/custom/state/dir");
|
||||
expect(STATE_DIR_CLAWDBOT).toBe(path.resolve("/custom/state/dir"));
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -412,7 +434,9 @@ describe("Nix integration (U3, U5, U9)", () => {
|
||||
{ CLAWDBOT_CONFIG_PATH: undefined, CLAWDBOT_STATE_DIR: undefined },
|
||||
async () => {
|
||||
const { CONFIG_PATH_CLAWDBOT } = await import("./config.js");
|
||||
expect(CONFIG_PATH_CLAWDBOT).toMatch(/\.clawdbot\/clawdbot\.json$/);
|
||||
expect(CONFIG_PATH_CLAWDBOT).toMatch(
|
||||
/\.clawdbot[\\/]clawdbot\.json$/,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -435,7 +459,9 @@ describe("Nix integration (U3, U5, U9)", () => {
|
||||
},
|
||||
async () => {
|
||||
const { CONFIG_PATH_CLAWDBOT } = await import("./config.js");
|
||||
expect(CONFIG_PATH_CLAWDBOT).toBe("/custom/state/clawdbot.json");
|
||||
expect(CONFIG_PATH_CLAWDBOT).toBe(
|
||||
path.join(path.resolve("/custom/state"), "clawdbot.json"),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveOAuthDir, resolveOAuthPath } from "./paths.js";
|
||||
@@ -9,9 +10,11 @@ describe("oauth paths", () => {
|
||||
CLAWDBOT_STATE_DIR: "/custom/state",
|
||||
} as NodeJS.ProcessEnv;
|
||||
|
||||
expect(resolveOAuthDir(env, "/custom/state")).toBe("/custom/oauth");
|
||||
expect(resolveOAuthDir(env, "/custom/state")).toBe(
|
||||
path.resolve("/custom/oauth"),
|
||||
);
|
||||
expect(resolveOAuthPath(env, "/custom/state")).toBe(
|
||||
"/custom/oauth/oauth.json",
|
||||
path.join(path.resolve("/custom/oauth"), "oauth.json"),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -21,10 +24,10 @@ describe("oauth paths", () => {
|
||||
} as NodeJS.ProcessEnv;
|
||||
|
||||
expect(resolveOAuthDir(env, "/custom/state")).toBe(
|
||||
"/custom/state/credentials",
|
||||
path.join("/custom/state", "credentials"),
|
||||
);
|
||||
expect(resolveOAuthPath(env, "/custom/state")).toBe(
|
||||
"/custom/state/credentials/oauth.json",
|
||||
path.join("/custom/state", "credentials", "oauth.json"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -138,7 +138,9 @@ describe("sessions", () => {
|
||||
{ CLAWDBOT_STATE_DIR: "/custom/state" } as NodeJS.ProcessEnv,
|
||||
() => "/home/ignored",
|
||||
);
|
||||
expect(dir).toBe("/custom/state/agents/main/sessions");
|
||||
expect(dir).toBe(
|
||||
path.join(path.resolve("/custom/state"), "agents", "main", "sessions"),
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to CLAWDIS_STATE_DIR for session transcripts dir", () => {
|
||||
@@ -146,7 +148,9 @@ describe("sessions", () => {
|
||||
{ CLAWDIS_STATE_DIR: "/legacy/state" } as NodeJS.ProcessEnv,
|
||||
() => "/home/ignored",
|
||||
);
|
||||
expect(dir).toBe("/legacy/state/agents/main/sessions");
|
||||
expect(dir).toBe(
|
||||
path.join(path.resolve("/legacy/state"), "agents", "main", "sessions"),
|
||||
);
|
||||
});
|
||||
|
||||
it("includes topic ids in session transcript filenames", () => {
|
||||
@@ -155,7 +159,13 @@ describe("sessions", () => {
|
||||
try {
|
||||
const sessionFile = resolveSessionTranscriptPath("sess-1", "main", 123);
|
||||
expect(sessionFile).toBe(
|
||||
"/custom/state/agents/main/sessions/sess-1-topic-123.jsonl",
|
||||
path.join(
|
||||
path.resolve("/custom/state"),
|
||||
"agents",
|
||||
"main",
|
||||
"sessions",
|
||||
"sess-1-topic-123.jsonl",
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
if (prev === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user