Resolve backend inventory from checkout
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user