Skip to content

Cover UptimeConfigFlow end-to-end (restart_now / restart_later / already_spooked) #1258

@frenckatron

Description

@frenckatron

Why This Matters

This is the user's explicit starter target. UptimeConfigFlow at custom_components/spook/config_flow.py:14-61 is small but does three things no static analyzer can catch: (1) aborts with already_spooked if an entry already exists, (2) writes a magic sentinel hass.data[DOMAIN] = "Boo!" that triggers a real Home Assistant restart in __init__.py:53-55, and (3) routes through a menu step. That sentinel is a string literal cross-coupling two files — exactly the kind of thing a rename will quietly break without a test. Locking the flow's behavior also establishes the canonical flow.async_init / flow.async_configure pattern that #1259 and any future flow tests will copy.

Approach

Add tests/test_config_flow.py. Use hass.config_entries.flow.async_init(DOMAIN, context={"source": SOURCE_USER}) to start the flow, then drive it with async_configure. Cover four paths: (a) initial async_step_user returns a form, (b) submitting the empty form reaches the choice_restart menu, (c) selecting restart_later creates an entry titled "Your homie" with data={}, (d) selecting restart_now creates the entry AND asserts hass.data[DOMAIN] == "Boo!", (e) a second flow with an existing MockConfigEntry aborts with reason already_spooked. Do NOT let the "Boo!" sentinel actually restart HA in the test — either don't call async_setup_entry after the flow, or patch hass.async_stop.

Acceptance Criteria

  • All five flow paths above are asserted
  • The "Boo!" sentinel value is referenced via const.DOMAIN + a named constant, not as a magic string in the test
  • Tests run in <1s and don't trigger a real HA shutdown
  • CI is green on the new test file

Risks & Caveats

The "Boo!" sentinel is a string literal — if a future PR renames it, the test must fail loudly. Consider promoting it to a named constant in const.py (e.g. RESTART_REQUESTED_SENTINEL) as part of this PR; otherwise the test just freezes the typo. The restart side-effect lives in __init__.py, not the config flow, so be careful not to accidentally trigger async_setup_entry in the test fixture.

Scores

  • Impact: ████████░░ 8/10
  • Difficulty: ████░░░░░░ 4/10
  • Short-Term ROI: █████████░ 9/10
  • Long-Term Value: ████████░░ 8/10

Priority

Immediate

Dependencies

#1257

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions