invariant: add proptest properties for source_complexity.rs 🔬#2606
invariant: add proptest properties for source_complexity.rs 🔬#2606EffortlessSteven wants to merge 1 commit into
Conversation
Added missing property-based invariants around `source_complexity.rs` to lock in aggregation logic. - Registered `properties.rs` within `crates/tokmd-analysis/src/source_complexity.rs`. - Added two invariants testing function order independence and that total complexity >= max complexity, verifying both pass with `cargo test -p tokmd-analysis properties`.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reached
More reviews will be available in 21 minutes and 53 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ 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 |
|
Droid finished @EffortlessSteven's task —— View job Droid validation complete. The P1 finding that |
Glass CockpitBase: origin/main Change Surface:
Composition:
Contracts:
Health: 100/100 (A) Review Plan
ReceiptsFull receipt data available in JSON format. |
| } | ||
| } | ||
| #[path = "source_complexity/properties.rs"] | ||
| mod properties; |
There was a problem hiding this comment.
[P2] Property-test file breaks the established tests.rs registration pattern used elsewhere in this crate
Siblings such as crates/tokmd-analysis/src/complexity/tests.rs, crates/tokmd-analysis/src/derived/tests.rs, crates/tokmd-analysis/src/git/tests.rs, and crates/tokmd-analysis/src/halstead/tests.rs all follow the same pattern: the production module file ends with a #[cfg(test)]-gated mod tests; (or mod moved_tests; with #[path = "tests.rs"]) and the tests.rs file pulls in a properties submodule from a tests/ subdirectory. This PR instead drops properties.rs directly next to mask.rs in source_complexity/ and registers it from the production file with #[path = "source_complexity/properties.rs"] mod properties;, skipping the #[cfg(test)] gate and the tests.rs indirection. Move the file to source_complexity/tests/properties.rs, introduce a source_complexity/tests.rs that contains mod properties; (or #[path = "tests/properties.rs"] mod properties; to match the rest of the crate), and replace this registration with #[cfg(test)] mod tests; to match the sibling-file pattern.
💡 Summary
Added missing property-based invariant tests around
source_complexity.rs. These invariants explicitly verify that the heuristic rust code parsing and metric aggregations are independent of structural shifts like function re-ordering.🎯 Why
The lightweight heuristic parser in
source_complexity.rsdrives cockpit review gates without pulling in a full AST. It relies on a custom token mask and a state machine tracking bracket depth and function spans. To ensure stable tracking oftotal_complexityandmax_complexity, we needed property-based verification confirming the aggregation math works commutatively and monotonically regardless of input structure.🔎 Evidence
Minimal proof:
crates/tokmd-analysis/src/source_complexity/properties.rssource_complexity.rswas not previously covered byproptest. Adding invariants discovered a minor issue with bad generated regexes that we fixed. Both invariants now pass deterministically over randomized input subsets.total >= maxalways holds.🧭 Options considered
Option A (recommended)
source_complexity.rsheuristic aggregations.analysis-stackshard, improves property coverage.Option B
tokmd-gate(e.g. ratchet definitions).✅ Decision
Option A. Adding property-based invariants directly against the
analyze_rust_function_complexityparser is an honest and high-value proof improvement within theanalysis-stackthat locks in true mathematical properties of the implementation.🧱 Changes made (SRP)
crates/tokmd-analysis/src/source_complexity/properties.rs.properties.rswithincrates/tokmd-analysis/src/source_complexity.rs.🧪 Verification receipts
🧭 Telemetry
source_complexity.rsand deleteproperties.rscargo test,cargo fmt -- --check,cargo clippy -- -D warnings,cargo build --verbose🗂️ .jules artifacts
.jules/runs/invariant_model_analysis/envelope.json.jules/runs/invariant_model_analysis/decision.md.jules/runs/invariant_model_analysis/receipts.jsonl.jules/runs/invariant_model_analysis/result.json.jules/runs/invariant_model_analysis/pr_body.md🔜 Follow-ups
None
PR created automatically by Jules for task 7696108606194472207 started by @EffortlessSteven