Isolate plan and task runtime per session
This commit is contained in:
@@ -199,10 +199,15 @@ class AgentContextTests(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir) / 'repo'
|
||||
workspace.mkdir(parents=True)
|
||||
runtime = TaskRuntime.from_workspace(workspace)
|
||||
scratchpad = workspace / '.port_sessions' / 'accounts' / 'alice' / 'sessions' / 's1' / 'scratchpad'
|
||||
scratchpad.mkdir(parents=True)
|
||||
runtime = TaskRuntime.from_storage_path(scratchpad / 'task_runtime.json')
|
||||
runtime.create_task(title='Review task runtime')
|
||||
|
||||
snapshot = build_context_snapshot(AgentRuntimeConfig(cwd=workspace))
|
||||
snapshot = build_context_snapshot(
|
||||
AgentRuntimeConfig(cwd=workspace),
|
||||
scratchpad_directory=scratchpad,
|
||||
)
|
||||
|
||||
self.assertIn('taskRuntime', snapshot.user_context)
|
||||
self.assertIn('Total tasks: 1', snapshot.user_context['taskRuntime'])
|
||||
@@ -211,17 +216,42 @@ class AgentContextTests(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir) / 'repo'
|
||||
workspace.mkdir(parents=True)
|
||||
plan_runtime = PlanRuntime.from_workspace(workspace)
|
||||
scratchpad = workspace / '.port_sessions' / 'accounts' / 'alice' / 'sessions' / 's1' / 'scratchpad'
|
||||
scratchpad.mkdir(parents=True)
|
||||
plan_runtime = PlanRuntime.from_storage_path(scratchpad / 'plan_runtime.json')
|
||||
plan_runtime.update_plan(
|
||||
[{'step': 'Inspect the runtime', 'status': 'in_progress'}],
|
||||
explanation='Use a stored plan.',
|
||||
)
|
||||
|
||||
snapshot = build_context_snapshot(AgentRuntimeConfig(cwd=workspace))
|
||||
snapshot = build_context_snapshot(
|
||||
AgentRuntimeConfig(cwd=workspace),
|
||||
scratchpad_directory=scratchpad,
|
||||
)
|
||||
|
||||
self.assertIn('planRuntime', snapshot.user_context)
|
||||
self.assertIn('Total plan steps: 1', snapshot.user_context['planRuntime'])
|
||||
|
||||
def test_user_context_ignores_workspace_plan_task_when_session_scratchpad_is_set(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir) / 'repo'
|
||||
workspace.mkdir(parents=True)
|
||||
TaskRuntime.from_workspace(workspace).create_task(title='Global task')
|
||||
PlanRuntime.from_workspace(workspace).update_plan(
|
||||
[{'step': 'Global plan', 'status': 'in_progress'}],
|
||||
explanation='This must not leak into a session.',
|
||||
)
|
||||
scratchpad = workspace / '.port_sessions' / 'accounts' / 'alice' / 'sessions' / 's1' / 'scratchpad'
|
||||
scratchpad.mkdir(parents=True)
|
||||
|
||||
snapshot = build_context_snapshot(
|
||||
AgentRuntimeConfig(cwd=workspace),
|
||||
scratchpad_directory=scratchpad,
|
||||
)
|
||||
|
||||
self.assertNotIn('taskRuntime', snapshot.user_context)
|
||||
self.assertNotIn('planRuntime', snapshot.user_context)
|
||||
|
||||
def test_user_context_loads_team_runtime_summary(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir) / 'repo'
|
||||
|
||||
@@ -269,11 +269,17 @@ class AgentPromptingTests(unittest.TestCase):
|
||||
def test_prompt_builder_mentions_tasks_when_runtime_is_loaded(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir)
|
||||
runtime = TaskRuntime.from_workspace(workspace)
|
||||
scratchpad = workspace / '.port_sessions' / 'accounts' / 'alice' / 'sessions' / 's1' / 'scratchpad'
|
||||
scratchpad.mkdir(parents=True)
|
||||
runtime = TaskRuntime.from_storage_path(scratchpad / 'task_runtime.json')
|
||||
runtime.create_task(title='Inspect runtime tasks')
|
||||
runtime_config = AgentRuntimeConfig(cwd=workspace)
|
||||
model_config = ModelConfig(model='Qwen/Qwen3-Coder-30B-A3B-Instruct')
|
||||
prompt_context = build_prompt_context(runtime_config, model_config)
|
||||
prompt_context = build_prompt_context(
|
||||
runtime_config,
|
||||
model_config,
|
||||
scratchpad_directory=scratchpad,
|
||||
)
|
||||
parts = build_system_prompt_parts(
|
||||
prompt_context=prompt_context,
|
||||
runtime_config=runtime_config,
|
||||
@@ -305,14 +311,20 @@ class AgentPromptingTests(unittest.TestCase):
|
||||
def test_prompt_builder_mentions_planning_when_runtime_is_loaded(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir)
|
||||
runtime = PlanRuntime.from_workspace(workspace)
|
||||
scratchpad = workspace / '.port_sessions' / 'accounts' / 'alice' / 'sessions' / 's1' / 'scratchpad'
|
||||
scratchpad.mkdir(parents=True)
|
||||
runtime = PlanRuntime.from_storage_path(scratchpad / 'plan_runtime.json')
|
||||
runtime.update_plan(
|
||||
[{'step': 'Inspect runtime planning', 'status': 'pending'}],
|
||||
explanation='Track the current plan.',
|
||||
)
|
||||
runtime_config = AgentRuntimeConfig(cwd=workspace)
|
||||
model_config = ModelConfig(model='Qwen/Qwen3-Coder-30B-A3B-Instruct')
|
||||
prompt_context = build_prompt_context(runtime_config, model_config)
|
||||
prompt_context = build_prompt_context(
|
||||
runtime_config,
|
||||
model_config,
|
||||
scratchpad_directory=scratchpad,
|
||||
)
|
||||
parts = build_system_prompt_parts(
|
||||
prompt_context=prompt_context,
|
||||
runtime_config=runtime_config,
|
||||
|
||||
@@ -183,7 +183,11 @@ class PlanRuntimeTests(unittest.TestCase):
|
||||
),
|
||||
)
|
||||
result = agent.run('Store the current plan')
|
||||
self.assertTrue((workspace / '.port_sessions' / 'plan_runtime.json').exists())
|
||||
self.assertIsNotNone(result.scratchpad_directory)
|
||||
self.assertTrue(
|
||||
(Path(result.scratchpad_directory) / 'plan_runtime.json').exists()
|
||||
)
|
||||
self.assertFalse((workspace / '.port_sessions' / 'plan_runtime.json').exists())
|
||||
|
||||
self.assertEqual(result.final_output, 'The plan was stored successfully.')
|
||||
self.assertEqual(result.tool_calls, 1)
|
||||
|
||||
@@ -233,7 +233,11 @@ class TaskRuntimeTests(unittest.TestCase):
|
||||
),
|
||||
)
|
||||
result = agent.run('Create a task for the current work')
|
||||
self.assertTrue((workspace / '.port_sessions' / 'task_runtime.json').exists())
|
||||
self.assertIsNotNone(result.scratchpad_directory)
|
||||
self.assertTrue(
|
||||
(Path(result.scratchpad_directory) / 'task_runtime.json').exists()
|
||||
)
|
||||
self.assertFalse((workspace / '.port_sessions' / 'task_runtime.json').exists())
|
||||
|
||||
self.assertEqual(result.final_output, 'The task was created successfully.')
|
||||
self.assertEqual(result.tool_calls, 1)
|
||||
|
||||
Reference in New Issue
Block a user