Skip to content

Commit e2fb050

Browse files
northdpoleclaude
andcommitted
test: keep environment changes from leaking between tests; stub Redis in the bearer test
Several tests set NO_LOAD_GRAPH_DB (admin_authz_hardening, admin_runtime_settings) or the librarian promoted defaults (evaluate_harness) process-wide and never restored them, so later db_test gap-analysis and parser tests failed in CI. The bearer test hit Redis, which CI does not have. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 26a507d commit e2fb050

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎application/tests/admin_authz_hardening_test.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os
66
import unittest
7+
from unittest import mock
78
from unittest.mock import patch
89

910
from application import create_app, sqla
@@ -12,8 +13,11 @@
1213

1314
class TestAdminAuthzHardening(unittest.TestCase):
1415
def setUp(self) -> None:
15-
os.environ["NO_LOAD_GRAPH_DB"] = "1"
16-
os.environ["INSECURE_REQUESTS"] = "1"
16+
patcher = mock.patch.dict(
17+
os.environ, {"NO_LOAD_GRAPH_DB": "1", "INSECURE_REQUESTS": "1"}
18+
)
19+
patcher.start()
20+
self.addCleanup(patcher.stop)
1721
self.app = create_app(mode="test")
1822
self.app.secret_key = "test-secret"
1923
self.ctx = self.app.app_context()

‎application/tests/admin_runtime_settings_test.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44

55
import os
66
import unittest
7+
from unittest import mock
78

89
from application import create_app, sqla
910
from application.utils.admin_panel import runtime_settings
1011

1112

1213
class TestAdminRuntimeSettings(unittest.TestCase):
1314
def setUp(self) -> None:
14-
os.environ["NO_LOAD_GRAPH_DB"] = "1"
15+
patcher = mock.patch.dict(os.environ, {"NO_LOAD_GRAPH_DB": "1"})
16+
patcher.start()
17+
self.addCleanup(patcher.stop)
1518
self.app = create_app(mode="test")
1619
self.ctx = self.app.app_context()
1720
self.ctx.push()

‎application/tests/api_tokens_test.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ def test_admin_oie_allows_bearer(self) -> None:
213213
name="admin-read",
214214
expires_at=datetime.now(timezone.utc) + timedelta(days=7),
215215
)
216-
with patch.dict(os.environ, {"CRE_ALLOW_IMPORT": "1"}):
216+
# This test is about bearer auth, not Redis (CI has none): stub the queue status.
217+
with patch.dict(os.environ, {"CRE_ALLOW_IMPORT": "1"}), patch(
218+
"application.utils.rq_dashboard_snapshot.oie_rq_status",
219+
return_value={"queues": []},
220+
):
217221
with self.app.test_client() as client:
218222
resp = client.get(
219223
"/admin/oie/rq/status",

‎application/tests/librarian/evaluate_harness_test.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io
2424
import os
2525
import unittest
26+
from unittest import mock
2627
from typing import Iterator, List, Optional
2728

2829
from application.utils.librarian.schemas import CreCandidate, RetrievalAudit
@@ -297,6 +298,13 @@ class BoundaryGateTest(unittest.TestCase):
297298
os.path.dirname(__file__), "fixtures", "golden_dataset.json"
298299
)
299300

301+
def setUp(self) -> None:
302+
# The harness loads the shipped librarian config, which sets promoted defaults
303+
# (e.g. CRE_EMBED_EXPECTED_DIM) process-wide; keep them out of later tests.
304+
patcher = mock.patch.dict(os.environ)
305+
patcher.start()
306+
self.addCleanup(patcher.stop)
307+
300308
def test_synthetic_row_satisfies_the_live_queue_schema(self) -> None:
301309
from application.utils.librarian.section_validator import (
302310
section_from_queue_row,

0 commit comments

Comments
 (0)