Skip to content

Commit 1148a19

Browse files
committed
Add github action for e2e. Script to init script
1 parent 91e5653 commit 1148a19

File tree

4 files changed

+187
-5
lines changed

4 files changed

+187
-5
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: E2E Cat App Test
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
pull_request:
7+
branches: ['main']
8+
9+
env:
10+
# Using the same local DB credentials as in docker-compose.yml
11+
# These will be used by the PostgreSQL service and the application
12+
POSTGRES_USER: manicode_user_local
13+
POSTGRES_PASSWORD: secretpassword_local
14+
POSTGRES_DB: manicode_db_local
15+
# Ensure the application connects to the service container
16+
DATABASE_URL: postgres://manicode_user_local:secretpassword_local@localhost:5432/manicode_db_local
17+
# Set environment to local to avoid production database requirements for the script
18+
NEXT_PUBLIC_CB_ENVIRONMENT: 'local'
19+
# Disable BigQuery for testing, as seen in e2e-cat-app-script.ts
20+
DISABLE_BIGQUERY: 'true'
21+
# Port for the backend service started by the E2E script
22+
PORT: 3001
23+
# Backend URL for the CLI started by the E2E script
24+
CODEBUFF_BACKEND_URL: http://localhost:3001
25+
# NEXTAUTH_SECRET for the seeding script
26+
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET_E2E_TEST }} # Use a dedicated secret for this
27+
28+
jobs:
29+
e2e-test:
30+
runs-on: ubuntu-latest
31+
services:
32+
postgres:
33+
image: postgres:16
34+
env:
35+
POSTGRES_USER: ${{ env.POSTGRES_USER }}
36+
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
37+
POSTGRES_DB: ${{ env.POSTGRES_DB }}
38+
ports:
39+
- 5432:5432
40+
# Options to ensure the service is healthy before proceeding
41+
options: >-
42+
--health-cmd pg_isready
43+
--health-interval 10s
44+
--health-timeout 5s
45+
--health-retries 5
46+
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v3
50+
51+
- name: Set up Bun
52+
uses: oven-sh/setup-bun@v2
53+
with:
54+
bun-version: '1.2.12' # Using version from ci.yml
55+
56+
- name: Cache dependencies
57+
uses: actions/cache@v3
58+
with:
59+
path: |
60+
node_modules
61+
*/node_modules
62+
packages/*/node_modules
63+
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lockb') }}
64+
restore-keys: |
65+
${{ runner.os }}-deps-
66+
67+
- name: Install dependencies
68+
run: bun install --frozen-lockfile
69+
70+
- name: Wait for PostgreSQL to be ready
71+
run: |
72+
echo "Waiting for PostgreSQL to start..."
73+
until pg_isready -h localhost -p 5432 -U ${{ env.POSTGRES_USER }}; do
74+
sleep 1
75+
done
76+
echo "PostgreSQL is ready."
77+
78+
- name: Run database migrations
79+
run: bun --cwd common db:migrate
80+
env:
81+
# Drizzle Kit needs the DATABASE_URL
82+
DATABASE_URL: ${{ env.DATABASE_URL }}
83+
84+
- name: Seed test user
85+
run: bun evals/e2e/seed-test-user.ts
86+
env:
87+
DATABASE_URL: ${{ env.DATABASE_URL }}
88+
NEXTAUTH_SECRET: ${{ env.NEXTAUTH_SECRET }}
89+
90+
- name: Run E2E Cat App Test Script
91+
run: bun evals/e2e/e2e-cat-app-script.ts
92+
# The script has its own timeouts, but we can add a general timeout for the step
93+
timeout-minutes: 5 # Adjust as needed, the script itself has a 2-minute task timeout + setup time

evals/e2e-cat-app-script.ts renamed to evals/e2e/e2e-cat-app-script.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import { spawn, ChildProcess } from 'child_process'
44
import fs from 'fs'
55
import path from 'path'
6-
import { sleep } from 'common/util/promise'
6+
import { sleep } from '../../common/src/util/promise' // Corrected import path
77

88
const BACKEND_PORT = 3001
99
const BACKEND_READY_TIMEOUT = 30000 // 30 seconds
1010
const CLI_READY_TIMEOUT = 10000 // 10 seconds
1111
const TASK_COMPLETION_TIMEOUT = 120000 // 2 minutes
1212
const TEST_DIR = 'cat-app-test'
13-
const projectRoot = path.resolve(__dirname, '..')
13+
const projectRoot = path.resolve(__dirname, '../..') // Corrected projectRoot definition
1414

1515
interface ProcessInfo {
1616
process: ChildProcess
@@ -176,7 +176,7 @@ export class E2ETestRunner {
176176
console.log('🚀 Starting backend server using package.json script...')
177177

178178
const backendProcess = spawn('bun', ['run', 'start-server'], {
179-
cwd: projectRoot, // Run from project root, not evals directory
179+
cwd: projectRoot, // Run from actual project root, not evals directory
180180
detached: true,
181181
stdio: ['ignore', 'pipe', 'pipe'],
182182
env: {
@@ -228,7 +228,7 @@ export class E2ETestRunner {
228228
console.log('🤖 Starting CLI using package.json script...')
229229

230230
const cliProcess = spawn('bun', ['run', 'start-client'], {
231-
cwd: path.join(process.cwd(), '..'), // Run from project root, not evals directory
231+
cwd: projectRoot, // Corrected: Run from actual project root
232232
detached: true,
233233
stdio: ['pipe', 'pipe', 'pipe'],
234234
env: {

evals/e2e/seed-test-user.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bun
2+
import fs from 'node:fs/promises'
3+
import path from 'node:path'
4+
import crypto from 'node:crypto'
5+
import os from 'node:os'
6+
7+
import db from '../../common/src/db' // Corrected import path
8+
import * as schema from '../../common/src/db/schema' // Corrected import path
9+
import { genAuthCode } from '../../common/src/util/credentials' // Corrected import path
10+
11+
async function seedTestUser() {
12+
console.log('🌱 Starting test user seeding...')
13+
14+
const nextAuthSecret = process.env.NEXTAUTH_SECRET
15+
if (!nextAuthSecret) {
16+
console.error('❌ NEXTAUTH_SECRET environment variable is not set.')
17+
process.exit(1)
18+
}
19+
20+
const userId = `test-user-${crypto.randomUUID()}`
21+
const userEmail = `test-${crypto.randomBytes(8).toString('hex')}@example.com`
22+
const userName = 'E2E Test User'
23+
const fingerprintId = `test-fp-${crypto.randomUUID()}`
24+
const sessionToken = `test-session-${crypto.randomUUID()}`
25+
26+
// For the fingerprintHash, we need an expiry. Let's set it far in the future for the test.
27+
const expiresAt = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000) // 1 year
28+
const fingerprintHash = genAuthCode(fingerprintId, expiresAt.getTime().toString(), nextAuthSecret)
29+
30+
try {
31+
// 1. Create User
32+
await db.insert(schema.user).values({
33+
id: userId,
34+
email: userEmail,
35+
name: userName,
36+
emailVerified: new Date(), // Mark as verified for simplicity
37+
})
38+
console.log(`👤 Created user: ${userId} (${userEmail})`)
39+
40+
// 2. Create Fingerprint
41+
await db.insert(schema.fingerprint).values({
42+
id: fingerprintId,
43+
sig_hash: fingerprintHash, // This hash links the fingerprint to the session/credentials
44+
created_at: new Date(),
45+
})
46+
console.log(`👆 Created fingerprint: ${fingerprintId}`)
47+
48+
// 3. Create Session
49+
await db.insert(schema.session).values({
50+
sessionToken: sessionToken,
51+
userId: userId,
52+
expires: expiresAt,
53+
fingerprint_id: fingerprintId,
54+
})
55+
console.log(`🔑 Created session: ${sessionToken} for user ${userId}`)
56+
57+
// 4. Create credentials.json
58+
const credentials = {
59+
default: {
60+
id: userId,
61+
email: userEmail,
62+
name: userName,
63+
authToken: sessionToken,
64+
fingerprintId: fingerprintId,
65+
fingerprintHash: fingerprintHash,
66+
},
67+
}
68+
69+
// Determine credentials path (mimicking npm-app/src/credentials.ts logic for 'local' env)
70+
const configDir = path.join(os.homedir(), '.config', 'manicode-local')
71+
const credentialsPath = path.join(configDir, 'credentials.json')
72+
73+
await fs.mkdir(configDir, { recursive: true })
74+
await fs.writeFile(credentialsPath, JSON.stringify(credentials, null, 2))
75+
console.log(`📝 Wrote credentials to: ${credentialsPath}`)
76+
77+
console.log('✅ Test user seeding complete!')
78+
} catch (error) {
79+
console.error('❌ Error during test user seeding:', error)
80+
process.exit(1)
81+
}
82+
}
83+
84+
if (require.main === module) {
85+
seedTestUser().catch((err) => {
86+
console.error('Unhandled error in seedTestUser:', err)
87+
process.exit(1)
88+
})
89+
}

evals/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test:manifold": "bun test manifold.test.ts",
88
"test:pglite": "bun test pglite-demo.test.ts",
99
"test:swe-bench": "bun test swe-bench.test.ts",
10-
"test:e2e-cat-app": "bun run e2e-cat-app-script.ts",
10+
"test:e2e-cat-app": "bun run e2e/e2e-cat-app-script.ts",
1111
"typecheck": "tsc --noEmit",
1212
"gen-git-evals": "bun run git-evals/gen-evals.ts",
1313
"run-git-evals": "bun run git-evals/run-git-evals.ts",

0 commit comments

Comments
 (0)