Skip to content

Graph-level roundtrip invariant test for reconstruct path #4

Description

@pedroanisio

Context

codebase_mapper/reconstruct.py (136 lines) materializes a working tree from inventory.ttl + the blobs/ directory. We have tests/verify_roundtrip.py for byte-identical blob-based roundtrip, but no invariant test that asserts the round-trip preserves the RDF graph itself.

The code-mapper bundle (analyzed in this session) carries tests/test_python_parser.py::TestRoundTrip.test_roundtrip_preserves_structure — exactly this shape: parse → re-serialize → re-parse → assert structural equality.

PALS's law (per CLAUDE.md): absence of an invariant test for the reconstruct path is an architectural omission.

Scope

Add tests/verify_reconstruct_invariant.py:

  1. Run the pipeline against a small fixture repo (existing static/schemas/ works as a low-content target, or a synthetic 2-file Python repo).
  2. Capture the emitted inventory.ttl.
  3. Reconstruct the working tree via codebase_mapper.reconstruct.
  4. Re-run the pipeline against the reconstructed tree.
  5. Assert the two RDF graphs are isomorphic (or hash-equal under canonical N-Triples sorting).

Implementation notes

  • Use rdflib.compare.isomorphic for the graph-equality check — handles blank-node renaming.
  • Or simpler: sort N-Triples lines after canonicalization and compare line-by-line.
  • The test should be fast (<5 seconds) — keep the fixture tiny.

Failure modes to catch

  • Reconstruct loses a predicate that was emitted by some plugin.
  • Reconstruct re-emits a predicate with a different blank-node ID that doesn't canonicalize.
  • The blob-content path round-trips bytes but a metadata predicate (e.g. cbm:size) is computed differently the second time.

Acceptance

The verifier passes today (or fails loudly with a diff of triples that differ). Then add it to the README ## Verify section's run list.

Related

  • tests/verify_roundtrip.py (existing) — byte-level
  • tests/verify_regenerate.py (existing) — TTL+AST regeneration semantic vs byte fidelity
  • This issue: graph-level invariant — the third corner of the triangle

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions