LifeMate — Personal, Family & Learning Companion
docs/child-education-access-decision
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 | import test from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { mkdtemp, writeFile, rm } from 'node:fs/promises'; |
| 4 | import { tmpdir } from 'node:os'; |
| 5 | import { join } from 'node:path'; |
| 6 | import { pathToFileURL } from 'node:url'; |
| 7 | import { buildSupabaseQaSql } from '../scripts/build-supabase-qa-sql.js'; |
| 8 | |
| 9 | test('QA bundle retains original checksums plus additive identity migrations and keeps private lockdown', async () => { |
| 10 | const { sql, manifest } = await buildSupabaseQaSql(); |
| 11 | assert.equal(manifest.length, 23); |
| 12 | assert.ok(manifest.slice(0,20).every((x,i) => x.filename.startsWith(String(i+1).padStart(4,'0')+'_'))); |
| 13 | assert.equal(manifest[20].filename, '0023_auth_ip_rate_limit.sql'); |
| 14 | assert.equal(manifest[21].filename, '0024_child_device_safety.sql'); |
| 15 | assert.equal(manifest[22].filename, '0025_managed_guardian_authority.sql'); |
| 16 | assert.match(sql, /create table auth_ip_rate_limit/); |
| 17 | assert.ok(manifest.every(x => /^[a-f0-9]{64}$/.test(x.sha256))); |
| 18 | assert.match(sql, /set local search_path=lifeguide_qa,extensions,pg_catalog/); |
| 19 | assert.equal((sql.match(/set search_path=lifeguide_qa,pg_catalog/gi) ?? []).length, 5); |
| 20 | assert.equal((sql.match(/set search_path=public,pg_catalog/gi) ?? []).length, 0); |
| 21 | assert.match(sql, /create table if not exists lifeguide_qa.schema_migration/); |
| 22 | assert.match(sql, /force row level security/); |
| 23 | assert.match(sql, /revoke all on schema lifeguide_qa from public, anon, authenticated, service_role/); |
| 24 | assert.doesNotMatch(sql, /create extension if not exists pgcrypto/i); |
| 25 | assert.doesNotMatch(sql, /alter schema public owner/i); |
| 26 | assert.doesNotMatch(sql, /reassign owned/i); |
| 27 | assert.doesNotMatch(sql, /create role/i); |
| 28 | assert.equal((sql.match(/^begin;/gm) ?? []).length, 1); |
| 29 | assert.equal((sql.match(/^commit;/gm) ?? []).length, 1); |
| 30 | }); |
| 31 | |
| 32 | test('QA bundle generation fails closed if source migration count is incomplete', async () => { |
| 33 | const dir = await mkdtemp(join(tmpdir(),'lifeguide-qa-missing-')); |
| 34 | try { |
| 35 | await writeFile(join(dir,'0001_identity_family.sql'),'select 1;'); |
| 36 | await assert.rejects(buildSupabaseQaSql({ migrationsDir:pathToFileURL(dir+'/') }),/expected_baseline_and_auth_migrations_in_order/); |
| 37 | } finally { await rm(dir,{recursive:true,force:true}); } |
| 38 | }); |
| 39 | |
| 40 | test('QA bundle generation rejects drift adding production schema privileges', async () => { |
| 41 | const dir = await mkdtemp(join(tmpdir(),'lifeguide-qa-drift-')); |
| 42 | try { |
| 43 | for (let n=1;n<=20;n++) { |
| 44 | const id=String(n).padStart(4,'0'); |
| 45 | const sql=n===1?'create extension if not exists pgcrypto;\nselect 1;':n===19? |
| 46 | Array(5).fill('create function test_fn() returns int language sql set search_path=public,pg_catalog as $$select 1$$;').join('\n'): |
| 47 | 'select 1;'; |
| 48 | await writeFile(join(dir,`${id}_test.sql`),sql); |
| 49 | } |
| 50 | await writeFile(join(dir,'0023_auth_ip_rate_limit.sql'), 'select 1;'); |
| 51 | await writeFile(join(dir,'0024_child_device_safety.sql'), 'select 1;'); |
| 52 | await writeFile(join(dir,'0025_managed_guardian_authority.sql'), 'select 1;'); |
| 53 | await writeFile(join(dir,'0004_test.sql'),'create table public.account(id int);'); |
| 54 | await assert.rejects(buildSupabaseQaSql({ migrationsDir:pathToFileURL(dir+'/') }),/source_migration_outside_private_qa:0004_test.sql/); |
| 55 | } finally { await rm(dir,{recursive:true,force:true}); } |
| 56 | }); |