@@ -951,15 +951,15 @@ describe("EnvironmentRegistry", () => {
951951 yield * Deferred . await ( relayChecked ) ;
952952
953953 const entries = yield * SubscriptionRef . get ( registry . entries ) ;
954- expect ( entries . get ( RELAY_TARGET . environmentId ) ) . toMatchObject ( { enabled : false } ) ;
954+ expect ( entries . get ( RELAY_TARGET . environmentId ) ?. unsupportedReason ) . toBeDefined ( ) ;
955955 expect ( entries . get ( TARGET . environmentId ) ) . toMatchObject ( { enabled : true } ) ;
956956 expect ( entries . get ( TARGET . environmentId ) ?. unsupportedReason ) . toBeUndefined ( ) ;
957957 expect ( ( yield * registry . state ( TARGET . environmentId ) ) . phase ) . toBe ( "connected" ) ;
958958 } ) . pipe ( Effect . provide ( harness . layer ) , Effect . scoped ) ;
959959 } ) ,
960960 ) ;
961961
962- it . effect ( "discovery keeps unsupported environments off until compatibility changes " , ( ) =>
962+ it . effect ( "a switched-off environment stays off after its compatibility block clears " , ( ) =>
963963 Effect . gen ( function * ( ) {
964964 const harness = yield * makeHarness ( [ RELAY_TARGET ] , [ ] , [ ] , {
965965 initialDisabled : [ RELAY_TARGET . environmentId ] ,
@@ -994,7 +994,7 @@ describe("EnvironmentRegistry", () => {
994994 } ) ,
995995 ) ;
996996
997- it . effect ( "a socket preflight rejection persists the connection as switched off" , ( ) =>
997+ it . effect ( "a socket preflight rejection pauses the connection without switching it off" , ( ) =>
998998 Effect . gen ( function * ( ) {
999999 const error = new ConnectionBlockedError ( {
10001000 reason : "unsupported" ,
@@ -1005,20 +1005,97 @@ describe("EnvironmentRegistry", () => {
10051005 const registry = yield * EnvironmentRegistry . EnvironmentRegistry ;
10061006 yield * registry . start ;
10071007 yield * SubscriptionRef . changes ( registry . entries ) . pipe (
1008- Stream . filter ( ( entries ) => entries . get ( RELAY_TARGET . environmentId ) ?. enabled === false ) ,
1008+ Stream . filter (
1009+ ( entries ) => entries . get ( RELAY_TARGET . environmentId ) ?. unsupportedReason !== undefined ,
1010+ ) ,
10091011 Stream . take ( 1 ) ,
10101012 Stream . runDrain ,
10111013 ) ;
1012- expect ( ( yield * Ref . get ( harness . storedDisabled ) ) . has ( RELAY_TARGET . environmentId ) ) . toBe ( true ) ;
1014+ expect ( ( yield * Ref . get ( harness . storedDisabled ) ) . has ( RELAY_TARGET . environmentId ) ) . toBe (
1015+ false ,
1016+ ) ;
10131017 expect (
1014- ( yield * SubscriptionRef . get ( registry . entries ) ) . get ( RELAY_TARGET . environmentId )
1015- ?. unsupportedReason ,
1016- ) . toBe ( error . message ) ;
1018+ ( yield * SubscriptionRef . get ( registry . entries ) ) . get ( RELAY_TARGET . environmentId ) ,
1019+ ) . toMatchObject ( { enabled : true , unsupportedReason : error . message } ) ;
1020+ yield * awaitConnectionState (
1021+ registry ,
1022+ RELAY_TARGET . environmentId ,
1023+ ( state ) => ! state . desired && state . phase === "available" ,
1024+ ) ;
10171025 expect ( yield * Ref . get ( harness . sessions ) ) . toHaveLength ( 0 ) ;
10181026 } ) . pipe ( Effect . provide ( harness . layer ) ) ;
10191027 } ) ,
10201028 ) ;
10211029
1030+ it . effect ( "an enabled environment reconnects once its compatibility block clears" , ( ) =>
1031+ Effect . gen ( function * ( ) {
1032+ const harness = yield * makeHarness ( [ RELAY_TARGET ] ) ;
1033+ const error = new ConnectionBlockedError ( {
1034+ reason : "unsupported" ,
1035+ detail : "Use a compatible client." ,
1036+ } ) ;
1037+ yield * Effect . gen ( function * ( ) {
1038+ const registry = yield * EnvironmentRegistry . EnvironmentRegistry ;
1039+ yield * registry . start ;
1040+ yield * awaitConnectionState (
1041+ registry ,
1042+ RELAY_TARGET . environmentId ,
1043+ ( state ) => state . phase === "connected" ,
1044+ ) ;
1045+
1046+ yield * registry . setCompatibility ( RELAY_TARGET . environmentId , error ) ;
1047+ yield * awaitConnectionState (
1048+ registry ,
1049+ RELAY_TARGET . environmentId ,
1050+ ( state ) => state . phase === "available" ,
1051+ ) ;
1052+ expect (
1053+ ( yield * SubscriptionRef . get ( registry . entries ) ) . get ( RELAY_TARGET . environmentId ) ,
1054+ ) . toMatchObject ( { enabled : true , unsupportedReason : error . message } ) ;
1055+ expect ( ( yield * Ref . get ( harness . storedDisabled ) ) . has ( RELAY_TARGET . environmentId ) ) . toBe (
1056+ false ,
1057+ ) ;
1058+
1059+ yield * registry . setCompatibility ( RELAY_TARGET . environmentId , null ) ;
1060+ yield * awaitConnectionState (
1061+ registry ,
1062+ RELAY_TARGET . environmentId ,
1063+ ( state ) => state . phase === "connected" ,
1064+ ) ;
1065+ expect ( yield * Ref . get ( harness . sessions ) ) . toHaveLength ( 2 ) ;
1066+ } ) . pipe ( Effect . provide ( harness . layer ) ) ;
1067+ } ) ,
1068+ ) ;
1069+
1070+ it . effect ( "a blocked environment comes back enabled after a relaunch" , ( ) =>
1071+ Effect . gen ( function * ( ) {
1072+ const harness = yield * makeHarness ( [ RELAY_TARGET ] ) ;
1073+ yield * Effect . gen ( function * ( ) {
1074+ const registry = yield * EnvironmentRegistry . EnvironmentRegistry ;
1075+ yield * registry . start ;
1076+ yield * registry . setCompatibility (
1077+ RELAY_TARGET . environmentId ,
1078+ new ConnectionBlockedError ( { reason : "unsupported" , detail : "Use a compatible client." } ) ,
1079+ ) ;
1080+ } ) . pipe ( Effect . provide ( harness . layer ) , Effect . scoped ) ;
1081+
1082+ yield * Effect . gen ( function * ( ) {
1083+ const registry = yield * EnvironmentRegistry . EnvironmentRegistry ;
1084+ const entry = ( yield * SubscriptionRef . get ( registry . entries ) ) . get (
1085+ RELAY_TARGET . environmentId ,
1086+ ) ;
1087+ expect ( entry ?. enabled ) . toBe ( true ) ;
1088+ expect ( entry ?. unsupportedReason ) . toBeUndefined ( ) ;
1089+ yield * registry . start ;
1090+ yield * awaitConnectionState (
1091+ registry ,
1092+ RELAY_TARGET . environmentId ,
1093+ ( state ) => state . phase === "connected" ,
1094+ ) ;
1095+ } ) . pipe ( Effect . provide ( harness . layer ) , Effect . scoped ) ;
1096+ } ) ,
1097+ ) ;
1098+
10221099 it . effect ( "switching an environment off disconnects it and persists the flag" , ( ) =>
10231100 Effect . gen ( function * ( ) {
10241101 const harness = yield * makeHarness ( [ RELAY_TARGET ] ) ;
@@ -1471,7 +1548,7 @@ describe("EnvironmentRegistry", () => {
14711548 yield * registry . reconcilePlatform ( [ registration ] ) ;
14721549 expect (
14731550 ( yield * SubscriptionRef . get ( registry . entries ) ) . get ( TARGET . environmentId ) ,
1474- ) . toMatchObject ( { enabled : false , unsupportedReason : error . message } ) ;
1551+ ) . toMatchObject ( { enabled : true , unsupportedReason : error . message } ) ;
14751552 expect ( yield * Ref . get ( harness . sessions ) ) . toHaveLength ( 1 ) ;
14761553 yield * registry . registerPlatform (
14771554 new PrimaryConnectionRegistration ( {
0 commit comments