-
Notifications
You must be signed in to change notification settings - Fork 141
187 lines (167 loc) · 7.69 KB
/
Copy pathtest_api.yml
File metadata and controls
187 lines (167 loc) · 7.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Copyright(C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT
# This workflow tests the GAIA OpenAI-compatible API server functionality
# Tests include: Chat completions, streaming SSE, model listing, error handling
name: API Server Tests
on:
workflow_call:
push:
branches: ["main"]
paths:
- 'src/gaia/version.py'
- '.github/actions/install-lemonade/**'
- 'src/gaia/api/**'
- 'src/gaia/agents/base/**'
- 'src/gaia/llm/**'
- 'hub/agents/routing/python/**'
- 'hub/agents/code/python/**'
- 'tests/test_api.py'
- 'setup.py'
- '.github/workflows/test_api.yml'
pull_request:
branches: ["main"]
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'src/gaia/version.py'
- '.github/actions/install-lemonade/**'
- 'src/gaia/api/**'
- 'src/gaia/agents/base/**'
- 'src/gaia/llm/**'
- 'hub/agents/routing/python/**'
- 'hub/agents/code/python/**'
- 'tests/test_api.py'
- 'setup.py'
- '.github/workflows/test_api.yml'
merge_group:
workflow_dispatch:
# Cancel in-progress runs when a new run is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
test-api:
name: API Tests
runs-on:
- self-hosted
- Windows
- ${{ contains(github.event.pull_request.labels.*.name, 'stx-test') && 'stx-test' || 'stx' }}
timeout-minutes: 30
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'ready_for_ci')
steps:
- uses: actions/checkout@v7
- name: Setup Python environment
uses: ./.github/actions/setup-venv
with:
python-version: '3.12'
install-package: '.[dev,api]'
- name: Install additional test dependencies
shell: powershell
run: |
uv pip install pytest pytest-timeout requests --python .venv\Scripts\python.exe
# The 'gaia-code' API model routes through RoutingAgent, which now
# ships as the standalone gaia-agent-routing wheel (#1102). Install
# both local hub packages (routing first, since gaia-agent-code
# depends on it and it isn't on PyPI) so the gaia-code streaming
# tests exercise the real agent instead of the missing-wheel error.
uv pip install -e hub/agents/routing/python --python .venv\Scripts\python.exe
uv pip install -e hub/agents/code/python --python .venv\Scripts\python.exe
# The email REST router only mounts when gaia-agent-email is
# importable; without it every /v1/email test in tests/test_api.py
# 404s (red on main since the email agent moved to a hub wheel).
uv pip install -e hub/agents/email/python --python .venv\Scripts\python.exe
- name: Install Lemonade Server
uses: ./.github/actions/install-lemonade
- name: Start Lemonade + API server and run API tests
shell: powershell
run: |
# Set console to UTF-8 for Unicode support
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$env:PYTHONIOENCODING = "utf-8"
$env:PYTHONUTF8 = "1"
chcp 65001 | Out-Null
try {
# Start Lemonade via the shared launcher (server + tests run in ONE
# step so the detached server survives for the test run). It launches
# LemonadeServer.exe --port directly (the `lemonade-server serve`
# shim was removed in Lemonade v10.5), captures stdout/stderr to
# logs, waits for health (dumping the logs on failure), and sets
# LEMONADE_PROCESS_ID for cleanup.
.\installer\scripts\start-lemonade.ps1 -Port 13305 -NoModel
if ($LASTEXITCODE -ne 0) { throw "Lemonade server failed to start" }
# Pull + load + verify the LLM via GAIA's LemonadeClient so CI
# validates our interface to Lemonade (incl. the model-load retry),
# not raw REST.
Write-Host "`n=== Pull + load + verify LLM via LemonadeClient ==="
uv run python tests/ci_lemonade_check.py --model Qwen3-0.6B-GGUF --chat
if ($LASTEXITCODE -ne 0) {
Write-Host "=== Server stdout (last 100 lines) ==="
Get-Content lemonade-server-stdout.log -Tail 100 -ErrorAction SilentlyContinue
Write-Host "=== Server stderr (last 100 lines) ==="
Get-Content lemonade-server-stderr.log -Tail 100 -ErrorAction SilentlyContinue
throw "LLM setup/verify via LemonadeClient failed"
}
# Start API server using gaia CLI (runs on default port 8080)
Write-Host "`n=== Starting GAIA API Server ==="
$apiJob = Start-Job -ScriptBlock {
Set-Location $using:PWD
& .\.venv\Scripts\Activate.ps1
$env:AGENT_ROUTING_MODEL = "Qwen3-0.6B-GGUF"
& gaia api start 2>&1
}
Write-Host "Started API server job with ID: $($apiJob.Id)"
$env:API_JOB_ID = $apiJob.Id
# Wait for API server to start
Write-Host "Waiting for API server to start..."
$maxWaitTime = 30
$waitTime = 0
$apiReady = $false
while ($waitTime -lt $maxWaitTime -and -not $apiReady) {
Start-Sleep -Seconds 2
$waitTime += 2
try {
$response = Invoke-RestMethod -Uri "http://localhost:8080/health" -Method GET -TimeoutSec 5
Write-Host "[OK] API server is running and healthy"
$apiReady = $true
} catch {
Write-Host "Waiting for API server... ($waitTime/$maxWaitTime seconds)"
}
}
if (-not $apiReady) {
Write-Host "[ERROR] API server failed to start after $maxWaitTime seconds"
if ($env:API_JOB_ID) {
Write-Host "=== API server job output ==="
Receive-Job -Id $env:API_JOB_ID -ErrorAction SilentlyContinue
}
throw "API server failed to start"
}
# Run tests in same session while servers are running
Write-Host "`n=== Running API Integration Tests ==="
$env:CI = "true"
uv run pytest tests/test_api.py -v --tb=short --capture=no
if ($LASTEXITCODE -ne 0) { throw "Tests failed with exit code $LASTEXITCODE" }
} finally {
# Always cleanup both servers (same-session vars).
Write-Host "`n=== Stopping Servers ==="
if ($env:API_JOB_ID) {
Stop-Job -Id $env:API_JOB_ID -ErrorAction SilentlyContinue
Remove-Job -Id $env:API_JOB_ID -ErrorAction SilentlyContinue
Write-Host "[OK] API server stopped"
}
if ($env:LEMONADE_PROCESS_ID) {
Stop-Process -Id $env:LEMONADE_PROCESS_ID -Force -ErrorAction SilentlyContinue
Write-Host "[OK] Lemonade server stopped (PID $env:LEMONADE_PROCESS_ID)"
}
}
- name: Upload API Server Logs
if: failure()
uses: actions/upload-artifact@v7
with:
name: api-server-logs
path: |
gaia.api.log
gaia_api.log
*.log