Skip to content

compare & diff

canontra compare <FILE1> <FILE2> [--diff] [--json]
canontra diff <FILE1> <FILE2> [--json]
  • compare: Computes all 9 fingerprints (F0 through F4) for both files, marks each tier as Identical or Different, and exits 0 when composite F4 matches or 1 when F4 differs.
  • diff: Parses both files into normalized IR and lists exact changes in declarations, imports, AST structure, call graph, control flow (CFG), and data flow (DFG). Passing --diff to compare prints the same detailed breakdown.

diff also accepts - to read one side from standard input.

Flag Short Applies To Default Description
--diff - compare false Show detailed function and graph changes alongside tier status
--json - compare, diff false Print ComparisonResult or DiffResult as JSON

compare exits 0 when crComposite == Identical, and 1 when crComposite == Different. diff exits 0 only when crComposite == Identical and all six change lists (declaration, dependency, structural, call_graph, cfg, dfg) are empty; otherwise it exits 1.

{
"target_a": "original.py",
"target_b": "modified.py",
"source": "Different",
"structural": "Identical",
"declaration": "Identical",
"dependency": "Identical",
"call_graph": "Identical",
"control_flow": "Identical",
"data_flow": "Identical",
"type_contract": "Identical",
"composite": "Identical"
}
  • Exit 0: Semantically identical.
  • Exit 1: Semantic difference found.
  • Exit 3: Parse error in either file.
  • Exit 4: Missing file or path outside the project root.
Terminal window
# CI gate: fails only when program behavior changed
canontra compare v1/billing.py v2/billing.py
# Inspect exact functions and graphs that changed
canontra diff v1/billing.py v2/billing.py --json