fix(runtime): pass session cwd through runtime construction
This commit is contained in:
@@ -92,6 +92,7 @@ async def run_print_mode(
|
||||
|
||||
bundle = await build_runtime(
|
||||
prompt=prompt,
|
||||
cwd=cwd,
|
||||
model=model,
|
||||
max_turns=max_turns,
|
||||
base_url=base_url,
|
||||
|
||||
@@ -85,6 +85,7 @@ class ReactBackendHost:
|
||||
api_format=self._config.api_format,
|
||||
active_profile=self._config.active_profile,
|
||||
api_client=self._config.api_client,
|
||||
cwd=self._config.cwd,
|
||||
restore_messages=self._config.restore_messages,
|
||||
permission_prompt=self._ask_permission,
|
||||
ask_user_prompt=self._ask_question,
|
||||
|
||||
@@ -163,6 +163,7 @@ def _resolve_api_client_from_settings(settings) -> SupportsStreamingMessages:
|
||||
async def build_runtime(
|
||||
*,
|
||||
prompt: str | None = None,
|
||||
cwd: str | None = None,
|
||||
model: str | None = None,
|
||||
max_turns: int | None = None,
|
||||
base_url: str | None = None,
|
||||
@@ -192,7 +193,7 @@ async def build_runtime(
|
||||
"permission_mode": permission_mode,
|
||||
}
|
||||
settings = load_settings().merge_cli_overrides(**settings_overrides)
|
||||
cwd = str(Path.cwd())
|
||||
cwd = str(Path(cwd).expanduser().resolve()) if cwd else str(Path.cwd())
|
||||
normalized_skill_dirs = tuple(str(Path(path).expanduser().resolve()) for path in (extra_skill_dirs or ()))
|
||||
normalized_plugin_roots = tuple(str(Path(path).expanduser().resolve()) for path in (extra_plugin_roots or ()))
|
||||
plugins = load_plugins(settings, cwd, extra_roots=normalized_plugin_roots)
|
||||
|
||||
@@ -241,6 +241,7 @@ class OpenHarnessTerminalApp(App[None]):
|
||||
async def on_mount(self) -> None:
|
||||
self._bundle = await build_runtime(
|
||||
prompt=self._config.prompt,
|
||||
cwd=str(self.app.cwd) if getattr(self.app, 'cwd', None) else None,
|
||||
model=self._config.model,
|
||||
base_url=self._config.base_url,
|
||||
system_prompt=self._config.system_prompt,
|
||||
|
||||
@@ -3,11 +3,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from types import SimpleNamespace
|
||||
|
||||
from openharness.ui.app import run_repl
|
||||
from openharness.ui.app import run_print_mode, run_repl
|
||||
from openharness.ui.react_launcher import build_backend_command
|
||||
|
||||
|
||||
class _AsyncIterator:
|
||||
def __aiter__(self):
|
||||
return self
|
||||
|
||||
async def __anext__(self):
|
||||
raise StopAsyncIteration
|
||||
|
||||
|
||||
def test_build_backend_command_includes_flags():
|
||||
command = build_backend_command(
|
||||
cwd="/tmp/demo",
|
||||
@@ -39,3 +48,35 @@ async def test_run_repl_uses_react_launcher_by_default(monkeypatch):
|
||||
assert seen["prompt"] == "hi"
|
||||
assert seen["cwd"] == "/tmp/demo"
|
||||
assert seen["model"] == "kimi-k2.5"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_print_mode_passes_cwd_to_build_runtime(monkeypatch):
|
||||
seen = {}
|
||||
|
||||
async def _build_runtime(**kwargs):
|
||||
seen.update(kwargs)
|
||||
return SimpleNamespace(
|
||||
app_state=SimpleNamespace(get=lambda: None),
|
||||
mcp_manager=SimpleNamespace(list_statuses=lambda: []),
|
||||
commands=SimpleNamespace(list_commands=lambda: []),
|
||||
events=_AsyncIterator(),
|
||||
)
|
||||
|
||||
async def _start_runtime(_bundle):
|
||||
return None
|
||||
|
||||
async def _handle_line(*_args, **_kwargs):
|
||||
return None
|
||||
|
||||
async def _close_runtime(_bundle):
|
||||
return None
|
||||
|
||||
monkeypatch.setattr("openharness.ui.app.build_runtime", _build_runtime)
|
||||
monkeypatch.setattr("openharness.ui.app.start_runtime", _start_runtime)
|
||||
monkeypatch.setattr("openharness.ui.app.handle_line", _handle_line)
|
||||
monkeypatch.setattr("openharness.ui.app.close_runtime", _close_runtime)
|
||||
|
||||
await run_print_mode(prompt="hi", cwd="/tmp/demo")
|
||||
|
||||
assert seen["cwd"] == "/tmp/demo"
|
||||
|
||||
Reference in New Issue
Block a user