oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2import Testing
3@testable import EquipoKit
4
5/// Paused work (spec 2026-11-24-paused-work-design.md): a held step is
6/// never a false green. Paul's case: Engineering held for the Claude
7/// allowance, which resets at 21:00 UTC; Codex has room; noon in Dublin.
8@MainActor @Suite struct PausedTests {
9 private let dublin = TimeZone(identifier: "Europe/Dublin")!
10 private let britain = Locale(identifier: "en_GB")
11 private let noon = ISO8601DateFormatter().date(from: "2026-11-24T12:00:00Z")!
12
13 private func task(_ step: String) throws -> ThinTask {
14 let json = """
15 {"id":"tk1","revision":3,"project_id":"p_1","project":"Equipo","title":"Swipe down to dismiss the keyboard on iOS","brief":"","stage":"in_progress","branch":"","url":"","candidate_sha":"","checks":"","checks_reason":"","verdict":"","review_label":"","needs_you":"","creator":"paul@example.com","created_at":"2026-11-24T09:00:00Z","updated_at":"2026-11-24T09:00:00Z","steps":[\(step)]}
16 """
17 return try EquipoJSON.decoder.decode(ThinTask.self, from: Data(json.utf8))
18 }
19 private let held = """
20 {"id":"s1","specialist":"engineering","state":"queued","reason":"","summary":"","headline":"","verdict":"","review_label":"","checks":"","gate":"","runner_label":"Paul’s Mac mini","hold":{"reason":"headroom","connection":"claude-1","provider":"claude","resets_at":"2026-11-24T21:00:00Z","wake_at":"2026-11-24T21:00:00Z","step_revision":4},"paused":{"since":"2026-11-24T09:00:00Z","used_percent":100,"run_now":{"connection":"cn_codex","provider":"codex","name":"Codex","billing":"subscription"}}}
21 """
22
23 @Test func paulsCaseIsPausedNotGreen() throws {
24 let t = try task(held)
25 #expect(t.steps?.first?.hold?.stepRevision == 4, "the hold decodes")
26 let pause = try #require(TaskPause(t, mine: true, now: noon, zone: dublin, locale: britain))
27 #expect(pause.tone == .paused)
28 #expect(pause.stop == "Paused")
29 #expect(pause.strong == "Paused until 21:00 tonight")
30 #expect(pause.rest == " (in 9 hours): your Claude allowance has run out.")
31 #expect(pause.next == "It carries on by itself then.")
32 #expect(pause.runNow == TaskPause.RunNow(label: "Run it now with Codex", step: "s1", revision: 4, offer: "cn_codex"))
33 #expect(pause.note == "Codex has room now")
34 var report = TaskReport(t, needsYou: false, mine: true, now: noon)
35 report.pause = pause
36 let current = try #require(report.track.first { $0.state == .current })
37 #expect(current.tone == .paused && current.label == "Paused" && current.stage == .inProgress)
38 }
39
40 @Test func someoneElseIsNotOfferedRunNow() throws {
41 let pause = try #require(TaskPause(try task(held), mine: false, now: noon, zone: dublin, locale: britain))
42 #expect(pause.runNow == nil && pause.strong == "Paused until 21:00 tonight")
43 }
44
45 @Test func theDevicesZoneMovesTheWords() throws {
46 let madrid = TimeZone(identifier: "Europe/Madrid")!
47 let pause = try #require(TaskPause(try task(held), mine: true, now: noon, zone: madrid, locale: britain))
48 #expect(pause.strong == "Paused until 22:00 tonight")
49 }
50
51 @Test func aRunningStepIsNotPaused() throws {
52 let running = """
53 {"id":"s1","specialist":"engineering","state":"running","reason":"","summary":"","headline":"","verdict":"","review_label":"","checks":"","gate":""}
54 """
55 #expect(TaskPause(try task(running), mine: true, now: noon, zone: dublin, locale: britain) == nil)
56 let report = TaskReport(try task(running), needsYou: false, mine: true, now: noon)
57 #expect(report.track.first { $0.state == .current }?.label == nil)
58 }
59
60 @Test func otherReasonsKeepTheColourRule() throws {
61 let busy = held.replacingOccurrences(of: "\"reason\":\"headroom\"", with: "\"reason\":\"busy\"").replacingOccurrences(of: "\"provider\":\"claude\"", with: "\"provider\":\"tensorx\"")
62 let b = try #require(TaskPause(try task(busy), mine: true, now: noon, zone: dublin, locale: britain))
63 #expect(b.tone == .paused && b.strong == "Paused for a moment:" && b.rest == " TensorX is busy with another step for you.")
64 let unknown = held.replacingOccurrences(of: "\"reason\":\"headroom\"", with: "\"reason\":\"spend_unknown\"").replacingOccurrences(of: "\"provider\":\"claude\"", with: "\"provider\":\"tensorx\"")
65 let u = try #require(TaskPause(try task(unknown), mine: true, now: noon, zone: dublin, locale: britain))
66 #expect(u.tone == .warning && u.stop == "Needs you" && u.strong == "Paused:")
67 let failed = """
68 {"id":"s1","specialist":"engineering","state":"failed","reason":"push_failed","summary":"","headline":"","verdict":"","review_label":"","checks":"","gate":""}
69 """
70 let f = try #require(TaskPause(try task(failed), mine: true, now: noon, zone: dublin, locale: britain))
71 #expect(f.tone == .negative && f.stop == "Stopped")
72 }
73
74 @Test func aRunnerTooOldWaitsForItsUpdate() throws {
75 let old = """
76 {"id":"s1","specialist":"engineering","state":"failed","reason":"runner_outdated","summary":"","headline":"","verdict":"","review_label":"","checks":"","gate":"","runner_label":"DOCS-T1"}
77 """
78 let p = try #require(TaskPause(try task(old), mine: true, now: noon, zone: dublin, locale: britain))
79 #expect(p.tone == .warning && p.stop == "Needs you" && p.strong == "Waiting for an update:" && p.rest == " the runner on DOCS-T1 is too old for this step.")
80 #expect(p.next == "It carries on by itself once the runner is updated.")
81 }
82
83 @Test func anOlderRunnerGetsPlainRunNow() throws {
84 let plain = held.replacingOccurrences(of: "\"run_now\":{\"connection\":\"cn_codex\",\"provider\":\"codex\",\"name\":\"Codex\",\"billing\":\"subscription\"}", with: "\"run_now\":{\"plain\":true,\"may_bill\":true}")
85 let p = try #require(TaskPause(try task(plain), mine: true, now: noon, zone: dublin, locale: britain))
86 #expect(p.runNow?.label == "Run it now anyway" && p.runNow?.offer == "plain" && p.note == "This may use a plan that bills per use.")
87 }
88
89 @Test func anOfflineRunnerIsNamed() throws {
90 let offline = """
91 {"id":"s1","specialist":"engineering","state":"queued","reason":"","summary":"","headline":"","verdict":"","review_label":"","checks":"","gate":"","runner_label":"DOCS-T1","paused":{"offline":true,"since":"2026-11-24T11:20:00Z"}}
92 """
93 let p = try #require(TaskPause(try task(offline), mine: true, now: noon, zone: dublin, locale: britain))
94 #expect(p.strong == "Paused since 11:20:" && p.next == "It carries on by itself when DOCS-T1 is back online.")
95 }
96}
97
98