Skip to content

[FEATURE] Golden-frame TUI tests via an Update/View pump #824

Closed as not planned
Closed as not planned

Description

@edenreich

Problem

No frame-level regression tests exist: no teatest, no testdata/*.golden anywhere in the repo. UI regressions (layout, wrapping, borders, component sizing) ship silently, and an agent iterating on the TUI has no red/green loop.

Design

Pure Update/View pump — no tea.Program, and deliberately no teatest: teatest/v2 at HEAD is type-compatible with charm.land/bubbletea/v2 but untagged (pseudo-version) and runs a real program with goroutines/timing, while github.com/charmbracelet/x/exp/golden (charm's own -update golden helper) is already in go.sum.

New tests/integration/chat_tui_golden_test.go, reusing newEnv() from agent_gateway_test.go (builds the real service container against the in-process mock gateway — proven pattern):

  • newChatApp(t, defaultModel) mirrors the 30 constructor args of cmd/chat.go:213-244 getter-for-getter — it compile-breaks when the ctor changes, which is intended.
  • pump(m, msgs...) feeds tea.WindowSizeMsg{Width: 120, Height: 40}, scripted domain.*Events, and tea.KeyPressMsg through Update. It does not run Init() or execute returned Cmds — goldens are pure Update/View state (Init currently has sync side-effects; skipping it keeps goldens stable through that separate cleanup).
  • frame(m) = ansi.Strip(m.View().Content) (from charmbracelet/x/ansi, direct dep), trim trailing spaces per line, drop trailing blank lines — so the alt-screen flicker fix won't churn goldens — then golden.RequireEqual(t, frame(m)).
  • INFER_TUI_DETERMINISTIC=1 set in TestMain via os.Setenv — the latch is process-wide (sync.OnceValue), so t.Setenv's scoped unset would be misleading.

Initial goldens (5):

  1. Model picker (defaultModel="" → ViewStateModelSelection)
  2. Streamed reply (ChatStartEvent → StreamingContentEvent×N → ChatCompleteEvent + UpdateHistoryEvent)
  3. Tool lifecycle (ToolCallPreviewEvent → ToolExecutionProgressEvent running → completed)
  4. Approval box (ToolApprovalRequestedEvent, handled at chat.go:514)
  5. Reasoning panel (StreamingContentEvent with ReasoningContent)

Regen workflow: go test ./tests/integration/ -run TestGolden -update → review the diff → commit goldens.

Acceptance criteria

  • Five goldens committed under tests/integration/testdata/
  • Second run without -update passes; changing a style constant fails with a readable diff
  • Runs in the normal task test job (no build tag)

Dependencies

Depends on #823.

Activity

  1. added
    enhancement
    on Jul 10, 2026
  2. moved this to Todo in 2026on Jul 10, 2026
  3. moved this from Todo to Done in 2026on Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions