test: add coverage for render_detail private helpers (#879)#882
Merged
test: add coverage for render_detail private helpers (#879)#882
Conversation
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>
There was a problem hiding this comment.
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 theUSER_MESSAGEbranch 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>
Contributor
|
Commit pushed:
|
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #879
Adds direct unit tests for four previously-untested private helpers in
render_detail.py:New test classes
TestFormatRelativeTime_format_relative_time+M:SS, over-hour+H:MM:SS, negative delta clamped to+0:00, zero, exact 1h boundaryTestRenderActivePeriod_render_active_periodTestRenderSessionDetailActivePeriodrender_session_detailwithis_active=Trueincludes Active Period panelTestEventTypeLabel_event_type_labelUSER_MESSAGE,ASSISTANT_MESSAGE,TOOL_EXECUTION_COMPLETE,SESSION_SHUTDOWN, and unknown wildcard branchTestBuildEventDetailsUserMessage_build_event_detailsUSER_MESSAGE branch…, empty content returns""Cleanup
Removed redundant local
from copilot_usage.render_detail import _build_event_detailsimports inTestBuildEventDetailsToolRequests— the function is now imported at module level alongside the other private helpers.Verification
make checkpasses cleanly: lint ✅ · typecheck ✅ · security ✅ · unit tests (99% coverage) ✅ · e2e tests ✅