Review fix: duplicate admin selections surface as a field error
Review round 3 (Codex gpt-5.6-terra, LOW): a duplicate raw submission reached set_admin_ids and crashed the flow with an unhandled ValueError; the flow now rejects duplicates as invalid_admin with a test proving the database is untouched. Suite: 905 passed.
This commit is contained in:
@@ -184,6 +184,11 @@ class NestQuestOptionsFlow(config_entries.OptionsFlowWithConfigEntry):
|
|||||||
# backs the raw-input path up so an unknown id can never
|
# backs the raw-input path up so an unknown id can never
|
||||||
# reach the allowlist.
|
# reach the allowlist.
|
||||||
errors[CONF_ADMIN_USER_IDS] = "invalid_admin"
|
errors[CONF_ADMIN_USER_IDS] = "invalid_admin"
|
||||||
|
elif admin_ids_present and len(set(admin_ids)) != len(admin_ids):
|
||||||
|
# set_admin_ids refuses duplicates with ValueError; a flow
|
||||||
|
# submission must surface that as a field error instead of
|
||||||
|
# an unhandled crash.
|
||||||
|
errors[CONF_ADMIN_USER_IDS] = "invalid_admin"
|
||||||
if errors:
|
if errors:
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init",
|
step_id="init",
|
||||||
|
|||||||
@@ -576,3 +576,32 @@ def test_options_flow_submit_without_admin_key_keeps_allowlist(tmp_path) -> None
|
|||||||
assert await_gather(list_admin_ids(database)) == ["u1"]
|
assert await_gather(list_admin_ids(database)) == ["u1"]
|
||||||
finally:
|
finally:
|
||||||
_run(database.close())
|
_run(database.close())
|
||||||
|
|
||||||
|
|
||||||
|
def test_options_flow_duplicate_selection_refused(tmp_path) -> None:
|
||||||
|
"""Duplicate ids surface as a field error, not an unhandled
|
||||||
|
ValueError from the business layer."""
|
||||||
|
database = _open_allowlist_db(tmp_path, "picker-dupe.db")
|
||||||
|
try:
|
||||||
|
from custom_components.nestquest.admin_allowlist import (
|
||||||
|
list_admin_ids,
|
||||||
|
set_admin_ids,
|
||||||
|
)
|
||||||
|
|
||||||
|
_run(set_admin_ids(database, ["u1"]))
|
||||||
|
entry = _make_entry()
|
||||||
|
flow = _make_flow(
|
||||||
|
entry,
|
||||||
|
users=[_user("u1", "Joshua"), _user("u2", "Sam")],
|
||||||
|
database=database,
|
||||||
|
)
|
||||||
|
result = _run(
|
||||||
|
flow.async_step_init(
|
||||||
|
{**VALID_INPUT, CONF_ADMIN_USER_IDS: ["u2", "u2"]}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assert result["type"] == "form"
|
||||||
|
assert result["errors"] == {CONF_ADMIN_USER_IDS: "invalid_admin"}
|
||||||
|
assert await_gather(list_admin_ids(database)) == ["u1"]
|
||||||
|
finally:
|
||||||
|
_run(database.close())
|
||||||
|
|||||||
Reference in New Issue
Block a user