diff --git a/loopx/capabilities/native_chat/github_pr_evidence.py b/loopx/capabilities/native_chat/github_pr_evidence.py index c74913787a..94834bfdc2 100644 --- a/loopx/capabilities/native_chat/github_pr_evidence.py +++ b/loopx/capabilities/native_chat/github_pr_evidence.py @@ -114,7 +114,7 @@ def _git_origin_slug(repo_path: Path) -> str | None: try: completed = subprocess.run( ["git", "-C", str(repo_path), "config", "--get", "remote.origin.url"], - capture_output=True, text=True, check=False, timeout=3, + capture_output=True, text=True, encoding="utf-8", check=False, timeout=3, ) if completed.returncode == 0: return normalize_github_repo_slug(completed.stdout.strip()) diff --git a/loopx/cli_commands/support_control_upgrade.py b/loopx/cli_commands/support_control_upgrade.py index 273f0119b3..40b453c021 100644 --- a/loopx/cli_commands/support_control_upgrade.py +++ b/loopx/cli_commands/support_control_upgrade.py @@ -219,7 +219,7 @@ def _upgrade_desktop(plan: dict[str, Any], timeout_seconds: int) -> dict[str, An [str(app / "Contents/MacOS" / executable), "--loopx-upgrade-prepare", f"--loopx-upgrade-request={request_id}", f"--loopx-upgrade-channel={plan['channel']}"], - capture_output=True, text=True, timeout=timeout_seconds, + capture_output=True, text=True, encoding="utf-8", timeout=timeout_seconds, ) result = json.loads(prepared.stdout) target = result.get("target") if isinstance(result, dict) else None diff --git a/loopx/control_plane/coordination/remote_authority_gateway.py b/loopx/control_plane/coordination/remote_authority_gateway.py index bc15e6e7b6..a2c16ce0c0 100644 --- a/loopx/control_plane/coordination/remote_authority_gateway.py +++ b/loopx/control_plane/coordination/remote_authority_gateway.py @@ -66,6 +66,7 @@ def check_remote_authority_gateway_status( env={key: os.environ[key] for key in ("PATH", "SystemRoot", "WINDIR", "TMPDIR", "TEMP") if key in os.environ}, text=True, + encoding="utf-8", capture_output=True, check=True, timeout=5, diff --git a/loopx/control_plane/status/goal_source.py b/loopx/control_plane/status/goal_source.py index 01aadf8d7c..25746ea128 100644 --- a/loopx/control_plane/status/goal_source.py +++ b/loopx/control_plane/status/goal_source.py @@ -386,7 +386,7 @@ def _read_page(self, goal_id, cursor, *, scope, load): raise with self._lock: if pages is not self._pages: - raise SourceScopeError("The original Goal source became unavailable during the read") + raise ValueError("The original Goal source became unavailable during the read") return {**page, "source": self.source.describe(), "goal_id": goal_id} def history(self, goal_id, cursor=""): diff --git a/loopx/control_plane/turn_driver/host_process_transport.py b/loopx/control_plane/turn_driver/host_process_transport.py index 07a1da28e0..0b1e79869d 100644 --- a/loopx/control_plane/turn_driver/host_process_transport.py +++ b/loopx/control_plane/turn_driver/host_process_transport.py @@ -422,7 +422,10 @@ def run_host_process( raise RuntimeError("Invalid managed Host process observation") finally: try: - if guarded is not None and (launch_deadline is not None or sys.exc_info()[0] is not None): + if guarded is not None and ( + launch_deadline is not None + or (supervision == "direct" and sys.exc_info()[0] is not None) + ): # A failed handoff still owns the Goal fence. The TS bridge must # report no launch or finish its Host cleanup before it releases. _cancel_guarded_host( diff --git a/loopx/extensions/lark/cli_resolution.py b/loopx/extensions/lark/cli_resolution.py index 981798caf7..f20a8ac4dd 100644 --- a/loopx/extensions/lark/cli_resolution.py +++ b/loopx/extensions/lark/cli_resolution.py @@ -278,7 +278,7 @@ def run( if dispatch_guard is not None: with dispatch_guard(): process = subprocess.Popen( - args, cwd=str(cwd) if cwd else None, env=env, text=True, + args, cwd=str(cwd) if cwd else None, env=env, text=True, encoding="utf-8", stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) with process: diff --git a/loopx/self_update.py b/loopx/self_update.py index 854a468dd9..396430b063 100644 --- a/loopx/self_update.py +++ b/loopx/self_update.py @@ -1512,7 +1512,7 @@ def execute_rollback_plan( # Share the archive installer's exact guard through checks and recovery. guard_path = release_root.parent / ".install-guard" guard_path.parent.mkdir(parents=True, exist_ok=True) - promotion_guard = os.fdopen(_open_lock_descriptor(guard_path, flags=os.O_CREAT | os.O_RDWR), "r+") + promotion_guard = os.fdopen(_open_lock_descriptor(guard_path, flags=os.O_CREAT | os.O_RDWR), "r+", encoding="utf-8") deadline = time.monotonic() + timeout_seconds while not _try_acquire_kernel_lock(promotion_guard): remaining = deadline - time.monotonic() diff --git a/tests/extensions/test_periodic_report_goal_channel_delivery.py b/tests/extensions/test_periodic_report_goal_channel_delivery.py index 6566498b65..bfd797ef81 100644 --- a/tests/extensions/test_periodic_report_goal_channel_delivery.py +++ b/tests/extensions/test_periodic_report_goal_channel_delivery.py @@ -12,6 +12,7 @@ build_periodic_report_generation_bundle, build_periodic_report_source_result, ) +from loopx.control_plane.goals.activation import build_goal_activation from loopx.extensions.lark.goal_channel_contracts import ( GOAL_CHANNEL_BINDING_SCHEMA_VERSION, write_goal_channel_binding, @@ -873,7 +874,11 @@ def test_goal_channel_delivery_rejects_canonical_stop_before_send( ) -> None: registry_path = tmp_path / ".loopx" / "registry.json" stopped = _goal() - stopped["activation_state"] = "stopped" + stopped["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-08-30T09:00:00Z", + reason="fixture stop", + ) _write_registry(registry_path, goal=stopped) _write_binding(registry_path) calls: list[list[str]] = [] @@ -981,7 +986,11 @@ def runner( if "+messages-send" in args and not stopped: stopped = True stopped_goal = _goal() - stopped_goal["activation_state"] = "stopped" + stopped_goal["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-08-30T09:00:00Z", + reason="fixture stop", + ) _write_registry(registry_path, goal=stopped_goal) return result diff --git a/tests/presentation/test_background_services_api.py b/tests/presentation/test_background_services_api.py index 623b9f18d8..9e12c810e1 100644 --- a/tests/presentation/test_background_services_api.py +++ b/tests/presentation/test_background_services_api.py @@ -33,6 +33,7 @@ def transport(_adapter, operation, **parameters): server = ChatHTTPServer(("127.0.0.1", 0), ChatRequestHandler) server.verbose = False server.codex_account_service = CodexAccountService(tmp_path, start_observer=False) + (tmp_path / "registry.json").write_text('{"schema_version": 1, "goals": []}', encoding="utf-8") server.manager_return_service = ReturnService(tmp_path / "runtime", tmp_path / "registry.json", ChatSessionStore(tmp_path / "runtime"), lambda *_: pytest.fail("No send is authorized")) server.lark_goal_topic_runtime = LarkGoalTopicRuntimeService( diff --git a/tests/test_chat_operation_actions.py b/tests/test_chat_operation_actions.py index 42395cd287..b35478125c 100644 --- a/tests/test_chat_operation_actions.py +++ b/tests/test_chat_operation_actions.py @@ -14,6 +14,7 @@ from loopx.chat_actions import ChatActionService, ProtectedActionGate from loopx.control_plane.collaboration.operation_handoff import agent_operation_action from loopx.control_plane.collaboration.inbox import pending +from loopx.control_plane.goals.activation import build_goal_activation from loopx.capabilities.manager_context import turn_start_hook from examples.operation_action_fixtures import ( GOAL_ID, @@ -286,7 +287,11 @@ def test_managed_pending_reuses_registered_agent_and_goal_instance_scope( ) registry = json.loads(service.registry_path.read_text()) - registry["goals"][0]["activation_state"] = "stopped" + registry["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) service.registry_path.write_text(json.dumps(registry)) # Stopping execution does not erase the original evidence-reconciliation locator. historical = handler("loopx_operation", args, native) @@ -682,7 +687,11 @@ def test_agent_handoff_fails_closed_on_expiry_binding_activation_or_terms_drift( elif change == "archived": registry["goals"][0]["status"] = "archived" else: - registry["goals"][0]["activation_state"] = "stopped" + registry["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) service.registry_path.write_text(json.dumps(registry)) else: data = json.loads(store.path.read_text()) @@ -849,7 +858,11 @@ def test_unknown_result_never_grants_resubmission_and_late_evidence_does_not_req **args, ) registry = json.loads(service.registry_path.read_text()) - registry["goals"][0]["activation_state"] = "stopped" + registry["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) registry["goals"][0]["coordination"]["thread_agent_bindings"][0]["thread_id"] = ( "thread-replacement" ) @@ -1022,7 +1035,11 @@ def test_replacement_session_reconciles_under_its_current_binding_without_recons ) if historical: registry = json.loads(service.registry_path.read_text()) - registry["goals"][0]["activation_state"] = "stopped" + registry["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) service.registry_path.write_text(json.dumps(registry)) after_expiry = (datetime.now(timezone.utc) + timedelta(hours=2)).isoformat() monkeypatch.setattr("loopx.chat_action_store._utc_now", lambda: after_expiry) diff --git a/tests/test_chat_status_owner.py b/tests/test_chat_status_owner.py index aa7563d9b8..edbaa3ab0c 100644 --- a/tests/test_chat_status_owner.py +++ b/tests/test_chat_status_owner.py @@ -19,7 +19,7 @@ def test_status_owner_imports_canonically_and_has_no_legacy_module(): code = """ import importlib.util from loopx.chat.status_api import ChatStatusRequestMixin, goal_read_runtime_root -from loopx.chat.todo_detail import goal_read_runtime_root as todo_runtime_root +from loopx.chat.todo_source import goal_read_runtime_root as todo_runtime_root from loopx.chat_server import ChatRequestHandler assert issubclass(ChatRequestHandler, ChatStatusRequestMixin) @@ -44,7 +44,7 @@ def test_status_owner_imports_canonically_and_has_no_legacy_module(): def test_registry_patch_reaches_already_imported_todo_consumer( monkeypatch, tmp_path, source_bound, controller_root, expected, ): - from loopx.chat.todo_detail import goal_read_runtime_root + from loopx.chat.todo_source import goal_read_runtime_root registry_path = tmp_path / "registry.json" calls = [] diff --git a/tests/test_contract_git_probe_budget.py b/tests/test_contract_git_probe_budget.py index 1fcbc72056..c3d5f3d7f4 100644 --- a/tests/test_contract_git_probe_budget.py +++ b/tests/test_contract_git_probe_budget.py @@ -181,7 +181,7 @@ def test_a_timed_out_probe_takes_the_helpers_it_started( subprocess.run( ["git", "-C", str(repo), "config", "core.fsmonitor", str(hook)], check=True ) - monkeypatch.setattr(contract, "GIT_PROBE_TIMEOUT_SECONDS", 0.8) + monkeypatch.setattr(contract, "GIT_PROBE_TIMEOUT_SECONDS", 1.5) started = time.monotonic() with pytest.raises(contract.GitProbeUnavailable): diff --git a/tests/test_doctor_git_probe_budget.py b/tests/test_doctor_git_probe_budget.py index 1a15a065b2..8efec24ee4 100644 --- a/tests/test_doctor_git_probe_budget.py +++ b/tests/test_doctor_git_probe_budget.py @@ -127,7 +127,7 @@ def test_a_blocked_query_takes_the_helpers_it_started( ["git", "-C", str(repo), "config", "core.fsmonitor", str(hook)], check=True ) - monkeypatch.setattr(doctor_git, "GIT_PROBE_TIMEOUT_SECONDS", 0.8) + monkeypatch.setattr(doctor_git, "GIT_PROBE_TIMEOUT_SECONDS", 1.5) cleanup_calls: list[float] = [] original_terminate = doctor_git.terminate_process_tree diff --git a/tests/test_global_todo_readiness_characterization.py b/tests/test_global_todo_readiness_characterization.py index 931c841b5d..66688a7902 100644 --- a/tests/test_global_todo_readiness_characterization.py +++ b/tests/test_global_todo_readiness_characterization.py @@ -14,7 +14,7 @@ FIXTURE = Path(__file__).parent / "fixtures/global_todo_readiness.json" NOW = "2026-11-02T00:00:00+00:00" -BASE_REVISION = "d4aaaaefbd37a83a30f10681de839b45d631eeb9" +BASE_REVISION = "d210e4cc1d002f92498b2811c565b9430e79f4c1" def observe(case, monkeypatch, tmp_path): diff --git a/tests/test_kunluncode_goal_mode.py b/tests/test_kunluncode_goal_mode.py index bd9fe3f927..afac67688a 100644 --- a/tests/test_kunluncode_goal_mode.py +++ b/tests/test_kunluncode_goal_mode.py @@ -179,6 +179,12 @@ def capture(command: list[str], **_kwargs) -> subprocess.CompletedProcess[str]: ), "settlement_identity": identity.as_dict(), "settlement_result": {"failure": None}, + "settlement_progress": { + "schema_version": "quota_settlement_progress_v0", + "state": "settled", + "next_step": None, + "quota_spend_source": "heartbeat", + }, } ) else: @@ -188,6 +194,12 @@ def capture(command: list[str], **_kwargs) -> subprocess.CompletedProcess[str]: "appended": True, "settlement_identity": identity.as_dict(), "settlement_result": {"failure": None}, + "settlement_progress": { + "schema_version": "quota_settlement_progress_v0", + "state": "settled", + "next_step": None, + "quota_spend_source": "heartbeat", + }, } ) return subprocess.CompletedProcess(command, 0, payload, "") @@ -281,6 +293,12 @@ def capture(command: list[str], **_kwargs) -> subprocess.CompletedProcess[str]: "completion_continuation": "active_goal", "settlement_identity": identity.as_dict(), "settlement_result": {"failure": None}, + "settlement_progress": { + "schema_version": "quota_settlement_progress_v0", + "state": "settled", + "next_step": None, + "quota_spend_source": "heartbeat", + }, } ) else: @@ -290,6 +308,12 @@ def capture(command: list[str], **_kwargs) -> subprocess.CompletedProcess[str]: "appended": True, "settlement_identity": identity.as_dict(), "settlement_result": {"failure": None}, + "settlement_progress": { + "schema_version": "quota_settlement_progress_v0", + "state": "settled", + "next_step": None, + "quota_spend_source": "heartbeat", + }, } ) return subprocess.CompletedProcess(command, 0, payload, "") @@ -408,6 +432,12 @@ def capture(command: list[str], **_kwargs) -> subprocess.CompletedProcess[str]: "status": "done", "settlement_identity": identity.as_dict(), "settlement_result": {"failure": None}, + "settlement_progress": { + "schema_version": "quota_settlement_progress_v0", + "state": "settled", + "next_step": None, + "quota_spend_source": "heartbeat", + }, } ) else: @@ -417,6 +447,12 @@ def capture(command: list[str], **_kwargs) -> subprocess.CompletedProcess[str]: "appended": True, "settlement_identity": identity.as_dict(), "settlement_result": {"failure": None}, + "settlement_progress": { + "schema_version": "quota_settlement_progress_v0", + "state": "settled", + "next_step": None, + "quota_spend_source": "heartbeat", + }, } ) return subprocess.CompletedProcess(command, 0, payload, "") diff --git a/tests/test_lark_event_collector_git_budget.py b/tests/test_lark_event_collector_git_budget.py index 7628b71d6d..04462acc96 100644 --- a/tests/test_lark_event_collector_git_budget.py +++ b/tests/test_lark_event_collector_git_budget.py @@ -82,7 +82,7 @@ def test_the_next_question_is_not_asked_after_one_goes_unanswered( "exit 0\n", monkeypatch, ) - monkeypatch.setattr(event_collector, "GIT_PROBE_TIMEOUT_SECONDS", 0.5) + monkeypatch.setattr(event_collector, "GIT_PROBE_TIMEOUT_SECONDS", 1.5) started = time.monotonic() with pytest.raises(ValueError, match="needs a Git answer"): @@ -141,7 +141,7 @@ def test_a_timed_out_probe_takes_the_helpers_it_started( subprocess.run( ["git", "-C", str(project), "config", "core.fsmonitor", str(hook)], check=True ) - monkeypatch.setattr(event_collector, "GIT_PROBE_TIMEOUT_SECONDS", 0.8) + monkeypatch.setattr(event_collector, "GIT_PROBE_TIMEOUT_SECONDS", 1.5) started = time.monotonic() with pytest.raises(ValueError, match="needs a Git answer"): diff --git a/tests/test_lark_native_reply_context.py b/tests/test_lark_native_reply_context.py index df2cdf0872..95b1eac41d 100644 --- a/tests/test_lark_native_reply_context.py +++ b/tests/test_lark_native_reply_context.py @@ -165,7 +165,10 @@ def test_unquoted_provider_root_keeps_plain_input_and_no_parent_read(ordinary): assert native_request(transport, event)["message"] == event["content"] calls = provider.calls[before:] assert sum("+messages-mget" in args for args in calls) == 1 - assert not any("api" in args for args in calls) + api_calls = [args[args.index("api"):] for args in calls if "api" in args] + assert api_calls == [ + ["api", "GET", f"/open-apis/im/v1/messages/{event['message_id']}", "--as", "bot"] + ] finally: runtime.close() diff --git a/tests/test_lark_private_ingress.py b/tests/test_lark_private_ingress.py index 4041f3d23b..97b7ba7cca 100644 --- a/tests/test_lark_private_ingress.py +++ b/tests/test_lark_private_ingress.py @@ -437,7 +437,7 @@ def answer(*, route, **_kwargs): message_id = route["message_id"] if message_id == group_events[0]["message_id"]: in_group_answer.set() - assert release.wait(8) + assert release.wait(15) answered.append(message_id) return "Group answer" @@ -452,7 +452,7 @@ def admit(profile_name, event, **kwargs): def first_connection(): yield group_events[0] - assert in_group_answer.wait(8) + assert in_group_answer.wait(15) yield group_events[1] queued.set() @@ -523,7 +523,7 @@ def change_private_binding(method, body): try: service.refresh() - assert queued.wait(8), service.health_snapshot() + assert queued.wait(15), service.health_snapshot() if retargeted or retarget_on_retry: provider.profile_apps[profile] = "cli_retargeted_app" if unreadable: @@ -547,7 +547,7 @@ def read_profile(args, cwd=None, timeout=None): rows = json.loads(response["stdout"]) response["stdout"] = json.dumps([row for row in rows if row["name"] != profile]) inventory_captured.set() - assert return_inventory.wait(8) + assert return_inventory.wait(15) return response if binding_change == "stale_inventory_after_error" and not return_inventory.is_set(): return unreadable_inventory @@ -575,7 +575,7 @@ def read_profile(args, cwd=None, timeout=None): assert replacement["provider_ref"] == identity_ref(provider.profile_apps[profile]) if delayed_inventory: retry = service._refresh_retry - assert retry is not None and inventory_captured.wait(8) + assert retry is not None and inventory_captured.wait(15) if inventory_during_queue_recovery: resume_session_queues = service._resume_session_queues @@ -583,7 +583,7 @@ def resume_after_retry(snapshot): # The foreground has the current inventory but has yet # to update the listener. Finish the older read here. return_inventory.set() - retry.join(8) + retry.join(15) assert not retry.is_alive() assert not original_worker[0].is_set() resume_session_queues(snapshot) @@ -596,27 +596,27 @@ def resume_after_retry(snapshot): assert service._workers[profile] == original_worker if closing: release.set() - assert second_replied.wait(8), service.health_snapshot() + assert second_replied.wait(15), service.health_snapshot() service.close() return_inventory.set() - retry.join(8) + retry.join(15) assert not retry.is_alive() if removed_inventory: assert original_worker[0].is_set() - assert consumer_processes[0].exited.wait(8) + assert consumer_processes[0].exited.wait(15) release.set() - original_worker[1].join(8) + original_worker[1].join(15) assert not original_worker[1].is_alive() expected = group_events[:1] else: if stale_inventory: assert not original_worker[0].is_set() release.set() - assert second_replied.wait(8), service.health_snapshot() + assert second_replied.wait(15), service.health_snapshot() with service._lock: recheck = service._refresh_retry assert recheck is not None and recheck is not retry - recheck.join(8) + recheck.join(15) assert not recheck.is_alive() assert timer_reads == [retry, recheck] assert service._workers[profile] == original_worker @@ -629,16 +629,16 @@ def resume_after_retry(snapshot): expected = group_events[:2] elif unreadable and not retarget_on_retry: release.set() - assert second_replied.wait(8), service.health_snapshot() - assert inventory_retried.wait(8) + assert second_replied.wait(15), service.health_snapshot() + assert inventory_retried.wait(15) assert service._workers[profile] == original_worker assert len(consumer_processes) == 1 expected = group_events[:2] else: - assert consumer_processes[0].exited.wait(8) + assert consumer_processes[0].exited.wait(15) assert len(consumer_processes) == 1 release.set() - assert next_stream_ready.wait(8), service.health_snapshot() + assert next_stream_ready.wait(15), service.health_snapshot() expected = group_events[:1] if different_transport or retarget_on_retry else group_events[:2] if removing or unreadable: expected += group_events[2:] diff --git a/tests/test_manager_context_handoff.py b/tests/test_manager_context_handoff.py index 210ae8830e..2be00b9e78 100644 --- a/tests/test_manager_context_handoff.py +++ b/tests/test_manager_context_handoff.py @@ -20,6 +20,7 @@ ) from loopx.capabilities.manager_context.tracking import query from loopx.control_plane.capability_hooks import dispatch_turn_start_hooks +from loopx.control_plane.goals.activation import build_goal_activation @pytest.fixture @@ -198,8 +199,8 @@ def reject_enumeration(_registry): {}, {"goal_instance_id": "invalid"}, {"goal_instance_id": "ginst_" + "b" * 32, "id": "unsafe/alias"}, - {"goal_instance_id": "ginst_" + "b" * 32, "activation_state": "stopped"}, - {"goal_instance_id": "ginst_" + "b" * 32, "activation_state": "invalid"}, + {"goal_instance_id": "ginst_" + "b" * 32, "activation": build_goal_activation(state="stopped", updated_at="2026-01-01T00:00:00Z", reason="fixture stop")}, + {"goal_instance_id": "ginst_" + "b" * 32, "activation": {"schema_version": "loopx_goal_activation_v1", "state": "invalid"}}, ]) def test_source_session_catalog_keeps_only_current_instantiated_recipients( fixture, strict_envelope, other_goal @@ -240,7 +241,11 @@ def test_stopped_goal_is_not_a_context_recipient_and_revokes_replay(fixture): first = deliver(root, registry, session=session, turn=turn, request=request) data = json.loads(registry.read_text()) - data["goals"][0]["activation_state"] = "stopped" + data["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) registry.write_text(json.dumps(data)) assert authority(root, registry, session, turn)["targets"] == [ {"goal_id": "other", "agent_id": "peer"} @@ -251,7 +256,11 @@ def test_stopped_goal_is_not_a_context_recipient_and_revokes_replay(fixture): assert before == {path: path.read_bytes() for path in _root(root).rglob("*.json")} assert len(pending(root, "research", "worker")["items"]) == 1 - data["goals"][0]["activation_state"] = "active" + data["goals"][0]["activation"] = build_goal_activation( + state="active", + updated_at="2026-01-01T00:01:00Z", + reason="fixture resume", + ) registry.write_text(json.dumps(data)) assert deliver(root, registry, session=session, turn=turn, request=request) == { **first, "replayed": True @@ -489,7 +498,11 @@ def test_operator_target_grant_fails_closed_without_audited_source_or_agent(fixt source["evidence_goal_ids"] = ["research"] _write(policy_path, {"schema_version": POLICY_SCHEMA, "sources": {channel: source}}) data = json.loads(registry.read_text()) - data["goals"][0]["activation_state"] = "stopped" + data["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) registry.write_text(json.dumps(data)) with pytest.raises(ValueError, match="active Goal"): configure_delivery_target(root, registry, channel=channel, **request, grant=True, execute=True) @@ -558,7 +571,11 @@ def test_goal_delivery_grant_inherits_agents_and_rechecks_specific_revocation(fi assert deliver(root, registry, session=session, turn=turn, request=future)["request_id"] == receipt["request_id"] with pytest.raises(ValueError, match="not authorized"): deliver(root, registry, session=session, turn=turn, request={"goal_id": "other", "agent_id": "peer"}) - data["goals"][0]["activation_state"] = "stopped" + data["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) registry.write_text(json.dumps(data)) assert authority(root, registry, session, turn)["targets"] == [] diff --git a/tests/test_native_steward_turn_host.py b/tests/test_native_steward_turn_host.py index b1a94f9630..5e8e6ca99f 100644 --- a/tests/test_native_steward_turn_host.py +++ b/tests/test_native_steward_turn_host.py @@ -542,16 +542,16 @@ def test_managed_work_never_commits_without_current_independent_postcondition(st observation.write_text("not ready") if fault == "stopped_after_model": from loopx.capabilities.native_chat.codex_adapter import CodexAppServerAdapter - original_start = CodexAppServerAdapter.start_turn + original_start = CodexAppServerAdapter.start_native_task_turn - def stopped(adapter, message, sink): - response = original_start(adapter, message, sink) + def stopped(adapter, message, sink, policy): + response = original_start(adapter, message, sink, policy) registry = json.loads(runtime.registry_path.read_text()) registry["goals"][0]["activation"] = dict(STOPPED_ACTIVATION) runtime.registry_path.write_text(json.dumps(registry)) return response - monkeypatch.setattr(CodexAppServerAdapter, "start_turn", stopped) + monkeypatch.setattr(CodexAppServerAdapter, "start_native_task_turn", stopped) calls = capture.read_bytes() accepted, _ = service.submit(session["session_id"], agent_id=actor["agent_id"], operation_id="unqualified", todo_id=todo_id) completed = finish(runtime, accepted) diff --git a/tests/test_task_lease_worktree.py b/tests/test_task_lease_worktree.py index e41a032fbe..4a9dfec8d9 100644 --- a/tests/test_task_lease_worktree.py +++ b/tests/test_task_lease_worktree.py @@ -125,7 +125,10 @@ def acquire(key, path, expected=0, scope="src/**"): @pytest.mark.parametrize("large_peer_scope", [False, True], ids=["small-scope", "large-scope"]) def test_ordinary_claim_uses_its_independent_worktree(tmp_path, monkeypatch, capsys, provider, large_peer_scope): """Normal claims admit sibling edits without weakening physical collisions.""" + import os + isolate_sqlite_runtime(tmp_path, monkeypatch) + monkeypatch.setenv("PATH", f"{Path(sys.executable).parent}{os.pathsep}{os.environ.get('PATH', '')}") project = tmp_path / "repo" project.mkdir() diff --git a/tests/test_turn_machine_credential.py b/tests/test_turn_machine_credential.py index 31a0dc4887..80a4b16785 100644 --- a/tests/test_turn_machine_credential.py +++ b/tests/test_turn_machine_credential.py @@ -64,13 +64,6 @@ def sdk_runner(**kwargs): monkeypatch.setattr(turn_host_adapter, "run_dsh_turn", sdk_runner) for name in ("first", "second"): project, runtime, registry = _write_live_fixture(tmp_path / name) - expected.append({ - "DEEPSEEK_API_KEY": KEY, - "LOOPX_TURN_GOAL_ID": "loopx-turn-fixture", - "LOOPX_TURN_AGENT_ID": "codex-fixture", - "LOOPX_TURN_TODO_ID": "todo_fixture0001", - "LOOPX_TURN_WORKSPACE": str(project.resolve()), - }) # A conflicting Goal-local store cannot redirect machine authentication. provider.write_operator_provider(runtime_root=runtime, api_key=GOAL_KEY) code, plan = turn(project, runtime, registry) @@ -83,6 +76,14 @@ def sdk_runner(**kwargs): assert code == 0, result assert result["result_kind"] == "iteration_failed" assert result["effects"]["quota_spent"] is False + expected.append({ + "DEEPSEEK_API_KEY": KEY, + "LOOPX_TURN_KEY": result["receipt"]["turn_key"], + "LOOPX_TURN_GOAL_ID": "loopx-turn-fixture", + "LOOPX_TURN_AGENT_ID": "codex-fixture", + "LOOPX_TURN_TODO_ID": "todo_fixture0001", + "LOOPX_TURN_WORKSPACE": str(project.resolve()), + }) assert received == expected diff --git a/tests/test_zcode_goal_bridge.py b/tests/test_zcode_goal_bridge.py index 631915e2ed..fe32b0a7d3 100644 --- a/tests/test_zcode_goal_bridge.py +++ b/tests/test_zcode_goal_bridge.py @@ -8,6 +8,7 @@ import pytest +from loopx.control_plane.goals.activation import build_goal_activation from loopx.zcode_goal_mode import bridge from loopx.zcode_goal_mode.api import ZCodeGoalRequestMixin, public_zcode_goal_readback @@ -55,7 +56,11 @@ def test_invalid_authority_cannot_launch_provider(authority, monkeypatch, mutati elif mutation == "invalid_instance": goal["goal_instance_id"] = 123 elif mutation == "stopped": - goal["activation_state"] = "stopped" + goal["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) elif mutation == "archived": goal["status"] = "archived" else: @@ -490,7 +495,11 @@ def test_real_provider_status_is_read_only_with_exact_identity(authority): @pytest.mark.parametrize("action", ["status", "pause", "stop"]) def test_same_exact_inactive_binding_can_be_read_or_cleaned(authority, monkeypatch, action): registry, _, payload = authority - payload["goals"][0]["activation_state"] = "stopped" + payload["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) registry.write_text(json.dumps(payload), encoding="utf-8") requests = _stub_operation(monkeypatch) result = bridge.zcode_goal_operation(action=action, registry_path=registry, goal_id="delivery", agent_id="zcode-worker") @@ -503,7 +512,11 @@ def test_same_exact_inactive_binding_can_be_read_or_cleaned(authority, monkeypat @pytest.mark.parametrize("action", ["bind", "start", "resume"]) def test_inactive_binding_cannot_admit_execution(authority, monkeypatch, action): registry, _, payload = authority - payload["goals"][0]["activation_state"] = "stopped" + payload["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) registry.write_text(json.dumps(payload), encoding="utf-8") monkeypatch.setattr(bridge, "_node_command", lambda: pytest.fail("inactive Goal reached provider")) with pytest.raises(bridge.ZCodeGoalBridgeError, match="no longer active"): @@ -512,7 +525,11 @@ def test_inactive_binding_cannot_admit_execution(authority, monkeypatch, action) def test_inactive_cleanup_still_rejects_changed_instance_or_unregistered_agent(authority, monkeypatch): registry, _, payload = authority - payload["goals"][0]["activation_state"] = "stopped" + payload["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) registry.write_text(json.dumps(payload), encoding="utf-8") def replace(request): payload["goals"][0]["goal_instance_id"] = INSTANCE_B @@ -598,7 +615,11 @@ def test_model_selection_forwards_existing_model_only(authority, monkeypatch): def test_internal_guard_requires_known_action_and_validates_inactive_cleanup(authority): registry, project, payload = authority - payload["goals"][0]["activation_state"] = "stopped" + payload["goals"][0]["activation"] = build_goal_activation( + state="stopped", + updated_at="2026-01-01T00:00:00Z", + reason="fixture stop", + ) registry.write_text(json.dumps(payload), encoding="utf-8") request = {"registry": str(registry), "project": str(project), "goal_id": "delivery", "agent_id": "zcode-worker", "goal_ref": {"goal_id": "delivery", "goal_instance_id": INSTANCE_A}} command = [sys.executable, "-X", "utf8", "-B", "-m", "loopx.zcode_goal_mode.bridge", "--validate-binding"]