Skip to content

Add mock API server for CI integration test coverage#303

Merged
jakebromberg merged 13 commits intomainfrom
feature/mock-api-slack-url
Apr 5, 2026
Merged

Add mock API server for CI integration test coverage#303
jakebromberg merged 13 commits intomainfrom
feature/mock-api-slack-url

Conversation

@jakebromberg
Copy link
Copy Markdown
Member

Summary

  • Add SLACK_WEBHOOK_URL env var override so Slack webhooks can route to a mock server in CI (uses fetch() with timeout, falls back to existing https.request path)
  • Add mock API server (dev_env/mock-api-server/) simulating LML, Slack, and tubafrenzy with fixture data for WXYC example artists
  • Add control API (/_admin/*) for test orchestration: request log, state reset, configurable error simulation
  • Update Docker Compose CI profile: mock-api service, USE_MOCK_SERVICES=false, route all external calls through mock
  • Add integration tests: metadata end-to-end via LML, proxy endpoints, Slack webhook delivery, mirror HTTP
  • Add MirrorCommandQueue unit tests (retry logic, backoff, fatal stop, queue persistence)
  • Update GitHub Actions workflow to build and start mock-api-server
  • Extract shared tests/utils/mock_api.js for consistent test helpers

Closes #298

Test plan

  • Mock API server starts and responds to health check
  • LML fixture data serves correct responses for Autechre, Jessica Pratt, etc.
  • Error simulation works (count-limited and permanent)
  • Slack postViaFetch respects SLACK_TIMEOUT_MS timeout
  • All 62 unit test suites pass (605 tests)
  • Integration tests pass against running mock-api + backend + auth
  • CI workflow builds and starts mock-api-server correctly

Jake Bromberg added 13 commits April 5, 2026 15:01
When SLACK_WEBHOOK_URL is set (e.g., http://mock-api:9090 in CI), the Slack service uses fetch() with that base URL instead of https.request to hooks.slack.com. This allows integration tests to route webhook calls to a mock server while leaving the production path unchanged. Malformed URLs (not starting with http) are ignored and fall back to the existing https.request path.
Express server (port 9090) that simulates three external services the backend depends on:

- LML (library-metadata-lookup): /api/v1/discogs/* endpoints with fixture data for Autechre, Jessica Pratt, Duke Ellington, Chuquimamani-Condori, and Sessa
- Slack: /services/* webhook receiver that records payloads
- Tubafrenzy: /playlists/api/flowsheetEntry for HTTP mirror POST/PATCH

Includes a control API (/_admin/*) for test orchestration: request log inspection, state reset, and configurable error simulation (e.g., 500s, 429s with count-limited retries).

Docker Compose CI profile updated to start mock-api before backend, with backend env vars pointing at the mock server (LIBRARY_METADATA_URL, SLACK_WEBHOOK_URL, TUBAFRENZY_URL) and USE_MOCK_SERVICES=false so real code paths execute.
Verifies the full fire-and-forget metadata pipeline: flowsheet insert triggers LML search, metadata is stored and returned in GET responses. Tests cover streaming URL enrichment, artist bio/Wikipedia population, unknown artist fallback to search URLs, and LML failure graceful degradation. Also tests proxy endpoints (/proxy/metadata/album, /proxy/metadata/artist, /proxy/entity/resolve) routing through LML with error translation.
Slack tests verify that song requests post to the mock webhook endpoint and that webhook failures don't break the request response. Mirror tests verify that flowsheet mutations (add/update) are POSTed/PATCHed to the mock tubafrenzy endpoint with correct entry type codes, and that mirror failures don't block the primary response.
Covers queue lifecycle: enqueue wraps SQL in transactions, successful commands emit 'succeeded' events, failed commands retry up to maxAttempts with backoff, fatal stop persists queue to disk and emits 'fatal' event, dead queues reject new commands, and commands drain in FIFO order. Uses fake timers for deterministic backoff testing.
Start mock-api-server alongside auth and backend in CI. Set USE_MOCK_SERVICES=false so real code paths execute against the mock server. Add mock-api to change detection filters, export MOCK_API_URL for test runner, and include mock server logs in failure diagnostics. Document SLACK_WEBHOOK_URL in CLAUDE.md.
- Add AbortController timeout to postViaFetch matching the 10s timeout in postViaHttps
- Extract shared mock API helpers into tests/utils/mock_api.js (isMockApiAvailable, resetMockApi, getMockRequests, simulateError)
- Standardize skip pattern across all integration tests: check availability once in beforeAll, guard individual tests with boolean
- Replace createRequire JSON import with readFileSync in mock server LML routes
@jakebromberg jakebromberg force-pushed the feature/mock-api-slack-url branch from 4f9140d to ac04412 Compare April 5, 2026 22:08
@jakebromberg jakebromberg merged commit 50b65df into main Apr 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add mock API server for CI integration test coverage

1 participant