Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/copilot_usage/test_render_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,37 @@ def test_active_session_shows_active_period_panel(self) -> None:
output = _strip_ansi(buf.getvalue())
assert "Active Period" in output

def test_pure_active_session_aggregate_stats_token_count(self) -> None:
"""render_session_detail Aggregate Stats panel shows correct (non-doubled) tokens."""
summary = SessionSummary(
session_id="pure-active-e2e-tok",
start_time=datetime(2026, 4, 1, 10, 0, 0, tzinfo=UTC),
is_active=True,
has_shutdown_metrics=False,
model_calls=2,
user_messages=1,
active_model_calls=2,
active_user_messages=1,
active_output_tokens=500,
model_metrics={
"claude-sonnet-4": ModelMetrics(
usage=TokenUsage(outputTokens=500),
)
},
)
ev = SessionEvent(
type=EventType.USER_MESSAGE,
timestamp=datetime(2026, 4, 1, 10, 5, 0, tzinfo=UTC),
data={"content": "test"},
)
buf, console = _buf_console()
render_session_detail([ev], summary, target_console=console)
output = _strip_ansi(buf.getvalue())

assert "Aggregate Stats" in output
assert "500" in output
assert "1000" not in output # double-count must not appear
Comment on lines +880 to +882


# ---------------------------------------------------------------------------
# _event_type_label — parametrized unit tests (issue #879)
Expand Down
27 changes: 27 additions & 0 deletions tests/copilot_usage/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,33 @@ def test_api_duration_formatted(self) -> None:
output = _capture_console(_render_aggregate_stats, summary)
assert "1m" in output

def test_pure_active_session_output_tokens_not_double_counted(self) -> None:
"""Pure-active session: Aggregate Stats shows model_metrics tokens, not 2× that value."""
summary = SessionSummary(
session_id="pure-active-agg",
is_active=True,
has_shutdown_metrics=False,
model_calls=4,
user_messages=3,
active_model_calls=4,
active_user_messages=3,
active_output_tokens=800,
model_metrics={
"gpt-4": ModelMetrics(
usage=TokenUsage(outputTokens=800),
)
},
)

output = _capture_console(_render_aggregate_stats, summary)

# Should show 800, NOT 1600 (double-count)
assert "800" in output, "Expected 800 output tokens in Aggregate Stats"
assert "1600" not in output, "Double-counted token value must not appear"
assert (
"1.6K" not in output
), "Double-counted token value must not appear as formatted K value"


# ---------------------------------------------------------------------------
# format_tokens tests
Expand Down
Loading