@@ -28,6 +28,13 @@ import {
2828import * as ManagedEndpointRuntime from "./ManagedEndpointRuntime.ts" ;
2929import { traceAuthenticatedRelayRequest , traceRelayRequest } from "./traceRelayRequest.ts" ;
3030
31+ const encodeEnvironmentHttpInternalServerError = Schema . encodeUnknownSync (
32+ EnvironmentHttpInternalServerError ,
33+ ) ;
34+ const decodeEnvironmentHttpInternalServerError = Schema . decodeUnknownSync (
35+ EnvironmentHttpInternalServerError ,
36+ ) ;
37+
3138const storeFailure = ( tag : "AlreadyExists" | "PermissionDenied" ) =>
3239 new ServerSecretStore . SecretStorePersistError ( {
3340 operation : "create" ,
@@ -210,21 +217,31 @@ describe("CloudRelayRequestError", () => {
210217 } ) ;
211218} ) ;
212219
213- it ( "preserves internal causes without encoding them into HTTP error bodies" , ( ) => {
220+ it ( "keeps internal causes out of encoded HTTP error bodies" , ( ) => {
214221 const cause = new Error ( "private upstream detail" ) ;
215222 const error = new EnvironmentHttpInternalServerError ( {
216- message : "Stable public failure. " ,
223+ operation : "generate_link_proof " ,
217224 cause,
218225 } ) ;
219- const encodeError = Schema . encodeUnknownSync ( EnvironmentHttpInternalServerError ) ;
220226
221227 expect ( error . cause ) . toBe ( cause ) ;
222- expect ( encodeError ( error ) ) . toEqual ( {
228+ expect ( encodeEnvironmentHttpInternalServerError ( error ) ) . toEqual ( {
223229 _tag : "EnvironmentHttpInternalServerError" ,
224- message : "Stable public failure." ,
230+ operation : "generate_link_proof" ,
231+ message : "Could not generate environment link proof." ,
225232 } ) ;
226233} ) ;
227234
235+ it ( "decodes legacy message-only HTTP errors during rolling deployments" , ( ) => {
236+ const error = decodeEnvironmentHttpInternalServerError ( {
237+ _tag : "EnvironmentHttpInternalServerError" ,
238+ message : "Legacy environment server failure." ,
239+ } ) ;
240+
241+ expect ( error . operation ) . toBeUndefined ( ) ;
242+ expect ( error . message ) . toBe ( "Legacy environment server failure." ) ;
243+ } ) ;
244+
228245describe ( "relay request tracing" , ( ) => {
229246 it . effect ( "does not accept an unauthenticated request trace parent" , ( ) =>
230247 Effect . gen ( function * ( ) {
@@ -298,6 +315,7 @@ describe("reconcileDesiredCloudLink", () => {
298315
299316 expect ( error ) . toMatchObject ( {
300317 _tag : "EnvironmentHttpUnauthorizedError" ,
318+ reason : "cloud_cli_authorization_required" ,
301319 message : "Run `t3 connect link` to authorize this environment." ,
302320 } ) ;
303321 } ) ,
@@ -334,6 +352,9 @@ describe("reconcileDesiredCloudLink", () => {
334352
335353 expect ( error ) . toMatchObject ( {
336354 _tag : "EnvironmentHttpInternalServerError" ,
355+ operation : "relay_request" ,
356+ relayOperation : "create-link-challenge" ,
357+ relayPhase : "send-request" ,
337358 message : "T3 Connect relay create-link-challenge failed during send-request." ,
338359 cause : {
339360 _tag : "CloudRelayRequestError" ,
@@ -346,7 +367,12 @@ describe("reconcileDesiredCloudLink", () => {
346367 const logFields = capturedLogs [ 0 ] ?. find (
347368 ( value ) : value is Record < string , unknown > => typeof value === "object" && value !== null ,
348369 ) ;
349- expect ( logFields ) . toMatchObject ( { causeTag : "CloudRelayRequestError" } ) ;
370+ expect ( logFields ) . toMatchObject ( {
371+ operation : "relay_request" ,
372+ relayOperation : "create-link-challenge" ,
373+ relayPhase : "send-request" ,
374+ causeTag : "CloudRelayRequestError" ,
375+ } ) ;
350376 expect ( logFields ) . not . toHaveProperty ( "cause" ) ;
351377 expect ( capturedLogs [ 0 ] ?. filter ( ( value ) => typeof value === "string" ) . join ( " " ) ) . not . toContain (
352378 transportCause . message ,
0 commit comments