record-api-calls-for-replay
Use when building tests against a live API. Record real request/response pairs once, then replay them offline so tests are deterministic and need no network.
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- record-api-calls-for-replay
- description
- Use when building tests against a live API. Record real request/response pairs once, then replay them offline so tests are deterministic and need no network.
02 资源文件 3
- 许可证LICENSE1.0 KB
- 参考文档SOURCE.md353 B
- 参考文档TRUST.auto.yaml2.2 KB
03 SKILL.md 正文
Record API calls for replay
Tests that hit a live API are slow, flaky, and rate-limited. Record the exchanges once, scrub the secrets, and replay them so the suite is deterministic and offline.
Procedure
- Record with a cassette library (
vcrpyfor Python,nockfor Node,VCRfor Ruby) or a mitm proxy:--record-mode=oncefirst run,noneafterwards. - Filter secrets before writing:
def before_record(r): r["headers"].pop("Authorization", None) return r - Commit cassettes so CI runs offline and deterministically.
- Normalise volatile values (timestamps, ids, request-ids) with match rules so replays are not brittle.
- Match on method plus path plus query — not full headers — so a header tweak does not break replay.
- Re-record when the API actually changes; a stale cassette hides a live breaking change.
- Record the error responses too: capture a 429 and a 500 deliberately to exercise the retry path.
Pitfalls
- Cassettes containing live keys leak credentials into version control.
- Full-header matching breaks on changing date/user-agent; match narrowly.
- A one-time cassette validates code against a shape the live API no longer serves.
- Exact-body matching fails when the request carries a random idempotency key; scrub it in the matcher.
- Recording a whole large run bloats the repo; record only the fixtures the tests use.
Verification
pytest -q --record-mode=none # passes with the network disabled
Report: "34 cassettes replay offline; 2 recorded 429s exercise the retry path."
04 同仓库更多 Skills
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
mexc-spot-websocket
MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.
mexc-spot-rest
MEXC Spot REST workflows for public data, signed account requests, orders, wallet/admin actions, and secure signing without exposing API keys.
mexc-futures-websocket
MEXC Futures WebSocket workflows for public streams, private account/order/position streams, ping/pong, subscriptions, and depth maintenance.
0xklen-version-and-refresh-sanctions-lists
暂无简介
verify-tests-cover-changed-lines
Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.