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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
"""Unit tests for the pure section-health rollup core.
Guards the two pure functions the ``/api/providers/section-health`` endpoint
composes, plus the status vocabulary itself. The I/O orchestration (resolving the
active provider, running the real connectivity test) is exercised separately; here
we only pin the rules so the tab indicator can never silently change meaning.
"""
from __future__ import annotations
from types import SimpleNamespace
import pytest
from dodaios.brain import provider_test
from dodaios.brain import section_health as sh
from dodaios.ui.web.provider_spec import PROVIDERS
class TestSectionStatusForTest:
def test_missing_credential_is_needs_setup_regardless_of_test(self) -> None:
# No key stored → the tab is "not set up", even if a stale test string is
# passed in. Missing always wins over any test outcome.
assert sh.section_status_for_test(None, configured=False) == sh.NEEDS_SETUP
assert sh.section_status_for_test("ok", configured=False) == sh.NEEDS_SETUP
assert sh.section_status_for_test("bad_key", configured=False) == sh.NEEDS_SETUP
def test_configured_and_ok_is_ok(self) -> None:
assert sh.section_status_for_test("ok", configured=True) == sh.OK
def test_configured_but_not_tested_is_unknown(self) -> None:
# Honesty: a stored key we haven't called yet must not claim "ok".
assert sh.section_status_for_test(None, configured=True) == sh.UNKNOWN
def test_test_not_configured_is_needs_setup(self) -> None:
# The live call itself found no key — treat as not set up, never a red error.
assert sh.section_status_for_test("not_configured", configured=True) == sh.NEEDS_SETUP
@pytest.mark.parametrize(
"bad",
["bad_key", "no_credits", "rate_limited", "model_unavailable", "unreachable", "error"],
)
def test_every_failing_test_status_is_error(self, bad: str) -> None:
assert sh.section_status_for_test(bad, configured=True) == sh.ERROR
def test_covers_every_provider_test_status(self) -> None:
# Anti-drift: every status the provider test can emit must map to a
# defined section bucket (no unmapped/silently-dropped outcome).
for status in provider_test.PROVIDER_TEST_STATUSES:
mapped = sh.section_status_for_test(status, configured=True)
assert mapped in sh.SECTION_HEALTH_STATUSES
class TestAggregate:
def test_empty_is_unknown(self) -> None:
assert sh.aggregate([]) == sh.UNKNOWN
def test_single_passthrough(self) -> None:
assert sh.aggregate([sh.OK]) == sh.OK
assert sh.aggregate([sh.NEEDS_SETUP]) == sh.NEEDS_SETUP
def test_error_beats_everything(self) -> None:
assert sh.aggregate([sh.OK, sh.NEEDS_SETUP, sh.ERROR]) == sh.ERROR
assert sh.aggregate([sh.ERROR, sh.UNKNOWN]) == sh.ERROR
def test_needs_setup_beats_ok_and_unknown(self) -> None:
assert sh.aggregate([sh.OK, sh.NEEDS_SETUP]) == sh.NEEDS_SETUP
assert sh.aggregate([sh.UNKNOWN, sh.NEEDS_SETUP]) == sh.NEEDS_SETUP
def test_ok_beats_unknown(self) -> None:
assert sh.aggregate([sh.UNKNOWN, sh.OK]) == sh.OK
class TestSectionStatusForOutcome:
"""A remembered real-call outcome, unlike a fresh probe, may be minutes
old: what clears on its own is amber, only what does not is red."""
@pytest.mark.parametrize("transient", ["rate_limited", "unreachable"])
def test_transient_outcomes_are_amber(self, transient: str) -> None:
assert sh.section_status_for_outcome(transient) == sh.NEEDS_SETUP
@pytest.mark.parametrize("hard", ["bad_key", "no_credits", "model_unavailable", "error"])
def test_lasting_failures_are_red(self, hard: str) -> None:
assert sh.section_status_for_outcome(hard) == sh.ERROR
def test_ok_is_ok(self) -> None:
assert sh.section_status_for_outcome("ok") == sh.OK
def test_vocabulary_is_exactly_four() -> None:
assert set(sh.SECTION_HEALTH_STATUSES) == {sh.OK, sh.NEEDS_SETUP, sh.ERROR, sh.UNKNOWN}
assert len(sh.SECTION_HEALTH_STATUSES) == 4
@pytest.mark.asyncio
@pytest.mark.parametrize("spec", PROVIDERS, ids=lambda spec: spec.id)
async def test_every_catalog_provider_health_is_bound_to_its_exact_id(
spec, monkeypatch: pytest.MonkeyPatch
) -> None:
"""The generic guard covers every Brain, TTS, STT, Realtime and wording card.
What is under test is the BINDING (a tier's health names the exact provider
it came from), so every way a card can be judged reads healthy here: a
recorded real-call success for its modality, the on-device readiness check
that answers for keyless cards, and credential presence for the wording
tier. No card may reach a provider on the way — the recorder proves it.
"""
from dodaios import codex_app_server
from dodaios.brain import provider_health_ledger as ledger
from dodaios.ui.web import provider_routes
from tests.fakes.fake_provider_calls import ProviderCallRecorder
recorder = ProviderCallRecorder().install(monkeypatch)
monkeypatch.setattr(provider_routes, "_is_credential_present", lambda *args: True)
async def _subscription_ready(_binary_path=None):
return True
monkeypatch.setattr(
codex_app_server,
"codex_subscription_login_ready",
_subscription_ready,
)
# The subscription-realtime card is judged from a live status snapshot of the
# local Codex app-server, not from a stored credential. Left unstubbed that is
# a real call to whatever machine runs the suite: it answers "busy" while a
# status check is in flight and "not_installed" on a host without the CLI, so
# the card would be graded on this machine's Codex state instead of on the
# binding under test.
monkeypatch.setattr(
provider_routes,
"_codex_subscription_status_payload",
lambda _binary_path=None: {"connected": True, "reason_code": None},
)
# On-device cards ask the disk whether engine + weights are really there.
# On a machine that never installed them that is an honest "needs setup" —
# true, and not what this test is about.
monkeypatch.setattr(
provider_routes,
"_local_runtime_payload",
lambda _spec: {"ready": True, "detail": "installed"},
)
modality = ledger.modality_for_tier(spec.tier)
if modality is not None:
ledger.get_ledger().record(spec.id, modality, provider_test.OK)
result = await provider_routes._tier_section_health(
SimpleNamespace(), spec, modality=modality
)
assert result.status == sh.OK
assert result.subject_id == spec.id
assert recorder.calls == []
def test_health_fingerprint_covers_every_model_selection_surface() -> None:
"""Every model-bearing API surface supersedes an older health snapshot."""
from dodaios.ui.web import provider_routes as pr
# ``tool_model`` is the canonical Tool-Model field; the real
# BrainProviderConfig exposes ``cu_model`` only as a property alias of it,
# so the fingerprint reads (and this fake carries) the canonical name.
openrouter = SimpleNamespace(model="brain-a", tool_model="cu-a")
realtime = SimpleNamespace(model="realtime-a", voice="voice-a")
cfg = SimpleNamespace(
brain=SimpleNamespace(
providers={"openrouter": openrouter, "openai-realtime": realtime},
worker=SimpleNamespace(model="worker-a"),
),
tts=SimpleNamespace(model="tts-a", voice_de="de-a", voice_en="en-a"),
stt=SimpleNamespace(model="stt-a"),
)
request = SimpleNamespace(
app=SimpleNamespace(state=SimpleNamespace(telephony_manager=None))
)
subjects = {
"brain": "openrouter",
"computer-use": "openrouter",
"tts": "openrouter-tts",
"stt": "openrouter-stt",
"realtime": "openai-realtime",
"subagents": "openrouter",
"advanced": None,
}
baseline = pr._section_health_fingerprint(request, cfg, subjects)
mutations = (
(openrouter, "model"),
(openrouter, "tool_model"),
(cfg.tts, "model"),
(cfg.tts, "voice_de"),
(cfg.tts, "voice_en"),
(cfg.stt, "model"),
(realtime, "model"),
(realtime, "voice"),
(cfg.brain.worker, "model"),
)
for owner, field in mutations:
original = getattr(owner, field)
setattr(owner, field, f"{original}-changed")
assert pr._section_health_fingerprint(request, cfg, subjects) != baseline
setattr(owner, field, original)
cfg.tts.model_extra = {"cartesia": {"model_id": "sonic-new"}}
assert pr._section_health_fingerprint(request, cfg, subjects) != baseline
class TestSubagentSectionHealth:
"""Live-honest Sub-Agents tab health (2026-07-06 incident: the tab stayed
green while every worker spawn 401'd on an expired OAuth token)."""
def _cfg(self, provider: str = "claude-api"):
class _Sub: # minimal cfg.brain.worker stand-in
pass
sub = _Sub()
sub.provider = provider
class _Brain:
worker = sub
primary = "openrouter"
class _Cfg:
brain = _Brain()
return _Cfg()
def test_selected_usable_is_ok(self, monkeypatch) -> None:
from dodaios.ui.web import provider_routes as pr
monkeypatch.setattr(pr, "_worker_usable", lambda p: True)
monkeypatch.setattr(pr, "_worker_flagged_dead", lambda p: False)
health = pr._jarvis_agent_section_health(self._cfg())
assert health.status == sh.OK
assert health.subject_id == "claude-api"
def test_selected_dead_with_fallback_is_needs_setup(self, monkeypatch) -> None:
from dodaios.ui.web import provider_routes as pr
monkeypatch.setattr(pr, "_worker_usable", lambda p: True)
monkeypatch.setattr(pr, "_worker_flagged_dead", lambda p: True)
monkeypatch.setattr(
"dodaios.missions.init.reachable_worker_families", lambda: ["codex"]
)
health = pr._jarvis_agent_section_health(self._cfg())
assert health.status == sh.NEEDS_SETUP
assert health.reason == "degraded"
assert "codex" in health.detail
def test_usage_capped_codex_selected_is_degraded(self, monkeypatch) -> None:
"""BUG-042 shape: selected provider codex, ChatGPT usage cap active —
the tab must NOT stay green while the factory skips codex."""
from dodaios.ui.web import provider_routes as pr
monkeypatch.setattr(pr, "_worker_usable", lambda p: True)
monkeypatch.setattr(
"dodaios.codex_auth_state.codex_needs_reauth", lambda: False
)
monkeypatch.setattr(
"dodaios.codex_quota_state.codex_in_quota_cooldown",
lambda **_k: True,
)
monkeypatch.setattr(
"dodaios.missions.init.reachable_worker_families", lambda: ["openrouter"]
)
health = pr._jarvis_agent_section_health(self._cfg(provider="codex"))
assert health.status == sh.NEEDS_SETUP
assert health.reason == "degraded"
def test_nothing_reachable_is_error(self, monkeypatch) -> None:
from dodaios.ui.web import provider_routes as pr
monkeypatch.setattr(pr, "_worker_usable", lambda p: False)
monkeypatch.setattr(pr, "_worker_flagged_dead", lambda p: False)
monkeypatch.setattr(
"dodaios.missions.init.reachable_worker_families", lambda: []
)
health = pr._jarvis_agent_section_health(self._cfg())
assert health.status == sh.ERROR
assert health.reason == "no_provider"
assert health.subject_id == "claude-api"
def test_degraded_label_says_subscription_for_oauth_user(
self, monkeypatch, tmp_path
) -> None:
"""2026-07-10 report: the banner blamed 'Claude (API-Key)' although the
user runs the worker on the Claude subscription login — the degraded
message must name the auth mode actually in play."""
import json
from dodaios import claude_credentials
from dodaios.claude_auth import ClaudeAuthService, ClaudeAuthStatus
from dodaios.ui.web import provider_routes as pr
(tmp_path / ".credentials.json").write_text(
json.dumps(
{
"claudeAiOauth": {
"accessToken": "sk-ant-oat01-x",
"expiresAt": 1.0, # expired-in-place — still an OAuth user
}
}
),
encoding="utf-8",
)
monkeypatch.setattr(
claude_credentials, "claude_config_dirs", lambda: [tmp_path]
)
monkeypatch.setattr(
ClaudeAuthService,
"status",
lambda self: ClaudeAuthStatus(installed=True, connected=False),
)
monkeypatch.setattr(pr, "_worker_usable", lambda p: False)
monkeypatch.setattr(pr, "_worker_flagged_dead", lambda p: True)
monkeypatch.setattr(
"dodaios.missions.init.reachable_worker_families", lambda: ["codex"]
)
health = pr._jarvis_agent_section_health(self._cfg())
assert "Claude (subscription)" in health.detail
assert "API-Key" not in health.detail
def test_degraded_label_keeps_api_key_for_keyed_user(
self, monkeypatch, tmp_path
) -> None:
from dodaios import claude_credentials
from dodaios.claude_auth import ClaudeAuthService, ClaudeAuthStatus
from dodaios.ui.web import provider_routes as pr
# No OAuth bearer anywhere → the user really is on the API-key path.
monkeypatch.setattr(
claude_credentials, "claude_config_dirs", lambda: [tmp_path]
)
monkeypatch.setattr(
ClaudeAuthService,
"status",
lambda self: ClaudeAuthStatus(installed=True, connected=False),
)
monkeypatch.setattr(pr, "_worker_usable", lambda p: False)
monkeypatch.setattr(pr, "_worker_flagged_dead", lambda p: True)
monkeypatch.setattr(
"dodaios.missions.init.reachable_worker_families", lambda: ["codex"]
)
health = pr._jarvis_agent_section_health(self._cfg())
assert "Claude (API-Key)" in health.detail
def _gpt_live_config(mode: str = "realtime") -> SimpleNamespace:
return SimpleNamespace(
voice=SimpleNamespace(mode=mode),
brain=SimpleNamespace(realtime=SimpleNamespace(provider="openai-live")),
)
async def _section_modalities(monkeypatch, cfg) -> dict[str, str | None]:
"""Run the rollup with every check stubbed; return each tier's modality."""
from dodaios.ui.web import provider_routes as pr
seen: dict[str, str | None] = {}
async def _tier(cfg, spec, *, modality=None, **kwargs):
if spec is not None:
seen[spec.id] = modality
return pr.SectionHealth(status=sh.OK, reason="ok")
def _sync_other(*args, **kwargs):
return pr.SectionHealth(status=sh.OK, reason="ok")
monkeypatch.setattr(pr, "_tier_section_health", _tier)
monkeypatch.setattr(pr, "_jarvis_agent_section_health", _sync_other)
monkeypatch.setattr(pr, "_advanced_section_health", _sync_other)
monkeypatch.setattr(pr, "_local_models_section_health", _sync_other)
monkeypatch.setattr(pr, "_codex_binary_path", lambda request: None)
monkeypatch.setattr(pr, "_polish_enabled", lambda cfg: False)
subjects = {key: None for key in pr._SECTION_HEALTH_KEYS}
subjects.update(
{
"brain": "openai",
"computer-use": "grok",
"tts": "elevenlabs",
"stt": "groq-api",
"realtime": "openai-live",
}
)
await pr._compute_section_health(SimpleNamespace(), cfg, subjects)
return seen
@pytest.mark.asyncio
async def test_every_tier_reads_its_own_real_call_outcomes(monkeypatch) -> None:
"""Each tab is judged by the record of ITS calls: brain turns for Brain,
tool-model steps for Tool Model, spoken sentences, transcriptions and
realtime handshakes — never by a probe of the page's own (2026-09-30)."""
from dodaios.brain import provider_health_ledger as ledger
seen = await _section_modalities(monkeypatch, _gpt_live_config())
assert seen == {
"openai": ledger.MODALITY_BRAIN,
"grok": ledger.MODALITY_TOOL,
"elevenlabs": ledger.MODALITY_TTS,
"groq-api": ledger.MODALITY_STT,
"openai-live": ledger.MODALITY_REALTIME,
}
@pytest.mark.asyncio
async def test_a_keyed_provider_never_used_is_silent_not_red(monkeypatch) -> None:
"""Credential present, no real call since: ``unknown`` — no dot, no probe."""
from dodaios.brain import provider_health_ledger as ledger
from dodaios.ui.web import provider_routes as pr
from tests.fakes.fake_provider_calls import ProviderCallRecorder
recorder = ProviderCallRecorder().install(monkeypatch)
monkeypatch.setattr(pr, "_is_credential_present", lambda *args: True)
health = await pr._tier_section_health(
None, pr.get_spec("elevenlabs"), modality=ledger.MODALITY_TTS
)
assert health.status == sh.UNKNOWN
assert health.reason == pr.UNVERIFIED_REASON
assert recorder.calls == []
@pytest.mark.asyncio
async def test_a_login_based_provider_is_ok_on_its_login(monkeypatch) -> None:
"""A signed-in CLI login is the whole verdict (the Test button gives no more)."""
from dodaios.brain import provider_health_ledger as ledger
from dodaios.ui.web import provider_routes as pr
monkeypatch.setattr(pr, "_is_credential_present", lambda *args: True)
health = await pr._tier_section_health(
None, pr.get_spec("codex"), modality=ledger.MODALITY_BRAIN
)
assert health.status == sh.OK
assert health.reason == "connected"
def test_passive_health_polls_reuse_the_cache_for_minutes() -> None:
"""Sidebar and dock read this in every window and every build reloads every
window; the credential/login reads behind it are cached for minutes."""
from dodaios.ui.web import provider_routes as pr
assert pr._SECTION_HEALTH_TTL_S >= 15 * 60
def test_a_new_real_call_outcome_supersedes_the_cached_rollup() -> None:
from dodaios.brain import provider_health_ledger as ledger
from dodaios.ui.web import provider_routes as pr
cfg = SimpleNamespace(brain=SimpleNamespace(providers={}))
request = SimpleNamespace(
app=SimpleNamespace(state=SimpleNamespace(telephony_manager=None))
)
subjects = {key: None for key in pr._SECTION_HEALTH_KEYS}
before = pr._section_health_fingerprint(request, cfg, subjects)
ledger.get_ledger().record("openai", ledger.MODALITY_BRAIN, provider_test.BAD_KEY)
assert pr._section_health_fingerprint(request, cfg, subjects) != before
@pytest.mark.asyncio
async def test_composer_health_reads_the_record_and_sends_nothing(monkeypatch) -> None:
"""The agent-chat composer used to spend one paid completion per keyed
provider on every open. It now reads the same record the tabs read."""
from dodaios.brain import provider_health_ledger as ledger
from dodaios.ui.web import provider_routes as pr
from tests.fakes.fake_provider_calls import ProviderCallRecorder
recorder = ProviderCallRecorder().install(monkeypatch)
monkeypatch.setattr(pr, "_is_credential_present", lambda *args: True)
ledger.get_ledger().record("grok", ledger.MODALITY_BRAIN, provider_test.NO_CREDITS)
cfg = _gpt_live_config()
grok = await pr.provider_health(cfg, "grok")
openai = await pr.provider_health(cfg, "openai")
assert (grok.status, grok.reason) == (sh.ERROR, provider_test.NO_CREDITS)
assert (openai.status, openai.reason) == (sh.UNKNOWN, pr.UNVERIFIED_REASON)
assert recorder.calls == []