Files
wehub-resource-sync 0418dc5cf9
CI / Python tests (3.10) (push) Has been cancelled
CI / Python tests (3.11) (push) Has been cancelled
CI / Python quality (push) Has been cancelled
CI / Frontend typecheck (push) Has been cancelled
Autopilot Pages / deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:45:00 +08:00

50 lines
1.8 KiB
Python

"""Tests for build_runtime auth failure handling."""
from __future__ import annotations
import pytest
from openharness.ui.runtime import build_runtime
@pytest.mark.asyncio
async def test_build_runtime_exits_cleanly_when_auth_resolution_fails(monkeypatch):
"""build_runtime should raise SystemExit(1) — not ValueError — when auth resolution fails."""
def fake_resolve_auth(self):
raise ValueError("No credentials found")
monkeypatch.setattr("openharness.config.settings.Settings.resolve_auth", fake_resolve_auth)
with pytest.raises(SystemExit, match="1"):
await build_runtime(active_profile="claude-api")
@pytest.mark.asyncio
async def test_build_runtime_exits_cleanly_for_openai_format(monkeypatch):
"""Same check for the openai-compatible path."""
def fake_resolve_auth(self):
raise ValueError("No credentials found")
monkeypatch.setattr("openharness.config.settings.Settings.resolve_auth", fake_resolve_auth)
with pytest.raises(SystemExit, match="1"):
await build_runtime(active_profile="openai-compatible", api_format="openai")
@pytest.mark.asyncio
async def test_build_runtime_reports_subscription_auth_setup(monkeypatch, tmp_path, capsys):
"""Subscription profiles should not be reported as missing API keys."""
monkeypatch.setenv("OPENHARNESS_CONFIG_DIR", str(tmp_path / "config"))
monkeypatch.delenv("ANTHROPIC_AUTH_TOKEN", raising=False)
with pytest.raises(SystemExit, match="1"):
await build_runtime(active_profile="claude-subscription")
captured = capsys.readouterr()
assert "subscription auth, not an API key" in captured.err
assert "oh auth claude-login" in captured.err
assert "oh provider use claude-subscription" in captured.err
assert "No API key configured" not in captured.err