study-buddy / tests /rag /test_pipeline_version.py
GitHub Actions
deploy d092bea3608b7a29952f16357fda39b7a29e399b
2e818da
Raw
History Blame Contribute Delete
2.32 kB
"""Tests for `app.rag.pipeline_version` (Task 8, Step 1).
Two things must be provably true before any dedup mechanism gets built on
top of this registry:
1. `rag-naive-v1` is frozen -- exactly `dedup_enabled=False`,
`overfetch_factor=1` -- forever. If someone edits the registry entry by
accident while working on `rag-dedup-v2`, this test catches it.
2. The unspecified/default path (`get_pipeline_version(None)`) resolves to
that exact frozen v1 behavior, so every ordinary product call site that
never passes a pipeline version is provably unaffected by anything
registered here.
An unknown, explicitly-requested version name is a hard error, never a
silent fallback to v1 -- see `UnknownPipelineVersionError`.
"""
from __future__ import annotations
import pytest
from app.rag.pipeline_version import (
DEFAULT_PIPELINE_VERSION,
PipelineVersion,
UnknownPipelineVersionError,
get_pipeline_version,
registered_versions,
)
def test_naive_v1_is_registered_and_frozen():
pv = get_pipeline_version("rag-naive-v1")
assert pv == PipelineVersion(
name="rag-naive-v1", dedup_enabled=False, overfetch_factor=1
)
def test_dedup_v2_is_registered_with_overfetch_and_dedup_enabled():
pv = get_pipeline_version("rag-dedup-v2")
assert pv.dedup_enabled is True
assert pv.overfetch_factor > 1
def test_default_none_resolves_to_naive_v1_exactly():
default_pv = get_pipeline_version(None)
explicit_v1 = get_pipeline_version("rag-naive-v1")
assert default_pv == explicit_v1
assert default_pv.name == DEFAULT_PIPELINE_VERSION
assert default_pv.dedup_enabled is False
assert default_pv.overfetch_factor == 1
def test_unknown_explicit_version_raises():
with pytest.raises(UnknownPipelineVersionError):
get_pipeline_version("rag-reranked-v3-does-not-exist")
def test_unknown_version_error_message_lists_registered_versions():
with pytest.raises(UnknownPipelineVersionError) as exc_info:
get_pipeline_version("not-a-real-version")
message = str(exc_info.value)
assert "rag-naive-v1" in message
assert "rag-dedup-v2" in message
def test_registered_versions_contains_both_known_versions():
versions = registered_versions()
assert "rag-naive-v1" in versions
assert "rag-dedup-v2" in versions