Skip to content

Commit 849905f

Browse files
thymikeeclaude
andcommitted
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]>
1 parent 3220eee commit 849905f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ private final class LitPanelBookingProbe: NSObject {
8484
case "frame": return NSValue(cgRect: Self.elementFrame(self))
8585
// A selector predicate reads `label` through KVC, and KVC caches the accessor it resolved:
8686
// once an earlier test evaluated `label` on an XCUIElement, the original lookup calls
87-
// XCTest's getter, not the stub, and resolves the fixture's button query.
88-
case "label" where isKind(of: XCUIElement.self): return label
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
8991
default: break
9092
}
9193
return original(self, #selector(NSObject.value(forKey:)), key as NSString)
@@ -384,6 +386,14 @@ extension RunnerTests {
384386
}
385387
}
386388

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+
387397
@MainActor
388398
func testCollapsedTabCandidatesExcludeOverlappingDarkWindowsAndKeepTheCaptureScope() throws {
389399
try withLitPanelBookingProbe { window in

0 commit comments

Comments
 (0)