LifeMate — Personal, Family & Learning Companion
test: add phase 4 safety contract tests
davoodmehraban89 committed
Oct 5, 2026 at 15:56 UTC
38b96d407f023419f49c139dec059d07a226d983
1 file changed
+24
backend/tests/phase4_contract.test.js
new
+24
@@ -0,0 +1,24 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import fs from 'node:fs';
4
+
5
+const src=fs.readFileSync(new URL('../src/phase4.js',import.meta.url),'utf8');
6
+const migration=fs.readFileSync(new URL('../migrations/0004_ai_learning_wellbeing.sql',import.meta.url),'utf8');
7
+
8
+test('phase4 schema contains learning wellbeing guide and proposal boundaries',()=>{
9
+ for(const table of ['learning_goal','learning_checkin','wellbeing_checkin','ai_guide_session','ai_guide_message','ai_plan_proposal']) assert.match(migration,new RegExp(`create table if not exists ${table}`));
10
+ assert.match(migration,/visibility in \('private','guardian_summary'\)/);
11
+ assert.match(migration,/status in \('proposed','accepted','rejected'\)/);
12
+});
13
+
14
+test('AI guide is advisory and has urgent safety path',()=>{
15
+ assert.match(src,/urgent_review/);
16
+ assert.match(src,/medicalDiagnosis:false/);
17
+ assert.match(src,/automaticAction:false/);
18
+ assert.match(src,/خدمات اضطراری محلی/);
19
+});
20
+
21
+test('wellbeing reads are owner scoped',()=>{
22
+ assert.match(src,/wellbeing_checkin where owner_user_id=\$1/);
23
+ assert.doesNotMatch(src,/guardian.*note/i);
24
+});