File size: 4,012 Bytes
ea9cb88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0bdb418
 
 
 
 
 
 
 
ea9cb88
 
 
0bdb418
ea9cb88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Landmark-design validation. This file guards the honesty mechanism.

The number that matters is not "how many passed" but "how many passed that
were checkable without trusting anyone's memory". A harness that lets an
uncited claim count as validation is worse than no harness, because it
launders a guess into a credential.
"""
import pytest

from dee.core import compiler_validation as V


def test_the_bundled_corpus_loads():
    cases = V.load_cases()
    assert cases, "the corpus must ship with the package"
    assert all("id" in c and "basis" in c for c in cases)


def test_every_chemistry_case_reproduces():
    """If this fails, the compiler changed its verdict on a settled design."""
    report = V.run_validation()
    assert not report.failures, [
        (f.name, f.mismatches) for f in report.failures]
    assert report.chemistry_passed == report.chemistry_total
    assert report.chemistry_total >= 5, "corpus should not silently shrink"


def test_the_sickle_cell_case_offers_no_base_editor_and_stays_that_way():
    """The anchor case. HbS is T>A on the forward strand — a transversion — so
    NO base editor can correct it, on either strand. That is the assertion; if
    an editor family ever appears here, something has broken very badly.

    It now compiles, because prime editing is designed. The chemistry the case
    tests did not change — only what the platform can offer for it.
    """
    report = V.run_validation()
    hbs = next(r for r in report.results if r.case_id == "hbs-sickle-hbb")
    assert hbs.status == "pass"
    assert hbs.observed["editor_family"] is None, "no base editor makes T>A"
    assert hbs.observed["route"] == "prime_editing"
    assert "transversion_no_base_editor" in hbs.observed["diagnostics"]


def test_an_uncited_literature_case_is_unverified_not_passed():
    """The mechanism. An expectation nobody can look up must never count."""
    cases = [{
        "id": "made-up", "name": "Uncited claim", "basis": "literature",
        "wt_base": "G", "patient_base": "A",
        "expect": {"compiles": True, "route": "base_editing"},
        "citation": "",
    }]
    report = V.run_validation(cases)
    assert report.results[0].status == "unverified"
    assert report.chemistry_passed == 0
    assert "Uncited claim" in report.unverified


def test_a_cited_literature_case_is_actually_run():
    cases = [{
        "id": "cited", "name": "Cited claim", "basis": "literature",
        "wt_base": "G", "patient_base": "A",
        "expect": {"compiles": True, "route": "base_editing",
                   "editor_family": "ABE"},
        "citation": "PMID:00000000",
    }]
    assert V.run_validation(cases).results[0].status == "pass"


def test_a_wrong_expectation_fails_loudly_with_the_delta():
    cases = [{
        "id": "wrong", "name": "Wrong", "basis": "chemistry",
        "wt_base": "G", "patient_base": "A",
        "expect": {"editor_family": "CBE"},        # it is ABE
    }]
    r = V.run_validation(cases).results[0]
    assert r.status == "fail"
    assert any("editor_family" in m and "ABE" in m for m in r.mismatches)


def test_a_case_is_not_failed_for_something_it_never_asserted():
    """Partial expectations are legitimate; only stated keys are checked."""
    cases = [{
        "id": "partial", "name": "Partial", "basis": "chemistry",
        "wt_base": "G", "patient_base": "A",
        "expect": {"compiles": True},              # says nothing about strand
    }]
    assert V.run_validation(cases).results[0].status == "pass"


def test_the_headline_never_reads_as_more_than_it_is():
    report = V.run_validation()
    h = report.headline
    assert "derivable from the genetic code" in h
    if report.unverified:
        assert "awaiting a citation and not counted" in h


def test_unverified_cases_are_named_not_merely_counted():
    """A gap with a name is a to-do; a gap as a number is a footnote."""
    report = V.run_validation()
    assert all(isinstance(n, str) and n for n in report.unverified)