|
| 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 | + ) |
0 commit comments