fix: return injected payload when express handles the request #212
All Vouch review confidence checks passed
Residual risk 0.38 = Change Risk (0.66) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.66 · 369 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.354
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.066
Real PR Conversation Timeline
1 comments
"Review active on #212"
general
weight: 0.35
mcollina
Fixes #54
fastify.inject()returns an empty payload for any request that goes through the express stack. That covers express routes and routers, and also plain Fastify routes once anyfastify.use()middleware is registered. The status code and headers are correct, but the body is''.Root cause:
runConnectinindex.jshandsreq.raw/reply.rawto express, and express'sapp.handle(express/lib/application.js) doesObject.setPrototypeOf(res, this.response). For an injected request,reply.rawis a light-my-requestResponse. Its prototype overrideswrite,end,writeHeadand a few more methods to collect the payload. Once the prototype is swapped, those overrides are lost and the plainhttp.ServerResponsemethods write to the mock socket instead. The existing tests that use inject only check status codes, so this never showed up.What changed: when
req.raw.isLightMyRequestis set (a documented light-my-request marker),runConnectcopies the own methods of the req/res prototype onto the instance before calling express. Express still swaps the prototype, but the instance properties shadow it, so light-my-request's methods keep working. Express's own methods (res.json,res.send,req.get, ...) are not affected because light-my-request doesn't define them. Requests from a real server never get this flag, so the normal HTTP path doesn't change.Tests: added
test/inject.test.js. It covers an express app route withres.jsonand a status/header, a router withres.sendandres.end, a POST body parsed byexpress.json(), and a Fastify route (JSON and stream) behind an express middleware. All 5 fail without the change toindex.jsand pass with it.npm testpasses: lint, 78 unit tests with 100% coverage, and tstyche.Repro script (fastify 5.12.8, light-my-request 6.8.0, express 5.3.0): express routes mounted with
fastify.use(), thenfastify.inject():Before:
After:
Left out: I only copy methods from the immediate prototype of the injected req/res. That prototype is the one light-my-request builds, and it also covers its custom
Requestoption, because light-my-request copies its methods onto that constructor's prototype. Methods that a user-suppliedRequestclass inherits from further up its own chain are not preserved. I didn't add a README note because inject should now just work.