Skip to content

Add unknown entity extractor tests - #1275

Merged
frenck merged 2 commits into
mainfrom
test/unknown-entity-extractor-tests
May 27, 2026
Merged

frenck merged 2 commits into
mainfrom
test/unknown-entity-extractor-tests

Conversation

@frenckatron

Copy link
Copy Markdown
Collaborator

Description

Add tests for the automation and Lovelace unknown entity reference extractors.

The automation tests cover the current helper behavior for extracting entity references from values, triggers, conditions, actions, and full automation configs. The Lovelace tests cover the dashboard walker across views, cards, badges, sections, picture elements, actions, visibility, and custom mushroom chips.

Motivation and Context

This ports the useful remaining test coverage from the old #1254 draft without bringing along the stale scaffold, dependency, workflow, or lockfile changes.

The tests give the unknown entity repair code a better baseline before refactoring the duplicated repair logic.

How has this been tested?

  • uv run pytest tests/ectoplasms/automation/repairs/test_unknown_entity_references.py tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py -q
  • uv run pytest -q
  • uv run ruff check tests/ectoplasms/automation tests/ectoplasms/lovelace
  • uv run ruff format --check tests/ectoplasms/automation tests/ectoplasms/lovelace
  • uv run pylint tests/ectoplasms/automation/repairs/test_unknown_entity_references.py tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py

Screenshots (if appropriate):

Not applicable.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@frenckatron frenckatron added the maintenance Generic maintenance tasks. label May 27, 2026
@coderabbitai

coderabbitai Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2b0f79ac-a204-41a3-86c0-77d438844c33

📥 Commits

Reviewing files that changed from the base of the PR and between c012db4 and 92bd52d.

📒 Files selected for processing (1)
  • tests/ectoplasms/automation/repairs/test_unknown_entity_references.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/ectoplasms/automation/repairs/test_unknown_entity_references.py

📝 Walkthrough

Walkthrough

Adds comprehensive golden-path pytest suites for unknown-entity extraction in two Spook ectoplasms: automation (value/trigger/condition/action/automation aggregation) and Lovelace (dashboard, card, badge, element traversal), plus package docstrings and test helpers/fixtures.

Changes

Automation unknown-entity extraction tests

Layer / File(s) Summary
Package setup and test imports
tests/ectoplasms/automation/__init__.py, tests/ectoplasms/automation/repairs/__init__.py, tests/ectoplasms/automation/repairs/test_unknown_entity_references.py
Module docstrings establish the test package and imports/fixture setup for extractor tests.
Value-level entity extraction tests
tests/ectoplasms/automation/repairs/test_unknown_entity_references.py
Tests for plain entity IDs, unknown-domain filtering, list/dict unwrapping, template extraction, and non-string/non-collection empty results.
Trigger / Condition / Action extraction tests
tests/ectoplasms/automation/repairs/test_unknown_entity_references.py
Recursive extraction from state/zone triggers, state/zone/and conditions, and actions (direct entity_id, target.entity_id, data dicts/templates, nested if/then/else).
Automation-level aggregation tests
tests/ectoplasms/automation/repairs/test_unknown_entity_references.py
Aggregation across trigger/condition/action sections, non-dict short-circuiting, and parametrized tests removing each section.

Lovelace unknown-entity extraction tests

Layer / File(s) Summary
Package setup, fixtures, and helper functions
tests/ectoplasms/lovelace/__init__.py, tests/ectoplasms/lovelace/repairs/__init__.py, tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py
Module docstrings, repair fixture, and wrappers to call name-mangled private extraction methods.
Dashboard-level extraction tests
tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py
Tests for empty/malformed dashboards and full walk through views, badges, cards, and sections.
Card-level extraction tests
tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py
Entity extraction for many card shapes: entity fields, mixed entities lists, camera_image, nested cards, actions/service-data, conditions, visibility, header/footer, picture-elements, and custom chips.
Badge and element extraction tests
tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py
Badge extraction from string/dict/list forms and element extraction including nested elements, visibility conditions, and action targets.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • frenck/spook#1173: Related Lovelace badge/entity extraction tests and handling.
  • frenck/spook#1076: Related automation unknown-entity extraction tests exercising the same extractor functions.
  • frenck/spook#977: Earlier automation entity extraction tests with overlapping coverage.

Suggested reviewers

  • frenck

Poem

🐇 In tests I hop through cards and rules,

I sniff out entities like tiny jewels.
From triggers to badges, I trace each line,
Golden paths shine — the tests pass fine.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding test coverage for unknown entity extractors in both automation and Lovelace components.
Description check ✅ Passed The description provides relevant context about the test additions, motivation (porting from a previous draft to establish baseline coverage before refactoring), and testing methods used.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/unknown-entity-extractor-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

codecov-commenter commented May 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.35%. Comparing base (4adf17f) to head (92bd52d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1275      +/-   ##
==========================================
+ Coverage   36.84%   46.35%   +9.50%     
==========================================
  Files         117      117              
  Lines        3029     3029              
  Branches      411      411              
==========================================
+ Hits         1116     1404     +288     
+ Misses       1898     1587     -311     
- Partials       15       38      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/ectoplasms/automation/repairs/test_unknown_entity_references.py`:
- Around line 185-193: The test test_action_if_then_else_nested uses a subset
assertion (<=) which permits extra unexpected entities; update the assertion to
require exact equality by replacing the subset check with an equality check so
the result must equal {"binary_sensor.door", "light.hall"} when calling
extract_entities_from_action_config(hass, config).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 29ad5ddd-b38a-42b0-8bf1-1bb22ab1935f

📥 Commits

Reviewing files that changed from the base of the PR and between 4adf17f and c012db4.

📒 Files selected for processing (6)
  • tests/ectoplasms/automation/__init__.py
  • tests/ectoplasms/automation/repairs/__init__.py
  • tests/ectoplasms/automation/repairs/test_unknown_entity_references.py
  • tests/ectoplasms/lovelace/__init__.py
  • tests/ectoplasms/lovelace/repairs/__init__.py
  • tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py

@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds pytest coverage for the unknown-entity-reference extractors in the automation and Lovelace ectoplasms. The tests pin down the current observable behavior of the helpers/private walkers so an upcoming refactor (consolidating duplicated repair logic into a single recursive walker) can be validated against a baseline. This is a tests-only change with no production code modified.

Changes:

  • New automation test module covering extract_entities_from_value, the trigger/condition/action extractors, and the top-level extract_entities_from_automation_config orchestrator (including a parametrized "missing section" case).
  • New Lovelace test module that exercises the name-mangled private walkers on SpookRepair for dashboards, views, sections, cards, badges, picture elements, actions, visibility, and mushroom chips.
  • New __init__.py package markers for the automation and lovelace test subpackages and their repairs children.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/ectoplasms/automation/init.py Marks the automation tests subpackage.
tests/ectoplasms/automation/repairs/init.py Marks the automation repairs tests subpackage.
tests/ectoplasms/automation/repairs/test_unknown_entity_references.py Async tests pinning the automation extractor behavior across value/trigger/condition/action/full-config paths.
tests/ectoplasms/lovelace/init.py Marks the Lovelace tests subpackage.
tests/ectoplasms/lovelace/repairs/init.py Marks the Lovelace repairs tests subpackage.
tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py Tests for SpookRepair's name-mangled dashboard/card/badge/element walkers, including mushroom chips and visibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Generic maintenance tasks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants