From 76d572ee0d13ac5dbed76c146222a341269c3605 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:40:52 +0800 Subject: [PATCH] Scope global registry discovery to Git alias candidates Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/project_alias.py | 16 ++++++-- tests/test_host_loop_activation.py | 59 ++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/loopx/project_alias.py b/loopx/project_alias.py index 996bbc5ef8..e7a5807d30 100644 --- a/loopx/project_alias.py +++ b/loopx/project_alias.py @@ -108,16 +108,26 @@ def resolve_canonical_project_alias( resolved_project = _resolve_path(project) target_common_dir = _git_common_dir(resolved_project) + if target_common_dir is None: + return { + "applied": False, + "kind": "none", + "input_project": str(resolved_project), + "global_registry": str(_resolve_path(global_registry)) if global_registry is not None else None, + "git_common_dir": None, + "reason": "git common-dir unavailable", + } + global_path = _resolve_path(global_registry or _default_global_registry_path()) payload = _read_global_registry(global_path) - if not payload or target_common_dir is None: + if not payload: return { "applied": False, "kind": "none", "input_project": str(resolved_project), "global_registry": str(global_path), - "git_common_dir": str(target_common_dir) if target_common_dir else None, - "reason": "global registry or git common-dir unavailable", + "git_common_dir": str(target_common_dir), + "reason": "global registry unavailable", } primary_repo = _primary_repo_from_common_dir(target_common_dir) diff --git a/tests/test_host_loop_activation.py b/tests/test_host_loop_activation.py index 4217609c42..d9454cae76 100644 --- a/tests/test_host_loop_activation.py +++ b/tests/test_host_loop_activation.py @@ -641,6 +641,65 @@ def test_non_traex_identity_selection_preserves_v0_prompt_fields( assert choice["activation_input_command"] == choice["heartbeat_prompt_json"] +def test_standalone_project_previews_use_their_declared_runtime_when_defaults_conflict( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], +) -> None: + from loopx import paths + from loopx.cli import main + + monkeypatch.delenv("LOOPX_REGISTRY", raising=False) + monkeypatch.delenv("LOOPX_RUNTIME_ROOT", raising=False) + for root in (paths.DEFAULT_RUNTIME_ROOT, paths.LEGACY_RUNTIME_ROOT): + root.mkdir(parents=True, exist_ok=True) + paths.global_registry_path(root).write_text('{"goals": []}', encoding="utf-8") + assert paths.default_runtime_route()["status"] == "conflict" + + goal_id = "standalone-route" + project, _ = _write_onboarding_goal( + tmp_path, goal_id=goal_id, registered_agents=["local-agent", "other-agent"], + ) + registry = project / ".loopx" / "registry.json" + configured = json.loads(registry.read_text(encoding="utf-8")) + configured["common_runtime_root"] = str(tmp_path / "project-runtime") + registry.write_text(json.dumps(configured), encoding="utf-8") + original = registry.read_bytes() + + for command, options in ( + ("agent-onboard", ["--agent-type", "codex-app"]), + ("agent-onboard", ["--agent-type", "antigravity-app", "--agent-id", "local-agent"]), + ("bootstrap-command-pack", ["--host-surface", "antigravity-app", "--agent-id", "local-agent"]), + ): + assert main(["--format", "json", command, "--project", str(project), "--goal-id", goal_id, *options]) == 0 + packet = json.loads(capsys.readouterr().out) + assert packet["ok"] is True + connection = packet["project_connection"] + assert Path(connection["registry"]) == registry.resolve() + assert connection["connection_state"] == "connected" + assert connection["canonical_project_alias"]["applied"] is False + assert connection["canonical_project_alias"]["global_registry"] is None + guard = packet["commands"]["quota_guard"] + if "codex-app" in options: + assert guard is None + assert {choice["agent_id"] for choice in packet["identity_selection_gate"]["choices"]} == { + "local-agent", "other-agent", + } + else: + argv = shlex.split(guard) + assert Path(argv[argv.index("--registry") + 1]) == registry.resolve() + assert registry.read_bytes() == original + + unconnected = tmp_path / "unconnected" + unconnected.mkdir() + with pytest.raises(ValueError, match="Both default LoopX registries exist"): + main(["--format", "json", "agent-onboard", "--project", str(unconnected), + "--goal-id", goal_id, "--agent-type", "antigravity-app"]) + + subprocess.run(["git", "init", str(project)], check=True, capture_output=True) + with pytest.raises(ValueError, match="Both default LoopX registries exist"): + main(["--format", "json", "agent-onboard", "--project", str(project), + "--goal-id", goal_id, "--agent-type", "antigravity-app"]) + + def test_new_agent_onboarding_gates_an_empty_agent_registry() -> None: packet = build_host_loop_activation_packet( agent_type="codex-app",