Skip to content

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

Merged
microsasa merged 2 commits intomainfrom
fix/issue-66-code-quality-cleanups-3f6de871f0ec0a7c
Mar 17, 2026
Merged

fix: code quality cleanups in report.py and models.py (#66)#113
microsasa merged 2 commits intomainfrom
fix/issue-66-code-quality-cleanups-3f6de871f0ec0a7c

Conversation

@microsasa
Copy link
Owner

Closes #66

Changes

1. Extract _format_session_running_time helper (report.py)
Deduplicates the 4-line running-time expression that was copy-pasted in render_live_sessions and _render_active_section. Both now call the new private helper.

2. Fix parameter shadowing in render_cost_view (report.py)
Renamed the reassignment sessions = _filter_sessions(...)filtered = _filter_sessions(...) and updated all internal references. This matches the pattern used by every other function that filters sessions.

3. Standardize output-token summation in _render_totals (report.py)
Replaced the nested for loop with the same comprehension form used in _render_historical_section.

4. Simplify AssistantMessageData.toolRequests default factory (models.py)
Removed the misleading lambda: list[dict[str, object]]() wrapper. Now uses default_factory=list[dict[str, object]] directly (the parameterized type is needed to satisfy pyright strict mode with nested generics).

Testing

  • Added TestFormatSessionRunningTime with 4 tests covering: start_time=None"—", last_resume_time absent, last_resume_time present, and delegation to _format_elapsed_since.
  • All 402 existing tests pass unchanged.
  • Full CI suite passes: ruff check, ruff format, pyright (0 errors), pytest (98% coverage).

Generated by Issue Implementer ·

@microsasa microsasa added the aw Created by agentic workflow label Mar 15, 2026
@microsasa microsasa enabled auto-merge March 15, 2026 22:08
@microsasa microsasa added the aw Created by agentic workflow label Mar 15, 2026
@microsasa microsasa disabled auto-merge March 16, 2026 02:48
@microsasa microsasa enabled auto-merge March 16, 2026 02:48
@microsasa microsasa disabled auto-merge March 16, 2026 06:24
@microsasa microsasa enabled auto-merge March 16, 2026 06:25
@microsasa microsasa requested a review from Copilot March 16, 2026 06:30
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 performs code-quality refactors in the reporting utilities and fixes a dataclass/model default initialization, with accompanying unit tests for the new session running-time helper.

Changes:

  • Extracts _format_session_running_time() and reuses it in live/active session rendering.
  • Cleans up render_cost_view local naming and simplifies total output token computation.
  • Updates AssistantMessageData.toolRequests default factory and adds tests for the new time-format helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/copilot_usage/test_report.py Adds unit tests for _format_session_running_time.
src/copilot_usage/report.py Introduces _format_session_running_time helper and refactors token summation / filtering variable naming.
src/copilot_usage/models.py Changes toolRequests field default_factory implementation.

💡 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: APPROVED

Evaluated dimensions:

Dimension Result
Code quality Good — clean refactoring following existing patterns
Tests 4 meaningful tests for new helper, all 402 existing tests pass
Impact LOW — helper extraction, variable rename, comprehension simplification, default factory cleanup

Changes summary:

  • _format_session_running_time extracts duplicated 4-line pattern from two call sites → clean DRY improvement
  • render_cost_view: sessionsfiltered fixes parameter shadowing, matches existing codebase convention
  • _render_totals: nested loop → comprehension matches pattern in _render_historical_section
  • toolRequests default factory: lambda: list[dict[str, object]]()list[dict[str, object]] — valid simplification (GenericAlias is callable in Python 3.12+, confirmed by CI)

Re: Copilot review comments:

  1. The default_factory=list[dict[str, object]] concern is a false positive — types.GenericAlias is callable in Python 3.12+ and CI confirms all tests pass.
  2. The flaky-test concern about test_delegates_to_format_elapsed_since is theoretically valid but extremely low risk (both calls execute within microseconds).

Low-impact refactoring with good test coverage. Auto-approving for merge.

@github-actions
Copy link
Contributor

Commit pushed: 0bfbe1b

Generated by Review Responder

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

Pull request was closed

@microsasa microsasa deleted the fix/issue-66-code-quality-cleanups-3f6de871f0ec0a7c branch March 16, 2026 07:08
@microsasa microsasa restored the fix/issue-66-code-quality-cleanups-3f6de871f0ec0a7c branch March 16, 2026 07:09
@microsasa microsasa reopened this Mar 16, 2026
@microsasa microsasa enabled auto-merge March 16, 2026 07:09
@microsasa
Copy link
Owner Author

Pipeline Orchestrator 🔄

PR #113 status:

  • ✅ Copilot review: submitted
  • ✅ Quality gate: approved
  • ✅ CI (check): passing
  • 2 unresolved review threads — both have the review-responder as last commenter and are ready to be resolved
  • Behind main — needs rebase before auto-merge can proceed

Blocker: The 2 Copilot review threads were addressed by the review-responder but never resolved. PR Rescue scheduled runs (cron) do not appear to be firing (0 scheduled runs in history), so the threads remain open and the rebase hasn't happened.

Next steps (manual):

  1. Resolve the 2 review threads on this PR
  2. Rebase onto main (or wait for PR Rescue to run)

Once threads are resolved and the branch is up-to-date, auto-merge should complete.

Generated by Pipeline Orchestrator ·

@microsasa
Copy link
Owner Author

Pipeline Orchestrator 🔄

PR #113 is approved (quality-gate), CI is passing, and the review-responder has replied to both Copilot review threads. However, 2 review threads remain unresolved, which blocks merging (branch protection requires conversation resolution).

Status:

  • ✅ Copilot review submitted
  • ✅ Review-responder replied to both threads
  • ✅ Quality-gate approved
  • ✅ CI passing
  • ⚠️ 2 unresolved threads (both answered by responder — ready to resolve)
  • ⚠️ Branch is behind main (needs rebase after threads resolved)

Action needed: Please resolve the 2 review threads manually (both have been addressed by the review-responder). Once resolved and rebased, auto-merge will complete.

Threads to resolve:

  1. src/copilot_usage/models.py:127default_factory discussion (Copilot's concern was addressed: list[dict[str, object]] is callable in Python 3.12+)
  2. tests/copilot_usage/test_report.py — flaky test concern (fixed: test now uses monkeypatching)

Generated by Pipeline Orchestrator ·

@microsasa
Copy link
Owner Author

🔄 Pipeline Orchestrator Status

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

Current State

Dimension Status
Copilot Review ✅ Completed (2 comments)
Review Response ✅ Responded (by review-responder)
Quality Gate ✅ Approved
CI (check) ✅ Passing
Merge State ⚠️ Behind main
Unresolved Threads ⚠️ 2 threads (responder replied, awaiting resolution)

Action Needed

Both unresolved review threads have been addressed by the review-responder — they are eligible for resolution. However, the orchestrator was unable to resolve them programmatically due to thread node IDs not being available through the current API tooling.

Next steps (manual or next cycle):

  1. Resolve both review threads (last commenter is the review-responder on both)
  2. Rebase onto main (PR is currently behind)
  3. Auto-merge should then proceed

Open Issues Awaiting Implementation

Skipped issue dispatch: open aw-labeled PR #113 is in flight.

Generated by Pipeline Orchestrator ·

@microsasa
Copy link
Owner Author

Pipeline Orchestrator 🔄

PR #113 status check:

Check Status
Copilot review ✅ Submitted
Review responses ✅ Responder replied to all threads
Quality gate ✅ Approved
CI (check job) ✅ Passing
Unresolved threads ⚠️ 2 threads need resolution
Merge state ⚠️ Behind main

Action needed: 2 review threads have been addressed by the review-responder but remain unresolved. These threads are blocking auto-merge (branch protection requires conversation resolution). Once resolved, the PR will also need a rebase onto main before auto-merge can proceed.

Threads to resolve:

  • src/copilot_usage/models.py line 127 — default_factory discussion (responder explained Python 3.12+ GenericAlias is callable)
  • tests/copilot_usage/test_report.py — flaky test concern (responder confirmed fix was pushed with monkeypatch)

Generated by Pipeline Orchestrator ·

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 code-quality issues in copilot_usage’s reporting and models layer, primarily reducing duplication and improving clarity in report rendering logic while keeping behavior consistent.

Changes:

  • Extracts _format_session_running_time() in report.py and reuses it across live/active session rendering.
  • Avoids parameter shadowing in render_cost_view() by using a dedicated filtered variable.
  • Standardizes output-token aggregation in _render_totals() and adds targeted unit tests for the new helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/copilot_usage/test_report.py Adds focused tests for _format_session_running_time(), including a non-flaky delegation test via patching.
src/copilot_usage/report.py Introduces _format_session_running_time(), removes duplicated logic, clarifies filtering variable naming, and simplifies token summation.
src/copilot_usage/models.py Simplifies toolRequests default factory by removing the lambda wrapper while preserving typing intent.

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

@microsasa
Copy link
Owner Author

Pipeline Orchestrator checked PR status.

Current state:

  • ✅ Copilot reviewed — review threads exist, review-response-attempted label present
  • ✅ Review Responder replied — last comment on both threads is from the responder
  • ✅ Quality Gate approved — quality-gate-approved label present
  • ✅ CI passing — all check runs succeeded
  • ⚠️ 2 unresolved review threads — both have responder as last commenter and should be resolved, but the orchestrator cannot obtain GraphQL thread node IDs (PRRT_...) through available API tooling
  • ⚠️ PR is behind main — needs rebase before auto-merge can proceed

Blocked on: Thread resolution requires GraphQL node IDs not exposed by current tools. Manual resolution of the 2 review threads (on src/copilot_usage/models.py:127 and tests/copilot_usage/test_report.py) + rebase onto main will unblock auto-merge.

Generated by Pipeline Orchestrator ·

@microsasa microsasa requested a review from Copilot March 17, 2026 11:19
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 layer by deduplicating logic, improving variable clarity, and standardizing token aggregation, with accompanying unit tests for the new helper.

Changes:

  • Extracted _format_session_running_time() and reused it in both live-session and active-section rendering.
  • Removed parameter shadowing in render_cost_view() by introducing a filtered variable for the filtered session list.
  • Standardized output-token summation in _render_totals() using the same comprehension style used elsewhere.
  • Simplified AssistantMessageData.toolRequests default factory and added tests for the running-time helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/copilot_usage/test_report.py Adds unit tests for _format_session_running_time() and imports the helper for direct testing.
src/copilot_usage/report.py Introduces _format_session_running_time(), refactors two call sites to use it, standardizes token summation, and avoids parameter shadowing in render_cost_view().
src/copilot_usage/models.py Updates AssistantMessageData.toolRequests to a simpler (non-lambda) default_factory form.

💡 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 a set of small code-quality improvements in the Copilot usage reporting/rendering layer and its Pydantic models, primarily reducing duplication and improving readability while keeping behavior consistent.

Changes:

  • Extracts a shared _format_session_running_time() helper and adds focused unit tests for it.
  • Avoids parameter shadowing in render_cost_view() by using a filtered variable for the date-range subset.
  • Simplifies total output-token aggregation in _render_totals() to match the comprehension style used elsewhere.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/copilot_usage/test_report.py Adds new unit tests covering _format_session_running_time() behavior and its delegation to _format_elapsed_since().
src/copilot_usage/report.py Introduces _format_session_running_time(), removes duplicated running-time logic, avoids parameter shadowing in render_cost_view(), and standardizes output-token summation.
src/copilot_usage/models.py Simplifies AssistantMessageData.toolRequests default factory by removing the lambda wrapper.

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

@microsasa microsasa disabled auto-merge March 17, 2026 16:32
@microsasa microsasa enabled auto-merge March 17, 2026 16:33
@microsasa microsasa disabled auto-merge March 17, 2026 17:37
@microsasa microsasa enabled auto-merge March 17, 2026 17:37
@microsasa microsasa disabled auto-merge March 17, 2026 17:41
@microsasa microsasa enabled auto-merge March 17, 2026 17:41
@microsasa microsasa disabled auto-merge March 17, 2026 17:42
@microsasa microsasa enabled auto-merge March 17, 2026 17:42
@microsasa microsasa disabled auto-merge March 17, 2026 17:44
@microsasa microsasa enabled auto-merge March 17, 2026 17:44
@microsasa microsasa disabled auto-merge March 17, 2026 18:42
@microsasa microsasa enabled auto-merge March 17, 2026 18:42
@microsasa microsasa disabled auto-merge March 17, 2026 19:16
@microsasa microsasa enabled auto-merge March 17, 2026 19:16
github-actions bot and others added 2 commits March 17, 2026 19:20
- 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 output-token summation in _render_totals to comprehension form
- Simplify AssistantMessageData.toolRequests default_factory (remove lambda)
- Add unit tests for _format_session_running_time

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa force-pushed the fix/issue-66-code-quality-cleanups-3f6de871f0ec0a7c branch from 0bfbe1b to 6020811 Compare March 17, 2026 19:20
@microsasa microsasa merged commit 826b146 into main Mar 17, 2026
4 checks passed
@microsasa microsasa deleted the fix/issue-66-code-quality-cleanups-3f6de871f0ec0a7c branch March 17, 2026 19:20
microsasa pushed a commit that referenced this pull request Mar 17, 2026
- Changelog: added entries for PRs #140-#143, dependabot bumps,
  orchestrator v1/v2, PR #113 auto-merge success
- Agentic-workflows: replaced removed orchestrator section with
  current bash implementation, updated agent inventory, added
  history entry
- Test-analysis: changed cron from weekly to daily (0 9 * * *)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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