28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
from guardrail_space.capsule import make_capsule
|
|
import json
|
|
|
|
|
|
def test_capsule_size_and_fields_default():
|
|
blob = make_capsule(plan_hash="plan-123", pov=0.75, energy_gap=1.5, verdict_code="warn", round_number=3)
|
|
assert isinstance(blob, (bytes, bytearray))
|
|
assert 128 <= len(blob) <= 512
|
|
|
|
j = json.loads(blob.decode("utf-8", errors="ignore"))
|
|
# machine fields
|
|
assert j.get("r") == 3
|
|
assert "p" in j and isinstance(j["p"], str)
|
|
assert abs(j.get("v") - 0.75) < 1e-6
|
|
assert abs(j.get("g") - 1.5) < 1e-6
|
|
assert j.get("c") == "warn"
|
|
# human summary exists
|
|
assert isinstance(j.get("h"), str) and len(j.get("h")) > 0
|
|
|
|
|
|
def test_capsule_user_summary_truncation_and_determinism():
|
|
# long user-provided summary should be truncated/padded deterministically
|
|
long_summary = "This is a very long human summary. " * 20
|
|
b1 = make_capsule(plan_hash="plan-abc", pov=0.1, energy_gap=0.0, verdict_code="ok", human_summary=long_summary)
|
|
b2 = make_capsule(plan_hash="plan-abc", pov=0.1, energy_gap=0.0, verdict_code="ok", human_summary=long_summary)
|
|
assert b1 == b2
|
|
assert 128 <= len(b1) <= 512
|