Skip to content

fix: code quality cleanups in report.py and models.py (#66)#93

Closed
microsasa wants to merge 2 commits intomainfrom
fix/issue-66-code-quality-cleanups-92a4ff0a9a4e52c6
Closed

fix: code quality cleanups in report.py and models.py (#66)#93
microsasa wants to merge 2 commits intomainfrom
fix/issue-66-code-quality-cleanups-92a4ff0a9a4e52c6

Conversation

@microsasa
Copy link
Owner

Closes #66

Changes

  1. Extract _format_session_running_time helper — The duplicated 4-line running-time expression in render_live_sessions and _render_active_section is now a single private helper.

  2. Rename shadowed parameter in render_cost_view — The sessions parameter was being reassigned to a filtered result. Renamed to filtered to match the pattern used elsewhere and avoid shadowing confusion.

  3. Standardize output-token summation in _render_totals — Replaced the nested for loop with the same generator-expression style used in _render_historical_section.

  4. Simplify AssistantMessageData.toolRequests factory — Changed from lambda: list[dict[str, object]]() (misleading runtime-erased generic) to default_factory=list, consistent with all other collection fields.

Testing

  • Added 3 unit tests for _format_session_running_time: no start_time → dash, start_time only, and last_resume_time preferred over start_time.
  • All 386 existing tests pass without modification.
  • Coverage: 97% (well above 80% threshold).
  • Full CI suite passes: ruff, pyright, bandit, pytest.

Generated by Issue Implementer ·

- Extract _format_session_running_time helper to deduplicate running-time
  computation in render_live_sessions and _render_active_section
- Rename shadowed sessions parameter to filtered in render_cost_view
- Standardize _render_totals output-token summation to comprehension form
- Simplify AssistantMessageData.toolRequests default_factory to list
- Add unit tests for _format_session_running_time

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 15, 2026 19:50
Copy link

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

This PR addresses several small code-quality issues in the Copilot usage reporting and telemetry models, primarily by deduplicating logic, avoiding parameter shadowing, and aligning implementation style across similar code paths.

Changes:

  • Extracted _format_session_running_time() and reused it in both live-session and active-section renderers.
  • Avoided shadowing sessions in render_cost_view() by introducing a filtered variable.
  • Standardized total output-token summation in _render_totals() to use a generator-expression form.
  • Simplified AssistantMessageData.toolRequests to use Field(default_factory=list) and added unit tests for the new helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/copilot_usage/report.py Refactors duplicated “running time” formatting into a helper; minor cleanups in totals and cost view.
src/copilot_usage/models.py Simplifies toolRequests default factory to match project-wide Pydantic collection conventions.
tests/copilot_usage/test_report.py Adds unit tests covering _format_session_running_time behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

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

This PR addresses Issue #66 by performing small code-quality cleanups in the Copilot usage reporting code and related Pydantic models, plus adding focused unit tests for the extracted helper.

Changes:

  • Extracts _format_session_running_time to de-duplicate running-time formatting logic and adds unit tests for it.
  • Avoids parameter shadowing in render_cost_view by using a filtered variable.
  • Standardizes output-token summation style in _render_totals and simplifies a Pydantic default_factory for toolRequests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/copilot_usage/report.py Extracts running-time helper, cleans up cost-view variable naming, and standardizes token aggregation.
src/copilot_usage/models.py Simplifies toolRequests default factory to list (but introduces a questionable pyright ignore).
tests/copilot_usage/test_report.py Adds unit tests covering _format_session_running_time behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
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 — AUTO-APPROVED

Evaluation summary:

  • aw label present
  • ✅ CI (check) passing
  • ✅ Copilot auto-review completed (COMMENTED)

Code quality: Good

  • Clean extraction of _format_session_running_time helper eliminating duplication in two call sites
  • Variable rename in render_cost_view correctly avoids parameter shadowing
  • Token summation refactored to generator expression matching existing project style
  • toolRequests default_factory simplified to match project Pydantic convention (Field(default_factory=list))
  • 3 focused unit tests covering all branches of the new helper

Impact: LOW — Purely internal refactoring (helper extraction, variable rename, style alignment) with no changes to public API, data models, or business logic. All existing tests pass unmodified.

Note: Copilot reviewer flagged the # pyright: ignore[reportUnknownVariableType] on toolRequests as potentially unnecessary/inconsistent. This is a minor style nit, not a correctness issue — it can be addressed in a follow-up if desired.

Auto-approving for merge.

@github-actions
Copy link
Contributor

Commit pushed: 28b7072

Generated by Review Responder

Remove pyright ignore comment on toolRequests field by using a typed
factory (list[dict[str, object]]) instead of bare list. This gives
pyright the type information it needs without suppressing diagnostics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa
Copy link
Owner Author

Closing — will re-dispatch implementer after pipeline fixes land (PR #97).

@microsasa microsasa closed this Mar 15, 2026
auto-merge was automatically disabled March 15, 2026 20:16

Pull request was closed

@microsasa microsasa deleted the fix/issue-66-code-quality-cleanups-92a4ff0a9a4e52c6 branch March 15, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][code health] Bundle of code quality cleanups in report.py and models.py

2 participants