Files
ThothII/harness/tests/test_p3_dwh_binding.py
T

63 lines
2.5 KiB
Python

import pytest
def _cfg(tmp_path, **overrides):
base = {
"dwh": {
"type": "thoth_rest",
"database": {"database": "warehouse", "schema": "dw"},
"endpoint": {"base_url": "http://dwh.example.invalid", "api_key": "secret"},
},
"vectors": {"type": "qdrant", "base_url": "http://qdrant:6333", "collection": "psd", "collection_lifecycle": "self_heal"},
"embeddings": {"provider": "ollama_internal", "base_url": "http://embedding:11434", "model": "qwen3-embedding:0.6b", "dimensions": 1024},
"roots": {"artifacts": str(tmp_path / "artifacts"), "indexes": str(tmp_path / "indexes")},
"paths": {"artifacts": str(tmp_path / "artifacts"), "indexes": str(tmp_path / "indexes"), "sessions": str(tmp_path / "sessions")},
}
base.update(overrides)
return base
def _write_cfg(tmp_path, raw):
import yaml as _yaml
from tht.config import load_config
path = tmp_path / "config.yaml"
path.write_text(_yaml.safe_dump(raw), encoding="utf-8")
cfg = load_config(path)
cfg._workspace_id = "psd"
cfg._config_source = "workspace://psd"
return cfg
@pytest.fixture()
def binding(tmp_path):
from tht.jobs.dwh_pipeline import config_dwh_binding
return config_dwh_binding(_write_cfg(tmp_path, _cfg(tmp_path)))
def test_binding_has_versioned_fingerprints(binding):
assert binding["workspace_id"] == "psd"
assert binding["config_fingerprint"].startswith("sha256:")
assert binding["input_fingerprint"].startswith("sha256:")
assert len(binding["config_fingerprint"]) == 71
def test_content_only_change_keeps_binding(tmp_path):
from tht.jobs.dwh_pipeline import config_dwh_binding
cfg1 = _write_cfg(tmp_path, _cfg(tmp_path))
import copy
raw = copy.deepcopy(_cfg(tmp_path))
raw["vectors"]["collection_lifecycle"] = "require_existing"
cfg3 = _write_cfg(tmp_path, raw)
assert config_dwh_binding(cfg1)["config_fingerprint"] == config_dwh_binding(cfg3)["config_fingerprint"]
def test_endpoint_change_changes_binding(tmp_path):
from tht.jobs.dwh_pipeline import config_dwh_binding
cfg1 = _write_cfg(tmp_path, _cfg(tmp_path))
raw = _cfg(tmp_path)
raw["dwh"] = {"type": "thoth_rest", "database": {"database": "warehouse", "schema": "dw"}, "endpoint": {"base_url": "http://other.example.invalid", "api_key": "secret"}}
cfg2 = _write_cfg(tmp_path, raw)
assert config_dwh_binding(cfg1)["config_fingerprint"] != config_dwh_binding(cfg2)["config_fingerprint"]