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.

2.5 KB
Raw Blame
from __future__ import annotations

from functools import partial
from types import SimpleNamespace
from unittest.mock import patch

from vibe import cli
from vibe.runtime import ProcessStartInfo


def _config_with_setup_state(*, ready: bool) -> SimpleNamespace:
    return SimpleNamespace(
        ui=SimpleNamespace(setup_host="127.0.0.1", setup_port=5123, open_browser=False),
        slack=SimpleNamespace(bot_token=""),
        has_configured_platform_credentials=lambda: ready,
    )


def _start_process(pid: int, *args, start_info: ProcessStartInfo, **kwargs) -> int:
    start_info.pid = pid
    start_info.reused = False
    return pid


def test_cmd_vibe_marks_setup_when_no_enabled_platform_has_credentials(capsys) -> None:
    config = _config_with_setup_state(ready=False)

    with (
        patch("vibe.cli.paths.ensure_data_dirs"),
        patch("vibe.cli._ensure_config", return_value=config),
        patch("vibe.cli.runtime.stop_service") as stop_service,
        patch("vibe.cli.runtime.stop_ui") as stop_ui,
        patch("vibe.cli.runtime.start_service", side_effect=partial(_start_process, 101)),
        patch("vibe.cli.runtime.start_ui", side_effect=partial(_start_process, 202)),
        patch("vibe.cli.runtime.wait_for_service_ready", return_value=101),
        patch("vibe.cli.runtime.write_status"),
        patch("vibe.cli._write_status") as write_status,
    ):
        cli.cmd_vibe()

    stop_service.assert_not_called()
    stop_ui.assert_not_called()
    write_status.assert_called_once_with("setup", "missing platform credentials")
    output = capsys.readouterr().out
    assert "Run: vibe remote" in output
    assert "SSH port forwarding" not in output


def test_cmd_vibe_marks_starting_when_non_slack_platform_is_configured() -> None:
    config = _config_with_setup_state(ready=True)

    with (
        patch("vibe.cli.paths.ensure_data_dirs"),
        patch("vibe.cli._ensure_config", return_value=config),
        patch("vibe.cli.runtime.stop_service") as stop_service,
        patch("vibe.cli.runtime.stop_ui") as stop_ui,
        patch("vibe.cli.runtime.start_service", side_effect=partial(_start_process, 101)),
        patch("vibe.cli.runtime.start_ui", side_effect=partial(_start_process, 202)),
        patch("vibe.cli.runtime.wait_for_service_ready", return_value=101),
        patch("vibe.cli.runtime.write_status"),
        patch("vibe.cli._write_status") as write_status,
    ):
        cli.cmd_vibe()

    stop_service.assert_not_called()
    stop_ui.assert_not_called()
    write_status.assert_called_once_with("starting")