Spaces:
Running

File size: 4,088 Bytes
b43c69f
 
 
 
 
 
 
 
 
 
 
 
 
cf826f7
 
b43c69f
 
 
 
 
 
 
 
cf826f7
b43c69f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf826f7
59d6e95
b43c69f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf826f7
b43c69f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""The bench header's specimen tile is the project's protein, turning.

It was a fixed glyph — the same curve on every project — in the one place on
the bench that names what you are working on. It is now Mission Control's
fold (structcard.js: the AlphaFold model's alpha-carbon trace in pLDDT
colours) on a slow turntable. These tests pin the parts that keep it honest
and cheap: the same drawing code as the cards, only a real accession gets a
fold, the view is framed on the confidently-modelled core, and the animation
stops when nobody can see it.
"""
import pathlib
import re

from _frontend import app_js

_ROOT = pathlib.Path(__file__).resolve().parents[1]


def _read(rel):
    return (_ROOT / rel).read_text(encoding="utf-8")


def _setthumb():
    app = app_js()
    body = app[app.index("function setThumb(id)"):]
    return body[:body.index("\n    }\n")]


def test_the_tile_uses_mission_controls_own_fold_drawing():
    sc = _read("dee/static/structcard.js")
    assert "spin: spin" in sc and "stop: stopSpin" in sc
    # Same fetch, same colours: spin goes through fetchTrace and plddtColor.
    spin = sc[sc.index("function spin(canvas, accession)"):]
    assert "fetchTrace(acc)" in spin
    frame = sc[sc.index("function spinFrame"):sc.index("function spinModel")]
    assert "plddtColor(" in frame
    assert "window.TDStructCard.spin(cv, a)" in _setthumb()


def test_only_a_real_accession_gets_a_fold():
    """structcard.js's rule: never a squiggle that could pass for a structure."""
    fn = _setthumb()
    assert "const ACC_OK = /^[A-Z0-9]{6,10}$/;" in app_js()
    assert "if (ACC_OK.test(acc)) { turn(acc); return; }" in fn
    assert "/api/structure/resolve?gene=" in fn, "the same resolver the cards use"
    assert "THUMB_GLYPH" in fn and "glyph();" in fn, "no accession keeps the plain glyph"
    assert ".then((ok) => { if (!ok) glyph(); })" in fn, "a failed fetch falls back"


def test_the_view_is_framed_on_the_confident_core():
    """HLA-A's ~70-residue disordered tail shrank the domain to a speck."""
    sc = _read("dee/static/structcard.js")
    model = sc[sc.index("function spinModel"):sc.index("function stopSpin")]
    assert "trace.plddt[i] >= 70" in model
    assert "project(trace.pts, core)" in model
    assert "if (core.length < 20) core = trace.pts;" in model


def test_it_costs_nothing_when_nobody_can_see_it():
    sc = _read("dee/static/structcard.js")
    spin = sc[sc.index("function spin(canvas, accession)"):sc.index("/* Lazy paint.")]
    assert "reducedMotion()" in spin, "prefers-reduced-motion draws one still frame"
    assert "document.hidden" in spin
    assert "IntersectionObserver" in spin
    assert "if (!canvas.isConnected) { stopSpin(canvas); return; }" in spin
    assert "stopSpin(canvas);" in spin.split("if (!ACC_RE.test(acc))")[0], (
        "a second spin on the same canvas must end the first")


def test_the_tile_follows_the_project_and_the_name():
    app = app_js()
    opener = app[app.index("function openConstruct(c)"):]
    opener = opener[:opener.index("\n    }\n")]
    assert "setThumb({ acc: current.uniprot || st.acc" in opener, (
        "the project's recorded structure decides the tile on open")
    update = app[app.index("    function update(patch)"):]
    update = update[:update.index("\n    }\n")]
    assert "setThumb({ acc: patch.uniprot" in update
    close = app[app.index("    function close() {\n        if (window.TDProject) window.TDProject.park();"):]
    assert "setThumb(null)" in close[:400], "closing the bench stops the turntable"
    cockpit = _read("dee/static/cockpit.js")
    name = cockpit[cockpit.index("function nameConstruct()"):]
    name = name[:name.index("\n    }\n")]
    assert 'uniprot: state.ident.uniprot || ""' in name


def test_the_tile_is_drawn_from_the_design_tokens():
    css = _read("dee/static/app.css")
    rule = re.search(r"\.bench-spec-thumb\.has-fold \{(.*?)\}", css, re.S).group(1)
    assert "var(--r-3)" in rule and "var(--bg-subtle)" in rule and "var(--line)" in rule
    assert "44px" in rule, "the 56px strip leaves room for 44"