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

+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:?}"
);
}