#!/usr/bin/env python3 """ Read-only end-to-end check of the login fix. Runs the real Playwright login, then exercises the Graph API with the captured token: plan discovery plus a Not-Started task listing for the first facility. Downloads nothing and never PATCHes a task, so it is safe to run against production Planner. Run: .venv\\Scripts\\python scripts\\verify_login.py [--headed] """ from __future__ import annotations import argparse import logging import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent SRC = ROOT / "src" for p in (str(ROOT), str(SRC)): if p not in sys.path: sys.path.insert(0, p) from config import read_app_config, read_facility_list # noqa: E402 from onedrive_planner_http import ( # noqa: E402 _build_client, _discover_all_plans, _login_with_retry, _match_plan, _not_started_tasks, ) def main() -> int: ap = argparse.ArgumentParser() ap.add_argument("--headed", action="store_true", help="show the browser window") args = ap.parse_args() logging.basicConfig( level=logging.DEBUG, format="%(asctime)s %(levelname)-8s %(name)s — %(message)s", stream=sys.stdout, ) cfg = read_app_config() facilities = read_facility_list() print("\n--- login ---") token, cookies = _login_with_retry(cfg, headless=not args.headed) print(f"token length : {len(token)}") print(f"cookies : {len(cookies)}") client = _build_client(cfg, token) print("\n--- plan discovery ---") plans = _discover_all_plans(client, cfg) print(f"plans visible: {len(plans)}") for p in plans[:5]: print(f" {p.get('title')!r} (group {p.get('_group_name')!r})") facility = facilities[0] print(f"\n--- read-only task listing for {facility!r} ---") plan = _match_plan(plans, facility) if not plan: print(" no matching plan found for this facility") return 1 tasks = _not_started_tasks(client, plan["id"], cfg) print(f" plan {plan.get('title')!r}: {len(tasks)} Not-Started task(s)") for t in tasks[:5]: print(f" - {t.get('title')!r}") print("\nOK — login, token capture and Graph API access all work.") return 0 if __name__ == "__main__": raise SystemExit(main())