Commit 1381851
test: address Patch76 review findings on PR #1406
Three findings from Patch76's review of #1406:
1. **Discriminator test wasn't actually discriminating** —
``test_event_capture_short_circuits_rest_scan`` previously seeded
``get_states()`` to return ``automation.from_rest`` on every call and
asserted ``result in {"automation.from_event", "automation.from_rest"}``.
That accepts both outcomes, so a regression that broke the closure-cell
short-circuit (forcing ``sample()`` to always fall through to
``get_states()``) would silently pass — REST would win every time. Now
seeds ``get_states()`` with a side_effect that returns empty on the
first call (post-subscribe sample) and the REST entity on subsequent
calls, then asserts ``result == "automation.from_event"`` (deterministic
discriminator: cell wins → event entity, regression → REST entity) and
``call_count == 1`` (the cell short-circuit means the post-event
re-sample never touches REST).
2. **Duplicate-unique-id collision branch untested** — Patch76 noted the
first-wins guard in ``event_filter`` (``util_helpers.py:1197``) had no
test pinning the contract. Added
``test_duplicate_unique_id_collision_first_wins`` which fires two
matching state_changed events back-to-back and asserts both
"automation.first wins" and "warning logged naming both entity_ids."
3. **``last_api_error`` wedged-channel branch untested** — Patch76 noted
the conditional warning at ``util_helpers.py:1222`` had no test pinning
the "REST channel down" vs "automation never published" discrimination
the code exists to make. Added
``test_wedged_rest_channel_surfaces_last_api_error`` which seeds
``get_states()`` to raise ``HomeAssistantAPIError`` on every call and
asserts the timeout warning includes "every REST sample failing" and
the last error message string.
Rebased onto current upstream/master. Mechanical conflict resolution per
Patch76: the ``_POLL_CADENCE`` deletion wins, taking #1389's measurement
instrumentation with it. ``_poll_for_automation_entity`` no longer needs
the cadence loop or the elapsed-time instrumentation because the WS
event-driven path resolves sub-second on the happy path and the REST
fallback uses uniform polling. The redundant local ``import time`` inside
``upsert_automation_config`` is also gone now that the top-level
``import time`` (added by #1389) remains for the unique_id-generation use
at ``time.time() * 1000``.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 1967976 commit 1381851
2 files changed
Lines changed: 118 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
895 | 895 | | |
896 | 896 | | |
897 | 897 | | |
898 | | - | |
899 | | - | |
900 | 898 | | |
901 | 899 | | |
902 | 900 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
979 | 979 | | |
980 | 980 | | |
981 | 981 | | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
991 | 1013 | | |
992 | 1014 | | |
993 | 1015 | | |
994 | 1016 | | |
995 | 1017 | | |
996 | | - | |
| 1018 | + | |
| 1019 | + | |
997 | 1020 | | |
998 | 1021 | | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
999 | 1025 | | |
1000 | 1026 | | |
1001 | 1027 | | |
| |||
1008 | 1034 | | |
1009 | 1035 | | |
1010 | 1036 | | |
1011 | | - | |
1012 | | - | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
1021 | 1044 | | |
1022 | 1045 | | |
1023 | 1046 | | |
| |||
1061 | 1084 | | |
1062 | 1085 | | |
1063 | 1086 | | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
0 commit comments