| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import EquipoKit |
| 4 | |
| 5 | @Suite struct NeedsRowActionTests { |
| 6 | static func stopped() throws -> ThinTask { |
| 7 | var task = try TaskDetailTests.task() |
| 8 | task.stage = "in_progress"; task.needsYou = "retry" |
| 9 | var step = task.steps![0]; step.state = "failed"; step.reason = "push_failed"; step.terminated = true |
| 10 | task.steps = [step]; return task |
| 11 | } |
| 12 | static func action(_ task: ThinTask, cards: [ThinCard] = [], mine: Bool = true, owner: Bool = true, resume: Bool = false) -> NeedsRowAction { |
| 13 | .init(task: task, cards: cards, mine: mine, owner: owner, canResume: resume) |
| 14 | } |
| 15 | @Test func retryIsTheListDecisionNotTheBroaderMenuOffer() throws { |
| 16 | var task = try Self.stopped() |
| 17 | for need in ["retry", "review_blocked"] { |
| 18 | task.needsYou = need; #expect(Self.action(task).kind == .retry) |
| 19 | } |
| 20 | for need in ["fix_rounds", "merge_conflict", "branch_moved", "machine_removed", "direction", "future", ""] { |
| 21 | task.needsYou = need; #expect(Self.action(task).kind == .open) |
| 22 | } |
| 23 | task.needsYou = "retry"; task.steps![0].terminated = false |
| 24 | #expect(Self.action(task).kind == .open) |
| 25 | task.steps![0].terminated = true; task.steps![0].state = "done" |
| 26 | #expect(Self.action(task).kind == .open) |
| 27 | } |
| 28 | @Test(arguments: ["other_creator", "member", "done", "cancelled", "merging", "moving", "stopping", "copy_hold", "copy_skip"]) |
| 29 | func ownershipAndLifecycleGuardRows(_ state: String) throws { |
| 30 | var task = try Self.stopped() |
| 31 | if ["done", "cancelled", "merging"].contains(state) { task.stage = state } |
| 32 | if state == "moving" { task.moving = true } |
| 33 | if state == "stopping" { task.stopping = true } |
| 34 | if state == "copy_hold" { task.copyHold = true } |
| 35 | if state == "copy_skip" { task.copyCanSkip = true } |
| 36 | #expect(Self.action(task, mine: state != "other_creator", owner: state != "member").kind == .open) |
| 37 | } |
| 38 | @Test func questionRendersAndMergeRequiresTheActualDecisionChoice() throws { |
| 39 | var task = try Self.stopped(); task.needsYou = "merge" |
| 40 | var merge = try TaskDecisionTests.card(task) |
| 41 | var question = try TaskDecisionTests.card(task, kind: "question", options: ["Yes", "No"]) |
| 42 | question.id = "question"; question.createdAt = merge.createdAt.addingTimeInterval(1) |
| 43 | #expect(Self.action(task, cards: [question]).kind == .question) |
| 44 | #expect(Self.action(task, cards: [question]).card?.id == question.id) |
| 45 | #expect(Self.action(task, cards: [merge, question]).kind == .merge) |
| 46 | task.needsYou = "retry" |
| 47 | #expect(Self.action(task, cards: [merge]).kind == .open) |
| 48 | task.needsYou = "merge"; merge.options = ["wait"] |
| 49 | #expect(Self.action(task, cards: [merge]).kind == .open) |
| 50 | merge.options = ["merge", "future"] |
| 51 | #expect(Self.action(task, cards: [merge]).kind == .open) |
| 52 | merge.state = "answered" |
| 53 | #expect(Self.action(task, cards: [merge]).kind == .open) |
| 54 | // A menu offer without a merge card is not a list decision. |
| 55 | #expect(Self.action(task).kind == .open) |
| 56 | } |
| 57 | @Test func holdsReuseTheResumeMatchAndRunNowOffer() throws { |
| 58 | var task = try Self.stopped(); task.needsYou = "held" |
| 59 | task.steps![0].state = "running" |
| 60 | task.steps![0].hold = ThinHold(reason: "spend_unknown", connection: "local", provider: "codex", stepRevision: 9) |
| 61 | #expect(Self.action(task, resume: false).kind == .open) |
| 62 | #expect(Self.action(task, resume: true).kind == .resume) |
| 63 | task.steps![0].hold?.reason = "headroom" |
| 64 | #expect(Self.action(task, resume: true).kind == .open) |
| 65 | task.steps![0].paused = ThinPaused(runNow: ThinRunNow(connection: "connection", name: "Codex")) |
| 66 | #expect(Self.action(task).kind == .runNow) |
| 67 | #expect(Self.action(task).pause?.runNow?.revision == 9) |
| 68 | task.needsYou = "fix_rounds" |
| 69 | #expect(Self.action(task, resume: true).kind == .open) |
| 70 | task.needsYou = "" |
| 71 | #expect(Self.action(task, resume: true).kind == .open) |
| 72 | task.needsYou = "held"; task.steps![0].paused = nil |
| 73 | let held = try TaskDecisionTests.card(task, kind: "held", options: ["run_now", "wait"]) |
| 74 | #expect(Self.action(task, cards: [held]).kind == .open) |
| 75 | task.steps![0].paused = ThinPaused(runNow: ThinRunNow(connection: "shown", name: "Codex")) |
| 76 | #expect(Self.action(task, cards: [held]).kind == .runNow) |
| 77 | #expect(Self.action(task, cards: [held]).card?.id == held.id) |
| 78 | task.needsYou = "retry" |
| 79 | #expect(Self.action(task, cards: [held]).kind == .open) |
| 80 | task.needsYou = "held" |
| 81 | var wait = held; wait.options = ["wait"] |
| 82 | #expect(Self.action(task, cards: [wait]).kind == .open) |
| 83 | wait.options = ["run_now", "future"] |
| 84 | #expect(Self.action(task, cards: [wait]).kind == .open) |
| 85 | } |
| 86 | } |
| 87 | |