Monorepo PR Impact Analysis
Large monorepos often run every test suite on every Pull Request because tracking cross-file callers across multiple languages is slow or fragile. canontra impact --pr-base traces affected callers over a compact CSR call graph (Canontra.Analysis.BatchImpact) and builds a ready-to-run birTestCommand for each language.
How PR Batch Impact Works
Section titled “How PR Batch Impact Works”- Canontra runs
git diff --name-only <GIT_REF>(read-only, without invoking a shell). - Each modified
.py,.js,.ts,.go, or.rsfile is compared against<GIT_REF>:<file>acrossF0..F4. - Files are grouped into three buckets:
birLevel1TriviaFiles:F4unchanged, so0tests are needed.birLevel2LogicFiles: Internal body (F1,F_CF,F_DF,F_CG) changed while public APIs (F2,F3,F_T) stayed identical, so only direct unit tests for those files need to run.birLevel3ApiFiles: Public signatures, imports, or type contracts (F2,F3,F_T) changed, so Canontra walksCSRGraph.backwardReachabilityConeto find every caller file (birTransitiveCallers).
findMatchingTestscollects tests covering modified and downstream caller files intobirImpactedTestsand buildsbirTestCommand.
Ecosystem Test Runner Commands
Section titled “Ecosystem Test Runner Commands”Depending on repository languages and test paths, generateTestCommand emits direct test commands:
| Ecosystem | Generated birTestCommand Format |
|---|---|
| Python | pytest tests/test_auth.py tests/test_billing.py |
| JavaScript / TypeScript | npx jest tests/auth.test.ts tests/billing.test.ts |
| Go | go test ./pkg/auth/... ./pkg/billing/... |
| Rust | cargo test auth billing |
Example Output (canontra impact --pr-base main)
Section titled “Example Output (canontra impact --pr-base main)”================================================================================ CANONTRA MULTI-FILE PR BATCH CHANGE IMPACT ANALYSIS (CSR CIA 2.0)================================================================================ Modified Files: 3 files Level 1 (Trivia): 1 file (safe to skip) Level 2 (Logic): 1 file (direct unit tests) Level 3 (API/Dep): 1 file (full CSR backward reachability cone) Transitive Callers: 4 files Impacted Tests: 2 / 48 suites (95.83% compute saved)-------------------------------------------------------------------------------- Recommended Command: pytest tests/test_auth.py tests/test_session.py================================================================================Executing in CI
Section titled “Executing in CI”CMD=$(canontra impact --pr-base origin/main --json | jq -r '.birTestCommand')if [ -n "$CMD" ] && [ "$CMD" != "null" ]; then eval "$CMD"fi