Paste's validation asks the pasteboard the route reads
Found by Task 21's check-native.sh: MacPasteRouteTests' two text pastes failed in the whole suite. NSTextView validates paste: against the general pasteboard, so with the person's clipboard holding no text the tests' ⌘V (on a private pasteboard) was disabled and never sent. The route now validates against the pasteboard it reads; in the app that is the general one, as before. The tests also wait for the field's text (up to 3 s) rather than a fixed 0.15 s. Gate: swift test -j 4 --filter 'MacPasteRouteTests|ComposerKeyTests': 18 passed, twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fix: Paste validation follows the route's pasteboard
2 files changed,
+15
−0
native/apple/Sources/BaseKit/Mac/MacPasteRoute.swift+5 −0native/apple/Tests/BaseKitTests/MacPasteRouteTests.swift+10 −0
CI failed — run details
CI log
=== build === CGO_ENABLED=0 go build ./... === vet === go vet ./... === fmt-check === === staticcheck === go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./... === govulncheck === go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./... No vulnerabilities found. === gitleaks === [90m10:49PM[0m [32mINF[0m [1mUnknown SCM platform. Use --platform to include links in findings.[0m [36mhost=[0mamadan.net [90m10:49PM[0m [32mINF[0m [1m1 commits scanned.[0m [90m10:49PM[0m [32mINF[0m [1mscanned ~3145344 bytes (3.15 MB) in 380ms[0m [90m10:49PM[0m [33mWRN[0m [1mleaks found: 1[0m exit status 1 make: *** [Makefile:71: gitleaks] Error 1 amadan: step gitleaks failed: exit status 2 amadan: job failed at step gitleaks — its output is above, not at the tail of this log
diff --git a/native/apple/Sources/BaseKit/Mac/MacPasteRoute.swift b/native/apple/Sources/BaseKit/Mac/MacPasteRoute.swift| index 9566c68..4781267 100644 |
| --- a/native/apple/Sources/BaseKit/Mac/MacPasteRoute.swift |
| +++ b/native/apple/Sources/BaseKit/Mac/MacPasteRoute.swift |
| @@ -73,6 +73,11 @@ import AppKit |
| // As AppKit would for paste:: the responder that would take it says. |
| guard let responder = window()?.firstResponder, |
| let target = NSApp.target(forAction: #selector(NSText.paste(_:)), to: responder, from: item) else { return false } |
| + // A text view validates paste: against the general pasteboard; with |
| + // another (a test's) it is asked of that one. |
| + if pasteboard !== NSPasteboard.general, let editor = target as? NSTextView { |
| + return pasteboard.availableType(from: editor.readablePasteboardTypes) != nil |
| + } |
| let standIn = NSMenuItem(title: item.title, action: #selector(NSText.paste(_:)), keyEquivalent: "") |
| return (target as? NSMenuItemValidation)?.validateMenuItem(standIn) ?? true |
| } |
diff --git a/native/apple/Tests/BaseKitTests/MacPasteRouteTests.swift b/native/apple/Tests/BaseKitTests/MacPasteRouteTests.swift| index a40634f..5d42f7e 100644 |
| --- a/native/apple/Tests/BaseKitTests/MacPasteRouteTests.swift |
| +++ b/native/apple/Tests/BaseKitTests/MacPasteRouteTests.swift |
| @@ -55,6 +55,13 @@ import XCTest |
| private func settle(_ seconds: Double = 0.15) { RunLoop.main.run(until: Date().addingTimeInterval(seconds)) } |
| + /// Spins the run loop until `condition`, for at most three seconds: the |
| + /// field reaches its binding a turn or two later, longer under load. |
| + private func eventually(_ condition: () -> Bool) { |
| + let deadline = Date().addingTimeInterval(3) |
| + while !condition(), Date() < deadline { settle(0.05) } |
| + } |
| + |
| /// ⌘V as the keyboard sends it: the window's views, then the main menu. |
| private func commandV(_ window: NSWindow) throws { |
| route.window = { window } |
| @@ -86,6 +93,7 @@ import XCTest |
| let window = try composer(m, attaching: true) |
| board.clearContents(); board.setData(png(), forType: .png) |
| try commandV(window) |
| + eventually { m.attachments.items.count == 1 } |
| XCTAssertEqual(m.attachments.items.count, 1) |
| XCTAssertEqual(m.text, "") |
| } |
| @@ -100,6 +108,7 @@ import XCTest |
| board.setString("The flour comes Thursday", forType: .string) |
| board.setData(png(), forType: .tiff) |
| try commandV(window) |
| + eventually { m.text == "The **flour** comes *Thursday*" } |
| XCTAssertEqual(m.text, "The **flour** comes *Thursday*") |
| XCTAssertTrue(m.attachments.items.isEmpty) |
| } |
| @@ -111,6 +120,7 @@ import XCTest |
| board.setData(png(), forType: .png) |
| board.setString("panel words", forType: .string) |
| try commandV(window) |
| + eventually { m.text == "panel words" } |
| XCTAssertEqual(m.text, "panel words") |
| XCTAssertTrue(m.attachments.items.isEmpty, "the menu panel's composer never attaches") |
| } |