Add mock API server for CI integration test coverage#303
Merged
jakebromberg merged 13 commits intomainfrom Apr 5, 2026
Merged
Conversation
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
4f9140d to
ac04412
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SLACK_WEBHOOK_URLenv var override so Slack webhooks can route to a mock server in CI (usesfetch()with timeout, falls back to existinghttps.requestpath)dev_env/mock-api-server/) simulating LML, Slack, and tubafrenzy with fixture data for WXYC example artists/_admin/*) for test orchestration: request log, state reset, configurable error simulationmock-apiservice,USE_MOCK_SERVICES=false, route all external calls through mocktests/utils/mock_api.jsfor consistent test helpersCloses #298
Test plan
postViaFetchrespectsSLACK_TIMEOUT_MStimeout