diff --git a/tests/test_runner_root_prompt.py b/tests/test_runner_root_prompt.py index 1bea19c2..8e6111f1 100644 --- a/tests/test_runner_root_prompt.py +++ b/tests/test_runner_root_prompt.py @@ -6,7 +6,7 @@ flow through to the root agent's ``build_strix_agent`` call. from __future__ import annotations -import types +import os from typing import Any import httpx @@ -17,12 +17,37 @@ from openai import RateLimitError import strix.tools.mcp as mcp_pkg import strix.tools.notes.tools as notes_tools import strix.tools.todo.tools as todo_tools +from strix.config.settings import Settings from strix.core import runner from strix.core.agents import AgentCoordinator from strix.runtime import session_manager from strix.tools.mcp import BearerAuth, McpConnectionConfig, McpConnectionRequest +_SETTINGS_ENV_PREFIXES = ( + "STRIX_", + "LLM_", + "OPENAI_", + "DEDUPE_LLM_", + "LITELLM_", + "OLLAMA_", + "PERPLEXITY_", + "POSTMAN_", +) + + +@pytest.fixture(autouse=True) +def _clear_settings_env(monkeypatch: pytest.MonkeyPatch) -> None: + """Drop ambient settings env vars so Settings() builds deterministically. + + A malformed unrelated value (e.g. a non-JSON LLM_EXTRA_HEADERS) would + otherwise make Settings() raise before the fields under test are assigned. + """ + for key in list(os.environ): + if key.startswith(_SETTINGS_ENV_PREFIXES): + monkeypatch.delenv(key, raising=False) + + def _make_rate_limit_error() -> RateLimitError: request = httpx.Request("POST", "https://api.openai.com/v1/responses") response = httpx.Response(status_code=429, request=request) @@ -44,17 +69,14 @@ def _patch_engine_scaffold( monkeypatch.setattr(runner, "setup_scan_logging", lambda _run_dir: lambda: None) monkeypatch.setattr(runner, "set_scan_id", lambda _scan_id: None) - settings = types.SimpleNamespace( - llm=types.SimpleNamespace( - model="openai/gpt-4o", - reasoning_effort="high", - force_required_tool_choice=False, - timeout=300, - prompt_cache=True, - extra_headers=None, - ), - runtime=types.SimpleNamespace(max_context_images=3), - ) + settings = Settings() + settings.llm.model = "openai/gpt-4o" + settings.llm.reasoning_effort = "high" + settings.llm.force_required_tool_choice = False + settings.llm.timeout = 300 + settings.llm.prompt_cache = True + settings.llm.extra_headers = None + settings.runtime.max_context_images = 3 monkeypatch.setattr(runner, "load_settings", lambda: settings) monkeypatch.setattr(runner, "configure_sdk_model_defaults", lambda _settings: None) monkeypatch.setattr(