Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

test(auth): add high-priority setup scenarios

cyhe337333a54da
diff --git a/tests/scenario_harness/core.py b/tests/scenario_harness/core.py
index 6a29fa4dd..9e0993a53 100644
--- a/tests/scenario_harness/core.py
+++ b/tests/scenario_harness/core.py
@@ -89,6 +89,8 @@ class FakeProcess:
self.returncode = None
self.stdout = SimpleNamespace(readline=AsyncMock(return_value=b""))
self._done = asyncio.Event()
+ self.terminate_calls = 0
+ self.kill_calls = 0
async def wait(self):
await self._done.wait()
@@ -99,9 +101,11 @@ class FakeProcess:
self._done.set()
def terminate(self):
+ self.terminate_calls += 1
self.finish(-15)
def kill(self):
+ self.kill_calls += 1
self.finish(-9)
@@ -169,3 +173,16 @@ class ScenarioExpect:
@staticmethod
def step_history(runner: ScenarioRunner, expected: list[str]):
assert runner.history == expected, f"Expected step history {expected!r}, got {runner.history!r}"
+
+ @staticmethod
+ def button_callback_contains(harness: BaseScenarioHarness, needle: str):
+ buttons = harness.controller.im_probe.matching("buttons")
+ assert buttons, "Expected at least one button event"
+ callbacks = []
+ for _, _, keyboard in buttons:
+ for row in getattr(keyboard, "buttons", []):
+ for button in row:
+ callbacks.append(getattr(button, "callback_data", ""))
+ assert any(needle in callback for callback in callbacks), (
+ f"Expected one button callback to contain {needle!r}, got {callbacks!r}"
+ )
diff --git a/tests/test_agent_auth_setup_scenarios.py b/tests/test_agent_auth_setup_scenarios.py
index 5c737cb24..96b5845d8 100644
--- a/tests/test_agent_auth_setup_scenarios.py
+++ b/tests/test_agent_auth_setup_scenarios.py
@@ -12,6 +12,72 @@ from tests.scenario_harness.core import ScenarioExpect, ScenarioRunner, Scenario
class AgentAuthSetupScenarioTests(unittest.IsolatedAsyncioTestCase):
+ async def test_codex_failure_scenario_emits_reset_path(self):
+ harness = AuthSetupScenarioHarness()
+ fake_process = FakeProcess()
+ runner = ScenarioRunner(harness)
+ harness.service._start_codex_process = AsyncMock(return_value=fake_process)
+ harness.service._read_codex_output = AsyncMock(return_value=None)
+ harness.service._verify_login = AsyncMock(return_value=(False, "not logged in"))
+ harness.service._refresh_backend_runtime = AsyncMock()
+
+ await runner.run(
+ ScenarioStep(
+ "start_setup",
+ lambda h: h.service.start_setup(h.context, backend="codex", force_reset=True),
+ ),
+ ScenarioStep(
+ "emit_device_url",
+ lambda h: h.service._handle_process_text(
+ h.context,
+ "codex",
+ "Open this URL to authenticate: https://auth.openai.com/codex/device",
+ ),
+ ),
+ )
+
+ fake_process.finish(0)
+ await harness.flow("codex").waiter_task
+
+ harness.service._refresh_backend_runtime.assert_not_awaited()
+ ScenarioExpect.step_history(runner, ["start_setup", "emit_device_url"])
+ ScenarioExpect.text_contains(harness, "failed")
+ ScenarioExpect.text_contains(harness, "not logged in")
+ ScenarioExpect.button_callback_contains(harness, "auth_setup:codex")
+ ScenarioExpect.flow_missing(harness, "C1:codex")
+
+ async def test_codex_reentry_scenario_replaces_existing_flow(self):
+ harness = AuthSetupScenarioHarness()
+ first_process = FakeProcess()
+ second_process = FakeProcess()
+ runner = ScenarioRunner(harness)
+ harness.service._start_codex_process = AsyncMock(side_effect=[first_process, second_process])
+ harness.service._read_codex_output = AsyncMock(return_value=None)
+
+ await runner.run(
+ ScenarioStep(
+ "start_first_setup",
+ lambda h: h.service.start_setup(h.context, backend="codex", force_reset=True),
+ ),
+ )
+ first_flow = harness.flow("codex")
+ self.assertFalse(first_flow.waiter_task.done())
+
+ await runner.run(
+ ScenarioStep(
+ "start_second_setup",
+ lambda h: h.service.start_setup(h.context, backend="codex", force_reset=True),
+ ),
+ )
+
+ second_flow = harness.flow("codex")
+ self.assertIsNot(first_flow, second_flow)
+ self.assertTrue(first_flow.waiter_task.cancelled())
+ self.assertGreaterEqual(first_process.terminate_calls, 1)
+ ScenarioExpect.step_history(runner, ["start_first_setup", "start_second_setup"])
+ ScenarioExpect.text_contains(harness, "starting codex", index=0)
+ ScenarioExpect.text_contains(harness, "starting codex", index=1)
+
async def test_codex_device_auth_scenario_reaches_terminal_success(self):
harness = AuthSetupScenarioHarness()
fake_process = FakeProcess()
@@ -153,6 +219,32 @@ class AgentAuthSetupScenarioTests(unittest.IsolatedAsyncioTestCase):
ScenarioExpect.text_contains(harness, "opencode login is active again")
ScenarioExpect.flow_missing(harness, "C1:opencode")
+ async def test_opencode_waiting_key_scenario_ignores_plain_chat(self):
+ harness = AuthSetupScenarioHarness()
+ runner = ScenarioRunner(harness)
+ harness.service._resolve_opencode_provider = AsyncMock(return_value="opencode")
+ harness.service._install_opencode_api_key = AsyncMock()
+ harness.service._refresh_backend_runtime = AsyncMock()
+ harness.service._clear_backend_sessions_for_context = AsyncMock()
+
+ await runner.run(
+ ScenarioStep(
+ "start_setup",
+ lambda h: h.service.start_setup(h.context, backend="opencode", force_reset=True),
+ ),
+ )
+ flow = harness.flow("opencode")
+ self.assertTrue(flow.awaiting_code)
+ before_count = len(harness.rendered_texts())
+
+ consumed = await harness.service.maybe_consume_setup_reply(harness.context, "hello world")
+
+ self.assertFalse(consumed)
+ self.assertTrue(flow.awaiting_code)
+ self.assertEqual(len(harness.rendered_texts()), before_count)
+ harness.service._install_opencode_api_key.assert_not_awaited()
+ ScenarioExpect.step_history(runner, ["start_setup"])
+
if __name__ == "__main__":
unittest.main()