|
7 | 7 | type DeviceServiceState, |
8 | 8 | } from "@t3tools/contracts"; |
9 | 9 | import * as Effect from "effect/Effect"; |
| 10 | +import * as Exit from "effect/Exit"; |
10 | 11 | import * as Deferred from "effect/Deferred"; |
11 | 12 | import * as Fiber from "effect/Fiber"; |
12 | 13 | import * as PubSub from "effect/PubSub"; |
@@ -470,87 +471,97 @@ it.effect.each(["shutdown", "close"] as const)( |
470 | 471 | ), |
471 | 472 | ); |
472 | 473 |
|
473 | | -it.effect("shuts down an iOS simulator that is already off through the tolerant hub route", () => |
474 | | - Effect.gen(function* () { |
475 | | - const deviceId = DeviceId.make("22222222-2222-2222-2222-222222222222"); |
476 | | - const paths: string[] = []; |
477 | | - // Stale: the simulator was powered off outside T3. |
478 | | - let booted = true; |
479 | | - const ready: DeviceHost.DeviceHostReady = { |
480 | | - nodePath: process.execPath, |
481 | | - hub: { origin: "http://device.test" }, |
482 | | - helpers: { serveSimAxSettings: null, serveSimCli: null }, |
483 | | - run: () => Effect.succeed({ code: 0, stdout: "", stderr: "" }), |
484 | | - }; |
485 | | - const host: DeviceHost.DeviceHost["Service"] = { |
486 | | - id: LOCAL_DEVICE_HOST_ID, |
487 | | - summary: Effect.succeed({ |
| 474 | +it.effect.each([ |
| 475 | + { hubReportsBooted: false, outcome: "succeeds" }, |
| 476 | + { hubReportsBooted: true, outcome: "fails" }, |
| 477 | +] as const)( |
| 478 | + "iOS shutdown $outcome when serve-sim rejects it and the hub reports booted=$hubReportsBooted", |
| 479 | + ({ hubReportsBooted, outcome }) => |
| 480 | + Effect.gen(function* () { |
| 481 | + const deviceId = DeviceId.make("22222222-2222-2222-2222-222222222222"); |
| 482 | + const paths: string[] = []; |
| 483 | + // The device list is stale until shutdown re-reads it from the hub. |
| 484 | + let booted = true; |
| 485 | + const ready: DeviceHost.DeviceHostReady = { |
| 486 | + nodePath: process.execPath, |
| 487 | + hub: { origin: "http://device.test" }, |
| 488 | + helpers: { serveSimAxSettings: null, serveSimCli: null }, |
| 489 | + run: () => Effect.succeed({ code: 0, stdout: "", stderr: "" }), |
| 490 | + }; |
| 491 | + const host: DeviceHost.DeviceHost["Service"] = { |
488 | 492 | id: LOCAL_DEVICE_HOST_ID, |
489 | | - kind: "local", |
490 | | - label: "Simulator host", |
491 | | - platforms: [{ platform: "ios", available: true }], |
492 | | - hubInstalled: true, |
493 | | - agentDeviceInstalled: false, |
494 | | - }), |
495 | | - platformAvailability: (platform) => Effect.succeed({ platform, available: true }), |
496 | | - ensureReady: () => Effect.succeed(ready), |
497 | | - ensureAgentReady: () => Effect.die("Agent access is not used in this test"), |
498 | | - current: Effect.succeed(ready), |
499 | | - stopAgent: Effect.void, |
500 | | - stop: Effect.void, |
501 | | - }; |
502 | | - const http = HttpClient.make((request) => |
503 | | - Effect.sync(() => { |
504 | | - const path = new URL(request.url).pathname; |
505 | | - paths.push(path); |
506 | | - if (path === "/api/devices") { |
507 | | - return HttpClientResponse.fromWeb( |
508 | | - request, |
509 | | - Response.json({ |
510 | | - emulators: [], |
511 | | - simulators: [ |
512 | | - { |
513 | | - id: deviceId, |
514 | | - name: "iPhone", |
515 | | - platform: "ios", |
516 | | - version: "26", |
517 | | - physical: false, |
518 | | - booted, |
519 | | - }, |
520 | | - ], |
521 | | - }), |
522 | | - ); |
523 | | - } |
524 | | - if (path === "/vendor/serve-sim/grid/api/shutdown") { |
525 | | - // serve-sim runs `simctl shutdown` bare and fails on an already-off device. |
526 | | - return HttpClientResponse.fromWeb( |
527 | | - request, |
528 | | - Response.json( |
529 | | - { ok: false, error: "Unable to shutdown device in current state: Shutdown" }, |
530 | | - { status: 500 }, |
531 | | - ), |
532 | | - ); |
533 | | - } |
534 | | - if (path === "/api/devices/shutdown") { |
535 | | - booted = false; |
536 | | - return HttpClientResponse.fromWeb(request, Response.json({ ok: true, id: deviceId })); |
537 | | - } |
538 | | - throw new Error(`Unexpected hub path: ${path}`); |
539 | | - }), |
540 | | - ); |
541 | | - const service = yield* makeWithHosts(new Map([[host.id, host]])).pipe( |
542 | | - Effect.provideService(HttpClient.HttpClient, http), |
543 | | - ); |
544 | | - yield* service.shutdown({ deviceId, platform: "ios" }); |
545 | | - expect(paths.filter((path) => path.endsWith("shutdown"))).toEqual([ |
546 | | - "/vendor/serve-sim/grid/api/shutdown", |
547 | | - "/api/devices/shutdown", |
548 | | - ]); |
549 | | - expect((yield* service.state).devices.find((device) => device.id === deviceId)?.booted).toBe( |
550 | | - false, |
551 | | - ); |
552 | | - }).pipe( |
553 | | - Effect.provide(ServerSettingsService.layerTest({ enableDeviceSupport: true })), |
554 | | - Effect.scoped, |
555 | | - ), |
| 493 | + summary: Effect.succeed({ |
| 494 | + id: LOCAL_DEVICE_HOST_ID, |
| 495 | + kind: "local", |
| 496 | + label: "Simulator host", |
| 497 | + platforms: [{ platform: "ios", available: true }], |
| 498 | + hubInstalled: true, |
| 499 | + agentDeviceInstalled: false, |
| 500 | + }), |
| 501 | + platformAvailability: (platform) => Effect.succeed({ platform, available: true }), |
| 502 | + ensureReady: () => Effect.succeed(ready), |
| 503 | + ensureAgentReady: () => Effect.die("Agent access is not used in this test"), |
| 504 | + current: Effect.succeed(ready), |
| 505 | + stopAgent: Effect.void, |
| 506 | + stop: Effect.void, |
| 507 | + }; |
| 508 | + const http = HttpClient.make((request) => |
| 509 | + Effect.sync(() => { |
| 510 | + const path = new URL(request.url).pathname; |
| 511 | + paths.push(path); |
| 512 | + if (path === "/api/devices") { |
| 513 | + return HttpClientResponse.fromWeb( |
| 514 | + request, |
| 515 | + Response.json({ |
| 516 | + emulators: [], |
| 517 | + simulators: [ |
| 518 | + { |
| 519 | + id: deviceId, |
| 520 | + name: "iPhone", |
| 521 | + platform: "ios", |
| 522 | + version: "26", |
| 523 | + physical: false, |
| 524 | + booted, |
| 525 | + }, |
| 526 | + ], |
| 527 | + }), |
| 528 | + ); |
| 529 | + } |
| 530 | + if (path === "/vendor/serve-sim/grid/api/shutdown") { |
| 531 | + // serve-sim runs `simctl shutdown` bare and returns its failure as-is. |
| 532 | + booted = hubReportsBooted; |
| 533 | + return HttpClientResponse.fromWeb( |
| 534 | + request, |
| 535 | + Response.json( |
| 536 | + { ok: false, error: "Unable to shutdown device in current state: Shutdown" }, |
| 537 | + { status: 500 }, |
| 538 | + ), |
| 539 | + ); |
| 540 | + } |
| 541 | + throw new Error(`Unexpected hub path: ${path}`); |
| 542 | + }), |
| 543 | + ); |
| 544 | + const service = yield* makeWithHosts(new Map([[host.id, host]])).pipe( |
| 545 | + Effect.provideService(HttpClient.HttpClient, http), |
| 546 | + ); |
| 547 | + yield* service.list; |
| 548 | + const exit = yield* Effect.exit(service.shutdown({ deviceId, platform: "ios" })); |
| 549 | + expect(paths.filter((path) => path.endsWith("shutdown"))).toEqual([ |
| 550 | + "/vendor/serve-sim/grid/api/shutdown", |
| 551 | + ]); |
| 552 | + if (outcome === "succeeds") { |
| 553 | + expect(Exit.isSuccess(exit)).toBe(true); |
| 554 | + expect( |
| 555 | + (yield* service.state).devices.find((device) => device.id === deviceId)?.booted, |
| 556 | + ).toBe(false); |
| 557 | + } else { |
| 558 | + expect(Exit.isFailure(exit)).toBe(true); |
| 559 | + expect( |
| 560 | + (yield* service.state).devices.find((device) => device.id === deviceId)?.booted, |
| 561 | + ).toBe(true); |
| 562 | + } |
| 563 | + }).pipe( |
| 564 | + Effect.provide(ServerSettingsService.layerTest({ enableDeviceSupport: true })), |
| 565 | + Effect.scoped, |
| 566 | + ), |
556 | 567 | ); |
0 commit comments