test(llm): add unit tests for openai type-introspection cache (follow-up to #2876)#3043
Open
Vasilije1990 wants to merge 1 commit into
Open
test(llm): add unit tests for openai type-introspection cache (follow-up to #2876)#3043Vasilije1990 wants to merge 1 commit into
Vasilije1990 wants to merge 1 commit into
Conversation
Follow-up to #2876. Covers the new openai_type_cache module: - install() runs on package import and is idempotent - all four helpers are rebound to shared cached wrappers across the openai import sites - cached results match the uncached originals for common typing shapes - unhashable arguments fall back to the uncached call instead of raising Also passes __name__ to get_logger() per review feedback so log records carry the module name. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Follow-up to #2876, stacked on
perf/openai-type-introspection-cache.#2876 adds
cognee/infrastructure/llm/openai_type_cache.pybut ships no tests for the new behavior. This PR adds a small unit test module (cognee/tests/unit/infrastructure/llm/test_openai_type_cache.py) that locks in the contract the perf patch relies on:cognee.infrastructure.llmandinstall()is idempotent (returnsFalseon repeat calls)get_origin,get_args,is_literal_type,is_annotated_type) are rebound to the same cached wrappers across the openai import sites (openai._models,openai._utils._compat,openai._utils._typing)__wrapped__) for common typing shapes, including repeated (cache-hit) callsTypeErrorIf a future openai-python release moves these private modules, these tests fail fast instead of silently losing the ~28% cognify CPU saving measured in #2876.
Also addresses the open CodeRabbit nit by passing
__name__toget_logger()so log records from the cache installer carry the module name.Tests pass locally:
uv run pytest cognee/tests/unit/infrastructure/llm/test_openai_type_cache.py(4 passed).Should merge after #2876 (or be merged into it).
🤖 Generated with Claude Code