diff --git a/object_model_parity.py b/object_model_parity.py index 7a8de66..f4c31b6 100644 --- a/object_model_parity.py +++ b/object_model_parity.py @@ -26,6 +26,18 @@ else Path(__file__).resolve().parent.parent / "PyMEOS" / "pymeos" / "factory.py") + +def _oracle_id(path: Path) -> str: + """The oracle named by its place INSIDE PyMEOS, never by this machine. + + Where the file sits on a given disk is a property of the checkout, not of + the audit, so recording it makes the artefact differ between two machines + that read the very same oracle -- and a consumer that regenerates the file + to check for drift then sees drift that is not there. + """ + parts = path.resolve().parts + return "/".join(parts[-2:]) if len(parts) >= 2 else path.name + _SUBTYPE = {"INSTANT": "TINSTANT", "SEQUENCE": "TSEQUENCE", "SEQUENCE_SET": "TSEQUENCESET"} _TEMPORAL_RE = re.compile( @@ -76,7 +88,7 @@ def add(kind, detail, status, ref=None): if oracle is None: return { "status": "oracle-unavailable", - "oraclePath": str(PYMEOS), + "oraclePath": _oracle_id(PYMEOS), "note": "PyMEOS factory.py not found; reporting curated " "corrections only — no fabricated parity verdict.", "total": len(work), "aligned": 0, @@ -137,7 +149,7 @@ def add(kind, detail, status, ref=None): needs = [w for w in work if w["status"] == "needs-correction"] return { "status": "audited", - "oraclePath": str(PYMEOS), + "oraclePath": _oracle_id(PYMEOS), "total": len(work), "aligned": aligned_concrete, "divergences": len(work), diff --git a/tests/test_object_model_parity.py b/tests/test_object_model_parity.py index c5120f1..14656e4 100644 --- a/tests/test_object_model_parity.py +++ b/tests/test_object_model_parity.py @@ -17,7 +17,8 @@ sys.path.insert(0, str(ROOT)) from parser.object_model import attach_object_model -from object_model_parity import build_parity, _parse_oracle, PYMEOS +from object_model_parity import (build_parity, _parse_oracle, _oracle_id, + PYMEOS) MODEL = ROOT / "meta" / "object-model.json" _CATALOG = ROOT / "output" / "meos-idl.json" @@ -58,6 +59,21 @@ def test_audited_against_fake_oracle(self): self.assertEqual(rep["knownCorrections"] + rep["needsCorrection"], rep["divergences"]) + def test_oracle_is_named_by_its_place_not_by_this_machine(self): + """Two checkouts of the same oracle must yield the same artefact. + + The consumer regenerates this file to detect drift, so an oracle path + carrying the checkout's location reports drift between any two machines + reading the very same oracle -- and the drift gate can then never go + green. + """ + a = _oracle_id(Path("/home/someone/src/PyMEOS/pymeos/factory.py")) + b = _oracle_id(Path("/opt/build-7f3/PyMEOS/pymeos/factory.py")) + self.assertEqual(a, b) + self.assertEqual(a, "pymeos/factory.py") + self.assertNotIn("/home", a) + self.assertFalse(Path(a).is_absolute()) + def test_every_divergence_has_a_correction(self): oracle = _parse_oracle(PYMEOS) if oracle is None: