oficina / docs Public

Docs native S2a: the header spike and the smoke test for the new window

native/smoke/document-window gains HeaderSpike (DOCS_SMOKE_SPIKE=1), the
spec §1 six-item checklist run on the real document window, and the smoke
test now toggles the floating inspector with View ▸ Hide/Show Format and
checks the page slides while the editor's space stays put.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 65902c980ef53d380ce7538b873a03c8a9b1ccbd parent 8d5ace3
2 files changed, +230 −9
  • native/smoke/document-window/Sources/HeaderSpike.swift +197 −0
  • native/smoke/document-window/Sources/Smoke.swift +33 −9
diff --git a/native/smoke/document-window/Sources/HeaderSpike.swift b/native/smoke/document-window/Sources/HeaderSpike.swift
new file mode 100644
index 0000000..df9d203
--- /dev/null
+++ b/native/smoke/document-window/Sources/HeaderSpike.swift
@@ -0,0 +1,197 @@
+import AppKit
+import SwiftUI
+
+/// The S2a header spike (spec 2026-11-22 §1, "Spike checklist"), run on the
+/// real document window: Docs' own title area at the toolbar's leading edge,
+/// the system title hidden but still set. Each item prints PASS, FAIL or
+/// UNVERIFIED with what was measured; the run never stops on a FAIL, so the
+/// whole checklist is reported at once. `DOCS_SMOKE_SPIKE=1` runs it.
+@MainActor enum HeaderSpike {
+ static func run(_ window: NSWindow, title: String) async {
+ print("SPIKE: macOS \(ProcessInfo.processInfo.operatingSystemVersionString)")
+ // 0. One title: the window's is the document's, hidden, and no
+ // principal (centred) item draws it again.
+ report("window title is the document title", window.title == title, "title=\(window.title)")
+ report("system title hidden", window.titleVisibility == .hidden, "titleVisibility=\(window.titleVisibility.rawValue)")
+ let toolbar = window.toolbar
+ report("no centred (.principal) item", toolbar?.centeredItemIdentifiers.isEmpty ?? true,
+ "centred=\(toolbar?.centeredItemIdentifiers.map(\.rawValue) ?? [])")
+ let titles = staticTexts(in: window, matching: title)
+ // In process, SwiftUI builds the toolbar's accessibility tree only for
+ // a running assistive technology: zero found means "not measured".
+ if titles.isEmpty { print("SPIKE UNVERIFIED: exactly one visible title — no accessibility tree in process; see the window capture") }
+ else { report("exactly one visible title", titles.count == 1, "static texts reading the title: \(titles.count)") }
+
+ // 6. VoiceOver: the window's name is the title; the title area reads
+ // the title, then the subtitle.
+ report("VoiceOver window name", window.accessibilityTitle() == title, "accessibilityTitle=\(window.accessibilityTitle() ?? "nil")")
+ let order = toolbarTexts(window)
+ print("SPIKE: toolbar accessibility texts in order: \(order)")
+ if let at = order.firstIndex(of: title) {
+ report("VoiceOver reads title then subtitle", order.count > at + 1 && order[at + 1].contains("·") || (order.count > at + 1 && !order[at + 1].isEmpty),
+ "after the title: \(order.count > at + 1 ? order[at + 1] : "nothing")")
+ } else { print("SPIKE UNVERIFIED: VoiceOver reads title then subtitle — no accessibility tree in process (needs VoiceOver on a real Mac)") }
+
+ // 5. Window tabs: the tab shows the document title.
+ report("window tab title", window.tab.title == title, "tab.title=\(window.tab.title)")
+
+ // 3. Overflow at narrow widths: the title area stays; trailing
+ // controls go into the » menu.
+ let original = window.frame
+ for width in [1120.0, 760, 560, 420] {
+ window.setContentSize(NSSize(width: width, height: 700))
+ try? await Task.sleep(for: .milliseconds(400))
+ let all = toolbar?.items.map(\.itemIdentifier.rawValue) ?? []
+ let visible = toolbar?.visibleItems?.map(\.itemIdentifier.rawValue) ?? []
+ let titleShown = window.toolbar?.visibleItems?.first?.itemIdentifier == window.toolbar?.items.first?.itemIdentifier
+ print("SPIKE: width \(Int(width)): items=\(all) visible=\(visible) titleShown=\(titleShown)")
+ }
+ window.setFrame(original, display: true)
+ try? await Task.sleep(for: .milliseconds(400))
+
+ // 2. Double-click on the title area renames.
+ if let frame = titleFrame(window, title) {
+ let point = NSPoint(x: frame.midX, y: frame.midY)
+ click(window, at: point, count: 2)
+ try? await Task.sleep(for: .milliseconds(400))
+ let field = editableField(window.contentView?.superview)
+ let editing = (window.firstResponder as? NSTextView)?.isFieldEditor == true
+ report("the rename field has the keyboard focus", editing, "firstResponder=\(String(describing: window.firstResponder.map { type(of: $0) }))")
+ report("double-click on the title renames", field != nil, "editable field: \(field.map { String(describing: type(of: $0)) } ?? "none")")
+ // Leave the rename as it was: Esc.
+ // Esc leaves the rename as it was (onExitCommand).
+ if field != nil, let esc = NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: [], timestamp: ProcessInfo.processInfo.systemUptime,
+ windowNumber: window.windowNumber, context: nil, characters: "\u{1b}", charactersIgnoringModifiers: "\u{1b}", isARepeat: false, keyCode: 53) {
+ window.sendEvent(esc)
+ }
+ try? await Task.sleep(for: .milliseconds(400))
+ report("Esc leaves the rename", editableField(window.contentView?.superview) == nil, "field after Esc: \(editableField(window.contentView?.superview) == nil ? "gone" : "still there")")
+ dump(window.toolbar?.items.first?.view, depth: 0)
+ print("SPIKE: in-process NSAccessibility exposes SwiftUI toolbar text only while an assistive technology is running, so VoiceOver's reading order is not measured here")
+
+ // 1. Drag by the title area: a mouse-down there may move the window.
+ let hit = window.contentView?.superview?.hitTest(window.contentView!.superview!.convert(point, from: nil))
+ var chain: [String] = []
+ var view = hit
+ var movable = false
+ while let v = view { chain.append("\(type(of: v)):\(v.mouseDownCanMoveWindow)"); if v.mouseDownCanMoveWindow { movable = true }; view = v.superview }
+ print("SPIKE: hit chain at the title: \(chain.prefix(6))")
+ report("title area can drag the window (mouseDownCanMoveWindow on the hit view)", hit?.mouseDownCanMoveWindow == true, "hit=\(hit.map { String(describing: type(of: $0)) } ?? "nil")")
+ // A real drag, posted as events: AppKit may run the drag through the
+ // window server, which reads the real cursor, so a non-move here is
+ // UNVERIFIED rather than FAIL.
+ let start = window.frame.origin
+ let screenPoint = window.convertPoint(toScreen: point)
+ func post(_ type: NSEvent.EventType, _ dx: CGFloat) {
+ let p = window.convertPoint(fromScreen: NSPoint(x: screenPoint.x + dx, y: screenPoint.y))
+ if let event = NSEvent.mouseEvent(with: type, location: p, modifierFlags: [], timestamp: ProcessInfo.processInfo.systemUptime,
+ windowNumber: window.windowNumber, context: nil, eventNumber: 0, clickCount: 1, pressure: 1) {
+ NSApp.postEvent(event, atStart: false)
+ }
+ }
+ post(.leftMouseDown, 0); for dx in stride(from: 10.0, through: 80, by: 10) { post(.leftMouseDragged, dx) }; post(.leftMouseUp, 80)
+ try? await Task.sleep(for: .milliseconds(800))
+ print("SPIKE \(window.frame.origin != start ? "PASS" : "UNVERIFIED"): posted drag on the title moves the window — \(start) -> \(window.frame.origin)")
+ if window.frame.origin != start { window.setFrameOrigin(start) }
+ _ = movable
+ } else { report("title area found", false, "no accessibility frame for the title") }
+
+ // 2b. Double-click on empty toolbar space still zooms or minimises.
+ let action = UserDefaults.standard.string(forKey: "AppleActionOnDoubleClick") ?? "Maximize"
+ if let frame = titleFrame(window, title) {
+ let empty = NSPoint(x: (frame.maxX + window.frame.width * 0.55) / 2, y: frame.midY)
+ let before = window.frame
+ click(window, at: empty, count: 2)
+ try? await Task.sleep(for: .milliseconds(900))
+ let changed = window.frame != before || window.isMiniaturized
+ report("double-click on empty toolbar (\(action))", changed || action == "None", "frame \(before) -> \(window.frame), miniaturised=\(window.isMiniaturized)")
+ if window.isMiniaturized { window.deminiaturize(nil); try? await Task.sleep(for: .milliseconds(900)) }
+ if window.frame != before { window.setFrame(before, display: true) }
+ }
+
+ // 4. Full screen: the title area and controls stay in the toolbar.
+ window.toggleFullScreen(nil)
+ try? await Task.sleep(for: .seconds(2))
+ let full = window.styleMask.contains(.fullScreen)
+ let titleInFull = window.toolbar?.visibleItems?.first?.view?.window != nil
+ report("full screen keeps the title area", full && titleInFull && window.title == title, "fullScreen=\(full) titleShown=\(titleInFull)")
+ if full { window.toggleFullScreen(nil); try? await Task.sleep(for: .seconds(2)) }
+ }
+
+ static func dump(_ view: NSView?, depth: Int) {
+ guard let view, depth < 12 else { return }
+ let ax = AX(object: view)
+ print("SPIKE AX \(String(repeating: " ", count: depth))\(type(of: view)) role=\(ax.role?.rawValue ?? "-") text=\(ax.text) children=\(ax.children.count)")
+ for child in ax.children where !(child.object is NSView) {
+ print("SPIKE AX \(String(repeating: " ", count: depth + 1))[element] role=\(child.role?.rawValue ?? "-") text=\(child.text) children=\(child.children.map { ($0.role?.rawValue ?? "-") + ":" + $0.text })")
+ }
+ for sub in view.subviews { dump(sub, depth: depth + 1) }
+ }
+ static func report(_ item: String, _ passed: Bool, _ detail: String) {
+ print("SPIKE \(passed ? "PASS" : "FAIL"): \(item) — \(detail)")
+ }
+
+ struct AX {
+ let object: AnyObject
+ var role: NSAccessibility.Role? { object.accessibilityRole?() }
+ var text: String {
+ if let element = object as? NSObject & NSAccessibilityProtocol, let value = element.accessibilityValue() as? String, !value.isEmpty { return value }
+ return (object as? NSObject & NSAccessibilityProtocol)?.accessibilityLabel() ?? object.accessibilityLabel?() ?? ""
+ }
+ var frame: NSRect { object.accessibilityFrame?() ?? .zero }
+ var children: [AX] { (object.accessibilityChildren?() ?? []).map { AX(object: $0 as AnyObject) } }
+ var hidden: Bool { (object as? NSView)?.isHiddenOrHasHiddenAncestor ?? false }
+ }
+ static func all(_ window: NSWindow) -> [AX] {
+ var found: [AX] = []
+ func walk(_ element: AX, depth: Int) {
+ guard depth < 40 else { return }
+ found.append(element)
+ for child in element.children { walk(child, depth: depth + 1) }
+ }
+ walk(AX(object: window), depth: 0)
+ // SwiftUI's toolbar items are their own hosting views, outside the
+ // content view's tree: walk them too.
+ for item in window.toolbar?.items ?? [] { if let view = item.view { walk(AX(object: view), depth: 0) } }
+ return found
+ }
+
+ /// Every accessibility static text in the window that reads `text`.
+ static func staticTexts(in window: NSWindow, matching text: String) -> [AX] {
+ all(window).filter { $0.role == .staticText && $0.text == text && !$0.hidden }
+ }
+
+ /// The static texts in the toolbar's band, in accessibility order.
+ static func toolbarTexts(_ window: NSWindow) -> [String] {
+ let top = window.frame.maxY - 60
+ return all(window).filter { $0.role == .staticText && $0.frame.minY >= top && !$0.text.isEmpty }.map(\.text)
+ }
+
+ /// The title's frame in window coordinates: the accessibility element's,
+ /// or the upper half of the leading (navigation) toolbar item's view.
+ static func titleFrame(_ window: NSWindow, _ title: String) -> NSRect? {
+ if let element = staticTexts(in: window, matching: title).first, element.frame != .zero {
+ return window.convertFromScreen(element.frame)
+ }
+ guard let view = window.toolbar?.items.first?.view, view.window != nil else { return nil }
+ let frame = view.convert(view.bounds, to: nil)
+ return NSRect(x: frame.minX, y: frame.midY, width: min(frame.width, 160), height: frame.height / 2)
+ }
+
+ static func click(_ window: NSWindow, at point: NSPoint, count: Int) {
+ for n in 1...count {
+ for type in [NSEvent.EventType.leftMouseDown, .leftMouseUp] {
+ if let event = NSEvent.mouseEvent(with: type, location: point, modifierFlags: [], timestamp: ProcessInfo.processInfo.systemUptime,
+ windowNumber: window.windowNumber, context: nil, eventNumber: 0, clickCount: n, pressure: 1) {
+ window.sendEvent(event)
+ }
+ }
+ }
+ }
+
+ static func editableField(_ view: NSView?) -> NSTextField? {
+ guard let view else { return nil }
+ if let field = view as? NSTextField, field.isEditable, !field.isHiddenOrHasHiddenAncestor { return field }
+ return view.subviews.lazy.compactMap(editableField).first
+ }
+}
diff --git a/native/smoke/document-window/Sources/Smoke.swift b/native/smoke/document-window/Sources/Smoke.swift
index 15d3cda..0ca442d 100644
--- a/native/smoke/document-window/Sources/Smoke.swift
+++ b/native/smoke/document-window/Sources/Smoke.swift
@@ -26,6 +26,9 @@ private struct Launcher: View {
.task {
guard !SmokeRun.started else { return }
SmokeRun.started = true
+ setlinebuf(stdout)
+ // The Format inspector's app-wide state starts at its default.
+ UserDefaults.standard.removeObject(forKey: "docs.inspector.open")
NSApp.setActivationPolicy(.regular)
openWindow(id: "document", value: "fixture")
if ProcessInfo.processInfo.environment["DOCS_SMOKE_DRAFT"] == "1" {
@@ -79,24 +82,45 @@ private struct Launcher: View {
@MainActor private func exercise(_ window: NSWindow, editor: NSTextView) async {
NSApp.activate(ignoringOtherApps: true)
window.makeKeyAndOrderFront(nil)
+ if ProcessInfo.processInfo.environment["DOCS_SMOKE_SPIKE"] == "1" {
+ try? await Task.sleep(for: .milliseconds(800))
+ await HeaderSpike.run(window, title: window.title)
+ if let path = ProcessInfo.processInfo.environment["DOCS_SMOKE_WINDOW_SHOT"] {
+ if let frame = window.contentView?.superview, let bitmap = frame.bitmapImageRepForCachingDisplay(in: frame.bounds) {
+ frame.cacheDisplay(in: frame.bounds, to: bitmap)
+ try? bitmap.representation(using: .png, properties: [:])?.write(to: URL(fileURLWithPath: path))
+ }
+ }
+ if ProcessInfo.processInfo.environment["DOCS_SMOKE_SPIKE_ONLY"] == "1" { NSApp.terminate(nil) }
+ NSApp.activate(ignoringOtherApps: true)
+ window.makeKeyAndOrderFront(nil)
+ window.makeFirstResponder(editor)
+ editor.setSelectedRange(NSRange(location: 1, length: 2))
+ try? await Task.sleep(for: .milliseconds(500))
+ print("after spike: key=\(NSApp.keyWindow === window) responder=\(String(describing: window.firstResponder)) inspector=\(String(describing: UserDefaults.standard.object(forKey: "docs.inspector.open")))")
+ }
window.makeFirstResponder(editor)
editor.setSelectedRange(NSRange(location: 1, length: 2))
try? await Task.sleep(for: .milliseconds(500))
let original = editor.string
for step in 0..<8 {
try? await Task.sleep(for: .milliseconds(200))
- guard let menu = NSApp.mainMenu, let initial = menuItem(docsMacString("Document inspector"), in: menu), let submenu = initial.menu else {
- fatalError("Document inspector command unavailable")
- }
- submenu.delegate?.menuNeedsUpdate?(submenu)
- submenu.update()
- guard let item = menuItem(docsMacString("Document inspector"), in: menu), item.isEnabled else {
- fatalError("Inspector command disabled in document window")
+ guard let menu = NSApp.mainMenu else { fatalError("no main menu") }
+ let title = step.isMultiple(of: 2) ? "Hide Format" : "Show Format"
+ for top in menu.items { if let submenu = top.submenu { submenu.delegate?.menuNeedsUpdate?(submenu); submenu.update() } }
+ guard let item = menuItem(title, in: menu), item.isEnabled else {
+ let view = menu.items.first { $0.submenu?.items.contains { $0.title.hasSuffix("Format") } == true }?.submenu
+ print("View menu: \(view?.items.map { "\($0.title)[\($0.isEnabled)]" } ?? [])"); fflush(stdout)
+ fatalError("\(title) unavailable or disabled in a writer's document window (step \(step))")
}
let beforeWidth = editor.enclosingScrollView!.frame.width
+ let beforeX = editor.frame.minX
item.menu?.performActionForItem(at: item.menu!.index(of: item))
try? await Task.sleep(for: .milliseconds(200))
- precondition(abs(editor.enclosingScrollView!.frame.width - beforeWidth) > 200, "Inspector did not change editor space")
+ // The floating inspector covers the desk: the scroll view keeps
+ // its width and the page slides (spec §1, page centring).
+ precondition(abs(editor.enclosingScrollView!.frame.width - beforeWidth) < 0.5, "Format changed the editor's space")
+ precondition(abs(editor.frame.minX - beforeX) > 10, "Format did not move the page: \(beforeX) -> \(editor.frame.minX)")
window.setContentSize(NSSize(width: step.isMultiple(of: 2) ? 900 : 1200, height: 760))
try? await Task.sleep(for: .milliseconds(200))
window.contentView?.layoutSubtreeIfNeeded()
@@ -172,7 +196,7 @@ private struct Launcher: View {
view.cacheDisplay(in: view.bounds, to: bitmap)
try? bitmap.representation(using: .png, properties: [:])?.write(to: URL(fileURLWithPath: path))
}
- print("PASS: document loads, inspector toggles, window resizes, editor and selection persist, Enter and typing keep caret geometry stable")
+ print("PASS: document loads, Format inspector toggles, window resizes, editor and selection persist, Enter and typing keep caret geometry stable")
NSApp.windows.first(where: { $0.title == "Smoke Home" })?.close()
window.makeKeyAndOrderFront(nil)
guard let menu = NSApp.mainMenu, let appMenu = menu.items.first?.submenu else { fatalError("App menu missing") }