From 81b39a901f23e4f250679dd753b30ba851fec1c5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 19:36:57 +0000 Subject: [PATCH 1/2] Fix test suite stability and configuration - Refactor `backend/tests/agent/test_rate_limiter.py` to use `unittest.mock` for `datetime`, ensuring deterministic behavior at daily boundaries. - Update `backend/tests/conftest.py` to implement `pytest_addoption` and `pytest_collection_modifyitems` for the `--only-extended` flag. - Add `pytestmark = pytest.mark.extended` to `backend/tests/test_utils_hypothesis.py` to correctly exclude these property-based tests from standard runs. - Verify full test suite (backend standard, extended, and frontend) passes. Co-authored-by: MasumRab <8943353+MasumRab@users.noreply.github.com> --- backend/tests/agent/test_rate_limiter.py | 25 ++++++++----- backend/tests/conftest.py | 45 ++++++++++++++++++++++++ backend/tests/test_utils_hypothesis.py | 2 ++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/backend/tests/agent/test_rate_limiter.py b/backend/tests/agent/test_rate_limiter.py index 5f6a8e6c1..d2620832d 100644 --- a/backend/tests/agent/test_rate_limiter.py +++ b/backend/tests/agent/test_rate_limiter.py @@ -7,13 +7,18 @@ from agent.rate_limiter import RateLimiter, PACIFIC_TZ class TestRateLimiter(unittest.TestCase): - def test_daily_reset_logic(self): + @patch('agent.rate_limiter.datetime') + def test_daily_reset_logic(self, mock_datetime): """Test that daily reset occurs at midnight Pacific Time.""" + # Setup mock time + now_date = datetime(2023, 10, 2, 12, 0, 0, tzinfo=PACIFIC_TZ) + mock_datetime.now.return_value = now_date + limiter = RateLimiter() # Manually set last reset date to yesterday - yesterday = datetime.now(PACIFIC_TZ).date() - timedelta(days=1) - limiter._last_reset_date = yesterday + yesterday_date = now_date.date() - timedelta(days=1) + limiter._last_reset_date = yesterday_date # Add some dummy requests limiter._requests_per_day.append(12345) @@ -24,15 +29,19 @@ def test_daily_reset_logic(self): # Should be cleared self.assertEqual(len(limiter._requests_per_day), 0) - self.assertEqual(limiter._last_reset_date, datetime.now(PACIFIC_TZ).date()) + self.assertEqual(limiter._last_reset_date, now_date.date()) - def test_no_reset_same_day(self): + @patch('agent.rate_limiter.datetime') + def test_no_reset_same_day(self, mock_datetime): """Test that daily reset does not occur on the same day.""" + # Setup mock time + now_date = datetime(2023, 10, 2, 12, 0, 0, tzinfo=PACIFIC_TZ) + mock_datetime.now.return_value = now_date + limiter = RateLimiter() # Set last reset date to today - today = datetime.now(PACIFIC_TZ).date() - limiter._last_reset_date = today + limiter._last_reset_date = now_date.date() # Add some dummy requests limiter._requests_per_day.append(12345) @@ -43,7 +52,7 @@ def test_no_reset_same_day(self): # Should NOT be cleared self.assertEqual(len(limiter._requests_per_day), 1) - self.assertEqual(limiter._last_reset_date, today) + self.assertEqual(limiter._last_reset_date, now_date.date()) if __name__ == "__main__": unittest.main() diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index 891dd2801..882943cc7 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -27,6 +27,51 @@ sys.path.insert(0, str(SRC_PATH)) +# ============================================================================= +# Pytest Hooks +# ============================================================================= + +def pytest_addoption(parser): + """Add custom command line options.""" + parser.addoption( + "--only-extended", + action="store_true", + default=False, + help="run only extended tests", + ) + + +def pytest_configure(config): + """Configure custom markers.""" + config.addinivalue_line("markers", "extended: mark test as extended test") + + +def pytest_collection_modifyitems(config, items): + """Filter tests based on --only-extended flag.""" + if config.getoption("--only-extended"): + # --only-extended given: remove tests NOT marked extended + selected = [] + deselected = [] + for item in items: + if "extended" in item.keywords: + selected.append(item) + else: + deselected.append(item) + items[:] = selected + config.hook.pytest_deselected(items=deselected) + else: + # --only-extended NOT given: remove tests marked extended + selected = [] + deselected = [] + for item in items: + if "extended" not in item.keywords: + selected.append(item) + else: + deselected.append(item) + items[:] = selected + config.hook.pytest_deselected(items=deselected) + + # ============================================================================= # State Fixtures # ============================================================================= diff --git a/backend/tests/test_utils_hypothesis.py b/backend/tests/test_utils_hypothesis.py index 1124bd841..25c9c185f 100644 --- a/backend/tests/test_utils_hypothesis.py +++ b/backend/tests/test_utils_hypothesis.py @@ -2,6 +2,8 @@ import pytest from agent.utils import insert_citation_markers +pytestmark = pytest.mark.extended + @settings(suppress_health_check=[HealthCheck.too_slow]) @given( text=st.text(min_size=1, max_size=500), From 05347134a79601b6b27025febbc017c9935ca6cb Mon Sep 17 00:00:00 2001 From: MasumRab <8943353+MasumRab@users.noreply.github.com> Date: Tue, 17 Feb 2026 13:21:02 +0000 Subject: [PATCH 2/2] Fix test suite stability and configuration - Refactor `backend/tests/agent/test_rate_limiter.py` to use `unittest.mock` for `datetime`, ensuring deterministic behavior at daily boundaries. - Update `backend/tests/conftest.py` to implement `pytest_addoption` and `pytest_collection_modifyitems` for the `--only-extended` flag. - Add `pytestmark = pytest.mark.extended` to `backend/tests/test_utils_hypothesis.py` to correctly exclude these property-based tests from standard runs. - Verify full test suite (backend standard, extended, and frontend) passes. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>