oficina / docs Public

Screenshot gate for Docs: library, onboarding, other ways, team picker, Settings

Human

Prompt

5. Adopt RastrilloSnapshots for Docs' key screens (library, onboarding, settings) per the adoption steps; note web/Metal views draw blank and bundled fonts must be registered first; push baselines in small commits (<700 KB each — the hub rejects packs over ~1 MB).

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

Tests/DocsSnapshots (Mac, swift test) and DocsPhoneSnapshots (iPhone, the same file as an XcodeGen logic-test target) draw a SnapshotCatalog(app: docs, tint: Docs' Calma accent): library with documents and empty (a ScriptedTransport answers the list), Oficina ID welcome, code and teams (models walked there through FakeOficinaIDService, no keychain or network), Other ways to sign in, the team picker, and on the Mac Settings (Oficina ID and server). Bundled faces are registered first. native/scripts/snapshots.sh [compare|record] [mac|iphone|all] runs rastrillo/native's own runner scripts from the pinned checkout; not in .amadan/ci.d, since baselines are exact only on the OS that drew them. Other ways now shows the server sign-in itself when no account is kept, and the team picker's buttons are borderless with the check inside the row, from reading the first recording.
Agent notes
Seen to fail: Teams → Teamz fails team-picker light and dark (35/41 px). The editor is not in the catalog: its first layout can outlast the settle window, and web/Metal content draws blank.
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 79ad07335ad4d8b5d1723b447681070fcf9db389 parent 45d7e53
5 files changed, +242 −6
  • native/apple/Package.swift +7 −0
  • native/apple/Sources/DocsKit/DocsOficinaViews.swift +17 −6
  • native/apple/Tests/DocsSnapshots/DocsSnapshots.swift +153 −0
  • native/ios/project.yml +29 −0
  • native/scripts/snapshots.sh +36 −0

CI cancelled — superseded by a newer push — run details

diff --git a/native/apple/Package.swift b/native/apple/Package.swift
index dae3474..f68bb26 100644
--- a/native/apple/Package.swift
+++ b/native/apple/Package.swift
@@ -14,4 +14,11 @@ let package = Package(name: "DocsNative", defaultLocalization: "en", platforms:
.executableTarget(name: "DocsMac", dependencies: [.product(name: "RastrilloMacUpdates", package: "native", condition: .when(platforms: [.macOS])), "DocsKit", .product(name: "RastrilloApple", package: "native")], path: "Sources/DocsApp"),
.testTarget(name: "DocsKitTests", dependencies: ["DocsKit", .product(name: "RastrilloTestSupport", package: "native")]),
.testTarget(name: "DocsWindowTests", dependencies: ["DocsMac", .product(name: "RastrilloApple", package: "native")]),
+ // The screenshot gate's Mac half; native/scripts/snapshots.sh runs it,
+ // plain `swift test` skips it. ios/project.yml builds the same file
+ // as DocsPhoneSnapshots for the iPhone half.
+ .testTarget(name: "DocsSnapshots", dependencies: ["DocsKit", .product(name: "RastrilloSnapshots", package: "native"),
+ .product(name: "RastrilloApple", package: "native"),
+ .product(name: "RastrilloTestSupport", package: "native")],
+ exclude: ["__Snapshots__"]),
])
diff --git a/native/apple/Sources/DocsKit/DocsOficinaViews.swift b/native/apple/Sources/DocsKit/DocsOficinaViews.swift
index 07bfd35..320e749 100644
--- a/native/apple/Sources/DocsKit/DocsOficinaViews.swift
+++ b/native/apple/Sources/DocsKit/DocsOficinaViews.swift
@@ -38,10 +38,11 @@ import SwiftUI
Section {
ForEach(teams) { team in
Button { choose(team) } label: {
- HStack(spacing: 8) {
- OficinaTeamRow(team: team)
- Image(systemName: "checkmark").foregroundStyle(OficinaPalette.accent(.docs))
- .opacity(team.sqid == current.team.sqid ? 1 : 0).accessibilityHidden(true)
+ OficinaTeamRow(team: team).overlay(alignment: .trailing) {
+ if team.sqid == current.team.sqid {
+ Image(systemName: "checkmark").font(.headline).foregroundStyle(OficinaPalette.accent(.docs))
+ .padding(.trailing, 14).accessibilityHidden(true)
+ }
}
}
.buttonStyle(.plain)
@@ -52,10 +53,13 @@ import SwiftUI
} header: { Text("native.oficinaid.teams", bundle: DocsResources.bundle) }
Section {
Button(OficinaIDText.text("otherWays")) { otherWays() }
+ .buttonStyle(.borderless)
.accessibilityIdentifier("docs.otherWays")
Button(role: .destructive) { signOut() } label: {
Text(verbatim: OficinaIDText.text("signOut", current.identity.label))
}
+ .buttonStyle(.borderless)
+ .foregroundStyle(OficinaPalette.negative)
.disabled(!canLeave)
.accessibilityIdentifier("docs.oficinaid.signOut")
}
@@ -85,7 +89,8 @@ import SwiftUI
/// "Other ways to sign in…": the server address and browser approval that
/// stay for self-hosted servers and local accounts (spec §11), with the way
-/// back to Oficina ID beneath.
+/// back to Oficina ID beneath. With no account kept yet it is the sign-in
+/// itself; with some, their list and "Add account".
@MainActor public struct DocsOtherWaysView: View {
@ObservedObject private var connection: NativeConnection
private let oficinaID: () -> Void
@@ -95,7 +100,13 @@ import SwiftUI
}
public var body: some View {
- NativeAccountsView("Docs", systemImage: "doc.text", connection: connection)
+ Group {
+ if connection.accounts.isEmpty {
+ NavigationStack { NativeSignInView("Docs", systemImage: "doc.text", connection: connection) }
+ } else {
+ NativeAccountsView("Docs", systemImage: "doc.text", connection: connection)
+ }
+ }
.safeAreaInset(edge: .bottom, spacing: 0) {
Button { connection.cancel(); oficinaID() } label: {
Label { Text("native.oficinaid.signin", bundle: DocsResources.bundle) } icon: { Image(systemName: "person.crop.circle") }
diff --git a/native/apple/Tests/DocsSnapshots/DocsSnapshots.swift b/native/apple/Tests/DocsSnapshots/DocsSnapshots.swift
new file mode 100644
index 0000000..580eb5c
--- /dev/null
+++ b/native/apple/Tests/DocsSnapshots/DocsSnapshots.swift
@@ -0,0 +1,153 @@
+import DocsKit
+import Foundation
+import RastrilloApple
+import RastrilloSnapshots
+import RastrilloTestSupport
+import SwiftUI
+import XCTest
+
+/// Docs' key screens for the screenshot gate (rastrillo/native
+/// RastrilloSnapshots): the library, Oficina ID onboarding as Docs shows it,
+/// Other ways to sign in, the team picker and, on the Mac, Settings. Drawn
+/// from fixtures with no server, keychain, App Group or network, in light and
+/// dark, and on iPhone at the default size and AX3.
+///
+/// `native/scripts/snapshots.sh` runs it (compare, or record); `swift test`
+/// alone skips it, because baselines match only the OS that drew them. The
+/// Mac half runs from `swift test`; the iPhone half is the same file in the
+/// `DocsPhoneSnapshots` target of `ios/project.yml`.
+///
+/// The editor is not here: its text views draw, but a document's first
+/// layout can finish after the gate's settle window, and anything in a web
+/// view or Metal layer draws blank. Bundled faces are registered first, or
+/// the baselines would record fallback faces.
+final class DocsSnapshots: XCTestCase {
+ @MainActor func testKeyScreens() async throws {
+ try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil,
+ "Run with native/scripts/snapshots.sh")
+ DocsFonts.register()
+ let fixtures = await Fixtures.make()
+ await assertSnapshots(of: Self.catalog(fixtures))
+ }
+
+ @MainActor static func catalog(_ fixtures: Fixtures) -> SnapshotCatalog {
+ var screens: [SnapshotScreen] = [
+ SnapshotScreen("library", mac: .fixed(width: 1000, height: 700), iphone: .fixed(width: 402, height: 874)) {
+ Fixtures.library(["Quarterly plan", "Meeting notes, 12 January", "Letter to the landlord", "Recipes"])
+ },
+ SnapshotScreen("library-empty", mac: .fixed(width: 1000, height: 700), iphone: .fixed(width: 402, height: 874)) {
+ Fixtures.library([])
+ },
+ SnapshotScreen("onboarding-welcome") {
+ OficinaOnboardingView(model: fixtures.welcome, otherWays: {})
+ },
+ SnapshotScreen("onboarding-code") {
+ OficinaOnboardingView(model: fixtures.code, otherWays: {})
+ },
+ SnapshotScreen("onboarding-teams") {
+ OficinaOnboardingView(model: fixtures.teams, otherWays: {})
+ },
+ SnapshotScreen("other-ways", mac: .fixed(width: 520, height: 480), iphone: .fixed(width: 402, height: 640)) {
+ DocsOtherWaysView(connection: Fixtures.connection()) {}
+ },
+ SnapshotScreen("team-picker", mac: .fixed(width: 460, height: 540), iphone: .fixed(width: 402, height: 720)) {
+ DocsTeamPicker(model: fixtures.signedIn, current: fixtures.signedInState, canLeave: true,
+ otherWays: {}, signOut: {}, done: {})
+ },
+ ]
+ #if os(macOS)
+ screens.append(SnapshotScreen("settings", mac: .width(480), iphone: nil) {
+ DocsSettingsView(account: .oficinaID(identity: "paul@tito.io", team: "Paul", teamLabel: "paulca"), canSignOut: true,
+ version: "0.1.0 (1)", manage: {}, signOut: {}, signIn: {})
+ })
+ screens.append(SnapshotScreen("settings-server", mac: .width(480), iphone: nil) {
+ DocsSettingsView(account: .server(name: "Tito", host: "tito.docs.oficina.works"), canSignOut: true,
+ version: "0.1.0 (1)", manage: {}, signOut: {}, signIn: {})
+ })
+ #endif
+ return SnapshotCatalog(app: "docs", settings: SnapshotSettings(tint: OficinaPalette.accent(.docs)), screens: screens)
+ }
+}
+
+/// Oficina ID models walked to each step through the kit's in-memory Home,
+/// directory and instances, exactly as a person would get there: nothing
+/// touches the keychain, an App Group or the network.
+@MainActor final class Fixtures {
+ static let origin = URL(string: "https://docs.snapshot.invalid")!
+ let welcome: OficinaIDModel
+ let code: OficinaIDModel
+ let teams: OficinaIDModel
+ let signedIn: OficinaIDModel
+ let signedInState: OficinaSignedIn
+
+ private init(welcome: OficinaIDModel, code: OficinaIDModel, teams: OficinaIDModel, signedIn: OficinaIDModel, state: OficinaSignedIn) {
+ self.welcome = welcome; self.code = code; self.teams = teams; self.signedIn = signedIn; signedInState = state
+ }
+
+ static func make() async -> Fixtures {
+ let welcome = model(), code = model(), teams = model(), signedIn = model()
+ await welcome.start()
+ await walk(code, to: 1)
+ await walk(teams, to: 2)
+ await walk(signedIn, to: 2)
+ if case .teams(let list) = signedIn.step, let first = list.first { await signedIn.choose(first) }
+ guard case .signedIn(let state) = signedIn.step else { preconditionFailure("fixture did not sign in: \(signedIn.step)") }
+ return Fixtures(welcome: welcome, code: code, teams: teams, signedIn: signedIn, state: state)
+ }
+
+ private static func team(_ sqid: String, _ name: String, _ label: String) -> OficinaTeam {
+ OficinaTeam(sqid: sqid, label: label, name: name, role: "member",
+ apps: [OficinaTeamApp(app: "docs", origin: "https://\(label).docs.oficina.works", consumerID: "\(sqid)-docs")])
+ }
+
+ private static func model() -> OficinaIDModel {
+ let service = FakeOficinaIDService()
+ service.addPerson(email: "paul@tito.io", identityID: "id-paul")
+ let teams = [team("t1", "Paul", "paulca"), team("t2", "Tito", "tito"), team("t3", "Campbells", "campbells")]
+ service.setTeams(teams, for: "id-paul")
+ for team in teams { service.admit("id-paul", at: team.origin(for: "docs")!, as: .linked) }
+ let suite = "DocsSnapshots.\(UUID().uuidString)"
+ let defaults = UserDefaults(suiteName: suite)!
+ defaults.removePersistentDomain(forName: suite)
+ let store = OficinaIDStore(shared: OficinaMemoryStore(), appPrivate: OficinaMemoryStore(), group: defaults)
+ return OficinaIDModel(configuration: DocsOficinaSession.configuration, store: store, service: service,
+ passkeys: FakePasskeys(), makeKey: { OficinaSoftwareKey() },
+ now: { SnapshotSettings.now }, appDefaults: defaults)
+ }
+
+ /// 1: the code step. 2: the team step, after the code.
+ private static func walk(_ model: OficinaIDModel, to stage: Int) async {
+ await model.start()
+ model.continueWithEmail()
+ model.email = "paul@tito.io"
+ await model.submitEmail()
+ guard stage > 1 else { return }
+ model.code = FakeOficinaIDService.goodCode
+ await model.submitCode()
+ }
+
+ /// A workspace whose server answers the document list and nothing else.
+ static func library(_ titles: [String]) -> some View {
+ let documents = titles.enumerated().map { #"{"sqid":"d\#($0.offset)","title":"\#($0.element)","shared":\#($0.offset == 1)}"# }
+ let list = Data(#"{"documents":[\#(documents.joined(separator: ","))],"can_create":true}"#.utf8)
+ let server = ScriptedTransport(origin: origin) { call in
+ call.path.hasPrefix("/?") ? .respond(status: 200, body: list) : .respond(status: 404)
+ }
+ return DocsWorkspace(client: NativeHTTP(origin: origin), transport: { server }, accounts: {}, signOut: {},
+ accountsLabel: DocsOficinaSession.teamsTitle,
+ signOutLabel: OficinaIDText.text("signOut", "paul@tito.io"))
+ }
+
+ /// A connection on a throwaway defaults suite and an origin no app holds
+ /// a credential for, so `NativeConnection.init`'s legacy-credential
+ /// migration can never find (and move) a real item.
+ static func connection() -> NativeConnection {
+ let suite = "DocsSnapshots.connection.\(UUID().uuidString)"
+ let defaults = UserDefaults(suiteName: suite)!
+ defaults.removePersistentDomain(forName: suite)
+ let connection = NativeConnection(defaultServer: origin.absoluteString, defaults: defaults,
+ connectivity: NativeConnectivity(source: ScriptedPathSource(.satisfied)))
+ connection.serverAddress = "https://docs.oficina.works"
+ return connection
+ }
+}
diff --git a/native/ios/project.yml b/native/ios/project.yml
index aade4d3..d843579 100644
--- a/native/ios/project.yml
+++ b/native/ios/project.yml
@@ -94,7 +94,36 @@ targets:
base:
GENERATE_INFOPLIST_FILE: true
TEST_TARGET_NAME: DocsReviewPhone
+ # The screenshot gate's iPhone half: the Mac half's catalog file, run as a
+ # logic test in the simulator by native/scripts/snapshots.sh.
+ DocsPhoneSnapshots:
+ type: bundle.unit-test
+ platform: iOS
+ sources:
+ - path: ../apple/Tests/DocsSnapshots
+ excludes:
+ - __Snapshots__
+ dependencies:
+ - package: DocsNative
+ product: DocsKit
+ - package: RastrilloNative
+ product: RastrilloApple
+ - package: RastrilloNative
+ product: RastrilloSnapshots
+ - package: RastrilloNative
+ product: RastrilloTestSupport
+ settings:
+ base:
+ GENERATE_INFOPLIST_FILE: true
+ PRODUCT_BUNDLE_IDENTIFIER: works.oficina.docs.snapshots
schemes:
+ DocsPhoneSnapshots:
+ build:
+ targets:
+ DocsPhoneSnapshots: [test]
+ test:
+ targets:
+ - DocsPhoneSnapshots
DocsReviewPhone:
build:
targets:
diff --git a/native/scripts/snapshots.sh b/native/scripts/snapshots.sh
new file mode 100755
index 0000000..1bc22d4
--- /dev/null
+++ b/native/scripts/snapshots.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Docs' screenshot gate (rastrillo/native RastrilloSnapshots): the library,
+# Oficina ID onboarding, Other ways to sign in, the team picker and Settings,
+# light and dark, and on iPhone at the default size and AX3.
+#
+# native/scripts/snapshots.sh [compare|record] [mac|iphone|all]
+#
+# compare (the default) fails on any changed, missing or stale picture;
+# record redraws the baselines in apple/Tests/DocsSnapshots/__Snapshots__/docs.
+# Review the contact sheet, apple/.build/snapshots/docs/index.html, before
+# committing a recording, and push baselines in commits under ~700 KB: the
+# hub drops a push whose pack is over about 1 MB.
+#
+# Not in .amadan/ci.d: baselines are exact only on the OS and simulator
+# runtime that drew them (ENVIRONMENT beside them says which). The runner
+# scripts are rastrillo/native's own, from the pinned checkout; the iPhone
+# half runs on its "Rastrillo Snapshots" simulator under its lock.
+set -eu
+cd "$(dirname "$0")/.."
+mode=${1:-compare}
+platforms=${2:-all}
+case "$mode" in compare|record) ;; *) echo "usage: $0 [compare|record] [mac|iphone|all]" >&2; exit 2 ;; esac
+if [ "${OFICINA_SKIP_PREPARE:-0}" != 1 ]; then scripts/build-crdt.sh; fi
+swift package --package-path apple resolve
+shared=${OFICINA_NATIVE_PACKAGE_PATH:-apple/.build/checkouts/native}
+case "$shared" in /*) ;; *) shared="$(pwd)/$shared" ;; esac
+tools="$shared/tools"
+case "$platforms" in mac|all)
+ (cd apple && "$tools/snapshots-mac.sh" "$mode" DocsSnapshots) ;;
+esac
+case "$platforms" in iphone|all)
+ xcodegen generate --spec ios/project.yml
+ # Build products stay under apple/.build, beside the Mac half's.
+ (cd apple && SNAPSHOT_DERIVED_DATA=.build/xcode "$tools/snapshots-iphone.sh" "$mode" DocsPhoneSnapshots DocsPhoneSnapshots \
+ -project ../ios/DocsPhone.xcodeproj) ;;
+esac