Skip to content

Commit 06abe2f

Browse files
authored
fix(tests): exercise canonical Goal Stop in Steward monitor checks (#8527)
1 parent 2101156 commit 06abe2f

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

‎tests/test_native_steward_monitor.py‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def local_watch_row(runtime, actor, todo_id):
3434
todo_id=todo_id, role="agent")["todo"]
3535

3636

37+
def stop_watch_goal(runtime, actor):
38+
from loopx.control_plane.goals.activation_service import set_goal_activation_state
39+
stopped = set_goal_activation_state(registry_path=runtime.registry_path, goal_id=actor["goal_id"],
40+
state="stopped", reason="Original owner stopped this synthetic Goal.",
41+
runtime_root_override=str(runtime.coordination_runtime_root), actor_kind="owner", execute=True)
42+
assert stopped["ok"] and stopped["written"] and stopped["readback"]["verified"], stopped
43+
return stopped
44+
45+
3746
def edit_local_watch(runtime, actor, todo_id, *changes):
3847
from loopx.capabilities.native_chat.steward_commands import native_command
3948
monitor = StewardMonitor(runtime)
@@ -210,22 +219,22 @@ def test_local_native_watch_denials_keep_original_deadline_and_invoke_no_model(s
210219
"wrong_session": ["--target-key", "managed-session-watch." + "0"*32],
211220
"not_watch": ["--action-kind", "different_source"]}[fault]
212221
edit_local_watch(runtime, actor, todo_id, *changes)
213-
elif fault in {"revoked", "stopped", "lifetime"}:
222+
elif fault in {"revoked", "lifetime"}:
214223
data = json.loads(runtime.registry_path.read_text())
215224
goal = next(g for g in data["goals"] if g["id"] == actor["goal_id"])
216225
if fault == "revoked":
217226
goal["coordination"]["registered_agents"] = ["peer"]
218-
elif fault == "stopped":
219-
goal["status"] = "stopped"
220227
else:
221228
goal["goal_instance_id"] = "replacement"
222229
runtime.registry_path.write_text(json.dumps(data))
223230
elif fault == "busy":
224231
store.update_session(session["session_id"], active_turn_id="original-busy")
225-
else:
232+
elif fault == "queued":
226233
store.create_queued_turn(session["session_id"], client_turn_id="user-first", message="Keep this first", origin="web")
227234
before, watch = capture.read_bytes(), local_watch_row(runtime, actor, todo_id)
228235
history = store.messages(session["session_id"])
236+
if fault == "stopped":
237+
stop_watch_goal(runtime, actor)
229238
assert not pump_steward_monitors(runtime)
230239
assert capture.read_bytes() == before and local_watch_row(runtime, actor, todo_id) == watch
231240
assert store.messages(session["session_id"]) == history
@@ -239,26 +248,29 @@ def test_local_watch_rechecks_native_authority_after_collection_before_poll(stew
239248
store, runtime, *_ = steward
240249
before, watch = capture.read_bytes(), local_watch_row(runtime, actor, todo_id)
241250
original_commit = StewardMonitor._commit_poll
251+
stop_receipt = None
242252
def changed(monitor, host, request, turn, context, argv):
253+
nonlocal stop_receipt
243254
if fault == "pause":
244255
native_command(runtime, ["todo", "update", "--goal-id", actor["goal_id"],
245256
"--todo-id", todo_id, "--agent-id", actor["agent_id"], "--update-operation-id", "pause-original-watch",
246257
"--role", "agent", "--reason", "Owner paused the original native watch.",
247258
"--status", "blocked", "--clear-resume-when", "--execute"])
259+
elif fault == "stop":
260+
stop_receipt = stop_watch_goal(runtime, actor)
248261
else:
249262
data = json.loads(runtime.registry_path.read_text())
250263
goal = next(g for g in data["goals"] if g["id"] == actor["goal_id"])
251-
if fault == "revoke":
252-
goal["coordination"]["registered_agents"] = ["peer"]
253-
else:
254-
goal["status"] = "stopped"
264+
goal["coordination"]["registered_agents"] = ["peer"]
255265
runtime.registry_path.write_text(json.dumps(data))
256266
return original_commit(monitor, host, request, turn, context, argv)
257267
monkeypatch.setattr(StewardMonitor, "_commit_poll", changed)
258268
turns = pump_steward_monitors(runtime)
259269
assert len(turns) == 1
260270
result = finish(runtime, turns[0])
261271
assert result["status"] == "failed", result
272+
if fault == "stop":
273+
assert stop_receipt is not None, result
262274
after = local_watch_row(runtime, actor, todo_id)
263275
for key in ["result_hash", "last_checked_at", "next_due_at", "material_change_generation"]:
264276
assert after.get(key) == watch.get(key)
@@ -1019,14 +1031,10 @@ def test_restarted_host_reads_paused_state_then_runs_one_fresh_native_generation
10191031

10201032

10211033
def test_native_goal_stop_blocks_observation_and_owner_can_still_pause_the_monitor(steward, tmp_path, monkeypatch):
1022-
from loopx.control_plane.goals.activation_service import set_goal_activation_state
10231034
_, runtime, _, transport, binding, capture, _ = steward
10241035
_, actor, monitor = prepared(steward, tmp_path, monkeypatch)
10251036
before, calls = monitor.current(actor), capture.read_bytes()
1026-
stopped = set_goal_activation_state(registry_path=runtime.registry_path, goal_id=actor["goal_id"],
1027-
state="stopped", reason="Original owner stopped this synthetic Goal.",
1028-
runtime_root_override=str(runtime.coordination_runtime_root), actor_kind="owner", execute=True)
1029-
assert stopped["ok"]
1037+
stop_watch_goal(runtime, actor)
10301038
assert not pump_steward_monitors(runtime)
10311039
assert monitor.current(actor) == before and capture.read_bytes() == calls
10321040
health = transport.managed_steward.health(binding["binding_id"])

0 commit comments

Comments
 (0)