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
3.9 KiB117 linesraw
1import { expect, test } from '@playwright/test';
2
3test.describe('PWA Service Worker', () => {
4	test('service worker is registered', async ({ page }) => {
5		await page.goto('/');
6
7		const swURL = await page.evaluate(async () => {
8			const registration = await Promise.race([
9				// eslint-disable-next-line @typescript-eslint/ban-ts-comment
10				// @ts-ignore - type inference differs from browser runtime
11				navigator.serviceWorker.ready,
12				new Promise((_, reject) =>
13					setTimeout(() => reject(new Error('Service worker registration failed: timeout')), 15000)
14				)
15			]);
16
17			// @ts-expect-error registration is of type unknown
18			return registration.active?.scriptURL;
19		});
20
21		expect(swURL).toBeTruthy();
22		expect(swURL).toContain('/sw.js');
23	});
24
25	test('service worker has precache configured', async ({ page }) => {
26		await page.goto('/');
27
28		await page.evaluate(async () => {
29			await navigator.serviceWorker.ready;
30		});
31
32		const swActive = await page.evaluate(async () => {
33			const reg = await navigator.serviceWorker.ready;
34
35			return reg.active?.scriptURL ?? null;
36		});
37
38		expect(swActive).toBeTruthy();
39
40		const swResponse = await page.request.get(swActive!);
41		const swContent = await swResponse.text();
42
43		// Precache contains SvelteKit content-hashed bundle paths
44		expect(swContent).toMatch(/"_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"/);
45		expect(swContent).toMatch(/"_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css"/);
46		expect(swContent).toMatch(/"manifest\.webmanifest"/);
47		expect(swContent).toMatch(/"_app\/version\.json"/);
48		// NavigationRoute is intentionally absent — server API endpoints
49		// (e.g. /slots, /models) must not be intercepted by the PWA and
50		// should return JSON directly from the server.
51		expect(swContent).not.toMatch(/NavigationRoute/);
52		expect(swContent).toMatch(/api-cache/);
53	});
54
55	test('offline mode - page loads when offline after caching', async ({ browser }) => {
56		const context = await browser.newContext();
57		const offlinePage = await context.newPage();
58
59		await offlinePage.goto('/');
60		await offlinePage.waitForLoadState('networkidle');
61
62		await offlinePage.evaluate(async () => {
63			await navigator.serviceWorker.ready;
64		});
65
66		await offlinePage.waitForTimeout(2000);
67
68		await context.setOffline(true);
69		await offlinePage.goto('/');
70
71		const bodyText = await offlinePage.locator('body').textContent();
72
73		expect(bodyText).toBeTruthy();
74
75		await context.close();
76	});
77
78	test('version.json is accessible and contains version', async ({ page }) => {
79		const versionResponse = await page.request.get('/_app/version.json');
80
81		expect(versionResponse.ok()).toBeTruthy();
82
83		const versionData = await versionResponse.json();
84
85		expect(versionData).toHaveProperty('version');
86		expect(typeof versionData.version).toBe('string');
87		expect(versionData.version.length).toBeGreaterThan(0);
88	});
89
90	test('manifest.webmanifest is accessible and valid', async ({ page }) => {
91		const response = await page.request.get('/manifest.webmanifest');
92
93		expect(response.ok()).toBeTruthy();
94
95		const manifest = await response.json();
96
97		expect(manifest).toHaveProperty('name', 'llama-ui');
98		expect(manifest).toHaveProperty('short_name', 'llama-ui');
99		expect(manifest).toHaveProperty('start_url', './');
100		expect(manifest).toHaveProperty('display', 'standalone');
101		expect(manifest.icons).toBeTruthy();
102		expect(manifest.icons.length).toBeGreaterThan(0);
103	});
104
105	test('index.html contains content-hashed bundle references', async ({ page }) => {
106		const response = await page.request.get('/');
107
108		expect(response.ok()).toBeTruthy();
109
110		const html = await response.text();
111
112		// SvelteKit outputs content-hashed bundle names in _app/immutable/
113		expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"/);
114		expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css"/);
115		expect(html).toMatch(/import\("(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"\)/);
116	});
117});