test: ensure sentence-transformers is in test env + conftest gate
This commit is contained in:
@@ -101,39 +101,31 @@ def test_rag_status_remains_error_after_sync_failure() -> None:
|
||||
|
||||
|
||||
def test_rag_engine_init_with_failing_local_embedding_leaves_engine_broken() -> None:
|
||||
"""RAGEngine with local embedding + sentence-transformers missing
|
||||
ends up in a broken state: self.embedding_provider is None.
|
||||
The sync path should detect this and NOT set status to 'ready'.
|
||||
"""When the LocalEmbeddingProvider ctor fails (e.g. sentence-transformers
|
||||
raises), the RAGEngine ctor itself raises ImportError. The sync path
|
||||
catches this and sets rag_status to 'error: ...' (the existing
|
||||
test_rag_status_remains_error_after_sync_failure covers this).
|
||||
|
||||
This is the actual bug surfaced in the test_rag_phase4_final_verify
|
||||
batch failure: in batch context (after the 4 sims run), the sync
|
||||
reports 'ready' but the RAG engine is broken. The AI attempts to
|
||||
use it, embedding fails silently, and the RAG context never
|
||||
appears in the user's history.
|
||||
This test verifies the precondition: that RAGEngine.__init__ actually
|
||||
raises ImportError when the local embedding provider can't be built,
|
||||
rather than silently swallowing the error and leaving a broken engine.
|
||||
|
||||
The 2026-06-08 RAG batch failure root-cause analysis showed the
|
||||
failure mode was NOT "engine is created with embedding_provider=None"
|
||||
(which was the original test docstring's claim) — the constructor
|
||||
RAISES. The actual bug was in the sync path's fallback to 'ready'
|
||||
status, which test_rag_status_remains_error_after_sync_failure
|
||||
verifies. This test is the lower-level sanity check that the
|
||||
precondition for the sync-path test is real.
|
||||
"""
|
||||
import subprocess
|
||||
# Test that the actual RAGEngine (real one) leaves embedding_provider
|
||||
# as None when the import fails
|
||||
result = subprocess.run(
|
||||
["uv", "run", "python", "-c", """
|
||||
import sys
|
||||
sys.path.insert(0, '.')
|
||||
from src import models, rag_engine
|
||||
config = models.RAGConfig(
|
||||
enabled=True,
|
||||
embedding_provider='local',
|
||||
vector_store=models.VectorStoreConfig(provider='chroma', collection_name='t')
|
||||
)
|
||||
try:
|
||||
engine = rag_engine.RAGEngine(config, base_dir='.')
|
||||
print('engine.embedding_provider:', engine.embedding_provider)
|
||||
print('engine.collection:', engine.collection)
|
||||
except ImportError as e:
|
||||
print('ImportError:', str(e)[:60])
|
||||
"""],
|
||||
capture_output=True, text=True, cwd='C:\\\\projects\\\\manual_slop'
|
||||
from src import models
|
||||
from src import rag_engine
|
||||
config = models.RAGConfig(
|
||||
enabled=True,
|
||||
embedding_provider="local",
|
||||
vector_store=models.VectorStoreConfig(provider="chroma", collection_name="t"),
|
||||
)
|
||||
print("STDOUT:", result.stdout)
|
||||
print("STDERR:", result.stderr[:200])
|
||||
assert "ImportError" in result.stdout
|
||||
assert "sentence-transformers" in result.stdout
|
||||
with patch("src.rag_engine._get_sentence_transformers",
|
||||
side_effect=ImportError("Local RAG embeddings require sentence-transformers.")):
|
||||
with pytest.raises(ImportError, match="sentence-transformers"):
|
||||
rag_engine.RAGEngine(config, base_dir=".")
|
||||
|
||||
Reference in New Issue
Block a user