-
Notifications
You must be signed in to change notification settings - Fork 0
293 lines (267 loc) · 10.3 KB
/
test_evaluation_function.yml
File metadata and controls
293 lines (267 loc) · 10.3 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
name: Endpoint Validation Test
on:
workflow_call:
inputs:
eval_function:
description: 'Evaluation Function Name'
required: true
type: string
sql_limit:
description: 'Max number of records to fetch'
required: false
type: string
default: 1000
request_delay:
description: 'Delay (seconds) between dispatching requests'
required: false
type: string
default: '0'
max_concurrency:
description: 'Max concurrent requests (lower for GPT-backed functions)'
required: false
type: string
default: '5'
seed:
description: 'Random seed for reproducible sampling (float in [-1.0, 1.0]). Leave blank to auto-generate.'
required: false
type: string
default: ''
pass_threshold:
description: 'Minimum pass rate % (0-100) required for the test to succeed. Default 100 means any error fails the run.'
required: false
type: string
default: '100'
ids_to_exclude:
description: 'Comma-separated submission UUIDs to add to the exclusion list before testing.'
required: false
type: string
default: ''
secrets:
TEST_API_ENDPOINT:
description: 'API Endpoint URL to test'
required: false
DB_USER:
required: false
DB_PASSWORD:
required: false
DB_HOST:
required: false
DB_PORT:
required: false
DB_NAME:
required: false
GCP_SERVICE_ACCOUNT_KEY:
required: false
GCP_PROJECT_ID:
required: false
workflow_dispatch:
inputs:
eval_function:
description: 'Evaluation Function Name'
required: true
type: string
endpoint:
description: 'API Endpoint URL to test'
required: true
type: string
ids_to_exclude:
description: 'Comma-separated submission UUIDs to add to the exclusion list before testing.'
required: false
type: string
default: ''
sql_limit:
description: 'Max number of records to fetch'
required: false
type: string
default: '1000'
request_delay:
description: 'Delay (seconds) between dispatching requests'
required: false
type: string
default: '0'
max_concurrency:
description: 'Max concurrent requests'
required: false
type: string
default: '5'
seed:
description: 'Random seed for reproducible sampling (float in [-1.0, 1.0]). Leave blank to auto-generate.'
required: false
type: string
default: ''
pass_threshold:
description: 'Minimum pass rate % (0-100) required for the test to succeed.'
required: false
type: string
default: '100'
jobs:
run_test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
repository: 'lambda-feedback/Database-Testing'
ref: main
token: ${{ github.token }}
path: Database-Testing
- name: Set up Python Environment
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Dependencies
working-directory: ./Database-Testing
run: |
set -euo pipefail
pip install -r requirements.txt
- name: Authenticate to GCP
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
- name: Add exclusions to Firestore
if: inputs.ids_to_exclude != ''
working-directory: ./Database-Testing
env:
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GOOGLE_CREDENTIALS_JSON: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
run: |
set -euo pipefail
IDS=$(echo "${{ inputs.ids_to_exclude }}" | tr ',' ' ')
python3 manage_exclusions.py \
--eval_function_name "${{ inputs.eval_function }}" \
add --ids $IDS
- name: Run Evaluation Function Against Database
id: run_script
working-directory: ./Database-Testing
env:
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GOOGLE_CREDENTIALS_JSON: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
run: |
set -euo pipefail
# Run the argparse-enabled script and capture exit code
SEED_ARG=""
if [ -n "${{ inputs.seed }}" ]; then
SEED_ARG="--seed ${{ inputs.seed }}"
fi
if ! python3 test_evaluation_function.py \
--endpoint "${{ secrets.TEST_API_ENDPOINT || inputs.endpoint }}" \
--eval_function_name "${{ inputs.eval_function }}" \
--sql_limit "${{ inputs.sql_limit }}" \
--grade_params_json "" \
--request_delay "${{ inputs.request_delay }}" \
--max_concurrency "${{ inputs.max_concurrency }}" \
$SEED_ARG; then
echo "::error::Python script failed with non-zero exit code"
exit 1
fi
# Verify report_data.json exists (needed for summary)
if [ ! -f report_data.json ]; then
echo "::error::report_data.json not found!"
exit 1
fi
REPORT_DATA="$(cat report_data.json)"
# Check for error status in the JSON response
STATUS="$(echo "$REPORT_DATA" | jq -r '.status // "unknown"')"
if [ "$STATUS" = "failed" ]; then
ERROR_MSG="$(echo "$REPORT_DATA" | jq -r '.error // "Unknown error"')"
echo "::error::Script returned failed status: ${ERROR_MSG}"
exit 1
fi
# Check pass rate against configurable threshold
PASSES="$(echo "$REPORT_DATA" | jq -r '.pass_count // 0')"
TESTED="$(echo "$REPORT_DATA" | jq -r '.tested_count // 0')"
ERRORS="$(echo "$REPORT_DATA" | jq -r '.number_of_errors // 0')"
THRESHOLD="${{ inputs.pass_threshold }}"
if [ "$TESTED" -gt 0 ]; then
PASS_RATE="$(echo "scale=4; $PASSES / $TESTED * 100" | bc -l)"
else
PASS_RATE="0"
fi
if [ "$(echo "$PASS_RATE < $THRESHOLD" | bc -l)" = "1" ]; then
echo "::error file=test_evaluation_function.py::Pass rate ${PASS_RATE}% is below the ${THRESHOLD}% threshold. ${ERRORS} test(s) failed."
exit 1
fi
- name: Create Job Summary Report
if: always() # Run even if the previous step failed/found errors
working-directory: ./Database-Testing
run: |
set -euo pipefail
if [ ! -f report_data.json ]; then
echo "## Evaluation Function Report" >> "$GITHUB_STEP_SUMMARY"
echo "**Status:** Failed - No report data generated" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
REPORT_DATA="$(cat report_data.json)"
# Check if this is an error response
STATUS="$(echo "$REPORT_DATA" | jq -r '.status // "unknown"')"
if [ "$STATUS" = "failed" ]; then
ERROR_MSG="$(echo "$REPORT_DATA" | jq -r '.error // "Unknown error"')"
{
echo "## Endpoint Validation Report"
echo "---"
echo "**Status:** Failed"
echo "**Error:** ${ERROR_MSG}"
echo "---"
} >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
PASSES="$(echo "$REPORT_DATA" | jq -r '.pass_count // 0')"
TOTAL="$(echo "$REPORT_DATA" | jq -r '.total_count // 0')"
TESTED="$(echo "$REPORT_DATA" | jq -r '.tested_count // 0')"
ERRORS="$(echo "$REPORT_DATA" | jq -r '.number_of_errors // 0')"
FEEDBACK_WARNINGS="$(echo "$REPORT_DATA" | jq -r '.number_of_feedback_warnings // 0')"
PARSING_WARNINGS="$(echo "$REPORT_DATA" | jq -r '.number_of_parsing_warnings // 0')"
FIRESTORE_LINK="$(echo "$REPORT_DATA" | jq -r '.firestore_link // ""')"
FIRESTORE_DOC_ID="$(echo "$REPORT_DATA" | jq -r '.firestore_doc_id // ""')"
SEED="$(echo "$REPORT_DATA" | jq -r '.seed // "N/A"')"
THRESHOLD="${{ inputs.pass_threshold }}"
if [ "$TESTED" -gt 0 ]; then
PASS_RATE="$(echo "scale=2; $PASSES / $TESTED * 100" | bc -l)"
else
PASS_RATE="0"
fi
STATUS_EMOJI="[PASS]"
if [ "$(echo "$PASS_RATE < $THRESHOLD" | bc -l)" = "1" ]; then
STATUS_EMOJI="[FAIL]"
fi
{
echo "## ${STATUS_EMOJI} Endpoint Validation Report"
echo "---"
echo "**Endpoint:** ${{ secrets.TEST_API_ENDPOINT || inputs.endpoint }}"
echo "**Evaluation Function:** ${{ inputs.eval_function }}"
echo ""
echo "| Metric | Value |"
echo "| :--- | :--- |"
echo "| **Fetched from DB** | ${TOTAL} |"
echo "| **Actually Tested** | ${TESTED} |"
echo "| **Passed** | ${PASSES} |"
echo "| **Failed** | **${ERRORS}** |"
echo "| **Parsing Warnings** | ${PARSING_WARNINGS} |"
echo "| **Feedback Warnings** | ${FEEDBACK_WARNINGS} |"
echo "| **Pass Rate** | ${PASS_RATE}% |"
echo "| **Pass Threshold** | ${THRESHOLD}% |"
echo "| **Seed** | \`${SEED}\` |"
echo "---"
# Add Firestore link if available
if [ -n "$FIRESTORE_LINK" ]; then
echo ""
echo "### Detailed Results"
echo ""
echo "**[View full results in Firestore](${FIRESTORE_LINK})**"
echo ""
echo "<details>"
echo "<summary>Firestore Document Details</summary>"
echo ""
echo "- **Document ID:** \`${FIRESTORE_DOC_ID}\`"
echo "- **Collection:** \`test-results\`"
echo "- **Project:** ${{ secrets.GCP_PROJECT_ID }}"
echo ""
echo "</details>"
fi
echo "---"
} >> "$GITHUB_STEP_SUMMARY"