mjdi docsv0.10.0latest
Graph diff: comparing two exports (P1-03)
scripts/graph_diff.py compares two mjdi.graph/1 exports and reports
Source: mjdi/docs/graph-diff.md
scripts/graph_diff.py compares two mjdi.graph/1 exports and reports
the architectural drift between them, with CI-friendly exit codes.
python3 scripts/graph_diff.py tests/fixtures/graph_before.json \
tests/fixtures/graph_after.json
What it detects
- added / removed services,
- added / removed dependencies (Inject and alias edges),
- changed provider kinds (class ↔ value ↔ factory ↔ alias),
- changed effective lifetimes (transient ↔ singleton ↔ scoped),
- changed alias targets,
- changed dependency relationships (an edge's provider kind, lifetime, or provided status),
- Copyable flag changes (graph metadata; a service becoming cached is reported through the lifetime change).
Output formats and exit codes
text(default): a human-readable terminal report, grouped by category.--format json: a structured diff (schema: "mjdi.graph/1/diff").--summary: append a one-line change-count summary.- exit
0— no differences; exit1— differences found (strict mode, the default); exit2— usage or input error (unreadable file, wrong schema).
Options
--warn: report differences but exit 0 (warning mode).--ignore CATEGORY[,CATEGORY...]: drop selected categories —services_added,services_removed,deps_added,deps_removed,provider_kind_changed,lifetime_changed,alias_target_changed,edge_changed,copyable_changed.
The CI guard
A pipeline can fail the build when an unintended architectural change lands:
- name: Fail on unintended architecture drift
run: |
python3 scripts/graph_diff.py \
tests/fixtures/graph_before.json \
tests/fixtures/graph_after.json \
--ignore services_added # planned additions are allowed
The checked-in fixtures are real mjdi exports of two snapshots of
one application registry (see tools/graph_export.mojo): a service
removed, a cache added, a repo's lifetime changed transient → singleton,
and a new dependency. tests/python/test_graph_diff.py pins every
category, the exit codes, the ignore flags, and the JSON format.
Related
- Graph export — producing the exports this tool compares.
- Graph visualization — inspecting either snapshot interactively.