LifeMate — Personal, Family & Learning Companion

fix/lifeguide-pages-qa-base-preflight
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
mjs 65 lines 4.07 KB
Raw
1 #!/usr/bin/env node
2 // Regression for a checked CI artifact on a Windows-style Git checkout.
3 // Requires a real, already built/postprocessed/stamped artifact. Never builds
4 // Flutter, restamps the artifact, changes repository inputs or touches Docker.
5 import assert from 'node:assert/strict';
6 import { execFileSync, spawnSync } from 'node:child_process';
7 import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
8 import { tmpdir } from 'node:os';
9 import { join, relative, resolve, sep } from 'node:path';
10 import { fileURLToPath } from 'node:url';
11
12 const app = resolve(process.argv[2] ?? fileURLToPath(new URL('../apps/lifemate/', import.meta.url)));
13 const root = execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd: app, encoding: 'utf8' }).trim();
14 const appRelative = relative(root, app).split(sep).join('/');
15 assert(appRelative && !appRelative.startsWith('../') && !appRelative.startsWith('/'), 'Application must be inside the repository');
16 const checker = join(root, 'scripts/prebuilt-web-check.mjs');
17 const shellScripts = ['backend/scripts/backup.sh', 'backend/scripts/restore.sh', 'scripts/local-deploy.sh'];
18 const tracked = execFileSync('git', ['ls-files', '-z', '--', appRelative, ...shellScripts], { cwd: root });
19 assert(tracked.length > 0, 'Application has no indexed source files');
20 const binaryInputs = tracked.toString('utf8').split('\0').filter(path => /\.(ttf|otf|woff2?|png|jpe?g|ico|webp)$/i.test(path));
21
22 function check(target, label, expectedError) {
23 const result = spawnSync(process.execPath, [checker, target], { cwd: root, encoding: 'utf8' });
24 if (expectedError) {
25 assert(result.status !== 0 && result.stderr.includes(expectedError), `${label}: expected rejection\n${result.stdout}\n${result.stderr}`);
26 } else {
27 assert.equal(result.status, 0, `${label}: checker failed\n${result.stdout}\n${result.stderr}`);
28 }
29 console.log(`PASS ${label}`);
30 }
31
32 check(app, 'original checked artifact');
33 const temporary = await mkdtemp(join(tmpdir(), 'lifeguide-checkout-regression-'));
34 try {
35 for (const [name, autocrlf] of [['lf', 'false'], ['windows', 'true']]) {
36 const checkout = join(temporary, name);
37 // Git consumes a slash-terminated checkout prefix, including on Windows.
38 const prefix = `${checkout.split(sep).join('/')}/`;
39 execFileSync('git', ['-c', `core.autocrlf=${autocrlf}`, 'checkout-index', '-z', '--stdin', `--prefix=${prefix}`], { cwd: root, input: tracked });
40 const checkedApp = join(checkout, appRelative);
41 await cp(join(app, 'build/web'), join(checkedApp, 'build/web'), { recursive: true });
42 check(checkedApp, `actual Git checkout core.autocrlf=${autocrlf}`);
43 for (const path of shellScripts) {
44 const contents = await readFile(join(checkout, path));
45 assert(!contents.includes(Buffer.from('\r\n')), `${path} must retain LF for Linux container execution`);
46 }
47 for (const path of binaryInputs) {
48 assert((await readFile(join(checkout, path))).equals(await readFile(join(root, path))), `${path} binary bytes changed during checkout`);
49 }
50 console.log(`PASS core.autocrlf=${autocrlf}: three shell scripts retain LF; ${binaryInputs.length} font/icon binaries are byte-identical`);
51 if (name === 'windows') {
52 const source = join(checkedApp, 'lib/main.dart');
53 const originalSource = await readFile(source);
54 await writeFile(source, Buffer.concat([originalSource, Buffer.from('\n// synthetic source integrity probe\n')]));
55 check(checkedApp, 'source change is still rejected', 'Source changed after recorded build');
56 await writeFile(source, originalSource);
57 const artifact = join(checkedApp, 'build/web/main.dart.js');
58 await writeFile(artifact, Buffer.concat([await readFile(artifact), Buffer.from('\n// synthetic artifact integrity probe\n')]));
59 check(checkedApp, 'artifact change is still rejected', 'Built artifact changed after its recorded check');
60 }
61 }
62 console.log('PASS prebuilt checkout regression: provenance, Windows checkout, shell endings, binary preservation and tamper rejection; no build or restamp performed.');
63 } finally {
64 await rm(temporary, { recursive: true, force: true });
65 }