LifeMate — Personal, Family & Learning Companion
test/android-reminder-acceptance
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
| 1 | import test, { after } from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | // Explicit synthetic opt-in; NODE_ENV=test never enables sensitive APIs itself. |
| 4 | process.env.ENABLE_SENSITIVE_FEATURES = 'true'; |
| 5 | const { app, pool } = await import('../src/server.js'); |
| 6 | |
| 7 | const server = app.listen(0); |
| 8 | const address = server.address(); |
| 9 | const base = `http://127.0.0.1:${address.port}`; |
| 10 | |
| 11 | after(async () => { |
| 12 | await new Promise((resolve) => server.close(resolve)); |
| 13 | await pool.end(); |
| 14 | }); |
| 15 | |
| 16 | async function request(path, { method = 'GET', body, token } = {}) { |
| 17 | const response = await fetch(base + path, { |
| 18 | method, |
| 19 | headers: { |
| 20 | 'content-type': 'application/json', |
| 21 | ...(token ? { authorization: `Bearer ${token}` } : {}), |
| 22 | }, |
| 23 | body: body === undefined ? undefined : JSON.stringify(body), |
| 24 | }); |
| 25 | const text = await response.text(); |
| 26 | return { |
| 27 | status: response.status, |
| 28 | body: text ? JSON.parse(text) : null, |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | async function registerVerified(email, displayName) { |
| 33 | const password = 'Phase4Pass!123'; |
| 34 | const registration = await request('/v1/auth/register', { |
| 35 | method: 'POST', |
| 36 | body: { email, displayName, password }, |
| 37 | }); |
| 38 | assert.equal(registration.status, 201); |
| 39 | assert.equal( |
| 40 | ( |
| 41 | await request('/v1/auth/verify-email', { |
| 42 | method: 'POST', |
| 43 | body: { token: registration.body.verificationToken, newPassword: password }, |
| 44 | }) |
| 45 | ).status, |
| 46 | 204, |
| 47 | ); |
| 48 | const login = await request('/v1/auth/login', { |
| 49 | method: 'POST', |
| 50 | body: { email, password }, |
| 51 | }); |
| 52 | assert.equal(login.status, 200); |
| 53 | return { token: login.body.accessToken, userId: registration.body.userId }; |
| 54 | } |
| 55 | |
| 56 | test('phase 4 learning wellbeing and guardian safety boundaries', async () => { |
| 57 | const suffix = Date.now().toString(36); |
| 58 | const parentEmail = `p4-parent-${suffix}@example.test`; |
| 59 | const teenEmail = `p4-teen-${suffix}@example.test`; |
| 60 | const outsiderEmail = `p4-outsider-${suffix}@example.test`; |
| 61 | |
| 62 | const parent = await registerVerified(parentEmail, 'Phase4 Parent'); |
| 63 | const teen = await registerVerified(teenEmail, 'Phase4 Teen'); |
| 64 | const outsider = await registerVerified(outsiderEmail, 'Phase4 Outsider'); |
| 65 | |
| 66 | const family = await request('/v1/families', { |
| 67 | method: 'POST', |
| 68 | token: parent.token, |
| 69 | body: { name: 'Phase4 Family', role: 'parent_guardian' }, |
| 70 | }); |
| 71 | assert.equal(family.status, 201); |
| 72 | |
| 73 | const invitation = await request(`/v1/families/${family.body.id}/invitations`, { |
| 74 | method: 'POST', |
| 75 | token: parent.token, |
| 76 | body: { |
| 77 | email: teenEmail, |
| 78 | role: 'teen_minor', |
| 79 | themePreference: 'girl_pink', |
| 80 | }, |
| 81 | }); |
| 82 | assert.equal(invitation.status, 201); |
| 83 | |
| 84 | assert.equal( |
| 85 | ( |
| 86 | await request('/v1/invitations/accept', { |
| 87 | method: 'POST', |
| 88 | token: teen.token, |
| 89 | body: { token: invitation.body.invitationToken }, |
| 90 | }) |
| 91 | ).status, |
| 92 | 204, |
| 93 | ); |
| 94 | |
| 95 | assert.equal( |
| 96 | ( |
| 97 | await request(`/v1/families/${family.body.id}/guardians`, { |
| 98 | method: 'POST', |
| 99 | token: parent.token, |
| 100 | body: { |
| 101 | guardianUserId: parent.userId, |
| 102 | minorUserId: teen.userId, |
| 103 | }, |
| 104 | }) |
| 105 | ).status, |
| 106 | 204, |
| 107 | ); |
| 108 | |
| 109 | const goal = await request('/v1/learning/goals', { |
| 110 | method: 'POST', |
| 111 | token: teen.token, |
| 112 | body: { title: 'تسلط روی جبر', target: 'حل تمرینهای فصل اول' }, |
| 113 | }); |
| 114 | assert.equal(goal.status, 201); |
| 115 | |
| 116 | const learningCheckin = await request('/v1/learning/checkins', { |
| 117 | method: 'POST', |
| 118 | token: teen.token, |
| 119 | body: { |
| 120 | learningGoalId: goal.body.id, |
| 121 | confidence: 3, |
| 122 | difficulty: 4, |
| 123 | note: 'تمرین بیشتری لازم دارم', |
| 124 | }, |
| 125 | }); |
| 126 | assert.equal(learningCheckin.status, 201); |
| 127 | |
| 128 | const privateCheckin = await request('/v1/wellbeing/checkins', { |
| 129 | method: 'POST', |
| 130 | token: teen.token, |
| 131 | body: { |
| 132 | mood: 3, |
| 133 | energy: 2, |
| 134 | stress: 4, |
| 135 | note: 'این متن خصوصی است', |
| 136 | visibility: 'private', |
| 137 | }, |
| 138 | }); |
| 139 | assert.equal(privateCheckin.status, 201); |
| 140 | assert.equal(Object.hasOwn(privateCheckin.body, 'note'), false); |
| 141 | |
| 142 | const sharedCheckin = await request('/v1/wellbeing/checkins', { |
| 143 | method: 'POST', |
| 144 | token: teen.token, |
| 145 | body: { |
| 146 | mood: 4, |
| 147 | energy: 3, |
| 148 | stress: 2, |
| 149 | note: 'این متن هم نباید به والد برگردد', |
| 150 | visibility: 'guardian_summary', |
| 151 | }, |
| 152 | }); |
| 153 | assert.equal(sharedCheckin.status, 201); |
| 154 | assert.equal(Object.hasOwn(sharedCheckin.body, 'note'), false); |
| 155 | |
| 156 | const ownCheckins = await request('/v1/wellbeing/checkins', { |
| 157 | token: teen.token, |
| 158 | }); |
| 159 | assert.equal(ownCheckins.status, 200); |
| 160 | assert.equal(ownCheckins.body.items.length >= 2, true); |
| 161 | assert.equal( |
| 162 | ownCheckins.body.items.some((item) => Object.hasOwn(item, 'note')), |
| 163 | false, |
| 164 | ); |
| 165 | |
| 166 | const guardianSummary = await request( |
| 167 | `/v1/families/${family.body.id}/children/${teen.userId}/wellbeing-summary`, |
| 168 | { token: parent.token }, |
| 169 | ); |
| 170 | assert.equal(guardianSummary.status, 200); |
| 171 | assert.equal(guardianSummary.body.summary.checkin_count, 1); |
| 172 | assert.equal(guardianSummary.body.rawNotesIncluded, false); |
| 173 | assert.equal(guardianSummary.body.rawConversationIncluded, false); |
| 174 | |
| 175 | const outsiderSummary = await request( |
| 176 | `/v1/families/${family.body.id}/children/${teen.userId}/wellbeing-summary`, |
| 177 | { token: outsider.token }, |
| 178 | ); |
| 179 | assert.equal(outsiderSummary.status, 403); |
| 180 | |
| 181 | const familyGuidance = await request( |
| 182 | `/v1/families/${family.body.id}/children/${teen.userId}/family-guidance`, |
| 183 | { |
| 184 | method: 'POST', |
| 185 | token: parent.token, |
| 186 | body: { question: 'چطور بدون فشار حمایتش کنم؟' }, |
| 187 | }, |
| 188 | ); |
| 189 | assert.equal(familyGuidance.status, 200); |
| 190 | assert.equal(familyGuidance.body.advisory, true); |
| 191 | assert.equal(familyGuidance.body.medicalDiagnosis, false); |
| 192 | assert.equal(familyGuidance.body.rawNotesIncluded, false); |
| 193 | assert.equal(familyGuidance.body.rawConversationIncluded, false); |
| 194 | |
| 195 | const outsiderGuidance = await request( |
| 196 | `/v1/families/${family.body.id}/children/${teen.userId}/family-guidance`, |
| 197 | { |
| 198 | method: 'POST', |
| 199 | token: outsider.token, |
| 200 | body: { question: 'وضعیت چیست؟' }, |
| 201 | }, |
| 202 | ); |
| 203 | assert.equal(outsiderGuidance.status, 403); |
| 204 | |
| 205 | const session = await request('/v1/ai/sessions', { |
| 206 | method: 'POST', |
| 207 | token: teen.token, |
| 208 | body: { kind: 'wellbeing' }, |
| 209 | }); |
| 210 | assert.equal(session.status, 201); |
| 211 | |
| 212 | const ordinary = await request(`/v1/ai/sessions/${session.body.id}/messages`, { |
| 213 | method: 'POST', |
| 214 | token: teen.token, |
| 215 | body: { message: 'امروز کمی استرس دارم' }, |
| 216 | }); |
| 217 | assert.equal(ordinary.status, 200); |
| 218 | assert.equal(ordinary.body.advisory, true); |
| 219 | assert.equal(ordinary.body.medicalDiagnosis, false); |
| 220 | assert.equal(ordinary.body.automaticAction, false); |
| 221 | |
| 222 | const urgent = await request(`/v1/ai/sessions/${session.body.id}/messages`, { |
| 223 | method: 'POST', |
| 224 | token: teen.token, |
| 225 | body: { message: 'به خودکشی فکر میکنم' }, |
| 226 | }); |
| 227 | assert.equal(urgent.status, 200); |
| 228 | assert.equal(urgent.body.safety_class, 'urgent_review'); |
| 229 | |
| 230 | const safetySummary = await request( |
| 231 | `/v1/families/${family.body.id}/children/${teen.userId}/wellbeing-summary`, |
| 232 | { token: parent.token }, |
| 233 | ); |
| 234 | assert.equal(safetySummary.status, 200); |
| 235 | assert.equal(safetySummary.body.safety.open_urgent_count >= 1, true); |
| 236 | }); |