@@ -53,17 +53,89 @@ jobs:
5353 pip install -r cueapi-core/requirements.txt
5454 pip install -e .
5555
56- - name : Run tests
56+ - name : Initialize test DB schema (model-driven, matches cueapi-core/tests/conftest.py)
57+ working-directory : cueapi-core
58+ env :
59+ DATABASE_URL : postgresql+asyncpg://runner@localhost:5432/cueapi_test
60+ REDIS_URL : redis://localhost:6379
61+ SESSION_SECRET : test-session-secret-32-chars-minimum!!
62+ ENV : test
63+ RESEND_API_KEY : " "
64+ run : |
65+ python <<'PY'
66+ import asyncio
67+ from sqlalchemy.ext.asyncio import create_async_engine
68+ from app.config import settings
69+ from app.database import Base
70+ # Import all models so Base.metadata sees them (mirrors tests/conftest.py).
71+ from app.models import ( # noqa: F401
72+ Alert, Cue, DispatchOutbox, Execution, UsageMonthly, User, Worker, DeviceCode,
73+ Agent, Message, UsageMessagesMonthly,
74+ )
75+
76+ async def _init():
77+ engine = create_async_engine(settings.DATABASE_URL)
78+ async with engine.begin() as conn:
79+ await conn.run_sync(Base.metadata.create_all)
80+ await engine.dispose()
81+
82+ asyncio.run(_init())
83+ print("Schema initialized via Base.metadata.create_all")
84+ PY
85+
86+ - name : Start cueapi-core API in background
87+ working-directory : cueapi-core
5788 env :
5889 DATABASE_URL : postgresql+asyncpg://runner@localhost:5432/cueapi_test
5990 REDIS_URL : redis://localhost:6379
6091 SESSION_SECRET : test-session-secret-32-chars-minimum!!
6192 ENV : test
6293 RESEND_API_KEY : " "
63- CUEAPI_STAGING_URL : https://api-staging-e962.up.railway.app
64- CUEAPI_STAGING_API_KEY : ${{ secrets.ARGUS_STAGING_KEY }}
94+ ALLOW_REGISTER : " true"
95+ BASE_URL : http://localhost:8000
96+ run : |
97+ nohup python -m uvicorn app.main:app --host 127.0.0.1 --port 8000 \
98+ > /tmp/uvicorn.log 2>&1 &
99+ echo $! > /tmp/uvicorn.pid
100+
101+ - name : Wait for API health
102+ run : |
103+ for i in $(seq 1 30); do
104+ if curl -sf http://127.0.0.1:8000/health > /dev/null; then
105+ echo "API ready after ${i}s"
106+ exit 0
107+ fi
108+ sleep 1
109+ done
110+ echo "API failed to start within 30s"
111+ cat /tmp/uvicorn.log
112+ exit 1
113+
114+ - name : Register test user and capture API key
115+ id : register_user
116+ run : |
117+ EMAIL="ci-sdk-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}@example.com"
118+ RESP=$(curl -sf -X POST http://127.0.0.1:8000/v1/auth/register \
119+ -H "Content-Type: application/json" \
120+ -d "{\"email\":\"${EMAIL}\"}")
121+ KEY=$(printf '%s' "$RESP" | python -c 'import sys,json;print(json.load(sys.stdin)["api_key"])')
122+ if [ -z "$KEY" ]; then
123+ echo "Registration failed; response: $RESP"
124+ exit 1
125+ fi
126+ echo "::add-mask::$KEY"
127+ echo "api_key=$KEY" >> "$GITHUB_OUTPUT"
128+
129+ - name : Run tests
130+ env :
131+ CUEAPI_STAGING_URL : http://127.0.0.1:8000
132+ CUEAPI_STAGING_API_KEY : ${{ steps.register_user.outputs.api_key }}
65133 run : pytest tests/ -v --tb=short
66134
135+ - name : Dump uvicorn log on failure
136+ if : failure()
137+ run : cat /tmp/uvicorn.log || true
138+
67139 auto-merge :
68140 needs : test
69141 runs-on : ubuntu-latest
0 commit comments