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