LifeMate — Personal, Family & Learning Companion
fix/study-duration-display
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 | """Developer-only real HTTPS PWA load test; requires Playwright + Chromium. |
| 2 | |
| 3 | The public CA must already be trusted normally by the browser. This program |
| 4 | never ignores TLS errors, intercepts network responses, or logs credentials. |
| 5 | Real Safari/Android and Iran reachability are separate acceptance gates. |
| 6 | """ |
| 7 | import argparse |
| 8 | import json |
| 9 | import re |
| 10 | import time |
| 11 | from pathlib import Path |
| 12 | from urllib.parse import urlparse |
| 13 | from playwright.sync_api import sync_playwright |
| 14 | |
| 15 | parser = argparse.ArgumentParser() |
| 16 | parser.add_argument("origin") |
| 17 | parser.add_argument("--chromium", default="/usr/bin/chromium") |
| 18 | parser.add_argument("--profile", required=True) |
| 19 | parser.add_argument("--screenshot", required=True) |
| 20 | parser.add_argument("--viewport-width", type=int, default=390) |
| 21 | parser.add_argument("--synthetic-login-email", choices=["stage0-mother@lifeguide.test", "stage0-father@lifeguide.test"]) |
| 22 | parser.add_argument("--synthetic-password-file") |
| 23 | parser.add_argument("--expected-task-title") |
| 24 | parser.add_argument("--expected-recorded-seconds", type=int) |
| 25 | parser.add_argument("--expected-planned-seconds", type=int) |
| 26 | parser.add_argument("--expected-status") |
| 27 | parser.add_argument("--resume-parent-session", action="store_true") |
| 28 | args = parser.parse_args() |
| 29 | |
| 30 | def duration_label(total_seconds): |
| 31 | minutes, seconds = divmod(total_seconds, 60) |
| 32 | if not seconds: |
| 33 | return f"{minutes} دقیقه" |
| 34 | if not minutes: |
| 35 | return f"{seconds} ثانیه" |
| 36 | return f"{minutes} دقیقه و {seconds} ثانیه" |
| 37 | |
| 38 | def duration_is_shown(rendered, prefix, total_seconds): |
| 39 | # A whole-minute expectation must not accept an extra second component. |
| 40 | expected = re.escape(f"{prefix} {duration_label(total_seconds)}") |
| 41 | return re.search(expected + r"(?!\s+و\b)", rendered) is not None |
| 42 | |
| 43 | origin = args.origin.rstrip("/") |
| 44 | parsed = urlparse(origin) |
| 45 | if parsed.scheme != "https" or parsed.username or parsed.password or parsed.path or parsed.query or parsed.fragment: |
| 46 | raise SystemExit("Use one HTTPS origin without credentials/path/query/fragment") |
| 47 | requests, failures, errors, http_errors, auth_responses = [], [], [], [], [] |
| 48 | login_verified, report_verified, report_body_verified, reported_task = False, False, False, None |
| 49 | if bool(args.synthetic_login_email) != bool(args.synthetic_password_file): |
| 50 | raise SystemExit("Synthetic login requires both the known fixture email and private local password file") |
| 51 | if args.resume_parent_session and not args.synthetic_login_email: |
| 52 | raise SystemExit("Resume requires a previously authenticated synthetic parent profile") |
| 53 | with sync_playwright() as playwright: |
| 54 | context = playwright.chromium.launch_persistent_context( |
| 55 | user_data_dir=args.profile, executable_path=args.chromium, headless=True, |
| 56 | viewport={"width": args.viewport_width, "height": 960}, ignore_https_errors=False, |
| 57 | service_workers="allow", timezone_id="Asia/Tehran", |
| 58 | ) |
| 59 | try: |
| 60 | page = context.pages[0] if context.pages else context.new_page() |
| 61 | def requested(request): |
| 62 | url = urlparse(request.url) |
| 63 | requests.append({"origin": f"{url.scheme}://{url.netloc}", "path": url.path}) |
| 64 | page.on("request", requested) |
| 65 | page.on("requestfailed", lambda request: failures.append({"path": urlparse(request.url).path, "failure": request.failure})) |
| 66 | page.on("pageerror", lambda error: errors.append(str(error))) |
| 67 | def responded(response): |
| 68 | path = urlparse(response.url).path |
| 69 | if response.status >= 400: |
| 70 | http_errors.append({"path": path, "status": response.status}) |
| 71 | if path in ("/api/v1/auth/login", "/api/v1/auth/refresh"): |
| 72 | auth_responses.append({"path": path, "status": response.status}) |
| 73 | page.on("response", responded) |
| 74 | initial_url = page.url |
| 75 | if initial_url.rstrip("/") == origin: |
| 76 | # Persistent Chromium may already be restoring the prior page. |
| 77 | # Never start a second navigation while it rotates refresh tokens. |
| 78 | response = None |
| 79 | page.wait_for_load_state("networkidle", timeout=90000) |
| 80 | else: |
| 81 | response = page.goto(origin, wait_until="networkidle", timeout=90000) |
| 82 | assert response and response.status == 200, "PWA navigation failed" |
| 83 | page.wait_for_selector("flt-glass-pane", state="attached", timeout=90000) |
| 84 | page.wait_for_function("() => !document.getElementById('startup-status')", timeout=90000) |
| 85 | placeholder = page.locator("flt-semantics-placeholder") |
| 86 | if placeholder.count(): |
| 87 | placeholder.evaluate("element => element.click()") |
| 88 | page.wait_for_load_state("networkidle") |
| 89 | if args.synthetic_login_email: |
| 90 | if args.resume_parent_session: |
| 91 | pass |
| 92 | else: |
| 93 | password = Path(args.synthetic_password_file).read_text().strip() |
| 94 | assert len(password) >= 10, "Synthetic password too short" |
| 95 | page.get_by_label("ایمیل یا شماره تلفن", exact=True).fill(args.synthetic_login_email) |
| 96 | page.get_by_label("رمز عبور", exact=True).fill(password) |
| 97 | password = None |
| 98 | with page.expect_response(lambda response: urlparse(response.url).path == "/api/v1/auth/login" and response.request.method == "POST") as logged_in: |
| 99 | page.get_by_role("button", name="ورود", exact=True).click() |
| 100 | assert logged_in.value.status == 200, f"Synthetic parent login HTTP {logged_in.value.status}" |
| 101 | page.get_by_role("tab", name="خانواده", exact=True).wait_for(timeout=30000) |
| 102 | page.wait_for_load_state("networkidle") |
| 103 | if args.resume_parent_session: |
| 104 | assert {"path": "/api/v1/auth/refresh", "status": 200} in auth_responses, "Saved parent session did not refresh after browser restart" |
| 105 | # Flutter's RTL semantic tab has a transformed DOM rectangle. Use |
| 106 | # the actual visible centre tab of the five-destination navbar. |
| 107 | page.mouse.click(args.viewport_width / 2, 920) |
| 108 | child = page.get_by_role("button", name=re.compile("فرزند آزمایشی")) |
| 109 | child.wait_for(timeout=30000) |
| 110 | with page.expect_response(lambda response: urlparse(response.url).path.endswith("/learning-report")) as loaded_report: |
| 111 | child.evaluate("element => element.click()") |
| 112 | assert loaded_report.value.status == 200, "Permitted child report API failed" |
| 113 | # Chromium's restored tab can expose a response without retaining |
| 114 | # its CDP response body. Fresh-login runs independently validate |
| 115 | # server JSON; restart runs validate refresh, new report HTTP 200 |
| 116 | # and the actual rendered values, without inventing a JSON check. |
| 117 | server_report = None if args.resume_parent_session else loaded_report.value.json() |
| 118 | report_body_verified = server_report is not None |
| 119 | if server_report is not None and args.expected_planned_seconds is not None: |
| 120 | assert server_report["metrics"]["plannedInRangeDurationSeconds"] == args.expected_planned_seconds, "Planned time for the selected report range differs" |
| 121 | page.get_by_role("heading", name=re.compile("گزارش یادگیری")).wait_for(timeout=30000) |
| 122 | if server_report is not None and args.expected_task_title: |
| 123 | reported_task = next((item for item in server_report["items"] if item["title"] == args.expected_task_title), None) |
| 124 | assert reported_task, "Expected synthetic homework missing from server report" |
| 125 | if args.expected_recorded_seconds is not None: |
| 126 | assert reported_task["recordedDurationSeconds"] == args.expected_recorded_seconds, "Reported task duration differs" |
| 127 | if args.expected_status: |
| 128 | assert reported_task["status"] == args.expected_status, "Reported task status differs" |
| 129 | assert "SYNTHETIC-OWNER-PRIVATE-NOTE" not in json.dumps(server_report), "Private owner note leaked to parent" |
| 130 | deadline = time.monotonic() + 30 |
| 131 | while True: |
| 132 | rendered = page.locator("body").aria_snapshot() |
| 133 | if "زمان ثبتشده" in rendered and (not args.expected_task_title or args.expected_task_title in rendered): |
| 134 | break |
| 135 | assert time.monotonic() < deadline, "Expected allowed report was not rendered in PWA" |
| 136 | page.wait_for_timeout(100) |
| 137 | if args.expected_recorded_seconds is not None: |
| 138 | assert duration_is_shown(rendered, "ثبت", args.expected_recorded_seconds), "Exact recorded task duration not shown in PWA" |
| 139 | if args.expected_status == "completed": |
| 140 | assert "انجامشده به گزارش فرزند" in rendered, "Recorded completion status not shown in PWA" |
| 141 | if args.expected_planned_seconds is not None: |
| 142 | assert duration_is_shown(rendered, "زمان برنامهریزیشده:", args.expected_planned_seconds), "Exact planned duration for report range not shown in PWA" |
| 143 | assert "SYNTHETIC-OWNER-PRIVATE-NOTE" not in rendered, "Private owner note rendered for parent" |
| 144 | login_verified, report_verified = True, True |
| 145 | external = [request for request in requests if request["origin"] != origin] |
| 146 | assert not external, f"Unexpected external request: {external}" |
| 147 | assert not failures, f"Network failure: {failures}" |
| 148 | assert not errors, f"Browser error: {errors}" |
| 149 | assert not http_errors, f"HTTP failure: {http_errors}" |
| 150 | assert any("/canvaskit/" in request["path"] and request["path"].endswith(".wasm") for request in requests), "Local CanvasKit WASM missing" |
| 151 | assert "LifeGuide" in page.title() and "لایفگاید" in page.title(), "Product title differs" |
| 152 | page.screenshot(path=args.screenshot, full_page=False) |
| 153 | print(json.dumps({"mode": "actual local HTTPS gateway, normal browser trust, real API", "browser": context.browser.version if context.browser else "Chromium", "http": response.status if response else "Chromium restored navigation; initial HTTP status UNVERIFIED", |
| 154 | "requestCount": len(requests), "externalRequests": external, |
| 155 | "failedRequests": failures, "browserErrors": errors, |
| 156 | "httpErrors": http_errors, |
| 157 | "syntheticParentLogin": login_verified and not args.resume_parent_session, |
| 158 | "syntheticParentAuthenticated": login_verified, |
| 159 | "permittedChildReportRendered": report_verified, |
| 160 | "serverReportBodyVerified": report_body_verified, |
| 161 | "reportBodyLimit": "Restored-tab JSON body UNVERIFIED; fresh-login runs independently validate JSON" if args.resume_parent_session else None, |
| 162 | "resumedPersistedParentSession": args.resume_parent_session, |
| 163 | "authResponses": auth_responses, |
| 164 | "reportedTask": None if reported_task is None else {key: reported_task.get(key) for key in ["title", "status", "recordedDurationSeconds", "plannedDurationSeconds", "activityState"]}, |
| 165 | "fonts": [request["path"] for request in requests if request["path"].endswith((".ttf", ".otf", ".woff2"))], |
| 166 | "inputLabels": page.locator("input").evaluate_all("els => els.map(e => ({type:e.type,label:e.getAttribute('aria-label')}))"), |
| 167 | "serviceWorkers": len(context.service_workers), |
| 168 | "limitations": "Safari install, Android, three physical devices and Iran reachability UNVERIFIED"}, ensure_ascii=False, indent=2)) |
| 169 | finally: |
| 170 | # Park the saved profile on a blank page before closing. Chromium may |
| 171 | # otherwise auto-restore the prior URL before a subsequent explicit |
| 172 | # navigation, accidentally racing two refresh rotations in this test. |
| 173 | for open_page in context.pages: |
| 174 | open_page.goto("about:blank") |
| 175 | context.close() |