Artifact 7c3df71dc6f347cf6063b369bddec478f409fe42f302ed0296be00a107336f96:
- File
docs/quality.md
— part of check-in
[27d847f693]
at
2026-11-18 16:19:19
on branch trunk
— suit syncs and clones over https
suit sync, suit clone and suit tend now work with https:// remotes. http:// and file:// keep libfossil's built-in channel.
libfossil is the private byot build 2f20f44ba4 in place of trunk f2983dcd78, approved while suit is being proven; only libfossil.c and libfossil.h differ from trunk's files. Its stream channel does all of the HTTP: request headers, Content-Length, chunked and close-delimited replies (the last only after a clean close), the reply-size limit and the timeout. suit supplies the transport: src/tls.c, over non-blocking TCP and BearSSL 0.6, now vendored.
- TLS 1.2 only, ECDHE key exchange, AES-GCM or ChaCha20-Poly1305. A server offering only TLS 1.3, RSA key exchange or CBC is refused. - The chain is verified against trust anchors and the host name against the certificate. Anchors come from the system's PEM bundle read at run time (SSL_CERT_FILE, then the usual macOS and Linux paths), or from a per-wardrobe CA file set with --ca, which replaces the bundle. No roots are compiled in and there is no way to trust anything. - A certificate file must be a regular file owned by the user or root, writable by no one else, in a folder that passes the same check; --ca refuses a symlink, and a FIFO is refused at once. - Redirects are refused, never followed, and the message names the new address. No proxy support. - Nothing is sent before the handshake has verified. The login goes out only as libfossil's login card. Commands that read the sync secret turn core files off first. - Every connect, read, write and name lookup waits in poll with a 30 s idle limit, and a whole command stops after 10 minutes. getaddrinfo has no deadline, so it runs in a forked child that is killed and reaped. - BearSSL makes no system call of its own: it is built without its own randomness or clock, and suit seeds it and gives it the time through its fault wrappers. - Exit 18 now means the secure connection failed (handshake, certificate, host name). 17 stays the network and 19 a refused login.
A per-wardrobe CA file is kept in cafiles in suit's home folder, one NAME PATH line each. suit-run is built without the network code and is unchanged at 35496 bytes; the speed budget passes. Release suit went from 2291288 to 2490024 bytes.
An independent security review found no critical or high issues. Its one medium finding, a CA file trusted without checking its owner, mode or type, is fixed here, as are its low ones: separate storage for each set of anchors, core files off, and the release check now covering every test-only switch.
Checked against a real server: an anonymous clone of this repository over https from its forge, 8.4 s, verified with stock fossil.
A new suite, test/https.sh, with 170 cases, runs local servers with test certificates made at test time, including servers that misbehave on purpose. It prints skip lines where openssl or nc is missing. A new fuzz target covers the bundle reader.
3788 unit checks (was 3669), 625 shell cases, 1153 store cases, 985 placement cases, 378 project cases, 236 usage cases, 288 curate cases, 376 curate-apply cases and 170 https cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (76 minutes, on a loaded machine). 100% coverage in all 34 source files. Three store cases that expected "cannot use https yet" now expect the refusal for a missing certificate bundle. (user: dmestas, size: 18978) [annotate] [blame] [check-ins using]
# Quality gates The bar for this project: built and tested under Fil-C, released in a fast build, zero untested branches, zero known flaws, best performance possible. Every gate below is a make target. `make all` runs the full local chain in order and stops at the first failure. The forge's Linux runner has no clang, so it runs `make ci` instead (`ci/test.yml`): the sanitizer tests with the system compiler, then Fil-C. Coverage, the analyzer and the fuzzers are local gates. ## The gates | Target | What it runs | What passing proves | |---|---|---| | `make` | Dev build in `build/dev/`: `-O1 -g`, ASan, UBSan, `-DSUIT_TEST` | It compiles with every warning on and `-Werror`: `-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wcast-align -Wformat=2 -Wundef -Wvla -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough`. | | `make release` | `-O2 -flto`, stripped, no sanitizers, no `SUIT_TEST`, to `build/release/suit` and `build/release/suit-run`, then `test/release_clean.sh` | The binary that ships has no fault-injection code: `strings` finds neither `SUIT_FAULT` nor the wrapper-name table in it, and does find them in the dev build (so the check is not blind). | | `make check` | `test/unit.c`, `test/run.sh`, `test/store.sh`, `test/place.sh` and a replay of every fuzz seed and saved corpus file, on the dev build | Behaviour is right, and no test trips ASan or UBSan. | | `make cover` | The same tests on a `-O0` build with `-fprofile-instr-generate -fcoverage-mapping`, then `tools/cover_gate.py` | Every function, line, region and branch of every file in `src/` ran, as a count per file. On failure it prints each uncovered line and branch. | | `make analyze` | The clang static analyzer over `src/`, test and coverage configurations | No analyzer report. | | `make check-budget` | `suit bench` on the release binary, quiet and then under `loadgen 30 8`, over the stamp a real `suit apply` writes for two wardrobes of 300 skills of 5 files each, 40 agents, 20 commands, a joined instructions file each, slots and files | `suit-run`, the program the timer starts, costs at most 1 ms and 1 MiB more than an empty program built the same way ([decisions](decisions.md)). The stamp lists fewer than 64 paths, a number that does not depend on the 1500 files in the skills (decisions, 2026-11-17). It is `suit-run` and not `suit` because with the store linked in `suit` alone is over the budget under load. Each measurement is taken three times, all three are printed, and the best of the three decides: a load average above about 100 from other work on the machine adds noise the test cannot separate from suit's own cost. The budget itself is unchanged. | | `make fuzz` | libFuzzer on the config parser, the stamp reader and the ledger parser, 30 seconds each; without libFuzzer, a fixed-seed mutation loop | No crash, sanitizer report or failed invariant on generated input. Findings are kept in `build/fuzz/corpus-*` and replayed by `check` and `cover`. | | `make quick SUITE=NAME` | One suite on the dev build as it is, plain, with `USER` and `LOGNAME` unset, and under `umask 027` | The suite does not depend on the environment it ran in. Not a gate: run it first. | | `make gate` | `tools/gate.sh`: the four runs of the whole local gate, in order, stopping at the first failure | Everything the hand-run sequence proved, with logs and summaries in one place. | | `make ci` | What the Linux runner runs (`ci/test.yml`): `make check` with the system `cc`, then `make filc`. Needs no clang, `llvm-cov` or libFuzzer | The code builds warning-free and passes under GCC's ASan and UBSan, which also means it uses no clang-only construct. The build takes `-std=c23`, or `-std=c2x` where that is the only name (GCC 13), and stops with a message if neither works. | | `make corpus` | libFuzzer's merge mode over each target's grown corpus (`build/fuzz/corpus-*`), then `tools/corpus.py` | Not a gate: it keeps the smallest inputs that reach what the grown corpus reaches in `test/corpus/NAME/` as `grown-*` files beside the seeds (at most 300 files or 1 MiB per target), so `check`, `cover` and Fil-C replay them on every push. Run it after a long fuzz and check the new files in. | | `make filc` | `tools/filc.sh`: unit tests, shell suite and fuzz replay built with Fil-C 0.687 | Every out-of-bounds access, use after free and bad cast in those runs would have been a crash, and none was. Linux only; `tools/filc-docker.sh` runs it in an ubuntu:24.04 container elsewhere. | ## Running the gates fast `make check` and `make cover` run the unit program and the shell suites side by side (`tools/suites.sh`), each to its own log in `build/dev/logs/` or `build/cover/logs/`, then print the logs in a fixed order (unit, run.sh, store.sh, place.sh, project.sh, usage.sh, curate.sh, curate_apply.sh, https.sh), each ending with its own summary line (`NAME: N cases, M failed`; unit: `unit: N checks, M failed`). The target fails if any suite exits non-zero or prints no summary line. Each suite works in its own `mktemp -d` folder under `build/tmp`, and the coverage run writes a profile file per process (`%p-%m`), so nothing is shared. `JOBS=N` sets how many suites run at once (and how many fault sweeps `test/store.sh` runs at once, through `TEST_JOBS`). The default is 6 on a machine with six or more cores, the core count from four to five, and 1 below four, as on the small Linux runner. `JOBS=1` is the old behaviour: one suite after another, every sweep one fault after another. `test/store.sh` run by hand runs one at a time unless `TEST_JOBS` is set. How to use them: 1. After touching a suite, `make quick SUITE=run` (or `store`, `place`, `project`, `usage`, `curate`, `unit`). It runs that one suite three ways in a row on the dev build as it is (it builds nothing): plain, with `USER` and `LOGNAME` unset, and under `umask 027`, and prints the three summary lines. That catches an environment-dependent failure in minutes. The full logs are `build/quick-SUITE-WAY.log`. 2. When that is green, `make gate` once. It runs, one after another and stopping at the first failure: `make check CC=gcc-16` and `make all`, each on a fresh `build/dev`, then `make check` with `USER` and `LOGNAME` unset, then `make check` under `umask 027`, to `build/check-gcc.log`, `build/all.log`, `build/check-nouser.log` and `build/check-umask.log`. The last two reuse the dev build `make all` just made (same compiler, same flags). It prints each run's exit status and its summary lines, and fails at once, saying so, if `gcc-16` (or `GATE_GCC`) is not installed. `make check-budget` inside `make all` measures time, so run nothing else while the gate runs. Measured on the 14-core development Mac with other work running (load 25 to 42, so an idle machine is faster). Seconds per suite, then the whole run: | | unit | run.sh | store.sh | place.sh | project.sh | whole | |---|---|---|---|---|---|---| | `make check`, before (one after another) | 9 | 41 | 509 | 148 | 100 | 847 | | `make check JOBS=1`, now | 10 | 43 | 500 | 151 | 106 | 815 | | `make check`, now (JOBS=6) | 10 | 49 | 271 | 178 | 116 | 276 | | `make cover`, now (JOBS=6) | 1 | 8 | 77 | 74 | 19 | 83 | `make gate`, now: 1870 s (about 31 minutes, at load about 33): the gcc check 467 s, `make all` 842 s, the no-user check 278 s, the umask check 284 s. Before, the same four runs took about 80 minutes by hand. `test/store.sh` spent about two thirds of its time in the two fault sweeps (`sweep behind` and `sweep forked`: eight faults, forty syncs each) and a tenth in the clone fault loop. With `TEST_JOBS` above 1 each fault runs in its own subshell on its own copy of the scenario. A worker builds its remote and its machines under a private folder of the same depth and name length as `$RT`: copying a machine and rewriting its remote address is not the same test, because the machine's repository records the remote's path, and coverage of the merge steps in `src/store.c` fell when that was tried. The suite ends after about 270 s now: the rest of its time is the sections that run one after another (sync, tend, lint, clone) and `place.sh` is the next longest. ## The 100% rule All of `src/` is held to 100% of functions, lines, regions and branches, as `llvm-cov` counts them. There are no exclusions: no file, line or marker is skipped. A branch that cannot be reached is not left uncovered. It becomes an `ensure` or is removed. Branches counted by `llvm-cov` include each side of every `&&`, `||` and `?:`, so each condition in a compound test needs a test that decides it. The coverage build adds `-D_FORTIFY_SOURCE=0`, because the macOS SDK's checked `snprintf` macro contains a branch that is never taken by construction. ### ensure `ensure(cond)` is for invariants that cannot fail: it reports `cond`, file and line on stderr and aborts. It is on in the release, sanitizer and Fil-C builds. In the coverage build alone it compiles to nothing, so the impossible side is not counted as a branch. `cond` must have no side effects. Anything that can happen is not an `ensure`: bad input and a failed call are error paths, each with a test. ## Fault injection Every libc or system call that can fail goes through a wrapper in `src/platform.c`: `sys_open`, `sys_read`, `sys_write`, `sys_close`, `sys_fsync`, `sys_stat`, `sys_fstatat`, `sys_rename`, `sys_mkdir`, `sys_unlink`, `sys_getenv`, `sys_spawn`, `sys_execv`, `sys_wait4`, `sys_now_ns` and `platform_self_path`. A wrapper returns what the libc call returns and sets `errno` the same way. Output goes through `say` and `Out`, which are built on `sys_write`. In a build with `-DSUIT_TEST`, the environment variable SUIT_FAULT=NAME:N[:ERRNO|short|delay|hang][,NAME:N...] makes the Nth call to the wrapper NAME fail. Up to four faults can be listed, separated by commas. The names are `open`, `read`, `write`, `close`, `fsync`, `stat`, `fstatat`, `rename`, `mkdir`, `unlink`, `getenv`, `spawn`, `wait4`, `clock_gettime`, `self_path`, `getcwd` and `exec`, and for https `socket`, `connect`, `poll`, `getsockopt`, `fcntl`, `recv`, `send`, `socketpair`, `fork`, `signal`, `getaddrinfo`, `entropy` and `setrlimit`. N counts from 1, and only that one call fails. `hang` makes that call sleep 10 minutes and then fail: it is how `test/https.sh` shows the name lookup's time limit holds (the child that hangs is killed by then). `delay` is different: every call to NAME from the Nth on first waits 20 ms, which is how the tests widen the window between a temporary file's write and its rename. ERRNO is a name (`EIO ENOSPC EACCES ENOENT ENOTDIR EEXIST EINTR EPERM ENOMEM EMFILE EAGAIN EINPROGRESS ECONNREFUSED`) or a positive number; the default is `EIO`. `short` applies to `read`, `write`, `recv` and `send` only: the call transfers between 1 and 4 bytes instead of failing. `getenv` returns null, `spawn` returns the error number, and the others return -1 or false. A malformed `SUIT_FAULT` exits with status 99 and says why. The release build contains none of this. The variable name and the name table are compiled out, and `test/release_clean.sh` checks the binary. Two things are deliberately not reported: a failed write to stderr (there is nowhere left to say so) and a failed `close` of a descriptor that was only read. ## Tests - `test/unit.c`: the parser through its API, the limits, and each wrapper failing, run in a child process with `SUIT_FAULT` set. - `test/run.sh`: the command line, every strict error with its line number, the stamp format and exit codes, the no-write assertion, the bench, and a fault case for each failure branch. - `test/replay.c`: replays fuzz seeds and saved corpus files through either fuzz target without libFuzzer, so `check`, `cover` and Fil-C can use them. `--mutate N` runs N fixed-seed mutations. - `test/https.sh`: sync, clone and tend over https against local servers only: stock fossil serving TLS and `test/badsrv.c`, a BearSSL server that misbehaves on purpose, each under `test/deadline.c`'s watchdog (dead within 15 minutes even if the suite dies). Certificates are made at test time by `test/https_certs.sh`; no private key is kept. Without fossil, openssl or nc it prints `skip` lines. The test build reads `SUIT_CA_BUNDLE` in place of the system's bundles, `SUIT_NET_TIMEOUT` and `SUIT_NET_DEADLINE` in place of the 30-second and 10-minute limits, and `SUIT_UID` in place of the user's id, so a file of the test's own counts as another user's. `test/release_clean.sh` checks that none of these names, nor `SUIT_NOW`, is in the release binary. - Fuzz targets: `test/fuzz_anchors.c` (the certificate bundle reader, any bytes as a PEM file), `test/fuzz_conf.c` (config parser), `test/fuzz_stamp.c` (stamp reader) and `test/fuzz_ledger.c` (ledger parser: whatever parses must write back out and parse again to the same entries). Seeds are in `test/corpus/`. - `test/place.sh`: the User scope end to end in a scratch HOME and SUIT_HOME: `plan`, `apply`, `status`, `off` and `run`, clashes, the lock, and a reader that must never see a link missing while it is replaced. - `test/project.sh`: finding projects, and the Project personal scope in scratch projects: links, the exclude block, clashes, machine limits, joined instructions, every refusal, the stamp, and a sweep that fails each write in turn and checks that `suit off` still puts every project back as it was. - `test/usage.sh`: the usage commands and files ([usage.md](usage.md)): a scan then a report on a small tree of made-up session files, repeats across a resumed session, appended bytes, a replaced and a removed file, the 45-day rule, two harnesses, the project of a folder, windows and filters, `--tsv`, the 400-day drop, the limits (lowered through `SUIT_USAGE_LIMITS`), `tend` running the scan, and a sweep that fails each system call in turn and checks that `events` and `offsets` are whole and a repeated scan ends where an unbroken one does. Fuzz target `test/fuzz_usage.c`, seeds in `test/corpus/usage`. - `test/curate.sh`: `suit curate` ([curate.md](curate.md)) on a fixture of two wardrobes: the page and its mode, that nothing else on disk changes, each field of the data, the arguments, the bounds (lowered through `SUIT_CURATE_LIMITS`, and 4097 real assets), and a sweep that fails each system call in turn. It runs `test/curate_page.js`, the page's script against a stub of the document, when `node` is on PATH, and otherwise prints a line that starts with `skip `, which `make quick` and `make gate` repeat. Fuzz target `test/fuzz_curate.c`, seeds in `test/corpus/curate`. - `test/curate_apply.sh`: `suit curate apply` ([curate.md](curate.md)) in scratch homes whose wardrobes are real repositories (the fixture of `store.sh` checked in with `suit commit`): the choices file, every choice for every starting state and kind, the outfits and wears made, reused and found in the other wardrobe, `*` and `include`, the exact diff of each config and the exact plan, CR LF, no final newline, the limits of a line and of the set, every refusal, the check-ins and a failing second one, the stamp and the next `suit run`, the page afterwards, and sweeps that fail each system call in turn. Unit checks of the parser, the SLUG rule and the line editor are in `test/unit.c`. Fuzz target `test/fuzz_choices.c` (the choices parser, the outfit name and the line editor on a config that parses), seeds in `test/corpus/choices`. - `test/live.sh` (`make live`): real harnesses through the local proxy. Not part of `make all` or `make ci`, because it needs the proxy and spends model calls. See [harnesses.md](harnesses.md). ## The store `src/store.c` runs every command as a list of steps. A step is one libfossil call or one small decision, and one function, `run`, decides what a failed step looks like: it prints the step's name and libfossil's own message. That is how every libfossil call has an error path with a message and a test without a branch per call. The libfossil failures that tests can cause (a corrupt or empty repository file, a read-only folder, a failed write by suit's file writer) are caused for real. `src/store_fs.c` is suit's file writer: libfossil writes through it, and each file goes to a temporary name beside it, is synced and is renamed over the file. `test/store.sh` runs on `test/fixtures/wardrobe.fossil`, a fixture remade by `test/make_fixture.sh`, so it needs no stock fossil. Where stock fossil is installed it also compares the store with `fossil open`'s checkout on a 600-file wardrobe, and checks that stock fossil reads suit's check-ins. A machine without it skips those cases and says so. Repair. Before an update changes anything it writes `$SUIT_HOME/NAME.journal` (the version it is leaving and the one it is going to, written beside and renamed). The update removes it when it finishes, or when its put-back finishes. While it exists every command but `suit store repair` refuses with exit 15. Repair puts every file back to the version the journal names, or, with no journal, to the version the working copy records, and refuses with exit 12 (listing the files) if that would throw away edits. A file an interrupted update had added and the old version does not have stays as an untracked file. Symlinks are refused (exit 16, naming the path): `open` and `update` refuse a wardrobe version that holds one, and `commit` refuses to check in a symlink in the store. libfossil's checkout writes a link as a regular file. See docs/evidence.md, "Phase 2". Out of memory is not handled: `fsl_cx_init` failing is an `ensure`. ## Vendored code SQLite, libfossil, zlib and BearSSL are in `vendor/` (see `vendor/README.md`: origin, version and SHA-256 of every file, "replace to update, never edit"). They are outside the 100% rule and the warning set and compile with `-w`. They are built and run under ASan, UBSan and Fil-C along with everything else, and suit's own code that calls them stays inside the rule. zlib is compiled in, so nothing links `-lz`, and Fil-C needs no separate zlib. BearSSL is built into `build/VARIANT/vendor/libbearssl.a` with its own system calls turned off (`BR_RDRAND=0 BR_USE_URANDOM=0 BR_USE_UNIX_TIME=0`), so its randomness and its clock come from suit's wrappers; under Fil-C also without its x86 intrinsics (`BR_AES_X86NI=0 BR_SSE2=0`). The fuzz targets and the replay programs link it too, since the certificate bundle reader is in the core. ## What "no known flaws" means Passing every gate is what "no known flaws" means here, and nothing more. The gates cannot show that an untested input is handled, that the fuzzers would find a bug given more time, or that the Linux build behaves like the macOS one when only macOS ran. A flaw found later is a missing test: add the test that fails, fix it, and the gates keep it fixed.