Skip to content

Commit 3569242

Browse files
committed
fix(ci): repair the three failures the Windows panic was hiding
With the Bun worker panic gone, `bun test` reached the end of the suite on windows-latest for the first time and reported 10 real failures. None are new; the crash simply killed the run at 38s, before any of them could execute. 1. `scripts/release.ts` — `Bun.spawn(["npm", ...])` cannot resolve a Windows `.cmd` shim. `Bun.$` can, which is why only the three `runQuiet` callers broke. Those run in the release preflight, the very first step, so the script aborted before invoking a single shim: the tests saw exit 1 and an empty call log. Resolve through `Bun.which` with PATHEXT candidates. 2. `tests/test-home-guard.test.ts` — `URL.pathname` is not a filesystem path on Windows (`/D:/a/...`). The leading slash made `cwd` invalid, and `Bun.spawnSync` blamed the executable instead: `ENOENT ... bun.exe`, for a Bun that was exactly where setup-bun left it. Use `fileURLToPath` for `cwd` and keep the `file://` href for specifiers interpolated into probe source, so Windows backslashes cannot be eaten as string escapes. 3. `gui/tests/client-resource-poll.test.tsx` — a 1s `waitFor` ceiling. The visibility test waits on a real 20ms interval plus a React commit, which a loaded macOS runner missed mid-suite while the same file passed alone. The assertion is whether the fetch happens, never how fast, so 5s costs a healthy run nothing. Its failure also cascaded into the next file's `window.event` teardown error. Evidence: 6190 pass / 0 fail across 445 files, 427 GUI tests pass, typecheck clean.
1 parent c300c6f commit 3569242

3 files changed

Lines changed: 59 additions & 11 deletions

File tree

‎gui/tests/client-resource-poll.test.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ afterEach(() => {
2626
}
2727
});
2828

