LifeMate — Personal, Family & Learning Companion
docs/offline-data-rescue-options
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 | #!/usr/bin/env node |
| 2 | // This records build inputs only after the operator has actually run the build. |
| 3 | // It does not compile Flutter and must never be reported as a build itself. |
| 4 | import { readFile, readdir, writeFile } from 'node:fs/promises'; |
| 5 | import { resolve, join, relative, basename, sep } from 'node:path'; |
| 6 | import { createHash } from 'node:crypto'; |
| 7 | |
| 8 | const app = resolve(process.argv[2] ?? 'apps/lifemate'); |
| 9 | const output = join(app, 'build/web'); |
| 10 | const stamp = process.argv.includes('--stamp-after-build'); |
| 11 | async function walk(directory) { |
| 12 | const files = []; |
| 13 | for (const entry of await readdir(directory, { withFileTypes: true })) { |
| 14 | const path = join(directory, entry.name); |
| 15 | if (entry.isSymbolicLink()) throw new Error('Symlinks forbidden in web build inputs/artifact'); |
| 16 | if (entry.isDirectory()) files.push(...await walk(path)); |
| 17 | else if (entry.isFile()) files.push(path); |
| 18 | } |
| 19 | return files.sort(); |
| 20 | } |
| 21 | function assert(condition, message) { if (!condition) throw new Error(message); } |
| 22 | const inputs = [join(app, 'pubspec.yaml'), join(app, 'pubspec.lock'), join(app, 'tool/self_host_web.mjs')]; |
| 23 | for (const path of ['lib', 'assets', 'web']) inputs.push(...await walk(join(app, path))); |
| 24 | const hash = createHash('sha256'); |
| 25 | for (const path of inputs.sort()) { |
| 26 | hash.update(relative(app, path).split(sep).join('/')); hash.update('\0'); |
| 27 | hash.update(await readFile(path)); hash.update('\0'); |
| 28 | } |
| 29 | const sourceDigest = hash.digest('hex'); |
| 30 | const files = await walk(output); |
| 31 | for (const path of files.filter(path => /\.(js|json|html)$/.test(path))) { |
| 32 | const text = await readFile(path, 'utf8'); |
| 33 | assert(!/https?:[^\s"'<>]*(?:gstatic\.com|googleapis\.com|up\.railway\.app)/i.test(text), `External runtime dependency: ${relative(output, path)}`); |
| 34 | } |
| 35 | for (const path of ['index.html', 'main.dart.js', 'flutter_bootstrap.js', 'lifeguide-sw.js', 'offline.html', 'offline-retry.js', 'canvaskit/canvaskit.wasm']) { |
| 36 | assert(files.includes(join(output, path)), `Missing built resource: ${path}`); |
| 37 | } |
| 38 | for (const name of ['LifeGuidePersian.ttf', 'LifeGuideLatin.ttf', 'LifeGuideEmoji.ttf']) { |
| 39 | assert(files.some(path => basename(path) === name), `Missing local font: ${name}`); |
| 40 | } |
| 41 | const manifest = JSON.parse(await readFile(join(output, 'manifest.json'), 'utf8')); |
| 42 | assert(manifest.name.includes('LifeGuide') && manifest.short_name === 'لایفگاید' && manifest.display === 'standalone', 'LifeGuide standalone manifest required'); |
| 43 | const config = JSON.parse(await readFile(join(output, 'config.json'), 'utf8')); |
| 44 | assert(config.apiBaseUrl === '/api', 'Prebuilt default API must use runtime same-origin /api'); |
| 45 | const builtTitle = /<title>([^<]+)<\/title>/.exec(await readFile(join(output, 'index.html'), 'utf8'))?.[1]; |
| 46 | const sourceTitle = /<title>([^<]+)<\/title>/.exec(await readFile(join(app, 'web/index.html'), 'utf8'))?.[1]; |
| 47 | assert(builtTitle === sourceTitle && builtTitle?.includes('LifeGuide'), 'LifeGuide HTML title must match source'); |
| 48 | for (const path of ['manifest.json', 'lifeguide-sw.js', 'offline.html', 'offline-retry.js', 'favicon.png', 'icons/Icon-192.png', 'icons/Icon-512.png', 'icons/Icon-maskable-192.png', 'icons/Icon-maskable-512.png']) { |
| 49 | assert((await readFile(join(output, path))).equals(await readFile(join(app, 'web', path))), `Built branding differs from source: ${path}`); |
| 50 | } |
| 51 | const provenance = join(output, 'build-provenance.json'); |
| 52 | const artifactHash = createHash('sha256'); |
| 53 | for (const path of files.filter(path => path !== provenance)) { |
| 54 | artifactHash.update(relative(output, path).split(sep).join('/')); artifactHash.update('\0'); |
| 55 | artifactHash.update(await readFile(path)); artifactHash.update('\0'); |
| 56 | } |
| 57 | const artifactDigest = artifactHash.digest('hex'); |
| 58 | if (stamp) { |
| 59 | await writeFile(provenance, JSON.stringify({ sourceDigest, artifactDigest, inputFiles: inputs.length, recordedAt: new Date().toISOString(), |
| 60 | requiredFlutterVersion: '3.47.6', requiredFlutterRevision: '5fc346839b5d0eef006ed8404392afb4dfae428d', |
| 61 | command: 'flutter build web --release --no-web-resources-cdn --pwa-strategy=none; node tool/self_host_web.mjs build/web', |
| 62 | limitation: 'Recorded only after a real build; this checker does not compile or prove device acceptance.' }, null, 2) + '\n'); |
| 63 | } else { |
| 64 | const recorded = JSON.parse(await readFile(provenance, 'utf8')); |
| 65 | assert(recorded.sourceDigest === sourceDigest, 'Source changed after recorded build; rebuild and recheck web before packaging'); |
| 66 | assert(recorded.artifactDigest === artifactDigest, 'Built artifact changed after its recorded check'); |
| 67 | } |
| 68 | console.log(`PASS prebuilt LifeGuide web: ${inputs.length} input files, local fonts/CanvasKit, same-origin runtime config, current branding and matching source digest.`); |