@davoodmehraban89 / LifeMate / commits / 5cb8585
Fork 0

LifeMate — Personal, Family & Learning Companion

test(pages): cover repo subpath, fail-closed API, and early Pages validation

davoodmehraban89 committed Oct 15, 2026 at 09:31 UTC 5cb8585fc1706c536a7a60b32cbba64be7ec2c5b
1 file changed +37 -14
backend/tests/github_pages_qa.test.js
+37 -14
@@ -1,28 +1,51 @@
1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { readFile } from 'node:fs/promises';
4 +import { execFile } from 'node:child_process';
5 +import { promisify } from 'node:util';
6 +
7 const read = path => readFile(new URL(path, import.meta.url), 'utf8');
8 +const run = promisify(execFile);
9
6 -test('LifeGuide GitHub Pages QA build reuses checked Flutter bundle without credentials', async () => {
10 +test('LifeGuide GitHub Pages QA supports repo-path smoke before a custom domain', async () => {
11 const script = await read('../../scripts/build-github-pages-qa.sh');
12 + const sharedBuilder = await read('../../scripts/build-cloudflare-pages-qa.sh');
13 + assert.match(script, /LIFEGUIDE_PAGES_BASE_HREF:-\/LifeMate\//);
14 + assert.match(script, /\/LifeMate\/\|\//);
15 + assert.match(script, /LIFEGUIDE_FLUTTER_BASE_HREF="\$LIFEGUIDE_PAGES_BASE_HREF"/);
16 + assert.match(sharedBuilder, /LIFEGUIDE_FLUTTER_BASE_HREF:-\//);
17 + assert.match(sharedBuilder, /--base-href "\$LIFEGUIDE_FLUTTER_BASE_HREF"/);
18 assert.match(script, /bash scripts\/build-cloudflare-pages-qa\.sh/);
19 assert.match(script, /touch "\$out\/\.nojekyll"/);
10 - assert.match(script, /config\.apiBaseUrl !== '\/api'/);
20 + assert.match(script, /const expectedApiBase = base === '\/' \? '\/api' : base \+ 'api'/);
21 + assert.match(script, /config\.apiBaseUrl = expectedApiBase/);
22 assert.match(script, /config\.apiFallbackUrls\.length !== 0/);
12 - assert.match(script, /<base href="\/">/);
23 + assert.match(script, /<base href="/);
24 assert.match(script, /site-check\.txt/);
14 - assert.doesNotMatch(script,/KAVENEGAR_API_KEY|DATABASE_URL|SUPABASE_SERVICE_ROLE_KEY|\.up\.railway\.app/);
25 + assert.doesNotMatch(script, /KAVENEGAR_API_KEY|DATABASE_URL|SUPABASE_SERVICE_ROLE_KEY|\.up\.railway\.app/);
26 +});
27 +
28 +test('LifeGuide Pages QA refuses unsupported base URLs before invoking Flutter', async () => {
29 + const script = new URL('../../scripts/build-github-pages-qa.sh', import.meta.url).pathname;
30 + await assert.rejects(
31 + () => run('bash', [script], {env: {...process.env, LIFEGUIDE_PAGES_BASE_HREF: '/untrusted/'}}),
32 + error => error.code === 2 && /Unsupported LifeGuide Pages QA base href/.test(error.stderr),
33 + );
34 });
35
17 -test('GitHub Pages workflow deploys only after configured Pages action approval', async () => {
36 +test('GitHub Pages QA fails before an expensive Flutter build when Pages is off', async () => {
37 const workflow = await read('../../.github/workflows/lifeguide-github-pages-qa.yml');
19 - assert.match(workflow,/infra\/lifeguide-github-pages-qa/);
20 - assert.match(workflow,/scripts\/build-github-pages-qa\.sh/);
21 - assert.match(workflow,/actions\/configure-pages@v5/);
22 - assert.match(workflow,/actions\/upload-pages-artifact@v4/);
23 - assert.match(workflow,/actions\/deploy-pages@v4/);
24 - assert.match(workflow,/pages: write/);
25 - assert.match(workflow,/id-token: write/);
26 - assert.match(workflow,/github-pages/);
27 - assert.doesNotMatch(workflow,/main\]|deployment-static|KAVENEGAR_API_KEY|DATABASE_URL|SUPABASE_SERVICE_ROLE_KEY/);
38 + assert.match(workflow, /infra\/lifeguide-github-pages-qa/);
39 + assert.match(workflow, /actions\/configure-pages@v5/);
40 + assert.match(workflow, /LIFEGUIDE_PAGES_BASE_HREF: \/LifeMate\//);
41 + assert.match(workflow, /scripts\/build-github-pages-qa\.sh/);
42 + assert.match(workflow, /actions\/upload-pages-artifact@v4/);
43 + assert.match(workflow, /actions\/deploy-pages@v4/);
44 + assert.match(workflow, /pages: write/);
45 + assert.match(workflow, /id-token: write/);
46 + assert.match(workflow, /github-pages/);
47 + assert(workflow.indexOf('actions/configure-pages@v5') <
48 + workflow.indexOf('scripts/build-github-pages-qa.sh'),
49 + 'Configure-pages must fail before Flutter fetch/build when disabled.');
50 + assert.doesNotMatch(workflow, /main\]|deployment-static|KAVENEGAR_API_KEY|DATABASE_URL|SUPABASE_SERVICE_ROLE_KEY/);
51 });