@davoodmehraban89 / LifeMate / commits / 96a1ff5
Fork 0

LifeMate — Personal, Family & Learning Companion

fix(ops): preserve checked web artifact bytes on Windows checkout

Quinn White committed Oct 9, 2026 at 07:45 UTC 96a1ff50475d0b4e3ea86f226984400c79ed96ab
2 files changed +69
.gitattributes
+4
@@ -1,2 +1,6 @@
1 +# CI artifacts hash source bytes and Linux containers execute these scripts.
2 +# Preserve LF on every platform; Git's auto detection leaves binaries intact.
3 +* text=auto eol=lf
4 +
5 # Preserve the upstream license text verbatim, including its line-end spaces.
6 apps/lifemate/assets/fonts/*.txt whitespace=-blank-at-eol
scripts/test-prebuilt-checkout.mjs new
+65
@@ -0,0 +1,65 @@
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 +}