Skip to content

Commit 5cbad62

Browse files
committed
fix(boxlite): start boxes after node sdk create
1 parent ef040c5 commit 5cbad62

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/boxlite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sandbank.dev/boxlite",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "BoxLite bare-metal sandbox adapter for Sandbank",
55
"license": "MIT",
66
"type": "module",

packages/boxlite/src/local-client.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,18 @@ export function createBoxLiteLocalClient(config: BoxLiteLocalConfig): BoxLiteCli
207207
return fresh
208208
}
209209

210+
async function startCreatedBox(box: NativeBox): Promise<NativeBox> {
211+
const status = normalizeStatus(box.info())
212+
if (status === 'running') return box
213+
214+
if (status === 'configured' || status === 'stopped' || status === 'paused') {
215+
await box.start()
216+
return await refreshBox(box.id).catch(() => box)
217+
}
218+
219+
return box
220+
}
221+
210222
async function startNativeExecution(boxId: string, req: BoxLiteExecRequest): Promise<NativeExecution> {
211223
const [command, ...args] = req.cmd
212224
if (!command) throw new Error('BoxLite exec requires a non-empty cmd array')
@@ -233,7 +245,7 @@ export function createBoxLiteLocalClient(config: BoxLiteLocalConfig): BoxLiteCli
233245

234246
return {
235247
async createBox(params: BoxLiteCreateParams): Promise<BoxLiteBox> {
236-
const box = await runtime.create(createBoxOptions(params), params.name ?? null)
248+
const box = await startCreatedBox(await runtime.create(createBoxOptions(params), params.name ?? null))
237249
boxes.set(box.id, box)
238250
return mapBoxInfo(box.info())
239251
},

packages/boxlite/test/local-client.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const mockState = vi.hoisted(() => {
9292
const box = makeBox({
9393
id: 'box_new',
9494
name: name ?? null,
95+
state: { status: 'configured', running: false },
9596
image: boxOptions.rootfsPath ?? boxOptions.image ?? '',
9697
cpus: boxOptions.cpus ?? 1,
9798
memoryMib: boxOptions.memoryMib ?? 512,
@@ -208,6 +209,7 @@ describe('BoxLiteLocalClient', () => {
208209
cmd: ['-lc', 'sleep infinity'],
209210
user: 'sandbank',
210211
}), 'named-box')
212+
expect(runtime.boxes.get('box_new').start).toHaveBeenCalledTimes(1)
211213
expect(box).toMatchObject({
212214
id: 'box_new',
213215
name: 'named-box',

0 commit comments

Comments
 (0)