From b61f149b6dc8ec7f4e4f6be81e16ef9ad573ff75 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 19 Mar 2026 16:44:14 +0000 Subject: [PATCH 1/2] test: add assertion gaps for cost-view grand totals and summary date range (#126) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add three new tests to close assertion gaps identified in issue #126: - test_resumed_session_grand_output_includes_historical_and_active: Dedicated test that grand output tokens = historical + active for resumed sessions (1000 + 200 = 1200 → "1.2K"). - test_mixed_sessions_grand_total: Verifies grand output sums metrics-output from a completed session plus active_output from an active-no-metrics session (2000 + 500 = 2500 → "2.5K"). - test_summary_header_single_session_same_date_both_ends: Asserts that with a single session the date appears on both ends of the date range subtitle. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/copilot_usage/test_report.py | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/copilot_usage/test_report.py b/tests/copilot_usage/test_report.py index 0b16ca5..0a51ebf 100644 --- a/tests/copilot_usage/test_report.py +++ b/tests/copilot_usage/test_report.py @@ -1023,6 +1023,12 @@ def test_summary_header_date_range_order_is_min_max(self) -> None: output = _capture_summary(sessions) assert "2025-01-01 → 2025-12-31" in output + def test_summary_header_single_session_same_date_both_ends(self) -> None: + """With a single session, earliest and latest are the same date.""" + s = _make_summary_session(start_time=datetime(2026, 3, 7, tzinfo=UTC)) + output = _capture_summary([s]) + assert output.count("2026-03-07") >= 2 # appears in both ends of range + def test_summary_header_no_start_times(self) -> None: """Sessions with no start_time → 'no sessions' subtitle (line 533).""" session = SessionSummary(session_id="no-time", start_time=None) @@ -1435,6 +1441,60 @@ def test_pure_active_no_metrics_grand_total_includes_active_tokens(self) -> None # 1500 output tokens → formatted as "1.5K" assert "1.5K" in output + def test_resumed_session_grand_output_includes_historical_and_active( + self, + ) -> None: + """Grand total output tokens = historical (from metrics) + active.""" + session = SessionSummary( + session_id="resume-out-1234", + name="Resumed", + model="claude-opus-4.6", + start_time=datetime(2025, 1, 15, 10, 0, tzinfo=UTC), + is_active=True, + model_calls=10, + active_model_calls=3, + active_output_tokens=200, + model_metrics={ + "claude-opus-4.6": ModelMetrics( + requests=RequestMetrics(count=7, cost=21), + usage=TokenUsage(outputTokens=1000), + ) + }, + ) + output = _capture_cost_view([session]) + # 1000 historical + 200 active = 1200 → "1.2K" + assert "1.2K" in output + + def test_mixed_sessions_grand_total(self) -> None: + """Grand total sums metrics-output from completed + active_output from active-no-metrics.""" + completed = SessionSummary( + session_id="comp-aaaa-111111", + name="Done", + model="claude-sonnet-4", + start_time=datetime(2025, 1, 10, tzinfo=UTC), + is_active=False, + model_calls=5, + model_metrics={ + "claude-sonnet-4": ModelMetrics( + requests=RequestMetrics(count=5, cost=5), + usage=TokenUsage(outputTokens=2000), + ) + }, + ) + active = SessionSummary( + session_id="actv-bbbb-222222", + name="Running", + model="claude-opus-4.6", + start_time=datetime(2025, 1, 15, tzinfo=UTC), + is_active=True, + model_calls=3, + active_model_calls=3, + active_output_tokens=500, + ) + output = _capture_cost_view([completed, active]) + # 2000 + 500 = 2500 → "2.5K" + assert "2.5K" in output + class TestRenderFullSummaryHelperReuse: """Verify _render_historical_section delegates to shared table helpers.""" From ac563f78573142b6bc5d04065fe9b86cc156eb36 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 19 Mar 2026 16:54:32 +0000 Subject: [PATCH 2/2] fix: address review comments - Remove duplicate test_resumed_session_grand_output_includes_historical_and_active (already covered by test_resumed_session_no_double_count) - Move test_summary_header_single_session_same_date_both_ends to TestRenderSummary class to match PR description Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/copilot_usage/test_report.py | 36 +++++------------------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/tests/copilot_usage/test_report.py b/tests/copilot_usage/test_report.py index 0a51ebf..956a9c8 100644 --- a/tests/copilot_usage/test_report.py +++ b/tests/copilot_usage/test_report.py @@ -835,6 +835,12 @@ def test_zero_tokens_session(self) -> None: assert "Copilot Usage Summary" in output assert "0s" in output + def test_summary_header_single_session_same_date_both_ends(self) -> None: + """With a single session, earliest and latest are the same date.""" + s = _make_summary_session(start_time=datetime(2026, 3, 7, tzinfo=UTC)) + output = _capture_summary([s]) + assert output.count("2026-03-07") >= 2 # appears in both ends of range + # --------------------------------------------------------------------------- # Coverage gap tests — report.py @@ -1023,12 +1029,6 @@ def test_summary_header_date_range_order_is_min_max(self) -> None: output = _capture_summary(sessions) assert "2025-01-01 → 2025-12-31" in output - def test_summary_header_single_session_same_date_both_ends(self) -> None: - """With a single session, earliest and latest are the same date.""" - s = _make_summary_session(start_time=datetime(2026, 3, 7, tzinfo=UTC)) - output = _capture_summary([s]) - assert output.count("2026-03-07") >= 2 # appears in both ends of range - def test_summary_header_no_start_times(self) -> None: """Sessions with no start_time → 'no sessions' subtitle (line 533).""" session = SessionSummary(session_id="no-time", start_time=None) @@ -1441,30 +1441,6 @@ def test_pure_active_no_metrics_grand_total_includes_active_tokens(self) -> None # 1500 output tokens → formatted as "1.5K" assert "1.5K" in output - def test_resumed_session_grand_output_includes_historical_and_active( - self, - ) -> None: - """Grand total output tokens = historical (from metrics) + active.""" - session = SessionSummary( - session_id="resume-out-1234", - name="Resumed", - model="claude-opus-4.6", - start_time=datetime(2025, 1, 15, 10, 0, tzinfo=UTC), - is_active=True, - model_calls=10, - active_model_calls=3, - active_output_tokens=200, - model_metrics={ - "claude-opus-4.6": ModelMetrics( - requests=RequestMetrics(count=7, cost=21), - usage=TokenUsage(outputTokens=1000), - ) - }, - ) - output = _capture_cost_view([session]) - # 1000 historical + 200 active = 1200 → "1.2K" - assert "1.2K" in output - def test_mixed_sessions_grand_total(self) -> None: """Grand total sums metrics-output from completed + active_output from active-no-metrics.""" completed = SessionSummary(