Commit d259934
committed
fix(opencode): fail open on empty token output, guard missing output.headers (review)
Addresses two Copilot review comments on #197:
- fetchToken() returned stdout.trim() unconditionally. If `ucode
auth-token` ever exits 0 with empty/whitespace-only stdout, the
plugin would cache and send Authorization: Bearer <empty>,
clobbering a possibly-still-valid bootstrap token for the full TTL
window instead of failing open. Empty output now throws, so the
hook's catch block fails open as intended.
- The chat.headers hook assumed output.headers always exists. If
opencode ever invokes the hook without a pre-populated headers
object, the assignment would throw -- caught silently by the
existing try/catch, but the refresh would never apply. Defensively
initialize output.headers before writing to it.
Both are proven by new Node-executed runtime tests (matching the
class of test that caught the input.provider?.id bug): each new test
was verified to fail against the pre-fix code and pass against the
fix, not just pass trivially.1 parent 7fce618 commit d259934
2 files changed
Lines changed: 54 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
226 | 233 | | |
227 | 234 | | |
228 | 235 | | |
| |||
259 | 266 | | |
260 | 267 | | |
261 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
262 | 274 | | |
263 | 275 | | |
264 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
522 | | - | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
523 | 529 | | |
524 | 530 | | |
525 | 531 | | |
| |||
528 | 534 | | |
529 | 535 | | |
530 | 536 | | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
535 | 542 | | |
536 | 543 | | |
537 | 544 | | |
| |||
544 | 551 | | |
545 | 552 | | |
546 | 553 | | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
547 | 559 | | |
548 | 560 | | |
549 | 561 | | |
550 | 562 | | |
551 | 563 | | |
552 | | - | |
| 564 | + | |
553 | 565 | | |
554 | 566 | | |
555 | 567 | | |
| |||
558 | 570 | | |
559 | 571 | | |
560 | 572 | | |
561 | | - | |
| 573 | + | |
562 | 574 | | |
563 | 575 | | |
564 | 576 | | |
| |||
589 | 601 | | |
590 | 602 | | |
591 | 603 | | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
592 | 626 | | |
593 | 627 | | |
594 | 628 | | |
| |||
0 commit comments