idea194-attractorforge-veri.../tests/test_compiler.py

49 lines
1.6 KiB
Python

from idea194_attractorforge_verified_attractor import AttractorCompiler, AttractorSpec
from idea194_attractorforge_verified_attractor.runtime import DeterministicRuntime
def test_motion_template_compiles_and_replays() -> None:
spec = AttractorSpec(
spec_id="motion-demo",
kind="motion_manifold",
state_labels=("radial_error", "along_track_error"),
target_state=(0.0, 0.0),
control_limit=0.8,
dt=0.1,
horizon=18,
basin_radius=1.5,
convergence_rate=0.3,
safety_margin=0.2,
objective="invariant-manifold-transfer",
)
result = AttractorCompiler().compile(spec)
replay = DeterministicRuntime().replay(result.controller, result.plan_delta)
assert replay.matched
assert result.plan_cert.spec_id == spec.spec_id
assert result.basin_sketch.controller_hash
assert abs(replay.final_state[0]) < 0.8
assert abs(replay.final_state[1]) < 0.8
def test_bio_template_uses_bounded_controls() -> None:
spec = AttractorSpec(
spec_id="bio-demo",
kind="bio_basin",
state_labels=("substrate", "biomass", "toxin"),
target_state=(1.0, 0.7, 0.15),
control_limit=0.6,
dt=0.1,
horizon=20,
basin_radius=0.8,
convergence_rate=0.25,
safety_margin=0.1,
objective="microbiome-basin-stabilization",
)
result = AttractorCompiler().compile(spec)
assert all(abs(v) <= spec.control_limit for step in result.plan_delta.steps for v in step.control)
assert result.plan_cert.certificate_hash
assert result.plan_cert.merkle_root == result.plan_delta.merkle_root