Commit d9e06ba
Make the router's routing state authoritative instead of sniffed
Disabling the router restored the original write method but left the
write_without_cli_ui marker method installed on the stream. Since
enabled? checked for that marker, the router reported itself enabled
while routing was actually inactive, and a later enable refused to do
anything. The process was stuck: output permanently bypassed routing,
and Capture#run's assert_enabled! still passed while captures silently
collected nothing.
with_enabled compounded this by always disabling on exit, so entering
that scope in a process that had already enabled the router (the common
production state) permanently broke routing.
Routing state now lives in a private stream => original-write registry
rather than being inferred from a marker method on the stream, so
nothing on the stream can make enabled? lie:
* enable/disable act per stream instead of all-or-nothing, so a process
that ends up half-routed (e.g. $stdout reassigned after enable, or
$stderr aliased to $stdout) can recover. with_enabled unroutes
exactly the streams it routed, leaving an already-enabled router
alone.
* Writer holds the stream's pre-routing write method, so it no longer
dispatches through write_without_cli_ui. A write already in flight on
another thread survives a concurrent disable.
* deactivate restores only a write it displaced. Previously every
disable left a singleton copy of the class's write behind, shadowing
the class method for the life of the stream.
* write_without_routing is the supported way to bypass the router.
Callers currently reach for the write_without_cli_ui alias directly
(dev's cd/edit commands do, unguarded); that alias only exists while
the stream is routed, and now really does disappear on disable.
* NotEnabled moves out of class << self, where it was only reachable as
StdoutRouter.singleton_class::NotEnabled - i.e. nobody could rescue
the error Capture#run raises.
* ensure_activated is now just enable, which is idempotent.
Co-authored-by: River <river@shopify.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 83cbecb commit d9e06ba
2 files changed
Lines changed: 204 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | | - | |
16 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
17 | 24 | | |
18 | 25 | | |
| 26 | + | |
19 | 27 | | |
20 | 28 | | |
21 | 29 | | |
| |||
38 | 46 | | |
39 | 47 | | |
40 | 48 | | |
41 | | - | |
| 49 | + | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
| |||
309 | 317 | | |
310 | 318 | | |
311 | 319 | | |
312 | | - | |
313 | | - | |
314 | 320 | | |
315 | 321 | | |
316 | 322 | | |
| |||
339 | 345 | | |
340 | 346 | | |
341 | 347 | | |
| 348 | + | |
| 349 | + | |
342 | 350 | | |
343 | 351 | | |
344 | | - | |
| 352 | + | |
345 | 353 | | |
346 | 354 | | |
347 | | - | |
| 355 | + | |
348 | 356 | | |
349 | 357 | | |
350 | 358 | | |
351 | 359 | | |
352 | 360 | | |
353 | | - | |
| 361 | + | |
354 | 362 | | |
355 | 363 | | |
| 364 | + | |
| 365 | + | |
356 | 366 | | |
357 | 367 | | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
| 368 | + | |
363 | 369 | | |
364 | 370 | | |
365 | 371 | | |
366 | 372 | | |
367 | | - | |
| 373 | + | |
368 | 374 | | |
369 | 375 | | |
370 | 376 | | |
371 | 377 | | |
372 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
373 | 391 | | |
374 | | - | |
375 | | - | |
376 | | - | |
| 392 | + | |
377 | 393 | | |
378 | 394 | | |
379 | 395 | | |
380 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
381 | 417 | | |
382 | 418 | | |
| 419 | + | |
383 | 420 | | |
384 | 421 | | |
385 | | - | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
386 | 427 | | |
387 | 428 | | |
388 | 429 | | |
389 | 430 | | |
390 | | - | |
| 431 | + | |
391 | 432 | | |
392 | | - | |
| 433 | + | |
| 434 | + | |
393 | 435 | | |
| 436 | + | |
394 | 437 | | |
395 | 438 | | |
396 | 439 | | |
397 | 440 | | |
| 441 | + | |
398 | 442 | | |
399 | 443 | | |
400 | 444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 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 | + | |
27 | 166 | | |
28 | 167 | | |
29 | 168 | | |
| |||
0 commit comments