Skip to content

Commit af69d17

Browse files
thymikeeclaude
andcommitted
fix(ios): keep the launch confirmation labels when a permission table is unreadable
The two reads are independent, so an unreadable permission table no longer discards Ouvrir and Annuler. The placeholder regex traps on a bad literal instead of silently disabling recognition. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent b5eddc6 commit af69d17

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAlertLabelVocabulary.swift‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ extension RunnerAlertLabelVocabulary {
4646
)
4747
}
4848

49-
/// Every permission table must read, or none counts: a missing table could hide the translation
50-
/// that makes a label in another table claim both actions. The launch confirmation's table only
51-
/// adds its own open and cancel labels (only those two keys are taken), so without it the permission vocabulary stays whole.
49+
/// Every permission table must read, or none of them counts: a missing table could hide the
50+
/// translation that makes a label in another table claim both actions. The launch confirmation's
51+
/// table is independent of them. Only its open and cancel labels are taken, so they stay when the
52+
/// permission read fails, and the permission vocabulary stays whole when that table is missing.
5253
static func composed(
5354
permission: Result<[RunnerSystemPromptStrings], RunnerSystemPromptStrings.UnavailableSource>,
5455
launchConfirmation: Result<[RunnerSystemPromptStrings], RunnerSystemPromptStrings.UnavailableSource>,
5556
languages: [String]
5657
) -> RunnerAlertLabelVocabulary {
57-
var tables: [RunnerSystemPromptStrings]
58+
var tables: [RunnerSystemPromptStrings] = []
5859
switch permission {
5960
case .failure(let failure):
6061
RunnerSystemPromptStrings.logUnavailable(failure, subsystem: "alert-vocabulary", languages: languages)
61-
return .english
6262
case .success(let read):
6363
tables = read
6464
}

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerLaunchConfirmationPrompt.swift‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ struct RunnerLaunchConfirmationPrompt {
1313

1414
static let unavailable = RunnerLaunchConfirmationPrompt(wordings: [])
1515

16-
private static let appNamePlaceholder = try? NSRegularExpression(pattern: "%(?:\\d+\\$)?(?:\\[[^\\]]*\\])?@")
16+
private static let appNamePlaceholder = try! NSRegularExpression(pattern: "%(?:\\d+\\$)?(?:\\[[^\\]]*\\])?@")
1717

1818
private let wordings: [(title: NSRegularExpression, open: String, cancel: String)]
1919

2020
/// A wording whose title format has no app-name placeholder is skipped, because its pattern would
2121
/// match a title with no app name. A placeholder is `%@`, a positional `%1$@`, or Apple's
2222
/// bracketed object format `%[tt]@`, as Finnish words it.
2323
init(wordings: [Wording]) {
24-
guard let placeholder = Self.appNamePlaceholder else {
25-
self.wordings = []
26-
return
27-
}
24+
let placeholder = Self.appNamePlaceholder
2825
self.wordings = wordings.compactMap { wording in
2926
let format = wording.titleFormat as NSString
3027
let slots = placeholder.matches(in: wording.titleFormat, range: NSRange(location: 0, length: format.length))

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,17 @@ extension RunnerTests {
158158
let noPermission = RunnerAlertLabelVocabulary.composed(
159159
permission: .failure(missing), launchConfirmation: .success([launch]), languages: ["fr"]
160160
)
161+
XCTAssertEqual(
162+
RunnerAlertButtonChoice.buttonIndex(for: ["Annuler", "Ouvrir"], action: "accept", vocabulary: noPermission),
163+
1,
164+
"the launch confirmation's labels survive an unreadable permission table"
165+
)
161166
XCTAssertNil(RunnerAlertButtonChoice.buttonIndex(for: ["Refuser", "Autoriser"], action: "dismiss", vocabulary: noPermission))
167+
168+
let neither = RunnerAlertLabelVocabulary.composed(
169+
permission: .failure(missing), launchConfirmation: .failure(missing), languages: ["fr"]
170+
)
171+
XCTAssertNil(RunnerAlertButtonChoice.buttonIndex(for: ["Annuler", "Ouvrir"], action: "accept", vocabulary: neither))
162172
}
163173

164174
/// An app alert can carry the exact wording and buttons, and `open` accepts a marked alert, so

0 commit comments

Comments
 (0)