feat(next): add e2e session injection and chat spec infra#103
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. WalkthroughRegisters test routes only when ALLOW_TEST or an explicit allowTest option is enabled, removes two deprecated test endpoints from the OpenAPI spec, adds a test-set-session API to inject auth cookies for E2E, and provides an E2E helper to perform token-based session injection; minor E2E test adjustments and docs note added. Changes
Sequence DiagramsequenceDiagram
participant Test as E2E Test
participant NextAPI as Next API (proxy)
participant Handler as test-set-session Handler
participant Cookie as Cookie Setter
Test->>NextAPI: Request magic-link (POST /magic-link/request)
NextAPI-->>Test: Success
Test->>NextAPI: Query test magic token (GET /test/magic-link/last)
NextAPI-->>Test: Magic token
Test->>NextAPI: Verify token (POST /verify) -> receive token & refreshToken
NextAPI-->>Test: { token, refreshToken }
Test->>NextAPI: GET /api/auth/test-set-session?token=X&refreshToken=Y
NextAPI->>Handler: proxy to test-set-session
Handler->>Handler: check ALLOW_TEST enabled
Handler->>Handler: validate token & refreshToken
Handler->>Cookie: set auth cookies on response
Cookie-->>Handler: cookies attached
Handler-->>Test: 303 Redirect to /
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/next/e2e/auth-helpers.ts (1)
110-141: Consider extracting shared login preamble to reduce duplication.Lines 110–117 duplicate the logic from
loginAsTestUser(lines 95–103): send magic link → assert status → wait for success message → delay → extract token. Extracting a shared helper (e.g.,sendAndExtractMagicToken(page)) would keep both methods DRY.♻️ Sketch
+ /** Shared: send magic link and extract the token */ + async _sendAndExtractMagicToken(page: Page): Promise<string> { + const response = await this.sendMagicLink(page) + if (response.status() !== 200) throw new Error('Magic link request failed') + const successMessage = page.getByText(/check your email for the magic link/i) + await successMessage.waitFor({ state: 'visible', timeout: 10000 }) + await new Promise(r => setTimeout(r, 200)) + const token = await this.extractToken(page) + if (!token) throw new Error('Failed to extract magic link token') + return token + }, + async loginAsTestUser(page: Page) { - const response = await this.sendMagicLink(page) - if (response.status() !== 200) throw new Error('Magic link request failed') - const successMessage = page.getByText(/check your email for the magic link/i) - await successMessage.waitFor({ state: 'visible', timeout: 10000 }) - await new Promise(r => setTimeout(r, 200)) - const token = await this.extractToken(page) - if (!token) throw new Error('Failed to extract magic link token') + const token = await this._sendAndExtractMagicToken(page) await this.verifyMagicLink(page, token) }, async loginAsTestUserWithTokenInjection(page: Page) { - const response = await this.sendMagicLink(page) - if (response.status() !== 200) throw new Error('Magic link request failed') - const successMessage = page.getByText(/check your email for the magic link/i) - await successMessage.waitFor({ state: 'visible', timeout: 10000 }) - await new Promise(r => setTimeout(r, 200)) - const magicToken = await this.extractToken(page) - if (!magicToken) throw new Error('Failed to extract magic link token') + const magicToken = await this._sendAndExtractMagicToken(page) // ... rest of token injection🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/next/e2e/auth-helpers.ts` around lines 110 - 141, The loginAsTestUserWithTokenInjection function duplicates the preamble from loginAsTestUser (sendMagicLink → response check → successMessage wait → small delay → extractToken); refactor by extracting that sequence into a shared helper (e.g., sendAndExtractMagicToken(page)) that calls sendMagicLink, awaits the visible success message, performs the short delay, and returns the extracted magicToken using extractToken, then update both loginAsTestUserWithTokenInjection and loginAsTestUser to call sendAndExtractMagicToken(page) and use its returned token for the subsequent verify and injection logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/fastify/src/app.ts`:
- Line 39: The ignoreFilter currently evaluates !(opts?.allowTest ??
env.ALLOW_TEST) which treats the string 'false' as truthy; change the check to
compare the value to the string 'true' explicitly, e.g. use (opts?.allowTest ??
env.ALLOW_TEST) !== 'true' (or equivalent explicit comparison) when computing
ignoreFilter so that env.ALLOW_TEST='false' properly disables test routes;
update the expression referencing ignoreFilter, opts?.allowTest and
env.ALLOW_TEST accordingly and ensure parentheses are used to preserve
evaluation order.
---
Nitpick comments:
In `@apps/next/e2e/auth-helpers.ts`:
- Around line 110-141: The loginAsTestUserWithTokenInjection function duplicates
the preamble from loginAsTestUser (sendMagicLink → response check →
successMessage wait → small delay → extractToken); refactor by extracting that
sequence into a shared helper (e.g., sendAndExtractMagicToken(page)) that calls
sendMagicLink, awaits the visible success message, performs the short delay, and
returns the extracted magicToken using extractToken, then update both
loginAsTestUserWithTokenInjection and loginAsTestUser to call
sendAndExtractMagicToken(page) and use its returned token for the subsequent
verify and injection logic.
Summary by CodeRabbit
Documentation
Bug Fixes
Chores