Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions parser/object_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,25 @@ class is invented; a function with no prefix match is recorded honestly as
def find_mobilitydb_src(headers_dir: Path | None = None) -> Path | None:
"""Resolve the MobilityDB C source root for the error scan / drift gate.

First existing of: $MOBILITYDB_SRC, the sparse-checkout
``_mobilitydb/meos/src``, or the ``src`` sibling of the headers dir.
Returns None when no source tree is available — callers must degrade to
an honest signal, never fabricate.
First existing of: $MOBILITYDB_SRC, the checkout $MDB_SRC_ROOT names, the
sparse-checkout ``_mobilitydb/meos/src``, or the ``src`` sibling of the
headers dir. Returns None when no source tree is available — callers must
degrade to an honest signal, never fabricate.

``MDB_SRC_ROOT`` is the checkout the provisioning hands the parse, and it is
consulted because the directory name is the provisioner's to choose: the CI
action checks MobilityDB out as ``_mobilitydb_src`` while the probe below
names ``_mobilitydb``, so a resolver that knows only the literal name reports
no source over a tree that is present, and every catalog it derives silently
loses what the source carries.
"""
candidates = []
env = os.environ.get("MOBILITYDB_SRC")
if env:
candidates.append(Path(env))
root = os.environ.get("MDB_SRC_ROOT")
if root:
candidates.append(Path(root) / "meos" / "src")
candidates.append(Path("_mobilitydb") / "meos" / "src")
if headers_dir is not None:
candidates.append(Path(headers_dir).parent / "src")
Expand Down
48 changes: 48 additions & 0 deletions tests/test_object_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import json
import os
import re
import sys
import tempfile
Expand Down Expand Up @@ -252,6 +253,53 @@ def _enum_block(text: str, end_marker: str) -> dict:
re.findall(r"\b([A-Z][A-Z0-9_]+)\s*=\s*(\d+)", block)}


class SourceRootResolutionTest(unittest.TestCase):
"""The resolver answers over the checkout the provisioning names.

The directory name belongs to the provisioner: the CI action checks MobilityDB
out as ``_mobilitydb_src`` and hands the parse ``MDB_SRC_ROOT``, while the
literal probe names ``_mobilitydb``. A resolver reading only the literal name
reports no source over a tree that is present, and the catalog then carries
neither the object model nor the type relations the source states.
"""

def _tree(self, d):
src = Path(d) / "meos" / "src" / "temporal"
src.mkdir(parents=True)
(src / "meos_catalog.c").write_text("/* catalog */\n")
return Path(d)

def test_provisioned_root_resolves_whatever_the_directory_is_called(self):
with tempfile.TemporaryDirectory() as d:
root = self._tree(Path(d) / "_mobilitydb_src")
saved = {k: os.environ.pop(k, None) for k in ("MOBILITYDB_SRC", "MDB_SRC_ROOT")}
try:
os.environ["MDB_SRC_ROOT"] = str(root)
self.assertEqual(find_mobilitydb_src(), root / "meos" / "src")
finally:
for k, v in saved.items():
if v is None:
os.environ.pop(k, None)
else:
os.environ[k] = v

def test_no_source_still_answers_none(self):
# From a directory holding no checkout, so the relative `_mobilitydb`
# probe cannot answer and the result is the resolver's own.
saved = {k: os.environ.pop(k, None) for k in ("MOBILITYDB_SRC", "MDB_SRC_ROOT")}
cwd = os.getcwd()
try:
os.environ["MDB_SRC_ROOT"] = "/no/such/checkout"
with tempfile.TemporaryDirectory() as empty:
os.chdir(empty)
self.assertIsNone(find_mobilitydb_src())
finally:
os.chdir(cwd)
for k, v in saved.items():
if v is not None:
os.environ[k] = v


_SRC = find_mobilitydb_src(ROOT / "meos" / "include")
_CAT_C = (_SRC / "temporal" / "meos_catalog.c") if _SRC else None

Expand Down
Loading