@ondeinference / xcrs-controlkit Mirror · read-only / commits / 63be8a7
Fork 0

Read-only mirror of github.com/ondeinference/xcrs-controlkit.

Mirrored from https://github.com/ondeinference/xcrs-controlkit.git

Synced Nov 24, 18:15 UTC

Fix a server-killing typeKey path and tighten app/type handling in the runner

typeKey ran against application(params), so typing a key into a stopped app recorded an XCTest failure. That failure ends the runner's only test case and takes the server down. Route it through runningApplication, the way the other interactions already do. A few smaller fixes in the same area: - screenshot's `named` flag counted an empty path or bundleId as naming an app, so `path: ""` screenshotted the app under test instead of erroring. Treat empty as absent, the way application(params) does. - The move-drag grab point could land on the traffic lights for windows narrower than about 140pt. Floor it at 100pt so it stays clear of them; normal windows are unchanged. - The type map used to narrow a tap left out several types device.dump.ui reports (group, scrollview, table, webview, and the rest), so narrowing by those failed with invalidParameter. In the parser, unquotedValue matched a ", value: " that sits inside a quoted title or label. It now scans past quoted attributes first, so a title like 'Total, value: n/a' is no longer read as a value. Added a test for that case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.6 <noreply@sigit.si>

Seto Elkahfi committed Nov 13, 2026 at 19:37 UTC 63be8a72fe29edccb0892cbe5d7ae679bcd3bad9
3 files changed +59 -4
Runners/Shared/ControlKitRPCServer.swift
+14 -3
@@ -392,6 +392,16 @@ final class ControlKitRPCServer {
392 "menubaritem": .menuBarItem,
393 "popupbutton": .popUpButton,
394 "tab": .tab,
395 + "group": .group,
396 + "scrollview": .scrollView,
397 + "table": .table,
398 + "webview": .webView,
399 + "progressindicator": .progressIndicator,
400 + "datepicker": .datePicker,
401 + "toolbar": .toolbar,
402 + "menu": .menu,
403 + "combobox": .comboBox,
404 + "window": .window,
405 "other": .other
406 ]
407
@@ -499,7 +509,8 @@ final class ControlKitRPCServer {
509 /// is named) or of the whole main screen (`target: "screen"`), base64-encoded.
510 /// Pixel sizes are read back from the PNG, so they include the display scale.
511 private func screenshot(_ params: [String: Any]) throws -> [String: Any] {
502 - let named = params["path"] != nil || params["bundleId"] != nil
512 + let named = !((params["path"] as? String) ?? "").isEmpty
513 + || !((params["bundleId"] as? String) ?? "").isEmpty
514 let target = (params["target"] as? String) ?? (named ? "window" : "screen")
515 let png: Data
516 switch target {
@@ -612,7 +623,7 @@ final class ControlKitRPCServer {
623 default: throw RunnerError.invalidParameter("modifiers")
624 }
625 }
615 - application(params).typeKey(key, modifierFlags: flags)
626 + try runningApplication(params).typeKey(key, modifierFlags: flags)
627 }
628
629 private static let namedKeys: [String: XCUIKeyboardKey] = [
@@ -653,7 +664,7 @@ final class ControlKitRPCServer {
664 let frame = window.frame
665 let grab = window
666 .coordinate(withNormalizedOffset: .zero)
656 - .withOffset(CGVector(dx: min(frame.width / 2, 160), dy: 8))
667 + .withOffset(CGVector(dx: min(max(frame.width / 2, 100), 160), dy: 8))
668 grab.press(forDuration: 0.2, thenDragTo: grab.withOffset(CGVector(
669 dx: x - frame.origin.x,
670 dy: y - frame.origin.y
Sources/XCRSControlKit/XCRSControlKit.swift
+24 -1
@@ -354,8 +354,31 @@ public enum XCRSControlKitAccessibilityParser {
354 /// `StaticText, 0x1, {{0.0, 0.0}, {10.0, 10.0}}, value: No file selected`.
355 /// It runs to the end of the line, less any trailing standalone flags.
356 private static func unquotedValue(in line: String) -> String? {
357 + // Find the separator outside any quoted attribute, so a `, value: ` that
358 + // sits inside a quoted `title`/`label`/`placeholderValue` is not mistaken
359 + // for the real value attribute.
360 + let separator = ", value: "
361 + var index = line.startIndex
362 + var quoted = false
363 + var valueStart: String.Index?
364 + while index < line.endIndex {
365 + let character = line[index]
366 + if character == "'" {
367 + if quoted {
368 + if isClosingQuote(at: index, in: line) {
369 + quoted = false
370 + }
371 + } else {
372 + quoted = true
373 + }
374 + } else if character == ",", !quoted, line[index...].hasPrefix(separator) {
375 + valueStart = line.index(index, offsetBy: separator.count)
376 + break
377 + }
378 + index = line.index(after: index)
379 + }
380 guard
358 - let valueStart = line.range(of: ", value: ")?.upperBound,
381 + let valueStart,
382 line[valueStart...].first != "'"
383 else {
384 return nil
Tests/XCRSControlKitTests/XCRSControlKitTests.swift
+21
@@ -192,6 +192,27 @@ final class XCRSControlKitTests: XCTestCase {
192 XCTAssertEqual(children[4].label, "Close", "an explicit label wins over title")
193 }
194
195 + func testAccessibilityParserIgnoresValueSeparatorInsideQuotedTitle() throws {
196 + let hierarchy = """
197 + Element subtree:
198 + →Application, 0x1, pid: 1
199 + Window (Main), 0x2, {{0.0, 0.0}, {10.0, 10.0}}
200 + StaticText, 0x3, {{0.0, 0.0}, {1.0, 1.0}}, title: 'Total, value: n/a'
201 + StaticText, 0x4, {{0.0, 0.0}, {1.0, 1.0}}, title: 'Volume', value: 50%
202 + Path to element:
203 + """
204 +
205 + let root = try XCRSControlKitAccessibilityParser.parse(
206 + debugDescription: hierarchy
207 + )
208 + let window = try XCTUnwrap(root.children.first)
209 + let children = window.children
210 + XCTAssertEqual(children[0].label, "Total, value: n/a")
211 + XCTAssertNil(children[0].value, "a `, value: ` inside a quoted title is not a value attribute")
212 + XCTAssertEqual(children[1].label, "Volume")
213 + XCTAssertEqual(children[1].value, "50%", "a real unquoted value outside quotes is still read")
214 + }
215 +
216 func testAccessibilityParserRejectsMultipleRootElements() {
217 let hierarchy = """
218 Element subtree: