From 60582b06a0b25fe49f88d445f0c01e989dc19d0c Mon Sep 17 00:00:00 2001 From: Sasa Junuzovic <44276455+microsasa@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:17:40 -0700 Subject: [PATCH 1/6] test(render_detail): cover untested _build_event_details branches (#860) Add tests for two uncovered branches in _build_event_details: - SESSION_SHUTDOWN with shutdownType=None returning empty string - TOOL_EXECUTION_COMPLETE with non-None model field in detail string Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/copilot_usage/test_render_detail.py | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/copilot_usage/test_render_detail.py b/tests/copilot_usage/test_render_detail.py index 186c7498..55125291 100644 --- a/tests/copilot_usage/test_render_detail.py +++ b/tests/copilot_usage/test_render_detail.py @@ -608,3 +608,40 @@ def test_multi_model_shutdown_via_full_render(self) -> None: row = next(line for line in output.splitlines() if "2025-01-01 01:00" in line) assert re.search(r"\b7\b", row) # total model calls = 3 + 4 assert re.search(r"\b800\b", row) # total output tokens = 500 + 300 + + +# --------------------------------------------------------------------------- +# Issue #860 — untested branches in _build_event_details +# --------------------------------------------------------------------------- + + +class TestBuildEventDetailsUntestedBranches: + """Cover the two branches in _build_event_details that had zero test + coverage: SESSION_SHUTDOWN with falsy shutdownType and + TOOL_EXECUTION_COMPLETE with a non-None model field.""" + + def test_session_shutdown_none_shutdown_type_returns_empty(self) -> None: + """SESSION_SHUTDOWN with shutdownType=None must return ''.""" + from copilot_usage.render_detail import _build_event_details + + ev = SessionEvent( + type=EventType.SESSION_SHUTDOWN, + data={"totalPremiumRequests": 0, "totalApiDurationMs": 0}, + ) + detail = _build_event_details(ev) + assert detail == "" + + def test_tool_execution_complete_with_model(self) -> None: + """TOOL_EXECUTION_COMPLETE with model set must include 'model=...'.""" + from copilot_usage.render_detail import _build_event_details + + ev = SessionEvent( + type=EventType.TOOL_EXECUTION_COMPLETE, + data={ + "toolCallId": "tc1", + "model": "claude-sonnet-4", + "success": True, + }, + ) + detail = _build_event_details(ev) + assert "model=claude-sonnet-4" in detail From d02d67d3d0439422383684c56dfcc2ba2afdcbb7 Mon Sep 17 00:00:00 2001 From: Sasa Junuzovic <44276455+microsasa@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:25:15 -0700 Subject: [PATCH 2/6] fix: address review comments Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/copilot_usage/test_render_detail.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/copilot_usage/test_render_detail.py b/tests/copilot_usage/test_render_detail.py index 55125291..7b52dc9b 100644 --- a/tests/copilot_usage/test_render_detail.py +++ b/tests/copilot_usage/test_render_detail.py @@ -617,16 +617,20 @@ def test_multi_model_shutdown_via_full_render(self) -> None: class TestBuildEventDetailsUntestedBranches: """Cover the two branches in _build_event_details that had zero test - coverage: SESSION_SHUTDOWN with falsy shutdownType and + coverage: SESSION_SHUTDOWN with empty shutdownType and TOOL_EXECUTION_COMPLETE with a non-None model field.""" - def test_session_shutdown_none_shutdown_type_returns_empty(self) -> None: - """SESSION_SHUTDOWN with shutdownType=None must return ''.""" + def test_session_shutdown_empty_shutdown_type_returns_empty(self) -> None: + """SESSION_SHUTDOWN with shutdownType='' must return ''.""" from copilot_usage.render_detail import _build_event_details ev = SessionEvent( type=EventType.SESSION_SHUTDOWN, - data={"totalPremiumRequests": 0, "totalApiDurationMs": 0}, + data={ + "shutdownType": "", + "totalPremiumRequests": 0, + "totalApiDurationMs": 0, + }, ) detail = _build_event_details(ev) assert detail == "" From f693d2b407041c2cff4321fd3e556b9ff0d987ed Mon Sep 17 00:00:00 2001 From: Sasa Junuzovic <44276455+microsasa@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:34:33 -0700 Subject: [PATCH 3/6] fix: address review comments Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/copilot_usage/test_render_detail.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/tests/copilot_usage/test_render_detail.py b/tests/copilot_usage/test_render_detail.py index 7b52dc9b..3e87022a 100644 --- a/tests/copilot_usage/test_render_detail.py +++ b/tests/copilot_usage/test_render_detail.py @@ -611,29 +611,12 @@ def test_multi_model_shutdown_via_full_render(self) -> None: # --------------------------------------------------------------------------- -# Issue #860 — untested branches in _build_event_details +# Issue #860 — untested branch in _build_event_details # --------------------------------------------------------------------------- class TestBuildEventDetailsUntestedBranches: - """Cover the two branches in _build_event_details that had zero test - coverage: SESSION_SHUTDOWN with empty shutdownType and - TOOL_EXECUTION_COMPLETE with a non-None model field.""" - - def test_session_shutdown_empty_shutdown_type_returns_empty(self) -> None: - """SESSION_SHUTDOWN with shutdownType='' must return ''.""" - from copilot_usage.render_detail import _build_event_details - - ev = SessionEvent( - type=EventType.SESSION_SHUTDOWN, - data={ - "shutdownType": "", - "totalPremiumRequests": 0, - "totalApiDurationMs": 0, - }, - ) - detail = _build_event_details(ev) - assert detail == "" + """Cover the remaining _build_event_details branch unique to this module.""" def test_tool_execution_complete_with_model(self) -> None: """TOOL_EXECUTION_COMPLETE with model set must include 'model=...'.""" From 9d397cae9a4490da1a2117dfb5ef1f4216ba5bfc Mon Sep 17 00:00:00 2001 From: Sasa Junuzovic <44276455+microsasa@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:44:52 -0700 Subject: [PATCH 4/6] fix: address review comments - Remove redundant test_tool_execution_complete_with_model (already covered by test_report.py::test_tool_execution_shows_name_and_success) - Add missing test_session_shutdown_falsy_shutdown_type to cover the else branch returning empty string when shutdownType is falsy Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/copilot_usage/test_render_detail.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/copilot_usage/test_render_detail.py b/tests/copilot_usage/test_render_detail.py index 3e87022a..93b9432e 100644 --- a/tests/copilot_usage/test_render_detail.py +++ b/tests/copilot_usage/test_render_detail.py @@ -616,19 +616,15 @@ def test_multi_model_shutdown_via_full_render(self) -> None: class TestBuildEventDetailsUntestedBranches: - """Cover the remaining _build_event_details branch unique to this module.""" + """Cover the SESSION_SHUTDOWN falsy-shutdownType branch in _build_event_details.""" - def test_tool_execution_complete_with_model(self) -> None: - """TOOL_EXECUTION_COMPLETE with model set must include 'model=...'.""" + def test_session_shutdown_falsy_shutdown_type(self) -> None: + """SESSION_SHUTDOWN with no shutdownType returns empty string.""" from copilot_usage.render_detail import _build_event_details ev = SessionEvent( - type=EventType.TOOL_EXECUTION_COMPLETE, - data={ - "toolCallId": "tc1", - "model": "claude-sonnet-4", - "success": True, - }, + type=EventType.SESSION_SHUTDOWN, + data={}, ) detail = _build_event_details(ev) - assert "model=claude-sonnet-4" in detail + assert detail == "" From 2c1cbcb79b856c5b6ea6ea5e3d979635b8bcdfbe Mon Sep 17 00:00:00 2001 From: Sasa Junuzovic <44276455+microsasa@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:56:00 -0700 Subject: [PATCH 5/6] fix: address review comments - Remove duplicate SESSION_SHUTDOWN test already covered in test_report.py - Add TOOL_EXECUTION_COMPLETE with model field test (was promised in PR description but missing from changeset) - Move _build_event_details import to module-level imports Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/copilot_usage/test_render_detail.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/copilot_usage/test_render_detail.py b/tests/copilot_usage/test_render_detail.py index 93b9432e..db90997b 100644 --- a/tests/copilot_usage/test_render_detail.py +++ b/tests/copilot_usage/test_render_detail.py @@ -22,6 +22,7 @@ ToolTelemetry, ) from copilot_usage.render_detail import ( + _build_event_details, _extract_tool_name, _render_code_changes, _render_recent_events, @@ -616,15 +617,20 @@ def test_multi_model_shutdown_via_full_render(self) -> None: class TestBuildEventDetailsUntestedBranches: - """Cover the SESSION_SHUTDOWN falsy-shutdownType branch in _build_event_details.""" - - def test_session_shutdown_falsy_shutdown_type(self) -> None: - """SESSION_SHUTDOWN with no shutdownType returns empty string.""" - from copilot_usage.render_detail import _build_event_details + """Cover the TOOL_EXECUTION_COMPLETE truthy-model branch in _build_event_details.""" + def test_tool_execution_complete_with_model(self) -> None: + """TOOL_EXECUTION_COMPLETE with model field includes model= in detail.""" ev = SessionEvent( - type=EventType.SESSION_SHUTDOWN, - data={}, + type=EventType.TOOL_EXECUTION_COMPLETE, + data={ + "toolCallId": "t1", + "success": True, + "model": "claude-sonnet-4", + "toolTelemetry": {"properties": {"tool_name": "bash"}}, + }, ) detail = _build_event_details(ev) - assert detail == "" + assert "model=claude-sonnet-4" in detail + assert "bash" in detail + assert "✓" in detail From 3aeb7ea905091101ec65c64da414542c5ebadffc Mon Sep 17 00:00:00 2001 From: Sasa Junuzovic <44276455+microsasa@users.noreply.github.com> Date: Wed, 8 Apr 2026 11:06:51 -0700 Subject: [PATCH 6/6] fix: address review comments Add the missing SESSION_SHUTDOWN test that was mentioned in the PR description but not included. Update class docstring to accurately reflect both covered branches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/copilot_usage/test_render_detail.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/copilot_usage/test_render_detail.py b/tests/copilot_usage/test_render_detail.py index db90997b..a60fe4eb 100644 --- a/tests/copilot_usage/test_render_detail.py +++ b/tests/copilot_usage/test_render_detail.py @@ -617,7 +617,20 @@ def test_multi_model_shutdown_via_full_render(self) -> None: class TestBuildEventDetailsUntestedBranches: - """Cover the TOOL_EXECUTION_COMPLETE truthy-model branch in _build_event_details.""" + """Cover untested branches in _build_event_details: + + 1. SESSION_SHUTDOWN with falsy shutdownType → returns "". + 2. TOOL_EXECUTION_COMPLETE with truthy model → includes model=. + """ + + def test_session_shutdown_with_falsy_shutdown_type(self) -> None: + """SESSION_SHUTDOWN with shutdownType='' returns empty string.""" + ev = SessionEvent( + type=EventType.SESSION_SHUTDOWN, + data={"totalPremiumRequests": 5}, + ) + detail = _build_event_details(ev) + assert detail == "" def test_tool_execution_complete_with_model(self) -> None: """TOOL_EXECUTION_COMPLETE with model field includes model= in detail."""