team-ljyzipelo

공개
58줄2.4 KB
1import hashlib
2import json
3from pathlib import Path, PurePosixPath
4import re
5import sys
6
7ROOT = Path(__file__).resolve().parents[2]
8HERE = Path(__file__).resolve().parent
9
10
11def sha(path):
12 return hashlib.sha256(path.read_bytes()).hexdigest()
13
14
15def main():
16 if sys.flags.optimize:
17 raise RuntimeError("최적화 모드에서는 검사할 수 없음")
18 if len(sys.argv) != 2 or re.fullmatch(r"[0-9a-f]{64}", sys.argv[1]) is None:
19 raise ValueError("별도 확인한 manifest SHA256 인수가 필요함")
20 manifest = HERE / "SHA256SUMS"
21 if sha(manifest) != sys.argv[1]:
22 raise ValueError("manifest 기대 hash 불일치")
23 data = manifest.read_bytes()
24 if not data.endswith(b"\n"):
25 raise ValueError("manifest 마지막 줄바꿈 누락")
26 names = set()
27 for row in data.decode("ascii").splitlines():
28 match = re.fullmatch(r"([0-9a-f]{64}) ([A-Za-z0-9_./-]+)", row)
29 if match is None:
30 raise ValueError("잘못된 hash 행")
31 expected, name = match.groups()
32 path = PurePosixPath(name)
33 if path.is_absolute() or str(path) != name or any(x in ("", ".", "..") for x in name.split("/")) or name in names:
34 raise ValueError("잘못된 경로 또는 중복")
35 names.add(name)
36 current = ROOT
37 for part in path.parts:
38 current = current / part
39 if current.is_symlink():
40 raise ValueError("symlink 거부")
41 if sha(current) != expected:
42 raise ValueError("파일 hash 불일치: " + name)
43 expected_names = set(json.loads((HERE / "files.json").read_text()))
44 if names != expected_names:
45 raise ValueError("누락 또는 추가 경로")
46 sources = json.loads((HERE / "sources.json").read_text())
47 for source in sources["files"]:
48 if sha(ROOT / source["path"]) != source["sha256"]:
49 raise ValueError("고정 source 불일치: " + source["path"])
50 contract = json.loads((HERE / "contract.json").read_text())
51 names = re.findall(r"#\[test\]\s*fn (\w+)", (HERE / "regressions.rs").read_text())
52 if len(names) != len(set(names)) or names != contract["validation"]["names"]:
53 raise ValueError("선언된 회귀 이름 불일치")
54 print(json.dumps({"static_files": len(expected_names), "upstream_files": len(sources["files"]), "declared_tests": len(names), "executed_tests": 0}))
55
56
57if __name__ == "__main__":
58 main()