Skip to content

Commit 099778f

Browse files
committed
test(ios-runner): make the presented-surface override answer every registered host
The override for `systemSurfaceHostState` only forced the hosts a test named, so every other registered host still answered from live simulator state: a registry walk could not be pinned end to end, and a new registry entry made the test's answer depend on the machine again. The override is now total while set — members report foreground, non-members do not. Production is unaffected: the seam is compiled only under the unit-test flag. This is hardening, not a mutation-proofed fix. Mutating the override back to the member-only form stays green on a simulator, because the two registered hosts already report notRunning there — which is the very reason the seam exists. Also write down what the `.noApp` presented arm actually controls. Tracing the first parent of c7b79ee: no `.noApp` command read the prepared target or the disclosed surface even pre-split (`status`/`uptime`/`recordStop`/`terminate`/ `targetReset`/`shutdown` answer before reading a target, iOS `screenshot` re-resolves its capture display (#2728), macOS `screenshot` resolves the named app, and `snapshot` — the only provenance consumer — is `.existingApp` and keeps its route in `prepareActivatedTarget`). The arm restores the prepared subject and disclosure, which is what the merge-base chain gave these commands; the test says so instead of claiming a payload the runner never stamped.
1 parent 09a172b commit 099778f

4 files changed

Lines changed: 57 additions & 25 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandDispatch.swift‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,18 @@ extension RunnerTests {
468468
}
469469
switch command.traits.launchPolicy {
470470
case .noApp:
471-
// A surface that is genuinely on screen is the screen this command would observe, so it is
472-
// served in place first, exactly as it is for the reads: bringing nothing forward is what makes
473-
// an observation honest, and it is not the same promise as ignoring what is presented (#2438).
471+
// The merge-base's prepared contract, which the policy axis dropped: a genuinely presented
472+
// surface is consulted first and served in place as the prepared target with that surface
473+
// disclosed, activating nothing and rebinding no session target (#2438). Both facts are
474+
// preparation-level and neither has a consumer for this class today — the same as at the
475+
// merge-base for every command it had: `status`, `uptime`, `recordStop`, `terminate`,
476+
// `targetReset` and `shutdown` answer before reading a target; iOS `screenshot` resolves its
477+
// own capture display on purpose (#2728) and macOS `screenshot` resolves the named app or the
478+
// full screen, so neither reads the prepared target either; off iOS the probe serves nothing
479+
// in place; and `snapshot` — the only provenance consumer — is `.existingApp` and keeps its
480+
// presented route in `prepareActivatedTarget`. `appState` is newer than the merge-base and
481+
// reads the named bundle's state itself. What the arm owns is the prepared subject and
482+
// disclosure, restored to the contract every following command was classified against.
474483
if let presented = presentedSystemSurfaceHost() {
475484
return .context(ActiveCommandContext(app: presented.app, systemSurface: presented.host))
476485
}
@@ -603,12 +612,14 @@ extension RunnerTests {
603612

604613
/// Whether a registered host is on screen. A registered host is an out-of-process service that only
605614
/// comes up because some app presented it, and `open` refuses to launch one, so no in-bundle test
606-
/// can make the system report one foreground; the named hosts answer that one question here and the
607-
/// registry order and the foreground condition above stay the production ones.
615+
/// can make the system report one foreground; the override answers that one question, and when it
616+
/// is set it is authoritative for every registered host — members are foreground, non-members are
617+
/// not — so a test pins the whole registry walk rather than the live state of what it left out.
618+
/// The registry order and the foreground condition above stay the production ones.
608619
private func systemSurfaceHostState(_ host: SystemSurfaceHost) -> XCUIApplication.State {
609620
#if AGENT_DEVICE_RUNNER_UNIT_TESTS
610-
if presentedSystemSurfaceForegroundOverrideForTesting?.contains(host.bundleId) == true {
611-
return .runningForeground
621+
if let override = presentedSystemSurfaceForegroundOverrideForTesting {
622+
return override.contains(host.bundleId) ? .runningForeground : .notRunning
612623
}
613624
#endif
614625
return XCUIApplication(bundleIdentifier: host.bundleId).state

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ enum CommandType: String, Codable, CaseIterable {
4646
enum CommandLaunchPolicy: Equatable {
4747
/// Preparation brings no app forward and binds no target: the command answers from the runner's own
4848
/// capture and state, or drives the runner's own lifecycle, so it is served the standing cached
49-
/// target. A surface that is genuinely presented is served in place instead, because that is the
50-
/// screen the command observes (#2438). Scoped to preparation: a command body may still go to the
51-
/// app it names, as macOS `screenshot` does.
49+
/// target. A surface that is genuinely presented is served in place instead, which is the prepared
50+
/// contract those commands had before the launch-policy axis (#2438); no command in this class
51+
/// consumes the prepared target or the disclosed surface today, and the arm that says so names
52+
/// where each command's answer actually comes from. Scoped to preparation either way: a command
53+
/// body may still go to the app it names, as macOS `screenshot` does.
5254
case noApp
5355
/// Answers from the surface that already has focus, where activating an app would cancel exactly
5456
/// what the command is about: an in-place system surface, or a press that belongs to the system.

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ final class RunnerTests: XCTestCase {
204204
var alertButtonHittabilityProbeOverrideForTesting: (@MainActor (Date) -> Bool)?
205205
// Unit-test-only seam for the in-place surface probe (`presentedSystemSurfaceHost`): a registered
206206
// host is an out-of-process XPC service that only comes up because some app presented it, and
207-
// `open` refuses to launch one, so the foreground answer for the named registered hosts is
208-
// supplied here. The probe's registry order and its `.runningForeground` condition stay the
207+
// `open` refuses to launch one, so the foreground answer for every registered host is supplied
208+
// here when set — members are foreground, non-members are not — which lets a test pin the whole
209+
// registry walk. The probe's registry order and its `.runningForeground` condition stay the
209210
// production ones. Production never compiles this property.
210211
var presentedSystemSurfaceForegroundOverrideForTesting: Set<String>?
211212
// Runs on the waiting thread after `runMainThreadWork`'s wait timed out and before it takes the

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

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,17 @@ extension RunnerTests {
144144
}
145145

146146
/// `.noApp` owes both of the merge-base's answers: a registered host presented over the session is
147-
/// served in place (#2438), and with nothing presented the standing cached target is served rather
148-
/// than a target resolved from the request. The policy axis dropped both. The request names a bundle
149-
/// the session never bound because that is the only shape separating the two targets — when the
150-
/// request agrees with the cache, both answers name the same app. The seam is the host's foreground
151-
/// state alone: the probe's registry walk and foreground condition stay the production ones, and the
152-
/// `snapshot`/`querySelector` route that consumes this preparation is pinned live by the replay
153-
/// layers, which need a host something actually presented.
147+
/// served in place with its surface disclosed (#2438), and with nothing presented the standing cached
148+
/// target is served rather than a target resolved from the request. The policy axis dropped both.
149+
/// The request names a bundle the session never bound because that is the only shape separating the
150+
/// two targets — when the request agrees with the cache, both answers name the same app. The seam is
151+
/// the hosts' foreground state alone and it is authoritative while set, so every registered host's
152+
/// answer is pinned here and none is read from live state; the probe's registry walk and foreground
153+
/// condition stay the production ones. This pins preparation, which is the whole contract for this
154+
/// class: no `.noApp` command body reads the prepared target or the disclosure, on this chain or at
155+
/// the merge-base, so the arm that says so in `prepareActiveCommandContext` is the consumer of
156+
/// record. Deleting the presented arm fails the first block, and resolving the target from the
157+
/// request instead of the cache fails the last.
154158
@MainActor
155159
func testNoAppCommandStillServesAPresentedSurfaceInPlaceAndOtherwiseTheStandingTarget() throws {
156160
let cachedBundleId = "com.example.session"
@@ -174,11 +178,11 @@ extension RunnerTests {
174178
XCTAssertEqual(
175179
presented.systemSurface,
176180
host,
177-
"a capture taken under a presented surface must carry that surface's provenance (#2438)"
181+
"a capture prepared under a presented surface must name that surface as its prepared subject (#2438)"
178182
)
179183
XCTAssertFalse(
180184
presented.app === app,
181-
"the capture target is the presented host, not the standing session target"
185+
"the prepared subject is the presented host, not the standing session target"
182186
)
183187
XCTAssertFalse(
184188
presented.app === springboard,
@@ -192,7 +196,8 @@ extension RunnerTests {
192196
)
193197

194198
// A second host reported instead of the first: an arm that returned the registry's first entry
195-
// rather than walking it would pass everything above and fail here.
199+
// rather than walking it would pass everything above and fail here. The total override makes the
200+
// first host's not-foreground answer pinned too, not merely observed.
196201
let secondHost = SystemSurfaceHostRegistry.hosts[1]
197202
presentedSystemSurfaceForegroundOverrideForTesting = [secondHost.bundleId]
198203
guard case .context(let other) = prepareActiveCommandContext(command: screenshot) else {
@@ -204,9 +209,22 @@ extension RunnerTests {
204209
"the probe must serve the host that is reported foreground, not the registry's first entry"
205210
)
206211

207-
// The other half, with nothing presented. Without this the arm could pass by serving a surface
208-
// that is not there.
209-
presentedSystemSurfaceForegroundOverrideForTesting = nil
212+
// Both reported: the registry's own order decides, because live state cannot be told to present
213+
// two hosts at once. Totality is what keeps the block's answer free of what the sim happens to
214+
// report for any host a future registry entry adds.
215+
presentedSystemSurfaceForegroundOverrideForTesting = [host.bundleId, secondHost.bundleId]
216+
guard case .context(let both) = prepareActiveCommandContext(command: screenshot) else {
217+
return XCTFail("screenshot must be prepared, not refused")
218+
}
219+
XCTAssertEqual(
220+
both.systemSurface,
221+
host,
222+
"with every host foreground the probe must serve them in registry order"
223+
)
224+
225+
// The other half, with nothing presented — an empty total override, so this half pins the
226+
// hosts' answers too. Without this the arm could pass by serving a surface that is not there.
227+
presentedSystemSurfaceForegroundOverrideForTesting = []
210228
guard case .context(let standing) = prepareActiveCommandContext(command: screenshot) else {
211229
return XCTFail("screenshot must be prepared, not refused")
212230
}

0 commit comments

Comments
 (0)