Files
mdmem/tests/test_config.py
T
Markus d9b42e3432 feat(p0): repo skeleton — pyproject, config, JSON logging, CLI, Containerfile
Non-root, read-only-rootfs image with HOME/XDG_CACHE_HOME on /tmp so nothing
writes outside /data and /tmp (§13a.3, §14.16).
2026-09-12 07:41:44 +00:00

62 lines
2.1 KiB
Python

import pytest
from mdmem.config import Settings
def test_defaults_match_plan(tmp_path, monkeypatch):
monkeypatch.setenv("VAULT_DIR", str(tmp_path / "vault"))
s = Settings.from_env()
assert s.embed_dim == 2560
assert s.fusion == "rrf"
assert s.inbox_weight == pytest.approx(0.8)
assert s.bm25_weights == (3.0, 2.0, 1.5, 1.0)
assert s.dup_threshold == pytest.approx(0.90)
assert s.max_note_chars == 8000
assert s.max_chars_default == 6000
assert s.min_score is None
assert s.include_inbox_default is True
assert s.fts_trigram is True
def test_paths_derive_from_vault_parent(tmp_path, monkeypatch):
monkeypatch.setenv("VAULT_DIR", str(tmp_path / "vault"))
monkeypatch.setenv("INDEX_DB", str(tmp_path / "index.db"))
s = Settings.from_env()
assert s.index_db == tmp_path / "index.db"
assert s.vault_dir == tmp_path / "vault"
def test_bm25_weights_parsed(monkeypatch, tmp_path):
monkeypatch.setenv("VAULT_DIR", str(tmp_path))
monkeypatch.setenv("BM25_WEIGHTS", "1,2,3,4")
assert Settings.from_env().bm25_weights == (1.0, 2.0, 3.0, 4.0)
def test_bad_bm25_weights_rejected(monkeypatch, tmp_path):
monkeypatch.setenv("VAULT_DIR", str(tmp_path))
monkeypatch.setenv("BM25_WEIGHTS", "1,2,3")
with pytest.raises(ValueError, match="BM25_WEIGHTS"):
Settings.from_env()
def test_bad_fusion_rejected(monkeypatch, tmp_path):
monkeypatch.setenv("VAULT_DIR", str(tmp_path))
monkeypatch.setenv("FUSION", "magic")
with pytest.raises(ValueError, match="FUSION"):
Settings.from_env()
def test_addr_parsing(monkeypatch, tmp_path):
monkeypatch.setenv("VAULT_DIR", str(tmp_path))
monkeypatch.setenv("MCP_ADDR", "0.0.0.0:9999")
s = Settings.from_env()
assert s.mcp_host == "0.0.0.0" and s.mcp_port == 9999
def test_empty_min_score_is_none(monkeypatch, tmp_path):
monkeypatch.setenv("VAULT_DIR", str(tmp_path))
monkeypatch.setenv("MIN_SCORE", "")
assert Settings.from_env().min_score is None
monkeypatch.setenv("MIN_SCORE", "0.2")
assert Settings.from_env().min_score == pytest.approx(0.2)