From 33f359cdc13024eec3c31f2d82564a656ebe6ee7 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Mon, 16 Nov 2026 13:39:42 +0800 Subject: [PATCH] test(quota): exercise routed hard-lease settlement and replay Follow the composed writeback for a hard lease and inspect the runtime-owned quota receipt. Keep the legacy split route under test and prove that both settle the original Turn once through the selected CLI. Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- tests/control_plane/test_cli_program_route.py | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/tests/control_plane/test_cli_program_route.py b/tests/control_plane/test_cli_program_route.py index 3a5adbfb94..e2d0f51f6e 100644 --- a/tests/control_plane/test_cli_program_route.py +++ b/tests/control_plane/test_cli_program_route.py @@ -132,28 +132,66 @@ def run(argv, *, expected_code=0): assert guard["decision"] == "run", guard identity = guard["heartbeat_receipt"]["settlement_identity"] assert identity["todo_id"] == cli.TODO_ID and identity["turn_instance_id"] == cli.TURN_ID - commands = {s["kind"]: s["command_template"] for s in channel["settlement_plan"]["ordered_steps"]} - for command in [*channel["next_cli_actions"], *commands.values()]: + plan = channel["settlement_plan"] + steps = {step["kind"]: step for step in plan["ordered_steps"]} + commands = [step["command_template"] for step in steps.values() if step["owner"] == "agent"] + for command in [*channel["next_cli_actions"], *commands]: assert shlex.split(command)[0] == program for read in guard["interaction_contract"]["agent_channel"].get("required_reads", []): assert shlex.split(read["command"])[0] != "loopx" - refresh = commands["durable_writeback"].replace("", "validated_progress") - refresh = refresh.replace("", "implementation").replace("", "outcome_progress") - refreshed = run([ + refresh = ( + steps["durable_writeback"]["command_template"] + .replace("", "validated_progress") + .replace("", "implementation") + .replace("", "outcome_progress") + ) + refresh_argv = [ *shlex.split(refresh), "--vision-state", "vision_on_track", "--vision-summary", "Continue eligible work.", "--vision-acceptance", "The original runtime settles its selected work once.", "--no-global-sync", "--suppress-external-sinks", - ]) + ] + spend_step = steps["quota_spend"] + if handoff_mode == "hard_lease": + assert plan["schema_version"] == "quota_settlement_plan_v2" + assert spend_step["owner"] == "runtime" + assert "command_template" not in spend_step + assert all("spend-slot" not in shlex.split(action) for action in channel["next_cli_actions"]) + assert {"--settle-turn", "--settlement-receipt"} <= set(refresh_argv) + else: + assert spend_step["owner"] == "agent" + + refreshed = run(refresh_argv) assert refreshed["vision_checkpoint"]["satisfied"] - owed = refreshed["settlement_owed"]["command"] - assert shlex.split(owed)[0] == program - first, replay = run(shlex.split(owed)), run(shlex.split(owed)) + if handoff_mode == "hard_lease": + assert refreshed["settlement_result"]["ok"] + receipts = refreshed["settlement_result"]["receipts"] + assert [receipt["step_kind"] for receipt in receipts] == [ + "validation", "durable_writeback", "quota_spend", + ] + assert all( + receipt["effect_id"] == identity["effect_id"] and receipt["status"] == "committed" + for receipt in receipts + ) + assert refreshed["quota_spend"]["appended"] + first = refreshed + settle_argv = refresh_argv + else: + assert cli._spend_run_count(runtime) == 0 + settle_argv = shlex.split(refreshed["settlement_owed"]["command"]) + assert settle_argv[0] == program + first = run(settle_argv) assert first["settlement_progress"]["state"] == "settled" and first["appended"] + assert cli._spend_run_count(runtime) == 1 + replay = run(settle_argv) assert replay["idempotent_replay"] and not replay["appended"] assert first["settlement_identity"] == identity + if handoff_mode == "hard_lease": + assert replay["settlement_identity"] == identity + assert replay["settlement_result"] == first["settlement_result"] assert cli._spend_run_count(runtime) == 1 + assert cli._classification_count(runtime, "validated_progress") == 1 if lease: released = run([ *prefix, "task-lease", "release", "--goal-id", cli.GOAL_ID,