Skip to content
Merged
Show file tree
Hide file tree
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
42 changes: 30 additions & 12 deletions tests/control_plane/test_turn_host_decision_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,14 @@ def no_new_host(_request):


@pytest.mark.parametrize("provider", ["file", "sqlite"])
@pytest.mark.parametrize("first_attempt_fails", [False, True])
@pytest.mark.parametrize(("first_attempt_fails", "restore_live_work"), [
pytest.param(False, False, id="committed"),
pytest.param(True, True, id="restore-live-work"),
pytest.param(True, False, id="changed-live-work"),
])
@pytest.mark.parametrize("legacy_pretty", [False, True])
def test_real_host_reads_original_capture_after_source_change(
tmp_path, monkeypatch, provider, first_attempt_fails, legacy_pretty,
tmp_path, monkeypatch, provider, first_attempt_fails, restore_live_work, legacy_pretty,
):
from loopx.cli_commands import turn_decision

Expand Down Expand Up @@ -701,8 +705,9 @@ def legacy_launch_selection(*_args, **_kwargs):
prefix = ["--registry", str(registry), "--runtime-root", str(runtime), "--format", "json"]
code, current = f._run_cli([*prefix, "todo", "list", "--goal-id", f.GOAL_ID, "--todo-id", f.TODO_ID])
assert code == 0
original_text = current["todo"]["text"]
code, update = f._run_cli([*prefix, "todo", "update", "--goal-id", f.GOAL_ID,
"--todo-id", f.TODO_ID, "--agent-id", f.AGENT_ID, "--text", current["todo"]["text"] + " SOURCE_B",
"--todo-id", f.TODO_ID, "--agent-id", f.AGENT_ID, "--text", original_text + " SOURCE_B",
"--update-operation-id", "source-b", "--update-expected-provider-revision",
current["authority_read"]["provider_revision"], "--execute"])
assert code == 0, update
Expand Down Expand Up @@ -773,17 +778,30 @@ def unexpected_effect(*_args, **_kwargs):
assert (workspace / "received.txt").read_bytes() == received_before
assert f._quota_spend_count(runtime) == 0
path.write_bytes(original)
code, recovered = f._run_cli([*replay, "--resume-turn-key", request["turn_key"],
"--retry-failed-turn", "--execute"])
assert code == 0 and recovered["status"] == "committed", json.dumps(recovered)
retried = json.loads((workspace / "received.txt").read_text().split("Turn request:\n", 1)[1])
assert retried["task_context"] == request["task_context"]
assert retried["detail_ref"] == detail
# The snapshot remains readable when live work changes. Launching it
# again also requires the current Todo to match the original work.
if restore_live_work:
code, restored = f._run_cli([*prefix, "todo", "update", "--goal-id", f.GOAL_ID,
"--todo-id", f.TODO_ID, "--agent-id", f.AGENT_ID, "--text", original_text,
"--update-operation-id", "restore-source-a", "--update-expected-provider-revision",
current["authority_read"]["provider_revision"], "--execute"])
assert code == 0 and restored["changed"], restored
code, recovered = f._run_cli(retry)
if restore_live_work:
assert code == 0 and recovered["status"] == "committed", json.dumps(recovered)
retried = json.loads((workspace / "received.txt").read_text().split("Turn request:\n", 1)[1])
assert retried["task_context"] == request["task_context"]
assert retried["detail_ref"] == detail
else:
assert code == 1 and recovered["error_code"] == "current_turn_work_changed", recovered
assert not any(recovered["effects"].values())
assert (workspace / "received.txt").read_bytes() == received_before
assert path.read_bytes() == original
code, repeated = f._run_cli([*replay, "--resume-turn-key", request["turn_key"], "--execute"])
assert code == 0, repeated
assert not any(repeated["effects"].values())
assert f._quota_spend_count(runtime) == 1
blocked_retry = first_attempt_fails and not restore_live_work
assert code == (1 if blocked_retry else 0), repeated
assert repeated["replayed"] and not any(repeated["effects"].values())
assert f._quota_spend_count(runtime) == (0 if blocked_retry else 1)
assert path.read_bytes() == original
# Admission can run between source validation and publication. It cannot
# replace or silently recreate an original capture changed in that window.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_steward_interrupted_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ def crash(**kwargs):
assert done["status"] == ("failed" if fault in {"native-changed", "review-action", "checkpoint-empty"} else "completed"), done
restarted.reconcile_request(path)
delivered = json.loads(path.read_text())
terminal = delivered["deliveries"]["terminal.recovery.22.review.1"]
terminal = delivered["deliveries"][f"terminal.recovery.{recovery['presentation_key']}"]
assert terminal["verified"]
actual = provider.messages[terminal["attempt"]["message_ref"]]
assert actual["chat_id"] == event["chat_id"] and actual["sender"]["id"] == provider.profile_apps["steward-app"]
Expand Down
Loading