Commit df96851
fix: recognize BrokenResourceError, close silent-branch test gap
Addresses two well-researched review findings, both verified directly
against the pinned mcp==1.28.1/anyio==4.10.0 in this repo's venv before
acting on them:
1. _is_only_closed_resource_errors (renamed
_is_only_disconnect_teardown_errors) only recognized
anyio.ClosedResourceError, missing its sibling anyio.BrokenResourceError
-- confirmed a plain Exception subclass, not a subclass of
ClosedResourceError. Per the reviewer's anyio-internals walkthrough,
which one surfaces for the exact same disconnect race depends on which
end of the memory stream closes first (our end closing raises Closed;
the peer's streamable_http terminate() closing first can wake a parked
sender into raising Broken instead). This repo already treats the two
as an equivalent pair for streamable-HTTP memory-stream teardown
elsewhere (tests/src/haos_runtime.py's transient-error tuple) -- now
the classifier does too. Not a regression either way: a
BrokenResourceError-only leaf simply fails closed (stays at ERROR)
without this, same as before the PR existed.
Also independently confirmed the reviewer's mcp-version finding while
verifying this: at the exact pinned mcp==1.28.1, Server._handle_request
already catches (BrokenResourceError, ClosedResourceError) around
respond() and drops it at DEBUG (mcp/server/lowlevel/server.py:805-815)
-- absent at older mcp versions. The live-validated production capture
this PR's tests describe as "the shape actually logged in production"
is accurate for whichever mcp version that deployment has (older,
given third-party deps aren't reinstalled per ha-mcp reload), not a
version-independent guarantee -- worth keeping in mind if this classifier
ever needs revisiting again as mcp gets upgraded.
2. No test constructed a genuine ModuleNotFoundError for exactly
ha_mcp.log_filters to prove the "older ha-mcp" branch in
_install_log_filters_if_available() actually stays silent -- the
existing test only exercised the module-present-but-attribute-missing
ImportError case, and asserted on survival, not on log output. Dropping
the err.name check would have left the suite green while every older
install gained a startup warning. Added
TestInstallLogFiltersIfAvailable: calls the function directly (not
through the full _serve()/_thread_main harness) with caplog, covering
all three branches -- genuinely missing module (silent), attribute
missing (warns), and a different missing dependency inside the import
(warns, naming it) -- using the same __path__ = [] sys.modules
technique _stub_ha_mcp_surface already established for this class of
problem.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 69f4d88 commit df96851
3 files changed
Lines changed: 181 additions & 24 deletions
File tree
- src/ha_mcp
- tests/src/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
101 | 116 | | |
102 | | - | |
| 117 | + | |
103 | 118 | | |
104 | 119 | | |
105 | 120 | | |
106 | | - | |
| 121 | + | |
107 | 122 | | |
108 | 123 | | |
109 | 124 | | |
| |||
118 | 133 | | |
119 | 134 | | |
120 | 135 | | |
121 | | - | |
122 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
123 | 139 | | |
124 | 140 | | |
125 | 141 | | |
| |||
135 | 151 | | |
136 | 152 | | |
137 | 153 | | |
138 | | - | |
| 154 | + | |
139 | 155 | | |
140 | 156 | | |
141 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2694 | 2694 | | |
2695 | 2695 | | |
2696 | 2696 | | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
2697 | 2777 | | |
2698 | 2778 | | |
2699 | 2779 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
19 | 25 | | |
20 | 26 | | |
21 | 27 | | |
| |||
100 | 106 | | |
101 | 107 | | |
102 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
103 | 123 | | |
104 | 124 | | |
105 | 125 | | |
| |||
118 | 138 | | |
119 | 139 | | |
120 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
121 | 156 | | |
122 | 157 | | |
123 | 158 | | |
| |||
174 | 209 | | |
175 | 210 | | |
176 | 211 | | |
177 | | - | |
| 212 | + | |
178 | 213 | | |
179 | 214 | | |
180 | 215 | | |
181 | 216 | | |
182 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
183 | 224 | | |
184 | 225 | | |
185 | 226 | | |
186 | | - | |
| 227 | + | |
187 | 228 | | |
188 | 229 | | |
189 | 230 | | |
190 | 231 | | |
191 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
192 | 247 | | |
193 | 248 | | |
194 | 249 | | |
195 | 250 | | |
196 | 251 | | |
197 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
198 | 259 | | |
199 | 260 | | |
200 | 261 | | |
201 | 262 | | |
202 | | - | |
| 263 | + | |
203 | 264 | | |
204 | 265 | | |
205 | 266 | | |
| |||
0 commit comments