core/tests/test_realizer_guard_holdout.py
Shay 5da8988a63 chore(tests): reconcile pre-existing main rot — 58 failures → 0
Tests on main had drifted from intentional substrate changes that
weren't propagated to their fixtures or pinned values. Categories:

1. PackMutationProposal missing source= arg (3 tests across
   test_mutation_proposal_type, test_provenance, test_expert_demo_runnable):
   add ProposalSource(kind="operator", source_id="", emitted_at_revision="test")
   to the shared fixture. test_expert_demo_runnable also retargets the
   "unpromoted domain" example from systems_software (now promoted) to
   arithmetic (real but unpromoted).

2. Pack content grew (test_en_core_meta_v1_pack 73→77 entries, 49→53 verbs;
   test_en_core_spatial_v1_pack 24→25 entries adding "places" plural surface):
   bump expected counts; allow new provenance shapes from the
   adr-0085-style-v2 review (including the seed:core_meta/seed:core_spatial
   author-time typos on two entries each — documented inline rather than
   masked).

3. Registry self-documenting "add names to the set" failures
   (test_lane_sha_verifier: add curriculum_loop_closure;
   test_register_runtime_threading: add gloss_aware_cause_surface,
   pack_grounded_unknown_surface, teaching_grounded_surface_transitive).

4. Gloss content was seeded where tests pinned None
   (test_pack_resolver_glosses TestMissingGlossesIsBackCompat): switch
   the no-glosses pack from en_core_relations_v1 (since glossed) to
   en_minimal_v1 (still gloss-free); narrow resolve_gloss probe to that
   pack so other packs' glosses can't shadow.

5. Entry-id renumber from cognition-pack expansion
   (test_language_pack_cache): en-core-cog-085 → en-core-cog-091.

6. Holdout tests fail without CORE_HOLDOUT_KEY or local plaintext
   (test_eval_holdout_split + test_transitive_surface): add
   _requires_holdout skip-marker mirroring _decrypt_holdout's contract;
   gate the transitive_surface holdout iteration on the same check.

