70 lines
3.6 KiB
Python
70 lines
3.6 KiB
Python
"""Read-only raw-archive validation. Does not execute any binary or rewrite files."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
base = Path(__file__).resolve().parent
|
|
|
|
def read(path):
|
|
return json.loads(path.read_text(encoding="utf-8"))
|
|
|
|
def sha(path):
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
def tree(path):
|
|
return {p.relative_to(path).as_posix(): sha(p) for p in path.rglob("*") if p.is_file()}
|
|
|
|
manifest = read(base / "manifest.json")
|
|
expected = {item["path"] for item in manifest["files"]}
|
|
assert set(tree(base)) == expected | {"manifest.json", "readback.json"}
|
|
for item in manifest["files"]:
|
|
path = base / item["path"]
|
|
assert path.stat().st_size == item["bytes"] and sha(path) == item["sha256"], item["path"]
|
|
assert sha(base / "manifest.json") == read(base / "readback.json")["manifestSha256"]
|
|
|
|
fixtures = read(base / "fixture-manifest.json")
|
|
assert len(fixtures["files"]) == 64
|
|
assert tree(base / "fixtures") == {item["path"]: item["sha256"] for item in fixtures["files"]}
|
|
screenshots = base / "trial/screenshots"
|
|
metadata = sorted(screenshots.glob("*.json"))
|
|
assert len(metadata) == 20
|
|
images = set()
|
|
for index, path in enumerate(metadata, 1):
|
|
assert path.name.startswith(f"{index:02d}-")
|
|
value = read(path)
|
|
assert len(value["screenshots"]) == 1
|
|
image = value["screenshots"][0]
|
|
assert (image["width"], image["height"]) == (1442, 932)
|
|
images.add(image["file"])
|
|
assert images == {p.name for p in screenshots.glob("*.jpg")}
|
|
|
|
checkpoints = base / "trial/checkpoints"
|
|
directories = sorted(p for p in checkpoints.iterdir() if p.is_dir())
|
|
assert len(directories) == 7
|
|
saved = {}
|
|
for directory in directories:
|
|
snapshot = read(directory / "snapshot.json")
|
|
assert tree(directory / "sources") == snapshot["files"], directory.name
|
|
assert snapshot["arcadiaFiles"] == 4 and snapshot["binaryFilesUnchanged"]
|
|
assert snapshot["pendingJournalExists"] == (directory.name == "recovery-open-journal")
|
|
if directory.name.endswith("final-saved"):
|
|
receipt = read(directory / "oracle.json")
|
|
assert receipt["exitCode"] == 0 and receipt["afterVisibleSaveConfirmedByCaller"]
|
|
assert receipt["files"] == snapshot["files"] == tree(base / "fixtures/valid")
|
|
assert receipt["oracleSha256"] == "967d9ba3c6fb3a7efb410833903ec94556ca2d48a67d5072c8bb160f40a00f9c"
|
|
assert (directory / "oracle.stderr.log").read_bytes() == b""
|
|
output = (directory / "oracle.stdout.log").read_text(encoding="utf-8")
|
|
assert "4" in output and "PASS" in output
|
|
saved[directory.name] = receipt["atUtc"]
|
|
assert len(saved) == 3
|
|
for label, fixture in {"missing-after-apply-before-save": "missing-include", "duplicate-after-apply-before-save": "ambiguous", "recovery-open-journal": "recovery", "recovery-after-rollback-before-save": "recovery-expected-before"}.items():
|
|
assert tree(checkpoints / label / "sources") == tree(base / "fixtures" / fixture), label
|
|
|
|
launch = read(base / "trial/launch.json")
|
|
closed = read(base / "trial/binary-after-close.json")
|
|
assert launch["pid"] == 10016 and launch["sourceCommit"] == "33c6d83e9ba9a5b1310b1b627d7c40affcbcf15c"
|
|
assert launch["binarySha256"] == closed["files"]["arcadia-studio.exe"] == "b183ef31f16b3986538b3f2aba8435eab45978635c47f99ca01be6e72b168848"
|
|
assert closed["unchanged"] and closed["absenceObservedByCaller"]
|
|
assert (base / "trial/stdout.log").read_bytes() == (base / "trial/stderr.log").read_bytes() == b""
|
|
print(json.dumps({"passed": True, "payloadFiles": len(expected), "fixtureFiles": 64, "screenshots": 20, "checkpoints": 7, "savedOracleReceipts": saved, "numericProcessExitCode": None}))
|