Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions tests/control_plane/test_cli_program_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>", "validated_progress")
refresh = refresh.replace("<scale>", "implementation").replace("<outcome>", "outcome_progress")
refreshed = run([
refresh = (
steps["durable_writeback"]["command_template"]
.replace("<validated_progress>", "validated_progress")
.replace("<scale>", "implementation")
.replace("<outcome>", "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,
Expand Down
Loading