/** * rust-verify's scratch (its extraction and target dir) is one per Mac, not one * per worktree. sccache keys `CARGO_MANIFEST_DIR`, so a per-worktree path made * every one of Cotton's own crates a miss the first time a new worktree * verified; at one fixed path a second worktree at the same commit compiles * zero crates (measured on the signing Mac, 11 Oct 2026: 83 s and 111 misses against * 39 s and none). Off a Mac there is no machine lock, so concurrent verifies * keep a scratch per worktree. */ import { execFileSync, spawnSync } from "node:child_process"; import { copyFileSync, mkdirSync, mkdtempSync, rmSync } from "node:fs"; import { platform, tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; const ROOT = resolve(__dirname, "../.."); let scratch: string | undefined; afterEach(() => { if (scratch) rmSync(scratch, { recursive: true, force: true }); scratch = undefined; }); /** A git checkout at `dir` carrying rust-verify.sh and the one file it sources before naming its scratch. */ function checkout(dir: string): string { mkdirSync(join(dir, "scripts", "lib"), { recursive: true }); copyFileSync(join(ROOT, "scripts/rust-verify.sh"), join(dir, "scripts/rust-verify.sh")); copyFileSync(join(ROOT, "scripts/lib/owned-root.sh"), join(dir, "scripts/lib/owned-root.sh")); execFileSync("git", ["init", "-q", dir]); return join(dir, "scripts/rust-verify.sh"); } function scratchOf(script: string, verifyRoot: string): string { const run = spawnSync("bash", [script, "--print-scratch"], { encoding: "utf8", env: { PATH: process.env.PATH ?? "/usr/bin:/bin", HOME: verifyRoot, RUST_VERIFY_DIR: join(verifyRoot, "verify") }, }); expect(run.status, run.stderr).toBe(0); return run.stdout.trim(); } describe("rust-verify — one scratch per Mac", () => { // RULE: On a Mac every worktree's rust:verify builds at one scratch path, so a second worktree at the same commit compiles zero crates; off a Mac each worktree keeps its own, because nothing serialises them there. it("two worktrees name the same scratch on a Mac and different ones elsewhere", () => { scratch = mkdtempSync(join(tmpdir(), "rust-verify-scratch-")); const a = scratchOf(checkout(join(scratch, "lane-a", "worktree")), scratch); const b = scratchOf(checkout(join(scratch, "lane-b", "worktree")), scratch); expect(a.startsWith(join(scratch, "verify"))).toBe(true); if (platform() === "darwin") expect(b).toBe(a); else expect(b).not.toBe(a); }); });