refactor(tests): share the OpenAI embeddings mock across vector-store suites - #2665
Merged
gold-silver-copper merged 2 commits intoOct 1, 2026
Merged
Conversation
… suites One mock_embeddings helper in test-support/service-tests/common.rs replaces 20 hand-written httpmock /embeddings blocks, along with copies of skip_if_docker_unavailable, the one-hot embedding helper, the mock OpenAI client and the shared word definitions. LanceDB's two tests share one mock and one table/index setup.
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.
refactor(tests): share the OpenAI embeddings mock across vector-store suites
Description
Smell. The vector-store suites under
tests/integrations/(run bytest-support/service-tests) each hand-wrote the same httpmock stand-in for OpenAIPOST /embeddings. There were 20 copies of onewhen/thenblock: the method, the path, the auth header, the request body, and the{"object":"list","data":[{"object":"embedding",...,"index":i}],"model":...,"usage":...}envelope. Around them sat four copies ofskip_if_docker_unavailable, two copies of the one-hot embedding helper (axis_embeddingandcreate_embedding_vector), about ten copies of the OpenAI client pointed at the mock, and the flurbo/glarb-glarb/linglingdong definitions, written out in both the mocks and theWordlists. The LanceDB suite also had two identical table-create/IVF-PQ-index blocks.Why it hurts. A change to the OpenAI embeddings wire meant editing about 20 copies by hand, and the copies had already drifted without anyone choosing it. Some matched
Content-Typeand some didn't, and the usage numbers varied. In each test, the useful part is which inputs map to which vectors, and that was buried in 30-line JSON literals.Change.
test-support/service-tests/common.rsis a new support module for the service suites, declared once inintegrations.rs. It holds:mock_embeddings(server, request, embeddings). The expected request body is passed explicitly at every call site, so the request boundary is still asserted, and each test keeps its exact inputs and vectors.openai_client(server),skip_if_docker_unavailable,axis_embeddingandWORD_DEFINITIONS.Inside LanceDB,
mock_embeddings_apiandindex_definitionsreplace the two copies of each block. AFLUMBUZZLE/flumbuzzles()fixture replaces the 256-row padding literal that appeared four times. No assertion changed.The module lives in
test-support/service-tests/rather thantests/integrations/, because xtask'sfull_lane_covers_every_integration_suitetreats every file intests/integrations/as a suite for arig-<name>crate.Deliberate small differences
Content-Type: application/json. The LanceDB and Neo4j copies already did, and every suite uses the same OpenAI client.insert_documents_testused 4/4, and no test reads usage.indexvalues are now sequential. The OpenAI embeddings decoder ignoresindexand keeps the array order, so LanceDB's old0,2,1,1...order decoded the same way.TempDir, so those branches never ran.create_openai_mock_servicehas#[rustfmt::skip]. Its four recorded-style 1536-value vectors used to sit insidejson!, where rustfmt doesn't reach. Outside it, rustfmt would put them one value per line (+6,000 lines).Net LOC:
git diff --shortstat origin/main...HEADgives10 files changed, 340 insertions(+), 1003 deletions(-), so net -663.Rejected or out of scope
WORD_DEFINITIONS → Word { id: docN }maps as they are. Each suite'sWordhas different derives or serde attributes, so a sharedWordtype would cost more than it saves.recorded_request/recorded_responsewrappers andscripted_unary.Changelog
None (test scaffolding only).
Migration
None.
Type of change
Refactor of test scaffolding.
Testing
cargo nextest run --locked -p rig-service-tests --all-features --run-ignored allwith local Docker: 17/18 passed. That covers lancedb (2), mongodb (2), neo4j, postgres, qdrant, sqlite (2), scylladb mock setup and vectorize (6, which skip without credentials). The ignoredscylladb::vector_search_testfailed atScyllaDbVectorStore::newwith a refused connection to the local Scylla container. That was after its mocked embeddings call had succeeded, so it's a local container problem.cargo clippy -p rig-service-tests --testswith all features, no features, andlancedb,sqlite,vectorizeandpostgreson their own: clean.cargo fmt --all,cargo xtask check-test-layout, andcargo nextest run -p xtask full_lane: all pass.Checklist:
CHANGELOG.mdorMIGRATING.md(they are generated at release)