Commit fd221b1
authored
refactor(contracts): build unavailable runtime facts once (#2291)
* refactor(contracts): build unavailable runtime facts from one policy table
freezeUnavailableFacts() classified each of the 34 UnavailablePlatformRuntimeFacts
cells with its own Object.freeze call and its own inline comment, and
createUnavailablePlatformRuntimeFacts() destructured all 38 fields off the
result before spreading them into the operations map. Replace the per-field
freezes with a single UNAVAILABLE_CELL_POLICY table (satisfies
Record<UnavailableCellKey, 'owner-stated' | 'inherits-network'>) and a loop, so
a new cell added to UnavailablePlatformRuntimeFacts must get a policy entry or
the file fails to type-check. The scattered per-field comments collapse into
one block comment above the table citing #1873. Drop the 39-line destructure;
createUnavailablePlatformRuntimeFacts now reads the frozen record's fields
directly.
Add createFullyUnavailablePlatformRuntimeFacts(), an exported constructor that
points every cell (lifecycle included) at one unavailability reason, for
missing-owner cases that have no per-family classification of their own.
Verified the table forces every cell to be classified: flipping `apps` from
'inherits-network' to 'owner-stated' (an optional cell most local runtimes
still leave unclassified) is not a type error, since the table only governs
runtime fallback and the field stays optional either way — but it does turn
into a real test failure: packages/platform-linux/src/runtime.test.ts's
`listApps` assertion goes from `{ available: false }` to `{}`, because the
loop now treats an unclassified `apps` cell as owner-stated and stops falling
back to the network gap. Reverted before committing.
* refactor(gateway): reuse the shared fully-unavailable facts constructor
unavailableProviderBinding() and unavailableProviderFacts() each hand-spelled
every UnavailablePlatformRuntimeFacts cell for a provider mode with no
registered module. The two lists had already drifted: the binding map omitted
`readiness`, the facts map included it — harmless only because both fall back
to the same 'unsupported-provider-mode' reason today, but nothing would have
caught a real divergence. Both become one-liners over
createFullyUnavailablePlatformRuntimeFacts(), so there is exactly one place
that enumerates "every cell is this one reason", and unavailableProviderLifecycleFacts()
is no longer needed.
Added a regression test asserting bind() and inspectFacts() produce
byte-for-byte equal facts for the same unregistered-provider device: it
passes today (confirmed against the pre-refactor gateway.ts, restored
temporarily to check) since the drift was reason-compatible, but it now pins
that equivalence so a future cell added to only one of the two paths fails
loudly instead of silently drifting again.
* refactor(contracts): derive unavailable-cell fallback from optionality
UNAVAILABLE_CELL_POLICY hand-duplicated which cells inherit the
network gap and which are owner-stated, restating exactly what
UnavailablePlatformRuntimeFacts's optional vs required properties
already say. Nothing checked the two against each other, so a
misclassified entry passed `satisfies Record<UnavailableCellKey,
'owner-stated' | 'inherits-network'>` and the cast at the read site
turned it into `Object.freeze({ ...undefined })` = `{}` at runtime -
a fact object missing `available` entirely.
Replaced the two-value table with a key-only UNAVAILABLE_CELLS list
and one `mapUnavailableCells` helper shared by both call sites.
freezeUnavailableFacts now reads `unavailable[cell] ?? unavailable.network`,
which TypeScript resolves without a cast because the union already
covers the optional case - a wrong classification is impossible to
express, not just checked for.
Seen red once: reverted the `?? unavailable.network` fallback (kept
`unavailable[cell]` alone) and reran
platform-runtime-unavailable.test.ts - the new `listApps` assertion
failed with the exact `{}` malformed-fact shape the policy-table bug
could produce. Restored the fallback and it passes.
Also added the missing inherits-network assertion itself
(platform-runtime-unavailable.test.ts): the existing test only
exercised owner-stated cells, so the inheriting path had no direct
coverage in this file.
* test(gateway): fold bind/inspect parity into the existing fixture
The parity test duplicated the whole gateway construction (single
apple module, inline webdriver ProviderDeviceRuntime literal) from
the test directly above it instead of reusing it. Appended the
inspectFacts() call and the equality assertion to that test instead,
and switched toEqual to toStrictEqual: toEqual ignores
undefined-valued keys, and an omitted cell is exactly how the two
facts maps could drift from each other.1 parent d23346c commit fd221b1
4 files changed
Lines changed: 178 additions & 258 deletions
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
95 | 100 | | |
96 | 101 | | |
97 | 102 | | |
| |||
Lines changed: 156 additions & 164 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
90 | 173 | | |
91 | 174 | | |
92 | 175 | | |
| |||
106 | 189 | | |
107 | 190 | | |
108 | 191 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 192 | + | |
148 | 193 | | |
149 | 194 | | |
150 | 195 | | |
151 | 196 | | |
152 | 197 | | |
153 | 198 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
170 | 215 | | |
171 | | - | |
172 | | - | |
173 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
174 | 219 | | |
175 | 220 | | |
176 | 221 | | |
177 | 222 | | |
178 | 223 | | |
179 | | - | |
180 | | - | |
| 224 | + | |
| 225 | + | |
181 | 226 | | |
182 | | - | |
183 | | - | |
| 227 | + | |
| 228 | + | |
184 | 229 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
190 | 235 | | |
191 | | - | |
192 | | - | |
| 236 | + | |
| 237 | + | |
193 | 238 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
202 | 247 | | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
208 | 253 | | |
209 | | - | |
210 | | - | |
211 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
212 | 261 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
217 | 265 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
222 | 270 | | |
223 | 271 | | |
224 | | - | |
225 | | - | |
| 272 | + | |
| 273 | + | |
226 | 274 | | |
227 | 275 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
233 | 281 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
239 | 287 | | |
240 | 288 | | |
241 | 289 | | |
| |||
254 | 302 | | |
255 | 303 | | |
256 | 304 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | 305 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
317 | 309 | | |
318 | 310 | | |
319 | 311 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
517 | 521 | | |
518 | 522 | | |
519 | 523 | | |
| |||
0 commit comments