From b40f1428fdffb1ad4ef8b365cd946401d9a3213f Mon Sep 17 00:00:00 2001 From: Albrecht Degering Date: Mon, 3 Aug 2026 01:12:41 +0200 Subject: [PATCH] Resolve backend inventory from checkout --- tests/test_platform_interface_inventory.py | 22 ++++++++++++++++++ .../inventory/platform-interface-inventory.py | 23 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/test_platform_interface_inventory.py b/tests/test_platform_interface_inventory.py index 198a27f..dadfcc7 100644 --- a/tests/test_platform_interface_inventory.py +++ b/tests/test_platform_interface_inventory.py @@ -21,6 +21,28 @@ SPEC.loader.exec_module(inventory) class PlatformInterfaceInventoryTests(unittest.TestCase): + def test_workspace_resolution_prefers_populated_checkout_siblings(self) -> None: + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + sibling = root / "checkout" + meta = sibling / "govoplan" + configured = root / "configured" + (sibling / "govoplan-core" / "src").mkdir(parents=True) + (configured / "govoplan-core").mkdir(parents=True) + previous = inventory.META_ROOT + inventory.META_ROOT = meta + try: + resolved = inventory._resolve_workspace_root( + { + "default_parent": str(configured), + "repositories": [{"path": "govoplan-core"}], + } + ) + finally: + inventory.META_ROOT = previous + + self.assertEqual(sibling.resolve(), resolved) + def test_canonical_api_path_normalizes_versions_and_parameters(self) -> None: self.assertEqual( inventory.canonical_api_path( diff --git a/tools/inventory/platform-interface-inventory.py b/tools/inventory/platform-interface-inventory.py index 70d07e8..51ef334 100644 --- a/tools/inventory/platform-interface-inventory.py +++ b/tools/inventory/platform-interface-inventory.py @@ -54,7 +54,7 @@ def main() -> int: args = parser.parse_args() catalog = json.loads((META_ROOT / "repositories.json").read_text(encoding="utf-8")) - workspace_root = Path(catalog["default_parent"]).resolve() + workspace_root = _resolve_workspace_root(catalog) webui = _extract_webui() backend_endpoints = _extract_backend_endpoints(catalog, workspace_root) manifests = _extract_manifests(catalog, workspace_root) @@ -103,6 +103,27 @@ def main() -> int: return 0 +def _resolve_workspace_root(catalog: dict[str, Any]) -> Path: + sibling_root = META_ROOT.parent.resolve() + configured_root = Path(str(catalog["default_parent"])).expanduser().resolve() + repositories = catalog.get("repositories") + if not isinstance(repositories, list): + raise ValueError("repository catalog has no repositories array") + + def source_count(root: Path) -> int: + return sum( + 1 + for item in repositories + if isinstance(item, dict) + and isinstance(item.get("path"), str) + and (root / item["path"] / "src").is_dir() + ) + + sibling_count = source_count(sibling_root) + configured_count = source_count(configured_root) + return sibling_root if sibling_count >= configured_count else configured_root + + def _extract_webui() -> dict[str, Any]: helper = META_ROOT / "tools" / "inventory" / "extract-webui-structure.mjs" completed = subprocess.run(