fix: 修复E2E测试基础设施

- docker-compose.e2e.yml: 使用简化的Dockerfile.e2e替代主Dockerfile
- e2e/Dockerfile.e2e: 新增E2E专用镜像(跳过前端构建,安装git/ripgrep/curl)
- e2e/seed.sh: 修复mkdir -p src顺序(在写入文件之前创建目录)
- e2e/test.sh: 修复Test 5需要admin JWT认证访问review runs API
This commit is contained in:
accelerator
2026-03-01 14:14:13 +08:00
parent 5c0b4808ee
commit e91ebdc974
4 changed files with 25 additions and 5 deletions

View File

@@ -37,7 +37,7 @@ services:
assistant:
build:
context: .
dockerfile: Dockerfile
dockerfile: e2e/Dockerfile.e2e
container_name: e2e-assistant
depends_on:
gitea:

16
e2e/Dockerfile.e2e Normal file
View File

@@ -0,0 +1,16 @@
# E2E 测试用简化 Dockerfile跳过 frontend 构建)
FROM oven/bun:1
WORKDIR /app
RUN apt-get update && apt-get install -y git ripgrep curl && rm -rf /var/lib/apt/lists/*
COPY package.json bun.lock* bun.lockb* ./
RUN bun install --no-frozen-lockfile
COPY src ./src
COPY tsconfig.json .
EXPOSE 3000
CMD ["bun", "run", "start"]

View File

@@ -70,6 +70,7 @@ pushd "${CLONE_DIR}/repo" > /dev/null
git config user.email "e2e@test.local"
git config user.name "E2E Bot"
mkdir -p src
cat > src/auth.ts << 'TSEOF'
export function authenticate(token: string): boolean {
// 正确的认证实现
@@ -84,7 +85,6 @@ function verifyToken(token: string): boolean {
}
TSEOF
mkdir -p src
git add -A
git commit -m "initial: add auth module" --allow-empty 2>/dev/null || true
git push origin main 2>/dev/null || true

View File

@@ -106,8 +106,12 @@ fi
# ─── 测试 5: Review Run 状态检查 ───
echo "[TEST 5] Review Run 状态"
RUNS=$(curl -sf "${ASSISTANT_URL}/admin/api/review/runs" 2>/dev/null || echo "[]")
RUN_COUNT=$(echo "${RUNS}" | python3 -c "import sys,json; d=json.load(sys.stdin); print(len(d) if isinstance(d,list) else len(d.get('runs',[])))" 2>/dev/null || echo "0")
ADMIN_JWT=$(curl -sf -X POST "${ASSISTANT_URL}/admin/api/login" \
-H "Content-Type: application/json" \
-d '{"password":"password"}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('token',''))" 2>/dev/null || echo "")
RUNS=$(curl -sf "${ASSISTANT_URL}/admin/api/review/runs" \
-H "Authorization: Bearer ${ADMIN_JWT}" 2>/dev/null || echo "[]")
RUN_COUNT=$(echo "${RUNS}" | python3 -c "import sys,json; d=json.load(sys.stdin); print(len(d.get('data',d if isinstance(d,list) else [])))" 2>/dev/null || echo "0")
if [ "${RUN_COUNT}" -gt "0" ]; then
echo " ✅ PASS: 发现 ${RUN_COUNT} 个 review run(s)"
@@ -116,7 +120,7 @@ if [ "${RUN_COUNT}" -gt "0" ]; then
echo "${RUNS}" | python3 -c "
import sys, json
data = json.load(sys.stdin)
runs = data if isinstance(data, list) else data.get('runs', [])
runs = data.get('data', data if isinstance(data, list) else data.get('runs', []))
for r in runs[:3]:
print(f\" - {r.get('id','?')[:8]}... status={r.get('status','?')} attempts={r.get('attempts','?')}\")
" 2>/dev/null || true