"""Tests for opencode_bridge.config.""" from opencode_bridge.config import OpenCodeConfig, resolve_config def test_all_defaults() -> None: config = resolve_config({}) assert config.url == "http://127.0.0.1:4096" assert config.user == "opencode" assert config.password == "" assert config.request_timeout_seconds == 120 def test_env_url_overrides_default(monkeypatch) -> None: monkeypatch.setenv("OPENCODE_BRIDGE_URL", "http://x:1") config = resolve_config({}) assert config.url == "http://x:1" def test_jupyter_settings_are_ignored(monkeypatch) -> None: monkeypatch.setenv("OPENCODE_BRIDGE_URL", "http://x:1") settings = {"opencode_bridge": {"opencodeServerUrl": "http://y:2"}} config = resolve_config(settings) assert config.url == "http://x:1" def test_all_env_vars(monkeypatch) -> None: monkeypatch.setenv("OPENCODE_BRIDGE_URL", "http://x:1") monkeypatch.setenv("OPENCODE_BRIDGE_USER", "u") monkeypatch.setenv("OPENCODE_BRIDGE_PASSWORD", "p") monkeypatch.setenv("OPENCODE_BRIDGE_TIMEOUT", "300") config = resolve_config({}) assert config.url == "http://x:1" assert config.user == "u" assert config.password == "p" assert config.request_timeout_seconds == 300 def test_auth_none_when_password_empty() -> None: config = resolve_config({}) assert config.auth is None def test_auth_when_password_set() -> None: config = OpenCodeConfig( url="http://127.0.0.1:4096", user="opencode", password="secret", request_timeout_seconds=120, ) assert config.auth == ("opencode", "secret") def test_request_timeout_from_env(monkeypatch) -> None: monkeypatch.setenv("OPENCODE_BRIDGE_TIMEOUT", "300") config = resolve_config({}) assert config.request_timeout_seconds == 300