Skip to content

Commit abdf845

Browse files
fix(server): require the hub to list the simulator as off before accepting a rejected shutdown
Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent cfc3831 commit abdf845

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

‎apps/server/src/device/DeviceService.test.ts‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -472,16 +472,17 @@ it.effect.each(["shutdown", "close"] as const)(
472472
);
473473

474474
it.effect.each([
475-
{ hubReportsBooted: false, outcome: "succeeds" },
476-
{ hubReportsBooted: true, outcome: "fails" },
475+
{ hubReports: "off", outcome: "succeeds" },
476+
{ hubReports: "booted", outcome: "fails" },
477+
{ hubReports: "missing", outcome: "fails" },
477478
] as const)(
478-
"iOS shutdown $outcome when serve-sim rejects it and the hub reports booted=$hubReportsBooted",
479-
({ hubReportsBooted, outcome }) =>
479+
"iOS shutdown $outcome when serve-sim rejects it and the hub reports the simulator $hubReports",
480+
({ hubReports, outcome }) =>
480481
Effect.gen(function* () {
481482
const deviceId = DeviceId.make("22222222-2222-2222-2222-222222222222");
482483
const paths: string[] = [];
483484
// The device list is stale until shutdown re-reads it from the hub.
484-
let booted = true;
485+
let listed: "booted" | "off" | "missing" = "booted";
485486
const ready: DeviceHost.DeviceHostReady = {
486487
nodePath: process.execPath,
487488
hub: { origin: "http://device.test" },
@@ -514,22 +515,27 @@ it.effect.each([
514515
request,
515516
Response.json({
516517
emulators: [],
517-
simulators: [
518-
{
519-
id: deviceId,
520-
name: "iPhone",
521-
platform: "ios",
522-
version: "26",
523-
physical: false,
524-
booted,
525-
},
526-
],
518+
simulators:
519+
listed === "missing"
520+
? []
521+
: [
522+
{
523+
id: deviceId,
524+
name: "iPhone",
525+
platform: "ios",
526+
version: "26",
527+
physical: false,
528+
booted: listed === "booted",
529+
},
530+
],
531+
// A partial listing still decodes; it must not read as "off".
532+
errors: listed === "missing" ? [{ message: "simctl list failed" }] : [],
527533
}),
528534
);
529535
}
530536
if (path === "/vendor/serve-sim/grid/api/shutdown") {
531537
// serve-sim runs `simctl shutdown` bare and returns its failure as-is.
532-
booted = hubReportsBooted;
538+
listed = hubReports;
533539
return HttpClientResponse.fromWeb(
534540
request,
535541
Response.json(

‎apps/server/src/device/DeviceService.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,9 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
700700
Effect.catch((cause) =>
701701
fetchDevices(ready).pipe(
702702
Effect.flatMap(({ devices }) =>
703-
devices.some((device) => device.id === deviceId && device.booted)
704-
? Effect.fail(cause)
705-
: Effect.logInfo("iOS simulator was already shut down", { deviceId }),
703+
devices.find((device) => device.id === deviceId)?.booted === false
704+
? Effect.logInfo("iOS simulator was already shut down", { deviceId })
705+
: Effect.fail(cause),
706706
),
707707
),
708708
),

0 commit comments

Comments
 (0)