Quickstart
This 3-minute guide walks through the four everyday Canontra commands: hashing a single file, reading from standard input (stdin), comparing two files, and finding the minimal test set for a Pull Request.
1. Hash a Single File (canontra fp)
Section titled “1. Hash a Single File (canontra fp)”Run canontra fp on any supported source file (.py, .pyi, .js, .jsx, .mjs, .cjs, .ts, .tsx, .go, .rs):
canontra fp src/service.py CANONTRA DETERMINISTIC MULTI-TIER FINGERPRINT MANIFEST================================================================================ Target File: src/service.py Language: python Engine Version: canontra 0.4.0-------------------------------------------------------------------------------- Tier Fingerprint Digest (SHA-256)-------------------------------------------------------------------------------- F0 (Source Code): 8b1a9953c4611296a827abf8c47804d7... F1 (Normalized AST): 4c2d01a8e7f9331029b1c6d4a2e88109... F2 (Declaration Hierarchy): 91e4f0c27b8d4e15a6c3012f9b7e45d0... F3 (Dependency Graph): 3a7c8d9e1f02b4c5d6e7f8091a2b3c4d... FCG (Intra-Module Call Graph): 7f12a3b4c5d6e70891a2b3c4d5e6f708... FCF (Control-Flow Graph): 19e8d7c6b5a4938271605f4e3d2c1b0a... FDF (Data-Flow SSA Graph): 605f4e3d2c1b0a9f8e7d6c5b4a392817... FT (Type Contract): c1d2e3f4a5b60718293a4b5c6d7e8f90...-------------------------------------------------------------------------------- F4 (Composite Program Hash): f4e3d2c1b0a9f8e7d6c5b4a39281706f...================================================================================For scripts and CI pipelines, output JSON or only the composite F4 hash:
canontra fp src/service.py --jsoncanontra fp src/service.py --hash2. Read Code from Standard Input (canontra fp -)
Section titled “2. Read Code from Standard Input (canontra fp -)”Pipe source code directly from editors, pre-commit hooks, or generators without creating temporary files. Pass -l (--language) so Canontra knows which parser to use:
echo "def add(x: int, y: int) -> int: return x + y" | canontra fp - -l python --hashSupported -l values: python (py), typescript (ts), javascript (js), go, rust (rs).
3. Compare Two Files (canontra compare & canontra diff)
Section titled “3. Compare Two Files (canontra compare & canontra diff)”Compare two versions of a file to check whether program behavior actually changed:
canontra compare v1/service.ts v2/service.ts- Exit code
0: Behavior is semantically identical (F4matches), even if raw bytes (F0) changed due to comments, whitespace, local variable renames, safe math swaps, or flippedif/elsebranches. - Exit code
1: Behavior diverged (F4differs).
To see exactly which functions, imports, or graphs changed:
canontra diff v1/service.ts v2/service.tscanontra diff v1/service.ts v2/service.ts --json4. Find Affected Tests for a Pull Request (canontra impact)
Section titled “4. Find Affected Tests for a Pull Request (canontra impact)”Scan every changed file against a Git base branch and compute the smallest set of tests that can be affected:
canontra impact --pr-base main --jsonCanontra groups changed files into three impact levels:
- Level 1 (Cosmetic / Trivia):
F4did not change, so0tests are needed. - Level 2 (Internal Logic): Only internal function bodies changed (
F1,F_CF, orF_DF); public APIs (F2,F3,F_T) stayed identical, so only direct unit tests for that module need to run. - Level 3 (Public API / Imports): Public signatures, dependencies, or type contracts changed (
F2,F3, orF_T), so Canontra walks the cross-file call graph to find all affected callers and tests.
The JSON output includes birTestCommand (for example, pytest tests/test_billing.py), ready to run in CI. See impact & slice for the full output schema.