Skip to content

Commit daefadf

Browse files
committed
test(control-plane): add quota should-run parity fixtures
1 parent 27bc9ac commit daefadf

2 files changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Parity fixture helpers for `quota should-run` extraction."""
2+
3+
from __future__ import annotations
4+
5+
from collections.abc import Mapping
6+
from typing import Any
7+
8+
from ...quota import build_quota_should_run
9+
10+
11+
def compact_quota_should_run_parity(
12+
packet: Mapping[str, Any],
13+
) -> dict[str, Any]:
14+
"""Return a compact stable surface for old/new quota builder comparison."""
15+
16+
interaction = (
17+
packet.get("interaction_contract")
18+
if isinstance(packet.get("interaction_contract"), Mapping)
19+
else {}
20+
)
21+
lane = (
22+
packet.get("work_lane_contract")
23+
if isinstance(packet.get("work_lane_contract"), Mapping)
24+
else {}
25+
)
26+
scheduler = (
27+
packet.get("scheduler_hint")
28+
if isinstance(packet.get("scheduler_hint"), Mapping)
29+
else {}
30+
)
31+
gate = packet.get("capability_gate")
32+
gate = gate if isinstance(gate, Mapping) else {}
33+
return {
34+
"decision": packet.get("decision"),
35+
"should_run": packet.get("should_run"),
36+
"effective_action": packet.get("effective_action"),
37+
"recommended_action": packet.get("recommended_action"),
38+
"interaction_mode": interaction.get("mode"),
39+
"interaction_action_required": interaction.get("action_required"),
40+
"lane": lane.get("lane"),
41+
"obligation": lane.get("obligation"),
42+
"must_attempt_work": lane.get("must_attempt_work"),
43+
"scheduler_action": scheduler.get("action"),
44+
"scheduler_cadence_class": scheduler.get("cadence_class"),
45+
"capability_gate_action": gate.get("action"),
46+
}
47+
48+
49+
def build_quota_should_run_parity(
50+
status_payload: Mapping[str, Any],
51+
**kwargs: Any,
52+
) -> dict[str, Any]:
53+
"""Build `quota should-run` and reduce it to the compact parity surface."""
54+
55+
return compact_quota_should_run_parity(
56+
build_quota_should_run(dict(status_payload), **kwargs)
57+
)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from __future__ import annotations
2+
3+
from loopx.control_plane.testing.quota_fixtures import quota_status_payload
4+
from loopx.control_plane.testing.quota_should_run_parity import (
5+
build_quota_should_run_parity,
6+
)
7+
8+
GOAL_ID = "quota-parity-fixture"
9+
10+
11+
def test_advancement_run_parity_surface() -> None:
12+
todo_text = "[P1] Advance the bounded slice."
13+
payload = quota_status_payload(
14+
goal_id=GOAL_ID,
15+
status="active",
16+
agent_todo_items=[
17+
{
18+
"index": 1,
19+
"text": todo_text,
20+
"role": "agent",
21+
"status": "open",
22+
"priority": "P1",
23+
"task_class": "advancement_task",
24+
}
25+
],
26+
recommended_action=todo_text,
27+
next_action=todo_text,
28+
)
29+
30+
parity = build_quota_should_run_parity(payload, goal_id=GOAL_ID)
31+
32+
assert parity["decision"] == "run"
33+
assert parity["should_run"] is True
34+
assert parity["effective_action"] == "normal_run"
35+
assert parity["lane"] == "advancement_task"
36+
assert parity["obligation"] == "advance_one_bounded_segment"
37+
assert parity["must_attempt_work"] is True
38+
assert parity["interaction_mode"] == "bounded_delivery"
39+
assert parity["capability_gate_action"] is None
40+
41+
42+
def test_capability_gate_repair_parity_surface() -> None:
43+
todo_text = "[P1] Network-only slice."
44+
payload = quota_status_payload(
45+
goal_id=GOAL_ID,
46+
status="active",
47+
agent_todo_items=[
48+
{
49+
"index": 1,
50+
"text": todo_text,
51+
"role": "agent",
52+
"status": "open",
53+
"priority": "P1",
54+
"task_class": "advancement_task",
55+
"required_capabilities": ["network"],
56+
}
57+
],
58+
recommended_action=todo_text,
59+
next_action=todo_text,
60+
)
61+
62+
parity = build_quota_should_run_parity(
63+
payload,
64+
goal_id=GOAL_ID,
65+
available_capabilities=["shell"],
66+
)
67+
68+
assert parity["decision"] == "repair_bridge"
69+
assert parity["should_run"] is True
70+
assert parity["effective_action"] == "capability_bridge_repair"
71+
assert parity["capability_gate_action"] == "repair_bridge"
72+
assert parity["lane"] == "advancement_task"

0 commit comments

Comments
 (0)