-
Notifications
You must be signed in to change notification settings - Fork 1
feat(e2e): add Stremio end-to-end CI harness #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bf29f69
chore(release): v1.6.1 [skip ci]
github-actions[bot] 8d35b2a
Merge pull request #41 from leo-mathurin/staging
leo-mathurin 41d5748
chore(release): v1.7.0 [skip ci]
github-actions[bot] 92fcc73
feat(e2e): add Stremio end-to-end test harness
leo-mathurin 6489176
fix(e2e): address Greptile review findings
leo-mathurin 5064df8
fix(e2e): include all persisted test users in cleanup
leo-mathurin 0843152
test(e2e): run full suite by default
leo-mathurin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| playwright-report | ||
| test-results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # @stremlist/e2e | ||
|
|
||
| End-to-end tests that exercise Stremlist the way a real user does: the addon | ||
| is installed into the **hosted Stremio Web app** (web.stremio.com) from a | ||
| backend running locally, with **live IMDb data** and a **local Supabase | ||
| stack**. The configure/onboarding pages of the frontend are covered too. | ||
|
|
||
| ## How it works | ||
|
|
||
| - Playwright starts the backend (`:7301`) and the frontend (`:7302`) as web | ||
| servers with ports distinct from the dev ones, so tests can run next to a | ||
| normal dev session. | ||
| - The backend points at a local Supabase stack (`supabase start`), reset | ||
| between tests. Functional seeding goes through the backend's own HTTP API, | ||
| so tests exercise real code paths. | ||
| - Stremio Web runs in anonymous mode: each fresh browser context has its own | ||
| local addon collection. No Stremio account or shared state is involved. | ||
| - Chromium is launched with `--disable-features=LocalNetworkAccessChecks,...` | ||
| because Chrome otherwise blocks the HTTPS Stremio Web page from fetching the | ||
| addon on `127.0.0.1` (Local Network Access permission, never grantable in | ||
| headless runs). | ||
| - IMDb is live. Assertions are structural (ordering invariants, id shapes, | ||
| counts) or compare the Stremio UI against the addon's own catalog JSON from | ||
| the same run, so they do not depend on what is in the watchlist today. | ||
| - The default run and pull request CI execute all three projects: deterministic | ||
| local coverage, four live smoke tests, and the broader live regression suite. | ||
|
|
||
| ## Running locally | ||
|
|
||
| ```sh | ||
| # One-time / per boot: start the local Supabase stack (needs Docker running) | ||
| supabase start -x gotrue,realtime,storage-api,imgproxy,studio,edge-runtime,logflare,vector,supavisor,mailpit,postgres-meta | ||
|
|
||
| # From the repo root: run every E2E project | ||
| pnpm test:e2e | ||
|
|
||
| # Select one project while debugging | ||
| pnpm --filter @stremlist/e2e test:e2e --project=local | ||
| pnpm --filter @stremlist/e2e test:e2e --project=live-smoke | ||
| pnpm --filter @stremlist/e2e test:e2e --project=live-regression | ||
| ``` | ||
|
|
||
| The suite deletes test users between cases. Foreign-key cascades clear their | ||
| watchlists and caches in the same database statement. The harness rejects any | ||
| non-loopback Supabase URL unless the caller provides the explicit destructive | ||
| confirmation described below. | ||
|
|
||
| ## Environment knobs | ||
|
|
||
| | Variable | Purpose | | ||
| | -------------------------------------------------------- | ----------------------------------------------------------------------------------------- | | ||
| | `E2E_SUPABASE_URL` / `E2E_SUPABASE_SERVICE_ROLE_KEY` | Non-default local Supabase stack | | ||
| | `E2E_ALLOW_REMOTE_DATABASE=I_UNDERSTAND_THIS_WIPES_DATA` | Permit an isolated remote test project. Cleanup deletes every user and all dependent data | | ||
| | `E2E_IMDB_USER_ID` / `E2E_IMDB_USER_ID_2` | Override the public watchlists under test | | ||
| | `E2E_IMDB_LIST_ID` | Override the public `ls` list under test | | ||
| | `E2E_PRIVATE_IMDB_USER_ID` | Override the private watchlist under test | | ||
| | `E2E_PRIVATE_IMDB_LIST_ID` | Enable the private `ls` list test | | ||
|
|
||
| ## Known limitations | ||
|
|
||
| - Drag-and-drop catalog reordering (pointer-based dnd-kit) is not covered. | ||
| - The newsletter endpoint is not covered (it would email real people). | ||
| - The live smoke and regression suites depend on web.stremio.com and IMDb. CI | ||
| retries failures twice. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Shared constants for the E2E harness. Every port is distinct from the | ||
| // regular dev ports (7001/5173) so tests can run next to a dev session. | ||
|
|
||
| export const BACKEND_PORT = 7301; | ||
| export const FRONTEND_PORT = 7302; | ||
|
|
||
| export const BACKEND_URL = `http://127.0.0.1:${BACKEND_PORT}`; | ||
| export const FRONTEND_URL = `http://127.0.0.1:${FRONTEND_PORT}`; | ||
|
|
||
| export const STREMIO_WEB_URL = "https://web.stremio.com"; | ||
|
|
||
| // Local Supabase stack (supabase start). The service-role key below is the | ||
| // public, well-known key every local Supabase CLI stack ships with — it is not | ||
| // a secret. Both values can be overridden for non-default stacks. | ||
| export const SUPABASE_URL = | ||
| process.env.E2E_SUPABASE_URL ?? "http://127.0.0.1:54321"; | ||
| export const SUPABASE_SERVICE_ROLE_KEY = | ||
| process.env.E2E_SUPABASE_SERVICE_ROLE_KEY ?? | ||
| "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU"; | ||
|
|
||
| const REMOTE_DATABASE_CONFIRMATION = "I_UNDERSTAND_THIS_WIPES_DATA"; | ||
|
|
||
| function assertSafeSupabaseTarget(): void { | ||
| let hostname: string; | ||
| try { | ||
| hostname = new URL(SUPABASE_URL).hostname.toLowerCase(); | ||
| } catch { | ||
| throw new Error(`E2E_SUPABASE_URL is not a valid URL: ${SUPABASE_URL}`); | ||
| } | ||
|
|
||
| const isLoopback = ["localhost", "127.0.0.1", "[::1]", "::1"].includes( | ||
| hostname, | ||
| ); | ||
| const remoteWipeConfirmed = | ||
| process.env.E2E_ALLOW_REMOTE_DATABASE === REMOTE_DATABASE_CONFIRMATION; | ||
|
|
||
| if (!isLoopback && !remoteWipeConfirmed) { | ||
| throw new Error( | ||
|
leo-mathurin marked this conversation as resolved.
|
||
| `Refusing to run destructive E2E cleanup against non-loopback Supabase host "${hostname}". ` + | ||
| `Use a disposable local stack, or set E2E_ALLOW_REMOTE_DATABASE=${REMOTE_DATABASE_CONFIRMATION} only for an isolated remote test project.`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| assertSafeSupabaseTarget(); | ||
|
|
||
| // Short cooldown so refresh-throttle tests stay fast. | ||
| export const REFRESH_COOLDOWN_SECONDS = 2; | ||
|
|
||
| export function addonManifestUrl(userId: string): string { | ||
| return `${BACKEND_URL}/${userId}/manifest.json`; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import baseConfig from "@stremlist/eslint-config/base"; | ||
| import prettier from "eslint-config-prettier/flat"; | ||
|
|
||
| export default [ | ||
| { ignores: ["eslint.config.mjs", "playwright-report/**", "test-results/**"] }, | ||
| ...baseConfig, | ||
| { | ||
| languageOptions: { | ||
| parserOptions: { | ||
| project: "./tsconfig.json", | ||
| tsconfigRootDir: import.meta.dirname, | ||
| }, | ||
| }, | ||
| rules: { | ||
| curly: ["error", "multi-line"], | ||
| }, | ||
| }, | ||
| prettier, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import type { | ||
| StremioManifest, | ||
| StremioMeta, | ||
| UserConfigResponse, | ||
| UserConfigUpdateWatchlist, | ||
| } from "@stremlist/shared"; | ||
| import { hcWithType } from "@stremlist/backend/client"; | ||
| import { BACKEND_URL } from "../env.js"; | ||
|
|
||
| // Thin typed wrappers over the backend HTTP API. Tests use these both to | ||
| // arrange state (through real code paths) and to assert the addon protocol | ||
| // contract that Stremio clients consume. | ||
|
|
||
| export type CatalogMeta = StremioMeta; | ||
| type Manifest = StremioManifest; | ||
| type UserConfig = UserConfigResponse; | ||
| const api = hcWithType(BACKEND_URL); | ||
|
|
||
| async function getJson<T>(path: string): Promise<{ status: number; body: T }> { | ||
| const response = await fetch(`${BACKEND_URL}${path}`); | ||
| return { status: response.status, body: (await response.json()) as T }; | ||
| } | ||
|
|
||
| export async function getBaseManifest(): Promise<Manifest> { | ||
| return (await getJson<Manifest>("/manifest.json")).body; | ||
| } | ||
|
|
||
| export async function getUserManifest(userId: string): Promise<Manifest> { | ||
| return (await getJson<Manifest>(`/${userId}/manifest.json`)).body; | ||
| } | ||
|
|
||
| export async function getConfig( | ||
| userId: string, | ||
| ): Promise<{ status: number; body: UserConfig }> { | ||
| const response = await api[":userId"].config.$get({ param: { userId } }); | ||
| return { | ||
| status: response.status, | ||
| body: (await response.json()) as UserConfig, | ||
| }; | ||
| } | ||
|
|
||
| type ConfigWatchlistInput = UserConfigUpdateWatchlist; | ||
|
|
||
| export async function postConfig( | ||
| userId: string, | ||
| watchlists: ConfigWatchlistInput[], | ||
| rpdbApiKey?: string, | ||
| ): Promise<{ status: number; body: unknown }> { | ||
| const response = await api[":userId"].config.$post({ | ||
| param: { userId }, | ||
| json: { watchlists, rpdbApiKey }, | ||
| }); | ||
| return { status: response.status, body: await response.json() }; | ||
| } | ||
|
|
||
| export async function getCatalog( | ||
| userId: string, | ||
| type: string, | ||
| catalogId: string, | ||
| ): Promise<{ status: number; metas: CatalogMeta[] }> { | ||
| const { status, body } = await getJson<{ metas: CatalogMeta[] }>( | ||
| `/${userId}/catalog/${type}/${catalogId}.json`, | ||
| ); | ||
| return { status, metas: body.metas }; | ||
| } | ||
|
|
||
| export async function getMeta( | ||
| userId: string, | ||
| type: string, | ||
| id: string, | ||
| ): Promise<{ status: number; meta: CatalogMeta | null }> { | ||
| const { status, body } = await getJson<{ meta: CatalogMeta | null }>( | ||
| `/${userId}/meta/${type}/${id}.json`, | ||
| ); | ||
| return { status, meta: body.meta }; | ||
| } | ||
|
|
||
| export async function refresh( | ||
| userId: string, | ||
| ): Promise<{ status: number; body: Record<string, unknown> }> { | ||
| const response = await api[":userId"].refresh.$post({ | ||
| param: { userId }, | ||
| }); | ||
| return { | ||
| status: response.status, | ||
| body: (await response.json()) as Record<string, unknown>, | ||
| }; | ||
| } | ||
|
|
||
| export async function validateUser( | ||
| userId: string, | ||
| ): Promise<Record<string, unknown>> { | ||
| const response = await api.validate[":userId"].$get({ param: { userId } }); | ||
| return (await response.json()) as Record<string, unknown>; | ||
| } | ||
|
|
||
| export async function validateList( | ||
| listId: string, | ||
| ): Promise<Record<string, unknown>> { | ||
| const response = await api["validate-list"][":listId"].$get({ | ||
| param: { listId }, | ||
| }); | ||
| return (await response.json()) as Record<string, unknown>; | ||
| } | ||
|
|
||
| /** | ||
| * Bootstrap a user exactly the way a real install does: the first manifest | ||
| * fetch upserts the user and seeds the default watchlist. Returns the config. | ||
| */ | ||
| export async function bootstrapUser(userId: string): Promise<UserConfig> { | ||
| await getUserManifest(userId); | ||
| const { status, body } = await getConfig(userId); | ||
| if (status !== 200) { | ||
| throw new Error(`bootstrapUser(${userId}) got ${status}`); | ||
| } | ||
| return body; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { createClient } from "@supabase/supabase-js"; | ||
| import type { Database } from "@stremlist/shared"; | ||
| import { SUPABASE_SERVICE_ROLE_KEY, SUPABASE_URL } from "../env.js"; | ||
| import { E2E_USER_IDS } from "./test-data.js"; | ||
|
|
||
| // Service-role client: bypasses RLS, used only to reset and inspect state | ||
| // between tests. All functional seeding goes through the backend's own HTTP | ||
| // API so the tests exercise real code paths. | ||
| const db = createClient<Database>(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY); | ||
|
|
||
| /** Delete only this run's test users. Foreign-key cascades reset their data. */ | ||
| export async function resetDb(): Promise<void> { | ||
| const { error } = await db | ||
| .from("users") | ||
| .delete() | ||
| .in("imdb_user_id", [...E2E_USER_IDS]); | ||
| if (error) throw new Error(`resetDb failed: ${error.message}`); | ||
|
leo-mathurin marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** Rewind a user's last_fetched_at so the refresh cooldown does not apply. */ | ||
| export async function clearRefreshCooldown(userId: string): Promise<void> { | ||
| const past = new Date(Date.now() - 60 * 60 * 1000).toISOString(); | ||
| const { error } = await db | ||
| .from("users") | ||
| .update({ last_fetched_at: past }) | ||
| .eq("imdb_user_id", userId); | ||
| if (error) throw new Error(`clearRefreshCooldown failed: ${error.message}`); | ||
| } | ||
|
|
||
| export async function countCacheItems(watchlistId: string): Promise<number> { | ||
| const { count, error } = await db | ||
| .from("watchlist_cache_items") | ||
| .select("*", { count: "exact", head: true }) | ||
| .eq("watchlist_id", watchlistId); | ||
| if (error) throw new Error(`countCacheItems failed: ${error.message}`); | ||
| return count ?? 0; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.