Skip to content

Commit f9869c4

Browse files
committed
refactor(apple): name the foreground reading type
Export SystemSurfaceForegroundReading and use it in the probe signature and both route sites. The native wedge test block now says it pins the stale abandon stamp, and its expectation names the abandonment it waits for. Follow-up to #4267.
1 parent a68693c commit f9869c4

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,24 @@ extension RunnerTests {
8383
let admitted = RunnerSnapshotBridgeReadForTest(request, 1000, { ["ok": true] }, 16)
8484
XCTAssertEqual(admitted["ok"] as? Bool, true)
8585

86+
// A read admitted after an abandoned one must not inherit the old abandon stamp (10): checked at
87+
// 100, while this read is still inside its budget, a stale stamp would answer bridge-reader-wedged.
8688
let started = DispatchSemaphore(value: 0)
8789
let secondRelease = DispatchSemaphore(value: 0)
88-
let finished = expectation(description: "second read outlives its budget")
90+
let secondAbandoned = expectation(description: "the second read is abandoned at its budget")
8991
DispatchQueue.global().async {
9092
let second = RunnerSnapshotBridgeReadForTest(request, 1000, {
9193
started.signal()
9294
secondRelease.wait()
9395
return ["ok": true]
9496
}, 100)
9597
XCTAssertEqual(second["error_code"] as? String, "bridge-read-abandoned")
96-
finished.fulfill()
98+
secondAbandoned.fulfill()
9799
}
98100
started.wait()
99101
let secondBusy = RunnerSnapshotBridgeReadForTest(request, 100, { ["ok": true] }, 100)
100102
XCTAssertEqual(secondBusy["error_code"] as? String, "bridge-read-in-flight")
101-
wait(for: [finished], timeout: 5)
103+
wait(for: [secondAbandoned], timeout: 5)
102104
secondRelease.signal()
103105
RunnerSnapshotBridgeDrainForTest()
104106
}

‎packages/platform-apple/src/snapshot-route.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { SnapshotSourceError } from './snapshot-source/errors.ts';
4141
import {
4242
createSystemSurfaceForegroundProbe,
4343
type SystemSurfaceForegroundProbe,
44+
type SystemSurfaceForegroundReading,
4445
} from './system-surface-foreground.ts';
4546
import {
4647
bridgeFailureDisposition,
@@ -208,7 +209,7 @@ function createSnapshotBridgeRouteCore<Target extends SnapshotBridgeRouteTarget>
208209
*/
209210
const circuitForProbe = (
210211
startingCircuit: typeof currentCircuit,
211-
probeResult: Awaited<ReturnType<SystemSurfaceForegroundProbe>>,
212+
probeResult: SystemSurfaceForegroundReading,
212213
device: DeviceInfo,
213214
): typeof currentCircuit => {
214215
const probedSessionId = channel.sessionChanged ? probeResult.sessionId : undefined;
@@ -451,7 +452,7 @@ async function readSurfaceForeground(
451452
input: CaptureSnapshotInput,
452453
signal: AbortSignal,
453454
probe: SystemSurfaceForegroundProbe,
454-
): Promise<Awaited<ReturnType<SystemSurfaceForegroundProbe>>> {
455+
): Promise<SystemSurfaceForegroundReading> {
455456
const requestId = input.execution?.requestId;
456457
const foreground = await probe(device, { signal, ...(requestId ? { requestId } : {}) });
457458
if (foreground.foreground === 'background') {

‎packages/platform-apple/src/system-surface-foreground.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ export type SystemSurfaceForeground =
2323
| 'background'
2424
| 'unknown';
2525

26+
/** One foreground read, with the runner session it was read through when that session is known. */
27+
export type SystemSurfaceForegroundReading = Readonly<{
28+
foreground: SystemSurfaceForeground;
29+
sessionId?: string;
30+
}>;
31+
2632
export type SystemSurfaceForegroundProbe = (
2733
device: DeviceInfo,
2834
input: Readonly<{ signal: AbortSignal; requestId?: string }>,
29-
) => Promise<Readonly<{ foreground: SystemSurfaceForeground; sessionId?: string }>>;
35+
) => Promise<SystemSurfaceForegroundReading>;
3036

3137
/**
3238
* Bounds each read below the read-only resend window, so a runner busy draining abandoned XCTest

0 commit comments

Comments
 (0)