Skip to content

refactor(tests): share the OpenAI embeddings mock across vector-store suites - #2665

Merged
gold-silver-copper merged 2 commits into
0xPlaygrounds:mainfrom
gold-silver-copper:arch-smell-d8ff57
Oct 1, 2026
Merged

gold-silver-copper merged 2 commits into
0xPlaygrounds:mainfrom
gold-silver-copper:arch-smell-d8ff57

Conversation

@gold-silver-copper

@gold-silver-copper gold-silver-copper commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

refactor(tests): share the OpenAI embeddings mock across vector-store suites

Description

Smell. The vector-store suites under tests/integrations/ (run by test-support/service-tests) each hand-wrote the same httpmock stand-in for OpenAI POST /embeddings. There were 20 copies of one when/then block: 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 of skip_if_docker_unavailable, two copies of the one-hot embedding helper (axis_embedding and create_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 the Word lists. 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-Type and 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.rs is a new support module for the service suites, declared once in integrations.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_embedding and WORD_DEFINITIONS.

Inside LanceDB, mock_embeddings_api and index_definitions replace the two copies of each block. A FLUMBUZZLE/flumbuzzles() fixture replaces the 256-row padding literal that appeared four times. No assertion changed.

The module lives in test-support/service-tests/ rather than tests/integrations/, because xtask's full_lane_covers_every_integration_suite treats every file in tests/integrations/ as a suite for a rig-<name> crate.

Deliberate small differences

  • Every mocked embeddings request now also matches Content-Type: application/json. The LanceDB and Neo4j copies already did, and every suite uses the same OpenAI client.
  • Every mocked response reports usage 8/8. Mongo's insert_documents_test used 4/4, and no test reads usage.
  • Response index values are now sequential. The OpenAI embeddings decoder ignores index and keeps the array order, so LanceDB's old 0,2,1,1... order decoded the same way.
  • LanceDB no longer checks whether the table or index already exists before creating it. Each test uses a fresh TempDir, so those branches never ran.
  • Postgres's create_openai_mock_service has #[rustfmt::skip]. Its four recorded-style 1536-value vectors used to sit inside json!, 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...HEAD gives 10 files changed, 340 insertions(+), 1003 deletions(-), so net -663.

Rejected or out of scope

  • I left the four 7-line WORD_DEFINITIONS → Word { id: docN } maps as they are. Each suite's Word has different derives or serde attributes, so a shared Word type would cost more than it saves.
  • The LanceDB chat-completions mock stays inline because it has only one copy.
  • Following the scope notes, I left alone the tracing capture helpers (refactor(test-utils): one tracing capture layer for span and event assertions #2659), the recorded_request/recorded_response wrappers and scripted_unary.

Changelog

None (test scaffolding only).

Migration

None.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Refactor of test scaffolding.

Testing

  • cargo nextest run --locked -p rig-service-tests --all-features --run-ignored all with 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 ignored scylladb::vector_search_test failed at ScyllaDbVectorStore::new with 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 --tests with all features, no features, and lancedb, sqlite, vectorize and postgres on their own: clean.
  • cargo fmt --all, cargo xtask check-test-layout, and cargo nextest run -p xtask full_lane: all pass.

Checklist:

  • I have updated READMEs and Rust docs affected by this change (none affected)
  • I have added tests that prove my fix is effective or that my feature works (refactor; existing tests unchanged)
  • I did not edit CHANGELOG.md or MIGRATING.md (they are generated at release)

… 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.
@gold-silver-copper
gold-silver-copper marked this pull request as ready for review October 1, 2026 02:17
@gold-silver-copper
gold-silver-copper added this pull request to the merge queue Oct 1, 2026
Merged via the queue into 0xPlaygrounds:main with commit 23d15e6 Oct 1, 2026
16 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.

1 participant