LifeMate — Personal, Family & Learning Companion

fix/auth-expiry-after-lock
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 49 lines 2.74 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 20 original checksums, creates private schema objects and corrects school guard paths', async () => {
10 const { sql, manifest } = await buildSupabaseQaSql();
11 assert.equal(manifest.length, 20);
12 assert.ok(manifest.every((x,i) => x.filename.startsWith(String(i+1).padStart(4,'0')+'_')));
13 assert.ok(manifest.every(x => /^[a-f0-9]{64}$/.test(x.sha256)));
14 assert.match(sql, /set local search_path=lifeguide_qa,extensions,pg_catalog/);
15 assert.equal((sql.match(/set search_path=lifeguide_qa,pg_catalog/gi) ?? []).length, 5);
16 assert.equal((sql.match(/set search_path=public,pg_catalog/gi) ?? []).length, 0);
17 assert.match(sql, /create table if not exists lifeguide_qa.schema_migration/);
18 assert.match(sql, /force row level security/);
19 assert.match(sql, /revoke all on schema lifeguide_qa from public, anon, authenticated, service_role/);
20 assert.doesNotMatch(sql, /create extension if not exists pgcrypto/i);
21 assert.doesNotMatch(sql, /alter schema public owner/i);
22 assert.doesNotMatch(sql, /reassign owned/i);
23 assert.doesNotMatch(sql, /create role/i);
24 assert.equal((sql.match(/^begin;/gm) ?? []).length, 1);
25 assert.equal((sql.match(/^commit;/gm) ?? []).length, 1);
26 });
27
28 test('QA bundle generation fails closed if source migration count is incomplete', async () => {
29 const dir = await mkdtemp(join(tmpdir(),'lifeguide-qa-missing-'));
30 try {
31 await writeFile(join(dir,'0001_identity_family.sql'),'select 1;');
32 await assert.rejects(buildSupabaseQaSql({ migrationsDir:pathToFileURL(dir+'/') }),/expected_exactly_20_original_migrations_in_order/);
33 } finally { await rm(dir,{recursive:true,force:true}); }
34 });
35
36 test('QA bundle generation rejects drift adding production schema privileges', async () => {
37 const dir = await mkdtemp(join(tmpdir(),'lifeguide-qa-drift-'));
38 try {
39 for (let n=1;n<=20;n++) {
40 const id=String(n).padStart(4,'0');
41 const sql=n===1?'create extension if not exists pgcrypto;\nselect 1;':n===19?
42 Array(5).fill('create function test_fn() returns int language sql set search_path=public,pg_catalog as $$select 1$$;').join('\n'):
43 'select 1;';
44 await writeFile(join(dir,`${id}_test.sql`),sql);
45 }
46 await writeFile(join(dir,'0004_test.sql'),'create table public.account(id int);');
47 await assert.rejects(buildSupabaseQaSql({ migrationsDir:pathToFileURL(dir+'/') }),/source_migration_outside_private_qa:0004_test.sql/);
48 } finally { await rm(dir,{recursive:true,force:true}); }
49 });