#if DEBUG import SwiftUI #if os(macOS) import AppKit #endif /// Offline task-view review fixture. It uses the production task screen and /// wire decoder; no live credential, project, or mutation is involved. public struct TaskViewFixture: View { @State private var session = makeSession() public init() {} private static func makeSession() -> EquipoSession { let transport = TaskViewFixtureTransport() var account = DeviceAccount.new(origin: transport.origin, label: "Fixture") account.credential = DeviceCredential(id: "fixture", token: "fixture", audience: "equipo.person.v1", instanceId: "fixture", expiresAt: .distantFuture) return EquipoSession(account: account, accounts: DeviceAccounts(store: MemorySecretStore()), transport: transport) } public var body: some View { NavigationStack { TaskScreen(session: session, taskID: "tk_fixture") .navigationTitle(EquipoStrings.text("task.title")) #if os(iOS) .navigationBarTitleDisplayMode(.inline) #endif } .modifier(SettingsSheetPresenter(session: session)) .preferredColorScheme(.light) .task { await session.refresh() #if os(macOS) if let path = ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_CAPTURE"] { try? await Task.sleep(for: .seconds(2)) if let window = NSApp.windows.first(where: { $0.isVisible && $0.isSheet }) ?? NSApp.windows.first(where: { $0.isVisible && !$0.isSheet }), let view = window.contentView { window.setContentSize(NSSize(width: 800, height: window.isSheet ? 600 : 1000)) view.layoutSubtreeIfNeeded(); window.displayIfNeeded() if let bitmap = view.bitmapImageRepForCachingDisplay(in: view.bounds) { view.cacheDisplay(in: view.bounds, to: bitmap) if let data = bitmap.representation(using: .png, properties: [:]) { _ = FileManager.default.createFile(atPath: path, contents: data) } } } } #endif } } } struct TaskViewFixtureTransport: EquipoTransport { private var changes: Bool { (ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] ?? "").hasPrefix("changes") } private var hiddenNames: Bool { (ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] ?? "").hasPrefix("changes-diff") || ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "changes-hidden" } private var candidate: String { changes ? String(repeating: "b", count: 40) : "3f9c2a167de8" } private var hosted: Bool { ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "hosted" } private var failed: Bool { hosted || ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "checks" } let origin = URL(string: "https://fixture.invalid")! func send(_ request: APIRequest) async throws -> APIResponse { let value: [String: Any] switch request.path { case "/snapshot": 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": []] case "/tasks", "/needs-you": value = ["items": [task]] case "/tasks/tk_fixture": value = task case "/tasks/tk_fixture/changes/diff": let path = request.query.first(where: { $0.name == "path" })?.value ?? "Sources/Session/EquipoSession.swift" value = ["task_id": "tk_fixture", "step_id": "engineering", "attempt": 1, "base": String(repeating: "a", count: 40), "candidate_sha": candidate, "path": path, "status": "modified", "truncated": false, "hidden_characters": true, "patch": ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "changes-diff-long" ? "+" + String(repeating: " ", count: 2000) + "evil()\r\n+warning = \"⚠️\"; rogue = \"x\u{FE0F}\"\n+safe\u{3164}\u{034F}\u{202E}end\n" : "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"] 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"] case "/projects": value = ["items": [], "allowed": ["oficina/equipo", "oficina/notes"]] default: value = [:] } return APIResponse(status: 200, data: try JSONSerialization.data(withJSONObject: value)) } func lines(_ request: APIRequest) async throws -> AsyncThrowingStream { AsyncThrowingStream { $0.finish() } } private var changeFiles: [String: Any] { let base = String(repeating: "a", count: 40) func file(_ path: String, _ status: String, _ added: Int = 0, _ removed: Int = 0, old: String? = nil, binary: Bool = false) -> [String: Any] { var result: [String: Any] = ["path": path, "status": status, "additions": added, "deletions": removed, "binary": binary] if let old { result["old_path"] = old } return result } if ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] == "changes-long" { return ["base": base, "sha": candidate, "files": 203, "additions": 203, "deletions": 0, "binary": 0, "entries": (0..<200).map { file("Sources/Folder\($0 % 4)/File\($0).swift", "added", 1) }, "truncated": true] } return ["base": base, "sha": candidate, "files": 6, "additions": 55, "deletions": 10, "binary": 1, "truncated": false, "entries": [ file(hiddenNames ? "Sources/Session/Equipo\u{3164}Session.swift" : "Sources/Session/EquipoSession.swift", "modified", 24, 4), file("Tests/NeedsBadgeTests.swift", "modified", 19, 2), file("Sources/Needs/Badge.swift", "added", 12), file("Resources/Badge.png", "modified", binary: true), file("docs/Badge behaviour.md", "renamed", old: hiddenNames ? "docs/Ba\u{034F}dge notes.md" : "docs/Badge notes.md"), file("Sources/Needs/OldBadge.swift", "deleted", 0, 4) ]] } private var card: [String: Any] { ["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"] } private var task: [String: Any] { func step(_ id: String, _ specialist: String, _ headline: String, _ summary: String = "") -> [String: Any] { ["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"] } var checks = step("checks", "checks", failed ? "One test failed" : "Native checks passed") checks["checks"] = failed ? "failed" : "passed"; checks["gate"] = ".amadan/ci.d"; checks["exit_code"] = failed ? 1 : 0 if hosted { checks["gate"] = "hosted CI"; checks["hosted"] = ["failed": ["format", "check shard 5 of 23"]] } 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.") review["verdict"] = "approve"; review["review_label"] = "approved" let earlierReview = review if failed { review["id"] = "review-latest" review["headline"] = "Changes requested" review["summary"] = "The signed-out account still contributes to the Needs you badge. Clear its count and prevent late requests from restoring it." review["verdict"] = "changes_requested"; review["review_label"] = "changes_requested" } var engineering = step("engineering", "engineering", "Clear the badge when signing out") if changes && ProcessInfo.processInfo.environment["EQUIPO_TASK_FIXTURE"] != "changes-old" { engineering["base_sha"] = String(repeating: "a", count: 40) engineering["change_files"] = changeFiles } let steps = failed ? [engineering, earlierReview, checks, review] : [engineering, checks, review] 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] } } #endif