@@ -20,6 +20,7 @@ describe("SearchTool", () => {
2020 validateLibraryExists : vi . fn ( ) ,
2121 findBestVersion : vi . fn ( ) ,
2222 searchStore : vi . fn ( ) ,
23+ listVersions : vi . fn ( ) ,
2324 } ;
2425
2526 searchTool = new SearchTool ( mockDocService as DocumentManagementService ) ;
@@ -58,6 +59,37 @@ describe("SearchTool", () => {
5859 expect ( result . error ) . toBeUndefined ( ) ;
5960 } ) ;
6061
62+ it ( "should throw VersionNotFoundError when exactMatch is true but no version is specified" , async ( ) => {
63+ const options : SearchToolOptions = {
64+ ...baseOptions ,
65+ exactMatch : true ,
66+ } ;
67+ const availableVersions = [ { version : "1.0.0" , indexed : true } ] ;
68+ ( mockDocService . validateLibraryExists as Mock ) . mockResolvedValue ( undefined ) ;
69+ ( mockDocService . listVersions as Mock ) . mockResolvedValue ( availableVersions ) ;
70+
71+ await expect ( searchTool . execute ( options ) ) . rejects . toThrow ( VersionNotFoundError ) ;
72+ expect ( mockDocService . validateLibraryExists ) . toHaveBeenCalledWith ( "test-lib" ) ;
73+ expect ( mockDocService . listVersions ) . toHaveBeenCalledWith ( "test-lib" ) ;
74+ expect ( mockDocService . searchStore ) . not . toHaveBeenCalled ( ) ;
75+ } ) ;
76+
77+ it ( "should throw VersionNotFoundError when exactMatch is true with 'latest' version" , async ( ) => {
78+ const options : SearchToolOptions = {
79+ ...baseOptions ,
80+ version : "latest" ,
81+ exactMatch : true ,
82+ } ;
83+ const availableVersions = [ { version : "1.0.0" , indexed : true } ] ;
84+ ( mockDocService . validateLibraryExists as Mock ) . mockResolvedValue ( undefined ) ;
85+ ( mockDocService . listVersions as Mock ) . mockResolvedValue ( availableVersions ) ;
86+
87+ await expect ( searchTool . execute ( options ) ) . rejects . toThrow ( VersionNotFoundError ) ;
88+ expect ( mockDocService . validateLibraryExists ) . toHaveBeenCalledWith ( "test-lib" ) ;
89+ expect ( mockDocService . listVersions ) . toHaveBeenCalledWith ( "test-lib" ) ;
90+ expect ( mockDocService . searchStore ) . not . toHaveBeenCalled ( ) ;
91+ } ) ;
92+
6193 it ( "should find best version and search when exactMatch is false (default)" , async ( ) => {
6294 const options : SearchToolOptions = { ...baseOptions , version : "1.x" } ;
6395 const findVersionResult = { bestMatch : "1.2.0" , hasUnversioned : false } ;
@@ -105,7 +137,8 @@ describe("SearchTool", () => {
105137
106138 await searchTool . execute ( options ) ;
107139
108- expect ( mockDocService . findBestVersion ) . toHaveBeenCalledWith ( "test-lib" , "latest" ) ; // Default version
140+ // The implementation passes undefined, which is defaulted to "latest" in the method
141+ expect ( mockDocService . findBestVersion ) . toHaveBeenCalledWith ( "test-lib" , undefined ) ;
109142 expect ( mockDocService . searchStore ) . toHaveBeenCalledWith (
110143 "test-lib" ,
111144 "1.2.0" ,
0 commit comments