Skip to content

test: add vitest coverage for tool render modules#123

Open
clean6378-max-it wants to merge 1 commit into
masterfrom
test/renderer-behavioral-depth
Open

test: add vitest coverage for tool render modules#123
clean6378-max-it wants to merge 1 commit 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 rendering reliability across many tool views, including clearer fallback messages, better handling of missing data, and more consistent summaries.
    • Strengthened HTML escaping in rendered content to help prevent raw script or markup from appearing in the UI.
  • Tests

    • Added broad test coverage for core tool-use and tool-result renderers.
    • Added smoke tests to confirm each renderer produces expected output and key UI markers.
    • Tightened test coverage requirements.

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

📝 Walkthrough

Walkthrough

This PR adds a shared test helper module and extensive Vitest behavioral test suites for tool_use/tool_result renderers, expands registry.test.js with fixture-driven smoke tests, and raises coverage thresholds/exclusions 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 (XSS_SCRIPT, XSS_IMG), mountToolUse/mountToolResult wrappers around registry renderers, and expectNoRawHtml/expectEscaped assertion helpers.
Registry fixtures and smoke tests
static/js/render/registry.test.js
Adds TOOL_USE_FIXTURES/TOOL_RESULT_FIXTURES and loop-based smoke tests asserting every registered renderer returns valid non-empty HTML with expected markers.
tool_result renderer 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 verifying rendered summaries, default/missing-input handling, and HTML escaping for each result renderer.
tool_use renderer 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 verifying rendered content, optional-field handling, and HTML escaping for each use renderer.
Coverage config updates
vitest.config.js
Excludes test_helpers.js from coverage and raises lines/functions/branches thresholds.

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

Possibly related PRs

Suggested reviewers: timon0305, wpak-ai

🚥 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 is concise and accurately summarizes the main change: adding Vitest coverage for tool render modules.
Linked Issues check ✅ Passed The PR adds registry-driven behavioral tests, sanitization checks, and higher coverage thresholds for the renderer modules, matching the issue's core goals.
Out of Scope Changes check ✅ Passed The changes stay within renderer tests, shared helpers, registry coverage, and Vitest config; no unrelated code paths are introduced.
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 on lines +6 to +19
it('renders completed task with duration and token stats', () => {
const html = renderTaskResult({
result_type: 'task',
status: 'completed',
total_duration_ms: 2500,
total_tokens: 1500,
total_tool_use_count: 3,
});
expect(html).toContain('Task completed');
expect(html).toContain('2.5s');
expect(html).toContain('1,500 tokens');
expect(html).toContain('3 tool calls');
expect(html).toContain('tool-result');
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does Node.js Intl.NumberFormat / toLocaleString default to en-US regardless of OS locale in typical CI (GitHub Actions) environments?

💡 Result:

In typical CI environments like GitHub Actions, Node.js Intl.NumberFormat and toLocaleString do not necessarily default to en-US solely because of the OS locale [1][2][3]. Instead, their behavior is primarily dictated by the ICU (International Components for Unicode) data bundle included with the specific Node.js binary being used [4][2][3]. Many standard Node.js distributions, particularly smaller builds, are configured with 'small-icu' data, which includes only English-language locale data by default [3]. Consequently, even if your OS locale is set to something else, these environments will frequently fall back to en-US [1][2]. To ensure consistent behavior in CI environments, you should consider the following: 1. Locale-Aware Code: Always explicitly specify the locale in your Intl constructor or methods (e.g., new Intl.NumberFormat('en-GB',...)) rather than relying on the environment's default [2][5]. 2. Full ICU Data: If you require full internationalization support, ensure the Node.js environment is configured with 'full-icu' data [4][3]. This can often be achieved by installing the full-icu npm package and setting the NODE_ICU_DATA environment variable to point to that package's data file [4][2]. 3. Verify Environment: Use Intl.NumberFormat.resolvedOptions.locale to programmatically check the effective default locale in your CI environment at runtime [6][7]. Relying on the implicit host OS locale in CI is generally discouraged because it introduces environmental dependencies that can cause tests to pass locally but fail in CI, or vice-versa [1][2][8].

Citations:


Avoid locale-dependent token assertions. toLocaleString() follows the runtime’s default ICU locale, so hard-coding 1,500 tokens can make this test flaky across environments. Use a locale-agnostic expectation or build the string from (1500).toLocaleString() in the test.

🤖 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/task.test.js` around lines 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.

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

1 participant