Skip to content

impact & slice

canontra impact <FILE> [-b|--base BASE_FILE] [-r|--repo DIR] [--json]
canontra impact --pr-base <GIT_REF> [-r|--repo DIR] [--json]
canontra slice <SYMBOL> [-r|--repo DIR] [--json]
  • impact <FILE>: Compares FILE against BASE_FILE (or git show HEAD:<FILE> if --base is omitted), builds the repository call graph, and lists downstream callers and matching test suites.
  • impact --pr-base <GIT_REF>: Analyzes an entire Pull Request (Canontra.Analysis.BatchImpact). Runs git diff --name-only <GIT_REF>, sorts each changed source file into Level 1 (Cosmetic / Trivia), Level 2 (Internal Logic), or Level 3 (Public API / Imports), walks the compact CSR call graph (backwardReachabilityCone) to find transitive callers, and outputs a ready-to-run test command (birTestCommand).
  • slice <SYMBOL>: Looks up a symbol by name (verify or auth.verify) across the repository call graph and prints its direct callers, transitive callers, affected files, matching tests, and outgoing calls.
Flag Short Default Description
--pr-base <GIT_REF> - - Base Git ref for Pull Request batch impact analysis (e.g. main, origin/main, HEAD~1)
--base <BASE_FILE> -b git HEAD Baseline file for single-file impact comparison
--repo <DIR> -r . Repository root directory
--json - false Print ImpactSlice, BatchImpactResult, or symbol slice as JSON

canontra impact --pr-base <GIT_REF> --json outputs BatchImpactResult:

{
"birModifiedFiles": ["src/auth.py", "src/formatting_only.py"],
"birLevel1TriviaFiles": ["src/formatting_only.py"],
"birLevel2LogicFiles": [],
"birLevel3ApiFiles": ["src/auth.py"],
"birTransitiveCallers": ["src/routes/login.py"],
"birImpactedTests": ["tests/test_auth.py", "tests/test_login.py"],
"birTotalRepoTests": 42,
"birSavedComputePct": 95.24,
"birTestCommand": "pytest tests/test_auth.py tests/test_login.py"
}
  • impact: Exits 0 on completion; 3 on parse error; 4 if --repo, target file, or git diff fails.
  • slice: Exits 0 when the symbol is found; exits 1 when the symbol is missing from the repository index.
Terminal window
# Multi-file PR impact slice against origin/main
canontra impact --pr-base origin/main --json
# Single-file impact against a saved baseline
canontra impact src/router.go -b /tmp/router.old.go -r .
# Upstream callers and downstream calls for one symbol
canontra slice calculate_discount --repo . --json