LifeMate — Personal, Family & Learning Companion

fix/personal-notification-controls
chore/phase1-repository-cleanup deploy/stable-web-apk deployment-static design/mobile-accessibility-v2 design/mobile-navigation-review docs/child-education-access-decision docs/offline-data-rescue-options docs/owner-guide-and-delivery-plan docs/phase1-policy-options docs/public-review-live-2026-10-15 feat/aparat-learning-library feat/child-device-safety feat/child-identity-schema feat/flutter-mobile-navigation feat/learning-content-operations feat/local-signing-preflight feat/online-family-stage0 feat/personal-encrypted-recovery feat/private-planner-series-api feat/public-review-page feat/standalone-weekly-planner feat/weekly-planner-android final-feature-1/iran-family-school fix/auth-abuse-expiry-safety fix/auth-expiry-after-lock fix/backend-request-safety fix/lifeguide-bootstrap-naming-ci fix/lifeguide-pages-qa-base-preflight fix/lifeguide-qa-pages-env-deployment fix/local-task-persistence fix/managed-child-session-boundary fix/personal-jalali-dates fix/personal-notification-controls fix/personal-upgrade-delivery-guard fix/sms-approval-gates fix/study-duration-display infra/cloudflare-neon-migration infra/lifeguide-cloudflare-qa infra/lifeguide-github-pages-qa infra/lifeguide-supabase-qa main phase-1/foundation-completion phase-2/product-foundation-identity phase-3/planner-school-family-core phase-4/ai-learning-wellbeing phase-5/hardening-observability-release test/android-reminder-acceptance test/personal-notification-settings test/personal-recovery-acceptance test/role-entry-apk
cjs 85 lines 5.03 KB
Raw
1 // Tests the actual compiled artifact at an intercepted synthetic HTTPS origin.
2 // This does not validate real TLS, an installed PWA, Safari or an Android device.
3 const assert = require('node:assert/strict');
4 const {readFile} = require('node:fs/promises');
5 const path = require('node:path');
6 const {chromium} = require('playwright');
7
8 const artifactRoot = path.resolve(process.argv[2] || 'build/web');
9 const testUrl = new URL(process.env.LIFEGUIDE_WEB_TEST_ORIGIN || 'https://family.example.test');
10 assert(testUrl.protocol === 'https:' && !testUrl.username && !testUrl.password &&
11 testUrl.pathname === '/' && !testUrl.search && !testUrl.hash,
12 'The synthetic test origin must be a plain HTTPS origin.');
13 const origin = testUrl.origin;
14 const screenshotIndex = process.argv.indexOf('--screenshot');
15 const screenshotPath = screenshotIndex < 0 ? null : process.argv[screenshotIndex + 1];
16 if (screenshotIndex >= 0) assert(screenshotPath, '--screenshot requires a file path');
17 const mime = {'.html':'text/html', '.js':'application/javascript', '.json':'application/json',
18 '.wasm':'application/wasm', '.ttf':'font/ttf', '.otf':'font/otf', '.woff2':'font/woff2',
19 '.png':'image/png', '.svg':'image/svg+xml'};
20 const csp = "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'; connect-src 'self'; worker-src 'self' blob:; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; form-action 'self'";
21
22 (async () => {
23 const executablePath = process.env.LIFEGUIDE_TEST_CHROMIUM_PATH;
24 const browser = await chromium.launch({headless:true,
25 ...(executablePath ? {executablePath} : {})});
26 try {
27 const context = await browser.newContext({viewport:{width:390,height:844},
28 ignoreHTTPSErrors:false, serviceWorkers:'block'});
29 const requested = [], missingAssets = [], errors = [];
30 await context.route('**/*', async route => {
31 const url = new URL(route.request().url());
32 requested.push(url.href);
33 if (url.origin !== origin) {
34 errors.push(`Unexpected external request: ${url.origin}`);
35 await route.abort();
36 return;
37 }
38 if (url.pathname === '/api/v1/auth/capabilities') {
39 await route.fulfill({contentType:'application/json', body:JSON.stringify({
40 emailDeliveryAvailable:false,smsAvailable:false,smsStatus:'UNVERIFIED'})});
41 return;
42 }
43 const local = path.resolve(artifactRoot,
44 '.' + (url.pathname === '/' ? '/index.html' : decodeURIComponent(url.pathname)));
45 assert(local.startsWith(artifactRoot + path.sep), 'Artifact requests cannot escape the output directory');
46 try {
47 await route.fulfill({contentType:mime[path.extname(local)] || 'application/octet-stream',
48 headers:{'content-security-policy':csp,'cache-control':'no-store'}, body:await readFile(local)});
49 } catch {
50 missingAssets.push(url.pathname);
51 await route.fulfill({status:404,body:'Missing synthetic artifact resource'});
52 }
53 });
54 const page = await context.newPage();
55 page.on('pageerror', error => errors.push(error.message));
56 page.on('console', message => {
57 if (message.type() === 'error') errors.push(message.text());
58 });
59 await page.goto(origin, {waitUntil:'networkidle',timeout:60000});
60 await page.waitForFunction(() => !document.getElementById('startup-status'), null, {timeout:60000});
61 await page.waitForLoadState('networkidle');
62 assert((await page.title()).includes('LifeGuide'), 'Built page must use the LifeGuide identity');
63 assert.equal(await page.locator('flt-glass-pane').count(),1,'Flutter engine must start');
64 if (screenshotPath) {
65 const enable = page.locator('flt-semantics-placeholder');
66 if (await enable.count()) await enable.evaluate(element => element.click());
67 await page.screenshot({path:screenshotPath,fullPage:true});
68 }
69 assert(requested.some(url => url.includes('/canvaskit/') && url.endsWith('.wasm')),
70 'CanvasKit WASM must load locally');
71 for (const font of ['LifeGuidePersian.ttf','LifeGuideLatin.ttf','LifeGuideEmoji.ttf']) {
72 assert(requested.some(url => url.endsWith(font)), `${font} must load locally`);
73 }
74 assert(!requested.some(url => /(?:gstatic\.com|googleapis\.com)/i.test(url)),
75 'Runtime requests cannot use Google font or CanvasKit hosts');
76 assert.equal(missingAssets.length,0,JSON.stringify(missingAssets));
77 assert.equal(errors.length,0,JSON.stringify(errors));
78 console.log(JSON.stringify({mode:'Synthetic HTTPS origin; intercepted compiled artifact responses; real TLS and service worker acceptance unverified',
79 requests:requested.length, fontRequests:requested.filter(url => /\.(?:ttf|otf|woff2)$/.test(url)).map(url => new URL(url).pathname),
80 canvasKitRequests:requested.filter(url => url.includes('/canvaskit/')).map(url => new URL(url).pathname),
81 externalRequests:requested.filter(url => new URL(url).origin !== origin),missingAssets,errors},null,2));
82 } finally {
83 await browser.close();
84 }
85 })().catch(error => {console.error(error.message);process.exitCode=1;});