Skip to content

test: move input matrices from e2e to unit tests - #385

Merged
willgosnold merged 11 commits into
mainfrom
test/matrices-to-units
Oct 27, 2026
Merged

willgosnold merged 11 commits into
mainfrom
test/matrices-to-units

Conversation

@willgosnold

@willgosnold willgosnold commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Part of #382

Problem

test/e2e.test.ts tested several validation rules with every input spelling through the real CLI, once per command. Each spelling costs a subprocess, a throwaway repo and about 0.2 s. The rule itself lives in one function, so the spellings belong in a unit table. e2e only needs to show that each command passes the refusal to the user and changes nothing.

Change

Each table's spellings now run against the function that decides them, in a new describe in test/units.test.ts. e2e keeps one or two rows per command, chosen as the inputs a user is most likely to hit. Each table is its own commit. Two commits first merge loops that ran the same test body.

Table (at 18b8b43) Deciding function Unit test added e2e removed e2e kept and why
unsafeVendors 15104 unsafeVendor unsafeVendor, 17 rows 44 of 53 Repo root (journal only), ../sibling, .git, for init, track, sync and the sync journal. The sibling row checks nothing outside the repo is touched, and .git checks the git dir survives.
nestedGits 15373 refuseNestedGit refuseNestedGit, 7 rows 9 of 14 A repo of its own and a linked worktree, the two a user makes with git, for init, track and sync.
"inside .git" loops 14684, 14805, 14862 Book.fromText (checkMounts) "an output git reads as .git", 13 refused and 6 allowed [output] to rows 11 of 13 First merged into one table. Keeps skills/.git and .git. for build --force and status.
14950 into 14884 Book.fromText (checkMounts) same describe, 7 mount rows checked in both layouts 1 test, plus 12 CLI calls inside 14884 14950 had the same setup as 14884, so its mounts became rows there first. 14884 keeps .git. for init and .git. and .GIT/x for track, in both layouts.
folded upstream 2138 refuseFoldedUpstream refuseFoldedUpstream, 7 refused and 4 allowed rows 6 of 9 .PATCHBOOK for clone, init, and sync with check.
hook .patchbook spellings 5800 Book.reservedOutput reservedOutput, 6 refused and 4 allowed rows 2 of 3 .patchbook./x.md. It runs on every file system, where the .PATCHBOOK row skips on a case-insensitive one.
escaping 5938 parseChange "an edit whose path leaves the tree", 16 rows 14 of 16 An add and a copy that climb out of the repo.
link refusals at init 3266, 3331 refuseDanglingLinks and the "already exists" check in cmdInit, private to cli.ts; Book#refuseLinkedTop for upstream.lock none 2 of 6 in 3266 Stays in e2e. The dangling-link and retired.md deciders are private. upstream.lock's decider is public, but its rows are one test per layout, which is already the e2e minimum, so a unit row would remove nothing. Only the config.toml rows of 3266 are cut. They link .patchbook/config.toml to a missing file, which the .patchbook/config.toml row of 3331 checks in both layouts, along with an unchanged repo.
LEFTHOOK_PAIRS 3879 configFiles in githook.ts, private none 0 Stays in e2e. Only the exported installHook reaches configFiles, and it needs a real repo and hook folder.
OTHER_NAMES 4322 LEFTHOOK and PRE_COMMIT formats "a hook manager config's pre-commit entries", 10 rows 8 of 10 One lefthook YAML and one pre-commit config.
NOT_RUNNING × MENTIONS 4350, 4364 LEFTHOOK and PRE_COMMIT formats same describe, 48 rows 46 of 48 echo "patchbook hook run" in one lefthook YAML and one pre-commit config.
NOT_ALWAYS 4404 LEFTHOOK format same describe, 7 rows 6 of 7 A skipped lefthook command.

The hook config builders (lefthookCommand, preCommitHook and the rest) move to test/helpers.ts so both files share them. Unit rows whose names hold U+FFFE or U+FFFF get word labels, because Bun writes those characters raw into the junit file and the XML stops parsing.

Verification

  • bun run typecheck passes. bun test --isolate test/units.test.ts test/paths.test.ts: 522 pass, 0 fail.
  • On the head rebased onto 0688792, the touched e2e tests, run with -t over their names: 149 pass from source, and 149 pass against dist/patchbook after bun run build. The binary run reports 161 because 12 matched tests skip under PATCHBOOK_CMD.
  • Each new unit table fails when its rule breaks. I edited the deciding condition, ran the table, then restored it:
