Bahn: aisupport, Analyse-O2C-C2S, awesome-bahn-mcp-servers, beam-mcp,
Confluence_Bot, db-planet-mcp-server, O2C-Harness, project-audit,
Projekt-KIQ-HP, teamlandkarte-mcp
Dhive: Jury-Voting
Privat: CV, NoteGraph (NOTE: NoteGraph needs complete redo after consolidation)
Shared: AI-Orchestrator, OrgMyLife, power_skills_and_more
Shared/references: symphony (read-only)
Bahn repos remain available as independent remotes - this monorepo
pulls them in via subtree, the originals are untouched.
119 lines
3.0 KiB
Python
119 lines
3.0 KiB
Python
"""Unit tests for ``MatchingConfig.default_method`` validation in ``load_config``.
|
|
|
|
Covers the three cases from spec task 5.3:
|
|
|
|
* ``default_method`` missing -> default ``"score"``.
|
|
* ``default_method = "llm_fulltext"`` -> accepted as-is.
|
|
* ``default_method = "irgendwas"`` -> ``ConfigError`` with helpful message.
|
|
|
|
Validates: Requirements 12.3, 12.4
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from teamlandkarte_mcp.config import ConfigError, load_config
|
|
|
|
|
|
def _write_config(tmp_path, *, default_method_line: str = ""):
|
|
"""Write a minimal valid ``config.toml`` for ``load_config`` tests.
|
|
|
|
``default_method_line`` is inserted into the ``[matching]`` section as a
|
|
raw TOML line (e.g. ``'default_method = "llm_fulltext"'``) or left empty
|
|
to omit the key entirely.
|
|
"""
|
|
|
|
content = f"""\
|
|
[database]
|
|
backend = "trino"
|
|
host = "trino.example"
|
|
port = 443
|
|
http_scheme = "https"
|
|
verify_ssl = true
|
|
catalog = "hive"
|
|
schema = "tier1_open_lake"
|
|
connect_timeout = 10
|
|
pool_size = 4
|
|
|
|
[matching]
|
|
competence_weight = 0.8
|
|
role_weight = 0.2
|
|
require_confirmation = true
|
|
{default_method_line}
|
|
|
|
[matching.thresholds]
|
|
top = 0.8
|
|
good = 0.65
|
|
partial = 0.5
|
|
low = 0.3
|
|
|
|
[matching.fuzzy]
|
|
min_similarity = 0.7
|
|
|
|
[cache]
|
|
db_ttl_hours = 12
|
|
search_ttl_minutes = 60
|
|
max_size = 100
|
|
|
|
[azure_openai]
|
|
endpoint = "https://example.openai.azure.com"
|
|
api_version = "2024-02-15-preview"
|
|
chat_deployment = "gpt-4"
|
|
show_costs_in_output = false
|
|
"""
|
|
p = tmp_path / "config.toml"
|
|
p.write_text(content)
|
|
return p
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _set_env(monkeypatch):
|
|
"""Provide the credentials required by ``load_config``."""
|
|
|
|
monkeypatch.setenv("DATA_LAKE_USERNAME", "u")
|
|
monkeypatch.setenv("DATA_LAKE_PASSWORD", "p")
|
|
monkeypatch.setenv("AZURE_OPENAI_LLM_API_KEY", "k")
|
|
|
|
|
|
def test_default_method_missing_falls_back_to_score(tmp_path):
|
|
path = _write_config(tmp_path)
|
|
cfg = load_config(path)
|
|
assert cfg.matching.default_method == "score"
|
|
|
|
|
|
def test_default_method_llm_fulltext_is_accepted(tmp_path):
|
|
path = _write_config(
|
|
tmp_path, default_method_line='default_method = "llm_fulltext"'
|
|
)
|
|
cfg = load_config(path)
|
|
assert cfg.matching.default_method == "llm_fulltext"
|
|
|
|
|
|
def test_default_method_score_is_accepted_explicit(tmp_path):
|
|
path = _write_config(
|
|
tmp_path, default_method_line='default_method = "score"'
|
|
)
|
|
cfg = load_config(path)
|
|
assert cfg.matching.default_method == "score"
|
|
|
|
|
|
def test_default_method_case_insensitive(tmp_path):
|
|
path = _write_config(
|
|
tmp_path, default_method_line='default_method = "LLM_FULLTEXT"'
|
|
)
|
|
cfg = load_config(path)
|
|
assert cfg.matching.default_method == "llm_fulltext"
|
|
|
|
|
|
def test_default_method_invalid_raises_config_error(tmp_path):
|
|
path = _write_config(
|
|
tmp_path, default_method_line='default_method = "irgendwas"'
|
|
)
|
|
with pytest.raises(ConfigError) as exc:
|
|
load_config(path)
|
|
msg = str(exc.value)
|
|
assert "default_method" in msg
|
|
assert "score" in msg
|
|
assert "llm_fulltext" in msg
|