QA defects D314-1 and D314-2 on the integrated Train A tree. D314-1: the golden runner had no branch for the raw_text malformed-input case (malformed_input_exit3); it now parses raw_text itself and expects exit 3 as the golden file states. D314-2: expected keys the tool did not compute were skipped but the case was counted as passed. Now every expected key is checked or the case is SKIPPED and counted separately; the summary prints "cases: N passed: P skipped: S failed: F" and `golden` exits 1 when a case is skipped unless --allow-skips is given. Newly computed: forbidden_tokens (on the printed output), mention (refusal message), blind_sd + forbidden_key_prefixes (new blind-sd sub-command, first 6 valid pairs, no mean), null_simulation (new simulate-null sub-command, own float path, seeded), --look K, series_b variants (permutation / unit-scale invariance). Unknown argv flags and unknown expected keys make a case SKIPPED. Still independent of series_eval.py and component_class.py; the golden file is only read, not committed here. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
499 lines
27 KiB
Python
499 lines
27 KiB
Python
"""Tests of the independent verdict recomputation (STRA-314, SDET).
|
|
|
|
Run from the repository root:
|
|
python -m unittest scripts.e2e.evidence.test_recompute_verdict -v
|
|
|
|
Expected values here come from three routes that do not use the code under test:
|
|
published Student-t table values, the closed-form t distribution for integer
|
|
dof (Abramowitz-Stegun 26.7.3/4) and the stdlib `statistics` module.
|
|
"""
|
|
|
|
import importlib.util
|
|
import json
|
|
import math
|
|
import os
|
|
import re
|
|
import statistics
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
SCRIPT = os.path.join(HERE, "recompute_verdict.py")
|
|
|
|
_spec = importlib.util.spec_from_file_location("recompute_verdict", SCRIPT)
|
|
rv = importlib.util.module_from_spec(_spec)
|
|
sys.modules["recompute_verdict"] = rv
|
|
_spec.loader.exec_module(rv)
|
|
|
|
# Published t(0.975, dof) for dof 1..30 (four decimals).
|
|
T975 = [12.7062, 4.3027, 3.1824, 2.7764, 2.5706, 2.4469, 2.3646, 2.3060, 2.2622, 2.2281,
|
|
2.2010, 2.1788, 2.1604, 2.1448, 2.1315, 2.1199, 2.1098, 2.1009, 2.0930, 2.0860,
|
|
2.0796, 2.0739, 2.0687, 2.0639, 2.0595, 2.0555, 2.0518, 2.0484, 2.0452, 2.0423]
|
|
|
|
|
|
def cdf_abs_closed_form(t, dof):
|
|
"""P(|T| < t) for integer dof, Abramowitz-Stegun 26.7.3 (odd) / 26.7.4 (even)."""
|
|
theta = math.atan(t / math.sqrt(dof))
|
|
c2 = math.cos(theta) ** 2
|
|
if dof == 1:
|
|
return 2.0 * theta / math.pi
|
|
if dof % 2 == 1:
|
|
total, term = 0.0, 1.0
|
|
for k in range((dof - 3) // 2 + 1):
|
|
if k > 0:
|
|
term *= (2.0 * k) / (2.0 * k + 1.0) * c2
|
|
total += term
|
|
return 2.0 / math.pi * (theta + math.sin(theta) * math.cos(theta) * total)
|
|
total, term = 0.0, 1.0
|
|
for k in range((dof - 2) // 2 + 1):
|
|
if k > 0:
|
|
term *= (2.0 * k - 1.0) / (2.0 * k) * c2
|
|
total += term
|
|
return math.sin(theta) * total
|
|
|
|
|
|
def make_series(ratios_by_metric, n_planned=None, rows=("vanilla_default", "vanilla_noskip"),
|
|
coincide=False, **extra):
|
|
"""series.json where ours is 100 and vanilla is 100*ratio (rate: 100/ratio).
|
|
|
|
ratios_by_metric: {metric: [exp(l_i) ...]} with l positive = ours better.
|
|
"""
|
|
n = len(next(iter(ratios_by_metric.values())))
|
|
pairs = []
|
|
for i in range(n):
|
|
arms = {"ours": {m: 100.0 for m in ("wall_norm", "ttft_sum", "decode_tps")}}
|
|
for row in rows:
|
|
arms[row] = {}
|
|
for metric, ratios in ratios_by_metric.items():
|
|
ratio = ratios[i]
|
|
arms[row][metric] = 100.0 / ratio if metric == "decode_tps" else 100.0 * ratio
|
|
pairs.append({"pair": i + 1, "valid": True, "reasons": [], "arms": arms})
|
|
series = {"machine": "server", "ours_build_id": "b1", "cache_state": "WARM-OS/EMPTY-ENGINE",
|
|
"schedule_hash": "h", "N": n_planned or n, "rows_coincide": coincide, "pairs": pairs}
|
|
series.update(extra)
|
|
return series
|
|
|
|
|
|
def uniform(ratios):
|
|
return {"wall_norm": ratios, "ttft_sum": ratios, "decode_tps": ratios}
|
|
|
|
|
|
def alternating(center, amp, n):
|
|
"""ratios whose logs alternate around `center` (negative lag-1 autocorrelation)."""
|
|
return [math.exp(center + (amp if i % 2 == 0 else -amp)) for i in range(n)]
|
|
|
|
|
|
def run_cli(*args):
|
|
proc = subprocess.run([sys.executable, SCRIPT] + list(args), stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE, universal_newlines=True)
|
|
return proc.returncode, proc.stdout, proc.stderr
|
|
|
|
|
|
class TempFiles(unittest.TestCase):
|
|
def setUp(self):
|
|
self._tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self._tmp.cleanup)
|
|
|
|
def write(self, name, obj):
|
|
path = os.path.join(self._tmp.name, name)
|
|
with open(path, "w", encoding="utf-8") as handle:
|
|
json.dump(obj, handle)
|
|
return path
|
|
|
|
|
|
class StudentTTests(unittest.TestCase):
|
|
def test_quantile_matches_published_table_dof_1_to_30(self):
|
|
for dof, expected in enumerate(T975, start=1):
|
|
got = rv.t_quantile_two_sided(dof, 0.05)
|
|
self.assertAlmostEqual(got, expected, delta=6e-5, msg="dof %d" % dof) # table is rounded to 4 decimals
|
|
self.assertAlmostEqual(rv.t_quantile_two_sided(29, 0.05), 2.0452, delta=5e-5)
|
|
|
|
def test_quantile_matches_closed_form_distribution(self):
|
|
for dof in (1, 2, 3, 4, 5, 8, 11, 12, 23, 24):
|
|
for alpha in (0.05, 0.0221, 0.0158):
|
|
t = rv.t_quantile_two_sided(dof, alpha)
|
|
self.assertAlmostEqual(cdf_abs_closed_form(t, dof), 1.0 - alpha, delta=1e-10,
|
|
msg="dof %d alpha %s" % (dof, alpha))
|
|
|
|
def test_quantile_exact_for_dof_1_and_2(self):
|
|
# dof 1 is the Cauchy law: t = tan(pi (1 - alpha / 2 - 1/2)); dof 2: t = (1 - alpha) / sqrt(alpha (1 - alpha / 2)) ... use p form
|
|
alpha = 0.05
|
|
self.assertAlmostEqual(rv.t_quantile_two_sided(1, alpha), math.tan(math.pi * (1 - alpha) / 2),
|
|
delta=1e-11)
|
|
p = 1 - alpha / 2
|
|
self.assertAlmostEqual(rv.t_quantile_two_sided(2, alpha),
|
|
(2 * p - 1) / math.sqrt(2 * p * (1 - p)), delta=1e-11)
|
|
|
|
|
|
class SeriesTests(TempFiles):
|
|
def test_hand_computed_interval_against_stdlib_statistics(self):
|
|
ratios = [1.02, 1.05, 1.01, 1.04, 1.03, 1.06]
|
|
# The rate metric is the same l (decode_tps built as 100/ratio -> ln(O/V) = ln(ratio)).
|
|
out = rv.recompute(make_series(uniform(ratios), n_planned=6))
|
|
logs = [math.log(r) for r in ratios]
|
|
mean, sd = statistics.mean(logs), statistics.stdev(logs)
|
|
# lag-1 autocorrelation by hand, to know which rule applies
|
|
dev = [x - mean for x in logs]
|
|
r1 = sum(dev[i] * dev[i + 1] for i in range(5)) / sum(d * d for d in dev)
|
|
n_eff = 6 * (1 - r1) / (1 + r1) if r1 > 0 else 6.0
|
|
dof = max(1, math.floor(n_eff - 1)) if r1 > 0 else 5
|
|
half = T975[dof - 1] * sd / math.sqrt(n_eff if r1 > 0 else 6)
|
|
cell = out["metrics"]["wall_norm"]["vanilla_default"]
|
|
self.assertEqual(cell["n"], 6)
|
|
self.assertAlmostEqual(cell["mean_l"], mean, places=14)
|
|
self.assertAlmostEqual(cell["r1"], r1, places=12)
|
|
self.assertAlmostEqual(cell["ci_lo"], mean - half, delta=1e-4 * sd)
|
|
self.assertAlmostEqual(cell["ci_hi"], mean + half, delta=1e-4 * sd)
|
|
self.assertAlmostEqual(cell["mde"], 2.8 * sd / math.sqrt(6), places=12)
|
|
|
|
def test_all_zero_series_is_tie_strict_and_pass_nonnegative(self):
|
|
out = rv.recompute(make_series(uniform([1.0] * 30)))
|
|
for row in ("vanilla_default", "vanilla_noskip"):
|
|
self.assertEqual(out["metrics"]["wall_norm"][row]["verdict"], "TIE")
|
|
self.assertEqual(out["metrics"]["ttft_sum"][row]["verdict"], "PASS")
|
|
self.assertEqual(out["metrics"]["decode_tps"][row]["verdict"], "PASS")
|
|
self.assertEqual(out["metrics"]["wall_norm"][row]["mean_l"], 0.0)
|
|
self.assertEqual(out["series_verdict"], "NOT_MET")
|
|
|
|
def test_bound_exactly_at_ln_099_is_not_a_pass_and_not_slower(self):
|
|
# sd = 0 makes the bound exact: every l_i = ln(100/99).. here ours is 1 percent slower
|
|
ratios = [0.99] * 30
|
|
out = rv.recompute(make_series({"wall_norm": [1.01] * 30, "ttft_sum": ratios,
|
|
"decode_tps": ratios}))
|
|
cell = out["metrics"]["ttft_sum"]["vanilla_default"]
|
|
self.assertEqual(cell["ci_lo"], cell["ci_hi"])
|
|
self.assertAlmostEqual(cell["ci_lo"], math.log(0.99), delta=1e-13)
|
|
self.assertEqual(cell["verdict"], "INCONCLUSIVE")
|
|
|
|
def test_clear_pass_slower_and_inconclusive(self):
|
|
good = alternating(0.05, 0.002, 30)
|
|
out = rv.recompute(make_series(uniform(good)))
|
|
self.assertEqual(out["series_verdict"], "MET")
|
|
self.assertTrue(all(c["verdict"] == "PASS" for m in out["metrics"].values() for c in m.values()))
|
|
bad = alternating(-0.05, 0.002, 30)
|
|
out = rv.recompute(make_series(uniform(bad)))
|
|
self.assertEqual(out["series_verdict"], "FAILED")
|
|
self.assertEqual(out["metrics"]["wall_norm"]["vanilla_default"]["verdict"], "SLOWER")
|
|
noisy = alternating(0.001, 0.2, 30)
|
|
out = rv.recompute(make_series(uniform(noisy)))
|
|
self.assertEqual(out["metrics"]["wall_norm"]["vanilla_default"]["verdict"], "INCONCLUSIVE")
|
|
self.assertEqual(out["series_verdict"], "NOT_MET")
|
|
|
|
def test_n29_is_screening_without_a_pass_token_and_n30_is_not(self):
|
|
good = alternating(0.05, 0.002, 30)
|
|
s29 = make_series(uniform(good[:29]), n_planned=30)
|
|
code, stdout, _ = run_cli("series", self.write("s29.json", s29))
|
|
self.assertEqual(code, 0)
|
|
self.assertEqual(json.loads(stdout)["series_verdict"], "SCREENING")
|
|
self.assertEqual(len(re.findall("PASS", stdout)), 0)
|
|
self.assertEqual(rv.recompute(make_series(uniform(good)))["series_verdict"], "MET")
|
|
|
|
def test_invalid_pairs_are_excluded(self):
|
|
series = make_series(uniform(alternating(0.05, 0.002, 31)), n_planned=30)
|
|
series["pairs"][3]["valid"] = False
|
|
series["pairs"][3]["reasons"] = ["power band"]
|
|
series["pairs"][3]["arms"]["ours"]["wall_norm"] = 1e9
|
|
out = rv.recompute(series)
|
|
self.assertEqual(out["n_valid"], 30)
|
|
self.assertEqual(out["series_verdict"], "MET")
|
|
|
|
def test_mixed_build_or_cache_state_is_refused_exit_2(self):
|
|
base = make_series(uniform(alternating(0.05, 0.002, 30)))
|
|
for key, other in (("ours_build_id", "b2"), ("cache_state", "COLD")):
|
|
series = json.loads(json.dumps(base))
|
|
series["pairs"][7][key] = other
|
|
series["pairs"][0][key] = series[key]
|
|
code, _, stderr = run_cli("series", self.write("mixed.json", series))
|
|
self.assertEqual(code, 2, key)
|
|
self.assertIn(key, stderr)
|
|
|
|
def test_malformed_input_exit_3(self):
|
|
code, _, _ = run_cli("series", self.write("bad.json", {"pairs": "x"}))
|
|
self.assertEqual(code, 3)
|
|
series = make_series(uniform([1.01] * 30))
|
|
series["pairs"][0]["arms"]["ours"]["wall_norm"] = 0
|
|
code, _, _ = run_cli("series", self.write("zero.json", series))
|
|
self.assertEqual(code, 3)
|
|
|
|
def test_unit_scale_and_pair_order_invariance(self):
|
|
ratios = alternating(0.03, 0.004, 30)
|
|
base = rv.recompute(make_series(uniform(ratios)))
|
|
scaled = make_series(uniform(ratios))
|
|
for pair in scaled["pairs"]:
|
|
for arm in pair["arms"].values():
|
|
for key in arm:
|
|
arm[key] *= 1000.0
|
|
out = rv.recompute(scaled)
|
|
for metric in rv.METRICS:
|
|
a = base["metrics"][metric]["vanilla_default"]
|
|
b = out["metrics"][metric]["vanilla_default"]
|
|
for field in ("mean_l", "ci_lo", "ci_hi"):
|
|
self.assertAlmostEqual(a[field], b[field], places=12)
|
|
# The pair order inside the file does not matter (pairs are ordered by number).
|
|
shuffled = make_series(uniform(ratios))
|
|
shuffled["pairs"].reverse()
|
|
out = rv.recompute(shuffled)
|
|
self.assertEqual(out["metrics"]["wall_norm"]["vanilla_default"]["ci_lo"],
|
|
base["metrics"]["wall_norm"]["vanilla_default"]["ci_lo"])
|
|
|
|
def test_rows_coincide_gives_one_row(self):
|
|
out = rv.recompute(make_series(uniform(alternating(0.05, 0.002, 30)), coincide=True))
|
|
self.assertEqual(len(out["metrics"]["wall_norm"]), 1)
|
|
out = rv.recompute(make_series(uniform(alternating(0.05, 0.002, 30))))
|
|
self.assertEqual(len(out["metrics"]["wall_norm"]), 2)
|
|
|
|
def test_positive_autocorrelation_widens_the_interval(self):
|
|
drift = [math.exp(0.002 * i) for i in range(30)] # trend: strong positive r1
|
|
out = rv.recompute(make_series(uniform(drift)))
|
|
cell = out["metrics"]["wall_norm"]["vanilla_default"]
|
|
self.assertGreater(cell["r1"], 0.5)
|
|
self.assertLess(cell["n_eff"], 30)
|
|
logs = [math.log(r) for r in drift]
|
|
plain_half = T975[28] * statistics.stdev(logs) / math.sqrt(30)
|
|
self.assertGreater(cell["ci_hi"] - cell["ci_lo"], 2 * plain_half)
|
|
|
|
def test_interim_look_can_only_end_as_failed_never_pass(self):
|
|
# 12 clearly slower pairs, then 18 clearly faster pairs: the look at 12 ends it.
|
|
ratios = alternating(-0.05, 0.002, 12) + alternating(0.30, 0.002, 18)
|
|
out = rv.recompute(make_series(uniform(ratios)))
|
|
self.assertEqual(out["early_exit_look"], 12)
|
|
self.assertEqual(out["series_verdict"], "FAILED")
|
|
# A strong early lead never produces PASS before the end.
|
|
out = rv.recompute(make_series(uniform(alternating(0.05, 0.002, 30)[:24]), n_planned=30))
|
|
self.assertEqual(out["series_verdict"], "SCREENING")
|
|
self.assertNotIn("PASS", [c["verdict"] for m in out["metrics"].values() for c in m.values()])
|
|
self.assertEqual([k["look_pairs"] for k in out["looks"]], [12, 24])
|
|
self.assertEqual(rv.look_points(30), [12, 24])
|
|
self.assertEqual(rv.look_points(36), [12, 24])
|
|
|
|
|
|
class CompareTests(TempFiles):
|
|
def evaluator_output(self, series):
|
|
"""What a correct evaluator prints (here: the recomputation in INTERFACE v1 shape)."""
|
|
mine = rv.recompute(series)
|
|
return {"metrics": {m: {r: {k: c[k] for k in ("n", "mean_l", "ci_lo", "ci_hi", "r1",
|
|
"n_eff", "mde", "verdict")}
|
|
for r, c in rows.items()} for m, rows in mine["metrics"].items()},
|
|
"series_verdict": mine["series_verdict"], "looks": []}
|
|
|
|
def test_agreeing_evaluator_exits_0(self):
|
|
series = make_series(uniform(alternating(0.05, 0.002, 30)))
|
|
code, stdout, _ = run_cli("compare", self.write("ev.json", self.evaluator_output(series)),
|
|
self.write("s.json", series))
|
|
self.assertEqual(code, 0, stdout)
|
|
self.assertIn("AGREE", stdout)
|
|
|
|
def test_mean_l_perturbed_by_0_005_exits_1_naming_metric_row_field(self):
|
|
series = make_series(uniform(alternating(0.05, 0.002, 30)))
|
|
evaluator = self.evaluator_output(series)
|
|
evaluator["metrics"]["ttft_sum"]["vanilla_noskip"]["mean_l"] += 0.005
|
|
code, stdout, _ = run_cli("compare", self.write("ev.json", evaluator),
|
|
self.write("s.json", series))
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("metric=ttft_sum", stdout)
|
|
self.assertIn("row=vanilla_noskip", stdout)
|
|
self.assertIn("field=mean_l", stdout)
|
|
|
|
def test_ci_bound_just_over_tolerance_is_caught_and_under_is_accepted(self):
|
|
series = make_series(uniform(alternating(0.05, 0.002, 30)))
|
|
evaluator = self.evaluator_output(series)
|
|
evaluator["metrics"]["wall_norm"]["vanilla_default"]["ci_lo"] += 5e-10
|
|
self.assertEqual(run_cli("compare", self.write("a.json", evaluator),
|
|
self.write("s.json", series))[0], 0)
|
|
evaluator["metrics"]["wall_norm"]["vanilla_default"]["ci_lo"] += 1e-8
|
|
code, stdout, _ = run_cli("compare", self.write("b.json", evaluator),
|
|
self.write("s.json", series))
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("field=ci_lo", stdout)
|
|
|
|
def test_verdict_class_and_n_disagreement(self):
|
|
series = make_series(uniform(alternating(0.05, 0.002, 30)))
|
|
evaluator = self.evaluator_output(series)
|
|
evaluator["metrics"]["decode_tps"]["vanilla_default"]["verdict"] = "INCONCLUSIVE"
|
|
code, stdout, _ = run_cli("compare", self.write("ev.json", evaluator),
|
|
self.write("s.json", series))
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("field=verdict", stdout)
|
|
evaluator = self.evaluator_output(series)
|
|
evaluator["metrics"]["wall_norm"]["vanilla_default"]["n"] = 29
|
|
code, stdout, _ = run_cli("compare", self.write("ev2.json", evaluator),
|
|
self.write("s.json", series))
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("field=n", stdout)
|
|
|
|
|
|
class GoldenTests(TempFiles):
|
|
def test_golden_runner_prints_counts_and_detects_a_wrong_expectation(self):
|
|
# Expected values below are written by hand from the definitions, not read from the code.
|
|
ratios_zero = uniform([1.0] * 30)
|
|
cases = {"cases": {
|
|
"all_zero": {"input": make_series(ratios_zero), "basis": "l_i = ln(1) = 0, sd = 0",
|
|
"expected": {"series_verdict": "NOT_MET", "metrics": {
|
|
"wall_norm": {"vanilla_default": {"n": 30, "mean_l": 0.0, "ci_lo": 0.0,
|
|
"ci_hi": 0.0, "verdict": "TIE"}},
|
|
"ttft_sum": {"vanilla_default": {"verdict": "PASS"}}}}},
|
|
"mixed_build": {"input": dict(make_series(ratios_zero), pairs=[
|
|
dict(p, ours_build_id="b%d" % (p["pair"] % 2)) for p in make_series(ratios_zero)["pairs"]]),
|
|
"basis": "two build ids", "expected": {"exit": 2}},
|
|
}}
|
|
code, stdout, _ = run_cli("golden", self.write("g.json", cases))
|
|
self.assertEqual(code, 0, stdout)
|
|
self.assertIn("cases: 2 passed: 2", stdout)
|
|
cases["cases"]["all_zero"]["expected"]["metrics"]["wall_norm"]["vanilla_default"]["verdict"] = "PASS"
|
|
code, stdout, _ = run_cli("golden", self.write("g2.json", cases))
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("cases: 2 passed: 1", stdout)
|
|
|
|
def golden(self, cases, *flags):
|
|
"""Run the golden sub-command on a list of cases; returns (code, stdout)."""
|
|
code, stdout, _ = run_cli("golden", self.write("g.json", {"cases": cases}), *flags)
|
|
return code, stdout
|
|
|
|
def test_raw_text_malformed_input_case_is_checked_for_exit_3(self):
|
|
good = {"name": "truncated", "argv": [], "basis": "x", "raw_text": '{"machine": "server", "N": 30, "pairs": [',
|
|
"expected": {"exit": 3}}
|
|
wrong = dict(good, name="wrong", expected={"exit": 0})
|
|
parses = dict(good, name="parses", raw_text=json.dumps(make_series(uniform([1.0] * 30))),
|
|
expected={"exit": 0, "series_verdict": "NOT_MET"})
|
|
code, stdout = self.golden([good, parses])
|
|
self.assertEqual(code, 0, stdout)
|
|
self.assertIn("cases: 2 passed: 2 skipped: 0 failed: 0", stdout)
|
|
code, stdout = self.golden([good, wrong])
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("FAIL wrong: exit: expected 0, recomputed 3", stdout)
|
|
|
|
def test_unchecked_expected_key_or_argv_flag_is_skipped_not_passed(self):
|
|
series = make_series(uniform(alternating(0.05, 0.002, 30)))
|
|
ok = {"name": "ok", "series": series, "expected": {"series_verdict": "MET"}}
|
|
unknown_key = {"name": "unk_key", "series": series,
|
|
"expected": {"series_verdict": "MET", "some_future_key": 1}}
|
|
unknown_flag = {"name": "unk_flag", "series": series, "argv": ["--frobnicate"],
|
|
"expected": {"series_verdict": "MET"}}
|
|
code, stdout = self.golden([ok, unknown_key, unknown_flag])
|
|
self.assertEqual(code, 1, stdout) # not fully verified
|
|
self.assertIn("cases: 3 passed: 1 skipped: 2 failed: 0", stdout)
|
|
self.assertIn("SKIPPED unk_key", stdout)
|
|
self.assertIn("some_future_key", stdout)
|
|
self.assertIn("SKIPPED unk_flag", stdout)
|
|
self.assertIn("NOT FULLY VERIFIED", stdout)
|
|
code, stdout = self.golden([ok, unknown_key], "--allow-skips")
|
|
self.assertEqual(code, 0, stdout)
|
|
self.assertIn("cases: 2 passed: 1 skipped: 1 failed: 0", stdout)
|
|
# a failure outranks a skip, and --allow-skips never hides a failure
|
|
bad = dict(unknown_key, name="bad", expected={"series_verdict": "FAILED", "some_future_key": 1})
|
|
code, stdout = self.golden([bad], "--allow-skips")
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("cases: 1 passed: 0 skipped: 0 failed: 1", stdout)
|
|
|
|
def test_forbidden_tokens_are_checked_on_the_printed_output(self):
|
|
screening = make_series(uniform(alternating(0.05, 0.002, 29)), n_planned=30)
|
|
ok = {"name": "no_pass", "series": screening,
|
|
"expected": {"series_verdict": "SCREENING", "forbidden_tokens": ["PASS", "TIE"]}}
|
|
leaks = {"name": "leaks", "series": screening,
|
|
"expected": {"series_verdict": "SCREENING", "forbidden_tokens": ["SCREENING"]}}
|
|
code, stdout = self.golden([ok, leaks])
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("cases: 2 passed: 1 skipped: 0 failed: 1", stdout)
|
|
self.assertIn("forbidden_tokens: 'SCREENING' appears", stdout)
|
|
|
|
def test_mention_of_a_refusal_is_checked(self):
|
|
mixed = make_series(uniform([1.0] * 30))
|
|
for i, pair in enumerate(mixed["pairs"]):
|
|
pair["ours_build_id"] = "b%d" % (i % 2)
|
|
right = {"name": "right", "series": mixed, "expected": {"exit": 2, "mention": "ours_build_id"}}
|
|
wrong = {"name": "wrong", "series": mixed, "expected": {"exit": 2, "mention": "cache_state"}}
|
|
code, stdout = self.golden([right, wrong])
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("cases: 2 passed: 1 skipped: 0 failed: 1", stdout)
|
|
self.assertIn("mention: expected the message to mention 'cache_state'", stdout)
|
|
|
|
def test_series_b_variant_is_recomputed_and_must_meet_the_same_expectation(self):
|
|
good = make_series(uniform(alternating(0.05, 0.002, 30)))
|
|
bad = make_series(uniform(alternating(-0.05, 0.002, 30)))
|
|
same = {"name": "same", "series": good, "series_b": good, "series_b_label": "copy",
|
|
"expected": {"series_verdict": "MET"}}
|
|
differs = {"name": "differs", "series": good, "series_b": bad, "series_b_label": "other",
|
|
"expected": {"series_verdict": "MET"}}
|
|
code, stdout = self.golden([same, differs])
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("cases: 2 passed: 1 skipped: 0 failed: 1", stdout)
|
|
self.assertIn("series_b (other): series_verdict", stdout)
|
|
|
|
def test_look_flag_restricts_the_series_to_the_look(self):
|
|
series = make_series(uniform(alternating(-0.2, 0.01, 24)), n_planned=30)
|
|
look1 = {"name": "look1", "series": series, "argv": ["--look", "1"], "expected": {"series_verdict": "FAILED"}}
|
|
too_few = {"name": "too_few", "series": make_series(uniform(alternating(-0.2, 0.01, 11)), n_planned=30),
|
|
"argv": ["--look", "1"], "expected": {"exit": 3}}
|
|
bad_look = {"name": "bad_look", "series": series, "argv": ["--look", "3"], "expected": {"exit": 3}}
|
|
code, stdout = self.golden([look1, too_few, bad_look])
|
|
self.assertEqual(code, 0, stdout)
|
|
self.assertIn("cases: 3 passed: 3 skipped: 0 failed: 0", stdout)
|
|
|
|
def test_blind_sd_value_and_absence_of_a_mean_are_checked(self):
|
|
series = make_series(uniform(alternating(0.05, 0.002, 30)))
|
|
sd6 = 0.002 * math.sqrt(1.2) # six values 0.05 +- 0.002, three of each, sample sd
|
|
ok = {"name": "ok", "series": series, "argv": ["--blind-sd"],
|
|
"expected": {"blind_sd": sd6, "forbidden_key_prefixes": ["mean"]}}
|
|
wrong_value = dict(ok, name="wrong_value", expected={"blind_sd": sd6 * 1.001})
|
|
has_prefix = dict(ok, name="has_prefix", expected={"blind_sd": sd6, "forbidden_key_prefixes": ["sd"]})
|
|
code, stdout = self.golden([ok, wrong_value, has_prefix])
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("cases: 3 passed: 1 skipped: 0 failed: 2", stdout)
|
|
self.assertIn("FAIL wrong_value: blind_sd", stdout)
|
|
self.assertIn("FAIL has_prefix: forbidden_key_prefixes", stdout)
|
|
code, stdout, _ = run_cli("blind-sd", self.write("s.json", series))
|
|
self.assertEqual(code, 0)
|
|
self.assertNotIn("mean", stdout)
|
|
|
|
def test_blind_key_without_the_flag_is_skipped(self):
|
|
series = make_series(uniform(alternating(0.05, 0.002, 30)))
|
|
case = {"name": "no_flag", "series": series, "expected": {"series_verdict": "MET", "blind_sd": 0.002}}
|
|
code, stdout = self.golden([case])
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("cases: 1 passed: 0 skipped: 1 failed: 0", stdout)
|
|
|
|
def test_null_simulation_is_run_and_its_arguments_are_compared(self):
|
|
series = make_series(uniform(alternating(0.0, 0.01, 30)))
|
|
argv = ["--simulate-null", "--runs", "2000", "--seed", "7"]
|
|
ok = {"name": "ok", "series": series, "argv": argv,
|
|
"expected": {"max_false_slower_rate": 0.05, "runs": 2000, "seed": 7}}
|
|
too_strict = dict(ok, name="too_strict", expected={"max_false_slower_rate": 0.0001})
|
|
wrong_seed = dict(ok, name="wrong_seed", expected={"max_false_slower_rate": 0.05, "seed": 8})
|
|
code, stdout = self.golden([ok, too_strict, wrong_seed])
|
|
self.assertEqual(code, 1)
|
|
self.assertIn("cases: 3 passed: 1 skipped: 0 failed: 2", stdout)
|
|
self.assertIn("FAIL too_strict: max_false_slower_rate", stdout)
|
|
self.assertIn("FAIL wrong_seed: seed: expected 8", stdout)
|
|
code, stdout, _ = run_cli("simulate-null", self.write("s.json", series), "--runs", "2000", "--seed", "7")
|
|
self.assertEqual(code, 0)
|
|
first = json.loads(stdout)
|
|
code, stdout, _ = run_cli("simulate-null", self.write("s.json", series), "--runs", "2000", "--seed", "7")
|
|
self.assertEqual(json.loads(stdout), first) # deterministic for a seed
|
|
self.assertTrue(0.0 < first["false_slower_rate"] < 0.05, first)
|
|
|
|
@unittest.skipUnless(os.path.exists(os.path.join(HERE, "golden", "series_cases.json")),
|
|
"STRA-310 golden file not present on this branch")
|
|
def test_real_golden_file_has_no_failed_and_no_skipped_case(self):
|
|
path = os.path.join(HERE, "golden", "series_cases.json")
|
|
code, stdout, _ = run_cli("golden", path)
|
|
self.assertEqual(code, 0, stdout)
|
|
self.assertRegex(stdout, r"cases: (\d+) passed: \1 skipped: 0 failed: 0")
|
|
|
|
|
|
class IndependenceTests(unittest.TestCase):
|
|
def test_no_import_of_the_evaluator_modules(self):
|
|
with open(SCRIPT, "r", encoding="utf-8") as handle:
|
|
lines = handle.read().splitlines()
|
|
imports = [ln for ln in lines if re.match(r"^(import|from)\s", ln)]
|
|
self.assertTrue(imports)
|
|
for line in imports:
|
|
self.assertNotRegex(line, "series_eval|component_class")
|
|
# nothing imports lazily either
|
|
self.assertFalse([ln for ln in lines if re.search(r"__import__|importlib", ln)])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|