From b18b39db276f669bed68828bfca2f15397699f45 Mon Sep 17 00:00:00 2001 From: Ben Matson Date: Mon, 16 Nov 2026 14:02:13 -0700 Subject: [PATCH] test: Make `tests/forges/test_github_api_url.py::test_with_no_setting_the_forge_calls_github` deterministic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tests come first and fail until the implementation. `agent_build_kit.settings.reload` writes a fresh read of the environment into the one process-wide `settings` object, in place, field by field (`src/agent_build_kit/settings.py:228`). Done when the doctor-with-setting test followed by the failing test passes in one process with no workers (on the base the second fails with `NotFound: POST /api/v3/repos/example/app/pulls`), no… Unit: fix-test-tests-forges-test-github-api-url-py-test-with-no-set-fb2349ad/1 --- tests/conftest.py | 17 +++++++++++++++++ tests/forges/test_github_api_url.py | 8 ++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 46db93e23..e36534a48 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,6 +34,7 @@ from agent_build_kit import claude_account, forges, orchestration, sandboxes from agent_build_kit import config as config_module from agent_build_kit import installation as installation_module +from agent_build_kit import settings as settings_module from agent_build_kit.cli import doctor from agent_build_kit.cli import pipeline as pipeline_cli from agent_build_kit.config import RepoConfig, WorkspaceConfig @@ -83,6 +84,22 @@ def build_session(new_session_id: Callable[[], str]) -> str: return new_session_id() +@pytest.fixture(autouse=True) +def settings_restored() -> Iterator[None]: + """Every test ends with the settings it started with. + + `settings.reload` writes the process-wide object in place, field by field, and loading an + installation or running the doctor calls it. `monkeypatch.setenv` restores the environment + but not the fields a reload wrote from it, so a later test on the same worker would read + the earlier one's value.""" + before = settings_module.settings.model_dump() + env_file = settings_module.loaded_env_file + yield + for name, value in before.items(): + setattr(settings_module.settings, name, value) + settings_module.loaded_env_file = env_file + + @pytest.fixture(autouse=True) def no_checkout_env_file(monkeypatch: pytest.MonkeyPatch) -> None: """A developer's ignored `.env` is not part of the suite: the lookup treats the checkout's diff --git a/tests/forges/test_github_api_url.py b/tests/forges/test_github_api_url.py index f484bc0a9..8aeca76c4 100644 --- a/tests/forges/test_github_api_url.py +++ b/tests/forges/test_github_api_url.py @@ -3,7 +3,9 @@ Read off the requests that reach the stand-in host (their URLs). The forge reads the setting from the settings object; the doctor loads the installation, which re-reads -the settings from the environment, so its tests set the environment variable. +the settings from the environment, so its tests set the environment variable. The `token` +fixture undoes that environment and reloads the settings afterwards, so a doctor test +leaves nothing for a forge test. """ from __future__ import annotations @@ -19,7 +21,7 @@ from agent_build_kit.forges.base import RepoId from agent_build_kit.forges.github import GitHubForge from agent_build_kit.forges.transport import clear_credentials -from agent_build_kit.settings import settings +from agent_build_kit.settings import reload, settings from tests.cli.test_doctor import Answers, which_all from tests.factories import init_repo from tests.forges.conftest import GH_TOKEN @@ -37,6 +39,8 @@ def token(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]: clear_credentials() yield clear_credentials() + monkeypatch.undo() + reload(None) def created() -> httpx.Response: