Public: anyone can read this; the crew can change it.

Test: dev-cell's git fixture runs with a built environment, not the host's #17608

opened this

Merged 15h 36m ago, live in production

dev-cell-git-env → main 0 commits 2 threads · 2 unresolved

  • Merged. dev-cell-git-env was merged into main as c703fb8.

Review

Sign in to review this change.
59 files changed +165 −61
test/app-release-15497.test.ts +2 −1
@@ -7,6 +7,7 @@
77 * `/api/v1/health` reads it back as `release`. A preview is never told one.
88 */
99
10 import { gitClientEnv } from "./helpers/git-client.ts";
1011 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1112 import { mkdtemp, rm } from "node:fs/promises";
1213 import { tmpdir } from "node:os";
@@ -19,7 +20,7 @@ import { releaseOf, running } from "../src/kernel/version.ts";
1920 import { ownProbeHeaders } from "../src/kernel/probe.ts";
2021
2122 const git = (cwd: string, ...args: string[]): string => {
22 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "[email protected]", "-c", "tag.gpgSign=false", "-c", "commit.gpgSign=false", ...args], { cwd });
23 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "[email protected]", "-c", "tag.gpgSign=false", "-c", "commit.gpgSign=false", ...args], { env: gitClientEnv(), cwd });
2324 if (r.exitCode !== 0) throw new Error(`git ${args.join(" ")}: ${r.stderr.toString()}`);
2425 return r.stdout.toString().trim();
2526 };
test/both-doors-refusal.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, expect, test } from "bun:test";
23 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
34 import { join } from "node:path";
@@ -8,7 +9,7 @@ const root = mkdtempSync(join(tmpdir(), "both-doors-"));
89 afterAll(() => rmSync(root, { recursive: true, force: true }));
910
1011 const run = (cwd: string, ...args: string[]) => {
11 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd });
12 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd });
1213 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
1314 return r.stdout.toString().trim();
1415 };
test/box-pass.test.ts +2 −1
@@ -4,6 +4,7 @@
44 * whose boxes are all ticked, and an issue held for boxes gets the same pass
55 * once. A builder is still never sent to redo shipped work.
66 */
7 import { gitClientEnv } from "./helpers/git-client.ts";
78 import { seatAs } from "./helpers/seat.ts";
89 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
910 import { mkdtemp, rm } from "node:fs/promises";
@@ -261,7 +262,7 @@ describe("the reviewer's pass over the boxes", () => {
261262 ["reflog", "expire", "--expire=now", "--all"],
262263 ["gc", "--prune=now", "--quiet"],
263264 ]) {
264 const ran = Bun.spawnSync(["git", ...args], { cwd: bare });
265 const ran = Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd: bare });
265266 if (ran.exitCode !== 0) throw new Error(ran.stderr.toString());
266267 }
267268 const gone = Bun.spawnSync(["git", "cat-file", "-e", `${pull.headOid}^{commit}`], { cwd: bare });
test/comment-wrap.test.ts +2 −1
@@ -4,6 +4,7 @@
44 *
55 * @not-a-tree-scan: every file it reads is in a temp directory of its own.
66 */
7 import { gitClientEnv } from "./helpers/git-client.ts";
78 import { expect, test } from "bun:test";
89 import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
910 import { tmpdir } from "node:os";
@@ -143,7 +144,7 @@ test("a pull is read, and fixed, only in the files it changes", () => {
143144 const root = mkdtempSync(join(tmpdir(), "forge-wrap-git-"));
144145 const saved = process.env.FORGE_CHECK_BASE;
145146 const sh = (...a: string[]) => {
146 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...a], { cwd: root });
147 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...a], { env: gitClientEnv(), cwd: root });
147148 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
148149 return r.stdout.toString().trim();
149150 };
test/contract-audit-cache.test.ts +2 −1
@@ -2,6 +2,7 @@
22 * `audit` keeps a repository's policy by (repository, tip): a warm read is
33 * fast, and a push that changes forge.json is seen on the next read.
44 */
5 import { gitClientEnv } from "./helpers/git-client.ts";
56 import { afterAll, beforeAll, expect, test } from "bun:test";
67 import { existsSync, mkdtempSync, rmSync } from "node:fs";
78 import { tmpdir } from "node:os";
@@ -84,7 +85,7 @@ test("a packed ref takes the git path, agrees with git, and a push still invalid
8485 const repo = () => getRepo(app.db, "alice", "packed")!;
8586 const dir = repoDir(app.reposRoot, "alice", "packed");
8687 const git = (...args: string[]) =>
87 Bun.spawnSync(["git", "-C", dir, ...args]).stdout.toString().trim();
88 Bun.spawnSync(["git", "-C", dir, ...args], { env: gitClientEnv() }).stdout.toString().trim();
8889
8990 await write(contract("anon"));
9091 git("pack-refs", "--all");
test/crew-interrupted.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
23 import type { Database } from "bun:sqlite";
34 import { listActive, type RunKind } from "../src/core/runs.ts";
@@ -566,7 +567,7 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Done.","to
566567 const { repo, clone } = await keptClone("paddock");
567568 writeFileSync(join(clone, "LOST.md"), "unpushed\n");
568569 const git = (...args: string[]) =>
569 Bun.spawnSync(["git", ...args], { cwd: clone });
570 Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd: clone });
570571 git("add", "LOST.md");
571572 git("-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "local");
572573 writeFileSync(join(clone, ".git", "index.lock"), "");
test/deepsec-step.test.ts +2 −1
@@ -4,6 +4,7 @@
44 * links its scope out of the checkout, an outside contributor's pull, or a host with no cell gets
55 * no run.
66 */
7 import { gitClientEnv } from "./helpers/git-client.ts";
78 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
89 import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
910 import { tmpdir } from "node:os";
@@ -21,7 +22,7 @@ let bare = "";
2122 let base = "";
2223 let head = "";
2324 const git = (cwd: string, ...args: string[]): string => {
24 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd, stdout: "pipe", stderr: "pipe" });
25 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd, stdout: "pipe", stderr: "pipe" });
2526 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
2627 return r.stdout.toString().trim();
2728 };
test/dev-cell.test.ts +4 −1
@@ -17,11 +17,14 @@ import { serve, type Servers } from "../src/http/server.ts";
1717 import { err, ok } from "../src/kernel/result.ts";
1818 import { pollUntil } from "./helpers/poll.ts";
1919 import { quietLogs } from "./helpers/globals.ts";
20 import { gitClientEnv } from "./helpers/git-client.ts";
2021
2122 quietLogs();
2223
24 // A built environment, never the host's: a machine's own git configuration (fetch.prune on a

