Skip to main content

memstead_base/ops/
coverage.rs

1//! Axis-coverage declarations: no read surface reports `clean` over
2//! state it did not examine. Where it cannot examine, it says so.
3//!
4//! WHY: eight findings in one sweep shared a single shape, a surface
5//! emitting an all-clear that asserted less than it read as. Strict
6//! health promoted a hand-remembered subset of conditions, `status`
7//! defaulted to a clean rollup when nothing was declared, the
8//! conformance linter could not fail against a mem's own schema, and
9//! `workspace dump` silently dropped mounts whose config did not
10//! parse. Each instance was fixed; this module is the rule that keeps
11//! the class shut. A reader who is told `clean` stops looking, so a
12//! clean verdict must carry the set of axes it answers for.
13//!
14//! THE RULE, STATED ONCE: every surface a caller can read is declared
15//! in a per-consumer registry. A surface that emits a clean/ok
16//! verdict declares, for EVERY axis in the workspace vocabulary,
17//! either that its verdict examined the axis or that the axis is
18//! excluded with a stated reason. A surface that emits no verdict
19//! declares why not. The declaration states intent, which is exactly
20//! what cannot be derived from the code, since the defect the rule
21//! closes is surfaces doing less than they claim. Scoped statements
22//! are instances of this rule, not siblings of it: the anchor
23//! surface saying "reconciliation could not be performed" and the
24//! verify rollup's blind-spots list are the per-run refinement of
25//! the same obligation the static declaration carries per surface.
26//!
27//! The vocabulary reuses [`HEALTH_INCLUDE_KEYS`] rather than
28//! inventing a parallel axis roster: those keys are already the one
29//! shared statement of what the engine can examine, and only the
30//! verdict subjects no health include covers are added here.
31//!
32//! ENFORCEMENT: [`validate_coverage`] is pure and total over data,
33//! so the gate can be demonstrated red against synthetic fixtures
34//! (a surface clean over an unexamined axis, an axis added without a
35//! declaration update) without reconstructing any historical tree.
36//! Each consumer crate holds a test that walks its own live surface
37//! roster (the clap command tree, the MCP tool router), hands the
38//! walk's output to the validator, and fails on any finding. Those
39//! tests ride the ordinary `cargo nextest` legs of `run-tests.sh`,
40//! the same path every other permanent guard runs on. One surface is
41//! deliberately outside the rule: `check` records a caller's verdict
42//! about the caller's own work, so its registry entry is
43//! [`CoverageDisposition::NoVerdict`], not an examined-axes claim.
44
45use crate::ops::health::HEALTH_INCLUDE_KEYS;
46
47/// Verdict subjects no health include key covers. `projection` is the
48/// fidelity axis `status` and `projection verify` answer for;
49/// `mounts` is the roster axis `workspace dump` and `overview` answer
50/// for (which mounts exist, which serve nothing, and why).
51pub const EXTRA_VERDICT_AXES: &[&str] = &["projection", "mounts"];
52
53/// The workspace axis vocabulary: everything a clean verdict can
54/// answer for. Composed, never copied, so it cannot drift from the
55/// health roster.
56pub fn verdict_axes() -> Vec<&'static str> {
57    let mut axes: Vec<&'static str> = HEALTH_INCLUDE_KEYS.to_vec();
58    axes.extend_from_slice(EXTRA_VERDICT_AXES);
59    axes
60}
61
62/// One surface's static coverage claim: which axes its verdict
63/// answers for, which it reports beside the verdict without folding
64/// them in, and which lie outside its scope altogether. The three
65/// lists must jointly name every axis in the vocabulary; a blanket
66/// "everything else" clause is deliberately impossible, because it
67/// would swallow a newly introduced axis silently, and the one
68/// permanent property this module owes is that a new axis fails
69/// every declaration that has not met it.
70///
71/// The three buckets, as they read on the wire:
72/// - `examined`: the verdict answers for the axis; a finding there
73///   makes the verdict fail.
74/// - `advisory`: the surface renders the axis (always, or on request)
75///   beside the verdict and never folds it in; a reader sees the
76///   figures, the verdict says nothing about them. Filing these under
77///   "not examined" read, to every independent reader so far, as "not
78///   looked at", and a gate reading the word would refuse a report
79///   that had done the work.
80/// - `not_examined`: the surface does not look at the axis at all;
81///   the reason names the surface that answers for it.
82#[derive(Debug, Clone, Copy)]
83pub struct AxisCoverage {
84    /// Axes the surface's clean verdict actually examined.
85    pub examined: &'static [&'static str],
86    /// Axes the surface reports beside its verdict without folding
87    /// them in, each with the reason a reader needs.
88    pub advisory: &'static [(&'static str, &'static str)],
89    /// Axes the surface does not examine, each with the reason a
90    /// reader needs (typically: which surface answers for it instead).
91    pub not_examined: &'static [(&'static str, &'static str)],
92}
93
94/// What a declared surface claims about verdicts.
95#[derive(Debug, Clone, Copy)]
96pub enum CoverageDisposition {
97    /// The surface can emit a clean/ok verdict and declares its axes.
98    Verdict(AxisCoverage),
99    /// The surface emits no clean/ok verdict; the reason says why the
100    /// rule does not bind it (it returns data, it reports what a
101    /// mutation did, or its verdict belongs to the caller).
102    NoVerdict(&'static str),
103}
104
105/// One registry row: a surface name exactly as the consumer's own
106/// mechanical walk produces it, plus its disposition.
107#[derive(Debug, Clone, Copy)]
108pub struct SurfaceCoverage {
109    pub surface: &'static str,
110    pub disposition: CoverageDisposition,
111}
112
113impl AxisCoverage {
114    /// The examined set as it is stamped into surface output.
115    pub fn examined_wire(&self) -> Vec<&'static str> {
116        self.examined.to_vec()
117    }
118
119    /// The advisory axes as they are stamped into surface output:
120    /// `(axis, reason)` pairs, so a reader can see which axes the
121    /// surface reports beside its verdict without reading the source.
122    pub fn advisory_wire(&self) -> Vec<(&'static str, &'static str)> {
123        self.advisory.to_vec()
124    }
125
126    /// The unexamined axes as they are stamped into surface output:
127    /// `(axis, reason)` pairs, so a reader can see which axes the
128    /// verdict does not cover without reading the source.
129    pub fn not_examined_wire(&self) -> Vec<(&'static str, &'static str)> {
130        self.not_examined.to_vec()
131    }
132
133    /// The declaration as it is stamped into surface output: one
134    /// compact line naming both axis sets, the same form on JSON,
135    /// markdown, and frontmatter surfaces. Axis names only: the
136    /// per-axis exclusion reasons stay a registry fact the gate test
137    /// enforces, because stamping static prose into every response
138    /// would tax each call's token budget, and the reader's question
139    /// the stamp answers is WHICH axes the verdict covers.
140    pub fn wire_line(&self) -> String {
141        self.wire_line_promoting(&[])
142    }
143
144    /// The wire line with the named advisory or unexamined axes
145    /// promoted into the examined set — for a report that rendered an
146    /// opt-in axis this pass (`--include anchors`) and therefore did
147    /// examine it. An axis in neither list is ignored; the static
148    /// declaration is untouched.
149    /// The wire line for a pass that included the named axes: an
150    /// axis filed `not_examined` because a default pass never computes
151    /// it moves into the examined set when the pass included it (the
152    /// report walked it and its findings fail `--strict`). Advisory
153    /// axes stay advisory whatever was included: rendering an axis
154    /// beside the verdict is not folding it in (the C10 rule on
155    /// `anchors`, 2026-09-03).
156    pub fn wire_line_for_includes(&self, included: &[&str]) -> String {
157        let promoted: Vec<&str> = self
158            .not_examined
159            .iter()
160            .map(|(a, _)| *a)
161            .filter(|a| included.contains(a))
162            .collect();
163        self.wire_line_promoting(&promoted)
164    }
165
166    pub fn wire_line_promoting(&self, promoted: &[&str]) -> String {
167        let mut examined: Vec<&str> = self.examined.to_vec();
168        let mut advisory: Vec<&str> = Vec::new();
169        let mut not_examined: Vec<&str> = Vec::new();
170        for (a, _) in self.advisory {
171            if promoted.contains(a) {
172                examined.push(a);
173            } else {
174                advisory.push(a);
175            }
176        }
177        for (a, _) in self.not_examined {
178            if promoted.contains(a) {
179                examined.push(a);
180            } else {
181                not_examined.push(a);
182            }
183        }
184        format!(
185            "examined={}; advisory={}; not_examined={}",
186            examined.join(","),
187            advisory.join(","),
188            not_examined.join(",")
189        )
190    }
191}
192
193impl SurfaceCoverage {
194    /// The verdict declaration, when this row carries one; the
195    /// stamping sites use it so a surface can only stamp what its
196    /// registry row declares.
197    pub fn axis_coverage(&self) -> Option<&AxisCoverage> {
198        match &self.disposition {
199            CoverageDisposition::Verdict(c) => Some(c),
200            CoverageDisposition::NoVerdict(_) => None,
201        }
202    }
203}
204
205/// The health surface's coverage claim, shared by every consumer
206/// that renders a health report (the CLI command and the MCP
207/// server's composer): the axes
208/// whose findings the report treats as defects, so an empty defect
209/// statement reads as an all-clear exactly over them. Everything
210/// descriptive or advisory is excluded by name.
211pub const HEALTH_COVERAGE: AxisCoverage = AxisCoverage {
212    // The axes every health pass computes. The four include-gated
213    // verdict axes (`missing_required_outgoing`, `constraints`,
214    // `signals`, `integrity`) are filed under `not_examined` below and
215    // promoted into this set by `wire_line_for_includes` on the pass
216    // that included them: a default report does not walk them, and a
217    // coverage line that named them examined told a reader the verdict
218    // had answered for findings it never computed.
219    examined: &["dangling_links", "config", "mounts"],
220    // Every axis health renders (always, or on `--include`) without
221    // folding it into the defect verdict. `anchors` is promoted into
222    // the examined set for the pass that rendered it.
223    advisory: &[
224        (
225            "orphans",
226            "descriptive list; the defect verdict polices orphan stubs through the integrity findings",
227        ),
228        (
229            "stubs",
230            "descriptive list; the defect verdict polices orphan stubs through the integrity findings",
231        ),
232        (
233            "most_connected",
234            "descriptive ranking with no pass/fail semantics",
235        ),
236        (
237            "missing_fields",
238            "advisory count, never part of the defect verdict",
239        ),
240        (
241            "stale",
242            "advisory freshness, never part of the defect verdict",
243        ),
244        (
245            "tags",
246            "descriptive distribution with no pass/fail semantics",
247        ),
248        (
249            "labelling",
250            "advisory audit, never part of the defect verdict",
251        ),
252        (
253            "conformance",
254            "reported per entity beside the verdict, never folded into it",
255        ),
256        (
257            "anchors",
258            "drifted anchors stay advisory; the verify surfaces carry the drift statement",
259        ),
260        ("friction", "descriptive ledger counts"),
261        ("open_questions", "descriptive listing of open questions"),
262        (
263            "vital_signs",
264            "descriptive model-truth counts; the remodel skill holds the thresholds",
265        ),
266        (
267            "stale_derivations",
268            "advisory freshness of derived artifacts",
269        ),
270        (
271            "checks",
272            "check states are derived views; the verdicts in them belong to their recording callers",
273        ),
274        ("ledger", "descriptive view of the check ledger"),
275        (
276            "due",
277            "descriptive due brief: what is overdue or due soon by a schema-declared due axis, a reading never a verdict",
278        ),
279    ],
280    not_examined: &[
281        (
282            "projection",
283            "projection fidelity is answered by status and projection verify; the one class \
284             health carries from the findings stores, an entity's claim about an artifact it \
285             does not anchor (`UNANCHORED_MENTION`), rides as a warning and never as a verdict",
286        ),
287        ("missing_required_outgoing", INCLUDE_GATED),
288        ("constraints", INCLUDE_GATED),
289        ("signals", INCLUDE_GATED),
290        ("integrity", INCLUDE_GATED),
291    ],
292};
293
294/// The reason on a verdict axis a health pass computes only under
295/// `--include <axis>` (`--strict` includes each of them): outside such
296/// a pass the report never walked it, and the line says so; on the
297/// pass that included it, [`AxisCoverage::wire_line_for_includes`]
298/// names it examined.
299const INCLUDE_GATED: &str = "computed only on a pass that includes the axis (`--include <axis>`, \
300                             or `--strict`), which then examines it; a default report does not walk it";
301
302/// The overview surface's coverage claim, shared by every consumer
303/// that renders the composed overview (the CLI command and both MCP
304/// servers), and stamped into the composed frontmatter by
305/// `compose_overview` itself so the declaration and the output cannot
306/// diverge.
307pub const OVERVIEW_COVERAGE: AxisCoverage = AxisCoverage {
308    examined: &["mounts", "config"],
309    advisory: &[(
310        "dangling_links",
311        "rendered on request as a listing; the verdict over them is health's",
312    )],
313    not_examined: &[
314        ("orphans", OVERVIEW_SCOPE),
315        ("stubs", OVERVIEW_SCOPE),
316        ("most_connected", OVERVIEW_SCOPE),
317        ("missing_fields", OVERVIEW_SCOPE),
318        ("stale", OVERVIEW_SCOPE),
319        ("tags", OVERVIEW_SCOPE),
320        ("missing_required_outgoing", OVERVIEW_SCOPE),
321        ("constraints", OVERVIEW_SCOPE),
322        ("signals", OVERVIEW_SCOPE),
323        ("labelling", OVERVIEW_SCOPE),
324        ("conformance", OVERVIEW_SCOPE),
325        ("integrity", OVERVIEW_SCOPE),
326        ("anchors", OVERVIEW_SCOPE),
327        ("friction", OVERVIEW_SCOPE),
328        ("open_questions", OVERVIEW_SCOPE),
329        ("vital_signs", OVERVIEW_SCOPE),
330        ("due", OVERVIEW_SCOPE),
331        ("stale_derivations", OVERVIEW_SCOPE),
332        ("checks", OVERVIEW_SCOPE),
333        ("ledger", OVERVIEW_SCOPE),
334        ("projection", OVERVIEW_SCOPE),
335    ],
336};
337
338const OVERVIEW_SCOPE: &str = "overview is a descriptive composition; its only \
339     all-clear claim is that the roster it renders is complete and its mounts serve";
340
341/// Hold a registry against the axis vocabulary and a mechanically
342/// discovered surface roster. Returns one finding per defect; an
343/// empty result is the only clean outcome. Pure and total: callers
344/// in tests pass the live vocabulary and their own live walk,
345/// fixtures pass synthetic ones.
346///
347/// The findings, each mapped to the failure it refuses:
348/// - a discovered surface with no registry row (a surface landed
349///   without declaring),
350/// - a registry row no walk discovers (a stale declaration reading
351///   as coverage),
352/// - a duplicate row (two claims, no single truth),
353/// - an axis named by a declaration that the vocabulary does not
354///   carry (a stale axis reading as coverage),
355/// - an axis in the vocabulary that a verdict declaration neither
356///   examines, reports as advisory, nor excludes (a new axis met by
357///   silence: the clean verdict would cover it by omission),
358/// - an axis in more than one bucket (a contradiction),
359/// - an advisory, exclusion or no-verdict claim with an empty reason
360///   (a declaration that declares nothing).
361pub fn validate_coverage(
362    vocab: &[&str],
363    registry: &[SurfaceCoverage],
364    discovered: &[&str],
365) -> Vec<String> {
366    let mut findings = Vec::new();
367
368    for d in discovered {
369        if !registry.iter().any(|r| r.surface == *d) {
370            findings.push(format!(
371                "surface `{d}` is discoverable and has no coverage declaration: \
372                 declare its verdict axes, or declare why it emits no verdict"
373            ));
374        }
375    }
376
377    let mut seen: Vec<&str> = Vec::new();
378    for row in registry {
379        if seen.contains(&row.surface) {
380            findings.push(format!(
381                "surface `{}` is declared more than once",
382                row.surface
383            ));
384            continue;
385        }
386        seen.push(row.surface);
387
388        if !discovered.contains(&row.surface) {
389            findings.push(format!(
390                "declared surface `{}` is not discoverable: a stale declaration \
391                 reads as coverage, remove it or fix the walk",
392                row.surface
393            ));
394        }
395
396        match row.disposition {
397            CoverageDisposition::NoVerdict(reason) => {
398                if reason.trim().is_empty() {
399                    findings.push(format!(
400                        "surface `{}` declares no verdict without a reason",
401                        row.surface
402                    ));
403                }
404            }
405            CoverageDisposition::Verdict(cov) => {
406                let in_advisory = |axis: &str| cov.advisory.iter().any(|(a, _)| *a == axis);
407                let in_not_examined = |axis: &str| cov.not_examined.iter().any(|(a, _)| *a == axis);
408                for axis in cov.examined {
409                    if !vocab.contains(axis) {
410                        findings.push(format!(
411                            "surface `{}` examines axis `{axis}`, which the \
412                             vocabulary does not carry",
413                            row.surface
414                        ));
415                    }
416                    if in_advisory(axis) || in_not_examined(axis) {
417                        findings.push(format!(
418                            "surface `{}` both examines and excludes axis `{axis}`",
419                            row.surface
420                        ));
421                    }
422                }
423                for (bucket, rows) in [
424                    ("advisory", cov.advisory),
425                    ("not_examined", cov.not_examined),
426                ] {
427                    for (axis, reason) in rows {
428                        if !vocab.contains(axis) {
429                            findings.push(format!(
430                                "surface `{}` files axis `{axis}` as {bucket}, which the \
431                                 vocabulary does not carry",
432                                row.surface
433                            ));
434                        }
435                        if reason.trim().is_empty() {
436                            findings.push(format!(
437                                "surface `{}` files axis `{axis}` as {bucket} without a reason",
438                                row.surface
439                            ));
440                        }
441                    }
442                }
443                for (axis, _) in cov.advisory {
444                    if in_not_examined(axis) {
445                        findings.push(format!(
446                            "surface `{}` files axis `{axis}` as both advisory and not_examined",
447                            row.surface
448                        ));
449                    }
450                }
451                for axis in vocab {
452                    let examined = cov.examined.contains(axis);
453                    if !examined && !in_advisory(axis) && !in_not_examined(axis) {
454                        findings.push(format!(
455                            "surface `{}` declares nothing for axis `{axis}`: \
456                             its clean verdict would cover the axis by omission, \
457                             examine it, report it as advisory, or exclude it with a reason",
458                            row.surface
459                        ));
460                    }
461                }
462            }
463        }
464    }
465
466    findings
467}
468
469#[cfg(test)]
470mod tests {
471    use super::*;
472
473    const VOCAB: &[&str] = &["anchors", "mounts"];
474
475    fn full() -> SurfaceCoverage {
476        SurfaceCoverage {
477            surface: "verify",
478            disposition: CoverageDisposition::Verdict(AxisCoverage {
479                examined: &["anchors"],
480                advisory: &[],
481                not_examined: &[("mounts", "the roster surface answers for mounts")],
482            }),
483        }
484    }
485
486    fn ledger() -> SurfaceCoverage {
487        SurfaceCoverage {
488            surface: "check",
489            disposition: CoverageDisposition::NoVerdict(
490                "records the caller's verdict about the caller's own work",
491            ),
492        }
493    }
494
495    /// The complement: a registry that declares everything, over a
496    /// walk that finds exactly the declared surfaces, is clean, and
497    /// the only burden it carried was the declaration itself.
498    #[test]
499    fn complete_registry_is_clean() {
500        let findings = validate_coverage(VOCAB, &[full(), ledger()], &["verify", "check"]);
501        assert!(findings.is_empty(), "{findings:?}");
502    }
503
504    /// The gate red, fixture one: a surface whose clean verdict
505    /// covers an axis by omission. This reproduces the sweep's
506    /// condition shape independently of whether the sweep happened,
507    /// since the fixture is synthetic.
508    #[test]
509    fn clean_over_an_unexamined_axis_fails() {
510        let silent = SurfaceCoverage {
511            surface: "verify",
512            disposition: CoverageDisposition::Verdict(AxisCoverage {
513                examined: &["anchors"],
514                advisory: &[],
515                not_examined: &[],
516            }),
517        };
518        let findings = validate_coverage(VOCAB, &[silent, ledger()], &["verify", "check"]);
519        assert!(
520            findings.iter().any(|f| f.contains("`verify`")
521                && f.contains("`mounts`")
522                && f.contains("by omission")),
523            "{findings:?}"
524        );
525    }
526
527    /// The gate red, fixture two: an axis is introduced and an
528    /// existing declaration is not updated. This is the recurrence
529    /// case; a gate that passes here is a one-time sweep.
530    #[test]
531    fn axis_added_without_declaration_update_fails() {
532        let grown: &[&str] = &["anchors", "mounts", "fences"];
533        let findings = validate_coverage(grown, &[full(), ledger()], &["verify", "check"]);
534        assert!(
535            findings
536                .iter()
537                .any(|f| f.contains("`verify`") && f.contains("`fences`")),
538            "{findings:?}"
539        );
540    }
541
542    /// A surface that landed without any declaration fails.
543    #[test]
544    fn undeclared_surface_fails() {
545        let findings = validate_coverage(VOCAB, &[full(), ledger()], &["verify", "check", "dump"]);
546        assert!(
547            findings
548                .iter()
549                .any(|f| f.contains("`dump`") && f.contains("no coverage declaration")),
550            "{findings:?}"
551        );
552    }
553
554    /// A declaration whose surface departed fails rather than skips.
555    #[test]
556    fn stale_surface_declaration_fails() {
557        let findings = validate_coverage(VOCAB, &[full(), ledger()], &["check"]);
558        assert!(
559            findings
560                .iter()
561                .any(|f| f.contains("`verify`") && f.contains("not discoverable")),
562            "{findings:?}"
563        );
564    }
565
566    /// An axis dropped from the vocabulary turns the declarations
567    /// naming it into findings, so a stale axis cannot read as
568    /// coverage.
569    #[test]
570    fn stale_axis_in_declaration_fails() {
571        let shrunk: &[&str] = &["anchors"];
572        let findings = validate_coverage(shrunk, &[full(), ledger()], &["verify", "check"]);
573        assert!(
574            findings
575                .iter()
576                .any(|f| f.contains("`mounts`") && f.contains("does not carry")),
577            "{findings:?}"
578        );
579    }
580
581    /// Excluding an axis without a reason fails: an unexplained
582    /// exclusion is a silent drop with paperwork.
583    #[test]
584    fn exclusion_without_reason_fails() {
585        let bare = SurfaceCoverage {
586            surface: "verify",
587            disposition: CoverageDisposition::Verdict(AxisCoverage {
588                examined: &["anchors"],
589                advisory: &[],
590                not_examined: &[("mounts", "  ")],
591            }),
592        };
593        let findings = validate_coverage(VOCAB, &[bare, ledger()], &["verify", "check"]);
594        assert!(
595            findings.iter().any(|f| f.contains("without a reason")),
596            "{findings:?}"
597        );
598    }
599
600    /// Examining and excluding the same axis is a contradiction, not
601    /// a double assurance.
602    #[test]
603    fn examined_and_excluded_fails() {
604        let both = SurfaceCoverage {
605            surface: "verify",
606            disposition: CoverageDisposition::Verdict(AxisCoverage {
607                examined: &["anchors", "mounts"],
608                advisory: &[],
609                not_examined: &[("mounts", "also excluded")],
610            }),
611        };
612        let findings = validate_coverage(VOCAB, &[both, ledger()], &["verify", "check"]);
613        assert!(
614            findings
615                .iter()
616                .any(|f| f.contains("both examines and excludes")),
617            "{findings:?}"
618        );
619    }
620
621    /// Two rows for one surface fail: two claims, no single truth.
622    #[test]
623    fn duplicate_declaration_fails() {
624        let findings = validate_coverage(VOCAB, &[full(), full(), ledger()], &["verify", "check"]);
625        assert!(
626            findings
627                .iter()
628                .any(|f| f.contains("declared more than once")),
629            "{findings:?}"
630        );
631    }
632
633    /// An axis filed as both advisory and not examined is a
634    /// contradiction, not a double assurance.
635    #[test]
636    fn advisory_and_not_examined_fails() {
637        let both = SurfaceCoverage {
638            surface: "verify",
639            disposition: CoverageDisposition::Verdict(AxisCoverage {
640                examined: &["anchors"],
641                advisory: &[("mounts", "rendered beside the verdict")],
642                not_examined: &[("mounts", "the roster surface answers for mounts")],
643            }),
644        };
645        let findings = validate_coverage(VOCAB, &[both, ledger()], &["verify", "check"]);
646        assert!(
647            findings
648                .iter()
649                .any(|f| f.contains("both advisory and not_examined")),
650            "{findings:?}"
651        );
652    }
653
654    /// The wire line names all three buckets, and a promoted axis
655    /// leaves its bucket for the examined set.
656    #[test]
657    fn wire_line_names_three_buckets_and_promotes() {
658        let cov = AxisCoverage {
659            examined: &["mounts"],
660            advisory: &[("anchors", "rendered on request")],
661            not_examined: &[("projection", "another surface answers")],
662        };
663        assert_eq!(
664            cov.wire_line(),
665            "examined=mounts; advisory=anchors; not_examined=projection"
666        );
667        assert_eq!(
668            cov.wire_line_promoting(&["anchors"]),
669            "examined=mounts,anchors; advisory=; not_examined=projection"
670        );
671    }
672
673    /// The health declaration files every axis it renders on request
674    /// as advisory, every axis it computes on every pass as examined,
675    /// and the include-gated verdict axes as not examined until a pass
676    /// includes them: the bucket names say what the report did.
677    #[test]
678    fn health_declaration_buckets_follow_what_the_report_renders() {
679        let cov = HEALTH_COVERAGE;
680        const INCLUDE_GATED_VERDICT_AXES: &[&str] = &[
681            "missing_required_outgoing",
682            "constraints",
683            "signals",
684            "integrity",
685        ];
686        for key in HEALTH_INCLUDE_KEYS {
687            let examined = cov.examined.contains(key);
688            let advisory = cov.advisory.iter().any(|(a, _)| a == key);
689            let gated = cov.not_examined.iter().any(|(a, _)| a == key)
690                && INCLUDE_GATED_VERDICT_AXES.contains(key);
691            assert!(
692                examined || advisory || gated,
693                "health include `{key}` renders on request, so it is examined, advisory, \
694                 or a verdict axis examined on the pass that includes it"
695            );
696        }
697        let mut not_examined: Vec<&str> = cov.not_examined.iter().map(|(a, _)| *a).collect();
698        not_examined.sort_unstable();
699        assert_eq!(
700            not_examined,
701            vec![
702                "constraints",
703                "integrity",
704                "missing_required_outgoing",
705                "projection",
706                "signals"
707            ]
708        );
709    }
710
711    /// A default health pass names only the axes it computed; the pass
712    /// that includes a gated verdict axis names it examined, and an
713    /// included advisory axis stays advisory.
714    #[test]
715    fn health_wire_line_examines_gated_axes_only_when_included() {
716        let default_line = HEALTH_COVERAGE.wire_line_for_includes(&[]);
717        assert!(default_line.starts_with("examined=dangling_links,config,mounts;"));
718        assert!(
719            default_line.contains(
720                "not_examined=projection,missing_required_outgoing,constraints,signals,integrity"
721            ),
722            "{default_line}"
723        );
724        let strict_line = HEALTH_COVERAGE.wire_line_for_includes(&[
725            "integrity",
726            "anchors",
727            "stale",
728            "missing_required_outgoing",
729            "constraints",
730            "signals",
731        ]);
732        assert!(
733            strict_line.starts_with(
734                "examined=dangling_links,config,mounts,missing_required_outgoing,constraints,signals,integrity;"
735            ),
736            "{strict_line}"
737        );
738        assert!(
739            strict_line.ends_with("not_examined=projection"),
740            "{strict_line}"
741        );
742        let (_, rest) = strict_line.split_once("advisory=").unwrap();
743        assert!(
744            rest.contains("anchors") && rest.contains("stale"),
745            "{strict_line}"
746        );
747    }
748
749    /// The live vocabulary is the health roster plus the declared
750    /// extras, nothing more: composition, not a copy that can drift.
751    #[test]
752    fn vocabulary_composes_health_roster() {
753        let axes = verdict_axes();
754        for key in HEALTH_INCLUDE_KEYS {
755            assert!(axes.contains(key), "health include `{key}` missing");
756        }
757        for key in EXTRA_VERDICT_AXES {
758            assert!(axes.contains(key), "extra axis `{key}` missing");
759        }
760        assert_eq!(
761            axes.len(),
762            HEALTH_INCLUDE_KEYS.len() + EXTRA_VERDICT_AXES.len()
763        );
764    }
765}