1+ """Unit tests for RerankerConfiguration model."""
2+
3+ import pytest
4+ from pydantic import ValidationError
5+
6+ from models .config import RerankerConfiguration
7+
8+
9+ class TestRerankerConfiguration :
10+ """Tests for RerankerConfiguration model."""
11+
12+ def test_default_values (self ) -> None :
13+ """Test that RerankerConfiguration has correct default values."""
14+ config = RerankerConfiguration ()
15+ assert config .enabled is True
16+ assert config .model == "cross-encoder/ms-marco-MiniLM-L6-v2"
17+ assert config .top_k_multiplier == 2.0
18+ assert config .byok_boost == 1.2
19+ assert config .okp_boost == 1.0
20+
21+ def test_custom_model (self ) -> None :
22+ """Test configuration with custom cross-encoder model."""
23+ config = RerankerConfiguration (
24+ model = "cross-encoder/ms-marco-TinyBERT-L2-v2"
25+ )
26+ assert config .model == "cross-encoder/ms-marco-TinyBERT-L2-v2"
27+ assert config .enabled is True
28+
29+ def test_disabled_reranker (self ) -> None :
30+ """Test configuration with reranker disabled."""
31+ config = RerankerConfiguration (enabled = False )
32+ assert config .enabled is False
33+ assert config .model == "cross-encoder/ms-marco-MiniLM-L6-v2"
34+
35+ def test_custom_boost_factors (self ) -> None :
36+ """Test configuration with custom boost factors."""
37+ config = RerankerConfiguration (
38+ byok_boost = 1.5 ,
39+ okp_boost = 0.8
40+ )
41+ assert config .byok_boost == 1.5
42+ assert config .okp_boost == 0.8
43+
44+ def test_custom_top_k_multiplier (self ) -> None :
45+ """Test configuration with custom top_k_multiplier."""
46+ config = RerankerConfiguration (top_k_multiplier = 3.0 )
47+ assert config .top_k_multiplier == 3.0
48+
49+ def test_all_custom_values (self ) -> None :
50+ """Test configuration with all custom values."""
51+ config = RerankerConfiguration (
52+ enabled = False ,
53+ model = "custom-cross-encoder" ,
54+ top_k_multiplier = 1.5 ,
55+ byok_boost = 2.0 ,
56+ okp_boost = 0.5
57+ )
58+ assert config .enabled is False
59+ assert config .model == "custom-cross-encoder"
60+ assert config .top_k_multiplier == 1.5
61+ assert config .byok_boost == 2.0
62+ assert config .okp_boost == 0.5
63+
64+ def test_explicit_configuration_detection (self ) -> None :
65+ """Test that explicitly configured values are detected."""
66+ # Non-default values should mark as explicitly configured
67+ config = RerankerConfiguration (enabled = False )
68+ assert hasattr (config , "_explicitly_configured" )
69+ # Note: The actual _explicitly_configured logic is private
70+ # and tested through integration tests
71+
72+ def test_invalid_field_rejected (self ) -> None :
73+ """Test that invalid fields are rejected due to extra='forbid'."""
74+ with pytest .raises (ValidationError ):
75+ RerankerConfiguration (invalid_field = "value" )
0 commit comments