test(agents,llm): cover RoutingAgent, code validators, OpenAI provider#1244
test(agents,llm): cover RoutingAgent, code validators, OpenAI provider#1244kovtcharov-amd wants to merge 3 commits into
Conversation
|
Three production modules — Issues Found🟡
|
The CLI-mode clarification test was passing via `_create_agent` (the default-to-typescript shortcut), never entering the `input()` branch. First LLM response now uses known language + unknown project_type + low confidence so `_default_unknown_language_to_typescript` leaves it alone and `_has_unknowns` fires. Asserts `mock_input.assert_called_once()`. Also drops redundant `call_kwargs[1].get()` fallbacks — `.kwargs` is the modern accessor and sufficient here.
|
135 tests land with zero production changes — a safe, focused PR. The test design is solid; three issues are worth addressing before the gaps get wider. Issues🟡 Important — tests cover
|
itomek
left a comment
There was a problem hiding this comment.
The clarification-loop test from the earlier review is now correct — it uses a known-language/unknown-project-type/confidence=0.4 first response so _has_unknowns actually fires, and asserts input() was called. Fixture layering and the patch.dict("sys.modules", {"openai": ...}) isolation are clean. Two items worth tracking, noted inline: the TestFallbackKeywordDetection class tests genuinely unreachable code (confirmed by reading routing/agent.py — process_query never calls _fallback_keyword_detection), and test_extra_kwargs_not_passed_to_openai_client documents a real base_url silent-drop in OpenAIProvider.init. Neither blocks this test PR; the dead-code class is the one worth filing an issue for. Approving.
Generated by Claude Code
There was a problem hiding this comment.
TestFallbackKeywordDetection (10 tests) exercises _fallback_keyword_detection, which is unreachable: process_query routes through _analyze_with_llm, whose JSON-decode failure returns a hardcoded default dict and whose generic except re-raises — the keyword fallback is never called. Testing it gives green CI for a method that could be arbitrarily wrong relative to the live routing path. Either gate the class behind @pytest.mark.skip(reason="dead code — tracked in #NNN") or wire the source up first. Worth filing an issue to track.
Generated by Claude Code
There was a problem hiding this comment.
test_extra_kwargs_not_passed_to_openai_client pins a real gap: OpenAIProvider.init swallows **_kwargs, so base_url=... is silently dropped — a caller pointing at a custom endpoint gets a misconfigured client with no error (the quiet-wrong-answer pattern the no-silent-fallbacks rule forbids). The test documents it; add a comment marking it as a known source bug to track, or better, forward base_url to openai.OpenAI() while you're touching this surface.
Generated by Claude Code
#880) RoutingAgent, code validators (syntax, antipattern, AST, requirements), and OpenAIProvider had zero dedicated unit tests. Adds 129 tests covering init, routing logic, LLM JSON parsing, disambiguation, keyword fallback, all four validator classes, and the full OpenAI provider surface (chat, stream, generate, embed, unsupported methods).
Adds boundary test at 0.89 confidence, CLI-mode interactive path coverage (mock input()), console.print_info verification, generate(stream=True), SDK exception propagation, and tighter embed/init assertions.
The CLI-mode clarification test was passing via `_create_agent` (the default-to-typescript shortcut), never entering the `input()` branch. First LLM response now uses known language + unknown project_type + low confidence so `_default_unknown_language_to_typescript` leaves it alone and `_has_unknowns` fires. Asserts `mock_input.assert_called_once()`. Also drops redundant `call_kwargs[1].get()` fallbacks — `.kwargs` is the modern accessor and sufficient here.
efadc81 to
06250c8
Compare
Three production modules had zero dedicated unit tests: RoutingAgent (agent selection logic), code validators (syntax/antipattern/AST/requirements checking), and the OpenAI provider (chat completion, streaming, error handling). Now they have 135 tests across 3 new files, all with mocked LLM and HTTP dependencies.
Review also surfaced source-level gaps worth tracking separately:
AntipatternCheckerignoresAsyncFunctionDef,validate_importsmissesfrom X import Yduplicates, and_fallback_keyword_detectionappears to be dead code in RoutingAgent.Test plan
python -m pytest tests/unit/agents/test_routing_agent.py tests/unit/agents/test_code_validators.py tests/unit/test_openai_provider.py -xvs— all 135 tests passCloses #880