Skip to content

Commit c4b46b7

Browse files
Patch76claude
andcommitted
test: add coverage gaps from PR homeassistant-ai#1168 review (Blockers 1/4/5 + Boy-Scout e/f/g)
Addresses kingpanther13's PR homeassistant-ai#1168 review test-coverage findings: Blocker #1 — DEEP_SEARCH_KEYS scenes: - Added 'scenes' to the test-helper tuple at tests/src/e2e/tools/test_deep_search.py:14; every default-call deep_search test had been silently skipping the scenes bucket because the iteration source didn't include it. - Updated test_deep_search_all_types to count scenes in the result tally. - Generalised test_deep_search_limit's count to iterate DEEP_SEARCH_KEYS so any future bucket addition flows through automatically. - Added test_deep_search_default_includes_scenes locking the contract that a default-call response must include the scenes bucket. Blocker #4 — DELETE blocklist coverage: - Added test_api_post_blocks_scene_config_delete next to test_api_post_blocks_scene_config_write. Sandbox exposes only api_post/api_get (no api_delete), so the test exercises the delete- flavored attack pattern (empty-body POST) and asserts the path-prefix blocklist still rejects it. Blocker #5 — 404 → ENTITY_NOT_FOUND: - ha_config_get_scene's exception catch now passes entity_id alongside scene_id so the helper's 404 classifier picks ENTITY_NOT_FOUND instead of the generic RESOURCE_NOT_FOUND fallback. Scenes are entities, and agents branching on the not-found code lose the scenes-are-entities signal otherwise. - Added TestSceneRestClientErrorMapping with two unit tests: test_get_scene_404_surfaces_as_entity_not_found locks the 404 path, test_set_scene_400_surfaces_with_scene_id_context covers Boy-Scout g (upsert 400 path — highest-likelihood scene failure when an LLM submits malformed entity state). Boy-Scout — additional test gaps closed: - (e) E2E rename scenario: test_scene_rename_decouples_entity_id_from_storage_key in tests/src/e2e/workflows/scenes/test_lifecycle.py exercises the full create → get → python_transform → remove path against a scene whose storage key and entity_id slug diverge. Locks the _resolve_scene_entity_id contract end-to-end against the no-warning invariant the BAT validation surfaced as broken before it landed. - (f) Phase 2.5 registry-augmentation: TestSceneRegistryAugmentation in tests/src/unit/test_smart_search_scene_phase25.py with two tests — one locking the alias-on-divergence behaviour, one verifying that a failing entity-registry list does not break the scene branch and falls through to storage-id keyed lookup. - (g) upsert 400 path: covered alongside Blocker #5 in TestSceneRestClientErrorMapping (one test class for both). Plus partial-failure coverage for Boy-Scout d (silent failures surfacing, landed in the previous commit): TestSceneFetchPartialFailure with test_per_id_failures_surface_partial and a test_no_partial_flag_when_everything_clean negative case so the 'partial' field doesn't accidentally always-be-set. ruff + mypy clean; full unit suite passes 1982 tests (was 1976; +6 new unit tests across the new test classes). E2E tests run in CI only. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5c5ac79 commit c4b46b7

6 files changed

Lines changed: 604 additions & 103 deletions

File tree

src/ha_mcp/tools/tools_config_scenes.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,17 @@ async def ha_config_get_scene(
152152
except ToolError:
153153
raise
154154
except Exception as e:
155+
# Pass `entity_id` so a 404 from rest_client surfaces as
156+
# ENTITY_NOT_FOUND (not the generic RESOURCE_NOT_FOUND fallback).
157+
# The naive ``scene.{scene_id}`` form is good enough at error
158+
# time — registry resolution happens inside the try block and
159+
# may not have run when an exception escapes to here.
155160
exception_to_structured_error(
156161
e,
157-
context={"scene_id": scene_id},
162+
context={
163+
"scene_id": scene_id,
164+
"entity_id": f"scene.{scene_id}",
165+
},
158166
suggestions=[
159167
"Verify scene_id exists using ha_search_entities(domain_filter='scene')",
160168
"Check Home Assistant connection",

0 commit comments

Comments
 (0)