fix: code quality cleanups in report.py and models.py (#66)#113
fix: code quality cleanups in report.py and models.py (#66)#113
Conversation
There was a problem hiding this comment.
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_viewlocal naming and simplifies total output token computation. - Updates
AssistantMessageData.toolRequestsdefault 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.
There was a problem hiding this comment.
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_timeextracts duplicated 4-line pattern from two call sites → clean DRY improvementrender_cost_view:sessions→filteredfixes parameter shadowing, matches existing codebase convention_render_totals: nested loop → comprehension matches pattern in_render_historical_sectiontoolRequestsdefault 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:
- The
default_factory=list[dict[str, object]]concern is a false positive —types.GenericAliasis callable in Python 3.12+ and CI confirms all tests pass. - The flaky-test concern about
test_delegates_to_format_elapsed_sinceis theoretically valid but extremely low risk (both calls execute within microseconds).
Low-impact refactoring with good test coverage. Auto-approving for merge.
|
Commit pushed:
|
Pull request was closed
|
Pipeline Orchestrator 🔄 PR #113 status:
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):
Once threads are resolved and the branch is up-to-date, auto-merge should complete.
|
|
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:
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:
|
🔄 Pipeline Orchestrator StatusPR #113 — Current State
Action NeededBoth 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):
Open Issues Awaiting Implementation
|
|
Pipeline Orchestrator 🔄 PR #113 status check:
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 Threads to resolve:
|
There was a problem hiding this comment.
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()inreport.pyand reuses it across live/active session rendering. - Avoids parameter shadowing in
render_cost_view()by using a dedicatedfilteredvariable. - 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.
|
Pipeline Orchestrator checked PR status. Current state:
Blocked on: Thread resolution requires GraphQL node IDs not exposed by current tools. Manual resolution of the 2 review threads (on
|
There was a problem hiding this comment.
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 afilteredvariable for the filtered session list. - Standardized output-token summation in
_render_totals()using the same comprehension style used elsewhere. - Simplified
AssistantMessageData.toolRequestsdefault 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.
There was a problem hiding this comment.
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 afilteredvariable 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.
- 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>
0bfbe1b to
6020811
Compare
- 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>
Closes #66
Changes
1. Extract
_format_session_running_timehelper (report.py)Deduplicates the 4-line running-time expression that was copy-pasted in
render_live_sessionsand_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
forloop with the same comprehension form used in_render_historical_section.4. Simplify
AssistantMessageData.toolRequestsdefault factory (models.py)Removed the misleading
lambda: list[dict[str, object]]()wrapper. Now usesdefault_factory=list[dict[str, object]]directly (the parameterized type is needed to satisfy pyright strict mode with nested generics).Testing
TestFormatSessionRunningTimewith 4 tests covering:start_time=None→"—",last_resume_timeabsent,last_resume_timepresent, and delegation to_format_elapsed_since.