fix(ci): stabilize windows paths

This commit is contained in:
Peter Steinberger
2026-01-08 03:02:46 +00:00
parent 7bddaa41ea
commit 6e4174b5dc
11 changed files with 126 additions and 41 deletions

View File

@@ -13,6 +13,40 @@ import {
resolveAuthProfileOrder,
} from "./auth-profiles.js";
const HOME_ENV_KEYS = ["HOME", "USERPROFILE", "HOMEDRIVE", "HOMEPATH"] as const;
type HomeEnvSnapshot = Record<
(typeof HOME_ENV_KEYS)[number],
string | undefined
>;
const snapshotHomeEnv = (): HomeEnvSnapshot => ({
HOME: process.env.HOME,
USERPROFILE: process.env.USERPROFILE,
HOMEDRIVE: process.env.HOMEDRIVE,
HOMEPATH: process.env.HOMEPATH,
});
const restoreHomeEnv = (snapshot: HomeEnvSnapshot) => {
for (const key of HOME_ENV_KEYS) {
const value = snapshot[key];
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
}
};
const setTempHome = (tempHome: string) => {
process.env.HOME = tempHome;
if (process.platform === "win32") {
process.env.USERPROFILE = tempHome;
const root = path.parse(tempHome).root;
process.env.HOMEDRIVE = root.replace(/\\$/, "");
process.env.HOMEPATH = tempHome.slice(root.length - 1);
}
};
describe("resolveAuthProfileOrder", () => {
const store: AuthProfileStore = {
version: 1,
@@ -347,12 +381,12 @@ describe("external CLI credential sync", () => {
const agentDir = fs.mkdtempSync(
path.join(os.tmpdir(), "clawdbot-cli-sync-"),
);
const originalHome = process.env.HOME;
const originalHome = snapshotHomeEnv();
try {
// Create a temp home with Claude CLI credentials
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "clawdbot-home-"));
process.env.HOME = tempHome;
setTempHome(tempHome);
// Create Claude CLI credentials
const claudeDir = path.join(tempHome, ".claude");
@@ -400,7 +434,7 @@ describe("external CLI credential sync", () => {
(store.profiles[CLAUDE_CLI_PROFILE_ID] as { expires: number }).expires,
).toBeGreaterThan(Date.now());
} finally {
process.env.HOME = originalHome;
restoreHomeEnv(originalHome);
fs.rmSync(agentDir, { recursive: true, force: true });
}
});
@@ -409,11 +443,11 @@ describe("external CLI credential sync", () => {
const agentDir = fs.mkdtempSync(
path.join(os.tmpdir(), "clawdbot-codex-sync-"),
);
const originalHome = process.env.HOME;
const originalHome = snapshotHomeEnv();
try {
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "clawdbot-home-"));
process.env.HOME = tempHome;
setTempHome(tempHome);
// Create Codex CLI credentials
const codexDir = path.join(tempHome, ".codex");
@@ -444,7 +478,7 @@ describe("external CLI credential sync", () => {
(store.profiles[CODEX_CLI_PROFILE_ID] as { access: string }).access,
).toBe("codex-access-token");
} finally {
process.env.HOME = originalHome;
restoreHomeEnv(originalHome);
fs.rmSync(agentDir, { recursive: true, force: true });
}
});
@@ -453,11 +487,11 @@ describe("external CLI credential sync", () => {
const agentDir = fs.mkdtempSync(
path.join(os.tmpdir(), "clawdbot-no-overwrite-"),
);
const originalHome = process.env.HOME;
const originalHome = snapshotHomeEnv();
try {
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "clawdbot-home-"));
process.env.HOME = tempHome;
setTempHome(tempHome);
// Create Claude CLI credentials
const claudeDir = path.join(tempHome, ".claude");
@@ -498,7 +532,7 @@ describe("external CLI credential sync", () => {
);
expect(store.profiles[CLAUDE_CLI_PROFILE_ID]).toBeDefined();
} finally {
process.env.HOME = originalHome;
restoreHomeEnv(originalHome);
fs.rmSync(agentDir, { recursive: true, force: true });
}
});
@@ -507,11 +541,11 @@ describe("external CLI credential sync", () => {
const agentDir = fs.mkdtempSync(
path.join(os.tmpdir(), "clawdbot-cli-no-downgrade-"),
);
const originalHome = process.env.HOME;
const originalHome = snapshotHomeEnv();
try {
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "clawdbot-home-"));
process.env.HOME = tempHome;
setTempHome(tempHome);
const claudeDir = path.join(tempHome, ".claude");
fs.mkdirSync(claudeDir, { recursive: true });
@@ -548,7 +582,7 @@ describe("external CLI credential sync", () => {
(store.profiles[CLAUDE_CLI_PROFILE_ID] as { access: string }).access,
).toBe("store-access");
} finally {
process.env.HOME = originalHome;
restoreHomeEnv(originalHome);
fs.rmSync(agentDir, { recursive: true, force: true });
}
});
@@ -557,11 +591,11 @@ describe("external CLI credential sync", () => {
const agentDir = fs.mkdtempSync(
path.join(os.tmpdir(), "clawdbot-codex-refresh-sync-"),
);
const originalHome = process.env.HOME;
const originalHome = snapshotHomeEnv();
try {
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "clawdbot-home-"));
process.env.HOME = tempHome;
setTempHome(tempHome);
const codexDir = path.join(tempHome, ".codex");
fs.mkdirSync(codexDir, { recursive: true });
@@ -596,7 +630,7 @@ describe("external CLI credential sync", () => {
(store.profiles[CODEX_CLI_PROFILE_ID] as { refresh: string }).refresh,
).toBe("new-refresh");
} finally {
process.env.HOME = originalHome;
restoreHomeEnv(originalHome);
fs.rmSync(agentDir, { recursive: true, force: true });
}
});

