| 1 | import hashlib |
| 2 | import json |
| 3 | from pathlib import Path, PurePosixPath |
| 4 | import re |
| 5 | import stat |
| 6 | import sys |
| 7 | import tomllib |
| 8 | |
| 9 | ROOT = Path(__file__).resolve().parents[2] |
| 10 | HERE = Path(__file__).resolve().parent |
| 11 | |
| 12 | |
| 13 | def require(value, message): |
| 14 | if not value: |
| 15 | raise ValueError(message) |
| 16 | |
| 17 | |
| 18 | def digest(path): |
| 19 | return hashlib.sha256(path.read_bytes()).hexdigest() |
| 20 | |
| 21 | |
| 22 | def checked_path(name, base): |
| 23 | path = PurePosixPath(name) |
| 24 | require(not path.is_absolute() and str(path) == name, "상대 경로가 아님") |
| 25 | require(all(part not in ("", ".", "..") for part in name.split("/")), "경로 요소 오류") |
| 26 | current = base |
| 27 | for part in path.parts: |
| 28 | current = current / part |
| 29 | require(not current.is_symlink(), "symlink 입력 거부") |
| 30 | require(stat.S_ISREG(current.lstat().st_mode), "일반 파일이 아님") |
| 31 | return current |
| 32 | |
| 33 | |
| 34 | def main(): |
| 35 | require(not sys.flags.optimize, "일반 Python 모드가 필요함") |
| 36 | require(len(sys.argv) == 2 and re.fullmatch(r"[0-9a-f]{64}", sys.argv[1]), "manifest hash 필요") |
| 37 | require(digest(HERE / "SHA256SUMS") == sys.argv[1], "manifest hash 불일치") |
| 38 | contract = json.loads((HERE / "contract.json").read_text()) |
| 39 | seen = set() |
| 40 | data = (HERE / "SHA256SUMS").read_text() |
| 41 | require(data.endswith("\n"), "manifest 끝 줄바꿈 누락") |
| 42 | for line in data.splitlines(): |
| 43 | match = re.fullmatch(r"([0-9a-f]{64}) ([A-Za-z0-9_./-]+)", line) |
| 44 | require(match is not None, "manifest 행 오류") |
| 45 | expected, name = match.groups() |
| 46 | require(name not in seen, "manifest 중복") |
| 47 | seen.add(name) |
| 48 | require(digest(checked_path(name, HERE)) == expected, "시험 입력 hash 불일치: " + name) |
| 49 | require(seen == set(contract["deliverables"]) - {"SHA256SUMS"}, "manifest 파일 집합 불일치") |
| 50 | pins = json.loads((HERE / "source-pins.json").read_text()) |
| 51 | paths = set() |
| 52 | for entry in pins["files"]: |
| 53 | require(entry["path"] not in paths, "source 중복") |
| 54 | paths.add(entry["path"]) |
| 55 | path = checked_path(entry["path"], ROOT) |
| 56 | raw = path.read_bytes() |
| 57 | blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() |
| 58 | require(blob == entry["git_blob"] and digest(path) == entry["sha256"], "source pin 불일치: " + entry["path"]) |
| 59 | mode = "100755" if path.stat().st_mode & 0o111 else "100644" |
| 60 | require(mode == entry["mode"], "source mode 불일치") |
| 61 | test_source = (HERE / "linux_loader.rs").read_text() |
| 62 | names = re.findall(r"#\[test\]\s*fn (\w+)", test_source) |
| 63 | require(names == contract["new_tests"], "신규 선언 이름 불일치") |
| 64 | require('#[path = "../../experiments/rust-ui-memory-app/src/system_font.rs"]' in test_source, "원본 모듈 재사용 누락") |
| 65 | require('#![cfg(target_os = "linux")]' in test_source, "Linux 시험 경계 누락") |
| 66 | original = json.loads((ROOT / "tests/rust-ui-memory-app/contract.json").read_text()) |
| 67 | old_source = (ROOT / "tests/rust-ui-memory-app/regressions.rs").read_text() |
| 68 | old_names = re.findall(r"#\[test\]\s*fn (\w+)", old_source) |
| 69 | require(old_names == original["validation"]["names"], "기존 UI 선언 불일치") |
| 70 | require(sorted(old_names) == contract["reused_ui_tests"] and len(old_names) == 31, "재사용 UI 이름 불일치") |
| 71 | app = (ROOT / "experiments/rust-ui-memory-app/src/app.rs").read_text() |
| 72 | mapping = "system_font::load().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?" |
| 73 | require(mapping in app and app.index(mapping) < app.index("eframe::run_native("), "AppCreation 정적 경계 변경") |
| 74 | require("FontData::from_owned(font.bytes)" in app and "data.index = font.face_index;" in app, "폰트 값 연결 변경") |
| 75 | historical = app.replace('#[path = "system_font.rs"]\nmod system_font;\n\n', "", 1) |
| 76 | historical = historical.replace( |
| 77 | "let font = " + mapping + ";", |
| 78 | 'let font = std::fs::read("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc")\n' |
| 79 | " .map_err(|e| eframe::Error::AppCreation(Box::new(e)))?;", 1) |
| 80 | historical = historical.replace("FontData::from_owned(font.bytes)", "FontData::from_owned(font)", 1) |
| 81 | historical = historical.replace("data.index = font.face_index;", "data.index = 1;", 1) |
| 82 | require(hashlib.sha256(historical.encode()).hexdigest() == contract["base_app_sha256"], "폰트 외 UI 변경 발견") |
| 83 | manifest = tomllib.loads((HERE / "Cargo.toml").read_text()) |
| 84 | require(not manifest.get("dependencies") and not manifest.get("dev-dependencies"), "신규 의존성 발견") |
| 85 | lock = tomllib.loads((HERE / "Cargo.lock").read_text()) |
| 86 | require([p["name"] for p in lock["package"]] == ["zipelo-ui-system-font-regressions"], "loader lock graph 변경") |
| 87 | print(json.dumps({"source_pins": len(paths), "new_tests_declared": len(names), |
| 88 | "reused_ui_tests_declared": len(old_names), "rust_compiled": False, |
| 89 | "rust_executed": False, "app_creation_evidence": "static-only"})) |
| 90 | |
| 91 | |
| 92 | if __name__ == "__main__": |
| 93 | main() |