LifeMate — Personal, Family & Learning Companion

docs/owner-guide-and-delivery-plan
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
js 60 lines 3.51 KB
Raw
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 and planner migrations and keeps private lockdown', async () => {
10 const { sql, manifest } = await buildSupabaseQaSql();
11 assert.equal(manifest.length, 24);
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.equal(manifest[23].filename, '0026_personal_planner_series.sql');
17 assert.match(sql, /create table planner_series/);
18 assert.match(sql, /plan_item_series_private/);
19 assert.match(sql, /create table auth_ip_rate_limit/);
20 assert.ok(manifest.every(x => /^[a-f0-9]{64}$/.test(x.sha256)));
21 assert.match(sql, /set local search_path=lifeguide_qa,extensions,pg_catalog/);
22 assert.equal((sql.match(/set search_path=lifeguide_qa,pg_catalog/gi) ?? []).length, 5);
23 assert.equal((sql.match(/set search_path=public,pg_catalog/gi) ?? []).length, 0);
24 assert.match(sql, /create table if not exists lifeguide_qa.schema_migration/);
25 assert.match(sql, /force row level security/);
26 assert.match(sql, /revoke all on schema lifeguide_qa from public, anon, authenticated, service_role/);
27 assert.doesNotMatch(sql, /create extension if not exists pgcrypto/i);
28 assert.doesNotMatch(sql, /alter schema public owner/i);
29 assert.doesNotMatch(sql, /reassign owned/i);
30 assert.doesNotMatch(sql, /create role/i);
31 assert.equal((sql.match(/^begin;/gm) ?? []).length, 1);
32 assert.equal((sql.match(/^commit;/gm) ?? []).length, 1);
33 });
34
35 test('QA bundle generation fails closed if source migration count is incomplete', async () => {
36 const dir = await mkdtemp(join(tmpdir(),'lifeguide-qa-missing-'));
37 try {
38 await writeFile(join(dir,'0001_identity_family.sql'),'select 1;');
39 await assert.rejects(buildSupabaseQaSql({ migrationsDir:pathToFileURL(dir+'/') }),/expected_baseline_and_auth_migrations_in_order/);
40 } finally { await rm(dir,{recursive:true,force:true}); }
41 });
42
43 test('QA bundle generation rejects drift adding production schema privileges', async () => {
44 const dir = await mkdtemp(join(tmpdir(),'lifeguide-qa-drift-'));
45 try {
46 for (let n=1;n<=20;n++) {
47 const id=String(n).padStart(4,'0');
48 const sql=n===1?'create extension if not exists pgcrypto;\nselect 1;':n===19?
49 Array(5).fill('create function test_fn() returns int language sql set search_path=public,pg_catalog as $$select 1$$;').join('\n'):
50 'select 1;';
51 await writeFile(join(dir,`${id}_test.sql`),sql);
52 }
53 await writeFile(join(dir,'0023_auth_ip_rate_limit.sql'), 'select 1;');
54 await writeFile(join(dir,'0024_child_device_safety.sql'), 'select 1;');
55 await writeFile(join(dir,'0025_managed_guardian_authority.sql'), 'select 1;');
56 await writeFile(join(dir,'0026_personal_planner_series.sql'), 'select 1;');
57 await writeFile(join(dir,'0004_test.sql'),'create table public.account(id int);');
58 await assert.rejects(buildSupabaseQaSql({ migrationsDir:pathToFileURL(dir+'/') }),/source_migration_outside_private_qa:0004_test.sql/);
59 } finally { await rm(dir,{recursive:true,force:true}); }
60 });