oficina / docs Public

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

Plain git — no account needed to clone.

Download

Download this file

1#!/usr/bin/env bash
2# The only CI this repo has. Everything a branch must pass before it can
3# squash-merge, in one script so CI and what you run locally are one
4# definition rather than two that drift.
5set -euo pipefail
6
7# rustup installs to ~/.cargo/bin, which is not on the PATH of a systemd
8# user unit and is not on the PATH of a login shell when rustup was run
9# with --no-modify-path. Source it here rather than depending on whoever
10# configured the runner having got it right — a gate that only works on one
11# machine is not a gate.
12[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
13
14for tool in cargo rustc rustfmt go node npm; do
15 command -v "$tool" >/dev/null || { echo "gate: $tool not on PATH" >&2; exit 1; }
16done
17rustup target list --installed 2>/dev/null | grep -qx wasm32-unknown-unknown \
18 || { echo "gate: wasm32-unknown-unknown target missing — rustup target add wasm32-unknown-unknown" >&2; exit 1; }
19
20export CGO_ENABLED=0
21export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}amadan.net/oficina/estilo.git,amadan.net/oficina/agent-access.git"
22
23# The runner clones a fresh worktree per branch, so fixtures/node_modules
24# (gitignored, like any node_modules) never carries over from a previous
25# run. npm ci reads fixtures/package-lock.json rather than resolving from
26# fixtures/package.json, so the installed yjs is exactly the pinned 13.6.27
27# — no silent drift from whatever a bare `npm install` would pick.
28echo "=== fixtures: node dependencies"
29(cd fixtures && npm ci)
30
31# save-queue.mjs is the editor's retry/drop logic, factored out so it
32# runs under plain Node with no DOM/browser needed (fixtures/
33# save-queue.mjs's own doc comment). This is fix round 1's regression
34# test for F1 — a permanently-rejected batch used to retry forever and
35# absorb every later edit, losing all of it silently — and it belongs
36# in the gate, not just something run by hand once, or a future
37# regression here goes uncaught the same way F1 itself did.
38echo "=== fixtures: the save queue's retry/drop logic (F1 regression)"
39(cd fixtures && node --test save-queue.test.mjs)
40
41# fix round 2's blocking finding: a resync that failed once used to
42# give up forever, silently recreating F1's own data loss for the
43# rest of the session (resync-controller.mjs's own doc comment has
44# the full mechanism). Same reasoning as the F1 test above — this
45# belongs in the gate, not just something run by hand once.
46echo "=== fixtures: the resync retry/backoff state machine (fix round 2 regression)"
47(cd fixtures && node --test resync-controller.test.mjs)
48
49# What a resync carries onto the rebuilt document (carry.mjs): which of
50# the updates written while diverged integrate there and are posted, and
51# the replay of a paste that waited for its font when its own updates
52# were anchored to the refused text (Claude Fable on #88: eleven cases,
53# and the classification that read only a client's first update).
54echo "=== fixtures: what a resync carries, and the replay of a waiting paste"
55(cd fixtures && node --test carry.test.mjs)
56
57# live-updates.mjs owns the cross-tab cursor and the stream's
58# connection policy, and two of its tests are regressions for defects
59# caught in review before the code existed: a cursor that advances
60# over a gap skips rows permanently, and an idle-close whose only
61# reopen triggers are visibility/focus/edit leaves a tab that is
62# merely being READ permanently stale. Both fail silently in a
63# browser — the document still saves, it just stops learning — so
64# they belong in the gate rather than in a manual check nobody
65# repeats.
66echo "=== fixtures: the live-update cursor and connection policy"
67(cd fixtures && node --test live-updates.test.mjs)
68
69# fixtures/build-bundles.mjs is byte-reproducible: no sourcemaps, no
70# banners, no timestamps, no absolute paths baked into the output, and
71# esbuild's actual work happens in a pinned native binary (0.28.2),
72# not interpreted JS, so the Node version running it does not enter
73# into the result either. Five consecutive runs on this one runner
74# produce identical sha256, which is all a freshness check ever
75# needs — a weaker bar than cross-machine reproducibility, and
76# already met. Rebuilding here and diffing what's committed mirrors
77# "the embedded wasm must match a fresh build" below, for the same
78# reason that check is safe rather than randomly red.
79# align.mjs is the editor's half of paragraph alignment — the schema
80# attribute, the command and the active-state reader — factored out of
81# editor-entry.js and toolbar.mjs so it runs under plain Node with no
82# DOM, exactly like the three modules above. It belongs in the gate for
83# the reason its own tests spell out: the class names and attribute
84# values in it are the same vocabulary as core/src/fragment.rs's
85# ALIGNMENTS and internal/export/pdf.go's alignOf, which are separate
86# binaries that cannot import it, and both of the mistakes it guards
87# (an alignment nobody chose written into the document, a command that
88# edits when it was only being asked a question) fail silently in a
89# browser.
90echo "=== fixtures: paragraph alignment in the editor"
91(cd fixtures && node --test align.test.mjs)
92
93# fonts.mjs is the font vocabulary, read from internal/fonts/fonts.json —
94# the families, their marks, and which of them an unmarked run is in. A
95# toolbar that disagrees with the server about the default fails
96# silently: the control names a face the text is not in. fonts.mjs also
97# runs a load-time guard that only executes because this test imports
98# it, the same arrangement align.test.mjs has with toolbar.mjs's.
99echo "=== fixtures: the font vocabulary and its default"
100(cd fixtures && node --test fonts.test.mjs)
101
102# font-session.mjs is the one rule every path to the screen goes through:
103# text is never painted in a face it will later leave (Paul, 2026-10-24).
104# A pick loads before it applies, a collaborator's change waits for its
105# font, and the page's gate commits a late face to its fallback. Each
106# failure is invisible in a Go test and a flash in a browser.
107echo "=== fixtures: fonts load before text is painted in them"
108(cd fixtures && node --test font-session.test.mjs)
109
110# paste.mjs decides what a blank line pasted out of Google Docs means.
111# It is in the gate because the mistake it is one edit away from is
112# invisible until someone pastes: turning EVERY hard_break into a
113# paragraph break would destroy Shift+Enter, which editor-entry.js binds
114# and core/src/fragment.rs renders, and it would do so only on the paste
115# path — which had no test at all before this file. Like the four above
116# it is DOM-free: transformPasted takes a Slice and returns a Slice.
117echo "=== fixtures: what a pasted blank line means"
118(cd fixtures && node --test paste.test.mjs)
119
120# indent.mjs is the second block attribute's vocabulary — the value is a
121# NUMBER where alignment's is a string, so where align.test.mjs above
122# checks that a closed table is consulted, this checks a clamp. The
123# cases that matter are the ones no editor produces and
124# POST /d/{sqid}/updates accepts anyway: a level past the maximum, a
125# zero, a value that is not a number. core/src/fragment.rs holds the
126# same three in Rust, independently, so a document cannot indent one
127# distance on screen and another on paper.
128echo "=== fixtures: the indent vocabulary and its clamp"
129(cd fixtures && node --test indent.test.mjs)
130
131# sizes.mjs is the point ladder, and importing it here is what makes its
132# own module-load guard run in the gate — the same arrangement align and
133# fonts already have, for the reason their comments give: a guard that
134# only executes when a browser mounts the editor is dead code in CI, so
135# a drifted vocabulary would pass everything and then throw for every
136# user. The legacy four-step marks are the part most worth holding: they
137# are no longer offered and must go on being understood forever, because
138# documents in the wild carry them.
139echo "=== fixtures: the point ladder, and the four-step scale it replaced"
140(cd fixtures && node --test sizes.test.mjs)
141
142# autoformat.mjs turns "- " into a bullet, and the Backspace that takes
143# it back is the whole reason the feature is tolerable rather than
144# infuriating. Both halves are in the gate because both are invisible
145# until someone types: a rule that fires where it should not, and a
146# revert that does not give back the characters, each look like a broken
147# editor and neither shows up in any Go test. DOM-free — ProseMirror's
148# state, model and inputrules packages are all headless, which matters
149# because Chromium will not start in this project's sandbox, so a rule
150# tested only through the browser drive is tested nowhere most of the
151# time.
152echo "=== fixtures: the autoformat rules, and the Backspace that undoes one"
153(cd fixtures && node --test autoformat.test.mjs)
154
155# A word count is a number people quote to each other, so being quietly
156# wrong is worse here than in most places. The cases that matter are the
157# ones whitespace-splitting gets wrong — punctuation, and the languages
158# that put no space between words at all, where splitting on whitespace
159# reports 1 for a whole sentence.
160echo "=== fixtures: counting words, including where there are no spaces"
161(cd fixtures && node --test wordcount.test.mjs)
162
163# menu.mjs's enabling logic, against a forty-line fake DOM.
164#
165# In the gate because its absence already shipped a bug: sync read the
166# module constant where it should have read the merged table, so every
167# command the caller passed in — paged, infinite, word count, the
168# shortcuts sheet — was disabled on every update and could never be
169# clicked. Three deliverables unreachable, and nothing saw it: the Go
170# tests check the model and the markup, and the gate cannot open a
171# browser. The first test in this file fails against that exact edit.
172echo "=== fixtures: which menu items the editor enables"
173(cd fixtures && node --test menu.test.mjs)
174
175# Both bars of the editor's chrome, against the same kind of recording
176# fake DOM. One plugin drives them in the browser (the toolbar's, with
177# the menu on its onSync) and this drives them the same way.
178#
179# In the gate because its absence shipped a visible flash and would ship
180# it again. Both bars sync on every ProseMirror state update, and both
181# used to rewrite every control's state unconditionally; setAttribute
182# with the value already there still invalidates style and still records
183# a mutation, and so does setting a reflected boolean property to the
184# value it already holds. So the chrome repainted once per keystroke,
185# and a tab getting its frames back paid for the whole backlog in one
186# visible frame — 23 mutations measured on reveal, 21 of them redundant
187# attribute writes.
188#
189# Held against the source as well as against the controls that exist
190# today, because the failure mode is a control added later: the count
191# went from 12 to 23 across the toolbar redesign, and then menu.mjs,
192# written afterwards by a different session, reproduced the whole defect
193# from scratch. Five of the 23 were its.
194echo "=== fixtures: the editor's chrome writes only what changed"
195(cd fixtures && node --test toolbar.test.mjs)
196
197# The roving tab stop reaches only drawn controls: from 64rem the bar is
198# the inspector, which the person can close, and a stop parked on a
199# hidden control sends focus nowhere (spec I2, C2; review on #106).
200echo "=== fixtures: the formatting bar's tab stop reaches only drawn controls"
201(cd fixtures && node --test toolbar-roving.test.mjs)
202
203echo "=== the editor bundle must match a fresh build"
204(cd fixtures && node build-bundles.mjs)
205if [ -n "$(git status --porcelain -- internal/docs/static/)" ]; then
206 echo "gate: internal/docs/static/ does not match a fresh build. Run 'cd fixtures && node build-bundles.mjs' and commit the result." >&2
207 # The rebuild above just mutated a committed directory as a side
208 # effect of checking it. Restore it to what's actually committed —
209 # tracked changes via checkout, any new hashed file the rebuild
210 # wrote via clean — so the only trace of this failure is the
211 # message and exit code above, not a stray dirty file a later
212 # command (or a re-run of this same script) trips over, or a
213 # rebuilt-to-fresh tree that would silently pass a second run
214 # without anyone having committed anything.
215 git checkout -- internal/docs/static/
216 git clean -fd -- internal/docs/static/ >/dev/null
217 exit 1
218fi
219
220echo "=== rust: fmt"
221cargo fmt --manifest-path core/Cargo.toml --check
222
223# build-wasm.sh is the ONLY clippy invocation in this gate (it runs
224# --all-targets -D warnings -D clippy::disallowed_methods) and it runs
225# BEFORE cargo test, for two reasons that used to be two separate bugs:
226#
227# 1. A second, looser clippy invocation here previously let a banned
228# method planted in a test file sail through this fast check and get
229# caught only ~40s later, inside build-wasm.sh's own clippy run --
230# defeating the point of failing fast. One invocation, no drift.
231# 2. core/tests/no_host_imports.rs asserts zero wasm imports by reading
232# the wasm32 artifact off disk; it only exists after this line. Running
233# cargo test first made the assertion's own presence into a race —
234# it silently reported PASS-via-SKIP unless some other test happened
235# to build the artifact as a side effect first. Building here removes
236# the race instead of hoping to win it.
237# Before the build below, which on Linux amd64 rewrites the stamp: this
238# must read the committed one. The input hash is the same on every host,
239# so this is the freshness check that holds on arm64, where no build
240# reproduces the committed amd64 bytes. It also fails if the committed
241# wasm is not the module the stamp was written for.
242echo "=== the embedded wasm must be built from these sources"
243./scripts/wasm-stamp.sh check docs_core
244
245echo "=== wasm: clippy, then the artifact the host embeds"
246./scripts/build-wasm.sh
247
248echo "=== rust: build, test"
249# DOCS_REQUIRE_WASM=1 turns core/tests/no_host_imports.rs's "artifact
250# missing" branch into a failure instead of a skip. It is always set here
251# because the wasm artifact was just built above; unset, a bare local
252# `cargo test` still skips gracefully on a fresh clone.
253export DOCS_REQUIRE_WASM=1
254cargo build --release --manifest-path core/Cargo.toml
255cargo test --manifest-path core/Cargo.toml
256
257echo "=== the embedded wasm must match a fresh build"
258if [[ "$(uname -s)" == Linux && "$(uname -m)" != x86_64 ]]; then
259 # Cargo hashes the host architecture into crate identities, so no
260 # Linux arm64 build reproduces the committed amd64 bytes (the build
261 # script builds natively here). The input stamp checked above holds
262 # freshness on this host; Linux amd64 runs check the bytes as well.
263 echo "gate: byte comparison skipped on Linux/$(uname -m): no build on this host reproduces the canonical amd64 bytes; the input stamp above holds freshness here"
264elif ! cmp -s core/target/wasm32-unknown-unknown/release/docs_core.wasm internal/core/testdata/docs_core.wasm; then
265 echo "gate: internal/core/testdata/docs_core.wasm is stale. Re-copy it." >&2
266 exit 1
267fi
268
269echo "=== wire compatibility, both directions"
270./scripts/wire-gate.sh
271
272# Fiesta's spacing check (Paul, 2026-11-22: no ad-hoc spacing): every
273# margin, padding and gap in brand/'s stylesheets is a var(--rst-sp-N),
274# or says why not with /* spacing-allow: why */. The templates' <style>
275# blocks, which the tool does not read, are held to the same check by
276# TestEveryStylesheetIsOnTheSpacingScale in the go test below.
277echo "=== spacing: every margin, padding and gap on the scale"
278go tool fiesta spacing internal/docs/brand
279
280echo "=== go: vet, test, gofmt"
281go vet ./...
282# The browser checks (internal/docs/*_browser_test.go) need a Chromium, so
283# the gate does not run them; it vets them, so a test behind a tag that
284# nothing compiles cannot rot silently.
285go vet -tags browser ./internal/docs/
286go test ./... -count=1
287
288echo "=== go: race detector on warm handles and the stream"
289# Everything above builds with CGO_ENABLED=0, which is the app's own
290# constraint, so no other step runs the race detector. It needs cgo and a C
291# compiler; the runner already has one, since cargo links its host test
292# binaries with it. Without one, this step fails loudly rather than skipping.
293# Scoped to the code with its own locking: the warm-handle cache (warm.go,
294# the live-push spec's §3.5, including an 8-goroutine stress test), the
295# stream, and live push (push.go: the stream and origin registries, the
296# frame cache, late answers). -short trims the 4,200-POST test, which needs no detector.
297CGO_ENABLED=1 go test -race -short -count=1 -run 'Warm|BoundToATransaction|Stream|Push|LateAnswers' ./internal/docs/
298test -z "$(gofmt -l .)" || { echo "gate: gofmt"; gofmt -l .; exit 1; }
299
300echo "=== go: build ./... (the app, not just the packages tests import)"
301# go vet/go test above already type-check every package they touch,
302# but neither one proves cmd/docs itself links into a runnable binary
303# under CGO_ENABLED=0 with no -mod flag (this repo's own constraint) —
304# a plain build is the only step that actually does. CGO_ENABLED is
305# already exported above; stated again here so this line reads
306# correctly on its own.
307CGO_ENABLED=0 go build ./...
308
309# There used to be a further step here: build cmd/docs with -tags
310# release and assert the result refuses to start with -dev-auth on
311# its command line, proving a release binary had no code path that
312# could ever turn the development-only stand-in identity on
313# (cmd/docs/devauth_flag_release.go). Fix round 1 on Task 1 deleted
314# that identity outright — internal/docs/devauth.go had zero readers
315# once rastrillo/auth's RequireSession started guarding every
316# document route unconditionally, with no flag anywhere capable of
317# disabling it — so the `release` build tag it was the only user of
318# is gone too, and there is no longer a release/non-release
319# distinction for this gate to hold apart. The property that check
320# guarded (an unauthenticated binary reachable at a real URL) is now
321# covered a different way: go test above runs
322# TestNewRefusesMissingInstanceKeyOutsideDevelopment and
323# TestNewRefusesMissingMailOutsideDevelopment (internal/docs/auth_test.go),
324# proving Env other than "development" still fails closed on its own
325# fail-closed configuration, and TestSignInRequiredForEverything
326# proves every document route — GET and POST alike — refuses a
327# signed-out request. A stray "-dev-auth" on any build's command line
328# today reaches rastrillo.Resolve's own flag.FlagSet undefined, and is
329# refused exactly like any other unrecognized flag.
330
331echo "gate: ok"
332