char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
92d1bb0c9
char/aliceai-t5-moe
1/// <reference types="@vitest/browser/matchers" /> 2/// <reference types="@vitest/browser/providers/playwright" /> 3 4import { beforeEach , vi } from 'vitest' ; 5 6// Mock fetch for API calls during client tests. 7// In test environment there is no backend server, so we intercept 8// the specific endpoints the app uses and return valid mock data. 9// The passthrough target is captured once at module load: capturing it 10// inside beforeEach grabs the previous test's spy (vi.spyOn returns the 11// existing spy), making the default branch recurse on itself as soon as 12// a test fetches a URL outside the mocked set. 13const originalFetch = globalThis . fetch . bind ( globalThis ); 14 15beforeEach (() => { 16vi . spyOn ( globalThis , 'fetch' ). mockImplementation ( 17async ( input :RequestInfo | URL , init ?:RequestInit ) => { 18const url = typeof input === 'string' ?input :input instanceof URL ?input . href :input . url ; 19 20// Mock server props endpoint 21if ( url . includes ( '/server' )) { 22return new Response ( 23JSON . stringify ({ 24git_branch :'test' , 25git_commit :'test' , 26mode :'router' , 27version :'test' 28}), 29{ headers :{ 'Content-Type' :'application/json' }, status :200 } 30); 31} 32 33// Mock models list endpoint 34if ( / \/v1\/models|\/models\b / . test ( url )) { 35return new Response ( 36JSON . stringify ({ 37data :[ 38{ 39created :0 , 40id :'test-model.gguf' , 41in_cache :false , 42meta :{}, 43object :'model' , 44owned_by :'llamacpp' , 45path :'models/test-model.gguf' , 46status :{ value :'unloaded' } 47} 48], 49models :[ 50{ 51details :{}, 52model :'test-model.gguf' , 53name :'Test Model' 54} 55], 56object :'list' 57}), 58{ headers :{ 'Content-Type' :'application/json' }, status :200 } 59); 60} 61 62// Mock /props endpoint (used for modalities) 63if ( url . includes ( '/props' )) { 64return new Response ( 65JSON . stringify ({ 66default_generation_settings :{ n_ctx :2048 } 67}), 68{ headers :{ 'Content-Type' :'application/json' }, status :200 } 69); 70} 71 72// Mock /tools endpoint (used for built-in tools list) 73if ( url . includes ( '/tools' )) { 74return new Response ( JSON . stringify ([]), { 75headers :{ 'Content-Type' :'application/json' }, 76status :200 77}); 78} 79 80// Default: use real fetch 81return originalFetch ( input , init ); 82} 83); 84});