pub struct Topic {
pub slug: &'static str,
pub title: &'static str,
pub body: &'static str,
}
macro_rules! topic {
($slug:literal, $title:literal, $file:literal) => {
Topic {
slug: $slug,
title: $title,
body: include_str!(concat!("../docs/", $file)),
}
};
}
pub const TOPICS: &[Topic] = &[
topic!(
"config-reference",
"Configuration reference — every file, every field",
"concept-config-reference.md"
),
topic!(
"bootstrap",
"Bootstrap — getting varve itself, verified",
"concept-install.md"
),
topic!(
"getting-started",
"Getting started — nothing to a dispatched tool",
"concept-getting-started.md"
),
topic!(
"pins",
"Pins — how a project names its toolchain",
"concept-pins.md"
),
topic!("realms", "Realms — trust universes", "concept-realms.md"),
topic!(
"layers",
"Layers — one signed, dated bundle per release",
"concept-layers.md"
),
topic!(
"signing-keys",
"Signing keys — the format, and what varve checks",
"concept-signing-keys.md"
),
topic!(
"trust-roots",
"Trust roots — the pinned signing key",
"concept-trust-roots.md"
),
topic!(
"payload-kinds",
"Payload kinds — tool, crate, wit, …",
"concept-payload-kinds.md"
),
topic!("air-gap", "Air-gapped operation", "concept-air-gap.md"),
topic!(
"environment",
"Environment — every variable varve reads, and precedence",
"concept-environment.md"
),
topic!(
"own-realm",
"Running your own realm — key to consumer, end to end",
"concept-own-realm.md"
),
topic!(
"composition",
"Composition — one pin, two trust universes",
"concept-composition.md"
),
topic!(
"artifacts",
"Shipping artifacts that are not executables",
"concept-artifacts.md"
),
topic!(
"recovery",
"Recovery — repairing, removing, and going back",
"concept-recovery.md"
),
topic!(
"threat-model",
"What verification does and does not prove",
"concept-threat-model.md"
),
topic!(
"deploy",
"Deploying a layer — the push, and what consumers need",
"concept-deploy.md"
),
topic!("which", "which — which binary runs here", "cmd-which.md"),
topic!("list", "list — layers in the core", "cmd-list.md"),
topic!(
"install",
"install — verify and lay down the pinned layer",
"cmd-install.md"
),
topic!(
"verify",
"verify — re-check the pinned layer",
"cmd-verify.md"
),
topic!(
"archive",
"archive — export the offline core",
"cmd-archive.md"
),
topic!(
"run",
"run — dispatch a tool with layer provenance",
"cmd-run.md"
),
topic!(
"keygen",
"keygen — mint a signing key and its public half",
"cmd-keygen.md"
),
topic!(
"pubkey",
"pubkey — the value a realm pins as trust-root",
"cmd-pubkey.md"
),
topic!(
"deposit",
"deposit — assemble and sign a layer (CI)",
"cmd-deposit.md"
),
topic!(
"export-bazel",
"export-bazel — checksum registries",
"cmd-export-bazel.md"
),
topic!(
"export-cargo",
"export-cargo — a Cargo local registry",
"cmd-export-cargo.md"
),
topic!(
"export-crates-vendor",
"export-crates-vendor — a cargo-vendor tree",
"cmd-export-crates-vendor.md"
),
topic!(
"export-bazel-distdir",
"export-bazel-distdir — the air-gap Bazel distdir",
"cmd-export-bazel-distdir.md"
),
topic!(
"export-vsix",
"export-vsix — VS Code extensions `code` installs",
"cmd-export-vsix.md"
),
topic!(
"sbom",
"sbom — the signed manifest as a bill of materials",
"cmd-sbom.md"
),
topic!(
"status",
"status — support window, yanks, known problems",
"cmd-status.md"
),
topic!(
"sign-attestation",
"sign-attestation — bind an attestation to a layer (CI)",
"cmd-sign-attestation.md"
),
topic!(
"check-attestation",
"check-attestation — does this attestation belong here?",
"cmd-check-attestation.md"
),
topic!(
"sign-status",
"sign-status — sign a line-status document (CI)",
"cmd-sign-status.md"
),
topic!(
"attach-status",
"attach-status — attach a baseline status (CI)",
"cmd-attach-status.md"
),
topic!(
"sign-index",
"sign-index — sign a line index (CI)",
"cmd-sign-index.md"
),
topic!(
"attach-index",
"attach-index — publish the signed line index (CI)",
"cmd-attach-index.md"
),
topic!("shim", "shim — PATH dispatchers", "cmd-shim.md"),
topic!("env", "env — shell setup", "cmd-env.md"),
topic!(
"completions",
"completions — shell completion scripts",
"cmd-completions.md"
),
topic!(
"sign-sums",
"sign-sums — sign release sums (CI)",
"cmd-sign-sums.md"
),
topic!(
"self-update",
"self-update — update the updater",
"cmd-self-update.md"
),
topic!(
"self-verify",
"self-verify — verify a release file",
"cmd-self-verify.md"
),
topic!("docs", "docs — this documentation", "cmd-docs.md"),
];
pub fn find(slug: &str) -> Option<&'static Topic> {
TOPICS.iter().find(|t| t.slug == slug)
}
pub const REQUIRED_TOPICS: &[&str] = &[
"bootstrap",
"getting-started",
"config-reference",
"environment",
"own-realm",
"composition",
"threat-model",
"deploy",
"signing-keys",
"recovery",
];
pub const TOPICS_NEEDING_EXAMPLES: &[&str] = &[
"bootstrap",
"recovery",
"environment",
"composition",
"getting-started",
"config-reference",
"own-realm",
"deploy",
"deposit",
"realms",
"pins",
"air-gap",
"export-vsix",
];
pub fn missing_required_topics() -> Vec<&'static str> {
missing_required_topics_in(TOPICS)
}
pub fn missing_required_topics_in(topics: &[Topic]) -> Vec<&'static str> {
REQUIRED_TOPICS
.iter()
.copied()
.filter(|slug| !topics.iter().any(|t| t.slug == *slug))
.collect()
}
pub fn topics_without_examples() -> Vec<&'static str> {
topics_without_examples_in(TOPICS)
}
pub fn topics_without_examples_in(topics: &[Topic]) -> Vec<&'static str> {
TOPICS_NEEDING_EXAMPLES
.iter()
.copied()
.filter(|slug| match topics.iter().find(|t| t.slug == *slug) {
Some(t) => !has_a_non_empty_fence(t.body),
None => false,
})
.collect()
}
fn has_a_non_empty_fence(body: &str) -> bool {
let mut inside = false;
for line in body.lines() {
if line.starts_with("```") {
inside = !inside;
continue;
}
if inside && !line.trim().is_empty() {
return true;
}
}
false
}
pub fn coverage_gaps(cmd: &clap::Command) -> Vec<String> {
cmd.get_subcommands()
.map(|c| c.get_name().to_string())
.filter(|name| find(name).is_none())
.collect()
}
pub fn render_list() -> String {
let mut out = String::from("varve docs — topics (varve docs <topic>):\n\n");
for t in TOPICS {
out.push_str(&format!(" {:<22} {}\n", t.slug, t.title));
}
out
}
pub fn render_json(slug: Option<&str>) -> String {
match slug {
None => {
let list: Vec<_> = TOPICS
.iter()
.map(|t| serde_json::json!({"slug": t.slug, "title": t.title}))
.collect();
serde_json::to_string_pretty(&list).expect("topic list serialises")
}
Some(s) => match find(s) {
Some(t) => serde_json::to_string_pretty(
&serde_json::json!({"slug": t.slug, "title": t.title, "body": t.body}),
)
.expect("topic serialises"),
None => "{}".to_string(),
},
}
}
pub fn grep(query: &str) -> Vec<(&'static str, String)> {
let q = query.to_lowercase();
let mut hits = Vec::new();
for t in TOPICS {
for line in t.body.lines() {
if line.to_lowercase().contains(&q) {
hits.push((t.slug, line.trim().to_string()));
}
}
}
hits
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_cli_subcommand_has_a_documented_topic() {
use clap::CommandFactory;
let cmd = crate::Cli::command();
let gaps = coverage_gaps(&cmd);
assert!(
gaps.is_empty(),
"these subcommands have no `varve docs` topic (REQ-DOCS-001): {gaps:?}"
);
}
fn fenced_blocks(slug: &str) -> Vec<(String, String)> {
let body = TOPICS
.iter()
.find(|t| t.slug == slug)
.unwrap_or_else(|| panic!("topic '{slug}' must exist"))
.body;
let mut out = Vec::new();
let mut lang: Option<String> = None;
let mut buf = String::new();
for line in body.lines() {
match (&lang, line.strip_prefix("```")) {
(None, Some(l)) => lang = Some(l.trim().to_string()),
(Some(l), Some(_)) => {
out.push((l.clone(), std::mem::take(&mut buf)));
lang = None;
}
(Some(_), None) => {
buf.push_str(line);
buf.push('\n');
}
(None, None) => {}
}
}
out
}
#[test]
fn the_gate_detects_a_broken_topic_set_not_merely_a_healthy_one() {
const EMPTY: &[Topic] = &[];
let missing = missing_required_topics_in(EMPTY);
assert_eq!(
missing.len(),
REQUIRED_TOPICS.len(),
"with no topics at all, every required topic must be reported missing"
);
const STUBBED: &[Topic] = &[Topic {
slug: "getting-started",
title: "Getting started",
body: "# Getting started\n\nRead the other topics.\n\n```sh\n```\n",
}];
assert!(
topics_without_examples_in(STUBBED).contains(&"getting-started"),
"an empty fence is not a worked example"
);
const REAL: &[Topic] = &[Topic {
slug: "getting-started",
title: "Getting started",
body: "# Getting started\n\n```sh\nvarve install\n```\n",
}];
assert!(
!topics_without_examples_in(REAL).contains(&"getting-started"),
"a fence with a command in it IS a worked example"
);
}
#[test]
fn the_two_flagship_topics_teach_their_feature_not_just_its_name() {
let composition = TOPICS
.iter()
.find(|t| t.slug == "composition")
.unwrap()
.body;
for needle in [
"[[include]]", "varve install", "cycle", "realm's trust root", ] {
assert!(
composition.contains(needle),
"the composition topic must teach `{needle}`"
);
}
let threat = TOPICS
.iter()
.find(|t| t.slug == "threat-model")
.unwrap()
.body;
for needle in [
"does not seal the directory",
"do not re-verify",
"No transparency log",
"No key rotation",
"signer equivocation",
] {
assert!(
threat.contains(needle),
"the threat-model topic must state the limit `{needle}` — a reader \
who cannot reach SECURITY.md has only this"
);
}
}
fn body(slug: &str) -> &'static str {
TOPICS
.iter()
.find(|t| t.slug == slug)
.unwrap_or_else(|| panic!("topic {slug} must exist"))
.body
}
#[test]
fn the_topics_state_the_limits_a_ten_persona_audit_found_them_denying() {
let threat = body("threat-model");
for needle in [
"unnamed files ARE dispatched",
"enumerates the **directory**",
"varve shim install",
"equivalent to code execution",
] {
assert!(
threat.contains(needle),
"the threat-model topic must say `{needle}` — the previous text \
read as though a planted file were inert, and it is dispatched"
);
}
for slug in ["layers", "config-reference"] {
let t = body(slug);
assert!(
t.contains("required in practice"),
"{slug} must not present `[[include]].realm` as merely optional"
);
assert!(
t.contains("re-deposit") || t.contains("re-depositing"),
"{slug} must say the include annotation is inside the SIGNED \
payload, so it cannot be added afterwards"
);
}
let cfg = body("config-reference");
for kind in [
"tool",
"crate",
"wit",
"zephyr-module",
"sdk",
"wasm-component",
"vsix",
] {
assert!(
cfg.contains(kind),
"config-reference must list the `{kind}` payload kind"
);
}
let env = body("environment");
assert!(
env.contains("fingerprint") && env.contains("varve-realms.toml"),
"environment must say `list` labels by fingerprint, not by realm"
);
for needle in ["VARVE_REGISTRY_AUTH", "VARVE_UPDATE_API", "VARVE_ROOT"] {
assert!(env.contains(needle), "environment must document {needle}");
}
let rec = body("recovery");
for needle in [
"does not work",
"rollback refused",
"Deleting the layer directory does not help",
"verify --all",
] {
assert!(
rec.contains(needle),
"recovery must state `{needle}` — repair-in-place holds only \
while no higher counter in the line has been installed"
);
}
for slug in ["archive", "air-gap"] {
let t = body(slug);
assert!(
t.contains("one platform") || t.contains("ONE platform"),
"{slug} must say an archive carries one platform's payloads"
);
assert!(
t.contains("one archive per platform"),
"{slug} must say a mixed site needs one archive per platform — \
varve cannot produce a cross-platform archive offline"
);
}
}
#[test]
fn every_documented_command_is_a_real_command() {
use clap::CommandFactory;
let cmd = crate::Cli::command();
let known: Vec<String> = cmd
.get_subcommands()
.map(|s| s.get_name().to_string())
.collect();
let mut checked = 0;
for topic in TOPICS.iter() {
for (lang, block) in fenced_blocks(topic.slug) {
if lang != "sh" && lang != "bash" && lang != "console" {
continue;
}
for line in block.lines() {
let mut words = line.split_whitespace().peekable();
while let Some(w) = words.next() {
if w != "varve" {
continue;
}
let Some(next) = words.peek() else { continue };
let sub = next.trim_matches(|c: char| {
!c.is_ascii_alphanumeric() && c != '-' && c != '_'
});
if sub.is_empty() || sub.starts_with('-') {
continue;
}
assert!(
known.iter().any(|k| k == sub),
"topic '{}' documents `varve {sub}`, which is not a \
subcommand — known: {known:?}",
topic.slug
);
checked += 1;
}
}
}
}
assert!(
checked >= 20,
"only {checked} documented invocation(s) were checked; the shell \
transcripts are the form users copy most"
);
}
#[test]
fn the_bootstrap_topic_states_what_the_first_hop_cannot_prove() {
let body = TOPICS.iter().find(|t| t.slug == "bootstrap").unwrap().body;
for needle in [
"trust on first use",
"not tell you the repository was not compromised",
"self-update",
"refuses rather than degrades",
] {
assert!(
body.contains(needle),
"the bootstrap topic must state `{needle}` — a page that teaches \
people to install a verification tool must say what its own \
first hop does not prove (REQ-BOOTSTRAP-001 clause 8)"
);
}
}
#[test]
fn a_topic_showing_the_published_realm_shows_the_published_key() {
let published = include_str!("../../../trust-roots/rolling.pub").trim();
assert_eq!(published.len(), 64, "the shipped root must be 64 hex chars");
for topic in TOPICS.iter() {
for (lang, block) in fenced_blocks(topic.slug) {
if lang != "toml" || !block.contains("[realm.pulseengine]") {
continue;
}
for line in block.lines() {
let l = line.trim_start();
if !l.starts_with("trust-root ") && !l.starts_with("trust-root=") {
continue;
}
let value = l.split('"').nth(1).unwrap_or("");
assert_eq!(
value, published,
"topic '{}' shows a trust-root for realm 'pulseengine' that is NOT \
the published rolling.pub — a user who copies it gets \
'No valid signatures'",
topic.slug
);
}
}
}
}
#[test]
fn the_adapter_topic_names_every_adapter_and_what_selects_it() {
let body = TOPICS
.iter()
.find(|t| t.slug == "payload-kinds")
.unwrap()
.body;
assert!(
!body.contains("The kind selects which export adapter applies"),
"the refuted claim must not come back"
);
for adapter in [
"export-cargo",
"export-crates-vendor",
"export-bazel-distdir",
"export-bazel",
] {
assert!(body.contains(adapter), "the table must name `{adapter}`");
}
assert!(
body.contains("[tool.source]") && body.contains("platform"),
"the topic must name what selects export-bazel, not just its name"
);
}
#[test]
fn the_recovery_topic_states_what_repairs_and_what_is_refused() {
let body = TOPICS.iter().find(|t| t.slug == "recovery").unwrap().body;
assert!(
body.contains("varve install --from"),
"the repair must be a command, not a description"
);
assert!(
body.contains("equal") || body.contains("**equal**"),
"it must say WHY re-installing is allowed — an equal counter is no \
regression — or a reader stops at the rollback error"
);
assert!(
body.contains("high-water-marks.json"),
"deliberate rollback means editing local state; name the file"
);
assert!(
body.contains("no `uninstall`") || body.contains("no `uninstall`, `repair`"),
"a missing command must be stated as missing, not left to be searched for"
);
}
#[test]
fn nothing_shipped_claims_varve_publishes() {
let readme = include_str!("../../../README.md");
for (surface, text) in [
("README.md", readme),
(
"the deposit topic",
TOPICS.iter().find(|t| t.slug == "deposit").unwrap().body,
),
(
"the deploy topic",
TOPICS.iter().find(|t| t.slug == "deploy").unwrap().body,
),
] {
for line in text.lines() {
let l = line.to_lowercase();
for claim in [
"and publish a layer",
"sign and publish",
"deposit publishes",
"deposit will publish",
] {
assert!(
!l.contains(claim),
"{surface} still says deposit publishes — varve runs no server \
and pushes nothing (REQ-DEPLOY-001): {line}"
);
}
}
}
}
#[test]
fn the_deploy_topic_carries_a_sequence_a_producer_can_actually_run() {
let body = TOPICS.iter().find(|t| t.slug == "deploy").unwrap().body;
for needle in ["oras blob push", "oras manifest push"] {
assert!(body.contains(needle), "the push must show `{needle}`");
}
for role in ["\"envelope\"", "\"payload\"", "\"line-status\""] {
assert!(
body.contains(role),
"the artifact manifest must annotate the {role} role, or every \
consumer fails to read what was pushed"
);
}
assert!(
!body.contains("<your artifact manifest>"),
"a producer cannot execute a placeholder"
);
for (clause, needle) in [
("the realm registry field", "registry"),
("the trust root", "trust-root"),
(
"first-time bootstrap",
"varve cannot verify the first realms file",
),
("the air-gapped alternative", "varve archive"),
] {
assert!(
body.contains(needle),
"the deploy topic must cover {clause} (REQ-DEPLOY-001)"
);
}
}
#[test]
fn every_documented_file_example_parses_with_the_real_parser() {
let tmp = std::env::temp_dir().join(format!("varve-docs-parse-{}", std::process::id()));
std::fs::create_dir_all(&tmp).unwrap();
let mut checked = 0;
let blocks: Vec<(String, String)> =
TOPICS.iter().flat_map(|t| fenced_blocks(t.slug)).collect();
let mut unclassified: Vec<String> = Vec::new();
for (lang, block) in blocks {
if matches!(lang.as_str(), "toml" | "json") {
let recognised = block.contains("[toolchain]")
|| block.contains("[realm.")
|| block.contains("[[tool]]")
|| block.contains("[tool.runner]")
|| block.contains("\"line\"");
if !recognised {
unclassified.push(block.lines().next().unwrap_or("").trim().to_string());
}
}
match lang.as_str() {
"toml" if block.contains("[toolchain]") => {
varve_core::pin::Pin::parse(&block, "docs")
.expect("the documented varve.toml must parse as a pin");
checked += 1;
}
"toml" if block.contains("[realm.") => {
std::fs::write(tmp.join(varve_core::realm::REALMS_FILE), &block).unwrap();
let names = varve_core::realm::realm_names(&tmp)
.expect("the documented varve-realms.toml must parse");
let first = names.first().expect("it must define a realm").clone();
varve_core::realm::resolve_realm(&tmp, &first)
.expect("the documented realm must RESOLVE, not merely parse");
checked += 1;
}
"toml" if block.contains("[[tool]]") || block.contains("[tool.runner]") => {
varve_core::deposit::parse_deposit_spec(&block)
.expect("the documented deposit spec must parse");
checked += 1;
}
"json" if block.contains("\"line\"") => {
serde_json::from_str::<varve_core::linestatus::LineStatus>(&block)
.expect("the documented line-status document must parse");
checked += 1;
}
_ => {}
}
}
let _ = std::fs::remove_dir_all(&tmp);
assert!(
unclassified.is_empty(),
"{} structured block(s) reached no parser — a silent skip is how a \
broken example survives the gate: {unclassified:?}",
unclassified.len()
);
assert!(
checked >= 6,
"the docs claim to cover every hand-written file; only {checked} \
example(s) were machine-checked against a real parser (REQ-DOCS-003)"
);
}
#[test]
fn the_docs_teach_the_facts_a_user_is_rejected_for_not_knowing() {
let must_appear: &[(&str, &str)] = &[
("manifest-version", "config-reference"),
("kind = \"crate\"", "config-reference"),
("VARVE_ROOT", "environment"),
("VARVE_TRUST_ROOT", "environment"),
("varve.toml", "config-reference"),
("varve-realms.toml", "config-reference"),
("trust-root", "config-reference"),
("[[include]]", "config-reference"),
];
for (fact, topic) in must_appear {
let body = TOPICS
.iter()
.find(|t| t.slug == *topic)
.unwrap_or_else(|| panic!("topic '{topic}' must exist"))
.body;
assert!(
body.contains(fact),
"topic '{topic}' must teach `{fact}` — a user who does not know it \
has their file REJECTED (REQ-DOCS-002)"
);
}
}
#[test]
fn the_task_topics_walk_a_user_through_a_sequence() {
for name in ["getting-started", "own-realm"] {
let body = TOPICS.iter().find(|t| t.slug == name).unwrap().body;
let commands = body.matches("varve ").count();
assert!(
commands >= 4,
"task topic '{name}' names {commands} varve invocation(s); a task is a \
SEQUENCE, not a single command (REQ-DOCS-002)"
);
}
}
#[test]
fn the_workflow_topics_exist() {
let missing = missing_required_topics();
assert!(
missing.is_empty(),
"required workflow topics missing (REQ-DOCS-003): {missing:?}"
);
}
#[test]
fn topics_a_user_must_act_on_show_a_worked_example() {
let bare = topics_without_examples();
assert!(
bare.is_empty(),
"these topics must show a literal example, not describe one \
(REQ-DOCS-003): {bare:?}"
);
}
#[test]
fn topics_are_findable_and_greppable() {
assert!(find("air-gap").is_some());
assert!(find("install").is_some());
assert!(find("nonexistent").is_none());
assert!(
!grep("verify").is_empty(),
"grep should find 'verify' somewhere"
);
}
#[test]
fn topic_list_renders_as_machine_readable_json() {
let v: serde_json::Value = serde_json::from_str(&render_json(None)).unwrap();
let arr = v.as_array().expect("--format json list is a JSON array");
assert_eq!(arr.len(), TOPICS.len());
let first = &arr[0];
assert!(first.get("slug").and_then(|s| s.as_str()).is_some());
assert!(first.get("title").and_then(|s| s.as_str()).is_some());
assert!(first.get("body").is_none(), "list form omits bodies");
}
#[test]
fn single_topic_renders_as_json_with_body() {
let v: serde_json::Value = serde_json::from_str(&render_json(Some("air-gap"))).unwrap();
assert_eq!(v.get("slug").and_then(|s| s.as_str()), Some("air-gap"));
assert!(
v.get("body").and_then(|s| s.as_str()).unwrap().len() > 40,
"single-topic JSON carries the full body"
);
}
#[test]
fn no_topic_body_is_empty() {
for t in TOPICS {
assert!(
t.body.trim().len() > 40,
"topic {} is too short to be real documentation",
t.slug
);
}
}
}