|
| 1 | +import AppKit |
| 2 | +import SwiftUI |
| 3 | + |
| 4 | +/// Compile the real controller and factory without loading app state or microphone services. |
| 5 | +enum TalkModePhase: String { |
| 6 | + case idle, listening, thinking, speaking |
| 7 | +} |
| 8 | + |
| 9 | +struct TalkOverlayView: View { |
| 10 | + var controller: TalkOverlayController |
| 11 | + var body: some View { |
| 12 | + Text("Synthetic Talk overlay proof").padding().background(.blue) |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +@MainActor |
| 17 | +private final class FixtureDelegate: NSObject, NSApplicationDelegate { |
| 18 | + func applicationDidFinishLaunching(_: Notification) { |
| 19 | + Task { @MainActor in |
| 20 | + do { |
| 21 | + var failures = 0 |
| 22 | + for delay in [0, 40, 120] { |
| 23 | + let controller = TalkOverlayController() |
| 24 | + controller.present() |
| 25 | + guard let panel = NSApplication.shared.windows.first(where: { |
| 26 | + ($0.contentView as? NSHostingView<TalkOverlayView>)?.rootView.controller === controller |
| 27 | + }) else { |
| 28 | + print("FAIL missing Talk panel") |
| 29 | + exit(2) |
| 30 | + } |
| 31 | + // Timed end-to-end observations with the normal AppKit run loop, not a completion hook. |
| 32 | + try await Task.sleep(for: .milliseconds(240)) |
| 33 | + controller.dismiss() |
| 34 | + if delay > 0 { try await Task.sleep(for: .milliseconds(delay)) } |
| 35 | + controller.present() |
| 36 | + try await Task.sleep(for: .milliseconds(450)) |
| 37 | + let shown = controller.model.isVisible && panel.isVisible && panel.alphaValue == 1 |
| 38 | + print("reopen delay_ms=\(delay) model=\(controller.model.isVisible) " + |
| 39 | + "panel=\(panel.isVisible) alpha=\(panel.alphaValue) pass=\(shown)") |
| 40 | + if !shown { failures += 1 } |
| 41 | + |
| 42 | + controller.dismiss() |
| 43 | + try await Task.sleep(for: .milliseconds(250)) |
| 44 | + let hidden = !controller.model.isVisible && !panel.isVisible |
| 45 | + print("dismiss model=\(controller.model.isVisible) panel=\(panel.isVisible) pass=\(hidden)") |
| 46 | + if !hidden { failures += 1 } |
| 47 | + panel.orderOut(nil) |
| 48 | + } |
| 49 | + print("RESULT failures=\(failures)") |
| 50 | + fflush(stdout) |
| 51 | + exit(failures == 0 ? 0 : 1) |
| 52 | + } catch { |
| 53 | + print("FAIL fixture interrupted: \(error)") |
| 54 | + exit(2) |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +@main |
| 61 | +private struct TalkOverlayFixture { |
| 62 | + @MainActor static func main() { |
| 63 | + let app = NSApplication.shared |
| 64 | + guard !NSScreen.screens.isEmpty else { |
| 65 | + print("FAIL Talk overlay fixture requires a logged-in macOS desktop") |
| 66 | + exit(2) |
| 67 | + } |
| 68 | + app.setActivationPolicy(.accessory) |
| 69 | + let delegate = FixtureDelegate() |
| 70 | + app.delegate = delegate |
| 71 | + withExtendedLifetime(delegate) { app.run() } |
| 72 | + } |
| 73 | +} |
0 commit comments