oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1#if DEBUG
2import SwiftUI
3#if os(macOS)
4import AppKit
5#endif
6
7/// Offline task-view review fixture. It uses the production task screen and
8/// wire decoder; no live credential, project, or mutation is involved.
9public struct TaskViewFixture: View {
10 @State private var session = makeSession()
11 public init() {}
12 private static func makeSession() -> EquipoSession {
13 let transport = TaskViewFixtureTransport()
14 var account = DeviceAccount.new(origin: transport.origin, label: "Fixture")
15 account.credential = DeviceCredential(id: "fixture", token: "fixture", audience: "equipo.person.v1", instanceId: "fixture", expiresAt: .distantFuture)
16 return EquipoSession(account: account, accounts: DeviceAccounts(store: MemorySecretStore()), transport: transport)
17 }
18 public var body: some View {
19 NavigationStack {
20 TaskScreen(session: session, taskID: "tk_fixture")
21 .navigationTitle(EquipoStrings.text("task.title"))
22 #if os(iOS)
23 .navigationBarTitleDisplayMode(.inline)
24 #endif
25 }
26 .modifier(SettingsSheetPresenter(session: session))
27 .preferredColorScheme(.light)
28 .task {
29 await session.refresh()
30 #if os(macOS)
31 if let path = ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_CAPTURE"] {
32 try? await Task.sleep(for: .seconds(2))
33 if let window = NSApp.windows.first(where: { $0.isVisible && $0.isSheet }) ?? NSApp.windows.first(where: { $0.isVisible && !$0.isSheet }), let view = window.contentView {
34 window.setContentSize(NSSize(width: 800, height: window.isSheet ? 600 : 1000))
35 view.layoutSubtreeIfNeeded(); window.displayIfNeeded()
36 if let bitmap = view.bitmapImageRepForCachingDisplay(in: view.bounds) {
37 view.cacheDisplay(in: view.bounds, to: bitmap)
38 if let data = bitmap.representation(using: .png, properties: [:]) { _ = FileManager.default.createFile(atPath: path, contents: data) }
39 }
40 }
41 }
42 #endif
43 }
44 }
45}
46
47struct TaskViewFixtureTransport: EquipoTransport {
48 private var changes: Bool { (ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] ?? "").hasPrefix("changes") }
49 private var hiddenNames: Bool { (ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] ?? "").hasPrefix("changes-diff") || ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "changes-hidden" }
50 private var candidate: String { changes ? String(repeating: "b", count: 40) : "3f9c2a167de8" }
51 private var hosted: Bool { ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "hosted" }
52 private var failed: Bool { hosted || ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "checks" }
53 let origin = URL(string: "https://fixture.invalid")!
54 func send(_ request: APIRequest) async throws -> APIResponse {
55 let value: [String: Any]
56 switch request.path {
57 case "/snapshot":
58 value = ["me": ["id": "fixture", "address": "paul@example.com", "role": "owner", "team_id": "fixture", "team_name": "Oficina", "revision": 1], "cursor": 1, "tasks": [task], "messages": [], "turns": [], "cards": failed ? [] : [card], "projects": []]
59 case "/tasks", "/needs-you": value = ["items": [task]]
60 case "/tasks/tk_fixture": value = task
61 case "/tasks/tk_fixture/changes/diff":
62 let path = request.query.first(where: { $0.name == "path" })?.value ?? "Sources/Session/EquipoSession.swift"
63 value = ["task_id": "tk_fixture", "step_id": "engineering", "attempt": 1,
64 "base": String(repeating: "a", count: 40), "candidate_sha": candidate,
65 "path": path, "status": "modified", "truncated": false, "hidden_characters": true,
66 "patch": ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "changes-diff-long"
67 ? "+" + String(repeating: " ", count: 2000) + "evil()\r\n+warning = \"⚠️\"; rogue = \"x\u{FE0F}\"\n+safe\u{3164}\u{034F}\u{202E}end\n"
68 : "diff --git a/\(path) b/\(path)\n--- a/\(path)\n+++ b/\(path)\n@@ -42,6 +42,8 @@\n func signOut() {\n+ needsYouCount = 0 // \u{202E}hidden\u{202C}\u{200B}\n+ accountGeneration += 1 // \u{3164}\u{034F}\u{FE0F}\n+ reset() // \u{001B}\r\n credential = nil\n- refreshBadge()\n+ notifications.updateBadge(count: 0, account: signedOutAccount, reason: .signedOut)\n }\n"]
69 case "/steps/checks/log": value = ["step_id": "checks", "attempt": 1, "tail": hosted ? "Hosted CI on oficina/equipo at 3f9c2a1: failed.\nFailed: format; check shard 5 of 23\n=== format\nThe changed Swift file needs formatting.\n=== check shard 5 of 23\nTest needsBadgeClearsAfterSignOut failed\nExpected: 0\nReceived: 1\n" : "=== formatting\nFormatting passed.\n=== native-tests\nRunning EquipoKitTests\nTest needsBadgeClearsAfterSignOut failed\nExpected: 0\nReceived: 1\nThe signed-out account still contributes to the Needs you badge.\nexit status 1"]
70 case "/projects": value = ["items": [], "allowed": ["oficina/equipo", "oficina/notes"]]
71 default: value = [:]
72 }
73 return APIResponse(status: 200, data: try JSONSerialization.data(withJSONObject: value))
74 }
75 func lines(_ request: APIRequest) async throws -> AsyncThrowingStream<String, Error> { AsyncThrowingStream { $0.finish() } }
76 private var changeFiles: [String: Any] {
77 let base = String(repeating: "a", count: 40)
78 func file(_ path: String, _ status: String, _ added: Int = 0, _ removed: Int = 0, old: String? = nil, binary: Bool = false) -> [String: Any] {
79 var result: [String: Any] = ["path": path, "status": status, "additions": added, "deletions": removed, "binary": binary]
80 if let old { result["old_path"] = old }
81 return result
82 }
83 if ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "changes-long" {
84 return ["base": base, "sha": candidate, "files": 203, "additions": 203, "deletions": 0, "binary": 0,
85 "entries": (0..<200).map { file("Sources/Folder\($0 % 4)/File\($0).swift", "added", 1) }, "truncated": true]
86 }
87 return ["base": base, "sha": candidate, "files": 6, "additions": 55, "deletions": 10, "binary": 1, "truncated": false,
88 "entries": [
89 file(hiddenNames ? "Sources/Session/Equipo\u{3164}Session.swift" : "Sources/Session/EquipoSession.swift", "modified", 24, 4),
90 file("Tests/NeedsBadgeTests.swift", "modified", 19, 2),
91 file("Sources/Needs/Badge.swift", "added", 12),
92 file("Resources/Badge.png", "modified", binary: true),
93 file("docs/Badge behaviour.md", "renamed", old: hiddenNames ? "docs/Ba\u{034F}dge notes.md" : "docs/Badge notes.md"),
94 file("Sources/Needs/OldBadge.swift", "deleted", 0, 4)
95 ]]
96 }
97 private var card: [String: Any] {
98 ["id": "card_merge", "revision": 3, "kind": "merge", "state": "open", "turn_id": "", "project_id": "project", "name": "", "question": "Merge the fix for the Needs you badge?", "options": ["merge", "not_now"], "choice": "", "task_id": "tk_fixture", "created_at": "2026-11-26T09:42:00Z", "updated_at": "2026-11-26T09:42:00Z"]
99 }
100 private var task: [String: Any] {
101 func step(_ id: String, _ specialist: String, _ headline: String, _ summary: String = "") -> [String: Any] {
102 ["id": id, "specialist": specialist, "candidate_sha": candidate, "state": "done", "reason": "", "headline": headline, "summary": summary, "verdict": "", "review_label": "", "checks": "", "gate": "", "started_at": "2026-11-26T09:42:00Z", "finished_at": "2026-11-26T09:48:00Z"]
103 }
104 var checks = step("checks", "checks", failed ? "One test failed" : "Native checks passed")
105 checks["checks"] = failed ? "failed" : "passed"; checks["gate"] = ".amadan/ci.d"; checks["exit_code"] = failed ? 1 : 0
106 if hosted { checks["gate"] = "hosted CI"; checks["hosted"] = ["failed": ["format", "check shard 5 of 23"]] }
107 var review = step("review", "review", "Approved", "The badge now resets when the person signs out. The account lifetime guard also prevents late updates from restoring the old count.")
108 review["verdict"] = "approve"; review["review_label"] = "approved"
109 let earlierReview = review
110 if failed {
111 review["id"] = "review-latest"
112 review["headline"] = "Changes requested"
113 review["summary"] = "The signed-out account still contributes to the Needs you badge. Clear its count and prevent late requests from restoring it."
114 review["verdict"] = "changes_requested"; review["review_label"] = "changes_requested"
115 }
116 var engineering = step("engineering", "engineering", "Clear the badge when signing out")
117 if changes && ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] != "changes-old" {
118 engineering["base_sha"] = String(repeating: "a", count: 40)
119 engineering["change_files"] = changeFiles
120 }
121 let steps = failed
122 ? [engineering, earlierReview, checks, review]
123 : [engineering, checks, review]
124 return ["id": "tk_fixture", "revision": 9, "project_id": "project", "project": "Equipo", "repo": "oficina/equipo", "title": "Fix the Needs you badge after sign-out", "brief": "When I sign out on my iPhone, the Needs you badge still shows the old count. Clear it as soon as I sign out, and keep it clear if a request finishes afterwards.", "stage": "ready_to_merge", "branch": "equipo/needs-badge-sign-out", "url": "https://amadan.net/oficina/equipo", "candidate_sha": candidate, "checks": failed ? "failed" : "passed", "checks_reason": "", "verdict": failed ? "changes_requested" : "approve", "review_label": failed ? "changes_requested" : "approved", "needs_you": failed ? "fix_rounds" : "merge", "merge_offered": !failed, "creator": "paul@example.com", "created_at": "2026-11-26T09:40:00Z", "updated_at": "2026-11-26T09:48:00Z", "steps": steps]
125 }
126}
127#endif
128