Fix CI auth: set cookie via /api/v1/health, not /login
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-frontend (pull_request) Successful in 5s
CI/CD / e2e-smoke (pull_request) Failing after 1m18s
CI/CD / test-runners (pull_request) Failing after 1m18s
CI/CD / test-go-pg (pull_request) Failing after 2m39s
CI/CD / build-and-deploy (pull_request) Has been cancelled
CI/CD / test-sqlite (pull_request) Has been cancelled

Navigating to /login triggers SDK boot which loads stale localStorage
tokens, attempts /auth/refresh (fails with 401), and clears all auth
state including the cookie we just set.

Fix: navigate to /api/v1/health (JSON endpoint, no SPA boot), set
arm_token cookie via document.cookie, then navigate to real surfaces.
The Go page-auth middleware reads the cookie on subsequent requests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-02 16:24:15 +00:00
parent b1a8568bff
commit 89f57fca22
2 changed files with 16 additions and 23 deletions

View File

@@ -100,20 +100,18 @@ async function discoverSurfaces(page) {
const page = await context.newPage();
// ── Authenticate via page context ─────────
// Navigate to login first, then inject tokens into localStorage
// and set the arm_token cookie via JS — same mechanism the login
// page uses. Playwright's addCookies doesn't reliably work with
// SameSite=Strict cookies in Docker DNS environments.
// Navigate to health endpoint (no SPA boot, no SDK interference),
// set the arm_token cookie via document.cookie, then navigate to
// real surfaces. The Go page-auth middleware reads this cookie.
//
// We cannot use /login because the SDK boots, sees stale tokens in
// localStorage, tries /auth/refresh, fails, and clears the cookie.
// We cannot use Playwright's addCookies because SameSite=Strict
// cookies set externally aren't sent in Docker DNS environments.
console.log('Setting up auth...');
await page.goto(SERVER + '/login', { waitUntil: 'networkidle', timeout: 30000 });
await page.goto(SERVER + '/api/v1/health', { waitUntil: 'networkidle', timeout: 30000 });
await page.evaluate((token) => {
localStorage.setItem('arm_auth', JSON.stringify({
accessToken: token,
refreshToken: token,
user: null,
cookieMaxAge: 604800,
}));
document.cookie = `arm_token=${token}; path=/; max-age=604800; SameSite=Strict`;
document.cookie = `arm_token=${token}; path=/; max-age=604800`;
}, TOKEN);
// ── Discover surfaces ─────────────────────