Merge branch 't3/p15-c1-desktop-packages': packages for Windows, macOS and Linux, and the Claude desktop extension (P15 C1)

The two Connect page baselines are re-blessed on the merged code: the
page gained the extension row here and the stopped test clock on main.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 15:57:46 -07:00
commit 813042a7a6
53 files changed
+3875 -276

No files matched your search

+10
View File
@@ -24,6 +24,11 @@ ledger-mcp = { path = "../ledger-mcp" }
ledger-store = { path = "../ledger-store" }
ledger-gui = { path = "../ledger-gui", optional = true }
# The parent's console for a command run in a terminal (console.rs): the
# raw bindings, already in the lockfile through ledger-store.
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Console"] }
[dev-dependencies]
base64 = "0.22"
chrono = "0.4"
@@ -70,6 +75,8 @@ workspace = true
# program: `just package-linux`. Paths are relative to the workspace root.
[package.metadata.generate-rpm]
name = "wanderbooks"
# Backups run the system's git (WB-pkg-4): dnf fetches it.
requires = { git = "*" }
summary = "Double-entry bookkeeping your agent keeps and you can read"
license = "MIT OR Apache-2.0"
url = "https://wanderbooks.ai"
@@ -77,5 +84,8 @@ assets = [
{ source = "target/release/wanderbooks", dest = "/usr/bin/wanderbooks", mode = "0755" },
{ source = "deploy/packaging/install-method-rpm", dest = "/usr/share/wanderbooks/install-method", mode = "0644" },
{ source = "deploy/packaging/wanderbooks-static.desktop", dest = "/usr/share/applications/wanderbooks.desktop", mode = "0644" },
{ source = "deploy/packaging/icons/512x512.png", dest = "/usr/share/icons/hicolor/512x512/apps/wanderbooks.png", mode = "0644" },
{ source = "LICENSE-MIT", dest = "/usr/share/doc/wanderbooks/LICENSE-MIT", mode = "0644" },
{ source = "LICENSE-APACHE", dest = "/usr/share/doc/wanderbooks/LICENSE-APACHE", mode = "0644" },
{ source = "THIRD-PARTY-NOTICES.txt", dest = "/usr/share/doc/wanderbooks/THIRD-PARTY-NOTICES.txt", mode = "0644" },
]
+85
View File
@@ -0,0 +1,85 @@
//! The program's console on Windows (plan P15 unit C1, WB-pkg-2).
//!
//! The installed program is one executable that is the window, the books
//! server child and the assistants' bridge. Built for the Windows GUI
//! subsystem (`windows_subsystem = "windows"` in `main.rs`), a double-click
//! or a Start Menu entry opens no console window. The same file still has
//! to be a command line: a person who types `wanderbooks books list` in a
//! terminal needs the words printed there, and an assistant that starts
//! `wanderbooks mcp --book X` hands it pipes, which a GUI-subsystem
//! program receives as they are.
//!
//! ```text
//! GOAL: no console window when the program starts as an app; its words
//! reach the terminal that started it as a command; a pipe handed to
//! it is never replaced.
//! SOURCE: WB-pkg-2 (one executable); Microsoft's documentation of
//! AttachConsole(ATTACH_PARENT_PROCESS) and SetStdHandle.
//! INVARIANTS:
//! 1. A standard handle the parent gave (a pipe, a file) is left as it
//! is; only a missing one (null or invalid) is pointed at the
//! parent's console (CONIN$ for input, CONOUT$ for output and
//! errors).
//! 2. With no parent console (a Start Menu launch, an assistant that
//! gave pipes and has no console) nothing is attached and nothing is
//! opened: the program never makes a console window of its own.
//! SCENARIOS:
//! 1. IF an assistant starts `mcp` with three pipes: SHOULD speak over
//! them, unchanged.
//! 2. IF a terminal starts `books list`: SHOULD print into the terminal.
//! 3. IF the Start Menu starts it with no words: SHOULD open the window
//! and no console.
//! ```
//!
//! Not run on Windows by the author (the unit was written on Linux); the
//! `release` workflow's Windows job builds it, and the first install is
//! the evidence for the scenarios.
/// Point the missing standard handles at the parent's console, if there
/// is one (INVARIANTS 1 and 2). A no-op everywhere but Windows.
#[cfg(windows)]
pub fn attach_parent_console() {
use std::os::windows::io::IntoRawHandle;
use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;
use windows_sys::Win32::System::Console::{
ATTACH_PARENT_PROCESS, AttachConsole, GetStdHandle, STD_ERROR_HANDLE, STD_INPUT_HANDLE,
STD_OUTPUT_HANDLE, SetStdHandle,
};
// SAFETY: plain Win32 calls with no pointers of ours; a failure is a
// value, and the handles opened below are given to the process, which
// keeps them open for its life.
unsafe {
let missing = |id| {
let handle = GetStdHandle(id);
handle.is_null() || handle == INVALID_HANDLE_VALUE
};
let wanted = [
(STD_INPUT_HANDLE, "CONIN$", true),
(STD_OUTPUT_HANDLE, "CONOUT$", false),
(STD_ERROR_HANDLE, "CONOUT$", false),
];
if !wanted.iter().any(|(id, _, _)| missing(*id)) {
return;
}
if AttachConsole(ATTACH_PARENT_PROCESS) == 0 {
return;
}
for (id, device, input) in wanted {
if !missing(id) {
continue;
}
let opened = std::fs::OpenOptions::new()
.read(input)
.write(!input)
.open(device);
if let Ok(file) = opened {
SetStdHandle(id, file.into_raw_handle());
}
}
}
}
/// Nothing to do where a program is a console program already.
#[cfg(not(windows))]
pub fn attach_parent_console() {}
+34 -2
View File
@@ -9,6 +9,13 @@
//! From nothing to the first post: `wanderbooks setup`, `wanderbooks books
//! create ID`, `wanderbooks connect claude --book ID` (then talk to the
//! agent).
//!
//! On Windows the executable is built for the GUI subsystem, so starting
//! it from the Start Menu opens no console window; `console` gives a
//! command run in a terminal its words back (WB-pkg-2).
#![cfg_attr(all(windows, feature = "gui"), windows_subsystem = "windows")]
mod console;
use std::env;
use std::io::Write;
@@ -275,6 +282,18 @@ impl ledger_gui::owner::Owner for ViewerOwner {
)
}
fn claude_desktop_extension(
&self,
book: &str,
company: &str,
) -> Result<ledger_gui::owner::ExtensionMade, String> {
let made = ledger_host::extension::claude_desktop_extension(&self.common, book, company)?;
Ok(ledger_gui::owner::ExtensionMade {
file: made.path.display().to_string(),
folder: made.folder.display().to_string(),
})
}
fn new_books(&self, id: &str, currency: &str) -> Result<String, String> {
ledger_host::commands::new_books_and_home(&self.common, id, currency)
}
@@ -390,6 +409,15 @@ impl ledger_gui::owner::Owner for ViewerOwner {
})
}
fn newer_version(&self) -> Option<ledger_gui::owner::NewerVersion> {
ledger_host::commands::newer_version(&self.common).map(|(version, page)| {
ledger_gui::owner::NewerVersion {
version,
page: page.to_string(),
}
})
}
fn check_for_updates(&self) -> Result<Vec<String>, String> {
ledger_host::commands::check_for_updates(&self.common).map(|l| vec![l])
}
@@ -683,8 +711,7 @@ fn is_bare_launch(words: &[String], stdin_is_terminal: bool) -> bool {
}
fn main() {
#[cfg(unix)]
ledger_host::update::set_program_version(env!("CARGO_PKG_VERSION"));
ledger_host::set_program_version(env!("CARGO_PKG_VERSION"));
// A file's path may be any name the system takes: the file commands
// get the words as given. Everything else is text.
let given: Vec<std::ffi::OsString> = env::args_os().skip(1).collect();
@@ -700,6 +727,11 @@ fn main() {
eprintln!("error: an argument isn't UTF-8 text");
std::process::exit(2);
};
// A command run in a terminal prints there; the app (no words) opens
// no console at all (console.rs).
if !words.is_empty() {
console::attach_parent_console();
}
// A bare launch is the viewer.
if is_bare_launch(&words, std::io::IsTerminal::is_terminal(&std::io::stdin())) {
std::process::exit(run_gui(Vec::new()));
+144
View File
@@ -0,0 +1,144 @@
//! The Claude desktop extension the Connect page writes (plan P15 unit C1,
//! WB-pkg-5): its package is Anthropic's MCP Bundle, and its manifest is
//! checked against Anthropic's published schema for manifest version 0.3
//! (`tests/fixtures/mcpb/`, with where it came from).
//!
//! ```text
//! GOAL: a package the Claude desktop app can install, naming this
//! program's bridge for one company, with nothing secret in it.
//! SOURCE: WB-pkg-5; Anthropic's MCP Bundle manifest specification
//! (the manifest page and the version 0.3 JSON schema of its
//! mcpb repository on GitHub); the writer's own spec block in
//! the host crate.
//! INVARIANTS:
//! 1. The package is a zip whose root holds `manifest.json`; every file
//! the manifest names (`icon`, `server.entry_point`) is in the zip.
//! 2. The manifest validates against the 0.3 schema, which refuses any
//! field the specification does not define.
//! 3. The server is a `binary` whose command is the program's path and
//! whose arguments are `mcp --book <id>`.
//! SCENARIOS:
//! 1. A package made for a company with an awkward name validates.
//! 2. Every required field of the schema is present.
//! ```
use serde_json::Value;
use std::io::Read;
fn schema() -> jsonschema::Validator {
let text = include_str!("fixtures/mcpb/mcpb-manifest-v0.3.schema.json");
jsonschema::validator_for(&serde_json::from_str::<Value>(text).unwrap()).unwrap()
}
fn made(company: &str) -> (tempfile::TempDir, std::path::PathBuf) {
let dir = tempfile::tempdir().unwrap();
let bridge: Vec<std::ffi::OsString> = [
"/Applications/Wanderbooks.app/Contents/MacOS/wanderbooks",
"mcp",
"--book",
"acme",
]
.map(Into::into)
.to_vec();
let made = ledger_host::extension::write_in(dir.path(), "acme", company, "0.1.0", &bridge)
.expect("the package is written");
(dir, made.path)
}
fn read(path: &std::path::Path) -> (Value, Vec<String>) {
let mut zip = zip::ZipArchive::new(std::fs::File::open(path).unwrap()).unwrap();
let names: Vec<String> = (0..zip.len())
.map(|i| zip.by_index(i).unwrap().name().unwrap().to_string())
.collect();
let mut text = String::new();
zip.by_name("manifest.json")
.expect("manifest.json is at the root of the package")
.read_to_string(&mut text)
.unwrap();
(serde_json::from_str(&text).unwrap(), names)
}
#[test]
fn the_manifest_is_one_the_published_schema_accepts() {
for company in [
"Wanderland Labs LLC",
"Quote \" and <markup> & \u{e9}\u{4e2d}",
&"long ".repeat(100),
"",
] {
let (_dir, path) = made(company);
let (manifest, _) = read(&path);
let errors: Vec<String> = schema()
.iter_errors(&manifest)
.map(|e| format!("{e} at {}", e.instance_path()))
.collect();
assert!(errors.is_empty(), "{company:?}: {errors:?}\n{manifest:#}");
// The check is not vacuous: a field the specification lacks, or a
// missing required one, is refused.
let mut extra = manifest.clone();
extra["no_such_field"] = Value::Bool(true);
assert!(!schema().is_valid(&extra));
let mut short = manifest.clone();
short.as_object_mut().unwrap().remove("author");
assert!(!schema().is_valid(&short));
}
}
#[test]
fn every_file_the_manifest_names_is_in_the_package() {
let (_dir, path) = made("Acme");
let (manifest, names) = read(&path);
assert_eq!(manifest["manifest_version"], "0.3");
for named in [
manifest["icon"].as_str().unwrap(),
manifest["server"]["entry_point"].as_str().unwrap(),
] {
assert!(names.iter().any(|n| n == named), "{named} in {names:?}");
}
// The schema's required fields, by the schema's own list.
let schema: Value =
serde_json::from_str(include_str!("fixtures/mcpb/mcpb-manifest-v0.3.schema.json")).unwrap();
for field in schema["required"].as_array().unwrap() {
assert!(manifest.get(field.as_str().unwrap()).is_some(), "{field}");
}
for field in schema["properties"]["server"]["required"]
.as_array()
.unwrap()
{
assert!(manifest["server"].get(field.as_str().unwrap()).is_some());
}
}
#[test]
fn the_server_runs_this_programs_bridge_for_the_company() {
let (_dir, path) = made("Acme");
let (manifest, _) = read(&path);
let server = &manifest["server"];
assert_eq!(server["type"], "binary");
assert_eq!(
server["mcp_config"]["command"],
"/Applications/Wanderbooks.app/Contents/MacOS/wanderbooks"
);
assert_eq!(
server["mcp_config"]["args"],
serde_json::json!(["mcp", "--book", "acme"])
);
// The package carries no program (the one executable is the installed
// one) and no key.
let (_, names) = read(&path);
assert_eq!(names.len(), 3, "{names:?}");
assert_eq!(manifest["name"], "wanderbooks-acme");
}
/// The 512 px icon is a PNG (the manifest's `icon` is "a png icon file").
#[test]
fn the_icon_is_a_png() {
let (_dir, path) = made("Acme");
let mut zip = zip::ZipArchive::new(std::fs::File::open(path).unwrap()).unwrap();
let mut head = [0u8; 8];
zip.by_name("icon.png")
.unwrap()
.read_exact(&mut head)
.unwrap();
assert_eq!(&head, b"\x89PNG\r\n\x1a\n");
}
+10
View File
@@ -0,0 +1,10 @@
mcpb-manifest-v0.3.schema.json is Anthropic's published JSON Schema for the
manifest.json of an MCP Bundle (.mcpb, formerly the Desktop Extension .dxt),
manifest_version 0.3, copied verbatim on 2026-11-21 from
https://github.com/anthropics/mcpb (schemas/mcpb-manifest-v0.3.schema.json,
main branch). The specification's prose is MANIFEST.md in the same
repository; the install steps are Claude's help article "Getting started
with Local MCP servers on Claude Desktop" (support.claude.com).
The repository's licence: Apache-2.0 for new contributions, MIT for older
ones (its LICENSE file); both fit this project's MIT OR Apache-2.0. It is
a test fixture only and is not shipped.
@@ -0,0 +1,376 @@
{
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"dxt_version": {
"type": "string",
"const": "0.3",
"description": "@deprecated Use manifest_version instead"
},
"manifest_version": {
"type": "string",
"const": "0.3"
},
"name": {
"type": "string"
},
"display_name": {
"type": "string"
},
"version": {
"type": "string"
},
"description": {
"type": "string"
},
"long_description": {
"type": "string"
},
"author": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"url": {
"type": "string",
"format": "uri"
}
},
"required": [
"name"
],
"additionalProperties": false
},
"repository": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"url": {
"type": "string",
"format": "uri"
}
},
"required": [
"type",
"url"
],
"additionalProperties": false
},
"homepage": {
"type": "string",
"format": "uri"
},
"documentation": {
"type": "string",
"format": "uri"
},
"support": {
"type": "string",
"format": "uri"
},
"icon": {
"type": "string"
},
"icons": {
"type": "array",
"items": {
"type": "object",
"properties": {
"src": {
"type": "string"
},
"size": {
"type": "string",
"pattern": "^\\d+x\\d+$"
},
"theme": {
"type": "string",
"minLength": 1
}
},
"required": [
"src",
"size"
],
"additionalProperties": false
}
},
"screenshots": {
"type": "array",
"items": {
"type": "string"
}
},
"localization": {
"type": "object",
"properties": {
"resources": {
"type": "string",
"pattern": "\\$\\{locale\\}"
},
"default_locale": {
"type": "string",
"pattern": "^[A-Za-z0-9]{2,8}(?:-[A-Za-z0-9]{1,8})*$"
}
},
"required": [
"resources",
"default_locale"
],
"additionalProperties": false
},
"server": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"python",
"node",
"binary"
]
},
"entry_point": {
"type": "string"
},
"mcp_config": {
"type": "object",
"properties": {
"command": {
"type": "string"
},
"args": {
"type": "array",
"items": {
"type": "string"
}
},
"env": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"platform_overrides": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"command": {
"$ref": "#/properties/server/properties/mcp_config/properties/command"
},
"args": {
"$ref": "#/properties/server/properties/mcp_config/properties/args"
},
"env": {
"$ref": "#/properties/server/properties/mcp_config/properties/env"
}
},
"additionalProperties": false
}
}
},
"required": [
"command"
],
"additionalProperties": false
}
},
"required": [
"type",
"entry_point",
"mcp_config"
],
"additionalProperties": false
},
"tools": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
}
},
"required": [
"name"
],
"additionalProperties": false
}
},
"tools_generated": {
"type": "boolean"
},
"prompts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"arguments": {
"type": "array",
"items": {
"type": "string"
}
},
"text": {
"type": "string"
}
},
"required": [
"name",
"text"
],
"additionalProperties": false
}
},
"prompts_generated": {
"type": "boolean"
},
"keywords": {
"type": "array",
"items": {
"type": "string"
}
},
"license": {
"type": "string"
},
"privacy_policies": {
"type": "array",
"items": {
"type": "string",
"format": "uri"
}
},
"compatibility": {
"type": "object",
"properties": {
"claude_desktop": {
"type": "string"
},
"platforms": {
"type": "array",
"items": {
"type": "string",
"enum": [
"darwin",
"win32",
"linux"
]
}
},
"runtimes": {
"type": "object",
"properties": {
"python": {
"type": "string"
},
"node": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
"user_config": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"string",
"number",
"boolean",
"directory",
"file"
]
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"required": {
"type": "boolean"
},
"default": {
"anyOf": [
{
"type": "string"
},
{
"type": "number"
},
{
"type": "boolean"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"multiple": {
"type": "boolean"
},
"sensitive": {
"type": "boolean"
},
"min": {
"type": "number"
},
"max": {
"type": "number"
}
},
"required": [
"type",
"title",
"description"
],
"additionalProperties": false
}
},
"_meta": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": {}
}
}
},
"required": [
"name",
"version",
"description",
"author",
"server"
],
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#"
}
+709
View File
@@ -0,0 +1,709 @@
//! The packages (plan P15 unit C1; WB-pkg-1 to WB-pkg-7): what can be checked
//! on Linux about the Windows installer, the macOS app, the Linux entries and
//! the one source of the version. For Windows and macOS the release workflow
//! is the real test (each packaging step fails loudly); these tests keep the
//! files it builds from true to the rules.
//!
//! ```text
//! GOAL: an installed Wanderbooks is one executable at a stable path, named
//! Wanderbooks everywhere a person sees it, with the licences beside
//! it; installing a newer one over it, or uninstalling it, never
//! touches the person's books.
//! SOURCE: WB-pkg-1 (installs like a normal program), WB-pkg-2 (one
//! executable, a stable bridge path), WB-pkg-6 (one version, one
//! name), WB-pkg-7 (the release carries the licences); D-77.
//! INVARIANTS:
//! 1. The version is written once (ledger-cli's Cargo.toml); the packaging
//! scripts read it through deploy/packaging/version.sh.
//! 2. The Windows installer is per user (no administrator), installs one
//! program, and its uninstaller names nothing but what the installer
//! put in its own folder: no recursive removal, no wildcard, no data
//! folder.
//! 3. The macOS bundle holds one program at Contents/MacOS/wanderbooks, an
//! Info.plist whose identifier, name, version and executable agree with
//! the scripts, and the licences.
//! 4. The Linux desktop entries launch plain `wanderbooks` (an AppImage's
//! launcher appends what it is given) with the icon, the name, and the
//! window's app id.
//! 5. Every package carries LICENSE-MIT, LICENSE-APACHE and
//! THIRD-PARTY-NOTICES.txt.
//! SCENARIOS:
//! 1. The bundle script run on Linux with a stand-in program makes a
//! bundle whose plist and files match the rules above.
//! ```
use std::path::{Path, PathBuf};
use std::process::Command;
fn root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")
}
fn read(path: &str) -> String {
std::fs::read_to_string(root().join(path)).unwrap_or_else(|e| panic!("{path}: {e}"))
}
/// The lines of `text` that are not comments (`;` for NSIS, `#` for shell
/// and TOML).
fn code(text: &str) -> Vec<&str> {
text.lines()
.map(str::trim)
.filter(|l| !l.is_empty() && !l.starts_with(';') && !l.starts_with('#'))
.collect()
}
const LICENCE_FILES: [&str; 3] = ["LICENSE-MIT", "LICENSE-APACHE", "THIRD-PARTY-NOTICES.txt"];
// ---- the version, written once ---------------------------------------------------
#[cfg(unix)]
#[test]
fn the_version_is_written_once_and_every_script_reads_it_from_there() {
let out = Command::new("sh")
.arg(root().join("deploy/packaging/version.sh"))
.output()
.unwrap();
assert!(out.status.success(), "{out:?}");
let said = String::from_utf8(out.stdout).unwrap();
assert_eq!(said.trim(), env!("CARGO_PKG_VERSION"));
// The Linux packager's own file carries a version the build script
// overwrites; it must not drift from the source.
let packager = read("deploy/packaging/packager.toml");
let line = code(&packager)
.into_iter()
.find(|l| l.starts_with("version = "))
.unwrap();
assert_eq!(line, format!("version = \"{}\"", env!("CARGO_PKG_VERSION")));
// No packaging script or workflow assigns a literal version.
for file in [
"deploy/packaging/windows/build-windows.sh",
"deploy/packaging/macos/build-macos.sh",
".github/workflows/release.yml",
] {
for line in code(&read(file)) {
let assigns = line.starts_with("version=") || line.starts_with("version:");
let literal = line.split(['=', ':']).nth(1).is_some_and(|v| {
v.trim()
.trim_matches('"')
.chars()
.next()
.is_some_and(|c| c.is_ascii_digit())
});
assert!(!(assigns && literal), "{file}: a literal version: {line}");
}
}
for file in [
"deploy/packaging/windows/build-windows.sh",
"deploy/packaging/macos/build-macos.sh",
"deploy/packaging/build-linux.sh",
] {
let text = read(file);
assert!(
text.contains("version.sh") || text.contains("ledger-cli/Cargo.toml"),
"{file} does not read the version from its one source"
);
}
}
#[cfg(unix)]
#[test]
fn a_version_that_is_not_three_numbers_is_refused() {
let dir = tempfile::tempdir().unwrap();
std::fs::create_dir_all(dir.path().join("deploy/packaging")).unwrap();
std::fs::create_dir_all(dir.path().join("crates/ledger-cli")).unwrap();
std::fs::copy(
root().join("deploy/packaging/version.sh"),
dir.path().join("deploy/packaging/version.sh"),
)
.unwrap();
for (toml, ok) in [
("version = \"0.2.0\"\n", true),
("version = \"0.2.0-rc1\"\n", false),
("version = \"two\"\n", false),
("", false),
] {
std::fs::write(dir.path().join("crates/ledger-cli/Cargo.toml"), toml).unwrap();
let out = Command::new("sh")
.arg(dir.path().join("deploy/packaging/version.sh"))
.output()
.unwrap();
assert_eq!(out.status.success(), ok, "{toml:?}: {out:?}");
}
}
// ---- Windows --------------------------------------------------------------------
#[test]
fn the_windows_installer_is_per_user_and_installs_one_program() {
let nsi = read("deploy/packaging/windows/wanderbooks.nsi");
let lines = code(&nsi);
let has = |needle: &str| lines.iter().any(|l| l.contains(needle));
// No administrator prompt; everything in the person's own profile.
assert!(has("RequestExecutionLevel user"));
assert!(has(r#"InstallDir "$LOCALAPPDATA\Programs\Wanderbooks""#));
assert!(
!lines.iter().any(|l| l.contains("HKLM")),
"per-machine registry"
);
assert!(!has("SetShellVarContext all"), "all users' Start Menu");
// A Start Menu entry named Wanderbooks, with the icon.
assert!(has(
r#"CreateShortCut "$SMPROGRAMS\${NAME}.lnk" "$INSTDIR\wanderbooks.exe""#
));
assert!(has(r#"!define NAME "Wanderbooks""#));
assert!(has("wanderbooks.ico"));
// An uninstaller, listed in Settings > Apps, whose name is the product's.
assert!(has("WriteUninstaller"));
assert!(has(r#""DisplayName" "${NAME}""#));
assert!(has("UninstallString"));
// One program: the only .exe installed besides the uninstaller.
let programs: Vec<&&str> = lines
.iter()
.filter(|l| l.starts_with("File ") && l.contains(".exe"))
.collect();
assert_eq!(programs.len(), 1, "{programs:?}");
assert!(programs[0].contains("/oname=wanderbooks.exe"));
// The licences travel with it.
for file in LICENCE_FILES {
assert!(has(&format!("/oname={file}")), "{file} is not installed");
}
}
/// WB-pkg-1: the uninstaller removes what the installer put in its own
/// folder and nothing else; the books are in the data folder, which it never
/// names.
#[test]
fn the_uninstaller_never_removes_the_books() {
let nsi = read("deploy/packaging/windows/wanderbooks.nsi");
let lines = code(&nsi);
let start = lines
.iter()
.position(|l| l.starts_with(r#"Section "Uninstall""#))
.expect("an uninstall section");
let section = &lines[start..];
let mut removals = 0;
for line in section {
let word = line.split_whitespace().next().unwrap_or("");
if matches!(word, "Delete" | "RMDir" | "DeleteRegKey" | "DeleteRegValue") {
removals += 1;
assert!(!line.contains("/r"), "a recursive removal: {line}");
assert!(
!line.contains('*') && !line.contains('?'),
"a wildcard: {line}"
);
let ok = line.contains("$INSTDIR")
|| line.contains("$SMPROGRAMS")
|| line.contains("${UNINSTALL_KEY}")
|| line.contains("${APP_KEY}");
assert!(
ok,
"removes something that is not the program's own: {line}"
);
}
}
assert!(removals >= 6, "the uninstaller removes the installed files");
// The data folder, the roaming settings and the keys are named nowhere
// in the script's code (the comments say where the books are).
for line in &lines {
for data in [
"$LOCALAPPDATA\\wanderbooks",
"$APPDATA",
"\\link",
"legacy",
"books\\",
] {
assert!(!line.contains(data), "{data} named: {line}");
}
}
// Only the registry keys of its own.
let keys: Vec<&&str> = lines
.iter()
.filter(|l| l.starts_with("!define") && l.contains("_KEY"))
.collect();
assert_eq!(keys.len(), 2, "{keys:?}");
assert!(keys[0].contains(r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Wanderbooks"));
assert!(keys[1].contains(r"Software\Wanderbooks"));
}
/// If NSIS is installed here, the script compiles with stand-in files
/// (the release workflow compiles it for real on Windows).
#[test]
fn the_installer_script_compiles_when_nsis_is_here() {
let Some(makensis) = std::env::var_os("PATH").and_then(|p| {
std::env::split_paths(&p)
.map(|d| d.join("makensis"))
.find(|f| f.is_file())
}) else {
eprintln!(
"makensis is not installed here: the Windows job of the release workflow compiles the installer"
);
return;
};
let dir = tempfile::tempdir().unwrap();
let p = dir.path();
std::fs::write(p.join("wanderbooks.exe"), b"MZ").unwrap();
for f in LICENCE_FILES {
std::fs::write(p.join(f), b"x").unwrap();
}
std::fs::copy(
root().join("deploy/packaging/icons/wanderbooks.ico"),
p.join("wanderbooks.ico"),
)
.unwrap();
let out = Command::new(makensis)
.arg("-V2")
.arg(format!("-DVERSION={}", env!("CARGO_PKG_VERSION")))
.arg(format!("-DPROGRAM={}", p.join("wanderbooks.exe").display()))
.arg(format!("-DICON={}", p.join("wanderbooks.ico").display()))
.arg(format!("-DLICENSES={}", p.display()))
.arg(format!("-DOUTFILE={}", p.join("setup.exe").display()))
.arg(root().join("deploy/packaging/windows/wanderbooks.nsi"))
.output()
.unwrap();
assert!(
out.status.success(),
"{}",
String::from_utf8_lossy(&out.stdout)
);
assert!(p.join("setup.exe").metadata().unwrap().len() > 0);
}
/// WB-pkg-2: on Windows the one executable is built for the GUI subsystem
/// (no console window for the app), and gives a terminal its words back.
#[test]
fn the_windows_program_opens_no_console_window_and_still_speaks_in_a_terminal() {
let main = read("crates/ledger-cli/src/main.rs");
assert!(
main.contains(
r#"#![cfg_attr(all(windows, feature = "gui"), windows_subsystem = "windows")]"#
)
);
assert!(main.contains("console::attach_parent_console()"));
let console = read("crates/ledger-cli/src/console.rs");
assert!(console.contains("AttachConsole(ATTACH_PARENT_PROCESS)"));
// The server child the app starts has no console window of its own.
assert!(read("crates/ledger-host/src/app_server.rs").contains("NO_WINDOW"));
}
// ---- macOS ----------------------------------------------------------------------
/// The `<key>`/value pairs of a plist's top-level dict, as text. Good enough
/// for the plain plists here (no nesting).
fn plist(text: &str) -> Vec<(String, String)> {
let mut pairs = Vec::new();
let mut key: Option<String> = None;
for line in text.lines().map(str::trim) {
if let Some(k) = line
.strip_prefix("<key>")
.and_then(|l| l.strip_suffix("</key>"))
{
assert!(key.is_none(), "a key with no value: {k}");
key = Some(k.to_string());
} else if let Some(k) = key.take_if(|_| line.starts_with('<') && !line.starts_with("<!--"))
{
let value = line
.strip_prefix("<string>")
.and_then(|l| l.strip_suffix("</string>"))
.map(str::to_string)
.unwrap_or_else(|| line.to_string());
pairs.push((k, value));
}
}
assert!(key.is_none(), "a key with no value at the end");
pairs
}
#[cfg(unix)]
#[test]
fn the_macos_bundle_has_one_program_and_a_plist_that_agrees_with_the_scripts() {
use std::os::unix::fs::PermissionsExt;
let dir = tempfile::tempdir().unwrap();
let stand_in = dir.path().join("program");
std::fs::write(&stand_in, b"not a real program").unwrap();
let version = "0.0.7";
let out = Command::new("bash")
.arg(root().join("deploy/packaging/macos/build-macos.sh"))
.arg(version)
.env("WB_PROGRAM", &stand_in)
.env("WB_NO_ICNS", "1")
.env("WB_BUNDLE_ONLY", "1")
.output()
.unwrap();
let app = root().join(format!(
"target/packages/.stage-macos-{version}/Wanderbooks.app"
));
let cleanup = Cleanup(root().join(format!("target/packages/.stage-macos-{version}")));
assert!(
out.status.success(),
"{}{}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
);
let exe = app.join("Contents/MacOS/wanderbooks");
assert!(exe.is_file());
assert_ne!(
exe.metadata().unwrap().permissions().mode() & 0o111,
0,
"not executable"
);
let programs: Vec<_> = std::fs::read_dir(app.join("Contents/MacOS"))
.unwrap()
.collect();
assert_eq!(programs.len(), 1, "one program in the bundle");
for file in LICENCE_FILES {
assert!(
app.join("Contents/Resources").join(file).is_file(),
"{file}"
);
}
let info = std::fs::read_to_string(app.join("Contents/Info.plist")).unwrap();
assert!(!info.contains('@'), "an unfilled placeholder: {info}");
let pairs = plist(&info);
let get = |k: &str| {
pairs
.iter()
.find(|(key, _)| key == k)
.unwrap_or_else(|| panic!("{k} is missing from Info.plist"))
.1
.clone()
};
assert_eq!(get("CFBundleIdentifier"), "ai.wanderbooks.app");
assert_eq!(get("CFBundleName"), "Wanderbooks");
assert_eq!(get("CFBundleDisplayName"), "Wanderbooks");
assert_eq!(get("CFBundleExecutable"), "wanderbooks");
assert_eq!(get("CFBundleShortVersionString"), version);
assert_eq!(get("CFBundleVersion"), version);
assert_eq!(get("CFBundlePackageType"), "APPL");
assert_eq!(get("LSMinimumSystemVersion"), "11.0");
assert_eq!(get("LSMultipleInstancesProhibited"), "<true/>");
assert!(get("NSDocumentsFolderUsageDescription").contains("Documents"));
drop(cleanup);
}
/// Removes a folder when dropped (a test's own scratch under `target/`).
struct Cleanup(PathBuf);
impl Drop for Cleanup {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.0);
}
}
#[test]
fn the_entitlements_are_empty_on_purpose_and_say_why() {
let text = read("deploy/packaging/macos/entitlements.plist");
assert!(
code(&text).contains(&"<dict/>"),
"no entitlement is claimed without a reason"
);
assert!(text.contains("hardened runtime"));
assert!(text.contains("NOT sandboxed"));
}
#[test]
fn the_macos_script_signs_only_with_an_identity_and_names_no_secret() {
let script = read("deploy/packaging/macos/build-macos.sh");
// Secrets come from the environment, by name; none is written here.
for name in [
"WB_SIGN_IDENTITY",
"WB_NOTARY_APPLE_ID",
"WB_NOTARY_TEAM_ID",
"WB_NOTARY_PASSWORD",
] {
assert!(script.contains(name), "{name}");
}
assert!(script.contains("--options runtime"), "the hardened runtime");
assert!(script.contains("entitlements.plist"));
assert!(script.contains("notarytool submit"));
assert!(script.contains("stapler staple"));
assert!(script.contains("lipo -create"), "universal");
for line in code(&script) {
assert!(
!line.contains("password=") || line.contains("$("),
"a literal password: {line}"
);
}
}
// ---- Linux ----------------------------------------------------------------------
/// The `Key=Value` lines of a desktop entry.
fn desktop(text: &str) -> Vec<(String, String)> {
text.lines()
.filter_map(|l| l.split_once('='))
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect()
}
#[test]
fn the_desktop_entries_launch_plain_wanderbooks_with_the_icon_and_the_window_id() {
// The id the window announces, which the launcher matches (Wayland, and
// X11's WM class).
let gui = read("crates/ledger-gui/src/lib.rs");
assert!(gui.contains(r#".with_app_id("wanderbooks")"#));
for file in [
"deploy/packaging/wanderbooks-static.desktop",
"deploy/packaging/wanderbooks.desktop",
] {
let entries = desktop(&read(file));
let get = |k: &str| {
entries
.iter()
.find(|(key, _)| key == k)
.unwrap_or_else(|| panic!("{file}: {k} is missing"))
.1
.clone()
};
assert_eq!(get("Type"), "Application", "{file}");
assert_eq!(get("Terminal"), "false", "{file}");
assert_eq!(get("StartupWMClass"), "wanderbooks", "{file}");
let categories = get("Categories");
assert!(
categories.starts_with("{{") || categories.ends_with(';'),
"{file}: {categories}"
);
// An AppImage's launcher appends what it is given to the Exec line:
// it names the program and nothing else.
let exec = get("Exec");
assert!(
exec == "wanderbooks" || exec == "{{exec}}",
"{file}: {exec}"
);
let name = get("Name");
assert!(
name == "Wanderbooks" || name == "{{name}}",
"{file}: {name}"
);
let icon = get("Icon");
assert!(
icon == "wanderbooks" || icon == "{{icon}}",
"{file}: {icon}"
);
}
// The static entry (the .rpm's) is a valid desktop file.
if let Some(tool) = std::env::var_os("PATH").and_then(|p| {
std::env::split_paths(&p)
.map(|d| d.join("desktop-file-validate"))
.find(|f| f.is_file())
}) {
let out = Command::new(tool)
.arg(root().join("deploy/packaging/wanderbooks-static.desktop"))
.output()
.unwrap();
assert!(
out.status.success(),
"{}",
String::from_utf8_lossy(&out.stdout)
);
}
}
/// WB-pkg-7: every package carries the licences, and the Linux packages
/// install the icon their desktop entry names.
#[test]
fn every_package_carries_the_licences_and_the_icon() {
let deb_pacman = read("deploy/packaging/packager.toml");
let rpm = read("crates/ledger-cli/Cargo.toml");
let rpm_script = read("deploy/packaging/build-linux.sh");
let windows = read("deploy/packaging/windows/wanderbooks.nsi");
let mac = read("deploy/packaging/macos/build-macos.sh");
for file in LICENCE_FILES {
assert!(
deb_pacman.contains(&format!("\"{file}\" = ")),
"deb or pacman lacks {file}"
);
assert_eq!(
deb_pacman.matches(&format!("\"{file}\" = ")).count(),
3,
"the deb, the AppImage and the pacman package each carry {file}"
);
assert!(
rpm.contains(&format!("source = \"{file}\"")),
"rpm lacks {file}"
);
assert!(
rpm_script.contains(&format!("source = \"{file}\"")),
"rpm script lacks {file}"
);
assert!(
windows.contains(&format!("/oname={file}")),
"windows lacks {file}"
);
assert!(mac.contains(file), "macos lacks {file}");
}
assert!(rpm.contains("512x512/apps/wanderbooks.png"));
assert!(rpm_script.contains("512x512/apps/wanderbooks.png"));
for file in LICENCE_FILES {
assert!(
root().join(file).is_file(),
"{file} is not in the repository"
);
}
}
#[test]
fn no_package_runs_a_script_that_could_touch_the_books() {
let packager = read("deploy/packaging/packager.toml");
for key in [
"postrm",
"post-remove",
"before-remove",
"preinst",
"postinst",
"after-install",
"scripts",
] {
assert!(!packager.contains(key), "{key} in packager.toml");
}
let rpm = read("crates/ledger-cli/Cargo.toml");
for key in [
"post_uninstall",
"pre_uninstall",
"post_install_script",
"pre_install_script",
] {
assert!(!rpm.contains(key), "{key} in Cargo.toml");
}
}
// ---- the release workflow -------------------------------------------------------
/// WB-pkg-7: the release builds all three packages, ends in a DRAFT with the
/// SHA-256 sums, runs only on a version tag or by hand, and publishes
/// nothing by itself.
#[test]
fn the_release_workflow_makes_a_draft_of_all_three_packages_and_publishes_nothing() {
let text = read(".github/workflows/release.yml");
let lines = code(&text);
let has = |needle: &str| lines.iter().any(|l| l.contains(needle));
// Triggers: a tag or by hand; never an ordinary push or a pull request.
let on = lines
.iter()
.position(|l| *l == "on:")
.expect("an `on:` block");
let jobs = lines.iter().position(|l| *l == "jobs:").expect("jobs");
let triggers: Vec<&&str> = lines[on + 1..jobs].iter().collect();
assert!(
triggers.iter().any(|l| l.starts_with("tags:")),
"{triggers:?}"
);
assert!(triggers.iter().any(|l| l.starts_with("workflow_dispatch:")));
assert!(
!triggers
.iter()
.any(|l| l.starts_with("pull_request") || l.starts_with("schedule"))
);
let push = triggers
.iter()
.position(|l| l.starts_with("push:"))
.unwrap();
assert!(
triggers[push + 1].starts_with("tags:"),
"a push trigger without tags"
);
// All three systems, each tested on its own system before packaging.
for runner in ["ubuntu-24.04", "windows-latest", "macos-latest"] {
assert!(has(&format!("runs-on: {runner}")), "{runner}");
}
assert_eq!(
lines
.iter()
.filter(|l| l.contains("cargo test --workspace --no-fail-fast"))
.count(),
3,
"each system runs the workspace's tests"
);
// The three packages, the sums, the licences and the update note.
for needle in [
"just package-linux",
"build-windows.sh",
"build-macos.sh",
"sha256sum",
"SHA256SUMS.txt",
"THIRD-PARTY-NOTICES.txt",
"LICENSE-MIT",
"LICENSE-APACHE",
"latest.json",
"scripts/notices.sh --check",
] {
assert!(has(needle), "{needle} is not in the release workflow");
}
// A draft, never published, never a published release touched.
assert!(has("gh release create"));
assert!(has("--draft"));
for never in [
"--draft=false",
"gh release edit",
"gh-pages",
"prerelease=false",
"make_latest",
] {
assert!(!has(never), "{never} would publish");
}
assert!(has("never changes a published release"));
// Secrets are read by name from the secrets store, never written here.
for secret in [
"WINDOWS_CERTIFICATE_PFX_BASE64",
"APPLE_CERTIFICATE_P12_BASE64",
"APPLE_SIGNING_IDENTITY",
"APPLE_APP_SPECIFIC_PASSWORD",
] {
assert!(has(&format!("${{{{ secrets.{secret} }}}}")), "{secret}");
}
// Signing steps say so when they are skipped.
assert!(has("macOS signing skipped"));
assert!(read("deploy/packaging/windows/sign-windows.ps1").contains("Windows signing skipped"));
assert!(read("deploy/packaging/macos/build-macos.sh").contains("macOS notarization skipped"));
// The Windows job installs and uninstalls the installer, and checks the
// books' folder survives.
assert!(has("THE UNINSTALLER REMOVED THE BOOKS' FOLDER"));
assert!(has("subsystem -ne 2"));
}
#[test]
fn only_a_person_runs_the_workflow_that_publishes_the_repositories() {
let text = read(".github/workflows/publish-repos.yml");
let lines = code(&text);
let on = lines.iter().position(|l| *l == "on:").unwrap();
let jobs = lines.iter().position(|l| *l == "jobs:").unwrap();
for l in &lines[on + 1..jobs] {
assert!(
!(l.starts_with("push:") || l.starts_with("pull_request") || l.starts_with("schedule")),
"{l}: only workflow_dispatch may start it"
);
}
assert!(lines.iter().any(|l| l.starts_with("workflow_dispatch:")));
assert!(
lines.iter().any(|l| l.contains("isDraft")),
"it refuses a draft"
);
}
/// WB-pkg-4: on Linux git is a dependency of every package, so the package
/// manager fetches it; nothing carries a git of its own.
#[test]
fn the_linux_packages_depend_on_git_and_none_carries_one() {
let packager = read("deploy/packaging/packager.toml");
assert_eq!(
packager.matches("\"git\"").count(),
2,
"the deb and the pacman package depend on git"
);
assert!(read("crates/ledger-cli/Cargo.toml").contains("requires = { git = \"*\" }"));
assert!(read("deploy/packaging/aur/PKGBUILD").contains("'git'"));
for file in [
"deploy/packaging/windows/wanderbooks.nsi",
"deploy/packaging/macos/build-macos.sh",
] {
let text = read(file).to_lowercase();
assert!(
!text.contains("mingit") && !text.contains("git.exe"),
"{file} bundles a git"
);
}
}