Skip to content

Bootstrap pytest scaffold with golden-path tests for entity-reference extractors - #1254

Closed
frenckatron wants to merge 2 commits into
frenck:mainfrom
frenckatron:frenckatron/bootstrap-test-scaffold
Closed

frenckatron wants to merge 2 commits into
frenck:mainfrom
frenckatron:frenckatron/bootstrap-test-scaffold

Conversation

@frenckatron

@frenckatron frenckatron commented May 20, 2026 •

Copy link
Copy Markdown
Collaborator

What

Bootstrap a pytest scaffold for Spook using pytest-homeassistant-custom-component, and pin down the synchronous, hass-free extractor helpers used by the entity-reference repairs and shared utilities.

Why

Spook had no test harness at all. Without one, every refactor — like the planned consolidation of the four-way per-domain unknown-reference repairs into a single recursive walker, or the upcoming repairs.py base-class extraction — has to be reviewed by hand. The HA core's pytest-homeassistant-custom-component plugin gives us a real hass fixture and matches the workflow contributors already know.

How

  • pyproject.toml gets pytest-homeassistant-custom-component in dev-dependencies and a [tool.pytest.ini_options] block with asyncio_mode = "auto" so plain async def tests don't each need @pytest.mark.asyncio. requires-python is bumped to >=3.13.2 to match the plugin's HA pin.
  • .github/workflows/test.yaml runs uv sync --frozen --dev and uv run pytest tests -v on every push and PR on Python 3.13.
  • tests/conftest.py autouse-enables enable_custom_integrations so Spook is loadable in every test.
  • Golden-path test suites land at the module boundary, not the class boundary:
    • tests/ectoplasms/automation/repairs/test_unknown_entity_references.py — extract_entities_from_value, extract_entities_from_trigger_config, extract_entities_from_condition_config, extract_entities_from_action_config, and the extract_entities_from_automation_config orchestrator.
    • tests/ectoplasms/lovelace/repairs/test_unknown_entity_references.py — dashboard, card, badge, and element walkers.
    • tests/ectoplasms/script/repairs/test_unknown_entity_references.py — the sync extract_entities_from_trigger_config blueprint-input walker.
    • tests/test_util.py — the three sync helpers reused across ectoplasms (is_template_string, split_comma_separated_entity_ids, extract_template_strings_from_config).

Testing

  • uv sync --frozen --dev
  • uv run pytest tests -v → 84 passed in 0.83s locally.
  • uv run ruff check tests/ and uv run ruff format --check tests/ are clean.

Quality Report

Changes: 16 files changed, 2412 insertions(+), 1225 deletions(-)

Code scan: 1 issue(s) found

  • uv.lock:0 — 1482 lines added

Tests: failed (command not found)

Branch hygiene: 1 issue(s)

  • Branch is not pushed to remote

Generated by Kōan post-mission quality pipeline

… extractors

Spook had no test infrastructure. This adds:

- A `tests/` package with `conftest.py` enabling pytest-homeassistant-custom-component.
- 47 golden-path tests pinning the current behavior of the two riskiest extractors:
  - `ectoplasms/automation/repairs/unknown_entity_references.py` module-level helpers
  - `ectoplasms/lovelace/repairs/unknown_entity_references.py` private dashboard walker
- A `Tests` GitHub Actions workflow that runs `pytest` on every push and PR.
- `pytest-homeassistant-custom-component` added to `tool.uv.dev-dependencies`.
- `requires-python` bumped from `>=3.13` to `>=3.13.2` to match the floor that
  current Home Assistant releases (and the pytest plugin) require.

The tests lock down behavior before the upcoming flatten/refactor of the two
extractors so any regression there will fail loudly.
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1d1d1e94-1845-4c41-b4b0-1bc705022037

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit 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.

Add module-level tests for the synchronous, hass-free helpers that the
existing scaffold did not yet pin down:

- `tests/ectoplasms/script/repairs/test_unknown_entity_references.py`
  covers the `extract_entities_from_trigger_config` walker used by the
  script repair to harvest entity IDs out of blueprint trigger inputs.
- `tests/test_util.py` covers the three pure helpers in
  `custom_components/spook/util.py` that ectoplasms rely on:
  `is_template_string`, `split_comma_separated_entity_ids`, and
  `extract_template_strings_from_config`.

The async, hass-aware helpers in `util.py` and the rest of the script
repair remain integration-test territory.

84 tests pass locally.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@frenckatron frenckatron mentioned this pull request May 27, 2026
2 of 7 tasks
@frenckatron

Copy link
Copy Markdown
Collaborator Author

Closing this as superseded by #1274.

The useful helper/script extractor tests were ported there using the project PR template. The remaining scaffold/workflow/dependency/lockfile changes in this draft are stale and conflict with current main.

@frenckatron frenckatron mentioned this pull request May 27, 2026
2 of 7 tasks
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