Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(e2e): let the approved-tools journey reach the isolated consent page

Alfredo Lopez6bf28d009c83
diff --git a/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts b/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts
index 2c866a2d1..75ef2fdb0 100644
--- a/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts
+++ b/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts
@@ -164,6 +164,12 @@ test('authenticated user without agent access cannot select the protected agents
.getByLabel('Password', { exact: true })
.fill(required('APPROVED_TOOLS_UNAUTHORIZED_PASSWORD'))
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
+ // Agents, Connectors and Plugins are menu items of the Settings submenu and
+ // are not rendered while it is collapsed (SidebarNav renders them under
+ // `settingsMenuOpen`), so the journey opens it the way a user does.
+ await expect(page.getByTestId('nav-settings-menu')).toHaveAttribute('aria-expanded', 'false')
+ await page.getByTestId('nav-settings-menu').click()
+ await expect(page.getByTestId('nav-settings-menu')).toHaveAttribute('aria-expanded', 'true')
await expect(page.getByTestId('nav-agents')).toBeVisible()
await page.getByTestId('nav-agents').click()
await expect(page.getByRole('heading', { name: 'Agents', exact: true })).toBeVisible()
@@ -181,6 +187,15 @@ test('authenticated user without agent access cannot select the protected agents
await expect(page.getByTestId('chat-input')).toHaveCount(0)
await expect(page.getByTestId('send-button')).toHaveCount(0)
expect(await Promise.all(cases.map(readEvidence))).toEqual(before)
+ // Sign out before the window closes. The session token lives in the macOS
+ // Keychain, keyed by the REST+RPC origin, which a fresh --user-data-dir does
+ // not isolate: leaving it behind signs the next launch in as this
+ // unauthorized user, and the next test's login form never renders. Signing
+ // out is part of this journey, so a failure here fails this test rather
+ // than the one that inherits the session.
+ await page.getByTestId('nav-settings-menu').click()
+ await page.getByTestId('logout-btn').click()
+ await expect(page.getByLabel('Email', { exact: true })).toBeVisible()
journeyPassed = true
} finally {
try {
diff --git a/tests/e2e/playwright/helpers/approved-tools-subscription.ts b/tests/e2e/playwright/helpers/approved-tools-subscription.ts
index 4996b047e..9369e127e 100644
--- a/tests/e2e/playwright/helpers/approved-tools-subscription.ts
+++ b/tests/e2e/playwright/helpers/approved-tools-subscription.ts
@@ -10,6 +10,10 @@ import { ControlUiShell, SecretsLlmSubscriptionsPage } from '../pages/codex-subs
import { type Scenario, required } from './approved-tools-scenarios'
const verificationUrl = 'https://auth.openai.com/codex/device'
+const devicePath = (connectionKey: string, step: 'start' | 'poll') =>
+ `/api/v1/admin/llm/providers/codex-subscription/connections/${connectionKey}/device/${step}`
+const anyDevicePath = (step: 'start' | 'poll') =>
+ new RegExp(`^/api/v1/admin/llm/providers/codex-subscription/connections/[^/]+/device/${step}$`)
export async function prepareSubscriptionVisible(page: Page, scenario: Scenario): Promise<string> {
if (required('APPROVED_TOOLS_UPSTREAM_MODE') === 'real') {
@@ -28,15 +32,6 @@ export async function prepareSubscriptionVisible(page: Page, scenario: Scenario)
scenario: scenarioLabel,
fixtureUserId: required('APPROVED_TOOLS_FIXTURE_USER_ID'),
})
- let connectionKey: string
- try {
- connectionKey = await subscriptions.createGrant(scenario.subscriptionName, metadata =>
- capture.record(metadata)
- )
- } finally {
- capture.close()
- }
- expect(connectionKey).not.toBe('unassigned')
const context = page.context()
const externalConsent = async (route: Route) => {
expect(route.request().url()).toBe(verificationUrl)
@@ -47,21 +42,28 @@ export async function prepareSubscriptionVisible(page: Page, scenario: Scenario)
})
}
// Exact external URL only; no Control UI/API route or browser session is mocked.
+ //
+ // Every listener below is registered BEFORE the Create click, because
+ // "Create and set up" is the whole user gesture: handleCreate chains straight
+ // into handleConnect, which opens the verification tab itself. A route or a
+ // waitForEvent('page') registered after that click arrives too late for the
+ // tab it already opened, and that tab then reaches the real auth.openai.com.
await context.route(verificationUrl, externalConsent)
let popup: Page | undefined
try {
const popupOpened = context.waitForEvent('page')
+ // The grant does not exist yet, so neither device path can name its
+ // connection key here. Both responses are matched on shape now and checked
+ // against the created key below, which keeps the assertion just as strict.
const started = page.waitForResponse(
response =>
- new URL(response.url()).pathname ===
- `/api/v1/admin/llm/providers/codex-subscription/connections/${connectionKey}/device/start` &&
+ anyDevicePath('start').test(new URL(response.url()).pathname) &&
response.request().method() === 'POST'
)
const connected = page.waitForResponse(
async response => {
if (
- new URL(response.url()).pathname !==
- `/api/v1/admin/llm/providers/codex-subscription/connections/${connectionKey}/device/poll` ||
+ !anyDevicePath('poll').test(new URL(response.url()).pathname) ||
response.request().method() !== 'GET' ||
!response.ok()
)
@@ -70,17 +72,26 @@ export async function prepareSubscriptionVisible(page: Page, scenario: Scenario)
},
{ timeout: 120_000 }
)
- await page
- .getByRole('dialog')
- .getByRole('button', { name: 'Sign in with ChatGPT', exact: true })
- .click()
+ let connectionKey: string
+ try {
+ connectionKey = await subscriptions.createGrant(scenario.subscriptionName, metadata =>
+ capture.record(metadata)
+ )
+ } finally {
+ capture.close()
+ }
+ expect(connectionKey).not.toBe('unassigned')
popup = await popupOpened
await expect(popup).toHaveURL(verificationUrl)
await expect(
popup.getByRole('heading', { name: 'Isolated OAuth consent', exact: true })
).toBeVisible()
- expect((await started).ok()).toBe(true)
- const result = await (await connected).json()
+ const startResponse = await started
+ expect(startResponse.ok()).toBe(true)
+ expect(new URL(startResponse.url()).pathname).toBe(devicePath(connectionKey, 'start'))
+ const connectedResponse = await connected
+ expect(new URL(connectedResponse.url()).pathname).toBe(devicePath(connectionKey, 'poll'))
+ const result = await connectedResponse.json()
expect(result.connection).toMatchObject({ connectionKey, catalogStatus: 'ready' })
await expect(page.getByTestId('codex-device-code')).toHaveCount(0)
await expect(page.getByLabel(scenario.modelName, { exact: true })).toBeVisible()
diff --git a/tests/e2e/playwright/package-lock.json b/tests/e2e/playwright/package-lock.json
index abbb808cf..3f82ffd68 100644
--- a/tests/e2e/playwright/package-lock.json
+++ b/tests/e2e/playwright/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-playwright-tests",
- "version": "0.1.53",
+ "version": "0.1.54",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-playwright-tests",
- "version": "0.1.53",
+ "version": "0.1.54",
"devDependencies": {
"@playwright/test": "^1.50.0",
"@types/node": "^22.0.0",
diff --git a/tests/e2e/playwright/package.json b/tests/e2e/playwright/package.json
index 6a051ab91..f83674c1e 100644
--- a/tests/e2e/playwright/package.json
+++ b/tests/e2e/playwright/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-playwright-tests",
- "version": "0.1.53",
+ "version": "0.1.54",
"private": true,
"description": "Playwright E2E tests for Control UI and Desktop App",
"scripts": {