Public: anyone can read this; the crew can change it.
Full suite red: test/apps-ws.test.ts #12674
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12650-full-suite-red-test-apps-ws-test-ts → main 1 commit fork 1 thread · 1 unresolved
1 file
changed +13
−6
src/apps/proxy.ts +13 −6
| @@ -1656,24 +1656,31 @@ export function connectUpstream( | ||
| 1656 | 1656 | return new Promise((resolve) => { |
| 1657 | 1657 | const socket = new WebSocket(url, { headers, protocols }); |
| 1658 | 1658 | socket.binaryType = "arraybuffer"; |
| 1659 | // Bun says why a handshake failed only in the error event ("Expected | |
| 1660 | // 101 status code: 404"); the close code is 1002 in some versions and | |
| 1661 | // 1006 in others, so both are read. | |
| 1662 | let refused = false; | |
| 1659 | 1663 | socket.addEventListener("open", () => resolve(ok(socket)), { once: true }); |
| 1660 | 1664 | socket.addEventListener( |
| 1661 | 1665 | "close", |
| 1662 | 1666 | (event) => |
| 1663 | 1667 | resolve( |
| 1664 | 1668 | err( |
| 1665 | // 1002 is Bun's word for a handshake the app answered with a | |
| 1666 | // status other than 101 — a path it does not upgrade. | |
| 1667 | event.code === 1002 | |
| 1669 | // A handshake the app answered with a status other than 101: | |
| 1670 | // a path it does not upgrade. | |
| 1671 | refused || event.code === 1002 | |
| 1668 | 1672 | ? "the app did not accept a websocket at this path" |
| 1669 | 1673 | : "the app stopped answering", |
| 1670 | 1674 | ), |
| 1671 | 1675 | ), |
| 1672 | 1676 | { once: true }, |
| 1673 | 1677 | ); |
| 1674 | // The close that follows carries the verdict; an error on its own has | |
| 1675 | // nothing to add and must not go unhandled. | |
| 1676 | socket.addEventListener("error", () => {}); | |
| 1678 | // The close that follows carries the verdict; the error only says | |
| 1679 | // whether the app answered with a non-101 status. | |
| 1680 | socket.addEventListener("error", (event) => { | |
| 1681 | const message = String((event as { message?: unknown }).message ?? ""); | |
| 1682 | if (message.includes("Expected 101")) refused = true; | |
| 1683 | }); | |
| 1677 | 1684 | }); |
| 1678 | 1685 | } |
| 1679 | 1686 |
new above
offline
Nit: the substring check is brittle against Bun rewording. Consider also treating any error that arrives before open as a refusal, if the close code is not 1000-range, or cover this with the fake-socket test mentioned in the review body.