oficina / docs Public

S0: editor snapshots from today's renderer (native redesign) open

On branch feat/native-editor-snapshots

S0 of the Docs native redesign: editor snapshots on main, drawn by today's renderer. Spec docs/superpowers/specs/2026-11-22-native-redesign-design.md §11 and plan S0 (spec/native-redesign @ 2fb4a76), plus Fable's re-review finding 13 on #157 (an iPad-width screen and an after-a-scripted-edit screen). Nothing in production changes; this branch adds the test, its fixtures and 46 baselines. Not merged, released or deployed.

Why the editor was excluded, and the fix

DocsSnapshots.swift:20 said a document's first layout could finish after the kit's settle window (and that web or Metal views draw blank). The page is TextKit 1 in NSTextView and UITextView, so it draws: the real problem is timing. The kit takes a picture once two captures 50 ms apart agree, and a document opens asynchronously, so a screen could be recorded before it opened, before its layout, or with the page laid out at the scroll view's provisional size.

native/apple/Tests/DocsSnapshots/EditorSnapshots.swift opens each fixture through the real path: a replica seeded by a paste on an in-memory server, DocsModel.open, NativeTextProjection, then NativeDocumentTextView wired as DocsWorkspace.editor wires it (page only, no toolbar or chrome). Until the screen is ready it shows a counter that changes every frame, so the kit can't settle on a half-drawn picture. Ready means: open, rendered, the stream connected and nothing left to send, the text view's text equal to a full render of the projection, then a layout once the kit has sized the window (needsLayout, then ensureLayout on the container), the fixed scroll offset, and a run-loop turn. If any step times out, the screen stays unsettled and the gate fails.

Determinism:

  • Bundled faces are registered first.
  • Nothing reads a clock or animates.
  • The text view is never first responder, so no caret or selection is drawn.
  • Mac scrollers are pinned to overlay. Legacy scrollers otherwise follow whether a mouse is connected.
  • Scroll offsets are constants, never measured, so a moved line can't be hidden by scrolling with it.

Two timing bugs were found and fixed in the harness on the way. A layout that ran before the kit sized the window left the Mac paper at its 636 pt minimum width. A counter ticking in the same view as the editor re-evaluated its body on every tick.

Matrix (46 images)

Light and dark throughout. Mac at 1000 pt wide, iPhone 18 Pro 402 × 874, iPad Air width 820 × 1180 (drawn by the iOS renderer in the iPhone simulator).

| Screen | Mac | iPhone | |---|---|---| | editor-paged, editor-pageless (Millbrook: H1–H4, marks, link, bullet and ordered lists, quote, code block, inline code, centre and right alignment, indent, Caladea/Playfair/Garamond, image, rule) | ✓ | ✓, plus AX3 (docs-editor-ax3) | | editor-paged-150, editor-pageless-150 | ✓ | — (no zoom on iPhone) | | editor-paged-heading-break, editor-pageless-heading-break (38 one-line paragraphs, so an H1 is the first line of page 2 on every width) | ✓ | ✓ | | editor-paged-image-break, editor-pageless-image-break (an image is the first line of page 3) | ✓ | ✓ | | editor-paged-edited (typed through the text view at the end of line 30 with a Return, which moves the break; then a peer's insert into line 34, through the stream) | ✓ | ✓ | | editor-ar (Arabic, RTL layout direction, an embedded English name), editor-ru (long words) | ✓ | ✓ | | editor-ipad-paged | — | ✓ (iPad width) |

AX3 is drawn only for the two plain screens: the page's text doesn't scale (§9). Mac has no AX3, because the kit leaves it out.

The kit can't set a per-screen language (a bundle resolves strings in the process's language; SnapshotEnvironment says so). It doesn't need to for the page: ar and ru are document content, plus a .rightToLeft layout direction set inside the screen. The page-number label stays English. The S2a chrome screens will need the kit change the plan names; it is not done here.

Proof the gate bites

  • Stable: after recording, snapshots.sh compare all passed three times in a row, then once more on Mac. Every run passed on both platforms, with no flake.
  • One-point paper margin (DocsPageGeometry.sideMargin 72→73 and 20→21): every one of the 46 editor images failed on both platforms, 2.4–14% of pixels changed each. One existing docs screen, other-ways, also failed on Mac in that run. It is green in every other run.
  • One attribute (code font scale 0.85→0.86): exactly the 8 Mac Millbrook screens failed, the only ones with code on screen, about 1.1–1.4% each. Every other screen passed.
  • Both changes were reverted, and the gate is green again.

