fix: mock dedup check in existing compilation tests#584
Conversation
There was a problem hiding this comment.
Pull request overview
This PR makes the existing compilation tests independent of the dedup-on-compile path introduced in PR #582 by globally patching _find_similar_article() in tests/core/test_compilation.py, preventing real embedding API calls during this test suite.
Changes:
- Add a module-level
autousefixture that monkeypatchesvalence.core.compilation._find_similar_articleto always returnNone. - Document why dedup is suppressed in these tests and point to
test_compilation_dedup.pyfor dedup coverage.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @pytest.fixture(autouse=True) | ||
| def _no_dedup(monkeypatch): | ||
| """Disable dedup check in compilation tests (tested separately in test_compilation_dedup.py).""" | ||
|
|
||
| async def _no_match(*args, **kwargs): | ||
| return None | ||
|
|
||
| monkeypatch.setattr("valence.core.compilation._find_similar_article", _no_match) | ||
|
|
||
|
|
||
| from valence.core.compilation import ( | ||
| DEFAULT_PROMPT_LIMITS, |
There was a problem hiding this comment.
from valence.core.compilation import (...) is placed after executable code (the autouse fixture), which triggers Ruff/pycodestyle E402 (module level import not at top of file) and will fail CI. Please move this import block up with the other imports (above the fixture), or add an explicit # noqa: E402 (reordering is preferable).
PR #582 added _find_similar_article() inside compile_article(), which calls generate_embedding() and makes a real API call. Add an autouse fixture that patches _find_similar_article to return None so existing tests keep testing compilation logic without a live embedding API. Dedup behaviour is exercised by test_compilation_dedup.py.
1a67f3d to
486e3df
Compare
Problem
PR #582 added
_find_similar_article()insidecompile_article(), which callsgenerate_embedding()— a real API call. The existing tests intests/core/test_compilation.pyhad no mock for this path, so they would fail in CI environments without a live OpenAI key (currently passing only because the exception is silently swallowed by thetry/exceptguard in_find_similar_article).Fix
Added a single module-level
autousefixture intests/core/test_compilation.py:This patches out
_find_similar_articlefor every test in the file, making the intent explicit and removing the silent dependency on error-swallowing behaviour. Dedup logic is already covered bytest_compilation_dedup.py.Verification
Changes
tests/core/test_compilation.py— add_no_dedupautouse fixture (+21 lines, no test logic changed)