Skip to content

Commit e26d200

Browse files
committed
fix(sdk/js): treat null volume backends as absent in validation
Address Codex review feedback: use `!= null` instead of `!== undefined` so that JSON-normalized null optionals (e.g. `{ ossfs: null }`) are correctly treated as absent rather than counting as a specified backend. Add test case to verify null backends do not trigger multi-backend error.
1 parent 55704bb commit e26d200

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

sdks/sandbox/javascript/src/sandbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export class Sandbox {
246246
// Validate volumes: exactly one backend must be specified per volume
247247
if (opts.volumes) {
248248
for (const vol of opts.volumes) {
249-
const backendsSpecified = [vol.host, vol.pvc, vol.ossfs].filter((b) => b !== undefined).length;
249+
const backendsSpecified = [vol.host, vol.pvc, vol.ossfs].filter((b) => b != null).length;
250250
if (backendsSpecified === 0) {
251251
throw new Error(
252252
`Volume '${vol.name}' must specify exactly one backend (host, pvc, ossfs), but none was provided.`

sdks/sandbox/javascript/tests/sandbox.create.test.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,26 @@ test("Sandbox.create rejects volume with multiple backends", async () => {
216216
/must specify exactly one backend \(host, pvc, ossfs\)/
217217
);
218218
});
219+
220+
test("Sandbox.create treats null backends as absent", async () => {
221+
const { adapterFactory, recordedRequests } = createAdapterFactory();
222+
223+
await Sandbox.create({
224+
adapterFactory,
225+
connectionConfig: { domain: "http://127.0.0.1:8080" },
226+
image: "python:3.12",
227+
skipHealthCheck: true,
228+
volumes: [
229+
{
230+
name: "host-with-null-ossfs",
231+
host: { path: "/tmp" },
232+
ossfs: null,
233+
pvc: undefined,
234+
mountPath: "/mnt",
235+
},
236+
],
237+
});
238+
239+
assert.equal(recordedRequests.length, 1);
240+
assert.equal(recordedRequests[0].volumes[0].host.path, "/tmp");
241+
});

0 commit comments

Comments
 (0)