65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
"""Regression tests for production backup wiring."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture()
|
|
def backup_script() -> object:
|
|
path = Path(__file__).parents[3] / "scripts" / "backup.py"
|
|
spec = importlib.util.spec_from_file_location("backup_script", path)
|
|
assert spec is not None and spec.loader is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
async def test_active_profile_provenance_contains_only_active_non_secret_revisions(
|
|
backup_script: object, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
class EmbeddingStore:
|
|
def __init__(self, path: Path) -> None:
|
|
pass
|
|
|
|
async def get_active(self) -> object:
|
|
return SimpleNamespace(profile="hybrid-v1", version="v3")
|
|
|
|
class GenerationStore:
|
|
def __init__(self, session_factory: object) -> None:
|
|
pass
|
|
|
|
async def get_active(self) -> object:
|
|
return SimpleNamespace(profile="answer-local", version="v1")
|
|
|
|
monkeypatch.setattr(backup_script, "JsonEmbeddingProfileStore", EmbeddingStore)
|
|
monkeypatch.setattr(backup_script, "PostgresGenerationProfileStore", GenerationStore)
|
|
result = await backup_script.active_profile_provenance(
|
|
settings=SimpleNamespace(embedding_profiles_path=Path("profiles.json")),
|
|
session_factory=object(),
|
|
)
|
|
assert result == {"embedding": "hybrid-v1:v3", "generation": "answer-local:v1"}
|
|
|
|
|
|
async def test_active_profile_provenance_allows_missing_optional_profiles(
|
|
backup_script: object, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
class EmptyStore:
|
|
def __init__(self, _: object) -> None:
|
|
pass
|
|
|
|
async def get_active(self) -> None:
|
|
return None
|
|
|
|
monkeypatch.setattr(backup_script, "JsonEmbeddingProfileStore", EmptyStore)
|
|
monkeypatch.setattr(backup_script, "PostgresGenerationProfileStore", EmptyStore)
|
|
result = await backup_script.active_profile_provenance(
|
|
settings=SimpleNamespace(embedding_profiles_path=Path("profiles.json")),
|
|
session_factory=object(),
|
|
)
|
|
assert result == {}
|