1- import { EnvironmentAuthInvalidError } from "@t3tools/contracts" ;
2- import { RelayAuthInvalidError } from "@t3tools/contracts/relay" ;
31import { describe , expect , it } from "@effect/vitest" ;
42
5- import { mapManagedRelayError , mapRemoteEnvironmentError } from "./errors.ts" ;
6- import * as ManagedRelay from "../relay/managedRelay.ts" ;
3+ import { mapRemoteEnvironmentError } from "./errors.ts" ;
74import {
85 RemoteEnvironmentAuthFetchError ,
96 RemoteEnvironmentAuthUndeclaredStatusError ,
107} from "../rpc/http.ts" ;
118
129describe ( "connection error mapping" , ( ) => {
13- it ( "retains the managed relay request as the cause when classifying a protected error" , ( ) => {
14- const relayError = new RelayAuthInvalidError ( {
15- code : "auth_invalid" ,
16- reason : "invalid_bearer" ,
17- traceId : "relay-trace-id" ,
18- } ) ;
19- const source = new ManagedRelay . ManagedRelayRequestFailedError ( {
20- action : "connect relay environment" ,
21- cause : relayError ,
22- relayError,
23- traceId : relayError . traceId ,
24- } ) ;
25-
26- const error = mapManagedRelayError ( source ) ;
27-
28- expect ( error ) . toMatchObject ( {
29- _tag : "ConnectionBlockedError" ,
30- reason : "authentication" ,
31- traceId : "relay-trace-id" ,
32- } ) ;
33- expect ( error . cause ) . toBe ( source ) ;
34- } ) ;
35-
36- it ( "retains a managed relay timeout and its structured activity" , ( ) => {
37- const source = new ManagedRelay . ManagedRelayRequestTimeoutError ( {
38- activity : "Relay environment connection" ,
39- timeoutMs : 10_000 ,
40- } ) ;
41-
42- const error = mapManagedRelayError ( source ) ;
43-
44- expect ( error ) . toMatchObject ( {
45- _tag : "ConnectionTransientError" ,
46- reason : "timeout" ,
47- } ) ;
48- expect ( error . cause ) . toBe ( source ) ;
49- expect ( source . activity ) . toBe ( "Relay environment connection" ) ;
50- } ) ;
51-
52- it ( "retains structured remote authorization failures" , ( ) => {
53- const source = new EnvironmentAuthInvalidError ( {
54- code : "auth_invalid" ,
55- reason : "invalid_credential" ,
56- traceId : "environment-trace-id" ,
57- } ) ;
58-
59- const error = mapRemoteEnvironmentError ( source ) ;
60-
61- expect ( error ) . toMatchObject ( {
62- _tag : "ConnectionBlockedError" ,
63- reason : "authentication" ,
64- traceId : "environment-trace-id" ,
65- } ) ;
66- expect ( error . cause ) . toBe ( source ) ;
67- } ) ;
68-
69- it ( "retains local transport failures without deriving their message from the cause" , ( ) => {
10+ it ( "keeps transport diagnostics structured and redacted" , ( ) => {
7011 const transportCause = new Error ( "sensitive transport implementation detail" ) ;
7112 const requestUrl =
7213 "https://environment-user:[email protected] /private/session?access_token=environment-secret#environment-fragment" ; @@ -82,8 +23,6 @@ describe("connection error mapping", () => {
8223 _tag : "ConnectionTransientError" ,
8324 reason : "network" ,
8425 } ) ;
85- expect ( error . cause ) . toBe ( source ) ;
86- expect ( source . cause ) . toBe ( transportCause ) ;
8726 expect ( source ) . toMatchObject ( {
8827 requestUrlInputLength : requestUrl . length ,
8928 requestUrlProtocol : "https:" ,
@@ -102,7 +41,7 @@ describe("connection error mapping", () => {
10241 }
10342 } ) ;
10443
105- it ( "retains the HTTP client cause for undeclared statuses " , ( ) => {
44+ it ( "keeps undeclared status diagnostics structured and redacted " , ( ) => {
10645 const cause = new Error ( "upstream response metadata" ) ;
10746 const requestUrl =
10847 "https://environment-user:[email protected] /private/session?access_token=environment-secret#environment-fragment" ; @@ -114,7 +53,6 @@ describe("connection error mapping", () => {
11453 requestUrlProtocol : "https:" ,
11554 requestUrlHostname : "environment.example.test" ,
11655 } ) ;
117- expect ( error . cause ) . toBe ( cause ) ;
11856 expect ( error ) . not . toHaveProperty ( "requestUrl" ) ;
11957 } ) ;
12058} ) ;
0 commit comments