@@ -126,6 +126,38 @@ describe("runGatewayHealthJsonRoute", () => {
126126 expect(runtime.exit).toHaveBeenCalledWith(1);
127127 });
128128
129+ it("preserves structured Gateway health request errors", async () => {
130+ const runtime = createRuntime();
131+ const error = new Error("health snapshot unavailable");
132+ const callGateway = vi.fn(async () => {
133+ throw error;
134+ });
135+ const payload = {
136+ ok: false,
137+ error: {
138+ type: "gateway_request_error",
139+ code: "UNAVAILABLE",
140+ message: "health snapshot unavailable",
141+ },
142+ };
143+ const formatGatewayClientRequestErrorJson = vi.fn(() => payload);
144+ const formatGatewayTransportErrorJson = vi.fn();
145+
146+ await runGatewayHealthJsonRoute({ rpc: { json: true, timeout: "10000" } }, runtime as never, {
147+ callGateway,
148+ readNonObservingHealthConfig: async () => ({}),
149+ emitReachableGatewayAuthDiagnostic: vi.fn(async () => false) as never,
150+ formatGatewayAuthErrorJson: vi.fn(() => null) as never,
151+ formatGatewayClientRequestErrorJson: formatGatewayClientRequestErrorJson as never,
152+ formatGatewayTransportErrorJson: formatGatewayTransportErrorJson as never,
153+ });
154+
155+ expect(formatGatewayClientRequestErrorJson).toHaveBeenCalledWith(error);
156+ expect(formatGatewayTransportErrorJson).not.toHaveBeenCalled();
157+ expect(runtime.writeJson).toHaveBeenCalledWith(payload, 2);
158+ expect(runtime.exit).toHaveBeenCalledWith(1);
159+ });
160+
129161 it("preserves structured auth errors when reachability is unknown", async () => {
130162 const runtime = createRuntime();
131163 const error = new Error("gateway health requires credentials");
0 commit comments