~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
test: quality cleanup — stop tests passing when the SUT misbehaves (#3970)
LearningCircuit8cdd902408f9
diff --git a/tests/database/backup/test_backup_service.py b/tests/database/backup/test_backup_service.pyindex 8fb83fa22e..7670948fa7 100644--- a/tests/database/backup/test_backup_service.py+++ b/tests/database/backup/test_backup_service.py@@ -17,6 +17,24 @@ from local_deep_research.database.backup.backup_executor import ()+def _has_sqlcipher() -> bool:+ try:+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )++ get_sqlcipher_module()+ return True+ except (ImportError, RuntimeError):+ return False+++HAS_SQLCIPHER = _has_sqlcipher()+requires_sqlcipher = pytest.mark.skipif(+ not HAS_SQLCIPHER, reason="SQLCipher not available"+)++class TestBackupResult:"""Tests for BackupResult dataclass."""@@ -1280,20 +1298,18 @@ class TestBackupServiceSuccessPath:class TestBackupFileIntegrity:"""Tests for backup file integrity verification."""+ @requires_sqlcipherdef test_verify_backup_with_valid_file(self, tmp_path):"""Should return True for valid backup file (using real SQLCipher if available)."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()# Create a real valid encrypted database filebackup_file = tmp_path / "valid_backup.db"@@ -1944,6 +1960,7 @@ class TestBackupConcurrency:"At most 4 backups should remain (3 old + 1 new)")+ @requires_sqlcipherdef test_backup_with_active_write_transaction(self, tmp_path):"""Backup should handle concurrent write transactions.@@ -1955,20 +1972,17 @@ class TestBackupConcurrency:This test verifies no database corruption occurs in either case."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_concurrent_write_password"@@ -2738,20 +2752,18 @@ class TestBackupEdgeCases:# Verify the final backup file exists (was renamed from .tmp)assert result.backup_path.exists()+ @requires_sqlcipherdef test_backup_of_empty_database(self, tmp_path):"""Should successfully backup a database with no user data."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_empty_db_password"@@ -2905,6 +2917,7 @@ class TestBackupEdgeCases:hasattr(os, "geteuid") and os.geteuid() == 0,reason="Root ignores filesystem permission restrictions",)+ @requires_sqlcipherdef test_backup_directory_readonly_fails_gracefully(self, tmp_path):"""Should return error if backup directory is read-only."""import os@@ -2914,18 +2927,15 @@ class TestBackupEdgeCases:if platform.system() == "Windows":pytest.skip("Windows handles permissions differently")- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_readonly_password"@@ -2979,6 +2989,7 @@ class TestBackupEdgeCases:# Restore permissionsos.chmod(backup_dir, original_mode)+ @requires_sqlcipherdef test_backup_timestamp_collision_handled(self, tmp_path):"""Should handle two backups created in same second.@@ -2987,18 +2998,15 @@ class TestBackupEdgeCases:overwrite) or fails gracefully without corruption."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_collision_password"@@ -3396,18 +3404,17 @@ class TestBackupEncryptionVerification:@pytest.fixturedef real_encrypted_db(self, tmp_path):"""Create a real encrypted SQLCipher database for testing."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )-- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):+ if not HAS_SQLCIPHER:pytest.skip("SQLCipher not available")+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )++ sqlcipher = get_sqlcipher_module()db_path = tmp_path / "test_encrypted.db"password = "test_password_123"@@ -3429,6 +3436,7 @@ class TestBackupEncryptionVerification:return {"db_path": db_path, "password": password}+ @requires_sqlcipherdef test_backup_file_header_is_not_sqlite_plaintext(self, real_encrypted_db, tmp_path):@@ -3437,20 +3445,17 @@ class TestBackupEncryptionVerification:SECURITY: If this test fails, backups are being created WITHOUT encryption,exposing user data to anyone with filesystem access."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()db_path = real_encrypted_db["db_path"]password = real_encrypted_db["password"]@@ -3496,6 +3501,7 @@ class TestBackupEncryptionVerification:"indicates unencrypted or improperly encrypted file.")+ @requires_sqlcipherdef test_backup_cannot_be_opened_without_any_password(self, real_encrypted_db, tmp_path):@@ -3504,20 +3510,17 @@ class TestBackupEncryptionVerification:SECURITY: If this test fails, backups can be read without authentication,completely defeating the purpose of encryption."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()db_path = real_encrypted_db["db_path"]password = real_encrypted_db["password"]@@ -3564,6 +3567,7 @@ class TestBackupEncryptionVerification:f"Expected encryption-related error, got: {exc_info.value}")+ @requires_sqlcipherdef test_backup_service_creates_encrypted_backup(self, tmp_path):"""End-to-end test: BackupService.create_backup() produces encrypted file.@@ -3574,18 +3578,15 @@ class TestBackupEncryptionVerification:3. Backup is readable with correct password4. Backup fails with wrong password"""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_secure_password_456"@@ -3668,6 +3669,7 @@ class TestBackupEncryptionVerification:conn.close()+ @requires_sqlcipherdef test_backup_rejected_by_standard_sqlite(self, tmp_path):"""Standard SQLite (not SQLCipher) should fail to open encrypted backup.@@ -3676,20 +3678,17 @@ class TestBackupEncryptionVerification:"""import sqlite3 # Standard library, not SQLCipher- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_password_789"@@ -3734,6 +3733,7 @@ class TestBackupEncryptionVerification:f"Expected 'not a database' error, got: {exc_info.value}")+ @requires_sqlcipherdef test_backup_file_has_high_entropy(self, tmp_path):"""Encrypted backup should have high Shannon entropy (~8 bits/byte).@@ -3742,20 +3742,17 @@ class TestBackupEncryptionVerification:"""import math- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_entropy_password"@@ -3828,25 +3825,23 @@ class TestBackupEncryptionVerification:f"suggests weak or missing encryption. Expected >= 7.5")+ @requires_sqlcipherdef test_backup_contains_no_readable_sql_strings(self, tmp_path):"""Encrypted backup should not contain readable SQL keywords or table names.This is a quick sanity check that no plaintext SQL leaked into the backup."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_strings_password"@@ -3915,6 +3910,7 @@ class TestBackupEncryptionVerification:f"'{forbidden.decode()}' in encrypted backup file!")+ @requires_sqlcipherdef test_backup_rejects_symlink_paths(self, tmp_path):"""Symlinks in backup path should be rejected or safely resolved.@@ -3923,18 +3919,15 @@ class TestBackupEncryptionVerification:important files or exposing data in insecure locations."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_symlink_password"@@ -4001,6 +3994,7 @@ class TestBackupEncryptionVerification:assert malicious_backup_dir.resolve() != malicious_backup_dirassert malicious_backup_dir.resolve() == outside_dir+ @requires_sqlcipherdef test_backup_file_has_restrictive_permissions(self, tmp_path):"""Backup files should have 0o600 or stricter (owner read/write only).@@ -4009,18 +4003,15 @@ class TestBackupEncryptionVerification:backup and attempt offline attacks."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_permissions_password"@@ -4139,6 +4130,7 @@ class TestBackupEncryptionVerification:# logs should be protected. For user-facing errors, sanitization# is more important.+ @requires_sqlcipherdef test_real_backup_verify_rejects_wrong_password(self, tmp_path):"""Encrypted backup must reject wrong password using real SQLCipher.@@ -4147,20 +4139,17 @@ class TestBackupEncryptionVerification:incorrect password. Unlike mocked tests, this uses real SQLCipheroperations to ensure the encryption is functioning correctly."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()correct_password = "correct_password_12345"wrong_password = "definitely_wrong_password"@@ -4244,26 +4233,24 @@ class TestBackupEncryptionVerification:assert len(rows) == 1assert rows[0][0] == "top_secret_value"+ @requires_sqlcipherdef test_backup_hmac_detects_tampering(self, tmp_path):"""Modifying backup bytes should cause verification failure.SECURITY: SQLCipher uses HMAC to verify page integrity. Tampering withencrypted data should be detected when attempting to read the database."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_hmac_password"@@ -4348,6 +4335,7 @@ class TestBackupEncryptionVerification:f"Expected integrity error, got: {e}")+ @requires_sqlcipherdef test_backup_kdf_iterations_match_source(self, tmp_path):"""Backup should preserve KDF iteration count from source settings.@@ -4355,20 +4343,17 @@ class TestBackupEncryptionVerification:of password-to-key derivation. Too few iterations make brute-forceattacks easier. This test verifies backups use the expected iterations."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_kdf_password"expected_settings = get_sqlcipher_settings()@@ -4428,6 +4413,7 @@ class TestBackupEncryptionVerification:"This could weaken backup security.")+ @requires_sqlcipherdef test_cipher_integrity_check_validation(self, tmp_path):"""Backup should pass cipher_integrity_check for HMAC validation.@@ -4437,20 +4423,17 @@ class TestBackupEncryptionVerification:Reference: https://www.zetetic.net/sqlcipher/sqlcipher-api/"""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- get_key_from_password,- apply_sqlcipher_pragmas,- get_sqlcipher_settings,- set_sqlcipher_key,- )+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ get_key_from_password,+ apply_sqlcipher_pragmas,+ get_sqlcipher_settings,+ set_sqlcipher_key,+ )- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ sqlcipher = get_sqlcipher_module()password = "test_integrity_check_password"@@ -4547,18 +4530,17 @@ class TestCrashRecoveryEndToEnd:@pytest.fixturedef encrypted_db_with_data(self, tmp_path):"""Create a real encrypted SQLCipher database with known test data."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )-- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):+ if not HAS_SQLCIPHER:pytest.skip("SQLCipher not available")+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )++ sqlcipher = get_sqlcipher_module()db_dir = tmp_path / "encrypted_databases"db_dir.mkdir()@@ -4774,18 +4756,17 @@ class TestPasswordChangeBackupSecurity:@pytest.fixturedef db_with_backup(self, tmp_path):"""Create encrypted DB, take a backup, return paths and passwords."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )-- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):+ if not HAS_SQLCIPHER:pytest.skip("SQLCipher not available")+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )++ sqlcipher = get_sqlcipher_module()db_dir = tmp_path / "encrypted_databases"db_dir.mkdir()@@ -4942,18 +4923,17 @@ class TestBackupCorruptionDetection:@pytest.fixturedef valid_backup(self, tmp_path):"""Create a valid backup file for corruption testing."""- try:- from local_deep_research.database.sqlcipher_compat import (- get_sqlcipher_module,- )- from local_deep_research.database.sqlcipher_utils import (- apply_sqlcipher_pragmas,- set_sqlcipher_key,- )-- sqlcipher = get_sqlcipher_module()- except (ImportError, RuntimeError):+ if not HAS_SQLCIPHER:pytest.skip("SQLCipher not available")+ from local_deep_research.database.sqlcipher_compat import (+ get_sqlcipher_module,+ )+ from local_deep_research.database.sqlcipher_utils import (+ apply_sqlcipher_pragmas,+ set_sqlcipher_key,+ )++ sqlcipher = get_sqlcipher_module()db_dir = tmp_path / "encrypted_databases"db_dir.mkdir()@@ -5209,14 +5189,12 @@ class TestBackupDiskSpaceAndAtomicity:# No .tmp files left behindassert list(backup_dir.glob("*.tmp")) == []+ @requires_sqlcipherdef test_backup_uses_tmp_suffix_pattern(self, tmp_path):"""Backup creates .db.tmp first, renames to .db on success."""- try:- from local_deep_research.database.sqlcipher_utils import (- create_sqlcipher_connection,- )- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ from local_deep_research.database.sqlcipher_utils import (+ create_sqlcipher_connection,+ )db_dir = tmp_path / "encrypted_databases"db_dir.mkdir()@@ -5260,14 +5238,12 @@ class TestBackupDiskSpaceAndAtomicity:assert result.backup_path.suffix == ".db"assert list(backup_dir.glob("*.tmp")) == []+ @requires_sqlcipherdef test_backup_result_has_correct_size(self, tmp_path):"""BackupResult.size_bytes matches actual file size."""- try:- from local_deep_research.database.sqlcipher_utils import (- create_sqlcipher_connection,- )- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ from local_deep_research.database.sqlcipher_utils import (+ create_sqlcipher_connection,+ )db_dir = tmp_path / "encrypted_databases"db_dir.mkdir()@@ -5321,14 +5297,12 @@ class TestBackupDiskSpaceAndAtomicity:class TestBackupFilePermissionsExtended:"""Extended tests for backup file permissions."""+ @requires_sqlcipherdef test_backup_file_has_600_permissions(self, tmp_path):"""Backup files should be owner-read-write only (0o600)."""- try:- from local_deep_research.database.sqlcipher_utils import (- create_sqlcipher_connection,- )- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ from local_deep_research.database.sqlcipher_utils import (+ create_sqlcipher_connection,+ )import sys@@ -5380,14 +5354,12 @@ class TestBackupFilePermissionsExtended:class TestPurgeAndRefreshEdgeCases:"""Tests for purge_and_refresh edge cases."""+ @requires_sqlcipherdef test_purge_with_no_existing_backups(self, tmp_path):"""purge_and_refresh works even when there are no existing backups."""- try:- from local_deep_research.database.sqlcipher_utils import (- create_sqlcipher_connection,- )- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ from local_deep_research.database.sqlcipher_utils import (+ create_sqlcipher_connection,+ )db_dir = tmp_path / "encrypted_databases"db_dir.mkdir()@@ -5429,14 +5401,12 @@ class TestPurgeAndRefreshEdgeCases:assert result.successassert len(list(backup_dir.glob("ldr_backup_*.db"))) == 1+ @requires_sqlcipherdef test_purge_removes_multiple_old_backups(self, tmp_path):"""purge_and_refresh removes all old backups, not just one."""- try:- from local_deep_research.database.sqlcipher_utils import (- create_sqlcipher_connection,- )- except (ImportError, RuntimeError):- pytest.skip("SQLCipher not available")+ from local_deep_research.database.sqlcipher_utils import (+ create_sqlcipher_connection,+ )db_dir = tmp_path / "encrypted_databases"db_dir.mkdir()diff --git a/tests/database/test_credential_store_base.py b/tests/database/test_credential_store_base.pyindex c8faf0e854..15b95a0cc7 100644--- a/tests/database/test_credential_store_base.py+++ b/tests/database/test_credential_store_base.py@@ -1,6 +1,8 @@"""Tests for credential store base class."""-import time+from datetime import timedelta++from freezegun import freeze_timeclass ConcreteCredentialStore:@@ -78,10 +80,11 @@ class TestCredentialStoreBase:def test_expired_entry_returns_none(self):store = ConcreteCredentialStore(ttl_seconds=1) # 1 second TTL- store.store("key1", "user1", "pass1")+ with freeze_time("2024-01-01 00:00:00") as frozen:+ store.store("key1", "user1", "pass1")- # Wait for expiration- time.sleep(1.1) # allow: unmarked-sleep+ # Wait for expiration+ frozen.tick(timedelta(milliseconds=1100))- result = store.retrieve("key1")- assert result is None+ result = store.retrieve("key1")+ assert result is Nonediff --git a/tests/database/test_credential_store_extended.py b/tests/database/test_credential_store_extended.pyindex 7a707605bb..f103ea992c 100644--- a/tests/database/test_credential_store_extended.py+++ b/tests/database/test_credential_store_extended.py@@ -12,8 +12,10 @@ Tests cover:import timeimport threading+from datetime import timedeltaimport pytest+from freezegun import freeze_timefrom local_deep_research.database.credential_store_base import (CredentialStoreBase,@@ -65,10 +67,11 @@ class TestCredentialStoreInitialization:def test_zero_ttl_store(self):"""Store with zero TTL should immediately expire entries."""store = ConcreteCredentialStore(ttl_seconds=0)- store.store("key1", "user", "pass")- # Entry should expire immediately- time.sleep(0.01)- assert store.retrieve("key1") is None+ with freeze_time("2024-01-01 00:00:00") as frozen:+ store.store("key1", "user", "pass")+ # Any forward progress past expires_at causes expiration+ frozen.tick(timedelta(microseconds=1))+ assert store.retrieve("key1") is Noneclass TestCredentialStorage:@@ -158,42 +161,49 @@ class TestTTLExpiration:"""Tests for TTL expiration behavior."""def test_entry_expires_after_ttl(self, short_ttl_store):- """Entry should expire after TTL."""+ """Entry should expire after TTL.++ This test deliberately uses a real ``time.sleep`` instead of+ ``freeze_time`` so that the rest of the freezegun-based suite is+ validated against the actual ``time.time()`` clock at least once.+ Don't migrate this one without keeping another integration anchor.+ """short_ttl_store.store("key1", "user1", "pass1")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) # allow: unmarked-sleep # Half of TTL- assert short_ttl_store.retrieve("key1") == ("user1", "pass1")+ with freeze_time("2024-01-01 00:00:00") as frozen:+ short_ttl_store.store("key1", "user1", "pass1")+ frozen.tick(timedelta(milliseconds=500)) # Half of 1s TTL+ assert short_ttl_store.retrieve("key1") == ("user1", "pass1")def test_each_entry_has_own_ttl(self):"""Each entry should have its own expiration time."""store = ConcreteCredentialStore(ttl_seconds=2)+ with freeze_time("2024-01-01 00:00:00") as frozen:+ store.store("key1", "user1", "pass1")+ frozen.tick(timedelta(seconds=1))+ store.store("key2", "user2", "pass2") # Added 1s later+ frozen.tick(timedelta(milliseconds=1500))- store.store("key1", "user1", "pass1")- time.sleep(1) # allow: unmarked-sleep- store.store("key2", "user2", "pass2") # Added 1s later- time.sleep(1.5) # allow: unmarked-sleep-- # key1 should be expired (2.5s old)- # key2 should still be valid (1.5s old)- assert store.retrieve("key1") is None- assert store.retrieve("key2") == ("user2", "pass2")+ # key1 should be expired (2.5s old)+ # key2 should still be valid (1.5s old)+ assert store.retrieve("key1") is None+ assert store.retrieve("key2") == ("user2", "pass2")def test_overwrite_resets_ttl(self):"""Overwriting an entry should reset its TTL."""store = ConcreteCredentialStore(ttl_seconds=1)+ with freeze_time("2024-01-01 00:00:00") as frozen:+ store.store("key1", "user1", "pass1")+ frozen.tick(timedelta(milliseconds=700))+ store.store("key1", "user1", "pass1") # Reset TTL+ frozen.tick(timedelta(milliseconds=700))- store.store("key1", "user1", "pass1")- time.sleep(0.7) # allow: unmarked-sleep- store.store("key1", "user1", "pass1") # Reset TTL- time.sleep(0.7) # allow: unmarked-sleep-- # Should still be valid (0.7s since reset, TTL is 1s)- assert store.retrieve("key1") == ("user1", "pass1")+ # Should still be valid (0.7s since reset, TTL is 1s)+ assert store.retrieve("key1") == ("user1", "pass1")class TestCleanupExpired:@@ -202,18 +212,18 @@ class TestCleanupExpired:def test_cleanup_removes_expired(self):"""Cleanup should remove expired entries."""store = ConcreteCredentialStore(ttl_seconds=1)+ with freeze_time("2024-01-01 00:00:00") as frozen:+ store.store("key1", "user1", "pass1")+ store.store("key2", "user2", "pass2")+ frozen.tick(timedelta(milliseconds=1500))- store.store("key1", "user1", "pass1")- store.store("key2", "user2", "pass2")- time.sleep(1.5) # allow: unmarked-sleep+ # Trigger cleanup by storing new entry+ store.store("key3", "user3", "pass3")- # Trigger cleanup by storing new entry- store.store("key3", "user3", "pass3")-- # Old entries should be cleaned up- assert store.retrieve("key1") is None- assert store.retrieve("key2") is None- assert store.retrieve("key3") == ("user3", "pass3")+ # Old entries should be cleaned up+ assert store.retrieve("key1") is None+ assert store.retrieve("key2") is None+ assert store.retrieve("key3") == ("user3", "pass3")def test_cleanup_preserves_valid_entries(self, store):"""Cleanup should preserve non-expired entries."""@@ -378,19 +388,19 @@ class TestMemoryManagement:def test_entries_cleaned_up_over_time(self):"""Old entries should be cleaned up."""store = ConcreteCredentialStore(ttl_seconds=1)+ with freeze_time("2024-01-01 00:00:00") as frozen:+ # Add many entries+ for i in range(100):+ store.store(f"key{i}", f"user{i}", f"pass{i}")- # Add many entries- for i in range(100):- store.store(f"key{i}", f"user{i}", f"pass{i}")-- time.sleep(1.5) # allow: unmarked-sleep+ frozen.tick(timedelta(milliseconds=1500))- # Add new entry to trigger cleanup- store.store("new_key", "new_user", "new_pass")+ # Add new entry to trigger cleanup+ store.store("new_key", "new_user", "new_pass")- # Old entries should be gone- assert store.retrieve("key0") is None- assert store.retrieve("new_key") == ("new_user", "new_pass")+ # Old entries should be gone+ assert store.retrieve("key0") is None+ assert store.retrieve("new_key") == ("new_user", "new_pass")class TestEdgeCases:diff --git a/tests/database/test_encrypted_db_extended.py b/tests/database/test_encrypted_db_extended.pyindex 7382c4dbe3..c3fee01305 100644--- a/tests/database/test_encrypted_db_extended.py+++ b/tests/database/test_encrypted_db_extended.py@@ -394,14 +394,9 @@ class TestDatabaseEncryption:def test_encryption_verify_key(self):"""Key verification check."""# Simulate key verification by querying- key_valid = True-- try:- # Would execute: SELECT count(*) FROM sqlite_master- result = 1- key_valid = result >= 0- except Exception:- key_valid = False+ # Would execute: SELECT count(*) FROM sqlite_master+ result = 1+ key_valid = result >= 0assert key_validdiff --git a/tests/document_loaders/test_bytes_loader.py b/tests/document_loaders/test_bytes_loader.pyindex 658eee184e..8050308b7f 100644--- a/tests/document_loaders/test_bytes_loader.py+++ b/tests/document_loaders/test_bytes_loader.py@@ -218,7 +218,8 @@ class TestTempFileCleanup:assert len(new_ldr_files) == 0, "Temp file was not cleaned up"def test_temp_file_cleaned_up_on_error(self) -> None:- """Test that temp file is cleaned up even on error."""+ """Test that temp file is cleaned up even on parse error."""+ import jsonimport osimport tempfile@@ -228,10 +229,13 @@ class TestTempFileCleanup:temp_dir = tempfile.gettempdir()initial_files = set(os.listdir(temp_dir))- # This should still work (JSON loader handles errors gracefully)+ # The JSON loader currently handles parse errors by returning a+ # Document with parse_error=True. If a future implementation switches+ # to raising, only the expected parse-error exception types should be+ # swallowed — anything else is a real bug.try:load_from_bytes(content, ".json", "invalid.json")- except Exception:+ except (json.JSONDecodeError, ValueError):passfinal_files = set(os.listdir(temp_dir))diff --git a/tests/library/download_management/test_database_init.py b/tests/library/download_management/test_database_init.pyindex 344b70856c..1c97ef2c13 100644--- a/tests/library/download_management/test_database_init.py+++ b/tests/library/download_management/test_database_init.py@@ -7,6 +7,8 @@ database initialization module to prevent file descriptor leaks.from unittest.mock import MagicMock, patch+import pytest+class TestInitDatabaseEngineDisposal:"""Tests for engine disposal in init_database()."""@@ -51,10 +53,8 @@ class TestInitDatabaseEngineDisposal:"Table creation failed")- try:+ with pytest.raises(Exception, match="Table creation failed"):init_database()- except Exception:- pass# Engine should still be disposed in finally blockmock_engine.dispose.assert_called_once()@@ -159,10 +159,8 @@ class TestVerifyTableExistsEngineDisposal:mock_create_engine.return_value = mock_enginemock_inspect.side_effect = Exception("Inspection failed")- try:+ with pytest.raises(Exception, match="Inspection failed"):verify_table_exists()- except Exception:- pass# Engine should still be disposed in finally blockmock_engine.dispose.assert_called_once()@@ -190,10 +188,8 @@ class TestVerifyTableExistsEngineDisposal:)mock_inspect.return_value = mock_inspector- try:+ with pytest.raises(Exception, match="Cannot read tables"):verify_table_exists()- except Exception:- pass# Engine should still be disposed in finally blockmock_engine.dispose.assert_called_once()diff --git a/tests/routes/test_settings_routes.py b/tests/routes/test_settings_routes.pyindex ae35fd27ce..f9436156aa 100644--- a/tests/routes/test_settings_routes.py+++ b/tests/routes/test_settings_routes.py@@ -643,44 +643,64 @@ class TestAPIRoutes:class TestLegacyRedirects:- """Tests for legacy route redirects."""-- def test_main_config_redirects(self, app, client):- """Test that /main route exists."""- try:- response = client.get("/settings/main", follow_redirects=False)- # Route exists if we get any response- assert response.status_code in [200, 302, 401, 403, 404, 500]- except Exception:- pass-- def test_collections_redirects(self, app, client):- """Test that /collections route exists."""- try:- response = client.get(- "/settings/collections", follow_redirects=False+ """Tests for legacy route redirects.++ Each legacy route is a `redirect(url_for("settings.settings_page"))`+ behind `@login_required`. With an unauthenticated client, the decorator+ returns `redirect(url_for("auth.login", next=...))` which needs both+ endpoints registered to build URLs successfully — without them the+ redirect raises BuildError (500). The fixture below stubs both endpoints+ so we can assert on the *actual* redirect status, not just "any+ response."+ """++ @pytest.fixture(autouse=True)+ def _register_redirect_targets(self, app):+ """Register stub endpoints for `auth.login` and `settings.settings_page`+ so that legacy-redirect routes can build their target URLs."""++ def _login():+ return "login", 200++ def _settings_page():+ return "settings_page", 200++ # `settings.settings_page` may already be registered by settings_bp; only+ # add a stub if not.+ if "settings.settings_page" not in app.view_functions:+ app.add_url_rule(+ "/settings/",+ endpoint="settings.settings_page",+ view_func=_settings_page,)- assert response.status_code in [200, 302, 401, 403, 404, 500]- except Exception:- pass-- def test_api_keys_redirects(self, app, client):- """Test that /api_keys route exists."""- try:- response = client.get("/settings/api_keys", follow_redirects=False)- assert response.status_code in [200, 302, 401, 403, 404, 500]- except Exception:- pass-- def test_search_engines_redirects(self, app, client):- """Test that /search_engines route exists."""- try:- response = client.get(- "/settings/search_engines", follow_redirects=False- )- assert response.status_code in [200, 302, 401, 403, 404, 500]- except Exception:- pass+ if "auth.login" not in app.view_functions:+ app.add_url_rule("/login", endpoint="auth.login", view_func=_login)++ def test_main_config_redirects(self, client):+ """`/settings/main` redirects (302) to login when unauthenticated."""+ response = client.get("/settings/main", follow_redirects=False)+ assert response.status_code == 302+ assert "/login" in response.headers["Location"]++ def test_collections_redirects(self, client):+ """`/settings/collections` redirects (302) to login when unauthenticated."""+ response = client.get("/settings/collections", follow_redirects=False)+ assert response.status_code == 302+ assert "/login" in response.headers["Location"]++ def test_api_keys_redirects(self, client):+ """`/settings/api_keys` redirects (302) to login when unauthenticated."""+ response = client.get("/settings/api_keys", follow_redirects=False)+ assert response.status_code == 302+ assert "/login" in response.headers["Location"]++ def test_search_engines_redirects(self, client):+ """`/settings/search_engines` redirects (302) to login when unauthenticated."""+ response = client.get(+ "/settings/search_engines", follow_redirects=False+ )+ assert response.status_code == 302+ assert "/login" in response.headers["Location"]class TestSettingFromSession:diff --git a/tests/test_api_settings_e2e.py b/tests/test_api_settings_e2e.pyindex 83f391b8c2..a0de381431 100644--- a/tests/test_api_settings_e2e.py+++ b/tests/test_api_settings_e2e.py@@ -1,6 +1,5 @@"""End-to-end tests for API settings in research workflows."""-import pytestfrom unittest.mock import patch, MagicMockfrom local_deep_research.api import quick_summary, detailed_research@@ -10,15 +9,16 @@ from local_deep_research.api.settings_utils import create_settings_snapshotclass TestE2EResearchWithSettings:"""Test end-to-end research workflows with various settings."""- @pytest.mark.skip(- reason="Requires complex thread context setup - tested via unit tests"- )- @patch("local_deep_research.config.llm_config.get_llm")- @patch(- "local_deep_research.web_search_engines.search_engine_factory.get_search"- )+ @patch("local_deep_research.api.research_functions.get_llm")+ @patch("local_deep_research.api.research_functions.get_search")def test_quick_summary_full_flow(self, mock_get_search, mock_get_llm):- """Test quick_summary with full settings propagation."""+ """Test quick_summary with full settings propagation.++ Patches happen on `api.research_functions` because the names are+ imported into that module at import time — patching the original+ module (`config.llm_config.get_llm`) would not affect already-bound+ references.+ """# Mock LLMmock_llm = MagicMock()mock_llm.invoke.return_value = MagicMock(content="Test summary")@@ -59,27 +59,32 @@ class TestE2EResearchWithSettings:# Verify LLM was configured correctlymock_get_llm.assert_called()- # Verify search was configured correctly+ # Verify search was configured correctly. get_search() takes the+ # tool name as the first positional arg; everything else is in+ # settings_snapshot rather than dedicated kwargs.mock_get_search.assert_called()- search_call_kwargs = mock_get_search.call_args[1]- assert search_call_kwargs["search_tool"] == "duckduckgo"- assert search_call_kwargs["max_results"] == 10- assert search_call_kwargs["region"] == "us-en"+ search_args, search_kwargs = mock_get_search.call_args+ assert search_args[0] == "duckduckgo"+ snapshot = search_kwargs["settings_snapshot"]+ assert snapshot["search.region"]["value"] == "us-en"+ assert snapshot["search.max_results"]["value"] == 10# Verify result structureassert "summary" in resultassert "findings" in resultassert "iterations" in result- @pytest.mark.skip(- reason="Requires complex thread context setup - tested via unit tests"- )- @patch("local_deep_research.config.llm_config.get_llm")- @patch(- "local_deep_research.web_search_engines.search_engine_factory.get_search"- )+ @patch("local_deep_research.api.research_functions.get_llm")+ @patch("local_deep_research.api.research_functions.get_search")def test_detailed_research_full_flow(self, mock_get_search, mock_get_llm):- """Test detailed_research with comprehensive settings."""+ """Test detailed_research with comprehensive settings.++ detailed_research accepts only `settings_snapshot` for configuration+ (unlike quick_summary which has provider/api_key shortcuts), so the+ test builds a snapshot via create_settings_snapshot and threads it+ in directly. Patch targets follow `api.research_functions` because+ that is where get_llm / get_search are imported and bound.+ """# Mock LLM with different responsesmock_llm = MagicMock()mock_llm.invoke.side_effect = [@@ -89,54 +94,35 @@ class TestE2EResearchWithSettings:]mock_get_llm.return_value = mock_llm- # Mock search with evolving resultsmock_search = MagicMock()- mock_search.search.side_effect = [- {- "results": [- {- "title": f"Initial {i}",- "url": f"http://example.com/init{i}",- "snippet": f"Initial snippet {i}",- }- for i in range(3)- ]- },- {- "results": [- {- "title": f"Deep {i}",- "url": f"http://example.com/deep{i}",- "snippet": f"Deep snippet {i}",- }- for i in range(5)- ]- },- ]mock_get_search.return_value = mock_search- # Run detailed research with custom settings- result = detailed_research(- "Explain the applications of quantum computing in cryptography",+ snapshot = create_settings_snapshot(provider="openai",- api_key="test-key",- temperature=0.3,- settings_override={- "research.max_iterations": 3,+ overrides={+ "search.iterations": 3,"search.max_results": 20,"search.engines.arxiv.enabled": True,"llm.max_tokens": 4000,},)- # Verify multiple search calls were made- assert mock_search.search.call_count >= 1+ # Run detailed research with custom settings+ result = detailed_research(+ "Explain the applications of quantum computing in cryptography",+ settings_snapshot=snapshot,+ )- # Verify result has detailed structure- assert "summary" in result- assert "findings" in result- assert "iterations" in result- assert result["iterations"] > 1 # Should do multiple iterations+ # The settings_snapshot values should be threaded through to+ # get_search.+ mock_get_search.assert_called()+ passed_snapshot = mock_get_search.call_args[1]["settings_snapshot"]+ assert passed_snapshot["search.max_results"]["value"] == 20+ assert passed_snapshot["search.iterations"]["value"] == 3++ # Verify the structured-report shape is returned (detailed_research+ # returns a report dict, not a summary dict).+ assert isinstance(result, dict)def test_settings_isolation_between_calls(self):"""Test that settings don't leak between API calls."""@@ -256,14 +242,18 @@ class TestMultiProviderScenarios:class TestSearchEngineIntegration:"""Test integration with various search engines through settings."""- @pytest.mark.skip(- reason="Requires complex thread context setup - tested via unit tests"- )- @patch(- "local_deep_research.web_search_engines.search_engine_factory.get_search"- )- def test_search_engine_specific_settings(self, mock_get_search):- """Test that search engine specific settings are applied."""+ @patch("local_deep_research.api.research_functions.get_llm")+ @patch("local_deep_research.api.research_functions.get_search")+ def test_search_engine_specific_settings(+ self, mock_get_search, mock_get_llm+ ):+ """Test that search engine specific settings are applied.++ Each call's positional first argument identifies the chosen tool;+ engine-specific settings should appear in `settings_snapshot`.+ Patches target `api.research_functions` since that is where the+ names are bound.+ """search_configs = [{"engine": "searxng",@@ -291,30 +281,29 @@ class TestSearchEngineIntegration:},]- mock_search = MagicMock()- mock_search.search.return_value = {"results": []}- mock_get_search.return_value = mock_search-- with patch("local_deep_research.config.llm_config.get_llm") as mock_llm:- mock_llm.return_value = MagicMock()-- for config in search_configs:- _ = quick_summary(- f"Test with {config['engine']}",- provider="openai",- api_key="test-key",- settings_override=config["settings"],+ mock_get_llm.return_value = MagicMock()+ mock_get_search.return_value = MagicMock()++ for config in search_configs:+ _ = quick_summary(+ f"Test with {config['engine']}",+ provider="openai",+ api_key="test-key",+ settings_override=config["settings"],+ )++ # Verify the chosen search engine appears as the first positional+ # argument (the get_search public signature).+ last_args, last_kwargs = mock_get_search.call_args+ assert last_args[0] == config["engine"]++ # Engine-specific overrides must propagate through settings_snapshot.+ snapshot = last_kwargs["settings_snapshot"]+ for key, value in config["settings"].items():+ assert key in snapshot, (+ f"missing snapshot key {key} for {config['engine']}")-- # Verify search engine was configured with correct settings- last_call = mock_get_search.call_args_list[-1][1]- assert last_call["search_tool"] == config["engine"]-- # Verify engine-specific settings were passed- settings_snapshot = last_call.get("settings_snapshot", {})- for key, value in config["settings"].items():- if key in settings_snapshot:- assert settings_snapshot[key].get("value") == value+ assert snapshot[key]["value"] == valueclass TestPerformanceSettings:diff --git a/tests/test_llm_provider_integration.py b/tests/test_llm_provider_integration.pyindex 4fae4481b9..bc91574774 100644--- a/tests/test_llm_provider_integration.py+++ b/tests/test_llm_provider_integration.py@@ -420,7 +420,14 @@ class TestLLMProviderIntegration:== "https://openrouter.ai/api/v1")- @pytest.mark.skip(reason="Requires actual database session with encryption")+ @pytest.mark.integration+ @pytest.mark.skip(+ reason=(+ "BenchmarkService.create_benchmark_run inserts into the encrypted "+ "user database, which the unit-test fixture does not stand up. "+ "Run as part of the integration suite with a real DB session."+ )+ )def test_benchmark_with_api_configured_llm(self, mock_session):"""Test running benchmarks with API-configured LLM."""from local_deep_research.benchmarks.web_api.benchmark_service import (diff --git a/tests/test_search_system_gaps.py b/tests/test_search_system_gaps.pyindex cd283c916f..a8abd5962e 100644--- a/tests/test_search_system_gaps.py+++ b/tests/test_search_system_gaps.py@@ -13,44 +13,56 @@ Focuses on testable pure logic:from unittest.mock import Mock, patch+import pytest+# ----------------------------------------------------------------------------# Helper to create an AdvancedSearchSystem without hitting real imports+# Factory fixture for AdvancedSearchSystem# ----------------------------------------------------------------------------def _make_system(- settings_snapshot=None, strategy_name="source-based", **kwargs-):- """Build an AdvancedSearchSystem with a mocked strategy factory."""- mock_llm = Mock()- mock_search = Mock()-- mock_strategy = Mock()- mock_strategy.questions_by_iteration = {}- mock_strategy.all_links_of_system = []- mock_strategy.set_progress_callback = Mock()- mock_strategy.analyze_topic = Mock(- return_value={- "findings": [],- "current_knowledge": "",- }- )-- with patch(- "local_deep_research.search_system_factory.create_strategy",- return_value=mock_strategy,+def make_system():+ """Factory fixture returning a function that builds an+ AdvancedSearchSystem with a mocked strategy.++ Returns ``(system, mock_strategy)`` so tests can inspect or mutate+ the strategy mock and assert on the system.+ """++ def _factory(+ settings_snapshot=None, strategy_name="source-based", **kwargs):- from local_deep_research.search_system import AdvancedSearchSystem-- system = AdvancedSearchSystem(- llm=mock_llm,- search=mock_search,- strategy_name=strategy_name,- settings_snapshot=settings_snapshot,- **kwargs,+ mock_llm = Mock()+ mock_search = Mock()++ mock_strategy = Mock()+ mock_strategy.questions_by_iteration = {}+ mock_strategy.all_links_of_system = []+ mock_strategy.set_progress_callback = Mock()+ mock_strategy.analyze_topic = Mock(+ return_value={+ "findings": [],+ "current_knowledge": "",+ })- return system, mock_strategy++ with patch(+ "local_deep_research.search_system_factory.create_strategy",+ return_value=mock_strategy,+ ):+ from local_deep_research.search_system import AdvancedSearchSystem++ system = AdvancedSearchSystem(+ llm=mock_llm,+ search=mock_search,+ strategy_name=strategy_name,+ settings_snapshot=settings_snapshot,+ **kwargs,+ )+ return system, mock_strategy++ return _factory# ---------------------------------------------------------------------------@@ -61,31 +73,31 @@ def _make_system(class TestMaxIterationsExtraction:"""AdvancedSearchSystem.__init__ reads max_iterations from settings."""- def test_explicit_value_takes_precedence(self):- system, _ = _make_system(+ def test_explicit_value_takes_precedence(self, make_system):+ system, _ = make_system(settings_snapshot={"search.iterations": {"value": 10}},max_iterations=5,)assert system.max_iterations == 5- def test_dict_with_value_key(self):- system, _ = _make_system(+ def test_dict_with_value_key(self, make_system):+ system, _ = make_system(settings_snapshot={"search.iterations": {"value": 7}},)assert system.max_iterations == 7- def test_plain_value(self):- system, _ = _make_system(+ def test_plain_value(self, make_system):+ system, _ = make_system(settings_snapshot={"search.iterations": 4},)assert system.max_iterations == 4- def test_missing_defaults_to_1(self):- system, _ = _make_system(settings_snapshot={})+ def test_missing_defaults_to_1(self, make_system):+ system, _ = make_system(settings_snapshot={})assert system.max_iterations == 1- def test_none_snapshot_defaults_to_1(self):- system, _ = _make_system(settings_snapshot=None)+ def test_none_snapshot_defaults_to_1(self, make_system):+ system, _ = make_system(settings_snapshot=None)assert system.max_iterations == 1@@ -97,27 +109,27 @@ class TestMaxIterationsExtraction:class TestQuestionsPerIterationExtraction:"""AdvancedSearchSystem.__init__ reads questions_per_iteration from settings."""- def test_explicit_value_takes_precedence(self):- system, _ = _make_system(+ def test_explicit_value_takes_precedence(self, make_system):+ system, _ = make_system(settings_snapshot={"search.questions_per_iteration": {"value": 10}},questions_per_iteration=2,)assert system.questions_per_iteration == 2- def test_dict_with_value_key(self):- system, _ = _make_system(+ def test_dict_with_value_key(self, make_system):+ system, _ = make_system(settings_snapshot={"search.questions_per_iteration": {"value": 5}},)assert system.questions_per_iteration == 5- def test_plain_value(self):- system, _ = _make_system(+ def test_plain_value(self, make_system):+ system, _ = make_system(settings_snapshot={"search.questions_per_iteration": 8},)assert system.questions_per_iteration == 8- def test_missing_defaults_to_3(self):- system, _ = _make_system(settings_snapshot={})+ def test_missing_defaults_to_3(self, make_system):+ system, _ = make_system(settings_snapshot={})assert system.questions_per_iteration == 3@@ -138,14 +150,11 @@ class TestPerformSearchSettingsExtraction:with patch("local_deep_research.news.core.search_integration.NewsSearchCallback",):- try:- system._perform_search("q", "id1", True, False, "user1")- except Exception:- pass+ system._perform_search("q", "id1", True, False, "user1")return calls- def test_extracts_from_dict_with_value(self):- system, _ = _make_system(+ def test_extracts_from_dict_with_value(self, make_system):+ system, _ = make_system(settings_snapshot={"llm.provider": {"value": "openai"},"llm.model": {"value": "gpt-4"},@@ -155,8 +164,8 @@ class TestPerformSearchSettingsExtraction:calls = self._run_perform_search(system)assert any("openai" in c[0] or "gpt-4" in c[0] for c in calls)- def test_extracts_plain_values(self):- system, _ = _make_system(+ def test_extracts_plain_values(self, make_system):+ system, _ = make_system(settings_snapshot={"llm.provider": "anthropic","llm.model": "claude",@@ -166,14 +175,14 @@ class TestPerformSearchSettingsExtraction:calls = self._run_perform_search(system)assert any("anthropic" in c[0] or "claude" in c[0] for c in calls)- def test_missing_settings_use_unknown(self):- system, _ = _make_system(settings_snapshot={})+ def test_missing_settings_use_unknown(self, make_system):+ system, _ = make_system(settings_snapshot={})calls = self._run_perform_search(system)assert any("unknown" in c[0] for c in calls)- def test_search_tool_default_from_dict(self):+ def test_search_tool_default_from_dict(self, make_system):"""search.tool dict without 'value' key defaults to 'searxng'."""- system, _ = _make_system(+ system, _ = make_system(settings_snapshot={"search.tool": {"other": "x"}},)calls = self._run_perform_search(system)@@ -189,10 +198,10 @@ class TestPerformSearchSettingsExtraction:class TestAllLinksDedup:"""_perform_search avoids extending all_links when objects are same."""- def test_same_object_no_duplication(self):+ def test_same_object_no_duplication(self, make_system):"""When strategy.all_links_of_system IS system.all_links_of_system,no extension should happen (prevents issue #301)."""- system, mock_strategy = _make_system(settings_snapshot={})+ system, mock_strategy = make_system(settings_snapshot={})# Make them the same objectmock_strategy.all_links_of_system = system.all_links_of_system@@ -201,27 +210,21 @@ class TestAllLinksDedup:with patch("local_deep_research.news.core.search_integration.NewsSearchCallback",):- try:- system._perform_search("q", "id1", True, False, "user1")- except Exception:- pass+ system._perform_search("q", "id1", True, False, "user1")# Should NOT be doubledassert len(system.all_links_of_system) == 1- def test_different_objects_extends(self):+ def test_different_objects_extends(self, make_system):"""When they are different objects, links should be extended."""- system, mock_strategy = _make_system(settings_snapshot={})+ system, mock_strategy = make_system(settings_snapshot={})mock_strategy.all_links_of_system = [{"link": "https://b.com"}]with patch("local_deep_research.news.core.search_integration.NewsSearchCallback",):- try:- system._perform_search("q", "id1", True, False, "user1")- except Exception:- pass+ system._perform_search("q", "id1", True, False, "user1")assert {"link": "https://b.com"} in system.all_links_of_system@@ -234,8 +237,8 @@ class TestAllLinksDedup:class TestClose:"""AdvancedSearchSystem.close cascades to strategy."""- def test_close_calls_safe_close_on_strategy(self):- system, mock_strategy = _make_system(settings_snapshot={})+ def test_close_calls_safe_close_on_strategy(self, make_system):+ system, mock_strategy = make_system(settings_snapshot={})with patch("local_deep_research.utilities.resource_utils.safe_close"@@ -245,9 +248,9 @@ class TestClose:mock_strategy, "search strategy")- def test_close_without_strategy_attribute(self):+ def test_close_without_strategy_attribute(self, make_system):"""close() should not raise if strategy attribute is missing."""- system, _ = _make_system(settings_snapshot={})+ system, _ = make_system(settings_snapshot={})del system.strategywith patch(@@ -263,8 +266,8 @@ class TestClose:class TestSetProgressCallback:- def test_callback_set_on_system_and_strategy(self):- system, mock_strategy = _make_system(settings_snapshot={})+ def test_callback_set_on_system_and_strategy(self, make_system):+ system, mock_strategy = make_system(settings_snapshot={})cb = Mock()system.set_progress_callback(cb)@@ -279,8 +282,8 @@ class TestSetProgressCallback:class TestAnalyzeTopicSearchId:- def test_generates_uuid_when_search_id_is_none(self):- system, _ = _make_system(settings_snapshot={})+ def test_generates_uuid_when_search_id_is_none(self, make_system):+ system, _ = make_system(settings_snapshot={})with patch.object(system, "_perform_search", return_value={}@@ -292,8 +295,8 @@ class TestAnalyzeTopicSearchId:assert len(search_id) == 36assert search_id.count("-") == 4- def test_uses_provided_search_id(self):- system, _ = _make_system(settings_snapshot={})+ def test_uses_provided_search_id(self, make_system):+ system, _ = make_system(settings_snapshot={})with patch.object(system, "_perform_search", return_value={}@@ -310,10 +313,10 @@ class TestAnalyzeTopicSearchId:class TestProgrammaticMode:- def test_programmatic_mode_stored(self):- system, _ = _make_system(settings_snapshot={}, programmatic_mode=True)+ def test_programmatic_mode_stored(self, make_system):+ system, _ = make_system(settings_snapshot={}, programmatic_mode=True)assert system.programmatic_mode is True- def test_non_programmatic_mode_default(self):- system, _ = _make_system(settings_snapshot={})+ def test_non_programmatic_mode_default(self, make_system):+ system, _ = make_system(settings_snapshot={})assert system.programmatic_mode is Falsediff --git a/tests/web/test_app_main_coverage.py b/tests/web/test_app_main_coverage.pyindex 3ba2119b1c..e88bf43e77 100644--- a/tests/web/test_app_main_coverage.py+++ b/tests/web/test_app_main_coverage.py@@ -492,12 +492,18 @@ class TestMainShutdownSchedulerAtexit:mock_app = MagicMock(spec=[])captured = self._run_and_capture(mock_app)- # Must not raise+ # The atexit handlers registered by app.main() must not raise even+ # when the app has no news_scheduler attribute. Collect any errors+ # explicitly so the assertion fails loudly if a handler does raise.+ errors = []for handler in captured:try:handler()- except Exception:- pass+ except Exception as exc:+ errors.append(exc)+ assert errors == [], (+ f"atexit handlers raised when app has no news_scheduler: {errors}"+ )def test_news_scheduler_stop_exception_is_swallowed(self):"""shutdown_scheduler swallows exceptions from news_scheduler.stop()."""@@ -508,12 +514,20 @@ class TestMainShutdownSchedulerAtexit:)captured = self._run_and_capture(mock_app)- # Must not raise+ # Even though stop() raises RuntimeError, the SUT's shutdown_scheduler+ # closure swallows it so the atexit chain keeps running. Collect any+ # errors that escape — there should be none.+ errors = []for handler in captured:try:handler()- except Exception:- pass+ except Exception as exc:+ errors.append(exc)+ assert errors == [], (+ f"atexit handlers leaked exceptions despite swallow: {errors}"+ )+ # And confirm the swallowed call actually happened.+ mock_app.background_job_scheduler.stop.assert_called_once()# ---------------------------------------------------------------------------