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
3import ImageIO
4import UniformTypeIdentifiers
5import CoreText
6
7/// Offline visual fixture: no saved account, keychain or real server.
8public struct AttachmentsFixture: View {
9 @State private var session = Self.makeSession()
10 public init() {}
11 #if os(iOS)
12 /// EQUIPO_FIXTURE_TABS=1: the phone's real tabs around the same session,
13 /// for the keyboard and floating tab bar checks.
14 @State private var model: EquipoAppModel? = ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_TABS"] == "1" ? EquipoAppModel(store: MemorySecretStore()) : nil
15 #endif
16 public var body: some View {
17 Group {
18 #if os(iOS)
19 if let model { PhoneSignedIn(model: model, session: session) } else { stack }
20 #else
21 stack
22 #endif
23 }.preferredColorScheme(ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_DARK"] == "1" ? .dark : .light)
24 .task {
25 await session.refresh()
26 if ProcessInfo.processInfo.environment["EQUIPO_ATTACHMENTS_FIXTURE"] != "sent" {
27 await Self.seedDraft(session)
28 }
29 }
30 }
31 private var stack: some View {
32 NavigationStack {
33 ConversationScreen(session: session) { _ in }
34 .navigationTitle(EquipoStrings.text("tab.conversation"))
35 #if os(iOS)
36 .navigationBarTitleDisplayMode(.inline)
37 #endif
38 }
39 }
40 public static func makeSession() -> EquipoSession {
41 let transport = AttachmentFixtureTransport()
42 var account = DeviceAccount.new(origin: transport.origin, label: "Fixture")
43 account.credential = DeviceCredential(id: "fixture", token: "fixture", audience: "equipo.person.v1", instanceId: "fixture", expiresAt: .distantFuture)
44 return EquipoSession(account: account, accounts: DeviceAccounts(store: MemorySecretStore()), transport: transport)
45 }
46 public static func seedDraft(_ session: EquipoSession) async {
47 async let first: Void = session.attachments.add(data: image, name: "Home.png")
48 async let second: Void = session.attachments.add(data: image, name: "Home-failed.png")
49 _ = await (first, second)
50 }
51 /// Landscape JPEG fixture exercises mixed image aspect ratios in a sent bubble.
52 nonisolated public static var landscape: Data {
53 let context = CGContext(data: nil, width: 640, height: 360, bitsPerComponent: 8, bytesPerRow: 640 * 4, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!
54 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))
55 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))
56 context.setFillColor(CGColor(red: 0.25, green: 0.46, blue: 0.37, alpha: 1))
57 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()
58 let data = NSMutableData()
59 let destination = CGImageDestinationCreateWithData(data, UTType.jpeg.identifier as CFString, 1, nil)!
60 CGImageDestinationAddImage(destination, context.makeImage()!, nil); CGImageDestinationFinalize(destination)
61 return data as Data
62 }
63 nonisolated public static var image: Data {
64 let context = CGContext(data: nil, width: 360, height: 640, bitsPerComponent: 8, bytesPerRow: 360 * 4, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!
65 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))
66 context.setFillColor(CGColor(gray: 1, alpha: 1)); context.fill(CGRect(x: 20, y: 240, width: 320, height: 230))
67 func line(_ text: String, _ y: CGFloat, _ size: CGFloat) {
68 let value = NSAttributedString(string: text, attributes: [.font: CTFontCreateWithName("Helvetica" as CFString, size, nil), .foregroundColor: CGColor(gray: 0.15, alpha: 1)])
69 context.textPosition = CGPoint(x: 32, y: y); CTLineDraw(CTLineCreateWithAttributedString(value), context)
70 }
71 line("Home", 570, 30); line("Sign in", 425, 24); line("Your address", 370, 16)
72 context.setStrokeColor(CGColor(gray: 0.75, alpha: 1)); context.stroke(CGRect(x: 32, y: 305, width: 296, height: 42))
73 line("paul@example.com", 320, 16)
74 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))
75 let data = NSMutableData()
76 let destination = CGImageDestinationCreateWithData(data, UTType.png.identifier as CFString, 1, nil)!
77 CGImageDestinationAddImage(destination, context.makeImage()!, nil); CGImageDestinationFinalize(destination)
78 return data as Data
79 }
80}
81
82private struct AttachmentFixtureTransport: EquipoTransport {
83 let origin = URL(string: "https://fixture.invalid")!
84 func send(_ request: APIRequest) async throws -> APIResponse {
85 if request.path == "/attachments" {
86 if request.contentDisposition?.contains("failed") == true { throw EquipoAPIError.offline }
87 request.uploadProgress?.report(0.42)
88 try await Task.sleep(for: .seconds(3600))
89 return APIResponse(status: 201, data: try JSONSerialization.data(withJSONObject: attachment))
90 }
91 if request.path.hasPrefix("/attachments/") { return APIResponse(status: 200, data: request.path.contains("at_landscape") ? AttachmentsFixture.landscape : AttachmentsFixture.image) }
92 let body: [String: Any]
93 switch request.path {
94 case "/snapshot":
95 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": []]
96 case "/tasks/tkkeyboard" where tabs: body = task
97 case "/tasks" where tabs: body = ["items": [task]]
98 default: body = ["items": []]
99 }
100 return APIResponse(status: 200, data: try JSONSerialization.data(withJSONObject: body))
101 }
102 func lines(_ request: APIRequest) async throws -> AsyncThrowingStream<String, Error> { AsyncThrowingStream { $0.finish() } }
103 private var attachment: [String: Any] {
104 ["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"]
105 }
106 private var landscapeAttachment: [String: Any] {
107 ["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"]
108 }
109 /// EQUIPO_FIXTURE_TABS: the Coordinator answers with a task link.
110 private var tabs: Bool { ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_TABS"] == "1" }
111 private var task: [String: Any] {
112 ["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": []]
113 }
114 private var messages: [[String: Any]] {
115 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]]]
116 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"]) }
117 return all
118 }
119}
120#endif
121