Skip to content

Commit 14bd21c

Browse files
committed
fix(ios): pass the cancel signal to the tvOS pbcopy write, and tidy the pasteboard test
1 parent aaef1f2 commit 14bd21c

4 files changed

Lines changed: 26 additions & 10 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+PasteboardWriteTests.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extension RunnerTests {
1313
@MainActor
1414
func testPasteboardWriteLeavesTheTextOnTheGeneralPasteboard() throws {
1515
let text = "one-time code \(UUID().uuidString)"
16+
defer { UIPasteboard.general.items = [] }
1617
let request = #"{"command":"pasteboardWrite","text":"\#(text)"}"#
1718
let response = executePasteboardWrite(command: try runnerCommandFixture(request))
1819
XCTAssertTrue(response.ok)

‎packages/platform-apple/src/core/__tests__/app-device-io.test.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ vi.mock('../simulator.ts', async (importOriginal) => ({
1414
ensureBootedSimulator: async () => {},
1515
}));
1616

17-
async function writeThroughBothRoutes(device: typeof IOS_SIMULATOR, text: string) {
17+
async function writeThroughBothRoutes(
18+
device: typeof IOS_SIMULATOR,
19+
text: string,
20+
signal = new AbortController().signal,
21+
) {
1822
const runnerCalls: RecordedRunnerCall[] = [];
19-
const toolCalls: Array<{ args: string[]; stdin: unknown }> = [];
23+
const toolCalls: Array<{ args: string[]; stdin: unknown; signal: unknown }> = [];
2024
const tools = createLocalAppleToolProvider({
2125
runCommand: async (_cmd, args, options) => {
22-
toolCalls.push({ args, stdin: options?.stdin });
26+
toolCalls.push({ args, stdin: options?.stdin, signal: options?.signal });
2327
return { exitCode: 0, stdout: '', stderr: '' };
2428
},
2529
});
2630
await withAppleToolProvider(tools, () =>
2731
withAppleRunnerProvider(recordingRunnerProvider(runnerCalls), { deviceId: device.id }, () =>
28-
writeIosClipboardText(device, text),
32+
writeIosClipboardText(device, text, { signal }),
2933
),
3034
);
3135
return { runnerCommands: runnerCalls.map(({ command }) => command), toolCalls };
@@ -40,9 +44,15 @@ test('an iOS simulator clipboard write is the runner setting the pasteboard, not
4044
});
4145

4246
test('a tvOS simulator, whose runner has no pasteboard, writes through simctl pbcopy', async () => {
43-
const { runnerCommands, toolCalls } = await writeThroughBothRoutes(TVOS_SIMULATOR, 'code 246810');
47+
const signal = new AbortController().signal;
48+
const { runnerCommands, toolCalls } = await writeThroughBothRoutes(
49+
TVOS_SIMULATOR,
50+
'code 246810',
51+
signal,
52+
);
4453
assert.deepEqual(runnerCommands, []);
4554
assert.equal(toolCalls.length, 1);
4655
assert.deepEqual(toolCalls[0]?.args.slice(-2), ['pbcopy', TVOS_SIMULATOR.id]);
4756
assert.equal(toolCalls[0]?.stdin, 'code 246810');
57+
assert.equal(toolCalls[0]?.signal, signal);
4858
});

‎packages/platform-apple/src/core/app-device-io.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ export async function writeIosClipboardText(
3636
}
3737
requireSimulatorDevice(device, 'clipboard');
3838
if (isTvOsDevice(device)) {
39-
await ensureBootedSimulator(device);
39+
const signal = runnerOptions?.signal;
40+
await ensureBootedSimulator(device, { signal });
4041
requireExecSuccess(
41-
await runSimctlForDevice(device, ['pbcopy', device.id], { allowFailure: true, stdin: text }),
42+
await runSimctlForDevice(device, ['pbcopy', device.id], {
43+
allowFailure: true,
44+
stdin: text,
45+
signal,
46+
}),
4247
'Failed to write tvOS simulator clipboard',
4348
);
4449
return;

‎packages/platform-apple/src/system/runtime.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ function appleHostOrSimulatorFact(
8585
}
8686

8787
/**
88-
* Read and write share one cell: both routes (the simulator's `simctl pbpaste` read and runner
89-
* write, and the macOS host pasteboard) expose the pair or neither, so splitting them here would
90-
* invent a cell no Apple owner can actually be in.
88+
* Read and write share one cell: both routes (the simulator's `simctl pbpaste` read with its
89+
* runner write, or `simctl pbcopy` on tvOS, and the macOS host pasteboard) expose the pair or
90+
* neither, so splitting them here would invent a cell no Apple owner can actually be in.
9191
*/
9292
function appleClipboardFact(device: DeviceInfo): RuntimeOperationFact {
9393
return appleHostOrSimulatorFact(device, clipboardKindUnavailable, clipboardLeafUnavailable);

0 commit comments

Comments
 (0)