Implement HeadlessRenderer for terminal-free UI testing #309

Closed
opened 2026-03-16 01:59:27 +00:00 by freemo · 0 comments
Owner

Metadata

Key Value
Branch feature/m2-headless-renderer
Commit Message feat: implement HeadlessRenderer for terminal-free UI testing
Parent Epic #306 — Render Pipeline

Background and Context

The render pipeline's Ncurses and Composite stages require a terminal to function. Automated tests (especially Cucumber integration tests in CI) run without a terminal. A HeadlessRenderer replaces the terminal-dependent stages with an in-memory capture system, allowing tests to verify UI behavior without ncurses.

Expected Behavior

HeadlessRenderer is a drop-in replacement for the Ncurses and Composite stages. Instead of writing to terminal buffers, it captures all render output as structured data:

renderer = HeadlessRenderer.new
pipeline = RenderPipeline.new(windows, layout, renderer: renderer)

# After processing ops...
renderer.window_content(:main)
# => ["A goblin enters from the north.", "You say, 'Hello!'"]

renderer.window_content(:status)
# => [{ bar: :hp, value: 85, max: 100 }]

renderer.last_frame
# => { main: [...], status: [...], map: [...] }

renderer.frame_count
# => 42

renderer.clear_history

Tests use the HeadlessRenderer to assert UI behavior:

expect(renderer.window_content(:main)).to include("A goblin enters")
expect(renderer.last_bar_update(:hp)).to eq({ value: 85, max: 100 })

Acceptance Criteria

  • HeadlessRenderer implements the same interface as the Ncurses+Composite stages.
  • Captures text content per window as an array of strings/structured data.
  • #window_content(window_name) returns current content for a window.
  • #last_frame returns a hash of all window contents from the last frame.
  • #frame_count tracks total frames rendered.
  • #clear_history resets all captured state.
  • Pipeline automatically uses HeadlessRenderer when no terminal is detected (or when configured for test mode).
  • Cucumber step definitions can access the HeadlessRenderer for assertions.

Subtasks

Code

  • Create HeadlessRenderer class implementing the render stage interface.
  • Implement per-window content capture as structured arrays.
  • Implement #window_content, #last_frame, #frame_count, #clear_history.
  • Implement #last_bar_update(bar_name) convenience method for status bar assertions.
  • Add auto-detection: use HeadlessRenderer when ENV['TERM'] is unset or HEADLESS=1.
  • Add pipeline configuration option to inject renderer.
  • Create Cucumber helper module exposing HeadlessRenderer to step definitions.