This says "A built environment, never the host's", but runLocal merges process.env underneath opts.env (src/git/local.ts:29-41). Env-supplied git config (GIT_CONFIG_COUNT/KEY_n/VALUE_n) still gets through. Pass gitClientEnv({ GIT_CONFIG_COUNT: "0" }) so the comment is true, or reword it to say only the config files are overridden.

25 // Mac) made the fixture's fetch fail there.
2326 const git = async (cwd: string, ...args: string[]): Promise<void> => {
24 const made = await runLocal(["-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd });
27 const made = await runLocal(["-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd, env: gitClientEnv() });

Build this once at module level (const env = gitClientEnv({ GIT_CONFIG_COUNT: "0" })) instead of on every call.

2528 if (!made.ok) throw new Error(`git ${args.join(" ")}: ${made.error.stderr}`);
2629 };
2730
test/direction-refusal.test.ts +3 −2
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, expect, test } from "bun:test";
23 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
34 import { join } from "node:path";
@@ -8,7 +9,7 @@ const root = mkdtempSync(join(tmpdir(), "direction-"));
89 afterAll(() => rmSync(root, { recursive: true, force: true }));
910
1011 const run = (cwd: string, ...args: string[]) => {
11 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd });
12 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd });
1213 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
1314 return r.stdout.toString().trim();
1415 };
@@ -128,7 +129,7 @@ test("a failing git diff --numstat refuses the pull rather than skipping the red
128129 run(dir, "commit", "-qm", "Add home");
129130 const git = (args: string[], cwd: string = dir) => {
130131 if (args.includes("--numstat")) return { ok: false, out: "" };
131 const r = Bun.spawnSync(["git", ...args], { cwd });
132 const r = Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd });
132133 return { ok: r.exitCode === 0, out: r.stdout.toString().trim() };
133134 };
134135 const out = await withBase(base, () => directionRefusal(dir, git));
test/dupes.test.ts +2 −1
@@ -1,5 +1,6 @@
11 /** The duplication report (#14620): shapes, clusters, the tuned threshold, and the gate's note. */
22
3 import { gitClientEnv } from "./helpers/git-client.ts";
34 import { afterAll, beforeAll, expect, test } from "bun:test";
45 import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
56 import { tmpdir } from "node:os";
@@ -83,7 +84,7 @@ test("the threshold is the one that best splits the forge's own labeled pairs",
8384
8485 let dir: string;
8586 const git = (...args: string[]) => {
86 const r = Bun.spawnSync(["git", ...args], { cwd: dir, stderr: "pipe" });
87 const r = Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd: dir, stderr: "pipe" });
8788 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
8889 return r.stdout.toString().trim();
8990 };
test/error-fixes.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
23 import { mkdtemp, rm } from "node:fs/promises";
34 import { tmpdir } from "node:os";
@@ -47,7 +48,7 @@ describe("errors resolve when the pull that fixes them is deployed (#16974)", ()
4748 return app.db.query<{ id: string }, [string]>("SELECT id FROM error_group WHERE fingerprint = ?1").get(`fp-${type}`)!.id;
4849 };
4950 const commit = async (parent: string | undefined, msg: string): Promise<string> => {
50 const tree = (await runLocal(["hash-object", "-t", "tree", "-w", "--stdin"], { cwd: dir, stdin: "" }));
51 const tree = (await runLocal(["hash-object", "-t", "tree", "-w", "--stdin"], { env: gitClientEnv(), cwd: dir, stdin: "" }));
5152 const args = ["commit-tree", tree.ok ? tree.value.trim() : "", "-m", msg, ...(parent ? ["-p", parent] : [])];
5253 const made = await runLocal(args, { cwd: dir, env: { GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "[email protected]", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "[email protected]" } });
5354 if (!made.ok) throw new Error("commit-tree failed");
test/flow-red-batches.test.ts +2 −1
@@ -4,6 +4,7 @@
44 * batch's bisection is one batch, and a pull check none, is checked through
55 * the real queue with a stand-in gate that goes red on any `red-*` file.
66 */
7 import { gitClientEnv } from "./helpers/git-client.ts";
78 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
89 import { mkdtemp, rm } from "node:fs/promises";
910 import { tmpdir } from "node:os";
@@ -31,7 +32,7 @@ describe("the red-batch rate", () => {
3132 let gates = 0;
3233
3334 const git = (repo: Repo, ...args: string[]) =>
34 Bun.spawnSync(["git", ...args], { cwd: repoDir(app.reposRoot, repo.ownerName, repo.name) })
35 Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd: repoDir(app.reposRoot, repo.ownerName, repo.name) })
3536 .stdout.toString()
3637 .trim();
3738
test/forge-box-unit.test.ts +2 −1
@@ -1,4 +1,5 @@
11 /** The box's systemd unit (`infra/forge-box/forge.service`) says what docs/EXTRACT.md step 3 says. */
2 import { gitClientEnv } from "./helpers/git-client.ts";
23 import { expect, test } from "bun:test";
34 import { mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
45 import { tmpdir } from "node:os";
@@ -109,7 +110,7 @@ test("the unit's ports are defaults that forge.env may override, and the install
109110 });
110111
111112 function git(cwd: string, ...args: string[]) {
112 const r = Bun.spawnSync(["git", ...args], { cwd, stderr: "pipe", stdout: "pipe" });
113 const r = Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd, stderr: "pipe", stdout: "pipe" });
113114 return { code: r.exitCode, out: r.stdout.toString().trim(), err: r.stderr.toString() };
114115 }
115116
test/fork-detach.test.ts +2 −1
@@ -4,6 +4,7 @@
44 * and a repository admin detaches a fork from its parent — planned first,
55 * repacked off the request path, then the parent forgotten.
66 */
7 import { gitClientEnv } from "./helpers/git-client.ts";
78 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
89 import { mkdtemp, rm } from "node:fs/promises";
910 import { tmpdir } from "node:os";
@@ -36,7 +37,7 @@ const ok = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T =>
3637 };
3738
3839 const git = async (cwd: string, ...args: string[]) => {
39 const p = Bun.spawn(["git", ...args], { cwd, stdout: "pipe", stderr: "pipe" });
40 const p = Bun.spawn(["git", ...args], { env: gitClientEnv(), cwd, stdout: "pipe", stderr: "pipe" });
4041 const [out, code] = await Promise.all([new Response(p.stdout).text(), p.exited]);
4142 return { out: out.trim(), code };
4243 };
test/gate-added-refusal.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterEach, expect, test } from "bun:test";
23 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
34 import { tmpdir } from "node:os";
@@ -14,7 +15,7 @@ afterEach(() => {
1415 });
1516
1617 function sh(cwd: string, ...args: string[]): string {
17 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...args], { cwd });
18 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...args], { env: gitClientEnv(), cwd });
1819 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
1920 return r.stdout.toString().trim();
2021 }
test/gate-base-list.test.ts +2 −1
@@ -3,6 +3,7 @@
33 * is refused with the file named, even when it also deletes the refusal from its own gate, since
44 * the forge runs the base's copy (`src/checks/base_gate.ts`). A pull that only adds a file passes.
55 */
6 import { gitClientEnv } from "./helpers/git-client.ts";
67 import { afterEach, expect, test } from "bun:test";
78 import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
89 import { tmpdir } from "node:os";
@@ -18,7 +19,7 @@ afterEach(() => {
1819 });
1920
2021 function sh(cwd: string, ...args: string[]): string {
21 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...args], { cwd });
22 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...args], { env: gitClientEnv(), cwd });
2223 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
2324 return r.stdout.toString().trim();
2425 }
test/gate-dependencies.test.ts +2 −1
@@ -2,6 +2,7 @@
22 * The gate refuses a pull that adds a package with no line of why (#12315):
33 * judged against FORGE_CHECK_BASE in a real repository, devDependencies too.
44 */
5 import { gitClientEnv } from "./helpers/git-client.ts";
56 import { afterEach, expect, test } from "bun:test";
67 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
78 import { tmpdir } from "node:os";
@@ -18,7 +19,7 @@ afterEach(() => {
1819 });
1920
2021 function sh(cwd: string, ...args: string[]): string {
21 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...args], { cwd });
22 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...args], { env: gitClientEnv(), cwd });
2223 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
2324 return r.stdout.toString().trim();
2425 }
test/gate-explain.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, expect, test } from "bun:test";
23 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
34 import { join } from "node:path";
@@ -9,7 +10,7 @@ const root = mkdtempSync(join(tmpdir(), "gate-explain-"));
910 afterAll(() => rmSync(root, { recursive: true, force: true }));
1011
1112 const git = (cwd: string, ...args: string[]) => {
12 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd });
13 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd });
1314 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
1415 return r.stdout.toString().trim();
1516 };
test/gate-last-slot.test.ts +2 −1
@@ -6,6 +6,7 @@
66 * once as it starts, and the tests wait on a run's state or a gate's own
77 * promise, never on a fixed delay.
88 */
9 import { gitClientEnv } from "./helpers/git-client.ts";
910 import { afterAll, beforeAll, expect, test } from "bun:test";
1011 import { mkdtemp, rm } from "node:fs/promises";
1112 import { tmpdir } from "node:os";
@@ -128,7 +129,7 @@ test("a pull's check does not take the last slot while a gate is forming", async
128129 test("a gate that is running keeps the slot: the pull's check starts when it settles", async () => {
129130 const dir = await mkdtemp(join(tmpdir(), "forge-gate-last-slot-git-"));
130131 const git = (...args: string[]) =>
131 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim();
132 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv() }).stdout.toString().trim();
132133 Bun.spawnSync(["git", "init", "-q", "-b", "main", dir]);
133134 git("commit", "-q", "--allow-empty", "-m", "start");
134135 git("checkout", "-q", "-b", "feature");
test/gate-look-note.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterEach, expect, test } from "bun:test";
23 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
34 import { tmpdir } from "node:os";
@@ -14,7 +15,7 @@ afterEach(() => {
1415 });
1516
1617 function sh(cwd: string, ...args: string[]): string {
17 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...args], { cwd });
18 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...args], { env: gitClientEnv(), cwd });
1819 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
1920 return r.stdout.toString().trim();
2021 }
test/gate-readme-cap.test.ts +2 −1
@@ -1,4 +1,5 @@
11 /** The gate refuses a pull that adds a section to, or grows, README.md (#12392). */
2 import { gitClientEnv } from "./helpers/git-client.ts";
23 import { afterEach, expect, test } from "bun:test";
34 import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
45 import { tmpdir } from "node:os";
@@ -39,7 +40,7 @@ test("the gate judges README.md against the pull's base in a real repository", a
3940 const dir = mkdtempSync(join(tmpdir(), "forge-readme-"));
4041 dirs.push(dir);
4142 const sh = (...a: string[]) => {
42 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...a], { cwd: dir });
43 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...a], { env: gitClientEnv(), cwd: dir });
4344 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
4445 return r.stdout.toString().trim();
4546 };
test/gate-update-pull.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, expect, test } from "bun:test";
23 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
34 import { join } from "node:path";
@@ -8,7 +9,7 @@ const root = mkdtempSync(join(tmpdir(), "gate-update-"));
89 afterAll(() => rmSync(root, { recursive: true, force: true }));
910
1011 const git = (cwd: string, ...args: string[]) => {
11 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd });
12 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd });
1213 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
1314 return r.stdout.toString().trim();
1415 };
test/git-spawn-failure.test.ts +2 −1
@@ -1,4 +1,5 @@
11 /** A git that cannot start is an error on one request, never the end of the forge (#12138). */
2 import { gitClientEnv } from "./helpers/git-client.ts";
23 import { afterAll, beforeAll, expect, test } from "bun:test";
34 import { mkdtemp, rm } from "node:fs/promises";
45 import { tmpdir } from "node:os";
@@ -24,7 +25,7 @@ test("a spawn that throws is an Err on every helper, not a rejection", async ()
2425 expect(cap.code).not.toBe(0);
2526 expect(cap.stderr).toBe("This repository is unavailable.");
2627 expect(cap.stderr).not.toContain(gone);
27 const local = await runLocal(["status"], { cwd: gone });
28 const local = await runLocal(["status"], { env: gitClientEnv(), cwd: gone });
2829 expect(local.ok).toBe(false);
2930 });
3031
test/guest-contribute.test.ts +2 −1
@@ -5,6 +5,7 @@
55 * sign-up to a person landing the change.
66 */
77
8 import { gitClientEnv } from "./helpers/git-client.ts";
89 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
910 import { mkdtemp, rm } from "node:fs/promises";
1011 import { tmpdir } from "node:os";
@@ -549,7 +550,7 @@ describe("a guest helps build a public repository", () => {
549550 const auth = `http.extraHeader=Authorization: Basic ${Buffer.from(`${user.username}:${token}`).toString("base64")}`;
550551 // The forge answers in this process, so git runs beside it, never blocking it.
551552 const run = (cwd: string, ...a: string[]) =>
552 Bun.spawn(["git", "-c", auth, "-c", "user.name=a", "-c", "user.email=a@a", ...a], { cwd, stdout: "ignore", stderr: "ignore" }).exited;
553 Bun.spawn(["git", "-c", auth, "-c", "user.name=a", "-c", "user.email=a@a", ...a], { env: gitClientEnv(), cwd, stdout: "ignore", stderr: "ignore" }).exited;
553554 expect(await run(work, "clone", `${servers.url}/${mine}.git`, "w")).toBe(0);
554555 const tree = join(work, "w");
555556 await Bun.write(join(tree, "GIT.md"), "pushed\n");
test/helpers/build-standin-builder.ts +2 −1
@@ -3,6 +3,7 @@
33 * given: edit, run the app's own tests, and only then commit and push.
44 * Argument: the file holding the prompt.
55 */
6 import { gitClientEnv } from "./git-client.ts";
67 import { readFileSync, writeFileSync } from "node:fs";
78 import { ANCHOR, READING_V1, READING_V2, routeFor, testFor } from "./build-standin.ts";
89
@@ -13,7 +14,7 @@ const finish = (ok: boolean, result: string): void =>
1314 JSON.stringify({ type: "result", subtype: ok ? "success" : "error_during_execution", is_error: !ok, result, total_cost_usd: 0.01, num_turns: 1, session_id: "build-1", terminal_reason: ok ? "completed" : "tool_error" }),
1415 );
1516 const git = (...args: string[]): void => {
16 const r = Bun.spawnSync(["git", ...args], { stdout: "pipe", stderr: "pipe" });
17 const r = Bun.spawnSync(["git", ...args], { env: gitClientEnv(), stdout: "pipe", stderr: "pipe" });
1718 if (r.exitCode !== 0) throw new Error(`${args.join(" ")}: ${r.stderr.toString()}`);
1819 };
1920
test/helpers/stranger-builder.ts +2 −1
@@ -7,6 +7,7 @@
77 * that already has the route (a reviewer's clone, a second run), changes
88 * nothing and says so. Argument: none; the prompt is read from stdin.
99 */
10 import { gitClientEnv } from "./git-client.ts";
1011 import { readFileSync, writeFileSync } from "node:fs";
1112 import { ANCHOR } from "./build-standin.ts";
1213
@@ -51,7 +52,7 @@ const finish = (ok: boolean, result: string): void =>
5152 }),
5253 );
5354 const git = (...args: string[]): void => {
54 const r = Bun.spawnSync(["git", ...args], { stdout: "pipe", stderr: "pipe" });
55 const r = Bun.spawnSync(["git", ...args], { env: gitClientEnv(), stdout: "pipe", stderr: "pipe" });
5556 if (r.exitCode !== 0) throw new Error(`${args.join(" ")}: ${r.stderr.toString()}`);
5657 };
5758
test/lands-once.test.ts +2 −1
@@ -6,6 +6,7 @@
66 * tree is the base's own commits nothing: the pull closes as merged into
77 * the commit that already carried it.
88 */
9 import { gitClientEnv } from "./helpers/git-client.ts";
910 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1011 import { mkdtemp, rm } from "node:fs/promises";
1112 import { tmpdir } from "node:os";
@@ -29,7 +30,7 @@ describe("a pull lands once", () => {
2930 let repo: Repo;
3031 const fresh = () => getRepoById(app.db, repo.id)!;
3132 const git = (...args: string[]) =>
32 Bun.spawnSync(["git", ...args], {
33 Bun.spawnSync(["git", ...args], { env: gitClientEnv(),
3334 cwd: repoDir(app.reposRoot, repo.ownerName, repo.name),
3435 })
3536 .stdout.toString()
test/log-tail-view.test.ts +2 −1
@@ -1,4 +1,5 @@
11 /** A .log or .txt over 5 MB opens its last 1,000 lines, and says what it left out (#13603). */
2 import { gitClientEnv } from "./helpers/git-client.ts";
23 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
34 import { mkdtemp, rm } from "node:fs/promises";
45 import { tmpdir } from "node:os";
@@ -17,7 +18,7 @@ let dir = "";
1718 beforeAll(async () => {
1819 dir = await mkdtemp(join(tmpdir(), "forge-tail-"));
1920 const git = (args: string[], stdin?: Uint8Array): string => {
20 const r = Bun.spawnSync(["git", ...args], { cwd: dir, stdin: stdin ?? "ignore" });
21 const r = Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd: dir, stdin: stdin ?? "ignore" });
2122 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
2223 return r.stdout.toString().trim();
2324 };
test/merge-queue-batch.test.ts +2 −1
@@ -7,6 +7,7 @@
77 * time, so "at once" is counted, never timed; it reads the candidate's tree:
88 * red when it holds `bad.txt`.
99 */
10 import { gitClientEnv } from "./helpers/git-client.ts";
1011 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1112 import { mkdtemp, rm } from "node:fs/promises";
1213 import { tmpdir } from "node:os";
@@ -22,7 +23,7 @@ describe("the merge queue's batch size", () => {
2223 let landings = 0;
2324
2425 const git = (...args: string[]) =>
25 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim();
26 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv() }).stdout.toString().trim();
2627
2728 beforeAll(async () => {
2829 dir = await mkdtemp(join(tmpdir(), "forge-merge-queue-batch-"));
test/merge-queue-check-retry.test.ts +2 −1
@@ -5,6 +5,7 @@
55 * the batch lands whole with nothing bisected; red again, it is searched,
66 * and the search's own prefixes are not gated twice.
77 */
8 import { gitClientEnv } from "./helpers/git-client.ts";
89 import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "bun:test";
910 import { mkdtemp, rm } from "node:fs/promises";
1011 import { tmpdir } from "node:os";
@@ -22,7 +23,7 @@ describe("the merge queue gates a red (check) once more before it searches", ()
2223 let floor: LogLevel;
2324
2425 const git = (...args: string[]) =>
25 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim();
26 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv() }).stdout.toString().trim();
2627
2728 beforeAll(async () => {
2829 dir = await mkdtemp(join(tmpdir(), "forge-merge-queue-check-retry-"));
test/merge-queue-clash.test.ts +2 −1
@@ -7,6 +7,7 @@
77 * pulls again; a push forgets it. The gate here reads the candidate's
88 * tree: red when it holds both `a.txt` and `b.txt`.
99 */
10 import { gitClientEnv } from "./helpers/git-client.ts";
1011 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1112 import { mkdtemp, rm } from "node:fs/promises";
1213 import { tmpdir } from "node:os";
@@ -23,7 +24,7 @@ describe("the merge queue remembers clashes", () => {
2324 const told: { pull: number; together: number[] }[] = [];
2425
2526 const git = (...args: string[]) =>
26 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim();
27 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv() }).stdout.toString().trim();
2728
2829 beforeAll(async () => {
2930 dir = await mkdtemp(join(tmpdir(), "forge-merge-queue-clash-"));
test/merge-queue-gate-result.test.ts +2 −1
@@ -6,6 +6,7 @@
66 * and `GET …/queue/gates` and the `queue_gates` MCP tool answer them. A test
77 * red in two gates that share no pull is flagged flaky.
88 */
9 import { gitClientEnv } from "./helpers/git-client.ts";
910 import { afterAll, beforeAll, describe, expect, spyOn, test } from "bun:test";
1011 import { mkdtemp, rm } from "node:fs/promises";
1112 import { tmpdir } from "node:os";
@@ -127,7 +128,7 @@ describe("the merge queue keeps and names each gate's failing tests", () => {
127128 const spies: { mockRestore(): void }[] = [];
128129
129130 const git = (repo: Repo, ...args: string[]) =>
130 Bun.spawnSync(["git", ...args], { cwd: repoDir(app.reposRoot, repo.ownerName, repo.name) })
131 Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd: repoDir(app.reposRoot, repo.ownerName, repo.name) })
131132 .stdout.toString()
132133 .trim();
133134
test/merge-queue-parallel.test.ts +3 −2
@@ -7,6 +7,7 @@
77 * gate the wave should hold has started, so "at once" is counted, never
88 * timed. It goes red on any tree holding a `red-*` file.
99 */
10 import { gitClientEnv } from "./helpers/git-client.ts";
1011 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1112 import { mkdtemp, rm } from "node:fs/promises";
1213 import { tmpdir } from "node:os";
@@ -45,7 +46,7 @@ describe("the merge queue in parallel", () => {
4546 let wave = 0;
4647
4748 const git = (repo: Repo, ...args: string[]) =>
48 Bun.spawnSync(["git", ...args], { cwd: repoDir(app.reposRoot, repo.ownerName, repo.name) })
49 Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd: repoDir(app.reposRoot, repo.ownerName, repo.name) })
4950 .stdout.toString()
5051 .trim();
5152
@@ -235,7 +236,7 @@ describe("the queue's extra gates and the pull checks' slots", () => {
235236 let app: App;
236237 let checks: ChecksHandle | undefined;
237238 const git = (...args: string[]) =>
238 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim();
239 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv() }).stdout.toString().trim();
239240
240241 beforeAll(async () => {
241242 dataDir = await mkdtemp(join(tmpdir(), "forge-merge-queue-slots-"));
test/merge-queue-reason.test.ts +2 −1
@@ -5,6 +5,7 @@
55 * bisected. A pull that conflicts with an earlier one of its batch is left
66 * out, named with it, and the rest land in that one gate.
77 */
8 import { gitClientEnv } from "./helpers/git-client.ts";
89 import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "bun:test";
910 import { mkdtemp, rm } from "node:fs/promises";
1011 import { tmpdir } from "node:os";
@@ -54,7 +55,7 @@ describe("the merge queue acts on why a gate went red", () => {
5455 const spies: { mockRestore(): void }[] = [];
5556
5657 const git = (...args: string[]) =>
57 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim();
58 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv() }).stdout.toString().trim();
5859
5960 beforeAll(async () => {
6061 dir = await mkdtemp(join(tmpdir(), "forge-merge-queue-reason-"));
test/merge-queue-restart.test.ts +2 −1
@@ -6,6 +6,7 @@
66 * gated again on the same base — and never plans the line from nothing.
77 * The lane here is a stand-in the test holds open and lets go of.
88 */
9 import { gitClientEnv } from "./helpers/git-client.ts";
910 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1011 import { mkdtemp, rm } from "node:fs/promises";
1112 import { tmpdir } from "node:os";
@@ -39,7 +40,7 @@ describe("the merge queue across a restart", () => {
3940 let lost = false;
4041
4142 const git = (repo: Repo, ...args: string[]) =>
42 Bun.spawnSync(["git", ...args], { cwd: repoDir(app.reposRoot, repo.ownerName, repo.name) })
43 Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd: repoDir(app.reposRoot, repo.ownerName, repo.name) })
4344 .stdout.toString()
4445 .trim();
4546
test/merge-queue-revert-alone.test.ts +2 −1
@@ -2,6 +2,7 @@
22 * A lane revert (`checks/revert_lane.ts`, `Queued.alone`) gates alone and first in the merge
33 * queue's line: it joins no batch, and the line's other pulls batch as before behind it.
44 */
5 import { gitClientEnv } from "./helpers/git-client.ts";
56 import { afterAll, beforeAll, expect, test } from "bun:test";
67 import { mkdtemp, rm } from "node:fs/promises";
78 import { tmpdir } from "node:os";
@@ -11,7 +12,7 @@ import type { LandVerdict } from "../src/checks/tiers.ts";
1112 import type { Pull } from "../src/core/pulls.ts";
1213
1314 let dir: string;
14 const git = (...args: string[]) => Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim();
15 const git = (...args: string[]) => Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv() }).stdout.toString().trim();
1516
1617 beforeAll(async () => {
1718 dir = await mkdtemp(join(tmpdir(), "forge-merge-queue-alone-"));
test/merge-queue-search.test.ts +2 −1
@@ -5,6 +5,7 @@
55 * gate here is held open and let go a wave at a time, so "at once" is counted,
66 * never timed; it reads the candidate's tree: red when it holds `bad.txt`.
77 */
8 import { gitClientEnv } from "./helpers/git-client.ts";
89 import { afterEach, beforeEach, describe, expect, test } from "bun:test";
910 import { mkdtemp, rm } from "node:fs/promises";
1011 import { tmpdir } from "node:os";
@@ -24,7 +25,7 @@ describe("the merge queue searches a red candidate by stacked prefixes", () => {
2425 const last = args[args.length - 1];
2526 const input = typeof last === "object" ? last.input : undefined;
2627 const words = args.filter((a): a is string => typeof a === "string");
27 return Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...words], { stdin: input === undefined ? undefined : Buffer.from(input) })
28 return Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...words], { env: gitClientEnv(), stdin: input === undefined ? undefined : Buffer.from(input) })
2829 .stdout.toString()
2930 .trim();
3031 };
test/merge-queue-suspect.test.ts +3 −2
@@ -5,6 +5,7 @@
55 * batches waits for a verdict of its own and never heads a third. The gate
66 * here reads the candidate's tree: red when it holds `bad.txt`.
77 */
8 import { gitClientEnv } from "./helpers/git-client.ts";
89 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
910 import { mkdtemp, rm } from "node:fs/promises";
1011 import { tmpdir } from "node:os";
@@ -20,7 +21,7 @@ describe("the merge queue judges a suspect alone", () => {
2021 const told: { pull: number; together: number[] }[] = [];
2122
2223 const git = (...args: string[]) =>
23 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim();
24 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv() }).stdout.toString().trim();
2425
2526 beforeAll(async () => {
2627 dir = await mkdtemp(join(tmpdir(), "forge-merge-queue-suspect-"));
@@ -36,7 +37,7 @@ describe("the merge queue judges a suspect alone", () => {
3637 function headAdding(file: string): string {
3738 // Plumbing only (three spawns, no checkout): main's tree plus one blob.
3839 const run = (input: string, ...args: string[]) =>
39 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { stdin: Buffer.from(input) })
40 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), stdin: Buffer.from(input) })
4041 .stdout.toString().trim();
4142 const blob = run(`${file}\n`, "hash-object", "-w", "--stdin");
4243 // The replace drops the leading newline when main's tree is empty.
test/merge-queue.test.ts +2 −1
@@ -5,6 +5,7 @@
55 * green part and hands the culprit back. The gate here is a stand-in that
66 * counts its runs and goes red on any tree holding a `red-*` file.
77 */
8 import { gitClientEnv } from "./helpers/git-client.ts";
89 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
910 import { mkdtemp, rm } from "node:fs/promises";
1011 import { tmpdir } from "node:os";
@@ -61,7 +62,7 @@ describe("the merge queue", () => {
6162 let atGate: (() => void) | undefined;
6263
6364 const git = (repo: Repo, ...args: string[]) =>
64 Bun.spawnSync(["git", ...args], {
65 Bun.spawnSync(["git", ...args], { env: gitClientEnv(),
6566 cwd: repoDir(app.reposRoot, repo.ownerName, repo.name),
6667 })
6768 .stdout.toString()
test/orphan-clones.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { describe, expect, test } from "bun:test";
23 import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
34 import { tmpdir } from "node:os";
@@ -63,7 +64,7 @@ describe("trimming idle clones' installed packages (#13514)", () => {
6364
6465 describe("removing clones idle for a day (#13734, #14007)", () => {
6566 const git = (cwd: string, ...args: string[]): void => {
66 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd });
67 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd });
6768 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
6869 };
6970 const age = async (dir: string, days: number, also: string[] = []): Promise<void> => {
test/path-listing.test.ts +2 −1
@@ -1,4 +1,5 @@
11 /** Path listings kept by tree id: a second ask reuses the first, a moved branch never reads stale. */
2 import { gitClientEnv } from "./helpers/git-client.ts";
23 import { afterAll, beforeAll, expect, test } from "bun:test";
34 import { mkdtemp, rm, writeFile } from "node:fs/promises";
45 import { tmpdir } from "node:os";
@@ -8,7 +9,7 @@ import { closeReader } from "../src/git/read.ts";
89
910 let dir: string;
1011 const git = (...args: string[]) => {
11 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], { cwd: dir });
12 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], { env: gitClientEnv(), cwd: dir });
1213 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
1314 };
1415 const commit = async (file: string) => {
test/pin-refusal.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, expect, test } from "bun:test";
23 import { TOOK_LINE } from "../src/checks/took_line.ts";
34 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
@@ -12,7 +13,7 @@ afterAll(() => rmSync(root, { recursive: true, force: true }));
1213
1314 const gateScript = join(import.meta.dir, "../scripts/gate.ts");
1415 const run = (cwd: string, ...args: string[]) => {
15 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd });
16 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd });
1617 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
1718 return r.stdout.toString().trim();
1819 };
test/queue-verdicts.test.ts +2 −1
@@ -3,6 +3,7 @@
33 * back with its failing tests, or calls the red the machine's, and says so
44 * in the keeper, the flow reading and the boards' sources.
55 */
6 import { gitClientEnv } from "./helpers/git-client.ts";
67 import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "bun:test";
78 import { mkdtemp, rm } from "node:fs/promises";
89 import { tmpdir } from "node:os";
@@ -23,7 +24,7 @@ describe("the merge queue says what a red batch was", () => {
2324 const kept: QueueVerdict[] = [];
2425 const spies: { mockRestore(): void }[] = [];
2526 const git = (...args: string[]) =>
26 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args]).stdout.toString().trim();
27 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv() }).stdout.toString().trim();
2728
2829 beforeAll(async () => {
2930 dir = await mkdtemp(join(tmpdir(), "forge-queue-verdicts-"));
test/red-on-main.test.ts +2 −1
@@ -6,6 +6,7 @@
66 *
77 * @not-a-tree-scan: the scans it writes list only their own scratch repository's src.
88 */
9 import { gitClientEnv } from "./helpers/git-client.ts";
910 import { describe, expect, test } from "bun:test";
1011 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
1112 import { tmpdir } from "node:os";
@@ -240,7 +241,7 @@ describe("the fast tier asks main", () => {
240241 const pass = `import { test } from "bun:test";\ntest("ok", () => {});\n`;
241242 const fail = `import { expect, test } from "bun:test";\ntest("red", () => { expect(1).toBe(2); });\n`;
242243 const git = (dir: string, ...args: string[]): number =>
243 Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], {
244 Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], { env: gitClientEnv(),
244245 cwd: dir,
245246 stdout: "ignore",
246247 stderr: "ignore",
test/release-subject.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, beforeAll, expect, test } from "bun:test";
23 import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
34 import { tmpdir } from "node:os";
@@ -9,7 +10,7 @@ let release: string;
910 let plain: string;
1011
1112 function git(...args: string[]): string {
12 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd: dir });
13 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd: dir });
1314 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
1415 return r.stdout.toString().trim();
1516 }
test/repo-delete-forks.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
23 import { chmod, mkdtemp, rm } from "node:fs/promises";
34 import { existsSync } from "node:fs";
@@ -17,7 +18,7 @@ import type { Repo } from "../src/core/repos.ts";
1718 */
1819
1920 const git = async (cwd: string, ...args: string[]) => {
20 const p = Bun.spawn(["git", ...args], { cwd, stdout: "pipe", stderr: "pipe" });
21 const p = Bun.spawn(["git", ...args], { env: gitClientEnv(), cwd, stdout: "pipe", stderr: "pipe" });
2122 const [out, code] = await Promise.all([new Response(p.stdout).text(), p.exited]);
2223 return { out: out.trim(), code };
2324 };
test/revert-gate.test.ts +2 −1
@@ -4,6 +4,7 @@
44 * pull row reverts a merged pull and its change is exactly that landing's inverse) and those two
55 * rules stand down. A pull that is not that revert is still held to both.
66 */
7 import { gitClientEnv } from "./helpers/git-client.ts";
78 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
89 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
910 import { tmpdir } from "node:os";
@@ -97,7 +98,7 @@ describe("the gate stands down two rules for a marked revert", () => {
9798 const root = mkdtempSync(join(tmpdir(), "revert-gate-"));
9899 afterAll(() => rmSync(root, { recursive: true, force: true }));
99100 const run = (cwd: string, ...args: string[]) => {
100 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd });
101 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd });
101102 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
102103 return r.stdout.toString().trim();
103104 };
test/scripts-fast.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { expect, test } from "bun:test";
23 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
34 import { tmpdir } from "node:os";
@@ -63,7 +64,7 @@ function repo(): string {
6364 const git = (...args: string[]): void => {
6465 const run = Bun.spawnSync(
6566 ["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args],
66 { cwd: dir },
67 { env: gitClientEnv(), cwd: dir },
6768 );
6869 if (run.exitCode !== 0) throw new Error(run.stderr.toString());
6970 };
test/search-grep-stops.test.ts +2 −1
@@ -1,6 +1,7 @@
11 // #10395: `git grep --max-count` is per file, so a one-letter query in a
22 // repository of many files wrote megabytes that the forge read whole on its
33 // event loop. The read now stops git once the hits it keeps are in.
4 import { gitClientEnv } from "./helpers/git-client.ts";
45 import { afterAll, beforeAll, expect, test } from "bun:test";
56 import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
67 import { tmpdir } from "node:os";
@@ -17,7 +18,7 @@ beforeAll(() => {
1718 const line = "a line that matches a\n";
1819 for (let i = 0; i < FILES; i++) writeFileSync(join(dir, `f${i}.txt`), line.repeat(LINES));
1920 const git = (...args: string[]) => {
20 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "[email protected]", ...args], { cwd: dir });
21 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "[email protected]", ...args], { env: gitClientEnv(), cwd: dir });
2122 if (r.exitCode !== 0) throw new Error(`git ${args[0]}: ${r.stderr.toString()}`);
2223 };
2324 git("init", "--quiet", "--initial-branch=main");
test/shards-run.test.ts +2 −1
@@ -7,6 +7,7 @@
77 * @not-a-tree-scan: it lists only its own temporary directories, and what
88 * it takes from scripts/gate.ts does not read the tree.
99 */
10 import { gitClientEnv } from "./helpers/git-client.ts";
1011 import { afterAll, describe, expect, test } from "bun:test";
1112 import { mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1213 import { tmpdir } from "node:os";
@@ -152,7 +153,7 @@ describe("the gate audit before any shard", () => {
152153 const script = new URL("../scripts/test-shards.ts", import.meta.url).pathname;
153154 const listed = presentTests();
154155 const git = (dir: string, ...args: string[]) =>
155 Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], {
156 Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], { env: gitClientEnv(),
156157 cwd: dir,
157158 stdout: "ignore",
158159 stderr: "ignore",
test/spawn-argv.test.ts +1 −1
@@ -285,7 +285,7 @@ function audit(sites: Site[], list: Allowed[]): { loose: string[]; miscounted: s
285285 describe("what the scan reads", () => {
286286 test("a literal or constant program is fixed; a variable or a template with a value is not", () => {
287287 const src = [
288 `const SETSID = Bun.which("setsid"); Bun.spawn(["git", ...args], { cwd });`,
288 `const SETSID = Bun.which("setsid"); Bun.spawn(["git", ...args], { env: gitClientEnv(), cwd });`,
289289 `Bun.spawnSync([process.execPath, "x.ts"]);`,
290290 `Bun.spawn([SETSID, "-c", ...argv]);`,
291291 `Bun.spawn(argv, {});`,
test/spawn-template-birth.test.ts +2 −1
@@ -4,6 +4,7 @@
44 * adds nothing more, and nothing of the parent travels.
55 */
66
7 import { gitClientEnv } from "./helpers/git-client.ts";
78 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
89 import { mkdtemp, readdir, rm } from "node:fs/promises";
910 import { tmpdir } from "node:os";
@@ -50,7 +51,7 @@ describe("a forge made from a template", () => {
5051 return childDirOf(parent, r.value.bodyId);
5152 };
5253 const git = (childDir: string, org: string, repo: string, ...args: string[]) =>
53 Bun.spawnSync(["git", ...args], { cwd: repoDir(join(childDir, "repos"), org, repo) }).stdout.toString();
54 Bun.spawnSync(["git", ...args], { env: gitClientEnv(), cwd: repoDir(join(childDir, "repos"), org, repo) }).stdout.toString();
5455 const repos = (childDir: string, org: string) => readdir(join(childDir, "repos", org)).catch(() => [] as string[]);
5556
5657 beforeAll(async () => {
test/tags-etag.test.ts +2 −1
@@ -1,4 +1,5 @@
11 /** GET /api/v1/repos/:owner/:name/tags carries an ETag and answers a repeat with 304 (#9161). */
2 import { gitClientEnv } from "./helpers/git-client.ts";
23 import { afterAll, beforeAll, expect, test } from "bun:test";
34 import { mkdtemp, rm } from "node:fs/promises";
45 import { tmpdir } from "node:os";
@@ -22,7 +23,7 @@ const cells = process.env["FORGE_CELLS"];
2223 const URL_ = "/api/v1/repos/alice/r/tags";
2324
2425 const git = async (...args: string[]): Promise<string> => {
25 const p = Bun.spawn(["git", "-c", "user.name=t", "-c", "[email protected]", "--git-dir", dir, ...args], { stdout: "pipe", stderr: "pipe" });
26 const p = Bun.spawn(["git", "-c", "user.name=t", "-c", "[email protected]", "--git-dir", dir, ...args], { env: gitClientEnv(), stdout: "pipe", stderr: "pipe" });
2627 const out = await new Response(p.stdout).text();
2728 if ((await p.exited) !== 0) throw new Error(await new Response(p.stderr).text());
2829 return out.trim();
test/template-scripts.test.ts +2 −1
@@ -2,6 +2,7 @@
22 * scripts/take-template.ts and scripts/birth-check.ts (#10305): the only
33 * checks that a template change still bundles and still boots.
44 */
5 import { gitClientEnv } from "./helpers/git-client.ts";
56 import { afterAll, beforeAll, expect, setDefaultTimeout, test } from "bun:test";
67 import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
78 import { tmpdir } from "node:os";
@@ -12,7 +13,7 @@ setDefaultTimeout(60_000);
1213
1314 let root: string;
1415 const git = (dir: string, ...args: string[]) =>
15 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { stdout: "pipe", stderr: "pipe" });
16 Bun.spawnSync(["git", "-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), stdout: "pipe", stderr: "pipe" });
1617
1718 async function checkout(name: string, extra: Record<string, Uint8Array | string> = {}): Promise<string> {
1819 const dir = join(root, name);
test/test-budget-run.test.ts +2 −1
@@ -8,6 +8,7 @@
88 * @not-a-tree-scan: it lists only the repository's test names, to make an
99 * audit-clean fixture, and reads nothing else of the tree.
1010 */
11 import { gitClientEnv } from "./helpers/git-client.ts";
1112 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1213 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
1314 import { tmpdir } from "node:os";
@@ -18,7 +19,7 @@ const script = new URL("../scripts/test-shards.ts", import.meta.url).pathname;
1819 let dir = "";
1920
2021 const git = (...args: string[]): number =>
21 Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], {
22 Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], { env: gitClientEnv(),
2223 cwd: dir,
2324 stdout: "ignore",
2425 stderr: "ignore",
test/test-git-env.test.ts added +45
@@ -0,0 +1,45 @@
1 /**
2 * A test's git child gets a built environment, never the host's (CLAUDE.md: `gitClientEnv`). A
3 * helper that spawns git with the caller's verb (`["git", ...args]`) and no `env` hands git the
4 * machine's own configuration: `fetch.prune` in a developer's global gitconfig made two of
5 * test/dev-cell.test.ts's tests fail on that machine and nowhere else.
6 *
7 * Every such spawn passes `env: gitClientEnv()` (test/helpers/git-client.ts); a new one without it
8 * fails here.
9 */
10 import { expect, test } from "bun:test";
11 import { readdirSync, readFileSync } from "node:fs";
12 import { join } from "node:path";
13
14 /** Whether `source` spawns git with a caller's arguments (or through `runLocal`) and no env. */
15 function spawnsGitOnHostEnv(source: string): boolean {
16 for (const m of source.matchAll(/\b(?:Bun\.spawn(?:Sync)?|runLocal)\(/g)) {
17 let depth = 0;
18 let i = source.indexOf("(", m.index);
19 const start = i;
20 for (; i < source.length; i++) {
21 if (source[i] === "(") depth++;
22 else if (source[i] === ")" && --depth === 0) break;
23 }
24 const call = source.slice(start, i);
25 const git = m[0].startsWith("runLocal") || /^\(\s*\[\s*"git"/.test(call);
26 if (!git || /\benv\b/.test(call)) continue;
27 if (m[0].startsWith("runLocal") || /^\(\s*\[\s*"git"[^\]]*\.\.\.\w+/.test(call)) return true;
28 }
29 return false;
30 }
31
32 test("no test spawns git on the host's environment", () => {
33 const dir = import.meta.dir;
34 const files = readdirSync(dir, { recursive: true }).map(String).filter((f) => f.endsWith(".ts")).sort();
35 // This file names the pattern in its own examples. Each one found: pass `env: gitClientEnv()`.
36 expect(files.filter((f) => f !== "test-git-env.test.ts" && spawnsGitOnHostEnv(readFileSync(join(dir, f), "utf8")))).toEqual([]);
37 });
38
39 test("the detector sees a bare helper, and spares one with its own env or a fixed verb", () => {
40 expect(spawnsGitOnHostEnv('const git = (...args: string[]) => Bun.spawnSync(["git", ...args], { cwd });')).toBe(true);
41 expect(spawnsGitOnHostEnv('await runLocal(["fetch", ...args], { cwd });')).toBe(true);
42 expect(spawnsGitOnHostEnv('Bun.spawnSync(["git", ...args], { cwd, env: gitClientEnv() });')).toBe(false);
43 expect(spawnsGitOnHostEnv('Bun.spawnSync(["git", "rev-parse", "HEAD"], { cwd });')).toBe(false);
44 expect(spawnsGitOnHostEnv('await runLocal(["fetch"], { cwd, env: gitClientEnv() });')).toBe(false);
45 });
test/tests-with-change.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { expect, test } from "bun:test";
23 import { testsWithChangeProblems } from "../src/kernel/tests_with_change.ts";
34 import { testsWithChangeRefusal } from "../scripts/gate.ts";
@@ -32,7 +33,7 @@ test("the gate judges a real commit range from FORGE_CHECK_BASE", async () => {
3233 const saved = process.env.FORGE_CHECK_BASE;
3334 try {
3435 const sh = (...a: string[]) => {
35 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...a], { cwd: dir });
36 const r = Bun.spawnSync(["git", "-c", "user.email=t@t", "-c", "user.name=t", "-c", "commit.gpgsign=false", ...a], { env: gitClientEnv(), cwd: dir });
3637 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
3738 return r.stdout.toString().trim();
3839 };
test/try-it.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, expect, test } from "bun:test";
23 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
34 import { join } from "node:path";
@@ -67,7 +68,7 @@ const root = mkdtempSync(join(tmpdir(), "try-it-"));
6768 afterAll(() => rmSync(root, { recursive: true, force: true }));
6869
6970 const git = (cwd: string, ...args: string[]) => {
70 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd });
71 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", ...args], { env: gitClientEnv(), cwd });
7172 if (r.exitCode !== 0) throw new Error(r.stderr.toString());
7273 return r.stdout.toString().trim();
7374 };
test/tui-forks-take.test.ts +2 −1
@@ -1,3 +1,4 @@
1 import { gitClientEnv } from "./helpers/git-client.ts";
12 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
23 import { mkdtemp, rm } from "node:fs/promises";
34 import { tmpdir } from "node:os";
@@ -76,7 +77,7 @@ describe("the terminal's forks screen takes the parent's updates with t", () =>
7677 const behind = async (owner: string) =>
7778 (await forkRelation(app, getRepo(app.db, owner, "app")!, upstream))!.behind;
7879 const git = async (cwd: string, ...args: string[]) => {
79 const p = Bun.spawn(["git", ...args], { cwd, stdout: "pipe", stderr: "pipe" });
80 const p = Bun.spawn(["git", ...args], { env: gitClientEnv(), cwd, stdout: "pipe", stderr: "pipe" });
8081 const out = await new Response(p.stdout).text();
8182 expect(await p.exited).toBe(0);
8283 return out.trim();

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs