File size: 3,423 Bytes
48f2b75
 
 
 
 
 
 
 
 
 
f628309
 
48f2b75
f628309
48f2b75
ba784dc
48f2b75
 
 
f628309
 
48f2b75
 
 
f628309
48f2b75
 
da61666
48f2b75
 
 
 
 
 
 
 
 
 
 
 
 
ba784dc
da61666
48f2b75
f628309
 
 
 
 
 
 
 
 
 
48f2b75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba784dc
 
 
 
 
 
 
 
48f2b75
 
 
 
f628309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48f2b75
 
 
 
 
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
106
"""Tests for the reason registry: the alphabet every refusal of this bundle answers in."""

from __future__ import annotations

from pathlib import Path

from lingologos_python import rules
from lingologos_python import session as session_module
from lingologos_python.reasons import (
    AMBIGUOUS_TARGET,
    CHECKER_ABSTAIN,
    CHECKER_REJECTED,
    GATE_ABSTAIN,
    GATE_MISSING,
    GATE_REJECTED,
    HARDLINKED_PATH_IN_WORKSPACE,
    KERNEL_REASONS,
    LINKED_PATH_IN_WORKSPACE,
    NODE_TIMEOUT,
    NOT_APPLIED,
    NO_INDEPENDENT_CONFIRMATION,
    PATCH_NOT_APPLIED,
    PATH_POLICY,
    PATTERN_REASONS,
    PROTECTED_PATH,
    REASON_CODES,
    RULE_REASONS,
    SESSION_LOCKED,
    SESSION_REASONS,
)

ROOT = Path(__file__).resolve().parents[1]


def test_the_registry_holds_the_session_and_the_kernel_answers() -> None:
    """The refusals the session and the catalog raise, and the verdicts the kernel returns, are codes."""
    assert set(SESSION_REASONS) == {
        PATH_POLICY,
        PATCH_NOT_APPLIED,
        NODE_TIMEOUT,
        LINKED_PATH_IN_WORKSPACE,
        HARDLINKED_PATH_IN_WORKSPACE,
        SESSION_LOCKED,
    }
    assert set(KERNEL_REASONS) == {
        GATE_REJECTED,
        GATE_ABSTAIN,
        GATE_MISSING,
        CHECKER_REJECTED,
        CHECKER_ABSTAIN,
        NOT_APPLIED,
        PROTECTED_PATH,
        NO_INDEPENDENT_CONFIRMATION,
    }
    assert set(PATTERN_REASONS) == {AMBIGUOUS_TARGET}
    assert set(SESSION_REASONS) | set(KERNEL_REASONS) | set(PATTERN_REASONS) <= REASON_CODES


def test_the_registry_keeps_pace_with_the_rules() -> None:
    """Every self-valued constant in rules is a registered code, in definition order."""
    self_valued = {
        value
        for name, value in vars(rules).items()
        if name.isupper() and isinstance(value, str) and value == name
    }
    assert set(RULE_REASONS) == self_valued
    assert self_valued <= REASON_CODES
    assert len(RULE_REASONS) == len(self_valued)


def test_the_session_still_answers_with_registered_codes() -> None:
    """The names the session and its tests import are the registry names, not copies."""
    for name in (
        "PATH_POLICY",
        "PATCH_NOT_APPLIED",
        "NODE_TIMEOUT",
        "LINKED_PATH_IN_WORKSPACE",
        "HARDLINKED_PATH_IN_WORKSPACE",
        "SESSION_LOCKED",
    ):
        assert getattr(session_module, name) in REASON_CODES
        assert getattr(session_module, name) == name


def test_the_registry_covers_every_refusal_the_kernel_can_answer_with() -> None:
    """A sweep found kernel reasons the registry did not hold; the drift may not return."""
    from lingologos_codex import decision as kernel_decision

    verdict_words = {"VERIFIED", "SINGLE_PROVER", "UNKNOWN", "CONFIRMED", "REJECTED", "ABSTAIN"}
    kernel_refusals = {
        value
        for name, value in vars(kernel_decision).items()
        if isinstance(value, str)
        and value.upper() == value
        and value not in verdict_words
        and not value.startswith("OK_")
    }
    assert kernel_refusals <= set(REASON_CODES)


def test_every_registered_code_is_named_in_the_card() -> None:
    """A code the bundle can answer with must be listed in the card a reader holds."""
    readme = (ROOT / "README.md").read_text(encoding="utf-8", newline="")
    unnamed = sorted(code for code in REASON_CODES if "`%s`" % code not in readme)
    assert unnamed == []