Skip to content

Your lightweight open-source personal agent.

test: isolate Star invitation state and stabilize late-result waits (#6076)

chengyongru42f06ab1dcf7
diff --git a/conftest.py b/conftest.py
index 5de6db38e..66bda8be9 100644
--- a/conftest.py
+++ b/conftest.py
@@ -57,6 +57,15 @@ def _isolate_sessions_root(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> I
yield
[email protected](autouse=True)
+def _isolate_star_prompt_store(
+ tmp_path_factory: pytest.TempPathFactory, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """Keep WebUI completion events out of the user's invitation state and lock."""
+ webui_dir = tmp_path_factory.mktemp("star-prompt-webui")
+ monkeypatch.setattr("nanobot.webui.star_prompt.get_webui_dir", lambda: webui_dir)
+
+
@pytest.fixture(autouse=True)
def _isolate_pairing_store(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""Keep channel pairing tests out of the user's active pairing store."""
diff --git a/nanobot/channels/websocket/tests/test_websocket_http_routes.py b/nanobot/channels/websocket/tests/test_websocket_http_routes.py
index e63a4131a..0cab606f9 100644
--- a/nanobot/channels/websocket/tests/test_websocket_http_routes.py
+++ b/nanobot/channels/websocket/tests/test_websocket_http_routes.py
@@ -4208,13 +4208,11 @@ def test_bootstrap_secret_also_enforced_on_localhost(bus: MagicMock) -> None:
@pytest.mark.asyncio
async def test_star_prompt_requires_authenticated_mutation_and_persists_dismissal(
- bus: MagicMock, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+ bus: MagicMock,
) -> None:
- from nanobot.webui.star_prompt import StarPromptState
+ from nanobot.webui.star_prompt import StarPromptState, get_webui_dir
- monkeypatch.setattr("nanobot.config.paths.get_data_dir", lambda: tmp_path)
- state_path = tmp_path / "webui" / "star-prompt.json"
- state_path.parent.mkdir()
+ state_path = get_webui_dir() / "star-prompt.json"
state_path.write_text(StarPromptState(
completed_replies=10, active_days=["2026-09-20", "2026-09-21", "2026-09-22"]
).model_dump_json(), encoding="utf-8")
diff --git a/tests/agent/test_loop_progress.py b/tests/agent/test_loop_progress.py
index a4cb48c77..6beb9ac02 100644
--- a/tests/agent/test_loop_progress.py
+++ b/tests/agent/test_loop_progress.py
@@ -882,7 +882,7 @@ class TestToolEventProgress:
},
)))
- await asyncio.wait_for(first_request_started.wait(), timeout=1)
+ await asyncio.wait_for(first_request_started.wait(), timeout=5)
await loop._pending_queues[session_key].put(InboundMessage(
channel="websocket",
sender_id="user",
@@ -891,7 +891,8 @@ class TestToolEventProgress:
session_key_override=session_key,
))
release_first_request.set()
- await asyncio.wait_for(dispatch, timeout=2)
+ # Events synchronize injection; the deadline only guards against a stuck worker.
+ await asyncio.wait_for(dispatch, timeout=5)
outbound = []
while bus.outbound_size > 0:
diff --git a/tests/webui/test_star_prompt.py b/tests/webui/test_star_prompt.py
index 424525143..71a2e9b80 100644
--- a/tests/webui/test_star_prompt.py
+++ b/tests/webui/test_star_prompt.py
@@ -8,9 +8,11 @@ from nanobot.webui import star_prompt
@pytest.fixture
-def state_path(tmp_path, monkeypatch):
- monkeypatch.setattr(star_prompt, "get_webui_dir", lambda: tmp_path)
- return tmp_path / "star-prompt.json"
+def state_path(tmp_path, tmp_path_factory):
+ webui_dir = star_prompt.get_webui_dir()
+ assert webui_dir.is_relative_to(tmp_path_factory.getbasetemp())
+ assert not webui_dir.is_relative_to(tmp_path)
+ return webui_dir / "star-prompt.json"
def seed_eligible(path: Path):