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.
174 lines
4.7 KiB
Python
174 lines
4.7 KiB
Python
"""Unit tests for core.cognition.provenance.
|
|
|
|
Covers the four expected source profiles:
|
|
- pack only (intent classified, no vault, no teaching)
|
|
- pack + vault (recall fired)
|
|
- pack + teaching (correction captured)
|
|
- no provenance (UNKNOWN intent, no vault, no teaching)
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
|
|
from core.cognition.provenance import compute_provenance
|
|
from core.cognition.result import CognitiveTurnResult
|
|
from field.state import FieldState
|
|
from generate.articulation import ArticulationPlan
|
|
from generate.intent import DialogueIntent, IntentTag
|
|
from generate.proposition import Proposition
|
|
from teaching.source import ProposalSource
|
|
from teaching.store import PackMutationProposal
|
|
|
|
|
|
def _zero_versor() -> np.ndarray:
|
|
v = np.zeros(32, dtype=np.float32)
|
|
v[0] = 1.0
|
|
return v
|
|
|
|
|
|
def _make_field_state() -> FieldState:
|
|
"""Build a minimal valid field state for tests."""
|
|
F = _zero_versor()
|
|
return FieldState(F=F)
|
|
|
|
|
|
def _make_result(
|
|
*,
|
|
intent_tag: IntentTag,
|
|
vault_hits: int,
|
|
teaching_proposal: PackMutationProposal | None,
|
|
trace_hash: str = "deadbeef",
|
|
) -> CognitiveTurnResult:
|
|
proposition = Proposition(
|
|
subject="x",
|
|
predicate="is",
|
|
object_="y",
|
|
surface="x is y",
|
|
frame_id="test",
|
|
subject_versor=_zero_versor(),
|
|
predicate_versor=_zero_versor(),
|
|
)
|
|
articulation = ArticulationPlan(
|
|
subject="x",
|
|
predicate="is",
|
|
object="y",
|
|
surface="x is y",
|
|
output_language="en",
|
|
frame_id="test",
|
|
)
|
|
fs = _make_field_state()
|
|
intent = (
|
|
DialogueIntent(tag=intent_tag, subject="x")
|
|
if intent_tag is not None
|
|
else None
|
|
)
|
|
return CognitiveTurnResult(
|
|
input_text="what is x?",
|
|
input_tokens=("what", "is", "x"),
|
|
filtered_tokens=("x",),
|
|
field_state_before=None,
|
|
field_state_after=fs,
|
|
proposition=proposition,
|
|
articulation=articulation,
|
|
surface="x is y",
|
|
walk_surface="x is y",
|
|
articulation_surface="x is y",
|
|
dialogue_role="elaborate",
|
|
identity_score=None,
|
|
vault_hits=vault_hits,
|
|
intent=intent,
|
|
proposition_graph=None,
|
|
articulation_target=None,
|
|
teaching_candidate=None,
|
|
reviewed_teaching_example=None,
|
|
pack_mutation_proposal=teaching_proposal,
|
|
versor_condition=0.0,
|
|
trace_hash=trace_hash,
|
|
)
|
|
|
|
|
|
def test_pack_only_source() -> None:
|
|
result = _make_result(
|
|
intent_tag=IntentTag.DEFINITION,
|
|
vault_hits=0,
|
|
teaching_proposal=None,
|
|
)
|
|
prov = compute_provenance(result)
|
|
|
|
assert prov.is_empty is False
|
|
assert prov.kinds() == ("pack",)
|
|
assert prov.refs("pack") == ("definition",)
|
|
assert prov.refs("vault") == ()
|
|
assert prov.refs("teaching") == ()
|
|
|
|
|
|
def test_pack_plus_vault() -> None:
|
|
result = _make_result(
|
|
intent_tag=IntentTag.RECALL,
|
|
vault_hits=3,
|
|
teaching_proposal=None,
|
|
)
|
|
prov = compute_provenance(result)
|
|
|
|
assert prov.kinds() == ("pack", "vault")
|
|
assert prov.refs("pack") == ("recall",)
|
|
assert prov.refs("vault") == ("vault_hit_0", "vault_hit_1", "vault_hit_2")
|
|
|
|
|
|
def test_pack_plus_teaching() -> None:
|
|
proposal = PackMutationProposal(
|
|
proposal_id="abc123",
|
|
candidate_id="cand1",
|
|
subject="x",
|
|
correction_text="x is z",
|
|
prior_surface="x is y",
|
|
source=ProposalSource(
|
|
kind="operator", source_id="", emitted_at_revision="test"
|
|
),
|
|
)
|
|
result = _make_result(
|
|
intent_tag=IntentTag.CORRECTION,
|
|
vault_hits=0,
|
|
teaching_proposal=proposal,
|
|
)
|
|
prov = compute_provenance(result)
|
|
|
|
assert prov.kinds() == ("pack", "teaching")
|
|
assert prov.refs("teaching") == ("abc123",)
|
|
|
|
|
|
def test_unknown_intent_no_vault_no_teaching_is_empty() -> None:
|
|
result = _make_result(
|
|
intent_tag=IntentTag.UNKNOWN,
|
|
vault_hits=0,
|
|
teaching_proposal=None,
|
|
)
|
|
prov = compute_provenance(result)
|
|
|
|
assert prov.is_empty is True
|
|
assert prov.kinds() == ()
|
|
|
|
|
|
def test_provenance_has_kind_helper() -> None:
|
|
result = _make_result(
|
|
intent_tag=IntentTag.DEFINITION,
|
|
vault_hits=1,
|
|
teaching_proposal=None,
|
|
)
|
|
prov = compute_provenance(result)
|
|
|
|
assert prov.has_kind("pack") is True
|
|
assert prov.has_kind("vault") is True
|
|
assert prov.has_kind("teaching") is False
|
|
|
|
|
|
def test_trace_hash_preserved() -> None:
|
|
result = _make_result(
|
|
intent_tag=IntentTag.DEFINITION,
|
|
vault_hits=0,
|
|
teaching_proposal=None,
|
|
trace_hash="cafebabe",
|
|
)
|
|
prov = compute_provenance(result)
|
|
assert prov.turn_trace_hash == "cafebabe"
|