char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
0021a77de
char/aliceai-t5-moe
1// Guards the @-mention picker's file_glob_search gate: when the server 2// does not expose the tool (started without --tools) or the user disabled 3// it, the picker still opens but explains why instead of firing searches 4// that would only fail with "Search failed". 5 6import ChatFormPickerMention from '$lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMention.svelte' ; 7import { DISABLED_TOOL_KEYS_LOCALSTORAGE_KEY } from '$lib/constants' ; 8import { BuiltInTool } from '$lib/enums' ; 9import { toolsStore } from '$lib/stores/tools.svelte' ; 10import type { OpenAIToolDefinition } from '$lib/types' ; 11import { tick } from 'svelte' ; 12import { afterEach , describe , expect , it } from 'vitest' ; 13import { render } from 'vitest-browser-svelte' ; 14 15const FILE_SEARCH_DEF :OpenAIToolDefinition = { 16function :{ description :'' , name :BuiltInTool . SERVER_FILE_GLOB_SEARCH , parameters :{} }, 17type :'function' 18}; 19const FILE_SEARCH_KEY = `server: ${ BuiltInTool . SERVER_FILE_GLOB_SEARCH } ` ; 20 21// The store keeps its server tool list private; tests inject it through 22// the reactive field so the derived gates recompute. 23function setServerTools ( defs :OpenAIToolDefinition []) { 24( toolsStore as unknown as { _serverTools :OpenAIToolDefinition [] }). _serverTools = defs ; 25} 26 27function renderPicker () { 28return render ( ChatFormPickerMention , { 29isOpen :true , 30onClose :() => {}, 31onSelect :() => {}, 32query :'main' 33}); 34} 35 36afterEach (() => { 37setServerTools ([]); 38toolsStore . setToolEnabled ( FILE_SEARCH_KEY , true ); 39localStorage . removeItem ( DISABLED_TOOL_KEYS_LOCALSTORAGE_KEY ); 40}); 41 42describe ( 'ChatFormPickerMention file_glob_search gate' , () => { 43it ( 'explains that file search is unavailable when the server has no tools' , async () => { 44setServerTools ([]); 45renderPicker (); 46await tick (); 47 48expect ( document . body . textContent ). toContain ( 49'File search is unavailable on this server (started without --tools)' 50); 51}); 52 53it ( 'explains that file search must be enabled when the user disabled it' , async () => { 54setServerTools ([ FILE_SEARCH_DEF ]); 55toolsStore . setToolEnabled ( FILE_SEARCH_KEY , false ); 56renderPicker (); 57await tick (); 58 59expect ( document . body . textContent ). toContain ( 60'File search is disabled - enable "Search files" in Settings > Tools to use @-mentions' 61); 62}); 63});