Skip to content

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.

  1. Canontra runs git diff --name-only <GIT_REF> (read-only, without invoking a shell).
  2. Each modified .py, .js, .ts, .go, or .rs file is compared against <GIT_REF>:<file> across F0..F4.
  3. Files are grouped into three buckets:
    • birLevel1TriviaFiles: F4 unchanged, so 0 tests 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 walks CSRGraph.backwardReachabilityCone to find every caller file (birTransitiveCallers).
  4. findMatchingTests collects tests covering modified and downstream caller files into birImpactedTests and builds birTestCommand.

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
================================================================================
Terminal window
CMD=$(canontra impact --pr-base origin/main --json | jq -r '.birTestCommand')
if [ -n "$CMD" ] && [ "$CMD" != "null" ]; then
eval "$CMD"
fi