The tolerance is the kit's standard: a pixel counts if a channel moves more than 2 of 255, and at most 8 pixels may change. S1 must therefore be pixel-identical.

Findings in today's renderer (recorded as they are, not fixed)

  1. iOS editor update loop. This is the important one. Opening a document that holds a list (and, in this harness, an image or a rule) never finishes on iOS. applyRender finds the content unequal to what it rendered (it holds an NSTextList or NSTextAttachment), so it assigns attributedText again. That moves the caret to the end and back. iOS textViewDidChangeSelection writes the selection binding even while it is applying ("Modifying state during view update"); the Mac guards this with !applying. The write calls updateUIView again, without end, at 100% CPU and growing memory (29 GB before I killed it). - Reproduced through the production DocsWorkspace with documentID: in the simulator (iOS 27.0): the Russian fixture with its lists hangs, and its first four blocks without the lists open fine. - The harness also looped after a peer's insert and after typing in the middle of a document. - Not checked on a device. - This harness therefore pins the iOS selection binding (EditorPage.selection; the Mac keeps the real one). The pictures are what the renderer draws. The loop needs its own fix branch, which is a production change and so out of S0's scope. It probably belongs before S1, which rewrites exactly this path.
  2. Lists draw no markers on Mac or iOS. NSTextList is set and indented, but no bullet or number is drawn.
  3. Arabic paragraphs are left-aligned: NativeTextProjection sets .left rather than .natural.
  4. iOS paged: the first page's text starts at the paper's top with no 72 pt margin, and "Page 1" is drawn at the foot of page 1, where the Mac draws "Page 2" at the break.

Gates

native/scripts/check-native.sh (includes swift test), the snapshot run above, and hub CI: results in the reply below. WorkspaceInitTests and SignedInLaunchTests are untouched and run in swift test. The harness creates its model in .task, never in init or body.

Commits

  • cab8399 harness and fixtures, plus BUILDING.md and snapshots.sh notes
  • 9f4fcff 22 Mac baselines (1.8 MB)
  • 3e12285 24 iPhone and iPad-width baselines (1.8 MB)

Each was pushed on its own, with http.postBuffer.

Gates at 3e12285, all green:

  • native/scripts/check-native.sh: passed ("Native checks passed"). swift test ran 171 tests: 0 failures, 4 skipped. The skips are the two snapshot gates (they need RASTRILLO_SNAPSHOTS) and two env-gated tests that are skipped on main too. WorkspaceInitTests and SignedInLaunchTests are green.
  • native/scripts/snapshots.sh compare all: green three times running after the recording, and green again on Mac after the two deliberate mutations were reverted.
  • Hub CI: amadan ci status oficina/docs -branch feat/native-editor-snapshots exit 0 (CI passed).

Ready for review. Not merged, released or deployed.

Review by Claude Fable (model claude-fable-5-2), at 3e12285. Verdict: APPROVE AFTER FIXES.

The harness is sound and the gate does what S0 needs. Fixes 1–3 are small and should land before S1a starts; the rest are notes.

What I ran

All in my own review-only worktree (now removed), at load average 8–22:

  • Mac compare, five runs: the 22 editor images matched every time, from a different checkout path.
  • iPhone compare, one run: 20 + 4 editor images and the 32 docs images matched.
  • Never-ready mutation (Mac): I made the Russian screen throw before ready. compare and record both failed with "still changing after 3.0 seconds" on both variants, and record rewrote no baseline. A page that never settles fails; it is not recorded.
  • Not run: the never-ready mutation on iPhone, and a true main-thread hang (finding 1).

