Просмотр исходного кода

fix(snapshot): reject manifest self-reference

root 3 месяцев назад
Родитель
Сommit
9a60eae608
3 измененных файлов с 21 добавлено и 5 удалено
  1. 3 2
      README.md
  2. 9 1
      tests/test_manifest.py
  3. 9 2
      tools/manifest_cli.py

+ 3 - 2
README.md

@@ -5,8 +5,9 @@ Android Repo-style manifests for the Prod2U thermal workspace. XML is the only r
 ```sh
 ./tools/manifest-lint manifests/products/6400-front-rear.xml
 ./tools/ws list manifests/products/6400-front-rear.xml
-./tools/snapshot-create manifests/products/6400-front-rear.xml manifests/snapshots/6400-front-rear/development.xml
-./tools/snapshot-verify manifests/snapshots/6400-front-rear/development.xml
+./tools/snapshot-create manifests/products/6400-front-rear.xml /data/prod2u/deliveries/prod2u-6400-v1.0.0-rc2/manifests/6400-front-rear.snapshot.xml
+./tools/snapshot-verify /data/prod2u/deliveries/prod2u-6400-v1.0.0-rc2/manifests/6400-front-rear.snapshot.xml
 ```
 
 Snapshot creation is fail-closed: every repository must exist, be clean, and have a resolvable HEAD.
+The output must stay outside every snapshotted repository so the Manifest repository can be bound without a self-reference cycle.

+ 9 - 1
tests/test_manifest.py

@@ -3,7 +3,7 @@ import tempfile
 
 import pytest
 
-from tools.manifest_cli import lint
+from tools.manifest_cli import create_snapshot, lint
 
 
 ROOT = Path(__file__).resolve().parents[1]
@@ -47,3 +47,11 @@ def test_floating_snapshot_is_rejected() -> None:
         )
         with pytest.raises(ValueError, match="full SHA"):
             lint(path, snapshot=True)
+
+
+def test_snapshot_output_inside_snapshotted_repository_is_rejected() -> None:
+    with pytest.raises(ValueError, match="outside every snapshotted repository"):
+        create_snapshot(
+            ROOT / "manifests/products/6400-front-rear.xml",
+            ROOT / "manifests/snapshots/6400-front-rear/development.xml",
+        )

+ 9 - 2
tools/manifest_cli.py

@@ -71,11 +71,18 @@ def lint(path: Path, snapshot: bool = False) -> list[ET.Element]:
 
 def create_snapshot(source: Path, output: Path) -> None:
     projects = lint(source)
+    output = output.resolve()
+    checkouts = [(project, (WORKSPACE / project.get("path", "")).resolve()) for project in projects]
+    for project, checkout in checkouts:
+        if output.is_relative_to(checkout):
+            raise ValueError(
+                "snapshot output must be outside every snapshotted repository: "
+                f"{project.get('name')} contains {output}"
+            )
     rows: list[tuple[str, str, str, str]] = []
-    for project in projects:
+    for project, checkout in checkouts:
         name = project.get("name", "")
         repo_path = project.get("path", "")
-        checkout = WORKSPACE / repo_path
         if not (checkout / ".git").exists():
             raise ValueError(f"repository missing: {checkout}")
         if git(checkout, "status", "--porcelain"):