29-
async function waitFor(predicate: () => boolean, timeoutMs = 1000): Promise<void> {
29+
/**
30+
* 1s was enough on an idle machine and not enough on a loaded CI runner: the
31+
* visibility test waits for a poll that only fires after a real 20ms interval
32+
* plus a React commit, and macOS CI blew through the budget mid-suite while the
33+
* same file passed in isolation. The assertions below are about *whether* the
34+
* fetch happens, never about how fast, so a longer ceiling costs nothing on a
35+
* healthy run — it only stops a busy runner from reading as a product bug.
36+
*/
37+
async function waitFor(predicate: () => boolean, timeoutMs = 5000): Promise<void> {
3038
const start = Date.now();
3139
while (!predicate()) {
3240
if (Date.now() - start > timeoutMs) throw new Error("waitFor timed out");

‎scripts/release.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,30 @@ const SERVICE_WORKFLOW = "service-lifecycle.yml";
3939
const CI_WAIT_TIMEOUT_MS = 20 * 60 * 1000;
4040
const CI_POLL_MS = 10 * 1000;
4141

42+
/**
43+
* On Windows, `npm`, `gh`, and `git` are usually `.cmd`/`.exe` shims rather than
44+
* bare files on PATH. `Bun.$` resolves those, but `Bun.spawn` does not: it looks
45+
* for a literal `npm` and fails. The preflight below is the FIRST thing the
46+
* release runs, so that mismatch aborted the script before a single shim was
47+
* invoked — which is why the release-helper tests saw exit 1 and an empty call
48+
* log on windows-latest while every other platform passed.
49+
*
50+
* `.cmd` is tried ahead of `.exe` because that is what npm and gh actually ship
51+
* on Windows; a real `.exe` (git) still resolves through PATHEXT lookup below.
52+
*/
53+
function resolveCommandForPlatform(command: string[]): string[] {
54+
if (process.platform !== "win32") return command;
55+
const [bin, ...rest] = command;
56+
if (!bin || bin.includes("\\") || bin.includes("/") || /\.[a-z]+$/i.test(bin)) return command;
57+
for (const extension of [".cmd", ".exe", ".bat"]) {
58+
const resolved = Bun.which(`${bin}${extension}`);
59+
if (resolved) return [resolved, ...rest];
60+
}
61+
return [Bun.which(bin) ?? bin, ...rest];
62+
}
63+
4264
async function runQuiet(command: string[]): Promise<CommandResult> {
43-
const proc = Bun.spawn(command, { stdout: "pipe", stderr: "pipe" });
65+
const proc = Bun.spawn(resolveCommandForPlatform(command), { stdout: "pipe", stderr: "pipe" });
4466
const [stdout, stderr, exitCode] = await Promise.all([
4567
new Response(proc.stdout).text(),
4668
new Response(proc.stderr).text(),

‎tests/test-home-guard.test.ts‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,28 @@ import { describe, expect, test } from "bun:test";
1313
import { mkdtempSync, mkdirSync, readFileSync, symlinkSync, writeFileSync } from "node:fs";
1414
import { homedir, tmpdir } from "node:os";
1515
import { join } from "node:path";
16+
import { fileURLToPath } from "node:url";
1617
import { assertNotRealHomeUnderTest, isTestHomeGuardArmed, protectedHomeForTests } from "../src/lib/test-home-guard";
1718
import { getConfigDir } from "../src/config";
1819

19-
const REPO_ROOT = new URL("..", import.meta.url).pathname;
20+
/**
21+
* Two different things are needed from the repo root, and conflating them is
22+
* what broke Windows.
23+
*
24+
* `cwd` needs a real filesystem path. `URL.pathname` is not one on Windows: it
25+
* yields `/D:/a/opencodex/opencodex/`, whose leading slash makes the directory
26+
* invalid, and `Bun.spawnSync` then reports the failure against the
27+
* *executable* — `ENOENT ... 'C:\Users\runneradmin\.bun\bin\bun.exe'` — even
28+
* though Bun sits exactly where setup-bun left it. That misdirection is why
29+
* this read as a missing-Bun problem for four CI runs.
30+
*/
31+
const REPO_ROOT = fileURLToPath(new URL("..", import.meta.url));
32+
/**
33+
* The probe source needs a module SPECIFIER, not a path. A Windows path
34+
* (`D:\a\...`) embedded in an import string would have its backslashes eaten as
35+
* escapes, so keep the `file://` URL form for anything interpolated into code.
36+
*/
37+
const REPO_ROOT_URL = new URL("..", import.meta.url).href;
2038

2139
/**
2240
* Run a probe in a child process so we control OCX_REAL_HOME at STARTUP — the guard
@@ -50,9 +68,9 @@ describe("real-home write guard", () => {
5068
test("armed + the protected home: all three writers throw", () => {
5169
const { realHome, opencodexHome } = sentinelHome();
5270
const probe = runProbe(`
53-
import { saveConfig } from "${REPO_ROOT}src/config";
54-
import { mutateStore } from "${REPO_ROOT}src/oauth/store";
55-
import { saveCodexAccountCredential } from "${REPO_ROOT}src/codex/account-store";
71+
import { saveConfig } from "${REPO_ROOT_URL}src/config";
72+
import { mutateStore } from "${REPO_ROOT_URL}src/oauth/store";
73+
import { saveCodexAccountCredential } from "${REPO_ROOT_URL}src/codex/account-store";
5674
const threw: string[] = [];
5775
const REFUSAL = "refusing to write the real OpenCodex home";
5876
try { saveConfig({ providers: {}, defaultProvider: "openai", port: 10100 } as never); }
@@ -79,7 +97,7 @@ describe("real-home write guard", () => {
7997
// The 54 suites that mkdtemp their own home must keep working with no opt-in.
8098
const dir = mkdtempSync(join(tmpdir(), "ocx-plain-home-"));
8199
const probe = runProbe(`
82-
import { saveConfig } from "${REPO_ROOT}src/config";
100+
import { saveConfig } from "${REPO_ROOT_URL}src/config";
83101
saveConfig({ providers: {}, defaultProvider: "openai", port: 10100 } as never);
84102
console.log("wrote");
85103
`, { OCX_TEST_HOME_GUARD: "1", OCX_REAL_HOME: join(tmpdir(), "ocx-nonexistent-real-home"), OPENCODEX_HOME: dir });
@@ -91,7 +109,7 @@ describe("real-home write guard", () => {
91109
test("disarmed: the protected home is allowed (production stays inert)", () => {
92110
const { realHome, opencodexHome } = sentinelHome();
93111
const probe = runProbe(`
94-
import { saveConfig } from "${REPO_ROOT}src/config";
112+
import { saveConfig } from "${REPO_ROOT_URL}src/config";
95113
saveConfig({ providers: {}, defaultProvider: "openai", port: 10100 } as never);
96114
console.log("wrote");
97115
`, { OCX_TEST_HOME_GUARD: undefined, OCX_REAL_HOME: realHome, OPENCODEX_HOME: opencodexHome });
@@ -105,7 +123,7 @@ describe("real-home write guard", () => {
105123
const { realHome } = sentinelHome();
106124
const decoyHome = mkdtempSync(join(tmpdir(), "ocx-decoy-home-"));
107125
const probe = runProbe(`
108-
import { protectedHomeForTests } from "${REPO_ROOT}src/lib/test-home-guard";
126+
import { protectedHomeForTests } from "${REPO_ROOT_URL}src/lib/test-home-guard";
109127
console.log(protectedHomeForTests());
110128
`, { OCX_TEST_HOME_GUARD: "1", OCX_REAL_HOME: realHome, HOME: decoyHome });
111129

@@ -119,7 +137,7 @@ describe("real-home write guard", () => {
119137
const link = join(linkDir, "looks-like-temp");
120138
symlinkSync(opencodexHome, link);
121139
const probe = runProbe(`
122-
import { assertNotRealHomeUnderTest } from "${REPO_ROOT}src/lib/test-home-guard";
140+
import { assertNotRealHomeUnderTest } from "${REPO_ROOT_URL}src/lib/test-home-guard";
123141
try { assertNotRealHomeUnderTest(${JSON.stringify(link)}); console.log("allowed"); }
124142
catch { console.log("rejected"); }
125143
`, { OCX_TEST_HOME_GUARD: "1", OCX_REAL_HOME: realHome });
@@ -133,7 +151,7 @@ describe("real-home write guard", () => {
133151
const { realHome } = sentinelHome();
134152
const aliased = realHome.startsWith("/var/") ? join("/private", realHome) : realHome.replace(/^\/private/, "");
135153
const probe = runProbe(`
136-
import { assertNotRealHomeUnderTest } from "${REPO_ROOT}src/lib/test-home-guard";
154+
import { assertNotRealHomeUnderTest } from "${REPO_ROOT_URL}src/lib/test-home-guard";
137155
const results: string[] = [];
138156
for (const path of [${JSON.stringify(join(realHome, ".opencodex"))}, ${JSON.stringify(join(aliased, ".opencodex"))}]) {
139157
try { assertNotRealHomeUnderTest(path); results.push("allowed"); } catch { results.push("rejected"); }

0 commit comments

Comments
 (0)