Skip to content

Commit 5709698

Browse files
committed
chore(gates): pin witness clearing for every command in the trait table
Whether the prepared path drops a remembered text-entry tap was argued from the retired read-only fact rather than asserted. The table now carries that column for every command, compared against the merge-base predicate plus a literal copy of its read-only set, so neither replay eligibility nor witness clearing can move with the classification under test. The commands `executeOnMain` answers before `executeOnMainPrepared` runs are compared nowhere: the old predicate never evaluated for them and neither does the derived one. `snapshot` stays in scope because it reaches that body, and `appState` postdates the merge-base and owes it no equality. Adding the `querySelector` bundle id to the witness-owner set — the change the review asked for — turns that row red.
1 parent bd0d2b3 commit 5709698

1 file changed

Lines changed: 65 additions & 1 deletion

File tree

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

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,55 @@ extension RunnerTests {
188188
)
189189
}
190190

191+
/// The commands the merge-base classified read-only, copied from its `CommandType.traits`
192+
/// (`git show 6428c54853:…/RunnerTests+Models.swift`) rather than read from anything under test:
193+
/// `readOnly: .always`, plus `alert`'s `get` action, which its `.conditional` case resolved to the
194+
/// same answer. Both consumers that fact had — replay eligibility and the prepared path's witness
195+
/// rule — are pinned against this literal below, so neither can move with the table (#2890 review).
196+
private static let mergeBaseReadOnlyCommands: Set<CommandType> = [
197+
.findText, .readText, .snapshot, .gestureViewport, .screenshot, .status, .alert,
198+
]
199+
200+
/// Commands that did not exist at the merge-base, so no classification of its is compared with
201+
/// theirs. `appState` arrived with #2929.
202+
private static let commandsNewerThanTheMergeBase: Set<CommandType> = [.appState]
203+
204+
/// The commands production never runs through the prepared path's body: `executeOnMain` answers
205+
/// these before `executeOnMainPrepared` runs, and `executeDispatched` answers `snapshot` earlier
206+
/// still, on both this and the merge-base chain. The merge-base witness predicate was therefore
207+
/// never evaluated for them and neither is the derived one. If a command starts reaching the
208+
/// prepared path, removing it here is a claim the equivalence assertion below has to keep proving.
209+
private static let commandsAnsweredBeforeThePreparedPath: Set<CommandType> = [
210+
.status, .uptime, .appState, .activate, .terminate, .targetReset, .shutdown,
211+
.recordStart, .recordStop, .snapshot,
212+
]
213+
214+
private func assertRememberedTextEntryWitnessInvalidation(
215+
_ command: Command,
216+
type: CommandType,
217+
wasReadOnlyAtMergeBase: Bool,
218+
_ request: String
219+
) {
220+
if !Self.commandsNewerThanTheMergeBase.contains(type) {
221+
XCTAssertEqual(
222+
command.traits.retryOnSessionLoss,
223+
wasReadOnlyAtMergeBase,
224+
"\(request) must stay replayable exactly where the merge-base classified it read-only"
225+
)
226+
}
227+
// The merge-base rule (`RunnerTests+CommandExecution.swift:11`):
228+
// `command != .tap && command != .type && !isReadOnlyCommand(command)`. `querySelector` is the
229+
// row this review round was about: it was never read-only, so the merge-base cleared a
230+
// remembered tap for it too and this column says so for every command, not just that one.
231+
let mergeBaseClears = type != .tap && type != .type && !wasReadOnlyAtMergeBase
232+
guard !Self.commandsAnsweredBeforeThePreparedPath.contains(type) else { return }
233+
XCTAssertEqual(
234+
command.invalidatesRememberedTextEntryTap,
235+
mergeBaseClears,
236+
"\(request) must invalidate a remembered text-entry tap exactly as the merge-base did"
237+
)
238+
}
239+
191240
/// Every decision the runner makes from a classification, asserted for every command from one
192241
/// table. `retry` is replay eligibility and `launch` is what the runner may do about a stopped
193242
/// app: `querySelector` is the row that proves one does not set the other (#2890). Each row names
@@ -247,6 +296,12 @@ extension RunnerTests {
247296
let command = try runnerCommandFixture(request)
248297
XCTAssertEqual(command.command, type, request)
249298
assertTraits(command.traits, matches: rowExpectation, request)
299+
assertRememberedTextEntryWitnessInvalidation(
300+
command,
301+
type: type,
302+
wasReadOnlyAtMergeBase: Self.mergeBaseReadOnlyCommands.contains(type),
303+
request
304+
)
250305
}
251306
XCTAssertEqual(
252307
Set(table.map { $0.0 }),
@@ -271,7 +326,16 @@ extension RunnerTests {
271326
for alertCase in alertCases {
272327
let request = alertCase.action.map { #"{"command":"alert","action":"\#($0)"}"# }
273328
?? #"{"command":"alert"}"#
274-
assertTraits(try runnerCommandFixture(request).traits, matches: alertCase.expectation, request)
329+
let command = try runnerCommandFixture(request)
330+
assertTraits(command.traits, matches: alertCase.expectation, request)
331+
// The merge-base resolved `alert` through `readOnly: .conditional`, whose rule was this same
332+
// action test, so only `get` — and the missing action it defaults to — was read-only there.
333+
assertRememberedTextEntryWitnessInvalidation(
334+
command,
335+
type: .alert,
336+
wasReadOnlyAtMergeBase: (command.action ?? "get").lowercased() == "get",
337+
request
338+
)
275339
}
276340
}
277341
}

0 commit comments

Comments
 (0)