LifeMate — Personal, Family & Learning Companion
feat/private-planner-series-api
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 | // Developer acceptance substitute: compiled PWA, real local HTTPS/API/Postgres. |
| 2 | // Requires a normally trusted public local CA and a NEW synthetic fixture. |
| 3 | // Does not intercept responses, disable TLS, publish lessons or play media. |
| 4 | const assert = require('node:assert/strict'); |
| 5 | const fs = require('node:fs/promises'); |
| 6 | const path = require('node:path'); |
| 7 | const os = require('node:os'); |
| 8 | const https = require('node:https'); |
| 9 | const {spawnSync} = require('node:child_process'); |
| 10 | const {chromium} = require('../apps/lifemate/node_modules/playwright'); |
| 11 | const {assertLearningProgressSemantics} = require('../apps/lifemate/tool/assert-learning-progress-semantics.cjs'); |
| 12 | |
| 13 | const root = path.resolve(__dirname, '..'); |
| 14 | const origin = process.env.LEARNING_BROWSER_ORIGIN || 'https://127.0.0.1:8445'; |
| 15 | const parsed = new URL(origin); |
| 16 | assert(parsed.protocol === 'https:' && parsed.hostname === '127.0.0.1' && |
| 17 | parsed.port === '8445' && parsed.pathname === '/' && !parsed.username && |
| 18 | !parsed.password && !parsed.search && !parsed.hash, |
| 19 | 'This test is restricted to the isolated local synthetic HTTPS stack on8445.'); |
| 20 | const email = process.env.SMOKE_EMAIL || ''; |
| 21 | const password = process.env.SMOKE_PASSWORD || ''; |
| 22 | assert(/^learning-browser-[a-f0-9]+@example\.test$/.test(email) && password.length >= 10, |
| 23 | 'Provide the dedicated synthetic fixture through SMOKE_EMAIL/SMOKE_PASSWORD.'); |
| 24 | assert(process.env.ROOT_CA && process.env.LEARNING_COMPOSE_ENV, |
| 25 | 'ROOT_CA and private LEARNING_COMPOSE_ENV paths are required.'); |
| 26 | const receiptFile = path.resolve(process.argv[2] || path.join(root, |
| 27 | 'docs/audits/evidence/content-operations-browser-2026-10-12.json')); |
| 28 | const screenshotFile = receiptFile.replace(/\.json$/, '.png'); |
| 29 | const uuid = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i; |
| 30 | const escaped = value => value.replace(/[.*+?^${}()|[\]\\]/g,'\\$&'); |
| 31 | const paths = [], errors = [], failures = [], auth = [], checks = []; |
| 32 | let stage = 'startup'; |
| 33 | let ca; |
| 34 | const check = name => { checks.push({name, status:'PASS'}); console.log(`PASS ${name}`); }; |
| 35 | |
| 36 | function api(method, endpoint, body, accessToken) { |
| 37 | return new Promise((resolve,reject) => { |
| 38 | const serialized = body === undefined ? null : Buffer.from(JSON.stringify(body)); |
| 39 | const req = https.request(new URL('/api' + endpoint, origin), { |
| 40 | method, ca, rejectUnauthorized:true, |
| 41 | headers:{...(serialized ? {'content-type':'application/json','content-length':serialized.length} : {}), |
| 42 | ...(accessToken ? {authorization:`Bearer ${accessToken}`} : {})} |
| 43 | }, response => { |
| 44 | assert(response.socket.authorized, 'Independent API socket must verify TLS.'); |
| 45 | let content = ''; |
| 46 | response.setEncoding('utf8'); response.on('data', part => content += part); |
| 47 | response.on('end', () => { |
| 48 | try {resolve({status:response.statusCode,json:content ? JSON.parse(content) : null});} |
| 49 | catch {reject(new Error('Independent API returned non-JSON content'));} |
| 50 | }); |
| 51 | }); |
| 52 | req.setTimeout(15000, () => req.destroy(new Error('Independent HTTPS API timed out'))); |
| 53 | req.on('error', reject); req.end(serialized); |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | function dbJson(query) { |
| 58 | const result = spawnSync('docker', ['compose','--env-file',process.env.LEARNING_COMPOSE_ENV, |
| 59 | 'exec','-T','postgres','sh','-c', |
| 60 | 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -At -v ON_ERROR_STOP=1'], |
| 61 | {cwd:root,input:query,encoding:'utf8',timeout:15000}); |
| 62 | assert.equal(result.status,0,'Independent synthetic DB assertion failed.'); |
| 63 | return JSON.parse(result.stdout.trim()); |
| 64 | } |
| 65 | |
| 66 | function observe(page) { |
| 67 | page.on('request', request => { |
| 68 | const url = new URL(request.url()); |
| 69 | paths.push({origin:url.origin,path:url.pathname.replace(/[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}/gi,':fixture-id'),method:request.method()}); |
| 70 | }); |
| 71 | page.on('requestfailed', request => failures.push({path:new URL(request.url()).pathname, |
| 72 | failure:request.failure()?.errorText || 'network failure'})); |
| 73 | page.on('pageerror', () => errors.push('Browser page error')); |
| 74 | page.on('response', response => { |
| 75 | const endpoint = new URL(response.url()).pathname; |
| 76 | if (['/api/v1/auth/login','/api/v1/auth/refresh'].includes(endpoint)) |
| 77 | auth.push({path:endpoint,status:response.status()}); |
| 78 | if (response.status() >= 400) errors.push(`HTTP ${response.status()} ${endpoint.replace(/[a-f0-9-]{36}/gi,':fixture-id')}`); |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | async function boot(context) { |
| 83 | const page = context.pages()[0] || await context.newPage(); observe(page); |
| 84 | const response = await page.goto(origin,{waitUntil:'networkidle',timeout:60000}); |
| 85 | assert.equal(response.status(),200); |
| 86 | await page.waitForFunction(() => !document.getElementById('startup-status'),null,{timeout:60000}); |
| 87 | await page.locator('flt-glass-pane').waitFor({state:'attached'}); |
| 88 | const accessibility = page.locator('flt-semantics-placeholder'); |
| 89 | if (await accessibility.count()) await accessibility.evaluate(element => element.click()); |
| 90 | await page.waitForLoadState('networkidle'); |
| 91 | return page; |
| 92 | } |
| 93 | |
| 94 | async function click(locator) { |
| 95 | await locator.waitFor({state:'attached',timeout:20000}); |
| 96 | // Flutter RTL semantics nodes may have transformed DOM hit rectangles. |
| 97 | // Activates the rendered semantic control; never injects API/state data. |
| 98 | await locator.evaluate(element => element.click()); |
| 99 | } |
| 100 | async function bodyIncludes(page, text) { |
| 101 | await page.waitForFunction(needle => document.body.textContent.includes(needle) || |
| 102 | [...document.querySelectorAll('[aria-label]')].some(element => |
| 103 | element.getAttribute('aria-label').includes(needle)),text,{timeout:20000}); |
| 104 | } |
| 105 | async function school(page) { |
| 106 | await click(page.getByRole('button',{name:'مدرسه من',exact:true})); |
| 107 | await bodyIncludes(page,'انتخاب پایه و رشته'); |
| 108 | } |
| 109 | async function lesson(page, course, unit) { |
| 110 | await page.getByLabel('جستجوی کتاب',{exact:true}).fill(course.titleFa); |
| 111 | await click(page.getByRole('button',{name:new RegExp('^' + escaped(course.titleFa) + ' ')})); |
| 112 | await bodyIncludes(page,'جستجوی درس یا صفحه'); |
| 113 | await page.getByLabel('جستجوی درس یا صفحه',{exact:true}).fill(unit.titleFa); |
| 114 | await click(page.getByRole('button',{name:new RegExp('^' + escaped(unit.titleFa) + ' ')})); |
| 115 | await bodyIncludes(page,'پیشرفت شخصی:'); |
| 116 | } |
| 117 | |
| 118 | (async () => { |
| 119 | ca = await fs.readFile(process.env.ROOT_CA); |
| 120 | const profile = await fs.mkdtemp(path.join(os.tmpdir(),'lifeguide-learning-browser-')); |
| 121 | const launch = () => chromium.launchPersistentContext(profile,{headless:true, |
| 122 | executablePath:process.env.LIFEGUIDE_TEST_CHROMIUM_PATH || '/usr/bin/chromium', |
| 123 | ignoreHTTPSErrors:false,serviceWorkers:'allow',timezoneId:'Asia/Tehran', |
| 124 | viewport:{width:1100,height:1050}}); |
| 125 | let context; |
| 126 | try { |
| 127 | stage = 'realTLS'; |
| 128 | assert.equal((await api('GET','/health')).status,200); check('independent verified HTTPS health'); |
| 129 | const loggedIn = await api('POST','/v1/auth/login',{email,password}); |
| 130 | assert.equal(loggedIn.status,200); const token = loggedIn.json.accessToken; |
| 131 | const profileResult = await api('GET','/v1/profile',undefined,token); |
| 132 | assert.equal(profileResult.status,200); const owner = profileResult.json.user_id; |
| 133 | assert(uuid.test(owner)); |
| 134 | assert.equal((await api('GET','/v1/education/library',undefined,token)).json.education,null, |
| 135 | 'Use a new fixture with no preselected education.'); |
| 136 | |
| 137 | context = await launch(); let page = await boot(context); |
| 138 | stage = 'realLogin'; |
| 139 | await page.getByLabel('ایمیل یا شماره تلفن',{exact:true}).fill(email); |
| 140 | await page.getByLabel('ایمیل یا شماره تلفن',{exact:true}).press('Tab'); |
| 141 | await page.getByLabel('رمز عبور',{exact:true}).fill(password); |
| 142 | await page.getByLabel('رمز عبور',{exact:true}).press('Tab'); |
| 143 | const loginResponse = page.waitForResponse(response => response.url().endsWith('/api/v1/auth/login') && response.request().method() === 'POST'); |
| 144 | await click(page.getByRole('button',{name:'ورود',exact:true})); |
| 145 | const browserLogin = await loginResponse; |
| 146 | const entered = browserLogin.request().postDataJSON(); |
| 147 | assert(entered.password === password,'Synthetic browser password field was not committed.'); |
| 148 | assert((entered.email ?? entered.identifier) === email,'Synthetic browser contact field was not committed.'); |
| 149 | assert.equal(browserLogin.status(),200); |
| 150 | await school(page); check('compiled PWA actual synthetic account login'); |
| 151 | |
| 152 | stage = 'educationSelection'; |
| 153 | await click(page.getByRole('button',{name:'انتخاب پایه و رشته',exact:true})); |
| 154 | // The dropdown is an actual Flutter semantic button, not a native select. |
| 155 | await click(page.getByRole('button',{name:'پایه',exact:true})); |
| 156 | await click(page.getByRole('menuitem',{name:'پایه 1',exact:true})); |
| 157 | const educationResponse = page.waitForResponse(response => response.url().endsWith('/api/v1/me/education') && response.request().method() === 'PUT'); |
| 158 | await click(page.getByRole('button',{name:'ذخیره',exact:true})); |
| 159 | assert.equal((await educationResponse).status(),200); |
| 160 | const library = (await api('GET','/v1/education/library',undefined,token)).json; |
| 161 | assert.deepEqual(library.education,{nationalGrade:1,trackCode:'common',schoolYear:'1405-1406'}); |
| 162 | const course = library.courses.find(item => item.unitCount > 0 && item.reviewCandidateCount > 0); |
| 163 | assert(course); const detail = (await api('GET',`/v1/education/courses/${course.id}`,undefined,token)).json; |
| 164 | const unit = detail.units.find(item => item.reviewCandidateCount > 0); |
| 165 | assert(unit && uuid.test(unit.id),'A real draft resource must exist behind the publication gate.'); |
| 166 | assert(detail.units.every(item => item.videos.length === 0)); |
| 167 | assert.equal((await api('GET','/v1/me/learning-progress',undefined,token)).json.progress.length,0, |
| 168 | 'Browsing a library must not fabricate learning progress.'); |
| 169 | check('grade1 common1405-1406 saved through UI and read by independent API'); |
| 170 | |
| 171 | stage = 'libraryLesson'; await lesson(page,course,unit); |
| 172 | await bodyIncludes(page,'ویدیوی بازبینیشده و منتشرشده هنوز ثبت نشده'); |
| 173 | assert.equal(await page.locator('iframe').count(),0); |
| 174 | assert.equal((await api('GET','/v1/me/learning-progress',undefined,token)).json.progress.length,0, |
| 175 | 'Opening a lesson must not automatically record learning progress.'); |
| 176 | check('actual imported lesson renders with draft videos unavailable, no iframe'); |
| 177 | |
| 178 | stage = 'progress'; |
| 179 | const progressResponse = page.waitForResponse(response => response.url().includes('/api/v1/me/learning-progress/') && response.request().method() === 'PUT'); |
| 180 | await click(page.getByRole('button',{name:'در حال یادگیری',exact:true})); |
| 181 | const ackResponse = await progressResponse; assert.equal(ackResponse.status(),200); |
| 182 | const ack = await ackResponse.json(); assert.equal(ack.source,'self_reported'); |
| 183 | assert.equal(ack.unitId,unit.id); assert.equal(ack.status,'in_progress'); assert.equal(ack.version,1); |
| 184 | const independent = (await api('GET','/v1/me/learning-progress',undefined,token)).json.progress; |
| 185 | assert.equal(independent.length,1); assert.equal(independent[0].status,'in_progress'); |
| 186 | const stored = dbJson(`select json_build_object('count',count(*),'status',max(status),'source',max(source),'version',max(version)) from learning_progress where owner_user_id='${owner}' and unit_id='${unit.id}';`); |
| 187 | assert.deepEqual(stored,{count:1,status:'in_progress',source:'self_reported',version:1}); |
| 188 | await page.waitForLoadState('networkidle'); |
| 189 | await assertLearningProgressSemantics(page,independent[0]); |
| 190 | check('compiled Chromium AXTree exposes one RTL status with acknowledged progress and server timestamp'); |
| 191 | await fs.mkdir(path.dirname(receiptFile),{recursive:true}); |
| 192 | await page.screenshot({path:receiptFile.replace(/\.json$/, '-progress.png'),fullPage:false}); |
| 193 | check('UI progress acknowledgement independently verified through API and PostgreSQL'); |
| 194 | |
| 195 | stage = 'quizGate'; |
| 196 | const quizResponse = page.waitForResponse(response => response.url().endsWith(`/api/v1/education/units/${unit.id}/assessment`)); |
| 197 | await click(page.getByRole('button',{name:'تمرین فهم درس و مرور',exact:true})); |
| 198 | const quiz = await quizResponse; assert.equal(quiz.status(),200); |
| 199 | assert.deepEqual(await quiz.json(),{assessment:null,reason:'review_pending'}); |
| 200 | await bodyIncludes(page,'آزمون این درس در انتظار بازبینی است'); |
| 201 | check('real draft assessment gate shows no invented question bank'); |
| 202 | await click(page.getByRole('button',{name:'برگشتن',exact:true})); |
| 203 | |
| 204 | stage = 'feedback'; |
| 205 | await click(page.getByRole('button',{name:'گزارش ایراد این درس',exact:true})); |
| 206 | const syntheticSummary = 'SYNTHETIC_BROWSER_FEEDBACK_NO_PERSONAL_DATA'; |
| 207 | const summaryInput = page.getByLabel('خلاصه ایراد یا پیشنهاد',{exact:true}); |
| 208 | await summaryInput.pressSequentially(syntheticSummary,{delay:5}); |
| 209 | await summaryInput.press('Tab'); |
| 210 | const postsBefore = paths.filter(item => item.path === '/api/v1/education/feedback' && item.method === 'POST').length; |
| 211 | await click(page.getByRole('button',{name:'ارسال بازخورد',exact:true})); |
| 212 | await bodyIncludes(page,'خلاصه و رضایت ارسال را تکمیل کن.'); |
| 213 | assert.equal(paths.filter(item => item.path === '/api/v1/education/feedback' && item.method === 'POST').length,postsBefore); |
| 214 | await click(page.getByRole('checkbox')); |
| 215 | const feedbackResponse = page.waitForResponse(response => response.url().endsWith('/api/v1/education/feedback') && response.request().method() === 'POST'); |
| 216 | await click(page.getByRole('button',{name:'ارسال بازخورد',exact:true})); |
| 217 | const sent = await feedbackResponse; assert.equal(sent.status(),201); |
| 218 | const feedback = (await sent.json()).feedback; assert(uuid.test(feedback.id)); |
| 219 | await bodyIncludes(page,'بازخورد در سرور ثبت شد'); |
| 220 | assert.equal((await api('GET','/v1/me/education-feedback',undefined,token)).json.feedback[0].summary,syntheticSummary); |
| 221 | check('feedback blocked without explicit consent then acknowledged by real server'); |
| 222 | const withdrawnResponse = page.waitForResponse(response => response.url().endsWith(`/api/v1/me/education-feedback/${feedback.id}`) && response.request().method() === 'DELETE'); |
| 223 | await click(page.getByRole('button',{name:'پسگرفتن رضایت',exact:true})); |
| 224 | assert.equal((await withdrawnResponse).status(),204); |
| 225 | await bodyIncludes(page,'رضایت ارسال پس گرفته شد'); |
| 226 | const withdrawn = (await api('GET','/v1/me/education-feedback',undefined,token)).json.feedback[0]; |
| 227 | assert.equal(withdrawn.summary,null); assert.equal(withdrawn.shareWithContentTeam,false); assert(withdrawn.withdrawnAt); |
| 228 | const redacted = dbJson(`select json_build_object('count',count(*),'summaryRedacted',bool_and(summary is null),'consentWithdrawn',bool_and(not share_with_content_team),'withdrawn',bool_and(withdrawn_at is not null)) from learning_content_feedback where owner_user_id='${owner}' and id='${feedback.id}';`); |
| 229 | assert.deepEqual(redacted,{count:1,summaryRedacted:true,consentWithdrawn:true,withdrawn:true}); |
| 230 | check('withdrawal redacts chosen text and consent in independent API and PostgreSQL'); |
| 231 | |
| 232 | stage = 'restart'; |
| 233 | await page.goto('about:blank'); await context.close(); context = null; |
| 234 | context = await launch(); page = await boot(context); |
| 235 | await school(page); await lesson(page,course,unit); |
| 236 | await page.waitForLoadState('networkidle'); |
| 237 | assert(auth.some(item => item.path === '/api/v1/auth/refresh' && item.status === 200)); |
| 238 | const afterRestart = (await api('GET','/v1/me/learning-progress',undefined,token)).json.progress; |
| 239 | assert.equal(afterRestart.length,1); assert.equal(afterRestart[0].version,1); |
| 240 | await assertLearningProgressSemantics(page,afterRestart[0]); |
| 241 | assert.equal(await page.locator('iframe').count(),0); |
| 242 | check('closed and reopened Chromium refreshes persisted session; independent API retains one acknowledged progress record'); |
| 243 | |
| 244 | stage = 'networkAudit'; |
| 245 | assert.equal(paths.filter(item => item.origin !== origin).length,0); |
| 246 | assert.equal(errors.length,0); assert.equal(failures.length,0); |
| 247 | assert(paths.some(item => item.path.includes('/canvaskit/') && item.path.endsWith('.wasm'))); |
| 248 | for (const font of ['LifeGuidePersian.ttf','LifeGuideLatin.ttf','LifeGuideEmoji.ttf']) |
| 249 | assert(paths.some(item => item.path.endsWith(font))); |
| 250 | check('real compiled runtime uses only local API, fonts and CanvasKit without errors'); |
| 251 | await fs.mkdir(path.dirname(receiptFile),{recursive:true}); |
| 252 | await page.screenshot({path:screenshotFile,fullPage:false}); |
| 253 | |
| 254 | stage = 'offlineIntent'; |
| 255 | await page.evaluate(async () => { |
| 256 | await navigator.serviceWorker.ready; |
| 257 | if (!navigator.serviceWorker.controller) await new Promise(resolve => |
| 258 | navigator.serviceWorker.addEventListener('controllerchange',resolve,{once:true})); |
| 259 | }); |
| 260 | const offlineStart = {requests:paths.length,errors:errors.length,failures:failures.length}; |
| 261 | const offlineKey = 'lifeguide.offline.v2.' + Buffer.from(origin+'/api|'+owner) |
| 262 | .toString('base64').replaceAll('+','-').replaceAll('/','_'); |
| 263 | await context.setOffline(true); |
| 264 | await click(page.getByRole('button',{name:'طبق گزارش من تکمیل شد',exact:true})); |
| 265 | await bodyIncludes(page,'تغییر روی دستگاه ذخیره شده؛ تأیید سرور دریافت نشده است.'); |
| 266 | const pendingBytes = await page.evaluate(key => localStorage.getItem(key),offlineKey); |
| 267 | assert(pendingBytes,'A real rendered offline action must create durable account-scoped bytes.'); |
| 268 | const pending = JSON.parse(JSON.parse(pendingBytes)).queue; |
| 269 | assert.equal(pending.length,1); |
| 270 | assert.equal(pending[0].entityType,'learning_progress'); |
| 271 | assert.equal(pending[0].entityId,unit.id); |
| 272 | assert.equal(pending[0].payload.status,'completed'); |
| 273 | assert.equal(pending[0].payload.expectedVersion,1); |
| 274 | assert(uuid.test(pending[0].id)); |
| 275 | assert.equal((await api('GET','/v1/me/learning-progress',undefined,token)).json.progress[0].version,1); |
| 276 | check('rendered offline action journals one stable progress intent; independent server remains unchanged'); |
| 277 | |
| 278 | stage = 'offlineReopen'; |
| 279 | await page.close(); |
| 280 | page = await context.newPage(); observe(page); |
| 281 | const disconnected = await page.goto(origin,{waitUntil:'networkidle',timeout:30000}); |
| 282 | assert.equal(disconnected.status(),200); |
| 283 | assert.equal(await page.locator('html').getAttribute('dir'),'rtl'); |
| 284 | await page.getByRole('status').filter({hasText:'اتصال برقرار نیست'}).waitFor(); |
| 285 | assert.equal(await page.locator('flt-glass-pane').count(),0); |
| 286 | assert(!(await page.locator('body').innerText()).includes(unit.titleFa)); |
| 287 | assert.equal(await page.evaluate(key => localStorage.getItem(key),offlineKey),pendingBytes); |
| 288 | for (const endpoint of ['/api/health','/config.json']) { |
| 289 | const result = await page.evaluate(async endpoint => { |
| 290 | try { const r=await fetch(endpoint); return {reachable:true,text:await r.text()}; } |
| 291 | catch { return {reachable:false}; } |
| 292 | },endpoint); |
| 293 | assert.equal(result.reachable,false,'Private/API/config paths must not receive cached offline HTML.'); |
| 294 | } |
| 295 | const cachedUrls = await page.evaluate(async () => { |
| 296 | const result=[]; |
| 297 | for (const name of await caches.keys()) for (const request of await (await caches.open(name)).keys()) |
| 298 | result.push(new URL(request.url).pathname); |
| 299 | return result; |
| 300 | }); |
| 301 | assert(!cachedUrls.some(p=>p==='/'||p==='/index.html'||p==='/config.json'||p.startsWith('/api/'))); |
| 302 | check('closed/reopened offline PWA shows only public RTL notice; exact pending bytes retained, API/config remain unavailable'); |
| 303 | |
| 304 | stage = 'offlineReconnect'; |
| 305 | await context.setOffline(false); |
| 306 | await page.getByRole('button',{name:'تلاش دوباره',exact:true}).click(); |
| 307 | await page.waitForFunction(() => !document.getElementById('startup-status'),null,{timeout:60000}); |
| 308 | await page.locator('flt-glass-pane').waitFor({state:'attached'}); |
| 309 | const placeholder=page.locator('flt-semantics-placeholder'); |
| 310 | if(await placeholder.count()) await placeholder.evaluate(e=>e.click()); |
| 311 | await school(page); await lesson(page,course,unit); |
| 312 | const replay = page.waitForResponse(r=>r.url().includes('/api/v1/me/learning-progress/')&&r.request().method()==='PUT'); |
| 313 | await click(page.getByRole('button',{name:'همگامسازی و تازهسازی',exact:true})); |
| 314 | const accepted = await replay; |
| 315 | assert.equal(accepted.status(),200); |
| 316 | const replayBody=accepted.request().postDataJSON(); |
| 317 | assert.deepEqual(replayBody,pending[0].payload); |
| 318 | await page.waitForLoadState('networkidle'); |
| 319 | const synced=(await api('GET','/v1/me/learning-progress',undefined,token)).json.progress; |
| 320 | assert.equal(synced.length,1); assert.equal(synced[0].version,2); assert.equal(synced[0].status,'completed'); |
| 321 | await assertLearningProgressSemantics(page,synced[0]); |
| 322 | const storedAfter=dbJson(`select json_build_object('count',count(*),'version',max(version),'status',max(status)) from learning_progress where owner_user_id='${owner}' and unit_id='${unit.id}';`); |
| 323 | assert.deepEqual(storedAfter,{count:1,version:2,status:'completed'}); |
| 324 | const afterBytes=await page.evaluate(key=>localStorage.getItem(key),offlineKey); |
| 325 | assert.equal(JSON.parse(JSON.parse(afterBytes)).queue.length,0); |
| 326 | await click(page.getByRole('button',{name:'همگامسازی و تازهسازی',exact:true})); |
| 327 | await page.waitForLoadState('networkidle'); |
| 328 | assert.equal((await api('GET','/v1/me/learning-progress',undefined,token)).json.progress[0].version,2); |
| 329 | check('manual reconnect authenticates current account and acknowledges identical intent once; second sync creates no duplicate'); |
| 330 | assert.equal(paths.filter(item=>item.origin!==origin).length,0); |
| 331 | assert.equal(errors.length,offlineStart.errors); |
| 332 | const receipt = {date:new Date().toISOString(),mode:'Actual isolated local Compose HTTPS; normal Node and Chromium CA trust; no network interception or TLS bypass', |
| 333 | origin,browser:'Chromium',checks,fixture:'Dedicated synthetic account; no real family/private/media data', |
| 334 | counts:{requests:paths.length,externalRequests:0,iframes:0,browserErrors:errors.length, |
| 335 | onlineFailedRequests:offlineStart.failures,expectedOfflineFailedRequests:failures.length-offlineStart.failures}, |
| 336 | offlineEvidence:'Chromium context deliberately disconnected; real UI journals a stable intent, page closes/reopens through actual service worker public fallback, reconnect retries exact body and independent API/SQL verify version2 once. Context stays open during offline page restart; process-kill/storage-eviction/Safari remain UNVERIFIED.', |
| 337 | realApprovedVideoCount:0,realApprovedQuestionBankCount:0, |
| 338 | visualEvidence:{progressScreenshot:path.basename(receiptFile.replace(/\.json$/, '-progress.png')), |
| 339 | reopenedLessonScreenshot:path.basename(screenshotFile), |
| 340 | automatedDynamicProgressSemantics:'Actual Chromium AXTree status label checked after acknowledgement and browser restart; physical screen-reader acceptance remains UNVERIFIED'}, |
| 341 | interactionMode:'Rendered Flutter semantic controls activated with DOM element.click because RTL hit rectangles are transformed; text entered through rendered fields and keyboard. No API or state injection. Physical touch/pointer/accessibility acceptance is UNVERIFIED.', |
| 342 | authResponses:auth,fonts:[...new Set(paths.filter(item => /\.(ttf|otf|woff2)$/.test(item.path)).map(item => item.path))], |
| 343 | limitations:['Real Android devices UNVERIFIED','Safari/Add to Home Screen UNVERIFIED','Video playback and teaching quality UNVERIFIED','Iran VPN-free reachability UNVERIFIED','Physical touch and screen reader UNVERIFIED']}; |
| 344 | await fs.writeFile(receiptFile,JSON.stringify(receipt,null,2)+'\n'); |
| 345 | console.log(JSON.stringify(receipt,null,2)); |
| 346 | } catch (error) { |
| 347 | if (process.env.LEARNING_BROWSER_DIAGNOSTICS && context && stage !== 'realLogin') { |
| 348 | const page = context.pages()[0]; |
| 349 | const file = path.resolve(process.env.LEARNING_BROWSER_DIAGNOSTICS); |
| 350 | assert(!file.startsWith(root + path.sep), 'Private diagnostics must stay outside the repo.'); |
| 351 | if (page) await fs.writeFile(file,(await page.locator('body').ariaSnapshot()) |
| 352 | .replaceAll(email,'[synthetic fixture]').replaceAll(password,'[redacted]'),{mode:0o600}); |
| 353 | if (page) await page.screenshot({path:file + '.png',fullPage:false}); |
| 354 | } |
| 355 | console.error(`FAIL ${stage}: ${error.message.replaceAll(email,'[synthetic fixture]').replaceAll(password,'[redacted]')}`); |
| 356 | throw new Error(`Local learning browser acceptance failed at ${stage}`); |
| 357 | } finally { |
| 358 | if(context) { for(const page of context.pages()) await page.goto('about:blank').catch(()=>{}); await context.close(); } |
| 359 | await fs.rm(profile,{recursive:true,force:true}); |
| 360 | } |
| 361 | })().catch(error => {console.error(error.message);process.exitCode=1;}); |