@@ -54,6 +54,7 @@ const phase = (auth: AntigravityAuth, value: ProviderAuthState["phase"], session
5454const makeHarness = Effect . fn ( "makeAuthTestHarness" ) ( function * (
5555 options : {
5656 readonly interactive ?: boolean ;
57+ readonly authorizationUrls ?: ReadonlyArray < string > ;
5758 readonly supportsLogout ?: boolean ;
5859 readonly forwardCallback ?: Effect . Effect < void , ProviderSetupError > ;
5960 } = { } ,
@@ -62,12 +63,16 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
6263 const discovered = yield * Deferred . make < void > ( ) ;
6364 const closed = yield * Deferred . make < void > ( ) ;
6465 const events : string [ ] = [ ] ;
66+ let receiveAuthorizationUrl :
67+ | ( ( url : string ) => Effect . Effect < void , AcpErrors . AcpError > )
68+ | undefined ;
6569 let forwarded = 0 ;
6670 let catalog = [ "previous-account-model" ] ;
6771 const auth = yield * makeAntigravityAuth ( {
6872 instanceId,
6973 makeRuntime : ( input ) =>
7074 Effect . gen ( function * ( ) {
75+ receiveAuthorizationUrl = input . onAuthorizationUrl ;
7176 events . push ( "process-open" ) ;
7277 yield * Effect . addFinalizer ( ( ) =>
7378 Effect . gen ( function * ( ) {
@@ -87,7 +92,9 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
8792 Effect . gen ( function * ( ) {
8893 events . push ( "authenticate" ) ;
8994 if ( options . interactive !== false && input . onAuthorizationUrl ) {
90- yield * input . onAuthorizationUrl ( authorizationUrl ) ;
95+ for ( const url of options . authorizationUrls ?? [ authorizationUrl ] ) {
96+ yield * input . onAuthorizationUrl ( url ) ;
97+ }
9198 }
9299 yield * Deferred . await ( authenticated ) ;
93100 events . push ( "session-new" ) ;
@@ -124,10 +131,62 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
124131 events,
125132 catalog : ( ) => catalog ,
126133 forwarded : ( ) => forwarded ,
134+ receiveAuthorizationUrl : ( url : string ) =>
135+ Effect . suspend ( ( ) =>
136+ receiveAuthorizationUrl
137+ ? receiveAuthorizationUrl ( url )
138+ : Effect . die ( "Authorization URL receiver is not ready." ) ,
139+ ) ,
127140 } ;
128141} ) ;
129142
130143it . layer ( NodeServices . layer ) ( "AntigravityAuth" , ( it ) => {
144+ it . effect ( "accepts the same authorization URL from stderr and stdout" , ( ) =>
145+ Effect . gen ( function * ( ) {
146+ const harness = yield * makeHarness ( {
147+ authorizationUrls : [ authorizationUrl , authorizationUrl ] ,
148+ } ) ;
149+ yield * harness . auth . controller . start ( owner ) ;
150+ const waiting = yield * phase ( harness . auth , "waiting" ) ;
151+ assert . equal ( waiting . authorizationUrl , authorizationUrl ) ;
152+
153+ yield * Deferred . succeed ( harness . authenticated , undefined ) ;
154+ yield * Deferred . succeed ( harness . discovered , undefined ) ;
155+ yield * phase ( harness . auth , "succeeded" ) ;
156+ } ) ,
157+ ) ;
158+
159+ it . effect ( "accepts a delayed duplicate after callback completion starts" , ( ) =>
160+ Effect . gen ( function * ( ) {
161+ const harness = yield * makeHarness ( ) ;
162+ const state = yield * harness . auth . controller . start ( owner ) ;
163+ yield * phase ( harness . auth , "waiting" ) ;
164+ yield * harness . auth . controller . complete ( owner , {
165+ flowId : state . flowId ! ,
166+ callbackUrl,
167+ } ) ;
168+
169+ yield * harness . receiveAuthorizationUrl ( authorizationUrl ) ;
170+
171+ yield * Deferred . succeed ( harness . authenticated , undefined ) ;
172+ yield * Deferred . succeed ( harness . discovered , undefined ) ;
173+ yield * phase ( harness . auth , "succeeded" ) ;
174+ } ) ,
175+ ) ;
176+
177+ it . effect ( "rejects a different second authorization URL" , ( ) =>
178+ Effect . gen ( function * ( ) {
179+ const harness = yield * makeHarness ( {
180+ authorizationUrls : [ authorizationUrl , `${ authorizationUrl } &scope=another-request` ] ,
181+ } ) ;
182+ yield * harness . auth . controller . start ( owner ) ;
183+
184+ const failed = yield * phase ( harness . auth , "failed" ) ;
185+ assert . isNull ( failed . authorizationUrl ) ;
186+ assert . deepEqual ( harness . catalog ( ) , [ "previous-account-model" ] ) ;
187+ } ) ,
188+ ) ;
189+
131190 it . effect ( "keeps a remote flow private and waits for native auth and catalog discovery" , ( ) =>
132191 Effect . gen ( function * ( ) {
133192 const harness = yield * makeHarness ( ) ;
0 commit comments