Skip to content

test: add vitest coverage for tool render modules#123

Merged
wpak-ai merged 2 commits into
masterfrom
test/renderer-behavioral-depth
Jul 8, 2026
Merged

test: add vitest coverage for tool render modules#123
wpak-ai merged 2 commits into
masterfrom
test/renderer-behavioral-depth

Conversation

@clean6378-max-it

@clean6378-max-it clean6378-max-it commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #115

Summary

Adds vitest files for the remaining registered renderers in tool_use/ and tool_result/. We had five test files covering a small slice of 32 render modules; now every registered renderer has at least one behavioral test.

test_helpers.js wraps renderToolUse / renderToolResult and gives a consistent way to check that raw HTML does not leak through. Most tests also cover empty or malformed input.

registry.test.js runs representative fixtures through every entry in TOOL_USE_RENDERERS and TOOL_RESULT_RENDERERS.

Coverage thresholds in vitest.config.js move from 80/70/50 to 85/75/55.

Test plan

  • npm test (156 passing, up from 93)
  • npm run test:coverage (tool_result/ and tool_use/ both around 99%)
  • Spot-check a session with Bash, Read, Task, Grep tool cards in the UI

Week 28 item #3. Wednesday PR 2 (adversarial dispatch fixtures) is separate.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of tool-use and tool-result rendering, including clearer “unknown” fallback messages and more graceful handling of missing fields (e.g., file paths, queries, counts).
    • Strengthened HTML escaping across tool inputs and outputs to prevent raw scripts/markup from appearing in the UI.
  • Tests

    • Expanded renderer test coverage with shared XSS/escaping assertions and dedicated suites for many tool types.
    • Added registry consistency smoke tests and tightened coverage thresholds.

Add per-renderer vitest coverage with XSS escaping assertions, a shared
test helper, registry-driven smoke tests, and raised coverage thresholds.
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e49cc724-80f4-4339-9e65-3cb4991eb31b

📥 Commits

Reviewing files that changed from the base of the PR and between 9126909 and 34d5b37.

📒 Files selected for processing (20)
  • static/js/render/registry.test.js
  • static/js/render/test_helpers.js
  • static/js/render/tool_result/bash.test.js
  • static/js/render/tool_result/fallback.test.js
  • static/js/render/tool_result/file_edit.test.js
  • static/js/render/tool_result/file_write.test.js
  • static/js/render/tool_result/plan.test.js
  • static/js/render/tool_result/task.test.js
  • static/js/render/tool_result/todo_write.test.js
  • static/js/render/tool_result/user_input.test.js
  • static/js/render/tool_result/web_fetch.test.js
  • static/js/render/tool_result/web_search.test.js
  • static/js/render/tool_use/ask_user_question.test.js
  • static/js/render/tool_use/fallback.test.js
  • static/js/render/tool_use/glob.test.js
  • static/js/render/tool_use/grep.test.js
  • static/js/render/tool_use/read.test.js
  • static/js/render/tool_use/task.test.js
  • static/js/render/tool_use/todo_write.test.js
  • static/js/render/tool_use/write.test.js
🚧 Files skipped from review as they are similar to previous changes (16)
  • static/js/render/tool_use/fallback.test.js
  • static/js/render/tool_result/file_write.test.js
  • static/js/render/tool_result/web_fetch.test.js
  • static/js/render/tool_use/ask_user_question.test.js
  • static/js/render/tool_use/glob.test.js
  • static/js/render/tool_result/fallback.test.js
  • static/js/render/tool_result/task.test.js
  • static/js/render/tool_use/grep.test.js
  • static/js/render/tool_result/web_search.test.js
  • static/js/render/tool_result/user_input.test.js
  • static/js/render/tool_use/read.test.js
  • static/js/render/tool_use/todo_write.test.js
  • static/js/render/tool_result/bash.test.js
  • static/js/render/tool_use/task.test.js
  • static/js/render/tool_use/write.test.js
  • static/js/render/tool_result/todo_write.test.js

📝 Walkthrough

Walkthrough

This PR adds shared renderer test helpers, registry consistency and smoke tests, broad Vitest coverage for tool_use and tool_result renderers, and updated coverage settings in vitest.config.js.

Changes

Renderer Behavioral Test Coverage

