oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1# Building and checking native Docs
2
3The native editor uses SwiftUI with AppKit/UIKit text controls and a bounded
4WASM interpreter for the shared Yjs-compatible CRDT. It does not load a web editor.
5
6Requirements: Xcode 26, XcodeGen, Swift 6.2+, Node/npm, and Rust with the
7`wasm32-unknown-unknown`, `aarch64-apple-darwin`, `x86_64-apple-darwin`,
8`aarch64-apple-ios`, `aarch64-apple-ios-sim`, and `x86_64-apple-ios` targets.
9The server gate additionally requires the Go version in `go.mod`.
10
11Run the native gate from the repository root:
12
13```sh
14native/scripts/check-native.sh
15```
16
17It builds the CRDT WASM, runs Rust editor and bounded-host tests (including
18opening and typing in a generated 200-page edited document on the host's
19production fuel budget; see `fuel_budget` in `host/src/lib.rs`), checks native
20and browser updates in both directions (including every list-rule reversal delta
21and its authoritative snapshot, the undo-kept garbage-collection repro of
22discussion #145, whose collected units must match Yjs's, and that each command's
23update carries only its own change, as the browser's per-transaction updates
24do), prepares the Apple XCFramework, and runs Swift adapter/actor tests.
25`--core-only` runs the Rust and wire checks on
26Linux. CI invokes this through `.amadan/ci.d/20-native`, alongside the existing
27server/web gate. `--mutations` additionally proves representative faulty changes
28are caught, restoring every changed source and saving logs under
29`native/build/mutation-logs`. Do not run mutations concurrently with builds.
30
31`native/scripts/test-iphone.sh` runs the tests that need UIKit's text view
32(DocsPhoneTests in `ios/project.yml`: the editor render-loop regression of
33TestFlight 0.1.10 (12), and the redesign's S1a tests of `DocumentSurface`:
34the flush triggers, delta safety, the block index, block render
35equivalence, render isolation with §7's counters; their Mac half runs in
36`swift test`) in the iOS 27.0 simulator. It is not in CI, which has no
37simulator: run it before changing `NativeDocumentTextView`,
38`DocumentSurface` or the render.
39
40§7's counters (`DocsKit/DocsProbes.swift`) compile under `DOCS_PROBES`:
41Package.swift defines it for debug builds, so `swift test` and
42test-iphone.sh hold the hard counters as gates (`RenderIsolationTests`);
43a release build, the one that ships, carries none of it. The timings are
44measured by `native/benchmarks/realtime` (its README), and the numbers are
45in `native/benchmarks/README.md`.
46
47The apps bundle every font in Docs' shared list
48(`internal/fonts/fonts.json`): `native/apple/Sources/DocsKit/Fonts` is a
49copy of the manifest, each family's TTFs and its licence, made by
50`native/scripts/sync-fonts.py`. Rerun it whenever `internal/fonts` changes;
51the native gate runs it with `--check`, on Linux too, and fails on any
52drift. Git stores the identical files once. The apps register every face
53synchronously before their first window and draw each run from its bundled
54file, never from a copy of the same name installed on the machine.
55
56`CARGO` can select a non-default Cargo executable; put its matching Rust toolchain
57on `PATH`. If that toolchain needs an explicit LLVM runtime lookup path, set
58`DOCS_LLVM_LIBRARY_PATH`. No generated native framework is committed.
59
60Build individual applications:
61
62```sh
63native/scripts/build-mac.sh
64native/scripts/build-iphone.sh simulator
65OFICINA_DEVELOPMENT_TEAM=YOUR_TEAM native/scripts/build-iphone.sh device
66```
67
68The suite's `build-native-apps.py` prepares the native framework and Xcode projects
69once, then runs Docs and Sheets builds concurrently with separate platform logs
70and a combined `results.json`. Its default targets are Mac and iOS Simulator;
71`--platforms mac simulator device` also builds signed device applications when
72`OFICINA_DEVELOPMENT_TEAM` is set. It does not install or publish applications.
73
74Native UI tests use fresh local credentials and isolated databases. See
75[REVIEW.md](REVIEW.md) for their runner, exact evidence, and untested behavior.
76Performance measurements and their limits are in
77[benchmarks/README.md](benchmarks/README.md).
78
79## Oficina ID: entitlements, profiles and the launch check
80
81Docs signs in with Oficina ID first (Home's
82`docs/superpowers/specs/2026-11-14-oficina-id-native.md`, slice A), through
83rastrillo/native's `RastrilloApple/OficinaID` kit. "Other ways to sign in…"
84keeps the server address and browser approval. The kit needs these grants on
85every build:
86
87| Build | File | App group |
88| --- | --- | --- |
89| Mac, Sparkle (Developer ID) | `macos/DeveloperID.entitlements`, named by `mac-updates.json` | `9U4A84C4WK.works.oficina` |
90| Mac App Store | `macos/AppStore.entitlements` | `9U4A84C4WK.works.oficina` |
91| iPhone and iPad | `ios/DocsPhone.entitlements` | `group.works.oficina` |
92
93All three have `keychain-access-groups` = `9U4A84C4WK.works.oficina.docs`
94**first**, then `9U4A84C4WK.works.oficina.id` (a query that names no group
95lands in the first, and Docs' own items must never land in the group every
96Oficina app reads), and `webcredentials:id.oficina.works`.
97
98A Developer ID Mac app that claims these without an embedded provisioning
99profile is killed at launch. `mac-updates.json` names the profile by its local
100path, `~/private_keys/oficina/profiles/Oficina-Docs-macOS-Developer-ID.provisionprofile`;
101the profile itself is never committed. Elsewhere, pass
102`--provisioning-profile <path>`, which wins over the configuration, to
103`scripts/build-mac.sh` and to rastrillo's `release_mac.py`. A signed build:
104
105```sh
106native/scripts/build-mac.sh --updates-config mac-updates.json \
107 --sign-identity 'Developer ID Application: Team Tito Limited (9U4A84C4WK)'
108```
109
110An ad hoc build (no `--sign-identity`) drops those grants and says so on
111stderr. It still runs, but Oficina ID cannot read the keychain there
112(-34018), so Welcome says it couldn't be read. Simulator builds
113(`CODE_SIGNING_ALLOWED=NO`) are the same.
114
115**The launch check** is the spec's launch gate (§13): before any Sparkle
116publish, run the final signed, notarised artifact's executable with
117`--oficina-id-launch-check`.
118
119```sh
120"native/build/Oficina Docs.app/Contents/MacOS/DocsMac" --oficina-id-launch-check
121```
122
123macOS checks the embedded profile as the process starts. The check then reads
124the signed entitlements (the keychain groups in order, the App Group, the
125associated domain) and both keychain groups, prints counts (never an identity
126or a session) and exits 0 only if all of them work. An ad hoc build, or the
127unsigned test runner (`OficinaIDAdoptionTests`), fails every line.
128
129With one Oficina ID on the device Docs goes straight in, with no screen
130(Paul, 2026-11-19; spec §9 "Straight in", rule 0); several ask which. While
131"Other ways to sign in…" is the route, nothing goes straight in: the home
132window suspends it at launch and on every route change (`routeChanged`, from
133`.onChange(of: route)`), and resumes it when the route is Oficina ID again. A
134signed-in session is never disturbed by either. The account menu (the Teams
135sheet, and Docs ▸ in the Mac menu bar) offers "Use another Oficina ID" only
136while signed in; the kit confirms (`oficinaReplaceConfirmation`, on the
137signed-in screen only), and Docs refuses, and says why, while a document
138window of the identity is open or its changes are unsent. Those are checked
139before the kit asks, and a document window of the identity opened while it
140asks withdraws the question.
141
142Docs' session guards answer a write whose session has ended with 403
143`signed out` (rastrillo's `sessions.Require`, and the identity guard for a
144native session past its seven days). `DocsSessionWatch` reads exactly those
145bytes as an ended session, re-mints it and surfaces a 401; every other 403 is
146a refusal of the request. `internal/docs/native_contract_test.go` pins the
147bytes on the server.
148
149An Oficina ID team's offline store key is filed under one fixed origin, not the
150team's, so a team whose address changes (a label moved, a rename, self-hosting
151by DNS) keeps its store and unsent outbox. Docs refreshes the team list at
152launch, when the team picker opens (at most every five minutes) and on a 403,
153through the kit's `refreshTeams`. Signing out, switching team or replacing the
154Oficina ID waits for every team's outbox to drain, those a crash left on disk
155included, and on the Mac for every document window of the identity to close;
156the picker and Settings say which.
157
158Sign-in itself needs Home's native endpoints at `id.oficina.works` and the
159directory at `oficina.works`; passkeys also need Home's association file. The
160kit's in-memory `FakeOficinaIDService` stands in for all of them in
161`OficinaIDAdoptionTests` and the screenshot gate.
162
163## The screenshot gate
164
165`native/scripts/snapshots.sh [compare|record] [mac|iphone|all]` draws Docs' key
166screens (library, Oficina ID onboarding, Other ways to sign in, the team
167picker, Mac Settings) in light and dark, and on iPhone at AX3 too, and compares
168them with `apple/Tests/DocsSnapshots/__Snapshots__/docs`. The contact sheet is
169`apple/.build/snapshots/docs/index.html`.
170
171The same run draws the editor's page from fixed fixtures
172(`apple/Tests/DocsSnapshots/EditorSnapshots.swift`, baselines in
173`__Snapshots__/docs-editor` and, for iPhone at AX3, `docs-editor-ax3`; sheets
174`apple/.build/snapshots/docs-editor*/index.html`). Each screen opens its
175document through `DocsModel` and `NativeDocumentTextView` on an in-memory
176server, and stays visibly unsettled until it is open, rendered, laid out and
177scrolled, so the kit never records it half drawn. Rendering work (the native
178redesign's S1) must leave these pictures unchanged; a screen that changes is
179re-recorded only with a reason in the branch's discussion.
180
181It is not in `.amadan/ci.d`:
182baselines are exact only on the OS and simulator runtime that drew them
183(`ENVIRONMENT` beside them; today macOS 27.0.0, Xcode 27.2, and the iOS
18427.0 runtime 24A434 on an iPhone 18 Pro). Hub CI builds the snapshot tests
185but skips them, since they need `RASTRILLO_SNAPSHOTS`. After an intended
186change, `record`, read the contact sheet, and push the pictures one commit
187per push with `git -c http.postBuffer=209715200 push`: without it the hub
188drops a pack over about 1 MB ("unexpected disconnect while reading sideband
189packet"), and pushes back to back trip its per-IP limit. Batch
190re-recordings: every one stays in the hub's history.
191
192A screen that hangs the main thread never reaches the kit's own 3 s limit,
193so the script stops the Mac test run after `SNAPSHOT_MAC_LIMIT` seconds
194(default 300) and gives each iPhone test XCTest's 120 s allowance.
195
196### Enforcing it
197
198Nothing but this procedure holds a branch to the gate, so:
199
200- **Every branch that can change rendering** (the redesign's S1a, S1b and
201 later, and any fix to the renderer) pastes the whole output of
202 `native/scripts/snapshots.sh compare all` into its discussion before it
203 asks for review. The script prints the environment each half drew on.
204- **The reviewer re-runs it** on their own checkout (about a minute a
205 platform once built) and says so in the review.
206- **When the environment no longer matches the baselines** (the script says
207 "ENVIRONMENT DIFFERS": a macOS, Xcode or simulator runtime update), the
208 failures are drift, not a regression, and can't be told apart from one.
209 Re-record from `main`, on a branch of its own whose only change is the
210 baselines, have the contact sheet reviewed, and land it first. Never
211 re-record on a rendering branch: that would bless whatever the branch
212 changed along with the drift.
213- A rendering fix re-records only the screens it means to change, and its
214 discussion names them.
215
216### Known rendering bugs in the baselines
217
218The editor baselines are today's pixels, bugs included, so that rendering
219work can't fix (or break) them by accident. Each fix is its own branch and
220re-records only the screens it changes:
221
222- Lists draw no bullet or number, on the Mac or iOS: `NSTextList` is set
223 and the items are indented, but no marker is drawn.
224- Arabic paragraphs are left-aligned: `NativeTextProjection` sets `.left`,
225 not `.natural`.
226- iPhone and iPad width, paged: the text sits about 72 pt above where the
227 page's top margin puts it, so it starts at the paper's top edge and stops
228 well above the page's foot. A paragraph's lines can split across pages
229 (iOS paginates by line).
230- The page label differs: the Mac draws "Page 2" at the first break, iOS
231 "Page 1" at the foot of page 1.
232- iOS draws no bar beside a blockquote; the Mac does.
233- In Mac light appearance the desk around the paper is as white as the
234 paper, so only the dark pictures show the paper's edges and the bands
235 between pages.
236