@@ -150,6 +150,17 @@ const authAccessHarness = vi.hoisted(() => {
150150const mockConnectDesktopSshEnvironment = vi . hoisted ( ( ) => vi . fn ( ) ) ;
151151const mockGetClerkToken = vi . hoisted ( ( ) => vi . fn ( async ( ) => null ) ) ;
152152const mockOpenClerkWaitlist = vi . hoisted ( ( ) => vi . fn ( ) ) ;
153+ const mockCreateServerPairingCredential = vi . hoisted ( ( ) => vi . fn ( ) ) ;
154+ const mockRevokeOtherServerClientSessions = vi . hoisted ( ( ) => vi . fn ( ) ) ;
155+
156+ vi . mock ( "~/environments/primary" , async ( importOriginal ) => {
157+ const actual = await importOriginal < typeof import ( "~/environments/primary" ) > ( ) ;
158+ return {
159+ ...actual ,
160+ createServerPairingCredential : mockCreateServerPairingCredential ,
161+ revokeOtherServerClientSessions : mockRevokeOtherServerClientSessions ,
162+ } ;
163+ } ) ;
153164
154165vi . mock ( "@clerk/react" , ( ) => ( {
155166 useAuth : ( ) => ( {
@@ -498,6 +509,8 @@ describe("GeneralSettingsPanel observability", () => {
498509 useUiStateStore . setState ( { defaultAdvertisedEndpointKey : null } ) ;
499510 authAccessHarness . reset ( ) ;
500511 mockConnectDesktopSshEnvironment . mockReset ( ) ;
512+ mockCreateServerPairingCredential . mockReset ( ) ;
513+ mockRevokeOtherServerClientSessions . mockReset ( ) ;
501514 } ) ;
502515
503516 afterEach ( async ( ) => {
@@ -539,28 +552,6 @@ describe("GeneralSettingsPanel observability", () => {
539552 } ) ,
540553 ] ,
541554 } ) ;
542- const fetchMock = vi . fn < typeof fetch > ( ) . mockImplementation ( async ( input ) => {
543- const url = String ( input ) ;
544- if ( url . endsWith ( "/api/auth/session" ) ) {
545- return new Response (
546- JSON . stringify ( {
547- authenticated : true ,
548- auth : createBaseServerConfig ( ) . auth ,
549- scopes : [ "orchestration:read" , "access:write" ] ,
550- sessionMethod : "browser-session-cookie" ,
551- expiresAt : "2036-05-07T00:00:00.000Z" ,
552- } ) ,
553- {
554- status : 200 ,
555- headers : { "content-type" : "application/json" } ,
556- } ,
557- ) ;
558- }
559-
560- throw new Error ( `Unhandled fetch GET ${ url } ` ) ;
561- } ) ;
562- vi . stubGlobal ( "fetch" , fetchMock ) ;
563-
564555 mounted = await render (
565556 < AppAtomRegistryProvider >
566557 < ConnectionsSettings />
@@ -570,14 +561,7 @@ describe("GeneralSettingsPanel observability", () => {
570561 await expect
571562 . element ( page . getByRole ( "heading" , { name : "This environment" , exact : true } ) )
572563 . toBeInTheDocument ( ) ;
573- await expect . element ( page . getByLabelText ( "Enable network access" ) ) . toBeDisabled ( ) ;
574- await expect
575- . element (
576- page . getByText (
577- "This backend is only reachable on this machine. Restart it with a non-loopback host to enable remote pairing." ,
578- ) ,
579- )
580- . toBeInTheDocument ( ) ;
564+ await expect . element ( page . getByLabelText ( "Enable network access" ) ) . not . toBeInTheDocument ( ) ;
581565 await expect . element ( page . getByText ( "Authorized clients" ) ) . not . toBeInTheDocument ( ) ;
582566 await expect . element ( page . getByText ( "Chrome on Mac" ) ) . not . toBeInTheDocument ( ) ;
583567 await expect
@@ -812,64 +796,51 @@ describe("GeneralSettingsPanel observability", () => {
812796 pairingLinks,
813797 clientSessions,
814798 } ) ;
815- vi . stubGlobal (
816- "fetch" ,
817- vi . fn < typeof fetch > ( ) . mockImplementation ( async ( input , init ) => {
818- const url = String ( input ) ;
819- const method = init ?. method ?? "GET" ;
820- if ( url . endsWith ( "/api/auth/pairing-token" ) && method === "POST" ) {
821- pairingLinks = [
822- makePairingLink ( {
823- id : "pairing-link-1" ,
824- credential : "pairing-token" ,
825- scopes : [ "orchestration:read" ] ,
826- subject : "one-time-token" ,
827- label : "Julius iPhone" ,
828- createdAt : "2036-04-07T00:00:00.000Z" ,
829- expiresAt : "2036-04-10T00:05:00.000Z" ,
830- } ) ,
831- ] ;
832- clientSessions = [
833- ...clientSessions ,
834- makeClientSession ( {
835- sessionId : "session-client" ,
836- subject : "one-time-token" ,
837- scopes : [ "orchestration:read" ] ,
838- method : "browser-session-cookie" ,
839- client : {
840- label : "Julius iPhone" ,
841- deviceType : "mobile" ,
842- os : "iOS" ,
843- browser : "Safari" ,
844- ipAddress : "192.168.1.88" ,
845- } ,
846- issuedAt : "2036-04-07T00:01:00.000Z" ,
847- expiresAt : "2036-05-07T00:01:00.000Z" ,
848- connected : false ,
849- current : false ,
850- } ) ,
851- ] ;
852- authAccessHarness . setSnapshot ( {
853- pairingLinks,
854- clientSessions,
855- } ) ;
856- return new Response (
857- JSON . stringify ( {
858- id : "pairing-link-1" ,
859- credential : "pairing-token" ,
860- label : "Julius iPhone" ,
861- expiresAt : "2036-04-10T00:05:00.000Z" ,
862- } ) ,
863- {
864- status : 200 ,
865- headers : { "content-type" : "application/json" } ,
866- } ,
867- ) ;
868- }
869-
870- throw new Error ( `Unhandled fetch ${ method } ${ url } ` ) ;
871- } ) ,
872- ) ;
799+ mockCreateServerPairingCredential . mockImplementation ( async ( ) => {
800+ pairingLinks = [
801+ makePairingLink ( {
802+ id : "pairing-link-1" ,
803+ credential : "pairing-token" ,
804+ scopes : [ "orchestration:read" ] ,
805+ subject : "one-time-token" ,
806+ label : "Julius iPhone" ,
807+ createdAt : "2036-04-07T00:00:00.000Z" ,
808+ expiresAt : "2036-04-10T00:05:00.000Z" ,
809+ } ) ,
810+ ] ;
811+ clientSessions = [
812+ ...clientSessions ,
813+ makeClientSession ( {
814+ sessionId : "session-client" ,
815+ subject : "one-time-token" ,
816+ scopes : [ "orchestration:read" ] ,
817+ method : "browser-session-cookie" ,
818+ client : {
819+ label : "Julius iPhone" ,
820+ deviceType : "mobile" ,
821+ os : "iOS" ,
822+ browser : "Safari" ,
823+ ipAddress : "192.168.1.88" ,
824+ } ,
825+ issuedAt : "2036-04-07T00:01:00.000Z" ,
826+ expiresAt : "2036-05-07T00:01:00.000Z" ,
827+ connected : false ,
828+ current : false ,
829+ } ) ,
830+ ] ;
831+ authAccessHarness . setSnapshot ( {
832+ pairingLinks,
833+ clientSessions,
834+ } ) ;
835+ authAccessHarness . emitPairingLinkUpserted ( pairingLinks [ 0 ] ! ) ;
836+ authAccessHarness . emitClientUpserted ( clientSessions [ 1 ] ! ) ;
837+ return {
838+ id : "pairing-link-1" ,
839+ credential : "pairing-token" ,
840+ label : "Julius iPhone" ,
841+ expiresAt : makeUtc ( "2036-04-10T00:05:00.000Z" ) ,
842+ } ;
843+ } ) ;
873844
874845 setServerConfigSnapshot ( createBaseServerConfig ( ) ) ;
875846
@@ -890,8 +861,6 @@ describe("GeneralSettingsPanel observability", () => {
890861 await expect . element ( page . getByRole ( "checkbox" , { name : / V i e w e n v i r o n m e n t / } ) ) . toBeChecked ( ) ;
891862 await expect . element ( page . getByRole ( "checkbox" , { name : / O p e r a t e t a s k s / } ) ) . not . toBeChecked ( ) ;
892863 await page . getByRole ( "button" , { name : "Create link" , exact : true } ) . click ( ) ;
893- authAccessHarness . emitPairingLinkUpserted ( pairingLinks [ 0 ] ! ) ;
894- authAccessHarness . emitClientUpserted ( clientSessions [ 1 ] ! ) ;
895864 await expect
896865 . element ( page . getByRole ( "button" , { name : "Pairing link scopes: show 1 scope" } ) )
897866 . toBeInTheDocument ( ) ;
@@ -1009,25 +978,15 @@ describe("GeneralSettingsPanel observability", () => {
1009978 clientSessions,
1010979 } ) ;
1011980
1012- const fetchMock = vi . fn < typeof fetch > ( ) . mockImplementation ( async ( input , init ) => {
1013- const url = String ( input ) ;
1014- const method = init ?. method ?? "GET" ;
1015- if ( url . endsWith ( "/api/auth/clients/revoke-others" ) && method === "POST" ) {
1016- clientSessions = clientSessions . filter ( ( session ) => session . current ) ;
1017- authAccessHarness . setSnapshot ( {
1018- pairingLinks : [ ] ,
1019- clientSessions,
1020- } ) ;
1021- authAccessHarness . emitClientRemoved ( "session-client" ) ;
1022- return new Response ( JSON . stringify ( { revokedCount : 1 } ) , {
1023- status : 200 ,
1024- headers : { "content-type" : "application/json" } ,
1025- } ) ;
1026- }
1027-
1028- throw new Error ( `Unhandled fetch ${ method } ${ url } ` ) ;
981+ mockRevokeOtherServerClientSessions . mockImplementation ( async ( ) => {
982+ clientSessions = clientSessions . filter ( ( session ) => session . current ) ;
983+ authAccessHarness . setSnapshot ( {
984+ pairingLinks : [ ] ,
985+ clientSessions,
986+ } ) ;
987+ authAccessHarness . emitClientRemoved ( "session-client" ) ;
988+ return 1 ;
1029989 } ) ;
1030- vi . stubGlobal ( "fetch" , fetchMock ) ;
1031990
1032991 setServerConfigSnapshot ( createBaseServerConfig ( ) ) ;
1033992
@@ -1041,7 +1000,7 @@ describe("GeneralSettingsPanel observability", () => {
10411000 await page . getByRole ( "button" , { name : "Revoke others" , exact : true } ) . click ( ) ;
10421001 await expect . element ( page . getByText ( "This Mac" ) ) . toBeInTheDocument ( ) ;
10431002 await expect . element ( page . getByText ( "Julius iPhone" ) ) . not . toBeInTheDocument ( ) ;
1044- expect ( fetchMock ) . toHaveBeenCalled ( ) ;
1003+ expect ( mockRevokeOtherServerClientSessions ) . toHaveBeenCalled ( ) ;
10451004 } ) ;
10461005
10471006 it ( "shows a disabled network access toggle with guidance in desktop builds" , async ( ) => {
0 commit comments