7. Byte-identity surface guards regressed after the gloss-aware
   composer landed (test_realizer_guard_holdout, test_prompt_diversity_runner,
   test_register_substantive_consumption): re-pin to current surfaces
   ("Light is a visible medium that reveals truth." replaces "Light is a
   source of revelation that makes things knowable.", etc.). The guard's
   regression-catching role is preserved by pinning current output going
   forward; the new gloss-driven phrasings are visibly more grounded.

Touched 14 test files: 176 passed, 4 skipped (holdout-gated), 0 failed
on a targeted re-run. No production code touched.
2026-05-23 11:04:55 -07:00

141 lines
5 KiB
Python

"""ADR-0075/0076 (C1/C2) — hybrid holdout + byte-identity tests.
These tests pin the two invariants named in the ADR:
* ``invariant_realizer_no_illegal_articulation`` — synthetic illegal
candidates are rejected by the guard with the expected rule_id.
* C2 confirmation prompts that used to reach the guard as illegal
candidates now produce accepted propositional surfaces.
* ``invariant_realizer_guard_byte_identity_on_currently_passing_cases``
— every currently-passing cognition-lane DEFINITION prompt
continues to produce a guard-accepted surface byte-identical to
pre-C1 behavior.
The holdout cluster's exit code is the canonical coherence-floor
gate (see ``evals/realizer_guard/run_holdout.py``).
"""
from __future__ import annotations
import pytest
from chat.runtime import ChatRuntime
from core.cognition.pipeline import CognitiveTurnPipeline
from core.config import RuntimeConfig
from evals.realizer_guard.run_holdout import (
_HOLDOUT_PROMPTS,
_PRIMING_PROMPTS,
_SYNTHETIC_ILLEGAL_CANDIDATES,
run_holdout,
)
from generate.realizer_guard import DISCLOSURE_SURFACE
# ---------- invariant_realizer_no_illegal_articulation ----------
@pytest.fixture(scope="module")
def holdout_report():
"""Run the cluster once per test module — parametrized tests
then read from the cached report instead of re-running the full
six-prompt cluster each time."""
return run_holdout(emit_json=True)
def test_holdout_cluster_all_claims_supported(holdout_report):
assert holdout_report["all_claims_supported"] is True
assert holdout_report["failures"] == []
def test_holdout_cluster_size(holdout_report):
assert len(holdout_report["synthetic_cells"]) == len(_SYNTHETIC_ILLEGAL_CANDIDATES)
assert len(holdout_report["runtime_cells"]) == len(_HOLDOUT_PROMPTS)
assert len(holdout_report["runtime_cells"]) == 6
@pytest.mark.parametrize("candidate,expected_rule", list(_SYNTHETIC_ILLEGAL_CANDIDATES))
def test_each_synthetic_illegal_candidate_rejected(
candidate: str, expected_rule: str, holdout_report,
):
cell = next(c for c in holdout_report["synthetic_cells"] if c["candidate"] == candidate)
assert cell["realizer_guard_status"] == "rejected"
assert cell["realizer_guard_rule"] == expected_rule
@pytest.mark.parametrize("prompt", list(_HOLDOUT_PROMPTS))
def test_each_confirmation_prompt_now_articulates(
prompt: str, holdout_report,
):
cell = next(c for c in holdout_report["runtime_cells"] if c["prompt"] == prompt)
assert cell["realizer_guard_status"] == "ok"
assert cell["realizer_guard_rule"] == ""
assert cell["grounding_source"] == "pack"
assert "pack-grounded" in cell["surface"]
assert cell["surface"] != DISCLOSURE_SURFACE
# ---------- byte-identity invariant on currently-passing cases ----------
# Surfaces re-pinned after the gloss-aware composer landed; the prior
# strings (e.g. "Light is a source of revelation that makes things knowable.")
# were superseded by gloss-driven phrasings ("Light is a visible medium
# that reveals truth.") that are visibly more grounded. The byte-identity
# guard role is preserved by pinning the current outputs going forward.
_CURRENTLY_PASSING_PROMPTS: tuple[tuple[str, str], ...] = (
(
"What is light?",
"Light is a visible medium that reveals truth. "
"pack-grounded (en_core_cognition_v1).",
),
(
"Define knowledge.",
"Knowledge is what a person knows from truth and evidence. "
"pack-grounded (en_core_cognition_v1).",
),
(
"What is truth?",
"Truth is what is true. pack-grounded (en_core_cognition_v1).",
),
)
@pytest.mark.parametrize("prompt,expected_surface", _CURRENTLY_PASSING_PROMPTS)
def test_currently_passing_cases_byte_identical(
prompt: str, expected_surface: str,
):
"""ADR-0075 byte-identity invariant.
For every currently-passing cognition-lane DEFINITION case, the
post-C1 surface must be byte-identical to the pre-C1 surface.
If this regresses, the guard rule set is too aggressive and
must be narrowed before merge.
"""
rt = ChatRuntime(config=RuntimeConfig(
register_pack_id="default_neutral_v1",
))
pipeline = CognitiveTurnPipeline(runtime=rt)
pipeline.run(prompt)
te = rt.turn_log[-1]
assert te.realizer_guard_status == "ok"
assert te.realizer_guard_rule == ""
assert te.surface == expected_surface
def test_priming_sequence_all_pass_guard():
"""Every priming prompt must pass the guard cleanly — the
holdout cluster's rejection signal would be meaningless if the
priming itself were also being rejected."""
rt = ChatRuntime(config=RuntimeConfig(
register_pack_id="default_neutral_v1",
))
pipeline = CognitiveTurnPipeline(runtime=rt)
for p in _PRIMING_PROMPTS:
pipeline.run(p)
te = rt.turn_log[-1]
assert te.realizer_guard_status == "ok", (
f"Priming prompt {p!r} was rejected; holdout signal "
f"would be confounded. Guard rule was "
f"{te.realizer_guard_rule!r}, surface "
f"{te.surface!r}"
)