@@ -542,3 +542,42 @@ async def test_query_invalid_include():
542542 action = CliAction .query , include = [QueryInclude .chunk , QueryInclude .document ]
543543 )
544544 assert await query (faulty_config ) != 0
545+
546+
547+ @pytest .mark .asyncio
548+ async def test_query_chunk_mode_no_metadata_fallback (mock_config ):
549+ mock_config .include = [QueryInclude .chunk , QueryInclude .path ]
550+ mock_client = AsyncMock ()
551+ mock_collection = AsyncMock ()
552+
553+ # Mock collection.get to return no IDs for the metadata check
554+ mock_collection .get .return_value = {"ids" : []}
555+
556+ with (
557+ patch ("vectorcode.subcommands.query.get_client" , return_value = mock_client ),
558+ patch (
559+ "vectorcode.subcommands.query.get_collection" , return_value = mock_collection
560+ ),
561+ patch ("vectorcode.subcommands.query.verify_ef" , return_value = True ),
562+ patch ("vectorcode.subcommands.query.build_query_results" ) as mock_build_results ,
563+ patch ("sys.stderr" ) as mock_stderr ,
564+ ):
565+ mock_build_results .return_value = [] # Return empty results for simplicity
566+
567+ result = await query (mock_config )
568+
569+ assert result == 0
570+
571+ # Verify the metadata check call
572+ mock_collection .get .assert_called_once_with (where = {"start" : {"$gte" : 0 }})
573+
574+ # Verify the warning was printed
575+ assert mock_stderr .write .call_count > 0
576+ call_args , _ = mock_stderr .write .call_args_list [0 ]
577+ assert "Falling back to `--include path document`" in call_args [0 ]
578+
579+ # Verify build_query_results was called with the *modified* config
580+ mock_build_results .assert_called_once ()
581+ args , _ = mock_build_results .call_args
582+ _ , called_config = args
583+ assert called_config .include == [QueryInclude .path , QueryInclude .document ]
0 commit comments