@molecule/api-code-sandbox-flyio 1.3.9 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,KAAK,EAaV,eAAe,EAGhB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EACL,YAAY,EAKb,MAAM,UAAU,CAAA;AA8BjB,OAAO,KAAK,EAEV,wBAAwB,EAEzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAmD,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAEhG,OAAO,KAAK,EAIV,WAAW,EAUZ,MAAM,YAAY,CAAA;AAyBnB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAIjG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE5E;AAgyID;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,YAAY,EACrB,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,GACzB,eAAe,GAAG,wBAAwB,CAE5C"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,KAAK,EAaV,eAAe,EAGhB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EACL,YAAY,EAKb,MAAM,UAAU,CAAA;AA8BjB,OAAO,KAAK,EAEV,wBAAwB,EAEzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAmD,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAEhG,OAAO,KAAK,EAIV,WAAW,EAUZ,MAAM,YAAY,CAAA;AAyBnB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAIjG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE5E;AA4zID;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,YAAY,EACrB,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,GACzB,eAAe,GAAG,wBAAwB,CAE5C"}
package/dist/provider.js CHANGED
@@ -3336,6 +3336,19 @@ class FlyioSandboxProvider {
3336
3336
  `${totalSeconds}s (last observed state: ${lastState ?? 'unknown'}).`,
3337
3337
  }), { cause: lastError });
3338
3338
  }
3339
+ /**
3340
+ * Activate an already populated Machine with one full-config update: startup command and idle
3341
+ * policy change together. The former command keeps the workload stopped, so the update's reboot
3342
+ * is the workload's first boot. Fly preserves parked Machines with skip_launch; startMachine
3343
+ * explicitly wakes those and waits, and is idempotent after a running Machine's update.
3344
+ */
3345
+ async activate(id, options) {
3346
+ if (!options.command.length)
3347
+ throw new Error('A sandbox activation needs a startup command');
3348
+ const { app, machineId } = parseSandboxId(id);
3349
+ await this.applyIdleAction(app, machineId, options.idleAction, options.command);
3350
+ await this.startMachine(app, machineId);
3351
+ }
3339
3352
  /**
3340
3353
  * Applies an idle policy to a running Machine's public service, in place.
3341
3354
  *
@@ -3356,10 +3369,11 @@ class FlyioSandboxProvider {
3356
3369
  * @param app - The Fly app name.
3357
3370
  * @param machineId - The Fly Machine id.
3358
3371
  * @param action - The idle action to apply to every service.
3372
+ * @param command - An activation command installed in the SAME update as the policy.
3359
3373
  * @throws {Error} When the Machine or its config cannot be read, the update is
3360
3374
  * rejected, or a rebooted Machine does not come back to `started`.
3361
3375
  */
3362
- async applyIdleAction(app, machineId, action) {
3376
+ async applyIdleAction(app, machineId, action, command) {
3363
3377
  const machine = await this.client.request(`/apps/${app}/machines/${machineId}`, {
3364
3378
  nullOn: [404],
3365
3379
  });
@@ -3370,14 +3384,21 @@ class FlyioSandboxProvider {
3370
3384
  }));
3371
3385
  }
3372
3386
  const services = machine.config.services;
3373
- if (!services?.length)
3374
- return;
3375
- if (services.every((service) => (service.autostop ?? 'off') === action))
3376
- return;
3387
+ const samePolicy = !services?.length || services.every((service) => (service.autostop ?? 'off') === action);
3388
+ const sameCommand = !command || JSON.stringify(machine.config.init?.exec) === JSON.stringify(command);
3389
+ if (samePolicy && sameCommand)
3390
+ return mapMachineState(machine.state ?? 'created');
3377
3391
  const config = {
3378
3392
  ...machine.config,
3379
- services: services.map((service) => ({ ...service, autostop: action })),
3393
+ ...(services
3394
+ ? { services: services.map((service) => ({ ...service, autostop: action })) }
3395
+ : {}),
3380
3396
  };
3397
+ if (command) {
3398
+ config.init = { ...machine.config.init, exec: [...command] };
3399
+ delete config.init.entrypoint;
3400
+ delete config.init.cmd;
3401
+ }
3381
3402
  // A running Machine reboots to apply the config, so wait for it; a parked
3382
3403
  // one is updated without being started (there is nothing to wait for).
3383
3404
  const wasRunning = machine.state === 'started' || machine.state === 'starting';
@@ -3394,6 +3415,7 @@ class FlyioSandboxProvider {
3394
3415
  });
3395
3416
  if (wasRunning)
3396
3417
  await this.waitForStarted(app, machineId);
3418
+ return wasRunning ? 'running' : mapMachineState(machine.state ?? 'created');
3397
3419
  }
3398
3420
  /**
3399
3421
  * Builds the `Sandbox` facade for one Machine.
@@ -3442,11 +3464,10 @@ class FlyioSandboxProvider {
3442
3464
  /**
3443
3465
  * Applies an idle policy to this Machine's public service (see
3444
3466
  * {@link FlyioSandboxProvider.applyIdleAction} for the endpoint and the
3445
- * reboot it costs). Resolves with the Machine running again.
3467
+ * reboot it costs). A parked Machine stays parked; a rebooted Machine is running again.
3446
3468
  */
3447
3469
  async setIdleAction(action) {
3448
- await provider.applyIdleAction(app, machineId, action);
3449
- this.status = 'running';
3470
+ this.status = await provider.applyIdleAction(app, machineId, action);
3450
3471
  },
3451
3472
  async exec(command, opts) {
3452
3473
  return await execCommand(exec, command, opts, WORKSPACE_PATH);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-code-sandbox-flyio",
3
- "version": "1.3.9",
3
+ "version": "1.4.0",
4
4
  "description": "Fly.io Machines (Firecracker microVM) code sandbox provider",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "license": "Apache-2.0",
32
32
  "devDependencies": {
33
33
  "@molecule/api-bond": "1.0.4",
34
- "@molecule/api-code-sandbox": "1.6.1",
34
+ "@molecule/api-code-sandbox": "1.7.0",
35
35
  "@types/node": "26.6.5",
36
36
  "typescript": "6.0.3",
37
37
  "vitest": "4.1.12"