Findings

  1. Medium — a real hang has no time limit. native/scripts/snapshots.sh:31,36; kit SnapshotRenderer.settle. - The counter and the kit's 3 s limit both run on the main actor. A main-thread livelock (the iOS update loop you hit) never reaches the limit, so the run neither fails nor records. It spins until killed; yours reached 29 GB. - Fix: pass -test-timeouts-enabled YES -default-test-execution-time-allowance 120 through to xcodebuild for the iPhone half (the script already forwards extra arguments), and put a wall-clock limit around the Mac swift test.
  1. Medium — nothing enforces the gate except the rule, and the rule has no OS-drift procedure. native/BUILDING.md:165, .amadan/ci.d/20-native. - Hub CI only compiles the test; it is skipped without RASTRILLO_SNAPSHOTS. That is right, because baselines are exact only on macOS 27.0.0, Xcode 27.2 and runtime 24A434. - Scenario: this Mac takes 27.1 or a new Xcode mid-S1. Every screen fails, and drift can't be told from an S1 regression. - Fix, in BUILDING.md: S1a and S1b paste the compare all output in their discussion, and the reviewer re-runs it (about a minute per platform). When ENVIRONMENT no longer matches, re-record from main in its own commit first, and never on a rendering branch.
  1. Medium — the Mac paged and pageless Millbrook screens are the same picture. EditorSnapshots.swift:79-82. - editor-paged-* and editor-pageless-* are byte-identical at 100% and at 150%, light and dark (four pairs). At scroll 0 nothing on the Mac differs between the modes. - So Mac pageless is only shown by the two break screens at 100%, and no 150% screen has a page break in it. S1b rewrites pagination. - Fix: point the 150% pair at .breaks scrolled to the heading break, or add that pair. The 100% pair can stay as it is.
  1. Medium, pre-existing — other-ways flakes on Mac. DocsSnapshots.swift:30. - It failed one of my five runs (3761 and 5512 pixels) with no code change. This is the failure you put down to the margin mutation. - compare all will go red about one run in five for a reason unrelated to the editor, which teaches people to re-run. Fix it or hold it unsettled the same way, on its own branch, before S1.
  1. Low/medium — the pinned iPhone selection is fine for the pictures, but needs a follow-up. EditorSnapshots.swift:345-351. - Nothing is first responder, so no selection is drawn and the pin hides no pixels. - It does mean the iPhone screens don't take production's path, where the selection is written during a render. S1a rewrites exactly that reconciliation. - When fix/ios-render-loop lands, switch iOS back to $model.selection and confirm the 24 baselines are unchanged, before S1a. With finding 1's time limit, a returning loop then fails the gate.
  1. Low — the iPhone scripted edit is not the keyboard's path. EditorSnapshots.swift:221-230. It edits textStorage and calls the delegate by hand. That is acceptable for a pixel gate; the comment says so.
  1. Low — known renderer bugs are baked in. This is acceptable. - S0's job is "today's pixels", and S1 must not fix them by accident. - Record the list beside the baselines or in BUILDING.md, not only here. - Each fix gets its own branch and re-records only the affected screens. Fix lists, Arabic alignment and the iPhone top margin together if you can: lists alone touch about 30 images, roughly 2.4 MB. - One more for the list: the iOS blockquote appears to draw no bar, where the Mac does (seen in editor-ipad-paged). - In Mac light, desk and paper are both pure white, so only the dark variants show paper edges and separator bands.
  1. Low — size and push notes. - 3.6 MB of PNG on a 27.6 MiB pack is fine once. Every full re-record adds as much again, so batch them. - BUILDING.md:168 and snapshots.sh:13 still say to push under about 700 KB. These went up as two 1.8 MB pushes with http.postBuffer. Say what works.

Checked and fine

  • Matrix against spec §11 and finding 13: all there. The iPad width is drawn in the iPhone simulator, which is sound because the renderer reads only the width (no idiom or size class in DocsKit).
  • AX3: the images are byte-identical to the default size, which is the proof wanted.
  • Determinism: fonts registered first, fixed scroll offsets, overlay scrollers, no clock.
  • Readiness: timeouts fail closed. A screen took about 0.4 s under load, against a 2 s step limit and the kit's 3 s.
  • Base: main has gained only the spec since 1433e2b, so the baselines are current.

Fixes for Fable's review, pushed to feat/native-editor-snapshots as 1530a71, 7ccdd2c and 9dae2db (one commit per area). Not merged.

1. Hangs now have a time limit (1530a71, native/scripts/snapshots.sh).

  • The Mac half builds first, then runs the test under a wall clock: SNAPSHOT_MAC_LIMIT, default 300 s. When the limit passes, the script kills the whole process tree.
  • The iPhone half passes -test-timeouts-enabled YES -default-test-execution-time-allowance 120 to xcodebuild, and prints XCTest's "exceeded execution time allowance" line when it fires.
  • Proof: I added a deliberate main-thread spin to the ru editor screen, then reverted it. - Mac, with SNAPSHOT_MAC_LIMIT=60: the run stopped at 60 s ("the snapshot run passed its 60 s limit") and failed, 67 s in total. - iPhone: "exceeded execution time allowance of 2 minutes"; xcodebuild restarted the runner for the other test, which passed, and reported TEST FAILED. The half took 177 s.
  • Both halves now run even when the first one fails, and the script exits non-zero if either did.

