Files
llama.cpp/tools/ui/tests/client/chat-form-mention-picker-gate.svelte.test.ts
T
Aleksander Grygier 6de1b63473 allozaur/feat/chat slash commands (#26716)
* base : slash-command/misc foundation - model icon and focus-selector constants

* feat : slash-command picker and command parsing helpers

* refactor : wire command and @-mention pickers into the chat form

* ui : improve model selector keyboard navigation and load/dismiss

* feat: Unify markdown/raw-text rendering under one setting with migration

* fix: Misc fixes - tool-call subtitle, assistant wrap, progress guards

* feat: Clamp and style numeric settings inputs from registry bounds
2026-08-07 20:20:01 +02:00

65 lines
2.2 KiB
TypeScript

// Guards the @-mention picker's file_glob_search gate: when the server
// does not expose the tool (started without --tools) or the user disabled
// it, the picker still opens but explains why instead of firing searches
// that would only fail with "Search failed".
import { describe, it, expect, afterEach } from 'vitest';
import { render } from 'vitest-browser-svelte';
import { tick } from 'svelte';
import ChatFormMentionPicker from '$lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormMentionPicker.svelte';
import { toolsStore } from '$lib/stores/tools.svelte';
import { BuiltInTool } from '$lib/enums';
import { DISABLED_TOOL_KEYS_LOCALSTORAGE_KEY } from '$lib/constants';
import type { OpenAIToolDefinition } from '$lib/types';
const FILE_SEARCH_DEF: OpenAIToolDefinition = {
type: 'function',
function: { name: BuiltInTool.FILE_GLOB_SEARCH, description: '', parameters: {} }
};
const FILE_SEARCH_KEY = `builtin:${BuiltInTool.FILE_GLOB_SEARCH}`;
// The store keeps its builtin tool list private; tests inject it through
// the reactive field so the derived gates recompute.
function setBuiltinTools(defs: OpenAIToolDefinition[]) {
(toolsStore as unknown as { _builtinTools: OpenAIToolDefinition[] })._builtinTools = defs;
}
function renderPicker() {
return render(ChatFormMentionPicker, {
isOpen: true,
query: 'main',
onClose: () => {},
onSelect: () => {}
});
}
afterEach(() => {
setBuiltinTools([]);
toolsStore.setToolEnabled(FILE_SEARCH_KEY, true);
localStorage.removeItem(DISABLED_TOOL_KEYS_LOCALSTORAGE_KEY);
});
describe('ChatFormMentionPicker file_glob_search gate', () => {
it('explains that file search is unavailable when the server has no tools', async () => {
setBuiltinTools([]);
renderPicker();
await tick();
expect(document.body.textContent).toContain(
'File search is unavailable on this server (started without --tools)'
);
});
it('explains that file search must be enabled when the user disabled it', async () => {
setBuiltinTools([FILE_SEARCH_DEF]);
toolsStore.setToolEnabled(FILE_SEARCH_KEY, false);
renderPicker();
await tick();
expect(document.body.textContent).toContain(
'File search is disabled - enable "Search files" in Settings > Tools to use @-mentions'
);
});
});