| 1 | # CI |
| 2 | |
| 3 | `ci.d/10-gate` is the only CI this repo has. It runs on every push to the |
| 4 | amadan remote, and it is the same script you can run locally — one |
| 5 | definition rather than two that drift. |
| 6 | |
| 7 | It requires a Rust toolchain with the `wasm32-unknown-unknown` target and |
| 8 | the `rustfmt` component, Go with `CGO_ENABLED=0`, and Node with `npm` on |
| 9 | `PATH`. The gate sources `~/.cargo/env` itself and checks every tool up |
| 10 | front, so a missing dependency fails on the first line with its own name |
| 11 | rather than fifty lines in as `cargo: command not found`. |
| 12 | |
| 13 | The runner clones a fresh worktree per branch, so `fixtures/node_modules` |
| 14 | never carries over — the gate runs `npm ci` itself, against |
| 15 | `fixtures/package-lock.json`, so the installed `yjs` is always exactly |
| 16 | 13.6.27 rather than whatever a bare `npm install` would resolve. |
| 17 | |
| 18 | **Known tradeoff:** that `npm ci` needs the npm registry reachable at run |
| 19 | time. It is the right fix for the fresh-worktree-per-branch problem above, |
| 20 | and the lockfile is committed so the *version* resolved never drifts, but |
| 21 | it does mean the gate is not fully offline-capable the way the Rust and Go |
| 22 | steps are once their caches are warm. If the registry is ever unreachable |
| 23 | from the runner, that is the failure this line produces — not a bug in |
| 24 | the gate itself. |
| 25 | |
| 26 | ## The runner |
| 27 | |
| 28 | Jobs are claimed by an `amadan runner` on the machine that has one. Two |
| 29 | things about it were wrong when this repo was created, and both fail |
| 30 | silently rather than loudly: |
| 31 | |
| 32 | - **The runner must be told to serve this repo.** `amadan runner -repo …` |
| 33 | is an allowlist. A repo nobody listed gets `amadan ci status` exit 3 |
| 34 | forever — "no status recorded", which reads like the gate has not run yet |
| 35 | rather than like nothing will ever run it. |
| 36 | - **The runner's `PATH` is the systemd unit's, not your shell's.** |
| 37 | `~/.cargo/bin` is not on it by default. |
| 38 | |
| 39 | Both were fixed on `DOCS-T1` on 2026-08-30 by editing |
| 40 | `~/.config/systemd/user/amadan-runner.service` and restarting. A restart |
| 41 | abandons any job already running, so check it is idle first. |
| 42 | |
| 43 | The gate fails if `internal/core/testdata/docs_core.wasm` is stale, because |
| 44 | `go:embed` will otherwise embed a stale module and the tests will pass |
| 45 | against it. It checks this two ways: |
| 46 | |
| 47 | - **On every host**, `scripts/wasm-stamp.sh check docs_core` recomputes a |
| 48 | SHA-256 over the files that decide the module's bytes and compares it with |
| 49 | `internal/core/testdata/docs_core.wasm.stamp`. The script lists those files: |
| 50 | the toolchain pin, `.cargo/config.toml`, `scripts/build-wasm.sh`, the |
| 51 | crate's manifest, lockfile and `src/`, and the vendored crates it patches |
| 52 | in. It also checks the committed wasm is the build the stamp was written |
| 53 | for. A failure reads "wasm is stale: inputs changed since it was built; |
| 54 | run scripts/build-wasm.sh". |
| 55 | - **On Linux amd64** it also rebuilds the module and compares bytes. |
| 56 | |
| 57 | To refresh the module, run `./scripts/build-wasm.sh`, which writes the stamp, |
| 58 | then copy `core/target/wasm32-unknown-unknown/release/docs_core.wasm` to |
| 59 | `internal/core/testdata/` and commit the wasm and its `.stamp` together. |
| 60 | |
| 61 | It also fails if regenerating the Yjs fixtures changes them. Fixtures are |
| 62 | the wire contract, not an output: a deliberate rule change regenerates them |
| 63 | in the same commit as the change. |
| 64 | |
| 65 | ## The app, not just the core |
| 66 | |
| 67 | `go vet ./...` and `go test ./...` already cover `cmd/docs` and |
| 68 | `internal/docs` — the rastrillo app built on top of `internal/core` — but |
| 69 | neither one proves the app actually links into a runnable binary. The gate |
| 70 | also runs `CGO_ENABLED=0 go build ./...` for that. |
| 71 | |
| 72 | There used to be a further step here: a separate `-tags release` build, |
| 73 | run with `-dev-auth` on its command line, asserting it refused to start — |
| 74 | proving a release binary had no code path that could turn a |
| 75 | development-only stand-in identity on. That identity |
| 76 | (`internal/docs/devauth.go`) had zero readers once rastrillo/auth's |
| 77 | `RequireSession` started guarding every document route unconditionally |
| 78 | (a fix round on Task 1, once real per-person sign-in existed), so it was |
| 79 | deleted rather than kept as dead code — and the `release` build tag it |
| 80 | was the only user of went with it. There is no release/non-release |
| 81 | distinction left for this gate to hold apart; `go test` covers the |
| 82 | fail-closed properties that matter now |
| 83 | (`TestNewRefusesMissingInstanceKeyOutsideDevelopment`, |
| 84 | `TestNewRefusesMissingMailOutsideDevelopment`, |
| 85 | `TestSignInRequiredForEverything` — all `internal/docs/auth_test.go`). |
| 86 | `scripts/run-dev.sh` builds and runs the ordinary binary with `-env |
| 87 | development`, a fixed port, and a scratch database — one command to see |
| 88 | the app in a browser, signed in for real via a magic link logged to the |
| 89 | terminal instead of mailed. |
| 90 | |
| 91 | The embedded WASM is built on Linux amd64 using fixed `/work`, |
| 92 | `/usr/local/cargo` and `/usr/local/rustup` paths. Rust/Cargo's crate identities |
| 93 | otherwise change code ordering across hosts, even with remapped source paths. |
| 94 | Linux amd64 uses unprivileged bubblewrap when available; Macs use the pinned |
| 95 | Rust Docker image, so install Docker on development Macs. Docker caches and |
| 96 | writable targets are separate from source. |
| 97 | |
| 98 | Cargo also hashes the host architecture into crate identities, so no build on |
| 99 | Linux arm64 (hosted CI) reproduces the committed amd64 bytes; it is about a |
| 100 | kilobyte larger. There `scripts/build-wasm.sh` builds natively with the |
| 101 | host's toolchain, for the tests that read the artifact, and writes no stamp. |
| 102 | The gate holds freshness on arm64 with the input stamp alone. |
| 103 | |