aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / tests / omegese45 / eval / mutants.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Mutation controls for the eval suite (aien-train #45). Standard library only. |
| 3 | |
| 4 | Each mutant copies eval/omegese45 to a temporary directory, disables exactly |
| 5 | one check by a literal source replacement, and reruns test_eval.py against |
| 6 | the copy (OE45_EVAL_DIR). A mutant is KILLED when the suite fails AND the |
| 7 | named test is among the failures. Prints `M <name> KILLED|SURVIVED` and |
| 8 | `OE45_EVAL_MUTANTS PASS|FAIL`. |
| 9 | """ |
| 10 | |
| 11 | import os |
| 12 | import shutil |
| 13 | import subprocess |
| 14 | import sys |
| 15 | import tempfile |
| 16 | |
| 17 | HERE = os.path.dirname(os.path.abspath(__file__)) |
| 18 | EVAL = os.path.abspath(os.path.join(HERE, "..", "..", "..", "eval", "omegese45")) |
| 19 | |
| 20 | # (name, file, literal old, literal new, test that must fail) |
| 21 | MUTANTS = [ |
| 22 | ("skip_independent_recompute", "oe_an0.py", |
| 23 | 'rec("recompute.output_digest", r["output_digest"] == want,', |
| 24 | 'rec("recompute.output_digest", True,', |
| 25 | "checkdemo.neg.output_digest_resigned"), |
| 26 | ("accept_missing_response", "check-demo", |
| 27 | 'rep.ok("english.present", False,', |
| 28 | 'rep.ok("english.present", True,', |
| 29 | "checkdemo.neg.missing_response"), |
| 30 | ("accept_high_s", "oe_an0.py", |
| 31 | " if s > N // 2:\n", |
| 32 | " if False:\n", |
| 33 | "real.neg.high_s_refused"), |
| 34 | ("ignore_english_seeds", "oe_en.py", |
| 35 | 'rec("english.seeds", claim["seeds"] == tuple(goal.seeds),', |
| 36 | 'rec("english.seeds", True,', |
| 37 | "checkdemo.neg.english_number"), |
| 38 | ("ignore_facts_order", "check-demo", |
| 39 | ' return "row%d job %d after its ok" % (i + 1, r["job"])\n', |
| 40 | ' pass\n', |
| 41 | "checkdemo.neg.facts_row_after_ok"), |
| 42 | ("accept_malformed_nonok_dag", "check-demo", |
| 43 | " if r[c] != \"-\" and not _hex(r[c], 64):\n", |
| 44 | " if False:\n", |
| 45 | "checkdemo.neg.facts_nonok_dag_short"), |
| 46 | ("replace_trust_root", "check-demo", |
| 47 | 'rep.ok("keys.trust_root", trusted,', |
| 48 | 'rep.ok("keys.trust_root", True,', |
| 49 | "checkdemo.neg.regenerated_keys"), |
| 50 | ("ignore_refuse_position", "oe_episode.py", |
| 51 | ' return "refuse-not-sole-first-A-followed-by-bound-P"\n', |
| 52 | ' return None\n', |
| 53 | "checkdemo.neg.refuse_then_job"), |
| 54 | ("terminal_job_binding_crash", "oe_episode.py", |
| 55 | ' if j is None:\n', |
| 56 | ' if False:\n', |
| 57 | "checkdemo.neg.binding_no_current_job"), |
| 58 | ("ignore_nonok_runtime", "check-demo", |
| 59 | 'why = nonok_runtime_rule(case, row)', |
| 60 | 'why = None', |
| 61 | "checkdemo.neg.replay_after_real_execution"), |
| 62 | ("ignore_replay_seen", "check-demo", |
| 63 | ' return "replay dag is not done in worker/seen"\n', |
| 64 | ' return None\n', |
| 65 | "checkdemo.neg.replay_missing_done"), |
| 66 | ] |
| 67 | |
| 68 | |
| 69 | def main(): |
| 70 | fails = [] |
| 71 | for name, fname, old, new, must_fail in MUTANTS: |
| 72 | with tempfile.TemporaryDirectory(prefix="oe45-mutant-") as tmp: |
| 73 | d = os.path.join(tmp, "omegese45") |
| 74 | shutil.copytree(EVAL, d, ignore=shutil.ignore_patterns("__pycache__")) |
| 75 | p = os.path.join(d, fname) |
| 76 | src = open(p).read() |
| 77 | if src.count(old) != 1: |
| 78 | print("M %s SURVIVED mutation site not unique (count=%d)" % (name, src.count(old))) |
| 79 | fails.append(name) |
| 80 | continue |
| 81 | open(p, "w").write(src.replace(old, new)) |
| 82 | env = dict(os.environ, OE45_EVAL_DIR=d, PYTHONDONTWRITEBYTECODE="1") |
| 83 | r = subprocess.run([sys.executable, os.path.join(HERE, "test_eval.py")] + sys.argv[1:], |
| 84 | capture_output=True, text=True, env=env) |
| 85 | failed = [l.split()[1] for l in r.stdout.splitlines() if l.startswith("T ") and l.split()[2] == "FAIL"] |
| 86 | killed = r.returncode != 0 and must_fail in failed |
| 87 | print("M %s %s rc=%d failed=%s" % (name, "KILLED" if killed else "SURVIVED", r.returncode, |
| 88 | ",".join(failed))) |
| 89 | if not killed: |
| 90 | fails.append(name) |
| 91 | print("OE45_EVAL_MUTANTS %s %s" % ("FAIL" if fails else "PASS", " ".join(fails))) |
| 92 | return 1 if fails else 0 |
| 93 | |
| 94 | |
| 95 | if __name__ == "__main__": |
| 96 | sys.exit(main()) |