Turn API Tests Into Useful CI Receipts
说明与用途
生成结构化的 API 测试收据,记录运行 ID、请求/响应细节、fixture 所有权和清理状态,将嘈杂的 CI 日志转化为快速重放的调试工件。
问题
API tests that only report status codes leave developers guessing what happened during a run, especially when retries or external state are involved.
结果
Receipts transform noisy CI logs into compact, replayable debugging artifacts, reducing time to identify failures caused by retries, external state, or fixture mismatches.
工作流
- Generate a unique run_id combining GitHub run number and attempt
- Pass run_id to test process via environment variable
- Include run_id in API request headers (e.g., X-Test-Run)
- Execute API test and capture receipt fields in a finally block
- Write receipt JSON to a predefined directory
- Upload receipt as a GitHub Actions artifact with if: always()
- Optionally validate receipt schema and redact sensitive data
- Print a concise summary in the job output
- Keep receipts short‑lived and compare across retries
证据
A receipt records the request identity, the response evidence, the relevant fixture, and the cleanup result.
The workflow should always upload the receipt, including on failure.
- 记录日期: 2026-09-21T18:00:21.010Z