Repository navigation
Conversation
NewTestIOWithOptions lets tests set the templates, color environment and redirected streams that NewTestIO leaves off. The color environment lookup moves into colorFromEnv so NewIO and the test path share it. tableview.RunWithOptions lets tests supply input and an initial window size. Run calls it with zero options, so production behaviour is unchanged. Both seams are behaviour-neutral when given their zero values. Co-authored-by: Isaac <no-reply@databricks.com>
✅ Integration test reportCommit: 58b99e3
Top 50 slowest tests (at least 2 minutes):
|
|
/review |
…put helpers
Opt-in capabilities for pinning what a command writes to a terminal:
- GoldenStyled renders SGR as inline markers ({fg=4}?{/}, {bold}).
- GoldenModes logs mode changes and the modes still active on exit,
covering cursor visibility, bracketed paste, alternate screen, mouse,
kitty keyboard and modifyOtherKeys.
- GoldenQueries logs terminal queries (DECRQM, kitty flags, OSC 11, CPR,
DA1/DA2, XTVERSION). Responder answers them after a delay.
- Leftover reports input bytes unread at exit (Unix only).
- TypeBurst, Paste, Settle, WaitForScreen and WaitForOrExit cover input
and timing that the existing helpers could not express.
- Options gains Env, ColorFromEnv, stream redirection, templates,
screen rows and newline mapping.
Existing goldens and default behaviour are unchanged.
Co-authored-by: Isaac <no-reply@databricks.com>
d3620d1 to
7f68a1a
Compare
Adds pin tests that record what the Charm v1 prompt, select, spinner, pager, tableview and LogString do today: keys (burst input, Alt and Shift+Enter, kitty Esc, paste), colors across TERM, CI, CLICOLOR and NO_COLOR, terminal modes on exit, terminal queries and leftover replies, pager paging and spinner frames, tableview search input, and stderr styling when a stream is redirected. The goldens under testdata/ are the reference. When the v2 swap lands, these tests fail and the golden diffs show the exact user-visible change. Regenerate with -update only for an intended change. Co-authored-by: Isaac <no-reply@databricks.com>
7f68a1a to
58b99e3
Compare
| tm := runPinPager(t, it) | ||
| termtest.GoldenText(t, "01-first-page-loading", observeSpinnerFrames(tm, 2, 3*time.Second)) | ||
| tm.Type(termtest.KeyEnter) | ||
| before := len(tm.Raw()) |
There was a problem hiding this comment.
With WaitForInputRead gone, nothing makes sure the program reads Enter before the first page lands. Type only writes to the pipe, and the spinner keeps ticking while the fetch is in flight, so its next frame satisfies waitForOutputPast whether or not Enter was read.
If the key is read late, startDrain takes the at-prompt branch (pager.go:229, starts a new fetch) instead of the one this test is named for (pager.go:226, drainAll recorded during an in-flight fetch). Both branches print all 120 rows, and onlyPagerRows strips the prompt remnants, so the goldens match either way and the test can't tell which branch it covered.
There's no portable way to see that the key was read, and nothing on screen changes when drainAll is set mid-fetch. So I'd drop the two wait lines and waitForOutputPast (this is its only caller), and name the test after what it does guarantee, e.g. TestPagerPin_EnterDrainsRemainingPages. A short comment could say the key may reach the pager during the fetch or at the prompt, and that both drain. The testdata/ directory would move with the rename. Or is the in-flight branch worth keeping a Unix-only read barrier for?
|
/review |
There was a problem hiding this comment.
Automated review at 58b99e3. Each finding was verified against the code.
Not ready yet: part of the automated review did not complete.
This PR adds test infrastructure to pin current Charm v1 TUI behavior ahead of a v2 migration, so the swap surfaces its changes as golden diffs. Production changes are minimal and behavior-neutral: an unexported colorFromEnv helper, a NewTestIOWithOptions test constructor, and a RunWithOptions entry point for tableview. The test harness extensions (styled/modes/queries goldens, responder, leftover capture) are well-documented and the 103 golden files serve their stated sentinel purpose. After tracing every candidate claim against the code, no defects survive.
This PR pins current Charm v1 TUI behaviour, so the Charm v2 migration shows its exact user-visible changes as golden diffs.
Changes
Test infrastructure only. No production behaviour changes.
Two behaviour-neutral seams for tests, both with zero-value defaults that keep production behaviour:
cmdio.NewTestIOWithOptionstakes templates, the color environment and redirected streams. The color-from-environment lookup moves intocolorFromEnv, shared byNewIOand the test path.tableview.RunWithOptionstakes an input and an initial window size.Runcalls it with zero options.termtestcapabilities (all opt-in; existing goldens unchanged):{fg=4}?{/},{bold},{fg=@208},{fg=#8fb3dc}), covering SGR colors, bold, faint, italic, underline styles (4:n,21), blink, reverse, strikethrough and overline. Colon and semicolon color forms are decoded.GoldenModes): every set and reset is recorded, so a repeated write shows as a diff. Covers cursor visibility, bracketed paste, alternate screen, mouse, kitty keyboard, modifyOtherKeys and DECST8C.GoldenQueries): DECRQM, kitty flags, OSC 10/11, CPR, DA1/DA2, XTVERSION. AResponderanswers them after a delay.Leftoverreports input left unread on exit. It closes the harness's end of the input pipe and reads to EOF, so it needs no platform-specific reads. Its tests are skipped on Windows.TypeBurst,Paste, key constants for Alt and Shift+Enter forms, andSettle, which waits until output is quiet.WaitForScreen,WaitForOrExit,WaitForRepliesandWaitForExit.Options:Env,ColorFromEnv, stream redirection, templates,ScreenRows(non-positive values use the default),MapNewlineandNormalize(applied to screen snapshots only).LogRawOnFailurelogs the raw output stream when a test fails.Pinned areas (
libs/cmdio/cmdiotest/pin_*_test.go, 103 new goldens undertestdata/):TERM(unset, xterm-256color, screen, vt100, dumb),CI,CLICOLOR=0,NO_COLOR, tmux with truecolor andCOLORTERM.LogStringwrites to a redirected stderr.LogStringitself writes its bytes unchanged. The SGR is stripped by the color helpers and the renderer, and the goldens show the effect.The goldens are the reference. When the v2 swap lands these tests fail, and the golden diffs show the exact change. Regenerate with
-updateonly for an intended change.Known flake:
TestPagerPin_SpaceLoadsNextPageonce showed the second page over the first. It has not recurred since the test waits for output to settle before pressing space. On failure the test logs the raw output stream for diagnosis.Waits that gate a golden fail the test on timeout. Two waits are deliberately tolerant, and say so at the call site: the spinner-frame count (the count is the pinned value) and the select's second cursor hide (a version that hides once must still reach its golden).
No
.nextchangesfragment: this is test-only.Why
The v2 migration changes key decoding, color detection, the bytes written when a TUI starts and exits, and paging/search behaviour. The existing tests run against pipes and an emulator, so they cannot show what changes for a user. Pinning the current v1 behaviour first makes each intended change a reviewable golden diff.
Some v1 behaviour pinned here is accidental (for example, Alt+Enter submits, and a late OSC 11 reply is typed into the prompt). The pins record it so the migration decides on each change explicitly rather than inheriting it silently.
Tests
go build ./...,go vet(linux, darwin, windows) and golangci-lint on./libs/cmdio/...and./libs/tableview/...pass. gofmt is clean.TERM=xterm-256color go test -race -count=10 ./libs/cmdio/...passes.-race -run Pin -count=10and 1 round of the same under 8 CPU-hog processes: zero failures. One full-package-race -count=3run failed once onTestSelectBaseline_EscKey(a key typed just before a snapshot was read before its echo). It has not reproduced: four further cmdiotest-only runs and a full./libs/cmdio/...run passed, and the test passes 10 of 10 in isolation. It does not useSettle,LeftoverorWaitForInputRead.go teston./libs/cmdio/cmdiotest/passes withTERM=dumband withTERMunset.go test ./cmd/auth/... ./libs/tableview/...passes.go test ./acceptance/...passes.testdatadiff against the base contains only added files.This pull request and its description were written by Isaac.