File size: 3,999 Bytes
a8943e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd00037
 
56f3cdf
 
 
 
 
 
 
 
bd00037
a8943e8
 
 
 
 
 
 
 
 
 
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
103
104
105
"""C13 — the security addendum says what the code enforces, and its host table cannot go stale.

A sentence in a security document that the code does not back is exactly the kind of claim a review
reads as a control. So every number the addendum states is read back from the code here, and the host
table is regenerated from config and compared.
"""

from __future__ import annotations

import re
import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
ADDENDUM = (ROOT / "docs/security/addendum-knowledge-specialist.md").read_text(encoding="utf-8")


def _flat(text: str) -> str:
    return " ".join(text.split())


def test_the_host_table_is_fresh():
    result = subprocess.run(
        [sys.executable, str(ROOT / "scripts/render_host_table.py"), "--check"],
        capture_output=True,
        text=True,
        check=False,
    )
    assert result.returncode == 0, result.stderr


def test_every_declared_host_is_in_the_addendum():
    from src import config

    for src in config.sources().values():
        for host in src["hosts"]:
            assert f"`{host}`" in ADDENDUM, host


def test_the_numbers_it_states_are_the_codes():
    from src import config
    from src.endpoints._common import ENDPOINT_BUDGET_SECONDS
    from src.identifiers import MAX_DISEASE_NAME, MAX_IDENTIFIERS

    text = _flat(ADDENDUM)
    assert (
        f"{len(config.allowed_tool_names())} are approved and the {len(config.endpoint_tool_names())}"
        in text
    )
    rates = {s["rate_per_second"] for s in config.sources().values()}
    timeouts = {s["timeout_seconds"] for s in config.sources().values()}
    assert rates == {3} and "At most 3 requests per second per source" in text
    assert timeouts == {30} and "30 seconds per call" in text
    assert f"{ENDPOINT_BUDGET_SECONDS} seconds per endpoint call" in text
    assert f"at most {MAX_IDENTIFIERS} per call" in text
    assert f"at most {MAX_DISEASE_NAME} characters" in text
    assert (
        config.source("clinicaltrials")["ttl_seconds"] == 24 * 3600
        and "24 hours for ClinicalTrials.gov" in text
    )
    assert config.source("opentargets")["ttl_seconds"] == 7 * 86400 and "up to 7 days" in text
    assert config.pinned_tooluniverse_version() == "1.5.6" and "pinned to 1.5.6" in text


def test_every_model_provider_it_names_is_refused():
    from src.tu_client import LLM_KEY_VARS

    named = {
        "OpenAI": "OPENAI_API_KEY",
        "Azure OpenAI": "AZURE_OPENAI_API_KEY",
        "Gemini": "GEMINI_API_KEY",
        "Google": "GOOGLE_API_KEY",
        "OpenRouter": "OPENROUTER_API_KEY",
        "Anthropic": "ANTHROPIC_API_KEY",
        "vLLM": "VLLM_SERVER_URL",
    }
    for provider, var in named.items():
        assert provider in ADDENDUM and var in LLM_KEY_VARS, provider


def test_the_accepted_finding_it_cites_is_the_recorded_one():
    accepted = (ROOT / "security/accepted-vulns.txt").read_text()
    # Every accepted id counts, not just CVE ids: some advisories arrive as GHSA ids only (batch 5).
    n_ids = len(re.findall(r"^(?:CVE|GHSA|PYSEC)-", accepted, re.MULTILINE))
    if n_ids == 0:
        # 2026-11-17: the pillow 12.3.0 set was closed by pillow 13.0.0 (gradio 6.32.0). The addendum
        # must then say nothing is accepted, not keep quoting an expiry for findings that are gone.
        assert "No finding is accepted" in _flat(ADDENDUM)
        assert "expires on" not in _flat(ADDENDUM)
        return
    expiries = set(re.findall(r"expires=(\d{4}-\d{2}-\d{2})", accepted))
    assert expiries == {"2026-12-18"} and "expires on 2026-12-18" in _flat(ADDENDUM)
    assert f"{n_ids} pillow 12.3.0" in _flat(ADDENDUM)


def test_it_states_the_egress_limit_honestly():
    text = _flat(ADDENDUM)
    assert "Hugging Face Spaces offer no egress allow-list" in text
    assert "not a network control" in text


def test_it_names_roles_not_people():
    assert not re.search(r"\b(Annie|Voigt|Sears|Rosalie|Carl|Pelz|Brody)\b", ADDENDUM)