@@ -7,7 +7,7 @@ pub mod vm;
77
88pub use vm:: VmComputeConfig ;
99
10- use crate :: grpc:: policy:: { SANDBOX_SETTINGS_OBJECT_TYPE , sandbox_settings_id } ;
10+ use crate :: grpc:: policy:: SANDBOX_SETTINGS_OBJECT_TYPE ;
1111use crate :: persistence:: { ObjectId , ObjectName , ObjectRecord , ObjectType , Store } ;
1212use crate :: sandbox_index:: SandboxIndex ;
1313use crate :: sandbox_watch:: SandboxWatchBus ;
@@ -406,7 +406,7 @@ impl ComputeRuntime {
406406
407407 if let Err ( e) = self
408408 . store
409- . delete ( SANDBOX_SETTINGS_OBJECT_TYPE , & sandbox_settings_id ( & id ) )
409+ . delete_by_name ( SANDBOX_SETTINGS_OBJECT_TYPE , & sandbox . name )
410410 . await
411411 {
412412 warn ! (
@@ -1183,6 +1183,115 @@ fn is_terminal_failure_reason(reason: &str) -> bool {
11831183 !transient_reasons. contains ( & reason. as_str ( ) )
11841184}
11851185
1186+ #[ cfg( test) ]
1187+ #[ derive( Debug , Default ) ]
1188+ pub ( crate ) struct NoopTestDriver ;
1189+
1190+ #[ cfg( test) ]
1191+ #[ tonic:: async_trait]
1192+ impl ComputeDriver for NoopTestDriver {
1193+ type WatchSandboxesStream = DriverWatchStream ;
1194+
1195+ async fn get_capabilities (
1196+ & self ,
1197+ _request : Request < GetCapabilitiesRequest > ,
1198+ ) -> Result < tonic:: Response < openshell_core:: proto:: compute:: v1:: GetCapabilitiesResponse > , Status >
1199+ {
1200+ Ok ( tonic:: Response :: new (
1201+ openshell_core:: proto:: compute:: v1:: GetCapabilitiesResponse {
1202+ driver_name : "noop-test-driver" . to_string ( ) ,
1203+ driver_version : "test" . to_string ( ) ,
1204+ default_image : "openshell/sandbox:test" . to_string ( ) ,
1205+ supports_gpu : false ,
1206+ } ,
1207+ ) )
1208+ }
1209+
1210+ async fn validate_sandbox_create (
1211+ & self ,
1212+ _request : Request < ValidateSandboxCreateRequest > ,
1213+ ) -> Result <
1214+ tonic:: Response < openshell_core:: proto:: compute:: v1:: ValidateSandboxCreateResponse > ,
1215+ Status ,
1216+ > {
1217+ Ok ( tonic:: Response :: new (
1218+ openshell_core:: proto:: compute:: v1:: ValidateSandboxCreateResponse { } ,
1219+ ) )
1220+ }
1221+
1222+ async fn get_sandbox (
1223+ & self ,
1224+ _request : Request < GetSandboxRequest > ,
1225+ ) -> Result < tonic:: Response < openshell_core:: proto:: compute:: v1:: GetSandboxResponse > , Status >
1226+ {
1227+ Err ( Status :: not_found ( "sandbox not found" ) )
1228+ }
1229+
1230+ async fn list_sandboxes (
1231+ & self ,
1232+ _request : Request < ListSandboxesRequest > ,
1233+ ) -> Result < tonic:: Response < openshell_core:: proto:: compute:: v1:: ListSandboxesResponse > , Status >
1234+ {
1235+ Ok ( tonic:: Response :: new (
1236+ openshell_core:: proto:: compute:: v1:: ListSandboxesResponse {
1237+ sandboxes : Vec :: new ( ) ,
1238+ } ,
1239+ ) )
1240+ }
1241+
1242+ async fn create_sandbox (
1243+ & self ,
1244+ _request : Request < CreateSandboxRequest > ,
1245+ ) -> Result < tonic:: Response < openshell_core:: proto:: compute:: v1:: CreateSandboxResponse > , Status >
1246+ {
1247+ Ok ( tonic:: Response :: new (
1248+ openshell_core:: proto:: compute:: v1:: CreateSandboxResponse { } ,
1249+ ) )
1250+ }
1251+
1252+ async fn stop_sandbox (
1253+ & self ,
1254+ _request : Request < openshell_core:: proto:: compute:: v1:: StopSandboxRequest > ,
1255+ ) -> Result < tonic:: Response < openshell_core:: proto:: compute:: v1:: StopSandboxResponse > , Status >
1256+ {
1257+ Ok ( tonic:: Response :: new (
1258+ openshell_core:: proto:: compute:: v1:: StopSandboxResponse { } ,
1259+ ) )
1260+ }
1261+
1262+ async fn delete_sandbox (
1263+ & self ,
1264+ _request : Request < DeleteSandboxRequest > ,
1265+ ) -> Result < tonic:: Response < openshell_core:: proto:: compute:: v1:: DeleteSandboxResponse > , Status >
1266+ {
1267+ Ok ( tonic:: Response :: new (
1268+ openshell_core:: proto:: compute:: v1:: DeleteSandboxResponse { deleted : true } ,
1269+ ) )
1270+ }
1271+
1272+ async fn watch_sandboxes (
1273+ & self ,
1274+ _request : Request < WatchSandboxesRequest > ,
1275+ ) -> Result < tonic:: Response < Self :: WatchSandboxesStream > , Status > {
1276+ Ok ( tonic:: Response :: new ( Box :: pin ( futures:: stream:: empty ( ) ) ) )
1277+ }
1278+ }
1279+
1280+ #[ cfg( test) ]
1281+ pub ( crate ) async fn new_test_runtime ( store : Arc < Store > ) -> ComputeRuntime {
1282+ ComputeRuntime {
1283+ driver : Arc :: new ( NoopTestDriver ) ,
1284+ _driver_process : None ,
1285+ default_image : "openshell/sandbox:test" . to_string ( ) ,
1286+ store,
1287+ sandbox_index : SandboxIndex :: new ( ) ,
1288+ sandbox_watch_bus : SandboxWatchBus :: new ( ) ,
1289+ tracing_log_bus : TracingLogBus :: new ( ) ,
1290+ supervisor_sessions : Arc :: new ( SupervisorSessionRegistry :: new ( ) ) ,
1291+ sync_lock : Arc :: new ( Mutex :: new ( ( ) ) ) ,
1292+ }
1293+ }
1294+
11861295#[ cfg( test) ]
11871296mod tests {
11881297 use super :: * ;
0 commit comments