@davoodmehraban89 / LifeMate / commits / 068a20f
Fork 0

LifeMate — Personal, Family & Learning Companion

test(cloudflare): verify QA Pages build and fail-closed API routes

davoodmehraban89 committed Oct 15, 2026 at 07:46 UTC 068a20f99e04f797a6e74a53c3c3d419b362668b
1 file changed +33
backend/tests/cloudflare_pages_qa.test.js new
+33
@@ -0,0 +1,33 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { readFile } from 'node:fs/promises';
4 +
5 +const read = path => readFile(new URL(path, import.meta.url), 'utf8');
6 +
7 +test('Cloudflare QA deploys only isolated LifeGuide web assets and disables live API until secure runtime exists', async () => {
8 + const script = await read('../../scripts/build-cloudflare-pages-qa.sh');
9 + assert.match(script,/FLUTTER_VERSION="3\.47\.6"/);
10 + assert.match(script,/flutter build web --release --no-web-resources-cdn --pwa-strategy=none/);
11 + assert.match(script,/self_host_web\.mjs build\/web/);
12 + assert.match(script,/apiBaseUrl!=='\/api'/);
13 + assert.match(script,/Cache-Control: no-store/);
14 + assert.doesNotMatch(script,/railway\.app|railway\.com|KAVENEGAR_API_KEY|SERVICE_ROLE_KEY|POSTGRES_PASSWORD|DATABASE_URL/);
15 +});
16 +
17 +test('QA API gateway paths fail closed with JSON 503, not SPA index.html fallback', async () => {
18 + for (const path of ['../../functions/api.ts','../../functions/api/[[path]].ts']) {
19 + const source = await read(path);
20 + assert.match(source,/503/);
21 + assert.match(source,/application\/json/);
22 + assert.match(source,/no-store/);
23 + assert.match(source,/lifeguide_api_not_ready/);
24 + assert.doesNotMatch(source,/fetch\s*\(/);
25 + assert.doesNotMatch(source,/service_role|supabaseKey|Authorization\s*:/i);
26 + }
27 + const ready=await read('../../functions/ready.ts');
28 + assert.match(ready,/status: 503/);
29 + assert.match(ready,/qa_backend_not_connected/);
30 + const health=await read('../../functions/health.ts');
31 + assert.match(health,/component: "pwa_gateway_only"/);
32 + assert.match(health,/backend: "not_connected"/);
33 +});