31 lines · 1.8 KB · TypeScriptRaw
import { spawnSync } from "node:child_process";import { mkdtempSync, mkdirSync, readFileSync, realpathSync, readdirSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join, resolve } from "node:path";import { expect, it } from "vitest";/// RULE: SwiftPM dependencies survive cut worktrees and automatic cleanup; a transient GitHub outage must not make a pinned, warm build cold.it("claims the shared dependency cache owner_only and resolves locked pins without updating remotes", () => { const root = mkdtempSync(join(tmpdir(), "swiftpm-cache-")); try { const home = join(root, "home"); const bin = join(root, "bin"); mkdirSync(home); mkdirSync(bin); const calls = join(root, "calls"); writeFileSync(join(bin, "swift"), '#!/bin/bash\nprintf "%s\\n" "$@" >> "$CALLS"\n', { mode: 0o755 }); const result = spawnSync("bash", [resolve("scripts/warm-swiftpm-cache.sh")], { env: { ...process.env, HOME: home, PATH: `${bin}:${process.env.PATH}`, CALLS: calls, COTTON_CLAIMS_DIR: join(home, "claims") }, encoding: "utf8", }); expect(result.status, result.stderr).toBe(0); const args = readFileSync(calls, "utf8").split("\n"); expect(args).toContain("--cache-path"); expect(args).toContain(join(home, ".cache/cottondb/swiftpm")); expect(args).toContain("--scratch-path"); expect(args).toContain("--skip-update"); expect(args).toContain("--force-resolved-versions"); expect(args).not.toContain("-Xswiftc"); const claims = readdirSync(join(home, "claims")).map(name => JSON.parse(readFileSync(join(home, "claims", name), "utf8"))); expect(claims).toContainEqual(expect.objectContaining({ path: realpathSync(join(home, ".cache/cottondb/swiftpm")), rule: "owner_only" })); } finally { rmSync(root, { recursive: true, force: true }); }});