"""The ten pilot tasks (L1) are a recorded experiment: their instances must not change. The fingerprints were computed inside the pilot image (sha256:7158ba87...).""" import hashlib import json import os import random import pytest from terminal_desk.families import ALL_FAMILIES, instance_seed PINNED = json.load(open(os.path.join(os.path.dirname(__file__), "fixtures", "pilot_fingerprints.json"))) def fingerprint(task_id: str) -> str: base = task_id.rsplit("-i", 1)[0] if "-i" in task_id.rsplit("-L", 1)[1] else task_id fid, lv = base.rsplit("-L", 1) b = ALL_FAMILIES[fid].build(int(lv), random.Random(instance_seed(task_id))) 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()) return h.hexdigest()[:16] @pytest.mark.parametrize("task_id", sorted(PINNED)) def test_pilot_instance_unchanged(task_id): assert fingerprint(task_id) == PINNED[task_id]