Add integration tests for Similarity Search API#541
Open
285729101 wants to merge 1 commit into1712n:mainfrom
Open
Add integration tests for Similarity Search API#541285729101 wants to merge 1 commit into1712n:mainfrom
285729101 wants to merge 1 commit into1712n:mainfrom
Conversation
Add 37 integration tests using Cloudflare's Vitest pool workers and SELF.fetch() to exercise the full request lifecycle of the Similarity Search Worker. Tests are organized into seven areas: 1. Authentication middleware - missing, invalid, empty, and correct API keys 2. POST / happy path - similarity score, JSON content-type, response shape 3. Input validation - wrong types (number, null, boolean, array, object), missing fields, empty object 4. Edge cases - empty strings, XSS characters, Unicode, emoji, long text, special namespace characters, whitespace-only input 5. HTTP method handling - GET, PUT, DELETE, PATCH all return 404 6. Undefined routes - various unregistered paths return 404 7. Malformed request bodies - non-JSON, empty body, extra fields Also fixes the AI mock in vitest.config.ts to return a proper array of 768-dimensional vectors (matching the bge-base-en-v1.5 model output) instead of an empty object, enabling the full embedding-to-query pipeline to execute correctly in tests. Closes 1712n#430
d5fbde5 to
a106738
Compare
a106738 to
79d7aed
Compare
Author
|
@kishoian @evgenydmitriev this adds integration tests for the Similarity Search API. Ready for review. |
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
Closes #430
Adds 37 integration tests for the Similarity Search API using Cloudflare's Vitest pool workers integration and the
SELF.fetch()pattern to test the full Worker request lifecycle.Methodology
All tests use
SELF.fetch()fromcloudflare:testto dispatch real HTTP requests through the Worker, exercising the complete middleware chain (authentication) and handler logic (embedding + vector query). AI and Vectorize bindings are mocked usingwrappedBindingswith lightweight auxiliary workers defined invitest.config.ts, following Cloudflare's recommended approach for services without local simulators.Test categories
/all return 404Changes
test/index.spec.ts-- Replaced the single existing test with 37 comprehensive integration tests organized into 7describeblocks.vitest.config.ts-- Fixed theworkers-aimock to return a proper 768-dimensional vector array matching the@cf/baai/bge-base-en-v1.5model output format. The original mock returned{ data: {} }(an empty object), causingmodelResp.data[0]to beundefined. The fix returns{ data: [Array(768)] }so the full embedding-to-query pipeline executes correctly.No source code changes
This PR only adds tests and fixes the test mock configuration. The Worker source code (
src/index.ts) is not modified.Test plan
npx vitest run(2.1s total, 242ms test execution)🤖 Generated with Claude Code