#if DEBUG import SwiftUI #if os(macOS) import AppKit #endif /// Offline visual fixture. Only compiled into Debug builds; never touches a /// saved account, keychain or network. Launch with EQUIPO_STOPPED_FIXTURE. public struct StoppedWorkFixture: View { @State private var session: EquipoSession public init() { session = Self.makeSession() } public static func makeSession() -> EquipoSession { let transport = StoppedFixtureTransport() 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: "fixture") .navigationTitle(EquipoStrings.text("task.title")) } .modifier(SettingsSheetPresenter(session: session)) .task { await session.refresh() #if os(macOS) // Capture this app's own native window when desktop recording is // unavailable. No other app or screen is read. 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 }), let view = window.contentView { window.setContentSize(NSSize(width: 800, height: 850)) 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 } } } private struct StoppedFixtureTransport: EquipoTransport { let origin = URL(string: "https://fixture.invalid")! private var resume: Bool { ProcessInfo.processInfo.environment["EQUIPO_STOPPED_FIXTURE"] == "conversation-resume" } private var paused: Bool { ProcessInfo.processInfo.environment["EQUIPO_STOPPED_FIXTURE"] == "paused" } func send(_ request: APIRequest) async throws -> APIResponse { let data: Data switch request.path { case "/snapshot": data = try JSONSerialization.data(withJSONObject: ["me": ["id": "fixture", "address": "paul@example.com", "role": "owner", "team_id": "fixture", "team_name": "Oficina", "revision": 1], "cursor": 1, "tasks": [task], "messages": messages, "turns": [], "cards": cards, "projects": []]) case "/needs-you" where paused: data = Data(#"{"items":[]}"#.utf8) case "/tasks", "/needs-you": data = try JSONSerialization.data(withJSONObject: ["items": [task]]) case "/tasks/fixture": data = try JSONSerialization.data(withJSONObject: task) case "/steps/failed/log": data = try JSONSerialization.data(withJSONObject: ["step_id": "failed", "attempt": 1, "tail": "git push amadan equipo/needs-badge-sign-out\nremote: HTTP 429 Too Many Requests\nfatal: the remote end hung up unexpectedly\nexit status 128"]) case "/connections": try await Task.sleep(for: .milliseconds(1500)) data = Data(#"{"items":[{"id":"cn_fixture","runner_id":"runner","local_id":"codex-1","provider":"codex","spend":{"unknown":true,"pause_revision":7}}]}"#.utf8) case "/tasks/fixture/retry": return APIResponse(status: 500, data: Data()) case "/projects": data = Data(#"{"items":[]}"#.utf8) default: data = Data("{}".utf8) } return APIResponse(status: 200, data: data) } func lines(_ request: APIRequest) async throws -> AsyncThrowingStream { AsyncThrowingStream { $0.finish() } } private var cards: [[String: Any]] { guard ProcessInfo.processInfo.environment["EQUIPO_STOPPED_FIXTURE"]?.hasPrefix("conversation-") == true else { return [] } return [["id": "report", "revision": 1, "kind": "task", "state": "open", "turn_id": "", "project_id": "project", "name": "", "question": "", "choice": "", "task_id": "fixture", "created_at": "2026-11-25T10:42:00Z", "updated_at": "2026-11-25T10:42:00Z"]] } private var messages: [[String: Any]] { guard !cards.isEmpty else { return [] } return [["id": "followup", "revision": 1, "role": "person", "text": "Please keep the current branch.", "turn_id": "", "created_at": "2026-11-25T10:43:00Z"]] } private var task: [String: Any] { let calendar = Calendar.current let today = calendar.startOfDay(for: Date()) let stop = calendar.date(byAdding: .minute, value: 10 * 60 + 42, to: today)! let resetToday = calendar.date(byAdding: .hour, value: 21, to: today)! let reset = resetToday > Date() ? resetToday : calendar.date(byAdding: .day, value: 1, to: resetToday)! let iso = ISO8601DateFormatter() var step: [String: Any] = ["id": "failed", "specialist": "engineering", "state": "failed", "reason": "push_failed", "terminated": true, "headline": "Push the branch", "summary": "", "verdict": "", "review_label": "", "checks": "", "gate": "", "finished_at": iso.string(from: stop)] if paused { step["state"] = "queued"; step["reason"] = ""; step["headline"] = ""; step.removeValue(forKey: "finished_at") step["hold"] = ["reason": "headroom", "provider": "claude", "connection": "claude-1", "step_revision": 4, "resets_at": iso.string(from: reset)] step["paused"] = ["since": iso.string(from: stop), "used_percent": 100, "run_now": ["connection": "codex-1", "name": "Codex", "provider": "codex", "billing": "subscription"]] } if resume { step["state"] = "queued"; step["reason"] = ""; step["runner_id"] = "runner" step["hold"] = ["reason": "spend_unknown", "provider": "codex", "connection": "codex-1", "step_revision": 4] } return ["id": "fixture", "revision": 1, "project_id": "project", "project": "Equipo", "title": paused ? "Show the stop reason on the native task view" : "Fix the Needs you badge after sign-out", "brief": "", "stage": "in_progress", "branch": "equipo/needs-badge-sign-out", "url": "", "candidate_sha": "3f9c2a1", "checks": "", "checks_reason": "", "verdict": "", "review_label": "", "needs_you": resume ? "held" : paused ? "" : "retry", "creator": "paul@example.com", "created_at": iso.string(from: stop), "updated_at": iso.string(from: stop), "steps": [step]] } } #endif