Skip to content

Add integration tests for Similarity Search API#541

Open
285729101 wants to merge 1 commit into1712n:mainfrom
285729101:feat/similarity-search-integration-tests
Open

Add integration tests for Similarity Search API#541
285729101 wants to merge 1 commit into1712n:mainfrom
285729101:feat/similarity-search-integration-tests

Conversation

@285729101
Copy link

@285729101 285729101 commented Feb 16, 2026

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() from cloudflare:test to 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 using wrappedBindings with lightweight auxiliary workers defined in vitest.config.ts, following Cloudflare's recommended approach for services without local simulators.

Test categories

Category Tests What is covered
Authentication 5 Missing key, wrong key, empty key, correct key, auth on undefined routes
POST / happy path 4 Similarity score value, JSON content-type, response shape, multiple namespaces
Input validation 11 Wrong types (number, null, boolean, array, object), missing fields, empty object
Edge cases 7 Empty strings, XSS/HTML injection, Unicode, emoji, long text (25 KB), special namespace chars, whitespace-only
HTTP methods 4 GET/PUT/DELETE/PATCH on / all return 404
Undefined routes 3 Various non-existent paths return 404
Malformed bodies 3 Non-JSON text, empty body, extra fields ignored

Changes

  • test/index.spec.ts -- Replaced the single existing test with 37 comprehensive integration tests organized into 7 describe blocks.
  • vitest.config.ts -- Fixed the workers-ai mock to return a proper 768-dimensional vector array matching the @cf/baai/bge-base-en-v1.5 model output format. The original mock returned { data: {} } (an empty object), causing modelResp.data[0] to be undefined. 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

  • All 37 tests pass locally via npx vitest run (2.1s total, 242ms test execution)
  • CI passes on the PR

🤖 Generated with Claude Code

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
@285729101 285729101 force-pushed the feat/similarity-search-integration-tests branch from d5fbde5 to a106738 Compare February 17, 2026 14:33
@285729101 285729101 changed the title test: add integration tests for Similarity Search API Add integration tests for Similarity Search API Feb 17, 2026
@285729101 285729101 force-pushed the feat/similarity-search-integration-tests branch from a106738 to 79d7aed Compare February 17, 2026 16:45
@285729101
Copy link
Author

@kishoian @evgenydmitriev this adds integration tests for the Similarity Search API. Ready for review.

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.

Similarity Search API Integration Testing

1 participant