Bolt Console: desktop app with chat list / new chat, dictation, file tools
Add a chat list and server-minted new chats on top of the desk API's
GET/POST /desk/chats:
- server_client.list_chats() / create_chat(), same shape and error
handling as list_outbox_files().
- Switching is config.set_session(id): a plain reassignment of the
SESSION_ID every call reads, persisted to session.json. The window
refuses to switch mid-turn rather than locking.
- gui/chat_list_window.py: a Chats dialog (Ctrl+K) with a QListWidget,
populated on open, with Refresh and New Chat. Network calls run as
QRunnables on the global QThreadPool and come back through Signals,
never from a slot. The header New chat (Ctrl+N) uses the same path.
- Switching clears the local transcript; there is no endpoint for a
past chat's messages. Bolt's memory is per user, so it carries over.
- Terminal: /chats, /chat <n|id>, and /new (server-minted id, local
fallback).
This commit also carries the uncommitted work since 54030a7 that turned
this Bolt-Pet fork into Bolt Console: the pet, wake word, TTS and screen
features removed; a Claude Code-style terminal client; the PySide6
window with tool cards, approvals and diffs; mic dictation through the
server's /desk/stt relay; filectl/JSON repairs; and detection of
invented tool results.
Build output (build/, dist/, Release/, *.spec) is now ignored.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+136
-33
@@ -6,14 +6,14 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
import pytest
|
||||
|
||||
from bolt_pet import server_client
|
||||
from bolt_console import server_client
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _configure(monkeypatch):
|
||||
monkeypatch.setattr(server_client.config, "SERVER_URL", "http://test-server:5002")
|
||||
monkeypatch.setattr(server_client.config, "API_KEY", "test-key")
|
||||
monkeypatch.setattr(server_client.config, "SESSION_ID", "pet-test")
|
||||
monkeypatch.setattr(server_client.config, "SESSION_ID", "pet-console-test")
|
||||
|
||||
|
||||
def _mock_response(json_data, ok=True):
|
||||
@@ -28,11 +28,10 @@ def test_converse_returns_reply_directly():
|
||||
post.return_value = _mock_response({"type": "reply", "text": "hello there"})
|
||||
result = server_client.converse("hi")
|
||||
assert result.text == "hello there"
|
||||
assert result.voice_id == "" # no speak_as on this reply
|
||||
post.assert_called_once()
|
||||
args, kwargs = post.call_args
|
||||
assert args[0] == "http://test-server:5002/desk/converse"
|
||||
assert kwargs["json"] == {"session_id": "pet-test", "text": "hi"}
|
||||
assert kwargs["json"] == {"session_id": "pet-console-test", "text": "hi"}
|
||||
assert kwargs["headers"] == {"X-Desk-Api-Key": "test-key"}
|
||||
|
||||
|
||||
@@ -50,23 +49,10 @@ def test_converse_relays_a_command_then_returns_reply():
|
||||
second_call = post.call_args_list[1]
|
||||
assert second_call.args[0] == "http://test-server:5002/desk/tool_result"
|
||||
assert second_call.kwargs["json"] == {
|
||||
"session_id": "pet-test", "token": "tok1", "output": "[exit 0]\nhi",
|
||||
"session_id": "pet-console-test", "token": "tok1", "output": "[exit 0]\nhi",
|
||||
}
|
||||
|
||||
|
||||
def test_converse_carries_a_speak_as_voice_back_with_the_reply():
|
||||
"""The server tags a reply with the voice it picked (speak_as); this
|
||||
client is what actually speaks in it, so the id has to survive the
|
||||
return trip rather than being dropped with the rest of the payload."""
|
||||
with patch.object(server_client.requests, "post") as post:
|
||||
post.return_value = _mock_response({
|
||||
"type": "reply", "text": "Ahoy there.",
|
||||
"voice_id": "hnhGxwvHP8fc469w51rM", "voice_name": "Terence",
|
||||
})
|
||||
result = server_client.converse("talk like a pirate")
|
||||
assert result == server_client.Reply("Ahoy there.", "hnhGxwvHP8fc469w51rM", "Terence")
|
||||
|
||||
|
||||
def test_converse_raises_server_error_on_error_payload():
|
||||
with patch.object(server_client.requests, "post") as post:
|
||||
post.return_value = _mock_response({"type": "error", "error": "unauthorized"})
|
||||
@@ -80,19 +66,6 @@ def test_converse_raises_server_error_when_unreachable():
|
||||
server_client.converse("hi")
|
||||
|
||||
|
||||
def test_report_status_returns_reply_text_when_present():
|
||||
with patch.object(server_client.requests, "post") as post:
|
||||
post.return_value = _mock_response({"reply": "don't forget your 3pm"})
|
||||
result = server_client.report_status()
|
||||
assert result == "don't forget your 3pm"
|
||||
|
||||
|
||||
def test_report_status_returns_none_when_nothing_pending():
|
||||
with patch.object(server_client.requests, "post") as post:
|
||||
post.return_value = _mock_response({"ok": True})
|
||||
assert server_client.report_status() is None
|
||||
|
||||
|
||||
def test_check_health_returns_parsed_json():
|
||||
with patch.object(server_client.requests, "get") as get:
|
||||
get.return_value = _mock_response({"ok": True, "service": "bolt-desk-api"})
|
||||
@@ -109,7 +82,7 @@ def test_list_outbox_files_returns_the_queue():
|
||||
assert result == [{"id": "abc", "name": "report.pdf", "size": 9}]
|
||||
args, kwargs = get.call_args
|
||||
assert args[0] == "http://test-server:5002/desk/files"
|
||||
assert kwargs["params"] == {"session_id": "pet-test"}
|
||||
assert kwargs["params"] == {"session_id": "pet-console-test"}
|
||||
assert kwargs["headers"] == {"X-Desk-Api-Key": "test-key"}
|
||||
|
||||
|
||||
@@ -134,7 +107,7 @@ def test_download_outbox_file_returns_raw_bytes():
|
||||
assert result == b"%PDF fake bytes"
|
||||
args, kwargs = get.call_args
|
||||
assert args[0] == "http://test-server:5002/desk/files/abc"
|
||||
assert kwargs["params"] == {"session_id": "pet-test"}
|
||||
assert kwargs["params"] == {"session_id": "pet-console-test"}
|
||||
|
||||
|
||||
def test_download_outbox_file_raises_server_error_on_http_failure():
|
||||
@@ -142,3 +115,133 @@ def test_download_outbox_file_raises_server_error_on_http_failure():
|
||||
get.return_value = _mock_response({}, ok=False)
|
||||
with pytest.raises(server_client.ServerError, match="abc"):
|
||||
server_client.download_outbox_file("abc")
|
||||
|
||||
|
||||
class _StreamResponse:
|
||||
def __init__(self, events):
|
||||
self._lines = [__import__("json").dumps(e) for e in events]
|
||||
self.closed = False
|
||||
|
||||
def raise_for_status(self):
|
||||
pass
|
||||
|
||||
def iter_lines(self, decode_unicode=True):
|
||||
return iter(self._lines)
|
||||
|
||||
def close(self):
|
||||
self.closed = True
|
||||
|
||||
|
||||
def test_converse_stream_hands_each_sentence_over_and_marks_the_reply_streamed():
|
||||
said = []
|
||||
events = [
|
||||
{"type": "say", "text": "First."},
|
||||
{"type": "say", "text": "Second."},
|
||||
{"type": "reply", "text": "First. Second.", "already_spoken": True},
|
||||
]
|
||||
with patch.object(server_client.requests, "post", return_value=_StreamResponse(events)):
|
||||
reply = server_client.converse_stream("hi", on_say=said.append)
|
||||
assert said == ["First.", "Second."]
|
||||
assert reply == server_client.Reply("First. Second.", streamed=True)
|
||||
|
||||
|
||||
def test_converse_stream_finishes_a_tool_call_through_the_plain_relay():
|
||||
events = [{"type": "command", "command": "filectl {}", "token": "t1"}]
|
||||
posts = [_StreamResponse(events), _mock_response({"type": "reply", "text": "done"})]
|
||||
on_command = MagicMock(return_value="out")
|
||||
with patch.object(server_client.requests, "post", side_effect=posts) as post:
|
||||
reply = server_client.converse_stream("hi", on_say=lambda _s: None, on_command=on_command)
|
||||
on_command.assert_called_once_with("filectl {}")
|
||||
assert post.call_args_list[1].args[0].endswith("/desk/tool_result")
|
||||
assert reply == server_client.Reply("done", streamed=False)
|
||||
|
||||
|
||||
def test_converse_stream_failing_before_any_text_raises_for_the_fallback():
|
||||
with patch.object(server_client.requests, "post", side_effect=ConnectionError("down")):
|
||||
with pytest.raises(server_client.ServerError):
|
||||
server_client.converse_stream("hi", on_say=lambda _s: None)
|
||||
|
||||
|
||||
def test_run_local_command_runs_in_the_current_directory(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
(tmp_path / "marker.txt").write_text("x")
|
||||
output = server_client.run_local_command("dir /b" if sys.platform == "win32" else "ls")
|
||||
assert output.startswith("[exit 0]")
|
||||
assert "marker.txt" in output
|
||||
|
||||
|
||||
def test_a_final_reply_repeating_the_streamed_sentences_is_not_shown_twice():
|
||||
"""Seen live: sentences streamed, then the same text again as the reply,
|
||||
without already_spoken — with line breaks the stream had dropped."""
|
||||
events = [
|
||||
{"type": "say", "text": "Let me check that."},
|
||||
{"type": "say", "text": "The folder contains:"},
|
||||
{"type": "reply", "text": "Let me check that.\n\nThe folder contains:\n- a\n- b"},
|
||||
]
|
||||
with patch.object(server_client.requests, "post", return_value=_StreamResponse(events)):
|
||||
reply = server_client.converse_stream("hi", on_say=lambda _s: None)
|
||||
assert reply == server_client.Reply("- a\n- b", streamed=False)
|
||||
|
||||
|
||||
def test_an_exact_repeat_counts_as_streamed():
|
||||
events = [{"type": "say", "text": "Done."}, {"type": "reply", "text": "Done."}]
|
||||
with patch.object(server_client.requests, "post", return_value=_StreamResponse(events)):
|
||||
reply = server_client.converse_stream("hi", on_say=lambda _s: None)
|
||||
assert reply.streamed and reply.text == ""
|
||||
|
||||
|
||||
def test_a_different_final_reply_is_shown_in_full():
|
||||
events = [{"type": "say", "text": "Checking."}, {"type": "reply", "text": "All good."}]
|
||||
with patch.object(server_client.requests, "post", return_value=_StreamResponse(events)):
|
||||
reply = server_client.converse_stream("hi", on_say=lambda _s: None)
|
||||
assert reply == server_client.Reply("All good.", streamed=False)
|
||||
|
||||
|
||||
def test_list_chats_returns_the_list_with_the_api_key():
|
||||
chats = [{"session_id": "chat-3f9a2b1c9e04", "label": "Fix the build",
|
||||
"last_message": "try again", "last_active": "2026-09-25T23:46:31+00:00"}]
|
||||
with patch.object(server_client.requests, "get") as get:
|
||||
get.return_value = _mock_response({"chats": chats})
|
||||
assert server_client.list_chats() == chats
|
||||
args, kwargs = get.call_args
|
||||
assert args[0] == "http://test-server:5002/desk/chats"
|
||||
assert kwargs["headers"] == {"X-Desk-Api-Key": "test-key"}
|
||||
|
||||
|
||||
def test_list_chats_defaults_to_empty_and_wraps_failures():
|
||||
with patch.object(server_client.requests, "get") as get:
|
||||
get.return_value = _mock_response({})
|
||||
assert server_client.list_chats() == []
|
||||
with patch.object(server_client.requests, "get") as get:
|
||||
get.return_value = _mock_response({}, ok=False) # e.g. a 401
|
||||
with pytest.raises(server_client.ServerError, match="couldn't list chats"):
|
||||
server_client.list_chats()
|
||||
|
||||
|
||||
def test_create_chat_posts_and_returns_the_new_session_id():
|
||||
with patch.object(server_client.requests, "post") as post:
|
||||
post.return_value = _mock_response({"session_id": "chat-3f9a2b1c9e04"})
|
||||
assert server_client.create_chat() == "chat-3f9a2b1c9e04"
|
||||
args, kwargs = post.call_args
|
||||
assert args[0] == "http://test-server:5002/desk/chats"
|
||||
assert kwargs["headers"] == {"X-Desk-Api-Key": "test-key"}
|
||||
|
||||
|
||||
def test_create_chat_without_a_session_id_is_an_error():
|
||||
with patch.object(server_client.requests, "post") as post:
|
||||
post.return_value = _mock_response({})
|
||||
with pytest.raises(server_client.ServerError, match="session_id"):
|
||||
server_client.create_chat()
|
||||
with patch.object(server_client.requests, "post", side_effect=ConnectionError("down")):
|
||||
with pytest.raises(server_client.ServerError):
|
||||
server_client.create_chat()
|
||||
|
||||
|
||||
def test_every_call_follows_a_reassigned_session_id(monkeypatch):
|
||||
"""Switching chats is just `config.SESSION_ID = new_id`; the next request
|
||||
must carry it, with no call site holding on to the old one."""
|
||||
monkeypatch.setattr(server_client.config, "SESSION_ID", "chat-new")
|
||||
with patch.object(server_client.requests, "post") as post:
|
||||
post.return_value = _mock_response({"type": "reply", "text": "hi"})
|
||||
server_client.converse("hi")
|
||||
assert post.call_args.kwargs["json"]["session_id"] == "chat-new"
|
||||
|
||||
Reference in New Issue
Block a user