Skip to content

Doubao-powered voice input for Linux, Wayland and Omarchy

test: 增加原生侧栏焦点回归检查产物

quanru8350a5bcfa9a
diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml
index a2b33f8..c29db18 100644
--- a/.github/workflows/macos.yml
+++ b/.github/workflows/macos.yml
@@ -23,10 +23,15 @@ jobs:
run: bash macos/check.sh
- name: Build development application
run: bash macos/build.sh
+ - name: Build opt-in sidebar focus probe
+ run: bash macos/Tests/Settings/build-sidebar-focus.sh
- name: Archive preview (development signing only)
run: |
ditto -c -k --sequesterRsrc --keepParent "build/macos/$(uname -m)/Doubao Say.app" build/Doubao-Say-macos-preview.zip
+ ditto -c -k build/macos/tests/sidebar-focus-check build/Sidebar-Focus-Check.zip
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: Doubao-Say-macos-development-preview
- path: build/Doubao-Say-macos-preview.zip
+ path: |
+ build/Doubao-Say-macos-preview.zip
+ build/Sidebar-Focus-Check.zip
diff --git a/macos/Tests/Settings/README.md b/macos/Tests/Settings/README.md
new file mode 100644
index 0000000..d089cc1
--- /dev/null
+++ b/macos/Tests/Settings/README.md
@@ -0,0 +1,28 @@
+# Native sidebar focus regression probe
+
+`SidebarFocusCheck.swift` opens the real SettingsWindow with synthetic state in a
+SwiftUI application. It never signs in, records audio, saves credentials or
+posts events to another application. Its only key/mouse events go through its own
+NSApplication. Each invocation exits after capturing the window or fails within
+ten seconds.
+
+Build with `bash macos/Tests/Settings/build-sidebar-focus.sh` under the local heavy
+resource gate. The macOS preview CI also includes a compiled probe in
+`Sidebar-Focus-Check.zip`, allowing local runtime verification without rebuilding.
+This probe is opt-in and is not executed by normal unit tests or shipped in DMGs.
+
+Run it from an isolated ad-hoc signed .app bundle with a unique CFBundleIdentifier
+and a separate preferences profile, under a runtime resource slot. The operator
+must enable macOS keyboard navigation for the scenario and restore its original
+state afterward; the probe does not modify that system preference itself. Do not
+run it against a production bundle ID. It prints `CAPTURE_WINDOW:<number>` for the
+existing external window capture mechanism.
+
+Set `DOUBAO_FOCUS_CASE` to `opened`, `external`, `keyboard`, `activate`, `mouse` or
+`reopen`, and pass `-language en` or `-language zh`. Assertions check that opening,
+external navigation, mouse navigation and reopening clear sidebar focus; Tab
+focuses a control without activating it; and Tab/Space selects Recognition while
+retaining keyboard focus. `DOUBAO_FOCUS_ASSERT=0` disables assertions for a failing
+baseline capture only. Inspect both languages and compare equivalent before/after
+screenshots following DEVELOPMENT.md. Verify VoiceOver and older macOS versions
+separately; a synthetic focus probe does not prove voice input or physical hotkeys.
diff --git a/macos/Tests/Settings/SidebarFocusCheck.swift b/macos/Tests/Settings/SidebarFocusCheck.swift
new file mode 100644
index 0000000..1bb4667
--- /dev/null
+++ b/macos/Tests/Settings/SidebarFocusCheck.swift
@@ -0,0 +1,58 @@
+// Opt-in native UI regression probe. Synthetic state; events target only this app.
+import AppKit
+import SwiftUI
+@main struct SidebarFocusCheck: App {
+ @NSApplicationDelegateAdaptor(SidebarFocusDelegate.self) var delegate
+ var body: some Scene { Settings { EmptyView() } }
+}
+@MainActor final class SidebarFocusDelegate: NSObject, NSApplicationDelegate {
+ private var settings: SettingsWindow?
+ private func key(_ native: NSWindow, _ code: UInt16, _ characters: String) {
+ for type: NSEvent.EventType in [.keyDown, .keyUp] {
+ if let event = NSEvent.keyEvent(with: type, location: .zero, modifierFlags: [], timestamp: ProcessInfo.processInfo.systemUptime, windowNumber: native.windowNumber, context: nil, characters: characters, charactersIgnoringModifiers: characters, isARepeat: false, keyCode: code) { NSApp.sendEvent(event) }
+ }
+ }
+ func applicationDidFinishLaunching(_ notification: Notification) {
+ NSApp.setActivationPolicy(.regular)
+ let state = AppState()
+ let window = SettingsWindow(state: state)
+ settings = window
+ window.model.apply = { _, _, _ in }
+ window.show(refresh: false)
+ let mode = ProcessInfo.processInfo.environment["DOUBAO_FOCUS_CASE"] ?? "opened"
+ let check = ProcessInfo.processInfo.environment["DOUBAO_FOCUS_ASSERT"] != "0"
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
+ guard let native = NSApp.windows.first else { fatalError("Missing settings window") }
+ NSApp.activate(ignoringOtherApps: true)
+ native.makeKeyAndOrderFront(nil)
+ precondition(NSApp.isFullKeyboardAccessEnabled, "This opt-in check requires keyboard navigation enabled")
+ if mode == "external" { window.model.selectedTab = "updates" }
+ if ["keyboard", "activate", "mouse", "reopen"].contains(mode) {
+ self.key(native, 48, "\t")
+ if mode == "activate" { self.key(native, 48, "\t"); self.key(native, 49, " ") }
+ if mode == "mouse" {
+ let target = NSPoint(x: 80, y: 650 - 128)
+ for type: NSEvent.EventType in [.leftMouseDown, .leftMouseUp] {
+ if let event = NSEvent.mouseEvent(with: type, location: target, modifierFlags: [], timestamp: ProcessInfo.processInfo.systemUptime, windowNumber: native.windowNumber, context: nil, eventNumber: 0, clickCount: 1, pressure: 1) { NSApp.sendEvent(event) }
+ }
+ }
+ if mode == "reopen" { window.hide(); window.show(refresh: false) }
+ }
+ }
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
+ guard let native = NSApp.windows.first else { fatalError("Missing settings window") }
+ let view = native.firstResponder as? NSView
+ print("FOCUS: \(String(describing: native.firstResponder)) FRAME: \(String(describing: view?.frame)) PAGE: \(window.model.selectedTab)")
+ if check {
+ if ["opened", "external", "mouse", "reopen"].contains(mode) { precondition(view == nil, "Stale sidebar focus remains in \(mode)") }
+ if mode == "keyboard" { precondition(view != nil && window.model.selectedTab == "setup", "Tab must focus without activating") }
+ if mode == "activate" { precondition(view != nil && window.model.selectedTab == "recognition", "Tab/Space must activate and retain keyboard focus") }
+ if mode == "mouse" { precondition(window.model.selectedTab == "recognition", "Mouse must navigate to recognition") }
+ }
+ print("PASS_INTERACTION: \(mode)")
+ window.captureImage(to: "synthetic")
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { window.close(); NSApp.terminate(nil) }
+ }
+ DispatchQueue.main.asyncAfter(deadline: .now() + 10) { fatalError("Fixture deadline exceeded") }
+ }
+}
diff --git a/macos/Tests/Settings/build-sidebar-focus.sh b/macos/Tests/Settings/build-sidebar-focus.sh
new file mode 100644
index 0000000..7514223
--- /dev/null
+++ b/macos/Tests/Settings/build-sidebar-focus.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+set -euo pipefail
+cd "$(dirname "$0")/../../.."
+mkdir -p build/macos/tests
+sources=()
+for source in macos/Sources/*.swift; do
+ [[ "$source" == *DoubaoSayApp.swift ]] || sources+=("$source")
+done
+xcrun swiftc -swift-version 5 -target "$(uname -m)-apple-macos13.0" \
+ -module-cache-path build/macos/module-cache \
+ "${sources[@]}" macos/Tests/Settings/SidebarFocusCheck.swift -o build/macos/tests/sidebar-focus-check