Skip to content

test: cover ui.py rendering helpers and slash menu - #86

Draft
aryansk wants to merge 3 commits into
shauryagangrade:mainfrom
aryansk:test/ui-helpers
Draft

test: cover ui.py rendering helpers and slash menu#86
aryansk wants to merge 3 commits into
shauryagangrade:mainfrom
aryansk:test/ui-helpers

Conversation

@aryansk

@aryansk aryansk commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Closes #60.

Change

Expanded tests/test_ui.py from a single goodbye test to full coverage of the pure display logic:

  • _truncate: short text unchanged, whitespace normalization, limit boundary (exact limit has no ellipsis, over-limit appends ), empty string, non-string input.
  • _summarize_tool: execute_bash command branch, path branch, non-string path → empty, path wins over other args, empty args, long-value truncation.
  • _show_slash_menu: command extraction with a mocked questionary — selection returns the command, cancel (None) returns empty, KeyboardInterrupt returns empty; asserts the choices are derived from the slash-command table.
  • Streaming refresh handler: token()/assistant_start()/assistant_end() against a fake Live — no update below the 80-char threshold, one Markdown update on crossing it, final render + stop on end.
  • tool_start: renders the tool name and summarized args via a recorded console.

Acceptance criteria

  • Helpers and the menu are covered; the goodbye snapshot test still passes.
  • _truncate/_summarize_tool are exercised exhaustively (all branches).

Validation

  • tests/test_ui.py: 18 passed (17 new).
  • Full suite: 124 passed (17 new).
  • ruff check . clean, ruff format --check . clean, mypy gcode clean, bandit clean, git diff --check clean.

The test job already runs coverage and uploads .coverage artifacts, but no
one aggregates or publishes the numbers. Emit coverage.xml in the test job
and upload it with codecov/codecov-action (fail_ci_if_error: false so CI
stays green until the Codecov token or app is configured), gitignore the
generated file, and add the Codecov badge to the README next to the build
badge. Fixes shauryagangrade#64.
CI enforces ruff check/format and mypy, but there was no local hook, so
contributors only learned about violations after pushing. Add a
.pre-commit-config.yaml with local hooks that run the exact CI commands
(uv run ruff check ., uv run ruff format --check ., uv run mypy gcode),
add pre-commit to the dev extras, and document the one-line install in
CONTRIBUTING. Fixes shauryagangrade#58.
Add unit coverage for _truncate (whitespace normalization, limit
boundary, ellipsis), _summarize_tool (execute_bash/path/other-args
branches), the /-menu command extraction with a mocked questionary
(selection, cancel, KeyboardInterrupt), the streaming refresh handler
against a fake Live, and tool_start rendering. Fixes shauryagangrade#60.

@shauryagangrade shauryagangrade left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good test coverage of the ui.py helpers. I verified each case against the current implementation:

  • _truncate: whitespace-normalizing + ellipsis behavior matches gcode/ui.py:48.
  • _summarize_tool: execute_bash/path/truncation branches match gcode/ui.py:55.
  • _show_slash_menu: choice-label format and the /cmd extraction match gcode/ui.py:96.
  • Streaming refresh: the 80-char _TRUNCATE_STEP threshold and final Markdown render match assistant_start/token/assistant_end (gcode/ui.py:164-190).

Two structural notes:

  • Stacking: this PR's diff still contains the codecov changes from #84 and the pre-commit changes from #85. Once those merge, rebase onto main so the diff is just the tests.
  • Minor: test_token_renders_markdown_after_threshold is a good integration-style test, but consider also asserting the intermediate threshold doesn't re-render (e.g. exactly 80 then 81) to pin the _last_len reset behavior.

Approve — ready once you mark the PR ready for review.

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.

[Testing]: Unit tests for gcode/ui.py rendering helpers

2 participants