Skip to content

fix(test): repair 6 failing tests blocking develop CI - #19

Merged
ngoclam9415 merged 1 commit into
developfrom
fix/develop-ci-red-test-failures
Jul 7, 2026
Merged

fix(test): repair 6 failing tests blocking develop CI#19
ngoclam9415 merged 1 commit into
developfrom
fix/develop-ci-red-test-failures

Conversation

@ngoclam9415

Copy link
Copy Markdown
Contributor

Problem

develop CI is red — 6 unit tests fail (the same 6 that fail on PR #18 develop→stable, since #18's head is develop). Develop has been broken since #16 (inject LLMProvider) and the Responses API work (#9/#15) landed.

FAILED tests/unit/core/test_inject_llm_provider.py::test_rlm_resource_set_llm_repoints — ValueError: OpenAI API key not found
FAILED tests/unit/core/test_inject_llm_provider.py::test_ltmemory_set_llm_repoints — ValueError: OpenAI API key not found
FAILED tests/unit/core/test_inject_llm_provider.py::test_set_llm_provider_string_path_updates_all_sinks — ValueError: Anthropic API key not found
FAILED tests/unit/test_llm_providers.py::TestOpenAIReasoningTokens::test_chat_with_reasoning_tokens — TypeError: 'MagicMock' object can't be awaited
FAILED tests/unit/test_llm_providers.py::TestOpenAIReasoningTokens::test_chat_without_reasoning_tokens — TypeError: 'MagicMock' object can't be awaited
FAILED tests/unit/test_llm_providers.py::TestOpenAIReasoningTokens::test_chat_with_zero_reasoning_tokens — TypeError: 'MagicMock' object can't be awaited

Root causes & fixes

1. test_inject_llm_provider.py (3 failures) — tests construct resources with llm_provider="openai"/"anthropic" (string path), which builds a real provider that reads OPENAI_API_KEY/ANTHROPIC_API_KEY from env. They only assert identity wiring and never call the LLM.
→ Added an autouse fixture supplying dummy env keys so construction succeeds offline.

2. TestOpenAIReasoningTokens (3 failures) — thinking models (gpt-5*) now route through the Responses API (client.responses.create) per #9/#15, but these tests still mocked client.chat.completions.create. The awaited responses.create hit an un-mocked MagicMock.
→ Rewrote the 3 tests to mock client.responses.create with a Responses-API-shaped response (output items + usage.output_tokens_details.reasoning_tokens) via a shared _responses_api_response helper. Test intent preserved: verify reasoning-token parsing (150 → 150, absent → None, 0 → None via falsy coercion).

Verification

Full suite, CI-identical invocation (DANA_MOCK_LLM=true DANA_USE_REAL_LLM=false uv run pytest tests/ -m "not live and not deep"):

Before: 6 failed, 1870 passed, 38 skipped
After:  1885 passed, 30 skipped, 166 deselected, 1 xfailed   ✅

Ruff + format clean on both files.

Scope

Test-only change. No production code touched.

Two unrelated groups, both pre-existing on develop:

1. tests/unit/core/test_inject_llm_provider.py (3 failures)
   Tests pass llm_provider="openai"/"anthropic" (string) which eagerly builds
   a real provider requiring OPENAI_API_KEY/ANTHROPIC_API_KEY. They only check
   identity wiring and never call the LLM. Add an autouse fixture that supplies
   dummy env keys so construction succeeds offline.

2. tests/unit/test_llm_providers.py::TestOpenAIReasoningTokens (3 failures)
   Thinking models (gpt-5*) route through the Responses API since #9/#15, but
   these tests still mocked client.chat.completions.create — so the awaited
   call hit an un-mocked MagicMock ("can't be awaited"). Rewrite to mock
   client.responses.create with a Responses-API-shaped response (output items
   + usage.output_tokens_details.reasoning_tokens) via a shared helper.
@ngoclam9415
ngoclam9415 merged commit 1c22655 into develop Jul 7, 2026
1 check passed
@ngoclam9415
ngoclam9415 deleted the fix/develop-ci-red-test-failures branch July 7, 2026 10:32
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