aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/harness.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 23:49:56 +0000
committertv <tv@krebsco.de>2026-11-17 01:02:49 +0100
commitcd47b1fc79893507096d4b6b7e25f47ee8c7cdbb (patch)
treee553ded02d1c87f25ccc83e6859fa8186ba1c1c6 /src/federation/harness.rs
parentd8b8f01b08b31f5a10dad0a0d23727a8eabc5499 (diff)
federation: each attack table checked whole, its rows marked sim too
One check of an attack table (`harness::every_row_has_its_test`), for the federation's and the store's: every row has its test among the sources of its kind, unit tests or the simulations (`simtest::holding`), but for the rows whose tests wait for later; a row marked `—` has none; no test names a row that isn't there, nor two tests one row. The rows waiting: forks, the remakes, flooding, what a node, a client or a tool does that isn't built yet, and a rule for two checkpoints proposed at once.
Diffstat (limited to 'src/federation/harness.rs')
-rw-r--r--src/federation/harness.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/federation/harness.rs b/src/federation/harness.rs
index 42ee870..4baf049 100644
--- a/src/federation/harness.rs
+++ b/src/federation/harness.rs
@@ -259,3 +259,75 @@ impl Spec {
.bytes()
}
}
+
+/// Checks the attack table of `doc` (its section Attacks): every row has its test, named
+/// `{prefix}{row}`, among the sources of its kind, `unit` rows among `unit` and `sim`
+/// rows among `sim`, but for the rows `later`, whose tests come with later stages; a row
+/// marked `—` has none; and no test names a row that isn't there, nor two tests one row.
+pub(crate) fn every_row_has_its_test(
+ doc: &str,
+ prefix: &str,
+ unit: &[&str],
+ sim: &[&str],
+ later: &[u32],
+) {
+ let attacks = doc.split("\n## Attacks").nth(1).expect("an attack table");
+ let attacks = attacks.split("\n## ").next().unwrap_or(attacks);
+ let rows: std::collections::BTreeMap<u32, String> = attacks
+ .lines()
+ .filter_map(|line| {
+ let cells: Vec<&str> = line.split('|').map(str::trim).collect();
+ Some((cells.get(1)?.parse().ok()?, cells.get(4)?.to_string()))
+ })
+ .collect();
+ let tests = |sources: &[&str]| -> Vec<u32> {
+ sources
+ .iter()
+ .flat_map(|source| source.lines())
+ .filter_map(|line| {
+ let line = line.trim();
+ line.strip_prefix("async ")
+ .unwrap_or(line)
+ .strip_prefix("fn ")?
+ .strip_prefix(prefix)?
+ .split('(')
+ .next()?
+ .parse()
+ .ok()
+ })
+ .collect()
+ };
+ let (unit, sim) = (tests(unit), tests(sim));
+ let all: Vec<u32> = unit.iter().chain(&sim).copied().collect();
+ for n in &all {
+ assert!(rows.contains_key(n), "a test of row {n}, which isn't there");
+ assert_eq!(
+ all.iter().filter(|m| *m == n).count(),
+ 1,
+ "row {n} tested twice"
+ );
+ }
+ let mut missing = Vec::new();
+ for (n, kind) in &rows {
+ let none = kind == "—";
+ let tested = if kind.starts_with("unit") {
+ unit.contains(n)
+ } else if kind == "sim" {
+ sim.contains(n)
+ } else {
+ false
+ };
+ if later.contains(n) {
+ assert!(!all.contains(n), "row {n} has its test now");
+ assert!(!none, "row {n} asks for no test");
+ } else if none {
+ assert!(!all.contains(n), "row {n} asks for no test, and has one");
+ } else if !tested {
+ missing.push(*n);
+ }
+ }
+ assert!(
+ missing.is_empty(),
+ "rows without their test of their kind: {missing:?}"
+ );
+}