External Service Testing external-service-testing

Build, register, and verify stateful network-boundary emulators for external APIs and services: audit outbound calls, choose vibestack/emulate or vercel-labs/emulate, emulate voice/LLM/image/map services deterministically, verify shapes against real APIs with mandatory secret redaction, and keep tests and CI offline.

Works in Claude, ChatGPT, Codex and more
Our test
—
not tested yet
GitHub stars
20k
elizaos/eliza
Added by
0
members
Updated
Dec 6
commit e932464
Content
1 file
no scripts · 11 KB
License
MIT
free to use

What our test found

Not tested yet. Our model tries every skill on a realistic request and scores the result, the most popular skills first. Until then, the safety checks on the right still apply.

View on GitHub ↗
name: external-service-testing
description: "Build, register, and verify stateful network-boundary emulators for external APIs and services: audit outbound calls, choose vibestack/emulate or vercel-labs/emulate, emulate voice/LLM/image/map services deterministically, verify shapes against real APIs with mandatory secret redaction, and keep tests and CI offline."

External service testing

Run this skill whenever a new external service is added, an outbound API integration changes, or an existing integration lacks a stateful emulator. Read in full once per session.

Real local services (in-process DBs, local workerd, local servers, queues, filesystems) run directly. Fake only services that cost money, cannot be undone, or cannot be run and reset locally — and fake them once at the network boundary, shared by every test (). Never mock your own application code, and never ship emulator code in production bundles.

1. Audit outbound external services

Run the built-in codebase auditor first:

pnpm exec vibestack emulate audit --json

(In this repository, node vibestack/spec.ts emulate audit --json runs the same audit directly from source.)

The auditor scans src/ for outbound https:// and wss:// URLs, *_API_KEY / *_BASE_URL environment bindings, and known external SDK imports (openai, @anthropic-ai/sdk, stripe, @slack/web-api, cartesia, Google Maps, and similar), then cross-references them against emulators/manifest.json (honoring optional ignoreHosts and ignoreDirs allowlists) to flag uncovered services.

Resolve every uncovered external service before running story QA ().

2. Choose the right emulation tier

Pick the lightest tier that models the real wire protocol and stateful behavior:

