Keep Mac task commands and screens on the same current context
12 files changed,
+294
−30
docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md+65 −0native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift+20 −2native/apple/Sources/EquipoKit/UI/Screens/TaskDetailScreen.swift+5 −3native/apple/Sources/EquipoMac/EquipoMacApp.swift+1 −0native/apple/Sources/EquipoMac/LiveTranscript.swift+5 −2native/apple/Sources/EquipoMac/MacComposer.swift+6 −3native/apple/Sources/EquipoMac/MacJumpPalette.swift+6 −1native/apple/Sources/EquipoMac/MacMainView.swift+2 −9native/apple/Sources/EquipoMac/MacPowerCommands.swift+2 −2native/apple/Sources/EquipoMac/MacWorkspace.swift+39 −6native/apple/Tests/EquipoKitTests/MacPowerReviewTests.swift+141 −0native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift+2 −2
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md b/docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md| index b2f7546f..04ba184f 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md |
| @@ -134,3 +134,68 @@ retained. No actual merge was sent by a capture. |
| Normal push with `agent-tools/push.sh`; exact head and Linux CI verdict are |
| reported in the handoff and saved CI JSON. No merge, deployment or release. |
| Own fixture processes and scratch are removed after validation. |
| + |
| +## Fable delta: same-task context, accessibility and navigation |
| + |
| +The task screen now resolves the Mac model directly from its current context. |
| +Its state owns a model only on the session/task initializer used outside that |
| +context. Replacing the context for the same task ID therefore replaces the |
| +screen's model as well as the command target. Notification, palette and |
| +other-window routes are covered; a mounted NSHostingView regression replaces |
| +the same-ID context and asserts that its Merge sheet attaches to the window. |
| +The palette's labelled accessibility element contains its children. Source |
| +contracts pin containment and the separate Not now, Open in New Window and |
| +result labels, following this repository's view-contract tests. An attempted |
| +in-process accessibility-tree walk returned no usable SwiftUI children in the |
| +Swift test host, so it is not used as evidence of spoken VoiceOver output. |
| + |
| +Pane changes retain the inspector's task and visibility. The workspace owns |
| +an unsent composer draft; recreated AppKit transcripts bind to it, including |
| +edits, paste and clearing after send. A Task-menu action reveals a hidden |
| +inspector before invoking its model. Palette Return ignores marked text. |
| +Task WindowGroup restoration is disabled, so old restored windows do not flash |
| +before account validation. Title-word-prefix matches rank first, other title |
| +matches next, metadata then whole-word brief matches (query length at least |
| +two). The index is cached until its source task/project data changes. |
| + |
| +Explicit deferrals: Command-Return from a list, double-click to open a task |
| +window, and a keyboard shortcut for Open in New Window. Existing sentence-case |
| +task labels in Mac menus remain the copy follow-up for Luna. No new copy. |
| + |
| +The notification-actions branch is checkpointed locally at 4dac0111 while this |
| +priority fix is handled. Its first focused Go tests passed; the unfinished |
| +implementation was not pushed. The approved share follow-ups come after this |
| +Mac delta and before notification work resumes. |
| + |
| +Delta validation: the initial review tests failed on the missing draft, routing |
| +and input-method helpers. Focused tests then passed, including the mounted |
| +same-task sheet test. All 15 deliberate mutations below failed the filtered |
| +`MacPowerReviewTests` suite; sources were restored after each run. Accessibility, |
| +restoration and keyboard wiring are source contracts; the other failures are |
| +behavioral assertions. The mounted screen also catches restoring the old |
| +state-owned Mac model. The first queued-clear log was too verbose for the |
| +runner's issue-line detector; its test did fail. A boolean assertion now keeps |
| +that output bounded, and the repeated mutation was observed failing cleanly. |
| + |
| +| Delta mutation | Result | |
| +| --- | --- | |
| +| Restore state-owned Mac screen model | killed | |
| +| Ignore palette accessibility children | killed | |
| +| Clear inspector/task on pane navigation | killed | |
| +| Stop storing edited composer text | killed | |
| +| Do not reveal inspector before menu action | killed | |
| +| Ignore marked text | killed | |
| +| Remove the Return marked-text wiring | killed | |
| +| Restore task windows automatically | killed | |
| +| Remove title-word-prefix ranking | killed | |
| +| Match brief substrings | killed | |
| +| Remove brief minimum query length | killed | |
| +| Rebuild the index on every query | killed | |
| +| Keep the queued action after navigation | killed | |
| +| Route own-task actions out of a task window | killed | |
| +| Allow a queued action across navigation with the same inspector | killed | |
| + |
| +Queued actions now also carry a navigation generation. Keeping the inspector |
| +across a pane change cannot revive an old action after its asynchronous read. |
| +Mutation logs, the driver and focused-test results are retained with the |
| +slice 9 review evidence. No simulator was started. |
diff --git a/native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift b/native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift| index 353d9e33..c449e2b5 100644 |
| --- a/native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift |
| +++ b/native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift |
| @@ -11,6 +11,7 @@ public struct MacJumpResult: Identifiable, Sendable { |
| public let subtitle: String |
| public let needsYou: Bool |
| let search: String |
| + var brief = "" |
| public var id: MacDestination { target } |
| } |
| @@ -27,7 +28,7 @@ public struct MacJumpIndex { |
| let task = latest[entry.id] ?? entry |
| entries.append(.init(target: .task(task.id), title: task.title, subtitle: task.project, |
| needsYou: needsIDs.contains(task.id), |
| - search: [task.title, task.project, task.repo ?? "", task.branch, task.brief].joined(separator: " "))) |
| + search: [task.project, task.repo ?? "", task.branch].joined(separator: " "), brief: task.brief)) |
| } |
| for project in projects where project.state == "active" { |
| entries.append(.init(target: .project(project.id), title: project.displayName, subtitle: project.repo, |
| @@ -40,10 +41,27 @@ public struct MacJumpIndex { |
| } |
| public func results(_ query: String) -> [MacJumpResult] { |
| entries.enumerated().compactMap { index, entry -> (Int, Int, MacJumpResult)? in |
| - guard let score = Self.score(query, in: entry.search) else { return nil } |
| + guard let score = Self.rank(query, entry: entry) else { return nil } |
| return (score, index, entry) |
| }.sorted { $0.0 == $1.0 ? $0.1 < $1.1 : $0.0 > $1.0 }.map(\.2) |
| } |
| + private static func folded(_ text: String) -> String { |
| + text.folding(options: [.caseInsensitive, .diacriticInsensitive], locale: .current) |
| + } |
| + private static func words(_ text: String) -> [String] { |
| + folded(text).split { !$0.isLetter && !$0.isNumber }.map(String.init) |
| + } |
| + private static func rank(_ query: String, entry: MacJumpResult) -> Int? { |
| + let query = folded(query.trimmingCharacters(in: .whitespacesAndNewlines)) |
| + if query.isEmpty { return 0 } |
| + let queryWords = words(query), titleWords = words(entry.title) |
| + if !queryWords.isEmpty, queryWords.allSatisfy({ q in titleWords.contains { $0.hasPrefix(q) } }) { return 50000 } |
| + if let titleScore = score(query, in: entry.title) { return 30000 + max(0, titleScore) } |
| + if let otherScore = score(query, in: entry.search) { return 10000 + max(0, otherScore) } |
| + let briefWords = Set(words(entry.brief)) |
| + if query.count >= 2, !queryWords.isEmpty, queryWords.allSatisfy({ briefWords.contains($0) }) { return 100 } |
| + return nil |
| + } |
| public static func score(_ query: String, in text: String) -> Int? { |
| let query = query.trimmingCharacters(in: .whitespacesAndNewlines).folding(options: [.caseInsensitive, .diacriticInsensitive], locale: .current) |
| let text = text.folding(options: [.caseInsensitive, .diacriticInsensitive], locale: .current) |
diff --git a/native/apple/Sources/EquipoKit/UI/Screens/TaskDetailScreen.swift b/native/apple/Sources/EquipoKit/UI/Screens/TaskDetailScreen.swift| index 8b270921..e4c6d1f0 100644 |
| --- a/native/apple/Sources/EquipoKit/UI/Screens/TaskDetailScreen.swift |
| +++ b/native/apple/Sources/EquipoKit/UI/Screens/TaskDetailScreen.swift |
| @@ -18,16 +18,17 @@ enum TaskDetailTab: String, CaseIterable, Identifiable { |
| /// the decision outside the scrolling evidence on every tab. |
| public struct TaskScreen: View { |
| private let macContext: MacTaskContext? |
| - @State private var model: TaskDetailModel |
| + @State private var ownedModel: TaskDetailModel? |
| + var model: TaskDetailModel { macContext?.detail ?? ownedModel! } |
| @State private var tab: TaskDetailTab = .overview |
| @State private var talking = false |
| public init(session: EquipoSession, taskID: String) { |
| macContext = nil |
| - _model = State(initialValue: TaskDetailModel(session: session, taskID: taskID)) |
| + _ownedModel = State(initialValue: TaskDetailModel(session: session, taskID: taskID)) |
| } |
| public init(context: MacTaskContext) { |
| macContext = context |
| - _model = State(initialValue: context.detail) |
| + _ownedModel = State(initialValue: nil) |
| } |
| public var body: some View { |
| @Bindable var model = model |
| @@ -183,6 +184,7 @@ public struct TaskScreen: View { |
| } |
| } |
| @ViewBuilder private func decisionBar(_ task: ThinTask) -> some View { |
| + @Bindable var model = model |
| VStack(alignment: .leading, spacing: 8) { |
| if let reverted = model.revertedTask { |
| NavigationLink(reverted.title) { TaskScreen(session: model.session, taskID: reverted.id) } |
diff --git a/native/apple/Sources/EquipoMac/EquipoMacApp.swift b/native/apple/Sources/EquipoMac/EquipoMacApp.swift| index 9c54b46f..30274129 100644 |
| --- a/native/apple/Sources/EquipoMac/EquipoMacApp.swift |
| +++ b/native/apple/Sources/EquipoMac/EquipoMacApp.swift |
| @@ -59,6 +59,7 @@ import SwiftUI |
| WindowGroup(EquipoStrings.text("task.title"), id: "task", for: MacTaskWindowID.self) { $identity in |
| MacTaskWindow(model: model, identity: identity) |
| }.defaultSize(width: 820, height: 900) |
| + .restorationBehavior(.disabled) |
| Settings { MacSettings(model: model) } |
| } |
| } |
diff --git a/native/apple/Sources/EquipoMac/LiveTranscript.swift b/native/apple/Sources/EquipoMac/LiveTranscript.swift| index e8fde92b..3ca4f4d6 100644 |
| --- a/native/apple/Sources/EquipoMac/LiveTranscript.swift |
| +++ b/native/apple/Sources/EquipoMac/LiveTranscript.swift |
| @@ -67,7 +67,7 @@ final class LiveTranscript: NSView { |
| if wantsComposerFocus { focusComposer() } |
| } |
| - init(session: EquipoSession, openTask: @escaping (String) -> Void) { |
| + init(session: EquipoSession, openTask: @escaping (String) -> Void, draft: MacComposerDraft? = nil) { |
| self.session = session |
| selectionHost = NSHostingView(rootView: ProjectSelectionChip(catalog: session.projectCatalog)) |
| self.openTask = openTask |
| @@ -79,6 +79,8 @@ final class LiveTranscript: NSView { |
| addSubview(scroll) |
| addSubview(composer) |
| addSubview(selectionHost) |
| + composer.setText(draft?.text ?? "") |
| + composer.onTextChange = { [weak draft] text in draft?.text = text } |
| composer.attach(session.attachments) |
| composer.onHeightChange = { [weak self] in self?.needsLayout = true } |
| composer.onSend = { [weak self] text in |
| @@ -657,11 +659,12 @@ struct TranscriptView: NSViewRepresentable { |
| @Binding var focusCard: String? |
| var openTask: (String) -> Void |
| var composerFocus: Int = 0 |
| + var draft: MacComposerDraft? = nil |
| final class Coordinator { var focus = -1 } |
| func makeCoordinator() -> Coordinator { Coordinator() } |
| func makeNSView(context: Context) -> LiveTranscript { |
| - let view = LiveTranscript(session: session, openTask: openTask) |
| + let view = LiveTranscript(session: session, openTask: openTask, draft: draft) |
| view.update(items: items) |
| focus(view) |
| return view |
diff --git a/native/apple/Sources/EquipoMac/MacComposer.swift b/native/apple/Sources/EquipoMac/MacComposer.swift| index 31137e6f..a5376a57 100644 |
| --- a/native/apple/Sources/EquipoMac/MacComposer.swift |
| +++ b/native/apple/Sources/EquipoMac/MacComposer.swift |
| @@ -3,6 +3,8 @@ import EquipoKit |
| import SwiftUI |
| import Observation |
| +@MainActor @Observable final class MacComposerDraft { var text = "" } |
| + |
| /// The composer's text view: Return sends, Shift-Return starts a new line, |
| /// and an input method's marked text is never sent half typed. |
| final class ComposerEditor: NSTextView { |
| @@ -66,6 +68,7 @@ final class MacComposer: NSView, NSTextViewDelegate { |
| let pill = ComposerPill() |
| let textScroll = NSScrollView() |
| var onSend: ((String) -> Void)? |
| + var onTextChange: ((String) -> Void)? |
| var onHeightChange: (() -> Void)? |
| private(set) var desiredHeight: CGFloat = 44 |
| private var updating = false |
| @@ -158,7 +161,7 @@ final class MacComposer: NSView, NSTextViewDelegate { |
| var text: String { editor.string } |
| private var canSend: Bool { draft?.canSend(text: editor.string) ?? !editor.string.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } |
| - func textDidChange(_ notification: Notification) { refresh() } |
| + func textDidChange(_ notification: Notification) { onTextChange?(editor.string); refresh() } |
| func textDidBeginEditing(_ notification: Notification) { pill.needsDisplay = true } |
| func textDidEndEditing(_ notification: Notification) { pill.needsDisplay = true } |
| @@ -179,12 +182,12 @@ final class MacComposer: NSView, NSTextViewDelegate { |
| return panel |
| } |
| - func setText(_ text: String) { editor.string = text; editor.needsDisplay = true; refresh() } |
| + func setText(_ text: String) { editor.string = text; editor.needsDisplay = true; onTextChange?(text); refresh() } |
| func submit() { |
| let value = editor.string.trimmingCharacters(in: .whitespacesAndNewlines) |
| guard canSend else { return } |
| - editor.string = ""; editor.needsDisplay = true |
| + editor.string = ""; editor.needsDisplay = true; onTextChange?("") |
| refresh(); onSend?(value) |
| window?.makeFirstResponder(editor) |
| } |
diff --git a/native/apple/Sources/EquipoMac/MacJumpPalette.swift b/native/apple/Sources/EquipoMac/MacJumpPalette.swift| index 71896445..439f8f90 100644 |
| --- a/native/apple/Sources/EquipoMac/MacJumpPalette.swift |
| +++ b/native/apple/Sources/EquipoMac/MacJumpPalette.swift |
| @@ -72,14 +72,19 @@ struct MacJumpPalette: View { |
| .onKeyPress(.downArrow) { move(1); return .handled } |
| .onKeyPress(.upArrow) { move(-1); return .handled } |
| .onKeyPress(keys: [.return], phases: .down) { event in |
| + guard Self.canActivate(firstResponder: NSApp.keyWindow?.firstResponder) else { return .ignored } |
| if let action = selectedAction { activate(action) } |
| else if let selected { activate(selected, window: event.modifiers.contains(.command)) } |
| return .handled |
| } |
| .onExitCommand { dismiss() } |
| .task(id: taskContext?.taskID) { await taskContext?.load() } |
| + .accessibilityElement(children: .contain) |
| .accessibilityLabel(EquipoStrings.text("native.mac.jump")) |
| } |
| + static func canActivate(firstResponder: NSResponder?) -> Bool { |
| + (firstResponder as? NSTextInputClient)?.hasMarkedText() != true |
| + } |
| private func resultRow(_ result: MacJumpResult) -> some View { |
| Button { activate(result.target, window: false) } label: { |
| HStack { |
| @@ -151,7 +156,7 @@ struct MacWorkspacePresenter: ViewModifier { |
| content.sheet(isPresented: $workspace.palette, onDismiss: { |
| let pending = workspace.pendingAction |
| workspace.pendingAction = nil |
| - if let pending { Task { await workspace.performRoutedAction(pending.action, context: pending.context) } } |
| + if let pending { Task { await workspace.performRoutedAction(pending.action, context: pending.context, navigation: pending.navigation) } } |
| }) { MacJumpPalette(workspace: workspace) } |
| .focusedSceneValue(workspace) |
| } |
diff --git a/native/apple/Sources/EquipoMac/MacMainView.swift b/native/apple/Sources/EquipoMac/MacMainView.swift| index bdacf7c5..585ab922 100644 |
| --- a/native/apple/Sources/EquipoMac/MacMainView.swift |
| +++ b/native/apple/Sources/EquipoMac/MacMainView.swift |
| @@ -58,7 +58,7 @@ struct MacMainView: View { |
| @ViewBuilder private var detail: some View { |
| switch workspace.pane { |
| case .conversation: |
| - TranscriptView(projectSelectionID: session.projectCatalog.selection?.id, projectSelectionNotice: session.projectCatalog.selectionNotice, items: Feed.build(session), session: session, focusCard: Binding(get: { workspace.focusCard }, set: { workspace.focusCard = $0 }), openTask: open, composerFocus: workspace.composerFocus) |
| + TranscriptView(projectSelectionID: session.projectCatalog.selection?.id, projectSelectionNotice: session.projectCatalog.selectionNotice, items: Feed.build(session), session: session, focusCard: Binding(get: { workspace.focusCard }, set: { workspace.focusCard = $0 }), openTask: open, composerFocus: workspace.composerFocus, draft: workspace.composerDraft) |
| case .projects: |
| HStack(spacing: 0) { |
| ProjectsScreen(session: session) { workspace.go(.project($0)) } |
| @@ -109,14 +109,7 @@ struct MacMainView: View { |
| /// A tapped notification: the conversation at its card, or the task in |
| /// the inspector beside Tasks. |
| private func go(_ destination: Destination) { |
| - workspace.go(.pane(destination.pane)) |
| - workspace.focusCard = destination.cardID |
| - if destination.focusComposer { workspace.composerFocus += 1 } |
| - if let project = destination.projectID { workspace.go(.project(project)) } |
| - if let task = destination.taskID { open(task) } |
| - if let action = destination.macAction, let context = workspace.context { |
| - Task { await workspace.performRoutedAction(action, context: context) } |
| - } |
| + workspace.open(destination) |
| } |
| private func open(_ taskID: String) { |
diff --git a/native/apple/Sources/EquipoMac/MacPowerCommands.swift b/native/apple/Sources/EquipoMac/MacPowerCommands.swift| index b838c28d..c6b286d1 100644 |
| --- a/native/apple/Sources/EquipoMac/MacPowerCommands.swift |
| +++ b/native/apple/Sources/EquipoMac/MacPowerCommands.swift |
| @@ -51,8 +51,8 @@ struct MacPowerCommands: Commands { |
| } |
| @ViewBuilder private func action(_ action: MacTaskAction, shortcut: KeyEquivalent? = nil) -> some View { |
| let button = Button(action.title, role: action == .cancel ? .destructive : nil) { |
| - let context = workspace?.context |
| - Task { await context?.perform(action) } |
| + let target = workspace |
| + Task { await target?.performMenuAction(action) } |
| }.disabled(workspace?.context?.actions.contains(action) != true || workspace?.palette == true) |
| if let shortcut { button.keyboardShortcut(shortcut, modifiers: [.command, .shift]) } |
| else { button } |
diff --git a/native/apple/Sources/EquipoMac/MacWorkspace.swift b/native/apple/Sources/EquipoMac/MacWorkspace.swift| index ee7287d7..85b23eac 100644 |
| --- a/native/apple/Sources/EquipoMac/MacWorkspace.swift |
| +++ b/native/apple/Sources/EquipoMac/MacWorkspace.swift |
| @@ -14,8 +14,10 @@ import SwiftUI |
| var focusCard: String? |
| var inspector = false |
| var palette = false |
| - struct QueuedAction { let action: MacTaskAction; let context: MacTaskContext } |
| + struct QueuedAction { let action: MacTaskAction; let context: MacTaskContext; let navigation: Int } |
| + private var navigationRevision = 0 |
| var pendingAction: QueuedAction? |
| + let composerDraft = MacComposerDraft() |
| var composerFocus = 0 |
| var context: MacTaskContext? |
| var mainRequest = 0 |
| @@ -23,8 +25,38 @@ import SwiftUI |
| self.app = app; self.session = session; standalone = taskID != nil |
| if let taskID { context = MacTaskContext(session: session, taskID: taskID) } |
| } |
| - var index: MacJumpIndex { MacJumpIndex(tasks: session.tasks, needs: session.needsYou ?? [], projects: session.projectCatalog.items) } |
| + private struct IndexSource: Equatable { |
| + let tasks: [ThinTask]; let needs: [ThinTask]; let projects: [ThinProject] |
| + } |
| + @ObservationIgnored private var indexSource: IndexSource? |
| + @ObservationIgnored private var cachedIndex = MacJumpIndex(tasks: [], needs: [], projects: []) |
| + @ObservationIgnored private(set) var indexGeneration = 0 |
| + var index: MacJumpIndex { |
| + let source = IndexSource(tasks: session.tasks, needs: session.needsYou ?? [], projects: session.projectCatalog.items) |
| + if source != indexSource { |
| + cachedIndex = MacJumpIndex(tasks: source.tasks, needs: source.needs, projects: source.projects) |
| + indexSource = source; indexGeneration += 1 |
| + } |
| + return cachedIndex |
| + } |
| + func open(_ destination: Destination) { |
| + go(.pane(destination.pane)) |
| + focusCard = destination.cardID |
| + if destination.focusComposer { composerFocus += 1 } |
| + if let project = destination.projectID { go(.project(project)) } |
| + if let task = destination.taskID { go(.task(task)) } |
| + if let action = destination.macAction, let context { |
| + let navigation = navigationRevision |
| + Task { await performRoutedAction(action, context: context, navigation: navigation) } |
| + } |
| + } |
| + func performMenuAction(_ action: MacTaskAction) async { |
| + guard let context, !palette, context.actions.contains(action) else { return } |
| + inspector = true |
| + await context.perform(action) |
| + } |
| func go(_ destination: MacDestination, record: Bool = true) { |
| + navigationRevision += 1 |
| palette = false; pendingAction = nil |
| if standalone { |
| switch destination { |
| @@ -37,7 +69,7 @@ import SwiftUI |
| } |
| if record { history.go(destination) } |
| switch destination { |
| - case .pane(let value): pane = value; inspector = false; context = nil |
| + case .pane(let value): pane = value |
| case .project(let id): pane = .projects; projectID = id |
| case .task(let id): |
| pane = history.pane |
| @@ -64,12 +96,13 @@ import SwiftUI |
| return true |
| } |
| self.context = context; inspector = true |
| - pendingAction = QueuedAction(action: action, context: context) |
| + pendingAction = QueuedAction(action: action, context: context, navigation: navigationRevision) |
| return false |
| } |
| - func performRoutedAction(_ action: MacTaskAction, context: MacTaskContext) async { |
| + func performRoutedAction(_ action: MacTaskAction, context: MacTaskContext, navigation: Int? = nil) async { |
| + let expected = navigation ?? navigationRevision |
| await context.load() |
| - guard self.context === context else { return } |
| + guard self.context === context, expected == navigationRevision else { return } |
| await context.perform(action) |
| } |
| func refresh() async { if let context { await context.refresh() } else { await session.refresh() } } |
diff --git a/native/apple/Tests/EquipoKitTests/MacPowerReviewTests.swift b/native/apple/Tests/EquipoKitTests/MacPowerReviewTests.swift| new file mode 100644 |
| index 00000000..471a6923 |
| --- /dev/null |
| +++ b/native/apple/Tests/EquipoKitTests/MacPowerReviewTests.swift |
| @@ -0,0 +1,141 @@ |
| +#if os(macOS) |
| +import AppKit |
| +import SwiftUI |
| +import Testing |
| +@testable import EquipoKit |
| +@testable import EquipoMac |
| + |
| +@MainActor @Suite(.serialized) struct MacPowerReviewTests { |
| + @Test func paneNavigationKeepsInspectorAndDraftButClearsQueuedAction() async throws { |
| + let detail = try TaskDetailModelTests.model(TaskDetailServer()) |
| + await detail.load() |
| + let workspace = MacWorkspace(app: EquipoAppModel(store: MemorySecretStore()), session: detail.session) |
| + let context = MacTaskContext(detail: detail) |
| + _ = workspace.queuePaletteAction(.cancel, context: context) |
| + workspace.composerDraft.text = "unfinished message" |
| + workspace.go(.pane(.needs)) |
| + let cleared = workspace.pendingAction == nil |
| + #expect(cleared) |
| + #expect(workspace.context === context && workspace.inspector) |
| + workspace.go(.pane(.conversation)) |
| + #expect(workspace.composerDraft.text == "unfinished message") |
| + let first = LiveTranscript(session: detail.session, openTask: { _ in }, draft: workspace.composerDraft) |
| + #expect(first.composer.text == "unfinished message") |
| + first.composer.editor.string = "still writing" |
| + first.composer.textDidChange(Notification(name: NSText.didChangeNotification)) |
| + let second = LiveTranscript(session: detail.session, openTask: { _ in }, draft: workspace.composerDraft) |
| + #expect(second.composer.text == "still writing") |
| + second.composer.submit() |
| + #expect(workspace.composerDraft.text.isEmpty) |
| + } |
| + @Test(arguments: ["notification", "palette", "task-window"]) |
| + func sameTaskReopenUsesVisibleModelAndRevealsHiddenInspector(_ source: String) async throws { |
| + let detail = try TaskDetailModelTests.model(TaskDetailServer()) |
| + let workspace = MacWorkspace(app: EquipoAppModel(store: MemorySecretStore()), session: detail.session) |
| + workspace.go(.task(detail.taskID)) |
| + let old = try #require(workspace.context) |
| + await old.load() |
| + if source == "palette" { |
| + let fresh = MacTaskContext(session: detail.session, taskID: detail.taskID) |
| + await fresh.load() |
| + _ = workspace.queuePaletteAction(.merge, context: fresh) |
| + } else if source == "task-window" { |
| + let other = MacWorkspace(app: workspace.app, session: detail.session, taskID: "other") |
| + other.go(.task(detail.taskID)) |
| + workspace.open(try #require(workspace.app.destination)) |
| + } else { |
| + workspace.open(Destination(pane: .tasks, taskID: detail.taskID)) |
| + } |
| + let current = try #require(workspace.context) |
| + let screen = TaskScreen(context: current) |
| + #expect(screen.model === current.detail) |
| + workspace.inspector = false |
| + await workspace.performMenuAction(.merge) |
| + #expect(workspace.inspector) |
| + #expect(screen.model.confirmation?.action == .merge) |
| + } |
| + @Test func replacingSameTaskContextInMountedScreenPresentsItsSheet() async throws { |
| + let detail = try TaskDetailModelTests.model(TaskDetailServer()) |
| + let old = MacTaskContext(detail: detail); await old.load() |
| + let host = NSHostingView(rootView: TaskScreen(context: old)) |
| + let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 820, height: 900), styleMask: [.titled], backing: .buffered, defer: false) |
| + window.isReleasedWhenClosed = false |
| + window.contentView = host; window.makeKeyAndOrderFront(nil) |
| + defer { if let sheet = window.attachedSheet { window.endSheet(sheet) }; window.orderOut(nil); window.contentView = nil; window.close() } |
| + try await Task.sleep(for: .milliseconds(150)) |
| + let fresh = MacTaskContext(session: detail.session, taskID: detail.taskID) |
| + await fresh.load() |
| + host.rootView = TaskScreen(context: fresh) |
| + host.layoutSubtreeIfNeeded() |
| + try await Task.sleep(for: .milliseconds(150)) |
| + await fresh.perform(.merge) |
| + for _ in 0..<30 where window.attachedSheet == nil { try await Task.sleep(for: .milliseconds(50)) } |
| + #expect(window.attachedSheet != nil) |
| + #expect(old.detail.confirmation == nil) |
| + #expect(fresh.detail.confirmation?.action == .merge) |
| + } |
| + @Test func navigationCancelsQueuedActionEvenWhenInspectorKeepsItsContext() async throws { |
| + let detail = try TaskDetailModelTests.model(TaskDetailServer()); await detail.load() |
| + let workspace = MacWorkspace(app: EquipoAppModel(store: MemorySecretStore()), session: detail.session) |
| + let context = MacTaskContext(detail: detail) |
| + _ = workspace.queuePaletteAction(.cancel, context: context) |
| + let pending = try #require(workspace.pendingAction) |
| + workspace.go(.pane(.needs)) |
| + await workspace.performRoutedAction(pending.action, context: pending.context, navigation: pending.navigation) |
| + #expect(detail.confirmation == nil) |
| + } |
| + @Test func taskWindowActionStaysOnItsOwnTask() async throws { |
| + let detail = try TaskDetailModelTests.model(TaskDetailServer()) |
| + let app = EquipoAppModel(store: MemorySecretStore()) |
| + let workspace = MacWorkspace(app: app, session: detail.session, taskID: detail.taskID) |
| + let own = try #require(workspace.context); await own.load() |
| + #expect(!workspace.queuePaletteAction(.cancel, context: own)) |
| + #expect(workspace.pendingAction?.context === own) |
| + #expect(app.destination == nil) |
| + await workspace.performMenuAction(.cancel) |
| + #expect(own.detail.confirmation?.action == .cancel) |
| + } |
| + @Test func briefOnlyMatchesWholeWordsAndTitlesWin() throws { |
| + var title = try TaskDetailTests.task(); title.id = "title"; title.title = "Fix login button"; title.brief = ""; title.project = "zz"; title.repo = "zz"; title.branch = "zz" |
| + var partial = title; partial.id = "partial"; partial.title = "Fix rebuttoning"; partial.brief = "" |
| + var brief = title; brief.id = "brief"; brief.title = "Unrelated"; brief.brief = "button narrow" |
| + let index = MacJumpIndex(tasks: [brief, partial, title], needs: [], projects: []) |
| + #expect(index.results("button").prefix(3).map(\.target) == [.task("title"), .task("partial"), .task("brief")]) |
| + #expect(!index.results("but").contains { $0.target == .task("brief") }) |
| + #expect(!index.results("bn").contains { $0.target == .task("brief") }) |
| + brief.brief = "a button"; brief.title = "XYZ" |
| + #expect(!MacJumpIndex(tasks: [brief], needs: [], projects: []).results("a").contains { $0.target == .task("brief") }) |
| + } |
| + @Test func indexRebuildsForDataChangesButNotQueries() async throws { |
| + let detail = try TaskDetailModelTests.model(TaskDetailServer()) |
| + let workspace = MacWorkspace(app: EquipoAppModel(store: MemorySecretStore()), session: detail.session) |
| + _ = workspace.index |
| + let generation = workspace.indexGeneration |
| + _ = workspace.index.results("one"); _ = workspace.index.results("two") |
| + #expect(workspace.indexGeneration == generation) |
| + await detail.session.refresh() |
| + _ = workspace.index.results("Swipe") |
| + #expect(workspace.indexGeneration == generation + 1) |
| + } |
| + @Test func presentationContractsKeepChildrenAndUseTheCurrentContext() throws { |
| + let sources = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("Sources") |
| + let palette = try String(contentsOf: sources.appendingPathComponent("EquipoMac/MacJumpPalette.swift"), encoding: .utf8) |
| + #expect(palette.contains(".accessibilityElement(children: .contain)\n .accessibilityLabel")) |
| + for key in ["chat.card.not_now", "native.mac.open_window"] { #expect(palette.contains("Button(EquipoStrings.text(\"" + key + "\")")) } |
| + #expect(palette.contains("Text(result.title)")) |
| + #expect(palette.contains("guard Self.canActivate(firstResponder: NSApp.keyWindow?.firstResponder)")) |
| + let screen = try String(contentsOf: sources.appendingPathComponent("EquipoKit/UI/Screens/TaskDetailScreen.swift"), encoding: .utf8) |
| + #expect(screen.contains("macContext?.detail ?? ownedModel!")) |
| + let app = try String(contentsOf: sources.appendingPathComponent("EquipoMac/EquipoMacApp.swift"), encoding: .utf8) |
| + #expect(app.contains(".restorationBehavior(.disabled)")) |
| + let commands = try String(contentsOf: sources.appendingPathComponent("EquipoMac/MacPowerCommands.swift"), encoding: .utf8) |
| + #expect(commands.contains("performMenuAction(action)")) |
| + } |
| + @Test func markedTextDoesNotActivatePalette() { |
| + let editor = NSTextView() |
| + #expect(MacJumpPalette.canActivate(firstResponder: editor)) |
| + editor.setMarkedText("未", selectedRange: NSRange(location: 0, length: 0), replacementRange: NSRange(location: NSNotFound, length: 0)) |
| + #expect(!MacJumpPalette.canActivate(firstResponder: editor)) |
| + } |
| +} |
| +#endif |
diff --git a/native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift b/native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift| index a9367259..f4dd6b86 100644 |
| --- a/native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift |
| +++ b/native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift |
| @@ -16,7 +16,7 @@ import Testing |
| #expect(two.context?.taskID == "other") |
| one.go(.project("project")); #expect(one.pane == .projects); #expect(one.projectID == "project") |
| one.back(); #expect(one.context?.taskID == detail.taskID); #expect(one.pane == .conversation) |
| - one.back(); #expect(one.pane == .conversation); #expect(!one.inspector) |
| + one.back(); #expect(one.pane == .conversation); #expect(one.inspector) |
| one.forward(); #expect(one.inspector) |
| one.newMessage(); #expect(one.pane == .conversation); #expect(one.composerFocus == 1) |
| #expect(two.context?.taskID == "other") |
| @@ -67,7 +67,7 @@ import Testing |
| await main.performRoutedAction(.cancel, context: target) |
| #expect(detail.confirmation?.action == .cancel) |
| #expect(await server.writes == 0) |
| - detail.confirmation = nil; main.go(.pane(.conversation)) |
| + detail.confirmation = nil; main.go(.task("other")) |
| await main.performRoutedAction(.cancel, context: target) |
| #expect(detail.confirmation == nil) |
| MacWorkspace.newMessage(app: app, focused: nil) |