mirror of
https://github.com/Matysh/houseplan-card
synced 2026-07-31 16:38:31 +00:00
HP-1470-02: only refuse a plan reference that is NEW and already broken
CI caught what the local pure suite cannot run. Four HA-harness tests store a plan url whose file is not there — and so, sooner or later, will a user: files disappear from outside Home Assistant, and one of them is what the 'broken plan' repair exists to report. Refusing every write that names a missing file would have locked the owner out of every edit, including detaching it. So the check compares against the stored configuration and only refuses names it has not seen before, which is exactly the pick-then-delete window it was written for. The repairs test now attaches a real plan and removes the file behind it; the quota test budgets from what the shared test config directory already holds instead of assuming an empty folder.
This commit is contained in:
@@ -784,8 +784,22 @@ async def test_repair_issue_goes_when_its_space_does(
|
||||
client = await hass_ws_client(hass)
|
||||
registry = ir.async_get(hass)
|
||||
|
||||
gone = "/api/houseplan/content/plans/_/nosuchfile.png"
|
||||
rev = (await _save(client, await _cfg([{"id": "r7", "plan_url": gone}]), 0))["result"]["rev"]
|
||||
# A reference can only go bad AFTER it is stored — config/set refuses a new
|
||||
# one that is already broken (HP-1470-02). So: attach a real plan, then let
|
||||
# the file disappear the way it does in life, from outside Home Assistant.
|
||||
import os
|
||||
|
||||
from custom_components.houseplan.const import PLANS_DIR
|
||||
|
||||
url, name = await _upload(client, "r7", b"PLAN")
|
||||
rev = (await _save(client, await _cfg([{"id": "r7", "plan_url": url}]), 0))["result"]["rev"]
|
||||
await hass.async_block_till_done()
|
||||
assert registry.async_get_issue(HP_DOMAIN, "broken_plan_r7") is None, "the file is there"
|
||||
|
||||
await hass.async_add_executor_job(
|
||||
os.remove, os.path.join(hass.config.path(PLANS_DIR), name)
|
||||
)
|
||||
rev = (await _save(client, await _cfg([{"id": "r7", "plan_url": url}]), rev))["result"]["rev"]
|
||||
await hass.async_block_till_done()
|
||||
assert registry.async_get_issue(HP_DOMAIN, "broken_plan_r7") is not None
|
||||
|
||||
@@ -940,6 +954,9 @@ async def test_startup_sweep_collects_what_no_commit_will(
|
||||
await _setup(hass)
|
||||
client = await hass_ws_client(hass)
|
||||
files, _plans, p = _paths(hass)
|
||||
# the plan it names has to exist: config/set refuses a NEW broken
|
||||
# reference (HP-1470-02). The orphans still arrive after the save.
|
||||
await _seed_aged(hass, [p["kept_plan"]])
|
||||
assert (await _save(client, await _referenced_config(), 0))["success"]
|
||||
|
||||
await _seed_aged(hass, list(p.values()))
|
||||
@@ -967,6 +984,9 @@ async def test_periodic_sweep_collects_too(
|
||||
await _setup(hass)
|
||||
client = await hass_ws_client(hass)
|
||||
_files, _plans, p = _paths(hass)
|
||||
# the plan it names has to exist: config/set refuses a NEW broken
|
||||
# reference (HP-1470-02). The orphans still arrive after the save.
|
||||
await _seed_aged(hass, [p["kept_plan"]])
|
||||
assert (await _save(client, await _referenced_config(), 0))["success"]
|
||||
|
||||
await _seed_aged(hass, list(p.values()))
|
||||
@@ -994,6 +1014,9 @@ async def test_sweep_and_a_config_write_do_not_race(
|
||||
await _setup(hass)
|
||||
client = await hass_ws_client(hass)
|
||||
_files, plans, p = _paths(hass)
|
||||
# the plan it names has to exist: config/set refuses a NEW broken
|
||||
# reference (HP-1470-02). The orphans still arrive after the save.
|
||||
await _seed_aged(hass, [p["kept_plan"]])
|
||||
rev = (await _save(client, await _referenced_config(), 0))["result"]["rev"]
|
||||
|
||||
# an aged, currently unreferenced plan that the commit below adopts
|
||||
@@ -1192,9 +1215,19 @@ async def test_uploads_are_bounded_by_a_store_quota(
|
||||
"""HP-1470-01: nothing is deleted for being old, so growth stops at the door."""
|
||||
from custom_components.houseplan import websocket_api as wsapi
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from custom_components.houseplan.const import PLANS_DIR
|
||||
from custom_components.houseplan.plans import dir_usage
|
||||
|
||||
await _setup(hass)
|
||||
client = await hass_ws_client(hass)
|
||||
monkeypatch.setattr(wsapi, "MAX_PLANS_FILES", 2)
|
||||
# every test in this module shares one config directory, so the plans folder
|
||||
# is not empty here — budget two more from whatever is already stored
|
||||
stored, _b = await hass.async_add_executor_job(
|
||||
lambda: dir_usage(Path(hass.config.path(PLANS_DIR)))[::-1]
|
||||
)
|
||||
monkeypatch.setattr(wsapi, "MAX_PLANS_FILES", stored + 2)
|
||||
|
||||
await _upload(client, "q1", b"one")
|
||||
await _upload(client, "q1", b"two")
|
||||
|
||||
Reference in New Issue
Block a user