Skip to content

fix: batch code-health fixes (#671, #790, #894, #909)#939

Merged
microsasa merged 5 commits intomainfrom
fix/671-dead-branch-cleanup
Apr 16, 2026
Merged

fix: batch code-health fixes (#671, #790, #894, #909)#939
microsasa merged 5 commits intomainfrom
fix/671-dead-branch-cleanup

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Code-health batch

Five commits addressing open code-health issues and guideline cleanup.

Commits

  1. Remove unreachable dead branch in _build_completed_summarycloses [aw][code health] Small cleanups: unreachable dead branch in _build_completed_summary + empty PRODUCT_VISION.md #671

    • Deleted if idx < len(events) else None guard that could never trigger
    • Removed test that manufactured the impossible scenario
  2. Use default_factory=lambda for complex generic Pydantic fieldscloses [aw][code health] Two Pydantic fields suppress reportUnknownVariableType instead of using default_factory=lambda: [] #790

    • toolRequests and shutdown_cycles fields changed from default_factory=list + # pyright: ignoredefault_factory=lambda: []
    • Updated CODING_GUIDELINES with lambda guidance for complex generics
  3. Remove arbitrary line-count threshold and dead-code guideline

    • Removed ~250-line module threshold (meaningless metric)
    • Removed Defensive Programming section that encouraged unreachable guard clauses
  4. Fix stale cli.py docstring + allow getattr/hasattr in testscloses [aw][code health] Minor guideline-compliance cleanup: stale docstring and banned hasattr/getattr in tests #894

    • Added missing vscode command to cli.py module docstring
    • Added test exception to getattr/hasattr guideline (introspection in tests is fine)
  5. Detect ambiguous partial pricing matches and fall backcloses [aw][code health] _cached_lookup partial pricing match is nondeterministic when multiple keys tie on match_len, silently mis [Content truncated due to length] #909

    • When _cached_lookup finds multiple keys tying on overlap length, falls back to unknown-model pricing (1.0×) and logs a warning
    • Previously silently used whichever key was first in dict insertion order

Testing

All checks pass: ruff lint/format, pyright, bandit, unit tests (99% coverage), e2e tests (86 passed).

Sasa Junuzovic and others added 4 commits April 15, 2026 21:02
The `idx < len(events)` guard was dead code — idx comes from
enumerate(events) in _first_pass and is always a valid index.
Simplified to direct `events[idx].timestamp` access.

Removed test that crafted an impossible out-of-bounds scenario
to exercise the dead branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…790)

Replace default_factory=list with default_factory=lambda: [] for
toolRequests and shutdown_cycles fields. Removes both pyright
ignore[reportUnknownVariableType] suppressions.

Updated CODING_GUIDELINES.md to note that complex generic list
types in Pydantic Field require lambda: [] (simple types are fine
with bare list).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Removed ~250-line module extraction trigger — line count alone is
  not a meaningful measure. Replaced with concern-based criterion.
- Removed 'Defensive Programming' section that encouraged leaving
  unreachable guard clauses in code as future-proofing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Added missing vscode command to cli.py module docstring
- Added test exception to getattr/hasattr guideline — introspection
  in tests (checking module exports, verifying field absence) is fine
- Items 2 and 3 from the issue (replacing getattr/hasattr in tests)
  are no longer violations per the updated guideline

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 16, 2026 04:25
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

Code-health batch addressing several open issues across parsing, pricing, models, CLI docs, and contributor guidelines to reduce dead code, improve typing hygiene, and make pricing lookups deterministic/safer.

Changes:

  • Simplifies session shutdown summary building by removing an unreachable guard and dropping the corresponding impossible test.
  • Updates Pydantic Field defaults for complex generics to use default_factory=lambda: [] and documents the convention in CODING_GUIDELINES.
  • Adjusts pricing partial-match logic to detect ambiguous ties, warn, and fall back to unknown-model pricing; updates tests accordingly.

Reviewed changes

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

Show a summary per file
File Description
src/copilot_usage/pricing.py Adds tie detection in partial-match pricing lookup and falls back to unknown-model pricing with a warning.
tests/copilot_usage/test_pricing.py Updates/expands tests to assert tie fallback behavior and warning emission.
src/copilot_usage/parser.py Removes unreachable shutdown index guard when building completed summaries.
tests/copilot_usage/test_parser.py Removes the test that fabricated an impossible out-of-bounds shutdown index scenario.
src/copilot_usage/models.py Replaces default_factory=list + pyright ignores with default_factory=lambda: [] for complex generic list fields.
src/copilot_usage/cli.py Fixes module docstring to include the vscode command.
.github/CODING_GUIDELINES.md Updates guidance on Pydantic defaults, removes dead code-health guidance, and permits getattr/hasattr in tests for introspection.

Comment thread src/copilot_usage/pricing.py
When _cached_lookup finds multiple keys tying on overlap length,
it now falls back to unknown-model pricing (1.0×, STANDARD) and
logs a warning instead of silently using whichever key appeared
first in dict insertion order.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa force-pushed the fix/671-dead-branch-cleanup branch from 66ce25b to 96d5c5c Compare April 16, 2026 04:36
@microsasa microsasa merged commit c526fda into main Apr 16, 2026
5 checks passed
@microsasa microsasa deleted the fix/671-dead-branch-cleanup branch April 16, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment