Skip to content

Commit 8736096

Browse files
PR Batch Testerclaude
andcommitted
fix(server): route the Save screenshot button through the device service
The panel's Save screenshot posted straight to the hub's serve-sim screenshot route, so it skipped the Xcode 26 simctl fallback and still failed. On hosts served by the hub, the proxy now answers that request with DeviceService.screenshot. Hosts with their own upstreams (EAS, Simlock) and Android keep the proxied path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d55fb49 commit 8736096

2 files changed

Lines changed: 97 additions & 2 deletions

File tree

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

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
AuthOrchestrationReadScope,
44
AuthOrchestrationOperateScope,
55
AuthSessionId,
6+
DeviceOperationError,
7+
type DeviceSummary,
68
LOCAL_DEVICE_HOST_ID,
79
type AuthEnvironmentScope,
810
} from "@t3tools/contracts";
@@ -24,6 +26,8 @@ const fixture = (
2426
fail = false,
2527
authError?: EnvironmentAuth.ServerAuthCredentialError | EnvironmentAuth.ServerAuthInternalError,
2628
upstream?: DeviceHost.DeviceHostReady["upstream"],
29+
screenshot: DeviceService.DeviceService["Service"]["screenshot"] = () =>
30+
Effect.die(new Error("unexpected screenshot")),
2731
) => {
2832
let finalized = 0;
2933
const requests: string[] = [];
@@ -65,6 +69,7 @@ const fixture = (
6569
hub: { origin: "http://hub.test" },
6670
...(upstream ? { upstream } : {}),
6771
}),
72+
screenshot,
6873
} as DeviceService.DeviceService["Service"]),
6974
),
7075
Layer.provideMerge(Layer.succeed(HttpClient.HttpClient, client)),
@@ -202,7 +207,7 @@ describe("device hub proxy", () => {
202207
undefined,
203208
(hubPath, search) =>
204209
Effect.succeed(
205-
hubPath === "/vendor/serve-sim/api"
210+
hubPath === "/vendor/serve-sim/api" || hubPath === "/vendor/serve-sim/api/screenshot"
206211
? {
207212
url: `https://session.test${hubPath.slice("/vendor/serve-sim".length)}?${search}`,
208213
headers: { authorization: "Bearer session-token" },
@@ -221,11 +226,72 @@ describe("device hub proxy", () => {
221226
await routed.text();
222227
expect(requests).toEqual(["https://session.test/api?device=udid-1"]);
223228
expect(headers[0]?.authorization).toBe("Bearer session-token");
229+
const screenshot = await handler(
230+
new Request(
231+
"http://t3.test/api/device-hub/vendor/serve-sim/api/screenshot?device=udid-1&hostId=eas",
232+
{ method: "POST" },
233+
),
234+
);
235+
expect(screenshot.status).toBe(200);
236+
await screenshot.text();
237+
expect(requests).toEqual([
238+
"https://session.test/api?device=udid-1",
239+
"https://session.test/api/screenshot?device=udid-1",
240+
]);
224241
const unrouted = await handler(
225242
new Request("http://t3.test/api/device-hub/vendor/serve-sim/helper/udid-2/stream.mjpeg"),
226243
);
227244
expect(unrouted.status).toBe(404);
228-
expect(requests).toHaveLength(1);
245+
expect(requests).toHaveLength(2);
246+
});
247+
248+
it("captures iOS screenshots through the device service on hub hosts", async () => {
249+
const captured: Array<{ readonly hostId?: string | undefined; readonly deviceId: string }> = [];
250+
const png = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
251+
const { handler, requests } = fixture(
252+
[AuthOrchestrationReadScope],
253+
false,
254+
undefined,
255+
undefined,
256+
(input) => {
257+
captured.push(input);
258+
return input.deviceId === "udid-1"
259+
? Effect.succeed({ device: {} as DeviceSummary, png })
260+
: Effect.fail(
261+
new DeviceOperationError({
262+
operation: "screenshot",
263+
reason: "command_failed",
264+
cause: "simctl failed",
265+
}),
266+
);
267+
},
268+
);
269+
const hub = "http://t3.test/api/device-hub/vendor";
270+
const ios = await handler(
271+
new Request(`${hub}/serve-sim/api/screenshot?device=udid-1&hostId=local`, {
272+
method: "POST",
273+
}),
274+
);
275+
expect(ios.status).toBe(200);
276+
expect(ios.headers.get("content-type")).toBe("image/png");
277+
expect(new Uint8Array(await ios.arrayBuffer())).toEqual(png);
278+
const failed = await handler(
279+
new Request(`${hub}/serve-sim/api/screenshot?device=udid-2`, { method: "POST" }),
280+
);
281+
expect(failed.status).toBe(502);
282+
expect(await failed.text()).not.toContain("simctl failed");
283+
expect(captured).toEqual([
284+
{ hostId: LOCAL_DEVICE_HOST_ID, deviceId: "udid-1" },
285+
{ hostId: LOCAL_DEVICE_HOST_ID, deviceId: "udid-2" },
286+
]);
287+
const android = await handler(
288+
new Request(`${hub}/serve-emu/api/screenshot?device=emulator-5554`, { method: "POST" }),
289+
);
290+
expect(android.status).toBe(200);
291+
await android.text();
292+
expect(requests).toEqual([
293+
"http://hub.test/vendor/serve-emu/api/screenshot?device=emulator-5554",
294+
]);
229295
});
230296

231297
it("never forwards the vendor shell endpoint", async () => {

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,35 @@ const handler = Effect.gen(function* () {
208208
upstreamSearch.delete("wsTicket");
209209
upstreamSearch.delete("hostId");
210210
const search = upstreamSearch.size > 0 ? `?${upstreamSearch.toString()}` : "";
211+
// The service owns iOS screenshot compatibility, such as Xcode 26's simctl. Hosts with their own
212+
// upstreams keep their routing, and Simlock serves Android through serve-sim too.
213+
const screenshotDevice = upstreamSearch.get("device");
214+
if (
215+
!ready.upstream &&
216+
request.method === "POST" &&
217+
hubPath === "/vendor/serve-sim/api/screenshot" &&
218+
screenshotDevice &&
219+
upstreamSearch.size === 1
220+
) {
221+
return yield* devices.screenshot({ hostId: ready.hostId, deviceId: screenshotDevice }).pipe(
222+
Effect.map(({ png }) =>
223+
HttpServerResponse.uint8Array(png, {
224+
contentType: "image/png",
225+
headers: { "cache-control": "no-store" },
226+
}),
227+
),
228+
Effect.catch((error) =>
229+
Effect.logWarning("Device screenshot failed", { cause: error }).pipe(
230+
Effect.as(
231+
HttpServerResponse.text(
232+
error._tag === "DeviceNotFoundError" ? "Device not found" : "Screenshot failed",
233+
{ status: error._tag === "DeviceNotFoundError" ? 404 : 502 },
234+
),
235+
),
236+
),
237+
),
238+
);
239+
}
211240
// Hosts with several upstreams (one per cloud session) route and authenticate requests themselves.
212241
const routed = ready.upstream ? yield* ready.upstream(hubPath, upstreamSearch) : undefined;
213242
if (routed === null) {

0 commit comments

Comments
 (0)