Skip to content

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.

2.1 KB
Raw Blame
"""Gemini Live credential aliases stay aligned across factory and UI paths."""

from __future__ import annotations

import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient

from dodaios.brain.app_control import AUTH_PROVIDER_ALIASES, is_credential_present
from dodaios.core import config as cfg_mod
from dodaios.core.config import PROVIDER_SECRET_CANDIDATES, JarvisConfig
from dodaios.plugins.realtime.gemini_live import GeminiLiveProvider
from dodaios.ui.web.provider_routes import router
from dodaios.ui.web.provider_spec import get_spec


def test_gemini_live_adapter_credentials_match_canonical_family() -> None:
    assert GeminiLiveProvider.credential_candidates == PROVIDER_SECRET_CANDIDATES[
        "gemini-live"
    ]
    assert AUTH_PROVIDER_ALIASES["gemini-live"] == "gemini-live"


def test_grok_realtime_stays_removed() -> None:
    """grok-realtime was removed 2026-07-16 (BUG-064 deaf-session wedge):
    the xAI server drops its session contract after any response cancel.
    Neither the credential registry nor the auth alias map may resurrect it."""
    assert "grok-realtime" not in PROVIDER_SECRET_CANDIDATES
    assert "grok-realtime" not in AUTH_PROVIDER_ALIASES


@pytest.mark.parametrize(
    "available_slot",
    ["gemini_api_key", "google_aistudio_api_key", "google_api_key"],
)
def test_gemini_live_provider_spec_and_switch_accept_every_alias(
    monkeypatch: pytest.MonkeyPatch,
    available_slot: str,
) -> None:
    def fake_get_secret(
        key: str, env_fallback: str | None = None
    ) -> str | None:
        return "AIza-test" if key == available_slot else None

    monkeypatch.setattr(cfg_mod, "get_secret", fake_get_secret)
    spec = get_spec("gemini-live")
    assert spec is not None
    assert is_credential_present(spec) is True

    app = FastAPI()
    app.include_router(router)
    app.state.config = JarvisConfig()
    response = TestClient(app).post(
        "/api/realtime/switch",
        json={"provider": "gemini-live", "persist": False},
    )

    assert response.status_code == 200
    assert response.json()["active"] == "gemini-live"