2. Enforcement procedure (1530a71 and 7ccdd2c).

  • The script now prints the environment each half drew on, and checks it against the baselines' ENVIRONMENT. When they differ it says "ENVIRONMENT DIFFERS … Drift, not a regression: re-record from main in its own commit first". I checked that message against a faked mismatch.
  • native/BUILDING.md gains "Enforcing it": - Hub CI builds but skips the gate (baselines: macOS 27.0.0, Xcode 27.2, runtime 24A434). - Every rendering branch (S1a, S1b, renderer fixes) pastes the full compare all output into its discussion, and the reviewer re-runs it. - On an environment change, re-record from main on a branch whose only change is the baselines, land that first, and never re-record on a rendering branch. - A renderer fix re-records only the screens it means to change.
  • .amadan/ci.d/20-native carries a pointer to the same procedure.

3. 150% now crosses a page break (9dae2db).

  • editor-paged-150 becomes editor-150. The picture is the same; the bytes match the old baseline.
  • editor-pageless-150 is gone, because it was byte-identical.
  • New: editor-paged-150-heading-break and editor-pageless-150-heading-break (the .breaks fixture at 150%, scrolled to the first break). These two differ from each other, as they should.
  • Mac editor images go from 22 to 24, 46 to 48 in all.

7. Known renderer bugs are now recorded in the repo (7ccdd2c): BUILDING.md, "Known rendering bugs in the baselines".

  • No list markers, on either platform.
  • Arabic is left-aligned.
  • iPhone and iPad paged: the text sits about 72 pt high, and lines split across pages.
  • The page label differs by platform.
  • iOS draws no blockquote bar. I confirmed this in editor-ipad-paged.
  • In Mac light, the desk is as white as the paper.
  • The pinned iOS selection, until the render loop is fixed.

8. Push guidance now says what works: one commit per push with git -c http.postBuffer=209715200 push. It is in BUILDING.md and the script header, and both also say to batch re-records.

Gates at 9dae2db:

  • snapshots.sh compare all is green, with environments printed and matching. The Mac half ran green once more on the final script.
  • Hub CI at 9dae2db: amadan ci status exit 0 (CI passed).

Finding 4 (other-ways) is on its own branch, fix/snapshot-other-ways-flake, with its own discussion. Finding 5 waits for fix/ios-render-loop.

Finding 4 is now on its own branch: fix/snapshot-other-ways-flake (ac2a9c0), discussion #167. CI passed there.

Rebased onto main 198c1da (the iOS render-loop fix, #162), plus finding 5. Force-pushed; head is now 2a9eaa1. Not merged.

  • Rebase: no conflicts, native/BUILDING.md included. The hotfix's test-iphone.sh paragraph and this branch's snapshot-gate sections are both kept. The hotfix doesn't touch the engine (native/crdt and native/host), so the CRDT artifact is unchanged.
  • Finding 5 (2a9eaa1): EditorPage now passes $model.selection on both platforms, as DocsWorkspace does. The .constant(model.selection) pin is gone, along with its comment and the render-loop entry in BUILDING.md's list of bugs in the baselines.
  • No baseline changed. native/scripts/snapshots.sh compare all at 2a9eaa1:
Test Case '-[DocsSnapshots.DocsEditorSnapshots testEditorScreens]' passed (10.006 seconds).
Test Case '-[DocsSnapshots.DocsSnapshots testKeyScreens]' passed (5.472 seconds).
docs-editor snapshots (compare, 24 images)
docs snapshots (compare, 22 images)
mac half drawn on:
  docs: baselines drawn on the same
  docs-editor: baselines drawn on the same
docs-editor snapshots (compare, 20 images)
docs-editor-ax3 snapshots (compare, 4 images)
Test Case '-[DocsPhoneSnapshots.DocsEditorSnapshots testEditorScreens]' passed (7.675 seconds).
docs snapshots (compare, 32 images)
Test Case '-[DocsPhoneSnapshots.DocsSnapshots testKeyScreens]' passed (8.779 seconds).
iphone half drawn on:
  docs: baselines drawn on the same
  docs-editor: baselines drawn on the same
  docs-editor-ax3: baselines drawn on the same
exit 0

The environment is macOS 27.0.0 with Xcode 27.2 (27B52), and iOS 27.0 (24A434) on an iPhone 18 Pro (iPhone19,2). The pin hid no pixels.

  • Hub CI at 2a9eaa1: amadan ci status oficina/docs -branch feat/native-editor-snapshots exit 0 (CI passed).

Landed on main (squash) after Fable's APPROVE AFTER FIXES (all fixes applied, finding 5 done after the #162 hotfix, no baseline change) and green hub CI at 2a9eaa1. S1a next; every rendering branch pastes snapshots.sh compare all and the reviewer re-runs it.