Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(tests): patch the seam the code reads, and pass the Request the routes now take
Ruben Lütke228fb90b0018
diff --git a/tests/unit/core/test_dictation_paste_chord_custom.py b/tests/unit/core/test_dictation_paste_chord_custom.pyindex d826c05ba5..33d79a1a78 100644--- a/tests/unit/core/test_dictation_paste_chord_custom.py+++ b/tests/unit/core/test_dictation_paste_chord_custom.py@@ -16,6 +16,8 @@ from __future__ import annotationsimport pytest+import jarvis.platform+import jarvis.platform.clipboard # noqa: F401 (binds the package attribute)from jarvis.core.config import DictationConfigfrom jarvis.dictation.insert import (CUSTOM_CHORD_KEYS,@@ -27,6 +29,23 @@ from jarvis.dictation.insert import ()from jarvis.dictation.outcomes import DICTATION_OUTCOMES++def _install_fake_clipboard(monkeypatch: pytest.MonkeyPatch, fake: object) -> None:+ """Put ``fake`` where ``insert_text`` actually looks for the clipboard.++ ``jarvis.dictation.insert`` reaches the module with ``from jarvis.platform+ import clipboard``, which reads the ATTRIBUTE off the already-imported+ ``jarvis.platform`` package and only falls back to ``sys.modules`` when+ that attribute is missing. Replacing the ``sys.modules`` entry alone+ therefore works exactly once -- in a run where nothing has imported the+ real module yet -- and is silently bypassed as soon as any earlier test+ binds the attribute. That is worse than a flaky assertion: the double+ would be ignored and the test would drive the REAL system clipboard of+ whoever ran the suite. Patch the attribute the code reads.+ """+ monkeypatch.setattr(jarvis.platform, "clipboard", fake)++# ----------------------------------------------------------------------# What the field accepts# ----------------------------------------------------------------------@@ -141,9 +160,7 @@ def test_a_custom_chord_reports_paste_sent_and_keeps_the_clipboard(clipboard = _Clipboard()actuator = _Actuator()- monkeypatch.setitem(- __import__("sys").modules, "jarvis.platform.clipboard", clipboard- )+ _install_fake_clipboard(monkeypatch, clipboard)monkeypatch.setattr(insert_mod, "describe_target", lambda: insert_mod.TargetReport(True, "", ""))@@ -179,12 +196,17 @@ def test_a_curated_chord_still_reports_inserted_and_restores(class _Clipboard:def __init__(self) -> None:self.content = "previous"+ # Every write is recorded so the closing assertion cannot pass+ # vacuously: a double that is never reached also never changes+ # ``content``, which is precisely the end state this test wants.+ self.writes: list[str] = []def read_text(self) -> str:return self.contentdef write_text(self, text: str) -> bool:self.content = text+ self.writes.append(text)return Trueclass _Actuator:@@ -192,9 +214,7 @@ def test_a_curated_chord_still_reports_inserted_and_restores(return Noneclipboard = _Clipboard()- monkeypatch.setitem(- __import__("sys").modules, "jarvis.platform.clipboard", clipboard- )+ _install_fake_clipboard(monkeypatch, clipboard)monkeypatch.setattr(insert_mod, "describe_target", lambda: insert_mod.TargetReport(True, "", ""))@@ -208,4 +228,5 @@ def test_a_curated_chord_still_reports_inserted_and_restores(assert result.status == "inserted"assert result.clipboard_restored is True+ assert clipboard.writes == ["dictated text", "previous"]assert clipboard.content == "previous"diff --git a/tests/unit/web/test_agentic_ide_recents.py b/tests/unit/web/test_agentic_ide_recents.pyindex bc2730cf1d..11c517fe00 100644--- a/tests/unit/web/test_agentic_ide_recents.py+++ b/tests/unit/web/test_agentic_ide_recents.py@@ -43,7 +43,13 @@ async def test_open_route_remembers_the_user_selected_folder(lambda path, *, terminals, agents: remembered.append((path, terminals, agents)),)+ # ``app.state.bus`` is all the route wants from the Request: opening a+ # workspace announces itself so other windows redraw. No bus, no+ # announcement — this test is about the recent-folder history.+ request = SimpleNamespace(app=SimpleNamespace(state=SimpleNamespace(bus=None)))+response = await routes.start_session(+ request,routes.StartSessionRequest(folder=str(tmp_path),terminals=[@@ -51,7 +57,7 @@ async def test_open_route_remembers_the_user_selected_folder(routes.TerminalRequest(agent="codex"),routes.TerminalRequest(agent="claude"),],- )+ ),)assert response["ok"] is Truediff --git a/tests/unit/web/test_agentic_ide_workspaces.py b/tests/unit/web/test_agentic_ide_workspaces.pyindex 63b46ceddb..a8dcef76b4 100644--- a/tests/unit/web/test_agentic_ide_workspaces.py+++ b/tests/unit/web/test_agentic_ide_workspaces.py@@ -14,6 +14,7 @@ other way round — still fails here.from __future__ import annotationsfrom pathlib import Path+from types import SimpleNamespaceimport pytest@@ -68,13 +69,25 @@ async def _noop_exit(_code: int) -> None:return None+def _request(bus: object | None = None) -> SimpleNamespace:+ """The one thing the open route needs from a Request: ``app.state.bus``.++ Opening a workspace announces itself on the bus so every OTHER window can+ redraw its grid instead of talking to a workspace that moved. Without a bus+ the announcement is skipped, which is what these tests want: they are about+ what opening DOES, and the announcement has its own suite.+ """+ return SimpleNamespace(app=SimpleNamespace(state=SimpleNamespace(bus=bus)))++async def _open(registry: Registry, folder: Path, panes: int = 1) -> object:folder.mkdir(parents=True, exist_ok=True)return await routes.start_session(+ _request(),routes.StartSessionRequest(folder=str(folder),terminals=[routes.TerminalRequest(agent="claude") for _ in range(panes)],- )+ ),)@@ -126,7 +139,9 @@ async def test_switching_starts_and_stops_nothing(spawns = len(fake_pty.spawns)await _open(registry, tmp_path / "beta")- result = await routes.activate_workspace(routes.ActivateWorkspaceRequest(id=first_id))+ result = await routes.activate_workspace(+ _request(), routes.ActivateWorkspaceRequest(id=first_id)+ )assert result["active_id"] == first_idassert first_pty not in fake_pty.closed, "switching must not stop an agent"@@ -147,7 +162,7 @@ async def test_the_wizard_state_keeps_every_workspace_open(pane = registry.session.terminals[0]await registry.attach(pane.name, 80, 24, _noop, _noop_exit)- result = await routes.activate_workspace(routes.ActivateWorkspaceRequest(id=None))+ result = await routes.activate_workspace(_request(), routes.ActivateWorkspaceRequest(id=None))assert result["active_id"] is Noneassert result["state"]["session"] is None, "no workspace is on screen"@@ -164,7 +179,7 @@ async def test_switching_to_a_workspace_that_is_gone_is_a_404(await _open(registry, tmp_path / "alpha")with pytest.raises(HTTPException) as caught:await routes.activate_workspace(- routes.ActivateWorkspaceRequest(id="ide_never_existed")+ _request(), routes.ActivateWorkspaceRequest(id="ide_never_existed"))assert caught.value.status_code == 404@@ -183,7 +198,7 @@ async def test_closing_one_workspace_stops_only_its_agents(second_pane = registry.get(second_id).terminals[0]await registry.attach(second_pane.name, 80, 24, _noop, _noop_exit, second_id)- result = await routes.close_workspace(second_id)+ result = await routes.close_workspace(_request(), second_id)assert result["closed"] == second_idassert second_pane.pty_id in fake_pty.closed@@ -199,7 +214,7 @@ async def test_closing_an_unknown_workspace_is_a_404(await _open(registry, tmp_path / "alpha")with pytest.raises(HTTPException) as caught:- await routes.close_workspace("ide_never_existed")+ await routes.close_workspace(_request(), "ide_never_existed")assert caught.value.status_code == 404@@ -210,7 +225,7 @@ async def test_the_plain_close_still_closes_the_front_one(await _open(registry, tmp_path / "alpha")second = await _open(registry, tmp_path / "beta")- result = await routes.end_session()+ result = await routes.end_session(_request())assert result["closed"] is Trueremaining = [w["name"] for w in result["state"]["workspaces"]]