Skip to content
Open
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
4 changes: 2 additions & 2 deletions loopx/presentation/goal_storage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ def _storage_cold_snapshot(
) -> tuple[Path, dict[str, object], dict[str, object]]:
from ..control_plane.coordination.authority_source_capture import build_runtime_shadow_source_snapshot
from ..control_plane.goals.state_resolution import resolve_goal_state
from ..control_plane.projects.registry_codec import load_project_registry
from ..control_plane.projects.registry_codec import load_registry
from ..registry import find_registry_goal

if source_registry != Path(self.server.registry_path).resolve():
registry = load_project_registry(source_registry)
registry = load_registry(source_registry)
selected_goal = find_registry_goal(registry, goal_id)
if selected_goal is None:
raise ValueError("registered Goal source changed")
Expand Down
44 changes: 44 additions & 0 deletions tests/architecture/test_source_session_registry_denial.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,47 @@ def test_generic_registry_decoder_enforces_source_session_denial() -> None:
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name)
}
assert "require_runtime_compatible_project_registry" in calls


def test_cold_snapshot_rejects_routed_source_session_registry(tmp_path: Path) -> None:
import json
from types import SimpleNamespace

from loopx.control_plane.projects.registry_codec import (
ProjectRegistryProtocolError,
SOURCE_SESSION_PROFILE_ID,
)
from loopx.presentation.goal_storage_api import GoalStorageRequestMixin

invoked_registry = tmp_path / "global" / "registry.global.json"
invoked_registry.parent.mkdir(mode=0o700, parents=True)
source_registry = tmp_path / "source" / "registry.json"
source_registry.parent.mkdir(mode=0o700, parents=True)
source_registry.write_text(
json.dumps(
{
"profile_id": SOURCE_SESSION_PROFILE_ID,
"goals": [
{
"id": "cold",
"repo": str(tmp_path / "project"),
"state_file": str(tmp_path / "project" / "STATE.md"),
}
],
}
),
encoding="utf-8",
)
handler = GoalStorageRequestMixin()
handler.server = SimpleNamespace(
registry_path=invoked_registry,
runtime_root=tmp_path / "runtime",
)
with pytest.raises(ProjectRegistryProtocolError, match=SOURCE_SESSION_PROFILE_ID):
handler._storage_cold_snapshot(
"cold",
{},
{"id": "cold"},
tmp_path / "runtime",
source_registry,
)
17 changes: 11 additions & 6 deletions tests/control_plane/test_pr_wait_consumer_adoption.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from loopx.todos import add_goal_todo, list_goal_todos
from tests.capabilities.test_pr_wait_observation import _invoke_turn, _observation
from tests.control_plane.canonical_authority_fixture import isolate_sqlite_runtime
from tests.control_plane.host_process_fixture import assert_host_task_context
from tests.test_loopx_turn_driver import _write_live_fixture


Expand Down Expand Up @@ -80,13 +81,14 @@ def fetch(reference, **kwargs):
assert observation["checks"]["pr_dependencies"]["external_read_count"] == (2 if number == 0 else 0)

captured = []
project_envelope = turn.build_turn_envelope
compose_decision = turn.compose_turn_decision

def capture(decision, **kwargs):
captured.append(copy.deepcopy(decision))
return project_envelope(decision, **kwargs)
result = compose_decision(decision, **kwargs)
captured.append(copy.deepcopy(result))
return result

monkeypatch.setattr(turn, "build_turn_envelope", capture)
monkeypatch.setattr(turn, "compose_turn_decision", capture)
runner = tmp_path / "consumer.py"
runner.write_text(
"import json\nfrom pathlib import Path\n"
Expand All @@ -95,7 +97,9 @@ def capture(decision, **kwargs):
" prompt = kwargs['prompt']\n"
" (root / 'consumer-input.txt').write_text(prompt)\n"
" request = json.JSONDecoder().raw_decode(prompt.split('Turn request:\\n', 1)[1])[0]\n"
" authority = request['work_contract']\n"
" assert request['schema_version'] == 'loopx_turn_model_context_v0'\n"
" assert 'work_contract' not in request\n"
" authority = request['task_context']\n"
" selected = authority['selected_todo']\n"
f" assert selected['todo_id'] == {todo_id!r}\n"
" assert selected['resume_when'] == 'pr_merged:owner/repo#42'\n"
Expand Down Expand Up @@ -139,7 +143,8 @@ def capture(decision, **kwargs):
assert expected["resume_condition"]["matched_event_at"] == "2026-10-01T00:00:00Z"
assert envelope["action_signature"]["matches"] is True
prompt = (project / "consumer-input.txt").read_text()
consumed = json.JSONDecoder().raw_decode(prompt.split("Turn request:\n", 1)[1])[0]["work_contract"]
model_input = json.JSONDecoder().raw_decode(prompt.split("Turn request:\n", 1)[1])[0]
consumed = assert_host_task_context(model_input, full)
assert consumed["selected_todo"]["resume_condition"] == expected["resume_condition"]
assert "Require the terminal independent artifact marker." in prompt

Expand Down
Loading