forked from bai/curriculum-project-hub
ci(hub): 补齐 Hub 检查和健康 smoke
This commit is contained in:
@@ -13,6 +13,20 @@ on:
|
||||
jobs:
|
||||
hub-check:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
env:
|
||||
POSTGRES_USER: paradigm
|
||||
POSTGRES_PASSWORD: paradigm
|
||||
POSTGRES_DB: cph_hub_test
|
||||
ports:
|
||||
- 5432:5432
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U paradigm -d cph_hub_test"
|
||||
--health-interval 5s
|
||||
--health-timeout 5s
|
||||
--health-retries 20
|
||||
defaults:
|
||||
run:
|
||||
working-directory: hub
|
||||
@@ -29,6 +43,29 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Wait for Postgres
|
||||
run: |
|
||||
node <<'NODE'
|
||||
const net = require("node:net");
|
||||
const deadline = Date.now() + 60000;
|
||||
function tryConnect() {
|
||||
const socket = net.createConnection({ host: "127.0.0.1", port: 5432 });
|
||||
socket.once("connect", () => {
|
||||
socket.end();
|
||||
process.exit(0);
|
||||
});
|
||||
socket.once("error", () => {
|
||||
socket.destroy();
|
||||
if (Date.now() > deadline) {
|
||||
console.error("Postgres did not become reachable at 127.0.0.1:5432");
|
||||
process.exit(1);
|
||||
}
|
||||
setTimeout(tryConnect, 1000);
|
||||
});
|
||||
}
|
||||
tryConnect();
|
||||
NODE
|
||||
|
||||
# Prisma client must be generated before tsc can check imports from
|
||||
# @prisma/client. Stub DATABASE_URL so prisma generate works.
|
||||
- name: Generate Prisma client
|
||||
@@ -37,6 +74,9 @@ jobs:
|
||||
- name: Type-check
|
||||
run: npx tsc -p tsconfig.json --noEmit
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Validate Prisma schema
|
||||
run: DATABASE_URL="postgresql://stub:stub@127.0.0.1:5432/stub" npx prisma validate --schema prisma/schema.prisma
|
||||
|
||||
@@ -57,25 +97,36 @@ jobs:
|
||||
env:
|
||||
DATABASE_URL: postgresql://paradigm:paradigm@127.0.0.1:5432/cph_hub_test
|
||||
|
||||
# Real-model tests are skipped automatically when OPENROUTER_API_KEY is
|
||||
# not set. When the secret is available (e.g. on the main branch), they
|
||||
# run against live OpenRouter — verifying the tool-calls loop end-to-end.
|
||||
- name: Smoke health endpoint
|
||||
run: |
|
||||
PORT=8878 \
|
||||
NODE_ENV=production \
|
||||
DATABASE_URL=postgresql://paradigm:paradigm@127.0.0.1:5432/cph_hub_test \
|
||||
ANTHROPIC_AUTH_TOKEN=smoke \
|
||||
FEISHU_APP_ID=cli_smoke \
|
||||
FEISHU_APP_SECRET=smoke_secret \
|
||||
FEISHU_BOT_OPEN_ID=ou_smoke \
|
||||
HUB_FEISHU_LISTENER_ENABLED=false \
|
||||
npm start &
|
||||
pid=$!
|
||||
trap 'kill "$pid" 2>/dev/null || true' EXIT
|
||||
for attempt in $(seq 1 30); do
|
||||
if curl --fail --silent "http://127.0.0.1:8878/api/healthz" >/dev/null; then
|
||||
exit 0
|
||||
fi
|
||||
if ! kill -0 "$pid" 2>/dev/null; then
|
||||
echo "hub server exited before health check passed"
|
||||
wait "$pid"
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
curl --fail --silent --show-error "http://127.0.0.1:8878/api/healthz" >/dev/null
|
||||
|
||||
# Real-model tests are opt-in: set RUN_REAL_MODEL_TESTS=true and provide
|
||||
# OPENROUTER_API_KEY when a branch should hit live OpenRouter.
|
||||
- name: Run real-model integration tests (optional, needs secret)
|
||||
run: npx vitest run test/integration/real-model.test.ts
|
||||
env:
|
||||
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
env:
|
||||
POSTGRES_USER: paradigm
|
||||
POSTGRES_PASSWORD: paradigm
|
||||
POSTGRES_DB: cph_hub_test
|
||||
ports:
|
||||
- 5432:5432
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
RUN_REAL_MODEL_TESTS: ${{ vars.RUN_REAL_MODEL_TESTS }}
|
||||
|
||||
Reference in New Issue
Block a user