mcp: Add unit tests with node:test runner#11
Conversation
- Adds node:test suites for PexClient (env validation, headers, query serialization, error mapping, retry behavior) and tools/utils (pagination, response/error helpers) - Wires npm test into CI and enables PR validation against main - Makes PexClient retry baseDelay injectable so retry tests don't spend real wall-clock time on backoff Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Code reviewLGTM overall — tests are well-organized, fast (~345ms locally, 28/28 pass), the build & typecheck pass, the Notes & suggestions1. The failing Recommend addressing in a separate follow-up PR (e.g. 2.
Worth updating in this PR so future agents have correct guidance — describe the 3. Optional follow-up coverage (non-blocking):
4. Tiny nit on function stubFetch(handler: FetchHandler): void {
globalThis.fetch = ((url: string, init: RequestInit) =>
handler(url, init)) as typeof fetch;
}The real Security / backward compat / performance:
Devin session: https://app.devin.ai/sessions/743e380c4b1544619fe242606d32a40f |
Upgrades the SDK from ^1.12.1 to ^1.29.0 and runs npm audit fix to pull patched versions of fast-uri, hono, @hono/node-server, ip-address, and express-rate-limit. Resolves 1 high + 4 moderate advisories that were failing the Security audit CI step. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Re-review of 445661dLooks good. The new commit bumps Verification:
Scope: Still open from prior review (all non-blocking, your call whether to roll into this PR):
LGTM as-is. Ready to come out of draft / merge whenever. Devin session: https://app.devin.ai/sessions/743e380c4b1544619fe242606d32a40f |
- Update AGENTS.md to document the test runner and conventions; remove the stale "no tests yet" guidance - Add coverage for 504 retry, network-error retry, request-timeout mapping (DOMException TimeoutError → PexClientError status 0), and paginateArray with a page past totalPages - Widen the stubFetch handler signature to (RequestInfo | URL, init?) to match the real fetch signature Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
node:testrunner (no new dev dependencies) coveringPexClientandtools/utils.PexClienttests cover constructor env validation, auth header, query-param serialization (incl. array join), JSON vs text response handling, error message mapping (401/403/404/429/500), retry behavior on 502/503, and no-retry on 4xx.tools/utilstests coverpaginateArray(clamping, edge cases),paginateNestedArray, and thetoolResponse/toolErrorhelpers.npm testinto the CI pipeline and enables PR validation againstmain(waspr: none).PexClientretrybaseDelayinjectable so retry tests pass0and the suite stays fast (~145ms total instead of ~3s of real backoff).Generated with Claude Code - claude-opus-4-7