char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
4.2 KiB139 linesraw
1// Guards the slash-command dispatch contract: commands dispatch only on
2// explicit selection (Enter/click in the picker), never mid-typing.
3// Typing `/model is broken` is prose until the command is picked - the
4// buffer must survive; only an actual selection consumes the token.
5
6import ChatFormPickersHarness from './components/ChatFormPickersHarness.svelte';
7import { tick } from 'svelte';
8import { describe, expect, it } from 'vitest';
9import { render } from 'vitest-browser-svelte';
10
11describe('slash command dispatch', () => {
12	it('does not dispatch or clear the buffer when a space follows the name', async () => {
13		const screen = render(ChatFormPickersHarness);
14
15		await tick();
16
17		screen.component.type('/model is broken');
18		await tick();
19
20		const pickers = screen.component.getPickers();
21
22		expect(screen.component.getValue()).toBe('/model is broken');
23		expect(screen.component.getCalls()).not.toContain('openModelSelector');
24		expect(screen.component.getCalls().some((c) => c.startsWith('setValue:'))).toBe(false);
25		expect(pickers.isCommandPickerOpen).toBe(true);
26		expect(pickers.commandQuery).toBe('model');
27	});
28
29	it('dispatches /model on explicit selection and consumes the token', async () => {
30		const screen = render(ChatFormPickersHarness);
31
32		await tick();
33
34		screen.component.type('/model is broken');
35		await tick();
36
37		const pickers = screen.component.getPickers();
38		const model = pickers.availableCommands.find((c) => c.name === 'model');
39
40		if (!model) throw new Error('model command missing');
41
42		pickers.handleCommandSelect(model);
43		await tick();
44
45		expect(screen.component.getValue()).toBe('');
46		expect(screen.component.getCalls()).toContain('openModelSelector');
47		expect(pickers.isCommandPickerOpen).toBe(false);
48	});
49
50	it('seeds the prompt picker search from the token args on selection', async () => {
51		const screen = render(ChatFormPickersHarness);
52
53		await tick();
54
55		screen.component.type('/prompt weather');
56		await tick();
57
58		const pickers = screen.component.getPickers();
59
60		expect(pickers.isPromptPickerOpen).toBe(false);
61
62		const prompt = pickers.availableCommands.find((c) => c.name === 'prompt');
63
64		if (!prompt) throw new Error('prompt command missing');
65
66		pickers.handleCommandSelect(prompt);
67		await tick();
68
69		expect(screen.component.getValue()).toBe('');
70		expect(pickers.isPromptPickerOpen).toBe(true);
71		expect(pickers.promptSearchQuery).toBe('weather');
72	});
73
74	it('normalizes a partial /cwd token on selection and keeps it in the buffer', async () => {
75		const screen = render(ChatFormPickersHarness);
76
77		await tick();
78
79		screen.component.type('/cw docs');
80		await tick();
81
82		const pickers = screen.component.getPickers();
83
84		expect(pickers.isWorkingDirectoryPickerOpen).toBe(false);
85
86		const cwd = pickers.availableCommands.find((c) => c.name === 'cwd');
87
88		if (!cwd) throw new Error('cwd command missing');
89
90		pickers.handleCommandSelect(cwd);
91		await tick();
92
93		expect(pickers.isWorkingDirectoryPickerOpen).toBe(true);
94		expect(pickers.workingDirectoryQuery).toBe('docs');
95		expect(screen.component.getValue()).toBe('/cwd docs');
96	});
97
98	it('syncs the /cwd token into the picker search while the picker is open', async () => {
99		const screen = render(ChatFormPickersHarness);
100
101		await tick();
102
103		const pickers = screen.component.getPickers();
104		const cwd = pickers.availableCommands.find((c) => c.name === 'cwd');
105
106		if (!cwd) throw new Error('cwd command missing');
107
108		screen.component.type('/cwd docs');
109		pickers.handleCommandSelect(cwd);
110		await tick();
111
112		screen.component.type('/cwd docs/sub');
113		await tick();
114
115		expect(pickers.isWorkingDirectoryPickerOpen).toBe(true);
116		expect(pickers.workingDirectoryQuery).toBe('docs/sub');
117		expect(pickers.isCommandPickerOpen).toBe(false);
118	});
119
120	it('abandons the /cwd picker when the token is edited away from /cwd', async () => {
121		const screen = render(ChatFormPickersHarness);
122
123		await tick();
124
125		const pickers = screen.component.getPickers();
126		const cwd = pickers.availableCommands.find((c) => c.name === 'cwd');
127
128		if (!cwd) throw new Error('cwd command missing');
129
130		screen.component.type('/cwd docs');
131		pickers.handleCommandSelect(cwd);
132		await tick();
133
134		screen.component.type('/cwdd docs');
135		await tick();
136
137		expect(pickers.isWorkingDirectoryPickerOpen).toBe(false);
138	});
139});