[hotfix] Make Ollama embedding test actually run in CI#686
Conversation
`test_ollama_embedding_setup` and `test_openai_embedding_model` both
construct a `BaseEmbeddingModelSetup` subclass with `connection` set to
a resource-name string, then call `setup.embed(...)` directly without
first invoking `setup.open()`.
`BaseEmbeddingModelSetup.open()` is what resolves `self.connection` from
the descriptor-supplied resource name into the actual
`BaseEmbeddingModelConnection` instance. Without it,
`_get_connection()` raises `TypeError("Expect BaseEmbeddingModelConnection,
but is str")` and the test fails. The Ollama test exhibits this failure
in CI on Python 3.10 once the ollama daemon is brought up by
`start_ollama_server.sh`; the OpenAI test is masked by the
`TEST_API_KEY` skipif but would fail identically if the gate were ever
satisfied. `test_tongyi_embedding_model` (the third embedding test in
this repo) already follows the correct pattern.
Add the missing `setup.open()` call to both tests so the connection is
resolved before `embed()`.
|
Hi, @weiqingy. Good Catch, the fix looks good to me. In theory, I think we may need to fix this issue together. |
Per @wenjin272's review on apache#686: `ollama run all-minilm:22m` cannot run non-interactively against an embedding model — `ollama` reports Error: embedding models require input text. Usage: ollama run all-minilm:22m "your text here" and exits non-zero. That bubbles up through `subprocess.run(check=True)` in `test_ollama_embedding_model.py`'s module-level setup, falls into the `except` block, and silently sets `client = None`, which makes the embedding test skip in CI on Python 3.10 — defeating the purpose of ever calling the script. `ollama pull` alone is sufficient to make the model discoverable via the daemon's `client.list()`; the chat-model sibling script (`integrations/chat_models/tests/start_ollama_server.sh`) already follows that minimal pattern. Drop the redundant `ollama run` line so the gate succeeds and the test actually executes in CI.
|
@wenjin272 Thanks for catching this! Confirmed by inspecting both scripts side-by-side: the chat-model sibling at Dropped the line in 3ade7fa. The preceding |
|
Hi, @weiqingy. I noticed that the latest CI run still skipped The root cause of this issue is environment variable leakage, and I have provided a detailed explanation below. I noticed that the title of this PR has been updated to “Make Ollama embedding test actually run in CI,” so I believe it is appropriate to address and fix this issue within the same PR. Alternatively, we can fix the issues with the Open and Ollama scripts in this PR alone, and submit a separate PR to address all environment variable leakage issues, including those related to the embedding model, chat model, and other environment variables. WDYT? Root Cause:
|
The e2e modules in e2e_tests_resource_cross_language assigned os.environ["OLLAMA_EMBEDDING_MODEL"] = OLLAMA_MODEL at module scope. Because pytest -k "not e2e_tests" only filters which tests run (not which files are collected/imported), pytest collection imported these modules and executed the assignment as a side effect, polluting OLLAMA_EMBEDDING_MODEL for the later-collected integrations/embedding_models/local/tests/test_ollama_embedding_model.py. Net effect: test_ollama_embedding_setup read the polluted "nomic-embed-text:latest" value instead of falling back to the hard-coded "all-minilm:22m" default, so the model_found gate failed and the test was silently skipped in the ut-python CI job. Removed the module-scope assignment and moved it into the test functions via monkeypatch.setenv, which preserves the runtime propagation behavior (Flink subprocess still sees the env var) and auto-restores after the test. Reported and root-caused by @wenjin272 in apache#686 (comment).
Resolve conflict in vector_store_cross_language_test.py: main (apache#663, Milvus integration) refactored the test into _run_vector_store_integration helper with two backend-specific test functions (ELASTICSEARCH, MILVUS). Reapply our Round 2 env-var fix on top of that structure: keep the module-scope os.environ["OLLAMA_EMBEDDING_MODEL"] = OLLAMA_MODEL removal, and add monkeypatch.setenv("OLLAMA_EMBEDDING_MODEL", OLLAMA_MODEL) inside the helper so both backends get the env var hygiene.
|
Thanks for the root-cause analysis, @wenjin272! Went with the in-this-PR narrow fix: moved |

Purpose of change
test_ollama_embedding_setupwas effectively dead in CI — silently skipped by a broken preload script, and would have failed on_get_connection()if it ever ran. This PR makes it actually run and pass on the Python 3.10 / Ubuntu UT job.Fix 1 —
ab62944— Addsetup.open()calls in the embedding setup tests.test_ollama_embedding_setupandtest_openai_embedding_modelboth construct aBaseEmbeddingModelSetupsubclass withconnectionset to a resource-name string, then callsetup.embed(...)directly.BaseEmbeddingModelSetup.open()is what resolvesself.connectionfrom the descriptor-supplied resource name into the actualBaseEmbeddingModelConnectioninstance; without it,_get_connection()raisesTypeError("Expect BaseEmbeddingModelConnection, but is str").test_tongyi_embedding_modelalready follows the correct pattern. (The OpenAI test is gated byTEST_API_KEYso the latent bug was masked, but the fix applies identically.)Fix 2 —
3ade7fa— Drop the failingollama runline fromstart_ollama_server.sh.The CI preload script ran
ollama run all-minilm:22m, which exits non-zero against an embedding model withError: embedding models require input text.test_ollama_embedding_model.py's module-level setup usessubprocess.run(..., check=True), so the failure fell into theexceptblock and setclient = None, which made@pytest.mark.skipif(client is None, ...)silently skip the test in every CI run. The precedingollama pull all-minilm:22mis sufficient to make the model discoverable viaclient.list(), which is what the gate actually checks; the parallel chat-modelstart_ollama_server.shalready follows that minimal pattern.Fix 3 —
acfd146— MoveOLLAMA_EMBEDDING_MODELout of module scope in two e2e tests.After Fix 2 the test was still being skipped. Root cause was module-level
os.environ["OLLAMA_EMBEDDING_MODEL"] = OLLAMA_MODELine2e_tests_resource_cross_language/embedding_model_cross_language_test.py:43-44andvector_store_cross_language_test.py:43-44. Becausetools/ut.shrunspytest flink_agents -k "not e2e_tests"and-konly filters which tests execute (not which files are collected), pytest imported the e2e modules during collection and executed the assignment as a side effect — pollutingOLLAMA_EMBEDDING_MODELto"nomic-embed-text:latest"beforetest_ollama_embedding_model.py:34read it with its"all-minilm:22m"default. Fix: removed the module-scope assignment; moved the assignment into the test function body viamonkeypatch.setenv, which preserves runtime propagation to the Flink subprocess while auto-restoring after each test.Tests
cd python && uv run pytest flink_agents/integrations/embedding_models/local/tests/test_ollama_embedding_model.py -v— passes locally when an Ollama daemon is reachable (previously raisedTypeError).cd python && uv run pytest flink_agents/integrations/embedding_models/tests/test_openai_embedding_model.py -v— gated byTEST_API_KEY; latent bug fixed../tools/lint.sh -cclean.API
No API changes — test/CI fixes only.
Documentation
doc-neededdoc-not-neededdoc-included