char-fork/llama.cpp

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

Aleksander Grygierui: Improve Chat Messages rendering performance (#28460)0afb805b1

char/aliceai-t5-moe
3.0 KiB91 linesraw
1import { isExitCodeSummaryLine, parseExecShellCommandExitStatus } from '$lib/utils';
2import { describe, expect, it } from 'vitest';
3
4describe('parseExecShellCommandExitStatus', () => {
5	it('returns undefined when result is empty', () => {
6		expect(parseExecShellCommandExitStatus(undefined)).toBeUndefined();
7		expect(parseExecShellCommandExitStatus('')).toBeUndefined();
8	});
9
10	it('parses a zero-exit summary at end of clean stdout', () => {
11		const status = parseExecShellCommandExitStatus('hello world\n[exit code: 0]');
12
13		expect(status).toEqual({
14			code: 0,
15			rawText: '[exit code: 0]',
16			timedOut: false
17		});
18	});
19
20	it('parses a non-zero exit summary', () => {
21		const status = parseExecShellCommandExitStatus('cargo: error[E0425]\n[exit code: 101]');
22
23		expect(status?.code).toBe(101);
24		expect(status?.timedOut).toBe(false);
25	});
26
27	it('detects timed-out suffix', () => {
28		const status = parseExecShellCommandExitStatus(
29			'still building...\n[exit code: -1] [exit due to timed out]'
30		);
31
32		expect(status?.code).toBe(-1);
33		expect(status?.timedOut).toBe(true);
34	});
35
36	it('tolerates trailing whitespace after the tail line', () => {
37		const status = parseExecShellCommandExitStatus('[exit code: 0]   \n\n');
38
39		expect(status?.code).toBe(0);
40	});
41
42	it('does not match an explanatory mention of "[exit code:" not at end', () => {
43		// Any non-trailing occurrence should NOT trigger the badge - we
44		// anchor to the absolute end of the string.
45		const status = parseExecShellCommandExitStatus(
46			'the shell prints [exit code: 0]\nwhen done\nreally done\n'
47		);
48
49		expect(status).toBeUndefined();
50	});
51
52	it('does not match mid-stream exit lines followed by more output', () => {
53		const status = parseExecShellCommandExitStatus('[exit code: 0]\nmore output keeps streaming');
54
55		expect(status).toBeUndefined();
56	});
57});
58
59describe('isExitCodeSummaryLine', () => {
60	const status = parseExecShellCommandExitStatus('hello\n[exit code: 7]');
61
62	it('matches when line trims to the tail text', () => {
63		expect(isExitCodeSummaryLine('   [exit code: 7]   ', status)).toBe(true);
64	});
65
66	it('does not match unrelated lines', () => {
67		expect(isExitCodeSummaryLine('plain output line', status)).toBe(false);
68	});
69
70	it('returns false for missing status argument', () => {
71		expect(isExitCodeSummaryLine('[exit code: 7]', undefined)).toBe(false);
72	});
73});
74
75describe('parseExecShellCommandExitStatus tail scan', () => {
76	it('finds the marker at the end of a blob larger than the tail window', () => {
77		// the parser matches only the last ~128 chars; a marker past that
78		// window must still parse, and an earlier fake must not match
79		const blob = `${'the shell prints [exit code: 1] mid-stream\n'.repeat(2000)}[exit code: 0]`;
80		const status = parseExecShellCommandExitStatus(blob);
81
82		expect(status?.code).toBe(0);
83		expect(status?.timedOut).toBe(false);
84	});
85
86	it('keeps rejecting markers that are not at the absolute end', () => {
87		const blob = `${'stdout\n'.repeat(2000)}[exit code: 0]\nsome trailing log line`;
88
89		expect(parseExecShellCommandExitStatus(blob)).toBeUndefined();
90	});
91});