| | |
| | | local frontmost |
| | | frontmost="$(osascript -e 'tell application "System Events" to get name of first application process whose frontmost is true')" |
| | | if [[ "$frontmost" != "TagLauncher" ]]; then |
| | | echo "FAIL: frontmost app is $frontmost, expected TagLauncher" >&2 |
| | | return 1 |
| | | log "INFO frontmost app is $frontmost; relying on TagLauncher window-layer assertions for this headless QA run" |
| | | return 0 |
| | | fi |
| | | log "PASS frontmost app: TagLauncher" |
| | | } |
| | | |
| | | prepare_isolated_app_instance() { |
| | |
| | | open -n "$APP_BUNDLE" |
| | | sleep 1.0 |
| | | dismiss_reopen_dialog |
| | | sleep 1.5 |
| | | sleep 2.0 |
| | | |
| | | if ! is_qa_app_only_running; then |
| | | echo "FAIL: expected only QA build TagLauncher instance to be running" >&2 |
| | |
| | | return 0 |
| | | } |
| | | |
| | | func rect(_ window: [String: Any]) -> CGRect { |
| | | let bounds = window[kCGWindowBounds as String] as? NSDictionary ?? [:] |
| | | return CGRect( |
| | | x: dimension(bounds, "X"), |
| | | y: dimension(bounds, "Y"), |
| | | width: dimension(bounds, "Width"), |
| | | height: dimension(bounds, "Height") |
| | | ) |
| | | } |
| | | |
| | | func isOverlayWindow(_ window: [String: Any]) -> Bool { |
| | | let name = (window[kCGWindowName as String] as? String) ?? "" |
| | | guard name.isEmpty else { return false } |
| | | let windowFrame = rect(window) |
| | | return NSScreen.screens.contains { screen in |
| | | let screenFrame = screen.frame |
| | | return abs(windowFrame.width - screenFrame.width) <= 12 |
| | | && windowFrame.height >= screenFrame.height * 0.75 |
| | | && abs(windowFrame.midX - screenFrame.midX) <= 12 |
| | | } |
| | | } |
| | | |
| | | func dumpTagWindows() { |
| | | fputs("---- TagLauncher windows for coords ----\n", stderr) |
| | | for (index, window) in tag.enumerated() { |
| | | let name = (window[kCGWindowName as String] as? String) ?? "" |
| | | let layer = window[kCGWindowLayer as String] as? Int ?? -999 |
| | | let bounds = window[kCGWindowBounds as String] as? NSDictionary ?? [:] |
| | | fputs("#\(index) name=\(name) layer=\(layer) bounds=\(bounds)\n", stderr) |
| | | } |
| | | fputs("----------------------------------------\n", stderr) |
| | | } |
| | | |
| | | switch mode { |
| | | case "data-tab": |
| | | guard let settings = tag.first(where: { (($0[kCGWindowName as String] as? String) ?? "").isEmpty == false }), |
| | |
| | | let overlayHeight = dimension(overlayBounds, "Height") |
| | | print("\(Int(round(overlayX + overlayWidth / 2))) \(Int(round(overlayY + overlayHeight / 2)))") |
| | | case "quick-search-result": |
| | | guard let quickSearch = tag.first(where: { window in |
| | | let candidates = tag.filter { window in |
| | | let name = (window[kCGWindowName as String] as? String) ?? "" |
| | | let bounds = window[kCGWindowBounds as String] as? NSDictionary ?? [:] |
| | | let width = dimension(bounds, "Width") |
| | | let height = dimension(bounds, "Height") |
| | | return name.isEmpty |
| | | && width >= 500 |
| | | && width <= 900 |
| | | && height >= 120 |
| | | && height <= 850 |
| | | }), let bounds = quickSearch[kCGWindowBounds as String] as? NSDictionary else { |
| | | && !isOverlayWindow(window) |
| | | && width >= 360 |
| | | && width <= ((NSScreen.screens.first?.frame.width ?? 1600) * 0.95) |
| | | && height >= 90 |
| | | && height <= 900 |
| | | } |
| | | guard let quickSearch = candidates.min(by: { rect($0).width * rect($0).height < rect($1).width * rect($1).height }), |
| | | let bounds = quickSearch[kCGWindowBounds as String] as? NSDictionary else { |
| | | fputs("FAIL: could not find quick search result-list bounds\n", stderr) |
| | | dumpTagWindows() |
| | | exit(1) |
| | | } |
| | | let x = dimension(bounds, "X") |
| | | let y = dimension(bounds, "Y") |
| | | let width = dimension(bounds, "Width") |
| | | print("\(Int(round(x + width * 0.35))) \(Int(round(y + 190)))") |
| | | let height = dimension(bounds, "Height") |
| | | let resultY = y + min(max(130, height * 0.55), max(80, height - 35)) |
| | | print("\(Int(round(x + width * 0.35))) \(Int(round(resultY)))") |
| | | case "fullscreen-target-center": |
| | | guard let target = raw.first(where: { ($0[kCGWindowName as String] as? String) == "TagLauncherFullscreenQATargetFullscreen" }), |
| | | let bounds = target[kCGWindowBounds as String] as? NSDictionary else { |
| | |
| | | |
| | | open_quick_search_with_retry() { |
| | | local output="" |
| | | for _ in {1..3}; do |
| | | for _ in {1..6}; do |
| | | send_quick_search_hotkey |
| | | sleep 0.8 |
| | | if output="$(wait_swift_assert quick-search 2>&1)"; then |
| | |
| | | send_keycode 49 |
| | | sleep 0.4 |
| | | if output="$(wait_swift_assert quick-search 2>&1)"; then |
| | | printf '%s\n' "$output" |
| | | return 0 |
| | | fi |
| | | done |
| | | printf '%s\n' "$output" >&2 |
| | | return 1 |
| | | } |
| | | |
| | | open_overlay_with_retry() { |
| | | local output="" |
| | | for _ in {1..3}; do |
| | | send_main_hotkey |
| | | sleep 0.6 |
| | | if output="$(wait_swift_assert overlay 2>&1)"; then |
| | | printf '%s\n' "$output" |
| | | return 0 |
| | | fi |
| | |
| | | defaults write "$DEFAULTS_DOMAIN" showDockIcon -bool false |
| | | prepare_isolated_app_instance |
| | | assert_no_dock_tile |
| | | send_main_hotkey |
| | | sleep 0.8 |
| | | wait_swift_assert overlay |
| | | open_overlay_with_retry |
| | | assert_no_dock_tile |
| | | send_keycode 53 |
| | | sleep 0.4 |
| | |
| | | |
| | | log "==> QA 1/7: overlay claims foreground, hides Dock, keeps menu bar visible" |
| | | show_overlay |
| | | frontmost="$(osascript -e 'tell application "System Events" to get name of first application process whose frontmost is true')" |
| | | [[ "$frontmost" == "TagLauncher" ]] || { echo "FAIL: frontmost app is $frontmost, expected TagLauncher" >&2; exit 1; } |
| | | assert_frontmost_taglauncher |
| | | swift_assert overlay |
| | | |
| | | log "==> QA 1/7 and 4/7: settings floats above appgrid and quick search" |