View File

@@ -7,6 +7,12 @@ import {
processTool,
} from "./bash-tools.js";
const nodePath = process.execPath.includes(" ")
? `"${process.execPath}"`
: process.execPath;
const nodeEval = (script: string) =>
`${nodePath} -e "${script.replaceAll('"', '\\"')}"`;
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
async function waitForCompletion(sessionId: string) {
@@ -32,7 +38,7 @@ beforeEach(() => {
describe("bash tool backgrounding", () => {
it("backgrounds after yield and can be polled", async () => {
const result = await bashTool.execute("call1", {
command: "node -e \"setTimeout(() => { console.log('done') }, 50)\"",
command: nodeEval("setTimeout(function(){ console.log('done') }, 50)"),
yieldMs: 10,
});
@@ -62,7 +68,7 @@ describe("bash tool backgrounding", () => {
it("supports explicit background", async () => {
const result = await bashTool.execute("call1", {
command: "node -e \"setTimeout(() => { console.log('later') }, 50)\"",
command: nodeEval("setTimeout(function(){ console.log('later') }, 50)"),
background: true,
});
@@ -97,7 +103,7 @@ describe("bash tool backgrounding", () => {
const customProcess = createProcessTool();
const result = await customBash.execute("call1", {
command: 'node -e "setInterval(() => {}, 1000)"',
command: nodeEval("setInterval(function(){}, 1000)"),
background: true,
});
@@ -148,8 +154,9 @@ describe("bash tool backgrounding", () => {
it("logs line-based slices and defaults to last lines", async () => {
const result = await bashTool.execute("call1", {
command:
"node -e \"console.log('one'); console.log('two'); console.log('three');\"",
command: nodeEval(
"console.log('one'); console.log('two'); console.log('three');",
),
background: true,
});
const sessionId = (result.details as { sessionId: string }).sessionId;
@@ -169,8 +176,9 @@ describe("bash tool backgrounding", () => {
it("supports line offsets for log slices", async () => {
const result = await bashTool.execute("call1", {
command:
"node -e \"console.log('alpha'); console.log('beta'); console.log('gamma');\"",
command: nodeEval(
"console.log('alpha'); console.log('beta'); console.log('gamma');",
),
background: true,
});
const sessionId = (result.details as { sessionId: string }).sessionId;
@@ -193,11 +201,11 @@ describe("bash tool backgrounding", () => {
const processB = createProcessTool({ scopeKey: "agent:beta" });
const resultA = await bashA.execute("call1", {
command: 'node -e "setTimeout(() => {}, 50)"',
command: nodeEval("setTimeout(function(){}, 50)"),
background: true,
});
const resultB = await bashB.execute("call2", {
command: 'node -e "setTimeout(() => {}, 50)"',
command: nodeEval("setTimeout(function(){}, 50)"),
background: true,
});

View File

@@ -1,4 +1,5 @@
import { EventEmitter } from "node:events";
import path from "node:path";
import { Readable } from "node:stream";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { ClawdbotConfig } from "../config/config.js";
@@ -349,7 +350,9 @@ describe("Agent-specific sandbox config", () => {
});
expect(context).toBeDefined();
expect(context?.workspaceDir).toContain("/tmp/isolated-sandboxes");
expect(context?.workspaceDir).toContain(
path.resolve("/tmp/isolated-sandboxes"),
);
});
it("should prefer agent config over global for multiple agents", async () => {