skills-desk / source /tests /test_determinism.py
Syndicate604's picture
Skills Desk v1: 40 training tasks, 20 reserved evaluation tasks (frozen)
a785ccd verified
Raw History Blame Contribute Delete
1.44 kB
"""Every task id builds byte-identical files in any process. Python's set and dict-of-set iteration
order depends on hash randomisation, so two containers could otherwise serve different layouts of
the same task id. Builds everything under two hash seeds and compares."""
import json
import os
import subprocess
import sys
SCRIPT = r'''
import hashlib, json, random, sys
sys.path.insert(0, ".")
from terminal_desk.families import ALL_FAMILIES, instance_seed, all_task_ids, reserved_task_ids
out = {}
for t in all_task_ids() + reserved_task_ids():
fid, lv = t.rsplit("-L", 1)
for k in range(2):
tid = t + (f"-i{k}" if k else "")
b = ALL_FAMILIES[fid].build(int(lv), random.Random(instance_seed(tid)))
h = hashlib.sha256(b.instruction.encode())
for name in sorted(b.files):
c = b.files[name]; h.update(name.encode()); h.update(c if isinstance(c, bytes) else c.encode())
out[tid] = h.hexdigest()
print(json.dumps(out))
'''
def build_all(seed: str) -> dict:
root = os.path.join(os.path.dirname(__file__), "..")
env = {**os.environ, "PYTHONHASHSEED": seed, "PYTHONPATH": root}
out = subprocess.run([sys.executable, "-c", SCRIPT], cwd=root, env=env, capture_output=True, text=True, check=True)
return json.loads(out.stdout)
def test_builds_do_not_depend_on_hash_seed():
a, b = build_all("1"), build_all("12345")
assert [k for k in a if a[k] != b[k]] == []