build(pyright): strict-check the pure modules (#245 Stage 2)#268
Conversation
Stage 2 of #245 (assessment F-4): add the seven pure/leaf modules — model, statemachine, policy, documents, machine, checks, sanitize — to pyright's `strict` list so the domain core is held to strict analysis while the I/O-heavy modules stay basic. `strict` overrides typeCheckingMode per path (same effect as a per-file `# pyright: strict` comment), verified against the 1.1.411 docs and pinned CI runner. No runtime changes — annotations, config, and suppressions only: - checks.Finding.detail / ValidationReport.{add,ok,warn,fail}: bare `dict` -> `Mapping[str, object]` (covariant, so install.py's dict[str,str] detail dicts stay assignable under basic mode). - documents.validate_document -> dict[str, object]; status_document's local `tasks` list annotated. - statemachine.py comes back strict-clean with zero changes. Three of the seven parse loosely-typed persisted data (json/tomllib hand back dict[str, Any]; isinstance-narrowing an Any yields dict[Unknown, Unknown]) or use the `field(default_factory=list|dict)` idiom pyright can only infer as `[Unknown]`. Those surface the three "expression fully known" rules on correct code at that boundary; clearing them would need a TypedDict per persisted shape or runtime coercions, out of scope here. So policy/model/sanitize/checks relax only those specific rules via a documented file-level pragma (a no-op in basic mode, where they are off), and machine's one stdlib-stub gap (TextIO.reconfigure) keeps a targeted inline ignore. Every other strict rule stays on and still catches drift.
|
Warning Review limit reached
Next review available in: 40 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughPyright strict checking is enabled for selected core modules. Public detail payloads and document return values receive precise container types, while local directives relax diagnostics at known dynamic boundaries. Runtime behavior remains unchanged. ChangesStrict typing configuration and annotations
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/bmad_loop/checks.py`:
- Line 91: Normalize Finds.detail to JSON-compatible plain dict and nested
values before validate --json reaches machine.emit(), rather than passing
arbitrary Mapping objects unchanged from validate_document. Update the emission
path around machine.emit() to recursively convert supported mappings and
containers into standard JSON-serializable structures while preserving existing
detail content.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a1368931-1f08-456f-88c0-d7aa2b5a29ff
📒 Files selected for processing (7)
pyproject.tomlsrc/bmad_loop/checks.pysrc/bmad_loop/documents.pysrc/bmad_loop/machine.pysrc/bmad_loop/model.pysrc/bmad_loop/policy.pysrc/bmad_loop/sanitize.py
CodeRabbit on #268 flagged that widening `Finding.detail` to `Mapping[str, object]` could let `validate --json` fail on a non-JSONable detail. No caller exercises that, and the prior bare `dict` (= dict[Any, Any]) was already equally permissive of nested non-JSONable values, so this is a regression-guard rather than a fix: it drives the exact production path `machine.emit(validate_document(...))` with every detail shape the real gates attach (str values, the nested `dict(role_names)` dict, str+int, install.py's `{**detail, "marker": ...}`, and the `detail=None` leg) and asserts the whole document still parses and each value survives.
Summary
Stage 2 of #245 (assessment F-4), the follow-up to the basic-mode gate that landed in #264. Adds the seven pure/leaf modules to pyright's
strictlist so the domain core is held to strict analysis while the I/O-heavy modules staybasic:model.py,statemachine.py,policy.py,documents.py,machine.py,checks.py,sanitize.pystrictoverridestypeCheckingModefor those paths only — the same effect as a per-file# pyright: strictcomment (verified against the 1.1.411 docs, the version CI pins). No runtime behaviour changes in this PR: annotations, config, and suppressions only.What the gate caught (and how it's resolved)
The spike surfaced 77 strict findings. Breakdown and disposition:
Genuine annotation fixes (source):
checks.Finding.detailandValidationReport.{add,ok,warn,fail}were baredict→Mapping[str, object].Mapping(covariant in its value type) is deliberate soinstall.py'sdict[str, str]detail dicts stay assignable under basic mode;dict[str, object]would have tripped invariance there.documents.validate_documentreturndict→dict[str, object];status_document's localtaskslist annotated.statemachine.pycomes back strict-clean with zero changes.Irreducible boundary / idiom noise (suppressed precisely): three of the seven modules reconstruct typed objects from loosely-typed persisted data —
json/tomllibhand backdict[str, Any], andisinstance-narrowing anAnyyieldsdict[Unknown, Unknown]— or use the idiomaticfield(default_factory=list|dict)that pyright can only infer as[Unknown]. These fire the three "expression fully known" rules (reportUnknown{Member,Argument,Variable}Type) on correct code. Clearing them would take aTypedDictper persisted shape or runtime coercions — out of scope for a no-runtime-change gate. So:policy.py/model.py/sanitize.py/checks.pyrelax only those specific rules via a documented file-level# pyright:pragma. Those rules are off in basic mode already, so the pragma is a no-op for every non-strict file.machine.py's single stdlib-stub gap (TextIO.reconfigure) keeps a targeted inline# pyright: ignore, written in black's wrapped form so the suppression stays on the flagged token line.Verification
uvx pyright@1.1.411→ 0 errors, 0 warnings (matches the pinned CI runner).trunk check→ clean. Formatting is black-stable (re-runningtrunk fmtis a no-op; the two trailing-ignore lines were reworked so black's wrap doesn't relocate them off the flagged token).test_module_skills_syncfailures are the pre-existing local-only drift (gitignored.agents/.claudeinstall copies atmodule_version 0.8.1vs canonical0.9.0); they touch nothing this PR changes and are absent on a fresh CI checkout.Completes #245.
Summary by CodeRabbit
Quality Improvements
Compatibility