Skip to content

Commit 43aa83d

Browse files
Fix flaky Playwright CI startup
1 parent 222c9bf commit 43aa83d

2 files changed

Lines changed: 97 additions & 30 deletions

File tree

.github/workflows/ci.yml

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ jobs:
5454

5555
web-e2e:
5656
runs-on: ubuntu-latest
57-
env:
58-
WMG_E2E_PYTHON: python
5957
steps:
6058
- uses: actions/checkout@v4
6159

@@ -83,6 +81,72 @@ jobs:
8381
working-directory: web
8482
run: npx playwright install --with-deps chromium
8583

84+
- name: Start API server
85+
run: |
86+
mkdir -p .tmp
87+
WMG_DB_URL=sqlite:///./.tmp/e2e.db \
88+
WMG_STORAGE_DIR=./.tmp/e2e-storage \
89+
WMG_UPLOAD_TOKEN=e2e-token \
90+
WMG_AUTO_MIGRATE=true \
91+
WMG_ENABLE_METRICS=false \
92+
WMG_SEED_DEMO_DATA=true \
93+
python -m uvicorn worldmodel_server.main:app --host 127.0.0.1 --port 8100 > .tmp/e2e-api.log 2>&1 &
94+
echo $! > .tmp/e2e-api.pid
95+
96+
- name: Start web server
97+
run: |
98+
mkdir -p .tmp
99+
cd web
100+
INTERNAL_API_BASE=http://127.0.0.1:8100 \
101+
NEXT_PUBLIC_API_BASE=http://127.0.0.1:8100 \
102+
npm run dev -- --hostname 127.0.0.1 --port 3100 > ../.tmp/e2e-web.log 2>&1 &
103+
echo $! > ../.tmp/e2e-web.pid
104+
105+
- name: Wait for local services
106+
run: |
107+
python - <<'PY'
108+
import sys
109+
import time
110+
from urllib.request import urlopen
111+
112+
targets = [
113+
"http://127.0.0.1:8100/healthz",
114+
"http://127.0.0.1:3100",
115+
]
116+
deadline = time.time() + 120
117+
pending = set(targets)
118+
119+
while pending and time.time() < deadline:
120+
for target in list(pending):
121+
try:
122+
with urlopen(target, timeout=2) as response:
123+
if response.status < 500:
124+
pending.remove(target)
125+
except Exception:
126+
pass
127+
if pending:
128+
time.sleep(2)
129+
130+
if pending:
131+
raise SystemExit(f"Services did not start in time: {sorted(pending)}")
132+
PY
133+
86134
- name: Run Playwright smoke tests
87135
working-directory: web
136+
env:
137+
PLAYWRIGHT_DISABLE_WEBSERVER: "1"
88138
run: npm run test:e2e
139+
140+
- name: Dump server logs on failure
141+
if: failure()
142+
run: |
143+
echo "===== API LOG ====="
144+
cat .tmp/e2e-api.log || true
145+
echo "===== WEB LOG ====="
146+
cat .tmp/e2e-web.log || true
147+
148+
- name: Stop background services
149+
if: always()
150+
run: |
151+
kill $(cat .tmp/e2e-api.pid) 2>/dev/null || true
152+
kill $(cat .tmp/e2e-web.pid) 2>/dev/null || true

web/playwright.config.ts

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { defineConfig } from "@playwright/test";
44

55
const repoRoot = path.resolve(__dirname, "..");
66
const pythonExecutable = process.env.WMG_E2E_PYTHON ?? ".venv/bin/python";
7+
const useManagedWebServers = process.env.PLAYWRIGHT_DISABLE_WEBSERVER !== "1";
78

89
export default defineConfig({
910
testDir: "./tests/e2e",
@@ -15,32 +16,34 @@ export default defineConfig({
1516
baseURL: "http://127.0.0.1:3100",
1617
trace: "on-first-retry"
1718
},
18-
webServer: [
19-
{
20-
command: `${pythonExecutable} -m uvicorn worldmodel_server.main:app --host 127.0.0.1 --port 8100`,
21-
cwd: repoRoot,
22-
env: {
23-
WMG_DB_URL: "sqlite:///./.tmp/e2e.db",
24-
WMG_STORAGE_DIR: "./.tmp/e2e-storage",
25-
WMG_UPLOAD_TOKEN: "e2e-token",
26-
WMG_AUTO_MIGRATE: "true",
27-
WMG_ENABLE_METRICS: "false",
28-
WMG_SEED_DEMO_DATA: "true"
29-
},
30-
url: "http://127.0.0.1:8100/healthz",
31-
reuseExistingServer: !process.env.CI,
32-
timeout: 120_000
33-
},
34-
{
35-
command: "npm run dev -- --hostname 127.0.0.1 --port 3100",
36-
cwd: path.resolve(repoRoot, "web"),
37-
env: {
38-
INTERNAL_API_BASE: "http://127.0.0.1:8100",
39-
NEXT_PUBLIC_API_BASE: "http://127.0.0.1:8100"
40-
},
41-
url: "http://127.0.0.1:3100",
42-
reuseExistingServer: !process.env.CI,
43-
timeout: 120_000
44-
}
45-
]
19+
webServer: useManagedWebServers
20+
? [
21+
{
22+
command: `${pythonExecutable} -m uvicorn worldmodel_server.main:app --host 127.0.0.1 --port 8100`,
23+
cwd: repoRoot,
24+
env: {
25+
WMG_DB_URL: "sqlite:///./.tmp/e2e.db",
26+
WMG_STORAGE_DIR: "./.tmp/e2e-storage",
27+
WMG_UPLOAD_TOKEN: "e2e-token",
28+
WMG_AUTO_MIGRATE: "true",
29+
WMG_ENABLE_METRICS: "false",
30+
WMG_SEED_DEMO_DATA: "true"
31+
},
32+
url: "http://127.0.0.1:8100/healthz",
33+
reuseExistingServer: !process.env.CI,
34+
timeout: 120_000
35+
},
36+
{
37+
command: "npm run dev -- --hostname 127.0.0.1 --port 3100",
38+
cwd: path.resolve(repoRoot, "web"),
39+
env: {
40+
INTERNAL_API_BASE: "http://127.0.0.1:8100",
41+
NEXT_PUBLIC_API_BASE: "http://127.0.0.1:8100"
42+
},
43+
url: "http://127.0.0.1:3100",
44+
reuseExistingServer: !process.env.CI,
45+
timeout: 120_000
46+
}
47+
]
48+
: undefined
4649
});

0 commit comments

Comments
 (0)