Skip to content

test: exercise duration_by_model absent-key fallback (#869)#871

Merged
microsasa merged 3 commits intomainfrom
fix/869-test-absent-duration-key-18e059a630d638db
Apr 8, 2026
Merged

test: exercise duration_by_model absent-key fallback (#869)#871
microsasa merged 3 commits intomainfrom
fix/869-test-absent-duration-key-18e059a630d638db

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #869

Summary

The .get(model, 0) fallback in render_vscode_summary was never exercised by tests — every existing test in TestRenderVscodeSummaryPerModelTable supplied matching keys in both requests_by_model and duration_by_model.

Changes

Added two tests to TestRenderVscodeSummaryPerModelTable in tests/copilot_usage/test_vscode_report.py:

  • test_per_model_table_absent_duration_defaults_to_zero_avg — a single model present in requests_by_model but completely absent from duration_by_model; verifies no exception and 0ms avg output.
  • test_per_model_table_partial_duration_dict — two models in requests_by_model, only one in duration_by_model; verifies the known model shows correct avg (500ms) and the absent one shows 0ms.

Both tests will fail with KeyError if the defensive .get(model, 0) is ever replaced with a direct subscript, catching the regression immediately.

Verification

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

Generated by Issue Implementer · ● 2.5M ·

Add two tests to TestRenderVscodeSummaryPerModelTable that verify the
.get(model, 0) guard in render_vscode_summary when a model appears in
requests_by_model but is missing from duration_by_model:

- test_per_model_table_absent_duration_defaults_to_zero_avg
- test_per_model_table_partial_duration_dict

These catch regressions if the defensive fallback is accidentally removed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa added the aw Created by agentic workflow label Apr 8, 2026
@microsasa microsasa enabled auto-merge April 8, 2026 20:44
Copilot AI review requested due to automatic review settings April 8, 2026 20:44
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 regression tests to ensure render_vscode_summary safely handles models that appear in requests_by_model but are missing from duration_by_model (exercising the .get(model, 0) fallback).

Changes:

  • Added a test for the fully absent duration_by_model case (defaults to 0ms).
  • Added a test for a partially populated duration_by_model where only some models have duration entries.

- Make test assertions target specific model rows instead of matching
  anywhere in the output, preventing false passes from incidental
  matches in the totals panel or other columns.
- Set total_duration_ms to non-zero values to avoid ambiguous 0ms
  matches.
- Apply same fix to pre-existing test_avg_ms_division_by_zero_guard
  which had the same class of issue (fix-forward).

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

github-actions bot commented Apr 8, 2026

Commit pushed: 2fe7ac5

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 2 comments.

@microsasa microsasa added the aw-review-response-attempted Responder has attempted to address review comments label Apr 8, 2026
- Use regex word-boundary assertion for standalone '0ms' check to avoid
  matching '0ms' inside '100ms' (line 177)
- Assert '500ms' count==2 to verify avg and total columns independently
  rather than relying on ambiguous substring match (line 220)

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

github-actions bot commented Apr 8, 2026

Commit pushed: e21d6c1

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 8, 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

Low-impact test-only change — auto-approving for merge.

What was evaluated:

  • 2 new tests exercising the defensive .get(model, 0) fallback in render_vscode_summary for absent/partial duration_by_model keys
  • 1 existing test (test_avg_ms_division_by_zero_guard) refined with more precise regex assertion and explicit total_duration_ms
  • All changes confined to tests/copilot_usage/test_vscode_report.py (41 additions, 1 deletion)
  • Tests follow existing patterns, use established helpers (_make_summary, _capture, _strip_ansi), and include meaningful docstrings
  • CI: all 10 checks green

@microsasa microsasa merged commit da727ad into main Apr 8, 2026
10 checks passed
@microsasa microsasa deleted the fix/869-test-absent-duration-key-18e059a630d638db branch April 8, 2026 21:09
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 aw-review-response-attempted Responder has attempted to address review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][test audit] vscode_report: duration_by_model absent-key fallback never exercised in tests

2 participants