Repository navigation
Description
Problem
The test suite is slow to run and awkward to work in, but it is not mostly redundant. Measurements at 18b8b43:
- CI wall time on a PR is set by one job.
test (root)takes about 17 minutes (16.7, 17.2 and 17.3 in the last three green runs). The three Ubuntu shards take about 3 minutes each. The required checktest (ubuntu-latest)needstest-root, so every PR waits about 17 minutes. That job runsbun test --isolateand then the whole e2e suite again against the binary, one after the other, in a single unsharded job. - Most of the suite is end to end. About 77% of cases go through the CLI as a subprocess.
test/e2e.test.tsis 19,231 lines, 82% of all test code, and holds about 1,700 runtime tests. Run from source, the suite takes about 700 test-seconds, and e2e is 689 of them. No test is slow: 1,887 of 2,327 take under 0.5s, and the slowest takes 4.7s. The cost is the number of tests. - The count comes from input matrices, not duplicates. Many rules are tested for every input class × every layout (fork, folder) × every command, each through the real CLI. For example, case-folded
.gitand.patchbooknames, link kinds, and hook-manager configs. - Real duplication is small. Per-test statement coverage over the whole suite reaches 96.7% of 5,761 statements. 680 e2e tests share an identical coverage set with another test. A random sample of 93 of them was read test by test: 8 were duplicates or could be merged, 64 were loops over input classes that each matter, and 21 pinned distinct behaviour. That puts the removable count at about 60 e2e tests (~3–4%).
So deleting tests won't fix this. The wins are in CI layout, and in where the input matrices live.
Proposal
In order of payoff. Each step can be its own PR.
1. Take the root job off the critical path
- Shard
test-rootwith the same three--test-name-patternpatterns thetestjob uses (fork,vendor,rest). - Run e2e as root once, against the compiled binary. Keep the from-source run only for what needs it: the unit files, and the describes that skip under
PATCHBOOK_CMD("init stopped by a preload", "killed by a preload"). - Keep the job's purpose: a test that needs a refused write and isn't wrapped in
permissionTestmust still fail as root. - Expected: PR wall time drops from ~17 minutes to about the length of the slowest Ubuntu shard plus build, roughly 4–6 minutes. Report the before and after times from real runs.
2. Move input-class matrices down to unit tests
The rule: test a validation rule's full table of inputs once, against the function that decides it, in units.test.ts or paths.test.ts. Keep e2e for proving the CLI wiring: one or two cases per command × layout that show the refusal reaches the user with the right message and leaves the repo untouched.
Candidate tables in test/e2e.test.ts (line numbers at 18b8b43):
| Lines | Table | What it varies |
|---|---|---|
| 15104–15143 | unsafeVendors |
case spellings of unsafe vendor paths |
| 15373 | nestedGits |
case-folding and zero-width spellings of a git dir |
| 14684, 14805, 14862 | "inside .git" loops | three loops with the same body and the same expected message; merge into one table first |
| 2138, 5800–5806 | folded upstream and .patchbook spellings |
case, trailing dot, trailing space |
| 5938–5951 | escaping |
backslash and climbing paths per verb |
| 3266–3270, 3331 | link refusals at init | link kind × file × layout |
| 3879, 4322, 4350, 4364, 4404 | LEFTHOOK_PAIRS, NOT_RUNNING × MENTIONS, NOT_ALWAYS, OTHER_NAMES |
hook-manager config detection |
For each table, check first that the deciding function is reachable as a unit. If it isn't, say so in the PR and leave the table in e2e. Don't export internals just for this.
3. Merge the confirmed duplicates
Each pair has the same setup and actions and differs only in what it asserts. Merge the assertions into one test:
8857"commit takes a mode change to a file the fork added" and8867"commit records a mode the index already has"12195into12045(ignored trackedx.log, edit, note commit)14950into14884(track rejection in both layouts, plus the.GIT/.Git/.gItvariants)2750into the stale-mirror row of the loop at29275999"record refuses a bad change name with no hand edits" as a row in the label loop at5988- The
config.tomlinstances of the link loop at3266duplicate the dangling-link test at3331for.patchbook/config.toml. Read both before cutting. The judgement came from a sample reviewer and wasn't double-checked.
4. Split test/e2e.test.ts by top-level describe
Split it into files such as e2e/fork.test.ts, e2e/vendor.test.ts, e2e/intent.test.ts, e2e/hook.test.ts, and so on. Move the shared fixtures (forkTest, vendorTest, hookCommit, startingRepo, …) into a helper module next to test/helpers.ts. Point the CI shards at files, not name patterns.
This is mostly for developer experience: you can run the area you're changing, and diffs and reviews stay readable. Check whether bun test runs files in parallel at the pinned Bun version. If it does, measure the local speed-up. If it doesn't, don't claim one.
5. Low priority: parametrise near-identical unit tests
A shingle-similarity scan found 151 pairs of unit tests above 0.9 similarity, for example setToml at 314/322 and applyStructure at 706/736. They're cheap to run, so only convert them to test.each where it reads better.
Guardrails
- No behaviour lost. Each PR that removes or moves an e2e case names the test that now covers it. Statement coverage must not drop below the baseline (96.7%). See "Measuring" below.
- No change to what CI proves:
- e2e still runs against the compiled binary on Ubuntu, and on macOS for pushes.
- Root still runs the full suite.
- The crash-injection check on the binary stays.
- Follow CONTRIBUTING.md: the e2e/units split rule still holds, it's just applied more strictly.
Measuring
Report before and after for each PR:
- runtime test count per file;
- test-seconds per file, using
bun test --reporter=junit --reporter-outfile=…; - wall time per CI job from
gh run view --json jobs.
How statement coverage was measured, so it can be rebuilt:
- Bun's coverage doesn't follow CLI subprocesses, so the harness preloads a Bun plugin into the CLI through
PATCHBOOK_CMD="bun --preload <preload> src/cli.ts". - The plugin uses the TypeScript 5 parser to insert a counter before each statement in
src/. - Each process writes its hit set on exit. A wrapper standing in for
bun:testtags each run with the current test's name. - Two limits: tests in
cli.test.tsthat start a plainbun -echild aren't recorded, and the 3env.test.tstests that checkprocess.envfail under the harness. - A working copy may still be at
/tmp/pbcov/harnesson the original machine.
Out of scope
- Coverage thresholds in CI.
- Lint rules for tests.
- Changing the
qa/journeys.
What you do now
Wait about 17 minutes per PR for test (root). Locally, run all of test/e2e.test.ts (about 11 minutes serial), or hand-write a -t pattern.
Would you like to write the PR?
Yes. An agent will pick this up.
🤖 Generated with Claude Code
Activity
ci: shard the root test job (#383)
willgosnold commentedon Oct 27, 2026
Plan for this issue. Each step is its own PR.
test/e2e.test.ts. Those items are the14950into14884merge, and theconfig.tomlrows of the link loop at3266against the dangling-link test at3331.test/e2e.test.ts): starts after steps 1 to 3 merge, because it moves every line they touch.test.eachtable. Most are one-lineexpect(f(input)).toEqual(output)tests whose names state different rules, and the issue asks for a conversion only where a table reads better.🤖 Generated with Claude Code
willgosnold commentedon Oct 27, 2026
All five steps are done. Closing.
LEFTHOOK_PAIRSstay in e2e, and the PR says why.5999stays its own test: it alone pins thatrecordchecks the name before it looks for edits.test/e2e.test.tstest/e2e/and a sharedtest/e2e-fixtures.ts. Every test keeps its full name. CI shards by file.test.eachtable. Most are one-line tests whose names state different rules. The rest were not read.bun test --paralleleverywhere. Locally, e2e against the binary went from 750 s to 167 s. In CI only therestshard gains (147 s to 98 s in one run each side), becauseforkandvendorare one file each.Statement coverage, measured with the harness from this issue, is 5569 of 5761 (96.67%) at
82fd7f6and after every PR, with 0 statements lost.Not done, for later:
test/e2e/fork.test.ts, at about 2.8 minutes. SplittingForkTestandVendorTestinto several files would lower it. Their nested describes are interleaved with local helpers, so that needs a second shared-helper module.PRE_COMMIT_NOT_ALWAYS,readsAsDotPatchbookand "init and track reject names Windows or a Mac reads as .patchbook" have the same shape as the tables step 2 moved. The new pre-commit unit rows cover only hooks that count as running on every commit. The rules that reject a hook, such asalways_run,pass_filenamesandargs, are still covered only byPRE_COMMIT_NOT_ALWAYSin e2e.Book#refuseLinkedTopis public and decides theupstream.locklink refusal, but no unit test calls it. test: move input matrices from e2e to unit tests #385 kept that case in e2e only..patchbook) and test: a renamed from-source-only describe drops out of CI without failing #389 (a renamed from-source-only describe drops out of CI without failing).🤖 Generated with Claude Code