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
3.5 KiB124 linesraw
1import { beforeEach, describe, expect, it, vi } from 'vitest';
2
3vi.mock('$lib/services/tools.service', () => ({
4	ToolsService: { 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(() => {
16	mockExecute.mockReset();
17});
18
19describe('runGlobSearchWithChildren', () => {
20	it('returns ranked outer entries as absolute paths without descending', async () => {
21		mockExecute.mockResolvedValueOnce({
22			base: '/Users/rootA',
23			entries: [
24				{ path: 'note.md', type: 'file' },
25				{ path: 'src', type: 'dir' }
26			]
27		});
28		const res = await runGlobSearchWithChildren(
29			'note',
30			'/Users/rootA',
31			3,
32			50,
33			new AbortController().signal
34		);
35
36		expect(res.error).toBeUndefined();
37		expect(res.entries.map((e) => e.path)).toEqual(['/Users/rootA/note.md', '/Users/rootA/src']);
38		expect(res.exactDir).toBeUndefined();
39		expect(mockExecute).toHaveBeenCalledTimes(1);
40	});
41
42	it('appends a matched directorys children when the query ends with a separator', async () => {
43		mockExecute
44			.mockResolvedValueOnce({ base: '/Users/rootB', entries: [{ path: 'src', type: 'dir' }] })
45			.mockResolvedValueOnce({
46				base: '/Users/rootB/src',
47				entries: [
48					{ path: 'a.txt', type: 'file' },
49					{ path: 'sub', type: 'dir' }
50				]
51			});
52		const res = await runGlobSearchWithChildren(
53			'/Users/rootB/src/',
54			'/Users/rootB',
55			3,
56			50,
57			new AbortController().signal,
58			{ descendOnTrailingSeparator: true, type: GlobSearchType.ALL }
59		);
60
61		expect(res.error).toBeUndefined();
62		expect(res.exactDir).toBe('/Users/rootB/src');
63		expect(res.entries.map((e) => e.path)).toEqual([
64			'/Users/rootB/src',
65			'/Users/rootB/src/a.txt',
66			'/Users/rootB/src/sub'
67		]);
68		expect(mockExecute).toHaveBeenCalledTimes(2);
69	});
70
71	it('does not descend without a trailing separator in mention mode', async () => {
72		mockExecute.mockResolvedValueOnce({
73			base: '/Users/rootC',
74			entries: [{ path: 'src', type: 'dir' }]
75		});
76		const res = await runGlobSearchWithChildren(
77			'/Users/rootC/src',
78			'/Users/rootC',
79			3,
80			50,
81			new AbortController().signal,
82			{ descendOnTrailingSeparator: true, type: GlobSearchType.ALL }
83		);
84
85		expect(res.exactDir).toBeUndefined();
86		expect(mockExecute).toHaveBeenCalledTimes(1);
87	});
88
89	it('descends on an exact directory match in WD mode', async () => {
90		mockExecute
91			.mockResolvedValueOnce({ base: '/Users/rootD', entries: [{ path: 'src', type: 'dir' }] })
92			.mockResolvedValueOnce({
93				base: '/Users/rootD/src',
94				entries: [{ path: 'a.txt', type: 'file' }]
95			});
96		const res = await runGlobSearchWithChildren(
97			'/Users/rootD/src',
98			'/Users/rootD',
99			3,
100			50,
101			new AbortController().signal,
102			{ type: GlobSearchType.DIR }
103		);
104
105		expect(res.exactDir).toBe('/Users/rootD/src');
106		expect(res.entries.map((e) => e.path)).toEqual(['/Users/rootD/src', '/Users/rootD/src/a.txt']);
107		expect(mockExecute).toHaveBeenCalledTimes(2);
108	});
109
110	it('surfaces a server error without attempting a child walk', async () => {
111		mockExecute.mockResolvedValueOnce({ error: 'boom' });
112		const res = await runGlobSearchWithChildren(
113			'src',
114			'/Users/rootE',
115			3,
116			50,
117			new AbortController().signal
118		);
119
120		expect(res.error).toBe('boom');
121		expect(res.entries).toEqual([]);
122		expect(mockExecute).toHaveBeenCalledTimes(1);
123	});
124});