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