litellm/tests/e2e/ui/constants.ts
mubashir1osmani 12b3d163b6 test(e2e/ui): derive the target from the environment and self-seed its users
tests/e2e/ui could only ever run against a locally provisioned stack, so it has
never run in the e2e pod. Three things pinned it there.

playwright.config.ts hardcoded baseURL http://localhost:4000 and globalSetup.ts
hardcoded the same host for /update/ui_settings and /ui/login. Both now derive
from LITELLM_PROXY_URL, falling back to localhost:4000 so local runs are
unchanged.

Storage state paths were repo-relative, so globalSetup wrote
admin.storageState.json into cwd. That is read-only in the runner image under
readOnlyRootFilesystem. They now sit under PLAYWRIGHT_STATE_DIR, defaulting to
"." for local runs. The per-role constants the specs import directly were
switched over too, so writer and readers stay in agreement.

globalSetup logged in as five roles whose users only exist if fixtures/seed.sql
was applied, and it throws when a login fails, so against an unseeded target the
whole suite died before a single spec ran. It now creates those users through the
proxy API first. ProxyAdmin is untouched since it logs in as "admin" with the
master key and needs no user row.

Verified against a live proxy that the seeding path works: /user/new returns 200,
/user/update sets the password, and /v2/login then authenticates as that user.
Worth knowing that /user/new accepts a password field but does not persist it
("User has no password set" on login), which is why the password is applied in a
second call.

All 25 spec files and 86 tests still collect, and the resolved values are correct
(trailing slash stripped, storage state redirected).

Teams, keys and the org from seed.sql are not self-seeded yet, so specs that
reference those ids still need them present on the target.
2026-07-25 11:39:20 -07:00

39 lines
2.1 KiB
TypeScript

// Target base URL for the proxy and its admin UI. Derived from the environment
// so the suite can run against a deployed proxy as well as a local one; the
// previous hardcoded http://localhost:4000 made it local-only.
export const BASE_URL = (process.env.LITELLM_PROXY_URL ?? "http://localhost:4000").replace(/\/+$/, "");
// Where Playwright storage state is written. cwd is read-only in the e2e runner
// image (readOnlyRootFilesystem), so allow redirecting it there while keeping
// the repo-relative default for local runs.
export const STATE_DIR = (process.env.PLAYWRIGHT_STATE_DIR ?? ".").replace(/\/+$/, "");
// Storage state paths for each role
export const ADMIN_STORAGE_PATH = `${STATE_DIR}/admin.storageState.json`;
export const ADMIN_VIEWER_STORAGE_PATH = `${STATE_DIR}/adminViewer.storageState.json`;
export const INTERNAL_USER_STORAGE_PATH = `${STATE_DIR}/internalUser.storageState.json`;
export const INTERNAL_VIEWER_STORAGE_PATH = `${STATE_DIR}/internalViewer.storageState.json`;
export const TEAM_ADMIN_STORAGE_PATH = `${STATE_DIR}/teamAdmin.storageState.json`;
// Seeded user identities (match seed.sql)
export const E2E_PROXY_ADMIN_USER_ID = "e2e-proxy-admin";
export const E2E_PROXY_ADMIN_EMAIL = "admin@test.local";
export const E2E_INTERNAL_USER_ID = "e2e-internal-user";
export const E2E_INTERNAL_USER_EMAIL = "internal@test.local";
// Key aliases for seeded test keys (match seed.sql)
export const E2E_UPDATE_LIMITS_KEY_ALIAS = "e2eUpdateLimitsKey";
export const E2E_DELETE_KEY_ALIAS = "e2eDeleteKey";
export const E2E_REGENERATE_KEY_ALIAS = "e2eRegenerateKey";
export const E2E_INTERNAL_USER_KEY_ALIAS = "e2eInternalUserKey";
export const E2E_VIEWER_KEY_ALIAS = "e2eViewerKey";
// Team identifiers (match seed.sql)
export const E2E_TEAM_CRUD_ID = "e2e-team-crud";
export const E2E_TEAM_CRUD_ALIAS = "E2E Team CRUD";
export const E2E_TEAM_DELETE_ID = "e2e-team-delete";
export const E2E_TEAM_DELETE_ALIAS = "E2E Team Delete";
export const E2E_TEAM_ORG_ID = "e2e-team-org";
export const E2E_TEAM_ORG_ALIAS = "E2E Team In Org";
export const E2E_TEAM_NO_ADMIN_ID = "e2e-team-no-admin";
export const E2E_TEAM_NO_ADMIN_ALIAS = "E2E Team No Admin";