char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
92d1bb0c9
char/aliceai-t5-moe
1import { existsSync , readdirSync , readFileSync } from 'node:fs' ; 2import { resolve } from 'node:path' ; 3import { describe , expect , it } from 'vitest' ; 4 5const DIST_DIR = resolve ( __dirname , '../../dist' ); 6const distExists = existsSync ( DIST_DIR ); 7 8// PWA Build Output tests are integration tests that require a built dist/. 9// CI builds first then runs these tests; local devs should run `npm run build` or use `npm run test:pwa`. 10describe ( 'PWA Build Output' , () => { 11if ( ! distExists ) { 12console . warn ( `⚠ Skipping PWA Build Output tests - dist/ not found (run 'npm run build' first)` ); 13it ( 'skipped - dist/ not found' , () => {}); 14 15return ; 16} 17 18const swContent = readFileSync ( resolve ( DIST_DIR , 'sw.js' ), 'utf-8' ); 19const indexContent = readFileSync ( resolve ( DIST_DIR , 'index.html' ), 'utf-8' ); 20 21describe ( 'Core files exist' , () => { 22it ( 'service worker (sw.js) exists' , () => { 23expect ( existsSync ( resolve ( DIST_DIR , 'sw.js' )), 'sw.js not found' ). toBeTruthy (); 24}); 25 26it ( 'workbox library exists (hashed filename)' , () => { 27// SvelteKit generates workbox-{hash}.js files 28const files = readdirSync ( DIST_DIR ). filter (( f ) => f . match ( / ^workbox-[^.]+\.js$ / )); 29 30expect ( files . length ). toBeGreaterThan ( 0 ); 31}); 32 33it ( 'manifest.webmanifest exists' , () => { 34expect ( 35existsSync ( resolve ( DIST_DIR , 'manifest.webmanifest' )), 36'manifest.webmanifest not found' 37). toBeTruthy (); 38}); 39 40it ( 'SvelteKit bundle.js exists in _app/immutable/' , () => { 41// SvelteKit generates hashed bundle names in _app/immutable/ 42const appDir = resolve ( DIST_DIR , '_app' , 'immutable' ); 43 44expect ( existsSync ( appDir ), '_app/immutable/ not found' ). toBeTruthy (); 45const files = readdirSync ( appDir ). filter (( f ) => f . startsWith ( 'bundle.' ) && f . endsWith ( '.js' )); 46 47expect ( files . length ). toBeGreaterThan ( 0 ); 48}); 49 50it ( 'SvelteKit bundle.css exists in _app/immutable/assets/' , () => { 51// SvelteKit generates hashed CSS bundles in _app/immutable/assets/ 52const cssDir = resolve ( DIST_DIR , '_app' , 'immutable' , 'assets' ); 53 54expect ( existsSync ( cssDir ), '_app/immutable/assets/ not found' ). toBeTruthy (); 55const files = readdirSync ( cssDir ). filter ( 56( f ) => f . startsWith ( 'bundle.' ) && f . endsWith ( '.css' ) 57); 58 59expect ( files . length ). toBeGreaterThan ( 0 ); 60}); 61 62it ( 'version.json exists in _app/' , () => { 63// SvelteKit stores version.json in _app directory 64expect ( 65existsSync ( resolve ( DIST_DIR , '_app' , 'version.json' )), 66'_app/version.json not found' 67). toBeTruthy (); 68}); 69}); 70 71describe ( 'version.json content' , () => { 72it ( 'has valid JSON with version field' , () => { 73const content = readFileSync ( resolve ( DIST_DIR , '_app' , 'version.json' ), 'utf-8' ); 74const parsed = JSON . parse ( content ); 75 76expect ( parsed ). toHaveProperty ( 'version' ); 77expect ( typeof parsed . version ). toBe ( 'string' ); 78expect ( parsed . version . length ). toBeGreaterThan ( 0 ); 79}); 80}); 81 82describe ( 'Service worker content' , () => { 83it ( 'service worker has minified self.define format' , () => { 84expect ( swContent ). toBeTruthy (); 85// SvelteKit's workbox-plugin-sveltekit produces a minified SW with self.define 86expect ( swContent ). toMatch ( / if\(!self.define\) / ); 87}); 88 89it ( 'references hashed workbox file (SvelteKit build output)' , () => { 90expect ( swContent ). toBeTruthy (); 91// SvelteKit's workbox-plugin-sveltekit references hashed workbox files 92expect ( swContent ). toMatch ( / define\(\["\.\/workbox-[a-zA-Z0-9]+"\] / ); 93}); 94 95it ( 'precache contains SvelteKit bundle.js with content hash' , () => { 96expect ( swContent ). toBeTruthy (); 97// SvelteKit uses content-hashed bundle names in _app/immutable/ 98expect ( swContent ). toMatch ( / "_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js" / ); 99}); 100 101it ( 'precache contains SvelteKit bundle.css with content hash' , () => { 102expect ( swContent ). toBeTruthy (); 103// SvelteKit uses content-hashed CSS bundle names in _app/immutable/assets/ 104expect ( swContent ). toMatch ( / "_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css" / ); 105}); 106 107it ( 'precache contains _app/version.json' , () => { 108expect ( swContent ). toBeTruthy (); 109// SvelteKit stores version.json in _app directory 110expect ( swContent ). toMatch ( / "_app\/version\.json" / ); 111}); 112 113it ( 'precache contains manifest.webmanifest' , () => { 114expect ( swContent ). toBeTruthy (); 115expect ( swContent ). toMatch ( / "manifest\.webmanifest" / ); 116}); 117 118it ( 'no navigation route — API endpoints bypass PWA' , () => { 119expect ( swContent ). toBeTruthy (); 120// NavigationRoute is intentionally absent so direct browser 121// navigation to server API endpoints returns JSON, not HTML. 122expect ( swContent ). not . toMatch ( / NavigationRoute / ); 123}); 124 125it ( 'has runtime caching for API routes' , () => { 126expect ( swContent ). toBeTruthy (); 127expect ( swContent ). toMatch ( / api-cache / ); 128expect ( swContent ). toMatch ( / NetworkFirst / ); 129}); 130}); 131 132describe ( 'index.html content' , () => { 133it ( 'has modulepreload link for SvelteKit bundle with content hash' , () => { 134expect ( indexContent ). toBeTruthy (); 135// SvelteKit generates hashed bundle names in _app/immutable/ 136expect ( indexContent ). toMatch ( / href="(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js" / ); 137}); 138 139it ( 'has stylesheet link for SvelteKit bundle.css with content hash' , () => { 140expect ( indexContent ). toBeTruthy (); 141expect ( indexContent ). toMatch ( 142/ href="(\.\/|\/)_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css" / 143); 144}); 145 146it ( 'has dynamic import for SvelteKit bundle with content hash' , () => { 147expect ( indexContent ). toBeTruthy (); 148expect ( indexContent ). toMatch ( 149/ import\("(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"\) / 150); 151}); 152 153it ( 'has __sveltekit__ variable (SvelteKit adds hash suffix)' , () => { 154expect ( indexContent ). toBeTruthy (); 155// SvelteKit 2.x uses __sveltekit__ as base with random suffix 156expect ( indexContent ). toMatch ( / __sveltekit_[a-zA-Z0-9-]+ / ); 157}); 158 159it ( 'has PWA manifest link' , () => { 160expect ( indexContent ). toBeTruthy (); 161expect ( indexContent ). toMatch ( / rel="manifest" href="(\.?\/)?manifest\.webmanifest" / ); 162}); 163 164it ( 'has apple-touch-icon link' , () => { 165expect ( indexContent ). toBeTruthy (); 166expect ( indexContent ). toMatch ( / rel="apple-touch-icon" / ); 167}); 168 169it ( 'has _app paths for SvelteKit bundles' , () => { 170expect ( indexContent ). toBeTruthy (); 171// SvelteKit uses _app paths for hashed assets 172expect ( indexContent ). toMatch ( / _app\/ / ); 173}); 174}); 175 176describe ( 'SvelteKit _app directory' , () => { 177it ( '_app directory exists (SvelteKit uses it for hashed assets)' , () => { 178expect ( existsSync ( resolve ( DIST_DIR , '_app' ))). toBeTruthy (); 179}); 180}); 181 182describe ( 'Hashed workbox files' , () => { 183it ( 'workbox-*.js files exist in dist root (SvelteKit build output)' , () => { 184const files = readdirSync ( DIST_DIR ). filter (( f ) => f . match ( / ^workbox-[^.]+\.js$ / )); 185 186expect ( files . length ). toBeGreaterThan ( 0 ); 187}); 188}); 189 190describe ( 'Static assets' , () => { 191it ( 'has favicon.ico' , () => { 192expect ( existsSync ( resolve ( DIST_DIR , 'favicon.ico' ))). toBeTruthy (); 193}); 194 195it ( 'has PWA icons' , () => { 196expect ( existsSync ( resolve ( DIST_DIR , 'pwa-64x64.png' ))). toBeTruthy (); 197expect ( existsSync ( resolve ( DIST_DIR , 'pwa-192x192.png' ))). toBeTruthy (); 198expect ( existsSync ( resolve ( DIST_DIR , 'pwa-512x512.png' ))). toBeTruthy (); 199}); 200}); 201});