tests/proto_is_holgers.rs
//! The vendored `proto/holger.proto` is a COPY of holger's contract, not a second
//! contract — and this test is the alarm that fires when it stops being one.
//!
//! `build.rs` compiles the vendored copy and nothing else, so that `git clone && cargo
//! build` is reproducible and a `git switch` in a sibling repository cannot change what
//! this console speaks (see `build.rs` for the day it could). The price of that is that
//! drift is invisible to the compiler, and this test is what pays it.
//!
//! **What it compares against.** holger's contract as holger COMMITS it, never a working
//! tree: the sibling checkout's `origin/main:proto/holger.proto` (what holger publishes)
//! OR its `HEAD:proto/holger.proto` (the holger a release line pairs this console with —
//! the nordisk sibling set names both checkouts at one commit each, and a feature line's
//! console speaks its feature line's holger before either reaches main). A copy of
//! either IS holger's contract; anything else is a second contract. Measured 2026-09-17:
//! `~/git/holger` was on an old main (170 lines) while its `origin/main`
//! carried the 414-line contract this console speaks — a parked checkout is why
//! `origin/main` stays a valid answer. Measured 2026-10-05: on the holger-ebox line
//! (holger 95335a8, the thin-UI's `WhoAmIRequest.repository`, not on main yet) no copy
//! could equal `origin/main` without dropping what the console calls, so the check
//! was red on every rung 0 of the line.
use std::path::Path;
use std::process::Command;
/// holger's contract as the sibling checkout COMMITS it at `rev` (`origin/main`,
/// `HEAD`). `None` when holger is not checked out beside this repo, or when git
/// cannot answer.
fn holgers_proto_at(repo: &Path, rev: &str) -> Option<String> {
if !repo.is_dir() {
return None;
}
let out = Command::new("git")
.arg("-C")
.arg(repo)
.args(["show", &format!("{rev}:proto/holger.proto")])
.output()
.ok()?;
out.status
.success()
.then(|| String::from_utf8(out.stdout).ok())
.flatten()
}
#[test]
fn the_vendored_proto_is_byte_identical_to_holgers() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let holger = root.join("../holger");
let at: Vec<(&str, String)> = ["HEAD", "origin/main"]
.into_iter()
.filter_map(|rev| holgers_proto_at(&holger, rev).map(|p| (rev, p)))
.collect();
if at.is_empty() {
eprintln!(
"skipping: holger is not checked out beside this repo ({}), or git knows \
neither its HEAD nor its origin/main — the vendored copy is the only contract here",
holger.display()
);
return;
}
let vendored = std::fs::read_to_string(root.join("proto/holger.proto")).unwrap();
assert!(
at.iter().any(|(_, p)| *p == vendored),
"proto/holger.proto is a copy of neither holger's HEAD nor its origin/main ({}) — \
refresh it from the holger this console is paired with: \
git -C ../holger show HEAD:proto/holger.proto > proto/holger.proto \
(build.rs compiles the vendored copy, so nothing else will tell you)",
at.iter().map(|(r, _)| *r).collect::<Vec<_>>().join(", ")
);
}
/// holger's file `name` as the sibling checkout commits it at `rev`.
fn holgers_file_at(repo: &Path, rev: &str, name: &str) -> Option<String> {
let out = Command::new("git").arg("-C").arg(repo).args(["show", &format!("{rev}:proto/{name}")]).output().ok()?;
out.status.success().then(|| String::from_utf8(out.stdout).ok()).flatten()
}
/// The account and token contracts (lanes P4 and P3) are copies of holger's too. A file
/// holger does not commit yet (the token contract before lane P3 lands) is a stub the console
/// was built against, said and skipped; once holger commits it, the copy must be its.
#[test]
fn the_vendored_account_and_token_contracts_are_holgers() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let holger = root.join("../holger");
if !holger.is_dir() {
eprintln!("skipping: holger is not checked out beside this repo");
return;
}
for name in ["holger-account.proto", "holger-token.proto"] {
let at: Vec<String> = ["HEAD", "origin/main"].into_iter().filter_map(|rev| holgers_file_at(&holger, rev, name)).collect();
if at.is_empty() {
eprintln!("skipping {name}: holger commits no such file yet — the vendored copy is the draft this console was built against");
continue;
}
let vendored = std::fs::read_to_string(root.join("proto").join(name)).unwrap();
assert!(at.iter().any(|p| *p == vendored), "proto/{name} is a copy of neither holger's HEAD nor its origin/main — refresh it: git -C ../holger show HEAD:proto/{name} > proto/{name}");
}
}