11// find tool tests cover custom search operation wiring and result-limit
22// normalization for session file discovery.
3+ import path from "node:path" ;
34import { Value } from "typebox/value" ;
45import { describe , expect , it , vi } from "vitest" ;
56import { createFindToolDefinition , type FindOperations } from "./find.js" ;
@@ -23,6 +24,72 @@ function execute(tool: ReturnType<typeof createFindToolDefinition>, limit: numbe
2324}
2425
2526describe ( "find tool" , ( ) => {
27+ const workspace = path . resolve ( path . sep , "find-fixture" ) ;
28+ it . each ( [
29+ {
30+ name : "absolute result" ,
31+ search : workspace ,
32+ found : path . join ( workspace , "alpha.txt" ) ,
33+ expected : "alpha.txt" ,
34+ } ,
35+ {
36+ name : "trailing search separator" ,
37+ search : `${ workspace } ${ path . sep } ` ,
38+ found : path . join ( workspace , "alpha.txt" ) ,
39+ expected : "alpha.txt" ,
40+ } ,
41+ {
42+ name : "root search" ,
43+ search : path . parse ( workspace ) . root ,
44+ found : path . join ( path . parse ( workspace ) . root , "alpha.txt" ) ,
45+ expected : "alpha.txt" ,
46+ } ,
47+ { name : "relative result" , search : workspace , found : "alpha.txt" , expected : "alpha.txt" } ,
48+ { name : "self-directory absolute" , search : workspace , found : workspace , expected : "." } ,
49+ {
50+ name : "self-directory with separator" ,
51+ search : workspace ,
52+ found : `${ workspace } ${ path . sep } ` ,
53+ expected : "./" ,
54+ } ,
55+ { name : "self-directory relative" , search : workspace , found : "." , expected : "." } ,
56+ {
57+ name : "prefix sibling" ,
58+ search : workspace ,
59+ found : path . join ( `${ workspace } -other` , "alpha.txt" ) ,
60+ expected : "../find-fixture-other/alpha.txt" ,
61+ } ,
62+ {
63+ name : "filename whitespace" ,
64+ search : workspace ,
65+ found : path . join ( workspace , "report.txt " ) ,
66+ expected : "report.txt " ,
67+ } ,
68+ {
69+ name : "absolute directory marker" ,
70+ search : `${ workspace } ${ path . sep } ` ,
71+ found : `${ path . join ( workspace , "folder" ) } ${ path . sep } ` ,
72+ expected : "folder/" ,
73+ } ,
74+ {
75+ name : "relative directory marker" ,
76+ search : workspace ,
77+ found : `folder${ path . sep } ` ,
78+ expected : "folder/" ,
79+ } ,
80+ ] ) ( "preserves $name from custom operations" , async ( { search, found, expected } ) => {
81+ const tool = createFindToolDefinition ( workspace , { operations : operations ( [ found ] ) } ) ;
82+ const result = await tool . execute (
83+ "paths" ,
84+ { pattern : "*" , path : search } ,
85+ undefined ,
86+ undefined ,
87+ { } as never ,
88+ ) ;
89+ expect ( textContent ( result ) ) . toBe ( expected ) ;
90+ expect ( result . details ) . toBeUndefined ( ) ;
91+ } ) ;
92+
2693 it ( "rejects fractional limits" , async ( ) => {
2794 const tool = createFindToolDefinition ( "/workspace" , { operations : operations ( [ ] ) } ) ;
2895
0 commit comments