Skip to content

Commit 6d8f285

Browse files
committed
test: make gitlink the component version source of truth
1 parent 3655843 commit 6d8f285

1 file changed

Lines changed: 34 additions & 16 deletions

File tree

tests/template_acceptance.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22
from __future__ import annotations
33

4-
import hashlib
54
import json
65
import os
76
import stat
@@ -13,7 +12,13 @@
1312

1413

1514
def run(*args: str, cwd: Path | None = None) -> subprocess.CompletedProcess[str]:
16-
return subprocess.run(args, cwd=cwd or ROOT, text=True, capture_output=True, check=True)
15+
return subprocess.run(
16+
args,
17+
cwd=cwd or ROOT,
18+
text=True,
19+
capture_output=True,
20+
check=True,
21+
)
1722

1823

1924
def executable(path: Path) -> bool:
@@ -23,19 +28,19 @@ def executable(path: Path) -> bool:
2328
def main() -> None:
2429
wiring = json.loads((ROOT / "WIRING.json").read_text(encoding="utf-8"))
2530
assert wiring, "empty wiring"
26-
assert (ROOT / "template" / "_components").exists()
31+
components_root = (ROOT / "template" / "_components").resolve(strict=True)
2732
for rel, info in wiring.items():
2833
path = ROOT / "template" / rel
2934
kind = info["type"]
3035
if kind == "file-symlink":
3136
assert path.is_symlink(), f"not a symlink: {rel}"
32-
resolved = path.resolve(strict=True)
33-
assert "_components" in resolved.parts, f"outside submodule: {rel}"
34-
source = resolved
37+
source = path.resolve(strict=True)
3538
else:
3639
assert path.is_file() and not path.is_symlink(), rel
37-
source = ROOT / "template" / info["source"]
38-
assert hashlib.sha256(source.read_bytes()).hexdigest() == info["sha256"], rel
40+
source = (ROOT / "template" / info["source"]).resolve(strict=True)
41+
assert executable(path) == bool(info["executable"]), rel
42+
assert source.is_relative_to(components_root), f"outside submodule: {rel}"
43+
assert source.is_file(), f"missing component source: {rel}"
3944
assert executable(source) == bool(info["executable"]), rel
4045

4146
with tempfile.TemporaryDirectory() as td:
@@ -50,16 +55,29 @@ def main() -> None:
5055
text = file.read_text(encoding="utf-8")
5156
except UnicodeDecodeError:
5257
continue
53-
assert not ("<<<<<<< " in text and "\n=======\n" in text and "\n>>>>>>> " in text), file
54-
executable_outputs = [rel for rel, info in wiring.items() if info["executable"]]
58+
assert not (
59+
"<<<<<<< " in text
60+
and "\n=======\n" in text
61+
and "\n>>>>>>> " in text
62+
), file
63+
executable_outputs = [
64+
rel for rel, info in wiring.items() if info["executable"]
65+
]
5566
if executable_outputs and os.name != "nt":
5667
assert executable(out / executable_outputs[0]), executable_outputs[0]
57-
print(json.dumps({
58-
"repository": ROOT.name,
59-
"wiring_files": len(wiring),
60-
"rendered_files": sum(1 for path in out.rglob("*") if path.is_file()),
61-
"platform": os.name,
62-
}, sort_keys=True))
68+
print(
69+
json.dumps(
70+
{
71+
"repository": ROOT.name,
72+
"wiring_files": len(wiring),
73+
"rendered_files": sum(
74+
1 for path in out.rglob("*") if path.is_file()
75+
),
76+
"platform": os.name,
77+
},
78+
sort_keys=True,
79+
)
80+
)
6381

6482

6583
if __name__ == "__main__":

0 commit comments

Comments
 (0)