| Tier | Tooling | Use when | Avoid when | |---|---|---|---| | Tier 0 (default, zero-dep) | vibestack/emulate (createEmulatorServer, SseHub, RequestLog, FaultArmory, /__control/*, namespace isolation) | Custom REST/JSON/SSE/WS APIs, domain backends, LLM/voice/image/map emulators, or when zero extra dependencies and sub-second CI startup matter | A maintained Tier 1 emulator already implements the full SaaS API surface you need | | Tier 1 (standard SaaS & AI) | vercel-labs/emulate (emulate, @emulators/ai, defineEmulator) wrapped via wrapEmulateService from vibestack/emulate | Standard Apache-2.0 built-ins already exist (OpenAI, Anthropic, Gemini, ElevenLabs, Stripe, GitHub, Google, Slack, Resend, Twilio, AWS, Clerk, Linear, Vercel) | The service is bespoke or only 1–2 endpoints are called (prefer Tier 0 over adding a 10+ MB dependency) |

Why `crvouga/mockingbird` is not a default dependency: its runtime plus SQLite WASM base weighs ~31 MB and carries solo-maintainer bus factor. Vibestack adopts its two best ideas natively inside vibestack/emulate instead: per-request namespace isolation (x-vibestack-namespace header or vibestack-ns cookie) and canonicalized differential live-parity shape verification (diffShapes). Reach for an individual Mockingbird service package only as an explicit, isolated escape hatch when no Tier 0 or Tier 1 option fits.

Core vibestack/emulate primitives
  • `createEmulatorServer<S>(config)` — stateful Node 26 HTTP + SSE server with per-namespace state (getState(ns?), setState(next, ns?), reset(ns?)), atomic 0o600 JSON persistence, CORS/OPTIONS preflight, and safe parseRequest (1 MB cap, prototype-pollution guard), bearerToken, verifyPkceS256, paginateSlice, sendJson, sendHtml, sendRedirect, and sendBytes.
  • Built-in control plane — POST /__control/reset, GET /__control/requests, GET /__control/state, POST /__control/fault, and DELETE /__control/fault (extensible via onControl).
  • `SseHub` — server-sent event fan-out with event filtering, replay, broadcast, closeWhere, and closeAll.
  • `RequestLog` — bounded ring buffer (record, list(filter?), clear) backing GET /__control/requests and QA evidence collection.
  • `FaultArmory` — deterministic fault injection (arm, consume, list, clear) supporting HTTP method, path glob, status (429, 500, 503), retryAfter, custom body, remaining count, delayMs, and stall.

3. Specialized service patterns

Voice (STT, TTS, and Realtime WebSocket)
  • Tier A — default for CI (<10ms, 0 MB, 100% deterministic):
  • Use createWavFixture, pcm16Tone, and createVoiceTranscriptMap from vibestack/emulate (or @emulators/ai audio routes for OpenAI/ElevenLabs).
  • Serve valid RIFF/WAVE PCM16 buffers over HTTP or local WebSockets so tests verify audio framing, sample rate, VAD/turn-commit protocol, barge-in cancellation, and deterministic transcript/audio roundtrips without shipping heavy acoustic models.
  • Tier B — opt-in local acoustic testing only (never required in default CI):
  • Use sherpa-onnx (Node-API native addon, local STT and TTS without Python) only when human-listening or speaker-to-mic acoustic pipeline testing is explicitly needed locally. Never gate pnpm check or CI on downloading ONNX weights.
LLM, Image, and Map services
  • LLM: Use createCannedMatcher({ rules, strict: true }) from vibestack/emulate (or @emulators/ai) keyed directly to spec/**/*.md story and QA queries (match, textContains, model, tool, path, plus stateful turn/callCount). Keep strict: true in QA so unmatched prompts fail loudly instead of silently returning filler. Model stateful conversation/response IDs, SSE token streaming (SseHub), tool-call loops, structured JSON outputs, and 429/503/stall faults via FaultArmory.
  • Image: Return valid binary PNGs via createPngFixture({ width, height, rgba }) (CRC32 + zlib-deflated PNG) or @emulators/ai image routes, and model async polling APIs with explicit job progression (queued -> running -> completed / failed).
  • Maps, Geocoding, Places, and Routing: Serve valid PNG tiles via createPngFixture, schema-valid GeoJSON/Places/Directions fixtures keyed to canonical QA queries, and stateful error/quota triggers (ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED).

4. Author doc-first, then capture and verify against the real API

Never block offline development on live credentials, and never pretend an unverified emulator matches production.

  1. Draft from official documentation: Read the provider's official API docs, OpenAPI specification, or SDK schemas first (). Implement a complete stateful emulator and register it in emulators/manifest.json with:
  2. service, kind ("http" | "ws" | "llm" | "voice" | "image" | "maps" | "custom"), provider ("emulate-builtin" | "vibestack-custom" | "local-model" | "canned-fixture"), baseUrlEnv, docsUrl, files, status: "unverified", contractHash, and optional verifiedEndpoints, capturesDir, and notes.
  3. Surface verification status loudly: Offline tests work immediately with status: "unverified", and pnpm exec vibestack emulate status (or --json) warns explicitly about every unverified or stale emulator. Pass --strict-verified only when gating a release or local verification pass on 100% verified contracts.
  4. Capture real HTTP exchanges locally (never in CI PRs): Whenever sandbox or dev credentials are available on your machine, record real exchanges: ``bash pnpm exec vibestack emulate capture --service <name> --url <url> [--method GET] [--header K:V] [--body JSON] [--out <file>] [--json] ` captureExchange enforces mandatory secret redaction (redactHeaders, redactUrl, redactPayload, assertNoSecrets) **before anything is written to disk**: it scrubs auth headers, cookies, secret query params, sensitive JSON keys (secret, token, key, password, credential, auth), JWTs, and provider key prefixes (sk_`, `ghp_, xox`, `AIza`), and throws if any unredacted secret matches.
  5. Verify canonicalized shape parity: Run the captured exchange against your local emulator: ``bash pnpm exec vibestack emulate verify --service <name> --capture <file> --emulator-url <url> [--json] ` verifyEmulatorParity / diffShapes strips volatile fields (UUIDs, ISO dates, timestamps, request IDs, nonces, signatures) and compares HTTP status, content-type`, required JSON keys, value types, nullability, array item shapes, and error envelopes.
  6. Fix drift and stamp `verified`: Fix every status, header, envelope, or field-type mismatch in the emulator until verify passes. Passing verify stamps status: "verified", contractHash, and verifiedAt in emulators/manifest.json.
  7. Automatic staleness on edit: computeContractHash hashes every file listed in files. Editing an emulator or fixture changes its hash and automatically flips its resolved status in resolveManifestStatus / emulate status to "stale" until re-verified.

5. Wire into shell, tests, workerd, and CI

  • Inject at the service boundary: Read each external service's base URL from a single typed config/env binding (*_BASE_URL) in the VibeLang shell (). Point Vitest, Playwright, and local workerd (pnpm dev:cf, pnpm test:deploy) at loopback 127.0.0.1:<port> emulator origins via env bindings — testing real HTTP serialization, headers, status handling, and retries without touching application code.
  • Keep production bundles clean: Never import vibestack/emulate, emulate, or emulator fixtures from production app or Worker entrypoints ().
  • Isolate parallel tests: Pass a per-test x-vibestack-namespace header (or vibestack-ns cookie) or call POST /__control/reset between journeys so concurrent tests never collide.
  • Verify offline in CI: Confirm pnpm test, pnpm check, and pnpm test:deploy (when applicable) pass with zero external API keys set.

Report

Summarize concisely when done:

  1. Services audited: external services found by pnpm exec vibestack emulate audit --json and any uncovered integrations closed.
  2. Emulators added or updated: tier chosen (vibestack/emulate vs vercel-labs/emulate), files touched, and baseUrlEnv bindings wired.
  3. Verification status: exact pnpm exec vibestack emulate status --json summary, explicitly flagging every unverified or stale emulator (and noting any live captures verified).
  4. Offline checks: test, deploy-test, and pnpm check results with no live external credentials.