Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

Make the Windows test failures test something

anirudhkumar-nanonetsc006a8f7ba90
diff --git a/test/claude-state.test.ts b/test/claude-state.test.ts
index 5f1aa630..aad13eb9 100644
--- a/test/claude-state.test.ts
+++ b/test/claude-state.test.ts
@@ -1,6 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { mkdtempSync, existsSync, chmodSync, mkdirSync, readdirSync, utimesSync } from 'node:fs';
+import { mkdtempSync, existsSync, mkdirSync, readdirSync, utimesSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import {
@@ -49,18 +49,27 @@ test('acquireLock reclaims a stale lock', () => {
assert.equal(acquireLock(d), true, 'stale lock reclaimed');
});
-test('writeJsonAtomic leaves no scratch file behind when the write fails', (t) => {
- if (process.getuid?.() === 0) return t.skip('root writes anywhere, so a read-only dir proves nothing');
+test('writeJsonAtomic leaves no scratch file behind when the write fails', () => {
const d = fresh();
const dir = join(d, 'locked');
mkdirSync(dir, { recursive: true });
- chmodSync(dir, 0o500);
+
+ // The failure is injected by putting a *directory* where the file belongs, so the
+ // rename fails. This replaces a read-only parent dir (`chmod 0o500`), which was
+ // both non-portable — Windows ignores it, and so does root, hence the skip this
+ // test used to carry — and weaker: the tmp file was never created there, so there
+ // was never anything that could have been left behind. Here it definitely is.
+ const target = join(dir, 'out.json');
+ mkdirSync(target);
// Every CLI invocation is a new pid, so a repeatedly failing write would leave one
// full-size `<path>.<pid>.tmp` per attempt, and nothing in graft ever lists these
// directories to clean them up — on a nearly-full disk that accelerates the ENOSPC
// that caused it.
- assert.throws(() => writeJsonAtomic(join(dir, 'out.json'), { pad: 'x'.repeat(1024) }));
- chmodSync(dir, 0o700);
- assert.deepEqual(readdirSync(dir), [], 'no .tmp residue');
+ assert.throws(() => writeJsonAtomic(target, { pad: 'x'.repeat(1024) }));
+ assert.deepEqual(
+ readdirSync(dir).filter((f) => f.endsWith('.tmp')),
+ [],
+ 'no .tmp residue',
+ );
});
diff --git a/test/graph-incremental.test.ts b/test/graph-incremental.test.ts
index 783478ce..46dfabff 100644
--- a/test/graph-incremental.test.ts
+++ b/test/graph-incremental.test.ts
@@ -15,6 +15,7 @@ import { fingerprintPath, isClean, probeDrift, readFingerprint } from "../src/gr
import { readAskIndex } from "../src/ask/index-file.js";
import { readGraph, wiringPath } from "../src/graph/write.js";
import type { GraphV1 } from "../src/graph/types.js";
+import { chmodDenialUnavailable } from "./helpers.js";
const MATH = [
"export function add(a: number, b: number): number {",
@@ -159,7 +160,8 @@ test("every file on disk lands in the fingerprint", async () => {
});
test("an unreadable file is still recorded, so it can't look new on every probe", async (t) => {
- if (process.getuid?.() === 0) return t.skip("root reads anything, so chmod 000 proves nothing");
+ const why = chmodDenialUnavailable();
+ if (why) return t.skip(why);
const d = repo();
const secret = join(d, "src", "secret.ts");
writeFileSync(secret, "export function secretFn(): number {\n return 1;\n}\n");
diff --git a/test/graph-refresh.test.ts b/test/graph-refresh.test.ts
index 86970113..14d22d64 100644
--- a/test/graph-refresh.test.ts
+++ b/test/graph-refresh.test.ts
@@ -8,7 +8,6 @@ import assert from "node:assert/strict";
import { chmodSync, existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { spawn } from "node:child_process";
-import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { buildGraph } from "../src/graph/build.js";
import { ensureFreshChildren, ensureFreshGraph, refreshNote } from "../src/graph/refresh.js";
@@ -18,6 +17,7 @@ import { readGraph, wiringPath } from "../src/graph/write.js";
import { acquireLock, readStats, releaseLock, writeStats, emptyStats } from "../src/util/state.js";
import { callTool } from "../src/mcp/tools.js";
import type { GraphV1 } from "../src/graph/types.js";
+import { chmodDenialUnavailable } from "./helpers.js";
const MATH = "export function add(a: number, b: number): number {\n return a + b;\n}\n";
/** A *function*, because a plain `export const` is not extracted as a symbol node. */
@@ -244,7 +244,8 @@ test("GRAFT_REFRESH=hash: drift the probe reports is drift the rebuild repairs",
});
test("a file that becomes readable again is picked up through the probe", async (t) => {
- if (process.getuid?.() === 0) return t.skip("root reads anything, so chmod 000 proves nothing");
+ const why = chmodDenialUnavailable();
+ if (why) return t.skip(why);
const d = repo();
const hidden = join(d, "src", "hidden.ts");
writeFileSync(hidden, "export function reachable(): number {\n return 1;\n}\n");
@@ -265,7 +266,10 @@ test("a file that becomes readable again is picked up through the probe", async
});
test("an unwritable cache costs reuse, not correctness", async (t) => {
- if (process.getuid?.() === 0) return t.skip("root writes anywhere, so a read-only dir proves nothing");
+ // A mode on a *directory* is the one denial Windows ignores completely, so unlike
+ // the read-only-file case below there is no portable way to run this there.
+ const why = chmodDenialUnavailable();
+ if (why) return t.skip(why);
const d = repo();
await buildGraph(d);
@@ -419,7 +423,13 @@ test("callTool refreshes before answering — except for graft_check_freshness",
assert.ok(!again.text.startsWith("[graft] refreshed"), "nothing moved — no note, no rebuild");
});
-test("a process killed while holding the lock releases it", async () => {
+test("a process killed while holding the lock releases it", async (t) => {
+ // Windows has no SIGTERM: `child.kill()` there calls TerminateProcess, so no
+ // handler runs and nothing can release the lock on the way out. The safety net on
+ // that platform is the stale-lock reclaim (`LOCK_STALE_MS`), covered above.
+ if (process.platform === "win32") {
+ return t.skip("no SIGTERM on Windows — kill() terminates without unwinding, so a handler cannot run");
+ }
const d = repo();
const cache = join(outOf(d), ".cache");
mkdirSync(cache, { recursive: true });
@@ -430,12 +440,14 @@ test("a process killed while holding the lock releases it", async () => {
// for that is to exit without unwinding. So the `finally` that releases the lock
// never ran, and the abandoned lock then blocked the background sync and made every
// query wait-then-answer-stale until it aged out.
- const src = fileURLToPath(new URL("../src", import.meta.url));
+ // `file://` URLs, not native paths: a dynamic `import("D:\\…\\state.ts")` fails on
+ // Windows, where ESM reads the drive letter as a URL scheme.
+ const mod = (rel: string) => JSON.stringify(new URL(rel, import.meta.url).href);
const child = spawn(
process.execPath,
["--import", "tsx", "-e",
- `const { acquireLockIn } = await import(${JSON.stringify(`${src}/util/state.ts`)});
- const { releaseOnSignal } = await import(${JSON.stringify(`${src}/graph/refresh.ts`)});
+ `const { acquireLockIn } = await import(${mod("../src/util/state.ts")});
+ const { releaseOnSignal } = await import(${mod("../src/graph/refresh.ts")});
const cache = process.argv[1];
if (!acquireLockIn(cache)) { process.exit(9); }
releaseOnSignal(cache);
diff --git a/test/graph-seed.test.ts b/test/graph-seed.test.ts
index bca1bf56..a2621477 100644
--- a/test/graph-seed.test.ts
+++ b/test/graph-seed.test.ts
@@ -14,29 +14,28 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
-import {
- existsSync,
- mkdirSync,
- mkdtempSync,
- readFileSync,
- readdirSync,
- realpathSync,
- rmSync,
- writeFileSync,
-} from "node:fs";
-import { tmpdir } from "node:os";
+import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { buildGraph } from "../src/graph/build.js";
+import { fingerprintPath } from "../src/graph/fingerprint.js";
import { ensureFreshGraph, refreshNote } from "../src/graph/refresh.js";
import { mainWorktreeRoot, seedGraph } from "../src/graph/seed.js";
import { readGraph, wiringPath } from "../src/graph/write.js";
import { callTool } from "../src/mcp/tools.js";
+import { tmpRepo } from "./helpers.js";
const MATH = "export function add(a: number, b: number): number {\n return a + b;\n}\n";
const MUL = "export function mul(a: number, b: number): number {\n return a * b;\n}\n";
const outOf = (d: string): string => join(d, "graft");
-const tmp = (tag: string): string => mkdtempSync(join(tmpdir(), `graft-seed-${tag}-`));
+/**
+ * Realpath'd (see {@link tmpRepo}), which this file needs more than most: git writes
+ * the *resolved* absolute path into a worktree's `.git` pointer, so `seededFrom` comes
+ * back long-form while `tmpdir()` on Windows hands out the 8.3 short form
+ * (`C:\Users\RUNNER~1\…` vs `C:\Users\runneradmin\…`). Comparing the two fails on a
+ * difference that isn't one.
+ */
+const tmp = (tag: string): string => tmpRepo(`seed-${tag}`);
/* ------------------------------------------------------------------ *
* mainWorktreeRoot: telling the shapes apart
@@ -154,7 +153,7 @@ function gitRepo(): string {
}
function addWorktree(main: string, name: string): string {
- const wt = join(mkdtempSync(join(tmpdir(), "graft-seed-wt-")), name);
+ const wt = join(tmp("wt"), name);
git(main, "worktree", "add", "--detach", wt, "HEAD");
return wt;
}
@@ -293,6 +292,14 @@ test("seedGraph declines a --dir override and a checkout that already has a grap
assert.equal(seedGraph(wt).seeded, true, "first call copies");
assert.deepEqual(seedGraph(wt), { seeded: false }, "second call has nothing to do");
+ // The freshness record has to travel with the graph, or the query right after the
+ // seed finds no fingerprint, cannot diff against the parent, and rebuilds the whole
+ // repo — which is the expensive thing seeding exists to avoid. Asserted on the
+ // direct `seedGraph` call because the refresh gate writes a fresh fingerprint of its
+ // own moments later, which would mask a copy that never happened.
+ assert.ok(existsSync(fingerprintPath(outOf(main))), "the parent has a fingerprint to give");
+ assert.ok(existsSync(fingerprintPath(outOf(wt))), "and the seed brought it across");
+
rmSync(main, { recursive: true, force: true });
rmSync(wt, { recursive: true, force: true });
});
@@ -312,9 +319,9 @@ test("`graft build` in a worktree starts from the parent's graph, not from scrat
writeFileSync(join(wt, "src", "math.ts"), `${MATH}${MUL}`);
const g = await buildGraph(wt);
- // `realpathSync`: git writes the canonical path into the worktree's `.git`, and on
- // macOS the temp dir arrives here as the `/var` symlink to `/private/var`.
- assert.equal(g.seededFrom, realpathSync(main), "reported, because the user never built here");
+ // Compared directly: `tmp()` already canonicalizes, and git writes that same
+ // canonical path into the worktree's `.git` pointer.
+ assert.equal(g.seededFrom, main, "reported, because the user never built here");
assert.equal(g.parsed, 1, "only the file this checkout changed was re-parsed");
assert.ok(g.cards > 0, "and the passive surface is rebuilt for this checkout");
diff --git a/test/helpers.ts b/test/helpers.ts
index 106c0c0d..73073bdb 100644
--- a/test/helpers.ts
+++ b/test/helpers.ts
@@ -2,9 +2,96 @@
* Offline, deterministic test doubles so the pipeline runs with no keys, no
* Ollama, and no network — the same "bring your own components" seam the engine
* exposes via EngineConfig.summarizer / .synthesizer.
+ *
+ * Also the shared scratch-dir and child-process helpers. Those live here rather
+ * than being hand-rolled per file because both carry a platform trap that is
+ * invisible until CI runs on Windows: see {@link tmpRepo} and {@link homeEnv}.
*/
+import { mkdtempSync, realpathSync } from "node:fs";
+import { spawnSync, type SpawnSyncReturns } from "node:child_process";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
import type { Summarizer, Synthesizer, SynthNode, SynthLink, FileSummary } from "../src/index.js";
+/**
+ * A fresh scratch directory, canonicalized.
+ *
+ * The canonicalization is the point. On Windows `tmpdir()` hands back the 8.3 short
+ * form (`C:\Users\RUNNER~1\AppData\Local\Temp`), while anything that resolves the
+ * path for itself — a child process, `git` writing a worktree's `.git` pointer —
+ * reports the long form (`C:\Users\runneradmin\…`). Compare the two and an
+ * assertion fails on a difference that isn't real. On macOS the same call unwraps
+ * `/var` → `/private/var`, which is why it's worth doing everywhere.
+ *
+ * `.native` specifically: plain `realpathSync` is JS-level and resolves symlinks
+ * without expanding a Windows short name, so it does *not* fix the case above.
+ * `.native` goes through the OS (`GetFinalPathNameByHandle`) and does.
+ */
+export function tmpRepo(tag: string): string {
+ return realpathSync.native(mkdtempSync(join(tmpdir(), `graft-${tag}-`)));
+}
+
+/**
+ * Child-process env that points `os.homedir()` at a scratch directory, so a test
+ * can never touch the real `~/.codex`.
+ *
+ * Both variables, because `homedir()` reads a different one per platform: `HOME`
+ * on posix, `USERPROFILE` on Windows. Setting only `HOME` leaves a Windows child
+ * pointed at the real profile — the test then exercises whatever agents happen to
+ * be installed on the runner instead of the fixture it built.
+ */
+export function homeEnv(home: string): NodeJS.ProcessEnv {
+ return { ...process.env, HOME: home, USERPROFILE: home };
+}
+
+/**
+ * Why a test can't inject a failure by removing permission — or null when it can.
+ *
+ * On Windows the mode bits map onto the read-only *attribute*: it does block writes
+ * to a file (so `chmod 0o400` to fail a write still works there), but nothing blocks
+ * reads, and a mode set on a *directory* is ignored outright. Node exposes no
+ * portable way to deny access, so a test that depends on denial says so by name
+ * rather than passing vacuously. Root has the same problem for the same reason,
+ * which is why both live behind one call.
+ */
+export function chmodDenialUnavailable(): string | null {
+ if (process.platform === "win32") {
+ return "chmod does not deny access on Windows — the mode maps onto the read-only attribute";
+ }
+ if (process.getuid?.() === 0) return "running as root, which reads and writes regardless of mode";
+ return null;
+}
+
+export interface CliRun extends SpawnSyncReturns<string> {
+ /** status/signal/stdout/stderr in one string, for assertion messages. */
+ describe(): string;
+}
+
+/**
+ * Run the real CLI through tsx and return the full result — stdout, stderr, exit
+ * status — rather than throwing on failure.
+ *
+ * `execFileSync` throws and buries stderr in the exception, which is how four
+ * `init` tests came to fail on Windows with nothing to go on but "did not match".
+ * The `timeout` matters just as much: a child that blocks on stdin used to burn
+ * the runner's patience silently, so it fails fast and says so instead.
+ */
+export function runCli(args: string[], opts: { home?: string; timeoutMs?: number } = {}): CliRun {
+ const res = spawnSync(process.execPath, ["--import", "tsx", "src/cli.ts", ...args], {
+ encoding: "utf8",
+ timeout: opts.timeoutMs ?? 120_000,
+ env: opts.home ? homeEnv(opts.home) : process.env,
+ }) as CliRun;
+ res.describe = () =>
+ [
+ `graft ${args.join(" ")}`,
+ ` status: ${res.status}${res.signal ? ` (signal ${res.signal})` : ""}`,
+ ` stdout: ${JSON.stringify(res.stdout ?? "")}`,
+ ` stderr: ${JSON.stringify(res.stderr ?? "")}`,
+ ].join("\n");
+ return res;
+}
+
/** Summarizer that passes the source through unchanged, so tests control the text. */
export class PassthroughSummarizer implements Summarizer {
async summarize(code: string): Promise<string> {
diff --git a/test/hosts-codex-hooks.test.ts b/test/hosts-codex-hooks.test.ts
index 6a235cd0..bb0bd339 100644
--- a/test/hosts-codex-hooks.test.ts
+++ b/test/hosts-codex-hooks.test.ts
@@ -7,6 +7,21 @@ import { installCodexHooks } from '../src/hosts/codex-hooks.js';
function fresh(): string { return mkdtempSync(join(tmpdir(), 'graft-cxhooks-')); }
+/**
+ * Windows has no POSIX exec bit — `statSync().mode & 0o111` is always 0 there, and
+ * `chmod` cannot strip a bit the filesystem doesn't have. So assert the property
+ * that exists on both platforms (the shim is installed where the hook config points)
+ * and check the mode only where there is one. Skipping the whole test instead would
+ * drop Windows coverage of the install path, which is the part that can actually
+ * break.
+ */
+const HAS_EXEC_BIT = process.platform !== 'win32';
+
+function assertRunnableShim(shim: string, note: string): void {
+ assert.ok(existsSync(shim), `${note}: shim missing at ${shim}`);
+ if (HAS_EXEC_BIT) assert.ok(statSync(shim).mode & 0o111, note);
+}
+
test('no-op when the CLI home dir is absent', () => {
assert.deepEqual(installCodexHooks(fresh()), []);
});
@@ -17,8 +32,7 @@ test('writes shim + hooks.json entry, idempotent on re-run', () => {
const w = installCodexHooks(home);
assert.equal(w.length, 2);
const shim = join(home, '.codex', 'hooks', 'graft', 'graft-hooks.cjs');
- assert.ok(existsSync(shim));
- assert.ok(statSync(shim).mode & 0o111, 'shim is executable');
+ assertRunnableShim(shim, 'shim is executable');
const cfg = JSON.parse(readFileSync(join(home, '.codex', 'hooks.json'), 'utf8'));
const entries = cfg.hooks.PostToolUse;
assert.equal(entries.length, 1);
@@ -72,8 +86,12 @@ test('re-heals shim exec bit when a prior install had its mode stripped', () =>
mkdirSync(join(home, '.codex'), { recursive: true });
installCodexHooks(home);
const shim = join(home, '.codex', 'hooks', 'graft', 'graft-hooks.cjs');
- chmodSync(shim, 0o644);
- assert.ok(!(statSync(shim).mode & 0o111), 'exec bit stripped before re-run');
+ if (HAS_EXEC_BIT) {
+ chmodSync(shim, 0o644);
+ assert.ok(!(statSync(shim).mode & 0o111), 'exec bit stripped before re-run');
+ }
+ // On Windows this is the plain re-run case: the install must still converge on a
+ // shim in place, which is all "re-healing" can mean without an exec bit.
installCodexHooks(home);
- assert.ok(statSync(shim).mode & 0o111, 'exec bit restored after re-run');
+ assertRunnableShim(shim, 'exec bit restored after re-run');
});
diff --git a/test/hosts-init.test.ts b/test/hosts-init.test.ts
index 1d414ecb..aff65a0d 100644
--- a/test/hosts-init.test.ts
+++ b/test/hosts-init.test.ts
@@ -4,13 +4,14 @@ import assert from 'node:assert/strict';
// The MCP launch command is resolved from PATH at init time; pin it to the npx
// form so these expectations are the same on every machine.
process.env.GRAFT_MCP_NPX = '1';
-import { mkdtempSync, mkdirSync, readFileSync, readdirSync, writeFileSync, existsSync } from 'node:fs';
-import { tmpdir } from 'node:os';
-import { join } from 'node:path';
-import { execFileSync, spawnSync } from 'node:child_process';
+import { mkdirSync, readFileSync, readdirSync, writeFileSync, existsSync } from 'node:fs';
+import { join, sep } from 'node:path';
+import { execFileSync } from 'node:child_process';
import { runHostsInit } from '../src/hosts/init.js';
+import { toPosixPath } from '../src/util/paths.js';
+import { runCli, tmpRepo } from './helpers.js';
-function fresh(): string { return mkdtempSync(join(tmpdir(), 'graft-hostsinit-')); }
+function fresh(): string { return tmpRepo('hostsinit'); }
test('writes only detected hosts by default', () => {
const home = fresh(); const repo = fresh();
@@ -106,7 +107,9 @@ test('runHostsInit registers MCP configs for selected hosts', () => {
const home = fresh(); const repo = fresh();
const r = runHostsInit(repo, { home, agents: ['cursor'] });
assert.equal(r.mcp.length, 1);
- assert.match(r.mcp[0].path, /\.cursor\/mcp\.json$/);
+ // An absolute filesystem path, so it carries the platform separator — assert the
+ // shape, not the platform.
+ assert.match(toPosixPath(r.mcp[0].path), /\.cursor\/mcp\.json$/);
const cfg = JSON.parse(readFileSync(join(repo, '.cursor', 'mcp.json'), 'utf8'));
assert.equal(cfg.mcpServers.graft.command, 'npx');
});
@@ -160,17 +163,17 @@ test('global: false keeps the instruction file but skips every ~ write', () => {
// --- CLI: choosing what gets written ------------------------------------
/**
- * Run `graft init` with a scratch HOME so tests never touch the real ~/.codex,
+ * Run `graft init` with a scratch home so tests never touch the real ~/.codex,
* and return stderr. The child gets a pipe rather than a TTY, which is exactly
* the non-interactive path we want to exercise.
+ *
+ * `runCli`'s `home` sets `USERPROFILE` as well as `HOME` — this used to set only
+ * `HOME`, so on Windows the child read the *runner's* profile and reported
+ * whichever agents it happened to have installed instead of the fixture's.
*/
function cliStderr(repo: string, home: string, extra: string[] = []): string {
- const res = spawnSync(
- process.execPath,
- ['--import', 'tsx', 'src/cli.ts', 'init', repo, '--no-build', ...extra],
- { encoding: 'utf8', env: { ...process.env, HOME: home } },
- );
- assert.equal(res.status, 0, `exited ${res.status}: ${res.stderr}`);
+ const res = runCli(['init', repo, '--no-build', ...extra], { home });
+ assert.equal(res.status, 0, res.describe());
return res.stderr ?? '';
}
@@ -190,10 +193,11 @@ test('CLI: --dry-run prints the plan, both sections, and writes nothing', () =>
const out = cliStderr(repo, home, ['--dry-run']);
assert.match(out, /would write — this repo:/);
- assert.match(out, /\.claude\/settings\.json/);
+ // The plan prints display paths, which keep the platform separator.
+ assert.ok(out.includes(join('.claude', 'settings.json')), out);
assert.match(out, /AGENTS\.md/);
assert.match(out, /affects ALL repos:/);
- assert.match(out, /~\/\.codex\/hooks\.json/);
+ assert.ok(out.includes(`~${sep}${join('.codex', 'hooks.json')}`), out);
assert.match(out, /nothing was written/);
assert.deepEqual(readdirSync(repo), []);
@@ -241,7 +245,7 @@ test('CLI: --dry-run respects an explicit --agents list', () => {
const home = fresh(); const repo = fresh();
mkdirSync(join(home, '.codex'), { recursive: true });
const out = cliStderr(repo, home, ['--agents', 'adal', '--dry-run']);
- assert.match(out, /\.adal\/skills\/graft\/SKILL\.md/);
+ assert.ok(out.includes(join('.adal', 'skills', 'graft', 'SKILL.md')), out);
assert.doesNotMatch(out, /AGENTS\.md/);
assert.doesNotMatch(out, /affects ALL repos/);
});
diff --git a/test/hosts-plan.test.ts b/test/hosts-plan.test.ts
index d68aba50..2e40af2d 100644
--- a/test/hosts-plan.test.ts
+++ b/test/hosts-plan.test.ts
@@ -1,13 +1,14 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { mkdtempSync, mkdirSync, readdirSync } from 'node:fs';
-import { tmpdir } from 'node:os';
+import { mkdirSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
import { planInit, selectedWrites } from '../src/hosts/plan.js';
import { runHostsInit } from '../src/hosts/init.js';
import { hostIds } from '../src/hosts/registry.js';
+import { toPosixPath } from '../src/util/paths.js';
+import { tmpRepo } from './helpers.js';
-function fresh(): string { return mkdtempSync(join(tmpdir(), 'graft-plan-')); }
+function fresh(): string { return tmpRepo('plan'); }
/** A home with every CLI graft can detect installed. */
function fullHome(): string {
@@ -47,8 +48,9 @@ test('the three ~/.codex writes are scoped global', () => {
const agents = planInit(fresh(), { home, ids: ['agents'] })[0];
const globals = agents.writes.filter((w) => w.scope === 'global');
assert.equal(globals.length, 3);
+ // Real filesystem paths, so compared in posix form rather than the platform's.
assert.deepEqual(
- globals.map((w) => w.path.slice(home.length)).sort(),
+ globals.map((w) => toPosixPath(w.path.slice(home.length))).sort(),
['/.codex/config.toml', '/.codex/hooks.json', '/.codex/hooks/graft/graft-hooks.cjs'],
);
});
@@ -72,7 +74,7 @@ test('adal is an instruction-only host — no MCP target', () => {
const adal = planInit(fresh(), { home: fullHome(), ids: ['adal'] })[0];
assert.equal(adal.writes.length, 1);
assert.equal(adal.writes[0].kind, 'instruction');
- assert.match(adal.writes[0].path, /\.adal\/skills\/graft\/SKILL\.md$/);
+ assert.match(toPosixPath(adal.writes[0].path), /\.adal\/skills\/graft\/SKILL\.md$/);
});
// The assertion that keeps the plan honest: whatever a real run writes must be