Move scripted runtime harness onto runtime handle
- SHA
69d958ea48a2a9b27cfb52d2516d9f33ff913f45- Parents
-
8805b88 - Tree
edf53f6
69d958e
69d958ea48a2a9b27cfb52d2516d9f33ff913f458805b88
edf53f6| Status | File | + | - |
|---|---|---|---|
| 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 | ||
| 6 | 6 | from pathlib import Path |
| 7 | 7 | from typing import Any |
| 8 | 8 | |
| 9 | -from loader.agent.loop import Agent, AgentConfig, AgentEvent | |
| 9 | +from loader.agent.loop import AgentConfig | |
| 10 | 10 | from loader.llm.base import CompletionResponse, LLMBackend, Message, StreamChunk |
| 11 | +from loader.runtime.events import AgentEvent | |
| 12 | +from loader.runtime.runtime_handle import RuntimeHandle | |
| 11 | 13 | from loader.tools.base import ToolRegistry, create_default_registry |
| 12 | 14 | |
| 13 | 15 | |
@@ -24,12 +26,12 @@ class BackendInvocation: | ||
| 24 | 26 | |
| 25 | 27 | @dataclass |
| 26 | 28 | class ScenarioRun: |
| 27 | - """Captured result of a scripted agent scenario.""" | |
| 29 | + """Captured result of a scripted runtime-owner scenario.""" | |
| 28 | 30 | |
| 29 | 31 | response: str |
| 30 | 32 | events: list[AgentEvent] |
| 31 | 33 | invocations: list[BackendInvocation] |
| 32 | - agent: Agent | |
| 34 | + agent: RuntimeHandle | |
| 33 | 35 | |
| 34 | 36 | |
| 35 | 37 | class ScriptedBackend(LLMBackend): |
@@ -107,11 +109,11 @@ async def run_scenario( | ||
| 107 | 109 | on_confirmation=None, |
| 108 | 110 | on_user_question=None, |
| 109 | 111 | ) -> ScenarioRun: |
| 110 | - """Run a scripted agent scenario and collect emitted events.""" | |
| 112 | + """Run a scripted runtime scenario and collect emitted events.""" | |
| 111 | 113 | |
| 112 | - agent = Agent( | |
| 114 | + agent = RuntimeHandle( | |
| 113 | 115 | backend=backend, |
| 114 | - registry=registry or create_default_registry(), | |
| 116 | + registry=registry or create_default_registry(project_root), | |
| 115 | 117 | config=config or AgentConfig(auto_context=False), |
| 116 | 118 | project_root=project_root, |
| 117 | 119 | ) |
@@ -141,9 +143,9 @@ async def run_explore_scenario( | ||
| 141 | 143 | config: AgentConfig | None = None, |
| 142 | 144 | project_root: Path | str | None = None, |
| 143 | 145 | ) -> ScenarioRun: |
| 144 | - """Run a scripted explore query and collect emitted events.""" | |
| 146 | + """Run a scripted explore query through the runtime-first harness.""" | |
| 145 | 147 | |
| 146 | - agent = Agent( | |
| 148 | + agent = RuntimeHandle( | |
| 147 | 149 | backend=backend, |
| 148 | 150 | config=config or AgentConfig(auto_context=False), |
| 149 | 151 | project_root=project_root, |
tests/test_runtime_handle.pymodified@@ -12,7 +12,7 @@ from loader.runtime.bootstrap import RuntimeBootstrapView, build_runtime_context | ||
| 12 | 12 | from loader.runtime.conversation import ConversationRuntime |
| 13 | 13 | from loader.runtime.launcher import RuntimeLauncher, build_runtime_launcher |
| 14 | 14 | 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 | |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | def test_runtime_handle_builds_runtime_bootstrap_contract( |
@@ -129,3 +129,30 @@ async def test_runtime_handle_runs_explore_and_streaming_entrypoints_without_age | ||
| 129 | 129 | assert explore_response == "Explore with runtime handle." |
| 130 | 130 | assert handle.last_turn_summary is not None |
| 131 | 131 | 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." | |