Quality

  • Docs: Update YARD comments on affected classes and methods. Update relevant Docusaurus documentation pages if applicable.
  • Tests (Cucumber): Add tests/unit/headless_renderer.feature covering capturing text_append ops per window, capturing bar_update ops, frame counting, clear history, window content retrieval, last frame snapshot, auto-detection of headless environment, Cucumber step integration.
  • Tests (Cucumber Integration): Add integration feature in tests/integration/ for HeadlessRenderer capturing render output for UI test verification.
  • Tests (Profiling): Run bundle exec rake unit_profile and verify no performance regressions.
  • Quality: Verify coverage >=97% via bundle exec rake unit. If coverage is <97% then review the current unit test coverage report at build/tests/unit/coverage/ and use it to write new Cucumber based unit tests to improve coverage. Specifically, write Cucumber/Gherkin style unit tests that are descriptively named and specifically improve coverage on whichever file has the most uncovered lines by writing tests that will target the uncovered lines in the report. Once that is done rerun bundle exec rake unit to verify all tests pass and coverage is above >=97%. Only mark this as complete once coverage is >=97%, if not repeat this task as many times as is needed until coverage reaches >=97%.
  • Quality: Run bundle exec rake (default task: unit tests with coverage) and bundle exec rake integration, fix any errors if needed ensuring both pass across entire code base, do not ignore any failure even if it seems unrelated to this commit, fix it.

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
## Metadata | Key | Value | |-----|-------| | **Branch** | `feature/m2-headless-renderer` | | **Commit Message** | `feat: implement HeadlessRenderer for terminal-free UI testing` | | **Parent Epic** | #306 — Render Pipeline | ## Background and Context The render pipeline's Ncurses and Composite stages require a terminal to function. Automated tests (especially Cucumber integration tests in CI) run without a terminal. A HeadlessRenderer replaces the terminal-dependent stages with an in-memory capture system, allowing tests to verify UI behavior without ncurses. ## Expected Behavior `HeadlessRenderer` is a drop-in replacement for the Ncurses and Composite stages. Instead of writing to terminal buffers, it captures all render output as structured data: ```ruby renderer = HeadlessRenderer.new pipeline = RenderPipeline.new(windows, layout, renderer: renderer) # After processing ops... renderer.window_content(:main) # => ["A goblin enters from the north.", "You say, 'Hello!'"] renderer.window_content(:status) # => [{ bar: :hp, value: 85, max: 100 }] renderer.last_frame # => { main: [...], status: [...], map: [...] } renderer.frame_count # => 42 renderer.clear_history ``` Tests use the HeadlessRenderer to assert UI behavior: ```ruby expect(renderer.window_content(:main)).to include("A goblin enters") expect(renderer.last_bar_update(:hp)).to eq({ value: 85, max: 100 }) ``` ## Acceptance Criteria - [ ] `HeadlessRenderer` implements the same interface as the Ncurses+Composite stages. - [ ] Captures text content per window as an array of strings/structured data. - [ ] `#window_content(window_name)` returns current content for a window. - [ ] `#last_frame` returns a hash of all window contents from the last frame. - [ ] `#frame_count` tracks total frames rendered. - [ ] `#clear_history` resets all captured state. - [ ] Pipeline automatically uses HeadlessRenderer when no terminal is detected (or when configured for test mode). - [ ] Cucumber step definitions can access the HeadlessRenderer for assertions. ## Subtasks ### Code - [ ] Create `HeadlessRenderer` class implementing the render stage interface. - [ ] Implement per-window content capture as structured arrays. - [ ] Implement `#window_content`, `#last_frame`, `#frame_count`, `#clear_history`. - [ ] Implement `#last_bar_update(bar_name)` convenience method for status bar assertions. - [ ] Add auto-detection: use HeadlessRenderer when `ENV['TERM']` is unset or `HEADLESS=1`. - [ ] Add pipeline configuration option to inject renderer. - [ ] Create Cucumber helper module exposing HeadlessRenderer to step definitions. ### Quality - [ ] Docs: Update YARD comments on affected classes and methods. Update relevant Docusaurus documentation pages if applicable. - [ ] Tests (Cucumber): Add `tests/unit/headless_renderer.feature` covering capturing text_append ops per window, capturing bar_update ops, frame counting, clear history, window content retrieval, last frame snapshot, auto-detection of headless environment, Cucumber step integration. - [ ] Tests (Cucumber Integration): Add integration feature in `tests/integration/` for HeadlessRenderer capturing render output for UI test verification. - [ ] Tests (Profiling): Run `bundle exec rake unit_profile` and verify no performance regressions. - [ ] Quality: Verify coverage >=97% via `bundle exec rake unit`. If coverage is <97% then review the current unit test coverage report at `build/tests/unit/coverage/` and use it to write new Cucumber based unit tests to improve coverage. Specifically, write Cucumber/Gherkin style unit tests that are descriptively named and specifically improve coverage on whichever file has the most uncovered lines by writing tests that will target the uncovered lines in the report. Once that is done rerun `bundle exec rake unit` to verify all tests pass and coverage is above >=97%. Only mark this as complete once coverage is >=97%, if not repeat this task as many times as is needed until coverage reaches >=97%. - [ ] Quality: Run `bundle exec rake` (default task: unit tests with coverage) and `bundle exec rake integration`, fix any errors if needed ensuring both pass across **entire** code base, do not ignore any failure even if it seems unrelated to this commit, fix it. ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done.
freemo added this to the v1.1.0 milestone 2026-03-16 01:59:27 +00:00
freemo self-assigned this 2026-03-16 01:59:27 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
Reference: aethyr/Aethyr#309
No description provided.