61 lines
2.2 KiB
Python
61 lines
2.2 KiB
Python
from gravityweave import ContactWindow, MissionNode, MissionSimulator, MissionTask
|
|
from gravityweave.delta_synopsis import build_synopsis, verify_synopsis
|
|
from gravityweave.plan_delta import PlanDelta
|
|
|
|
|
|
def test_plan_delta_snapshot_round_trip():
|
|
delta = PlanDelta(origin="sat1")
|
|
delta.commitments.add({"task_id": "t1", "type": "downlink"}, ts=2.0)
|
|
delta.priority.write(11, ts=3.0)
|
|
|
|
restored = PlanDelta.from_snapshot(delta.snapshot())
|
|
|
|
assert restored.origin == "sat1"
|
|
assert restored.priority.read() == 11
|
|
assert restored.priority.ts == 3.0
|
|
assert restored.commitments.value() == [{"task_id": "t1", "type": "downlink"}]
|
|
|
|
|
|
def test_synopsis_verification_with_fixed_id():
|
|
delta = PlanDelta(origin="sat1")
|
|
delta.commitments.add({"task_id": "t2", "type": "science"}, ts=1.0)
|
|
delta.priority.write(8, ts=1.0)
|
|
|
|
syn = build_synopsis(
|
|
delta,
|
|
parent_version="v1",
|
|
urgency_score=3,
|
|
impact_score=8,
|
|
affected_assets=["sat1"],
|
|
signer="sat1",
|
|
key=b"secret",
|
|
delta_id="fixed-delta",
|
|
)
|
|
|
|
assert syn["delta_id"] == "fixed-delta"
|
|
assert verify_synopsis(syn, key=b"secret")
|
|
|
|
|
|
def test_mission_simulator_is_deterministic():
|
|
nodes = [MissionNode("sat1", "satellite"), MissionNode("relay1", "relay")]
|
|
tasks = [
|
|
MissionTask("task-a", "sat1", "downlink", utility=9.0, deadline_step=0, safety_critical=True, payload_bytes=256),
|
|
MissionTask("task-b", "sat1", "science", utility=4.0, deadline_step=1, payload_bytes=256),
|
|
]
|
|
windows = [
|
|
ContactWindow("sat1", "relay1", step=0, bandwidth_bytes=1024),
|
|
ContactWindow("sat1", "relay1", step=1, bandwidth_bytes=1024),
|
|
]
|
|
|
|
sim_one = MissionSimulator(nodes=nodes, tasks=tasks, windows=windows, ledger_key=b"ledger", synopsis_key=b"syn")
|
|
metrics_one = sim_one.run()
|
|
|
|
nodes_again = [MissionNode("sat1", "satellite"), MissionNode("relay1", "relay")]
|
|
sim_two = MissionSimulator(nodes=nodes_again, tasks=tasks, windows=windows, ledger_key=b"ledger", synopsis_key=b"syn")
|
|
metrics_two = sim_two.run()
|
|
|
|
assert metrics_one == metrics_two
|
|
assert metrics_one["tasks_completed"] == 2
|
|
assert metrics_one["safety_critical_completed"] == 1
|
|
assert sim_one.ledger.verify_chain()
|