Skip to content

Commit bc9c486

Browse files
thymikeeclaude
andauthored
test(ios): answer the panel fixture's label through KVC (#4320)
* test(ios): answer the panel fixture's label through KVC A selector predicate reads label through KVC, and KVC caches the accessor it resolved. After an earlier test evaluated label on an XCUIElement, the fixture's fall-through called XCTest's getter instead of the stub, which resolved the fixture app's absent button. The full nightly suite reached that order; isolated runs did not. Fixes #4262 Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(ios): send label to the installed getter from the panel fixture's KVC The lit-panel probe swaps valueForKey: in every mode but swaps the label getter only when composed, so an uncomposed probe answered KVC label with the stub constant for real elements. Sending label reaches whichever getter is installed: the stub when composed, XCTest's otherwise, and never KVC's cached accessor. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 939102d commit bc9c486

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerRequestPanelTests.swift‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ private final class LitPanelBookingProbe: NSObject {
8282
case "screen": return LitPanelBookingScreen(self === Self.darkWindow ? 1 : Self.windowDisplayID)
8383
case "exists": return true
8484
case "frame": return NSValue(cgRect: Self.elementFrame(self))
85+
// A selector predicate reads `label` through KVC, and KVC caches the accessor it resolved:
86+
// once an earlier test evaluated `label` on an XCUIElement, the original lookup calls
87+
// XCTest's getter even while the composed probe swaps it. Sending `label` reaches the getter
88+
// installed now. XCUIElement inherits NSObject's `valueForKey:`, so this IMP serves every
89+
// object, and only an element answers `label`.
90+
case "label" where isKind(of: XCUIElement.self): return unsafeBitCast(self, to: XCUIElement.self).label
8591
default: break
8692
}
8793
return original(self, #selector(NSObject.value(forKey:)), key as NSString)
@@ -380,6 +386,14 @@ extension RunnerTests {
380386
}
381387
}
382388

389+
@MainActor
390+
func testUncomposedLitPanelProbeLeavesKVCLabelReadsToXCTest() throws {
391+
try withLitPanelBookingProbe { _ in
392+
let title = app.staticTexts.firstMatch
393+
XCTAssertEqual(title.value(forKey: "label") as? String, "Agent Device Runner")
394+
}
395+
}
396+
383397
@MainActor
384398
func testCollapsedTabCandidatesExcludeOverlappingDarkWindowsAndKeepTheCaptureScope() throws {
385399
try withLitPanelBookingProbe { window in

0 commit comments

Comments
 (0)