#if DEBUG import SwiftUI import ImageIO import UniformTypeIdentifiers import CoreText /// Offline visual fixture: no saved account, keychain or real server. public struct AttachmentsFixture: View { @State private var session = Self.makeSession() public init() {} #if os(iOS) /// EQUIPO_FIXTURE_TABS=1: the phone's real tabs around the same session, /// for the keyboard and floating tab bar checks. @State private var model: EquipoAppModel? = ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_TABS"] == "1" ? EquipoAppModel(store: MemorySecretStore()) : nil #endif public var body: some View { Group { #if os(iOS) if let model { PhoneSignedIn(model: model, session: session) } else { stack } #else stack #endif }.preferredColorScheme(ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_DARK"] == "1" ? .dark : .light) .task { await session.refresh() if ProcessInfo.processInfo.environment["EQUIPO_ATTACHMENTS_FIXTURE"] != "sent" { await Self.seedDraft(session) } } } private var stack: some View { NavigationStack { ConversationScreen(session: session) { _ in } .navigationTitle(EquipoStrings.text("tab.conversation")) #if os(iOS) .navigationBarTitleDisplayMode(.inline) #endif } } public static func makeSession() -> EquipoSession { let transport = AttachmentFixtureTransport() 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 static func seedDraft(_ session: EquipoSession) async { async let first: Void = session.attachments.add(data: image, name: "Home.png") async let second: Void = session.attachments.add(data: image, name: "Home-failed.png") _ = await (first, second) } /// Landscape JPEG fixture exercises mixed image aspect ratios in a sent bubble. nonisolated public static var landscape: Data { let context = CGContext(data: nil, width: 640, height: 360, bitsPerComponent: 8, bytesPerRow: 640 * 4, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)! context.setFillColor(CGColor(red: 0.55, green: 0.76, blue: 0.9, alpha: 1)); context.fill(CGRect(x: 0, y: 0, width: 640, height: 360)) context.setFillColor(CGColor(red: 0.97, green: 0.88, blue: 0.56, alpha: 1)); context.fillEllipse(in: CGRect(x: 470, y: 245, width: 60, height: 60)) context.setFillColor(CGColor(red: 0.25, green: 0.46, blue: 0.37, alpha: 1)) context.move(to: CGPoint(x: 0, y: 0)); context.addLine(to: CGPoint(x: 0, y: 125)); context.addCurve(to: CGPoint(x: 640, y: 155), control1: CGPoint(x: 230, y: 320), control2: CGPoint(x: 340, y: 30)); context.addLine(to: CGPoint(x: 640, y: 0)); context.closePath(); context.fillPath() let data = NSMutableData() let destination = CGImageDestinationCreateWithData(data, UTType.jpeg.identifier as CFString, 1, nil)! CGImageDestinationAddImage(destination, context.makeImage()!, nil); CGImageDestinationFinalize(destination) return data as Data } nonisolated public static var image: Data { let context = CGContext(data: nil, width: 360, height: 640, bitsPerComponent: 8, bytesPerRow: 360 * 4, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)! context.setFillColor(CGColor(red: 0.98, green: 0.97, blue: 0.94, alpha: 1)); context.fill(CGRect(x: 0, y: 0, width: 360, height: 640)) context.setFillColor(CGColor(gray: 1, alpha: 1)); context.fill(CGRect(x: 20, y: 240, width: 320, height: 230)) func line(_ text: String, _ y: CGFloat, _ size: CGFloat) { let value = NSAttributedString(string: text, attributes: [.font: CTFontCreateWithName("Helvetica" as CFString, size, nil), .foregroundColor: CGColor(gray: 0.15, alpha: 1)]) context.textPosition = CGPoint(x: 32, y: y); CTLineDraw(CTLineCreateWithAttributedString(value), context) } line("Home", 570, 30); line("Sign in", 425, 24); line("Your address", 370, 16) context.setStrokeColor(CGColor(gray: 0.75, alpha: 1)); context.stroke(CGRect(x: 32, y: 305, width: 296, height: 42)) line("paul@example.com", 320, 16) context.setFillColor(CGColor(red: 0.15, green: 0.32, blue: 0.8, alpha: 1)); context.fill(CGRect(x: 32, y: 240, width: 296, height: 42)) let data = NSMutableData() let destination = CGImageDestinationCreateWithData(data, UTType.png.identifier as CFString, 1, nil)! CGImageDestinationAddImage(destination, context.makeImage()!, nil); CGImageDestinationFinalize(destination) return data as Data } } private struct AttachmentFixtureTransport: EquipoTransport { let origin = URL(string: "https://fixture.invalid")! func send(_ request: APIRequest) async throws -> APIResponse { if request.path == "/attachments" { if request.contentDisposition?.contains("failed") == true { throw EquipoAPIError.offline } request.uploadProgress?.report(0.42) try await Task.sleep(for: .seconds(3600)) return APIResponse(status: 201, data: try JSONSerialization.data(withJSONObject: attachment)) } if request.path.hasPrefix("/attachments/") { return APIResponse(status: 200, data: request.path.contains("at_landscape") ? AttachmentsFixture.landscape : AttachmentsFixture.image) } let body: [String: Any] switch request.path { case "/snapshot": body = ["me": ["id": "fixture", "address": "paul@example.com", "role": "owner", "team_id": "fixture", "team_name": "Oficina", "revision": 1], "cursor": 1, "tasks": tabs ? [task] : [], "messages": messages, "turns": [], "cards": [], "projects": []] case "/tasks/tkkeyboard" where tabs: body = task case "/tasks" where tabs: body = ["items": [task]] default: body = ["items": []] } return APIResponse(status: 200, data: try JSONSerialization.data(withJSONObject: body)) } func lines(_ request: APIRequest) async throws -> AsyncThrowingStream { AsyncThrowingStream { $0.finish() } } private var attachment: [String: Any] { ["id": "at_fixture", "revision": 1, "kind": "image", "name": "Home.png", "media_type": "image/png", "size": 8000, "sha256": "fixture", "width": 360, "height": 640, "message_id": "message", "created_at": "2026-11-25T10:51:00Z"] } private var landscapeAttachment: [String: Any] { ["id": "at_landscape", "revision": 1, "kind": "image", "name": "Landscape.jpg", "media_type": "image/jpeg", "size": AttachmentsFixture.landscape.count, "sha256": "fixture", "width": 640, "height": 360, "message_id": "message", "created_at": "2026-11-25T10:51:00Z"] } /// EQUIPO_FIXTURE_TABS: the Coordinator answers with a task link. private var tabs: Bool { ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_TABS"] == "1" } private var task: [String: Any] { ["id": "tkkeyboard", "revision": 1, "project_id": "project", "project": "Home", "title": "Fix the sign-in button", "brief": "", "stage": "in_progress", "branch": "home/sign-in", "url": "", "candidate_sha": "", "checks": "", "checks_reason": "", "verdict": "", "review_label": "", "needs_you": "", "creator": "paul@example.com", "created_at": "2026-11-25T10:52:00Z", "updated_at": "2026-11-25T10:52:00Z", "steps": []] } private var messages: [[String: Any]] { var all: [[String: Any]] = [["id": "message", "revision": 1, "role": "person", "text": "Home’s sign-in button is cut off on my phone.", "turn_id": "", "created_at": "2026-11-25T10:51:00Z", "attachments": [attachment, landscapeAttachment]]] if tabs { all.append(["id": "reply", "revision": 1, "role": "coordinator", "text": "I started [Fix the sign-in button](/tasks/tkkeyboard).", "turn_id": "", "created_at": "2026-11-25T10:52:00Z"]) } return all } } #endif