Skip to content

Commit aecd423

Browse files
committed
fix(sdk): adapt to main proto drift after rebase
Rebasing the SDK extraction onto main surfaced three breaking changes: - tonic 0.12 -> 0.14 renamed the `tls` feature; use the `channel` + `tls-native-roots` features the other client crates use. - phase and current_policy_version moved out of `Sandbox` into the nested `SandboxStatus` message (#1565); read phase from `status`. - GPU selection moved under `SandboxSpec.resource_requirements` and `gpu_device` was removed (#1815, device selection is now driver config); map the SDK `gpu` flag onto `ResourceRequirements` and drop `gpu_device` from the public spec and napi binding. Update the client_mock test (status.phase, new update_provider_profiles RPC, resource_requirements assertion) and regenerate the napi index.d.ts.
1 parent b629766 commit aecd423

6 files changed

Lines changed: 25 additions & 16 deletions

File tree

crates/openshell-sdk-node/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,4 @@ export interface SandboxSpec {
134134
environment?: Record<string, string>
135135
providers?: Array<string>
136136
gpu?: boolean
137-
gpuDevice?: string
138137
}

crates/openshell-sdk-node/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub struct SandboxSpec {
9090
pub environment: Option<HashMap<String, String>>,
9191
pub providers: Option<Vec<String>>,
9292
pub gpu: Option<bool>,
93-
pub gpu_device: Option<String>,
9493
}
9594

9695
/// Options for [`OpenShellClient::list_sandboxes`].
@@ -164,7 +163,6 @@ fn sdk_spec_from_js(spec: SandboxSpec) -> sdk::SandboxSpec {
164163
environment: spec.environment.unwrap_or_default(),
165164
providers: spec.providers.unwrap_or_default(),
166165
gpu: spec.gpu.unwrap_or(false),
167-
gpu_device: spec.gpu_device,
168166
}
169167
}
170168

crates/openshell-sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tokio = { workspace = true }
2727
tokio-rustls = { workspace = true }
2828
tokio-stream = { workspace = true }
2929
tokio-tungstenite = { workspace = true }
30-
tonic = { workspace = true, features = ["tls", "tls-native-roots"] }
30+
tonic = { workspace = true, features = ["channel", "tls-native-roots"] }
3131
tower = { workspace = true }
3232
tracing = { workspace = true }
3333

crates/openshell-sdk/src/client.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,20 @@ fn create_sandbox_request(spec: SandboxSpec) -> proto::CreateSandboxRequest {
290290
environment,
291291
providers,
292292
gpu,
293-
gpu_device,
294293
} = spec;
295294
let template = image.map(|image| proto::SandboxTemplate {
296295
image,
297296
..proto::SandboxTemplate::default()
298297
});
298+
let resource_requirements = gpu.then(|| proto::ResourceRequirements {
299+
gpu: Some(proto::GpuResourceRequirements { count: None }),
300+
});
299301
proto::CreateSandboxRequest {
300302
spec: Some(proto::SandboxSpec {
301303
environment,
302304
template,
303305
providers,
304-
gpu,
305-
gpu_device: gpu_device.unwrap_or_default(),
306+
resource_requirements,
306307
..proto::SandboxSpec::default()
307308
}),
308309
name: name.unwrap_or_default(),

crates/openshell-sdk/src/types.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ pub struct SandboxSpec {
102102
pub providers: Vec<String>,
103103
/// Request a GPU.
104104
pub gpu: bool,
105-
/// Driver-specific GPU device selector (CDI ID for Docker/Podman; BDF or
106-
/// index for VM). Only meaningful when `gpu` is true; empty defers to the
107-
/// driver's default selection.
108-
pub gpu_device: Option<String>,
109105
}
110106

111107
/// Reference to a sandbox owned by the gateway.
@@ -122,10 +118,11 @@ pub struct SandboxRef {
122118
impl SandboxRef {
123119
pub(crate) fn from_proto(sandbox: proto::Sandbox) -> Self {
124120
let meta = sandbox.metadata.unwrap_or_default();
121+
let phase = sandbox.status.unwrap_or_default().phase;
125122
Self {
126123
id: meta.id,
127124
name: meta.name,
128-
phase: sandbox.phase.into(),
125+
phase: phase.into(),
129126
labels: meta.labels,
130127
resource_version: meta.resource_version,
131128
}

crates/openshell-sdk/tests/client_mock.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ fn sandbox_with_phase(name: &str, phase: proto::SandboxPhase) -> proto::Sandbox
5252
resource_version: 1,
5353
}),
5454
spec: None,
55-
status: None,
56-
phase: phase.into(),
57-
current_policy_version: 0,
55+
status: Some(proto::SandboxStatus {
56+
phase: phase.into(),
57+
..Default::default()
58+
}),
5859
}
5960
}
6061

@@ -70,6 +71,13 @@ impl OpenShell for TestOpenShell {
7071
}))
7172
}
7273

74+
async fn update_provider_profiles(
75+
&self,
76+
_: tonic::Request<proto::UpdateProviderProfilesRequest>,
77+
) -> Result<Response<proto::UpdateProviderProfilesResponse>, Status> {
78+
Ok(Response::new(proto::UpdateProviderProfilesResponse::default()))
79+
}
80+
7381
async fn create_sandbox(
7482
&self,
7583
request: tonic::Request<proto::CreateSandboxRequest>,
@@ -599,7 +607,13 @@ async fn create_sandbox_passes_spec_through() {
599607
assert_eq!(observed.name, "my-box");
600608
assert_eq!(observed.labels, labels);
601609
let observed_spec = observed.spec.unwrap();
602-
assert!(observed_spec.gpu);
610+
assert!(
611+
observed_spec
612+
.resource_requirements
613+
.as_ref()
614+
.and_then(|r| r.gpu.as_ref())
615+
.is_some()
616+
);
603617
assert_eq!(
604618
observed_spec.template.as_ref().unwrap().image,
605619
"ghcr.io/foo:bar"

0 commit comments

Comments
 (0)