Files
hkuds--openharness/tests/test_ui/test_runtime_api_key.py
T
tjb-tech b9bfb0520e Merge PR #38: show friendly error on missing API key instead of traceback
Adapted to main's _resolve_api_client_from_settings() architecture.
Added _safe_resolve_auth() wrapper that catches ValueError and prints
a clear message before SystemExit(1).

Co-authored-by: José Maia <glitch-ux@users.noreply.github.com>
2026-04-07 12:06:47 +00:00

28 lines
927 B
Python

"""Tests for build_runtime behaviour when no API key is configured."""
from __future__ import annotations
import pytest
from openharness.ui.runtime import build_runtime
@pytest.mark.asyncio
async def test_build_runtime_exits_cleanly_when_api_key_missing(monkeypatch):
"""build_runtime should raise SystemExit(1) — not ValueError — when no API key is set."""
monkeypatch.delenv("ANTHROPIC_API_KEY", raising=False)
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
with pytest.raises(SystemExit, match="1"):
await build_runtime()
@pytest.mark.asyncio
async def test_build_runtime_exits_cleanly_for_openai_format(monkeypatch):
"""Same check for the openai api_format path."""
monkeypatch.delenv("ANTHROPIC_API_KEY", raising=False)
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
with pytest.raises(SystemExit, match="1"):
await build_runtime(api_format="openai")