feat(scanner/imports): detect policy imports across languages#67
Conversation
…pagate Extends find_policy_imports beyond TS/JS to walk the import grammars of Go (import_spec with optional package_identifier alias, basename fallback, blank/dot imports skipped), Python (import_statement, import_from_statement; wildcard skipped), and Java (scoped_identifier; static + wildcard handled). On the OCP corpus repo this alone moved externalization from 0% to 8%. Adds one-hop intra-file data-flow propagation so DI patterns are recognized: struct/object literal field initializers, short var decls, plain assignments, attribute/field-access LHS, and TS class fields all flow the binding set forward to a fixed point. Reuses the same is_enforcement_point regex semantics, but compiles a single combined \b(a|b|c)\b regex per iteration — earlier draft compiled one regex per binding per edge, which turned the OCP scan from 0.3s to 9.5s. OCP externalization: 0% → 65% (15/23 enforcement points). EA monorepo: 74% → 82% (96/117). The remaining residuals on OCP are cross-file flow within a package and same-package implementation files, both tracked in issue #66. 23 new unit tests in scanner::imports::tests cover the four languages across import detection, propagation single-hop, multi-hop, and negative cases. 3 new integration tests in scanner_enforcement_points.rs exercise the end-to-end scanner against Go/Python/Java fixtures.
Pair assignment targets with their corresponding RHS expressions when propagating policy-import bindings in Go and Python. This prevents unrelated local authorization-looking calls from being counted as externalized enforcement points.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe pull request extends policy import binding detection across TypeScript/JavaScript, Go, Python, and Java by introducing iterative one-hop propagation over assignment-shaped edges. Initial bindings are extracted per language via tree-sitter, then propagated intra-file through regex-driven edge matching until fixed point. New language-specific import and edge collectors are added, with comprehensive test coverage and updated documentation. ChangesMulti-Language Policy Import Detection with Iterative Propagation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~65 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
The implementation successfully extends policy import detection to Go, Python, and Java while adding intra-file data-flow propagation. The code is well-structured with comprehensive test coverage and properly handles edge cases like multi-assignment pairing to prevent false positives. All critical functionality appears to work correctly based on the extensive test suite covering real-world patterns from the OCP corpus.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
Summary
Changes
Testing
cargo fmt --checkcargo checkcargo clippy --all-features -- -D warningscargo test --all-featuresSummary by CodeRabbit
New Features
Tests