Layer / File(s) Summary
Shared test helper module
static/js/render/test_helpers.js
Adds XSS payload constants, HTML assertion helpers, and a shared summary-only result suite helper.
Registry fixtures and smoke tests
static/js/render/registry.test.js
Adds registry alignment checks, representative fixtures, and render-smoke tests for core tool-use and tool-result entries.
tool_result renderer behavioral tests
static/js/render/tool_result/bash.test.js, fallback.test.js, file_edit.test.js, file_write.test.js, glob.test.js, grep.test.js, plan.test.js, task.test.js, todo_write.test.js, user_input.test.js, web_fetch.test.js, web_search.test.js
Adds behavioral suites covering expected rendering, default/missing input handling, and escaping for result renderers.
tool_use renderer behavioral tests
static/js/render/tool_use/ask_user_question.test.js, fallback.test.js, glob.test.js, grep.test.js, read.test.js, task.test.js, todo_write.test.js, write.test.js
Adds behavioral suites covering expected rendering, optional-field handling, and escaping for use renderers.
Coverage config updates
vitest.config.js
Excludes test_helpers.js from coverage and raises the configured thresholds.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: timon0305

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding Vitest coverage for tool render modules.
Linked Issues check ✅ Passed The PR adds behavioral Vitest coverage across most tool_use/tool_result renderers, includes sanitization and edge-case checks, extends registry tests, and raises coverage thresholds.
Out of Scope Changes check ✅ Passed The changes stay focused on renderer tests, shared helpers, registry smoke checks, and coverage config; no unrelated feature work stands out.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/renderer-behavioral-depth

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
static/js/render/tool_result/file_edit.test.js (1)

1-29: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider a shared test factory for summary-only renderers.

This file and plan.test.js follow an identical three-test pattern (render field, missing field defaults, XSS escape) for renderers that just build a "<Label>: <field>" summary via finishToolResult. A small parametrized helper (e.g., testSummaryOnlyRenderer(name, renderFn, field, label)) could reduce duplication if more such renderers are added later.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@static/js/render/tool_result/file_edit.test.js` around lines 1 - 29, The
tests in renderFileEditResult duplicate the same three-case pattern used by
other summary-only renderers, so extract a shared parametrized test helper for
this shape. Create a reusable factory (for example, around mountToolResult,
expectNoRawHtml, and the renderer under test) that accepts the render function,
field name, and label, then use it from file_edit.test.js and plan.test.js to
cover summary, missing-field default, and XSS escaping consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@static/js/render/tool_result/task.test.js`:
- Around line 6-19: The completed-task rendering test is asserting a
locale-specific token string, which can vary across environments. Update the
`renderTaskResult` test to avoid hard-coding the formatted token value in the
`renders completed task with duration and token stats` case, and instead compare
against a locale-agnostic expectation or derive the expected text using
`toLocaleString()` from the same numeric value.

---

Nitpick comments:
In `@static/js/render/tool_result/file_edit.test.js`:
- Around line 1-29: The tests in renderFileEditResult duplicate the same
three-case pattern used by other summary-only renderers, so extract a shared
parametrized test helper for this shape. Create a reusable factory (for example,
around mountToolResult, expectNoRawHtml, and the renderer under test) that
accepts the render function, field name, and label, then use it from
file_edit.test.js and plan.test.js to cover summary, missing-field default, and
XSS escaping consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 759aa381-9776-4d07-9d03-ffacba6ed9a2

📥 Commits

Reviewing files that changed from the base of the PR and between a725bd2 and 9126909.

📒 Files selected for processing (23)
  • static/js/render/registry.test.js
  • static/js/render/test_helpers.js
  • static/js/render/tool_result/bash.test.js
  • static/js/render/tool_result/fallback.test.js
  • static/js/render/tool_result/file_edit.test.js
  • static/js/render/tool_result/file_write.test.js
  • static/js/render/tool_result/glob.test.js
  • static/js/render/tool_result/grep.test.js
  • static/js/render/tool_result/plan.test.js
  • static/js/render/tool_result/task.test.js
  • static/js/render/tool_result/todo_write.test.js
  • static/js/render/tool_result/user_input.test.js
  • static/js/render/tool_result/web_fetch.test.js
  • static/js/render/tool_result/web_search.test.js
  • static/js/render/tool_use/ask_user_question.test.js
  • static/js/render/tool_use/fallback.test.js
  • static/js/render/tool_use/glob.test.js
  • static/js/render/tool_use/grep.test.js
  • static/js/render/tool_use/read.test.js
  • static/js/render/tool_use/task.test.js
  • static/js/render/tool_use/todo_write.test.js
  • static/js/render/tool_use/write.test.js
  • vitest.config.js

Comment thread static/js/render/tool_result/task.test.js
Comment thread static/js/render/registry.test.js
Comment thread static/js/render/registry.test.js
Comment thread static/js/render/registry.test.js
Comment thread static/js/render/registry.test.js
Comment thread static/js/render/test_helpers.js Outdated
Comment thread static/js/render/test_helpers.js Outdated
@clean6378-max-it clean6378-max-it requested a review from wpak-ai July 8, 2026 17:16
@wpak-ai wpak-ai merged commit 46ae6f0 into master Jul 8, 2026
16 checks passed
@wpak-ai wpak-ai deleted the test/renderer-behavioral-depth branch July 8, 2026 17:55
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.

claude-code-chat-browser: Renderer behavioral test depth for tool_result and tool_use modules

3 participants