Skip to content

test(llm): add unit tests for openai type-introspection cache (follow-up to #2876)#3043

Open
Vasilije1990 wants to merge 1 commit into
perf/openai-type-introspection-cachefrom
followup/pr-2876
Open

test(llm): add unit tests for openai type-introspection cache (follow-up to #2876)#3043
Vasilije1990 wants to merge 1 commit into
perf/openai-type-introspection-cachefrom
followup/pr-2876

Conversation

@Vasilije1990

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #2876, stacked on perf/openai-type-introspection-cache.

#2876 adds cognee/infrastructure/llm/openai_type_cache.py but 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:

  • the cache is installed as an import side effect of cognee.infrastructure.llm and install() is idempotent (returns False on repeat calls)
  • all four helpers (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)
  • cached results match the uncached originals (via __wrapped__) for common typing shapes, including repeated (cache-hit) calls
  • unhashable arguments fall back to the uncached call instead of raising TypeError

If 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__ to get_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

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>
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