7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
104 lines
3.5 KiB
Python
104 lines
3.5 KiB
Python
"""
|
|
Tests for get_user_database_filename() and get_data_directory() in paths.py.
|
|
|
|
Covers SHA-256 hash-based filename generation and LDR_DATA_DIR env var override.
|
|
"""
|
|
|
|
import hashlib
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
|
|
def _get_user_db_fn():
|
|
from local_deep_research.config.paths import get_user_database_filename
|
|
|
|
return get_user_database_filename
|
|
|
|
|
|
def _get_data_dir_fn():
|
|
from local_deep_research.config.paths import get_data_directory
|
|
|
|
return get_data_directory
|
|
|
|
|
|
class TestGetUserDatabaseFilename:
|
|
"""Tests for get_user_database_filename()."""
|
|
|
|
def test_basic_username(self):
|
|
expected_hash = hashlib.sha256("alice".encode()).hexdigest()[:16]
|
|
result = _get_user_db_fn()("alice")
|
|
assert result == f"ldr_user_{expected_hash}.db"
|
|
|
|
def test_deterministic(self):
|
|
fn = _get_user_db_fn()
|
|
assert fn("alice") == fn("alice")
|
|
|
|
def test_different_users_different_filenames(self):
|
|
fn = _get_user_db_fn()
|
|
assert fn("alice") != fn("bob")
|
|
|
|
def test_case_sensitive(self):
|
|
fn = _get_user_db_fn()
|
|
assert fn("Alice") != fn("alice")
|
|
|
|
def test_special_characters_safe(self):
|
|
result = _get_user_db_fn()("user@domain.com")
|
|
assert "@" not in result
|
|
assert result.startswith("ldr_user_")
|
|
assert result.endswith(".db")
|
|
|
|
def test_unicode_username(self):
|
|
result = _get_user_db_fn()("用户")
|
|
assert result.startswith("ldr_user_")
|
|
assert result.endswith(".db")
|
|
# Extract hash portion and verify it's 16-char hex
|
|
hash_part = result[len("ldr_user_") : -len(".db")]
|
|
assert len(hash_part) == 16
|
|
assert all(c in "0123456789abcdef" for c in hash_part)
|
|
|
|
|
|
class TestGetDataDirectory:
|
|
"""Tests for get_data_directory()."""
|
|
|
|
def test_ldr_data_dir_set(self, monkeypatch):
|
|
monkeypatch.setenv("LDR_DATA_DIR", "/tmp/custom")
|
|
result = _get_data_dir_fn()()
|
|
assert result == Path("/tmp/custom")
|
|
|
|
def test_ldr_data_dir_empty_falls_through(self, monkeypatch):
|
|
monkeypatch.setenv("LDR_DATA_DIR", "")
|
|
with patch(
|
|
"local_deep_research.config.paths.platformdirs.user_data_dir",
|
|
return_value="/fake/platformdirs/local-deep-research",
|
|
):
|
|
result = _get_data_dir_fn()()
|
|
assert "local-deep-research" in str(result)
|
|
|
|
def test_ldr_data_dir_unset_uses_platformdirs(self, monkeypatch):
|
|
monkeypatch.delenv("LDR_DATA_DIR", raising=False)
|
|
with patch(
|
|
"local_deep_research.config.paths.platformdirs.user_data_dir",
|
|
return_value="/fake/platformdirs/local-deep-research",
|
|
):
|
|
result = _get_data_dir_fn()()
|
|
assert result == Path("/fake/platformdirs/local-deep-research")
|
|
|
|
def test_returns_path_object(self, monkeypatch):
|
|
monkeypatch.setenv("LDR_DATA_DIR", "/tmp/test")
|
|
result = _get_data_dir_fn()()
|
|
assert isinstance(result, Path)
|
|
|
|
def test_platformdirs_path_contains_app_name(self, monkeypatch):
|
|
monkeypatch.delenv("LDR_DATA_DIR", raising=False)
|
|
with patch(
|
|
"local_deep_research.config.paths.platformdirs.user_data_dir",
|
|
return_value="/home/user/.local/share/local-deep-research",
|
|
):
|
|
result = _get_data_dir_fn()()
|
|
assert "local-deep-research" in str(result)
|
|
|
|
def test_ldr_data_dir_with_spaces(self, monkeypatch):
|
|
monkeypatch.setenv("LDR_DATA_DIR", "/tmp/my data")
|
|
result = _get_data_dir_fn()()
|
|
assert result == Path("/tmp/my data")
|