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.
155    pub fn wire_line_for_includes(&self, included: &[&str]) -> String {
156        let promoted: Vec<&str> = self
157            .not_examined
158            .iter()
159            .map(|(a, _)| *a)
160            .filter(|a| included.contains(a))
161            .collect();
162        self.wire_line_promoting(&promoted)
163    }
164
165    pub fn wire_line_promoting(&self, promoted: &[&str]) -> String {
166        let mut examined: Vec<&str> = self.examined.to_vec();
167        let mut advisory: Vec<&str> = Vec::new();
168        let mut not_examined: Vec<&str> = Vec::new();
169        for (a, _) in self.advisory {
170            if promoted.contains(a) {
171                examined.push(a);
172            } else {
173                advisory.push(a);
174            }
175        }
176        for (a, _) in self.not_examined {
177            if promoted.contains(a) {
178                examined.push(a);
179            } else {
180                not_examined.push(a);
181            }
182        }
183        format!(
184            "examined={}; advisory={}; not_examined={}",
185            examined.join(","),
186            advisory.join(","),
187            not_examined.join(",")
188        )
189    }
190}
191
192impl SurfaceCoverage {
193    /// The verdict declaration, when this row carries one; the
194    /// stamping sites use it so a surface can only stamp what its
195    /// registry row declares.
196    pub fn axis_coverage(&self) -> Option<&AxisCoverage> {
197        match &self.disposition {
198            CoverageDisposition::Verdict(c) => Some(c),
199            CoverageDisposition::NoVerdict(_) => None,
200        }
201    }
202}
203
204/// The health surface's coverage claim, shared by every consumer
205/// that renders a health report (the CLI command and the MCP
206/// server's composer): the axes
207/// whose findings the report treats as defects, so an empty defect
208/// statement reads as an all-clear exactly over them. Everything
209/// descriptive or advisory is excluded by name.
210pub const HEALTH_COVERAGE: AxisCoverage = AxisCoverage {
211    // The axes every health pass computes. The four include-gated
212    // verdict axes (`missing_required_outgoing`, `constraints`,
213    // `signals`, `integrity`) are filed under `not_examined` below and
214    // promoted into this set by `wire_line_for_includes` on the pass
215    // that included them: a default report does not walk them, and a
216    // coverage line that named them examined told a reader the verdict
217    // had answered for findings it never computed.
218    examined: &["dangling_links", "config", "mounts"],
219    // Every axis health renders (always, or on `--include`) without
220    // folding it into the defect verdict. `anchors` is promoted into
221    // the examined set for the pass that rendered it.
222    advisory: &[
223        (
224            "orphans",
225            "descriptive list; the defect verdict polices orphan stubs through the integrity findings",
226        ),
227        (
228            "stubs",
229            "descriptive list; the defect verdict polices orphan stubs through the integrity findings",
230        ),
231        (
232            "most_connected",
233            "descriptive ranking with no pass/fail semantics",
234        ),
235        (
236            "missing_fields",
237            "advisory count, never part of the defect verdict",
238        ),
239        (
240            "stale",
241            "advisory freshness, never part of the defect verdict",
242        ),
243        (
244            "tags",
245            "descriptive distribution with no pass/fail semantics",
246        ),
247        (
248            "labelling",
249            "advisory audit, never part of the defect verdict",
250        ),
251        (
252            "conformance",
253            "reported per entity beside the verdict, never folded into it",
254        ),
255        (
256            "anchors",
257            "drifted anchors stay advisory; the verify surfaces carry the drift statement",
258        ),
259        ("friction", "descriptive ledger counts"),
260        ("open_questions", "descriptive listing of open questions"),
261        (
262            "vital_signs",
263            "descriptive model-truth counts; the remodel skill holds the thresholds",
264        ),
265        (
266            "stale_derivations",
267            "advisory freshness of derived artifacts",
268        ),
269        (
270            "checks",
271            "check states are derived views; the verdicts in them belong to their recording callers",
272        ),
273        ("ledger", "descriptive view of the check ledger"),
274        (
275            "due",
276            "descriptive due brief: what is overdue or due soon by a schema-declared due axis, a reading never a verdict",
277        ),
278    ],
279    not_examined: &[
280        (
281            "projection",
282            "projection fidelity is answered by status and projection verify; the one class \
283             health carries from the findings stores, an entity's claim about an artifact it \
284             does not anchor (`UNANCHORED_MENTION`), rides as a warning and never as a verdict",
285        ),
286        ("missing_required_outgoing", INCLUDE_GATED),
287        ("constraints", INCLUDE_GATED),
288        ("signals", INCLUDE_GATED),
289        ("integrity", INCLUDE_GATED),
290    ],
291};
292
293/// The reason on a verdict axis a health pass computes only under
294/// `--include <axis>` (`--strict` includes each of them): outside such
295/// a pass the report never walked it, and the line says so; on the
296/// pass that included it, [`AxisCoverage::wire_line_for_includes`]
297/// names it examined.
298const INCLUDE_GATED: &str = "computed only on a pass that includes the axis (`--include <axis>`, \
299                             or `--strict`), which then examines it; a default report does not walk it";
300
301/// The overview surface's coverage claim, shared by every consumer
302/// that renders the composed overview (the CLI command and both MCP
303/// servers), and stamped into the composed frontmatter by
304/// `compose_overview` itself so the declaration and the output cannot
305/// diverge.
306pub const OVERVIEW_COVERAGE: AxisCoverage = AxisCoverage {
307    examined: &["mounts", "config"],
308    advisory: &[(
309        "dangling_links",
310        "rendered on request as a listing; the verdict over them is health's",
311    )],
312    not_examined: &[
313        ("orphans", OVERVIEW_SCOPE),
314        ("stubs", OVERVIEW_SCOPE),
315        ("most_connected", OVERVIEW_SCOPE),
316        ("missing_fields", OVERVIEW_SCOPE),
317        ("stale", OVERVIEW_SCOPE),
318        ("tags", OVERVIEW_SCOPE),
319        ("missing_required_outgoing", OVERVIEW_SCOPE),
320        ("constraints", OVERVIEW_SCOPE),
321        ("signals", OVERVIEW_SCOPE),
322        ("labelling", OVERVIEW_SCOPE),
323        ("conformance", OVERVIEW_SCOPE),
324        ("integrity", OVERVIEW_SCOPE),
325        ("anchors", OVERVIEW_SCOPE),
326        ("friction", OVERVIEW_SCOPE),
327        ("open_questions", OVERVIEW_SCOPE),
328        ("vital_signs", OVERVIEW_SCOPE),
329        ("due", OVERVIEW_SCOPE),
330        ("stale_derivations", OVERVIEW_SCOPE),
331        ("checks", OVERVIEW_SCOPE),
332        ("ledger", OVERVIEW_SCOPE),
333        ("projection", OVERVIEW_SCOPE),
334    ],
335};
336
337const OVERVIEW_SCOPE: &str = "overview is a descriptive composition; its only \
338     all-clear claim is that the roster it renders is complete and its mounts serve";
339
340/// Hold a registry against the axis vocabulary and a mechanically
341/// discovered surface roster. Returns one finding per defect; an
342/// empty result is the only clean outcome. Pure and total: callers
343/// in tests pass the live vocabulary and their own live walk,
344/// fixtures pass synthetic ones.
345///
346/// The findings, each mapped to the failure it refuses:
347/// - a discovered surface with no registry row (a surface landed
348///   without declaring),
349/// - a registry row no walk discovers (a stale declaration reading
350///   as coverage),
351/// - a duplicate row (two claims, no single truth),
352/// - an axis named by a declaration that the vocabulary does not
353///   carry (a stale axis reading as coverage),
354/// - an axis in the vocabulary that a verdict declaration neither
355///   examines, reports as advisory, nor excludes (a new axis met by
356///   silence: the clean verdict would cover it by omission),
357/// - an axis in more than one bucket (a contradiction),
358/// - an advisory, exclusion or no-verdict claim with an empty reason
359///   (a declaration that declares nothing).
360pub fn validate_coverage(
361    vocab: &[&str],
362    registry: &[SurfaceCoverage],
363    discovered: &[&str],
364) -> Vec<String> {
365    let mut findings = Vec::new();
366
367    for d in discovered {
368        if !registry.iter().any(|r| r.surface == *d) {
369            findings.push(format!(
370                "surface `{d}` is discoverable and has no coverage declaration: \
371                 declare its verdict axes, or declare why it emits no verdict"
372            ));
373        }
374    }
375
376    let mut seen: Vec<&str> = Vec::new();
377    for row in registry {
378        if seen.contains(&row.surface) {
379            findings.push(format!(
380                "surface `{}` is declared more than once",
381                row.surface
382            ));
383            continue;
384        }
385        seen.push(row.surface);
386
387        if !discovered.contains(&row.surface) {
388            findings.push(format!(
389                "declared surface `{}` is not discoverable: a stale declaration \
390                 reads as coverage, remove it or fix the walk",
391                row.surface
392            ));
393        }
394
395        match row.disposition {
396            CoverageDisposition::NoVerdict(reason) => {
397                if reason.trim().is_empty() {
398                    findings.push(format!(
399                        "surface `{}` declares no verdict without a reason",
400                        row.surface
401                    ));
402                }
403            }
404            CoverageDisposition::Verdict(cov) => {
405                let in_advisory = |axis: &str| cov.advisory.iter().any(|(a, _)| *a == axis);
406                let in_not_examined = |axis: &str| cov.not_examined.iter().any(|(a, _)| *a == axis);
407                for axis in cov.examined {
408                    if !vocab.contains(axis) {
409                        findings.push(format!(
410                            "surface `{}` examines axis `{axis}`, which the \
411                             vocabulary does not carry",
412                            row.surface
413                        ));
414                    }
415                    if in_advisory(axis) || in_not_examined(axis) {
416                        findings.push(format!(
417                            "surface `{}` both examines and excludes axis `{axis}`",
418                            row.surface
419                        ));
420                    }
421                }
422                for (bucket, rows) in [
423                    ("advisory", cov.advisory),
424                    ("not_examined", cov.not_examined),
425                ] {
426                    for (axis, reason) in rows {
427                        if !vocab.contains(axis) {
428                            findings.push(format!(
429                                "surface `{}` files axis `{axis}` as {bucket}, which the \
430                                 vocabulary does not carry",
431                                row.surface
432                            ));
433                        }
434                        if reason.trim().is_empty() {
435                            findings.push(format!(
436                                "surface `{}` files axis `{axis}` as {bucket} without a reason",
437                                row.surface
438                            ));
439                        }
440                    }
441                }
442                for (axis, _) in cov.advisory {
443                    if in_not_examined(axis) {
444                        findings.push(format!(
445                            "surface `{}` files axis `{axis}` as both advisory and not_examined",
446                            row.surface
447                        ));
448                    }
449                }
450                for axis in vocab {
451                    let examined = cov.examined.contains(axis);
452                    if !examined && !in_advisory(axis) && !in_not_examined(axis) {
453                        findings.push(format!(
454                            "surface `{}` declares nothing for axis `{axis}`: \
455                             its clean verdict would cover the axis by omission, \
456                             examine it, report it as advisory, or exclude it with a reason",
457                            row.surface
458                        ));
459                    }
460                }
461            }
462        }
463    }
464
465    findings
466}
467
468#[cfg(test)]
469mod tests {
470    use super::*;
471
472    const VOCAB: &[&str] = &["anchors", "mounts"];
473
474    fn full() -> SurfaceCoverage {
475        SurfaceCoverage {
476            surface: "verify",
477            disposition: CoverageDisposition::Verdict(AxisCoverage {
478                examined: &["anchors"],
479                advisory: &[],
480                not_examined: &[("mounts", "the roster surface answers for mounts")],
481            }),
482        }
483    }
484
485    fn ledger() -> SurfaceCoverage {
486        SurfaceCoverage {
487            surface: "check",
488            disposition: CoverageDisposition::NoVerdict(
489                "records the caller's verdict about the caller's own work",
490            ),
491        }
492    }
493
494    /// The complement: a registry that declares everything, over a
495    /// walk that finds exactly the declared surfaces, is clean, and
496    /// the only burden it carried was the declaration itself.
497    #[test]
498    fn complete_registry_is_clean() {
499        let findings = validate_coverage(VOCAB, &[full(), ledger()], &["verify", "check"]);
500        assert!(findings.is_empty(), "{findings:?}");
501    }
502
503    /// The gate red, fixture one: a surface whose clean verdict
504    /// covers an axis by omission. This reproduces the sweep's
505    /// condition shape independently of whether the sweep happened,
506    /// since the fixture is synthetic.
507    #[test]
508    fn clean_over_an_unexamined_axis_fails() {
509        let silent = SurfaceCoverage {
510            surface: "verify",
511            disposition: CoverageDisposition::Verdict(AxisCoverage {
512                examined: &["anchors"],
513                advisory: &[],
514                not_examined: &[],
515            }),
516        };
517        let findings = validate_coverage(VOCAB, &[silent, ledger()], &["verify", "check"]);
518        assert!(
519            findings.iter().any(|f| f.contains("`verify`")
520                && f.contains("`mounts`")
521                && f.contains("by omission")),
522            "{findings:?}"
523        );
524    }
525
526    /// The gate red, fixture two: an axis is introduced and an
527    /// existing declaration is not updated. This is the recurrence
528    /// case; a gate that passes here is a one-time sweep.
529    #[test]
530    fn axis_added_without_declaration_update_fails() {
531        let grown: &[&str] = &["anchors", "mounts", "fences"];
532        let findings = validate_coverage(grown, &[full(), ledger()], &["verify", "check"]);
533        assert!(
534            findings
535                .iter()
536                .any(|f| f.contains("`verify`") && f.contains("`fences`")),
537            "{findings:?}"
538        );
539    }
540
541    /// A surface that landed without any declaration fails.
542    #[test]
543    fn undeclared_surface_fails() {
544        let findings = validate_coverage(VOCAB, &[full(), ledger()], &["verify", "check", "dump"]);
545        assert!(
546            findings
547                .iter()
548                .any(|f| f.contains("`dump`") && f.contains("no coverage declaration")),
549            "{findings:?}"
550        );
551    }
552
553    /// A declaration whose surface departed fails rather than skips.
554    #[test]
555    fn stale_surface_declaration_fails() {
556        let findings = validate_coverage(VOCAB, &[full(), ledger()], &["check"]);
557        assert!(
558            findings
559                .iter()
560                .any(|f| f.contains("`verify`") && f.contains("not discoverable")),
561            "{findings:?}"
562        );
563    }
564
565    /// An axis dropped from the vocabulary turns the declarations
566    /// naming it into findings, so a stale axis cannot read as
567    /// coverage.
568    #[test]
569    fn stale_axis_in_declaration_fails() {
570        let shrunk: &[&str] = &["anchors"];
571        let findings = validate_coverage(shrunk, &[full(), ledger()], &["verify", "check"]);
572        assert!(
573            findings
574                .iter()
575                .any(|f| f.contains("`mounts`") && f.contains("does not carry")),
576            "{findings:?}"
577        );
578    }
579
580    /// Excluding an axis without a reason fails: an unexplained
581    /// exclusion is a silent drop with paperwork.
582    #[test]
583    fn exclusion_without_reason_fails() {
584        let bare = SurfaceCoverage {
585            surface: "verify",
586            disposition: CoverageDisposition::Verdict(AxisCoverage {
587                examined: &["anchors"],
588                advisory: &[],
589                not_examined: &[("mounts", "  ")],
590            }),
591        };
592        let findings = validate_coverage(VOCAB, &[bare, ledger()], &["verify", "check"]);
593        assert!(
594            findings.iter().any(|f| f.contains("without a reason")),
595            "{findings:?}"
596        );
597    }
598
599    /// Examining and excluding the same axis is a contradiction, not
600    /// a double assurance.
601    #[test]
602    fn examined_and_excluded_fails() {
603        let both = SurfaceCoverage {
604            surface: "verify",
605            disposition: CoverageDisposition::Verdict(AxisCoverage {
606                examined: &["anchors", "mounts"],
607                advisory: &[],
608                not_examined: &[("mounts", "also excluded")],
609            }),
610        };
611        let findings = validate_coverage(VOCAB, &[both, ledger()], &["verify", "check"]);
612        assert!(
613            findings
614                .iter()
615                .any(|f| f.contains("both examines and excludes")),
616            "{findings:?}"
617        );
618    }
619
620    /// Two rows for one surface fail: two claims, no single truth.
621    #[test]
622    fn duplicate_declaration_fails() {
623        let findings = validate_coverage(VOCAB, &[full(), full(), ledger()], &["verify", "check"]);
624        assert!(
625            findings
626                .iter()
627                .any(|f| f.contains("declared more than once")),
628            "{findings:?}"
629        );
630    }
631
632    /// An axis filed as both advisory and not examined is a
633    /// contradiction, not a double assurance.
634    #[test]
635    fn advisory_and_not_examined_fails() {
636        let both = SurfaceCoverage {
637            surface: "verify",
638            disposition: CoverageDisposition::Verdict(AxisCoverage {
639                examined: &["anchors"],
640                advisory: &[("mounts", "rendered beside the verdict")],
641                not_examined: &[("mounts", "the roster surface answers for mounts")],
642            }),
643        };
644        let findings = validate_coverage(VOCAB, &[both, ledger()], &["verify", "check"]);
645        assert!(
646            findings
647                .iter()
648                .any(|f| f.contains("both advisory and not_examined")),
649            "{findings:?}"
650        );
651    }
652
653    /// The wire line names all three buckets, and a promoted axis
654    /// leaves its bucket for the examined set.
655    #[test]
656    fn wire_line_names_three_buckets_and_promotes() {
657        let cov = AxisCoverage {
658            examined: &["mounts"],
659            advisory: &[("anchors", "rendered on request")],
660            not_examined: &[("projection", "another surface answers")],
661        };
662        assert_eq!(
663            cov.wire_line(),
664            "examined=mounts; advisory=anchors; not_examined=projection"
665        );
666        assert_eq!(
667            cov.wire_line_promoting(&["anchors"]),
668            "examined=mounts,anchors; advisory=; not_examined=projection"
669        );
670    }
671
672    /// The health declaration files every axis it renders on request
673    /// as advisory, every axis it computes on every pass as examined,
674    /// and the include-gated verdict axes as not examined until a pass
675    /// includes them: the bucket names say what the report did.
676    #[test]
677    fn health_declaration_buckets_follow_what_the_report_renders() {
678        let cov = HEALTH_COVERAGE;
679        const INCLUDE_GATED_VERDICT_AXES: &[&str] = &[
680            "missing_required_outgoing",
681            "constraints",
682            "signals",
683            "integrity",
684        ];
685        for key in HEALTH_INCLUDE_KEYS {
686            let examined = cov.examined.contains(key);
687            let advisory = cov.advisory.iter().any(|(a, _)| a == key);
688            let gated = cov.not_examined.iter().any(|(a, _)| a == key)
689                && INCLUDE_GATED_VERDICT_AXES.contains(key);
690            assert!(
691                examined || advisory || gated,
692                "health include `{key}` renders on request, so it is examined, advisory, \
693                 or a verdict axis examined on the pass that includes it"
694            );
695        }
696        let mut not_examined: Vec<&str> = cov.not_examined.iter().map(|(a, _)| *a).collect();
697        not_examined.sort_unstable();
698        assert_eq!(
699            not_examined,
700            vec![
701                "constraints",
702                "integrity",
703                "missing_required_outgoing",
704                "projection",
705                "signals"
706            ]
707        );
708    }
709
710    /// A default health pass names only the axes it computed; the pass
711    /// that includes a gated verdict axis names it examined, and an
712    /// included advisory axis stays advisory.
713    #[test]
714    fn health_wire_line_examines_gated_axes_only_when_included() {
715        let default_line = HEALTH_COVERAGE.wire_line_for_includes(&[]);
716        assert!(default_line.starts_with("examined=dangling_links,config,mounts;"));
717        assert!(
718            default_line.contains(
719                "not_examined=projection,missing_required_outgoing,constraints,signals,integrity"
720            ),
721            "{default_line}"
722        );
723        let strict_line = HEALTH_COVERAGE.wire_line_for_includes(&[
724            "integrity",
725            "anchors",
726            "stale",
727            "missing_required_outgoing",
728            "constraints",
729            "signals",
730        ]);
731        assert!(
732            strict_line.starts_with(
733                "examined=dangling_links,config,mounts,missing_required_outgoing,constraints,signals,integrity;"
734            ),
735            "{strict_line}"
736        );
737        assert!(
738            strict_line.ends_with("not_examined=projection"),
739            "{strict_line}"
740        );
741        let (_, rest) = strict_line.split_once("advisory=").unwrap();
742        assert!(
743            rest.contains("anchors") && rest.contains("stale"),
744            "{strict_line}"
745        );
746    }
747
748    /// The live vocabulary is the health roster plus the declared
749    /// extras, nothing more: composition, not a copy that can drift.
750    #[test]
751    fn vocabulary_composes_health_roster() {
752        let axes = verdict_axes();
753        for key in HEALTH_INCLUDE_KEYS {
754            assert!(axes.contains(key), "health include `{key}` missing");
755        }
756        for key in EXTRA_VERDICT_AXES {
757            assert!(axes.contains(key), "extra axis `{key}` missing");
758        }
759        assert_eq!(
760            axes.len(),
761            HEALTH_INCLUDE_KEYS.len() + EXTRA_VERDICT_AXES.len()
762        );
763    }
764}