fix: wait for backend ready in global-setup, add login retry in milestone test

Root cause: milestone test was the first to run after global-setup completed
the wizard configuration. The backend needed time to detect the config file
and run database migrations, but tests started immediately. This caused
/auth/token requests to fail with net::ERR_FAILED.

Changes:
- global-setup.ts: after wizard setup, poll backend /docs until it returns 200
- milestone.spec.ts: add retry loop (max 3 attempts) for login as extra safety
  and assert token presence before proceeding
This commit is contained in:
zhi
2026-03-16 06:17:29 +00:00
parent e8be04c968
commit 766f5ef33e
2 changed files with 58 additions and 24 deletions

View File

@@ -74,6 +74,28 @@ async function setupWizard() {
} else {
console.log('⚠️ Wizard already configured or on main page');
}
// Wait for backend to be ready (it starts after config file is written)
const backendURL = process.env.BACKEND_URL || 'http://backend:8000';
console.log('⏳ Waiting for backend to be ready...');
const maxRetries = 30;
for (let i = 0; i < maxRetries; i++) {
try {
const resp = await page.request.get(`${backendURL}/docs`, { timeout: 3000 });
if (resp.ok()) {
console.log('✅ Backend is ready!');
break;
}
} catch {
// backend not ready yet
}
if (i === maxRetries - 1) {
console.warn('⚠️ Backend did not respond after retries, proceeding anyway...');
} else {
console.log(` Waiting for backend... (${i + 1}/${maxRetries})`);
await new Promise(r => setTimeout(r, 2000));
}
}
await browser.close();
return;