import { test } from "node:test"; import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { carry } from "./integration/forge.ts"; /** * A bed's forge takes the lab's checkouts as they are: shallow (novox/hq issue 689). The lab module clones * every repository with `--depth`, and the genesis bed's forge refused the push ("shallow update not * allowed"), so the bed never reached its installer. Held here with a real git and no lab. */ const git = (cwd: string, ...args: string[]) => execFileSync("git", ["-C", cwd, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, GIT_AUTHOR_NAME: "lab", GIT_AUTHOR_EMAIL: "lab@example.org", GIT_COMMITTER_NAME: "lab", GIT_COMMITTER_EMAIL: "lab@example.org" } }).trim(); test("a shallow checkout, as the lab clones it, is carried into the bed's forge and served from it", () => { const dir = mkdtempSync(join(tmpdir(), "mesh-lab-689-")); try { const origin = join(dir, "origin"); execFileSync("git", ["init", "-q", "-b", "main", origin]); for (let i = 0; i < 5; i++) { writeFileSync(join(origin, "file"), `${i}\n`); git(origin, "add", "file"); git(origin, "commit", "-q", "-m", `commit ${i}`); } // As the lab module clones: shallow, over a transport that honours the depth. const checkout = join(dir, "checkout"); execFileSync("git", ["clone", "-q", "--depth", "2", "--branch", "main", `file://${origin}`, checkout]); assert.equal(git(checkout, "rev-parse", "--is-shallow-repository"), "true"); const bare = join(dir, "forge", "repo.git"); const head = carry(checkout, bare, ["main", "lab"]); assert.equal(head, git(origin, "rev-parse", "HEAD")); assert.equal(git(bare, "rev-parse", "refs/heads/main"), head); assert.equal(git(bare, "rev-parse", "refs/heads/lab"), head); // What the bed's machines do with it: clone over git's protocol, and find the commit under test. const served = join(dir, "served"); execFileSync("git", ["clone", "-q", "--branch", "main", `file://${bare}`, served]); assert.equal(git(served, "rev-parse", "HEAD"), head); assert.equal(git(served, "show", "HEAD:file"), "4"); } finally { rmSync(dir, { recursive: true, force: true }); } });