tenseleyflow/loader / 69d958e

Browse files

Move scripted runtime harness onto runtime handle

Authored by espadonne
SHA
69d958ea48a2a9b27cfb52d2516d9f33ff913f45
Parents
8805b88
Tree
edf53f6

2 changed files

StatusFile+-
M tests/helpers/runtime_harness.py 10 8
M tests/test_runtime_handle.py 28 1
tests/helpers/runtime_harness.pymodified
@@ -6,8 +6,10 @@ from dataclasses import dataclass
66
 from pathlib import Path
77
 from typing import Any
88
 
9
-from loader.agent.loop import Agent, AgentConfig, AgentEvent
9
+from loader.agent.loop import AgentConfig
1010
 from loader.llm.base import CompletionResponse, LLMBackend, Message, StreamChunk
11
+from loader.runtime.events import AgentEvent
12
+from loader.runtime.runtime_handle import RuntimeHandle
1113
 from loader.tools.base import ToolRegistry, create_default_registry
1214
 
1315
 
@@ -24,12 +26,12 @@ class BackendInvocation:
2426
 
2527
 @dataclass
2628
 class ScenarioRun:
27
-    """Captured result of a scripted agent scenario."""
29
+    """Captured result of a scripted runtime-owner scenario."""
2830
 
2931
     response: str
3032
     events: list[AgentEvent]
3133
     invocations: list[BackendInvocation]
32
-    agent: Agent
34
+    agent: RuntimeHandle
3335
 
3436
 
3537
 class ScriptedBackend(LLMBackend):
@@ -107,11 +109,11 @@ async def run_scenario(
107109
     on_confirmation=None,
108110
     on_user_question=None,
109111
 ) -> ScenarioRun:
110
-    """Run a scripted agent scenario and collect emitted events."""
112
+    """Run a scripted runtime scenario and collect emitted events."""
111113
 
112
-    agent = Agent(
114
+    agent = RuntimeHandle(
113115
         backend=backend,
114
-        registry=registry or create_default_registry(),
116
+        registry=registry or create_default_registry(project_root),
115117
         config=config or AgentConfig(auto_context=False),
116118
         project_root=project_root,
117119
     )
@@ -141,9 +143,9 @@ async def run_explore_scenario(
141143
     config: AgentConfig | None = None,
142144
     project_root: Path | str | None = None,
143145
 ) -> ScenarioRun:
144
-    """Run a scripted explore query and collect emitted events."""
146
+    """Run a scripted explore query through the runtime-first harness."""
145147
 
146
-    agent = Agent(
148
+    agent = RuntimeHandle(
147149
         backend=backend,
148150
         config=config or AgentConfig(auto_context=False),
149151
         project_root=project_root,
tests/test_runtime_handle.pymodified
@@ -12,7 +12,7 @@ from loader.runtime.bootstrap import RuntimeBootstrapView, build_runtime_context
1212
 from loader.runtime.conversation import ConversationRuntime
1313
 from loader.runtime.launcher import RuntimeLauncher, build_runtime_launcher
1414
 from loader.runtime.runtime_handle import RuntimeHandle
15
-from tests.helpers.runtime_harness import ScriptedBackend
15
+from tests.helpers.runtime_harness import ScriptedBackend, run_explore_scenario, run_scenario
1616
 
1717
 
1818
 def test_runtime_handle_builds_runtime_bootstrap_contract(
@@ -129,3 +129,30 @@ async def test_runtime_handle_runs_explore_and_streaming_entrypoints_without_age
129129
     assert explore_response == "Explore with runtime handle."
130130
     assert handle.last_turn_summary is not None
131131
     assert handle.last_turn_summary.workflow_mode == "explore"
132
+
133
+
134
+@pytest.mark.asyncio
135
+async def test_runtime_harness_uses_runtime_handle_for_scripted_runs(
136
+    temp_dir: Path,
137
+) -> None:
138
+    run = await run_scenario(
139
+        "Summarize the runtime-first harness.",
140
+        ScriptedBackend(
141
+            completions=[CompletionResponse(content="Runtime harness reply.")]
142
+        ),
143
+        config=AgentConfig(auto_context=False, stream=False),
144
+        project_root=temp_dir,
145
+    )
146
+    explore_run = await run_explore_scenario(
147
+        "Where should I start?",
148
+        ScriptedBackend(
149
+            completions=[CompletionResponse(content="Explore harness reply.")]
150
+        ),
151
+        config=AgentConfig(auto_context=False, stream=False),
152
+        project_root=temp_dir,
153
+    )
154
+
155
+    assert isinstance(run.agent, RuntimeHandle)
156
+    assert run.response == "Runtime harness reply."
157
+    assert isinstance(explore_run.agent, RuntimeHandle)
158
+    assert explore_run.response == "Explore harness reply."