codex-python / tests /test_reasons.py
tailot's picture
Upload folder using huggingface_hub
ba784dc verified
Raw History Blame Contribute Delete
3.42 kB
"""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 == []