From 5f65989eb0b73b47c4e89253312fc3d55c3b8274 Mon Sep 17 00:00:00 2001 From: sudoHG Date: Mon, 16 Nov 2026 10:01:26 +0800 Subject: [PATCH 1/3] Use the maintainer's wording for the approval card footer and drop the Esc hint The approval panel's footer now shows only its sentence, in the maintainer's wording (#356): "This request will be sent to iPhone in 18 s" while an eligible request waits for its send, and "This request expires in 4:59" otherwise, including after the send. When each form applies, and the countdown, do not change. The footer has its own catalog keys; "Expires in %@", shared with the pending-request list and the pairing sheet, is untouched, and the keys left unused are removed. "Esc to decide later" is gone from the panel. Esc still decides later: the panel is now an AgentApprovalPanel, which takes Esc in sendEvent(_:), where AppKit delivers every key event to the window whichever view is first responder, and hands it to the card's decide-later path. A cancel sent up the responder chain (Command-period) does the same. VoiceOver keeps a way to decide later through a "Decide Later" action on the footer, in both languages. Tests cover the strings in both languages, Esc in the production panel with either first responder, and the footer's VoiceOver action. Renders 17-19 show the new footer; ADR 0014's footer strings and the Why that no longer fit are updated. --- .../AgentApprovalPanelFactory.swift | 30 +++- .../App/AppDelegate+Approval.swift | 3 + .../App/FrozenAgentApprovalPrompt.swift | 34 +--- .../App/RemoteApprovalPanelState.swift | 37 ++-- .../Resources/Localizable.xcstrings | 24 +-- .../ApprovalPromptContentTests.swift | 5 +- .../RemoteApprovalFooterHintTests.swift | 6 +- .../RemoteApprovalFooterTests.swift | 165 ++++++++++++++---- .../RemoteApprovalRenderTests.swift | 19 +- Tests/AskKeyE2ETests/ScreenshotE2ETests.swift | 9 +- docs/adr/0014-remote-approval.md | 8 +- 11 files changed, 225 insertions(+), 115 deletions(-) diff --git a/Sources/AskKeyAppKit/AgentApprovalPanelFactory.swift b/Sources/AskKeyAppKit/AgentApprovalPanelFactory.swift index 0a884451..e8dee99e 100644 --- a/Sources/AskKeyAppKit/AgentApprovalPanelFactory.swift +++ b/Sources/AskKeyAppKit/AgentApprovalPanelFactory.swift @@ -1,9 +1,35 @@ import AppKit +/// The approval panel's window. Esc decides later with no control on the +/// card (#356): every key event AppKit delivers to the panel passes through +/// `sendEvent(_:)`, whichever view is first responder, so the panel takes +/// Esc there and hands it to `cancel`. Command-period and any other cancel +/// sent up the responder chain end in `cancelOperation(_:)` and do the same. +final class AgentApprovalPanel: NSPanel { + var cancel: (@MainActor () -> Void)? + + override func sendEvent(_ event: NSEvent) { + if let cancel, Self.isEscape(event) { return cancel() } + super.sendEvent(event) + } + + override func cancelOperation(_ sender: Any?) { + guard let cancel else { return super.cancelOperation(sender) } + cancel() + } + + /// Esc without Command, Control, Option or Shift, as the card's former + /// `.cancelAction` shortcut matched it. + static func isEscape(_ event: NSEvent) -> Bool { + event.type == .keyDown && event.keyCode == 53 // kVK_Escape + && event.modifierFlags.intersection([.command, .control, .option, .shift]).isEmpty + } +} + @MainActor enum AgentApprovalPanelFactory { - static func make(contentSize: NSSize) -> NSPanel { - let panel = NSPanel( + static func make(contentSize: NSSize) -> AgentApprovalPanel { + let panel = AgentApprovalPanel( contentRect: NSRect(origin: .zero, size: contentSize), // Non-activating: the panel takes keyboard focus without bringing // Ask Key, and any open management window, to the front. diff --git a/Sources/AskKeyAppKit/App/AppDelegate+Approval.swift b/Sources/AskKeyAppKit/App/AppDelegate+Approval.swift index f0741795..8f170c97 100644 --- a/Sources/AskKeyAppKit/App/AppDelegate+Approval.swift +++ b/Sources/AskKeyAppKit/App/AppDelegate+Approval.swift @@ -377,6 +377,9 @@ extension AppDelegate { let hosting = NSHostingController(rootView: AgentApprovalPanelContent(prompt: prompt, layout: layout)) hosting.sizingOptions = [.preferredContentSize] panel.contentViewController = hosting + // Esc decides later (#356). The panel reaches the card through its + // content, so it never keeps the card's decision closure alive. + panel.cancel = { [weak hosting] in hosting?.rootView.prompt.finish(nil) } layout.start() return panel } diff --git a/Sources/AskKeyAppKit/App/FrozenAgentApprovalPrompt.swift b/Sources/AskKeyAppKit/App/FrozenAgentApprovalPrompt.swift index a4524470..b06b046a 100644 --- a/Sources/AskKeyAppKit/App/FrozenAgentApprovalPrompt.swift +++ b/Sources/AskKeyAppKit/App/FrozenAgentApprovalPrompt.swift @@ -280,37 +280,21 @@ struct FrozenAgentApprovalPrompt: View { /// One moving number at a time: the send countdown while the request /// waits for a paired iPhone, otherwise the expiry (ADR 0014 → Mac App). - /// A footer too long for one line, as the English "Also on iPhone" form - /// is, puts the text and "Esc to decide later" on a line each, so - /// neither breaks. VoiceOver reads it as one sentence and decides later - /// when it is activated; mouse and Esc work as before. + /// The footer shows only that sentence (#356); Esc decides later through + /// the panel (`AgentApprovalPanel`), and VoiceOver offers it as a named + /// action on the footer. A sentence too long for one line wraps. private var footer: some View { let hint = remote?.footer return TimelineView(RemoteApprovalFooterSchedule(anchor: RemoteApprovalFooter.anchor(hint, expiresAt: expiresAt))) { context in let text = RemoteApprovalFooter.text(hint, expiresAt: expiresAt, now: context.date) - ViewThatFits(in: .horizontal) { - HStack(spacing: Theme.Spacing.xs) { - Text(text).monospacedDigit() - Text(verbatim: "·") - decideLaterButton - } - VStack(spacing: Theme.Spacing.xs) { - Text(text).monospacedDigit() - decideLaterButton - } - } - .accessibilityElement(children: .ignore) - .accessibilityLabel(Text(verbatim: RemoteApprovalFooter.sentence(text))) - .accessibilityAddTraits(.isButton) - .accessibilityAction { finish(nil) } + Text(verbatim: text) + .monospacedDigit() + .multilineTextAlignment(.center) + .fixedSize(horizontal: false, vertical: true) + .accessibilityAction(named: Text(verbatim: RemoteApprovalFooter.decideLaterAction)) { finish(nil) } + .accessibilityIdentifier("approval-footer") } .font(Theme.Fonts.caption) .foregroundStyle(Theme.textTertiary) } - - private var decideLaterButton: some View { - Button(appLocalized("Esc to decide later")) { finish(nil) } - .buttonStyle(.plain) - .keyboardShortcut(.cancelAction) - } } diff --git a/Sources/AskKeyAppKit/App/RemoteApprovalPanelState.swift b/Sources/AskKeyAppKit/App/RemoteApprovalPanelState.swift index ad937492..efa608d6 100644 --- a/Sources/AskKeyAppKit/App/RemoteApprovalPanelState.swift +++ b/Sources/AskKeyAppKit/App/RemoteApprovalPanelState.swift @@ -3,7 +3,7 @@ import Observation import SwiftUI /// What the approval panel's footer says about the approvers (ADR 0014 → -/// Mac App, amended by #345). Without a hint the footer is unchanged. +/// Mac App, amended by #345). Without a hint the footer shows the expiry. enum RemoteApprovalFooterHint: Equatable { /// An eligible request waits for its 20-second send to an approver with /// room under its limit. @@ -12,36 +12,29 @@ enum RemoteApprovalFooterHint: Equatable { case sent } -/// The footer's text before "Esc to decide later": one moving number at a -/// time (#344, decision 6). The send countdown takes the expiry's place -/// while the request waits; the expiry returns once a copy was saved. +/// The footer's text: one moving number at a time, in the maintainer's +/// wording (#356, replacing #344 decision 6's). The send countdown takes the +/// expiry's place while the request waits; the expiry returns once the +/// send is due, worded the same whether or not a copy was saved. enum RemoteApprovalFooter { static func text(_ hint: RemoteApprovalFooterHint?, expiresAt: Date?, now: Date) -> String { - let expiry = FrozenCountdown.format(deadline: expiresAt, now: now) - switch hint { - case .waiting(let sendAt): - guard let seconds = secondsUntilSend(sendAt, now: now) else { break } + if case .waiting(let sendAt) = hint, let seconds = secondsUntilSend(sendAt, now: now) { // "s" inflects in neither catalog language; the count still goes // through the plural lookup, so a language that inflects can add // plural variations to this key. - return AppLanguage.localizedCount("iPhone can decide in %lld s", oneKey: "iPhone can decide in %lld s", + return AppLanguage.localizedCount("This request will be sent to iPhone in %lld s", + oneKey: "This request will be sent to iPhone in %lld s", count: seconds, language: AppLanguage.current) - case .sent: - return appLocalizedFormat("Also on iPhone · Expires in %@", expiry) - case nil: - break } - return appLocalizedFormat("Expires in %@", expiry) + return appLocalizedFormat("This request expires in %@", FrozenCountdown.format(deadline: expiresAt, now: now)) } - /// The whole footer as one sentence, for VoiceOver: the text, then - /// "Esc to decide later". - static func sentence(_ text: String) -> String { - text + " · " + appLocalized("Esc to decide later") - } + /// The name of the footer's VoiceOver action, which decides later as + /// Esc does. + static var decideLaterAction: String { appLocalized("Decide Later") } /// Whole seconds left before the send, rounded up, from 20 to 1; nil - /// once the send is due, when the footer is unchanged until it is saved. + /// once the send is due, when the footer shows the expiry. static func secondsUntilSend(_ sendAt: Date, now: Date) -> Int? { let remaining = sendAt.timeIntervalSince(now) guard remaining > 0 else { return nil } @@ -111,8 +104,8 @@ final class RemoteApprovalPanelState { } /// Records the coordinator's latest decision when it decided this request. - /// The footer's hint goes with it, so "Also on iPhone" never shows next - /// to the approver's decision. + /// The footer's hint goes with it, so a hint about the approvers never + /// shows next to the approver's decision. func record(_ decision: RemoteAppliedDecision?, now: Date) { guard outcome == nil, let decision, decision.requestID == requestID else { return } outcome = decision diff --git a/Sources/AskKeyAppKit/Resources/Localizable.xcstrings b/Sources/AskKeyAppKit/Resources/Localizable.xcstrings index 35659c66..dfe0cb3f 100644 --- a/Sources/AskKeyAppKit/Resources/Localizable.xcstrings +++ b/Sources/AskKeyAppKit/Resources/Localizable.xcstrings @@ -715,12 +715,12 @@ "qps-ploc": { "stringUnit": { "state": "translated", "value": "[!!Create!!]" } } } }, - "Esc to decide later": { + "Decide Later": { "extractionState": "manual", "localizations": { - "en": { "stringUnit": { "state": "translated", "value": "Esc to decide later" } }, - "zh-Hans": { "stringUnit": { "state": "translated", "value": "Esc 稍后处理" } }, - "qps-ploc": { "stringUnit": { "state": "translated", "value": "[!!Esc to decide later!!]" } } + "en": { "stringUnit": { "state": "translated", "value": "Decide Later" } }, + "zh-Hans": { "stringUnit": { "state": "translated", "value": "稍后处理" } }, + "qps-ploc": { "stringUnit": { "state": "translated", "value": "[!!Decide Later!!]" } } } }, "Hands over": { @@ -16041,48 +16041,48 @@ } } }, - "iPhone can decide in %lld s": { + "This request will be sent to iPhone in %lld s": { "extractionState": "manual", "localizations": { "en": { "stringUnit": { "state": "translated", - "value": "iPhone can decide in %lld s" + "value": "This request will be sent to iPhone in %lld s" } }, "zh-Hans": { "stringUnit": { "state": "translated", - "value": "%lld 秒后 iPhone 也能处理" + "value": "%lld 秒后将把审批请求发到 iPhone" } }, "qps-ploc": { "stringUnit": { "state": "translated", - "value": "[!!iPhone can decide in %lld s!!]" + "value": "[!!This request will be sent to iPhone in %lld s!!]" } } } }, - "Also on iPhone · Expires in %@": { + "This request expires in %@": { "extractionState": "manual", "localizations": { "en": { "stringUnit": { "state": "translated", - "value": "Also on iPhone · Expires in %@" + "value": "This request expires in %@" } }, "zh-Hans": { "stringUnit": { "state": "translated", - "value": "iPhone 也能处理 · %@ 后失效" + "value": "审批请求将于 %@ 后失效" } }, "qps-ploc": { "stringUnit": { "state": "translated", - "value": "[!!Also on iPhone · Expires in %@!!]" + "value": "[!!This request expires in %@!!]" } } } diff --git a/Tests/AskKeyAppTests/ApprovalPromptContentTests.swift b/Tests/AskKeyAppTests/ApprovalPromptContentTests.swift index 9d246625..0523aeeb 100644 --- a/Tests/AskKeyAppTests/ApprovalPromptContentTests.swift +++ b/Tests/AskKeyAppTests/ApprovalPromptContentTests.swift @@ -153,8 +153,9 @@ final class ApprovalPromptContentTests: AskKeyAppTestCase { func testFooterInBothLanguages() { Fixtures.withLanguages { language in - let footer = appLocalizedFormat("Expires in %@", "4:11") + " · " + appLocalized("Esc to decide later") - XCTAssertEqual(footer, language == "en" ? "Expires in 4:11 · Esc to decide later" : "4:11 后失效 · Esc 稍后处理") // i18n-literal: Chinese footer. + let now = Date(timeIntervalSince1970: 2_000_000_000) + let footer = RemoteApprovalFooter.text(nil, expiresAt: now.addingTimeInterval(251), now: now) + XCTAssertEqual(footer, language == "en" ? "This request expires in 4:11" : "审批请求将于 4:11 后失效") // i18n-literal: Chinese footer. XCTAssertEqual(appLocalized("Details"), language == "en" ? "Details" : "详细信息") // i18n-literal: Chinese Details link. } } diff --git a/Tests/AskKeyAppTests/RemoteApprovalFooterHintTests.swift b/Tests/AskKeyAppTests/RemoteApprovalFooterHintTests.swift index 2b70e84c..83401cc5 100644 --- a/Tests/AskKeyAppTests/RemoteApprovalFooterHintTests.swift +++ b/Tests/AskKeyAppTests/RemoteApprovalFooterHintTests.swift @@ -9,8 +9,8 @@ import XCTest /// What the coordinator tells the approval panel's footer (ADR 0014 → Mac /// App, amended by #345): the countdown only while an eligible request waits -/// for an approver with room, "Also on iPhone" only while a saved copy is -/// outstanding, and the unchanged footer in every other case. The footer +/// for an approver with room, the sent hint only while a saved copy is +/// outstanding, and no hint in every other case. The footer /// only reads; none of these steps changes what is sent. @MainActor final class RemoteApprovalFooterHintTests: AskKeyAppTestCase { @@ -43,7 +43,7 @@ final class RemoteApprovalFooterHintTests: AskKeyAppTestCase { await harness.coordinator.remoteApprovalTick() } - func testTheCountdownRunsUntilTheSendThenTheSavedCopySaysAlsoOnIPhone() async throws { + func testTheCountdownRunsUntilTheSendThenTheSavedCopyGivesTheSentHint() async throws { let (pending, sendAt) = try await waitingRead() for _ in 0..<19 { XCTAssertEqual(hint(pending), .waiting(sendAt: sendAt)) diff --git a/Tests/AskKeyAppTests/RemoteApprovalFooterTests.swift b/Tests/AskKeyAppTests/RemoteApprovalFooterTests.swift index 29801f9e..7b9dead3 100644 --- a/Tests/AskKeyAppTests/RemoteApprovalFooterTests.swift +++ b/Tests/AskKeyAppTests/RemoteApprovalFooterTests.swift @@ -7,8 +7,10 @@ import XCTest @testable import AskKeyAppKit /// The approval panel's footer with a paired iPhone (ADR 0014 → Mac App, -/// amended by #345): one moving number at a time, in English and -/// Simplified Chinese, on a fake clock. +/// amended by #345): one moving number at a time in the maintainer's +/// wording (#356), in English and Simplified Chinese, on a fake clock; and +/// deciding later with Esc or VoiceOver now that the footer shows no Esc +/// hint. @MainActor final class RemoteApprovalFooterTests: XCTestCase { private let start = Date(timeIntervalSince1970: 2_000_000_000) @@ -16,7 +18,7 @@ final class RemoteApprovalFooterTests: XCTestCase { private var expiresAt: Date { start.addingTimeInterval(300) } private func footer(_ hint: RemoteApprovalFooterHint?, at seconds: TimeInterval) -> String { - RemoteApprovalFooter.sentence(RemoteApprovalFooter.text(hint, expiresAt: expiresAt, now: start.addingTimeInterval(seconds))) + RemoteApprovalFooter.text(hint, expiresAt: expiresAt, now: start.addingTimeInterval(seconds)) } func testTheSendCountdownRunsFromTwentyToOneThenTheExpiryReturns() { @@ -24,31 +26,47 @@ final class RemoteApprovalFooterTests: XCTestCase { let english = language == "en" let waiting = RemoteApprovalFooterHint.waiting(sendAt: sendAt) XCTAssertEqual(footer(waiting, at: 0), english - ? "iPhone can decide in 20 s · Esc to decide later" - : "20 秒后 iPhone 也能处理 · Esc 稍后处理") // i18n-literal: maintainer's Chinese footer (#344, decision 6). + ? "This request will be sent to iPhone in 20 s" + : "20 秒后将把审批请求发到 iPhone") // i18n-literal: maintainer's Chinese footer (#356). for elapsed in 0..<20 { // Each tick falls just after a whole second. let seconds = 20 - elapsed - let expected = english ? "iPhone can decide in \(seconds) s" : "\(seconds) 秒后 iPhone 也能处理" // i18n-literal: Chinese countdown. - XCTAssertEqual(RemoteApprovalFooter.text(waiting, expiresAt: expiresAt, - now: start.addingTimeInterval(Double(elapsed) + 0.01)), expected) - XCTAssertEqual(RemoteApprovalFooter.text(waiting, expiresAt: expiresAt, - now: start.addingTimeInterval(Double(elapsed) + 0.99)), expected) + let expected = english + ? "This request will be sent to iPhone in \(seconds) s" + : "\(seconds) 秒后将把审批请求发到 iPhone" // i18n-literal: Chinese countdown. + XCTAssertEqual(footer(waiting, at: Double(elapsed) + 0.01), expected) + XCTAssertEqual(footer(waiting, at: Double(elapsed) + 0.99), expected) } XCTAssertEqual(footer(waiting, at: 2), english - ? "iPhone can decide in 18 s · Esc to decide later" - : "18 秒后 iPhone 也能处理 · Esc 稍后处理") // i18n-literal: maintainer's Chinese footer (#344, decision 6). + ? "This request will be sent to iPhone in 18 s" + : "18 秒后将把审批请求发到 iPhone") // i18n-literal: maintainer's Chinese footer (#356). XCTAssertEqual(footer(waiting, at: 19.5), english - ? "iPhone can decide in 1 s · Esc to decide later" - : "1 秒后 iPhone 也能处理 · Esc 稍后处理") // i18n-literal: Chinese footer at one second. - // The send is due but not saved yet: the footer is unchanged. + ? "This request will be sent to iPhone in 1 s" + : "1 秒后将把审批请求发到 iPhone") // i18n-literal: Chinese footer at one second. + // The send is due but not saved yet: the footer shows the expiry. XCTAssertEqual(footer(waiting, at: 20), english - ? "Expires in 4:40 · Esc to decide later" : "4:40 后失效 · Esc 稍后处理") // i18n-literal: Chinese footer. + ? "This request expires in 4:40" : "审批请求将于 4:40 后失效") // i18n-literal: Chinese footer. XCTAssertEqual(footer(.sent, at: 20.5), english - ? "Also on iPhone · Expires in 4:39 · Esc to decide later" - : "iPhone 也能处理 · 4:39 后失效 · Esc 稍后处理") // i18n-literal: maintainer's Chinese footer (#344, decision 6). + ? "This request expires in 4:39" + : "审批请求将于 4:39 后失效") // i18n-literal: maintainer's Chinese footer (#356). XCTAssertEqual(footer(nil, at: 0.5), english - ? "Expires in 4:59 · Esc to decide later" : "4:59 后失效 · Esc 稍后处理") // i18n-literal: Chinese footer. + ? "This request expires in 4:59" + : "审批请求将于 4:59 后失效") // i18n-literal: maintainer's Chinese footer (#356). + } + } + + /// The footer is only its sentence (#356): no Esc hint in any state, and + /// the pending-request list and the pairing sheet keep their own + /// "Expires in" wording. + func testTheFooterDropsTheEscHintAndLeavesTheSharedExpiryWording() { + ApprovalCardFixtures.withLanguages { language in + for hint in [RemoteApprovalFooterHint.waiting(sendAt: sendAt), .sent, nil] { + let text = footer(hint, at: 2) + XCTAssertFalse(text.contains("Esc"), text) + XCTAssertFalse(text.contains("·"), text) + } + XCTAssertEqual(appLocalizedFormat("Expires in %@", "4:11"), language == "en" + ? "Expires in 4:11" : "4:11 后失效") // i18n-literal: Chinese shared expiry. } } @@ -59,7 +77,8 @@ final class RemoteApprovalFooterTests: XCTestCase { XCTAssertTrue(waiting.contains("iPhone")) let sent = RemoteApprovalFooter.text(.sent, expiresAt: expiresAt, now: start) XCTAssertTrue(sent.contains("5:00")) - XCTAssertTrue(sent.contains("iPhone")) + XCTAssertEqual(sent, RemoteApprovalFooter.text(nil, expiresAt: expiresAt, now: start), + "after the send the footer reads as it does without an approver") } } @@ -76,8 +95,9 @@ final class RemoteApprovalFooterTests: XCTestCase { RemoteApprovalFooter.text(.waiting(sendAt: sendAt), expiresAt: expiresAt, now: $0) } XCTAssertEqual(texts, language == "en" - ? ["iPhone can decide in 18 s", "iPhone can decide in 17 s", "iPhone can decide in 16 s"] - : ["18 秒后 iPhone 也能处理", "17 秒后 iPhone 也能处理", "16 秒后 iPhone 也能处理"]) // i18n-literal: Chinese countdown. + ? ["This request will be sent to iPhone in 18 s", "This request will be sent to iPhone in 17 s", + "This request will be sent to iPhone in 16 s"] + : ["18 秒后将把审批请求发到 iPhone", "17 秒后将把审批请求发到 iPhone", "16 秒后将把审批请求发到 iPhone"]) // i18n-literal: Chinese countdown. } let expiry = RemoteApprovalFooterSchedule(anchor: expiresAt).entries(from: start.addingTimeInterval(0.5), mode: .normal) XCTAssertEqual(try XCTUnwrap(expiry.next()).timeIntervalSince(start), 0.01, accuracy: 0.000_1) @@ -98,30 +118,26 @@ final class RemoteApprovalFooterTests: XCTestCase { XCTAssertEqual(step(footer: .sent), .keepOpen) XCTAssertEqual(state.footer, .sent) XCTAssertEqual(step(ended: true, footer: .sent), .close) - XCTAssertNil(state.footer, "a request that left pending never says the iPhone can decide") + XCTAssertNil(state.footer, "a request that left pending never counts down to a send") XCTAssertEqual(step(unlocked: false, footer: .sent), .close, "a lock closes the panel as before") } func testAnApproversDecisionClearsTheHintAtOnce() { let state = RemoteApprovalPanelState(requestID: "request", footer: .sent) state.record(RemoteAppliedDecision(requestID: "request", deviceName: "Synthetic iPhone", approved: true), now: start) - XCTAssertNil(state.footer, "\"Also on iPhone\" never shows next to \"Approved on\"") + XCTAssertNil(state.footer, "a hint about the approvers never shows next to \"Approved on\"") XCTAssertEqual(state.step(requestEnded: false, screenUnlocked: true, expired: false, now: start, status: nil, footer: .sent, lastDecision: nil, applying: true), .keepOpen) XCTAssertNil(state.footer) } /// The panel follows its state's hint, and a footer that needs a second - /// line, as the English sent form does, grows the panel downward: its top - /// edge, and with it every button, stays where it was. - func testTheFooterFollowsTheHintAndAGrowingFooterKeepsTheButtonsInPlace() throws { + /// line grows the panel downward: its top edge, and with it every button, + /// stays where it was. Every Chinese form fits on one line. + func testTheFooterFollowsTheHintAndKeepsTheButtonsInPlace() throws { _ = NSApplication.shared try ApprovalCardFixtures.withLanguages { language in - let request = ApprovalCardFixtures.request(.read, display: ApprovalCardFixtures.display()) let remote = RemoteApprovalPanelState(requestID: "synthetic", footer: .waiting(sendAt: Date(timeIntervalSinceNow: 18))) - let prompt = FrozenAgentApprovalPrompt(request: request, trustedCredentialName: "Staging API", - expiresAt: Date(timeIntervalSinceNow: 300), timedAllowanceEnabled: true, remote: remote, - finish: { _ in XCTFail("Laying out must never decide") }) - let panel = AppDelegate.makeFrozenApprovalPanel(prompt, visibleFrame: { _ in NSRect(x: 0, y: 0, width: 1440, height: 900) }) + let panel = makePanel(remote: remote) { _ in XCTFail("Laying out must never decide") } defer { panel.contentViewController = nil; panel.close() } func show(_ hint: RemoteApprovalFooterHint?) -> NSRect { _ = remote.step(requestEnded: false, screenUnlocked: true, expired: false, now: Date(), status: nil, @@ -135,14 +151,93 @@ final class RemoteApprovalFooterTests: XCTestCase { } let waiting = show(.waiting(sendAt: Date(timeIntervalSinceNow: 18))) let sent = show(.sent) + let none = show(nil) XCTAssertFalse(panel.isVisible) XCTAssertEqual(sent.maxY, waiting.maxY, accuracy: 0.5, "the top edge stays") + XCTAssertEqual(none.maxY, waiting.maxY, accuracy: 0.5, "the top edge stays") + XCTAssertEqual(sent.height, none.height, accuracy: 0.5, "both expiry forms take one line") if language == "en" { - XCTAssertGreaterThan(sent.height, waiting.height, "the English sent form takes a second line") + XCTAssertGreaterThanOrEqual(waiting.height, none.height - 0.5, "English may wrap, downward") } else { - XCTAssertEqual(sent.height, waiting.height, accuracy: 0.5, "every Chinese form fits on one line") + XCTAssertEqual(waiting.height, none.height, accuracy: 0.5, "every Chinese form fits on one line") } - XCTAssertEqual(show(nil), waiting, "the unchanged footer is one line again") } } + + // MARK: Deciding later + + /// Esc decides later in the production panel (#356) with no control on + /// the card. The panel takes Esc in `sendEvent(_:)`, through which AppKit + /// delivers every key event to it, whether the panel itself or the card's + /// hosting view is first responder (as when keyboard navigation focuses a + /// button). A cancel sent up the responder chain, as Command-period is, + /// decides later too. Other keys pass through. + func testEscInThePanelDecidesLater() throws { + _ = NSApplication.shared + var decisions: [BrokerApprovalDecision?] = [] + let remote = RemoteApprovalPanelState(requestID: "synthetic", footer: .waiting(sendAt: Date(timeIntervalSinceNow: 18))) + let panel = makePanel(remote: remote) { decisions.append($0) } + defer { panel.contentViewController = nil; panel.close() } + settle(panel) + XCTAssertTrue(panel is AgentApprovalPanel) + let hosting = try XCTUnwrap(panel.contentView) + for responder in [panel, hosting] as [NSResponder] { + XCTAssertTrue(panel.makeFirstResponder(responder)) + XCTAssertTrue(panel.firstResponder === responder) + panel.sendEvent(try key("\u{1b}", code: 53, in: panel)) + } + XCTAssertEqual(decisions.count, 2, "each Esc reached the card") + panel.sendEvent(try key("a", code: 0, in: panel)) + panel.sendEvent(try key("\u{1b}", code: 53, modifiers: .command, in: panel)) + XCTAssertEqual(decisions.count, 2, "other keys never decide") + XCTAssertTrue(hosting.tryToPerform(#selector(NSResponder.cancelOperation(_:)), with: nil)) + XCTAssertEqual(decisions.count, 3, "a cancel up the responder chain reached the card") + XCTAssertTrue(decisions.allSatisfy { $0 == nil }, "Esc decides later and never approves or denies") + } + + /// VoiceOver keeps a way to decide later: the footer is one element + /// with a "Decide Later" action, named in both languages, that decides + /// later as Esc does. SwiftUI builds no accessibility tree for a panel + /// that is never shown, so this checks the footer's wiring and the + /// action's name; the screenshot flow finds the footer in the real panel. + func testVoiceOverOffersDecideLaterOnTheFooter() throws { + ApprovalCardFixtures.withLanguages { language in + XCTAssertEqual(RemoteApprovalFooter.decideLaterAction, language == "en" + ? "Decide Later" : "稍后处理") // i18n-literal: Chinese VoiceOver action. + } + let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() + let source = try String(contentsOf: root.appendingPathComponent("Sources/AskKeyAppKit/App/FrozenAgentApprovalPrompt.swift"), + encoding: .utf8) + let footer = try XCTUnwrap(source.range(of: "private var footer: some View {") + .map { String(source[$0.lowerBound...]) }) + XCTAssertTrue(footer.contains( + ".accessibilityAction(named: Text(verbatim: RemoteApprovalFooter.decideLaterAction)) { finish(nil) }")) + XCTAssertTrue(footer.contains(".accessibilityIdentifier(\"approval-footer\")")) + XCTAssertFalse(source.contains(".keyboardShortcut(.cancelAction)"), "Esc is the panel's, not a control's") + } + + // MARK: Helpers + + private func makePanel(remote: RemoteApprovalPanelState, + finish: @escaping (BrokerApprovalDecision?) -> Void) -> NSPanel { + let request = ApprovalCardFixtures.request(.read, display: ApprovalCardFixtures.display()) + let prompt = FrozenAgentApprovalPrompt(request: request, trustedCredentialName: "Staging API", + expiresAt: Date(timeIntervalSinceNow: 300), timedAllowanceEnabled: true, remote: remote, finish: finish) + return AppDelegate.makeFrozenApprovalPanel(prompt, visibleFrame: { _ in NSRect(x: 0, y: 0, width: 1440, height: 900) }) + } + + private func settle(_ panel: NSPanel) { + for _ in 0..<12 { + panel.layoutIfNeeded() + panel.contentView?.layoutSubtreeIfNeeded() + RunLoop.current.run(mode: .default, before: Date(timeIntervalSinceNow: 0.02)) + } + } + + private func key(_ characters: String, code: UInt16, modifiers: NSEvent.ModifierFlags = [], + in panel: NSPanel) throws -> NSEvent { + try XCTUnwrap(NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: modifiers, + timestamp: ProcessInfo.processInfo.systemUptime, windowNumber: panel.windowNumber, context: nil, + characters: characters, charactersIgnoringModifiers: characters, isARepeat: false, keyCode: code)) + } } diff --git a/Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift b/Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift index d09976d0..7a97b95d 100644 --- a/Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift +++ b/Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift @@ -14,7 +14,8 @@ import XCTest /// without approval, and Remove's confirmation; every step of the pairing /// sheet with its approval statements at its own size (a SwiftUI sheet can't /// be captured offscreen); and the approval panel through the production -/// panel factory, with its footer before and after the send (#350). No +/// panel factory, with its footer before and after the send (#350, worded +/// as in #356). No /// window is ordered in. Set /// `REMOTE_APPROVAL_RENDER_DIRECTORY` to keep the PNGs, and also /// `REMOTE_APPROVAL_WINDOW_RENDERS=1` on a desktop session to render the @@ -217,7 +218,7 @@ final class RemoteApprovalRenderTests: AskKeyAppTestCase { deliveredAt: delivered ? sent.addingTimeInterval(2) : nil)]) } let cases: [(String, RemoteApprovalPanelState, Bool)] = [ - // Saved and still open, so the footer says "Also on iPhone" (#350). + // Saved and still open, so the footer has the sent hint (#350). ("11", RemoteApprovalPanelState(requestID: "synthetic", status: status(delivered: false), footer: .sent), true), ("12", RemoteApprovalPanelState(requestID: "synthetic", status: status(delivered: true), footer: .sent), true), ("13", outcome(approved: true, status: status(delivered: true)), false), @@ -234,10 +235,11 @@ final class RemoteApprovalRenderTests: AskKeyAppTestCase { return names } - /// The footer with a paired iPhone (#350): the send countdown at 18 - /// seconds, "Also on iPhone" after the send, and the unchanged footer - /// when no approver can take the request. Details stay collapsed, so the - /// render shows the whole front next to the footer. + /// The footer with a paired iPhone (#350) in the maintainer's wording + /// (#356): the send countdown at 18 seconds, the expiry after the send, + /// and the expiry when no approver can take the request, never with an + /// Esc hint. Details stay collapsed, so the render shows the whole front + /// next to the footer. private func renderFooters(tag: String) throws -> [String] { let deviceID = try XCTUnwrap(DeviceID(rawValue: Data(repeating: 9, count: 16))) let sent = RemoteApprovalStatus(approvers: [.init(deviceID: deviceID, displayName: "Synthetic iPhone", @@ -258,6 +260,7 @@ final class RemoteApprovalRenderTests: AskKeyAppTestCase { let tick = try XCTUnwrap(schedule.entries(from: now, mode: .normal).next()) let shown = RemoteApprovalFooter.text(remote.footer, expiresAt: expiresAt, now: tick) XCTAssertTrue(shown.contains(number), "\(label) shows \(shown)") + XCTAssertFalse(shown.contains("Esc"), "\(label) shows \(shown)") try renderPanel(remote: remote, expanded: false, expiresAt: expiresAt, as: name) if Date().timeIntervalSince(now) < 0.9 { names.append(name) @@ -266,10 +269,10 @@ final class RemoteApprovalRenderTests: AskKeyAppTestCase { } XCTFail("\(name) took longer than 0.9 s to render three times") } - try footer("17-panel-footer-iphone-in-18s", expiresIn: 297.95, shows: "18") { + try footer("17-panel-footer-send-in-18s", expiresIn: 297.95, shows: "18") { RemoteApprovalPanelState(requestID: "synthetic", footer: .waiting(sendAt: $0.addingTimeInterval(17.95))) } - try footer("18-panel-footer-also-on-iphone", expiresIn: 279.95, shows: "4:39") { _ in + try footer("18-panel-footer-after-send", expiresIn: 279.95, shows: "4:39") { _ in RemoteApprovalPanelState(requestID: "synthetic", status: sent, footer: .sent) } try footer("19-panel-footer-no-approver", expiresIn: 299.95, shows: "4:59") { _ in diff --git a/Tests/AskKeyE2ETests/ScreenshotE2ETests.swift b/Tests/AskKeyE2ETests/ScreenshotE2ETests.swift index ab65f6bf..c6ba9df3 100644 --- a/Tests/AskKeyE2ETests/ScreenshotE2ETests.swift +++ b/Tests/AskKeyE2ETests/ScreenshotE2ETests.swift @@ -172,8 +172,13 @@ final class ScreenshotE2ETests: E2EBaseCase { XCTAssertEqual(app.buttons["approval-allow-once"].label, "Allow Once") XCTAssertEqual(app.buttons["approval-allow-timed"].label, "Allow for 30 Minutes") XCTAssertEqual(app.buttons["approval-deny"].label, "Deny") - // The footer is one VoiceOver sentence, "Expires in … · Esc to decide later" (#350). - waitForText("Esc to decide later", containing: true) + // The footer shows only its sentence and carries VoiceOver's Decide + // Later action; Esc still decides later (#356, + // testPendingRequestsAndAccessRecords). + XCTAssertTrue(app.descendants(matching: .any)["approval-footer"].waitForExistence(timeout: 8)) + waitForText("This request expires in", containing: true) + XCTAssertFalse(app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS %@ OR value CONTAINS %@", + "Esc to decide later", "Esc to decide later")).firstMatch.exists, "the footer has no Esc hint") XCTAssertFalse(app.staticTexts["Requested by"].exists, "everything else stays behind Details") capture("12-approval-default", approval: true) click("approval-details") diff --git a/docs/adr/0014-remote-approval.md b/docs/adr/0014-remote-approval.md index d726582c..010856b2 100644 --- a/docs/adr/0014-remote-approval.md +++ b/docs/adr/0014-remote-approval.md @@ -239,7 +239,7 @@ A forged QR code can put a fake Mac on the iPhone's list (ADR 0013). Since [#336 ### Mac App - **Devices** ([#336](https://github.com/sudoHG/AskKey/issues/336)): a paired iPhone's row has no approval control. It says that the iPhone approves agent requests or, for an entry without the flag, that it cannot until it is removed and paired again. **Remove** says that the device stops approving at once and its open requests close. A required desktop flow completes a pairing with one simulated iPhone, checks that its new row says it approves agent requests, then clicks **Remove**, confirms and checks that the row is gone; it replaces the flow that clicked the switch, so a real click on the Mac's only revocation control stays covered on the macOS 26 runner (#299, #300). -- **Approval panel:** the front (one sentence and one subtitle line) is unchanged. Details add, per approver, "Sent to “iPhone” at 10:02", "Delivered to “iPhone” at 10:02" (when the Mac processed the receipt, on its own clock) or "Not delivered yet". When a remote decision applies while the panel is open and the screen is unlocked, the panel shows "Approved on “iPhone”" or "Denied on “iPhone”" for about two seconds and closes; while locked it closes at once. The footer ([#345](https://github.com/sudoHG/AskKey/issues/345)) shows one moving number at a time. While the screen is unlocked and the request waits for its 20-second send, with its send time ahead, still eligible and with at least one active approver below its 16-request limit, the footer counts down to that moment in place of the expiry: "iPhone can decide in 18 s · Esc to decide later". While at least one approver's copy has been saved to its inbox (Details' "Sent to") and is still outstanding, it says "Also on iPhone · Expires in 4:39 · Esc to decide later". Otherwise, including while sealing, while a first send is retrying, when every approver is full and once every copy has closed, it is unchanged: "Expires in 4:59 · Esc to decide later". It says "iPhone", not a device's name, also with several approvers. The footer only reads the coordinator's state and changes nothing about when or whether a request is sent. The Simplified Chinese wording is fixed in [#344](https://github.com/sudoHG/AskKey/issues/344) (decision 6). +- **Approval panel:** the front (one sentence and one subtitle line) is unchanged. Details add, per approver, "Sent to “iPhone” at 10:02", "Delivered to “iPhone” at 10:02" (when the Mac processed the receipt, on its own clock) or "Not delivered yet". When a remote decision applies while the panel is open and the screen is unlocked, the panel shows "Approved on “iPhone”" or "Denied on “iPhone”" for about two seconds and closes; while locked it closes at once. The footer ([#345](https://github.com/sudoHG/AskKey/issues/345)) shows one moving number at a time. While the screen is unlocked and the request waits for its 20-second send, with its send time ahead, still eligible and with at least one active approver below its 16-request limit, the footer counts down to that moment in place of the expiry: "This request will be sent to iPhone in 18 s". While at least one approver's copy has been saved to its inbox (Details' "Sent to") and is still outstanding, it shows the expiry: "This request expires in 4:39". Otherwise, including while sealing, while a first send is retrying, when every approver is full and once every copy has closed, it shows the expiry the same way: "This request expires in 4:59". It says "iPhone", not a device's name, also with several approvers. It shows no Esc hint: Esc still decides later, and VoiceOver offers Decide Later as a named action on the footer. The footer only reads the coordinator's state and changes nothing about when or whether a request is sent. The Simplified Chinese wording is the maintainer's, fixed in [#356](https://github.com/sudoHG/AskKey/issues/356), which replaced that of [#344](https://github.com/sudoHG/AskKey/issues/344) (decision 6). - The pending-requests list shows "Sent to iPhone" for requests that went out. - **Pairing sheet:** before the QR code it tells the person to install Ask Key on the iPhone first, with the fixed link `https://askkey.sudohg.com/iphone`, a redirect in `site/_redirects` that the maintainer points at the public TestFlight link and later at the App Store. Since #336 it also says there that the iPhone will be able to approve this Mac's agent requests, so the person pairs only their own iPhone. Once the code matches, before the system authentication that confirms the pairing, it names the device, says that confirming lets it approve agent read requests, and lists what a request sends to it; the authentication's reason says that an iPhone that can approve agent requests is being paired. The paired state says the iPhone can now approve agent requests. - **Push registration** moves from launch to the moment an identity exists, so a Mac that never starts pairing registers no push. @@ -424,9 +424,9 @@ The Decision sections above describe the amended design; the main ones are [iPho ### Mac card hint -- **One moving number at a time** (decision 6, option A). While the screen is unlocked and an eligible request waits for its 20-second send with an approver able to take it, the approval panel's footer counts down to that moment in place of the expiry: "iPhone can decide in 18 s · Esc to decide later". While a copy saved to an approver's inbox is still outstanding, the footer says "Also on iPhone · Expires in 4:39 · Esc to decide later". In every other case it stays "Expires in 4:59 · Esc to decide later". The Simplified Chinese strings are the maintainer's, fixed word for word in #344 and repeated in [#350](https://github.com/sudoHG/AskKey/issues/350). -- *Why:* the maintainer rejected a footer that showed the send countdown and the expiry side by side, and wording about where the request goes rather than what the person can do. During the first 20 seconds the expiry is still minutes away, so the moment the iPhone can help is the number worth showing; after the send, the expiry is again. The footer says "iPhone", not a device's name, also with several approvers; names stay in Details. The front (one sentence and one subtitle line) and Details do not change, so the card keeps its v0.2 shape. -- **What the footer follows.** It reads the coordinator's existing state (whether the request is waiting with a send time ahead, whether it is still eligible, whether an active approver is below its 16-request limit, and whether a copy was saved and is still outstanding) and changes nothing about when or whether a request is sent. A request that stops being eligible during the wait, for example because the last approver was removed, the account became unavailable or agent access was paused, shows the unchanged footer, and so does one whose approvers are all full, one being sealed or retrying its first send, and one whose every copy closed. The sent form follows the same saved state as Details' "Sent to", so the footer never says the iPhone can decide before its inbox holds the request. The seconds count down once a second; VoiceOver reads the footer as one sentence and does not announce each second. On a locked screen the panel behaves as before. +- **One moving number at a time** (decision 6, option A). While the screen is unlocked and an eligible request waits for its 20-second send with an approver able to take it, the approval panel's footer counts down to that moment in place of the expiry: "This request will be sent to iPhone in 18 s". While a copy saved to an approver's inbox is still outstanding, the footer shows the expiry: "This request expires in 4:39". In every other case it shows the expiry the same way: "This request expires in 4:59". The footer shows no Esc hint; Esc still decides later, and VoiceOver offers Decide Later as a named action on the footer. The Simplified Chinese strings are the maintainer's, fixed word for word in [#356](https://github.com/sudoHG/AskKey/issues/356) (2026-11-16); they replace the strings of #344 that [#350](https://github.com/sudoHG/AskKey/issues/350) built. +- *Why:* the maintainer rejected a footer that showed the send countdown and the expiry side by side. After seeing #350's footer, they replaced its wording with their own, which says when the request is sent to iPhone and when it expires, and removed the Esc hint (#356). During the first 20 seconds the expiry is still minutes away, so the moment the request goes to the iPhone is the number worth showing; after the send, the expiry is again. The footer says "iPhone", not a device's name, also with several approvers; names stay in Details. The front (one sentence and one subtitle line) and Details do not change, so the card keeps its v0.2 shape. +- **What the footer follows.** It reads the coordinator's existing state (whether the request is waiting with a send time ahead, whether it is still eligible, whether an active approver is below its 16-request limit, and whether a copy was saved and is still outstanding) and changes nothing about when or whether a request is sent. A request that stops being eligible during the wait, for example because the last approver was removed, the account became unavailable or agent access was paused, shows the expiry, and so does one whose approvers are all full, one being sealed or retrying its first send, and one whose every copy closed. The sent state follows the same saved state as Details' "Sent to"; its footer reads like the others after the send, so the footer never claims the iPhone holds the request. The seconds count down once a second; VoiceOver reads the footer's sentence, does not announce each second, and offers Decide Later as a named action on it. On a locked screen the panel behaves as before. ### What is accepted From 57c735b943b6135a4d6a5c06b2d8fdebad694751 Mon Sep 17 00:00:00 2001 From: sudoHG Date: Mon, 16 Nov 2026 11:02:55 +0800 Subject: [PATCH 2/3] Test the Esc filter instead of AppKit's handling of modified Esc The Esc test sent Command-Esc through the panel and expected no decision. The panel passes Esc with a modifier on to AppKit, which turns it into cancelOperation(_:) only while the app is active: on the CI runner it is, so the cancel reached the panel and decided later, as that path is meant to. The test now checks that other keys never decide and that the panel's filter rejects Esc with each modifier, which holds whether or not the test process is active. --- .../RemoteApprovalFooterTests.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Tests/AskKeyAppTests/RemoteApprovalFooterTests.swift b/Tests/AskKeyAppTests/RemoteApprovalFooterTests.swift index 7b9dead3..e42fe4f8 100644 --- a/Tests/AskKeyAppTests/RemoteApprovalFooterTests.swift +++ b/Tests/AskKeyAppTests/RemoteApprovalFooterTests.swift @@ -133,9 +133,9 @@ final class RemoteApprovalFooterTests: XCTestCase { /// The panel follows its state's hint, and a footer that needs a second /// line grows the panel downward: its top edge, and with it every button, /// stays where it was. Every Chinese form fits on one line. - func testTheFooterFollowsTheHintAndKeepsTheButtonsInPlace() throws { + func testTheFooterFollowsTheHintAndKeepsTheButtonsInPlace() { _ = NSApplication.shared - try ApprovalCardFixtures.withLanguages { language in + ApprovalCardFixtures.withLanguages { language in let remote = RemoteApprovalPanelState(requestID: "synthetic", footer: .waiting(sendAt: Date(timeIntervalSinceNow: 18))) let panel = makePanel(remote: remote) { _ in XCTFail("Laying out must never decide") } defer { panel.contentViewController = nil; panel.close() } @@ -171,7 +171,10 @@ final class RemoteApprovalFooterTests: XCTestCase { /// delivers every key event to it, whether the panel itself or the card's /// hosting view is first responder (as when keyboard navigation focuses a /// button). A cancel sent up the responder chain, as Command-period is, - /// decides later too. Other keys pass through. + /// decides later too. Other keys pass through. Esc with a modifier is not + /// the panel's: it goes on to AppKit, which turns it into a cancel only + /// while the app is active (it is on the CI runner, not in a local run), + /// so the test checks the panel's filter for it instead of sending it. func testEscInThePanelDecidesLater() throws { _ = NSApplication.shared var decisions: [BrokerApprovalDecision?] = [] @@ -188,8 +191,13 @@ final class RemoteApprovalFooterTests: XCTestCase { } XCTAssertEqual(decisions.count, 2, "each Esc reached the card") panel.sendEvent(try key("a", code: 0, in: panel)) - panel.sendEvent(try key("\u{1b}", code: 53, modifiers: .command, in: panel)) XCTAssertEqual(decisions.count, 2, "other keys never decide") + XCTAssertTrue(AgentApprovalPanel.isEscape(try key("\u{1b}", code: 53, in: panel))) + for modifier in [NSEvent.ModifierFlags.command, .control, .option, .shift] { + XCTAssertFalse(AgentApprovalPanel.isEscape(try key("\u{1b}", code: 53, modifiers: modifier, in: panel)), + "Esc with \(modifier) is AppKit's") + } + XCTAssertFalse(AgentApprovalPanel.isEscape(try key("a", code: 0, in: panel))) XCTAssertTrue(hosting.tryToPerform(#selector(NSResponder.cancelOperation(_:)), with: nil)) XCTAssertEqual(decisions.count, 3, "a cancel up the responder chain reached the card") XCTAssertTrue(decisions.allSatisfy { $0 == nil }, "Esc decides later and never approves or denies") From 71f4720c9779afa0591d9097a8eb3605d547983c Mon Sep 17 00:00:00 2001 From: sudoHG Date: Mon, 16 Nov 2026 12:22:20 +0800 Subject: [PATCH 3/3] Address the cross review: Esc repeats, panel closing, stale wording - A held Esc decides once: the key approval panel swallows Esc repeats, so they never decide the next queued request. The Esc test covers a repeated Esc. - The screenshot flow asserts that Esc closes the real panel, not only that the request stays pending. - AgentApprovalPanel's doc no longer says Command-period always decides later: AppKit sends a responder-chain cancel only while the app is active, which is why the non-activating panel takes Esc in sendEvent. - Test names and messages that still said "Also on iPhone" or "unchanged", and ADR 0014's #350 task entry, are reworded. --- .../AskKeyAppKit/AgentApprovalPanelFactory.swift | 15 ++++++++++----- .../RemoteApprovalFooterHintTests.swift | 14 +++++++------- .../RemoteApprovalFooterTests.swift | 12 ++++++++---- .../RemoteApprovalRenderTests.swift | 3 +-- Tests/AskKeyE2ETests/ScreenshotE2ETests.swift | 2 ++ docs/adr/0014-remote-approval.md | 2 +- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Sources/AskKeyAppKit/AgentApprovalPanelFactory.swift b/Sources/AskKeyAppKit/AgentApprovalPanelFactory.swift index e8dee99e..5bef01f9 100644 --- a/Sources/AskKeyAppKit/AgentApprovalPanelFactory.swift +++ b/Sources/AskKeyAppKit/AgentApprovalPanelFactory.swift @@ -2,15 +2,20 @@ import AppKit /// The approval panel's window. Esc decides later with no control on the /// card (#356): every key event AppKit delivers to the panel passes through -/// `sendEvent(_:)`, whichever view is first responder, so the panel takes -/// Esc there and hands it to `cancel`. Command-period and any other cancel -/// sent up the responder chain end in `cancelOperation(_:)` and do the same. +/// `sendEvent(_:)`, whichever view is first responder and whether or not +/// the app is active, so the panel takes Esc there and hands it to `cancel`. +/// Holding Esc decides once: whichever approval panel is key swallows the +/// repeats, so they never decide the next request. A cancel that reaches the +/// panel through the +/// responder chain (AppKit sends one for Command-period or Esc with a +/// modifier while the app is active) ends in `cancelOperation(_:)` and +/// decides later too. final class AgentApprovalPanel: NSPanel { var cancel: (@MainActor () -> Void)? override func sendEvent(_ event: NSEvent) { - if let cancel, Self.isEscape(event) { return cancel() } - super.sendEvent(event) + guard let cancel, Self.isEscape(event) else { return super.sendEvent(event) } + if !event.isARepeat { cancel() } } override func cancelOperation(_ sender: Any?) { diff --git a/Tests/AskKeyAppTests/RemoteApprovalFooterHintTests.swift b/Tests/AskKeyAppTests/RemoteApprovalFooterHintTests.swift index 83401cc5..a8ce672a 100644 --- a/Tests/AskKeyAppTests/RemoteApprovalFooterHintTests.swift +++ b/Tests/AskKeyAppTests/RemoteApprovalFooterHintTests.swift @@ -54,14 +54,14 @@ final class RemoteApprovalFooterHintTests: AskKeyAppTestCase { harness.clock.advance(by: 1) harness.coordinator.reconcileRemoteRequests() XCTAssertEqual(harness.coordinator.remoteRequests[pending.requestID]?.phase, .sending) - XCTAssertNil(hint(pending), "unchanged while the request is being sealed") + XCTAssertNil(hint(pending), "no hint while the request is being sealed") try await harness.waitForRequests(1) try await harness.waitUntil { harness.entries(pending).first?.sentAt != nil } XCTAssertEqual(hint(pending), .sent) XCTAssertTrue(harness.coordinator.wasSentToApprover(pending.requestID), "the same saved state as Details' Sent to") } - func testARequestDecidedOnTheMacWithinTwentySecondsNeverSaysAlsoOnIPhone() async throws { + func testARequestDecidedOnTheMacWithinTwentySecondsNeverGetsTheSentHint() async throws { let (pending, sendAt) = try await waitingRead() harness.clock.advance(by: 10) await harness.coordinator.remoteApprovalTick() @@ -78,7 +78,7 @@ final class RemoteApprovalFooterHintTests: AskKeyAppTestCase { XCTAssertTrue(harness.macSent(.approvalRequest).isEmpty) } - func testWithoutAnApproverTheFooterIsAlwaysUnchanged() async throws { + func testWithoutAnApproverTheFooterNeverHasAHint() async throws { try await harness.pairPhone() await harness.coordinator.removeDevice(harness.phone.deviceID) try await harness.addUnflaggedEntry(for: harness.phone, name: "Synthetic Phone") @@ -126,7 +126,7 @@ final class RemoteApprovalFooterHintTests: AskKeyAppTestCase { XCTAssertNil(hint(pending), "a request that will not be sealed never promises the iPhone") } - func testWhenEveryApproverIsFullTheFooterIsUnchangedUntilOneHasRoom() async throws { + func testWhenEveryApproverIsFullTheFooterHasNoHintUntilOneHasRoom() async throws { try await harness.pairApprover() var sent: [BrokerPendingApproval] = [] for _ in 0.. NSEvent { + repeating: Bool = false, in panel: NSPanel) throws -> NSEvent { try XCTUnwrap(NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: modifiers, timestamp: ProcessInfo.processInfo.systemUptime, windowNumber: panel.windowNumber, context: nil, - characters: characters, charactersIgnoringModifiers: characters, isARepeat: false, keyCode: code)) + characters: characters, charactersIgnoringModifiers: characters, isARepeat: repeating, keyCode: code)) } } diff --git a/Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift b/Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift index 7a97b95d..c50461aa 100644 --- a/Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift +++ b/Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift @@ -15,8 +15,7 @@ import XCTest /// sheet with its approval statements at its own size (a SwiftUI sheet can't /// be captured offscreen); and the approval panel through the production /// panel factory, with its footer before and after the send (#350, worded -/// as in #356). No -/// window is ordered in. Set +/// as in #356). No window is ordered in. Set /// `REMOTE_APPROVAL_RENDER_DIRECTORY` to keep the PNGs, and also /// `REMOTE_APPROVAL_WINDOW_RENDERS=1` on a desktop session to render the /// Devices section in the real Settings window, scrolled to it. diff --git a/Tests/AskKeyE2ETests/ScreenshotE2ETests.swift b/Tests/AskKeyE2ETests/ScreenshotE2ETests.swift index c6ba9df3..5ea1a414 100644 --- a/Tests/AskKeyE2ETests/ScreenshotE2ETests.swift +++ b/Tests/AskKeyE2ETests/ScreenshotE2ETests.swift @@ -150,6 +150,8 @@ final class ScreenshotE2ETests: E2EBaseCase { _ = try waitForEvidence("approval-pending.json") XCTAssertTrue(app.buttons["approval-deny"].waitForExistence(timeout: 8)) app.typeKey(XCUIKeyboardKey.escape.rawValue, modifierFlags: []) + // Esc closes the panel and leaves the request pending (#356). + XCTAssertTrue(app.buttons["approval-deny"].waitForNonExistence(timeout: 8), "Esc closed the approval panel") moveManagementAboveDock() click("unlock-management") click("sidebar-pending") diff --git a/docs/adr/0014-remote-approval.md b/docs/adr/0014-remote-approval.md index 010856b2..f2783443 100644 --- a/docs/adr/0014-remote-approval.md +++ b/docs/adr/0014-remote-approval.md @@ -450,7 +450,7 @@ The order and dependencies are in #344. Each task keeps all four CI jobs green, - Pruning when the app comes to the front as well as at launch and at every write, tested with a fake clock; "Saved to History." only after a write succeeded. - Acceptance cases: verified, app terminated, relaunched after the transport expiry gives one timed-out entry; a closed message and its request in one fetch give one entry and no card; a request with a reused record name from another Mac leaves the first entry unchanged; a Mac removed after one of its requests timed out keeps that entry. - Docs: the files of the iPhone history row in `docs/features.md` (and its status once built), the approved Chinese label in the request history row of `docs/glossary.md`, and the privacy pages' wording for History and **Clear All History** if the approved strings differ. -5. **[#350](https://github.com/sudoHG/AskKey/issues/350), the Mac card hint** (decision 6): `Sources/AskKeyAppKit/App/FrozenAgentApprovalPrompt.swift` (`footer` only), `Sources/AskKeyAppKit/App/RemoteApprovalPanelState.swift`, a read-only accessor in `Sources/AskKeyAppKit/Devices/DeviceCoordinator+Presentation.swift`, `Sources/AskKeyAppKit/App/AppDelegate+Approval.swift` only to pass the state in, `Sources/AskKeyAppKit/Resources/Localizable.xcstrings`, `Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift` and a unit test for the footer. From this amendment, beyond its issue's table, it picks up: the countdown form needs the request to be still eligible with at least one active approver below its 16-request limit, not only a send time ahead; the sent form needs a copy saved to an approver's inbox (the state behind Details' "Sent to") that is still outstanding; and the footer is unchanged while sealing, while a first send retries, when every approver is full and once every copy has closed. Its acceptance gains a case for each. +5. **[#350](https://github.com/sudoHG/AskKey/issues/350), the Mac card hint** (decision 6): `Sources/AskKeyAppKit/App/FrozenAgentApprovalPrompt.swift` (`footer` only), `Sources/AskKeyAppKit/App/RemoteApprovalPanelState.swift`, a read-only accessor in `Sources/AskKeyAppKit/Devices/DeviceCoordinator+Presentation.swift`, `Sources/AskKeyAppKit/App/AppDelegate+Approval.swift` only to pass the state in, `Sources/AskKeyAppKit/Resources/Localizable.xcstrings`, `Tests/AskKeyAppTests/RemoteApprovalRenderTests.swift` and a unit test for the footer. From this amendment, beyond its issue's table, it picks up: the countdown form needs the request to be still eligible with at least one active approver below its 16-request limit, not only a send time ahead; the sent form needs a copy saved to an approver's inbox (the state behind Details' "Sent to") that is still outstanding; and the footer shows only the expiry while sealing, while a first send retries, when every approver is full and once every copy has closed. Its acceptance gains a case for each. [#356](https://github.com/sudoHG/AskKey/issues/356) later replaced the footer's wording; see Mac card hint above. 6. **[#351](https://github.com/sudoHG/AskKey/issues/351), the welcome, key-reset and privacy cover screens**: `Views/WelcomeView.swift`, `Views/RootView.swift` (`UnusableIdentityContent`), `Views/PrivacyCover.swift`, the catalog and tests. The reset screen's statement that the reset deletes the history matches this amendment; the cover keeps covering every tab. This PR updates `SECURITY.md`, `docs/features.md`, `docs/glossary.md` and both privacy pages. The maintainer publishes the privacy pages only with the release that ships the history.