From b5483ff5e125d308d7340c4abb1be9c585f29c7b Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Sun, 23 Aug 2026 01:14:31 +0500 Subject: [PATCH] patch capture issues --- scripts/patch-node-modules.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/patch-node-modules.sh b/scripts/patch-node-modules.sh index 7e51d8e..99ef718 100755 --- a/scripts/patch-node-modules.sh +++ b/scripts/patch-node-modules.sh @@ -120,4 +120,30 @@ redirect_ws_to_real_package() { echo "==> [node_modules] redirecting ws requires past bun's built-in shim" redirect_ws_to_real_package node_modules/mockttp/dist +# mockttp decides whether a response is still ongoing or already completed by +# sniffing the object's shape: +# +# // Ongoing response has 'getHeaders' - completed has 'headers'. +# if ('headers' in response) return response; +# +# An ongoing response is a live http.ServerResponse; a completed one is the plain +# object built by buildInitiatedResponse(). On node that test works, because +# ServerResponse has no `headers` property. Bun's ServerResponse *does* have one +# (`'headers' in res` === true, typeof object), so the check is inverted for every +# single response: waitForCompletedResponse() bails out immediately and hands back +# the live ServerResponse, having neither awaited the body nor attached rawHeaders. +# +# The admin server then tries to serialise that as a GraphQL Response, whose +# schema declares `rawHeaders: Json!`, and the whole responseCompleted event is +# dropped with "Cannot return null for non-nullable field Response.rawHeaders." +# Traffic still proxies correctly - but the UI only ever receives the *initiated* +# response, so exchanges render with status and headers and no body, forever. +# +# Testing for the ongoing-response method instead is unambiguous under either +# runtime: a completed response is a plain object and has no getHeaders. +echo "==> [node_modules] fixing mockttp's ongoing-vs-completed response check for bun" +replace_literal node_modules/mockttp/dist/util/request-utils.js \ + "if ('headers' in response)" \ + "if (typeof response.getHeaders !== 'function')" + echo "==> patch-node-modules.sh complete."