@@ -2043,6 +2043,69 @@ def test_multiple_stores_attribute_not_in_mapping(
20432043 )
20442044 assert source == "vs-unknown"
20452045
2046+ def test_multiple_stores_source_attribute_fallback (
2047+ self , mocker : MockerFixture
2048+ ) -> None :
2049+ """Test resolution falls back to source attribute when no vector_store_id."""
2050+ mock_result = mocker .Mock ()
2051+ mock_result .filename = "file-abc123"
2052+ mock_result .attributes = {"source" : "ocp-documentation" }
2053+
2054+ source = _resolve_source_for_result (
2055+ mock_result ,
2056+ ["vs-001" , "vs-002" ],
2057+ {"vs-001" : "ocp-4.18-docs" },
2058+ )
2059+ assert source == "ocp-documentation"
2060+
2061+ def test_multiple_stores_source_attribute_ignores_mapping (
2062+ self , mocker : MockerFixture
2063+ ) -> None :
2064+ """Test source attribute is returned directly without rag_id_mapping lookup."""
2065+ mock_result = mocker .Mock ()
2066+ mock_result .filename = "file-abc123"
2067+ mock_result .attributes = {"source" : "custom-index" }
2068+
2069+ source = _resolve_source_for_result (
2070+ mock_result ,
2071+ ["vs-001" , "vs-002" ],
2072+ {"custom-index" : "should-not-be-used" },
2073+ )
2074+ assert source == "custom-index"
2075+
2076+ def test_multiple_stores_source_preferred_over_vector_store_id (
2077+ self , mocker : MockerFixture
2078+ ) -> None :
2079+ """Test source attribute takes precedence over vector_store_id."""
2080+ mock_result = mocker .Mock ()
2081+ mock_result .filename = "file-abc123"
2082+ mock_result .attributes = {
2083+ "vector_store_id" : "vs-002" ,
2084+ "source" : "ocp-documentation" ,
2085+ }
2086+
2087+ source = _resolve_source_for_result (
2088+ mock_result ,
2089+ ["vs-001" , "vs-002" ],
2090+ {"vs-002" : "rhel-9-docs" },
2091+ )
2092+ assert source == "ocp-documentation"
2093+
2094+ def test_multiple_stores_no_vector_store_id_no_source (
2095+ self , mocker : MockerFixture
2096+ ) -> None :
2097+ """Test resolution returns None when neither vector_store_id nor source present."""
2098+ mock_result = mocker .Mock ()
2099+ mock_result .filename = "file-abc123"
2100+ mock_result .attributes = {"title" : "some doc" }
2101+
2102+ source = _resolve_source_for_result (
2103+ mock_result ,
2104+ ["vs-001" , "vs-002" ],
2105+ {"vs-001" : "ocp-docs" },
2106+ )
2107+ assert source is None
2108+
20462109
20472110class TestBuildChunkAttributes :
20482111 """Tests for _build_chunk_attributes function."""
0 commit comments