char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
92d1bb0c9
char/aliceai-t5-moe
1import { beforeEach , describe , expect , it , vi } from 'vitest' ; 2 3vi . mock ( '$lib/services/tools.service' , () => ({ 4ToolsService :{ executeToolRaw :vi . fn () } 5})); 6 7import { GlobSearchType } from '$lib/enums' ; 8import { ToolsService } from '$lib/services/tools.service' ; 9import { runGlobSearchWithChildren } from '$lib/utils' ; 10 11const mockExecute = vi . mocked ( ToolsService . executeToolRaw ); 12 13// Distinct roots per test so the module-level search cache never serves a 14// prior test's result under the same (type, path, glob, depth) key. 15beforeEach (() => { 16mockExecute . mockReset (); 17}); 18 19describe ( 'runGlobSearchWithChildren' , () => { 20it ( 'returns ranked outer entries as absolute paths without descending' , async () => { 21mockExecute . mockResolvedValueOnce ({ 22base :'/Users/rootA' , 23entries :[ 24{ path :'note.md' , type :'file' }, 25{ path :'src' , type :'dir' } 26] 27}); 28const res = await runGlobSearchWithChildren ( 29'note' , 30'/Users/rootA' , 313 , 3250 , 33new AbortController (). signal 34); 35 36expect ( res . error ). toBeUndefined (); 37expect ( res . entries . map (( e ) => e . path )). toEqual ([ '/Users/rootA/note.md' , '/Users/rootA/src' ]); 38expect ( res . exactDir ). toBeUndefined (); 39expect ( mockExecute ). toHaveBeenCalledTimes ( 1 ); 40}); 41 42it ( 'appends a matched directorys children when the query ends with a separator' , async () => { 43mockExecute 44. mockResolvedValueOnce ({ base :'/Users/rootB' , entries :[{ path :'src' , type :'dir' }] }) 45. mockResolvedValueOnce ({ 46base :'/Users/rootB/src' , 47entries :[ 48{ path :'a.txt' , type :'file' }, 49{ path :'sub' , type :'dir' } 50] 51}); 52const res = await runGlobSearchWithChildren ( 53'/Users/rootB/src/' , 54'/Users/rootB' , 553 , 5650 , 57new AbortController (). signal , 58{ descendOnTrailingSeparator :true , type :GlobSearchType . ALL } 59); 60 61expect ( res . error ). toBeUndefined (); 62expect ( res . exactDir ). toBe ( '/Users/rootB/src' ); 63expect ( res . entries . map (( e ) => e . path )). toEqual ([ 64'/Users/rootB/src' , 65'/Users/rootB/src/a.txt' , 66'/Users/rootB/src/sub' 67]); 68expect ( mockExecute ). toHaveBeenCalledTimes ( 2 ); 69}); 70 71it ( 'does not descend without a trailing separator in mention mode' , async () => { 72mockExecute . mockResolvedValueOnce ({ 73base :'/Users/rootC' , 74entries :[{ path :'src' , type :'dir' }] 75}); 76const res = await runGlobSearchWithChildren ( 77'/Users/rootC/src' , 78'/Users/rootC' , 793 , 8050 , 81new AbortController (). signal , 82{ descendOnTrailingSeparator :true , type :GlobSearchType . ALL } 83); 84 85expect ( res . exactDir ). toBeUndefined (); 86expect ( mockExecute ). toHaveBeenCalledTimes ( 1 ); 87}); 88 89it ( 'descends on an exact directory match in WD mode' , async () => { 90mockExecute 91. mockResolvedValueOnce ({ base :'/Users/rootD' , entries :[{ path :'src' , type :'dir' }] }) 92. mockResolvedValueOnce ({ 93base :'/Users/rootD/src' , 94entries :[{ path :'a.txt' , type :'file' }] 95}); 96const res = await runGlobSearchWithChildren ( 97'/Users/rootD/src' , 98'/Users/rootD' , 993 , 10050 , 101new AbortController (). signal , 102{ type :GlobSearchType . DIR } 103); 104 105expect ( res . exactDir ). toBe ( '/Users/rootD/src' ); 106expect ( res . entries . map (( e ) => e . path )). toEqual ([ '/Users/rootD/src' , '/Users/rootD/src/a.txt' ]); 107expect ( mockExecute ). toHaveBeenCalledTimes ( 2 ); 108}); 109 110it ( 'surfaces a server error without attempting a child walk' , async () => { 111mockExecute . mockResolvedValueOnce ({ error :'boom' }); 112const res = await runGlobSearchWithChildren ( 113'src' , 114'/Users/rootE' , 1153 , 11650 , 117new AbortController (). signal 118); 119 120expect ( res . error ). toBe ( 'boom' ); 121expect ( res . entries ). toEqual ([]); 122expect ( mockExecute ). toHaveBeenCalledTimes ( 1 ); 123}); 124});