@@ -245,20 +245,6 @@ fn workload_template_proto(name: &str, workspace: &str) -> proto::SandboxWorkloa
245245
246246#[ tonic:: async_trait]
247247impl OpenShell for TestOpenShell {
248- async fn get_service_route_snapshot (
249- & self ,
250- _: tonic:: Request < proto:: GetServiceRouteSnapshotRequest > ,
251- ) -> Result < Response < proto:: GetServiceRouteSnapshotResponse > , Status > {
252- Err ( Status :: unimplemented ( "unused" ) )
253- }
254- type WatchServiceRoutesStream =
255- tokio_stream:: wrappers:: ReceiverStream < Result < proto:: WatchServiceRoutesResponse , Status > > ;
256- async fn watch_service_routes (
257- & self ,
258- _: tonic:: Request < proto:: WatchServiceRoutesRequest > ,
259- ) -> Result < Response < Self :: WatchServiceRoutesStream > , Status > {
260- Err ( Status :: unimplemented ( "unused" ) )
261- }
262248 async fn peer_notify_config_update (
263249 & self ,
264250 _request : tonic:: Request < proto:: PeerNotifyConfigUpdateRequest > ,
@@ -1209,6 +1195,35 @@ impl SandboxUpdates for TestOpenShell {
12091195 }
12101196}
12111197
1198+ #[ tonic:: async_trait]
1199+ impl proto:: service_discovery_server:: ServiceDiscovery for TestOpenShell {
1200+ async fn get_service_route_snapshot (
1201+ & self ,
1202+ request : tonic:: Request < proto:: GetServiceRouteSnapshotRequest > ,
1203+ ) -> Result < Response < proto:: GetServiceRouteSnapshotResponse > , Status > {
1204+ if let Some ( expected) = & self . state . require_bearer
1205+ && request
1206+ . metadata ( )
1207+ . get ( "authorization" )
1208+ . and_then ( |v| v. to_str ( ) . ok ( ) )
1209+ != Some ( expected. as_str ( ) )
1210+ {
1211+ return Err ( Status :: unauthenticated ( "invalid or missing bearer token" ) ) ;
1212+ }
1213+ Ok ( Response :: new ( proto:: GetServiceRouteSnapshotResponse {
1214+ snapshot : Some ( proto:: ServiceRouteSnapshot :: default ( ) ) ,
1215+ } ) )
1216+ }
1217+ type WatchServiceRoutesStream =
1218+ tokio_stream:: wrappers:: ReceiverStream < Result < proto:: WatchServiceRoutesResponse , Status > > ;
1219+ async fn watch_service_routes (
1220+ & self ,
1221+ _: tonic:: Request < proto:: WatchServiceRoutesRequest > ,
1222+ ) -> Result < Response < Self :: WatchServiceRoutesStream > , Status > {
1223+ Err ( Status :: unimplemented ( "unused" ) )
1224+ }
1225+ }
1226+
12121227/// Spin up the mock gateway, return its endpoint URL.
12131228async fn start_mock ( state : Arc < MockState > ) -> String {
12141229 let listener = TcpListener :: bind ( "127.0.0.1:0" ) . await . unwrap ( ) ;
@@ -1218,11 +1233,15 @@ async fn start_mock(state: Arc<MockState>) -> String {
12181233 let updates = SandboxUpdatesServer :: new ( TestOpenShell {
12191234 state : state. clone ( ) ,
12201235 } ) ;
1236+ let discovery = proto:: service_discovery_server:: ServiceDiscoveryServer :: new ( TestOpenShell {
1237+ state : state. clone ( ) ,
1238+ } ) ;
12211239 let svc = OpenShellServer :: new ( TestOpenShell { state } ) ;
12221240 tokio:: spawn ( async move {
12231241 let _ = tonic:: transport:: Server :: builder ( )
12241242 . add_service ( svc)
12251243 . add_service ( updates)
1244+ . add_service ( discovery)
12261245 . serve_with_incoming ( stream)
12271246 . await ;
12281247 } ) ;
@@ -2471,6 +2490,58 @@ async fn raw_sandbox_updates_shares_transport_and_live_auth_slot() {
24712490 assert_eq ! ( * state. last_update. lock( ) . await , Some ( request) ) ;
24722491}
24732492
2493+ #[ tokio:: test]
2494+ async fn raw_discovery_shares_transport_and_refreshes_the_live_auth_slot ( ) {
2495+ let state = Arc :: new ( MockState {
2496+ require_bearer : Some ( "Bearer fresh-token" . into ( ) ) ,
2497+ ..Default :: default ( )
2498+ } ) ;
2499+ let endpoint = start_mock ( state) . await ;
2500+ let calls = Arc :: new ( AtomicU32 :: new ( 0 ) ) ;
2501+ let mut config = ClientConfig :: new ( & endpoint) ;
2502+ config. auth = Some ( AuthConfig :: Oidc {
2503+ token : "stale-token" . into ( ) ,
2504+ expires_at : Some (
2505+ std:: time:: SystemTime :: now ( )
2506+ . duration_since ( std:: time:: UNIX_EPOCH )
2507+ . unwrap ( )
2508+ . as_secs ( )
2509+ + 5 ,
2510+ ) ,
2511+ refresh : Some ( Arc :: new ( OneShotRefresher {
2512+ calls : calls. clone ( ) ,
2513+ } ) ) ,
2514+ } ) ;
2515+ let client = OpenShellClient :: connect ( config) . await . unwrap ( ) ;
2516+ let mut discovery = client. raw_service_discovery ( ) ;
2517+ let request = proto:: GetServiceRouteSnapshotRequest {
2518+ workspace_scope : Some ( proto:: workspace_selector ( "team" ) ) ,
2519+ } ;
2520+ assert_eq ! (
2521+ discovery
2522+ . get_service_route_snapshot( request. clone( ) )
2523+ . await
2524+ . unwrap_err( )
2525+ . code( ) ,
2526+ tonic:: Code :: Unauthenticated
2527+ ) ;
2528+ assert_eq ! ( calls. load( Ordering :: SeqCst ) , 0 ) ;
2529+ client
2530+ . raw_service_discovery_fresh ( )
2531+ . await
2532+ . unwrap ( )
2533+ . get_service_route_snapshot ( request. clone ( ) )
2534+ . await
2535+ . unwrap ( ) ;
2536+ assert_eq ! ( calls. load( Ordering :: SeqCst ) , 1 ) ;
2537+ discovery. get_service_route_snapshot ( request) . await . unwrap ( ) ;
2538+ client
2539+ . raw_grpc ( )
2540+ . health ( proto:: HealthRequest { } )
2541+ . await
2542+ . unwrap ( ) ;
2543+ }
2544+
24742545#[ tokio:: test]
24752546async fn watch_logs_forwards_logs_and_warnings ( ) {
24762547 let state = Arc :: new ( MockState {
0 commit comments