idea193-proofweave-proof-ca.../tests/test_compile.py

38 lines
1.1 KiB
Python

import json
import os
import tempfile
from proofweave.compiler import compile_genome
def test_compile_creates_files(tmp_path):
genome = {
"parent_hash": None,
"delta_hash": "abc123",
"mutation_policy": {"max_cpu_ms": 100},
"toolchain_digest": "toy-compiler-0.1",
"authors": ["tester"],
"resource_envelope": {"cpu_ms": 5, "memory_bytes": 32768},
"allowed_syscalls": ["read", "net:egress"],
}
out = tmp_path / "out"
out.mkdir()
res = compile_genome(genome, str(out))
# Verify files exist
for key in ("manifest", "wasm", "proof_summary"):
assert key in res
assert os.path.exists(res[key])
# Validate manifest contents
with open(res["manifest"], "r", encoding="utf-8") as f:
manifest = json.load(f)
assert manifest["delta_hash"] == "abc123"
assert manifest["toolchain_digest"] == "toy-compiler-0.1"
# Validate proof summary
with open(res["proof_summary"], "r", encoding="utf-8") as f:
proof = json.load(f)
assert proof["resource_cert"]["cpu_ms"] == 5
assert isinstance(proof["summary_fingerprint"], str)