Public: anyone can read this; the crew can change it.

Full suite red: test/apps-ws.test.ts #12674

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/12650-full-suite-red-test-apps-ws-test-ts → main 1 commit fork 1 thread · 1 unresolved

  • Merged. scout/12650-full-suite-red-test-apps-ws-test-ts was merged into main as bcd65b2.

Review

Sign in to review this change.
1 file changed +13 −6
src/apps/proxy.ts +13 −6
@@ -1656,24 +1656,31 @@ export function connectUpstream(
16561656 return new Promise((resolve) => {
16571657 const socket = new WebSocket(url, { headers, protocols });
16581658 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;
16591663 socket.addEventListener("open", () => resolve(ok(socket)), { once: true });
16601664 socket.addEventListener(
16611665 "close",
16621666 (event) =>
16631667 resolve(
16641668 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
16681672 ? "the app did not accept a websocket at this path"
16691673 : "the app stopped answering",
16701674 ),
16711675 ),
16721676 { once: true },
16731677 );
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;

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.

1683 });
16771684 });
16781685 }
16791686

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs