Merge branch 'native/merge-card' into main
11 files changed,
+551
−25
native/apple/Sources/EquipoKit/Presentation/Roster.swift+81 −0native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings+176 −0native/apple/Sources/EquipoKit/UI/LiveCards.swift+91 −18native/apple/Sources/EquipoKit/UI/Screens/ConversationScreen.swift+1 −1native/apple/Sources/EquipoKit/UI/Screens/TaskScreens.swift+1 −1native/apple/Sources/EquipoMac/LiveTranscript.swift+55 −3native/apple/Tests/EquipoKitTests/MergeCardTests.swift+95 −0native/scripts/check-native.sh+1 −0native/scripts/check-parity.py+32 −0native/scripts/check-strings.py+1 −1native/scripts/strings.json+17 −1
CI cancelled — superseded by a newer push — run details
diff --git a/native/apple/Sources/EquipoKit/Presentation/Roster.swift b/native/apple/Sources/EquipoKit/Presentation/Roster.swift| index a95bc769..15fdf353 100644 |
| --- a/native/apple/Sources/EquipoKit/Presentation/Roster.swift |
| +++ b/native/apple/Sources/EquipoKit/Presentation/Roster.swift |
| @@ -255,3 +255,84 @@ public enum Feed { |
| card.kind == "project" || (card.kind == "home" && card.state != "ask") |
| } |
| } |
| + |
| +// MARK: - Decisions answered here |
| + |
| +/// A decision card the device answers itself: merges and "Does main ship?", |
| +/// laid out exactly as the web's chat_page.go cardView and chat.html do |
| +/// (parity row R-02, must_match). Labels and outcome lines use the web's own |
| +/// copy keys (`chat.card.*`, `work.tl.*`); native/scripts/check-parity.py |
| +/// fails if their words differ from copy.go. |
| +public struct DecisionView: Sendable, Equatable { |
| + public struct Choice: Sendable, Equatable, Identifiable { |
| + public var value: String |
| + public var label: String |
| + public var primary: Bool |
| + public var id: String { value } |
| + } |
| + public var line: String |
| + public var open: Bool |
| + public var choices: [Choice] |
| + /// What was decided, once it was; the web's note. |
| + public var note: String? |
| + /// The candidate has a preview. It opens through the web's own page |
| + /// (Feed.previewURL), never at the address the card carries. |
| + public var hasPreview: Bool |
| + /// A closed card with an outcome shows only that line, as chat.html's |
| + /// equipo-card-done does: no question, no link. |
| + public var showsOnlyNote: Bool { !open && note != nil } |
| +} |
| + |
| +/// A conflict's "This item has changed" stays until the card moves past |
| +/// the revision the conflict returned, so a stale tap is never followed by |
| +/// a silent second one. |
| +public enum AnswerFeedback { |
| + public static func stillChanged(conflictAt: Int64, now: Int64) -> Bool { now <= conflictAt } |
| +} |
| + |
| +extension Feed { |
| + /// nil sends the card to the web: any other kind, or a choice with no words. |
| + public static func decision(_ card: ThinCard, task: ThinTask?) -> DecisionView? { |
| + let primary: String, chose: String, resolved: String |
| + var open = card.state == "open" |
| + switch card.kind { |
| + case "merge": |
| + primary = "merge"; chose = "chat.card.merge_chose_"; resolved = "chat.card.merge_resolved" |
| + case "merge_ships": |
| + primary = "not_ships"; chose = "chat.card.ships_chose_"; resolved = "chat.card.merge_policy_stale" |
| + open = open && !(card.options ?? []).isEmpty |
| + default: |
| + return nil |
| + } |
| + var choices: [DecisionView.Choice] = [] |
| + for value in card.options ?? [] { |
| + guard let label = webText("chat.card." + value) else { return nil } |
| + choices.append(.init(value: value, label: label, primary: value == primary)) |
| + } |
| + var note: String? |
| + if card.kind == "merge", task?.kind == "explore" { |
| + // From before the task became an exploration: it never merges. |
| + open = false; note = webText("work.tl.merge_dropped") |
| + } else if card.state == "answered" { |
| + note = webText(chose + card.choice) |
| + } else if card.state == "resolved" { |
| + note = webText(resolved) |
| + } |
| + // chat_page.go links a preview only on an open merge card, and always |
| + // through /tasks/<id>/preview (the sandboxed, checked wrapper). |
| + let preview = card.kind == "merge" && open && !(card.previewUrl ?? "").isEmpty |
| + return DecisionView(line: card.question, open: open, choices: open ? choices : [], note: note, hasPreview: preview) |
| + } |
| + |
| + /// The web's preview page for a card's task: Equipo's own wrapper, which |
| + /// refuses unsafe addresses and expired candidates. |
| + public static func previewURL(_ card: ThinCard, origin: URL) -> URL { |
| + origin.appendingPathComponent("tasks").appendingPathComponent(card.taskId).appendingPathComponent("preview") |
| + } |
| + |
| + /// A web copy key's words in the catalog, or nil when the catalog has none. |
| + static func webText(_ key: String) -> String? { |
| + let text = EquipoStrings.text(.init(key)) |
| + return text == key ? nil : text |
| + } |
| +} |
diff --git a/native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings b/native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings| index 81ab2ab6..415c5a7b 100644 |
| --- a/native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings |
| +++ b/native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings |
| @@ -244,6 +244,171 @@ |
| } |
| } |
| }, |
| + "chat.card.merge": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Merge" |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.merge_chose_merge": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Merging without checks." |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.merge_chose_not_now": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Not now." |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.merge_chose_wait": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Waiting for checks." |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.merge_chose_wait_mac": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Waiting for a Mac." |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.merge_policy_stale": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "The merge rules changed since I asked, so nothing was saved." |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.merge_resolved": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Nothing to decide any more." |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.not_now": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Not now" |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.not_ships": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "It doesn't" |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.preview_link": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Open the preview" |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.ships": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "It ships" |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.ships_chose_not_ships": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Main isn't a release, so I can merge small changes on my own when the other rules allow." |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.ships_chose_ships": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Merging to main ships to users, so I'll ask before merging without checks." |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.wait": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Wait for checks" |
| + } |
| + } |
| + } |
| + }, |
| + "chat.card.wait_mac": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "Wait for a Mac" |
| + } |
| + } |
| + } |
| + }, |
| "checks.cannot_run": { |
| "extractionState": "manual", |
| "localizations": { |
| @@ -1574,6 +1739,17 @@ |
| } |
| } |
| } |
| + }, |
| + "work.tl.merge_dropped": { |
| + "extractionState": "manual", |
| + "localizations": { |
| + "en": { |
| + "stringUnit": { |
| + "state": "translated", |
| + "value": "An earlier attempt to add this change was dropped when the task became an exploration." |
| + } |
| + } |
| + } |
| } |
| } |
| } |
diff --git a/native/apple/Sources/EquipoKit/UI/LiveCards.swift b/native/apple/Sources/EquipoKit/UI/LiveCards.swift| index 4538cddc..0e9e052e 100644 |
| --- a/native/apple/Sources/EquipoKit/UI/LiveCards.swift |
| +++ b/native/apple/Sources/EquipoKit/UI/LiveCards.swift |
| @@ -10,7 +10,7 @@ struct LiveQuestionCard: View { |
| let session: EquipoSession |
| @State private var phase: Phase = .open |
| - enum Phase: Equatable { case open, sending(String), changed, offline, failed } |
| + enum Phase: Equatable { case open, sending(String), changed(at: Int64), offline, failed } |
| var body: some View { |
| RaisedCard(flat: !card.isOpen) { |
| @@ -29,7 +29,9 @@ struct LiveQuestionCard: View { |
| } |
| } |
| .accessibilityElement(children: .contain) |
| - .onChange(of: card.revision) { _, _ in if phase == .changed { phase = .open } } |
| + .onChange(of: card.revision) { _, now in |
| + if case .changed(let at) = phase, !AnswerFeedback.stillChanged(conflictAt: at, now: now) { phase = .open } |
| + } |
| } |
| private var isSending: Bool { if case .sending = phase { return true }; return false } |
| @@ -66,39 +68,110 @@ struct LiveQuestionCard: View { |
| phase = .sending(choice) |
| switch await session.answer(card, choice: choice) { |
| case .answered: phase = .open |
| - case .changed: phase = .changed |
| + case .changed: phase = .changed(at: session.cards.first { $0.id == card.id }?.revision ?? card.revision) |
| case .offline: phase = .offline |
| case .failed: phase = .failed |
| } |
| } |
| } |
| -/// A decision this slice does not take natively: merges, approvals and the |
| -/// rest open the web app, where the full context and the must-match |
| -/// behaviour already are (sync proposal, parity rows R-02 and R-03). |
| +/// A decision card. Merges and "Does main ship?" are answered here, in the |
| +/// web's words (Feed.decision); every other decision opens the web app, |
| +/// where its full context is. |
| struct LiveDecisionCard: View { |
| let card: ThinCard |
| let taskTitle: String? |
| - let origin: URL |
| + let session: EquipoSession |
| + @State private var phase: Phase = .open |
| @Environment(\.openURL) private var openURL |
| + |
| + enum Phase: Equatable { case open, sending(String), changed(at: Int64), offline, failed } |
| + |
| var body: some View { |
| - RaisedCard(flat: !card.isOpen) { |
| - if let taskTitle, !card.question.contains(taskTitle) { |
| + let view = Feed.decision(card, task: session.task(card.taskId)) |
| + RaisedCard(flat: !(view?.open ?? card.isOpen)) { |
| + if let taskTitle, !card.question.isEmpty, !card.question.contains(taskTitle) { |
| Text(taskTitle).font(Typo.caption).foregroundStyle(Palette.secondary) |
| } |
| - CardHead(text: card.question.isEmpty ? (taskTitle ?? String(localized: "decision.untitled", bundle: .module)) : card.question) |
| - if card.isOpen { |
| - Text(String(localized: "decision.on_web", bundle: .module)).font(Typo.secondary).foregroundStyle(Palette.secondary) |
| - .fixedSize(horizontal: false, vertical: true) |
| - RosterButton(title: String(localized: "card.open_on_web", bundle: .module), primary: true) { |
| - openURL(Feed.webURL(for: card, origin: origin)) |
| - } |
| + if let view, view.showsOnlyNote, let note = view.note { |
| + // As the web's equipo-card-done: the outcome alone. |
| + Label { Text(note) } icon: { Image(systemName: "checkmark") } |
| + .font(Typo.secondaryStrong).foregroundStyle(Palette.positive) |
| } else { |
| - QuietLink(title: String(localized: "card.open_on_web", bundle: .module), icon: "arrow.up.right") { |
| - openURL(Feed.webURL(for: card, origin: origin)) |
| + CardHead(text: card.question.isEmpty ? (taskTitle ?? String(localized: "decision.untitled", bundle: .module)) : card.question) |
| + if let view { |
| + answerable(view) |
| + } else if card.isOpen { |
| + Text(String(localized: "decision.on_web", bundle: .module)).font(Typo.secondary).foregroundStyle(Palette.secondary) |
| + .fixedSize(horizontal: false, vertical: true) |
| + RosterButton(title: String(localized: "card.open_on_web", bundle: .module), primary: true) { |
| + openURL(Feed.webURL(for: card, origin: session.origin)) |
| + } |
| + } else { |
| + QuietLink(title: String(localized: "card.open_on_web", bundle: .module), icon: "arrow.up.right") { |
| + openURL(Feed.webURL(for: card, origin: session.origin)) |
| + } |
| } |
| } |
| } |
| + .accessibilityElement(children: .contain) |
| + .onChange(of: card.revision) { _, now in |
| + if case .changed(let at) = phase, !AnswerFeedback.stillChanged(conflictAt: at, now: now) { phase = .open } |
| + } |
| + } |
| + |
| + @ViewBuilder private func answerable(_ view: DecisionView) -> some View { |
| + if view.hasPreview { |
| + QuietLink(title: String(localized: "chat.card.preview_link", bundle: .module), icon: "arrow.up.right") { |
| + openURL(Feed.previewURL(card, origin: session.origin)) |
| + } |
| + } |
| + if view.open { |
| + let sending: String? = { if case .sending(let v) = phase { return v }; return nil }() |
| + ViewThatFits(in: .horizontal) { |
| + HStack(spacing: 10) { buttons(view, sending: sending) } |
| + VStack(spacing: 10) { buttons(view, sending: sending) } |
| + } |
| + feedback |
| + } |
| + } |
| + |
| + @ViewBuilder private func buttons(_ view: DecisionView, sending: String?) -> some View { |
| + ForEach(view.choices) { choice in |
| + RosterButton(title: choice.label, primary: choice.primary, expanded: true, |
| + busy: sending == choice.value ? String(localized: "action.sending", bundle: .module) : nil) { |
| + Task { await submit(choice.value) } |
| + } |
| + .disabled(sending != nil) |
| + } |
| + } |
| + |
| + @ViewBuilder private var feedback: some View { |
| + switch phase { |
| + case .changed: Text(String(localized: "card.changed", bundle: .module)).font(Typo.secondary).foregroundStyle(Palette.negative) |
| + case .offline: Text(String(localized: "card.offline", bundle: .module)).font(Typo.secondary).foregroundStyle(Palette.negative) |
| + case .failed: Text(String(localized: "card.failed", bundle: .module)).font(Typo.secondary).foregroundStyle(Palette.negative) |
| + default: EmptyView() |
| + } |
| + } |
| + |
| + private func submit(_ choice: String) async { |
| + if case .sending = phase { return } |
| + phase = .sending(choice) |
| + let outcome = await session.answer(card, choice: choice) |
| + switch outcome { |
| + case .answered: phase = .open |
| + case .changed: |
| + // The card as it is now, after the conflict: the message stays until it moves past it. |
| + phase = .changed(at: session.cards.first { $0.id == card.id }?.revision ?? card.revision) |
| + announce(String(localized: "card.changed", bundle: .module)) |
| + case .offline: phase = .offline; announce(String(localized: "card.offline", bundle: .module)) |
| + case .failed: phase = .failed; announce(String(localized: "card.failed", bundle: .module)) |
| + } |
| + } |
| + |
| + private func announce(_ text: String) { |
| + AccessibilityNotification.Announcement(text).post() |
| } |
| } |
diff --git a/native/apple/Sources/EquipoKit/UI/Screens/ConversationScreen.swift b/native/apple/Sources/EquipoKit/UI/Screens/ConversationScreen.swift| index d3a73bfe..eaf354e0 100644 |
| --- a/native/apple/Sources/EquipoKit/UI/Screens/ConversationScreen.swift |
| +++ b/native/apple/Sources/EquipoKit/UI/Screens/ConversationScreen.swift |
| @@ -58,7 +58,7 @@ public struct ConversationScreen: View { |
| case .decision(let card, let byline): |
| VStack(alignment: .leading, spacing: 8) { |
| Byline(byline: byline) |
| - LiveDecisionCard(card: card, taskTitle: session.task(card.taskId)?.title, origin: session.origin) |
| + LiveDecisionCard(card: card, taskTitle: session.task(card.taskId)?.title, session: session) |
| } |
| case .receipt(let card, _): |
| LiveReceipt(card: card) |
diff --git a/native/apple/Sources/EquipoKit/UI/Screens/TaskScreens.swift b/native/apple/Sources/EquipoKit/UI/Screens/TaskScreens.swift| index 146c6db8..fd349991 100644 |
| --- a/native/apple/Sources/EquipoKit/UI/Screens/TaskScreens.swift |
| +++ b/native/apple/Sources/EquipoKit/UI/Screens/TaskScreens.swift |
| @@ -102,7 +102,7 @@ struct TaskCards: View { |
| if card.kind == "question" { |
| LiveQuestionCard(card: card, taskTitle: nil, session: session) |
| } else { |
| - LiveDecisionCard(card: card, taskTitle: task.title, origin: session.origin) |
| + LiveDecisionCard(card: card, taskTitle: task.title, session: session) |
| } |
| } |
| } |
diff --git a/native/apple/Sources/EquipoMac/LiveTranscript.swift b/native/apple/Sources/EquipoMac/LiveTranscript.swift| index 8532e04d..7043e9ea 100644 |
| --- a/native/apple/Sources/EquipoMac/LiveTranscript.swift |
| +++ b/native/apple/Sources/EquipoMac/LiveTranscript.swift |
| @@ -210,7 +210,7 @@ final class LiveTranscript: NSView { |
| } |
| private func questionCard(_ card: ThinCard, taskTitle: String?, width: CGFloat) -> RaisedPlate { |
| - if let seen = answeredRevision[card.id], seen != card.revision { |
| + if let seen = answeredRevision[card.id], !AnswerFeedback.stillChanged(conflictAt: seen, now: card.revision) { |
| if case .sending = answers[card.id] {} else { answers[card.id] = nil; answeredRevision[card.id] = nil } |
| } |
| let state = answers[card.id] |
| @@ -277,7 +277,10 @@ final class LiveTranscript: NSView { |
| guard let self else { return } |
| switch outcome { |
| case .answered: self.answers[card.id] = nil |
| - case .changed: self.answers[card.id] = .changed |
| + case .changed: |
| + self.answers[card.id] = .changed |
| + // The card as it is now: the message stays until it moves past it. |
| + self.answeredRevision[card.id] = session.cards.first { $0.id == card.id }?.revision ?? card.revision |
| case .offline: self.answers[card.id] = .offline |
| case .failed: self.answers[card.id] = .failed |
| } |
| @@ -286,7 +289,8 @@ final class LiveTranscript: NSView { |
| } |
| private func decisionCard(_ card: ThinCard, taskTitle: String?, width: CGFloat) -> RaisedPlate { |
| - let plate = RaisedPlate(width: width, height: 0, flat: !card.isOpen) |
| + let open = Feed.decision(card, task: session.task(card.taskId))?.open ?? card.isOpen |
| + let plate = RaisedPlate(width: width, height: 0, flat: !open) |
| let inner = width - 2 * MacMetric.pad |
| var y = MacMetric.pad |
| func add(_ view: NSView, gap: CGFloat = MacMetric.gap) { |
| @@ -295,8 +299,56 @@ final class LiveTranscript: NSView { |
| if let taskTitle, !card.question.isEmpty, !card.question.contains(taskTitle) { |
| add(makeText(taskTitle, MacType.caption, .webSecondary, width: inner), gap: 4) |
| } |
| + let decision = Feed.decision(card, task: session.task(card.taskId)) |
| + if let decision, decision.showsOnlyNote, let note = decision.note { |
| + // As the web's equipo-card-done: the outcome alone. |
| + add(outcome(note, width: inner)) |
| + return finish(plate, height: y - MacMetric.gap + MacMetric.pad) |
| + } |
| let head = card.question.isEmpty ? (taskTitle ?? EquipoStrings.text("decision.untitled")) : card.question |
| add(makeText(head, MacType.line, .webText, width: inner, lineSpacing: 2, selectable: true), gap: 4) |
| + // Merges and "Does main ship?" are answered here, in the web's words. |
| + if let view = decision { |
| + if view.hasPreview { |
| + let preview = Feed.previewURL(card, origin: session.origin) |
| + add(button(EquipoStrings.text("chat.card.preview_link"), .link) { NSWorkspace.shared.open(preview) }) |
| + } |
| + if view.open { |
| + if let seen = answeredRevision[card.id], !AnswerFeedback.stillChanged(conflictAt: seen, now: card.revision) { |
| + if case .sending = answers[card.id] {} else { answers[card.id] = nil; answeredRevision[card.id] = nil } |
| + } |
| + let state = answers[card.id] |
| + let sending: String? = { if case .sending(let v) = state { return v }; return nil }() |
| + let gap: CGFloat = 10 |
| + let w = floor((inner - gap * CGFloat(max(view.choices.count - 1, 0))) / CGFloat(max(view.choices.count, 1))) |
| + for (index, choice) in view.choices.enumerated() { |
| + let busy = sending == choice.value ? EquipoStrings.text("action.sending") : nil |
| + let b = button(choice.label, choice.primary ? .primary : .choice, busy: busy) { [weak self] in |
| + self?.submit(card: card, choice: choice.value) |
| + } |
| + if sending != nil && sending != choice.value { b.isEnabled = false } |
| + b.frame = NSRect(x: MacMetric.pad + CGFloat(index) * (w + gap), y: y, width: w, height: 32) |
| + b.setAccessibilityLabel(busy ?? choice.label) |
| + plate.content.addSubview(b) |
| + } |
| + y += 32 + MacMetric.gap |
| + let feedback: String? = { |
| + switch state { |
| + case .changed: return EquipoStrings.text("card.changed") |
| + case .offline: return EquipoStrings.text("card.offline") |
| + case .failed: return EquipoStrings.text("card.failed") |
| + default: return nil |
| + } |
| + }() |
| + if let feedback { |
| + let line = makeText(feedback, MacType.small, .webNegative, width: inner) |
| + line.setAccessibilityRole(.staticText) |
| + add(line) |
| + NSAccessibility.post(element: line, notification: .announcementRequested, userInfo: [.announcement: feedback]) |
| + } |
| + } |
| + return finish(plate, height: y - MacMetric.gap + MacMetric.pad) |
| + } |
| if card.isOpen { |
| add(makeText(EquipoStrings.text("decision.on_web"), MacType.small, .webSecondary, width: inner)) |
| } |
diff --git a/native/apple/Tests/EquipoKitTests/MergeCardTests.swift b/native/apple/Tests/EquipoKitTests/MergeCardTests.swift| new file mode 100644 |
| index 00000000..49f640db |
| --- /dev/null |
| +++ b/native/apple/Tests/EquipoKitTests/MergeCardTests.swift |
| @@ -0,0 +1,95 @@ |
| +import Foundation |
| +import Testing |
| +@testable import EquipoKit |
| + |
| +/// Merges answered on the device must match the web (parity row R-02, |
| +/// must_match): the server's question, the same choices in the same order |
| +/// with the same words, the same primary, and the same outcome line. |
| +@MainActor @Suite struct MergeCardTests { |
| + private func cards() throws -> [ThinCard] { |
| + let snapshot: Snapshot = try Fixture.decode("thin/snapshot") |
| + return snapshot.cards ?? [] |
| + } |
| + |
| + @Test func anOpenMergeIsAnsweredHereInTheWebsWords() throws { |
| + let card = try #require(try cards().first { $0.kind == "merge" && $0.state == "open" }) |
| + let view = try #require(Feed.decision(card, task: nil)) |
| + #expect(view.open) |
| + #expect(view.line == card.question, "the server's question, as the web shows it") |
| + #expect(view.choices.map(\.value) == ["merge", "wait_mac"], "the server's choices, in its order") |
| + #expect(view.choices.map(\.label) == ["Merge", "Wait for a Mac"]) |
| + #expect(view.choices.filter(\.primary).map(\.value) == ["merge"], "Merge is primary, as on the web") |
| + #expect(view.note == nil) |
| + } |
| + |
| + @Test func anAnsweredMergeSaysWhatWasChosen() throws { |
| + let card = try #require(try cards().first { $0.kind == "merge" && $0.state == "answered" }) |
| + let view = try #require(Feed.decision(card, task: nil)) |
| + #expect(!view.open) |
| + #expect(view.note == "Merging without checks.") |
| + var resolved = card; resolved.state = "resolved" |
| + #expect(Feed.decision(resolved, task: nil)?.note == "Nothing to decide any more.") |
| + } |
| + |
| + @Test func doesMainShipHasItsOwnPrimaryAndOutcome() throws { |
| + var card = try #require(try cards().first { $0.kind == "merge_ships" }) |
| + let view = try #require(Feed.decision(card, task: nil)) |
| + #expect(view.choices.map(\.label) == ["It ships", "It doesn't"]) |
| + #expect(view.choices.filter(\.primary).map(\.value) == ["not_ships"]) |
| + card.state = "answered"; card.choice = "ships" |
| + #expect(Feed.decision(card, task: nil)?.note == "Merging to main ships to users, so I'll ask before merging without checks.") |
| + } |
| + |
| + @Test func aMergeFromBeforeAnExplorationIsClosed() throws { |
| + let card = try #require(try cards().first { $0.kind == "merge" && $0.state == "open" }) |
| + let tasks: ThinList<ThinTask> = try Fixture.decode("thin/tasks") |
| + var task = try #require(tasks.items?.first); task.kind = "explore" |
| + let view = try #require(Feed.decision(card, task: task)) |
| + #expect(!view.open) |
| + #expect(view.note == "An earlier attempt to add this change was dropped when the task became an exploration.") |
| + } |
| + |
| + @Test func anUnknownChoiceSendsYouToTheWeb() throws { |
| + var card = try #require(try cards().first { $0.kind == "merge" && $0.state == "open" }) |
| + card.options = ["merge", "something_new"] |
| + #expect(Feed.decision(card, task: nil) == nil, "a choice with no words is never guessed at") |
| + for kind in ["publish", "direction", "merge_policy", "specialist", "question"] { |
| + var other = try #require(try cards().first { $0.kind == "merge" && $0.state == "open" }) |
| + other.kind = kind |
| + #expect(Feed.decision(other, task: nil) == nil, "\(kind) still opens the web, even with choices that have words") |
| + } |
| + } |
| + |
| + @Test func thePreviewOpensThroughTheWebsWrapperOnly() throws { |
| + let origin = URL(string: "https://team.example.test")! |
| + var card = try #require(try cards().first { $0.kind == "merge" && $0.state == "open" }) |
| + #expect(Feed.decision(card, task: nil)?.hasPreview == false, "no preview yet, no link") |
| + // Whatever the candidate's own address, the device opens Equipo's wrapper page. |
| + for raw in ["https://preview.example.test/x", "https://equipo.example@evil.test/", "javascript:alert(1)"] { |
| + card.previewUrl = raw |
| + #expect(Feed.decision(card, task: nil)?.hasPreview == true) |
| + #expect(Feed.previewURL(card, origin: origin).absoluteString == "https://team.example.test/tasks/\(card.taskId)/preview") |
| + } |
| + var ships = try #require(try cards().first { $0.kind == "merge_ships" }) |
| + ships.previewUrl = "https://preview.example.test/x" |
| + #expect(Feed.decision(ships, task: nil)?.hasPreview == false, "the web links a preview only on merge cards") |
| + } |
| + |
| + @Test func aClosedCardShowsOnlyItsOutcome() throws { |
| + var card = try #require(try cards().first { $0.kind == "merge" && $0.state == "answered" }) |
| + card.previewUrl = "https://preview.example.test/x" |
| + let view = try #require(Feed.decision(card, task: nil)) |
| + #expect(view.showsOnlyNote, "as chat.html's equipo-card-done: the note and nothing else") |
| + #expect(!view.hasPreview) |
| + var ships = try #require(try cards().first { $0.kind == "merge_ships" }) |
| + ships.options = [] |
| + let empty = try #require(Feed.decision(ships, task: nil)) |
| + #expect(!empty.open, "a ships card with no choices is not open, as on the web") |
| + } |
| + |
| + @Test func aChangedCardKeepsSayingSoUntilItMovesOn() { |
| + // The conflict returns the card at revision 7: the message stays at 7 and goes after it. |
| + #expect(AnswerFeedback.stillChanged(conflictAt: 7, now: 7)) |
| + #expect(!AnswerFeedback.stillChanged(conflictAt: 7, now: 8)) |
| + } |
| +} |
diff --git a/native/scripts/check-native.sh b/native/scripts/check-native.sh| index ffb16940..13cb067a 100755 |
| --- a/native/scripts/check-native.sh |
| +++ b/native/scripts/check-native.sh |
| @@ -7,6 +7,7 @@ cd "$(dirname "$0")/.." |
| logs=build/logs; mkdir -p "$logs" |
| python3 scripts/check-fixtures.py |
| python3 scripts/check-strings.py |
| +python3 scripts/check-parity.py |
| # The repository-wide reference scan (make ci) reads native files too. |
| python3 ../scripts/runner-dead-references.py |
| swift test --package-path apple > "$logs/swift-test.log" 2>&1 || { tail -40 "$logs/swift-test.log"; exit 1; } |
diff --git a/native/scripts/check-parity.py b/native/scripts/check-parity.py| new file mode 100755 |
| index 00000000..2d0a11c4 |
| --- /dev/null |
| +++ b/native/scripts/check-parity.py |
| @@ -0,0 +1,32 @@ |
| +#!/usr/bin/env python3 |
| +"""Keep the native apps in the web's words where they must match. |
| + |
| +Every native string whose key is one of the web's copy keys (chat.card.*, |
| +work.tl.*) must equal copy.go's text for that key, so a merge card says |
| +exactly what the web says (sync proposal, parity row R-02).""" |
| +import json, re, sys |
| +from pathlib import Path |
| + |
| +native = Path(__file__).resolve().parents[1] |
| +strings = json.loads((native / 'scripts/strings.json').read_text()) |
| +copy = (native.parent / 'internal/equipo/copy.go').read_text() |
| +problems, checked = [], 0 |
| +# Every outcome the web can show for a decision answered here needs native |
| +# words, or the answered card would silently show none. |
| +for pattern in (r'chat\.card\.merge_chose_\w+', r'chat\.card\.ships_chose_\w+'): |
| + for key in sorted(set(re.findall('"(' + pattern + ')":', copy))): |
| + if key not in strings: |
| + problems.append(f'{key}: the web has this outcome; native has no words for it') |
| +for key, text in sorted(strings.items()): |
| + if not key.startswith(('chat.card.', 'work.tl.')): |
| + continue |
| + found = re.findall(r'"' + re.escape(key) + r'":\s*"((?:[^"\\]|\\.)*)"', copy) |
| + if len(found) != 1: |
| + problems.append(f'{key}: found {len(found)} times in copy.go, expected once'); continue |
| + web = json.loads('"' + found[0] + '"') |
| + checked += 1 |
| + if web != text: |
| + problems.append(f'{key}: native says {text!r}, the web says {web!r}') |
| +for p in problems: print(p) |
| +if problems: sys.exit(1) |
| +print(f'{checked} native strings match the web') |
diff --git a/native/scripts/check-strings.py b/native/scripts/check-strings.py| index f0600a09..e81d8b18 100755 |
| --- a/native/scripts/check-strings.py |
| +++ b/native/scripts/check-strings.py |
| @@ -43,6 +43,6 @@ for p in problems: print(p) |
| if problems: sys.exit(1) |
| # Facts look their words up by a key made from the wire value |
| # (TaskReport.facts); FactWordsTests checks each one resolves. |
| -computed = {k for k in source if k.startswith(('checks.', 'review.'))} |
| +computed = {k for k in source if k.startswith(('checks.', 'review.', 'chat.card.', 'work.tl.'))} |
| unused = sorted(source.keys() - used_keys() - computed) |
| print(f'{len(source)} strings, all used keys present' + (f'; unused: {unused}' if unused else '')) |
diff --git a/native/scripts/strings.json b/native/scripts/strings.json| index b5882da5..15aff146 100644 |
| --- a/native/scripts/strings.json |
| +++ b/native/scripts/strings.json |
| @@ -21,6 +21,21 @@ |
| "card.offline": "Couldn’t reach your team. Try again.", |
| "card.open_on_web": "Open in Equipo on the web", |
| "card.question": "Question", |
| + "chat.card.merge": "Merge", |
| + "chat.card.merge_chose_merge": "Merging without checks.", |
| + "chat.card.merge_chose_not_now": "Not now.", |
| + "chat.card.merge_chose_wait": "Waiting for checks.", |
| + "chat.card.merge_chose_wait_mac": "Waiting for a Mac.", |
| + "chat.card.merge_policy_stale": "The merge rules changed since I asked, so nothing was saved.", |
| + "chat.card.merge_resolved": "Nothing to decide any more.", |
| + "chat.card.not_now": "Not now", |
| + "chat.card.not_ships": "It doesn't", |
| + "chat.card.preview_link": "Open the preview", |
| + "chat.card.ships": "It ships", |
| + "chat.card.ships_chose_not_ships": "Main isn't a release, so I can merge small changes on my own when the other rules allow.", |
| + "chat.card.ships_chose_ships": "Merging to main ships to users, so I'll ask before merging without checks.", |
| + "chat.card.wait": "Wait for checks", |
| + "chat.card.wait_mac": "Wait for a Mac", |
| "checks.cannot_run": "Can’t run here", |
| "checks.exit %@ %@": "%1$@, exit code %2$@", |
| "checks.failed": "Failed", |
| @@ -141,5 +156,6 @@ |
| "thread.reading %@": "%@ is reading", |
| "thread.sent": "Sent", |
| "track.position %@ %@": "%1$@ of %2$@", |
| - "track.spoken %@": "Stage: %@" |
| + "track.spoken %@": "Stage: %@", |
| + "work.tl.merge_dropped": "An earlier attempt to add this change was dropped when the task became an exploration." |
| } |