From 93e29a34e9f3f2bebb0408ec0cae4d44751ce93a Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 23 Nov 2026 12:10:57 -0600 Subject: [PATCH] test(fleet): check published queue reference against registered commands --- .../development/keeping-this-book-current.md | 2 +- .../fleet-registry/tests/pmo_operator_docs.rs | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/pkgs/fleet/book/development/keeping-this-book-current.md b/pkgs/fleet/book/development/keeping-this-book-current.md index a7b12d4e02..e83fb8313b 100644 --- a/pkgs/fleet/book/development/keeping-this-book-current.md +++ b/pkgs/fleet/book/development/keeping-this-book-current.md @@ -13,7 +13,7 @@ The supporting rules in the same section: - **The inventory is the registry.** `fleet --help` renders the full registry on every variant and `fleet capabilities` prints it as JSON. The registered inventory lives in one place — `crates/fleet-registry/src/lib.rs` — so no build can know a domain another build forgot. See [Register a domain or capability](register-a-domain.md). - **Designed-versus-shipped discipline.** Spellings that are designed but not yet shipped are documented _as contract, not surface_, explicitly marked as not in the registered inventory and not dispatchable today, each with its shipped equivalent. Invoking one answers `unknown command`. Never write a designed spelling into a procedure as if it works. - **Decision records for settled semantics.** A change to claim/park/resume semantics, supervision or stop authority, cap policy, or attribution/logging requires a fleet decision record (FDR, in repository-root `doc/decisions/`, indexed by `doc/decisions/README.md`) in the same body of work — the same pull request, or the same run for non-PR work. -- **A machine check enforces the inventory half.** The test `pmo_operator_docs_match_registered_help_inventory` in `crates/fleet-registry/tests/pmo_operator_docs.rs` ties the README's operator contract to the registered help inventory: a verb added to the registry without its contract docs, or vice versa, fails the workspace test suite. See [Testing](testing.md). +- **A machine check enforces the inventory half.** The test `pmo_operator_docs_match_registered_help_inventory` in `crates/fleet-registry/tests/pmo_operator_docs.rs` ties the README's operator contract to the registered help inventory: a verb added to the registry without its contract docs, or vice versa, fails the workspace test suite. The companion test `published_queue_reference_matches_registered_help_inventory` compares `fleet queue --help`'s registered commands with command headings in the reference chapters linked from `SUMMARY.md`. A group can appear as a leaf heading, such as `fleet queue session status`. The test names missing and obsolete top-level commands. Review nested leaves, flags, defaults and procedures against the matching handlers and help output. See [Testing](testing.md). ## The extension: the book is part of the same change diff --git a/pkgs/fleet/crates/fleet-registry/tests/pmo_operator_docs.rs b/pkgs/fleet/crates/fleet-registry/tests/pmo_operator_docs.rs index bb00ff8d89..be7e20bc71 100644 --- a/pkgs/fleet/crates/fleet-registry/tests/pmo_operator_docs.rs +++ b/pkgs/fleet/crates/fleet-registry/tests/pmo_operator_docs.rs @@ -213,3 +213,71 @@ fn pmo_operator_docs_match_registered_help_inventory() { ); } } + +/// Oracle: the same queue subcommands rendered by `fleet queue --help`. +/// Only reference chapters linked from SUMMARY reach the published book. +/// A group such as `session` can be documented under its individual leaves. +#[test] +fn published_queue_reference_matches_registered_help_inventory() { + use std::collections::BTreeSet; + + let registered: BTreeSet<_> = fleet_registry::DOMAINS + .iter() + .find(|domain| domain.name == "queue") + .expect("registered queue domain") + .subcommands + .iter() + .copied() + .collect(); + let book = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../book"); + let summary = fs::read_to_string(book.join("SUMMARY.md")).expect("read Fleet book contents"); + let mut documented = BTreeSet::new(); + for line in summary.lines() { + let Some((_, link)) = line.trim().split_once("](reference/") else { + continue; + }; + let Some(chapter) = link.strip_suffix(')') else { + continue; + }; + let path = book.join("reference").join(chapter); + let contents = fs::read_to_string(&path) + .unwrap_or_else(|error| panic!("read {}: {error}", path.display())); + // The book uses fenced examples. Headings inside an example do + // not document a command for the purpose of this contract. + let mut fence = None; + for line in contents.lines() { + let line = line.trim_start(); + if line.starts_with("```") || line.starts_with("~~~") { + let mark = line.as_bytes()[0]; + let width = line.bytes().take_while(|&byte| byte == mark).count(); + match fence { + None => fence = Some((mark, width)), + Some((open, len)) + if mark == open && width >= len && line[width..].trim().is_empty() => + { + fence = None + } + _ => {} + } + continue; + } + if fence.is_none() { + if let Some(command) = line + .strip_prefix("## fleet queue ") + .or_else(|| line.strip_prefix("### fleet queue ")) + .and_then(|heading| heading.split_whitespace().next()) + { + documented.insert(command.to_owned()); + } + } + } + } + + let documented: BTreeSet<_> = documented.iter().map(String::as_str).collect(); + let missing: Vec<_> = registered.difference(&documented).collect(); + let obsolete: Vec<_> = documented.difference(®istered).collect(); + assert!( + missing.is_empty() && obsolete.is_empty(), + "queue book drift: missing reference headings {missing:?}; unregistered headings {obsolete:?}" + ); +}