LifeMate — Personal, Family & Learning Companion
fix/study-duration-display
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
| 1 | // Compiled-client regression adapted from the independent security probe. |
| 2 | // Synthetic held refresh + explicit pagehide + HTTP401; no live backend, TLS, |
| 3 | // true BFCache restoration or in-flight real renderer crash is claimed. |
| 4 | const assert = require('node:assert/strict'); |
| 5 | const { readFile } = require('node:fs/promises'); |
| 6 | const path = require('node:path'); |
| 7 | const { chromium } = require('playwright'); |
| 8 | const root = path.resolve(process.argv.find(arg => arg.startsWith('--artifact='))?.slice('--artifact='.length) || 'build/web'); |
| 9 | const expectedPending = Number(process.argv.find(arg => arg.startsWith('--expected-pending='))?.slice('--expected-pending='.length) ?? 1); |
| 10 | assert([0,1].includes(expectedPending), 'Use --expected-pending=0 or 1'); |
| 11 | const origin = 'https://review.example.test'; |
| 12 | const userId = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa'; |
| 13 | const sessionKey = 'lifeguide.refresh_session.v1'; |
| 14 | const scope = origin + '/api|' + userId; |
| 15 | const offlineKey = 'lifeguide.offline.v2.' + Buffer.from(scope).toString('base64').replaceAll('+','-').replaceAll('/','_'); |
| 16 | const access = 'synthetic.' + Buffer.from(JSON.stringify({ sub: userId })).toString('base64url') + '.synthetic'; |
| 17 | const types = { '.html':'text/html', '.js':'application/javascript', '.json':'application/json', '.wasm':'application/wasm', '.ttf':'font/ttf', '.otf':'font/otf', '.png':'image/png' }; |
| 18 | (async () => { |
| 19 | const browser = await chromium.launch({ headless: true, ...(process.env.LIFEGUIDE_TEST_CHROMIUM_PATH ? {executablePath:process.env.LIFEGUIDE_TEST_CHROMIUM_PATH} : {}) }); |
| 20 | try { |
| 21 | const ctx = await browser.newContext({ serviceWorkers:'block' }); |
| 22 | let refreshes = 0, releaseFirst, firstObserved; |
| 23 | const observed = new Promise(resolve => firstObserved = resolve); |
| 24 | const released = new Promise(resolve => releaseFirst = resolve); |
| 25 | await ctx.route('**/*', async route => { |
| 26 | const url = new URL(route.request().url()); |
| 27 | assert.equal(url.origin, origin, 'External requests are forbidden'); |
| 28 | const json = (body, status=200) => route.fulfill({ status, contentType:'application/json', body:JSON.stringify(body) }); |
| 29 | if (url.pathname === '/setup') return route.fulfill({ contentType:'text/html', body:'<!doctype html><title>Synthetic setup</title>' }); |
| 30 | if (url.pathname === '/config.json') return json({ apiBaseUrl:'/api', apiFallbackUrls:[] }); |
| 31 | if (url.pathname === '/api/v1/auth/refresh') { |
| 32 | refreshes++; |
| 33 | if (refreshes === 1) { firstObserved(); await released; return json({ accessToken:access, refreshToken:'synthetic-new-token-after-rotation' }); } |
| 34 | return json({ error:'invalid_refresh' }, 401); |
| 35 | } |
| 36 | if (url.pathname.startsWith('/api/')) return json({ emailDeliveryAvailable:false, smsAvailable:false, smsStatus:'UNVERIFIED' }); |
| 37 | const file = path.resolve(root, '.' + (url.pathname === '/' ? '/index.html' : url.pathname)); |
| 38 | assert(file.startsWith(root + path.sep)); |
| 39 | try { return route.fulfill({ contentType:types[path.extname(file)] || 'application/octet-stream', body:await readFile(file) }); } |
| 40 | catch { return route.fulfill({ status:404, body:'Missing synthetic resource' }); } |
| 41 | }); |
| 42 | const page = await ctx.newPage(); |
| 43 | await page.goto(origin + '/setup'); |
| 44 | await page.evaluate(({sessionKey,userId,origin,offlineKey,scope}) => { |
| 45 | localStorage.setItem(sessionKey, JSON.stringify({ endpoint:origin+'/api', userId, refreshToken:'synthetic-old-token' })); |
| 46 | localStorage.setItem(offlineKey, JSON.stringify(JSON.stringify({ version:2, scope, caches:{}, queue:[{ id:'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb',entityId:'cccccccc-cccc-4ccc-8ccc-cccccccccccc',payload:{title:'Synthetic unsent item'},queueStatus:'queued' }],lastSyncAt:null,lastAckAt:null }))); |
| 47 | }, {sessionKey,userId,origin,offlineKey,scope}); |
| 48 | const snapshot = () => page.evaluate(({sessionKey,offlineKey}) => { |
| 49 | const raw = localStorage.getItem(offlineKey); |
| 50 | return { sessionPresent:localStorage.getItem(sessionKey)!==null, pending:raw ? JSON.parse(JSON.parse(raw)).queue.length : null }; |
| 51 | }, {sessionKey,offlineKey}); |
| 52 | await page.goto(origin, {waitUntil:'domcontentloaded'}); |
| 53 | let observedTimeout; |
| 54 | try { await Promise.race([observed, new Promise((_,reject) => { observedTimeout=setTimeout(() => reject(new Error('No first refresh within 30 seconds')),30000); })]); } finally { clearTimeout(observedTimeout); } |
| 55 | const before = await snapshot(); |
| 56 | const originalCache = await page.evaluate(key => localStorage.getItem(key), offlineKey); |
| 57 | await page.evaluate(() => window.dispatchEvent(new PageTransitionEvent('pagehide',{persisted:true}))); |
| 58 | assert.equal(await page.evaluate(() => window.lifeguideInstanceOwned), false); |
| 59 | releaseFirst(); |
| 60 | await page.waitForLoadState('networkidle'); |
| 61 | const afterLateResponse = await snapshot(); |
| 62 | await page.reload({waitUntil:'networkidle'}); |
| 63 | await page.waitForFunction(() => !localStorage.getItem('lifeguide.refresh_session.v1')); |
| 64 | // Network idle plus a bounded drain allows expiry's local async cleanup to finish. |
| 65 | await page.waitForTimeout(1000); |
| 66 | const afterReopen = await snapshot(); |
| 67 | assert.equal(before.pending,1); |
| 68 | assert.equal(afterLateResponse.pending,1); |
| 69 | assert.equal(refreshes,2); |
| 70 | assert.equal(afterReopen.sessionPresent,false); |
| 71 | assert.equal(afterReopen.pending,expectedPending,'Forced expiry must preserve unsent account-scoped mutations when expected-pending=1'); |
| 72 | if (expectedPending === 1) assert.equal(await page.evaluate(key => localStorage.getItem(key),offlineKey), originalCache, 'Forced expiry cannot rewrite any durable private payload'); |
| 73 | console.log(JSON.stringify({ evidence:'compiled current artifact; actual Chromium; synthetic intercepted refresh commit; explicit pagehide; no live server/TLS/Safari proof', before, afterLateResponse, afterReopen, refreshes })); |
| 74 | await ctx.close(); |
| 75 | } finally { await browser.close(); } |
| 76 | })().catch(error => { console.error(error.stack); process.exitCode=1; }); |