fix(bin): route remaining Windows-reachable mkdirSync sites through mkdirpSync

Sweep follow-up to #2641's lib/fs-utils.ts helper: bun on Windows throws EEXIST from a recursive mkdir on an existing dir, so every unguarded recursive mkdirSync on a Windows-reachable path is a latent crash. Converted: bin/gstack-decision-log (unguarded, runs on every decision log — the second call on any machine hits the pre-existing projects dir), bin/gstack-evidence logsDir + ledger dir sites, and bin/gstack-redact-prepush's skip-log site (already try-wrapped, so its failure mode was a silent skip-log loss rather than a crash — the fix makes the log survive). The ~15 remaining gbrain/mac-lane sites are deliberately left alone.

Regression: fs-utils.test.ts drives gstack-decision-log twice, the second run under the bun-Windows EEXIST preload fixture — the pre-sweep code exits 1 with EEXIST there; verified red against v1.68.3.0.
This commit is contained in:
Garry Tan
2026-08-22 01:59:16 +00:00
parent 790c42505a
commit 361dfebcbe
4 changed files with 40 additions and 6 deletions
+27
View File
@@ -61,6 +61,33 @@ describe("mkdirpSync", () => {
});
});
describe("swept mkdirp sites under bun-on-Windows EEXIST semantics (#2635)", () => {
const DECISION_LOG = path.resolve(import.meta.dir, "..", "bin", "gstack-decision-log");
test("decision-log still writes when its projects dir already exists", () => {
// Proves the sweep WIRING, not just the helper: the first call creates
// ~/.gstack/projects/<slug>/, the second hits the emulated Windows EEXIST
// on that pre-existing dir — bare mkdirSync crashed here before the sweep.
const base = tmpdir();
try {
const work = path.join(base, "work");
fs.mkdirSync(work, { recursive: true });
const payload = '{"decision":"eexist probe","rationale":"r","scope":"repo","source":"user"}';
const env = { ...process.env, HOME: base };
const first = spawnSync("bun", [DECISION_LOG, payload], { cwd: work, encoding: "utf8", env });
expect(first.status).toBe(0);
const second = spawnSync(
"bun", ["--preload", EEXIST_PRELOAD, DECISION_LOG, payload],
{ cwd: work, encoding: "utf8", env },
);
expect(second.status).toBe(0);
expect(second.stderr ?? "").not.toContain("EEXIST");
} finally {
fs.rmSync(base, { recursive: true, force: true });
}
});
});
describe("install-prepush-hook under bun-on-Windows EEXIST semantics (#2635)", () => {
test("install succeeds when .git/hooks already exists, existing hook preserved", () => {
const base = tmpdir();