~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
chore(hooks): add pre-commit hook to enforce @pytest.mark.slow on sleeping tests (#3260)
LearningCircuit17b3f5a46a79
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex d76a5707cd..6aeb810d1c 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -279,6 +279,13 @@ repos:pass_filenames: falsealways_run: truedescription: "Block commits with substantial new code but no tests"+ - id: check-unmarked-sleep+ name: Check time.sleep() in tests has @pytest.mark.slow+ entry: .pre-commit-hooks/check-unmarked-sleep.py+ language: script+ files: ^tests/.*\.py$+ description: "Ensure test functions with time.sleep(>0.1s) are marked+ @pytest.mark.slow so CI can skip them with -m 'not slow'"# Hooks intentionally NOT added# See docs/decisions/0002-pre-commit-hook-reviews.md for full rationale.diff --git a/.pre-commit-hooks/check-unmarked-sleep.py b/.pre-commit-hooks/check-unmarked-sleep.pynew file mode 100755index 0000000000..5b3b8eb73a--- /dev/null+++ b/.pre-commit-hooks/check-unmarked-sleep.py@@ -0,0 +1,200 @@+#!/usr/bin/env python3+"""+Pre-commit hook to detect time.sleep() calls in test files missing @pytest.mark.slow.++Tests that call time.sleep() with a delay > 0.1 seconds should be marked with[email protected] so CI can skip them with ``-m "not slow"``.++Uses Python AST to find real ``time.sleep(>0.1)`` calls (ignores mocked/patched+ones) and checks whether the enclosing test function or class carries the+``@pytest.mark.slow`` decorator.++Opt-out: add ``# allow: unmarked-sleep`` on the time.sleep() line.+"""++import ast+import re+import sys++SUPPRESS_RE = re.compile(r"#\s*allow:\s*unmarked-sleep(?:\s|$)")++# Minimum sleep duration (seconds) to flag. Tiny sleeps used for thread+# yielding (0.001-0.05 s) are not worth marking slow.+THRESHOLD = 0.1+++class SleepMarkerChecker(ast.NodeVisitor):+ """AST visitor that flags ``time.sleep(>THRESHOLD)`` without ``@pytest.mark.slow``."""++ def __init__(self, filepath: str, lines: list[str]):+ self.filepath = filepath+ self.lines = lines+ self.issues: list[tuple[int, float, str]] = []+ self._class_stack: list[ast.ClassDef] = []+ self._func_stack: list[ast.FunctionDef | ast.AsyncFunctionDef] = []+ # Track import aliases for ``import time as X``+ self._time_aliases: set[str] = {"time"}++ # -- import tracking ---------------------------------------------------++ def visit_Import(self, node: ast.Import) -> None:+ for alias in node.names:+ if alias.name == "time":+ self._time_aliases.add(alias.asname or alias.name)+ self.generic_visit(node)++ # -- scope tracking ----------------------------------------------------++ def visit_ClassDef(self, node: ast.ClassDef) -> None:+ self._class_stack.append(node)+ self.generic_visit(node)+ self._class_stack.pop()++ def visit_FunctionDef(self, node: ast.FunctionDef) -> None:+ self._func_stack.append(node)+ self.generic_visit(node)+ self._func_stack.pop()++ visit_AsyncFunctionDef = visit_FunctionDef++ # -- detection ---------------------------------------------------------++ def visit_Call(self, node: ast.Call) -> None:+ func = node.func+ # Match ``time.sleep()``, ``t.sleep()`` (any alias of ``import time``)+ if (+ isinstance(func, ast.Attribute)+ and func.attr == "sleep"+ and isinstance(func.value, ast.Name)+ and func.value.id in self._time_aliases+ ):+ self._check_sleep(node)+ self.generic_visit(node)++ def _check_sleep(self, node: ast.Call) -> None:+ if not node.args:+ return++ val = self._constant_value(node.args[0])+ if val is None or val <= THRESHOLD:+ return++ # Check for suppress comment on the call's lines (handles multi-line calls)+ start = node.lineno - 1+ end = getattr(node, "end_lineno", node.lineno) - 1+ for idx in range(start, min(end + 1, len(self.lines))):+ if SUPPRESS_RE.search(self.lines[idx]):+ return++ # Check if enclosing function or class has @pytest.mark.slow+ if self._func_stack and self._has_slow_marker(self._func_stack[-1]):+ return+ if self._class_stack and self._has_slow_marker(self._class_stack[-1]):+ return++ func_name = (+ self._func_stack[-1].name if self._func_stack else "<module>"+ )+ cls_name = self._class_stack[-1].name if self._class_stack else None+ qual = f"{cls_name}.{func_name}" if cls_name else func_name+ self.issues.append((node.lineno, val, qual))++ # -- helpers -----------------------------------------------------------++ @staticmethod+ def _constant_value(node: ast.expr) -> float | None:+ """Return numeric value of an AST node, or None if not a constant."""+ if isinstance(node, ast.Constant) and isinstance(+ node.value, (int, float)+ ):+ return float(node.value)+ # Handle negative numbers: ast.UnaryOp(op=USub, operand=Constant)+ if (+ isinstance(node, ast.UnaryOp)+ and isinstance(node.op, ast.USub)+ and isinstance(node.operand, ast.Constant)+ and isinstance(node.operand.value, (int, float))+ ):+ return -float(node.operand.value)+ return None++ @staticmethod+ def _has_slow_marker(+ node: ast.ClassDef | ast.FunctionDef | ast.AsyncFunctionDef,+ ) -> bool:+ """True when node is decorated with ``@pytest.mark.slow``."""+ for dec in node.decorator_list:+ if _is_pytest_mark_slow(dec):+ return True+ return False+++def _is_pytest_mark_slow(node: ast.expr) -> bool:+ """Check whether a decorator is exactly ``@pytest.mark.slow``."""+ # Unwrap call: @pytest.mark.slow(reason="...")+ if isinstance(node, ast.Call):+ return _is_pytest_mark_slow(node.func)+ # @pytest.mark.slow → Attribute(value=Attribute(value=Name(id='pytest'), attr='mark'), attr='slow')+ if (+ isinstance(node, ast.Attribute)+ and node.attr == "slow"+ and isinstance(node.value, ast.Attribute)+ and node.value.attr == "mark"+ and isinstance(node.value.value, ast.Name)+ and node.value.value.id == "pytest"+ ):+ return True+ return False+++def check_file(filepath: str) -> list[tuple[int, float, str]]:+ """Return list of (lineno, sleep_value, qualified_name) for violations."""+ try:+ with open(filepath, encoding="utf-8") as f:+ source = f.read()+ except Exception as exc:+ print(f"WARNING: Cannot read {filepath}: {exc}", file=sys.stderr)+ return []++ try:+ tree = ast.parse(source, filename=filepath)+ except SyntaxError as exc:+ print(f"WARNING: Syntax error in {filepath}: {exc}", file=sys.stderr)+ return []++ lines = source.splitlines()+ checker = SleepMarkerChecker(filepath, lines)+ checker.visit(tree)+ return checker.issues+++def main() -> int:+ exit_code = 0+ violations = 0++ for filepath in sys.argv[1:]:+ issues = check_file(filepath)+ for lineno, val, qual in issues:+ violations += 1+ print(+ f"{filepath}:{lineno}: time.sleep({val}) in {qual} "+ f"missing @pytest.mark.slow"+ )+ exit_code = 1++ if exit_code:+ print()+ print(+ "Hint: either add @pytest.mark.slow to the test function/class, "+ "or replace time.sleep() with freezegun time travel."+ )+ print(+ " Suppress with `# allow: unmarked-sleep` if the sleep is intentional."+ )+ print(f" {violations} violation(s) found.")++ return exit_code+++if __name__ == "__main__":+ sys.exit(main())diff --git a/tests/api_tests/test_all_endpoints.py b/tests/api_tests/test_all_endpoints.pyindex 55bc1dc43d..168f21b78e 100644--- a/tests/api_tests/test_all_endpoints.py+++ b/tests/api_tests/test_all_endpoints.py@@ -163,7 +163,7 @@ class TestAllEndpoints:research_id = data["research_id"]# Give it a moment to start- time.sleep(0.5)+ time.sleep(0.5) # allow: unmarked-sleep# Test various research endpointsresearch_endpoints = [diff --git a/tests/api_tests/test_comprehensive_apis.py b/tests/api_tests/test_comprehensive_apis.pyindex 230e84b66c..6b77255b1b 100644--- a/tests/api_tests/test_comprehensive_apis.py+++ b/tests/api_tests/test_comprehensive_apis.py@@ -127,7 +127,7 @@ class TestComprehensiveAPIs:research_id = data["research_id"]# Give it a moment to start- time.sleep(0.5)+ time.sleep(0.5) # allow: unmarked-sleep# Check statusresponse = authenticated_client.get(diff --git a/tests/api_tests/test_research_api_debug.py b/tests/api_tests/test_research_api_debug.pyindex d36b5ca9a0..14dcdfaa34 100644--- a/tests/api_tests/test_research_api_debug.py+++ b/tests/api_tests/test_research_api_debug.py@@ -301,7 +301,7 @@ class ResearchAPIDebugTest:try:# Wait a moment for research to initialize- time.sleep(1)+ time.sleep(1) # allow: unmarked-sleepstatus_url = f"{self.base_url}/api/research/{research_id}/status"response = self.session.get(status_url)diff --git a/tests/api_tests/test_research_creation.py b/tests/api_tests/test_research_creation.pyindex c2ee6d1504..483bfd8a94 100644--- a/tests/api_tests/test_research_creation.py+++ b/tests/api_tests/test_research_creation.py@@ -111,7 +111,7 @@ class TestResearchCreation:assert research_id is not None# Give it a moment to start- time.sleep(0.5)+ time.sleep(0.5) # allow: unmarked-sleep# Check statusresponse = authenticated_client.get(@@ -146,7 +146,7 @@ class TestResearchCreation:assert research_id is not None# Give it a moment to start- time.sleep(0.5)+ time.sleep(0.5) # allow: unmarked-sleep# Terminate itresponse = authenticated_client.post(f"/api/terminate/{research_id}")diff --git a/tests/api_tests_with_login/pytest_tests/test_export_formats.py b/tests/api_tests_with_login/pytest_tests/test_export_formats.pyindex 31ec44f0bd..5e1aa23ad2 100644--- a/tests/api_tests_with_login/pytest_tests/test_export_formats.py+++ b/tests/api_tests_with_login/pytest_tests/test_export_formats.py@@ -59,7 +59,7 @@ def test_export_latex(auth_session, base_url):print(f"Research did not complete within {max_wait} seconds")# Additional wait to ensure report is saved- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleep# Try to export as LaTeXexport_response = session.post(@@ -138,7 +138,7 @@ def test_export_pdf_via_javascript(auth_session, base_url):print(f"Research did not complete within {max_wait} seconds")# Additional wait to ensure report is saved- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleep# Get the research report contentreport_response = session.get(f"{base_url}/api/report/{research_id}")@@ -202,7 +202,7 @@ def test_export_markdown(auth_session, base_url):print(f"Research did not complete within {max_wait} seconds")# Additional wait to ensure report is saved- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleep# Get the markdown directly from the report APIreport_response = session.get(f"{base_url}/api/report/{research_id}")@@ -290,7 +290,7 @@ def test_export_quarto(auth_session, base_url):print(f"Research did not complete within {max_wait} seconds")# Additional wait to ensure report is saved- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleep# Try to export as Quartoexport_response = session.post(@@ -356,7 +356,7 @@ def test_export_ris(auth_session, base_url):print(f"Research did not complete within {max_wait} seconds")# Additional wait to ensure report is saved- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleep# Try to export as RISexport_response = session.post(diff --git a/tests/api_tests_with_login/pytest_tests/test_model_parameter.py b/tests/api_tests_with_login/pytest_tests/test_model_parameter.pyindex e542a20713..85b1fd4470 100644--- a/tests/api_tests_with_login/pytest_tests/test_model_parameter.py+++ b/tests/api_tests_with_login/pytest_tests/test_model_parameter.py@@ -28,7 +28,7 @@ def test_model_parameter_in_logs(auth_session, base_url):research_id = response.json()["research_id"]# Give it time to start- time.sleep(3)+ time.sleep(3) # allow: unmarked-sleep# Check logs for model parameterlogs_response = session.get(f"{base_url}/api/research/{research_id}/logs")diff --git a/tests/api_tests_with_login/pytest_tests/test_research_completion.py b/tests/api_tests_with_login/pytest_tests/test_research_completion.pyindex 01636701d0..3193280852 100644--- a/tests/api_tests_with_login/pytest_tests/test_research_completion.py+++ b/tests/api_tests_with_login/pytest_tests/test_research_completion.py@@ -57,7 +57,7 @@ def test_research_completion_time(auth_session, base_url):print(f" {log}")pytest.fail("Research failed - check logs above")- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleepassert completed, f"Research did not complete within {max_wait} seconds"print(f"✓ Research completed in {int(time.time() - start_time)} seconds")diff --git a/tests/api_tests_with_login/pytest_tests/test_research_results.py b/tests/api_tests_with_login/pytest_tests/test_research_results.pyindex 84d4508787..f7977747ac 100644--- a/tests/api_tests_with_login/pytest_tests/test_research_results.py+++ b/tests/api_tests_with_login/pytest_tests/test_research_results.py@@ -40,7 +40,7 @@ def test_research_produces_valid_report(auth_session, base_url):breakif status == "failed":pytest.fail("Research failed")- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleep# Get the reportreport_response = session.get(f"{base_url}/api/report/{research_id}")diff --git a/tests/api_tests_with_login/pytest_tests/test_start_research.py b/tests/api_tests_with_login/pytest_tests/test_start_research.pyindex 4e99702b62..ef3c39e336 100644--- a/tests/api_tests_with_login/pytest_tests/test_start_research.py+++ b/tests/api_tests_with_login/pytest_tests/test_start_research.py@@ -47,7 +47,7 @@ def test_start_research_with_model(auth_session, base_url):print(f"Started research with ID: {research_id}")# Wait for research to start processing- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleep# Check research status and logsstatus_response = session.get(diff --git a/tests/api_tests_with_login/test_research_api_pytest.py b/tests/api_tests_with_login/test_research_api_pytest.pyindex b4a21f3bca..8d9e83e06b 100644--- a/tests/api_tests_with_login/test_research_api_pytest.py+++ b/tests/api_tests_with_login/test_research_api_pytest.py@@ -138,7 +138,7 @@ class TestResearchAPI:print(f"Started research with ID: {research_id}")# Wait for research to start processing- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleep# Check research status and logsstatus_response = session.get(@@ -177,7 +177,7 @@ class TestResearchAPI:)# Wait a bit more for research to progress- time.sleep(5)+ time.sleep(5) # allow: unmarked-sleep# Check if research actually produces resultsreport_response = session.get(f"{BASE_URL}/api/report/{research_id}")@@ -268,7 +268,7 @@ class TestResearchAPI:print(f" {log}")pytest.fail("Research failed - check logs above")- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleepassert completed, f"Research did not complete within {max_wait} seconds"print(diff --git a/tests/auth_tests/test_inmemory_storage.py b/tests/auth_tests/test_inmemory_storage.pyindex 36b464f188..afa3f8cb96 100644--- a/tests/auth_tests/test_inmemory_storage.py+++ b/tests/auth_tests/test_inmemory_storage.py@@ -140,7 +140,7 @@ class TestTemporaryAuthStore:token = temp_auth_store.store_auth(username, password)# Wait for expiration- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleep# Should be expiredexpired = temp_auth_store.peek_auth(token)diff --git a/tests/database/backup/test_backup_service.py b/tests/database/backup/test_backup_service.pyindex 088cbea6be..ad5909bbb5 100644--- a/tests/database/backup/test_backup_service.py+++ b/tests/database/backup/test_backup_service.py@@ -848,7 +848,7 @@ class TestBackupSchedulerShutdown:scheduler.shutdown(wait=False)# Give a moment for things to settle- time.sleep(0.2)+ time.sleep(0.2) # allow: unmarked-sleep# Verify no .tmp files are left orphanedtmp_files = list(backup_dir.glob("*.tmp"))diff --git a/tests/database/test_credential_store_base.py b/tests/database/test_credential_store_base.pyindex 6e377fd556..c8faf0e854 100644--- a/tests/database/test_credential_store_base.py+++ b/tests/database/test_credential_store_base.py@@ -81,7 +81,7 @@ class TestCredentialStoreBase:store.store("key1", "user1", "pass1")# Wait for expiration- time.sleep(1.1)+ time.sleep(1.1) # allow: unmarked-sleepresult = store.retrieve("key1")assert result is Nonediff --git a/tests/database/test_credential_store_behavior.py b/tests/database/test_credential_store_behavior.pyindex 3e1568637f..4abe485945 100644--- a/tests/database/test_credential_store_behavior.py+++ b/tests/database/test_credential_store_behavior.py@@ -131,7 +131,7 @@ class TestCredentialStoreTTL:store = TemporaryAuthStore(ttl_seconds=1)token = store.store_auth("testuser", "testpass")# Wait for expiration- time.sleep(1.5)+ time.sleep(1.5) # allow: unmarked-sleepresult = store.retrieve_auth(token)assert result is None@@ -304,7 +304,7 @@ class TestCredentialStoreCleanup:store = TemporaryAuthStore(ttl_seconds=1)token1 = store.store_auth("user1", "pass1")- time.sleep(1.5) # Wait for expiration+ time.sleep(1.5) # allow: unmarked-sleep # Wait for expiration# Storing new entry should trigger cleanupstore.store_auth("user2", "pass2")# token1 should be expired and cleaneddiff --git a/tests/database/test_credential_store_extended.py b/tests/database/test_credential_store_extended.pyindex 23465f583c..7a707605bb 100644--- a/tests/database/test_credential_store_extended.py+++ b/tests/database/test_credential_store_extended.py@@ -160,13 +160,13 @@ class TestTTLExpiration:def test_entry_expires_after_ttl(self, short_ttl_store):"""Entry should expire after TTL."""short_ttl_store.store("key1", "user1", "pass1")- time.sleep(1.5) # Wait for TTL + buffer+ time.sleep(1.5) # allow: unmarked-sleep # Wait for TTL + bufferassert short_ttl_store.retrieve("key1") is Nonedef test_entry_valid_before_ttl(self, short_ttl_store):"""Entry should be valid before TTL expires."""short_ttl_store.store("key1", "user1", "pass1")- time.sleep(0.5) # Half of TTL+ time.sleep(0.5) # allow: unmarked-sleep # Half of TTLassert short_ttl_store.retrieve("key1") == ("user1", "pass1")def test_each_entry_has_own_ttl(self):@@ -174,9 +174,9 @@ class TestTTLExpiration:store = ConcreteCredentialStore(ttl_seconds=2)store.store("key1", "user1", "pass1")- time.sleep(1)+ time.sleep(1) # allow: unmarked-sleepstore.store("key2", "user2", "pass2") # Added 1s later- time.sleep(1.5)+ time.sleep(1.5) # allow: unmarked-sleep# key1 should be expired (2.5s old)# key2 should still be valid (1.5s old)@@ -188,9 +188,9 @@ class TestTTLExpiration:store = ConcreteCredentialStore(ttl_seconds=1)store.store("key1", "user1", "pass1")- time.sleep(0.7)+ time.sleep(0.7) # allow: unmarked-sleepstore.store("key1", "user1", "pass1") # Reset TTL- time.sleep(0.7)+ time.sleep(0.7) # allow: unmarked-sleep# Should still be valid (0.7s since reset, TTL is 1s)assert store.retrieve("key1") == ("user1", "pass1")@@ -205,7 +205,7 @@ class TestCleanupExpired:store.store("key1", "user1", "pass1")store.store("key2", "user2", "pass2")- time.sleep(1.5)+ time.sleep(1.5) # allow: unmarked-sleep# Trigger cleanup by storing new entrystore.store("key3", "user3", "pass3")@@ -383,7 +383,7 @@ class TestMemoryManagement:for i in range(100):store.store(f"key{i}", f"user{i}", f"pass{i}")- time.sleep(1.5)+ time.sleep(1.5) # allow: unmarked-sleep# Add new entry to trigger cleanupstore.store("new_key", "new_user", "new_pass")diff --git a/tests/library/test_auto_indexing.py b/tests/library/test_auto_indexing.pyindex 5e387a649b..29c4804988 100644--- a/tests/library/test_auto_indexing.py+++ b/tests/library/test_auto_indexing.py@@ -356,7 +356,7 @@ class TestAutoIndexExecutor:futures = [executor.submit(slow_worker) for _ in range(max_workers + 2)]# Give threads time to start- time.sleep(0.2)+ time.sleep(0.2) # allow: unmarked-sleep# Only max_workers should be runningwith count_lock:diff --git a/tests/metrics/test_pricing_cache.py b/tests/metrics/test_pricing_cache.pyindex fa85e19cbe..933f5a6312 100644--- a/tests/metrics/test_pricing_cache.py+++ b/tests/metrics/test_pricing_cache.py@@ -62,7 +62,7 @@ class TestPricingCacheGetSet:cache.set("test_key", {"value": 789})# Wait for expiration- time.sleep(1.1)+ time.sleep(1.1) # allow: unmarked-sleepresult = cache.get("test_key")assert result is None@@ -149,7 +149,7 @@ class TestPricingCacheClear:cache.set("old_key", "old_value")# Wait for old entry to expire- time.sleep(2.1)+ time.sleep(2.1) # allow: unmarked-sleep# Add new entrycache.set("new_key", "new_value")@@ -195,7 +195,7 @@ class TestPricingCacheStats:cache = PricingCache(cache_ttl=1)cache.set("key1", "value1")- time.sleep(1.1)+ time.sleep(1.1) # allow: unmarked-sleepstats = cache.get_cache_stats()@@ -229,7 +229,7 @@ class TestPricingCacheTTL:assert cache.get("key1") == "value1"# Wait for expiration- time.sleep(1.1)+ time.sleep(1.1) # allow: unmarked-sleep# Entry should be expiredassert cache.get("key1") is Nonediff --git a/tests/run_all_tests.py b/tests/run_all_tests.pyindex abef0b0532..3dd8227fce 100755--- a/tests/run_all_tests.py+++ b/tests/run_all_tests.py@@ -269,7 +269,7 @@ class TestRunner:# Wait for server to start (max 45 seconds)for i in range(45):- time.sleep(1)+ time.sleep(1) # allow: unmarked-sleepif self.check_server_running():self.log(f"Server started successfully after {i + 1} seconds"diff --git a/tests/security/test_rate_limiter_extended.py b/tests/security/test_rate_limiter_extended.pyindex f9bd60de2b..41ded124f4 100644--- a/tests/security/test_rate_limiter_extended.py+++ b/tests/security/test_rate_limiter_extended.py@@ -50,7 +50,7 @@ class TestRateLimitSlidingWindow:return len(window["requests"])add_request()- time.sleep(0.15) # Wait for window to expire+ time.sleep(0.15) # allow: unmarked-sleep # Wait for window to expirecount = add_request()assert count == 1 # Old request should have expireddiff --git a/tests/test_search_cache_stampede.py b/tests/test_search_cache_stampede.pyindex e3b50ab485..20332989e3 100644--- a/tests/test_search_cache_stampede.py+++ b/tests/test_search_cache_stampede.py@@ -154,7 +154,7 @@ class TestSearchCacheStampede(unittest.TestCase):self.assertEqual(self.api_call_count, 1)# Wait for cache to expire- time.sleep(1.5)+ time.sleep(1.5) # allow: unmarked-sleep# Multiple threads try to fetch expired entrynum_threads = 5@@ -195,7 +195,7 @@ class TestSearchCacheStampede(unittest.TestCase):def slow_fetch():fetch_started.set()- time.sleep(0.5) # Simulate slow API+ time.sleep(0.5) # allow: unmarked-sleep # Simulate slow APIfetch_complete.set()return self.mock_api_call(query)@@ -276,7 +276,7 @@ class TestSearchCacheStampede(unittest.TestCase):self.cache.get_or_fetch(query, lambda: self.mock_api_call(query))# Wait for cleanup thread to run (cleanup delay is 2 seconds)- time.sleep(3)+ time.sleep(3) # allow: unmarked-sleep# Check that locks and events have been cleaned upquery_hash = self.cache._get_query_hash(query)diff --git a/tests/ui_tests/test_simple_research_api.py b/tests/ui_tests/test_simple_research_api.pyindex 5cc1ac3560..c23de60476 100644--- a/tests/ui_tests/test_simple_research_api.py+++ b/tests/ui_tests/test_simple_research_api.py@@ -109,7 +109,7 @@ def main():# Check status after a few secondsfor i in range(5):- time.sleep(2)+ time.sleep(2) # allow: unmarked-sleepstatus_resp = session.get(f"http://127.0.0.1:5000/api/research/{research_id}/status")diff --git a/tests/utilities/test_search_cache.py b/tests/utilities/test_search_cache.pyindex 1c2045955a..5886b8c375 100644--- a/tests/utilities/test_search_cache.py+++ b/tests/utilities/test_search_cache.py@@ -222,7 +222,7 @@ class TestSearchCachePutGet:)# Wait for expiration- time.sleep(2.5)+ time.sleep(2.5) # allow: unmarked-sleep# Clear memory cache to force DB checkcache._memory_cache.clear()@@ -248,7 +248,7 @@ class TestSearchCacheExpiration:cache.put("test query", results)# Wait for expiration- time.sleep(1.5)+ time.sleep(1.5) # allow: unmarked-sleep# Clear memory cache to force DB checkcache._memory_cache.clear()@@ -262,7 +262,7 @@ class TestSearchCacheExpiration:cache.put("test query", results)# Wait for expiration- time.sleep(1.5)+ time.sleep(1.5) # allow: unmarked-sleep# Access should remove expired entry from memorycache.get("test query")@@ -476,7 +476,7 @@ class TestSearchCacheGetOrFetch:def slow_fetch():fetch_count.append(1)- time.sleep(0.2)+ time.sleep(0.2) # allow: unmarked-sleepreturn [{"title": "Result"}]threads = []diff --git a/tests/utilities/test_search_cache_stampede.py b/tests/utilities/test_search_cache_stampede.pyindex 0f81787891..7270071d91 100644--- a/tests/utilities/test_search_cache_stampede.py+++ b/tests/utilities/test_search_cache_stampede.py@@ -155,7 +155,7 @@ class TestStampedeProtectionConcurrency:cache.get_or_fetch("cleanup test", quick_fetch, "engine1")# Wait for cleanup thread- time.sleep(3)+ time.sleep(3) # allow: unmarked-sleep# Internal state should be cleaned upquery_hash = cache._get_query_hash("cleanup test", "engine1")@@ -187,7 +187,7 @@ class TestStampedeProtectionConcurrency:# Immediately after fetch, artifacts should exist# Note: They might already be cleaned up by the daemon thread# Wait for cleanup (2 second delay + some buffer)- time.sleep(3)+ time.sleep(3) # allow: unmarked-sleep# After cleanup, should be removedassert query_hash not in cache._fetch_events@@ -465,7 +465,7 @@ class TestTTLExpiration:assert result is not None# Wait for expiration- time.sleep(5)+ time.sleep(5) # allow: unmarked-sleepresult = short_ttl_cache.get("expiring", "engine1")assert result is None@@ -479,7 +479,7 @@ class TestTTLExpiration:assert query_hash in short_ttl_cache._memory_cache- time.sleep(2.5)+ time.sleep(2.5) # allow: unmarked-sleep# Access triggers removalshort_ttl_cache.get("memory_expire", "engine1")@@ -490,7 +490,7 @@ class TestTTLExpiration:"""_cleanup_expired removes DB entries."""short_ttl_cache.put("db_expire", [{"title": "DB"}], "engine1", ttl=2)- time.sleep(2.5)+ time.sleep(2.5) # allow: unmarked-sleep# Run cleanupshort_ttl_cache._cleanup_expired()