From 1baae811659d6b6358fea00339b06b7b85bab4ec Mon Sep 17 00:00:00 2001 From: Dev Agent Date: Fri, 5 Jun 2026 00:00:01 +0300 Subject: [PATCH] test: reset webhook secret per-test to fix cross-file isolation (CI green) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds autouse fixture _reset_webhook_secrets to tests/conftest.py that resets the process-wide Pydantic settings singleton before every test: 1. gitea_webhook_secret / plane_webhook_secret → "" (HMAC disabled by default). Tests that deliberately test the 401 path (test_webhook_dedup.py:268,278) override this with their own monkeypatch which runs after autouse fixtures and wins for that test only. 2. db_path → os.environ["ORCH_DB_PATH"] (last written value after all test modules are imported). Without this, test_webhook_dedup.py (imported first alphabetically) seeds settings.db_path = dedup.db, while test_webhooks.py setup_db tries to remove test_orchestrator.db — leaving the DB dirty between tests that share a branch name and causing get_task_by_repo_branch() to return a stale row with the wrong stage. Per-test monkeypatches in test_webhook_dedup.setup_db still override it. Root cause: both leaks come from the same singleton settings being read once at import, before any per-test isolation runs. The autouse fixture is the correct per-test reset point for process-wide singletons. Result: pytest tests/ → 294 passed, 0 failed (was 10 failed/284 passed). --- tests/conftest.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 991f025..d012ccc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -38,3 +38,36 @@ def _no_telegram(monkeypatch): monkeypatch.setattr("src.agents.launcher.send_telegram", _noop, raising=False) monkeypatch.setattr("src.queue_worker.send_telegram", _noop, raising=False) yield + + +@pytest.fixture(autouse=True) +def _reset_webhook_secrets(monkeypatch): + """Isolate settings singleton between test files (CI cross-file isolation). + + settings is a process-wide Pydantic singleton read once at import. Different + test modules set env variables differently at import-time, so those values leak + across files when pytest collects them together (as CI does). + + 1. webhook secrets: reset to "" so HMAC is disabled by default. Tests that + intentionally test the 401 path (test_webhook_dedup.py:268,278) re-apply + their own monkeypatch AFTER this autouse fixture runs, which overrides the + reset for the duration of that one test only. + + 2. db_path: reset to the value from ORCH_DB_PATH env var (last written by the + last imported test module). Without this, test_webhook_dedup.py (imported + first, alphabetically) seeds settings.db_path = dedup.db, while + test_webhooks.py's setup_db fixture tries to remove test_orchestrator.db, + leaving the DB dirty across tests that share a branch name and causing + get_task_by_repo_branch() to return a stale row with the wrong stage. + Per-test monkeypatches in test_webhook_dedup.setup_db override this reset. + """ + import os + from src.webhooks import gitea as gitea_mod + from src.webhooks import plane as plane_mod + from src import db as db_mod + monkeypatch.setattr(gitea_mod.settings, "gitea_webhook_secret", "", raising=False) + monkeypatch.setattr(plane_mod.settings, "plane_webhook_secret", "", raising=False) + db_path_env = os.environ.get("ORCH_DB_PATH", "") + if db_path_env: + monkeypatch.setattr(db_mod.settings, "db_path", db_path_env, raising=False) + yield