core/tests/test_adr_0238_goldtether.py
Shay e7d116c924 feat(physics,cognition): Cl(4,1) geometric sovereignty convergence
Excise identity L2 dual-mode and pipeline PASSTHROUGH cold-starts; enforce
wave-only IdentityCheck with MissingWaveStateError; hard-fail GoldTether
transitions via GoldTetherViolationError; dual-competing Shadow Coherence
Gate with populated contract_assessment; auto-compile field packets before
intent ratify; conformal argmax ratification and content-addressed proof
atoms; sandwich multi-modality ingress with GoldTether digests.

Amend ADR-0243/0244 (docs/adr + research) for wave-only / SUPERSEDED sketches.
Pin binary gates in tests/test_geometric_convergence_checklist.py.

[Verification]: Smoke suite passed locally (~136–142s, 176 passed);
cognition suite passed (122 passed, 1 skipped); lifecycle suite 51 passed.
2026-07-20 12:20:05 -07:00

136 lines
4.2 KiB
Python

"""ADR-0238 — GoldTether residual, floor, autonomy, may_relax_hitl, blend."""
from __future__ import annotations
import numpy as np
import pytest
from hypothesis import given, settings
from hypothesis import strategies as st
from algebra.rotor import make_rotor_from_angle
from algebra.versor import versor_condition
from core.physics.goldtether import (
AutonomyBand,
GoldTetherMonitor,
GoldTetherViolationError,
OperatingMode,
coherence_residual,
require_unitary,
)
def _id() -> np.ndarray:
v = np.zeros(32, dtype=np.float64)
v[0] = 1.0
return v
def test_coherence_residual_nonnegative_and_zero_on_identity():
assert coherence_residual(_id()) == 0.0
r = coherence_residual(make_rotor_from_angle(0.5))
assert r >= 0.0
def test_residual_dual_corrected_and_replay():
m = GoldTetherMonitor()
F = make_rotor_from_angle(0.4)
assert m.residual(F) == m.residual(F)
assert m.residual(F) == coherence_residual(F)
def test_fail_closed_on_drift():
m = GoldTetherMonitor(epsilon_drift=1e-9)
# Inject a non-closed multivector by raw coefficients
dirty = np.zeros(32, dtype=np.float64)
dirty[0] = 0.5
dirty[1] = 0.5
with pytest.raises(GoldTetherViolationError) as excinfo:
m.update(dirty, epistemic_elevation=True)
assert excinfo.value.residual > m.epsilon_drift
assert m.autonomy == 0.0
assert m.may_relax_hitl() is False
def test_require_unitary_rejects_above_epsilon():
dirty = np.zeros(32, dtype=np.float64)
dirty[0] = 0.5
dirty[1] = 0.5
with pytest.raises(GoldTetherViolationError):
require_unitary(dirty, epsilon=1e-6)
# Identity is admitted.
assert require_unitary(_id(), epsilon=1e-6) == 0.0
def test_epistemic_elevation_raises_floor_and_autonomy():
m = GoldTetherMonitor(epsilon_drift=1e-5, floor_step=0.1, autonomy_step=0.1)
F = _id()
for _ in range(10):
m.update(F, epistemic_elevation=True)
assert m.floor > 0.0
assert m.autonomy > 0.0
assert m.autonomy <= m.floor
assert m.supervised_autonomy_level == m.autonomy
def test_never_autonomy_above_floor():
m = GoldTetherMonitor(floor_step=0.02, autonomy_step=0.5)
for _ in range(20):
m.update(_id(), epistemic_elevation=True)
assert m.autonomy <= m.floor + 1e-12
def test_may_relax_hitl_thresholds():
m = GoldTetherMonitor(
hitl_floor_threshold=0.3,
hitl_autonomy_threshold=0.2,
floor_step=0.1,
autonomy_step=0.1,
)
assert m.may_relax_hitl() is False
for _ in range(20):
m.update(_id(), epistemic_elevation=True)
assert m.may_relax_hitl() is True
def test_force_reset():
m = GoldTetherMonitor()
m.update(_id(), epistemic_elevation=True)
m.force_reset()
assert m.floor == 0.0 and m.autonomy == 0.0 and m.history == []
def test_serve_never_autonomous_band():
m = GoldTetherMonitor(floor_step=0.2, autonomy_step=0.2, hitl_floor_threshold=0.1, hitl_autonomy_threshold=0.1)
for _ in range(10):
m.update(_id(), epistemic_elevation=True)
d = m.decide(0.0, mode=OperatingMode.SERVE)
assert d.band is not AutonomyBand.AUTONOMOUS
def test_lifelong_curve_telemetry_replay():
m1 = GoldTetherMonitor()
m2 = GoldTetherMonitor()
for _ in range(5):
# identity always closed; deterministic elevation path
m1.update(_id(), epistemic_elevation=True)
m2.update(_id(), epistemic_elevation=True)
assert m1.telemetry()["history_tail"] == m2.telemetry()["history_tail"]
assert m1.telemetry()["schema_version"] == "goldtether_coherence_v2"
def test_supervised_blend_closure_and_endpoints():
m = GoldTetherMonitor()
src = _id()
tgt = make_rotor_from_angle(0.6)
assert np.allclose(m.supervised_blend(src, tgt, 0.0), src)
assert np.allclose(m.supervised_blend(src, tgt, 1.0), tgt, atol=1e-6)
mid = m.supervised_blend(src, tgt, 0.5)
assert versor_condition(mid) < 1e-6
@given(st.floats(min_value=0.0, max_value=1.0, allow_nan=False, allow_infinity=False))
@settings(max_examples=30)
def test_blend_property_closed(alpha: float):
m = GoldTetherMonitor()
out = m.supervised_blend(_id(), make_rotor_from_angle(0.8), float(alpha))
assert versor_condition(out) < 1e-6