32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
from gravityweave.plan_delta import PlanDelta
|
|
from gravityweave.witness import generate_feasibility_witness
|
|
from gravityweave.safety_stub import extract_safety_stub
|
|
|
|
|
|
def test_generate_feasibility_witness_basic():
|
|
pd = PlanDelta(origin="node1")
|
|
pd.commitments.add({"type": "burn", "fuel": 5.0, "power": 1.0, "payload_bytes": 100})
|
|
pd.commitments.add({"type": "downlink", "fuel": 0.0, "power": 2.0, "payload_bytes": 200})
|
|
|
|
w = generate_feasibility_witness(pd)
|
|
assert w["total_fuel"] == 5.0
|
|
assert w["total_power"] == 3.0
|
|
assert w["max_payload_bytes"] == 300
|
|
assert w["commitment_count"] == 2
|
|
assert isinstance(w["summary_hash"], str) and len(w["summary_hash"]) == 16
|
|
|
|
|
|
def test_extract_safety_stub_filters():
|
|
pd = PlanDelta(origin="satA")
|
|
pd.commitments.add({"task_id": "t1", "type": "science", "safety_critical": True, "fuel": 1.0})
|
|
pd.commitments.add({"task_id": "t2", "type": "downlink", "fuel": 0.0})
|
|
pd.commitments.add({"task_id": "t3", "type": "safe-hold", "fuel": 0.0})
|
|
|
|
stub = extract_safety_stub(pd)
|
|
# should include t1 (safety_critical) and t3 (whitelist)
|
|
ids = {c.get("task_id") for c in stub["stub_commitments"]}
|
|
assert "t1" in ids
|
|
assert "t3" in ids
|
|
assert stub["origin"] == "satA"
|
|
assert isinstance(stub["provenance"], str) and len(stub["provenance"]) == 16
|