tenseleyflow/loader / d67b8f9

Browse files

Cover runtime bootstrap source contract

Authored by espadonne
SHA
d67b8f99f005b49de6752069d8a61f84284f2dc0
Parents
3c26874
Tree
ebfca5e

6 changed files

StatusFile+-
M tests/test_response_route_handlers.py 1 1
M tests/test_response_routing.py 1 1
M tests/test_runtime_bootstrap.py 21 7
M tests/test_runtime_context.py 5 3
M tests/test_runtime_launcher.py 4 1
M tests/test_turn_iteration.py 1 1
tests/test_response_route_handlers.pymodified
@@ -51,7 +51,7 @@ async def _prepare_context(
5151
         task=prepared.task,
5252
         effective_task=prepared.effective_task,
5353
         iterations=1,
54
-        max_iterations=runtime.agent.config.max_iterations,
54
+        max_iterations=runtime.context.config.max_iterations,
5555
         actions_taken=[],
5656
         continuation_count=continuation_count,
5757
         consecutive_errors=consecutive_errors,
tests/test_response_routing.pymodified
@@ -53,7 +53,7 @@ async def _prepare_context(
5353
         task=prepared.task,
5454
         effective_task=prepared.effective_task,
5555
         iterations=1,
56
-        max_iterations=runtime.agent.config.max_iterations,
56
+        max_iterations=runtime.context.config.max_iterations,
5757
         actions_taken=[],
5858
         continuation_count=continuation_count,
5959
         consecutive_errors=consecutive_errors,
tests/test_runtime_bootstrap.pymodified
@@ -5,7 +5,12 @@ from __future__ import annotations
55
 from pathlib import Path
66
 
77
 from loader.agent.loop import Agent, AgentConfig
8
-from loader.runtime.bootstrap import build_runtime_context, sync_runtime_context
8
+from loader.runtime.bootstrap import (
9
+    RuntimeBootstrapView,
10
+    build_runtime_bootstrap_source,
11
+    build_runtime_context,
12
+    sync_runtime_context,
13
+)
914
 from loader.runtime.conversation import ConversationRuntime
1015
 from loader.runtime.explore import ExploreRuntime
1116
 from loader.runtime.launcher import RuntimeLauncher, build_runtime_launcher
@@ -21,8 +26,9 @@ def test_build_runtime_context_uses_shared_bootstrap_contract(
2126
         config=AgentConfig(auto_context=False),
2227
         project_root=temp_dir,
2328
     )
29
+    source = build_runtime_bootstrap_source(agent)
2430
 
25
-    context = build_runtime_context(agent)
31
+    context = build_runtime_context(source)
2632
 
2733
     assert context.project_root == temp_dir.resolve()
2834
     assert context.backend is agent.backend
@@ -35,6 +41,7 @@ def test_build_runtime_context_uses_shared_bootstrap_contract(
3541
     assert context.workflow_mode == agent.workflow_mode
3642
     assert context.prompt_format == agent.prompt_format
3743
     assert context.prompt_sections == agent.prompt_sections
44
+    assert source.metadata == {"owner_type": "Agent"}
3845
 
3946
 
4047
 def test_sync_runtime_context_refreshes_prompt_and_capability_state(
@@ -46,7 +53,8 @@ def test_sync_runtime_context_refreshes_prompt_and_capability_state(
4653
         config=AgentConfig(auto_context=False),
4754
         project_root=temp_dir,
4855
     )
49
-    context = build_runtime_context(agent)
56
+    source = build_runtime_bootstrap_source(agent)
57
+    context = build_runtime_context(source)
5058
 
5159
     agent.prompt_format = "native"
5260
     agent.prompt_sections = ["Workflow Context", "Runtime Config"]
@@ -54,7 +62,7 @@ def test_sync_runtime_context_refreshes_prompt_and_capability_state(
5462
     backend._supports_native_tools = False  # type: ignore[attr-defined]
5563
     agent.refresh_capability_profile()
5664
 
57
-    sync_runtime_context(context, agent)
65
+    sync_runtime_context(context, source)
5866
 
5967
     assert context.workflow_mode == "clarify"
6068
     assert context.prompt_format == "native"
@@ -83,10 +91,12 @@ def test_conversation_runtime_uses_shared_bootstrap_factory(
8391
         fake_build_runtime_context,
8492
     )
8593
 
86
-    runtime = ConversationRuntime(agent)
94
+    source = build_runtime_bootstrap_source(agent)
95
+    runtime = ConversationRuntime(source)
8796
 
8897
     assert calls == ["conversation"]
8998
     assert runtime.context.project_root == temp_dir.resolve()
99
+    assert runtime.source is source
90100
 
91101
 
92102
 def test_explore_runtime_uses_shared_bootstrap_factory(
@@ -110,10 +120,12 @@ def test_explore_runtime_uses_shared_bootstrap_factory(
110120
         fake_build_runtime_context,
111121
     )
112122
 
113
-    runtime = ExploreRuntime(agent)
123
+    source = build_runtime_bootstrap_source(agent)
124
+    runtime = ExploreRuntime(source)
114125
 
115126
     assert calls == ["explore"]
116127
     assert runtime.context.project_root == temp_dir.resolve()
128
+    assert runtime.source is source
117129
 
118130
 
119131
 def test_build_runtime_launcher_wraps_shared_bootstrap_source(
@@ -128,4 +140,6 @@ def test_build_runtime_launcher_wraps_shared_bootstrap_source(
128140
     launcher = build_runtime_launcher(agent)
129141
 
130142
     assert isinstance(launcher, RuntimeLauncher)
131
-    assert launcher.source is agent
143
+    assert isinstance(launcher.source, RuntimeBootstrapView)
144
+    assert launcher.source is not agent
145
+    assert launcher.source.metadata == {"owner_type": "Agent"}
tests/test_runtime_context.pymodified
@@ -5,7 +5,7 @@ from __future__ import annotations
55
 from pathlib import Path
66
 
77
 from loader.agent.loop import Agent, AgentConfig
8
-from loader.runtime.bootstrap import build_runtime_context
8
+from loader.runtime.bootstrap import build_runtime_bootstrap_source, build_runtime_context
99
 from loader.runtime.context import RuntimeContext
1010
 from loader.runtime.recovery import RecoveryContext
1111
 from tests.helpers.runtime_harness import ScriptedBackend
@@ -18,8 +18,9 @@ def test_agent_builds_typed_runtime_context(temp_dir: Path) -> None:
1818
         config=AgentConfig(auto_context=False),
1919
         project_root=temp_dir,
2020
     )
21
+    source = build_runtime_bootstrap_source(agent)
2122
 
22
-    context = build_runtime_context(agent)
23
+    context = build_runtime_context(source)
2324
 
2425
     assert isinstance(context, RuntimeContext)
2526
     assert context.project_root == temp_dir.resolve()
@@ -47,8 +48,9 @@ def test_runtime_context_control_callbacks_stay_in_sync(temp_dir: Path) -> None:
4748
         config=AgentConfig(auto_context=False),
4849
         project_root=temp_dir,
4950
     )
51
+    source = build_runtime_bootstrap_source(agent)
5052
 
51
-    context = build_runtime_context(agent)
53
+    context = build_runtime_context(source)
5254
     context.queue_steering_message("Re-check the current task.")
5355
 
5456
     assert context.drain_steering_messages() == ["Re-check the current task."]
tests/test_runtime_launcher.pymodified
@@ -8,6 +8,7 @@ import pytest
88
 
99
 from loader.agent.loop import Agent, AgentConfig, ReasoningConfig
1010
 from loader.llm.base import CompletionResponse, StreamChunk
11
+from loader.runtime.bootstrap import RuntimeBootstrapView
1112
 from loader.runtime.launcher import RuntimeLauncher, build_runtime_launcher
1213
 from tests.helpers.runtime_harness import ScriptedBackend
1314
 
@@ -24,7 +25,9 @@ def test_build_runtime_launcher_returns_launcher_for_agent_source(
2425
     launcher = build_runtime_launcher(agent)
2526
 
2627
     assert isinstance(launcher, RuntimeLauncher)
27
-    assert launcher.source is agent
28
+    assert isinstance(launcher.source, RuntimeBootstrapView)
29
+    assert launcher.source is not agent
30
+    assert launcher.source.metadata == {"owner_type": "Agent"}
2831
 
2932
 
3033
 @pytest.mark.asyncio
tests/test_turn_iteration.pymodified
@@ -44,7 +44,7 @@ async def _run_iteration(
4444
         original_task=original_task,
4545
         effective_max_tokens=prepared.effective_max_tokens,
4646
         iterations=1,
47
-        max_iterations=runtime.agent.config.max_iterations,
47
+        max_iterations=runtime.context.config.max_iterations,
4848
         actions_taken=[],
4949
         continuation_count=0,
5050
         empty_retry_count=0,