mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-01 08:42:20 +03:00
feat(tui): unify session history and context
This commit is contained in:
@@ -10,6 +10,8 @@ from nanobot.cli.tui_launcher import (
|
||||
_authenticated_ws_url,
|
||||
_download_release_tui,
|
||||
_ensure_gateway,
|
||||
_initial_tui_chat_id,
|
||||
_read_tui_chat_id,
|
||||
_resolve_tui_command,
|
||||
_websocket_chat_id,
|
||||
)
|
||||
@@ -36,6 +38,28 @@ def test_websocket_chat_id(session_id: str, expected: str | None) -> None:
|
||||
assert _websocket_chat_id(session_id) == expected
|
||||
|
||||
|
||||
def test_tui_chat_state_is_optional_and_validated(tmp_path: Path) -> None:
|
||||
path = tmp_path / "tui" / "state.json"
|
||||
assert _read_tui_chat_id(path) is None
|
||||
|
||||
path.parent.mkdir()
|
||||
path.write_text('{"schema_version": 1, "chat_id": "saved-chat"}', encoding="utf-8")
|
||||
assert _read_tui_chat_id(path) == "saved-chat"
|
||||
|
||||
path.write_text('{"chat_id": "bad\\nchat"}', encoding="utf-8")
|
||||
assert _read_tui_chat_id(path) is None
|
||||
|
||||
|
||||
def test_default_tui_resumes_but_explicit_session_wins(tmp_path: Path) -> None:
|
||||
path = tmp_path / "tui" / "state.json"
|
||||
path.parent.mkdir()
|
||||
path.write_text('{"chat_id": "saved-chat"}', encoding="utf-8")
|
||||
|
||||
assert _initial_tui_chat_id(None, path) == "saved-chat"
|
||||
assert _initial_tui_chat_id("cli:direct", path) == "tui-direct"
|
||||
assert _initial_tui_chat_id("websocket:chosen", path) == "chosen"
|
||||
|
||||
|
||||
def test_explicit_tui_binary_must_exist(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
|
||||
Reference in New Issue
Block a user