refactor(test): extract shared TUI test helpers - #838
Closed
kelsonpw wants to merge 1 commit into
Closed
Conversation
Add `src/ui/tui/__tests__/helpers/`: - `strip-ansi.ts` — `stripAnsi(s)` + `ANSI_CSI_REGEX` / `ANSI_OSC_REGEX`. Replaces 19 per-file `ANSI = /.../` + `stripAnsi = (s) => s.replace(...)` definitions scattered across TUI tests. Every callsite that previously stripped only CSI also gets the OSC strip — a no-op on plain CSI frames but defensive on TTY-capable terminals where Ink emits OSC 8 hyperlinks (same rationale as `snapshot-utils.tsx`). - `render-frame.tsx` — `frameOf(node)` shorthand for the render-strip-unmount idiom used by 6 component tests. The pattern was literally identical at each call site (`render` → `lastFrame()` → strip → `unmount` → return). `snapshot-utils.tsx` now reuses the shared `stripAnsi` instead of defining its own. Migrated 21 test files (no behavior changes — only the source of the helper changes). `FinalizingPanel.test.tsx` is intentionally left alone: it uses a narrower SGR-only `/[0-9;]*m/` regex and the test cases assert on cursor/clear sequences elsewhere; folding it in would broaden the strip semantics for that file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
Closing as part of pat-leave handoff to reduce open-PR load on the team. Branch preserved on origin — reopen if specific changes are wanted. The highest-impact wins from this refactor round already merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/ui/tui/__tests__/helpers/withstrip-ansi.ts(stripAnsi+ANSI_CSI_REGEX/ANSI_OSC_REGEX) andrender-frame.tsx(frameOf(node)render-strip-unmount shorthand).ANSI = /.../+ per-filestripAnsidefinitions and 6 hand-rolledframeOfwrappers.snapshot-utils.tsxnow reuses the sharedstripAnsi.No behavior changes: every callsite still strips CSI sequences; callers that previously stripped only CSI now also strip OSC (no-op on CSI-only frames, defensive on TTY-capable terminals — same rationale as
snapshot-utils.tsxalready used).Follows up #814/#819 (mkdtempSync helper extraction) — same playbook applied to the next-largest cluster of duplication in TUI tests.
Patterns deferred (with reasons)
FinalizingPanel.test.tsx— narrower SGR-only regex/[0-9;]*m/. Folding it in would broaden strip semantics for that file; left alone.new WizardStore(...)/ per-filemakeStorevariants — 5 distinct signatures (4 take differentPartialshapes;ActivityLine.makeStoreWithActivityis unique). A sharedcreateTestStorewould need careful design to not regress per-test setup; deferred.useStdoutDimensionsmock — only 3 callsites and 2 already share viaink-stdin.tsx. Below the duplication threshold.await new Promise((r) => setTimeout(r, ...))Ink-tick yielding — 41 instances across 10 files, but the delay values and surrounding wait conditions vary per case; a shared helper would force a one-size-fits-all timeout.Test plan
pnpm tsc --noEmitcleanpnpm lintclean (prettier + eslint)pnpm test— all 298 files / 4473 tests pass--pool=forks --maxWorkers=1AuthScreen.snap,OutroScreen.snap,RegionSelectScreen.snap) match unchanged🤖 Generated with Claude Code
Note
Low Risk
Test-only refactor that centralizes ANSI stripping and frame rendering; low risk aside from potential snapshot churn if OSC/CSI stripping semantics differ across environments.
Overview
Refactors TUI tests to use shared rendering/sanitization helpers. Adds
__tests__/helpers/strip-ansi.ts(sharedstripAnsi+ CSI/OSC regexes) and__tests__/helpers/render-frame.tsx(frameOf()render→strip→unmount shortcut).Updates TUI component/screen/primitive tests and
snapshot-utils.tsxto remove per-file ANSI regexes and ad-hocframeOfwrappers, standardizing on always stripping both CSI and OSC sequences for more deterministic snapshots across TTY vs CI runs.Reviewed by Cursor Bugbot for commit a1e4cc1. Bugbot is set up for automated code reviews on this repo. Configure here.