char-fork/llama.cpp

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

Aleksander Grygierui: Stores split refactor (#27240)521a64cd0

char/aliceai-t5-moe
1.9 KiB66 linesraw
1import { SANDBOX_TOOL_NAME } from '$lib/constants';
2import { SandboxService } from '$lib/services/sandbox.service';
3import { beforeEach, describe, expect, it } from 'vitest';
4
5const run = (code: string, timeoutMs?: number) =>
6	SandboxService.executeTool(SANDBOX_TOOL_NAME, {
7		code,
8		...(timeoutMs !== undefined ? { timeout_ms: timeoutMs } : {})
9	});
10
11describe('sandbox service', () => {
12	beforeEach(async () => {
13		const { settingsStore } = await import('$lib/stores/settings/index.svelte');
14
15		settingsStore.config = {
16			...settingsStore.config,
17			symbolicMathEnabled: true
18		};
19	});
20
21	it('executes plain JavaScript', async () => {
22		const reply = await run('return 1 + 1;');
23
24		expect(reply.isError).toBe(false);
25		expect(reply.content).toContain('=> 2');
26	});
27
28	it('exposes nerdamer for symbolic computation', async () => {
29		const reply = await run("return nerdamer.diff('sin(x)/x', 'x').toString();");
30
31		expect(reply.isError).toBe(false);
32		expect(reply.content).toContain('cos(x)');
33	});
34
35	it('computes exact rational arithmetic', async () => {
36		const reply = await run("return nerdamer('1/3 + 1/6').toString();");
37
38		expect(reply.isError).toBe(false);
39		expect(reply.content).toContain('=> 1/2');
40	});
41
42	it('proves a polynomial identity symbolically', async () => {
43		const reply = await run(
44			"return nerdamer('expand((1+x*y)^3 - (1 + 3*x*y + 3*x^2*y^2 + x^3*y^3))').toString();"
45		);
46
47		expect(reply.isError).toBe(false);
48		expect(reply.content).toContain('=> 0');
49	});
50
51	it('blocks network egress in the worker via CSP', async () => {
52		const reply = await run(
53			"try { await fetch('https://example.com/'); return 'leaked'; } catch { return 'blocked'; }"
54		);
55
56		expect(reply.isError).toBe(false);
57		expect(reply.content).toContain('=> blocked');
58	});
59
60	it('enforces the timeout on runaway code', async () => {
61		const reply = await run('while (true) {}', 500);
62
63		expect(reply.isError).toBe(true);
64		expect(reply.content).toContain('timed out');
65	});
66});