Skip to content

test: add coverage for render_detail private helpers (#879)#882

Merged
microsasa merged 2 commits intomainfrom
fix/879-render-detail-test-coverage-16aec4ca8168955f
Apr 9, 2026
Merged

test: add coverage for render_detail private helpers (#879)#882
microsasa merged 2 commits intomainfrom
fix/879-render-detail-test-coverage-16aec4ca8168955f

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #879

Adds direct unit tests for four previously-untested private helpers in render_detail.py:

New test classes

Class Covers Tests
TestFormatRelativeTime _format_relative_time sub-hour +M:SS, over-hour +H:MM:SS, negative delta clamped to +0:00, zero, exact 1h boundary
TestRenderActivePeriod _render_active_period active session renders panel with stats; inactive session produces no output
TestRenderSessionDetailActivePeriod Integration render_session_detail with is_active=True includes Active Period panel
TestEventTypeLabel _event_type_label parametrized over USER_MESSAGE, ASSISTANT_MESSAGE, TOOL_EXECUTION_COMPLETE, SESSION_SHUTDOWN, and unknown wildcard branch
TestBuildEventDetailsUserMessage _build_event_details USER_MESSAGE branch content returned as-is, long content truncated with , empty content returns ""

Cleanup

Removed redundant local from copilot_usage.render_detail import _build_event_details imports in TestBuildEventDetailsToolRequests — the function is now imported at module level alongside the other private helpers.

Verification

make check passes cleanly: lint ✅ · typecheck ✅ · security ✅ · unit tests (99% coverage) ✅ · e2e tests ✅

Generated by Issue Implementer · ● 7.9M ·

Add direct unit tests for _format_relative_time, _render_active_period,
_event_type_label, and the USER_MESSAGE branch of _build_event_details.

- TestFormatRelativeTime: sub-hour, over-hour, negative-clamped, zero,
  and exact-one-hour branches
- TestRenderActivePeriod: active panel rendered / inactive produces
  no output
- TestRenderSessionDetailActivePeriod: integration test verifying
  Active Period panel appears in full render_session_detail output
- TestEventTypeLabel: parametrized over known event types plus the
  wildcard branch for unknown types
- TestBuildEventDetailsUserMessage: content returned, long content
  truncated with ellipsis, empty content returns empty string

Also removes redundant local imports of _build_event_details in
TestBuildEventDetailsToolRequests (now imported at module level).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa added the aw Created by agentic workflow label Apr 9, 2026
Copilot AI review requested due to automatic review settings April 9, 2026 09:56
@microsasa microsasa enabled auto-merge April 9, 2026 09:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds direct unit test coverage for previously untested private helpers in src/copilot_usage/render_detail.py, increasing confidence in session-detail rendering behavior and guarding key formatting/labeling branches.

Changes:

  • Added unit tests for _format_relative_time, _render_active_period, _event_type_label, and the USER_MESSAGE branch of _build_event_details.
  • Added an integration test ensuring render_session_detail(..., is_active=True) includes the Active Period panel.
  • Cleaned up redundant local imports by importing private helpers at module scope.

- Strip ANSI from Rich output before asserting specific substrings
  ("3 model calls", "2 user messages") instead of bare digits
- Extend _event_type_label parametrization to cover all match cases
  (added TOOL_EXECUTION_START, ASSISTANT_TURN_START/END, SESSION_START)
- Fix-forward: apply _strip_ansi consistently in integration test too

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Commit pushed: 38d9408

Generated by Review Responder

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@microsasa microsasa added the aw-quality-gate-approved Quality gate approved the PR label Apr 9, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Quality Gate: APPROVED

Impact: LOW — Test-only change (1 file, 156 additions, 12 deletions in tests/copilot_usage/test_render_detail.py).

What was evaluated:

  • 5 new test classes covering _format_relative_time, _render_active_period, _event_type_label, and _build_event_details (USER_MESSAGE branch)
  • Tests exercise meaningful edge cases: negative delta clamping, hour boundary, content truncation, empty/unknown inputs
  • Import cleanup removes 6 redundant local imports in favor of module-level imports
  • All 10 CI checks pass (lint, typecheck, security, unit tests, CodeQL)
  • Code follows repository conventions: type annotations, docstrings, pytest patterns, ruff formatting

Low-impact test addition with good coverage. Auto-approving for merge.

@microsasa microsasa merged commit d04b63d into main Apr 9, 2026
10 checks passed
@microsasa microsasa deleted the fix/879-render-detail-test-coverage-16aec4ca8168955f branch April 9, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow aw-quality-gate-approved Quality gate approved the PR

Projects

None yet

2 participants