Break Rows that failed
unsafeVendor without .toLowerCase() 3 of 17 (the case-folded .patchbook rows)
findGit matching only .git 3 of 7
namesGit without the NTFS rule 5 of 19 [output] to rows
checkMounts without the .git check all 20 refused rows
NTFS_DOT_PATCHBOOK case-sensitive 3 of 11
reservedOutput using under(path, ".patchbook") 4 of 10
unsafePath without the backslash rule 9 of 16
callsIn ignoring the lefthook limits 7 of 65
runsCall accepting any text that holds the call 48 of 65
File 82fd7f6 this PR, rebased on 0688792
e2e.test.ts 1686 1534
units.test.ts 331 483
paths.test.ts 39 39
total 2314 2314
  • I couldn't measure test-seconds cleanly, because other agents were loading the machine. In one serial pair at 82fd7f6, the 149 removed e2e tests took 27.1 test-seconds. But the 1549 tests both sides share took 472.5 s at base and 507.9 s at head, a 35 s drift from load alone, so the totals don't compare. The CI job times on this PR show the real effect. The new unit tests add 0.2 test-seconds to units.test.ts.

I couldn't check macOS. CI runs it on push.

Found while writing the tables, not changed here: unsafeVendor accepts .patchbook., .patchbook /x and .patchbook:x, which Windows reads as .patchbook. The output folder check refuses those spellings through inPatchbook. It needs its own issue, and the unit table here leaves those rows out.

Written with Claude Opus 5.5 in Claude Code

🤖 Generated with Claude Code

willgosnold and others added 11 commits October 27, 2026 19:56
The e2e loop ran 14 spellings of an unsafe vendor folder through init,
track, sync and a sync journal. unsafeVendor decides all of them, so the
spellings now live in a unit table. e2e keeps the repo root (journal
only), a sibling of the repo and .git, to show each command refuses and
writes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
init, track and sync each ran five kinds of nested git dir through the
CLI. refuseNestedGit decides which names count, so the spellings now
live in a unit table. e2e keeps a repo of its own and a linked worktree,
the two a user makes with git itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three loops ran build --force and status for an output folder that git
reads as .git, with the same body and the same expected message. They
are now rows of one table. The same 13 cases run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every command that reads the config builds the Book through
Book.fromText, which refuses an output folder git reads as .git. The 13
spellings, and 6 names that only look like .git, now run there as a unit
table. e2e keeps skills/.git and .git. to show build --force and status
refuse and leave the repo as it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"track rejects a mount with a git segment in another case in both
layouts" had the same setup and assertions as "init and track reject
names git reads as .git in both layouts". Its three mounts are now rows
of the latter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
track builds the new config through Book.fromText, which refuses a mount
git reads as .git in both layouts. The seven mount spellings now run
there as unit rows, and init's three --output-to spellings were already
rows of the [output] to table. e2e keeps .git. for init and .git. and
.GIT/x for track in each layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ream

clone, init, sync and check each ran three spellings of a folder that
macOS or Windows reads as .patchbook. refuseFoldedUpstream decides them,
so seven refused and four allowed paths now run there as a unit table.
e2e keeps .PATCHBOOK for each command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The commit hook refuses a staged file the Book reserves, and
Book.reservedOutput decides which paths those are. The three spellings
the hook test looped over now run there with more rows. e2e keeps
.patchbook./x.md, which runs on every file system, to show the hook
refuses the commit and changes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 edit lines with a climbing, absolute, empty-segment or backslash path
each ran status, status --json and build --force through the CLI.
parseChange holds and refuses them, so the lines now run there as a
unit table. e2e keeps an add and a copy that climb out of the repo, to
show status reports them and build writes nothing inside or outside.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its config.toml rows linked .patchbook/config.toml to a missing file
and checked init refuses it in each layout. "init refuses a dangling
link at .patchbook/config.toml and writes nothing" does the same in both
layouts and also checks the repo is unchanged. The loop keeps
upstream.lock and retired.md, which link to a file that exists.

The rest of the table stays in e2e: refuseDanglingLinks and the checks
in cmdInit are private to cli.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…formats

hook install asks the LEFTHOOK and PRE_COMMIT formats whether a config
already runs patchbook, only mentions the call, or has a patchbook entry
that doesn't always run. The 10 other-name configs, the 48 mention
configs and the 7 limited lefthook entries now run against those formats
as unit tables. e2e keeps one lefthook and one pre-commit config for the
first two, and a skipped lefthook command for the third.

The config builders move to helpers.ts so both files share them.
LEFTHOOK_PAIRS stays in e2e: the pick of lefthook's config file is
private to githook.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@willgosnold

Copy link
Copy Markdown
Owner Author

Out of scope for this PR, found while reviewing it. This PR doesn't change unsafeVendor.

unsafeVendor (src/book.ts:226) refuses a vendor folder named .git. or a/.git /x. It allows .patchbook., .patchbook /x, .patchbook./x and .patchbook:x, which Windows reads as .patchbook or a stream on it. The output-folder check refuses those same spellings.

Through the CLI at a37b015, track --vendor in a fork and in a folder, and init --output-to out --vendor in a folder, all exit 0 and write the vendored copy under each of the four names (12 of 12). On Linux these are separate folders. On Windows the copy would land in .patchbook, and a sync replaces it. That part is reasoned from the code, not run on Windows.

I'll open an issue for it.

🤖 Generated with Claude Code

@willgosnold
willgosnold merged commit 0d4ee20 into main Oct 27, 2026
8 checks passed
@willgosnold
willgosnold deleted the test/matrices-to-units branch October 27, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant