The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(e2e-ui): assert user-observable behavior instead of DOM structure in audit fixes
Yuneng Jiang4a163f1a6a05
diff --git a/tests/e2e/ui/tests/guardrails/guardrails.spec.ts b/tests/e2e/ui/tests/guardrails/guardrails.spec.tsindex a3ce6a73075..77ff020510b 100644--- a/tests/e2e/ui/tests/guardrails/guardrails.spec.ts+++ b/tests/e2e/ui/tests/guardrails/guardrails.spec.ts@@ -29,9 +29,7 @@ test.describe("Guardrails", () => {await page.keyboard.type("pre_call");await expect(page.getByRole("option", { name: "pre_call" })).toBeAttached({ timeout: 5_000 });await page.keyboard.press("Enter");- await expect(dialog.locator('[data-slot="combobox-chip"]').filter({ hasText: "pre_call" })).toBeVisible({- timeout: 5_000,- });+ await expect(dialog.getByText("pre_call", { exact: true })).toBeVisible({ timeout: 5_000 });await dialog.getByText("Create guardrail", { exact: true }).click();await dialog.getByLabel("presidio_analyzer_api_base").fill("http://127.0.0.1:9999");@@ -46,7 +44,7 @@ test.describe("Guardrails", () => {await dialog.getByRole("button", { name: "Create Guardrail" }).click();await expect(page.getByText("Guardrail created successfully").first()).toBeVisible({ timeout: 15_000 });- const row = page.locator("table tbody tr").filter({ hasText: guardrailName });+ const row = page.getByRole("row").filter({ hasText: guardrailName });await expect(row).toHaveCount(1, { timeout: 15_000 });await navigateToPage(page, Page.Teams);@@ -78,6 +76,6 @@ test.describe("Guardrails", () => {await page.reload();await expect(page.getByRole("button", { name: /Add New Guardrail/i })).toBeVisible({ timeout: 20_000 });- await expect(page.locator("table tbody tr").filter({ hasText: guardrailName })).toHaveCount(0);+ await expect(page.getByRole("row").filter({ hasText: guardrailName })).toHaveCount(0);});});diff --git a/tests/e2e/ui/tests/internal-user/internalUser.spec.ts b/tests/e2e/ui/tests/internal-user/internalUser.spec.tsindex 79733b3289b..f392c5104da 100644--- a/tests/e2e/ui/tests/internal-user/internalUser.spec.ts+++ b/tests/e2e/ui/tests/internal-user/internalUser.spec.ts@@ -44,35 +44,34 @@ test.describe("Internal User", () => {const suffix = Date.now();const auth = { Authorization: `Bearer ${masterKey()}` };- let apiKey = "";- try {- await navigateToPage(page, Page.ApiKeys);+ await navigateToPage(page, Page.ApiKeys);- await page.getByRole("button", { name: /Create New Key/i }).click();- await expect(page.getByText("Key Ownership")).toBeVisible({ timeout: 10_000 });+ await page.getByRole("button", { name: /Create New Key/i }).click();+ await expect(page.getByText("Key Ownership")).toBeVisible({ timeout: 10_000 });- await expect(page.getByRole("radio", { name: "You", exact: true })).toBeVisible({ timeout: 10_000 });- await expect(page.getByRole("radio", { name: "Another User" })).toHaveCount(0);+ await expect(page.getByRole("radio", { name: "You", exact: true })).toBeVisible({ timeout: 10_000 });+ await expect(page.getByRole("radio", { name: "Another User" })).toHaveCount(0);- const keyName = `e2e-internal-team-key-${suffix}`;- await page.getByLabel(/Key Name/).fill(keyName);+ const keyName = `e2e-internal-team-key-${suffix}`;+ await page.getByLabel(/Key Name/).fill(keyName);- const teamSelect = page.getByTestId("team-dropdown").getByRole("combobox");- await teamSelect.click();- await page.keyboard.type(E2E_TEAM_KEYGEN_ALIAS);- await page.locator('[data-slot="combobox-content"]:visible').getByText(E2E_TEAM_KEYGEN_ALIAS).first().click();+ const teamSelect = page.getByTestId("team-dropdown").getByRole("combobox");+ await teamSelect.click();+ await page.keyboard.type(E2E_TEAM_KEYGEN_ALIAS);+ await page.getByRole("option", { name: E2E_TEAM_KEYGEN_ALIAS }).first().click();- await page.getByRole("combobox", { name: "Select models" }).click();- await page.getByRole("option", { name: "All Team Models", exact: true }).click();- await page.keyboard.press("Escape");+ await page.getByRole("combobox", { name: "Select models" }).click();+ await page.getByRole("option", { name: "All Team Models", exact: true }).click();+ await page.keyboard.press("Escape");- await page.getByRole("button", { name: "Create Key", exact: true }).click();+ await page.getByRole("button", { name: "Create Key", exact: true }).click();- await expect(page.getByText("Save your Key")).toBeVisible({ timeout: 10_000 });- apiKey = (await page.getByRole("dialog", { name: "Save your Key" }).locator("pre").innerText()).trim();- expect(apiKey).toMatch(/^sk-/);- await page.keyboard.press("Escape");+ await expect(page.getByText("Save your Key")).toBeVisible({ timeout: 10_000 });+ const apiKey = (await page.getByRole("dialog", { name: "Save your Key" }).locator("pre").innerText()).trim();+ expect(apiKey).toMatch(/^sk-/);+ await page.keyboard.press("Escape");+ try {await openPlayground(page);await keySourceSelect(page).click();await onlyVisible(page.getByRole("option", { name: "Virtual Key" })).click({ timeout: 15_000 });@@ -86,9 +85,7 @@ test.describe("Internal User", () => {await expect(page.getByText(MOCK_RESPONSE_TEXT, { exact: false }).first()).toBeVisible({ timeout: 60_000 });} finally {- if (apiKey) {- await request.post("/key/delete", { headers: auth, data: { keys: [apiKey] } });- }+ await request.post("/key/delete", { headers: auth, data: { keys: [apiKey] } });}});diff --git a/tests/e2e/ui/tests/internal-user/internalUserWithTeams.spec.ts b/tests/e2e/ui/tests/internal-user/internalUserWithTeams.spec.tsindex d4c636e0541..62681e9ceb5 100644--- a/tests/e2e/ui/tests/internal-user/internalUserWithTeams.spec.ts+++ b/tests/e2e/ui/tests/internal-user/internalUserWithTeams.spec.ts@@ -8,12 +8,6 @@ import {import { Page } from "../../fixtures/pages";import { navigateToPage } from "../../helpers/navigation";-/**- * Differential partner to internalUserNoTeam.spec.ts: the seeded- * e2e-internal-user belongs to exactly three teams, so the Create Key dropdown- * must list all of them. Without this, the no-team spec's "zero options" assertion- * would still pass against a bug that empties the dropdown for everyone.- */test.describe("Internal User with team memberships", () => {test.use({ storageState: INTERNAL_USER_STORAGE_PATH });@@ -26,8 +20,6 @@ test.describe("Internal User with team memberships", () => {const teamSelect = page.getByTestId("team-dropdown").getByRole("combobox");await teamSelect.click();- // All seeded memberships render, and nothing else does — proving the- // dropdown is scoped to the user's teams rather than empty or unfiltered.await expect(page.getByRole("option", { name: E2E_TEAM_CRUD_ALIAS })).toBeVisible({ timeout: 10_000 });await expect(page.getByRole("option", { name: E2E_TEAM_ORG_ALIAS })).toBeVisible();await expect(page.getByRole("option", { name: E2E_TEAM_KEYGEN_ALIAS })).toBeVisible();diff --git a/tests/e2e/ui/tests/modelHub/modelHub.spec.ts b/tests/e2e/ui/tests/modelHub/modelHub.spec.tsindex 7fe3894d75d..6877fc9c48d 100644--- a/tests/e2e/ui/tests/modelHub/modelHub.spec.ts+++ b/tests/e2e/ui/tests/modelHub/modelHub.spec.ts@@ -85,7 +85,17 @@ test.describe("Public model hub (/ui/model_hub_table)", () => {const mcpServerName = `e2e_public_mcp_${suffix}`;const auth = { Authorization: `Bearer ${masterKey()}` };- const seedPublicEntries = async (api: APIRequestContext): Promise<{ agentId: string; serverId: string }> => {+ const publicMcpServerIds = async (api: APIRequestContext): Promise<string[]> => {+ const res = await api.get("/public/mcp_hub");+ expect(res.ok(), `public mcp_hub read failed (${res.status()}): ${await res.text()}`).toBe(true);+ const servers: { server_id: string }[] = await res.json();+ return servers.map((server) => server.server_id);+ };++ const seedPublicEntries = async (+ api: APIRequestContext,+ priorMcpIds: string[],+ ): Promise<{ agentId: string; serverId: string }> => {const agentRes = await api.post("/v1/agents", {headers: auth,data: {@@ -117,21 +127,19 @@ test.describe("Public model hub (/ui/model_hub_table)", () => {expect(serverRes.ok(), `mcp server create failed (${serverRes.status()}): ${await serverRes.text()}`).toBe(true);const serverId = (await serverRes.json()).server_id as string;- const agentPublicRes = await api.post("/v1/agents/make_public", {- headers: auth,- data: { agent_ids: [agentId] },- });- expect(agentPublicRes.ok(), `agents make_public failed: ${await agentPublicRes.text()}`).toBe(true);+ const agentPublicRes = await api.post(`/v1/agents/${agentId}/make_public`, { headers: auth });+ expect(agentPublicRes.ok(), `agent make_public failed: ${await agentPublicRes.text()}`).toBe(true);const mcpPublicRes = await api.post("/v1/mcp/make_public", {headers: auth,- data: { mcp_server_ids: [serverId] },+ data: { mcp_server_ids: [...priorMcpIds, serverId] },});expect(mcpPublicRes.ok(), `mcp make_public failed: ${await mcpPublicRes.text()}`).toBe(true);return { agentId, serverId };};- const { agentId, serverId } = await seedPublicEntries(request);+ const priorMcpIds = await publicMcpServerIds(request);+ const { agentId, serverId } = await seedPublicEntries(request, priorMcpIds);try {await page.goto(`/ui/model_hub_table?key=${masterKey()}`);await dismissFeedbackPopup(page);@@ -150,8 +158,7 @@ test.describe("Public model hub (/ui/model_hub_table)", () => {await expect(page.getByRole("row").filter({ hasText: mcpServerName })).toHaveCount(1, { timeout: 10_000 });await expect(page.getByText("E2E public MCP server").first()).toBeVisible();} finally {- await request.post("/v1/agents/make_public", { headers: auth, data: { agent_ids: [] } });- await request.post("/v1/mcp/make_public", { headers: auth, data: { mcp_server_ids: [] } });+ await request.post("/v1/mcp/make_public", { headers: auth, data: { mcp_server_ids: priorMcpIds } });await request.delete(`/v1/agents/${agentId}`, { headers: auth });await request.delete(`/v1/mcp/server/${serverId}`, { headers: auth });}diff --git a/tests/e2e/ui/tests/modelsPage/deleteTeamModel.spec.ts b/tests/e2e/ui/tests/modelsPage/deleteTeamModel.spec.tsindex dca7d9f006b..96abd9833c0 100644--- a/tests/e2e/ui/tests/modelsPage/deleteTeamModel.spec.ts+++ b/tests/e2e/ui/tests/modelsPage/deleteTeamModel.spec.ts@@ -5,8 +5,10 @@ import { navigateToPage } from "../../helpers/navigation";import { readBack } from "../../helpers/roundTrip";import { masterKey } from "../../helpers/traffic";-async function findDeploymentByName(page: PlaywrightPage, modelName: string): Promise<Record<string, any> | undefined> {- const body = await readBack<{ data: Record<string, any>[] }>(page, "/v2/model/info");+type DeploymentRow = { model_name?: string };++async function findDeploymentByName(page: PlaywrightPage, modelName: string): Promise<DeploymentRow | undefined> {+ const body = await readBack<{ data: DeploymentRow[] }>(page, "/v2/model/info");return body.data.find((row) => row.model_name === modelName);}@@ -41,7 +43,7 @@ test.describe("Delete team model", () => {await navigateToPage(page, Page.Models);await page.getByPlaceholder("Search model names").fill(modelName);- const row = page.locator("table tbody tr").filter({ hasText: modelName });+ const row = page.getByRole("row").filter({ hasText: modelName });await expect(row).toHaveCount(1, { timeout: 15_000 });await expect(row.getByText(E2E_TEAM_CRUD_ID)).toBeVisible({ timeout: 10_000 });@@ -65,6 +67,6 @@ test.describe("Delete team model", () => {await page.reload();await page.getByPlaceholder("Search model names").fill(modelName);await expect(page.getByText("No models found").first()).toBeVisible({ timeout: 15_000 });- await expect(page.locator("table tbody tr").filter({ hasText: modelName })).toHaveCount(0);+ await expect(page.getByRole("row").filter({ hasText: modelName })).toHaveCount(0);});});diff --git a/tests/e2e/ui/tests/proxy-admin/secondAdmin.spec.ts b/tests/e2e/ui/tests/proxy-admin/secondAdmin.spec.tsindex 2dd30060d2d..5a8bc84cc13 100644--- a/tests/e2e/ui/tests/proxy-admin/secondAdmin.spec.ts+++ b/tests/e2e/ui/tests/proxy-admin/secondAdmin.spec.ts@@ -13,35 +13,38 @@ test.describe("Second proxy admin", () => {const password = "e2e-second-admin-password";const auth = { Authorization: `Bearer ${masterKey()}` };- const adminContext = await browser.newContext({ storageState: ADMIN_STORAGE_PATH });- let userId = "";- try {- const adminPage = await adminContext.newPage();- await navigateToPage(adminPage, Page.Users);- await dismissFeedbackPopup(adminPage);-- await adminPage.getByRole("button", { name: "+ Invite User", exact: true }).click();- const dialog = adminPage.getByRole("dialog", { name: "Invite User" });- await expect(dialog).toBeVisible({ timeout: 5_000 });-- await dialog.getByLabel("User Email").fill(email);-- await dialog.getByLabel(/Global Proxy Role/).click();- await adminPage.getByRole("option", { name: /Admin \(All Permissions\)/ }).click();-- const createdResponse = adminPage.waitForResponse(- (res) => res.url().includes("/user/new") && res.request().method() === "POST",- );- await dialog.getByRole("button", { name: "Invite User" }).click();- const createdBody = await (await createdResponse).json();- userId = (createdBody.data?.user_id ?? createdBody.user_id) as string;- expect(userId, "created user id from /user/new").toBeTruthy();-- await expect(adminPage.getByText("API user Created").first()).toBeVisible({ timeout: 10_000 });- } finally {- await adminContext.close();- }+ const inviteAdminUser = async (): Promise<string> => {+ const adminContext = await browser.newContext({ storageState: ADMIN_STORAGE_PATH });+ try {+ const adminPage = await adminContext.newPage();+ await navigateToPage(adminPage, Page.Users);+ await dismissFeedbackPopup(adminPage);++ await adminPage.getByRole("button", { name: "+ Invite User", exact: true }).click();+ const dialog = adminPage.getByRole("dialog", { name: "Invite User" });+ await expect(dialog).toBeVisible({ timeout: 5_000 });++ await dialog.getByLabel("User Email").fill(email);++ await dialog.getByLabel(/Global Proxy Role/).click();+ await adminPage.getByRole("option", { name: /Admin \(All Permissions\)/ }).click();++ const createdResponse = adminPage.waitForResponse(+ (res) => res.url().includes("/user/new") && res.request().method() === "POST",+ );+ await dialog.getByRole("button", { name: "Invite User" }).click();+ const createdBody = await (await createdResponse).json();+ const createdUserId = (createdBody.data?.user_id ?? createdBody.user_id) as string;+ expect(createdUserId, "created user id from /user/new").toBeTruthy();++ await expect(adminPage.getByText("API user Created").first()).toBeVisible({ timeout: 10_000 });+ return createdUserId;+ } finally {+ await adminContext.close();+ }+ };+ const userId = await inviteAdminUser();try {const passwordRes = await request.post("/user/update", {headers: auth,diff --git a/tests/e2e/ui/tests/team-admin/teamAdmin.spec.ts b/tests/e2e/ui/tests/team-admin/teamAdmin.spec.tsindex d902959de4c..26a6fa50b4b 100644--- a/tests/e2e/ui/tests/team-admin/teamAdmin.spec.ts+++ b/tests/e2e/ui/tests/team-admin/teamAdmin.spec.ts@@ -147,8 +147,6 @@ test.describe("Team Admin", () => {expect(teamRes.ok(), `team create failed (${teamRes.status()}): ${await teamRes.text()}`).toBe(true);const teamId = (await teamRes.json()).team_id as string;- let modelId = "";- let teamKey = "";try {const modelRes = await request.post("/model/new", {headers: auth,@@ -163,55 +161,57 @@ test.describe("Team Admin", () => {},});expect(modelRes.ok(), `model create failed (${modelRes.status()}): ${await modelRes.text()}`).toBe(true);- modelId = (await modelRes.json()).model_info?.id as string;-- const keyRes = await request.post("/key/generate", { headers: auth, data: { team_id: teamId } });- expect(keyRes.ok(), `key generate failed (${keyRes.status()}): ${await keyRes.text()}`).toBe(true);- teamKey = (await keyRes.json()).key as string;-- await expect- .poll(- async () => {- const res = await request.get("/model_group/info", {- headers: { Authorization: `Bearer ${teamKey}` },- });- if (!res.ok()) return false;- const body: { data?: { model_group?: string }[] } = await res.json();- return (body.data ?? []).some((group) => group.model_group === teamModelName);- },- {- message: `model group ${teamModelName} never became visible to the team key`,- timeout: 30_000,- },- )- .toBe(true);-- await openPlayground(page);- await keySourceSelect(page).click();- await onlyVisible(page.getByRole("option", { name: "Virtual Key" })).click({ timeout: 15_000 });-- const keyInput = onlyVisible(page.getByPlaceholder("Enter custom Virtual Key"));- await expect(keyInput).toBeVisible({ timeout: 10_000 });- await keyInput.fill(teamKey);-- const select = modelSelect(page);- await select.click();- await select.fill(teamModelName);- await expect(onlyVisible(page.getByRole("option", { name: teamModelName }))).toBeVisible({- timeout: 15_000,- });-- await select.fill(CHAT_MODEL_A);- await expect(onlyVisible(page.getByRole("option", { name: CHAT_MODEL_A }))).toBeVisible({- timeout: 15_000,- });- } finally {- if (teamKey) {- await request.post("/key/delete", { headers: auth, data: { keys: [teamKey] } });- }- if (modelId) {+ const modelId = (await modelRes.json()).model_info?.id as string;++ try {+ const keyRes = await request.post("/key/generate", { headers: auth, data: { team_id: teamId } });+ expect(keyRes.ok(), `key generate failed (${keyRes.status()}): ${await keyRes.text()}`).toBe(true);+ const teamKey = (await keyRes.json()).key as string;++ try {+ await expect+ .poll(+ async () => {+ const res = await request.get("/model_group/info", {+ headers: { Authorization: `Bearer ${teamKey}` },+ });+ if (!res.ok()) return false;+ const body: { data?: { model_group?: string }[] } = await res.json();+ return (body.data ?? []).some((group) => group.model_group === teamModelName);+ },+ {+ message: `model group ${teamModelName} never became visible to the team key`,+ timeout: 30_000,+ },+ )+ .toBe(true);++ await openPlayground(page);+ await keySourceSelect(page).click();+ await onlyVisible(page.getByRole("option", { name: "Virtual Key" })).click({ timeout: 15_000 });++ const keyInput = onlyVisible(page.getByPlaceholder("Enter custom Virtual Key"));+ await expect(keyInput).toBeVisible({ timeout: 10_000 });+ await keyInput.fill(teamKey);++ const select = modelSelect(page);+ await select.click();+ await select.fill(teamModelName);+ await expect(onlyVisible(page.getByRole("option", { name: teamModelName }))).toBeVisible({+ timeout: 15_000,+ });++ await select.fill(CHAT_MODEL_A);+ await expect(onlyVisible(page.getByRole("option", { name: CHAT_MODEL_A }))).toBeVisible({+ timeout: 15_000,+ });+ } finally {+ await request.post("/key/delete", { headers: auth, data: { keys: [teamKey] } });+ }+ } finally {await request.post("/model/delete", { headers: auth, data: { id: modelId } });}+ } finally {await request.post("/team/delete", { headers: auth, data: { team_ids: [teamId] } });}});