Skip to content

Commit e8fcd97

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 5709698 commit e8fcd97

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
@@ -464,9 +464,18 @@ extension RunnerTests {
464464
}
465465
switch command.traits.launchPolicy {
466466
case .noApp:
467-
// A surface that is genuinely on screen is the screen this command would observe, so it is
468-
// served in place first, exactly as it is for the reads: bringing nothing forward is what makes
469-
// an observation honest, and it is not the same promise as ignoring what is presented (#2438).
467+
// The merge-base's prepared contract, which the policy axis dropped: a genuinely presented
468+
// surface is consulted first and served in place as the prepared target with that surface
469+
// disclosed, activating nothing and rebinding no session target (#2438). Both facts are
470+
// preparation-level and neither has a consumer for this class today — the same as at the
471+
// merge-base for every command it had: `status`, `uptime`, `recordStop`, `terminate`,
472+
// `targetReset` and `shutdown` answer before reading a target; iOS `screenshot` resolves its
473+
// own capture display on purpose (#2728) and macOS `screenshot` resolves the named app or the
474+
// full screen, so neither reads the prepared target either; off iOS the probe serves nothing
475+
// in place; and `snapshot` — the only provenance consumer — is `.existingApp` and keeps its
476+
// presented route in `prepareActivatedTarget`. `appState` is newer than the merge-base and
477+
// reads the named bundle's state itself. What the arm owns is the prepared subject and
478+
// disclosure, restored to the contract every following command was classified against.
470479
if let presented = presentedSystemSurfaceHost() {
471480
return .context(ActiveCommandContext(app: presented.app, systemSurface: presented.host))
472481
}
@@ -598,12 +607,14 @@ extension RunnerTests {
598607

599608
/// Whether a registered host is on screen. A registered host is an out-of-process service that only
600609
/// comes up because some app presented it, and `open` refuses to launch one, so no in-bundle test
601-
/// can make the system report one foreground; the named hosts answer that one question here and the
602-
/// registry order and the foreground condition above stay the production ones.
610+
/// can make the system report one foreground; the override answers that one question, and when it
611+
/// is set it is authoritative for every registered host — members are foreground, non-members are
612+
/// not — so a test pins the whole registry walk rather than the live state of what it left out.
613+
/// The registry order and the foreground condition above stay the production ones.
603614
private func systemSurfaceHostState(_ host: SystemSurfaceHost) -> XCUIApplication.State {
604615
#if AGENT_DEVICE_RUNNER_UNIT_TESTS
605-
if presentedSystemSurfaceForegroundOverrideForTesting?.contains(host.bundleId) == true {
606-
return .runningForeground
616+
if let override = presentedSystemSurfaceForegroundOverrideForTesting {
617+
return override.contains(host.bundleId) ? .runningForeground : .notRunning
607618
}
608619
#endif
609620
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
@@ -210,8 +210,9 @@ final class RunnerTests: XCTestCase {
210210
var alertButtonHittabilityProbeOverrideForTesting: ((Date) -> Bool)?
211211
// Unit-test-only seam for the in-place surface probe (`presentedSystemSurfaceHost`): a registered
212212
// host is an out-of-process XPC service that only comes up because some app presented it, and
213-
// `open` refuses to launch one, so the foreground answer for the named registered hosts is
214-
// supplied here. The probe's registry order and its `.runningForeground` condition stay the
213+
// `open` refuses to launch one, so the foreground answer for every registered host is supplied
214+
// here when set — members are foreground, non-members are not — which lets a test pin the whole
215+
// registry walk. The probe's registry order and its `.runningForeground` condition stay the
215216
// production ones. Production never compiles this property.
216217
var presentedSystemSurfaceForegroundOverrideForTesting: Set<String>?
217218
// 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
@@ -142,13 +142,17 @@ extension RunnerTests {
142142
}
143143

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

191195
// A second host reported instead of the first: an arm that returned the registry's first entry
192-
// rather than walking it would pass everything above and fail here.
196+
// rather than walking it would pass everything above and fail here. The total override makes the
197+
// first host's not-foreground answer pinned too, not merely observed.
193198
let secondHost = SystemSurfaceHostRegistry.hosts[1]
194199
presentedSystemSurfaceForegroundOverrideForTesting = [secondHost.bundleId]
195200
guard case .context(let other) = prepareActiveCommandContext(command: screenshot) else {
@@ -201,9 +206,22 @@ extension RunnerTests {
201206
"the probe must serve the host that is reported foreground, not the registry's first entry"
202207
)
203208

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

0 commit comments

Comments
 (0)