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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
test(auth): extract scenario harness primitives
cyhb6fa39276d03
diff --git a/docs/regression/AUTH_SETUP_SCENARIOS.md b/docs/regression/AUTH_SETUP_SCENARIOS.mdindex 0c6bc3a41..37b7228c7 100644--- a/docs/regression/AUTH_SETUP_SCENARIOS.md+++ b/docs/regression/AUTH_SETUP_SCENARIOS.md@@ -28,8 +28,9 @@ The preferred pattern is:1. keep production code changes small2. add a focused scenario test under `tests/test_agent_auth_setup_scenarios.py`-3. use fake process / fake control client / fake IM client transcripts-4. drive the real public service methods (`start_setup`, `maybe_consume_setup_reply`, `submit_code`) whenever practical+3. reuse shared test primitives from `tests/scenario_harness/` before creating new one-off fakes+4. use fake process / fake control client / fake IM client transcripts+5. drive the real public service methods (`start_setup`, `maybe_consume_setup_reply`, `submit_code`) whenever practicalIf a new helper is only needed by one scenario, keep it local to the test file.@@ -49,6 +50,14 @@ When changing auth/setup behavior, add or update at least one closed-loop scenarFor any backend-specific auth flow, the default target is one happy-path scenario plus unit tests for branchy edge cases.+## Current Project Mapping++Reference implementation currently lives in:++- `tests/scenario_harness/`+- `tests/test_agent_auth_setup_scenarios.py`+- `docs/regression/AUTH_SETUP_SCENARIOS.md`+## Current Scenario Matrix- Codex device auth:diff --git a/tests/scenario_harness/README.md b/tests/scenario_harness/README.mdnew file mode 100644index 000000000..f8a4af9f0--- /dev/null+++ b/tests/scenario_harness/README.md@@ -0,0 +1,15 @@+# Scenario Harness++This package holds reusable test-side primitives for capability-level scenario tests.++Rules:++- keep these helpers lightweight+- prefer service-boundary simulation over full E2E machinery+- only promote a fake or helper here after at least one real scenario proves the reuse+- keep provider-specific parsing logic out of this layer++Current contents:++- `auth_setup.py`+ Shared harness primitives for IM-driven auth/setup scenariosdiff --git a/tests/scenario_harness/__init__.py b/tests/scenario_harness/__init__.pynew file mode 100644index 000000000..bf71195f1--- /dev/null+++ b/tests/scenario_harness/__init__.py@@ -0,0 +1 @@+"""Reusable scenario-harness primitives for capability-level tests."""diff --git a/tests/scenario_harness/auth_setup.py b/tests/scenario_harness/auth_setup.pynew file mode 100644index 000000000..8d79ff2d2--- /dev/null+++ b/tests/scenario_harness/auth_setup.py@@ -0,0 +1,99 @@+import asyncio+from types import SimpleNamespace+from unittest.mock import AsyncMock++from core.agent_auth_service import AgentAuthService+from modules.im import MessageContext+++class ScenarioIMClient:+ """Capture user-visible outputs emitted during a scenario run."""++ def __init__(self):+ self.events = []++ async def send_message(self, context, text, parse_mode=None):+ self.events.append(("message", text))+ return f"msg-{len(self.events)}"++ async def send_message_with_buttons(self, context, text, keyboard, parse_mode=None):+ self.events.append(("buttons", text, keyboard))+ return f"btn-{len(self.events)}"++ def rendered_texts(self):+ return [event[1] for event in self.events]+++class ScenarioController:+ """Minimal controller surface for AgentAuthService scenario tests."""++ def __init__(self):+ self.config = SimpleNamespace(+ platform="slack",+ language="en",+ agents=SimpleNamespace(+ codex=SimpleNamespace(cli_path="codex"),+ claude=SimpleNamespace(cli_path="claude"),+ opencode=SimpleNamespace(cli_path="opencode"),+ ),+ )+ self.im_client = ScenarioIMClient()+ self.agent_service = SimpleNamespace(agents={})+ self.sessions = SimpleNamespace(get_agent_session_id=lambda *args, **kwargs: None)+ self.session_handler = SimpleNamespace(+ get_session_info=lambda context: ("base-1", "/tmp/workdir", "base-1:/tmp/workdir"),+ get_working_path=lambda context: "/tmp/workdir",+ )++ def get_im_client_for_context(self, context):+ return self.im_client++ def _get_settings_key(self, context):+ return context.channel_id++ def _get_lang(self):+ return "en"++ def resolve_agent_for_context(self, context):+ return "codex"++ def get_opencode_overrides(self, context):+ return (None, None, None)+++class FakeProcess:+ """Simple completion-controlled process stub for setup flows."""++ def __init__(self):+ self.returncode = None+ self.stdout = SimpleNamespace(readline=AsyncMock(return_value=b""))+ self._done = asyncio.Event()++ async def wait(self):+ await self._done.wait()+ return self.returncode++ def finish(self, returncode=0):+ self.returncode = returncode+ self._done.set()++ def terminate(self):+ self.finish(-15)++ def kill(self):+ self.finish(-9)+++class AuthSetupScenarioHarness:+ """Reusable harness for capability-level auth/setup scenarios."""++ def __init__(self):+ self.controller = ScenarioController()+ self.service = AgentAuthService(self.controller)+ self.context = MessageContext(user_id="U1", channel_id="C1")++ def flow(self, backend: str):+ return self.service._flows[f"C1:{backend}"]++ def rendered_texts(self):+ return self.controller.im_client.rendered_texts()diff --git a/tests/test_agent_auth_setup_scenarios.py b/tests/test_agent_auth_setup_scenarios.pyindex a80d8b3fd..3119d7b3b 100644--- a/tests/test_agent_auth_setup_scenarios.py+++ b/tests/test_agent_auth_setup_scenarios.py@@ -2,105 +2,18 @@ import asyncioimport sysimport unittestfrom pathlib import Path-from types import SimpleNamespacefrom unittest.mock import AsyncMockROOT = Path(__file__).resolve().parents[1]sys.path.insert(0, str(ROOT))-from core.agent_auth_service import AgentAuthService-from modules.im import MessageContext---class _ScenarioIMClient:- def __init__(self):- self.events = []-- async def send_message(self, context, text, parse_mode=None):- self.events.append(("message", text))- return f"msg-{len(self.events)}"-- async def send_message_with_buttons(self, context, text, keyboard, parse_mode=None):- self.events.append(("buttons", text, keyboard))- return f"btn-{len(self.events)}"-- def rendered_texts(self):- return [event[1] for event in self.events]---class _ScenarioController:- def __init__(self):- self.config = SimpleNamespace(- platform="slack",- language="en",- agents=SimpleNamespace(- codex=SimpleNamespace(cli_path="codex"),- claude=SimpleNamespace(cli_path="claude"),- opencode=SimpleNamespace(cli_path="opencode"),- ),- )- self.im_client = _ScenarioIMClient()- self.agent_service = SimpleNamespace(agents={})- self.sessions = SimpleNamespace(get_agent_session_id=lambda *args, **kwargs: None)- self.session_handler = SimpleNamespace(- get_session_info=lambda context: ("base-1", "/tmp/workdir", "base-1:/tmp/workdir"),- get_working_path=lambda context: "/tmp/workdir",- )-- def get_im_client_for_context(self, context):- return self.im_client-- def _get_settings_key(self, context):- return context.channel_id-- def _get_lang(self):- return "en"-- def resolve_agent_for_context(self, context):- return "codex"-- def get_opencode_overrides(self, context):- return (None, None, None)---class _FakeProcess:- def __init__(self):- self.returncode = None- self.stdout = SimpleNamespace(readline=AsyncMock(return_value=b""))- self._done = asyncio.Event()-- async def wait(self):- await self._done.wait()- return self.returncode-- def finish(self, returncode=0):- self.returncode = returncode- self._done.set()-- def terminate(self):- self.finish(-15)-- def kill(self):- self.finish(-9)---class _SetupScenarioHarness:- def __init__(self):- self.controller = _ScenarioController()- self.service = AgentAuthService(self.controller)- self.context = MessageContext(user_id="U1", channel_id="C1")-- def flow(self, backend: str):- return self.service._flows[f"C1:{backend}"]-- def rendered_texts(self):- return self.controller.im_client.rendered_texts()+from tests.scenario_harness.auth_setup import AuthSetupScenarioHarness, FakeProcessclass AgentAuthSetupScenarioTests(unittest.IsolatedAsyncioTestCase):async def test_codex_device_auth_scenario_reaches_terminal_success(self):- harness = _SetupScenarioHarness()- fake_process = _FakeProcess()+ harness = AuthSetupScenarioHarness()+ fake_process = FakeProcess()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=(True, "Logged in using ChatGPT"))@@ -134,7 +47,7 @@ class AgentAuthSetupScenarioTests(unittest.IsolatedAsyncioTestCase):self.assertNotIn("C1:codex", harness.service._flows)async def test_claude_manual_callback_scenario_accepts_plain_reply_and_completes(self):- harness = _SetupScenarioHarness()+ harness = AuthSetupScenarioHarness()fake_client = object()completion_released = asyncio.Event()callback_payloads = []@@ -187,7 +100,7 @@ class AgentAuthSetupScenarioTests(unittest.IsolatedAsyncioTestCase):self.assertNotIn("C1:claude", harness.service._flows)async def test_opencode_direct_key_scenario_installs_key_and_refreshes_runtime(self):- harness = _SetupScenarioHarness()+ harness = AuthSetupScenarioHarness()harness.service._resolve_opencode_provider = AsyncMock(return_value="opencode")harness.service._install_opencode_api_key = AsyncMock()harness.service._refresh_backend_runtime = AsyncMock()