char-fork/llama.cpp

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

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

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