merge: third-party licence notices, generated, checked and printed by the program (checked, small rework)

Every MIT, Apache, BSD and ISC crate and every bundled font asks that its
notice travel with a copy of the binary. THIRD-PARTY-NOTICES.txt is
generated from the lock file (cargo-about) and the font licences, compiled
into the program and printed by `wanderbooks licenses`; the lint part of
`just check` fails when it is out of date.

Checked before merging: the accepted list equals deny.toml's; two runs are
byte-identical; the check exits 1 on a changed file and 0 after
regenerating; no path or user name in the text; the three ledger-cli test
files pass (licenses 4, hostile_args 6, one_executable 9); fmt and clippy
clean.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude committed 2026-11-09 21:46:23 -07:00
commit 9d1cb28f22
10 files changed
+12660 -11

No files matched your search

File diff suppressed because it is too large. Load diff
+43
View File
@@ -0,0 +1,43 @@
# What cargo-about may report when it writes THIRD-PARTY-NOTICES.txt
# (`just notices`). The accepted list is deny.toml's `allow` list, word for
# word: the gate and the notices describe the same set of licences. A
# licence that is not here is not in the program either; if cargo-about
# meets one, fix the dependency, never this list.
accepted = [
"MIT",
"MIT-0",
"Apache-2.0",
"Apache-2.0 WITH LLVM-exception",
"BSD-2-Clause",
"BSD-3-Clause",
"ISC",
"Zlib",
"0BSD",
"BSL-1.0",
"CC0-1.0",
"Unlicense",
"Unicode-3.0",
"bzip2-1.0.6",
"MPL-2.0",
"CDLA-Permissive-2.0",
]
# Every platform the program ships on. The list is fixed rather than the
# build machine's, so the notices name the same dependencies everywhere.
targets = [
"x86_64-unknown-linux-gnu",
"aarch64-unknown-linux-gnu",
"x86_64-apple-darwin",
"aarch64-apple-darwin",
"x86_64-pc-windows-msvc",
]
# Only what the binary links: a build script's dependencies and the tests'
# are not shipped, so their licences have no notice to travel with.
ignore-build-dependencies = true
ignore-dev-dependencies = true
# The workspace's own crates are `publish = false`: they are the program,
# not third parties, and the program's own licence is stated at the top of
# the notices.
private = { ignore = true }
+51 -10
View File
@@ -11,8 +11,14 @@
//! agent).
use std::env;
use std::io::Write;
use std::path::PathBuf;
/// Every third-party licence the program must travel with, built into it
/// by the build (`just notices`; scripts/notices.sh). `wanderbooks
/// licenses` prints it.
const NOTICES: &str = include_str!("../../../THIRD-PARTY-NOTICES.txt");
fn print_usage() {
eprintln!("usage: wanderbooks setup [--root PATH] [--home DIR]");
eprintln!(" wanderbooks gui [BOOK | --root PATH --book ID]");
@@ -29,6 +35,7 @@ fn print_usage() {
eprintln!(" wanderbooks download --book ID [--token NAME] ATTACHMENT --to FOLDER");
eprintln!(" wanderbooks serve | close | doctor");
eprintln!(" wanderbooks update [--check] | rollback");
eprintln!(" wanderbooks licenses");
eprintln!();
eprintln!(" setup make the books' private folder (only your account can open it)");
eprintln!(" gui open the live, read-only view of the books (a book of the data root)");
@@ -45,6 +52,7 @@ fn print_usage() {
eprintln!(" close close the books now: everything holding them lets go");
eprintln!(" doctor whether the books are open, what holds them, what went wrong");
eprintln!(" update bring this program to the newest release (`rollback` goes back)");
eprintln!(" licenses the licences of the libraries and fonts this program includes");
}
/// The viewer's arguments for `wanderbooks gui ARGS` (plan 3.6): a lone
@@ -381,6 +389,25 @@ fn run_server(args: Vec<String>) -> i32 {
}
}
/// `wanderbooks licenses`: the third-party notices compiled into the
/// program. It opens no books and reads no file: what it prints is part of
/// this binary. A pipe that closes early (`| head`) is how the reader
/// finished, not an error, so a write error is ignored.
fn run_licenses(args: Vec<String>) -> i32 {
if !args.is_empty() {
eprintln!("usage: wanderbooks licenses");
return 2;
}
let mut out = std::io::stdout().lock();
let header = format!(
"wanderbooks {} is licensed under MIT OR Apache-2.0.\n\n",
env!("CARGO_PKG_VERSION")
);
let _ = out.write_all(header.as_bytes());
let _ = out.write_all(NOTICES.as_bytes());
0
}
/// The modes that open and hold the books (plan 3.9): the host, the
/// agents' bridge, and the owner's commands.
fn run_local(mode: &str, args: Vec<String>) -> i32 {
@@ -478,6 +505,7 @@ fn main() {
Some("gui") => std::process::exit(run_gui(all.collect())),
Some("setup") => std::process::exit(run_setup(all.collect())),
Some("server") => std::process::exit(run_server(all.collect())),
Some("licenses") => std::process::exit(run_licenses(all.collect())),
Some(
mode @ ("host" | "mcp" | "serve" | "close" | "books" | "doctor" | "token" | "connect"
| "passphrase" | "update" | "rollback"),
@@ -499,16 +527,29 @@ fn main() {
std::process::exit(2);
}
// A mode named after a flag: it must come first.
match words
.iter()
.map(String::as_str)
.find(|w| !w.starts_with('-'))
{
Some(
mode @ ("gui" | "setup" | "server" | "host" | "mcp" | "serve" | "connect" | "close"
| "books" | "doctor" | "token" | "passphrase" | "update" | "rollback"
| "upload" | "download"),
) => {
match words.iter().map(String::as_str).find(|w| {
matches!(
*w,
"gui"
| "setup"
| "server"
| "host"
| "mcp"
| "serve"
| "connect"
| "close"
| "books"
| "doctor"
| "token"
| "passphrase"
| "update"
| "rollback"
| "upload"
| "download"
| "licenses"
)
}) {
Some(mode) => {
eprintln!("`{mode}` must come first: wanderbooks {mode} [its own flags]");
std::process::exit(2);
}
+75
View File
@@ -0,0 +1,75 @@
//! `wanderbooks licenses`: the third-party notices are part of the binary
//! and print as plain text, and the mode behaves like every other one.
use std::process::Command;
fn wanderbooks() -> Command {
Command::new(env!("CARGO_BIN_EXE_wanderbooks"))
}
#[test]
fn licenses_prints_the_notices_and_nothing_on_stderr() {
let out = wanderbooks().arg("licenses").output().unwrap();
assert_eq!(out.status.code(), Some(0), "{out:?}");
assert!(
out.stderr.is_empty(),
"{:?}",
String::from_utf8_lossy(&out.stderr)
);
let text = String::from_utf8(out.stdout).unwrap();
assert!(
text.starts_with("wanderbooks "),
"the version line comes first: {:?}",
&text[..text.len().min(80)]
);
for needle in [
"MIT OR Apache-2.0",
"Apache License",
"SIL OPEN FONT LICENSE",
"rust_decimal",
"egui",
"rusqlite",
"Inter Project Authors",
"Bitstream",
] {
assert!(text.contains(needle), "{needle:?} is not in the notices");
}
}
#[test]
fn the_printed_notices_are_the_file_at_the_repository_root() {
let notices = include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../THIRD-PARTY-NOTICES.txt"
));
let out = wanderbooks().arg("licenses").output().unwrap();
let done = out
.stdout
.windows(2)
.position(|w| w == b"\n\n")
.expect("the header line and an empty line");
assert_eq!(&out.stdout[done + 2..], notices);
}
#[test]
fn licenses_takes_no_arguments() {
let out = wanderbooks().args(["licenses", "extra"]).output().unwrap();
assert_eq!(out.status.code(), Some(2), "{out:?}");
assert!(
String::from_utf8_lossy(&out.stderr).contains("usage: wanderbooks licenses"),
"{out:?}"
);
}
#[test]
fn licenses_comes_first_like_every_mode() {
let out = wanderbooks()
.args(["--root", "x", "licenses"])
.output()
.unwrap();
assert_eq!(out.status.code(), Some(2), "{out:?}");
assert!(
String::from_utf8_lossy(&out.stderr).contains("must come first"),
"{out:?}"
);
}
+25
View File
@@ -0,0 +1,25 @@
{{! Plain-text notices for the third-party crates the program links
(`just notices`). The `text` field is licence text, not HTML: triple
braces keep it as it is. }}
THIRD-PARTY NOTICES
wanderbooks is licensed under MIT OR Apache-2.0. It is built with the
third-party Rust crates named below, each under the licence named in its
section, and each licence's text follows. The fonts the program embeds are
listed at the end of this file, under FONTS, each with its licence. A
build-time or development-only dependency is not part of the program as
shipped and is not listed here.
{{#each licenses}}
================================================================================
{{{name}}}
================================================================================
Used by:
{{#each used_by}}
{{crate.name}} {{crate.version}}
{{/each}}
{{{text}}}
{{/each}}
+1 -1
View File
@@ -38,7 +38,7 @@ the specification in `bookspec/` (which never depends on the engine).
| `ledger-mcp` | the books server: the MCP tools (122), resources, the handbook, scopes, the door and the access log, backups' scheduling | all of the above |
| `ledger-host` | the host and its leases, the agent bridge (`wanderbooks mcp`), tokens in 0600 files under the data root (D-63), the owner's commands, uploads and downloads, `update` and `rollback` (P11a), books homes and how to start an agent in one (P11b) | `ledger-store`, `ledger-mcp`, `ledger-config` |
| `ledger-gui` | the viewer: read-only, live, egui; the Books menu hands work to the server; the agent dock and the first-run page (P11b) | `ledger-core`, `ledger-store`, `ledger-config`, `ledger-import`, `ledger-package`, `ledger-vault`, `ledger-host` |
| `ledger-cli` | `wanderbooks`, the one executable: every mode (`serve`, `server`, `host`, `mcp`, `gui`, `setup`, `books`, `token`, `connect`, `doctor`, …) and the over-the-wire test suites | everything |
| `ledger-cli` | `wanderbooks`, the one executable: every mode (`serve`, `server`, `host`, `mcp`, `gui`, `setup`, `books`, `token`, `connect`, `doctor`, `licenses`, …) and the over-the-wire test suites | everything |
| `bookspec/checker`, `bookspec/runner` | the example schema and parser, the rule catalogue, the `Engine` trait; the per-rule runner | nothing of ours (the adapter in `ledger-core`'s tests depends on them) |
Dependency direction is always inward toward `ledger-core`; nothing in
+1
View File
@@ -29,6 +29,7 @@ promise.
| Miri | undefined behavior in our use of dependencies (4) | the core's unit, bridge, invariant tests (the exhaustive calendar walk aside) | `just miri` | ~4 min | on demand |
| Golden | `tests/golden/fixture_company.json` (5) | `invariants.rs` | `just check` | <1s | every change |
| Dependencies | no crate in the lock file with a known vulnerability (RustSec) or yanked; none under a licence that does not fit MIT OR Apache-2.0; none from a source `deny.toml` does not name; none of our own unmaintained (4) | `deny.toml`, each exception with its reason and date | `just deny` (in `just check`, the lint part) | seconds, needs the network | every change, and weekly (`scheduled.yml`), since an advisory is published when it is, not when we push. First run, 2026-11-09: 23 advisories; closed by upgrades (quick-xml, rusqlite, rust_xlsxwriter, rmcp, rustls, tokio, zstd, pulldown-cmark) but two, lived with in `deny.toml` |
| Notices | every crate the program links and every font it embeds, with the licence text each asks to travel with (1, the licence itself) | `THIRD-PARTY-NOTICES.txt`, written by cargo-about from `ledger-cli`'s manifest and from the licence files beside the fonts | `just notices`; `just notices-check` (in `just check`, the lint part) | ~2 min (12 CPU-minutes: it reads every crate's files for licence text) | every change that touches a dependency or a font. `just notices` writes the file; `just notices-check` fails when a dependency changed and the file was not regenerated, and the fix is `just notices` and committing the result |
| Benchmarks | a baseline (6) | `ledger-core/benches/books.rs`, `ledger-store/benches/store.rs` | `just bench` | ~2 min | none (no budget, by decision) |
| Coverage | the code lines, regions and branches the suites execute (6) | `ledger-core` and `ledger-store` library sources (`src/proofs.rs` is Kani-only and excluded, as are test and bench files) | `just coverage` (HTML and a per-file table in `target/coverage/`), `just coverage-check` (docs/coverage-floor.md's floor, 0.5 pp tolerance) | ~1–3 h (nightly branch coverage) | weekly (`scheduled.yml`) |
| Mutation | can the tests fail? | `ledger-core` (2026-10-13: 1,011 caught + 13 timeouts of 1,024 viable, 0 missed) | `just mutants` | ~3 h | weekly |
+13
View File
@@ -39,6 +39,7 @@ check-shard shard:
just server-only
just check-shards-agree
just deny
just notices-check
;;
# The viewer's tests are half of the suite's time, in two halves
# of their own: its unit tests, and its integration tests. Between
@@ -66,6 +67,18 @@ check-shard shard:
deny:
cargo deny check
# The third-party notices every licence asks to travel with
# (THIRD-PARTY-NOTICES.txt): each crate the `wanderbooks` binary links and
# its licence text, then the fonts embedded, each with its licence. Writes
# the file; commit it.
notices:
scripts/notices.sh
# Whether THIRD-PARTY-NOTICES.txt still matches the dependencies: a crate
# added, removed or upgraded without regenerating it fails (`just notices`).
notices-check:
scripts/notices.sh --check
# CI's list of parts is this file's: a part CI never runs is a check
# nobody makes, and a part only CI names fails there, not here.
check-shards-agree:
+3
View File
@@ -30,6 +30,9 @@ node = "26"
# none yanked, none under a licence that does not fit MIT OR Apache-2.0,
# none from a source nobody named (deny.toml).
cargo-deny = "0.20.2"
# `just notices`: cargo-about reads every crate the program links and the
# licence it carries, to write THIRD-PARTY-NOTICES.txt.
"cargo:cargo-about" = { version = "0.9.3", features = ["cli"] }
# A compile cache shared by every jj workspace's target dir: point
# cargo's build.rustc-wrapper at it (~/.cargo/config.toml).
sccache = "0.18.0"
+165
View File
@@ -0,0 +1,165 @@
#!/usr/bin/env bash
# The third-party notices the program must travel with (MIT, Apache-2.0,
# BSD, ISC, Zlib, SIL OFL 1.1 and the rest all ask that their copyright
# notice and licence text go with every copy).
#
# scripts/notices.sh write THIRD-PARTY-NOTICES.txt
# scripts/notices.sh --check fail if it is out of date (`just notices-check`)
#
# The file has two parts. The first is cargo-about's: every crate the
# `wanderbooks` binary links, with the licence it carries and that
# licence's text. cargo-about reads the manifest of `ledger-cli` (the one
# executable), every feature and every platform the program ships on, so
# the list is what the program contains, not what this machine happens to
# build. The second part is the fonts the program embeds: each file under
# `crates/ledger-gui/assets/fonts/` and `crates/ledger-import/fonts/`,
# with the licence file beside it. A font file that no entry below names
# fails the script, so a new font cannot ship without its notice.
#
# The output is plain text, says nothing about this machine (no dates, no
# absolute paths), and is the same on two runs; `--check` compares it with
# the committed file byte for byte, so a changed dependency shows up as a
# red `just check` until the file is regenerated and committed.
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
out=THIRD-PARTY-NOTICES.txt
case "${1:-}" in
"" | --check) ;;
*)
echo "usage: scripts/notices.sh [--check]" >&2
exit 2
;;
esac
check=${1:-}
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
# Which licence each bundled font carries. Every `*.ttf` and `*.otf`
# under the two font folders must match one pattern here; a new font is
# added here beside its licence file, never left out of the notices.
font_map=(
"crates/ledger-gui/assets/fonts/InterTab-*.ttf|crates/ledger-gui/assets/fonts/Inter-LICENSE.txt"
"crates/ledger-gui/assets/fonts/Hack-Regular.ttf|crates/ledger-gui/assets/fonts/Hack-LICENSE.txt"
"crates/ledger-gui/assets/fonts/NotoEmoji-Regular.ttf|crates/ledger-gui/assets/fonts/NotoEmoji-LICENSE.txt"
"crates/ledger-gui/assets/fonts/emoji-icon-font.ttf|crates/ledger-gui/assets/fonts/emoji-icon-font-LICENSE.txt"
# The PDFs' Inter is the same font and licence as the viewer's.
"crates/ledger-import/fonts/Inter-*.ttf|crates/ledger-gui/assets/fonts/Inter-LICENSE.txt"
"crates/ledger-import/fonts/NotoSans*-Regular.ttf|crates/ledger-import/fonts/NotoSans-LICENSE.txt"
"crates/ledger-import/fonts/NotoSansCJKsc-*.otf|crates/ledger-import/fonts/NotoSansCJK-LICENSE.txt"
)
# font -> licence, filled from font_map below.
declare -A font_licence=()
for entry in "${font_map[@]}"; do
pattern=${entry%%|*}
licence=${entry#*|}
matched=0
for file in $pattern; do
[ -f "$file" ] || continue
font_licence["$file"]=$licence
matched=1
done
if [ "$matched" -eq 0 ]; then
echo "notices: no font matches $pattern (the map in scripts/notices.sh is stale)" >&2
exit 2
fi
done
# Every font file must be accounted for: a font that no entry names has
# no notice to travel with.
fonts=$(find crates/ledger-gui/assets/fonts crates/ledger-import/fonts \
-type f \( -name '*.ttf' -o -name '*.otf' \) | sort)
for font in $fonts; do
if [ -z "${font_licence[$font]:-}" ]; then
echo "notices: no licence for $font: add it to the map in scripts/notices.sh" >&2
exit 1
fi
done
# The fonts section, grouped by licence file: every font that carries a
# licence is listed, then that licence's text once.
font_section() {
echo "================================================================================"
echo "FONTS"
echo "================================================================================"
echo
echo "The program embeds the fonts below. Each font file is listed under"
echo "the licence it carries, and that licence's text follows."
echo
local seen=() entry licence font found seen_licence
for entry in "${font_map[@]}"; do
licence=${entry#*|}
found=0
for seen_licence in ${seen[@]+"${seen[@]}"}; do
[ "$seen_licence" = "$licence" ] && found=1
done
[ "$found" -eq 0 ] || continue
seen+=("$licence")
if [ ! -f "$licence" ]; then
echo "notices: no licence file $licence" >&2
exit 1
fi
echo "--------------------------------------------------------------------------------"
echo "$licence"
echo "--------------------------------------------------------------------------------"
echo
echo "Fonts:"
while IFS= read -r font; do
[ -n "$font" ] || continue
[ "${font_licence[$font]:-}" = "$licence" ] || continue
echo " $font"
done <<<"$fonts"
echo
cat "$licence"
echo
done
}
# One full copy of the notices, in $1.
write_notices() {
local target=$1
command -v cargo >/dev/null || {
echo "notices: cargo is not installed (mise install)" >&2
exit 2
}
# --offline: cargo-about reads only the crates' own packaged files.
# Without it, a crate packaged without its licence file is looked up
# in its git repository, so the file could change with no change
# here. The cost: such a crate gets the licence's standard text,
# without the copyright line its repository holds. The manifest is
# ledger-cli's, the one executable: that dependency graph is what the
# binary links.
if ! cargo about generate --locked --all-features --offline \
-m crates/ledger-cli/Cargo.toml -c about.toml \
deploy/notices/about.hbs > "$work/about.txt"; then
echo "notices: cargo-about failed. It reads every crate in Cargo.lock from the local" >&2
echo "registry, every platform's included: if one is missing, run \`cargo fetch --locked\` first." >&2
exit 2
fi
{
cat "$work/about.txt"
echo
font_section
} > "$work/all.txt"
# Plain text: trailing whitespace off every line, and exactly one
# newline at the end (the licence files and cargo-about differ).
sed 's/[[:space:]]*$//' "$work/all.txt" > "$work/clean.txt"
printf '%s\n' "$(cat "$work/clean.txt")" > "$target"
}
if [ "$check" = --check ]; then
write_notices "$work/check.txt"
if ! cmp -s "$work/check.txt" "$out"; then
diff -u "$out" "$work/check.txt" | head -40 >&2 || true
echo 'THIRD-PARTY-NOTICES.txt is out of date: run `just notices` and commit the result' >&2
exit 1
fi
echo "notices: $out is up to date"
else
write_notices "$out"
echo "notices: wrote $out"
fi