fix: UX deep dive — 28 fixes across authoring, navigation, consistency, and cleanup #86
@@ -27,8 +27,20 @@ def _configure_seed_module(mod: object, api_url: str, email: str, password: str)
|
|||||||
mod.ADMIN_PASSWORD = password # type: ignore[attr-defined]
|
mod.ADMIN_PASSWORD = password # type: ignore[attr-defined]
|
||||||
|
|
||||||
|
|
||||||
|
async def _seed_users_directly() -> None:
|
||||||
|
"""Seed test users directly via DB if they don't exist yet."""
|
||||||
|
try:
|
||||||
|
from scripts.seed_test_users import main as seed_users
|
||||||
|
logger.info("[seed] Seeding test users directly via DB...")
|
||||||
|
await seed_users()
|
||||||
|
logger.info("[seed] Test users seeded!")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"[seed] User seeding failed: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
async def _seed_trees_background() -> None:
|
async def _seed_trees_background() -> None:
|
||||||
"""Background task: seed all flows via HTTP API after server is ready."""
|
"""Background task: seed test users + all flows after server is ready."""
|
||||||
await asyncio.sleep(5) # Wait for server to be fully ready
|
await asyncio.sleep(5) # Wait for server to be fully ready
|
||||||
port = os.environ.get("PORT", "8000")
|
port = os.environ.get("PORT", "8000")
|
||||||
api_url = f"http://127.0.0.1:{port}/api/v1"
|
api_url = f"http://127.0.0.1:{port}/api/v1"
|
||||||
@@ -37,12 +49,17 @@ async def _seed_trees_background() -> None:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import httpx
|
import httpx
|
||||||
# Login to verify admin user exists
|
# Try to login — if it fails, seed users first
|
||||||
async with httpx.AsyncClient(base_url=api_url, timeout=30) as client:
|
async with httpx.AsyncClient(base_url=api_url, timeout=30) as client:
|
||||||
login_resp = await client.post("/auth/login/json", json={"email": email, "password": password})
|
login_resp = await client.post("/auth/login/json", json={"email": email, "password": password})
|
||||||
if login_resp.status_code != 200:
|
if login_resp.status_code != 200:
|
||||||
logger.warning("[seed] Could not login as admin — skipping flow seeding")
|
logger.warning("[seed] Admin login failed — seeding users first")
|
||||||
return
|
await _seed_users_directly()
|
||||||
|
# Retry login after seeding users
|
||||||
|
login_resp = await client.post("/auth/login/json", json={"email": email, "password": password})
|
||||||
|
if login_resp.status_code != 200:
|
||||||
|
logger.error(f"[seed] Admin login still failing after user seed (status={login_resp.status_code}) — aborting")
|
||||||
|
return
|
||||||
|
|
||||||
token = login_resp.json()["access_token"]
|
token = login_resp.json()["access_token"]
|
||||||
# Check if trees already exist
|
# Check if trees already exist
|
||||||
|
|||||||
Reference in New Issue
Block a user