fix: stabilize gateway tests on windows

This commit is contained in:
Peter Steinberger
2026-01-19 12:12:51 +00:00
parent 588dc43787
commit 9e06d945a2
5 changed files with 50 additions and 8 deletions

View File

@@ -60,17 +60,39 @@ function ensureExperimentalWarningSuppressed(): boolean {
function normalizeWindowsArgv(argv: string[]): string[] {
if (process.platform !== "win32") return argv;
if (argv.length < 3) return argv;
const execBase = path.basename(process.execPath).toLowerCase();
const execPath = process.execPath;
const execPathLower = execPath.toLowerCase();
const execBase = path.basename(execPath).toLowerCase();
const isExecPath = (value: string | undefined): boolean => {
if (!value) return false;
const lower = value.toLowerCase();
return lower === execPathLower || path.basename(lower) === execBase;
};
const arg1 = path.basename(argv[1] ?? "").toLowerCase();
const arg2 = path.basename(argv[2] ?? "").toLowerCase();
const looksLikeEntry = arg1 === "entry.ts" || arg1 === "entry.js";
let next = argv;
if (arg1 === execBase) {
return [argv[0], ...argv.slice(2)];
next = [argv[0], ...argv.slice(2)];
} else if (looksLikeEntry && arg2 === execBase) {
next = [argv[0], argv[1], ...argv.slice(3)];
}
if (looksLikeEntry && arg2 === execBase) {
return [argv[0], argv[1], ...argv.slice(3)];
if (next.length < 3) return next;
const cleaned = [...next];
for (let i = 2; i < cleaned.length; ) {
const arg = cleaned[i];
if (!arg || arg.startsWith("-")) {
i += 1;
continue;
}
if (isExecPath(arg)) {
cleaned.splice(i, 1);
continue;
}
break;
}
return argv;
return cleaned;
}
process.argv = normalizeWindowsArgv(process.argv);

View File

@@ -13,6 +13,7 @@ async function startServerWithDefaultConfig(port: number) {
host: "127.0.0.1",
auth: { mode: "token", token: "secret" },
controlUiEnabled: false,
openAiChatCompletionsEnabled: false,
});
}

View File

@@ -81,12 +81,12 @@ describe("gateway server sessions", () => {
},
"discord:group:dev": {
sessionId: "sess-group",
updatedAt: now - 120_000,
updatedAt: now - 10 * 60_000,
totalTokens: 50,
},
"agent:main:subagent:one": {
sessionId: "sess-subagent",
updatedAt: now - 120_000,
updatedAt: now - 10 * 60_000,
spawnedBy: "agent:main:main",
},
global: {
@@ -147,7 +147,7 @@ describe("gateway server sessions", () => {
}>(ws, "sessions.list", {
includeGlobal: false,
includeUnknown: false,
activeMinutes: 1,
activeMinutes: 5,
});
expect(active.ok).toBe(true);
expect(active.payload?.sessions.map((s) => s.key)).toEqual(["agent:main:main"]);

View File

@@ -37,6 +37,9 @@ let previousHome: string | undefined;
let previousUserProfile: string | undefined;
let previousStateDir: string | undefined;
let previousConfigPath: string | undefined;
let previousSkipBrowserControl: string | undefined;
let previousSkipGmailWatcher: string | undefined;
let previousSkipCanvasHost: string | undefined;
let tempHome: string | undefined;
let tempConfigRoot: string | undefined;
@@ -75,11 +78,17 @@ export function installGatewayTestHooks() {
previousUserProfile = process.env.USERPROFILE;
previousStateDir = process.env.CLAWDBOT_STATE_DIR;
previousConfigPath = process.env.CLAWDBOT_CONFIG_PATH;
previousSkipBrowserControl = process.env.CLAWDBOT_SKIP_BROWSER_CONTROL_SERVER;
previousSkipGmailWatcher = process.env.CLAWDBOT_SKIP_GMAIL_WATCHER;
previousSkipCanvasHost = process.env.CLAWDBOT_SKIP_CANVAS_HOST;
tempHome = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-gateway-home-"));
process.env.HOME = tempHome;
process.env.USERPROFILE = tempHome;
process.env.CLAWDBOT_STATE_DIR = path.join(tempHome, ".clawdbot");
delete process.env.CLAWDBOT_CONFIG_PATH;
process.env.CLAWDBOT_SKIP_BROWSER_CONTROL_SERVER = "1";
process.env.CLAWDBOT_SKIP_GMAIL_WATCHER = "1";
process.env.CLAWDBOT_SKIP_CANVAS_HOST = "1";
tempConfigRoot = path.join(tempHome, ".clawdbot-test");
setTestConfigRoot(tempConfigRoot);
sessionStoreSaveDelayMs.value = 0;
@@ -128,6 +137,13 @@ export function installGatewayTestHooks() {
else process.env.CLAWDBOT_STATE_DIR = previousStateDir;
if (previousConfigPath === undefined) delete process.env.CLAWDBOT_CONFIG_PATH;
else process.env.CLAWDBOT_CONFIG_PATH = previousConfigPath;
if (previousSkipBrowserControl === undefined)
delete process.env.CLAWDBOT_SKIP_BROWSER_CONTROL_SERVER;
else process.env.CLAWDBOT_SKIP_BROWSER_CONTROL_SERVER = previousSkipBrowserControl;
if (previousSkipGmailWatcher === undefined) delete process.env.CLAWDBOT_SKIP_GMAIL_WATCHER;
else process.env.CLAWDBOT_SKIP_GMAIL_WATCHER = previousSkipGmailWatcher;
if (previousSkipCanvasHost === undefined) delete process.env.CLAWDBOT_SKIP_CANVAS_HOST;
else process.env.CLAWDBOT_SKIP_CANVAS_HOST = previousSkipCanvasHost;
if (tempHome) {
await fs.rm(tempHome, {
recursive: true,