Skip to content

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.

Run canontra fp on any supported source file (.py, .pyi, .js, .jsx, .mjs, .cjs, .ts, .tsx, .go, .rs):

Terminal window
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:

Terminal window
canontra fp src/service.py --json
canontra fp src/service.py --hash

2. 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:

Terminal window
echo "def add(x: int, y: int) -> int: return x + y" | canontra fp - -l python --hash

Supported -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:

Terminal window
canontra compare v1/service.ts v2/service.ts
  • Exit code 0: Behavior is semantically identical (F4 matches), even if raw bytes (F0) changed due to comments, whitespace, local variable renames, safe math swaps, or flipped if/else branches.
  • Exit code 1: Behavior diverged (F4 differs).

To see exactly which functions, imports, or graphs changed:

Terminal window
canontra diff v1/service.ts v2/service.ts
canontra diff v1/service.ts v2/service.ts --json

4. 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:

Terminal window
canontra impact --pr-base main --json

Canontra groups changed files into three impact levels:

  1. Level 1 (Cosmetic / Trivia): F4 did not change, so 0 tests are needed.
  2. Level 2 (Internal Logic): Only internal function bodies changed (F1, F_CF, or F_DF); public APIs (F2, F3, F_T) stayed identical, so only direct unit tests for that module need to run.
  3. Level 3 (Public API / Imports): Public signatures, dependencies, or type contracts changed (F2, F3, or F_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.