From 9baf71b2a56671f863f903fb203bde8ff1620bd9 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 21:17:56 -0700 Subject: [PATCH] feat(cli): wanderbooks licenses prints the notices compiled into the program The notices must reach the person holding the binary, not only the repository: THIRD-PARTY-NOTICES.txt is compiled in with include_str!, so `wanderbooks licenses` prints the program's version line and then every crate's and font's licence without opening books or reading a file. A closed pipe (`| head`) is ignored, not a panic. Tests check the version line, the notices required in the output, that the bytes after the header are exactly the repository's file, and that the mode takes no arguments and must come first like every other. Docs: the testing table says what `just notices` writes and how `notices-check` fails on a stale file; the architecture's list of modes names licenses. Co-Authored-By: DeepSeek V4.1 Flash --- crates/ledger-cli/src/main.rs | 61 +++++++++++++++++++---- crates/ledger-cli/tests/licenses.rs | 75 +++++++++++++++++++++++++++++ docs/architecture.md | 2 +- docs/testing.md | 1 + 4 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 crates/ledger-cli/tests/licenses.rs diff --git a/crates/ledger-cli/src/main.rs b/crates/ledger-cli/src/main.rs index 2194fafc..42aab5b1 100644 --- a/crates/ledger-cli/src/main.rs +++ b/crates/ledger-cli/src/main.rs @@ -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) -> 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) -> 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) -> 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); } diff --git a/crates/ledger-cli/tests/licenses.rs b/crates/ledger-cli/tests/licenses.rs new file mode 100644 index 00000000..9158cd2c --- /dev/null +++ b/crates/ledger-cli/tests/licenses.rs @@ -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:?}" + ); +} diff --git a/docs/architecture.md b/docs/architecture.md index ea787df2..b9994dd3 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -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 diff --git a/docs/testing.md b/docs/testing.md index 4aa7526a..8812e400 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -28,6 +28,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) | seconds | 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 |