Skip to content

git-stats: an e2e suite that would actually notice the card breaking - #29

Merged
navbytes merged 1 commit into
mainfrom
e2e-rendering-tests
Sep 10, 2026
Merged

git-stats: an e2e suite that would actually notice the card breaking#29
navbytes merged 1 commit into
mainfrom
e2e-rendering-tests

Conversation

@navbytes

Copy link
Copy Markdown
Owner

The 90 unit tests cover pure functions. Nothing exercised the card rendering against
OpenCode's sidebar API — precisely the surface that has broken twice while those
stayed green, most recently a chip that looked clickable and was not.

test/e2e boots the real OpenCode TUI in a pty with the built plugin, against a real
git repo and a real gh, and asserts on the pyte-composed screen and the raw terminal
bytes:

figures match git +3 tracked lines + a 2-line untracked file → +5 -0 · 2 files
clean tree working tree clean
chip state #20 Merged once gh answers
chip colour raw bytes contain 48;2;130;80;223
click opens stub open on PATH records exactly the PR URL
click × chip gone from the next frame, stub open records nothing
gh logged out #20 … and gh: run `gh auth login`

Click coordinates are found by parsing the cursor-position escape before the chip's
own run in the raw capture, not hardcoded, so the tests survive the card moving.

Checked against a broken plugin

A rendering suite that passes on a broken plugin is worse than none, so both halves
were verified by sabotage:

  • deleting the two onMouseDown handlers → the click test fails (expected [PR_URL], received [])
  • changing the merged colour to #ff0000 → the colour test fails

Both restored; full suite green afterwards.

Cost

Opt-in behind GIT_STATS_E2E=1 — it needs an authenticated gh and takes ~4 minutes.
Plain bun test skips it and still finishes in 3 seconds, so CI is unchanged.

The 90 unit tests cover pure functions. Nothing exercised the card rendering
against OpenCode's sidebar API — which is precisely the surface that has broken
twice while those stayed green, most recently a chip that looked clickable and
was not.

test/e2e boots the real OpenCode TUI in a pty with the built plugin, against a
real git repo and a real `gh`, and asserts on the pyte-composed screen and the raw
terminal bytes:

- the figures match what git itself reports for the fixture (+3 tracked lines and
  a 2-line untracked file render as "+5 -0 · 2 files", untracked counted as
  all-additions the way OpenCode's vcs.status does)
- a clean tree says "working tree clean"
- the chip renders "#20 Merged" once gh answers, painted 48;2;130;80;223
- a scripted SGR mouse click on the chip opens the pull request (asserted against
  a stub `open` first on PATH, whose recorded argv must equal the PR URL exactly)
- a click on the × dismisses the chip and opens nothing
- a logged-out gh degrades to "#20 …" with the reason on the card

The click coordinates are found by parsing the cursor-position escape before the
chip's own run in the raw capture, not hardcoded, so the tests survive the card
moving.

Checked against a broken plugin, because a rendering suite that passes on one is
worse than no suite: deleting the two onMouseDown handlers fails the click test
(expected the URL, got []), and changing the merged colour to #ff0000 fails the
colour test. Both restored.

Opt-in behind GIT_STATS_E2E=1 — it needs an authenticated gh and takes ~4 minutes.
Plain `bun test` skips it and still runs in 3 seconds, so CI is unchanged.
@navbytes
navbytes merged commit a37d907 into main Sep 10, 2026
1 check passed
@navbytes
navbytes deleted the e2e-rendering-tests branch September 10, 2026 13:42
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