mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
test(e2e): add Playwright suite covering every app route
This commit is contained in:
1 parent
51e92d8cf2
commit
2580cdf863
10 files changed
+401
No files matched your search
@@ -98,3 +98,51 @@ jobs:
|
||||
|
||||
- name: Run tests
|
||||
run: pnpm test
|
||||
|
||||
e2e:
|
||||
name: E2E
|
||||
needs: check-ready
|
||||
if: needs.check-ready.outputs.should-run == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 10.28.1
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "24"
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Install OpenCode CLI
|
||||
run: |
|
||||
source scripts/lib/opencode-release.sh
|
||||
download_opencode_to 2.0.24 "$RUNNER_TEMP/opencode/bin/opencode"
|
||||
echo "$RUNNER_TEMP/opencode/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Verify OpenCode CLI
|
||||
run: opencode --version
|
||||
|
||||
- name: Install Playwright browsers
|
||||
run: pnpm exec playwright install --with-deps chromium
|
||||
|
||||
- name: Run end-to-end tests
|
||||
run: pnpm test:e2e
|
||||
|
||||
- name: Upload Playwright artifacts
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: playwright-artifacts
|
||||
path: |
|
||||
playwright-report/
|
||||
test-results/
|
||||
retention-days: 7
|
||||
@@ -20,4 +20,7 @@ workspace/
|
||||
/config/
|
||||
temp/
|
||||
.forge/
|
||||
e2e/.tmp
|
||||
test-results/
|
||||
playwright-report/
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { test, expect } from './fixtures'
|
||||
import { ADMIN_EMAIL, ADMIN_PASSWORD, BASE_URL, STORAGE_STATE } from './env'
|
||||
|
||||
test('authenticate as the env admin', async ({ page, request }) => {
|
||||
await page.goto('/login')
|
||||
|
||||
await page.getByLabel('Email').fill(ADMIN_EMAIL)
|
||||
await page.getByLabel('Password').fill(ADMIN_PASSWORD)
|
||||
await page.getByRole('button', { name: 'Sign In', exact: true }).click()
|
||||
|
||||
await expect(page).toHaveURL('/')
|
||||
await expect(page.getByRole('button', { name: 'Repo', exact: true })).toBeVisible()
|
||||
|
||||
await page.context().storageState({ path: STORAGE_STATE })
|
||||
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
const response = await request.get(`${BASE_URL}/api/health`)
|
||||
if (!response.ok()) return `http-${response.status()}`
|
||||
const body = await response.json()
|
||||
return body.opencode
|
||||
},
|
||||
{ timeout: 120_000, message: 'OpenCode server did not become healthy' },
|
||||
)
|
||||
.toBe('healthy')
|
||||
})
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
import { existsSync } from 'node:fs'
|
||||
import os from 'node:os'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
export const E2E_ROOT = path.dirname(fileURLToPath(import.meta.url))
|
||||
export const REPO_ROOT = path.resolve(E2E_ROOT, '..')
|
||||
export const E2E_TMP = path.join(E2E_ROOT, '.tmp')
|
||||
export const STORAGE_STATE = path.join(E2E_TMP, 'storage-state.json')
|
||||
|
||||
export const BASE_URL = 'http://127.0.0.1:5013'
|
||||
export const SERVER_PORT = 5013
|
||||
export const OPENCODE_SERVER_PORT = 5561
|
||||
export const PREVIEW_PORT = 5014
|
||||
|
||||
export const ADMIN_EMAIL = 'e2e-admin@example.com'
|
||||
export const ADMIN_PASSWORD = 'e2e-admin-password'
|
||||
export const AUTH_SECRET = 'e2e-playwright-auth-secret-0123456789'
|
||||
|
||||
function resolveOpenCodeBin(): string {
|
||||
const candidates = [
|
||||
process.env.OPENCODE_BIN,
|
||||
path.join(os.homedir(), '.opencode', 'bin', 'opencode'),
|
||||
'/usr/local/bin/opencode',
|
||||
'/opt/opencode/bin/opencode',
|
||||
].filter((candidate): candidate is string => Boolean(candidate))
|
||||
|
||||
return candidates.find((candidate) => existsSync(candidate)) ?? 'opencode'
|
||||
}
|
||||
|
||||
export function createServerEnv(): Record<string, string> {
|
||||
return {
|
||||
NODE_ENV: 'production',
|
||||
PORT: String(SERVER_PORT),
|
||||
HOST: '127.0.0.1',
|
||||
CORS_ORIGIN: BASE_URL,
|
||||
OPENCODE_SERVER_PORT: String(OPENCODE_SERVER_PORT),
|
||||
OPENCODE_HOST: '127.0.0.1',
|
||||
PREVIEW_PORT: String(PREVIEW_PORT),
|
||||
DATABASE_PATH: path.join(E2E_TMP, 'data', 'opencode-manager.db'),
|
||||
WORKSPACE_PATH: path.join(E2E_TMP, 'workspace'),
|
||||
REPO_BROWSE_ROOT: path.join(E2E_TMP, 'workspace'),
|
||||
AUTH_SECRET,
|
||||
AUTH_TRUSTED_ORIGINS: `${BASE_URL},http://localhost:${SERVER_PORT}`,
|
||||
AUTH_SECURE_COOKIES: 'false',
|
||||
PASSKEY_ORIGIN: BASE_URL,
|
||||
PASSKEY_RP_ID: '127.0.0.1',
|
||||
PASSKEY_RP_NAME: 'OpenCode Manager E2E',
|
||||
ADMIN_EMAIL,
|
||||
ADMIN_PASSWORD,
|
||||
HOME: path.join(E2E_TMP, 'home'),
|
||||
TMPDIR: path.join(E2E_TMP, 'tmp'),
|
||||
XDG_RUNTIME_DIR: path.join(E2E_TMP, 'run'),
|
||||
OPENCODE_BIN: resolveOpenCodeBin(),
|
||||
VAPID_PUBLIC_KEY: '',
|
||||
VAPID_PRIVATE_KEY: '',
|
||||
VAPID_SUBJECT: '',
|
||||
DEBUG: 'false',
|
||||
LOG_LEVEL: 'error',
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { test as base, expect, request as playwrightRequest, type Page } from '@playwright/test'
|
||||
import { BASE_URL, E2E_TMP, STORAGE_STATE } from './env'
|
||||
|
||||
const UNAUTHENTICATED_BOOTSTRAP_ENDPOINTS = [
|
||||
'/api/settings',
|
||||
'/api/schedules/all/runs/unread',
|
||||
'/api/repos',
|
||||
'/api/sse/stream',
|
||||
]
|
||||
|
||||
function isIgnoredConsoleError(text: string): boolean {
|
||||
if (!text.includes('401 (Unauthorized)')) return false
|
||||
return UNAUTHENTICATED_BOOTSTRAP_ENDPOINTS.some((endpoint) => text.includes(endpoint))
|
||||
}
|
||||
|
||||
export interface RepoFixture {
|
||||
id: number
|
||||
name: string
|
||||
fullPath: string
|
||||
sessionId: string
|
||||
}
|
||||
|
||||
interface WorkerFixtures {
|
||||
repo: RepoFixture
|
||||
}
|
||||
|
||||
async function createGitFixtureRepo(directory: string): Promise<void> {
|
||||
fs.rmSync(directory, { recursive: true, force: true })
|
||||
fs.mkdirSync(directory, { recursive: true })
|
||||
fs.writeFileSync(path.join(directory, 'README.md'), '# e2e fixture repository\n')
|
||||
|
||||
const git = (...args: string[]) => execFileSync('git', args, { cwd: directory, stdio: 'pipe' })
|
||||
git('-c', 'init.defaultBranch=main', 'init', '-q')
|
||||
git('-c', 'user.name=e2e', '-c', 'user.email=e2e@example.com', 'add', '-A')
|
||||
git('-c', 'user.name=e2e', '-c', 'user.email=e2e@example.com', 'commit', '-q', '-m', 'initial commit')
|
||||
}
|
||||
|
||||
export const test = base.extend<{ page: Page }, WorkerFixtures>({
|
||||
page: async ({ page }, use) => {
|
||||
const errors: string[] = []
|
||||
page.on('pageerror', (error) => {
|
||||
errors.push(`pageerror: ${error.message}`)
|
||||
})
|
||||
page.on('console', (message) => {
|
||||
if (message.type() !== 'error') return
|
||||
const url = message.location().url
|
||||
const text = `${message.text()}${url ? ` (${url})` : ''}`
|
||||
if (isIgnoredConsoleError(text)) return
|
||||
errors.push(`console.error: ${text}`)
|
||||
})
|
||||
|
||||
await use(page)
|
||||
|
||||
expect(errors, `Unexpected browser errors:\n${errors.join('\n')}`).toEqual([])
|
||||
},
|
||||
|
||||
repo: [
|
||||
async ({}, use, workerInfo) => {
|
||||
const api = await playwrightRequest.newContext({
|
||||
baseURL: BASE_URL,
|
||||
storageState: STORAGE_STATE,
|
||||
})
|
||||
|
||||
try {
|
||||
const directory = path.join(E2E_TMP, `e2e-fixture-repo-${workerInfo.workerIndex}`)
|
||||
await createGitFixtureRepo(directory)
|
||||
|
||||
const repoResponse = await api.post('/api/repos', { data: { localPath: directory } })
|
||||
if (!repoResponse.ok()) {
|
||||
throw new Error(`Failed to register e2e repo: ${repoResponse.status()} ${await repoResponse.text()}`)
|
||||
}
|
||||
const repo = await repoResponse.json()
|
||||
|
||||
const sessionResponse = await api.post('/api/opencode/api/session', {
|
||||
data: { location: { directory: repo.fullPath } },
|
||||
})
|
||||
if (!sessionResponse.ok()) {
|
||||
throw new Error(`Failed to create e2e session: ${sessionResponse.status()} ${await sessionResponse.text()}`)
|
||||
}
|
||||
const session = await sessionResponse.json()
|
||||
|
||||
await use({
|
||||
id: repo.id,
|
||||
name: path.basename(repo.localPath),
|
||||
fullPath: repo.fullPath,
|
||||
sessionId: session.data.id,
|
||||
})
|
||||
} finally {
|
||||
await api.dispose()
|
||||
}
|
||||
},
|
||||
{ scope: 'worker' },
|
||||
],
|
||||
})
|
||||
|
||||
export { expect }
|
||||
@@ -0,0 +1,48 @@
|
||||
import path from 'node:path'
|
||||
import { defineConfig, devices } from '@playwright/test'
|
||||
import { BASE_URL, E2E_ROOT, REPO_ROOT, STORAGE_STATE, createServerEnv } from './env'
|
||||
|
||||
export default defineConfig({
|
||||
testDir: E2E_ROOT,
|
||||
outputDir: path.join(REPO_ROOT, 'test-results'),
|
||||
fullyParallel: false,
|
||||
forbidOnly: Boolean(process.env.CI),
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
workers: process.env.CI ? 1 : undefined,
|
||||
timeout: 60_000,
|
||||
expect: { timeout: 15_000 },
|
||||
reporter: [
|
||||
['list'],
|
||||
['html', { open: 'never', outputFolder: path.join(REPO_ROOT, 'playwright-report') }],
|
||||
],
|
||||
use: {
|
||||
baseURL: BASE_URL,
|
||||
trace: 'on-first-retry',
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'retain-on-failure',
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: 'setup',
|
||||
testMatch: /auth\.setup\.ts/,
|
||||
},
|
||||
{
|
||||
name: 'chromium',
|
||||
testMatch: /.*\.spec\.ts/,
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
storageState: STORAGE_STATE,
|
||||
},
|
||||
dependencies: ['setup'],
|
||||
},
|
||||
],
|
||||
webServer: {
|
||||
command: 'bash e2e/server.sh',
|
||||
cwd: REPO_ROOT,
|
||||
url: `${BASE_URL}/api/health`,
|
||||
timeout: 180_000,
|
||||
reuseExistingServer: false,
|
||||
gracefulShutdown: { signal: 'SIGTERM', timeout: 15_000 },
|
||||
env: createServerEnv(),
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,73 @@
|
||||
import { test, expect } from './fixtures'
|
||||
|
||||
test.describe('application routes', () => {
|
||||
test('repos list renders the registered repository', async ({ page, repo }) => {
|
||||
await page.goto('/')
|
||||
await expect(page.getByRole('button', { name: 'Repo', exact: true })).toBeVisible()
|
||||
await expect(page.getByRole('heading', { name: repo.name })).toBeVisible()
|
||||
})
|
||||
|
||||
test('repo detail renders', async ({ page, repo }) => {
|
||||
await page.goto(`/repos/${repo.id}`)
|
||||
await expect(page.getByRole('heading', { name: repo.name })).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: 'New Session', exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test('repo assistant renders', async ({ page, repo }) => {
|
||||
await page.goto(`/repos/${repo.id}/assistant`)
|
||||
await expect(page.getByRole('heading', { name: 'Assistant' })).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: 'New Session', exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test('global assistant renders', async ({ page }) => {
|
||||
await page.goto('/assistant')
|
||||
await expect(page.getByRole('heading', { name: 'Assistant' })).toBeVisible()
|
||||
})
|
||||
|
||||
test('session detail renders', async ({ page, repo }) => {
|
||||
await page.goto(`/repos/${repo.id}/sessions/${repo.sessionId}`)
|
||||
await expect(page.getByTestId('session-header-region')).toBeVisible()
|
||||
await expect(page.getByPlaceholder('Send a message...')).toBeVisible()
|
||||
})
|
||||
|
||||
test('repo schedules renders', async ({ page, repo }) => {
|
||||
await page.goto(`/repos/${repo.id}/schedules`)
|
||||
await expect(page.getByRole('button', { name: `Switch repository (${repo.name})` })).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: 'New Schedule' })).toBeVisible()
|
||||
})
|
||||
|
||||
test('global schedules renders', async ({ page }) => {
|
||||
await page.goto('/schedules')
|
||||
await expect(page.getByRole('button', { name: 'Switch repository (All repos)' })).toBeVisible()
|
||||
await expect(page.getByRole('tab', { name: 'Jobs' })).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('unauthenticated routes', () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
test('login page renders the credentials form', async ({ page }) => {
|
||||
await page.goto('/login')
|
||||
await expect(page.getByLabel('Email')).toBeVisible()
|
||||
await expect(page.getByLabel('Password')).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: 'Sign In', exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test('register redirects to login', async ({ page }) => {
|
||||
await page.goto('/register')
|
||||
await expect(page).toHaveURL(/\/login$/)
|
||||
await expect(page.getByRole('button', { name: 'Sign In', exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test('setup redirects to login', async ({ page }) => {
|
||||
await page.goto('/setup')
|
||||
await expect(page).toHaveURL(/\/login$/)
|
||||
await expect(page.getByRole('button', { name: 'Sign In', exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test('protected route redirects to login', async ({ page }) => {
|
||||
await page.goto('/schedules')
|
||||
await expect(page).toHaveURL(/\/login$/)
|
||||
await expect(page.getByRole('button', { name: 'Sign In', exact: true })).toBeVisible()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
TMP="$ROOT/e2e/.tmp"
|
||||
|
||||
rm -rf "$TMP"
|
||||
mkdir -p "$TMP/home" "$TMP/data" "$TMP/workspace" "$TMP/tmp" "$TMP/run"
|
||||
|
||||
cd "$ROOT"
|
||||
exec bun run backend/dist/index.js
|
||||
@@ -25,6 +25,8 @@
|
||||
"test:cli": "pnpm --filter @opencode-manager/ocm-cli test",
|
||||
"test:frontend": "pnpm --filter frontend exec vitest run",
|
||||
"test:backend": "pnpm --filter backend run test",
|
||||
"test:e2e": "pnpm build && pnpm test:e2e:run",
|
||||
"test:e2e:run": "playwright test -c e2e/playwright.config.ts",
|
||||
"lint": "pnpm run lint:cli && pnpm run lint:frontend && pnpm run lint:backend",
|
||||
"lint:cli": "pnpm --filter @opencode-manager/ocm-cli lint",
|
||||
"lint:frontend": "pnpm --filter frontend lint",
|
||||
@@ -38,6 +40,7 @@
|
||||
"docker:restart": "docker-compose restart"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.64.0",
|
||||
"concurrently": "^9.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
Generated
+28
@@ -17,6 +17,9 @@ importers:
|
||||
specifier: ^0.7.1
|
||||
version: 0.7.1
|
||||
devDependencies:
|
||||
'@playwright/test':
|
||||
specifier: ^1.64.0
|
||||
version: 1.64.0
|
||||
concurrently:
|
||||
specifier: ^9.1.0
|
||||
version: 9.2.1
|
||||
@@ -1438,6 +1441,11 @@ packages:
|
||||
resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==}
|
||||
engines: {node: '>=14'}
|
||||
|
||||
'@playwright/test@1.64.0':
|
||||
resolution: {integrity: sha512-oTN9FNYuN6bqQMwiho6jJKLCG2/QOYCixGXuCjRmzOq23eODeukuY2XiAVoVpAECbuezMt1MHQjAiQxK8F+Y+g==}
|
||||
engines: {node: '>=20'}
|
||||
hasBin: true
|
||||
|
||||
'@polka/url@1.0.0-next.29':
|
||||
resolution: {integrity: sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==}
|
||||
|
||||
@@ -4496,6 +4504,16 @@ packages:
|
||||
resolution: {integrity: sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
playwright-core@1.64.0:
|
||||
resolution: {integrity: sha512-T9r+MZkTECl2+oUcZ26YgZzTrYidTsIhYYkJix+6iDOymOb1FB2RLLSOxRGnZGv5DStt+aduIVbt+E8WygXYpg==}
|
||||
engines: {node: '>=20'}
|
||||
hasBin: true
|
||||
|
||||
playwright@1.64.0:
|
||||
resolution: {integrity: sha512-kVzTnYFYEyQ9RGzBjNCd2+yEqWmVbxl3AHPynv3qQ6JTjv4a+kwRcnqQwIpuP3NnrnIrE/Q6wWAIAvMfIE2/Yg==}
|
||||
engines: {node: '>=20'}
|
||||
hasBin: true
|
||||
|
||||
points-on-curve@0.2.0:
|
||||
resolution: {integrity: sha512-0mYKnYYe9ZcqMCWhUjItv/oHjvgEsfKvnUTg8sAtnHr3GVy7rGkXCb6d5cSyqrWqL4k81b9CPg3urd+T7aop3A==}
|
||||
|
||||
@@ -6817,6 +6835,10 @@ snapshots:
|
||||
'@pkgjs/parseargs@0.11.0':
|
||||
optional: true
|
||||
|
||||
'@playwright/test@1.64.0':
|
||||
dependencies:
|
||||
playwright: 1.64.0
|
||||
|
||||
'@polka/url@1.0.0-next.29': {}
|
||||
|
||||
'@protobufjs/aspromise@1.1.2': {}
|
||||
@@ -10187,6 +10209,12 @@ snapshots:
|
||||
dependencies:
|
||||
find-up: 3.0.0
|
||||
|
||||
playwright-core@1.64.0: {}
|
||||
|
||||
playwright@1.64.0:
|
||||
dependencies:
|
||||
playwright-core: 1.64.0
|
||||
|
||||
points-on-curve@0.2.0: {}
|
||||
|
||||
points-on-path@0.2.1:
|
||||
|
||||
Reference in new issue
Block a user