Files
hkuds--openharness/tests/test_ui/test_runtime_plan_mode.py
T
Mcy0618 033dce67b1 fix(runtime): refresh prompt for permission mode changes
Inject the active permission mode into the runtime system prompt so plan/default/full-auto state is visible to the model.

Refresh the engine model, effort, permission checker, and system prompt when runtime-affecting slash commands update settings.

Based-on: #268
2026-05-24 09:10:10 +00:00

50 lines
1.5 KiB
Python

from __future__ import annotations
from pathlib import Path
import pytest
from openharness.ui.runtime import build_runtime, close_runtime, handle_line
class _StaticApiClient:
async def stream_message(self, request):
del request
if False:
yield None
@pytest.mark.asyncio
async def test_plan_command_refreshes_engine_system_prompt(tmp_path: Path, monkeypatch):
monkeypatch.setenv("OPENHARNESS_CONFIG_DIR", str(tmp_path / "config"))
monkeypatch.setenv("OPENHARNESS_DATA_DIR", str(tmp_path / "data"))
monkeypatch.setenv("OPENHARNESS_LOGS_DIR", str(tmp_path / "logs"))
bundle = await build_runtime(cwd=str(tmp_path), api_client=_StaticApiClient())
try:
assert "Plan mode is enabled" not in bundle.engine.system_prompt
async def print_system(text: str) -> None:
del text
async def render_event(event) -> None:
del event
async def clear_output() -> None:
pass
should_continue = await handle_line(
bundle,
"/plan on",
print_system=print_system,
render_event=render_event,
clear_output=clear_output,
)
assert should_continue is True
assert bundle.app_state.get().permission_mode == "plan"
assert "Plan mode is enabled" in bundle.engine.system_prompt
assert "Do not call mutating tools" in bundle.engine.system_prompt
finally:
await close_runtime(bundle)