Skip to content

Commit 58b669e

Browse files
committed
test(macos): retain native Talk overlay race proof
1 parent 27ae3f1 commit 58b669e

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
# Opt-in, timed AppKit E2E; requires a logged-in macOS desktop and Developer ID.
3+
# Usage: bash apps/macos/Tests/Fixtures/TalkOverlay/run.sh '<Developer ID identity or SHA>'
4+
set -euo pipefail
5+
6+
identity="${1:?Pass the matching Developer ID Application signing identity or certificate SHA}"
7+
fixture_source="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
8+
repo_root="$(cd -- "$fixture_source/../../../../.." && pwd)"
9+
fixture_dir="$(mktemp -d /tmp/openclaw-talk-overlay.XXXXXX)"
10+
trap 'rm -rf -- "$fixture_dir"' EXIT
11+
bundle="$fixture_dir/TalkOverlayFixture.app"
12+
mkdir -p "$bundle/Contents/MacOS"
13+
cat > "$bundle/Contents/Info.plist" <<'PLIST'
14+
<?xml version="1.0" encoding="UTF-8"?>
15+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
16+
<plist version="1.0"><dict>
17+
<key>CFBundleIdentifier</key><string>ai.openclaw.talk-overlay-fixture</string>
18+
<key>CFBundleExecutable</key><string>TalkOverlayFixture</string>
19+
<key>CFBundlePackageType</key><string>APPL</string>
20+
<key>LSUIElement</key><true/>
21+
</dict></plist>
22+
PLIST
23+
24+
cd -- "$repo_root"
25+
sources=(
26+
apps/macos/Sources/OpenClaw/TalkOverlay.swift
27+
apps/macos/Sources/OpenClaw/OverlayPanelFactory.swift
28+
apps/macos/Tests/Fixtures/TalkOverlay/Fixture.swift
29+
)
30+
shasum -a 256 "${sources[@]}" apps/macos/Tests/Fixtures/TalkOverlay/run.sh
31+
binary="$bundle/Contents/MacOS/TalkOverlayFixture"
32+
xcrun swiftc -swift-version 6 -parse-as-library "${sources[@]}" -o "$binary"
33+
codesign --force --sign "$identity" --timestamp=none "$bundle"
34+
codesign --verify --strict "$bundle"
35+
codesign -dv --verbose=4 "$bundle" 2>&1 | awk '
36+
/^Authority=Developer ID Application:/ { found = 1 }
37+
END { if (!found) { print "Expected Developer ID Application signature"; exit 1 } }
38+
'
39+
printf 'fixture_binary_sha256=%s\n' "$(shasum -a 256 "$binary" | cut -d ' ' -f 1)"
40+
"$binary"

0 commit comments

Comments
 (0)