From b86e61f4098310154906a7340e42be90e4746638 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 24 Nov 2026 14:03:23 +0100 Subject: [PATCH 1/3] =?UTF-8?q?test:=20reproduce=20#1817=20=E2=80=94=20the?= =?UTF-8?q?=20push=20hook=20runs=20the=20repo=20tests=20on=20a=20bug/-r?= =?UTF-8?q?epro=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/push-hook.test.ts | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/push-hook.test.ts diff --git a/src/push-hook.test.ts b/src/push-hook.test.ts new file mode 100644 index 000000000..87cec9422 --- /dev/null +++ b/src/push-hook.test.ts @@ -0,0 +1,71 @@ +import { execFileSync, spawnSync } from "node:child_process"; +import { + chmodSync, + existsSync, + mkdirSync, + mkdtempSync, + readFileSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { describe, expect, it } from "vitest"; + +const ROOT = join(dirname(fileURLToPath(import.meta.url)), ".."); +const LEFTHOOK = join(ROOT, "node_modules", ".bin", "lefthook"); + +// why: the stand-in pnpm fails as `vitest run` does when the branch carries a failing +// *.repo.test.ts, so the step's exit is the hook's verdict on such a push. +function pushRepoTests(branch: string) { + const repo = mkdtempSync(join(tmpdir(), "push-hook-")); + execFileSync("git", ["init", "-q", "-b", branch, repo]); + execFileSync( + "git", + ["-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "--allow-empty", "-m", "x"], + { + cwd: repo, + }, + ); + const config = JSON.parse( + execFileSync(LEFTHOOK, ["dump", "--format", "json"], { cwd: ROOT, encoding: "utf8" }), + ); + const repoTests = config["pre-push"].commands["repo-tests"]; + writeFileSync( + join(repo, "lefthook.json"), + JSON.stringify({ "pre-push": { commands: { "repo-tests": repoTests } } }), + ); + const bin = join(repo, ".bin"); + mkdirSync(bin); + const calls = join(repo, "pnpm-calls"); + writeFileSync(join(bin, "pnpm"), `#!/bin/sh\necho "$@" >> "${calls}"\nexit 1\n`); + chmodSync(join(bin, "pnpm"), 0o755); + const { LEFTHOOK: _off, LEFTHOOK_EXCLUDE: _excluded, ...inherited } = process.env; + const env = { ...inherited, PATH: `${bin}:${process.env.PATH}` }; + const result = spawnSync( + LEFTHOOK, + ["run", "pre-push", "--force", "--no-auto-install", "--no-tty"], + { cwd: repo, env, encoding: "utf8" }, + ); + return { + status: result.status, + pnpm: existsSync(calls) ? readFileSync(calls, "utf8") : null, + }; +} + +describe("the push hook's repo-tests step", () => { + it.each(["bug/7-repro", "wip/7-repro"])( + "does not run the repo tests on %s, whose reproduction fails by design", + (branch) => { + expect(pushRepoTests(branch)).toEqual({ status: 0, pnpm: null }); + }, + ); + + it("runs every repo test on any other branch and refuses the push when one fails", () => { + expect(pushRepoTests("task/7")).toEqual({ + status: 1, + pnpm: "exec vitest run --project unit .repo.test.ts\n", + }); + }); +}); From bf4e938630cdf6d8bee0439aca3922177028e4ce Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 24 Nov 2026 15:12:22 +0100 Subject: [PATCH 2/3] fix(hooks): the push hook skips the repo tests on a triage branch (#1817) --- docs/internal/agent-rules/toolchain.md | 4 +++- lefthook.yml | 4 ++++ src/{push-hook.test.ts => push-hook.repo.test.ts} | 0 3 files changed, 7 insertions(+), 1 deletion(-) rename src/{push-hook.test.ts => push-hook.repo.test.ts} (100%) diff --git a/docs/internal/agent-rules/toolchain.md b/docs/internal/agent-rules/toolchain.md index e91edab39..946f7715b 100644 --- a/docs/internal/agent-rules/toolchain.md +++ b/docs/internal/agent-rules/toolchain.md @@ -57,7 +57,9 @@ list and this one the same. e2e typecheck. A test that reads the repository's files instead of importing code is named `*.repo.test.ts` and runs in about a second: `pnpm test:changed` selects it only when the branch edits the test - itself, so the hook runs every one. + itself, so the hook runs every one, except on `bug/-repro` and + `wip/-repro`, where a triage's reproduction fails by design; CI runs + them all. - **CI:** what `pnpm check` runs, and Fallow, on every push. CI's Fallow (`fallow --ci`) checks the whole tree and fails on any dead-code finding or clone group, `warn` rules included; complexity fails above the diff --git a/lefthook.yml b/lefthook.yml index e1bd3cd63..25427fb5b 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -57,6 +57,10 @@ pre-push: # never selects them and any change can break them; together they take about a second. repo-tests: priority: 1 + # why: a triage branch pushes a reproduction that fails by design (delivery rule 8); CI runs every repo test. + skip: + - ref: bug/*-repro + - ref: wip/*-repro run: pnpm exec vitest run --project unit .repo.test.ts fail_text: "A test of the repository's own files fails (a size cap, the ADR index, a doc's audience): the output names the file and the rule." protocol-bump: diff --git a/src/push-hook.test.ts b/src/push-hook.repo.test.ts similarity index 100% rename from src/push-hook.test.ts rename to src/push-hook.repo.test.ts From 40f444913b2f29fedbd4ef1523d9eaaa281dfd3c Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 24 Nov 2026 15:20:16 +0100 Subject: [PATCH 3/3] fix(hooks): the push-hook test runs the step's own block inside a git hook (#1817) --- src/push-hook.repo.test.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/push-hook.repo.test.ts b/src/push-hook.repo.test.ts index 87cec9422..47528761c 100644 --- a/src/push-hook.repo.test.ts +++ b/src/push-hook.repo.test.ts @@ -19,6 +19,10 @@ const LEFTHOOK = join(ROOT, "node_modules", ".bin", "lefthook"); // why: the stand-in pnpm fails as `vitest run` does when the branch carries a failing // *.repo.test.ts, so the step's exit is the hook's verdict on such a push. function pushRepoTests(branch: string) { + // why: a git hook runs with GIT_DIR set, which would aim the scratch repo's git calls at this checkout. + for (const name of Object.keys(process.env)) { + if (name.startsWith("GIT_")) delete process.env[name]; + } const repo = mkdtempSync(join(tmpdir(), "push-hook-")); execFileSync("git", ["init", "-q", "-b", branch, repo]); execFileSync( @@ -28,14 +32,12 @@ function pushRepoTests(branch: string) { cwd: repo, }, ); - const config = JSON.parse( - execFileSync(LEFTHOOK, ["dump", "--format", "json"], { cwd: ROOT, encoding: "utf8" }), - ); - const repoTests = config["pre-push"].commands["repo-tests"]; - writeFileSync( - join(repo, "lefthook.json"), - JSON.stringify({ "pre-push": { commands: { "repo-tests": repoTests } } }), + // why: `lefthook dump` drops a skip it has judged against this checkout's branch, and `--command` ignores one, so the + // scratch repo gets the step's own block from lefthook.yml and the hook runs there on the scratch branch. + const block = /^ {4}repo-tests:\n(?: {5,}.*\n|\s*\n)*/m.exec( + readFileSync(join(ROOT, "lefthook.yml"), "utf8"), ); + writeFileSync(join(repo, "lefthook.yml"), `pre-push:\n commands:\n${block?.[0]}`); const bin = join(repo, ".bin"); mkdirSync(bin); const calls = join(repo, "pnpm-calls");