//! Typed config source provenance.
//!
//! `ConfigSource` catalogs the *kind* of every layer in a [`crate::ProviderChain`]
//! — defaults, env vars, files — so consumers can answer "where did this
//! value come from?" without parsing logs or re-walking discovery. Every
//! `with_*` builder on `ProviderChain` pushes a `ConfigSource`; the chain
//! exposes them in merge order (lowest priority first).
//!
//! The variants are `#[non_exhaustive]` so future additions (HTTP, Vault,
//! `ConfigMap`, etc.) can land without breaking consumers that match.
use std::fmt;
use std::panic::Location;
use std::path::{Path, PathBuf};
use std::str::FromStr;
/// A single layer in a config provider chain.
///
/// Variants are emitted in merge order (lowest priority first, highest
/// priority last). The closed enum makes the universe of source kinds
/// structural: a misspelled or fabricated source cannot exist.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ConfigSource {
/// Serde-serialized defaults injected via
/// [`crate::ProviderChain::with_defaults`].
Defaults,
/// Environment variables under the given prefix
/// (e.g. `"MYAPP_"`). Empty prefix means no namespace.
Env(String),
/// A config file on disk. The format is auto-detected from the
/// extension by [`crate::ProviderChain::with_file`].
File(PathBuf),
}
impl ConfigSource {
/// Returns the file path if this source is a [`ConfigSource::File`].
#[must_use]
pub fn as_path(&self) -> Option<&Path> {
match self {
Self::File(p) => Some(p.as_path()),
_ => None,
}
}
/// Returns the env-var prefix if this source is a [`ConfigSource::Env`].
#[must_use]
pub fn as_env_prefix(&self) -> Option<&str> {
match self {
Self::Env(prefix) => Some(prefix.as_str()),
_ => None,
}
}
/// Returns `true` for [`ConfigSource::File`].
#[must_use]
pub fn is_file(&self) -> bool {
matches!(self, Self::File(_))
}
/// Returns `true` for [`ConfigSource::Env`].
#[must_use]
pub fn is_env(&self) -> bool {
matches!(self, Self::Env(_))
}
/// Returns `true` for [`ConfigSource::Defaults`].
#[must_use]
pub fn is_defaults(&self) -> bool {
matches!(self, Self::Defaults)
}
/// Data-free discriminant of this [`ConfigSource`]: the kind of
/// layer ([`ConfigSourceKind::Defaults`] / [`ConfigSourceKind::Env`]
/// / [`ConfigSourceKind::File`]) independent of its specific path
/// or prefix.
///
/// One source of truth for the kind partition over [`ConfigSource`]:
/// observers that need only the layer-kind axis (filtering a chain,
/// hashing a layer's class, comparing against
/// [`crate::AttributionRule::layer_kind`]) match on this closed
/// enum instead of matching three [`Self::is_defaults`] /
/// [`Self::is_env`] / [`Self::is_file`] booleans together.
///
/// Pairs with [`crate::AttributionRule::layer_kind`] under the
/// invariant `attr.rule.layer_kind() == attr.source.kind()` for
/// every [`crate::FailingSourceAttribution`] the resolver
/// produces — pinned by
/// `attribution_rule_layer_kind_agrees_with_source_kind` in
/// `error.rs`. Without the kind primitive this contract was
/// implicit in the rule names; lifting it makes "the rule and the
/// source agree on layer kind" a structural law.
///
/// `Copy + Eq + Hash + #[non_exhaustive]`, allocation-free,
/// trait-bounds parity with the sibling typescape primitives
/// ([`crate::AttributionRule`], [`crate::AttributionConfidence`],
/// [`FigmentSourceTag`], [`FigmentNameTag`]).
#[must_use]
pub fn kind(&self) -> ConfigSourceKind {
match self {
Self::Defaults => ConfigSourceKind::Defaults,
Self::Env(_) => ConfigSourceKind::Env,
Self::File(_) => ConfigSourceKind::File,
}
}
/// The [`crate::discovery::Format`] declared by this source's file
/// extension, if this is a [`Self::File`] with a recognized extension.
///
/// Returns `None` for [`Self::Defaults`] / [`Self::Env`] sources. A
/// `File` whose extension is unrecognized or absent also yields `None`
/// — [`crate::ProviderChain::with_file`] parses such files with the
/// conservative TOML fallback, so a `None` on a `File` source means
/// "the extension did not declare a format", not "no file". Use
/// [`Self::is_file`] / [`Self::as_path`] to distinguish.
///
/// Routes through [`crate::discovery::Format::from_path`], the single
/// `(path → Format)` detection site that `with_file` also uses, so the
/// recorded provenance chain reports exactly the format the loader
/// detected — a consumer reading "which format parsed this layer?" off
/// the chain never re-derives the extension triple, and reload (which
/// replays this chain) and the original load agree on format by
/// construction.
#[must_use]
pub fn file_format(&self) -> Option<crate::discovery::Format> {
match self {
Self::File(path) => crate::discovery::Format::from_path(path),
_ => None,
}
}
/// The [`EnvMetadataTagKind`] declared by this source's recorded env
/// prefix shape, if this is a [`Self::Env`] layer.
///
/// Returns `Some(EnvMetadataTagKind::Bare)` for [`Self::Env`] with an
/// empty prefix (the layer figment routes through
/// [`figment::providers::Env::raw`]-shape emission), and
/// `Some(EnvMetadataTagKind::Prefixed)` for [`Self::Env`] with any
/// non-empty prefix (the layer figment routes through
/// [`figment::providers::Env::prefixed`]-shape emission). Returns
/// `None` for [`Self::Defaults`] / [`Self::File`] sources — those
/// layers carry no env-prefix shape at all.
///
/// The chain-side projection on the env-name sub-axis: pointwise
/// peer of the figment-side [`EnvMetadataTag::kind`] projection that
/// reaches the same [`EnvMetadataTagKind`] axis from the parsed
/// `figment::Metadata::name`. The two surfaces converge on one kind
/// axis by construction — given the same `prefix`, the chain entry
/// `ConfigSource::Env(prefix.into()).env_prefix_kind()` agrees with
/// `ConfigSource::strip_env_metadata_name(&ConfigSource::env_metadata_name(prefix))
/// .map(EnvMetadataTag::kind)` — pinned by
/// `env_prefix_kind_agrees_with_figment_env_metadata_tag_kind` so a
/// future divergence (e.g. figment growing a `Glob` env shape that
/// [`Self::strip_env_metadata_name`] recognizes but the chain
/// projection does not) surfaces at the boundary.
///
/// The partial projection composed by
/// [`ConfigSourceChain::env_prefix_kind_histogram`] to lift the
/// (chain → `EnvMetadataTagKind`) tally over the env-prefix-presence
/// axis — peer to [`Self::file_format`] on the file-format axis and
/// [`Self::kind`] on the layer-kind axis. Together the three
/// projections close the natural per-cell axes of the chain entry:
/// every [`ConfigSource`] carries a total [`ConfigSourceKind`]
/// discriminant ([`Self::kind`]) and at most one of the two partial
/// sub-axis projections ([`Self::file_format`] on `File` layers with
/// recognized extensions, [`Self::env_prefix_kind`] on `Env` layers
/// regardless of prefix shape) — a structural partition the trait-
/// default histograms now expose as three aggregate projections.
#[must_use]
pub fn env_prefix_kind(&self) -> Option<EnvMetadataTagKind> {
match self {
Self::Env(prefix) if prefix.is_empty() => Some(EnvMetadataTagKind::Bare),
Self::Env(_) => Some(EnvMetadataTagKind::Prefixed),
_ => None,
}
}
/// Canonical `figment::Metadata::name` shape emitted by
/// [`figment::providers::Env`]: `` `PREFIX` environment variable(s) ``
/// for prefixed providers, `"environment variable(s)"` for raw env
/// (no prefix). Mirrors figment's `Env::metadata` impl one-to-one,
/// including the prefix-uppercasing discipline.
///
/// Empty `prefix` yields the bare shape; non-empty `prefix` yields
/// the backtick-wrapped form with the prefix uppercased to match
/// figment's emission.
///
/// One source of truth for the env-provider metadata-name shape on
/// the shikumi side: providers (figment) emit it, the
/// failing-source resolver inverts it via [`Self::strip_env_metadata_name`],
/// and tests round-trip both directions through one definition.
#[must_use]
pub fn env_metadata_name(prefix: &str) -> String {
if prefix.is_empty() {
"environment variable(s)".to_owned()
} else {
format!("`{}` environment variable(s)", prefix.to_ascii_uppercase())
}
}
/// Inverse of [`Self::env_metadata_name`]: recognize a
/// `figment::Metadata::name` as a `figment::providers::Env`-shaped
/// tag and recover the (uppercased) prefix when present.
///
/// Returns:
/// - `Some(EnvMetadataTag::Prefixed(prefix))` for
/// `` `PREFIX` environment variable(s) ``. The returned slice is
/// borrowed into `name` (no allocation) and carries figment's
/// uppercased prefix verbatim — callers matching against a
/// recorded [`ConfigSource::Env`] must compare with
/// [`str::eq_ignore_ascii_case`] since users may pass mixed-case
/// prefixes to [`crate::ProviderChain::with_env`].
/// - `Some(EnvMetadataTag::Bare)` for `"environment variable(s)"`
/// (no prefix; figment's `Env::raw()` shape).
/// - `None` for any other metadata name (file-path tags from
/// figment's YAML/TOML providers, shikumi-built provider tags
/// recognized by [`crate::Format::strip_metadata_name`], unrelated
/// names, or the empty string).
///
/// Used by [`crate::ShikumiError::failing_source`] to map figment
/// per-value metadata back to a [`ConfigSource::Env`] entry in the
/// recorded chain without re-implementing the figment-side shape.
#[must_use]
pub fn strip_env_metadata_name(name: &str) -> Option<EnvMetadataTag<'_>> {
if !name.contains("environment variable") {
return None;
}
if let Some(rest) = name.strip_prefix('`')
&& let Some(end) = rest.find('`')
{
return Some(EnvMetadataTag::Prefixed(&rest[..end]));
}
Some(EnvMetadataTag::Bare)
}
}
/// Data-free discriminant of [`ConfigSource`]: the kind of layer
/// independent of its inner path or prefix.
///
/// Closed three-way partition over the [`ConfigSource`] variant space,
/// returned by [`ConfigSource::kind`]. The enum exists so consumers
/// that care only about the kind axis (chain filters, layer-class
/// hashes, the (rule × layer-kind) attribution invariant) match on one
/// closed enum instead of matching three
/// ([`ConfigSource::is_defaults`] / [`ConfigSource::is_env`] /
/// [`ConfigSource::is_file`]) booleans together.
///
/// Paired with [`crate::AttributionRule::layer_kind`] under the
/// invariant `attr.rule.layer_kind() == attr.source.kind()` for every
/// [`crate::FailingSourceAttribution`] the resolver produces. Adding a
/// future [`ConfigSource`] variant (e.g. `Http(_)`, `Vault(_)`,
/// `ConfigMap(_)`) means adding one [`ConfigSourceKind`] variant in
/// lockstep — the exhaustive [`ConfigSource::kind`] match forces the
/// assignment at compile time, and any new [`crate::AttributionRule`]
/// that attributes to the new layer must declare the same kind in its
/// [`crate::AttributionRule::layer_kind`] arm.
///
/// `Copy + Eq + Hash + #[non_exhaustive]`, allocation-free,
/// trait-bounds parity with the sibling typescape primitives
/// ([`crate::AttributionRule`], [`crate::AttributionConfidence`],
/// [`FigmentSourceTag`], [`FigmentNameTag`], [`EnvMetadataTag`]).
///
/// **Trait surface** — alongside the canonical
/// `Debug + Clone + Copy + PartialEq + Eq + Hash` set, the derive also
/// includes [`Ord`] + [`PartialOrd`]. The total order is the
/// declaration-order lex over [`Self::ALL`]
/// (`Defaults < Env < File`), so a
/// [`BTreeMap<ConfigSourceKind, T>`][std::collections::BTreeMap] keyed
/// on the layer-kind axis (per-kind attribution histograms, per-kind
/// failure-rate dashboards, attestation manifests recording the layer-
/// kind cardinality mix of a recorded chain) emits rows in declaration
/// order deterministically without a hand-rolled comparator at the
/// renderer. Idiom-peer of the [`Ord`] derive on
/// [`crate::FormatProvenance`] (commit `2c7654c`), [`crate::Format`]
/// (commit `b56b121`), and the typed-cube classifiers
/// ([`crate::ModalityClass`], [`crate::PartitionFace`], …); pinned by
/// [`tests::config_source_kind_ord_matches_all_declaration_order`].
///
/// **Canonical-string surface** — [`fmt::Display`] /
/// [`std::str::FromStr`] round-trip through the canonical operator-
/// facing lowercase label [`Self::as_str`] returns (`"defaults"` /
/// `"env"` / `"file"`); `FromStr` lowers through the trait-default
/// [`crate::ClosedAxisLabel::from_canonical_str`] parse and inherits
/// ASCII case-insensitivity. Pinned by
/// [`tests::config_source_kind_display_matches_as_str`] and
/// [`tests::config_source_kind_from_str_round_trips_over_every_variant`].
///
/// **Serde surface** — [`serde::Serialize`] / [`serde::Deserialize`]
/// are the canonical idiom-peer of the ([`fmt::Display`],
/// [`std::str::FromStr`]) pair. Serialize emits the canonical
/// lowercase label through [`serde::Serializer::collect_str`];
/// Deserialize lowers through [`<Self as FromStr>::from_str`],
/// inheriting the trait-default case-insensitivity. An attestation
/// manifest field recording which layer-kind originated a failing
/// attribution, a structured-log payload tagging the layer-kind of a
/// chain entry, or a consumer struct holding a [`ConfigSourceKind`]
/// under `#[derive(Serialize, Deserialize)]` round-trips through the
/// canonical label without a consumer-side rename helper. Pinned by
/// [`tests::config_source_kind_serde_yaml_round_trips_over_every_variant`],
/// [`tests::config_source_kind_serde_json_round_trips_over_every_variant`],
/// [`tests::config_source_kind_serde_yaml_is_case_insensitive`], and
/// [`tests::config_source_kind_serde_yaml_unknown_kind_error_carries_label_verbatim`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
#[non_exhaustive]
pub enum ConfigSourceKind {
/// Maps to [`ConfigSource::Defaults`].
Defaults,
/// Maps to [`ConfigSource::Env`] regardless of prefix value.
Env,
/// Maps to [`ConfigSource::File`] regardless of path value.
File,
}
impl ConfigSourceKind {
/// Every [`ConfigSourceKind`] variant, in declaration order
/// ([`Self::Defaults`], [`Self::Env`], [`Self::File`]).
///
/// The closed list of layer kinds shikumi recognizes. Iterate to
/// enumerate the layer-kind space without listing variants by hand
/// at every consumer site — e.g. dashboards initializing per-kind
/// chain counters, attestation manifests recording the layer-kind
/// space's cardinality, tests asserting cube-coverage over the
/// orthogonal `(axis × layer_kind × confidence)` coordinate space
/// in [`crate::AttributionRule::from_coordinates`].
///
/// One source of truth for the layer-kind enumeration on the
/// [`ConfigSourceKind`] axis: peer to [`crate::Format::ALL`] on the
/// [`crate::Format`] axis, [`crate::ShikumiErrorKind::ALL`] on the
/// kind axis, and [`crate::AttributionRule::ALL`] on the rule axis
/// — the same typescape discipline applied across the closed-enum
/// primitive set. Before this constant, the layer-kind enumeration
/// was inlined as a `[File, Env, Defaults]` array literal at sites
/// that needed to iterate (the cube-coverage loop in
/// `attribution_rule_from_coordinates_returns_none_for_unrecognized_cells`,
/// the trait-bounds parity check in
/// `config_source_kind_is_copy_and_hashable`); each duplicated
/// literal had to be manually kept in lockstep with the enum's
/// variant set.
///
/// Adding a new variant to [`Self`] (e.g. a future `Http`, `Vault`,
/// or `ConfigMap` layer kind paired with a new
/// [`ConfigSource`] variant) means extending this slice in lockstep
/// with the variant itself. The compiler enforces nothing here
/// directly, so the
/// `config_source_kind_all_covers_every_constructible_variant` test
/// pins the contract by asserting that every kind produced by
/// [`ConfigSource::kind`] over the canonical sample table appears
/// in [`Self::ALL`], and the `config_source_kind_all_has_no_duplicates`
/// test pins that the constant is a set (no double-listed variant).
/// Together they pin the constant to the variant space the
/// typescape recognizes.
pub const ALL: &'static [Self] = &[Self::Defaults, Self::Env, Self::File];
/// Canonical operator-facing lowercase name of the layer kind —
/// `"defaults"`, `"env"`, or `"file"`.
///
/// The single source of truth for the layer-kind label strings on
/// the [`ConfigSourceKind`] axis. Inherent mirror of the
/// [`crate::ClosedAxisLabel`] trait method; the trait impl
/// delegates here so the canonical names live at one site instead
/// of being re-stated at every operator-facing surface (a future
/// structured-log field naming the failing layer's class, a CLI
/// flag filtering attributions by layer kind, an attestation
/// manifest recording the layer-kind histogram of loaded values).
/// The strings match the variant identifiers in ASCII-lowercase
/// form — the same form an operator would type into an env var or
/// CLI flag.
///
/// Pairs with [`crate::ClosedAxisLabel::from_canonical_str`] via
/// the trait-default linear-scan parse; the round-trip law
/// `Self::from_canonical_str(v.as_str()) == Some(v)` is pinned for
/// every variant uniformly by the trait-uniform
/// `closed_axis_label_round_trips_for_every_implementor` test in
/// `cube::tests`. The concrete-position pin at
/// `config_source_kind_as_str_yields_canonical_lowercase_names`
/// holds the literal strings stable so a future rename
/// (e.g. capitalizing `"Env"`, prefixing `"layer-env"`) fails at
/// that site before drifting through the round-trip law.
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Defaults => "defaults",
Self::Env => "env",
Self::File => "file",
}
}
}
impl crate::ClosedAxis for ConfigSourceKind {
const ALL: &'static [Self] = Self::ALL;
}
impl crate::ClosedAxisLabel for ConfigSourceKind {
fn as_str(self) -> &'static str {
Self::as_str(self)
}
}
// The canonical (Display, FromStr, Serialize, Deserialize) string-surface
// quartet on the layer-kind closed-enum, lifted to one macro after the
// 16+ hand-rolled idiom-peers preceding this commit (WatchEventClass at
// `94f8a8b`, ShikumiErrorKind at `4b53792`, DiffLineKind at `74ee853`).
// See `closed_axis_label_string_surface!` in `crate::macros` for the
// contract; behavior is byte-identical to the hand-rolled impls the
// macro replaces — the verbatim-label `Parse` error body, the case-
// insensitive `from_canonical_str` lowering, the `collect_str`-based
// serde emission, and the visitor's `expecting` message all match the
// prior surface pointwise. Pinned by
// `tests::config_source_kind_display_matches_as_str`,
// `tests::config_source_kind_from_str_*`, and
// `tests::config_source_kind_serde_yaml_*`.
closed_axis_label_string_surface! {
type = ConfigSourceKind,
parse_error = "unknown config source kind",
expecting = "a canonical ConfigSourceKind lowercase label \
(`defaults`, `env`, `file`; case-insensitive)",
}
/// Chain-level provenance queries over a recorded [`ConfigSource`] chain.
///
/// The recorded chain — the `&[ConfigSource]` returned by
/// [`crate::ConfigStore::sources`] / [`crate::ProviderChain::sources`] and
/// replayed verbatim on every [`crate::ConfigStore::reload`] — is the
/// executable recipe that built a store. This trait turns "which layer in
/// the recipe …?" questions into named queries over the slice, so the
/// answer is read off the typed provenance rather than re-derived by an
/// open-coded `iter().find` / `iter().filter` at every consumer.
///
/// One source of truth for the chain-walk discipline: the failing-source
/// resolver behind [`crate::ShikumiError::failing_source`] previously
/// open-coded "find the [`ConfigSource::File`] whose path equals P" twice
/// (once per file-attribution rule), "the sole layer of kind K" twice
/// (the env- and defaults-uniqueness rules), and "the [`ConfigSource::Env`]
/// layer whose prefix matches P case-insensitively" once
/// (the env-by-prefix rule); all five collapse to one
/// [`Self::find_file`] / [`Self::unique_of_kind`] / [`Self::find_env_by_prefix`]
/// site here. Future consumers reading the recipe — an attestation
/// manifest grouping layers by kind, a diagnostic dump locating the file
/// layer behind a value, a chain-diff that needs to match an env layer
/// across reloads, a new uniqueness-keyed attribution rule for a future
/// [`ConfigSource`] variant — key on these queries instead of re-walking
/// the slice.
///
/// Implemented for `[ConfigSource]`, so it applies to any `&[ConfigSource]`
/// (a borrowed `Vec`, a stored chain slice) by deref.
pub trait ConfigSourceChain {
/// The first [`ConfigSource::File`] entry whose path equals `path`,
/// or `None` if no file layer in the chain was loaded from `path`.
///
/// Matches only [`ConfigSource::File`] layers — [`ConfigSource::Env`]
/// and [`ConfigSource::Defaults`] carry no path and never match. The
/// comparison is exact-path (per [`ConfigSource::as_path`]); it does
/// not canonicalize, so a caller comparing against a discovery result
/// should pass the same path shape the chain recorded.
fn find_file(&self, path: &Path) -> Option<&ConfigSource>;
/// The sole chain entry whose [`ConfigSource::kind`] equals `kind`,
/// or `None` if the chain holds zero or more than one such layer.
///
/// Returns `Some` only on a *unique* match: this is the
/// "exactly one layer of this kind" query the failing-source resolver
/// uses to attribute an unprefixed env value to the chain's sole
/// [`ConfigSourceKind::Env`] layer, or a code-sourced value to its
/// sole [`ConfigSourceKind::Defaults`] layer. Keyed on the typed
/// [`ConfigSourceKind`] discriminant, so a future variant participates
/// without touching this method.
fn unique_of_kind(&self, kind: ConfigSourceKind) -> Option<&ConfigSource>;
/// The first [`ConfigSource::Env`] entry whose recorded prefix equals
/// `prefix` under ASCII-case-insensitive comparison, or `None` if no
/// env layer in the chain carries that prefix.
///
/// Matches only [`ConfigSource::Env`] layers — [`ConfigSource::File`]
/// and [`ConfigSource::Defaults`] carry no prefix and never match.
/// The comparison is [`str::eq_ignore_ascii_case`] rather than
/// strict equality because figment uppercases the prefix when
/// emitting [`figment::Metadata::name`] (see
/// [`ConfigSource::env_metadata_name`]) while users may pass any
/// case to [`crate::ProviderChain::with_env`]; a strict comparison
/// would silently drop legitimate matches when the user-supplied
/// prefix and figment's emitted form disagree on case.
///
/// The third chain-level provenance query peer to [`Self::find_file`]
/// (path-equality on `ConfigSource::File`) and [`Self::unique_of_kind`]
/// (kind-uniqueness on the typed discriminant). Together the three
/// methods close the chain-walk discipline for the failing-source
/// resolver: every "which layer in the recipe …?" question routes
/// through one named primitive instead of an open-coded
/// `iter().find` / `iter().filter` that re-derives the comparison
/// shape at every consumer.
fn find_env_by_prefix(&self, prefix: &str) -> Option<&ConfigSource>;
/// Dense per-layer-kind tally of the chain over the
/// [`ConfigSourceKind`] axis — the typed histogram every
/// attestation manifest, structured-log dashboard, and
/// chain-shape audit bucketing the (defaults × env × file) layer
/// counts has previously re-derived inline.
///
/// Equivalent to
/// `crate::axis_histogram(self.iter().map(ConfigSource::kind))`
/// but named at the chain-walk surface so consumers reading the
/// recipe ([`crate::ConfigStore::sources`] /
/// [`crate::ProviderChain::sources`]) don't reach for the cube-
/// level generic helper. The histogram's `total()` equals
/// `self.len()` pointwise (every chain entry projects to exactly
/// one kind); `is_empty()` iff the chain is empty.
///
/// Peer to [`crate::ConfigDiff::kind_histogram`] on the
/// diff-line axis, [`crate::axis_histogram`] on the generic
/// closed-axis helper surface. The two concrete consumers of
/// [`crate::AxisHistogram`] now sit on the (chain-shape × diff-
/// shape) pair the typescape's recipe and reload surfaces emit;
/// future axis-tally consumers (a watcher-side reload-trigger
/// histogram over [`crate::WatchEventClass`], a secret-resolution
/// refusal histogram over [`crate::secret_client::SecretErrorKind`],
/// a format-axis loader histogram over [`crate::Format`]) inherit
/// the same lift discipline by composing `axis_histogram` over
/// the appropriate per-cell projection.
///
/// The fourth chain-level provenance query peer to
/// [`Self::find_file`], [`Self::unique_of_kind`], and
/// [`Self::find_env_by_prefix`]: those three answer
/// "*which layer in the recipe …?*" point queries; this one
/// answers the *aggregate* "*how many layers of each kind?*"
/// over the same chain. Trait-default implementation so a
/// chain-shape consumer reading the histogram does not need to
/// retain the chain slice — the projection is one method call.
fn layer_kind_histogram(&self) -> crate::AxisHistogram<ConfigSourceKind>
where
Self: AsRef<[ConfigSource]>,
{
crate::axis_histogram(self.as_ref().iter().map(ConfigSource::kind))
}
/// The distinct [`ConfigSourceKind`]s that appear as ≥1 layer in
/// this chain, in [`ConfigSourceKind::ALL`] declaration order —
/// the chain-altitude dual of "which layer kinds actually
/// surfaced in this recipe".
///
/// Routes through [`Self::layer_kind_histogram`]:
/// [`crate::AxisHistogram::observed`] iterates the histogram's
/// support (the closed-axis cells with nonzero count) in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`ConfigSourceKind`] canonical order
/// (`Defaults → Env → File`) by construction — the closed-axis
/// discipline provides the sort + dedup automatically, so this
/// method reads directly off the shikumi cube-native primitive
/// instead of hand-rolling `Vec::contains` (`O(n·k)` in the
/// chain length and distinct-kind count) + explicit
/// `sort_by_key(axis_ordinal)` at every attestation manifest,
/// structured-log dashboard, or config-show renderer summarizing
/// which layer kinds contributed to the recipe.
///
/// The chain-altitude peer of
/// [`crate::ConfigDiff::present_kinds`] on the diff altitude and
/// [`crate::ProvenanceMap::contributing_tiers`] on the tier
/// altitude — all three project the observed-support of the
/// underlying [`crate::AxisHistogram`] over their local closed
/// axis, all three live as a `Vec<CellKind>` collect wrapper
/// alongside their respective `_histogram()` primitive, and all
/// three spell the closed-axis declaration-order cell iteration
/// at the API boundary. Sister lifts on the same chain-shape
/// surface — the observed-cells peers of
/// [`Self::file_format_histogram`] and
/// [`Self::env_prefix_kind_histogram`] — inherit the same
/// template.
///
/// # Invariants
///
/// - `present_layer_kinds().len() ==
/// layer_kind_histogram().distinct_cells()` — both project
/// the same support-cardinality off the histogram.
/// - `present_layer_kinds().is_empty() ==
/// self.as_ref().is_empty()` — an empty chain has no present
/// kinds; a non-empty chain has ≥1 present kind (every entry
/// projects to exactly one kind, so the histogram support is
/// nonempty iff the chain is).
/// - `layer_kind_histogram().is_full_cover() ==
/// (present_layer_kinds().len() ==
/// crate::axis_cardinality::<ConfigSourceKind>())` — the
/// full-cover predicate and the observed-cells cardinality
/// agree by construction over the same shared histogram.
/// - `present_layer_kinds()` is sorted strictly ascending by
/// [`crate::axis_ordinal`] on [`ConfigSourceKind`] — dedup and
/// sort for free from the closed-axis discipline; no
/// hand-rolled `sort_by_key` at the consumer.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<ConfigSourceKind>()`
/// (the support scan). Both are `O(n)` in practice since the
/// layer-kind axis carries a fixed three-cell cardinality; the
/// returned `Vec<ConfigSourceKind>` is at most three elements
/// long regardless of chain length.
fn present_layer_kinds(&self) -> Vec<ConfigSourceKind>
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().observed().collect()
}
/// The number of distinct [`ConfigSourceKind`]s that appear as ≥1
/// layer in this chain — the support-size scalar-count peer of
/// [`Self::present_layer_kinds`] on the layer-kind sub-axis of the
/// chain altitude, and the chain-altitude sister of
/// [`crate::ProvenanceMap::contributing_tiers_count`] on the tier
/// altitude.
///
/// Routes through [`Self::layer_kind_histogram`]:
/// [`crate::AxisHistogram::distinct_cells`] is the cube-native
/// single-pass `.filter(|&&c| c > 0).count()` walk over the
/// fixed-cardinality counts vector, so this method reads the
/// support size in one call instead of paying for the
/// `Vec<ConfigSourceKind>` allocation
/// [`Self::present_layer_kinds`] materialises and then walking
/// [`Vec::len`] to read the length back — the exact idiom every
/// operator-facing consumer asking *"how many layer kinds
/// contributed to this recipe?"* has been open-coding at
/// [`Vec::len`] of the observed-cells `Vec` peer:
///
/// - the config-show summary line *"2 of 3 layer kinds contributed
/// to this recipe"* reading the support cardinality directly off
/// the seam,
/// - the attestation manifest recording the layer-kind support size
/// of a `ProviderChain` between two rebuild-window snapshots,
/// - the alerting policy reading *"support size = 1"* to flag a
/// recipe where only one layer kind surfaced.
///
/// The layer-kind sub-axis scalar-count peer of the chain altitude,
/// sister to the tier altitude's
/// [`crate::ProvenanceMap::contributing_tiers_count`] and the diff
/// altitude's [`crate::ConfigDiff::present_kinds`] length peer.
/// Together with [`Self::present_layer_kinds`] and
/// [`Self::absent_layer_kinds`], this seam closes the
/// `(observed, unobserved) × (cells, count)` 2×2 support / coverage-
/// gap grid on the layer-kind sub-axis:
///
/// | | cells (Vec) | count (usize) |
/// |---|---|---|
/// | observed | `present_layer_kinds` | **`present_layer_kinds_count`** |
/// | unobserved | `absent_layer_kinds` | [`Self::absent_layer_kinds_count`] |
///
/// # Invariants
///
/// - `present_layer_kinds_count() ==
/// layer_kind_histogram().distinct_cells()` — both project
/// the same nonzero-cell count off the same primitive; the named
/// seam is the cube-native routing of the histogram surface.
/// Pinned by
/// [`tests::present_layer_kinds_count_matches_layer_kind_histogram_distinct_cells_pointwise`].
/// - `present_layer_kinds_count() == present_layer_kinds().len()`
/// — the scalar-count peer of the observed-cells `Vec` peer;
/// both name the same support cardinality without materialising
/// the vector. Pinned by
/// [`tests::present_layer_kinds_count_equals_present_layer_kinds_len_pointwise`].
/// - `present_layer_kinds_count() + absent_layer_kinds().len() ==
/// crate::axis_cardinality::<ConfigSourceKind>()` — the observed
/// / coverage-gap partition on the layer-kind axis without
/// remainder, the scalar dual of the
/// [`tests::absent_layer_kinds_and_present_layer_kinds_partition_axis`]
/// set-level partition law. Pinned by
/// [`tests::present_layer_kinds_count_and_absent_layer_kinds_len_partition_axis_cardinality`].
/// - `present_layer_kinds_count() == 0` ⇔
/// `self.as_ref().is_empty()` — the empty-chain / empty-support
/// boundary equivalence (every entry projects to one kind, so a
/// zero-support recipe has zero entries and vice versa). Pinned
/// by
/// [`tests::present_layer_kinds_count_is_zero_iff_chain_is_empty`].
/// - `present_layer_kinds_count() >= 1` whenever the chain is
/// non-empty — the support of a non-empty recipe is at least the
/// singleton of the first-layer kind. Pinned by
/// [`tests::present_layer_kinds_count_is_at_least_one_on_nonempty_chain`].
/// - `present_layer_kinds_count() <=
/// crate::axis_cardinality::<ConfigSourceKind>()` — the support
/// of a histogram over a closed axis is bounded above by the axis
/// cardinality (the observed-cells set is a subset of
/// [`ConfigSourceKind::ALL`]). Pinned by
/// [`tests::present_layer_kinds_count_is_bounded_by_axis_cardinality`].
/// - `present_layer_kinds_count() <=
/// layer_kind_histogram().total()` — the support of a histogram
/// is bounded above by the total observation count (every
/// distinct cell contributes at least one observation to the
/// total). Pinned by
/// [`tests::present_layer_kinds_count_is_bounded_by_layer_kind_histogram_total`].
/// - `present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>()` ⇔
/// `absent_layer_kinds().is_empty()` ⇔
/// `layer_kind_histogram().is_full_cover()` — the full-cover
/// boundary equivalence, the layer-kind-sub-axis scalar-count
/// peer of the [`crate::AxisHistogram::is_full_cover`] boundary
/// law. Pinned by
/// [`tests::present_layer_kinds_count_equals_axis_cardinality_iff_is_full_cover`].
/// - `present_layer_kinds_count() == 1` ⇔
/// `layer_kind_histogram().has_singular_support()` — the
/// singleton-support boundary equivalence, the layer-kind-sub-
/// axis peer of the [`crate::AxisHistogram::has_singular_support`]
/// boundary law. Pinned by
/// [`tests::present_layer_kinds_count_is_one_iff_has_singular_support`].
/// - `present_layer_kinds_count() == 1` ⇒ `dominant_layer_kind() ==
/// recessive_layer_kind()` — a singleton-support recipe has the
/// modal and anti-modal cells coincide on the sole observed kind
/// (the support-size scalar witnesses the
/// [`crate::AxisHistogram`] support-collapse degenerate). Pinned
/// by
/// [`tests::present_layer_kinds_count_of_one_implies_dominant_equals_recessive`].
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// support scan). Both are `O(n)` in practice since the layer-kind
/// axis carries a fixed three-cell cardinality; unlike
/// [`Self::present_layer_kinds`], no `Vec<ConfigSourceKind>`
/// allocation is paid on every call site.
fn present_layer_kinds_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().distinct_cells()
}
/// The distinct [`ConfigSourceKind`]s that appear as **zero** layers in
/// this chain, in [`ConfigSourceKind::ALL`] declaration order — the
/// coverage-gap peer of [`Self::present_layer_kinds`] and the chain-
/// altitude dual of [`crate::ConfigDiff::absent_kinds`] on the diff
/// altitude and [`crate::ProvenanceMap::absent_tiers`] on the tier
/// altitude.
///
/// Routes through [`Self::layer_kind_histogram`]:
/// [`crate::AxisHistogram::unobserved`] iterates the histogram's
/// **coverage gap** (the closed-axis cells with zero count) in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`ConfigSourceKind`] canonical order (`Defaults → Env → File`) by
/// construction — the closed-axis discipline provides the sort +
/// dedup automatically, so this method reads directly off the shikumi
/// cube-native primitive instead of hand-rolling
/// `ConfigSourceKind::ALL.iter().filter(|k| !self.present_layer_kinds().
/// contains(k))` (`O(k·k)` in axis-cardinality, quadratic on the
/// observed side) at every operator-facing consumer asking *"which
/// layer kinds are absent from this recipe?"* — the CLI `config-show`
/// summary reading *"no `Env` layers; skip the env-prefix legend"*,
/// the attestation manifest recording the layer-kind coverage gap of
/// a `ProviderChain`, the alerting policy suppressing per-kind bins
/// that never fired for this rebuild window.
///
/// The observed-cells peer ([`Self::present_layer_kinds`]) and the
/// coverage-gap peer ([`Self::absent_layer_kinds`]) together form the
/// **support / coverage-gap partition** on the chain altitude — every
/// cell of [`ConfigSourceKind::ALL`] lies in exactly one of the two,
/// and the two `Vec<ConfigSourceKind>` lengths sum to
/// [`crate::axis_cardinality::<ConfigSourceKind>()`][crate::axis_cardinality].
/// The chain-altitude dual of the diff-altitude
/// [`crate::ConfigDiff::absent_kinds`] and the tier-altitude
/// [`crate::ProvenanceMap::absent_tiers`] — every altitude of the
/// shikumi typescape now closes both halves of the histogram's
/// observed / unobserved partition at one named `Vec<CellKind>` seam
/// alongside the underlying `_histogram()` primitive. Sister lifts
/// one axis over on the same chain-shape surface — the unobserved-
/// cells peers of [`Self::file_format_histogram`] and
/// [`Self::env_prefix_kind_histogram`] — inherit the same template.
///
/// # Invariants
///
/// - `absent_layer_kinds().len() ==
/// layer_kind_histogram().unobserved_cells()` — both project the
/// same coverage-gap cardinality off the histogram.
/// - `present_layer_kinds().len() + absent_layer_kinds().len() ==
/// crate::axis_cardinality::<ConfigSourceKind>()` — the two peers
/// partition the closed axis without remainder (every cell is
/// either observed or unobserved, never both).
/// - `present_layer_kinds()` and `absent_layer_kinds()` are disjoint:
/// no [`ConfigSourceKind`] appears in both.
/// - `absent_layer_kinds().is_empty() ==
/// layer_kind_histogram().is_full_cover()` — the coverage-gap is
/// empty iff every layer kind was observed at least once (all
/// three of `Defaults` / `Env` / `File` appear as ≥1 layer).
/// - `absent_layer_kinds()` on an empty chain (no layers) equals
/// [`ConfigSourceKind::ALL`] — every kind is absent when no layer
/// contributed, the empty-chain / full-coverage-gap boundary.
/// - `absent_layer_kinds()` is sorted strictly ascending by
/// [`crate::axis_ordinal`] on [`ConfigSourceKind`] — dedup + sort
/// for free from the closed-axis discipline.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// coverage-gap scan). Both are `O(n)` in practice since the layer-
/// kind axis carries a fixed three-cell cardinality; the returned
/// `Vec<ConfigSourceKind>` is at most three elements long regardless
/// of chain length.
fn absent_layer_kinds(&self) -> Vec<ConfigSourceKind>
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().unobserved().collect()
}
/// The number of distinct [`ConfigSourceKind`]s that appear as
/// **zero** layers in this chain — the coverage-gap-size scalar-
/// count peer of [`Self::absent_layer_kinds`] on the layer-kind
/// sub-axis of the chain altitude, and the chain-altitude sister of
/// [`crate::ProvenanceMap::absent_tiers_count`] on the tier altitude
/// and [`crate::ConfigDiff::absent_kinds_count`] on the diff
/// altitude.
///
/// Routes through [`Self::layer_kind_histogram`]:
/// [`crate::AxisHistogram::unobserved_cells`] is the cube-native
/// single-pass `.filter(|&&c| c == 0).count()` walk over the
/// fixed-cardinality counts vector, so this method reads the
/// coverage-gap size in one call instead of paying for the
/// `Vec<ConfigSourceKind>` allocation [`Self::absent_layer_kinds`]
/// materialises and then walking [`Vec::len`] to read the length
/// back — the exact idiom every operator-facing consumer asking
/// *"how many layer kinds are absent from this recipe?"* has been
/// open-coding at [`Vec::len`] of the coverage-gap `Vec` peer:
///
/// - the config-show summary line *"1 of 3 layer kinds absent this
/// rebuild window"* reading the coverage-gap cardinality directly
/// off the seam,
/// - the attestation manifest recording the layer-kind coverage-gap
/// size of a `ProviderChain` between two rebuild-window snapshots,
/// - the alerting policy reading *"coverage-gap size = 3"* to flag a
/// recipe where no layer kind surfaced.
///
/// The layer-kind sub-axis scalar-count coverage-gap peer of the
/// chain altitude, sister to the tier altitude's
/// [`crate::ProvenanceMap::absent_tiers_count`] and the diff
/// altitude's [`crate::ConfigDiff::absent_kinds_count`]. Together
/// with [`Self::present_layer_kinds`], [`Self::absent_layer_kinds`],
/// and [`Self::present_layer_kinds_count`], this seam closes the
/// `(observed, unobserved) × (cells, count)` 2×2 support / coverage-
/// gap grid on the layer-kind sub-axis explicitly — every quadrant
/// of the grid is now a named seam:
///
/// | | cells (Vec) | count (usize) |
/// |---|---|---|
/// | observed | [`Self::present_layer_kinds`] | [`Self::present_layer_kinds_count`] |
/// | unobserved | [`Self::absent_layer_kinds`] | **`absent_layer_kinds_count`** |
///
/// Extends the "coverage-gap-size across altitudes" projection —
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::absent_kinds_count`] and lifted to the tier
/// altitude by [`crate::ProvenanceMap::absent_tiers_count`] — down
/// to the chain altitude's first sub-axis. The chain-altitude
/// file-format and env-prefix sister lifts
/// ([`Self::absent_file_formats_count`],
/// [`Self::absent_env_prefix_kinds_count`]) on the same chain-shape
/// surface inherit the same template.
///
/// **Empty-chain convention** — returns
/// [`crate::axis_cardinality::<ConfigSourceKind>()`][crate::axis_cardinality]
/// (not `Option<usize>`) matching the [`Self::absent_layer_kinds`]
/// full-axis convention and the
/// [`crate::AxisHistogram::unobserved_cells`] convention one altitude
/// down. The coverage-gap-size scalar is well-defined as the axis
/// cardinality on the empty chain: the unobserved-cells set is the
/// entire axis, its cardinality is
/// [`crate::axis_cardinality::<ConfigSourceKind>()`][crate::axis_cardinality],
/// and the coverage-partition sum
/// [`Self::present_layer_kinds_count`] + `absent_layer_kinds_count()`
/// still balances the axis cardinality (`0 +
/// axis_cardinality::<ConfigSourceKind>() ==
/// axis_cardinality::<ConfigSourceKind>()`).
///
/// # Invariants
///
/// - `absent_layer_kinds_count() ==
/// layer_kind_histogram().unobserved_cells()` — both project the
/// same coverage-gap cardinality off the same primitive; the named
/// seam is the cube-native routing of the histogram surface.
/// Pinned by
/// [`tests::absent_layer_kinds_count_matches_layer_kind_histogram_unobserved_cells_pointwise`].
/// - `absent_layer_kinds_count() == absent_layer_kinds().len()` —
/// the scalar-count peer of the coverage-gap `Vec` peer; both name
/// the same coverage-gap cardinality without materialising the
/// vector. Pinned by
/// [`tests::absent_layer_kinds_count_equals_absent_layer_kinds_len_pointwise`].
/// - `present_layer_kinds_count() + absent_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>()` — the observed
/// / coverage-gap partition on the layer-kind axis without
/// remainder, the fully-scalar dual of
/// [`tests::absent_layer_kinds_and_present_layer_kinds_partition_axis`]
/// (both sides now scalar, no `.len()` on either). Pinned by
/// [`tests::present_layer_kinds_count_and_absent_layer_kinds_count_partition_axis_cardinality`].
/// - `absent_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>() -
/// present_layer_kinds_count()` — the algebraic rearrangement of
/// the partition, useful for consumers that already hold the
/// support-size scalar. Pinned by
/// [`tests::absent_layer_kinds_count_equals_axis_cardinality_minus_present_layer_kinds_count`].
/// - `absent_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>()` ⇔
/// `self.as_ref().is_empty()` — the empty-chain / full-coverage-
/// gap boundary, the scalar peer of `absent_layer_kinds() ==
/// ConfigSourceKind::ALL`. Pinned by
/// [`tests::absent_layer_kinds_count_is_axis_cardinality_iff_chain_is_empty`].
/// - `absent_layer_kinds_count() == 0` ⇔
/// `layer_kind_histogram().is_full_cover()` — the full-cover
/// boundary equivalence, the layer-kind-sub-axis scalar-count
/// coverage-gap peer of the [`crate::AxisHistogram::is_full_cover`]
/// boundary law and the coverage-gap dual of
/// `present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>()`. Pinned by
/// [`tests::absent_layer_kinds_count_is_zero_iff_is_full_cover`].
/// - `absent_layer_kinds_count() <=
/// crate::axis_cardinality::<ConfigSourceKind>()` — the coverage
/// gap of a histogram over a closed axis is bounded above by the
/// axis cardinality (the unobserved-cells set is a subset of
/// [`ConfigSourceKind::ALL`]). Pinned by
/// [`tests::absent_layer_kinds_count_is_bounded_by_axis_cardinality`].
/// - `absent_layer_kinds_count() >= 1` whenever
/// `!layer_kind_histogram().is_full_cover()` — a non-full-cover
/// recipe carries at least one absent kind. Pinned by
/// [`tests::absent_layer_kinds_count_is_at_least_one_when_not_full_cover`].
/// - `absent_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1` ⇔
/// `layer_kind_histogram().has_singular_support()` — the
/// singleton-support boundary in coverage-gap form: when exactly
/// one layer kind is observed, exactly `axis_cardinality - 1` are
/// absent. Pinned by
/// [`tests::absent_layer_kinds_count_is_axis_cardinality_minus_one_iff_has_singular_support`].
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// coverage-gap scan). Both are `O(n)` in practice since the layer-
/// kind axis carries a fixed three-cell cardinality; the returned
/// `usize` reads one scalar. Halves the wall-cost of the previous
/// `absent_layer_kinds().len()` idiom by eliding the
/// `Vec<ConfigSourceKind>` allocation the coverage-gap collect paid
/// on every call site.
fn absent_layer_kinds_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().unobserved_cells()
}
/// The layer kind whose entries produced the greatest number of
/// contributing layers on this chain — the modal cell of
/// [`Self::layer_kind_histogram`] on the chain altitude. `None`
/// exactly when the chain is empty (no layer contributed).
///
/// Routes through [`Self::layer_kind_histogram`]:
/// [`crate::AxisHistogram::dominant_cell`] picks the argmax cell in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`ConfigSourceKind`] canonical order (`Defaults → Env → File`) by
/// construction — the closed-axis discipline provides deterministic
/// tie-breaking automatically, so this method reads directly off the
/// shikumi cube-native primitive instead of hand-rolling
/// `hist.iter().filter(|&(_, c)| c > 0).max_by_key(|&(_, c)| c).map(|(v, _)| v)`
/// — the inline `max_by_key` form silently picks the *last* tied
/// cell (per [`Iterator::max_by_key`]'s contract), so two consumers
/// reading "the dominant layer kind" off the same chain would
/// disagree under ties unless every one carefully reversed the
/// comparison. The lift names the scalar at one site with a
/// documented tie-breaking rule.
///
/// The chain-altitude scalar-mode peer of [`Self::present_layer_kinds`]
/// (the observed-cells vector peer) and [`Self::absent_layer_kinds`]
/// (the coverage-gap vector peer): the layer-kind sub-axis of the
/// chain-shape surface now carries the natural triple of "*which*
/// layer kinds surfaced" / "*which* layer kinds didn't" / "*which
/// single* layer kind dominated" projections at one named seam
/// each, over the shared [`Self::layer_kind_histogram`] primitive.
/// Direct sister of [`crate::ProvenanceMap::dominant_tier`] on the
/// tier altitude and [`crate::ConfigDiff::dominant_kind`] on the
/// diff altitude — every altitude of the shikumi typescape now
/// closes the histogram surface's scalar-mode dominance peer at
/// one named `Option<CellKind>` seam alongside the observed /
/// coverage-gap vector-mode pair.
///
/// Operator-facing consumers answering *"which layer kind dominated
/// this chain?"* — the CLI `config-show` summary headlining
/// *"File layers dominate: 5 of 7"* to explain why the recipe is
/// file-heavy, the attestation manifest recording the modal layer
/// kind between two `ProviderChain` snapshots, the alerting policy
/// reading *"chain dominance: Env"* to flag a rebuild window where
/// env overlays swamp the discovered file set — now route through
/// this named seam instead of a per-consumer `max_by_key` walk.
///
/// **Tie-breaking is deterministic by declaration order.** When
/// multiple layer kinds share the maximum layer count, the kind
/// earliest in [`ConfigSourceKind::ALL`] wins — the same
/// [`ConfigSourceKind`] canonical order [`Self::present_layer_kinds`]
/// and [`Self::absent_layer_kinds`] walk. A uniform-cover chain
/// (each kind producing the same nonzero layer count) therefore
/// reports `Some(ConfigSourceKind::Defaults)` — the first cell in
/// declaration order — pointwise stable regardless of the insertion
/// order of individual layers into the chain slice.
///
/// Sister lifts one sub-axis over on the same chain-shape surface —
/// the scalar-mode dominance peers of [`Self::file_format_histogram`]
/// (`dominant_file_format`) and [`Self::env_prefix_kind_histogram`]
/// (`dominant_env_prefix_kind`) — inherit the same template. Each
/// carries a distinct presence bound: unlike this method, the file-
/// format and env-prefix-presence peers fire `None` on any chain
/// whose layers all project through `file_format()` /
/// `env_prefix_kind()` to `None`, even when the chain itself is
/// non-empty (the underlying histogram is empty even when the
/// chain is not).
///
/// # Invariants
///
/// - `dominant_layer_kind().is_some() == !self.as_ref().is_empty()`
/// — every non-empty chain contributes at least one layer to the
/// layer-kind histogram (every [`ConfigSource`] projects to
/// exactly one [`ConfigSourceKind`] cell through
/// [`ConfigSource::kind`]), so the modal cell is defined on every
/// non-empty chain and undefined only on the empty chain — the
/// presence bound is `is_empty`. Cross-axis divergence from
/// `dominant_file_format()` and `dominant_env_prefix_kind()`,
/// whose presence bounds are the corresponding sub-axis
/// histogram's `is_empty()`.
/// - `dominant_layer_kind() == layer_kind_histogram().dominant_cell()`
/// — both project the same modal cell off the same primitive;
/// the named seam is the cube-native routing of the chain-shape
/// surface.
/// - When `Some(k)`, `k` is a member of `present_layer_kinds()` —
/// the modal cell is by definition observed.
/// - When `Some(k)`, `k` is **not** a member of `absent_layer_kinds()`
/// — the observed / coverage-gap partition is disjoint.
/// - `layer_kind_histogram().count(dominant_layer_kind().unwrap()) ==
/// layer_kind_histogram().peak_count()` whenever the chain is
/// non-empty — the modal cell carries the peak observation count.
/// Peer to the `(dominant_cell, peak_count)` modal pair invariant
/// on [`crate::AxisHistogram`].
/// - `dominant_layer_kind()` on a uniform per-kind chain (one layer
/// per kind) equals `Some(ConfigSourceKind::Defaults)` —
/// declaration-order tie-breaking on the three-cell axis picks
/// the first cell.
/// - `dominant_layer_kind()` on an empty chain equals `None` —
/// the empty-chain / empty-histogram boundary.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// argmax scan). Both are `O(n)` in practice since the layer-kind
/// axis carries a fixed three-cell cardinality; the returned
/// `Option<ConfigSourceKind>` reads one cell.
#[must_use]
fn dominant_layer_kind(&self) -> Option<ConfigSourceKind>
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().dominant_cell()
}
/// The [`ConfigSourceKind`] whose layers are rarest (but still ≥1) on
/// this chain — the anti-modal (rarest observed) cell of
/// [`Self::layer_kind_histogram`] on the chain altitude. `None` exactly
/// when the chain is empty.
///
/// Routes through [`Self::layer_kind_histogram`]:
/// [`crate::AxisHistogram::recessive_cell`] picks the argmin cell over
/// the histogram's *support* (the nonzero cells) in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`ConfigSourceKind`] canonical order (`Defaults → Env → File`) by
/// construction — the closed-axis discipline provides deterministic
/// tie-breaking automatically, so this method reads directly off the
/// shikumi cube-native primitive instead of hand-rolling
/// `hist.iter().filter(|&(_, c)| c > 0).min_by_key(|&(_, c)| c).map(|(v, _)| v)`
/// — the inline `min_by_key` form silently picks the *first* tied cell
/// (per [`Iterator::min_by_key`]'s contract, which reverses
/// [`Iterator::max_by_key`]'s "last on ties" behavior), so an
/// open-coded argmin and the open-coded argmax on the dominant side
/// would disagree on which tied cell to pick. The pair of lifts
/// ([`Self::dominant_layer_kind`] and [`Self::recessive_layer_kind`])
/// pins one consistent tie-breaking rule across both projections.
///
/// **Zero-count kinds are excluded from the search.** The argmin is
/// taken over the histogram's support, not over the full axis. Kinds
/// that contributed no layer would trivially be the minimum over the
/// full axis and would shadow the rarest *observed* kind; excluding
/// them surfaces the rarest kind some layer actually landed on — the
/// question the CLI `config-show` summary, attestation manifest, and
/// alerting policy ask when they surface *"the runt layer kind this
/// recipe saw"*. This matches [`Self::dominant_layer_kind`]'s symmetry
/// on the maximum side: both projections operate over the nonzero
/// support, so the empty-chain convention is identical (both return
/// `None`) and the singleton-support case is identical (both return
/// the sole observed kind).
///
/// The chain-altitude anti-modal peer of [`Self::dominant_layer_kind`]
/// (the modal-cell scalar peer of the same
/// [`Self::layer_kind_histogram`] primitive) — the layer-kind sub-axis
/// of the chain-shape surface now carries the fused (dominant,
/// recessive) cell pair, matching the
/// ([`crate::AxisHistogram::dominant_cell`],
/// [`crate::AxisHistogram::recessive_cell`]) pair on the shared
/// [`crate::AxisHistogram`] primitive one altitude down. Direct sister
/// of [`crate::ProvenanceMap::recessive_tier`] on the tier altitude
/// and [`crate::ConfigDiff::recessive_kind`] on the diff altitude —
/// all three project the anti-modal cell of their local closed-axis
/// histogram off the shared [`crate::AxisHistogram::recessive_cell`]
/// primitive, all three live as an `Option<CellKind>` scalar
/// alongside the modal-cell peer.
///
/// Operator-facing consumers answering *"which layer kind is the runt
/// of this recipe?"* — the CLI `config-show` summary headlining
/// *"runt: Defaults, 1 of 47 layers"*, the attestation manifest
/// recording the anti-modal layer kind between two `ProviderChain`
/// snapshots, the alerting policy reading *"chain runt: Env"* to flag
/// a rebuild window where the env overlay contributed almost nothing
/// — now route through this named seam instead of a per-consumer
/// `min_by_key` walk.
///
/// **Tie-breaking is deterministic by declaration order.** When
/// multiple observed kinds share the minimum layer count, the kind
/// earliest in [`ConfigSourceKind::ALL`] wins (`Defaults → Env →
/// File`) — the same order [`Self::present_layer_kinds`],
/// [`Self::absent_layer_kinds`], and [`Self::dominant_layer_kind`]
/// walk. A uniform-cover chain (each kind producing the same nonzero
/// layer count) therefore reports `Some(ConfigSourceKind::Defaults)`
/// — the first cell in declaration order — pointwise identical to
/// [`Self::dominant_layer_kind`] on the same input (the
/// singleton-modality degenerate where the modal and anti-modal cells
/// coincide).
///
/// # Invariants
///
/// - `recessive_layer_kind().is_some() == !self.as_ref().is_empty()`
/// — the recessive layer kind is defined exactly when the chain has
/// at least one layer. Peer to the `is_empty` boundary
/// [`Self::dominant_layer_kind`], [`Self::present_layer_kinds`],
/// and [`Self::absent_layer_kinds`] all witness. Cross-axis
/// divergence from [`Self::recessive_file_format`] /
/// [`Self::recessive_env_prefix_kind`], whose presence bounds are
/// the corresponding sub-axis histogram's `is_empty()`.
/// - `recessive_layer_kind().is_some() == dominant_layer_kind().is_some()`
/// — both projections are defined on the same support
/// (`!self.as_ref().is_empty()`), lifted from the
/// [`crate::AxisHistogram::recessive_cell`] /
/// [`crate::AxisHistogram::dominant_cell`] presence-bound law.
/// - `recessive_layer_kind() == layer_kind_histogram().recessive_cell()`
/// — both project the same anti-modal cell off the same primitive;
/// the named seam is the cube-native routing of the chain-shape
/// surface.
/// - When `Some(k)`, `k` is a member of `present_layer_kinds()` —
/// the anti-modal cell is by definition observed.
/// - When `Some(k)`, `k` is **not** a member of `absent_layer_kinds()`
/// — the observed / coverage-gap partition is disjoint, and the
/// argmin over the *support* never coincides with a zero-count
/// cell.
/// - `layer_kind_histogram().count(recessive_layer_kind().unwrap()) ==
/// layer_kind_histogram().trough_count()` whenever the chain is
/// non-empty — the anti-modal cell carries the trough-of-support
/// observation count. Peer to the (`recessive_cell`,
/// `trough_count`) anti-modal pair invariant on
/// [`crate::AxisHistogram`].
/// - `layer_kind_histogram().count(recessive_layer_kind().unwrap()) <=
/// layer_kind_histogram().count(dominant_layer_kind().unwrap())`
/// whenever the chain is non-empty — the trough-of-support count is
/// bounded above by the peak count. Lifted from the trait-uniform
/// `count(recessive_cell) <= count(dominant_cell)` law on
/// [`crate::AxisHistogram`].
/// - `recessive_layer_kind() == dominant_layer_kind()` whenever
/// `present_layer_kinds().len() == 1` — a single observed kind is
/// both the modal and the anti-modal cell (the singleton-support
/// degenerate).
/// - `recessive_layer_kind()` on a uniform per-kind chain (one layer
/// per kind) equals `Some(ConfigSourceKind::Defaults)` —
/// declaration-order tie-breaking on the three-cell axis picks the
/// first cell, pointwise identical to `dominant_layer_kind()` on
/// the same input.
/// - `recessive_layer_kind()` on an empty chain equals `None` — the
/// empty-chain / empty-histogram boundary.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// argmin scan). Both are `O(n)` in practice since the layer-kind
/// axis carries a fixed three-cell cardinality; the returned
/// `Option<ConfigSourceKind>` reads one cell.
#[must_use]
fn recessive_layer_kind(&self) -> Option<ConfigSourceKind>
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().recessive_cell()
}
/// The **peak layer count** — the number of layers contributed by the
/// dominant (majority-observed) [`ConfigSourceKind`] on this chain.
/// Returns `0` exactly when the chain is empty; otherwise returns the
/// count carried by [`Self::dominant_layer_kind`] (pointwise equal to
/// it, and always `>= 1` by the histogram-support definition).
///
/// The **scalar peer** of [`Self::dominant_layer_kind`] on the count
/// side — the natural typed primitive for chain-shape dashboards,
/// attestation manifests, and alerting policies asking *"how many
/// layers did the majority kind contribute?"*: the CLI `config-show`
/// summary headline *"majority kind: File, 3 of 5 layers"* (where 3
/// is this scalar), the attestation manifest recording the peak
/// layer-kind observation count between two `ProviderChain`
/// snapshots, the alerting policy reading *"chain peak-kind count =
/// 12"* to gate a rebuild window on the modal kind's density. Before
/// this lift, every such consumer re-derived the projection inline
/// as `chain.layer_kind_histogram().peak_count()` or (equivalently
/// but at twice the cost) `chain.dominant_layer_kind().map_or(0, |k|
/// chain.layer_kind_histogram().count(k))` — which walked the
/// histogram *twice* (once to argmax, once to read the count back
/// through [`crate::AxisHistogram::count`] indexing) and re-built
/// the histogram at every site. Routes through
/// [`Self::layer_kind_histogram`]:
/// [`crate::AxisHistogram::peak_count`] reads a single pass over the
/// fixed-cardinality counts vector.
///
/// The chain-altitude scalar-count peer of [`Self::dominant_layer_kind`]
/// (the modal-cell scalar peer of [`Self::layer_kind_histogram`]) —
/// the layer-kind sub-axis of the chain-shape surface now carries
/// the fused `(dominant_layer_kind, peak_layer_kind_count)` modal
/// pair, matching the ([`crate::AxisHistogram::dominant_cell`],
/// [`crate::AxisHistogram::peak_count`]) pair on the shared
/// [`crate::AxisHistogram`] primitive one altitude down, the
/// ([`crate::ProvenanceMap::dominant_tier`],
/// [`crate::ProvenanceMap::peak_tier_count`]) pair on the tier
/// altitude, and the ([`crate::ConfigDiff::dominant_kind`],
/// [`crate::ConfigDiff::peak_kind_count`]) pair on the diff altitude.
/// Consumers answering *"which layer kind dominated the chain and by
/// how much?"* now read a single `(dominant_layer_kind(),
/// peak_layer_kind_count())` pair — one method each, both routing
/// through the same primitive — instead of re-deriving the count off
/// the modal cell.
///
/// **Empty-chain convention** — returns `0` (not `Option<usize>`)
/// matching the [`crate::AxisHistogram::peak_count`] convention one
/// altitude down, the [`crate::ProvenanceMap::peak_tier_count`] and
/// [`crate::ConfigDiff::peak_kind_count`] conventions on the peer
/// altitudes, and the `self.as_ref().len()` empty convention on the
/// same chain; the scalar `(self.as_ref().len(),
/// peak_layer_kind_count)` pair reads uniformly `(0, 0)` on the
/// empty chain. The dual-form [`Self::dominant_layer_kind`] carries
/// `Option<ConfigSourceKind>` because the *kind* is undefined when
/// no layer contributes; the *count* is well-defined as zero. The
/// asymmetry is intentional: every scalar projection reads zero on
/// empty; every cell projection reads `None`.
///
/// # Invariants
///
/// - `peak_layer_kind_count() == 0` ⇔ `self.as_ref().is_empty()` —
/// peer to the empty-chain boundary [`Self::dominant_layer_kind`]
/// and [`Self::recessive_layer_kind`] both witness on the cell
/// side. Unlike the file-format and env-prefix sub-axes, the
/// presence bound coincides with `self.as_ref().is_empty()` (every
/// layer projects to exactly one [`ConfigSourceKind`] cell through
/// [`ConfigSource::kind`]).
/// - `peak_layer_kind_count() == layer_kind_histogram().peak_count()`
/// — both project the same scalar off the same primitive; the
/// named seam is the cube-native routing of the chain-shape
/// surface.
/// - `peak_layer_kind_count() == dominant_layer_kind().map_or(0, |k|
/// layer_kind_histogram().count(k))` — the count projection of the
/// `(dominant_layer_kind, peak_layer_kind_count)` modal pair
/// equals [`Self::peak_layer_kind_count`] pointwise on every chain
/// (empty: `None.map_or(0, …) == 0 == peak_layer_kind_count`;
/// non-empty: `Some(k).map_or(0, |k| count(k)) ==
/// peak_layer_kind_count`, since `count(dominant_layer_kind()) ==
/// peak_count()`).
/// - `peak_layer_kind_count() <= self.as_ref().len()` always: the
/// peak is bounded above by the total layer count (every kind
/// contributes at most every layer, and the others contribute
/// zero). Equality holds iff `present_layer_kinds().len() <= 1`.
/// - `peak_layer_kind_count() == self.as_ref().len()` iff
/// `present_layer_kinds().len() <= 1`: a single observed kind
/// carries every layer, so the peak equals the total. Zero
/// observed kinds (empty) reads `0 == 0`; one observed kind reads
/// `N == N`; two or more reads `peak < total` strictly.
/// - `peak_layer_kind_count() >= 1` whenever
/// `!self.as_ref().is_empty()` — a non-empty chain always has at
/// least one layer on the dominant kind.
/// - `peak_layer_kind_count()` on a uniform per-kind chain (one
/// layer per kind) equals `1` — every observed kind collects one
/// layer, dominant included.
/// - `peak_layer_kind_count()` on a singleton-support chain (every
/// layer on the same kind) equals `self.as_ref().len()` — the
/// dominant kind collects every layer.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// argmax scan). Both are `O(n)` in practice since the layer-kind
/// axis carries a fixed three-cell cardinality; the returned
/// `usize` reads one scalar. Halves the cost of the previous
/// `dominant_layer_kind().map_or(0, |k|
/// layer_kind_histogram().count(k))` idiom (which walked the
/// histogram twice — once to argmax, once to read the count back).
#[must_use]
fn peak_layer_kind_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().peak_count()
}
/// The **trough layer count** — the number of layers contributed by the
/// recessive (rarest-observed) [`ConfigSourceKind`] on this chain.
/// Returns `0` exactly when the chain is empty; otherwise returns the
/// count carried by [`Self::recessive_layer_kind`] (pointwise equal to
/// it, and always `>= 1` by the histogram-support definition).
///
/// The **scalar peer** of [`Self::recessive_layer_kind`] on the count
/// side — the natural typed primitive for chain-shape dashboards,
/// attestation manifests, and alerting policies asking *"how many
/// layers did the runt kind contribute?"*: the CLI `config-show`
/// summary line *"runt: Defaults, 1 of 5 layers"* (where 1 is this
/// scalar), the attestation manifest recording the trough layer-kind
/// observation count between two `ProviderChain` snapshots, the
/// alerting policy reading *"chain trough-kind count = 1"* to flag a
/// rebuild window where a kind barely contributed. Before this lift,
/// every such consumer re-derived the projection inline as
/// `chain.layer_kind_histogram().trough_count()` or (equivalently but
/// at twice the cost) `chain.recessive_layer_kind().map_or(0, |k|
/// chain.layer_kind_histogram().count(k))` — which walked the
/// histogram *twice* (once to argmin over the support, once to read
/// the count back through [`crate::AxisHistogram::count`] indexing)
/// and re-built the histogram at every site. Routes through
/// [`Self::layer_kind_histogram`]:
/// [`crate::AxisHistogram::trough_count`] reads a single pass over
/// the fixed-cardinality counts vector (filtering the zero-count
/// cells out of the argmin search).
///
/// The chain-altitude scalar-count peer of [`Self::recessive_layer_kind`]
/// (the anti-modal-cell scalar peer of [`Self::layer_kind_histogram`])
/// — the layer-kind sub-axis of the chain-shape surface now carries
/// the fused `(recessive_layer_kind, trough_layer_kind_count)`
/// anti-modal pair, matching the ([`crate::AxisHistogram::recessive_cell`],
/// [`crate::AxisHistogram::trough_count`]) pair on the shared
/// [`crate::AxisHistogram`] primitive one altitude down, the
/// ([`crate::ProvenanceMap::recessive_tier`],
/// [`crate::ProvenanceMap::trough_tier_count`]) pair on the tier
/// altitude, and the ([`crate::ConfigDiff::recessive_kind`],
/// [`crate::ConfigDiff::trough_kind_count`]) pair on the diff altitude.
/// Consumers answering *"which layer kind is the runt of the chain
/// and by how much?"* now read a single `(recessive_layer_kind(),
/// trough_layer_kind_count())` pair — one method each, both routing
/// through the same primitive — instead of re-deriving the count off
/// the anti-modal cell.
///
/// The 2×2 `(dominant, recessive) × (cell, count)` scalar grid on the
/// layer-kind sub-axis of the chain-shape surface closes with this
/// lift: the four seams ([`Self::dominant_layer_kind`],
/// [`Self::peak_layer_kind_count`], [`Self::recessive_layer_kind`],
/// [`Self::trough_layer_kind_count`]) now each route through the same
/// [`Self::layer_kind_histogram`] primitive at one pass per
/// projection, matching the `(dominant_cell, peak_count,
/// recessive_cell, trough_count)` quad on the shared
/// [`crate::AxisHistogram`] primitive one altitude down, the
/// `(dominant_tier, peak_tier_count, recessive_tier,
/// trough_tier_count)` quad on the tier altitude, and the
/// `(dominant_kind, peak_kind_count, recessive_kind,
/// trough_kind_count)` quad on the diff altitude.
///
/// **Empty-chain convention** — returns `0` (not `Option<usize>`)
/// matching the [`crate::AxisHistogram::trough_count`] convention one
/// altitude down, the [`Self::peak_layer_kind_count`] convention on
/// the same sub-axis, the
/// [`crate::ProvenanceMap::trough_tier_count`] and
/// [`crate::ConfigDiff::trough_kind_count`] conventions on the peer
/// altitudes, and the `self.as_ref().len()` empty convention on the
/// same chain; the scalar `(peak_layer_kind_count,
/// trough_layer_kind_count)` pair reads uniformly `(0, 0)` on the
/// empty chain. The dual-form [`Self::recessive_layer_kind`] carries
/// `Option<ConfigSourceKind>` because the *kind* is undefined when no
/// layer contributes; the *count* is well-defined as zero. The
/// asymmetry is intentional: every scalar projection reads zero on
/// empty; every cell projection reads `None`.
///
/// # Invariants
///
/// - `trough_layer_kind_count() == 0` ⇔ `self.as_ref().is_empty()` —
/// peer to the empty-chain boundary [`Self::dominant_layer_kind`],
/// [`Self::recessive_layer_kind`], and [`Self::peak_layer_kind_count`]
/// all witness on the cell / count sides. Unlike the file-format
/// and env-prefix sub-axes, the presence bound coincides with
/// `self.as_ref().is_empty()` (every layer projects to exactly one
/// [`ConfigSourceKind`] cell through [`ConfigSource::kind`]).
/// - `trough_layer_kind_count() == layer_kind_histogram().trough_count()`
/// — both project the same scalar off the same primitive; the
/// named seam is the cube-native routing of the chain-shape
/// surface.
/// - `trough_layer_kind_count() == recessive_layer_kind().map_or(0,
/// |k| layer_kind_histogram().count(k))` — the count projection of
/// the `(recessive_layer_kind, trough_layer_kind_count)` anti-modal
/// pair equals [`Self::trough_layer_kind_count`] pointwise on
/// every chain (empty: `None.map_or(0, …) == 0 ==
/// trough_layer_kind_count`; non-empty: `Some(k).map_or(0, |k|
/// count(k)) == trough_layer_kind_count`, since
/// `count(recessive_layer_kind()) == trough_count()`).
/// - `trough_layer_kind_count() <= peak_layer_kind_count()` always:
/// the trough is bounded above by the peak (lifted from the
/// trait-uniform `trough_count() <= peak_count()` law on
/// [`crate::AxisHistogram`]). The empty-chain case reads `0 <= 0`;
/// the non-empty case reads the trough-of-support bounded above by
/// the peak-of-support.
/// - `trough_layer_kind_count() == peak_layer_kind_count()` iff
/// `present_layer_kinds().len() <= 1`: on the empty chain both are
/// 0; on a singleton-support chain both equal `self.as_ref().len()`;
/// on two or more observed kinds with distinct counts the trough
/// is strictly below the peak.
/// - `trough_layer_kind_count() >= 1` whenever
/// `!self.as_ref().is_empty()` — the argmin is taken over the
/// histogram's *support* (nonzero cells), so the trough of a
/// non-empty histogram is always at least one.
/// - `trough_layer_kind_count()` on a uniform per-kind chain (one
/// layer per kind) equals `1` — every observed kind collects one
/// layer; the trough coincides with the peak on the uniform-cover
/// degenerate (the singleton-modality analogue on the count side).
/// - `trough_layer_kind_count()` on a singleton-support chain (every
/// layer on the same kind) equals `self.as_ref().len()` — the sole
/// observed kind is both the modal and anti-modal cell, so
/// `trough == peak == len`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// argmin scan over the support). Both are `O(n)` in practice since
/// the layer-kind axis carries a fixed three-cell cardinality; the
/// returned `usize` reads one scalar. Halves the cost of the previous
/// `recessive_layer_kind().map_or(0, |k|
/// layer_kind_histogram().count(k))` idiom (which walked the
/// histogram twice — once to argmin, once to read the count back).
#[must_use]
fn trough_layer_kind_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().trough_count()
}
/// The **scalar dispersion** of the layer-count distribution across the
/// observed [`ConfigSourceKind`]s on this chain — the layer-kind
/// sub-axis lift of the "spread across altitudes" projection seeded on
/// the diff altitude by [`crate::ConfigDiff::kind_spread`] and climbed
/// to the tier altitude by [`crate::ProvenanceMap::tier_spread`].
/// Returns `0` exactly on every empty chain, every singleton-support
/// chain (only one observed kind, trivially balanced), and every
/// uniform per-kind chain (each observed kind contributing the same
/// nonzero layer count, dominant included).
///
/// The **scalar dispersion peer** of the fused
/// `(peak_layer_kind_count, trough_layer_kind_count)` modal-count pair
/// on the layer-kind sub-axis of the chain altitude — the natural typed
/// primitive for chain-shape dashboards, attestation manifests, and
/// alerting policies asking *"how unevenly distributed are the layers
/// across the observed kinds?"*: the CLI `config-show` summary line
/// *"kind skew 2: File owns 3 of 5 layers, Defaults 1 of 5"* (where 2
/// is this scalar), the attestation manifest recording the layer-kind
/// spread between two `ProviderChain` snapshots, the alerting policy
/// reading *"chain kind spread = 2"* to flag a rebuild window where
/// one layer kind dwarfed the others. Before this lift, every such
/// consumer re-derived the projection inline as
/// `chain.peak_layer_kind_count() - chain.trough_layer_kind_count()`
/// — two method calls plus a subtraction at every site, each site
/// having to reason independently about the structural non-negativity
/// of the difference (`peak_layer_kind_count() >=
/// trough_layer_kind_count()` holds on every chain by lifting the
/// trait-uniform `peak_count() >= trough_count()` law on
/// [`crate::AxisHistogram`], but not on the inline subtraction surface
/// — an unwitnessed refactor swapping the operands would silently
/// underflow). Routes through [`crate::AxisHistogram::spread`] one
/// altitude down — the underflow-safe named seam whose docs pin the
/// monotonicity invariant explicitly.
///
/// The layer-kind sub-axis lift in the "spread across altitudes"
/// projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kind_spread`] and climbed to the tier altitude
/// by [`crate::ProvenanceMap::tier_spread`]. The pattern is the same
/// at every altitude: fuse the (`peak_count`, `trough_count`) modal-
/// count pair into a single dispersion scalar named at the surface,
/// routed through the shared [`crate::AxisHistogram::spread`]
/// primitive one altitude down. The two chain-altitude sub-axis
/// peers [`Self::file_format_spread`] over
/// [`Self::file_format_histogram`] and [`Self::env_prefix_kind_spread`]
/// over [`Self::env_prefix_kind_histogram`] close the projection
/// sideways on the same doc-cited template — the chain-altitude
/// "spread across altitudes" triple
/// `(layer_kind_spread, file_format_spread, env_prefix_kind_spread)`
/// now spans every sub-axis of the chain surface.
///
/// **Empty-chain convention** — returns `0`, matching the
/// [`crate::AxisHistogram::spread`] empty convention one altitude
/// down and the [`Self::peak_layer_kind_count`] /
/// [`Self::trough_layer_kind_count`] empty conventions on the same
/// sub-axis. The scalar-count triple
/// `(peak_layer_kind_count, trough_layer_kind_count,
/// layer_kind_spread)` reads uniformly `(0, 0, 0)` on the empty
/// chain — every observation scalar reads zero on empty; every cell
/// projection ([`Self::dominant_layer_kind`],
/// [`Self::recessive_layer_kind`]) reads `None`. The asymmetry is
/// intentional and matches the [`crate::AxisHistogram`] convention
/// one altitude down.
///
/// **Structural-skew predicate.** `layer_kind_spread() == 0` is the
/// typed *balanced-layer-kinds* predicate at the layer-kind sub-axis
/// of the chain altitude — every observed [`ConfigSourceKind`]
/// contributed the same number of layers. Pointwise equivalent to
/// `peak_layer_kind_count() == trough_layer_kind_count()` on the
/// scalar-count pair and to `dominant_layer_kind() ==
/// recessive_layer_kind()` on the modal-cell pair whenever the chain
/// is non-empty (both branches reduce to `Some(first) == Some(first)`
/// on singleton-support and uniform-cover chains, and to `false` on
/// skewed chains). Together with `self.as_ref().is_empty()` and the
/// full-cover predicate on [`Self::layer_kind_histogram`], the
/// layer-kind sub-axis of the chain-shape surface now carries the
/// natural boundary triple *"did any layer contribute?"* / *"did every
/// kind fire?"* / *"did the kinds fire equally?"* — each a single
/// method call.
///
/// # Invariants
///
/// - `layer_kind_spread() == layer_kind_histogram().spread()` — both
/// project the same scalar off the same primitive; the named seam
/// is the cube-native routing of the histogram surface.
/// - `layer_kind_spread() == peak_layer_kind_count() -
/// trough_layer_kind_count()` — the fused-pair identity of the
/// scalar-dispersion peer. The subtraction is underflow-safe
/// because `peak_layer_kind_count() >= trough_layer_kind_count()`
/// holds structurally on every chain (lifted from the trait-
/// uniform `peak_count() >= trough_count()` law on
/// [`crate::AxisHistogram`]).
/// - `layer_kind_spread() == 0` on the empty chain — the vacuous
/// uniformity boundary, matching the
/// [`crate::AxisHistogram::spread`] empty convention one altitude
/// down. The `(peak_layer_kind_count, trough_layer_kind_count,
/// layer_kind_spread)` triple reads `(0, 0, 0)` uniformly on the
/// empty chain.
/// - `layer_kind_spread() == 0` whenever `present_layer_kinds().len()
/// <= 1` — singleton-support chains are trivially balanced (the one
/// observed kind's count is both the peak and the trough). Also
/// holds on every uniform per-kind chain (each observed kind
/// contributing the same nonzero count, dominant included).
/// - `layer_kind_spread() <= peak_layer_kind_count()` always — the
/// trough is non-negative, so the subtraction is bounded above by
/// the minuend. Equality holds iff the trough is zero — i.e. on
/// the empty chain. Lifted from the trait-uniform `spread() <=
/// peak_count()` law on [`crate::AxisHistogram`].
/// - `layer_kind_spread() <= self.as_ref().len()` always —
/// composition of `layer_kind_spread() <= peak_layer_kind_count()`
/// (this method) with `peak_layer_kind_count() <= self.as_ref().len()`
/// (documented on [`Self::peak_layer_kind_count`]).
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// fused peak-and-trough scan). Both are `O(n)` in practice since
/// the layer-kind axis carries a fixed three-cell cardinality; the
/// returned `usize` reads one scalar. Halves the cost of the
/// previous inline `chain.peak_layer_kind_count() -
/// chain.trough_layer_kind_count()` idiom (which walked the counts
/// vector twice — once for the max, once for the min-over-support —
/// where [`crate::AxisHistogram::spread`] can fuse both into a
/// single walk with a running-max/min pair).
#[must_use]
fn layer_kind_spread(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().spread()
}
/// The **balanced-layer-kinds boolean predicate** on the layer-kind
/// sub-axis of the chain altitude — `true` exactly when every observed
/// [`ConfigSourceKind`] contributed the same number of layers. The
/// typed boolean peer of `layer_kind_spread() == 0` on the scalar-
/// dispersion surface, lifting the same structural-skew boundary from
/// the scalar surface to a named predicate at the layer-kind sub-axis
/// of the chain altitude. Routes through
/// [`crate::AxisHistogram::is_uniform_count`] one altitude down: the
/// single-pass scan over the fixed-cardinality counts vector that
/// short-circuits on the first pair of distinct nonzero cells, tighter
/// than the two-scan [`Self::peak_layer_kind_count`] /
/// [`Self::trough_layer_kind_count`] fusion the scalar-spread form
/// pays for.
///
/// The **balanced-layer-kinds peer** of the fused
/// `(peak_layer_kind_count, trough_layer_kind_count,
/// layer_kind_spread)` dispersion triple on the layer-kind sub-axis of
/// the chain altitude — the natural typed boolean primitive for chain-
/// shape dashboards, attestation manifests, and alerting policies
/// asking *"did every observed layer kind fire equally?"*: the CLI
/// `config-show` headline *"balanced recipe: every observed kind owns
/// the same number of layers"*, the attestation manifest gate
/// *"rebuild window balanced across layer kinds"*, the alerting
/// policy predicate *"chain balanced"*. Before this lift, every such
/// consumer re-derived the predicate inline as
/// `chain.layer_kind_spread() == 0` (the scalar-spread form, which
/// routes through a subtraction whose underflow safety relies on the
/// structural `peak >= trough` invariant on
/// [`Self::layer_kind_spread`]), or as
/// `chain.peak_layer_kind_count() == chain.trough_layer_kind_count()`
/// (the scalar-pair form, which pays for two count walks and equates
/// two `usize`s without saying structurally *what* is being equated),
/// or as `chain.dominant_layer_kind() == chain.recessive_layer_kind()`
/// (the modal-pair form, which peers through
/// `Option<ConfigSourceKind>` equality across two argmax/argmin
/// walks). The three forms drifted in subtle ways at every consumer
/// site. This lift names the balanced-layer-kinds predicate directly
/// at the layer-kind sub-axis with a single-pass short-circuiting
/// scan — the typed boolean every operator-facing "is this recipe
/// balanced?" check reads off as a single method call.
///
/// The layer-kind sub-axis lift in the "balanced across altitudes"
/// projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_balanced`] and climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_balanced`]. The pattern
/// is the same at every altitude / sub-axis: fuse the
/// (`peak_count`, `trough_count`, `spread`) scalar triple's balanced-
/// boundary into a single boolean predicate named at the surface,
/// routed through the shared
/// [`crate::AxisHistogram::is_uniform_count`] primitive one altitude
/// down. Parallels the "spread across altitudes" projection climbed
/// to the same sub-axis by [`Self::layer_kind_spread`]. The two
/// remaining chain-altitude sub-axes are lifted sideways to the same
/// projection: [`Self::file_formats_balanced`] over
/// [`Self::file_format_histogram`] and
/// [`Self::env_prefix_kinds_balanced`] over
/// [`Self::env_prefix_kind_histogram`], closing the "balanced across
/// altitudes" projection across every altitude / sub-axis.
///
/// **Empty-chain convention** — returns `true` vacuously: the empty
/// chain has no observed cells, so the universal "every observed
/// cell carries the same count" reads `true` over the empty support.
/// Matches [`crate::AxisHistogram::is_uniform_count`]'s empty
/// convention one altitude down and `layer_kind_spread() == 0` on
/// the empty case (peak == trough == 0). The empty chain is
/// therefore on the `true` side of the balanced-layer-kinds
/// boundary — the vacuous-uniformity witness.
///
/// **Singleton-support convention** — returns `true` on every chain
/// whose observed support is a single [`ConfigSourceKind`] (trivially
/// balanced: the one observed kind's count is both the peak and the
/// trough). Includes every chain in which one kind owns every layer.
///
/// **Uniform per-kind convention** — returns `true` on every uniform
/// per-kind chain (each observed kind contributing the same nonzero
/// count), including the k-kind-observed-once-each shape and the
/// uniform full-cover shape over all three [`ConfigSourceKind`]
/// cells.
///
/// # Invariants
///
/// - `layer_kinds_balanced() == layer_kind_histogram().is_uniform_count()` —
/// both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram surface.
/// - `layer_kinds_balanced() == (layer_kind_spread() == 0)` always —
/// the defining equivalence on the scalar-spread surface at the
/// layer-kind sub-axis.
/// - `layer_kinds_balanced() == (peak_layer_kind_count() ==
/// trough_layer_kind_count())` always — the structural form on the
/// underlying scalar pair.
/// - `layer_kinds_balanced() == (dominant_layer_kind() ==
/// recessive_layer_kind())` always — the modal-pair form; both
/// branches agree on the empty chain (`None == None`), on every
/// singleton-support chain (`Some(k) == Some(k)`), on every uniform
/// per-kind chain (`Some(first_kind) == Some(first_kind)` after
/// declaration-order tie-break), and on every skewed chain (both
/// sides read `false`).
/// - `self.as_ref().is_empty() ⇒ layer_kinds_balanced()` — vacuous
/// uniformity on the empty chain. Contrapositively,
/// `!layer_kinds_balanced() ⇒ !self.as_ref().is_empty()` (a skewed
/// chain has at least two distinct positive counts, so the chain
/// is non-empty).
/// - `present_layer_kinds().len() <= 1 ⇒ layer_kinds_balanced()` —
/// every chain with support size 0 or 1 is trivially balanced.
/// Contrapositively, `!layer_kinds_balanced() ⇒
/// present_layer_kinds().len() >= 2` (a skewed chain observes at
/// least two distinct kinds with differing counts).
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// uniform-count scan). Both are `O(n)` in practice since the layer-
/// kind axis carries a fixed three-cell cardinality; the returned
/// `bool` reads one predicate. The scan short-circuits on the first
/// pair of distinct nonzero cells (bounded at two nonzero cells
/// visited), strictly tighter than the two-full-scan
/// `peak_layer_kind_count()` / `trough_layer_kind_count()` fusion the
/// scalar-spread form pays for on skewed chains.
#[must_use]
fn layer_kinds_balanced(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().is_uniform_count()
}
/// The **full-cover-layer-kinds boolean predicate** on the
/// layer-kind sub-axis of the chain altitude — `true` exactly when
/// every [`ConfigSourceKind`] cell was observed at least once on
/// this chain. Routes through
/// [`crate::AxisHistogram::is_full_cover`] one altitude down: the
/// single-pass short-circuiting scan over the fixed-cardinality
/// counts vector that stops on the first zero cell, strictly
/// tighter than every coverage-gap / support scalar-equality form
/// one seam over. Operator-facing consumers answering *"did every
/// layer kind fire on this recipe?"* — the CLI `config-show`
/// headline *"full-cover recipe: every layer kind fired at least
/// once"*, the attestation manifest gate *"rebuild window
/// full-cover across layer kinds"*, the alerting policy predicate
/// *"recipe full-cover"* — now route through this named seam
/// instead of four previously drifting inline forms:
/// `chain.absent_layer_kinds().is_empty()` (the coverage-gap-`Vec`
/// form, which allocates a `Vec<ConfigSourceKind>` and reads its
/// emptiness), `chain.absent_layer_kinds_count() == 0` (the
/// coverage-gap-scalar form, which pays for a full-axis scan and
/// equates a `usize` to zero without saying structurally *what* is
/// being equated), `chain.present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>()` (the support-
/// scalar form, which pays for the support scan and pulls in the
/// `axis_cardinality` turbofish at every call site), and
/// `chain.present_layer_kinds().len() ==
/// crate::axis_cardinality::<ConfigSourceKind>()` (the support-
/// `Vec` form, which allocates a `Vec<ConfigSourceKind>` and reads
/// its length back). Pointwise-equivalent with
/// `layer_kind_histogram().unobserved_cells() == 0`,
/// `layer_kind_histogram().distinct_cells() ==
/// crate::axis_cardinality::<ConfigSourceKind>()`, and
/// `layer_kind_histogram().unobserved().next().is_none()` one
/// altitude down.
///
/// **Lifts sideways to the layer-kind sub-axis of the chain
/// altitude** in the "full-cover across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_full_cover`] and climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_full_cover`]. The
/// pattern is the same at every altitude / sub-axis: fuse the
/// (`present_cells`, `absent_cells`, `present_cells_count`,
/// `absent_cells_count`) support / coverage-gap 2×2 grid's
/// full-cover-boundary into a single boolean predicate named at
/// the surface, routed through the shared
/// [`crate::AxisHistogram::is_full_cover`] primitive one altitude
/// down. Parallels the "balanced across altitudes" projection
/// lifted to the same sub-axis by [`Self::layer_kinds_balanced`]
/// and the "spread across altitudes" projection lifted to the
/// same sub-axis by [`Self::layer_kind_spread`]. The two remaining
/// chain-altitude sub-axes are the natural next sideways lifts:
/// [`Self::file_formats_full_cover`] over
/// [`Self::file_format_histogram`] and
/// [`Self::env_prefix_kinds_full_cover`] over
/// [`Self::env_prefix_kind_histogram`], closing the "full-cover
/// across altitudes" projection across every altitude / sub-axis
/// alongside the balanced / spread projections that already closed
/// the same grid.
///
/// **Empty-chain convention** — returns `false` on the empty
/// chain: no observed cells means the coverage gap equals every
/// cell of [`ConfigSourceKind::ALL`] — the full-cover predicate
/// fails. Matches [`crate::AxisHistogram::is_full_cover`]'s
/// empty-histogram convention one altitude down on the non-zero-
/// cardinality [`ConfigSourceKind`] axis (three cells: `Defaults`,
/// `Env`, `File`). The empty chain is therefore on the `false`
/// side of the full-cover-layer-kinds boundary — the dual of the
/// vacuous-uniformity witness on [`Self::layer_kinds_balanced`],
/// which reads `true` on the empty chain.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single [`ConfigSourceKind`]:
/// one observed cell out of three leaves at least two cells in the
/// coverage gap, so the full-cover predicate fails. Every chain in
/// which one kind owns every layer is a witness.
///
/// **Uniform three-kind cover convention** — returns `true` on
/// every chain where each of the three [`ConfigSourceKind`] cells
/// was observed at least once (regardless of per-kind count).
/// Includes the k-kind-observed-once-each shape (one layer per
/// kind) and every skewed three-kind cover.
///
/// # Invariants
///
/// - `layer_kinds_full_cover() ==
/// layer_kind_histogram().is_full_cover()` — both project the
/// same predicate off the same primitive; the named seam is the
/// cube-native routing of the histogram surface.
/// - `layer_kinds_full_cover() == absent_layer_kinds().is_empty()`
/// always — the defining equivalence on the coverage-gap-`Vec`
/// surface at the layer-kind sub-axis.
/// - `layer_kinds_full_cover() == (absent_layer_kinds_count() ==
/// 0)` always — the defining equivalence on the coverage-gap-
/// scalar surface, without allocating the
/// `Vec<ConfigSourceKind>`.
/// - `layer_kinds_full_cover() == (present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>())` always — the
/// support-scalar form, the dual-side surfacing of the same
/// boolean across the (observed, unobserved) partition.
/// - `layer_kinds_full_cover() == (present_layer_kinds().len() ==
/// crate::axis_cardinality::<ConfigSourceKind>())` always — the
/// support-`Vec` form, without allocating twice through
/// [`Vec::len`].
/// - `layer_kinds_full_cover() ⇒ !self.as_ref().is_empty()` — a
/// full-cover chain observes at least one layer per
/// [`ConfigSourceKind`], so the chain is non-empty.
/// Contrapositively, `self.as_ref().is_empty() ⇒
/// !layer_kinds_full_cover()` (the empty-chain / full-coverage-
/// gap boundary).
/// - `layer_kinds_full_cover() ⇒ present_layer_kinds().len() ==
/// crate::axis_cardinality::<ConfigSourceKind>()` — a full-cover
/// chain observes every kind, so the support size equals the
/// axis cardinality. Contrapositively,
/// `present_layer_kinds().len() <
/// crate::axis_cardinality::<ConfigSourceKind>() ⇒
/// !layer_kinds_full_cover()`.
/// - `layer_kinds_full_cover() ⇒ self.as_ref().len() >=
/// crate::axis_cardinality::<ConfigSourceKind>()` — a full-cover
/// chain observes at least one layer per kind, so the chain
/// length is bounded below by the axis cardinality.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<ConfigSourceKind>()`
/// (the full-cover scan). Both are `O(n)` in practice since the
/// layer-kind axis carries a fixed three-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits on
/// the first zero cell (bounded at one zero cell visited on a
/// non-full-cover chain), strictly tighter than the four
/// coverage-gap equality forms — no `Vec<ConfigSourceKind>`
/// allocation, no [`crate::axis_cardinality`] turbofish, no scalar
/// equality against a magic axis-cardinality constant.
#[must_use]
fn layer_kinds_full_cover(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().is_full_cover()
}
/// The **any-observed-layer-kinds boolean predicate** on the
/// layer-kind sub-axis of the chain altitude — `true` exactly when
/// at least one [`ConfigSourceKind`] cell was observed on this
/// chain. Routes through [`crate::AxisHistogram::is_empty`] negated
/// one altitude down: the single-pass short-circuiting scan over the
/// fixed-cardinality counts vector that stops on the first nonzero
/// cell, strictly tighter than every allocation-or-turbofish form
/// one seam over. Operator-facing consumers answering *"did any
/// layer kind fire on this recipe at all?"* — the CLI `config-show`
/// headline *"non-empty recipe: at least one layer kind fired"*,
/// the attestation manifest gate *"rebuild window carries at least
/// one layer observation"*, the alerting policy predicate *"recipe
/// non-empty"* — now route through this named seam instead of four
/// previously drifting inline forms: `!chain.as_ref().is_empty()`
/// (the slice-nonempty form, which projects the boolean off the raw
/// chain slice without saying structurally *what* is being asked at
/// the layer-kind sub-axis), `chain.present_layer_kinds_count() >
/// 0` (the support-scalar form, which pays for a full-axis scan and
/// compares a `usize` to zero without naming the coverage-support
/// boundary), `!chain.present_layer_kinds().is_empty()` (the
/// support-`Vec` form, which allocates a `Vec<ConfigSourceKind>`
/// and reads its emptiness back), and `chain.absent_layer_kinds_count()
/// < crate::axis_cardinality::<ConfigSourceKind>()` (the coverage-
/// gap-scalar form, which pays for the coverage-gap scan and pulls
/// in the `axis_cardinality` turbofish at every call site). Routes
/// through `!AxisHistogram::is_empty` one altitude down.
///
/// **Lifts sideways to the layer-kind sub-axis of the chain
/// altitude** in the "any-observed across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_any_observed`] and climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_any_observed`]. The
/// pattern is the same at every altitude / sub-axis: fuse the
/// (`present_cells`, `absent_cells`, `present_cells_count`,
/// `absent_cells_count`) support / coverage-gap 2×2 grid's non-
/// empty-boundary into a single boolean predicate named at the
/// surface, routed through the shared
/// [`crate::AxisHistogram::is_empty`] primitive one altitude down.
/// Parallels the "full-cover across altitudes" projection lifted to
/// the same sub-axis by [`Self::layer_kinds_full_cover`] and the
/// "balanced across altitudes" projection lifted to the same sub-
/// axis by [`Self::layer_kinds_balanced`]. The two remaining chain-
/// altitude sub-axes are the natural next sideways lifts:
/// `file_formats_any_observed` over
/// [`Self::file_format_histogram`] and `env_prefix_kinds_any_observed`
/// over [`Self::env_prefix_kind_histogram`], closing the "any-
/// observed across altitudes" projection across every altitude /
/// sub-axis alongside the balanced / full-cover projections that
/// already closed the same grid.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// no observed cells means the "any observed" predicate fails.
/// Matches [`crate::AxisHistogram::is_empty`]'s empty-histogram
/// convention negated one altitude down. The empty chain is
/// therefore on the `false` side of the any-observed boundary —
/// matching [`Self::layer_kinds_full_cover`]'s empty-chain `false`
/// polarity and orthogonal to [`Self::layer_kinds_balanced`]'s
/// empty-chain `true` polarity. The three predicates partition the
/// empty chain into the polarity triple (`any_observed`=false,
/// `balanced`=true, `full_cover`=false).
///
/// **Singleton-support convention** — returns `true` on every chain
/// whose observed support is a single [`ConfigSourceKind`]: one
/// observed cell suffices for the any-observed predicate. Every
/// chain in which one kind owns every layer is a witness. Matches
/// [`Self::layer_kinds_balanced`]'s `true` side on the singleton
/// and orthogonal to [`Self::layer_kinds_full_cover`]'s `false`
/// side on the same singleton — the three boundaries partition the
/// singleton-support fixture into the polarity triple
/// (`any_observed`=true, `balanced`=true, `full_cover`=false).
///
/// **Uniform three-kind cover convention** — returns `true` on
/// every chain where each of the three [`ConfigSourceKind`] cells
/// was observed at least once. The uniform three-kind cover is on
/// the `true` side of all three coverage-support boundaries
/// (`any_observed`, `balanced`, `full_cover`).
///
/// # Invariants
///
/// - `layer_kinds_any_observed() == !layer_kind_histogram().is_empty()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `layer_kinds_any_observed() == !self.as_ref().is_empty()`
/// always — every chain layer contributes to a [`ConfigSourceKind`]
/// cell, so the histogram is empty iff the chain slice is empty.
/// - `layer_kinds_any_observed() == (present_layer_kinds_count() >
/// 0)` always — the support-scalar surface, without allocating
/// the `Vec<ConfigSourceKind>`.
/// - `layer_kinds_any_observed() == !present_layer_kinds().is_empty()`
/// always — the support-`Vec` surface.
/// - `layer_kinds_any_observed() == (absent_layer_kinds_count() <
/// crate::axis_cardinality::<ConfigSourceKind>())` always — the
/// coverage-gap-scalar surface, the dual-side surfacing of the
/// same boolean across the (observed, unobserved) partition.
/// - `layer_kinds_full_cover() ⇒ layer_kinds_any_observed()` — a
/// full-cover chain observes every cell, so it observes at least
/// one cell. Contrapositively, `!layer_kinds_any_observed() ⇒
/// !layer_kinds_full_cover()`.
/// - `layer_kinds_any_observed() ⇒ self.as_ref().len() >= 1` — a
/// chain with any observed layer kind carries at least one layer.
/// - `!layer_kinds_any_observed() ⇒ layer_kinds_balanced()` — the
/// empty chain is the only chain on the `false` side of
/// `layer_kinds_any_observed` and it is vacuously balanced.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// any-observed scan). Both are `O(n)` in practice since the layer-
/// kind axis carries a fixed three-cell cardinality; the returned
/// `bool` reads one predicate. The scan short-circuits on the first
/// nonzero cell (bounded at one nonzero cell visited on any non-
/// empty chain), strictly tighter than the four support /
/// coverage-gap equality forms — no `Vec<ConfigSourceKind>`
/// allocation, no [`crate::axis_cardinality`] turbofish, no scalar
/// equality against a magic axis-cardinality constant.
#[must_use]
fn layer_kinds_any_observed(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
!self.layer_kind_histogram().is_empty()
}
/// The **singleton-support-layer-kinds boolean predicate** on the
/// layer-kind sub-axis of the chain altitude — `true` exactly when
/// this chain observes exactly one [`ConfigSourceKind`] cell.
/// Routes through [`crate::AxisHistogram::has_singular_support`] one
/// altitude down: the single-pass short-circuiting scan over the
/// fixed-cardinality counts vector that finds the first nonzero
/// cell and confirms no second nonzero cell follows, strictly
/// tighter than every allocation-or-turbofish form one seam over.
/// Operator-facing consumers answering *"did the recipe land on
/// exactly one layer kind?"* — the CLI `config-show` headline *"one-
/// kind recipe: every layer is a File"*, the attestation manifest
/// gate *"rebuild window carries a single layer-kind"*, the
/// alerting policy predicate *"recipe collapsed to one kind"* —
/// now route through this named seam instead of four previously
/// drifting inline forms: `chain.present_layer_kinds_count() == 1`
/// (the support-scalar form, which pays for a full-axis scan and
/// compares a `usize` to one without saying structurally *what* is
/// being asked at the layer-kind sub-axis),
/// `chain.present_layer_kinds().len() == 1` (the support-`Vec`
/// form, which allocates a `Vec<ConfigSourceKind>` and reads its
/// length back), `chain.absent_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1` (the
/// coverage-gap-scalar form, which pays for a full-axis scan and
/// pulls in the [`crate::axis_cardinality`] turbofish at every
/// call site), and `chain.absent_layer_kinds().len() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1` (the
/// coverage-gap-`Vec` form, which allocates a
/// `Vec<ConfigSourceKind>` and reads its length back).
///
/// **Lifts sideways to the layer-kind sub-axis of the chain
/// altitude** in the "singleton-support across altitudes"
/// projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_singular_support`] and climbed to
/// the tier altitude by
/// [`crate::ProvenanceMap::tiers_singular_support`]. The pattern
/// is the same at every altitude / sub-axis: fuse the
/// (`present_cells`, `absent_cells`, `present_cells_count`,
/// `absent_cells_count`) support / coverage-gap 2×2 grid's
/// exactly-one-cell boundary into a single boolean predicate
/// named at the surface, routed through the shared
/// [`crate::AxisHistogram::has_singular_support`] primitive one
/// altitude down. Parallels the "any-observed across altitudes"
/// projection lifted to the same sub-axis by
/// [`Self::layer_kinds_any_observed`] on the strictly-looser
/// cardinality slice of the same coverage-support partition
/// (`any_observed` = *at-least-one* cell; `singular_support` =
/// *exactly-one* cell), the "full-cover across altitudes"
/// projection lifted to the same sub-axis by
/// [`Self::layer_kinds_full_cover`] on the opposite-extreme
/// cardinality slice, and the "balanced across altitudes"
/// projection lifted to the same sub-axis by
/// [`Self::layer_kinds_balanced`] on the count-uniformity axis.
/// The two remaining chain-altitude sub-axes are the natural next
/// sideways lifts: `file_formats_singular_support` over
/// [`Self::file_format_histogram`] and
/// `env_prefix_kinds_singular_support` over
/// [`Self::env_prefix_kind_histogram`], closing the "singleton-
/// support across altitudes" projection across every altitude /
/// sub-axis alongside the balanced / full-cover / any-observed
/// projections that already closed the same grid.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// no observed cells means the singleton-support predicate fails
/// (support cardinality is 0, not 1). Matches
/// [`crate::AxisHistogram::has_singular_support`]'s empty-histogram
/// `false` convention one altitude down. The empty chain is
/// therefore on the `false` side of the singular-support boundary
/// — matching [`Self::layer_kinds_any_observed`]'s and
/// [`Self::layer_kinds_full_cover`]'s empty-chain `false`
/// polarity, and orthogonal to [`Self::layer_kinds_balanced`]'s
/// empty-chain `true` polarity. The four predicates partition the
/// empty chain into the polarity quadruple (`any_observed`=false,
/// `singular_support`=false, `balanced`=true, `full_cover`=false).
///
/// **Singleton-support convention** — returns `true` on every chain
/// whose observed support is a single [`ConfigSourceKind`]: one
/// observed cell is exactly the singleton-support boundary. Every
/// chain in which one kind owns every layer is a witness. Matches
/// [`Self::layer_kinds_any_observed`]'s and
/// [`Self::layer_kinds_balanced`]'s `true` side on the singleton
/// and orthogonal to [`Self::layer_kinds_full_cover`]'s `false`
/// side on the same singleton — the four boundaries partition the
/// singleton-support fixture into the polarity quadruple
/// (`any_observed`=true, `singular_support`=true,
/// `balanced`=true, `full_cover`=false).
///
/// **Uniform three-kind cover convention** — returns `false` on
/// every chain where each of the three [`ConfigSourceKind`] cells
/// was observed at least once: the support is the full three-cell
/// axis (not one), so the singleton-support predicate fails. The
/// uniform three-kind cover is on the `false` side of the
/// singular-support boundary and on the `true` side of the other
/// three coverage-support boundaries — the four boundaries
/// partition the uniform-cover fixture with (`any_observed`=true,
/// `singular_support`=false, `balanced`=true, `full_cover`=true).
///
/// # Invariants
///
/// - `layer_kinds_singular_support() ==
/// layer_kind_histogram().has_singular_support()` — both project
/// the same predicate off the same primitive; the named seam is
/// the cube-native routing of the histogram surface.
/// - `layer_kinds_singular_support() ==
/// (present_layer_kinds_count() == 1)` always — the support-
/// scalar surface, without allocating the `Vec<ConfigSourceKind>`.
/// - `layer_kinds_singular_support() ==
/// (present_layer_kinds().len() == 1)` always — the support-`Vec`
/// surface.
/// - `layer_kinds_singular_support() == (absent_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1)` always —
/// the coverage-gap-scalar surface, the dual-side surfacing of
/// the same boolean across the (observed, unobserved) partition.
/// - `layer_kinds_singular_support() ⇒ layer_kinds_any_observed()`
/// — a chain with exactly one observed cell has at least one
/// observed cell. Contrapositively,
/// `!layer_kinds_any_observed() ⇒ !layer_kinds_singular_support()`.
/// - `layer_kinds_singular_support() ⇒ layer_kinds_balanced()` — a
/// chain with exactly one observed count has a trivially uniform
/// support (one count is vacuously equal to itself), so the
/// balanced predicate holds.
/// - `layer_kinds_singular_support() ⇒ !layer_kinds_full_cover()`
/// on every axis with cardinality `>= 2` (every implementor
/// today — [`ConfigSourceKind`] carries three cells): a
/// singleton support has size 1, a full cover has size
/// `axis_cardinality::<A>()` `>= 2`, so the two boundaries are
/// disjoint.
/// - `layer_kinds_singular_support() ⇒ self.as_ref().len() >= 1`
/// — a chain with a singleton support has at least one layer
/// contributing to that one observed cell.
/// - `layer_kinds_singular_support() ⇒ dominant_layer_kind() ==
/// recessive_layer_kind() && dominant_layer_kind().is_some()` —
/// when support is singular, the modal pair collapses to the
/// one observed cell on both sides.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// singular-support scan). Both are `O(n)` in practice since the
/// layer-kind axis carries a fixed three-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits
/// on the second nonzero cell (bounded at two nonzero cells
/// visited on any two-or-more-cell-support chain), strictly
/// tighter than the four support / coverage-gap equality forms
/// — no `Vec<ConfigSourceKind>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no scalar equality
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn layer_kinds_singular_support(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().has_singular_support()
}
/// Returns `true` exactly when this chain observes every
/// [`ConfigSourceKind`] cell except one — the singleton-gap
/// boundary of the coverage-support partition on the layer-kind
/// sub-axis of the chain altitude.
///
/// The cube-native answer to *"did this chain miss exactly one
/// layer-kind cell?"*, routed through the shared
/// [`crate::AxisHistogram::has_singular_gap`] primitive on
/// [`Self::layer_kind_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard singleton-gap
/// headline over the chain's layer-kind composition, the
/// attestation manifest gate *"chain observes all-but-one layer
/// kind"*, the alerting policy predicate *"layer-kind gap
/// singular"* — now route through this named seam instead of four
/// previously drifting inline forms: `chain.absent_layer_kinds_count()
/// == 1` (coverage-gap-scalar), `chain.absent_layer_kinds().len() ==
/// 1` (coverage-gap-`Vec`), `chain.present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1` (support-
/// scalar, which pays for a full-axis scan and pulls in the
/// [`crate::axis_cardinality`] turbofish at every call site), and
/// `chain.present_layer_kinds().len() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1` (support-
/// `Vec`, which allocates a `Vec<ConfigSourceKind>` and reads its
/// length back). The four forms drifted in subtle ways at every
/// consumer site (allocation vs. scalar, turbofish vs. name-only,
/// coverage-gap side vs. support side). This lift names the
/// singleton-gap-layer-kinds predicate directly at the chain-
/// altitude surface with a single-pass short-circuiting scan.
///
/// **Lifts sideways to the layer-kind sub-axis of the chain
/// altitude** in the "singleton-gap across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_singular_gap`] and climbed to the
/// tier altitude by
/// [`crate::ProvenanceMap::tiers_singular_gap`]. Dual of the
/// closed "singleton-support across altitudes" projection lifted
/// to the same sub-axis by [`Self::layer_kinds_singular_support`]
/// on the *complementary* cardinality slice of the same coverage-
/// support partition (`singular_support` = *exactly-one* observed
/// cell; `singular_gap` = *exactly-one* unobserved cell). Parallels
/// the "any-observed across altitudes" projection lifted to the
/// same sub-axis by [`Self::layer_kinds_any_observed`] on the
/// strictly-looser cardinality slice of the same partition
/// (`any_observed` = *at-least-one* cell), the "full-cover across
/// altitudes" projection lifted to the same sub-axis by
/// [`Self::layer_kinds_full_cover`] on the opposite-extreme
/// cardinality slice, and the "balanced across altitudes"
/// projection lifted to the same sub-axis by
/// [`Self::layer_kinds_balanced`] on the count-uniformity axis.
/// The two remaining chain-altitude sub-axes are the natural next
/// sideways lifts: `file_formats_singular_gap` over
/// [`Self::file_format_histogram`] and
/// `env_prefix_kinds_singular_gap` over
/// [`Self::env_prefix_kind_histogram`], closing the "singleton-gap
/// across altitudes" projection across every altitude / sub-axis
/// alongside the balanced / full-cover / any-observed /
/// singular-support projections that already closed the same grid.
///
/// **Empty-chain convention** — returns `false` on the empty chain
/// (on every axis with cardinality `>= 2`, i.e. every implementor
/// today — [`ConfigSourceKind`] carries three cells): the empty
/// chain has every cell unobserved (three, not one), so the
/// singleton-gap predicate fails. Matches
/// [`crate::AxisHistogram::has_singular_gap`]'s empty-histogram
/// `false` convention one altitude down. The empty chain is
/// therefore on the `false` side of the singular-gap boundary —
/// matching [`Self::layer_kinds_any_observed`]'s and
/// [`Self::layer_kinds_full_cover`]'s and
/// [`Self::layer_kinds_singular_support`]'s empty-chain `false`
/// polarity, and orthogonal to [`Self::layer_kinds_balanced`]'s
/// empty-chain `true` polarity. The five predicates partition the
/// empty chain into the polarity quintuple (`any_observed`=false,
/// `singular_support`=false, `singular_gap`=false, `balanced`=true,
/// `full_cover`=false).
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single [`ConfigSourceKind`]:
/// two cells are unobserved on the three-cell axis (not one), so
/// the singleton-gap predicate fails. Every chain in which one
/// kind owns every layer is a witness on the `false` side. The
/// singleton-support fixture partitions the five coverage-support
/// boundaries with (`any_observed`=true, `singular_support`=true,
/// `singular_gap`=false, `balanced`=true, `full_cover`=false) —
/// orthogonal to `singular_gap` on this axis.
///
/// **Two-kind partial cover convention** — returns `true` on every
/// chain whose observed support is exactly two [`ConfigSourceKind`]
/// cells: one cell is unobserved (three total minus two observed
/// equals one unobserved), exactly the singleton-gap boundary.
/// [`crate::ConfigSourceChain`]'s `sample_chain()` (two `File` +
/// one `Env`) is a witness: `Defaults` is silent, satisfying the
/// singular-gap. The two-kind partial cover fixture partitions the
/// five coverage-support boundaries with (`any_observed`=true,
/// `singular_support`=false, `singular_gap`=true, `balanced`=either
/// polarity depending on per-kind counts, `full_cover`=false) —
/// the row this predicate isolates from the surrounding boundaries.
///
/// **Uniform three-kind cover convention** — returns `false` on
/// every chain where each of the three [`ConfigSourceKind`] cells
/// was observed at least once: zero cells are unobserved (not
/// one), so the singleton-gap predicate fails. Matches
/// [`Self::layer_kinds_full_cover`]'s `true` side on the same
/// fixture — the two boundaries `singular_gap` and `full_cover`
/// are disjoint at the top of the coverage-support partition
/// (adjacent support cardinalities `axis_cardinality - 1` and
/// `axis_cardinality`). The uniform three-kind cover partitions
/// the five coverage-support boundaries with (`any_observed`=true,
/// `singular_support`=false, `singular_gap`=false, `balanced`=true,
/// `full_cover`=true).
///
/// # Invariants
///
/// - `layer_kinds_singular_gap() ==
/// layer_kind_histogram().has_singular_gap()` — both project the
/// same predicate off the same primitive; the named seam is the
/// cube-native routing of the histogram surface.
/// - `layer_kinds_singular_gap() == (absent_layer_kinds_count() == 1)`
/// always — the coverage-gap-scalar surface, without allocating
/// the `Vec<ConfigSourceKind>`.
/// - `layer_kinds_singular_gap() == (absent_layer_kinds().len() == 1)`
/// always — the coverage-gap-`Vec` surface.
/// - `layer_kinds_singular_gap() == (present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1)` always —
/// the support-scalar surface, the dual-side surfacing of the
/// same boolean across the (observed, unobserved) partition.
/// - `layer_kinds_singular_gap() == (present_layer_kinds().len() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1)` always —
/// the support-`Vec` surface.
/// - `layer_kinds_singular_gap() ⇒ layer_kinds_any_observed()` on
/// every axis with cardinality `>= 2` (every implementor today
/// — [`ConfigSourceKind`] carries three cells): a chain missing
/// exactly one cell observes at least `axis_cardinality - 1 >= 1`
/// cells. Contrapositively, `!layer_kinds_any_observed() ⇒
/// !layer_kinds_singular_gap()`.
/// - `layer_kinds_singular_gap() ⇒ !layer_kinds_full_cover()`
/// always: full cover has zero unobserved cells, singular gap
/// has exactly one, so the two boundaries are disjoint on every
/// axis.
/// - `layer_kinds_singular_gap() ⇒ !layer_kinds_singular_support()`
/// on every axis with cardinality `>= 3` (every implementor
/// today — [`ConfigSourceKind`] carries three cells): singleton-
/// support has support cardinality `1`, singleton-gap has
/// support cardinality `axis_cardinality - 1 >= 2`, so the two
/// are disjoint. On the cardinality-`2` corner (no chain-
/// altitude sub-axis today) the two coincide pointwise.
/// - `layer_kinds_singular_gap() ⇒ self.as_ref().len() >=
/// crate::axis_cardinality::<ConfigSourceKind>() - 1` — a chain
/// missing exactly one cell has at least one layer for each of
/// the `axis_cardinality - 1` observed cells.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// singular-gap scan). Both are `O(n)` in practice since the
/// layer-kind axis carries a fixed three-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits on
/// the second zero cell (bounded at two zero cells visited on any
/// two-or-more-cell-gap chain), strictly tighter than the four
/// support / coverage-gap equality forms — no
/// `Vec<ConfigSourceKind>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no scalar equality
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn layer_kinds_singular_gap(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().has_singular_gap()
}
/// Returns `true` exactly when this chain's observed
/// [`ConfigSourceKind`] support sits *strictly between* the two
/// singular-cardinality boundaries — at least *two* observed cells
/// *and* at least *two* unobserved cells. The boundary-free interior
/// of the coverage-support partition strictly inside the middle leg
/// of the coarser coverage trichotomy on the layer-kind sub-axis of
/// the chain altitude.
///
/// The cube-native answer to *"did this chain land in the strict
/// interior of the layer-kind support-cardinality interval — neither
/// on a singular boundary nor on a coverage boundary?"*, routed
/// through the shared
/// [`crate::AxisHistogram::has_strict_partial_cover`] primitive on
/// [`Self::layer_kind_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard strict-interior
/// headline over the chain's layer-kind composition, the
/// attestation manifest gate *"chain layer-kind support strictly
/// interior"*, the alerting policy predicate *"layer-kind support
/// strictly interior"* — now route through this named seam instead
/// of four previously drifting inline forms:
/// `chain.layer_kind_histogram().has_partial_cover() &&
/// !chain.layer_kinds_singular_support() &&
/// !chain.layer_kinds_singular_gap()` (structural conjunction on
/// three named predicates), `1 < chain.present_layer_kinds_count()
/// && chain.present_layer_kinds_count() + 1 <
/// crate::axis_cardinality::<ConfigSourceKind>()` (support-scalar
/// strict-interval with [`crate::axis_cardinality`] turbofish and
/// `+ 1 <` arithmetic), `1 < chain.absent_layer_kinds_count() &&
/// chain.absent_layer_kinds_count() + 1 <
/// crate::axis_cardinality::<ConfigSourceKind>()` (coverage-gap-
/// scalar strict-interval on the complementary side), and
/// `chain.present_layer_kinds().len() >= 2 &&
/// chain.absent_layer_kinds().len() >= 2` (dual-`Vec` at-least-two-
/// of-each, allocating two vectors just to peek their lengths).
///
/// **Lifts sideways to the layer-kind sub-axis of the chain
/// altitude** in the "strict-partial-cover across altitudes"
/// projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_strict_partial_cover`] and climbed to
/// the tier altitude by
/// [`crate::ProvenanceMap::tiers_strict_partial_cover`]. Middle-leg-
/// corner peer of the five already-closed coverage-support boundary
/// families on the same sub-axis
/// ([`Self::layer_kinds_balanced`], [`Self::layer_kinds_full_cover`],
/// [`Self::layer_kinds_any_observed`],
/// [`Self::layer_kinds_singular_support`],
/// [`Self::layer_kinds_singular_gap`]) — the last unnamed corner of
/// the 5-corner support-cardinality partition on the layer-kind
/// sub-axis. The two remaining chain-altitude sub-axes are the
/// natural next sideways lifts: `file_formats_strict_partial_cover`
/// over [`Self::file_format_histogram`] and
/// `env_prefix_kinds_strict_partial_cover` over
/// [`Self::env_prefix_kind_histogram`], closing the "strict-partial-
/// cover across altitudes" projection across every altitude / sub-
/// axis alongside the five previously-closed rows and promoting the
/// coverage-support predicate cube from 5×5 to 6×5 corners.
///
/// **Cardinality-`3` reachability at the chain layer-kind sub-axis
/// — vacuously `false` on every chain.** The strict interior carries
/// witnesses only on axes with `axis_cardinality::<A>() >= 4` (the
/// strict interval `[2, cardinality - 2]` is empty on cardinality
/// `0`, `1`, `2`, or `3`). [`ConfigSourceKind`] carries three cells,
/// so `layer_kinds_strict_partial_cover()` reads `false` on every
/// chain regardless of the observed support — the empty chain (0
/// observed), every singleton-support chain (1 observed), every
/// two-kind partial cover (2 observed, gap 1), and every uniform
/// three-kind cover (3 observed, gap 0) all read `false`. Matches
/// the diff-altitude peer
/// [`crate::ConfigDiff::kinds_strict_partial_cover`], where
/// [`crate::tiered::DiffLineKind`] also carries three cells and the
/// predicate is likewise vacuously `false`. The value of this lift
/// at the chain layer-kind sub-axis lies in naming the boundary at
/// the surface for downstream consumers reading the recipe — not in
/// its witnesses, which are structurally empty by the cardinality-
/// conditional-reachability trait-uniform law on
/// [`crate::AxisHistogram::has_strict_partial_cover`] one altitude
/// down. The remaining two chain sub-axes carry the same vacuously-
/// `false` polarity on
/// [`crate::env_metadata::EnvMetadataTagKind`] (cardinality `2`) and
/// a witness on [`crate::discovery::Format`] (cardinality `4`) — the
/// only chain-altitude sub-axis where the strict interior is
/// reachable.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain has zero observed cells, so the "at least two
/// observed" half of the conjunction fails uniformly. Matches
/// [`crate::AxisHistogram::has_strict_partial_cover`]'s empty-
/// histogram `false` convention one altitude down. The empty chain
/// is therefore on the `false` side of the strict-interior boundary
/// — matching [`Self::layer_kinds_any_observed`]'s empty-chain
/// `false` polarity, [`Self::layer_kinds_full_cover`]'s empty-chain
/// `false` polarity, [`Self::layer_kinds_singular_support`]'s empty-
/// chain `false` polarity, and [`Self::layer_kinds_singular_gap`]'s
/// empty-chain `false` polarity.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single [`ConfigSourceKind`]
/// cell: the support cardinality is `1` (not `>= 2`), so the "at
/// least two observed" half fails uniformly.
///
/// **Two-kind partial cover convention** — returns `false` on every
/// chain whose observed support is exactly two [`ConfigSourceKind`]
/// cells: only one cell is unobserved (three total minus two
/// observed equals one unobserved), so the "at least two unobserved"
/// half fails uniformly. Direct witness of
/// `layer_kinds_singular_gap ⇒ !layer_kinds_strict_partial_cover`
/// on the cardinality-`3` [`ConfigSourceKind`] axis.
///
/// **Uniform three-kind cover convention** — returns `false` on
/// every chain where each [`ConfigSourceKind`] cell was observed at
/// least once: zero cells are unobserved, so the "at least two
/// unobserved" half fails uniformly. Matches
/// [`crate::AxisHistogram::has_strict_partial_cover`]'s full-cover
/// `false` convention one altitude down.
///
/// # Invariants
///
/// - `layer_kinds_strict_partial_cover() ==
/// layer_kind_histogram().has_strict_partial_cover()` — both
/// project the same predicate off the same primitive; the named
/// seam is the cube-native routing of the histogram surface.
/// - `layer_kinds_strict_partial_cover() ⇔
/// layer_kind_histogram().has_partial_cover() &&
/// !layer_kinds_singular_support() && !layer_kinds_singular_gap()`
/// always — the defining structural-conjunction form on the
/// existing named-boundary triad: the strict interior is exactly
/// the partial-cover middle leg minus its two singular-cardinality
/// corners.
/// - `layer_kinds_strict_partial_cover() == (1 <
/// present_layer_kinds_count() && present_layer_kinds_count() + 1
/// < crate::axis_cardinality::<ConfigSourceKind>())` always — the
/// support-scalar strict-interval form, without allocating the
/// `Vec<ConfigSourceKind>`.
/// - `layer_kinds_strict_partial_cover() == (1 <
/// absent_layer_kinds_count() && absent_layer_kinds_count() + 1
/// < crate::axis_cardinality::<ConfigSourceKind>())` always — the
/// coverage-gap-scalar strict-interval form on the complementary
/// side of the same partition.
/// - `layer_kinds_strict_partial_cover() ⇒
/// layer_kinds_any_observed()` on every axis with cardinality
/// `>= 4`. On [`ConfigSourceKind`] (cardinality `3`) the
/// antecedent never fires so the implication holds vacuously.
/// Contrapositively, `!layer_kinds_any_observed() ⇒
/// !layer_kinds_strict_partial_cover()`.
/// - `layer_kinds_strict_partial_cover() ⇒
/// !layer_kinds_full_cover()` always: the strict interior
/// requires `>= 2` unobserved cells, a full cover has zero
/// unobserved cells.
/// - `layer_kinds_strict_partial_cover() ⇒
/// !layer_kinds_singular_support()` always: the strict interior
/// requires `>= 2` observed cells, a singleton support has
/// exactly `1` observed cell.
/// - `layer_kinds_strict_partial_cover() ⇒
/// !layer_kinds_singular_gap()` always: the strict interior
/// requires `>= 2` unobserved cells, a singleton gap has exactly
/// `1` unobserved cell.
/// - `layer_kinds_strict_partial_cover() ⇒ self.as_ref().len() >= 2`
/// — a chain with `>= 2` observed cells has at least one layer on
/// each observed cell.
/// - `(!layer_kinds_any_observed, layer_kinds_singular_support,
/// layer_kinds_strict_partial_cover, layer_kinds_singular_gap,
/// layer_kinds_full_cover)` is pairwise disjoint on every chain —
/// distinct support cardinalities `0`, `1`, `[2, cardinality - 2]`,
/// `cardinality - 1`, `cardinality` never overlap. Together the
/// five predicates partition every chain on the layer-kind sub-
/// axis (exactly one of the five corners fires per chain).
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// strict-partial-cover scan). Both are `O(n)` in practice since
/// the layer-kind axis carries a fixed three-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits
/// once it has witnessed both *two* zero counts and *two* nonzero
/// counts (bounded at four witness cells visited on any strict-
/// interior histogram — unreachable on cardinality-`3` axes),
/// strictly tighter than the four documented open-coded surfaces —
/// no `Vec<ConfigSourceKind>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no dual scalar equality
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn layer_kinds_strict_partial_cover(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().has_strict_partial_cover()
}
/// Returns `true` exactly when this chain's observed
/// [`ConfigSourceKind`] support sits at the *bottom* of the
/// support-cardinality interval — at most *one* observed cell.
/// The **low-support-layer-kinds boolean predicate** on the
/// layer-kind sub-axis of the chain altitude, the union-of-low-
/// boundaries corner of the support-cardinality magnitude-
/// direction ternary partition `(low_support,
/// strict_partial_cover, high_support)` — the bottom leg of the
/// magnitude ternary, folding the empty-chain and the
/// singleton-support boundaries into a single named
/// low-magnitude corner.
///
/// The cube-native answer to *"did this chain land in the
/// low-magnitude corner of the layer-kind support-cardinality
/// interval?"*, routed through the shared
/// [`crate::AxisHistogram::has_low_support`] primitive on
/// [`Self::layer_kind_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard low-magnitude
/// headline over the chain's layer-kind composition, the
/// attestation manifest gate *"chain layer-kind support at most
/// singleton"*, the alerting policy predicate *"layer-kind
/// support low-magnitude"* — now route through this named seam
/// instead of four previously drifting inline forms: defining-
/// union-of-low-boundaries disjunction on the two named
/// histogram-side peers (`!chain.layer_kinds_any_observed() ||
/// chain.layer_kinds_singular_support()`), support-scalar
/// at-most-one form (`chain.present_layer_kinds_count() <= 1`),
/// support-`Vec` at-most-one form
/// (`chain.present_layer_kinds().len() <= 1`, allocating a
/// `Vec<ConfigSourceKind>` just to peek its length), and
/// coverage-gap-scalar at-least-axis-cardinality-minus-one form
/// (`chain.absent_layer_kinds_count() >=
/// crate::axis_cardinality::<ConfigSourceKind>() - 1` with
/// [`crate::axis_cardinality`] turbofish and `- 1` arithmetic).
///
/// **Lifts sideways to the layer-kind sub-axis of the chain
/// altitude** in the "low-support across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_low_support`] and climbed to the
/// tier altitude by [`crate::ProvenanceMap::tiers_low_support`].
/// Bottom-leg-corner peer of the six already-closed coverage-
/// support boundary and interior families on the same sub-axis
/// ([`Self::layer_kinds_balanced`], [`Self::layer_kinds_full_cover`],
/// [`Self::layer_kinds_any_observed`],
/// [`Self::layer_kinds_singular_support`],
/// [`Self::layer_kinds_singular_gap`],
/// [`Self::layer_kinds_strict_partial_cover`]). The two
/// remaining chain-altitude sub-axes are the natural next
/// sideways lifts: `file_formats_low_support` over
/// [`Self::file_format_histogram`] and
/// `env_prefix_kinds_low_support` over
/// [`Self::env_prefix_kind_histogram`], closing the "low-support
/// across altitudes" projection alongside the coverage-support
/// predicate cube already carrying six rows and continuing the
/// magnitude-direction ternary vertical row by row.
///
/// **Cardinality-`3` reachability at the chain layer-kind
/// sub-axis — non-vacuous witnesses on both sides.** The bottom
/// magnitude corner carries witnesses on every axis with
/// `axis_cardinality::<A>() >= 1` (the empty chain always
/// witnesses low support via the "at most one observed"
/// clause). [`ConfigSourceKind`] carries three cells, so
/// `layer_kinds_low_support()` reads `true` on the empty chain
/// and on every singleton-support chain (all layers attributed
/// to only-`Defaults`, only-`Env`, or only-`File`), and `false`
/// on every two-or-more-cell-cover chain (two-kind partial
/// cover, uniform three-kind cover). Strictly wider than the
/// strict-interior predicate
/// [`Self::layer_kinds_strict_partial_cover`] whose support-
/// cardinality interval `[2, cardinality - 2]` is empty on
/// cardinality-`3` axes — the low-magnitude corner remains
/// non-vacuous on both sides of the boundary. Matches the
/// diff-altitude peer [`crate::ConfigDiff::kinds_low_support`]
/// on the same cardinality-`3`
/// [`crate::tiered::DiffLineKind`] axis.
///
/// **Empty-chain convention** — returns `true` on the empty
/// chain: zero observed cells satisfy the "at most one
/// observed" clause vacuously. Matches
/// [`crate::AxisHistogram::has_low_support`]'s empty-histogram
/// `true` convention one altitude down, and diverges from
/// [`Self::layer_kinds_any_observed`]'s empty-chain `false`
/// polarity — the low-support boundary strictly includes the
/// empty chain by folding the "no observation" case into the
/// low-magnitude corner.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single [`ConfigSourceKind`]
/// cell: support cardinality `1` satisfies `<= 1`. Peer of
/// [`Self::layer_kinds_singular_support`]'s `true` side on the
/// same fixture — the singleton-support boundary fires into the
/// low-magnitude corner via the union-of-low-boundaries
/// disjunction.
///
/// **Two-kind partial cover convention** — returns `false` on
/// every chain whose observed support is exactly two
/// [`ConfigSourceKind`] cells: support cardinality `2` violates
/// `<= 1`. Direct witness of
/// `layer_kinds_singular_gap ⇒ !layer_kinds_low_support` on the
/// cardinality-`3` axis where the singleton-gap slice sits at
/// support cardinality `axis_cardinality - 1 = 2`.
///
/// **Uniform three-kind cover convention** — returns `false` on
/// every chain where each [`ConfigSourceKind`] cell was
/// observed at least once: support cardinality `3` violates
/// `<= 1`. Matches
/// [`crate::AxisHistogram::has_low_support`]'s full-cover
/// `false` convention one altitude down on cardinality-`>= 2`
/// axes.
///
/// # Invariants
///
/// - `layer_kinds_low_support() ==
/// layer_kind_histogram().has_low_support()` — both project
/// the same predicate off the same primitive; the named seam
/// is the cube-native routing of the histogram surface.
/// - `layer_kinds_low_support() ⇔ !layer_kinds_any_observed()
/// || layer_kinds_singular_support()` always — the defining
/// union-of-low-boundaries disjunction on the two named
/// histogram-side peers.
/// - `layer_kinds_low_support() ==
/// (present_layer_kinds_count() <= 1)` always — the
/// support-scalar at-most-one form, without allocating the
/// `Vec<ConfigSourceKind>`.
/// - `layer_kinds_low_support() ==
/// (present_layer_kinds().len() <= 1)` always — the
/// support-`Vec` at-most-one form.
/// - `layer_kinds_low_support() == (absent_layer_kinds_count() >=
/// crate::axis_cardinality::<ConfigSourceKind>() - 1)` always —
/// the coverage-gap-scalar at-least-axis-cardinality-minus-one
/// form, the dual-side surfacing of the same boolean across the
/// (observed, unobserved) partition.
/// - `layer_kinds_low_support() ⇒ !layer_kinds_full_cover()`
/// on every axis with `axis_cardinality::<A>() >= 2` (every
/// implementor today — [`ConfigSourceKind`] carries three
/// cells): low support has size `<= 1`, full cover has size
/// `axis_cardinality >= 2`.
/// - `layer_kinds_low_support() ⇒ !layer_kinds_singular_gap()`
/// on every axis with `axis_cardinality::<A>() >= 3` (every
/// implementor today — [`ConfigSourceKind`] carries three
/// cells): low support has size `<= 1`, singular-gap has
/// support size `axis_cardinality - 1 >= 2`.
/// - `layer_kinds_low_support() ⇒
/// !layer_kinds_strict_partial_cover()` always: the strict
/// interior requires `>= 2` observed cells; low support has
/// `<= 1`. On the cardinality-`3` `ConfigSourceKind` axis
/// this holds vacuously (the consequent is always `true`).
/// - `!layer_kinds_any_observed() ⇒ layer_kinds_low_support()`
/// always — the empty chain always sits at the bottom of the
/// magnitude interval.
/// - `layer_kinds_singular_support() ⇒
/// layer_kinds_low_support()` always — every singleton-
/// support chain lands on the low-magnitude corner by the
/// union-of-low-boundaries disjunction.
/// - `(layer_kinds_low_support, layer_kinds_strict_partial_cover,
/// layer_kinds_high_support)` forms a strict ternary
/// partition on every axis with `axis_cardinality::<A>() >=
/// 2` — pinned trait-uniformly one altitude down by
/// `axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<ConfigSourceKind>()`
/// (the low-support scan). Both are `O(n)` in practice since
/// the layer-kind axis carries a fixed three-cell cardinality;
/// the returned `bool` reads one predicate. The scan short-
/// circuits once it has witnessed the *second* nonzero cell
/// (bounded at two nonzero cells visited on any two-or-more-
/// cell-support chain), strictly tighter than the four
/// documented open-coded surfaces — no `Vec<ConfigSourceKind>`
/// allocation, no [`crate::axis_cardinality`] turbofish, no
/// `- 1` arithmetic against a magic axis-cardinality-minus-one
/// constant.
#[must_use]
fn layer_kinds_low_support(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().has_low_support()
}
/// Returns `true` exactly when this chain's observed
/// [`ConfigSourceKind`] support sits at the *top* of the
/// support-cardinality interval — at most *one* unobserved cell,
/// excising the cardinality-`2` dual-singular-collapse case
/// (`ConfigSourceKind` carries three cells so the excision never
/// fires at the layer-kind sub-axis). The **high-support-layer-
/// kinds boolean predicate** on the layer-kind sub-axis of the
/// chain altitude, the strict-singular-gap-or-full-cover corner
/// of the support-cardinality magnitude-direction ternary
/// partition `(low_support, strict_partial_cover, high_support)`
/// — the top leg of the magnitude ternary, folding the full-
/// cover and the strict singleton-gap boundaries into a single
/// named high-magnitude corner.
///
/// The cube-native answer to *"did this chain land in the
/// high-magnitude corner of the layer-kind support-cardinality
/// interval?"*, routed through the shared
/// [`crate::AxisHistogram::has_high_support`] primitive on
/// [`Self::layer_kind_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard high-magnitude
/// headline over the chain's layer-kind composition, the
/// attestation manifest gate *"chain layer-kind support at least
/// axis-cardinality-minus-one"*, the alerting policy predicate
/// *"layer-kind support high-magnitude"* — now route through
/// this named seam instead of four previously drifting inline
/// forms: defining strict-singular-gap-or-full-cover disjunction
/// on three named histogram-side peers
/// (`chain.layer_kinds_full_cover() ||
/// (chain.layer_kinds_singular_gap() &&
/// !chain.layer_kinds_singular_support())`), coverage-gap-scalar
/// dual-interval form (`chain.absent_layer_kinds_count() <= 1 &&
/// chain.present_layer_kinds_count() >= 2`), support-scalar
/// dual-interval form (`chain.present_layer_kinds_count() + 1 >=
/// crate::axis_cardinality::<ConfigSourceKind>() &&
/// chain.present_layer_kinds_count() >= 2`), and support-`Vec`
/// dual-length form (`chain.present_layer_kinds().len() + 1 >=
/// crate::axis_cardinality::<ConfigSourceKind>() &&
/// chain.present_layer_kinds().len() >= 2`, allocating a
/// `Vec<ConfigSourceKind>` just to peek its length).
///
/// **Lifts sideways to the layer-kind sub-axis of the chain
/// altitude** in the "high-support across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_high_support`] and climbed to the
/// tier altitude by [`crate::ProvenanceMap::tiers_high_support`].
/// Top-leg-corner peer of the seven already-closed coverage-
/// support and magnitude boundary and interior families on the
/// same sub-axis ([`Self::layer_kinds_balanced`],
/// [`Self::layer_kinds_full_cover`],
/// [`Self::layer_kinds_any_observed`],
/// [`Self::layer_kinds_singular_support`],
/// [`Self::layer_kinds_singular_gap`],
/// [`Self::layer_kinds_strict_partial_cover`],
/// [`Self::layer_kinds_low_support`]). The two remaining chain-
/// altitude sub-axes are the natural next sideways lifts:
/// `file_formats_high_support` over
/// [`Self::file_format_histogram`] and
/// `env_prefix_kinds_high_support` over
/// [`Self::env_prefix_kind_histogram`], closing the "high-
/// support across altitudes" projection alongside the parallel
/// low-support projection and continuing the magnitude-direction
/// ternary vertical row by row.
///
/// **Cardinality-`3` reachability at the chain layer-kind
/// sub-axis — non-vacuous witnesses on both sides, degenerate
/// ternary.** The top magnitude corner carries witnesses on
/// every axis with `axis_cardinality::<A>() >= 2` (the full-
/// cover fixture always witnesses high support via the
/// `is_full_cover()` disjunct). [`ConfigSourceKind`] carries
/// three cells, so `layer_kinds_high_support()` reads `true` on
/// every two-kind partial cover (support size
/// `axis_cardinality - 1 = 2`, `layer_kinds_singular_gap` fires)
/// and every uniform three-kind cover (support size `3`,
/// `layer_kinds_full_cover` fires), and `false` on the empty
/// chain and on every singleton-support chain. The strict-
/// interior middle leg [`Self::layer_kinds_strict_partial_cover`]
/// is vacuously `false` on the cardinality-`3` layer-kind axis
/// (the strict interval `[2, cardinality - 2] = [2, 1]` is
/// empty), so the magnitude-direction ternary degenerates to
/// the dual partition `(layer_kinds_low_support,
/// layer_kinds_high_support)` on this sub-axis — matching the
/// diff-altitude peer [`crate::ConfigDiff::kinds_high_support`]
/// on the same cardinality-`3` [`crate::tiered::DiffLineKind`]
/// axis, and diverging from the tier-altitude peer
/// [`crate::ProvenanceMap::tiers_high_support`] where the
/// cardinality-`4` axis inhabits every leg. The value of the
/// non-vacuous disjointness `layer_kinds_high_support ⇒
/// !layer_kinds_strict_partial_cover` at this sub-axis is the
/// vacuously-`true` closure that transports the ternary
/// discipline verbatim to the tier altitude, where every leg is
/// inhabited.
///
/// **Empty-chain convention** — returns `false` on the empty
/// chain: zero observed cells fail the "at least two observed"
/// clause uniformly. Matches
/// [`crate::AxisHistogram::has_high_support`]'s empty-histogram
/// `false` convention one altitude down for every cardinality-
/// `>= 2` axis. Orthogonal polarity to
/// [`Self::layer_kinds_low_support`]'s empty-chain `true` — the
/// two magnitude corners partition every non-strict-interior
/// fold at the layer-kind sub-axis and the empty chain sits at
/// the *bottom* of the magnitude interval, not the top.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single [`ConfigSourceKind`]
/// cell: support cardinality `1` violates the "at least
/// axis-cardinality-minus-one" clause uniformly on cardinality-
/// `>= 3` axes. Peer of
/// [`Self::layer_kinds_singular_support`]'s `true` side on the
/// same fixture — the singleton-support boundary lands on the
/// low-magnitude corner, not the high-magnitude corner.
///
/// **Two-kind partial cover convention** — returns `true` on
/// every chain whose observed support is exactly two
/// [`ConfigSourceKind`] cells: support cardinality `2` on the
/// cardinality-`3` axis leaves exactly one unobserved cell —
/// `layer_kinds_singular_gap` fires. Direct witness of the
/// strict subsumption `layer_kinds_singular_gap ⇒
/// layer_kinds_high_support` on the cardinality-`>= 3` axis
/// where the dual-singular-collapse never fires. Distinguishes
/// the layer-kind sub-axis from the tier altitude, where two-
/// tier partial cover falls in the strict interior (support
/// size `2` on the cardinality-`4` axis) and lands on
/// `tiers_high_support == false`.
///
/// **Uniform three-kind cover convention** — returns `true` on
/// every chain where each [`ConfigSourceKind`] cell was
/// observed at least once: support cardinality `3` (no
/// unobserved cells) — `layer_kinds_full_cover` fires. Direct
/// witness of the strict subsumption `layer_kinds_full_cover ⇒
/// layer_kinds_high_support` on every axis with
/// `axis_cardinality::<A>() >= 2`. Matches
/// [`crate::AxisHistogram::has_high_support`]'s full-cover
/// `true` convention one altitude down.
///
/// # Invariants
///
/// - `layer_kinds_high_support() ==
/// layer_kind_histogram().has_high_support()` — both project
/// the same predicate off the same primitive; the named seam
/// is the cube-native routing of the histogram surface.
/// - `layer_kinds_high_support() ⇔ layer_kinds_full_cover() ||
/// (layer_kinds_singular_gap() && !layer_kinds_singular_support())`
/// always — the defining strict-singular-gap-or-full-cover
/// disjunction on three named histogram-side peers. The
/// `!layer_kinds_singular_support()` excision is vacuous on
/// the cardinality-`3` layer-kind axis (when singular-gap
/// fires, support size `2 != 1`) but is pinned verbatim so
/// downstream cardinality-`2` sub-axis lifts inherit the
/// dual-singular-collapse excision.
/// - `layer_kinds_high_support() == (absent_layer_kinds_count()
/// <= 1 && present_layer_kinds_count() >= 2)` always — the
/// coverage-gap-scalar dual-interval form on the
/// complementary side of the same partition, without
/// allocating either `Vec<ConfigSourceKind>`.
/// - `layer_kinds_high_support() == (present_layer_kinds_count() + 1 >=
/// crate::axis_cardinality::<ConfigSourceKind>() &&
/// present_layer_kinds_count() >= 2)` always — the support-
/// scalar dual-interval form.
/// - `layer_kinds_high_support() == (present_layer_kinds().len() + 1 >=
/// crate::axis_cardinality::<ConfigSourceKind>() &&
/// present_layer_kinds().len() >= 2)` always — the support-
/// `Vec` dual-length form, the allocating peer of the scalar
/// surface above.
/// - `layer_kinds_high_support() ⇒ !layer_kinds_low_support()`
/// on every axis with `axis_cardinality::<A>() >= 2` (every
/// implementor today — [`ConfigSourceKind`] carries three
/// cells): high support has size `>= 2`, low support has
/// size `<= 1`, so the two magnitude corners are disjoint.
/// - `layer_kinds_high_support() ⇒
/// !layer_kinds_strict_partial_cover()` always: the strict
/// interior requires `>= 2` unobserved cells; high support
/// has `<= 1`. On the cardinality-`3` `ConfigSourceKind`
/// axis this holds vacuously (the consequent is always
/// `true` — the strict interior is unreachable).
/// - `layer_kinds_high_support() ⇒ layer_kinds_any_observed()`
/// on every axis with `axis_cardinality::<A>() >= 2`: high
/// support has size `>= 2 >= 1`, so at least one cell was
/// observed. The empty chain sits on the disjoint
/// `!layer_kinds_any_observed()` boundary at the bottom of
/// the magnitude interval.
/// - `layer_kinds_full_cover() ⇒ layer_kinds_high_support()`
/// always — the strict subsumption over the top full-cover
/// peer via the `is_full_cover()` disjunct on the bridge.
/// The full-cover corner always sits inside the high-
/// magnitude corner.
/// - `layer_kinds_singular_gap() ⇒ layer_kinds_high_support()`
/// on every axis with cardinality `>= 3` (every layer-kind
/// implementor today): singleton-gap has support size
/// `axis_cardinality - 1 >= 2`, so the "at most one
/// unobserved" *and* "at least two observed" clauses both
/// hold. On the cardinality-`2` corner (no layer-kind axis
/// today) the two diverge via the dual-singular-collapse
/// excision.
/// - `(layer_kinds_low_support, layer_kinds_strict_partial_cover,
/// layer_kinds_high_support)` forms a strict ternary partition
/// on every axis with `axis_cardinality::<A>() >= 2`. On the
/// cardinality-`3` layer-kind axis the middle leg is
/// vacuously empty and the ternary degenerates to the dual
/// partition `(layer_kinds_low_support,
/// layer_kinds_high_support)` — pinned trait-uniformly one
/// altitude down by
/// `axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<ConfigSourceKind>()`
/// (the high-support scan). Both are `O(n)` in practice since
/// the layer-kind axis carries a fixed three-cell cardinality;
/// the returned `bool` reads one predicate. The scan short-
/// circuits on the *second* zero cell (bounded at two zero-
/// witness cells visited on any two-or-more-unobserved-cell
/// chain), strictly tighter than the four documented open-
/// coded surfaces — no three-way boolean disjunction across
/// three named predicates, no `Vec<ConfigSourceKind>`
/// allocation, no [`crate::axis_cardinality`] turbofish with
/// `+ 1` arithmetic against a magic threshold.
#[must_use]
fn layer_kinds_high_support(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().has_high_support()
}
/// Returns `true` exactly when this chain's observed
/// [`ConfigSourceKind`] support sits on a *singular near-boundary*
/// — either exactly one observed cell
/// ([`Self::layer_kinds_singular_support`]) or exactly one
/// unobserved cell ([`Self::layer_kinds_singular_gap`]). The
/// **singular-layer-kinds boolean predicate** on the layer-kind
/// sub-axis of the chain altitude, the singular near-boundary
/// corner of the distance-from-boundary ternary partition
/// `(has_boundary, has_singular, has_strict_partial_cover)` —
/// the middle leg of the distance ternary, folding the two
/// singular-cardinality boundaries into a single named one-cell-
/// off-boundary corner. Routes through
/// [`crate::AxisHistogram::has_singular`] one altitude down: the
/// single-pass short-circuiting scan over the fixed-cardinality
/// counts vector that short-circuits the moment both a *second*
/// zero cell *and* a *second* nonzero cell have been witnessed,
/// bounded at four witness cells — strictly tighter than any of
/// the four documented open-coded surfaces one seam over.
///
/// The **singular-layer-kinds peer** of the four documented
/// surface forms consumers previously re-derived inline:
/// `chain.layer_kinds_singular_support() ||
/// chain.layer_kinds_singular_gap()` (the defining-union-of-
/// singular-boundaries disjunction on two named histogram-side
/// peers, a boolean or on two method calls that walks the counts
/// vector twice), `chain.present_layer_kinds_count() == 1 ||
/// chain.present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1` (the
/// support-scalar dual-equality form, which pays for a full-
/// axis scan and equates a `usize` against two magic thresholds
/// with the [`crate::axis_cardinality`] turbofish and `- 1`
/// arithmetic), `chain.present_layer_kinds_count() == 1 ||
/// chain.absent_layer_kinds_count() == 1` (the dual-scalar
/// equality form on the two named cardinality peers, without
/// allocating either `Vec<ConfigSourceKind>`), and
/// `chain.present_layer_kinds().len() == 1 ||
/// chain.absent_layer_kinds().len() == 1` (the dual-`Vec`
/// equality form, which allocates *two* `Vec<ConfigSourceKind>`
/// values just to peek their lengths). The four forms drifted
/// in subtle ways at every consumer site (allocation vs.
/// scalar, turbofish vs. name-only, support side vs. coverage-
/// gap side, structural disjunction vs. dual-equality
/// arithmetic). This lift names the singular-layer-kinds
/// predicate directly at the chain-altitude surface with a
/// single-pass short-circuiting scan — the typed boolean every
/// operator-facing *"did the chain land one layer-kind cell off
/// the coverage boundary?"* check reads off as a single method
/// call.
///
/// **Lifts sideways to the layer-kind sub-axis of the chain
/// altitude** in the "singular across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_singular`] and climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_singular`].
/// Middle-leg-corner peer of the seven already-closed coverage-
/// support and magnitude boundary and interior families on the
/// same sub-axis ([`Self::layer_kinds_balanced`],
/// [`Self::layer_kinds_full_cover`],
/// [`Self::layer_kinds_any_observed`],
/// [`Self::layer_kinds_singular_support`],
/// [`Self::layer_kinds_singular_gap`],
/// [`Self::layer_kinds_strict_partial_cover`],
/// [`Self::layer_kinds_low_support`],
/// [`Self::layer_kinds_high_support`]). The two remaining
/// chain-altitude sub-axes are the natural next sideways lifts:
/// `file_formats_singular` over [`Self::file_format_histogram`]
/// and `env_prefix_kinds_singular` over
/// [`Self::env_prefix_kind_histogram`], closing the "singular
/// across altitudes" projection alongside the already-closed
/// coverage-support predicate cube and completing the middle
/// leg of the distance-from-boundary ternary row by row.
///
/// **Cardinality-`3` reachability at the chain layer-kind sub-
/// axis — non-vacuous witnesses on both sides, degenerate
/// ternary.** [`ConfigSourceKind`] carries three cells, so the
/// two singular boundaries sit at support cardinalities `1` and
/// `2` (= `axis_cardinality - 1`), disjoint from each other and
/// from the two boundary cardinalities `0` and `3`. Every chain
/// whose observed support is a single layer-kind (support `1`)
/// reads `true` via `layer_kinds_singular_support`; every chain
/// observing exactly two layer-kinds (support `2`) reads `true`
/// via `layer_kinds_singular_gap`; every empty chain and every
/// uniform three-kind cover reads `false`. The strict-interior
/// middle leg [`Self::layer_kinds_strict_partial_cover`] is
/// vacuously `false` on the cardinality-`3` layer-kind axis
/// (the strict interval `[2, cardinality - 2] = [2, 1]` is
/// empty), so the distance-from-boundary ternary degenerates to
/// the dual partition `(has_boundary, has_singular)` on this
/// sub-axis — matching the diff-altitude peer
/// [`crate::ConfigDiff::kinds_singular`] on the same
/// cardinality-`3` [`crate::tiered::DiffLineKind`] axis, and
/// diverging from the tier-altitude peer
/// [`crate::ProvenanceMap::tiers_singular`] where the
/// cardinality-`4` axis inhabits every leg. On the cardinality-
/// `3` layer-kind axis `layer_kinds_singular ⇔
/// (layer_kinds_any_observed && !layer_kinds_full_cover)`
/// pointwise — the middle-leg fold reduces to the partial-cover
/// slice of the coverage boundary.
///
/// **Empty-chain convention** — returns `false` on the empty
/// chain: zero observed cells satisfy neither the `nonzeros ==
/// 1` nor the `zeros == 1` clause on the cardinality-`3` axis
/// (three zeros, zero nonzeros). Matches
/// [`crate::AxisHistogram::has_singular`]'s empty-histogram
/// `false` convention one altitude down for every cardinality-
/// `>= 2` axis. The empty chain sits on the disjoint bottom
/// coverage boundary of the distance-from-boundary ternary
/// partition, carried by `has_boundary` (via
/// `!layer_kinds_any_observed`) instead. Peer of
/// [`crate::ConfigDiff::kinds_singular`]'s empty-diff `false`
/// polarity and
/// [`crate::ProvenanceMap::tiers_singular`]'s empty-map `false`
/// polarity in the same projection.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single [`ConfigSourceKind`]
/// cell: the support cardinality is `1` (two unobserved cells
/// on the cardinality-`3` axis), so `layer_kinds_singular_support`
/// fires and the disjunction holds via that disjunct. Every
/// chain whose layers all attribute to only-`Defaults`,
/// only-`Env`, or only-`File` is a witness on the `true` side.
/// Direct witness of the subsumption
/// `layer_kinds_singular_support ⇒ layer_kinds_singular` on
/// every axis with cardinality `>= 2`.
///
/// **Two-kind partial cover convention** — returns `true` on
/// every chain whose observed support is exactly two
/// [`ConfigSourceKind`] cells: the support cardinality is `2`
/// (one unobserved cell on the cardinality-`3` axis), exactly
/// the singleton-gap boundary, so `layer_kinds_singular_gap`
/// fires and the disjunction holds via that disjunct. Direct
/// witness of the subsumption `layer_kinds_singular_gap ⇒
/// layer_kinds_singular` on every axis via the singleton-gap
/// disjunct of the defining union. Distinguishes the layer-
/// kind sub-axis from the tier altitude, where two-tier partial
/// cover falls in the strict interior (support size `2` on the
/// cardinality-`4` axis) and lands on `tiers_singular == false`
/// via the strict-interior disjointness.
///
/// **Uniform three-kind cover convention** — returns `false` on
/// every chain where each [`ConfigSourceKind`] cell was observed
/// at least once: the support cardinality is `3` (no unobserved
/// cells on the cardinality-`3` axis) — `layer_kinds_singular_gap`
/// fails (`zeros == 0 ≠ 1`) and `layer_kinds_singular_support`
/// fails (`nonzeros == 3 ≠ 1`). The full-cover boundary sits
/// at the top of the coverage interval, one of the two boundary
/// corners carried by `has_boundary` (via
/// `layer_kinds_full_cover`) in the distance ternary — disjoint
/// from the singular near-boundary corner.
///
/// # Invariants
///
/// - `layer_kinds_singular() ==
/// layer_kind_histogram().has_singular()` — both project the
/// same predicate off the same primitive; the named seam is
/// the cube-native routing of the histogram surface.
/// - `layer_kinds_singular() ⇔ layer_kinds_singular_support()
/// || layer_kinds_singular_gap()` — the defining union-of-
/// singular-boundaries disjunction on the two named
/// histogram-side peers. The singular near-boundary corner
/// folds the two singular-cardinality boundaries into one
/// named one-cell-off-boundary corner without discarding the
/// finer resolution below.
/// - `layer_kinds_singular() ⇔ (layer_kinds_any_observed()
/// && !layer_kinds_full_cover())` on the cardinality-`3`
/// layer-kind axis — the partial-cover-minus-strict-interior
/// form reduced pointwise on the cardinality-`3` axis where
/// the strict interior is empty. Matches the diff-altitude
/// peer `kinds_singular ⇔ (kinds_any_observed &&
/// !kinds_full_cover)` on the same cardinality-`3` axis and
/// diverges from the tier altitude where the strict-interior
/// leg carries content and the equivalence tightens to
/// `tiers_singular ⇔ (tiers_any_observed && !tiers_full_cover)
/// && !tiers_strict_partial_cover`.
/// - `layer_kinds_singular() == (present_layer_kinds_count()
/// == 1 || present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>() - 1)`
/// always — the support-scalar dual-equality surface,
/// without allocating either `Vec<ConfigSourceKind>`. On the
/// cardinality-`3` layer-kind axis the two equalities are
/// disjoint (`1 ≠ 2 = cardinality - 1`) and the disjunction
/// reads the true dual.
/// - `layer_kinds_singular() == (present_layer_kinds_count()
/// == 1 || absent_layer_kinds_count() == 1)` always — the
/// dual-scalar equality form on the two named cardinality
/// peers, the `present + absent == axis_cardinality`
/// invariant restated. Peer of the histogram-side dual-
/// scalar equality form `hist.distinct_cells() == 1 ||
/// hist.unobserved_cells() == 1` pinned one altitude down.
/// - `layer_kinds_singular_support() ⇒ layer_kinds_singular()`
/// always — the subsumption via the
/// `layer_kinds_singular_support` disjunct of the defining
/// union. The singleton-support boundary always sits inside
/// the singular near-boundary corner.
/// - `layer_kinds_singular_gap() ⇒ layer_kinds_singular()`
/// always — the subsumption via the `layer_kinds_singular_gap`
/// disjunct of the defining union. The singleton-gap
/// boundary always sits inside the singular near-boundary
/// corner.
/// - `layer_kinds_singular() ⇒ layer_kinds_any_observed()` on
/// every axis with cardinality `>= 2`: both disjuncts require
/// at least one observed cell (`singular_support` has
/// nonzeros `>= 1`; `singular_gap` has nonzeros `=
/// cardinality - 1 >= 1`). Empty-chain subsumption on the
/// bottom coverage boundary.
/// - `layer_kinds_singular() ⇒ !layer_kinds_full_cover()` on
/// every axis with cardinality `>= 2`:
/// `layer_kinds_singular_support` has support `1 <
/// cardinality`, `layer_kinds_singular_gap` has support
/// `cardinality - 1 < cardinality`. Full-cover disjointness
/// on the top coverage boundary.
/// - `layer_kinds_singular() ⇒
/// !layer_kinds_strict_partial_cover()` always — the two
/// named corners of the distance-from-boundary ternary are
/// pairwise disjoint. On the cardinality-`3` layer-kind axis
/// the consequent holds vacuously (the strict interior is
/// unreachable), unlike the non-vacuous consequent at the
/// cardinality-`4` tier altitude where the two-tier partial-
/// cover fixture separates the strict interior from the
/// singular near-boundary. Peer of the histogram-side
/// `axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor`
/// partition law one altitude down.
/// - `(!layer_kinds_any_observed() || layer_kinds_full_cover(),
/// layer_kinds_singular, layer_kinds_strict_partial_cover)`
/// is a strict ternary partition on every axis with
/// cardinality `>= 2`. On the cardinality-`3` layer-kind
/// axis the third leg vanishes and the ternary degenerates
/// to the dual `(!layer_kinds_any_observed() ||
/// layer_kinds_full_cover(), layer_kinds_singular)`
/// pointwise — matching the diff altitude's degenerate two-
/// way partition on the same cardinality-`3`
/// [`crate::tiered::DiffLineKind`] axis. Pinned on the
/// histogram surface as
/// `axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor`.
/// - **Cross-surface bridge law** —
/// `chain.layer_kinds_singular() ==
/// chain.layer_kind_histogram().support_cardinality_class().is_singular()`
/// always. The class-side projection lands on
/// [`crate::SupportCardinalityClass::SingularSupport`] or
/// [`crate::SupportCardinalityClass::SingularGap`] exactly
/// when the histogram-side disjunction fires, and
/// [`crate::SupportCardinalityClass::is_singular`] reads
/// `true` on either variant. Peer of the histogram-side
/// bridge
/// `axis_histogram_has_singular_agrees_with_class_is_singular_for_every_closed_axis_implementor`
/// one altitude down, closing the (histogram, class) duality
/// on the singular near-boundary leg at the chain layer-
/// kind sub-axis.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<ConfigSourceKind>()`
/// (the singular scan). Both are `O(n)` in practice since the
/// layer-kind axis carries a fixed three-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits
/// the *moment* both a *second* zero count *and* a *second*
/// nonzero count have been witnessed (bounded at four witness
/// cells visited on any strict-interior histogram —
/// unreachable on cardinality-`3` axes), strictly tighter than
/// the four documented open-coded surfaces — no boolean
/// disjunction across two named predicates with two full walks
/// of the counts vector, no [`crate::axis_cardinality`]
/// turbofish with `- 1` arithmetic against a magic threshold,
/// no `Vec<ConfigSourceKind>` allocation.
#[must_use]
fn layer_kinds_singular(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().has_singular()
}
/// `true` exactly when this chain's observed [`ConfigSourceKind`]
/// support sits on a *coverage boundary* — either every layer-kind
/// cell unobserved ([`Self::layer_kinds_any_observed`] `== false`)
/// or every layer-kind cell observed at least once
/// ([`Self::layer_kinds_full_cover`] `== true`).
///
/// The **boundary-layer-kinds boolean predicate** on the layer-kind
/// sub-axis of the chain altitude, the top-leg corner of the
/// distance-from-boundary ternary partition `(has_boundary,
/// has_singular, has_strict_partial_cover)` — folding the two
/// extreme coverage-cardinality corners (support cardinality `0`
/// and `axis_cardinality`) into a single named on-boundary corner
/// without discarding the finer resolution below. Routes through
/// [`Self::layer_kind_histogram`]`::has_boundary`, the single-pass
/// short-circuiting scan over the fixed-cardinality counts vector
/// that returns `false` the moment both a zero cell *and* a
/// nonzero cell have been witnessed, bounded at two witness cells
/// — strictly tighter than any of the documented open-coded
/// surfaces one seam over.
///
/// The **boundary-layer-kinds peer** of the two documented surface
/// forms consumers previously re-derived inline:
/// `!chain.layer_kinds_any_observed() ||
/// chain.layer_kinds_full_cover()` (the defining union-of-coverage-
/// boundaries disjunction on the two named histogram-side peers —
/// one negation and two method calls with a boolean or), and
/// `chain.present_layer_kinds_count() == 0 ||
/// chain.present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>()` (the support-
/// scalar dual-equality form, which pays for a full-axis scan and
/// equates a `usize` against two magic thresholds with a
/// turbofish). This lift names the boundary-layer-kinds predicate
/// directly at the chain-altitude surface with a single-pass
/// short-circuiting scan — the typed boolean every operator-facing
/// *"did the chain land on a layer-kind coverage boundary?"* check
/// reads off as a single method call.
///
/// The chain-altitude layer-kind sub-axis boundary-predicate peer
/// that **lifts the "boundary across altitudes" projection
/// sideways** from the tier altitude
/// ([`crate::ProvenanceMap::tiers_boundary`]) to the first chain-
/// altitude sub-axis, seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_boundary`]. The two remaining chain-
/// altitude sub-axes ([`Self::file_formats_boundary`] over
/// [`Self::file_format_histogram`], [`Self::env_prefix_kinds_boundary`]
/// over [`Self::env_prefix_kind_histogram`]) are the natural next
/// sideways lifts. The pattern is the same at every altitude /
/// sub-axis: fuse the documented open-coded surface forms into a
/// single boolean predicate named at the surface, routed through
/// the shared [`crate::AxisHistogram::has_boundary`] primitive one
/// altitude down.
///
/// **Cardinality-`3` reachability at the layer-kind sub-axis —
/// non-vacuous witnesses on both sides, degenerate ternary.**
/// [`ConfigSourceKind`] carries three cells so `layer_kinds_boundary()`
/// reads `true` on the empty chain (three unobserved cells — empty
/// disjunct) and on every uniform three-kind cover (three observed
/// cells — full-cover disjunct), and `false` on every singleton-
/// support chain (support cardinality `1` — one nonzero and two
/// zeros mixed) and every two-kind partial cover (support
/// cardinality `2` — two nonzeros and one zero mixed, exactly the
/// singleton-gap boundary). The strict-interior middle leg
/// [`Self::layer_kinds_strict_partial_cover`] is vacuously `false`
/// on the cardinality-`3` axis (the strict interval `[2,
/// cardinality - 2] = [2, 1]` is empty), so the distance ternary
/// degenerates to the dual partition `(layer_kinds_boundary,
/// layer_kinds_singular)` on this sub-axis — matching the diff-
/// altitude peer on the same cardinality-`3` `DiffLineKind` axis
/// and diverging from the tier-altitude peer where the cardinality-
/// `4` `ConfigTierKind` axis inhabits every leg (the two-tier
/// partial-cover fixture is the unique strict-interior witness).
/// The vacuously-`true` closure of the disjointness
/// `layer_kinds_boundary ⇒ !layer_kinds_strict_partial_cover`
/// transports the ternary discipline verbatim to the tier altitude,
/// where every leg is inhabited.
///
/// **Empty-chain convention** — returns `true` on the empty chain:
/// the empty chain observes zero cells, so every cell is
/// unobserved (three zeros on the cardinality-`3` axis) — the
/// single-pass scan sees no nonzero cell and falls through to
/// `true`. Matches [`crate::AxisHistogram::has_boundary`]'s empty-
/// histogram `true` convention one altitude down. The empty chain
/// sits on the bottom coverage boundary via the
/// [`Self::layer_kinds_any_observed`]-negation disjunct. Peer of
/// [`crate::ProvenanceMap::tiers_boundary`]'s empty-map `true`
/// polarity and [`crate::ConfigDiff::kinds_boundary`]'s empty-diff
/// `true` polarity in the same projection.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single [`ConfigSourceKind`]
/// cell: the support cardinality is `1` (one nonzero and two zeros
/// on the cardinality-`3` axis), so the single-pass scan sees a
/// nonzero cell *and* a zero cell and returns `false`. Every chain
/// with all layers being only-`Defaults`, only-`Env`, or only-
/// `File` is a witness on the `false` side — singleton-support
/// chains sit strictly off the two coverage boundaries.
///
/// **Two-kind partial cover convention** — returns `false` on every
/// chain whose observed support is exactly two [`ConfigSourceKind`]
/// cells: the support cardinality is `2` (two nonzeros and one
/// zero on the cardinality-`3` axis), so the single-pass scan sees
/// both a nonzero and a zero cell and returns `false`. The
/// `sample_chain()` fixture (two File + one Env, {Env, File}
/// support) is a witness on the `false` side — sitting on the
/// disjoint [`Self::layer_kinds_singular_gap`] boundary carried by
/// [`Self::layer_kinds_singular`] in the distance ternary.
///
/// **Uniform three-kind cover convention** — returns `true` on
/// every chain where each [`ConfigSourceKind`] cell was observed at
/// least once: the support cardinality is `3` (no unobserved cells
/// on the cardinality-`3` axis), so the single-pass scan sees only
/// nonzero cells and falls through to `true`. The full-cover
/// boundary sits at the top of the coverage interval via the
/// [`Self::layer_kinds_full_cover`] disjunct.
///
/// # Invariants
///
/// - `layer_kinds_boundary() == layer_kind_histogram().has_boundary()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram surface.
/// - `layer_kinds_boundary() ⇔ !layer_kinds_any_observed() ||
/// layer_kinds_full_cover()` — the defining union-of-coverage-
/// boundaries disjunction on the two named coverage-boundary
/// peers.
/// - `layer_kinds_boundary() == (present_layer_kinds_count() == 0
/// || present_layer_kinds_count() ==
/// crate::axis_cardinality::<ConfigSourceKind>())` always — the
/// support-scalar dual-equality surface, without allocating
/// `Vec<ConfigSourceKind>`. The two equalities are strictly
/// disjoint (`0 != 3 = cardinality` on the layer-kind axis).
/// - `layer_kinds_boundary() == (present_layer_kinds_count() == 0
/// || absent_layer_kinds_count() == 0)` always — the dual-scalar
/// equality form on the two named cardinality peers, the
/// `present + absent == axis_cardinality` invariant restated.
/// - `!layer_kinds_any_observed() ⇒ layer_kinds_boundary()` always
/// — the empty chain sits on the boundary via the bottom
/// disjunct.
/// - `layer_kinds_full_cover() ⇒ layer_kinds_boundary()` always —
/// the full-cover chain sits on the boundary via the top
/// disjunct.
/// - `layer_kinds_boundary() ⇒ !layer_kinds_singular()` on every
/// axis with cardinality `>= 2`: the two boundary cardinalities
/// sit strictly outside the two singular cardinalities.
/// - `layer_kinds_boundary() ⇒ !layer_kinds_strict_partial_cover()`
/// always. Vacuously-`true` on the cardinality-`3` layer-kind
/// axis (the strict interior is unreachable), transporting the
/// ternary disjointness discipline verbatim to the tier altitude
/// where every leg is inhabited.
/// - `(layer_kinds_boundary, layer_kinds_singular,
/// layer_kinds_strict_partial_cover)` is a strict ternary
/// partition on every axis with cardinality `>= 2`. Degenerates
/// to the dual `(layer_kinds_boundary, layer_kinds_singular)` on
/// the cardinality-`3` layer-kind axis, matching the diff
/// altitude's degenerate two-way partition on `DiffLineKind`.
/// - **Cross-surface bridge law** — `chain.layer_kinds_boundary() ==
/// chain.layer_kind_histogram().support_cardinality_class().is_boundary()`
/// always. Peer of the histogram-side bridge
/// `axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor`
/// one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<ConfigSourceKind>()` (the
/// boundary scan). Both are `O(n)` in practice since the layer-kind
/// axis carries a fixed three-cell cardinality; the returned
/// `bool` reads one predicate. The scan returns `false` the
/// *moment* a mixed-parity witness (one zero *and* one nonzero)
/// has been seen — bounded at two witness cells visited — strictly
/// tighter than the documented open-coded surfaces.
#[must_use]
fn layer_kinds_boundary(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().has_boundary()
}
/// `true` exactly when this chain's observed [`ConfigSourceKind`]
/// support sits *strictly between* the two coverage boundaries —
/// at least one layer-kind cell observed
/// ([`Self::layer_kinds_any_observed`] `== true`) *and* at least
/// one layer-kind cell unobserved
/// ([`Self::layer_kinds_full_cover`] `== false`).
///
/// The **partial-cover-layer-kinds boolean predicate** on the
/// layer-kind sub-axis of the chain altitude, the *middle* leg of
/// the coverage trichotomy `(!layer_kinds_any_observed,
/// layer_kinds_partial_cover, layer_kinds_full_cover)` — the
/// direct strict-complement of the top-leg [`Self::layer_kinds_boundary`]
/// corner, folding both singular near-boundary corners *and* the
/// strict interior into a single "some but not all" corner
/// without discarding the finer resolution below. Routes through
/// [`Self::layer_kind_histogram`]`::has_partial_cover`, the single-
/// pass short-circuiting scan over the fixed-cardinality counts
/// vector that returns `true` the moment both a zero cell *and* a
/// nonzero cell have been witnessed, bounded at two witness cells
/// — strictly tighter than any of the documented open-coded
/// surfaces one seam over.
///
/// The **partial-cover-layer-kinds peer** of the documented surface
/// forms consumers previously re-derived inline:
/// `chain.layer_kinds_any_observed() &&
/// !chain.layer_kinds_full_cover()` (the defining conjunction-of-
/// negations form on the two named coverage-boundary peers — two
/// method calls with a boolean and — the exact expression used
/// verbatim by the pre-existing bipartition-law pin
/// [`tests::layer_kinds_boundary_and_layer_kinds_partial_cover_form_strict_bipartition_pointwise`]),
/// `0 < chain.present_layer_kinds_count() &&
/// chain.present_layer_kinds_count() <
/// crate::axis_cardinality::<ConfigSourceKind>()` (the support-
/// scalar strict-interval form, which pays for a full-axis scan
/// and brackets a `usize` between two magic thresholds with a
/// turbofish), and `chain.present_layer_kinds_count() > 0 &&
/// chain.absent_layer_kinds_count() > 0` (the dual-scalar mixed-
/// side non-emptiness form on the two named cardinality peers).
/// This lift names the partial-cover-layer-kinds predicate
/// directly at the chain-altitude surface with a single-pass
/// short-circuiting scan — the typed boolean every operator-facing
/// *"did the chain see some but not all layer kinds?"* check reads
/// off as a single method call.
///
/// The chain-altitude layer-kind sub-axis partial-cover-predicate
/// peer that **lifts the "partial-cover across altitudes"
/// projection sideways** from the tier altitude
/// ([`crate::ProvenanceMap::tiers_partial_cover`]) to the first
/// chain-altitude sub-axis, seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_partial_cover`]. The two remaining
/// chain-altitude sub-axes ([`Self::file_formats_partial_cover`]
/// over [`Self::file_format_histogram`],
/// [`Self::env_prefix_kinds_partial_cover`] over
/// [`Self::env_prefix_kind_histogram`]) are the natural next
/// sideways lifts. The pattern is the same at every altitude /
/// sub-axis: fuse the documented open-coded surface forms into a
/// single boolean predicate named at the surface, routed through
/// the shared [`crate::AxisHistogram::has_partial_cover`]
/// primitive one altitude down.
///
/// **Cardinality-`3` reachability at the layer-kind sub-axis —
/// non-vacuous witnesses on both sides, degenerate ternary.**
/// [`ConfigSourceKind`] carries three cells so
/// `layer_kinds_partial_cover()` reads `true` on every singleton-
/// support chain (support cardinality `1` — one nonzero and two
/// zeros mixed) and every two-kind partial cover (support
/// cardinality `2` — two nonzeros and one zero mixed, exactly the
/// singleton-gap boundary), and `false` on the empty chain
/// (three unobserved cells — no nonzero witness) and on every
/// uniform three-kind cover (three observed cells — no zero
/// witness). The strict-interior middle leg
/// [`Self::layer_kinds_strict_partial_cover`] is vacuously `false`
/// on the cardinality-`3` axis (the strict interval `[2,
/// cardinality - 2] = [2, 1]` is empty), so on this sub-axis
/// `layer_kinds_partial_cover` collapses to the two singular
/// near-boundary corners
/// (`layer_kinds_singular_support ∨ layer_kinds_singular_gap`) —
/// matching the diff-altitude peer on the same cardinality-`3`
/// `DiffLineKind` axis and diverging from the tier-altitude peer
/// where the cardinality-`4` `ConfigTierKind` axis inhabits every
/// leg (the two-tier partial-cover fixture is the unique strict-
/// interior witness). The non-vacuous subsumption
/// `layer_kinds_strict_partial_cover ⇒ layer_kinds_partial_cover`
/// transports the coverage-trichotomy discipline verbatim to the
/// tier altitude, where every leg is inhabited.
///
/// **Empty-chain convention** — returns `false` on the empty
/// chain: the empty chain observes zero cells, so every cell is
/// unobserved (three zeros on the cardinality-`3` axis) — the
/// single-pass scan sees no nonzero cell and falls through to
/// `false`. Matches [`crate::AxisHistogram::has_partial_cover`]'s
/// empty-histogram `false` convention one altitude down. The
/// empty chain sits strictly outside the partial-cover middle
/// leg via the [`Self::layer_kinds_any_observed`]-negation half
/// of the defining conjunction. Peer of
/// [`crate::ProvenanceMap::tiers_partial_cover`]'s empty-map
/// `false` polarity and
/// [`crate::ConfigDiff::kinds_partial_cover`]'s empty-diff
/// `false` polarity in the same projection.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single [`ConfigSourceKind`]
/// cell: the support cardinality is `1` (one nonzero and two
/// zeros on the cardinality-`3` axis), so the single-pass scan
/// sees a nonzero cell *and* a zero cell and returns `true`.
/// Direct witness of the subsumption
/// `layer_kinds_singular_support ⇒ layer_kinds_partial_cover`
/// via the mixed-parity witness — every chain with all layers
/// being only-`Defaults`, only-`Env`, or only-`File` is a witness
/// on the `true` side.
///
/// **Two-kind partial cover convention** — returns `true` on every
/// chain whose observed support is exactly two
/// [`ConfigSourceKind`] cells: the support cardinality is `2`
/// (two nonzeros and one zero on the cardinality-`3` axis),
/// exactly the singleton-gap boundary — the single-pass scan sees
/// both a nonzero and a zero cell and returns `true`. The
/// `sample_chain()` fixture (two File + one Env, {Env, File}
/// support) is a witness on the `true` side — sitting on the
/// [`Self::layer_kinds_singular_gap`] boundary carried by
/// [`Self::layer_kinds_singular`] in the distance ternary.
///
/// **Uniform three-kind cover convention** — returns `false` on
/// every chain where each [`ConfigSourceKind`] cell was observed
/// at least once: the support cardinality is `3` (no unobserved
/// cells on the cardinality-`3` axis), so the single-pass scan
/// sees only nonzero cells and falls through to `false`. The
/// full-cover boundary sits strictly above the partial-cover
/// middle leg via the [`Self::layer_kinds_full_cover`]-negation
/// half of the defining conjunction.
///
/// # Invariants
///
/// - `layer_kinds_partial_cover() == layer_kind_histogram().has_partial_cover()`
/// — both project the same predicate off the same primitive;
/// the named seam is the cube-native routing of the histogram
/// surface.
/// - `layer_kinds_partial_cover() ⇔ layer_kinds_any_observed() &&
/// !layer_kinds_full_cover()` — the defining conjunction-of-
/// negations form on the two named coverage-boundary peers.
/// - `layer_kinds_partial_cover() == (0 < present_layer_kinds_count()
/// && present_layer_kinds_count() <
/// crate::axis_cardinality::<ConfigSourceKind>())` always —
/// the support-scalar strict-interval surface, without
/// allocating `Vec<ConfigSourceKind>`.
/// - `layer_kinds_partial_cover() == (0 < absent_layer_kinds_count()
/// && absent_layer_kinds_count() <
/// crate::axis_cardinality::<ConfigSourceKind>())` always —
/// the coverage-gap dual-scalar strict-interval surface, the
/// `present + absent == axis_cardinality` invariant restated.
/// - `layer_kinds_partial_cover() == (present_layer_kinds_count() > 0
/// && absent_layer_kinds_count() > 0)` always — the mixed-side
/// dual-scalar non-emptiness form, the direct histogram-surface
/// `distinct_cells > 0 && unobserved_cells > 0` pin restated at
/// the chain layer-kind sub-axis, without allocating either
/// `Vec<ConfigSourceKind>`.
/// - `layer_kinds_partial_cover() ⇒ layer_kinds_any_observed()`
/// always — the partial-cover corner requires at least one
/// observed cell.
/// - `layer_kinds_partial_cover() ⇒ !layer_kinds_full_cover()`
/// always — the partial-cover corner excludes the top coverage
/// boundary.
/// - `layer_kinds_singular_support() ⇒ layer_kinds_partial_cover()`
/// always on cardinality-`>= 2` axes: support cardinality `1`
/// is strictly between `0` and cardinality. Direct pin of the
/// histogram-side subsumption
/// `has_singular_support ⇒ has_partial_cover` one altitude down.
/// - `layer_kinds_singular_gap() ⇒ layer_kinds_partial_cover()`
/// always on cardinality-`>= 2` axes: support cardinality
/// `cardinality - 1` is strictly between `0` and cardinality.
/// - `layer_kinds_singular() ⇒ layer_kinds_partial_cover()` always
/// on cardinality-`>= 2` axes — the union of the two singular-
/// side subsumptions.
/// - `layer_kinds_strict_partial_cover() ⇒ layer_kinds_partial_cover()`
/// always — the strict interior sits inside the partial-cover
/// middle leg by definition. Vacuously-`true` on the
/// cardinality-`3` layer-kind axis (the strict interior is
/// unreachable), transporting the subsumption discipline
/// verbatim to the tier altitude where the two-tier partial-
/// cover fixture witnesses both consequent and antecedent
/// `true` non-vacuously.
/// - `layer_kinds_partial_cover()` and [`Self::layer_kinds_boundary`]
/// form a strict bipartition — exactly one fires on every
/// chain. Peer of the histogram-side bipartition law
/// `axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`
/// one altitude down.
/// - **Coverage-trichotomy partition law** —
/// `(!layer_kinds_any_observed, layer_kinds_partial_cover,
/// layer_kinds_full_cover)` is a strict ternary partition on
/// every axis with cardinality `>= 1` (every chain-altitude
/// implementor today — the cardinality-`3` [`ConfigSourceKind`]
/// axis). Exactly one leg fires on every chain — the coverage
/// trichotomy of the `(is_empty, has_partial_cover,
/// is_full_cover)` histogram-side partition restated at the
/// chain layer-kind sub-axis. Peer of the trait-uniform pin
/// `axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor`
/// one altitude down.
/// - **Cross-surface bridge law** —
/// `chain.layer_kinds_partial_cover() ==
/// chain.layer_kind_histogram().support_cardinality_class().is_partial_cover()`
/// always. Peer of the histogram-side bridge
/// `axis_histogram_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover_for_every_closed_axis_implementor`
/// one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<ConfigSourceKind>()`
/// (the partial-cover scan). Both are `O(n)` in practice since
/// the layer-kind axis carries a fixed three-cell cardinality;
/// the returned `bool` reads one predicate. The scan returns
/// `true` the *moment* a mixed-parity witness (one zero *and*
/// one nonzero) has been seen — bounded at two witness cells
/// visited on any strict-interior histogram — strictly tighter
/// than the documented open-coded surfaces.
#[must_use]
fn layer_kinds_partial_cover(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().has_partial_cover()
}
/// `true` exactly when this chain's observed [`ConfigSourceKind`]
/// histogram has two or more cells tied at the peak leaf count —
/// the peak is *shared* rather than uniquely held.
///
/// The **modally-tied-layer-kinds boolean predicate** on the layer-
/// kind sub-axis of the chain altitude, the direct strict-complement
/// of [`crate::AxisHistogram::is_strictly_modally_unique`] on every
/// non-empty chain (both read `false` on the empty chain — the
/// shared boundary below both branches of the strict modal
/// partition). Routes through [`Self::layer_kind_histogram`]`::is_modally_tied`,
/// the single-pass scan over the fixed-cardinality counts vector
/// reading `peak_multiplicity() >= 2` off one predicate — strictly
/// tighter than either of the documented open-coded surface forms
/// one seam over.
///
/// The **modally-tied-layer-kinds peer** of the two documented
/// surface forms consumers previously re-derived inline:
/// `chain.layer_kind_histogram().peak_multiplicity() >= 2` (the
/// defining multiplicity-scalar inequality form — one method call
/// plus a magic `>= 2` threshold at the consumer site), and
/// `chain.layer_kind_histogram().modality_degree().0 >= 2` (the
/// modality-pair projection-inequality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison — a fused-pair build for a single-component
/// projection). This lift names the modally-tied-layer-kinds
/// predicate directly at the chain-altitude surface — the typed
/// boolean every operator-facing *"is the dominant layer kind
/// uniquely held on this chain, or tied?"* check reads off as a
/// single method call.
///
/// The chain-altitude layer-kind sub-axis modality-tie-predicate
/// peer that **lifts the "modally-tied across altitudes" projection
/// sideways** from the tier altitude
/// ([`crate::ProvenanceMap::tiers_modally_tied`]) to the first
/// chain-altitude sub-axis, seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_modally_tied`]. The two remaining
/// chain-altitude sub-axes ([`Self::file_formats_modally_tied`]
/// over [`Self::file_format_histogram`],
/// [`Self::env_prefix_kinds_modally_tied`] over
/// [`Self::env_prefix_kind_histogram`]) are the natural next
/// sideways lifts. The pattern is the same at every altitude /
/// sub-axis: fuse the two open-coded surface forms (multiplicity-
/// scalar inequality, modality-pair projection-inequality) into a
/// single boolean predicate named at the surface, routed through
/// the shared [`crate::AxisHistogram::is_modally_tied`] primitive
/// one altitude down.
///
/// **Cardinality-`3` reachability at the layer-kind sub-axis — the
/// modally-tied corner carries witnesses on the two off-boundary
/// support cardinalities.** [`ConfigSourceKind`] carries three
/// cells, so `layer_kinds_modally_tied()` reads `true` on every
/// chain whose peak leaf count is shared by two or more observed
/// layer-kind cells (e.g. one-`Defaults`+one-`Env` tied at count
/// `1`, or the uniform three-kind cover tied at count `1`), and
/// `false` on the empty chain (no observed cell), on every
/// singleton-support chain (support cardinality `1`, peak
/// multiplicity `1`), and on every strictly-modal skewed chain
/// (e.g. two-`File` + one-`Env` where `File` uniquely peaks at
/// count `2`). Matches the diff-altitude peer on the same
/// cardinality-`3` [`crate::DiffLineKind`] axis in reachability —
/// support-`2` tied and support-`3`/full-cover tied are the two
/// off-singleton support cardinalities carrying witnesses; the
/// tier altitude (cardinality-`4` [`crate::ConfigTierKind`] axis)
/// carries the additional support-`3` tied witness that this
/// sub-axis cannot inhabit.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain observes zero cells, so
/// [`crate::AxisHistogram::peak_multiplicity`] reads `0` and the
/// inequality `0 >= 2` fails. Matches
/// [`crate::AxisHistogram::is_modally_tied`]'s empty-histogram
/// convention one altitude down. The empty-chain row on the strict
/// modal partition pair
/// `(is_strictly_modally_unique, is_modally_tied)` reads
/// `(false, false)` — the shared boundary below both branches.
/// Peer of [`crate::ConfigDiff::kinds_modally_tied`]'s empty-diff
/// `false` polarity and
/// [`crate::ProvenanceMap::tiers_modally_tied`]'s empty-map
/// `false` polarity in the same projection.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single [`ConfigSourceKind`]
/// cell: the lone observed cell stands alone at its own peak (no
/// tie-break to exercise), so `peak_multiplicity` reads `1` and
/// the inequality `1 >= 2` fails. Every chain with all layers
/// being only-`Defaults`, only-`Env`, or only-`File` is a witness
/// on the `false` side — the singleton-support corner is uniformly
/// on the strictly-modal-unique side of the strict modal partition.
/// Direct pin of the histogram-side subsumption
/// `has_singular_support ⇒ !is_modally_tied` one altitude down.
///
/// **Uniform three-kind cover convention** — returns `true` on
/// every chain where each [`ConfigSourceKind`] cell was observed
/// at exactly the same positive count (in particular the chain
/// with one layer per kind): the three cells share the same count,
/// so `peak_multiplicity` reads `3` and the inequality `3 >= 2`
/// fires. Peer of the histogram-side axis-cover convention one
/// altitude down, which reads `true` on every implementor with
/// `axis_cardinality::<A>() >= 2` — the cardinality-`3`
/// [`ConfigSourceKind`] axis honours the general condition.
///
/// **Two-way modal partition on non-empty chains** — on every non-
/// empty chain exactly one of the modal-uniqueness pair fires:
/// either the peak is uniquely held (strictly-modal-unique fires,
/// modally-tied does not) or the peak is shared (modally-tied
/// fires, strictly-modal-unique does not). The empty chain sits
/// below both branches (both read `false`). Direct pin of the
/// histogram-side strict modal partition
/// `!is_empty ⇒ is_modally_tied ⇔ !is_strictly_modally_unique`
/// one altitude down.
///
/// # Invariants
///
/// - `layer_kinds_modally_tied() == layer_kind_histogram().is_modally_tied()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `layer_kinds_modally_tied() ⇔
/// layer_kind_histogram().peak_multiplicity() >= 2` — the
/// defining multiplicity-scalar inequality form on the
/// [`crate::AxisHistogram::peak_multiplicity`] scalar peer, the
/// canonical open-coded expression of the predicate one altitude
/// down.
/// - `layer_kinds_modally_tied() ⇔
/// layer_kind_histogram().modality_degree().0 >= 2` — the
/// modality-pair projection-inequality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison.
/// - `layer_kinds_modally_tied() ⇒ layer_kinds_any_observed()`
/// always — a tied peak requires at least two observed cells,
/// so the empty chain (zero observed cells) cannot fire.
/// Contrapositively, `!layer_kinds_any_observed() ⇒
/// !layer_kinds_modally_tied()`.
/// - `layer_kinds_singular_support() ⇒ !layer_kinds_modally_tied()`
/// always — a singleton-support chain has exactly one observed
/// cell, so the modal level set has cardinality `1` and the tie
/// predicate fails. Contrapositively, `layer_kinds_modally_tied()
/// ⇒ !layer_kinds_singular_support()`: a fired tie predicate
/// means at least two observed cells. Direct pin of the
/// histogram-side subsumption `has_singular_support ⇒
/// !is_modally_tied` one altitude down.
/// - `layer_kinds_full_cover() ∧ layer_kinds_balanced() ⇒
/// layer_kinds_modally_tied()` on the cardinality-`>= 2` axis:
/// a full-cover uniform-count chain has every cell observed at
/// the same count, so the modal level set equals the full axis
/// — the peak multiplicity rises to
/// `axis_cardinality::<ConfigSourceKind>()` which is `3`, and
/// the tie predicate fires. Cardinality-`>= 2` witness of the
/// uniform-cover corner of the histogram-side subsumption tying
/// [`crate::AxisHistogram::is_uniform_count`] and
/// [`crate::AxisHistogram::has_singular_support`] on non-empty
/// histograms one altitude down.
/// - **Strict modal partition on non-empty chains** —
/// `layer_kinds_any_observed() ⇒ (layer_kinds_modally_tied ⇔
/// !layer_kind_histogram().is_strictly_modally_unique())`
/// always. On every non-empty chain exactly one of
/// `(layer_kinds_modally_tied,
/// layer_kind_histogram().is_strictly_modally_unique())` fires;
/// both read `false` on the empty chain — the shared boundary
/// below both branches. Direct pin of the histogram-side strict
/// modal partition one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<ConfigSourceKind>()`
/// (the peak-multiplicity scan). Both are `O(n)` in practice since
/// the layer-kind axis carries a fixed three-cell cardinality; the
/// returned `bool` reads one predicate — the peak scan walks the
/// counts vector once and counts cells matching the max, then
/// reads `multiplicity >= 2` off one comparison. Strictly tighter
/// than the two documented open-coded surfaces one seam over (no
/// exposed `>= 2` magic threshold at the consumer site, no
/// [`crate::AxisHistogram::modality_degree`] fused-pair build for
/// a single-component projection).
#[must_use]
fn layer_kinds_modally_tied(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().is_modally_tied()
}
/// `true` exactly when this chain's observed [`ConfigSourceKind`]
/// histogram has two or more cells tied at the trough leaf count —
/// the trough is *shared* rather than uniquely held.
///
/// The **antimodally-tied-layer-kinds boolean predicate** on the
/// layer-kind sub-axis of the chain altitude, the direct strict-
/// complement of [`crate::AxisHistogram::is_strictly_antimodally_unique`]
/// on every non-empty chain (both read `false` on the empty chain —
/// the shared boundary below both branches of the strict antimodal
/// partition). Routes through [`Self::layer_kind_histogram`]`::is_antimodally_tied`,
/// the single-pass scan over the fixed-cardinality counts vector
/// reading `trough_multiplicity() >= 2` off one predicate — strictly
/// tighter than either of the documented open-coded surface forms
/// one seam over.
///
/// The **antimodally-tied-layer-kinds peer** of the two documented
/// surface forms consumers previously re-derived inline:
/// `chain.layer_kind_histogram().trough_multiplicity() >= 2` (the
/// defining multiplicity-scalar inequality form — one method call
/// plus a magic `>= 2` threshold at the consumer site), and
/// `chain.layer_kind_histogram().modality_degree().1 >= 2` (the
/// modality-pair projection-inequality form, reading the antimodal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison — a fused-pair build for a single-component
/// projection). This lift names the antimodally-tied-layer-kinds
/// predicate directly at the chain-altitude surface — the typed
/// boolean every operator-facing *"is the rarest layer kind
/// uniquely held on this chain, or is the declaration-order tie-
/// break exercised?"* check reads off as a single method call.
///
/// The chain-altitude layer-kind sub-axis antimodal-tie-predicate
/// peer that **lifts the "antimodally-tied across altitudes"
/// projection sideways** from the tier altitude
/// ([`crate::ProvenanceMap::tiers_antimodally_tied`]) to the first
/// chain-altitude sub-axis, seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_antimodally_tied`]. The two remaining
/// chain-altitude sub-axes ([`Self::file_formats_antimodally_tied`]
/// over [`Self::file_format_histogram`],
/// [`Self::env_prefix_kinds_antimodally_tied`] over
/// [`Self::env_prefix_kind_histogram`]) are the natural next
/// sideways lifts, mirroring the four-step lift trajectory of the
/// seven prior projections. The pattern is the same at every
/// altitude / sub-axis: fuse the two open-coded surface forms
/// (multiplicity-scalar inequality, modality-pair projection-
/// inequality) into a single boolean predicate named at the
/// surface, routed through the shared
/// [`crate::AxisHistogram::is_antimodally_tied`] primitive one
/// altitude down.
///
/// **Cardinality-`3` reachability at the layer-kind sub-axis — the
/// antimodally-tied corner carries witnesses on the two off-
/// singleton support cardinalities.** [`ConfigSourceKind`] carries
/// three cells, so `layer_kinds_antimodally_tied()` reads `true`
/// on every chain whose trough leaf count is shared by two or more
/// observed layer-kind cells (e.g. one-`Defaults`+one-`Env` tied
/// at count `1`, or the uniform three-kind cover tied at count
/// `1`), and `false` on the empty chain (no observed cell), on
/// every singleton-support chain (support cardinality `1`, trough
/// multiplicity `1`), and on every strictly-antimodal skewed chain
/// (e.g. two-`File`+one-`Env` where `Env` uniquely holds the
/// trough at count `1` while `File` peaks at `2` — the
/// `sample_chain()` fixture). Matches the diff-altitude peer on
/// the same cardinality-`3` [`crate::DiffLineKind`] axis in
/// reachability — support-`2` tied and support-`3`/full-cover tied
/// are the two off-singleton support cardinalities carrying
/// witnesses; the tier altitude (cardinality-`4`
/// [`crate::ConfigTierKind`] axis) carries the additional support-
/// `3` shared-trough witness that this sub-axis cannot inhabit.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain observes zero cells, so
/// [`crate::AxisHistogram::trough_multiplicity`] reads `0` and the
/// inequality `0 >= 2` fails. Matches
/// [`crate::AxisHistogram::is_antimodally_tied`]'s empty-histogram
/// convention one altitude down. The empty-chain row on the strict
/// antimodal partition pair
/// `(is_strictly_antimodally_unique, is_antimodally_tied)` reads
/// `(false, false)` — the shared boundary below both branches.
/// Peer of [`crate::ConfigDiff::kinds_antimodally_tied`]'s empty-
/// diff `false` polarity and
/// [`crate::ProvenanceMap::tiers_antimodally_tied`]'s empty-map
/// `false` polarity in the same projection.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single [`ConfigSourceKind`]
/// cell: the lone observed cell stands alone at its own trough
/// (peak and trough coincide, no tie-break to exercise), so
/// `trough_multiplicity` reads `1` and the inequality `1 >= 2`
/// fails. Every chain with all layers being only-`Defaults`,
/// only-`Env`, or only-`File` is a witness on the `false` side —
/// the singleton-support corner is uniformly on the strictly-
/// antimodal-unique side of the strict antimodal partition. Direct
/// pin of the histogram-side subsumption `has_singular_support ⇒
/// !is_antimodally_tied` one altitude down.
///
/// **Uniform three-kind cover convention** — returns `true` on
/// every chain where each [`ConfigSourceKind`] cell was observed
/// at exactly the same positive count (in particular the chain
/// with one layer per kind): the three cells share the same count,
/// so `trough_multiplicity` reads `3` and the inequality `3 >= 2`
/// fires. Peer of the histogram-side axis-cover convention one
/// altitude down, which reads `true` on every implementor with
/// `axis_cardinality::<A>() >= 2` — the cardinality-`3`
/// [`ConfigSourceKind`] axis honours the general condition.
///
/// **Two-way antimodal partition on non-empty chains** — on every
/// non-empty chain exactly one of the antimodal-uniqueness pair
/// fires: either the trough is uniquely held (strictly-antimodal-
/// unique fires, antimodally-tied does not) or the trough is
/// shared (antimodally-tied fires, strictly-antimodal-unique does
/// not). The empty chain sits below both branches (both read
/// `false`). Direct pin of the histogram-side strict antimodal
/// partition `!is_empty ⇒ is_antimodally_tied ⇔
/// !is_strictly_antimodally_unique` one altitude down.
///
/// **Modal / antimodal collapse on uniform-count non-empty chains**
/// — on every uniform-count multi-cell chain the modal and
/// antimodal level sets coincide with the support, so
/// `layer_kinds_antimodally_tied ⇔ layer_kinds_modally_tied` — the
/// classifier pair collapses to a single boolean, the multi-cell-
/// support witness. Direct pin of the histogram-side collapse law
/// `is_uniform_count ∧ !is_empty ⇒ is_antimodally_tied ⇔
/// is_modally_tied` one altitude down, peer of the same collapse
/// pinned at the diff altitude by
/// [`crate::ConfigDiff::kinds_antimodally_tied`] and at the tier
/// altitude by [`crate::ProvenanceMap::tiers_antimodally_tied`].
///
/// # Invariants
///
/// - `layer_kinds_antimodally_tied() == layer_kind_histogram().is_antimodally_tied()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `layer_kinds_antimodally_tied() ⇔
/// layer_kind_histogram().trough_multiplicity() >= 2` — the
/// defining multiplicity-scalar inequality form on the
/// [`crate::AxisHistogram::trough_multiplicity`] scalar peer, the
/// canonical open-coded expression of the predicate one altitude
/// down.
/// - `layer_kinds_antimodally_tied() ⇔
/// layer_kind_histogram().modality_degree().1 >= 2` — the
/// modality-pair projection-inequality form, reading the
/// antimodal component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison.
/// - `layer_kinds_antimodally_tied() ⇒ layer_kinds_any_observed()`
/// always — a tied trough requires at least two observed cells,
/// so the empty chain (zero observed cells) cannot fire.
/// Contrapositively, `!layer_kinds_any_observed() ⇒
/// !layer_kinds_antimodally_tied()`.
/// - `layer_kinds_singular_support() ⇒
/// !layer_kinds_antimodally_tied()` always — a singleton-support
/// chain has exactly one observed cell, so the antimodal level
/// set has cardinality `1` and the tie predicate fails.
/// Contrapositively, `layer_kinds_antimodally_tied() ⇒
/// !layer_kinds_singular_support()`: a fired tie predicate means
/// at least two observed cells. Direct pin of the histogram-side
/// subsumption `has_singular_support ⇒ !is_antimodally_tied` one
/// altitude down.
/// - `layer_kinds_full_cover() ∧ layer_kinds_balanced() ⇒
/// layer_kinds_antimodally_tied()` on the cardinality-`>= 2`
/// axis: a full-cover uniform-count chain has every cell
/// observed at the same count, so the antimodal level set equals
/// the full axis — the trough multiplicity rises to
/// `axis_cardinality::<ConfigSourceKind>()` which is `3`, and
/// the tie predicate fires. Cardinality-`>= 2` witness of the
/// uniform-cover corner of the histogram-side subsumption tying
/// [`crate::AxisHistogram::is_uniform_count`] and
/// [`crate::AxisHistogram::has_singular_support`] on non-empty
/// histograms one altitude down.
/// - **Strict antimodal partition on non-empty chains** —
/// `layer_kinds_any_observed() ⇒ (layer_kinds_antimodally_tied
/// ⇔ !layer_kind_histogram().is_strictly_antimodally_unique())`
/// always. On every non-empty chain exactly one of
/// `(layer_kinds_antimodally_tied,
/// layer_kind_histogram().is_strictly_antimodally_unique())`
/// fires; both read `false` on the empty chain — the shared
/// boundary below both branches. Direct pin of the histogram-
/// side strict antimodal partition one altitude down.
/// - **Modal / antimodal collapse on uniform-count non-empty
/// chains** — `layer_kinds_balanced() ∧
/// layer_kinds_any_observed() ⇒ (layer_kinds_antimodally_tied
/// ⇔ layer_kinds_modally_tied)`. On every uniform-count non-
/// empty chain the two tie predicates collapse to the same
/// value. Direct pin of the histogram-side collapse
/// `is_uniform_count ∧ !is_empty ⇒ is_antimodally_tied ⇔
/// is_modally_tied` one altitude down, peer of the same collapse
/// pinned at the diff altitude by
/// [`crate::ConfigDiff::kinds_antimodally_tied`] and at the tier
/// altitude by
/// [`crate::ProvenanceMap::tiers_antimodally_tied`].
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<ConfigSourceKind>()`
/// (the trough-multiplicity scan). Both are `O(n)` in practice
/// since the layer-kind axis carries a fixed three-cell
/// cardinality; the returned `bool` reads one predicate — the
/// trough scan walks the counts vector once and counts cells
/// matching the strictly-positive minimum, then reads
/// `multiplicity >= 2` off one comparison. Strictly tighter than
/// the two documented open-coded surfaces one seam over (no
/// exposed `>= 2` magic threshold at the consumer site, no
/// [`crate::AxisHistogram::modality_degree`] fused-pair build for
/// a single-component projection).
#[must_use]
fn layer_kinds_antimodally_tied(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().is_antimodally_tied()
}
/// `true` exactly when this chain's observed [`ConfigSourceKind`]
/// histogram has exactly one cell holding the peak leaf count — the
/// peak is *uniquely held* rather than shared.
///
/// The **strictly-modally-unique-layer-kinds boolean predicate** on
/// the layer-kind sub-axis of the chain altitude, the direct strict-
/// complement of [`Self::layer_kinds_modally_tied`] on every non-
/// empty chain (both read `false` on the empty chain — the shared
/// boundary below both branches of the strict modal partition).
/// Routes through [`Self::layer_kind_histogram`]`::is_strictly_modally_unique`,
/// the single-pass scan over the fixed-cardinality counts vector
/// reading `peak_multiplicity() == 1` off one predicate — strictly
/// tighter than either of the documented open-coded surface forms
/// one seam over.
///
/// The **strictly-modally-unique-layer-kinds peer** of the two
/// documented surface forms consumers previously re-derived inline:
/// `chain.layer_kind_histogram().peak_multiplicity() == 1` (the
/// defining multiplicity-scalar equality form — one method call
/// plus a magic `== 1` threshold at the consumer site), and
/// `chain.layer_kind_histogram().modality_degree().0 == 1` (the
/// modality-pair projection-equality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// equality — a fused-pair build for a single-component
/// projection). This lift names the strictly-modally-unique-layer-
/// kinds predicate directly at the chain-altitude surface — the
/// typed boolean every operator-facing *"is the dominant layer kind
/// uniquely held on this chain, or is the declaration-order tie-
/// break exercised?"* check reads off as a single method call, on
/// the strict-uniqueness side of the strict modal partition.
///
/// The chain-altitude layer-kind sub-axis strict-modal-uniqueness-
/// predicate peer that **lifts the "strictly-modally-unique across
/// altitudes" projection sideways** from the tier altitude
/// ([`crate::ProvenanceMap::tiers_strictly_modally_unique`]) to the
/// first chain-altitude sub-axis, seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_strictly_modally_unique`]. The two
/// remaining chain-altitude sub-axes
/// ([`Self::file_formats_strictly_modally_unique`] over
/// [`Self::file_format_histogram`],
/// [`Self::env_prefix_kinds_strictly_modally_unique`] over
/// [`Self::env_prefix_kind_histogram`]) are the natural next
/// sideways lifts, mirroring the four-step lift trajectory of the
/// eight prior projections. Strict-uniqueness row on top of the
/// closed modality-tie boolean pair
/// ([`Self::layer_kinds_modally_tied`],
/// [`Self::layer_kinds_antimodally_tied`]) — with this lift the
/// "strictly-modally-unique across altitudes" projection carries
/// one named cube-native seam at three of the five altitudes /
/// sub-axes (diff, tier, and the first chain sub-axis). The
/// pattern is the same at every altitude / sub-axis: fuse the two
/// open-coded surface forms (multiplicity-scalar equality,
/// modality-pair projection-equality) into a single boolean
/// predicate named at the surface, routed through the shared
/// [`crate::AxisHistogram::is_strictly_modally_unique`] primitive
/// one altitude down.
///
/// **Cardinality-`3` reachability at the layer-kind sub-axis —
/// the strictly-modally-unique corner carries witnesses across
/// the singleton-support and strictly-modal-skewed corners.**
/// [`ConfigSourceKind`] carries three cells, so
/// `layer_kinds_strictly_modally_unique()` reads `true` on every
/// chain whose peak leaf count is uniquely held by exactly one
/// observed layer-kind cell (e.g. a singleton-support chain with
/// all layers on `File`, or the `sample_chain()` fixture with
/// two-`File`+one-`Env` where `File` uniquely peaks at count
/// `2`), and `false` on the empty chain (no observed cell, no
/// peak), on every two-kind tied-at-count-`1` chain (two cells
/// share the peak), and on the uniform three-kind cover (all
/// three cells sit at the same peak count). Matches the diff-
/// altitude peer on the same cardinality-`3` [`crate::DiffLineKind`]
/// axis in reachability; the tier altitude (cardinality-`4`
/// [`crate::ConfigTierKind`] axis) carries an additional support-`3`
/// three-tier tied-at-`1` counter-witness that the cardinality-`3`
/// axis cannot inhabit (three-cell tied-at-`1` is the full-cover
/// corner one column up).
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain observes zero cells, so
/// [`crate::AxisHistogram::peak_multiplicity`] reads `0` and the
/// equality `0 == 1` fails. Matches
/// [`crate::AxisHistogram::is_strictly_modally_unique`]'s empty-
/// histogram convention one altitude down. The empty-chain row on
/// the strict modal partition pair
/// `(is_strictly_modally_unique, is_modally_tied)` reads
/// `(false, false)` — the shared boundary below both branches.
/// Peer of [`crate::ConfigDiff::kinds_strictly_modally_unique`]'s
/// empty-diff `false` polarity and
/// [`crate::ProvenanceMap::tiers_strictly_modally_unique`]'s
/// empty-map `false` polarity in the same projection.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single [`ConfigSourceKind`]
/// cell: the lone observed cell stands alone at its own peak (no
/// tie-break to exercise), so `peak_multiplicity` reads `1` and
/// the equality `1 == 1` fires. Every chain with all layers being
/// only-`Defaults`, only-`Env`, or only-`File` is a witness on
/// the `true` side — the singleton-support corner is uniformly on
/// the strictly-modally-unique side of the strict modal partition.
/// Direct pin of the histogram-side subsumption
/// `has_singular_support ⇒ is_strictly_modally_unique` one
/// altitude down.
///
/// **Uniform three-kind cover convention** — returns `false` on
/// every chain where each [`ConfigSourceKind`] cell was observed
/// at exactly the same positive count (in particular the chain
/// with one layer per kind): the three cells share the same
/// count, so `peak_multiplicity` reads `3` and the equality
/// `3 == 1` fails. Peer of the histogram-side axis-cover
/// convention one altitude down, which reads `false` on every
/// implementor with `axis_cardinality::<A>() >= 2` — the
/// cardinality-`3` [`ConfigSourceKind`] axis honours the general
/// condition.
///
/// **Two-way modal partition on non-empty chains** — on every
/// non-empty chain exactly one of the modal-uniqueness pair
/// `(layer_kinds_strictly_modally_unique, layer_kinds_modally_tied)`
/// fires: either the peak is uniquely held (strictly-modally-
/// unique fires, modally-tied does not) or the peak is shared
/// (modally-tied fires, strictly-modally-unique does not). The
/// empty chain sits below both branches (both read `false`).
/// Direct pin of the histogram-side strict modal partition
/// `!is_empty ⇒ is_strictly_modally_unique ⇔ !is_modally_tied`
/// one altitude down, phrased as an XOR on the two named seams
/// at the chain layer-kind sub-axis surface — the seam-level
/// dual of the matching pin
/// [`Self::layer_kinds_modally_tied`] that reads the strict side
/// off the histogram primitive.
///
/// # Invariants
///
/// - `layer_kinds_strictly_modally_unique() == layer_kind_histogram().is_strictly_modally_unique()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `layer_kinds_strictly_modally_unique() ⇔
/// layer_kind_histogram().peak_multiplicity() == 1` — the
/// defining multiplicity-scalar equality form on the
/// [`crate::AxisHistogram::peak_multiplicity`] scalar peer, the
/// canonical open-coded expression of the predicate one altitude
/// down.
/// - `layer_kinds_strictly_modally_unique() ⇔
/// layer_kind_histogram().modality_degree().0 == 1` — the
/// modality-pair projection-equality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// equality.
/// - `layer_kinds_strictly_modally_unique() ⇒
/// layer_kinds_any_observed()` always — a strictly-unique peak
/// requires at least one observed cell as the sole member of
/// the modal level set, so the empty chain (zero observed
/// cells) cannot fire. Contrapositively,
/// `!layer_kinds_any_observed() ⇒
/// !layer_kinds_strictly_modally_unique()`.
/// - `layer_kinds_singular_support() ⇒
/// layer_kinds_strictly_modally_unique()` always — a singleton-
/// support chain has exactly one observed cell as the sole
/// member of the modal level set, so the uniqueness predicate
/// fires. Direct pin of the histogram-side subsumption
/// `has_singular_support ⇒ is_strictly_modally_unique` one
/// altitude down.
/// - **Strict modal partition on non-empty chains** —
/// `layer_kinds_any_observed() ⇒
/// (layer_kinds_strictly_modally_unique ⇔
/// !layer_kinds_modally_tied())` always. On every non-empty
/// chain exactly one of
/// `(layer_kinds_strictly_modally_unique,
/// layer_kinds_modally_tied)` fires; both read `false` on the
/// empty chain — the shared boundary below both branches.
/// Direct pin of the histogram-side strict-modal-partition law
/// one altitude down, phrased as an XOR on the two named seams
/// at the chain layer-kind sub-axis surface.
/// - `layer_kinds_full_cover() ∧ layer_kinds_balanced() ⇒
/// !layer_kinds_strictly_modally_unique()` on the cardinality-
/// `>= 2` axis: a full-cover uniform-count chain has every
/// cell observed at the same count, so the modal level set
/// equals the full axis — the peak multiplicity rises to
/// `axis_cardinality::<ConfigSourceKind>()` which is `3`, and
/// the uniqueness predicate fails. Cardinality-`>= 2` witness
/// of the uniform-cover corner of the histogram-side
/// subsumption tying [`crate::AxisHistogram::is_uniform_count`]
/// and [`crate::AxisHistogram::has_singular_support`] on non-
/// empty histograms one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<ConfigSourceKind>()`
/// (the peak-multiplicity scan). Both are `O(n)` in practice
/// since the layer-kind axis carries a fixed three-cell
/// cardinality; the returned `bool` reads one predicate — the
/// peak scan walks the counts vector once and counts cells
/// matching the max, then reads `multiplicity == 1` off one
/// comparison. Strictly tighter than the two documented open-
/// coded surfaces one seam over (no exposed `== 1` magic
/// threshold at the consumer site, no
/// [`crate::AxisHistogram::modality_degree`] fused-pair build for
/// a single-component projection).
#[must_use]
fn layer_kinds_strictly_modally_unique(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.layer_kind_histogram().is_strictly_modally_unique()
}
/// Dense per-format tally of the chain's [`ConfigSource::File`]
/// layers over the [`crate::discovery::Format`] axis — the typed
/// histogram every per-format dashboard, attestation manifest
/// bucketing the (yaml × toml × lisp × nix) loader counts, and
/// chain-shape audit has previously re-derived inline.
///
/// Equivalent to
/// `crate::axis_histogram(self.iter().filter_map(ConfigSource::file_format))`
/// but named at the chain-walk surface so consumers reading the
/// recipe ([`crate::ConfigStore::sources`] /
/// [`crate::ProviderChain::sources`]) don't reach for the cube-
/// level generic helper. Only [`ConfigSource::File`] entries with
/// a recognized extension contribute: [`ConfigSource::Defaults`]
/// and [`ConfigSource::Env`] entries project to [`None`] through
/// [`ConfigSource::file_format`] (no path to read), as do `File`
/// entries whose extension is unrecognized or absent (the
/// conservative TOML fallback in
/// [`crate::ProviderChain::with_file`] does not declare a format
/// on the recipe). The histogram's `total()` therefore equals the
/// count of `File` entries with recognized extensions, which is
/// at most `self.layer_kind_histogram().count(ConfigSourceKind::File)`
/// — with equality exactly when every file layer in the chain
/// carries a recognized extension. `is_empty()` iff no chain
/// entry projects through [`ConfigSource::file_format`] to a
/// recognized format.
///
/// Peer to [`Self::layer_kind_histogram`] on the
/// [`ConfigSourceKind`] axis,
/// [`crate::ConfigDiff::kind_histogram`] on the diff-line axis,
/// and [`crate::axis_histogram`] on the generic closed-axis
/// helper surface. With this lift the chain-shape surface carries
/// the two natural aggregate projections side by side: one over
/// the (defaults × env × file) layer-kind axis (every entry
/// contributes), and one over the (yaml × toml × lisp × nix)
/// file-format axis (file entries with recognized extensions
/// contribute). The named histogram delivers the
/// "format-axis loader histogram over [`crate::Format`]" the
/// [`Self::layer_kind_histogram`] doc-string promised as the next
/// axis-tally consumer.
///
/// Trait-default implementation so a chain-shape consumer reading
/// the histogram does not need to retain the chain slice — the
/// projection is one method call. A future [`crate::Format`]
/// variant lands as one new column in the histogram automatically
/// (the typescape's [`crate::Format::ALL`] / [`crate::AxisHistogram`]
/// discipline sizes the slot count); no per-consumer update is
/// required.
fn file_format_histogram(&self) -> crate::AxisHistogram<crate::discovery::Format>
where
Self: AsRef<[ConfigSource]>,
{
crate::axis_histogram(self.as_ref().iter().filter_map(ConfigSource::file_format))
}
/// The distinct [`crate::discovery::Format`]s that appear as ≥1
/// recognized-extension file layer in this chain, in
/// [`crate::discovery::Format::ALL`] declaration order — the
/// chain-altitude dual of "which file formats actually surfaced in
/// this recipe".
///
/// Routes through [`Self::file_format_histogram`]:
/// [`crate::AxisHistogram::observed`] iterates the histogram's
/// support (the closed-axis cells with nonzero count) in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`crate::discovery::Format`] canonical order
/// (`Yaml → Toml → Lisp → Nix`) by construction — the closed-axis
/// discipline provides the sort + dedup automatically, so this
/// method reads directly off the shikumi cube-native primitive
/// instead of hand-rolling `Vec::contains` (`O(n·k)` in the chain
/// length and distinct-format count) + explicit
/// `sort_by_key(axis_ordinal)` at every attestation manifest,
/// structured-log dashboard, or config-show renderer summarizing
/// which file formats contributed to the recipe.
///
/// The chain-altitude sister of [`Self::present_layer_kinds`] on
/// the [`ConfigSourceKind`] layer-kind axis — same observed-cells
/// projection template, one axis over. Together with
/// [`Self::present_env_prefix_kinds`] the three chain-shape
/// histograms all carry the observed-cells peer alongside their
/// respective `_histogram()` primitive; every "which cells
/// surfaced?" question on the recipe reaches for the same named
/// seam at whichever sub-axis it lives on. Peer to
/// [`crate::ConfigDiff::present_kinds`] on the diff altitude and
/// [`crate::ProvenanceMap::contributing_tiers`] on the tier
/// altitude — all four project the observed-support of the
/// underlying [`crate::AxisHistogram`] over their local closed
/// axis, all four live as a `Vec<CellKind>` collect wrapper
/// alongside their respective `_histogram()` primitive, and all
/// four spell the closed-axis declaration-order cell iteration at
/// the API boundary.
///
/// # Invariants
///
/// - `present_file_formats().len() ==
/// file_format_histogram().distinct_cells()` — both project the
/// same support-cardinality off the histogram.
/// - `present_file_formats().is_empty() ==
/// file_format_histogram().is_empty()` — a histogram with no
/// observed file-format cell has no present formats, and vice
/// versa. Unlike [`Self::present_layer_kinds`], the presence
/// bound is NOT tied to `self.as_ref().is_empty()`: a chain of
/// only [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers is
/// non-empty but has no present formats, because those entries
/// project to [`None`] through [`ConfigSource::file_format`].
/// - `file_format_histogram().is_full_cover() ==
/// (present_file_formats().len() ==
/// crate::axis_cardinality::<crate::discovery::Format>())` —
/// the full-cover predicate and the observed-cells cardinality
/// agree by construction over the same shared histogram.
/// - `present_file_formats()` is sorted strictly ascending by
/// [`crate::axis_ordinal`] on [`crate::discovery::Format`] —
/// dedup and sort for free from the closed-axis discipline; no
/// hand-rolled `sort_by_key` at the consumer.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the support scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `Vec<Format>` is at most four elements long regardless
/// of chain length.
fn present_file_formats(&self) -> Vec<crate::discovery::Format>
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().observed().collect()
}
/// The number of distinct [`crate::discovery::Format`]s that appear as
/// ≥1 recognized-extension file layer in this chain — the support-size
/// scalar-count peer of [`Self::present_file_formats`] on the file-
/// format sub-axis of the chain altitude, and the file-format-sub-axis
/// sister of [`Self::present_layer_kinds_count`] on the layer-kind
/// sub-axis one axis over.
///
/// Routes through [`Self::file_format_histogram`]:
/// [`crate::AxisHistogram::distinct_cells`] is the cube-native
/// single-pass `.filter(|&&c| c > 0).count()` walk over the
/// fixed-cardinality counts vector, so this method reads the support
/// size in one call instead of paying for the `Vec<Format>` allocation
/// [`Self::present_file_formats`] materialises and then walking
/// [`Vec::len`] to read the length back — the exact idiom every
/// operator-facing consumer asking *"how many file formats
/// contributed to this recipe?"* has been open-coding at [`Vec::len`]
/// of the observed-cells `Vec` peer:
///
/// - the config-show summary line *"1 of 4 file formats contributed
/// to this recipe"* reading the support cardinality directly off
/// the seam,
/// - the attestation manifest recording the file-format support size
/// of a `ProviderChain` between two rebuild-window snapshots,
/// - the alerting policy reading *"file-format support size = 1"* to
/// flag a recipe where only one file format surfaced.
///
/// The file-format sub-axis scalar-count peer of the chain altitude,
/// sister to the layer-kind sub-axis's
/// [`Self::present_layer_kinds_count`], the tier altitude's
/// [`crate::ProvenanceMap::contributing_tiers_count`], and the diff
/// altitude's [`crate::ConfigDiff::present_kinds`] length peer.
/// Together with [`Self::present_file_formats`] and
/// [`Self::absent_file_formats`], this seam closes the
/// `(observed, unobserved) × (cells, count)` 2×2 support / coverage-
/// gap grid on the file-format sub-axis:
///
/// | | cells (Vec) | count (usize) |
/// |---|---|---|
/// | observed | [`Self::present_file_formats`] | **`present_file_formats_count`** |
/// | unobserved | [`Self::absent_file_formats`] | [`Self::absent_file_formats_count`] |
///
/// # Invariants
///
/// - `present_file_formats_count() ==
/// file_format_histogram().distinct_cells()` — both project the
/// same nonzero-cell count off the same primitive; the named seam
/// is the cube-native routing of the histogram surface. Pinned by
/// [`tests::present_file_formats_count_matches_file_format_histogram_distinct_cells_pointwise`].
/// - `present_file_formats_count() == present_file_formats().len()` —
/// the scalar-count peer of the observed-cells `Vec` peer; both
/// name the same support cardinality without materialising the
/// vector. Pinned by
/// [`tests::present_file_formats_count_equals_present_file_formats_len_pointwise`].
/// - `present_file_formats_count() + absent_file_formats().len() ==
/// crate::axis_cardinality::<crate::discovery::Format>()` — the
/// observed / coverage-gap partition on the file-format sub-axis
/// without remainder, the scalar dual of the
/// [`tests::absent_file_formats_and_present_file_formats_partition_axis`]
/// set-level partition law. Pinned by
/// [`tests::present_file_formats_count_and_absent_file_formats_len_partition_axis_cardinality`].
/// - `present_file_formats_count() == 0` ⇔
/// `file_format_histogram().is_empty()` — the empty-histogram /
/// empty-support boundary equivalence. Unlike
/// [`Self::present_layer_kinds_count`], the zero boundary is
/// **not** tied to `self.as_ref().is_empty()`: a chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers is
/// non-empty but reads zero, because those entries project to
/// [`None`] through [`ConfigSource::file_format`]. Pinned by
/// [`tests::present_file_formats_count_is_zero_iff_file_format_histogram_is_empty`].
/// - `present_file_formats_count() >= 1` whenever
/// `!file_format_histogram().is_empty()` — the support of a
/// non-empty histogram is at least the singleton of the first
/// observed cell. Pinned by
/// [`tests::present_file_formats_count_is_at_least_one_on_nonempty_histogram`].
/// - `present_file_formats_count() <=
/// crate::axis_cardinality::<crate::discovery::Format>()` — the
/// support of a histogram over a closed axis is bounded above by
/// the axis cardinality (the observed-cells set is a subset of
/// [`crate::discovery::Format::ALL`]). Pinned by
/// [`tests::present_file_formats_count_is_bounded_by_axis_cardinality`].
/// - `present_file_formats_count() <=
/// file_format_histogram().total()` — the support of a histogram
/// is bounded above by the total observation count (every distinct
/// cell contributes at least one observation to the total).
/// Pinned by
/// [`tests::present_file_formats_count_is_bounded_by_file_format_histogram_total`].
/// - `present_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>()` ⇔
/// `absent_file_formats().is_empty()` ⇔
/// `file_format_histogram().is_full_cover()` — the full-cover
/// boundary equivalence, the file-format-sub-axis scalar-count
/// peer of the [`crate::AxisHistogram::is_full_cover`] boundary
/// law. Pinned by
/// [`tests::present_file_formats_count_equals_axis_cardinality_iff_is_full_cover`].
/// - `present_file_formats_count() == 1` ⇔
/// `file_format_histogram().has_singular_support()` — the
/// singleton-support boundary equivalence, the file-format-sub-
/// axis peer of the [`crate::AxisHistogram::has_singular_support`]
/// boundary law. Pinned by
/// [`tests::present_file_formats_count_is_one_iff_has_singular_support`].
/// - `present_file_formats_count() == 1` ⇒ `dominant_file_format()
/// == recessive_file_format()` — a singleton-support recipe has
/// the modal and anti-modal cells coincide on the sole observed
/// format (the support-size scalar witnesses the
/// [`crate::AxisHistogram`] support-collapse degenerate). Pinned
/// by
/// [`tests::present_file_formats_count_of_one_implies_dominant_equals_recessive`].
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the support scan). Both are `O(n)` in practice since the file-
/// format axis carries a fixed four-cell cardinality; unlike
/// [`Self::present_file_formats`], no `Vec<Format>` allocation is
/// paid on every call site.
fn present_file_formats_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().distinct_cells()
}
/// The distinct [`crate::discovery::Format`]s that appear as **zero**
/// recognized-extension file layers in this chain, in
/// [`crate::discovery::Format::ALL`] declaration order — the coverage-
/// gap peer of [`Self::present_file_formats`] and the file-format-axis
/// sister of [`Self::absent_layer_kinds`] one axis over on the same
/// chain-shape surface.
///
/// Routes through [`Self::file_format_histogram`]:
/// [`crate::AxisHistogram::unobserved`] iterates the histogram's
/// **coverage gap** (the closed-axis cells with zero count) in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`crate::discovery::Format`] canonical order
/// (`Yaml → Toml → Lisp → Nix`) by construction — the closed-axis
/// discipline provides the sort + dedup automatically, so this method
/// reads directly off the shikumi cube-native primitive instead of
/// hand-rolling
/// `crate::discovery::Format::ALL.iter().filter(|f| !self.present_file_formats().
/// contains(f))` (`O(k·k)` in axis-cardinality, quadratic on the
/// observed side) at every operator-facing consumer asking *"which
/// file formats are absent from this recipe?"* — the CLI `config-show`
/// summary reading *"no `.nix` loader; skip the nix-loader legend"*,
/// the attestation manifest recording the file-format coverage gap
/// of a `ProviderChain`, the alerting policy suppressing per-format
/// bins that never fired for this rebuild window.
///
/// The observed-cells peer ([`Self::present_file_formats`]) and the
/// coverage-gap peer ([`Self::absent_file_formats`]) together form the
/// **support / coverage-gap partition** on the file-format sub-axis
/// — every cell of [`crate::discovery::Format::ALL`] lies in exactly
/// one of the two, and the two `Vec<Format>` lengths sum to
/// [`crate::axis_cardinality::<crate::discovery::Format>()`][crate::axis_cardinality].
/// The file-format-axis sister of [`Self::absent_layer_kinds`] on the
/// [`ConfigSourceKind`] layer-kind axis — same coverage-gap
/// projection template, one axis over. With this lift the chain-shape
/// surface now closes both halves of the histogram's observed /
/// unobserved partition at two named `Vec<CellKind>` seams over the
/// layer-kind and file-format sub-axes; only the env-prefix-presence
/// sub-axis still awaits its coverage-gap peer
/// ([`Self::absent_env_prefix_kinds`]).
///
/// # Invariants
///
/// - `absent_file_formats().len() ==
/// file_format_histogram().unobserved_cells()` — both project the
/// same coverage-gap cardinality off the histogram.
/// - `present_file_formats().len() + absent_file_formats().len() ==
/// crate::axis_cardinality::<crate::discovery::Format>()` — the
/// two peers partition the closed axis without remainder (every
/// cell is either observed or unobserved, never both).
/// - `present_file_formats()` and `absent_file_formats()` are
/// disjoint: no [`crate::discovery::Format`] appears in both.
/// - `absent_file_formats().is_empty() ==
/// file_format_histogram().is_full_cover()` — the coverage-gap is
/// empty iff every file format was observed at least once (all
/// four of `Yaml` / `Toml` / `Lisp` / `Nix` appear as ≥1 file
/// layer with the matching extension).
/// - `absent_file_formats()` on an empty chain (no layers) equals
/// [`crate::discovery::Format::ALL`] — every format is absent
/// when no layer contributed. Unlike
/// [`Self::absent_layer_kinds`], the full-axis boundary also
/// fires on any chain of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::Env`] / unrecognized-extension
/// [`ConfigSource::File`] layers — those entries all project to
/// [`None`] through [`ConfigSource::file_format`], so the
/// histogram is empty even when the chain is not.
/// - `absent_file_formats()` is sorted strictly ascending by
/// [`crate::axis_ordinal`] on [`crate::discovery::Format`] —
/// dedup + sort for free from the closed-axis discipline.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the coverage-gap scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `Vec<Format>` is at most four elements long regardless
/// of chain length.
fn absent_file_formats(&self) -> Vec<crate::discovery::Format>
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().unobserved().collect()
}
/// The number of distinct [`crate::discovery::Format`]s that appear as
/// **zero** recognized-extension file layers in this chain — the
/// coverage-gap-size scalar-count peer of [`Self::absent_file_formats`]
/// on the file-format sub-axis of the chain altitude, and the file-
/// format-sub-axis sister of [`Self::absent_layer_kinds_count`] on the
/// layer-kind sub-axis one axis over on the same chain-shape surface.
///
/// Routes through [`Self::file_format_histogram`]:
/// [`crate::AxisHistogram::unobserved_cells`] is the cube-native single-
/// pass `.filter(|&&c| c == 0).count()` walk over the fixed-cardinality
/// counts vector, so this method reads the coverage-gap size in one call
/// instead of paying for the `Vec<Format>` allocation
/// [`Self::absent_file_formats`] materialises and then walking
/// [`Vec::len`] to read the length back — the exact idiom every
/// operator-facing consumer asking *"how many file formats are absent
/// from this recipe?"* has been open-coding at [`Vec::len`] of the
/// coverage-gap `Vec` peer:
///
/// - the config-show summary line *"3 of 4 file formats absent this
/// rebuild window"* reading the coverage-gap cardinality directly off
/// the seam,
/// - the attestation manifest recording the file-format coverage-gap
/// size of a `ProviderChain` between two rebuild-window snapshots,
/// - the alerting policy reading *"file-format coverage-gap size = 3"*
/// to flag a recipe where only one format surfaced.
///
/// The file-format sub-axis scalar-count coverage-gap peer of the chain
/// altitude, sister to the layer-kind sub-axis's
/// [`Self::absent_layer_kinds_count`], the tier altitude's
/// [`crate::ProvenanceMap::absent_tiers_count`], and the diff altitude's
/// [`crate::ConfigDiff::absent_kinds_count`]. Together with
/// [`Self::present_file_formats`], [`Self::absent_file_formats`], and
/// [`Self::present_file_formats_count`], this seam closes the
/// `(observed, unobserved) × (cells, count)` 2×2 support / coverage-gap
/// grid on the file-format sub-axis explicitly — every quadrant of the
/// grid is now a named seam:
///
/// | | cells (Vec) | count (usize) |
/// |---|---|---|
/// | observed | [`Self::present_file_formats`] | [`Self::present_file_formats_count`] |
/// | unobserved | [`Self::absent_file_formats`] | **`absent_file_formats_count`** |
///
/// Extends the "coverage-gap-size across altitudes" projection — seeded
/// on the diff altitude by [`crate::ConfigDiff::absent_kinds_count`],
/// lifted to the tier altitude by
/// [`crate::ProvenanceMap::absent_tiers_count`], and opened on the chain
/// altitude's layer-kind sub-axis by [`Self::absent_layer_kinds_count`]
/// — sideways to the chain altitude's second sub-axis. The chain-
/// altitude env-prefix sister lift
/// ([`Self::absent_env_prefix_kinds_count`]) on the same chain-shape
/// surface closes the projection across every altitude and every chain
/// sub-axis on the same template.
///
/// **Empty-histogram convention** — returns
/// [`crate::axis_cardinality::<crate::discovery::Format>()`][crate::axis_cardinality]
/// (not `Option<usize>`) matching the [`Self::absent_file_formats`]
/// full-axis convention and the
/// [`crate::AxisHistogram::unobserved_cells`] convention one altitude
/// down. Unlike [`Self::absent_layer_kinds_count`], the full-axis
/// boundary is tied to the histogram's own emptiness, **not** the
/// chain's: a non-empty chain of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::Env`] / unrecognized-extension [`ConfigSource::File`]
/// layers still reads `axis_cardinality::<Format>()` because every
/// entry projects to [`None`] through [`ConfigSource::file_format`],
/// leaving the histogram empty and every format in the coverage gap.
///
/// # Invariants
///
/// - `absent_file_formats_count() ==
/// file_format_histogram().unobserved_cells()` — both project the
/// same coverage-gap cardinality off the same primitive; the named
/// seam is the cube-native routing of the histogram surface. Pinned
/// by
/// [`tests::absent_file_formats_count_matches_file_format_histogram_unobserved_cells_pointwise`].
/// - `absent_file_formats_count() == absent_file_formats().len()` —
/// the scalar-count peer of the coverage-gap `Vec` peer; both name
/// the same coverage-gap cardinality without materialising the
/// vector. Pinned by
/// [`tests::absent_file_formats_count_equals_absent_file_formats_len_pointwise`].
/// - `present_file_formats_count() + absent_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>()` — the
/// observed / coverage-gap partition on the file-format sub-axis
/// without remainder, the fully-scalar dual of
/// [`tests::absent_file_formats_and_present_file_formats_partition_axis`]
/// (both sides now scalar-count, no `.len()` on either). Pinned by
/// [`tests::present_file_formats_count_and_absent_file_formats_count_partition_axis_cardinality`].
/// - `absent_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>() -
/// present_file_formats_count()` — the algebraic rearrangement of
/// the partition, useful for consumers that already hold the
/// support-size scalar. Pinned by
/// [`tests::absent_file_formats_count_equals_axis_cardinality_minus_present_file_formats_count`].
/// - `absent_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>()` ⇔
/// `file_format_histogram().is_empty()` — the empty-histogram /
/// full-coverage-gap boundary equivalence, the scalar peer of
/// `absent_file_formats() == Format::ALL`. Unlike
/// [`Self::absent_layer_kinds_count`], the full-axis boundary fires
/// on any chain whose entries all project to [`None`] through
/// [`ConfigSource::file_format`] — not just on the empty chain.
/// Pinned by
/// [`tests::absent_file_formats_count_is_axis_cardinality_iff_file_format_histogram_is_empty`].
/// - `absent_file_formats_count() == 0` ⇔
/// `file_format_histogram().is_full_cover()` — the full-cover
/// boundary equivalence, the file-format-sub-axis scalar-count
/// coverage-gap peer of the [`crate::AxisHistogram::is_full_cover`]
/// boundary law and the coverage-gap dual of
/// `present_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>()`. Pinned by
/// [`tests::absent_file_formats_count_is_zero_iff_is_full_cover`].
/// - `absent_file_formats_count() <=
/// crate::axis_cardinality::<crate::discovery::Format>()` — the
/// coverage gap of a histogram over a closed axis is bounded above
/// by the axis cardinality (the unobserved-cells set is a subset of
/// [`crate::discovery::Format::ALL`]). Pinned by
/// [`tests::absent_file_formats_count_is_bounded_by_axis_cardinality`].
/// - `absent_file_formats_count() >= 1` whenever
/// `!file_format_histogram().is_full_cover()` — a non-full-cover
/// recipe carries at least one absent format. Pinned by
/// [`tests::absent_file_formats_count_is_at_least_one_when_not_full_cover`].
/// - `absent_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>() - 1` ⇔
/// `file_format_histogram().has_singular_support()` — the
/// singleton-support boundary in coverage-gap form: when exactly
/// one file format is observed, exactly `axis_cardinality - 1` are
/// absent. Pinned by
/// [`tests::absent_file_formats_count_is_axis_cardinality_minus_one_iff_has_singular_support`].
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the coverage-gap scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `usize` reads one scalar. Halves the wall-cost of the
/// previous `absent_file_formats().len()` idiom by eliding the
/// `Vec<Format>` allocation the coverage-gap collect paid on every
/// call site.
fn absent_file_formats_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().unobserved_cells()
}
/// The [`crate::discovery::Format`] whose entries produced the greatest
/// number of recognized-extension file layers on this chain — the modal
/// cell of [`Self::file_format_histogram`] on the chain altitude. `None`
/// exactly when the histogram is empty (no chain entry projects through
/// [`ConfigSource::file_format`] to a recognized format).
///
/// Routes through [`Self::file_format_histogram`]:
/// [`crate::AxisHistogram::dominant_cell`] picks the argmax cell in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`crate::discovery::Format`] canonical order
/// (`Yaml → Toml → Lisp → Nix`) by construction — the closed-axis
/// discipline provides deterministic tie-breaking automatically, so
/// this method reads directly off the shikumi cube-native primitive
/// instead of hand-rolling
/// `hist.iter().filter(|&(_, c)| c > 0).max_by_key(|&(_, c)| c).map(|(v, _)| v)`
/// — the inline `max_by_key` form silently picks the *last* tied cell
/// (per [`Iterator::max_by_key`]'s contract), so two consumers reading
/// "the dominant file format" off the same chain would disagree under
/// ties unless every one carefully reversed the comparison. The lift
/// names the scalar at one site with a documented tie-breaking rule.
///
/// The chain-altitude scalar-mode peer of [`Self::present_file_formats`]
/// (the observed-cells vector peer) and [`Self::absent_file_formats`]
/// (the coverage-gap vector peer): the file-format sub-axis of the
/// chain-shape surface now carries the natural triple of "*which*
/// formats surfaced" / "*which* formats didn't" / "*which single*
/// format dominated" projections at one named seam each, over the
/// shared [`Self::file_format_histogram`] primitive. Direct sister of
/// [`Self::dominant_layer_kind`] on the same chain altitude one sub-
/// axis over — with this lift two of the three chain-shape sub-axes
/// close the scalar-mode dominance peer at one named
/// `Option<CellKind>` seam alongside the observed / coverage-gap
/// vector-mode pair; the env-prefix-presence sub-axis
/// ([`Self::dominant_env_prefix_kind`]) closes the same peer in a
/// sibling lift.
///
/// Operator-facing consumers answering *"which file format dominated
/// this chain?"* — the CLI `config-show` summary headlining
/// *"YAML loaders dominate: 3 of 4 files"* to explain why the recipe
/// is yaml-heavy, the attestation manifest recording the modal format
/// between two `ProviderChain` snapshots, the alerting policy reading
/// *"format dominance: Toml"* to flag a migration window where a
/// yaml-first recipe drifted toml-first — now route through this
/// named seam instead of a per-consumer `max_by_key` walk.
///
/// **Tie-breaking is deterministic by declaration order.** When
/// multiple formats share the maximum file-layer count, the format
/// earliest in [`crate::discovery::Format::ALL`] wins — the same
/// [`crate::discovery::Format`] canonical order
/// [`Self::present_file_formats`] and [`Self::absent_file_formats`]
/// walk. A uniform-cover chain (each format producing the same
/// nonzero file-layer count) therefore reports
/// `Some(crate::discovery::Format::Yaml)` — the first cell in
/// declaration order — pointwise stable regardless of the insertion
/// order of individual file layers into the chain slice.
///
/// # Invariants
///
/// - `dominant_file_format().is_some() ==
/// !file_format_histogram().is_empty()` — unlike
/// [`Self::dominant_layer_kind`], the presence bound is *not*
/// `!self.as_ref().is_empty()`: [`ConfigSource::Defaults`] /
/// [`ConfigSource::Env`] / unrecognized-extension
/// [`ConfigSource::File`] entries all project to [`None`] through
/// [`ConfigSource::file_format`], so the histogram is empty even on
/// a non-empty chain when no `File` entry carries a recognized
/// extension.
/// - `dominant_file_format() == file_format_histogram().dominant_cell()`
/// — both project the same modal cell off the same primitive; the
/// named seam is the cube-native routing of the chain-shape surface.
/// - When `Some(f)`, `f` is a member of `present_file_formats()` —
/// the modal cell is by definition observed.
/// - When `Some(f)`, `f` is **not** a member of `absent_file_formats()`
/// — the observed / coverage-gap partition is disjoint.
/// - `file_format_histogram().count(dominant_file_format().unwrap()) ==
/// file_format_histogram().peak_count()` whenever the histogram is
/// non-empty — the modal cell carries the peak observation count.
/// Peer to the `(dominant_cell, peak_count)` modal pair invariant
/// on [`crate::AxisHistogram`].
/// - `dominant_file_format()` on a uniform full-cover chain (one file
/// layer per format) equals
/// `Some(crate::discovery::Format::Yaml)` — declaration-order
/// tie-breaking on the four-cell axis picks the first cell.
/// - `dominant_file_format()` on an empty chain equals `None` — the
/// empty-chain / empty-histogram boundary.
/// - `dominant_file_format()` on a chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers equals
/// `None` — the non-empty-chain / empty-histogram boundary the
/// file-format sub-axis pins that the layer-kind sub-axis does not.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the argmax scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `Option<crate::discovery::Format>` reads one cell.
#[must_use]
fn dominant_file_format(&self) -> Option<crate::discovery::Format>
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().dominant_cell()
}
/// The [`crate::discovery::Format`] whose entries produced the
/// smallest nonzero number of recognized-extension file layers on this
/// chain — the anti-modal cell of [`Self::file_format_histogram`] on
/// the chain altitude. `None` exactly when the histogram is empty (no
/// chain entry projects through [`ConfigSource::file_format`] to a
/// recognized format).
///
/// Routes through [`Self::file_format_histogram`]:
/// [`crate::AxisHistogram::recessive_cell`] picks the argmin cell over
/// the histogram's *support* (the nonzero cells) in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`crate::discovery::Format`] canonical order
/// (`Yaml → Toml → Lisp → Nix`) by construction — the closed-axis
/// discipline provides deterministic tie-breaking automatically, so
/// this method reads directly off the shikumi cube-native primitive
/// instead of hand-rolling
/// `hist.iter().filter(|&(_, c)| c > 0).min_by_key(|&(_, c)| c).map(|(v, _)| v)`
/// — the inline `min_by_key` form silently picks the *first* tied cell
/// (per [`Iterator::min_by_key`]'s contract, which reverses
/// [`Iterator::max_by_key`]'s "last on ties" behavior), so an
/// open-coded argmin and the open-coded argmax on the dominant side
/// would disagree on which tied cell to pick. The pair of lifts
/// ([`Self::dominant_file_format`] and [`Self::recessive_file_format`])
/// pins one consistent tie-breaking rule across both projections on
/// the chain-altitude file-format sub-axis.
///
/// **Zero-count formats are excluded from the search.** The argmin is
/// taken over the histogram's support, not over the full axis. Formats
/// that contributed no recognized-extension file layer would trivially
/// be the minimum over the full axis and would shadow the rarest
/// *observed* format; excluding them surfaces the rarest format some
/// file layer actually landed on — the question the CLI `config-show`
/// summary, attestation manifest, and alerting policy ask when they
/// surface *"the runt file format this recipe saw"*. This matches
/// [`Self::dominant_file_format`]'s symmetry on the maximum side: both
/// projections operate over the nonzero support, so the empty-histogram
/// convention is identical (both return `None`) and the singleton-
/// support case is identical (both return the sole observed format).
///
/// The chain-altitude anti-modal peer of [`Self::dominant_file_format`]
/// (the modal-cell scalar peer of the same
/// [`Self::file_format_histogram`] primitive) — the file-format sub-
/// axis of the chain-shape surface now carries the fused (dominant,
/// recessive) cell pair, matching the
/// ([`crate::AxisHistogram::dominant_cell`],
/// [`crate::AxisHistogram::recessive_cell`]) pair on the shared
/// [`crate::AxisHistogram`] primitive one altitude down. Direct sister
/// of [`Self::recessive_layer_kind`] on the layer-kind sub-axis of the
/// same chain altitude, [`crate::ProvenanceMap::recessive_tier`] on
/// the tier altitude, and [`crate::ConfigDiff::recessive_kind`] on the
/// diff altitude — all four project the anti-modal cell of their local
/// closed-axis histogram off the shared
/// [`crate::AxisHistogram::recessive_cell`] primitive, all four live
/// as an `Option<CellKind>` scalar alongside the modal-cell peer.
///
/// Operator-facing consumers answering *"which file format is the
/// runt of this recipe?"* — the CLI `config-show` summary headlining
/// *"runt: Nix, 1 of 47 recognized files"*, the attestation manifest
/// recording the anti-modal file format between two `ProviderChain`
/// snapshots, the alerting policy reading *"format runt: Lisp"* to
/// flag a migration window where the Lisp overlay contributed almost
/// no file layers — now route through this named seam instead of a
/// per-consumer `min_by_key` walk.
///
/// **Tie-breaking is deterministic by declaration order.** When
/// multiple observed formats share the minimum file-layer count, the
/// format earliest in [`crate::discovery::Format::ALL`] wins (`Yaml →
/// Toml → Lisp → Nix`) — the same order [`Self::present_file_formats`],
/// [`Self::absent_file_formats`], and [`Self::dominant_file_format`]
/// walk. A uniform-cover chain (each format producing the same nonzero
/// file-layer count) therefore reports
/// `Some(crate::discovery::Format::Yaml)` — the first cell in
/// declaration order — pointwise identical to
/// [`Self::dominant_file_format`] on the same input (the singleton-
/// modality degenerate where the modal and anti-modal cells coincide).
///
/// # Invariants
///
/// - `recessive_file_format().is_some() ==
/// !file_format_histogram().is_empty()` — unlike
/// [`Self::recessive_layer_kind`], the presence bound is *not*
/// `!self.as_ref().is_empty()`: [`ConfigSource::Defaults`] /
/// [`ConfigSource::Env`] / unrecognized-extension
/// [`ConfigSource::File`] entries all project to [`None`] through
/// [`ConfigSource::file_format`], so the histogram is empty even on
/// a non-empty chain when no `File` entry carries a recognized
/// extension. Mirrors [`Self::dominant_file_format`]'s presence
/// bound at the same sub-axis one modality over.
/// - `recessive_file_format().is_some() == dominant_file_format().is_some()`
/// — both projections are defined on the same support
/// (`!file_format_histogram().is_empty()`), lifted from the
/// [`crate::AxisHistogram::recessive_cell`] /
/// [`crate::AxisHistogram::dominant_cell`] presence-bound law.
/// - `recessive_file_format() == file_format_histogram().recessive_cell()`
/// — both project the same anti-modal cell off the same primitive;
/// the named seam is the cube-native routing of the chain-shape
/// surface.
/// - When `Some(f)`, `f` is a member of `present_file_formats()` —
/// the anti-modal cell is by definition observed.
/// - When `Some(f)`, `f` is **not** a member of `absent_file_formats()`
/// — the observed / coverage-gap partition is disjoint, and the
/// argmin over the *support* never coincides with a zero-count
/// cell.
/// - `file_format_histogram().count(recessive_file_format().unwrap()) ==
/// file_format_histogram().trough_count()` whenever the histogram is
/// non-empty — the anti-modal cell carries the trough-of-support
/// observation count. Peer to the (`recessive_cell`,
/// `trough_count`) anti-modal pair invariant on
/// [`crate::AxisHistogram`].
/// - `file_format_histogram().count(recessive_file_format().unwrap()) <=
/// file_format_histogram().count(dominant_file_format().unwrap())`
/// whenever the histogram is non-empty — the trough-of-support count
/// is bounded above by the peak count. Lifted from the trait-uniform
/// `count(recessive_cell) <= count(dominant_cell)` law on
/// [`crate::AxisHistogram`].
/// - `recessive_file_format() == dominant_file_format()` whenever
/// `present_file_formats().len() == 1` — a single observed format
/// is both the modal and the anti-modal cell (the singleton-support
/// degenerate).
/// - `recessive_file_format()` on a uniform full-cover chain (one file
/// layer per format) equals
/// `Some(crate::discovery::Format::Yaml)` — declaration-order
/// tie-breaking on the four-cell axis picks the first cell,
/// pointwise identical to `dominant_file_format()` on the same
/// input.
/// - `recessive_file_format()` on an empty chain equals `None` — the
/// empty-chain / empty-histogram boundary.
/// - `recessive_file_format()` on a chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers equals
/// `None` — the non-empty-chain / empty-histogram boundary the
/// file-format sub-axis pins that the layer-kind sub-axis does not.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the argmin scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `Option<crate::discovery::Format>` reads one cell.
#[must_use]
fn recessive_file_format(&self) -> Option<crate::discovery::Format>
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().recessive_cell()
}
/// The **peak file-layer count** — the number of recognized-extension
/// file layers contributed by the dominant [`crate::discovery::Format`]
/// on this chain. Returns `0` when the [`Self::file_format_histogram`]
/// is empty (no chain entry projects through
/// [`ConfigSource::file_format`] to a recognized format — i.e. an empty
/// chain, OR a non-empty chain of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::Env`] / unrecognized-extension [`ConfigSource::File`]
/// entries); otherwise returns the count carried by
/// [`Self::dominant_file_format`] (pointwise equal to it, and always
/// `>= 1` by the histogram-support definition).
///
/// The **scalar peer** of [`Self::dominant_file_format`] on the count
/// side — the natural typed primitive for chain-shape dashboards,
/// attestation manifests, and alerting policies asking *"how many
/// file layers did the majority format contribute?"*: the CLI
/// `config-show` summary headline *"YAML dominant: 3 of 4 files"*
/// (where 3 is this scalar), the attestation manifest recording the
/// peak file-format observation count between two `ProviderChain`
/// snapshots, the alerting policy reading *"format peak count = 7"*
/// to gate a rebuild window on the modal format's density. Before
/// this lift, every such consumer re-derived the projection inline as
/// `chain.file_format_histogram().peak_count()` or (equivalently but
/// at twice the cost) `chain.dominant_file_format().map_or(0, |f|
/// chain.file_format_histogram().count(f))` — which walked the
/// histogram *twice* (once to argmax, once to read the count back
/// through [`crate::AxisHistogram::count`] indexing) and re-built
/// the histogram at every site. Routes through
/// [`Self::file_format_histogram`]:
/// [`crate::AxisHistogram::peak_count`] reads a single pass over the
/// fixed-cardinality counts vector.
///
/// The chain-altitude scalar-count peer of [`Self::dominant_file_format`]
/// (the modal-cell scalar peer of [`Self::file_format_histogram`]) —
/// the file-format sub-axis of the chain-shape surface now carries
/// the fused `(dominant_file_format, peak_file_format_count)` modal
/// pair, matching the ([`crate::AxisHistogram::dominant_cell`],
/// [`crate::AxisHistogram::peak_count`]) pair on the shared
/// [`crate::AxisHistogram`] primitive one altitude down, the
/// ([`Self::dominant_layer_kind`], [`Self::peak_layer_kind_count`])
/// pair on the layer-kind sub-axis of the same chain altitude, the
/// ([`crate::ProvenanceMap::dominant_tier`],
/// [`crate::ProvenanceMap::peak_tier_count`]) pair on the tier
/// altitude, and the ([`crate::ConfigDiff::dominant_kind`],
/// [`crate::ConfigDiff::peak_kind_count`]) pair on the diff altitude.
/// Consumers answering *"which file format dominated the chain and by
/// how many layers?"* now read a single `(dominant_file_format(),
/// peak_file_format_count())` pair — one method each, both routing
/// through the same primitive — instead of re-deriving the count off
/// the modal cell.
///
/// **Empty-histogram convention** — returns `0` (not `Option<usize>`)
/// matching the [`crate::AxisHistogram::peak_count`] convention one
/// altitude down, the [`Self::peak_layer_kind_count`] convention on
/// the layer-kind sub-axis, and the
/// [`crate::ProvenanceMap::peak_tier_count`] /
/// [`crate::ConfigDiff::peak_kind_count`] conventions on the peer
/// altitudes; the scalar reads `0` uniformly on the empty-histogram
/// boundary. Unlike [`Self::peak_layer_kind_count`], the zero boundary
/// is NOT `!self.as_ref().is_empty()`:
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] / unrecognized-
/// extension [`ConfigSource::File`] entries all project to [`None`]
/// through [`ConfigSource::file_format`], so the histogram is empty
/// (and this scalar reads zero) even on a non-empty chain when no
/// `File` entry carries a recognized extension. The dual-form
/// [`Self::dominant_file_format`] carries
/// `Option<crate::discovery::Format>` because the *format* is
/// undefined when no recognized-extension file layer contributes;
/// the *count* is well-defined as zero.
///
/// # Invariants
///
/// - `peak_file_format_count() == 0 ⇔
/// file_format_histogram().is_empty()` — peer to the empty-histogram
/// boundary [`Self::dominant_file_format`] /
/// [`Self::recessive_file_format`] both witness on the cell side.
/// Unlike [`Self::peak_layer_kind_count`], the zero boundary is
/// NOT `self.as_ref().is_empty()`: a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers reads
/// zero as well.
/// - `peak_file_format_count() == file_format_histogram().peak_count()`
/// — both project the same scalar off the same primitive; the named
/// seam is the cube-native routing of the chain-shape surface.
/// - `peak_file_format_count() == dominant_file_format().map_or(0, |f|
/// file_format_histogram().count(f))` — the count projection of the
/// `(dominant_file_format, peak_file_format_count)` modal pair
/// equals [`Self::peak_file_format_count`] pointwise on every chain
/// (empty-histogram: `None.map_or(0, …) == 0 ==
/// peak_file_format_count`; non-empty-histogram: `Some(f).map_or(0,
/// |f| count(f)) == peak_file_format_count`, since
/// `count(dominant_file_format()) == peak_count()`).
/// - `peak_file_format_count() <= file_format_histogram().total()`
/// always: the peak is bounded above by the total recognized-
/// extension file-layer count (every format contributes at most
/// every recognized file layer, and the others contribute zero).
/// Equality holds iff `present_file_formats().len() <= 1`.
/// - `peak_file_format_count() <=
/// layer_kind_histogram().count(ConfigSourceKind::File)` always:
/// the peak on the file-format sub-axis is bounded above by the
/// count of `File` layers on the layer-kind sub-axis (every
/// recognized-extension file layer is a `File` layer, and some
/// `File` layers may have unrecognized extensions and contribute
/// to no format cell).
/// - `peak_file_format_count() >= 1` whenever
/// `!file_format_histogram().is_empty()` — a non-empty histogram
/// always has at least one layer on the dominant format.
/// - `peak_file_format_count()` on a uniform full-cover chain (one
/// file layer per format) equals `1` — every observed format
/// collects one file layer, dominant included.
/// - `peak_file_format_count()` on a singleton-support chain (every
/// recognized-extension file layer on the same format) equals
/// `file_format_histogram().total()` — the dominant format collects
/// every recognized file layer.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the argmax scan). Both are `O(n)` in practice since the file-
/// format axis carries a fixed four-cell cardinality; the returned
/// `usize` reads one scalar. Halves the cost of the previous
/// `dominant_file_format().map_or(0, |f|
/// file_format_histogram().count(f))` idiom (which walked the
/// histogram twice — once to argmax, once to read the count back).
#[must_use]
fn peak_file_format_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().peak_count()
}
/// The **trough file-layer count** — the number of recognized-extension
/// file layers contributed by the recessive (rarest-observed)
/// [`crate::discovery::Format`] on this chain. Returns `0` when the
/// [`Self::file_format_histogram`] is empty (no chain entry projects
/// through [`ConfigSource::file_format`] to a recognized format — i.e.
/// an empty chain, OR a non-empty chain of only [`ConfigSource::Defaults`]
/// / [`ConfigSource::Env`] / unrecognized-extension [`ConfigSource::File`]
/// entries); otherwise returns the count carried by
/// [`Self::recessive_file_format`] (pointwise equal to it, and always
/// `>= 1` by the histogram-support definition).
///
/// The **scalar peer** of [`Self::recessive_file_format`] on the count
/// side — the natural typed primitive for chain-shape dashboards,
/// attestation manifests, and alerting policies asking *"how many file
/// layers did the runt format contribute?"*: the CLI `config-show`
/// summary line *"runt format: lisp, 1 of 4 file layers"* (where 1 is
/// this scalar), the attestation manifest recording the trough
/// file-format observation count between two `ProviderChain` snapshots,
/// the alerting policy reading *"format trough count = 1"* to flag a
/// rebuild window where a recognized format barely contributed. Before
/// this lift, every such consumer re-derived the projection inline as
/// `chain.file_format_histogram().trough_count()` or (equivalently but
/// at twice the cost) `chain.recessive_file_format().map_or(0, |f|
/// chain.file_format_histogram().count(f))` — which walked the
/// histogram *twice* (once to argmin over the support, once to read the
/// count back through [`crate::AxisHistogram::count`] indexing) and
/// re-built the histogram at every site. Routes through
/// [`Self::file_format_histogram`]:
/// [`crate::AxisHistogram::trough_count`] reads a single pass over the
/// fixed-cardinality counts vector (filtering the zero-count cells out
/// of the argmin search).
///
/// The chain-altitude scalar-count peer of [`Self::recessive_file_format`]
/// (the anti-modal-cell scalar peer of [`Self::file_format_histogram`])
/// — the file-format sub-axis of the chain-shape surface now carries
/// the fused `(recessive_file_format, trough_file_format_count)`
/// anti-modal pair, matching the ([`crate::AxisHistogram::recessive_cell`],
/// [`crate::AxisHistogram::trough_count`]) pair on the shared
/// [`crate::AxisHistogram`] primitive one altitude down, the
/// ([`Self::recessive_layer_kind`], [`Self::trough_layer_kind_count`])
/// pair on the layer-kind sub-axis of the same chain altitude, the
/// ([`crate::ProvenanceMap::recessive_tier`],
/// [`crate::ProvenanceMap::trough_tier_count`]) pair on the tier
/// altitude, and the ([`crate::ConfigDiff::recessive_kind`],
/// [`crate::ConfigDiff::trough_kind_count`]) pair on the diff altitude.
/// Consumers answering *"which file format is the runt of the chain and
/// by how few layers?"* now read a single `(recessive_file_format(),
/// trough_file_format_count())` pair — one method each, both routing
/// through the same primitive — instead of re-deriving the count off
/// the anti-modal cell.
///
/// The 2×2 `(dominant, recessive) × (cell, count)` scalar grid on the
/// file-format sub-axis of the chain-shape surface closes with this
/// lift: the four seams ([`Self::dominant_file_format`],
/// [`Self::peak_file_format_count`], [`Self::recessive_file_format`],
/// [`Self::trough_file_format_count`]) now each route through the same
/// [`Self::file_format_histogram`] primitive at one pass per
/// projection, matching the closed `(dominant, peak, recessive,
/// trough)` quad on the layer-kind sub-axis of the same chain altitude,
/// the shared [`crate::AxisHistogram`] primitive one altitude down, the
/// tier altitude, and the diff altitude.
///
/// **Empty-histogram convention** — returns `0` (not `Option<usize>`)
/// matching the [`crate::AxisHistogram::trough_count`] convention one
/// altitude down, the [`Self::peak_file_format_count`] convention on
/// the same sub-axis, the [`Self::trough_layer_kind_count`] convention
/// on the layer-kind sub-axis, and the
/// [`crate::ProvenanceMap::trough_tier_count`] /
/// [`crate::ConfigDiff::trough_kind_count`] conventions on the peer
/// altitudes; the scalar `(peak_file_format_count,
/// trough_file_format_count)` pair reads uniformly `(0, 0)` on the
/// empty-histogram boundary. Unlike [`Self::trough_layer_kind_count`],
/// the zero boundary is NOT `self.as_ref().is_empty()`:
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] / unrecognized-
/// extension [`ConfigSource::File`] entries all project to [`None`]
/// through [`ConfigSource::file_format`], so the histogram is empty
/// (and this scalar reads zero) even on a non-empty chain when no
/// `File` entry carries a recognized extension. The dual-form
/// [`Self::recessive_file_format`] carries
/// `Option<crate::discovery::Format>` because the *format* is undefined
/// when no recognized-extension file layer contributes; the *count* is
/// well-defined as zero.
///
/// # Invariants
///
/// - `trough_file_format_count() == 0 ⇔
/// file_format_histogram().is_empty()` — peer to the empty-histogram
/// boundary [`Self::dominant_file_format`] /
/// [`Self::recessive_file_format`] both witness on the cell side, and
/// [`Self::peak_file_format_count`] witnesses on the modal count side.
/// Unlike [`Self::trough_layer_kind_count`], the zero boundary is NOT
/// `self.as_ref().is_empty()`: a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers reads zero as
/// well.
/// - `trough_file_format_count() == file_format_histogram().trough_count()`
/// — both project the same scalar off the same primitive; the named
/// seam is the cube-native routing of the chain-shape surface.
/// - `trough_file_format_count() == recessive_file_format().map_or(0,
/// |f| file_format_histogram().count(f))` — the count projection of
/// the `(recessive_file_format, trough_file_format_count)` anti-modal
/// pair equals [`Self::trough_file_format_count`] pointwise on every
/// chain (empty-histogram: `None.map_or(0, …) == 0 ==
/// trough_file_format_count`; non-empty-histogram: `Some(f).map_or(0,
/// |f| count(f)) == trough_file_format_count`, since
/// `count(recessive_file_format()) == trough_count()`).
/// - `trough_file_format_count() <= peak_file_format_count()` always:
/// the trough is bounded above by the peak (lifted from the
/// trait-uniform `trough_count() <= peak_count()` law on
/// [`crate::AxisHistogram`]). The empty-histogram case reads `0 <=
/// 0`; the non-empty-histogram case reads the trough-of-support
/// bounded above by the peak-of-support.
/// - `trough_file_format_count() <=
/// layer_kind_histogram().count(ConfigSourceKind::File)` always: the
/// trough on the file-format sub-axis is bounded above by the count
/// of `File` layers on the layer-kind sub-axis (every recognized-
/// extension file layer is a `File` layer, and some `File` layers
/// may have unrecognized extensions and contribute to no format
/// cell). Cross-sub-axis slack the file-format sub-axis carries
/// against the layer-kind sub-axis, absent from
/// [`Self::trough_layer_kind_count`].
/// - `trough_file_format_count() == peak_file_format_count()` iff
/// `present_file_formats().len() <= 1` (assuming distinct counts on
/// multi-support histograms) — the one-directional pin only. Zero:
/// empty histogram, both zero. One: singleton-support histogram,
/// every recognized file layer on the same format, both equal
/// `file_format_histogram().total()`. Two or more with distinct
/// counts: trough strictly below peak.
/// - `trough_file_format_count() >= 1` whenever
/// `!file_format_histogram().is_empty()` — the argmin is taken over
/// the histogram's *support* (nonzero cells), so the trough of a
/// non-empty histogram is always at least one.
/// - `trough_file_format_count()` on a uniform full-cover chain (one
/// file layer per format) equals `1` — every observed format
/// collects one file layer; the trough coincides with the peak on
/// the uniform-cover degenerate (the singleton-modality analogue on
/// the count side).
/// - `trough_file_format_count()` on a singleton-support chain (every
/// recognized-extension file layer on the same format) equals
/// `file_format_histogram().total()` — the sole observed format is
/// both the modal and anti-modal cell, so `trough == peak == total`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build) and
/// `k = crate::axis_cardinality::<crate::discovery::Format>()` (the
/// argmin scan over the support). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the returned
/// `usize` reads one scalar. Halves the cost of the previous
/// `recessive_file_format().map_or(0, |f|
/// file_format_histogram().count(f))` idiom (which walked the histogram
/// twice — once to argmin, once to read the count back).
#[must_use]
fn trough_file_format_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().trough_count()
}
/// The **file-format spread** — the difference between the peak and
/// trough recognized-extension file-layer counts across the observed
/// [`crate::discovery::Format`]s on this chain. Equal to
/// `self.peak_file_format_count() - self.trough_file_format_count()`
/// by construction. Routes through
/// [`Self::file_format_histogram`]: [`crate::AxisHistogram::spread`]
/// reads a single pass over the fixed-cardinality counts vector
/// (fusing the max-over-axis / min-over-support pair into one
/// running scan). The file-format sub-axis lift of the "spread across
/// altitudes" projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kind_spread`], climbed to the tier altitude
/// by [`crate::ProvenanceMap::tier_spread`], and lifted sideways to
/// the layer-kind sub-axis by [`Self::layer_kind_spread`]. Returns
/// `0` exactly on every chain whose file-format histogram is empty
/// (an empty chain, OR a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] / unrecognized-
/// extension [`ConfigSource::File`] entries), every singleton-support
/// chain (only one observed format, trivially balanced), and every
/// uniform per-format chain (each observed format contributing the
/// same nonzero file-layer count, dominant included).
///
/// The **scalar dispersion peer** of the fused
/// `(peak_file_format_count, trough_file_format_count)` modal-count
/// pair on the file-format sub-axis of the chain altitude — the
/// natural typed primitive for chain-shape dashboards, attestation
/// manifests, and alerting policies asking *"how unevenly distributed
/// are the file layers across the observed formats?"*: the CLI
/// `config-show` summary line *"format skew 2: Toml owns 3 of 4 file
/// layers, Yaml 1 of 4"* (where 2 is this scalar), the attestation
/// manifest recording the file-format spread between two
/// `ProviderChain` snapshots, the alerting policy reading *"chain
/// format spread = 2"* to flag a rebuild window where one file
/// format dwarfed the others. Before this lift, every such consumer
/// re-derived the projection inline as
/// `chain.peak_file_format_count() -
/// chain.trough_file_format_count()` — two method calls plus a
/// subtraction at every site, each site having to reason
/// independently about the structural non-negativity of the
/// difference (`peak_file_format_count() >=
/// trough_file_format_count()` holds on every chain by lifting the
/// trait-uniform `peak_count() >= trough_count()` law on
/// [`crate::AxisHistogram`], but not on the inline subtraction
/// surface — an unwitnessed refactor swapping the operands would
/// silently underflow). Routes through
/// [`crate::AxisHistogram::spread`] one altitude down — the
/// underflow-safe named seam whose docs pin the monotonicity
/// invariant explicitly.
///
/// The file-format sub-axis lift in the "spread across altitudes"
/// projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kind_spread`], climbed to the tier altitude
/// by [`crate::ProvenanceMap::tier_spread`], and lifted sideways to
/// the layer-kind sub-axis of the same chain altitude by
/// [`Self::layer_kind_spread`]. The pattern is the same at every
/// altitude: fuse the (`peak_count`, `trough_count`) modal-count
/// pair into a single dispersion scalar named at the surface,
/// routed through the shared [`crate::AxisHistogram::spread`]
/// primitive one altitude down. The env-prefix-presence sub-axis
/// peer [`Self::env_prefix_kind_spread`] over
/// [`Self::env_prefix_kind_histogram`] closes the projection
/// sideways on the same doc-cited template — the chain-altitude
/// "spread across altitudes" triple
/// `(layer_kind_spread, file_format_spread, env_prefix_kind_spread)`
/// now spans every sub-axis of the chain surface.
///
/// **Empty-histogram convention** — returns `0`, matching the
/// [`crate::AxisHistogram::spread`] empty convention one altitude
/// down and the [`Self::peak_file_format_count`] /
/// [`Self::trough_file_format_count`] empty conventions on the same
/// sub-axis. The scalar-count triple
/// `(peak_file_format_count, trough_file_format_count,
/// file_format_spread)` reads uniformly `(0, 0, 0)` on the empty
/// histogram. Unlike [`Self::layer_kind_spread`], the zero-boundary
/// is NOT `self.as_ref().is_empty()`: a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers reads
/// `(0, 0, 0)` as well, because those entries project to [`None`]
/// through [`ConfigSource::file_format`]. Cross-sub-axis divergence
/// from [`Self::layer_kind_spread`] — the file-format sub-axis's
/// empty-boundary is the sub-axis histogram's `is_empty()`, not the
/// chain's.
///
/// **Structural-skew predicate.** `file_format_spread() == 0` is the
/// typed *balanced-file-formats* predicate at the file-format
/// sub-axis of the chain altitude — every observed
/// [`crate::discovery::Format`] contributed the same number of file
/// layers. Pointwise equivalent to `peak_file_format_count() ==
/// trough_file_format_count()` on the scalar-count pair and to
/// `dominant_file_format() == recessive_file_format()` on the
/// modal-cell pair whenever the file-format histogram is non-empty
/// (both branches reduce to `Some(first) == Some(first)` on
/// singleton-support and uniform-cover chains, and to `false` on
/// skewed chains). Together with `file_format_histogram().is_empty()`
/// and the full-cover predicate on [`Self::file_format_histogram`],
/// the file-format sub-axis of the chain-shape surface now carries
/// the natural boundary triple *"did any file layer contribute?"* /
/// *"did every format fire?"* / *"did the formats fire equally?"* —
/// each a single method call.
///
/// # Invariants
///
/// - `file_format_spread() == file_format_histogram().spread()` —
/// both project the same scalar off the same primitive; the named
/// seam is the cube-native routing of the histogram surface.
/// - `file_format_spread() == peak_file_format_count() -
/// trough_file_format_count()` — the fused-pair identity of the
/// scalar-dispersion peer. The subtraction is underflow-safe
/// because `peak_file_format_count() >= trough_file_format_count()`
/// holds structurally on every chain (lifted from the trait-
/// uniform `peak_count() >= trough_count()` law on
/// [`crate::AxisHistogram`]).
/// - `file_format_spread() == 0` on every chain whose file-format
/// histogram is empty — the vacuous uniformity boundary, matching
/// the [`crate::AxisHistogram::spread`] empty convention one
/// altitude down. The `(peak_file_format_count,
/// trough_file_format_count, file_format_spread)` triple reads
/// `(0, 0, 0)` uniformly. Unlike [`Self::layer_kind_spread`], the
/// zero boundary is NOT `self.as_ref().is_empty()`: a non-empty
/// chain of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::Env`] / unrecognized-extension
/// [`ConfigSource::File`] layers reads zero as well.
/// - `file_format_spread() == 0` whenever
/// `present_file_formats().len() <= 1` — the empty-histogram case
/// (no observed format, trivially balanced) and the
/// singleton-support case (the one observed format's count is both
/// the peak and the trough). Also holds on every uniform per-
/// format chain (each observed format contributing the same
/// nonzero count, dominant included).
/// - `file_format_spread() <= peak_file_format_count()` always —
/// the trough is non-negative, so the subtraction is bounded
/// above by the minuend. Equality holds iff the trough is zero —
/// i.e. iff `file_format_histogram().is_empty()`. Lifted from the
/// trait-uniform `spread() <= peak_count()` law on
/// [`crate::AxisHistogram`]. Cross-sub-axis divergence from
/// [`Self::layer_kind_spread`], where the equality-case coincides
/// with `self.as_ref().is_empty()` (the layer-kind sub-axis
/// zero-trough boundary).
/// - `file_format_spread() <= file_format_histogram().total()`
/// always — composition of `file_format_spread() <=
/// peak_file_format_count()` (this method) with
/// `peak_file_format_count() <= file_format_histogram().total()`
/// (documented on [`Self::peak_file_format_count`]). The histogram
/// total equals the count of `File` entries with recognized
/// extensions, at most
/// `layer_kind_histogram().count(ConfigSourceKind::File)`.
/// - `file_format_spread() <= self.as_ref().len()` always —
/// composition of the above with `file_format_histogram().total()
/// <= self.as_ref().len()` (every recognized-extension file layer
/// is a chain entry). The chain-length bound the layer-kind
/// sub-axis carries at cell-count tightness; the file-format
/// sub-axis carries it with the histogram-total slack.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the fused peak-and-trough scan). Both are `O(n)` in practice
/// since the file-format axis carries a fixed four-cell cardinality;
/// the returned `usize` reads one scalar. Halves the cost of the
/// previous inline `chain.peak_file_format_count() -
/// chain.trough_file_format_count()` idiom (which walked the counts
/// vector twice — once for the max, once for the min-over-support —
/// where [`crate::AxisHistogram::spread`] can fuse both into a
/// single walk with a running-max/min pair).
#[must_use]
fn file_format_spread(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().spread()
}
/// The **balanced-file-formats boolean predicate** on the file-format
/// sub-axis of the chain altitude — `true` exactly when every observed
/// [`crate::discovery::Format`] contributed the same number of
/// recognized-extension file layers. The typed boolean peer of
/// `file_format_spread() == 0` on the scalar-dispersion surface,
/// lifting the same structural-skew boundary from the scalar surface
/// to a named predicate at the file-format sub-axis of the chain
/// altitude. Routes through
/// [`crate::AxisHistogram::is_uniform_count`] one altitude down: the
/// single-pass scan over the fixed-cardinality counts vector that
/// short-circuits on the first pair of distinct nonzero cells, tighter
/// than the two-scan [`Self::peak_file_format_count`] /
/// [`Self::trough_file_format_count`] fusion the scalar-spread form
/// pays for.
///
/// The **balanced-file-formats peer** of the fused
/// `(peak_file_format_count, trough_file_format_count,
/// file_format_spread)` dispersion triple on the file-format sub-axis
/// of the chain altitude — the natural typed boolean primitive for
/// per-format dashboards, attestation manifests, and alerting policies
/// asking *"did every observed file format fire equally?"*: the CLI
/// `config-show` headline *"balanced recipe: every observed file
/// format owns the same number of layers"*, the attestation manifest
/// gate *"rebuild window balanced across file formats"*, the alerting
/// policy predicate *"chain balanced by format"*. Before this lift,
/// every such consumer re-derived the predicate inline as
/// `chain.file_format_spread() == 0` (the scalar-spread form, which
/// routes through a subtraction whose underflow safety relies on the
/// structural `peak >= trough` invariant on
/// [`Self::file_format_spread`]), or as
/// `chain.peak_file_format_count() ==
/// chain.trough_file_format_count()` (the scalar-pair form, which
/// pays for two count walks and equates two `usize`s without saying
/// structurally *what* is being equated), or as
/// `chain.dominant_file_format() == chain.recessive_file_format()`
/// (the modal-pair form, which peers through
/// `Option<crate::discovery::Format>` equality across two
/// argmax/argmin walks). The three forms drifted in subtle ways at
/// every consumer site. This lift names the balanced-file-formats
/// predicate directly at the file-format sub-axis with a single-pass
/// short-circuiting scan — the typed boolean every operator-facing
/// "is this recipe balanced by format?" check reads off as a single
/// method call.
///
/// The file-format sub-axis lift in the "balanced across altitudes"
/// projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_balanced`], climbed to the tier altitude
/// by [`crate::ProvenanceMap::tiers_balanced`], and lifted sideways to
/// the first chain sub-axis by [`Self::layer_kinds_balanced`]. The
/// pattern is the same at every altitude / sub-axis: fuse the
/// (`peak_count`, `trough_count`, `spread`) scalar triple's balanced-
/// boundary into a single boolean predicate named at the surface,
/// routed through the shared
/// [`crate::AxisHistogram::is_uniform_count`] primitive one altitude
/// down. Parallels the "spread across altitudes" projection lifted to
/// the same sub-axis by [`Self::file_format_spread`]. The last
/// remaining chain-altitude sub-axis is lifted sideways to the same
/// projection by [`Self::env_prefix_kinds_balanced`] over
/// [`Self::env_prefix_kind_histogram`], closing the "balanced across
/// altitudes" projection across every altitude / sub-axis.
///
/// **Empty-histogram convention** — returns `true` vacuously on every
/// chain whose file-format histogram is empty: no observed cells, so
/// the universal "every observed cell carries the same count" reads
/// `true` over the empty support. Matches
/// [`crate::AxisHistogram::is_uniform_count`]'s empty convention one
/// altitude down and `file_format_spread() == 0` on the empty case
/// (peak == trough == 0). Unlike [`Self::layer_kinds_balanced`], the
/// `true` boundary is NOT `self.as_ref().is_empty()`: a non-empty
/// chain of only [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers is trivially
/// balanced under this predicate as well (empty histogram). Cross-
/// sub-axis divergence from the layer-kind sub-axis, where the
/// vacuous-uniformity boundary coincides with the empty chain.
///
/// **Singleton-support convention** — returns `true` on every chain
/// whose observed support is a single [`crate::discovery::Format`]
/// (trivially balanced: the one observed format's count is both the
/// peak and the trough). Includes every chain in which one format
/// owns every recognized-extension file layer.
///
/// **Uniform per-format convention** — returns `true` on every uniform
/// per-format chain (each observed format contributing the same
/// nonzero count), including the k-format-observed-once-each shape
/// and the uniform full-cover shape over all four
/// [`crate::discovery::Format`] cells.
///
/// # Invariants
///
/// - `file_formats_balanced() == file_format_histogram().is_uniform_count()` —
/// both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram surface.
/// - `file_formats_balanced() == (file_format_spread() == 0)` always —
/// the defining equivalence on the scalar-spread surface at the
/// file-format sub-axis.
/// - `file_formats_balanced() == (peak_file_format_count() ==
/// trough_file_format_count())` always — the structural form on
/// the underlying scalar pair.
/// - `file_formats_balanced() == (dominant_file_format() ==
/// recessive_file_format())` always — the modal-pair form; both
/// branches agree on the empty-histogram chain (`None == None`), on
/// every singleton-support chain (`Some(f) == Some(f)`), on every
/// uniform per-format chain (`Some(first_format) ==
/// Some(first_format)` after declaration-order tie-break), and on
/// every skewed chain (both sides read `false`).
/// - `file_format_histogram().is_empty() ⇒ file_formats_balanced()` —
/// vacuous uniformity on every chain whose file-format histogram
/// is empty (empty chain, or non-empty chain of only Defaults /
/// Env / unrecognized-extension File layers). Contrapositively,
/// `!file_formats_balanced() ⇒ !file_format_histogram().is_empty()`
/// (a skewed chain has at least two distinct positive counts, so
/// the histogram is non-empty). Cross-sub-axis divergence from
/// [`Self::layer_kinds_balanced`], where the vacuous-uniformity
/// implication reads on `self.as_ref().is_empty()` instead of the
/// histogram-empty predicate.
/// - `present_file_formats().len() <= 1 ⇒ file_formats_balanced()` —
/// every chain with file-format support size 0 or 1 is trivially
/// balanced. Contrapositively, `!file_formats_balanced() ⇒
/// present_file_formats().len() >= 2` (a skewed chain observes at
/// least two distinct formats with differing counts).
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the uniform-count scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits on
/// the first pair of distinct nonzero cells (bounded at two nonzero
/// cells visited), strictly tighter than the two-full-scan
/// `peak_file_format_count()` / `trough_file_format_count()` fusion
/// the scalar-spread form pays for on skewed chains.
#[must_use]
fn file_formats_balanced(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().is_uniform_count()
}
/// Named typed boolean predicate — `true` exactly when every
/// [`crate::discovery::Format`] cell was observed at least once
/// on this chain's [`ConfigSource::File`] layers with recognized
/// extensions (every observed cell of the closed
/// [`crate::discovery::Format`] axis has a nonzero count on the
/// recipe's file-format histogram). Routes through
/// [`Self::file_format_histogram`]'s
/// [`crate::AxisHistogram::is_full_cover`], the cube-native single-
/// pass short-circuiting scan over the fixed-cardinality counts
/// vector one altitude down.
///
/// Operator-facing consumers answering *"did every file format fire
/// on this recipe?"* — the CLI `config-show` headline *"full-cover
/// recipe: every file format fired at least once"*, the attestation
/// manifest gate *"rebuild window full-cover across file formats"*,
/// the alerting policy predicate *"recipe full-cover by format"* —
/// now route through this named seam instead of four previously
/// drifting inline forms: `chain.absent_file_formats().is_empty()`
/// (the coverage-gap-`Vec` form, which allocates a
/// `Vec<crate::discovery::Format>` and reads its emptiness),
/// `chain.absent_file_formats_count() == 0` (the coverage-gap-
/// scalar form, which pays for a full-axis scan and equates a
/// `usize` to zero without saying structurally *what* is being
/// equated), `chain.present_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>()` (the
/// support-scalar form, which pays for the support scan and pulls
/// in the `axis_cardinality` turbofish at every call site), and
/// `chain.present_file_formats().len() ==
/// crate::axis_cardinality::<crate::discovery::Format>()` (the
/// support-`Vec` form, which allocates a
/// `Vec<crate::discovery::Format>` and reads its length back).
/// Pointwise-equivalent with
/// `file_format_histogram().unobserved_cells() == 0`,
/// `file_format_histogram().distinct_cells() ==
/// crate::axis_cardinality::<crate::discovery::Format>()`, and
/// `file_format_histogram().unobserved().next().is_none()` one
/// altitude down.
///
/// **Lifts sideways to the file-format sub-axis of the chain
/// altitude** in the "full-cover across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_full_cover`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_full_cover`], and
/// lifted sideways to the layer-kind sub-axis by
/// [`Self::layer_kinds_full_cover`]. Parallels the "balanced
/// across altitudes" projection lifted to the same sub-axis by
/// [`Self::file_formats_balanced`] and the "spread across altitudes"
/// projection lifted to the same sub-axis by
/// [`Self::file_format_spread`]. The last remaining chain-altitude
/// sub-axis is the natural next sideways lift:
/// [`Self::env_prefix_kinds_full_cover`] over
/// [`Self::env_prefix_kind_histogram`], closing the "full-cover
/// across altitudes" projection across every altitude / sub-axis
/// alongside the balanced / spread projections that already closed
/// the same grid.
///
/// **Empty-histogram convention** — returns `false` on every chain
/// whose file-format histogram is empty (no recognized-extension
/// file layers): no observed cells means the coverage gap equals
/// every cell of [`crate::discovery::Format::ALL`] — the full-cover
/// predicate fails. Matches [`crate::AxisHistogram::is_full_cover`]'s
/// empty-histogram convention one altitude down on the non-zero-
/// cardinality [`crate::discovery::Format`] axis (four cells:
/// `Yaml`, `Toml`, `Lisp`, `Nix`). Cross-sub-axis divergence from
/// [`Self::layer_kinds_full_cover`]: the empty-chain boundary is
/// weaker on the file-format sub-axis — a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers ALSO reads
/// `false` (the histogram is empty even though the chain is not).
/// Dual of the vacuous-uniformity witness on
/// [`Self::file_formats_balanced`], which reads `true` on every
/// empty-histogram chain: full-cover and balanced fall on opposite
/// sides of the empty-histogram boundary at the file-format sub-
/// axis, matching the diff-altitude / tier-altitude / layer-kind
/// sub-axis empty-vs-empty orthogonality.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single
/// [`crate::discovery::Format`]: one observed cell out of four
/// leaves at least three cells in the coverage gap, so the full-
/// cover predicate fails. Every chain in which one format owns
/// every recognized-extension file layer is a witness.
///
/// **Uniform four-format cover convention** — returns `true` on
/// every chain where each of the four [`crate::discovery::Format`]
/// cells was observed at least once (regardless of per-format
/// count). Includes the k-format-observed-once-each shape (one
/// recognized-extension file layer per format) and every skewed
/// four-format cover.
///
/// # Invariants
///
/// - `file_formats_full_cover() ==
/// file_format_histogram().is_full_cover()` — both project the
/// same predicate off the same primitive; the named seam is the
/// cube-native routing of the histogram surface.
/// - `file_formats_full_cover() == absent_file_formats().is_empty()`
/// always — the defining equivalence on the coverage-gap-`Vec`
/// surface at the file-format sub-axis.
/// - `file_formats_full_cover() == (absent_file_formats_count() ==
/// 0)` always — the defining equivalence on the coverage-gap-
/// scalar surface, without allocating the
/// `Vec<crate::discovery::Format>`.
/// - `file_formats_full_cover() == (present_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>())` always
/// — the support-scalar form, the dual-side surfacing of the same
/// boolean across the (observed, unobserved) partition.
/// - `file_formats_full_cover() == (present_file_formats().len() ==
/// crate::axis_cardinality::<crate::discovery::Format>())` always
/// — the support-`Vec` form, without allocating twice through
/// [`Vec::len`].
/// - `file_formats_full_cover() ⇒
/// !file_format_histogram().is_empty()` — a full-cover chain
/// observes at least one recognized-extension file layer per
/// [`crate::discovery::Format`], so the histogram is non-empty.
/// Contrapositively, `file_format_histogram().is_empty() ⇒
/// !file_formats_full_cover()` (the empty-histogram / full-
/// coverage-gap boundary). Unlike
/// [`Self::layer_kinds_full_cover`], the contrapositive reads on
/// the *histogram-empty* condition rather than the chain-empty
/// condition — cross-sub-axis divergence.
/// - `file_formats_full_cover() ⇒ present_file_formats().len() ==
/// crate::axis_cardinality::<crate::discovery::Format>()` — a
/// full-cover chain observes every format, so the support size
/// equals the axis cardinality. Contrapositively,
/// `present_file_formats().len() <
/// crate::axis_cardinality::<crate::discovery::Format>() ⇒
/// !file_formats_full_cover()`.
/// - `file_formats_full_cover() ⇒
/// file_format_histogram().total() >=
/// crate::axis_cardinality::<crate::discovery::Format>()` — a
/// full-cover chain observes at least one recognized-extension
/// file layer per format, so the histogram total is bounded
/// below by the axis cardinality.
/// - `file_formats_full_cover() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::File) >=
/// crate::axis_cardinality::<crate::discovery::Format>()` — a
/// full-cover chain observes at least one recognized-extension
/// file layer per format; every such layer is a
/// [`ConfigSource::File`], so the layer-kind File count is
/// bounded below by the file-format axis cardinality. Cross-
/// sub-axis lower-bound implication linking the file-format sub-
/// axis full-cover boundary to the layer-kind sub-axis File cell
/// count.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the full-cover scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits on
/// the first zero cell (bounded at one zero cell visited on a
/// non-full-cover chain), strictly tighter than the four coverage-
/// gap equality forms — no `Vec<crate::discovery::Format>`
/// allocation, no [`crate::axis_cardinality`] turbofish, no scalar
/// equality against a magic axis-cardinality constant.
#[must_use]
fn file_formats_full_cover(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().is_full_cover()
}
/// Named typed boolean predicate — `true` exactly when at least one
/// [`crate::discovery::Format`] cell was observed on this chain's
/// [`ConfigSource::File`] layers with recognized extensions (at
/// least one cell of the closed [`crate::discovery::Format`] axis
/// has a nonzero count on the recipe's file-format histogram).
/// Routes through [`Self::file_format_histogram`]'s
/// [`crate::AxisHistogram::is_empty`], negated: the cube-native
/// single-pass short-circuiting scan over the fixed-cardinality
/// counts vector one altitude down that returns on the first
/// nonzero cell.
///
/// Operator-facing consumers answering *"did any file format fire
/// on this recipe at all?"* — the CLI `config-show` headline *"non-
/// empty file-format recipe: at least one recognized-extension file
/// layer fired"*, the attestation manifest gate *"rebuild window
/// carries at least one recognized file-format observation"*, the
/// alerting policy predicate *"recipe has any file-format layer"* —
/// now route through this named seam instead of four previously
/// drifting inline forms: `!chain.file_format_histogram().is_empty()`
/// (the histogram-nonempty form, which reads through the histogram
/// primitive but without a chain-level named seam),
/// `chain.present_file_formats_count() > 0` (the support-scalar
/// form, which pays for a full-axis scan and compares a `usize` to
/// zero without naming the coverage-support boundary),
/// `!chain.present_file_formats().is_empty()` (the support-`Vec`
/// form, which allocates a `Vec<crate::discovery::Format>` and
/// reads its emptiness back), and `chain.absent_file_formats_count()
/// < crate::axis_cardinality::<crate::discovery::Format>()` (the
/// coverage-gap-scalar form, which pays for the coverage-gap scan
/// and pulls in the `axis_cardinality` turbofish at every call
/// site). Routes through `!AxisHistogram::is_empty` one altitude
/// down.
///
/// **Lifts sideways to the file-format sub-axis of the chain
/// altitude** in the "any-observed across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_any_observed`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_any_observed`], and
/// lifted sideways to the layer-kind sub-axis by
/// [`Self::layer_kinds_any_observed`]. Parallels the "balanced
/// across altitudes" projection lifted to the same sub-axis by
/// [`Self::file_formats_balanced`] and the "full-cover across
/// altitudes" projection lifted to the same sub-axis by
/// [`Self::file_formats_full_cover`]. The last remaining chain-
/// altitude sub-axis is the natural next sideways lift:
/// [`Self::env_prefix_kinds_any_observed`] over
/// [`Self::env_prefix_kind_histogram`], closing the "any-observed
/// across altitudes" projection across every altitude / sub-axis
/// alongside the balanced / full-cover projections that already
/// closed the same grid.
///
/// **Empty-histogram convention** — returns `false` on every chain
/// whose file-format histogram is empty: no observed cells means
/// the any-observed predicate fails. Matches
/// [`crate::AxisHistogram::is_empty`]'s `true` reading on the empty
/// histogram one altitude down, projected through the negation
/// seam. Cross-sub-axis divergence from
/// [`Self::layer_kinds_any_observed`]: the empty-chain boundary is
/// weaker on the file-format sub-axis — a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers ALSO reads
/// `false` (the histogram is empty even though the chain is not).
/// Matches [`Self::file_formats_full_cover`]'s same-sided
/// convention at the empty-histogram boundary and dual of
/// [`Self::file_formats_balanced`]'s vacuous-uniformity witness
/// (which reads `true` on every empty-histogram chain): any-
/// observed and balanced fall on opposite sides of the empty-
/// histogram boundary, matching the layer-kind sub-axis
/// (`any_observed`, `balanced`, `full_cover`) empty-chain polarity
/// triple.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single [`crate::discovery::Format`]
/// (one observed cell suffices for the any-observed predicate).
/// Every chain in which one format owns every recognized-extension
/// file layer is a witness. Matches [`Self::file_formats_balanced`]'s
/// `true` side on the singleton and orthogonal to
/// [`Self::file_formats_full_cover`]'s `false` side on the same
/// singleton — the three boundaries partition the singleton-
/// support fixture into the polarity triple
/// (`any_observed`=true, `balanced`=true, `full_cover`=false).
///
/// **Uniform four-format cover convention** — returns `true` on
/// every chain where each of the four [`crate::discovery::Format`]
/// cells was observed at least once. The uniform four-format cover
/// is on the `true` side of all three coverage-support boundaries
/// (`any_observed`, `balanced`, `full_cover`).
///
/// # Invariants
///
/// - `file_formats_any_observed() == !file_format_histogram().is_empty()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `file_formats_any_observed() == (present_file_formats_count() >
/// 0)` always — the support-scalar surface, without allocating
/// the `Vec<crate::discovery::Format>`.
/// - `file_formats_any_observed() == !present_file_formats().is_empty()`
/// always — the support-`Vec` surface.
/// - `file_formats_any_observed() == (absent_file_formats_count() <
/// crate::axis_cardinality::<crate::discovery::Format>())`
/// always — the coverage-gap-scalar surface, the dual-side
/// surfacing of the same boolean across the (observed,
/// unobserved) partition.
/// - `file_formats_full_cover() ⇒ file_formats_any_observed()` — a
/// full-cover chain observes every cell, so it observes at least
/// one cell. Contrapositively, `!file_formats_any_observed() ⇒
/// !file_formats_full_cover()`.
/// - `file_formats_any_observed() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::File) >= 1` —
/// a chain observing any file format has at least one
/// recognized-extension file layer, and every such layer is a
/// [`ConfigSource::File`]. Cross-sub-axis lower-bound implication
/// linking the file-format sub-axis any-observed boundary to the
/// layer-kind sub-axis File cell count. Cross-sub-axis
/// divergence from [`Self::layer_kinds_any_observed`]'s
/// `self.as_ref().len() >= 1` implication, which reads on the
/// chain-length rather than the File-layer count.
/// - `!file_formats_any_observed() ⇒ file_formats_balanced()` — the
/// empty-histogram chain is the only chain on the `false` side of
/// `file_formats_any_observed` and it is vacuously balanced.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the any-observed scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits on
/// the first nonzero cell (bounded at one nonzero cell visited on
/// any non-empty-histogram chain), strictly tighter than the four
/// support / coverage-gap equality forms — no
/// `Vec<crate::discovery::Format>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no scalar equality
/// against a magic axis-cardinality constant.
#[must_use]
fn file_formats_any_observed(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
!self.file_format_histogram().is_empty()
}
/// Named typed boolean predicate — `true` exactly when this chain's
/// [`ConfigSource::File`] layers with recognized extensions observe
/// exactly one [`crate::discovery::Format`] cell (exactly one cell
/// of the closed [`crate::discovery::Format`] axis has a nonzero
/// count on the recipe's file-format histogram — the singleton-
/// support boundary of the coverage-support partition). Routes
/// through [`Self::file_format_histogram`]'s
/// [`crate::AxisHistogram::has_singular_support`]: the cube-native
/// single-pass short-circuiting scan over the fixed-cardinality
/// counts vector one altitude down that finds the first nonzero
/// cell and confirms no second nonzero cell follows.
///
/// Operator-facing consumers answering *"did the recipe land on
/// exactly one file format?"* — the CLI `config-show` headline
/// *"singleton-format recipe: exactly one file format fired"*, the
/// attestation manifest gate *"rebuild window observes exactly
/// one file format"*, the alerting policy predicate *"recipe
/// collapsed to a single file format"* — now route through this
/// named seam instead of four previously drifting inline forms:
/// `chain.present_file_formats_count() == 1` (the support-scalar
/// form, which pays for a full-axis scan and compares a `usize`
/// to one without naming the coverage-support boundary),
/// `chain.present_file_formats().len() == 1` (the support-`Vec`
/// form, which allocates a `Vec<crate::discovery::Format>` and
/// reads its length back), `chain.absent_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>() - 1`
/// (the coverage-gap-scalar form, which pays for the coverage-
/// gap scan and pulls in the `axis_cardinality` turbofish at
/// every call site), and `chain.absent_file_formats().len() ==
/// crate::axis_cardinality::<crate::discovery::Format>() - 1`
/// (the coverage-gap-`Vec` form, which allocates the coverage-
/// gap vector and reads its length back).
///
/// **Lifts sideways to the file-format sub-axis of the chain
/// altitude** the "singleton-support across altitudes"
/// projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_singular_support`], climbed to the
/// tier altitude by
/// [`crate::ProvenanceMap::tiers_singular_support`], and lifted
/// sideways to the layer-kind sub-axis by
/// [`Self::layer_kinds_singular_support`]. Parallels the
/// "balanced across altitudes" projection at this sub-axis by
/// [`Self::file_formats_balanced`], the "full-cover across
/// altitudes" projection at this sub-axis by
/// [`Self::file_formats_full_cover`], and the "any-observed
/// across altitudes" projection at this sub-axis by
/// [`Self::file_formats_any_observed`]. The file-format-sub-axis
/// quadruple (`file_formats_balanced`, `file_formats_full_cover`,
/// `file_formats_any_observed`, `file_formats_singular_support`)
/// now spans all four coverage-support boundaries at this sub-
/// axis, mirroring the layer-kind-sub-axis quadruple
/// (`layer_kinds_balanced`, `layer_kinds_full_cover`,
/// `layer_kinds_any_observed`, `layer_kinds_singular_support`)
/// and the tier-altitude / diff-altitude peer quadruples on the
/// same grid. The last remaining chain-altitude sub-axis is the
/// natural next sideways lift: `env_prefix_kinds_singular_support`
/// over [`Self::env_prefix_kind_histogram`], closing the
/// "singleton-support across altitudes" projection across every
/// altitude / sub-axis alongside the balanced / full-cover / any-
/// observed projections that already closed the same grid.
///
/// **Empty-histogram convention** — returns `false` on every
/// chain whose file-format histogram is empty: no observed cells
/// means the singleton-support predicate fails (support
/// cardinality is 0, not 1). Matches
/// [`crate::AxisHistogram::has_singular_support`]'s empty-
/// histogram `false` convention one altitude down. Cross-sub-
/// axis divergence from [`Self::layer_kinds_singular_support`]:
/// the `false` side of the boundary is wider on the file-format
/// sub-axis — a non-empty chain of only [`ConfigSource::Defaults`]
/// / [`ConfigSource::Env`] / unrecognized-extension
/// [`ConfigSource::File`] layers ALSO reads `false` (the
/// histogram is empty even though the chain is not). Matches
/// [`Self::file_formats_any_observed`]'s and
/// [`Self::file_formats_full_cover`]'s same-sided convention at
/// the empty-histogram boundary and dual of
/// [`Self::file_formats_balanced`]'s vacuous-uniformity witness
/// (which reads `true` on every empty-histogram chain): the four
/// boundaries partition the empty-histogram chain into the
/// polarity quadruple (`any_observed`=false,
/// `singular_support`=false, `balanced`=true, `full_cover`=false).
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single
/// [`crate::discovery::Format`]: one observed cell is exactly
/// the singleton-support boundary. Every chain in which one
/// format owns every recognized-extension file layer is a witness
/// (`sample_chain` — two `.yaml` file layers plus one env layer —
/// is one such witness on the file-format sub-axis, though not on
/// the layer-kind sub-axis where support is 2). Matches
/// [`Self::file_formats_any_observed`]'s and
/// [`Self::file_formats_balanced`]'s `true` side on the singleton
/// and orthogonal to [`Self::file_formats_full_cover`]'s `false`
/// side on the same singleton — the four boundaries partition
/// the singleton-support fixture into the polarity quadruple
/// (`any_observed`=true, `singular_support`=true, `balanced`=true,
/// `full_cover`=false).
///
/// **Uniform four-format cover convention** — returns `false` on
/// every chain where each of the four
/// [`crate::discovery::Format`] cells was observed at least once:
/// the support is the full four-cell axis (not one), so the
/// singleton-support predicate fails. The uniform four-format
/// cover is on the `false` side of the singular-support boundary
/// and on the `true` side of the other three coverage-support
/// boundaries — the four boundaries partition the uniform-cover
/// fixture with (`any_observed`=true, `singular_support`=false,
/// `balanced`=true, `full_cover`=true).
///
/// # Invariants
///
/// - `file_formats_singular_support() ==
/// file_format_histogram().has_singular_support()` — both
/// project the same predicate off the same primitive; the named
/// seam is the cube-native routing of the histogram surface.
/// - `file_formats_singular_support() ==
/// (present_file_formats_count() == 1)` always — the support-
/// scalar surface, without allocating the
/// `Vec<crate::discovery::Format>`.
/// - `file_formats_singular_support() ==
/// (present_file_formats().len() == 1)` always — the support-
/// `Vec` surface.
/// - `file_formats_singular_support() == (absent_file_formats_count()
/// == crate::axis_cardinality::<crate::discovery::Format>() - 1)`
/// always — the coverage-gap-scalar surface, the dual-side
/// surfacing of the same boolean across the (observed,
/// unobserved) partition.
/// - `file_formats_singular_support() ⇒
/// file_formats_any_observed()` — a chain with exactly one
/// observed cell has at least one observed cell.
/// Contrapositively, `!file_formats_any_observed() ⇒
/// !file_formats_singular_support()`.
/// - `file_formats_singular_support() ⇒
/// file_formats_balanced()` — a chain with exactly one observed
/// count has a trivially uniform support (one count is vacuously
/// equal to itself), so the balanced predicate holds.
/// - `file_formats_singular_support() ⇒
/// !file_formats_full_cover()` on every axis with cardinality
/// `>= 2` (every implementor today —
/// [`crate::discovery::Format`] carries four cells): a singleton
/// support has size 1, a full cover has size
/// `axis_cardinality::<A>()` `>= 2`, so the two boundaries are
/// disjoint.
/// - `file_formats_singular_support() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::File) >= 1` —
/// a chain with a singleton file-format support has at least
/// one recognized-extension file layer, and every such layer is
/// a [`ConfigSource::File`]. Cross-sub-axis lower-bound
/// implication linking the file-format sub-axis singleton-
/// support boundary to the layer-kind sub-axis File cell count.
/// Cross-sub-axis divergence from
/// [`Self::layer_kinds_singular_support`]'s
/// `self.as_ref().len() >= 1` implication, which reads on the
/// chain-length rather than the File-layer count — matching the
/// same divergence pattern between
/// [`Self::file_formats_any_observed`] and
/// [`Self::layer_kinds_any_observed`] on the strictly-looser
/// cardinality slice.
/// - `file_formats_singular_support() ⇒ dominant_file_format() ==
/// recessive_file_format() && dominant_file_format().is_some()`
/// — when support is singular, the modal pair collapses to the
/// one observed cell on both sides.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k =
/// crate::axis_cardinality::<crate::discovery::Format>()` (the
/// singular-support scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits
/// on the second nonzero cell (bounded at two nonzero cells
/// visited on any two-or-more-cell-support chain), strictly
/// tighter than the four support / coverage-gap equality forms —
/// no `Vec<crate::discovery::Format>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no scalar equality
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn file_formats_singular_support(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().has_singular_support()
}
/// Returns `true` exactly when this chain's
/// [`ConfigSource::File`] layers with recognized extensions observe
/// every [`crate::discovery::Format`] cell except one — the
/// singleton-gap boundary of the coverage-support partition on the
/// file-format sub-axis of the chain altitude.
///
/// The cube-native answer to *"did this chain miss exactly one
/// file-format cell?"*, routed through the shared
/// [`crate::AxisHistogram::has_singular_gap`] primitive on
/// [`Self::file_format_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard singleton-gap headline
/// over the recipe's file-format composition, the attestation
/// manifest gate *"rebuild window observes all-but-one file
/// format"*, the alerting policy predicate *"file-format gap
/// singular"* — now route through this named seam instead of four
/// previously drifting inline forms:
/// `chain.absent_file_formats_count() == 1` (coverage-gap-scalar),
/// `chain.absent_file_formats().len() == 1` (coverage-gap-`Vec`),
/// `chain.present_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>() - 1`
/// (support-scalar, which pays for a full-axis scan and pulls in
/// the [`crate::axis_cardinality`] turbofish at every call site),
/// and `chain.present_file_formats().len() ==
/// crate::axis_cardinality::<crate::discovery::Format>() - 1`
/// (support-`Vec`, which allocates a `Vec<crate::discovery::Format>`
/// and reads its length back). The four forms drifted in subtle
/// ways at every consumer site (allocation vs. scalar, turbofish
/// vs. name-only, coverage-gap side vs. support side). This lift
/// names the singleton-gap-file-formats predicate directly at the
/// chain-altitude surface with a single-pass short-circuiting scan.
///
/// **Lifts sideways to the file-format sub-axis of the chain
/// altitude** in the "singleton-gap across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_singular_gap`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_singular_gap`], and
/// lifted sideways to the layer-kind sub-axis by
/// [`Self::layer_kinds_singular_gap`]. Dual of the "singleton-
/// support across altitudes" projection at this sub-axis by
/// [`Self::file_formats_singular_support`] on the *complementary*
/// cardinality slice of the same coverage-support partition
/// (`singular_support` = *exactly-one* observed cell; `singular_gap`
/// = *exactly-one* unobserved cell). Parallels the "balanced across
/// altitudes" projection at this sub-axis by
/// [`Self::file_formats_balanced`], the "full-cover across
/// altitudes" projection at this sub-axis by
/// [`Self::file_formats_full_cover`], and the "any-observed across
/// altitudes" projection at this sub-axis by
/// [`Self::file_formats_any_observed`]. The last remaining chain-
/// altitude sub-axis is the natural next sideways lift:
/// `env_prefix_kinds_singular_gap` over
/// [`Self::env_prefix_kind_histogram`], closing the "singleton-gap
/// across altitudes" projection across every altitude / sub-axis
/// alongside the balanced / full-cover / any-observed / singular-
/// support projections that already closed the same grid.
///
/// **Empty-histogram convention** — returns `false` on every chain
/// whose file-format histogram is empty: every cell is unobserved
/// (`axis_cardinality::<crate::discovery::Format>() = 4`, not one),
/// so the singleton-gap predicate fails. Matches
/// [`crate::AxisHistogram::has_singular_gap`]'s empty-histogram
/// `false` convention one altitude down. Cross-sub-axis divergence
/// from [`Self::layer_kinds_singular_gap`]: the `false` side of the
/// boundary is wider on the file-format sub-axis — a non-empty
/// chain of only [`ConfigSource::Defaults`] / [`ConfigSource::Env`]
/// / unrecognized-extension [`ConfigSource::File`] layers ALSO reads
/// `false` (the histogram is empty even though the chain is not).
/// Matches [`Self::file_formats_any_observed`]'s,
/// [`Self::file_formats_full_cover`]'s, and
/// [`Self::file_formats_singular_support`]'s same-sided convention
/// at the empty-histogram boundary and dual of
/// [`Self::file_formats_balanced`]'s vacuous-uniformity witness
/// (which reads `true` on every empty-histogram chain): the five
/// boundaries partition the empty-histogram chain into the polarity
/// quintuple (`any_observed`=false, `singular_support`=false,
/// `singular_gap`=false, `balanced`=true, `full_cover`=false).
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single
/// [`crate::discovery::Format`]: three cells are unobserved on the
/// four-cell axis (not one), so the singleton-gap predicate fails.
/// Matches the strict disjointness
/// `file_formats_singular_gap ⇒ !file_formats_singular_support` on
/// this cardinality-4 sub-axis (adjacent support cardinalities `1`
/// vs. `3`). The singleton-support fixture partitions the five
/// coverage-support boundaries with (`any_observed`=true,
/// `singular_support`=true, `singular_gap`=false, `balanced`=true,
/// `full_cover`=false) — orthogonal to `singular_gap` on this axis.
///
/// **Three-format partial-cover convention** — returns `true` on
/// every chain whose observed support is exactly three
/// [`crate::discovery::Format`] cells: one cell is unobserved (four
/// total minus three observed equals one unobserved), exactly the
/// singleton-gap boundary. A chain of `/a.yaml + /b.toml + /c.lisp`
/// missing `Nix` is a witness. The three-format partial cover
/// fixture partitions the five coverage-support boundaries with
/// (`any_observed`=true, `singular_support`=false,
/// `singular_gap`=true, `balanced`=either polarity depending on
/// per-format counts, `full_cover`=false) — the row this predicate
/// isolates from the surrounding boundaries.
///
/// **Uniform four-format cover convention** — returns `false` on
/// every chain where each of the four
/// [`crate::discovery::Format`] cells was observed at least once:
/// zero cells are unobserved (not one), so the singleton-gap
/// predicate fails. Matches [`Self::file_formats_full_cover`]'s
/// `true` side on the same fixture — the two boundaries
/// `singular_gap` and `full_cover` are disjoint at the top of the
/// coverage-support partition (adjacent support cardinalities
/// `axis_cardinality - 1` and `axis_cardinality`). The uniform
/// four-format cover partitions the five coverage-support
/// boundaries with (`any_observed`=true, `singular_support`=false,
/// `singular_gap`=false, `balanced`=true, `full_cover`=true).
///
/// # Invariants
///
/// - `file_formats_singular_gap() ==
/// file_format_histogram().has_singular_gap()` — both project
/// the same predicate off the same primitive; the named seam is
/// the cube-native routing of the histogram surface.
/// - `file_formats_singular_gap() == (absent_file_formats_count()
/// == 1)` always — the coverage-gap-scalar surface, without
/// allocating the `Vec<crate::discovery::Format>`.
/// - `file_formats_singular_gap() == (absent_file_formats().len()
/// == 1)` always — the coverage-gap-`Vec` surface.
/// - `file_formats_singular_gap() == (present_file_formats_count()
/// == crate::axis_cardinality::<crate::discovery::Format>() - 1)`
/// always — the support-scalar surface, the dual-side surfacing
/// of the same boolean across the (observed, unobserved)
/// partition.
/// - `file_formats_singular_gap() == (present_file_formats().len()
/// == crate::axis_cardinality::<crate::discovery::Format>() - 1)`
/// always — the support-`Vec` surface.
/// - `file_formats_singular_gap() ⇒ file_formats_any_observed()`
/// on every axis with cardinality `>= 2` (every implementor today
/// — [`crate::discovery::Format`] carries four cells): a chain
/// missing exactly one cell observes at least `axis_cardinality -
/// 1 >= 1` cells. Contrapositively,
/// `!file_formats_any_observed() ⇒ !file_formats_singular_gap()`.
/// - `file_formats_singular_gap() ⇒ !file_formats_full_cover()`
/// always: full cover has zero unobserved cells, singular gap has
/// exactly one, so the two boundaries are disjoint on every axis.
/// - `file_formats_singular_gap() ⇒ !file_formats_singular_support()`
/// on every axis with cardinality `>= 3` (every implementor today
/// — [`crate::discovery::Format`] carries four cells): singleton-
/// support has support cardinality `1`, singleton-gap has support
/// cardinality `axis_cardinality - 1 >= 2`, so the two are
/// disjoint. On the cardinality-`2` corner (no chain-altitude
/// sub-axis today) the two coincide pointwise.
/// - `file_formats_singular_gap() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::File) >=
/// crate::axis_cardinality::<crate::discovery::Format>() - 1` —
/// a chain with a singleton file-format gap observes at least
/// `axis_cardinality - 1` recognized-extension file layers, one
/// for each observed cell, and every such layer is a
/// [`ConfigSource::File`]. Cross-sub-axis lower-bound implication
/// linking the file-format sub-axis singleton-gap boundary to the
/// layer-kind sub-axis File cell count. Cross-sub-axis divergence
/// from [`Self::layer_kinds_singular_gap`]'s
/// `self.as_ref().len() >= axis_cardinality::<ConfigSourceKind>() - 1`
/// implication, which reads on the chain-length rather than the
/// File-layer count — matching the same divergence pattern
/// between [`Self::file_formats_singular_support`] and
/// [`Self::layer_kinds_singular_support`] on the complementary
/// cardinality slice.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the singular-gap scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits on
/// the second zero cell (bounded at two zero cells visited on any
/// two-or-more-cell-gap chain), strictly tighter than the four
/// support / coverage-gap equality forms — no
/// `Vec<crate::discovery::Format>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no scalar equality
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn file_formats_singular_gap(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().has_singular_gap()
}
/// Returns `true` exactly when this chain's
/// [`ConfigSource::File`] layers with recognized extensions observe a
/// [`crate::discovery::Format`] support sitting *strictly between*
/// the two singular-cardinality boundaries — at least *two* observed
/// cells *and* at least *two* unobserved cells. The boundary-free
/// interior of the coverage-support partition strictly inside the
/// middle leg of the coarser coverage trichotomy on the file-format
/// sub-axis of the chain altitude.
///
/// The cube-native answer to *"did this chain's file-format
/// composition land in the strict interior of the support-cardinality
/// interval — neither on a singular boundary nor on a coverage
/// boundary?"*, routed through the shared
/// [`crate::AxisHistogram::has_strict_partial_cover`] primitive on
/// [`Self::file_format_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard strict-interior
/// headline over the chain's file-format composition, the
/// attestation manifest gate *"chain file-format support strictly
/// interior"*, the alerting policy predicate *"file-format support
/// strictly interior"* — now route through this named seam instead
/// of four previously drifting inline forms:
/// `chain.file_format_histogram().has_partial_cover() &&
/// !chain.file_formats_singular_support() &&
/// !chain.file_formats_singular_gap()` (structural conjunction on
/// three named predicates), `1 < chain.present_file_formats_count()
/// && chain.present_file_formats_count() + 1 <
/// crate::axis_cardinality::<crate::discovery::Format>()` (support-
/// scalar strict-interval with [`crate::axis_cardinality`] turbofish
/// and `+ 1 <` arithmetic), `1 < chain.absent_file_formats_count()
/// && chain.absent_file_formats_count() + 1 <
/// crate::axis_cardinality::<crate::discovery::Format>()` (coverage-
/// gap-scalar strict-interval on the complementary side), and
/// `chain.present_file_formats().len() >= 2 &&
/// chain.absent_file_formats().len() >= 2` (dual-`Vec` at-least-two-
/// of-each, allocating two vectors just to peek their lengths).
///
/// **Lifts sideways to the file-format sub-axis of the chain
/// altitude** in the "strict-partial-cover across altitudes"
/// projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_strict_partial_cover`], climbed to the
/// tier altitude by
/// [`crate::ProvenanceMap::tiers_strict_partial_cover`], and lifted
/// sideways to the layer-kind sub-axis by
/// [`Self::layer_kinds_strict_partial_cover`]. Middle-leg-corner
/// peer of the five already-closed coverage-support boundary
/// families on the same sub-axis
/// ([`Self::file_formats_balanced`],
/// [`Self::file_formats_full_cover`],
/// [`Self::file_formats_any_observed`],
/// [`Self::file_formats_singular_support`],
/// [`Self::file_formats_singular_gap`]) — the last unnamed corner of
/// the 5-corner support-cardinality partition on the file-format
/// sub-axis. The remaining chain-altitude sub-axis is the natural
/// next sideways lift: `env_prefix_kinds_strict_partial_cover` over
/// [`Self::env_prefix_kind_histogram`], closing the "strict-partial-
/// cover across altitudes" projection across every altitude / sub-
/// axis alongside the five previously-closed rows and promoting the
/// coverage-support predicate cube from 5×5 to 6×5 corners.
///
/// **Cardinality-`4` reachability — the *only* reachable altitude /
/// sub-axis in the projection.** The strict interior carries
/// witnesses only on axes with `axis_cardinality::<A>() >= 4` (the
/// strict interval `[2, cardinality - 2]` is empty on cardinality
/// `0`, `1`, `2`, or `3`). [`crate::discovery::Format`] carries
/// exactly four cells, so the strict interior on the file-format
/// sub-axis is reachable at support cardinality `2` (exactly two
/// observed cells and two unobserved cells) — the *unique* corner
/// where the strict-interior boundary fires. Every chain observing
/// exactly two file-format cells (Yaml + Toml, Toml + Nix, etc.) is
/// a witness — the two-format partial cover fixture with two `.toml`
/// and one `.yaml` file layer in the recessive-file-format fixture
/// set is one such witness. Distinguishes the file-format sub-axis
/// from every other altitude / sub-axis in the "strict-partial-cover
/// across altitudes" projection: the diff altitude ([`DiffLineKind`]
/// cardinality `3`), the chain layer-kind sub-axis
/// ([`ConfigSourceKind`] cardinality `3`), and the chain env-prefix
/// sub-axis ([`crate::env_metadata::EnvMetadataTagKind`] cardinality
/// `2`) all read `false` uniformly. The tier altitude
/// ([`crate::tiered::ConfigTierKind`] cardinality `4`) is the peer
/// where the strict interior is reachable at the same support
/// cardinality `2`.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain has zero observed cells, so the "at least two
/// observed" half of the conjunction fails uniformly. Matches
/// [`crate::AxisHistogram::has_strict_partial_cover`]'s empty-
/// histogram `false` convention one altitude down. The empty chain
/// is therefore on the `false` side of the strict-interior boundary
/// — matching [`Self::file_formats_any_observed`]'s empty-chain
/// `false` polarity, [`Self::file_formats_full_cover`]'s empty-chain
/// `false` polarity, [`Self::file_formats_singular_support`]'s
/// empty-chain `false` polarity, and
/// [`Self::file_formats_singular_gap`]'s empty-chain `false`
/// polarity.
///
/// **No-recognized-files convention** — returns `false` on every
/// non-empty chain whose file-format histogram is empty (chains of
/// only [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers). The
/// histogram is empty even though the chain is not, so the "at
/// least two observed" half fails uniformly. Cross-sub-axis
/// divergence from [`Self::layer_kinds_strict_partial_cover`]: the
/// `false` side of the boundary is wider on the file-format sub-axis
/// — the empty-histogram non-empty-chain case is also `false` here,
/// matching [`Self::file_formats_singular_gap`]'s and
/// [`Self::file_formats_singular_support`]'s same-sided convention
/// on the same fixtures.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single
/// [`crate::discovery::Format`] cell: the support cardinality is `1`
/// (not `>= 2`), so the "at least two observed" half fails
/// uniformly. Direct witness of the strict disjointness
/// `file_formats_singular_support ⇒
/// !file_formats_strict_partial_cover`.
///
/// **Three-format partial cover convention** — returns `false` on
/// every chain whose observed support is exactly three
/// [`crate::discovery::Format`] cells: only one cell is unobserved
/// (four total minus three observed equals one unobserved), so the
/// "at least two unobserved" half fails uniformly. Direct witness of
/// the strict disjointness `file_formats_singular_gap ⇒
/// !file_formats_strict_partial_cover` on the cardinality-`4`
/// [`crate::discovery::Format`] axis (adjacent support cardinalities
/// `3` and `[2, 2]` never overlap).
///
/// **Uniform four-format cover convention** — returns `false` on
/// every chain where each of the four
/// [`crate::discovery::Format`] cells was observed at least once:
/// zero cells are unobserved, so the "at least two unobserved" half
/// fails uniformly. Matches
/// [`crate::AxisHistogram::has_strict_partial_cover`]'s full-cover
/// `false` convention one altitude down.
///
/// **Two-format partial cover convention (the reachable corner)** —
/// returns `true` on every chain whose observed support is exactly
/// two [`crate::discovery::Format`] cells: two cells are observed
/// and two cells are unobserved on the four-cell axis, exactly the
/// strict-interior boundary at support cardinality `2`. A chain
/// observing `.yaml + .toml` (missing `.lisp + .nix`) is a witness.
/// The two-format partial cover fixture partitions the five
/// coverage-support boundaries with (`any_observed`=true,
/// `singular_support`=false, `singular_gap`=false,
/// `strict_partial_cover`=true, `full_cover`=false) — the row this
/// predicate isolates from the surrounding boundaries.
///
/// # Invariants
///
/// - `file_formats_strict_partial_cover() ==
/// file_format_histogram().has_strict_partial_cover()` — both
/// project the same predicate off the same primitive; the named
/// seam is the cube-native routing of the histogram surface.
/// - `file_formats_strict_partial_cover() ⇔
/// file_format_histogram().has_partial_cover() &&
/// !file_formats_singular_support() &&
/// !file_formats_singular_gap()` always — the defining structural-
/// conjunction form on the existing named-boundary triad: the
/// strict interior is exactly the partial-cover middle leg minus
/// its two singular-cardinality corners.
/// - `file_formats_strict_partial_cover() == (1 <
/// present_file_formats_count() && present_file_formats_count() +
/// 1 < crate::axis_cardinality::<crate::discovery::Format>())`
/// always — the support-scalar strict-interval form, without
/// allocating the `Vec<crate::discovery::Format>`.
/// - `file_formats_strict_partial_cover() == (1 <
/// absent_file_formats_count() && absent_file_formats_count() + 1
/// < crate::axis_cardinality::<crate::discovery::Format>())`
/// always — the coverage-gap-scalar strict-interval form on the
/// complementary side of the same partition.
/// - `file_formats_strict_partial_cover() ⇒
/// file_formats_any_observed()` on the cardinality-`4`
/// [`crate::discovery::Format`] axis (a strict-interior chain has
/// `>= 2` observed cells, so `>= 1` observed cell).
/// Contrapositively, `!file_formats_any_observed() ⇒
/// !file_formats_strict_partial_cover()`.
/// - `file_formats_strict_partial_cover() ⇒
/// !file_formats_full_cover()` always: the strict interior
/// requires `>= 2` unobserved cells, a full cover has zero
/// unobserved cells.
/// - `file_formats_strict_partial_cover() ⇒
/// !file_formats_singular_support()` always: the strict interior
/// requires `>= 2` observed cells, a singleton support has
/// exactly `1` observed cell.
/// - `file_formats_strict_partial_cover() ⇒
/// !file_formats_singular_gap()` always: the strict interior
/// requires `>= 2` unobserved cells, a singleton gap has exactly
/// `1` unobserved cell.
/// - `file_formats_strict_partial_cover() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::File) >= 2` —
/// a chain with `>= 2` observed file-format cells has at least
/// `2` recognized-extension file layers, one for each observed
/// cell, and every such layer is a [`ConfigSource::File`]. Cross-
/// sub-axis lower-bound implication linking the file-format sub-
/// axis strict-interior boundary to the layer-kind sub-axis File
/// cell count. Cross-sub-axis divergence from
/// [`Self::layer_kinds_strict_partial_cover`]'s vacuously-`false`
/// antecedent — on the cardinality-`3` layer-kind sub-axis the
/// antecedent never fires, so the implication holds vacuously and
/// the file-format sub-axis carries the *first* non-vacuous witness
/// of the strict-interior boundary on the chain altitude.
/// - `(!file_formats_any_observed, file_formats_singular_support,
/// file_formats_strict_partial_cover, file_formats_singular_gap,
/// file_formats_full_cover)` is pairwise disjoint on every chain
/// whose file-format histogram is non-empty — distinct support
/// cardinalities `0`, `1`, `[2, cardinality - 2]`,
/// `cardinality - 1`, `cardinality` never overlap. Together the
/// five predicates partition every chain on the file-format sub-
/// axis (exactly one of the five corners fires per chain).
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the strict-partial-cover scan). Both are `O(n)` in practice
/// since the file-format axis carries a fixed four-cell cardinality;
/// the returned `bool` reads one predicate. The scan short-circuits
/// once it has witnessed both *two* zero counts and *two* nonzero
/// counts (bounded at four witness cells visited on any strict-
/// interior histogram — the whole four-cell axis on the cardinality-
/// `4` file-format sub-axis), strictly tighter than the four
/// documented open-coded surfaces — no
/// `Vec<crate::discovery::Format>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no dual scalar equality
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn file_formats_strict_partial_cover(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().has_strict_partial_cover()
}
/// Returns `true` exactly when this chain's observed
/// [`crate::discovery::Format`] support sits at the *bottom* of the
/// support-cardinality interval — at most *one* observed cell.
/// The **low-support-file-formats boolean predicate** on the
/// file-format sub-axis of the chain altitude, the union-of-low-
/// boundaries corner of the support-cardinality magnitude-
/// direction ternary partition `(low_support,
/// strict_partial_cover, high_support)` — the bottom leg of the
/// magnitude ternary, folding the empty-histogram and the
/// singleton-support boundaries into a single named
/// low-magnitude corner.
///
/// The cube-native answer to *"did this chain land in the
/// low-magnitude corner of the file-format support-cardinality
/// interval?"*, routed through the shared
/// [`crate::AxisHistogram::has_low_support`] primitive on
/// [`Self::file_format_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard low-magnitude
/// headline over the chain's file-format composition, the
/// attestation manifest gate *"chain file-format support at most
/// singleton"*, the alerting policy predicate *"file-format
/// support low-magnitude"* — now route through this named seam
/// instead of four previously drifting inline forms: defining-
/// union-of-low-boundaries disjunction on the two named
/// histogram-side peers (`!chain.file_formats_any_observed() ||
/// chain.file_formats_singular_support()`), support-scalar
/// at-most-one form (`chain.present_file_formats_count() <= 1`),
/// support-`Vec` at-most-one form
/// (`chain.present_file_formats().len() <= 1`, allocating a
/// `Vec<crate::discovery::Format>` just to peek its length), and
/// coverage-gap-scalar at-least-axis-cardinality-minus-one form
/// (`chain.absent_file_formats_count() >=
/// crate::axis_cardinality::<crate::discovery::Format>() - 1`
/// with [`crate::axis_cardinality`] turbofish and `- 1`
/// arithmetic).
///
/// **Lifts sideways to the file-format sub-axis of the chain
/// altitude** in the "low-support across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_low_support`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_low_support`], and
/// lifted sideways to the layer-kind sub-axis by
/// [`Self::layer_kinds_low_support`]. Bottom-leg-corner peer of
/// the six already-closed coverage-support boundary and interior
/// families on the same sub-axis
/// ([`Self::file_formats_balanced`],
/// [`Self::file_formats_full_cover`],
/// [`Self::file_formats_any_observed`],
/// [`Self::file_formats_singular_support`],
/// [`Self::file_formats_singular_gap`],
/// [`Self::file_formats_strict_partial_cover`]). The remaining
/// chain-altitude sub-axis is the natural next sideways lift:
/// `env_prefix_kinds_low_support` over
/// [`Self::env_prefix_kind_histogram`], closing the "low-support
/// across altitudes" projection alongside the six coverage-
/// support predicate cube rows already carried and continuing
/// the magnitude-direction ternary vertical row by row.
///
/// **Cardinality-`4` reachability — strict-interior peer
/// disjointness is non-vacuous here.** The bottom magnitude
/// corner carries witnesses on every axis with
/// `axis_cardinality::<A>() >= 1` (the empty histogram always
/// witnesses low support via the "at most one observed"
/// clause). [`crate::discovery::Format`] carries four cells, so
/// `file_formats_low_support()` reads `true` on the empty chain,
/// on every non-empty chain whose file-format histogram is empty
/// (chains of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::Env`] / unrecognized-extension
/// [`ConfigSource::File`] layers), and on every singleton-
/// support chain (all recognized-extension file layers observing
/// only-`Yaml`, only-`Toml`, only-`Lisp`, or only-`Nix`), and
/// `false` on every two-or-more-cell-cover chain (two-format
/// partial cover, three-format partial cover, uniform four-
/// format cover). Strictly disjoint from the strict-interior
/// predicate [`Self::file_formats_strict_partial_cover`] whose
/// support-cardinality interval `[2, cardinality - 2]` is
/// non-empty on the cardinality-`4` file-format sub-axis — this
/// lift's strict-interior disjointness carries its *first*
/// non-vacuous witness on the chain altitude (the two-format
/// partial cover fixture reads `strict_partial_cover=true`
/// AND `low_support=false`, exercising both sides of the strict
/// disjointness on the same fixture). The layer-kind sub-axis
/// [`Self::layer_kinds_low_support`] on the cardinality-`3`
/// [`ConfigSourceKind`] axis carries the same disjointness
/// vacuously (the strict interior is unreachable), so the
/// file-format sub-axis is the *first* row of the "low-support
/// across altitudes" projection where the ternary partition
/// carries content on both sides of the middle leg. Matches the
/// tier altitude ([`crate::tiered::ConfigTierKind`] cardinality
/// `4`) as the second reachable strict-interior peer in the
/// projection.
///
/// **Empty-chain convention** — returns `true` on the empty
/// chain: zero observed cells satisfy the "at most one observed"
/// clause vacuously. Matches
/// [`crate::AxisHistogram::has_low_support`]'s empty-histogram
/// `true` convention one altitude down, and diverges from
/// [`Self::file_formats_any_observed`]'s empty-chain `false`
/// polarity — the low-support boundary strictly includes the
/// empty chain by folding the "no observation" case into the
/// low-magnitude corner.
///
/// **No-recognized-files convention** — returns `true` on every
/// non-empty chain whose file-format histogram is empty (chains
/// of only [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers). The
/// histogram is empty even though the chain is not, so the "at
/// most one observed" clause holds vacuously. Cross-sub-axis
/// divergence from [`Self::layer_kinds_low_support`]: the
/// low-magnitude corner is wider on the file-format sub-axis —
/// the empty-histogram non-empty-chain case reads `true` here,
/// matching [`Self::file_formats_any_observed`]'s empty-
/// histogram `false` polarity through negation and diverging
/// from the layer-kind sub-axis peer where every non-empty chain
/// observes at least one layer-kind cell.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single
/// [`crate::discovery::Format`] cell: support cardinality `1`
/// satisfies `<= 1`. Peer of
/// [`Self::file_formats_singular_support`]'s `true` side on the
/// same fixture — the singleton-support boundary fires into the
/// low-magnitude corner via the union-of-low-boundaries
/// disjunction.
///
/// **Two-format partial cover convention (the strict-interior
/// witness)** — returns `false` on every chain whose observed
/// support is exactly two [`crate::discovery::Format`] cells:
/// support cardinality `2` violates `<= 1`. Direct witness of
/// the strict disjointness `file_formats_strict_partial_cover ⇒
/// !file_formats_low_support` on the cardinality-`4`
/// [`crate::discovery::Format`] axis — the *first* non-vacuous
/// witness of the strict-interior disjointness clause on the
/// chain altitude, unavailable at the layer-kind sub-axis whose
/// cardinality-`3` axis renders the antecedent vacuous.
///
/// **Three-format partial cover convention** — returns `false`
/// on every chain whose observed support is exactly three
/// [`crate::discovery::Format`] cells: support cardinality `3`
/// violates `<= 1`. Direct witness of the disjointness
/// `file_formats_singular_gap ⇒ !file_formats_low_support` on
/// the cardinality-`4` axis where the singleton-gap slice sits
/// at support cardinality `axis_cardinality - 1 = 3`.
///
/// **Uniform four-format cover convention** — returns `false`
/// on every chain where each [`crate::discovery::Format`] cell
/// was observed at least once: support cardinality `4` violates
/// `<= 1`. Matches
/// [`crate::AxisHistogram::has_low_support`]'s full-cover
/// `false` convention one altitude down on cardinality-`>= 2`
/// axes.
///
/// # Invariants
///
/// - `file_formats_low_support() ==
/// file_format_histogram().has_low_support()` — both project
/// the same predicate off the same primitive; the named seam
/// is the cube-native routing of the histogram surface.
/// - `file_formats_low_support() ⇔ !file_formats_any_observed()
/// || file_formats_singular_support()` always — the defining
/// union-of-low-boundaries disjunction on the two named
/// histogram-side peers.
/// - `file_formats_low_support() ==
/// (present_file_formats_count() <= 1)` always — the
/// support-scalar at-most-one form, without allocating the
/// `Vec<crate::discovery::Format>`.
/// - `file_formats_low_support() ==
/// (present_file_formats().len() <= 1)` always — the support-
/// `Vec` at-most-one form.
/// - `file_formats_low_support() == (absent_file_formats_count() >=
/// crate::axis_cardinality::<crate::discovery::Format>() - 1)`
/// always — the coverage-gap-scalar at-least-axis-cardinality-
/// minus-one form, the dual-side surfacing of the same boolean
/// across the (observed, unobserved) partition.
/// - `file_formats_low_support() ⇒ !file_formats_full_cover()`
/// on every axis with `axis_cardinality::<A>() >= 2` (every
/// implementor today — [`crate::discovery::Format`] carries
/// four cells): low support has size `<= 1`, full cover has
/// size `axis_cardinality >= 2`.
/// - `file_formats_low_support() ⇒ !file_formats_singular_gap()`
/// on every axis with `axis_cardinality::<A>() >= 3` (every
/// implementor today — [`crate::discovery::Format`] carries
/// four cells): low support has size `<= 1`, singular-gap has
/// support size `axis_cardinality - 1 >= 2`.
/// - `file_formats_low_support() ⇒
/// !file_formats_strict_partial_cover()` always: the strict
/// interior requires `>= 2` observed cells; low support has
/// `<= 1`. On the cardinality-`4`
/// [`crate::discovery::Format`] axis this carries content on
/// both sides (the two-format partial cover fixture is a
/// `strict_partial_cover=true, low_support=false` witness) —
/// the *first* non-vacuous witness of the disjointness on the
/// chain altitude.
/// - `!file_formats_any_observed() ⇒ file_formats_low_support()`
/// always — the empty histogram always sits at the bottom of
/// the magnitude interval.
/// - `file_formats_singular_support() ⇒
/// file_formats_low_support()` always — every singleton-
/// support chain lands on the low-magnitude corner by the
/// union-of-low-boundaries disjunction.
/// - `(file_formats_low_support, file_formats_strict_partial_cover,
/// file_formats_high_support)` forms a strict ternary partition
/// on every axis with `axis_cardinality::<A>() >= 2` — pinned
/// trait-uniformly one altitude down by
/// `axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k =
/// crate::axis_cardinality::<crate::discovery::Format>()` (the
/// low-support scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits
/// once it has witnessed the *second* nonzero cell (bounded at
/// two nonzero cells visited on any two-or-more-cell-support
/// chain), strictly tighter than the four documented open-coded
/// surfaces — no `Vec<crate::discovery::Format>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no `- 1` arithmetic
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn file_formats_low_support(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().has_low_support()
}
/// Returns `true` exactly when this chain's observed
/// [`crate::discovery::Format`] support sits at the *top* of the
/// support-cardinality interval — at most *one* unobserved cell,
/// excising the cardinality-`2` dual-singular-collapse case
/// ([`crate::discovery::Format`] carries four cells so the excision
/// never fires at the file-format sub-axis). The **high-support-
/// file-formats boolean predicate** on the file-format sub-axis of
/// the chain altitude, the strict-singular-gap-or-full-cover
/// corner of the support-cardinality magnitude-direction ternary
/// partition `(low_support, strict_partial_cover, high_support)`
/// — the top leg of the magnitude ternary, folding the full-cover
/// and the strict singleton-gap boundaries into a single named
/// high-magnitude corner.
///
/// The cube-native answer to *"did this chain land in the
/// high-magnitude corner of the file-format support-cardinality
/// interval?"*, routed through the shared
/// [`crate::AxisHistogram::has_high_support`] primitive on
/// [`Self::file_format_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard high-magnitude
/// headline over the chain's file-format composition, the
/// attestation manifest gate *"chain file-format support at least
/// axis-cardinality-minus-one"*, the alerting policy predicate
/// *"file-format support high-magnitude"* — now route through
/// this named seam instead of four previously drifting inline
/// forms: defining strict-singular-gap-or-full-cover disjunction
/// on three named histogram-side peers
/// (`chain.file_formats_full_cover() ||
/// (chain.file_formats_singular_gap() &&
/// !chain.file_formats_singular_support())`), coverage-gap-scalar
/// dual-interval form (`chain.absent_file_formats_count() <= 1 &&
/// chain.present_file_formats_count() >= 2`), support-scalar
/// dual-interval form (`chain.present_file_formats_count() + 1 >=
/// crate::axis_cardinality::<crate::discovery::Format>() &&
/// chain.present_file_formats_count() >= 2`), and support-`Vec`
/// dual-length form (`chain.present_file_formats().len() + 1 >=
/// crate::axis_cardinality::<crate::discovery::Format>() &&
/// chain.present_file_formats().len() >= 2`, allocating a
/// `Vec<crate::discovery::Format>` just to peek its length).
///
/// **Lifts sideways to the file-format sub-axis of the chain
/// altitude** in the "high-support across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_high_support`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_high_support`], and
/// lifted sideways to the layer-kind sub-axis by
/// [`Self::layer_kinds_high_support`]. Top-leg-corner peer of the
/// seven already-closed coverage-support and magnitude boundary
/// and interior families on the same sub-axis
/// ([`Self::file_formats_balanced`],
/// [`Self::file_formats_full_cover`],
/// [`Self::file_formats_any_observed`],
/// [`Self::file_formats_singular_support`],
/// [`Self::file_formats_singular_gap`],
/// [`Self::file_formats_strict_partial_cover`],
/// [`Self::file_formats_low_support`]). The remaining chain-
/// altitude sub-axis is the natural next sideways lift:
/// `env_prefix_kinds_high_support` over
/// [`Self::env_prefix_kind_histogram`], closing the "high-support
/// across altitudes" projection alongside the parallel low-support
/// projection and continuing the magnitude-direction ternary
/// vertical row by row.
///
/// **Cardinality-`4` reachability at the chain file-format
/// sub-axis — the two high-magnitude witnesses AND a non-vacuous
/// middle leg.** The top magnitude corner carries witnesses on
/// every axis with `axis_cardinality::<A>() >= 2` (the full-cover
/// fixture always witnesses high support via the `is_full_cover()`
/// disjunct on the bridge). [`crate::discovery::Format`] carries
/// four cells, so `file_formats_high_support()` reads `false` on
/// the empty chain, on every non-empty chain whose file-format
/// histogram is empty (chains of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::Env`] / unrecognized-extension
/// [`ConfigSource::File`] layers), on every singleton-support
/// chain, AND on every two-format partial cover (support size `2`,
/// two unobserved cells — the strict-interior fold), and `true`
/// on every three-format partial cover
/// (`file_formats_singular_gap` fires with support size `3`) and
/// on every uniform four-format cover (`file_formats_full_cover`
/// fires with support size `4`). Strict advance over the layer-
/// kind sub-axis: the strict-interior disjointness
/// `file_formats_high_support ⇒ !file_formats_strict_partial_cover`
/// carries content at the file-format sub-axis (the two-format
/// partial-cover fixture reads `file_formats_strict_partial_cover
/// == true` and `file_formats_high_support == false`), unlike the
/// vacuously-`true` consequent on the cardinality-`3` layer-kind
/// axis where the strict interior is unreachable. Matches the
/// tier altitude ([`crate::tiered::ConfigTierKind`] cardinality
/// `4`) as the second reachable strict-interior peer in the
/// projection — the magnitude-direction ternary closes strictly
/// *and* non-vacuously at both the tier altitude and the file-
/// format sub-axis, and degenerately at the layer-kind sub-axis
/// and the diff altitude.
///
/// **Empty-chain convention** — returns `false` on the empty
/// chain: zero observed cells fail the "at least two observed"
/// clause uniformly. Matches
/// [`crate::AxisHistogram::has_high_support`]'s empty-histogram
/// `false` convention one altitude down for every cardinality-
/// `>= 2` axis. Orthogonal polarity to
/// [`Self::file_formats_low_support`]'s empty-chain `true` — the
/// two magnitude corners partition every non-strict-interior fold
/// at the file-format sub-axis and the empty chain sits at the
/// *bottom* of the magnitude interval, not the top.
///
/// **No-recognized-files convention** — returns `false` on every
/// non-empty chain whose file-format histogram is empty (chains
/// of only [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers). The
/// histogram is empty even though the chain is not, so every cell
/// is unobserved (four zeros on the cardinality-`4` axis) — the
/// "at most one unobserved" clause fails. Cross-sub-axis
/// divergence from [`Self::layer_kinds_high_support`]: the
/// high-magnitude corner is narrower on the file-format sub-axis
/// — the empty-histogram non-empty-chain case reads `false` here,
/// matching [`Self::file_formats_low_support`]'s empty-histogram
/// `true` polarity through disjointness and diverging from the
/// layer-kind sub-axis peer where every non-empty chain observes
/// at least one layer-kind cell.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed support is a single
/// [`crate::discovery::Format`] cell: support cardinality `1`
/// violates the "at least axis-cardinality-minus-one" clause
/// uniformly on cardinality-`>= 3` axes. Peer of
/// [`Self::file_formats_singular_support`]'s `true` side on the
/// same fixture — the singleton-support boundary lands on the
/// low-magnitude corner, not the high-magnitude corner.
///
/// **Two-format partial cover convention (the strict-interior
/// witness)** — returns `false` on every chain whose observed
/// support is exactly two [`crate::discovery::Format`] cells:
/// support cardinality `2` on the cardinality-`4` axis leaves
/// exactly two unobserved cells — the "at most one unobserved"
/// clause fails. Direct witness of the *non-vacuous* strict
/// disjointness `file_formats_strict_partial_cover ⇒
/// !file_formats_high_support` on the cardinality-`4`
/// [`crate::discovery::Format`] axis — a strict advance over the
/// cardinality-`3` layer-kind sub-axis where the same
/// disjointness holds vacuously (the strict interior is
/// unreachable). Matches the tier altitude
/// ([`crate::tiered::ConfigTierKind`] cardinality `4`) — the
/// two-tier partial-cover fixture there reads
/// `tiers_strict_partial_cover == true` and
/// `tiers_high_support == false` on the same strict-interior
/// boundary.
///
/// **Three-format partial cover convention** — returns `true` on
/// every chain whose observed support is exactly three
/// [`crate::discovery::Format`] cells: support cardinality `3`
/// on the cardinality-`4` axis leaves exactly one unobserved
/// cell — `file_formats_singular_gap` fires. Direct witness of
/// the strict subsumption `file_formats_singular_gap ⇒
/// file_formats_high_support` on the cardinality-`>= 3` axis
/// where the dual-singular-collapse never fires.
///
/// **Uniform four-format cover convention** — returns `true` on
/// every chain where each [`crate::discovery::Format`] cell was
/// observed at least once: support cardinality `4` (no
/// unobserved cells) — `file_formats_full_cover` fires. Direct
/// witness of the strict subsumption `file_formats_full_cover ⇒
/// file_formats_high_support` on every axis with
/// `axis_cardinality::<A>() >= 2`. Matches
/// [`crate::AxisHistogram::has_high_support`]'s full-cover
/// `true` convention one altitude down.
///
/// # Invariants
///
/// - `file_formats_high_support() ==
/// file_format_histogram().has_high_support()` — both project
/// the same predicate off the same primitive; the named seam
/// is the cube-native routing of the histogram surface.
/// - `file_formats_high_support() ⇔ file_formats_full_cover() ||
/// (file_formats_singular_gap() && !file_formats_singular_support())`
/// always — the defining strict-singular-gap-or-full-cover
/// disjunction on three named histogram-side peers. The
/// `!file_formats_singular_support()` excision is vacuous on
/// the cardinality-`4` file-format axis (when singular-gap
/// fires, support size `3 != 1`) but is pinned verbatim so
/// downstream cardinality-`2` sub-axis lifts inherit the
/// dual-singular-collapse excision.
/// - `file_formats_high_support() == (absent_file_formats_count()
/// <= 1 && present_file_formats_count() >= 2)` always — the
/// coverage-gap-scalar dual-interval form on the complementary
/// side of the same partition, without allocating either
/// `Vec<crate::discovery::Format>`.
/// - `file_formats_high_support() == (present_file_formats_count() + 1 >=
/// crate::axis_cardinality::<crate::discovery::Format>() &&
/// present_file_formats_count() >= 2)` always — the support-
/// scalar dual-interval form.
/// - `file_formats_high_support() == (present_file_formats().len() + 1 >=
/// crate::axis_cardinality::<crate::discovery::Format>() &&
/// present_file_formats().len() >= 2)` always — the support-
/// `Vec` dual-length form, the allocating peer of the scalar
/// surface above.
/// - `file_formats_high_support() ⇒ !file_formats_low_support()`
/// on every axis with `axis_cardinality::<A>() >= 2` (every
/// implementor today — [`crate::discovery::Format`] carries
/// four cells): high support has size `>= 2`, low support has
/// size `<= 1`, so the two magnitude corners are disjoint.
/// - `file_formats_high_support() ⇒
/// !file_formats_strict_partial_cover()` always: the strict
/// interior requires `>= 2` unobserved cells; high support has
/// `<= 1`. On the cardinality-`4` `crate::discovery::Format`
/// axis this carries content on both sides (the two-format
/// partial cover fixture is a `strict_partial_cover=true,
/// high_support=false` witness) — the *first non-vacuous*
/// witness of the disjointness on the chain altitude, unlike
/// the vacuously-`true` consequent on the cardinality-`3`
/// layer-kind sub-axis.
/// - `file_formats_high_support() ⇒ file_formats_any_observed()`
/// on every axis with `axis_cardinality::<A>() >= 2`: high
/// support has size `>= 2 >= 1`, so at least one cell was
/// observed. The empty chain and every empty-histogram non-
/// empty chain sit on the disjoint `!file_formats_any_observed`
/// boundary at the bottom of the magnitude interval.
/// - `file_formats_full_cover() ⇒ file_formats_high_support()`
/// always — the strict subsumption over the top full-cover
/// peer via the `is_full_cover()` disjunct on the bridge.
/// The full-cover corner always sits inside the high-magnitude
/// corner.
/// - `file_formats_singular_gap() ⇒ file_formats_high_support()`
/// on every axis with cardinality `>= 3` (every file-format
/// implementor today): singleton-gap has support size
/// `axis_cardinality - 1 >= 2`, so the "at most one
/// unobserved" *and* "at least two observed" clauses both
/// hold. On the cardinality-`2` corner (no file-format axis
/// today) the two diverge via the dual-singular-collapse
/// excision.
/// - `(file_formats_low_support, file_formats_strict_partial_cover,
/// file_formats_high_support)` forms a strict ternary partition
/// on every axis with `axis_cardinality::<A>() >= 2`. On the
/// cardinality-`4` file-format axis every leg is inhabited —
/// the ternary partitions the fold non-vacuously into three
/// distinct magnitude regions (empty / singleton-support on
/// the low leg, two-format partial cover on the strict-
/// interior middle leg, three-format partial cover / uniform
/// four-format cover on the high leg). A strict advance over
/// the cardinality-`3` layer-kind sub-axis where the middle
/// leg is vacuously empty. Pinned trait-uniformly one altitude
/// down by
/// `axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the high-support scan). Both are `O(n)` in practice since
/// the file-format axis carries a fixed four-cell cardinality;
/// the returned `bool` reads one predicate. The scan short-
/// circuits on the *second* zero cell (bounded at two zero-
/// witness cells visited on any two-or-more-unobserved-cell
/// chain), strictly tighter than the four documented open-
/// coded surfaces — no three-way boolean disjunction across
/// three named predicates, no `Vec<crate::discovery::Format>`
/// allocation, no [`crate::axis_cardinality`] turbofish with
/// `+ 1` arithmetic against a magic threshold.
#[must_use]
fn file_formats_high_support(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().has_high_support()
}
/// Returns `true` exactly when this chain's observed
/// [`crate::discovery::Format`] support sits on a *singular near-
/// boundary* — either exactly one observed cell
/// ([`Self::file_formats_singular_support`]) or exactly one
/// unobserved cell ([`Self::file_formats_singular_gap`]). The
/// **singular-file-formats boolean predicate** on the file-format
/// sub-axis of the chain altitude, the singular near-boundary
/// corner of the distance-from-boundary ternary partition
/// `(has_boundary, has_singular, has_strict_partial_cover)` — the
/// middle leg of the distance ternary, folding the two singular-
/// cardinality boundaries into a single named one-cell-off-
/// boundary corner. Routes through
/// [`crate::AxisHistogram::has_singular`] one altitude down: the
/// single-pass short-circuiting scan over the fixed-cardinality
/// counts vector that short-circuits the moment both a *second*
/// zero cell *and* a *second* nonzero cell have been witnessed,
/// bounded at four witness cells — strictly tighter than any of
/// the four documented open-coded surfaces one seam over.
///
/// The **singular-file-formats peer** of the four documented
/// surface forms consumers previously re-derived inline:
/// `chain.file_formats_singular_support() ||
/// chain.file_formats_singular_gap()` (the defining-union-of-
/// singular-boundaries disjunction on two named histogram-side
/// peers, a boolean or on two method calls that walks the counts
/// vector twice), `chain.present_file_formats_count() == 1 ||
/// chain.present_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>() - 1`
/// (the support-scalar dual-equality form, which pays for a full-
/// axis scan and equates a `usize` against two magic thresholds
/// with the [`crate::axis_cardinality`] turbofish and `- 1`
/// arithmetic), `chain.present_file_formats_count() == 1 ||
/// chain.absent_file_formats_count() == 1` (the dual-scalar
/// equality form on the two named cardinality peers, without
/// allocating either `Vec<crate::discovery::Format>`), and
/// `chain.present_file_formats().len() == 1 ||
/// chain.absent_file_formats().len() == 1` (the dual-`Vec`
/// equality form, which allocates *two*
/// `Vec<crate::discovery::Format>` values just to peek their
/// lengths). The four forms drifted in subtle ways at every
/// consumer site (allocation vs. scalar, turbofish vs. name-only,
/// support side vs. coverage-gap side, structural disjunction vs.
/// dual-equality arithmetic). This lift names the singular-file-
/// formats predicate directly at the chain-altitude surface with
/// a single-pass short-circuiting scan — the typed boolean every
/// operator-facing *"did the chain land one file-format cell off
/// the coverage boundary?"* check reads off as a single method
/// call.
///
/// **Lifts sideways to the file-format sub-axis of the chain
/// altitude** in the "singular across altitudes" projection
/// seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_singular`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_singular`], and
/// lifted sideways to the layer-kind sub-axis by
/// [`Self::layer_kinds_singular`]. Middle-leg-corner peer of the
/// eight already-closed coverage-support and magnitude boundary
/// and interior families on the same sub-axis
/// ([`Self::file_formats_balanced`],
/// [`Self::file_formats_full_cover`],
/// [`Self::file_formats_any_observed`],
/// [`Self::file_formats_singular_support`],
/// [`Self::file_formats_singular_gap`],
/// [`Self::file_formats_strict_partial_cover`],
/// [`Self::file_formats_low_support`],
/// [`Self::file_formats_high_support`]). The remaining chain-
/// altitude sub-axis is the natural next sideways lift:
/// `env_prefix_kinds_singular` over
/// [`Self::env_prefix_kind_histogram`] (cardinality-`2`, where
/// the dual-singular-collapse fires and both singular boundaries
/// coincide with the two-cell cover), closing the "singular
/// across altitudes" projection across the same 5-column altitude
/// / sub-axis grid the prior coverage-support predicate rows
/// already carry.
///
/// **Cardinality-`4` reachability at the chain file-format sub-
/// axis — non-vacuous strict-interior middle leg.**
/// [`crate::discovery::Format`] carries four cells, so the two
/// singular boundaries sit at support cardinalities `1` and `3`
/// (= `axis_cardinality - 1`), disjoint from each other AND —
/// crucially — from a reachable strict-interior leg (support
/// cardinality `2`, the two-format partial cover fixture). The
/// distance-from-boundary ternary closes strictly *and* non-
/// vacuously on every leg at this sub-axis: a strict advance over
/// the layer-kind sub-axis ([`Self::layer_kinds_singular`]) and
/// the diff altitude ([`crate::ConfigDiff::kinds_singular`]),
/// where the cardinality-`3` axis renders the strict-interior leg
/// unreachable and the ternary degenerates to the dual partition
/// `(has_boundary, has_singular)`. Matches the tier altitude
/// ([`crate::tiered::ConfigTierKind`] cardinality `4`) as the
/// second reachable strict-interior peer in this projection —
/// the singular near-boundary corner reduces here to the tighter
/// `file_formats_singular ⇔ (file_formats_any_observed &&
/// !file_formats_full_cover && !file_formats_strict_partial_cover)`
/// form, matching the tier altitude's tightened equivalence and
/// diverging from the layer-kind sub-axis's degenerate reduction
/// `layer_kinds_singular ⇔ (layer_kinds_any_observed &&
/// !layer_kinds_full_cover)`.
///
/// **Empty-chain convention** — returns `false` on the empty
/// chain: zero observed cells satisfy neither the `nonzeros == 1`
/// nor the `zeros == 1` clause on the cardinality-`4` axis (four
/// zeros, zero nonzeros). Matches
/// [`crate::AxisHistogram::has_singular`]'s empty-histogram
/// `false` convention one altitude down for every cardinality-
/// `>= 2` axis. The empty chain sits on the disjoint bottom
/// coverage boundary of the distance-from-boundary ternary
/// partition, carried by `has_boundary` (via
/// `!file_formats_any_observed`) instead.
///
/// **No-recognized-files convention** — returns `false` on every
/// non-empty chain whose file-format histogram is empty (chains
/// of only [`ConfigSource::Defaults`] / [`ConfigSource::Env`] /
/// unrecognized-extension [`ConfigSource::File`] layers). The
/// histogram is empty even though the chain is not, so neither
/// singular boundary fires. Cross-sub-axis divergence from
/// [`Self::layer_kinds_singular`]: the singular near-boundary
/// corner does NOT open on the empty-histogram non-empty-chain
/// fixtures at the file-format sub-axis — matching
/// [`Self::file_formats_any_observed`]'s empty-histogram `false`
/// polarity through subsumption and diverging from the layer-
/// kind sub-axis peer where a chain of only `Defaults` observes
/// one layer-kind cell and lands on
/// `layer_kinds_singular_support ⇒ layer_kinds_singular = true`.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single
/// [`crate::discovery::Format`] cell: the support cardinality is
/// `1` (three unobserved cells on the cardinality-`4` axis), so
/// `file_formats_singular_support` fires and the disjunction
/// holds via that disjunct. Every chain whose recognized-
/// extension file layers all attribute to only-`Yaml`, only-
/// `Toml`, only-`Lisp`, or only-`Nix` is a witness on the
/// `true` side. Direct witness of the subsumption
/// `file_formats_singular_support ⇒ file_formats_singular` on
/// every axis with cardinality `>= 2`.
///
/// **Two-format partial cover convention (the strict-interior
/// witness)** — returns `false` on every chain whose observed
/// support is exactly two [`crate::discovery::Format`] cells:
/// support cardinality `2` on the cardinality-`4` axis lands in
/// the strict interior `[2, cardinality - 2] = [2, 2]`,
/// satisfying neither `nonzeros == 1` nor `zeros == 1`. Direct
/// witness of the *non-vacuous* strict disjointness
/// `file_formats_strict_partial_cover ⇒
/// !file_formats_singular` on the cardinality-`4`
/// [`crate::discovery::Format`] axis — a strict advance over the
/// cardinality-`3` layer-kind sub-axis where the same
/// disjointness holds vacuously (the strict interior is
/// unreachable). Matches the tier altitude's non-vacuous witness
/// on the cardinality-`4` [`crate::tiered::ConfigTierKind`] axis
/// (the two-tier partial cover fixture) — the file-format sub-
/// axis is the second reachable strict-interior peer in the
/// "singular across altitudes" projection, exercising both sides
/// of the strict disjointness on the same fixture. Distinguishes
/// the file-format sub-axis from the layer-kind sub-axis where
/// two-kind partial cover (support size `2` on the cardinality-
/// `3` axis) falls at the singleton-gap boundary and lands on
/// `layer_kinds_singular = true` via the singleton-gap disjunct.
///
/// **Three-format partial cover convention** — returns `true` on
/// every chain whose observed support is exactly three
/// [`crate::discovery::Format`] cells: support cardinality `3`
/// on the cardinality-`4` axis leaves exactly one unobserved
/// cell — `file_formats_singular_gap` fires and the disjunction
/// holds via that disjunct. Direct witness of the subsumption
/// `file_formats_singular_gap ⇒ file_formats_singular` on every
/// axis via the singleton-gap disjunct of the defining union.
///
/// **Uniform four-format cover convention** — returns `false` on
/// every chain where each [`crate::discovery::Format`] cell was
/// observed at least once: the support cardinality is `4` (no
/// unobserved cells on the cardinality-`4` axis) —
/// `file_formats_singular_gap` fails (`zeros == 0 ≠ 1`) and
/// `file_formats_singular_support` fails (`nonzeros == 4 ≠ 1`).
/// The full-cover boundary sits at the top of the coverage
/// interval, one of the two boundary corners carried by
/// `has_boundary` (via `file_formats_full_cover`) in the distance
/// ternary — disjoint from the singular near-boundary corner.
///
/// # Invariants
///
/// - `file_formats_singular() ==
/// file_format_histogram().has_singular()` — both project the
/// same predicate off the same primitive; the named seam is
/// the cube-native routing of the histogram surface.
/// - `file_formats_singular() ⇔ file_formats_singular_support()
/// || file_formats_singular_gap()` — the defining union-of-
/// singular-boundaries disjunction on the two named histogram-
/// side peers. The singular near-boundary corner folds the two
/// singular-cardinality boundaries into one named one-cell-off-
/// boundary corner without discarding the finer resolution
/// below.
/// - `file_formats_singular() ⇔ (file_formats_any_observed() &&
/// !file_formats_full_cover() &&
/// !file_formats_strict_partial_cover())` on the cardinality-
/// `4` file-format axis — the partial-cover-minus-strict-
/// interior form tightened by the non-vacuous strict-interior
/// excision. Matches the tier altitude's tightened equivalence
/// `tiers_singular ⇔ (tiers_any_observed && !tiers_full_cover
/// && !tiers_strict_partial_cover)` on the same cardinality-
/// `4` `ConfigTierKind` axis and diverges from the layer-kind
/// sub-axis where the strict-interior slice is vacuously empty
/// and the equivalence loosens to
/// `(layer_kinds_any_observed && !layer_kinds_full_cover)`
/// with no strict-interior excision needed.
/// - `file_formats_singular() == (present_file_formats_count()
/// == 1 || present_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>() - 1)`
/// always — the support-scalar dual-equality surface, without
/// allocating either `Vec<crate::discovery::Format>`. On the
/// cardinality-`4` file-format axis the two equalities are
/// disjoint (`1 ≠ 3 = cardinality - 1`) and the disjunction
/// reads the true dual.
/// - `file_formats_singular() == (present_file_formats_count()
/// == 1 || absent_file_formats_count() == 1)` always — the
/// dual-scalar equality form on the two named cardinality
/// peers, the `present + absent == axis_cardinality`
/// invariant restated. Peer of the histogram-side dual-scalar
/// equality form `hist.distinct_cells() == 1 ||
/// hist.unobserved_cells() == 1` pinned one altitude down.
/// - `file_formats_singular_support() ⇒ file_formats_singular()`
/// always — the subsumption via the
/// `file_formats_singular_support` disjunct of the defining
/// union. The singleton-support boundary always sits inside
/// the singular near-boundary corner.
/// - `file_formats_singular_gap() ⇒ file_formats_singular()`
/// always — the subsumption via the `file_formats_singular_gap`
/// disjunct of the defining union. The singleton-gap boundary
/// always sits inside the singular near-boundary corner.
/// - `file_formats_singular() ⇒ file_formats_any_observed()` on
/// every axis with cardinality `>= 2`: both disjuncts require
/// at least one observed cell (`singular_support` has nonzeros
/// `>= 1`; `singular_gap` has nonzeros `= cardinality - 1 >=
/// 1`). Empty-chain and empty-histogram subsumption on the
/// bottom coverage boundary.
/// - `file_formats_singular() ⇒ !file_formats_full_cover()` on
/// every axis with cardinality `>= 2`:
/// `file_formats_singular_support` has support `1 <
/// cardinality`, `file_formats_singular_gap` has support
/// `cardinality - 1 < cardinality`. Full-cover disjointness on
/// the top coverage boundary.
/// - `file_formats_singular() ⇒
/// !file_formats_strict_partial_cover()` always — the two
/// named corners of the distance-from-boundary ternary are
/// pairwise disjoint. On the cardinality-`4`
/// [`crate::discovery::Format`] axis this is *non-vacuous* —
/// the two-format partial-cover fixture reads
/// `strict_partial_cover=true, singular=false`, exercising
/// both sides of the strict disjointness on the same fixture.
/// Strict advance over the vacuously-`true` peer at the
/// cardinality-`3` layer-kind sub-axis and matching the non-
/// vacuous peer at the cardinality-`4` tier altitude. Peer of
/// the histogram-side
/// `axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor`
/// partition law one altitude down.
/// - `(!file_formats_any_observed() || file_formats_full_cover(),
/// file_formats_singular, file_formats_strict_partial_cover)`
/// is a strict ternary partition on every axis with
/// cardinality `>= 2`. On the cardinality-`4` file-format
/// axis every leg is inhabited — the ternary closes non-
/// vacuously (empty and uniform four-format cover on the
/// boundary leg, singleton support and three-format cover on
/// the singular leg, two-format partial cover on the strict-
/// interior middle leg). Strict advance over the layer-kind
/// sub-axis where the third leg vanishes and the ternary
/// degenerates to the dual pointwise, matching the tier
/// altitude's non-vacuous three-leg partition.
/// - **Cross-surface bridge law** —
/// `chain.file_formats_singular() ==
/// chain.file_format_histogram().support_cardinality_class().is_singular()`
/// always. The class-side projection lands on
/// [`crate::SupportCardinalityClass::SingularSupport`] or
/// [`crate::SupportCardinalityClass::SingularGap`] exactly
/// when the histogram-side disjunction fires, and
/// [`crate::SupportCardinalityClass::is_singular`] reads
/// `true` on either variant. Peer of the histogram-side
/// bridge
/// `axis_histogram_has_singular_agrees_with_class_is_singular_for_every_closed_axis_implementor`
/// one altitude down, closing the (histogram, class) duality
/// on the singular near-boundary leg at the chain file-format
/// sub-axis.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the singular scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits
/// the *moment* both a *second* zero count *and* a *second*
/// nonzero count have been witnessed (bounded at four witness
/// cells visited on any strict-interior histogram — reachable
/// on the cardinality-`4` file-format axis), strictly tighter
/// than the four documented open-coded surfaces — no boolean
/// disjunction across two named predicates with two full walks
/// of the counts vector, no [`crate::axis_cardinality`]
/// turbofish with `- 1` arithmetic against a magic threshold,
/// no `Vec<crate::discovery::Format>` allocation.
#[must_use]
fn file_formats_singular(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().has_singular()
}
/// `true` exactly when this chain's observed
/// [`crate::discovery::Format`] support sits on a *coverage boundary*
/// — either every file-format cell unobserved
/// ([`Self::file_formats_any_observed`] `== false`) or every file-
/// format cell observed at least once
/// ([`Self::file_formats_full_cover`] `== true`).
///
/// The **boundary-file-formats boolean predicate** on the file-
/// format sub-axis of the chain altitude, the top-leg corner of
/// the distance-from-boundary ternary partition `(has_boundary,
/// has_singular, has_strict_partial_cover)` — folding the two
/// extreme coverage-cardinality corners (support cardinality `0`
/// and `axis_cardinality`) into a single named on-boundary corner
/// without discarding the finer resolution below. Routes through
/// [`Self::file_format_histogram`]`::has_boundary`, the single-pass
/// short-circuiting scan over the fixed-cardinality counts vector
/// that returns `false` the moment both a zero cell *and* a
/// nonzero cell have been witnessed, bounded at two witness cells
/// — strictly tighter than any of the documented open-coded
/// surfaces one seam over.
///
/// The **boundary-file-formats peer** of the two documented surface
/// forms consumers previously re-derived inline:
/// `!chain.file_formats_any_observed() ||
/// chain.file_formats_full_cover()` (the defining union-of-coverage-
/// boundaries disjunction on the two named histogram-side peers —
/// one negation and two method calls with a boolean or), and
/// `chain.present_file_formats_count() == 0 ||
/// chain.present_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>()` (the
/// support-scalar dual-equality form, which pays for a full-axis
/// scan and equates a `usize` against two magic thresholds with a
/// turbofish). This lift names the boundary-file-formats predicate
/// directly at the chain-altitude surface with a single-pass
/// short-circuiting scan — the typed boolean every operator-facing
/// *"did the chain land on a file-format coverage boundary?"*
/// check reads off as a single method call.
///
/// The chain-altitude file-format sub-axis boundary-predicate peer
/// that **lifts the "boundary across altitudes" projection
/// sideways** from the layer-kind sub-axis
/// ([`Self::layer_kinds_boundary`]) to the second chain-altitude
/// sub-axis, matching the tier-altitude climb
/// ([`crate::ProvenanceMap::tiers_boundary`]) and the diff-altitude
/// seed ([`crate::ConfigDiff::kinds_boundary`]). The remaining
/// chain-altitude sub-axis ([`Self::env_prefix_kinds_boundary`]
/// over [`Self::env_prefix_kind_histogram`]) is the natural next
/// sideways lift. The pattern is the same at every altitude /
/// sub-axis: fuse the documented open-coded surface forms into a
/// single boolean predicate named at the surface, routed through
/// the shared [`crate::AxisHistogram::has_boundary`] primitive one
/// altitude down.
///
/// **Cardinality-`4` reachability at the file-format sub-axis —
/// non-vacuous witnesses on every distance-ternary leg.**
/// [`crate::discovery::Format`] carries four cells so
/// `file_formats_boundary()` reads `true` on the empty chain (four
/// unobserved cells — empty disjunct), on every no-recognized-
/// files chain whose histogram is empty (same empty disjunct even
/// though the chain itself is non-empty — the file-format
/// projection is a partial function unlike the layer-kind
/// projection), and on every uniform four-format cover (four
/// observed cells — full-cover disjunct), and `false` on every
/// singleton-support chain (support cardinality `1` — one nonzero
/// and three zeros mixed), every two-format partial cover (support
/// cardinality `2` — two nonzeros and two zeros mixed, the strict-
/// interior of the cardinality-`4` axis where `[2, cardinality -
/// 2] = [2, 2]` is a singleton), and every three-format partial
/// cover (support cardinality `3` — three nonzeros and one zero
/// mixed, the singleton-gap boundary). The strict-interior middle
/// leg [`Self::file_formats_strict_partial_cover`] is *reachable*
/// on the cardinality-`4` axis (the two-format partial cover is
/// the unique strict-interior witness), so the distance ternary
/// closes strictly *and* non-vacuously on every leg — matching
/// the tier-altitude peer's non-vacuous three-leg partition on
/// the cardinality-`4` `ConfigTierKind` axis and diverging from
/// the layer-kind sub-axis and the diff altitude where the
/// strict-interior leg is vacuously empty and the ternary
/// degenerates pointwise to the dual `(has_boundary,
/// has_singular)` partition.
///
/// **Empty-chain convention** — returns `true` on the empty chain:
/// the empty chain observes zero cells, so every cell is
/// unobserved (four zeros on the cardinality-`4` axis) — the
/// single-pass scan sees no nonzero cell and falls through to
/// `true`. Matches [`crate::AxisHistogram::has_boundary`]'s empty-
/// histogram `true` convention one altitude down. The empty chain
/// sits on the bottom coverage boundary via the
/// [`Self::file_formats_any_observed`]-negation disjunct. Peer of
/// [`Self::layer_kinds_boundary`]'s empty-chain `true` polarity
/// one sub-axis over on the same chain altitude, of
/// [`crate::ProvenanceMap::tiers_boundary`]'s empty-map `true`
/// polarity, and of [`crate::ConfigDiff::kinds_boundary`]'s empty-
/// diff `true` polarity in the same projection.
///
/// **No-recognized-files convention** — returns `true` on every
/// non-empty chain whose file-format histogram is empty (only
/// `Defaults`, `Env`, and unrecognized-extension `File` layers).
/// The file-format projection is a partial function
/// ([`ConfigSource::file_format`] returns [`None`] for the
/// unrecognized cases), so a non-empty chain can still project to
/// an empty histogram — the single-pass scan sees no nonzero cell
/// and falls through to `true`. This is the boundary-side
/// cross-sub-axis divergence pin against
/// [`Self::layer_kinds_boundary`]: on the same fixtures the
/// layer-kind sub-axis observes at least one layer-kind cell
/// (Defaults / Env / File) so the boundary corner reads `false`
/// on the no-recognized-files chain that has cover between `1`
/// and `axis_cardinality`, while the file-format sub-axis's
/// narrower boundary corner still fires via the empty-histogram
/// disjunct.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed file-format support is a single
/// [`crate::discovery::Format`] cell: the support cardinality is
/// `1` (one nonzero and three zeros on the cardinality-`4` axis),
/// so the single-pass scan sees a nonzero cell *and* a zero cell
/// and returns `false`. `sample_chain()` (two `.yaml` file layers
/// alongside one Env layer, `{Yaml}` file-format support) is a
/// witness on the `false` side.
///
/// **Two-format partial cover convention** — returns `false` on
/// every chain whose observed file-format support is exactly two
/// [`crate::discovery::Format`] cells: the support cardinality is
/// `2` (two nonzeros and two zeros on the cardinality-`4` axis),
/// so the single-pass scan sees both a nonzero and a zero cell
/// and returns `false`. A chain with a `.yaml` + a `.toml` file
/// layer is the strict-interior witness (the two-format partial
/// cover fixture).
///
/// **Three-format partial cover convention** — returns `false` on
/// every chain whose observed file-format support is exactly
/// three [`crate::discovery::Format`] cells: the support
/// cardinality is `3` (three nonzeros and one zero on the
/// cardinality-`4` axis), so the single-pass scan sees both a
/// nonzero and a zero cell and returns `false`. A chain with
/// `.yaml + .toml + .lisp` file layers is a witness on the
/// `false` side — sitting on the disjoint
/// [`Self::file_formats_singular_gap`] boundary carried by
/// [`Self::file_formats_singular`] in the distance ternary.
///
/// **Uniform four-format cover convention** — returns `true` on
/// every chain where each [`crate::discovery::Format`] cell was
/// observed at least once: the support cardinality is `4` (no
/// unobserved cells on the cardinality-`4` axis), so the single-
/// pass scan sees only nonzero cells and falls through to `true`.
/// The full-cover boundary sits at the top of the coverage
/// interval via the [`Self::file_formats_full_cover`] disjunct.
///
/// # Invariants
///
/// - `file_formats_boundary() == file_format_histogram().has_boundary()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram surface.
/// - `file_formats_boundary() ⇔ !file_formats_any_observed() ||
/// file_formats_full_cover()` — the defining union-of-coverage-
/// boundaries disjunction on the two named coverage-boundary
/// peers.
/// - `file_formats_boundary() == (present_file_formats_count() ==
/// 0 || present_file_formats_count() ==
/// crate::axis_cardinality::<crate::discovery::Format>())` always
/// — the support-scalar dual-equality surface, without
/// allocating `Vec<crate::discovery::Format>`. The two
/// equalities are strictly disjoint (`0 != 4 = cardinality` on
/// the file-format axis).
/// - `file_formats_boundary() == (present_file_formats_count() ==
/// 0 || absent_file_formats_count() == 0)` always — the dual-
/// scalar equality form on the two named cardinality peers, the
/// `present + absent == axis_cardinality` invariant restated.
/// - `!file_formats_any_observed() ⇒ file_formats_boundary()`
/// always — the empty chain and every no-recognized-files chain
/// sit on the boundary via the bottom disjunct.
/// - `file_formats_full_cover() ⇒ file_formats_boundary()` always
/// — the full-cover chain sits on the boundary via the top
/// disjunct.
/// - `file_formats_boundary() ⇒ !file_formats_singular()` on
/// every axis with cardinality `>= 2`: the two boundary
/// cardinalities sit strictly outside the two singular
/// cardinalities.
/// - `file_formats_boundary() ⇒
/// !file_formats_strict_partial_cover()` always. *Non-vacuous*
/// on the cardinality-`4` file-format axis (the two-format
/// partial cover fixture is the strict-interior witness reading
/// `strict_partial_cover=true, boundary=false`), a strict
/// advance over the layer-kind sub-axis where the strict
/// interior is unreachable and the disjointness holds vacuously.
/// - `(file_formats_boundary, file_formats_singular,
/// file_formats_strict_partial_cover)` is a strict ternary
/// partition on every axis with cardinality `>= 2`. Every leg
/// is inhabited on the cardinality-`4` file-format axis — the
/// ternary closes strictly *and* non-vacuously, matching the
/// tier altitude's non-vacuous partition on `ConfigTierKind`
/// and diverging from the layer-kind sub-axis's degenerate
/// two-way partition on `ConfigSourceKind`.
/// - **Cross-surface bridge law** — `chain.file_formats_boundary() ==
/// chain.file_format_histogram().support_cardinality_class().is_boundary()`
/// always. Peer of the histogram-side bridge
/// `axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor`
/// one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the boundary scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate. The scan returns `false`
/// the *moment* a mixed-parity witness (one zero *and* one
/// nonzero) has been seen — bounded at two witness cells visited
/// — strictly tighter than the documented open-coded surfaces.
#[must_use]
fn file_formats_boundary(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().has_boundary()
}
/// `true` exactly when this chain's observed
/// [`crate::discovery::Format`] support sits *strictly between* the
/// two coverage boundaries — at least one file-format cell observed
/// ([`Self::file_formats_any_observed`] `== true`) *and* at least
/// one file-format cell unobserved ([`Self::file_formats_full_cover`]
/// `== false`).
///
/// The **partial-cover-file-formats boolean predicate** on the
/// file-format sub-axis of the chain altitude, the *middle* leg of
/// the coverage trichotomy `(!file_formats_any_observed,
/// file_formats_partial_cover, file_formats_full_cover)` — the
/// direct strict-complement of the top-leg
/// [`Self::file_formats_boundary`] corner, folding both singular
/// near-boundary corners *and* the strict interior into a single
/// "some but not all" corner without discarding the finer resolution
/// below. Routes through
/// [`Self::file_format_histogram`]`::has_partial_cover`, the single-
/// pass short-circuiting scan over the fixed-cardinality counts
/// vector that returns `true` the moment both a zero cell *and* a
/// nonzero cell have been witnessed, bounded at two witness cells
/// — strictly tighter than any of the documented open-coded
/// surfaces one seam over.
///
/// The **partial-cover-file-formats peer** of the documented surface
/// forms consumers previously re-derived inline:
/// `chain.file_formats_any_observed() &&
/// !chain.file_formats_full_cover()` (the defining conjunction-of-
/// negations form on the two named coverage-boundary peers — two
/// method calls with a boolean and — the exact expression used
/// verbatim by the pre-existing bipartition-law pin
/// [`tests::file_formats_boundary_and_file_formats_partial_cover_form_strict_bipartition_pointwise`]),
/// `0 < chain.present_file_formats_count() &&
/// chain.present_file_formats_count() <
/// crate::axis_cardinality::<crate::discovery::Format>()` (the
/// support-scalar strict-interval form, which pays for a full-axis
/// scan and brackets a `usize` between two magic thresholds with a
/// turbofish), and `chain.present_file_formats_count() > 0 &&
/// chain.absent_file_formats_count() > 0` (the dual-scalar mixed-
/// side non-emptiness form on the two named cardinality peers).
/// This lift names the partial-cover-file-formats predicate
/// directly at the chain-altitude surface with a single-pass
/// short-circuiting scan — the typed boolean every operator-facing
/// *"did the chain see some but not all file formats?"* check reads
/// off as a single method call.
///
/// The chain-altitude file-format sub-axis partial-cover-predicate
/// peer that **lifts the "partial-cover across altitudes"
/// projection sideways** from the layer-kind sub-axis
/// ([`Self::layer_kinds_partial_cover`]) to the second chain-
/// altitude sub-axis, matching the tier-altitude climb
/// ([`crate::ProvenanceMap::tiers_partial_cover`]) and the diff-
/// altitude seed ([`crate::ConfigDiff::kinds_partial_cover`]). The
/// remaining chain-altitude sub-axis
/// ([`Self::env_prefix_kinds_partial_cover`] over
/// [`Self::env_prefix_kind_histogram`]) is the natural next
/// sideways lift. The pattern is the same at every altitude /
/// sub-axis: fuse the documented open-coded surface forms into a
/// single boolean predicate named at the surface, routed through
/// the shared [`crate::AxisHistogram::has_partial_cover`] primitive
/// one altitude down.
///
/// **Cardinality-`4` reachability at the file-format sub-axis —
/// non-vacuous witnesses on every distance-ternary leg.**
/// [`crate::discovery::Format`] carries four cells so
/// `file_formats_partial_cover()` reads `true` on every singleton-
/// support chain (support cardinality `1` — one nonzero and three
/// zeros mixed), every two-format partial cover (support cardinality
/// `2` — two nonzeros and two zeros mixed, exactly the strict-
/// interior of the cardinality-`4` axis where `[2, cardinality -
/// 2] = [2, 2]` is a singleton), and every three-format partial
/// cover (support cardinality `3` — three nonzeros and one zero
/// mixed, the singleton-gap boundary), and `false` on the empty
/// chain (four unobserved cells — no nonzero witness), on every
/// no-recognized-files non-empty chain (four unobserved cells via
/// the partial-function projection — no nonzero witness), and on
/// every uniform four-format cover (four observed cells — no zero
/// witness). The strict-interior middle leg
/// [`Self::file_formats_strict_partial_cover`] is *reachable* on
/// the cardinality-`4` axis (the two-format partial cover is the
/// unique strict-interior witness), so the non-vacuous subsumption
/// `file_formats_strict_partial_cover ⇒ file_formats_partial_cover`
/// carries content on the strict-interior leg — matching the tier-
/// altitude peer on the cardinality-`4` `ConfigTierKind` axis and
/// diverging from the layer-kind sub-axis and the diff altitude
/// where the strict-interior antecedent is vacuous and the same
/// subsumption holds only trivially.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain observes zero cells, so every cell is
/// unobserved (four zeros on the cardinality-`4` axis) — the
/// single-pass scan sees no nonzero cell and falls through to
/// `false`. Matches [`crate::AxisHistogram::has_partial_cover`]'s
/// empty-histogram `false` convention one altitude down. The empty
/// chain sits strictly outside the partial-cover middle leg via
/// the [`Self::file_formats_any_observed`]-negation half of the
/// defining conjunction. Peer of
/// [`Self::layer_kinds_partial_cover`]'s empty-chain `false`
/// polarity one sub-axis over on the same chain altitude, of
/// [`crate::ProvenanceMap::tiers_partial_cover`]'s empty-map
/// `false` polarity, and of
/// [`crate::ConfigDiff::kinds_partial_cover`]'s empty-diff `false`
/// polarity in the same projection.
///
/// **No-recognized-files convention** — returns `false` on every
/// non-empty chain whose file-format histogram is empty (only
/// `Defaults`, `Env`, and unrecognized-extension `File` layers).
/// The file-format projection is a partial function
/// ([`ConfigSource::file_format`] returns [`None`] for the
/// unrecognized cases), so a non-empty chain can still project to
/// an empty histogram — the single-pass scan sees no nonzero cell
/// and falls through to `false`. This is the partial-cover-side
/// cross-sub-axis divergence pin against
/// [`Self::layer_kinds_partial_cover`]: on the same fixtures the
/// layer-kind sub-axis observes at least one layer-kind cell
/// (Defaults / Env / File) at partial support and typically reads
/// `layer_kinds_partial_cover = true`, while the file-format sub-
/// axis's partial-cover middle leg silently drops out via the
/// empty-histogram disjunct of the strict-complement
/// [`Self::file_formats_boundary`] corner. Every no-recognized-
/// files chain sits on `file_formats_boundary = true`, so the
/// bipartition still holds — but the partial-cover leg's meaning
/// is *narrower* at the file-format sub-axis than at the layer-
/// kind sub-axis.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed file-format support is a single
/// [`crate::discovery::Format`] cell: the support cardinality is
/// `1` (one nonzero and three zeros on the cardinality-`4` axis),
/// so the single-pass scan sees a nonzero cell *and* a zero cell
/// and returns `true`. Direct witness of the subsumption
/// `file_formats_singular_support ⇒ file_formats_partial_cover`
/// via the mixed-parity witness — `sample_chain()` (two `.yaml`
/// file layers alongside one Env layer, `{Yaml}` file-format
/// support) is a witness on the `true` side.
///
/// **Two-format partial cover convention** — returns `true` on
/// every chain whose observed file-format support is exactly two
/// [`crate::discovery::Format`] cells: the support cardinality is
/// `2` (two nonzeros and two zeros on the cardinality-`4` axis),
/// exactly the strict interior of the cardinality-`4` axis where
/// `[2, cardinality - 2] = [2, 2]` is a singleton — the single-
/// pass scan sees both a nonzero and a zero cell and returns
/// `true`. Direct *non-vacuous* witness of the subsumption
/// `file_formats_strict_partial_cover ⇒ file_formats_partial_cover`
/// unavailable at the cardinality-`3` layer-kind sub-axis where
/// the strict interior is vacuous. A chain with a `.yaml` + a
/// `.toml` file layer is the strict-interior witness on the `true`
/// side.
///
/// **Three-format partial cover convention** — returns `true` on
/// every chain whose observed file-format support is exactly
/// three [`crate::discovery::Format`] cells: the support
/// cardinality is `3` (three nonzeros and one zero on the
/// cardinality-`4` axis), exactly the singleton-gap boundary —
/// the single-pass scan sees both a nonzero and a zero cell and
/// returns `true`. Direct witness of the subsumption
/// `file_formats_singular_gap ⇒ file_formats_partial_cover` via
/// the mixed-parity witness — sitting on the
/// [`Self::file_formats_singular_gap`] boundary carried by
/// [`Self::file_formats_singular`] in the distance ternary. A
/// chain with `.yaml + .toml + .lisp` file layers is a witness on
/// the `true` side.
///
/// **Uniform four-format cover convention** — returns `false` on
/// every chain where each [`crate::discovery::Format`] cell was
/// observed at least once: the support cardinality is `4` (no
/// unobserved cells on the cardinality-`4` axis), so the single-
/// pass scan sees only nonzero cells and falls through to `false`.
/// The full-cover boundary sits strictly above the partial-cover
/// middle leg via the [`Self::file_formats_full_cover`]-negation
/// half of the defining conjunction.
///
/// # Invariants
///
/// - `file_formats_partial_cover() == file_format_histogram().has_partial_cover()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram surface.
/// - `file_formats_partial_cover() ⇔ file_formats_any_observed() &&
/// !file_formats_full_cover()` — the defining conjunction-of-
/// negations form on the two named coverage-boundary peers.
/// - `file_formats_partial_cover() == (0 < present_file_formats_count()
/// && present_file_formats_count() <
/// crate::axis_cardinality::<crate::discovery::Format>())` always
/// — the support-scalar strict-interval surface, without
/// allocating `Vec<crate::discovery::Format>`.
/// - `file_formats_partial_cover() == (0 < absent_file_formats_count()
/// && absent_file_formats_count() <
/// crate::axis_cardinality::<crate::discovery::Format>())` always
/// — the coverage-gap dual-scalar strict-interval surface, the
/// `present + absent == axis_cardinality` invariant restated.
/// - `file_formats_partial_cover() == (present_file_formats_count() > 0
/// && absent_file_formats_count() > 0)` always — the mixed-side
/// dual-scalar non-emptiness form, the direct histogram-surface
/// `distinct_cells > 0 && unobserved_cells > 0` pin restated at
/// the chain file-format sub-axis, without allocating either
/// `Vec<crate::discovery::Format>`.
/// - `file_formats_partial_cover() ⇒ file_formats_any_observed()`
/// always — the partial-cover corner requires at least one
/// observed cell.
/// - `file_formats_partial_cover() ⇒ !file_formats_full_cover()`
/// always — the partial-cover corner excludes the top coverage
/// boundary.
/// - `file_formats_singular_support() ⇒ file_formats_partial_cover()`
/// always on cardinality-`>= 2` axes: support cardinality `1`
/// is strictly between `0` and cardinality. Direct pin of the
/// histogram-side subsumption
/// `has_singular_support ⇒ has_partial_cover` one altitude down.
/// - `file_formats_singular_gap() ⇒ file_formats_partial_cover()`
/// always on cardinality-`>= 2` axes: support cardinality
/// `cardinality - 1` is strictly between `0` and cardinality.
/// - `file_formats_singular() ⇒ file_formats_partial_cover()` always
/// on cardinality-`>= 2` axes — the union of the two singular-
/// side subsumptions.
/// - `file_formats_strict_partial_cover() ⇒ file_formats_partial_cover()`
/// always. *Non-vacuous* on the cardinality-`4` file-format axis
/// (the two-format partial cover fixture is the strict-interior
/// witness reading `strict_partial_cover=true,
/// partial_cover=true`), a strict advance over the layer-kind
/// sub-axis where the strict-interior antecedent is unreachable
/// and the subsumption holds vacuously.
/// - `file_formats_partial_cover()` and [`Self::file_formats_boundary`]
/// form a strict bipartition — exactly one fires on every
/// chain. Peer of the histogram-side bipartition law
/// `axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`
/// one altitude down.
/// - **Coverage-trichotomy partition law** —
/// `(!file_formats_any_observed, file_formats_partial_cover,
/// file_formats_full_cover)` is a strict ternary partition on
/// every axis with cardinality `>= 1` (the cardinality-`4`
/// [`crate::discovery::Format`] axis). Exactly one leg fires on
/// every chain — the coverage trichotomy of the `(is_empty,
/// has_partial_cover, is_full_cover)` histogram-side partition
/// restated at the chain file-format sub-axis. Peer of the
/// trait-uniform pin
/// `axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor`
/// one altitude down.
/// - **Cross-surface bridge law** —
/// `chain.file_formats_partial_cover() ==
/// chain.file_format_histogram().support_cardinality_class().is_partial_cover()`
/// always. Peer of the histogram-side bridge
/// `axis_histogram_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover_for_every_closed_axis_implementor`
/// one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the partial-cover scan). Both are `O(n)` in practice since the
/// file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate. The scan returns `true`
/// the *moment* a mixed-parity witness (one zero *and* one
/// nonzero) has been seen — bounded at two witness cells visited
/// on any strict-interior histogram — strictly tighter than the
/// documented open-coded surfaces.
#[must_use]
fn file_formats_partial_cover(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().has_partial_cover()
}
/// `true` exactly when this chain's observed
/// [`crate::discovery::Format`] histogram has two or more cells tied
/// at the peak leaf count — the peak file-format is *shared* rather
/// than uniquely held.
///
/// The **modally-tied-file-formats boolean predicate** on the file-
/// format sub-axis of the chain altitude, the direct strict-complement
/// of [`crate::AxisHistogram::is_strictly_modally_unique`] on every
/// non-empty file-format histogram (both read `false` on the empty
/// histogram — the shared boundary below both branches of the strict
/// modal partition). Routes through
/// [`Self::file_format_histogram`]`::is_modally_tied`, the single-pass
/// scan over the fixed-cardinality counts vector reading
/// `peak_multiplicity() >= 2` off one predicate — strictly tighter
/// than either of the documented open-coded surface forms one seam
/// over.
///
/// The **modally-tied-file-formats peer** of the two documented
/// surface forms consumers previously re-derived inline:
/// `chain.file_format_histogram().peak_multiplicity() >= 2` (the
/// defining multiplicity-scalar inequality form — one method call
/// plus a magic `>= 2` threshold at the consumer site), and
/// `chain.file_format_histogram().modality_degree().0 >= 2` (the
/// modality-pair projection-inequality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison — a fused-pair build for a single-component
/// projection). This lift names the modally-tied-file-formats
/// predicate directly at the chain-altitude surface — the typed
/// boolean every operator-facing *"is the dominant file format
/// uniquely held on this chain, or tied?"* check reads off as a
/// single method call.
///
/// The chain-altitude file-format sub-axis modality-tie-predicate
/// peer that **lifts the "modally-tied across altitudes" projection
/// sideways** from the first chain-altitude sub-axis
/// ([`Self::layer_kinds_modally_tied`]) to the second chain-altitude
/// sub-axis, matching the tier-altitude climb
/// ([`crate::ProvenanceMap::tiers_modally_tied`]) and the diff-
/// altitude seed ([`crate::ConfigDiff::kinds_modally_tied`]). The
/// remaining chain-altitude sub-axis
/// ([`Self::env_prefix_kinds_modally_tied`] over
/// [`Self::env_prefix_kind_histogram`]) is the natural next
/// sideways lift. The pattern is the same at every altitude /
/// sub-axis: fuse the two open-coded surface forms (multiplicity-
/// scalar inequality, modality-pair projection-inequality) into a
/// single boolean predicate named at the surface, routed through
/// the shared [`crate::AxisHistogram::is_modally_tied`] primitive
/// one altitude down.
///
/// **Cardinality-`4` reachability at the file-format sub-axis — the
/// modally-tied corner carries witnesses on all three off-singleton
/// support cardinalities.** [`crate::discovery::Format`] carries
/// four cells, so `file_formats_modally_tied()` reads `true` on
/// every chain whose peak leaf count is shared by two or more
/// observed file-format cells (e.g. one-`.yaml`+one-`.toml` tied at
/// count `1`, three-format uniform partial cover tied at count `1`,
/// or the uniform four-format cover tied at count `1`), and `false`
/// on the empty chain (no observed cell), on every no-recognized-
/// files non-empty chain (empty file-format histogram — no observed
/// cell via the partial-function projection), on every singleton-
/// support chain (support cardinality `1`, peak multiplicity `1`),
/// and on every strictly-modal skewed chain (e.g. two-`.yaml` +
/// one-`.toml` where `Yaml` uniquely peaks at count `2`). Matches
/// the tier-altitude peer on the cardinality-`4` [`crate::ConfigTierKind`]
/// axis in reachability — the additional support-`3` tied witness
/// unavailable at the cardinality-`3` layer-kind sub-axis / diff
/// altitude is *reachable* here, a strict advance over both.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain observes zero cells, so
/// [`crate::AxisHistogram::peak_multiplicity`] reads `0` and the
/// inequality `0 >= 2` fails. Matches
/// [`crate::AxisHistogram::is_modally_tied`]'s empty-histogram
/// convention one altitude down. The empty-chain row on the strict
/// modal partition pair
/// `(is_strictly_modally_unique, is_modally_tied)` reads
/// `(false, false)` — the shared boundary below both branches. Peer
/// of [`Self::layer_kinds_modally_tied`]'s empty-chain `false`
/// polarity one sub-axis over on the same chain altitude, of
/// [`crate::ProvenanceMap::tiers_modally_tied`]'s empty-map `false`
/// polarity, and of [`crate::ConfigDiff::kinds_modally_tied`]'s
/// empty-diff `false` polarity in the same projection.
///
/// **No-recognized-files convention** — returns `false` on every
/// non-empty chain whose file-format histogram is empty (only
/// `Defaults`, `Env`, and unrecognized-extension `File` layers).
/// The file-format projection is a partial function
/// ([`ConfigSource::file_format`] returns [`None`] for the
/// unrecognized cases), so a non-empty chain can still project to
/// an empty histogram — `peak_multiplicity` reads `0` and the
/// inequality `0 >= 2` fails. This is the modal-tie-side cross-sub-
/// axis divergence pin against [`Self::layer_kinds_modally_tied`]:
/// on the same fixtures the layer-kind sub-axis observes at least
/// one layer-kind cell (Defaults / Env / File) and may fire the
/// modally-tied predicate (e.g. one `Defaults` + one `Env` reads
/// `layer_kinds_modally_tied = true`), while the file-format sub-
/// axis's modally-tied predicate silently drops out via the empty-
/// histogram disjunct — the modal-tie leg's meaning is *narrower*
/// at the file-format sub-axis than at the layer-kind sub-axis.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed file-format support is a single
/// [`crate::discovery::Format`] cell: the lone observed cell stands
/// alone at its own peak (no tie-break to exercise), so
/// `peak_multiplicity` reads `1` and the inequality `1 >= 2` fails.
/// The `sample_chain()` fixture (two `.yaml` file layers + one Env
/// layer, `{Yaml}` file-format support with count `2`) is a witness
/// on the `false` side — the singleton-support corner is uniformly
/// on the strictly-modal-unique side of the strict modal partition.
/// Direct pin of the histogram-side subsumption
/// `has_singular_support ⇒ !is_modally_tied` one altitude down.
///
/// **Uniform four-format cover convention** — returns `true` on
/// every chain where each [`crate::discovery::Format`] cell was
/// observed at exactly the same positive count (in particular the
/// chain with one file per format): the four cells share the same
/// count, so `peak_multiplicity` reads `4` and the inequality
/// `4 >= 2` fires. Peer of the histogram-side axis-cover convention
/// one altitude down, which reads `true` on every implementor with
/// `axis_cardinality::<A>() >= 2` — the cardinality-`4`
/// [`crate::discovery::Format`] axis honours the general condition.
///
/// **Two-way modal partition on non-empty file-format histograms**
/// — on every non-empty file-format histogram exactly one of the
/// modal-uniqueness pair fires: either the peak is uniquely held
/// (strictly-modal-unique fires, modally-tied does not) or the peak
/// is shared (modally-tied fires, strictly-modal-unique does not).
/// The empty histogram sits below both branches (both read `false`)
/// — this covers both the empty chain and every no-recognized-files
/// non-empty chain. Direct pin of the histogram-side strict modal
/// partition
/// `!is_empty ⇒ is_modally_tied ⇔ !is_strictly_modally_unique` one
/// altitude down.
///
/// # Invariants
///
/// - `file_formats_modally_tied() == file_format_histogram().is_modally_tied()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `file_formats_modally_tied() ⇔
/// file_format_histogram().peak_multiplicity() >= 2` — the
/// defining multiplicity-scalar inequality form on the
/// [`crate::AxisHistogram::peak_multiplicity`] scalar peer, the
/// canonical open-coded expression of the predicate one altitude
/// down.
/// - `file_formats_modally_tied() ⇔
/// file_format_histogram().modality_degree().0 >= 2` — the
/// modality-pair projection-inequality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison.
/// - `file_formats_modally_tied() ⇒ file_formats_any_observed()`
/// always — a tied peak requires at least two observed cells,
/// so both the empty chain (zero observed cells) and every no-
/// recognized-files non-empty chain (empty file-format histogram
/// via the partial-function projection) cannot fire.
/// Contrapositively, `!file_formats_any_observed() ⇒
/// !file_formats_modally_tied()`.
/// - `file_formats_singular_support() ⇒ !file_formats_modally_tied()`
/// always — a singleton-support chain has exactly one observed
/// cell, so the modal level set has cardinality `1` and the tie
/// predicate fails. Contrapositively, `file_formats_modally_tied()
/// ⇒ !file_formats_singular_support()`: a fired tie predicate
/// means at least two observed cells. Direct pin of the
/// histogram-side subsumption `has_singular_support ⇒
/// !is_modally_tied` one altitude down.
/// - `file_formats_full_cover() ∧ file_formats_balanced() ⇒
/// file_formats_modally_tied()` on the cardinality-`>= 2` axis:
/// a full-cover uniform-count chain has every cell observed at
/// the same count, so the modal level set equals the full axis
/// — the peak multiplicity rises to
/// `axis_cardinality::<crate::discovery::Format>()` which is `4`,
/// and the tie predicate fires. Cardinality-`>= 2` witness of
/// the uniform-cover corner of the histogram-side subsumption
/// tying [`crate::AxisHistogram::is_uniform_count`] and
/// [`crate::AxisHistogram::has_singular_support`] on non-empty
/// histograms one altitude down.
/// - **Strict modal partition on non-empty file-format histograms**
/// — `!file_format_histogram().is_empty() ⇒
/// (file_formats_modally_tied ⇔
/// !file_format_histogram().is_strictly_modally_unique())` always.
/// On every non-empty file-format histogram exactly one of
/// `(file_formats_modally_tied,
/// file_format_histogram().is_strictly_modally_unique())` fires;
/// both read `false` on the empty histogram — the shared
/// boundary below both branches. Direct pin of the histogram-side
/// strict modal partition one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the peak-multiplicity scan). Both are `O(n)` in practice since
/// the file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate — the peak scan walks the
/// counts vector once and counts cells matching the max, then
/// reads `multiplicity >= 2` off one comparison. Strictly tighter
/// than the two documented open-coded surfaces one seam over (no
/// exposed `>= 2` magic threshold at the consumer site, no
/// [`crate::AxisHistogram::modality_degree`] fused-pair build for
/// a single-component projection).
#[must_use]
fn file_formats_modally_tied(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().is_modally_tied()
}
/// `true` exactly when this chain's observed
/// [`crate::discovery::Format`] histogram has two or more cells tied
/// at the trough leaf count — the recessive file-format is *shared*
/// rather than uniquely held.
///
/// The **antimodally-tied-file-formats boolean predicate** on the
/// file-format sub-axis of the chain altitude, the direct strict-
/// complement of [`crate::AxisHistogram::is_strictly_antimodally_unique`]
/// on every non-empty file-format histogram (both read `false` on the
/// empty histogram — the shared boundary below both branches of the
/// strict antimodal partition). Routes through
/// [`Self::file_format_histogram`]`::is_antimodally_tied`, the
/// single-pass scan over the fixed-cardinality counts vector reading
/// `trough_multiplicity() >= 2` off one predicate — strictly tighter
/// than either of the documented open-coded surface forms one seam
/// over.
///
/// The **antimodally-tied-file-formats peer** of the two documented
/// surface forms consumers previously re-derived inline:
/// `chain.file_format_histogram().trough_multiplicity() >= 2` (the
/// defining multiplicity-scalar inequality form — one method call
/// plus a magic `>= 2` threshold at the consumer site), and
/// `chain.file_format_histogram().modality_degree().1 >= 2` (the
/// modality-pair projection-inequality form, reading the antimodal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison — a fused-pair build for a single-component
/// projection). This lift names the antimodally-tied-file-formats
/// predicate directly at the chain-altitude surface — the typed
/// boolean every operator-facing *"is the rarest file format
/// uniquely held on this chain, or is the declaration-order tie-
/// break exercised?"* check reads off as a single method call.
///
/// The chain-altitude file-format sub-axis antimodal-tie-predicate
/// peer that **lifts the "antimodally-tied across altitudes"
/// projection sideways** from the first chain-altitude sub-axis
/// ([`Self::layer_kinds_antimodally_tied`]) to the second chain-
/// altitude sub-axis, matching the tier-altitude climb
/// ([`crate::ProvenanceMap::tiers_antimodally_tied`]) and the diff-
/// altitude seed ([`crate::ConfigDiff::kinds_antimodally_tied`]).
/// Antimodal-side row of the modality classifier pair
/// `(is_modally_tied, is_antimodally_tied)`, complementary to the
/// modally-tied row [`Self::file_formats_modally_tied`] on the same
/// chain file-format sub-axis. The remaining chain-altitude sub-axis
/// ([`Self::env_prefix_kinds_antimodally_tied`] over
/// [`Self::env_prefix_kind_histogram`]) is the natural next sideways
/// lift. The pattern is the same at every altitude / sub-axis: fuse
/// the two open-coded surface forms (multiplicity-scalar inequality,
/// modality-pair projection-inequality) into a single boolean
/// predicate named at the surface, routed through the shared
/// [`crate::AxisHistogram::is_antimodally_tied`] primitive one
/// altitude down.
///
/// **Cardinality-`4` reachability at the file-format sub-axis — the
/// antimodally-tied corner carries witnesses on all three off-
/// singleton support cardinalities.** [`crate::discovery::Format`]
/// carries four cells, so `file_formats_antimodally_tied()` reads
/// `true` on every chain whose trough leaf count is shared by two or
/// more observed file-format cells (e.g. one-`.yaml`+one-`.toml`
/// tied at count `1`, three-format uniform partial cover tied at
/// count `1`, the uniform four-format cover tied at count `1`, or
/// the two-`.yaml`+one-`.toml`+one-`.lisp` mixed-count chain where
/// `Toml` and `Lisp` share the trough at count `1` while `Yaml`
/// uniquely peaks at count `2` — a strictly-modal *and* antimodally-
/// tied witness, unavailable at the cardinality-`3` layer-kind sub-
/// axis), and `false` on the empty chain (no observed cell), on
/// every no-recognized-files non-empty chain (empty file-format
/// histogram via the partial-function projection — no observed
/// cell), on every singleton-support chain (support cardinality `1`,
/// trough multiplicity `1`), and on every strictly-antimodal skewed
/// chain (e.g. two-`.yaml`+one-`.toml` where `Toml` uniquely holds
/// the trough at count `1` while `Yaml` peaks at `2`). Matches the
/// tier-altitude peer on the cardinality-`4` [`crate::ConfigTierKind`]
/// axis in reachability — the additional support-`3` shared-trough
/// witness unavailable at the cardinality-`3` layer-kind sub-axis /
/// diff altitude is *reachable* here, a strict advance over both.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain observes zero cells, so
/// [`crate::AxisHistogram::trough_multiplicity`] reads `0` and the
/// inequality `0 >= 2` fails. Matches
/// [`crate::AxisHistogram::is_antimodally_tied`]'s empty-histogram
/// convention one altitude down. The empty-chain row on the strict
/// antimodal partition pair
/// `(is_strictly_antimodally_unique, is_antimodally_tied)` reads
/// `(false, false)` — the shared boundary below both branches. Peer
/// of [`Self::layer_kinds_antimodally_tied`]'s empty-chain `false`
/// polarity one sub-axis over on the same chain altitude, of
/// [`crate::ProvenanceMap::tiers_antimodally_tied`]'s empty-map
/// `false` polarity, and of [`crate::ConfigDiff::kinds_antimodally_tied`]'s
/// empty-diff `false` polarity in the same projection.
///
/// **No-recognized-files convention** — returns `false` on every
/// non-empty chain whose file-format histogram is empty (only
/// `Defaults`, `Env`, and unrecognized-extension `File` layers).
/// The file-format projection is a partial function
/// ([`ConfigSource::file_format`] returns [`None`] for the
/// unrecognized cases), so a non-empty chain can still project to an
/// empty histogram — `trough_multiplicity` reads `0` and the
/// inequality `0 >= 2` fails. This is the antimodal-tie-side cross-
/// sub-axis divergence pin against
/// [`Self::layer_kinds_antimodally_tied`]: on the same fixtures the
/// layer-kind sub-axis observes at least one layer-kind cell
/// (Defaults / Env / File) and may fire the antimodal-tie predicate
/// (e.g. one `Defaults` + one `Env` reads
/// `layer_kinds_antimodally_tied = true`), while the file-format
/// sub-axis's antimodal-tie predicate silently drops out via the
/// empty-histogram disjunct — the antimodal-tie leg's meaning is
/// *narrower* at the file-format sub-axis than at the layer-kind
/// sub-axis, matching the same narrowing pinned at the modal-tie
/// row [`Self::file_formats_modally_tied`].
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed file-format support is a single
/// [`crate::discovery::Format`] cell: the lone observed cell stands
/// alone at its own trough (peak and trough coincide, no tie-break
/// to exercise), so `trough_multiplicity` reads `1` and the
/// inequality `1 >= 2` fails. The `sample_chain()` fixture (two
/// `.yaml` file layers + one Env layer, `{Yaml}` file-format support
/// with count `2`) is a witness on the `false` side — the singleton-
/// support corner is uniformly on the strictly-antimodal-unique
/// side of the strict antimodal partition. Direct pin of the
/// histogram-side subsumption `has_singular_support ⇒
/// !is_antimodally_tied` one altitude down.
///
/// **Uniform four-format cover convention** — returns `true` on
/// every chain where each [`crate::discovery::Format`] cell was
/// observed at exactly the same positive count (in particular the
/// chain with one file per format): the four cells share the same
/// count, so `trough_multiplicity` reads `4` and the inequality
/// `4 >= 2` fires. Peer of the histogram-side axis-cover convention
/// one altitude down, which reads `true` on every implementor with
/// `axis_cardinality::<A>() >= 2` — the cardinality-`4`
/// [`crate::discovery::Format`] axis honours the general condition.
///
/// **Two-way antimodal partition on non-empty file-format
/// histograms** — on every non-empty file-format histogram exactly
/// one of the antimodal-uniqueness pair fires: either the trough is
/// uniquely held (strictly-antimodal-unique fires, antimodally-tied
/// does not) or the trough is shared (antimodally-tied fires,
/// strictly-antimodal-unique does not). The empty histogram sits
/// below both branches (both read `false`) — this covers both the
/// empty chain and every no-recognized-files non-empty chain.
/// Direct pin of the histogram-side strict antimodal partition
/// `!is_empty ⇒ is_antimodally_tied ⇔
/// !is_strictly_antimodally_unique` one altitude down.
///
/// **Modal / antimodal collapse on uniform-count non-empty file-
/// format histograms** — on every uniform-count non-empty file-
/// format histogram the modal and antimodal level sets coincide
/// with the support, so `file_formats_antimodally_tied ⇔
/// file_formats_modally_tied` — the classifier pair collapses to a
/// single boolean, the multi-cell-support witness. Direct pin of
/// the histogram-side collapse law `is_uniform_count ∧ !is_empty ⇒
/// is_antimodally_tied ⇔ is_modally_tied` one altitude down, peer of
/// the same collapse pinned at the diff altitude by
/// [`crate::ConfigDiff::kinds_antimodally_tied`], at the tier
/// altitude by [`crate::ProvenanceMap::tiers_antimodally_tied`], and
/// at the chain layer-kind sub-axis by
/// [`Self::layer_kinds_antimodally_tied`].
///
/// # Invariants
///
/// - `file_formats_antimodally_tied() == file_format_histogram().is_antimodally_tied()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `file_formats_antimodally_tied() ⇔
/// file_format_histogram().trough_multiplicity() >= 2` — the
/// defining multiplicity-scalar inequality form on the
/// [`crate::AxisHistogram::trough_multiplicity`] scalar peer, the
/// canonical open-coded expression of the predicate one altitude
/// down.
/// - `file_formats_antimodally_tied() ⇔
/// file_format_histogram().modality_degree().1 >= 2` — the
/// modality-pair projection-inequality form, reading the
/// antimodal component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison.
/// - `file_formats_antimodally_tied() ⇒ file_formats_any_observed()`
/// always — a tied trough requires at least two observed cells,
/// so both the empty chain (zero observed cells) and every no-
/// recognized-files non-empty chain (empty file-format histogram
/// via the partial-function projection) cannot fire.
/// Contrapositively, `!file_formats_any_observed() ⇒
/// !file_formats_antimodally_tied()`.
/// - `file_formats_singular_support() ⇒
/// !file_formats_antimodally_tied()` always — a singleton-support
/// chain has exactly one observed cell, so the antimodal level
/// set has cardinality `1` and the tie predicate fails.
/// Contrapositively, `file_formats_antimodally_tied() ⇒
/// !file_formats_singular_support()`: a fired tie predicate means
/// at least two observed cells. Direct pin of the histogram-side
/// subsumption `has_singular_support ⇒ !is_antimodally_tied` one
/// altitude down.
/// - `file_formats_full_cover() ∧ file_formats_balanced() ⇒
/// file_formats_antimodally_tied()` on the cardinality-`>= 2`
/// axis: a full-cover uniform-count chain has every cell observed
/// at the same count, so the antimodal level set equals the full
/// axis — the trough multiplicity rises to
/// `axis_cardinality::<crate::discovery::Format>()` which is `4`,
/// and the tie predicate fires. Cardinality-`>= 2` witness of the
/// uniform-cover corner of the histogram-side subsumption tying
/// [`crate::AxisHistogram::is_uniform_count`] and
/// [`crate::AxisHistogram::has_singular_support`] on non-empty
/// histograms one altitude down.
/// - **Strict antimodal partition on non-empty file-format
/// histograms** — `!file_format_histogram().is_empty() ⇒
/// (file_formats_antimodally_tied ⇔
/// !file_format_histogram().is_strictly_antimodally_unique())`
/// always. On every non-empty file-format histogram exactly one
/// of `(file_formats_antimodally_tied,
/// file_format_histogram().is_strictly_antimodally_unique())`
/// fires; both read `false` on the empty histogram — the shared
/// boundary below both branches. Direct pin of the histogram-side
/// strict antimodal partition one altitude down.
/// - **Modal / antimodal collapse on uniform-count non-empty
/// file-format histograms** — `file_formats_balanced() ∧
/// file_formats_any_observed() ⇒ (file_formats_antimodally_tied
/// ⇔ file_formats_modally_tied)`. On every uniform-count non-
/// empty file-format histogram the two tie predicates collapse
/// to the same value. Direct pin of the histogram-side collapse
/// `is_uniform_count ∧ !is_empty ⇒ is_antimodally_tied ⇔
/// is_modally_tied` one altitude down, peer of the same collapse
/// pinned at the diff altitude by
/// [`crate::ConfigDiff::kinds_antimodally_tied`], at the tier
/// altitude by [`crate::ProvenanceMap::tiers_antimodally_tied`],
/// and at the chain layer-kind sub-axis by
/// [`Self::layer_kinds_antimodally_tied`].
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the trough-multiplicity scan). Both are `O(n)` in practice
/// since the file-format axis carries a fixed four-cell
/// cardinality; the returned `bool` reads one predicate — the
/// trough scan walks the counts vector once and counts cells
/// matching the strictly-positive minimum, then reads
/// `multiplicity >= 2` off one comparison. Strictly tighter than
/// the two documented open-coded surfaces one seam over (no
/// exposed `>= 2` magic threshold at the consumer site, no
/// [`crate::AxisHistogram::modality_degree`] fused-pair build for
/// a single-component projection).
#[must_use]
fn file_formats_antimodally_tied(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().is_antimodally_tied()
}
/// `true` exactly when this chain's observed
/// [`crate::discovery::Format`] histogram has exactly one cell holding
/// the peak leaf count — the peak file-format is *uniquely held*
/// rather than shared.
///
/// The **strictly-modally-unique-file-formats boolean predicate** on
/// the file-format sub-axis of the chain altitude, the direct strict-
/// complement of [`Self::file_formats_modally_tied`] on every non-
/// empty file-format histogram (both read `false` on the empty
/// histogram — the shared boundary below both branches of the strict
/// modal partition). Routes through
/// [`Self::file_format_histogram`]`::is_strictly_modally_unique`, the
/// single-pass scan over the fixed-cardinality counts vector reading
/// `peak_multiplicity() == 1` off one predicate — strictly tighter
/// than either of the documented open-coded surface forms one seam
/// over.
///
/// The **strictly-modally-unique-file-formats peer** of the two
/// documented surface forms consumers previously re-derived inline:
/// `chain.file_format_histogram().peak_multiplicity() == 1` (the
/// defining multiplicity-scalar equality form — one method call
/// plus a magic `== 1` threshold at the consumer site), and
/// `chain.file_format_histogram().modality_degree().0 == 1` (the
/// modality-pair projection-equality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// equality — a fused-pair build for a single-component
/// projection). This lift names the strictly-modally-unique-file-
/// formats predicate directly at the chain-altitude surface — the
/// typed boolean every operator-facing *"is the dominant file
/// format uniquely held on this chain, or is the declaration-order
/// tie-break exercised?"* check reads off as a single method call,
/// on the strict-uniqueness side of the strict modal partition.
///
/// The chain-altitude file-format sub-axis strict-modal-uniqueness-
/// predicate peer that **lifts the "strictly-modally-unique across
/// altitudes" projection sideways** from the first chain-altitude
/// sub-axis ([`Self::layer_kinds_strictly_modally_unique`]) to the
/// second chain-altitude sub-axis, matching the tier-altitude climb
/// ([`crate::ProvenanceMap::tiers_strictly_modally_unique`]) and the
/// diff-altitude seed ([`crate::ConfigDiff::kinds_strictly_modally_unique`]).
/// The remaining chain-altitude sub-axis
/// ([`Self::env_prefix_kinds_strictly_modally_unique`] over
/// [`Self::env_prefix_kind_histogram`]) is the natural next
/// sideways lift, mirroring the four-step lift trajectory of the
/// eight prior projections. Strict-uniqueness row on top of the
/// closed modality-tie boolean pair
/// ([`Self::file_formats_modally_tied`],
/// [`Self::file_formats_antimodally_tied`]) — with this lift the
/// "strictly-modally-unique across altitudes" projection carries
/// one named cube-native seam at four of the five altitudes /
/// sub-axes (diff, tier, chain layer-kind, and chain file-format).
/// The pattern is the same at every altitude / sub-axis: fuse the
/// two open-coded surface forms (multiplicity-scalar equality,
/// modality-pair projection-equality) into a single boolean
/// predicate named at the surface, routed through the shared
/// [`crate::AxisHistogram::is_strictly_modally_unique`] primitive
/// one altitude down.
///
/// **Cardinality-`4` reachability at the file-format sub-axis —
/// the strictly-modally-unique corner carries witnesses across the
/// singleton-support and strictly-modal-skewed corners.**
/// [`crate::discovery::Format`] carries four cells, so
/// `file_formats_strictly_modally_unique()` reads `true` on every
/// chain whose peak leaf count is uniquely held by exactly one
/// observed file-format cell (e.g. a singleton-support chain with
/// all recognized-extension file layers on `.yaml`, or the
/// two-`.yaml`+one-`.toml` chain where `Yaml` uniquely peaks at
/// count `2`), and `false` on the empty chain (no observed cell,
/// no peak), on every no-recognized-files non-empty chain (empty
/// file-format histogram via the partial-function projection — no
/// observed cell), on every two-format tied-at-count-`1` chain
/// (two cells share the peak), on every three-format tied-at-
/// count-`1` chain (three cells share the peak), and on the
/// uniform four-format cover (all four cells sit at the same peak
/// count). Matches the tier-altitude peer on the cardinality-`4`
/// [`crate::ConfigTierKind`] axis in reachability — the additional
/// support-`3` three-format tied-at-`1` counter-witness
/// unavailable at the cardinality-`3` layer-kind sub-axis / diff
/// altitude is *reachable* here, a strict advance over both.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain observes zero cells, so
/// [`crate::AxisHistogram::peak_multiplicity`] reads `0` and the
/// equality `0 == 1` fails. Matches
/// [`crate::AxisHistogram::is_strictly_modally_unique`]'s empty-
/// histogram convention one altitude down. The empty-chain row on
/// the strict modal partition pair
/// `(is_strictly_modally_unique, is_modally_tied)` reads
/// `(false, false)` — the shared boundary below both branches. Peer
/// of [`Self::layer_kinds_strictly_modally_unique`]'s empty-chain
/// `false` polarity one sub-axis over on the same chain altitude,
/// of [`crate::ProvenanceMap::tiers_strictly_modally_unique`]'s
/// empty-map `false` polarity, and of
/// [`crate::ConfigDiff::kinds_strictly_modally_unique`]'s empty-diff
/// `false` polarity in the same projection.
///
/// **No-recognized-files convention** — returns `false` on every
/// non-empty chain whose file-format histogram is empty (only
/// `Defaults`, `Env`, and unrecognized-extension `File` layers).
/// The file-format projection is a partial function
/// ([`ConfigSource::file_format`] returns [`None`] for the
/// unrecognized cases), so a non-empty chain can still project to
/// an empty histogram — `peak_multiplicity` reads `0` and the
/// equality `0 == 1` fails. This is the strict-uniqueness-side
/// cross-sub-axis divergence pin against
/// [`Self::layer_kinds_strictly_modally_unique`]: on the same
/// fixtures the layer-kind sub-axis observes at least one layer-
/// kind cell (Defaults / Env / File) and may fire the strictly-
/// modally-unique predicate (e.g. one `Defaults` reads
/// `layer_kinds_strictly_modally_unique = true`), while the file-
/// format sub-axis's strictly-modally-unique predicate silently
/// drops out via the empty-histogram disjunct — the strict-
/// uniqueness leg's meaning is *narrower* at the file-format sub-
/// axis than at the layer-kind sub-axis.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed file-format support is a single
/// [`crate::discovery::Format`] cell: the lone observed cell
/// stands alone at its own peak (no tie-break to exercise), so
/// `peak_multiplicity` reads `1` and the equality `1 == 1` fires.
/// The `sample_chain()` fixture (two `.yaml` file layers + one Env
/// layer, `{Yaml}` file-format support with count `2`) is a
/// witness on the `true` side — the singleton-support corner is
/// uniformly on the strictly-modally-unique side of the strict
/// modal partition. Direct pin of the histogram-side subsumption
/// `has_singular_support ⇒ is_strictly_modally_unique` one
/// altitude down.
///
/// **Uniform four-format cover convention** — returns `false` on
/// every chain where each [`crate::discovery::Format`] cell was
/// observed at exactly the same positive count (in particular the
/// chain with one file per format): the four cells share the same
/// count, so `peak_multiplicity` reads `4` and the equality
/// `4 == 1` fails. Peer of the histogram-side axis-cover
/// convention one altitude down, which reads `false` on every
/// implementor with `axis_cardinality::<A>() >= 2` — the
/// cardinality-`4` [`crate::discovery::Format`] axis honours the
/// general condition.
///
/// **Two-way modal partition on non-empty file-format histograms**
/// — on every non-empty file-format histogram exactly one of the
/// modal-uniqueness pair
/// `(file_formats_strictly_modally_unique, file_formats_modally_tied)`
/// fires: either the peak is uniquely held (strictly-modally-
/// unique fires, modally-tied does not) or the peak is shared
/// (modally-tied fires, strictly-modally-unique does not). The
/// empty histogram sits below both branches (both read `false`) —
/// this covers both the empty chain and every no-recognized-files
/// non-empty chain. Direct pin of the histogram-side strict modal
/// partition
/// `!is_empty ⇒ is_strictly_modally_unique ⇔ !is_modally_tied` one
/// altitude down, phrased as an XOR on the two named seams at the
/// chain file-format sub-axis surface — the seam-level dual of
/// the matching pin
/// [`Self::file_formats_modally_tied`] that reads the strict side
/// off the histogram primitive.
///
/// # Invariants
///
/// - `file_formats_strictly_modally_unique() == file_format_histogram().is_strictly_modally_unique()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `file_formats_strictly_modally_unique() ⇔
/// file_format_histogram().peak_multiplicity() == 1` — the
/// defining multiplicity-scalar equality form on the
/// [`crate::AxisHistogram::peak_multiplicity`] scalar peer, the
/// canonical open-coded expression of the predicate one altitude
/// down.
/// - `file_formats_strictly_modally_unique() ⇔
/// file_format_histogram().modality_degree().0 == 1` — the
/// modality-pair projection-equality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// equality.
/// - `file_formats_strictly_modally_unique() ⇒
/// file_formats_any_observed()` always — a strictly-unique peak
/// requires at least one observed cell as the sole member of
/// the modal level set, so both the empty chain (zero observed
/// cells) and every no-recognized-files non-empty chain (empty
/// file-format histogram via the partial-function projection)
/// cannot fire. Contrapositively, `!file_formats_any_observed()
/// ⇒ !file_formats_strictly_modally_unique()`.
/// - `file_formats_singular_support() ⇒
/// file_formats_strictly_modally_unique()` always — a
/// singleton-support chain has exactly one observed cell as the
/// sole member of the modal level set, so the uniqueness
/// predicate fires. Direct pin of the histogram-side
/// subsumption `has_singular_support ⇒
/// is_strictly_modally_unique` one altitude down.
/// - **Strict modal partition on non-empty file-format histograms**
/// — `!file_format_histogram().is_empty() ⇒
/// (file_formats_strictly_modally_unique ⇔
/// !file_formats_modally_tied())` always. On every non-empty
/// file-format histogram exactly one of
/// `(file_formats_strictly_modally_unique,
/// file_formats_modally_tied)` fires; both read `false` on the
/// empty file-format histogram — the shared boundary below both
/// branches. Direct pin of the histogram-side strict-modal-
/// partition law one altitude down, phrased as an XOR on the
/// two named seams at the chain file-format sub-axis surface.
/// - `file_formats_full_cover() ∧ file_formats_balanced() ⇒
/// !file_formats_strictly_modally_unique()` on the cardinality-
/// `>= 2` axis: a full-cover uniform-count chain has every cell
/// observed at the same count, so the modal level set equals
/// the full axis — the peak multiplicity rises to
/// `axis_cardinality::<crate::discovery::Format>()` which is `4`,
/// and the uniqueness predicate fails. Cardinality-`>= 2`
/// witness of the uniform-cover corner of the histogram-side
/// subsumption tying [`crate::AxisHistogram::is_uniform_count`]
/// and [`crate::AxisHistogram::has_singular_support`] on non-
/// empty histograms one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::discovery::Format>()`
/// (the peak-multiplicity scan). Both are `O(n)` in practice since
/// the file-format axis carries a fixed four-cell cardinality; the
/// returned `bool` reads one predicate — the peak scan walks the
/// counts vector once and counts cells matching the max, then
/// reads `multiplicity == 1` off one comparison. Strictly tighter
/// than the two documented open-coded surfaces one seam over (no
/// exposed `== 1` magic threshold at the consumer site, no
/// [`crate::AxisHistogram::modality_degree`] fused-pair build for
/// a single-component projection).
#[must_use]
fn file_formats_strictly_modally_unique(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.file_format_histogram().is_strictly_modally_unique()
}
/// Dense per-env-prefix-presence tally of the chain's
/// [`ConfigSource::Env`] layers over the [`EnvMetadataTagKind`] axis
/// — the typed histogram every attestation manifest, structured-log
/// dashboard, and chain-shape audit bucketing the (prefixed × bare)
/// env-layer counts has previously re-derived inline.
///
/// Equivalent to
/// `crate::axis_histogram(self.iter().filter_map(ConfigSource::env_prefix_kind))`
/// but named at the chain-walk surface so consumers reading the
/// recipe ([`crate::ConfigStore::sources`] /
/// [`crate::ProviderChain::sources`]) don't reach for the cube-
/// level generic helper. Only [`ConfigSource::Env`] entries
/// contribute: [`ConfigSource::Defaults`] and [`ConfigSource::File`]
/// entries project to [`None`] through
/// [`ConfigSource::env_prefix_kind`] (no env-prefix shape to read).
/// Unlike [`Self::file_format_histogram`] — where some `File` entries
/// can project to [`None`] when the extension is unrecognized — every
/// `Env` entry projects to a `Some` cell regardless of prefix value:
/// the empty-prefix case maps to [`EnvMetadataTagKind::Bare`], every
/// non-empty prefix maps to [`EnvMetadataTagKind::Prefixed`]. The
/// histogram's `total()` therefore equals
/// `self.layer_kind_histogram().count(ConfigSourceKind::Env)`
/// pointwise — strict equality, not the inequality bound the file-
/// format histogram carries. `is_empty()` iff the chain holds no
/// `Env` entries.
///
/// Third chain-level histogram peer of [`Self::layer_kind_histogram`]
/// on the [`ConfigSourceKind`] layer-kind axis and
/// [`Self::file_format_histogram`] on the file-format axis. With this
/// lift the chain-shape surface carries the three natural aggregate
/// projections side by side: one over the total layer-kind axis
/// (every entry contributes), one over the file-format axis (file
/// entries with recognized extensions contribute), and one over the
/// env-prefix-presence axis (every env entry contributes). The named
/// histogram delivers the "env-name sub-axis loader histogram over
/// [`EnvMetadataTagKind`]" the chain-shape lift discipline now closes
/// at three sites — every future axis-tally consumer composes
/// [`crate::axis_histogram`] over the appropriate per-cell projection
/// on the same template.
///
/// Pairs structurally with the figment-side
/// [`EnvMetadataTag::kind`] projection: for any `Env(prefix)` chain
/// entry, the chain-side projection
/// [`ConfigSource::env_prefix_kind`] agrees pointwise with the
/// figment-side projection over
/// [`ConfigSource::env_metadata_name`]/
/// [`ConfigSource::strip_env_metadata_name`]. The two histograms
/// (one on each surface) would read the same per-cell counts, so a
/// future divergence in either projection surfaces at the kind axis.
///
/// Trait-default implementation so a chain-shape consumer reading
/// the histogram does not need to retain the chain slice — the
/// projection is one method call. A future [`EnvMetadataTag`]
/// variant lands as one new column in the histogram automatically
/// (the typescape's [`EnvMetadataTagKind::ALL`] /
/// [`crate::AxisHistogram`] discipline sizes the slot count); no
/// per-consumer update is required.
fn env_prefix_kind_histogram(&self) -> crate::AxisHistogram<EnvMetadataTagKind>
where
Self: AsRef<[ConfigSource]>,
{
crate::axis_histogram(
self.as_ref()
.iter()
.filter_map(ConfigSource::env_prefix_kind),
)
}
/// The distinct [`EnvMetadataTagKind`]s that appear as ≥1
/// contributing [`ConfigSource::Env`] layer in this chain, in
/// [`EnvMetadataTagKind::ALL`] declaration order — the
/// chain-altitude dual of "which env-prefix kinds actually
/// surfaced in this recipe".
///
/// Routes through [`Self::env_prefix_kind_histogram`]:
/// [`crate::AxisHistogram::observed`] iterates the histogram's
/// support (the closed-axis cells with nonzero count) in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`EnvMetadataTagKind`] canonical order (`Prefixed → Bare`) by
/// construction — the closed-axis discipline provides the sort +
/// dedup automatically, so this method reads directly off the
/// shikumi cube-native primitive instead of hand-rolling
/// `Vec::contains` (`O(n·k)` in the chain length and distinct-
/// prefix-kind count) + explicit `sort_by_key(axis_ordinal)` at
/// every attestation manifest, structured-log dashboard, or
/// config-show renderer summarizing which env-prefix classes
/// contributed to the recipe.
///
/// The chain-altitude sister of [`Self::present_layer_kinds`] on
/// the [`ConfigSourceKind`] layer-kind axis and
/// [`Self::present_file_formats`] on the file-format axis —
/// same observed-cells projection template, one axis over. With
/// this lift the three chain-shape histograms
/// ([`Self::layer_kind_histogram`],
/// [`Self::file_format_histogram`],
/// [`Self::env_prefix_kind_histogram`]) all carry the observed-
/// cells peer alongside their respective `_histogram()`
/// primitive; every "which cells surfaced?" question on the
/// recipe reaches for the same named seam at whichever sub-axis
/// it lives on. Peer to [`crate::ConfigDiff::present_kinds`] on
/// the diff altitude and
/// [`crate::ProvenanceMap::contributing_tiers`] on the tier
/// altitude — all four project the observed-support of the
/// underlying [`crate::AxisHistogram`] over their local closed
/// axis, all four live as a `Vec<CellKind>` collect wrapper
/// alongside their respective `_histogram()` primitive, and all
/// four spell the closed-axis declaration-order cell iteration
/// at the API boundary.
///
/// # Invariants
///
/// - `present_env_prefix_kinds().len() ==
/// env_prefix_kind_histogram().distinct_cells()` — both
/// project the same support-cardinality off the histogram.
/// - `present_env_prefix_kinds().is_empty() ==
/// env_prefix_kind_histogram().is_empty()` — a histogram with
/// no observed env-prefix-kind cell has no present kinds, and
/// vice versa. Like [`Self::present_file_formats`] and unlike
/// [`Self::present_layer_kinds`], the presence bound is NOT
/// tied to `self.as_ref().is_empty()`: a chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers
/// is non-empty but has no present env-prefix kinds, because
/// those entries project to [`None`] through
/// [`ConfigSource::env_prefix_kind`].
/// - `env_prefix_kind_histogram().is_full_cover() ==
/// (present_env_prefix_kinds().len() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>())` — the
/// full-cover predicate and the observed-cells cardinality
/// agree by construction over the same shared histogram.
/// - `present_env_prefix_kinds()` is sorted strictly ascending
/// by [`crate::axis_ordinal`] on [`EnvMetadataTagKind`] —
/// dedup and sort for free from the closed-axis discipline;
/// no hand-rolled `sort_by_key` at the consumer.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<EnvMetadataTagKind>()`
/// (the support scan). Both are `O(n)` in practice since the
/// env-prefix-kind axis carries a fixed two-cell cardinality;
/// the returned `Vec<EnvMetadataTagKind>` is at most two elements
/// long regardless of chain length.
fn present_env_prefix_kinds(&self) -> Vec<EnvMetadataTagKind>
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().observed().collect()
}
/// How many distinct [`EnvMetadataTagKind`]s appear as ≥1
/// contributing [`ConfigSource::Env`] layer in this chain — the
/// support-size scalar peer of [`Self::present_env_prefix_kinds`]
/// on the env-prefix-presence sub-axis of the chain altitude,
/// closing the third chain-shape sub-axis's `(observed,
/// unobserved) × (cells, count)` 2×2 support / coverage-gap grid
/// alongside [`Self::present_layer_kinds_count`] on the layer-kind
/// sub-axis one axis over and [`Self::present_file_formats_count`]
/// on the file-format sub-axis one axis over.
///
/// Routes through [`Self::env_prefix_kind_histogram`]:
/// [`crate::AxisHistogram::distinct_cells`] is the cube-native
/// single-pass `.filter(|&&c| c > 0).count()` walk over the
/// fixed-cardinality counts vector, so this method reads the
/// support size in one call instead of paying for the
/// `Vec<EnvMetadataTagKind>` allocation
/// [`Self::present_env_prefix_kinds`] materialises and then
/// walking [`Vec::len`] to read the length back — the exact idiom
/// every operator-facing consumer asking *"how many env-prefix
/// kinds contributed to this recipe?"* has been open-coding at
/// [`Vec::len`] of the observed-cells `Vec` peer:
///
/// - the config-show summary line *"1 of 2 env-prefix kinds
/// contributed to this recipe"* reading the support cardinality
/// directly off the seam,
/// - the attestation manifest recording the env-prefix-presence
/// support size of a `ProviderChain` between two rebuild-window
/// snapshots,
/// - the alerting policy reading *"env-prefix support size = 1"*
/// to flag a recipe where only one env-prefix class surfaced
/// (only `Prefixed` or only `Bare`, never both).
///
/// The env-prefix-presence sub-axis scalar-count peer of the
/// chain altitude, sister to the layer-kind sub-axis's
/// [`Self::present_layer_kinds_count`], the file-format sub-
/// axis's [`Self::present_file_formats_count`], the tier
/// altitude's [`crate::ProvenanceMap::contributing_tiers_count`],
/// and the diff altitude's [`crate::ConfigDiff::present_kinds`]
/// length peer. With this lift the chain-shape surface closes the
/// **support-size scalar peer at every one of its three sub-
/// axes** — the "how many cells got observed" scalar projection
/// is now a typed primitive on every chain-shape sub-axis of the
/// substrate. Together with [`Self::present_env_prefix_kinds`]
/// and [`Self::absent_env_prefix_kinds`], this seam closes the
/// `(observed, unobserved) × (cells, count)` 2×2 support /
/// coverage-gap grid on the env-prefix-presence sub-axis:
///
/// | | cells (Vec) | count (usize) |
/// |---|---|---|
/// | observed | [`Self::present_env_prefix_kinds`] | **`present_env_prefix_kinds_count`** |
/// | unobserved | [`Self::absent_env_prefix_kinds`] | [`Self::absent_env_prefix_kinds_count`] |
///
/// # Invariants
///
/// - `present_env_prefix_kinds_count() ==
/// env_prefix_kind_histogram().distinct_cells()` — both project
/// the same nonzero-cell count off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface. Pinned by
/// [`tests::present_env_prefix_kinds_count_matches_env_prefix_kind_histogram_distinct_cells_pointwise`].
/// - `present_env_prefix_kinds_count() ==
/// present_env_prefix_kinds().len()` — the scalar-count peer of
/// the observed-cells `Vec` peer; both name the same support
/// cardinality without materialising the vector. Pinned by
/// [`tests::present_env_prefix_kinds_count_equals_present_env_prefix_kinds_len_pointwise`].
/// - `present_env_prefix_kinds_count() +
/// absent_env_prefix_kinds().len() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>()` — the
/// observed / coverage-gap partition on the env-prefix-
/// presence sub-axis without remainder, the scalar dual of the
/// [`tests::absent_env_prefix_kinds_and_present_env_prefix_kinds_partition_axis`]
/// set-level partition law. Pinned by
/// [`tests::present_env_prefix_kinds_count_and_absent_env_prefix_kinds_len_partition_axis_cardinality`].
/// - `present_env_prefix_kinds_count() == 0` ⇔
/// `env_prefix_kind_histogram().is_empty()` — the empty-
/// histogram / empty-support boundary equivalence. Like
/// [`Self::present_file_formats_count`] and unlike
/// [`Self::present_layer_kinds_count`], the zero boundary is
/// **not** tied to `self.as_ref().is_empty()`: a chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers is
/// non-empty but reads zero, because those entries project to
/// [`None`] through [`ConfigSource::env_prefix_kind`]. Pinned by
/// [`tests::present_env_prefix_kinds_count_is_zero_iff_env_prefix_kind_histogram_is_empty`].
/// - `present_env_prefix_kinds_count() >= 1` whenever
/// `!env_prefix_kind_histogram().is_empty()` — the support of a
/// non-empty histogram is at least the singleton of the first
/// observed cell. Pinned by
/// [`tests::present_env_prefix_kinds_count_is_at_least_one_on_nonempty_histogram`].
/// - `present_env_prefix_kinds_count() <=
/// crate::axis_cardinality::<EnvMetadataTagKind>()` — the
/// support of a histogram over a closed axis is bounded above
/// by the axis cardinality (the observed-cells set is a subset
/// of [`EnvMetadataTagKind::ALL`]). Pinned by
/// [`tests::present_env_prefix_kinds_count_is_bounded_by_axis_cardinality`].
/// - `present_env_prefix_kinds_count() <=
/// env_prefix_kind_histogram().total()` — the support of a
/// histogram is bounded above by the total observation count
/// (every distinct cell contributes at least one observation to
/// the total). Pinned by
/// [`tests::present_env_prefix_kinds_count_is_bounded_by_env_prefix_kind_histogram_total`].
/// - `present_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>()` ⇔
/// `absent_env_prefix_kinds().is_empty()` ⇔
/// `env_prefix_kind_histogram().is_full_cover()` — the full-
/// cover boundary equivalence, the env-prefix-presence-sub-
/// axis scalar-count peer of the
/// [`crate::AxisHistogram::is_full_cover`] boundary law. Pinned
/// by
/// [`tests::present_env_prefix_kinds_count_equals_axis_cardinality_iff_is_full_cover`].
/// - `present_env_prefix_kinds_count() == 1` ⇔
/// `env_prefix_kind_histogram().has_singular_support()` — the
/// singleton-support boundary equivalence, the env-prefix-
/// presence-sub-axis peer of the
/// [`crate::AxisHistogram::has_singular_support`] boundary law.
/// Pinned by
/// [`tests::present_env_prefix_kinds_count_is_one_iff_has_singular_support`].
/// - `present_env_prefix_kinds_count() == 1` ⇒
/// `dominant_env_prefix_kind() == recessive_env_prefix_kind()`
/// — a singleton-support recipe has the modal and anti-modal
/// cells coincide on the sole observed env-prefix kind (the
/// support-size scalar witnesses the
/// [`crate::AxisHistogram`] support-collapse degenerate).
/// Pinned by
/// [`tests::present_env_prefix_kinds_count_of_one_implies_dominant_equals_recessive`].
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<EnvMetadataTagKind>()`
/// (the support scan). Both are `O(n)` in practice since the
/// env-prefix-presence axis carries a fixed two-cell cardinality;
/// unlike [`Self::present_env_prefix_kinds`], no
/// `Vec<EnvMetadataTagKind>` allocation is paid on every call
/// site.
fn present_env_prefix_kinds_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().distinct_cells()
}
/// The distinct [`EnvMetadataTagKind`]s that appear as **zero**
/// contributing [`ConfigSource::Env`] layers in this chain, in
/// [`EnvMetadataTagKind::ALL`] declaration order — the coverage-
/// gap peer of [`Self::present_env_prefix_kinds`] and the
/// env-prefix-presence-axis sister of [`Self::absent_layer_kinds`] /
/// [`Self::absent_file_formats`] on the same chain-shape surface.
///
/// Routes through [`Self::env_prefix_kind_histogram`]:
/// [`crate::AxisHistogram::unobserved`] iterates the histogram's
/// **coverage gap** (the closed-axis cells with zero count) in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`EnvMetadataTagKind`] canonical order (`Prefixed → Bare`) by
/// construction — the closed-axis discipline provides the sort +
/// dedup automatically, so this method reads directly off the
/// shikumi cube-native primitive instead of hand-rolling
/// `EnvMetadataTagKind::ALL.iter().filter(|k| !self.present_env_prefix_kinds().
/// contains(k))` (`O(k·k)` in axis-cardinality, quadratic on the
/// observed side) at every operator-facing consumer asking *"which
/// env-prefix kinds are absent from this recipe?"* — the CLI
/// `config-show` summary reading *"no `Env::raw()` layer; skip the
/// bare-env legend"*, the attestation manifest recording the
/// env-prefix coverage gap of a `ProviderChain`, the alerting policy
/// suppressing per-env-kind bins that never fired for this rebuild
/// window.
///
/// The observed-cells peer ([`Self::present_env_prefix_kinds`]) and
/// the coverage-gap peer ([`Self::absent_env_prefix_kinds`]) together
/// form the **support / coverage-gap partition** on the env-prefix-
/// presence sub-axis — every cell of [`EnvMetadataTagKind::ALL`]
/// lies in exactly one of the two, and the two
/// `Vec<EnvMetadataTagKind>` lengths sum to
/// [`crate::axis_cardinality::<EnvMetadataTagKind>()`][crate::axis_cardinality].
/// With this lift the chain-shape surface closes both halves of the
/// histogram's observed / unobserved partition at three named
/// `Vec<CellKind>` seams over the three chain-shape sub-axes
/// (layer-kind, file-format, env-prefix-presence) — the last sister
/// coverage-gap peer at the chain altitude. Peer to
/// [`crate::ConfigDiff::absent_kinds`] on the diff altitude and
/// [`crate::ProvenanceMap::absent_tiers`] on the tier altitude —
/// all five project the unobserved-support of the underlying
/// [`crate::AxisHistogram`] over their local closed axis at a named
/// `Vec<CellKind>` collect wrapper alongside their respective
/// `_histogram()` primitive.
///
/// # Invariants
///
/// - `absent_env_prefix_kinds().len() ==
/// env_prefix_kind_histogram().unobserved_cells()` — both project
/// the same coverage-gap cardinality off the histogram.
/// - `present_env_prefix_kinds().len() + absent_env_prefix_kinds().len() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>()` — the two
/// peers partition the closed axis without remainder (every cell
/// is either observed or unobserved, never both).
/// - `present_env_prefix_kinds()` and `absent_env_prefix_kinds()`
/// are disjoint: no [`EnvMetadataTagKind`] appears in both.
/// - `absent_env_prefix_kinds().is_empty() ==
/// env_prefix_kind_histogram().is_full_cover()` — the coverage-gap
/// is empty iff every env-prefix kind was observed at least once
/// (both `Prefixed` and `Bare` appear as ≥1 `Env` layer).
/// - `absent_env_prefix_kinds()` on an empty chain (no layers)
/// equals [`EnvMetadataTagKind::ALL`] — every kind is absent when
/// no layer contributed. Like [`Self::absent_file_formats`] and
/// unlike [`Self::absent_layer_kinds`], the full-axis boundary
/// also fires on any chain of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::File`] layers — those entries all project to
/// [`None`] through [`ConfigSource::env_prefix_kind`], so the
/// histogram is empty even when the chain is not.
/// - `absent_env_prefix_kinds()` is sorted strictly ascending by
/// [`crate::axis_ordinal`] on [`EnvMetadataTagKind`] — dedup +
/// sort for free from the closed-axis discipline.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// coverage-gap scan). Both are `O(n)` in practice since the
/// env-prefix-presence axis carries a fixed two-cell cardinality;
/// the returned `Vec<EnvMetadataTagKind>` is at most two elements
/// long regardless of chain length.
fn absent_env_prefix_kinds(&self) -> Vec<EnvMetadataTagKind>
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().unobserved().collect()
}
/// How many distinct [`EnvMetadataTagKind`]s appear as **zero**
/// contributing [`ConfigSource::Env`] layers in this chain — the
/// coverage-gap-size scalar peer of [`Self::absent_env_prefix_kinds`]
/// on the env-prefix-presence sub-axis of the chain altitude, closing
/// the third chain-shape sub-axis's `(observed, unobserved) × (cells,
/// count)` 2×2 support / coverage-gap grid alongside
/// [`Self::absent_layer_kinds_count`] on the layer-kind sub-axis one
/// axis over and [`Self::absent_file_formats_count`] on the file-
/// format sub-axis one axis over.
///
/// Routes through [`Self::env_prefix_kind_histogram`]:
/// [`crate::AxisHistogram::unobserved_cells`] is the cube-native
/// single-pass `.filter(|&&c| c == 0).count()` walk over the fixed-
/// cardinality counts vector, so this method reads the coverage-gap
/// size in one call instead of paying for the
/// `Vec<EnvMetadataTagKind>` allocation
/// [`Self::absent_env_prefix_kinds`] materialises and then walking
/// [`Vec::len`] to read the length back — the exact idiom every
/// operator-facing consumer asking *"how many env-prefix kinds are
/// absent from this recipe?"* has been open-coding at [`Vec::len`]
/// of the coverage-gap `Vec` peer:
///
/// - the config-show summary line *"1 of 2 env-prefix kinds absent
/// this rebuild window"* reading the coverage-gap cardinality
/// directly off the seam,
/// - the attestation manifest recording the env-prefix-presence
/// coverage-gap size of a `ProviderChain` between two rebuild-
/// window snapshots,
/// - the alerting policy reading *"env-prefix coverage-gap size = 1"*
/// to flag a recipe where only one env-prefix class surfaced
/// (only `Prefixed` or only `Bare`, never both).
///
/// The env-prefix-presence sub-axis scalar-count coverage-gap peer of
/// the chain altitude, sister to the layer-kind sub-axis's
/// [`Self::absent_layer_kinds_count`], the file-format sub-axis's
/// [`Self::absent_file_formats_count`], the tier altitude's
/// [`crate::ProvenanceMap::absent_tiers_count`], and the diff
/// altitude's [`crate::ConfigDiff::absent_kinds_count`]. With this
/// lift the chain-shape surface closes the **coverage-gap-size scalar
/// peer at every one of its three sub-axes** — the "how many cells
/// were unobserved" scalar projection is now a typed primitive on
/// every chain-shape sub-axis of the substrate, and the "coverage-gap-
/// size across altitudes" projection spans every altitude
/// (diff, tier, chain) and every chain sub-axis (layer-kind, file-
/// format, env-prefix-presence) on one symmetric 2×2 template.
/// Together with [`Self::present_env_prefix_kinds`],
/// [`Self::present_env_prefix_kinds_count`], and
/// [`Self::absent_env_prefix_kinds`], this seam closes the
/// `(observed, unobserved) × (cells, count)` 2×2 support / coverage-
/// gap grid on the env-prefix-presence sub-axis:
///
/// | | cells (Vec) | count (usize) |
/// |---|---|---|
/// | observed | [`Self::present_env_prefix_kinds`] | [`Self::present_env_prefix_kinds_count`] |
/// | unobserved | [`Self::absent_env_prefix_kinds`] | **`absent_env_prefix_kinds_count`** |
///
/// **Empty-histogram convention** — returns
/// [`crate::axis_cardinality::<EnvMetadataTagKind>()`][crate::axis_cardinality]
/// (not `Option<usize>`) matching the [`Self::absent_env_prefix_kinds`]
/// full-axis convention and the
/// [`crate::AxisHistogram::unobserved_cells`] convention one altitude
/// down. Like [`Self::absent_file_formats_count`] and unlike
/// [`Self::absent_layer_kinds_count`], the full-axis boundary is tied
/// to the histogram's own emptiness, **not** the chain's: a non-empty
/// chain of only [`ConfigSource::Defaults`] / [`ConfigSource::File`]
/// layers still reads `axis_cardinality::<EnvMetadataTagKind>()`
/// because every entry projects to [`None`] through
/// [`ConfigSource::env_prefix_kind`], leaving the histogram empty and
/// every env-prefix kind in the coverage gap.
///
/// # Invariants
///
/// - `absent_env_prefix_kinds_count() ==
/// env_prefix_kind_histogram().unobserved_cells()` — both project
/// the same coverage-gap cardinality off the same primitive; the
/// named seam is the cube-native routing of the histogram surface.
/// Pinned by
/// [`tests::absent_env_prefix_kinds_count_matches_env_prefix_kind_histogram_unobserved_cells_pointwise`].
/// - `absent_env_prefix_kinds_count() ==
/// absent_env_prefix_kinds().len()` — the scalar-count peer of the
/// coverage-gap `Vec` peer; both name the same coverage-gap
/// cardinality without materialising the vector. Pinned by
/// [`tests::absent_env_prefix_kinds_count_equals_absent_env_prefix_kinds_len_pointwise`].
/// - `present_env_prefix_kinds_count() +
/// absent_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>()` — the fully-
/// scalar observed / coverage-gap partition on the env-prefix-
/// presence sub-axis without remainder (no `.len()` on either
/// side), the fully-scalar dual of the
/// [`tests::absent_env_prefix_kinds_and_present_env_prefix_kinds_partition_axis`]
/// set-level partition law. Pinned by
/// [`tests::present_env_prefix_kinds_count_and_absent_env_prefix_kinds_count_partition_axis_cardinality`].
/// - `absent_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>() -
/// present_env_prefix_kinds_count()` — the algebraic rearrangement
/// of the partition law, useful for consumers that already hold the
/// support-size scalar. Pinned by
/// [`tests::absent_env_prefix_kinds_count_equals_axis_cardinality_minus_present_env_prefix_kinds_count`].
/// - `absent_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>()` ⇔
/// `env_prefix_kind_histogram().is_empty()` — the empty-histogram /
/// full-coverage-gap boundary equivalence. Like
/// [`Self::absent_file_formats_count`] and unlike
/// [`Self::absent_layer_kinds_count`], the full-axis boundary fires
/// whenever the histogram is empty, **including** on non-empty
/// chains of only [`ConfigSource::Defaults`] / [`ConfigSource::File`]
/// layers. Pinned by
/// [`tests::absent_env_prefix_kinds_count_is_axis_cardinality_iff_env_prefix_kind_histogram_is_empty`].
/// - `absent_env_prefix_kinds_count() == 0` ⇔
/// `env_prefix_kind_histogram().is_full_cover()` — the full-cover
/// boundary equivalence in coverage-gap form, the env-prefix-
/// presence-sub-axis scalar-count coverage-gap peer of the
/// [`crate::AxisHistogram::is_full_cover`] boundary law. Pinned by
/// [`tests::absent_env_prefix_kinds_count_is_zero_iff_is_full_cover`].
/// - `absent_env_prefix_kinds_count() <=
/// crate::axis_cardinality::<EnvMetadataTagKind>()` — the coverage
/// gap of a closed-axis histogram is at most the axis cardinality
/// (the unobserved-cells set is a subset of
/// [`EnvMetadataTagKind::ALL`]). Pinned by
/// [`tests::absent_env_prefix_kinds_count_is_bounded_by_axis_cardinality`].
/// - `absent_env_prefix_kinds_count() >= 1` whenever
/// `!env_prefix_kind_histogram().is_full_cover()` — a non-full-
/// cover recipe carries at least one absent env-prefix kind, the
/// coverage-gap-side lower bound dual to
/// [`Self::present_env_prefix_kinds_count`]'s
/// `>= 1 on nonempty histogram` invariant. Pinned by
/// [`tests::absent_env_prefix_kinds_count_is_at_least_one_when_not_full_cover`].
/// - `absent_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>() - 1` ⇔
/// `env_prefix_kind_histogram().has_singular_support()` — the
/// singleton-support boundary equivalence in coverage-gap form,
/// the env-prefix-presence-sub-axis peer of the
/// [`crate::AxisHistogram::has_singular_support`] boundary law.
/// Pinned by
/// [`tests::absent_env_prefix_kinds_count_is_axis_cardinality_minus_one_iff_has_singular_support`].
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// coverage-gap scan). Both are `O(n)` in practice since the env-
/// prefix-presence axis carries a fixed two-cell cardinality; the
/// returned `usize` reads one scalar. Halves the wall-cost of the
/// previous `absent_env_prefix_kinds().len()` idiom by eliding the
/// `Vec<EnvMetadataTagKind>` allocation the coverage-gap collect
/// paid on every call site.
fn absent_env_prefix_kinds_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().unobserved_cells()
}
/// The [`EnvMetadataTagKind`] whose entries produced the greatest number
/// of contributing [`ConfigSource::Env`] layers on this chain — the modal
/// cell of [`Self::env_prefix_kind_histogram`] on the chain altitude.
/// `None` exactly when the histogram is empty (the chain holds no `Env`
/// entries).
///
/// Routes through [`Self::env_prefix_kind_histogram`]:
/// [`crate::AxisHistogram::dominant_cell`] picks the argmax cell in
/// [`crate::ClosedAxis::ALL`] declaration order, which is the
/// [`EnvMetadataTagKind`] canonical order (`Prefixed → Bare`) by
/// construction — the closed-axis discipline provides deterministic
/// tie-breaking automatically, so this method reads directly off the
/// shikumi cube-native primitive instead of hand-rolling
/// `hist.iter().filter(|&(_, c)| c > 0).max_by_key(|&(_, c)| c).map(|(v, _)| v)`
/// — the inline `max_by_key` form silently picks the *last* tied cell
/// (per [`Iterator::max_by_key`]'s contract), so two consumers reading
/// "the dominant env-prefix kind" off the same chain would disagree
/// under ties unless every one carefully reversed the comparison. The
/// lift names the scalar at one site with a documented tie-breaking
/// rule.
///
/// The chain-altitude scalar-mode peer of
/// [`Self::present_env_prefix_kinds`] (the observed-cells vector peer)
/// and [`Self::absent_env_prefix_kinds`] (the coverage-gap vector peer):
/// the env-prefix-presence sub-axis of the chain-shape surface now
/// carries the natural triple of "*which* prefix kinds surfaced" /
/// "*which* prefix kinds didn't" / "*which single* prefix kind
/// dominated" projections at one named seam each, over the shared
/// [`Self::env_prefix_kind_histogram`] primitive. Direct sister of
/// [`Self::dominant_layer_kind`] and [`Self::dominant_file_format`] on
/// the same chain altitude one sub-axis over — with this lift all
/// three chain-shape sub-axes close the scalar-mode dominance peer at
/// one named `Option<CellKind>` seam alongside the observed /
/// coverage-gap vector-mode pair. The three natural triples now sit
/// side by side at three named seams each across the three chain-shape
/// sub-axes (layer-kind, file-format, env-prefix-presence), matching
/// the closed triples on the tier altitude
/// (`contributing_tiers` / `absent_tiers` / `dominant_tier`) and the
/// diff altitude (`present_kinds` / `absent_kinds` / `dominant_kind`).
///
/// Operator-facing consumers answering *"which env-prefix kind dominated
/// this chain?"* — the CLI `config-show` summary headlining *"prefixed
/// env layers dominate: 3 of 4"* to explain why the recipe is
/// prefix-scoped, the attestation manifest recording the modal
/// env-prefix kind between two `ProviderChain` snapshots, the alerting
/// policy reading *"env-prefix dominance: Bare"* to flag a rebuild
/// window where `figment::providers::Env::raw()` layers swamped the
/// prefixed set — now route through this named seam instead of a
/// per-consumer `max_by_key` walk.
///
/// **Tie-breaking is deterministic by declaration order.** When both
/// env-prefix kinds share the maximum env-layer count, the kind
/// earliest in [`EnvMetadataTagKind::ALL`] wins — the same
/// [`EnvMetadataTagKind`] canonical order
/// [`Self::present_env_prefix_kinds`] and
/// [`Self::absent_env_prefix_kinds`] walk. A uniform full-cover chain
/// (one `Env` layer per kind — one bare + one prefixed) therefore
/// reports `Some(EnvMetadataTagKind::Prefixed)` — the first cell in
/// declaration order — pointwise stable regardless of the insertion
/// order of individual env layers into the chain slice.
///
/// # Invariants
///
/// - `dominant_env_prefix_kind().is_some() ==
/// !env_prefix_kind_histogram().is_empty()` — like
/// [`Self::dominant_file_format`] and unlike
/// [`Self::dominant_layer_kind`], the presence bound is *not*
/// `!self.as_ref().is_empty()`: [`ConfigSource::Defaults`] /
/// [`ConfigSource::File`] entries all project to [`None`] through
/// [`ConfigSource::env_prefix_kind`], so the histogram is empty even
/// on a non-empty chain when no `Env` entry contributes.
/// - `dominant_env_prefix_kind() ==
/// env_prefix_kind_histogram().dominant_cell()` — both project the
/// same modal cell off the same primitive; the named seam is the
/// cube-native routing of the chain-shape surface.
/// - When `Some(k)`, `k` is a member of `present_env_prefix_kinds()` —
/// the modal cell is by definition observed.
/// - When `Some(k)`, `k` is **not** a member of
/// `absent_env_prefix_kinds()` — the observed / coverage-gap
/// partition is disjoint.
/// - `env_prefix_kind_histogram().count(dominant_env_prefix_kind().unwrap())
/// == env_prefix_kind_histogram().peak_count()` whenever the
/// histogram is non-empty — the modal cell carries the peak
/// observation count. Peer to the `(dominant_cell, peak_count)`
/// modal pair invariant on [`crate::AxisHistogram`].
/// - `dominant_env_prefix_kind()` on a uniform full-cover chain (one
/// `Env` layer per kind) equals `Some(EnvMetadataTagKind::Prefixed)`
/// — declaration-order tie-breaking on the two-cell axis picks the
/// first cell.
/// - `dominant_env_prefix_kind()` on an empty chain equals `None` —
/// the empty-chain / empty-histogram boundary.
/// - `dominant_env_prefix_kind()` on a chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers equals
/// `None` — the non-empty-chain / empty-histogram boundary the
/// env-prefix-presence sub-axis pins that the layer-kind sub-axis
/// does not.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// argmax scan). Both are `O(n)` in practice since the env-prefix-
/// presence axis carries a fixed two-cell cardinality; the returned
/// `Option<EnvMetadataTagKind>` reads one cell.
#[must_use]
fn dominant_env_prefix_kind(&self) -> Option<EnvMetadataTagKind>
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().dominant_cell()
}
/// The [`EnvMetadataTagKind`] whose entries produced the smallest nonzero
/// number of contributing [`ConfigSource::Env`] layers on this chain — the
/// anti-modal cell of [`Self::env_prefix_kind_histogram`] on the chain
/// altitude. `None` exactly when the histogram is empty (the chain holds
/// no `Env` entries).
///
/// Routes through [`Self::env_prefix_kind_histogram`]:
/// [`crate::AxisHistogram::recessive_cell`] picks the argmin cell over the
/// histogram's support (nonzero cells) in [`crate::ClosedAxis::ALL`]
/// declaration order — the [`EnvMetadataTagKind`] canonical order
/// (`Prefixed → Bare`) by construction — so the closed-axis discipline
/// provides deterministic tie-breaking automatically. This method reads
/// directly off the shikumi cube-native primitive instead of hand-rolling
/// `hist.iter().filter(|&(_, c)| c > 0).min_by_key(|&(_, c)| c).map(|(v, _)| v)`
/// — the inline `min_by_key` form silently picks the *first* tied cell
/// (per [`Iterator::min_by_key`]'s contract, which reverses
/// [`Iterator::max_by_key`]'s "last on ties" behavior), so an open-coded
/// argmin and the open-coded argmax on the dominant side would disagree
/// on which tied cell to pick. The pair of lifts
/// ([`Self::dominant_env_prefix_kind`] and [`Self::recessive_env_prefix_kind`])
/// pins one consistent tie-breaking rule across both projections on the
/// chain-altitude env-prefix-presence sub-axis.
///
/// **Zero-count kinds are excluded from the search.** The argmin is taken
/// over the histogram's support, not over the full axis. Kinds that
/// contributed no env layer would trivially be the minimum over the full
/// axis and would shadow the rarest *observed* kind; excluding them
/// surfaces the rarest kind some env layer actually landed on — the
/// question the CLI `config-show` summary, attestation manifest, and
/// alerting policy ask when they surface *"the runt env-prefix kind this
/// recipe saw"*. This matches [`Self::dominant_env_prefix_kind`]'s
/// symmetry on the maximum side: both projections operate over the
/// nonzero support, so the empty-histogram convention is identical (both
/// return `None`) and the singleton-support case is identical (both
/// return the sole observed kind).
///
/// The chain-altitude anti-modal peer of [`Self::dominant_env_prefix_kind`]
/// (the modal-cell scalar peer of the same
/// [`Self::env_prefix_kind_histogram`] primitive) — the env-prefix-
/// presence sub-axis of the chain-shape surface now carries the fused
/// (dominant, recessive) cell pair, matching the
/// ([`crate::AxisHistogram::dominant_cell`],
/// [`crate::AxisHistogram::recessive_cell`]) pair on the shared
/// [`crate::AxisHistogram`] primitive one altitude down. Direct sister of
/// [`Self::recessive_layer_kind`] on the layer-kind sub-axis and
/// [`Self::recessive_file_format`] on the file-format sub-axis of the
/// same chain altitude, [`crate::ProvenanceMap::recessive_tier`] on the
/// tier altitude, and [`crate::ConfigDiff::recessive_kind`] on the diff
/// altitude — all five project the anti-modal cell of their local
/// closed-axis histogram off the shared
/// [`crate::AxisHistogram::recessive_cell`] primitive, all five live as
/// an `Option<CellKind>` scalar alongside the modal-cell peer. With this
/// lift the substrate closes the (dominant, recessive) modal pair across
/// every `_histogram()` primitive it carries: three chain-shape sub-axes
/// (layer-kind, file-format, env-prefix-presence), one tier altitude,
/// one diff altitude.
///
/// Operator-facing consumers answering *"which env-prefix kind is the
/// runt of this recipe?"* — the CLI `config-show` summary headlining
/// *"runt: Bare, 1 of 47 env layers"*, the attestation manifest recording
/// the anti-modal env-prefix kind between two `ProviderChain` snapshots,
/// the alerting policy reading *"env-prefix runt: Prefixed"* to flag a
/// rebuild window where `figment::providers::Env::raw()` layers swamped
/// the prefixed set to the near-total exclusion of prefixed loaders —
/// now route through this named seam instead of a per-consumer
/// `min_by_key` walk.
///
/// **Tie-breaking is deterministic by declaration order.** When both
/// env-prefix kinds share the minimum env-layer count, the kind
/// earliest in [`EnvMetadataTagKind::ALL`] wins — the same
/// [`EnvMetadataTagKind`] canonical order [`Self::present_env_prefix_kinds`],
/// [`Self::absent_env_prefix_kinds`], and [`Self::dominant_env_prefix_kind`]
/// walk. A uniform full-cover chain (one `Env` layer per kind — one
/// bare, one prefixed) therefore reports
/// `Some(EnvMetadataTagKind::Prefixed)` — the first cell in declaration
/// order — pointwise identical to [`Self::dominant_env_prefix_kind`] on
/// the same input (the singleton-modality degenerate where the modal and
/// anti-modal cells coincide).
///
/// # Invariants
///
/// - `recessive_env_prefix_kind().is_some() ==
/// !env_prefix_kind_histogram().is_empty()` — like
/// [`Self::recessive_file_format`] and unlike
/// [`Self::recessive_layer_kind`], the presence bound is *not*
/// `!self.as_ref().is_empty()`: [`ConfigSource::Defaults`] /
/// [`ConfigSource::File`] entries all project to [`None`] through
/// [`ConfigSource::env_prefix_kind`], so the histogram is empty even on
/// a non-empty chain when no `Env` entry contributes. Mirrors
/// [`Self::dominant_env_prefix_kind`]'s presence bound at the same
/// sub-axis one modality over.
/// - `recessive_env_prefix_kind().is_some() ==
/// dominant_env_prefix_kind().is_some()` — both projections are defined
/// on the same support (`!env_prefix_kind_histogram().is_empty()`),
/// lifted from the [`crate::AxisHistogram::recessive_cell`] /
/// [`crate::AxisHistogram::dominant_cell`] presence-bound law.
/// - `recessive_env_prefix_kind() ==
/// env_prefix_kind_histogram().recessive_cell()` — both project the
/// same anti-modal cell off the same primitive; the named seam is the
/// cube-native routing of the chain-shape surface.
/// - When `Some(k)`, `k` is a member of `present_env_prefix_kinds()` —
/// the anti-modal cell is by definition observed.
/// - When `Some(k)`, `k` is **not** a member of `absent_env_prefix_kinds()`
/// — the observed / coverage-gap partition is disjoint, and the argmin
/// over the *support* never coincides with a zero-count cell.
/// - `env_prefix_kind_histogram().count(recessive_env_prefix_kind().unwrap())
/// == env_prefix_kind_histogram().trough_count()` whenever the
/// histogram is non-empty — the anti-modal cell carries the
/// trough-of-support observation count. Peer to the (`recessive_cell`,
/// `trough_count`) anti-modal pair invariant on
/// [`crate::AxisHistogram`].
/// - `env_prefix_kind_histogram().count(recessive_env_prefix_kind().unwrap())
/// <= env_prefix_kind_histogram().count(dominant_env_prefix_kind().unwrap())`
/// whenever the histogram is non-empty — the trough-of-support count is
/// bounded above by the peak count. Lifted from the trait-uniform
/// `count(recessive_cell) <= count(dominant_cell)` law on
/// [`crate::AxisHistogram`].
/// - `recessive_env_prefix_kind() == dominant_env_prefix_kind()` whenever
/// `present_env_prefix_kinds().len() == 1` — a single observed kind is
/// both the modal and the anti-modal cell (the singleton-support
/// degenerate).
/// - `recessive_env_prefix_kind()` on a uniform full-cover chain (one
/// `Env` layer per kind) equals `Some(EnvMetadataTagKind::Prefixed)`
/// — declaration-order tie-breaking on the two-cell axis picks the
/// first cell, pointwise identical to `dominant_env_prefix_kind()` on
/// the same input.
/// - `recessive_env_prefix_kind()` on an empty chain equals `None` — the
/// empty-chain / empty-histogram boundary.
/// - `recessive_env_prefix_kind()` on a chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers equals
/// `None` — the non-empty-chain / empty-histogram boundary the
/// env-prefix-presence sub-axis pins that the layer-kind sub-axis does
/// not.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the argmin
/// scan). Both are `O(n)` in practice since the env-prefix-presence axis
/// carries a fixed two-cell cardinality; the returned
/// `Option<EnvMetadataTagKind>` reads one cell.
#[must_use]
fn recessive_env_prefix_kind(&self) -> Option<EnvMetadataTagKind>
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().recessive_cell()
}
/// The **peak env-prefix-kind layer count** — the number of
/// [`ConfigSource::Env`] layers contributed by the dominant
/// [`EnvMetadataTagKind`] on this chain. Returns `0` when the
/// [`Self::env_prefix_kind_histogram`] is empty (no chain entry
/// projects through [`ConfigSource::env_prefix_kind`] — i.e. an
/// empty chain, OR a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] entries);
/// otherwise returns the env-layer count carried by
/// [`Self::dominant_env_prefix_kind`] (pointwise equal to it, and
/// always `>= 1` by the histogram-support definition).
///
/// The **scalar peer** of [`Self::dominant_env_prefix_kind`] on the
/// count side — the natural typed primitive for chain-shape
/// dashboards, attestation manifests, and alerting policies asking
/// *"how many env layers did the dominant prefix kind
/// contribute?"*: the CLI `config-show` summary line *"prefixed env
/// layers dominate: 3 of 4"* (where 3 is this scalar), the
/// attestation manifest recording the peak env-prefix-kind
/// observation count between two `ProviderChain` snapshots, the
/// alerting policy reading *"env-prefix peak count = 3"* to flag a
/// rebuild window where a prefix kind dominated the env recipe.
/// Before this lift, every such consumer re-derived the projection
/// inline as `chain.env_prefix_kind_histogram().peak_count()` or
/// (equivalently but at twice the cost)
/// `chain.dominant_env_prefix_kind().map_or(0, |k|
/// chain.env_prefix_kind_histogram().count(k))` — which walked the
/// histogram *twice* (once to argmax over the support, once to read
/// the count back through [`crate::AxisHistogram::count`] indexing)
/// and re-built the histogram at every site. Routes through
/// [`Self::env_prefix_kind_histogram`]:
/// [`crate::AxisHistogram::peak_count`] reads a single pass over the
/// fixed-cardinality counts vector.
///
/// The chain-altitude scalar-count peer of
/// [`Self::dominant_env_prefix_kind`] (the modal-cell scalar peer of
/// [`Self::env_prefix_kind_histogram`]) — the env-prefix-presence
/// sub-axis of the chain-shape surface now carries the fused
/// `(dominant_env_prefix_kind, peak_env_prefix_kind_count)` modal
/// pair, matching the ([`crate::AxisHistogram::dominant_cell`],
/// [`crate::AxisHistogram::peak_count`]) pair on the shared
/// [`crate::AxisHistogram`] primitive one altitude down, the
/// ([`Self::dominant_layer_kind`], [`Self::peak_layer_kind_count`])
/// pair on the layer-kind sub-axis of the same chain altitude, the
/// ([`Self::dominant_file_format`], [`Self::peak_file_format_count`])
/// pair on the file-format sub-axis of the same chain altitude, the
/// ([`crate::ProvenanceMap::dominant_tier`],
/// [`crate::ProvenanceMap::peak_tier_count`]) pair on the tier
/// altitude, and the ([`crate::ConfigDiff::dominant_kind`],
/// [`crate::ConfigDiff::peak_kind_count`]) pair on the diff altitude.
/// Consumers answering *"which env-prefix kind dominated the chain
/// and by how many layers?"* now read a single
/// `(dominant_env_prefix_kind(), peak_env_prefix_kind_count())` pair
/// — one method each, both routing through the same primitive —
/// instead of re-deriving the count off the modal cell.
///
/// **Empty-histogram convention** — returns `0` (not
/// `Option<usize>`) matching the [`crate::AxisHistogram::peak_count`]
/// convention one altitude down, the [`Self::peak_layer_kind_count`]
/// convention on the layer-kind sub-axis, the
/// [`Self::peak_file_format_count`] convention on the file-format
/// sub-axis, and the [`crate::ProvenanceMap::peak_tier_count`] /
/// [`crate::ConfigDiff::peak_kind_count`] conventions on the peer
/// altitudes; the scalar reads `0` uniformly on the empty-histogram
/// boundary. Unlike [`Self::peak_layer_kind_count`], the zero
/// boundary is NOT `!self.as_ref().is_empty()`:
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] entries all
/// project to [`None`] through [`ConfigSource::env_prefix_kind`], so
/// the histogram is empty (and this scalar reads zero) even on a
/// non-empty chain when no `Env` entry contributes. The dual-form
/// [`Self::dominant_env_prefix_kind`] carries
/// `Option<EnvMetadataTagKind>` because the *kind* is undefined when
/// no env layer contributes; the *count* is well-defined as zero.
///
/// # Invariants
///
/// - `peak_env_prefix_kind_count() == 0 ⇔
/// env_prefix_kind_histogram().is_empty()` — peer to the
/// empty-histogram boundary [`Self::dominant_env_prefix_kind`] /
/// [`Self::recessive_env_prefix_kind`] both witness on the cell
/// side. Unlike [`Self::peak_layer_kind_count`], the zero boundary
/// is NOT `self.as_ref().is_empty()`: a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers
/// reads zero as well.
/// - `peak_env_prefix_kind_count() ==
/// env_prefix_kind_histogram().peak_count()` — both project the
/// same scalar off the same primitive; the named seam is the
/// cube-native routing of the chain-shape surface.
/// - `peak_env_prefix_kind_count() ==
/// dominant_env_prefix_kind().map_or(0, |k|
/// env_prefix_kind_histogram().count(k))` — the count projection
/// of the `(dominant_env_prefix_kind, peak_env_prefix_kind_count)`
/// modal pair equals [`Self::peak_env_prefix_kind_count`]
/// pointwise on every chain (empty-histogram: `None.map_or(0, …)
/// == 0 == peak_env_prefix_kind_count`; non-empty-histogram:
/// `Some(k).map_or(0, |k| count(k)) == peak_env_prefix_kind_count`,
/// since `count(dominant_env_prefix_kind()) == peak_count()`).
/// - `peak_env_prefix_kind_count() ==
/// env_prefix_kind_histogram().total()` iff
/// `present_env_prefix_kinds().len() <= 1` — the peak equals the
/// histogram total exactly when zero or one kind is observed.
/// Lifted from the trait-uniform `peak_count() == total()` law on
/// [`crate::AxisHistogram`].
/// - `peak_env_prefix_kind_count() <=
/// layer_kind_histogram().count(ConfigSourceKind::Env)` always:
/// the peak on the env-prefix-presence sub-axis is bounded above
/// by the count of `Env` layers on the layer-kind sub-axis (every
/// env-prefix-kind projection comes from an `Env` layer; the
/// histogram total equals the `Env` layer count). Equality holds
/// whenever the histogram is non-empty and there are no non-`Env`
/// projections — always true on this axis since only `Env` layers
/// contribute.
/// - `peak_env_prefix_kind_count() >= 1` whenever
/// `!env_prefix_kind_histogram().is_empty()` — a non-empty
/// histogram always has at least one env layer on the dominant
/// kind.
/// - `peak_env_prefix_kind_count()` on a uniform full-cover chain
/// (one env layer per kind — one bare + one prefixed) equals `1`
/// — every observed kind collects one env layer, dominant
/// included.
/// - `peak_env_prefix_kind_count()` on a singleton-support chain
/// (every env layer on the same kind) equals
/// `env_prefix_kind_histogram().total()` — the dominant kind
/// collects every env layer.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// argmax scan). Both are `O(n)` in practice since the env-prefix-
/// presence axis carries a fixed two-cell cardinality; the returned
/// `usize` reads one scalar. Halves the cost of the previous
/// `dominant_env_prefix_kind().map_or(0, |k|
/// env_prefix_kind_histogram().count(k))` idiom (which walked the
/// histogram twice — once to argmax, once to read the count back).
#[must_use]
fn peak_env_prefix_kind_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().peak_count()
}
/// The **trough env-prefix-kind layer count** — the number of
/// [`ConfigSource::Env`] layers contributed by the recessive
/// (rarest-observed) [`EnvMetadataTagKind`] on this chain. Returns
/// `0` when the [`Self::env_prefix_kind_histogram`] is empty (no
/// chain entry projects through [`ConfigSource::env_prefix_kind`] —
/// i.e. an empty chain, OR a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] entries);
/// otherwise returns the env-layer count carried by
/// [`Self::recessive_env_prefix_kind`] (pointwise equal to it, and
/// always `>= 1` by the histogram-support definition).
///
/// The **scalar peer** of [`Self::recessive_env_prefix_kind`] on the
/// count side — the natural typed primitive for chain-shape
/// dashboards, attestation manifests, and alerting policies asking
/// *"how many env layers did the runt prefix kind contribute?"*: the
/// CLI `config-show` summary line *"runt env-prefix: bare, 1 of 4
/// env layers"* (where 1 is this scalar), the attestation manifest
/// recording the trough env-prefix-kind observation count between
/// two `ProviderChain` snapshots, the alerting policy reading
/// *"env-prefix trough count = 1"* to flag a rebuild window where a
/// prefix kind barely contributed to the env recipe. Before this
/// lift, every such consumer re-derived the projection inline as
/// `chain.env_prefix_kind_histogram().trough_count()` or
/// (equivalently but at twice the cost)
/// `chain.recessive_env_prefix_kind().map_or(0, |k|
/// chain.env_prefix_kind_histogram().count(k))` — which walked the
/// histogram *twice* (once to argmin over the support, once to read
/// the count back through [`crate::AxisHistogram::count`] indexing)
/// and re-built the histogram at every site. Routes through
/// [`Self::env_prefix_kind_histogram`]:
/// [`crate::AxisHistogram::trough_count`] reads a single pass over
/// the fixed-cardinality counts vector (filtering the zero-count
/// cells out of the argmin search).
///
/// The chain-altitude scalar-count peer of
/// [`Self::recessive_env_prefix_kind`] (the anti-modal-cell scalar
/// peer of [`Self::env_prefix_kind_histogram`]) — the
/// env-prefix-presence sub-axis of the chain-shape surface now
/// carries the fused `(recessive_env_prefix_kind,
/// trough_env_prefix_kind_count)` anti-modal pair, matching the
/// ([`crate::AxisHistogram::recessive_cell`],
/// [`crate::AxisHistogram::trough_count`]) pair on the shared
/// [`crate::AxisHistogram`] primitive one altitude down, the
/// ([`Self::recessive_layer_kind`], [`Self::trough_layer_kind_count`])
/// pair on the layer-kind sub-axis of the same chain altitude, the
/// ([`Self::recessive_file_format`],
/// [`Self::trough_file_format_count`]) pair on the file-format
/// sub-axis of the same chain altitude, the
/// ([`crate::ProvenanceMap::recessive_tier`],
/// [`crate::ProvenanceMap::trough_tier_count`]) pair on the tier
/// altitude, and the ([`crate::ConfigDiff::recessive_kind`],
/// [`crate::ConfigDiff::trough_kind_count`]) pair on the diff
/// altitude. Consumers answering *"which env-prefix kind is the
/// runt of the chain and by how few layers?"* now read a single
/// `(recessive_env_prefix_kind(), trough_env_prefix_kind_count())`
/// pair — one method each, both routing through the same primitive
/// — instead of re-deriving the count off the anti-modal cell.
///
/// The 2×2 `(dominant, recessive) × (cell, count)` scalar grid on
/// the env-prefix-presence sub-axis of the chain-shape surface
/// closes with this lift: the four seams
/// ([`Self::dominant_env_prefix_kind`],
/// [`Self::peak_env_prefix_kind_count`],
/// [`Self::recessive_env_prefix_kind`],
/// [`Self::trough_env_prefix_kind_count`]) now each route through
/// the same [`Self::env_prefix_kind_histogram`] primitive at one
/// pass per projection, matching the closed `(dominant, peak,
/// recessive, trough)` quad on the layer-kind sub-axis of the same
/// chain altitude, the closed quad on the file-format sub-axis of
/// the same chain altitude, the shared [`crate::AxisHistogram`]
/// primitive one altitude down, the tier altitude, and the diff
/// altitude. All three chain-shape sub-axes now carry the closed
/// modal / anti-modal `(cell, count)` quad at named seams.
///
/// **Empty-histogram convention** — returns `0` (not
/// `Option<usize>`) matching the [`crate::AxisHistogram::trough_count`]
/// convention one altitude down, the
/// [`Self::peak_env_prefix_kind_count`] convention on the same
/// sub-axis, the [`Self::trough_layer_kind_count`] convention on
/// the layer-kind sub-axis, the [`Self::trough_file_format_count`]
/// convention on the file-format sub-axis, and the
/// [`crate::ProvenanceMap::trough_tier_count`] /
/// [`crate::ConfigDiff::trough_kind_count`] conventions on the peer
/// altitudes; the scalar `(peak_env_prefix_kind_count,
/// trough_env_prefix_kind_count)` pair reads uniformly `(0, 0)` on
/// the empty-histogram boundary. Unlike
/// [`Self::trough_layer_kind_count`], the zero boundary is NOT
/// `self.as_ref().is_empty()`: [`ConfigSource::Defaults`] /
/// [`ConfigSource::File`] entries all project to [`None`] through
/// [`ConfigSource::env_prefix_kind`], so the histogram is empty
/// (and this scalar reads zero) even on a non-empty chain when no
/// `Env` entry contributes. The dual-form
/// [`Self::recessive_env_prefix_kind`] carries
/// `Option<EnvMetadataTagKind>` because the *kind* is undefined
/// when no env layer contributes; the *count* is well-defined as
/// zero.
///
/// # Invariants
///
/// - `trough_env_prefix_kind_count() == 0 ⇔
/// env_prefix_kind_histogram().is_empty()` — peer to the
/// empty-histogram boundary [`Self::dominant_env_prefix_kind`] /
/// [`Self::recessive_env_prefix_kind`] both witness on the cell
/// side, and [`Self::peak_env_prefix_kind_count`] witnesses on
/// the modal count side. Unlike [`Self::trough_layer_kind_count`],
/// the zero boundary is NOT `self.as_ref().is_empty()`: a
/// non-empty chain of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::File`] layers reads zero as well.
/// - `trough_env_prefix_kind_count() ==
/// env_prefix_kind_histogram().trough_count()` — both project the
/// same scalar off the same primitive; the named seam is the
/// cube-native routing of the chain-shape surface.
/// - `trough_env_prefix_kind_count() ==
/// recessive_env_prefix_kind().map_or(0, |k|
/// env_prefix_kind_histogram().count(k))` — the count projection
/// of the `(recessive_env_prefix_kind,
/// trough_env_prefix_kind_count)` anti-modal pair equals
/// [`Self::trough_env_prefix_kind_count`] pointwise on every
/// chain (empty-histogram: `None.map_or(0, …) == 0 ==
/// trough_env_prefix_kind_count`; non-empty-histogram:
/// `Some(k).map_or(0, |k| count(k)) ==
/// trough_env_prefix_kind_count`, since
/// `count(recessive_env_prefix_kind()) == trough_count()`).
/// - `trough_env_prefix_kind_count() <= peak_env_prefix_kind_count()`
/// always: the trough is bounded above by the peak (lifted from
/// the trait-uniform `trough_count() <= peak_count()` law on
/// [`crate::AxisHistogram`]). The empty-histogram case reads `0
/// <= 0`; the non-empty-histogram case reads the trough-of-support
/// bounded above by the peak-of-support.
/// - `trough_env_prefix_kind_count() <=
/// layer_kind_histogram().count(ConfigSourceKind::Env)` always:
/// the trough on the env-prefix-presence sub-axis is bounded
/// above by the count of `Env` layers on the layer-kind sub-axis
/// (every env-prefix-kind projection comes from an `Env` layer;
/// the histogram total equals the `Env` layer count). Cross-sub-
/// axis exact-total equality
/// `env_prefix_kind_histogram().total() ==
/// layer_kind_histogram().count(Env)` — a stronger relation than
/// the file-format sub-axis carries, since
/// [`ConfigSource::env_prefix_kind`] is total over `Env` layers
/// while [`ConfigSource::file_format`] is partial over `File`
/// layers.
/// - `trough_env_prefix_kind_count() == peak_env_prefix_kind_count()`
/// iff `present_env_prefix_kinds().len() <= 1` — the two-cell
/// env-prefix-presence axis carries the tight bidirectional
/// equivalence: zero (empty-histogram, both zero), one
/// (singleton-support, every env layer on the same kind, both
/// equal `env_prefix_kind_histogram().total()`), two (both cells
/// observed, distinct counts by pigeonhole on any non-uniform
/// distribution — the uniform-full-cover degenerate at 1-1 lifts
/// `present_env_prefix_kinds().len() > 1` to `trough == peak`
/// without violating the bidirectional pin, since the equivalence
/// is against `<= 1` on the support, not on `== peak`). This is
/// the modal-count bidirectional equivalence
/// [`Self::trough_file_format_count`] one sub-axis over pins
/// one-directionally only (four-cell axis with uniform-cover
/// ambiguity); the two-cell env-prefix-presence axis lifts it to
/// the tighter iff on the support side.
/// - `trough_env_prefix_kind_count() >= 1` whenever
/// `!env_prefix_kind_histogram().is_empty()` — the argmin is
/// taken over the histogram's *support* (nonzero cells), so the
/// trough of a non-empty histogram is always at least one.
/// - `trough_env_prefix_kind_count()` on a uniform full-cover chain
/// (one env layer per kind — one bare + one prefixed) equals `1`
/// — every observed kind collects one env layer; the trough
/// coincides with the peak on the uniform-cover degenerate (the
/// singleton-modality analogue on the count side).
/// - `trough_env_prefix_kind_count()` on a singleton-support chain
/// (every env layer on the same kind) equals
/// `env_prefix_kind_histogram().total()` — the sole observed
/// kind is both the modal and anti-modal cell, so `trough == peak
/// == total`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// argmin scan over the support). Both are `O(n)` in practice since
/// the env-prefix-presence axis carries a fixed two-cell
/// cardinality; the returned `usize` reads one scalar. Halves the
/// cost of the previous `recessive_env_prefix_kind().map_or(0, |k|
/// env_prefix_kind_histogram().count(k))` idiom (which walked the
/// histogram twice — once to argmin, once to read the count back).
#[must_use]
fn trough_env_prefix_kind_count(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().trough_count()
}
/// The **env-prefix-presence spread** — the difference between the
/// peak and trough env-layer counts across the observed
/// [`EnvMetadataTagKind`] cells on this chain. Equal to
/// `self.peak_env_prefix_kind_count() -
/// self.trough_env_prefix_kind_count()` by construction. Routes
/// through [`Self::env_prefix_kind_histogram`]:
/// [`crate::AxisHistogram::spread`] reads a single pass over the
/// fixed-cardinality counts vector (fusing the max-over-axis /
/// min-over-support pair into one running scan). The env-prefix-
/// presence sub-axis lift of the "spread across altitudes" projection
/// seeded on the diff altitude by [`crate::ConfigDiff::kind_spread`],
/// climbed to the tier altitude by
/// [`crate::ProvenanceMap::tier_spread`], and lifted sideways to the
/// layer-kind sub-axis by [`Self::layer_kind_spread`] and to the file-
/// format sub-axis by [`Self::file_format_spread`]. Returns `0`
/// exactly on every chain whose env-prefix histogram is empty (an
/// empty chain, OR a non-empty chain of only [`ConfigSource::Defaults`]
/// / [`ConfigSource::File`] entries — no [`ConfigSource::Env`] layer
/// contributes), every singleton-support chain (only one observed
/// env-prefix kind — every `Env` layer bare, or every `Env` layer
/// prefixed; trivially balanced), and every uniform per-kind chain
/// (the same nonzero env-layer count on both cells).
///
/// The **scalar dispersion peer** of the fused
/// `(peak_env_prefix_kind_count, trough_env_prefix_kind_count)`
/// modal-count pair on the env-prefix-presence sub-axis of the chain
/// altitude — the natural typed primitive for chain-shape dashboards,
/// attestation manifests, and alerting policies asking *"how unevenly
/// distributed are the env layers across bare vs prefixed?"*: the CLI
/// `config-show` summary line *"env prefix skew 2: Prefixed owns 3 of
/// 4 env layers, Bare 1 of 4"* (where 2 is this scalar), the
/// attestation manifest recording the env-prefix spread between two
/// `ProviderChain` snapshots, the alerting policy reading *"chain env
/// prefix spread = 2"* to flag a rebuild window where one env-prefix
/// kind dwarfed the other. Before this lift, every such consumer
/// re-derived the projection inline as
/// `chain.peak_env_prefix_kind_count() -
/// chain.trough_env_prefix_kind_count()` — two method calls plus a
/// subtraction at every site, each site having to reason
/// independently about the structural non-negativity of the
/// difference (`peak_env_prefix_kind_count() >=
/// trough_env_prefix_kind_count()` holds on every chain by lifting
/// the trait-uniform `peak_count() >= trough_count()` law on
/// [`crate::AxisHistogram`], but not on the inline subtraction
/// surface — an unwitnessed refactor swapping the operands would
/// silently underflow). Routes through
/// [`crate::AxisHistogram::spread`] one altitude down — the
/// underflow-safe named seam whose docs pin the monotonicity
/// invariant explicitly.
///
/// The env-prefix-presence sub-axis lift in the "spread across
/// altitudes" projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kind_spread`], climbed to the tier altitude
/// by [`crate::ProvenanceMap::tier_spread`], and lifted sideways to
/// the layer-kind sub-axis of the same chain altitude by
/// [`Self::layer_kind_spread`] and to the file-format sub-axis by
/// [`Self::file_format_spread`]. The pattern is the same at every
/// altitude: fuse the (`peak_count`, `trough_count`) modal-count
/// pair into a single dispersion scalar named at the surface, routed
/// through the shared [`crate::AxisHistogram::spread`] primitive one
/// altitude down. This closes the chain-altitude sub-axis spread
/// family — the chain-shape "spread across altitudes" triple
/// `(layer_kind_spread, file_format_spread, env_prefix_kind_spread)`
/// now spans every sub-axis of the chain surface.
///
/// **Empty-histogram convention** — returns `0`, matching the
/// [`crate::AxisHistogram::spread`] empty convention one altitude
/// down and the [`Self::peak_env_prefix_kind_count`] /
/// [`Self::trough_env_prefix_kind_count`] empty conventions on the
/// same sub-axis. The scalar-count triple
/// `(peak_env_prefix_kind_count, trough_env_prefix_kind_count,
/// env_prefix_kind_spread)` reads uniformly `(0, 0, 0)` on the empty
/// histogram. Like [`Self::file_format_spread`] and unlike
/// [`Self::layer_kind_spread`], the zero-boundary is NOT
/// `self.as_ref().is_empty()`: a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers is
/// non-empty but has an empty env-prefix histogram (those entries
/// project to [`None`] through [`ConfigSource::env_prefix_kind`]) —
/// the empty-boundary is the sub-axis histogram's `is_empty()`, not
/// the chain's. Unlike [`Self::file_format_spread`], the empty-
/// histogram / no-`Env`-layers condition is exactly the layer-kind
/// `count(ConfigSourceKind::Env) == 0` condition: every `Env` entry
/// projects to a `Some` cell regardless of prefix value (the empty-
/// prefix case maps to [`EnvMetadataTagKind::Bare`], every non-empty
/// prefix maps to [`EnvMetadataTagKind::Prefixed`]), so no `Env`
/// entry is silently dropped by the projection the way an
/// unrecognized-extension `File` entry is on the file-format sub-
/// axis.
///
/// **Structural-skew predicate.** `env_prefix_kind_spread() == 0` is
/// the typed *balanced-env-prefixes* predicate at the env-prefix-
/// presence sub-axis of the chain altitude — bare and prefixed env
/// layers contributed the same count. Pointwise equivalent to
/// `peak_env_prefix_kind_count() == trough_env_prefix_kind_count()`
/// on the scalar-count pair and to `dominant_env_prefix_kind() ==
/// recessive_env_prefix_kind()` on the modal-cell pair whenever the
/// env-prefix histogram is non-empty (both branches reduce to
/// `Some(first) == Some(first)` on singleton-support and uniform-
/// cover chains, and to `false` on skewed chains). Together with
/// `env_prefix_kind_histogram().is_empty()` and the full-cover
/// predicate on [`Self::env_prefix_kind_histogram`], the env-prefix
/// sub-axis of the chain-shape surface now carries the natural
/// boundary triple *"did any env layer contribute?"* / *"did both
/// kinds fire?"* / *"did the kinds fire equally?"* — each a single
/// method call.
///
/// # Invariants
///
/// - `env_prefix_kind_spread() == env_prefix_kind_histogram().spread()`
/// — both project the same scalar off the same primitive; the
/// named seam is the cube-native routing of the histogram surface.
/// - `env_prefix_kind_spread() == peak_env_prefix_kind_count() -
/// trough_env_prefix_kind_count()` — the fused-pair identity of
/// the scalar-dispersion peer. The subtraction is underflow-safe
/// because `peak_env_prefix_kind_count() >=
/// trough_env_prefix_kind_count()` holds structurally on every
/// chain (lifted from the trait-uniform `peak_count() >=
/// trough_count()` law on [`crate::AxisHistogram`]).
/// - `env_prefix_kind_spread() == 0` on every chain whose env-prefix
/// histogram is empty — the vacuous uniformity boundary, matching
/// the [`crate::AxisHistogram::spread`] empty convention one
/// altitude down. The `(peak_env_prefix_kind_count,
/// trough_env_prefix_kind_count, env_prefix_kind_spread)` triple
/// reads `(0, 0, 0)` uniformly. Like
/// [`Self::file_format_spread`] and unlike
/// [`Self::layer_kind_spread`], the zero boundary is NOT
/// `self.as_ref().is_empty()`: a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers
/// reads zero as well.
/// - `env_prefix_kind_spread() == 0` whenever
/// `present_env_prefix_kinds().len() <= 1` — the empty-histogram
/// case (no observed kind, trivially balanced) and the singleton-
/// support case (the one observed kind's count is both the peak
/// and the trough). Also holds on every uniform per-kind chain
/// (each observed kind contributing the same nonzero count,
/// dominant included).
/// - `env_prefix_kind_spread() <= peak_env_prefix_kind_count()`
/// always — the trough is non-negative, so the subtraction is
/// bounded above by the minuend. Equality holds iff the trough is
/// zero — i.e. iff `env_prefix_kind_histogram().is_empty()`.
/// Lifted from the trait-uniform `spread() <= peak_count()` law
/// on [`crate::AxisHistogram`]. Cross-sub-axis divergence from
/// [`Self::layer_kind_spread`], where the equality-case coincides
/// with `self.as_ref().is_empty()`; agreement with
/// [`Self::file_format_spread`], where the equality-case coincides
/// with `file_format_histogram().is_empty()` on the sister sub-
/// axis.
/// - `env_prefix_kind_spread() <= env_prefix_kind_histogram().total()`
/// always — composition of `env_prefix_kind_spread() <=
/// peak_env_prefix_kind_count()` (this method) with
/// `peak_env_prefix_kind_count() <=
/// env_prefix_kind_histogram().total()` (documented on
/// [`Self::peak_env_prefix_kind_count`]). The histogram total
/// equals `layer_kind_histogram().count(ConfigSourceKind::Env)`
/// pointwise — strict equality, not the inequality bound the
/// file-format histogram carries; every `Env` layer contributes
/// to the env-prefix histogram, while only recognized-extension
/// `File` layers contribute to the file-format histogram.
/// - `env_prefix_kind_spread() <= self.as_ref().len()` always —
/// composition of the above with
/// `env_prefix_kind_histogram().total() <= self.as_ref().len()`
/// (every env layer is a chain entry). The chain-length bound the
/// layer-kind sub-axis carries at cell-count tightness; the env-
/// prefix sub-axis carries it with the env-layer-count slack.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// fused peak-and-trough scan). Both are `O(n)` in practice since
/// the env-prefix-presence axis carries a fixed two-cell
/// cardinality; the returned `usize` reads one scalar. Halves the
/// cost of the previous inline `chain.peak_env_prefix_kind_count() -
/// chain.trough_env_prefix_kind_count()` idiom (which walked the
/// counts vector twice — once for the max, once for the min-over-
/// support — where [`crate::AxisHistogram::spread`] can fuse both
/// into a single walk with a running-max/min pair).
#[must_use]
fn env_prefix_kind_spread(&self) -> usize
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().spread()
}
/// The **balanced-env-prefix-kinds boolean predicate** on the env-
/// prefix-presence sub-axis of the chain altitude — `true` exactly when
/// every observed [`EnvMetadataTagKind`] contributed the same number of
/// [`ConfigSource::Env`] layers (bare and prefixed env layers fired at
/// equal counts, or the chain observed at most one kind). The typed
/// boolean peer of `env_prefix_kind_spread() == 0` on the scalar-
/// dispersion surface, lifting the same structural-skew boundary from
/// the scalar surface to a named predicate at the env-prefix sub-axis
/// of the chain altitude. Routes through
/// [`crate::AxisHistogram::is_uniform_count`] one altitude down: the
/// single-pass scan over the fixed-cardinality counts vector that
/// short-circuits on the first pair of distinct nonzero cells, tighter
/// than the two-scan [`Self::peak_env_prefix_kind_count`] /
/// [`Self::trough_env_prefix_kind_count`] fusion the scalar-spread form
/// pays for.
///
/// The **balanced-env-prefix-kinds peer** of the fused
/// `(peak_env_prefix_kind_count, trough_env_prefix_kind_count,
/// env_prefix_kind_spread)` dispersion triple on the env-prefix sub-
/// axis of the chain altitude — the natural typed boolean primitive
/// for per-env-prefix dashboards, attestation manifests, and alerting
/// policies asking *"did every observed env-prefix kind fire
/// equally?"*: the CLI `config-show` headline *"balanced recipe: bare
/// and prefixed env layers fired at equal counts"*, the attestation
/// manifest gate *"rebuild window balanced across env-prefix kinds"*,
/// the alerting policy predicate *"chain balanced by env-prefix"*.
/// Before this lift, every such consumer re-derived the predicate
/// inline as `chain.env_prefix_kind_spread() == 0` (the scalar-spread
/// form, which routes through a subtraction whose underflow safety
/// relies on the structural `peak >= trough` invariant on
/// [`Self::env_prefix_kind_spread`]), or as
/// `chain.peak_env_prefix_kind_count() ==
/// chain.trough_env_prefix_kind_count()` (the scalar-pair form, which
/// pays for two count walks and equates two `usize`s without saying
/// structurally *what* is being equated), or as
/// `chain.dominant_env_prefix_kind() ==
/// chain.recessive_env_prefix_kind()` (the modal-pair form, which
/// peers through `Option<EnvMetadataTagKind>` equality across two
/// argmax/argmin walks). The three forms drifted in subtle ways at
/// every consumer site. This lift names the balanced-env-prefix-kinds
/// predicate directly at the env-prefix sub-axis with a single-pass
/// short-circuiting scan — the typed boolean every operator-facing
/// "is this recipe balanced by env-prefix?" check reads off as a
/// single method call.
///
/// The env-prefix sub-axis lift in the "balanced across altitudes"
/// projection seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_balanced`], climbed to the tier altitude
/// by [`crate::ProvenanceMap::tiers_balanced`], and lifted sideways to
/// the first chain sub-axis by [`Self::layer_kinds_balanced`] and to
/// the file-format sub-axis by [`Self::file_formats_balanced`]. The
/// pattern is the same at every altitude / sub-axis: fuse the
/// (`peak_count`, `trough_count`, `spread`) scalar triple's balanced-
/// boundary into a single boolean predicate named at the surface,
/// routed through the shared
/// [`crate::AxisHistogram::is_uniform_count`] primitive one altitude
/// down. Parallels the "spread across altitudes" projection lifted to
/// the same sub-axis by [`Self::env_prefix_kind_spread`]. This closes
/// the chain-altitude sub-axis balanced family — the chain-shape
/// "balanced across altitudes" triple `(layer_kinds_balanced,
/// file_formats_balanced, env_prefix_kinds_balanced)` now spans every
/// sub-axis of the chain surface, matching the fully-covered scalar-
/// spread triple `(layer_kind_spread, file_format_spread,
/// env_prefix_kind_spread)` one dispersion surface over.
///
/// **Empty-histogram convention** — returns `true` vacuously on every
/// chain whose env-prefix histogram is empty: no observed cells, so
/// the universal "every observed cell carries the same count" reads
/// `true` over the empty support. Matches
/// [`crate::AxisHistogram::is_uniform_count`]'s empty convention one
/// altitude down and `env_prefix_kind_spread() == 0` on the empty case
/// (peak == trough == 0). Like [`Self::file_formats_balanced`] and
/// unlike [`Self::layer_kinds_balanced`], the `true` boundary is NOT
/// `self.as_ref().is_empty()`: a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers is
/// trivially balanced under this predicate as well (empty histogram).
/// Unlike [`Self::file_formats_balanced`], the empty-histogram / no-
/// `Env`-layers condition is exactly the layer-kind
/// `count(ConfigSourceKind::Env) == 0` condition: every `Env` entry
/// projects to a `Some` cell regardless of prefix value, so no `Env`
/// entry is silently dropped by the projection the way an
/// unrecognized-extension `File` entry is on the file-format sub-axis.
///
/// **Singleton-support convention** — returns `true` on every chain
/// whose observed support is a single [`EnvMetadataTagKind`] (trivially
/// balanced: the one observed kind's count is both the peak and the
/// trough). Includes every prefixed-only chain (all env layers carry
/// non-empty prefixes) and every bare-only chain (all env layers carry
/// the empty prefix).
///
/// **Uniform per-kind convention** — returns `true` on every uniform
/// per-kind chain (each observed kind contributing the same nonzero
/// count), including the k-kind-observed-once-each shape and the
/// uniform full-cover shape over both [`EnvMetadataTagKind`] cells.
///
/// # Invariants
///
/// - `env_prefix_kinds_balanced() == env_prefix_kind_histogram().is_uniform_count()` —
/// both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram surface.
/// - `env_prefix_kinds_balanced() == (env_prefix_kind_spread() == 0)` always —
/// the defining equivalence on the scalar-spread surface at the
/// env-prefix sub-axis.
/// - `env_prefix_kinds_balanced() == (peak_env_prefix_kind_count() ==
/// trough_env_prefix_kind_count())` always — the structural form on
/// the underlying scalar pair.
/// - `env_prefix_kinds_balanced() == (dominant_env_prefix_kind() ==
/// recessive_env_prefix_kind())` always — the modal-pair form; both
/// branches agree on the empty-histogram chain (`None == None`), on
/// every singleton-support chain (`Some(k) == Some(k)`), on every
/// uniform per-kind chain (`Some(first_kind) == Some(first_kind)`
/// after declaration-order tie-break), and on every skewed chain
/// (both sides read `false`).
/// - `env_prefix_kind_histogram().is_empty() ⇒ env_prefix_kinds_balanced()` —
/// vacuous uniformity on every chain whose env-prefix histogram is
/// empty (empty chain, or non-empty chain of only Defaults / File
/// layers). Contrapositively, `!env_prefix_kinds_balanced() ⇒
/// !env_prefix_kind_histogram().is_empty()` (a skewed chain has at
/// least two distinct positive counts, so the histogram is non-
/// empty). Agreement with [`Self::file_formats_balanced`], where the
/// vacuous-uniformity implication reads on the histogram-empty
/// predicate too; cross-sub-axis divergence from
/// [`Self::layer_kinds_balanced`], where the vacuous-uniformity
/// implication reads on `self.as_ref().is_empty()` instead.
/// - `present_env_prefix_kinds().len() <= 1 ⇒ env_prefix_kinds_balanced()` —
/// every chain with env-prefix support size 0 or 1 is trivially
/// balanced. Contrapositively, `!env_prefix_kinds_balanced() ⇒
/// present_env_prefix_kinds().len() >= 2` (a skewed chain observes
/// both bare and prefixed env kinds with differing counts).
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// uniform-count scan). Both are `O(n)` in practice since the env-
/// prefix-presence axis carries a fixed two-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits on
/// the first pair of distinct nonzero cells (bounded at two nonzero
/// cells visited), strictly tighter than the two-full-scan
/// `peak_env_prefix_kind_count()` / `trough_env_prefix_kind_count()`
/// fusion the scalar-spread form pays for on skewed chains.
#[must_use]
fn env_prefix_kinds_balanced(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().is_uniform_count()
}
/// Named typed boolean predicate — `true` exactly when every
/// [`EnvMetadataTagKind`] cell was observed at least once on this
/// chain's [`ConfigSource::Env`] layers (every cell of the closed
/// [`EnvMetadataTagKind`] axis has a nonzero count on the recipe's
/// env-prefix histogram). Routes through
/// [`Self::env_prefix_kind_histogram`]'s
/// [`crate::AxisHistogram::is_full_cover`], the cube-native single-
/// pass short-circuiting scan over the fixed-cardinality counts
/// vector one altitude down.
///
/// Operator-facing consumers answering *"did every env-prefix kind
/// fire on this recipe?"* — the CLI `config-show` headline *"full-
/// cover recipe: every env-prefix kind fired at least once"*, the
/// attestation manifest gate *"rebuild window full-cover across env
/// prefixes"*, the alerting policy predicate *"recipe full-cover by
/// env-prefix"* — now route through this named seam instead of four
/// previously drifting inline forms:
/// `chain.absent_env_prefix_kinds().is_empty()` (the coverage-gap-
/// `Vec` form, which allocates a `Vec<EnvMetadataTagKind>` and reads
/// its emptiness), `chain.absent_env_prefix_kinds_count() == 0` (the
/// coverage-gap-scalar form, which pays for a full-axis scan and
/// equates a `usize` to zero without saying structurally *what* is
/// being equated), `chain.present_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>()` (the support-
/// scalar form, which pays for the support scan and pulls in the
/// `axis_cardinality` turbofish at every call site), and
/// `chain.present_env_prefix_kinds().len() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>()` (the support-
/// `Vec` form, which allocates a `Vec<EnvMetadataTagKind>` and reads
/// its length back). Pointwise-equivalent with
/// `env_prefix_kind_histogram().unobserved_cells() == 0`,
/// `env_prefix_kind_histogram().distinct_cells() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>()`, and
/// `env_prefix_kind_histogram().unobserved().next().is_none()` one
/// altitude down.
///
/// **Closes the "full-cover across altitudes" projection** across
/// every altitude / sub-axis. Seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_full_cover`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_full_cover`], and lifted
/// sideways to the chain altitude's sister sub-axes by
/// [`Self::layer_kinds_full_cover`] over
/// [`Self::layer_kind_histogram`] and
/// [`Self::file_formats_full_cover`] over
/// [`Self::file_format_histogram`]; this lift closes the third and
/// final chain-altitude sub-axis, matching the fully-covered chain-
/// shape triples `(layer_kinds_balanced, file_formats_balanced,
/// env_prefix_kinds_balanced)` and `(layer_kind_spread,
/// file_format_spread, env_prefix_kind_spread)` one boundary /
/// dispersion surface over. The chain-shape "full-cover across
/// altitudes" triple `(layer_kinds_full_cover, file_formats_full_cover,
/// env_prefix_kinds_full_cover)` now spans every sub-axis of the
/// chain surface.
///
/// **Empty-histogram convention** — returns `false` on every chain
/// whose env-prefix histogram is empty (no [`ConfigSource::Env`]
/// layers): no observed cells means the coverage gap equals every
/// cell of [`EnvMetadataTagKind::ALL`] — the full-cover predicate
/// fails. Matches [`crate::AxisHistogram::is_full_cover`]'s empty-
/// histogram convention one altitude down on the non-zero-cardinality
/// [`EnvMetadataTagKind`] axis (two cells: `Prefixed`, `Bare`).
/// Agreement with [`Self::file_formats_full_cover`]'s empty-histogram
/// / non-empty-chain divergence: a non-empty chain of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers ALSO
/// reads `false` (the histogram is empty even though the chain is
/// not). Cross-sub-axis divergence from
/// [`Self::layer_kinds_full_cover`], where the empty-chain boundary
/// reads on `self.as_ref().is_empty()` instead of the histogram-empty
/// predicate. Unlike [`Self::file_formats_full_cover`], the empty-
/// histogram / no-`Env`-layers condition is exactly the layer-kind
/// `count(ConfigSourceKind::Env) == 0` condition: every `Env` entry
/// projects to a `Some` cell regardless of prefix value, so no `Env`
/// entry is silently dropped by the projection the way an
/// unrecognized-extension `File` entry is on the file-format sub-
/// axis. Dual of the vacuous-uniformity witness on
/// [`Self::env_prefix_kinds_balanced`], which reads `true` on every
/// empty-histogram chain: full-cover and balanced fall on opposite
/// sides of the empty-histogram boundary at the env-prefix sub-axis,
/// matching the diff-altitude / tier-altitude / layer-kind / file-
/// format sub-axis empty-vs-empty orthogonality.
///
/// **Singleton-support convention** — returns `false` on every chain
/// whose observed support is a single [`EnvMetadataTagKind`]: one
/// observed cell out of two leaves one cell in the coverage gap, so
/// the full-cover predicate fails. Every prefixed-only chain (all env
/// layers carry non-empty prefixes) and every bare-only chain (all
/// env layers carry the empty prefix) is a witness.
///
/// **Uniform two-kind cover convention** — returns `true` on every
/// chain where each of the two [`EnvMetadataTagKind`] cells was
/// observed at least once (regardless of per-kind count). Includes
/// the k-kind-observed-once-each shape (one env layer per kind) and
/// every skewed two-kind cover.
///
/// **Two-cell-axis boundary — `!balanced ⇒ full_cover`** — unique
/// tightening on the two-cell env-prefix axis: any imbalance
/// necessarily observes both cells at differing nonzero counts, so
/// the imbalanced chain is automatically full-cover. Equivalently,
/// every chain is `env_prefix_kinds_balanced() ||
/// env_prefix_kinds_full_cover()` — the union covers the total. This
/// tightening does NOT lift to the three-cell layer-kind or four-cell
/// file-format sub-axes (where imbalance is compatible with partial
/// cover). Peer characterization of the two-cell axis carrying no
/// "imbalanced-and-not-full-cover" region.
///
/// # Invariants
///
/// - `env_prefix_kinds_full_cover() ==
/// env_prefix_kind_histogram().is_full_cover()` — both project the
/// same predicate off the same primitive; the named seam is the
/// cube-native routing of the histogram surface.
/// - `env_prefix_kinds_full_cover() == absent_env_prefix_kinds().is_empty()`
/// always — the defining equivalence on the coverage-gap-`Vec`
/// surface at the env-prefix sub-axis.
/// - `env_prefix_kinds_full_cover() == (absent_env_prefix_kinds_count() ==
/// 0)` always — the defining equivalence on the coverage-gap-
/// scalar surface, without allocating the
/// `Vec<EnvMetadataTagKind>`.
/// - `env_prefix_kinds_full_cover() == (present_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>())` always — the
/// support-scalar form, the dual-side surfacing of the same
/// boolean across the (observed, unobserved) partition.
/// - `env_prefix_kinds_full_cover() == (present_env_prefix_kinds().len() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>())` always — the
/// support-`Vec` form, without allocating twice through
/// [`Vec::len`].
/// - `env_prefix_kinds_full_cover() ⇒
/// !env_prefix_kind_histogram().is_empty()` — a full-cover chain
/// observes at least one env layer per [`EnvMetadataTagKind`], so
/// the histogram is non-empty. Contrapositively,
/// `env_prefix_kind_histogram().is_empty() ⇒
/// !env_prefix_kinds_full_cover()` (the empty-histogram / full-
/// coverage-gap boundary). Agreement with
/// [`Self::file_formats_full_cover`], whose contrapositive also
/// reads on the *histogram-empty* condition; cross-sub-axis
/// divergence from [`Self::layer_kinds_full_cover`], where the
/// contrapositive reads on the *chain-empty* condition.
/// - `env_prefix_kinds_full_cover() ⇒ present_env_prefix_kinds().len() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>()` — a full-cover
/// chain observes every kind, so the support size equals the axis
/// cardinality. Contrapositively,
/// `present_env_prefix_kinds().len() <
/// crate::axis_cardinality::<EnvMetadataTagKind>() ⇒
/// !env_prefix_kinds_full_cover()`.
/// - `env_prefix_kinds_full_cover() ⇒
/// env_prefix_kind_histogram().total() >=
/// crate::axis_cardinality::<EnvMetadataTagKind>()` — a full-cover
/// chain observes at least one env layer per kind, so the
/// histogram total is bounded below by the axis cardinality.
/// - `env_prefix_kinds_full_cover() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::Env) >=
/// crate::axis_cardinality::<EnvMetadataTagKind>()` — a full-cover
/// chain observes at least one env layer per kind; every such
/// layer is a [`ConfigSource::Env`], so the layer-kind Env count
/// is bounded below by the env-prefix axis cardinality. Cross-
/// sub-axis lower-bound implication linking the env-prefix sub-
/// axis's full-cover boundary to the layer-kind sub-axis Env cell
/// count. Sister of the file-format sub-axis's
/// `file_formats_full_cover() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::File) >=
/// axis_cardinality::<Format>()` lower-bound.
/// - `!env_prefix_kinds_balanced() ⇒ env_prefix_kinds_full_cover()` —
/// two-cell-axis tightening: on the two-cell env-prefix axis, any
/// imbalance observes both cells at differing nonzero counts, so
/// the imbalanced chain is automatically full-cover. Equivalently,
/// `env_prefix_kinds_balanced() || env_prefix_kinds_full_cover()`
/// on every chain. This tightening does NOT lift to the three-cell
/// layer-kind or four-cell file-format sub-axes.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// full-cover scan). Both are `O(n)` in practice since the env-prefix
/// axis carries a fixed two-cell cardinality; the returned `bool`
/// reads one predicate. The scan short-circuits on the first zero
/// cell (bounded at one zero cell visited on a non-full-cover chain),
/// strictly tighter than the four coverage-gap equality forms — no
/// `Vec<EnvMetadataTagKind>` allocation, no [`crate::axis_cardinality`]
/// turbofish, no scalar equality against a magic axis-cardinality
/// constant.
#[must_use]
fn env_prefix_kinds_full_cover(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().is_full_cover()
}
/// Named typed boolean predicate — `true` exactly when at least one
/// [`EnvMetadataTagKind`] cell was observed on this chain's
/// [`ConfigSource::Env`] layers (at least one cell of the closed
/// [`EnvMetadataTagKind`] axis has a nonzero count on the recipe's
/// env-prefix histogram). Routes through
/// [`Self::env_prefix_kind_histogram`]'s
/// [`crate::AxisHistogram::is_empty`], negated: the cube-native
/// single-pass short-circuiting scan over the fixed-cardinality
/// counts vector one altitude down that returns on the first
/// nonzero cell.
///
/// Operator-facing consumers answering *"did any env-prefix kind
/// fire on this recipe at all?"* — the CLI `config-show` headline
/// *"non-empty env-prefix recipe: at least one env layer fired"*,
/// the attestation manifest gate *"rebuild window carries at least
/// one env-prefix observation"*, the alerting policy predicate
/// *"recipe has any env layer"* — now route through this named seam
/// instead of four previously drifting inline forms:
/// `!chain.env_prefix_kind_histogram().is_empty()` (the histogram-
/// nonempty form, which reads through the histogram primitive but
/// without a chain-level named seam),
/// `chain.present_env_prefix_kinds_count() > 0` (the support-scalar
/// form, which pays for a full-axis scan and compares a `usize` to
/// zero without naming the coverage-support boundary),
/// `!chain.present_env_prefix_kinds().is_empty()` (the support-
/// `Vec` form, which allocates a `Vec<EnvMetadataTagKind>` and
/// reads its emptiness back), and `chain.absent_env_prefix_kinds_count()
/// < crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// coverage-gap-scalar form, which pays for the coverage-gap scan
/// and pulls in the `axis_cardinality` turbofish at every call
/// site). Routes through `!AxisHistogram::is_empty` one altitude
/// down.
///
/// **Closes the "any-observed across altitudes" projection** across
/// every altitude / sub-axis. Seeded on the diff altitude by
/// [`crate::ConfigDiff::kinds_any_observed`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_any_observed`], and
/// lifted sideways to the chain-altitude sister sub-axes by
/// [`Self::layer_kinds_any_observed`] over
/// [`Self::layer_kind_histogram`] and
/// [`Self::file_formats_any_observed`] over
/// [`Self::file_format_histogram`]; this lift closes the third and
/// final chain-altitude sub-axis, matching the fully-covered chain-
/// shape triples `(layer_kinds_balanced, file_formats_balanced,
/// env_prefix_kinds_balanced)` and `(layer_kinds_full_cover,
/// file_formats_full_cover, env_prefix_kinds_full_cover)` one
/// boundary surface over. The chain-shape "any-observed across
/// altitudes" triple `(layer_kinds_any_observed,
/// file_formats_any_observed, env_prefix_kinds_any_observed)` now
/// spans every sub-axis of the chain surface.
///
/// **Empty-histogram convention** — returns `false` on every chain
/// whose env-prefix histogram is empty: no observed cells means the
/// any-observed predicate fails. Matches
/// [`crate::AxisHistogram::is_empty`]'s `true` reading on the empty
/// histogram one altitude down, projected through the negation
/// seam. Agreement with [`Self::file_formats_any_observed`]'s
/// same-sided convention at the empty-histogram / non-empty-chain
/// boundary: a non-empty chain of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::File`] layers ALSO reads `false` (the histogram
/// is empty even though the chain is not). Cross-sub-axis
/// divergence from [`Self::layer_kinds_any_observed`], where the
/// empty-chain boundary reads on `self.as_ref().is_empty()`
/// instead of the histogram-empty predicate. Unlike
/// [`Self::file_formats_any_observed`], the empty-histogram / no-
/// `Env`-layers condition is exactly the layer-kind
/// `count(ConfigSourceKind::Env) == 0` condition: every `Env` entry
/// projects to a `Some` cell regardless of prefix value, so no
/// `Env` entry is silently dropped by the projection the way an
/// unrecognized-extension `File` entry is on the file-format sub-
/// axis. Dual of the vacuous-uniformity witness on
/// [`Self::env_prefix_kinds_balanced`], which reads `true` on every
/// empty-histogram chain: any-observed and balanced fall on
/// opposite sides of the empty-histogram boundary at the env-prefix
/// sub-axis, matching the diff-altitude / tier-altitude / layer-
/// kind / file-format sub-axis (`any_observed`, `balanced`,
/// `full_cover`) empty-histogram polarity triple.
///
/// **Singleton-support convention** — returns `true` on every chain
/// whose observed support is a single [`EnvMetadataTagKind`] (one
/// observed cell out of two suffices for the any-observed
/// predicate). Every prefixed-only chain (all env layers carry
/// non-empty prefixes) and every bare-only chain (all env layers
/// carry the empty prefix) is a witness. Matches
/// [`Self::env_prefix_kinds_balanced`]'s `true` side on the
/// singleton and orthogonal to [`Self::env_prefix_kinds_full_cover`]'s
/// `false` side on the same singleton — the three boundaries
/// partition the singleton-support fixture into the polarity triple
/// (`any_observed`=true, `balanced`=true, `full_cover`=false).
///
/// **Uniform two-kind cover convention** — returns `true` on every
/// chain where each of the two [`EnvMetadataTagKind`] cells was
/// observed at least once. The uniform two-kind cover is on the
/// `true` side of all three coverage-support boundaries
/// (`any_observed`, `balanced`, `full_cover`).
///
/// **Two-cell-axis boundary — `any_observed ⇔ !balanced ∨ full_cover`**
/// — unique tightening on the two-cell env-prefix axis: because
/// `env_prefix_kinds_balanced || env_prefix_kinds_full_cover`
/// covers every chain, the `false` side of `any_observed` is
/// exactly the intersection `balanced ∧ !full_cover ∧
/// histogram.is_empty()` — every non-empty-histogram chain
/// automatically reads `true` on `any_observed`. This tightening
/// does NOT lift to the three-cell layer-kind or four-cell file-
/// format sub-axes.
///
/// # Invariants
///
/// - `env_prefix_kinds_any_observed() ==
/// !env_prefix_kind_histogram().is_empty()` — both project the
/// same predicate off the same primitive; the named seam is the
/// cube-native routing of the histogram surface.
/// - `env_prefix_kinds_any_observed() == (present_env_prefix_kinds_count() >
/// 0)` always — the support-scalar surface, without allocating
/// the `Vec<EnvMetadataTagKind>`.
/// - `env_prefix_kinds_any_observed() == !present_env_prefix_kinds().is_empty()`
/// always — the support-`Vec` surface.
/// - `env_prefix_kinds_any_observed() == (absent_env_prefix_kinds_count() <
/// crate::axis_cardinality::<EnvMetadataTagKind>())` always —
/// the coverage-gap-scalar surface, the dual-side surfacing of
/// the same boolean across the (observed, unobserved) partition.
/// - `env_prefix_kinds_full_cover() ⇒ env_prefix_kinds_any_observed()`
/// — a full-cover chain observes every cell, so it observes at
/// least one cell. Contrapositively, `!env_prefix_kinds_any_observed()
/// ⇒ !env_prefix_kinds_full_cover()`.
/// - `env_prefix_kinds_any_observed() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::Env) >= 1` — a
/// chain observing any env-prefix kind has at least one env
/// layer, and every such layer is a [`ConfigSource::Env`].
/// Cross-sub-axis lower-bound implication linking the env-prefix
/// sub-axis any-observed boundary to the layer-kind sub-axis Env
/// cell count. Cross-sub-axis divergence from
/// [`Self::layer_kinds_any_observed`]'s `self.as_ref().len() >= 1`
/// implication, which reads on the chain-length rather than the
/// Env-layer count. Sister of the file-format sub-axis's
/// `file_formats_any_observed() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::File) >= 1`
/// lower-bound.
/// - `!env_prefix_kinds_any_observed() ⇒ env_prefix_kinds_balanced()`
/// — the empty-histogram chain is the only chain on the `false`
/// side of `env_prefix_kinds_any_observed` and it is vacuously
/// balanced.
/// - `!env_prefix_kinds_any_observed() ⇒ !env_prefix_kinds_full_cover()`
/// — the empty-histogram chain has every cell in the coverage
/// gap, so full-cover fails. Contrapositive of the subsumption
/// implication above.
/// - `!env_prefix_kind_histogram().is_empty() ⇒
/// env_prefix_kinds_any_observed()` — a non-empty-histogram
/// chain observes at least one cell; combined with the two-cell-
/// axis `balanced || full_cover` tightening from
/// [`Self::env_prefix_kinds_full_cover`], every non-empty-
/// histogram chain reads `true` on `any_observed`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<EnvMetadataTagKind>()`
/// (the any-observed scan). Both are `O(n)` in practice since the
/// env-prefix axis carries a fixed two-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits on
/// the first nonzero cell (bounded at one nonzero cell visited on
/// any non-empty-histogram chain), strictly tighter than the four
/// support / coverage-gap equality forms — no
/// `Vec<EnvMetadataTagKind>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no scalar equality
/// against a magic axis-cardinality constant.
#[must_use]
fn env_prefix_kinds_any_observed(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
!self.env_prefix_kind_histogram().is_empty()
}
/// Named typed boolean predicate — `true` exactly when this chain's
/// [`ConfigSource::Env`] layers observe exactly one
/// [`EnvMetadataTagKind`] cell (exactly one cell of the closed
/// [`EnvMetadataTagKind`] axis has a nonzero count on the recipe's
/// env-prefix histogram — the singleton-support boundary of the
/// coverage-support partition). Routes through
/// [`Self::env_prefix_kind_histogram`]'s
/// [`crate::AxisHistogram::has_singular_support`]: the cube-native
/// single-pass short-circuiting scan over the fixed-cardinality
/// counts vector one altitude down that finds the first nonzero
/// cell and confirms no second nonzero cell follows.
///
/// Operator-facing consumers answering *"did the recipe land on
/// exactly one env-prefix kind?"* — the CLI `config-show` headline
/// *"singleton-prefix recipe: every env layer carries the same
/// prefix polarity"*, the attestation manifest gate *"rebuild
/// window observes exactly one env-prefix kind"*, the alerting
/// policy predicate *"recipe collapsed to a single env-prefix
/// kind"* — now route through this named seam instead of four
/// previously drifting inline forms:
/// `chain.present_env_prefix_kinds_count() == 1` (the support-scalar
/// form, which pays for a full-axis scan and compares a `usize`
/// to one without naming the coverage-support boundary),
/// `chain.present_env_prefix_kinds().len() == 1` (the support-`Vec`
/// form, which allocates a `Vec<EnvMetadataTagKind>` and reads its
/// length back), `chain.absent_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>() - 1` (the
/// coverage-gap-scalar form, which pays for the coverage-gap
/// scan and pulls in the [`crate::axis_cardinality`] turbofish at
/// every call site), and `chain.absent_env_prefix_kinds().len() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>() - 1` (the
/// coverage-gap-`Vec` form, which allocates the coverage-gap
/// vector and reads its length back).
///
/// **Closes the "singleton-support across altitudes" projection**
/// across every altitude / sub-axis. Seeded on the diff altitude
/// by [`crate::ConfigDiff::kinds_singular_support`], climbed to
/// the tier altitude by
/// [`crate::ProvenanceMap::tiers_singular_support`], and lifted
/// sideways to the chain-altitude sister sub-axes by
/// [`Self::layer_kinds_singular_support`] over
/// [`Self::layer_kind_histogram`] and
/// [`Self::file_formats_singular_support`] over
/// [`Self::file_format_histogram`]; this lift closes the third and
/// final chain-altitude sub-axis, matching the fully-covered
/// chain-shape triples `(layer_kinds_balanced, file_formats_balanced,
/// env_prefix_kinds_balanced)`, `(layer_kinds_full_cover,
/// file_formats_full_cover, env_prefix_kinds_full_cover)`, and
/// `(layer_kinds_any_observed, file_formats_any_observed,
/// env_prefix_kinds_any_observed)` one boundary surface over. The
/// 4-boundary × 5-altitude/sub-axis (`kinds`, `tiers`, `layer_kinds`,
/// `file_formats`, `env_prefix_kinds`) coverage-support predicate
/// cube — `(balanced, full_cover, any_observed, singular_support)`
/// × (diff, tier, chain-layer-kind, chain-file-format, chain-env-
/// prefix) — now spans every corner at every altitude / sub-axis,
/// each corner routed through the same
/// [`crate::AxisHistogram`] primitive one altitude down at a single
/// named seam.
///
/// **Empty-histogram convention** — returns `false` on every chain
/// whose env-prefix histogram is empty: no observed cells means
/// the singleton-support predicate fails (support cardinality is
/// 0, not 1). Matches
/// [`crate::AxisHistogram::has_singular_support`]'s empty-histogram
/// `false` convention one altitude down. Agreement with
/// [`Self::file_formats_singular_support`]'s and
/// [`Self::env_prefix_kinds_any_observed`]'s same-sided convention
/// at the empty-histogram / non-empty-chain boundary: a non-empty
/// chain of only [`ConfigSource::Defaults`] / [`ConfigSource::File`]
/// layers ALSO reads `false` (the histogram is empty even though
/// the chain is not). Cross-sub-axis divergence from
/// [`Self::layer_kinds_singular_support`], where the empty-chain
/// boundary reads on `self.as_ref().is_empty()` instead of the
/// histogram-empty predicate. Unlike
/// [`Self::file_formats_singular_support`], the empty-histogram /
/// no-`Env`-layers condition is exactly the layer-kind
/// `count(ConfigSourceKind::Env) == 0` condition: every `Env`
/// entry projects to a `Some` cell regardless of prefix value, so
/// no `Env` entry is silently dropped by the projection the way
/// an unrecognized-extension `File` entry is on the file-format
/// sub-axis. Dual of the vacuous-uniformity witness on
/// [`Self::env_prefix_kinds_balanced`], which reads `true` on
/// every empty-histogram chain: the four boundaries partition the
/// empty-histogram chain into the polarity quadruple
/// (`any_observed`=false, `singular_support`=false,
/// `balanced`=true, `full_cover`=false).
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single
/// [`EnvMetadataTagKind`]: one observed cell is exactly the
/// singleton-support boundary. Every prefixed-only chain (all env
/// layers carry non-empty prefixes) and every bare-only chain
/// (all env layers carry the empty prefix) is a witness — as is
/// `sample_chain` (two `.yaml` file layers + one prefixed env
/// layer: `Prefixed` is the sole observed cell). Matches
/// [`Self::env_prefix_kinds_any_observed`]'s and
/// [`Self::env_prefix_kinds_balanced`]'s `true` side on the
/// singleton and orthogonal to
/// [`Self::env_prefix_kinds_full_cover`]'s `false` side on the
/// same singleton — the four boundaries partition the singleton-
/// support fixture into the polarity quadruple
/// (`any_observed`=true, `singular_support`=true, `balanced`=true,
/// `full_cover`=false).
///
/// **Uniform two-kind cover convention** — returns `false` on
/// every chain where each of the two [`EnvMetadataTagKind`] cells
/// was observed at least once: the support is the full two-cell
/// axis (not one), so the singleton-support predicate fails. The
/// uniform two-kind cover is on the `false` side of the singular-
/// support boundary and on the `true` side of the other three
/// coverage-support boundaries — the four boundaries partition
/// the uniform-cover fixture with (`any_observed`=true,
/// `singular_support`=false, `balanced`=true, `full_cover`=true).
///
/// **Two-cell-axis boundary tightening — `singular_support ⇔
/// any_observed ∧ !full_cover`** — unique tightening on the two-
/// cell env-prefix axis: because the two-cell-axis polarity space
/// realizes only four of the eight triples
/// (`(any_observed, balanced, full_cover)` ∈ {(F,T,F), (T,T,F),
/// (T,F,T), (T,T,T)}), the `true` side of `singular_support` is
/// exactly the (T,T,F) triple — every chain observing at least
/// one cell but not both — and the `false` side is the union of
/// the other three triples. Equivalently on the two-cell axis:
/// `singular_support ⇔ balanced ∧ any_observed ∧ !full_cover ⇔
/// !balanced ∨ !any_observed ⇒ !singular_support`. This
/// tightening does NOT lift to the three-cell layer-kind or four-
/// cell file-format sub-axes, where two-cell partial covers can
/// carry (T,F,F) polarity (any observed, not balanced, not full
/// cover) and singular-support is a strict subset of that side.
///
/// # Invariants
///
/// - `env_prefix_kinds_singular_support() ==
/// env_prefix_kind_histogram().has_singular_support()` — both
/// project the same predicate off the same primitive; the named
/// seam is the cube-native routing of the histogram surface.
/// - `env_prefix_kinds_singular_support() ==
/// (present_env_prefix_kinds_count() == 1)` always — the
/// support-scalar surface, without allocating the
/// `Vec<EnvMetadataTagKind>`.
/// - `env_prefix_kinds_singular_support() ==
/// (present_env_prefix_kinds().len() == 1)` always — the
/// support-`Vec` surface.
/// - `env_prefix_kinds_singular_support() ==
/// (absent_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>() - 1)` always
/// — the coverage-gap-scalar surface, the dual-side surfacing
/// of the same boolean across the (observed, unobserved)
/// partition.
/// - `env_prefix_kinds_singular_support() ⇒
/// env_prefix_kinds_any_observed()` — a chain with exactly one
/// observed cell has at least one observed cell.
/// Contrapositively, `!env_prefix_kinds_any_observed() ⇒
/// !env_prefix_kinds_singular_support()`.
/// - `env_prefix_kinds_singular_support() ⇒
/// env_prefix_kinds_balanced()` — a chain with exactly one
/// observed count has a trivially uniform support (one count
/// is vacuously equal to itself), so the balanced predicate
/// holds.
/// - `env_prefix_kinds_singular_support() ⇒
/// !env_prefix_kinds_full_cover()` on every axis with
/// cardinality `>= 2` (every implementor today —
/// [`EnvMetadataTagKind`] carries two cells): a singleton
/// support has size 1, a full cover has size
/// `axis_cardinality::<A>()` `>= 2`, so the two boundaries are
/// disjoint.
/// - `env_prefix_kinds_singular_support() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::Env) >= 1` —
/// a chain with a singleton env-prefix support has at least
/// one env layer, and every such layer is a
/// [`ConfigSource::Env`]. Cross-sub-axis lower-bound
/// implication linking the env-prefix sub-axis singleton-
/// support boundary to the layer-kind sub-axis Env cell count.
/// Cross-sub-axis divergence from
/// [`Self::layer_kinds_singular_support`]'s
/// `self.as_ref().len() >= 1` implication, which reads on the
/// chain-length rather than the Env-layer count. Sister of the
/// file-format sub-axis's `file_formats_singular_support() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::File) >= 1`
/// lower-bound.
/// - `env_prefix_kinds_singular_support() ⇒
/// dominant_env_prefix_kind() == recessive_env_prefix_kind()
/// && dominant_env_prefix_kind().is_some()` — when support is
/// singular, the modal pair collapses to the one observed cell
/// on both sides.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k =
/// crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// singular-support scan). Both are `O(n)` in practice since the
/// env-prefix axis carries a fixed two-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits
/// on the second nonzero cell (bounded at two nonzero cells
/// visited on any two-or-more-cell-support chain), strictly
/// tighter than the four support / coverage-gap equality forms
/// — no `Vec<EnvMetadataTagKind>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no scalar equality
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn env_prefix_kinds_singular_support(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().has_singular_support()
}
/// Returns `true` exactly when this chain's [`ConfigSource::Env`]
/// layers observe every [`EnvMetadataTagKind`] cell except one —
/// the singleton-gap boundary of the coverage-support partition on
/// the env-prefix sub-axis of the chain altitude.
///
/// The cube-native answer to *"did this chain miss exactly one
/// env-prefix cell?"*, routed through the shared
/// [`crate::AxisHistogram::has_singular_gap`] primitive on
/// [`Self::env_prefix_kind_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard singleton-gap headline
/// over the recipe's env-prefix composition, the attestation
/// manifest gate *"rebuild window observes all-but-one env-prefix
/// kind"*, the alerting policy predicate *"env-prefix gap singular"*
/// — now route through this named seam instead of four previously
/// drifting inline forms:
/// `chain.absent_env_prefix_kinds_count() == 1` (coverage-gap-scalar),
/// `chain.absent_env_prefix_kinds().len() == 1` (coverage-gap-`Vec`),
/// `chain.present_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>() - 1` (support-
/// scalar, which pays for a full-axis scan and pulls in the
/// [`crate::axis_cardinality`] turbofish at every call site), and
/// `chain.present_env_prefix_kinds().len() ==
/// crate::axis_cardinality::<EnvMetadataTagKind>() - 1` (support-
/// `Vec`, which allocates a `Vec<EnvMetadataTagKind>` and reads its
/// length back). The four forms drifted in subtle ways at every
/// consumer site (allocation vs. scalar, turbofish vs. name-only,
/// coverage-gap side vs. support side). This lift names the
/// singleton-gap-env-prefix predicate directly at the chain-altitude
/// surface with a single-pass short-circuiting scan.
///
/// **Closes the "singleton-gap across altitudes" projection**
/// across every altitude / sub-axis. Seeded on the diff altitude
/// by [`crate::ConfigDiff::kinds_singular_gap`], climbed to the
/// tier altitude by [`crate::ProvenanceMap::tiers_singular_gap`],
/// and lifted sideways to the chain-altitude sister sub-axes by
/// [`Self::layer_kinds_singular_gap`] over
/// [`Self::layer_kind_histogram`] and
/// [`Self::file_formats_singular_gap`] over
/// [`Self::file_format_histogram`]; this lift closes the third and
/// final chain-altitude sub-axis, matching the fully-covered
/// chain-shape triples `(layer_kinds_balanced, file_formats_balanced,
/// env_prefix_kinds_balanced)`, `(layer_kinds_full_cover,
/// file_formats_full_cover, env_prefix_kinds_full_cover)`,
/// `(layer_kinds_any_observed, file_formats_any_observed,
/// env_prefix_kinds_any_observed)`, and `(layer_kinds_singular_support,
/// file_formats_singular_support, env_prefix_kinds_singular_support)`
/// one boundary surface over. The 5-boundary × 5-altitude/sub-axis
/// (`kinds`, `tiers`, `layer_kinds`, `file_formats`,
/// `env_prefix_kinds`) coverage-support predicate cube — `(balanced,
/// full_cover, any_observed, singular_support, singular_gap)` ×
/// (diff, tier, chain-layer-kind, chain-file-format, chain-env-
/// prefix) — now spans every corner at every altitude / sub-axis,
/// each corner routed through the same [`crate::AxisHistogram`]
/// primitive one altitude down at a single named seam. Dual of
/// [`Self::env_prefix_kinds_singular_support`] on the *complementary*
/// cardinality slice of the same coverage-support partition
/// (`singular_support` = *exactly-one* observed cell; `singular_gap`
/// = *exactly-one* unobserved cell).
///
/// **Two-cell-axis singular-boundary coincidence** — unique on
/// this two-cell env-prefix axis:
/// [`EnvMetadataTagKind::ALL`] carries exactly two cells, so
/// support cardinality `1` (singleton-support) and support
/// cardinality `axis_cardinality - 1 = 1` (singleton-gap) coincide
/// pointwise. Every chain reads
/// `env_prefix_kinds_singular_gap() ==
/// env_prefix_kinds_singular_support()` — the two boundaries name
/// the same fixture set from opposite sides of the coverage-
/// support partition. This coincidence is a *feature*, not a
/// degeneracy: the named seams stay separate so consumers writing
/// *"missed exactly one cell"* diagnostics route through
/// `singular_gap` and consumers writing *"landed on exactly one
/// cell"* diagnostics route through `singular_support`, matching
/// the semantic they mean at the call site instead of forcing one
/// name onto both sides. The coincidence does NOT lift to the
/// three-cell layer-kind or four-cell file-format sub-axes, where
/// singleton-support has support cardinality `1` and singleton-gap
/// has support cardinality `axis_cardinality - 1 >= 2` and the two
/// boundaries are strictly disjoint. Pinned by
/// [`crate::AxisHistogram::has_singular_gap`]'s trait-uniform law
/// `has_singular_gap() ⇔ has_singular_support()` on every axis
/// with cardinality `2`, of which the env-prefix sub-axis is the
/// sole chain-altitude witness today.
///
/// **Empty-histogram convention** — returns `false` on every chain
/// whose env-prefix histogram is empty: every cell is unobserved
/// (`axis_cardinality::<EnvMetadataTagKind>() = 2`, not one), so the
/// singleton-gap predicate fails. Matches
/// [`crate::AxisHistogram::has_singular_gap`]'s empty-histogram
/// `false` convention one altitude down. Agreement with
/// [`Self::file_formats_singular_gap`]'s and
/// [`Self::env_prefix_kinds_singular_support`]'s same-sided
/// convention at the empty-histogram / non-empty-chain boundary: a
/// non-empty chain of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::File`] layers ALSO reads `false` (the histogram
/// is empty even though the chain is not). Cross-sub-axis
/// divergence from [`Self::layer_kinds_singular_gap`], where the
/// empty-chain boundary reads on `self.as_ref().is_empty()` instead
/// of the histogram-empty predicate. Unlike
/// [`Self::file_formats_singular_gap`], the empty-histogram / no-
/// `Env`-layers condition is exactly the layer-kind
/// `count(ConfigSourceKind::Env) == 0` condition: every `Env` entry
/// projects to a `Some` cell regardless of prefix value, so no
/// `Env` entry is silently dropped by the projection the way an
/// unrecognized-extension `File` entry is on the file-format sub-
/// axis. Dual of the vacuous-uniformity witness on
/// [`Self::env_prefix_kinds_balanced`], which reads `true` on
/// every empty-histogram chain: the five boundaries partition the
/// empty-histogram chain into the polarity quintuple
/// (`any_observed`=false, `singular_support`=false,
/// `singular_gap`=false, `balanced`=true, `full_cover`=false).
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single [`EnvMetadataTagKind`]:
/// on the two-cell env-prefix axis a singleton support has exactly
/// one unobserved cell, so the singleton-gap predicate holds by
/// the two-cell-axis coincidence. Every prefixed-only chain (all
/// env layers carry non-empty prefixes) and every bare-only chain
/// (all env layers carry the empty prefix) is a witness — as is
/// `sample_chain` (two `.yaml` file layers + one prefixed env
/// layer: `Prefixed` is the sole observed cell, `Bare` the sole
/// unobserved cell). Matches
/// [`Self::env_prefix_kinds_singular_support`]'s,
/// [`Self::env_prefix_kinds_any_observed`]'s, and
/// [`Self::env_prefix_kinds_balanced`]'s `true` side on the
/// singleton and orthogonal to [`Self::env_prefix_kinds_full_cover`]'s
/// `false` side on the same singleton — the five boundaries
/// partition the singleton-support fixture into the polarity
/// quintuple (`any_observed`=true, `singular_support`=true,
/// `singular_gap`=true, `balanced`=true, `full_cover`=false).
///
/// **Uniform two-kind cover convention** — returns `false` on
/// every chain where each of the two [`EnvMetadataTagKind`] cells
/// was observed at least once: zero cells are unobserved (not
/// one), so the singleton-gap predicate fails. Matches
/// [`Self::env_prefix_kinds_full_cover`]'s `true` side on the same
/// fixture — the two boundaries `singular_gap` and `full_cover`
/// are disjoint at the top of the coverage-support partition
/// (adjacent support cardinalities `axis_cardinality - 1` and
/// `axis_cardinality`). The uniform two-kind cover partitions the
/// five coverage-support boundaries with (`any_observed`=true,
/// `singular_support`=false, `singular_gap`=false, `balanced`=true,
/// `full_cover`=true).
///
/// **Two-cell-axis boundary tightening — `singular_gap ⇔
/// any_observed ∧ !full_cover`** — unique tightening on the two-
/// cell env-prefix axis: because the two-cell-axis polarity space
/// realizes only four of the eight triples
/// (`(any_observed, balanced, full_cover)` ∈ {(F,T,F), (T,T,F),
/// (T,F,T), (T,T,T)}), the `true` side of `singular_gap` is
/// exactly the (T,T,F) triple — every chain observing at least
/// one cell but not both — and the `false` side is the union of
/// the other three triples. Equivalently on the two-cell axis:
/// `singular_gap ⇔ singular_support ⇔ balanced ∧ any_observed ∧
/// !full_cover ⇔ !balanced ∨ !any_observed ⇒ !singular_gap`. This
/// tightening does NOT lift to the three-cell layer-kind or four-
/// cell file-format sub-axes, where two-cell partial covers can
/// carry (T,F,F) polarity (any observed, not balanced, not full
/// cover) and singular-gap and singular-support isolate strictly
/// disjoint sides of that region.
///
/// # Invariants
///
/// - `env_prefix_kinds_singular_gap() ==
/// env_prefix_kind_histogram().has_singular_gap()` — both project
/// the same predicate off the same primitive; the named seam is
/// the cube-native routing of the histogram surface.
/// - `env_prefix_kinds_singular_gap() == (absent_env_prefix_kinds_count()
/// == 1)` always — the coverage-gap-scalar surface, without
/// allocating the `Vec<EnvMetadataTagKind>`.
/// - `env_prefix_kinds_singular_gap() == (absent_env_prefix_kinds().len()
/// == 1)` always — the coverage-gap-`Vec` surface.
/// - `env_prefix_kinds_singular_gap() == (present_env_prefix_kinds_count()
/// == crate::axis_cardinality::<EnvMetadataTagKind>() - 1)`
/// always — the support-scalar surface, the dual-side surfacing
/// of the same boolean across the (observed, unobserved)
/// partition.
/// - `env_prefix_kinds_singular_gap() == (present_env_prefix_kinds().len()
/// == crate::axis_cardinality::<EnvMetadataTagKind>() - 1)`
/// always — the support-`Vec` surface.
/// - `env_prefix_kinds_singular_gap() ⇒ env_prefix_kinds_any_observed()`
/// on every axis with cardinality `>= 2` (every implementor today
/// — [`EnvMetadataTagKind`] carries two cells): a chain missing
/// exactly one cell observes at least `axis_cardinality - 1 >= 1`
/// cells. Contrapositively, `!env_prefix_kinds_any_observed() ⇒
/// !env_prefix_kinds_singular_gap()`.
/// - `env_prefix_kinds_singular_gap() ⇒ !env_prefix_kinds_full_cover()`
/// always: full cover has zero unobserved cells, singular gap has
/// exactly one, so the two boundaries are disjoint on every axis.
/// - `env_prefix_kinds_singular_gap() ⇔ env_prefix_kinds_singular_support()`
/// on the two-cell env-prefix axis (unique cardinality-2
/// coincidence — support `1` and support `axis_cardinality - 1`
/// coincide). Combined with the general disjointness
/// `singular_gap ⇒ !singular_support` on cardinality `>= 3` axes,
/// this is the unique two-cell exception the sub-axis carries.
/// - `env_prefix_kinds_singular_gap() ⇒
/// layer_kind_histogram().count(ConfigSourceKind::Env) >= 1` —
/// a chain with a singleton env-prefix gap observes exactly one
/// env-prefix cell (by the two-cell-axis coincidence) so has at
/// least one env layer, and every such layer is a
/// [`ConfigSource::Env`]. Cross-sub-axis lower-bound implication
/// linking the env-prefix sub-axis singleton-gap boundary to the
/// layer-kind sub-axis Env cell count. Cross-sub-axis divergence
/// from [`Self::layer_kinds_singular_gap`]'s
/// `self.as_ref().len() >= axis_cardinality::<ConfigSourceKind>() - 1`
/// implication, which reads on the chain-length rather than the
/// Env-layer count — matching the same divergence pattern
/// between [`Self::env_prefix_kinds_singular_support`] and
/// [`Self::layer_kinds_singular_support`] on the complementary
/// cardinality slice, tightened on this env-prefix sub-axis by
/// the two-cell-axis coincidence: the lower bound is exactly
/// `>= 1` (not `>= axis_cardinality - 1`), matching
/// [`Self::env_prefix_kinds_singular_support`]'s bound.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// singular-gap scan). Both are `O(n)` in practice since the env-
/// prefix axis carries a fixed two-cell cardinality; the returned
/// `bool` reads one predicate. The scan short-circuits on the
/// second zero cell (bounded at two zero cells visited on any
/// two-or-more-cell-gap chain), strictly tighter than the four
/// support / coverage-gap equality forms — no
/// `Vec<EnvMetadataTagKind>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no scalar equality
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn env_prefix_kinds_singular_gap(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().has_singular_gap()
}
/// Returns `true` exactly when this chain's [`ConfigSource::Env`]
/// layers observe an [`EnvMetadataTagKind`] support sitting *strictly
/// between* the two singular-cardinality boundaries — at least *two*
/// observed cells *and* at least *two* unobserved cells. The
/// boundary-free interior of the coverage-support partition strictly
/// inside the middle leg of the coarser coverage trichotomy on the
/// env-prefix sub-axis of the chain altitude.
///
/// The cube-native answer to *"did this chain's env-prefix
/// composition land in the strict interior of the support-cardinality
/// interval — neither on a singular boundary nor on a coverage
/// boundary?"*, routed through the shared
/// [`crate::AxisHistogram::has_strict_partial_cover`] primitive on
/// [`Self::env_prefix_kind_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard strict-interior
/// headline over the chain's env-prefix composition, the attestation
/// manifest gate *"chain env-prefix support strictly interior"*, the
/// alerting policy predicate *"env-prefix support strictly interior"*
/// — now route through this named seam instead of four previously
/// drifting inline forms:
/// `chain.env_prefix_kind_histogram().has_partial_cover() &&
/// !chain.env_prefix_kinds_singular_support() &&
/// !chain.env_prefix_kinds_singular_gap()` (structural conjunction on
/// three named predicates), `1 < chain.present_env_prefix_kinds_count()
/// && chain.present_env_prefix_kinds_count() + 1 <
/// crate::axis_cardinality::<EnvMetadataTagKind>()` (support-scalar
/// strict-interval with [`crate::axis_cardinality`] turbofish and
/// `+ 1 <` arithmetic), `1 < chain.absent_env_prefix_kinds_count()
/// && chain.absent_env_prefix_kinds_count() + 1 <
/// crate::axis_cardinality::<EnvMetadataTagKind>()` (coverage-gap-
/// scalar strict-interval on the complementary side), and
/// `chain.present_env_prefix_kinds().len() >= 2 &&
/// chain.absent_env_prefix_kinds().len() >= 2` (dual-`Vec` at-least-
/// two-of-each, allocating two vectors just to peek their lengths).
///
/// **Closes the "strict-partial-cover across altitudes" projection**
/// at the sixth and final altitude / sub-axis: seeded on the diff
/// altitude by [`crate::ConfigDiff::kinds_strict_partial_cover`],
/// climbed to the tier altitude by
/// [`crate::ProvenanceMap::tiers_strict_partial_cover`], lifted
/// sideways to the chain layer-kind sub-axis by
/// [`Self::layer_kinds_strict_partial_cover`], and lifted sideways to
/// the chain file-format sub-axis by
/// [`Self::file_formats_strict_partial_cover`]. Middle-leg-corner peer
/// of the five already-closed coverage-support boundary families on
/// the same sub-axis ([`Self::env_prefix_kinds_balanced`],
/// [`Self::env_prefix_kinds_full_cover`],
/// [`Self::env_prefix_kinds_any_observed`],
/// [`Self::env_prefix_kinds_singular_support`],
/// [`Self::env_prefix_kinds_singular_gap`]) — the last unnamed corner
/// of the 5-corner support-cardinality partition on the env-prefix
/// sub-axis. With this lift the coverage-support predicate cube
/// promotes from 5×5 to 6×5 corners — every altitude / sub-axis
/// carries the same six-predicate row (`balanced`, `full_cover`,
/// `any_observed`, `singular_support`, `singular_gap`,
/// `strict_partial_cover`) at the same closed shape.
///
/// **Cardinality-`2` reachability at the chain env-prefix sub-axis —
/// vacuously `false` on every chain.** The strict interior carries
/// witnesses only on axes with `axis_cardinality::<A>() >= 4` (the
/// strict interval `[2, cardinality - 2]` is empty on cardinality
/// `0`, `1`, `2`, or `3`). [`EnvMetadataTagKind`] carries exactly two
/// cells, so `env_prefix_kinds_strict_partial_cover()` reads `false`
/// on every chain regardless of the observed support — the empty
/// chain (0 observed), every singleton-support chain (1 observed,
/// coverage gap 1), and every uniform two-kind cover (2 observed,
/// coverage gap 0) all read `false`. The value of this lift at the
/// chain env-prefix sub-axis lies in naming the boundary at the
/// surface for downstream consumers reading the recipe, closing the
/// 5-corner partition at the third and final chain-altitude sub-axis
/// and completing the 6×5 coverage-support predicate cube — not in
/// its witnesses, which are structurally empty by the cardinality-
/// conditional-reachability trait-uniform law on
/// [`crate::AxisHistogram::has_strict_partial_cover`] one altitude
/// down. Matches the vacuously-`false` polarity at the two other
/// cardinality-`<= 3` altitudes in the projection: the diff altitude
/// ([`crate::tiered::DiffLineKind`] cardinality `3`) and the chain
/// layer-kind sub-axis ([`ConfigSourceKind`] cardinality `3`). The
/// tier altitude ([`crate::tiered::ConfigTierKind`] cardinality `4`)
/// and the chain file-format sub-axis
/// ([`crate::discovery::Format`] cardinality `4`) are the only two
/// rows in the projection where the strict interior is reachable —
/// on the two-cell env-prefix sub-axis the strict-interior corner is
/// the *tightest* vacuously-`false` corner, since the interval closes
/// two cardinality steps below the reachability threshold.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain has zero observed cells, so the "at least two
/// observed" half of the conjunction fails uniformly. Matches
/// [`crate::AxisHistogram::has_strict_partial_cover`]'s empty-
/// histogram `false` convention one altitude down. The empty chain
/// is therefore on the `false` side of the strict-interior boundary
/// — matching [`Self::env_prefix_kinds_any_observed`]'s empty-chain
/// `false` polarity, [`Self::env_prefix_kinds_full_cover`]'s empty-
/// chain `false` polarity,
/// [`Self::env_prefix_kinds_singular_support`]'s empty-chain `false`
/// polarity, and [`Self::env_prefix_kinds_singular_gap`]'s empty-
/// chain `false` polarity.
///
/// **No-env-layers convention** — returns `false` on every non-empty
/// chain whose env-prefix histogram is empty (chains of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers). The
/// histogram is empty even though the chain is not, so the "at least
/// two observed" half fails uniformly. Cross-sub-axis divergence from
/// [`Self::layer_kinds_strict_partial_cover`]: the `false` side of
/// the boundary is wider on the env-prefix sub-axis — the empty-
/// histogram non-empty-chain case is also `false` here, matching
/// [`Self::env_prefix_kinds_singular_gap`]'s,
/// [`Self::env_prefix_kinds_singular_support`]'s,
/// [`Self::env_prefix_kinds_any_observed`]'s, and
/// [`Self::env_prefix_kinds_full_cover`]'s same-sided convention on
/// the same fixtures.
///
/// **Singleton-support convention** — returns `false` on every chain
/// whose observed support is a single [`EnvMetadataTagKind`] cell:
/// the support cardinality is `1` (not `>= 2`), so the "at least two
/// observed" half fails uniformly.
///
/// **Uniform two-kind cover convention** — returns `false` on every
/// chain where each [`EnvMetadataTagKind`] cell was observed at least
/// once: zero cells are unobserved, so the "at least two unobserved"
/// half fails uniformly. Matches
/// [`crate::AxisHistogram::has_strict_partial_cover`]'s full-cover
/// `false` convention one altitude down.
///
/// # Invariants
///
/// - `env_prefix_kinds_strict_partial_cover() ==
/// env_prefix_kind_histogram().has_strict_partial_cover()` — both
/// project the same predicate off the same primitive; the named
/// seam is the cube-native routing of the histogram surface.
/// - `env_prefix_kinds_strict_partial_cover() ⇔
/// env_prefix_kind_histogram().has_partial_cover() &&
/// !env_prefix_kinds_singular_support() &&
/// !env_prefix_kinds_singular_gap()` always — the defining
/// structural-conjunction form on the existing named-boundary
/// triad: the strict interior is exactly the partial-cover middle
/// leg minus its two singular-cardinality corners.
/// - `env_prefix_kinds_strict_partial_cover() == (1 <
/// present_env_prefix_kinds_count() &&
/// present_env_prefix_kinds_count() + 1 <
/// crate::axis_cardinality::<EnvMetadataTagKind>())` always — the
/// support-scalar strict-interval form, without allocating the
/// `Vec<EnvMetadataTagKind>`.
/// - `env_prefix_kinds_strict_partial_cover() == (1 <
/// absent_env_prefix_kinds_count() &&
/// absent_env_prefix_kinds_count() + 1 <
/// crate::axis_cardinality::<EnvMetadataTagKind>())` always — the
/// coverage-gap-scalar strict-interval form on the complementary
/// side of the same partition.
/// - `env_prefix_kinds_strict_partial_cover() ⇒
/// env_prefix_kinds_any_observed()` on every axis with cardinality
/// `>= 4`. On [`EnvMetadataTagKind`] (cardinality `2`) the
/// antecedent never fires so the implication holds vacuously.
/// Contrapositively, `!env_prefix_kinds_any_observed() ⇒
/// !env_prefix_kinds_strict_partial_cover()`.
/// - `env_prefix_kinds_strict_partial_cover() ⇒
/// !env_prefix_kinds_full_cover()` always: the strict interior
/// requires `>= 2` unobserved cells, a full cover has zero
/// unobserved cells.
/// - `env_prefix_kinds_strict_partial_cover() ⇒
/// !env_prefix_kinds_singular_support()` always: the strict
/// interior requires `>= 2` observed cells, a singleton support
/// has exactly `1` observed cell.
/// - `env_prefix_kinds_strict_partial_cover() ⇒
/// !env_prefix_kinds_singular_gap()` always: the strict interior
/// requires `>= 2` unobserved cells, a singleton gap has exactly
/// `1` unobserved cell.
/// - `(!env_prefix_kinds_any_observed,
/// env_prefix_kinds_singular_support,
/// env_prefix_kinds_strict_partial_cover,
/// env_prefix_kinds_singular_gap, env_prefix_kinds_full_cover)`
/// is pairwise disjoint on every chain — distinct support
/// cardinalities `0`, `1`, `[2, cardinality - 2]`,
/// `cardinality - 1`, `cardinality` never overlap. Together the
/// five predicates partition every chain on the env-prefix sub-
/// axis. On the cardinality-`2` [`EnvMetadataTagKind`] axis the
/// strict-interior corner is structurally empty and the two
/// singular corners coincide pointwise (`singular_support ⇔
/// singular_gap`), so every chain fires exactly one of the four
/// active corners `{!any_observed, singular_support ∧ singular_gap,
/// full_cover}` plus the always-`false` strict-interior corner.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// strict-partial-cover scan). Both are `O(n)` in practice since the
/// env-prefix axis carries a fixed two-cell cardinality; the returned
/// `bool` reads one predicate. The scan short-circuits once it has
/// witnessed both *two* zero counts and *two* nonzero counts (bounded
/// at four witness cells visited on any strict-interior histogram —
/// unreachable on cardinality-`2` axes), strictly tighter than the
/// four documented open-coded surfaces — no
/// `Vec<EnvMetadataTagKind>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no dual scalar equality
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn env_prefix_kinds_strict_partial_cover(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().has_strict_partial_cover()
}
/// Returns `true` exactly when this chain's [`ConfigSource::Env`]
/// layers observe an [`EnvMetadataTagKind`] support sitting at the
/// *bottom* of the support-cardinality interval — at most *one*
/// observed cell. The **low-support-env-prefix-kinds boolean
/// predicate** on the env-prefix sub-axis of the chain altitude, the
/// union-of-low-boundaries corner of the support-cardinality
/// magnitude-direction ternary partition `(low_support,
/// strict_partial_cover, high_support)` — the bottom leg of the
/// magnitude ternary, folding the empty-histogram and the singleton-
/// support boundaries into a single named low-magnitude corner.
///
/// The cube-native answer to *"did this chain's env-prefix
/// composition land in the low-magnitude corner of the support-
/// cardinality interval?"*, routed through the shared
/// [`crate::AxisHistogram::has_low_support`] primitive on
/// [`Self::env_prefix_kind_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard low-magnitude headline
/// over the chain's env-prefix composition, the attestation manifest
/// gate *"chain env-prefix support at most singleton"*, the alerting
/// policy predicate *"env-prefix support low-magnitude"* — now route
/// through this named seam instead of four previously drifting inline
/// forms: defining-union-of-low-boundaries disjunction on the two
/// named histogram-side peers
/// (`!chain.env_prefix_kinds_any_observed() ||
/// chain.env_prefix_kinds_singular_support()`), support-scalar
/// at-most-one form
/// (`chain.present_env_prefix_kinds_count() <= 1`), support-`Vec`
/// at-most-one form (`chain.present_env_prefix_kinds().len() <= 1`,
/// allocating a `Vec<EnvMetadataTagKind>` just to peek its length),
/// and coverage-gap-scalar at-least-axis-cardinality-minus-one form
/// (`chain.absent_env_prefix_kinds_count() >=
/// crate::axis_cardinality::<EnvMetadataTagKind>() - 1` with
/// [`crate::axis_cardinality`] turbofish and `- 1` arithmetic).
///
/// **Closes the "low-support across altitudes" projection** at the
/// fifth and final altitude / sub-axis: seeded on the diff altitude
/// by [`crate::ConfigDiff::kinds_low_support`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_low_support`], lifted
/// sideways to the chain layer-kind sub-axis by
/// [`Self::layer_kinds_low_support`], and lifted sideways to the
/// chain file-format sub-axis by [`Self::file_formats_low_support`].
/// Bottom-leg-corner peer of the six already-closed coverage-support
/// boundary and interior families on the same sub-axis
/// ([`Self::env_prefix_kinds_balanced`],
/// [`Self::env_prefix_kinds_full_cover`],
/// [`Self::env_prefix_kinds_any_observed`],
/// [`Self::env_prefix_kinds_singular_support`],
/// [`Self::env_prefix_kinds_singular_gap`],
/// [`Self::env_prefix_kinds_strict_partial_cover`]) — the last
/// unnamed corner of the magnitude-direction ternary partition on
/// the env-prefix sub-axis. With this lift the "low-support across
/// altitudes" projection carries the same one-predicate row at
/// every altitude / sub-axis of the closed 6×5 coverage-support
/// predicate cube, and the magnitude-direction ternary's bottom leg
/// closes at every altitude / sub-axis pointwise alongside the
/// six coverage-support boundary corners already named.
///
/// **Cardinality-`2` reachability at the chain env-prefix sub-axis —
/// wider than the strict interior, coinciding with the two singular
/// corners.** The bottom magnitude corner carries witnesses on every
/// axis with `axis_cardinality::<A>() >= 1` (the empty histogram
/// always witnesses low support via the "at most one observed"
/// clause). [`EnvMetadataTagKind`] carries two cells, so
/// `env_prefix_kinds_low_support()` reads `true` on the empty chain,
/// on every non-empty chain whose env-prefix histogram is empty
/// (chains of only [`ConfigSource::Defaults`] / [`ConfigSource::File`]
/// layers), and on every singleton-support chain (every env layer
/// carries the same prefix polarity — all-`Prefixed` or all-`Bare`),
/// and `false` only on uniform two-kind cover chains (both cells
/// observe at least one env layer). Coincides pointwise with the
/// disjunction of the two singular corners
/// (`!env_prefix_kinds_any_observed || env_prefix_kinds_singular_support`)
/// which on the cardinality-`2` axis further coincides with
/// `!env_prefix_kinds_full_cover` — the low-magnitude corner is
/// exactly the complement of the full-cover corner on the two-cell
/// axis, since the strict interior is structurally empty and every
/// non-full-cover chain sits at support cardinality `0` or `1`
/// (both `<= 1`). Strictly disjoint from the strict-interior
/// predicate [`Self::env_prefix_kinds_strict_partial_cover`] whose
/// support-cardinality interval `[2, cardinality - 2]` is empty on
/// cardinality-`2` axes — the disjointness holds vacuously (the
/// antecedent never fires). Matches the vacuously-`false`
/// strict-interior polarity at the two other cardinality-`<= 3`
/// altitudes in the projection (diff / chain layer-kind); the
/// strict-interior disjointness carries no non-vacuous witness here,
/// mirroring [`Self::layer_kinds_low_support`]'s vacuous behavior on
/// its own strict-interior peer.
///
/// **Empty-chain convention** — returns `true` on the empty chain:
/// zero observed cells satisfy the "at most one observed" clause
/// vacuously. Matches [`crate::AxisHistogram::has_low_support`]'s
/// empty-histogram `true` convention one altitude down, and
/// diverges from [`Self::env_prefix_kinds_any_observed`]'s empty-
/// chain `false` polarity — the low-support boundary strictly
/// includes the empty chain by folding the "no observation" case
/// into the low-magnitude corner.
///
/// **No-env-layers convention** — returns `true` on every non-empty
/// chain whose env-prefix histogram is empty (chains of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers). The
/// histogram is empty even though the chain is not, so the "at most
/// one observed" clause holds vacuously. Cross-sub-axis divergence
/// from [`Self::layer_kinds_low_support`]: the low-magnitude corner
/// is wider on the env-prefix sub-axis — the empty-histogram
/// non-empty-chain case reads `true` here, matching
/// [`Self::file_formats_low_support`]'s no-recognized-files
/// convention one sub-axis over and diverging from the layer-kind
/// sub-axis peer where every non-empty chain observes at least one
/// layer-kind cell.
///
/// **Singleton-support convention** — returns `true` on every chain
/// whose observed env-prefix support is a single [`EnvMetadataTagKind`]
/// cell: support cardinality `1` satisfies `<= 1`. Peer of
/// [`Self::env_prefix_kinds_singular_support`]'s `true` side on the
/// same fixture — the singleton-support boundary fires into the
/// low-magnitude corner via the union-of-low-boundaries disjunction.
/// On the two-cell env-prefix axis this side coincides pointwise
/// with [`Self::env_prefix_kinds_singular_gap`]'s `true` side by the
/// two-cell-axis coincidence (`singular_support ⇔ singular_gap` on
/// cardinality-`2` axes), so the low-magnitude corner absorbs both
/// singular boundaries into one named row.
///
/// **Uniform two-kind cover convention** — returns `false` on every
/// chain where each [`EnvMetadataTagKind`] cell was observed at
/// least once: support cardinality `2` violates `<= 1`. Matches
/// [`crate::AxisHistogram::has_low_support`]'s full-cover `false`
/// convention one altitude down on cardinality-`>= 2` axes. On the
/// cardinality-`2` env-prefix axis the uniform two-kind cover is
/// the *unique* `false` side of the boundary — the low-magnitude
/// corner is exactly the complement of the full-cover corner here.
///
/// # Invariants
///
/// - `env_prefix_kinds_low_support() ==
/// env_prefix_kind_histogram().has_low_support()` — both project
/// the same predicate off the same primitive; the named seam is
/// the cube-native routing of the histogram surface.
/// - `env_prefix_kinds_low_support() ⇔ !env_prefix_kinds_any_observed()
/// || env_prefix_kinds_singular_support()` always — the defining
/// union-of-low-boundaries disjunction on the two named
/// histogram-side peers.
/// - `env_prefix_kinds_low_support() ==
/// (present_env_prefix_kinds_count() <= 1)` always — the support-
/// scalar at-most-one form, without allocating the
/// `Vec<EnvMetadataTagKind>`.
/// - `env_prefix_kinds_low_support() ==
/// (present_env_prefix_kinds().len() <= 1)` always — the support-
/// `Vec` at-most-one form.
/// - `env_prefix_kinds_low_support() == (absent_env_prefix_kinds_count() >=
/// crate::axis_cardinality::<EnvMetadataTagKind>() - 1)` always —
/// the coverage-gap-scalar at-least-axis-cardinality-minus-one
/// form, the dual-side surfacing of the same boolean across the
/// (observed, unobserved) partition.
/// - `env_prefix_kinds_low_support() ⇔ !env_prefix_kinds_full_cover()`
/// on the cardinality-`2` env-prefix axis — the low-magnitude
/// corner is exactly the complement of the full-cover corner
/// here, since the strict interior is structurally empty and
/// every non-full-cover chain sits at support cardinality `<= 1`.
/// The two-cell-axis tightening of the general disjointness
/// `low_support ⇒ !full_cover` into an equivalence — the two
/// corners partition the two-cell axis. Does NOT lift to the
/// cardinality-`>= 3` sub-axes ([`Self::layer_kinds_low_support`]
/// and [`Self::file_formats_low_support`]) where two-kind and
/// three-format partial covers sit on the `!low_support ∧
/// !full_cover` middle interval.
/// - `env_prefix_kinds_low_support() ⇒ !env_prefix_kinds_full_cover()`
/// always — the general side of the tightening above; low support
/// has size `<= 1`, full cover has size `axis_cardinality >= 2`.
/// - `env_prefix_kinds_low_support() ⇒
/// !env_prefix_kinds_strict_partial_cover()` always: the strict
/// interior requires `>= 2` observed cells; low support has
/// `<= 1`. On the cardinality-`2` [`EnvMetadataTagKind`] axis
/// this holds vacuously (the antecedent's negation is always
/// `true`).
/// - `!env_prefix_kinds_any_observed() ⇒ env_prefix_kinds_low_support()`
/// always — the empty histogram always sits at the bottom of the
/// magnitude interval.
/// - `env_prefix_kinds_singular_support() ⇒
/// env_prefix_kinds_low_support()` always — every singleton-
/// support chain lands on the low-magnitude corner by the union-
/// of-low-boundaries disjunction.
/// - `env_prefix_kinds_singular_gap() ⇒ env_prefix_kinds_low_support()`
/// on the cardinality-`2` env-prefix axis by the two-cell-axis
/// coincidence `singular_gap ⇔ singular_support`, folded through
/// the singular-support subsumption above. Does NOT lift to the
/// cardinality-`>= 3` sub-axes where singular-gap sits at support
/// cardinality `axis_cardinality - 1 >= 2` on the wrong side of
/// the low-support boundary.
/// - `(env_prefix_kinds_low_support,
/// env_prefix_kinds_strict_partial_cover,
/// env_prefix_kinds_high_support)` forms a strict ternary
/// partition on every axis with `axis_cardinality::<A>() >= 2` —
/// pinned trait-uniformly one altitude down by
/// `axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<EnvMetadataTagKind>()` (the
/// low-support scan). Both are `O(n)` in practice since the env-
/// prefix axis carries a fixed two-cell cardinality; the returned
/// `bool` reads one predicate. The scan short-circuits once it has
/// witnessed the *second* nonzero cell (bounded at two nonzero
/// cells visited on any two-or-more-cell-support chain — on the
/// cardinality-`2` axis the bound coincides with the full axis
/// scan), strictly tighter than the four documented open-coded
/// surfaces — no `Vec<EnvMetadataTagKind>` allocation, no
/// [`crate::axis_cardinality`] turbofish, no `- 1` arithmetic
/// against a magic axis-cardinality-minus-one constant.
#[must_use]
fn env_prefix_kinds_low_support(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().has_low_support()
}
/// Returns `true` exactly when this chain's [`ConfigSource::Env`]
/// layers observe an [`EnvMetadataTagKind`] support sitting at the
/// *top* of the support-cardinality interval — at most *one*
/// unobserved cell, excising the cardinality-`2` dual-singular-
/// collapse case ([`EnvMetadataTagKind`] carries two cells so the
/// excision fires structurally at this sub-axis, collapsing the
/// high-magnitude corner onto the full-cover corner). The
/// **high-support-env-prefix-kinds boolean predicate** on the env-
/// prefix sub-axis of the chain altitude, the strict-singular-gap-
/// or-full-cover corner of the support-cardinality magnitude-
/// direction ternary partition `(low_support, strict_partial_cover,
/// high_support)` — the top leg of the magnitude ternary, folding
/// the full-cover and the strict singleton-gap boundaries into a
/// single named high-magnitude corner.
///
/// The cube-native answer to *"did the chain land in the high-
/// magnitude corner of the env-prefix support-cardinality
/// interval?"*, routed through the shared
/// [`crate::AxisHistogram::has_high_support`] primitive on
/// [`Self::env_prefix_kind_histogram`] one altitude down. Consumers
/// asking that question — the fleet dashboard high-magnitude
/// headline over the chain's env-prefix composition, the
/// attestation manifest gate *"chain env-prefix support at least
/// axis-cardinality-minus-one"*, the alerting policy predicate
/// *"env-prefix support high-magnitude"* — now route through this
/// named seam instead of four previously drifting inline forms:
/// defining strict-singular-gap-or-full-cover disjunction on three
/// named histogram-side peers (`chain.env_prefix_kinds_full_cover()
/// || (chain.env_prefix_kinds_singular_gap() &&
/// !chain.env_prefix_kinds_singular_support())`), coverage-gap-
/// scalar dual-interval form (`chain.absent_env_prefix_kinds_count()
/// <= 1 && chain.present_env_prefix_kinds_count() >= 2`), support-
/// scalar dual-interval form
/// (`chain.present_env_prefix_kinds_count() + 1 >= crate::axis_cardinality::<crate::EnvMetadataTagKind>() && chain.present_env_prefix_kinds_count() >= 2`),
/// and support-`Vec` dual-length form
/// (`chain.present_env_prefix_kinds().len() + 1 >= crate::axis_cardinality::<crate::EnvMetadataTagKind>() && chain.present_env_prefix_kinds().len() >= 2`),
/// allocating a `Vec<crate::EnvMetadataTagKind>` just to peek its
/// length.
///
/// **Closes the "high-support across altitudes" projection** at
/// the fifth and final altitude / sub-axis: seeded on the diff
/// altitude by [`crate::ConfigDiff::kinds_high_support`], climbed
/// to the tier altitude by
/// [`crate::ProvenanceMap::tiers_high_support`], lifted sideways to
/// the chain layer-kind sub-axis by
/// [`Self::layer_kinds_high_support`], and lifted sideways to the
/// chain file-format sub-axis by
/// [`Self::file_formats_high_support`]. Top-leg-corner peer of the
/// eight already-closed coverage-support and magnitude boundary
/// and interior families on the same sub-axis
/// ([`Self::env_prefix_kinds_balanced`],
/// [`Self::env_prefix_kinds_full_cover`],
/// [`Self::env_prefix_kinds_any_observed`],
/// [`Self::env_prefix_kinds_singular_support`],
/// [`Self::env_prefix_kinds_singular_gap`],
/// [`Self::env_prefix_kinds_strict_partial_cover`],
/// [`Self::env_prefix_kinds_low_support`]) — the last unnamed
/// corner of the magnitude-direction ternary partition on the
/// env-prefix sub-axis. With this lift the "high-support across
/// altitudes" projection carries the same one-predicate row at
/// every altitude / sub-axis of the closed 6×5 coverage-support
/// predicate cube, and the magnitude-direction ternary's top leg
/// closes at every altitude / sub-axis pointwise alongside the
/// seven coverage-support boundary corners already named.
///
/// **Cardinality-`2` reachability at the chain env-prefix sub-axis
/// — high-support collapses onto full-cover, degenerate ternary.**
/// The top magnitude corner carries witnesses on every axis with
/// `axis_cardinality::<A>() >= 2` (the full-cover fixture always
/// witnesses high support via the `is_full_cover()` disjunct on
/// the bridge). [`EnvMetadataTagKind`] carries two cells, so
/// `env_prefix_kinds_high_support()` reads `false` on the empty
/// chain, on every non-empty chain whose env-prefix histogram is
/// empty (chains of only [`ConfigSource::Defaults`] /
/// [`ConfigSource::File`] layers), and on every singleton-support
/// chain (every env layer carries the same prefix polarity —
/// all-`Prefixed` or all-`Bare`, where the dual-singular-collapse
/// excision fires: one zero cell but only one nonzero cell, so the
/// "at least two observed" clause fails), and `true` only on
/// uniform two-kind cover chains (both cells observe at least one
/// env layer — `env_prefix_kinds_full_cover` fires). The strict-
/// interior middle leg [`Self::env_prefix_kinds_strict_partial_cover`]
/// is vacuously `false` on the cardinality-`2` env-prefix axis
/// (the strict interval `[2, cardinality - 2] = [2, 0]` is empty),
/// so the magnitude-direction ternary degenerates to the dual
/// partition `(env_prefix_kinds_low_support,
/// env_prefix_kinds_high_support)` on this sub-axis — matching the
/// layer-kind sub-axis and the diff altitude, and diverging from
/// the tier altitude and the file-format sub-axis where the
/// cardinality-`4` axis inhabits every leg. Coincides pointwise
/// with [`Self::env_prefix_kinds_full_cover`] — the *unique*
/// two-cell-axis collapse of the high-magnitude corner onto the
/// full-cover corner, the strict tightening of the general
/// subsumption `full_cover ⇒ high_support` into an equivalence on
/// the two-cell axis, since the strict singleton-gap boundary is
/// structurally the singleton-support boundary (the dual-singular-
/// collapse) and the excision clause excises it.
///
/// **Empty-chain convention** — returns `false` on the empty
/// chain: zero observed cells fail the "at least two observed"
/// clause uniformly. Matches
/// [`crate::AxisHistogram::has_high_support`]'s empty-histogram
/// `false` convention one altitude down for every cardinality-
/// `>= 2` axis. Orthogonal polarity to
/// [`Self::env_prefix_kinds_low_support`]'s empty-chain `true` —
/// the two magnitude corners partition the two-cell env-prefix
/// axis exhaustively (the strict-interior middle leg is
/// structurally empty), and the empty chain sits at the *bottom*
/// of the magnitude interval, not the top.
///
/// **No-env-layers convention** — returns `false` on every non-
/// empty chain whose env-prefix histogram is empty (chains of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers).
/// The histogram is empty even though the chain is not, so every
/// cell is unobserved (two zeros on the cardinality-`2` axis) —
/// the "at most one unobserved" clause fails. Cross-sub-axis
/// divergence from [`Self::layer_kinds_high_support`]: the high-
/// magnitude corner is narrower on the env-prefix sub-axis — the
/// empty-histogram non-empty-chain case reads `false` here,
/// matching [`Self::file_formats_high_support`]'s no-recognized-
/// files convention one sub-axis over and diverging from the
/// layer-kind sub-axis peer where every non-empty chain observes
/// at least one layer-kind cell.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed env-prefix support is a single
/// [`EnvMetadataTagKind`] cell: support cardinality `1` violates
/// the "at least two observed" clause. On the cardinality-`2` axis
/// this is precisely the dual-singular-collapse case (one zero,
/// one nonzero) — the excision clause excises the singular-gap
/// disjunct on the two-cell axis, so the high-magnitude corner
/// tracks the full-cover corner exactly. Peer of
/// [`Self::env_prefix_kinds_singular_support`]'s `true` side on
/// the same fixture — the singleton-support boundary lands on the
/// low-magnitude corner, not the high-magnitude corner. On this
/// axis the boundary further coincides pointwise with
/// [`Self::env_prefix_kinds_singular_gap`]'s `true` side by the
/// two-cell-axis coincidence (`singular_support ⇔ singular_gap` on
/// cardinality-`2` axes), so both singular boundaries land on the
/// low-magnitude corner and both fail the high-magnitude corner.
///
/// **Uniform two-kind cover convention** — returns `true` on every
/// chain where each [`EnvMetadataTagKind`] cell was observed at
/// least once: support cardinality `2` (no unobserved cells) —
/// `env_prefix_kinds_full_cover` fires and the "at most one
/// unobserved" *and* "at least two observed" clauses both hold.
/// Direct witness of the strict subsumption
/// `env_prefix_kinds_full_cover ⇒ env_prefix_kinds_high_support`
/// on every axis with `axis_cardinality::<A>() >= 2`. On the
/// cardinality-`2` env-prefix axis the uniform two-kind cover is
/// the *unique* `true` side of the boundary — the high-magnitude
/// corner is exactly the full-cover corner here, tightening the
/// general subsumption into an equivalence.
///
/// # Invariants
///
/// - `env_prefix_kinds_high_support() ==
/// env_prefix_kind_histogram().has_high_support()` — both project
/// the same predicate off the same primitive; the named seam is
/// the cube-native routing of the histogram surface.
/// - `env_prefix_kinds_high_support() ⇔ env_prefix_kinds_full_cover()
/// || (env_prefix_kinds_singular_gap() &&
/// !env_prefix_kinds_singular_support())` always — the defining
/// strict-singular-gap-or-full-cover disjunction on three named
/// histogram-side peers. The `!env_prefix_kinds_singular_support()`
/// excision *fires* on the cardinality-`2` env-prefix axis (when
/// singular-gap fires, support size `1` — the dual-singular-
/// collapse), so the disjunction reduces pointwise to
/// `env_prefix_kinds_full_cover` at this sub-axis. The three-way
/// raw form is pinned verbatim so the equivalence discipline
/// inherits the excision-fires case from downstream.
/// - `env_prefix_kinds_high_support() == (absent_env_prefix_kinds_count() <= 1 && present_env_prefix_kinds_count() >= 2)`
/// always — the coverage-gap-scalar dual-interval form on the
/// complementary side of the same partition, without allocating
/// either `Vec<crate::EnvMetadataTagKind>`.
/// - `env_prefix_kinds_high_support() == (present_env_prefix_kinds_count() + 1 >= crate::axis_cardinality::<crate::EnvMetadataTagKind>() && present_env_prefix_kinds_count() >= 2)`
/// always — the support-scalar dual-interval form.
/// - `env_prefix_kinds_high_support() == (present_env_prefix_kinds().len() + 1 >= crate::axis_cardinality::<crate::EnvMetadataTagKind>() && present_env_prefix_kinds().len() >= 2)`
/// always — the support-`Vec` dual-length form, the allocating
/// peer of the scalar surface above.
/// - `env_prefix_kinds_high_support() ⇔ env_prefix_kinds_full_cover()`
/// on the cardinality-`2` env-prefix axis — the high-magnitude
/// corner is exactly the full-cover corner here, the *unique*
/// two-cell-axis tightening of the general subsumption
/// `full_cover ⇒ high_support` (documented at every altitude /
/// sub-axis) into an equivalence. Does NOT lift to the
/// cardinality-`>= 3` sub-axes ([`Self::layer_kinds_high_support`]
/// and [`Self::file_formats_high_support`]) where the singular-
/// gap boundary sits at support cardinality `axis_cardinality -
/// 1 >= 2` on the `high_support ∧ !full_cover` middle interval.
/// - `env_prefix_kinds_high_support() ⇒ !env_prefix_kinds_low_support()`
/// on every axis with `axis_cardinality::<A>() >= 2` (every
/// implementor today — [`EnvMetadataTagKind`] carries two
/// cells): high support has size `>= 2`, low support has size
/// `<= 1`, so the two magnitude corners are disjoint. Tightened
/// on the two-cell env-prefix axis into the equivalence
/// `env_prefix_kinds_high_support ⇔ !env_prefix_kinds_low_support`
/// — the low-magnitude corner and the high-magnitude corner
/// partition the two-cell axis exhaustively (the strict interior
/// is structurally empty).
/// - `env_prefix_kinds_high_support() ⇒
/// !env_prefix_kinds_strict_partial_cover()` always: the strict
/// interior requires `>= 2` unobserved cells; high support has
/// `<= 1`. On the cardinality-`2` [`EnvMetadataTagKind`] axis
/// this holds vacuously (the strict interior is structurally
/// empty, so `!env_prefix_kinds_strict_partial_cover` reads
/// `true` on every chain), matching
/// [`Self::layer_kinds_high_support`]'s vacuously-`true`
/// consequent on the cardinality-`3` layer-kind sub-axis and
/// diverging from [`Self::file_formats_high_support`]'s non-
/// vacuous peer on the cardinality-`4` file-format sub-axis
/// where the two-format partial-cover fixture witnesses the
/// strict interior. The env-prefix sub-axis carries the
/// *tightest* vacuously-true consequent in the projection.
/// - `env_prefix_kinds_high_support() ⇒ env_prefix_kinds_any_observed()`
/// on every axis with `axis_cardinality::<A>() >= 2`: high
/// support has size `>= 2 >= 1`, so at least one cell was
/// observed. The empty chain and every empty-histogram non-
/// empty chain sit on the disjoint `!env_prefix_kinds_any_observed`
/// boundary at the bottom of the magnitude interval.
/// - `env_prefix_kinds_full_cover() ⇒ env_prefix_kinds_high_support()`
/// always — the strict subsumption over the top full-cover peer
/// via the `is_full_cover()` disjunct on the bridge. The full-
/// cover corner always sits inside the high-magnitude corner.
/// Tightened on the two-cell env-prefix axis into the
/// equivalence documented above.
/// - `env_prefix_kinds_singular_gap() ⇏ env_prefix_kinds_high_support()`
/// on the cardinality-`2` env-prefix axis: on this axis the
/// singular-gap boundary coincides with the singular-support
/// boundary (the dual-singular-collapse), so the excision clause
/// `!env_prefix_kinds_singular_support` in the disjunction
/// excises the singular-gap disjunct. Every singular-gap chain
/// lands on the low-magnitude corner, not the high-magnitude
/// corner — the *unique* two-cell-axis divergence from the
/// general subsumption `singular_gap ⇒ high_support` (which
/// holds on the cardinality-`>= 3` sub-axes
/// [`Self::layer_kinds_high_support`] and
/// [`Self::file_formats_high_support`]).
/// - `(env_prefix_kinds_low_support, env_prefix_kinds_strict_partial_cover,
/// env_prefix_kinds_high_support)` forms a strict ternary partition
/// on every axis with `axis_cardinality::<A>() >= 2`. On the
/// cardinality-`2` env-prefix axis the middle leg is vacuously
/// empty and the ternary degenerates to the dual partition
/// `(env_prefix_kinds_low_support, env_prefix_kinds_high_support)`
/// — pinned trait-uniformly one altitude down by
/// `axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<EnvMetadataTagKind>()`
/// (the high-support scan). Both are `O(n)` in practice since the
/// env-prefix axis carries a fixed two-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits on
/// the *second* zero cell (bounded at two zero-witness cells
/// visited on any two-or-more-unobserved-cell chain — on the
/// cardinality-`2` axis the bound coincides with the full axis
/// scan), strictly tighter than the four documented open-coded
/// surfaces — no three-way boolean disjunction across three named
/// predicates, no `Vec<EnvMetadataTagKind>` allocation, no
/// [`crate::axis_cardinality`] turbofish with `+ 1` arithmetic
/// against a magic threshold.
#[must_use]
fn env_prefix_kinds_high_support(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().has_high_support()
}
/// Returns `true` exactly when this chain's observed
/// [`EnvMetadataTagKind`] support sits on a *singular near-
/// boundary* — either exactly one observed cell
/// ([`Self::env_prefix_kinds_singular_support`]) or exactly one
/// unobserved cell ([`Self::env_prefix_kinds_singular_gap`]). The
/// **singular-env-prefix-kinds boolean predicate** on the env-
/// prefix sub-axis of the chain altitude, the singular near-
/// boundary corner of the distance-from-boundary ternary
/// partition `(has_boundary, has_singular,
/// has_strict_partial_cover)` — the middle leg of the distance
/// ternary, folding the two singular-cardinality boundaries into
/// a single named one-cell-off-boundary corner. Routes through
/// [`crate::AxisHistogram::has_singular`] one altitude down: the
/// single-pass short-circuiting scan over the fixed-cardinality
/// counts vector that short-circuits the moment both a *second*
/// zero cell *and* a *second* nonzero cell have been witnessed,
/// bounded at four witness cells — strictly tighter than any of
/// the four documented open-coded surfaces one seam over.
///
/// The **singular-env-prefix-kinds peer** of the four documented
/// surface forms consumers previously re-derived inline:
/// `chain.env_prefix_kinds_singular_support() ||
/// chain.env_prefix_kinds_singular_gap()` (the defining-union-of-
/// singular-boundaries disjunction on two named histogram-side
/// peers, a boolean or on two method calls that walks the counts
/// vector twice — on the cardinality-`2` env-prefix axis the two
/// disjuncts coincide by the two-cell-axis dual-singular-
/// collapse `singular_support ⇔ singular_gap`, so the union
/// reads pointwise `singular ⇔ singular_support ⇔ singular_gap`),
/// `chain.present_env_prefix_kinds_count() == 1 ||
/// chain.present_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<crate::EnvMetadataTagKind>() - 1`
/// (the support-scalar dual-equality form, which pays for a full-
/// axis scan and equates a `usize` against two magic thresholds
/// with the [`crate::axis_cardinality`] turbofish and `- 1`
/// arithmetic — on the cardinality-`2` env-prefix axis the two
/// thresholds coincide `1 == 1 = cardinality - 1` and the
/// disjunction reads the same scalar equality twice),
/// `chain.present_env_prefix_kinds_count() == 1 ||
/// chain.absent_env_prefix_kinds_count() == 1` (the dual-scalar
/// equality form on the two named cardinality peers, without
/// allocating either `Vec<crate::EnvMetadataTagKind>` — on the
/// cardinality-`2` env-prefix axis `present == 1 ⇔ absent == 1`
/// via the `present + absent == axis_cardinality` invariant so
/// the two disjuncts coincide pointwise), and
/// `chain.present_env_prefix_kinds().len() == 1 ||
/// chain.absent_env_prefix_kinds().len() == 1` (the dual-`Vec`
/// equality form, which allocates *two*
/// `Vec<crate::EnvMetadataTagKind>` values just to peek their
/// lengths). The four forms drifted in subtle ways at every
/// consumer site (allocation vs. scalar, turbofish vs. name-only,
/// support side vs. coverage-gap side, structural disjunction vs.
/// dual-equality arithmetic). This lift names the singular-env-
/// prefix-kinds predicate directly at the chain-altitude surface
/// with a single-pass short-circuiting scan — the typed boolean
/// every operator-facing *"did the chain land one env-prefix
/// cell off the coverage boundary?"* check reads off as a single
/// method call.
///
/// **Closes the "singular across altitudes" projection** at the
/// fifth and final altitude / sub-axis: seeded on the diff
/// altitude by [`crate::ConfigDiff::kinds_singular`], climbed to
/// the tier altitude by [`crate::ProvenanceMap::tiers_singular`],
/// lifted sideways to the chain layer-kind sub-axis by
/// [`Self::layer_kinds_singular`], and lifted sideways to the
/// chain file-format sub-axis by
/// [`Self::file_formats_singular`]. Middle-leg-corner peer of
/// the eight already-closed coverage-support and magnitude
/// boundary and interior families on the same sub-axis
/// ([`Self::env_prefix_kinds_balanced`],
/// [`Self::env_prefix_kinds_full_cover`],
/// [`Self::env_prefix_kinds_any_observed`],
/// [`Self::env_prefix_kinds_singular_support`],
/// [`Self::env_prefix_kinds_singular_gap`],
/// [`Self::env_prefix_kinds_strict_partial_cover`],
/// [`Self::env_prefix_kinds_low_support`],
/// [`Self::env_prefix_kinds_high_support`]) — the last unnamed
/// corner of the distance-from-boundary ternary partition on the
/// env-prefix sub-axis. With this lift the "singular across
/// altitudes" projection carries the same one-predicate row at
/// every altitude / sub-axis of the closed 6×5 coverage-support
/// predicate cube, and the distance-from-boundary ternary's
/// middle leg closes at every altitude / sub-axis pointwise
/// alongside the boundary corners already named. Symmetric peer
/// of the parallel "high-support across altitudes" and "low-
/// support across altitudes" projections closed at this same
/// sub-axis by [`Self::env_prefix_kinds_high_support`] and
/// [`Self::env_prefix_kinds_low_support`].
///
/// **Cardinality-`2` reachability at the chain env-prefix sub-
/// axis — dual-singular-collapse, degenerate distance ternary.**
/// [`EnvMetadataTagKind`] carries two cells, so the two singular
/// boundaries sit at support cardinalities `1` and
/// `cardinality - 1`, which coincide at `1` pointwise (the
/// dual-singular-collapse case where
/// `singular_support ⇔ singular_gap`). The
/// distance-from-boundary ternary degenerates to the dual
/// partition `(has_boundary, has_singular)` on this sub-axis —
/// the strict-interior middle leg
/// [`Self::env_prefix_kinds_strict_partial_cover`] is vacuously
/// `false` (the strict interval `[2, cardinality - 2] = [2, 0]`
/// is empty), matching the layer-kind sub-axis and the diff
/// altitude on their cardinality-`3` axes and diverging from the
/// tier altitude and the file-format sub-axis where the
/// cardinality-`4` axis inhabits every leg. The env-prefix sub-
/// axis carries the *tightest* degenerate distance ternary in
/// the projection: two cardinality steps below the reachability
/// threshold, the two singular boundaries themselves collapse on
/// top of each other, so `singular` reduces to the same fixture
/// set as each of its two disjuncts.
///
/// **Empty-chain convention** — returns `false` on the empty
/// chain: zero observed cells satisfy neither the `nonzeros ==
/// 1` nor the `zeros == 1` clause on the cardinality-`2` axis
/// (two zeros, zero nonzeros). Matches
/// [`crate::AxisHistogram::has_singular`]'s empty-histogram
/// `false` convention one altitude down for every cardinality-
/// `>= 2` axis. The empty chain sits on the disjoint bottom
/// coverage boundary of the distance-from-boundary ternary
/// partition, carried by `has_boundary` (via
/// `!env_prefix_kinds_any_observed`) instead.
///
/// **No-env-layers convention** — returns `false` on every non-
/// empty chain whose env-prefix histogram is empty (chains of
/// only [`ConfigSource::Defaults`] / [`ConfigSource::File`]
/// layers). The histogram is empty even though the chain is
/// not, so neither singular boundary fires. Cross-sub-axis
/// divergence from [`Self::layer_kinds_singular`]: the singular
/// near-boundary corner does NOT open on the empty-histogram
/// non-empty-chain fixtures at the env-prefix sub-axis —
/// matching [`Self::file_formats_singular`]'s no-recognized-
/// files convention one sub-axis over and
/// [`Self::env_prefix_kinds_any_observed`]'s empty-histogram
/// `false` polarity through subsumption, and diverging from the
/// layer-kind sub-axis peer where a chain of only `Defaults`
/// observes one layer-kind cell and lands on
/// `layer_kinds_singular_support ⇒ layer_kinds_singular = true`.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed support is a single
/// [`EnvMetadataTagKind`] cell: on the cardinality-`2` env-
/// prefix axis a singleton-support chain has exactly one
/// unobserved cell, so BOTH `env_prefix_kinds_singular_support`
/// AND `env_prefix_kinds_singular_gap` fire (the dual-singular-
/// collapse), and the disjunction holds via either disjunct.
/// Every prefixed-only chain (all env layers carry non-empty
/// prefixes) and every bare-only chain (all env layers carry the
/// empty prefix) is a witness — as is `sample_chain` (two
/// `.yaml` file layers + one prefixed env layer: `Prefixed` is
/// the sole observed cell, `Bare` the sole unobserved cell).
/// Direct witness of BOTH direction subsumptions
/// `env_prefix_kinds_singular_support ⇒
/// env_prefix_kinds_singular` and
/// `env_prefix_kinds_singular_gap ⇒ env_prefix_kinds_singular`
/// simultaneously on the same fixture — the two subsumptions
/// coincide pointwise on the cardinality-`2` env-prefix axis
/// (their antecedents coincide, their consequent is the same).
///
/// **Uniform two-kind cover convention** — returns `false` on
/// every chain where each [`EnvMetadataTagKind`] cell was
/// observed at least once: the support cardinality is `2` (no
/// unobserved cells on the cardinality-`2` axis) —
/// `env_prefix_kinds_singular_gap` fails (`zeros == 0 ≠ 1`) and
/// `env_prefix_kinds_singular_support` fails (`nonzeros == 2 ≠
/// 1`). `env_prefix_kinds_singular` reads `false`. The full-
/// cover boundary sits at the top of the coverage interval, one
/// of the two boundary corners carried by `has_boundary` (via
/// `env_prefix_kinds_full_cover`) in the distance ternary —
/// disjoint from the singular near-boundary corner.
///
/// # Invariants
///
/// - `env_prefix_kinds_singular() ==
/// env_prefix_kind_histogram().has_singular()` — both project
/// the same predicate off the same primitive; the named seam
/// is the cube-native routing of the histogram surface.
/// - `env_prefix_kinds_singular() ⇔
/// env_prefix_kinds_singular_support() ||
/// env_prefix_kinds_singular_gap()` — the defining union-of-
/// singular-boundaries disjunction on the two named histogram-
/// side peers. On the cardinality-`2` env-prefix axis the two
/// disjuncts coincide pointwise (the dual-singular-collapse
/// `singular_support ⇔ singular_gap`) so the union reads
/// `env_prefix_kinds_singular ⇔ env_prefix_kinds_singular_support
/// ⇔ env_prefix_kinds_singular_gap` — the *unique* two-cell-
/// axis three-way collapse in the projection.
/// - `env_prefix_kinds_singular() ⇔ (env_prefix_kinds_any_observed()
/// && !env_prefix_kinds_full_cover())` on the cardinality-`2`
/// env-prefix axis — the partial-cover-minus-strict-interior
/// form reduced on the two-cell axis: no strict-interior
/// excision needed because
/// `env_prefix_kinds_strict_partial_cover` is vacuously
/// `false` (the strict interval `[2, cardinality - 2] = [2, 0]`
/// is empty). Matches the layer-kind sub-axis's degenerate
/// reduction `layer_kinds_singular ⇔ (layer_kinds_any_observed
/// && !layer_kinds_full_cover)` on the cardinality-`3` layer-
/// kind axis and the diff altitude's degenerate reduction
/// `kinds_singular ⇔ (kinds_any_observed && !kinds_full_cover)`
/// on the cardinality-`3` diff axis, diverging from the tier
/// altitude's and the file-format sub-axis's tightened
/// equivalences that carry a load-bearing strict-interior
/// excision clause on their cardinality-`4` axes.
/// - `env_prefix_kinds_singular() ⇔ (env_prefix_kinds_any_observed()
/// && env_prefix_kinds_low_support())` on the cardinality-`2`
/// env-prefix axis — folding the two-cell-axis equivalence
/// `env_prefix_kinds_low_support ⇔ !env_prefix_kinds_full_cover`
/// (documented at
/// [`Self::env_prefix_kinds_low_support`]) through the reduced
/// form above. Reads the singular near-boundary corner off the
/// magnitude-direction ternary's bottom leg on this sub-axis —
/// the *unique* two-cell-axis cross-projection tightening
/// between the distance-from-boundary and magnitude-direction
/// ternaries, unavailable at any cardinality-`>= 3` altitude
/// / sub-axis where the strict interior separates the
/// `low_support ∧ !full_cover` middle from the singular near-
/// boundary corner.
/// - `env_prefix_kinds_singular() == (present_env_prefix_kinds_count()
/// == 1 || present_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<crate::EnvMetadataTagKind>() - 1)`
/// always — the support-scalar dual-equality surface, without
/// allocating either `Vec<crate::EnvMetadataTagKind>`. On the
/// cardinality-`2` env-prefix axis the two equalities coincide
/// `1 == 1 = cardinality - 1` and the disjunction reads the
/// same scalar equality twice — the *unique* two-cell-axis
/// collapse of the dual-equality form onto a single equality.
/// - `env_prefix_kinds_singular() == (present_env_prefix_kinds_count()
/// == 1 || absent_env_prefix_kinds_count() == 1)` always — the
/// dual-scalar equality form on the two named cardinality
/// peers, the `present + absent == axis_cardinality` invariant
/// restated. On the cardinality-`2` env-prefix axis the two
/// disjuncts coincide pointwise (`present == 1 ⇔ absent == 1`
/// via the invariant). Peer of the histogram-side dual-scalar
/// equality form `hist.distinct_cells() == 1 ||
/// hist.unobserved_cells() == 1` pinned one altitude down.
/// - `env_prefix_kinds_singular_support() ⇒
/// env_prefix_kinds_singular()` always — the subsumption via
/// the `env_prefix_kinds_singular_support` disjunct of the
/// defining union. The singleton-support boundary always sits
/// inside the singular near-boundary corner. Tightened on the
/// cardinality-`2` env-prefix axis into the equivalence
/// `env_prefix_kinds_singular_support ⇔
/// env_prefix_kinds_singular` by the dual-singular-collapse
/// folded through the defining union.
/// - `env_prefix_kinds_singular_gap() ⇒
/// env_prefix_kinds_singular()` always — the subsumption via
/// the `env_prefix_kinds_singular_gap` disjunct of the
/// defining union. Tightened on the cardinality-`2` env-prefix
/// axis into the equivalence `env_prefix_kinds_singular_gap ⇔
/// env_prefix_kinds_singular` by the dual-singular-collapse
/// folded through the defining union.
/// - `env_prefix_kinds_singular() ⇒ env_prefix_kinds_any_observed()`
/// on every axis with cardinality `>= 2`: both disjuncts
/// require at least one observed cell (`singular_support` has
/// nonzeros `>= 1`; `singular_gap` has nonzeros
/// `= cardinality - 1 >= 1`). Empty-chain and empty-histogram
/// subsumption on the bottom coverage boundary.
/// - `env_prefix_kinds_singular() ⇒ !env_prefix_kinds_full_cover()`
/// on every axis with cardinality `>= 2`:
/// `env_prefix_kinds_singular_support` has support `1 <
/// cardinality`, `env_prefix_kinds_singular_gap` has support
/// `cardinality - 1 < cardinality`. Full-cover disjointness
/// on the top coverage boundary.
/// - `env_prefix_kinds_singular() ⇒
/// !env_prefix_kinds_strict_partial_cover()` always — the two
/// named corners of the distance-from-boundary ternary are
/// pairwise disjoint. On the cardinality-`2`
/// [`EnvMetadataTagKind`] axis this holds *vacuously* — the
/// strict interior is structurally empty (the strict interval
/// `[2, cardinality - 2] = [2, 0]` is empty), so
/// `!env_prefix_kinds_strict_partial_cover` reads `true` on
/// every chain regardless of `env_prefix_kinds_singular`. The
/// env-prefix sub-axis carries the *tightest* vacuously-true
/// consequent in the projection — two cardinality steps below
/// the reachability threshold, matching the layer-kind sub-
/// axis's and the diff altitude's vacuously-`true` consequent
/// on their cardinality-`3` axes (one cardinality step below
/// the threshold) and diverging from the tier altitude's and
/// the file-format sub-axis's non-vacuous consequent on their
/// cardinality-`4` axes. Peer of the histogram-side
/// `axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor`
/// partition law one altitude down.
/// - `env_prefix_kinds_singular() ⇒
/// env_prefix_kinds_low_support()` on the cardinality-`2` env-
/// prefix axis by the cross-projection tightening above,
/// folding the equivalence `env_prefix_kinds_singular ⇔
/// (env_prefix_kinds_any_observed &&
/// env_prefix_kinds_low_support)` through the low-support
/// conjunct. The *unique* two-cell-axis cross-projection
/// subsumption between the distance-from-boundary and
/// magnitude-direction ternaries. Does NOT lift to the
/// cardinality-`>= 3` sub-axes where the singleton-gap
/// boundary sits on the `high_support` side of the magnitude
/// partition (support cardinality `axis_cardinality - 1 >= 2`)
/// and the singular near-boundary corner spans both magnitude
/// legs.
/// - `(!env_prefix_kinds_any_observed() || env_prefix_kinds_full_cover(),
/// env_prefix_kinds_singular,
/// env_prefix_kinds_strict_partial_cover)` is a strict ternary
/// partition on every axis with cardinality `>= 2`. On the
/// cardinality-`2` env-prefix axis the third leg is vacuously
/// empty and the ternary degenerates to the dual partition
/// `(!env_prefix_kinds_any_observed || env_prefix_kinds_full_cover,
/// env_prefix_kinds_singular)` pointwise — the *tightest*
/// degenerate distance ternary in the projection, matching the
/// layer-kind sub-axis's and the diff altitude's degenerate
/// two-way partition on their cardinality-`3` axes and
/// diverging from the tier altitude's and the file-format
/// sub-axis's non-vacuous three-leg partition on their
/// cardinality-`4` axes.
/// - **Cross-surface bridge law** —
/// `chain.env_prefix_kinds_singular() ==
/// chain.env_prefix_kind_histogram().support_cardinality_class().is_singular()`
/// always. The class-side projection lands on
/// [`crate::SupportCardinalityClass::SingularSupport`] or
/// [`crate::SupportCardinalityClass::SingularGap`] exactly
/// when the histogram-side disjunction fires, and
/// [`crate::SupportCardinalityClass::is_singular`] reads
/// `true` on either variant. Peer of the histogram-side
/// bridge
/// `axis_histogram_has_singular_agrees_with_class_is_singular_for_every_closed_axis_implementor`
/// one altitude down, closing the (histogram, class) duality
/// on the singular near-boundary leg at the chain env-prefix
/// sub-axis.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::EnvMetadataTagKind>()`
/// (the singular scan). Both are `O(n)` in practice since the
/// env-prefix axis carries a fixed two-cell cardinality; the
/// returned `bool` reads one predicate. The scan short-circuits
/// the *moment* both a *second* zero count *and* a *second*
/// nonzero count have been witnessed — on the cardinality-`2`
/// axis this bound coincides with the full axis scan (the axis
/// carries only two cells), strictly tighter than the four
/// documented open-coded surfaces — no boolean disjunction
/// across two named predicates with two full walks of the
/// counts vector, no [`crate::axis_cardinality`] turbofish with
/// `- 1` arithmetic against a magic threshold, no
/// `Vec<crate::EnvMetadataTagKind>` allocation.
#[must_use]
fn env_prefix_kinds_singular(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().has_singular()
}
/// `true` exactly when this chain's observed
/// [`EnvMetadataTagKind`] support sits on a *coverage boundary*
/// — either every env-prefix cell unobserved
/// ([`Self::env_prefix_kinds_any_observed`] `== false`) or every
/// env-prefix cell observed at least once
/// ([`Self::env_prefix_kinds_full_cover`] `== true`).
///
/// The **boundary-env-prefix-kinds boolean predicate** on the env-
/// prefix sub-axis of the chain altitude, the top-leg corner of the
/// distance-from-boundary ternary partition `(has_boundary,
/// has_singular, has_strict_partial_cover)` — folding the two
/// extreme coverage-cardinality corners (support cardinality `0` and
/// `axis_cardinality`) into a single named on-boundary corner
/// without discarding the finer resolution below. Routes through
/// [`Self::env_prefix_kind_histogram`]`::has_boundary`, the single-
/// pass short-circuiting scan over the fixed-cardinality counts
/// vector that returns `false` the moment both a zero cell *and* a
/// nonzero cell have been witnessed, bounded at two witness cells —
/// strictly tighter than any of the documented open-coded surfaces
/// one seam over.
///
/// The **boundary-env-prefix-kinds peer** of the two documented
/// surface forms consumers previously re-derived inline:
/// `!chain.env_prefix_kinds_any_observed() ||
/// chain.env_prefix_kinds_full_cover()` (the defining union-of-
/// coverage-boundaries disjunction on the two named histogram-side
/// peers — one negation and two method calls with a boolean or),
/// and `chain.present_env_prefix_kinds_count() == 0 ||
/// chain.present_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<crate::EnvMetadataTagKind>()` (the
/// support-scalar dual-equality form, which pays for a full-axis
/// scan and equates a `usize` against two magic thresholds with a
/// turbofish). This lift names the boundary-env-prefix-kinds
/// predicate directly at the chain-altitude surface with a single-
/// pass short-circuiting scan — the typed boolean every operator-
/// facing *"did the chain land on an env-prefix coverage boundary?"*
/// check reads off as a single method call.
///
/// **Closes the "boundary across altitudes" projection** at the
/// fifth and final altitude / sub-axis: seeded on the diff altitude
/// by [`crate::ConfigDiff::kinds_boundary`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_boundary`], lifted
/// sideways to the chain layer-kind sub-axis by
/// [`Self::layer_kinds_boundary`], and lifted sideways to the chain
/// file-format sub-axis by [`Self::file_formats_boundary`]. With
/// this lift the "boundary across altitudes" projection carries the
/// same one-predicate row at every altitude / sub-axis of the
/// closed coverage-support predicate cube, and the distance-from-
/// boundary ternary's top leg closes at every altitude / sub-axis
/// pointwise alongside the boundary-free strict interior and
/// singular near-boundary corners already named. Symmetric peer of
/// the parallel "singular across altitudes",
/// "strict-partial-cover across altitudes", "high-support across
/// altitudes", and "low-support across altitudes" projections
/// closed at this same sub-axis by
/// [`Self::env_prefix_kinds_singular`],
/// [`Self::env_prefix_kinds_strict_partial_cover`],
/// [`Self::env_prefix_kinds_high_support`], and
/// [`Self::env_prefix_kinds_low_support`].
///
/// **Cardinality-`2` reachability at the chain env-prefix sub-axis
/// — degenerate distance ternary, boundary/singular exhaustion.**
/// [`EnvMetadataTagKind`] carries two cells, so the strict interior
/// of the distance ternary is *structurally empty* (interval `[2,
/// cardinality - 2] = [2, 0]` is empty) —
/// [`Self::env_prefix_kinds_strict_partial_cover`] is vacuously
/// `false` on every chain, so the distance-from-boundary ternary
/// degenerates to the dual partition `(has_boundary, has_singular)`
/// on this sub-axis. The env-prefix sub-axis carries the *tightest*
/// degenerate distance ternary in the projection: two cardinality
/// steps below the reachability threshold, matching the layer-kind
/// sub-axis and the diff altitude on their cardinality-`3` axes and
/// diverging from the tier altitude and the file-format sub-axis
/// where the cardinality-`4` axis inhabits every leg non-vacuously.
/// The boundary corner is inhabited on the empty chain, on every
/// no-env-layers chain (empty-histogram non-empty chain), and on
/// every uniform two-kind cover; the singular near-boundary corner
/// is inhabited on every singleton-support chain — together the
/// two corners exhaust the cardinality-`2` fixture space, so
/// `env_prefix_kinds_boundary ⇔ !env_prefix_kinds_singular`
/// pointwise.
///
/// **Empty-chain convention** — returns `true` on the empty chain:
/// the empty chain observes zero cells, so every cell is unobserved
/// (two zeros on the cardinality-`2` axis) — the single-pass scan
/// sees no nonzero cell and falls through to `true`. Matches
/// [`crate::AxisHistogram::has_boundary`]'s empty-histogram `true`
/// convention one altitude down. The empty chain sits on the bottom
/// coverage boundary via the
/// [`Self::env_prefix_kinds_any_observed`]-negation disjunct. Peer
/// of [`Self::file_formats_boundary`]'s empty-chain `true` polarity
/// one sub-axis over on the same chain altitude, of
/// [`Self::layer_kinds_boundary`]'s empty-chain `true` polarity,
/// of [`crate::ProvenanceMap::tiers_boundary`]'s empty-map `true`
/// polarity, and of [`crate::ConfigDiff::kinds_boundary`]'s empty-
/// diff `true` polarity in the same projection.
///
/// **No-env-layers convention** — returns `true` on every non-empty
/// chain whose env-prefix histogram is empty (chains of only
/// [`ConfigSource::Defaults`] / [`ConfigSource::File`] layers). The
/// env-prefix projection is a partial function
/// ([`ConfigSource::env_prefix_kind`] returns [`None`] for
/// [`ConfigSource::Defaults`] and [`ConfigSource::File`]), so a
/// non-empty chain can still project to an empty histogram — the
/// single-pass scan sees no nonzero cell and falls through to
/// `true`. Cross-sub-axis divergence pin against
/// [`Self::layer_kinds_boundary`]: on the same fixtures the layer-
/// kind sub-axis observes at least one layer-kind cell (Defaults /
/// File) with partial support, so `layer_kinds_boundary` typically
/// reads `false` — the narrower env-prefix boundary still fires via
/// the partial-function projection's empty-histogram case. Matches
/// [`Self::file_formats_boundary`]'s no-recognized-files convention
/// one sub-axis over.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed env-prefix support is a single
/// [`EnvMetadataTagKind`] cell: the support cardinality is `1` (one
/// nonzero and one zero on the cardinality-`2` axis), so the single-
/// pass scan sees a nonzero cell *and* a zero cell and returns
/// `false`. On the cardinality-`2` axis the singleton-support
/// boundary IS the singular near-boundary corner (the dual-
/// singular-collapse `singular_support ⇔ singular_gap`), so every
/// singleton-support chain lands on the singular leg of the
/// (degenerate) distance ternary. `sample_chain()` (two `.yaml` file
/// layers alongside one prefixed env layer, `{Prefixed}` env-prefix
/// support) is a witness on the `false` side.
///
/// **Uniform two-kind cover convention** — returns `true` on every
/// chain where each [`EnvMetadataTagKind`] cell was observed at
/// least once: the support cardinality is `2` (no unobserved cells
/// on the cardinality-`2` axis) — the single-pass scan sees only
/// nonzero cells and falls through to `true`. The full-cover
/// boundary sits at the top of the coverage interval via the
/// [`Self::env_prefix_kinds_full_cover`] disjunct.
///
/// # Invariants
///
/// - `env_prefix_kinds_boundary() ==
/// env_prefix_kind_histogram().has_boundary()` — both project the
/// same predicate off the same primitive; the named seam is the
/// cube-native routing of the histogram surface.
/// - `env_prefix_kinds_boundary() ⇔ !env_prefix_kinds_any_observed()
/// || env_prefix_kinds_full_cover()` — the defining union-of-
/// coverage-boundaries disjunction on the two named coverage-
/// boundary peers.
/// - `env_prefix_kinds_boundary() ==
/// (present_env_prefix_kinds_count() == 0 ||
/// present_env_prefix_kinds_count() ==
/// crate::axis_cardinality::<crate::EnvMetadataTagKind>())`
/// always — the support-scalar dual-equality surface, without
/// allocating either `Vec<crate::EnvMetadataTagKind>`. The two
/// equalities are strictly disjoint (`0 != 2 = cardinality` on
/// the env-prefix axis).
/// - `env_prefix_kinds_boundary() ==
/// (present_env_prefix_kinds_count() == 0 ||
/// absent_env_prefix_kinds_count() == 0)` always — the dual-
/// scalar equality form on the two named cardinality peers, the
/// `present + absent == axis_cardinality` invariant restated.
/// - `!env_prefix_kinds_any_observed() ⇒
/// env_prefix_kinds_boundary()` always — the empty chain AND
/// every empty-histogram non-empty chain sit on the boundary via
/// the bottom disjunct.
/// - `env_prefix_kinds_full_cover() ⇒ env_prefix_kinds_boundary()`
/// always — the full-cover chain sits on the boundary via the top
/// disjunct.
/// - `env_prefix_kinds_boundary() ⇒ !env_prefix_kinds_singular()`
/// on every axis with cardinality `>= 2`: the two boundary
/// cardinalities (`0` and `cardinality`) sit strictly outside the
/// two singular cardinalities (`1` and `cardinality - 1`) — the
/// boundary corner and the singular near-boundary corner are
/// pairwise disjoint legs of the distance ternary. Strengthened
/// on the cardinality-`2` env-prefix axis into the equivalence
/// `env_prefix_kinds_boundary ⇔ !env_prefix_kinds_singular` by
/// the boundary-and-singular exhaustion (the vacuous strict
/// interior collapses the ternary to a bipartition).
/// - `env_prefix_kinds_boundary() ⇒
/// !env_prefix_kinds_strict_partial_cover()` always. Holds
/// *vacuously* on the cardinality-`2` env-prefix axis — the
/// strict interior is structurally empty (the strict interval
/// `[2, cardinality - 2] = [2, 0]` is empty), so
/// `!env_prefix_kinds_strict_partial_cover` reads `true` on
/// every chain regardless of `env_prefix_kinds_boundary`. The
/// env-prefix sub-axis carries the *tightest* vacuously-true
/// consequent in the projection — two cardinality steps below
/// the reachability threshold, matching the layer-kind sub-axis's
/// and the diff altitude's vacuously-`true` consequent on their
/// cardinality-`3` axes and diverging from the tier altitude's
/// and the file-format sub-axis's non-vacuous consequent on their
/// cardinality-`4` axes. Peer of the histogram-side
/// `axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor`
/// partition law one altitude down.
/// - `(env_prefix_kinds_boundary, env_prefix_kinds_singular,
/// env_prefix_kinds_strict_partial_cover)` is a strict ternary
/// partition on every axis with cardinality `>= 2`. On the
/// cardinality-`2` env-prefix axis the third leg is vacuously
/// empty and the ternary degenerates to the dual partition
/// `(env_prefix_kinds_boundary, env_prefix_kinds_singular)`
/// pointwise — the *tightest* degenerate distance ternary in the
/// projection, matching the layer-kind sub-axis's and the diff
/// altitude's degenerate two-way partition on their cardinality-
/// `3` axes and diverging from the tier altitude's and the file-
/// format sub-axis's non-vacuous three-leg partition on their
/// cardinality-`4` axes.
/// - **Cross-surface bridge law** — `chain.env_prefix_kinds_boundary()
/// == chain.env_prefix_kind_histogram().support_cardinality_class().is_boundary()`
/// always. The class-side projection lands on
/// [`crate::SupportCardinalityClass::Empty`] or
/// [`crate::SupportCardinalityClass::FullCover`] exactly when the
/// histogram-side disjunction fires, and
/// [`crate::SupportCardinalityClass::is_boundary`] reads `true`
/// on either variant. Peer of the histogram-side bridge
/// `axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor`
/// one altitude down, closing the (histogram, class) duality on
/// the boundary leg at the chain env-prefix sub-axis.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram build)
/// and `k = crate::axis_cardinality::<crate::EnvMetadataTagKind>()`
/// (the boundary scan). Both are `O(n)` in practice since the
/// env-prefix axis carries a fixed two-cell cardinality; the
/// returned `bool` reads one predicate. The scan returns `false`
/// the *moment* a mixed-parity witness (one zero *and* one nonzero)
/// has been seen — bounded at two witness cells visited — strictly
/// tighter than the documented open-coded surfaces.
#[must_use]
fn env_prefix_kinds_boundary(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().has_boundary()
}
/// `true` exactly when this chain's observed [`EnvMetadataTagKind`]
/// support sits *strictly between* the two coverage boundaries —
/// at least one env-prefix cell observed
/// ([`Self::env_prefix_kinds_any_observed`] `== true`) *and* at
/// least one env-prefix cell unobserved
/// ([`Self::env_prefix_kinds_full_cover`] `== false`).
///
/// The **partial-cover-env-prefix-kinds boolean predicate** on the
/// env-prefix sub-axis of the chain altitude, the *middle* leg of
/// the coverage trichotomy `(!env_prefix_kinds_any_observed,
/// env_prefix_kinds_partial_cover, env_prefix_kinds_full_cover)` —
/// the direct strict-complement of the top-leg
/// [`Self::env_prefix_kinds_boundary`] corner, folding both
/// singular near-boundary corners into a single "some but not all"
/// corner on the cardinality-`2` env-prefix axis (the strict
/// interior is structurally empty here, so the middle leg collapses
/// onto the two singular near-boundary corners). Routes through
/// [`Self::env_prefix_kind_histogram`]`::has_partial_cover`, the
/// single-pass short-circuiting scan over the fixed-cardinality
/// counts vector that returns `true` the moment both a zero cell
/// *and* a nonzero cell have been witnessed, bounded at two
/// witness cells — strictly tighter than any of the documented
/// open-coded surfaces one seam over.
///
/// The **partial-cover-env-prefix-kinds peer** of the documented
/// surface forms consumers previously re-derived inline:
/// `chain.env_prefix_kinds_any_observed() &&
/// !chain.env_prefix_kinds_full_cover()` (the defining conjunction-
/// of-negations form on the two named coverage-boundary peers —
/// two method calls with a boolean and — the exact expression used
/// verbatim by the pre-existing bipartition-law pin
/// [`tests::env_prefix_kinds_boundary_and_env_prefix_kinds_partial_cover_form_strict_bipartition_pointwise`]),
/// `0 < chain.present_env_prefix_kinds_count() &&
/// chain.present_env_prefix_kinds_count() <
/// crate::axis_cardinality::<crate::EnvMetadataTagKind>()` (the
/// support-scalar strict-interval form, which pays for a full-axis
/// scan and brackets a `usize` between two magic thresholds with a
/// turbofish), and `chain.present_env_prefix_kinds_count() > 0 &&
/// chain.absent_env_prefix_kinds_count() > 0` (the dual-scalar
/// mixed-side non-emptiness form on the two named cardinality
/// peers). This lift names the partial-cover-env-prefix-kinds
/// predicate directly at the chain-altitude surface with a single-
/// pass short-circuiting scan — the typed boolean every operator-
/// facing *"did the chain see some but not all env-prefix kinds?"*
/// check reads off as a single method call.
///
/// **Closes the "partial-cover across altitudes" projection** at
/// the fifth and final altitude / sub-axis: seeded on the diff
/// altitude by [`crate::ConfigDiff::kinds_partial_cover`], climbed
/// to the tier altitude by
/// [`crate::ProvenanceMap::tiers_partial_cover`], lifted sideways
/// to the chain layer-kind sub-axis by
/// [`Self::layer_kinds_partial_cover`], and lifted sideways to the
/// chain file-format sub-axis by
/// [`Self::file_formats_partial_cover`]. Middle-leg-corner peer of
/// the nine already-closed coverage-support and magnitude boundary
/// and interior families on the same sub-axis
/// ([`Self::env_prefix_kinds_balanced`],
/// [`Self::env_prefix_kinds_full_cover`],
/// [`Self::env_prefix_kinds_any_observed`],
/// [`Self::env_prefix_kinds_singular_support`],
/// [`Self::env_prefix_kinds_singular_gap`],
/// [`Self::env_prefix_kinds_strict_partial_cover`],
/// [`Self::env_prefix_kinds_low_support`],
/// [`Self::env_prefix_kinds_high_support`],
/// [`Self::env_prefix_kinds_singular`],
/// [`Self::env_prefix_kinds_boundary`]) — the strict-complement
/// middle-leg peer of the top-leg boundary corner on the coverage
/// trichotomy. With this lift the "partial-cover across altitudes"
/// projection carries the same one-predicate row at every altitude
/// / sub-axis of the closed coverage-support predicate cube,
/// mirroring the six sibling projections already closed across the
/// same grid (`boundary`, `singular`, `strict_partial_cover`,
/// `low_support`, `high_support`, and the extremal `any_observed` /
/// `full_cover` boundary peers).
///
/// **Cardinality-`2` reachability at the chain env-prefix sub-
/// axis — degenerate ternary, partial-cover collapses onto the
/// singular corners.** [`EnvMetadataTagKind`] carries two cells so
/// `env_prefix_kinds_partial_cover()` reads `true` on every
/// singleton-support chain (support cardinality `1` — one nonzero
/// and one zero mixed, exactly *both* singular near-boundary
/// corners of the distance ternary at once via the dual-singular-
/// collapse `singular_support ⇔ singular_gap` on the cardinality-
/// `2` axis), and `false` on the empty chain and every empty-
/// histogram non-empty chain (two unobserved cells — no nonzero
/// witness) and on every uniform two-kind cover (two observed
/// cells — no zero witness). The strict-interior middle leg
/// [`Self::env_prefix_kinds_strict_partial_cover`] is *vacuously*
/// `false` on the cardinality-`2` axis (the strict interval `[2,
/// cardinality - 2] = [2, 0]` is empty), so on this sub-axis
/// `env_prefix_kinds_partial_cover` collapses to the singular
/// near-boundary corner
/// (`env_prefix_kinds_partial_cover ⇔ env_prefix_kinds_singular`
/// pointwise via the tightening of the general distance ternary
/// onto the two-cell axis) — the *tightest* degenerate partial-
/// cover leg in the projection, matching the layer-kind sub-axis
/// and the diff altitude on their cardinality-`3` axes (also
/// degenerate through the vacuous strict interior into a singular-
/// only middle leg) and diverging from the tier altitude and the
/// file-format sub-axis where the cardinality-`4` axis inhabits
/// every leg (the two-tier / two-format partial-cover fixtures are
/// the unique strict-interior witnesses).
///
/// **Cross-sub-axis divergence pin against
/// [`Self::layer_kinds_partial_cover`]** — the no-env-layers non-
/// empty chain silently drops out of the partial-cover middle leg
/// on the env-prefix sub-axis. A non-empty chain of only Defaults
/// / File layers has an empty env-prefix histogram (the
/// [`ConfigSource::env_prefix_kind`] projection is a partial
/// function, returning `None` for Defaults / File), so
/// `env_prefix_kinds_partial_cover` reads `false` via the empty-
/// histogram case. On the same fixtures the layer-kind sub-axis
/// observes at least one layer-kind cell (Defaults / File) with
/// partial support and typically reads
/// `layer_kinds_partial_cover = true` — the bipartition still
/// holds on both sides, but the partial-cover leg's meaning is
/// *narrower* at the env-prefix sub-axis than at the layer-kind
/// sub-axis (same shape as the file-format sub-axis's no-
/// recognized-files convention).
///
/// **Empty-chain convention** — returns `false` on the empty
/// chain: the empty chain observes zero cells, so every cell is
/// unobserved (two zeros on the cardinality-`2` axis) — the
/// single-pass scan sees no nonzero cell and falls through to
/// `false`. Matches [`crate::AxisHistogram::has_partial_cover`]'s
/// empty-histogram `false` convention one altitude down. The
/// empty chain sits strictly outside the partial-cover middle
/// leg via the [`Self::env_prefix_kinds_any_observed`]-negation
/// half of the defining conjunction. Peer of
/// [`crate::ProvenanceMap::tiers_partial_cover`]'s empty-map
/// `false` polarity and
/// [`crate::ConfigDiff::kinds_partial_cover`]'s empty-diff
/// `false` polarity in the same projection.
///
/// **Singleton-support convention** — returns `true` on every
/// chain whose observed env-prefix support is a single
/// [`EnvMetadataTagKind`] cell (prefixed-only or bare-only): the
/// support cardinality is `1` (one nonzero and one zero on the
/// cardinality-`2` axis), so the single-pass scan sees a nonzero
/// cell *and* a zero cell and returns `true`. Direct witness of
/// the subsumption `env_prefix_kinds_singular ⇒
/// env_prefix_kinds_partial_cover` via the mixed-parity witness
/// on the dual-singular-collapse two-cell axis. The
/// `sample_chain()` fixture (two `.yaml` file layers + one
/// `"APP_"` Env layer, {Prefixed} support) is a witness on the
/// `true` side.
///
/// **Uniform two-kind cover convention** — returns `false` on
/// every chain where each [`EnvMetadataTagKind`] cell was
/// observed at least once: the support cardinality is `2` (no
/// unobserved cells on the cardinality-`2` axis), so the single-
/// pass scan sees only nonzero cells and falls through to
/// `false`. The full-cover boundary sits strictly above the
/// partial-cover middle leg via the
/// [`Self::env_prefix_kinds_full_cover`]-negation half of the
/// defining conjunction.
///
/// # Invariants
///
/// - `env_prefix_kinds_partial_cover() == env_prefix_kind_histogram().has_partial_cover()`
/// — both project the same predicate off the same primitive;
/// the named seam is the cube-native routing of the histogram
/// surface.
/// - `env_prefix_kinds_partial_cover() ⇔ env_prefix_kinds_any_observed() &&
/// !env_prefix_kinds_full_cover()` — the defining conjunction-
/// of-negations form on the two named coverage-boundary peers.
/// - `env_prefix_kinds_partial_cover() == (0 < present_env_prefix_kinds_count()
/// && present_env_prefix_kinds_count() <
/// crate::axis_cardinality::<crate::EnvMetadataTagKind>())`
/// always — the support-scalar strict-interval surface, without
/// allocating `Vec<crate::EnvMetadataTagKind>`.
/// - `env_prefix_kinds_partial_cover() == (0 < absent_env_prefix_kinds_count()
/// && absent_env_prefix_kinds_count() <
/// crate::axis_cardinality::<crate::EnvMetadataTagKind>())`
/// always — the coverage-gap dual-scalar strict-interval
/// surface, the `present + absent == axis_cardinality`
/// invariant restated.
/// - `env_prefix_kinds_partial_cover() == (present_env_prefix_kinds_count() > 0
/// && absent_env_prefix_kinds_count() > 0)` always — the mixed-
/// side dual-scalar non-emptiness form, the direct histogram-
/// surface `distinct_cells > 0 && unobserved_cells > 0` pin
/// restated at the chain env-prefix sub-axis, without
/// allocating either `Vec<crate::EnvMetadataTagKind>`.
/// - `env_prefix_kinds_partial_cover() ⇒ env_prefix_kinds_any_observed()`
/// always — the partial-cover corner requires at least one
/// observed cell.
/// - `env_prefix_kinds_partial_cover() ⇒ !env_prefix_kinds_full_cover()`
/// always — the partial-cover corner excludes the top coverage
/// boundary.
/// - `env_prefix_kinds_singular_support() ⇒ env_prefix_kinds_partial_cover()`
/// always on cardinality-`>= 2` axes: support cardinality `1`
/// is strictly between `0` and cardinality. Direct pin of the
/// histogram-side subsumption `has_singular_support ⇒
/// has_partial_cover` one altitude down.
/// - `env_prefix_kinds_singular_gap() ⇒ env_prefix_kinds_partial_cover()`
/// always on cardinality-`>= 2` axes: support cardinality
/// `cardinality - 1` is strictly between `0` and cardinality.
/// On the cardinality-`2` env-prefix axis the singular-gap
/// boundary coincides with the singular-support boundary (the
/// dual-singular-collapse `singular_gap ⇔ singular_support`),
/// so this subsumption reads the same witnesses as the peer
/// above.
/// - `env_prefix_kinds_singular() ⇒ env_prefix_kinds_partial_cover()`
/// always on cardinality-`>= 2` axes — the union of the two
/// singular-side subsumptions.
/// - `env_prefix_kinds_strict_partial_cover() ⇒ env_prefix_kinds_partial_cover()`
/// always — the strict interior sits inside the partial-cover
/// middle leg by definition. *Vacuously-`true`* on the
/// cardinality-`2` env-prefix axis (the strict interior is
/// structurally empty), the *tightest* vacuously-true
/// antecedent in the projection — matching the layer-kind sub-
/// axis and the diff altitude on their cardinality-`3` axes
/// and diverging from the tier altitude and the file-format
/// sub-axis where the cardinality-`4` axis witnesses both
/// consequent and antecedent `true` non-vacuously.
/// - `env_prefix_kinds_partial_cover() ⇔ env_prefix_kinds_singular()`
/// pointwise on the cardinality-`2` env-prefix axis — the
/// *unique* two-cell-axis tightening of the general
/// subsumption `singular ⇒ partial_cover` (documented at every
/// altitude / sub-axis) into an equivalence, via the vacuously-
/// `false` strict interior on this axis (the partial-cover
/// middle leg has no strict-interior witnesses, so it
/// collapses onto the singular near-boundary corner). Does NOT
/// lift to the cardinality-`>= 3` sub-axes
/// ([`Self::layer_kinds_partial_cover`],
/// [`Self::file_formats_partial_cover`]) where the singleton-
/// gap boundary sits at support cardinality
/// `axis_cardinality - 1 >= 2` on the strict interior of the
/// partial-cover middle leg (cardinality-`4` file-format
/// sub-axis) or collapses to the same singular-only middle leg
/// as here through a *different* vacuous strict interior
/// (cardinality-`3` layer-kind sub-axis).
/// - `env_prefix_kinds_partial_cover()` and
/// [`Self::env_prefix_kinds_boundary`] form a strict
/// bipartition — exactly one fires on every chain. Peer of the
/// histogram-side bipartition law
/// `axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`
/// one altitude down.
/// - **Coverage-trichotomy partition law** —
/// `(!env_prefix_kinds_any_observed, env_prefix_kinds_partial_cover,
/// env_prefix_kinds_full_cover)` is a strict ternary partition
/// on every axis with cardinality `>= 1` (the cardinality-`2`
/// [`EnvMetadataTagKind`] axis). Exactly one leg fires on
/// every chain — the coverage trichotomy of the `(is_empty,
/// has_partial_cover, is_full_cover)` histogram-side partition
/// restated at the chain env-prefix sub-axis. Peer of the
/// trait-uniform pin
/// `axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor`
/// one altitude down.
/// - **Cross-surface bridge law** —
/// `chain.env_prefix_kinds_partial_cover() ==
/// chain.env_prefix_kind_histogram().support_cardinality_class().is_partial_cover()`
/// always. Peer of the histogram-side bridge
/// `axis_histogram_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover_for_every_closed_axis_implementor`
/// one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::EnvMetadataTagKind>()`
/// (the partial-cover scan). Both are `O(n)` in practice since
/// the env-prefix axis carries a fixed two-cell cardinality; the
/// returned `bool` reads one predicate. The scan returns `true`
/// the *moment* a mixed-parity witness (one zero *and* one
/// nonzero) has been seen — bounded at two witness cells
/// visited on any strict-interior histogram — strictly tighter
/// than the documented open-coded surfaces.
#[must_use]
fn env_prefix_kinds_partial_cover(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().has_partial_cover()
}
/// `true` exactly when this chain's observed [`EnvMetadataTagKind`]
/// histogram has two or more cells tied at the peak leaf count — the
/// peak env-prefix kind is *shared* rather than uniquely held.
///
/// The **modally-tied-env-prefix-kinds boolean predicate** on the
/// env-prefix sub-axis of the chain altitude, the direct strict-
/// complement of [`crate::AxisHistogram::is_strictly_modally_unique`]
/// on every non-empty env-prefix histogram (both read `false` on the
/// empty histogram — the shared boundary below both branches of the
/// strict modal partition). Routes through
/// [`Self::env_prefix_kind_histogram`]`::is_modally_tied`, the
/// single-pass scan over the fixed-cardinality counts vector reading
/// `peak_multiplicity() >= 2` off one predicate — strictly tighter
/// than either of the documented open-coded surface forms one seam
/// over.
///
/// The **modally-tied-env-prefix-kinds peer** of the two documented
/// surface forms consumers previously re-derived inline:
/// `chain.env_prefix_kind_histogram().peak_multiplicity() >= 2` (the
/// defining multiplicity-scalar inequality form — one method call
/// plus a magic `>= 2` threshold at the consumer site), and
/// `chain.env_prefix_kind_histogram().modality_degree().0 >= 2` (the
/// modality-pair projection-inequality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison — a fused-pair build for a single-component
/// projection). This lift names the modally-tied-env-prefix-kinds
/// predicate directly at the chain-altitude surface — the typed
/// boolean every operator-facing *"is the dominant env-prefix kind
/// uniquely held on this chain, or tied?"* check reads off as a
/// single method call.
///
/// **Closes the "modally-tied across altitudes" projection** at the
/// fifth and final altitude / sub-axis: seeded on the diff altitude
/// by [`crate::ConfigDiff::kinds_modally_tied`], climbed to the tier
/// altitude by [`crate::ProvenanceMap::tiers_modally_tied`], lifted
/// sideways to the chain layer-kind sub-axis by
/// [`Self::layer_kinds_modally_tied`], and lifted sideways to the
/// chain file-format sub-axis by [`Self::file_formats_modally_tied`].
/// Modal-tie-side row on top of the closed coverage-support
/// predicate cube (`low_support`, `high_support`,
/// `strict_partial_cover`, `singular`, `boundary`, `partial_cover`)
/// — the seventh projection to close at every altitude / sub-axis
/// in lockstep, matching the shape of the six sibling projections
/// on the same grid. With this lift the "modally-tied across
/// altitudes" projection carries the same one-predicate row at
/// every altitude / sub-axis of the fully-closed cube.
///
/// **Cardinality-`2` reachability at the chain env-prefix sub-axis
/// — degenerate strict modal partition, modally-tied collapses onto
/// the uniform-cover boundary corner.** [`EnvMetadataTagKind`]
/// carries two cells so `env_prefix_kinds_modally_tied()` reads
/// `true` exactly when both cells share the peak leaf count (the
/// uniform two-kind cover, e.g. one prefixed + one bare tied at
/// count `1`, or two prefixed + two bare tied at count `2`), and
/// `false` on the empty chain (no observed cell), on every no-env-
/// layers non-empty chain (empty env-prefix histogram via the
/// partial-function projection), on every singleton-support chain
/// (support cardinality `1`, peak multiplicity `1` — the lone
/// observed cell stands alone at its own peak), and on every
/// strictly-modal skewed chain (e.g. two prefixed + one bare where
/// `Prefixed` uniquely peaks at count `2`). On the cardinality-`2`
/// axis the modally-tied corner reduces to *exactly* the uniform-
/// cover boundary corner (`env_prefix_kinds_modally_tied ⇔
/// env_prefix_kinds_full_cover ∧ env_prefix_kinds_balanced` on this
/// axis — the peak-multiplicity walk reaches `2` iff both cells are
/// observed at the same count, which on cardinality-`2` is precisely
/// the uniform-cover corner). The *tightest* degenerate modally-
/// tied leg in the projection: the layer-kind sub-axis and the
/// diff altitude carry the two-of-three-observed strict-interior
/// tied witness at their cardinality-`3` axes, and the tier
/// altitude and file-format sub-axis carry the additional support-
/// `3` tied witness at their cardinality-`4` axes — both classes
/// unreachable at the cardinality-`2` env-prefix sub-axis.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain observes zero cells, so
/// [`crate::AxisHistogram::peak_multiplicity`] reads `0` and the
/// inequality `0 >= 2` fails. Matches
/// [`crate::AxisHistogram::is_modally_tied`]'s empty-histogram
/// convention one altitude down. The empty-chain row on the strict
/// modal partition pair
/// `(is_strictly_modally_unique, is_modally_tied)` reads
/// `(false, false)` — the shared boundary below both branches. Peer
/// of [`Self::file_formats_modally_tied`]'s empty-chain `false`
/// polarity and [`Self::layer_kinds_modally_tied`]'s empty-chain
/// `false` polarity one sub-axis over on the same chain altitude,
/// of [`crate::ProvenanceMap::tiers_modally_tied`]'s empty-map
/// `false` polarity, and of [`crate::ConfigDiff::kinds_modally_tied`]'s
/// empty-diff `false` polarity — closing the empty-witness row of
/// the projection at the fifth and final altitude / sub-axis.
///
/// **No-env-layers convention** — returns `false` on every non-empty
/// chain whose env-prefix histogram is empty (only `Defaults` and
/// `File` layers). The env-prefix projection is a partial function
/// ([`ConfigSource::env_prefix_kind`] returns [`None`] for both
/// `Defaults` and `File`), so a non-empty chain can still project
/// to an empty histogram — `peak_multiplicity` reads `0` and the
/// inequality `0 >= 2` fails. This is the modal-tie-side cross-sub-
/// axis divergence pin against [`Self::layer_kinds_modally_tied`]:
/// on the same fixtures the layer-kind sub-axis observes at least
/// one layer-kind cell (Defaults / File) and may fire the modally-
/// tied predicate (e.g. one `Defaults` + one `File` reads
/// `layer_kinds_modally_tied = true`), while the env-prefix sub-
/// axis's modally-tied predicate silently drops out via the empty-
/// histogram disjunct — the modal-tie leg's meaning is *narrower*
/// at the env-prefix sub-axis than at the layer-kind sub-axis.
/// Mirrors the shape of [`Self::file_formats_modally_tied`]'s no-
/// recognized-files convention on the sister partial-function
/// projection.
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed env-prefix support is a single
/// [`EnvMetadataTagKind`] cell (prefixed-only or bare-only): the
/// lone observed cell stands alone at its own peak (no tie-break
/// to exercise), so `peak_multiplicity` reads `1` and the
/// inequality `1 >= 2` fails. The `sample_chain()` fixture (two
/// `.yaml` file layers + one `"APP_"` Env layer, `{Prefixed}`
/// env-prefix support with count `1`) is a witness on the `false`
/// side — the singleton-support corner is uniformly on the strictly-
/// modal-unique side of the strict modal partition. Direct pin of
/// the histogram-side subsumption `has_singular_support ⇒
/// !is_modally_tied` one altitude down.
///
/// **Uniform two-kind cover convention** — returns `true` on every
/// chain where each [`EnvMetadataTagKind`] cell was observed at
/// exactly the same positive count (the *only* modally-tied witness
/// class on the cardinality-`2` env-prefix axis): the two cells
/// share the same count, so `peak_multiplicity` reads `2` and the
/// inequality `2 >= 2` fires. Peer of the histogram-side axis-cover
/// convention one altitude down, which reads `true` on every
/// implementor with `axis_cardinality::<A>() >= 2` — the
/// cardinality-`2` [`EnvMetadataTagKind`] axis honours the general
/// condition. Also the *tightest* modally-tied surface: on
/// cardinality-`2` axes the modally-tied predicate reads `true`
/// iff *both* cells are observed at the same count, i.e. exactly
/// the [`Self::env_prefix_kinds_full_cover`] ∧
/// [`Self::env_prefix_kinds_balanced`] corner.
///
/// **Two-way modal partition on non-empty env-prefix histograms** —
/// on every non-empty env-prefix histogram exactly one of the modal-
/// uniqueness pair fires: either the peak is uniquely held
/// (strictly-modal-unique fires, modally-tied does not) or the peak
/// is shared (modally-tied fires, strictly-modal-unique does not).
/// The empty histogram sits below both branches (both read `false`)
/// — this covers both the empty chain and every no-env-layers non-
/// empty chain. Direct pin of the histogram-side strict modal
/// partition
/// `!is_empty ⇒ is_modally_tied ⇔ !is_strictly_modally_unique` one
/// altitude down.
///
/// # Invariants
///
/// - `env_prefix_kinds_modally_tied() == env_prefix_kind_histogram().is_modally_tied()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `env_prefix_kinds_modally_tied() ⇔
/// env_prefix_kind_histogram().peak_multiplicity() >= 2` — the
/// defining multiplicity-scalar inequality form on the
/// [`crate::AxisHistogram::peak_multiplicity`] scalar peer, the
/// canonical open-coded expression of the predicate one altitude
/// down.
/// - `env_prefix_kinds_modally_tied() ⇔
/// env_prefix_kind_histogram().modality_degree().0 >= 2` — the
/// modality-pair projection-inequality form, reading the modal
/// component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison.
/// - `env_prefix_kinds_modally_tied() ⇒ env_prefix_kinds_any_observed()`
/// always — a tied peak requires at least two observed cells, so
/// both the empty chain (zero observed cells) and every no-env-
/// layers non-empty chain (empty env-prefix histogram via the
/// partial-function projection) cannot fire.
/// Contrapositively, `!env_prefix_kinds_any_observed() ⇒
/// !env_prefix_kinds_modally_tied()`.
/// - `env_prefix_kinds_singular_support() ⇒ !env_prefix_kinds_modally_tied()`
/// always — a singleton-support chain has exactly one observed
/// cell, so the modal level set has cardinality `1` and the tie
/// predicate fails. Contrapositively, `env_prefix_kinds_modally_tied()
/// ⇒ !env_prefix_kinds_singular_support()`: a fired tie predicate
/// means at least two observed cells. Direct pin of the
/// histogram-side subsumption `has_singular_support ⇒
/// !is_modally_tied` one altitude down.
/// - `env_prefix_kinds_full_cover() ∧ env_prefix_kinds_balanced() ⇒
/// env_prefix_kinds_modally_tied()` on the cardinality-`>= 2`
/// axis: a full-cover uniform-count chain has every cell observed
/// at the same count, so the modal level set equals the full axis
/// — the peak multiplicity rises to
/// `axis_cardinality::<EnvMetadataTagKind>()` which is `2`, and
/// the tie predicate fires. Cardinality-`>= 2` witness of the
/// uniform-cover corner of the histogram-side subsumption tying
/// [`crate::AxisHistogram::is_uniform_count`] and
/// [`crate::AxisHistogram::has_singular_support`] on non-empty
/// histograms one altitude down.
/// - `env_prefix_kinds_modally_tied() ⇔ env_prefix_kinds_full_cover() ∧
/// env_prefix_kinds_balanced()` pointwise on the cardinality-`2`
/// env-prefix axis — the *unique* two-cell-axis tightening of the
/// general uniform-cover subsumption above into an equivalence,
/// via the collapse of the modally-tied corner onto the uniform-
/// cover boundary corner. On this axis the two-of-three-observed
/// strict-interior tied witness available at the layer-kind sub-
/// axis / diff altitude (cardinality-`3` axes) is structurally
/// unreachable, and the support-`3` tied witness available at the
/// file-format sub-axis / tier altitude (cardinality-`4` axes) is
/// likewise unreachable — the *only* modally-tied witness class
/// is the uniform-cover corner itself. Does NOT lift to the
/// cardinality-`>= 3` sub-axes ([`Self::layer_kinds_modally_tied`],
/// [`Self::file_formats_modally_tied`]) where the strict-interior
/// tied witness carries `modally_tied=true, full_cover=false,
/// balanced=varies` non-vacuously.
/// - **Strict modal partition on non-empty env-prefix histograms**
/// — `!env_prefix_kind_histogram().is_empty() ⇒
/// (env_prefix_kinds_modally_tied ⇔
/// !env_prefix_kind_histogram().is_strictly_modally_unique())`
/// always. On every non-empty env-prefix histogram exactly one of
/// `(env_prefix_kinds_modally_tied,
/// env_prefix_kind_histogram().is_strictly_modally_unique())`
/// fires; both read `false` on the empty histogram — the shared
/// boundary below both branches. Direct pin of the histogram-side
/// strict modal partition one altitude down.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::EnvMetadataTagKind>()`
/// (the peak-multiplicity scan). Both are `O(n)` in practice since
/// the env-prefix axis carries a fixed two-cell cardinality; the
/// returned `bool` reads one predicate — the peak scan walks the
/// counts vector once and counts cells matching the max, then
/// reads `multiplicity >= 2` off one comparison. Strictly tighter
/// than the two documented open-coded surfaces one seam over (no
/// exposed `>= 2` magic threshold at the consumer site, no
/// [`crate::AxisHistogram::modality_degree`] fused-pair build for
/// a single-component projection).
#[must_use]
fn env_prefix_kinds_modally_tied(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().is_modally_tied()
}
/// `true` exactly when this chain's observed [`EnvMetadataTagKind`]
/// histogram has two or more cells tied at the trough leaf count —
/// the rarest env-prefix kind is *shared* rather than uniquely
/// held.
///
/// The **antimodally-tied-env-prefix-kinds boolean predicate** on
/// the env-prefix sub-axis of the chain altitude, the direct strict-
/// complement of [`crate::AxisHistogram::is_strictly_antimodally_unique`]
/// on every non-empty env-prefix histogram (both read `false` on the
/// empty histogram — the shared boundary below both branches of the
/// strict antimodal partition). Routes through
/// [`Self::env_prefix_kind_histogram`]`::is_antimodally_tied`, the
/// single-pass scan over the fixed-cardinality counts vector reading
/// `trough_multiplicity() >= 2` off one predicate — strictly tighter
/// than either of the documented open-coded surface forms one seam
/// over.
///
/// The **antimodally-tied-env-prefix-kinds peer** of the two
/// documented surface forms consumers previously re-derived inline:
/// `chain.env_prefix_kind_histogram().trough_multiplicity() >= 2`
/// (the defining multiplicity-scalar inequality form — one method
/// call plus a magic `>= 2` threshold at the consumer site), and
/// `chain.env_prefix_kind_histogram().modality_degree().1 >= 2` (the
/// modality-pair projection-inequality form, reading the antimodal
/// component of the fused [`crate::AxisHistogram::modality_degree`]
/// pair before the comparison — a fused-pair build for a single-
/// component projection). This lift names the antimodally-tied-env-
/// prefix-kinds predicate directly at the chain-altitude surface —
/// the typed boolean every operator-facing *"is the rarest env-
/// prefix kind uniquely held on this chain, or is the declaration-
/// order tie-break exercised?"* check reads off as a single method
/// call.
///
/// **Closes the "antimodally-tied across altitudes" projection** at
/// the fifth and final altitude / sub-axis: seeded on the diff
/// altitude by [`crate::ConfigDiff::kinds_antimodally_tied`],
/// climbed to the tier altitude by
/// [`crate::ProvenanceMap::tiers_antimodally_tied`], lifted sideways
/// to the chain layer-kind sub-axis by
/// [`Self::layer_kinds_antimodally_tied`], and lifted sideways to
/// the chain file-format sub-axis by
/// [`Self::file_formats_antimodally_tied`]. Antimodal-tie-side row
/// on top of the closed coverage-support predicate cube
/// (`low_support`, `high_support`, `strict_partial_cover`,
/// `singular`, `boundary`, `partial_cover`) and complementary to
/// the modal-tie-side row [`Self::env_prefix_kinds_modally_tied`]
/// at the same env-prefix sub-axis — the eighth projection to close
/// at every altitude / sub-axis in lockstep, matching the shape of
/// the seven sibling projections on the same grid. With this lift
/// the "antimodally-tied across altitudes" projection carries the
/// same one-predicate row at every altitude / sub-axis of the fully-
/// closed cube, and the modality-tie boolean pair
/// `(is_modally_tied, is_antimodally_tied)` now carries both rows
/// at every altitude / sub-axis of the 5-column grid — closing the
/// half of the four-primitive multiplicity boolean algebra
/// `(is_strictly_modally_unique, is_modally_tied,
/// is_strictly_antimodally_unique, is_antimodally_tied)` covered by
/// the two tie predicates.
///
/// **Cardinality-`2` reachability at the chain env-prefix sub-axis
/// — degenerate strict antimodal partition, antimodally-tied
/// collapses onto the uniform-cover boundary corner.**
/// [`EnvMetadataTagKind`] carries two cells so
/// `env_prefix_kinds_antimodally_tied()` reads `true` exactly when
/// both cells share the trough leaf count (the uniform two-kind
/// cover, e.g. one prefixed + one bare tied at count `1`, or two
/// prefixed + two bare tied at count `2`), and `false` on the empty
/// chain (no observed cell), on every no-env-layers non-empty chain
/// (empty env-prefix histogram via the partial-function projection),
/// on every singleton-support chain (support cardinality `1`,
/// trough multiplicity `1` — the lone observed cell stands alone at
/// its own trough), and on every strictly-antimodal skewed chain
/// (e.g. two prefixed + one bare where `Bare` uniquely holds the
/// trough at count `1` while `Prefixed` peaks at `2`). On the
/// cardinality-`2` axis the antimodally-tied corner reduces to
/// *exactly* the uniform-cover boundary corner
/// (`env_prefix_kinds_antimodally_tied ⇔
/// env_prefix_kinds_full_cover ∧ env_prefix_kinds_balanced` on this
/// axis — the trough-multiplicity walk reaches `2` iff both cells
/// are observed at the same count, which on cardinality-`2` is
/// precisely the uniform-cover corner). The *tightest* degenerate
/// antimodally-tied leg in the projection: the layer-kind sub-axis
/// and the diff altitude carry the strict-interior tied witness at
/// their cardinality-`3` axes, and the tier altitude and file-
/// format sub-axis carry the additional support-`3` tied witness at
/// their cardinality-`4` axes — both classes unreachable at the
/// cardinality-`2` env-prefix sub-axis.
///
/// **Empty-chain convention** — returns `false` on the empty chain:
/// the empty chain observes zero cells, so
/// [`crate::AxisHistogram::trough_multiplicity`] reads `0` and the
/// inequality `0 >= 2` fails. Matches
/// [`crate::AxisHistogram::is_antimodally_tied`]'s empty-histogram
/// convention one altitude down. The empty-chain row on the strict
/// antimodal partition pair
/// `(is_strictly_antimodally_unique, is_antimodally_tied)` reads
/// `(false, false)` — the shared boundary below both branches. Peer
/// of [`Self::file_formats_antimodally_tied`]'s empty-chain `false`
/// polarity and [`Self::layer_kinds_antimodally_tied`]'s empty-
/// chain `false` polarity one sub-axis over on the same chain
/// altitude, of [`crate::ProvenanceMap::tiers_antimodally_tied`]'s
/// empty-map `false` polarity, and of
/// [`crate::ConfigDiff::kinds_antimodally_tied`]'s empty-diff
/// `false` polarity — closing the empty-witness row of the
/// projection at the fifth and final altitude / sub-axis.
///
/// **No-env-layers convention** — returns `false` on every non-
/// empty chain whose env-prefix histogram is empty (only `Defaults`
/// and `File` layers). The env-prefix projection is a partial
/// function ([`ConfigSource::env_prefix_kind`] returns [`None`] for
/// both `Defaults` and `File`), so a non-empty chain can still
/// project to an empty histogram — `trough_multiplicity` reads `0`
/// and the inequality `0 >= 2` fails. This is the antimodal-tie-
/// side cross-sub-axis divergence pin against
/// [`Self::layer_kinds_antimodally_tied`]: on the same fixtures the
/// layer-kind sub-axis observes at least one layer-kind cell
/// (Defaults / File) and may fire the antimodally-tied predicate
/// (e.g. one `Defaults` + one `File` reads
/// `layer_kinds_antimodally_tied = true`), while the env-prefix
/// sub-axis's antimodally-tied predicate silently drops out via the
/// empty-histogram disjunct — the antimodal-tie leg's meaning is
/// *narrower* at the env-prefix sub-axis than at the layer-kind
/// sub-axis, matching the same narrowing pinned at the modal-tie
/// row [`Self::env_prefix_kinds_modally_tied`] and at the file-
/// format sister sub-axis [`Self::file_formats_antimodally_tied`].
///
/// **Singleton-support convention** — returns `false` on every
/// chain whose observed env-prefix support is a single
/// [`EnvMetadataTagKind`] cell (prefixed-only or bare-only): the
/// lone observed cell stands alone at its own trough (peak and
/// trough coincide, no tie-break to exercise), so
/// `trough_multiplicity` reads `1` and the inequality `1 >= 2`
/// fails. The `sample_chain()` fixture (two `.yaml` file layers +
/// one `"APP_"` Env layer, `{Prefixed}` env-prefix support with
/// count `1`) is a witness on the `false` side — the singleton-
/// support corner is uniformly on the strictly-antimodal-unique
/// side of the strict antimodal partition. Direct pin of the
/// histogram-side subsumption `has_singular_support ⇒
/// !is_antimodally_tied` one altitude down.
///
/// **Uniform two-kind cover convention** — returns `true` on every
/// chain where each [`EnvMetadataTagKind`] cell was observed at
/// exactly the same positive count (the *only* antimodally-tied
/// witness class on the cardinality-`2` env-prefix axis): the two
/// cells share the same count, so `trough_multiplicity` reads `2`
/// and the inequality `2 >= 2` fires. Peer of the histogram-side
/// axis-cover convention one altitude down, which reads `true` on
/// every implementor with `axis_cardinality::<A>() >= 2` — the
/// cardinality-`2` [`EnvMetadataTagKind`] axis honours the general
/// condition. Also the *tightest* antimodally-tied surface: on
/// cardinality-`2` axes the antimodally-tied predicate reads `true`
/// iff *both* cells are observed at the same count, i.e. exactly
/// the [`Self::env_prefix_kinds_full_cover`] ∧
/// [`Self::env_prefix_kinds_balanced`] corner.
///
/// **Two-way antimodal partition on non-empty env-prefix
/// histograms** — on every non-empty env-prefix histogram exactly
/// one of the antimodal-uniqueness pair fires: either the trough is
/// uniquely held (strictly-antimodal-unique fires, antimodally-tied
/// does not) or the trough is shared (antimodally-tied fires,
/// strictly-antimodal-unique does not). The empty histogram sits
/// below both branches (both read `false`) — this covers both the
/// empty chain and every no-env-layers non-empty chain. Direct pin
/// of the histogram-side strict antimodal partition
/// `!is_empty ⇒ is_antimodally_tied ⇔
/// !is_strictly_antimodally_unique` one altitude down.
///
/// **Modal / antimodal collapse on uniform-count non-empty env-
/// prefix histograms** — on every uniform-count non-empty env-
/// prefix histogram the modal and antimodal level sets coincide
/// with the support, so `env_prefix_kinds_antimodally_tied ⇔
/// env_prefix_kinds_modally_tied` — the classifier pair collapses
/// to a single boolean, the multi-cell-support witness. Direct pin
/// of the histogram-side collapse law
/// `is_uniform_count ∧ !is_empty ⇒ is_antimodally_tied ⇔
/// is_modally_tied` one altitude down, peer of the same collapse
/// pinned at the diff altitude by
/// [`crate::ConfigDiff::kinds_antimodally_tied`], at the tier
/// altitude by [`crate::ProvenanceMap::tiers_antimodally_tied`], at
/// the chain layer-kind sub-axis by
/// [`Self::layer_kinds_antimodally_tied`], and at the chain file-
/// format sub-axis by [`Self::file_formats_antimodally_tied`].
///
/// **Full modal / antimodal collapse on the cardinality-`2` env-
/// prefix axis** — on this axis `env_prefix_kinds_antimodally_tied
/// ⇔ env_prefix_kinds_modally_tied` on *every* histogram (empty,
/// singleton-support, uniform, and strictly-skewed), a strict
/// tightening of the general uniform-count-non-empty collapse law
/// documented above. Direct consequence of the two-cell degeneracy:
/// with only two cells the peak level set and the trough level set
/// coincide pointwise — either both cells share the same count
/// (uniform two-kind cover, both `peak_multiplicity` and
/// `trough_multiplicity` read `2`, both tie predicates fire) or
/// they carry distinct counts (peak and trough are the two distinct
/// counts, both multiplicities read `1`, neither tie predicate
/// fires) or only one cell is observed (peak and trough coincide at
/// the observed count, multiplicity `1`, neither fires) or neither
/// cell is observed (empty histogram, both read `false`). Does NOT
/// lift to the cardinality-`>= 3` sub-axes
/// ([`Self::layer_kinds_antimodally_tied`] over cardinality-`3`,
/// [`Self::file_formats_antimodally_tied`] over cardinality-`4`)
/// where the strict-interior corners
/// `(modally_tied = true, antimodally_tied = false)` and
/// `(modally_tied = false, antimodally_tied = true)` carry
/// witnesses non-vacuously, nor to the tier altitude
/// ([`crate::ProvenanceMap::tiers_antimodally_tied`] over
/// cardinality-`4`) or the diff altitude
/// ([`crate::ConfigDiff::kinds_antimodally_tied`] over cardinality-
/// `3`) where the same divergence carries witnesses.
///
/// # Invariants
///
/// - `env_prefix_kinds_antimodally_tied() == env_prefix_kind_histogram().is_antimodally_tied()`
/// — both project the same predicate off the same primitive; the
/// named seam is the cube-native routing of the histogram
/// surface.
/// - `env_prefix_kinds_antimodally_tied() ⇔
/// env_prefix_kind_histogram().trough_multiplicity() >= 2` — the
/// defining multiplicity-scalar inequality form on the
/// [`crate::AxisHistogram::trough_multiplicity`] scalar peer, the
/// canonical open-coded expression of the predicate one altitude
/// down.
/// - `env_prefix_kinds_antimodally_tied() ⇔
/// env_prefix_kind_histogram().modality_degree().1 >= 2` — the
/// modality-pair projection-inequality form, reading the
/// antimodal component of the fused
/// [`crate::AxisHistogram::modality_degree`] pair before the
/// comparison.
/// - `env_prefix_kinds_antimodally_tied() ⇒
/// env_prefix_kinds_any_observed()` always — a tied trough
/// requires at least two observed cells, so both the empty chain
/// (zero observed cells) and every no-env-layers non-empty chain
/// (empty env-prefix histogram via the partial-function
/// projection) cannot fire.
/// Contrapositively, `!env_prefix_kinds_any_observed() ⇒
/// !env_prefix_kinds_antimodally_tied()`.
/// - `env_prefix_kinds_singular_support() ⇒
/// !env_prefix_kinds_antimodally_tied()` always — a singleton-
/// support chain has exactly one observed cell, so the antimodal
/// level set has cardinality `1` and the tie predicate fails.
/// Contrapositively, `env_prefix_kinds_antimodally_tied() ⇒
/// !env_prefix_kinds_singular_support()`: a fired tie predicate
/// means at least two observed cells. Direct pin of the
/// histogram-side subsumption `has_singular_support ⇒
/// !is_antimodally_tied` one altitude down.
/// - `env_prefix_kinds_full_cover() ∧ env_prefix_kinds_balanced() ⇒
/// env_prefix_kinds_antimodally_tied()` on the cardinality-`>= 2`
/// axis: a full-cover uniform-count chain has every cell observed
/// at the same count, so the antimodal level set equals the full
/// axis — the trough multiplicity rises to
/// `axis_cardinality::<EnvMetadataTagKind>()` which is `2`, and
/// the tie predicate fires. Cardinality-`>= 2` witness of the
/// uniform-cover corner of the histogram-side subsumption tying
/// [`crate::AxisHistogram::is_uniform_count`] and
/// [`crate::AxisHistogram::has_singular_support`] on non-empty
/// histograms one altitude down.
/// - `env_prefix_kinds_antimodally_tied() ⇔
/// env_prefix_kinds_full_cover() ∧ env_prefix_kinds_balanced()`
/// pointwise on the cardinality-`2` env-prefix axis — the
/// *unique* two-cell-axis tightening of the general uniform-
/// cover subsumption above into an equivalence, via the collapse
/// of the antimodally-tied corner onto the uniform-cover boundary
/// corner. On this axis the strict-interior tied witnesses
/// available at the cardinality-`>= 3` sister sub-axes are
/// structurally unreachable — the *only* antimodally-tied
/// witness class is the uniform-cover corner itself. Peer of the
/// same two-cell-axis equivalence pinned at the modal-tie row
/// [`Self::env_prefix_kinds_modally_tied`].
/// - **Strict antimodal partition on non-empty env-prefix
/// histograms** — `!env_prefix_kind_histogram().is_empty() ⇒
/// (env_prefix_kinds_antimodally_tied ⇔
/// !env_prefix_kind_histogram().is_strictly_antimodally_unique())`
/// always. On every non-empty env-prefix histogram exactly one of
/// `(env_prefix_kinds_antimodally_tied,
/// env_prefix_kind_histogram().is_strictly_antimodally_unique())`
/// fires; both read `false` on the empty histogram — the shared
/// boundary below both branches. Direct pin of the histogram-side
/// strict antimodal partition one altitude down.
/// - **Modal / antimodal collapse on uniform-count non-empty env-
/// prefix histograms** — `env_prefix_kinds_balanced() ∧
/// env_prefix_kinds_any_observed() ⇒
/// (env_prefix_kinds_antimodally_tied ⇔
/// env_prefix_kinds_modally_tied)`. On every uniform-count non-
/// empty env-prefix histogram the two tie predicates collapse to
/// the same value. Direct pin of the histogram-side collapse
/// `is_uniform_count ∧ !is_empty ⇒ is_antimodally_tied ⇔
/// is_modally_tied` one altitude down, peer of the same collapse
/// pinned at the diff altitude by
/// [`crate::ConfigDiff::kinds_antimodally_tied`], at the tier
/// altitude by [`crate::ProvenanceMap::tiers_antimodally_tied`],
/// at the chain layer-kind sub-axis by
/// [`Self::layer_kinds_antimodally_tied`], and at the chain
/// file-format sub-axis by
/// [`Self::file_formats_antimodally_tied`].
/// - **Full modal / antimodal collapse on the cardinality-`2` env-
/// prefix axis** — `env_prefix_kinds_antimodally_tied ⇔
/// env_prefix_kinds_modally_tied` pointwise on the cardinality-
/// `2` env-prefix axis, on *every* histogram regardless of shape
/// (empty, singleton-support, uniform, strictly-skewed). Strict
/// tightening of the uniform-count-non-empty collapse law above
/// into an unconditional equivalence — a direct consequence of
/// the two-cell degeneracy where the peak level set and the
/// trough level set coincide pointwise. Does NOT lift to the
/// cardinality-`>= 3` sister sub-axes / altitudes where the two
/// strict-interior corners
/// `(modally_tied, antimodally_tied) ∈ {(true, false),
/// (false, true)}` carry witnesses non-vacuously.
///
/// # Cost
///
/// `O(n + k)` where `n = self.as_ref().len()` (the histogram
/// build) and `k = crate::axis_cardinality::<crate::EnvMetadataTagKind>()`
/// (the trough-multiplicity scan). Both are `O(n)` in practice
/// since the env-prefix axis carries a fixed two-cell cardinality;
/// the returned `bool` reads one predicate — the trough scan walks
/// the counts vector once and counts cells matching the strictly-
/// positive minimum, then reads `multiplicity >= 2` off one
/// comparison. Strictly tighter than the two documented open-coded
/// surfaces one seam over (no exposed `>= 2` magic threshold at
/// the consumer site, no [`crate::AxisHistogram::modality_degree`]
/// fused-pair build for a single-component projection).
#[must_use]
fn env_prefix_kinds_antimodally_tied(&self) -> bool
where
Self: AsRef<[ConfigSource]>,
{
self.env_prefix_kind_histogram().is_antimodally_tied()
}
}
impl ConfigSourceChain for [ConfigSource] {
fn find_file(&self, path: &Path) -> Option<&ConfigSource> {
self.iter().find(|s| s.as_path() == Some(path))
}
fn unique_of_kind(&self, kind: ConfigSourceKind) -> Option<&ConfigSource> {
let mut matches = self.iter().filter(|s| s.kind() == kind);
let first = matches.next()?;
matches.next().is_none().then_some(first)
}
fn find_env_by_prefix(&self, prefix: &str) -> Option<&ConfigSource> {
self.iter().find(|s| {
s.as_env_prefix()
.is_some_and(|p| p.eq_ignore_ascii_case(prefix))
})
}
}
/// Recognized form of [`figment::providers::Env`]'s
/// `figment::Metadata::name`, as parsed by
/// [`ConfigSource::strip_env_metadata_name`].
///
/// The closed enum makes the env-tag shape space structural: any
/// figment env metadata name maps to exactly one variant (or to `None`
/// if it isn't an env tag at all).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum EnvMetadataTag<'a> {
/// `` `PREFIX` environment variable(s) `` — figment emitted the
/// prefix uppercased; the borrowed slice carries it verbatim.
Prefixed(&'a str),
/// `environment variable(s)` — `figment::providers::Env::raw()`
/// shape (no prefix).
Bare,
}
impl EnvMetadataTag<'_> {
/// Data-free, `'static` discriminant of this [`EnvMetadataTag`]:
/// the kind of figment env-metadata shape
/// ([`EnvMetadataTagKind::Prefixed`] / [`EnvMetadataTagKind::Bare`])
/// independent of the inner borrowed prefix slice.
///
/// One source of truth for the env-metadata-tag kind partition.
/// Observers that need only the kind axis (filtering by prefix
/// presence, hashing in a `'static` map, recording the
/// prefixed/bare class of a failing env attribution in an
/// attestation manifest, comparing across thread boundaries) match
/// on this closed enum instead of pattern-matching against the
/// borrowed tag with a lifetime parameter.
///
/// Symmetric peer of [`FigmentSourceTag::kind`] and
/// [`FigmentNameTag::kind`] on the third figment-metadata sub-axis:
/// together the triple [`FigmentSourceKind`] /
/// [`FigmentNameTagKind`] / [`EnvMetadataTagKind`] closes the
/// figment-metadata kind universe (source axis × name axis ×
/// env-name sub-axis) under one typescape primitive set, every
/// borrowed tag projects to a `'static` discriminant on its axis.
///
/// A future [`EnvMetadataTag`] variant landing (e.g. a hypothetical
/// `Glob(&str)` shape if figment grows pattern-matched env
/// providers) forces a corresponding [`EnvMetadataTagKind`] arm
/// through the exhaustive match below.
#[must_use]
pub fn kind(self) -> EnvMetadataTagKind {
match self {
Self::Prefixed(_) => EnvMetadataTagKind::Prefixed,
Self::Bare => EnvMetadataTagKind::Bare,
}
}
}
/// Data-free, `'static` discriminant of [`EnvMetadataTag`]: the kind of
/// figment env-metadata shape independent of the inner borrowed prefix
/// slice.
///
/// Closed two-way partition over the [`EnvMetadataTag`] variant space,
/// returned by [`EnvMetadataTag::kind`]. The enum exists so consumers
/// that need only the kind axis (filtering by prefix presence, hashing
/// in a `'static` map, recording the prefixed/bare class of a failing
/// env attribution in an attestation manifest, comparing across thread
/// boundaries) match on one closed enum instead of pattern-matching
/// against the borrowed tag with a lifetime parameter.
///
/// Symmetric peer of [`FigmentSourceKind`] on the figment-Source axis
/// and [`FigmentNameTagKind`] on the figment-Name axis: same typescape
/// discipline (closed, allocation-free,
/// `Copy + Eq + Hash + #[non_exhaustive]`, exhaustive forward map),
/// applied to figment's env-metadata sub-axis. Before this lift, the
/// figment-metadata kind universe carried typed `'static` kinds on the
/// outer `Metadata::source` and `Metadata::name` axes but the inner
/// env-name sub-axis (the [`FigmentNameTag::Env`] variant's borrowed
/// payload) had only the borrowed tag with no `'static` discriminant;
/// observers needing the cross-thread, cross-axis prefixed/bare
/// classification had to either retain the borrowed tag (lifetime
/// contamination) or re-derive the partition through inlined
/// `matches!(tag, EnvMetadataTag::Prefixed(_))` predicates at every
/// observation site.
///
/// `'static` and allocation-free — no lifetime parameter, unlike
/// [`EnvMetadataTag`]. The kind survives any borrow on the originating
/// `figment::Metadata::name` and can therefore cross thread boundaries,
/// serialize, and live in long-lived structures (the way
/// [`ConfigSourceKind`] does on the captured cross-thread observable
/// form of [`crate::ReloadFailure`], and [`FigmentSourceKind`] /
/// [`FigmentNameTagKind`] do on the outer figment-metadata axes).
///
/// Adding a future [`EnvMetadataTag`] variant (e.g. a hypothetical
/// `Glob(&str)` shape if figment grows pattern-matched env providers)
/// means adding one [`EnvMetadataTagKind`] variant in lockstep — the
/// exhaustive [`EnvMetadataTag::kind`] match forces the assignment at
/// compile time.
/// `Ord` / `PartialOrd` are declaration-order lex over
/// [`Self::ALL`] (`Prefixed < Bare`): a `BTreeMap<EnvMetadataTagKind, T>`
/// keyed on the env-name sub-axis kind (per-kind attribution
/// histograms, per-kind failure-rate dashboards, attestation manifests
/// recording the env-name sub-axis kind cardinality mix of a recorded
/// chain) emits rows in that order deterministically without a
/// hand-rolled comparator at the renderer. Idiom-peer of the same
/// derive on [`FigmentSourceKind`] (commit `5df265c`) and
/// [`FigmentNameTagKind`] (commit `64a47e7`) lifted onto the env-name
/// sub-axis sibling closed-enum.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[non_exhaustive]
pub enum EnvMetadataTagKind {
/// Maps to [`EnvMetadataTag::Prefixed`] regardless of inner
/// borrowed prefix slice. Reached from a
/// `figment::Metadata::name` of shape
/// `` `PREFIX` environment variable(s) `` emitted by
/// [`figment::providers::Env::prefixed`].
Prefixed,
/// Maps to [`EnvMetadataTag::Bare`]. Reached from a
/// `figment::Metadata::name` of shape `"environment variable(s)"`
/// emitted by [`figment::providers::Env::raw`].
Bare,
}
impl EnvMetadataTagKind {
/// Every [`EnvMetadataTagKind`] variant, in declaration order
/// ([`Self::Prefixed`], [`Self::Bare`]).
///
/// The closed list of env-metadata-tag shape classes shikumi
/// recognizes. Iterate to enumerate the env-name sub-axis kind
/// space without listing variants by hand at every consumer site —
/// dashboards initializing per-kind counters (weighting `Bare`
/// attributions visibly more weakly than `Prefixed` ones since the
/// bare shape carries no scoping information), attestation
/// manifests recording the env-name sub-axis kind histogram of
/// failing attributions, structured-diagnostics legends rendering
/// different prose per class, or partition-coverage tests asserting
/// disjointness across the classification.
///
/// One source of truth for the kind enumeration on the
/// [`EnvMetadataTagKind`] axis: peer to [`FigmentSourceKind::ALL`]
/// on the figment-Source axis, [`FigmentNameTagKind::ALL`] on the
/// figment-Name axis, and the other closed-axis primitives' `ALL`
/// constants — the same typescape discipline (closed `'static`
/// slice, in declaration order) applied to figment's env-name
/// sub-axis.
///
/// Adding a new variant to [`Self`] (e.g. a future `Glob` kind in
/// lockstep with a hypothetical `EnvMetadataTag::Glob` if figment
/// grows pattern-matched env providers) means extending this slice
/// in lockstep with the variant itself. The compiler enforces
/// nothing here directly, so the
/// `env_metadata_tag_kind_all_covers_every_constructible_tag` test
/// pins the contract by asserting that every kind produced by
/// [`EnvMetadataTag::kind`] over the canonical sample table
/// appears in [`Self::ALL`], and the
/// `env_metadata_tag_kind_all_has_no_duplicates` test pins that the
/// constant is a set (no double-listed variant).
pub const ALL: &'static [Self] = &[Self::Prefixed, Self::Bare];
/// Returns `true` for [`Self::Prefixed`]; equivalent to
/// `self == EnvMetadataTagKind::Prefixed`. Convenience predicate
/// matching the [`FigmentNameTagKind::is_format`] /
/// [`FigmentNameTagKind::is_env`] sibling pattern on the
/// figment-Name axis.
#[must_use]
pub fn is_prefixed(self) -> bool {
matches!(self, Self::Prefixed)
}
/// Returns `true` for [`Self::Bare`].
#[must_use]
pub fn is_bare(self) -> bool {
matches!(self, Self::Bare)
}
/// Canonical operator-facing lowercase name of the env-metadata
/// kind — `"prefixed"` for [`Self::Prefixed`], `"bare"` for
/// [`Self::Bare`].
///
/// The single source of truth for the env-name sub-axis kind label
/// strings on the [`EnvMetadataTagKind`] axis. Inherent mirror of
/// the [`crate::ClosedAxisLabel`] trait method; the trait impl
/// delegates here so the canonical names live at one site instead
/// of being re-stated at every operator-facing surface (a future
/// structured-log field naming the env-tag kind of a failing
/// attribution, a CLI flag filtering env attributions by
/// prefixed/bare class, an attestation manifest recording the
/// env-name sub-axis kind histogram of loaded values). The
/// strings match the variant identifiers in ASCII-lowercase form.
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Prefixed => "prefixed",
Self::Bare => "bare",
}
}
}
impl crate::ClosedAxis for EnvMetadataTagKind {
const ALL: &'static [Self] = Self::ALL;
}
impl crate::ClosedAxisLabel for EnvMetadataTagKind {
fn as_str(self) -> &'static str {
Self::as_str(self)
}
}
// The canonical (Display, FromStr, Serialize, Deserialize) string-surface
// quartet on the env-name sub-axis kind closed-enum, lifted to one macro
// after the seven hand-rolled idiom-peers preceding this commit
// (WatchEventClass at `94f8a8b`, ShikumiErrorKind at `4b53792`,
// DiffLineKind at `74ee853`, ConfigSourceKind at `ae24a13`,
// FormatProvenance at `212d6fb`, FigmentNameTagKind at `25bab65`,
// FigmentSourceKind at `8a0277d`). See
// `closed_axis_label_string_surface!` in `crate::macros` for the
// contract; behavior is byte-identical to the hand-rolled impls the
// macro replaces — the verbatim-label `Parse` error body, the
// case-insensitive `from_canonical_str` lowering, the `collect_str`-based
// serde emission, and the visitor's `expecting` message all match the
// prior surface pointwise. Pinned by
// `tests::env_metadata_tag_kind_display_matches_as_str`,
// `tests::env_metadata_tag_kind_from_str_*`, and
// `tests::env_metadata_tag_kind_serde_yaml_*`.
closed_axis_label_string_surface! {
type = EnvMetadataTagKind,
parse_error = "unknown env metadata tag kind",
expecting = "a canonical EnvMetadataTagKind lowercase label \
(`prefixed`, `bare`; case-insensitive)",
}
/// Closed-enum classification of `figment::Metadata::name`.
///
/// figment attaches per-value attribution along two axes: the
/// `figment::Source` axis (parsed by [`FigmentSourceTag::classify`])
/// and the `figment::Metadata::name` axis (parsed here). Three name
/// shapes are recognized today, partitioned across two variants:
///
/// - `"<format>: <path>"` from a shikumi-built provider (recognized
/// via [`crate::Format::parse_metadata_tag`]) →
/// [`Self::Format`].
/// - `` `PREFIX` environment variable(s) `` from
/// [`figment::providers::Env::prefixed`] (recognized via
/// [`ConfigSource::strip_env_metadata_name`] returning
/// [`EnvMetadataTag::Prefixed`]) → [`Self::Env`].
/// - `"environment variable(s)"` from
/// [`figment::providers::Env::raw`] (recognized via the same parser
/// returning [`EnvMetadataTag::Bare`]) → [`Self::Env`].
///
/// The two sub-parsers' recognized inputs are disjoint (pinned by
/// `strip_env_metadata_name_disjoint_from_format_strip` in this
/// module), so every `figment::Metadata::name` maps to exactly one
/// variant or to `None`.
///
/// Structural mirror of [`FigmentSourceTag`] on the name axis: the
/// pair `(FigmentSourceTag, FigmentNameTag)` closes the
/// figment-metadata coordinate space the failing-source resolver
/// dispatches over. Together with [`FormatMetadataTag`] (the
/// `"<format>: <path>"` envelope on the shikumi-provider sub-axis),
/// [`EnvMetadataTag`] (the env-name sub-axis), and
/// [`crate::AttributionRule`] (the
/// `(source × name × chain) → rule` dispatch), the four typed shapes
/// together close figment's metadata attribution surface.
///
/// `Copy` and allocation-free: both inner variants borrow into the
/// input metadata-name `&str`. `#[non_exhaustive]` so a future
/// figment provider attaching a third name-axis shape (e.g. a
/// hypothetical `"http://… config endpoint"` tag) lands as one new
/// variant without breaking exhaustivity at consumer matches.
///
/// [`FormatMetadataTag`]: crate::FormatMetadataTag
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum FigmentNameTag<'a> {
/// `"<format>: <path>"` shape — a shikumi-built provider's
/// `figment::Metadata::name`. Carries the parsed
/// [`crate::FormatMetadataTag`] envelope (format + borrowed path).
Format(crate::discovery::FormatMetadataTag<'a>),
/// `` `PREFIX` environment variable(s) `` or
/// `"environment variable(s)"` — figment's `Env` provider's
/// `figment::Metadata::name`. Carries the
/// prefixed/bare distinction in [`EnvMetadataTag`].
Env(EnvMetadataTag<'a>),
}
impl<'a> FigmentNameTag<'a> {
/// Classify a `figment::Metadata::name` into its typed shape.
///
/// Tries the shikumi-provider format-prefix shape first via
/// [`crate::Format::parse_metadata_tag`]; on no match, tries the
/// figment-Env shape via
/// [`ConfigSource::strip_env_metadata_name`]; returns `None` for
/// any other shape (file paths from figment's YAML/TOML providers,
/// unrelated names, the empty string).
///
/// The two sub-parsers are disjoint (pinned by
/// `strip_env_metadata_name_disjoint_from_format_strip`), so
/// iteration order does not affect correctness; the order matches
/// the failing-source resolver's preference.
///
/// One source of truth for the figment-name-axis dispatch on
/// [`figment::Metadata`]: callers ([`crate::ShikumiError::failing_source`]
/// and any future per-value attribution consumer) match on this
/// enum instead of calling
/// [`crate::Format::parse_metadata_tag`] and
/// [`ConfigSource::strip_env_metadata_name`] in sequence. If a
/// new figment-recognized name shape lands, exactly one site here
/// changes (a new variant + a new branch in `classify`) and the
/// resolver's match becomes non-exhaustive at compile time —
/// catching unhandled cases before they reach users.
#[must_use]
pub fn classify(name: &'a str) -> Option<Self> {
if let Some(tag) = crate::discovery::Format::parse_metadata_tag(name) {
return Some(Self::Format(tag));
}
if let Some(tag) = ConfigSource::strip_env_metadata_name(name) {
return Some(Self::Env(tag));
}
None
}
/// Returns the inner [`crate::FormatMetadataTag`] if this is the
/// [`Self::Format`] variant.
#[must_use]
pub fn as_format(self) -> Option<crate::discovery::FormatMetadataTag<'a>> {
match self {
Self::Format(tag) => Some(tag),
Self::Env(_) => None,
}
}
/// Returns the inner [`EnvMetadataTag`] if this is the
/// [`Self::Env`] variant.
#[must_use]
pub fn as_env(self) -> Option<EnvMetadataTag<'a>> {
match self {
Self::Env(tag) => Some(tag),
Self::Format(_) => None,
}
}
/// Data-free, `'static` discriminant of this [`FigmentNameTag`]:
/// the kind of `figment::Metadata::name` shape
/// ([`FigmentNameTagKind::Format`] / [`FigmentNameTagKind::Env`])
/// independent of the inner borrowed [`crate::FormatMetadataTag`]
/// envelope or [`EnvMetadataTag`] prefix.
///
/// One source of truth for the figment-name-axis kind partition.
/// Observers that need only the kind axis (filtering by name-tag
/// class, hashing in a `'static` map, recording per-failure
/// name-class in an attestation manifest, comparing across thread
/// boundaries) match on this closed enum instead of pattern-matching
/// against [`FigmentNameTag`] with a borrowed lifetime, or chaining
/// [`Self::as_format`] / [`Self::as_env`] together. The kind is
/// `'static`, so it can cross threads, serialize, and persist
/// across observation boundaries the borrowed tag cannot.
///
/// Symmetric peer of [`FigmentSourceTag::kind`] on the figment-Source
/// axis: same typescape discipline (closed, allocation-free,
/// `Copy + Eq + Hash + #[non_exhaustive]`, exhaustive forward map),
/// applied to figment's `Metadata::name` axis. The pair
/// ([`FigmentSourceKind`] on the source axis, [`FigmentNameTagKind`]
/// on the name axis) closes the figment-metadata kind universe under
/// one typescape primitive set: every `figment::Metadata` field's
/// borrowed tag projects to a `'static` discriminant on its axis.
///
/// Pairs with [`Self::attribution_axis`]: the projection is constant
/// ([`crate::AttributionAxis::MetadataName`] for every variant) since
/// [`FigmentNameTag`] *is* the typed reading of
/// `figment::Metadata::name`. That structural law mirrors the
/// `attribution_axis` constant on [`FigmentSourceTag`] (always
/// [`crate::AttributionAxis::MetadataSource`]).
/// A future variant landing on [`FigmentNameTag`] (e.g. a
/// hypothetical `"http://… config endpoint"` name shape) forces a
/// [`FigmentNameTagKind`] arm in lockstep at compile time, and the
/// constant axis projection extends without per-site updates.
#[must_use]
pub fn kind(self) -> FigmentNameTagKind {
match self {
Self::Format(_) => FigmentNameTagKind::Format,
Self::Env(_) => FigmentNameTagKind::Env,
}
}
/// [`crate::AttributionAxis`] of this tag — constant
/// [`crate::AttributionAxis::MetadataName`] for every variant, since
/// [`FigmentNameTag`] *is* the typed reading of
/// `figment::Metadata::name`.
///
/// One source of truth for the structural law that every
/// figment-name-axis attribution dispatches off `metadata.name`,
/// regardless of which variant fires. Mirrors
/// [`FigmentSourceTag::attribution_axis`] (constant
/// [`crate::AttributionAxis::MetadataSource`]) on the source axis:
/// each typed reading of a `figment::Metadata` field maps to its
/// originating axis as a constant. The pair
/// (name-side: [`Self::attribution_axis`], source-side:
/// [`FigmentSourceTag::attribution_axis`], resolver-side:
/// [`crate::AttributionRule::metadata_axis`]) cross-checks the axis
/// across the three surfaces; consumers see the same axis label
/// without re-deriving the (typed-source × name-string) partition.
#[must_use]
pub fn attribution_axis(self) -> crate::AttributionAxis {
let _ = self.kind();
crate::AttributionAxis::MetadataName
}
}
/// Data-free, `'static` discriminant of [`FigmentNameTag`]: the kind of
/// `figment::Metadata::name` shape independent of the inner borrowed
/// [`crate::FormatMetadataTag`] envelope or [`EnvMetadataTag`] prefix.
///
/// Closed two-way partition over the [`FigmentNameTag`] variant space,
/// returned by [`FigmentNameTag::kind`]. The enum exists so consumers
/// that need only the kind axis (filtering by name-tag class, hashing
/// in a `'static` map, recording per-failure name-class in an
/// attestation manifest, comparing across thread boundaries) match on
/// one closed enum instead of pattern-matching against the borrowed
/// tag or chaining [`FigmentNameTag::as_format`] /
/// [`FigmentNameTag::as_env`] together.
///
/// Symmetric peer of [`FigmentSourceKind`] on the figment-Source axis:
/// same typescape discipline (closed, allocation-free,
/// `Copy + Eq + Hash + #[non_exhaustive]`, exhaustive forward map),
/// applied to figment's `Metadata::name` axis. Before this lift, the
/// figment-metadata kind universe was asymmetric — the
/// `Metadata::source` axis had a typed `'static` kind ([`FigmentSourceKind`])
/// but the `Metadata::name` axis had only the borrowed tag
/// ([`FigmentNameTag`]) with no `'static` discriminant; observers
/// needing the cross-thread, cross-axis kind classification on the
/// name side had to either retain the borrowed tag (lifetime
/// contamination) or re-derive the partition through
/// [`FigmentNameTag::as_format`] / [`FigmentNameTag::as_env`]
/// inlined at every observation site.
///
/// `'static` and allocation-free — no lifetime parameter, unlike
/// [`FigmentNameTag`]. The kind survives any borrow on the originating
/// `figment::Metadata::name` and can therefore cross thread boundaries,
/// serialize, and live in long-lived structures (the way
/// [`ConfigSourceKind`] does on the captured cross-thread observable
/// form of [`crate::ReloadFailure`], and [`FigmentSourceKind`] does on
/// the figment-Source side).
///
/// Adding a future [`FigmentNameTag`] variant (e.g. a hypothetical
/// `"http://… config endpoint"` shape if figment's name-axis grows one)
/// means adding one [`FigmentNameTagKind`] variant in lockstep — the
/// exhaustive [`FigmentNameTag::kind`] match forces the assignment at
/// compile time.
///
/// `Ord` and `PartialOrd` are derived as declaration-order lex over
/// [`Self::ALL`] (`Format < Env`): a `BTreeMap<FigmentNameTagKind, T>`
/// keyed on the figment-Name-axis kind (per-kind attribution
/// histograms, per-kind failure-rate dashboards, attestation manifests
/// recording the figment-Name kind cardinality mix of a recorded
/// chain) emits rows in that order deterministically without a
/// hand-rolled comparator at the renderer. Idiom-peer of the same
/// derive on [`FigmentSourceKind`] (commit `5df265c`) lifted onto the
/// figment-Name-axis sibling closed-enum.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[non_exhaustive]
pub enum FigmentNameTagKind {
/// Maps to [`FigmentNameTag::Format`] regardless of inner
/// [`crate::FormatMetadataTag`] envelope. Reached from a
/// `figment::Metadata::name` of shape `"<format>: <path>"` emitted
/// by a shikumi-built provider ([`crate::LispProvider`],
/// [`crate::NixProvider`]).
Format,
/// Maps to [`FigmentNameTag::Env`] regardless of inner
/// [`EnvMetadataTag`] prefix. Reached from a
/// `figment::Metadata::name` of shape
/// `` `PREFIX` environment variable(s) `` or
/// `"environment variable(s)"` emitted by `figment::providers::Env`.
Env,
}
impl FigmentNameTagKind {
/// Every [`FigmentNameTagKind`] variant, in declaration order
/// ([`Self::Format`], [`Self::Env`]).
///
/// The closed list of `figment::Metadata::name` shape classes shikumi
/// recognizes. Iterate to enumerate the figment-name-axis kind space
/// without listing variants by hand at every consumer site — e.g.
/// dashboards initializing per-kind counters (weighting `Env`
/// attributions visibly differently from `Format` ones since they
/// originate from distinct provider classes), attestation manifests
/// recording the figment-name-axis kind space's cardinality,
/// structured-diagnostics legends rendering different prose per
/// class, or partition-coverage tests asserting disjointness across
/// the figment-side classification on the name axis.
///
/// One source of truth for the kind enumeration on the
/// [`FigmentNameTagKind`] axis: peer to [`FigmentSourceKind::ALL`]
/// on the figment-Source axis, [`ConfigSourceKind::ALL`] on the
/// shikumi-side layer-kind axis, [`crate::AttributionAxis::ALL`] on
/// the metadata axis, and the other closed-axis primitives' `ALL`
/// constants — the same typescape discipline (closed `'static` slice,
/// in declaration order) applied to figment's `Metadata::name` axis.
///
/// Adding a new variant to [`Self`] (e.g. a future `Url` kind in
/// lockstep with a hypothetical `FigmentNameTag::Url` if figment
/// grows one) means extending this slice in lockstep with the
/// variant itself. The compiler enforces nothing here directly,
/// so the `figment_name_tag_kind_all_covers_every_constructible_tag`
/// test pins the contract by asserting that every kind produced by
/// [`FigmentNameTag::kind`] over the canonical sample table appears
/// in [`Self::ALL`], and the `figment_name_tag_kind_all_has_no_duplicates`
/// test pins that the constant is a set (no double-listed variant).
pub const ALL: &'static [Self] = &[Self::Format, Self::Env];
/// Returns `true` for [`Self::Format`]; equivalent to
/// `self == FigmentNameTagKind::Format`. Convenience predicate
/// matching the [`FigmentSourceKind::is_file`] /
/// [`FigmentSourceKind::is_code`] / [`FigmentSourceKind::is_custom`]
/// sibling pattern on the figment-Source axis.
#[must_use]
pub fn is_format(self) -> bool {
matches!(self, Self::Format)
}
/// Returns `true` for [`Self::Env`].
#[must_use]
pub fn is_env(self) -> bool {
matches!(self, Self::Env)
}
/// Canonical operator-facing lowercase name of the figment-name
/// kind — `"format"` for [`Self::Format`], `"env"` for [`Self::Env`].
///
/// The single source of truth for the figment-name-axis kind label
/// strings on the [`FigmentNameTagKind`] axis. Inherent mirror of
/// the [`crate::ClosedAxisLabel`] trait method; the trait impl
/// delegates here so the canonical names live at one site instead
/// of being re-stated at every operator-facing surface (a future
/// structured-log field naming the figment-name-axis kind of a
/// failing attribution, a CLI flag filtering attributions by
/// figment-name-axis kind, an attestation manifest recording the
/// figment-name-axis kind histogram of loaded values). The
/// strings match the variant identifiers in ASCII-lowercase form.
///
/// The `"env"` label intentionally coincides with
/// [`ConfigSourceKind::Env`]'s label by typescape design: the two
/// axes meet at the shikumi-env-layer ↔ figment-Env-name
/// resolution boundary. The trait-uniform distinctness law
/// (`closed_axis_label_as_str_distinct_for_every_implementor`)
/// pins distinctness within an axis only; cross-axis label
/// coincidence is structural, not a discipline violation.
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Format => "format",
Self::Env => "env",
}
}
}
impl crate::ClosedAxis for FigmentNameTagKind {
const ALL: &'static [Self] = Self::ALL;
}
impl crate::ClosedAxisLabel for FigmentNameTagKind {
fn as_str(self) -> &'static str {
Self::as_str(self)
}
}
// The canonical (Display, FromStr, Serialize, Deserialize) string-surface
// quartet on the figment-Name-axis kind closed-enum, lifted to one macro
// after the 16+ hand-rolled idiom-peers preceding this commit
// (WatchEventClass at `94f8a8b`, ShikumiErrorKind at `4b53792`,
// DiffLineKind at `74ee853`, ConfigSourceKind at `ae24a13`,
// FormatProvenance at `212d6fb`). See `closed_axis_label_string_surface!`
// in `crate::macros` for the contract; behavior is byte-identical to the
// hand-rolled impls the macro replaces — the verbatim-label `Parse` error
// body, the case-insensitive `from_canonical_str` lowering, the
// `collect_str`-based serde emission, and the visitor's `expecting`
// message all match the prior surface pointwise. Pinned by
// `tests::figment_name_tag_kind_display_matches_as_str`,
// `tests::figment_name_tag_kind_from_str_*`, and
// `tests::figment_name_tag_kind_serde_yaml_*`.
closed_axis_label_string_surface! {
type = FigmentNameTagKind,
parse_error = "unknown figment name tag kind",
expecting = "a canonical FigmentNameTagKind lowercase label \
(`format`, `env`; case-insensitive)",
}
/// Borrowed classification of a [`figment::Source`].
///
/// figment's `Source` is `#[non_exhaustive]` and is queried via three
/// `Option`-returning accessors ([`figment::Source::file_path`],
/// [`figment::Source::code_location`], [`figment::Source::custom`]). This
/// enum lifts those open-coded probes into one typed dispatch: a single
/// [`Self::classify`] call takes `&figment::Source` and returns the one
/// recognized variant (or `None` if figment grew a fourth variant we
/// don't yet model).
///
/// The source axis of figment metadata is the structural mirror of the
/// name axis ([`crate::Format::strip_metadata_name`] /
/// [`ConfigSource::strip_env_metadata_name`]): every `figment::Metadata`
/// carries an optional `name: Cow<'static, str>` and an optional
/// `source: Option<Source>`. The three primitives partition the
/// recognized shapes across both axes; resolvers (e.g.
/// [`crate::ShikumiError::failing_source`]) dispatch on them without
/// re-implementing figment's Source-side query methods.
///
/// All variants borrow into either the input `Source` (`File`, `Custom`)
/// or into the `'static` panic location figment carries (`Code`), so the
/// enum is `Copy` and allocation-free.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum FigmentSourceTag<'a> {
/// `figment::Source::File(_)` — the borrowed file path. This is the
/// shape figment's built-in YAML/TOML providers attach to per-value
/// metadata; matched by [`ConfigSource::as_path`] equality in the
/// resolver.
File(&'a Path),
/// `figment::Source::Code(_)` — the source-code location attached by
/// [`figment::providers::Serialized`] (the shape behind
/// [`crate::ProviderChain::with_defaults`]). Carries figment's
/// `&'static Location<'static>` verbatim.
Code(&'static Location<'static>),
/// `figment::Source::Custom(_)` — the borrowed custom-source string.
/// Used by figment-ecosystem providers that can't fit the File/Code
/// shape (e.g. HTTP, Vault, in-memory dicts).
Custom(&'a str),
}
impl<'a> FigmentSourceTag<'a> {
/// Classify a [`figment::Source`] into its typed shape.
///
/// Returns `Some(variant)` for each of figment's three documented
/// `Source` variants (`File` / `Code` / `Custom`), with the inner
/// data borrowed from `source`. Returns `None` only if figment grew
/// a new variant after this enum was last extended; callers should
/// treat `None` as "unrecognized source shape" rather than "no
/// source attached".
///
/// One source of truth for the figment-Source-axis dispatch: the
/// resolver in [`crate::ShikumiError::failing_source`] routes its
/// `Source::File` / `Source::Code` arms through this primitive
/// instead of calling [`figment::Source::file_path`] /
/// [`figment::Source::code_location`] in line. If figment changes
/// its Source taxonomy (renames a variant, adds `Source::Url`,
/// etc.), exactly one site here changes and the
/// `figment_source_tag_classifies_*` tests catch the drift before
/// it reaches the resolver.
#[must_use]
pub fn classify(source: &'a figment::Source) -> Option<Self> {
if let Some(p) = source.file_path() {
return Some(Self::File(p));
}
if let Some(loc) = source.code_location() {
return Some(Self::Code(loc));
}
if let Some(c) = source.custom() {
return Some(Self::Custom(c));
}
None
}
/// Returns the file path if this tag is a [`Self::File`].
#[must_use]
pub fn as_file_path(self) -> Option<&'a Path> {
match self {
Self::File(p) => Some(p),
_ => None,
}
}
/// Returns `true` for [`Self::Code`].
#[must_use]
pub fn is_code(self) -> bool {
matches!(self.kind(), FigmentSourceKind::Code)
}
/// Returns the custom-source string if this tag is a [`Self::Custom`].
#[must_use]
pub fn as_custom(self) -> Option<&'a str> {
match self {
Self::Custom(c) => Some(c),
_ => None,
}
}
/// Data-free, `'static` discriminant of this [`FigmentSourceTag`]:
/// the kind of `figment::Source` ([`FigmentSourceKind::File`] /
/// [`FigmentSourceKind::Code`] / [`FigmentSourceKind::Custom`])
/// independent of the inner borrowed path / location / string.
///
/// One source of truth for the figment-Source-axis kind partition.
/// Observers that need only the kind axis (filtering by source class,
/// hashing in a `'static` map, recording per-failure source-class in
/// an attestation manifest) match on this closed enum instead of
/// pattern-matching against [`FigmentSourceTag`] with a borrowed
/// lifetime, or chaining [`Self::as_file_path`] / [`Self::is_code`] /
/// [`Self::as_custom`] together. The kind is `'static`, so it can
/// cross threads, serialize, and persist across observation
/// boundaries the borrowed tag cannot.
///
/// Mirrors the [`ConfigSource`] → [`ConfigSourceKind`] lift on the
/// shikumi-source axis: same typescape discipline (closed,
/// allocation-free, `Copy + Eq + Hash + #[non_exhaustive]`,
/// exhaustive forward map), applied to figment's `Source` axis. The
/// two kind partitions are structurally distinct universes — one
/// classifies shikumi's recorded chain layers, the other classifies
/// figment's per-value source attribution — but compose under one
/// typescape primitive set.
///
/// Pairs with [`Self::attribution_axis`]: the projection is constant
/// ([`crate::AttributionAxis::MetadataSource`] for every variant)
/// since [`FigmentSourceTag`] *is* the typed reading of
/// `figment::Metadata::source`. That structural law is pinned by
/// `figment_source_tag_attribution_axis_is_always_metadata_source`.
/// A future variant landing on [`FigmentSourceTag`] (e.g. a
/// `Source::Url` shape if figment grows one) forces a
/// [`FigmentSourceKind`] arm in lockstep at compile time, and the
/// constant axis projection extends without per-site updates.
#[must_use]
pub fn kind(self) -> FigmentSourceKind {
match self {
Self::File(_) => FigmentSourceKind::File,
Self::Code(_) => FigmentSourceKind::Code,
Self::Custom(_) => FigmentSourceKind::Custom,
}
}
/// [`crate::AttributionAxis`] of this tag — constant
/// [`crate::AttributionAxis::MetadataSource`] for every variant,
/// since [`FigmentSourceTag`] *is* the typed reading of
/// `figment::Metadata::source`.
///
/// One source of truth for the structural law that every
/// figment-Source-axis attribution dispatches off `metadata.source`,
/// regardless of which variant fires. The pair
/// (figment-side: [`FigmentSourceTag::attribution_axis`],
/// resolver-side: [`crate::AttributionRule::metadata_axis`]) cross-checks
/// the axis between the two surfaces; consumers reading either side
/// see the same axis label without re-deriving the
/// (typed-source × name-string) partition. Mirrors
/// [`FigmentNameTag`]-shaped attributions, which always sit on
/// [`crate::AttributionAxis::MetadataName`] by the same structural
/// argument.
#[must_use]
pub fn attribution_axis(self) -> crate::AttributionAxis {
let _ = self.kind();
crate::AttributionAxis::MetadataSource
}
}
/// Data-free, `'static` discriminant of [`FigmentSourceTag`]: the kind
/// of `figment::Source` independent of the inner borrowed path /
/// location / string.
///
/// Closed three-way partition over the [`FigmentSourceTag`] variant
/// space, returned by [`FigmentSourceTag::kind`]. The enum exists so
/// consumers that need only the kind axis (filtering by source class,
/// hashing in a `'static` map, recording per-failure source-class in
/// an attestation manifest, comparing across thread boundaries) match
/// on one closed enum instead of pattern-matching against the borrowed
/// tag or chaining [`FigmentSourceTag::as_file_path`] /
/// [`FigmentSourceTag::is_code`] / [`FigmentSourceTag::as_custom`]
/// together.
///
/// Mirrors the [`ConfigSource`] → [`ConfigSourceKind`] lift on the
/// shikumi-source axis: same typescape discipline (closed,
/// allocation-free, `Copy + Eq + Hash + #[non_exhaustive]`,
/// exhaustive forward map), applied to figment's `Source` axis.
///
/// `'static` and allocation-free — no lifetime parameter, unlike
/// [`FigmentSourceTag`]. The kind survives any borrow on the
/// originating `figment::Source` and can therefore cross thread
/// boundaries, serialize, and live in long-lived structures (the way
/// [`ConfigSourceKind`] does on the captured cross-thread observable
/// form of [`crate::ReloadFailure`]).
///
/// Adding a future [`FigmentSourceTag`] variant (e.g. a `Source::Url`
/// shape if figment grows one) means adding one [`FigmentSourceKind`]
/// variant in lockstep — the exhaustive [`FigmentSourceTag::kind`]
/// match forces the assignment at compile time.
///
/// **Total order** — the derived `Ord` / `PartialOrd` impls lex over
/// the variant declaration order in [`Self::ALL`]
/// (`File < Code < Custom`), matching the trait-uniform discipline
/// already landed on the sibling closed-enum axis primitives
/// [`ConfigSourceKind`] (commit `e0b96d1`),
/// [`crate::Format`] (commit `b56b121`),
/// [`crate::FormatProvenance`] (commit `2c7654c`), and
/// [`crate::FormatCoordinates`] (commit `06a2f42`). A
/// `BTreeMap<FigmentSourceKind, T>` keyed on the figment-Source axis
/// kind (per-kind attribution counters, per-kind failure-rate
/// dashboards, attestation manifests recording the figment-Source
/// kind cardinality mix) emits rows in declaration order
/// deterministically. Pinned by
/// [`tests::figment_source_kind_ord_matches_all_declaration_order`]
/// and
/// [`tests::figment_source_kind_btreemap_emits_in_declaration_order`].
///
/// **Canonical wire form** — the [`fmt::Display`], [`FromStr`],
/// [`serde::Serialize`], and [`serde::Deserialize`] impls route
/// through the canonical lowercase label [`Self::as_str`] returns
/// (`"file"`, `"code"`, `"custom"`). A consumer struct holding a
/// [`FigmentSourceKind`] field under
/// `#[derive(Serialize, Deserialize)]` round-trips through the
/// canonical label without a consumer-side rename helper; an
/// operator typing the canonical name into an env var or CLI flag
/// parses pointwise through [`FromStr`] case-insensitively over
/// ASCII. Idiom-peer of the canonical surface already lifted onto
/// [`ConfigSourceKind`] (commit `e0b96d1`).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
#[non_exhaustive]
pub enum FigmentSourceKind {
/// Maps to [`FigmentSourceTag::File`] regardless of inner path.
File,
/// Maps to [`FigmentSourceTag::Code`] regardless of inner location.
Code,
/// Maps to [`FigmentSourceTag::Custom`] regardless of inner string.
Custom,
}
impl FigmentSourceKind {
/// Every [`FigmentSourceKind`] variant, in declaration order
/// ([`Self::File`], [`Self::Code`], [`Self::Custom`]).
///
/// The closed list of `figment::Source` kinds shikumi recognizes.
/// Iterate to enumerate the figment-Source-axis kind space without
/// listing variants by hand at every consumer site — e.g.
/// dashboards initializing per-kind counters (weighting `Custom`
/// attributions visibly weaker than `File`/`Code` ones since
/// `Source::Custom` is a free-form string), attestation manifests
/// recording the figment-Source-axis kind space's cardinality,
/// structured-diagnostics legends rendering different prose per
/// class, or partition-coverage tests asserting disjointness across
/// the figment-side classification.
///
/// One source of truth for the kind enumeration on the
/// [`FigmentSourceKind`] axis: peer to [`crate::Format::ALL`] on
/// the format axis, [`crate::ShikumiErrorKind::ALL`] on the kind
/// axis, [`crate::AttributionRule::ALL`] on the rule axis,
/// [`ConfigSourceKind::ALL`] on the shikumi-side layer-kind axis,
/// [`crate::FieldPathLocalization::ALL`] on the
/// field-path-localization axis,
/// [`crate::FormatProvenance::ALL`] on the format-provenance
/// axis, [`crate::AttributionAxis::ALL`] on the metadata axis,
/// and [`crate::AttributionConfidence::ALL`] on the confidence
/// axis — the same typescape discipline (closed `'static` slice,
/// in declaration order) applied to figment's `Source`-axis kind.
/// Before this constant, the kind enumeration was inlined as a
/// `[File, Code, Custom]` array literal at sites that needed to
/// iterate (the `figment_source_kind_is_static_and_copy_and_hashable`
/// test inserted each variant by hand; the
/// `figment_source_kind_partitions_disjointly` test built a
/// `[(Tag, Kind); 3]` table inline); each duplicated literal had to
/// be manually kept in lockstep with the enum's variant set.
///
/// Adding a new variant to [`Self`] (e.g. a future `Url` kind in
/// lockstep with a hypothetical `FigmentSourceTag::Url` if figment
/// grows one) means extending this slice in lockstep with the
/// variant itself. The compiler enforces nothing here directly,
/// so the `figment_source_kind_all_covers_every_constructible_tag`
/// test pins the contract by asserting that every kind produced by
/// [`FigmentSourceTag::kind`] over the canonical sample table
/// appears in [`Self::ALL`], and the
/// `figment_source_kind_all_has_no_duplicates` test pins that the
/// constant is a set (no double-listed variant). Together they pin
/// the constant to the variant space the typescape recognizes.
pub const ALL: &'static [Self] = &[Self::File, Self::Code, Self::Custom];
/// Returns `true` for [`Self::File`]; equivalent to
/// `self == FigmentSourceKind::File`. Convenience predicate
/// matching the [`ConfigSource::is_file`] /
/// [`ConfigSource::is_env`] / [`ConfigSource::is_defaults`]
/// sibling pattern on the shikumi-source axis.
#[must_use]
pub fn is_file(self) -> bool {
matches!(self, Self::File)
}
/// Returns `true` for [`Self::Code`].
#[must_use]
pub fn is_code(self) -> bool {
matches!(self, Self::Code)
}
/// Returns `true` for [`Self::Custom`].
#[must_use]
pub fn is_custom(self) -> bool {
matches!(self, Self::Custom)
}
/// Canonical operator-facing lowercase name of the figment-Source
/// kind — `"file"`, `"code"`, or `"custom"`.
///
/// The single source of truth for the figment-Source-axis kind
/// label strings on the [`FigmentSourceKind`] axis. Inherent mirror
/// of the [`crate::ClosedAxisLabel`] trait method; the trait impl
/// delegates here so the canonical names live at one site instead
/// of being re-stated at every operator-facing surface (a future
/// structured-log field naming the figment-Source-axis kind of a
/// failing attribution, a CLI flag filtering attributions by
/// figment-Source-axis kind, an attestation manifest recording the
/// figment-Source-axis kind histogram of loaded values). The
/// strings match the variant identifiers in ASCII-lowercase form —
/// the same form an operator would type into an env var or CLI
/// flag.
///
/// The label space coincides with [`ConfigSourceKind::as_str`] on
/// the `"file"` cell — [`Self::File`] and
/// [`ConfigSourceKind::File`] both render as `"file"`, by design:
/// the shikumi-side file layer typically loads through a figment
/// File-source provider, so the operator-facing label is the same
/// concept viewed from the two sides of the resolution boundary
/// ([`crate::AttributionSourceKindCoordinates`] joins the two
/// axes as the (figment-source-kind × shikumi-layer-kind) cube).
/// The other two cells (`"code"`, `"custom"`) are unique to the
/// figment-Source axis. The trait-uniform distinctness law
/// (`closed_axis_label_as_str_distinct_for_every_implementor`)
/// pins distinctness within an axis only; cross-axis label
/// coincidence is structural, not a discipline violation.
///
/// Pairs with [`crate::ClosedAxisLabel::from_canonical_str`] via
/// the trait-default linear-scan parse; the round-trip law
/// `Self::from_canonical_str(v.as_str()) == Some(v)` is pinned for
/// every variant uniformly by the trait-uniform
/// `closed_axis_label_round_trips_for_every_implementor` test in
/// `cube::tests`. The concrete-position pin at
/// `figment_source_kind_as_str_yields_canonical_lowercase_names`
/// holds the literal strings stable so a future rename
/// (e.g. capitalizing `"Code"`, prefixing `"figment-file"`) fails
/// at that site before drifting through the round-trip law.
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::File => "file",
Self::Code => "code",
Self::Custom => "custom",
}
}
}
impl crate::ClosedAxis for FigmentSourceKind {
const ALL: &'static [Self] = Self::ALL;
}
impl crate::ClosedAxisLabel for FigmentSourceKind {
fn as_str(self) -> &'static str {
Self::as_str(self)
}
}
// The canonical (Display, FromStr, Serialize, Deserialize) string-surface
// quartet on the figment-Source-axis kind closed-enum, lifted to one macro
// after the six hand-rolled idiom-peers preceding this commit
// (WatchEventClass at `94f8a8b`, ShikumiErrorKind at `4b53792`,
// DiffLineKind at `74ee853`, ConfigSourceKind at `ae24a13`,
// FormatProvenance at `212d6fb`, FigmentNameTagKind at `25bab65`). See
// `closed_axis_label_string_surface!` in `crate::macros` for the
// contract; behavior is byte-identical to the hand-rolled impls the
// macro replaces — the verbatim-label `Parse` error body, the
// case-insensitive `from_canonical_str` lowering, the `collect_str`-based
// serde emission, and the visitor's `expecting` message all match the
// prior surface pointwise. Pinned by
// `tests::figment_source_kind_display_matches_as_str`,
// `tests::figment_source_kind_from_str_*`, and
// `tests::figment_source_kind_serde_yaml_*`.
closed_axis_label_string_surface! {
type = FigmentSourceKind,
parse_error = "unknown figment source kind",
expecting = "a canonical FigmentSourceKind lowercase label \
(`file`, `code`, `custom`; case-insensitive)",
}
impl fmt::Display for ConfigSource {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Defaults => f.write_str("defaults"),
Self::Env(prefix) if prefix.is_empty() => f.write_str("env"),
Self::Env(prefix) => write!(f, "env({prefix})"),
Self::File(path) => write!(f, "file({})", path.display()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_display() {
assert_eq!(ConfigSource::Defaults.to_string(), "defaults");
}
#[test]
fn env_display_with_prefix() {
let s = ConfigSource::Env("MYAPP_".to_owned());
assert_eq!(s.to_string(), "env(MYAPP_)");
}
#[test]
fn env_display_empty_prefix() {
assert_eq!(ConfigSource::Env(String::new()).to_string(), "env");
}
#[test]
fn file_display_includes_path() {
let s = ConfigSource::File(PathBuf::from("/etc/app/app.yaml"));
assert_eq!(s.to_string(), "file(/etc/app/app.yaml)");
}
#[test]
fn as_path_returns_path_for_file_only() {
let f = ConfigSource::File(PathBuf::from("/x.yaml"));
assert_eq!(f.as_path(), Some(Path::new("/x.yaml")));
assert_eq!(ConfigSource::Defaults.as_path(), None);
assert_eq!(ConfigSource::Env("X_".to_owned()).as_path(), None);
}
#[test]
fn file_format_reports_extension_format_for_file_only() {
use crate::discovery::Format;
assert_eq!(
ConfigSource::File(PathBuf::from("/etc/app/app.yaml")).file_format(),
Some(Format::Yaml)
);
assert_eq!(
ConfigSource::File(PathBuf::from("app.yml")).file_format(),
Some(Format::Yaml)
);
assert_eq!(
ConfigSource::File(PathBuf::from("app.toml")).file_format(),
Some(Format::Toml)
);
assert_eq!(
ConfigSource::File(PathBuf::from("app.lisp")).file_format(),
Some(Format::Lisp)
);
assert_eq!(
ConfigSource::File(PathBuf::from("app.nix")).file_format(),
Some(Format::Nix)
);
// Non-File sources have no file format.
assert_eq!(ConfigSource::Defaults.file_format(), None);
assert_eq!(ConfigSource::Env("APP_".to_owned()).file_format(), None);
}
#[test]
fn file_format_none_for_unrecognized_or_extensionless_file() {
// A `File` with an unknown extension yields `None` even though
// `with_file` would parse it via the TOML fallback — `None` here
// means "extension declared no format", distinguished from a
// non-File source by `is_file`.
let unknown = ConfigSource::File(PathBuf::from("app.conf"));
assert_eq!(unknown.file_format(), None);
assert!(unknown.is_file());
let no_ext = ConfigSource::File(PathBuf::from("app"));
assert_eq!(no_ext.file_format(), None);
assert!(no_ext.is_file());
}
#[test]
fn file_format_agrees_with_format_from_path_pointwise() {
// The accessor is exactly `Format::from_path` on the recorded path
// for `File` sources, and `None` otherwise.
for path in [
"c.yaml", "c.yml", "c.toml", "c.lisp", "c.el", "c.nix", "c.json", "c",
] {
let src = ConfigSource::File(PathBuf::from(path));
assert_eq!(
src.file_format(),
crate::discovery::Format::from_path(Path::new(path)),
"path: {path}"
);
}
}
#[test]
fn as_env_prefix_returns_prefix_for_env_only() {
let e = ConfigSource::Env("APP_".to_owned());
assert_eq!(e.as_env_prefix(), Some("APP_"));
assert_eq!(ConfigSource::Defaults.as_env_prefix(), None);
assert_eq!(
ConfigSource::File(PathBuf::from("/x")).as_env_prefix(),
None
);
}
#[test]
fn predicates_match_one_variant_each() {
let f = ConfigSource::File(PathBuf::from("/a"));
let e = ConfigSource::Env("E_".to_owned());
let d = ConfigSource::Defaults;
assert!(f.is_file() && !f.is_env() && !f.is_defaults());
assert!(!e.is_file() && e.is_env() && !e.is_defaults());
assert!(!d.is_file() && !d.is_env() && d.is_defaults());
}
#[test]
fn equality_and_hash_distinguish_variants() {
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert(ConfigSource::Defaults);
set.insert(ConfigSource::Env("X_".to_owned()));
set.insert(ConfigSource::Env("X_".to_owned())); // duplicate
set.insert(ConfigSource::File(PathBuf::from("/a.yaml")));
assert_eq!(set.len(), 3, "duplicate env entries should collapse");
assert!(set.contains(&ConfigSource::Defaults));
}
#[test]
fn clone_preserves_data() {
let s = ConfigSource::File(PathBuf::from("/a/b.yaml"));
let c = s.clone();
assert_eq!(s, c);
}
// ---- ConfigSourceChain (chain-level provenance queries) ----
fn sample_chain() -> Vec<ConfigSource> {
vec![
ConfigSource::File(PathBuf::from("/etc/app/app.yaml")),
ConfigSource::File(PathBuf::from("/home/u/.config/app/app.yaml")),
ConfigSource::Env("APP_".to_owned()),
]
}
#[test]
fn find_file_returns_matching_file_entry() {
let chain = sample_chain();
let hit = chain
.find_file(Path::new("/home/u/.config/app/app.yaml"))
.expect("a file layer was loaded from that path");
assert_eq!(
hit.as_path(),
Some(Path::new("/home/u/.config/app/app.yaml"))
);
}
#[test]
fn find_file_none_for_unrecorded_path() {
let chain = sample_chain();
assert!(chain.find_file(Path::new("/nope.yaml")).is_none());
}
#[test]
fn find_file_ignores_non_file_layers() {
// A path that no File layer carries; Env/Defaults must never match
// even though the chain has those layers.
let chain = [ConfigSource::Defaults, ConfigSource::Env("E_".to_owned())];
assert!(chain.find_file(Path::new("/etc/app/app.yaml")).is_none());
}
#[test]
fn find_file_agrees_with_open_coded_walk_pointwise() {
let chain = sample_chain();
for probe in [
Path::new("/etc/app/app.yaml"),
Path::new("/home/u/.config/app/app.yaml"),
Path::new("/missing.toml"),
] {
let lifted = chain.find_file(probe);
let manual = chain.iter().find(|s| s.as_path() == Some(probe));
assert_eq!(
lifted, manual,
"find_file must match the walk for {probe:?}"
);
}
}
#[test]
fn unique_of_kind_returns_sole_layer() {
let chain = [
ConfigSource::Defaults,
ConfigSource::Env("ONLY_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let env = chain
.unique_of_kind(ConfigSourceKind::Env)
.expect("exactly one env layer");
assert_eq!(env.as_env_prefix(), Some("ONLY_"));
let defaults = chain
.unique_of_kind(ConfigSourceKind::Defaults)
.expect("exactly one defaults layer");
assert!(defaults.is_defaults());
}
#[test]
fn unique_of_kind_none_when_ambiguous() {
// Two File layers → File is not unique.
let chain = sample_chain();
assert!(chain.unique_of_kind(ConfigSourceKind::File).is_none());
}
#[test]
fn unique_of_kind_none_when_absent() {
// Chain with no defaults layer.
let chain = sample_chain();
assert!(chain.unique_of_kind(ConfigSourceKind::Defaults).is_none());
}
#[test]
fn unique_of_kind_agrees_with_open_coded_uniqueness() {
// Pin equivalence to the filter+next+next().is_none() pattern the
// failing-source resolver used to inline, over every kind and over
// chains with 0, 1, and 2 layers of the probed kind.
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env("A_".to_owned()),
ConfigSource::Env("B_".to_owned()),
],
];
for chain in &chains {
for kind in ConfigSourceKind::ALL.iter().copied() {
let lifted = chain.unique_of_kind(kind);
let mut hits = chain.iter().filter(|s| s.kind() == kind);
let manual = hits.next().filter(|_| hits.next().is_none());
assert_eq!(
lifted, manual,
"unique_of_kind({kind:?}) must match the open-coded uniqueness walk"
);
}
}
}
#[test]
fn find_env_by_prefix_returns_matching_env_entry() {
let chain = sample_chain();
let hit = chain
.find_env_by_prefix("APP_")
.expect("an env layer was recorded with that prefix");
assert_eq!(hit.as_env_prefix(), Some("APP_"));
}
#[test]
fn find_env_by_prefix_matches_case_insensitively() {
// figment uppercases the prefix when emitting metadata names,
// while users may pass any case to ProviderChain::with_env. The
// primitive must match across the case boundary so the
// failing-source resolver's EnvByPrefix rule fires regardless of
// which side carries the canonical casing.
let chain = [ConfigSource::Env("myapp_".to_owned())];
let hit = chain
.find_env_by_prefix("MYAPP_")
.expect("ASCII case-insensitive match must locate the layer");
assert_eq!(hit.as_env_prefix(), Some("myapp_"));
let chain = [ConfigSource::Env("MyApp_".to_owned())];
assert!(chain.find_env_by_prefix("MYAPP_").is_some());
assert!(chain.find_env_by_prefix("myapp_").is_some());
assert!(chain.find_env_by_prefix("myApp_").is_some());
}
#[test]
fn find_env_by_prefix_none_for_unrecorded_prefix() {
let chain = sample_chain();
assert!(chain.find_env_by_prefix("OTHER_").is_none());
}
#[test]
fn find_env_by_prefix_ignores_non_env_layers() {
// A chain of File/Defaults layers must never match, even when the
// probe is a non-empty prefix string that could conceivably collide
// with some file path; only Env layers carry prefixes.
let chain = [
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/etc/APP_/app.yaml")),
];
assert!(chain.find_env_by_prefix("APP_").is_none());
}
#[test]
fn find_env_by_prefix_returns_first_match() {
// Two env layers with the same prefix (degenerate but constructible
// via two with_env calls): the first match wins, matching the
// iter().find semantics the resolver previously inlined.
let first = ConfigSource::Env("DUP_".to_owned());
let second = ConfigSource::Env("DUP_".to_owned());
let chain = [first.clone(), second];
let hit = chain
.find_env_by_prefix("DUP_")
.expect("first matching env layer");
// Compare by address: must be the first slot, not the second.
assert!(std::ptr::eq(hit, &chain[0]));
}
#[test]
fn find_env_by_prefix_matches_empty_prefix() {
// figment::providers::Env::raw() emits the bare metadata-name
// shape, recognized as EnvMetadataTag::Bare and routed to the
// uniqueness rule by the resolver — but a chain may still carry
// an Env layer with the empty prefix. The primitive matches it
// pointwise.
let chain = [ConfigSource::Env(String::new())];
let hit = chain
.find_env_by_prefix("")
.expect("empty-prefix env layer");
assert_eq!(hit.as_env_prefix(), Some(""));
}
#[test]
fn find_env_by_prefix_agrees_with_open_coded_walk_pointwise() {
// Pin equivalence to the iter().find(|s| s.as_env_prefix()
// .is_some_and(|p| p.eq_ignore_ascii_case(probe))) pattern the
// failing-source resolver used to inline, across the case
// boundary and across chains with 0, 1, and 2 env layers.
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env("A_".to_owned()),
ConfigSource::Env("B_".to_owned()),
],
vec![ConfigSource::Env("MixedCase_".to_owned())],
];
for chain in &chains {
for probe in ["APP_", "app_", "A_", "MIXEDCASE_", "OTHER_", ""] {
let lifted = chain.find_env_by_prefix(probe);
let manual = chain.iter().find(|s| {
s.as_env_prefix()
.is_some_and(|p| p.eq_ignore_ascii_case(probe))
});
assert_eq!(
lifted, manual,
"find_env_by_prefix({probe:?}) must match the open-coded walk"
);
}
}
}
// ---- ConfigSourceChain::layer_kind_histogram ----
#[test]
fn layer_kind_histogram_counts_each_kind_pointwise() {
// Concrete pin on the (chain → ConfigSourceKind tally)
// projection. `sample_chain()` is two File layers + one Env
// layer (no Defaults), so the histogram must read 2 File,
// 1 Env, 0 Defaults.
let chain = sample_chain();
let hist = chain.as_slice().layer_kind_histogram();
assert_eq!(hist.count(ConfigSourceKind::File), 2);
assert_eq!(hist.count(ConfigSourceKind::Env), 1);
assert_eq!(hist.count(ConfigSourceKind::Defaults), 0);
// total() equals chain length pointwise (every entry projects
// to exactly one kind).
assert_eq!(hist.total(), chain.len());
}
#[test]
fn layer_kind_histogram_empty_chain_is_zero_on_every_cell() {
// Empty-chain law: every cell reads zero, total is zero,
// is_empty() is true. Pins the monoid identity at the
// chain-shape boundary.
let chain: [ConfigSource; 0] = [];
let hist = chain.layer_kind_histogram();
for kind in ConfigSourceKind::ALL.iter().copied() {
assert_eq!(
hist.count(kind),
0,
"empty chain must read zero on every kind cell ({kind:?})",
);
}
assert_eq!(hist.total(), 0);
assert!(hist.is_empty());
}
#[test]
fn layer_kind_histogram_agrees_with_open_coded_per_kind_count() {
// The lift collapses the per-cell `iter().filter(|s| s.kind()
// == k).count()` loop the typescape doc-strings promised — pin
// pointwise equivalence over the typed kind axis across chains
// with 0, 1, 2, and 3 entries of mixed kinds, so a future
// regression in either side surfaces here.
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("X_".to_owned()),
],
];
for chain in &chains {
let hist = chain.as_slice().layer_kind_histogram();
for kind in ConfigSourceKind::ALL.iter().copied() {
let manual = chain.iter().filter(|s| s.kind() == kind).count();
assert_eq!(
hist.count(kind),
manual,
"layer_kind_histogram({kind:?}) must equal the open-coded \
filter-count over chain of length {}",
chain.len(),
);
}
}
}
#[test]
fn layer_kind_histogram_iter_yields_declaration_order() {
// The dense per-cell iteration must yield the
// ConfigSourceKind::ALL declaration order
// (Defaults, Env, File) regardless of the chain's observation
// order — observation order does not leak into the histogram's
// value-side iteration. Mirror of
// `kind_histogram_iter_yields_declaration_order` on the
// diff-line axis in `tiered::tests`.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("E_".to_owned()),
ConfigSource::Defaults,
];
let pairs: Vec<(ConfigSourceKind, usize)> =
chain.as_slice().layer_kind_histogram().iter().collect();
let values: Vec<ConfigSourceKind> = pairs.iter().map(|(k, _)| *k).collect();
assert_eq!(values, ConfigSourceKind::ALL.to_vec());
}
#[test]
fn layer_kind_histogram_equals_axis_histogram_over_kind_projection() {
// Pin equivalence to the generic
// `crate::axis_histogram(self.iter().map(ConfigSource::kind))`
// shape the trait-default method routes through — the lift
// must not silently re-implement the per-cell count loop on
// a parallel surface. Pointwise equality on every kind cell.
let chains = [
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Defaults],
vec![
ConfigSource::Env("A_".to_owned()),
ConfigSource::Env("B_".to_owned()),
ConfigSource::File(PathBuf::from("/x.toml")),
],
];
for chain in &chains {
let lifted = chain.as_slice().layer_kind_histogram();
let generic = crate::axis_histogram(chain.iter().map(ConfigSource::kind));
for kind in ConfigSourceKind::ALL.iter().copied() {
assert_eq!(
lifted.count(kind),
generic.count(kind),
"layer_kind_histogram must equal axis_histogram(kind-projection) \
on {kind:?} over chain of length {}",
chain.len(),
);
}
}
}
// ---- ConfigSourceChain::present_layer_kinds — observed-cells
// peer of ConfigDiff::present_kinds / ProvenanceMap::
// contributing_tiers on the chain-shape altitude ----
#[test]
fn present_layer_kinds_matches_layer_kind_histogram_observed_pointwise() {
// The observed-support pin: `present_layer_kinds` routes
// through `layer_kind_histogram().observed().collect()`, so the
// two seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Mirror
// of `present_kinds_matches_kind_histogram_observed_pointwise`
// on the diff altitude and
// `contributing_tiers_matches_tier_histogram_observed` on the
// tier altitude.
let fixtures: [Vec<ConfigSource>; 4] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let via_direct = chain.as_slice().present_layer_kinds();
let via_histogram: Vec<ConfigSourceKind> =
chain.as_slice().layer_kind_histogram().observed().collect();
assert_eq!(
via_direct,
via_histogram,
"present_layer_kinds must equal \
layer_kind_histogram().observed().collect() pointwise \
over chain of length {}",
chain.len(),
);
}
}
#[test]
fn present_layer_kinds_empty_chain_is_empty() {
// The empty-boundary invariant: an empty chain has no present
// kinds; a non-empty chain has ≥1 present kind (every entry
// projects to exactly one kind). Peer of the same empty-
// boundary pin on `ConfigDiff::present_kinds` and
// `ProvenanceMap::contributing_tiers`.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.present_layer_kinds().is_empty());
assert_eq!(empty.present_layer_kinds(), Vec::<ConfigSourceKind>::new());
let one_layer = vec![ConfigSource::Defaults];
assert!(!one_layer.is_empty());
assert!(!one_layer.as_slice().present_layer_kinds().is_empty());
}
#[test]
fn present_layer_kinds_iterates_in_declaration_order() {
// Declaration-order pin: even when the observation order is
// File → Env → Defaults (the reverse of ::ALL), the returned
// Vec walks the closed axis in canonical
// (Defaults → Env → File) order — the closed-axis discipline
// provides the sort automatically. Mirror of
// `present_kinds_iterates_in_declaration_order` on the diff
// altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
];
assert_eq!(
chain.as_slice().present_layer_kinds(),
vec![
ConfigSourceKind::Defaults,
ConfigSourceKind::Env,
ConfigSourceKind::File,
],
);
}
#[test]
fn present_layer_kinds_dedups_across_repeated_observations() {
// Repeated observations of the same kind collapse to one entry
// in the returned Vec — the closed-axis discipline provides
// dedup automatically. Six layers split (2 Defaults × 3 File ×
// 1 Env) yield three present kinds. Mirror of
// `present_kinds_dedups_across_repeated_observations` on the
// diff altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::Env("APP_".to_owned()),
];
assert_eq!(
chain.as_slice().present_layer_kinds(),
vec![
ConfigSourceKind::Defaults,
ConfigSourceKind::Env,
ConfigSourceKind::File,
],
);
}
#[test]
fn present_layer_kinds_singleton_chain_yields_singleton_support() {
// A chain composed only of one kind has exactly that kind as
// its present-kinds set — the support is the singleton
// observed cell. Boundary case pinning that unobserved cells
// do not leak into the returned Vec (the closed-axis
// discipline drops zero-count cells).
let defaults_only = vec![ConfigSource::Defaults, ConfigSource::Defaults];
assert_eq!(
defaults_only.as_slice().present_layer_kinds(),
vec![ConfigSourceKind::Defaults],
);
let env_only = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
assert_eq!(
env_only.as_slice().present_layer_kinds(),
vec![ConfigSourceKind::Env],
);
let files_only = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
assert_eq!(
files_only.as_slice().present_layer_kinds(),
vec![ConfigSourceKind::File],
);
}
#[test]
fn present_layer_kinds_len_matches_distinct_cells() {
// The support-cardinality invariant:
// `present_layer_kinds().len()` equals
// `layer_kind_histogram().distinct_cells()` pointwise. Both
// project the observed-cell count off the shared histogram
// over the ConfigSourceKind closed axis. Mirror of
// `present_kinds_distinct_cells_matches_histogram` on the
// diff altitude.
let fixtures: [Vec<ConfigSource>; 4] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_layer_kinds().len(),
chain.as_slice().layer_kind_histogram().distinct_cells(),
"present_layer_kinds().len() must equal \
layer_kind_histogram().distinct_cells() over chain of length {}",
chain.len(),
);
}
}
#[test]
fn present_layer_kinds_full_cover_matches_axis_cardinality() {
// Cross-surface pin on the full-cover predicate: a chain
// whose `layer_kind_histogram().is_full_cover()` returns
// `true` has exactly
// `crate::axis_cardinality::<ConfigSourceKind>()` observed
// cells, and `present_layer_kinds()` returns
// `ConfigSourceKind::ALL` in declaration order. Reads the
// typed full-cover question directly off the observed-cells
// peer instead of open-coding
// `distinct_cells == axis_cardinality`.
let axis_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
assert!(axis_cover.as_slice().layer_kind_histogram().is_full_cover());
assert_eq!(
axis_cover.as_slice().present_layer_kinds().len(),
crate::axis_cardinality::<ConfigSourceKind>(),
);
assert_eq!(
axis_cover.as_slice().present_layer_kinds(),
ConfigSourceKind::ALL.to_vec(),
);
// Strict-subset case: the sample chain has no Defaults entry,
// so it is NOT a full cover, and the present-kinds cardinality
// is strictly less than the axis cardinality.
let chain = sample_chain();
assert!(!chain.as_slice().layer_kind_histogram().is_full_cover());
assert!(
chain.as_slice().present_layer_kinds().len()
< crate::axis_cardinality::<ConfigSourceKind>(),
);
}
#[test]
fn present_layer_kinds_is_strictly_ascending_by_axis_ordinal() {
// Structural-sort pin: the returned Vec is strictly ascending
// by `crate::axis_ordinal` on ConfigSourceKind — dedup + sort
// for free from the closed-axis discipline. Every consecutive
// pair in the returned Vec has strictly increasing axis
// ordinal. Mirror of
// `present_kinds_is_strictly_ascending_by_axis_ordinal` on the
// diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
];
let present = chain.as_slice().present_layer_kinds();
for window in present.windows(2) {
let a = crate::axis_ordinal(window[0]);
let b = crate::axis_ordinal(window[1]);
assert!(
a < b,
"present_layer_kinds must be strictly ascending by \
axis_ordinal, but ord({:?})={a} >= ord({:?})={b}",
window[0],
window[1],
);
}
}
#[test]
fn present_layer_kinds_agrees_with_open_coded_dedup_walk() {
// Parity pin against a hand-rolled `Vec::contains` + sort_by_key
// consumer — the exact pattern the trait-level lift replaces.
// Any future divergence (e.g. `observed()` changing its
// iteration order, `layer_kind_histogram` projecting through
// a different kind function) surfaces here as a structural
// mismatch between the lifted seam and the open-coded walk.
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::Defaults,
],
];
for chain in &chains {
let lifted = chain.as_slice().present_layer_kinds();
let mut manual: Vec<ConfigSourceKind> = Vec::new();
for source in chain {
let k = source.kind();
if !manual.contains(&k) {
manual.push(k);
}
}
manual.sort_by_key(|k| crate::axis_ordinal(*k));
assert_eq!(
lifted,
manual,
"present_layer_kinds must equal the open-coded \
contains+sort walk over chain of length {}",
chain.len(),
);
}
}
// ---- ConfigSourceChain::present_layer_kinds_count — support-size
// scalar peer of present_layer_kinds on the layer-kind sub-axis
// of the chain altitude ----
#[test]
fn present_layer_kinds_count_matches_layer_kind_histogram_distinct_cells_pointwise() {
// The support-size pin: `present_layer_kinds_count` routes
// through `layer_kind_histogram().distinct_cells()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Chain-
// altitude peer of
// `contributing_tiers_count_matches_tier_histogram_distinct_cells_pointwise`
// on the tier altitude.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let via_histogram = chain.as_slice().layer_kind_histogram().distinct_cells();
assert_eq!(
chain.as_slice().present_layer_kinds_count(),
via_histogram,
"present_layer_kinds_count must equal \
layer_kind_histogram().distinct_cells() over chain of \
length {}",
chain.len(),
);
}
}
#[test]
fn present_layer_kinds_count_equals_present_layer_kinds_len_pointwise() {
// The Vec-peer identity: the scalar-count seam equals the length
// of the observed-cells `Vec` peer. Any future re-implementation
// of either seam must keep this equality — pinned uniformly.
// Chain-altitude peer of
// `contributing_tiers_count_equals_contributing_tiers_len_pointwise`
// on the tier altitude.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_layer_kinds_count(),
chain.as_slice().present_layer_kinds().len(),
);
}
}
#[test]
fn present_layer_kinds_count_and_absent_layer_kinds_len_partition_axis_cardinality() {
// The partition law: the scalar dual of
// `absent_layer_kinds_and_present_layer_kinds_partition_axis`.
// Every layer-kind cell lies in exactly one of (observed,
// unobserved), so the scalar-count peers of the two Vec peers
// sum to the axis cardinality. Chain-altitude peer of
// `contributing_tiers_count_and_absent_tiers_len_partition_axis_cardinality`
// on the tier altitude.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_layer_kinds_count()
+ chain.as_slice().absent_layer_kinds().len(),
axis_size,
);
}
}
#[test]
fn present_layer_kinds_count_is_zero_iff_chain_is_empty() {
// The empty-boundary equivalence: a zero-support recipe has
// zero entries and vice versa. Chain-altitude peer of
// `contributing_tiers_count_is_zero_iff_map_is_empty` on the
// tier altitude.
let empty: Vec<ConfigSource> = Vec::new();
assert!(empty.is_empty());
assert_eq!(empty.as_slice().present_layer_kinds_count(), 0);
let one_layer = vec![ConfigSource::Defaults];
assert!(!one_layer.is_empty());
assert!(one_layer.as_slice().present_layer_kinds_count() > 0);
let chain = sample_chain();
assert!(!chain.is_empty());
assert!(chain.as_slice().present_layer_kinds_count() > 0);
}
#[test]
fn present_layer_kinds_count_is_at_least_one_on_nonempty_chain() {
// The lower-bound invariant: the support of a non-empty recipe
// carries at least the singleton of the first-layer kind.
// Chain-altitude peer of
// `contributing_tiers_count_is_at_least_one_on_nonempty_map` on
// the tier altitude.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert!(!chain.is_empty());
assert!(chain.as_slice().present_layer_kinds_count() >= 1);
}
}
#[test]
fn present_layer_kinds_count_is_bounded_by_axis_cardinality() {
// The upper-bound invariant: the support of a closed-axis
// histogram is at most the axis cardinality (the observed-cells
// set is a subset of `ConfigSourceKind::ALL`). Chain-altitude
// peer of `contributing_tiers_count_is_bounded_by_axis_cardinality`
// on the tier altitude.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert!(chain.as_slice().present_layer_kinds_count() <= axis_size);
}
}
#[test]
fn present_layer_kinds_count_is_bounded_by_layer_kind_histogram_total() {
// The support ≤ total invariant: every distinct cell contributes
// at least one observation to the total, so the support size is
// bounded above by the total observation count. Chain-altitude
// peer of
// `contributing_tiers_count_is_bounded_by_tier_histogram_total`
// on the tier altitude.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert!(
chain.as_slice().present_layer_kinds_count()
<= chain.as_slice().layer_kind_histogram().total(),
);
}
}
#[test]
fn present_layer_kinds_count_equals_axis_cardinality_iff_is_full_cover() {
// The full-cover boundary equivalence: the support size equals
// the axis cardinality iff every layer kind contributed ≥1
// entry iff the coverage gap is empty. Chain-altitude peer of
// `contributing_tiers_count_equals_axis_cardinality_iff_is_full_cover`
// on the tier altitude.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
// Full-cover: one entry per layer kind.
let axis_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
assert!(axis_cover.as_slice().layer_kind_histogram().is_full_cover());
assert!(axis_cover.as_slice().absent_layer_kinds().is_empty());
assert_eq!(axis_cover.as_slice().present_layer_kinds_count(), axis_size,);
// Strict-subset: sample_chain omits Defaults, so full-cover is
// false and the support size is strictly less than axis size.
let chain = sample_chain();
assert!(!chain.as_slice().layer_kind_histogram().is_full_cover());
assert!(chain.as_slice().present_layer_kinds_count() < axis_size);
}
#[test]
fn present_layer_kinds_count_is_one_iff_has_singular_support() {
// The singleton-support boundary equivalence: the support size
// equals 1 iff exactly one layer kind contributed iff the
// histogram has singular support. Chain-altitude peer of
// `contributing_tiers_count_is_one_iff_has_singular_support` on
// the tier altitude.
let defaults_only = vec![ConfigSource::Defaults, ConfigSource::Defaults];
assert!(
defaults_only
.as_slice()
.layer_kind_histogram()
.has_singular_support()
);
assert_eq!(defaults_only.as_slice().present_layer_kinds_count(), 1);
let env_only = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
assert!(
env_only
.as_slice()
.layer_kind_histogram()
.has_singular_support()
);
assert_eq!(env_only.as_slice().present_layer_kinds_count(), 1);
// Sample chain spans two kinds, so singular-support reads false
// and the support size is > 1.
let chain = sample_chain();
assert!(
!chain
.as_slice()
.layer_kind_histogram()
.has_singular_support()
);
assert!(chain.as_slice().present_layer_kinds_count() > 1);
}
#[test]
fn present_layer_kinds_count_of_one_implies_dominant_equals_recessive() {
// The support-collapse degenerate: a singleton-support recipe
// has the modal and anti-modal cells coincide on the sole
// observed kind. Chain-altitude peer of
// `contributing_tiers_count_of_one_implies_dominant_equals_recessive`
// on the tier altitude.
let defaults_only = vec![ConfigSource::Defaults, ConfigSource::Defaults];
assert_eq!(defaults_only.as_slice().present_layer_kinds_count(), 1);
assert_eq!(
defaults_only.as_slice().dominant_layer_kind(),
defaults_only.as_slice().recessive_layer_kind(),
);
let env_only = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
assert_eq!(env_only.as_slice().present_layer_kinds_count(), 1);
assert_eq!(
env_only.as_slice().dominant_layer_kind(),
env_only.as_slice().recessive_layer_kind(),
);
let files_only = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
assert_eq!(files_only.as_slice().present_layer_kinds_count(), 1);
assert_eq!(
files_only.as_slice().dominant_layer_kind(),
files_only.as_slice().recessive_layer_kind(),
);
}
#[test]
fn present_layer_kinds_count_agrees_with_open_coded_nonzero_walk() {
// Parity against the exact
// `ConfigSourceKind::ALL.iter().filter(|k|
// layer_kind_histogram().count(*k) > 0).count()` walk this lift
// replaces. Chain-altitude peer of
// `contributing_tiers_count_agrees_with_open_coded_nonzero_walk`
// on the tier altitude.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let via_seam = chain.as_slice().present_layer_kinds_count();
let hist = chain.as_slice().layer_kind_histogram();
let hand_rolled = ConfigSourceKind::ALL
.iter()
.filter(|k| hist.count(**k) > 0)
.count();
assert_eq!(via_seam, hand_rolled);
}
}
#[test]
fn present_layer_kinds_count_sample_chain_is_two() {
// Direct fixture pin: sample_chain has two Files and one Env,
// so present_layer_kinds_count reads 2 (File, Env observed;
// Defaults absent).
let chain = sample_chain();
assert_eq!(chain.as_slice().present_layer_kinds_count(), 2);
}
#[test]
fn present_layer_kinds_count_full_cover_is_axis_cardinality() {
// Direct fixture pin: a chain covering every layer kind reads
// the axis cardinality (3 = |{Defaults, Env, File}|).
let axis_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
assert_eq!(
axis_cover.as_slice().present_layer_kinds_count(),
crate::axis_cardinality::<ConfigSourceKind>(),
);
}
// ---- ConfigSourceChain::absent_layer_kinds — unobserved-cells
// peer of present_layer_kinds on the chain-shape altitude ----
#[test]
fn absent_layer_kinds_matches_layer_kind_histogram_unobserved_pointwise() {
// The coverage-gap pin: `absent_layer_kinds` routes through
// `layer_kind_histogram().unobserved().collect()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Chain-
// altitude peer of
// `absent_kinds_matches_kind_histogram_unobserved_pointwise` on
// the diff altitude and
// `absent_tiers_matches_tier_histogram_unobserved_pointwise` on
// the tier altitude.
let fixtures: [Vec<ConfigSource>; 4] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
let via_direct = chain.as_slice().absent_layer_kinds();
let via_histogram: Vec<ConfigSourceKind> = chain
.as_slice()
.layer_kind_histogram()
.unobserved()
.collect();
assert_eq!(
via_direct,
via_histogram,
"absent_layer_kinds must equal \
layer_kind_histogram().unobserved().collect() pointwise \
over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_layer_kinds_empty_chain_is_full_axis() {
// An empty chain has no observed kinds — every cell of
// `ConfigSourceKind::ALL` lies in the coverage gap. The empty-
// chain / full-coverage-gap boundary of the observed /
// unobserved partition, chain-altitude peer of
// `absent_kinds_empty_diff_is_full_axis` on the diff altitude
// and `absent_tiers_empty_map_is_full_axis` on the tier
// altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.absent_layer_kinds(), ConfigSourceKind::ALL.to_vec(),);
}
#[test]
fn absent_layer_kinds_iterates_in_declaration_order() {
// The coverage-gap iter walks `ConfigSourceKind::ALL` in
// declaration order (`Defaults → Env → File`) and yields
// only the cells with zero count. Pinned here on the empty
// chain, whose gap is the entire axis — the emitted order
// matches `ConfigSourceKind::ALL` verbatim.
let empty: [ConfigSource; 0] = [];
assert_eq!(
empty.absent_layer_kinds(),
vec![
ConfigSourceKind::Defaults,
ConfigSourceKind::Env,
ConfigSourceKind::File,
],
);
}
#[test]
fn absent_layer_kinds_defaults_only_chain_is_env_and_file() {
// A chain composed only of `Defaults` layers has exactly
// { Env, File } as its coverage gap — the non-Defaults
// subset of the axis is entirely absent. Operator-facing pin
// on the "only serde defaults; no env, no file" recipe.
let defaults_only = vec![ConfigSource::Defaults, ConfigSource::Defaults];
assert_eq!(
defaults_only.as_slice().absent_layer_kinds(),
vec![ConfigSourceKind::Env, ConfigSourceKind::File],
);
}
#[test]
fn absent_layer_kinds_env_only_chain_is_defaults_and_file() {
// A chain composed only of `Env` layers has exactly
// { Defaults, File } as its coverage gap. Boundary pin on the
// "env-only recipe" — e.g. a service reading only from
// environment variables — the closed-axis discipline gives
// dedup and canonical order automatically.
let env_only = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
assert_eq!(
env_only.as_slice().absent_layer_kinds(),
vec![ConfigSourceKind::Defaults, ConfigSourceKind::File],
);
}
#[test]
fn absent_layer_kinds_file_only_chain_is_defaults_and_env() {
// A chain composed only of `File` layers has exactly
// { Defaults, Env } as its coverage gap. Boundary pin on the
// "file-only recipe" — the coverage-gap iter emits in
// declaration order regardless of observation order.
let files_only = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
assert_eq!(
files_only.as_slice().absent_layer_kinds(),
vec![ConfigSourceKind::Defaults, ConfigSourceKind::Env],
);
}
#[test]
fn absent_layer_kinds_len_matches_unobserved_cells() {
// The coverage-gap-cardinality invariant on the histogram's
// support / gap partition: `absent_layer_kinds().len()` equals
// `layer_kind_histogram().unobserved_cells()` pointwise across
// every fixture. Any future re-implementation of either seam
// must keep this equality.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_layer_kinds().len(),
chain.as_slice().layer_kind_histogram().unobserved_cells(),
"absent_layer_kinds().len() must equal \
layer_kind_histogram().unobserved_cells() over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_layer_kinds_and_present_layer_kinds_partition_axis() {
// The support / coverage-gap partition on the closed axis:
// every cell of `ConfigSourceKind::ALL` lies in exactly one of
// (observed, unobserved), so the two Vec lengths sum to the
// axis cardinality. Chain-altitude peer of
// `absent_kinds_and_present_kinds_partition_axis` on the diff
// altitude and
// `absent_tiers_and_contributing_tiers_partition_axis` on the
// tier altitude.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let observed = chain.as_slice().present_layer_kinds();
let absent = chain.as_slice().absent_layer_kinds();
assert_eq!(observed.len() + absent.len(), axis_size);
for kind in &observed {
assert!(
!absent.contains(kind),
"kind {kind:?} appears in both present and absent \
over chain of length {}",
chain.len(),
);
}
for cell in ConfigSourceKind::ALL {
assert!(
observed.contains(cell) || absent.contains(cell),
"kind {cell:?} appears in neither present nor absent \
over chain of length {}",
chain.len(),
);
}
}
}
#[test]
fn absent_layer_kinds_is_empty_iff_is_full_cover() {
// The coverage-gap is empty iff every layer kind was observed
// at least once. Pinned across every fixture in the module
// against `layer_kind_histogram().is_full_cover()`, plus a
// direct positive pin: a chain carrying one Defaults, one
// Env, and one File is full-cover; the coverage-gap is empty.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_layer_kinds().is_empty(),
chain.as_slice().layer_kind_histogram().is_full_cover(),
);
}
let full_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
assert!(full_cover.as_slice().layer_kind_histogram().is_full_cover());
assert_eq!(
full_cover.as_slice().absent_layer_kinds(),
Vec::<ConfigSourceKind>::new(),
);
assert_eq!(
full_cover.as_slice().present_layer_kinds(),
ConfigSourceKind::ALL.to_vec(),
);
}
#[test]
fn absent_layer_kinds_is_strictly_ascending_by_axis_ordinal() {
// Structural sort pin: the coverage-gap walks the closed axis
// in declaration order, so `absent_layer_kinds()` is strictly
// ascending by `crate::axis_ordinal` — the dedup + sort every
// hand-rolled walk would have to spell explicitly comes for
// free from the closed-axis discipline.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
];
for chain in &fixtures {
let absent = chain.as_slice().absent_layer_kinds();
for pair in absent.windows(2) {
assert!(
crate::axis_ordinal(pair[0]) < crate::axis_ordinal(pair[1]),
"absent_layer_kinds must be strictly ascending: {absent:?}",
);
}
}
}
#[test]
fn absent_layer_kinds_singleton_chain_yields_two_absent() {
// A chain of a single layer has exactly `axis_cardinality - 1`
// absent kinds — every axis cell except the one carried by
// that layer. Cross-verified against
// `present_layer_kinds().len() + absent_layer_kinds().len()
// == axis_cardinality`. Chain-altitude peer of
// `absent_kinds_singleton_diff_yields_two_absent` on the diff
// altitude.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
for (source, present_kind) in [
(ConfigSource::Defaults, ConfigSourceKind::Defaults),
(ConfigSource::Env("APP_".to_owned()), ConfigSourceKind::Env),
(
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSourceKind::File,
),
] {
let chain = vec![source];
let absent = chain.as_slice().absent_layer_kinds();
assert_eq!(absent.len(), axis_size - 1);
assert!(
!absent.contains(&present_kind),
"the observed kind {present_kind:?} must not appear in \
the coverage gap",
);
for cell in ConfigSourceKind::ALL {
if *cell != present_kind {
assert!(
absent.contains(cell),
"the singleton chain's coverage gap must contain \
every non-observed axis cell — missing {cell:?}",
);
}
}
}
}
#[test]
fn absent_layer_kinds_agrees_with_open_coded_coverage_gap_walk() {
// Parity against the exact
// `ConfigSourceKind::ALL.iter().filter(|k|
// !present_layer_kinds().contains(k))` walk this lift
// replaces — both the named seam and the hand-rolled
// coverage-gap must pointwise agree over every fixture.
// Chain-altitude peer of
// `absent_kinds_agrees_with_open_coded_coverage_gap_walk` on
// the diff altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let via_seam = chain.as_slice().absent_layer_kinds();
let present = chain.as_slice().present_layer_kinds();
let hand_rolled: Vec<ConfigSourceKind> = ConfigSourceKind::ALL
.iter()
.copied()
.filter(|k| !present.contains(k))
.collect();
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::absent_layer_kinds_count — coverage-gap-
// size scalar peer on the layer-kind sub-axis of the chain
// altitude ----
#[test]
fn absent_layer_kinds_count_matches_layer_kind_histogram_unobserved_cells_pointwise() {
// The coverage-gap-size pin: `absent_layer_kinds_count` routes
// through `layer_kind_histogram().unobserved_cells()`, so the
// two seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Chain-
// altitude sub-axis peer of
// `absent_tiers_count_matches_tier_histogram_unobserved_cells_pointwise`
// on the tier altitude and
// `absent_kinds_count_matches_kind_histogram_unobserved_cells_pointwise`
// on the diff altitude, and coverage-gap peer of
// `present_layer_kinds_count_matches_layer_kind_histogram_distinct_cells_pointwise`.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let via_histogram = chain.as_slice().layer_kind_histogram().unobserved_cells();
assert_eq!(
chain.as_slice().absent_layer_kinds_count(),
via_histogram,
"absent_layer_kinds_count must equal \
layer_kind_histogram().unobserved_cells() pointwise \
over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_layer_kinds_count_equals_absent_layer_kinds_len_pointwise() {
// The Vec-peer identity: the scalar-count seam equals the length
// of the coverage-gap `Vec` peer. Any future re-implementation
// of either seam must keep this equality — pinned uniformly.
// Chain-altitude sub-axis peer of
// `absent_tiers_count_equals_absent_tiers_len_pointwise` on the
// tier altitude.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_layer_kinds_count(),
chain.as_slice().absent_layer_kinds().len(),
);
}
}
#[test]
fn present_layer_kinds_count_and_absent_layer_kinds_count_partition_axis_cardinality() {
// The fully-scalar partition law: both sides now the scalar-
// count peers, no `.len()` on either. Every layer-kind cell lies
// in exactly one of (observed, unobserved). The scalar dual of
// `absent_layer_kinds_and_present_layer_kinds_partition_axis`
// closed on both sides. Sits alongside
// `present_layer_kinds_count_and_absent_layer_kinds_len_partition_axis_cardinality`
// which still uses `.len()` on the coverage-gap side.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_layer_kinds_count()
+ chain.as_slice().absent_layer_kinds_count(),
axis_size,
);
}
}
#[test]
fn absent_layer_kinds_count_equals_axis_cardinality_minus_present_layer_kinds_count() {
// The algebraic rearrangement: the coverage-gap size equals the
// axis cardinality minus the support size, useful for consumers
// that already hold the support-size scalar. Chain-altitude sub-
// axis peer of
// `absent_tiers_count_equals_axis_cardinality_minus_contributing_tiers_count`
// on the tier altitude.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_layer_kinds_count(),
axis_size - chain.as_slice().present_layer_kinds_count(),
);
}
}
#[test]
fn absent_layer_kinds_count_is_axis_cardinality_iff_chain_is_empty() {
// The empty-chain / full-coverage-gap boundary equivalence: an
// empty chain has every kind absent (the coverage gap is the
// whole axis), and a non-empty chain has at least one kind
// observed so the coverage-gap is strictly smaller. The scalar
// peer of `absent_layer_kinds_empty_chain_is_full_axis` and the
// chain-altitude sub-axis peer of
// `absent_tiers_count_is_axis_cardinality_iff_map_is_empty` on
// the tier altitude.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
let empty: Vec<ConfigSource> = Vec::new();
assert!(empty.is_empty());
assert_eq!(empty.as_slice().absent_layer_kinds_count(), axis_size);
for chain in [
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
] {
assert!(!chain.is_empty());
assert!(chain.as_slice().absent_layer_kinds_count() < axis_size);
}
}
#[test]
fn absent_layer_kinds_count_is_zero_iff_is_full_cover() {
// The full-cover boundary equivalence in coverage-gap form: the
// coverage gap is empty iff every layer kind contributed ≥1
// layer iff the histogram is full-cover. Chain-altitude sub-axis
// scalar-count coverage-gap peer of `AxisHistogram::is_full_cover`
// and peer of `absent_tiers_count_is_zero_iff_is_full_cover` on
// the tier altitude.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_layer_kinds_count() == 0,
chain.as_slice().layer_kind_histogram().is_full_cover(),
);
}
// Full-cover direct pin: a chain carrying one Defaults, one Env,
// one File is full-cover; the coverage-gap scalar reads zero.
let full_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
assert!(full_cover.as_slice().layer_kind_histogram().is_full_cover());
assert_eq!(full_cover.as_slice().absent_layer_kinds_count(), 0);
}
#[test]
fn absent_layer_kinds_count_is_bounded_by_axis_cardinality() {
// The upper-bound invariant: the coverage gap of a closed-axis
// histogram is at most the axis cardinality (the unobserved-
// cells set is a subset of `ConfigSourceKind::ALL`). Chain-
// altitude sub-axis peer of
// `absent_tiers_count_is_bounded_by_axis_cardinality` on the
// tier altitude.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert!(chain.as_slice().absent_layer_kinds_count() <= axis_size);
}
}
#[test]
fn absent_layer_kinds_count_is_at_least_one_when_not_full_cover() {
// A non-full-cover recipe carries at least one absent kind. The
// coverage-gap-side lower bound on non-full-cover, dual to
// `present_layer_kinds_count_is_at_least_one_on_nonempty_chain`
// on the observed side, and peer of
// `absent_tiers_count_is_at_least_one_when_not_full_cover` on
// the tier altitude.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
if chain.as_slice().layer_kind_histogram().is_full_cover() {
continue;
}
assert!(chain.as_slice().absent_layer_kinds_count() >= 1);
}
}
#[test]
fn absent_layer_kinds_count_is_axis_cardinality_minus_one_iff_has_singular_support() {
// The singleton-support boundary in coverage-gap form: when
// exactly one layer kind is observed, exactly `axis_cardinality
// - 1` are absent. Chain-altitude sub-axis coverage-gap peer of
// `present_layer_kinds_count_is_one_iff_has_singular_support`
// and `absent_tiers_count_is_axis_cardinality_minus_one_iff_has_singular_support`.
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
// Singleton-support: chains carrying layers of only one kind
// have exactly `axis_cardinality - 1` absent.
for singleton in [
vec![ConfigSource::Defaults, ConfigSource::Defaults],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
] {
assert!(
singleton
.as_slice()
.layer_kind_histogram()
.has_singular_support()
);
assert_eq!(
singleton.as_slice().absent_layer_kinds_count(),
axis_size - 1,
);
}
// Non-singleton-support: full-cover has zero absent (< axis_size - 1).
let full_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
assert!(
!full_cover
.as_slice()
.layer_kind_histogram()
.has_singular_support()
);
assert!(full_cover.as_slice().absent_layer_kinds_count() < axis_size - 1);
// Empty chain: coverage gap is the full axis (> axis_size - 1).
let empty: Vec<ConfigSource> = Vec::new();
assert!(
!empty
.as_slice()
.layer_kind_histogram()
.has_singular_support()
);
assert!(empty.as_slice().absent_layer_kinds_count() > axis_size - 1);
}
#[test]
fn absent_layer_kinds_count_agrees_with_open_coded_zero_walk() {
// Parity against the exact `ConfigSourceKind::ALL.iter().filter(|k|
// layer_kind_histogram().count(**k) == 0).count()` walk this
// lift replaces on the coverage-gap side. Chain-altitude sub-
// axis peer of `absent_tiers_count_agrees_with_open_coded_zero_walk`
// on the tier altitude.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let via_seam = chain.as_slice().absent_layer_kinds_count();
let hist = chain.as_slice().layer_kind_histogram();
let hand_rolled = ConfigSourceKind::ALL
.iter()
.copied()
.filter(|k| hist.count(*k) == 0)
.count();
assert_eq!(via_seam, hand_rolled);
}
}
#[test]
fn absent_layer_kinds_count_empty_chain_is_axis_cardinality() {
// Direct fixture pin: an empty chain has full coverage gap so
// `absent_layer_kinds_count` reads the axis cardinality
// (3 = |{Defaults, Env, File}|). Chain-altitude sub-axis peer
// of `absent_tiers_count_empty_map_is_axis_cardinality` on the
// tier altitude.
let empty: Vec<ConfigSource> = Vec::new();
assert_eq!(
empty.as_slice().absent_layer_kinds_count(),
crate::axis_cardinality::<ConfigSourceKind>(),
);
}
#[test]
fn absent_layer_kinds_count_full_cover_is_zero() {
// Direct fixture pin: a chain carrying one Defaults, one Env,
// one File covers every layer kind so the coverage-gap scalar
// reads 0. Chain-altitude sub-axis peer of
// `absent_tiers_count_full_cover_is_zero` on the tier altitude.
let full_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
assert_eq!(full_cover.as_slice().absent_layer_kinds_count(), 0);
}
#[test]
fn absent_layer_kinds_count_sample_chain_is_one() {
// Direct fixture pin: `sample_chain` covers two of three layer
// kinds (Env, File observed; Defaults absent), so the coverage-
// gap scalar reads 1. Coverage-gap peer of
// `present_layer_kinds_count_sample_chain_is_two` on the same
// fixture and altitude.
let chain = sample_chain();
assert_eq!(chain.as_slice().absent_layer_kinds_count(), 1);
}
#[test]
fn absent_layer_kinds_count_singleton_chain_is_two() {
// Direct fixture pin: a chain of a single layer covers exactly
// one kind, so the coverage-gap scalar reads `axis_cardinality
// - 1 = 2`. Cross-verified against
// `absent_layer_kinds_singleton_chain_yields_two_absent` (the
// Vec-peer counterpart).
let axis_size = crate::axis_cardinality::<ConfigSourceKind>();
for chain in [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
] {
assert_eq!(chain.as_slice().absent_layer_kinds_count(), axis_size - 1);
}
}
// ---- ConfigSourceChain::file_format_histogram ----
#[test]
fn file_format_histogram_counts_each_recognized_format_pointwise() {
// Concrete pin on the (chain → Format tally) projection on the
// file-axis sub-slice. `sample_chain()` is two `.yaml` File
// layers + one Env layer (no Defaults), so the histogram must
// read 2 Yaml, 0 Toml, 0 Lisp, 0 Nix. The Env layer projects
// to None through `file_format()` and contributes to no cell.
use crate::discovery::Format;
let chain = sample_chain();
let hist = chain.as_slice().file_format_histogram();
assert_eq!(hist.count(Format::Yaml), 2);
assert_eq!(hist.count(Format::Toml), 0);
assert_eq!(hist.count(Format::Lisp), 0);
assert_eq!(hist.count(Format::Nix), 0);
// total() equals the count of File entries with recognized
// extensions — here 2 (both `.yaml`).
assert_eq!(hist.total(), 2);
}
#[test]
fn file_format_histogram_covers_every_recognized_format() {
// A chain with one File entry per recognized format must
// produce a histogram with exactly one observation per Format
// cell — total equals Format::ALL cardinality. Pins the
// uniform-cover law on the file-format axis.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let hist = chain.as_slice().file_format_histogram();
for format in Format::ALL.iter().copied() {
assert_eq!(
hist.count(format),
1,
"uniform-cover chain must read 1 on every Format cell ({format:?})",
);
}
assert_eq!(hist.total(), Format::ALL.len());
}
#[test]
fn file_format_histogram_empty_chain_is_zero_on_every_cell() {
// Empty-chain law on the file-format axis: every cell reads
// zero, total is zero, is_empty() is true. Pins the monoid
// identity at the chain-shape boundary on the second
// chain-level histogram surface.
use crate::discovery::Format;
let chain: [ConfigSource; 0] = [];
let hist = chain.file_format_histogram();
for format in Format::ALL.iter().copied() {
assert_eq!(
hist.count(format),
0,
"empty chain must read zero on every Format cell ({format:?})",
);
}
assert_eq!(hist.total(), 0);
assert!(hist.is_empty());
}
#[test]
fn file_format_histogram_ignores_defaults_and_env_layers() {
// Defaults and Env entries carry no path and project to None
// through `file_format()`; they must not contribute to any
// Format cell regardless of how many chain entries of those
// kinds are present.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
let hist = chain.as_slice().file_format_histogram();
for format in Format::ALL.iter().copied() {
assert_eq!(
hist.count(format),
0,
"Defaults/Env-only chain must read zero on every Format cell ({format:?})",
);
}
assert_eq!(hist.total(), 0);
assert!(hist.is_empty());
}
#[test]
fn file_format_histogram_ignores_unrecognized_and_extensionless_files() {
// File entries whose extension is unrecognized or absent yield
// None through `file_format()` (the conservative TOML fallback
// in `with_file` does not declare a format on the recipe);
// they must not contribute to any Format cell. Pins the
// `None`-discipline pointwise.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/etc/cfg.unknownext")),
ConfigSource::File(PathBuf::from("/etc/no_extension")),
ConfigSource::File(PathBuf::from("/etc/.dotfile")),
];
let hist = chain.as_slice().file_format_histogram();
for format in Format::ALL.iter().copied() {
assert_eq!(
hist.count(format),
0,
"unrecognized-extension chain must read zero on {format:?}",
);
}
assert_eq!(hist.total(), 0);
}
#[test]
fn file_format_histogram_agrees_with_open_coded_per_format_count() {
// The lift collapses the per-cell
// `iter().filter_map(file_format).filter(|f| *f == X).count()`
// loop the typescape doc-strings promised — pin pointwise
// equivalence over the typed format axis across chains of
// mixed kinds, mixed formats, and mixed recognized/unrecognized
// extensions so a future regression in either side surfaces
// here.
use crate::discovery::Format;
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.lisp")),
ConfigSource::File(PathBuf::from("/e.unknownext")),
ConfigSource::Env("X_".to_owned()),
],
];
for chain in &chains {
let hist = chain.as_slice().file_format_histogram();
for format in Format::ALL.iter().copied() {
let manual = chain
.iter()
.filter_map(ConfigSource::file_format)
.filter(|f| *f == format)
.count();
assert_eq!(
hist.count(format),
manual,
"file_format_histogram({format:?}) must equal the open-coded \
filter_map+filter count over chain of length {}",
chain.len(),
);
}
}
}
#[test]
fn file_format_histogram_iter_yields_format_all_declaration_order() {
// The dense per-cell iteration must yield the Format::ALL
// declaration order (Yaml, Toml, Lisp, Nix) regardless of the
// chain's observation order — observation order does not leak
// into the histogram's value-side iteration. Peer to
// `layer_kind_histogram_iter_yields_declaration_order` on the
// ConfigSourceKind axis.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
];
let pairs: Vec<(Format, usize)> = chain.as_slice().file_format_histogram().iter().collect();
let values: Vec<Format> = pairs.iter().map(|(f, _)| *f).collect();
assert_eq!(values, Format::ALL.to_vec());
}
#[test]
fn file_format_histogram_equals_axis_histogram_over_file_format_projection() {
// Pin equivalence to the generic
// `crate::axis_histogram(self.iter().filter_map(ConfigSource::file_format))`
// shape the trait-default method routes through — the lift
// must not silently re-implement the per-cell count loop on a
// parallel surface. Pointwise equality on every Format cell.
use crate::discovery::Format;
let chains = [
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/x.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.unknownext")),
ConfigSource::Env("E_".to_owned()),
],
];
for chain in &chains {
let lifted = chain.as_slice().file_format_histogram();
let generic = crate::axis_histogram(chain.iter().filter_map(ConfigSource::file_format));
for format in Format::ALL.iter().copied() {
assert_eq!(
lifted.count(format),
generic.count(format),
"file_format_histogram must equal \
axis_histogram(file_format-projection) on {format:?} \
over chain of length {}",
chain.len(),
);
}
}
}
#[test]
fn file_format_histogram_total_bounded_by_file_layer_count() {
// Cross-histogram invariant: the file-format histogram's total
// is at most the layer-kind histogram's count of File entries,
// since `file_format()` projects only `File` layers to `Some`
// (and even then only when the extension is recognized). The
// strict inequality happens exactly when some `File` layer
// carries an unrecognized or absent extension. Pins the
// structural relationship between the two chain-level
// histograms the trait now exposes.
let chains: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Env("E_".to_owned())],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.unknownext")),
ConfigSource::File(PathBuf::from("/c.no_extension")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
];
for chain in &chains {
let file_kind_count = chain
.as_slice()
.layer_kind_histogram()
.count(ConfigSourceKind::File);
let format_total = chain.as_slice().file_format_histogram().total();
assert!(
format_total <= file_kind_count,
"file_format_histogram total ({format_total}) must be at most \
layer_kind_histogram(File) ({file_kind_count}) over chain of length {}",
chain.len(),
);
}
// Equality case: every File layer carries a recognized
// extension — the bound is tight on the uniform-cover chain.
let uniform = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let file_kind_count = uniform
.as_slice()
.layer_kind_histogram()
.count(ConfigSourceKind::File);
let format_total = uniform.as_slice().file_format_histogram().total();
assert_eq!(
format_total, file_kind_count,
"uniform-cover chain: file_format_histogram total must equal \
layer_kind_histogram(File)",
);
// Strict-inequality case: at least one File layer carries an
// unrecognized extension — the bound is strict.
let mixed = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.unknownext")),
];
let file_kind_count = mixed
.as_slice()
.layer_kind_histogram()
.count(ConfigSourceKind::File);
let format_total = mixed.as_slice().file_format_histogram().total();
assert!(
format_total < file_kind_count,
"mixed-extension chain: file_format_histogram total ({format_total}) \
must be strictly less than layer_kind_histogram(File) ({file_kind_count})",
);
}
// ---- ConfigSourceChain::present_file_formats — observed-cells
// peer of ConfigSourceChain::file_format_histogram on the
// chain-shape altitude ----
#[test]
fn present_file_formats_matches_file_format_histogram_observed_pointwise() {
// The observed-support pin: `present_file_formats` routes
// through `file_format_histogram().observed().collect()`, so
// the two seams must stay pointwise equivalent under every
// fixture. Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive.
// Sister of `present_layer_kinds_matches_layer_kind_histogram_observed_pointwise`
// one axis over.
use crate::discovery::Format;
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.unknown")),
],
];
for chain in &fixtures {
let via_direct = chain.as_slice().present_file_formats();
let via_histogram: Vec<Format> = chain
.as_slice()
.file_format_histogram()
.observed()
.collect();
assert_eq!(
via_direct,
via_histogram,
"present_file_formats must equal \
file_format_histogram().observed().collect() pointwise \
over chain of length {}",
chain.len(),
);
}
}
#[test]
fn present_file_formats_empty_chain_is_empty() {
// Empty-chain boundary: no entries, no observed formats. Sister
// of `present_layer_kinds_empty_chain_is_empty` on the file-
// format axis. Note the presence bound diverges from
// present_layer_kinds: a chain of only Defaults / Env / bad-
// extension File entries is non-empty but has no present
// formats — the file_format_histogram-emptiness law asserted
// in the separate `_no_recognized_files_is_empty` test below.
use crate::discovery::Format;
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.present_file_formats().is_empty());
assert_eq!(empty.present_file_formats(), Vec::<Format>::new());
}
#[test]
fn present_file_formats_no_recognized_files_is_empty() {
// Presence-bound pin distinguishing this peer from
// `present_layer_kinds`: a non-empty chain of Defaults, Env,
// and unrecognized-extension File layers all project to None
// through file_format(), so present_file_formats() is empty
// even though the chain is not. Reads the histogram-empty law
// documented in the trait doc-string.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b")),
];
assert!(!chain.is_empty());
assert!(chain.as_slice().file_format_histogram().is_empty());
assert!(chain.as_slice().present_file_formats().is_empty());
assert_eq!(
chain.as_slice().present_file_formats(),
Vec::<Format>::new()
);
}
#[test]
fn present_file_formats_iterates_in_declaration_order() {
// Declaration-order pin: even when the observation order is
// Nix → Lisp → Toml → Yaml (the reverse of ::ALL), the returned
// Vec walks the closed axis in canonical
// (Yaml → Toml → Lisp → Nix) order — the closed-axis discipline
// provides the sort automatically. Sister of
// `present_layer_kinds_iterates_in_declaration_order` on the
// file-format axis.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/d.nix")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
assert_eq!(
chain.as_slice().present_file_formats(),
vec![Format::Yaml, Format::Toml, Format::Lisp, Format::Nix],
);
}
#[test]
fn present_file_formats_dedups_across_repeated_observations() {
// Repeated observations of the same format collapse to one
// entry in the returned Vec — the closed-axis discipline
// provides dedup automatically. Six file layers split
// (3 Yaml × 2 Toml × 1 Nix) yield three present formats.
// Sister of `present_layer_kinds_dedups_across_repeated_observations`
// on the file-format axis.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.toml")),
ConfigSource::File(PathBuf::from("/e.toml")),
ConfigSource::File(PathBuf::from("/f.nix")),
];
assert_eq!(
chain.as_slice().present_file_formats(),
vec![Format::Yaml, Format::Toml, Format::Nix],
);
}
#[test]
fn present_file_formats_singleton_chain_yields_singleton_support() {
// A chain composed only of one file-format kind has exactly
// that format as its present-formats set — the support is the
// singleton observed cell. Boundary case pinning that
// unobserved cells do not leak into the returned Vec (the
// closed-axis discipline drops zero-count cells) — one
// fixture per Format::ALL cell.
use crate::discovery::Format;
for (format, path) in [
(Format::Yaml, "/a.yaml"),
(Format::Toml, "/a.toml"),
(Format::Lisp, "/a.lisp"),
(Format::Nix, "/a.nix"),
] {
let chain = vec![
ConfigSource::File(PathBuf::from(path)),
ConfigSource::File(PathBuf::from(path)),
];
assert_eq!(
chain.as_slice().present_file_formats(),
vec![format],
"singleton-support chain over {format:?} must yield \
that single format",
);
}
}
#[test]
fn present_file_formats_len_matches_distinct_cells() {
// Support-cardinality invariant:
// `present_file_formats().len()` equals
// `file_format_histogram().distinct_cells()` pointwise. Both
// project the observed-cell count off the shared histogram
// over the Format closed axis. Sister of
// `present_layer_kinds_len_matches_distinct_cells` one axis
// over.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_file_formats().len(),
chain.as_slice().file_format_histogram().distinct_cells(),
"present_file_formats().len() must equal \
file_format_histogram().distinct_cells() over chain of length {}",
chain.len(),
);
}
}
#[test]
fn present_file_formats_full_cover_matches_axis_cardinality() {
// Cross-surface pin on the full-cover predicate: a chain whose
// `file_format_histogram().is_full_cover()` returns `true` has
// exactly `crate::axis_cardinality::<Format>()` observed
// cells, and `present_file_formats()` returns `Format::ALL` in
// declaration order.
use crate::discovery::Format;
let axis_cover = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
assert!(
axis_cover
.as_slice()
.file_format_histogram()
.is_full_cover()
);
assert_eq!(
axis_cover.as_slice().present_file_formats().len(),
crate::axis_cardinality::<Format>(),
);
assert_eq!(
axis_cover.as_slice().present_file_formats(),
Format::ALL.to_vec(),
);
// Strict-subset case: sample_chain has two `.yaml` files and
// no toml / lisp / nix, so it is NOT a full cover, and the
// present-formats cardinality is strictly less than the axis
// cardinality.
let chain = sample_chain();
assert!(!chain.as_slice().file_format_histogram().is_full_cover());
assert!(
chain.as_slice().present_file_formats().len() < crate::axis_cardinality::<Format>(),
);
}
#[test]
fn present_file_formats_is_strictly_ascending_by_axis_ordinal() {
// Structural-sort pin: the returned Vec is strictly ascending
// by `crate::axis_ordinal` on Format — dedup + sort for free
// from the closed-axis discipline. Every consecutive pair in
// the returned Vec has strictly increasing axis ordinal.
// Sister of `present_layer_kinds_is_strictly_ascending_by_axis_ordinal`
// one axis over.
let chain = vec![
ConfigSource::File(PathBuf::from("/d.nix")),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/e.yaml")),
];
let present = chain.as_slice().present_file_formats();
for window in present.windows(2) {
let a = crate::axis_ordinal(window[0]);
let b = crate::axis_ordinal(window[1]);
assert!(
a < b,
"present_file_formats must be strictly ascending by \
axis_ordinal, but ord({:?})={a} >= ord({:?})={b}",
window[0],
window[1],
);
}
}
#[test]
fn present_file_formats_agrees_with_open_coded_dedup_walk() {
// Parity pin against a hand-rolled `Vec::contains` + sort_by_key
// consumer — the exact pattern the trait-level lift replaces.
// Any future divergence (e.g. `observed()` changing its
// iteration order, `file_format_histogram` projecting through
// a different file_format function) surfaces here as a
// structural mismatch between the lifted seam and the open-
// coded walk.
use crate::discovery::Format;
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.nix")),
ConfigSource::File(PathBuf::from("/d.unknown")),
],
vec![
ConfigSource::File(PathBuf::from("/a.lisp")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.toml")),
ConfigSource::File(PathBuf::from("/e.nix")),
],
];
for chain in &chains {
let lifted = chain.as_slice().present_file_formats();
let mut manual: Vec<Format> = Vec::new();
for source in chain {
if let Some(f) = source.file_format()
&& !manual.contains(&f)
{
manual.push(f);
}
}
manual.sort_by_key(|f| crate::axis_ordinal(*f));
assert_eq!(
lifted,
manual,
"present_file_formats must equal the open-coded \
contains+sort walk over chain of length {}",
chain.len(),
);
}
}
// ---- ConfigSourceChain::present_file_formats_count — support-size
// scalar peer of present_file_formats on the file-format sub-axis
// of the chain altitude ----
#[test]
fn present_file_formats_count_matches_file_format_histogram_distinct_cells_pointwise() {
// The support-size pin: `present_file_formats_count` routes
// through `file_format_histogram().distinct_cells()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. File-
// format-sub-axis peer of
// `present_layer_kinds_count_matches_layer_kind_histogram_distinct_cells_pointwise`
// on the layer-kind sub-axis of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![ConfigSource::Defaults, ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.unknown")),
],
];
for chain in &fixtures {
let via_histogram = chain.as_slice().file_format_histogram().distinct_cells();
assert_eq!(
chain.as_slice().present_file_formats_count(),
via_histogram,
"present_file_formats_count must equal \
file_format_histogram().distinct_cells() over chain of \
length {}",
chain.len(),
);
}
}
#[test]
fn present_file_formats_count_equals_present_file_formats_len_pointwise() {
// The Vec-peer identity: the scalar-count seam equals the length
// of the observed-cells `Vec` peer. Any future re-implementation
// of either seam must keep this equality — pinned uniformly.
// File-format-sub-axis peer of
// `present_layer_kinds_count_equals_present_layer_kinds_len_pointwise`
// on the layer-kind sub-axis of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.unknown")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_file_formats_count(),
chain.as_slice().present_file_formats().len(),
);
}
}
#[test]
fn present_file_formats_count_and_absent_file_formats_len_partition_axis_cardinality() {
// The partition law: the scalar dual of
// `absent_file_formats_and_present_file_formats_partition_axis`.
// Every file-format cell lies in exactly one of (observed,
// unobserved), so the scalar-count peers of the two Vec peers
// sum to the axis cardinality. File-format-sub-axis peer of
// `present_layer_kinds_count_and_absent_layer_kinds_len_partition_axis_cardinality`
// on the layer-kind sub-axis of the same chain altitude.
let axis_size = crate::axis_cardinality::<crate::discovery::Format>();
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.unknown")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_file_formats_count()
+ chain.as_slice().absent_file_formats().len(),
axis_size,
"partition must sum to axis cardinality over chain of length {}",
chain.len(),
);
}
}
#[test]
fn present_file_formats_count_is_zero_iff_file_format_histogram_is_empty() {
// The empty-boundary equivalence: the file-format-sub-axis's
// divergence from the layer-kind sub-axis — the zero boundary
// is the histogram's own emptiness, NOT the chain's. A
// non-empty chain of only Defaults / Env / unrecognized-
// extension File layers reads zero because every entry
// projects to None through `file_format()`. File-format-sub-
// axis peer of
// `present_layer_kinds_count_is_zero_iff_chain_is_empty` on
// the layer-kind sub-axis (whose zero boundary is the chain's
// is_empty).
// Empty chain: histogram empty, support zero.
let empty: Vec<ConfigSource> = Vec::new();
assert!(empty.as_slice().file_format_histogram().is_empty());
assert_eq!(empty.as_slice().present_file_formats_count(), 0);
// Non-empty chain, empty histogram: support still zero — the
// load-bearing divergence from the layer-kind sub-axis.
let no_recognized = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.unknown")),
];
assert!(!no_recognized.is_empty());
assert!(no_recognized.as_slice().file_format_histogram().is_empty());
assert_eq!(no_recognized.as_slice().present_file_formats_count(), 0);
// Non-empty histogram: support strictly positive.
let chain = sample_chain();
assert!(!chain.as_slice().file_format_histogram().is_empty());
assert!(chain.as_slice().present_file_formats_count() > 0);
}
#[test]
fn present_file_formats_count_is_at_least_one_on_nonempty_histogram() {
// The lower-bound invariant on the non-empty-histogram side:
// whenever the file-format histogram carries at least one
// observation, the support is at least the singleton of that
// observed cell. File-format-sub-axis peer of
// `present_layer_kinds_count_is_at_least_one_on_nonempty_chain`
// on the layer-kind sub-axis — pinned against the histogram's
// own emptiness rather than the chain's.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
];
for chain in &fixtures {
assert!(!chain.as_slice().file_format_histogram().is_empty());
assert!(chain.as_slice().present_file_formats_count() >= 1);
}
}
#[test]
fn present_file_formats_count_is_bounded_by_axis_cardinality() {
// The upper-bound invariant: the support of a closed-axis
// histogram is at most the axis cardinality (the observed-
// cells set is a subset of `Format::ALL`). File-format-sub-
// axis peer of
// `present_layer_kinds_count_is_bounded_by_axis_cardinality`
// on the layer-kind sub-axis of the same chain altitude.
let axis_size = crate::axis_cardinality::<crate::discovery::Format>();
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
],
];
for chain in &fixtures {
assert!(chain.as_slice().present_file_formats_count() <= axis_size);
}
}
#[test]
fn present_file_formats_count_is_bounded_by_file_format_histogram_total() {
// The support ≤ total invariant: every distinct cell contributes
// at least one observation to the total, so the support size is
// bounded above by the total observation count. File-format-sub-
// axis peer of
// `present_layer_kinds_count_is_bounded_by_layer_kind_histogram_total`
// on the layer-kind sub-axis of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
];
for chain in &fixtures {
assert!(
chain.as_slice().present_file_formats_count()
<= chain.as_slice().file_format_histogram().total(),
);
}
}
#[test]
fn present_file_formats_count_equals_axis_cardinality_iff_is_full_cover() {
// The full-cover boundary equivalence: the support size equals
// the axis cardinality iff every file format contributed ≥1
// entry iff the coverage gap is empty. File-format-sub-axis
// peer of
// `present_layer_kinds_count_equals_axis_cardinality_iff_is_full_cover`
// on the layer-kind sub-axis of the same chain altitude.
let axis_size = crate::axis_cardinality::<crate::discovery::Format>();
// Full-cover: one file per format.
let axis_cover = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
assert!(
axis_cover
.as_slice()
.file_format_histogram()
.is_full_cover()
);
assert!(axis_cover.as_slice().absent_file_formats().is_empty());
assert_eq!(
axis_cover.as_slice().present_file_formats_count(),
axis_size,
);
// Strict-subset: sample_chain has only .yaml files, so full-
// cover is false and the support size is strictly less than
// axis size.
let chain = sample_chain();
assert!(!chain.as_slice().file_format_histogram().is_full_cover());
assert!(chain.as_slice().present_file_formats_count() < axis_size);
}
#[test]
fn present_file_formats_count_is_one_iff_has_singular_support() {
// The singleton-support boundary equivalence: the support size
// equals 1 iff exactly one file format contributed iff the
// histogram has singular support. File-format-sub-axis peer of
// `present_layer_kinds_count_is_one_iff_has_singular_support`
// on the layer-kind sub-axis of the same chain altitude.
let yaml_only = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
assert!(
yaml_only
.as_slice()
.file_format_histogram()
.has_singular_support()
);
assert_eq!(yaml_only.as_slice().present_file_formats_count(), 1);
let nix_only = vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::File(PathBuf::from("/c.nix")),
];
assert!(
nix_only
.as_slice()
.file_format_histogram()
.has_singular_support()
);
assert_eq!(nix_only.as_slice().present_file_formats_count(), 1);
// Multi-format chain spans two formats, so singular-support
// reads false and the support size is > 1.
let mixed = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
assert!(
!mixed
.as_slice()
.file_format_histogram()
.has_singular_support()
);
assert!(mixed.as_slice().present_file_formats_count() > 1);
}
#[test]
fn present_file_formats_count_of_one_implies_dominant_equals_recessive() {
// The support-collapse degenerate: a singleton-support recipe
// has the modal and anti-modal cells coincide on the sole
// observed format. File-format-sub-axis peer of
// `present_layer_kinds_count_of_one_implies_dominant_equals_recessive`
// on the layer-kind sub-axis of the same chain altitude.
let yaml_only = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
assert_eq!(yaml_only.as_slice().present_file_formats_count(), 1);
assert_eq!(
yaml_only.as_slice().dominant_file_format(),
yaml_only.as_slice().recessive_file_format(),
);
let toml_only = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
assert_eq!(toml_only.as_slice().present_file_formats_count(), 1);
assert_eq!(
toml_only.as_slice().dominant_file_format(),
toml_only.as_slice().recessive_file_format(),
);
let lisp_only = vec![ConfigSource::File(PathBuf::from("/a.lisp"))];
assert_eq!(lisp_only.as_slice().present_file_formats_count(), 1);
assert_eq!(
lisp_only.as_slice().dominant_file_format(),
lisp_only.as_slice().recessive_file_format(),
);
}
#[test]
fn present_file_formats_count_agrees_with_open_coded_nonzero_walk() {
// Parity against the exact
// `Format::ALL.iter().filter(|f|
// file_format_histogram().count(*f) > 0).count()` walk this
// lift replaces. File-format-sub-axis peer of
// `present_layer_kinds_count_agrees_with_open_coded_nonzero_walk`
// on the layer-kind sub-axis of the same chain altitude.
use crate::discovery::Format;
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.unknown")),
],
];
for chain in &fixtures {
let via_seam = chain.as_slice().present_file_formats_count();
let hist = chain.as_slice().file_format_histogram();
let hand_rolled = Format::ALL.iter().filter(|f| hist.count(**f) > 0).count();
assert_eq!(via_seam, hand_rolled);
}
}
#[test]
fn present_file_formats_count_sample_chain_is_one() {
// Direct fixture pin: sample_chain has two `.yaml` File layers
// and one Env, so present_file_formats_count reads 1 (only
// Yaml observed; Toml / Lisp / Nix absent).
let chain = sample_chain();
assert_eq!(chain.as_slice().present_file_formats_count(), 1);
}
#[test]
fn present_file_formats_count_full_cover_is_axis_cardinality() {
// Direct fixture pin: a chain covering every file format reads
// the axis cardinality (4 = |{Yaml, Toml, Lisp, Nix}|).
let axis_cover = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
assert_eq!(
axis_cover.as_slice().present_file_formats_count(),
crate::axis_cardinality::<crate::discovery::Format>(),
);
}
#[test]
fn present_file_formats_count_no_recognized_files_is_zero() {
// Direct fixture pin on the file-format sub-axis's divergent
// boundary: a non-empty chain of only Defaults, Env, and
// unrecognized-extension File layers reads zero because every
// entry projects to None through `file_format()`. Companion to
// `present_file_formats_no_recognized_files_is_empty` on the
// observed-cells Vec peer.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b")),
];
assert!(!chain.is_empty());
assert!(chain.as_slice().file_format_histogram().is_empty());
assert_eq!(chain.as_slice().present_file_formats_count(), 0);
}
// ---- ConfigSourceChain::absent_file_formats — unobserved-cells
// peer of present_file_formats on the chain-shape altitude ----
#[test]
fn absent_file_formats_matches_file_format_histogram_unobserved_pointwise() {
// The coverage-gap pin: `absent_file_formats` routes through
// `file_format_histogram().unobserved().collect()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Sister of
// `absent_layer_kinds_matches_layer_kind_histogram_unobserved_pointwise`
// one axis over on the same chain-shape surface.
use crate::discovery::Format;
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.unknown")),
],
];
for chain in &fixtures {
let via_direct = chain.as_slice().absent_file_formats();
let via_histogram: Vec<Format> = chain
.as_slice()
.file_format_histogram()
.unobserved()
.collect();
assert_eq!(
via_direct,
via_histogram,
"absent_file_formats must equal \
file_format_histogram().unobserved().collect() pointwise \
over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_file_formats_empty_chain_is_full_axis() {
// An empty chain has no observed formats — every cell of
// `Format::ALL` lies in the coverage gap. Sister of
// `absent_layer_kinds_empty_chain_is_full_axis` one axis over
// on the same chain-shape surface.
use crate::discovery::Format;
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.absent_file_formats(), Format::ALL.to_vec(),);
}
#[test]
fn absent_file_formats_no_recognized_files_is_full_axis() {
// Presence-bound divergence from `absent_layer_kinds` — the
// chain is non-empty but every entry projects to None through
// `file_format()`, so the histogram is empty and every axis
// cell is absent. Peer of
// `present_file_formats_no_recognized_files_is_empty` on the
// coverage-gap side: a non-empty chain of Defaults, Env, and
// unrecognized-extension File layers has the full file-format
// axis as its coverage gap.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b")),
];
assert!(!chain.is_empty());
assert!(chain.as_slice().file_format_histogram().is_empty());
assert_eq!(chain.as_slice().absent_file_formats(), Format::ALL.to_vec(),);
}
#[test]
fn absent_file_formats_iterates_in_declaration_order() {
// The coverage-gap iter walks `Format::ALL` in declaration
// order (`Yaml → Toml → Lisp → Nix`) and yields only the cells
// with zero count. Pinned here on the empty chain, whose gap
// is the entire axis — the emitted order matches `Format::ALL`
// verbatim.
use crate::discovery::Format;
let empty: [ConfigSource; 0] = [];
assert_eq!(
empty.absent_file_formats(),
vec![Format::Yaml, Format::Toml, Format::Lisp, Format::Nix],
);
}
#[test]
fn absent_file_formats_yaml_only_chain_is_toml_lisp_nix() {
// A chain composed only of `.yaml` file layers has exactly
// { Toml, Lisp, Nix } as its coverage gap — the non-Yaml
// subset of the axis is entirely absent. Operator-facing pin
// on the "yaml-only recipe" — the common shikumi default
// where discovery locates only `.yaml` config files.
use crate::discovery::Format;
let yaml_only = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
assert_eq!(
yaml_only.as_slice().absent_file_formats(),
vec![Format::Toml, Format::Lisp, Format::Nix],
);
}
#[test]
fn absent_file_formats_toml_only_chain_is_yaml_lisp_nix() {
// A chain composed only of `.toml` file layers has exactly
// { Yaml, Lisp, Nix } as its coverage gap. Boundary pin on
// the "toml-only recipe" — the closed-axis discipline emits
// in declaration order regardless of observation order.
use crate::discovery::Format;
let toml_only = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
assert_eq!(
toml_only.as_slice().absent_file_formats(),
vec![Format::Yaml, Format::Lisp, Format::Nix],
);
}
#[test]
fn absent_file_formats_len_matches_unobserved_cells() {
// The coverage-gap-cardinality invariant on the histogram's
// support / gap partition:
// `absent_file_formats().len()` equals
// `file_format_histogram().unobserved_cells()` pointwise across
// every fixture. Sister of
// `absent_layer_kinds_len_matches_unobserved_cells` one axis
// over.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_file_formats().len(),
chain.as_slice().file_format_histogram().unobserved_cells(),
"absent_file_formats().len() must equal \
file_format_histogram().unobserved_cells() over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_file_formats_and_present_file_formats_partition_axis() {
// The support / coverage-gap partition on the closed axis:
// every cell of `Format::ALL` lies in exactly one of
// (observed, unobserved), so the two Vec lengths sum to the
// axis cardinality. Sister of
// `absent_layer_kinds_and_present_layer_kinds_partition_axis`
// one axis over.
use crate::discovery::Format;
let axis_size = crate::axis_cardinality::<Format>();
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.unknown")),
],
];
for chain in &fixtures {
let observed = chain.as_slice().present_file_formats();
let absent = chain.as_slice().absent_file_formats();
assert_eq!(observed.len() + absent.len(), axis_size);
for format in &observed {
assert!(
!absent.contains(format),
"format {format:?} appears in both present and absent \
over chain of length {}",
chain.len(),
);
}
for cell in Format::ALL {
assert!(
observed.contains(cell) || absent.contains(cell),
"format {cell:?} appears in neither present nor absent \
over chain of length {}",
chain.len(),
);
}
}
}
#[test]
fn absent_file_formats_is_empty_iff_is_full_cover() {
// The coverage-gap is empty iff every file format was observed
// at least once. Pinned across every fixture in the module
// against `file_format_histogram().is_full_cover()`, plus a
// direct positive pin: a chain carrying one `.yaml` + one
// `.toml` + one `.lisp` + one `.nix` is full-cover; the
// coverage-gap is empty.
use crate::discovery::Format;
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_file_formats().is_empty(),
chain.as_slice().file_format_histogram().is_full_cover(),
);
}
let full_cover = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
assert!(
full_cover
.as_slice()
.file_format_histogram()
.is_full_cover()
);
assert_eq!(
full_cover.as_slice().absent_file_formats(),
Vec::<Format>::new(),
);
assert_eq!(
full_cover.as_slice().present_file_formats(),
Format::ALL.to_vec(),
);
}
#[test]
fn absent_file_formats_is_strictly_ascending_by_axis_ordinal() {
// Structural sort pin: the coverage-gap walks the closed axis
// in declaration order, so `absent_file_formats()` is strictly
// ascending by `crate::axis_ordinal` — dedup + sort for free
// from the closed-axis discipline. Sister of
// `absent_layer_kinds_is_strictly_ascending_by_axis_ordinal`
// one axis over.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.nix")),
],
];
for chain in &fixtures {
let absent = chain.as_slice().absent_file_formats();
for pair in absent.windows(2) {
assert!(
crate::axis_ordinal(pair[0]) < crate::axis_ordinal(pair[1]),
"absent_file_formats must be strictly ascending: {absent:?}",
);
}
}
}
#[test]
fn absent_file_formats_singleton_chain_yields_three_absent() {
// A chain of a single recognized-extension file layer has
// exactly `axis_cardinality - 1` absent formats — every axis
// cell except the one carried by that layer. Sister of
// `absent_layer_kinds_singleton_chain_yields_two_absent` one
// axis over (the file-format axis carries cardinality four,
// so the singleton coverage-gap has three cells, not two).
use crate::discovery::Format;
let axis_size = crate::axis_cardinality::<Format>();
for (source, present_format) in [
(ConfigSource::File(PathBuf::from("/a.yaml")), Format::Yaml),
(ConfigSource::File(PathBuf::from("/a.toml")), Format::Toml),
(ConfigSource::File(PathBuf::from("/a.lisp")), Format::Lisp),
(ConfigSource::File(PathBuf::from("/a.nix")), Format::Nix),
] {
let chain = vec![source];
let absent = chain.as_slice().absent_file_formats();
assert_eq!(absent.len(), axis_size - 1);
assert!(
!absent.contains(&present_format),
"the observed format {present_format:?} must not appear in \
the coverage gap",
);
for cell in Format::ALL {
if *cell != present_format {
assert!(
absent.contains(cell),
"the singleton chain's coverage gap must contain \
every non-observed axis cell — missing {cell:?}",
);
}
}
}
}
#[test]
fn absent_file_formats_agrees_with_open_coded_coverage_gap_walk() {
// Parity against the exact `Format::ALL.iter().filter(|f|
// !present_file_formats().contains(f))` walk this lift
// replaces — both the named seam and the hand-rolled coverage-
// gap must pointwise agree over every fixture. Sister of
// `absent_layer_kinds_agrees_with_open_coded_coverage_gap_walk`
// one axis over.
use crate::discovery::Format;
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.nix")),
ConfigSource::File(PathBuf::from("/d.unknown")),
],
vec![
ConfigSource::File(PathBuf::from("/a.lisp")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.toml")),
ConfigSource::File(PathBuf::from("/e.nix")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
];
for chain in &chains {
let lifted = chain.as_slice().absent_file_formats();
let present = chain.as_slice().present_file_formats();
let manual: Vec<Format> = Format::ALL
.iter()
.copied()
.filter(|f| !present.contains(f))
.collect();
assert_eq!(
lifted,
manual,
"absent_file_formats must equal the open-coded \
coverage-gap walk over chain of length {}",
chain.len(),
);
}
}
// ---- ConfigSourceChain::absent_file_formats_count — coverage-gap-
// size scalar peer on the file-format sub-axis of the chain
// altitude ----
#[test]
fn absent_file_formats_count_matches_file_format_histogram_unobserved_cells_pointwise() {
// The coverage-gap-size pin: `absent_file_formats_count` routes
// through `file_format_histogram().unobserved_cells()`, so the two
// seams must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops projecting
// through the shared cube-native primitive. File-format-sub-axis
// peer of
// `absent_layer_kinds_count_matches_layer_kind_histogram_unobserved_cells_pointwise`
// on the layer-kind sub-axis of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![ConfigSource::Defaults, ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.unknown")),
],
];
for chain in &fixtures {
let via_histogram = chain.as_slice().file_format_histogram().unobserved_cells();
assert_eq!(
chain.as_slice().absent_file_formats_count(),
via_histogram,
"absent_file_formats_count must equal \
file_format_histogram().unobserved_cells() pointwise \
over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_file_formats_count_equals_absent_file_formats_len_pointwise() {
// The Vec-peer identity: the scalar-count seam equals the length
// of the coverage-gap `Vec` peer. Any future re-implementation of
// either seam must keep this equality — pinned uniformly. File-
// format-sub-axis peer of
// `absent_layer_kinds_count_equals_absent_layer_kinds_len_pointwise`
// on the layer-kind sub-axis of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.unknown")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_file_formats_count(),
chain.as_slice().absent_file_formats().len(),
);
}
}
#[test]
fn present_file_formats_count_and_absent_file_formats_count_partition_axis_cardinality() {
// The fully-scalar partition law: both sides now the scalar-count
// peers, no `.len()` on either. Every file-format cell lies in
// exactly one of (observed, unobserved). The scalar dual of
// `absent_file_formats_and_present_file_formats_partition_axis`
// closed on both sides. Sits alongside
// `present_file_formats_count_and_absent_file_formats_len_partition_axis_cardinality`
// which still uses `.len()` on the coverage-gap side. File-format-
// sub-axis peer of
// `present_layer_kinds_count_and_absent_layer_kinds_count_partition_axis_cardinality`
// on the layer-kind sub-axis of the same chain altitude.
let axis_size = crate::axis_cardinality::<crate::discovery::Format>();
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.unknown")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_file_formats_count()
+ chain.as_slice().absent_file_formats_count(),
axis_size,
"fully-scalar partition must sum to axis cardinality \
over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_file_formats_count_equals_axis_cardinality_minus_present_file_formats_count() {
// The algebraic rearrangement: the coverage-gap size equals the
// axis cardinality minus the support size, useful for consumers
// that already hold the support-size scalar. File-format-sub-
// axis peer of
// `absent_layer_kinds_count_equals_axis_cardinality_minus_present_layer_kinds_count`
// on the layer-kind sub-axis of the same chain altitude.
let axis_size = crate::axis_cardinality::<crate::discovery::Format>();
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_file_formats_count(),
axis_size - chain.as_slice().present_file_formats_count(),
);
}
}
#[test]
fn absent_file_formats_count_is_axis_cardinality_iff_file_format_histogram_is_empty() {
// The empty-histogram / full-coverage-gap boundary equivalence:
// the file-format-sub-axis's divergence from the layer-kind sub-
// axis — the full-axis boundary is tied to the histogram's own
// emptiness, NOT the chain's. Unlike
// `absent_layer_kinds_count_is_axis_cardinality_iff_chain_is_empty`,
// a non-empty chain of only Defaults / Env / unrecognized-extension
// File layers still reads the axis cardinality because every entry
// projects to None through `file_format()`.
let axis_size = crate::axis_cardinality::<crate::discovery::Format>();
// Empty chain: histogram empty, coverage-gap full.
let empty: Vec<ConfigSource> = Vec::new();
assert!(empty.as_slice().file_format_histogram().is_empty());
assert_eq!(empty.as_slice().absent_file_formats_count(), axis_size);
// Non-empty chain, empty histogram: coverage-gap still full —
// the load-bearing divergence from the layer-kind sub-axis.
let no_recognized = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.unknown")),
];
assert!(!no_recognized.is_empty());
assert!(no_recognized.as_slice().file_format_histogram().is_empty());
assert_eq!(
no_recognized.as_slice().absent_file_formats_count(),
axis_size,
);
// Non-empty histogram: coverage-gap strictly less than full.
let chain = sample_chain();
assert!(!chain.as_slice().file_format_histogram().is_empty());
assert!(chain.as_slice().absent_file_formats_count() < axis_size);
}
#[test]
fn absent_file_formats_count_is_zero_iff_is_full_cover() {
// The full-cover boundary equivalence in coverage-gap form: the
// coverage gap is empty iff every file format contributed ≥1
// recognized file layer iff the histogram is full-cover. File-
// format-sub-axis scalar-count coverage-gap peer of
// `AxisHistogram::is_full_cover` and peer of
// `absent_layer_kinds_count_is_zero_iff_is_full_cover` on the
// layer-kind sub-axis of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_file_formats_count() == 0,
chain.as_slice().file_format_histogram().is_full_cover(),
);
}
// Full-cover direct pin: one file per format is full-cover; the
// coverage-gap scalar reads zero.
let full_cover = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
assert!(
full_cover
.as_slice()
.file_format_histogram()
.is_full_cover()
);
assert_eq!(full_cover.as_slice().absent_file_formats_count(), 0);
}
#[test]
fn absent_file_formats_count_is_bounded_by_axis_cardinality() {
// The upper-bound invariant: the coverage gap of a closed-axis
// histogram is at most the axis cardinality (the unobserved-cells
// set is a subset of `Format::ALL`). File-format-sub-axis peer of
// `absent_layer_kinds_count_is_bounded_by_axis_cardinality` on
// the layer-kind sub-axis of the same chain altitude.
let axis_size = crate::axis_cardinality::<crate::discovery::Format>();
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
],
];
for chain in &fixtures {
assert!(chain.as_slice().absent_file_formats_count() <= axis_size);
}
}
#[test]
fn absent_file_formats_count_is_at_least_one_when_not_full_cover() {
// A non-full-cover recipe carries at least one absent format. The
// coverage-gap-side lower bound on non-full-cover, dual to
// `present_file_formats_count_is_at_least_one_on_nonempty_histogram`
// on the observed side, and peer of
// `absent_layer_kinds_count_is_at_least_one_when_not_full_cover`
// on the layer-kind sub-axis of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
],
];
for chain in &fixtures {
if chain.as_slice().file_format_histogram().is_full_cover() {
continue;
}
assert!(chain.as_slice().absent_file_formats_count() >= 1);
}
}
#[test]
fn absent_file_formats_count_is_axis_cardinality_minus_one_iff_has_singular_support() {
// The singleton-support boundary in coverage-gap form: when
// exactly one file format is observed, exactly `axis_cardinality
// - 1` are absent. File-format-sub-axis coverage-gap peer of
// `present_file_formats_count_is_one_iff_has_singular_support`
// and
// `absent_layer_kinds_count_is_axis_cardinality_minus_one_iff_has_singular_support`.
let axis_size = crate::axis_cardinality::<crate::discovery::Format>();
// Singleton-support: chains carrying recognized files of only one
// format have exactly `axis_cardinality - 1` absent.
for singleton in [
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![ConfigSource::File(PathBuf::from("/a.lisp"))],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.nix")),
],
] {
assert!(
singleton
.as_slice()
.file_format_histogram()
.has_singular_support()
);
assert_eq!(
singleton.as_slice().absent_file_formats_count(),
axis_size - 1,
);
}
// Full-cover: zero absent (< axis_size - 1).
let full_cover = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
assert!(
!full_cover
.as_slice()
.file_format_histogram()
.has_singular_support()
);
assert!(full_cover.as_slice().absent_file_formats_count() < axis_size - 1);
// Empty histogram: coverage gap is the full axis (> axis_size - 1).
let empty: Vec<ConfigSource> = Vec::new();
assert!(
!empty
.as_slice()
.file_format_histogram()
.has_singular_support()
);
assert!(empty.as_slice().absent_file_formats_count() > axis_size - 1);
}
#[test]
fn absent_file_formats_count_agrees_with_open_coded_zero_walk() {
// Parity against the exact `Format::ALL.iter().filter(|f|
// file_format_histogram().count(*f) == 0).count()` walk this lift
// replaces on the coverage-gap side. File-format-sub-axis peer of
// `absent_layer_kinds_count_agrees_with_open_coded_zero_walk` on
// the layer-kind sub-axis of the same chain altitude.
use crate::discovery::Format;
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.unknown")),
],
];
for chain in &fixtures {
let via_seam = chain.as_slice().absent_file_formats_count();
let hist = chain.as_slice().file_format_histogram();
let hand_rolled = Format::ALL.iter().filter(|f| hist.count(**f) == 0).count();
assert_eq!(via_seam, hand_rolled);
}
}
#[test]
fn absent_file_formats_count_empty_chain_is_axis_cardinality() {
// Direct fixture pin: an empty chain has full coverage gap so
// `absent_file_formats_count` reads the axis cardinality
// (4 = |{Yaml, Toml, Lisp, Nix}|). File-format-sub-axis peer of
// `absent_layer_kinds_count_empty_chain_is_axis_cardinality` on
// the layer-kind sub-axis of the same chain altitude.
let empty: Vec<ConfigSource> = Vec::new();
assert_eq!(
empty.as_slice().absent_file_formats_count(),
crate::axis_cardinality::<crate::discovery::Format>(),
);
}
#[test]
fn absent_file_formats_count_full_cover_is_zero() {
// Direct fixture pin: a chain covering every file format has zero
// coverage gap. File-format-sub-axis peer of
// `absent_layer_kinds_count_full_cover_is_zero` on the layer-kind
// sub-axis of the same chain altitude.
let full_cover = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
assert_eq!(full_cover.as_slice().absent_file_formats_count(), 0);
}
#[test]
fn absent_file_formats_count_sample_chain_is_three() {
// Direct fixture pin: `sample_chain` covers one of four formats
// (two `.yaml` File layers, one Env), so the coverage-gap scalar
// reads 3 (Toml, Lisp, Nix absent). Coverage-gap peer of
// `present_file_formats_count_sample_chain_is_one` on the same
// fixture and altitude.
let chain = sample_chain();
assert_eq!(chain.as_slice().absent_file_formats_count(), 3);
}
#[test]
fn absent_file_formats_count_no_recognized_files_is_axis_cardinality() {
// Direct fixture pin on the file-format sub-axis's divergent
// boundary: a non-empty chain of only Defaults, Env, and
// unrecognized-extension File layers reads the full axis
// cardinality because every entry projects to None through
// `file_format()`, leaving every format in the coverage gap.
// Companion to
// `present_file_formats_count_no_recognized_files_is_zero` on
// the support-size scalar peer.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b")),
];
assert!(!chain.is_empty());
assert!(chain.as_slice().file_format_histogram().is_empty());
assert_eq!(
chain.as_slice().absent_file_formats_count(),
crate::axis_cardinality::<crate::discovery::Format>(),
);
}
// ---- ConfigSourceChain::dominant_file_format — modal-cell scalar
// peer of file_format_histogram on the chain-shape altitude ----
#[test]
fn dominant_file_format_matches_file_format_histogram_dominant_cell_pointwise() {
// The modal-cell pin: `dominant_file_format` routes through
// `file_format_histogram().dominant_cell()`, so the two seams
// must stay pointwise equivalent under every fixture. Sister of
// `dominant_layer_kind_matches_layer_kind_histogram_dominant_cell_pointwise`
// one sub-axis over on the same chain altitude.
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Env(String::new())],
vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b")),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.nix")),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
let via_histogram = chain.as_slice().file_format_histogram().dominant_cell();
assert_eq!(chain.as_slice().dominant_file_format(), via_histogram);
}
}
#[test]
fn dominant_file_format_sample_chain_is_yaml() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one Env layer. Yaml is uniquely dominant with 2 of 2 recognized
// file layers (Env layers don't contribute to the file-format
// histogram). Sister of `dominant_layer_kind_sample_chain_is_file`
// one sub-axis over on the same named fixture.
use crate::discovery::Format;
let chain = sample_chain();
assert_eq!(chain.as_slice().dominant_file_format(), Some(Format::Yaml));
}
#[test]
fn dominant_file_format_toml_majority_is_toml() {
// Direct pin against a toml-majority chain: three `.toml` file
// layers + one `.yaml` + one Env + one Defaults. Toml is uniquely
// dominant with 3 of 4 recognized file layers. Cross-verified
// against `hist.count(Toml) == hist.peak_count() == 3`. Sister of
// `dominant_layer_kind_env_majority_is_env` one sub-axis over.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.dominant_file_format(), Some(Format::Toml));
let hist = slice.file_format_histogram();
assert_eq!(hist.count(Format::Toml), 3);
assert_eq!(hist.peak_count(), 3);
}
#[test]
fn dominant_file_format_empty_chain_is_none() {
// The empty-chain / `None` boundary — every chain-level histogram
// over an empty chain is the all-zero histogram, so
// `dominant_cell` reads `None`. Peer of
// `dominant_layer_kind_empty_chain_is_none` on the same chain
// altitude one sub-axis over.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.dominant_file_format(), None);
}
#[test]
fn dominant_file_format_no_recognized_files_is_none() {
// The non-empty-chain / empty-histogram boundary the file-format
// sub-axis pins that the layer-kind sub-axis does *not*. A chain
// of only `Defaults` / `Env` / unrecognized-extension `File`
// layers is non-empty but has no `Some` file_format projection,
// so the histogram is empty and `dominant_file_format` reads
// `None`. Distinguishing pin against a mis-implementation that
// would confuse `!self.as_ref().is_empty()` (the layer-kind sub-
// axis's presence bound) with the file-format sub-axis's
// (`!file_format_histogram().is_empty()`).
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert_eq!(chain.as_slice().dominant_file_format(), None);
}
}
#[test]
fn dominant_file_format_is_some_iff_histogram_is_nonempty() {
// Structural completeness of the
// `(file_format_histogram().is_empty(), dominant_file_format)`
// cross-surface pair. Unlike `dominant_layer_kind`, the presence
// bound is the sub-axis histogram's `is_empty()` — a non-empty
// chain can still have an empty file-format histogram (only
// `Defaults` / `Env` / unrecognized `File` layers). Sister of
// `dominant_layer_kind_is_some_iff_chain_is_nonempty` one sub-
// axis over with the correct sub-axis presence bound.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().dominant_file_format().is_some(),
!chain.as_slice().file_format_histogram().is_empty(),
);
}
}
#[test]
fn dominant_file_format_is_member_of_present_file_formats() {
// Structural pin: whenever `dominant_file_format()` is
// `Some(f)`, `f` is a member of the observed-cells vector peer.
// The modal cell is by definition observed. Sister of
// `dominant_layer_kind_is_member_of_present_layer_kinds` one
// sub-axis over.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
let dominant = chain
.as_slice()
.dominant_file_format()
.expect("non-empty file-format histogram has a dominant format");
let present = chain.as_slice().present_file_formats();
assert!(
present.contains(&dominant),
"dominant file format {dominant:?} must appear in \
present_file_formats() = {present:?}",
);
}
}
#[test]
fn dominant_file_format_is_not_member_of_absent_file_formats() {
// Structural pin: whenever `dominant_file_format()` is
// `Some(f)`, `f` is NOT a member of the coverage-gap vector
// peer — the observed / coverage-gap partition is disjoint,
// so the modal (observed) cell is disjoint from the coverage
// gap. Sister of `dominant_layer_kind_is_not_member_of_absent_layer_kinds`
// one sub-axis over.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
let dominant = chain
.as_slice()
.dominant_file_format()
.expect("non-empty file-format histogram has a dominant format");
let absent = chain.as_slice().absent_file_formats();
assert!(
!absent.contains(&dominant),
"dominant file format {dominant:?} must NOT appear in \
absent_file_formats() = {absent:?}",
);
}
}
#[test]
fn dominant_file_format_count_equals_peak_count_on_nonempty_histogram() {
// The `(dominant_cell, peak_count)` modal-pair pin:
// `hist.count(dominant_file_format().unwrap()) ==
// hist.peak_count()` on every chain whose file-format histogram
// is non-empty. Sister of
// `dominant_layer_kind_count_equals_peak_count_on_nonempty_chain`
// one sub-axis over with the sub-axis's presence bound.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
let hist = chain.as_slice().file_format_histogram();
let dominant = chain
.as_slice()
.dominant_file_format()
.expect("non-empty file-format histogram has a dominant format");
assert_eq!(hist.count(dominant), hist.peak_count());
}
}
#[test]
fn dominant_file_format_uniform_full_cover_picks_yaml() {
// Uniform full-cover chain — one file layer of each format (all
// four cells tied at count 1). The declaration-order tiebreak on
// `Format::ALL` (`Yaml → Toml → Lisp → Nix`) picks the FIRST
// tied cell — `Yaml` — not the LAST that `Iterator::max_by_key`
// would return. Sister of
// `dominant_layer_kind_ties_broken_by_declaration_order` /
// `dominant_layer_kind_uniform_cover_picks_first_cell` one sub-
// axis over.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
];
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert!(hist.is_full_cover());
assert_eq!(hist.count(Format::Yaml), 1);
assert_eq!(hist.count(Format::Toml), 1);
assert_eq!(hist.count(Format::Lisp), 1);
assert_eq!(hist.count(Format::Nix), 1);
assert_eq!(hist.peak_count(), 1);
assert_eq!(slice.dominant_file_format(), Some(Format::Yaml));
}
#[test]
fn dominant_file_format_two_way_tie_picks_earliest_declared_observed_cell() {
// Two-way tie between cells that are NOT the first cell of
// `Format::ALL`: 2 Toml + 2 Lisp, zero Yaml + zero Nix. Toml
// wins because it is earlier in `ALL` than Lisp — the tiebreak
// is "earliest tied observed cell", not "first cell of `ALL`
// regardless of observation" (Yaml appears in `ALL` before Toml
// but has zero count, so it doesn't participate in the tie).
// Distinguishing pin against a mis-implementation that would
// return `Yaml` (the first cell of `ALL`) instead of `Toml`
// (the first tied observed cell). Sister of
// `dominant_layer_kind_two_way_tie_picks_earliest_declared_observed_cell`
// one sub-axis over.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.lisp")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.toml")),
];
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert_eq!(hist.count(Format::Yaml), 0);
assert_eq!(hist.count(Format::Toml), 2);
assert_eq!(hist.count(Format::Lisp), 2);
assert_eq!(hist.count(Format::Nix), 0);
assert_eq!(slice.dominant_file_format(), Some(Format::Toml));
}
#[test]
fn dominant_file_format_agrees_with_open_coded_argmax_walk() {
// Parity against the exact fold-forward argmax walk this lift
// replaces — spelling the declaration-order tiebreak explicitly
// with strict `>` inequality so the FIRST tied cell wins,
// mirroring `AxisHistogram::dominant_cell` rather than
// `max_by_key`'s LAST-tied-cell semantics. Sister of
// `dominant_layer_kind_agrees_with_open_coded_argmax_walk` one
// sub-axis over.
use crate::discovery::Format;
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.lisp")),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a.lisp")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
],
];
for chain in &chains {
let hist = chain.as_slice().file_format_histogram();
let mut manual: Option<(Format, usize)> = None;
for cell in Format::ALL.iter().copied() {
let count = hist.count(cell);
if count == 0 {
continue;
}
match manual {
None => manual = Some((cell, count)),
Some((_, best)) if count > best => manual = Some((cell, count)),
_ => {}
}
}
let via_seam = chain.as_slice().dominant_file_format();
assert_eq!(via_seam, manual.map(|(cell, _)| cell));
}
}
// ---- ConfigSourceChain::recessive_file_format — anti-modal-cell
// scalar peer of file_format_histogram on the chain-shape
// altitude ----
fn recessive_file_format_fixtures() -> Vec<Vec<ConfigSource>> {
// Reused fixture set for the recessive_file_format trait-uniform
// pins — mirrors the `dominant_file_format_matches_...` fixture
// set at that site (seven chains covering empty, sample, empty-
// histogram-non-empty-chain, toml-majority, full-cover, no-
// recognized-file, and mixed shapes).
vec![
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Env(String::new())],
vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
],
vec![
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b")),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.nix")),
ConfigSource::Env("APP_".to_owned()),
],
]
}
#[test]
fn recessive_file_format_matches_file_format_histogram_recessive_cell_pointwise() {
// The anti-modal-cell pin: `recessive_file_format` routes through
// `file_format_histogram().recessive_cell()`, so the two seams
// must stay pointwise equivalent under every fixture. Direct
// sister of
// `recessive_layer_kind_matches_layer_kind_histogram_recessive_cell_pointwise`
// one sub-axis over on the same chain altitude, and dominant-side
// peer of
// `dominant_file_format_matches_file_format_histogram_dominant_cell_pointwise`.
for chain in recessive_file_format_fixtures() {
let via_histogram = chain.as_slice().file_format_histogram().recessive_cell();
assert_eq!(chain.as_slice().recessive_file_format(), via_histogram);
}
}
#[test]
fn recessive_file_format_sample_chain_is_yaml() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one Env layer. Yaml is the sole observed format (Env layers
// don't contribute to the file-format histogram), so it is both
// the modal AND the anti-modal cell (singleton-support
// degenerate). Peer of `dominant_file_format_sample_chain_is_yaml`
// on the same named fixture.
use crate::discovery::Format;
let chain = sample_chain();
assert_eq!(chain.as_slice().recessive_file_format(), Some(Format::Yaml));
assert_eq!(
chain.as_slice().recessive_file_format(),
chain.as_slice().dominant_file_format(),
);
}
#[test]
fn recessive_file_format_toml_majority_is_yaml() {
// Direct pin against a toml-majority chain: three `.toml` file
// layers + one `.yaml` + one Env + one Defaults. Toml is the
// modal cell at count 3; Yaml is uniquely the anti-modal cell at
// count 1. Cross-verified against `hist.count(Yaml) ==
// hist.trough_count() == 1`. Peer of
// `dominant_file_format_toml_majority_is_toml` at the same
// fixture — the two projections partition the two-cell support.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.recessive_file_format(), Some(Format::Yaml));
let hist = slice.file_format_histogram();
assert_eq!(hist.count(Format::Yaml), 1);
assert_eq!(hist.count(Format::Toml), 3);
assert_eq!(hist.trough_count(), 1);
}
#[test]
fn recessive_file_format_empty_chain_is_none() {
// The empty-chain / `None` boundary — every chain-level histogram
// over an empty chain is the all-zero histogram, so
// `recessive_cell` reads `None`. Peer of
// `dominant_file_format_empty_chain_is_none` on the modal side,
// and `recessive_layer_kind_empty_chain_is_none` on the layer-
// kind sub-axis.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.recessive_file_format(), None);
}
#[test]
fn recessive_file_format_no_recognized_files_is_none() {
// The non-empty-chain / empty-histogram boundary the file-format
// sub-axis pins that the layer-kind sub-axis does *not*. A chain
// of only `Defaults` / `Env` / unrecognized-extension `File`
// layers is non-empty but has no `Some` file_format projection,
// so the histogram is empty and `recessive_file_format` reads
// `None`. Distinguishing pin against a mis-implementation that
// would confuse `!self.as_ref().is_empty()` (the layer-kind sub-
// axis's presence bound) with the file-format sub-axis's
// (`!file_format_histogram().is_empty()`). Peer of
// `dominant_file_format_no_recognized_files_is_none` on the
// modal side.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert_eq!(chain.as_slice().recessive_file_format(), None);
}
}
#[test]
fn recessive_file_format_is_some_iff_histogram_is_nonempty() {
// Structural completeness of the
// `(file_format_histogram().is_empty(), recessive_file_format)`
// cross-surface pair. Unlike `recessive_layer_kind`, the presence
// bound is the sub-axis histogram's `is_empty()` — a non-empty
// chain can still have an empty file-format histogram (only
// `Defaults` / `Env` / unrecognized `File` layers). Peer of
// `dominant_file_format_is_some_iff_histogram_is_nonempty` on the
// modal side.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().recessive_file_format().is_some(),
!chain.as_slice().file_format_histogram().is_empty(),
);
}
}
#[test]
fn recessive_file_format_is_some_iff_dominant_file_format_is_some() {
// Cross-projection pin lifted from the trait-uniform
// `recessive_cell().is_some() == dominant_cell().is_some()` law
// on AxisHistogram: both projections operate over the same
// nonzero support, so they agree on presence at every input.
// Peer of `recessive_layer_kind_is_some_iff_dominant_layer_kind_is_some`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
assert_eq!(
chain.as_slice().recessive_file_format().is_some(),
chain.as_slice().dominant_file_format().is_some(),
);
}
}
#[test]
fn recessive_file_format_is_member_of_present_file_formats() {
// Structural pin: whenever `recessive_file_format()` is
// `Some(f)`, `f` must appear in `present_file_formats()` — the
// anti-modal cell is taken over the support, so it is by
// definition observed. Peer of
// `dominant_file_format_is_member_of_present_file_formats` on
// the modal side, and
// `recessive_layer_kind_is_member_of_present_layer_kinds` on
// the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let Some(recessive) = chain.as_slice().recessive_file_format() else {
continue;
};
let present = chain.as_slice().present_file_formats();
assert!(
present.contains(&recessive),
"recessive file format {recessive:?} must appear in \
present_file_formats() = {present:?}",
);
}
}
#[test]
fn recessive_file_format_is_not_member_of_absent_file_formats() {
// Structural pin: whenever `recessive_file_format()` is
// `Some(f)`, `f` must NOT appear in `absent_file_formats()` —
// the anti-modal cell lies on the observed side of the observed
// / coverage-gap partition by construction (argmin taken over
// the nonzero support). Disjointness pin between the two named
// seams. Peer of
// `dominant_file_format_is_not_member_of_absent_file_formats`
// on the modal side, and
// `recessive_layer_kind_is_not_member_of_absent_layer_kinds`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let Some(recessive) = chain.as_slice().recessive_file_format() else {
continue;
};
let absent = chain.as_slice().absent_file_formats();
assert!(
!absent.contains(&recessive),
"recessive file format {recessive:?} must NOT appear in \
absent_file_formats() = {absent:?}",
);
}
}
#[test]
fn recessive_file_format_count_equals_trough_count_on_nonempty_histogram() {
// The `(recessive_cell, trough_count)` anti-modal-pair invariant
// lifted to the chain altitude: the observation count of the
// recessive file format equals the histogram's trough count over
// the support. Peer of
// `dominant_file_format_count_equals_peak_count_on_nonempty_histogram`
// on the modal side, and
// `recessive_layer_kind_count_equals_trough_count_on_nonempty_chain`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let Some(recessive) = chain.as_slice().recessive_file_format() else {
continue;
};
let hist = chain.as_slice().file_format_histogram();
assert_eq!(hist.count(recessive), hist.trough_count());
}
}
#[test]
fn recessive_file_format_count_bounded_by_dominant_file_format_count() {
// Structural bound lifted from the trait-uniform
// `count(recessive_cell) <= count(dominant_cell)` law on
// AxisHistogram: the trough-of-support is bounded above by the
// peak-of-support at every fixture. Cross-projection pin between
// `recessive_file_format` and `dominant_file_format`. Peer of
// `recessive_layer_kind_count_bounded_by_dominant_layer_kind_count`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let Some(recessive) = chain.as_slice().recessive_file_format() else {
continue;
};
let Some(dominant) = chain.as_slice().dominant_file_format() else {
unreachable!("presence of recessive format implies presence of dominant format");
};
let hist = chain.as_slice().file_format_histogram();
assert!(
hist.count(recessive) <= hist.count(dominant),
"count(recessive={recessive:?})={r} must be <= count(dominant={dominant:?})={d}",
r = hist.count(recessive),
d = hist.count(dominant),
);
}
}
#[test]
fn recessive_file_format_uniform_full_cover_picks_yaml() {
// Uniform full-cover chain — one file layer of each format (all
// four cells tied at count 1). The declaration-order tiebreak on
// `Format::ALL` (`Yaml → Toml → Lisp → Nix`) picks the FIRST
// tied cell — `Yaml` — pointwise identical to
// `dominant_file_format` on the same input (the singleton-
// modality degenerate where the modal and anti-modal cells
// coincide). Peer of
// `dominant_file_format_uniform_full_cover_picks_yaml` on the
// modal side, and
// `recessive_layer_kind_uniform_cover_picks_first_cell` on the
// layer-kind sub-axis.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
];
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert!(hist.is_full_cover());
assert_eq!(hist.count(Format::Yaml), 1);
assert_eq!(hist.count(Format::Toml), 1);
assert_eq!(hist.count(Format::Lisp), 1);
assert_eq!(hist.count(Format::Nix), 1);
assert_eq!(hist.trough_count(), 1);
assert_eq!(slice.recessive_file_format(), Some(Format::Yaml));
assert_eq!(slice.recessive_file_format(), slice.dominant_file_format());
}
#[test]
fn recessive_file_format_two_way_tie_picks_earliest_declared_observed_cell() {
// Two-way tie between cells that are NOT the first cell of
// `Format::ALL`: 3 Yaml + 1 Toml + 1 Lisp, zero Nix. The
// support {Yaml, Toml, Lisp} has trough count 1 with Toml and
// Lisp tied. Toml wins because it precedes Lisp in `ALL` — the
// tiebreak is "earliest tied observed cell at the trough", not
// "first cell of `ALL` regardless of trough participation" (Yaml
// appears in `ALL` before Toml but has count 3 and does not
// participate in the trough tie). Distinguishing pin against a
// mis-implementation that would return `Yaml` (the first cell
// of `ALL`) instead of `Toml` (the first tied observed cell at
// the trough). Peer of
// `dominant_file_format_two_way_tie_picks_earliest_declared_observed_cell`
// on the modal side, and
// `recessive_layer_kind_two_way_tie_picks_earliest_declared_observed_cell`
// on the layer-kind sub-axis.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.toml")),
ConfigSource::File(PathBuf::from("/e.lisp")),
];
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert_eq!(hist.count(Format::Yaml), 3);
assert_eq!(hist.count(Format::Toml), 1);
assert_eq!(hist.count(Format::Lisp), 1);
assert_eq!(hist.count(Format::Nix), 0);
assert_eq!(hist.trough_count(), 1);
assert_eq!(slice.recessive_file_format(), Some(Format::Toml));
}
#[test]
fn recessive_file_format_singleton_support_agrees_with_dominant_file_format() {
// Singleton-support degenerate lifted from the trait-uniform
// `distinct_cells() == 1 → dominant_cell() == recessive_cell()`
// law on AxisHistogram: when only one format contributes, that
// format is both the modal and the anti-modal cell. Direct
// construction: three `.toml` files + Env + Defaults (Toml is
// the sole observed format). Peer of
// `recessive_layer_kind_singleton_support_agrees_with_dominant_layer_kind`
// on the layer-kind sub-axis.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert_eq!(slice.recessive_file_format(), slice.dominant_file_format());
assert_eq!(slice.recessive_file_format(), Some(Format::Toml));
}
#[test]
fn recessive_file_format_agrees_with_open_coded_argmin_walk() {
// Parity against the exact fold-forward argmin walk this lift
// replaces — spelling the declaration-order tiebreak explicitly
// with strict `<` inequality so the FIRST tied cell wins,
// mirroring `AxisHistogram::recessive_cell` rather than
// `min_by_key`'s FIRST-tied-cell semantics which agrees by
// coincidence but drifts under any reversed comparison. Peer of
// `dominant_file_format_agrees_with_open_coded_argmax_walk` on
// the modal side, and
// `recessive_layer_kind_agrees_with_open_coded_argmin_walk` on
// the layer-kind sub-axis.
use crate::discovery::Format;
for chain in recessive_file_format_fixtures() {
let hist = chain.as_slice().file_format_histogram();
let mut manual: Option<(Format, usize)> = None;
for cell in Format::ALL.iter().copied() {
let count = hist.count(cell);
if count == 0 {
continue;
}
match manual {
None => manual = Some((cell, count)),
Some((_, best)) if count < best => manual = Some((cell, count)),
_ => {}
}
}
let via_seam = chain.as_slice().recessive_file_format();
assert_eq!(via_seam, manual.map(|(cell, _)| cell));
}
}
// ---- ConfigSourceChain::peak_file_format_count — modal-cell scalar-
// count peer of file_format_histogram on the chain altitude,
// fusing with dominant_file_format into the (cell, count) modal
// pair on the file-format sub-axis of the chain-shape surface ----
#[test]
fn peak_file_format_count_matches_file_format_histogram_peak_count_pointwise() {
// The scalar-count pin: `peak_file_format_count` routes through
// `file_format_histogram().peak_count()`, so the two seams must
// stay pointwise equivalent under every fixture. Direct sister
// of `peak_layer_kind_count_matches_layer_kind_histogram_peak_count_pointwise`
// on the layer-kind sub-axis of the same chain altitude, and
// `peak_tier_count_matches_tier_histogram_peak_count_pointwise` /
// `peak_kind_count_matches_kind_histogram_peak_count_pointwise`
// on the tier and diff altitudes.
for chain in recessive_file_format_fixtures() {
let via_histogram = chain.as_slice().file_format_histogram().peak_count();
assert_eq!(chain.as_slice().peak_file_format_count(), via_histogram);
}
}
#[test]
fn peak_file_format_count_sample_chain_is_two() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one Env layer. Yaml is the sole observed format with 2 of 2
// recognized-extension file layers, so the peak count is 2. The
// (dominant_file_format, peak_file_format_count) modal pair reads
// `(Some(Yaml), 2)`.
use crate::discovery::Format;
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.dominant_file_format(), Some(Format::Yaml));
assert_eq!(slice.peak_file_format_count(), 2);
}
#[test]
fn peak_file_format_count_toml_majority_is_three() {
// Toml-majority fixture: three `.toml` file layers + one `.yaml`
// + one Env + one Defaults. Toml is uniquely dominant with 3 of
// 4 recognized-extension file layers, so the peak count is 3.
// Cross-verified against `hist.peak_count() == 3` at the same
// observation site — the fused-pair count projection reads
// through the seam.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.dominant_file_format(), Some(Format::Toml));
assert_eq!(slice.peak_file_format_count(), 3);
assert_eq!(slice.file_format_histogram().peak_count(), 3);
}
#[test]
fn peak_file_format_count_empty_chain_is_zero() {
// Empty-chain / zero boundary: the fused
// (dominant_file_format, peak_file_format_count) modal scalar
// pair reads `(None, 0)` uniformly on the empty chain, matching
// the `(AxisHistogram::dominant_cell, AxisHistogram::peak_count)`
// pair on the shared histogram primitive one altitude down. Peer
// of `peak_layer_kind_count_empty_chain_is_zero` on the layer-
// kind sub-axis, `peak_tier_count_empty_map_is_zero` on the tier
// altitude, and `peak_kind_count_empty_diff_is_zero` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.dominant_file_format(), None);
assert_eq!(empty.peak_file_format_count(), 0);
}
#[test]
fn peak_file_format_count_no_recognized_files_is_zero() {
// The non-empty-chain / empty-histogram boundary the file-format
// sub-axis pins that the layer-kind sub-axis does *not*. A chain
// of only `Defaults` / `Env` / unrecognized-extension `File`
// layers is non-empty but has no `Some` file_format projection,
// so the histogram is empty and `peak_file_format_count` reads
// zero. Distinguishing pin against a mis-implementation that
// would confuse `!self.as_ref().is_empty()` (the layer-kind sub-
// axis's zero boundary) with the file-format sub-axis's
// (`file_format_histogram().is_empty()`). Peer of
// `dominant_file_format_no_recognized_files_is_none` and
// `recessive_file_format_no_recognized_files_is_none` on the cell
// sides.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert_eq!(chain.as_slice().peak_file_format_count(), 0);
}
}
#[test]
fn peak_file_format_count_is_zero_iff_histogram_is_empty() {
// The `peak_file_format_count() == 0 ⇔
// file_format_histogram().is_empty()` presence-bound pin — unlike
// the layer-kind sub-axis (where the zero boundary is the chain's
// `is_empty()`), the file-format sub-axis's zero boundary is the
// sub-axis histogram's `is_empty()`. Cross-axis divergence from
// `peak_layer_kind_count_is_zero_iff_chain_is_empty`. Direct
// sister of the (`dominant_file_format().is_some() ==
// !histogram.is_empty()`) invariant on the cell side.
for chain in recessive_file_format_fixtures() {
assert_eq!(
chain.as_slice().peak_file_format_count() == 0,
chain.as_slice().file_format_histogram().is_empty(),
);
}
}
#[test]
fn peak_file_format_count_equals_count_at_dominant_file_format_on_nonempty_histogram() {
// The `(dominant_cell, peak_count)` modal-pair invariant lifted
// to the chain altitude on the file-format sub-axis:
// `hist.count(dominant_file_format().unwrap()) ==
// peak_file_format_count()` on every chain with a non-empty
// histogram. Peer of
// `peak_layer_kind_count_equals_count_at_dominant_layer_kind_on_nonempty_chain`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let hist = chain.as_slice().file_format_histogram();
if hist.is_empty() {
continue;
}
let dominant = chain
.as_slice()
.dominant_file_format()
.expect("non-empty histogram has a dominant file format");
assert_eq!(
hist.count(dominant),
chain.as_slice().peak_file_format_count(),
);
}
}
#[test]
fn peak_file_format_count_equals_dominant_file_format_map_or_count() {
// The fused-pair identity `peak_file_format_count() ==
// dominant_file_format().map_or(0, |f|
// file_format_histogram().count(f))` on every input — the count
// projection of the (dominant_file_format,
// peak_file_format_count) modal pair reads through the seam
// uniformly across the empty-histogram / non-empty-histogram
// partition. Includes the empty-histogram boundary (`None
// .map_or(0, …) == 0 == peak_file_format_count`) — this is the
// pin that the fused-pair identity is boundary-complete. Peer of
// `peak_layer_kind_count_equals_dominant_layer_kind_map_or_count`
// on the layer-kind sub-axis,
// `peak_tier_count_equals_dominant_tier_map_or_count` on the
// tier altitude, and `peak_kind_count_equals_dominant_kind_map_or_count`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let hist = chain.as_slice().file_format_histogram();
let via_fused_pair = chain
.as_slice()
.dominant_file_format()
.map_or(0, |f| hist.count(f));
assert_eq!(chain.as_slice().peak_file_format_count(), via_fused_pair);
}
}
#[test]
fn peak_file_format_count_is_bounded_by_histogram_total() {
// Structural bound `peak_file_format_count() <=
// file_format_histogram().total()` on every input — the peak is
// bounded above by the total recognized-extension file-layer
// count (every format contributes at most every recognized file
// layer, the others contribute zero). Lifted from the trait-
// uniform `peak_count() <= total()` law on AxisHistogram. Peer
// of `peak_layer_kind_count_is_bounded_by_len` on the layer-kind
// sub-axis (where the total equals `self.as_ref().len()`);
// here the total equals the recognized-extension file-layer
// count, not the chain length.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert!(
slice.peak_file_format_count() <= hist.total(),
"peak_file_format_count()={p} must be <= histogram.total()={t}",
p = slice.peak_file_format_count(),
t = hist.total(),
);
}
}
#[test]
fn peak_file_format_count_is_bounded_by_file_layer_count() {
// Cross-sub-axis structural bound: the file-format sub-axis's
// peak is bounded above by the layer-kind sub-axis's count of
// `File` layers — every recognized-extension file layer is a
// `File` layer, and some `File` layers may have unrecognized
// extensions and contribute to no format cell. Distinguishes the
// file-format sub-axis's slack against the layer-kind sub-axis
// from the total-equality bound on the layer-kind sub-axis. No
// direct peer on the layer-kind sub-axis — this invariant is
// specific to the file-format sub-axis's optional-projection
// discipline.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let file_layer_count = slice.layer_kind_histogram().count(ConfigSourceKind::File);
assert!(
slice.peak_file_format_count() <= file_layer_count,
"peak_file_format_count()={p} must be <= File layer count={f}",
p = slice.peak_file_format_count(),
f = file_layer_count,
);
}
}
#[test]
fn peak_file_format_count_equals_total_iff_at_most_one_present_file_format() {
// Structural bound `peak_file_format_count() ==
// file_format_histogram().total()` iff `present_file_formats()
// .len() <= 1` — the peak equals the histogram total exactly
// when zero or one format is observed. Zero: empty-histogram,
// both zero. One: singleton-support, every recognized file layer
// on the same format. Two or more: peak strictly below total.
// Lifted from the trait-uniform `peak_count() == total()` law
// on AxisHistogram. Peer of
// `peak_layer_kind_count_equals_len_iff_at_most_one_present_layer_kind`
// on the layer-kind sub-axis (where the total is the chain
// length).
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert_eq!(
slice.peak_file_format_count() == hist.total(),
slice.present_file_formats().len() <= 1,
"peak == total iff present_file_formats.len() <= 1 \
(peak={p}, total={t}, present={c})",
p = slice.peak_file_format_count(),
t = hist.total(),
c = slice.present_file_formats().len(),
);
}
}
#[test]
fn peak_file_format_count_is_at_least_one_on_nonempty_histogram() {
// Structural pin: whenever
// `!file_format_histogram().is_empty()`,
// `peak_file_format_count() >= 1` — a non-empty histogram always
// has at least one layer on the dominant format. Combined with
// the `<= total()` bound above, this pins `1 <=
// peak_file_format_count() <= total()` on every non-empty
// histogram. Peer of
// `peak_layer_kind_count_is_at_least_one_on_nonempty_chain` on
// the layer-kind sub-axis (where the boundary is the chain's
// `is_empty()` rather than the histogram's).
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
if hist.is_empty() {
continue;
}
assert!(
slice.peak_file_format_count() >= 1,
"non-empty histogram must have peak_file_format_count >= 1 (peak={p})",
p = slice.peak_file_format_count(),
);
}
}
#[test]
fn peak_file_format_count_uniform_full_cover_is_one() {
// Uniform full-cover chain — one file layer of each format (all
// four cells tied at count 1). Full-cover histogram with uniform
// count 1 per cell, so the peak count is 1. Combined with
// `dominant_file_format_uniform_full_cover_picks_yaml` (the cell
// picks Yaml by declaration-order tie-breaking), the fused pair
// `(dominant_file_format, peak_file_format_count)` reads
// `(Some(Yaml), 1)` on the uniform full-cover chain. Peer of
// `peak_layer_kind_count_uniform_cover_is_two` on the layer-kind
// sub-axis (that fixture uses two layers per kind so the peak is
// 2; here we use one layer per format so the peak is 1).
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
];
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert!(hist.is_full_cover());
assert_eq!(slice.peak_file_format_count(), 1);
assert_eq!(slice.dominant_file_format(), Some(Format::Yaml));
}
#[test]
fn peak_file_format_count_singleton_support_equals_histogram_total() {
// Singleton-support degenerate: when only one format contributes,
// every recognized file layer lands on that format, so the peak
// equals the histogram total. Direct construction: three `.toml`
// files + Env + Defaults (Toml is the sole observed format). The
// scalar peer of the singleton-support cell degenerate
// `dominant_file_format() == recessive_file_format()` in
// `recessive_file_format_singleton_support_agrees_with_dominant_file_format`
// — that test pins the *cell*; this test pins the *count*
// through the `peak_file_format_count() == total()` equality on
// the singleton-support boundary. Peer of
// `peak_layer_kind_count_singleton_support_equals_len` on the
// layer-kind sub-axis (where the equality is against
// `self.as_ref().len()`, not the histogram total).
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert_eq!(slice.present_file_formats().len(), 1);
assert_eq!(slice.peak_file_format_count(), hist.total());
assert_eq!(slice.peak_file_format_count(), 3);
}
#[test]
fn peak_file_format_count_agrees_with_open_coded_max_over_axis_walk() {
// Parity against the exact `hist.iter().map(|(_, c)| c).max()`
// walk this lift replaces — both the named seam and the hand-
// rolled max must pointwise agree over every fixture. The
// `.max().unwrap_or(0)` idiom mirrors the empty-histogram
// convention on `AxisHistogram::peak_count` one altitude down
// (both read 0 on empty). Peer of
// `peak_layer_kind_count_agrees_with_open_coded_max_over_axis_walk`
// on the layer-kind sub-axis,
// `peak_tier_count_agrees_with_open_coded_max_over_axis_walk`
// on the tier altitude, and
// `peak_kind_count_agrees_with_open_coded_max_over_axis_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let via_seam = chain.as_slice().peak_file_format_count();
let hand_rolled = chain
.as_slice()
.file_format_histogram()
.iter()
.map(|(_, c)| c)
.max()
.unwrap_or(0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::trough_file_format_count — anti-modal-cell
// scalar-count peer of file_format_histogram on the chain
// altitude, closing the (dom, rec) × (cell, count) 2×2 scalar
// grid on the file-format sub-axis of the chain-shape surface ----
#[test]
fn trough_file_format_count_matches_file_format_histogram_trough_count_pointwise() {
// The scalar-count pin: `trough_file_format_count` routes through
// `file_format_histogram().trough_count()`, so the two seams must
// stay pointwise equivalent under every fixture. Direct sister of
// `trough_layer_kind_count_matches_layer_kind_histogram_trough_count_pointwise`
// on the layer-kind sub-axis of the same chain altitude, and
// `trough_tier_count_matches_tier_histogram_trough_count_pointwise` /
// `trough_kind_count_matches_kind_histogram_trough_count_pointwise`
// on the tier and diff altitudes.
for chain in recessive_file_format_fixtures() {
let via_histogram = chain.as_slice().file_format_histogram().trough_count();
assert_eq!(chain.as_slice().trough_file_format_count(), via_histogram);
}
}
#[test]
fn trough_file_format_count_sample_chain_is_two() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one Env layer. Yaml is the sole observed format (singleton-
// support degenerate), so it is both the modal AND the anti-modal
// cell and the trough count coincides with the peak at 2. The
// (recessive_file_format, trough_file_format_count) anti-modal
// pair reads `(Some(Yaml), 2)`.
use crate::discovery::Format;
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.recessive_file_format(), Some(Format::Yaml));
assert_eq!(slice.trough_file_format_count(), 2);
assert_eq!(
slice.trough_file_format_count(),
slice.peak_file_format_count(),
);
}
#[test]
fn trough_file_format_count_toml_majority_is_one() {
// Toml-majority fixture: three `.toml` file layers + one `.yaml`
// + one Env + one Defaults. Yaml is uniquely anti-modal with 1
// of 4 recognized-extension file layers, so the trough count is
// 1. Cross-verified against `hist.trough_count() == 1` at the
// same observation site — the fused-pair count projection reads
// through the seam.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.recessive_file_format(), Some(Format::Yaml));
assert_eq!(slice.trough_file_format_count(), 1);
assert_eq!(slice.file_format_histogram().trough_count(), 1);
}
#[test]
fn trough_file_format_count_empty_chain_is_zero() {
// Empty-chain / zero boundary: the fused
// (recessive_file_format, trough_file_format_count) anti-modal
// scalar pair reads `(None, 0)` uniformly on the empty chain,
// matching the `(AxisHistogram::recessive_cell,
// AxisHistogram::trough_count)` pair on the shared histogram
// primitive one altitude down. Peer of
// `trough_layer_kind_count_empty_chain_is_zero` on the layer-
// kind sub-axis, `trough_tier_count_empty_map_is_zero` on the
// tier altitude, and `trough_kind_count_empty_diff_is_zero` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.recessive_file_format(), None);
assert_eq!(empty.trough_file_format_count(), 0);
}
#[test]
fn trough_file_format_count_no_recognized_files_is_zero() {
// The non-empty-chain / empty-histogram boundary the file-format
// sub-axis pins that the layer-kind sub-axis does *not*. A chain
// of only `Defaults` / `Env` / unrecognized-extension `File`
// layers is non-empty but has no `Some` file_format projection,
// so the histogram is empty and `trough_file_format_count` reads
// zero. Distinguishing pin against a mis-implementation that
// would confuse `!self.as_ref().is_empty()` (the layer-kind sub-
// axis's zero boundary) with the file-format sub-axis's
// (`file_format_histogram().is_empty()`). Peer of
// `peak_file_format_count_no_recognized_files_is_zero` on the
// modal side, and `recessive_file_format_no_recognized_files_is_none`
// / `dominant_file_format_no_recognized_files_is_none` on the
// cell sides.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert_eq!(chain.as_slice().trough_file_format_count(), 0);
}
}
#[test]
fn trough_file_format_count_is_zero_iff_histogram_is_empty() {
// The `trough_file_format_count() == 0 ⇔
// file_format_histogram().is_empty()` presence-bound pin —
// unlike the layer-kind sub-axis (where the zero boundary is
// the chain's `is_empty()`), the file-format sub-axis's zero
// boundary is the sub-axis histogram's `is_empty()`. Cross-axis
// divergence from `trough_layer_kind_count_is_zero_iff_chain_is_empty`.
// Direct sister of the (`recessive_file_format().is_some() ==
// !histogram.is_empty()`) invariant on the cell side.
for chain in recessive_file_format_fixtures() {
assert_eq!(
chain.as_slice().trough_file_format_count() == 0,
chain.as_slice().file_format_histogram().is_empty(),
);
}
}
#[test]
fn trough_file_format_count_equals_count_at_recessive_file_format_on_nonempty_histogram() {
// The `(recessive_cell, trough_count)` anti-modal-pair invariant
// lifted to the chain altitude on the file-format sub-axis:
// `hist.count(recessive_file_format().unwrap()) ==
// trough_file_format_count()` on every chain with a non-empty
// histogram. Peer of
// `trough_layer_kind_count_equals_count_at_recessive_layer_kind_on_nonempty_chain`
// on the layer-kind sub-axis (whose non-empty boundary coincides
// with `!chain.is_empty()` — the file-format sub-axis's
// non-empty boundary is `!file_format_histogram().is_empty()`).
for chain in recessive_file_format_fixtures() {
let hist = chain.as_slice().file_format_histogram();
if hist.is_empty() {
continue;
}
let recessive = chain
.as_slice()
.recessive_file_format()
.expect("non-empty histogram has a recessive file format");
assert_eq!(
hist.count(recessive),
chain.as_slice().trough_file_format_count(),
);
}
}
#[test]
fn trough_file_format_count_equals_recessive_file_format_map_or_count() {
// The fused-pair identity `trough_file_format_count() ==
// recessive_file_format().map_or(0, |f|
// file_format_histogram().count(f))` on every input — the count
// projection of the (recessive_file_format,
// trough_file_format_count) anti-modal pair reads through the
// seam uniformly across the empty-histogram / non-empty-histogram
// partition. Includes the empty-histogram boundary (`None
// .map_or(0, …) == 0 == trough_file_format_count`) — this is the
// pin that the fused-pair identity is boundary-complete. Peer of
// `trough_layer_kind_count_equals_recessive_layer_kind_map_or_count`
// on the layer-kind sub-axis,
// `trough_tier_count_equals_recessive_tier_map_or_count` on the
// tier altitude, and `trough_kind_count_equals_recessive_kind_map_or_count`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let hist = chain.as_slice().file_format_histogram();
let via_fused_pair = chain
.as_slice()
.recessive_file_format()
.map_or(0, |f| hist.count(f));
assert_eq!(chain.as_slice().trough_file_format_count(), via_fused_pair,);
}
}
#[test]
fn trough_file_format_count_bounded_above_by_peak_file_format_count() {
// Structural bound `trough_file_format_count() <=
// peak_file_format_count()` on every input — the trough is
// bounded above by the peak (lifted from the trait-uniform
// `trough_count() <= peak_count()` law on AxisHistogram). The
// empty-histogram case reads `0 <= 0`; the non-empty case reads
// the trough-of-support bounded above by the peak-of-support.
// Peer of `trough_layer_kind_count_bounded_above_by_peak_layer_kind_count`
// on the layer-kind sub-axis,
// `trough_tier_count_bounded_above_by_peak_tier_count` on the
// tier altitude, and
// `trough_kind_count_bounded_above_by_peak_kind_count` on the
// diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
assert!(
slice.trough_file_format_count() <= slice.peak_file_format_count(),
"trough_file_format_count()={t} must be <= peak_file_format_count()={p}",
t = slice.trough_file_format_count(),
p = slice.peak_file_format_count(),
);
}
}
#[test]
fn trough_file_format_count_is_bounded_by_file_layer_count() {
// Cross-sub-axis structural bound: the file-format sub-axis's
// trough is bounded above by the layer-kind sub-axis's count of
// `File` layers — every recognized-extension file layer is a
// `File` layer, and some `File` layers may have unrecognized
// extensions and contribute to no format cell. Distinguishes the
// file-format sub-axis's slack against the layer-kind sub-axis
// from the total-equality bound on the layer-kind sub-axis. No
// direct peer on the layer-kind sub-axis — this invariant is
// specific to the file-format sub-axis's optional-projection
// discipline. Peer of `peak_file_format_count_is_bounded_by_file_layer_count`
// on the modal side, closing the `(peak, trough) <= File-count`
// pair on the file-format sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let file_layer_count = slice.layer_kind_histogram().count(ConfigSourceKind::File);
assert!(
slice.trough_file_format_count() <= file_layer_count,
"trough_file_format_count()={t} must be <= File layer count={f}",
t = slice.trough_file_format_count(),
f = file_layer_count,
);
}
}
#[test]
fn trough_file_format_count_equals_peak_file_format_count_iff_at_most_one_present_file_format()
{
// Structural bound `trough_file_format_count() ==
// peak_file_format_count()` iff `present_file_formats().len() <=
// 1` (assuming distinct counts on multi-support histograms) —
// the one-directional pin only. Zero: empty histogram, both
// zero. One: singleton-support histogram, every recognized file
// layer on the same format, both equal
// `file_format_histogram().total()`. Two or more with distinct
// counts: trough strictly below peak. The uniform-count-multi-
// support degenerate (uniform full cover — four `.yaml`,
// `.toml`, `.lisp`, `.nix` layers at count 1 each) is the reason
// the converse is not universal; this test only asserts the
// `support_le_one → equal` half, matching the pattern in
// `trough_layer_kind_count_equals_peak_layer_kind_count_iff_at_most_one_present_layer_kind`
// on the layer-kind sub-axis and the tier / diff altitude peers.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let equal = slice.trough_file_format_count() == slice.peak_file_format_count();
let support_le_one = slice.present_file_formats().len() <= 1;
if support_le_one {
assert!(
equal,
"at_most_one_present_file_format → trough == peak \
(trough={t}, peak={p}, present={present:?})",
t = slice.trough_file_format_count(),
p = slice.peak_file_format_count(),
present = slice.present_file_formats(),
);
}
}
}
#[test]
fn trough_file_format_count_is_at_least_one_on_nonempty_histogram() {
// Structural pin: whenever `!file_format_histogram().is_empty()`,
// `trough_file_format_count() >= 1` — the argmin is taken over
// the histogram's *support* (nonzero cells), so the trough of a
// non-empty histogram is always at least one. Combined with the
// `<= peak_file_format_count()` bound above, this pins `1 <=
// trough_file_format_count() <= peak_file_format_count()` on
// every non-empty histogram. Peer of
// `trough_layer_kind_count_is_at_least_one_on_nonempty_chain` on
// the layer-kind sub-axis (where the boundary is the chain's
// `is_empty()` rather than the histogram's).
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
if hist.is_empty() {
continue;
}
assert!(
slice.trough_file_format_count() >= 1,
"non-empty histogram must have trough_file_format_count >= 1 (trough={t})",
t = slice.trough_file_format_count(),
);
}
}
#[test]
fn trough_file_format_count_uniform_full_cover_is_one() {
// Uniform full-cover chain — one file layer of each format (all
// four cells tied at count 1). Full-cover histogram with uniform
// count 1 per cell, so the trough count coincides with the peak
// count at 1 (the uniform-cover degenerate where every cell
// equals the modal cell). Direct sister of
// `peak_file_format_count_uniform_full_cover_is_one` — the same
// fixture read on the trough side. Combined with
// `recessive_file_format_uniform_full_cover_picks_yaml` (the
// cell picks Yaml by declaration-order tie-breaking), the fused
// pair `(recessive_file_format, trough_file_format_count)`
// reads `(Some(Yaml), 1)` on the uniform full-cover chain.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
];
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert!(hist.is_full_cover());
assert_eq!(slice.trough_file_format_count(), 1);
assert_eq!(
slice.trough_file_format_count(),
slice.peak_file_format_count(),
);
assert_eq!(slice.recessive_file_format(), Some(Format::Yaml));
}
#[test]
fn trough_file_format_count_singleton_support_equals_histogram_total() {
// Singleton-support degenerate: when only one format contributes,
// every recognized file layer lands on that format, so both
// trough and peak equal the histogram total. Direct construction:
// three `.toml` files + Env + Defaults (Toml is the sole
// observed format). The scalar peer of the singleton-support
// cell degenerate `dominant_file_format() ==
// recessive_file_format()` in
// `recessive_file_format_singleton_support_agrees_with_dominant_file_format`
// — that test pins the *cell*; this test pins the *count*
// through the `trough_file_format_count() == total()` equality
// on the singleton-support boundary. Peer of
// `peak_file_format_count_singleton_support_equals_histogram_total`
// on the modal side and
// `trough_layer_kind_count_singleton_support_equals_len` on the
// layer-kind sub-axis (where the equality is against
// `self.as_ref().len()`, not the histogram total — the file-
// format sub-axis's optional-projection discipline diverges the
// total from the chain length).
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
assert_eq!(slice.present_file_formats().len(), 1);
assert_eq!(slice.trough_file_format_count(), hist.total());
assert_eq!(slice.trough_file_format_count(), 3);
assert_eq!(
slice.trough_file_format_count(),
slice.peak_file_format_count(),
);
}
#[test]
fn trough_file_format_count_agrees_with_open_coded_min_over_support_walk() {
// Parity against the exact
// `hist.iter().filter(|(_, c)| *c > 0).map(|(_, c)| c).min()`
// walk this lift replaces — both the named seam and the
// hand-rolled min-over-support must pointwise agree over every
// fixture. The `.min().unwrap_or(0)` idiom mirrors the empty-
// histogram convention on `AxisHistogram::trough_count` one
// altitude down (both read 0 on empty). The `filter(|(_, c)|
// *c > 0)` step is the load-bearing seam: the naive `.min()`
// over the full axis would silently pick zero-count absent
// cells on any non-full-cover histogram, shadowing the trough-
// of-support the seam surfaces. Peer of
// `trough_layer_kind_count_agrees_with_open_coded_min_over_support_walk`
// on the layer-kind sub-axis,
// `trough_tier_count_agrees_with_open_coded_min_over_support_walk`
// on the tier altitude, and
// `trough_kind_count_agrees_with_open_coded_min_over_support_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let via_seam = chain.as_slice().trough_file_format_count();
let hand_rolled = chain
.as_slice()
.file_format_histogram()
.iter()
.map(|(_, c)| c)
.filter(|&c| c > 0)
.min()
.unwrap_or(0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::present_env_prefix_kinds — observed-cells
// peer of ConfigSourceChain::env_prefix_kind_histogram on the
// chain-shape altitude ----
#[test]
fn present_env_prefix_kinds_matches_env_prefix_kind_histogram_observed_pointwise() {
// The observed-support pin: `present_env_prefix_kinds` routes
// through `env_prefix_kind_histogram().observed().collect()`,
// so the two seams must stay pointwise equivalent under every
// fixture. Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive.
// Sister of
// `present_file_formats_matches_file_format_histogram_observed_pointwise`
// and `present_layer_kinds_matches_layer_kind_histogram_observed_pointwise`
// one axis over.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
let via_direct = chain.as_slice().present_env_prefix_kinds();
let via_histogram: Vec<EnvMetadataTagKind> = chain
.as_slice()
.env_prefix_kind_histogram()
.observed()
.collect();
assert_eq!(
via_direct,
via_histogram,
"present_env_prefix_kinds must equal \
env_prefix_kind_histogram().observed().collect() \
pointwise over chain of length {}",
chain.len(),
);
}
}
#[test]
fn present_env_prefix_kinds_empty_chain_is_empty() {
// Empty-chain boundary: no entries, no observed env-prefix
// kinds. Sister of `present_file_formats_empty_chain_is_empty`
// on the env-prefix-presence axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.present_env_prefix_kinds().is_empty());
assert_eq!(
empty.present_env_prefix_kinds(),
Vec::<EnvMetadataTagKind>::new(),
);
}
#[test]
fn present_env_prefix_kinds_no_env_layers_is_empty() {
// Presence-bound pin distinguishing this peer from
// `present_layer_kinds`: a non-empty chain of Defaults and
// File layers all project to None through env_prefix_kind(),
// so present_env_prefix_kinds() is empty even though the
// chain is not. Reads the histogram-empty law documented in
// the trait doc-string. Sister of
// `present_file_formats_no_recognized_files_is_empty` on the
// env-prefix-presence axis.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.unknown")),
];
assert!(!chain.is_empty());
assert!(chain.as_slice().env_prefix_kind_histogram().is_empty());
assert!(chain.as_slice().present_env_prefix_kinds().is_empty());
assert_eq!(
chain.as_slice().present_env_prefix_kinds(),
Vec::<EnvMetadataTagKind>::new(),
);
}
#[test]
fn present_env_prefix_kinds_iterates_in_declaration_order() {
// Declaration-order pin: even when the observation order is
// Bare → Prefixed (the reverse of ::ALL), the returned Vec
// walks the closed axis in canonical (Prefixed → Bare) order
// — the closed-axis discipline provides the sort
// automatically. Sister of
// `present_file_formats_iterates_in_declaration_order` on the
// env-prefix-presence axis.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
assert_eq!(
chain.as_slice().present_env_prefix_kinds(),
vec![EnvMetadataTagKind::Prefixed, EnvMetadataTagKind::Bare],
);
}
#[test]
fn present_env_prefix_kinds_dedups_across_repeated_observations() {
// Repeated observations of the same env-prefix kind collapse
// to one entry in the returned Vec — the closed-axis
// discipline provides dedup automatically. Six Env layers
// split (2 Bare × 3 Prefixed × 1 Prefixed) yield two present
// kinds (both cells observed). A supplementary fixture drops
// to a single kind so the dedup covers both the axis-cover
// and singleton-support cases. Sister of
// `present_file_formats_dedups_across_repeated_observations`
// on the env-prefix-presence axis.
let both = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
assert_eq!(
both.as_slice().present_env_prefix_kinds(),
vec![EnvMetadataTagKind::Prefixed, EnvMetadataTagKind::Bare],
);
let prefixed_only = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
assert_eq!(
prefixed_only.as_slice().present_env_prefix_kinds(),
vec![EnvMetadataTagKind::Prefixed],
);
}
#[test]
fn present_env_prefix_kinds_singleton_chain_yields_singleton_support() {
// A chain composed only of one env-prefix kind has exactly
// that kind as its present-kinds set — the support is the
// singleton observed cell. Boundary case pinning that
// unobserved cells do not leak into the returned Vec (the
// closed-axis discipline drops zero-count cells) — one
// fixture per EnvMetadataTagKind::ALL cell.
for (kind, layer) in [
(
EnvMetadataTagKind::Prefixed,
ConfigSource::Env("APP_".to_owned()),
),
(EnvMetadataTagKind::Bare, ConfigSource::Env(String::new())),
] {
let chain = vec![layer.clone(), layer];
assert_eq!(
chain.as_slice().present_env_prefix_kinds(),
vec![kind],
"singleton-support chain over {kind:?} must yield \
that single kind",
);
}
}
#[test]
fn present_env_prefix_kinds_len_matches_distinct_cells() {
// Support-cardinality invariant:
// `present_env_prefix_kinds().len()` equals
// `env_prefix_kind_histogram().distinct_cells()` pointwise.
// Both project the observed-cell count off the shared
// histogram over the EnvMetadataTagKind closed axis. Sister
// of `present_file_formats_len_matches_distinct_cells` one
// axis over.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_env_prefix_kinds().len(),
chain
.as_slice()
.env_prefix_kind_histogram()
.distinct_cells(),
"present_env_prefix_kinds().len() must equal \
env_prefix_kind_histogram().distinct_cells() over \
chain of length {}",
chain.len(),
);
}
}
#[test]
fn present_env_prefix_kinds_full_cover_matches_axis_cardinality() {
// Cross-surface pin on the full-cover predicate: a chain
// whose `env_prefix_kind_histogram().is_full_cover()` returns
// `true` has exactly
// `crate::axis_cardinality::<EnvMetadataTagKind>()` observed
// cells, and `present_env_prefix_kinds()` returns
// `EnvMetadataTagKind::ALL` in declaration order.
let axis_cover = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
assert!(
axis_cover
.as_slice()
.env_prefix_kind_histogram()
.is_full_cover()
);
assert_eq!(
axis_cover.as_slice().present_env_prefix_kinds().len(),
crate::axis_cardinality::<EnvMetadataTagKind>(),
);
assert_eq!(
axis_cover.as_slice().present_env_prefix_kinds(),
EnvMetadataTagKind::ALL.to_vec(),
);
// Strict-subset case: sample_chain has one Env("APP_") layer
// and no bare Env layer, so it is NOT a full cover, and the
// present-kinds cardinality is strictly less than the axis
// cardinality.
let chain = sample_chain();
assert!(!chain.as_slice().env_prefix_kind_histogram().is_full_cover());
assert!(
chain.as_slice().present_env_prefix_kinds().len()
< crate::axis_cardinality::<EnvMetadataTagKind>(),
);
}
#[test]
fn present_env_prefix_kinds_is_strictly_ascending_by_axis_ordinal() {
// Structural-sort pin: the returned Vec is strictly ascending
// by `crate::axis_ordinal` on EnvMetadataTagKind — dedup +
// sort for free from the closed-axis discipline. Every
// consecutive pair in the returned Vec has strictly
// increasing axis ordinal. Sister of
// `present_file_formats_is_strictly_ascending_by_axis_ordinal`
// one axis over.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::Env("OTHER_".to_owned()),
];
let present = chain.as_slice().present_env_prefix_kinds();
for window in present.windows(2) {
let a = crate::axis_ordinal(window[0]);
let b = crate::axis_ordinal(window[1]);
assert!(
a < b,
"present_env_prefix_kinds must be strictly ascending \
by axis_ordinal, but ord({:?})={a} >= ord({:?})={b}",
window[0],
window[1],
);
}
}
#[test]
fn present_env_prefix_kinds_agrees_with_open_coded_dedup_walk() {
// Parity pin against a hand-rolled `Vec::contains` +
// sort_by_key consumer — the exact pattern the trait-level
// lift replaces. Any future divergence (e.g. `observed()`
// changing its iteration order, `env_prefix_kind_histogram`
// projecting through a different env_prefix_kind function)
// surfaces here as a structural mismatch between the lifted
// seam and the open-coded walk.
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("OTHER_".to_owned()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &chains {
let lifted = chain.as_slice().present_env_prefix_kinds();
let mut manual: Vec<EnvMetadataTagKind> = Vec::new();
for source in chain {
if let Some(k) = source.env_prefix_kind()
&& !manual.contains(&k)
{
manual.push(k);
}
}
manual.sort_by_key(|k| crate::axis_ordinal(*k));
assert_eq!(
lifted,
manual,
"present_env_prefix_kinds must equal the open-coded \
contains+sort walk over chain of length {}",
chain.len(),
);
}
}
// ---- ConfigSourceChain::present_env_prefix_kinds_count — support-
// size scalar peer of present_env_prefix_kinds on the env-prefix-
// presence sub-axis of the chain altitude ----
#[test]
fn present_env_prefix_kinds_count_matches_env_prefix_kind_histogram_distinct_cells_pointwise() {
// The support-size pin: `present_env_prefix_kinds_count` routes
// through `env_prefix_kind_histogram().distinct_cells()`, so the
// two seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-
// prefix-presence-sub-axis peer of
// `present_layer_kinds_count_matches_layer_kind_histogram_distinct_cells_pointwise`
// and
// `present_file_formats_count_matches_file_format_histogram_distinct_cells_pointwise`
// on the sister sub-axes of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
let via_histogram = chain
.as_slice()
.env_prefix_kind_histogram()
.distinct_cells();
assert_eq!(
chain.as_slice().present_env_prefix_kinds_count(),
via_histogram,
"present_env_prefix_kinds_count must equal \
env_prefix_kind_histogram().distinct_cells() over chain \
of length {}",
chain.len(),
);
}
}
#[test]
fn present_env_prefix_kinds_count_equals_present_env_prefix_kinds_len_pointwise() {
// The Vec-peer identity: the scalar-count seam equals the length
// of the observed-cells `Vec` peer. Any future re-implementation
// of either seam must keep this equality — pinned uniformly.
// Env-prefix-presence-sub-axis peer of
// `present_layer_kinds_count_equals_present_layer_kinds_len_pointwise`
// and
// `present_file_formats_count_equals_present_file_formats_len_pointwise`
// on the sister sub-axes of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.unknown")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_env_prefix_kinds_count(),
chain.as_slice().present_env_prefix_kinds().len(),
);
}
}
#[test]
fn present_env_prefix_kinds_count_and_absent_env_prefix_kinds_len_partition_axis_cardinality() {
// The partition law: the scalar dual of
// `absent_env_prefix_kinds_and_present_env_prefix_kinds_partition_axis`.
// Every env-prefix-presence cell lies in exactly one of
// (observed, unobserved), so the scalar-count peers of the two
// Vec peers sum to the axis cardinality. Env-prefix-presence-
// sub-axis peer of
// `present_layer_kinds_count_and_absent_layer_kinds_len_partition_axis_cardinality`
// and
// `present_file_formats_count_and_absent_file_formats_len_partition_axis_cardinality`
// on the sister sub-axes of the same chain altitude.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.unknown")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_env_prefix_kinds_count()
+ chain.as_slice().absent_env_prefix_kinds().len(),
axis_size,
"partition must sum to axis cardinality over chain of length {}",
chain.len(),
);
}
}
#[test]
fn present_env_prefix_kinds_count_is_zero_iff_env_prefix_kind_histogram_is_empty() {
// The empty-boundary equivalence: like the file-format sub-axis
// and unlike the layer-kind sub-axis, the zero boundary is the
// histogram's own emptiness, NOT the chain's. A non-empty chain
// of only Defaults / File layers reads zero because every entry
// projects to None through `env_prefix_kind()`. Env-prefix-
// presence-sub-axis peer of
// `present_file_formats_count_is_zero_iff_file_format_histogram_is_empty`
// and divergence from
// `present_layer_kinds_count_is_zero_iff_chain_is_empty` (whose
// zero boundary is the chain's is_empty).
// Empty chain: histogram empty, support zero.
let empty: Vec<ConfigSource> = Vec::new();
assert!(empty.as_slice().env_prefix_kind_histogram().is_empty());
assert_eq!(empty.as_slice().present_env_prefix_kinds_count(), 0);
// Non-empty chain, empty histogram: support still zero — the
// load-bearing divergence from the layer-kind sub-axis.
let no_env = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
];
assert!(!no_env.is_empty());
assert!(no_env.as_slice().env_prefix_kind_histogram().is_empty());
assert_eq!(no_env.as_slice().present_env_prefix_kinds_count(), 0);
// Non-empty histogram: support strictly positive.
let chain = sample_chain();
assert!(!chain.as_slice().env_prefix_kind_histogram().is_empty());
assert!(chain.as_slice().present_env_prefix_kinds_count() > 0);
}
#[test]
fn present_env_prefix_kinds_count_is_at_least_one_on_nonempty_histogram() {
// The lower-bound invariant on the non-empty-histogram side:
// whenever the env-prefix-presence histogram carries at least
// one observation, the support is at least the singleton of
// that observed cell. Env-prefix-presence-sub-axis peer of
// `present_file_formats_count_is_at_least_one_on_nonempty_histogram`
// — pinned against the histogram's own emptiness rather than
// the chain's.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
];
for chain in &fixtures {
assert!(!chain.as_slice().env_prefix_kind_histogram().is_empty());
assert!(chain.as_slice().present_env_prefix_kinds_count() >= 1);
}
}
#[test]
fn present_env_prefix_kinds_count_is_bounded_by_axis_cardinality() {
// The upper-bound invariant: the support of a closed-axis
// histogram is at most the axis cardinality (the observed-
// cells set is a subset of `EnvMetadataTagKind::ALL`). Env-
// prefix-presence-sub-axis peer of
// `present_layer_kinds_count_is_bounded_by_axis_cardinality`
// and
// `present_file_formats_count_is_bounded_by_axis_cardinality`
// on the sister sub-axes of the same chain altitude.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
],
];
for chain in &fixtures {
assert!(chain.as_slice().present_env_prefix_kinds_count() <= axis_size);
}
}
#[test]
fn present_env_prefix_kinds_count_is_bounded_by_env_prefix_kind_histogram_total() {
// The support ≤ total invariant: every distinct cell contributes
// at least one observation to the total, so the support size is
// bounded above by the total observation count. Env-prefix-
// presence-sub-axis peer of
// `present_layer_kinds_count_is_bounded_by_layer_kind_histogram_total`
// and
// `present_file_formats_count_is_bounded_by_file_format_histogram_total`
// on the sister sub-axes of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
assert!(
chain.as_slice().present_env_prefix_kinds_count()
<= chain.as_slice().env_prefix_kind_histogram().total(),
);
}
}
#[test]
fn present_env_prefix_kinds_count_equals_axis_cardinality_iff_is_full_cover() {
// The full-cover boundary equivalence: the support size equals
// the axis cardinality iff every env-prefix kind contributed ≥1
// entry iff the coverage gap is empty. Env-prefix-presence-sub-
// axis peer of
// `present_layer_kinds_count_equals_axis_cardinality_iff_is_full_cover`
// and
// `present_file_formats_count_equals_axis_cardinality_iff_is_full_cover`
// on the sister sub-axes of the same chain altitude.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
// Full-cover: one env of each kind.
let axis_cover = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
assert!(
axis_cover
.as_slice()
.env_prefix_kind_histogram()
.is_full_cover()
);
assert!(axis_cover.as_slice().absent_env_prefix_kinds().is_empty());
assert_eq!(
axis_cover.as_slice().present_env_prefix_kinds_count(),
axis_size,
);
// Strict-subset: sample_chain has only the prefixed `APP_` env,
// so full-cover is false and the support size is strictly less
// than axis size.
let chain = sample_chain();
assert!(!chain.as_slice().env_prefix_kind_histogram().is_full_cover());
assert!(chain.as_slice().present_env_prefix_kinds_count() < axis_size);
}
#[test]
fn present_env_prefix_kinds_count_is_one_iff_has_singular_support() {
// The singleton-support boundary equivalence: the support size
// equals 1 iff exactly one env-prefix kind contributed iff the
// histogram has singular support. Env-prefix-presence-sub-axis
// peer of
// `present_layer_kinds_count_is_one_iff_has_singular_support`
// and
// `present_file_formats_count_is_one_iff_has_singular_support`
// on the sister sub-axes of the same chain altitude.
let prefixed_only = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
assert!(
prefixed_only
.as_slice()
.env_prefix_kind_histogram()
.has_singular_support()
);
assert_eq!(prefixed_only.as_slice().present_env_prefix_kinds_count(), 1,);
let bare_only = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
assert!(
bare_only
.as_slice()
.env_prefix_kind_histogram()
.has_singular_support()
);
assert_eq!(bare_only.as_slice().present_env_prefix_kinds_count(), 1);
// Multi-kind chain spans both env-prefix kinds, so singular-
// support reads false and the support size is > 1.
let mixed = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
assert!(
!mixed
.as_slice()
.env_prefix_kind_histogram()
.has_singular_support()
);
assert!(mixed.as_slice().present_env_prefix_kinds_count() > 1);
}
#[test]
fn present_env_prefix_kinds_count_of_one_implies_dominant_equals_recessive() {
// The support-collapse degenerate: a singleton-support recipe
// has the modal and anti-modal cells coincide on the sole
// observed env-prefix kind. Env-prefix-presence-sub-axis peer
// of
// `present_layer_kinds_count_of_one_implies_dominant_equals_recessive`
// and
// `present_file_formats_count_of_one_implies_dominant_equals_recessive`
// on the sister sub-axes of the same chain altitude.
let prefixed_only = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
assert_eq!(prefixed_only.as_slice().present_env_prefix_kinds_count(), 1,);
assert_eq!(
prefixed_only.as_slice().dominant_env_prefix_kind(),
prefixed_only.as_slice().recessive_env_prefix_kind(),
);
let bare_only = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
assert_eq!(bare_only.as_slice().present_env_prefix_kinds_count(), 1);
assert_eq!(
bare_only.as_slice().dominant_env_prefix_kind(),
bare_only.as_slice().recessive_env_prefix_kind(),
);
let singleton_prefixed = vec![ConfigSource::Env("APP_".to_owned())];
assert_eq!(
singleton_prefixed
.as_slice()
.present_env_prefix_kinds_count(),
1,
);
assert_eq!(
singleton_prefixed.as_slice().dominant_env_prefix_kind(),
singleton_prefixed.as_slice().recessive_env_prefix_kind(),
);
}
#[test]
fn present_env_prefix_kinds_count_agrees_with_open_coded_nonzero_walk() {
// Parity against the exact
// `EnvMetadataTagKind::ALL.iter().filter(|k|
// env_prefix_kind_histogram().count(*k) > 0).count()` walk this
// lift replaces. Env-prefix-presence-sub-axis peer of
// `present_layer_kinds_count_agrees_with_open_coded_nonzero_walk`
// and
// `present_file_formats_count_agrees_with_open_coded_nonzero_walk`
// on the sister sub-axes of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.unknown")),
],
];
for chain in &fixtures {
let via_seam = chain.as_slice().present_env_prefix_kinds_count();
let hist = chain.as_slice().env_prefix_kind_histogram();
let hand_rolled = EnvMetadataTagKind::ALL
.iter()
.filter(|k| hist.count(**k) > 0)
.count();
assert_eq!(via_seam, hand_rolled);
}
}
#[test]
fn present_env_prefix_kinds_count_sample_chain_is_one() {
// Direct fixture pin: sample_chain has one prefixed `APP_` Env
// and no bare Env, so present_env_prefix_kinds_count reads 1
// (only Prefixed observed; Bare absent).
let chain = sample_chain();
assert_eq!(chain.as_slice().present_env_prefix_kinds_count(), 1);
}
#[test]
fn present_env_prefix_kinds_count_full_cover_is_axis_cardinality() {
// Direct fixture pin: a chain covering every env-prefix kind
// reads the axis cardinality (2 = |{Prefixed, Bare}|).
let axis_cover = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
assert_eq!(
axis_cover.as_slice().present_env_prefix_kinds_count(),
crate::axis_cardinality::<EnvMetadataTagKind>(),
);
}
#[test]
fn present_env_prefix_kinds_count_no_env_layers_is_zero() {
// Direct fixture pin on the env-prefix-presence sub-axis's
// divergent boundary: a non-empty chain of only Defaults and
// File layers reads zero because every entry projects to None
// through `env_prefix_kind()`. Companion to
// `present_env_prefix_kinds_no_env_layers_is_empty` on the
// observed-cells Vec peer.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.unknown")),
];
assert!(!chain.is_empty());
assert!(chain.as_slice().env_prefix_kind_histogram().is_empty());
assert_eq!(chain.as_slice().present_env_prefix_kinds_count(), 0);
}
// ---- ConfigSourceChain::absent_env_prefix_kinds — unobserved-cells
// peer of present_env_prefix_kinds on the chain-shape altitude ----
#[test]
fn absent_env_prefix_kinds_matches_env_prefix_kind_histogram_unobserved_pointwise() {
// The coverage-gap pin: `absent_env_prefix_kinds` routes through
// `env_prefix_kind_histogram().unobserved().collect()`, so the
// two seams must stay pointwise equivalent under every fixture.
// Sister of
// `absent_file_formats_matches_file_format_histogram_unobserved_pointwise`
// and `absent_layer_kinds_matches_layer_kind_histogram_unobserved_pointwise`
// one axis over on the same chain-shape surface.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
let via_direct = chain.as_slice().absent_env_prefix_kinds();
let via_histogram: Vec<EnvMetadataTagKind> = chain
.as_slice()
.env_prefix_kind_histogram()
.unobserved()
.collect();
assert_eq!(
via_direct,
via_histogram,
"absent_env_prefix_kinds must equal \
env_prefix_kind_histogram().unobserved().collect() \
pointwise over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_env_prefix_kinds_empty_chain_is_full_axis() {
// An empty chain has no observed env-prefix kinds — every cell
// of `EnvMetadataTagKind::ALL` lies in the coverage gap. Sister
// of `absent_file_formats_empty_chain_is_full_axis` and
// `absent_layer_kinds_empty_chain_is_full_axis` one axis over.
let empty: [ConfigSource; 0] = [];
assert_eq!(
empty.absent_env_prefix_kinds(),
EnvMetadataTagKind::ALL.to_vec(),
);
}
#[test]
fn absent_env_prefix_kinds_no_env_layers_is_full_axis() {
// Presence-bound divergence from `absent_layer_kinds` — the
// chain is non-empty but every entry projects to None through
// `env_prefix_kind()`, so the histogram is empty and every axis
// cell is absent. Peer of
// `present_env_prefix_kinds_no_env_layers_is_empty` on the
// coverage-gap side: a non-empty chain of Defaults and File
// layers has the full env-prefix-presence axis as its coverage
// gap. Same presence-bound shape as
// `absent_file_formats_no_recognized_files_is_full_axis` one
// axis over.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.unknown")),
];
assert!(!chain.is_empty());
assert!(chain.as_slice().env_prefix_kind_histogram().is_empty());
assert_eq!(
chain.as_slice().absent_env_prefix_kinds(),
EnvMetadataTagKind::ALL.to_vec(),
);
}
#[test]
fn absent_env_prefix_kinds_iterates_in_declaration_order() {
// The coverage-gap iter walks `EnvMetadataTagKind::ALL` in
// declaration order (`Prefixed → Bare`) and yields only the
// cells with zero count. Pinned here on the empty chain, whose
// gap is the entire axis — the emitted order matches
// `EnvMetadataTagKind::ALL` verbatim.
let empty: [ConfigSource; 0] = [];
assert_eq!(
empty.absent_env_prefix_kinds(),
vec![EnvMetadataTagKind::Prefixed, EnvMetadataTagKind::Bare],
);
}
#[test]
fn absent_env_prefix_kinds_prefixed_only_chain_is_bare_only() {
// A chain composed only of prefixed Env layers has exactly
// `{ Bare }` as its coverage gap — the non-prefixed cell of the
// axis is the only unobserved cell. Operator-facing pin on the
// "prefixed-only recipe" — the common shikumi default where
// discovery injects only `figment::providers::Env::prefixed`.
let prefixed_only = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
assert_eq!(
prefixed_only.as_slice().absent_env_prefix_kinds(),
vec![EnvMetadataTagKind::Bare],
);
}
#[test]
fn absent_env_prefix_kinds_bare_only_chain_is_prefixed_only() {
// A chain composed only of bare Env layers has exactly
// `{ Prefixed }` as its coverage gap. Boundary pin on the
// "bare-only recipe" — the closed-axis discipline emits in
// declaration order regardless of observation order.
let bare_only = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
assert_eq!(
bare_only.as_slice().absent_env_prefix_kinds(),
vec![EnvMetadataTagKind::Prefixed],
);
}
#[test]
fn absent_env_prefix_kinds_len_matches_unobserved_cells() {
// The coverage-gap-cardinality invariant on the histogram's
// support / gap partition:
// `absent_env_prefix_kinds().len()` equals
// `env_prefix_kind_histogram().unobserved_cells()` pointwise
// across every fixture. Sister of
// `absent_file_formats_len_matches_unobserved_cells` one axis
// over.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_env_prefix_kinds().len(),
chain
.as_slice()
.env_prefix_kind_histogram()
.unobserved_cells(),
"absent_env_prefix_kinds().len() must equal \
env_prefix_kind_histogram().unobserved_cells() over \
chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_env_prefix_kinds_and_present_env_prefix_kinds_partition_axis() {
// The support / coverage-gap partition on the closed axis:
// every cell of `EnvMetadataTagKind::ALL` lies in exactly one
// of (observed, unobserved), so the two Vec lengths sum to the
// axis cardinality. Sister of
// `absent_file_formats_and_present_file_formats_partition_axis`
// one axis over.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
let observed = chain.as_slice().present_env_prefix_kinds();
let absent = chain.as_slice().absent_env_prefix_kinds();
assert_eq!(observed.len() + absent.len(), axis_size);
for kind in &observed {
assert!(
!absent.contains(kind),
"kind {kind:?} appears in both present and absent \
over chain of length {}",
chain.len(),
);
}
for cell in EnvMetadataTagKind::ALL {
assert!(
observed.contains(cell) || absent.contains(cell),
"kind {cell:?} appears in neither present nor absent \
over chain of length {}",
chain.len(),
);
}
}
}
#[test]
fn absent_env_prefix_kinds_is_empty_iff_is_full_cover() {
// The coverage-gap is empty iff every env-prefix kind was
// observed at least once. Pinned across every fixture in the
// module against `env_prefix_kind_histogram().is_full_cover()`,
// plus a direct positive pin: a chain carrying one prefixed +
// one bare Env layer is full-cover; the coverage-gap is empty.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![ConfigSource::Env("APP_".to_owned())],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_env_prefix_kinds().is_empty(),
chain.as_slice().env_prefix_kind_histogram().is_full_cover(),
);
}
let full_cover = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
assert!(
full_cover
.as_slice()
.env_prefix_kind_histogram()
.is_full_cover()
);
assert_eq!(
full_cover.as_slice().absent_env_prefix_kinds(),
Vec::<EnvMetadataTagKind>::new(),
);
assert_eq!(
full_cover.as_slice().present_env_prefix_kinds(),
EnvMetadataTagKind::ALL.to_vec(),
);
}
#[test]
fn absent_env_prefix_kinds_is_strictly_ascending_by_axis_ordinal() {
// Structural sort pin: the coverage-gap walks the closed axis
// in declaration order, so `absent_env_prefix_kinds()` is
// strictly ascending by `crate::axis_ordinal` — dedup + sort
// for free from the closed-axis discipline. Sister of
// `absent_file_formats_is_strictly_ascending_by_axis_ordinal`
// one axis over. On the two-cell env-prefix-presence axis every
// fixture's coverage gap has at most two cells, so most
// `windows(2)` iterations are trivial — pinned here for
// template parity with the layer-kind and file-format sisters.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::Env(String::new())],
];
for chain in &fixtures {
let absent = chain.as_slice().absent_env_prefix_kinds();
for pair in absent.windows(2) {
assert!(
crate::axis_ordinal(pair[0]) < crate::axis_ordinal(pair[1]),
"absent_env_prefix_kinds must be strictly ascending: \
{absent:?}",
);
}
}
}
#[test]
fn absent_env_prefix_kinds_singleton_chain_yields_one_absent() {
// A chain of a single Env layer has exactly
// `axis_cardinality - 1` absent kinds — every axis cell except
// the one carried by that layer. Sister of
// `absent_file_formats_singleton_chain_yields_three_absent`
// (four-cell axis, three absent) and
// `absent_layer_kinds_singleton_chain_yields_two_absent`
// (three-cell axis, two absent) one axis over — the two-cell
// env-prefix-presence axis carries cardinality two, so the
// singleton coverage-gap has exactly one cell, not two or
// three. Distinguishing pin on the axis cardinality: the same
// template lands with a different arithmetic constant.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
for (source, present_kind) in [
(
ConfigSource::Env("APP_".to_owned()),
EnvMetadataTagKind::Prefixed,
),
(ConfigSource::Env(String::new()), EnvMetadataTagKind::Bare),
] {
let chain = vec![source];
let absent = chain.as_slice().absent_env_prefix_kinds();
assert_eq!(absent.len(), axis_size - 1);
assert!(
!absent.contains(&present_kind),
"the observed kind {present_kind:?} must not appear in \
the coverage gap",
);
for cell in EnvMetadataTagKind::ALL {
if *cell != present_kind {
assert!(
absent.contains(cell),
"the singleton chain's coverage gap must contain \
every non-observed axis cell — missing {cell:?}",
);
}
}
}
}
#[test]
fn absent_env_prefix_kinds_agrees_with_open_coded_coverage_gap_walk() {
// Parity against the exact `EnvMetadataTagKind::ALL.iter().
// filter(|k| !present_env_prefix_kinds().contains(k))` walk
// this lift replaces — both the named seam and the hand-rolled
// coverage-gap must pointwise agree over every fixture. Sister
// of
// `absent_file_formats_agrees_with_open_coded_coverage_gap_walk`
// one axis over.
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("OTHER_".to_owned()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
];
for chain in &chains {
let lifted = chain.as_slice().absent_env_prefix_kinds();
let present = chain.as_slice().present_env_prefix_kinds();
let manual: Vec<EnvMetadataTagKind> = EnvMetadataTagKind::ALL
.iter()
.copied()
.filter(|k| !present.contains(k))
.collect();
assert_eq!(
lifted,
manual,
"absent_env_prefix_kinds must equal the open-coded \
coverage-gap walk over chain of length {}",
chain.len(),
);
}
}
// ---- ConfigSourceChain::absent_env_prefix_kinds_count — coverage-
// gap-size scalar peer on the env-prefix-presence sub-axis of
// the chain altitude ----
#[test]
fn absent_env_prefix_kinds_count_matches_env_prefix_kind_histogram_unobserved_cells_pointwise()
{
// The coverage-gap-size pin: `absent_env_prefix_kinds_count` routes
// through `env_prefix_kind_histogram().unobserved_cells()`, so the
// two seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-prefix-
// presence-sub-axis peer of
// `absent_file_formats_count_matches_file_format_histogram_unobserved_cells_pointwise`
// and
// `absent_layer_kinds_count_matches_layer_kind_histogram_unobserved_cells_pointwise`
// on the sister sub-axes of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![ConfigSource::Defaults, ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let via_histogram = chain
.as_slice()
.env_prefix_kind_histogram()
.unobserved_cells();
assert_eq!(
chain.as_slice().absent_env_prefix_kinds_count(),
via_histogram,
"absent_env_prefix_kinds_count must equal \
env_prefix_kind_histogram().unobserved_cells() pointwise \
over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_env_prefix_kinds_count_equals_absent_env_prefix_kinds_len_pointwise() {
// The Vec-peer identity: the scalar-count seam equals the length of
// the coverage-gap `Vec` peer. Any future re-implementation of
// either seam must keep this equality — pinned uniformly. Env-
// prefix-presence-sub-axis peer of
// `absent_file_formats_count_equals_absent_file_formats_len_pointwise`
// and
// `absent_layer_kinds_count_equals_absent_layer_kinds_len_pointwise`
// on the sister sub-axes of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_env_prefix_kinds_count(),
chain.as_slice().absent_env_prefix_kinds().len(),
);
}
}
#[test]
fn present_env_prefix_kinds_count_and_absent_env_prefix_kinds_count_partition_axis_cardinality()
{
// The fully-scalar partition law: both sides now the scalar-count
// peers, no `.len()` on either. Every env-prefix cell lies in
// exactly one of (observed, unobserved). The fully-scalar dual of
// `absent_env_prefix_kinds_and_present_env_prefix_kinds_partition_axis`
// closed on both sides. Sits alongside
// `present_env_prefix_kinds_count_and_absent_env_prefix_kinds_len_partition_axis_cardinality`
// which still uses `.len()` on the coverage-gap side. Env-prefix-
// presence-sub-axis peer of
// `present_file_formats_count_and_absent_file_formats_count_partition_axis_cardinality`
// and
// `present_layer_kinds_count_and_absent_layer_kinds_count_partition_axis_cardinality`
// on the sister sub-axes of the same chain altitude.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().present_env_prefix_kinds_count()
+ chain.as_slice().absent_env_prefix_kinds_count(),
axis_size,
"fully-scalar partition must sum to axis cardinality \
over chain of length {}",
chain.len(),
);
}
}
#[test]
fn absent_env_prefix_kinds_count_equals_axis_cardinality_minus_present_env_prefix_kinds_count()
{
// The algebraic rearrangement: the coverage-gap size equals the
// axis cardinality minus the support size, useful for consumers
// that already hold the support-size scalar. Env-prefix-presence-
// sub-axis peer of
// `absent_file_formats_count_equals_axis_cardinality_minus_present_file_formats_count`
// and
// `absent_layer_kinds_count_equals_axis_cardinality_minus_present_layer_kinds_count`
// on the sister sub-axes of the same chain altitude.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_env_prefix_kinds_count(),
axis_size - chain.as_slice().present_env_prefix_kinds_count(),
);
}
}
#[test]
fn absent_env_prefix_kinds_count_is_axis_cardinality_iff_env_prefix_kind_histogram_is_empty() {
// The empty-histogram / full-coverage-gap boundary equivalence:
// the env-prefix-presence sub-axis shares the file-format sub-
// axis's divergence from the layer-kind sub-axis — the full-axis
// boundary is tied to the histogram's own emptiness, NOT the
// chain's. Unlike
// `absent_layer_kinds_count_is_axis_cardinality_iff_chain_is_empty`,
// a non-empty chain of only Defaults / File layers still reads the
// axis cardinality because every entry projects to None through
// `env_prefix_kind()`. Peer to
// `absent_file_formats_count_is_axis_cardinality_iff_file_format_histogram_is_empty`
// on the file-format sub-axis, which shares the same divergence.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
// Empty chain: histogram empty, coverage-gap full.
let empty: Vec<ConfigSource> = Vec::new();
assert!(empty.as_slice().env_prefix_kind_histogram().is_empty());
assert_eq!(empty.as_slice().absent_env_prefix_kinds_count(), axis_size);
// Non-empty chain, empty histogram: coverage-gap still full — the
// load-bearing divergence from the layer-kind sub-axis.
let no_env = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
assert!(!no_env.is_empty());
assert!(no_env.as_slice().env_prefix_kind_histogram().is_empty());
assert_eq!(no_env.as_slice().absent_env_prefix_kinds_count(), axis_size,);
// Non-empty histogram: coverage-gap strictly less than full.
let chain = sample_chain();
assert!(!chain.as_slice().env_prefix_kind_histogram().is_empty());
assert!(chain.as_slice().absent_env_prefix_kinds_count() < axis_size);
}
#[test]
fn absent_env_prefix_kinds_count_is_zero_iff_is_full_cover() {
// The full-cover boundary equivalence in coverage-gap form: the
// coverage gap is empty iff every env-prefix kind contributed ≥1
// Env layer iff the histogram is full-cover. Env-prefix-presence-
// sub-axis scalar-count coverage-gap peer of
// `AxisHistogram::is_full_cover` and peer of
// `absent_file_formats_count_is_zero_iff_is_full_cover` /
// `absent_layer_kinds_count_is_zero_iff_is_full_cover` on the
// sister sub-axes of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().absent_env_prefix_kinds_count() == 0,
chain.as_slice().env_prefix_kind_histogram().is_full_cover(),
);
}
// Full-cover direct pin: one env layer per kind is full-cover; the
// coverage-gap scalar reads zero.
let full_cover = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
assert!(
full_cover
.as_slice()
.env_prefix_kind_histogram()
.is_full_cover()
);
assert_eq!(full_cover.as_slice().absent_env_prefix_kinds_count(), 0);
}
#[test]
fn absent_env_prefix_kinds_count_is_bounded_by_axis_cardinality() {
// The upper-bound invariant: the coverage gap of a closed-axis
// histogram is at most the axis cardinality (the unobserved-cells
// set is a subset of `EnvMetadataTagKind::ALL`). Env-prefix-
// presence-sub-axis peer of
// `absent_file_formats_count_is_bounded_by_axis_cardinality` and
// `absent_layer_kinds_count_is_bounded_by_axis_cardinality` on the
// sister sub-axes of the same chain altitude.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
assert!(chain.as_slice().absent_env_prefix_kinds_count() <= axis_size);
}
}
#[test]
fn absent_env_prefix_kinds_count_is_at_least_one_when_not_full_cover() {
// A non-full-cover recipe carries at least one absent env-prefix
// kind. The coverage-gap-side lower bound on non-full-cover, dual
// to `present_env_prefix_kinds_count_is_at_least_one_on_nonempty_histogram`
// on the observed side, and peer of
// `absent_file_formats_count_is_at_least_one_when_not_full_cover`
// / `absent_layer_kinds_count_is_at_least_one_when_not_full_cover`
// on the sister sub-axes of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
if chain.as_slice().env_prefix_kind_histogram().is_full_cover() {
continue;
}
assert!(chain.as_slice().absent_env_prefix_kinds_count() >= 1);
}
}
#[test]
fn absent_env_prefix_kinds_count_is_axis_cardinality_minus_one_iff_has_singular_support() {
// The singleton-support boundary in coverage-gap form: when
// exactly one env-prefix kind is observed, exactly `axis_cardinality
// - 1` are absent. Env-prefix-presence-sub-axis coverage-gap peer
// of `present_env_prefix_kinds_count_is_one_iff_has_singular_support`
// and
// `absent_file_formats_count_is_axis_cardinality_minus_one_iff_has_singular_support`
// /
// `absent_layer_kinds_count_is_axis_cardinality_minus_one_iff_has_singular_support`
// on the sister sub-axes of the same chain altitude.
let axis_size = crate::axis_cardinality::<EnvMetadataTagKind>();
// Singleton-support: chains carrying env layers of only one kind
// have exactly `axis_cardinality - 1` absent.
for singleton in [
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
],
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
],
] {
assert!(
singleton
.as_slice()
.env_prefix_kind_histogram()
.has_singular_support()
);
assert_eq!(
singleton.as_slice().absent_env_prefix_kinds_count(),
axis_size - 1,
);
}
// Full-cover: zero absent (< axis_size - 1).
let full_cover = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
assert!(
!full_cover
.as_slice()
.env_prefix_kind_histogram()
.has_singular_support()
);
assert!(full_cover.as_slice().absent_env_prefix_kinds_count() < axis_size - 1);
// Empty histogram: coverage gap is the full axis (> axis_size - 1).
let empty: Vec<ConfigSource> = Vec::new();
assert!(
!empty
.as_slice()
.env_prefix_kind_histogram()
.has_singular_support()
);
assert!(empty.as_slice().absent_env_prefix_kinds_count() > axis_size - 1);
}
#[test]
fn absent_env_prefix_kinds_count_agrees_with_open_coded_zero_walk() {
// Parity against the exact `EnvMetadataTagKind::ALL.iter().filter(|k|
// env_prefix_kind_histogram().count(*k) == 0).count()` walk this
// lift replaces on the coverage-gap side. Env-prefix-presence-
// sub-axis peer of
// `absent_file_formats_count_agrees_with_open_coded_zero_walk` and
// `absent_layer_kinds_count_agrees_with_open_coded_zero_walk` on
// the sister sub-axes of the same chain altitude.
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![ConfigSource::Env("APP_".to_owned())],
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
let via_seam = chain.as_slice().absent_env_prefix_kinds_count();
let hist = chain.as_slice().env_prefix_kind_histogram();
let hand_rolled = EnvMetadataTagKind::ALL
.iter()
.filter(|k| hist.count(**k) == 0)
.count();
assert_eq!(via_seam, hand_rolled);
}
}
#[test]
fn absent_env_prefix_kinds_count_empty_chain_is_axis_cardinality() {
// Direct fixture pin: an empty chain has full coverage gap so
// `absent_env_prefix_kinds_count` reads the axis cardinality
// (2 = |{Prefixed, Bare}|). Env-prefix-presence-sub-axis peer of
// `absent_file_formats_count_empty_chain_is_axis_cardinality` and
// `absent_layer_kinds_count_empty_chain_is_axis_cardinality` on
// the sister sub-axes of the same chain altitude.
let empty: Vec<ConfigSource> = Vec::new();
assert_eq!(
empty.as_slice().absent_env_prefix_kinds_count(),
crate::axis_cardinality::<EnvMetadataTagKind>(),
);
}
#[test]
fn absent_env_prefix_kinds_count_full_cover_is_zero() {
// Direct fixture pin: a chain covering every env-prefix kind has
// zero coverage gap. Env-prefix-presence-sub-axis peer of
// `absent_file_formats_count_full_cover_is_zero` and
// `absent_layer_kinds_count_full_cover_is_zero` on the sister sub-
// axes of the same chain altitude.
let full_cover = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
assert_eq!(full_cover.as_slice().absent_env_prefix_kinds_count(), 0);
}
#[test]
fn absent_env_prefix_kinds_count_sample_chain_is_one() {
// Direct fixture pin: `sample_chain` carries one Env layer with a
// prefixed name (`"APP_"`), so the histogram is {Prefixed: 1,
// Bare: 0}. The coverage-gap scalar reads 1 (only Bare absent).
// Coverage-gap peer of
// `present_env_prefix_kinds_count_sample_chain_is_one` on the same
// fixture and altitude.
let chain = sample_chain();
assert_eq!(chain.as_slice().absent_env_prefix_kinds_count(), 1);
}
#[test]
fn absent_env_prefix_kinds_count_no_env_layers_is_axis_cardinality() {
// Direct fixture pin on the env-prefix-presence sub-axis's
// divergent boundary: a non-empty chain of only Defaults and File
// layers reads the full axis cardinality because every entry
// projects to None through `env_prefix_kind()`, leaving every kind
// in the coverage gap. Companion to
// `absent_file_formats_count_no_recognized_files_is_axis_cardinality`
// on the file-format sub-axis, which shares the same divergence.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.unknown")),
];
assert!(!chain.is_empty());
assert!(chain.as_slice().env_prefix_kind_histogram().is_empty());
assert_eq!(
chain.as_slice().absent_env_prefix_kinds_count(),
crate::axis_cardinality::<EnvMetadataTagKind>(),
);
}
// ---- ConfigSourceChain::dominant_env_prefix_kind — modal-cell
// scalar peer of env_prefix_kind_histogram on the chain-shape
// altitude ----
#[test]
fn dominant_env_prefix_kind_matches_env_prefix_kind_histogram_dominant_cell_pointwise() {
// The modal-cell pin: `dominant_env_prefix_kind` routes through
// `env_prefix_kind_histogram().dominant_cell()`, so the two seams
// must stay pointwise equivalent under every fixture. Sister of
// `dominant_file_format_matches_file_format_histogram_dominant_cell_pointwise`
// and `dominant_layer_kind_matches_layer_kind_histogram_dominant_cell_pointwise`
// one sub-axis over on the same chain altitude.
let fixtures: [Vec<ConfigSource>; 7] = [
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Env(String::new())],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Defaults,
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env(String::new()),
],
];
for chain in &fixtures {
let via_histogram = chain.as_slice().env_prefix_kind_histogram().dominant_cell();
assert_eq!(
chain.as_slice().dominant_env_prefix_kind(),
via_histogram,
"dominant_env_prefix_kind must equal \
env_prefix_kind_histogram().dominant_cell() over \
chain of length {}",
chain.len(),
);
}
}
#[test]
fn dominant_env_prefix_kind_sample_chain_is_prefixed() {
// Direct pin against `sample_chain()`: two file layers + one Env
// layer with a prefixed name (`"APP_"`). Prefixed is uniquely
// dominant with 1 of 1 env layer (file/defaults layers don't
// contribute to the env-prefix-presence histogram). Sister of
// `dominant_file_format_sample_chain_is_yaml` and
// `dominant_layer_kind_sample_chain_is_file` one sub-axis over on
// the same named fixture.
let chain = sample_chain();
assert_eq!(
chain.as_slice().dominant_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
}
#[test]
fn dominant_env_prefix_kind_bare_majority_is_bare() {
// Direct pin against a bare-majority chain: three bare env layers
// + one prefixed + one file + one Defaults. Bare is uniquely
// dominant with 3 of 4 env layers. Cross-verified against
// `hist.count(Bare) == hist.peak_count() == 3`. Sister of
// `dominant_file_format_toml_majority_is_toml` and
// `dominant_layer_kind_env_majority_is_env` one sub-axis over.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(
slice.dominant_env_prefix_kind(),
Some(EnvMetadataTagKind::Bare),
);
let hist = slice.env_prefix_kind_histogram();
assert_eq!(hist.count(EnvMetadataTagKind::Bare), 3);
assert_eq!(hist.peak_count(), 3);
}
#[test]
fn dominant_env_prefix_kind_empty_chain_is_none() {
// The empty-chain / `None` boundary — every chain-level histogram
// over an empty chain is the all-zero histogram, so
// `dominant_cell` reads `None`. Peer of
// `dominant_layer_kind_empty_chain_is_none` and
// `dominant_file_format_empty_chain_is_none` on the same chain
// altitude one sub-axis over.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.dominant_env_prefix_kind(), None);
}
#[test]
fn dominant_env_prefix_kind_no_env_layers_is_none() {
// The non-empty-chain / empty-histogram boundary the env-prefix-
// presence sub-axis pins that the layer-kind sub-axis does *not*.
// A chain of only `Defaults` / `File` layers is non-empty but has
// no `Some` env_prefix_kind projection, so the histogram is empty
// and `dominant_env_prefix_kind` reads `None`. Distinguishing pin
// against a mis-implementation that would confuse
// `!self.as_ref().is_empty()` (the layer-kind sub-axis's presence
// bound) with the env-prefix-presence sub-axis's
// (`!env_prefix_kind_histogram().is_empty()`). Sister of
// `dominant_file_format_no_recognized_files_is_none` one sub-
// axis over with the env-prefix-presence sub-axis's precise
// presence bound.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.unknown")),
],
vec![
ConfigSource::File(PathBuf::from("/a.lisp")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix-kind histogram",
);
assert_eq!(chain.as_slice().dominant_env_prefix_kind(), None);
}
}
#[test]
fn dominant_env_prefix_kind_is_some_iff_histogram_is_nonempty() {
// Structural completeness of the
// `(env_prefix_kind_histogram().is_empty(), dominant_env_prefix_kind)`
// cross-surface pair. Like `dominant_file_format` and unlike
// `dominant_layer_kind`, the presence bound is the sub-axis
// histogram's `is_empty()` — a non-empty chain can still have an
// empty env-prefix-kind histogram (only `Defaults` / `File`
// layers). Sister of
// `dominant_file_format_is_some_iff_histogram_is_nonempty` one
// sub-axis over with the env-prefix-presence sub-axis's precise
// presence bound.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().dominant_env_prefix_kind().is_some(),
!chain.as_slice().env_prefix_kind_histogram().is_empty(),
);
}
}
#[test]
fn dominant_env_prefix_kind_is_member_of_present_env_prefix_kinds() {
// Structural pin: whenever `dominant_env_prefix_kind()` is
// `Some(k)`, `k` is a member of the observed-cells vector peer.
// The modal cell is by definition observed. Sister of
// `dominant_file_format_is_member_of_present_file_formats` and
// `dominant_layer_kind_is_member_of_present_layer_kinds` one
// sub-axis over.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
let dominant = chain
.as_slice()
.dominant_env_prefix_kind()
.expect("non-empty env-prefix-kind histogram has a dominant kind");
let present = chain.as_slice().present_env_prefix_kinds();
assert!(
present.contains(&dominant),
"dominant env-prefix kind {dominant:?} must appear in \
present_env_prefix_kinds() = {present:?}",
);
}
}
#[test]
fn dominant_env_prefix_kind_is_not_member_of_absent_env_prefix_kinds() {
// Structural pin: whenever `dominant_env_prefix_kind()` is
// `Some(k)`, `k` is NOT a member of the coverage-gap vector peer
// — the observed / coverage-gap partition is disjoint, so the
// modal (observed) cell is disjoint from the coverage gap.
// Sister of `dominant_file_format_is_not_member_of_absent_file_formats`
// and `dominant_layer_kind_is_not_member_of_absent_layer_kinds`
// one sub-axis over.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
let dominant = chain
.as_slice()
.dominant_env_prefix_kind()
.expect("non-empty env-prefix-kind histogram has a dominant kind");
let absent = chain.as_slice().absent_env_prefix_kinds();
assert!(
!absent.contains(&dominant),
"dominant env-prefix kind {dominant:?} must NOT appear \
in absent_env_prefix_kinds() = {absent:?}",
);
}
}
#[test]
fn dominant_env_prefix_kind_count_equals_peak_count_on_nonempty_histogram() {
// The `(dominant_cell, peak_count)` modal-pair pin:
// `hist.count(dominant_env_prefix_kind().unwrap()) ==
// hist.peak_count()` on every chain whose env-prefix-kind
// histogram is non-empty. Sister of
// `dominant_file_format_count_equals_peak_count_on_nonempty_histogram`
// one sub-axis over with the sub-axis's presence bound.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
],
];
for chain in &fixtures {
let hist = chain.as_slice().env_prefix_kind_histogram();
let dominant = chain
.as_slice()
.dominant_env_prefix_kind()
.expect("non-empty env-prefix-kind histogram has a dominant kind");
assert_eq!(hist.count(dominant), hist.peak_count());
}
}
#[test]
fn dominant_env_prefix_kind_uniform_full_cover_picks_prefixed() {
// Uniform full-cover chain — one env layer of each kind (both
// cells tied at count 1). The declaration-order tiebreak on
// `EnvMetadataTagKind::ALL` (`Prefixed → Bare`) picks the FIRST
// tied cell — `Prefixed` — not the LAST that
// `Iterator::max_by_key` would return. Sister of
// `dominant_file_format_uniform_full_cover_picks_yaml` and
// `dominant_layer_kind_uniform_cover_picks_first_cell` one sub-
// axis over.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert!(hist.is_full_cover());
assert_eq!(hist.count(EnvMetadataTagKind::Prefixed), 1);
assert_eq!(hist.count(EnvMetadataTagKind::Bare), 1);
assert_eq!(hist.peak_count(), 1);
assert_eq!(
slice.dominant_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
}
#[test]
fn dominant_env_prefix_kind_uniform_full_cover_is_insertion_order_stable() {
// Uniform full-cover chain — one env layer of each kind — but
// with insertion order flipped (bare first, prefixed second).
// The declaration-order tiebreak on `EnvMetadataTagKind::ALL`
// (`Prefixed → Bare`) still picks `Prefixed` because the tiebreak
// is off the closed-axis declaration order, NOT the chain's
// insertion order. Distinguishing pin against a
// mis-implementation that would return the cell whose most
// recent occurrence was latest in the chain (which
// `Iterator::max_by_key` walking the histogram in some other
// order could produce). Sister of the modal-pair-under-insertion-
// reorder pin on the other two sub-axes (implicit in their
// uniform-full-cover picks, but pinned explicitly here because
// the two-cell env-prefix axis surfaces the invariant most
// cleanly).
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert!(hist.is_full_cover());
assert_eq!(hist.count(EnvMetadataTagKind::Prefixed), 1);
assert_eq!(hist.count(EnvMetadataTagKind::Bare), 1);
assert_eq!(hist.peak_count(), 1);
assert_eq!(
slice.dominant_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
}
#[test]
fn dominant_env_prefix_kind_singleton_bare_chain_is_bare() {
// Strict-minority pin on the `Bare` cell: a chain of only bare
// env layers (zero prefixed) reports `Some(Bare)` — the ONLY
// observed cell wins even though it is not the first cell of
// `EnvMetadataTagKind::ALL`. Distinguishing pin against a
// mis-implementation that would return `Prefixed` (the first
// cell of `ALL`) instead of `Bare` (the only observed cell) —
// the mode is "earliest tied *observed* cell", not "first cell
// of `ALL` regardless of observation". Peer of the two-way-tie
// pins on the other two sub-axes at the single-cell-observed
// boundary.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert_eq!(hist.count(EnvMetadataTagKind::Prefixed), 0);
assert_eq!(hist.count(EnvMetadataTagKind::Bare), 2);
assert_eq!(
slice.dominant_env_prefix_kind(),
Some(EnvMetadataTagKind::Bare),
);
}
#[test]
fn dominant_env_prefix_kind_agrees_with_open_coded_argmax_walk() {
// Parity against the exact fold-forward argmax walk this lift
// replaces — spelling the declaration-order tiebreak explicitly
// with strict `>` inequality so the FIRST tied cell wins,
// mirroring `AxisHistogram::dominant_cell` rather than
// `max_by_key`'s LAST-tied-cell semantics. Sister of
// `dominant_file_format_agrees_with_open_coded_argmax_walk` and
// `dominant_layer_kind_agrees_with_open_coded_argmax_walk` one
// sub-axis over.
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::Defaults,
],
];
for chain in &chains {
let hist = chain.as_slice().env_prefix_kind_histogram();
let mut manual: Option<(EnvMetadataTagKind, usize)> = None;
for cell in EnvMetadataTagKind::ALL.iter().copied() {
let count = hist.count(cell);
if count == 0 {
continue;
}
match manual {
None => manual = Some((cell, count)),
Some((_, best)) if count > best => manual = Some((cell, count)),
_ => {}
}
}
let via_seam = chain.as_slice().dominant_env_prefix_kind();
assert_eq!(via_seam, manual.map(|(cell, _)| cell));
}
}
// ---- ConfigSourceChain::recessive_env_prefix_kind — anti-modal-cell
// scalar peer of env_prefix_kind_histogram on the chain-shape
// altitude ----
fn recessive_env_prefix_kind_fixtures() -> Vec<Vec<ConfigSource>> {
// Reused fixture set for the recessive_env_prefix_kind trait-uniform
// pins — mirrors the `dominant_env_prefix_kind_matches_...` fixture
// set at that site (seven chains covering empty, sample, empty-
// histogram-non-empty-chain, prefixed-majority, bare-majority, no-
// env-layer, and mixed shapes).
vec![
Vec::new(),
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Env(String::new())],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Defaults,
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env(String::new()),
],
]
}
#[test]
fn recessive_env_prefix_kind_matches_env_prefix_kind_histogram_recessive_cell_pointwise() {
// The anti-modal-cell pin: `recessive_env_prefix_kind` routes
// through `env_prefix_kind_histogram().recessive_cell()`, so the
// two seams must stay pointwise equivalent under every fixture.
// Direct sister of
// `recessive_file_format_matches_file_format_histogram_recessive_cell_pointwise`
// and `recessive_layer_kind_matches_layer_kind_histogram_recessive_cell_pointwise`
// one sub-axis over on the same chain altitude, and dominant-side
// peer of
// `dominant_env_prefix_kind_matches_env_prefix_kind_histogram_dominant_cell_pointwise`.
for chain in recessive_env_prefix_kind_fixtures() {
let via_histogram = chain
.as_slice()
.env_prefix_kind_histogram()
.recessive_cell();
assert_eq!(chain.as_slice().recessive_env_prefix_kind(), via_histogram,);
}
}
#[test]
fn recessive_env_prefix_kind_sample_chain_is_prefixed() {
// Direct pin against `sample_chain()`: two file layers + one Env
// layer with a prefixed name (`"APP_"`). Prefixed is the sole
// observed env-prefix kind (Bare has count 0), so it is both the
// modal AND the anti-modal cell (singleton-support degenerate).
// Peer of `recessive_file_format_sample_chain_is_yaml` on the
// same named fixture.
let chain = sample_chain();
assert_eq!(
chain.as_slice().recessive_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
assert_eq!(
chain.as_slice().recessive_env_prefix_kind(),
chain.as_slice().dominant_env_prefix_kind(),
);
}
#[test]
fn recessive_env_prefix_kind_bare_majority_is_prefixed() {
// Direct pin against a bare-majority chain: three bare env layers
// + one prefixed + one file + one Defaults. Bare is the modal cell
// at count 3; Prefixed is uniquely the anti-modal cell at count 1.
// Cross-verified against `hist.count(Prefixed) ==
// hist.trough_count() == 1`. Peer of
// `recessive_file_format_toml_majority_is_yaml` at the same
// fixture — the two projections partition the two-cell support.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(
slice.recessive_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
let hist = slice.env_prefix_kind_histogram();
assert_eq!(hist.count(EnvMetadataTagKind::Prefixed), 1);
assert_eq!(hist.count(EnvMetadataTagKind::Bare), 3);
assert_eq!(hist.trough_count(), 1);
}
#[test]
fn recessive_env_prefix_kind_empty_chain_is_none() {
// The empty-chain / `None` boundary — every chain-level histogram
// over an empty chain is the all-zero histogram, so
// `recessive_cell` reads `None`. Peer of
// `dominant_env_prefix_kind_empty_chain_is_none` on the modal
// side, and `recessive_file_format_empty_chain_is_none` /
// `recessive_layer_kind_empty_chain_is_none` on the other two
// sub-axes.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.recessive_env_prefix_kind(), None);
}
#[test]
fn recessive_env_prefix_kind_no_env_layers_is_none() {
// The non-empty-chain / empty-histogram boundary the env-prefix-
// presence sub-axis pins that the layer-kind sub-axis does *not*.
// A chain of only `Defaults` / `File` layers is non-empty but has
// no `Some` env_prefix_kind projection, so the histogram is empty
// and `recessive_env_prefix_kind` reads `None`. Distinguishing pin
// against a mis-implementation that would confuse
// `!self.as_ref().is_empty()` (the layer-kind sub-axis's presence
// bound) with the env-prefix-presence sub-axis's
// (`!env_prefix_kind_histogram().is_empty()`). Peer of
// `dominant_env_prefix_kind_no_env_layers_is_none` on the modal
// side.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.unknown")),
],
vec![
ConfigSource::File(PathBuf::from("/a.lisp")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix-kind histogram",
);
assert_eq!(chain.as_slice().recessive_env_prefix_kind(), None);
}
}
#[test]
fn recessive_env_prefix_kind_is_some_iff_histogram_is_nonempty() {
// Structural completeness of the
// `(env_prefix_kind_histogram().is_empty(), recessive_env_prefix_kind)`
// cross-surface pair. Unlike `recessive_layer_kind`, the presence
// bound is the sub-axis histogram's `is_empty()` — a non-empty
// chain can still have an empty env-prefix-kind histogram (only
// `Defaults` / `File` layers). Peer of
// `dominant_env_prefix_kind_is_some_iff_histogram_is_nonempty` on
// the modal side.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![ConfigSource::Env(String::new())],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().recessive_env_prefix_kind().is_some(),
!chain.as_slice().env_prefix_kind_histogram().is_empty(),
);
}
}
#[test]
fn recessive_env_prefix_kind_is_some_iff_dominant_env_prefix_kind_is_some() {
// Cross-projection pin lifted from the trait-uniform
// `recessive_cell().is_some() == dominant_cell().is_some()` law on
// AxisHistogram: both projections operate over the same nonzero
// support, so they agree on presence at every input. Peer of
// `recessive_file_format_is_some_iff_dominant_file_format_is_some`
// and `recessive_layer_kind_is_some_iff_dominant_layer_kind_is_some`
// on the other two sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
assert_eq!(
chain.as_slice().recessive_env_prefix_kind().is_some(),
chain.as_slice().dominant_env_prefix_kind().is_some(),
);
}
}
#[test]
fn recessive_env_prefix_kind_is_member_of_present_env_prefix_kinds() {
// Structural pin: whenever `recessive_env_prefix_kind()` is
// `Some(k)`, `k` must appear in `present_env_prefix_kinds()` —
// the anti-modal cell is taken over the support, so it is by
// definition observed. Peer of
// `dominant_env_prefix_kind_is_member_of_present_env_prefix_kinds`
// on the modal side, and
// `recessive_file_format_is_member_of_present_file_formats` /
// `recessive_layer_kind_is_member_of_present_layer_kinds` on the
// other two sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let Some(recessive) = chain.as_slice().recessive_env_prefix_kind() else {
continue;
};
let present = chain.as_slice().present_env_prefix_kinds();
assert!(
present.contains(&recessive),
"recessive env-prefix kind {recessive:?} must appear in \
present_env_prefix_kinds() = {present:?}",
);
}
}
#[test]
fn recessive_env_prefix_kind_is_not_member_of_absent_env_prefix_kinds() {
// Structural pin: whenever `recessive_env_prefix_kind()` is
// `Some(k)`, `k` must NOT appear in `absent_env_prefix_kinds()` —
// the anti-modal cell lies on the observed side of the observed /
// coverage-gap partition by construction (argmin taken over the
// nonzero support). Disjointness pin between the two named seams.
// Peer of
// `dominant_env_prefix_kind_is_not_member_of_absent_env_prefix_kinds`
// on the modal side, and
// `recessive_file_format_is_not_member_of_absent_file_formats` /
// `recessive_layer_kind_is_not_member_of_absent_layer_kinds` on
// the other two sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let Some(recessive) = chain.as_slice().recessive_env_prefix_kind() else {
continue;
};
let absent = chain.as_slice().absent_env_prefix_kinds();
assert!(
!absent.contains(&recessive),
"recessive env-prefix kind {recessive:?} must NOT appear \
in absent_env_prefix_kinds() = {absent:?}",
);
}
}
#[test]
fn recessive_env_prefix_kind_count_equals_trough_count_on_nonempty_histogram() {
// The `(recessive_cell, trough_count)` anti-modal-pair invariant
// lifted to the chain altitude: the observation count of the
// recessive env-prefix kind equals the histogram's trough count
// over the support. Peer of
// `dominant_env_prefix_kind_count_equals_peak_count_on_nonempty_histogram`
// on the modal side, and
// `recessive_file_format_count_equals_trough_count_on_nonempty_histogram`
// / `recessive_layer_kind_count_equals_trough_count_on_nonempty_chain`
// on the other two sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let Some(recessive) = chain.as_slice().recessive_env_prefix_kind() else {
continue;
};
let hist = chain.as_slice().env_prefix_kind_histogram();
assert_eq!(hist.count(recessive), hist.trough_count());
}
}
#[test]
fn recessive_env_prefix_kind_count_bounded_by_dominant_env_prefix_kind_count() {
// Structural bound lifted from the trait-uniform
// `count(recessive_cell) <= count(dominant_cell)` law on
// AxisHistogram: the trough-of-support is bounded above by the
// peak-of-support at every fixture. Cross-projection pin between
// `recessive_env_prefix_kind` and `dominant_env_prefix_kind`.
// Peer of
// `recessive_file_format_count_bounded_by_dominant_file_format_count`
// / `recessive_layer_kind_count_bounded_by_dominant_layer_kind_count`
// on the other two sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let Some(recessive) = chain.as_slice().recessive_env_prefix_kind() else {
continue;
};
let Some(dominant) = chain.as_slice().dominant_env_prefix_kind() else {
unreachable!(
"presence of recessive env-prefix kind implies \
presence of dominant env-prefix kind"
);
};
let hist = chain.as_slice().env_prefix_kind_histogram();
assert!(
hist.count(recessive) <= hist.count(dominant),
"count(recessive={recessive:?})={r} must be <= \
count(dominant={dominant:?})={d}",
r = hist.count(recessive),
d = hist.count(dominant),
);
}
}
#[test]
fn recessive_env_prefix_kind_uniform_full_cover_picks_prefixed() {
// Uniform full-cover chain — one env layer of each kind (both
// cells tied at count 1). The declaration-order tiebreak on
// `EnvMetadataTagKind::ALL` (`Prefixed → Bare`) picks the FIRST
// tied cell — `Prefixed` — pointwise identical to
// `dominant_env_prefix_kind` on the same input (the
// singleton-modality degenerate where the modal and anti-modal
// cells coincide). Peer of
// `dominant_env_prefix_kind_uniform_full_cover_picks_prefixed` on
// the modal side, and
// `recessive_file_format_uniform_full_cover_picks_yaml` /
// `recessive_layer_kind_uniform_cover_picks_first_cell` on the
// other two sub-axes.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert!(hist.is_full_cover());
assert_eq!(hist.count(EnvMetadataTagKind::Prefixed), 1);
assert_eq!(hist.count(EnvMetadataTagKind::Bare), 1);
assert_eq!(hist.trough_count(), 1);
assert_eq!(
slice.recessive_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
assert_eq!(
slice.recessive_env_prefix_kind(),
slice.dominant_env_prefix_kind(),
);
}
#[test]
fn recessive_env_prefix_kind_uniform_full_cover_is_insertion_order_stable() {
// Uniform full-cover chain — one env layer of each kind — but
// with insertion order flipped (bare first, prefixed second). The
// declaration-order tiebreak on `EnvMetadataTagKind::ALL`
// (`Prefixed → Bare`) still picks `Prefixed` because the tiebreak
// is off the closed-axis declaration order, NOT the chain's
// insertion order. Distinguishing pin against a mis-implementation
// that would return the cell whose most recent occurrence was
// latest in the chain. Peer of
// `dominant_env_prefix_kind_uniform_full_cover_is_insertion_order_stable`
// on the modal side.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert!(hist.is_full_cover());
assert_eq!(hist.count(EnvMetadataTagKind::Prefixed), 1);
assert_eq!(hist.count(EnvMetadataTagKind::Bare), 1);
assert_eq!(hist.trough_count(), 1);
assert_eq!(
slice.recessive_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
}
#[test]
fn recessive_env_prefix_kind_singleton_bare_chain_is_bare() {
// Strict-minority pin on the `Bare` cell: a chain of only bare
// env layers (zero prefixed) reports `Some(Bare)` — the ONLY
// observed cell wins even though it is not the first cell of
// `EnvMetadataTagKind::ALL`. Distinguishing pin against a
// mis-implementation that would return `Prefixed` (the first
// cell of `ALL`) instead of `Bare` (the only observed cell) —
// the anti-mode is "earliest tied *observed* cell", not "first
// cell of `ALL` regardless of observation". Peer of
// `dominant_env_prefix_kind_singleton_bare_chain_is_bare` on the
// modal side. Singleton-support degenerate on the `Bare` cell.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert_eq!(hist.count(EnvMetadataTagKind::Prefixed), 0);
assert_eq!(hist.count(EnvMetadataTagKind::Bare), 2);
assert_eq!(
slice.recessive_env_prefix_kind(),
Some(EnvMetadataTagKind::Bare),
);
assert_eq!(
slice.recessive_env_prefix_kind(),
slice.dominant_env_prefix_kind(),
);
}
#[test]
fn recessive_env_prefix_kind_singleton_support_agrees_with_dominant_env_prefix_kind() {
// Singleton-support degenerate lifted from the trait-uniform
// `distinct_cells() == 1 → dominant_cell() == recessive_cell()`
// law on AxisHistogram: when only one kind contributes, that kind
// is both the modal and the anti-modal cell. Direct construction:
// three prefixed env layers + Defaults + File (Prefixed is the
// sole observed kind). Peer of
// `recessive_file_format_singleton_support_agrees_with_dominant_file_format`
// / `recessive_layer_kind_singleton_support_agrees_with_dominant_layer_kind`
// on the other two sub-axes.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert_eq!(
slice.recessive_env_prefix_kind(),
slice.dominant_env_prefix_kind(),
);
assert_eq!(
slice.recessive_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
}
#[test]
fn recessive_env_prefix_kind_agrees_with_open_coded_argmin_walk() {
// Parity against the exact fold-forward argmin walk this lift
// replaces — spelling the declaration-order tiebreak explicitly
// with strict `<` inequality so the FIRST tied cell wins,
// mirroring `AxisHistogram::recessive_cell`. Peer of
// `dominant_env_prefix_kind_agrees_with_open_coded_argmax_walk`
// on the modal side, and
// `recessive_file_format_agrees_with_open_coded_argmin_walk` /
// `recessive_layer_kind_agrees_with_open_coded_argmin_walk` on
// the other two sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let hist = chain.as_slice().env_prefix_kind_histogram();
let mut manual: Option<(EnvMetadataTagKind, usize)> = None;
for cell in EnvMetadataTagKind::ALL.iter().copied() {
let count = hist.count(cell);
if count == 0 {
continue;
}
match manual {
None => manual = Some((cell, count)),
Some((_, best)) if count < best => manual = Some((cell, count)),
_ => {}
}
}
let via_seam = chain.as_slice().recessive_env_prefix_kind();
assert_eq!(via_seam, manual.map(|(cell, _)| cell));
}
}
// ---- ConfigSourceChain::peak_env_prefix_kind_count — modal-cell
// scalar-count peer of env_prefix_kind_histogram on the chain
// altitude, fusing with dominant_env_prefix_kind into the
// (cell, count) modal pair on the env-prefix-presence sub-axis
// of the chain-shape surface ----
#[test]
fn peak_env_prefix_kind_count_matches_env_prefix_kind_histogram_peak_count_pointwise() {
// The scalar-count pin: `peak_env_prefix_kind_count` routes
// through `env_prefix_kind_histogram().peak_count()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Direct sister of
// `peak_layer_kind_count_matches_layer_kind_histogram_peak_count_pointwise`
// and
// `peak_file_format_count_matches_file_format_histogram_peak_count_pointwise`
// on the layer-kind and file-format sub-axes of the same chain
// altitude, and
// `peak_tier_count_matches_tier_histogram_peak_count_pointwise` /
// `peak_kind_count_matches_kind_histogram_peak_count_pointwise`
// on the tier and diff altitudes.
for chain in recessive_env_prefix_kind_fixtures() {
let via_histogram = chain.as_slice().env_prefix_kind_histogram().peak_count();
assert_eq!(chain.as_slice().peak_env_prefix_kind_count(), via_histogram);
}
}
#[test]
fn peak_env_prefix_kind_count_sample_chain_is_one() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one Env layer with a prefixed name (`"APP_"`). Prefixed is the
// sole observed env-prefix kind with 1 of 1 env layer, so the
// peak count is 1. The (dominant_env_prefix_kind,
// peak_env_prefix_kind_count) modal pair reads `(Some(Prefixed),
// 1)`.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(
slice.dominant_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
assert_eq!(slice.peak_env_prefix_kind_count(), 1);
}
#[test]
fn peak_env_prefix_kind_count_bare_majority_is_three() {
// Bare-majority fixture: three bare env layers + one prefixed +
// one file + one Defaults. Bare is uniquely dominant with 3 of 4
// env layers, so the peak count is 3. Cross-verified against
// `hist.peak_count() == 3` at the same observation site — the
// fused-pair count projection reads through the seam.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(
slice.dominant_env_prefix_kind(),
Some(EnvMetadataTagKind::Bare),
);
assert_eq!(slice.peak_env_prefix_kind_count(), 3);
assert_eq!(slice.env_prefix_kind_histogram().peak_count(), 3);
}
#[test]
fn peak_env_prefix_kind_count_empty_chain_is_zero() {
// Empty-chain / zero boundary: the fused
// (dominant_env_prefix_kind, peak_env_prefix_kind_count) modal
// scalar pair reads `(None, 0)` uniformly on the empty chain,
// matching the `(AxisHistogram::dominant_cell,
// AxisHistogram::peak_count)` pair on the shared histogram
// primitive one altitude down. Peer of
// `peak_layer_kind_count_empty_chain_is_zero` on the layer-kind
// sub-axis, `peak_file_format_count_empty_chain_is_zero` on the
// file-format sub-axis, `peak_tier_count_empty_map_is_zero` on
// the tier altitude, and `peak_kind_count_empty_diff_is_zero` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.dominant_env_prefix_kind(), None);
assert_eq!(empty.peak_env_prefix_kind_count(), 0);
}
#[test]
fn peak_env_prefix_kind_count_no_env_layers_is_zero() {
// The non-empty-chain / empty-histogram boundary the env-prefix-
// presence sub-axis pins that the layer-kind sub-axis does *not*.
// A chain of only `Defaults` / `File` layers is non-empty but
// has no `Some` env_prefix_kind projection, so the histogram is
// empty and `peak_env_prefix_kind_count` reads zero.
// Distinguishing pin against a mis-implementation that would
// confuse `!self.as_ref().is_empty()` (the layer-kind sub-axis's
// zero boundary) with the env-prefix-presence sub-axis's
// (`env_prefix_kind_histogram().is_empty()`). Peer of
// `dominant_env_prefix_kind_no_env_layers_is_none` and
// `recessive_env_prefix_kind_no_env_layers_is_none` on the cell
// sides.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.unknown")),
],
vec![
ConfigSource::File(PathBuf::from("/a.lisp")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix-kind histogram",
);
assert_eq!(chain.as_slice().peak_env_prefix_kind_count(), 0);
}
}
#[test]
fn peak_env_prefix_kind_count_is_zero_iff_histogram_is_empty() {
// The `peak_env_prefix_kind_count() == 0 ⇔
// env_prefix_kind_histogram().is_empty()` presence-bound pin —
// unlike the layer-kind sub-axis (where the zero boundary is the
// chain's `is_empty()`), the env-prefix-presence sub-axis's zero
// boundary is the sub-axis histogram's `is_empty()`. Cross-axis
// divergence from `peak_layer_kind_count_is_zero_iff_chain_is_empty`.
// Direct sister of the (`dominant_env_prefix_kind().is_some() ==
// !histogram.is_empty()`) invariant on the cell side.
for chain in recessive_env_prefix_kind_fixtures() {
assert_eq!(
chain.as_slice().peak_env_prefix_kind_count() == 0,
chain.as_slice().env_prefix_kind_histogram().is_empty(),
);
}
}
#[test]
fn peak_env_prefix_kind_count_equals_count_at_dominant_env_prefix_kind_on_nonempty_histogram() {
// The `(dominant_cell, peak_count)` modal-pair invariant lifted
// to the chain altitude on the env-prefix-presence sub-axis:
// `hist.count(dominant_env_prefix_kind().unwrap()) ==
// peak_env_prefix_kind_count()` on every chain with a non-empty
// histogram. Peer of
// `peak_layer_kind_count_equals_count_at_dominant_layer_kind_on_nonempty_chain`
// on the layer-kind sub-axis and
// `peak_file_format_count_equals_count_at_dominant_file_format_on_nonempty_histogram`
// on the file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let hist = chain.as_slice().env_prefix_kind_histogram();
if hist.is_empty() {
continue;
}
let dominant = chain
.as_slice()
.dominant_env_prefix_kind()
.expect("non-empty histogram has a dominant env-prefix kind");
assert_eq!(
hist.count(dominant),
chain.as_slice().peak_env_prefix_kind_count(),
);
}
}
#[test]
fn peak_env_prefix_kind_count_equals_dominant_env_prefix_kind_map_or_count() {
// The fused-pair identity `peak_env_prefix_kind_count() ==
// dominant_env_prefix_kind().map_or(0, |k|
// env_prefix_kind_histogram().count(k))` on every input — the
// count projection of the (dominant_env_prefix_kind,
// peak_env_prefix_kind_count) modal pair reads through the seam
// uniformly across the empty-histogram / non-empty-histogram
// partition. Includes the empty-histogram boundary (`None
// .map_or(0, …) == 0 == peak_env_prefix_kind_count`) — this is
// the pin that the fused-pair identity is boundary-complete.
// Peer of
// `peak_layer_kind_count_equals_dominant_layer_kind_map_or_count`
// on the layer-kind sub-axis,
// `peak_file_format_count_equals_dominant_file_format_map_or_count`
// on the file-format sub-axis,
// `peak_tier_count_equals_dominant_tier_map_or_count` on the
// tier altitude, and
// `peak_kind_count_equals_dominant_kind_map_or_count` on the
// diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let hist = chain.as_slice().env_prefix_kind_histogram();
let via_fused_pair = chain
.as_slice()
.dominant_env_prefix_kind()
.map_or(0, |k| hist.count(k));
assert_eq!(
chain.as_slice().peak_env_prefix_kind_count(),
via_fused_pair,
);
}
}
#[test]
fn peak_env_prefix_kind_count_is_bounded_by_histogram_total() {
// Structural bound `peak_env_prefix_kind_count() <=
// env_prefix_kind_histogram().total()` on every input — the peak
// is bounded above by the total env-layer count (every kind
// contributes at most every env layer, the others contribute
// zero). Lifted from the trait-uniform `peak_count() <= total()`
// law on AxisHistogram. Peer of
// `peak_layer_kind_count_is_bounded_by_len` on the layer-kind
// sub-axis (where the total equals `self.as_ref().len()`) and
// `peak_file_format_count_is_bounded_by_histogram_total` on the
// file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert!(
slice.peak_env_prefix_kind_count() <= hist.total(),
"peak_env_prefix_kind_count()={p} must be <= histogram.total()={t}",
p = slice.peak_env_prefix_kind_count(),
t = hist.total(),
);
}
}
#[test]
fn peak_env_prefix_kind_count_is_bounded_by_env_layer_count() {
// Cross-sub-axis structural bound: the env-prefix-presence
// sub-axis's peak is bounded above by the layer-kind sub-axis's
// count of `Env` layers — every env-prefix-kind projection comes
// from an `Env` layer. Unlike the file-format sub-axis
// (`ConfigSource::file_format` is partial over `File` layers),
// this bound is an equality-at-total on the env-prefix-presence
// sub-axis: the histogram total equals the `Env` layer count
// exactly, since `ConfigSource::env_prefix_kind` is total over
// `Env` layers. Cross-sub-axis equality between
// `env_prefix_kind_histogram().total()` and
// `layer_kind_histogram().count(ConfigSourceKind::Env)`
// that the file-format sub-axis does not carry. Peer of
// `peak_file_format_count_is_bounded_by_file_layer_count` on the
// file-format sub-axis (bound only, no equality).
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let env_layer_count = slice.layer_kind_histogram().count(ConfigSourceKind::Env);
assert!(
slice.peak_env_prefix_kind_count() <= env_layer_count,
"peak_env_prefix_kind_count()={p} must be <= Env layer count={e}",
p = slice.peak_env_prefix_kind_count(),
e = env_layer_count,
);
// Total equality (env-prefix-kind projection is total over
// `Env` layers, so the histogram total equals the env layer
// count exactly on every chain).
assert_eq!(
slice.env_prefix_kind_histogram().total(),
env_layer_count,
"env_prefix_kind_histogram.total() must equal Env layer count",
);
}
}
#[test]
fn peak_env_prefix_kind_count_equals_total_iff_at_most_one_present_env_prefix_kind() {
// Structural bound `peak_env_prefix_kind_count() ==
// env_prefix_kind_histogram().total()` iff
// `present_env_prefix_kinds().len() <= 1` — the peak equals the
// histogram total exactly when zero or one kind is observed.
// Zero: empty-histogram, both zero. One: singleton-support,
// every env layer on the same kind. Two: with two distinct
// counts, peak strictly below total (on a two-cell axis this is
// the only nontrivial case). Lifted from the trait-uniform
// `peak_count() == total()` law on AxisHistogram. Peer of
// `peak_layer_kind_count_equals_len_iff_at_most_one_present_layer_kind`
// on the layer-kind sub-axis (where the total is the chain
// length) and
// `peak_file_format_count_equals_total_iff_at_most_one_present_file_format`
// on the file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert_eq!(
slice.peak_env_prefix_kind_count() == hist.total(),
slice.present_env_prefix_kinds().len() <= 1,
"peak == total iff present_env_prefix_kinds.len() <= 1 \
(peak={p}, total={t}, present={c})",
p = slice.peak_env_prefix_kind_count(),
t = hist.total(),
c = slice.present_env_prefix_kinds().len(),
);
}
}
#[test]
fn peak_env_prefix_kind_count_is_at_least_one_on_nonempty_histogram() {
// Structural pin: whenever
// `!env_prefix_kind_histogram().is_empty()`,
// `peak_env_prefix_kind_count() >= 1` — a non-empty histogram
// always has at least one env layer on the dominant kind.
// Combined with the `<= total()` bound above, this pins `1 <=
// peak_env_prefix_kind_count() <= total()` on every non-empty
// histogram. Peer of
// `peak_layer_kind_count_is_at_least_one_on_nonempty_chain` on
// the layer-kind sub-axis (where the boundary is the chain's
// `is_empty()` rather than the histogram's) and
// `peak_file_format_count_is_at_least_one_on_nonempty_histogram`
// on the file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
if hist.is_empty() {
continue;
}
assert!(
slice.peak_env_prefix_kind_count() >= 1,
"non-empty histogram must have peak_env_prefix_kind_count >= 1 (peak={p})",
p = slice.peak_env_prefix_kind_count(),
);
}
}
#[test]
fn peak_env_prefix_kind_count_uniform_full_cover_is_one() {
// Uniform full-cover chain — one env layer of each kind (both
// cells tied at count 1). Full-cover histogram with uniform
// count 1 per cell, so the peak count is 1. Combined with
// `dominant_env_prefix_kind_uniform_full_cover_picks_prefixed`
// (the cell picks `Prefixed` by declaration-order tie-breaking),
// the fused pair `(dominant_env_prefix_kind,
// peak_env_prefix_kind_count)` reads `(Some(Prefixed), 1)` on
// the uniform full-cover chain. Peer of
// `peak_layer_kind_count_uniform_cover_is_two` on the layer-kind
// sub-axis (that fixture uses two layers per kind so the peak is
// 2; here we use one layer per kind so the peak is 1) and
// `peak_file_format_count_uniform_full_cover_is_one` on the
// file-format sub-axis.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert!(hist.is_full_cover());
assert_eq!(slice.peak_env_prefix_kind_count(), 1);
assert_eq!(
slice.dominant_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
}
#[test]
fn peak_env_prefix_kind_count_singleton_support_equals_histogram_total() {
// Singleton-support degenerate: when only one kind contributes,
// every env layer lands on that kind, so the peak equals the
// histogram total. Direct construction: three prefixed env
// layers + Defaults + File (Prefixed is the sole observed
// kind). The scalar peer of the singleton-support cell
// degenerate `dominant_env_prefix_kind() ==
// recessive_env_prefix_kind()` in
// `recessive_env_prefix_kind_singleton_support_agrees_with_dominant_env_prefix_kind`
// — that test pins the *cell*; this test pins the *count*
// through the `peak_env_prefix_kind_count() == total()` equality
// on the singleton-support boundary. Peer of
// `peak_layer_kind_count_singleton_support_equals_len` on the
// layer-kind sub-axis (where the equality is against
// `self.as_ref().len()`, not the histogram total) and
// `peak_file_format_count_singleton_support_equals_histogram_total`
// on the file-format sub-axis.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert_eq!(slice.peak_env_prefix_kind_count(), hist.total());
assert_eq!(slice.peak_env_prefix_kind_count(), 3);
}
#[test]
fn peak_env_prefix_kind_count_agrees_with_open_coded_max_over_axis_walk() {
// Parity against the exact `hist.iter().map(|(_, c)| c).max()`
// walk this lift replaces — both the named seam and the
// hand-rolled max must pointwise agree over every fixture. The
// `.max().unwrap_or(0)` idiom mirrors the empty-histogram
// convention on `AxisHistogram::peak_count` one altitude down
// (both read 0 on empty). Peer of
// `peak_layer_kind_count_agrees_with_open_coded_max_over_axis_walk`
// on the layer-kind sub-axis,
// `peak_file_format_count_agrees_with_open_coded_max_over_axis_walk`
// on the file-format sub-axis,
// `peak_tier_count_agrees_with_open_coded_max_over_axis_walk`
// on the tier altitude, and
// `peak_kind_count_agrees_with_open_coded_max_over_axis_walk`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let via_seam = chain.as_slice().peak_env_prefix_kind_count();
let hand_rolled = chain
.as_slice()
.env_prefix_kind_histogram()
.iter()
.map(|(_, c)| c)
.max()
.unwrap_or(0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::trough_env_prefix_kind_count — anti-modal-cell
// scalar-count peer of env_prefix_kind_histogram on the chain
// altitude, closing the (dom, rec) × (cell, count) 2×2 scalar
// grid on the env-prefix-presence sub-axis of the chain-shape
// surface ----
#[test]
fn trough_env_prefix_kind_count_matches_env_prefix_kind_histogram_trough_count_pointwise() {
// The scalar-count pin: `trough_env_prefix_kind_count` routes
// through `env_prefix_kind_histogram().trough_count()`, so the
// two seams must stay pointwise equivalent under every fixture.
// Direct sister of
// `trough_layer_kind_count_matches_layer_kind_histogram_trough_count_pointwise`
// and
// `trough_file_format_count_matches_file_format_histogram_trough_count_pointwise`
// on the layer-kind and file-format sub-axes of the same chain
// altitude, and
// `trough_tier_count_matches_tier_histogram_trough_count_pointwise`
// / `trough_kind_count_matches_kind_histogram_trough_count_pointwise`
// on the tier and diff altitudes.
for chain in recessive_env_prefix_kind_fixtures() {
let via_histogram = chain.as_slice().env_prefix_kind_histogram().trough_count();
assert_eq!(
chain.as_slice().trough_env_prefix_kind_count(),
via_histogram,
);
}
}
#[test]
fn trough_env_prefix_kind_count_sample_chain_is_one() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one Env layer with a prefixed name (`"APP_"`). Prefixed is the
// sole observed env-prefix kind (singleton-support degenerate),
// so it is both the modal AND the anti-modal cell and the trough
// count coincides with the peak at 1. The
// (recessive_env_prefix_kind, trough_env_prefix_kind_count)
// anti-modal pair reads `(Some(Prefixed), 1)`.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(
slice.recessive_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
assert_eq!(slice.trough_env_prefix_kind_count(), 1);
assert_eq!(
slice.trough_env_prefix_kind_count(),
slice.peak_env_prefix_kind_count(),
);
}
#[test]
fn trough_env_prefix_kind_count_bare_majority_is_one() {
// Bare-majority fixture: three bare env layers + one prefixed +
// one file + one Defaults. Prefixed is uniquely anti-modal with
// 1 of 4 env layers, so the trough count is 1. Cross-verified
// against `hist.trough_count() == 1` at the same observation
// site — the fused-pair count projection reads through the
// seam.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(
slice.recessive_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
assert_eq!(slice.trough_env_prefix_kind_count(), 1);
assert_eq!(slice.env_prefix_kind_histogram().trough_count(), 1);
}
#[test]
fn trough_env_prefix_kind_count_empty_chain_is_zero() {
// Empty-chain / zero boundary: the fused
// (recessive_env_prefix_kind, trough_env_prefix_kind_count)
// anti-modal scalar pair reads `(None, 0)` uniformly on the
// empty chain, matching the `(AxisHistogram::recessive_cell,
// AxisHistogram::trough_count)` pair on the shared histogram
// primitive one altitude down. Peer of
// `trough_layer_kind_count_empty_chain_is_zero` on the
// layer-kind sub-axis,
// `trough_file_format_count_empty_chain_is_zero` on the
// file-format sub-axis, `trough_tier_count_empty_map_is_zero`
// on the tier altitude, and
// `trough_kind_count_empty_diff_is_zero` on the diff altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.recessive_env_prefix_kind(), None);
assert_eq!(empty.trough_env_prefix_kind_count(), 0);
}
#[test]
fn trough_env_prefix_kind_count_no_env_layers_is_zero() {
// The non-empty-chain / empty-histogram boundary the env-prefix-
// presence sub-axis pins that the layer-kind sub-axis does *not*.
// A chain of only `Defaults` / `File` layers is non-empty but
// has no `Some` env_prefix_kind projection, so the histogram is
// empty and `trough_env_prefix_kind_count` reads zero.
// Distinguishing pin against a mis-implementation that would
// confuse `!self.as_ref().is_empty()` (the layer-kind sub-axis's
// zero boundary) with the env-prefix-presence sub-axis's
// (`env_prefix_kind_histogram().is_empty()`). Peer of
// `peak_env_prefix_kind_count_no_env_layers_is_zero` on the
// modal count side, and
// `recessive_env_prefix_kind_no_env_layers_is_none` /
// `dominant_env_prefix_kind_no_env_layers_is_none` on the cell
// sides.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.unknown")),
],
vec![
ConfigSource::File(PathBuf::from("/a.lisp")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix-kind histogram",
);
assert_eq!(chain.as_slice().trough_env_prefix_kind_count(), 0);
}
}
#[test]
fn trough_env_prefix_kind_count_is_zero_iff_histogram_is_empty() {
// The `trough_env_prefix_kind_count() == 0 ⇔
// env_prefix_kind_histogram().is_empty()` presence-bound pin —
// unlike the layer-kind sub-axis (where the zero boundary is
// the chain's `is_empty()`), the env-prefix-presence sub-axis's
// zero boundary is the sub-axis histogram's `is_empty()`. Cross-
// axis divergence from
// `trough_layer_kind_count_is_zero_iff_chain_is_empty`. Direct
// sister of the (`recessive_env_prefix_kind().is_some() ==
// !histogram.is_empty()`) invariant on the cell side.
for chain in recessive_env_prefix_kind_fixtures() {
assert_eq!(
chain.as_slice().trough_env_prefix_kind_count() == 0,
chain.as_slice().env_prefix_kind_histogram().is_empty(),
);
}
}
#[test]
fn trough_env_prefix_kind_count_equals_count_at_recessive_env_prefix_kind_on_nonempty_histogram()
{
// The `(recessive_cell, trough_count)` anti-modal-pair invariant
// lifted to the chain altitude on the env-prefix-presence sub-
// axis: `hist.count(recessive_env_prefix_kind().unwrap()) ==
// trough_env_prefix_kind_count()` on every chain with a non-
// empty histogram. Peer of
// `trough_layer_kind_count_equals_count_at_recessive_layer_kind_on_nonempty_chain`
// on the layer-kind sub-axis (whose non-empty boundary coincides
// with `!chain.is_empty()` — the env-prefix-presence sub-axis's
// non-empty boundary is `!env_prefix_kind_histogram().is_empty()`)
// and
// `trough_file_format_count_equals_count_at_recessive_file_format_on_nonempty_histogram`
// on the file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let hist = chain.as_slice().env_prefix_kind_histogram();
if hist.is_empty() {
continue;
}
let recessive = chain
.as_slice()
.recessive_env_prefix_kind()
.expect("non-empty histogram has a recessive env-prefix kind");
assert_eq!(
hist.count(recessive),
chain.as_slice().trough_env_prefix_kind_count(),
);
}
}
#[test]
fn trough_env_prefix_kind_count_equals_recessive_env_prefix_kind_map_or_count() {
// The fused-pair identity `trough_env_prefix_kind_count() ==
// recessive_env_prefix_kind().map_or(0, |k|
// env_prefix_kind_histogram().count(k))` on every input — the
// count projection of the (recessive_env_prefix_kind,
// trough_env_prefix_kind_count) anti-modal pair reads through
// the seam uniformly across the empty-histogram / non-empty-
// histogram partition. Includes the empty-histogram boundary
// (`None.map_or(0, …) == 0 == trough_env_prefix_kind_count`) —
// this is the pin that the fused-pair identity is boundary-
// complete. Peer of
// `trough_layer_kind_count_equals_recessive_layer_kind_map_or_count`
// on the layer-kind sub-axis,
// `trough_file_format_count_equals_recessive_file_format_map_or_count`
// on the file-format sub-axis,
// `trough_tier_count_equals_recessive_tier_map_or_count` on the
// tier altitude, and
// `trough_kind_count_equals_recessive_kind_map_or_count` on the
// diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let hist = chain.as_slice().env_prefix_kind_histogram();
let via_fused_pair = chain
.as_slice()
.recessive_env_prefix_kind()
.map_or(0, |k| hist.count(k));
assert_eq!(
chain.as_slice().trough_env_prefix_kind_count(),
via_fused_pair,
);
}
}
#[test]
fn trough_env_prefix_kind_count_bounded_above_by_peak_env_prefix_kind_count() {
// Structural bound `trough_env_prefix_kind_count() <=
// peak_env_prefix_kind_count()` on every input — the trough is
// bounded above by the peak (lifted from the trait-uniform
// `trough_count() <= peak_count()` law on AxisHistogram). The
// empty-histogram case reads `0 <= 0`; the non-empty case reads
// the trough-of-support bounded above by the peak-of-support.
// Peer of
// `trough_layer_kind_count_bounded_above_by_peak_layer_kind_count`
// on the layer-kind sub-axis,
// `trough_file_format_count_bounded_above_by_peak_file_format_count`
// on the file-format sub-axis,
// `trough_tier_count_bounded_above_by_peak_tier_count` on the
// tier altitude, and
// `trough_kind_count_bounded_above_by_peak_kind_count` on the
// diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
assert!(
slice.trough_env_prefix_kind_count() <= slice.peak_env_prefix_kind_count(),
"trough_env_prefix_kind_count()={t} must be <= peak_env_prefix_kind_count()={p}",
t = slice.trough_env_prefix_kind_count(),
p = slice.peak_env_prefix_kind_count(),
);
}
}
#[test]
fn trough_env_prefix_kind_count_is_bounded_by_env_layer_count() {
// Cross-sub-axis structural bound: the env-prefix-presence sub-
// axis's trough is bounded above by the layer-kind sub-axis's
// count of `Env` layers — every env-prefix-kind projection
// comes from an `Env` layer. Unlike the file-format sub-axis
// (`ConfigSource::file_format` is partial over `File` layers),
// this bound closes against an equality-at-total on the
// env-prefix-presence sub-axis: the histogram total equals the
// `Env` layer count exactly, since
// `ConfigSource::env_prefix_kind` is total over `Env` layers.
// Cross-sub-axis exact-total equality between
// `env_prefix_kind_histogram().total()` and
// `layer_kind_histogram().count(ConfigSourceKind::Env)` that
// the file-format sub-axis does not carry. Peer of
// `peak_env_prefix_kind_count_is_bounded_by_env_layer_count` on
// the modal side, closing the `(peak, trough) <= Env-count`
// pair on the env-prefix-presence sub-axis, and
// `trough_file_format_count_is_bounded_by_file_layer_count` on
// the file-format sub-axis (bound only, no equality).
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let env_layer_count = slice.layer_kind_histogram().count(ConfigSourceKind::Env);
assert!(
slice.trough_env_prefix_kind_count() <= env_layer_count,
"trough_env_prefix_kind_count()={t} must be <= Env layer count={e}",
t = slice.trough_env_prefix_kind_count(),
e = env_layer_count,
);
assert_eq!(
slice.env_prefix_kind_histogram().total(),
env_layer_count,
"env_prefix_kind_histogram.total() must equal Env layer count",
);
}
}
#[test]
fn trough_env_prefix_kind_count_equals_peak_env_prefix_kind_count_iff_at_most_one_present_env_prefix_kind()
{
// Bidirectional structural bound `trough_env_prefix_kind_count()
// == peak_env_prefix_kind_count()` iff
// `present_env_prefix_kinds().len() <= 1`. The env-prefix-
// presence axis carries only two cells (bare × prefixed), so
// the `<= 1`-support half implies zero (empty-histogram) or
// singleton-support, both yielding `trough == peak`; the `>= 2`-
// support half means both cells are observed, but on a two-cell
// axis both cells nonzero with counts (c_bare, c_prefixed)
// where either c_bare == c_prefixed (the uniform-full-cover
// degenerate, `trough == peak` STILL holds by count-equality
// even with two present cells) or c_bare != c_prefixed (`trough
// < peak`). The one-directional `support_le_one → equal` half
// (matching the pattern in
// `trough_layer_kind_count_equals_peak_layer_kind_count_iff_at_most_one_present_layer_kind`,
// `trough_file_format_count_equals_peak_file_format_count_iff_at_most_one_present_file_format`
// on the other two sub-axes) is what this test pins, since
// the converse fails on the uniform-full-cover degenerate on
// the two-cell axis as well. Peer of the tier / diff altitude
// one-directional peers.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let equal = slice.trough_env_prefix_kind_count() == slice.peak_env_prefix_kind_count();
let support_le_one = slice.present_env_prefix_kinds().len() <= 1;
if support_le_one {
assert!(
equal,
"at_most_one_present_env_prefix_kind → trough == peak \
(trough={t}, peak={p}, present={present:?})",
t = slice.trough_env_prefix_kind_count(),
p = slice.peak_env_prefix_kind_count(),
present = slice.present_env_prefix_kinds(),
);
}
}
}
#[test]
fn trough_env_prefix_kind_count_is_at_least_one_on_nonempty_histogram() {
// Structural pin: whenever
// `!env_prefix_kind_histogram().is_empty()`,
// `trough_env_prefix_kind_count() >= 1` — the argmin is taken
// over the histogram's *support* (nonzero cells), so the trough
// of a non-empty histogram is always at least one. Combined
// with the `<= peak_env_prefix_kind_count()` bound above, this
// pins `1 <= trough_env_prefix_kind_count() <=
// peak_env_prefix_kind_count()` on every non-empty histogram.
// Peer of
// `trough_layer_kind_count_is_at_least_one_on_nonempty_chain`
// on the layer-kind sub-axis (where the boundary is the chain's
// `is_empty()` rather than the histogram's) and
// `trough_file_format_count_is_at_least_one_on_nonempty_histogram`
// on the file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
if hist.is_empty() {
continue;
}
assert!(
slice.trough_env_prefix_kind_count() >= 1,
"non-empty histogram must have trough_env_prefix_kind_count >= 1 (trough={t})",
t = slice.trough_env_prefix_kind_count(),
);
}
}
#[test]
fn trough_env_prefix_kind_count_uniform_full_cover_is_one() {
// Uniform full-cover chain — one env layer of each kind (both
// cells tied at count 1). Full-cover histogram with uniform
// count 1 per cell, so the trough count coincides with the
// peak count at 1 (the uniform-cover degenerate where every
// cell equals the modal cell). Direct sister of
// `peak_env_prefix_kind_count_uniform_full_cover_is_one` — the
// same fixture read on the trough side. Combined with
// `recessive_env_prefix_kind_uniform_full_cover_picks_prefixed`
// (the cell picks Prefixed by declaration-order tie-breaking),
// the fused pair `(recessive_env_prefix_kind,
// trough_env_prefix_kind_count)` reads `(Some(Prefixed), 1)`
// on the uniform full-cover chain. Peer of
// `trough_layer_kind_count_uniform_cover_is_two` on the
// layer-kind sub-axis (that fixture uses two layers per kind so
// the trough is 2; here we use one layer per kind so the trough
// is 1) and
// `trough_file_format_count_uniform_full_cover_is_one` on the
// file-format sub-axis.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert!(hist.is_full_cover());
assert_eq!(slice.trough_env_prefix_kind_count(), 1);
assert_eq!(
slice.trough_env_prefix_kind_count(),
slice.peak_env_prefix_kind_count(),
);
assert_eq!(
slice.recessive_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
}
#[test]
fn trough_env_prefix_kind_count_singleton_support_equals_histogram_total() {
// Singleton-support degenerate: when only one kind contributes,
// every env layer lands on that kind, so both trough and peak
// equal the histogram total. Direct construction: three
// prefixed env layers + Defaults + File (Prefixed is the sole
// observed kind). The scalar peer of the singleton-support
// cell degenerate `dominant_env_prefix_kind() ==
// recessive_env_prefix_kind()` in
// `recessive_env_prefix_kind_singleton_support_agrees_with_dominant_env_prefix_kind`
// — that test pins the *cell*; this test pins the *count*
// through the `trough_env_prefix_kind_count() == total()`
// equality on the singleton-support boundary. Peer of
// `peak_env_prefix_kind_count_singleton_support_equals_histogram_total`
// on the modal side and
// `trough_file_format_count_singleton_support_equals_histogram_total`
// on the file-format sub-axis.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert_eq!(slice.trough_env_prefix_kind_count(), hist.total());
assert_eq!(slice.trough_env_prefix_kind_count(), 3);
assert_eq!(
slice.trough_env_prefix_kind_count(),
slice.peak_env_prefix_kind_count(),
);
}
#[test]
fn trough_env_prefix_kind_count_agrees_with_open_coded_min_over_support_walk() {
// Parity against the exact
// `hist.iter().filter(|(_, c)| *c > 0).map(|(_, c)| c).min()`
// walk this lift replaces — both the named seam and the
// hand-rolled min-over-support must pointwise agree over every
// fixture. The `.min().unwrap_or(0)` idiom mirrors the empty-
// histogram convention on `AxisHistogram::trough_count` one
// altitude down (both read 0 on empty). The `filter(|(_, c)|
// *c > 0)` step is the load-bearing seam: the naive `.min()`
// over the full axis would silently pick zero-count absent
// cells on any non-full-cover histogram, shadowing the trough-
// of-support the seam surfaces. Peer of
// `trough_layer_kind_count_agrees_with_open_coded_min_over_support_walk`
// on the layer-kind sub-axis,
// `trough_file_format_count_agrees_with_open_coded_min_over_support_walk`
// on the file-format sub-axis,
// `trough_tier_count_agrees_with_open_coded_min_over_support_walk`
// on the tier altitude, and
// `trough_kind_count_agrees_with_open_coded_min_over_support_walk`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let via_seam = chain.as_slice().trough_env_prefix_kind_count();
let hand_rolled = chain
.as_slice()
.env_prefix_kind_histogram()
.iter()
.map(|(_, c)| c)
.filter(|&c| c > 0)
.min()
.unwrap_or(0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::dominant_layer_kind — modal-cell scalar
// peer of layer_kind_histogram on the chain-shape altitude ----
#[test]
fn dominant_layer_kind_matches_layer_kind_histogram_dominant_cell_pointwise() {
// The modal-cell pin: `dominant_layer_kind` routes through
// `layer_kind_histogram().dominant_cell()`, so the two seams
// must stay pointwise equivalent under every fixture. Direct
// sister of
// `dominant_tier_matches_tier_histogram_dominant_cell_pointwise`
// and
// `dominant_kind_matches_kind_histogram_dominant_cell_pointwise`
// on the tier and diff altitudes.
let fixtures: [Vec<ConfigSource>; 6] = [
Vec::new(),
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let via_histogram = chain.as_slice().layer_kind_histogram().dominant_cell();
assert_eq!(chain.as_slice().dominant_layer_kind(), via_histogram);
}
}
#[test]
fn dominant_layer_kind_sample_chain_is_file() {
// Direct pin against `sample_chain()`: two File layers + one
// Env layer (no Defaults). File is uniquely dominant with 2 of
// 3 layers. Peer of
// `dominant_tier_prog_fixture_is_default` on the tier altitude
// — one direct majority-cell pin against a named fixture.
let chain = sample_chain();
assert_eq!(
chain.as_slice().dominant_layer_kind(),
Some(ConfigSourceKind::File),
);
}
#[test]
fn dominant_layer_kind_env_majority_is_env() {
// Direct pin against an env-majority chain: three Env layers +
// one File + one Defaults. Env is uniquely dominant with 3 of
// 5 layers. Cross-verified against
// `hist.count(Env) == hist.peak_count() == 3` at the same
// observation site.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.dominant_layer_kind(), Some(ConfigSourceKind::Env));
let hist = slice.layer_kind_histogram();
assert_eq!(hist.count(ConfigSourceKind::Env), 3);
assert_eq!(hist.peak_count(), 3);
}
#[test]
fn dominant_layer_kind_empty_chain_is_none() {
// The empty-chain / `None` boundary — every chain-level
// histogram over an empty chain is the all-zero histogram, so
// `dominant_cell` reads `None`. Peer of
// `dominant_tier_empty_map_is_none` on the tier altitude and
// `dominant_kind_empty_diff_is_none` on the diff altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.dominant_layer_kind(), None);
}
#[test]
fn dominant_layer_kind_is_some_iff_chain_is_nonempty() {
// Structural completeness of the `(is_empty, dominant_layer_kind)`
// cross-surface pair. Every non-empty chain contributes at least
// one layer to the layer-kind histogram (unlike the file-format
// and env-prefix sub-axes, which can be empty on a non-empty
// chain), so the presence bound is precisely `is_empty`. Peer
// of `dominant_tier_is_some_iff_map_is_nonempty` on the tier
// altitude — same structural completeness pin.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().dominant_layer_kind().is_some(),
!chain.is_empty(),
);
}
}
#[test]
fn dominant_layer_kind_is_member_of_present_layer_kinds() {
// Structural pin: whenever `dominant_layer_kind()` is
// `Some(k)`, `k` is a member of the observed-cells vector
// peer. The modal cell is by definition observed. Peer of
// `dominant_tier_is_member_of_contributing_tiers` on the tier
// altitude.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Defaults],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
let dominant = chain
.as_slice()
.dominant_layer_kind()
.expect("non-empty chain has a dominant layer kind");
let present = chain.as_slice().present_layer_kinds();
assert!(
present.contains(&dominant),
"dominant layer kind {dominant:?} must appear in \
present_layer_kinds() = {present:?}",
);
}
}
#[test]
fn dominant_layer_kind_is_not_member_of_absent_layer_kinds() {
// Structural pin: whenever `dominant_layer_kind()` is
// `Some(k)`, `k` is NOT a member of the coverage-gap vector
// peer — the observed / coverage-gap partition is disjoint,
// so the modal (observed) cell is disjoint from the coverage
// gap. Peer of `dominant_tier_is_not_member_of_absent_tiers`
// on the tier altitude.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Defaults],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
let dominant = chain
.as_slice()
.dominant_layer_kind()
.expect("non-empty chain has a dominant layer kind");
let absent = chain.as_slice().absent_layer_kinds();
assert!(
!absent.contains(&dominant),
"dominant layer kind {dominant:?} must NOT appear in \
absent_layer_kinds() = {absent:?}",
);
}
}
#[test]
fn dominant_layer_kind_count_equals_peak_count_on_nonempty_chain() {
// The `(dominant_cell, peak_count)` modal-pair pin:
// `hist.count(dominant_layer_kind().unwrap()) ==
// hist.peak_count()` on every non-empty chain. Peer of
// `dominant_tier_count_equals_peak_count_on_nonempty_map` on
// the tier altitude.
let fixtures: [Vec<ConfigSource>; 4] = [
sample_chain(),
vec![ConfigSource::Defaults, ConfigSource::Defaults],
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &fixtures {
let hist = chain.as_slice().layer_kind_histogram();
let dominant = chain
.as_slice()
.dominant_layer_kind()
.expect("non-empty chain has a dominant layer kind");
assert_eq!(hist.count(dominant), hist.peak_count());
}
}
#[test]
fn dominant_layer_kind_ties_broken_by_declaration_order() {
// Uniform-cover chain — one layer of each kind (all three
// cells tied at count 1). The declaration-order tiebreak on
// `ConfigSourceKind::ALL` (`Defaults → Env → File`) picks the
// FIRST tied cell — `Defaults` — not the LAST that
// `Iterator::max_by_key` would return. Peer of
// `dominant_tier_ties_broken_by_declaration_order` on the
// tier altitude and
// `dominant_kind_three_way_tie_picks_first_declared_cell` on
// the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
];
let slice = chain.as_slice();
let hist = slice.layer_kind_histogram();
assert_eq!(hist.count(ConfigSourceKind::Defaults), 1);
assert_eq!(hist.count(ConfigSourceKind::Env), 1);
assert_eq!(hist.count(ConfigSourceKind::File), 1);
assert_eq!(hist.peak_count(), 1);
assert_eq!(
slice.dominant_layer_kind(),
Some(ConfigSourceKind::Defaults)
);
}
#[test]
fn dominant_layer_kind_two_way_tie_picks_earliest_declared_observed_cell() {
// Two-way tie between cells that are NOT the first cell of
// `ConfigSourceKind::ALL`: 2 Env + 2 File, zero Defaults. Env
// wins because it is earlier in `ALL` than File — the tiebreak
// is "earliest tied observed cell", not "first cell of `ALL`
// regardless of observation" (Defaults appears in `ALL` before
// Env but has zero count, so it doesn't participate in the
// tie). Distinguishing pin against a mis-implementation that
// would return `Defaults` (the first cell of `ALL`) instead of
// `Env` (the first tied observed cell). Peer of
// `dominant_kind_two_way_tie_picks_earliest_declared_observed_cell`
// on the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::Env("OTHER_".to_owned()),
];
let slice = chain.as_slice();
let hist = slice.layer_kind_histogram();
assert_eq!(hist.count(ConfigSourceKind::Defaults), 0);
assert_eq!(hist.count(ConfigSourceKind::Env), 2);
assert_eq!(hist.count(ConfigSourceKind::File), 2);
assert_eq!(slice.dominant_layer_kind(), Some(ConfigSourceKind::Env));
}
#[test]
fn dominant_layer_kind_agrees_with_open_coded_argmax_walk() {
// Parity against the exact fold-forward argmax walk this lift
// replaces — spelling the declaration-order tiebreak
// explicitly with strict `>` inequality so the FIRST tied cell
// wins, mirroring `AxisHistogram::dominant_cell` rather than
// `max_by_key`'s LAST-tied-cell semantics. Peer of
// `dominant_tier_agrees_with_open_coded_argmax_walk` on the
// tier altitude.
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("OTHER_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::Env("OTHER_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &chains {
let hist = chain.as_slice().layer_kind_histogram();
let mut manual: Option<(ConfigSourceKind, usize)> = None;
for cell in ConfigSourceKind::ALL.iter().copied() {
let count = hist.count(cell);
if count == 0 {
continue;
}
match manual {
None => manual = Some((cell, count)),
Some((_, best)) if count > best => manual = Some((cell, count)),
_ => {}
}
}
let via_seam = chain.as_slice().dominant_layer_kind();
assert_eq!(via_seam, manual.map(|(cell, _)| cell));
}
}
#[test]
fn dominant_layer_kind_uniform_cover_picks_first_cell() {
// Trait-uniform uniform-cover invariant: a full-cover chain
// with uniform count 2 per kind (2 Defaults + 2 Env + 2 File)
// picks `Some(Defaults)` — the first cell in
// `ConfigSourceKind::ALL`. Peer of
// `dominant_tier_uniform_cover_picks_first_cell` on the tier
// altitude and
// `dominant_kind_uniform_cover_picks_first_cell` on the diff
// altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
let slice = chain.as_slice();
let hist = slice.layer_kind_histogram();
assert!(hist.is_full_cover());
assert_eq!(hist.count(ConfigSourceKind::Defaults), 2);
assert_eq!(hist.count(ConfigSourceKind::Env), 2);
assert_eq!(hist.count(ConfigSourceKind::File), 2);
assert_eq!(
slice.dominant_layer_kind(),
Some(ConfigSourceKind::Defaults)
);
}
// ---- ConfigSourceChain::recessive_layer_kind — anti-modal-cell
// scalar peer of layer_kind_histogram on the chain-shape
// altitude ----
fn recessive_layer_kind_fixtures() -> Vec<Vec<ConfigSource>> {
// Reused fixture set for the recessive_layer_kind trait-uniform
// pins — mirrors the `dominant_layer_kind_matches_...` fixture
// set at that site (six chains covering empty, sample, two-cell,
// env-only, three-cell, and full-cover shapes).
vec![
Vec::new(),
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
],
]
}
#[test]
fn recessive_layer_kind_matches_layer_kind_histogram_recessive_cell_pointwise() {
// The anti-modal-cell pin: `recessive_layer_kind` routes through
// `layer_kind_histogram().recessive_cell()`, so the two seams
// must stay pointwise equivalent under every fixture. Direct
// sister of
// `recessive_tier_matches_tier_histogram_recessive_cell_pointwise`
// and `recessive_kind_matches_kind_histogram_recessive_cell_pointwise`
// on the tier and diff altitudes, and dominant-side peer of
// `dominant_layer_kind_matches_layer_kind_histogram_dominant_cell_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let via_histogram = chain.as_slice().layer_kind_histogram().recessive_cell();
assert_eq!(chain.as_slice().recessive_layer_kind(), via_histogram);
}
}
#[test]
fn recessive_layer_kind_sample_chain_is_env() {
// Direct pin against `sample_chain()`: two File layers + one Env
// layer (no Defaults). The support {Env, File} is Env=1, File=2
// — Env is uniquely the recessive cell at count 1. Peer of
// `dominant_layer_kind_sample_chain_is_file` on the same fixture
// — the two projections partition the two-cell support.
let chain = sample_chain();
assert_eq!(
chain.as_slice().recessive_layer_kind(),
Some(ConfigSourceKind::Env),
);
}
#[test]
fn recessive_layer_kind_env_majority_is_file() {
// Direct pin against an env-majority chain: three Env layers +
// one File + one Defaults. The support {Defaults, Env, File}
// reads Defaults=1, Env=3, File=1 — Defaults is the earliest
// declaration-order cell at the trough count 1, so it wins the
// tie against File on declaration order. Cross-verified against
// the per-kind counts on the underlying histogram. Peer of
// `dominant_layer_kind_env_majority_is_env` at the same fixture
// — the modal and anti-modal cells partition the same support.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(
slice.recessive_layer_kind(),
Some(ConfigSourceKind::Defaults),
);
let hist = slice.layer_kind_histogram();
assert_eq!(hist.count(ConfigSourceKind::Defaults), 1);
assert_eq!(hist.count(ConfigSourceKind::File), 1);
assert_eq!(hist.trough_count(), 1);
}
#[test]
fn recessive_layer_kind_empty_chain_is_none() {
// The empty-chain / `None` boundary — every chain-level histogram
// over an empty chain is the all-zero histogram, so
// `recessive_cell` reads `None`. Peer of
// `dominant_layer_kind_empty_chain_is_none` on the modal side,
// and `recessive_tier_empty_map_is_none` /
// `recessive_kind_empty_diff_is_none` on the tier and diff
// altitudes.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.recessive_layer_kind(), None);
}
#[test]
fn recessive_layer_kind_is_some_iff_chain_is_nonempty() {
// Structural completeness of the `(is_empty, recessive_layer_kind)`
// cross-surface pair. Every non-empty chain contributes at least
// one layer to the layer-kind histogram (unlike the file-format
// and env-prefix sub-axes, which can be empty on a non-empty
// chain), so the presence bound is precisely `is_empty`. Peer
// of `dominant_layer_kind_is_some_iff_chain_is_nonempty` on the
// modal side.
let fixtures: [Vec<ConfigSource>; 5] = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
],
];
for chain in &fixtures {
assert_eq!(
chain.as_slice().recessive_layer_kind().is_some(),
!chain.is_empty(),
);
}
}
#[test]
fn recessive_layer_kind_is_some_iff_dominant_layer_kind_is_some() {
// Cross-projection pin lifted from the trait-uniform
// `recessive_cell().is_some() == dominant_cell().is_some()` law
// on AxisHistogram: both projections operate over the same
// nonzero support, so they agree on presence at every input.
// Peer of `recessive_tier_is_some_iff_dominant_tier_is_some` and
// `recessive_kind_is_some_iff_dominant_kind_is_some`.
for chain in recessive_layer_kind_fixtures() {
assert_eq!(
chain.as_slice().recessive_layer_kind().is_some(),
chain.as_slice().dominant_layer_kind().is_some(),
);
}
}
#[test]
fn recessive_layer_kind_is_member_of_present_layer_kinds() {
// Structural pin: whenever `recessive_layer_kind()` is `Some(k)`,
// `k` must appear in `present_layer_kinds()` — the anti-modal
// cell is taken over the support, so it is by definition
// observed. Peer of
// `dominant_layer_kind_is_member_of_present_layer_kinds` on the
// modal side, and `recessive_kind_is_member_of_present_kinds` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let Some(recessive) = chain.as_slice().recessive_layer_kind() else {
continue;
};
let present = chain.as_slice().present_layer_kinds();
assert!(
present.contains(&recessive),
"recessive layer kind {recessive:?} must appear in \
present_layer_kinds() = {present:?}",
);
}
}
#[test]
fn recessive_layer_kind_is_not_member_of_absent_layer_kinds() {
// Structural pin: whenever `recessive_layer_kind()` is `Some(k)`,
// `k` must NOT appear in `absent_layer_kinds()` — the anti-modal
// cell lies on the observed side of the observed / coverage-gap
// partition by construction (argmin taken over the nonzero
// support). Disjointness pin between the two named seams. Peer
// of `dominant_layer_kind_is_not_member_of_absent_layer_kinds`
// on the modal side, and
// `recessive_kind_is_not_member_of_absent_kinds` on the diff
// altitude.
for chain in recessive_layer_kind_fixtures() {
let Some(recessive) = chain.as_slice().recessive_layer_kind() else {
continue;
};
let absent = chain.as_slice().absent_layer_kinds();
assert!(
!absent.contains(&recessive),
"recessive layer kind {recessive:?} must NOT appear in \
absent_layer_kinds() = {absent:?}",
);
}
}
#[test]
fn recessive_layer_kind_count_equals_trough_count_on_nonempty_chain() {
// The `(recessive_cell, trough_count)` anti-modal-pair invariant
// lifted to the chain altitude: the observation count of the
// recessive layer kind equals the histogram's trough count over
// the support. Peer of
// `dominant_layer_kind_count_equals_peak_count_on_nonempty_chain`
// on the modal side, and
// `recessive_kind_count_equals_trough_count_on_nonempty_diff` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let Some(recessive) = chain.as_slice().recessive_layer_kind() else {
continue;
};
let hist = chain.as_slice().layer_kind_histogram();
assert_eq!(hist.count(recessive), hist.trough_count());
}
}
#[test]
fn recessive_layer_kind_count_bounded_by_dominant_layer_kind_count() {
// Structural bound lifted from the trait-uniform
// `count(recessive_cell) <= count(dominant_cell)` law on
// AxisHistogram: the trough-of-support is bounded above by the
// peak-of-support at every fixture. Cross-projection pin between
// `recessive_layer_kind` and `dominant_layer_kind`. Peer of
// `recessive_kind_count_bounded_by_dominant_kind_count` on the
// diff altitude.
for chain in recessive_layer_kind_fixtures() {
let Some(recessive) = chain.as_slice().recessive_layer_kind() else {
continue;
};
let Some(dominant) = chain.as_slice().dominant_layer_kind() else {
unreachable!("presence of recessive kind implies presence of dominant kind");
};
let hist = chain.as_slice().layer_kind_histogram();
assert!(
hist.count(recessive) <= hist.count(dominant),
"count(recessive={recessive:?})={r} must be <= count(dominant={dominant:?})={d}",
r = hist.count(recessive),
d = hist.count(dominant),
);
}
}
#[test]
fn recessive_layer_kind_ties_broken_by_declaration_order() {
// Uniform-cover chain — one layer of each kind (all three cells
// tied at count 1). The declaration-order tiebreak on
// `ConfigSourceKind::ALL` (`Defaults → Env → File`) picks the
// FIRST tied cell — `Defaults` — pointwise identical to
// `dominant_layer_kind` on the same input (the singleton-
// modality degenerate where the modal and anti-modal cells
// coincide). Peer of
// `dominant_layer_kind_ties_broken_by_declaration_order` on the
// modal side and
// `recessive_kind_ties_broken_by_declaration_order` on the diff
// altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Defaults,
];
let slice = chain.as_slice();
let hist = slice.layer_kind_histogram();
assert_eq!(hist.count(ConfigSourceKind::Defaults), 1);
assert_eq!(hist.count(ConfigSourceKind::Env), 1);
assert_eq!(hist.count(ConfigSourceKind::File), 1);
assert!(hist.is_full_cover());
assert_eq!(
slice.recessive_layer_kind(),
Some(ConfigSourceKind::Defaults),
);
assert_eq!(slice.recessive_layer_kind(), slice.dominant_layer_kind());
}
#[test]
fn recessive_layer_kind_two_way_tie_picks_earliest_declared_observed_cell() {
// Two-way tie between cells that are NOT the first cell of
// `ConfigSourceKind::ALL`: 3 Defaults + 1 Env + 1 File, so the
// support {Defaults, Env, File} has trough count 1 with Env and
// File tied. Env wins because it precedes File in `ALL` — the
// tiebreak is "earliest tied observed cell at the trough", not
// "first cell of `ALL` regardless of trough participation"
// (Defaults appears in `ALL` before Env but has count 3 and does
// not participate in the trough tie). Distinguishing pin against
// a mis-implementation that would return `Defaults` (the first
// cell of `ALL`) instead of `Env` (the first tied observed cell
// at the trough). Peer of
// `dominant_layer_kind_two_way_tie_picks_earliest_declared_observed_cell`
// on the modal side.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
let hist = slice.layer_kind_histogram();
assert_eq!(hist.count(ConfigSourceKind::Defaults), 3);
assert_eq!(hist.count(ConfigSourceKind::Env), 1);
assert_eq!(hist.count(ConfigSourceKind::File), 1);
assert_eq!(hist.trough_count(), 1);
assert_eq!(slice.recessive_layer_kind(), Some(ConfigSourceKind::Env));
}
#[test]
fn recessive_layer_kind_singleton_support_agrees_with_dominant_layer_kind() {
// Singleton-support degenerate lifted from the trait-uniform
// `distinct_cells() == 1 → dominant_cell() == recessive_cell()`
// law on AxisHistogram: when only one kind contributes, that
// kind is both the modal and the anti-modal cell. Direct
// construction: three layers, all File. Peer of
// `recessive_tier_singleton_support_agrees_with_dominant_tier`
// and
// `recessive_kind_singleton_support_agrees_with_dominant_kind`.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert_eq!(slice.recessive_layer_kind(), slice.dominant_layer_kind());
assert_eq!(slice.recessive_layer_kind(), Some(ConfigSourceKind::File));
}
#[test]
fn recessive_layer_kind_agrees_with_open_coded_argmin_walk() {
// Parity against the exact fold-forward argmin walk this lift
// replaces — spelling the declaration-order tiebreak explicitly
// with strict `<` inequality so the FIRST tied cell wins,
// mirroring `AxisHistogram::recessive_cell`, rather than
// `min_by_key`'s FIRST-tied-cell semantics which agrees by
// coincidence but drifts under any reversed comparison. Peer of
// `dominant_layer_kind_agrees_with_open_coded_argmax_walk` on
// the modal side and
// `recessive_kind_agrees_with_open_coded_argmin_walk` on the
// diff altitude.
for chain in recessive_layer_kind_fixtures() {
let hist = chain.as_slice().layer_kind_histogram();
let mut manual: Option<(ConfigSourceKind, usize)> = None;
for cell in ConfigSourceKind::ALL.iter().copied() {
let count = hist.count(cell);
if count == 0 {
continue;
}
match manual {
None => manual = Some((cell, count)),
Some((_, best)) if count < best => manual = Some((cell, count)),
_ => {}
}
}
let via_seam = chain.as_slice().recessive_layer_kind();
assert_eq!(via_seam, manual.map(|(cell, _)| cell));
}
}
#[test]
fn recessive_layer_kind_uniform_cover_picks_first_cell() {
// Trait-uniform uniform-cover invariant: a full-cover chain with
// uniform count 2 per kind (2 Defaults + 2 Env + 2 File) picks
// `Some(Defaults)` — the first cell in `ConfigSourceKind::ALL`
// — and equals `dominant_layer_kind` on the same input (the
// singleton-modality degenerate). Peer of
// `dominant_layer_kind_uniform_cover_picks_first_cell` on the
// modal side and
// `recessive_kind_uniform_cover_picks_first_cell` on the diff
// altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
let slice = chain.as_slice();
let hist = slice.layer_kind_histogram();
assert!(hist.is_full_cover());
assert_eq!(hist.count(ConfigSourceKind::Defaults), 2);
assert_eq!(hist.count(ConfigSourceKind::Env), 2);
assert_eq!(hist.count(ConfigSourceKind::File), 2);
assert_eq!(
slice.recessive_layer_kind(),
Some(ConfigSourceKind::Defaults),
);
assert_eq!(slice.recessive_layer_kind(), slice.dominant_layer_kind());
}
// ---- ConfigSourceChain::peak_layer_kind_count — modal-cell scalar-
// count peer of layer_kind_histogram on the chain altitude,
// fusing with dominant_layer_kind into the (cell, count) modal
// pair on the layer-kind sub-axis of the chain-shape surface ----
#[test]
fn peak_layer_kind_count_matches_layer_kind_histogram_peak_count_pointwise() {
// The scalar-count pin: `peak_layer_kind_count` routes through
// `layer_kind_histogram().peak_count()`, so the two seams must
// stay pointwise equivalent under every fixture. Direct sister
// of `peak_tier_count_matches_tier_histogram_peak_count_pointwise`
// and `peak_kind_count_matches_kind_histogram_peak_count_pointwise`
// on the tier and diff altitudes.
for chain in recessive_layer_kind_fixtures() {
let via_histogram = chain.as_slice().layer_kind_histogram().peak_count();
assert_eq!(chain.as_slice().peak_layer_kind_count(), via_histogram);
}
}
#[test]
fn peak_layer_kind_count_sample_chain_is_two() {
// Direct pin against `sample_chain()`: two File layers + one Env
// layer (no Defaults). File is uniquely dominant with 2 of 3
// layers, so the peak count is 2. The (dominant_layer_kind,
// peak_layer_kind_count) modal pair reads `(Some(File), 2)`.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.dominant_layer_kind(), Some(ConfigSourceKind::File));
assert_eq!(slice.peak_layer_kind_count(), 2);
}
#[test]
fn peak_layer_kind_count_env_majority_is_three() {
// Env-majority fixture: three Env layers + one File + one
// Defaults. Env is uniquely dominant with 3 of 5 layers, so the
// peak count is 3. Cross-verified against `hist.peak_count() ==
// 3` at the same observation site — the fused-pair count
// projection reads through the seam.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.dominant_layer_kind(), Some(ConfigSourceKind::Env));
assert_eq!(slice.peak_layer_kind_count(), 3);
assert_eq!(slice.layer_kind_histogram().peak_count(), 3);
}
#[test]
fn peak_layer_kind_count_empty_chain_is_zero() {
// Empty-chain / zero boundary: the fused
// (dominant_layer_kind, peak_layer_kind_count) modal scalar pair
// reads `(None, 0)` uniformly on the empty chain, matching the
// `(AxisHistogram::dominant_cell, AxisHistogram::peak_count)`
// pair on the shared histogram primitive one altitude down.
// Peer of `peak_tier_count_empty_map_is_zero` on the tier
// altitude and `peak_kind_count_empty_diff_is_zero` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.dominant_layer_kind(), None);
assert_eq!(empty.peak_layer_kind_count(), 0);
}
#[test]
fn peak_layer_kind_count_is_zero_iff_chain_is_empty() {
// The `peak_layer_kind_count() == 0 ⇔ self.as_ref().is_empty()`
// presence-bound pin — every layer projects to exactly one
// `ConfigSourceKind` cell through `ConfigSource::kind`, so a
// non-empty chain always contributes a positive peak, and an
// empty chain always reads zero. Cross-axis divergence from the
// file-format and env-prefix sub-axes, whose zero-peak boundary
// is the corresponding histogram's `is_empty()`. Direct sister
// of `peak_tier_count_is_zero_iff_map_is_empty` on the tier
// altitude.
for chain in recessive_layer_kind_fixtures() {
assert_eq!(
chain.as_slice().peak_layer_kind_count() == 0,
chain.as_slice().is_empty(),
);
}
}
#[test]
fn peak_layer_kind_count_equals_count_at_dominant_layer_kind_on_nonempty_chain() {
// The `(dominant_cell, peak_count)` modal-pair invariant lifted
// to the chain altitude on the layer-kind sub-axis:
// `hist.count(dominant_layer_kind().unwrap()) ==
// peak_layer_kind_count()` on every non-empty chain. Peer of
// `peak_tier_count_equals_count_at_dominant_tier_on_nonempty_map`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
if chain.as_slice().is_empty() {
continue;
}
let hist = chain.as_slice().layer_kind_histogram();
let dominant = chain
.as_slice()
.dominant_layer_kind()
.expect("non-empty chain has a dominant layer kind");
assert_eq!(
hist.count(dominant),
chain.as_slice().peak_layer_kind_count(),
);
}
}
#[test]
fn peak_layer_kind_count_equals_dominant_layer_kind_map_or_count() {
// The fused-pair identity `peak_layer_kind_count() ==
// dominant_layer_kind().map_or(0, |k|
// layer_kind_histogram().count(k))` on every input — the count
// projection of the (dominant_layer_kind, peak_layer_kind_count)
// modal pair reads through the seam uniformly across the empty-
// chain / non-empty-chain partition. Includes the empty chain
// (`None.map_or(0, …) == 0 == peak_layer_kind_count`) — this is
// the pin that the fused-pair identity is boundary-complete.
// Peer of `peak_tier_count_equals_dominant_tier_map_or_count`
// on the tier altitude and
// `peak_kind_count_equals_dominant_kind_map_or_count` on the
// diff altitude.
for chain in recessive_layer_kind_fixtures() {
let hist = chain.as_slice().layer_kind_histogram();
let via_fused_pair = chain
.as_slice()
.dominant_layer_kind()
.map_or(0, |k| hist.count(k));
assert_eq!(chain.as_slice().peak_layer_kind_count(), via_fused_pair,);
}
}
#[test]
fn peak_layer_kind_count_is_bounded_by_len() {
// Structural bound `peak_layer_kind_count() <=
// self.as_ref().len()` on every input — the peak is bounded
// above by the total layer count (every kind contributes at
// most every layer, the others contribute zero). Lifted from
// the trait-uniform `peak_count() <= total()` law on
// AxisHistogram. Peer of `peak_tier_count_is_bounded_by_len`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
assert!(
slice.peak_layer_kind_count() <= slice.len(),
"peak_layer_kind_count()={p} must be <= len()={n}",
p = slice.peak_layer_kind_count(),
n = slice.len(),
);
}
}
#[test]
fn peak_layer_kind_count_equals_len_iff_at_most_one_present_layer_kind() {
// Structural bound `peak_layer_kind_count() ==
// self.as_ref().len()` iff `present_layer_kinds().len() <= 1`
// — the peak equals the total exactly when zero or one kind is
// observed. Zero: empty chain, both zero. One: singleton-support
// chain, every layer on the same kind. Two or more: peak
// strictly below total. Lifted from the trait-uniform
// `peak_count() == total()` law on AxisHistogram. Peer of
// `peak_tier_count_equals_len_iff_at_most_one_contributing_tier`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
assert_eq!(
slice.peak_layer_kind_count() == slice.len(),
slice.present_layer_kinds().len() <= 1,
"peak == len iff present_layer_kinds.len() <= 1 (peak={p}, len={n}, present={c})",
p = slice.peak_layer_kind_count(),
n = slice.len(),
c = slice.present_layer_kinds().len(),
);
}
}
#[test]
fn peak_layer_kind_count_is_at_least_one_on_nonempty_chain() {
// Structural pin: whenever `!self.as_ref().is_empty()`,
// `peak_layer_kind_count() >= 1` — a non-empty chain always has
// at least one layer on the dominant kind. Combined with the
// `<= len()` bound above, this pins `1 <= peak_layer_kind_count()
// <= len()` on every non-empty chain. Peer of
// `peak_tier_count_is_at_least_one_on_nonempty_map` on the tier
// altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.is_empty() {
continue;
}
assert!(
slice.peak_layer_kind_count() >= 1,
"non-empty chain must have peak_layer_kind_count >= 1 (peak={p})",
p = slice.peak_layer_kind_count(),
);
}
}
#[test]
fn peak_layer_kind_count_uniform_cover_is_two() {
// Uniform-cover chain — two layers of each kind (2 Defaults +
// 2 Env + 2 File). Full-cover histogram with uniform count 2
// per cell, so the peak count is 2. Direct sister of
// `peak_tier_count_uniform_cover_is_one` on the tier altitude
// (that fixture uses one leaf per tier so the peak is 1; here
// we use two layers per kind so the peak is 2). Combined with
// `dominant_layer_kind_uniform_cover_picks_first_cell`, the
// fused pair `(dominant_layer_kind, peak_layer_kind_count)`
// reads `(Some(Defaults), 2)` on the uniform-cover chain.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kind_histogram().is_full_cover());
assert_eq!(slice.peak_layer_kind_count(), 2);
}
#[test]
fn peak_layer_kind_count_singleton_support_equals_len() {
// Singleton-support degenerate: when only one kind contributes,
// every layer lands on that kind, so the peak equals the total.
// Direct construction: three layers, all File. The scalar peer
// of the singleton-support cell degenerate
// `dominant_layer_kind() == recessive_layer_kind()` in
// `recessive_layer_kind_singleton_support_agrees_with_dominant_layer_kind`
// — that test pins the *cell*; this test pins the *count*
// through the `peak_layer_kind_count() == len()` equality on
// the singleton-support boundary. Peer of
// `peak_tier_count_singleton_support_equals_len` on the tier
// altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert_eq!(slice.peak_layer_kind_count(), slice.len());
assert_eq!(slice.peak_layer_kind_count(), 3);
}
#[test]
fn peak_layer_kind_count_agrees_with_open_coded_max_over_axis_walk() {
// Parity against the exact `hist.iter().map(|(_, c)| c).max()`
// walk this lift replaces — both the named seam and the hand-
// rolled max must pointwise agree over every fixture. The
// `.max().unwrap_or(0)` idiom mirrors the empty-histogram
// convention on `AxisHistogram::peak_count` one altitude down
// (both read 0 on empty). Peer of
// `peak_tier_count_agrees_with_open_coded_max_over_axis_walk`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let via_seam = chain.as_slice().peak_layer_kind_count();
let hand_rolled = chain
.as_slice()
.layer_kind_histogram()
.iter()
.map(|(_, c)| c)
.max()
.unwrap_or(0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::trough_layer_kind_count — anti-modal-cell
// scalar-count peer of layer_kind_histogram on the chain
// altitude, closing the (dom, rec) × (cell, count) 2×2 scalar
// grid on the layer-kind sub-axis of the chain-shape surface ----
#[test]
fn trough_layer_kind_count_matches_layer_kind_histogram_trough_count_pointwise() {
// The scalar-count pin: `trough_layer_kind_count` routes through
// `layer_kind_histogram().trough_count()`, so the two seams must
// stay pointwise equivalent under every fixture. Direct sister
// of `trough_tier_count_matches_tier_histogram_trough_count_pointwise`
// and `trough_kind_count_matches_kind_histogram_trough_count_pointwise`
// on the tier and diff altitudes.
for chain in recessive_layer_kind_fixtures() {
let via_histogram = chain.as_slice().layer_kind_histogram().trough_count();
assert_eq!(chain.as_slice().trough_layer_kind_count(), via_histogram);
}
}
#[test]
fn trough_layer_kind_count_sample_chain_is_one() {
// Direct pin against `sample_chain()`: two File layers + one
// Env layer (no Defaults). Env is uniquely recessive with 1 of
// 3 layers, so the trough count is 1. The
// (recessive_layer_kind, trough_layer_kind_count) anti-modal
// pair reads `(Some(Env), 1)`.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.recessive_layer_kind(), Some(ConfigSourceKind::Env));
assert_eq!(slice.trough_layer_kind_count(), 1);
}
#[test]
fn trough_layer_kind_count_env_majority_is_one() {
// Env-majority fixture: three Env layers + one File + one
// Defaults. Defaults is (jointly) recessive with 1 of 5 layers;
// declaration-order tie-breaking picks Defaults over File
// (both count 1), so the trough count is 1. Cross-verified
// against `hist.trough_count() == 1` at the same observation
// site — the fused-pair count projection reads through the
// seam.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(
slice.recessive_layer_kind(),
Some(ConfigSourceKind::Defaults),
);
assert_eq!(slice.trough_layer_kind_count(), 1);
assert_eq!(slice.layer_kind_histogram().trough_count(), 1);
}
#[test]
fn trough_layer_kind_count_empty_chain_is_zero() {
// Empty-chain / zero boundary: the fused
// (recessive_layer_kind, trough_layer_kind_count) anti-modal
// scalar pair reads `(None, 0)` uniformly on the empty chain,
// matching the `(AxisHistogram::recessive_cell,
// AxisHistogram::trough_count)` pair on the shared histogram
// primitive one altitude down. Peer of
// `trough_tier_count_empty_map_is_zero` on the tier altitude
// and `trough_kind_count_empty_diff_is_zero` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.recessive_layer_kind(), None);
assert_eq!(empty.trough_layer_kind_count(), 0);
}
#[test]
fn trough_layer_kind_count_is_zero_iff_chain_is_empty() {
// The `trough_layer_kind_count() == 0 ⇔ self.as_ref().is_empty()`
// presence-bound pin — every layer projects to exactly one
// `ConfigSourceKind` cell through `ConfigSource::kind`, so a
// non-empty chain always contributes a positive trough (argmin
// of a nonempty support), and an empty chain always reads
// zero. Cross-axis divergence from the file-format and
// env-prefix sub-axes, whose zero-trough boundary is the
// corresponding histogram's `is_empty()`. Direct sister of
// `trough_tier_count_is_zero_iff_map_is_empty` on the tier
// altitude and `trough_kind_count_is_zero_iff_diff_is_empty`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
assert_eq!(
chain.as_slice().trough_layer_kind_count() == 0,
chain.as_slice().is_empty(),
);
}
}
#[test]
fn trough_layer_kind_count_equals_count_at_recessive_layer_kind_on_nonempty_chain() {
// The `(recessive_cell, trough_count)` anti-modal-pair
// invariant lifted to the chain altitude on the layer-kind
// sub-axis: `hist.count(recessive_layer_kind().unwrap()) ==
// trough_layer_kind_count()` on every non-empty chain. Peer
// of `trough_tier_count_equals_count_at_recessive_tier_on_nonempty_map`
// on the tier altitude and
// `trough_kind_count_equals_count_at_recessive_kind_on_nonempty_diff`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
if chain.as_slice().is_empty() {
continue;
}
let hist = chain.as_slice().layer_kind_histogram();
let recessive = chain
.as_slice()
.recessive_layer_kind()
.expect("non-empty chain has a recessive layer kind");
assert_eq!(
hist.count(recessive),
chain.as_slice().trough_layer_kind_count(),
);
}
}
#[test]
fn trough_layer_kind_count_equals_recessive_layer_kind_map_or_count() {
// The fused-pair identity `trough_layer_kind_count() ==
// recessive_layer_kind().map_or(0, |k|
// layer_kind_histogram().count(k))` on every input — the count
// projection of the (recessive_layer_kind,
// trough_layer_kind_count) anti-modal pair reads through the
// seam uniformly across the empty-chain / non-empty-chain
// partition. Includes the empty chain (`None.map_or(0, …) == 0
// == trough_layer_kind_count`) — this is the pin that the
// fused-pair identity is boundary-complete. Peer of
// `trough_tier_count_equals_recessive_tier_map_or_count` on
// the tier altitude and
// `trough_kind_count_equals_recessive_kind_map_or_count` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let hist = chain.as_slice().layer_kind_histogram();
let via_fused_pair = chain
.as_slice()
.recessive_layer_kind()
.map_or(0, |k| hist.count(k));
assert_eq!(chain.as_slice().trough_layer_kind_count(), via_fused_pair,);
}
}
#[test]
fn trough_layer_kind_count_bounded_above_by_peak_layer_kind_count() {
// Structural bound `trough_layer_kind_count() <=
// peak_layer_kind_count()` on every input — the trough is
// bounded above by the peak (lifted from the trait-uniform
// `trough_count() <= peak_count()` law on AxisHistogram). The
// empty-chain case reads `0 <= 0`; the non-empty case reads
// the trough-of-support bounded above by the peak-of-support.
// Peer of `trough_tier_count_bounded_above_by_peak_tier_count`
// on the tier altitude and
// `trough_kind_count_bounded_above_by_peak_kind_count` on the
// diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
assert!(
slice.trough_layer_kind_count() <= slice.peak_layer_kind_count(),
"trough_layer_kind_count()={t} must be <= peak_layer_kind_count()={p}",
t = slice.trough_layer_kind_count(),
p = slice.peak_layer_kind_count(),
);
}
}
#[test]
fn trough_layer_kind_count_equals_peak_layer_kind_count_iff_at_most_one_present_layer_kind() {
// Structural bound `trough_layer_kind_count() ==
// peak_layer_kind_count()` iff `present_layer_kinds().len() <=
// 1` (assuming distinct counts on multi-support chains) — the
// one-directional pin only. Zero: empty chain, both zero. One:
// singleton-support chain, every layer on the same kind, both
// equal `self.as_ref().len()`. Two or more with distinct
// counts: trough strictly below peak. The uniform-count-multi-
// support degenerate (e.g. `[Defaults, File]` — one layer per
// observed kind, so trough == peak == 1 with present == 2) is
// the reason the converse is not universal; this test only
// asserts the `support_le_one → equal` half, matching the
// pattern in
// `trough_kind_count_equals_peak_kind_count_iff_at_most_one_present_kind`
// on the diff altitude and
// `trough_tier_count_equals_peak_tier_count_iff_at_most_one_contributing_tier`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let equal = slice.trough_layer_kind_count() == slice.peak_layer_kind_count();
let support_le_one = slice.present_layer_kinds().len() <= 1;
if support_le_one {
assert!(
equal,
"at_most_one_present_layer_kind → trough == peak \
(trough={t}, peak={p}, present={present:?})",
t = slice.trough_layer_kind_count(),
p = slice.peak_layer_kind_count(),
present = slice.present_layer_kinds(),
);
}
}
}
#[test]
fn trough_layer_kind_count_is_at_least_one_on_nonempty_chain() {
// Structural pin: whenever `!self.as_ref().is_empty()`,
// `trough_layer_kind_count() >= 1` — the argmin is taken over
// the histogram's *support* (nonzero cells), so the trough of
// a non-empty histogram is always at least one. Combined with
// the `<= peak_layer_kind_count()` bound above, this pins
// `1 <= trough_layer_kind_count() <= peak_layer_kind_count()`
// on every non-empty chain. Peer of
// `trough_tier_count_is_at_least_one_on_nonempty_map` on the
// tier altitude and
// `trough_kind_count_is_at_least_one_on_nonempty_diff` on the
// diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.is_empty() {
continue;
}
assert!(
slice.trough_layer_kind_count() >= 1,
"non-empty chain must have trough_layer_kind_count >= 1 (trough={t})",
t = slice.trough_layer_kind_count(),
);
}
}
#[test]
fn trough_layer_kind_count_uniform_cover_is_two() {
// Uniform-cover chain — two layers of each kind (2 Defaults +
// 2 Env + 2 File). Full-cover histogram with uniform count 2
// per cell, so the trough count coincides with the peak count
// at 2 (the uniform-cover degenerate where every cell equals
// the modal cell). Direct sister of
// `peak_layer_kind_count_uniform_cover_is_two` — the same
// fixture read on the trough side. Combined with
// `recessive_layer_kind_uniform_cover_picks_first_cell` (the
// cell picks Defaults by declaration-order tie-breaking), the
// fused pair `(recessive_layer_kind, trough_layer_kind_count)`
// reads `(Some(Defaults), 2)` on the uniform-cover chain.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kind_histogram().is_full_cover());
assert_eq!(slice.trough_layer_kind_count(), 2);
assert_eq!(
slice.trough_layer_kind_count(),
slice.peak_layer_kind_count(),
);
}
#[test]
fn trough_layer_kind_count_singleton_support_equals_len() {
// Singleton-support degenerate: when only one kind
// contributes, every layer lands on that kind, so both trough
// and peak equal the total. Direct construction: three layers,
// all File. The scalar peer of the singleton-support cell
// degenerate `dominant_layer_kind() == recessive_layer_kind()`
// in
// `recessive_layer_kind_singleton_support_agrees_with_dominant_layer_kind`
// — that test pins the *cell*; this test pins the *count*
// through the `trough_layer_kind_count() == len()` equality on
// the singleton-support boundary. Peer of
// `trough_tier_count_singleton_support_equals_len` on the tier
// altitude and `trough_kind_count_singleton_support_equals_lines_len`
// on the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert_eq!(slice.trough_layer_kind_count(), slice.len());
assert_eq!(slice.trough_layer_kind_count(), 3);
assert_eq!(
slice.trough_layer_kind_count(),
slice.peak_layer_kind_count(),
);
}
#[test]
fn trough_layer_kind_count_agrees_with_open_coded_min_over_support_walk() {
// Parity against the exact
// `hist.iter().filter(|(_, c)| *c > 0).map(|(_, c)| c).min()`
// walk this lift replaces — both the named seam and the
// hand-rolled min-over-support must pointwise agree over every
// fixture. The `.min().unwrap_or(0)` idiom mirrors the empty-
// histogram convention on `AxisHistogram::trough_count` one
// altitude down (both read 0 on empty). The `filter(|(_, c)|
// *c > 0)` step is the load-bearing seam: the naive `.min()`
// over the full axis would silently pick zero-count absent
// cells on any non-full-cover chain, shadowing the trough-of-
// support the seam surfaces. Peer of
// `trough_tier_count_agrees_with_open_coded_min_over_support_walk`
// on the tier altitude and
// `trough_kind_count_agrees_with_open_coded_min_over_support_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let via_seam = chain.as_slice().trough_layer_kind_count();
let hand_rolled = chain
.as_slice()
.layer_kind_histogram()
.iter()
.map(|(_, c)| c)
.filter(|&c| c > 0)
.min()
.unwrap_or(0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::layer_kind_spread — scalar-dispersion peer
// on the layer-kind sub-axis of the chain altitude, fusing
// peak_layer_kind_count and trough_layer_kind_count into one
// dispersion scalar and lifting the "spread across altitudes"
// projection sideways to the layer-kind sub-axis ----
#[test]
fn layer_kind_spread_matches_layer_kind_histogram_spread_pointwise() {
// The scalar-dispersion pin: `layer_kind_spread` routes through
// `layer_kind_histogram().spread()`, so the two seams must stay
// pointwise equivalent under every fixture. Direct sister of
// `tier_spread_matches_tier_histogram_spread_pointwise` on the
// tier altitude and
// `kind_spread_matches_kind_histogram_spread_pointwise` on the
// diff altitude.
for chain in recessive_layer_kind_fixtures() {
let via_histogram = chain.as_slice().layer_kind_histogram().spread();
assert_eq!(chain.as_slice().layer_kind_spread(), via_histogram);
}
}
#[test]
fn layer_kind_spread_equals_peak_minus_trough_pointwise() {
// The fused-pair pin: `layer_kind_spread == peak_layer_kind_count
// - trough_layer_kind_count` on every fixture. The subtraction is
// underflow-safe because `peak_layer_kind_count() >=
// trough_layer_kind_count()` holds structurally on every chain
// (lifted from the trait-uniform `peak_count >= trough_count` law
// on AxisHistogram); this pin asserts the monotonicity invariant
// explicitly at every fixture so any future refactor that swaps
// the operands fails visibly. Peer of
// `tier_spread_equals_peak_minus_trough_pointwise` on the tier
// altitude and `kind_spread_equals_peak_minus_trough_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let peak = slice.peak_layer_kind_count();
let trough = slice.trough_layer_kind_count();
assert!(
peak >= trough,
"peak={peak} must be >= trough={trough} on every chain",
);
assert_eq!(slice.layer_kind_spread(), peak - trough);
}
}
#[test]
fn layer_kind_spread_sample_chain_is_one() {
// Direct pin against `sample_chain()`: two File layers + one Env
// layer. File dominant at 2, Env recessive at 1 — the spread is
// 1. Reads the paired `(peak_layer_kind_count,
// trough_layer_kind_count, layer_kind_spread)` dispersion triple
// as `(2, 1, 1)`. Peer of `tier_spread_prog_fixture_is_one` on
// the tier altitude and `kind_spread_added_dominated_fixture_is_one`
// on the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.peak_layer_kind_count(), 2);
assert_eq!(slice.trough_layer_kind_count(), 1);
assert_eq!(slice.layer_kind_spread(), 1);
}
#[test]
fn layer_kind_spread_env_majority_is_two() {
// Direct pin against an env-majority chain: three Env layers +
// one File + one Defaults. Env dominant at 3, Defaults recessive
// at 1 (declaration-order tie against File at 1) — the spread is
// 2. Reads the paired `(peak_layer_kind_count,
// trough_layer_kind_count, layer_kind_spread)` dispersion triple
// as `(3, 1, 2)`. Cross-verified against `hist.spread() == 2` at
// the same observation site — the fused-pair spread projection
// reads through the seam.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.peak_layer_kind_count(), 3);
assert_eq!(slice.trough_layer_kind_count(), 1);
assert_eq!(slice.layer_kind_spread(), 2);
assert_eq!(slice.layer_kind_histogram().spread(), 2);
}
#[test]
fn layer_kind_spread_empty_chain_is_zero() {
// An empty chain has no layers and therefore zero spread — reads
// `0` per the AxisHistogram::spread empty convention one altitude
// down; the `(peak_layer_kind_count, trough_layer_kind_count,
// layer_kind_spread)` triple reads `(0, 0, 0)` uniformly on
// empty. Peer of `tier_spread_empty_map_is_zero` on the tier
// altitude and `kind_spread_empty_diff_is_zero` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.peak_layer_kind_count(), 0);
assert_eq!(empty.trough_layer_kind_count(), 0);
assert_eq!(empty.layer_kind_spread(), 0);
}
#[test]
fn layer_kind_spread_singleton_support_is_zero() {
// Singleton-support pin: every layer lands on the same kind, so
// the dominant kind is both peak and trough of the support, and
// the spread is zero — the balanced-layer-kinds boundary on the
// singleton-support side. Direct construction: three File
// layers, present == {File}. Peer of
// `tier_spread_singleton_support_is_zero` on the tier altitude
// and `kind_spread_singleton_support_is_zero` on the diff
// altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert_eq!(slice.layer_kind_spread(), 0);
}
#[test]
fn layer_kind_spread_uniform_cover_is_zero() {
// Uniform-cover pin: every observed kind contributes the same
// nonzero count (two layers each here — a full-cover chain with
// uniform count 2 per cell), so peak == trough == 2 and the
// spread is zero — the balanced-layer-kinds boundary on the
// uniform-cover side. Peer of `tier_spread_uniform_cover_is_zero`
// on the tier altitude and `kind_spread_uniform_cover_is_zero`
// on the diff altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kind_histogram().is_full_cover());
assert_eq!(slice.peak_layer_kind_count(), 2);
assert_eq!(slice.trough_layer_kind_count(), 2);
assert_eq!(slice.layer_kind_spread(), 0);
}
#[test]
fn layer_kind_spread_is_zero_iff_peak_equals_trough() {
// Structural-skew boundary: `layer_kind_spread() == 0` iff
// `peak_layer_kind_count() == trough_layer_kind_count()` — the
// scalar-pair form of the balanced-layer-kinds predicate. On
// every fixture, the predicate agrees with the equality of the
// fused modal-count pair. Peer of
// `tier_spread_is_zero_iff_peak_equals_trough` on the tier
// altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let spread_zero = slice.layer_kind_spread() == 0;
let peak_eq_trough = slice.peak_layer_kind_count() == slice.trough_layer_kind_count();
assert_eq!(
spread_zero,
peak_eq_trough,
"layer_kind_spread() == 0 iff peak == trough \
(spread={s}, peak={p}, trough={t})",
s = slice.layer_kind_spread(),
p = slice.peak_layer_kind_count(),
t = slice.trough_layer_kind_count(),
);
}
}
#[test]
fn layer_kind_spread_agrees_with_modal_pair_equality_on_nonempty_chain() {
// Cross-surface pin: on every non-empty chain, `layer_kind_spread()
// == 0` agrees with `dominant_layer_kind() ==
// recessive_layer_kind()` — the modal-pair equality form of the
// balanced-layer-kinds predicate. Both branches reduce to
// `Some(first) == Some(first)` on singleton-support and uniform-
// cover chains, and to `false` on skewed chains. Peer of
// `tier_spread_agrees_with_modal_pair_equality_on_nonempty_map`
// on the tier altitude and
// `kind_spread_agrees_with_modal_pair_equality_on_nonempty_diff`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.is_empty() {
continue;
}
let spread_zero = slice.layer_kind_spread() == 0;
let dom_eq_rec = slice.dominant_layer_kind() == slice.recessive_layer_kind();
assert_eq!(
spread_zero, dom_eq_rec,
"on non-empty chain, layer_kind_spread() == 0 iff \
dominant_layer_kind() == recessive_layer_kind()",
);
}
}
#[test]
fn layer_kind_spread_bounded_above_by_peak_layer_kind_count() {
// Structural bound: `layer_kind_spread() <= peak_layer_kind_count()`
// on every fixture — the trough is non-negative, so the
// subtraction is bounded above by the minuend. Lifted from the
// trait-uniform `spread() <= peak_count()` law on AxisHistogram.
// Peer of `tier_spread_bounded_above_by_peak_tier_count` on the
// tier altitude and `kind_spread_bounded_above_by_peak_kind_count`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
assert!(
slice.layer_kind_spread() <= slice.peak_layer_kind_count(),
"layer_kind_spread()={s} must be <= peak_layer_kind_count()={p}",
s = slice.layer_kind_spread(),
p = slice.peak_layer_kind_count(),
);
}
}
#[test]
fn layer_kind_spread_equals_peak_iff_chain_is_empty() {
// Equality-case pin of the `layer_kind_spread <=
// peak_layer_kind_count` bound: equality holds iff the trough is
// zero, which by `trough_layer_kind_count == 0 <=>
// self.as_ref().is_empty()` (the layer-kind sub-axis zero-trough
// boundary — every layer projects to exactly one
// ConfigSourceKind cell) holds iff the chain is empty. Peer of
// `tier_spread_equals_peak_iff_map_is_empty` on the tier
// altitude and `kind_spread_equals_peak_iff_diff_is_empty` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let equal = slice.layer_kind_spread() == slice.peak_layer_kind_count();
assert_eq!(
equal,
slice.is_empty(),
"layer_kind_spread == peak_layer_kind_count iff chain \
is empty (spread={s}, peak={p}, len={n})",
s = slice.layer_kind_spread(),
p = slice.peak_layer_kind_count(),
n = slice.len(),
);
}
}
#[test]
fn layer_kind_spread_bounded_above_by_len() {
// Composition bound: `layer_kind_spread() <= self.as_ref().len()`
// on every fixture — chaining `layer_kind_spread <=
// peak_layer_kind_count` (previous pin) with
// `peak_layer_kind_count <= len()` (documented on
// `peak_layer_kind_count`). Peer of
// `tier_spread_bounded_above_by_len` on the tier altitude and
// `kind_spread_bounded_above_by_lines_len` on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
assert!(
slice.layer_kind_spread() <= slice.len(),
"layer_kind_spread()={s} must be <= len()={n}",
s = slice.layer_kind_spread(),
n = slice.len(),
);
}
}
#[test]
fn layer_kind_spread_singleton_support_multi_layer_is_zero() {
// Direct pin at a 4-layer singleton-support File-only chain —
// present == {File}, peak == trough == 4, spread == 0. The
// scalar peer of the singleton-support cell degenerate
// `dominant_layer_kind() == recessive_layer_kind()` — the
// dispersion triple reads `(4, 4, 0)`, distinct from the 3-layer
// fixture in `layer_kind_spread_singleton_support_is_zero` so
// any misread that reintroduces the `peak - trough` inline idiom
// as `peak` alone silently underflows on a fixture at a
// different peak. Peer of
// `tier_spread_singleton_support_multi_leaf_is_zero` on the tier
// altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert_eq!(slice.peak_layer_kind_count(), 4);
assert_eq!(slice.trough_layer_kind_count(), 4);
assert_eq!(slice.layer_kind_spread(), 0);
}
#[test]
fn layer_kind_spread_agrees_with_open_coded_max_minus_min_walk() {
// Parity against the exact `hist.iter().map(|(_, c)| c).max()
// .unwrap_or(0) - hist.iter().filter(|&(_, c)| c > 0)
// .map(|(_, c)| c).min().unwrap_or(0)` walk this lift replaces
// — both the named seam and the hand-rolled max-minus-min-over-
// support must pointwise agree over every fixture. The
// `filter(|(_, c)| c > 0)` step on the min side is the load-
// bearing seam: the naive `.min()` over the full axis would
// silently pick zero-count absent cells on any non-full-cover
// chain, shadowing the trough-of-support the seam surfaces —
// and once the trough shadows to zero, the spread coincides
// with the peak alone, silently overreporting the dispersion.
// Peer of `tier_spread_agrees_with_open_coded_max_minus_min_walk`
// on the tier altitude and
// `kind_spread_agrees_with_open_coded_max_minus_min_walk` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kind_spread();
let hist = slice.layer_kind_histogram();
let peak = hist.iter().map(|(_, c)| c).max().unwrap_or(0);
let trough = hist
.iter()
.map(|(_, c)| c)
.filter(|&c| c > 0)
.min()
.unwrap_or(0);
assert_eq!(via_seam, peak - trough);
}
}
// ---- ConfigSourceChain::layer_kinds_balanced — balanced-layer-kinds
// boolean predicate on the layer-kind sub-axis of the chain
// altitude, lifting is_uniform_count from the histogram surface
// and climbing the "balanced across altitudes" projection
// sideways from the tier altitude to the first chain sub-axis ----
#[test]
fn layer_kinds_balanced_matches_layer_kind_histogram_is_uniform_count_pointwise() {
// The routing pin: `layer_kinds_balanced` routes through
// `layer_kind_histogram().is_uniform_count()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches any
// future drift where either implementation stops projecting
// through the shared cube-native primitive. Layer-kind sub-axis
// peer of `tiers_balanced_matches_tier_histogram_is_uniform_count_pointwise`
// on the tier altitude and
// `kinds_balanced_matches_kind_histogram_is_uniform_count_pointwise`
// on the diff altitude, in the "balanced across altitudes"
// projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().is_uniform_count();
assert_eq!(slice.layer_kinds_balanced(), via_histogram);
}
}
#[test]
fn layer_kinds_balanced_agrees_with_layer_kind_spread_zero_pointwise() {
// The defining equivalence on the scalar-spread surface at the
// layer-kind sub-axis: `layer_kinds_balanced() ==
// (layer_kind_spread() == 0)` on every fixture. The balanced-
// boundary of the fused `(peak_layer_kind_count,
// trough_layer_kind_count, layer_kind_spread)` dispersion triple
// as a named boolean predicate. Lifted from the trait-uniform
// `is_uniform_count() == (spread() == 0)` law on AxisHistogram.
// Peer of `tiers_balanced_agrees_with_tier_spread_zero_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let balanced = slice.layer_kinds_balanced();
let spread_zero = slice.layer_kind_spread() == 0;
assert_eq!(
balanced,
spread_zero,
"layer_kinds_balanced ({balanced}) must agree with \
layer_kind_spread == 0 (spread={s}) for chain",
s = slice.layer_kind_spread(),
);
}
}
#[test]
fn layer_kinds_balanced_agrees_with_peak_equals_trough_pointwise() {
// The structural form on the underlying scalar pair:
// `layer_kinds_balanced() == (peak_layer_kind_count() ==
// trough_layer_kind_count())` on every fixture. Pins the
// balanced-layer-kinds predicate against the direct scalar-pair
// equality form. Peer of
// `tiers_balanced_agrees_with_peak_equals_trough_pointwise` on
// the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let balanced = slice.layer_kinds_balanced();
let peak = slice.peak_layer_kind_count();
let trough = slice.trough_layer_kind_count();
assert_eq!(
balanced,
peak == trough,
"layer_kinds_balanced ({balanced}) must agree with \
peak_layer_kind_count == trough_layer_kind_count \
({peak} == {trough}) for chain",
);
}
}
#[test]
fn layer_kinds_balanced_agrees_with_modal_pair_equality_pointwise() {
// The modal-pair form: `layer_kinds_balanced() ==
// (dominant_layer_kind() == recessive_layer_kind())` on every
// fixture — including the empty chain where both branches reduce
// to `None == None`, every singleton-support chain where both
// reduce to `Some(k) == Some(k)`, every uniform per-kind chain
// where both reduce to `Some(first) == Some(first)` (after
// declaration-order tie-break on both sides), and every skewed
// chain where both read `false`. Lifted from the trait-uniform
// `is_uniform_count() == (dominant_cell() == recessive_cell())`
// law on AxisHistogram. Peer of
// `tiers_balanced_agrees_with_modal_pair_equality_pointwise` on
// the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let balanced = slice.layer_kinds_balanced();
let modal_pair_equal = slice.dominant_layer_kind() == slice.recessive_layer_kind();
assert_eq!(
balanced, modal_pair_equal,
"layer_kinds_balanced ({balanced}) must agree with \
dominant_layer_kind == recessive_layer_kind for chain",
);
}
}
#[test]
fn layer_kinds_balanced_empty_chain_is_true() {
// Vacuous-uniformity boundary: the empty chain has no observed
// cells, so the universal "every observed cell carries the same
// count" reads `true` over the empty support — matching
// AxisHistogram::is_uniform_count's empty convention one altitude
// down and `layer_kind_spread == 0` on the empty case. Peer of
// `tiers_balanced_empty_map_is_true` on the tier altitude and
// `layer_kind_spread_empty_chain_is_zero` on the scalar-spread
// surface at the same sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.layer_kinds_balanced());
assert_eq!(empty.layer_kind_spread(), 0);
}
#[test]
fn layer_kinds_balanced_singleton_support_is_true() {
// Singleton-support pin: every layer lands on the same kind, so
// the one observed kind's count is both peak and trough of the
// support — trivially balanced. Peer of
// `tiers_balanced_singleton_support_is_true` on the tier altitude
// and `layer_kind_spread_singleton_support_is_zero` on the
// scalar-spread surface at the same sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_balanced());
}
#[test]
fn layer_kinds_balanced_uniform_cover_is_true() {
// Uniform-cover pin: every observed kind contributes the same
// nonzero count (two layers each here — a full-cover chain with
// uniform count 2 per cell), so peak == trough == 2 and the
// balanced-layer-kinds predicate reads `true`. Peer of
// `tiers_balanced_uniform_cover_is_true` on the tier altitude
// and `layer_kind_spread_uniform_cover_is_zero` on the scalar-
// spread surface at the same sub-axis.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kind_histogram().is_full_cover());
assert!(slice.layer_kinds_balanced());
}
#[test]
fn layer_kinds_balanced_sample_chain_is_false() {
// Direct pin against `sample_chain()`: two File layers + one Env
// layer. File dominant at 2, Env recessive at 1 — spread == 1,
// so `layer_kinds_balanced` reads `false`. Peer of
// `tiers_balanced_prog_fixture_is_false` on the tier altitude on
// the boolean side and `layer_kind_spread_sample_chain_is_one` on
// the scalar-spread surface.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.layer_kind_spread(), 1);
assert!(!slice.layer_kinds_balanced());
}
#[test]
fn layer_kinds_balanced_env_majority_is_false() {
// Direct pin against an env-majority chain: three Env layers +
// one File + one Defaults. Env dominant at 3, both other cells
// recessive at 1 — spread == 2, so `layer_kinds_balanced` reads
// `false`. Peer of `tiers_balanced_nested_fixture_is_false` on
// the tier altitude on the boolean side and
// `layer_kind_spread_env_majority_is_two` on the scalar-spread
// surface.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.layer_kind_spread(), 2);
assert!(!slice.layer_kinds_balanced());
}
#[test]
fn layer_kinds_balanced_singleton_support_multi_layer_is_true() {
// Singleton-support multi-layer pin: 4 File layers all on one
// kind — peak == trough == 4, balanced reads `true`. Distinct
// peak from the 3-layer singleton fixture above so any misread
// that reintroduces a `layer_kind_spread == 0` inline idiom
// silently underflows on a fixture at a different peak. Peer of
// `tiers_balanced_singleton_support_multi_leaf_is_true` on the
// tier altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.peak_layer_kind_count(), 4);
assert_eq!(slice.trough_layer_kind_count(), 4);
assert!(slice.layer_kinds_balanced());
}
#[test]
fn layer_kinds_balanced_implies_at_most_one_present_kind_or_uniform_cover() {
// Structural characterization: on every fixture,
// `layer_kinds_balanced` holds when the chain has support size 0
// or 1, or every observed kind carries the same nonzero count.
// Direct witness of the trait-uniform `distinct_cells() <= 1 ⇒
// is_uniform_count()` law on AxisHistogram, lifted to the layer-
// kind sub-axis of the chain altitude. Peer of
// `tiers_balanced_implies_at_most_one_contributing_tier_or_uniform_cover`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.present_layer_kinds().len() <= 1 {
assert!(
slice.layer_kinds_balanced(),
"chain with present_layer_kinds.len() = {} must be \
layer_kinds_balanced",
slice.present_layer_kinds().len(),
);
}
}
}
#[test]
fn layer_kinds_balanced_false_implies_chain_is_nonempty() {
// Contrapositive of the vacuous-uniformity implication:
// `!layer_kinds_balanced() ⇒ !self.as_ref().is_empty()`. A
// skewed chain has at least two distinct positive counts, so
// the chain is non-empty. Directly witnessed on the fixture set.
// Peer of `tiers_balanced_false_implies_map_is_nonempty` on the
// tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if !slice.layer_kinds_balanced() {
assert!(
!slice.is_empty(),
"non-balanced chain must be non-empty (len={})",
slice.len(),
);
}
}
}
#[test]
fn layer_kinds_balanced_false_implies_at_least_two_present_layer_kinds() {
// Contrapositive of the singleton-support implication:
// `!layer_kinds_balanced() ⇒ present_layer_kinds().len() >= 2`.
// A skewed chain observes at least two distinct kinds with
// differing counts. Lifted from the trait-uniform
// `!is_uniform_count() ⇒ distinct_cells() >= 2` law on
// AxisHistogram. Peer of
// `tiers_balanced_false_implies_at_least_two_contributing_tiers`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if !slice.layer_kinds_balanced() {
assert!(
slice.present_layer_kinds().len() >= 2,
"non-balanced chain must observe >= 2 present layer \
kinds (was {})",
slice.present_layer_kinds().len(),
);
}
}
}
#[test]
fn layer_kinds_balanced_skewed_three_cell_fixture_is_false() {
// Direct pin: a strictly-ordered three-cell chain with
// Defaults=1, Env=2, File=3 — peak 3, trough 1, spread 2 — reads
// `false`. Every count distinct, no tie-breaking on either side
// of the modal-count pair. Peer of
// `tiers_balanced_skewed_three_cell_fixture_is_false` on the
// tier altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.peak_layer_kind_count(), 3);
assert_eq!(slice.trough_layer_kind_count(), 1);
assert!(!slice.layer_kinds_balanced());
}
#[test]
fn layer_kinds_balanced_agrees_with_open_coded_uniform_walk() {
// Parity against the exact hand-rolled uniform-count walk this
// lift replaces: pull the nonzero counts and check they all
// agree. Empty support reads `true` vacuously. Mirrors the
// parity pin `tiers_balanced_agrees_with_open_coded_uniform_walk`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_balanced();
let hist = slice.layer_kind_histogram();
let mut nonzero = hist.iter().map(|(_, c)| c).filter(|&c| c > 0);
let hand_rolled = match nonzero.next() {
None => true,
Some(first) => nonzero.all(|c| c == first),
};
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::layer_kinds_full_cover — full-cover-layer-
// kinds boolean predicate on the layer-kind sub-axis of the chain
// altitude, lifting is_full_cover from the histogram surface and
// lifting the "full-cover across altitudes" projection sideways
// from the tier altitude to the first chain sub-axis ----
#[test]
fn layer_kinds_full_cover_matches_layer_kind_histogram_is_full_cover_pointwise() {
// The routing pin: `layer_kinds_full_cover` routes through
// `layer_kind_histogram().is_full_cover()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops
// projecting through the shared cube-native primitive. Layer-
// kind sub-axis peer of
// `tiers_full_cover_matches_tier_histogram_is_full_cover_pointwise`
// on the tier altitude and
// `kinds_full_cover_matches_kind_histogram_is_full_cover_pointwise`
// on the diff altitude, in the "full-cover across altitudes"
// projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().is_full_cover();
assert_eq!(slice.layer_kinds_full_cover(), via_histogram);
}
}
#[test]
fn layer_kinds_full_cover_agrees_with_absent_layer_kinds_empty_pointwise() {
// The defining equivalence on the coverage-gap-Vec surface at
// the layer-kind sub-axis: `layer_kinds_full_cover() ==
// absent_layer_kinds().is_empty()` on every fixture. The
// full-cover-boundary of the fused `(absent_layer_kinds,
// absent_layer_kinds_count)` coverage-gap peers as a named
// boolean predicate. Lifted from the trait-uniform
// `is_full_cover() == unobserved().next().is_none()` law on
// AxisHistogram. Peer of
// `tiers_full_cover_agrees_with_absent_tiers_empty_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.layer_kinds_full_cover();
let gap_empty = slice.absent_layer_kinds().is_empty();
assert_eq!(
full_cover, gap_empty,
"layer_kinds_full_cover ({full_cover}) must agree with \
absent_layer_kinds().is_empty() ({gap_empty}) for chain",
);
}
}
#[test]
fn layer_kinds_full_cover_agrees_with_absent_layer_kinds_count_zero_pointwise() {
// The coverage-gap-scalar form: `layer_kinds_full_cover() ==
// (absent_layer_kinds_count() == 0)` on every fixture. Pins
// the full-cover-layer-kinds predicate against the scalar-zero
// equality form on the coverage-gap side. Peer of
// `tiers_full_cover_agrees_with_absent_tiers_count_zero_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.layer_kinds_full_cover();
let count_zero = slice.absent_layer_kinds_count() == 0;
assert_eq!(
full_cover,
count_zero,
"layer_kinds_full_cover ({full_cover}) must agree with \
absent_layer_kinds_count == 0 (count={c}) for chain",
c = slice.absent_layer_kinds_count(),
);
}
}
#[test]
fn layer_kinds_full_cover_agrees_with_present_layer_kinds_count_equals_axis_cardinality_pointwise()
{
// The support-scalar form: `layer_kinds_full_cover() ==
// (present_layer_kinds_count() ==
// axis_cardinality::<ConfigSourceKind>())` on every fixture —
// the dual-side surfacing of the same boolean across the
// (observed, unobserved) partition. Lifted from the trait-
// uniform `is_full_cover() == (distinct_cells() ==
// axis_cardinality::<A>())` law on AxisHistogram. Peer of
// `tiers_full_cover_agrees_with_contributing_tiers_count_equals_axis_cardinality_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.layer_kinds_full_cover();
let support_full =
slice.present_layer_kinds_count() == crate::axis_cardinality::<ConfigSourceKind>();
assert_eq!(
full_cover, support_full,
"layer_kinds_full_cover ({full_cover}) must agree with \
present_layer_kinds_count == axis_cardinality for chain",
);
}
}
#[test]
fn layer_kinds_full_cover_agrees_with_present_layer_kinds_len_equals_axis_cardinality_pointwise()
{
// The support-Vec form: `layer_kinds_full_cover() ==
// (present_layer_kinds().len() ==
// axis_cardinality::<ConfigSourceKind>())` on every fixture.
// Pins the predicate against the `Vec<ConfigSourceKind>`
// length form consumers reach for when they already hold the
// support vector. Peer of
// `tiers_full_cover_agrees_with_contributing_tiers_len_equals_axis_cardinality_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.layer_kinds_full_cover();
let support_len_full =
slice.present_layer_kinds().len() == crate::axis_cardinality::<ConfigSourceKind>();
assert_eq!(
full_cover, support_len_full,
"layer_kinds_full_cover ({full_cover}) must agree with \
present_layer_kinds().len() == axis_cardinality for chain",
);
}
}
#[test]
fn layer_kinds_full_cover_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has no observed cells,
// so the coverage gap equals every cell of
// `ConfigSourceKind::ALL` (three-cell axis, no zero-cardinality
// degenerate case) — `layer_kinds_full_cover` reads `false`.
// Dual of `layer_kinds_balanced_empty_chain_is_true`: the
// empty chain is on the opposite side of the full-cover
// boundary from the balanced boundary. Matches `is_full_cover`
// reading `false` on the empty histogram over a non-zero-
// cardinality axis one altitude down. Peer of
// `tiers_full_cover_empty_map_is_false` on the tier altitude
// and `kinds_full_cover_empty_diff_is_false` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_full_cover());
assert_eq!(
empty.absent_layer_kinds_count(),
crate::axis_cardinality::<ConfigSourceKind>()
);
}
#[test]
fn layer_kinds_full_cover_singleton_support_is_false() {
// Singleton-support pin: every layer lands on the same kind,
// so one observed cell out of three leaves two cells in the
// coverage gap — `layer_kinds_full_cover` reads `false`. Peer
// of `layer_kinds_balanced_singleton_support_is_true` on the
// opposite side of the boundary: singleton-support is
// trivially balanced but never full-cover on a three-cell
// axis. Peer of `tiers_full_cover_singleton_support_is_false`
// on the tier altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(!slice.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_full_cover_two_kind_cover_is_false() {
// Two-kind cover pin: a chain observing Env + File but never
// Defaults leaves one cell in the coverage gap —
// `layer_kinds_full_cover` reads `false`. Direct witness that
// the two-kind-observed shape (support size 2 out of 3) is on
// the `false` side of the full-cover boundary. Peer of
// `tiers_full_cover_three_tier_cover_is_false` at the tier
// altitude (three-of-four cover) — same "one cell short of
// full cover" boundary at the sister altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(!slice.layer_kinds_full_cover());
assert!(
slice
.absent_layer_kinds()
.contains(&ConfigSourceKind::Defaults)
);
}
#[test]
fn layer_kinds_full_cover_uniform_cover_is_true() {
// Uniform-cover pin: every kind contributes one layer, so
// every cell of `ConfigSourceKind::ALL` receives at least one
// observation — `layer_kinds_full_cover` reads `true`. Peer of
// `layer_kinds_balanced_uniform_cover_is_true` on the same
// fixture shape (uniform three-kind cover): uniform full-cover
// is on the `true` side of BOTH the balanced-layer-kinds and
// full-cover-layer-kinds boundaries. Peer of
// `tiers_full_cover_uniform_cover_is_true` on the tier
// altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_full_cover());
assert!(slice.layer_kinds_balanced());
}
#[test]
fn layer_kinds_full_cover_skewed_three_cell_fixture_is_true() {
// Direct pin: a strictly-ordered three-cell chain with
// Defaults=1, Env=2, File=3 has every kind observed —
// `layer_kinds_full_cover` reads `true`, orthogonal to
// `layer_kinds_balanced` which reads `false` on the identical
// fixture (peak 3, trough 1, spread 2). Every kind observed
// but at strictly-distinct counts: full-cover is the coverage
// boundary, not the uniformity boundary. Peer of
// `tiers_full_cover_skewed_four_cell_fixture_is_true` on the
// tier altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_full_cover());
assert!(!slice.layer_kinds_balanced());
}
#[test]
fn layer_kinds_full_cover_env_majority_full_cover_is_true() {
// Direct pin against an env-majority chain: three Env layers +
// one File + one Defaults. Every kind observed at least once,
// so `layer_kinds_full_cover` reads `true` — orthogonal to
// `layer_kinds_balanced_env_majority_is_false` on the exact
// same fixture (spread 2). Confirms full-cover and balanced
// partition the observation space independently at the same
// sub-axis.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_full_cover());
assert!(!slice.layer_kinds_balanced());
}
#[test]
fn layer_kinds_full_cover_sample_chain_is_false() {
// Direct pin against `sample_chain()`: two File layers + one
// Env layer, no Defaults. The support is {Env, File} — size 2
// out of 3 — so `layer_kinds_full_cover` reads `false`. Peer
// of `layer_kinds_balanced_sample_chain_is_false` on the same
// fixture on the sister boundary; both boundaries read `false`
// here but for different structural reasons (Defaults absent
// vs. counts skewed).
let chain = sample_chain();
let slice = chain.as_slice();
assert!(!slice.layer_kinds_full_cover());
assert!(
slice
.absent_layer_kinds()
.contains(&ConfigSourceKind::Defaults)
);
}
#[test]
fn layer_kinds_full_cover_implies_chain_is_nonempty() {
// Contrapositive of the empty-chain boundary:
// `layer_kinds_full_cover() ⇒ !self.as_ref().is_empty()`. A
// full-cover chain observes at least one layer per kind, so
// the chain is non-empty. Directly witnessed on the fixture
// set. Peer of `tiers_full_cover_implies_map_is_nonempty` on
// the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_full_cover() {
assert!(
!slice.is_empty(),
"full-cover chain must be non-empty (len={})",
slice.len(),
);
}
}
}
#[test]
fn layer_kinds_full_cover_implies_present_layer_kinds_equals_axis_cardinality() {
// Structural characterization: `layer_kinds_full_cover() ⇒
// present_layer_kinds().len() ==
// axis_cardinality::<ConfigSourceKind>()`. A full-cover chain
// observes every kind, so the support size equals the axis
// cardinality. Direct witness of the trait-uniform
// `is_full_cover() ⇒ distinct_cells() ==
// axis_cardinality::<A>()` law on AxisHistogram, lifted to
// the layer-kind sub-axis of the chain altitude. Peer of
// `tiers_full_cover_implies_contributing_tiers_equals_axis_cardinality`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_full_cover() {
assert_eq!(
slice.present_layer_kinds().len(),
crate::axis_cardinality::<ConfigSourceKind>(),
"full-cover chain must observe every ConfigSourceKind",
);
}
}
}
#[test]
fn layer_kinds_full_cover_implies_chain_length_bounded_below_by_axis_cardinality() {
// Chain-length lower-bound characterization:
// `layer_kinds_full_cover() ⇒ self.as_ref().len() >=
// axis_cardinality::<ConfigSourceKind>()`. A full-cover chain
// observes at least one layer per kind, so the chain length
// is bounded below by the axis cardinality (three on the
// ConfigSourceKind axis). Directly witnessed on the fixture
// set. Peer of
// `tiers_full_cover_implies_leaf_count_bounded_below_by_axis_cardinality`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_full_cover() {
assert!(
slice.len() >= crate::axis_cardinality::<ConfigSourceKind>(),
"full-cover chain must have >= axis_cardinality layers (was {})",
slice.len(),
);
}
}
}
#[test]
fn layer_kinds_full_cover_agrees_with_open_coded_all_positive_walk() {
// Parity against the exact hand-rolled full-cover walk this
// lift replaces: walk every cell of the histogram and check
// every count is positive. Mirrors the parity pin
// `tiers_full_cover_agrees_with_open_coded_all_positive_walk`
// on the tier altitude and
// `kinds_full_cover_agrees_with_open_coded_all_positive_walk`
// on the diff altitude. Note the walk uses `hist.iter()` which
// iterates over the closed axis's ALL cells in declaration
// order — a full-cover chain has every cell nonzero regardless
// of order.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_full_cover();
let hist = slice.layer_kind_histogram();
let hand_rolled = hist.iter().all(|(_, c)| c > 0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::layer_kinds_any_observed — any-observed-
// layer-kinds boolean predicate on the layer-kind sub-axis of
// the chain altitude, lifting the "any-observed across
// altitudes" projection sideways from the tier altitude
// (`ProvenanceMap::tiers_any_observed`) into the first chain
// sub-axis. Routed through the shared
// `!AxisHistogram::is_empty` primitive one altitude down. ----
#[test]
fn layer_kinds_any_observed_matches_layer_kind_histogram_is_empty_negation_pointwise() {
// The routing pin: `layer_kinds_any_observed` routes through
// `!layer_kind_histogram().is_empty()`, so the two seams must
// stay pointwise equivalent under every fixture. Catches any
// future drift where either implementation stops projecting
// through the shared cube-native primitive. Layer-kind sub-
// axis peer of
// `tiers_any_observed_matches_tier_histogram_is_empty_negation_pointwise`
// on the tier altitude and
// `kinds_any_observed_matches_kind_histogram_is_empty_negation_pointwise`
// on the diff altitude, in the "any-observed across altitudes"
// projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = !slice.layer_kind_histogram().is_empty();
assert_eq!(slice.layer_kinds_any_observed(), via_histogram);
}
}
#[test]
fn layer_kinds_any_observed_agrees_with_chain_nonempty_pointwise() {
// Slice-nonempty surface: `layer_kinds_any_observed() ==
// !self.as_ref().is_empty()`. Every chain layer contributes to
// a ConfigSourceKind cell, so the histogram is empty iff the
// chain slice is empty. Peer of
// `tiers_any_observed_agrees_with_map_nonempty_pointwise` on
// the tier altitude and
// `kinds_any_observed_agrees_with_lines_nonempty_pointwise` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_any_observed();
let via_len = !slice.is_empty();
assert_eq!(
via_seam, via_len,
"layer_kinds_any_observed ({via_seam}) must agree with \
!slice.is_empty() ({via_len}) for chain",
);
}
}
#[test]
fn layer_kinds_any_observed_agrees_with_present_layer_kinds_count_positive_pointwise() {
// Support-scalar surface: `layer_kinds_any_observed() ==
// (present_layer_kinds_count() > 0)`, without allocating the
// `Vec<ConfigSourceKind>`. Peer of
// `tiers_any_observed_agrees_with_contributing_tiers_count_positive_pointwise`
// on the tier altitude and
// `kinds_any_observed_agrees_with_present_kinds_count_positive_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_any_observed();
let via_scalar = slice.present_layer_kinds_count() > 0;
assert_eq!(
via_seam,
via_scalar,
"layer_kinds_any_observed ({via_seam}) must agree with \
present_layer_kinds_count > 0 (count={c}) for chain",
c = slice.present_layer_kinds_count(),
);
}
}
#[test]
fn layer_kinds_any_observed_agrees_with_present_layer_kinds_nonempty_pointwise() {
// Support-`Vec` surface: `layer_kinds_any_observed() ==
// !present_layer_kinds().is_empty()`. Pins the predicate
// against the `Vec<ConfigSourceKind>` non-empty form consumers
// reach for when they already hold the support vector. Peer of
// `tiers_any_observed_agrees_with_contributing_tiers_nonempty_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_any_observed();
let via_vec = !slice.present_layer_kinds().is_empty();
assert_eq!(
via_seam, via_vec,
"layer_kinds_any_observed ({via_seam}) must agree with \
!present_layer_kinds().is_empty() ({via_vec}) for chain",
);
}
}
#[test]
fn layer_kinds_any_observed_agrees_with_absent_layer_kinds_count_below_axis_cardinality_pointwise()
{
// Coverage-gap-scalar surface: `layer_kinds_any_observed() ==
// (absent_layer_kinds_count() <
// crate::axis_cardinality::<ConfigSourceKind>())`. The dual-
// side surfacing of the same boolean across the (observed,
// unobserved) partition. Peer of
// `tiers_any_observed_agrees_with_absent_tiers_count_below_axis_cardinality_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_any_observed();
let via_gap =
slice.absent_layer_kinds_count() < crate::axis_cardinality::<ConfigSourceKind>();
assert_eq!(
via_seam, via_gap,
"layer_kinds_any_observed ({via_seam}) must agree with \
absent_layer_kinds_count < axis_cardinality ({via_gap}) for chain",
);
}
}
#[test]
fn layer_kinds_any_observed_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has no observed cells,
// so the "any observed" predicate fails —
// `layer_kinds_any_observed` reads `false`. Matches
// `is_empty` reading `true` on the empty histogram over the
// ConfigSourceKind axis one altitude down. Dual of
// `layer_kinds_balanced_empty_chain_is_true`: the empty chain
// is on the opposite side of the any-observed boundary from
// the balanced boundary and on the same side as the full-cover
// boundary — the (`any_observed`=false, `balanced`=true,
// `full_cover`=false) polarity triple. Peer of
// `tiers_any_observed_empty_map_is_false` on the tier altitude
// and `kinds_any_observed_empty_diff_is_false` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_any_observed());
assert!(empty.layer_kinds_balanced());
assert!(!empty.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_any_observed_singleton_support_is_true() {
// Singleton-support pin: every layer lands on the same kind,
// so one observed cell out of three suffices for the any-
// observed predicate — `layer_kinds_any_observed` reads
// `true`. Peer of `layer_kinds_balanced_singleton_support_is_true`
// on the same side of the boundary and orthogonal to
// `layer_kinds_full_cover_singleton_support_is_false` on the
// opposite side: singleton-support is trivially observed and
// trivially balanced but never full-cover on a three-cell
// axis. Peer of `tiers_any_observed_singleton_support_is_true`
// on the tier altitude — same
// (`any_observed`=true, `balanced`=true, `full_cover`=false)
// polarity triple on the singleton-support fixture.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_any_observed());
assert!(slice.layer_kinds_balanced());
assert!(!slice.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_any_observed_uniform_cover_is_true() {
// Uniform-cover pin: every kind contributes one layer, so
// every cell of `ConfigSourceKind::ALL` receives at least one
// observation — `layer_kinds_any_observed` reads `true`. Peer
// of `layer_kinds_balanced_uniform_cover_is_true` and
// `layer_kinds_full_cover_uniform_cover_is_true`: uniform
// three-kind cover is on the `true` side of ALL THREE
// coverage-support boundaries at this sub-axis. Peer of
// `tiers_any_observed_uniform_cover_is_true` on the tier
// altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_any_observed());
assert!(slice.layer_kinds_balanced());
assert!(slice.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_any_observed_two_kind_partial_cover_is_true() {
// Two-kind-cover pin: `sample_chain()` observes {Env, File}
// (support size 2 out of 3), so at least one cell is observed
// — `layer_kinds_any_observed` reads `true`. Direct witness of
// `layer_kinds_full_cover ⇒ layer_kinds_any_observed` on a
// fixture where full-cover reads `false` but any-observed
// still holds. Peer of
// `tiers_any_observed_three_tier_partial_cover_is_true` on the
// tier altitude at the sister partial-cover fixture.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(slice.layer_kinds_any_observed());
assert!(!slice.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_full_cover_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_full_cover() ⇒
// layer_kinds_any_observed()` on every fixture — a full-cover
// chain observes every cell, so it observes at least one cell.
// Peer of `tiers_full_cover_implies_tiers_any_observed_pointwise`
// on the tier altitude and
// `kinds_full_cover_implies_kinds_any_observed_pointwise` on
// the diff altitude. Names the ordering `full_cover ≤
// any_observed` on the coverage-support partition at the
// layer-kind sub-axis.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_full_cover() {
assert!(
slice.layer_kinds_any_observed(),
"full-cover chain must be any-observed (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn layer_kinds_any_observed_implies_chain_length_positive_pointwise() {
// Chain-length lower-bound pin: `layer_kinds_any_observed() ⇒
// self.as_ref().len() >= 1`. A chain observing any layer kind
// carries at least one layer. Peer of
// `tiers_any_observed_implies_leaf_count_positive_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_any_observed() {
assert!(
!slice.is_empty(),
"any-observed chain must be non-empty (len={})",
slice.len(),
);
}
}
}
#[test]
fn layer_kinds_any_observed_negation_implies_layer_kinds_balanced_pointwise() {
// Empty-chain / vacuous-balanced interaction pin: the empty
// chain is the only chain on the `false` side of
// `layer_kinds_any_observed`, and it is vacuously balanced. So
// `!layer_kinds_any_observed() ⇒ layer_kinds_balanced()`
// holds pointwise. Peer of
// `tiers_any_observed_negation_implies_tiers_balanced_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if !slice.layer_kinds_any_observed() {
assert!(
slice.layer_kinds_balanced(),
"non-any-observed chain must be vacuously balanced",
);
}
}
}
#[test]
fn layer_kinds_any_observed_agrees_with_open_coded_any_positive_walk() {
// Parity against the exact hand-rolled any-observed walk this
// lift replaces: walk every cell of the histogram and check
// any count is positive. Mirrors the parity pin
// `tiers_any_observed_agrees_with_open_coded_any_positive_walk`
// on the tier altitude and
// `kinds_any_observed_agrees_with_open_coded_any_positive_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_any_observed();
let hist = slice.layer_kind_histogram();
let hand_rolled = hist.iter().any(|(_, c)| c > 0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::layer_kinds_singular_support —
// singleton-support-layer-kinds boolean predicate on the
// layer-kind sub-axis of the chain altitude, lifting
// has_singular_support from the histogram surface and lifting
// the "singleton-support across altitudes" projection sideways
// from the tier altitude
// (`ProvenanceMap::tiers_singular_support`) into the first
// chain sub-axis. Routed through the shared
// `AxisHistogram::has_singular_support` primitive one altitude
// down. ----
#[test]
fn layer_kinds_singular_support_matches_layer_kind_histogram_has_singular_support_pointwise() {
// Routing pin: `layer_kinds_singular_support` routes through
// `layer_kind_histogram().has_singular_support()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Layer-
// kind sub-axis peer of
// `tiers_singular_support_matches_tier_histogram_has_singular_support_pointwise`
// on the tier altitude and
// `kinds_singular_support_matches_kind_histogram_has_singular_support_pointwise`
// on the diff altitude, in the "singleton-support across
// altitudes" projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().has_singular_support();
assert_eq!(slice.layer_kinds_singular_support(), via_histogram);
}
}
#[test]
fn layer_kinds_singular_support_agrees_with_present_layer_kinds_count_equals_one_pointwise() {
// Support-scalar surface: `layer_kinds_singular_support() ==
// (present_layer_kinds_count() == 1)` on every fixture. The
// support-side surfacing of the same boolean, without
// allocating the `Vec<ConfigSourceKind>`. Lifted from the
// trait-uniform `has_singular_support() ⇔ distinct_cells() == 1`
// law on AxisHistogram. Peer of
// `tiers_singular_support_agrees_with_contributing_tiers_count_equals_one_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular_support();
let via_scalar = slice.present_layer_kinds_count() == 1;
assert_eq!(
via_seam,
via_scalar,
"layer_kinds_singular_support ({via_seam}) must agree with \
present_layer_kinds_count == 1 (count={c}) for chain",
c = slice.present_layer_kinds_count(),
);
}
}
#[test]
fn layer_kinds_singular_support_agrees_with_present_layer_kinds_len_equals_one_pointwise() {
// Support-`Vec` form: `layer_kinds_singular_support() ==
// (present_layer_kinds().len() == 1)` on every fixture. Pins
// the predicate against the `Vec<ConfigSourceKind>` length
// form consumers reach for when they already hold the support
// vector. Peer of
// `tiers_singular_support_agrees_with_contributing_tiers_len_equals_one_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular_support();
let via_vec = slice.present_layer_kinds().len() == 1;
assert_eq!(
via_seam, via_vec,
"layer_kinds_singular_support ({via_seam}) must agree with \
present_layer_kinds().len() == 1 ({via_vec}) for chain",
);
}
}
#[test]
fn layer_kinds_singular_support_agrees_with_absent_layer_kinds_count_equals_axis_cardinality_minus_one_pointwise()
{
// Coverage-gap-scalar form: `layer_kinds_singular_support() ==
// (absent_layer_kinds_count() ==
// axis_cardinality::<ConfigSourceKind>() - 1)` on every
// fixture. The coverage-gap-side surfacing of the same
// boolean — a singleton-support chain observes one cell and
// misses the remaining `axis_cardinality - 1` cells. Peer of
// `tiers_singular_support_agrees_with_absent_tiers_count_equals_axis_cardinality_minus_one_pointwise`.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular_support();
let via_gap = slice.absent_layer_kinds_count()
== crate::axis_cardinality::<ConfigSourceKind>() - 1;
assert_eq!(
via_seam,
via_gap,
"layer_kinds_singular_support ({via_seam}) must agree with \
absent_layer_kinds_count == axis_cardinality - 1 (gap={g}) for chain",
g = slice.absent_layer_kinds_count(),
);
}
}
#[test]
fn layer_kinds_singular_support_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has no observed cells,
// so the singular-support predicate reads `false` (support
// cardinality is 0, not 1). Matches `has_singular_support`
// reading `false` on the empty histogram one altitude down.
// Peer of `layer_kinds_any_observed_empty_chain_is_false` and
// `layer_kinds_full_cover_empty_chain_is_false` on the same
// polarity of the coverage-support partition, and orthogonal
// to `layer_kinds_balanced_empty_chain_is_true` on the
// opposite polarity — the four boundaries partition the
// empty chain into the polarity quadruple
// (`any_observed`=false, `singular_support`=false,
// `balanced`=true, `full_cover`=false). Peer of
// `tiers_singular_support_empty_map_is_false` on the tier
// altitude and `kinds_singular_support_empty_diff_is_false` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_singular_support());
assert!(!empty.layer_kinds_any_observed());
assert!(empty.layer_kinds_balanced());
assert!(!empty.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_singular_support_singleton_support_is_true() {
// Singleton-support pin: every layer lands on the same kind,
// so the support is exactly one cell —
// `layer_kinds_singular_support` reads `true`. Peer of
// `layer_kinds_any_observed_singleton_support_is_true` and
// `layer_kinds_balanced_singleton_support_is_true` on the
// same polarity and orthogonal to
// `layer_kinds_full_cover_singleton_support_is_false` on the
// opposite polarity. The singleton-support fixture partitions
// the four boundaries with (`any_observed`=true,
// `singular_support`=true, `balanced`=true,
// `full_cover`=false). Peer of
// `tiers_singular_support_singleton_support_is_true` on the
// tier altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_support());
assert!(slice.layer_kinds_any_observed());
assert!(slice.layer_kinds_balanced());
assert!(!slice.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_singular_support_uniform_cover_is_false() {
// Uniform-cover pin: every kind contributes one layer, so the
// support is the full three-cell axis —
// `layer_kinds_singular_support` reads `false` (three, not
// one). The uniform three-kind cover is on the `false` side
// of the singular-support boundary and on the `true` side of
// the other three coverage-support boundaries. Peer of
// `tiers_singular_support_uniform_cover_is_false` on the tier
// altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(!slice.layer_kinds_singular_support());
assert!(slice.layer_kinds_any_observed());
assert!(slice.layer_kinds_balanced());
assert!(slice.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_singular_support_two_kind_partial_cover_is_false() {
// Two-kind-cover pin: `sample_chain()` observes {Env, File}
// (support size 2 out of 3) — `layer_kinds_singular_support`
// reads `false` (two, not one) even though
// `layer_kinds_any_observed` reads `true`. Direct witness of
// the strict subsumption `layer_kinds_singular_support ⇒
// layer_kinds_any_observed` on a fixture where the two
// boundaries split. Peer of
// `tiers_singular_support_two_tier_partial_cover_is_false` on
// the tier altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(!slice.layer_kinds_singular_support());
assert!(slice.layer_kinds_any_observed());
}
#[test]
fn layer_kinds_singular_support_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_singular_support() ⇒
// layer_kinds_any_observed()` on every fixture — a chain with
// exactly one observed cell has at least one observed cell.
// The strict subsumption relates the singleton-support
// boundary and the any-observed boundary as strictly-tighter
// cardinality slices of the coverage-support partition
// (=1 ⇒ ≥1). Peer of
// `tiers_singular_support_implies_tiers_any_observed_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
slice.layer_kinds_any_observed(),
"singular-support chain must be any-observed",
);
}
}
}
#[test]
fn layer_kinds_singular_support_implies_layer_kinds_balanced_pointwise() {
// Subsumption pin: `layer_kinds_singular_support() ⇒
// layer_kinds_balanced()` on every fixture — a chain with
// exactly one observed count has a trivially uniform support
// (a single value is vacuously equal to itself), so the
// balanced predicate holds. Pins the interaction between the
// singular-support boundary and the uniformity boundary. Peer
// of `tiers_singular_support_implies_tiers_balanced_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
slice.layer_kinds_balanced(),
"singular-support chain must be balanced",
);
}
}
}
#[test]
fn layer_kinds_singular_support_implies_not_layer_kinds_full_cover_pointwise() {
// Disjointness pin: `layer_kinds_singular_support() ⇒
// !layer_kinds_full_cover()` on every fixture. A singleton
// support has cardinality 1; a full cover has cardinality
// `axis_cardinality::<ConfigSourceKind>()` (three). The two
// are disjoint on every axis with cardinality `>= 2`, which
// includes ConfigSourceKind (three cells). Direct witness
// that the two coverage-support boundaries are pairwise
// disjoint on the implementor set today. Peer of
// `tiers_singular_support_implies_not_tiers_full_cover_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
!slice.layer_kinds_full_cover(),
"singular-support chain cannot be full-cover on \
a cardinality >= 2 axis",
);
}
}
}
#[test]
fn layer_kinds_singular_support_implies_chain_length_positive_pointwise() {
// Chain-length lower-bound pin: `layer_kinds_singular_support()
// ⇒ self.as_ref().len() >= 1`. Any chain with a singleton
// support has at least one layer contributing to the one
// observed cell. Peer of
// `layer_kinds_any_observed_implies_chain_length_positive_pointwise`
// on the strictly-tighter cardinality slice of the same
// coverage-support partition. Peer of
// `tiers_singular_support_implies_leaf_count_positive_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
!slice.is_empty(),
"singular-support chain must have at least one layer (len={})",
slice.len(),
);
}
}
}
#[test]
fn layer_kinds_singular_support_implies_dominant_equals_recessive_pointwise() {
// Modal-collapse pin: `layer_kinds_singular_support() ⇒
// dominant_layer_kind() == recessive_layer_kind() &&
// dominant_layer_kind().is_some()`. When support is
// singular, the modal pair collapses to the one observed cell
// on both sides. Direct witness of the trait-uniform
// `has_singular_support() ⇒ dominant_cell() == recessive_cell()`
// law on AxisHistogram, lifted to the layer-kind sub-axis of
// the chain altitude. Peer of
// `tiers_singular_support_implies_dominant_equals_recessive_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
let dom = slice.dominant_layer_kind();
let rec = slice.recessive_layer_kind();
assert!(
dom.is_some(),
"singular-support chain must have Some dominant layer-kind",
);
assert_eq!(
dom, rec,
"singular-support chain must have dominant == recessive",
);
}
}
}
#[test]
fn layer_kinds_any_observed_negation_implies_not_layer_kinds_singular_support_pointwise() {
// Contrapositive: `!layer_kinds_any_observed() ⇒
// !layer_kinds_singular_support()`. If no cell was observed,
// the support is empty (cardinality 0), which is strictly
// less than 1 — the singleton-support predicate fails. Pins
// the strictly-tighter cardinality relation between the two
// coverage-support boundaries. Peer of
// `tiers_any_observed_negation_implies_not_tiers_singular_support_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if !slice.layer_kinds_any_observed() {
assert!(
!slice.layer_kinds_singular_support(),
"empty-support chain cannot be singular-support",
);
}
}
}
#[test]
fn layer_kinds_singular_support_agrees_with_open_coded_exactly_one_positive_walk() {
// Parity against the exact hand-rolled singular-support walk
// this lift replaces: walk every cell of the histogram and
// count how many carry a positive count; the singleton-
// support predicate reads `true` iff exactly one cell is
// positive. Mirrors the parity pins
// `layer_kinds_any_observed_agrees_with_open_coded_any_positive_walk`
// on the same coverage-support partition's cardinality-≥1
// boundary and
// `tiers_singular_support_agrees_with_open_coded_exactly_one_positive_walk`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular_support();
let hist = slice.layer_kind_histogram();
let hand_rolled = hist.iter().filter(|(_, c)| *c > 0).count() == 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::layer_kinds_singular_gap — singleton-gap-
// layer-kinds boolean predicate on the layer-kind sub-axis of
// the chain altitude, lifting the "singleton-gap across
// altitudes" projection sideways from the tier altitude
// (`ProvenanceMap::tiers_singular_gap`) into the first chain
// sub-axis. Routed through the shared
// `AxisHistogram::has_singular_gap` primitive one altitude
// down. ----
#[test]
fn layer_kinds_singular_gap_matches_layer_kind_histogram_has_singular_gap_pointwise() {
// Routing pin: `layer_kinds_singular_gap` routes through
// `layer_kind_histogram().has_singular_gap()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Layer-
// kind sub-axis peer of
// `tiers_singular_gap_matches_tier_histogram_has_singular_gap_pointwise`
// on the tier altitude and
// `kinds_singular_gap_matches_kind_histogram_has_singular_gap_pointwise`
// on the diff altitude, in the "singleton-gap across
// altitudes" projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().has_singular_gap();
assert_eq!(slice.layer_kinds_singular_gap(), via_histogram);
}
}
#[test]
fn layer_kinds_singular_gap_agrees_with_absent_layer_kinds_count_equals_one_pointwise() {
// Coverage-gap-scalar surface: `layer_kinds_singular_gap() ==
// (absent_layer_kinds_count() == 1)` on every fixture. The
// coverage-gap-side scalar surfacing of the same boolean,
// without allocating the `Vec<ConfigSourceKind>`. Peer of
// `tiers_singular_gap_agrees_with_absent_tiers_count_equals_one_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular_gap();
let via_gap_scalar = slice.absent_layer_kinds_count() == 1;
assert_eq!(
via_seam,
via_gap_scalar,
"layer_kinds_singular_gap ({via_seam}) must agree with \
absent_layer_kinds_count == 1 (gap={g}) for chain",
g = slice.absent_layer_kinds_count(),
);
}
}
#[test]
fn layer_kinds_singular_gap_agrees_with_absent_layer_kinds_len_equals_one_pointwise() {
// Coverage-gap-`Vec` form: `layer_kinds_singular_gap() ==
// (absent_layer_kinds().len() == 1)` on every fixture. Pins
// the predicate against the `Vec<ConfigSourceKind>` length
// form consumers reach for when they already hold the
// coverage-gap vector. Peer of
// `tiers_singular_gap_agrees_with_absent_tiers_len_equals_one_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular_gap();
let via_vec = slice.absent_layer_kinds().len() == 1;
assert_eq!(
via_seam, via_vec,
"layer_kinds_singular_gap ({via_seam}) must agree with \
absent_layer_kinds().len() == 1 ({via_vec}) for chain",
);
}
}
#[test]
fn layer_kinds_singular_gap_agrees_with_present_layer_kinds_count_equals_axis_cardinality_minus_one_pointwise()
{
// Support-scalar form: `layer_kinds_singular_gap() ==
// (present_layer_kinds_count() ==
// axis_cardinality::<ConfigSourceKind>() - 1)` on every
// fixture. The support-side surfacing of the same boolean —
// a singleton-gap chain observes `axis_cardinality - 1` cells
// and misses one. Peer of
// `tiers_singular_gap_agrees_with_contributing_tiers_count_equals_axis_cardinality_minus_one_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular_gap();
let via_support_scalar = slice.present_layer_kinds_count()
== crate::axis_cardinality::<ConfigSourceKind>() - 1;
assert_eq!(
via_seam,
via_support_scalar,
"layer_kinds_singular_gap ({via_seam}) must agree with \
present_layer_kinds_count == axis_cardinality - 1 (count={c}) for chain",
c = slice.present_layer_kinds_count(),
);
}
}
#[test]
fn layer_kinds_singular_gap_agrees_with_present_layer_kinds_len_equals_axis_cardinality_minus_one_pointwise()
{
// Support-`Vec` form: `layer_kinds_singular_gap() ==
// (present_layer_kinds().len() == axis_cardinality::<ConfigSourceKind>()
// - 1)` on every fixture. Pins the predicate against the
// `Vec<ConfigSourceKind>` length form consumers reach for
// when they already hold the support vector. Peer of
// `tiers_singular_gap_agrees_with_contributing_tiers_len_equals_axis_cardinality_minus_one_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular_gap();
let via_support_vec = slice.present_layer_kinds().len()
== crate::axis_cardinality::<ConfigSourceKind>() - 1;
assert_eq!(
via_seam, via_support_vec,
"layer_kinds_singular_gap ({via_seam}) must agree with \
present_layer_kinds().len() == axis_cardinality - 1 ({via_support_vec}) for chain",
);
}
}
#[test]
fn layer_kinds_singular_gap_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has every cell
// unobserved (three, not one), so the singular-gap predicate
// reads `false`. Matches `has_singular_gap` reading `false`
// on the empty histogram one altitude down. Peer of
// `layer_kinds_any_observed_empty_chain_is_false`,
// `layer_kinds_full_cover_empty_chain_is_false`, and
// `layer_kinds_singular_support_empty_chain_is_false` on the
// same polarity of the coverage-support partition, and
// orthogonal to `layer_kinds_balanced_empty_chain_is_true` on
// the opposite polarity — the five boundaries partition the
// empty chain into the polarity quintuple
// (`any_observed`=false, `singular_support`=false,
// `singular_gap`=false, `balanced`=true, `full_cover`=false).
// Peer of `tiers_singular_gap_empty_map_is_false` on the tier
// altitude and `kinds_singular_gap_empty_diff_is_false` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_singular_gap());
assert!(!empty.layer_kinds_any_observed());
assert!(empty.layer_kinds_balanced());
assert!(!empty.layer_kinds_full_cover());
assert!(!empty.layer_kinds_singular_support());
}
#[test]
fn layer_kinds_singular_gap_singleton_support_is_false() {
// Singleton-support pin: every layer lands on the same kind,
// so two cells are unobserved on the three-cell axis (not
// one) — `layer_kinds_singular_gap` reads `false`. The row
// this predicate isolates from the singleton-support boundary
// one cardinality slice over: the strict disjointness
// `layer_kinds_singular_gap ⇒ !layer_kinds_singular_support`
// (adjacent support cardinalities `1` vs. `2` on this axis).
// Peer of `tiers_singular_gap_singleton_support_is_false` on
// the tier altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_support());
assert!(!slice.layer_kinds_singular_gap());
assert!(slice.layer_kinds_any_observed());
assert!(slice.layer_kinds_balanced());
assert!(!slice.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_singular_gap_two_kind_partial_cover_is_true() {
// Two-kind-cover pin: `sample_chain()` observes {Env, File}
// (support size 2 out of 3, missing {Defaults}) —
// `layer_kinds_singular_gap` reads `true`. The row this
// predicate isolates from the surrounding boundaries: direct
// witness of the strict subsumption `layer_kinds_singular_gap
// ⇒ layer_kinds_any_observed` and the disjointness
// `layer_kinds_singular_gap ⇒ !layer_kinds_full_cover` on the
// same fixture. Peer of
// `tiers_singular_gap_three_tier_partial_cover_is_true` on
// the tier altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert_eq!(slice.absent_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_gap());
assert!(slice.layer_kinds_any_observed());
assert!(!slice.layer_kinds_singular_support());
assert!(!slice.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_singular_gap_uniform_cover_is_false() {
// Uniform-cover pin: every kind contributes one layer, so
// zero cells are unobserved (not one) —
// `layer_kinds_singular_gap` reads `false`. The uniform
// three-kind cover is on the `false` side of the singular-
// gap boundary and on the `true` side of `full_cover` — the
// two boundaries are disjoint at the top of the coverage-
// support partition (adjacent support cardinalities
// `axis_cardinality - 1` and `axis_cardinality`). Peer of
// `tiers_singular_gap_uniform_cover_is_false` on the tier
// altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(!slice.layer_kinds_singular_gap());
assert!(slice.layer_kinds_any_observed());
assert!(slice.layer_kinds_balanced());
assert!(slice.layer_kinds_full_cover());
assert!(!slice.layer_kinds_singular_support());
}
#[test]
fn layer_kinds_singular_gap_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_singular_gap() ⇒
// layer_kinds_any_observed()` on every fixture — a chain
// missing exactly one cell observes at least
// `axis_cardinality - 1 >= 1` cells (ConfigSourceKind carries
// three cells). The strict subsumption relates the singleton-
// gap boundary and the any-observed boundary as strictly-
// tighter cardinality slices of the coverage-support
// partition (=axis_cardinality - 1 ⇒ ≥1). Peer of
// `tiers_singular_gap_implies_tiers_any_observed_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_gap() {
assert!(
slice.layer_kinds_any_observed(),
"singular-gap chain must be any-observed",
);
}
}
}
#[test]
fn layer_kinds_singular_gap_implies_not_layer_kinds_full_cover_pointwise() {
// Disjointness pin: `layer_kinds_singular_gap() ⇒
// !layer_kinds_full_cover()` on every fixture. Full cover has
// zero unobserved cells; singular gap has exactly one — the
// two boundaries are disjoint on every axis. Peer of
// `tiers_singular_gap_implies_not_tiers_full_cover_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_gap() {
assert!(
!slice.layer_kinds_full_cover(),
"singular-gap chain cannot be full-cover",
);
}
}
}
#[test]
fn layer_kinds_singular_gap_implies_not_layer_kinds_singular_support_pointwise() {
// Disjointness pin: `layer_kinds_singular_gap() ⇒
// !layer_kinds_singular_support()` on every fixture. On the
// three-cell [`ConfigSourceKind`] axis, singleton-support has
// support cardinality `1` and singleton-gap has support
// cardinality `axis_cardinality - 1 = 2`, so the two are
// disjoint. Direct witness of the strict disjointness between
// the two coverage-support boundary predicates on a
// cardinality-≥3 axis. Peer of
// `tiers_singular_gap_implies_not_tiers_singular_support_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_gap() {
assert!(
!slice.layer_kinds_singular_support(),
"singular-gap chain cannot be singular-support on \
a cardinality >= 3 axis",
);
}
}
}
#[test]
fn layer_kinds_singular_gap_implies_chain_length_at_least_axis_cardinality_minus_one_pointwise()
{
// Chain-length lower-bound pin: `layer_kinds_singular_gap()
// ⇒ self.as_ref().len() >= axis_cardinality::<ConfigSourceKind>()
// - 1`. Any chain missing exactly one cell has at least one
// layer for each of the `axis_cardinality - 1` observed cells.
// Tightened from the `>= 1` bound `layer_kinds_singular_support`
// carries to `>= axis_cardinality - 1` since every observed
// cell has at least one layer. Peer of
// `tiers_singular_gap_implies_leaf_count_at_least_axis_cardinality_minus_one_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_gap() {
assert!(
slice.len() >= crate::axis_cardinality::<ConfigSourceKind>() - 1,
"singular-gap chain must have at least axis_cardinality - 1 = {} \
layers (len={})",
crate::axis_cardinality::<ConfigSourceKind>() - 1,
slice.len(),
);
}
}
}
#[test]
fn layer_kinds_any_observed_negation_implies_not_layer_kinds_singular_gap_pointwise() {
// Contrapositive: `!layer_kinds_any_observed() ⇒
// !layer_kinds_singular_gap()` on every axis with cardinality
// `>= 2`. If no cell was observed, the coverage gap has size
// `axis_cardinality > 1`, so the singleton-gap predicate
// fails. Pins the strictly-looser cardinality relation
// between the two coverage-support boundaries in the negative
// direction. Peer of
// `tiers_any_observed_negation_implies_not_tiers_singular_gap_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if !slice.layer_kinds_any_observed() {
assert!(
!slice.layer_kinds_singular_gap(),
"empty-support chain cannot be singular-gap on a \
cardinality >= 2 axis",
);
}
}
}
#[test]
fn layer_kinds_singular_gap_agrees_with_open_coded_exactly_one_zero_walk() {
// Parity against the exact hand-rolled singular-gap walk this
// lift replaces: walk every cell of the histogram and count
// how many carry a zero count; the singleton-gap predicate
// reads `true` iff exactly one cell is zero. Mirrors the
// parity pins
// `tiers_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the tier altitude and
// `kinds_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular_gap();
let hist = slice.layer_kind_histogram();
let hand_rolled = hist.iter().filter(|(_, c)| *c == 0).count() == 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::layer_kinds_strict_partial_cover —
// strict-partial-cover-layer-kinds boolean predicate on the
// layer-kind sub-axis of the chain altitude, lifting the
// "strict-partial-cover across altitudes" projection sideways
// from the tier altitude
// (`ProvenanceMap::tiers_strict_partial_cover`) into the first
// chain sub-axis. Routed through the shared
// `AxisHistogram::has_strict_partial_cover` primitive one
// altitude down. Vacuously `false` on every chain by the
// cardinality-`3` reachability convention — `ConfigSourceKind`
// carries three cells so the strict interval
// `[2, cardinality - 2] = [2, 1]` is empty. ----
#[test]
fn layer_kinds_strict_partial_cover_matches_layer_kind_histogram_has_strict_partial_cover_pointwise()
{
// Routing pin: `layer_kinds_strict_partial_cover` routes through
// `layer_kind_histogram().has_strict_partial_cover()`, so the
// two seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Layer-
// kind sub-axis peer of
// `tiers_strict_partial_cover_matches_tier_histogram_has_strict_partial_cover_pointwise`
// on the tier altitude and
// `kinds_strict_partial_cover_matches_kind_histogram_has_strict_partial_cover_pointwise`
// on the diff altitude, in the "strict-partial-cover across
// altitudes" projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().has_strict_partial_cover();
assert_eq!(slice.layer_kinds_strict_partial_cover(), via_histogram);
}
}
#[test]
fn layer_kinds_strict_partial_cover_matches_structural_conjunction_pointwise() {
// Defining structural-conjunction form:
// `layer_kinds_strict_partial_cover() ⇔
// layer_kind_histogram().has_partial_cover() &&
// !layer_kinds_singular_support() &&
// !layer_kinds_singular_gap()` on every fixture. Pins the
// predicate against the three-way conjunction on the existing
// named-boundary triad consumers reach for when they open-code
// the strict interior in structural terms. Peer of
// `tiers_strict_partial_cover_matches_structural_conjunction_pointwise`
// on the tier altitude and
// `kinds_strict_partial_cover_matches_structural_conjunction_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_strict_partial_cover();
let via_structural = slice.layer_kind_histogram().has_partial_cover()
&& !slice.layer_kinds_singular_support()
&& !slice.layer_kinds_singular_gap();
assert_eq!(
via_seam, via_structural,
"layer_kinds_strict_partial_cover ({via_seam}) must agree with \
has_partial_cover && !singular_support && !singular_gap ({via_structural})",
);
}
}
#[test]
fn layer_kinds_strict_partial_cover_agrees_with_present_layer_kinds_count_strict_interval_pointwise()
{
// Support-scalar strict-interval form:
// `layer_kinds_strict_partial_cover() == (1 <
// present_layer_kinds_count() && present_layer_kinds_count() + 1
// < axis_cardinality::<ConfigSourceKind>())` on every fixture.
// The support-side surfacing of the same boolean, without
// allocating the `Vec<ConfigSourceKind>`. Peer of
// `tiers_strict_partial_cover_agrees_with_contributing_tiers_count_strict_interval_pointwise`
// on the tier altitude and
// `kinds_strict_partial_cover_agrees_with_present_kinds_count_strict_interval_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_strict_partial_cover();
let count = slice.present_layer_kinds_count();
let via_interval =
1 < count && count + 1 < crate::axis_cardinality::<ConfigSourceKind>();
assert_eq!(
via_seam, via_interval,
"layer_kinds_strict_partial_cover ({via_seam}) must agree with \
1 < present_layer_kinds_count && present_layer_kinds_count + 1 < axis_cardinality \
(count={count})",
);
}
}
#[test]
fn layer_kinds_strict_partial_cover_agrees_with_absent_layer_kinds_count_strict_interval_pointwise()
{
// Coverage-gap-scalar strict-interval form:
// `layer_kinds_strict_partial_cover() == (1 <
// absent_layer_kinds_count() && absent_layer_kinds_count() + 1
// < axis_cardinality::<ConfigSourceKind>())` on every fixture.
// The coverage-gap-side surfacing of the same boolean, without
// allocating the `Vec<ConfigSourceKind>`. Complementary to the
// support-scalar strict-interval form on the same partition via
// the `present_layer_kinds_count + absent_layer_kinds_count ==
// axis_cardinality` invariant. Peer of
// `tiers_strict_partial_cover_agrees_with_absent_tiers_count_strict_interval_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_strict_partial_cover();
let gap = slice.absent_layer_kinds_count();
let via_interval = 1 < gap && gap + 1 < crate::axis_cardinality::<ConfigSourceKind>();
assert_eq!(
via_seam, via_interval,
"layer_kinds_strict_partial_cover ({via_seam}) must agree with \
1 < absent_layer_kinds_count && absent_layer_kinds_count + 1 < axis_cardinality \
(gap={gap})",
);
}
}
#[test]
fn layer_kinds_strict_partial_cover_agrees_with_dual_vec_at_least_two_of_each_pointwise() {
// Dual-`Vec` at-least-two-of-each form:
// `layer_kinds_strict_partial_cover() ==
// (present_layer_kinds().len() >= 2 &&
// absent_layer_kinds().len() >= 2)` on every fixture. Pins the
// predicate against the dual-vector form consumers reach for
// when they already hold both support and coverage-gap vectors
// — the allocating-both-vectors open-coding this lift replaces.
// Peer of
// `tiers_strict_partial_cover_agrees_with_dual_vec_at_least_two_of_each_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_strict_partial_cover();
let via_vec =
slice.present_layer_kinds().len() >= 2 && slice.absent_layer_kinds().len() >= 2;
assert_eq!(
via_seam, via_vec,
"layer_kinds_strict_partial_cover ({via_seam}) must agree with \
present_layer_kinds().len() >= 2 && absent_layer_kinds().len() >= 2 ({via_vec})",
);
}
}
#[test]
fn layer_kinds_strict_partial_cover_chain_altitude_is_vacuously_false_pointwise() {
// Cardinality-conditional reachability pin at the chain layer-
// kind sub-axis: `!layer_kinds_strict_partial_cover()` on every
// chain fixture. `ConfigSourceKind` carries three cells, so the
// strict interval `[2, cardinality - 2] = [2, 1]` on the
// support-cardinality scalar is empty — no chain can observe
// `>= 2` cells AND leave `>= 2` cells unobserved simultaneously.
// Trait-uniform pin of the lift's vacuously-`false` polarity at
// the chain layer-kind sub-axis, matching
// `AxisHistogram::has_strict_partial_cover`'s cardinality-`3`
// scan one altitude down and the diff-altitude peer
// `kinds_strict_partial_cover_diff_altitude_is_vacuously_false_pointwise`
// (also on cardinality `3`). Distinguishes this chain sub-axis
// from the tier altitude and the chain file-format sub-axis,
// where cardinality `>= 4` opens a strict-interior witness.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
assert!(
!slice.layer_kinds_strict_partial_cover(),
"layer_kinds_strict_partial_cover must read false on every \
ConfigSourceKind (cardinality-3) chain — the strict interior \
is unreachable on cardinality-`<= 3` axes",
);
}
}
#[test]
fn layer_kinds_strict_partial_cover_empty_chain_is_false() {
// Empty-chain boundary: the empty chain observes zero cells, so
// the "at least two observed" half of the conjunction fails
// uniformly — `layer_kinds_strict_partial_cover` reads `false`.
// Matches `has_strict_partial_cover` reading `false` on the
// empty histogram one altitude down. Peer of
// `layer_kinds_any_observed_empty_chain_is_false`,
// `layer_kinds_full_cover_empty_chain_is_false`,
// `layer_kinds_singular_support_empty_chain_is_false`, and
// `layer_kinds_singular_gap_empty_chain_is_false` on the same
// polarity of the coverage-support partition. Peer of
// `tiers_strict_partial_cover_empty_map_is_false` on the tier
// altitude and
// `kinds_strict_partial_cover_empty_diff_is_false` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_strict_partial_cover());
assert!(!empty.layer_kinds_any_observed());
assert!(!empty.layer_kinds_singular_support());
assert!(!empty.layer_kinds_singular_gap());
assert!(!empty.layer_kinds_full_cover());
}
#[test]
fn layer_kinds_strict_partial_cover_singleton_support_is_false() {
// Singleton-support pin: every layer lands on the same kind, so
// the support cardinality is `1` (not `>= 2`) — the "at least
// two observed" half fails uniformly. Direct witness of the
// strict disjointness `layer_kinds_singular_support ⇒
// !layer_kinds_strict_partial_cover`. Peer of
// `tiers_strict_partial_cover_singleton_support_is_false` on
// the tier altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_support());
assert!(!slice.layer_kinds_strict_partial_cover());
}
#[test]
fn layer_kinds_strict_partial_cover_two_kind_partial_cover_is_false() {
// Two-kind-cover pin: `sample_chain()` observes {Env, File}
// (support size 2 out of 3, missing {Defaults}) — the coverage
// gap is `1` (not `>= 2`), so the "at least two unobserved"
// half fails uniformly and `layer_kinds_strict_partial_cover`
// reads `false`. Direct witness of the strict disjointness
// `layer_kinds_singular_gap ⇒
// !layer_kinds_strict_partial_cover` on the cardinality-`3`
// axis (the two boundaries occupy adjacent, non-overlapping
// support-cardinality slices). Distinguishes the chain layer-
// kind sub-axis from the tier altitude, where the two-tier
// partial cover falls on the strict interior (cardinality-`4`
// reachability opens a strict-interior witness at support
// cardinality `2`).
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert_eq!(slice.absent_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_gap());
assert!(!slice.layer_kinds_strict_partial_cover());
}
#[test]
fn layer_kinds_strict_partial_cover_uniform_cover_is_false() {
// Uniform-cover pin: every kind contributes at least one layer,
// so zero cells are unobserved — the "at least two unobserved"
// half fails uniformly. Direct witness of the strict
// disjointness `layer_kinds_full_cover ⇒
// !layer_kinds_strict_partial_cover` on every axis. Peer of
// `tiers_strict_partial_cover_uniform_cover_is_false` on the
// tier altitude and
// `kinds_strict_partial_cover_uniform_cover_is_false` on the
// diff altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_full_cover());
assert!(!slice.layer_kinds_strict_partial_cover());
}
#[test]
fn layer_kinds_strict_partial_cover_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_strict_partial_cover() ⇒
// layer_kinds_any_observed()` on every axis with cardinality
// `>= 4`. On the cardinality-`3` `ConfigSourceKind` axis the
// antecedent never fires so the implication holds vacuously;
// the pin still walks every fixture to catch any future
// implementation that would erroneously fire the antecedent.
// Peer of
// `tiers_strict_partial_cover_implies_tiers_any_observed_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_strict_partial_cover() {
assert!(
slice.layer_kinds_any_observed(),
"strict-partial-cover chain must be any-observed",
);
}
}
}
#[test]
fn layer_kinds_strict_partial_cover_implies_not_layer_kinds_singular_support_pointwise() {
// Disjointness pin: `layer_kinds_strict_partial_cover() ⇒
// !layer_kinds_singular_support()` on every axis. A strict-
// interior chain has `>= 2` observed cells; a singleton support
// has exactly `1`. Peer of
// `tiers_strict_partial_cover_implies_not_tiers_singular_support_pointwise`
// on the tier altitude and
// `kinds_strict_partial_cover_implies_not_kinds_singular_support_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_strict_partial_cover() {
assert!(
!slice.layer_kinds_singular_support(),
"strict-partial-cover chain cannot be singular-support",
);
}
}
}
#[test]
fn layer_kinds_strict_partial_cover_implies_not_layer_kinds_singular_gap_pointwise() {
// Disjointness pin: `layer_kinds_strict_partial_cover() ⇒
// !layer_kinds_singular_gap()` on every axis. A strict-interior
// chain has `>= 2` unobserved cells; a singleton gap has
// exactly `1`. Peer of
// `tiers_strict_partial_cover_implies_not_tiers_singular_gap_pointwise`
// on the tier altitude and
// `kinds_strict_partial_cover_implies_not_kinds_singular_gap_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_strict_partial_cover() {
assert!(
!slice.layer_kinds_singular_gap(),
"strict-partial-cover chain cannot be singular-gap",
);
}
}
}
#[test]
fn layer_kinds_strict_partial_cover_implies_not_layer_kinds_full_cover_pointwise() {
// Disjointness pin: `layer_kinds_strict_partial_cover() ⇒
// !layer_kinds_full_cover()` on every axis. A strict-interior
// chain has `>= 2` unobserved cells; a full cover has zero.
// Peer of
// `tiers_strict_partial_cover_implies_not_tiers_full_cover_pointwise`
// on the tier altitude and
// `kinds_strict_partial_cover_implies_not_kinds_full_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_strict_partial_cover() {
assert!(
!slice.layer_kinds_full_cover(),
"strict-partial-cover chain cannot be full-cover",
);
}
}
}
#[test]
fn layer_kinds_any_observed_negation_implies_not_layer_kinds_strict_partial_cover_pointwise() {
// Contrapositive: `!layer_kinds_any_observed() ⇒
// !layer_kinds_strict_partial_cover()` on every axis. If no
// cell was observed, the "at least two observed" half of the
// conjunction fails uniformly — the strict-interior predicate
// fails. Peer of
// `tiers_any_observed_negation_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if !slice.layer_kinds_any_observed() {
assert!(
!slice.layer_kinds_strict_partial_cover(),
"empty-support chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn layer_kinds_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk() {
// Parity against the exact hand-rolled strict-partial-cover
// walk this lift replaces: walk every cell of the histogram
// and count how many carry a zero count and how many carry a
// positive count; the strict-partial-cover predicate reads
// `true` iff at least two cells are zero AND at least two
// cells are positive. On the cardinality-`3` `ConfigSourceKind`
// axis this is unreachable — both sides read `false` on every
// fixture. Peer of
// `tiers_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk`
// on the tier altitude and
// `kinds_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_strict_partial_cover();
let hist = slice.layer_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros >= 2 && nonzeros >= 2;
assert_eq!(via_seam, hand_rolled);
}
}
#[test]
fn layer_kinds_partition_covers_every_chain_pointwise() {
// Trichotomy closure pin at the chain layer-kind sub-axis:
// exactly one of `(!layer_kinds_any_observed,
// layer_kinds_singular_support,
// layer_kinds_strict_partial_cover, layer_kinds_singular_gap,
// layer_kinds_full_cover)` fires per chain on every axis with
// cardinality `>= 3`. With this lift the 5-corner support-
// cardinality partition is jointly exhaustive AND pairwise
// disjoint on every chain fixture. On the cardinality-`3`
// `ConfigSourceKind` axis the strict-interior corner is
// structurally empty, so every chain fires exactly one of the
// other four corners — the pin still enforces the exclusivity
// discipline (no chain fires two corners simultaneously). Peer
// of `tiers_partition_covers_every_map_pointwise` on the tier
// altitude and `kinds_partition_covers_every_diff_pointwise`
// on the diff altitude in the same closed-partition shape.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let empty = !slice.layer_kinds_any_observed();
let sup = slice.layer_kinds_singular_support();
let strict = slice.layer_kinds_strict_partial_cover();
let gap = slice.layer_kinds_singular_gap();
let full = slice.layer_kinds_full_cover();
let fires =
u8::from(empty) + u8::from(sup) + u8::from(strict) + u8::from(gap) + u8::from(full);
assert_eq!(
fires, 1,
"exactly one of (empty, singular_support, strict_partial_cover, \
singular_gap, full_cover) must fire per chain — observed {fires}",
);
}
}
// ---- ConfigSourceChain::layer_kinds_low_support —
// low-support-layer-kinds boolean predicate on the layer-
// kind sub-axis of the chain altitude, lifting the "low-
// support across altitudes" projection sideways from the
// tier altitude (`ProvenanceMap::tiers_low_support`) and
// the diff altitude (`ConfigDiff::kinds_low_support`) into
// the first chain sub-axis. Routed through the shared
// `AxisHistogram::has_low_support` primitive one altitude
// down. Non-vacuous on the cardinality-`3`
// `ConfigSourceKind` axis: the empty chain and every
// singleton-support chain read `true`; every two-or-more-
// cell-cover chain reads `false`. ----
#[test]
fn layer_kinds_low_support_matches_layer_kind_histogram_has_low_support_pointwise() {
// Routing pin: `layer_kinds_low_support` routes through
// `layer_kind_histogram().has_low_support()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive.
// Layer-kind sub-axis peer of
// `tiers_low_support_matches_tier_histogram_has_low_support_pointwise`
// on the tier altitude and
// `kinds_low_support_matches_kind_histogram_has_low_support_pointwise`
// on the diff altitude, in the "low-support across
// altitudes" projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().has_low_support();
assert_eq!(slice.layer_kinds_low_support(), via_histogram);
}
}
#[test]
fn layer_kinds_low_support_matches_defining_union_of_low_boundaries_pointwise() {
// Defining-union-of-low-boundaries disjunction:
// `layer_kinds_low_support() ⇔ !layer_kinds_any_observed()
// || layer_kinds_singular_support()` on every fixture. Pins
// the predicate against the two-way disjunction on the two
// named histogram-side peers consumers reach for when they
// open-code the low-magnitude corner as "empty OR
// singleton-support". Peer of
// `tiers_low_support_matches_defining_union_of_low_boundaries_pointwise`
// on the tier altitude and
// `kinds_low_support_matches_defining_union_of_low_boundaries_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_low_support();
let via_disj =
!slice.layer_kinds_any_observed() || slice.layer_kinds_singular_support();
assert_eq!(
via_seam, via_disj,
"layer_kinds_low_support ({via_seam}) must agree with \
!layer_kinds_any_observed || layer_kinds_singular_support ({via_disj})",
);
}
}
#[test]
fn layer_kinds_low_support_agrees_with_present_layer_kinds_count_at_most_one_pointwise() {
// Support-scalar at-most-one form:
// `layer_kinds_low_support() == (present_layer_kinds_count()
// <= 1)` on every fixture. The support-side surfacing of
// the same boolean, without allocating the
// `Vec<ConfigSourceKind>`. Peer of
// `tiers_low_support_agrees_with_contributing_tiers_count_at_most_one_pointwise`
// on the tier altitude and
// `kinds_low_support_agrees_with_present_kinds_count_at_most_one_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_low_support();
let count = slice.present_layer_kinds_count();
assert_eq!(
via_seam,
count <= 1,
"layer_kinds_low_support ({via_seam}) must agree with \
present_layer_kinds_count() <= 1 (count={count})",
);
}
}
#[test]
fn layer_kinds_low_support_agrees_with_present_layer_kinds_len_at_most_one_pointwise() {
// Support-`Vec` at-most-one form:
// `layer_kinds_low_support() == (present_layer_kinds().len()
// <= 1)` on every fixture. Pins the predicate against the
// support-`Vec` form consumers reach for when they already
// hold the support vector — the allocating open-coding this
// lift replaces. Peer of
// `kinds_low_support_agrees_with_present_kinds_len_at_most_one_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_low_support();
let via_vec = slice.present_layer_kinds().len() <= 1;
assert_eq!(
via_seam, via_vec,
"layer_kinds_low_support ({via_seam}) must agree with \
present_layer_kinds().len() <= 1 ({via_vec})",
);
}
}
#[test]
fn layer_kinds_low_support_agrees_with_absent_layer_kinds_count_at_least_axis_cardinality_minus_one_pointwise()
{
// Coverage-gap-scalar at-least-axis-cardinality-minus-one
// form: `layer_kinds_low_support() ==
// (absent_layer_kinds_count() >=
// axis_cardinality::<ConfigSourceKind>() - 1)` on every
// fixture. The coverage-gap-side surfacing of the same
// boolean via the `present + absent == axis_cardinality`
// invariant. Peer of
// `kinds_low_support_agrees_with_absent_kinds_count_at_least_axis_cardinality_minus_one_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_low_support();
let gap = slice.absent_layer_kinds_count();
let via_gap = gap >= crate::axis_cardinality::<ConfigSourceKind>() - 1;
assert_eq!(
via_seam, via_gap,
"layer_kinds_low_support ({via_seam}) must agree with \
absent_layer_kinds_count() >= axis_cardinality - 1 ({via_gap}, gap={gap})",
);
}
}
#[test]
fn layer_kinds_low_support_empty_chain_is_true() {
// Empty-chain boundary: zero observed cells satisfy the "at
// most one observed" clause vacuously —
// `layer_kinds_low_support` reads `true`. Matches
// `has_low_support` reading `true` on the empty histogram
// one altitude down. Diverges from
// `layer_kinds_any_observed`'s and
// `layer_kinds_full_cover`'s and
// `layer_kinds_singular_support`'s empty-chain `false`
// polarity — the low-support boundary strictly *includes*
// the empty chain by folding the "no observation" case into
// the low-magnitude corner. Peer of
// `tiers_low_support_empty_map_is_true` on the tier
// altitude and `kinds_low_support_empty_diff_is_true` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.layer_kinds_low_support());
assert!(!empty.layer_kinds_any_observed());
assert!(!empty.layer_kinds_singular_support());
assert!(!empty.layer_kinds_singular_gap());
assert!(!empty.layer_kinds_full_cover());
assert!(!empty.layer_kinds_strict_partial_cover());
}
#[test]
fn layer_kinds_low_support_singleton_support_is_true() {
// Singleton-support pin: every layer lands on the same
// kind, so the support cardinality is `1` (at most `1`) —
// `layer_kinds_low_support` reads `true`. Direct witness of
// the subsumption `layer_kinds_singular_support ⇒
// layer_kinds_low_support`: every singleton-support chain
// lands on the low-magnitude corner by the union-of-low-
// boundaries disjunction. Peer of
// `tiers_low_support_singleton_support_is_true` on the tier
// altitude and `kinds_low_support_singleton_support_is_true`
// on the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_support());
assert!(slice.layer_kinds_low_support());
}
#[test]
fn layer_kinds_low_support_two_kind_partial_cover_is_false() {
// Two-kind-cover pin: `sample_chain()` observes {Env, File}
// (support size 2 out of 3) — support cardinality `2`
// violates `<= 1`, so `layer_kinds_low_support` reads
// `false`. Direct witness of the disjointness
// `layer_kinds_singular_gap ⇒ !layer_kinds_low_support` on
// the cardinality-`3` axis where the singleton-gap slice
// sits at support cardinality `axis_cardinality - 1 = 2`.
// Peer of `kinds_low_support_two_kind_partial_cover_is_false`
// on the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(slice.layer_kinds_singular_gap());
assert!(!slice.layer_kinds_low_support());
}
#[test]
fn layer_kinds_low_support_uniform_cover_is_false() {
// Uniform-cover pin: every kind contributes at least one
// layer, so the support cardinality is `3` (violates
// `<= 1`) — `layer_kinds_low_support` reads `false`. Direct
// witness of the disjointness `layer_kinds_full_cover ⇒
// !layer_kinds_low_support` on every cardinality-`>= 2`
// axis. Peer of `tiers_low_support_uniform_cover_is_false`
// on the tier altitude and
// `kinds_low_support_uniform_cover_is_false` on the diff
// altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_full_cover());
assert!(!slice.layer_kinds_low_support());
}
#[test]
fn layer_kinds_low_support_implies_not_layer_kinds_full_cover_pointwise() {
// Disjointness pin: `layer_kinds_low_support() ⇒
// !layer_kinds_full_cover()` on every axis with cardinality
// `>= 2`. Low support has size `<= 1`; full cover has size
// `axis_cardinality >= 2`. Peer of
// `tiers_low_support_implies_not_tiers_full_cover_pointwise`
// on the tier altitude and
// `kinds_low_support_implies_not_kinds_full_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_low_support() {
assert!(
!slice.layer_kinds_full_cover(),
"low-support chain cannot be full-cover",
);
}
}
}
#[test]
fn layer_kinds_low_support_implies_not_layer_kinds_singular_gap_pointwise() {
// Disjointness pin: `layer_kinds_low_support() ⇒
// !layer_kinds_singular_gap()` on every axis with
// cardinality `>= 3` (every implementor today —
// `ConfigSourceKind` carries three cells). Low support has
// size `<= 1`; singular-gap has support size
// `axis_cardinality - 1 >= 2`. Peer of
// `tiers_low_support_implies_not_tiers_singular_gap_pointwise`
// on the tier altitude and
// `kinds_low_support_implies_not_kinds_singular_gap_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_low_support() {
assert!(
!slice.layer_kinds_singular_gap(),
"low-support chain cannot be singular-gap",
);
}
}
}
#[test]
fn layer_kinds_low_support_implies_not_layer_kinds_strict_partial_cover_pointwise() {
// Disjointness pin: `layer_kinds_low_support() ⇒
// !layer_kinds_strict_partial_cover()` always. The strict
// interior requires `>= 2` observed cells; low support has
// `<= 1`. On the cardinality-`3` `ConfigSourceKind` axis
// the consequent holds vacuously (the strict interior is
// unreachable), but the pin still walks every fixture to
// enforce the disjointness discipline. Peer of
// `tiers_low_support_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude and
// `kinds_low_support_implies_not_kinds_strict_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_low_support() {
assert!(
!slice.layer_kinds_strict_partial_cover(),
"low-support chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn layer_kinds_any_observed_negation_implies_layer_kinds_low_support_pointwise() {
// Subsumption pin: `!layer_kinds_any_observed() ⇒
// layer_kinds_low_support()` on every axis. If no cell was
// observed, the "at most one observed" clause holds
// vacuously. Peer of
// `tiers_any_observed_negation_implies_tiers_low_support_pointwise`
// on the tier altitude and
// `kinds_any_observed_negation_implies_kinds_low_support_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if !slice.layer_kinds_any_observed() {
assert!(
slice.layer_kinds_low_support(),
"empty-support chain must be low-support",
);
}
}
}
#[test]
fn layer_kinds_singular_support_implies_layer_kinds_low_support_pointwise() {
// Subsumption pin: `layer_kinds_singular_support() ⇒
// layer_kinds_low_support()` on every axis. A singleton-
// support chain lands on the low-magnitude corner by the
// union-of-low-boundaries disjunction. Peer of
// `tiers_singular_support_implies_tiers_low_support_pointwise`
// on the tier altitude and
// `kinds_singular_support_implies_kinds_low_support_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
slice.layer_kinds_low_support(),
"singular-support chain must be low-support",
);
}
}
}
#[test]
fn layer_kinds_low_support_agrees_with_open_coded_at_most_one_positive_walk() {
// Parity against the exact hand-rolled at-most-one-
// positive walk this lift replaces: walk every cell of the
// histogram and count how many carry a positive count; the
// low-support predicate reads `true` iff at most one cell
// carries a positive count. Peer of
// `tiers_low_support_agrees_with_open_coded_at_most_one_positive_walk`
// on the tier altitude and
// `kinds_low_support_agrees_with_open_coded_at_most_one_positive_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_low_support();
let hist = slice.layer_kind_histogram();
let positives = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = positives <= 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::layer_kinds_high_support —
// high-support-layer-kinds boolean predicate on the layer-
// kind sub-axis of the chain altitude, lifting the "high-
// support across altitudes" projection sideways from the
// tier altitude (`ProvenanceMap::tiers_high_support`) and
// the diff altitude (`ConfigDiff::kinds_high_support`) into
// the first chain sub-axis. Routed through the shared
// `AxisHistogram::has_high_support` primitive one altitude
// down. Non-vacuous on the cardinality-`3`
// `ConfigSourceKind` axis: every two-kind partial cover and
// every uniform three-kind cover read `true`; the empty
// chain and every singleton-support chain read `false`.
// The strict-interior middle leg is vacuously empty on the
// cardinality-`3` axis, so the magnitude-direction ternary
// degenerates to the dual partition — matches the diff
// altitude's degenerate two-way partition and diverges from
// the tier altitude's non-vacuous three-way partition. ----
#[test]
fn layer_kinds_high_support_matches_layer_kind_histogram_has_high_support_pointwise() {
// Routing pin: `layer_kinds_high_support` routes through
// `layer_kind_histogram().has_high_support()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive.
// Layer-kind sub-axis peer of
// `tiers_high_support_matches_tier_histogram_has_high_support_pointwise`
// on the tier altitude and
// `kinds_high_support_matches_kind_histogram_has_high_support_pointwise`
// on the diff altitude, in the "high-support across
// altitudes" projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().has_high_support();
assert_eq!(slice.layer_kinds_high_support(), via_histogram);
}
}
#[test]
fn layer_kinds_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise() {
// Defining strict-singular-gap-or-full-cover form:
// `layer_kinds_high_support() ⇔ layer_kinds_full_cover() ||
// (layer_kinds_singular_gap() &&
// !layer_kinds_singular_support())`. Pins the predicate
// against the three-way disjunction on three named
// histogram-side peers consumers reach for when they open-
// code the high-magnitude corner as a boolean fold over the
// full-cover and strict singleton-gap boundaries. The
// `!layer_kinds_singular_support()` excision is vacuously
// `true` on the cardinality-`3` layer-kind axis when
// `layer_kinds_singular_gap` fires (support size `2 != 1`),
// so the disjunction reduces to `layer_kinds_full_cover ||
// layer_kinds_singular_gap` at this sub-axis — but the raw
// form is pinned here so downstream lifts to cardinality-`2`
// sub-axes inherit the excision verbatim. Peer of
// `tiers_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise`
// on the tier altitude and
// `kinds_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_high_support();
let via_union = slice.layer_kinds_full_cover()
|| (slice.layer_kinds_singular_gap() && !slice.layer_kinds_singular_support());
assert_eq!(
via_seam, via_union,
"layer_kinds_high_support ({via_seam}) must agree with \
layer_kinds_full_cover || (layer_kinds_singular_gap && !layer_kinds_singular_support) ({via_union})",
);
}
}
#[test]
fn layer_kinds_high_support_agrees_with_absent_layer_kinds_count_at_most_one_and_support_at_least_two_pointwise()
{
// Coverage-gap-scalar dual-interval surface:
// `layer_kinds_high_support() == (absent_layer_kinds_count()
// <= 1 && present_layer_kinds_count() >= 2)` on every
// fixture. The coverage-gap-side surfacing of the same
// boolean, without allocating either `Vec<ConfigSourceKind>`.
// On the cardinality-`3` axis the `>= 2` clause is
// redundant with the `<= 1` clause via the partition
// invariant `present_count + absent_count ==
// axis_cardinality == 3` (absent_count <= 1 forces
// present_count >= 2), but the raw dual form lifts verbatim
// to cardinality-`2` sub-axes where the excision is load-
// bearing. Peer of
// `tiers_high_support_agrees_with_absent_tiers_count_at_most_one_and_support_at_least_two_pointwise`
// on the tier altitude and
// `kinds_high_support_agrees_with_absent_kinds_count_at_most_one_and_support_at_least_two_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_high_support();
let gap = slice.absent_layer_kinds_count();
let support = slice.present_layer_kinds_count();
let via_scalar = gap <= 1 && support >= 2;
assert_eq!(
via_seam, via_scalar,
"layer_kinds_high_support ({via_seam}) must agree with \
absent_layer_kinds_count <= 1 && present_layer_kinds_count >= 2 \
(gap={gap}, support={support})",
);
}
}
#[test]
fn layer_kinds_high_support_agrees_with_present_layer_kinds_count_plus_one_at_least_axis_cardinality_pointwise()
{
// Support-scalar dual-interval form:
// `layer_kinds_high_support() == (present_layer_kinds_count()
// + 1 >= axis_cardinality::<ConfigSourceKind>() &&
// present_layer_kinds_count() >= 2)` on every fixture. The
// support-side surfacing of the same boolean — a high-
// magnitude fold observes at least `axis_cardinality - 1`
// cells; the `>= 2` clause excises the cardinality-`2`
// singleton where the dual-singular-collapse fires. Dual of
// the coverage-gap-scalar surface on the complementary side
// of the same partition via the `present + absent ==
// axis_cardinality` invariant. Peer of
// `tiers_high_support_agrees_with_contributing_tiers_count_plus_one_at_least_axis_cardinality_pointwise`
// on the tier altitude and
// `kinds_high_support_agrees_with_present_kinds_count_plus_one_at_least_axis_cardinality_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_high_support();
let support = slice.present_layer_kinds_count();
let via_scalar =
support + 1 >= crate::axis_cardinality::<ConfigSourceKind>() && support >= 2;
assert_eq!(
via_seam, via_scalar,
"layer_kinds_high_support ({via_seam}) must agree with \
present_layer_kinds_count + 1 >= axis_cardinality && \
present_layer_kinds_count >= 2 (support={support})",
);
}
}
#[test]
fn layer_kinds_high_support_agrees_with_present_layer_kinds_len_at_least_axis_cardinality_minus_one_pointwise()
{
// Support-`Vec` dual-length form:
// `layer_kinds_high_support() == (present_layer_kinds().len()
// + 1 >= axis_cardinality::<ConfigSourceKind>() &&
// present_layer_kinds().len() >= 2)` on every fixture. Pins
// the predicate against the `Vec<ConfigSourceKind>` length
// form consumers reach for when they already hold the
// support vector. Allocating peer of the support-scalar
// dual-interval surface one pin over. Peer of
// `tiers_high_support_agrees_with_contributing_tiers_len_at_least_axis_cardinality_minus_one_pointwise`
// on the tier altitude and
// `kinds_high_support_agrees_with_present_kinds_len_at_least_axis_cardinality_minus_one_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_high_support();
let len = slice.present_layer_kinds().len();
let via_vec = len + 1 >= crate::axis_cardinality::<ConfigSourceKind>() && len >= 2;
assert_eq!(
via_seam, via_vec,
"layer_kinds_high_support ({via_seam}) must agree with \
present_layer_kinds().len() dual-interval ({via_vec}, len={len})",
);
}
}
#[test]
fn layer_kinds_high_support_empty_chain_is_false() {
// Empty-chain boundary: the empty chain observes zero
// cells, so every cell is unobserved (three zeros on the
// cardinality-`3` axis) — the "at most one unobserved"
// predicate fails and `layer_kinds_high_support` reads
// `false`. Matches `has_high_support` reading `false` on
// the empty histogram one altitude down for every
// cardinality-`>= 2` axis. Direct witness of the
// disjointness `layer_kinds_low_support ⇒
// !layer_kinds_high_support` on the empty-chain corner —
// the empty chain sits at the *bottom* of the magnitude
// interval, not the top. Orthogonal polarity to
// `layer_kinds_low_support` reading `true` on the empty
// chain — the two magnitude corners partition every non-
// strict-interior fold at the layer-kind sub-axis. Peer of
// `tiers_high_support_empty_map_is_false` on the tier
// altitude and `kinds_high_support_empty_diff_is_false` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_high_support());
assert!(empty.layer_kinds_low_support());
assert!(!empty.layer_kinds_any_observed());
assert!(!empty.layer_kinds_singular_support());
assert!(!empty.layer_kinds_singular_gap());
assert!(!empty.layer_kinds_full_cover());
assert!(!empty.layer_kinds_strict_partial_cover());
}
#[test]
fn layer_kinds_high_support_singleton_support_is_false() {
// Singleton-support pin: every layer lands on the same
// kind, so the support cardinality is `1` (two unobserved
// cells on the cardinality-`3` axis) — the "at most one
// unobserved" predicate fails and `layer_kinds_high_support`
// reads `false`. Direct witness of the disjointness
// `layer_kinds_singular_support ⇒ !layer_kinds_high_support`
// on every cardinality-`>= 2` axis. Peer of
// `tiers_high_support_singleton_support_is_false` on the
// tier altitude and `kinds_high_support_singleton_support_is_false`
// on the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_support());
assert!(!slice.layer_kinds_high_support());
}
#[test]
fn layer_kinds_high_support_two_kind_partial_cover_is_true() {
// Two-kind-cover pin: `sample_chain()` observes {Env, File}
// (support size 2 out of 3) — `layer_kinds_singular_gap`
// fires (one unobserved cell on the cardinality-`3` axis)
// and `layer_kinds_high_support` reads `true`. Direct
// witness of the strict subsumption `layer_kinds_singular_gap
// ⇒ layer_kinds_high_support` on the cardinality-`>= 3`
// axis where the dual-singular-collapse never fires, and of
// the non-vacuous content on the `true` side of the high-
// support boundary at the layer-kind sub-axis.
// Distinguishes the layer-kind sub-axis from the tier
// altitude, where two-tier partial cover falls in the
// strict interior (support size `2` on the cardinality-`4`
// axis) and lands on `tiers_high_support == false` via the
// non-vacuous disjointness. Peer of
// `kinds_high_support_two_kind_partial_cover_is_true` on
// the diff altitude — the singleton-gap fixture on the
// respective cardinality-`3` axis.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(slice.layer_kinds_singular_gap());
assert!(slice.layer_kinds_high_support());
}
#[test]
fn layer_kinds_high_support_uniform_cover_is_true() {
// Uniform-cover pin: every kind contributes at least one
// layer, so the support cardinality is `3` (no unobserved
// cells) — the "at most one unobserved" predicate holds
// and `layer_kinds_high_support` reads `true`. Direct
// witness of the strict subsumption `layer_kinds_full_cover
// ⇒ layer_kinds_high_support` on every axis (the full-
// cover corner always sits inside the high-magnitude
// corner). The uniform three-kind cover partitions the
// seven coverage-support boundaries with
// (`any_observed`=true, `singular_support`=false,
// `singular_gap`=false, `full_cover`=true,
// `strict_partial_cover`=false, `low_support`=false,
// `high_support`=true). Peer of
// `tiers_high_support_uniform_cover_is_true` on the tier
// altitude and `kinds_high_support_uniform_cover_is_true`
// on the diff altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_full_cover());
assert!(slice.layer_kinds_high_support());
}
#[test]
fn layer_kinds_high_support_implies_not_layer_kinds_low_support_pointwise() {
// Disjointness pin: `layer_kinds_high_support() ⇒
// !layer_kinds_low_support()` on every axis with
// cardinality `>= 2`. High support has size `>= 2`; low
// support has size `<= 1`. The two magnitude corners sit
// at opposite ends of the support-cardinality interval on
// every non-degenerate axis. Pins the strict pairwise
// disjointness of the magnitude-direction ternary's two
// magnitude legs at the layer-kind sub-axis. Peer of
// `tiers_high_support_implies_not_tiers_low_support_pointwise`
// on the tier altitude and
// `kinds_high_support_implies_not_kinds_low_support_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_high_support() {
assert!(
!slice.layer_kinds_low_support(),
"high-support chain cannot be low-support on a \
cardinality >= 2 axis",
);
}
}
}
#[test]
fn layer_kinds_high_support_implies_not_layer_kinds_strict_partial_cover_pointwise() {
// Disjointness pin: `layer_kinds_high_support() ⇒
// !layer_kinds_strict_partial_cover()` always. The strict
// interior requires `>= 2` unobserved cells; high support
// has `<= 1`. On the cardinality-`3` `ConfigSourceKind`
// axis the consequent holds vacuously (the strict interior
// is unreachable), but the pin still walks every fixture
// to enforce the disjointness discipline. Vacuous-here
// sister of the *non-vacuous* pin at the tier altitude
// where the two-tier partial-cover fixture separates the
// strict interior from high support. Peer of
// `tiers_high_support_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude and
// `kinds_high_support_implies_not_kinds_strict_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_high_support() {
assert!(
!slice.layer_kinds_strict_partial_cover(),
"high-support chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn layer_kinds_high_support_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_high_support() ⇒
// layer_kinds_any_observed()` on every axis with
// cardinality `>= 2`. High support has size `>= 2 >= 1`,
// so at least one cell was observed. The empty chain sits
// on the disjoint `!layer_kinds_any_observed` boundary at
// the bottom of the magnitude interval — every high-
// support chain is non-empty. Peer of
// `tiers_high_support_implies_tiers_any_observed_pointwise`
// on the tier altitude and
// `kinds_high_support_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_high_support() {
assert!(
slice.layer_kinds_any_observed(),
"high-support chain must observe at least one cell",
);
}
}
}
#[test]
fn layer_kinds_full_cover_implies_layer_kinds_high_support_pointwise() {
// Subsumption pin: `layer_kinds_full_cover() ⇒
// layer_kinds_high_support()` on every axis. The full-
// cover corner always sits inside the high-magnitude
// corner via the `is_full_cover()` disjunct on the bridge.
// Direct witness of the strict subsumption between the
// top coverage-support boundary and the top magnitude
// corner at the layer-kind sub-axis. Peer of
// `tiers_full_cover_implies_tiers_high_support_pointwise`
// on the tier altitude and
// `kinds_full_cover_implies_kinds_high_support_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_full_cover() {
assert!(
slice.layer_kinds_high_support(),
"full-cover chain must be high-support",
);
}
}
}
#[test]
fn layer_kinds_singular_gap_implies_layer_kinds_high_support_pointwise() {
// Subsumption pin: `layer_kinds_singular_gap() ⇒
// layer_kinds_high_support()` on every axis with
// cardinality `>= 3` (every layer-kind implementor today
// — `ConfigSourceKind` carries three cells). A singleton-
// gap fold has support size `axis_cardinality - 1 >= 2`,
// so the "at most one unobserved" *and* "at least two
// observed" clauses both hold. Direct witness of the
// strict subsumption between the strict singleton-gap
// boundary and the top magnitude corner. On cardinality-
// `2` sub-axes (no layer-kind axis today) the two diverge
// via the dual-singular-collapse excision — pinned
// separately by the histogram-side test one altitude
// down. Peer of
// `tiers_singular_gap_implies_tiers_high_support_pointwise`
// on the tier altitude and
// `kinds_singular_gap_implies_kinds_high_support_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_gap() {
assert!(
slice.layer_kinds_high_support(),
"singular-gap chain must be high-support on a \
cardinality >= 3 axis",
);
}
}
}
#[test]
fn layer_kinds_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise()
{
// Ternary partition pin: `(layer_kinds_low_support,
// layer_kinds_strict_partial_cover,
// layer_kinds_high_support)` is a strict partition on every
// axis with cardinality `>= 2` (every layer-kind
// implementor today). Exactly one leg fires on every
// chain — the magnitude-direction ternary of the 5-corner
// support-cardinality partition, folding the two singular-
// cardinality boundaries into the two magnitude corners
// and naming the boundary-free strict interior separately.
// At the layer-kind sub-axis the middle leg is vacuously
// `false` on the cardinality-`3` axis (the strict-interior
// interval `[2, 1]` is empty), so the ternary degenerates
// to the dual partition `(low_support, high_support)` —
// matching the diff altitude's degenerate two-way
// partition on the same cardinality-`3` `DiffLineKind`
// axis and diverging from the tier altitude's non-vacuous
// three-way partition on the cardinality-`4`
// `ConfigTierKind` axis. Peer of
// `tiers_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise`
// on the tier altitude and
// `kinds_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise`
// on the diff altitude, and of the trait-uniform pin
// `axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`
// one altitude down.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let low = slice.layer_kinds_low_support();
let mid = slice.layer_kinds_strict_partial_cover();
let high = slice.layer_kinds_high_support();
let count = usize::from(low) + usize::from(mid) + usize::from(high);
assert_eq!(
count, 1,
"exactly one of (low_support, strict_partial_cover, \
high_support) must fire (low={low}, mid={mid}, \
high={high})",
);
}
}
#[test]
fn layer_kinds_high_support_agrees_with_open_coded_at_most_one_zero_walk() {
// Parity against the exact hand-rolled high-support walk
// this lift replaces on cardinality-`>= 3` axes: walk
// every cell of the histogram and count how many carry a
// zero count; the high-support predicate reads `true` iff
// at most one cell is a zero (and at least two cells are
// nonzero — the dual-singular-collapse excision, vacuously
// satisfied on cardinality-`>= 3` axes when the "at most
// one zero" clause holds). Mirrors the parity pin
// `layer_kinds_low_support_agrees_with_open_coded_at_most_one_positive_walk`
// on the opposite magnitude leg. Peer of
// `tiers_high_support_agrees_with_open_coded_at_most_one_zero_walk`
// on the tier altitude and
// `kinds_high_support_agrees_with_open_coded_at_most_one_zero_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_high_support();
let hist = slice.layer_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros <= 1 && nonzeros >= 2;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::layer_kinds_singular — singular-near-boundary
// boolean predicate on the layer-kind sub-axis of the chain
// altitude, lifting the "singular across altitudes" projection
// sideways from the tier altitude ([`ProvenanceMap::tiers_singular`])
// onto the first chain-altitude sub-axis. On the cardinality-`3`
// `ConfigSourceKind` axis the distance ternary degenerates to
// the dual `(has_boundary, has_singular)` — matches the diff
// altitude and diverges from the tier altitude's non-vacuous
// three-leg ternary. ──
#[test]
fn layer_kinds_singular_matches_layer_kind_histogram_has_singular_pointwise() {
// Routing pin: `layer_kinds_singular` routes through
// `layer_kind_histogram().has_singular()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops
// projecting through the shared cube-native primitive. Layer-
// kind sub-axis peer of
// `tiers_singular_matches_tier_histogram_has_singular_pointwise`
// on the tier altitude and
// `kinds_singular_matches_kind_histogram_has_singular_pointwise`
// on the diff altitude, in the "singular across altitudes"
// projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().has_singular();
assert_eq!(slice.layer_kinds_singular(), via_histogram);
}
}
#[test]
fn layer_kinds_singular_matches_defining_union_of_singular_boundaries_pointwise() {
// Defining union-of-singular-boundaries form:
// `layer_kinds_singular() ⇔ layer_kinds_singular_support() ||
// layer_kinds_singular_gap()`. Pins the predicate against the
// two-way disjunction on two named histogram-side peers
// consumers reach for when they open-code the singular near-
// boundary corner as a boolean fold over the two singular-
// cardinality boundaries. Peer of
// `tiers_singular_matches_defining_union_of_singular_boundaries_pointwise`
// on the tier altitude and
// `kinds_singular_matches_defining_union_of_singular_boundaries_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular();
let via_union =
slice.layer_kinds_singular_support() || slice.layer_kinds_singular_gap();
assert_eq!(
via_seam, via_union,
"layer_kinds_singular ({via_seam}) must agree with \
layer_kinds_singular_support || layer_kinds_singular_gap ({via_union})",
);
}
}
#[test]
fn layer_kinds_singular_agrees_with_any_observed_and_not_full_cover_on_cardinality_three_pointwise()
{
// Partial-cover-minus-strict-interior form reduced on the
// cardinality-`3` layer-kind axis: `layer_kinds_singular() ==
// layer_kinds_any_observed() && !layer_kinds_full_cover()`.
// The strict interior of the layer-kind axis is empty
// (interval `[2, cardinality - 2] = [2, 1]`), so the middle-
// leg fold reduces pointwise to the partial-cover slice of
// the coverage boundary. Matches the diff-altitude peer
// `kinds_singular ⇔ (kinds_any_observed && !kinds_full_cover)`
// on the same cardinality-`3` axis and diverges from the
// tier altitude where the strict-interior leg carries content
// and the equivalence tightens further. Peer of
// `kinds_singular_agrees_with_any_observed_and_not_full_cover_on_cardinality_three_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular();
let via_slice = slice.layer_kinds_any_observed() && !slice.layer_kinds_full_cover();
assert_eq!(
via_seam, via_slice,
"layer_kinds_singular ({via_seam}) must agree with \
layer_kinds_any_observed && !layer_kinds_full_cover ({via_slice})",
);
}
}
#[test]
fn layer_kinds_singular_agrees_with_present_layer_kinds_count_dual_equality_pointwise() {
// Support-scalar dual-equality surface:
// `layer_kinds_singular() == (present_layer_kinds_count() ==
// 1 || present_layer_kinds_count() ==
// axis_cardinality::<ConfigSourceKind>() - 1)` on every
// fixture. The support-side surfacing of the same boolean,
// without allocating either `Vec<ConfigSourceKind>`. On the
// cardinality-`3` layer-kind axis the two equalities are
// disjoint (`1 ≠ 2 = cardinality - 1`) and the disjunction
// reads the true dual. Peer of
// `tiers_singular_agrees_with_contributing_tiers_count_dual_equality_pointwise`
// on the tier altitude and
// `kinds_singular_agrees_with_present_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular();
let support = slice.present_layer_kinds_count();
let via_scalar =
support == 1 || support == crate::axis_cardinality::<ConfigSourceKind>() - 1;
assert_eq!(
via_seam, via_scalar,
"layer_kinds_singular ({via_seam}) must agree with \
present_layer_kinds_count == 1 || present_layer_kinds_count == cardinality - 1 \
({via_scalar}, support={support})",
);
}
}
#[test]
fn layer_kinds_singular_agrees_with_present_and_absent_layer_kinds_count_dual_equality_pointwise()
{
// Dual-scalar equality surface: `layer_kinds_singular() ==
// (present_layer_kinds_count() == 1 ||
// absent_layer_kinds_count() == 1)` on every fixture. The
// `present + absent == axis_cardinality` invariant restated
// on the two named cardinality peers, without allocating
// either `Vec<ConfigSourceKind>`. Peer of the histogram-side
// dual-scalar equality form `hist.distinct_cells() == 1 ||
// hist.unobserved_cells() == 1` pinned one altitude down.
// Peer of
// `tiers_singular_agrees_with_contributing_and_absent_tiers_count_dual_equality_pointwise`
// on the tier altitude and
// `kinds_singular_agrees_with_present_and_absent_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular();
let support = slice.present_layer_kinds_count();
let gap = slice.absent_layer_kinds_count();
let via_scalar = support == 1 || gap == 1;
assert_eq!(
via_seam, via_scalar,
"layer_kinds_singular ({via_seam}) must agree with \
present_layer_kinds_count == 1 || absent_layer_kinds_count == 1 \
({via_scalar}, support={support}, gap={gap})",
);
}
}
#[test]
fn layer_kinds_singular_empty_chain_is_false() {
// Empty-chain boundary: the empty chain observes zero cells,
// so all three cells are unobserved (three zeros on the
// cardinality-`3` axis) — neither `layer_kinds_singular_support`
// (nonzeros `== 1`) nor `layer_kinds_singular_gap` (zeros
// `== 1`) fires. `layer_kinds_singular` reads `false`.
// Matches `has_singular` reading `false` on the empty
// histogram one altitude down for every cardinality-`>= 2`
// axis. The empty chain sits on the disjoint bottom coverage
// boundary of the distance-from-boundary ternary partition,
// carried by `has_boundary` (via `!layer_kinds_any_observed`)
// instead. Peer of `tiers_singular_empty_map_is_false` on
// the tier altitude and `kinds_singular_empty_diff_is_false`
// on the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_singular());
assert!(!empty.layer_kinds_any_observed());
assert!(!empty.layer_kinds_singular_support());
assert!(!empty.layer_kinds_singular_gap());
}
#[test]
fn layer_kinds_singular_singleton_support_is_true() {
// Singleton-support pin: every layer lands on the same kind,
// so the support cardinality is `1` (two unobserved cells on
// the cardinality-`3` axis) — `layer_kinds_singular_support`
// fires and the disjunction holds via that disjunct.
// `layer_kinds_singular` reads `true`. Direct witness of the
// subsumption `layer_kinds_singular_support ⇒
// layer_kinds_singular` on every axis with cardinality `>=
// 2`. Peer of `tiers_singular_singleton_support_is_true` on
// the tier altitude and
// `kinds_singular_singleton_support_is_true` on the diff
// altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_support());
assert!(slice.layer_kinds_singular());
}
#[test]
fn layer_kinds_singular_two_kind_partial_cover_is_true() {
// Two-kind-cover pin: `sample_chain()` observes {Env, File}
// (support size 2 out of 3) — the support cardinality is `2`
// = `axis_cardinality - 1`, exactly the singleton-gap
// boundary on the cardinality-`3` axis — so
// `layer_kinds_singular_gap` fires and the disjunction holds
// via that disjunct. `layer_kinds_singular` reads `true`.
// Direct witness of the subsumption
// `layer_kinds_singular_gap ⇒ layer_kinds_singular` on the
// cardinality-`>= 3` axis via the singleton-gap disjunct of
// the defining union. Distinguishes the layer-kind sub-axis
// from the tier altitude, where two-tier partial cover falls
// in the strict interior (support size `2` on the
// cardinality-`4` axis) and lands on `tiers_singular ==
// false` via the strict-interior disjointness. Peer of
// `kinds_singular_two_kind_partial_cover_is_true` on the diff
// altitude at the same cardinality-`3` singleton-gap fixture.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(slice.layer_kinds_singular_gap());
assert!(slice.layer_kinds_singular());
}
#[test]
fn layer_kinds_singular_uniform_cover_is_false() {
// Uniform-cover pin: every kind contributes at least one
// layer, so the support cardinality is `3` (no unobserved
// cells on the cardinality-`3` axis) — `layer_kinds_singular_gap`
// fails (`zeros == 0 ≠ 1`) and `layer_kinds_singular_support`
// fails (`nonzeros == 3 ≠ 1`). `layer_kinds_singular` reads
// `false`. The full-cover boundary sits at the top of the
// coverage interval, one of the two boundary corners carried
// by `has_boundary` (via `layer_kinds_full_cover`) in the
// distance ternary — disjoint from the singular near-
// boundary corner. Peer of `tiers_singular_uniform_cover_is_false`
// on the tier altitude and
// `kinds_singular_uniform_cover_is_false` on the diff altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_full_cover());
assert!(!slice.layer_kinds_singular());
}
#[test]
fn layer_kinds_singular_support_implies_layer_kinds_singular_pointwise() {
// Subsumption pin: `layer_kinds_singular_support() ⇒
// layer_kinds_singular()` on every axis via the
// `layer_kinds_singular_support` disjunct of the defining
// union. The singleton-support boundary always sits inside
// the singular near-boundary corner. Direct witness of one
// leg of the union bridge. Peer of
// `tiers_singular_support_implies_tiers_singular_pointwise`
// on the tier altitude and
// `kinds_singular_support_implies_kinds_singular_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
slice.layer_kinds_singular(),
"singular-support chain must be singular",
);
}
}
}
#[test]
fn layer_kinds_singular_gap_implies_layer_kinds_singular_pointwise() {
// Subsumption pin: `layer_kinds_singular_gap() ⇒
// layer_kinds_singular()` on every axis via the
// `layer_kinds_singular_gap` disjunct of the defining union.
// The singleton-gap boundary always sits inside the singular
// near-boundary corner. Direct witness of the other leg of
// the union bridge. Peer of
// `tiers_singular_gap_implies_tiers_singular_pointwise` on
// the tier altitude and
// `kinds_singular_gap_implies_kinds_singular_pointwise` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_gap() {
assert!(
slice.layer_kinds_singular(),
"singular-gap chain must be singular",
);
}
}
}
#[test]
fn layer_kinds_singular_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_singular() ⇒
// layer_kinds_any_observed()` on every axis with cardinality
// `>= 2`. Both disjuncts require at least one observed cell
// (`singular_support` has nonzeros `>= 1`; `singular_gap` has
// nonzeros `= cardinality - 1 >= 1`). The empty chain sits
// on the disjoint `!layer_kinds_any_observed` boundary at
// the bottom coverage boundary — every singular chain is
// non-empty. Peer of
// `tiers_singular_implies_tiers_any_observed_pointwise` on
// the tier altitude and
// `kinds_singular_implies_kinds_any_observed_pointwise` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular() {
assert!(
slice.layer_kinds_any_observed(),
"singular chain must observe at least one cell",
);
}
}
}
#[test]
fn layer_kinds_singular_implies_not_layer_kinds_full_cover_pointwise() {
// Disjointness pin: `layer_kinds_singular() ⇒
// !layer_kinds_full_cover()` on every axis with cardinality
// `>= 2`. `layer_kinds_singular_support` has support `1 <
// cardinality`; `layer_kinds_singular_gap` has support
// `cardinality - 1 < cardinality`. The full-cover corner
// sits at the top coverage boundary — one of the two
// boundary corners disjoint from the singular near-boundary
// corner. Peer of
// `tiers_singular_implies_not_tiers_full_cover_pointwise` on
// the tier altitude and
// `kinds_singular_implies_not_kinds_full_cover_pointwise` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular() {
assert!(
!slice.layer_kinds_full_cover(),
"singular chain cannot be full-cover on a \
cardinality >= 2 axis",
);
}
}
}
#[test]
fn layer_kinds_singular_implies_not_layer_kinds_strict_partial_cover_pointwise() {
// Disjointness pin: `layer_kinds_singular() ⇒
// !layer_kinds_strict_partial_cover()` always. The two named
// corners of the distance-from-boundary ternary partition
// are pairwise disjoint. On the cardinality-`3`
// `ConfigSourceKind` axis the consequent holds vacuously
// (the strict interior is unreachable), but the pin still
// walks every fixture to enforce the disjointness
// discipline. Vacuous-here sister of the *non-vacuous* pin
// at the tier altitude where the two-tier partial-cover
// fixture separates the strict interior from the singular
// near-boundary. Peer of
// `tiers_singular_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude and
// `kinds_singular_implies_not_kinds_strict_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular() {
assert!(
!slice.layer_kinds_strict_partial_cover(),
"singular chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn layer_kinds_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise() {
// Ternary partition pin at the chain layer-kind sub-axis:
// exactly one of the three legs
// `(!layer_kinds_any_observed || layer_kinds_full_cover,
// layer_kinds_singular,
// layer_kinds_strict_partial_cover)`
// fires on every chain — the distance-from-boundary ternary
// of the 5-corner support-cardinality partition, folding
// the two boundary corners (empty and full-cover) into
// `has_boundary`, the two singular near-boundary corners
// into `has_singular`, and the boundary-free strict interior
// into `has_strict_partial_cover`. On the cardinality-`3`
// `ConfigSourceKind` axis the `has_strict_partial_cover` leg
// is vacuously empty (interval `[2, 1]` is empty), so the
// ternary degenerates to the dual partition
// `(!layer_kinds_any_observed || layer_kinds_full_cover,
// layer_kinds_singular)` pointwise — matching the diff-
// altitude peer on the same cardinality-`3` `DiffLineKind`
// axis and diverging from the tier altitude's non-vacuous
// three-leg partition on the cardinality-`4` `ConfigTierKind`
// axis. Peer of the trait-uniform pin
// `axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor`
// one altitude down, of
// `tiers_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise`
// on the tier altitude, and of
// `kinds_boundary_and_kinds_singular_and_kinds_strict_partial_cover_form_ternary_partition_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let boundary = !slice.layer_kinds_any_observed() || slice.layer_kinds_full_cover();
let singular = slice.layer_kinds_singular();
let strict = slice.layer_kinds_strict_partial_cover();
let count = usize::from(boundary) + usize::from(singular) + usize::from(strict);
assert_eq!(
count, 1,
"exactly one of (boundary, singular, strict_partial_cover) \
must fire (boundary={boundary}, singular={singular}, \
strict={strict})",
);
}
}
#[test]
fn layer_kinds_singular_bridges_support_cardinality_class_is_singular_pointwise() {
// Cross-surface bridge law: `layer_kinds_singular() ==
// layer_kind_histogram().support_cardinality_class().is_singular()`
// on every fixture. The class-side projection lands on
// `SupportCardinalityClass::SingularSupport` or
// `SupportCardinalityClass::SingularGap` exactly when the
// histogram-side disjunction fires, and
// `SupportCardinalityClass::is_singular` reads `true` on
// either variant. Peer of the histogram-side bridge
// `axis_histogram_has_singular_agrees_with_class_is_singular_for_every_closed_axis_implementor`
// one altitude down, closing the (histogram, class) duality
// on the singular near-boundary leg at the chain layer-kind
// sub-axis. Peer of
// `tiers_singular_bridges_support_cardinality_class_is_singular_pointwise`
// on the tier altitude and
// `kinds_singular_bridges_support_cardinality_class_is_singular_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular();
let via_class = slice
.layer_kind_histogram()
.support_cardinality_class()
.is_singular();
assert_eq!(
via_seam, via_class,
"layer_kinds_singular ({via_seam}) must agree with \
layer_kind_histogram().support_cardinality_class().is_singular() \
({via_class})",
);
}
}
#[test]
fn layer_kinds_singular_agrees_with_open_coded_singular_boundary_walk() {
// Parity against the exact hand-rolled singular walk this
// lift replaces on cardinality-`>= 2` axes: walk every cell
// of the histogram and count how many carry a zero count
// and how many carry a nonzero count; the singular predicate
// reads `true` iff exactly one cell is nonzero (singular
// support) or exactly one cell is a zero (singular gap).
// Mirrors the parity pins
// `layer_kinds_singular_support_agrees_with_open_coded_exactly_one_positive_walk`
// and `layer_kinds_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the two singular-cardinality boundaries the union
// folds. Peer of
// `tiers_singular_agrees_with_open_coded_singular_boundary_walk`
// on the tier altitude and
// `kinds_singular_agrees_with_open_coded_singular_boundary_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_singular();
let hist = slice.layer_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = nonzeros == 1 || zeros == 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ── layer_kinds_boundary coverage — the boundary-layer-kinds
// top-leg corner of the distance-from-boundary ternary partition
// `(has_boundary, has_singular, has_strict_partial_cover)` at
// the chain layer-kind sub-axis, lifting the tier-altitude climb
// `tiers_boundary` sideways to the first chain-altitude sub-
// axis. On the cardinality-`3` `ConfigSourceKind` axis the
// distance ternary's third leg vanishes and reduces to the
// dual `(layer_kinds_boundary, layer_kinds_singular)` — matches
// the diff altitude and diverges from the tier altitude's non-
// vacuous three-leg ternary. ──
#[test]
fn layer_kinds_boundary_matches_layer_kind_histogram_has_boundary_pointwise() {
// Routing pin: `layer_kinds_boundary` routes through
// `layer_kind_histogram().has_boundary()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops
// projecting through the shared cube-native primitive. Layer-
// kind sub-axis peer of
// `tiers_boundary_matches_tier_histogram_has_boundary_pointwise`
// on the tier altitude and
// `kinds_boundary_matches_kind_histogram_has_boundary_pointwise`
// on the diff altitude, in the "boundary across altitudes"
// projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().has_boundary();
assert_eq!(slice.layer_kinds_boundary(), via_histogram);
}
}
#[test]
fn layer_kinds_boundary_matches_defining_union_of_coverage_boundaries_pointwise() {
// Defining union-of-coverage-boundaries form:
// `layer_kinds_boundary() ⇔ !layer_kinds_any_observed() ||
// layer_kinds_full_cover()`. Pins the predicate against the
// two-way disjunction on the two named coverage-boundary peers
// consumers reach for when they open-code the boundary corner
// as a boolean fold over the two extreme coverage
// cardinalities. Peer of
// `tiers_boundary_matches_defining_union_of_coverage_boundaries_pointwise`
// on the tier altitude and
// `kinds_boundary_matches_defining_union_of_coverage_boundaries_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_boundary();
let via_union = !slice.layer_kinds_any_observed() || slice.layer_kinds_full_cover();
assert_eq!(
via_seam, via_union,
"layer_kinds_boundary ({via_seam}) must agree with \
!layer_kinds_any_observed || layer_kinds_full_cover ({via_union})",
);
}
}
#[test]
fn layer_kinds_boundary_agrees_with_present_layer_kinds_count_dual_equality_pointwise() {
// Support-scalar dual-equality surface:
// `layer_kinds_boundary() == (present_layer_kinds_count() == 0
// || present_layer_kinds_count() ==
// axis_cardinality::<ConfigSourceKind>())` on every fixture.
// The support-side surfacing of the same boolean, without
// allocating either `Vec<ConfigSourceKind>`. The two
// equalities are strictly disjoint (`0 != 3 = cardinality` on
// the layer-kind axis). Peer of
// `tiers_boundary_agrees_with_contributing_tiers_count_dual_equality_pointwise`
// on the tier altitude and
// `kinds_boundary_agrees_with_present_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_boundary();
let support = slice.present_layer_kinds_count();
let via_scalar =
support == 0 || support == crate::axis_cardinality::<ConfigSourceKind>();
assert_eq!(
via_seam, via_scalar,
"layer_kinds_boundary ({via_seam}) must agree with \
present_layer_kinds_count == 0 || present_layer_kinds_count == cardinality \
({via_scalar}, support={support})",
);
}
}
#[test]
fn layer_kinds_boundary_agrees_with_present_and_absent_layer_kinds_count_dual_equality_pointwise()
{
// Dual-scalar equality surface: `layer_kinds_boundary() ==
// (present_layer_kinds_count() == 0 ||
// absent_layer_kinds_count() == 0)` on every fixture. The
// `present + absent == axis_cardinality` invariant restated
// on the two named cardinality peers, without allocating
// either `Vec<ConfigSourceKind>`. Peer of the histogram-side
// dual-scalar equality form `hist.distinct_cells() == 0 ||
// hist.unobserved_cells() == 0` pinned one altitude down.
// Peer of
// `tiers_boundary_agrees_with_contributing_and_absent_tiers_count_dual_equality_pointwise`
// on the tier altitude and
// `kinds_boundary_agrees_with_present_and_absent_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_boundary();
let support = slice.present_layer_kinds_count();
let gap = slice.absent_layer_kinds_count();
let via_scalar = support == 0 || gap == 0;
assert_eq!(
via_seam, via_scalar,
"layer_kinds_boundary ({via_seam}) must agree with \
present_layer_kinds_count == 0 || absent_layer_kinds_count == 0 \
({via_scalar}, support={support}, gap={gap})",
);
}
}
#[test]
fn layer_kinds_boundary_empty_chain_is_true() {
// Empty-chain boundary: the empty chain observes zero cells,
// so every cell is unobserved (three zeros on the cardinality-
// `3` axis) — the scan sees no nonzero cell and falls through
// to `true`. `layer_kinds_boundary` reads `true`. Matches
// `has_boundary` reading `true` on the empty histogram one
// altitude down. Direct witness of the subsumption
// `!layer_kinds_any_observed ⇒ layer_kinds_boundary` via the
// empty-chain disjunct. Peer of `tiers_boundary_empty_map_is_true`
// on the tier altitude and `kinds_boundary_empty_diff_is_true`
// on the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.layer_kinds_boundary());
assert!(!empty.layer_kinds_any_observed());
}
#[test]
fn layer_kinds_boundary_singleton_support_is_false() {
// Singleton-support pin: every layer lands on the same kind,
// so the support cardinality is `1` (one nonzero and two
// zeros on the cardinality-`3` axis) — the scan sees a
// nonzero cell *and* a zero cell and returns `false`.
// `layer_kinds_boundary` reads `false`. Direct witness of
// the disjointness `layer_kinds_singular_support ⇒
// !layer_kinds_boundary` via the mixed-parity witness. Peer
// of `tiers_boundary_singleton_support_is_false` on the tier
// altitude and `kinds_boundary_singleton_support_is_false`
// on the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(!slice.layer_kinds_boundary());
assert!(slice.layer_kinds_singular_support());
}
#[test]
fn layer_kinds_boundary_two_kind_partial_cover_is_false() {
// Two-kind-cover pin: `sample_chain()` observes {Env, File}
// — the support cardinality is `2` (two nonzeros and one
// zero on the cardinality-`3` axis), exactly the singleton-
// gap boundary — the scan sees a nonzero and a zero cell
// and returns `false`. `layer_kinds_boundary` reads `false`.
// Direct witness of the disjointness `layer_kinds_singular_gap
// ⇒ !layer_kinds_boundary` via the mixed-parity witness —
// the singleton-gap boundary is a singular near-boundary
// corner, disjoint from the boundary corners of the distance
// ternary. Peer of `tiers_boundary_three_tier_partial_cover_is_false`
// on the tier altitude (analog fixture at the singleton-gap
// boundary on the cardinality-`4` tier axis).
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(!slice.layer_kinds_boundary());
assert!(slice.layer_kinds_singular_gap());
}
#[test]
fn layer_kinds_boundary_uniform_cover_is_true() {
// Uniform-cover pin: every kind contributes at least one
// layer, so the support cardinality is `3` (no unobserved
// cells on the cardinality-`3` axis) — the scan sees only
// nonzero cells and falls through to `true`.
// `layer_kinds_boundary` reads `true`. Direct witness of the
// subsumption `layer_kinds_full_cover ⇒ layer_kinds_boundary`
// via the full-cover disjunct. Peer of
// `tiers_boundary_uniform_cover_is_true` on the tier altitude
// and `kinds_boundary_uniform_cover_is_true` on the diff
// altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_full_cover());
assert!(slice.layer_kinds_boundary());
}
#[test]
fn layer_kinds_not_any_observed_implies_layer_kinds_boundary_pointwise() {
// Subsumption pin: `!layer_kinds_any_observed() ⇒
// layer_kinds_boundary()` always via the bottom-boundary
// disjunct of the defining union. The empty chain always
// sits inside the boundary corner. Peer of
// `tiers_not_any_observed_implies_tiers_boundary_pointwise`
// on the tier altitude and
// `kinds_not_any_observed_implies_kinds_boundary_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if !slice.layer_kinds_any_observed() {
assert!(
slice.layer_kinds_boundary(),
"empty chain must be on boundary",
);
}
}
}
#[test]
fn layer_kinds_full_cover_implies_layer_kinds_boundary_pointwise() {
// Subsumption pin: `layer_kinds_full_cover() ⇒
// layer_kinds_boundary()` always via the top-boundary disjunct
// of the defining union. The full-cover chain always sits
// inside the boundary corner. Peer of
// `tiers_full_cover_implies_tiers_boundary_pointwise` on the
// tier altitude and
// `kinds_full_cover_implies_kinds_boundary_pointwise` on the
// diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_full_cover() {
assert!(
slice.layer_kinds_boundary(),
"full-cover chain must be on boundary",
);
}
}
}
#[test]
fn layer_kinds_boundary_implies_not_layer_kinds_singular_pointwise() {
// Disjointness pin: `layer_kinds_boundary() ⇒
// !layer_kinds_singular()` on every axis with cardinality
// `>= 2`. The two boundary cardinalities (`0` and
// `cardinality`) sit strictly outside the two singular
// cardinalities (`1` and `cardinality - 1`) — the boundary
// corner and the singular near-boundary corner are pairwise
// disjoint legs of the distance ternary. Peer of
// `tiers_boundary_implies_not_tiers_singular_pointwise` on
// the tier altitude and
// `kinds_boundary_implies_not_kinds_singular_pointwise` on
// the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_boundary() {
assert!(
!slice.layer_kinds_singular(),
"boundary chain cannot be singular on a cardinality \
>= 2 axis",
);
}
}
}
#[test]
fn layer_kinds_boundary_implies_not_layer_kinds_strict_partial_cover_pointwise() {
// Disjointness pin: `layer_kinds_boundary() ⇒
// !layer_kinds_strict_partial_cover()` always. The strict-
// interior interval `[2, cardinality - 2]` never contains
// the two boundary cardinalities `0` and `cardinality` —
// the third pairwise-disjointness leg of the distance
// ternary. Vacuously-`true` at the layer-kind sub-axis —
// `layer_kinds_strict_partial_cover` is unreachable on the
// cardinality-`3` `ConfigSourceKind` axis — but the pin
// still walks every fixture to enforce the disjointness
// discipline. Transports verbatim to the tier altitude where
// the two-tier partial-cover fixture makes it non-vacuous.
// Peer of `tiers_boundary_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude and
// `kinds_boundary_implies_not_kinds_strict_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_boundary() {
assert!(
!slice.layer_kinds_strict_partial_cover(),
"boundary chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn layer_kinds_boundary_layer_kinds_singular_layer_kinds_strict_partial_cover_form_ternary_partition_pointwise()
{
// Ternary partition pin at the chain layer-kind sub-axis via
// the named seam: exactly one of the three legs
// `(layer_kinds_boundary, layer_kinds_singular,
// layer_kinds_strict_partial_cover)` fires on every chain —
// the distance-from-boundary ternary of the 5-corner support-
// cardinality partition. On the cardinality-`3`
// `ConfigSourceKind` axis the third leg is vacuously empty
// (interval `[2, 1]` is empty), so the ternary degenerates
// to the dual `(layer_kinds_boundary, layer_kinds_singular)`
// pointwise — matches the diff-altitude peer on the same
// cardinality-`3` `DiffLineKind` axis and diverges from the
// tier altitude's non-vacuous three-leg partition on
// `ConfigTierKind`. The `layer_kinds_boundary` seam now names
// the top leg of the ternary directly at the surface,
// replacing the open-coded `!layer_kinds_any_observed ||
// layer_kinds_full_cover` disjunction used by the sibling
// `layer_kinds_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise`
// pin (still kept alongside as the open-coded parity
// witness). Peer of
// `tiers_boundary_tiers_singular_tiers_strict_partial_cover_form_ternary_partition_pointwise`
// on the tier altitude and
// `kinds_boundary_kinds_singular_kinds_strict_partial_cover_form_ternary_partition_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let boundary = slice.layer_kinds_boundary();
let singular = slice.layer_kinds_singular();
let strict = slice.layer_kinds_strict_partial_cover();
let count = usize::from(boundary) + usize::from(singular) + usize::from(strict);
assert_eq!(
count, 1,
"exactly one of (boundary, singular, strict_partial_cover) \
must fire (boundary={boundary}, singular={singular}, \
strict={strict})",
);
}
}
#[test]
fn layer_kinds_boundary_and_layer_kinds_partial_cover_form_strict_bipartition_pointwise() {
// Strict-bipartition pin at the chain layer-kind sub-axis:
// `layer_kinds_boundary` and its complement
// `layer_kinds_any_observed && !layer_kinds_full_cover` (the
// partial-cover strict interior at the layer-kind sub-axis)
// are pointwise complementary — exactly one fires on every
// chain. The named boundary corner is the exact complement
// of the partial-cover strict interior. Peer of the
// histogram-side bipartition law
// `axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`
// one altitude down,
// `tiers_boundary_and_tiers_partial_cover_form_strict_bipartition_pointwise`
// on the tier altitude, and
// `kinds_boundary_and_kinds_partial_cover_form_strict_bipartition_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let boundary = slice.layer_kinds_boundary();
let partial = slice.layer_kinds_any_observed() && !slice.layer_kinds_full_cover();
let count = usize::from(boundary) + usize::from(partial);
assert_eq!(
count, 1,
"exactly one of (boundary, partial_cover) must fire \
(boundary={boundary}, partial={partial})",
);
}
}
#[test]
fn layer_kinds_boundary_bridges_support_cardinality_class_is_boundary_pointwise() {
// Cross-surface bridge law: `layer_kinds_boundary() ==
// layer_kind_histogram().support_cardinality_class().is_boundary()`
// on every fixture. The class-side projection lands on
// `SupportCardinalityClass::Empty` or
// `SupportCardinalityClass::FullCover` exactly when the
// histogram-side disjunction fires, and
// `SupportCardinalityClass::is_boundary` reads `true` on
// either variant. Peer of the histogram-side bridge
// `axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor`
// one altitude down, closing the (histogram, class) duality
// on the boundary leg at the chain layer-kind sub-axis. Peer
// of `tiers_boundary_bridges_support_cardinality_class_is_boundary_pointwise`
// on the tier altitude and
// `kinds_boundary_bridges_support_cardinality_class_is_boundary_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_boundary();
let via_class = slice
.layer_kind_histogram()
.support_cardinality_class()
.is_boundary();
assert_eq!(
via_seam, via_class,
"layer_kinds_boundary ({via_seam}) must agree with \
layer_kind_histogram().support_cardinality_class().is_boundary() \
({via_class})",
);
}
}
#[test]
fn layer_kinds_boundary_agrees_with_open_coded_uniform_parity_walk() {
// Parity against the exact hand-rolled boundary walk this
// lift replaces on cardinality-`>= 1` axes: walk every cell
// of the histogram and count how many carry a zero count
// and how many carry a nonzero count; the boundary predicate
// reads `true` iff every cell is zero (empty) or every cell
// is nonzero (full cover) — i.e. not both a zero *and* a
// nonzero cell appear. Peer of
// `tiers_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the tier altitude and
// `kinds_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_boundary();
let hist = slice.layer_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros == 0 || nonzeros == 0;
assert_eq!(via_seam, hand_rolled);
}
}
// ── layer_kinds_partial_cover coverage — the partial-cover-layer-
// kinds middle-leg corner of the coverage trichotomy
// `(!layer_kinds_any_observed, layer_kinds_partial_cover,
// layer_kinds_full_cover)` at the chain layer-kind sub-axis,
// lifting the tier-altitude climb `tiers_partial_cover`
// sideways to the first chain-altitude sub-axis. Direct strict-
// complement peer of the top-leg `layer_kinds_boundary` corner
// via the bipartition law `layer_kinds_partial_cover ⇔
// !layer_kinds_boundary` on every axis. On the cardinality-`3`
// `ConfigSourceKind` axis the distance ternary's strict-interior
// leg vanishes so `layer_kinds_partial_cover` collapses to the
// two singular near-boundary corners
// (`layer_kinds_singular_support ∨ layer_kinds_singular_gap`)
// — matches the diff altitude and diverges from the tier
// altitude's non-vacuous three-leg ternary. Middle-leg peer of
// `layer_kinds_boundary` / `tiers_partial_cover` /
// `kinds_partial_cover`. ──
#[test]
fn layer_kinds_partial_cover_matches_layer_kind_histogram_has_partial_cover_pointwise() {
// Routing pin: `layer_kinds_partial_cover` routes through
// `layer_kind_histogram().has_partial_cover()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Layer-
// kind sub-axis peer of
// `tiers_partial_cover_matches_tier_histogram_has_partial_cover_pointwise`
// on the tier altitude and
// `kinds_partial_cover_matches_kind_histogram_has_partial_cover_pointwise`
// on the diff altitude, in the "partial-cover across
// altitudes" projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().has_partial_cover();
assert_eq!(slice.layer_kinds_partial_cover(), via_histogram);
}
}
#[test]
fn layer_kinds_partial_cover_matches_defining_conjunction_of_negations_pointwise() {
// Defining conjunction-of-negations form:
// `layer_kinds_partial_cover() ⇔ layer_kinds_any_observed() &&
// !layer_kinds_full_cover()`. Pins the predicate against the
// two-way conjunction on the two named coverage-boundary
// peers consumers reach for when they open-code the middle-
// leg corner as a boolean fold over the two extreme coverage
// cardinalities. The middle-leg-fold peer of the two boundary
// corners — the exact expression used verbatim by the pre-
// existing bipartition-law pin
// `layer_kinds_boundary_and_layer_kinds_partial_cover_form_strict_bipartition_pointwise`.
// Peer of
// `tiers_partial_cover_matches_defining_conjunction_of_negations_pointwise`
// on the tier altitude and
// `kinds_partial_cover_matches_defining_conjunction_of_negations_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_partial_cover();
let via_conjunction =
slice.layer_kinds_any_observed() && !slice.layer_kinds_full_cover();
assert_eq!(
via_seam, via_conjunction,
"layer_kinds_partial_cover ({via_seam}) must agree with \
layer_kinds_any_observed && !layer_kinds_full_cover ({via_conjunction})",
);
}
}
#[test]
fn layer_kinds_partial_cover_agrees_with_present_layer_kinds_count_strict_interval_pointwise() {
// Support-scalar strict-interval surface:
// `layer_kinds_partial_cover() == (0 < present_layer_kinds_count()
// && present_layer_kinds_count() <
// axis_cardinality::<ConfigSourceKind>())` on every fixture.
// The support-side surfacing of the same boolean, without
// allocating `Vec<ConfigSourceKind>`. On every cardinality-
// `>= 2` axis the interval `(0, cardinality)` is non-empty.
// Peer of
// `tiers_partial_cover_agrees_with_contributing_tiers_count_strict_interval_pointwise`
// on the tier altitude and
// `kinds_partial_cover_agrees_with_present_kinds_count_strict_interval_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_partial_cover();
let support = slice.present_layer_kinds_count();
let via_scalar = 0 < support && support < crate::axis_cardinality::<ConfigSourceKind>();
assert_eq!(
via_seam, via_scalar,
"layer_kinds_partial_cover ({via_seam}) must agree with \
0 < present_layer_kinds_count < cardinality \
({via_scalar}, support={support})",
);
}
}
#[test]
fn layer_kinds_partial_cover_agrees_with_absent_layer_kinds_count_strict_interval_pointwise() {
// Coverage-gap dual-scalar strict-interval surface:
// `layer_kinds_partial_cover() == (0 < absent_layer_kinds_count()
// && absent_layer_kinds_count() <
// axis_cardinality::<ConfigSourceKind>())` on every fixture.
// The `present + absent == axis_cardinality` invariant
// restated on the two named cardinality peers, without
// allocating `Vec<ConfigSourceKind>`. Peer of the histogram-
// side dual-scalar strict-interval form
// `0 < hist.unobserved_cells() && hist.unobserved_cells() <
// axis_cardinality::<A>()` pinned one altitude down. Peer of
// `tiers_partial_cover_agrees_with_absent_tiers_count_strict_interval_pointwise`
// on the tier altitude and
// `kinds_partial_cover_agrees_with_absent_kinds_count_strict_interval_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_partial_cover();
let gap = slice.absent_layer_kinds_count();
let via_scalar = 0 < gap && gap < crate::axis_cardinality::<ConfigSourceKind>();
assert_eq!(
via_seam, via_scalar,
"layer_kinds_partial_cover ({via_seam}) must agree with \
0 < absent_layer_kinds_count < cardinality \
({via_scalar}, gap={gap})",
);
}
}
#[test]
fn layer_kinds_partial_cover_agrees_with_present_and_absent_layer_kinds_count_both_positive_pointwise()
{
// Mixed-side dual-scalar non-emptiness surface:
// `layer_kinds_partial_cover() == (present_layer_kinds_count() > 0
// && absent_layer_kinds_count() > 0)` on every fixture. The
// direct histogram-surface `distinct_cells > 0 &&
// unobserved_cells > 0` pin restated at the chain layer-kind
// sub-axis — the boolean asking "did the chain see at least
// one kind *and* miss at least one kind?" against the two
// named cardinality peers, without allocating either
// `Vec<ConfigSourceKind>`. Peer of the sibling
// `layer_kinds_boundary` dual-scalar equality form
// `present_layer_kinds_count == 0 || absent_layer_kinds_count
// == 0` (its exact strict-complement) one seam over on the
// coverage-trichotomy bipartition. Peer of
// `tiers_partial_cover_agrees_with_contributing_and_absent_tiers_count_both_positive_pointwise`
// on the tier altitude and
// `kinds_partial_cover_agrees_with_present_and_absent_kinds_count_both_positive_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_partial_cover();
let support = slice.present_layer_kinds_count();
let gap = slice.absent_layer_kinds_count();
let via_scalar = support > 0 && gap > 0;
assert_eq!(
via_seam, via_scalar,
"layer_kinds_partial_cover ({via_seam}) must agree with \
present_layer_kinds_count > 0 && absent_layer_kinds_count > 0 \
({via_scalar}, support={support}, gap={gap})",
);
}
}
#[test]
fn layer_kinds_partial_cover_empty_chain_is_false() {
// Empty-chain partial-cover: the empty chain observes zero
// cells, so every cell is unobserved (three zeros on the
// cardinality-`3` axis) — the scan sees no nonzero cell and
// falls through to `false`. `layer_kinds_partial_cover`
// reads `false`. Matches `has_partial_cover` reading `false`
// on the empty histogram one altitude down. Direct witness
// of the disjointness
// `!layer_kinds_any_observed ⇒ !layer_kinds_partial_cover`
// via the empty-chain disjunct of `layer_kinds_boundary`.
// Peer of `tiers_partial_cover_empty_map_is_false` on the
// tier altitude and `kinds_partial_cover_empty_diff_is_false`
// on the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_partial_cover());
assert!(!empty.layer_kinds_any_observed());
assert!(empty.layer_kinds_boundary());
}
#[test]
fn layer_kinds_partial_cover_singleton_support_is_true() {
// Singleton-support pin: every layer lands on the same kind,
// so the support cardinality is `1` (one nonzero and two
// zeros on the cardinality-`3` axis) — the scan sees a
// nonzero cell *and* a zero cell and returns `true`.
// `layer_kinds_partial_cover` reads `true`. Direct witness
// of the subsumption
// `layer_kinds_singular_support ⇒ layer_kinds_partial_cover`
// via the mixed-parity witness. Peer of
// `tiers_partial_cover_singleton_support_is_true` on the
// tier altitude and
// `kinds_partial_cover_singleton_support_is_true` on the
// diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_partial_cover());
assert!(slice.layer_kinds_singular_support());
}
#[test]
fn layer_kinds_partial_cover_two_kind_partial_cover_is_true() {
// Two-kind-cover pin: `sample_chain()` observes {Env, File}
// — the support cardinality is `2` (two nonzeros and one
// zero on the cardinality-`3` axis), exactly the singleton-
// gap boundary — the scan sees a nonzero and a zero cell
// and returns `true`. `layer_kinds_partial_cover` reads
// `true`. Direct witness of the subsumption
// `layer_kinds_singular_gap ⇒ layer_kinds_partial_cover`
// via the mixed-parity witness — the singleton-gap boundary
// is a singular near-boundary corner, inside the partial-
// cover middle leg of the coverage trichotomy. Peer of
// `tiers_partial_cover_three_tier_partial_cover_is_true`
// on the tier altitude in the same shape (the analog
// fixture on the cardinality-`4` tier axis is the three-
// tier cover, which also lands on `singular_gap`).
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(slice.layer_kinds_partial_cover());
assert!(slice.layer_kinds_singular_gap());
}
#[test]
fn layer_kinds_partial_cover_uniform_cover_is_false() {
// Uniform-cover pin: every kind contributes at least one
// layer, so the support cardinality is `3` (no unobserved
// cells on the cardinality-`3` axis) — the scan sees only
// nonzero cells and falls through to `false`.
// `layer_kinds_partial_cover` reads `false`. Direct witness
// of the disjointness
// `layer_kinds_full_cover ⇒ !layer_kinds_partial_cover`
// via the full-cover boundary of `layer_kinds_boundary`.
// Peer of `tiers_partial_cover_uniform_cover_is_false` on
// the tier altitude and
// `kinds_partial_cover_uniform_cover_is_false` on the diff
// altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert!(slice.layer_kinds_full_cover());
assert!(!slice.layer_kinds_partial_cover());
}
#[test]
fn layer_kinds_partial_cover_and_layer_kinds_boundary_form_strict_bipartition_pointwise() {
// Strict-bipartition pin at the chain layer-kind sub-axis
// *with the named seam*: `layer_kinds_partial_cover` and
// `layer_kinds_boundary` are pointwise complementary —
// exactly one fires on every chain. The named partial-cover
// corner is the exact complement of the named boundary
// corner. Peer of the pre-existing pin
// `layer_kinds_boundary_and_layer_kinds_partial_cover_form_strict_bipartition_pointwise`
// (kept alongside as the open-coded parity witness against
// `layer_kinds_any_observed && !layer_kinds_full_cover`),
// and peer of the histogram-side bipartition law
// `axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`
// one altitude down. The `layer_kinds_partial_cover` seam
// now names the middle leg of the coverage trichotomy
// directly at the surface, replacing the open-coded
// conjunction-of-negations expression used by the pre-
// existing pin. Peer of
// `tiers_partial_cover_and_tiers_boundary_form_strict_bipartition_pointwise`
// on the tier altitude and
// `kinds_partial_cover_and_kinds_boundary_form_strict_bipartition_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let partial = slice.layer_kinds_partial_cover();
let boundary = slice.layer_kinds_boundary();
let count = usize::from(partial) + usize::from(boundary);
assert_eq!(
count, 1,
"exactly one of (partial_cover, boundary) must fire \
(partial={partial}, boundary={boundary})",
);
}
}
#[test]
fn layer_kinds_partial_cover_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_partial_cover() ⇒
// layer_kinds_any_observed()` always via the "at least one
// observed" half of the defining conjunction. Every partial-
// cover chain observes at least one cell — the middle-leg
// corner sits on the `true` side of the any-observed
// boundary. Peer of
// `tiers_partial_cover_implies_tiers_any_observed_pointwise`
// on the tier altitude and
// `kinds_partial_cover_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_partial_cover() {
assert!(
slice.layer_kinds_any_observed(),
"partial-cover chain must observe at least one cell",
);
}
}
}
#[test]
fn layer_kinds_partial_cover_implies_not_layer_kinds_full_cover_pointwise() {
// Subsumption pin: `layer_kinds_partial_cover() ⇒
// !layer_kinds_full_cover()` always via the "at least one
// unobserved" half of the defining conjunction. Every
// partial-cover chain misses at least one cell — the middle-
// leg corner sits strictly below the full-cover top
// boundary. Peer of
// `tiers_partial_cover_implies_not_tiers_full_cover_pointwise`
// on the tier altitude and
// `kinds_partial_cover_implies_not_kinds_full_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_partial_cover() {
assert!(
!slice.layer_kinds_full_cover(),
"partial-cover chain cannot be full-cover",
);
}
}
}
#[test]
fn layer_kinds_singular_support_implies_layer_kinds_partial_cover_pointwise() {
// Subsumption pin: `layer_kinds_singular_support() ⇒
// layer_kinds_partial_cover()` always on cardinality-`>= 2`
// axes. Support cardinality `1` is strictly between `0` and
// cardinality — the singular-support boundary sits inside
// the partial-cover middle leg. Direct pin of the histogram-
// side subsumption
// `has_singular_support ⇒ has_partial_cover` one altitude
// down. Peer of
// `tiers_singular_support_implies_tiers_partial_cover_pointwise`
// on the tier altitude and
// `kinds_singular_support_implies_kinds_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
slice.layer_kinds_partial_cover(),
"singular-support chain must be partial-cover",
);
}
}
}
#[test]
fn layer_kinds_singular_gap_implies_layer_kinds_partial_cover_pointwise() {
// Subsumption pin: `layer_kinds_singular_gap() ⇒
// layer_kinds_partial_cover()` always on cardinality-`>= 2`
// axes. Support cardinality `cardinality - 1` is strictly
// between `0` and cardinality — the singular-gap boundary
// sits inside the partial-cover middle leg. Peer of the
// opposite-end subsumption on the support-cardinality
// interval, closing the dual-singular pair
// `(has_singular_support, has_singular_gap) ⇒
// has_partial_cover` at the chain layer-kind sub-axis. Peer
// of `tiers_singular_gap_implies_tiers_partial_cover_pointwise`
// on the tier altitude and
// `kinds_singular_gap_implies_kinds_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_gap() {
assert!(
slice.layer_kinds_partial_cover(),
"singular-gap chain must be partial-cover",
);
}
}
}
#[test]
fn layer_kinds_singular_implies_layer_kinds_partial_cover_pointwise() {
// Subsumption pin: `layer_kinds_singular() ⇒
// layer_kinds_partial_cover()` always on cardinality-`>= 2`
// axes. The union of the two singular-side subsumptions
// lands the middle-leg singular corners inside the partial-
// cover middle leg. Direct fold over the disjunction — the
// singular near-boundary corner of the distance ternary
// sits inside the partial-cover middle leg of the coverage
// trichotomy. Peer of
// `tiers_singular_implies_tiers_partial_cover_pointwise`
// on the tier altitude and
// `kinds_singular_implies_kinds_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular() {
assert!(
slice.layer_kinds_partial_cover(),
"singular chain must be partial-cover",
);
}
}
}
#[test]
fn layer_kinds_strict_partial_cover_implies_layer_kinds_partial_cover_pointwise() {
// Subsumption pin: `layer_kinds_strict_partial_cover() ⇒
// layer_kinds_partial_cover()` always. The strict interior
// sits inside the partial-cover middle leg by definition.
// Direct pin of the histogram-side subsumption
// `has_strict_partial_cover ⇒ has_partial_cover` one
// altitude down. Vacuously-`true` at the layer-kind sub-
// axis — `layer_kinds_strict_partial_cover` is unreachable
// on the cardinality-`3` `ConfigSourceKind` axis — but the
// pin still walks every fixture to enforce the subsumption
// discipline. Transports verbatim to the tier altitude
// where the two-tier partial-cover fixture makes it non-
// vacuous. Peer of
// `tiers_strict_partial_cover_implies_tiers_partial_cover_pointwise`
// on the tier altitude and
// `kinds_strict_partial_cover_implies_kinds_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_strict_partial_cover() {
assert!(
slice.layer_kinds_partial_cover(),
"strict-partial-cover chain must be partial-cover",
);
}
}
}
#[test]
fn layer_kinds_partial_cover_and_layer_kinds_any_observed_negation_and_layer_kinds_full_cover_form_coverage_trichotomy_pointwise()
{
// Coverage-trichotomy partition pin at the chain layer-kind
// sub-axis: exactly one of the three legs
// `(!layer_kinds_any_observed, layer_kinds_partial_cover,
// layer_kinds_full_cover)` fires on every chain — the
// coverage trichotomy of the `(is_empty, has_partial_cover,
// is_full_cover)` histogram-side partition restated at the
// chain layer-kind sub-axis. Peer of the trait-uniform pin
// `axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor`
// one altitude down. The `layer_kinds_partial_cover` seam
// now carries the middle leg of this partition directly at
// the surface, folding the open-coded expression
// `layer_kinds_any_observed && !layer_kinds_full_cover`
// (the surface used verbatim by the pre-existing
// bipartition-law pin
// `layer_kinds_boundary_and_layer_kinds_partial_cover_form_strict_bipartition_pointwise`)
// into one named boolean. Peer of
// `tiers_partial_cover_and_tiers_any_observed_negation_and_tiers_full_cover_form_coverage_trichotomy_pointwise`
// on the tier altitude and
// `kinds_partial_cover_and_kinds_any_observed_negation_and_kinds_full_cover_form_coverage_trichotomy_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let empty = !slice.layer_kinds_any_observed();
let partial = slice.layer_kinds_partial_cover();
let full = slice.layer_kinds_full_cover();
let count = usize::from(empty) + usize::from(partial) + usize::from(full);
assert_eq!(
count, 1,
"exactly one of (!any_observed, partial_cover, full_cover) \
must fire (empty={empty}, partial={partial}, full={full})",
);
}
}
#[test]
fn layer_kinds_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise() {
// Cross-surface bridge law: `layer_kinds_partial_cover() ==
// layer_kind_histogram().support_cardinality_class().is_partial_cover()`
// on every fixture. The class-side projection lands on
// `SupportCardinalityClass::SingularSupport`,
// `SupportCardinalityClass::StrictPartialCover`, or
// `SupportCardinalityClass::SingularGap` exactly when the
// histogram-side conjunction fires, and
// `SupportCardinalityClass::is_partial_cover` reads `true`
// on any of the three variants. Peer of the histogram-side
// bridge
// `axis_histogram_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover_for_every_closed_axis_implementor`
// one altitude down, closing the (histogram, class) duality
// on the partial-cover middle leg at the chain layer-kind
// sub-axis. Peer of
// `tiers_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise`
// on the tier altitude and
// `kinds_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_partial_cover();
let via_class = slice
.layer_kind_histogram()
.support_cardinality_class()
.is_partial_cover();
assert_eq!(
via_seam, via_class,
"layer_kinds_partial_cover ({via_seam}) must agree with \
layer_kind_histogram().support_cardinality_class().is_partial_cover() \
({via_class})",
);
}
}
#[test]
fn layer_kinds_partial_cover_agrees_with_open_coded_mixed_parity_walk() {
// Parity against the exact hand-rolled partial-cover walk
// this lift replaces on cardinality-`>= 2` axes: walk every
// cell of the histogram and count how many carry a zero
// count and how many carry a nonzero count; the partial-
// cover predicate reads `true` iff *both* a zero cell *and*
// a nonzero cell appear. Mirrors the parity pin
// `layer_kinds_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the strict-complement top-leg projection — the two
// parity walks are pointwise complementary on every
// cardinality-`>= 1` axis. Peer of
// `tiers_partial_cover_agrees_with_open_coded_mixed_parity_walk`
// on the tier altitude and
// `kinds_partial_cover_agrees_with_open_coded_mixed_parity_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_partial_cover();
let hist = slice.layer_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros > 0 && nonzeros > 0;
assert_eq!(via_seam, hand_rolled);
}
}
// ── layer_kinds_modally_tied coverage — the modally-tied-layer-
// kinds boolean predicate on the layer-kind sub-axis of the
// chain altitude, lifting the tier-altitude climb
// `tiers_modally_tied` sideways to the first chain-altitude
// sub-axis, seeded on the diff altitude by
// `ConfigDiff::kinds_modally_tied`. Modal-side row on top of
// the closed coverage-support predicate cube (`low_support`,
// `high_support`, `strict_partial_cover`, `singular`,
// `boundary`, `partial_cover`) — the seventh projection to
// appear at the layer-kind sub-axis, matching the cadence set
// by the six sibling projections already closed at every
// altitude / sub-axis. Direct strict-complement peer of the
// histogram-side `is_strictly_modally_unique` primitive on
// every non-empty chain. ──
#[test]
fn layer_kinds_modally_tied_matches_layer_kind_histogram_is_modally_tied_pointwise() {
// Routing pin: `layer_kinds_modally_tied` routes through
// `layer_kind_histogram().is_modally_tied()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops
// projecting through the shared cube-native primitive. Layer-
// kind sub-axis peer of
// `tiers_modally_tied_matches_tier_histogram_is_modally_tied_pointwise`
// on the tier altitude and
// `kinds_modally_tied_matches_kind_histogram_is_modally_tied_pointwise`
// on the diff altitude, in the "modally-tied across
// altitudes" projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().is_modally_tied();
assert_eq!(slice.layer_kinds_modally_tied(), via_histogram);
}
}
#[test]
fn layer_kinds_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise() {
// Defining multiplicity-scalar inequality form:
// `layer_kinds_modally_tied() ⇔
// layer_kind_histogram().peak_multiplicity() >= 2`. Pins the
// predicate against the canonical open-coded expression on
// the `AxisHistogram::peak_multiplicity` scalar peer one
// altitude down — the surface consumers reach for when they
// open-code "two or more cells tied at the peak". Peer of
// `tiers_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise`
// on the tier altitude and
// `kinds_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_modally_tied();
let mult = slice.layer_kind_histogram().peak_multiplicity();
let via_scalar = mult >= 2;
assert_eq!(
via_seam, via_scalar,
"layer_kinds_modally_tied ({via_seam}) must agree with \
peak_multiplicity >= 2 ({via_scalar}, mult={mult})",
);
}
}
#[test]
fn layer_kinds_modally_tied_matches_modality_degree_modal_component_pointwise() {
// Modality-pair projection-inequality form:
// `layer_kinds_modally_tied() ⇔
// layer_kind_histogram().modality_degree().0 >= 2`. Pins the
// predicate against the modal-component reading of the fused
// `(peak_multiplicity, trough_multiplicity)` pair, the second
// documented surface form consumers reach for when they read
// the classifier pair before the comparison. Peer of
// `tiers_modally_tied_matches_modality_degree_modal_component_pointwise`
// on the tier altitude and
// `kinds_modally_tied_matches_modality_degree_modal_component_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_modally_tied();
let (peak_mult, _) = slice.layer_kind_histogram().modality_degree();
let via_pair = peak_mult >= 2;
assert_eq!(
via_seam, via_pair,
"layer_kinds_modally_tied ({via_seam}) must agree with \
modality_degree().0 >= 2 ({via_pair}, peak_mult={peak_mult})",
);
}
}
#[test]
fn layer_kinds_modally_tied_empty_chain_is_false() {
// Empty-chain modal-tie: the empty chain observes zero cells,
// so `peak_multiplicity` reads `0` and the inequality `0 >= 2`
// fails. `layer_kinds_modally_tied` reads `false`. Matches
// `is_modally_tied` reading `false` on the empty histogram one
// altitude down. Direct witness of the subsumption
// `layer_kinds_modally_tied ⇒ layer_kinds_any_observed` via
// the empty-chain disjunct of `!layer_kinds_any_observed`.
// Peer of `tiers_modally_tied_empty_map_is_false` on the tier
// altitude and `kinds_modally_tied_empty_diff_is_false` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_modally_tied());
assert!(!empty.layer_kinds_any_observed());
}
#[test]
fn layer_kinds_modally_tied_singleton_support_is_false() {
// Singleton-support pin: every layer lands on the same kind,
// so the lone observed cell stands alone at its own peak —
// `peak_multiplicity` reads `1` and the inequality `1 >= 2`
// fails. `layer_kinds_modally_tied` reads `false`. Direct
// witness of the subsumption `layer_kinds_singular_support ⇒
// !layer_kinds_modally_tied` via the singleton-support corner.
// Peer of `tiers_modally_tied_singleton_support_is_false` on
// the tier altitude and
// `kinds_modally_tied_singleton_support_is_false` on the diff
// altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_support());
assert!(!slice.layer_kinds_modally_tied());
}
#[test]
fn layer_kinds_modally_tied_two_kind_uniform_cover_is_true() {
// Two-kind uniform-cover pin: a chain of one `Defaults` + one
// `Env` has two observed cells tied at count `1` on the
// cardinality-`3` `ConfigSourceKind` axis — `peak_multiplicity`
// reads `2` and the inequality `2 >= 2` fires.
// `layer_kinds_modally_tied` reads `true`. Witness on the
// modally-tied side of the strict modal partition. Support-`2`
// reachability at the chain layer-kind sub-axis, matching the
// support-`2` reachability at the diff altitude on the same
// cardinality-`3` axis.
let chain = vec![ConfigSource::Defaults, ConfigSource::Env("APP_".to_owned())];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(slice.layer_kinds_modally_tied());
}
#[test]
fn layer_kinds_modally_tied_uniform_three_kind_cover_is_true() {
// Uniform axis-cover pin: a chain observing every cell of
// `ConfigSourceKind` exactly once has three observed cells
// tied at count `1` — `peak_multiplicity` reads `3` and the
// inequality `3 >= 2` fires. `layer_kinds_modally_tied` reads
// `true`. Peer of the histogram-side axis-cover convention
// one altitude down, which reads `true` on every implementor
// with `axis_cardinality::<A>() >= 2` — the cardinality-`3`
// `ConfigSourceKind` axis honours the general condition.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 3);
assert!(slice.layer_kinds_full_cover());
assert!(slice.layer_kinds_balanced());
assert!(slice.layer_kinds_modally_tied());
}
#[test]
fn layer_kinds_modally_tied_strictly_modal_skewed_chain_is_false() {
// Strictly-modal skewed-chain pin: a chain of two `File` +
// one `Env` (the `sample_chain()` fixture) has `File`
// uniquely peaking at count `2` (Env sits at `1`, Defaults
// at `0`) — `peak_multiplicity` reads `1` and the inequality
// `1 >= 2` fails. `layer_kinds_modally_tied` reads `false`.
// Witness on the strictly-modal side of the strict modal
// partition. Peer of
// `tiers_modally_tied_strictly_modal_skewed_map_is_false`
// on the tier altitude and
// `kinds_modally_tied_strictly_modal_skewed_diff_is_false`
// on the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.dominant_layer_kind(), Some(ConfigSourceKind::File));
assert_eq!(slice.peak_layer_kind_count(), 2);
assert!(!slice.layer_kinds_modally_tied());
}
#[test]
fn layer_kinds_modally_tied_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_modally_tied() ⇒
// layer_kinds_any_observed()` always. A tied peak requires
// at least two observed cells, so the empty chain (zero
// observed cells) cannot fire the tie predicate — every
// modally-tied chain observes at least one cell (in fact at
// least two). Direct pin of the histogram-side subsumption
// `is_modally_tied ⇒ !is_empty` one altitude down. Peer of
// `tiers_modally_tied_implies_tiers_any_observed_pointwise`
// on the tier altitude and
// `kinds_modally_tied_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_modally_tied() {
assert!(
slice.layer_kinds_any_observed(),
"modally-tied chain must observe at least one cell",
);
}
}
}
#[test]
fn layer_kinds_modally_tied_implies_not_layer_kinds_singular_support_pointwise() {
// Subsumption pin: `layer_kinds_modally_tied() ⇒
// !layer_kinds_singular_support()` always. A tied peak
// requires at least two observed cells sitting at the same
// maximum count, so the modal level set has cardinality
// `>= 2` — strictly more than the singleton-support corner.
// Direct pin of the histogram-side subsumption
// `has_singular_support ⇒ !is_modally_tied` (contrapositive)
// one altitude down. Peer of
// `tiers_modally_tied_implies_not_tiers_singular_support_pointwise`
// on the tier altitude and
// `kinds_modally_tied_implies_not_kinds_singular_support_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_modally_tied() {
assert!(
!slice.layer_kinds_singular_support(),
"modally-tied chain cannot be singular-support",
);
}
}
}
#[test]
fn layer_kinds_singular_support_implies_not_layer_kinds_modally_tied_pointwise() {
// The forward direction of the singleton-support corner
// subsumption: `layer_kinds_singular_support() ⇒
// !layer_kinds_modally_tied()` always. A single observed
// cell is the only member of the modal level set
// (cardinality `1`), so the tie predicate never fires on
// any singleton-support chain. Every singleton-support
// chain sits uniformly on the strictly-modal-unique side
// of the strict modal partition. Peer of
// `tiers_singular_support_implies_not_tiers_modally_tied_pointwise`
// on the tier altitude and
// `kinds_singular_support_implies_not_kinds_modally_tied_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
!slice.layer_kinds_modally_tied(),
"singular-support chain cannot be modally tied",
);
}
}
}
#[test]
fn layer_kinds_modally_tied_forms_strict_modal_partition_on_non_empty_chains_pointwise() {
// Strict modal partition pin on non-empty chains: on every
// non-empty chain exactly one of the pair
// (layer_kinds_modally_tied, is_strictly_modally_unique)
// fires. On the empty chain both read `false` (the shared
// boundary below both branches of the strict modal
// partition). Direct pin of the histogram-side strict-modal-
// partition law `!is_empty ⇒ is_modally_tied ⇔
// !is_strictly_modally_unique` one altitude down. Peer of
// `tiers_modally_tied_forms_strict_modal_partition_on_non_empty_maps_pointwise`
// on the tier altitude and
// `kinds_modally_tied_forms_strict_modal_partition_on_non_empty_diffs_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let hist = slice.layer_kind_histogram();
let tied = slice.layer_kinds_modally_tied();
let strict = hist.is_strictly_modally_unique();
if slice.layer_kinds_any_observed() {
let count = usize::from(tied) + usize::from(strict);
assert_eq!(
count, 1,
"on a non-empty chain exactly one of \
(modally_tied, strictly_modally_unique) must fire \
(tied={tied}, strict={strict})",
);
} else {
assert!(!tied, "empty chain cannot be modally tied");
assert!(!strict, "empty chain cannot be strictly modally unique");
}
}
}
#[test]
fn layer_kinds_full_cover_and_layer_kinds_balanced_imply_layer_kinds_modally_tied_pointwise() {
// Cardinality-`>= 2` uniform-cover pin: on every full-cover
// balanced chain on the cardinality-`3` `ConfigSourceKind`
// axis, the modal level set equals the full axis — all three
// cells share the peak count — so `layer_kinds_modally_tied`
// fires. Cardinality-`>= 2` witness of the histogram-side
// subsumption `is_uniform_count ∧ !is_empty ⇒ is_modally_tied
// ⇔ !has_singular_support` one altitude down. Peer of
// `tiers_full_cover_and_tiers_balanced_imply_tiers_modally_tied_pointwise`
// on the tier altitude and
// `kinds_full_cover_and_kinds_balanced_imply_kinds_modally_tied_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_full_cover() && slice.layer_kinds_balanced() {
assert!(
slice.layer_kinds_modally_tied(),
"full-cover balanced chain on cardinality-3 axis \
must be modally tied",
);
}
}
}
#[test]
fn layer_kinds_modally_tied_agrees_with_open_coded_peak_multiplicity_walk() {
// Parity against the exact hand-rolled peak-multiplicity
// walk this lift replaces: walk every cell of the histogram
// and count how many carry the maximum observed count; the
// modally-tied predicate reads `true` iff the multiplicity
// is at least `2`. Empty histogram has max `0` and no cells
// above zero, so multiplicity reads `0` and the predicate
// fails. Peer of
// `tiers_modally_tied_agrees_with_open_coded_peak_multiplicity_walk`
// on the tier altitude and
// `kinds_modally_tied_agrees_with_open_coded_peak_multiplicity_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_modally_tied();
let hist = slice.layer_kind_histogram();
let max = hist.iter().map(|(_, c)| c).max().unwrap_or(0);
let hand_rolled = if max == 0 {
false
} else {
hist.iter().filter(|(_, c)| *c == max).count() >= 2
};
assert_eq!(via_seam, hand_rolled);
}
}
// ── layer_kinds_antimodally_tied coverage — the antimodally-tied-
// layer-kinds boolean predicate on the layer-kind sub-axis of
// the chain altitude, lifting the tier-altitude climb
// `tiers_antimodally_tied` sideways to the first chain-altitude
// sub-axis, seeded on the diff altitude by
// `ConfigDiff::kinds_antimodally_tied`. Antimodal-side row on
// the modality classifier pair (is_modally_tied,
// is_antimodally_tied), complementary to the just-closed
// modally-tied row at the same chain layer-kind sub-axis.
// Direct strict-complement peer of the histogram-side
// `is_strictly_antimodally_unique` primitive on every non-
// empty chain. ──
#[test]
fn layer_kinds_antimodally_tied_matches_layer_kind_histogram_is_antimodally_tied_pointwise() {
// Routing pin: `layer_kinds_antimodally_tied` routes through
// `layer_kind_histogram().is_antimodally_tied()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Layer-
// kind sub-axis peer of
// `tiers_antimodally_tied_matches_tier_histogram_is_antimodally_tied_pointwise`
// on the tier altitude and
// `kinds_antimodally_tied_matches_kind_histogram_is_antimodally_tied_pointwise`
// on the diff altitude, in the "antimodally-tied across
// altitudes" projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().is_antimodally_tied();
assert_eq!(slice.layer_kinds_antimodally_tied(), via_histogram);
}
}
#[test]
fn layer_kinds_antimodally_tied_matches_defining_trough_multiplicity_inequality_pointwise() {
// Defining multiplicity-scalar inequality form:
// `layer_kinds_antimodally_tied() ⇔
// layer_kind_histogram().trough_multiplicity() >= 2`. Pins the
// predicate against the canonical open-coded expression on
// the `AxisHistogram::trough_multiplicity` scalar peer one
// altitude down — the surface consumers reach for when they
// open-code "two or more cells tied at the trough". Peer of
// `tiers_antimodally_tied_matches_defining_trough_multiplicity_inequality_pointwise`
// on the tier altitude and
// `kinds_antimodally_tied_matches_defining_trough_multiplicity_inequality_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_antimodally_tied();
let mult = slice.layer_kind_histogram().trough_multiplicity();
let via_scalar = mult >= 2;
assert_eq!(
via_seam, via_scalar,
"layer_kinds_antimodally_tied ({via_seam}) must agree with \
trough_multiplicity >= 2 ({via_scalar}, mult={mult})",
);
}
}
#[test]
fn layer_kinds_antimodally_tied_matches_modality_degree_antimodal_component_pointwise() {
// Modality-pair projection-inequality form:
// `layer_kinds_antimodally_tied() ⇔
// layer_kind_histogram().modality_degree().1 >= 2`. Pins the
// predicate against the antimodal-component reading of the
// fused `(peak_multiplicity, trough_multiplicity)` pair, the
// second documented surface form consumers reach for when
// they read the classifier pair before the comparison. Peer
// of
// `tiers_antimodally_tied_matches_modality_degree_antimodal_component_pointwise`
// on the tier altitude and
// `kinds_antimodally_tied_matches_modality_degree_antimodal_component_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_antimodally_tied();
let (_, trough_mult) = slice.layer_kind_histogram().modality_degree();
let via_pair = trough_mult >= 2;
assert_eq!(
via_seam, via_pair,
"layer_kinds_antimodally_tied ({via_seam}) must agree with \
modality_degree().1 >= 2 ({via_pair}, trough_mult={trough_mult})",
);
}
}
#[test]
fn layer_kinds_antimodally_tied_empty_chain_is_false() {
// Empty-chain antimodal-tie: the empty chain observes zero
// cells, so `trough_multiplicity` reads `0` and the inequality
// `0 >= 2` fails. `layer_kinds_antimodally_tied` reads
// `false`. Matches `is_antimodally_tied` reading `false` on
// the empty histogram one altitude down. Direct witness of
// the subsumption `layer_kinds_antimodally_tied ⇒
// layer_kinds_any_observed` via the empty-chain disjunct of
// `!layer_kinds_any_observed`. Peer of
// `tiers_antimodally_tied_empty_map_is_false` on the tier
// altitude and `kinds_antimodally_tied_empty_diff_is_false`
// on the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_antimodally_tied());
assert!(!empty.layer_kinds_any_observed());
}
#[test]
fn layer_kinds_antimodally_tied_singleton_support_is_false() {
// Singleton-support pin: every layer lands on the same kind,
// so the lone observed cell stands alone at its own trough
// (peak and trough coincide) — `trough_multiplicity` reads
// `1` and the inequality `1 >= 2` fails.
// `layer_kinds_antimodally_tied` reads `false`. Direct witness
// of the subsumption `layer_kinds_singular_support ⇒
// !layer_kinds_antimodally_tied` via the singleton-support
// corner. Peer of
// `tiers_antimodally_tied_singleton_support_is_false` on the
// tier altitude and
// `kinds_antimodally_tied_singleton_support_is_false` on the
// diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_support());
assert!(!slice.layer_kinds_antimodally_tied());
}
#[test]
fn layer_kinds_antimodally_tied_two_kind_uniform_cover_is_true() {
// Two-kind uniform-cover pin: a chain of one `Defaults` + one
// `Env` has two observed cells tied at count `1` on the
// cardinality-`3` `ConfigSourceKind` axis (with one silent
// cell at count `0`) — `trough_multiplicity` reads `2` and
// the inequality `2 >= 2` fires.
// `layer_kinds_antimodally_tied` reads `true`. Witness on the
// antimodally-tied side of the strict antimodal partition at
// the chain layer-kind sub-axis. Support-`2` reachability at
// the chain layer-kind sub-axis, matching the support-`2`
// reachability at the diff altitude on the same cardinality-
// `3` axis.
let chain = vec![ConfigSource::Defaults, ConfigSource::Env("APP_".to_owned())];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(slice.layer_kinds_antimodally_tied());
}
#[test]
fn layer_kinds_antimodally_tied_uniform_three_kind_cover_is_true() {
// Uniform axis-cover pin: a chain observing every cell of
// `ConfigSourceKind` exactly once has three observed cells
// tied at count `1` — `trough_multiplicity` reads `3` and the
// inequality `3 >= 2` fires. `layer_kinds_antimodally_tied`
// reads `true`. Peer of the histogram-side axis-cover
// convention one altitude down, which reads `true` on every
// implementor with `axis_cardinality::<A>() >= 2` — the
// cardinality-`3` `ConfigSourceKind` axis honours the general
// condition.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 3);
assert!(slice.layer_kinds_full_cover());
assert!(slice.layer_kinds_balanced());
assert!(slice.layer_kinds_antimodally_tied());
}
#[test]
fn layer_kinds_antimodally_tied_strictly_antimodal_skewed_chain_is_false() {
// Strictly-antimodal skewed-chain pin: a chain of two `File`
// + one `Env` (the `sample_chain()` fixture) has `Env`
// uniquely holding the trough at count `1` while `File`
// peaks at count `2` (Defaults sits at `0`) —
// `trough_multiplicity` reads `1` and the inequality
// `1 >= 2` fails. `layer_kinds_antimodally_tied` reads
// `false`. Witness on the strictly-antimodal side of the
// strict antimodal partition. Peer of
// `tiers_antimodally_tied_strictly_antimodal_skewed_map_is_false`
// on the tier altitude and
// `kinds_antimodally_tied_strictly_antimodal_skewed_diff_is_false`
// on the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.recessive_layer_kind(), Some(ConfigSourceKind::Env));
assert_eq!(slice.trough_layer_kind_count(), 1);
assert!(!slice.layer_kinds_antimodally_tied());
}
#[test]
fn layer_kinds_antimodally_tied_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_antimodally_tied() ⇒
// layer_kinds_any_observed()` always. A tied trough requires
// at least two observed cells, so the empty chain (zero
// observed cells) cannot fire the tie predicate — every
// antimodally-tied chain observes at least one cell (in fact
// at least two). Direct pin of the histogram-side subsumption
// `is_antimodally_tied ⇒ !is_empty` one altitude down. Peer
// of
// `tiers_antimodally_tied_implies_tiers_any_observed_pointwise`
// on the tier altitude and
// `kinds_antimodally_tied_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_antimodally_tied() {
assert!(
slice.layer_kinds_any_observed(),
"antimodally-tied chain must observe at least one cell",
);
}
}
}
#[test]
fn layer_kinds_antimodally_tied_implies_not_layer_kinds_singular_support_pointwise() {
// Subsumption pin: `layer_kinds_antimodally_tied() ⇒
// !layer_kinds_singular_support()` always. A tied trough
// requires at least two observed cells sitting at the same
// strictly-positive minimum count, so the antimodal level
// set has cardinality `>= 2` — strictly more than the
// singleton-support corner. Direct pin of the histogram-side
// subsumption `has_singular_support ⇒ !is_antimodally_tied`
// (contrapositive) one altitude down. Peer of
// `tiers_antimodally_tied_implies_not_tiers_singular_support_pointwise`
// on the tier altitude and
// `kinds_antimodally_tied_implies_not_kinds_singular_support_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_antimodally_tied() {
assert!(
!slice.layer_kinds_singular_support(),
"antimodally-tied chain cannot be singular-support",
);
}
}
}
#[test]
fn layer_kinds_singular_support_implies_not_layer_kinds_antimodally_tied_pointwise() {
// The forward direction of the singleton-support corner
// subsumption: `layer_kinds_singular_support() ⇒
// !layer_kinds_antimodally_tied()` always. A single observed
// cell is the only member of the antimodal level set
// (cardinality `1`), so the tie predicate never fires on any
// singleton-support chain. Every singleton-support chain sits
// uniformly on the strictly-antimodal-unique side of the
// strict antimodal partition. Peer of
// `tiers_singular_support_implies_not_tiers_antimodally_tied_pointwise`
// on the tier altitude and
// `kinds_singular_support_implies_not_kinds_antimodally_tied_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
!slice.layer_kinds_antimodally_tied(),
"singular-support chain cannot be antimodally tied",
);
}
}
}
#[test]
fn layer_kinds_antimodally_tied_forms_strict_antimodal_partition_on_non_empty_chains_pointwise()
{
// Strict antimodal partition pin on non-empty chains: on
// every non-empty chain exactly one of the pair
// (layer_kinds_antimodally_tied, is_strictly_antimodally_unique)
// fires. On the empty chain both read `false` (the shared
// boundary below both branches of the strict antimodal
// partition). Direct pin of the histogram-side strict-
// antimodal-partition law `!is_empty ⇒ is_antimodally_tied ⇔
// !is_strictly_antimodally_unique` one altitude down. Peer of
// `tiers_antimodally_tied_forms_strict_antimodal_partition_on_non_empty_maps_pointwise`
// on the tier altitude and
// `kinds_antimodally_tied_forms_strict_antimodal_partition_on_non_empty_diffs_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let hist = slice.layer_kind_histogram();
let tied = slice.layer_kinds_antimodally_tied();
let strict = hist.is_strictly_antimodally_unique();
if slice.layer_kinds_any_observed() {
let count = usize::from(tied) + usize::from(strict);
assert_eq!(
count, 1,
"on a non-empty chain exactly one of \
(antimodally_tied, strictly_antimodally_unique) \
must fire (tied={tied}, strict={strict})",
);
} else {
assert!(!tied, "empty chain cannot be antimodally tied");
assert!(!strict, "empty chain cannot be strictly antimodally unique",);
}
}
}
#[test]
fn layer_kinds_full_cover_and_layer_kinds_balanced_imply_layer_kinds_antimodally_tied_pointwise()
{
// Cardinality-`>= 2` uniform-cover pin: on every full-cover
// balanced chain on the cardinality-`3` `ConfigSourceKind`
// axis, the antimodal level set equals the full axis — all
// three cells share the trough count — so
// `layer_kinds_antimodally_tied` fires. Cardinality-`>= 2`
// witness of the histogram-side subsumption `is_uniform_count
// ∧ !is_empty ⇒ is_antimodally_tied ⇔ !has_singular_support`
// one altitude down. Peer of
// `tiers_full_cover_and_tiers_balanced_imply_tiers_antimodally_tied_pointwise`
// on the tier altitude and
// `kinds_full_cover_and_kinds_balanced_imply_kinds_antimodally_tied_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_full_cover() && slice.layer_kinds_balanced() {
assert!(
slice.layer_kinds_antimodally_tied(),
"full-cover balanced chain on cardinality-3 axis \
must be antimodally tied",
);
}
}
}
#[test]
fn layer_kinds_antimodally_tied_collapses_with_layer_kinds_modally_tied_on_uniform_multi_cell_chains_pointwise()
{
// Modal / antimodal collapse pin: on every uniform-count
// multi-cell chain the two tie predicates read the same
// value. Direct pin of the histogram-side collapse law
// `is_uniform_count ∧ !is_empty ⇒ is_antimodally_tied ⇔
// is_modally_tied` one altitude down, at the chain layer-
// kind sub-axis. On the singleton-support uniform corner
// both read `false`; on every multi-cell uniform chain both
// read `true`. Peer of
// `tiers_antimodally_tied_collapses_with_tiers_modally_tied_on_uniform_multi_cell_maps_pointwise`
// on the tier altitude and
// `kinds_antimodally_tied_collapses_with_kinds_modally_tied_on_uniform_multi_cell_diffs_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_balanced() && slice.layer_kinds_any_observed() {
assert_eq!(
slice.layer_kinds_antimodally_tied(),
slice.layer_kinds_modally_tied(),
"on a uniform-count non-empty chain the two tie \
predicates must collapse to the same value",
);
}
}
}
#[test]
fn layer_kinds_antimodally_tied_agrees_with_open_coded_trough_multiplicity_walk() {
// Parity against the exact hand-rolled trough-multiplicity
// walk this lift replaces: walk every cell of the histogram
// and count how many carry the strictly-positive minimum
// observed count; the antimodally-tied predicate reads `true`
// iff the multiplicity is at least `2`. Empty histogram has
// no strictly-positive counts, so multiplicity reads `0` and
// the predicate fails. Peer of
// `tiers_antimodally_tied_agrees_with_open_coded_trough_multiplicity_walk`
// on the tier altitude and
// `kinds_antimodally_tied_agrees_with_open_coded_trough_multiplicity_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_antimodally_tied();
let hist = slice.layer_kind_histogram();
let min = hist
.iter()
.map(|(_, c)| c)
.filter(|c| *c > 0)
.min()
.unwrap_or(0);
let hand_rolled = if min == 0 {
false
} else {
hist.iter().filter(|(_, c)| *c == min).count() >= 2
};
assert_eq!(via_seam, hand_rolled);
}
}
// ── layer_kinds_strictly_modally_unique coverage — the strictly-
// modally-unique-layer-kinds boolean predicate on the layer-kind
// sub-axis of the chain altitude, lifting the tier-altitude climb
// `tiers_strictly_modally_unique` sideways to the first chain-
// altitude sub-axis, seeded on the diff altitude by
// `ConfigDiff::kinds_strictly_modally_unique`. Strict-uniqueness
// row on top of the closed modality-tie boolean pair
// (layer_kinds_modally_tied, layer_kinds_antimodally_tied) at
// the chain layer-kind sub-axis. Direct strict-complement peer
// of `layer_kinds_modally_tied` on every non-empty chain
// (both read `false` on the empty chain — the shared boundary
// below both branches of the strict modal partition). ──
#[test]
fn layer_kinds_strictly_modally_unique_matches_layer_kind_histogram_is_strictly_modally_unique_pointwise()
{
// Routing pin: `layer_kinds_strictly_modally_unique` routes
// through `layer_kind_histogram().is_strictly_modally_unique()`,
// so the two seams must stay pointwise equivalent under every
// fixture. Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive.
// Layer-kind sub-axis peer of
// `tiers_strictly_modally_unique_matches_tier_histogram_is_strictly_modally_unique_pointwise`
// on the tier altitude and
// `kinds_strictly_modally_unique_matches_kind_histogram_is_strictly_modally_unique_pointwise`
// on the diff altitude, in the "strictly-modally-unique across
// altitudes" projection.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.layer_kind_histogram().is_strictly_modally_unique();
assert_eq!(slice.layer_kinds_strictly_modally_unique(), via_histogram);
}
}
#[test]
fn layer_kinds_strictly_modally_unique_matches_defining_peak_multiplicity_equality_pointwise() {
// Defining multiplicity-scalar equality form:
// `layer_kinds_strictly_modally_unique() ⇔
// layer_kind_histogram().peak_multiplicity() == 1`. Pins the
// predicate against the canonical open-coded expression on
// the `AxisHistogram::peak_multiplicity` scalar peer one
// altitude down — the surface consumers reach for when they
// open-code "exactly one cell holds the peak". Peer of
// `tiers_strictly_modally_unique_matches_defining_peak_multiplicity_equality_pointwise`
// on the tier altitude and
// `kinds_strictly_modally_unique_matches_defining_peak_multiplicity_equality_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_strictly_modally_unique();
let mult = slice.layer_kind_histogram().peak_multiplicity();
let via_scalar = mult == 1;
assert_eq!(
via_seam, via_scalar,
"layer_kinds_strictly_modally_unique ({via_seam}) must \
agree with peak_multiplicity == 1 ({via_scalar}, \
mult={mult})",
);
}
}
#[test]
fn layer_kinds_strictly_modally_unique_matches_modality_degree_modal_component_pointwise() {
// Modality-pair projection-equality form:
// `layer_kinds_strictly_modally_unique() ⇔
// layer_kind_histogram().modality_degree().0 == 1`. Pins the
// predicate against the modal-component reading of the fused
// `(peak_multiplicity, trough_multiplicity)` pair, the second
// documented surface form consumers reach for when they read
// the classifier pair before the equality. Peer of
// `tiers_strictly_modally_unique_matches_modality_degree_modal_component_pointwise`
// on the tier altitude and
// `kinds_strictly_modally_unique_matches_modality_degree_modal_component_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_strictly_modally_unique();
let (peak_mult, _) = slice.layer_kind_histogram().modality_degree();
let via_pair = peak_mult == 1;
assert_eq!(
via_seam, via_pair,
"layer_kinds_strictly_modally_unique ({via_seam}) must \
agree with modality_degree().0 == 1 ({via_pair}, \
peak_mult={peak_mult})",
);
}
}
#[test]
fn layer_kinds_strictly_modally_unique_empty_chain_is_false() {
// Empty-chain strict-modal-uniqueness: the empty chain
// observes zero cells, so `peak_multiplicity` reads `0` and
// the equality `0 == 1` fails.
// `layer_kinds_strictly_modally_unique` reads `false`. Matches
// `is_strictly_modally_unique` reading `false` on the empty
// histogram one altitude down. The empty-chain row on the
// strict modal partition pair
// `(is_strictly_modally_unique, is_modally_tied)` reads
// `(false, false)` — the shared boundary below both branches.
// Peer of `tiers_strictly_modally_unique_empty_map_is_false`
// on the tier altitude and
// `kinds_strictly_modally_unique_empty_diff_is_false` on the
// diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.layer_kinds_strictly_modally_unique());
assert!(!empty.layer_kinds_any_observed());
}
#[test]
fn layer_kinds_strictly_modally_unique_singleton_support_is_true() {
// Singleton-support pin: every layer lands on the same kind,
// so the lone observed cell stands alone at its own peak (no
// tie-break to exercise) — `peak_multiplicity` reads `1` and
// the equality `1 == 1` fires.
// `layer_kinds_strictly_modally_unique` reads `true`. Direct
// witness of the subsumption `layer_kinds_singular_support ⇒
// layer_kinds_strictly_modally_unique` via the singleton-
// support corner. Peer of
// `tiers_strictly_modally_unique_singleton_support_is_true`
// on the tier altitude and
// `kinds_strictly_modally_unique_singleton_support_is_true`
// on the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 1);
assert!(slice.layer_kinds_singular_support());
assert!(slice.layer_kinds_strictly_modally_unique());
}
#[test]
fn layer_kinds_strictly_modally_unique_two_kind_uniform_cover_is_false() {
// Two-kind uniform-cover pin: a chain of one `Defaults` + one
// `Env` has two observed cells tied at count `1` on the
// cardinality-`3` `ConfigSourceKind` axis — `peak_multiplicity`
// reads `2` and the equality `2 == 1` fails.
// `layer_kinds_strictly_modally_unique` reads `false`. Witness
// on the modally-tied side of the strict modal partition at
// the chain layer-kind sub-axis. Support-`2` reachability at
// the chain layer-kind sub-axis, matching the support-`2`
// reachability at the diff altitude on the same cardinality-
// `3` axis.
let chain = vec![ConfigSource::Defaults, ConfigSource::Env("APP_".to_owned())];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 2);
assert!(!slice.layer_kinds_strictly_modally_unique());
}
#[test]
fn layer_kinds_strictly_modally_unique_uniform_three_kind_cover_is_false() {
// Uniform axis-cover pin: a chain observing every cell of
// `ConfigSourceKind` exactly once has three observed cells
// tied at count `1` — `peak_multiplicity` reads `3` and the
// equality `3 == 1` fails.
// `layer_kinds_strictly_modally_unique` reads `false`. Peer
// of the histogram-side axis-cover convention one altitude
// down, which reads `false` on every implementor with
// `axis_cardinality::<A>() >= 2` — the cardinality-`3`
// `ConfigSourceKind` axis honours the general condition.
// Peer of
// `tiers_strictly_modally_unique_uniform_four_tier_cover_is_false`
// on the tier altitude and
// `kinds_strictly_modally_unique_uniform_three_kind_cover_is_false`
// on the diff altitude.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_layer_kinds().len(), 3);
assert!(slice.layer_kinds_full_cover());
assert!(slice.layer_kinds_balanced());
assert!(!slice.layer_kinds_strictly_modally_unique());
}
#[test]
fn layer_kinds_strictly_modally_unique_strictly_modal_skewed_chain_is_true() {
// Strictly-modal skewed-chain pin: a chain of two `File` +
// one `Env` (the `sample_chain()` fixture) has `File`
// uniquely peaking at count `2` (Env sits at `1`, Defaults at
// `0`) — `peak_multiplicity` reads `1` and the equality
// `1 == 1` fires. `layer_kinds_strictly_modally_unique` reads
// `true`. Witness on the strictly-modally-unique side of the
// strict modal partition. Peer of
// `tiers_strictly_modally_unique_strictly_modal_skewed_map_is_true`
// on the tier altitude and
// `kinds_strictly_modally_unique_strictly_modal_skewed_diff_is_true`
// on the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.dominant_layer_kind(), Some(ConfigSourceKind::File));
assert_eq!(slice.peak_layer_kind_count(), 2);
assert!(slice.layer_kinds_strictly_modally_unique());
}
#[test]
fn layer_kinds_strictly_modally_unique_implies_layer_kinds_any_observed_pointwise() {
// Subsumption pin: `layer_kinds_strictly_modally_unique() ⇒
// layer_kinds_any_observed()` always. A strictly-unique peak
// requires at least one observed cell as the sole member of
// the modal level set, so the empty chain (zero observed
// cells) cannot fire the uniqueness predicate. Direct pin of
// the histogram-side subsumption `is_strictly_modally_unique
// ⇒ !is_empty` one altitude down. Peer of
// `tiers_strictly_modally_unique_implies_tiers_any_observed_pointwise`
// on the tier altitude and
// `kinds_strictly_modally_unique_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_strictly_modally_unique() {
assert!(
slice.layer_kinds_any_observed(),
"strictly-modally-unique chain must observe at \
least one cell",
);
}
}
}
#[test]
fn layer_kinds_singular_support_implies_layer_kinds_strictly_modally_unique_pointwise() {
// Subsumption pin: `layer_kinds_singular_support() ⇒
// layer_kinds_strictly_modally_unique()` always. A single
// observed cell is the only member of the modal level set
// (cardinality `1`), so the uniqueness predicate fires on
// every singleton-support chain. Every singleton-support
// chain sits uniformly on the strictly-modally-unique side
// of the strict modal partition. Direct pin of the histogram-
// side subsumption `has_singular_support ⇒
// is_strictly_modally_unique` one altitude down. Peer of
// `tiers_singular_support_implies_tiers_strictly_modally_unique_pointwise`
// on the tier altitude and
// `kinds_singular_support_implies_kinds_strictly_modally_unique_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_singular_support() {
assert!(
slice.layer_kinds_strictly_modally_unique(),
"singular-support chain must be strictly modally \
unique",
);
}
}
}
#[test]
fn layer_kinds_strictly_modally_unique_forms_strict_modal_partition_on_non_empty_chains_pointwise()
{
// Strict modal partition pin on non-empty chains: on every
// non-empty chain exactly one of the pair
// (layer_kinds_strictly_modally_unique, layer_kinds_modally_tied)
// fires. On the empty chain both read `false` (the shared
// boundary below both branches of the strict modal
// partition). Direct pin of the histogram-side strict-modal-
// partition law `!is_empty ⇒ is_strictly_modally_unique ⇔
// !is_modally_tied` one altitude down, phrased as an XOR on
// the two named seams at the chain layer-kind sub-axis
// surface — the seam-level dual of the matching pin
// `layer_kinds_modally_tied_forms_strict_modal_partition_on_non_empty_chains_pointwise`
// that reads the strict side off the histogram primitive.
// Peer of
// `tiers_strictly_modally_unique_forms_strict_modal_partition_on_non_empty_maps_pointwise`
// on the tier altitude and
// `kinds_strictly_modally_unique_forms_strict_modal_partition_on_non_empty_diffs_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let strict = slice.layer_kinds_strictly_modally_unique();
let tied = slice.layer_kinds_modally_tied();
if slice.layer_kinds_any_observed() {
let count = usize::from(strict) + usize::from(tied);
assert_eq!(
count, 1,
"on a non-empty chain exactly one of \
(strictly_modally_unique, modally_tied) must fire \
(strict={strict}, tied={tied})",
);
} else {
assert!(!strict, "empty chain cannot be strictly modally unique",);
assert!(!tied, "empty chain cannot be modally tied");
}
}
}
#[test]
fn layer_kinds_full_cover_and_layer_kinds_balanced_imply_not_layer_kinds_strictly_modally_unique_pointwise()
{
// Cardinality-`>= 2` uniform-cover pin: on every full-cover
// balanced chain on the cardinality-`3` `ConfigSourceKind`
// axis, the modal level set equals the full axis — all three
// cells share the peak count — so
// `layer_kinds_strictly_modally_unique` fails. Cardinality-
// `>= 2` witness of the histogram-side subsumption
// `is_uniform_count ∧ !is_empty ⇒ is_strictly_modally_unique
// ⇔ has_singular_support` one altitude down: on a uniform-
// cover with cardinality `>= 2`, singleton-support fails so
// strict-modal-uniqueness fails. Peer of
// `tiers_full_cover_and_tiers_balanced_imply_not_tiers_strictly_modally_unique_pointwise`
// on the tier altitude and
// `kinds_full_cover_and_kinds_balanced_imply_not_kinds_strictly_modally_unique_pointwise`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
if slice.layer_kinds_full_cover() && slice.layer_kinds_balanced() {
assert!(
!slice.layer_kinds_strictly_modally_unique(),
"full-cover balanced chain on cardinality-3 axis \
cannot be strictly modally unique",
);
}
}
}
#[test]
fn layer_kinds_strictly_modally_unique_agrees_with_open_coded_peak_multiplicity_walk() {
// Parity against the exact hand-rolled peak-multiplicity walk
// this lift replaces: walk every cell of the histogram and
// count how many carry the maximum observed count; the
// strictly-modally-unique predicate reads `true` iff the
// multiplicity is exactly `1`. Empty histogram has max `0`
// and no cells above zero, so multiplicity reads `0` and the
// predicate fails. Peer of
// `tiers_strictly_modally_unique_agrees_with_open_coded_peak_multiplicity_walk`
// on the tier altitude and
// `kinds_strictly_modally_unique_agrees_with_open_coded_peak_multiplicity_walk`
// on the diff altitude.
for chain in recessive_layer_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.layer_kinds_strictly_modally_unique();
let hist = slice.layer_kind_histogram();
let max = hist.iter().map(|(_, c)| c).max().unwrap_or(0);
let hand_rolled = if max == 0 {
false
} else {
hist.iter().filter(|(_, c)| *c == max).count() == 1
};
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::file_format_spread — scalar-dispersion peer
// on the file-format sub-axis of the chain altitude, fusing
// peak_file_format_count and trough_file_format_count into one
// dispersion scalar and lifting the "spread across altitudes"
// projection sideways to the second chain-altitude sub-axis ----
#[test]
fn file_format_spread_matches_file_format_histogram_spread_pointwise() {
// The scalar-dispersion pin: `file_format_spread` routes through
// `file_format_histogram().spread()`, so the two seams must stay
// pointwise equivalent under every fixture. Direct sister of
// `layer_kind_spread_matches_layer_kind_histogram_spread_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tier_spread_matches_tier_histogram_spread_pointwise` on the
// tier altitude, and
// `kind_spread_matches_kind_histogram_spread_pointwise` on the
// diff altitude.
for chain in recessive_file_format_fixtures() {
let via_histogram = chain.as_slice().file_format_histogram().spread();
assert_eq!(chain.as_slice().file_format_spread(), via_histogram);
}
}
#[test]
fn file_format_spread_equals_peak_minus_trough_pointwise() {
// The fused-pair pin: `file_format_spread == peak_file_format_count
// - trough_file_format_count` on every fixture. The subtraction is
// underflow-safe because `peak_file_format_count() >=
// trough_file_format_count()` holds structurally on every chain
// (lifted from the trait-uniform `peak_count >= trough_count` law
// on AxisHistogram); this pin asserts the monotonicity invariant
// explicitly at every fixture so any future refactor that swaps
// the operands fails visibly. Peer of
// `layer_kind_spread_equals_peak_minus_trough_pointwise` on the
// layer-kind sub-axis of the same chain altitude,
// `tier_spread_equals_peak_minus_trough_pointwise` on the tier
// altitude, and `kind_spread_equals_peak_minus_trough_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let peak = slice.peak_file_format_count();
let trough = slice.trough_file_format_count();
assert!(
peak >= trough,
"peak={peak} must be >= trough={trough} on every chain",
);
assert_eq!(slice.file_format_spread(), peak - trough);
}
}
#[test]
fn file_format_spread_sample_chain_is_zero() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one Env layer. Yaml is the sole observed format (present ==
// {Yaml}), so peak == trough == 2 and the spread is 0 — the
// singleton-support balanced-boundary through the seam. Reads
// the paired `(peak_file_format_count, trough_file_format_count,
// file_format_spread)` dispersion triple as `(2, 2, 0)`. Cross-
// sub-axis divergence pin against
// `layer_kind_spread_sample_chain_is_one`: on the same
// `sample_chain()` fixture, the layer-kind sub-axis reads spread
// 1 (File dominant, Env recessive) while the file-format sub-
// axis reads spread 0 (only Yaml observed).
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.peak_file_format_count(), 2);
assert_eq!(slice.trough_file_format_count(), 2);
assert_eq!(slice.file_format_spread(), 0);
}
#[test]
fn file_format_spread_toml_majority_is_two() {
// Direct pin against a toml-majority chain: three `.toml` file
// layers + one `.yaml` + one Env + one Defaults. Toml dominant
// at 3, Yaml recessive at 1 — the spread is 2. Reads the paired
// `(peak_file_format_count, trough_file_format_count,
// file_format_spread)` dispersion triple as `(3, 1, 2)`. Cross-
// verified against `hist.spread() == 2` at the same observation
// site — the fused-pair spread projection reads through the
// seam.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.peak_file_format_count(), 3);
assert_eq!(slice.trough_file_format_count(), 1);
assert_eq!(slice.file_format_spread(), 2);
assert_eq!(slice.file_format_histogram().spread(), 2);
}
#[test]
fn file_format_spread_empty_chain_is_zero() {
// An empty chain has no file layers and therefore zero spread —
// reads `0` per the AxisHistogram::spread empty convention one
// altitude down; the `(peak_file_format_count,
// trough_file_format_count, file_format_spread)` triple reads
// `(0, 0, 0)` uniformly on empty. Peer of
// `layer_kind_spread_empty_chain_is_zero` on the layer-kind
// sub-axis, `tier_spread_empty_map_is_zero` on the tier
// altitude, and `kind_spread_empty_diff_is_zero` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.peak_file_format_count(), 0);
assert_eq!(empty.trough_file_format_count(), 0);
assert_eq!(empty.file_format_spread(), 0);
}
#[test]
fn file_format_spread_no_recognized_files_is_zero() {
// The non-empty-chain / empty-histogram boundary the file-format
// sub-axis pins that the layer-kind sub-axis does *not*. A chain
// of only `Defaults` / `Env` / unrecognized-extension `File`
// layers is non-empty but has no `Some` file_format projection,
// so the histogram is empty and `file_format_spread` reads zero
// — the vacuous-uniformity boundary reads through the seam.
// Distinguishing pin against the layer-kind sub-axis
// `layer_kind_spread` idiom: on those same chains,
// `layer_kind_spread` reads a nonzero dispersion (Defaults / Env
// / File layers still contribute to the layer-kind histogram)
// while `file_format_spread` reads zero. Cross-sub-axis
// divergence at the empty-boundary.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert_eq!(chain.as_slice().file_format_spread(), 0);
}
}
#[test]
fn file_format_spread_singleton_support_is_zero() {
// Singleton-support pin: every recognized-extension file layer
// lands on the same format, so the dominant format is both peak
// and trough of the support, and the spread is zero — the
// balanced-file-formats boundary on the singleton-support side.
// Direct construction: three `.toml` file layers, present ==
// {Toml}. Peer of
// `layer_kind_spread_singleton_support_is_zero` on the layer-
// kind sub-axis and `tier_spread_singleton_support_is_zero` on
// the tier altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert_eq!(slice.file_format_spread(), 0);
}
#[test]
fn file_format_spread_uniform_cover_is_zero() {
// Uniform-cover pin: every observed format contributes the same
// nonzero count (one file layer per format here — a full-cover
// chain with uniform count 1 per cell), so peak == trough == 1
// and the spread is zero — the balanced-file-formats boundary
// on the uniform-cover side. Peer of
// `layer_kind_spread_uniform_cover_is_zero` on the layer-kind
// sub-axis and `tier_spread_uniform_cover_is_zero` on the tier
// altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_format_histogram().is_full_cover());
assert_eq!(slice.peak_file_format_count(), 1);
assert_eq!(slice.trough_file_format_count(), 1);
assert_eq!(slice.file_format_spread(), 0);
}
#[test]
fn file_format_spread_is_zero_iff_peak_equals_trough() {
// Structural-skew boundary: `file_format_spread() == 0` iff
// `peak_file_format_count() == trough_file_format_count()` —
// the scalar-pair form of the balanced-file-formats predicate.
// On every fixture, the predicate agrees with the equality of
// the fused modal-count pair. Peer of
// `layer_kind_spread_is_zero_iff_peak_equals_trough` on the
// layer-kind sub-axis and
// `tier_spread_is_zero_iff_peak_equals_trough` on the tier
// altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let spread_zero = slice.file_format_spread() == 0;
let peak_eq_trough = slice.peak_file_format_count() == slice.trough_file_format_count();
assert_eq!(
spread_zero,
peak_eq_trough,
"file_format_spread() == 0 iff peak == trough \
(spread={s}, peak={p}, trough={t})",
s = slice.file_format_spread(),
p = slice.peak_file_format_count(),
t = slice.trough_file_format_count(),
);
}
}
#[test]
fn file_format_spread_agrees_with_modal_pair_equality_on_nonempty_histogram() {
// Cross-surface pin: on every chain with a non-empty file-
// format histogram, `file_format_spread() == 0` agrees with
// `dominant_file_format() == recessive_file_format()` — the
// modal-pair equality form of the balanced-file-formats
// predicate. Both branches reduce to `Some(first) ==
// Some(first)` on singleton-support and uniform-cover chains,
// and to `false` on skewed chains. Cross-sub-axis divergence
// from `layer_kind_spread_agrees_with_modal_pair_equality_on_nonempty_chain`:
// the layer-kind sub-axis quantifies over non-empty chains, but
// the file-format sub-axis must quantify over chains with a
// non-empty histogram — a non-empty chain with only Defaults /
// Env / unrecognized-extension File entries has both
// `dominant_file_format() == None == recessive_file_format()`
// (trivial-equal side) and `file_format_spread() == 0` (empty-
// histogram side), so the non-empty-chain quantifier would
// include the empty-histogram case as a trivial-equal
// agreement; the non-empty-histogram quantifier excludes it as
// a distinct boundary.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_format_histogram().is_empty() {
continue;
}
let spread_zero = slice.file_format_spread() == 0;
let dom_eq_rec = slice.dominant_file_format() == slice.recessive_file_format();
assert_eq!(
spread_zero, dom_eq_rec,
"on non-empty-histogram chain, file_format_spread() == 0 iff \
dominant_file_format() == recessive_file_format()",
);
}
}
#[test]
fn file_format_spread_bounded_above_by_peak_file_format_count() {
// Structural bound: `file_format_spread() <=
// peak_file_format_count()` on every fixture — the trough is
// non-negative, so the subtraction is bounded above by the
// minuend. Lifted from the trait-uniform `spread() <=
// peak_count()` law on AxisHistogram. Peer of
// `layer_kind_spread_bounded_above_by_peak_layer_kind_count`
// on the layer-kind sub-axis,
// `tier_spread_bounded_above_by_peak_tier_count` on the tier
// altitude, and `kind_spread_bounded_above_by_peak_kind_count`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
assert!(
slice.file_format_spread() <= slice.peak_file_format_count(),
"file_format_spread()={s} must be <= peak_file_format_count()={p}",
s = slice.file_format_spread(),
p = slice.peak_file_format_count(),
);
}
}
#[test]
fn file_format_spread_equals_peak_iff_histogram_is_empty() {
// Equality-case pin of the `file_format_spread <=
// peak_file_format_count` bound: equality holds iff the trough
// is zero, which by `trough_file_format_count == 0 <=>
// file_format_histogram().is_empty()` (the file-format sub-
// axis's zero-trough boundary — the file-format histogram is
// empty exactly when no recognized-extension file layer
// contributes) holds iff the histogram is empty. Cross-sub-
// axis divergence pin against
// `layer_kind_spread_equals_peak_iff_chain_is_empty`: on the
// layer-kind sub-axis, the equality-case coincides with
// `self.as_ref().is_empty()`; on the file-format sub-axis, it
// coincides with `file_format_histogram().is_empty()` — the
// stricter boundary. Peer of
// `tier_spread_equals_peak_iff_map_is_empty` on the tier
// altitude and `kind_spread_equals_peak_iff_diff_is_empty` on
// the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let equal = slice.file_format_spread() == slice.peak_file_format_count();
assert_eq!(
equal,
slice.file_format_histogram().is_empty(),
"file_format_spread == peak_file_format_count iff \
file_format_histogram is empty (spread={s}, peak={p}, \
hist_empty={e})",
s = slice.file_format_spread(),
p = slice.peak_file_format_count(),
e = slice.file_format_histogram().is_empty(),
);
}
}
#[test]
fn file_format_spread_bounded_above_by_histogram_total() {
// Composition bound: `file_format_spread() <=
// file_format_histogram().total()` on every fixture — chaining
// `file_format_spread <= peak_file_format_count` (previous pin)
// with `peak_file_format_count <= file_format_histogram().total()`
// (documented on `peak_file_format_count`). Cross-sub-axis
// divergence from `layer_kind_spread_bounded_above_by_len`:
// the layer-kind sub-axis's histogram total equals the chain
// length (every entry projects to one cell), so the layer-kind
// sub-axis composes to `self.as_ref().len()`; the file-format
// sub-axis's histogram total is at most the count of `File`
// layers with recognized extensions (bounded by the chain
// length but not equal to it), so the file-format sub-axis
// composes to `file_format_histogram().total()` — the tighter
// bound.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let hist_total = slice.file_format_histogram().total();
assert!(
slice.file_format_spread() <= hist_total,
"file_format_spread()={s} must be <= \
file_format_histogram().total()={t}",
s = slice.file_format_spread(),
t = hist_total,
);
}
}
#[test]
fn file_format_spread_singleton_support_multi_layer_is_zero() {
// Direct pin at a 5-layer singleton-support Toml-only chain —
// present == {Toml}, peak == trough == 5, spread == 0. The
// scalar peer of the singleton-support cell degenerate
// `dominant_file_format() == recessive_file_format()` — the
// dispersion triple reads `(5, 5, 0)`, distinct from the
// 3-layer fixture in
// `file_format_spread_singleton_support_is_zero` so any misread
// that reintroduces the `peak - trough` inline idiom as `peak`
// alone silently underflows on a fixture at a different peak.
// Peer of `layer_kind_spread_singleton_support_multi_layer_is_zero`
// on the layer-kind sub-axis and
// `tier_spread_singleton_support_multi_leaf_is_zero` on the
// tier altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.toml")),
ConfigSource::File(PathBuf::from("/e.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert_eq!(slice.peak_file_format_count(), 5);
assert_eq!(slice.trough_file_format_count(), 5);
assert_eq!(slice.file_format_spread(), 0);
}
#[test]
fn file_format_spread_agrees_with_open_coded_max_minus_min_walk() {
// Parity against the exact `hist.iter().map(|(_, c)| c).max()
// .unwrap_or(0) - hist.iter().filter(|&(_, c)| c > 0)
// .map(|(_, c)| c).min().unwrap_or(0)` walk this lift replaces
// — both the named seam and the hand-rolled max-minus-min-over-
// support must pointwise agree over every fixture. The
// `filter(|(_, c)| c > 0)` step on the min side is the load-
// bearing seam: the naive `.min()` over the full axis would
// silently pick zero-count absent cells on any non-full-cover
// chain, shadowing the trough-of-support the seam surfaces —
// and once the trough shadows to zero, the spread coincides
// with the peak alone, silently overreporting the dispersion.
// Peer of `layer_kind_spread_agrees_with_open_coded_max_minus_min_walk`
// on the layer-kind sub-axis,
// `tier_spread_agrees_with_open_coded_max_minus_min_walk` on
// the tier altitude, and
// `kind_spread_agrees_with_open_coded_max_minus_min_walk` on
// the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_format_spread();
let hist = slice.file_format_histogram();
let peak = hist.iter().map(|(_, c)| c).max().unwrap_or(0);
let trough = hist
.iter()
.map(|(_, c)| c)
.filter(|&c| c > 0)
.min()
.unwrap_or(0);
assert_eq!(via_seam, peak - trough);
}
}
// ---- ConfigSourceChain::file_formats_balanced — balanced-file-formats
// boolean predicate on the file-format sub-axis of the chain
// altitude, lifting is_uniform_count from the histogram surface
// and continuing the "balanced across altitudes" projection
// sideways from the layer-kind sub-axis to the second chain
// sub-axis ----
#[test]
fn file_formats_balanced_matches_file_format_histogram_is_uniform_count_pointwise() {
// The routing pin: `file_formats_balanced` routes through
// `file_format_histogram().is_uniform_count()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches any
// future drift where either implementation stops projecting
// through the shared cube-native primitive. File-format sub-axis
// peer of
// `layer_kinds_balanced_matches_layer_kind_histogram_is_uniform_count_pointwise`
// on the layer-kind sub-axis,
// `tiers_balanced_matches_tier_histogram_is_uniform_count_pointwise`
// on the tier altitude, and
// `kinds_balanced_matches_kind_histogram_is_uniform_count_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().is_uniform_count();
assert_eq!(slice.file_formats_balanced(), via_histogram);
}
}
#[test]
fn file_formats_balanced_agrees_with_file_format_spread_zero_pointwise() {
// The defining equivalence on the scalar-spread surface at the
// file-format sub-axis: `file_formats_balanced() ==
// (file_format_spread() == 0)` on every fixture. The balanced-
// boundary of the fused `(peak_file_format_count,
// trough_file_format_count, file_format_spread)` dispersion
// triple as a named boolean predicate. Lifted from the trait-
// uniform `is_uniform_count() == (spread() == 0)` law on
// AxisHistogram. Peer of
// `layer_kinds_balanced_agrees_with_layer_kind_spread_zero_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let balanced = slice.file_formats_balanced();
let spread_zero = slice.file_format_spread() == 0;
assert_eq!(
balanced,
spread_zero,
"file_formats_balanced ({balanced}) must agree with \
file_format_spread == 0 (spread={s}) for chain",
s = slice.file_format_spread(),
);
}
}
#[test]
fn file_formats_balanced_agrees_with_peak_equals_trough_pointwise() {
// The structural form on the underlying scalar pair:
// `file_formats_balanced() == (peak_file_format_count() ==
// trough_file_format_count())` on every fixture. Pins the
// balanced-file-formats predicate against the direct scalar-pair
// equality form. Peer of
// `layer_kinds_balanced_agrees_with_peak_equals_trough_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let balanced = slice.file_formats_balanced();
let peak = slice.peak_file_format_count();
let trough = slice.trough_file_format_count();
assert_eq!(
balanced,
peak == trough,
"file_formats_balanced ({balanced}) must agree with \
peak_file_format_count == trough_file_format_count \
({peak} == {trough}) for chain",
);
}
}
#[test]
fn file_formats_balanced_agrees_with_modal_pair_equality_pointwise() {
// The modal-pair form: `file_formats_balanced() ==
// (dominant_file_format() == recessive_file_format())` on every
// fixture — including the empty-histogram chain where both
// branches reduce to `None == None`, every singleton-support
// chain where both reduce to `Some(f) == Some(f)`, every uniform
// per-format chain where both reduce to `Some(first) ==
// Some(first)` (after declaration-order tie-break on both sides),
// and every skewed chain where both read `false`. Cross-sub-axis
// divergence pin against
// `file_format_spread_agrees_with_modal_pair_equality_on_nonempty_histogram`:
// the balanced predicate agrees with the modal-pair equality
// universally over the fixture set (both branches read `true` on
// the empty-histogram trivial-equal case), while the scalar-
// spread agreement pin quantifies over non-empty-histogram
// chains only. Peer of
// `layer_kinds_balanced_agrees_with_modal_pair_equality_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let balanced = slice.file_formats_balanced();
let modal_pair_equal = slice.dominant_file_format() == slice.recessive_file_format();
assert_eq!(
balanced, modal_pair_equal,
"file_formats_balanced ({balanced}) must agree with \
dominant_file_format == recessive_file_format for chain",
);
}
}
#[test]
fn file_formats_balanced_empty_chain_is_true() {
// Vacuous-uniformity boundary: the empty chain has no observed
// cells, so the universal "every observed cell carries the same
// count" reads `true` over the empty support — matching
// AxisHistogram::is_uniform_count's empty convention one altitude
// down and `file_format_spread == 0` on the empty case. Peer of
// `layer_kinds_balanced_empty_chain_is_true` on the layer-kind
// sub-axis and `file_format_spread_empty_chain_is_zero` on the
// scalar-spread surface at the same sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.file_formats_balanced());
assert_eq!(empty.file_format_spread(), 0);
}
#[test]
fn file_formats_balanced_no_recognized_files_is_true() {
// The non-empty-chain / empty-histogram vacuous-uniformity
// boundary the file-format sub-axis pins that the layer-kind
// sub-axis does *not*. A chain of only Defaults / Env /
// unrecognized-extension File layers is non-empty but has no
// recognized file_format projection, so the histogram is empty
// and `file_formats_balanced` reads `true` — the vacuous-
// uniformity boundary reads through the seam. Distinguishing
// pin against `layer_kinds_balanced`: on those same chains,
// `layer_kinds_balanced` reads `false` when the layer-kind
// histogram is skewed (Defaults / Env / File layers still
// contribute to the layer-kind histogram at differing counts)
// while `file_formats_balanced` reads `true`. Cross-sub-axis
// divergence at the empty-histogram-boundary.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert!(slice.file_formats_balanced());
}
}
#[test]
fn file_formats_balanced_singleton_support_is_true() {
// Singleton-support pin: every recognized-extension file layer
// lands on the same format, so the one observed format's count
// is both peak and trough of the support — trivially balanced.
// Peer of `layer_kinds_balanced_singleton_support_is_true` on
// the layer-kind sub-axis and
// `file_format_spread_singleton_support_is_zero` on the scalar-
// spread surface at the same sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_balanced());
}
#[test]
fn file_formats_balanced_uniform_cover_is_true() {
// Uniform-cover pin: every observed format contributes the same
// nonzero count (one file layer per format here — a full-cover
// chain with uniform count 1 per cell), so peak == trough == 1
// and the balanced-file-formats predicate reads `true`. Peer of
// `layer_kinds_balanced_uniform_cover_is_true` on the layer-kind
// sub-axis and `file_format_spread_uniform_cover_is_zero` on the
// scalar-spread surface at the same sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_format_histogram().is_full_cover());
assert!(slice.file_formats_balanced());
}
#[test]
fn file_formats_balanced_toml_majority_is_false() {
// Direct pin against a toml-majority chain: three `.toml` file
// layers + one `.yaml` + one Env + one Defaults. Toml dominant
// at 3, Yaml recessive at 1 — spread == 2, so
// `file_formats_balanced` reads `false`. Peer of
// `layer_kinds_balanced_sample_chain_is_false` and
// `layer_kinds_balanced_env_majority_is_false` on the layer-kind
// sub-axis on the boolean side and
// `file_format_spread_toml_majority_is_two` on the scalar-spread
// surface.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.yaml")),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.file_format_spread(), 2);
assert!(!slice.file_formats_balanced());
}
#[test]
fn file_formats_balanced_sample_chain_is_true() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one Env layer. Yaml is the sole observed format (Env layers
// don't contribute to the file-format histogram), so peak ==
// trough == 2 and `file_formats_balanced` reads `true` — the
// singleton-support degenerate. Cross-sub-axis divergence pin
// against `layer_kinds_balanced_sample_chain_is_false`: on the
// same fixture, the layer-kind sub-axis reads `false` (File
// dominant at 2, Env recessive at 1) while the file-format sub-
// axis reads `true` (only Yaml observed).
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.file_format_spread(), 0);
assert!(slice.file_formats_balanced());
}
#[test]
fn file_formats_balanced_singleton_support_multi_layer_is_true() {
// Singleton-support multi-layer pin: 5 File layers all on the
// same format — peak == trough == 5, balanced reads `true`.
// Distinct peak from the 3-layer singleton fixture above so any
// misread that reintroduces a `file_format_spread == 0` inline
// idiom silently underflows on a fixture at a different peak.
// Peer of
// `layer_kinds_balanced_singleton_support_multi_layer_is_true`
// on the layer-kind sub-axis and
// `file_format_spread_singleton_support_multi_layer_is_zero` on
// the scalar-spread surface at the same sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.toml")),
ConfigSource::File(PathBuf::from("/e.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.peak_file_format_count(), 5);
assert_eq!(slice.trough_file_format_count(), 5);
assert!(slice.file_formats_balanced());
}
#[test]
fn file_formats_balanced_implies_at_most_one_present_format_or_uniform_cover() {
// Structural characterization: on every fixture,
// `file_formats_balanced` holds when the chain's file-format
// support size is 0 or 1, or every observed format carries the
// same nonzero count. Direct witness of the trait-uniform
// `distinct_cells() <= 1 ⇒ is_uniform_count()` law on
// AxisHistogram, lifted to the file-format sub-axis of the
// chain altitude. Peer of
// `layer_kinds_balanced_implies_at_most_one_present_kind_or_uniform_cover`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.present_file_formats().len() <= 1 {
assert!(
slice.file_formats_balanced(),
"chain with present_file_formats.len() = {} must be \
file_formats_balanced",
slice.present_file_formats().len(),
);
}
}
}
#[test]
fn file_formats_balanced_false_implies_file_format_histogram_is_nonempty() {
// Contrapositive of the vacuous-uniformity implication:
// `!file_formats_balanced() ⇒ !file_format_histogram().is_empty()`.
// A skewed chain has at least two distinct positive counts on
// the file-format histogram, so the histogram is non-empty.
// Cross-sub-axis divergence pin against
// `layer_kinds_balanced_false_implies_chain_is_nonempty`: on the
// layer-kind sub-axis, the contrapositive falls on
// `!self.as_ref().is_empty()`; on the file-format sub-axis, it
// falls on the stricter `!file_format_histogram().is_empty()` —
// a non-empty chain of only Defaults / Env / unrecognized-
// extension File layers has an empty file-format histogram and
// is `file_formats_balanced`, so the chain-non-empty
// implication would fail on those fixtures.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if !slice.file_formats_balanced() {
assert!(
!slice.file_format_histogram().is_empty(),
"non-balanced chain must have non-empty file-format \
histogram",
);
}
}
}
#[test]
fn file_formats_balanced_false_implies_at_least_two_present_file_formats() {
// Contrapositive of the singleton-support implication:
// `!file_formats_balanced() ⇒ present_file_formats().len() >= 2`.
// A skewed chain observes at least two distinct formats with
// differing counts. Lifted from the trait-uniform
// `!is_uniform_count() ⇒ distinct_cells() >= 2` law on
// AxisHistogram. Peer of
// `layer_kinds_balanced_false_implies_at_least_two_present_layer_kinds`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if !slice.file_formats_balanced() {
assert!(
slice.present_file_formats().len() >= 2,
"non-balanced chain must observe >= 2 present file \
formats (was {})",
slice.present_file_formats().len(),
);
}
}
}
#[test]
fn file_formats_balanced_skewed_three_cell_fixture_is_false() {
// Direct pin: a strictly-ordered three-cell chain with
// Yaml=1, Toml=2, Lisp=3 — peak 3, trough 1, spread 2 — reads
// `false`. Every count distinct, no tie-breaking on either side
// of the modal-count pair. Peer of
// `layer_kinds_balanced_skewed_three_cell_fixture_is_false` on
// the layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.lisp")),
ConfigSource::File(PathBuf::from("/e.lisp")),
ConfigSource::File(PathBuf::from("/f.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.peak_file_format_count(), 3);
assert_eq!(slice.trough_file_format_count(), 1);
assert!(!slice.file_formats_balanced());
}
#[test]
fn file_formats_balanced_agrees_with_open_coded_uniform_walk() {
// Parity against the exact hand-rolled uniform-count walk this
// lift replaces: pull the nonzero counts and check they all
// agree. Empty support reads `true` vacuously. Mirrors the
// parity pin
// `layer_kinds_balanced_agrees_with_open_coded_uniform_walk` on
// the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_balanced();
let hist = slice.file_format_histogram();
let mut nonzero = hist.iter().map(|(_, c)| c).filter(|&c| c > 0);
let hand_rolled = match nonzero.next() {
None => true,
Some(first) => nonzero.all(|c| c == first),
};
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::file_formats_full_cover — full-cover-file-
// formats boolean predicate on the file-format sub-axis of the
// chain altitude, lifting is_full_cover from the histogram
// surface and lifting the "full-cover across altitudes"
// projection sideways from the layer-kind sub-axis to the
// second chain-altitude sub-axis ----
#[test]
fn file_formats_full_cover_matches_file_format_histogram_is_full_cover_pointwise() {
// The routing pin: `file_formats_full_cover` routes through
// `file_format_histogram().is_full_cover()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops
// projecting through the shared cube-native primitive. File-
// format sub-axis peer of
// `layer_kinds_full_cover_matches_layer_kind_histogram_is_full_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_full_cover_matches_tier_histogram_is_full_cover_pointwise`
// on the tier altitude, and
// `kinds_full_cover_matches_kind_histogram_is_full_cover_pointwise`
// on the diff altitude, in the "full-cover across altitudes"
// projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().is_full_cover();
assert_eq!(slice.file_formats_full_cover(), via_histogram);
}
}
#[test]
fn file_formats_full_cover_agrees_with_absent_file_formats_empty_pointwise() {
// The defining equivalence on the coverage-gap-Vec surface at
// the file-format sub-axis: `file_formats_full_cover() ==
// absent_file_formats().is_empty()` on every fixture. The
// full-cover-boundary of the fused `(absent_file_formats,
// absent_file_formats_count)` coverage-gap peers as a named
// boolean predicate. Lifted from the trait-uniform
// `is_full_cover() == unobserved().next().is_none()` law on
// AxisHistogram. Peer of
// `layer_kinds_full_cover_agrees_with_absent_layer_kinds_empty_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.file_formats_full_cover();
let gap_empty = slice.absent_file_formats().is_empty();
assert_eq!(
full_cover, gap_empty,
"file_formats_full_cover ({full_cover}) must agree with \
absent_file_formats().is_empty() ({gap_empty}) for chain",
);
}
}
#[test]
fn file_formats_full_cover_agrees_with_absent_file_formats_count_zero_pointwise() {
// The coverage-gap-scalar form: `file_formats_full_cover() ==
// (absent_file_formats_count() == 0)` on every fixture. Pins
// the full-cover-file-formats predicate against the scalar-
// zero equality form on the coverage-gap side. Peer of
// `layer_kinds_full_cover_agrees_with_absent_layer_kinds_count_zero_pointwise`.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.file_formats_full_cover();
let count_zero = slice.absent_file_formats_count() == 0;
assert_eq!(
full_cover,
count_zero,
"file_formats_full_cover ({full_cover}) must agree with \
absent_file_formats_count == 0 (count={c}) for chain",
c = slice.absent_file_formats_count(),
);
}
}
#[test]
fn file_formats_full_cover_agrees_with_present_file_formats_count_equals_axis_cardinality_pointwise()
{
// The support-scalar form: `file_formats_full_cover() ==
// (present_file_formats_count() ==
// axis_cardinality::<crate::discovery::Format>())` on every
// fixture — the dual-side surfacing of the same boolean across
// the (observed, unobserved) partition. Lifted from the trait-
// uniform `is_full_cover() == (distinct_cells() ==
// axis_cardinality::<A>())` law on AxisHistogram. Peer of
// `layer_kinds_full_cover_agrees_with_present_layer_kinds_count_equals_axis_cardinality_pointwise`.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.file_formats_full_cover();
let support_full = slice.present_file_formats_count()
== crate::axis_cardinality::<crate::discovery::Format>();
assert_eq!(
full_cover, support_full,
"file_formats_full_cover ({full_cover}) must agree with \
present_file_formats_count == axis_cardinality for chain",
);
}
}
#[test]
fn file_formats_full_cover_agrees_with_present_file_formats_len_equals_axis_cardinality_pointwise()
{
// The support-Vec form: `file_formats_full_cover() ==
// (present_file_formats().len() ==
// axis_cardinality::<crate::discovery::Format>())` on every
// fixture. Pins the predicate against the
// `Vec<crate::discovery::Format>` length form consumers reach
// for when they already hold the support vector. Peer of
// `layer_kinds_full_cover_agrees_with_present_layer_kinds_len_equals_axis_cardinality_pointwise`.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.file_formats_full_cover();
let support_len_full = slice.present_file_formats().len()
== crate::axis_cardinality::<crate::discovery::Format>();
assert_eq!(
full_cover, support_len_full,
"file_formats_full_cover ({full_cover}) must agree with \
present_file_formats().len() == axis_cardinality for chain",
);
}
}
#[test]
fn file_formats_full_cover_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has no observed cells,
// so the coverage gap equals every cell of
// `crate::discovery::Format::ALL` (four-cell axis, no zero-
// cardinality degenerate case) — `file_formats_full_cover`
// reads `false`. Dual of `file_formats_balanced_empty_chain_is_true`:
// the empty chain is on the opposite side of the full-cover
// boundary from the balanced boundary at the file-format sub-
// axis, matching the diff-altitude / tier-altitude / layer-
// kind sub-axis empty-vs-empty orthogonality. Matches
// `is_full_cover` reading `false` on the empty histogram over
// a non-zero-cardinality axis one altitude down. Peer of
// `layer_kinds_full_cover_empty_chain_is_false` on the layer-
// kind sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_full_cover());
assert_eq!(
empty.absent_file_formats_count(),
crate::axis_cardinality::<crate::discovery::Format>()
);
}
#[test]
fn file_formats_full_cover_no_recognized_files_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_full_cover_empty_chain_is_false`: on the file-
// format sub-axis the *non-empty-chain / empty-histogram*
// boundary ALSO reads `false`. A chain of only Defaults / Env
// / unrecognized-extension File layers is non-empty but has an
// empty file-format histogram, so the coverage gap equals
// every cell — `file_formats_full_cover` reads `false`.
// Distinguishing pin against `file_formats_balanced` on the
// exact same fixtures (where the vacuous-uniformity boundary
// reads `true`): full-cover and balanced fall on opposite
// sides of the empty-histogram boundary at the file-format
// sub-axis. Also distinguishing against
// `layer_kinds_full_cover` on the same fixtures — the layer-
// kind sub-axis on these chains reads `false` because the
// support is incomplete on the layer-kind axis too, but for a
// structurally different reason (missing kinds vs. missing
// formats).
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert!(!slice.file_formats_full_cover());
assert!(slice.file_formats_balanced());
}
}
#[test]
fn file_formats_full_cover_singleton_support_is_false() {
// Singleton-support pin: every recognized-extension file layer
// lands on the same format, so one observed cell out of four
// leaves three cells in the coverage gap —
// `file_formats_full_cover` reads `false`. Peer of
// `file_formats_balanced_singleton_support_is_true` on the
// opposite side of the boundary: singleton-support is
// trivially balanced but never full-cover on a four-cell axis.
// Peer of `layer_kinds_full_cover_singleton_support_is_false`
// on the layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(!slice.file_formats_full_cover());
}
#[test]
fn file_formats_full_cover_two_format_cover_is_false() {
// Two-format cover pin: a chain observing Toml + Yaml but
// never Lisp / Nix leaves two cells in the coverage gap —
// `file_formats_full_cover` reads `false`. Direct witness that
// the two-format-observed shape (support size 2 out of 4) is
// on the `false` side of the full-cover boundary. Peer of
// `layer_kinds_full_cover_two_kind_cover_is_false` on the
// layer-kind sub-axis (two-of-three cover) — same "still short
// of full cover" boundary at the sister sub-axis.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(!slice.file_formats_full_cover());
assert!(slice.absent_file_formats().contains(&Format::Lisp));
assert!(slice.absent_file_formats().contains(&Format::Nix));
}
#[test]
fn file_formats_full_cover_uniform_cover_is_true() {
// Uniform-cover pin: every format contributes one file layer,
// so every cell of `crate::discovery::Format::ALL` receives at
// least one observation — `file_formats_full_cover` reads
// `true`. Peer of `file_formats_balanced_uniform_cover_is_true`
// on the same fixture shape (uniform four-format cover):
// uniform full-cover is on the `true` side of BOTH the
// balanced-file-formats and full-cover-file-formats boundaries.
// Peer of `layer_kinds_full_cover_uniform_cover_is_true` on
// the layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_formats_full_cover());
assert!(slice.file_formats_balanced());
}
#[test]
fn file_formats_full_cover_skewed_four_cell_fixture_is_true() {
// Direct pin: a strictly-ordered four-cell chain with
// Yaml=1, Toml=2, Lisp=3, Nix=4 has every format observed —
// `file_formats_full_cover` reads `true`, orthogonal to
// `file_formats_balanced` which reads `false` on the identical
// fixture (peak 4, trough 1, spread 3). Every format observed
// but at strictly-distinct counts: full-cover is the coverage
// boundary, not the uniformity boundary. Peer of
// `layer_kinds_full_cover_skewed_three_cell_fixture_is_true`
// on the layer-kind sub-axis and
// `tiers_full_cover_skewed_four_cell_fixture_is_true` on the
// tier altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.lisp")),
ConfigSource::File(PathBuf::from("/e.lisp")),
ConfigSource::File(PathBuf::from("/f.lisp")),
ConfigSource::File(PathBuf::from("/g.nix")),
ConfigSource::File(PathBuf::from("/h.nix")),
ConfigSource::File(PathBuf::from("/i.nix")),
ConfigSource::File(PathBuf::from("/j.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_formats_full_cover());
assert!(!slice.file_formats_balanced());
}
#[test]
fn file_formats_full_cover_sample_chain_is_false() {
// Direct pin against `sample_chain()`: two `.yaml` file layers
// + one Env layer. The support is {Yaml} — size 1 out of 4 —
// so `file_formats_full_cover` reads `false`. Peer of
// `file_formats_balanced_sample_chain_is_true` on the same
// fixture on the sister boundary: balanced reads `true`
// (singleton support is trivially balanced) while full-cover
// reads `false` — orthogonal boundary witnesses at the same
// fixture.
use crate::discovery::Format;
let chain = sample_chain();
let slice = chain.as_slice();
assert!(!slice.file_formats_full_cover());
assert!(slice.absent_file_formats().contains(&Format::Toml));
assert!(slice.absent_file_formats().contains(&Format::Lisp));
assert!(slice.absent_file_formats().contains(&Format::Nix));
}
#[test]
fn file_formats_full_cover_implies_file_format_histogram_is_nonempty() {
// Contrapositive of the empty-histogram boundary:
// `file_formats_full_cover() ⇒
// !file_format_histogram().is_empty()`. A full-cover chain
// observes at least one recognized-extension file layer per
// format, so the histogram is non-empty. Directly witnessed on
// the fixture set. Cross-sub-axis divergence from the layer-
// kind sub-axis's `layer_kinds_full_cover_implies_chain_is_nonempty`
// pin: the file-format sub-axis's contrapositive reads on the
// *histogram-empty* condition rather than the *chain-empty*
// condition, matching the empty-histogram / non-empty-chain
// distinction that separates the file-format sub-axis's
// vacuous-uniformity boundary from the layer-kind sub-axis's.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() {
assert!(
!slice.file_format_histogram().is_empty(),
"full-cover chain must have non-empty file-format histogram",
);
}
}
}
#[test]
fn file_formats_full_cover_implies_present_file_formats_equals_axis_cardinality() {
// Structural characterization: `file_formats_full_cover() ⇒
// present_file_formats().len() ==
// axis_cardinality::<crate::discovery::Format>()`. A full-
// cover chain observes every format, so the support size
// equals the axis cardinality. Direct witness of the trait-
// uniform `is_full_cover() ⇒ distinct_cells() ==
// axis_cardinality::<A>()` law on AxisHistogram, lifted to
// the file-format sub-axis of the chain altitude. Peer of
// `layer_kinds_full_cover_implies_present_layer_kinds_equals_axis_cardinality`.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() {
assert_eq!(
slice.present_file_formats().len(),
crate::axis_cardinality::<crate::discovery::Format>(),
"full-cover chain must observe every Format",
);
}
}
}
#[test]
fn file_formats_full_cover_implies_file_format_histogram_total_bounded_below_by_axis_cardinality()
{
// Histogram-total lower-bound characterization:
// `file_formats_full_cover() ⇒ file_format_histogram().total()
// >= axis_cardinality::<crate::discovery::Format>()`. A full-
// cover chain observes at least one recognized-extension file
// layer per format, so the histogram total is bounded below by
// the axis cardinality. Directly witnessed on the fixture set.
// Cross-sub-axis divergence from the layer-kind sub-axis's
// `layer_kinds_full_cover_implies_chain_length_bounded_below_by_axis_cardinality`
// pin: on the file-format sub-axis the lower bound reads on
// the *histogram total* rather than the chain length — the
// chain may include unrelated Defaults / Env / unrecognized-
// extension File layers that don't contribute to the histogram
// but grow the chain length.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() {
assert!(
slice.file_format_histogram().total()
>= crate::axis_cardinality::<crate::discovery::Format>(),
"full-cover chain must have histogram total >= axis_cardinality (was {})",
slice.file_format_histogram().total(),
);
}
}
}
#[test]
fn file_formats_full_cover_implies_layer_kind_file_count_bounded_below_by_axis_cardinality() {
// Cross-sub-axis lower-bound implication: a full-cover chain
// on the file-format sub-axis observes at least one
// recognized-extension file layer per format; every such
// layer is a `ConfigSource::File`, so the layer-kind-sub-axis
// File cell count is bounded below by the file-format axis
// cardinality. Directly witnesses the cross-sub-axis link
// between the file-format sub-axis's full-cover boundary and
// the layer-kind sub-axis's File cell count.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() {
assert!(
slice.layer_kind_histogram().count(ConfigSourceKind::File)
>= crate::axis_cardinality::<crate::discovery::Format>(),
"full-cover chain must have >= axis_cardinality File layers (was {})",
slice.layer_kind_histogram().count(ConfigSourceKind::File),
);
}
}
}
#[test]
fn file_formats_full_cover_agrees_with_open_coded_all_positive_walk() {
// Parity against the exact hand-rolled full-cover walk this
// lift replaces: walk every cell of the histogram and check
// every count is positive. Mirrors the parity pin
// `layer_kinds_full_cover_agrees_with_open_coded_all_positive_walk`
// on the layer-kind sub-axis,
// `tiers_full_cover_agrees_with_open_coded_all_positive_walk`
// on the tier altitude, and
// `kinds_full_cover_agrees_with_open_coded_all_positive_walk`
// on the diff altitude. Note the walk uses `hist.iter()` which
// iterates over the closed axis's ALL cells in declaration
// order — a full-cover chain has every cell nonzero regardless
// of order.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_full_cover();
let hist = slice.file_format_histogram();
let hand_rolled = hist.iter().all(|(_, c)| c > 0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::file_formats_any_observed — any-observed-
// file-formats boolean predicate on the file-format sub-axis of
// the chain altitude, lifting the "any-observed across altitudes"
// projection sideways from the layer-kind sub-axis to the second
// chain-altitude sub-axis. Routed through the shared
// `!AxisHistogram::is_empty` primitive one altitude down. ----
#[test]
fn file_formats_any_observed_matches_file_format_histogram_is_empty_negation_pointwise() {
// The routing pin: `file_formats_any_observed` routes through
// `!file_format_histogram().is_empty()`, so the two seams must
// stay pointwise equivalent under every fixture. Catches any
// future drift where either implementation stops projecting
// through the shared cube-native primitive. File-format sub-
// axis peer of
// `layer_kinds_any_observed_matches_layer_kind_histogram_is_empty_negation_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_any_observed_matches_tier_histogram_is_empty_negation_pointwise`
// on the tier altitude, and
// `kinds_any_observed_matches_kind_histogram_is_empty_negation_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = !slice.file_format_histogram().is_empty();
assert_eq!(slice.file_formats_any_observed(), via_histogram);
}
}
#[test]
fn file_formats_any_observed_agrees_with_present_file_formats_count_positive_pointwise() {
// Support-scalar surface: `file_formats_any_observed() ==
// (present_file_formats_count() > 0)`, without allocating the
// `Vec<crate::discovery::Format>`. Peer of
// `layer_kinds_any_observed_agrees_with_present_layer_kinds_count_positive_pointwise`
// on the layer-kind sub-axis and
// `tiers_any_observed_agrees_with_contributing_tiers_count_positive_pointwise`
// on the tier altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_any_observed();
let via_scalar = slice.present_file_formats_count() > 0;
assert_eq!(
via_seam,
via_scalar,
"file_formats_any_observed ({via_seam}) must agree with \
present_file_formats_count > 0 (count={c}) for chain",
c = slice.present_file_formats_count(),
);
}
}
#[test]
fn file_formats_any_observed_agrees_with_present_file_formats_nonempty_pointwise() {
// Support-`Vec` surface: `file_formats_any_observed() ==
// !present_file_formats().is_empty()`. Pins the predicate
// against the `Vec<crate::discovery::Format>` non-empty form
// consumers reach for when they already hold the support
// vector. Peer of
// `layer_kinds_any_observed_agrees_with_present_layer_kinds_nonempty_pointwise`.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_any_observed();
let via_vec = !slice.present_file_formats().is_empty();
assert_eq!(
via_seam, via_vec,
"file_formats_any_observed ({via_seam}) must agree with \
!present_file_formats().is_empty() ({via_vec}) for chain",
);
}
}
#[test]
fn file_formats_any_observed_agrees_with_absent_file_formats_count_below_axis_cardinality_pointwise()
{
// Coverage-gap-scalar surface: `file_formats_any_observed() ==
// (absent_file_formats_count() <
// crate::axis_cardinality::<crate::discovery::Format>())`. The
// dual-side surfacing of the same boolean across the
// (observed, unobserved) partition. Peer of
// `layer_kinds_any_observed_agrees_with_absent_layer_kinds_count_below_axis_cardinality_pointwise`.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_any_observed();
let via_gap = slice.absent_file_formats_count()
< crate::axis_cardinality::<crate::discovery::Format>();
assert_eq!(
via_seam, via_gap,
"file_formats_any_observed ({via_seam}) must agree with \
absent_file_formats_count < axis_cardinality ({via_gap}) for chain",
);
}
}
#[test]
fn file_formats_any_observed_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has no observed cells,
// so the "any observed" predicate fails —
// `file_formats_any_observed` reads `false`. Matches
// `is_empty` reading `true` on the empty histogram over the
// `crate::discovery::Format` axis one altitude down. Dual of
// `file_formats_balanced_empty_chain_is_true`: the empty chain
// is on the opposite side of the any-observed boundary from
// the balanced boundary and on the same side as the full-cover
// boundary — the (`any_observed`=false, `balanced`=true,
// `full_cover`=false) polarity triple. Peer of
// `layer_kinds_any_observed_empty_chain_is_false` on the
// layer-kind sub-axis, `tiers_any_observed_empty_map_is_false`
// on the tier altitude, and
// `kinds_any_observed_empty_diff_is_false` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_any_observed());
assert!(empty.file_formats_balanced());
assert!(!empty.file_formats_full_cover());
}
#[test]
fn file_formats_any_observed_no_recognized_files_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_any_observed_empty_chain_is_false`: on the file-
// format sub-axis the *non-empty-chain / empty-histogram*
// boundary ALSO reads `false`. A chain of only Defaults / Env
// / unrecognized-extension File layers is non-empty but has an
// empty file-format histogram, so no observed cell fires —
// `file_formats_any_observed` reads `false`. Distinguishing
// pin against `file_formats_balanced` on the exact same
// fixtures (where the vacuous-uniformity boundary reads
// `true`): any-observed and balanced fall on opposite sides
// of the empty-histogram boundary at the file-format sub-
// axis. Also matches
// `file_formats_full_cover_no_recognized_files_is_false` on
// the same-shape fixtures (both any-observed and full-cover
// read `false` on empty-histogram non-empty chains).
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert!(!slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(!slice.file_formats_full_cover());
}
}
#[test]
fn file_formats_any_observed_singleton_support_is_true() {
// Singleton-support pin: every recognized-extension file layer
// lands on the same format, so one observed cell out of four
// suffices for the any-observed predicate —
// `file_formats_any_observed` reads `true`. Peer of
// `file_formats_balanced_singleton_support_is_true` on the
// same side of the boundary and orthogonal to
// `file_formats_full_cover_singleton_support_is_false` on the
// opposite side: singleton-support is trivially observed and
// trivially balanced but never full-cover on a four-cell
// axis. Peer of `layer_kinds_any_observed_singleton_support_is_true`
// on the layer-kind sub-axis — same
// (`any_observed`=true, `balanced`=true, `full_cover`=false)
// polarity triple on the singleton-support fixture.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(!slice.file_formats_full_cover());
}
#[test]
fn file_formats_any_observed_uniform_cover_is_true() {
// Uniform-cover pin: every format contributes one file layer,
// so every cell of `crate::discovery::Format::ALL` receives at
// least one observation — `file_formats_any_observed` reads
// `true`. Peer of `file_formats_balanced_uniform_cover_is_true`
// and `file_formats_full_cover_uniform_cover_is_true`: uniform
// four-format cover is on the `true` side of ALL THREE
// coverage-support boundaries at this sub-axis. Peer of
// `layer_kinds_any_observed_uniform_cover_is_true` on the
// layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(slice.file_formats_full_cover());
}
#[test]
fn file_formats_any_observed_two_format_partial_cover_is_true() {
// Two-format cover pin: a chain observing Toml + Yaml but
// never Lisp / Nix (support size 2 out of 4) still fires at
// least one observed cell — `file_formats_any_observed` reads
// `true`. Direct witness of `file_formats_full_cover ⇒
// file_formats_any_observed` on a fixture where full-cover
// reads `false` but any-observed still holds. Peer of
// `layer_kinds_any_observed_two_kind_partial_cover_is_true`
// on the layer-kind sub-axis at the sister partial-cover
// fixture.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(slice.file_formats_any_observed());
assert!(!slice.file_formats_full_cover());
}
#[test]
fn file_formats_full_cover_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_full_cover() ⇒
// file_formats_any_observed()` on every fixture — a full-cover
// chain observes every cell, so it observes at least one cell.
// Peer of `layer_kinds_full_cover_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis,
// `tiers_full_cover_implies_tiers_any_observed_pointwise` on
// the tier altitude, and
// `kinds_full_cover_implies_kinds_any_observed_pointwise` on
// the diff altitude. Names the ordering `full_cover ≤
// any_observed` on the coverage-support partition at the file-
// format sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() {
assert!(
slice.file_formats_any_observed(),
"full-cover chain must be any-observed (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn file_formats_any_observed_implies_layer_kind_file_count_positive_pointwise() {
// Cross-sub-axis lower-bound implication:
// `file_formats_any_observed() ⇒
// layer_kind_histogram().count(ConfigSourceKind::File) >= 1`.
// A chain observing any file format has at least one
// recognized-extension file layer, and every such layer is a
// `ConfigSource::File`. Cross-sub-axis divergence from
// `layer_kinds_any_observed_implies_chain_length_positive_pointwise`
// on the layer-kind sub-axis, which reads on the chain-length
// rather than the File-layer count — the file-format sub-axis
// carries the stronger implication because Defaults / Env /
// unrecognized-extension File layers don't contribute to the
// file-format histogram.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_any_observed() {
assert!(
slice.layer_kind_histogram().count(ConfigSourceKind::File) >= 1,
"any-observed chain must have >= 1 File layer (was {})",
slice.layer_kind_histogram().count(ConfigSourceKind::File),
);
}
}
}
#[test]
fn file_formats_any_observed_negation_implies_file_formats_balanced_pointwise() {
// Empty-histogram / vacuous-balanced interaction pin: the
// empty-histogram chain is the only chain on the `false` side
// of `file_formats_any_observed`, and it is vacuously
// balanced. So `!file_formats_any_observed() ⇒
// file_formats_balanced()` holds pointwise. Peer of
// `layer_kinds_any_observed_negation_implies_layer_kinds_balanced_pointwise`
// on the layer-kind sub-axis and
// `tiers_any_observed_negation_implies_tiers_balanced_pointwise`
// on the tier altitude. Cross-sub-axis divergence from the
// layer-kind sub-axis: on the file-format sub-axis the `false`
// side of `any_observed` includes both the empty chain and
// every non-empty chain of only Defaults / Env / unrecognized-
// extension File layers.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if !slice.file_formats_any_observed() {
assert!(
slice.file_formats_balanced(),
"non-any-observed chain must be vacuously balanced",
);
}
}
}
#[test]
fn file_formats_any_observed_agrees_with_open_coded_any_positive_walk() {
// Parity against the exact hand-rolled any-observed walk this
// lift replaces: walk every cell of the histogram and check
// any count is positive. Mirrors the parity pin
// `layer_kinds_any_observed_agrees_with_open_coded_any_positive_walk`
// on the layer-kind sub-axis,
// `tiers_any_observed_agrees_with_open_coded_any_positive_walk`
// on the tier altitude, and
// `kinds_any_observed_agrees_with_open_coded_any_positive_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_any_observed();
let hist = slice.file_format_histogram();
let hand_rolled = hist.iter().any(|(_, c)| c > 0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::file_formats_singular_support —
// singleton-support-file-formats boolean predicate on the
// file-format sub-axis of the chain altitude, lifting the
// "singleton-support across altitudes" projection sideways
// from the layer-kind sub-axis
// (`ConfigSourceChain::layer_kinds_singular_support`) into the
// second chain-altitude sub-axis. Routed through the shared
// `AxisHistogram::has_singular_support` primitive one altitude
// down. ----
#[test]
fn file_formats_singular_support_matches_file_format_histogram_has_singular_support_pointwise()
{
// Routing pin: `file_formats_singular_support` routes through
// `file_format_histogram().has_singular_support()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. File-
// format sub-axis peer of
// `layer_kinds_singular_support_matches_layer_kind_histogram_has_singular_support_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_support_matches_tier_histogram_has_singular_support_pointwise`
// on the tier altitude, and
// `kinds_singular_support_matches_kind_histogram_has_singular_support_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().has_singular_support();
assert_eq!(slice.file_formats_singular_support(), via_histogram);
}
}
#[test]
fn file_formats_singular_support_agrees_with_present_file_formats_count_equals_one_pointwise() {
// Support-scalar surface: `file_formats_singular_support() ==
// (present_file_formats_count() == 1)` on every fixture. The
// support-side surfacing of the same boolean, without
// allocating the `Vec<crate::discovery::Format>`. Lifted from
// the trait-uniform `has_singular_support() ⇔ distinct_cells()
// == 1` law on AxisHistogram. Peer of
// `layer_kinds_singular_support_agrees_with_present_layer_kinds_count_equals_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular_support();
let via_scalar = slice.present_file_formats_count() == 1;
assert_eq!(
via_seam,
via_scalar,
"file_formats_singular_support ({via_seam}) must agree with \
present_file_formats_count == 1 (count={c}) for chain",
c = slice.present_file_formats_count(),
);
}
}
#[test]
fn file_formats_singular_support_agrees_with_present_file_formats_len_equals_one_pointwise() {
// Support-`Vec` form: `file_formats_singular_support() ==
// (present_file_formats().len() == 1)` on every fixture. Pins
// the predicate against the `Vec<crate::discovery::Format>`
// length form consumers reach for when they already hold the
// support vector. Peer of
// `layer_kinds_singular_support_agrees_with_present_layer_kinds_len_equals_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular_support();
let via_vec = slice.present_file_formats().len() == 1;
assert_eq!(
via_seam, via_vec,
"file_formats_singular_support ({via_seam}) must agree with \
present_file_formats().len() == 1 ({via_vec}) for chain",
);
}
}
#[test]
fn file_formats_singular_support_agrees_with_absent_file_formats_count_equals_axis_cardinality_minus_one_pointwise()
{
// Coverage-gap-scalar form: `file_formats_singular_support() ==
// (absent_file_formats_count() ==
// axis_cardinality::<crate::discovery::Format>() - 1)` on every
// fixture. The coverage-gap-side surfacing of the same boolean
// — a singleton-support chain observes one cell and misses the
// remaining `axis_cardinality - 1` cells. Peer of
// `layer_kinds_singular_support_agrees_with_absent_layer_kinds_count_equals_axis_cardinality_minus_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular_support();
let via_gap = slice.absent_file_formats_count()
== crate::axis_cardinality::<crate::discovery::Format>() - 1;
assert_eq!(
via_seam,
via_gap,
"file_formats_singular_support ({via_seam}) must agree with \
absent_file_formats_count == axis_cardinality - 1 (gap={g}) for chain",
g = slice.absent_file_formats_count(),
);
}
}
#[test]
fn file_formats_singular_support_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has no observed cells,
// so the singular-support predicate reads `false` (support
// cardinality is 0, not 1). Matches `has_singular_support`
// reading `false` on the empty histogram one altitude down.
// Peer of `file_formats_any_observed_empty_chain_is_false` and
// `file_formats_full_cover_empty_chain_is_false` on the same
// polarity of the coverage-support partition, and orthogonal
// to `file_formats_balanced_empty_chain_is_true` on the
// opposite polarity — the four boundaries partition the empty
// chain into the polarity quadruple (`any_observed`=false,
// `singular_support`=false, `balanced`=true, `full_cover`=false).
// Peer of `layer_kinds_singular_support_empty_chain_is_false`
// on the layer-kind sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_singular_support());
assert!(!empty.file_formats_any_observed());
assert!(empty.file_formats_balanced());
assert!(!empty.file_formats_full_cover());
}
#[test]
fn file_formats_singular_support_no_recognized_files_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_singular_support_empty_chain_is_false`: on the
// file-format sub-axis the *non-empty-chain / empty-histogram*
// boundary ALSO reads `false`. A chain of only Defaults / Env
// / unrecognized-extension File layers is non-empty but has an
// empty file-format histogram, so no observed cell fires and
// support cardinality is 0 — `file_formats_singular_support`
// reads `false`. Matches
// `file_formats_any_observed_no_recognized_files_is_false` and
// `file_formats_full_cover_no_recognized_files_is_false` on
// the same-shape fixtures (all three read `false` on empty-
// histogram non-empty chains). Distinguishing pin against
// `file_formats_balanced` on the exact same fixtures (where
// the vacuous-uniformity boundary reads `true`).
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert!(!slice.file_formats_singular_support());
assert!(!slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(!slice.file_formats_full_cover());
}
}
#[test]
fn file_formats_singular_support_singleton_support_is_true() {
// Singleton-support pin: every recognized-extension file
// layer lands on the same format, so the support is exactly
// one cell — `file_formats_singular_support` reads `true`.
// Peer of `file_formats_any_observed_singleton_support_is_true`
// and `file_formats_balanced_singleton_support_is_true` on the
// same polarity and orthogonal to
// `file_formats_full_cover_singleton_support_is_false` on the
// opposite polarity. The singleton-support fixture partitions
// the four boundaries with (`any_observed`=true,
// `singular_support`=true, `balanced`=true,
// `full_cover`=false). Peer of
// `layer_kinds_singular_support_singleton_support_is_true` on
// the layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(!slice.file_formats_full_cover());
}
#[test]
fn file_formats_singular_support_sample_chain_is_true() {
// Cross-sub-axis divergence witness: `sample_chain()` observes
// {Yaml} on the file-format sub-axis (only its two `.yaml`
// file layers project to a `Some(Format)`; the Env layer
// projects to `None`), so `file_formats_singular_support`
// reads `true` — even though on the layer-kind sub-axis
// `layer_kinds_singular_support` reads `false` (support size
// is 2 = {Env, File}). Direct fixture witness of the file-
// format sub-axis's strictly-wider singleton-support boundary
// (the file-format sub-axis routes only through
// `ConfigSource::File` entries with recognized extensions),
// matching the cross-sub-axis divergence documented on the
// impl.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(!slice.layer_kinds_singular_support());
}
#[test]
fn file_formats_singular_support_uniform_cover_is_false() {
// Uniform-cover pin: every format contributes one file layer,
// so the support is the full four-cell axis —
// `file_formats_singular_support` reads `false` (four, not
// one). The uniform four-format cover is on the `false` side
// of the singular-support boundary and on the `true` side of
// the other three coverage-support boundaries. Peer of
// `layer_kinds_singular_support_uniform_cover_is_false` on the
// layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(!slice.file_formats_singular_support());
assert!(slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(slice.file_formats_full_cover());
}
#[test]
fn file_formats_singular_support_two_format_partial_cover_is_false() {
// Two-format-cover pin: a chain observing Toml + Yaml but
// never Lisp / Nix (support size 2 out of 4) —
// `file_formats_singular_support` reads `false` (two, not
// one) even though `file_formats_any_observed` reads `true`.
// Direct witness of the strict subsumption
// `file_formats_singular_support ⇒
// file_formats_any_observed` on a fixture where the two
// boundaries split. Peer of
// `layer_kinds_singular_support_two_kind_partial_cover_is_false`
// on the layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(!slice.file_formats_singular_support());
assert!(slice.file_formats_any_observed());
}
#[test]
fn file_formats_singular_support_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_singular_support() ⇒
// file_formats_any_observed()` on every fixture — a chain with
// exactly one observed cell has at least one observed cell.
// The strict subsumption relates the singleton-support
// boundary and the any-observed boundary as strictly-tighter
// cardinality slices of the coverage-support partition (=1 ⇒
// ≥1). Peer of
// `layer_kinds_singular_support_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
slice.file_formats_any_observed(),
"singular-support chain must be any-observed",
);
}
}
}
#[test]
fn file_formats_singular_support_implies_file_formats_balanced_pointwise() {
// Subsumption pin: `file_formats_singular_support() ⇒
// file_formats_balanced()` on every fixture — a chain with
// exactly one observed count has a trivially uniform support
// (a single value is vacuously equal to itself), so the
// balanced predicate holds. Pins the interaction between the
// singular-support boundary and the uniformity boundary. Peer
// of `layer_kinds_singular_support_implies_layer_kinds_balanced_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
slice.file_formats_balanced(),
"singular-support chain must be balanced",
);
}
}
}
#[test]
fn file_formats_singular_support_implies_not_file_formats_full_cover_pointwise() {
// Disjointness pin: `file_formats_singular_support() ⇒
// !file_formats_full_cover()` on every fixture. A singleton
// support has cardinality 1; a full cover has cardinality
// `axis_cardinality::<crate::discovery::Format>()` (four).
// The two are disjoint on every axis with cardinality `>= 2`,
// which includes `crate::discovery::Format` (four cells).
// Direct witness that the two coverage-support boundaries are
// pairwise disjoint on the implementor set today. Peer of
// `layer_kinds_singular_support_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
!slice.file_formats_full_cover(),
"singular-support chain cannot be full-cover on \
a cardinality >= 2 axis",
);
}
}
}
#[test]
fn file_formats_singular_support_implies_layer_kind_file_count_positive_pointwise() {
// Cross-sub-axis lower-bound implication:
// `file_formats_singular_support() ⇒
// layer_kind_histogram().count(ConfigSourceKind::File) >= 1`.
// A chain with a singleton file-format support has at least
// one recognized-extension file layer, and every such layer is
// a `ConfigSource::File`. Cross-sub-axis divergence from
// `layer_kinds_singular_support_implies_chain_length_positive_pointwise`,
// which reads on the chain-length rather than the File-layer
// count — the file-format sub-axis carries the stronger
// implication because Defaults / Env / unrecognized-extension
// File layers don't contribute to the file-format histogram.
// Matches
// `file_formats_any_observed_implies_layer_kind_file_count_positive_pointwise`
// on the strictly-looser cardinality slice of the same
// coverage-support partition.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
slice.layer_kind_histogram().count(ConfigSourceKind::File) >= 1,
"singular-support chain must have >= 1 File layer (was {})",
slice.layer_kind_histogram().count(ConfigSourceKind::File),
);
}
}
}
#[test]
fn file_formats_singular_support_implies_dominant_equals_recessive_pointwise() {
// Modal-collapse pin: `file_formats_singular_support() ⇒
// dominant_file_format() == recessive_file_format() &&
// dominant_file_format().is_some()`. When support is singular,
// the modal pair collapses to the one observed cell on both
// sides. Direct witness of the trait-uniform
// `has_singular_support() ⇒ dominant_cell() == recessive_cell()`
// law on AxisHistogram, lifted to the file-format sub-axis of
// the chain altitude. Peer of
// `layer_kinds_singular_support_implies_dominant_equals_recessive_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
let dom = slice.dominant_file_format();
let rec = slice.recessive_file_format();
assert!(
dom.is_some(),
"singular-support chain must have Some dominant file format",
);
assert_eq!(
dom, rec,
"singular-support chain must have dominant == recessive",
);
}
}
}
#[test]
fn file_formats_any_observed_negation_implies_not_file_formats_singular_support_pointwise() {
// Contrapositive: `!file_formats_any_observed() ⇒
// !file_formats_singular_support()`. If no cell was observed,
// the support is empty (cardinality 0), which is strictly less
// than 1 — the singleton-support predicate fails. Pins the
// strictly-tighter cardinality relation between the two
// coverage-support boundaries. Peer of
// `layer_kinds_any_observed_negation_implies_not_layer_kinds_singular_support_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if !slice.file_formats_any_observed() {
assert!(
!slice.file_formats_singular_support(),
"empty-support chain cannot be singular-support",
);
}
}
}
#[test]
fn file_formats_singular_support_agrees_with_open_coded_exactly_one_positive_walk() {
// Parity against the exact hand-rolled singular-support walk
// this lift replaces: walk every cell of the histogram and
// count how many carry a positive count; the singleton-
// support predicate reads `true` iff exactly one cell is
// positive. Mirrors the parity pin
// `layer_kinds_singular_support_agrees_with_open_coded_exactly_one_positive_walk`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular_support();
let hist = slice.file_format_histogram();
let hand_rolled = hist.iter().filter(|(_, c)| *c > 0).count() == 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::file_formats_singular_gap — singleton-gap-
// file-formats boolean predicate on the file-format sub-axis of
// the chain altitude, lifting has_singular_gap sideways from the
// layer-kind sub-axis and continuing the "singleton-gap across
// altitudes" projection ----
#[test]
fn file_formats_singular_gap_matches_file_format_histogram_has_singular_gap_pointwise() {
// Routing pin: `file_formats_singular_gap` routes through
// `file_format_histogram().has_singular_gap()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops projecting
// through the shared cube-native primitive. File-format sub-
// axis peer of
// `layer_kinds_singular_gap_matches_layer_kind_histogram_has_singular_gap_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_gap_matches_tier_histogram_has_singular_gap_pointwise`
// on the tier altitude, and
// `kinds_singular_gap_matches_kind_histogram_has_singular_gap_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().has_singular_gap();
assert_eq!(slice.file_formats_singular_gap(), via_histogram);
}
}
#[test]
fn file_formats_singular_gap_agrees_with_absent_file_formats_count_equals_one_pointwise() {
// Coverage-gap-scalar surface: `file_formats_singular_gap() ==
// (absent_file_formats_count() == 1)` on every fixture. The
// coverage-gap-side scalar surfacing of the same boolean,
// without allocating the `Vec<crate::discovery::Format>`. Peer
// of
// `layer_kinds_singular_gap_agrees_with_absent_layer_kinds_count_equals_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular_gap();
let via_gap_scalar = slice.absent_file_formats_count() == 1;
assert_eq!(
via_seam,
via_gap_scalar,
"file_formats_singular_gap ({via_seam}) must agree with \
absent_file_formats_count == 1 (gap={g}) for chain",
g = slice.absent_file_formats_count(),
);
}
}
#[test]
fn file_formats_singular_gap_agrees_with_absent_file_formats_len_equals_one_pointwise() {
// Coverage-gap-`Vec` form: `file_formats_singular_gap() ==
// (absent_file_formats().len() == 1)` on every fixture. Pins
// the predicate against the `Vec<crate::discovery::Format>`
// length form consumers reach for when they already hold the
// coverage-gap vector. Peer of
// `layer_kinds_singular_gap_agrees_with_absent_layer_kinds_len_equals_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular_gap();
let via_vec = slice.absent_file_formats().len() == 1;
assert_eq!(
via_seam, via_vec,
"file_formats_singular_gap ({via_seam}) must agree with \
absent_file_formats().len() == 1 ({via_vec}) for chain",
);
}
}
#[test]
fn file_formats_singular_gap_agrees_with_present_file_formats_count_equals_axis_cardinality_minus_one_pointwise()
{
// Support-scalar form: `file_formats_singular_gap() ==
// (present_file_formats_count() ==
// axis_cardinality::<crate::discovery::Format>() - 1)` on every
// fixture. The support-side surfacing of the same boolean — a
// singleton-gap chain observes `axis_cardinality - 1` cells and
// misses one. Peer of
// `layer_kinds_singular_gap_agrees_with_present_layer_kinds_count_equals_axis_cardinality_minus_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular_gap();
let via_support_scalar = slice.present_file_formats_count()
== crate::axis_cardinality::<crate::discovery::Format>() - 1;
assert_eq!(
via_seam,
via_support_scalar,
"file_formats_singular_gap ({via_seam}) must agree with \
present_file_formats_count == axis_cardinality - 1 (count={c}) for chain",
c = slice.present_file_formats_count(),
);
}
}
#[test]
fn file_formats_singular_gap_agrees_with_present_file_formats_len_equals_axis_cardinality_minus_one_pointwise()
{
// Support-`Vec` form: `file_formats_singular_gap() ==
// (present_file_formats().len() ==
// axis_cardinality::<crate::discovery::Format>() - 1)` on every
// fixture. Pins the predicate against the
// `Vec<crate::discovery::Format>` length form consumers reach
// for when they already hold the support vector. Peer of
// `layer_kinds_singular_gap_agrees_with_present_layer_kinds_len_equals_axis_cardinality_minus_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular_gap();
let via_support_vec = slice.present_file_formats().len()
== crate::axis_cardinality::<crate::discovery::Format>() - 1;
assert_eq!(
via_seam, via_support_vec,
"file_formats_singular_gap ({via_seam}) must agree with \
present_file_formats().len() == axis_cardinality - 1 ({via_support_vec}) for chain",
);
}
}
#[test]
fn file_formats_singular_gap_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has every cell
// unobserved (four, not one), so the singular-gap predicate
// reads `false`. Matches `has_singular_gap` reading `false` on
// the empty histogram one altitude down. Peer of
// `file_formats_any_observed_empty_chain_is_false`,
// `file_formats_full_cover_empty_chain_is_false`, and
// `file_formats_singular_support_empty_chain_is_false` on the
// same polarity of the coverage-support partition, and
// orthogonal to `file_formats_balanced_empty_chain_is_true` on
// the opposite polarity — the five boundaries partition the
// empty chain into the polarity quintuple
// (`any_observed`=false, `singular_support`=false,
// `singular_gap`=false, `balanced`=true, `full_cover`=false).
// Peer of `layer_kinds_singular_gap_empty_chain_is_false` on
// the layer-kind sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_singular_gap());
assert!(!empty.file_formats_any_observed());
assert!(empty.file_formats_balanced());
assert!(!empty.file_formats_full_cover());
assert!(!empty.file_formats_singular_support());
}
#[test]
fn file_formats_singular_gap_no_recognized_files_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_singular_gap_empty_chain_is_false`: on the file-
// format sub-axis the *non-empty-chain / empty-histogram*
// boundary ALSO reads `false`. A chain of only Defaults / Env
// / unrecognized-extension File layers is non-empty but has an
// empty file-format histogram, so every cell is unobserved (all
// four, not one) and the singular-gap predicate reads `false`.
// Matches `file_formats_any_observed_no_recognized_files_is_false`,
// `file_formats_full_cover_no_recognized_files_is_false`, and
// `file_formats_singular_support_no_recognized_files_is_false`
// on the same-shape fixtures (all four read `false` on empty-
// histogram non-empty chains). Distinguishing pin against
// `file_formats_balanced` on the exact same fixtures (where
// the vacuous-uniformity boundary reads `true`).
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert!(!slice.file_formats_singular_gap());
assert!(!slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(!slice.file_formats_full_cover());
assert!(!slice.file_formats_singular_support());
}
}
#[test]
fn file_formats_singular_gap_singleton_support_is_false() {
// Singleton-support pin: every recognized-extension file layer
// lands on the same format, so three cells are unobserved on
// the four-cell axis (not one) — `file_formats_singular_gap`
// reads `false`. The row this predicate isolates from the
// singleton-support boundary two cardinality slices over: the
// strict disjointness `file_formats_singular_gap ⇒
// !file_formats_singular_support` (adjacent support
// cardinalities `1` vs. `3` on this axis). Peer of
// `layer_kinds_singular_gap_singleton_support_is_false` on the
// layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(!slice.file_formats_singular_gap());
assert!(slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(!slice.file_formats_full_cover());
}
#[test]
fn file_formats_singular_gap_three_format_partial_cover_is_true() {
// Three-format-cover pin: a chain observing Yaml + Toml + Lisp
// but never Nix (support size 3 out of 4) —
// `file_formats_singular_gap` reads `true`. The row this
// predicate isolates from the surrounding boundaries: direct
// witness of the strict subsumption `file_formats_singular_gap
// ⇒ file_formats_any_observed` and the disjointness
// `file_formats_singular_gap ⇒ !file_formats_full_cover` on
// the same fixture. Peer of
// `layer_kinds_singular_gap_two_kind_partial_cover_is_true` on
// the layer-kind sub-axis one sub-axis over (a cardinality-3
// axis whose singleton-gap boundary lands on support size 2).
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert_eq!(slice.absent_file_formats().len(), 1);
assert!(slice.file_formats_singular_gap());
assert!(slice.file_formats_any_observed());
assert!(!slice.file_formats_singular_support());
assert!(!slice.file_formats_full_cover());
}
#[test]
fn file_formats_singular_gap_uniform_cover_is_false() {
// Uniform-cover pin: every format contributes one file layer,
// so zero cells are unobserved (not one) —
// `file_formats_singular_gap` reads `false`. The uniform four-
// format cover is on the `false` side of the singular-gap
// boundary and on the `true` side of `full_cover` — the two
// boundaries are disjoint at the top of the coverage-support
// partition (adjacent support cardinalities `axis_cardinality
// - 1` and `axis_cardinality`). Peer of
// `layer_kinds_singular_gap_uniform_cover_is_false` on the
// layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(!slice.file_formats_singular_gap());
assert!(slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(slice.file_formats_full_cover());
assert!(!slice.file_formats_singular_support());
}
#[test]
fn file_formats_singular_gap_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_singular_gap() ⇒
// file_formats_any_observed()` on every fixture — a chain
// missing exactly one cell observes at least
// `axis_cardinality - 1 >= 1` cells (Format carries four
// cells). The strict subsumption relates the singleton-gap
// boundary and the any-observed boundary as strictly-tighter
// cardinality slices of the coverage-support partition
// (=axis_cardinality - 1 ⇒ ≥1). Peer of
// `layer_kinds_singular_gap_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_gap() {
assert!(
slice.file_formats_any_observed(),
"singular-gap chain must be any-observed",
);
}
}
}
#[test]
fn file_formats_singular_gap_implies_not_file_formats_full_cover_pointwise() {
// Disjointness pin: `file_formats_singular_gap() ⇒
// !file_formats_full_cover()` on every fixture. Full cover has
// zero unobserved cells; singular gap has exactly one — the two
// boundaries are disjoint on every axis. Peer of
// `layer_kinds_singular_gap_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_gap() {
assert!(
!slice.file_formats_full_cover(),
"singular-gap chain cannot be full-cover",
);
}
}
}
#[test]
fn file_formats_singular_gap_implies_not_file_formats_singular_support_pointwise() {
// Disjointness pin: `file_formats_singular_gap() ⇒
// !file_formats_singular_support()` on every fixture. On the
// four-cell [`crate::discovery::Format`] axis, singleton-
// support has support cardinality `1` and singleton-gap has
// support cardinality `axis_cardinality - 1 = 3`, so the two
// are disjoint. Direct witness of the strict disjointness
// between the two coverage-support boundary predicates on a
// cardinality-≥3 axis. Peer of
// `layer_kinds_singular_gap_implies_not_layer_kinds_singular_support_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_gap() {
assert!(
!slice.file_formats_singular_support(),
"singular-gap chain cannot be singular-support on \
a cardinality >= 3 axis",
);
}
}
}
#[test]
fn file_formats_singular_gap_implies_layer_kind_file_count_at_least_axis_cardinality_minus_one_pointwise()
{
// Cross-sub-axis lower-bound implication:
// `file_formats_singular_gap() ⇒
// layer_kind_histogram().count(ConfigSourceKind::File) >=
// axis_cardinality::<crate::discovery::Format>() - 1`. A chain
// with a singleton file-format gap observes at least
// `axis_cardinality - 1` recognized-extension file layers, one
// for each observed cell, and every such layer is a
// `ConfigSource::File`. Cross-sub-axis divergence from
// `layer_kinds_singular_gap_implies_chain_length_at_least_axis_cardinality_minus_one_pointwise`,
// which reads on the chain-length rather than the File-layer
// count — the file-format sub-axis carries the stronger
// implication because Defaults / Env / unrecognized-extension
// File layers don't contribute to the file-format histogram.
// Matches the same divergence pattern between
// `file_formats_singular_support_implies_layer_kind_file_count_positive_pointwise`
// and `layer_kinds_singular_support_implies_chain_length_positive_pointwise`
// on the complementary cardinality slice.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_gap() {
let file_count = slice.layer_kind_histogram().count(ConfigSourceKind::File);
let lower_bound = crate::axis_cardinality::<crate::discovery::Format>() - 1;
assert!(
file_count >= lower_bound,
"singular-gap chain must have >= {lower_bound} File layers (was {file_count})",
);
}
}
}
#[test]
fn file_formats_any_observed_negation_implies_not_file_formats_singular_gap_pointwise() {
// Contrapositive: `!file_formats_any_observed() ⇒
// !file_formats_singular_gap()` on every axis with cardinality
// `>= 2`. If no cell was observed, the coverage gap has size
// `axis_cardinality > 1`, so the singleton-gap predicate fails.
// Pins the strictly-looser cardinality relation between the
// two coverage-support boundaries in the negative direction.
// Peer of
// `layer_kinds_any_observed_negation_implies_not_layer_kinds_singular_gap_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if !slice.file_formats_any_observed() {
assert!(
!slice.file_formats_singular_gap(),
"empty-support chain cannot be singular-gap on a \
cardinality >= 2 axis",
);
}
}
}
#[test]
fn file_formats_singular_gap_agrees_with_open_coded_exactly_one_zero_walk() {
// Parity against the exact hand-rolled singular-gap walk this
// lift replaces: walk every cell of the histogram and count
// how many carry a zero count; the singleton-gap predicate
// reads `true` iff exactly one cell is zero. Mirrors the parity
// pin
// `layer_kinds_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the layer-kind sub-axis,
// `tiers_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the tier altitude, and
// `kinds_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular_gap();
let hist = slice.file_format_histogram();
let hand_rolled = hist.iter().filter(|(_, c)| *c == 0).count() == 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::file_formats_strict_partial_cover —
// strict-partial-cover-file-formats boolean predicate on the
// file-format sub-axis of the chain altitude, lifting the
// "strict-partial-cover across altitudes" projection sideways
// from the layer-kind sub-axis
// (`ConfigSourceChain::layer_kinds_strict_partial_cover`) into
// the second chain sub-axis. Routed through the shared
// `AxisHistogram::has_strict_partial_cover` primitive one
// altitude down. Cardinality-`4` `crate::discovery::Format` axis
// is the *first* non-vacuously-`false` corner in the projection
// — the strict interior fires at support cardinality `2` (two
// observed cells, two unobserved cells). ----
#[test]
fn file_formats_strict_partial_cover_matches_file_format_histogram_has_strict_partial_cover_pointwise()
{
// Routing pin: `file_formats_strict_partial_cover` routes through
// `file_format_histogram().has_strict_partial_cover()`, so the
// two seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. File-
// format sub-axis peer of
// `layer_kinds_strict_partial_cover_matches_layer_kind_histogram_has_strict_partial_cover_pointwise`
// on the layer-kind sub-axis,
// `tiers_strict_partial_cover_matches_tier_histogram_has_strict_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_strict_partial_cover_matches_kind_histogram_has_strict_partial_cover_pointwise`
// on the diff altitude, in the "strict-partial-cover across
// altitudes" projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().has_strict_partial_cover();
assert_eq!(slice.file_formats_strict_partial_cover(), via_histogram);
}
}
#[test]
fn file_formats_strict_partial_cover_matches_structural_conjunction_pointwise() {
// Defining structural-conjunction form:
// `file_formats_strict_partial_cover() ⇔
// file_format_histogram().has_partial_cover() &&
// !file_formats_singular_support() &&
// !file_formats_singular_gap()` on every fixture. Pins the
// predicate against the three-way conjunction on the existing
// named-boundary triad consumers reach for when they open-code
// the strict interior in structural terms. Peer of
// `layer_kinds_strict_partial_cover_matches_structural_conjunction_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_strict_partial_cover();
let via_structural = slice.file_format_histogram().has_partial_cover()
&& !slice.file_formats_singular_support()
&& !slice.file_formats_singular_gap();
assert_eq!(
via_seam, via_structural,
"file_formats_strict_partial_cover ({via_seam}) must agree with \
has_partial_cover && !singular_support && !singular_gap ({via_structural})",
);
}
}
#[test]
fn file_formats_strict_partial_cover_agrees_with_present_file_formats_count_strict_interval_pointwise()
{
// Support-scalar strict-interval form:
// `file_formats_strict_partial_cover() == (1 <
// present_file_formats_count() && present_file_formats_count() +
// 1 < axis_cardinality::<crate::discovery::Format>())` on every
// fixture. The support-side surfacing of the same boolean,
// without allocating the `Vec<crate::discovery::Format>`. Peer of
// `layer_kinds_strict_partial_cover_agrees_with_present_layer_kinds_count_strict_interval_pointwise`
// on the layer-kind sub-axis and
// `tiers_strict_partial_cover_agrees_with_contributing_tiers_count_strict_interval_pointwise`
// on the tier altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_strict_partial_cover();
let count = slice.present_file_formats_count();
let via_interval =
1 < count && count + 1 < crate::axis_cardinality::<crate::discovery::Format>();
assert_eq!(
via_seam, via_interval,
"file_formats_strict_partial_cover ({via_seam}) must agree with \
1 < present_file_formats_count && present_file_formats_count + 1 < axis_cardinality \
(count={count})",
);
}
}
#[test]
fn file_formats_strict_partial_cover_agrees_with_absent_file_formats_count_strict_interval_pointwise()
{
// Coverage-gap-scalar strict-interval form:
// `file_formats_strict_partial_cover() == (1 <
// absent_file_formats_count() && absent_file_formats_count() + 1
// < axis_cardinality::<crate::discovery::Format>())` on every
// fixture. The coverage-gap-side surfacing of the same boolean,
// without allocating the `Vec<crate::discovery::Format>`.
// Complementary to the support-scalar strict-interval form on the
// same partition via the `present_file_formats_count +
// absent_file_formats_count == axis_cardinality` invariant. Peer
// of
// `layer_kinds_strict_partial_cover_agrees_with_absent_layer_kinds_count_strict_interval_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_strict_partial_cover();
let gap = slice.absent_file_formats_count();
let via_interval =
1 < gap && gap + 1 < crate::axis_cardinality::<crate::discovery::Format>();
assert_eq!(
via_seam, via_interval,
"file_formats_strict_partial_cover ({via_seam}) must agree with \
1 < absent_file_formats_count && absent_file_formats_count + 1 < axis_cardinality \
(gap={gap})",
);
}
}
#[test]
fn file_formats_strict_partial_cover_agrees_with_dual_vec_at_least_two_of_each_pointwise() {
// Dual-`Vec` at-least-two-of-each form:
// `file_formats_strict_partial_cover() ==
// (present_file_formats().len() >= 2 &&
// absent_file_formats().len() >= 2)` on every fixture. Pins the
// predicate against the dual-vector form consumers reach for when
// they already hold both support and coverage-gap vectors — the
// allocating-both-vectors open-coding this lift replaces. Peer of
// `layer_kinds_strict_partial_cover_agrees_with_dual_vec_at_least_two_of_each_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_strict_partial_cover();
let via_vec =
slice.present_file_formats().len() >= 2 && slice.absent_file_formats().len() >= 2;
assert_eq!(
via_seam, via_vec,
"file_formats_strict_partial_cover ({via_seam}) must agree with \
present_file_formats().len() >= 2 && absent_file_formats().len() >= 2 ({via_vec})",
);
}
}
#[test]
fn file_formats_strict_partial_cover_empty_chain_is_false() {
// Empty-chain boundary: the empty chain observes zero cells, so
// the "at least two observed" half of the conjunction fails
// uniformly — `file_formats_strict_partial_cover` reads `false`.
// Matches `has_strict_partial_cover` reading `false` on the
// empty histogram one altitude down. Peer of
// `file_formats_any_observed_empty_chain_is_false`,
// `file_formats_full_cover_empty_chain_is_false`,
// `file_formats_singular_support_empty_chain_is_false`, and
// `file_formats_singular_gap_empty_chain_is_false` on the same
// polarity of the coverage-support partition. Peer of
// `layer_kinds_strict_partial_cover_empty_chain_is_false` on the
// layer-kind sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_strict_partial_cover());
assert!(!empty.file_formats_any_observed());
assert!(!empty.file_formats_singular_support());
assert!(!empty.file_formats_singular_gap());
assert!(!empty.file_formats_full_cover());
}
#[test]
fn file_formats_strict_partial_cover_no_recognized_files_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_strict_partial_cover_empty_chain_is_false`: on the
// file-format sub-axis the *non-empty-chain / empty-histogram*
// boundary ALSO reads `false`. A chain of only Defaults / Env /
// unrecognized-extension File layers is non-empty but has an
// empty file-format histogram, so zero cells are observed and
// the "at least two observed" half fails uniformly. Matches
// `file_formats_any_observed_no_recognized_files_is_false`,
// `file_formats_full_cover_no_recognized_files_is_false`,
// `file_formats_singular_support_no_recognized_files_is_false`,
// and `file_formats_singular_gap_no_recognized_files_is_false`
// on the same-shape fixtures.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert!(!slice.file_formats_strict_partial_cover());
assert!(!slice.file_formats_any_observed());
assert!(slice.file_formats_balanced());
assert!(!slice.file_formats_full_cover());
assert!(!slice.file_formats_singular_support());
assert!(!slice.file_formats_singular_gap());
}
}
#[test]
fn file_formats_strict_partial_cover_singleton_support_is_false() {
// Singleton-support pin: every recognized-extension file layer
// lands on the same format, so the support cardinality is `1`
// (not `>= 2`) — the "at least two observed" half fails
// uniformly. Direct witness of the strict disjointness
// `file_formats_singular_support ⇒
// !file_formats_strict_partial_cover`. Peer of
// `layer_kinds_strict_partial_cover_singleton_support_is_false`
// on the layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(!slice.file_formats_strict_partial_cover());
}
#[test]
fn file_formats_strict_partial_cover_two_format_partial_cover_is_true() {
// Reachable-corner witness on the cardinality-`4`
// `crate::discovery::Format` axis — the *first* non-vacuously-
// `false` corner in the "strict-partial-cover across altitudes"
// projection: two observed cells (Yaml + Toml) and two
// unobserved cells (Lisp + Nix), exactly the strict-interior
// boundary at support cardinality `2`. `file_formats_strict_partial_cover`
// reads `true` on this fixture. Cross-sub-axis divergence pin
// against
// `layer_kinds_strict_partial_cover_two_kind_partial_cover_is_false`
// (cardinality-`3` axis where the two-kind partial cover reads
// `false` because the coverage gap is `1`, not `>= 2`). Peer of
// `tiers_strict_partial_cover_two_tier_partial_cover_is_true` on
// the tier altitude — the other cardinality-`4` axis in the
// projection where the strict interior is reachable.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert_eq!(slice.absent_file_formats().len(), 2);
assert!(slice.file_formats_strict_partial_cover());
assert!(slice.file_formats_any_observed());
assert!(!slice.file_formats_singular_support());
assert!(!slice.file_formats_singular_gap());
assert!(!slice.file_formats_full_cover());
}
#[test]
fn file_formats_strict_partial_cover_sample_chain_two_format_witness_is_true() {
// Sample-fixture witness lifted from the standing
// `recessive_file_format_fixtures` set: the `{2 x .toml + 1 x
// .yaml}` chain observes exactly two cells (Yaml + Toml) and
// misses two cells (Lisp + Nix) on the four-cell
// `crate::discovery::Format` axis — the strict interior fires
// even when the two observed cells carry uneven per-format
// counts (not just the balanced two-format cover). Pins the
// predicate against the standing fixture set to catch any future
// implementation that would erroneously exclude uneven-count
// two-format chains from the strict-interior corner.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert_eq!(slice.absent_file_formats().len(), 2);
assert!(slice.file_formats_strict_partial_cover());
}
#[test]
fn file_formats_strict_partial_cover_three_format_partial_cover_is_false() {
// Three-format partial-cover pin: a chain observing Yaml + Toml
// + Lisp but never Nix (support size 3 out of 4, coverage gap
// `1`) — the "at least two unobserved" half fails uniformly and
// `file_formats_strict_partial_cover` reads `false`. Direct
// witness of the strict disjointness `file_formats_singular_gap
// ⇒ !file_formats_strict_partial_cover` on the cardinality-`4`
// `crate::discovery::Format` axis (adjacent support cardinalities
// `3` and `[2, 2]` never overlap).
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert_eq!(slice.absent_file_formats().len(), 1);
assert!(slice.file_formats_singular_gap());
assert!(!slice.file_formats_strict_partial_cover());
}
#[test]
fn file_formats_strict_partial_cover_uniform_cover_is_false() {
// Uniform-cover pin: every format contributes at least one file
// layer, so zero cells are unobserved — the "at least two
// unobserved" half fails uniformly. Direct witness of the strict
// disjointness `file_formats_full_cover ⇒
// !file_formats_strict_partial_cover` on every axis. Peer of
// `layer_kinds_strict_partial_cover_uniform_cover_is_false` on
// the layer-kind sub-axis and
// `tiers_strict_partial_cover_uniform_cover_is_false` on the
// tier altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_formats_full_cover());
assert!(!slice.file_formats_strict_partial_cover());
}
#[test]
fn file_formats_strict_partial_cover_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_strict_partial_cover() ⇒
// file_formats_any_observed()` on every fixture. On the
// cardinality-`4` `crate::discovery::Format` axis the antecedent
// fires at support cardinality `2`, which is `>= 1` — so the
// implication holds non-vacuously (unlike the cardinality-`3`
// layer-kind sub-axis where the antecedent never fires and the
// implication holds vacuously). Peer of
// `layer_kinds_strict_partial_cover_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_strict_partial_cover() {
assert!(
slice.file_formats_any_observed(),
"strict-partial-cover chain must be any-observed",
);
}
}
}
#[test]
fn file_formats_strict_partial_cover_implies_not_file_formats_singular_support_pointwise() {
// Disjointness pin: `file_formats_strict_partial_cover() ⇒
// !file_formats_singular_support()` on every fixture. A strict-
// interior chain has `>= 2` observed cells; a singleton support
// has exactly `1`. Peer of
// `layer_kinds_strict_partial_cover_implies_not_layer_kinds_singular_support_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_strict_partial_cover() {
assert!(
!slice.file_formats_singular_support(),
"strict-partial-cover chain cannot be singular-support",
);
}
}
}
#[test]
fn file_formats_strict_partial_cover_implies_not_file_formats_singular_gap_pointwise() {
// Disjointness pin: `file_formats_strict_partial_cover() ⇒
// !file_formats_singular_gap()` on every fixture. A strict-
// interior chain has `>= 2` unobserved cells; a singleton gap
// has exactly `1`. Peer of
// `layer_kinds_strict_partial_cover_implies_not_layer_kinds_singular_gap_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_strict_partial_cover() {
assert!(
!slice.file_formats_singular_gap(),
"strict-partial-cover chain cannot be singular-gap",
);
}
}
}
#[test]
fn file_formats_strict_partial_cover_implies_not_file_formats_full_cover_pointwise() {
// Disjointness pin: `file_formats_strict_partial_cover() ⇒
// !file_formats_full_cover()` on every fixture. A strict-
// interior chain has `>= 2` unobserved cells; a full cover has
// zero. Peer of
// `layer_kinds_strict_partial_cover_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_strict_partial_cover() {
assert!(
!slice.file_formats_full_cover(),
"strict-partial-cover chain cannot be full-cover",
);
}
}
}
#[test]
fn file_formats_strict_partial_cover_implies_layer_kind_file_count_at_least_two_pointwise() {
// Cross-sub-axis lower-bound implication:
// `file_formats_strict_partial_cover() ⇒
// layer_kind_histogram().count(ConfigSourceKind::File) >= 2`. A
// chain with `>= 2` observed file-format cells has at least `2`
// recognized-extension file layers, one for each observed cell,
// and every such layer is a `ConfigSource::File`. Cross-sub-axis
// divergence pin against
// `layer_kinds_strict_partial_cover_chain_altitude_is_vacuously_false_pointwise`:
// on the cardinality-`3` layer-kind sub-axis the antecedent
// never fires so no implication carries witnesses; the file-
// format sub-axis is the *first* non-vacuously-`false` corner
// of the projection where cross-sub-axis lower-bound implications
// actually carry witnesses.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_strict_partial_cover() {
let file_count = slice.layer_kind_histogram().count(ConfigSourceKind::File);
assert!(
file_count >= 2,
"strict-partial-cover chain must have >= 2 File layers (was {file_count})",
);
}
}
}
#[test]
fn file_formats_any_observed_negation_implies_not_file_formats_strict_partial_cover_pointwise()
{
// Contrapositive: `!file_formats_any_observed() ⇒
// !file_formats_strict_partial_cover()` on every fixture. If no
// cell was observed, the "at least two observed" half of the
// conjunction fails uniformly — the strict-interior predicate
// fails. Peer of
// `layer_kinds_any_observed_negation_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if !slice.file_formats_any_observed() {
assert!(
!slice.file_formats_strict_partial_cover(),
"empty-support chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn file_formats_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk() {
// Parity against the exact hand-rolled strict-partial-cover walk
// this lift replaces: walk every cell of the histogram and count
// how many carry a zero count and how many carry a positive
// count; the strict-partial-cover predicate reads `true` iff at
// least two cells are zero AND at least two cells are positive.
// On the cardinality-`4` `crate::discovery::Format` axis this is
// reachable at support cardinality `2` (two positives, two
// zeros). Peer of
// `layer_kinds_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk`
// on the layer-kind sub-axis and
// `tiers_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk`
// on the tier altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_strict_partial_cover();
let hist = slice.file_format_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros >= 2 && nonzeros >= 2;
assert_eq!(via_seam, hand_rolled);
}
}
#[test]
fn file_formats_partition_covers_every_chain_pointwise() {
// Trichotomy closure pin at the chain file-format sub-axis:
// exactly one of `(!file_formats_any_observed,
// file_formats_singular_support,
// file_formats_strict_partial_cover, file_formats_singular_gap,
// file_formats_full_cover)` fires per chain on every axis with
// cardinality `>= 3`. With this lift the 5-corner support-
// cardinality partition is jointly exhaustive AND pairwise
// disjoint on every chain fixture on the cardinality-`4`
// `crate::discovery::Format` axis — every chain fires exactly
// one of the five corners. Peer of
// `layer_kinds_partition_covers_every_chain_pointwise` on the
// layer-kind sub-axis (where the strict-interior corner is
// structurally empty by cardinality-`3` reachability so the
// partition collapses to four active corners) and
// `tiers_partition_covers_every_map_pointwise` /
// `kinds_partition_covers_every_diff_pointwise` on the peer
// altitudes.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let empty = !slice.file_formats_any_observed();
let sup = slice.file_formats_singular_support();
let strict = slice.file_formats_strict_partial_cover();
let gap = slice.file_formats_singular_gap();
let full = slice.file_formats_full_cover();
let fires =
u8::from(empty) + u8::from(sup) + u8::from(strict) + u8::from(gap) + u8::from(full);
assert_eq!(
fires, 1,
"exactly one of (empty, singular_support, strict_partial_cover, \
singular_gap, full_cover) must fire per chain — observed {fires}",
);
}
}
// ---- ConfigSourceChain::file_formats_low_support — low-support-file-
// formats boolean predicate on the file-format sub-axis of the
// chain altitude, lifting `has_low_support` from the histogram
// surface sideways from the layer-kind sub-axis
// (`layer_kinds_low_support`) into the second chain sub-axis.
// Routed through the shared `AxisHistogram::has_low_support`
// primitive one altitude down. Non-vacuous on the cardinality-`4`
// `crate::discovery::Format` axis: the empty chain, every non-
// empty chain with an empty file-format histogram, and every
// singleton-support chain read `true`; every two-or-more-cell-
// cover chain reads `false`. First non-vacuous witness of the
// strict-interior disjointness on the chain altitude — the two-
// format partial cover fixture reads `strict_partial_cover=true,
// low_support=false`, unavailable at the layer-kind sub-axis. ----
#[test]
fn file_formats_low_support_matches_file_format_histogram_has_low_support_pointwise() {
// Routing pin: `file_formats_low_support` routes through
// `file_format_histogram().has_low_support()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops projecting
// through the shared cube-native primitive. File-format sub-
// axis peer of
// `layer_kinds_low_support_matches_layer_kind_histogram_has_low_support_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_low_support_matches_tier_histogram_has_low_support_pointwise`
// on the tier altitude, and
// `kinds_low_support_matches_kind_histogram_has_low_support_pointwise`
// on the diff altitude, in the "low-support across altitudes"
// projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().has_low_support();
assert_eq!(slice.file_formats_low_support(), via_histogram);
}
}
#[test]
fn file_formats_low_support_matches_defining_union_of_low_boundaries_pointwise() {
// Defining-union-of-low-boundaries disjunction:
// `file_formats_low_support() ⇔ !file_formats_any_observed()
// || file_formats_singular_support()` on every fixture. Pins
// the predicate against the two-way disjunction on the two
// named histogram-side peers consumers reach for when they
// open-code the low-magnitude corner as "empty OR singleton-
// support". Peer of
// `layer_kinds_low_support_matches_defining_union_of_low_boundaries_pointwise`
// on the layer-kind sub-axis and
// `tiers_low_support_matches_defining_union_of_low_boundaries_pointwise`
// on the tier altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_low_support();
let via_disj =
!slice.file_formats_any_observed() || slice.file_formats_singular_support();
assert_eq!(
via_seam, via_disj,
"file_formats_low_support ({via_seam}) must agree with \
!file_formats_any_observed || file_formats_singular_support ({via_disj})",
);
}
}
#[test]
fn file_formats_low_support_agrees_with_present_file_formats_count_at_most_one_pointwise() {
// Support-scalar at-most-one form:
// `file_formats_low_support() == (present_file_formats_count()
// <= 1)` on every fixture. The support-side surfacing of the
// same boolean, without allocating the
// `Vec<crate::discovery::Format>`. Peer of
// `layer_kinds_low_support_agrees_with_present_layer_kinds_count_at_most_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_low_support();
let count = slice.present_file_formats_count();
assert_eq!(
via_seam,
count <= 1,
"file_formats_low_support ({via_seam}) must agree with \
present_file_formats_count() <= 1 (count={count})",
);
}
}
#[test]
fn file_formats_low_support_agrees_with_present_file_formats_len_at_most_one_pointwise() {
// Support-`Vec` at-most-one form:
// `file_formats_low_support() == (present_file_formats().len()
// <= 1)` on every fixture. Pins the predicate against the
// support-`Vec` form consumers reach for when they already
// hold the support vector — the allocating open-coding this
// lift replaces. Peer of
// `layer_kinds_low_support_agrees_with_present_layer_kinds_len_at_most_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_low_support();
let via_vec = slice.present_file_formats().len() <= 1;
assert_eq!(
via_seam, via_vec,
"file_formats_low_support ({via_seam}) must agree with \
present_file_formats().len() <= 1 ({via_vec})",
);
}
}
#[test]
fn file_formats_low_support_agrees_with_absent_file_formats_count_at_least_axis_cardinality_minus_one_pointwise()
{
// Coverage-gap-scalar at-least-axis-cardinality-minus-one
// form: `file_formats_low_support() ==
// (absent_file_formats_count() >=
// axis_cardinality::<Format>() - 1)` on every fixture. The
// coverage-gap-side surfacing of the same boolean via the
// `present + absent == axis_cardinality` invariant. Peer of
// `layer_kinds_low_support_agrees_with_absent_layer_kinds_count_at_least_axis_cardinality_minus_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_low_support();
let gap = slice.absent_file_formats_count();
let via_gap = gap >= crate::axis_cardinality::<crate::discovery::Format>() - 1;
assert_eq!(
via_seam, via_gap,
"file_formats_low_support ({via_seam}) must agree with \
absent_file_formats_count() >= axis_cardinality - 1 ({via_gap}, gap={gap})",
);
}
}
#[test]
fn file_formats_low_support_empty_chain_is_true() {
// Empty-chain boundary: zero observed cells satisfy the "at
// most one observed" clause vacuously —
// `file_formats_low_support` reads `true`. Matches
// `has_low_support` reading `true` on the empty histogram
// one altitude down. Diverges from
// `file_formats_any_observed`'s, `file_formats_full_cover`'s,
// `file_formats_singular_support`'s, and
// `file_formats_singular_gap`'s empty-chain `false` polarity
// — the low-support boundary strictly *includes* the empty
// chain by folding the "no observation" case into the low-
// magnitude corner. Peer of
// `layer_kinds_low_support_empty_chain_is_true` on the layer-
// kind sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.file_formats_low_support());
assert!(!empty.file_formats_any_observed());
assert!(!empty.file_formats_singular_support());
assert!(!empty.file_formats_singular_gap());
assert!(!empty.file_formats_full_cover());
assert!(!empty.file_formats_strict_partial_cover());
}
#[test]
fn file_formats_low_support_no_recognized_files_is_true() {
// Non-empty-chain / empty-histogram boundary the file-format
// sub-axis pins that the layer-kind sub-axis does *not*. A
// chain of only `Defaults` / `Env` / unrecognized-extension
// `File` layers is non-empty but has no `Some` file-format
// projection, so the histogram is empty and the "at most one
// observed" clause holds vacuously —
// `file_formats_low_support` reads `true`. Cross-sub-axis
// divergence pin against `layer_kinds_low_support`: on the
// same fixtures the layer-kind sub-axis observes at least
// one layer-kind cell (Defaults / Env / File) so the low-
// support corner is narrower there. Peer of
// `file_formats_any_observed_no_recognized_files_is_false`
// through negation.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(slice.file_format_histogram().is_empty());
assert!(!slice.file_formats_any_observed());
assert!(slice.file_formats_low_support());
}
}
#[test]
fn file_formats_low_support_singleton_support_is_true() {
// Singleton-support pin: `sample_chain()` observes only Yaml
// (two `.yaml` file layers + one Env layer), so the file-
// format support cardinality is `1` (at most `1`) —
// `file_formats_low_support` reads `true`. Direct witness of
// the subsumption `file_formats_singular_support ⇒
// file_formats_low_support`: every singleton-support chain
// lands on the low-magnitude corner by the union-of-low-
// boundaries disjunction. Peer of
// `layer_kinds_low_support_singleton_support_is_true` on the
// layer-kind sub-axis.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(slice.file_formats_low_support());
}
#[test]
fn file_formats_low_support_two_format_partial_cover_is_false() {
// Two-format-cover pin — the *first non-vacuous* strict-
// interior disjointness witness on the chain altitude. A
// chain observing exactly two file-format cells
// (`.yaml + .toml`) reads `strict_partial_cover=true` on the
// cardinality-`4` `crate::discovery::Format` axis; support
// cardinality `2` violates `<= 1`, so
// `file_formats_low_support` reads `false`. Direct witness
// of the disjointness `file_formats_strict_partial_cover ⇒
// !file_formats_low_support` — unavailable at the
// cardinality-`3` layer-kind sub-axis where the strict-
// interior antecedent is vacuous. Peer of
// `layer_kinds_low_support_two_kind_partial_cover_is_false`
// on the layer-kind sub-axis (which reads through
// `layer_kinds_singular_gap ⇒ !layer_kinds_low_support`
// instead — the same fixture cardinality `2` sits on the
// singular-gap boundary at cardinality-`3`, but on the
// strict-interior boundary at cardinality-`4`).
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(slice.file_format_histogram().count(Format::Yaml) > 0);
assert!(slice.file_format_histogram().count(Format::Toml) > 0);
assert!(slice.file_formats_strict_partial_cover());
assert!(!slice.file_formats_low_support());
}
#[test]
fn file_formats_low_support_three_format_partial_cover_is_false() {
// Three-format-cover pin: a chain observing exactly three
// file-format cells (`.yaml + .toml + .lisp`) sits at
// support cardinality `3` — one cell unobserved on the
// cardinality-`4` axis, exactly the singleton-gap boundary.
// Support cardinality `3` violates `<= 1`, so
// `file_formats_low_support` reads `false`. Direct witness
// of the disjointness `file_formats_singular_gap ⇒
// !file_formats_low_support` on the cardinality-`4` axis
// where the singleton-gap slice sits at support cardinality
// `axis_cardinality - 1 = 3`.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert!(slice.file_formats_singular_gap());
assert!(!slice.file_formats_low_support());
}
#[test]
fn file_formats_low_support_uniform_cover_is_false() {
// Uniform-cover pin: every file-format cell contributes at
// least one recognized-extension file layer, so the support
// cardinality is `4` (violates `<= 1`) —
// `file_formats_low_support` reads `false`. Direct witness
// of the disjointness `file_formats_full_cover ⇒
// !file_formats_low_support` on every cardinality-`>= 2`
// axis. Peer of `layer_kinds_low_support_uniform_cover_is_false`
// on the layer-kind sub-axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_formats_full_cover());
assert!(!slice.file_formats_low_support());
}
#[test]
fn file_formats_low_support_implies_not_file_formats_full_cover_pointwise() {
// Disjointness pin: `file_formats_low_support() ⇒
// !file_formats_full_cover()` on every axis with cardinality
// `>= 2`. Low support has size `<= 1`; full cover has size
// `axis_cardinality >= 2`. Peer of
// `layer_kinds_low_support_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_low_support() {
assert!(
!slice.file_formats_full_cover(),
"low-support chain cannot be full-cover",
);
}
}
}
#[test]
fn file_formats_low_support_implies_not_file_formats_singular_gap_pointwise() {
// Disjointness pin: `file_formats_low_support() ⇒
// !file_formats_singular_gap()` on every axis with
// cardinality `>= 3` (every implementor today —
// `crate::discovery::Format` carries four cells). Low
// support has size `<= 1`; singular-gap has support size
// `axis_cardinality - 1 >= 2`. Peer of
// `layer_kinds_low_support_implies_not_layer_kinds_singular_gap_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_low_support() {
assert!(
!slice.file_formats_singular_gap(),
"low-support chain cannot be singular-gap",
);
}
}
}
#[test]
fn file_formats_low_support_implies_not_file_formats_strict_partial_cover_pointwise() {
// Disjointness pin: `file_formats_low_support() ⇒
// !file_formats_strict_partial_cover()` always. The strict
// interior requires `>= 2` observed cells; low support has
// `<= 1`. On the cardinality-`4` `crate::discovery::Format`
// axis the antecedent is reachable AND the consequent is
// meaningfully constrained — the two-format partial cover
// fixture is a `strict_partial_cover=true, low_support=false`
// witness. Contrasts with
// `layer_kinds_low_support_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the cardinality-`3` layer-kind sub-axis where the same
// implication holds vacuously (the strict interior is
// unreachable). This lift carries the *first* non-vacuous
// strict-interior disjointness witness on the chain
// altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_low_support() {
assert!(
!slice.file_formats_strict_partial_cover(),
"low-support chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn file_formats_any_observed_negation_implies_file_formats_low_support_pointwise() {
// Subsumption pin: `!file_formats_any_observed() ⇒
// file_formats_low_support()` on every axis. If no cell was
// observed, the "at most one observed" clause holds
// vacuously. Peer of
// `layer_kinds_any_observed_negation_implies_layer_kinds_low_support_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if !slice.file_formats_any_observed() {
assert!(
slice.file_formats_low_support(),
"empty-support chain must be low-support",
);
}
}
}
#[test]
fn file_formats_singular_support_implies_file_formats_low_support_pointwise() {
// Subsumption pin: `file_formats_singular_support() ⇒
// file_formats_low_support()` on every axis. A singleton-
// support chain lands on the low-magnitude corner by the
// union-of-low-boundaries disjunction. Peer of
// `layer_kinds_singular_support_implies_layer_kinds_low_support_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
slice.file_formats_low_support(),
"singular-support chain must be low-support",
);
}
}
}
#[test]
fn file_formats_low_support_agrees_with_open_coded_at_most_one_positive_walk() {
// Parity against the exact hand-rolled at-most-one-positive
// walk this lift replaces: walk every cell of the histogram
// and count how many carry a positive count; the low-
// support predicate reads `true` iff at most one cell
// carries a positive count. Peer of
// `layer_kinds_low_support_agrees_with_open_coded_at_most_one_positive_walk`
// on the layer-kind sub-axis.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_low_support();
let hist = slice.file_format_histogram();
let positives = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = positives <= 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::file_formats_high_support —
// high-support-file-formats boolean predicate on the file-
// format sub-axis of the chain altitude, lifting the "high-
// support across altitudes" projection sideways from the
// layer-kind sub-axis (`layer_kinds_high_support`), the tier
// altitude (`ProvenanceMap::tiers_high_support`), and the
// diff altitude (`ConfigDiff::kinds_high_support`) into the
// second chain sub-axis. Routed through the shared
// `AxisHistogram::has_high_support` primitive one altitude
// down. Non-vacuous on the cardinality-`4`
// `crate::discovery::Format` axis: every three-format
// partial cover and every uniform four-format cover read
// `true`; the empty chain, every non-empty chain with an
// empty file-format histogram, every singleton-support
// chain, AND every two-format partial cover read `false`.
// First non-vacuous witness of the strict-interior
// disjointness on the chain altitude (via the two-format
// partial cover fixture: strict_partial_cover=true,
// high_support=false) — the magnitude-direction ternary
// closes strictly *and* non-vacuously at this sub-axis,
// matching the tier altitude and diverging from the
// degenerate two-way partition at the layer-kind sub-axis
// and the diff altitude. ----
#[test]
fn file_formats_high_support_matches_file_format_histogram_has_high_support_pointwise() {
// Routing pin: `file_formats_high_support` routes through
// `file_format_histogram().has_high_support()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive.
// File-format sub-axis peer of
// `layer_kinds_high_support_matches_layer_kind_histogram_has_high_support_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_matches_tier_histogram_has_high_support_pointwise`
// on the tier altitude, and
// `kinds_high_support_matches_kind_histogram_has_high_support_pointwise`
// on the diff altitude, in the "high-support across
// altitudes" projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().has_high_support();
assert_eq!(slice.file_formats_high_support(), via_histogram);
}
}
#[test]
fn file_formats_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise() {
// Defining strict-singular-gap-or-full-cover form:
// `file_formats_high_support() ⇔ file_formats_full_cover() ||
// (file_formats_singular_gap() &&
// !file_formats_singular_support())`. Pins the predicate
// against the three-way disjunction on three named
// histogram-side peers consumers reach for when they open-
// code the high-magnitude corner as a boolean fold over the
// full-cover and strict singleton-gap boundaries. The
// `!file_formats_singular_support()` excision is vacuously
// `true` on the cardinality-`4` file-format axis when
// `file_formats_singular_gap` fires (support size `3 != 1`),
// so the disjunction reduces to `file_formats_full_cover ||
// file_formats_singular_gap` at this sub-axis — but the raw
// form is pinned here so downstream lifts to cardinality-`2`
// sub-axes inherit the excision verbatim. Peer of
// `layer_kinds_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise`
// on the tier altitude, and
// `kinds_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_high_support();
let via_union = slice.file_formats_full_cover()
|| (slice.file_formats_singular_gap() && !slice.file_formats_singular_support());
assert_eq!(
via_seam, via_union,
"file_formats_high_support ({via_seam}) must agree with \
file_formats_full_cover || (file_formats_singular_gap && !file_formats_singular_support) ({via_union})",
);
}
}
#[test]
fn file_formats_high_support_agrees_with_absent_file_formats_count_at_most_one_and_support_at_least_two_pointwise()
{
// Coverage-gap-scalar dual-interval surface:
// `file_formats_high_support() == (absent_file_formats_count()
// <= 1 && present_file_formats_count() >= 2)` on every
// fixture. The coverage-gap-side surfacing of the same
// boolean, without allocating either
// `Vec<crate::discovery::Format>`. On the cardinality-`4`
// axis both clauses carry content — the `<= 1` clause fails
// on the two-format partial cover (absent_count=2) even
// though the `>= 2` clause holds (present_count=2), pinning
// the two-format-cover strict-interior disjointness on the
// coverage-gap side. Peer of
// `layer_kinds_high_support_agrees_with_absent_layer_kinds_count_at_most_one_and_support_at_least_two_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_agrees_with_absent_tiers_count_at_most_one_and_support_at_least_two_pointwise`
// on the tier altitude, and
// `kinds_high_support_agrees_with_absent_kinds_count_at_most_one_and_support_at_least_two_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_high_support();
let gap = slice.absent_file_formats_count();
let support = slice.present_file_formats_count();
let via_scalar = gap <= 1 && support >= 2;
assert_eq!(
via_seam, via_scalar,
"file_formats_high_support ({via_seam}) must agree with \
absent_file_formats_count <= 1 && present_file_formats_count >= 2 \
(gap={gap}, support={support})",
);
}
}
#[test]
fn file_formats_high_support_agrees_with_present_file_formats_count_plus_one_at_least_axis_cardinality_pointwise()
{
// Support-scalar dual-interval form:
// `file_formats_high_support() == (present_file_formats_count()
// + 1 >= axis_cardinality::<crate::discovery::Format>() &&
// present_file_formats_count() >= 2)` on every fixture. The
// support-side surfacing of the same boolean — a high-
// magnitude fold observes at least `axis_cardinality - 1`
// cells; the `>= 2` clause excises the cardinality-`2`
// singleton where the dual-singular-collapse fires. Dual of
// the coverage-gap-scalar surface on the complementary side
// of the same partition via the `present + absent ==
// axis_cardinality` invariant. Peer of
// `layer_kinds_high_support_agrees_with_present_layer_kinds_count_plus_one_at_least_axis_cardinality_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_agrees_with_contributing_tiers_count_plus_one_at_least_axis_cardinality_pointwise`
// on the tier altitude, and
// `kinds_high_support_agrees_with_present_kinds_count_plus_one_at_least_axis_cardinality_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_high_support();
let support = slice.present_file_formats_count();
let via_scalar = support + 1 >= crate::axis_cardinality::<crate::discovery::Format>()
&& support >= 2;
assert_eq!(
via_seam, via_scalar,
"file_formats_high_support ({via_seam}) must agree with \
present_file_formats_count + 1 >= axis_cardinality && \
present_file_formats_count >= 2 (support={support})",
);
}
}
#[test]
fn file_formats_high_support_agrees_with_present_file_formats_len_at_least_axis_cardinality_minus_one_pointwise()
{
// Support-`Vec` dual-length form:
// `file_formats_high_support() == (present_file_formats().len()
// + 1 >= axis_cardinality::<crate::discovery::Format>() &&
// present_file_formats().len() >= 2)` on every fixture. Pins
// the predicate against the `Vec<crate::discovery::Format>`
// length form consumers reach for when they already hold the
// support vector. Allocating peer of the support-scalar
// dual-interval surface one pin over. Peer of
// `layer_kinds_high_support_agrees_with_present_layer_kinds_len_at_least_axis_cardinality_minus_one_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_agrees_with_contributing_tiers_len_at_least_axis_cardinality_minus_one_pointwise`
// on the tier altitude, and
// `kinds_high_support_agrees_with_present_kinds_len_at_least_axis_cardinality_minus_one_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_high_support();
let len = slice.present_file_formats().len();
let via_vec =
len + 1 >= crate::axis_cardinality::<crate::discovery::Format>() && len >= 2;
assert_eq!(
via_seam, via_vec,
"file_formats_high_support ({via_seam}) must agree with \
present_file_formats().len() dual-interval ({via_vec}, len={len})",
);
}
}
#[test]
fn file_formats_high_support_empty_chain_is_false() {
// Empty-chain boundary: the empty chain observes zero cells,
// so every cell is unobserved (four zeros on the cardinality-
// `4` axis) — the "at most one unobserved" predicate fails
// and `file_formats_high_support` reads `false`. Matches
// `has_high_support` reading `false` on the empty histogram
// one altitude down for every cardinality-`>= 2` axis. Direct
// witness of the disjointness `file_formats_low_support ⇒
// !file_formats_high_support` on the empty-chain corner —
// the empty chain sits at the *bottom* of the magnitude
// interval, not the top. Orthogonal polarity to
// `file_formats_low_support` reading `true` on the empty
// chain — the two magnitude corners partition every non-
// strict-interior fold at the file-format sub-axis. Peer of
// `layer_kinds_high_support_empty_chain_is_false` on the
// layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_empty_map_is_false` on the tier
// altitude, and `kinds_high_support_empty_diff_is_false` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_high_support());
assert!(empty.file_formats_low_support());
assert!(!empty.file_formats_any_observed());
assert!(!empty.file_formats_singular_support());
assert!(!empty.file_formats_singular_gap());
assert!(!empty.file_formats_full_cover());
assert!(!empty.file_formats_strict_partial_cover());
}
#[test]
fn file_formats_high_support_no_recognized_files_is_false() {
// Non-empty-chain / empty-histogram boundary the file-format
// sub-axis pins that the layer-kind sub-axis does *not*. A
// chain of only `Defaults` / `Env` / unrecognized-extension
// `File` layers is non-empty but has no `Some` file-format
// projection, so the histogram is empty (four zeros on the
// cardinality-`4` axis) — the "at most one unobserved"
// clause fails and `file_formats_high_support` reads
// `false`. Cross-sub-axis divergence pin against
// `layer_kinds_high_support`: on the same fixtures the
// layer-kind sub-axis observes at least one layer-kind cell
// (Defaults / Env / File) so the high-support corner can
// fire there, but the file-format sub-axis's narrower
// high-magnitude corner does not. Peer of
// `file_formats_low_support_no_recognized_files_is_true`
// through negation on the opposite magnitude leg.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(slice.file_format_histogram().is_empty());
assert!(!slice.file_formats_any_observed());
assert!(!slice.file_formats_high_support());
assert!(slice.file_formats_low_support());
}
}
#[test]
fn file_formats_high_support_singleton_support_is_false() {
// Singleton-support pin: `sample_chain()` observes only Yaml
// (two `.yaml` file layers + one Env layer), so the file-
// format support cardinality is `1` (three unobserved cells
// on the cardinality-`4` axis) — the "at most one
// unobserved" predicate fails and `file_formats_high_support`
// reads `false`. Direct witness of the disjointness
// `file_formats_singular_support ⇒
// !file_formats_high_support` on every cardinality-`>= 2`
// axis. Peer of
// `layer_kinds_high_support_singleton_support_is_false` on
// the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_singleton_support_is_false` on the
// tier altitude, and
// `kinds_high_support_singleton_support_is_false` on the
// diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(!slice.file_formats_high_support());
}
#[test]
fn file_formats_high_support_two_format_partial_cover_is_false() {
// Two-format-cover pin — the *first non-vacuous* strict-
// interior disjointness witness on the chain altitude. A
// chain observing exactly two file-format cells
// (`.yaml + .toml`) reads `strict_partial_cover=true` on the
// cardinality-`4` `crate::discovery::Format` axis; support
// cardinality `2` leaves two unobserved cells, so the "at
// most one unobserved" clause fails and
// `file_formats_high_support` reads `false`. Direct witness
// of the *non-vacuous* strict disjointness
// `file_formats_strict_partial_cover ⇒
// !file_formats_high_support` — unavailable at the
// cardinality-`3` layer-kind sub-axis where the strict-
// interior antecedent is vacuous. Matches the tier altitude
// (cardinality-`4` `ConfigTierKind`) — the two-tier partial-
// cover fixture there reads
// `tiers_strict_partial_cover=true, tiers_high_support=false`
// on the same strict-interior boundary. Peer of
// `file_formats_low_support_two_format_partial_cover_is_false`
// on the opposite magnitude leg (both magnitude corners
// fail on the strict-interior fold — the two-format partial
// cover fixture is the file-format sub-axis's shared
// witness of the strict-interior middle leg of the
// magnitude-direction ternary).
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(slice.file_format_histogram().count(Format::Yaml) > 0);
assert!(slice.file_format_histogram().count(Format::Toml) > 0);
assert!(slice.file_formats_strict_partial_cover());
assert!(!slice.file_formats_high_support());
}
#[test]
fn file_formats_high_support_three_format_partial_cover_is_true() {
// Three-format-cover pin: a chain observing exactly three
// file-format cells (`.yaml + .toml + .lisp`) sits at
// support cardinality `3` — one cell unobserved on the
// cardinality-`4` axis, exactly the singleton-gap boundary.
// `file_formats_singular_gap` fires (one unobserved cell)
// and `file_formats_high_support` reads `true`. Direct
// witness of the strict subsumption
// `file_formats_singular_gap ⇒ file_formats_high_support`
// on the cardinality-`>= 3` axis where the dual-singular-
// collapse never fires. Peer of
// `layer_kinds_high_support_two_kind_partial_cover_is_true`
// on the layer-kind sub-axis (which reads through the
// singleton-gap subsumption at support cardinality `2` on
// the cardinality-`3` axis — the same subsumption on
// different support cardinalities).
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert!(slice.file_formats_singular_gap());
assert!(slice.file_formats_high_support());
}
#[test]
fn file_formats_high_support_uniform_cover_is_true() {
// Uniform-cover pin: every file-format cell contributes at
// least one recognized-extension file layer, so the support
// cardinality is `4` (no unobserved cells) — the "at most
// one unobserved" predicate holds and
// `file_formats_high_support` reads `true`. Direct witness
// of the strict subsumption `file_formats_full_cover ⇒
// file_formats_high_support` on every axis (the full-cover
// corner always sits inside the high-magnitude corner via
// the `is_full_cover()` disjunct on the bridge). The
// uniform four-format cover partitions the seven coverage-
// support boundaries with (`any_observed`=true,
// `singular_support`=false, `singular_gap`=false,
// `full_cover`=true, `strict_partial_cover`=false,
// `low_support`=false, `high_support`=true). Peer of
// `layer_kinds_high_support_uniform_cover_is_true` on the
// layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_uniform_cover_is_true` on the tier
// altitude, and `kinds_high_support_uniform_cover_is_true`
// on the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_formats_full_cover());
assert!(slice.file_formats_high_support());
}
#[test]
fn file_formats_high_support_implies_not_file_formats_low_support_pointwise() {
// Disjointness pin: `file_formats_high_support() ⇒
// !file_formats_low_support()` on every axis with
// cardinality `>= 2`. High support has size `>= 2`; low
// support has size `<= 1`. The two magnitude corners sit at
// opposite ends of the support-cardinality interval on
// every non-degenerate axis. Pins the strict pairwise
// disjointness of the magnitude-direction ternary's two
// magnitude legs at the file-format sub-axis. Peer of
// `layer_kinds_high_support_implies_not_layer_kinds_low_support_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_implies_not_tiers_low_support_pointwise`
// on the tier altitude, and
// `kinds_high_support_implies_not_kinds_low_support_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_high_support() {
assert!(
!slice.file_formats_low_support(),
"high-support chain cannot be low-support on a \
cardinality >= 2 axis",
);
}
}
}
#[test]
fn file_formats_high_support_implies_not_file_formats_strict_partial_cover_pointwise() {
// Disjointness pin: `file_formats_high_support() ⇒
// !file_formats_strict_partial_cover()` always. The strict
// interior requires `>= 2` unobserved cells; high support
// has `<= 1`. On the cardinality-`4` `crate::discovery::Format`
// axis this is *non-vacuous* — the two-format partial cover
// fixture reads `strict_partial_cover=true,
// high_support=false`, exercising both sides of the strict
// disjointness on the same fixture. Strict advance over the
// vacuously-`true` peer at the cardinality-`3` layer-kind
// sub-axis where the strict interior is unreachable and the
// consequent holds vacuously. Matches the non-vacuous peer
// at the tier altitude on the cardinality-`4`
// `ConfigTierKind` axis. Peer of
// `layer_kinds_high_support_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_high_support_implies_not_kinds_strict_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_high_support() {
assert!(
!slice.file_formats_strict_partial_cover(),
"high-support chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn file_formats_high_support_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_high_support() ⇒
// file_formats_any_observed()` on every axis with
// cardinality `>= 2`. High support has size `>= 2 >= 1`,
// so at least one cell was observed. The empty chain and
// every empty-histogram non-empty chain sit on the disjoint
// `!file_formats_any_observed` boundary at the bottom of
// the magnitude interval — every high-support chain
// observes at least one file-format cell. Peer of
// `layer_kinds_high_support_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_implies_tiers_any_observed_pointwise`
// on the tier altitude, and
// `kinds_high_support_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_high_support() {
assert!(
slice.file_formats_any_observed(),
"high-support chain must observe at least one cell",
);
}
}
}
#[test]
fn file_formats_full_cover_implies_file_formats_high_support_pointwise() {
// Subsumption pin: `file_formats_full_cover() ⇒
// file_formats_high_support()` on every axis. The full-
// cover corner always sits inside the high-magnitude corner
// via the `is_full_cover()` disjunct on the bridge. Direct
// witness of the strict subsumption between the top
// coverage-support boundary and the top magnitude corner at
// the file-format sub-axis. Peer of
// `layer_kinds_full_cover_implies_layer_kinds_high_support_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_full_cover_implies_tiers_high_support_pointwise`
// on the tier altitude, and
// `kinds_full_cover_implies_kinds_high_support_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() {
assert!(
slice.file_formats_high_support(),
"full-cover chain must be high-support",
);
}
}
}
#[test]
fn file_formats_singular_gap_implies_file_formats_high_support_pointwise() {
// Subsumption pin: `file_formats_singular_gap() ⇒
// file_formats_high_support()` on every axis with
// cardinality `>= 3` (every file-format implementor today
// — `crate::discovery::Format` carries four cells). A
// singleton-gap fold has support size `axis_cardinality - 1
// >= 2`, so the "at most one unobserved" *and* "at least
// two observed" clauses both hold. Direct witness of the
// strict subsumption between the strict singleton-gap
// boundary and the top magnitude corner. On cardinality-`2`
// sub-axes (no file-format axis today) the two diverge via
// the dual-singular-collapse excision — pinned separately
// by the histogram-side test one altitude down. Peer of
// `layer_kinds_singular_gap_implies_layer_kinds_high_support_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_gap_implies_tiers_high_support_pointwise`
// on the tier altitude, and
// `kinds_singular_gap_implies_kinds_high_support_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_gap() {
assert!(
slice.file_formats_high_support(),
"singular-gap chain must be high-support on a \
cardinality >= 3 axis",
);
}
}
}
#[test]
fn file_formats_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise()
{
// Ternary partition pin: `(file_formats_low_support,
// file_formats_strict_partial_cover,
// file_formats_high_support)` is a strict partition on
// every axis with cardinality `>= 2` (every file-format
// implementor today). Exactly one leg fires on every chain
// — the magnitude-direction ternary of the 5-corner
// support-cardinality partition, folding the two singular-
// cardinality boundaries into the two magnitude corners and
// naming the boundary-free strict interior separately. At
// the file-format sub-axis on the cardinality-`4`
// `crate::discovery::Format` axis the middle leg is
// *reachable* (support size `2` fits inside the strict
// interval `[2, cardinality - 2] = [2, 2]`), so the ternary
// closes non-vacuously — matching the tier altitude
// (cardinality-`4` `ConfigTierKind`) and diverging from the
// degenerate two-way partition at the layer-kind sub-axis
// (cardinality-`3` `ConfigSourceKind`) and the diff altitude
// (cardinality-`3` `DiffLineKind`). Peer of
// `layer_kinds_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise`
// on the tier altitude, and
// `kinds_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise`
// on the diff altitude, and of the trait-uniform pin
// `axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`
// one altitude down.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let low = slice.file_formats_low_support();
let mid = slice.file_formats_strict_partial_cover();
let high = slice.file_formats_high_support();
let count = usize::from(low) + usize::from(mid) + usize::from(high);
assert_eq!(
count, 1,
"exactly one of (low_support, strict_partial_cover, \
high_support) must fire (low={low}, mid={mid}, \
high={high})",
);
}
}
#[test]
fn file_formats_low_support_strict_partial_cover_high_support_ternary_partition_all_legs_inhabited()
{
// Non-vacuous ternary pin: each of the three legs of the
// magnitude-direction ternary partition `(file_formats_low_support,
// file_formats_strict_partial_cover, file_formats_high_support)`
// is inhabited by an explicit fixture on the cardinality-
// `4` `crate::discovery::Format` axis. Strict advance over
// the cardinality-`3` layer-kind sub-axis and the diff
// altitude where the strict-interior middle leg is
// vacuously empty (the strict interval `[2, cardinality - 2]
// = [2, 1]` is empty on the cardinality-`3` axis). Matches
// the tier altitude's non-vacuous peer
// `tiers_low_support_strict_partial_cover_high_support_ternary_partition_all_legs_inhabited`.
// Low leg witnessed by the empty chain (support size `0`),
// strict-interior middle leg by the two-format partial
// cover (support size `2`), high leg by the uniform four-
// format cover (support size `4`).
let empty_chain: Vec<ConfigSource> = Vec::new();
let low_slice = empty_chain.as_slice();
assert!(low_slice.file_formats_low_support());
assert!(!low_slice.file_formats_strict_partial_cover());
assert!(!low_slice.file_formats_high_support());
let mid_chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let mid_slice = mid_chain.as_slice();
assert!(!mid_slice.file_formats_low_support());
assert!(mid_slice.file_formats_strict_partial_cover());
assert!(!mid_slice.file_formats_high_support());
let high_chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let high_slice = high_chain.as_slice();
assert!(!high_slice.file_formats_low_support());
assert!(!high_slice.file_formats_strict_partial_cover());
assert!(high_slice.file_formats_high_support());
}
#[test]
fn file_formats_high_support_agrees_with_open_coded_at_most_one_zero_walk() {
// Parity against the exact hand-rolled high-support walk
// this lift replaces on cardinality-`>= 3` axes: walk every
// cell of the histogram and count how many carry a zero
// count; the high-support predicate reads `true` iff at
// most one cell is a zero (and at least two cells are
// nonzero — the dual-singular-collapse excision, vacuously
// satisfied on cardinality-`>= 3` axes when the "at most
// one zero" clause holds). Mirrors the parity pin
// `file_formats_low_support_agrees_with_open_coded_at_most_one_positive_walk`
// on the opposite magnitude leg. Peer of
// `layer_kinds_high_support_agrees_with_open_coded_at_most_one_zero_walk`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_high_support_agrees_with_open_coded_at_most_one_zero_walk`
// on the tier altitude, and
// `kinds_high_support_agrees_with_open_coded_at_most_one_zero_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_high_support();
let hist = slice.file_format_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros <= 1 && nonzeros >= 2;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::file_formats_singular — singular-near-
// boundary boolean predicate on the file-format sub-axis of
// the chain altitude, lifting the "singular across altitudes"
// projection sideways from the layer-kind sub-axis to the
// second chain-altitude sub-axis. On the cardinality-`4`
// `crate::discovery::Format` axis the distance ternary closes
// non-vacuously on every leg — matches the tier altitude and
// diverges from the degenerate two-way partition at the
// layer-kind sub-axis and the diff altitude. ──
#[test]
fn file_formats_singular_matches_file_format_histogram_has_singular_pointwise() {
// Routing pin: `file_formats_singular` routes through
// `file_format_histogram().has_singular()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops
// projecting through the shared cube-native primitive. File-
// format sub-axis peer of
// `layer_kinds_singular_matches_layer_kind_histogram_has_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_matches_tier_histogram_has_singular_pointwise`
// on the tier altitude, and
// `kinds_singular_matches_kind_histogram_has_singular_pointwise`
// on the diff altitude, in the "singular across altitudes"
// projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().has_singular();
assert_eq!(slice.file_formats_singular(), via_histogram);
}
}
#[test]
fn file_formats_singular_matches_defining_union_of_singular_boundaries_pointwise() {
// Defining union-of-singular-boundaries form:
// `file_formats_singular() ⇔ file_formats_singular_support() ||
// file_formats_singular_gap()`. Pins the predicate against the
// two-way disjunction on two named histogram-side peers
// consumers reach for when they open-code the singular near-
// boundary corner as a boolean fold over the two singular-
// cardinality boundaries. Peer of
// `layer_kinds_singular_matches_defining_union_of_singular_boundaries_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_matches_defining_union_of_singular_boundaries_pointwise`
// on the tier altitude, and
// `kinds_singular_matches_defining_union_of_singular_boundaries_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular();
let via_union =
slice.file_formats_singular_support() || slice.file_formats_singular_gap();
assert_eq!(
via_seam, via_union,
"file_formats_singular ({via_seam}) must agree with \
file_formats_singular_support || file_formats_singular_gap ({via_union})",
);
}
}
#[test]
fn file_formats_singular_agrees_with_any_observed_not_full_cover_not_strict_partial_cover_pointwise()
{
// Partial-cover-minus-strict-interior form tightened by the
// non-vacuous strict-interior excision on the cardinality-`4`
// file-format axis: `file_formats_singular() ==
// file_formats_any_observed() && !file_formats_full_cover() &&
// !file_formats_strict_partial_cover()`. The strict interior
// of the file-format axis is reachable (interval
// `[2, cardinality - 2] = [2, 2]`), so the middle-leg fold
// requires the `!strict_partial_cover` excision to read
// through the partial-cover slice cleanly. Matches the tier-
// altitude peer `tiers_singular ⇔ (tiers_any_observed &&
// !tiers_full_cover && !tiers_strict_partial_cover)` on the
// same cardinality-`4` axis and diverges from the layer-kind
// sub-axis where the strict-interior leg is vacuously empty
// and the equivalence loosens to `(any_observed &&
// !full_cover)`.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular();
let via_slice = slice.file_formats_any_observed()
&& !slice.file_formats_full_cover()
&& !slice.file_formats_strict_partial_cover();
assert_eq!(
via_seam, via_slice,
"file_formats_singular ({via_seam}) must agree with \
file_formats_any_observed && !file_formats_full_cover && \
!file_formats_strict_partial_cover ({via_slice})",
);
}
}
#[test]
fn file_formats_singular_agrees_with_present_file_formats_count_dual_equality_pointwise() {
// Support-scalar dual-equality surface:
// `file_formats_singular() == (present_file_formats_count() ==
// 1 || present_file_formats_count() ==
// axis_cardinality::<crate::discovery::Format>() - 1)` on
// every fixture. The support-side surfacing of the same
// boolean, without allocating either
// `Vec<crate::discovery::Format>`. On the cardinality-`4`
// file-format axis the two equalities are disjoint (`1 ≠ 3 =
// cardinality - 1`) and the disjunction reads the true dual.
// Peer of
// `layer_kinds_singular_agrees_with_present_layer_kinds_count_dual_equality_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_agrees_with_contributing_tiers_count_dual_equality_pointwise`
// on the tier altitude, and
// `kinds_singular_agrees_with_present_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular();
let support = slice.present_file_formats_count();
let via_scalar = support == 1
|| support == crate::axis_cardinality::<crate::discovery::Format>() - 1;
assert_eq!(
via_seam, via_scalar,
"file_formats_singular ({via_seam}) must agree with \
present_file_formats_count == 1 || present_file_formats_count == cardinality - 1 \
({via_scalar}, support={support})",
);
}
}
#[test]
fn file_formats_singular_agrees_with_present_and_absent_file_formats_count_dual_equality_pointwise()
{
// Dual-scalar equality surface: `file_formats_singular() ==
// (present_file_formats_count() == 1 ||
// absent_file_formats_count() == 1)` on every fixture. The
// `present + absent == axis_cardinality` invariant restated
// on the two named cardinality peers, without allocating
// either `Vec<crate::discovery::Format>`. Peer of the
// histogram-side dual-scalar equality form
// `hist.distinct_cells() == 1 || hist.unobserved_cells() == 1`
// pinned one altitude down. Peer of
// `layer_kinds_singular_agrees_with_present_and_absent_layer_kinds_count_dual_equality_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_agrees_with_contributing_and_absent_tiers_count_dual_equality_pointwise`
// on the tier altitude, and
// `kinds_singular_agrees_with_present_and_absent_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular();
let support = slice.present_file_formats_count();
let gap = slice.absent_file_formats_count();
let via_scalar = support == 1 || gap == 1;
assert_eq!(
via_seam, via_scalar,
"file_formats_singular ({via_seam}) must agree with \
present_file_formats_count == 1 || absent_file_formats_count == 1 \
({via_scalar}, support={support}, gap={gap})",
);
}
}
#[test]
fn file_formats_singular_empty_chain_is_false() {
// Empty-chain boundary: the empty chain observes zero cells,
// so every cell is unobserved (four zeros on the cardinality-
// `4` axis) — neither `file_formats_singular_support`
// (nonzeros `== 1`) nor `file_formats_singular_gap` (zeros
// `== 1`) fires. `file_formats_singular` reads `false`.
// Matches `has_singular` reading `false` on the empty
// histogram one altitude down for every cardinality-`>= 2`
// axis. The empty chain sits on the disjoint bottom coverage
// boundary of the distance-from-boundary ternary partition,
// carried by `has_boundary` (via `!file_formats_any_observed`)
// instead. Peer of `layer_kinds_singular_empty_chain_is_false`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_empty_map_is_false` on the tier altitude,
// and `kinds_singular_empty_diff_is_false` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_singular());
assert!(!empty.file_formats_any_observed());
assert!(!empty.file_formats_singular_support());
assert!(!empty.file_formats_singular_gap());
}
#[test]
fn file_formats_singular_no_recognized_files_is_false() {
// Non-empty-chain / empty-histogram boundary the file-format
// sub-axis pins that the layer-kind sub-axis does *not*. A
// chain of only `Defaults` / `Env` / unrecognized-extension
// `File` layers is non-empty but has no `Some` file-format
// projection, so the histogram is empty (four zeros on the
// cardinality-`4` axis) — neither
// `file_formats_singular_support` nor
// `file_formats_singular_gap` fires and
// `file_formats_singular` reads `false`. Cross-sub-axis
// divergence pin against `layer_kinds_singular`: on the same
// fixtures the layer-kind sub-axis observes at least one
// layer-kind cell (Defaults / Env / File) so the singular
// near-boundary corner can fire there, but the file-format
// sub-axis's narrower singular corner does not. Peer of
// `file_formats_high_support_no_recognized_files_is_false`
// via the `singular ⇒ any_observed` subsumption on the empty-
// histogram fixture.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(slice.file_format_histogram().is_empty());
assert!(!slice.file_formats_any_observed());
assert!(!slice.file_formats_singular());
assert!(!slice.file_formats_singular_support());
assert!(!slice.file_formats_singular_gap());
}
}
#[test]
fn file_formats_singular_singleton_support_is_true() {
// Singleton-support pin: `sample_chain()` observes only Yaml
// (two `.yaml` file layers + one Env layer), so the file-
// format support cardinality is `1` (three unobserved cells
// on the cardinality-`4` axis) — `file_formats_singular_support`
// fires and the disjunction holds via that disjunct.
// `file_formats_singular` reads `true`. Direct witness of
// the subsumption `file_formats_singular_support ⇒
// file_formats_singular` on every axis with cardinality
// `>= 2`. Peer of
// `layer_kinds_singular_singleton_support_is_true` on the
// layer-kind sub-axis of the same chain altitude,
// `tiers_singular_singleton_support_is_true` on the tier
// altitude, and `kinds_singular_singleton_support_is_true`
// on the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(slice.file_formats_singular());
}
#[test]
fn file_formats_singular_two_format_partial_cover_is_false() {
// Two-format-cover pin — the *first non-vacuous* strict-
// interior disjointness witness on the chain altitude for
// the singular near-boundary corner. A chain observing
// exactly two file-format cells (`.yaml + .toml`) reads
// `strict_partial_cover=true` on the cardinality-`4`
// `crate::discovery::Format` axis; support cardinality `2`
// satisfies neither `nonzeros == 1` nor `zeros == 1`, so
// `file_formats_singular` reads `false`. Direct witness of
// the *non-vacuous* strict disjointness
// `file_formats_strict_partial_cover ⇒
// !file_formats_singular` — unavailable at the cardinality-
// `3` layer-kind sub-axis where the strict-interior
// antecedent is vacuous and the two-kind partial cover
// fixture reads `layer_kinds_singular_gap ⇒
// layer_kinds_singular = true` instead. Matches the tier
// altitude (cardinality-`4` `ConfigTierKind`) — the two-
// tier partial-cover fixture there reads
// `tiers_strict_partial_cover=true, tiers_singular=false`
// on the same strict-interior boundary.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(slice.file_format_histogram().count(Format::Yaml) > 0);
assert!(slice.file_format_histogram().count(Format::Toml) > 0);
assert!(slice.file_formats_strict_partial_cover());
assert!(!slice.file_formats_singular());
assert!(!slice.file_formats_singular_support());
assert!(!slice.file_formats_singular_gap());
}
#[test]
fn file_formats_singular_three_format_partial_cover_is_true() {
// Three-format-cover pin: a chain observing exactly three
// file-format cells (`.yaml + .toml + .lisp`) sits at
// support cardinality `3` = `axis_cardinality - 1`, exactly
// the singleton-gap boundary on the cardinality-`4` axis —
// so `file_formats_singular_gap` fires and the disjunction
// holds via that disjunct. `file_formats_singular` reads
// `true`. Direct witness of the subsumption
// `file_formats_singular_gap ⇒ file_formats_singular` on
// every axis via the singleton-gap disjunct of the defining
// union. Distinguishes the file-format sub-axis from the
// layer-kind sub-axis where the singleton-gap boundary sits
// at support cardinality `2` on the cardinality-`3` axis
// instead.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert!(slice.file_formats_singular_gap());
assert!(slice.file_formats_singular());
}
#[test]
fn file_formats_singular_uniform_cover_is_false() {
// Uniform-cover pin: every file-format cell contributes at
// least one recognized-extension file layer, so the support
// cardinality is `4` (no unobserved cells on the cardinality-
// `4` axis) — `file_formats_singular_gap` fails (`zeros == 0
// ≠ 1`) and `file_formats_singular_support` fails (`nonzeros
// == 4 ≠ 1`). `file_formats_singular` reads `false`. The
// full-cover boundary sits at the top of the coverage
// interval, one of the two boundary corners carried by
// `has_boundary` (via `file_formats_full_cover`) in the
// distance ternary — disjoint from the singular near-
// boundary corner. Peer of
// `layer_kinds_singular_uniform_cover_is_false` on the layer-
// kind sub-axis of the same chain altitude,
// `tiers_singular_uniform_cover_is_false` on the tier
// altitude, and `kinds_singular_uniform_cover_is_false` on
// the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_formats_full_cover());
assert!(!slice.file_formats_singular());
}
#[test]
fn file_formats_singular_support_implies_file_formats_singular_pointwise() {
// Subsumption pin: `file_formats_singular_support() ⇒
// file_formats_singular()` on every axis via the
// `file_formats_singular_support` disjunct of the defining
// union. The singleton-support boundary always sits inside
// the singular near-boundary corner. Direct witness of one
// leg of the union bridge. Peer of
// `layer_kinds_singular_support_implies_layer_kinds_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_support_implies_tiers_singular_pointwise`
// on the tier altitude, and
// `kinds_singular_support_implies_kinds_singular_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
slice.file_formats_singular(),
"singular-support chain must be singular",
);
}
}
}
#[test]
fn file_formats_singular_gap_implies_file_formats_singular_pointwise() {
// Subsumption pin: `file_formats_singular_gap() ⇒
// file_formats_singular()` on every axis via the
// `file_formats_singular_gap` disjunct of the defining union.
// The singleton-gap boundary always sits inside the singular
// near-boundary corner. Direct witness of the other leg of
// the union bridge. Peer of
// `layer_kinds_singular_gap_implies_layer_kinds_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_gap_implies_tiers_singular_pointwise` on
// the tier altitude, and
// `kinds_singular_gap_implies_kinds_singular_pointwise` on
// the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_gap() {
assert!(
slice.file_formats_singular(),
"singular-gap chain must be singular",
);
}
}
}
#[test]
fn file_formats_singular_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_singular() ⇒
// file_formats_any_observed()` on every axis with cardinality
// `>= 2`. Both disjuncts require at least one observed cell
// (`singular_support` has nonzeros `>= 1`; `singular_gap` has
// nonzeros `= cardinality - 1 >= 1`). The empty chain AND
// every empty-histogram non-empty chain sit on the disjoint
// `!file_formats_any_observed` boundary at the bottom
// coverage boundary — every singular chain observes at least
// one file-format cell. Peer of
// `layer_kinds_singular_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_implies_tiers_any_observed_pointwise` on
// the tier altitude, and
// `kinds_singular_implies_kinds_any_observed_pointwise` on
// the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular() {
assert!(
slice.file_formats_any_observed(),
"singular chain must observe at least one cell",
);
}
}
}
#[test]
fn file_formats_singular_implies_not_file_formats_full_cover_pointwise() {
// Disjointness pin: `file_formats_singular() ⇒
// !file_formats_full_cover()` on every axis with cardinality
// `>= 2`. `file_formats_singular_support` has support `1 <
// cardinality`; `file_formats_singular_gap` has support
// `cardinality - 1 < cardinality`. The full-cover corner
// sits at the top coverage boundary — one of the two
// boundary corners disjoint from the singular near-boundary
// corner. Peer of
// `layer_kinds_singular_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_implies_not_tiers_full_cover_pointwise` on
// the tier altitude, and
// `kinds_singular_implies_not_kinds_full_cover_pointwise` on
// the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular() {
assert!(
!slice.file_formats_full_cover(),
"singular chain cannot be full-cover on a \
cardinality >= 2 axis",
);
}
}
}
#[test]
fn file_formats_singular_implies_not_file_formats_strict_partial_cover_pointwise() {
// Disjointness pin: `file_formats_singular() ⇒
// !file_formats_strict_partial_cover()` always. The two
// named corners of the distance-from-boundary ternary
// partition are pairwise disjoint. On the cardinality-`4`
// `crate::discovery::Format` axis this is *non-vacuous* —
// the two-format partial-cover fixture reads
// `strict_partial_cover=true, singular=false`, exercising
// both sides of the strict disjointness on the same fixture.
// Strict advance over the vacuously-`true` peer at the
// cardinality-`3` layer-kind sub-axis where the strict
// interior is unreachable and the consequent holds
// vacuously. Matches the non-vacuous peer at the tier
// altitude on the cardinality-`4` `ConfigTierKind` axis. Peer
// of
// `layer_kinds_singular_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_singular_implies_not_kinds_strict_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular() {
assert!(
!slice.file_formats_strict_partial_cover(),
"singular chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn file_formats_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise() {
// Ternary partition pin at the chain file-format sub-axis:
// exactly one of the three legs
// `(!file_formats_any_observed || file_formats_full_cover,
// file_formats_singular,
// file_formats_strict_partial_cover)`
// fires on every chain — the distance-from-boundary ternary
// of the 5-corner support-cardinality partition, folding
// the two boundary corners (empty/empty-histogram and full-
// cover) into `has_boundary`, the two singular near-boundary
// corners into `has_singular`, and the boundary-free strict
// interior into `has_strict_partial_cover`. On the
// cardinality-`4` `crate::discovery::Format` axis every leg
// is inhabited — the ternary closes strictly *and* non-
// vacuously (interval `[2, cardinality - 2] = [2, 2]` is
// non-empty) — a strict advance over the layer-kind sub-
// axis and the diff altitude where the third leg vanishes
// and the ternary degenerates to the dual pointwise, and
// matching the tier altitude's non-vacuous three-leg
// partition on the cardinality-`4` `ConfigTierKind` axis.
// Peer of the trait-uniform pin
// `axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor`
// one altitude down, of
// `layer_kinds_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise`
// on the tier altitude, and
// `kinds_boundary_and_kinds_singular_and_kinds_strict_partial_cover_form_ternary_partition_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let boundary = !slice.file_formats_any_observed() || slice.file_formats_full_cover();
let singular = slice.file_formats_singular();
let strict = slice.file_formats_strict_partial_cover();
let count = usize::from(boundary) + usize::from(singular) + usize::from(strict);
assert_eq!(
count, 1,
"exactly one of (boundary, singular, strict_partial_cover) \
must fire (boundary={boundary}, singular={singular}, \
strict={strict})",
);
}
}
#[test]
fn file_formats_boundary_singular_strict_partial_cover_ternary_partition_all_legs_inhabited() {
// Non-vacuous ternary pin: each of the three legs of the
// distance-from-boundary ternary partition
// `(!file_formats_any_observed || file_formats_full_cover,
// file_formats_singular, file_formats_strict_partial_cover)`
// is inhabited by an explicit fixture on the cardinality-
// `4` `crate::discovery::Format` axis. Strict advance over
// the cardinality-`3` layer-kind sub-axis and the diff
// altitude where the strict-interior middle leg is
// vacuously empty (the strict interval `[2, cardinality - 2]
// = [2, 1]` is empty on the cardinality-`3` axis). Matches
// the tier altitude's non-vacuous peer
// `tiers_boundary_singular_strict_partial_cover_ternary_partition_all_legs_inhabited`.
// Boundary leg witnessed by the empty chain (support size
// `0`) and by the uniform four-format cover (support size
// `4`), singular leg witnessed by the singleton-support
// fixture (support size `1`) and by the three-format cover
// (support size `3`), strict-interior middle leg witnessed
// by the two-format partial cover (support size `2`).
let empty_chain: Vec<ConfigSource> = Vec::new();
let empty_slice = empty_chain.as_slice();
assert!(!empty_slice.file_formats_any_observed());
assert!(!empty_slice.file_formats_singular());
assert!(!empty_slice.file_formats_strict_partial_cover());
let singleton_chain = vec![ConfigSource::File(PathBuf::from("/a.yaml"))];
let singleton_slice = singleton_chain.as_slice();
assert!(singleton_slice.file_formats_singular());
assert!(!singleton_slice.file_formats_full_cover());
assert!(!singleton_slice.file_formats_strict_partial_cover());
let two_chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let two_slice = two_chain.as_slice();
assert!(!two_slice.file_formats_singular());
assert!(two_slice.file_formats_strict_partial_cover());
let three_chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let three_slice = three_chain.as_slice();
assert!(three_slice.file_formats_singular());
assert!(!three_slice.file_formats_full_cover());
assert!(!three_slice.file_formats_strict_partial_cover());
let uniform_chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let uniform_slice = uniform_chain.as_slice();
assert!(uniform_slice.file_formats_full_cover());
assert!(!uniform_slice.file_formats_singular());
assert!(!uniform_slice.file_formats_strict_partial_cover());
}
#[test]
fn file_formats_singular_bridges_support_cardinality_class_is_singular_pointwise() {
// Cross-surface bridge law: `file_formats_singular() ==
// file_format_histogram().support_cardinality_class().is_singular()`
// on every fixture. The class-side projection lands on
// `SupportCardinalityClass::SingularSupport` or
// `SupportCardinalityClass::SingularGap` exactly when the
// histogram-side disjunction fires, and
// `SupportCardinalityClass::is_singular` reads `true` on
// either variant. Peer of the histogram-side bridge
// `axis_histogram_has_singular_agrees_with_class_is_singular_for_every_closed_axis_implementor`
// one altitude down, closing the (histogram, class) duality
// on the singular near-boundary leg at the chain file-
// format sub-axis. Peer of
// `layer_kinds_singular_bridges_support_cardinality_class_is_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_bridges_support_cardinality_class_is_singular_pointwise`
// on the tier altitude, and
// `kinds_singular_bridges_support_cardinality_class_is_singular_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular();
let via_class = slice
.file_format_histogram()
.support_cardinality_class()
.is_singular();
assert_eq!(
via_seam, via_class,
"file_formats_singular ({via_seam}) must agree with \
file_format_histogram().support_cardinality_class().is_singular() \
({via_class})",
);
}
}
#[test]
fn file_formats_singular_agrees_with_open_coded_singular_boundary_walk() {
// Parity against the exact hand-rolled singular walk this
// lift replaces on cardinality-`>= 2` axes: walk every cell
// of the histogram and count how many carry a zero count
// and how many carry a nonzero count; the singular predicate
// reads `true` iff exactly one cell is nonzero (singular
// support) or exactly one cell is a zero (singular gap).
// Mirrors the parity pins
// `file_formats_singular_support_agrees_with_present_file_formats_count_equals_one_pointwise`
// and the sibling on `singular_gap` on the two singular-
// cardinality boundaries the union folds. Peer of
// `layer_kinds_singular_agrees_with_open_coded_singular_boundary_walk`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_agrees_with_open_coded_singular_boundary_walk`
// on the tier altitude, and
// `kinds_singular_agrees_with_open_coded_singular_boundary_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_singular();
let hist = slice.file_format_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = nonzeros == 1 || zeros == 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ── file_formats_boundary coverage — the boundary-file-formats
// top-leg corner of the distance-from-boundary ternary partition
// `(has_boundary, has_singular, has_strict_partial_cover)` at
// the chain file-format sub-axis, lifting the layer-kind sub-
// axis sideways `layer_kinds_boundary` to the second chain-
// altitude sub-axis. On the cardinality-`4` `Format` axis the
// distance ternary closes non-vacuously on every leg — matches
// the tier altitude and diverges from the degenerate two-way
// partition at the layer-kind sub-axis and the diff altitude.
// The file-format projection is a partial function, so the
// empty-histogram disjunct fires on the no-recognized-files
// non-empty-chain fixture as well as on the truly empty chain.
// ──
#[test]
fn file_formats_boundary_matches_file_format_histogram_has_boundary_pointwise() {
// Routing pin: `file_formats_boundary` routes through
// `file_format_histogram().has_boundary()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops
// projecting through the shared cube-native primitive. File-
// format sub-axis peer of
// `layer_kinds_boundary_matches_layer_kind_histogram_has_boundary_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_matches_tier_histogram_has_boundary_pointwise`
// on the tier altitude, and
// `kinds_boundary_matches_kind_histogram_has_boundary_pointwise`
// on the diff altitude, in the "boundary across altitudes"
// projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().has_boundary();
assert_eq!(slice.file_formats_boundary(), via_histogram);
}
}
#[test]
fn file_formats_boundary_matches_defining_union_of_coverage_boundaries_pointwise() {
// Defining union-of-coverage-boundaries form:
// `file_formats_boundary() ⇔ !file_formats_any_observed() ||
// file_formats_full_cover()`. Pins the predicate against the
// two-way disjunction on the two named coverage-boundary
// peers consumers reach for when they open-code the boundary
// corner as a boolean fold over the two extreme coverage
// cardinalities. Peer of
// `layer_kinds_boundary_matches_defining_union_of_coverage_boundaries_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_matches_defining_union_of_coverage_boundaries_pointwise`
// on the tier altitude, and
// `kinds_boundary_matches_defining_union_of_coverage_boundaries_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_boundary();
let via_union = !slice.file_formats_any_observed() || slice.file_formats_full_cover();
assert_eq!(
via_seam, via_union,
"file_formats_boundary ({via_seam}) must agree with \
!file_formats_any_observed || file_formats_full_cover ({via_union})",
);
}
}
#[test]
fn file_formats_boundary_agrees_with_present_file_formats_count_dual_equality_pointwise() {
// Support-scalar dual-equality surface:
// `file_formats_boundary() == (present_file_formats_count() ==
// 0 || present_file_formats_count() ==
// axis_cardinality::<crate::discovery::Format>())` on every
// fixture. The support-side surfacing of the same boolean,
// without allocating either `Vec<crate::discovery::Format>`.
// The two equalities are strictly disjoint (`0 != 4 =
// cardinality` on the file-format axis). Peer of
// `layer_kinds_boundary_agrees_with_present_layer_kinds_count_dual_equality_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_agrees_with_contributing_tiers_count_dual_equality_pointwise`
// on the tier altitude, and
// `kinds_boundary_agrees_with_present_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_boundary();
let support = slice.present_file_formats_count();
let via_scalar =
support == 0 || support == crate::axis_cardinality::<crate::discovery::Format>();
assert_eq!(
via_seam, via_scalar,
"file_formats_boundary ({via_seam}) must agree with \
present_file_formats_count == 0 || present_file_formats_count == cardinality \
({via_scalar}, support={support})",
);
}
}
#[test]
fn file_formats_boundary_agrees_with_present_and_absent_file_formats_count_dual_equality_pointwise()
{
// Dual-scalar equality surface: `file_formats_boundary() ==
// (present_file_formats_count() == 0 ||
// absent_file_formats_count() == 0)` on every fixture. The
// `present + absent == axis_cardinality` invariant restated
// on the two named cardinality peers, without allocating
// either `Vec<crate::discovery::Format>`. Peer of the
// histogram-side dual-scalar equality form
// `hist.distinct_cells() == 0 || hist.unobserved_cells() == 0`
// pinned one altitude down. Peer of
// `layer_kinds_boundary_agrees_with_present_and_absent_layer_kinds_count_dual_equality_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_agrees_with_contributing_and_absent_tiers_count_dual_equality_pointwise`
// on the tier altitude, and
// `kinds_boundary_agrees_with_present_and_absent_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_boundary();
let support = slice.present_file_formats_count();
let gap = slice.absent_file_formats_count();
let via_scalar = support == 0 || gap == 0;
assert_eq!(
via_seam, via_scalar,
"file_formats_boundary ({via_seam}) must agree with \
present_file_formats_count == 0 || absent_file_formats_count == 0 \
({via_scalar}, support={support}, gap={gap})",
);
}
}
#[test]
fn file_formats_boundary_empty_chain_is_true() {
// Empty-chain boundary: the empty chain observes zero cells,
// so every cell is unobserved (four zeros on the cardinality-
// `4` axis) — the scan sees no nonzero cell and falls through
// to `true`. `file_formats_boundary` reads `true`. Matches
// `has_boundary` reading `true` on the empty histogram one
// altitude down. Direct witness of the subsumption
// `!file_formats_any_observed ⇒ file_formats_boundary` via
// the empty-chain disjunct. Peer of
// `layer_kinds_boundary_empty_chain_is_true` on the layer-
// kind sub-axis of the same chain altitude,
// `tiers_boundary_empty_map_is_true` on the tier altitude,
// and `kinds_boundary_empty_diff_is_true` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.file_formats_boundary());
assert!(!empty.file_formats_any_observed());
}
#[test]
fn file_formats_boundary_no_recognized_files_is_true() {
// Non-empty-chain / empty-histogram boundary the file-format
// sub-axis pins that the layer-kind sub-axis does *not*. A
// chain of only `Defaults` / `Env` / unrecognized-extension
// `File` layers is non-empty but has no `Some` file-format
// projection, so the histogram is empty (four zeros on the
// cardinality-`4` axis) — the scan sees no nonzero cell and
// falls through to `true`. `file_formats_boundary` reads
// `true` via the empty-histogram disjunct. Cross-sub-axis
// divergence pin against `layer_kinds_boundary`: on the same
// fixtures the layer-kind sub-axis observes at least one
// layer-kind cell (Defaults / Env / File) with partial
// support, so `layer_kinds_boundary` typically reads `false`
// — the narrower file-format boundary still fires via the
// partial-function projection's empty-histogram case. Peer
// of `file_formats_singular_no_recognized_files_is_false`
// via the disjoint-corner relationship — the singular near-
// boundary corner does not fire on the same fixture that
// sits on the boundary corner.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(slice.file_format_histogram().is_empty());
assert!(!slice.file_formats_any_observed());
assert!(slice.file_formats_boundary());
}
}
#[test]
fn file_formats_boundary_singleton_support_is_false() {
// Singleton-support pin: `sample_chain()` observes only Yaml
// (two `.yaml` file layers + one Env layer), so the file-
// format support cardinality is `1` (one nonzero and three
// zeros on the cardinality-`4` axis) — the scan sees a
// nonzero cell *and* a zero cell and returns `false`.
// `file_formats_boundary` reads `false`. Direct witness of
// the disjointness `file_formats_singular_support ⇒
// !file_formats_boundary` via the mixed-parity witness. Peer
// of `layer_kinds_boundary_singleton_support_is_false` on the
// layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_singleton_support_is_false` on the tier
// altitude, and `kinds_boundary_singleton_support_is_false`
// on the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(!slice.file_formats_boundary());
assert!(slice.file_formats_singular_support());
}
#[test]
fn file_formats_boundary_two_format_partial_cover_is_false() {
// Two-format-cover pin — the *first non-vacuous* strict-
// interior disjointness witness on the chain altitude for
// the boundary corner. A chain observing exactly two file-
// format cells (`.yaml + .toml`) reads
// `strict_partial_cover=true` on the cardinality-`4`
// `crate::discovery::Format` axis; support cardinality `2`
// satisfies neither `support == 0` nor `support ==
// cardinality`, so `file_formats_boundary` reads `false`.
// Direct witness of the *non-vacuous* strict disjointness
// `file_formats_strict_partial_cover ⇒
// !file_formats_boundary` — unavailable at the cardinality-
// `3` layer-kind sub-axis where the strict-interior
// antecedent is vacuous. Matches the tier altitude
// (cardinality-`4` `ConfigTierKind`) — the two-tier partial-
// cover fixture there reads
// `tiers_strict_partial_cover=true, tiers_boundary=false`
// on the same strict-interior boundary.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(slice.file_format_histogram().count(Format::Yaml) > 0);
assert!(slice.file_format_histogram().count(Format::Toml) > 0);
assert!(slice.file_formats_strict_partial_cover());
assert!(!slice.file_formats_boundary());
}
#[test]
fn file_formats_boundary_three_format_partial_cover_is_false() {
// Three-format-cover pin: a chain observing exactly three
// file-format cells (`.yaml + .toml + .lisp`) sits at
// support cardinality `3` = `axis_cardinality - 1`, exactly
// the singleton-gap boundary on the cardinality-`4` axis —
// the scan sees a nonzero and a zero cell and returns
// `false`. `file_formats_boundary` reads `false`. Direct
// witness of the disjointness `file_formats_singular_gap ⇒
// !file_formats_boundary` via the mixed-parity witness —
// the singleton-gap boundary is a singular near-boundary
// corner, disjoint from the boundary corners of the
// distance ternary. Distinguishes the file-format sub-axis
// from the layer-kind sub-axis where the two-kind partial
// cover at support `2` is the singleton-gap fixture on the
// cardinality-`3` axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert!(slice.file_formats_singular_gap());
assert!(!slice.file_formats_boundary());
}
#[test]
fn file_formats_boundary_uniform_cover_is_true() {
// Uniform-cover pin: every file-format cell contributes at
// least one recognized-extension file layer, so the support
// cardinality is `4` (no unobserved cells on the cardinality-
// `4` axis) — the scan sees only nonzero cells and falls
// through to `true`. `file_formats_boundary` reads `true`.
// Direct witness of the subsumption `file_formats_full_cover
// ⇒ file_formats_boundary` via the full-cover disjunct. Peer
// of `layer_kinds_boundary_uniform_cover_is_true` on the
// layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_uniform_cover_is_true` on the tier
// altitude, and `kinds_boundary_uniform_cover_is_true` on
// the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_formats_full_cover());
assert!(slice.file_formats_boundary());
}
#[test]
fn file_formats_not_any_observed_implies_file_formats_boundary_pointwise() {
// Subsumption pin: `!file_formats_any_observed() ⇒
// file_formats_boundary()` always via the bottom-boundary
// disjunct of the defining union. The empty chain AND every
// empty-histogram non-empty chain (no-recognized-files) sit
// inside the boundary corner. Peer of
// `layer_kinds_not_any_observed_implies_layer_kinds_boundary_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_not_any_observed_implies_tiers_boundary_pointwise`
// on the tier altitude, and
// `kinds_not_any_observed_implies_kinds_boundary_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if !slice.file_formats_any_observed() {
assert!(
slice.file_formats_boundary(),
"empty-histogram chain must be on boundary",
);
}
}
}
#[test]
fn file_formats_full_cover_implies_file_formats_boundary_pointwise() {
// Subsumption pin: `file_formats_full_cover() ⇒
// file_formats_boundary()` always via the top-boundary
// disjunct of the defining union. The full-cover chain
// always sits inside the boundary corner. Peer of
// `layer_kinds_full_cover_implies_layer_kinds_boundary_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_full_cover_implies_tiers_boundary_pointwise` on
// the tier altitude, and
// `kinds_full_cover_implies_kinds_boundary_pointwise` on
// the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() {
assert!(
slice.file_formats_boundary(),
"full-cover chain must be on boundary",
);
}
}
}
#[test]
fn file_formats_boundary_implies_not_file_formats_singular_pointwise() {
// Disjointness pin: `file_formats_boundary() ⇒
// !file_formats_singular()` on every axis with cardinality
// `>= 2`. The two boundary cardinalities (`0` and
// `cardinality`) sit strictly outside the two singular
// cardinalities (`1` and `cardinality - 1`) — the boundary
// corner and the singular near-boundary corner are pairwise
// disjoint legs of the distance ternary. Peer of
// `layer_kinds_boundary_implies_not_layer_kinds_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_implies_not_tiers_singular_pointwise` on
// the tier altitude, and
// `kinds_boundary_implies_not_kinds_singular_pointwise` on
// the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_boundary() {
assert!(
!slice.file_formats_singular(),
"boundary chain cannot be singular on a cardinality \
>= 2 axis",
);
}
}
}
#[test]
fn file_formats_boundary_implies_not_file_formats_strict_partial_cover_pointwise() {
// Disjointness pin: `file_formats_boundary() ⇒
// !file_formats_strict_partial_cover()` always. The strict-
// interior interval `[2, cardinality - 2]` never contains
// the two boundary cardinalities `0` and `cardinality` —
// the third pairwise-disjointness leg of the distance
// ternary. *Non-vacuous* on the cardinality-`4` file-format
// axis (the two-format partial cover fixture is the strict-
// interior witness reading `strict_partial_cover=true,
// boundary=false`) — a strict advance over the layer-kind
// sub-axis where the strict interior is unreachable and
// the disjointness holds vacuously. Matches the tier
// altitude's non-vacuous disjointness on the same
// cardinality-`4` `ConfigTierKind` axis. Peer of
// `layer_kinds_boundary_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_boundary_implies_not_kinds_strict_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_boundary() {
assert!(
!slice.file_formats_strict_partial_cover(),
"boundary chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn file_formats_boundary_file_formats_singular_file_formats_strict_partial_cover_form_ternary_partition_pointwise()
{
// Ternary partition pin at the chain file-format sub-axis
// via the named seam: exactly one of the three legs
// `(file_formats_boundary, file_formats_singular,
// file_formats_strict_partial_cover)` fires on every chain
// — the distance-from-boundary ternary of the 5-corner
// support-cardinality partition. Every leg is inhabited on
// the cardinality-`4` file-format axis — the ternary closes
// strictly *and* non-vacuously (interval `[2, cardinality -
// 2] = [2, 2]` is non-empty) — matching the tier altitude
// on the same cardinality-`4` `ConfigTierKind` axis and
// diverging from the layer-kind sub-axis and the diff
// altitude where the third leg vanishes and the ternary
// degenerates pointwise to the dual `(has_boundary,
// has_singular)`. The `file_formats_boundary` seam now
// names the top leg of the ternary directly at the surface,
// replacing the open-coded `!file_formats_any_observed ||
// file_formats_full_cover` disjunction used by the sibling
// `file_formats_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise`
// pin (still kept alongside as the open-coded parity
// witness). Peer of
// `layer_kinds_boundary_layer_kinds_singular_layer_kinds_strict_partial_cover_form_ternary_partition_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_tiers_singular_tiers_strict_partial_cover_form_ternary_partition_pointwise`
// on the tier altitude, and
// `kinds_boundary_kinds_singular_kinds_strict_partial_cover_form_ternary_partition_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let boundary = slice.file_formats_boundary();
let singular = slice.file_formats_singular();
let strict = slice.file_formats_strict_partial_cover();
let count = usize::from(boundary) + usize::from(singular) + usize::from(strict);
assert_eq!(
count, 1,
"exactly one of (boundary, singular, strict_partial_cover) \
must fire (boundary={boundary}, singular={singular}, \
strict={strict})",
);
}
}
#[test]
fn file_formats_boundary_and_file_formats_partial_cover_form_strict_bipartition_pointwise() {
// Strict-bipartition pin at the chain file-format sub-axis:
// `file_formats_boundary` and its complement
// `file_formats_any_observed && !file_formats_full_cover`
// (the partial-cover strict interior at the file-format
// sub-axis) are pointwise complementary — exactly one fires
// on every chain. The named boundary corner is the exact
// complement of the partial-cover strict interior. Peer of
// the histogram-side bipartition law
// `axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`
// one altitude down,
// `layer_kinds_boundary_and_layer_kinds_partial_cover_form_strict_bipartition_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_and_tiers_partial_cover_form_strict_bipartition_pointwise`
// on the tier altitude, and
// `kinds_boundary_and_kinds_partial_cover_form_strict_bipartition_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let boundary = slice.file_formats_boundary();
let partial = slice.file_formats_any_observed() && !slice.file_formats_full_cover();
let count = usize::from(boundary) + usize::from(partial);
assert_eq!(
count, 1,
"exactly one of (boundary, partial_cover) must fire \
(boundary={boundary}, partial={partial})",
);
}
}
#[test]
fn file_formats_boundary_bridges_support_cardinality_class_is_boundary_pointwise() {
// Cross-surface bridge law: `file_formats_boundary() ==
// file_format_histogram().support_cardinality_class().is_boundary()`
// on every fixture. The class-side projection lands on
// `SupportCardinalityClass::Empty` or
// `SupportCardinalityClass::FullCover` exactly when the
// histogram-side disjunction fires, and
// `SupportCardinalityClass::is_boundary` reads `true` on
// either variant. Peer of the histogram-side bridge
// `axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor`
// one altitude down, closing the (histogram, class) duality
// on the boundary leg at the chain file-format sub-axis.
// Peer of
// `layer_kinds_boundary_bridges_support_cardinality_class_is_boundary_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_bridges_support_cardinality_class_is_boundary_pointwise`
// on the tier altitude, and
// `kinds_boundary_bridges_support_cardinality_class_is_boundary_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_boundary();
let via_class = slice
.file_format_histogram()
.support_cardinality_class()
.is_boundary();
assert_eq!(
via_seam, via_class,
"file_formats_boundary ({via_seam}) must agree with \
file_format_histogram().support_cardinality_class().is_boundary() \
({via_class})",
);
}
}
#[test]
fn file_formats_boundary_agrees_with_open_coded_uniform_parity_walk() {
// Parity against the exact hand-rolled boundary walk this
// lift replaces on cardinality-`>= 1` axes: walk every cell
// of the histogram and count how many carry a zero count
// and how many carry a nonzero count; the boundary predicate
// reads `true` iff every cell is zero (empty) or every cell
// is nonzero (full cover) — i.e. not both a zero *and* a
// nonzero cell appear. Peer of
// `layer_kinds_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the tier altitude, and
// `kinds_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_boundary();
let hist = slice.file_format_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros == 0 || nonzeros == 0;
assert_eq!(via_seam, hand_rolled);
}
}
// ── file_formats_partial_cover coverage — the partial-cover-file-
// formats middle-leg corner of the coverage trichotomy
// `(!file_formats_any_observed, file_formats_partial_cover,
// file_formats_full_cover)` at the chain file-format sub-axis,
// lifting the layer-kind sub-axis sideways
// `layer_kinds_partial_cover` to the second chain-altitude sub-
// axis. On the cardinality-`4` `Format` axis the strict-interior
// subsumption `file_formats_strict_partial_cover ⇒
// file_formats_partial_cover` carries content non-vacuously —
// matches the tier altitude and diverges from the layer-kind
// sub-axis and the diff altitude where the strict-interior
// antecedent is vacuous. The file-format projection is a partial
// function, so the no-recognized-files non-empty-chain fixture
// silently drops out of the partial-cover middle leg (unlike
// `layer_kinds_partial_cover` which typically fires there via
// partial layer-kind support). Middle-leg peer of
// `file_formats_boundary` / `layer_kinds_partial_cover` /
// `tiers_partial_cover` / `kinds_partial_cover`. ──
#[test]
fn file_formats_partial_cover_matches_file_format_histogram_has_partial_cover_pointwise() {
// Routing pin: `file_formats_partial_cover` routes through
// `file_format_histogram().has_partial_cover()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. File-
// format sub-axis peer of
// `layer_kinds_partial_cover_matches_layer_kind_histogram_has_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_matches_tier_histogram_has_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_matches_kind_histogram_has_partial_cover_pointwise`
// on the diff altitude, in the "partial-cover across altitudes"
// projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().has_partial_cover();
assert_eq!(slice.file_formats_partial_cover(), via_histogram);
}
}
#[test]
fn file_formats_partial_cover_matches_defining_conjunction_of_negations_pointwise() {
// Defining conjunction-of-negations form:
// `file_formats_partial_cover() ⇔ file_formats_any_observed() &&
// !file_formats_full_cover()`. Pins the predicate against the
// two-way conjunction on the two named coverage-boundary peers
// consumers reach for when they open-code the middle-leg corner
// as a boolean fold over the two extreme coverage cardinalities.
// The middle-leg-fold peer of the two boundary corners — the
// exact expression used verbatim by the pre-existing bipartition-
// law pin
// `file_formats_boundary_and_file_formats_partial_cover_form_strict_bipartition_pointwise`.
// Peer of
// `layer_kinds_partial_cover_matches_defining_conjunction_of_negations_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_matches_defining_conjunction_of_negations_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_matches_defining_conjunction_of_negations_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_partial_cover();
let via_conjunction =
slice.file_formats_any_observed() && !slice.file_formats_full_cover();
assert_eq!(
via_seam, via_conjunction,
"file_formats_partial_cover ({via_seam}) must agree with \
file_formats_any_observed && !file_formats_full_cover ({via_conjunction})",
);
}
}
#[test]
fn file_formats_partial_cover_agrees_with_present_file_formats_count_strict_interval_pointwise()
{
// Support-scalar strict-interval surface:
// `file_formats_partial_cover() == (0 < present_file_formats_count()
// && present_file_formats_count() <
// axis_cardinality::<crate::discovery::Format>())` on every
// fixture. The support-side surfacing of the same boolean,
// without allocating `Vec<crate::discovery::Format>`. On every
// cardinality-`>= 2` axis the interval `(0, cardinality)` is
// non-empty. Peer of
// `layer_kinds_partial_cover_agrees_with_present_layer_kinds_count_strict_interval_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_agrees_with_contributing_tiers_count_strict_interval_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_agrees_with_present_kinds_count_strict_interval_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_partial_cover();
let support = slice.present_file_formats_count();
let via_scalar =
0 < support && support < crate::axis_cardinality::<crate::discovery::Format>();
assert_eq!(
via_seam, via_scalar,
"file_formats_partial_cover ({via_seam}) must agree with \
0 < present_file_formats_count < cardinality \
({via_scalar}, support={support})",
);
}
}
#[test]
fn file_formats_partial_cover_agrees_with_absent_file_formats_count_strict_interval_pointwise()
{
// Coverage-gap dual-scalar strict-interval surface:
// `file_formats_partial_cover() == (0 < absent_file_formats_count()
// && absent_file_formats_count() <
// axis_cardinality::<crate::discovery::Format>())` on every
// fixture. The `present + absent == axis_cardinality`
// invariant restated on the two named cardinality peers,
// without allocating `Vec<crate::discovery::Format>`. Peer of
// the histogram-side dual-scalar strict-interval form
// `0 < hist.unobserved_cells() && hist.unobserved_cells() <
// axis_cardinality::<A>()` pinned one altitude down. Peer of
// `layer_kinds_partial_cover_agrees_with_absent_layer_kinds_count_strict_interval_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_agrees_with_absent_tiers_count_strict_interval_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_agrees_with_absent_kinds_count_strict_interval_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_partial_cover();
let gap = slice.absent_file_formats_count();
let via_scalar = 0 < gap && gap < crate::axis_cardinality::<crate::discovery::Format>();
assert_eq!(
via_seam, via_scalar,
"file_formats_partial_cover ({via_seam}) must agree with \
0 < absent_file_formats_count < cardinality \
({via_scalar}, gap={gap})",
);
}
}
#[test]
fn file_formats_partial_cover_agrees_with_present_and_absent_file_formats_count_both_positive_pointwise()
{
// Mixed-side dual-scalar non-emptiness surface:
// `file_formats_partial_cover() == (present_file_formats_count() > 0
// && absent_file_formats_count() > 0)` on every fixture. The
// direct histogram-surface `distinct_cells > 0 &&
// unobserved_cells > 0` pin restated at the chain file-format
// sub-axis — the boolean asking "did the chain see at least
// one format *and* miss at least one format?" against the two
// named cardinality peers, without allocating either
// `Vec<crate::discovery::Format>`. Peer of the sibling
// `file_formats_boundary` dual-scalar equality form
// `present_file_formats_count == 0 || absent_file_formats_count
// == 0` (its exact strict-complement) one seam over on the
// coverage-trichotomy bipartition. Peer of
// `layer_kinds_partial_cover_agrees_with_present_and_absent_layer_kinds_count_both_positive_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_agrees_with_contributing_and_absent_tiers_count_both_positive_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_agrees_with_present_and_absent_kinds_count_both_positive_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_partial_cover();
let support = slice.present_file_formats_count();
let gap = slice.absent_file_formats_count();
let via_scalar = support > 0 && gap > 0;
assert_eq!(
via_seam, via_scalar,
"file_formats_partial_cover ({via_seam}) must agree with \
present_file_formats_count > 0 && absent_file_formats_count > 0 \
({via_scalar}, support={support}, gap={gap})",
);
}
}
#[test]
fn file_formats_partial_cover_empty_chain_is_false() {
// Empty-chain partial-cover: the empty chain observes zero
// cells, so every cell is unobserved (four zeros on the
// cardinality-`4` axis) — the scan sees no nonzero cell and
// falls through to `false`. `file_formats_partial_cover`
// reads `false`. Matches `has_partial_cover` reading `false`
// on the empty histogram one altitude down. Direct witness
// of the disjointness
// `!file_formats_any_observed ⇒ !file_formats_partial_cover`
// via the empty-chain disjunct of `file_formats_boundary`.
// Peer of `layer_kinds_partial_cover_empty_chain_is_false`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_empty_map_is_false` on the tier
// altitude, and `kinds_partial_cover_empty_diff_is_false` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_partial_cover());
assert!(!empty.file_formats_any_observed());
assert!(empty.file_formats_boundary());
}
#[test]
fn file_formats_partial_cover_no_recognized_files_is_false() {
// Non-empty-chain / empty-histogram partial-cover — the
// file-format sub-axis cross-sub-axis divergence pin against
// the layer-kind sub-axis. A chain of only `Defaults` /
// `Env` / unrecognized-extension `File` layers is non-empty
// but has no `Some` file-format projection, so the histogram
// is empty (four zeros on the cardinality-`4` axis) — the
// scan sees no nonzero cell and falls through to `false`.
// `file_formats_partial_cover` reads `false` via the empty-
// histogram case. Direct divergence pin against
// `layer_kinds_partial_cover`: on the same fixtures the
// layer-kind sub-axis observes at least one layer-kind cell
// (Defaults / Env / File) at partial support and typically
// reads `layer_kinds_partial_cover = true`, while the file-
// format sub-axis's partial-cover middle leg silently drops
// out via the empty-histogram case of the strict-complement
// `file_formats_boundary` corner. Peer of
// `file_formats_boundary_no_recognized_files_is_true` via
// the disjoint-corner relationship — every no-recognized-
// files chain sits on `file_formats_boundary = true`, so
// the bipartition still holds. Peer of
// `file_formats_singular_no_recognized_files_is_false` and
// `file_formats_singular_gap_no_recognized_files_is_false`
// on the same fixtures — the singular near-boundary corners
// also drop out via the empty-histogram case.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(slice.file_format_histogram().is_empty());
assert!(!slice.file_formats_any_observed());
assert!(!slice.file_formats_partial_cover());
assert!(slice.file_formats_boundary());
}
}
#[test]
fn file_formats_partial_cover_singleton_support_is_true() {
// Singleton-support pin: `sample_chain()` observes only Yaml
// (two `.yaml` file layers + one Env layer), so the file-
// format support cardinality is `1` (one nonzero and three
// zeros on the cardinality-`4` axis) — the scan sees a
// nonzero cell *and* a zero cell and returns `true`.
// `file_formats_partial_cover` reads `true`. Direct witness
// of the subsumption
// `file_formats_singular_support ⇒ file_formats_partial_cover`
// via the mixed-parity witness. Peer of
// `layer_kinds_partial_cover_singleton_support_is_true` on
// the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_singleton_support_is_true` on the
// tier altitude, and
// `kinds_partial_cover_singleton_support_is_true` on the
// diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_partial_cover());
assert!(slice.file_formats_singular_support());
}
#[test]
fn file_formats_partial_cover_two_format_partial_cover_is_true() {
// Two-format-cover pin — the *first non-vacuous* strict-
// interior subsumption witness on the chain altitude for the
// partial-cover middle-leg corner. A chain observing exactly
// two file-format cells (`.yaml + .toml`) reads
// `strict_partial_cover=true` on the cardinality-`4`
// `crate::discovery::Format` axis; support cardinality `2`
// satisfies `0 < support < cardinality`, so
// `file_formats_partial_cover` reads `true`. Direct witness
// of the *non-vacuous* strict-interior subsumption
// `file_formats_strict_partial_cover ⇒
// file_formats_partial_cover` — unavailable at the
// cardinality-`3` layer-kind sub-axis where the strict-
// interior antecedent is vacuous. Matches the tier altitude
// (cardinality-`4` `ConfigTierKind`) — the two-tier partial-
// cover fixture there reads
// `tiers_strict_partial_cover=true, tiers_partial_cover=true`
// on the same strict-interior middle leg.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(slice.file_format_histogram().count(Format::Yaml) > 0);
assert!(slice.file_format_histogram().count(Format::Toml) > 0);
assert!(slice.file_formats_strict_partial_cover());
assert!(slice.file_formats_partial_cover());
}
#[test]
fn file_formats_partial_cover_three_format_partial_cover_is_true() {
// Three-format-cover pin: a chain observing exactly three
// file-format cells (`.yaml + .toml + .lisp`) sits at
// support cardinality `3` = `axis_cardinality - 1`, exactly
// the singleton-gap boundary on the cardinality-`4` axis —
// the scan sees a nonzero and a zero cell and returns
// `true`. `file_formats_partial_cover` reads `true`. Direct
// witness of the subsumption `file_formats_singular_gap ⇒
// file_formats_partial_cover` via the mixed-parity witness
// — the singleton-gap boundary is a singular near-boundary
// corner, inside the partial-cover middle leg of the
// coverage trichotomy. Peer of
// `tiers_partial_cover_three_tier_partial_cover_is_true` on
// the tier altitude in the same shape on the cardinality-
// `4` `ConfigTierKind` axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert!(slice.file_formats_partial_cover());
assert!(slice.file_formats_singular_gap());
}
#[test]
fn file_formats_partial_cover_uniform_cover_is_false() {
// Uniform-cover pin: every file-format cell contributes at
// least one recognized-extension file layer, so the support
// cardinality is `4` (no unobserved cells on the cardinality-
// `4` axis) — the scan sees only nonzero cells and falls
// through to `false`. `file_formats_partial_cover` reads
// `false`. Direct witness of the disjointness
// `file_formats_full_cover ⇒ !file_formats_partial_cover`
// via the full-cover boundary of `file_formats_boundary`.
// Peer of `layer_kinds_partial_cover_uniform_cover_is_false`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_uniform_cover_is_false` on the tier
// altitude, and `kinds_partial_cover_uniform_cover_is_false`
// on the diff altitude.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert!(slice.file_formats_full_cover());
assert!(!slice.file_formats_partial_cover());
}
#[test]
fn file_formats_partial_cover_and_file_formats_boundary_form_strict_bipartition_pointwise() {
// Strict-bipartition pin at the chain file-format sub-axis
// *with the named seam*: `file_formats_partial_cover` and
// `file_formats_boundary` are pointwise complementary —
// exactly one fires on every chain. The named partial-cover
// corner is the exact complement of the named boundary
// corner. Peer of the pre-existing pin
// `file_formats_boundary_and_file_formats_partial_cover_form_strict_bipartition_pointwise`
// (kept alongside as the open-coded parity witness against
// `file_formats_any_observed && !file_formats_full_cover`),
// and peer of the histogram-side bipartition law
// `axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`
// one altitude down. The `file_formats_partial_cover` seam
// now names the middle leg of the coverage trichotomy
// directly at the surface, replacing the open-coded
// conjunction-of-negations expression used by the pre-
// existing pin. Peer of
// `layer_kinds_partial_cover_and_layer_kinds_boundary_form_strict_bipartition_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_and_tiers_boundary_form_strict_bipartition_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_and_kinds_boundary_form_strict_bipartition_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let partial = slice.file_formats_partial_cover();
let boundary = slice.file_formats_boundary();
let count = usize::from(partial) + usize::from(boundary);
assert_eq!(
count, 1,
"exactly one of (partial_cover, boundary) must fire \
(partial={partial}, boundary={boundary})",
);
}
}
#[test]
fn file_formats_partial_cover_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_partial_cover() ⇒
// file_formats_any_observed()` always via the "at least one
// observed" half of the defining conjunction. Every partial-
// cover chain observes at least one cell — the middle-leg
// corner sits on the `true` side of the any-observed
// boundary. Peer of
// `layer_kinds_partial_cover_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_implies_tiers_any_observed_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_partial_cover() {
assert!(
slice.file_formats_any_observed(),
"partial-cover chain must observe at least one cell",
);
}
}
}
#[test]
fn file_formats_partial_cover_implies_not_file_formats_full_cover_pointwise() {
// Subsumption pin: `file_formats_partial_cover() ⇒
// !file_formats_full_cover()` always via the "at least one
// unobserved" half of the defining conjunction. Every
// partial-cover chain misses at least one cell — the middle-
// leg corner sits strictly below the full-cover top boundary.
// Peer of
// `layer_kinds_partial_cover_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_implies_not_tiers_full_cover_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_implies_not_kinds_full_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_partial_cover() {
assert!(
!slice.file_formats_full_cover(),
"partial-cover chain cannot be full-cover",
);
}
}
}
#[test]
fn file_formats_singular_support_implies_file_formats_partial_cover_pointwise() {
// Subsumption pin: `file_formats_singular_support() ⇒
// file_formats_partial_cover()` always on cardinality-`>= 2`
// axes. Support cardinality `1` is strictly between `0` and
// cardinality — the singular-support boundary sits inside
// the partial-cover middle leg. Direct pin of the histogram-
// side subsumption `has_singular_support ⇒
// has_partial_cover` one altitude down. Peer of
// `layer_kinds_singular_support_implies_layer_kinds_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_support_implies_tiers_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_singular_support_implies_kinds_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
slice.file_formats_partial_cover(),
"singular-support chain must be partial-cover",
);
}
}
}
#[test]
fn file_formats_singular_gap_implies_file_formats_partial_cover_pointwise() {
// Subsumption pin: `file_formats_singular_gap() ⇒
// file_formats_partial_cover()` always on cardinality-`>= 2`
// axes. Support cardinality `cardinality - 1` is strictly
// between `0` and cardinality — the singular-gap boundary
// sits inside the partial-cover middle leg. Peer of the
// opposite-end subsumption on the support-cardinality
// interval, closing the dual-singular pair
// `(has_singular_support, has_singular_gap) ⇒
// has_partial_cover` at the chain file-format sub-axis. Peer
// of
// `layer_kinds_singular_gap_implies_layer_kinds_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_gap_implies_tiers_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_singular_gap_implies_kinds_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_gap() {
assert!(
slice.file_formats_partial_cover(),
"singular-gap chain must be partial-cover",
);
}
}
}
#[test]
fn file_formats_singular_implies_file_formats_partial_cover_pointwise() {
// Subsumption pin: `file_formats_singular() ⇒
// file_formats_partial_cover()` always on cardinality-`>= 2`
// axes. The union of the two singular-side subsumptions
// lands the middle-leg singular corners inside the partial-
// cover middle leg. Direct fold over the disjunction — the
// singular near-boundary corner of the distance ternary
// sits inside the partial-cover middle leg of the coverage
// trichotomy. Peer of
// `layer_kinds_singular_implies_layer_kinds_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_implies_tiers_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_singular_implies_kinds_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular() {
assert!(
slice.file_formats_partial_cover(),
"singular chain must be partial-cover",
);
}
}
}
#[test]
fn file_formats_strict_partial_cover_implies_file_formats_partial_cover_pointwise() {
// Subsumption pin: `file_formats_strict_partial_cover() ⇒
// file_formats_partial_cover()` always. The strict interior
// sits inside the partial-cover middle leg by definition.
// Direct pin of the histogram-side subsumption
// `has_strict_partial_cover ⇒ has_partial_cover` one
// altitude down. **Non-vacuous** at the file-format sub-axis
// — the two-format partial cover fixture on the cardinality-
// `4` `crate::discovery::Format` axis reads
// `strict_partial_cover=true, partial_cover=true`, a strict
// advance over the layer-kind sub-axis where the strict-
// interior antecedent is vacuous and the subsumption holds
// only trivially. Peer of
// `layer_kinds_strict_partial_cover_implies_layer_kinds_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_strict_partial_cover_implies_tiers_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_strict_partial_cover_implies_kinds_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_strict_partial_cover() {
assert!(
slice.file_formats_partial_cover(),
"strict-partial-cover chain must be partial-cover",
);
}
}
}
#[test]
fn file_formats_partial_cover_and_file_formats_any_observed_negation_and_file_formats_full_cover_form_coverage_trichotomy_pointwise()
{
// Coverage-trichotomy partition pin at the chain file-format
// sub-axis: exactly one of the three legs
// `(!file_formats_any_observed, file_formats_partial_cover,
// file_formats_full_cover)` fires on every chain — the
// coverage trichotomy of the `(is_empty, has_partial_cover,
// is_full_cover)` histogram-side partition restated at the
// chain file-format sub-axis. Peer of the trait-uniform pin
// `axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor`
// one altitude down. The `file_formats_partial_cover` seam
// now carries the middle leg of this partition directly at
// the surface, folding the open-coded expression
// `file_formats_any_observed && !file_formats_full_cover`
// (the surface used verbatim by the pre-existing bipartition-
// law pin
// `file_formats_boundary_and_file_formats_partial_cover_form_strict_bipartition_pointwise`)
// into one named boolean. Peer of
// `layer_kinds_partial_cover_and_layer_kinds_any_observed_negation_and_layer_kinds_full_cover_form_coverage_trichotomy_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_and_tiers_any_observed_negation_and_tiers_full_cover_form_coverage_trichotomy_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_and_kinds_any_observed_negation_and_kinds_full_cover_form_coverage_trichotomy_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let empty = !slice.file_formats_any_observed();
let partial = slice.file_formats_partial_cover();
let full = slice.file_formats_full_cover();
let count = usize::from(empty) + usize::from(partial) + usize::from(full);
assert_eq!(
count, 1,
"exactly one of (!any_observed, partial_cover, full_cover) \
must fire (empty={empty}, partial={partial}, full={full})",
);
}
}
#[test]
fn file_formats_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise() {
// Cross-surface bridge law: `file_formats_partial_cover() ==
// file_format_histogram().support_cardinality_class().is_partial_cover()`
// on every fixture. The class-side projection lands on
// `SupportCardinalityClass::SingularSupport`,
// `SupportCardinalityClass::StrictPartialCover`, or
// `SupportCardinalityClass::SingularGap` exactly when the
// histogram-side conjunction fires, and
// `SupportCardinalityClass::is_partial_cover` reads `true`
// on any of the three variants. Peer of the histogram-side
// bridge
// `axis_histogram_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover_for_every_closed_axis_implementor`
// one altitude down, closing the (histogram, class) duality
// on the partial-cover middle leg at the chain file-format
// sub-axis. Peer of
// `layer_kinds_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_partial_cover();
let via_class = slice
.file_format_histogram()
.support_cardinality_class()
.is_partial_cover();
assert_eq!(
via_seam, via_class,
"file_formats_partial_cover ({via_seam}) must agree with \
file_format_histogram().support_cardinality_class().is_partial_cover() \
({via_class})",
);
}
}
#[test]
fn file_formats_partial_cover_agrees_with_open_coded_mixed_parity_walk() {
// Parity against the exact hand-rolled partial-cover walk
// this lift replaces on cardinality-`>= 2` axes: walk every
// cell of the histogram and count how many carry a zero
// count and how many carry a nonzero count; the partial-
// cover predicate reads `true` iff *both* a zero cell *and*
// a nonzero cell appear. Mirrors the parity pin
// `file_formats_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the strict-complement top-leg projection — the two
// parity walks are pointwise complementary on every
// cardinality-`>= 1` axis. Peer of
// `layer_kinds_partial_cover_agrees_with_open_coded_mixed_parity_walk`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_agrees_with_open_coded_mixed_parity_walk`
// on the tier altitude, and
// `kinds_partial_cover_agrees_with_open_coded_mixed_parity_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_partial_cover();
let hist = slice.file_format_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros > 0 && nonzeros > 0;
assert_eq!(via_seam, hand_rolled);
}
}
// ── file_formats_modally_tied coverage — the modally-tied-file-
// formats boolean predicate on the file-format sub-axis of the
// chain altitude, lifting the layer-kind-sub-axis
// `layer_kinds_modally_tied` sideways to the second chain-
// altitude sub-axis, matching the tier-altitude climb
// `tiers_modally_tied` and the diff-altitude seed
// `ConfigDiff::kinds_modally_tied`. Modal-side row on top of
// the closed coverage-support predicate cube (`low_support`,
// `high_support`, `strict_partial_cover`, `singular`,
// `boundary`, `partial_cover`) — the seventh projection to
// appear at the file-format sub-axis, matching the cadence
// set by the six sibling projections already closed at every
// altitude / sub-axis. Direct strict-complement peer of the
// histogram-side `is_strictly_modally_unique` primitive on
// every non-empty file-format histogram. ──
#[test]
fn file_formats_modally_tied_matches_file_format_histogram_is_modally_tied_pointwise() {
// Routing pin: `file_formats_modally_tied` routes through
// `file_format_histogram().is_modally_tied()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. File-
// format sub-axis peer of
// `layer_kinds_modally_tied_matches_layer_kind_histogram_is_modally_tied_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_modally_tied_matches_tier_histogram_is_modally_tied_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_matches_kind_histogram_is_modally_tied_pointwise`
// on the diff altitude, in the "modally-tied across
// altitudes" projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().is_modally_tied();
assert_eq!(slice.file_formats_modally_tied(), via_histogram);
}
}
#[test]
fn file_formats_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise() {
// Defining multiplicity-scalar inequality form:
// `file_formats_modally_tied() ⇔
// file_format_histogram().peak_multiplicity() >= 2`. Pins the
// predicate against the canonical open-coded expression on
// the `AxisHistogram::peak_multiplicity` scalar peer one
// altitude down — the surface consumers reach for when they
// open-code "two or more cells tied at the peak". Peer of
// `layer_kinds_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_modally_tied();
let mult = slice.file_format_histogram().peak_multiplicity();
let via_scalar = mult >= 2;
assert_eq!(
via_seam, via_scalar,
"file_formats_modally_tied ({via_seam}) must agree with \
peak_multiplicity >= 2 ({via_scalar}, mult={mult})",
);
}
}
#[test]
fn file_formats_modally_tied_matches_modality_degree_modal_component_pointwise() {
// Modality-pair projection-inequality form:
// `file_formats_modally_tied() ⇔
// file_format_histogram().modality_degree().0 >= 2`. Pins the
// predicate against the modal-component reading of the fused
// `(peak_multiplicity, trough_multiplicity)` pair, the second
// documented surface form consumers reach for when they read
// the classifier pair before the comparison. Peer of
// `layer_kinds_modally_tied_matches_modality_degree_modal_component_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_modally_tied_matches_modality_degree_modal_component_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_matches_modality_degree_modal_component_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_modally_tied();
let (peak_mult, _) = slice.file_format_histogram().modality_degree();
let via_pair = peak_mult >= 2;
assert_eq!(
via_seam, via_pair,
"file_formats_modally_tied ({via_seam}) must agree with \
modality_degree().0 >= 2 ({via_pair}, peak_mult={peak_mult})",
);
}
}
#[test]
fn file_formats_modally_tied_empty_chain_is_false() {
// Empty-chain modal-tie: the empty chain observes zero cells,
// so `peak_multiplicity` reads `0` and the inequality `0 >= 2`
// fails. `file_formats_modally_tied` reads `false`. Matches
// `is_modally_tied` reading `false` on the empty histogram one
// altitude down. Direct witness of the subsumption
// `file_formats_modally_tied ⇒ file_formats_any_observed` via
// the empty-chain disjunct of `!file_formats_any_observed`.
// Peer of `layer_kinds_modally_tied_empty_chain_is_false` on
// the sister sub-axis of the same chain altitude,
// `tiers_modally_tied_empty_map_is_false` on the tier altitude,
// and `kinds_modally_tied_empty_diff_is_false` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_modally_tied());
assert!(!empty.file_formats_any_observed());
}
#[test]
fn file_formats_modally_tied_no_recognized_files_is_false() {
// No-recognized-files pin: a non-empty chain of only
// `Defaults` / `Env` / unrecognized-extension `File` layers
// projects to an empty file-format histogram via the partial
// function `ConfigSource::file_format` — `peak_multiplicity`
// reads `0` and the inequality `0 >= 2` fails.
// `file_formats_modally_tied` reads `false`. Cross-sub-axis
// divergence pin against `layer_kinds_modally_tied`: on the
// same fixture the layer-kind sub-axis observes at least one
// layer-kind cell and may fire the modal-tie predicate (e.g.
// one `Defaults` + one `Env` reads
// `layer_kinds_modally_tied = true`), while the file-format
// sub-axis's modal-tie predicate silently drops out via the
// empty-histogram disjunct — the modal-tie leg is *narrower*
// at the file-format sub-axis than at the layer-kind sub-axis.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert!(
!slice.file_formats_modally_tied(),
"no-recognized-files chain must not fire modally-tied",
);
assert!(!slice.file_formats_any_observed());
}
}
#[test]
fn file_formats_modally_tied_singleton_support_is_false() {
// Singleton-support pin: every recognized file layer lands on
// the same file format, so the lone observed cell stands alone
// at its own peak — `peak_multiplicity` reads `1` and the
// inequality `1 >= 2` fails. `file_formats_modally_tied` reads
// `false`. Direct witness of the subsumption
// `file_formats_singular_support ⇒ !file_formats_modally_tied`
// via the singleton-support corner. The `sample_chain()`
// fixture (two `.yaml` file layers + one Env layer, `{Yaml}`
// file-format support with count `2`) is a witness on the
// `false` side. Peer of
// `layer_kinds_modally_tied_singleton_support_is_false` on the
// sister sub-axis of the same chain altitude,
// `tiers_modally_tied_singleton_support_is_false` on the tier
// altitude, and `kinds_modally_tied_singleton_support_is_false`
// on the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(!slice.file_formats_modally_tied());
}
#[test]
fn file_formats_modally_tied_two_format_uniform_partial_cover_is_true() {
// Two-format uniform-partial-cover pin: a chain of one `.yaml`
// + one `.toml` file layer has two observed cells tied at
// count `1` on the cardinality-`4` `Format` axis —
// `peak_multiplicity` reads `2` and the inequality `2 >= 2`
// fires. `file_formats_modally_tied` reads `true`. Witness on
// the modally-tied side of the strict modal partition.
// Support-`2` reachability at the chain file-format sub-axis,
// matching the support-`2` reachability at the layer-kind
// sub-axis on the cardinality-`3` axis and on the diff
// altitude on the same cardinality-`3` axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(slice.file_formats_modally_tied());
}
#[test]
fn file_formats_modally_tied_three_format_uniform_partial_cover_is_true() {
// Three-format uniform-partial-cover pin: a chain of one
// `.yaml` + one `.toml` + one `.lisp` file layer has three
// observed cells tied at count `1` on the cardinality-`4`
// `Format` axis — `peak_multiplicity` reads `3` and the
// inequality `3 >= 2` fires. `file_formats_modally_tied` reads
// `true`. Support-`3` tied reachability at the chain file-
// format sub-axis — the additional off-singleton support
// cardinality unavailable at the layer-kind sub-axis
// (cardinality-`3`) and the diff altitude (cardinality-`3`),
// matching the tier altitude on the cardinality-`4`
// `ConfigTierKind` axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert!(slice.file_formats_modally_tied());
}
#[test]
fn file_formats_modally_tied_uniform_four_format_cover_is_true() {
// Uniform axis-cover pin: a chain observing every cell of
// `Format` exactly once has four observed cells tied at count
// `1` — `peak_multiplicity` reads `4` and the inequality
// `4 >= 2` fires. `file_formats_modally_tied` reads `true`.
// Peer of the histogram-side axis-cover convention one
// altitude down, which reads `true` on every implementor with
// `axis_cardinality::<A>() >= 2` — the cardinality-`4`
// `Format` axis honours the general condition.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 4);
assert!(slice.file_formats_full_cover());
assert!(slice.file_formats_balanced());
assert!(slice.file_formats_modally_tied());
}
#[test]
fn file_formats_modally_tied_strictly_modal_skewed_chain_is_false() {
// Strictly-modal skewed-chain pin: the `sample_chain()`
// fixture is a *singleton-support* chain on the file-format
// sub-axis (see the singleton-support pin above), so we
// construct a strictly-modal skewed fixture explicitly here:
// two `.yaml` file layers + one `.toml` file layer. `Yaml`
// uniquely peaks at count `2` (Toml sits at `1`, Lisp at `0`,
// Nix at `0`) — `peak_multiplicity` reads `1` and the
// inequality `1 >= 2` fails. `file_formats_modally_tied` reads
// `false`. Witness on the strictly-modal side of the strict
// modal partition. Peer of
// `layer_kinds_modally_tied_strictly_modal_skewed_chain_is_false`
// on the sister sub-axis of the same chain altitude,
// `tiers_modally_tied_strictly_modal_skewed_map_is_false` on
// the tier altitude, and
// `kinds_modally_tied_strictly_modal_skewed_diff_is_false` on
// the diff altitude.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.dominant_file_format(), Some(Format::Yaml));
assert_eq!(slice.peak_file_format_count(), 2);
assert!(!slice.file_formats_modally_tied());
}
#[test]
fn file_formats_modally_tied_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_modally_tied() ⇒
// file_formats_any_observed()` always. A tied peak requires
// at least two observed cells, so the empty chain (zero
// observed cells) and every no-recognized-files non-empty
// chain (empty file-format histogram via the partial-function
// projection) cannot fire the tie predicate — every modally-
// tied chain observes at least one file-format cell (in fact
// at least two). Direct pin of the histogram-side subsumption
// `is_modally_tied ⇒ !is_empty` one altitude down. Peer of
// `layer_kinds_modally_tied_implies_layer_kinds_any_observed_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_modally_tied_implies_tiers_any_observed_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_modally_tied() {
assert!(
slice.file_formats_any_observed(),
"modally-tied chain must observe at least one file-format cell",
);
}
}
}
#[test]
fn file_formats_modally_tied_implies_not_file_formats_singular_support_pointwise() {
// Subsumption pin: `file_formats_modally_tied() ⇒
// !file_formats_singular_support()` always. A tied peak
// requires at least two observed cells sitting at the same
// maximum count, so the modal level set has cardinality
// `>= 2` — strictly more than the singleton-support corner.
// Direct pin of the histogram-side subsumption
// `has_singular_support ⇒ !is_modally_tied` (contrapositive)
// one altitude down. Peer of
// `layer_kinds_modally_tied_implies_not_layer_kinds_singular_support_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_modally_tied_implies_not_tiers_singular_support_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_implies_not_kinds_singular_support_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_modally_tied() {
assert!(
!slice.file_formats_singular_support(),
"modally-tied chain cannot be singular-support",
);
}
}
}
#[test]
fn file_formats_singular_support_implies_not_file_formats_modally_tied_pointwise() {
// The forward direction of the singleton-support corner
// subsumption: `file_formats_singular_support() ⇒
// !file_formats_modally_tied()` always. A single observed
// cell is the only member of the modal level set
// (cardinality `1`), so the tie predicate never fires on
// any singleton-support chain. Every singleton-support
// chain sits uniformly on the strictly-modal-unique side
// of the strict modal partition. Peer of
// `layer_kinds_singular_support_implies_not_layer_kinds_modally_tied_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_singular_support_implies_not_tiers_modally_tied_pointwise`
// on the tier altitude, and
// `kinds_singular_support_implies_not_kinds_modally_tied_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
!slice.file_formats_modally_tied(),
"singular-support chain cannot be modally tied",
);
}
}
}
#[test]
fn file_formats_modally_tied_forms_strict_modal_partition_on_non_empty_histograms_pointwise() {
// Strict modal partition pin on non-empty file-format
// histograms: on every chain whose file-format histogram is
// non-empty exactly one of the pair
// (file_formats_modally_tied, is_strictly_modally_unique)
// fires. On the empty histogram (empty chain OR no-recognized-
// files chain) both read `false` (the shared boundary below
// both branches of the strict modal partition). Direct pin of
// the histogram-side strict-modal-partition law
// `!is_empty ⇒ is_modally_tied ⇔ !is_strictly_modally_unique`
// one altitude down. Peer of
// `layer_kinds_modally_tied_forms_strict_modal_partition_on_non_empty_chains_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_modally_tied_forms_strict_modal_partition_on_non_empty_maps_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_forms_strict_modal_partition_on_non_empty_diffs_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
let tied = slice.file_formats_modally_tied();
let strict = hist.is_strictly_modally_unique();
if !hist.is_empty() {
let count = usize::from(tied) + usize::from(strict);
assert_eq!(
count, 1,
"on a non-empty file-format histogram exactly one of \
(modally_tied, strictly_modally_unique) must fire \
(tied={tied}, strict={strict})",
);
} else {
assert!(!tied, "empty file-format histogram cannot be modally tied");
assert!(
!strict,
"empty file-format histogram cannot be strictly modally unique",
);
}
}
}
#[test]
fn file_formats_full_cover_and_file_formats_balanced_imply_file_formats_modally_tied_pointwise()
{
// Cardinality-`>= 2` uniform-cover pin: on every full-cover
// balanced chain on the cardinality-`4` `Format` axis, the
// modal level set equals the full axis — all four cells share
// the peak count — so `file_formats_modally_tied` fires.
// Cardinality-`>= 2` witness of the histogram-side subsumption
// `is_uniform_count ∧ !is_empty ⇒ is_modally_tied ⇔
// !has_singular_support` one altitude down. Peer of
// `layer_kinds_full_cover_and_layer_kinds_balanced_imply_layer_kinds_modally_tied_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_full_cover_and_tiers_balanced_imply_tiers_modally_tied_pointwise`
// on the tier altitude, and
// `kinds_full_cover_and_kinds_balanced_imply_kinds_modally_tied_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() && slice.file_formats_balanced() {
assert!(
slice.file_formats_modally_tied(),
"full-cover balanced chain on cardinality-4 axis \
must be modally tied",
);
}
}
}
#[test]
fn file_formats_modally_tied_agrees_with_open_coded_peak_multiplicity_walk() {
// Parity against the exact hand-rolled peak-multiplicity
// walk this lift replaces: walk every cell of the histogram
// and count how many carry the maximum observed count; the
// modally-tied predicate reads `true` iff the multiplicity
// is at least `2`. Empty histogram has max `0` and no cells
// above zero, so multiplicity reads `0` and the predicate
// fails. Peer of
// `layer_kinds_modally_tied_agrees_with_open_coded_peak_multiplicity_walk`
// on the sister sub-axis of the same chain altitude,
// `tiers_modally_tied_agrees_with_open_coded_peak_multiplicity_walk`
// on the tier altitude, and
// `kinds_modally_tied_agrees_with_open_coded_peak_multiplicity_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_modally_tied();
let hist = slice.file_format_histogram();
let max = hist.iter().map(|(_, c)| c).max().unwrap_or(0);
let hand_rolled = if max == 0 {
false
} else {
hist.iter().filter(|(_, c)| *c == max).count() >= 2
};
assert_eq!(via_seam, hand_rolled);
}
}
// ── file_formats_antimodally_tied coverage — the antimodally-tied-
// file-formats boolean predicate on the file-format sub-axis of
// the chain altitude, lifting the layer-kind-sub-axis
// `layer_kinds_antimodally_tied` sideways to the second chain-
// altitude sub-axis, matching the tier-altitude climb
// `tiers_antimodally_tied` and the diff-altitude seed
// `ConfigDiff::kinds_antimodally_tied`. Antimodal-side row on
// the modality classifier pair (is_modally_tied,
// is_antimodally_tied), complementary to the just-closed
// modally-tied row at the same chain file-format sub-axis.
// Direct strict-complement peer of the histogram-side
// `is_strictly_antimodally_unique` primitive on every non-
// empty file-format histogram. ──
#[test]
fn file_formats_antimodally_tied_matches_file_format_histogram_is_antimodally_tied_pointwise() {
// Routing pin: `file_formats_antimodally_tied` routes through
// `file_format_histogram().is_antimodally_tied()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. File-
// format sub-axis peer of
// `layer_kinds_antimodally_tied_matches_layer_kind_histogram_is_antimodally_tied_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_matches_tier_histogram_is_antimodally_tied_pointwise`
// on the tier altitude, and
// `kinds_antimodally_tied_matches_kind_histogram_is_antimodally_tied_pointwise`
// on the diff altitude, in the "antimodally-tied across
// altitudes" projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().is_antimodally_tied();
assert_eq!(slice.file_formats_antimodally_tied(), via_histogram);
}
}
#[test]
fn file_formats_antimodally_tied_matches_defining_trough_multiplicity_inequality_pointwise() {
// Defining multiplicity-scalar inequality form:
// `file_formats_antimodally_tied() ⇔
// file_format_histogram().trough_multiplicity() >= 2`. Pins
// the predicate against the canonical open-coded expression on
// the `AxisHistogram::trough_multiplicity` scalar peer one
// altitude down — the surface consumers reach for when they
// open-code "two or more cells tied at the trough". Peer of
// `layer_kinds_antimodally_tied_matches_defining_trough_multiplicity_inequality_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_matches_defining_trough_multiplicity_inequality_pointwise`
// on the tier altitude, and
// `kinds_antimodally_tied_matches_defining_trough_multiplicity_inequality_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_antimodally_tied();
let mult = slice.file_format_histogram().trough_multiplicity();
let via_scalar = mult >= 2;
assert_eq!(
via_seam, via_scalar,
"file_formats_antimodally_tied ({via_seam}) must agree with \
trough_multiplicity >= 2 ({via_scalar}, mult={mult})",
);
}
}
#[test]
fn file_formats_antimodally_tied_matches_modality_degree_antimodal_component_pointwise() {
// Modality-pair projection-inequality form:
// `file_formats_antimodally_tied() ⇔
// file_format_histogram().modality_degree().1 >= 2`. Pins the
// predicate against the antimodal-component reading of the
// fused `(peak_multiplicity, trough_multiplicity)` pair, the
// second documented surface form consumers reach for when they
// read the classifier pair before the comparison. Peer of
// `layer_kinds_antimodally_tied_matches_modality_degree_antimodal_component_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_matches_modality_degree_antimodal_component_pointwise`
// on the tier altitude, and
// `kinds_antimodally_tied_matches_modality_degree_antimodal_component_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_antimodally_tied();
let (_, trough_mult) = slice.file_format_histogram().modality_degree();
let via_pair = trough_mult >= 2;
assert_eq!(
via_seam, via_pair,
"file_formats_antimodally_tied ({via_seam}) must agree with \
modality_degree().1 >= 2 ({via_pair}, trough_mult={trough_mult})",
);
}
}
#[test]
fn file_formats_antimodally_tied_empty_chain_is_false() {
// Empty-chain antimodal-tie: the empty chain observes zero
// cells, so `trough_multiplicity` reads `0` and the inequality
// `0 >= 2` fails. `file_formats_antimodally_tied` reads
// `false`. Matches `is_antimodally_tied` reading `false` on
// the empty histogram one altitude down. Direct witness of the
// subsumption `file_formats_antimodally_tied ⇒
// file_formats_any_observed` via the empty-chain disjunct of
// `!file_formats_any_observed`. Peer of
// `layer_kinds_antimodally_tied_empty_chain_is_false` on the
// sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_empty_map_is_false` on the tier
// altitude, and `kinds_antimodally_tied_empty_diff_is_false`
// on the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_antimodally_tied());
assert!(!empty.file_formats_any_observed());
}
#[test]
fn file_formats_antimodally_tied_no_recognized_files_is_false() {
// No-recognized-files pin: a non-empty chain of only
// `Defaults` / `Env` / unrecognized-extension `File` layers
// projects to an empty file-format histogram via the partial
// function `ConfigSource::file_format` — `trough_multiplicity`
// reads `0` and the inequality `0 >= 2` fails.
// `file_formats_antimodally_tied` reads `false`. Cross-sub-
// axis divergence pin against `layer_kinds_antimodally_tied`:
// on the same fixture the layer-kind sub-axis observes at
// least one layer-kind cell and may fire the antimodal-tie
// predicate (e.g. one `Defaults` + one `Env` reads
// `layer_kinds_antimodally_tied = true`), while the file-
// format sub-axis's antimodal-tie predicate silently drops out
// via the empty-histogram disjunct — the antimodal-tie leg is
// *narrower* at the file-format sub-axis than at the layer-
// kind sub-axis, matching the same narrowing pinned at the
// modal-tie row `file_formats_modally_tied`.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert!(
!slice.file_formats_antimodally_tied(),
"no-recognized-files chain must not fire antimodally-tied",
);
assert!(!slice.file_formats_any_observed());
}
}
#[test]
fn file_formats_antimodally_tied_singleton_support_is_false() {
// Singleton-support pin: every recognized file layer lands on
// the same file format, so the lone observed cell stands alone
// at its own trough (peak and trough coincide) —
// `trough_multiplicity` reads `1` and the inequality `1 >= 2`
// fails. `file_formats_antimodally_tied` reads `false`. Direct
// witness of the subsumption `file_formats_singular_support ⇒
// !file_formats_antimodally_tied` via the singleton-support
// corner. The `sample_chain()` fixture (two `.yaml` file layers
// + one Env layer, `{Yaml}` file-format support with count `2`)
// is a witness on the `false` side. Peer of
// `layer_kinds_antimodally_tied_singleton_support_is_false` on
// the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_singleton_support_is_false` on the
// tier altitude, and
// `kinds_antimodally_tied_singleton_support_is_false` on the
// diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(!slice.file_formats_antimodally_tied());
}
#[test]
fn file_formats_antimodally_tied_two_format_uniform_partial_cover_is_true() {
// Two-format uniform-partial-cover pin: a chain of one `.yaml`
// + one `.toml` file layer has two observed cells tied at
// count `1` on the cardinality-`4` `Format` axis (with two
// silent cells at count `0`) — `trough_multiplicity` reads `2`
// and the inequality `2 >= 2` fires.
// `file_formats_antimodally_tied` reads `true`. Witness on the
// antimodally-tied side of the strict antimodal partition at
// the chain file-format sub-axis. Support-`2` reachability at
// the chain file-format sub-axis, matching the support-`2`
// reachability at the layer-kind sub-axis on the cardinality-
// `3` axis and on the diff altitude on the same cardinality-
// `3` axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(slice.file_formats_antimodally_tied());
}
#[test]
fn file_formats_antimodally_tied_three_format_uniform_partial_cover_is_true() {
// Three-format uniform-partial-cover pin: a chain of one
// `.yaml` + one `.toml` + one `.lisp` file layer has three
// observed cells tied at count `1` on the cardinality-`4`
// `Format` axis — `trough_multiplicity` reads `3` and the
// inequality `3 >= 2` fires. `file_formats_antimodally_tied`
// reads `true`. Support-`3` shared-trough reachability at the
// chain file-format sub-axis — the additional off-singleton
// support cardinality unavailable at the layer-kind sub-axis
// (cardinality-`3`) and the diff altitude (cardinality-`3`),
// matching the tier altitude on the cardinality-`4`
// `ConfigTierKind` axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert!(slice.file_formats_antimodally_tied());
}
#[test]
fn file_formats_antimodally_tied_uniform_four_format_cover_is_true() {
// Uniform axis-cover pin: a chain observing every cell of
// `Format` exactly once has four observed cells tied at count
// `1` — `trough_multiplicity` reads `4` and the inequality
// `4 >= 2` fires. `file_formats_antimodally_tied` reads
// `true`. Peer of the histogram-side axis-cover convention
// one altitude down, which reads `true` on every implementor
// with `axis_cardinality::<A>() >= 2` — the cardinality-`4`
// `Format` axis honours the general condition.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 4);
assert!(slice.file_formats_full_cover());
assert!(slice.file_formats_balanced());
assert!(slice.file_formats_antimodally_tied());
}
#[test]
fn file_formats_antimodally_tied_strictly_antimodal_skewed_chain_is_false() {
// Strictly-antimodal skewed-chain pin: a chain of two `.yaml`
// + one `.toml` file layer has `Toml` uniquely holding the
// trough at count `1` while `Yaml` peaks at count `2` (Lisp
// sits at `0`, Nix at `0`) — `trough_multiplicity` reads `1`
// and the inequality `1 >= 2` fails.
// `file_formats_antimodally_tied` reads `false`. Witness on
// the strictly-antimodal side of the strict antimodal
// partition. Peer of
// `layer_kinds_antimodally_tied_strictly_antimodal_skewed_chain_is_false`
// on the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_strictly_antimodal_skewed_map_is_false`
// on the tier altitude, and
// `kinds_antimodally_tied_strictly_antimodal_skewed_diff_is_false`
// on the diff altitude.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.dominant_file_format(), Some(Format::Yaml));
assert_eq!(slice.peak_file_format_count(), 2);
assert!(!slice.file_formats_antimodally_tied());
}
#[test]
fn file_formats_antimodally_tied_strictly_modal_and_antimodally_tied_chain_is_true() {
// Modal-side / antimodal-side divergence pin: on the
// cardinality-`4` `Format` axis a mixed-count chain can
// simultaneously carry a *unique* peak and a *shared* trough
// — two `.yaml` + one `.toml` + one `.lisp` gives
// `{Yaml: 2, Toml: 1, Lisp: 1, Nix: 0}`. `Yaml` uniquely
// peaks at count `2` (`peak_multiplicity = 1`, modally-tied
// fails), while `Toml` and `Lisp` share the trough at count
// `1` (`trough_multiplicity = 2`, antimodally-tied fires).
// Direct witness of the *strictly-modal-unique ∧
// antimodally-tied* corner of the four-quadrant modality
// classifier — reachable at the file-format sub-axis
// (cardinality-`4`) but requiring three off-silent cells,
// matching the tier altitude on the cardinality-`4`
// `ConfigTierKind` axis. Peer of the corresponding cross-
// corner witnesses at the diff and tier altitudes in the
// "antimodally-tied across altitudes" projection.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
ConfigSource::File(PathBuf::from("/d.lisp")),
];
let slice = chain.as_slice();
assert!(!slice.file_formats_modally_tied());
assert!(slice.file_formats_antimodally_tied());
}
#[test]
fn file_formats_antimodally_tied_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_antimodally_tied() ⇒
// file_formats_any_observed()` always. A tied trough requires
// at least two observed cells, so the empty chain (zero
// observed cells) and every no-recognized-files non-empty
// chain (empty file-format histogram via the partial-function
// projection) cannot fire the tie predicate — every
// antimodally-tied chain observes at least one file-format
// cell (in fact at least two). Direct pin of the histogram-
// side subsumption `is_antimodally_tied ⇒ !is_empty` one
// altitude down. Peer of
// `layer_kinds_antimodally_tied_implies_layer_kinds_any_observed_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_implies_tiers_any_observed_pointwise`
// on the tier altitude, and
// `kinds_antimodally_tied_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_antimodally_tied() {
assert!(
slice.file_formats_any_observed(),
"antimodally-tied chain must observe at least one file-format cell",
);
}
}
}
#[test]
fn file_formats_antimodally_tied_implies_not_file_formats_singular_support_pointwise() {
// Subsumption pin: `file_formats_antimodally_tied() ⇒
// !file_formats_singular_support()` always. A tied trough
// requires at least two observed cells sitting at the same
// strictly-positive minimum count, so the antimodal level set
// has cardinality `>= 2` — strictly more than the singleton-
// support corner. Direct pin of the histogram-side subsumption
// `has_singular_support ⇒ !is_antimodally_tied`
// (contrapositive) one altitude down. Peer of
// `layer_kinds_antimodally_tied_implies_not_layer_kinds_singular_support_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_implies_not_tiers_singular_support_pointwise`
// on the tier altitude, and
// `kinds_antimodally_tied_implies_not_kinds_singular_support_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_antimodally_tied() {
assert!(
!slice.file_formats_singular_support(),
"antimodally-tied chain cannot be singular-support",
);
}
}
}
#[test]
fn file_formats_singular_support_implies_not_file_formats_antimodally_tied_pointwise() {
// The forward direction of the singleton-support corner
// subsumption: `file_formats_singular_support() ⇒
// !file_formats_antimodally_tied()` always. A single observed
// cell is the only member of the antimodal level set
// (cardinality `1`), so the tie predicate never fires on any
// singleton-support chain. Every singleton-support chain sits
// uniformly on the strictly-antimodal-unique side of the
// strict antimodal partition. Peer of
// `layer_kinds_singular_support_implies_not_layer_kinds_antimodally_tied_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_singular_support_implies_not_tiers_antimodally_tied_pointwise`
// on the tier altitude, and
// `kinds_singular_support_implies_not_kinds_antimodally_tied_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
!slice.file_formats_antimodally_tied(),
"singular-support chain cannot be antimodally tied",
);
}
}
}
#[test]
fn file_formats_antimodally_tied_forms_strict_antimodal_partition_on_non_empty_histograms_pointwise()
{
// Strict antimodal partition pin on non-empty file-format
// histograms: on every chain whose file-format histogram is
// non-empty exactly one of the pair
// (file_formats_antimodally_tied, is_strictly_antimodally_unique)
// fires. On the empty histogram (empty chain OR no-recognized-
// files chain) both read `false` (the shared boundary below
// both branches of the strict antimodal partition). Direct
// pin of the histogram-side strict-antimodal-partition law
// `!is_empty ⇒ is_antimodally_tied ⇔
// !is_strictly_antimodally_unique` one altitude down. Peer of
// `layer_kinds_antimodally_tied_forms_strict_antimodal_partition_on_non_empty_chains_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_forms_strict_antimodal_partition_on_non_empty_maps_pointwise`
// on the tier altitude, and
// `kinds_antimodally_tied_forms_strict_antimodal_partition_on_non_empty_diffs_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
let tied = slice.file_formats_antimodally_tied();
let strict = hist.is_strictly_antimodally_unique();
if !hist.is_empty() {
let count = usize::from(tied) + usize::from(strict);
assert_eq!(
count, 1,
"on a non-empty file-format histogram exactly one of \
(antimodally_tied, strictly_antimodally_unique) must fire \
(tied={tied}, strict={strict})",
);
} else {
assert!(
!tied,
"empty file-format histogram cannot be antimodally tied",
);
assert!(
!strict,
"empty file-format histogram cannot be strictly antimodally unique",
);
}
}
}
#[test]
fn file_formats_full_cover_and_file_formats_balanced_imply_file_formats_antimodally_tied_pointwise()
{
// Cardinality-`>= 2` uniform-cover pin: on every full-cover
// balanced chain on the cardinality-`4` `Format` axis, the
// antimodal level set equals the full axis — all four cells
// share the trough count — so
// `file_formats_antimodally_tied` fires. Cardinality-`>= 2`
// witness of the histogram-side subsumption `is_uniform_count
// ∧ !is_empty ⇒ is_antimodally_tied ⇔ !has_singular_support`
// one altitude down. Peer of
// `layer_kinds_full_cover_and_layer_kinds_balanced_imply_layer_kinds_antimodally_tied_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_full_cover_and_tiers_balanced_imply_tiers_antimodally_tied_pointwise`
// on the tier altitude, and
// `kinds_full_cover_and_kinds_balanced_imply_kinds_antimodally_tied_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() && slice.file_formats_balanced() {
assert!(
slice.file_formats_antimodally_tied(),
"full-cover balanced chain on cardinality-4 axis \
must be antimodally tied",
);
}
}
}
#[test]
fn file_formats_antimodally_tied_collapses_with_file_formats_modally_tied_on_uniform_multi_cell_chains_pointwise()
{
// Modal / antimodal collapse pin: on every uniform-count non-
// empty file-format histogram the two tie predicates read the
// same value. Direct pin of the histogram-side collapse law
// `is_uniform_count ∧ !is_empty ⇒ is_antimodally_tied ⇔
// is_modally_tied` one altitude down, at the chain file-
// format sub-axis. On the singleton-support uniform corner
// both read `false`; on every multi-cell uniform chain both
// read `true`. Peer of
// `layer_kinds_antimodally_tied_collapses_with_layer_kinds_modally_tied_on_uniform_multi_cell_chains_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_collapses_with_tiers_modally_tied_on_uniform_multi_cell_maps_pointwise`
// on the tier altitude, and
// `kinds_antimodally_tied_collapses_with_kinds_modally_tied_on_uniform_multi_cell_diffs_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_balanced() && slice.file_formats_any_observed() {
assert_eq!(
slice.file_formats_antimodally_tied(),
slice.file_formats_modally_tied(),
"on a uniform-count non-empty file-format histogram \
the two tie predicates must collapse to the same value",
);
}
}
}
#[test]
fn file_formats_antimodally_tied_agrees_with_open_coded_trough_multiplicity_walk() {
// Parity against the exact hand-rolled trough-multiplicity
// walk this lift replaces: walk every cell of the histogram
// and count how many carry the strictly-positive minimum
// observed count; the antimodally-tied predicate reads `true`
// iff the multiplicity is at least `2`. Empty histogram has
// no strictly-positive counts, so multiplicity reads `0` and
// the predicate fails. Peer of
// `layer_kinds_antimodally_tied_agrees_with_open_coded_trough_multiplicity_walk`
// on the sister sub-axis of the same chain altitude,
// `tiers_antimodally_tied_agrees_with_open_coded_trough_multiplicity_walk`
// on the tier altitude, and
// `kinds_antimodally_tied_agrees_with_open_coded_trough_multiplicity_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_antimodally_tied();
let hist = slice.file_format_histogram();
let min = hist
.iter()
.map(|(_, c)| c)
.filter(|c| *c > 0)
.min()
.unwrap_or(0);
let hand_rolled = if min == 0 {
false
} else {
hist.iter().filter(|(_, c)| *c == min).count() >= 2
};
assert_eq!(via_seam, hand_rolled);
}
}
// ── file_formats_strictly_modally_unique coverage — the strictly-
// modally-unique-file-formats boolean predicate on the file-
// format sub-axis of the chain altitude, lifting the layer-kind-
// sub-axis `layer_kinds_strictly_modally_unique` sideways to the
// second chain-altitude sub-axis, matching the tier-altitude
// climb `tiers_strictly_modally_unique` and the diff-altitude
// seed `ConfigDiff::kinds_strictly_modally_unique`. Strict-
// uniqueness row on top of the closed modality-tie boolean pair
// (file_formats_modally_tied, file_formats_antimodally_tied) at
// the chain file-format sub-axis. Direct strict-complement peer
// of `file_formats_modally_tied` on every non-empty file-format
// histogram (both read `false` on the empty file-format
// histogram — the shared boundary below both branches of the
// strict modal partition). ──
#[test]
fn file_formats_strictly_modally_unique_matches_file_format_histogram_is_strictly_modally_unique_pointwise()
{
// Routing pin: `file_formats_strictly_modally_unique` routes
// through `file_format_histogram().is_strictly_modally_unique()`,
// so the two seams must stay pointwise equivalent under every
// fixture. Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive.
// File-format sub-axis peer of
// `layer_kinds_strictly_modally_unique_matches_layer_kind_histogram_is_strictly_modally_unique_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_strictly_modally_unique_matches_tier_histogram_is_strictly_modally_unique_pointwise`
// on the tier altitude, and
// `kinds_strictly_modally_unique_matches_kind_histogram_is_strictly_modally_unique_pointwise`
// on the diff altitude, in the "strictly-modally-unique across
// altitudes" projection.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.file_format_histogram().is_strictly_modally_unique();
assert_eq!(slice.file_formats_strictly_modally_unique(), via_histogram);
}
}
#[test]
fn file_formats_strictly_modally_unique_matches_defining_peak_multiplicity_equality_pointwise()
{
// Defining multiplicity-scalar equality form:
// `file_formats_strictly_modally_unique() ⇔
// file_format_histogram().peak_multiplicity() == 1`. Pins the
// predicate against the canonical open-coded expression on
// the `AxisHistogram::peak_multiplicity` scalar peer one
// altitude down — the surface consumers reach for when they
// open-code "exactly one cell holds the peak". Peer of
// `layer_kinds_strictly_modally_unique_matches_defining_peak_multiplicity_equality_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_strictly_modally_unique_matches_defining_peak_multiplicity_equality_pointwise`
// on the tier altitude, and
// `kinds_strictly_modally_unique_matches_defining_peak_multiplicity_equality_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_strictly_modally_unique();
let mult = slice.file_format_histogram().peak_multiplicity();
let via_scalar = mult == 1;
assert_eq!(
via_seam, via_scalar,
"file_formats_strictly_modally_unique ({via_seam}) must \
agree with peak_multiplicity == 1 ({via_scalar}, \
mult={mult})",
);
}
}
#[test]
fn file_formats_strictly_modally_unique_matches_modality_degree_modal_component_pointwise() {
// Modality-pair projection-equality form:
// `file_formats_strictly_modally_unique() ⇔
// file_format_histogram().modality_degree().0 == 1`. Pins the
// predicate against the modal-component reading of the fused
// `(peak_multiplicity, trough_multiplicity)` pair, the second
// documented surface form consumers reach for when they read
// the classifier pair before the equality. Peer of
// `layer_kinds_strictly_modally_unique_matches_modality_degree_modal_component_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_strictly_modally_unique_matches_modality_degree_modal_component_pointwise`
// on the tier altitude, and
// `kinds_strictly_modally_unique_matches_modality_degree_modal_component_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_strictly_modally_unique();
let (peak_mult, _) = slice.file_format_histogram().modality_degree();
let via_pair = peak_mult == 1;
assert_eq!(
via_seam, via_pair,
"file_formats_strictly_modally_unique ({via_seam}) must \
agree with modality_degree().0 == 1 ({via_pair}, \
peak_mult={peak_mult})",
);
}
}
#[test]
fn file_formats_strictly_modally_unique_empty_chain_is_false() {
// Empty-chain strict-modal-uniqueness: the empty chain
// observes zero cells, so `peak_multiplicity` reads `0` and
// the equality `0 == 1` fails.
// `file_formats_strictly_modally_unique` reads `false`. Matches
// `is_strictly_modally_unique` reading `false` on the empty
// histogram one altitude down. The empty-chain row on the
// strict modal partition pair
// `(is_strictly_modally_unique, is_modally_tied)` reads
// `(false, false)` — the shared boundary below both branches.
// Peer of `layer_kinds_strictly_modally_unique_empty_chain_is_false`
// on the sister sub-axis of the same chain altitude,
// `tiers_strictly_modally_unique_empty_map_is_false` on the
// tier altitude, and
// `kinds_strictly_modally_unique_empty_diff_is_false` on the
// diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.file_formats_strictly_modally_unique());
assert!(!empty.file_formats_any_observed());
}
#[test]
fn file_formats_strictly_modally_unique_no_recognized_files_is_false() {
// No-recognized-files pin: a non-empty chain of only
// `Defaults` / `Env` / unrecognized-extension `File` layers
// projects to an empty file-format histogram via the partial
// function `ConfigSource::file_format` — `peak_multiplicity`
// reads `0` and the equality `0 == 1` fails.
// `file_formats_strictly_modally_unique` reads `false`. Cross-
// sub-axis divergence pin against
// `layer_kinds_strictly_modally_unique`: on the same fixture
// the layer-kind sub-axis observes at least one layer-kind
// cell and may fire the strictly-modally-unique predicate
// (e.g. a single `Defaults` layer reads
// `layer_kinds_strictly_modally_unique = true` via singleton-
// support), while the file-format sub-axis's strictly-
// modally-unique predicate silently drops out via the empty-
// histogram disjunct — the strict-uniqueness leg is *narrower*
// at the file-format sub-axis than at the layer-kind sub-axis.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::Env("APP_".to_owned())],
vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
],
vec![
ConfigSource::File(PathBuf::from("/a")),
ConfigSource::File(PathBuf::from("/b.unknown")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.file_format_histogram().is_empty(),
"fixture must have empty file-format histogram",
);
assert!(
!slice.file_formats_strictly_modally_unique(),
"no-recognized-files chain must not fire strictly-modally-unique",
);
assert!(!slice.file_formats_any_observed());
}
}
#[test]
fn file_formats_strictly_modally_unique_singleton_support_is_true() {
// Singleton-support pin: every recognized file layer lands on
// the same file format, so the lone observed cell stands
// alone at its own peak (no tie-break to exercise) —
// `peak_multiplicity` reads `1` and the equality `1 == 1`
// fires. `file_formats_strictly_modally_unique` reads `true`.
// Direct witness of the subsumption
// `file_formats_singular_support ⇒
// file_formats_strictly_modally_unique` via the singleton-
// support corner. The `sample_chain()` fixture (two `.yaml`
// file layers + one Env layer, `{Yaml}` file-format support
// with count `2`) is a witness on the `true` side. Peer of
// `layer_kinds_strictly_modally_unique_singleton_support_is_true`
// on the sister sub-axis of the same chain altitude,
// `tiers_strictly_modally_unique_singleton_support_is_true`
// on the tier altitude, and
// `kinds_strictly_modally_unique_singleton_support_is_true`
// on the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 1);
assert!(slice.file_formats_singular_support());
assert!(slice.file_formats_strictly_modally_unique());
}
#[test]
fn file_formats_strictly_modally_unique_two_format_uniform_partial_cover_is_false() {
// Two-format uniform-partial-cover pin: a chain of one `.yaml`
// + one `.toml` file layer has two observed cells tied at
// count `1` on the cardinality-`4` `Format` axis —
// `peak_multiplicity` reads `2` and the equality `2 == 1`
// fails. `file_formats_strictly_modally_unique` reads `false`.
// Witness on the modally-tied side of the strict modal
// partition at the chain file-format sub-axis. Support-`2`
// reachability at the chain file-format sub-axis, matching
// the support-`2` reachability at the layer-kind sub-axis on
// the cardinality-`3` axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 2);
assert!(!slice.file_formats_strictly_modally_unique());
}
#[test]
fn file_formats_strictly_modally_unique_three_format_uniform_partial_cover_is_false() {
// Three-format uniform-partial-cover pin: a chain of one
// `.yaml` + one `.toml` + one `.lisp` file layer has three
// observed cells tied at count `1` on the cardinality-`4`
// `Format` axis — `peak_multiplicity` reads `3` and the
// equality `3 == 1` fails.
// `file_formats_strictly_modally_unique` reads `false`.
// Support-`3` tied reachability at the chain file-format sub-
// axis — the additional off-singleton support cardinality
// unavailable at the layer-kind sub-axis (cardinality-`3`)
// and the diff altitude (cardinality-`3`), matching the tier
// altitude on the cardinality-`4` `ConfigTierKind` axis.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 3);
assert!(!slice.file_formats_strictly_modally_unique());
}
#[test]
fn file_formats_strictly_modally_unique_uniform_four_format_cover_is_false() {
// Uniform axis-cover pin: a chain observing every cell of
// `Format` exactly once has four observed cells tied at count
// `1` — `peak_multiplicity` reads `4` and the equality
// `4 == 1` fails.
// `file_formats_strictly_modally_unique` reads `false`. Peer
// of the histogram-side axis-cover convention one altitude
// down, which reads `false` on every implementor with
// `axis_cardinality::<A>() >= 2` — the cardinality-`4`
// `Format` axis honours the general condition. Peer of
// `tiers_strictly_modally_unique_uniform_four_tier_cover_is_false`
// on the tier altitude, at the same cardinality-`4` support-
// `4` uniform-cover corner.
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
ConfigSource::File(PathBuf::from("/c.lisp")),
ConfigSource::File(PathBuf::from("/d.nix")),
];
let slice = chain.as_slice();
assert_eq!(slice.present_file_formats().len(), 4);
assert!(slice.file_formats_full_cover());
assert!(slice.file_formats_balanced());
assert!(!slice.file_formats_strictly_modally_unique());
}
#[test]
fn file_formats_strictly_modally_unique_strictly_modal_skewed_chain_is_true() {
// Strictly-modal skewed-chain pin: a chain of two `.yaml`
// file layers + one `.toml` file layer has `Yaml` uniquely
// peaking at count `2` (Toml sits at `1`, Lisp at `0`, Nix
// at `0`) — `peak_multiplicity` reads `1` and the equality
// `1 == 1` fires.
// `file_formats_strictly_modally_unique` reads `true`.
// Witness on the strictly-modally-unique side of the strict
// modal partition. Peer of
// `layer_kinds_strictly_modally_unique_strictly_modal_skewed_chain_is_true`
// on the sister sub-axis of the same chain altitude,
// `tiers_strictly_modally_unique_strictly_modal_skewed_map_is_true`
// on the tier altitude, and
// `kinds_strictly_modally_unique_strictly_modal_skewed_diff_is_true`
// on the diff altitude.
use crate::discovery::Format;
let chain = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.toml")),
];
let slice = chain.as_slice();
assert_eq!(slice.dominant_file_format(), Some(Format::Yaml));
assert_eq!(slice.peak_file_format_count(), 2);
assert!(slice.file_formats_strictly_modally_unique());
}
#[test]
fn file_formats_strictly_modally_unique_implies_file_formats_any_observed_pointwise() {
// Subsumption pin: `file_formats_strictly_modally_unique() ⇒
// file_formats_any_observed()` always. A strictly-unique peak
// requires at least one observed cell as the sole member of
// the modal level set, so both the empty chain (zero observed
// cells) and every no-recognized-files non-empty chain (empty
// file-format histogram via the partial-function projection)
// cannot fire the uniqueness predicate. Direct pin of the
// histogram-side subsumption `is_strictly_modally_unique ⇒
// !is_empty` one altitude down. Peer of
// `layer_kinds_strictly_modally_unique_implies_layer_kinds_any_observed_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_strictly_modally_unique_implies_tiers_any_observed_pointwise`
// on the tier altitude, and
// `kinds_strictly_modally_unique_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_strictly_modally_unique() {
assert!(
slice.file_formats_any_observed(),
"strictly-modally-unique chain must observe at \
least one file-format cell",
);
}
}
}
#[test]
fn file_formats_singular_support_implies_file_formats_strictly_modally_unique_pointwise() {
// Subsumption pin: `file_formats_singular_support() ⇒
// file_formats_strictly_modally_unique()` always. A single
// observed cell is the only member of the modal level set
// (cardinality `1`), so the uniqueness predicate fires on
// every singleton-support chain. Every singleton-support
// chain sits uniformly on the strictly-modally-unique side
// of the strict modal partition. Direct pin of the histogram-
// side subsumption `has_singular_support ⇒
// is_strictly_modally_unique` one altitude down. Peer of
// `layer_kinds_singular_support_implies_layer_kinds_strictly_modally_unique_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_singular_support_implies_tiers_strictly_modally_unique_pointwise`
// on the tier altitude, and
// `kinds_singular_support_implies_kinds_strictly_modally_unique_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_singular_support() {
assert!(
slice.file_formats_strictly_modally_unique(),
"singular-support chain must be strictly modally \
unique",
);
}
}
}
#[test]
fn file_formats_strictly_modally_unique_forms_strict_modal_partition_on_non_empty_histograms_pointwise()
{
// Strict modal partition pin on non-empty file-format
// histograms: on every chain whose file-format histogram is
// non-empty exactly one of the pair
// (file_formats_strictly_modally_unique,
// file_formats_modally_tied) fires. On the empty histogram
// (empty chain OR no-recognized-files chain) both read
// `false` (the shared boundary below both branches of the
// strict modal partition). Direct pin of the histogram-side
// strict-modal-partition law
// `!is_empty ⇒ is_strictly_modally_unique ⇔ !is_modally_tied`
// one altitude down, phrased as an XOR on the two named
// seams at the chain file-format sub-axis surface — the
// seam-level dual of the matching pin
// `file_formats_modally_tied_forms_strict_modal_partition_on_non_empty_histograms_pointwise`
// that reads the strict side off the histogram primitive.
// Peer of
// `layer_kinds_strictly_modally_unique_forms_strict_modal_partition_on_non_empty_chains_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_strictly_modally_unique_forms_strict_modal_partition_on_non_empty_maps_pointwise`
// on the tier altitude, and
// `kinds_strictly_modally_unique_forms_strict_modal_partition_on_non_empty_diffs_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let hist = slice.file_format_histogram();
let strict = slice.file_formats_strictly_modally_unique();
let tied = slice.file_formats_modally_tied();
if !hist.is_empty() {
let count = usize::from(strict) + usize::from(tied);
assert_eq!(
count, 1,
"on a non-empty file-format histogram exactly one \
of (strictly_modally_unique, modally_tied) must \
fire (strict={strict}, tied={tied})",
);
} else {
assert!(
!strict,
"empty file-format histogram cannot be strictly modally unique",
);
assert!(!tied, "empty file-format histogram cannot be modally tied",);
}
}
}
#[test]
fn file_formats_full_cover_and_file_formats_balanced_imply_not_file_formats_strictly_modally_unique_pointwise()
{
// Cardinality-`>= 2` uniform-cover pin: on every full-cover
// balanced chain on the cardinality-`4` `Format` axis, the
// modal level set equals the full axis — all four cells share
// the peak count — so
// `file_formats_strictly_modally_unique` fails. Cardinality-
// `>= 2` witness of the histogram-side subsumption
// `is_uniform_count ∧ !is_empty ⇒ is_strictly_modally_unique
// ⇔ has_singular_support` one altitude down: on a uniform-
// cover with cardinality `>= 2`, singleton-support fails so
// strict-modal-uniqueness fails. Peer of
// `layer_kinds_full_cover_and_layer_kinds_balanced_imply_not_layer_kinds_strictly_modally_unique_pointwise`
// on the sister sub-axis of the same chain altitude,
// `tiers_full_cover_and_tiers_balanced_imply_not_tiers_strictly_modally_unique_pointwise`
// on the tier altitude, and
// `kinds_full_cover_and_kinds_balanced_imply_not_kinds_strictly_modally_unique_pointwise`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
if slice.file_formats_full_cover() && slice.file_formats_balanced() {
assert!(
!slice.file_formats_strictly_modally_unique(),
"full-cover balanced chain on cardinality-4 axis \
cannot be strictly modally unique",
);
}
}
}
#[test]
fn file_formats_strictly_modally_unique_agrees_with_open_coded_peak_multiplicity_walk() {
// Parity against the exact hand-rolled peak-multiplicity walk
// this lift replaces: walk every cell of the histogram and
// count how many carry the maximum observed count; the
// strictly-modally-unique predicate reads `true` iff the
// multiplicity is exactly `1`. Empty histogram has max `0`
// and no cells above zero, so multiplicity reads `0` and the
// predicate fails. Peer of
// `layer_kinds_strictly_modally_unique_agrees_with_open_coded_peak_multiplicity_walk`
// on the sister sub-axis of the same chain altitude,
// `tiers_strictly_modally_unique_agrees_with_open_coded_peak_multiplicity_walk`
// on the tier altitude, and
// `kinds_strictly_modally_unique_agrees_with_open_coded_peak_multiplicity_walk`
// on the diff altitude.
for chain in recessive_file_format_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.file_formats_strictly_modally_unique();
let hist = slice.file_format_histogram();
let max = hist.iter().map(|(_, c)| c).max().unwrap_or(0);
let hand_rolled = if max == 0 {
false
} else {
hist.iter().filter(|(_, c)| *c == max).count() == 1
};
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_modally_tied — modally-tied-
// env-prefix-kinds boolean predicate on the env-prefix sub-axis of
// the chain altitude, lifting is_modally_tied from the histogram
// surface and closing the "modally-tied across altitudes"
// projection at the fifth and final altitude / sub-axis ----
#[test]
fn env_prefix_kinds_modally_tied_matches_env_prefix_kind_histogram_is_modally_tied_pointwise() {
// Routing pin: `env_prefix_kinds_modally_tied` routes through
// `env_prefix_kind_histogram().is_modally_tied()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-
// prefix sub-axis peer of
// `file_formats_modally_tied_matches_file_format_histogram_is_modally_tied_pointwise`
// and
// `layer_kinds_modally_tied_matches_layer_kind_histogram_is_modally_tied_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_modally_tied_matches_tier_histogram_is_modally_tied_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_matches_kind_histogram_is_modally_tied_pointwise`
// on the diff altitude — closing the "modally-tied across
// altitudes" projection across every altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().is_modally_tied();
assert_eq!(slice.env_prefix_kinds_modally_tied(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise() {
// Defining multiplicity-scalar inequality form:
// `env_prefix_kinds_modally_tied() ⇔
// env_prefix_kind_histogram().peak_multiplicity() >= 2`. Pins
// the predicate against the canonical open-coded expression on
// the `AxisHistogram::peak_multiplicity` scalar peer one
// altitude down — the surface consumers reach for when they
// open-code "two or more cells tied at the peak". Peer of
// `file_formats_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise`
// and
// `layer_kinds_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_matches_defining_peak_multiplicity_inequality_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_modally_tied();
let mult = slice.env_prefix_kind_histogram().peak_multiplicity();
let via_scalar = mult >= 2;
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_modally_tied ({via_seam}) must agree with \
peak_multiplicity >= 2 ({via_scalar}, mult={mult})",
);
}
}
#[test]
fn env_prefix_kinds_modally_tied_matches_modality_degree_modal_component_pointwise() {
// Modality-pair projection-inequality form:
// `env_prefix_kinds_modally_tied() ⇔
// env_prefix_kind_histogram().modality_degree().0 >= 2`. Pins
// the predicate against the modal-component reading of the
// fused `(peak_multiplicity, trough_multiplicity)` pair, the
// second documented surface form consumers reach for when they
// read the classifier pair before the comparison. Peer of
// `file_formats_modally_tied_matches_modality_degree_modal_component_pointwise`
// and
// `layer_kinds_modally_tied_matches_modality_degree_modal_component_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_modally_tied_matches_modality_degree_modal_component_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_matches_modality_degree_modal_component_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_modally_tied();
let (peak_mult, _) = slice.env_prefix_kind_histogram().modality_degree();
let via_pair = peak_mult >= 2;
assert_eq!(
via_seam, via_pair,
"env_prefix_kinds_modally_tied ({via_seam}) must agree with \
modality_degree().0 >= 2 ({via_pair}, peak_mult={peak_mult})",
);
}
}
#[test]
fn env_prefix_kinds_modally_tied_empty_chain_is_false() {
// Empty-chain modal-tie: the empty chain observes zero cells,
// so `peak_multiplicity` reads `0` and the inequality `0 >= 2`
// fails. `env_prefix_kinds_modally_tied` reads `false`. Matches
// `is_modally_tied` reading `false` on the empty histogram one
// altitude down. Direct witness of the subsumption
// `env_prefix_kinds_modally_tied ⇒ env_prefix_kinds_any_observed`
// via the empty-chain disjunct of
// `!env_prefix_kinds_any_observed`. Peer of
// `file_formats_modally_tied_empty_chain_is_false` and
// `layer_kinds_modally_tied_empty_chain_is_false` on the sister
// sub-axes of the same chain altitude,
// `tiers_modally_tied_empty_map_is_false` on the tier altitude,
// and `kinds_modally_tied_empty_diff_is_false` on the diff
// altitude — closing the empty-witness row of the projection at
// the fifth and final altitude / sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_modally_tied());
assert!(!empty.env_prefix_kinds_any_observed());
}
#[test]
fn env_prefix_kinds_modally_tied_no_env_layers_is_false() {
// No-env-layers pin: a non-empty chain of only `Defaults` /
// `File` layers projects to an empty env-prefix histogram via
// the partial function `ConfigSource::env_prefix_kind` —
// `peak_multiplicity` reads `0` and the inequality `0 >= 2`
// fails. `env_prefix_kinds_modally_tied` reads `false`. Cross-
// sub-axis divergence pin against `layer_kinds_modally_tied`:
// on the same fixture the layer-kind sub-axis observes at least
// one layer-kind cell and may fire the modal-tie predicate
// (e.g. one `Defaults` + one `File` reads
// `layer_kinds_modally_tied = true`), while the env-prefix sub-
// axis's modal-tie predicate silently drops out via the empty-
// histogram disjunct — the modal-tie leg is *narrower* at the
// env-prefix sub-axis than at the layer-kind sub-axis. Mirrors
// the shape of `file_formats_modally_tied_no_recognized_files_is_false`
// on the sister partial-function sub-axis at the same chain
// altitude.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert!(
!slice.env_prefix_kinds_modally_tied(),
"no-env-layers chain must not fire modally-tied",
);
assert!(!slice.env_prefix_kinds_any_observed());
}
}
#[test]
fn env_prefix_kinds_modally_tied_singleton_support_is_false() {
// Singleton-support pin: every env layer lands on the same env-
// prefix cell, so the lone observed cell stands alone at its
// own peak — `peak_multiplicity` reads `1` and the inequality
// `1 >= 2` fails. `env_prefix_kinds_modally_tied` reads `false`.
// Direct witness of the subsumption
// `env_prefix_kinds_singular_support ⇒
// !env_prefix_kinds_modally_tied` via the singleton-support
// corner. The `sample_chain()` fixture (two `.yaml` file layers
// + one `"APP_"` Env layer, `{Prefixed}` env-prefix support
// with count `1`) is a witness on the `false` side. Peer of
// `file_formats_modally_tied_singleton_support_is_false` and
// `layer_kinds_modally_tied_singleton_support_is_false` on the
// sister sub-axes of the same chain altitude,
// `tiers_modally_tied_singleton_support_is_false` on the tier
// altitude, and
// `kinds_modally_tied_singleton_support_is_false` on the diff
// altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_modally_tied());
}
#[test]
fn env_prefix_kinds_modally_tied_prefixed_only_is_false() {
// Singleton-support pin on the prefixed side: every env layer
// carries a non-empty prefix, so `Prefixed` is the sole
// observed cell out of two — peak multiplicity `1`, so
// `env_prefix_kinds_modally_tied` reads `false`. Symmetric
// sister of the bare-only pin below on the two-cell env-prefix
// axis: both singleton-support corners sit on the
// (`modally_tied`=false, `singular_support`=true) polarity
// pair. Peer of
// `env_prefix_kinds_partial_cover_prefixed_only_is_true` on
// the strict-complement partial-cover corner one seam over
// (the two projections are pointwise complementary on this
// fixture through the disjointness
// `singular_support ⇒ !modally_tied`).
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_modally_tied());
}
#[test]
fn env_prefix_kinds_modally_tied_bare_only_is_false() {
// Singleton-support pin on the bare side: every env layer
// carries the empty prefix, so `Bare` is the sole observed
// cell — peak multiplicity `1`, so
// `env_prefix_kinds_modally_tied` reads `false`. Symmetric
// sister of the prefixed-only pin above.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_modally_tied());
}
#[test]
fn env_prefix_kinds_modally_tied_uniform_two_kind_cover_is_true() {
// Uniform axis-cover pin: one prefixed + one bare env layer,
// so both cells of `EnvMetadataTagKind::ALL` receive equal
// counts (both `1`) — `peak_multiplicity` reads `2` and the
// inequality `2 >= 2` fires. `env_prefix_kinds_modally_tied`
// reads `true`. On the cardinality-`2` axis this is the *only*
// modally-tied witness class — every other non-empty
// configuration is either singleton-support (peak multiplicity
// `1`) or strictly-modal skewed (peak multiplicity `1`). Peer
// of the histogram-side axis-cover convention one altitude
// down, which reads `true` on every implementor with
// `axis_cardinality::<A>() >= 2` — the cardinality-`2`
// `EnvMetadataTagKind` axis honours the general condition.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 2);
assert!(slice.env_prefix_kinds_full_cover());
assert!(slice.env_prefix_kinds_balanced());
assert!(slice.env_prefix_kinds_modally_tied());
}
#[test]
fn env_prefix_kinds_modally_tied_uniform_two_kind_cover_at_count_two_is_true() {
// Multi-count uniform-cover pin: two prefixed + two bare env
// layers, so both cells of `EnvMetadataTagKind::ALL` receive
// equal counts (both `2`) — `peak_multiplicity` reads `2` and
// the inequality `2 >= 2` fires.
// `env_prefix_kinds_modally_tied` reads `true`. Direct pin that
// the modally-tied predicate depends only on the modal-cell
// multiplicity, not on the absolute count height — the uniform-
// cover corner witnesses `modally_tied = true` regardless of
// the height at which the cells are tied.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 2);
assert_eq!(slice.env_prefix_kind_histogram().peak_multiplicity(), 2);
assert!(slice.env_prefix_kinds_full_cover());
assert!(slice.env_prefix_kinds_balanced());
assert!(slice.env_prefix_kinds_modally_tied());
}
#[test]
fn env_prefix_kinds_modally_tied_strictly_modal_skewed_chain_is_false() {
// Strictly-modal skewed-chain pin: two prefixed + one bare env
// layer. `Prefixed` uniquely peaks at count `2` (Bare sits at
// `1`) — `peak_multiplicity` reads `1` and the inequality
// `1 >= 2` fails. `env_prefix_kinds_modally_tied` reads `false`.
// Witness on the strictly-modal side of the strict modal
// partition. Peer of
// `file_formats_modally_tied_strictly_modal_skewed_chain_is_false`
// and
// `layer_kinds_modally_tied_strictly_modal_skewed_chain_is_false`
// on the sister sub-axes of the same chain altitude,
// `tiers_modally_tied_strictly_modal_skewed_map_is_false` on the
// tier altitude, and
// `kinds_modally_tied_strictly_modal_skewed_diff_is_false` on
// the diff altitude.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(
slice.dominant_env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
);
assert_eq!(slice.peak_env_prefix_kind_count(), 2);
assert_eq!(slice.env_prefix_kind_histogram().peak_multiplicity(), 1);
assert!(!slice.env_prefix_kinds_modally_tied());
}
#[test]
fn env_prefix_kinds_modally_tied_implies_env_prefix_kinds_any_observed_pointwise() {
// Subsumption pin: `env_prefix_kinds_modally_tied() ⇒
// env_prefix_kinds_any_observed()` always. A tied peak requires
// at least two observed cells, so the empty chain (zero
// observed cells) and every no-env-layers non-empty chain
// (empty env-prefix histogram via the partial-function
// projection) cannot fire the tie predicate — every modally-
// tied chain observes at least one env-prefix cell (in fact
// both). Direct pin of the histogram-side subsumption
// `is_modally_tied ⇒ !is_empty` one altitude down. Peer of
// `file_formats_modally_tied_implies_file_formats_any_observed_pointwise`
// and
// `layer_kinds_modally_tied_implies_layer_kinds_any_observed_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_modally_tied_implies_tiers_any_observed_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_modally_tied() {
assert!(
slice.env_prefix_kinds_any_observed(),
"modally-tied chain must observe at least one env-prefix cell",
);
}
}
}
#[test]
fn env_prefix_kinds_modally_tied_implies_not_env_prefix_kinds_singular_support_pointwise() {
// Subsumption pin: `env_prefix_kinds_modally_tied() ⇒
// !env_prefix_kinds_singular_support()` always. A tied peak
// requires at least two observed cells sitting at the same
// maximum count, so the modal level set has cardinality `>= 2`
// — strictly more than the singleton-support corner. Direct
// pin of the histogram-side subsumption
// `has_singular_support ⇒ !is_modally_tied` (contrapositive)
// one altitude down. Peer of
// `file_formats_modally_tied_implies_not_file_formats_singular_support_pointwise`
// and
// `layer_kinds_modally_tied_implies_not_layer_kinds_singular_support_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_modally_tied_implies_not_tiers_singular_support_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_implies_not_kinds_singular_support_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_modally_tied() {
assert!(
!slice.env_prefix_kinds_singular_support(),
"modally-tied chain cannot be singular-support",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_support_implies_not_env_prefix_kinds_modally_tied_pointwise() {
// The forward direction of the singleton-support corner
// subsumption: `env_prefix_kinds_singular_support() ⇒
// !env_prefix_kinds_modally_tied()` always. A single observed
// cell is the only member of the modal level set (cardinality
// `1`), so the tie predicate never fires on any singleton-
// support chain. Every singleton-support chain sits uniformly
// on the strictly-modal-unique side of the strict modal
// partition. Peer of
// `file_formats_singular_support_implies_not_file_formats_modally_tied_pointwise`
// and
// `layer_kinds_singular_support_implies_not_layer_kinds_modally_tied_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_singular_support_implies_not_tiers_modally_tied_pointwise`
// on the tier altitude, and
// `kinds_singular_support_implies_not_kinds_modally_tied_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_support() {
assert!(
!slice.env_prefix_kinds_modally_tied(),
"singular-support chain cannot be modally tied",
);
}
}
}
#[test]
fn env_prefix_kinds_modally_tied_forms_strict_modal_partition_on_non_empty_histograms_pointwise()
{
// Strict modal partition pin on non-empty env-prefix
// histograms: on every chain whose env-prefix histogram is
// non-empty exactly one of the pair
// (env_prefix_kinds_modally_tied, is_strictly_modally_unique)
// fires. On the empty histogram (empty chain OR no-env-layers
// chain) both read `false` (the shared boundary below both
// branches of the strict modal partition). Direct pin of the
// histogram-side strict-modal-partition law
// `!is_empty ⇒ is_modally_tied ⇔ !is_strictly_modally_unique`
// one altitude down. Peer of
// `file_formats_modally_tied_forms_strict_modal_partition_on_non_empty_histograms_pointwise`
// and
// `layer_kinds_modally_tied_forms_strict_modal_partition_on_non_empty_chains_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_modally_tied_forms_strict_modal_partition_on_non_empty_maps_pointwise`
// on the tier altitude, and
// `kinds_modally_tied_forms_strict_modal_partition_on_non_empty_diffs_pointwise`
// on the diff altitude — closing the strict-modal-partition
// law at the fifth and final altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
let tied = slice.env_prefix_kinds_modally_tied();
let strict = hist.is_strictly_modally_unique();
if !hist.is_empty() {
let count = usize::from(tied) + usize::from(strict);
assert_eq!(
count, 1,
"on a non-empty env-prefix histogram exactly one of \
(modally_tied, strictly_modally_unique) must fire \
(tied={tied}, strict={strict})",
);
} else {
assert!(!tied, "empty env-prefix histogram cannot be modally tied");
assert!(
!strict,
"empty env-prefix histogram cannot be strictly modally unique",
);
}
}
}
#[test]
fn env_prefix_kinds_full_cover_and_env_prefix_kinds_balanced_imply_env_prefix_kinds_modally_tied_pointwise()
{
// Cardinality-`>= 2` uniform-cover pin: on every full-cover
// balanced chain on the cardinality-`2` `EnvMetadataTagKind`
// axis, the modal level set equals the full axis — both cells
// share the peak count — so `env_prefix_kinds_modally_tied`
// fires. Cardinality-`>= 2` witness of the histogram-side
// subsumption `is_uniform_count ∧ !is_empty ⇒ is_modally_tied
// ⇔ !has_singular_support` one altitude down. Peer of
// `file_formats_full_cover_and_file_formats_balanced_imply_file_formats_modally_tied_pointwise`
// and
// `layer_kinds_full_cover_and_layer_kinds_balanced_imply_layer_kinds_modally_tied_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_full_cover_and_tiers_balanced_imply_tiers_modally_tied_pointwise`
// on the tier altitude, and
// `kinds_full_cover_and_kinds_balanced_imply_kinds_modally_tied_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_full_cover() && slice.env_prefix_kinds_balanced() {
assert!(
slice.env_prefix_kinds_modally_tied(),
"full-cover balanced chain on cardinality-2 axis \
must be modally tied",
);
}
}
}
#[test]
fn env_prefix_kinds_modally_tied_iff_env_prefix_kinds_full_cover_and_env_prefix_kinds_balanced_on_cardinality_two_pointwise()
{
// Two-cell-axis modally_tied/uniform-cover equivalence pin:
// `env_prefix_kinds_modally_tied ⇔ env_prefix_kinds_full_cover
// ∧ env_prefix_kinds_balanced` on the cardinality-`2` env-
// prefix axis. On this axis the modal level set can reach
// cardinality `2` only when both cells are observed at the same
// count — i.e. precisely the uniform-cover corner. The
// *unique* two-cell-axis tightening of the general uniform-
// cover subsumption
// `env_prefix_kinds_full_cover ∧ env_prefix_kinds_balanced ⇒
// env_prefix_kinds_modally_tied` (documented at every altitude
// / sub-axis) into an equivalence, via the collapse of the
// modally-tied corner onto the uniform-cover boundary corner.
// Does NOT lift to the cardinality-`>= 3` sub-axes
// (`layer_kinds_modally_tied`, `file_formats_modally_tied`)
// where the strict-interior tied witness (two-of-three
// observed) carries `modally_tied=true, full_cover=false`, nor
// to the tier altitude (cardinality-`4`) where the support-`3`
// tied witness carries the same divergence.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let tied = slice.env_prefix_kinds_modally_tied();
let uniform = slice.env_prefix_kinds_full_cover() && slice.env_prefix_kinds_balanced();
assert_eq!(
tied, uniform,
"on the cardinality-2 env-prefix axis modally_tied ({tied}) \
must equal full_cover ∧ balanced ({uniform})",
);
}
}
#[test]
fn env_prefix_kinds_modally_tied_agrees_with_open_coded_peak_multiplicity_walk() {
// Parity against the exact hand-rolled peak-multiplicity walk
// this lift replaces: walk every cell of the histogram and
// count how many carry the maximum observed count; the modally-
// tied predicate reads `true` iff the multiplicity is at least
// `2`. Empty histogram has max `0` and no cells above zero, so
// multiplicity reads `0` and the predicate fails. Peer of
// `file_formats_modally_tied_agrees_with_open_coded_peak_multiplicity_walk`
// and
// `layer_kinds_modally_tied_agrees_with_open_coded_peak_multiplicity_walk`
// on the sister sub-axes of the same chain altitude,
// `tiers_modally_tied_agrees_with_open_coded_peak_multiplicity_walk`
// on the tier altitude, and
// `kinds_modally_tied_agrees_with_open_coded_peak_multiplicity_walk`
// on the diff altitude — closing the peak-multiplicity parity
// discipline at the fifth and final altitude / sub-axis in the
// "modally-tied across altitudes" projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_modally_tied();
let hist = slice.env_prefix_kind_histogram();
let max = hist.iter().map(|(_, c)| c).max().unwrap_or(0);
let hand_rolled = if max == 0 {
false
} else {
hist.iter().filter(|(_, c)| *c == max).count() >= 2
};
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_antimodally_tied —
// antimodally-tied-env-prefix-kinds boolean predicate on the
// env-prefix sub-axis of the chain altitude, lifting
// is_antimodally_tied from the histogram surface and closing
// the "antimodally-tied across altitudes" projection at the
// fifth and final altitude / sub-axis. Antimodal-side row
// complementary to `env_prefix_kinds_modally_tied` at the
// same env-prefix sub-axis — with this closing the modality-
// tie boolean pair `(is_modally_tied, is_antimodally_tied)`
// carries both rows at every altitude / sub-axis of the 5-
// column grid ----
#[test]
fn env_prefix_kinds_antimodally_tied_matches_env_prefix_kind_histogram_is_antimodally_tied_pointwise()
{
// Routing pin: `env_prefix_kinds_antimodally_tied` routes
// through `env_prefix_kind_histogram().is_antimodally_tied()`,
// so the two seams must stay pointwise equivalent under every
// fixture. Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive.
// Env-prefix sub-axis peer of
// `file_formats_antimodally_tied_matches_file_format_histogram_is_antimodally_tied_pointwise`
// and
// `layer_kinds_antimodally_tied_matches_layer_kind_histogram_is_antimodally_tied_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_antimodally_tied_matches_tier_histogram_is_antimodally_tied_pointwise`
// on the tier altitude, and
// `kinds_antimodally_tied_matches_kind_histogram_is_antimodally_tied_pointwise`
// on the diff altitude — closing the "antimodally-tied across
// altitudes" projection across every altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().is_antimodally_tied();
assert_eq!(slice.env_prefix_kinds_antimodally_tied(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_matches_defining_trough_multiplicity_inequality_pointwise()
{
// Defining multiplicity-scalar inequality form:
// `env_prefix_kinds_antimodally_tied() ⇔
// env_prefix_kind_histogram().trough_multiplicity() >= 2`. Pins
// the predicate against the canonical open-coded expression on
// the `AxisHistogram::trough_multiplicity` scalar peer one
// altitude down. Peer of the trough-multiplicity inequality
// pin at every sibling altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_antimodally_tied();
let mult = slice.env_prefix_kind_histogram().trough_multiplicity();
let via_scalar = mult >= 2;
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_antimodally_tied ({via_seam}) must agree with \
trough_multiplicity >= 2 ({via_scalar}, mult={mult})",
);
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_matches_modality_degree_antimodal_component_pointwise() {
// Modality-pair projection-inequality form:
// `env_prefix_kinds_antimodally_tied() ⇔
// env_prefix_kind_histogram().modality_degree().1 >= 2`. Pins
// the predicate against the antimodal-component reading of the
// fused `(peak_multiplicity, trough_multiplicity)` pair.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_antimodally_tied();
let (_, trough_mult) = slice.env_prefix_kind_histogram().modality_degree();
let via_pair = trough_mult >= 2;
assert_eq!(
via_seam, via_pair,
"env_prefix_kinds_antimodally_tied ({via_seam}) must agree with \
modality_degree().1 >= 2 ({via_pair}, trough_mult={trough_mult})",
);
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_empty_chain_is_false() {
// Empty-chain antimodal-tie: the empty chain observes zero
// cells, so `trough_multiplicity` reads `0` and the inequality
// `0 >= 2` fails. Peer of the empty-chain false polarity at
// every sibling altitude / sub-axis in the "antimodally-tied
// across altitudes" projection — closing the empty-witness
// row at the fifth and final altitude / sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_antimodally_tied());
assert!(!empty.env_prefix_kinds_any_observed());
}
#[test]
fn env_prefix_kinds_antimodally_tied_no_env_layers_is_false() {
// No-env-layers pin: a non-empty chain of only `Defaults` /
// `File` layers projects to an empty env-prefix histogram via
// the partial function `ConfigSource::env_prefix_kind` —
// `trough_multiplicity` reads `0` and the inequality `0 >= 2`
// fails. Cross-sub-axis divergence pin against
// `layer_kinds_antimodally_tied`: on the same fixture the
// layer-kind sub-axis observes at least one layer-kind cell
// and may fire the antimodal-tie predicate (e.g. one
// `Defaults` + one `File` reads `layer_kinds_antimodally_tied
// = true`), while the env-prefix sub-axis's antimodal-tie
// predicate silently drops out via the empty-histogram
// disjunct — the antimodal-tie leg is *narrower* at the env-
// prefix sub-axis than at the layer-kind sub-axis. Mirrors the
// shape of `file_formats_antimodally_tied_no_recognized_files_is_false`
// on the sister partial-function sub-axis, and of
// `env_prefix_kinds_modally_tied_no_env_layers_is_false` on
// the sibling modal-tie row at the same env-prefix sub-axis.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert!(
!slice.env_prefix_kinds_antimodally_tied(),
"no-env-layers chain must not fire antimodally-tied",
);
assert!(!slice.env_prefix_kinds_any_observed());
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_singleton_support_is_false() {
// Singleton-support pin: every env layer lands on the same
// env-prefix cell, so the lone observed cell stands alone at
// its own trough — `trough_multiplicity` reads `1` and the
// inequality `1 >= 2` fails. Direct witness of the subsumption
// `env_prefix_kinds_singular_support ⇒
// !env_prefix_kinds_antimodally_tied` via the singleton-
// support corner. The `sample_chain()` fixture is a witness on
// the `false` side.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_antimodally_tied());
}
#[test]
fn env_prefix_kinds_antimodally_tied_prefixed_only_is_false() {
// Singleton-support pin on the prefixed side: `Prefixed` is
// the sole observed cell out of two — trough multiplicity `1`,
// so `env_prefix_kinds_antimodally_tied` reads `false`.
// Symmetric sister of the bare-only pin below on the two-cell
// env-prefix axis: both singleton-support corners sit on the
// (`antimodally_tied`=false, `singular_support`=true) polarity
// pair.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_antimodally_tied());
}
#[test]
fn env_prefix_kinds_antimodally_tied_bare_only_is_false() {
// Singleton-support pin on the bare side: `Bare` is the sole
// observed cell — trough multiplicity `1`, so
// `env_prefix_kinds_antimodally_tied` reads `false`. Symmetric
// sister of the prefixed-only pin above.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_antimodally_tied());
}
#[test]
fn env_prefix_kinds_antimodally_tied_uniform_two_kind_cover_is_true() {
// Uniform axis-cover pin: one prefixed + one bare env layer,
// so both cells of `EnvMetadataTagKind::ALL` receive equal
// counts (both `1`) — `trough_multiplicity` reads `2` and the
// inequality `2 >= 2` fires. On the cardinality-`2` axis this
// is the *only* antimodally-tied witness class — every other
// non-empty configuration is either singleton-support (trough
// multiplicity `1`) or strictly-skewed (trough multiplicity
// `1`). Peer of the histogram-side axis-cover convention one
// altitude down.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 2);
assert!(slice.env_prefix_kinds_full_cover());
assert!(slice.env_prefix_kinds_balanced());
assert!(slice.env_prefix_kinds_antimodally_tied());
}
#[test]
fn env_prefix_kinds_antimodally_tied_uniform_two_kind_cover_at_count_two_is_true() {
// Multi-count uniform-cover pin: two prefixed + two bare env
// layers, so both cells receive equal counts (both `2`) —
// `trough_multiplicity` reads `2` and the inequality `2 >= 2`
// fires. Direct pin that the antimodally-tied predicate depends
// only on the antimodal-cell multiplicity, not on the absolute
// count height — the uniform-cover corner witnesses
// `antimodally_tied = true` regardless of the height at which
// the cells are tied.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 2);
assert_eq!(slice.env_prefix_kind_histogram().trough_multiplicity(), 2);
assert!(slice.env_prefix_kinds_full_cover());
assert!(slice.env_prefix_kinds_balanced());
assert!(slice.env_prefix_kinds_antimodally_tied());
}
#[test]
fn env_prefix_kinds_antimodally_tied_strictly_skewed_chain_is_false() {
// Strictly-skewed chain pin: two prefixed + one bare env
// layer. `Bare` uniquely holds the trough at count `1` while
// `Prefixed` peaks at count `2` — `trough_multiplicity` reads
// `1` and the inequality `1 >= 2` fails.
// `env_prefix_kinds_antimodally_tied` reads `false`. Witness on
// the strictly-antimodal-unique side of the strict antimodal
// partition. On the cardinality-`2` axis every strictly-skewed
// chain is *identically* strictly-modal and strictly-antimodal
// (peak and trough are the two distinct counts, both held by
// a single cell), so this chain also reads
// `env_prefix_kinds_modally_tied = false` — the full modal /
// antimodal collapse degeneracy of the two-cell axis.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.env_prefix_kind_histogram().trough_multiplicity(), 1);
assert_eq!(slice.env_prefix_kind_histogram().peak_multiplicity(), 1);
assert!(!slice.env_prefix_kinds_antimodally_tied());
assert!(!slice.env_prefix_kinds_modally_tied());
}
#[test]
fn env_prefix_kinds_antimodally_tied_implies_env_prefix_kinds_any_observed_pointwise() {
// Subsumption pin: `env_prefix_kinds_antimodally_tied() ⇒
// env_prefix_kinds_any_observed()` always. A tied trough
// requires at least two observed cells, so the empty chain and
// every no-env-layers non-empty chain cannot fire the tie
// predicate. Direct pin of the histogram-side subsumption
// `is_antimodally_tied ⇒ !is_empty` one altitude down.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_antimodally_tied() {
assert!(
slice.env_prefix_kinds_any_observed(),
"antimodally-tied chain must observe at least one env-prefix cell",
);
}
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_implies_not_env_prefix_kinds_singular_support_pointwise() {
// Subsumption pin: `env_prefix_kinds_antimodally_tied() ⇒
// !env_prefix_kinds_singular_support()` always. A tied trough
// requires at least two observed cells sitting at the same
// minimum count. Direct pin of the histogram-side subsumption
// `has_singular_support ⇒ !is_antimodally_tied`
// (contrapositive) one altitude down.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_antimodally_tied() {
assert!(
!slice.env_prefix_kinds_singular_support(),
"antimodally-tied chain cannot be singular-support",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_support_implies_not_env_prefix_kinds_antimodally_tied_pointwise() {
// The forward direction of the singleton-support corner
// subsumption: `env_prefix_kinds_singular_support() ⇒
// !env_prefix_kinds_antimodally_tied()` always. Every
// singleton-support chain sits uniformly on the strictly-
// antimodal-unique side of the strict antimodal partition.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_support() {
assert!(
!slice.env_prefix_kinds_antimodally_tied(),
"singular-support chain cannot be antimodally tied",
);
}
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_forms_strict_antimodal_partition_on_non_empty_histograms_pointwise()
{
// Strict antimodal partition pin on non-empty env-prefix
// histograms: on every chain whose env-prefix histogram is
// non-empty exactly one of the pair
// (env_prefix_kinds_antimodally_tied,
// is_strictly_antimodally_unique) fires. On the empty histogram
// (empty chain OR no-env-layers chain) both read `false` — the
// shared boundary below both branches of the strict antimodal
// partition. Direct pin of the histogram-side strict-antimodal-
// partition law `!is_empty ⇒ is_antimodally_tied ⇔
// !is_strictly_antimodally_unique` one altitude down — closing
// the strict-antimodal-partition law at the fifth and final
// altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let hist = slice.env_prefix_kind_histogram();
let tied = slice.env_prefix_kinds_antimodally_tied();
let strict = hist.is_strictly_antimodally_unique();
if !hist.is_empty() {
let count = usize::from(tied) + usize::from(strict);
assert_eq!(
count, 1,
"on a non-empty env-prefix histogram exactly one of \
(antimodally_tied, strictly_antimodally_unique) must fire \
(tied={tied}, strict={strict})",
);
} else {
assert!(
!tied,
"empty env-prefix histogram cannot be antimodally tied"
);
assert!(
!strict,
"empty env-prefix histogram cannot be strictly antimodally unique",
);
}
}
}
#[test]
fn env_prefix_kinds_full_cover_and_env_prefix_kinds_balanced_imply_env_prefix_kinds_antimodally_tied_pointwise()
{
// Cardinality-`>= 2` uniform-cover pin: on every full-cover
// balanced chain on the cardinality-`2` `EnvMetadataTagKind`
// axis, the antimodal level set equals the full axis — both
// cells share the trough count — so
// `env_prefix_kinds_antimodally_tied` fires. Cardinality-`>= 2`
// witness of the histogram-side subsumption
// `is_uniform_count ∧ !is_empty ⇒ is_antimodally_tied ⇔
// !has_singular_support` one altitude down.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_full_cover() && slice.env_prefix_kinds_balanced() {
assert!(
slice.env_prefix_kinds_antimodally_tied(),
"full-cover balanced chain on cardinality-2 axis \
must be antimodally tied",
);
}
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_iff_env_prefix_kinds_full_cover_and_env_prefix_kinds_balanced_on_cardinality_two_pointwise()
{
// Two-cell-axis antimodally_tied/uniform-cover equivalence pin:
// `env_prefix_kinds_antimodally_tied ⇔
// env_prefix_kinds_full_cover ∧ env_prefix_kinds_balanced` on
// the cardinality-`2` env-prefix axis. On this axis the
// antimodal level set can reach cardinality `2` only when both
// cells are observed at the same count — i.e. precisely the
// uniform-cover corner. The *unique* two-cell-axis tightening
// of the general uniform-cover subsumption into an equivalence.
// Does NOT lift to the cardinality-`>= 3` sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let tied = slice.env_prefix_kinds_antimodally_tied();
let uniform = slice.env_prefix_kinds_full_cover() && slice.env_prefix_kinds_balanced();
assert_eq!(
tied, uniform,
"on the cardinality-2 env-prefix axis antimodally_tied ({tied}) \
must equal full_cover ∧ balanced ({uniform})",
);
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_collapses_with_env_prefix_kinds_modally_tied_on_uniform_multi_cell_chains_pointwise()
{
// Modal / antimodal collapse pin: on every uniform-count non-
// empty env-prefix histogram the two tie predicates read the
// same value. Direct pin of the histogram-side collapse law
// `is_uniform_count ∧ !is_empty ⇒ is_antimodally_tied ⇔
// is_modally_tied` one altitude down, at the chain env-prefix
// sub-axis. Peer of
// `file_formats_antimodally_tied_collapses_with_file_formats_modally_tied_on_uniform_multi_cell_chains_pointwise`
// and
// `layer_kinds_antimodally_tied_collapses_with_layer_kinds_modally_tied_on_uniform_multi_cell_chains_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_antimodally_tied_collapses_with_tiers_modally_tied_on_uniform_multi_cell_maps_pointwise`
// on the tier altitude, and
// `kinds_antimodally_tied_collapses_with_kinds_modally_tied_on_uniform_multi_cell_diffs_pointwise`
// on the diff altitude — closing the modal / antimodal collapse
// law at the fifth and final altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_balanced() && slice.env_prefix_kinds_any_observed() {
assert_eq!(
slice.env_prefix_kinds_antimodally_tied(),
slice.env_prefix_kinds_modally_tied(),
"on a uniform-count non-empty env-prefix histogram \
the two tie predicates must collapse to the same value",
);
}
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_iff_env_prefix_kinds_modally_tied_on_cardinality_two_pointwise()
{
// **Full modal / antimodal collapse pin — unique to the
// cardinality-`2` env-prefix axis.** On this axis
// `env_prefix_kinds_antimodally_tied ⇔
// env_prefix_kinds_modally_tied` on *every* histogram
// (empty, singleton-support, uniform, strictly-skewed) — a
// strict tightening of the uniform-count-non-empty collapse
// law above into an unconditional equivalence. Direct
// consequence of the two-cell degeneracy where the peak level
// set and the trough level set coincide pointwise: either both
// cells share the same count (uniform two-kind cover, both
// multiplicities read `2`, both tie predicates fire), or the
// cells carry distinct counts (peak and trough are the two
// distinct counts, both multiplicities read `1`, neither
// fires), or only one cell is observed (singleton-support,
// multiplicity `1`, neither fires), or neither is observed
// (empty histogram, both read `false`). This unconditional
// equivalence does NOT lift to the cardinality-`>= 3` sister
// sub-axes (`layer_kinds`, `file_formats`) or the tier /
// diff altitudes, where the two strict-interior corners
// `(modally_tied, antimodally_tied) ∈ {(true, false),
// (false, true)}` carry witnesses non-vacuously. The tightest
// degenerate form of the tie-pair collapse in the projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
assert_eq!(
slice.env_prefix_kinds_antimodally_tied(),
slice.env_prefix_kinds_modally_tied(),
"on the cardinality-2 env-prefix axis the two tie \
predicates must collapse to the same value on every \
histogram shape",
);
}
}
#[test]
fn env_prefix_kinds_antimodally_tied_agrees_with_open_coded_trough_multiplicity_walk() {
// Parity against the exact hand-rolled trough-multiplicity
// walk this lift replaces: walk every cell of the histogram
// and count how many carry the strictly-positive minimum
// observed count; the antimodally-tied predicate reads `true`
// iff the multiplicity is at least `2`. Empty histogram has
// no strictly-positive counts, so multiplicity reads `0` and
// the predicate fails. Peer of the trough-multiplicity walk
// parity at every sibling altitude / sub-axis — closing the
// trough-multiplicity parity discipline at the fifth and final
// altitude / sub-axis in the "antimodally-tied across
// altitudes" projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_antimodally_tied();
let hist = slice.env_prefix_kind_histogram();
let min = hist
.iter()
.map(|(_, c)| c)
.filter(|c| *c > 0)
.min()
.unwrap_or(0);
let hand_rolled = if min == 0 {
false
} else {
hist.iter().filter(|(_, c)| *c == min).count() >= 2
};
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_full_cover — full-cover-
// env-prefix-kinds boolean predicate on the env-prefix sub-axis
// of the chain altitude, lifting is_full_cover from the histogram
// surface and closing the "full-cover across altitudes"
// projection sideways to the third and final chain-altitude
// sub-axis ----
#[test]
fn env_prefix_kinds_full_cover_matches_env_prefix_kind_histogram_is_full_cover_pointwise() {
// The routing pin: `env_prefix_kinds_full_cover` routes through
// `env_prefix_kind_histogram().is_full_cover()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops projecting
// through the shared cube-native primitive. Env-prefix sub-axis
// peer of
// `file_formats_full_cover_matches_file_format_histogram_is_full_cover_pointwise`
// and
// `layer_kinds_full_cover_matches_layer_kind_histogram_is_full_cover_pointwise`
// on the sister sub-axes of the chain altitude,
// `tiers_full_cover_matches_tier_histogram_is_full_cover_pointwise`
// on the tier altitude, and
// `kinds_full_cover_matches_kind_histogram_is_full_cover_pointwise`
// on the diff altitude — closing the "full-cover across
// altitudes" projection across every altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().is_full_cover();
assert_eq!(slice.env_prefix_kinds_full_cover(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_full_cover_agrees_with_absent_env_prefix_kinds_empty_pointwise() {
// The defining equivalence on the coverage-gap-Vec surface at
// the env-prefix sub-axis: `env_prefix_kinds_full_cover() ==
// absent_env_prefix_kinds().is_empty()` on every fixture. The
// full-cover-boundary of the fused `(absent_env_prefix_kinds,
// absent_env_prefix_kinds_count)` coverage-gap peers as a named
// boolean predicate. Lifted from the trait-uniform
// `is_full_cover() == unobserved().next().is_none()` law on
// AxisHistogram. Peer of
// `file_formats_full_cover_agrees_with_absent_file_formats_empty_pointwise`
// and
// `layer_kinds_full_cover_agrees_with_absent_layer_kinds_empty_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.env_prefix_kinds_full_cover();
let gap_empty = slice.absent_env_prefix_kinds().is_empty();
assert_eq!(
full_cover, gap_empty,
"env_prefix_kinds_full_cover ({full_cover}) must agree with \
absent_env_prefix_kinds().is_empty() ({gap_empty}) for chain",
);
}
}
#[test]
fn env_prefix_kinds_full_cover_agrees_with_absent_env_prefix_kinds_count_zero_pointwise() {
// The coverage-gap-scalar form: `env_prefix_kinds_full_cover() ==
// (absent_env_prefix_kinds_count() == 0)` on every fixture. Pins
// the full-cover-env-prefix-kinds predicate against the scalar-
// zero equality form on the coverage-gap side. Peer of
// `file_formats_full_cover_agrees_with_absent_file_formats_count_zero_pointwise`
// and
// `layer_kinds_full_cover_agrees_with_absent_layer_kinds_count_zero_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.env_prefix_kinds_full_cover();
let count_zero = slice.absent_env_prefix_kinds_count() == 0;
assert_eq!(
full_cover,
count_zero,
"env_prefix_kinds_full_cover ({full_cover}) must agree with \
absent_env_prefix_kinds_count == 0 (count={c}) for chain",
c = slice.absent_env_prefix_kinds_count(),
);
}
}
#[test]
fn env_prefix_kinds_full_cover_agrees_with_present_env_prefix_kinds_count_equals_axis_cardinality_pointwise()
{
// The support-scalar form: `env_prefix_kinds_full_cover() ==
// (present_env_prefix_kinds_count() ==
// axis_cardinality::<EnvMetadataTagKind>())` on every fixture —
// the dual-side surfacing of the same boolean across the
// (observed, unobserved) partition. Lifted from the trait-
// uniform `is_full_cover() == (distinct_cells() ==
// axis_cardinality::<A>())` law on AxisHistogram. Peer of
// `file_formats_full_cover_agrees_with_present_file_formats_count_equals_axis_cardinality_pointwise`
// and
// `layer_kinds_full_cover_agrees_with_present_layer_kinds_count_equals_axis_cardinality_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.env_prefix_kinds_full_cover();
let support_full = slice.present_env_prefix_kinds_count()
== crate::axis_cardinality::<EnvMetadataTagKind>();
assert_eq!(
full_cover, support_full,
"env_prefix_kinds_full_cover ({full_cover}) must agree with \
present_env_prefix_kinds_count == axis_cardinality for chain",
);
}
}
#[test]
fn env_prefix_kinds_full_cover_agrees_with_present_env_prefix_kinds_len_equals_axis_cardinality_pointwise()
{
// The support-Vec form: `env_prefix_kinds_full_cover() ==
// (present_env_prefix_kinds().len() ==
// axis_cardinality::<EnvMetadataTagKind>())` on every fixture.
// Pins the predicate against the `Vec<EnvMetadataTagKind>` length
// form consumers reach for when they already hold the support
// vector. Peer of
// `file_formats_full_cover_agrees_with_present_file_formats_len_equals_axis_cardinality_pointwise`
// and
// `layer_kinds_full_cover_agrees_with_present_layer_kinds_len_equals_axis_cardinality_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let full_cover = slice.env_prefix_kinds_full_cover();
let support_len_full = slice.present_env_prefix_kinds().len()
== crate::axis_cardinality::<EnvMetadataTagKind>();
assert_eq!(
full_cover, support_len_full,
"env_prefix_kinds_full_cover ({full_cover}) must agree with \
present_env_prefix_kinds().len() == axis_cardinality for chain",
);
}
}
#[test]
fn env_prefix_kinds_full_cover_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has no observed cells,
// so the coverage gap equals every cell of
// `EnvMetadataTagKind::ALL` (two-cell axis, no zero-cardinality
// degenerate case) — `env_prefix_kinds_full_cover` reads `false`.
// Dual of `env_prefix_kinds_balanced_empty_chain_is_true`: the
// empty chain is on the opposite side of the full-cover boundary
// from the balanced boundary at the env-prefix sub-axis, matching
// the diff-altitude / tier-altitude / layer-kind / file-format
// sub-axis empty-vs-empty orthogonality. Matches `is_full_cover`
// reading `false` on the empty histogram over a non-zero-
// cardinality axis one altitude down. Peer of
// `file_formats_full_cover_empty_chain_is_false` and
// `layer_kinds_full_cover_empty_chain_is_false` on the sister
// sub-axes.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_full_cover());
assert_eq!(
empty.absent_env_prefix_kinds_count(),
crate::axis_cardinality::<EnvMetadataTagKind>()
);
}
#[test]
fn env_prefix_kinds_full_cover_no_env_layers_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_full_cover_empty_chain_is_false`: on the env-
// prefix sub-axis the *non-empty-chain / empty-histogram*
// boundary ALSO reads `false`. A chain of only Defaults / File
// layers is non-empty but has an empty env-prefix histogram
// (every `Env` entry would project to a `Some` cell, but there
// are no `Env` entries), so the coverage gap equals every cell
// — `env_prefix_kinds_full_cover` reads `false`. Distinguishing
// pin against `env_prefix_kinds_balanced` on the exact same
// fixtures (where the vacuous-uniformity boundary reads `true`):
// full-cover and balanced fall on opposite sides of the empty-
// histogram boundary at the env-prefix sub-axis. Agreement with
// `file_formats_full_cover_no_recognized_files_is_false` on the
// sister sub-axis's non-empty-chain / empty-histogram boundary.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert!(!slice.env_prefix_kinds_full_cover());
assert!(slice.env_prefix_kinds_balanced());
}
}
#[test]
fn env_prefix_kinds_full_cover_prefixed_only_is_false() {
// Singleton-support pin (prefixed side): every env layer carries
// a non-empty prefix, so only the Prefixed cell is observed —
// one observed cell out of two leaves Bare in the coverage gap
// — `env_prefix_kinds_full_cover` reads `false`. Peer of
// `env_prefix_kinds_balanced_singleton_support_is_true` on the
// opposite side of the boundary: singleton-support is trivially
// balanced but never full-cover on a two-cell axis. Peer of
// `file_formats_full_cover_singleton_support_is_false` and
// `layer_kinds_full_cover_singleton_support_is_false` on the
// sister sub-axes.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(!slice.env_prefix_kinds_full_cover());
assert!(
slice
.absent_env_prefix_kinds()
.contains(&EnvMetadataTagKind::Bare)
);
}
#[test]
fn env_prefix_kinds_full_cover_bare_only_is_false() {
// Singleton-support pin (bare side): every env layer carries the
// empty prefix, so only the Bare cell is observed — one observed
// cell out of two leaves Prefixed in the coverage gap —
// `env_prefix_kinds_full_cover` reads `false`. Symmetric witness
// to `env_prefix_kinds_full_cover_prefixed_only_is_false` on the
// opposite side of the two-cell axis: both singleton-support
// shapes read `false` on the full-cover boundary, and both read
// `true` on the balanced boundary.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(!slice.env_prefix_kinds_full_cover());
assert!(
slice
.absent_env_prefix_kinds()
.contains(&EnvMetadataTagKind::Prefixed)
);
}
#[test]
fn env_prefix_kinds_full_cover_uniform_cover_is_true() {
// Uniform-cover pin: every env-prefix kind contributes one env
// layer, so both cells of `EnvMetadataTagKind::ALL` receive at
// least one observation — `env_prefix_kinds_full_cover` reads
// `true`. Peer of `env_prefix_kinds_balanced_uniform_cover_is_true`
// on the same fixture shape (uniform two-kind cover): uniform
// full-cover is on the `true` side of BOTH the balanced-env-
// prefix-kinds and full-cover-env-prefix-kinds boundaries. Peer
// of `file_formats_full_cover_uniform_cover_is_true` and
// `layer_kinds_full_cover_uniform_cover_is_true` on the sister
// sub-axes.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kinds_full_cover());
assert!(slice.env_prefix_kinds_balanced());
}
#[test]
fn env_prefix_kinds_full_cover_skewed_two_cell_fixture_is_true() {
// Direct pin: a strictly-skewed two-cell chain with Bare=3,
// Prefixed=1 has both cells observed — `env_prefix_kinds_full_cover`
// reads `true`, orthogonal to `env_prefix_kinds_balanced` which
// reads `false` on the identical fixture (peak 3, trough 1,
// spread 2). Both cells observed but at distinct counts: full-
// cover is the coverage boundary, not the uniformity boundary.
// Peer of `file_formats_full_cover_skewed_four_cell_fixture_is_true`
// and `layer_kinds_full_cover_skewed_three_cell_fixture_is_true`
// on the sister sub-axes and
// `tiers_full_cover_skewed_four_cell_fixture_is_true` on the
// tier altitude.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kinds_full_cover());
assert!(!slice.env_prefix_kinds_balanced());
assert_eq!(slice.env_prefix_kind_spread(), 2);
}
#[test]
fn env_prefix_kinds_full_cover_sample_chain_is_false() {
// Direct pin against `sample_chain()`: two `.yaml` file layers
// + one Env layer with a prefixed name. The support is {Prefixed}
// — size 1 out of 2 — so `env_prefix_kinds_full_cover` reads
// `false`. Peer of `env_prefix_kinds_balanced_sample_chain_is_true`
// on the same fixture on the sister boundary: balanced reads
// `true` (singleton support is trivially balanced) while full-
// cover reads `false` — orthogonal boundary witnesses at the
// same fixture. Agreement with
// `file_formats_full_cover_sample_chain_is_false` on the sister
// sub-axis.
let chain = sample_chain();
let slice = chain.as_slice();
assert!(!slice.env_prefix_kinds_full_cover());
assert!(
slice
.absent_env_prefix_kinds()
.contains(&EnvMetadataTagKind::Bare)
);
}
#[test]
fn env_prefix_kinds_full_cover_implies_env_prefix_kind_histogram_is_nonempty() {
// Contrapositive of the empty-histogram boundary:
// `env_prefix_kinds_full_cover() ⇒
// !env_prefix_kind_histogram().is_empty()`. A full-cover chain
// observes at least one env layer per kind, so the histogram is
// non-empty. Directly witnessed on the fixture set. Cross-sub-
// axis divergence from the layer-kind sub-axis's
// `layer_kinds_full_cover_implies_chain_is_nonempty` pin: the
// env-prefix sub-axis's contrapositive reads on the *histogram-
// empty* condition rather than the *chain-empty* condition,
// matching the file-format sub-axis's contrapositive. The empty-
// histogram / non-empty-chain distinction separates the env-
// prefix / file-format sub-axes' vacuous-uniformity boundaries
// from the layer-kind sub-axis's.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_full_cover() {
assert!(
!slice.env_prefix_kind_histogram().is_empty(),
"full-cover chain must have non-empty env-prefix histogram",
);
}
}
}
#[test]
fn env_prefix_kinds_full_cover_implies_present_env_prefix_kinds_equals_axis_cardinality() {
// Structural characterization: `env_prefix_kinds_full_cover() ⇒
// present_env_prefix_kinds().len() ==
// axis_cardinality::<EnvMetadataTagKind>()`. A full-cover chain
// observes every kind, so the support size equals the axis
// cardinality. Direct witness of the trait-uniform
// `is_full_cover() ⇒ distinct_cells() == axis_cardinality::<A>()`
// law on AxisHistogram, lifted to the env-prefix sub-axis of the
// chain altitude. Peer of
// `file_formats_full_cover_implies_present_file_formats_equals_axis_cardinality`
// and
// `layer_kinds_full_cover_implies_present_layer_kinds_equals_axis_cardinality`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_full_cover() {
assert_eq!(
slice.present_env_prefix_kinds().len(),
crate::axis_cardinality::<EnvMetadataTagKind>(),
"full-cover chain must observe every EnvMetadataTagKind",
);
}
}
}
#[test]
fn env_prefix_kinds_full_cover_implies_env_prefix_kind_histogram_total_bounded_below_by_axis_cardinality()
{
// Histogram-total lower-bound characterization:
// `env_prefix_kinds_full_cover() ⇒
// env_prefix_kind_histogram().total() >=
// axis_cardinality::<EnvMetadataTagKind>()`. A full-cover chain
// observes at least one env layer per kind, so the histogram
// total is bounded below by the axis cardinality. Directly
// witnessed on the fixture set. Cross-sub-axis divergence from
// the layer-kind sub-axis's
// `layer_kinds_full_cover_implies_chain_length_bounded_below_by_axis_cardinality`
// pin: on the env-prefix sub-axis the lower bound reads on the
// *histogram total* rather than the chain length — the chain
// may include unrelated Defaults / File layers that don't
// contribute to the histogram but grow the chain length.
// Agreement with the file-format sub-axis's histogram-total
// lower-bound.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_full_cover() {
assert!(
slice.env_prefix_kind_histogram().total()
>= crate::axis_cardinality::<EnvMetadataTagKind>(),
"full-cover chain must have histogram total >= axis_cardinality (was {})",
slice.env_prefix_kind_histogram().total(),
);
}
}
}
#[test]
fn env_prefix_kinds_full_cover_implies_layer_kind_env_count_bounded_below_by_axis_cardinality()
{
// Cross-sub-axis lower-bound implication: a full-cover chain on
// the env-prefix sub-axis observes at least one env layer per
// kind; every such layer is a `ConfigSource::Env`, so the
// layer-kind-sub-axis Env cell count is bounded below by the
// env-prefix axis cardinality. Directly witnesses the cross-
// sub-axis link between the env-prefix sub-axis's full-cover
// boundary and the layer-kind sub-axis's Env cell count. Sister
// of the file-format sub-axis's
// `file_formats_full_cover_implies_layer_kind_file_count_bounded_below_by_axis_cardinality`
// lower-bound linking that sub-axis's full-cover boundary to the
// layer-kind File cell count.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_full_cover() {
assert!(
slice.layer_kind_histogram().count(ConfigSourceKind::Env)
>= crate::axis_cardinality::<EnvMetadataTagKind>(),
"full-cover chain must have >= axis_cardinality Env layers (was {})",
slice.layer_kind_histogram().count(ConfigSourceKind::Env),
);
}
}
}
#[test]
fn env_prefix_kinds_full_cover_balanced_or_full_cover_covers_every_chain() {
// Two-cell-axis tightening unique to the env-prefix sub-axis:
// `!env_prefix_kinds_balanced() ⇒ env_prefix_kinds_full_cover()`,
// equivalently `env_prefix_kinds_balanced() ||
// env_prefix_kinds_full_cover()` on every chain. Any imbalance on
// the two-cell axis observes both cells at differing nonzero
// counts, so the imbalanced chain is automatically full-cover.
// Direct witness that the two-cell axis carries no "imbalanced-
// and-not-full-cover" region — distinguishing pin against the
// three-cell layer-kind sub-axis and the four-cell file-format
// sub-axis, where imbalance is compatible with partial cover
// (e.g. the layer-kind sub-axis reads `!balanced && !full_cover`
// on `sample_chain()` where File=2, Defaults=0, Env=1). Also
// verifies the intersection: uniform full-cover reads `true` on
// both boundaries at once (witnessed by
// `env_prefix_kinds_full_cover_uniform_cover_is_true`).
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let balanced = slice.env_prefix_kinds_balanced();
let full_cover = slice.env_prefix_kinds_full_cover();
assert!(
balanced || full_cover,
"every chain must be env_prefix_kinds_balanced ({balanced}) or \
env_prefix_kinds_full_cover ({full_cover}) on the two-cell axis",
);
}
}
#[test]
fn env_prefix_kinds_full_cover_agrees_with_open_coded_all_positive_walk() {
// Parity against the exact hand-rolled full-cover walk this
// lift replaces: walk every cell of the histogram and check
// every count is positive. Mirrors the parity pins
// `file_formats_full_cover_agrees_with_open_coded_all_positive_walk`
// and
// `layer_kinds_full_cover_agrees_with_open_coded_all_positive_walk`
// on the sister sub-axes,
// `tiers_full_cover_agrees_with_open_coded_all_positive_walk`
// on the tier altitude, and
// `kinds_full_cover_agrees_with_open_coded_all_positive_walk`
// on the diff altitude. Note the walk uses `hist.iter()` which
// iterates over the closed axis's ALL cells in declaration
// order — a full-cover chain has every cell nonzero regardless
// of order.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_full_cover();
let hist = slice.env_prefix_kind_histogram();
let hand_rolled = hist.iter().all(|(_, c)| c > 0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_any_observed — any-observed-
// env-prefix-kinds boolean predicate on the env-prefix sub-axis
// of the chain altitude, closing the "any-observed across
// altitudes" projection sideways from the file-format sub-axis
// to the third and final chain-altitude sub-axis. Routed through
// the shared `!AxisHistogram::is_empty` primitive one altitude
// down. ----
#[test]
fn env_prefix_kinds_any_observed_matches_env_prefix_kind_histogram_is_empty_negation_pointwise()
{
// The routing pin: `env_prefix_kinds_any_observed` routes
// through `!env_prefix_kind_histogram().is_empty()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-
// prefix sub-axis peer of
// `file_formats_any_observed_matches_file_format_histogram_is_empty_negation_pointwise`
// and
// `layer_kinds_any_observed_matches_layer_kind_histogram_is_empty_negation_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tiers_any_observed_matches_tier_histogram_is_empty_negation_pointwise`
// on the tier altitude, and
// `kinds_any_observed_matches_kind_histogram_is_empty_negation_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = !slice.env_prefix_kind_histogram().is_empty();
assert_eq!(slice.env_prefix_kinds_any_observed(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_any_observed_agrees_with_present_env_prefix_kinds_count_positive_pointwise()
{
// Support-scalar surface: `env_prefix_kinds_any_observed() ==
// (present_env_prefix_kinds_count() > 0)`, without allocating
// the `Vec<EnvMetadataTagKind>`. Peer of
// `file_formats_any_observed_agrees_with_present_file_formats_count_positive_pointwise`
// on the file-format sub-axis,
// `layer_kinds_any_observed_agrees_with_present_layer_kinds_count_positive_pointwise`
// on the layer-kind sub-axis, and
// `tiers_any_observed_agrees_with_contributing_tiers_count_positive_pointwise`
// on the tier altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_any_observed();
let via_scalar = slice.present_env_prefix_kinds_count() > 0;
assert_eq!(
via_seam,
via_scalar,
"env_prefix_kinds_any_observed ({via_seam}) must agree with \
present_env_prefix_kinds_count > 0 (count={c}) for chain",
c = slice.present_env_prefix_kinds_count(),
);
}
}
#[test]
fn env_prefix_kinds_any_observed_agrees_with_present_env_prefix_kinds_nonempty_pointwise() {
// Support-`Vec` surface: `env_prefix_kinds_any_observed() ==
// !present_env_prefix_kinds().is_empty()`. Pins the predicate
// against the `Vec<EnvMetadataTagKind>` non-empty form
// consumers reach for when they already hold the support
// vector. Peer of
// `file_formats_any_observed_agrees_with_present_file_formats_nonempty_pointwise`
// on the file-format sub-axis and
// `layer_kinds_any_observed_agrees_with_present_layer_kinds_nonempty_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_any_observed();
let via_vec = !slice.present_env_prefix_kinds().is_empty();
assert_eq!(
via_seam, via_vec,
"env_prefix_kinds_any_observed ({via_seam}) must agree with \
!present_env_prefix_kinds().is_empty() ({via_vec}) for chain",
);
}
}
#[test]
fn env_prefix_kinds_any_observed_agrees_with_absent_env_prefix_kinds_count_below_axis_cardinality_pointwise()
{
// Coverage-gap-scalar surface: `env_prefix_kinds_any_observed()
// == (absent_env_prefix_kinds_count() <
// crate::axis_cardinality::<EnvMetadataTagKind>())`. The dual-
// side surfacing of the same boolean across the (observed,
// unobserved) partition. Peer of
// `file_formats_any_observed_agrees_with_absent_file_formats_count_below_axis_cardinality_pointwise`
// on the file-format sub-axis and
// `layer_kinds_any_observed_agrees_with_absent_layer_kinds_count_below_axis_cardinality_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_any_observed();
let via_gap = slice.absent_env_prefix_kinds_count()
< crate::axis_cardinality::<EnvMetadataTagKind>();
assert_eq!(
via_seam, via_gap,
"env_prefix_kinds_any_observed ({via_seam}) must agree with \
absent_env_prefix_kinds_count < axis_cardinality ({via_gap}) for chain",
);
}
}
#[test]
fn env_prefix_kinds_any_observed_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has no observed cells,
// so the "any observed" predicate fails —
// `env_prefix_kinds_any_observed` reads `false`. Matches
// `is_empty` reading `true` on the empty histogram over the
// `EnvMetadataTagKind` axis one altitude down. Dual of
// `env_prefix_kinds_balanced_empty_chain_is_true`: the empty
// chain is on the opposite side of the any-observed boundary
// from the balanced boundary and on the same side as the full-
// cover boundary — the (`any_observed`=false, `balanced`=true,
// `full_cover`=false) polarity triple. Peer of
// `file_formats_any_observed_empty_chain_is_false` and
// `layer_kinds_any_observed_empty_chain_is_false` on the sister
// sub-axes of the same chain altitude,
// `tiers_any_observed_empty_map_is_false` on the tier altitude,
// and `kinds_any_observed_empty_diff_is_false` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_any_observed());
assert!(empty.env_prefix_kinds_balanced());
assert!(!empty.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_any_observed_no_env_layers_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_any_observed_empty_chain_is_false`: on the env-
// prefix sub-axis the *non-empty-chain / empty-histogram*
// boundary ALSO reads `false`. A chain of only Defaults / File
// layers is non-empty but has an empty env-prefix histogram, so
// no observed cell fires — `env_prefix_kinds_any_observed`
// reads `false`. Distinguishing pin against
// `env_prefix_kinds_balanced` on the exact same fixtures
// (where the vacuous-uniformity boundary reads `true`): any-
// observed and balanced fall on opposite sides of the empty-
// histogram boundary at the env-prefix sub-axis. Also matches
// `env_prefix_kinds_full_cover_no_env_layers_is_false` on the
// same-shape fixtures (both any-observed and full-cover read
// `false` on empty-histogram non-empty chains). Unlike the
// file-format sub-axis, the empty-histogram / non-empty-chain
// condition is exactly `layer_kind_histogram().count(Env) == 0`
// — every Env layer projects to a Some cell regardless of
// prefix value.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert_eq!(
slice.layer_kind_histogram().count(ConfigSourceKind::Env),
0,
"fixture must have zero Env layers",
);
assert!(!slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
}
#[test]
fn env_prefix_kinds_any_observed_prefixed_only_is_true() {
// Singleton-support pin on the prefixed side: every env layer
// carries a non-empty prefix, so `Prefixed` is the sole observed
// cell out of two — one observed cell suffices for the any-
// observed predicate, so `env_prefix_kinds_any_observed` reads
// `true`. Peer of `env_prefix_kinds_balanced_singleton_support_is_true`
// on the same side of the boundary and orthogonal to
// `env_prefix_kinds_full_cover_prefixed_only_is_false` on the
// opposite side: prefixed-only support is trivially observed
// and trivially balanced but never full-cover on the two-cell
// env-prefix axis. Peer of
// `file_formats_any_observed_singleton_support_is_true` and
// `layer_kinds_any_observed_singleton_support_is_true` on the
// sister sub-axes — same (`any_observed`=true, `balanced`=true,
// `full_cover`=false) polarity triple on the singleton-support
// fixture.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_any_observed_bare_only_is_true() {
// Singleton-support pin on the bare side: every env layer
// carries the empty prefix, so `Bare` is the sole observed
// cell — `env_prefix_kinds_any_observed` reads `true`. Symmetric
// sister of `env_prefix_kinds_any_observed_prefixed_only_is_true`
// on the two-cell env-prefix axis: both singletons sit on the
// (`any_observed`=true, `balanced`=true, `full_cover`=false)
// polarity triple. Peer of
// `env_prefix_kinds_full_cover_bare_only_is_false` on the
// opposite side of the full-cover boundary.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_any_observed_uniform_cover_is_true() {
// Uniform-cover pin: one Prefixed env + one Bare env layer, so
// every cell of `EnvMetadataTagKind::ALL` receives at least one
// observation — `env_prefix_kinds_any_observed` reads `true`.
// Peer of `env_prefix_kinds_balanced_uniform_cover_is_true` and
// `env_prefix_kinds_full_cover_uniform_cover_is_true`: the
// uniform two-kind cover is on the `true` side of ALL THREE
// coverage-support boundaries at this sub-axis. Peer of
// `file_formats_any_observed_uniform_cover_is_true` and
// `layer_kinds_any_observed_uniform_cover_is_true` on the
// sister sub-axes.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_any_observed_skewed_two_cell_fixture_is_true() {
// Skewed two-cell cover pin: a chain observing Prefixed twice
// and Bare once still fires at least one observed cell —
// `env_prefix_kinds_any_observed` reads `true`. Direct witness
// of `env_prefix_kinds_full_cover ⇒ env_prefix_kinds_any_observed`
// on a fixture where full-cover reads `true` (both cells
// observed) but balanced reads `false` (peak ≠ trough). Peer
// of `env_prefix_kinds_full_cover_skewed_two_cell_fixture_is_true`
// on the same side of full-cover and orthogonal to
// `env_prefix_kinds_balanced_bare_majority_is_false` on the
// balanced boundary — the (`any_observed`=true, `balanced`=false,
// `full_cover`=true) polarity triple that only lifts to the
// two-cell axis (imbalance forces full-cover, and full-cover
// forces any-observed).
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 2);
assert!(slice.env_prefix_kinds_any_observed());
assert!(!slice.env_prefix_kinds_balanced());
assert!(slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_full_cover_implies_env_prefix_kinds_any_observed_pointwise() {
// Subsumption pin: `env_prefix_kinds_full_cover() ⇒
// env_prefix_kinds_any_observed()` on every fixture — a full-
// cover chain observes every cell, so it observes at least one
// cell. Peer of
// `file_formats_full_cover_implies_file_formats_any_observed_pointwise`
// on the file-format sub-axis,
// `layer_kinds_full_cover_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis,
// `tiers_full_cover_implies_tiers_any_observed_pointwise` on
// the tier altitude, and
// `kinds_full_cover_implies_kinds_any_observed_pointwise` on
// the diff altitude. Names the ordering `full_cover ≤
// any_observed` on the coverage-support partition at the env-
// prefix sub-axis, closing the subsumption implication across
// every altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_full_cover() {
assert!(
slice.env_prefix_kinds_any_observed(),
"full-cover chain must be any-observed (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn env_prefix_kinds_any_observed_implies_layer_kind_env_count_positive_pointwise() {
// Cross-sub-axis lower-bound implication:
// `env_prefix_kinds_any_observed() ⇒
// layer_kind_histogram().count(ConfigSourceKind::Env) >= 1`. A
// chain observing any env-prefix kind has at least one env
// layer, and every such layer is a `ConfigSource::Env`. Sister
// of `file_formats_any_observed_implies_layer_kind_file_count_positive_pointwise`
// on the file-format sub-axis (same shape, Env cell instead of
// File cell). Cross-sub-axis divergence from
// `layer_kinds_any_observed_implies_chain_length_positive_pointwise`
// on the layer-kind sub-axis, which reads on the chain-length
// rather than the Env-layer count — the env-prefix sub-axis
// carries the stronger implication because Defaults / File
// layers don't contribute to the env-prefix histogram.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_any_observed() {
assert!(
slice.layer_kind_histogram().count(ConfigSourceKind::Env) >= 1,
"any-observed chain must have >= 1 Env layer (was {})",
slice.layer_kind_histogram().count(ConfigSourceKind::Env),
);
}
}
}
#[test]
fn env_prefix_kinds_any_observed_negation_implies_env_prefix_kinds_balanced_pointwise() {
// Empty-histogram / vacuous-balanced interaction pin: the
// empty-histogram chain is the only chain on the `false` side
// of `env_prefix_kinds_any_observed`, and it is vacuously
// balanced. So `!env_prefix_kinds_any_observed() ⇒
// env_prefix_kinds_balanced()` holds pointwise. Peer of
// `file_formats_any_observed_negation_implies_file_formats_balanced_pointwise`
// on the file-format sub-axis,
// `layer_kinds_any_observed_negation_implies_layer_kinds_balanced_pointwise`
// on the layer-kind sub-axis, and
// `tiers_any_observed_negation_implies_tiers_balanced_pointwise`
// on the tier altitude. Cross-sub-axis divergence from the
// layer-kind sub-axis: on the env-prefix sub-axis the `false`
// side of `any_observed` includes both the empty chain and
// every non-empty chain of only Defaults / File layers.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if !slice.env_prefix_kinds_any_observed() {
assert!(
slice.env_prefix_kinds_balanced(),
"non-any-observed chain must be vacuously balanced",
);
}
}
}
#[test]
fn env_prefix_kinds_any_observed_negation_implies_env_prefix_kinds_full_cover_false_pointwise()
{
// Empty-histogram / no-full-cover interaction pin: the empty-
// histogram chain has every cell in the coverage gap, so full-
// cover fails. Contrapositive of the subsumption pin
// `env_prefix_kinds_full_cover ⇒ env_prefix_kinds_any_observed`
// above — the two boundaries agree on their `false` side over
// the empty-histogram chain. Unique to the two-cell env-prefix
// axis boundary, where the `false` side of `any_observed` is
// exactly the empty-histogram set and every non-empty-
// histogram chain reads `true` on `any_observed` via the
// two-cell-axis `balanced || full_cover` tightening one
// boundary over.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if !slice.env_prefix_kinds_any_observed() {
assert!(
!slice.env_prefix_kinds_full_cover(),
"non-any-observed chain must not be full-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_any_observed_iff_env_prefix_kind_histogram_nonempty_pointwise() {
// Two-cell-axis unique boundary pin: on every chain,
// `env_prefix_kinds_any_observed() ==
// !env_prefix_kind_histogram().is_empty()` — the `true` side
// of `any_observed` is exactly the non-empty-histogram set
// and the `false` side is exactly the empty-histogram set,
// regardless of `balanced` / `full_cover` polarity. This
// biconditional is the routing pin lifted to the whole-
// fixture-set boundary predicate: on every fixture the
// any-observed seam agrees with the histogram-non-empty
// predicate directly, so no non-empty-histogram chain sneaks
// onto the `false` side of `any_observed` and no empty-
// histogram chain sneaks onto the `true` side. Combined with
// the two-cell-axis `balanced || full_cover` tightening (see
// `env_prefix_kinds_full_cover_balanced_or_full_cover_covers_every_chain`),
// this closes the two-cell-axis polarity space at four
// reachable triples out of eight: (F,T,F) empty-histogram,
// (T,T,F) singleton-support, (T,F,T) skewed-two-cell, and
// (T,T,T) uniform-cover.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_any_observed();
let via_nonempty = !slice.env_prefix_kind_histogram().is_empty();
assert_eq!(
via_seam, via_nonempty,
"any_observed ({via_seam}) must agree with histogram-nonempty ({via_nonempty})",
);
}
}
#[test]
fn env_prefix_kinds_any_observed_agrees_with_open_coded_any_positive_walk() {
// Parity against the exact hand-rolled any-observed walk this
// lift replaces: walk every cell of the histogram and check
// any count is positive. Mirrors the parity pins
// `file_formats_any_observed_agrees_with_open_coded_any_positive_walk`
// and
// `layer_kinds_any_observed_agrees_with_open_coded_any_positive_walk`
// on the sister sub-axes,
// `tiers_any_observed_agrees_with_open_coded_any_positive_walk`
// on the tier altitude, and
// `kinds_any_observed_agrees_with_open_coded_any_positive_walk`
// on the diff altitude. Note the walk uses `hist.iter()` which
// iterates over the closed axis's ALL cells in declaration
// order — an any-observed chain has at least one cell nonzero
// regardless of order.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_any_observed();
let hist = slice.env_prefix_kind_histogram();
let hand_rolled = hist.iter().any(|(_, c)| c > 0);
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_singular_support —
// singleton-support-env-prefix-kinds boolean predicate on the
// env-prefix sub-axis of the chain altitude, lifting
// has_singular_support from the histogram surface and closing
// the "singleton-support across altitudes" projection sideways
// to the third and final chain-altitude sub-axis — the last
// remaining corner of the 4-boundary × 5-altitude/sub-axis
// coverage-support predicate cube ----
#[test]
fn env_prefix_kinds_singular_support_matches_env_prefix_kind_histogram_has_singular_support_pointwise()
{
// Routing pin: `env_prefix_kinds_singular_support` routes
// through `env_prefix_kind_histogram().has_singular_support()`,
// so the two seams must stay pointwise equivalent under every
// fixture. Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive.
// Env-prefix sub-axis peer of
// `file_formats_singular_support_matches_file_format_histogram_has_singular_support_pointwise`
// and
// `layer_kinds_singular_support_matches_layer_kind_histogram_has_singular_support_pointwise`
// on the sister sub-axes of the chain altitude,
// `tiers_singular_support_matches_tier_histogram_has_singular_support_pointwise`
// on the tier altitude, and
// `kinds_singular_support_matches_kind_histogram_has_singular_support_pointwise`
// on the diff altitude — closing the "singleton-support across
// altitudes" projection across every altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().has_singular_support();
assert_eq!(slice.env_prefix_kinds_singular_support(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_singular_support_agrees_with_present_env_prefix_kinds_count_equals_one_pointwise()
{
// Support-scalar surface: `env_prefix_kinds_singular_support()
// == (present_env_prefix_kinds_count() == 1)` on every fixture
// — the same boolean without allocating the
// `Vec<EnvMetadataTagKind>`. Peer of
// `file_formats_singular_support_agrees_with_present_file_formats_count_equals_one_pointwise`
// and
// `layer_kinds_singular_support_agrees_with_present_layer_kinds_count_equals_one_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular_support();
let via_support = slice.present_env_prefix_kinds_count() == 1;
assert_eq!(
via_seam, via_support,
"env_prefix_kinds_singular_support ({via_seam}) must agree with \
present_env_prefix_kinds_count == 1 ({via_support}) for chain",
);
}
}
#[test]
fn env_prefix_kinds_singular_support_agrees_with_present_env_prefix_kinds_len_equals_one_pointwise()
{
// Support-`Vec` surface: `env_prefix_kinds_singular_support() ==
// (present_env_prefix_kinds().len() == 1)` on every fixture —
// the same boolean via the allocating support form the seam
// replaces. Peer of
// `file_formats_singular_support_agrees_with_present_file_formats_len_equals_one_pointwise`
// and
// `layer_kinds_singular_support_agrees_with_present_layer_kinds_len_equals_one_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular_support();
let via_len = slice.present_env_prefix_kinds().len() == 1;
assert_eq!(
via_seam, via_len,
"env_prefix_kinds_singular_support ({via_seam}) must agree with \
present_env_prefix_kinds().len() == 1 ({via_len}) for chain",
);
}
}
#[test]
fn env_prefix_kinds_singular_support_agrees_with_absent_env_prefix_kinds_count_equals_axis_cardinality_minus_one_pointwise()
{
// Coverage-gap-scalar surface:
// `env_prefix_kinds_singular_support() ==
// (absent_env_prefix_kinds_count() ==
// axis_cardinality::<EnvMetadataTagKind>() - 1)` on every
// fixture — the dual-side surfacing of the same boolean across
// the (observed, unobserved) partition. Peer of
// `file_formats_singular_support_agrees_with_absent_file_formats_count_equals_axis_cardinality_minus_one_pointwise`
// and
// `layer_kinds_singular_support_agrees_with_absent_layer_kinds_count_equals_axis_cardinality_minus_one_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular_support();
let via_gap = slice.absent_env_prefix_kinds_count()
== crate::axis_cardinality::<EnvMetadataTagKind>() - 1;
assert_eq!(
via_seam, via_gap,
"env_prefix_kinds_singular_support ({via_seam}) must agree with \
absent_env_prefix_kinds_count == axis_cardinality - 1 ({via_gap}) for chain",
);
}
}
#[test]
fn env_prefix_kinds_singular_support_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has no observed cells,
// so the singular-support predicate fails —
// `env_prefix_kinds_singular_support` reads `false`. Matches
// `has_singular_support` reading `false` on the empty histogram
// over the `EnvMetadataTagKind` axis one altitude down. Empty-
// chain polarity quadruple: (`any_observed`=false,
// `singular_support`=false, `balanced`=true, `full_cover`=false).
// Peer of `file_formats_singular_support_empty_chain_is_false`
// and `layer_kinds_singular_support_empty_chain_is_false` on the
// sister sub-axes of the same chain altitude,
// `tiers_singular_support_empty_map_is_false` on the tier
// altitude, and `kinds_singular_support_empty_diff_is_false` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_singular_support());
assert!(!empty.env_prefix_kinds_any_observed());
assert!(empty.env_prefix_kinds_balanced());
assert!(!empty.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_support_no_env_layers_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_singular_support_empty_chain_is_false`: on the
// env-prefix sub-axis the *non-empty-chain / empty-histogram*
// boundary ALSO reads `false`. A chain of only Defaults / File
// layers is non-empty but has an empty env-prefix histogram, so
// no observed cell fires — `env_prefix_kinds_singular_support`
// reads `false`. Matches
// `env_prefix_kinds_any_observed_no_env_layers_is_false` and
// `env_prefix_kinds_full_cover_no_env_layers_is_false` on the
// same-shape fixtures (both any-observed and full-cover read
// `false` on empty-histogram non-empty chains); distinguishing
// pin against `env_prefix_kinds_balanced` on the exact same
// fixtures (where the vacuous-uniformity boundary reads `true`).
// Unlike the file-format sub-axis, the empty-histogram / non-
// empty-chain condition is exactly
// `layer_kind_histogram().count(Env) == 0` — every Env layer
// projects to a Some cell regardless of prefix value.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert_eq!(
slice.layer_kind_histogram().count(ConfigSourceKind::Env),
0,
"fixture must have zero Env layers",
);
assert!(!slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
}
#[test]
fn env_prefix_kinds_singular_support_prefixed_only_is_true() {
// Singleton-support pin on the prefixed side: every env layer
// carries a non-empty prefix, so `Prefixed` is the sole
// observed cell out of two — exactly one observed cell, so
// `env_prefix_kinds_singular_support` reads `true`. Peer of
// `env_prefix_kinds_any_observed_prefixed_only_is_true` and
// `env_prefix_kinds_balanced_singleton_support_is_true` on the
// same side of their boundaries and orthogonal to
// `env_prefix_kinds_full_cover_prefixed_only_is_false` on the
// opposite side: prefixed-only support is trivially singular
// and trivially balanced but never full-cover on the two-cell
// env-prefix axis. Peer of
// `file_formats_singular_support_singleton_support_is_true` and
// `layer_kinds_singular_support_singleton_support_is_true` on
// the sister sub-axes — same (`any_observed`=true,
// `singular_support`=true, `balanced`=true, `full_cover`=false)
// polarity quadruple on the singleton-support fixture.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_support_bare_only_is_true() {
// Singleton-support pin on the bare side: every env layer
// carries the empty prefix, so `Bare` is the sole observed
// cell — `env_prefix_kinds_singular_support` reads `true`.
// Symmetric sister of
// `env_prefix_kinds_singular_support_prefixed_only_is_true` on
// the two-cell env-prefix axis: both singletons sit on the
// (`any_observed`=true, `singular_support`=true, `balanced`=true,
// `full_cover`=false) polarity quadruple. Peer of
// `env_prefix_kinds_any_observed_bare_only_is_true` and
// `env_prefix_kinds_full_cover_bare_only_is_false` on the
// sister boundaries.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_support_sample_chain_is_true() {
// Direct pin against `sample_chain()`: two `.yaml` file layers
// + one prefixed env layer (`"APP_"`). `Prefixed` is the sole
// observed env-prefix cell (Bare has count 0) — the env-prefix
// sub-axis reads support cardinality 1, so
// `env_prefix_kinds_singular_support` reads `true`. Peer of
// `file_formats_singular_support_sample_chain_is_true` on the
// file-format sub-axis (Yaml the sole observed file-format
// cell); cross-sub-axis divergence from
// `layer_kinds_singular_support` on the same fixture, where
// support is 2 (File + Env) — the sample chain sits on the
// singular-support boundary on both projection-limited sub-axes
// and off it on the total layer-kind sub-axis.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_support_uniform_cover_is_false() {
// Uniform-cover pin: one Prefixed env + one Bare env layer, so
// both cells of `EnvMetadataTagKind::ALL` receive equal counts
// — support cardinality is 2, so
// `env_prefix_kinds_singular_support` reads `false` (two, not
// one). Peer of
// `env_prefix_kinds_any_observed_uniform_cover_is_true`,
// `env_prefix_kinds_balanced_uniform_cover_is_true`, and
// `env_prefix_kinds_full_cover_uniform_cover_is_true`: the
// uniform two-kind cover is on the `false` side of ONLY the
// singular-support boundary at this sub-axis. Peer of
// `file_formats_singular_support_uniform_cover_is_false` and
// `layer_kinds_singular_support_uniform_cover_is_false` on the
// sister sub-axes.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 2);
assert!(!slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_support_skewed_two_cell_fixture_is_false() {
// Skewed two-cell cover pin: a chain observing Prefixed twice
// and Bare once — both cells nonzero (support cardinality 2),
// so `env_prefix_kinds_singular_support` reads `false`. Direct
// witness of the two-cell-axis boundary tightening
// `singular_support ⇔ any_observed ∧ !full_cover` from the
// false side: this fixture reads `full_cover`=true, so
// singular-support must read false. Peer of
// `env_prefix_kinds_any_observed_skewed_two_cell_fixture_is_true`
// on the same fixture where any-observed reads `true` but
// singular-support reads `false` — the (`any_observed`=true,
// `singular_support`=false, `balanced`=false, `full_cover`=true)
// polarity quadruple that only lifts to the two-cell axis
// (imbalance forces full-cover on 2 cells, and full-cover
// forces !singular-support). Peer of
// `file_formats_singular_support_two_format_partial_cover_is_false`
// and `layer_kinds_singular_support_two_kind_partial_cover_is_false`
// on the sister sub-axes (same "support cardinality 2"
// fixture-shape); cross-sub-axis divergence from those two —
// where a two-cell partial cover reads `full_cover`=false (the
// support is a strict subset of the axis) — because on the
// two-cell axis every two-cell support IS a full cover.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 2);
assert!(!slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_any_observed());
assert!(!slice.env_prefix_kinds_balanced());
assert!(slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_support_implies_env_prefix_kinds_any_observed_pointwise() {
// Subsumption pin: `env_prefix_kinds_singular_support() ⇒
// env_prefix_kinds_any_observed()` on every fixture — exactly
// one observed cell has at least one observed cell. Peer of
// `file_formats_singular_support_implies_file_formats_any_observed_pointwise`
// and
// `layer_kinds_singular_support_implies_layer_kinds_any_observed_pointwise`
// on the sister sub-axes,
// `tiers_singular_support_implies_tiers_any_observed_pointwise`
// on the tier altitude, and
// `kinds_singular_support_implies_kinds_any_observed_pointwise`
// on the diff altitude. Names the ordering `singular_support ≤
// any_observed` on the coverage-support partition at the env-
// prefix sub-axis, closing the subsumption implication across
// every altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_support() {
assert!(
slice.env_prefix_kinds_any_observed(),
"singular-support chain must be any-observed (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn env_prefix_kinds_singular_support_implies_env_prefix_kinds_balanced_pointwise() {
// Subsumption pin: `env_prefix_kinds_singular_support() ⇒
// env_prefix_kinds_balanced()` on every fixture — a chain with
// exactly one observed count has a trivially uniform support
// (one count is vacuously equal to itself). Peer of
// `file_formats_singular_support_implies_file_formats_balanced_pointwise`
// and
// `layer_kinds_singular_support_implies_layer_kinds_balanced_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_support() {
assert!(
slice.env_prefix_kinds_balanced(),
"singular-support chain must be vacuously balanced (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn env_prefix_kinds_singular_support_implies_not_env_prefix_kinds_full_cover_pointwise() {
// Disjointness pin: `env_prefix_kinds_singular_support() ⇒
// !env_prefix_kinds_full_cover()` on every fixture — cardinality
// 1 vs cardinality 2 disjoint on `EnvMetadataTagKind`. Peer of
// `file_formats_singular_support_implies_not_file_formats_full_cover_pointwise`
// (four-cell) and
// `layer_kinds_singular_support_implies_not_layer_kinds_full_cover_pointwise`
// (three-cell) on the sister sub-axes — the same disjointness
// reads on every axis with cardinality `>= 2`.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_support() {
assert!(
!slice.env_prefix_kinds_full_cover(),
"singular-support chain must not be full-cover (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn env_prefix_kinds_singular_support_implies_layer_kind_env_count_positive_pointwise() {
// Cross-sub-axis lower-bound implication:
// `env_prefix_kinds_singular_support() ⇒
// layer_kind_histogram().count(ConfigSourceKind::Env) >= 1`. A
// chain with a singleton env-prefix support has at least one
// env layer, and every such layer is a `ConfigSource::Env`.
// Sister of
// `file_formats_singular_support_implies_layer_kind_file_count_positive_pointwise`
// on the file-format sub-axis (same shape, Env cell instead of
// File cell). Cross-sub-axis divergence from
// `layer_kinds_singular_support_implies_chain_length_positive_pointwise`
// on the layer-kind sub-axis, which reads on the chain-length
// rather than the Env-layer count — the env-prefix sub-axis
// carries the stronger implication because Defaults / File
// layers don't contribute to the env-prefix histogram.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_support() {
assert!(
slice.layer_kind_histogram().count(ConfigSourceKind::Env) >= 1,
"singular-support chain must have >= 1 Env layer (was {})",
slice.layer_kind_histogram().count(ConfigSourceKind::Env),
);
}
}
}
#[test]
fn env_prefix_kinds_singular_support_implies_dominant_equals_recessive_pointwise() {
// Modal-collapse pin: `env_prefix_kinds_singular_support() ⇒
// dominant_env_prefix_kind() == recessive_env_prefix_kind() &&
// dominant_env_prefix_kind().is_some()` on every fixture — when
// support is singular, the modal pair collapses to the one
// observed cell on both sides. Peer of
// `file_formats_singular_support_implies_dominant_equals_recessive_pointwise`
// and
// `layer_kinds_singular_support_implies_dominant_equals_recessive_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_support() {
let dom = slice.dominant_env_prefix_kind();
let rec = slice.recessive_env_prefix_kind();
assert!(
dom.is_some(),
"singular-support chain must have a dominant cell",
);
assert_eq!(
dom, rec,
"singular-support chain must have dominant == recessive (dom={dom:?}, rec={rec:?})",
);
}
}
}
#[test]
fn env_prefix_kinds_any_observed_negation_implies_not_env_prefix_kinds_singular_support_pointwise()
{
// Contrapositive of `singular_support ⇒ any_observed`: if no
// cell was observed, the singular-support predicate fails.
// Peer of
// `file_formats_any_observed_negation_implies_not_file_formats_singular_support_pointwise`
// and
// `layer_kinds_any_observed_negation_implies_not_layer_kinds_singular_support_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if !slice.env_prefix_kinds_any_observed() {
assert!(
!slice.env_prefix_kinds_singular_support(),
"non-any-observed chain must not be singular-support (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn env_prefix_kinds_singular_support_agrees_with_open_coded_exactly_one_positive_walk() {
// Parity against the exact hand-rolled singular-support walk
// this lift replaces: walk every cell of the histogram and
// count how many carry a positive count; the singleton-
// support predicate reads `true` iff exactly one cell is
// positive. Mirrors the parity pins
// `file_formats_singular_support_agrees_with_open_coded_exactly_one_positive_walk`
// and
// `layer_kinds_singular_support_agrees_with_open_coded_exactly_one_positive_walk`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular_support();
let hist = slice.env_prefix_kind_histogram();
let hand_rolled = hist.iter().filter(|(_, c)| *c > 0).count() == 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_singular_gap — singleton-
// gap-env-prefix-kinds boolean predicate on the env-prefix sub-
// axis of the chain altitude, closing the "singleton-gap across
// altitudes" projection sideways to the third and final chain-
// altitude sub-axis — the last remaining corner of the 5-boundary
// × 5-altitude/sub-axis coverage-support predicate cube ----
#[test]
fn env_prefix_kinds_singular_gap_matches_env_prefix_kind_histogram_has_singular_gap_pointwise()
{
// Routing pin: `env_prefix_kinds_singular_gap` routes through
// `env_prefix_kind_histogram().has_singular_gap()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-
// prefix sub-axis peer of
// `file_formats_singular_gap_matches_file_format_histogram_has_singular_gap_pointwise`
// and
// `layer_kinds_singular_gap_matches_layer_kind_histogram_has_singular_gap_pointwise`
// on the sister sub-axes of the chain altitude,
// `tiers_singular_gap_matches_tier_histogram_has_singular_gap_pointwise`
// on the tier altitude, and
// `kinds_singular_gap_matches_kind_histogram_has_singular_gap_pointwise`
// on the diff altitude — closing the "singleton-gap across
// altitudes" projection across every altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().has_singular_gap();
assert_eq!(slice.env_prefix_kinds_singular_gap(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_singular_gap_agrees_with_absent_env_prefix_kinds_count_equals_one_pointwise()
{
// Coverage-gap-scalar surface: `env_prefix_kinds_singular_gap()
// == (absent_env_prefix_kinds_count() == 1)` on every fixture
// — the coverage-gap-side scalar surfacing of the same boolean,
// without allocating the `Vec<EnvMetadataTagKind>`. Peer of
// `file_formats_singular_gap_agrees_with_absent_file_formats_count_equals_one_pointwise`
// and
// `layer_kinds_singular_gap_agrees_with_absent_layer_kinds_count_equals_one_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular_gap();
let via_gap_scalar = slice.absent_env_prefix_kinds_count() == 1;
assert_eq!(
via_seam,
via_gap_scalar,
"env_prefix_kinds_singular_gap ({via_seam}) must agree with \
absent_env_prefix_kinds_count == 1 (gap={g}) for chain",
g = slice.absent_env_prefix_kinds_count(),
);
}
}
#[test]
fn env_prefix_kinds_singular_gap_agrees_with_absent_env_prefix_kinds_len_equals_one_pointwise()
{
// Coverage-gap-`Vec` form: `env_prefix_kinds_singular_gap() ==
// (absent_env_prefix_kinds().len() == 1)` on every fixture —
// the allocating coverage-gap-vec form the seam replaces. Peer
// of `file_formats_singular_gap_agrees_with_absent_file_formats_len_equals_one_pointwise`
// and `layer_kinds_singular_gap_agrees_with_absent_layer_kinds_len_equals_one_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular_gap();
let via_vec = slice.absent_env_prefix_kinds().len() == 1;
assert_eq!(
via_seam, via_vec,
"env_prefix_kinds_singular_gap ({via_seam}) must agree with \
absent_env_prefix_kinds().len() == 1 ({via_vec}) for chain",
);
}
}
#[test]
fn env_prefix_kinds_singular_gap_agrees_with_present_env_prefix_kinds_count_equals_axis_cardinality_minus_one_pointwise()
{
// Support-scalar surface: `env_prefix_kinds_singular_gap() ==
// (present_env_prefix_kinds_count() ==
// axis_cardinality::<EnvMetadataTagKind>() - 1)` on every
// fixture — the support-side surfacing of the same boolean
// across the (observed, unobserved) partition. Peer of
// `file_formats_singular_gap_agrees_with_present_file_formats_count_equals_axis_cardinality_minus_one_pointwise`
// and
// `layer_kinds_singular_gap_agrees_with_present_layer_kinds_count_equals_axis_cardinality_minus_one_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular_gap();
let via_support_scalar = slice.present_env_prefix_kinds_count()
== crate::axis_cardinality::<EnvMetadataTagKind>() - 1;
assert_eq!(
via_seam,
via_support_scalar,
"env_prefix_kinds_singular_gap ({via_seam}) must agree with \
present_env_prefix_kinds_count == axis_cardinality - 1 (count={c}) for chain",
c = slice.present_env_prefix_kinds_count(),
);
}
}
#[test]
fn env_prefix_kinds_singular_gap_agrees_with_present_env_prefix_kinds_len_equals_axis_cardinality_minus_one_pointwise()
{
// Support-`Vec` form: `env_prefix_kinds_singular_gap() ==
// (present_env_prefix_kinds().len() ==
// axis_cardinality::<EnvMetadataTagKind>() - 1)` on every
// fixture — the allocating support-vec form the seam replaces.
// Peer of `file_formats_singular_gap_agrees_with_present_file_formats_len_equals_axis_cardinality_minus_one_pointwise`
// and `layer_kinds_singular_gap_agrees_with_present_layer_kinds_len_equals_axis_cardinality_minus_one_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular_gap();
let via_support_vec = slice.present_env_prefix_kinds().len()
== crate::axis_cardinality::<EnvMetadataTagKind>() - 1;
assert_eq!(
via_seam, via_support_vec,
"env_prefix_kinds_singular_gap ({via_seam}) must agree with \
present_env_prefix_kinds().len() == axis_cardinality - 1 ({via_support_vec}) for chain",
);
}
}
#[test]
fn env_prefix_kinds_singular_gap_empty_chain_is_false() {
// Empty-chain boundary: the empty chain has every cell
// unobserved (both, not one), so the singular-gap predicate
// reads `false`. Matches `has_singular_gap` reading `false` on
// the empty histogram over the `EnvMetadataTagKind` axis one
// altitude down. Empty-chain polarity quintuple:
// (`any_observed`=false, `singular_support`=false,
// `singular_gap`=false, `balanced`=true, `full_cover`=false).
// Peer of `file_formats_singular_gap_empty_chain_is_false` and
// `layer_kinds_singular_gap_empty_chain_is_false` on the
// sister sub-axes of the same chain altitude,
// `tiers_singular_gap_empty_map_is_false` on the tier altitude,
// and `kinds_singular_gap_empty_diff_is_false` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_singular_gap());
assert!(!empty.env_prefix_kinds_singular_support());
assert!(!empty.env_prefix_kinds_any_observed());
assert!(empty.env_prefix_kinds_balanced());
assert!(!empty.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_gap_no_env_layers_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_singular_gap_empty_chain_is_false`: on the env-
// prefix sub-axis the *non-empty-chain / empty-histogram*
// boundary ALSO reads `false`. A chain of only Defaults / File
// layers is non-empty but has an empty env-prefix histogram, so
// no cells are observed and every cell is unobserved (both,
// not one) — `env_prefix_kinds_singular_gap` reads `false`.
// Matches `env_prefix_kinds_singular_support_no_env_layers_is_false`,
// `env_prefix_kinds_any_observed_no_env_layers_is_false`, and
// `env_prefix_kinds_full_cover_no_env_layers_is_false` on the
// same-shape fixtures (all four read `false` on empty-histogram
// non-empty chains); distinguishing pin against
// `env_prefix_kinds_balanced` on the exact same fixtures
// (where the vacuous-uniformity boundary reads `true`).
// Unlike the file-format sub-axis, the empty-histogram / non-
// empty-chain condition is exactly
// `layer_kind_histogram().count(Env) == 0` — every Env layer
// projects to a Some cell regardless of prefix value.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert_eq!(
slice.layer_kind_histogram().count(ConfigSourceKind::Env),
0,
"fixture must have zero Env layers",
);
assert!(!slice.env_prefix_kinds_singular_gap());
assert!(!slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
}
#[test]
fn env_prefix_kinds_singular_gap_prefixed_only_is_true() {
// Singleton-gap pin on the prefixed side: every env layer
// carries a non-empty prefix, so `Prefixed` is the sole
// observed cell and `Bare` is the sole unobserved cell —
// exactly one cell missing on the two-cell axis, so
// `env_prefix_kinds_singular_gap` reads `true`. Direct witness
// of the two-cell-axis coincidence
// `env_prefix_kinds_singular_gap ⇔ env_prefix_kinds_singular_support`.
// Polarity quintuple on this fixture:
// (`any_observed`=true, `singular_support`=true,
// `singular_gap`=true, `balanced`=true, `full_cover`=false).
// Cross-sub-axis divergence from
// `file_formats_singular_gap_singleton_support_is_false` and
// `layer_kinds_singular_gap_singleton_support_is_false` on the
// sister sub-axes — where the same "one observed cell" shape
// reads singular-gap FALSE because those cardinality-≥3 axes
// isolate the two singular boundaries into strictly disjoint
// sides.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert_eq!(slice.absent_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_gap());
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_gap_bare_only_is_true() {
// Singleton-gap pin on the bare side: every env layer carries
// the empty prefix, so `Bare` is the sole observed cell and
// `Prefixed` is the sole unobserved cell — exactly one cell
// missing on the two-cell axis, so
// `env_prefix_kinds_singular_gap` reads `true`. Symmetric
// sister of `env_prefix_kinds_singular_gap_prefixed_only_is_true`
// on the two-cell env-prefix axis: both singletons sit on the
// (`any_observed`=true, `singular_support`=true,
// `singular_gap`=true, `balanced`=true, `full_cover`=false)
// polarity quintuple. Peer of
// `env_prefix_kinds_any_observed_bare_only_is_true` and
// `env_prefix_kinds_full_cover_bare_only_is_false` on the
// sister boundaries.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert_eq!(slice.absent_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_gap());
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_gap_sample_chain_is_true() {
// Direct pin against `sample_chain()`: two `.yaml` file layers
// + one prefixed env layer (`"APP_"`). `Prefixed` is the sole
// observed env-prefix cell, `Bare` the sole unobserved cell —
// exactly one cell missing on the two-cell axis, so
// `env_prefix_kinds_singular_gap` reads `true`. Peer of
// `env_prefix_kinds_singular_support_sample_chain_is_true` on
// the same fixture — the two-cell-axis coincidence collapses
// both named seams onto the same fixture reading. Cross-sub-
// axis divergence from
// `file_formats_singular_gap_singleton_support_is_false` on
// `sample_chain()`: on the four-cell file-format sub-axis
// `sample_chain` has support size 1 (Yaml the sole observed
// cell) and gap size 3, so file-format singular-gap reads
// `false`.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert_eq!(slice.absent_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_gap());
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_gap_uniform_cover_is_false() {
// Uniform-cover pin: one Prefixed env + one Bare env layer, so
// both cells of `EnvMetadataTagKind::ALL` are observed and
// zero cells are unobserved (not one) —
// `env_prefix_kinds_singular_gap` reads `false`. The uniform
// two-kind cover is on the `false` side of the singular-gap
// boundary and on the `true` side of `full_cover` — the two
// boundaries are disjoint at the top of the coverage-support
// partition (adjacent support cardinalities
// `axis_cardinality - 1` and `axis_cardinality`). Peer of
// `file_formats_singular_gap_uniform_cover_is_false` and
// `layer_kinds_singular_gap_uniform_cover_is_false` on the
// sister sub-axes.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 2);
assert_eq!(slice.absent_env_prefix_kinds().len(), 0);
assert!(!slice.env_prefix_kinds_singular_gap());
assert!(!slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(slice.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_singular_gap_iff_singular_support_pointwise() {
// Two-cell-axis coincidence pin: on the two-cell
// `EnvMetadataTagKind` axis, singleton-support (exactly one
// observed cell) and singleton-gap (exactly one unobserved
// cell) coincide pointwise because `axis_cardinality - 1 == 1`.
// This is the UNIQUE two-cell exception to the general
// strict disjointness `singular_gap ⇒ !singular_support` on
// cardinality-≥3 axes; every consumer relying on that
// disjointness on the layer-kind / file-format sub-axes must
// NOT rely on it here. Distinguishing pin against
// `file_formats_singular_gap_implies_not_file_formats_singular_support_pointwise`
// and
// `layer_kinds_singular_gap_implies_not_layer_kinds_singular_support_pointwise`
// on the sister sub-axes where the disjointness holds.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
assert_eq!(
slice.env_prefix_kinds_singular_gap(),
slice.env_prefix_kinds_singular_support(),
"two-cell-axis coincidence: singular_gap must equal singular_support \
on the env-prefix sub-axis (fixture len={})",
slice.len(),
);
}
}
#[test]
fn env_prefix_kinds_singular_gap_implies_env_prefix_kinds_any_observed_pointwise() {
// Subsumption pin: `env_prefix_kinds_singular_gap() ⇒
// env_prefix_kinds_any_observed()` on every fixture — a chain
// missing exactly one cell observes at least
// `axis_cardinality - 1 >= 1` cells (EnvMetadataTagKind carries
// two cells). Peer of
// `file_formats_singular_gap_implies_file_formats_any_observed_pointwise`
// and
// `layer_kinds_singular_gap_implies_layer_kinds_any_observed_pointwise`
// on the sister sub-axes,
// `tiers_singular_gap_implies_tiers_any_observed_pointwise` on
// the tier altitude, and
// `kinds_singular_gap_implies_kinds_any_observed_pointwise` on
// the diff altitude. Names the ordering `singular_gap ≤
// any_observed` on the coverage-support partition at the env-
// prefix sub-axis, closing the subsumption implication across
// every altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_gap() {
assert!(
slice.env_prefix_kinds_any_observed(),
"singular-gap chain must be any-observed (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn env_prefix_kinds_singular_gap_implies_not_env_prefix_kinds_full_cover_pointwise() {
// Disjointness pin: `env_prefix_kinds_singular_gap() ⇒
// !env_prefix_kinds_full_cover()` on every fixture — full
// cover has zero unobserved cells, singular gap has exactly
// one, so the two boundaries are disjoint on every axis. Peer
// of `file_formats_singular_gap_implies_not_file_formats_full_cover_pointwise`
// and `layer_kinds_singular_gap_implies_not_layer_kinds_full_cover_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_gap() {
assert!(
!slice.env_prefix_kinds_full_cover(),
"singular-gap chain cannot be full-cover (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn env_prefix_kinds_singular_gap_implies_layer_kind_env_count_positive_pointwise() {
// Cross-sub-axis lower-bound implication:
// `env_prefix_kinds_singular_gap() ⇒
// layer_kind_histogram().count(ConfigSourceKind::Env) >= 1`. A
// chain with a singleton env-prefix gap observes exactly one
// env-prefix cell (by the two-cell-axis coincidence) so has
// at least one env layer, and every such layer is a
// `ConfigSource::Env`. Sister of
// `env_prefix_kinds_singular_support_implies_layer_kind_env_count_positive_pointwise`
// on the complementary cardinality slice (same lower bound
// by the coincidence). Cross-sub-axis divergence from
// `layer_kinds_singular_gap_implies_chain_length_at_least_axis_cardinality_minus_one_pointwise`
// on the layer-kind sub-axis, which reads on the chain-length
// and on `axis_cardinality - 1` rather than the Env-layer
// count — the env-prefix sub-axis carries the two-cell-axis-
// tightened bound `>= 1` (not `>= axis_cardinality - 1`),
// matching the sister singular-support lower-bound on this
// sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_gap() {
assert!(
slice.layer_kind_histogram().count(ConfigSourceKind::Env) >= 1,
"singular-gap chain must have >= 1 Env layer (was {})",
slice.layer_kind_histogram().count(ConfigSourceKind::Env),
);
}
}
}
#[test]
fn env_prefix_kinds_any_observed_negation_implies_not_env_prefix_kinds_singular_gap_pointwise()
{
// Contrapositive of `singular_gap ⇒ any_observed`: if no cell
// was observed, the singular-gap predicate fails. Peer of
// `file_formats_any_observed_negation_implies_not_file_formats_singular_gap_pointwise`
// and `layer_kinds_any_observed_negation_implies_not_layer_kinds_singular_gap_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if !slice.env_prefix_kinds_any_observed() {
assert!(
!slice.env_prefix_kinds_singular_gap(),
"empty-support chain cannot be singular-gap on a \
cardinality >= 2 axis (fixture len={})",
slice.len(),
);
}
}
}
#[test]
fn env_prefix_kinds_singular_gap_agrees_with_open_coded_exactly_one_zero_walk() {
// Parity against the exact hand-rolled singular-gap walk this
// lift replaces: walk every cell of the histogram and count
// how many carry a zero count; the singleton-gap predicate
// reads `true` iff exactly one cell is zero. Mirrors the
// parity pin
// `file_formats_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the file-format sub-axis,
// `layer_kinds_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the layer-kind sub-axis,
// `tiers_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the tier altitude, and
// `kinds_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular_gap();
let hist = slice.env_prefix_kind_histogram();
let hand_rolled = hist.iter().filter(|(_, c)| *c == 0).count() == 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_strict_partial_cover —
// boundary-free middle-leg corner of the coverage-support
// partition on the env-prefix sub-axis of the chain altitude,
// closing the "strict-partial-cover across altitudes" projection
// at the sixth and final altitude / sub-axis and completing the
// 6×5 coverage-support predicate cube. `EnvMetadataTagKind`
// cardinality-`2` axis: the strict interior is vacuously `false`
// on every chain (strict interval `[2, 0]` is empty), matching
// the vacuously-`false` polarity at the two other cardinality-
// `<= 3` altitudes in the projection (diff / chain layer-kind);
// routes through `AxisHistogram::has_strict_partial_cover` one
// altitude down. ----
#[test]
fn env_prefix_kinds_strict_partial_cover_matches_env_prefix_kind_histogram_has_strict_partial_cover_pointwise()
{
// Routing pin: `env_prefix_kinds_strict_partial_cover` routes
// through `env_prefix_kind_histogram().has_strict_partial_cover()`,
// so the two seams must stay pointwise equivalent under every
// fixture. Catches any future drift where either implementation
// stops projecting through the shared cube-native primitive. Env-
// prefix sub-axis peer of
// `file_formats_strict_partial_cover_matches_file_format_histogram_has_strict_partial_cover_pointwise`
// on the file-format sub-axis,
// `layer_kinds_strict_partial_cover_matches_layer_kind_histogram_has_strict_partial_cover_pointwise`
// on the layer-kind sub-axis,
// `tiers_strict_partial_cover_matches_tier_histogram_has_strict_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_strict_partial_cover_matches_kind_histogram_has_strict_partial_cover_pointwise`
// on the diff altitude, closing the "strict-partial-cover across
// altitudes" projection at the sixth and final altitude / sub-
// axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().has_strict_partial_cover();
assert_eq!(slice.env_prefix_kinds_strict_partial_cover(), via_histogram,);
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_matches_structural_conjunction_pointwise() {
// Defining structural-conjunction form:
// `env_prefix_kinds_strict_partial_cover() ⇔
// env_prefix_kind_histogram().has_partial_cover() &&
// !env_prefix_kinds_singular_support() &&
// !env_prefix_kinds_singular_gap()` on every fixture. Pins the
// predicate against the three-way conjunction on the existing
// named-boundary triad consumers reach for when they open-code
// the strict interior in structural terms. Peer of
// `file_formats_strict_partial_cover_matches_structural_conjunction_pointwise`
// and
// `layer_kinds_strict_partial_cover_matches_structural_conjunction_pointwise`
// on the sister chain sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_strict_partial_cover();
let via_structural = slice.env_prefix_kind_histogram().has_partial_cover()
&& !slice.env_prefix_kinds_singular_support()
&& !slice.env_prefix_kinds_singular_gap();
assert_eq!(
via_seam, via_structural,
"env_prefix_kinds_strict_partial_cover ({via_seam}) must agree with \
has_partial_cover && !singular_support && !singular_gap ({via_structural})",
);
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_agrees_with_present_env_prefix_kinds_count_strict_interval_pointwise()
{
// Support-scalar strict-interval form:
// `env_prefix_kinds_strict_partial_cover() == (1 <
// present_env_prefix_kinds_count() && present_env_prefix_kinds_count()
// + 1 < axis_cardinality::<EnvMetadataTagKind>())` on every
// fixture. The support-side surfacing of the same boolean,
// without allocating the `Vec<EnvMetadataTagKind>`. Peer of
// `file_formats_strict_partial_cover_agrees_with_present_file_formats_count_strict_interval_pointwise`
// on the file-format sub-axis and
// `layer_kinds_strict_partial_cover_agrees_with_present_layer_kinds_count_strict_interval_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_strict_partial_cover();
let count = slice.present_env_prefix_kinds_count();
let via_interval =
1 < count && count + 1 < crate::axis_cardinality::<EnvMetadataTagKind>();
assert_eq!(
via_seam, via_interval,
"env_prefix_kinds_strict_partial_cover ({via_seam}) must agree with \
1 < present_env_prefix_kinds_count && present_env_prefix_kinds_count + 1 < axis_cardinality \
(count={count})",
);
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_agrees_with_absent_env_prefix_kinds_count_strict_interval_pointwise()
{
// Coverage-gap-scalar strict-interval form:
// `env_prefix_kinds_strict_partial_cover() == (1 <
// absent_env_prefix_kinds_count() && absent_env_prefix_kinds_count()
// + 1 < axis_cardinality::<EnvMetadataTagKind>())` on every
// fixture. The coverage-gap-side surfacing of the same boolean,
// without allocating the `Vec<EnvMetadataTagKind>`. Complementary
// to the support-scalar strict-interval form on the same
// partition via the `present_env_prefix_kinds_count +
// absent_env_prefix_kinds_count == axis_cardinality` invariant.
// Peer of
// `file_formats_strict_partial_cover_agrees_with_absent_file_formats_count_strict_interval_pointwise`
// on the file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_strict_partial_cover();
let gap = slice.absent_env_prefix_kinds_count();
let via_interval = 1 < gap && gap + 1 < crate::axis_cardinality::<EnvMetadataTagKind>();
assert_eq!(
via_seam, via_interval,
"env_prefix_kinds_strict_partial_cover ({via_seam}) must agree with \
1 < absent_env_prefix_kinds_count && absent_env_prefix_kinds_count + 1 < axis_cardinality \
(gap={gap})",
);
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_agrees_with_dual_vec_at_least_two_of_each_pointwise() {
// Dual-`Vec` at-least-two-of-each form:
// `env_prefix_kinds_strict_partial_cover() ==
// (present_env_prefix_kinds().len() >= 2 &&
// absent_env_prefix_kinds().len() >= 2)` on every fixture. Pins
// the predicate against the dual-vector form consumers reach for
// when they already hold both support and coverage-gap vectors —
// the allocating-both-vectors open-coding this lift replaces.
// Peer of
// `file_formats_strict_partial_cover_agrees_with_dual_vec_at_least_two_of_each_pointwise`
// on the file-format sub-axis and
// `layer_kinds_strict_partial_cover_agrees_with_dual_vec_at_least_two_of_each_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_strict_partial_cover();
let via_vec = slice.present_env_prefix_kinds().len() >= 2
&& slice.absent_env_prefix_kinds().len() >= 2;
assert_eq!(
via_seam, via_vec,
"env_prefix_kinds_strict_partial_cover ({via_seam}) must agree with \
present_env_prefix_kinds().len() >= 2 && absent_env_prefix_kinds().len() >= 2 ({via_vec})",
);
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_chain_altitude_is_vacuously_false_pointwise() {
// Cardinality-conditional reachability pin at the chain env-
// prefix sub-axis: `!env_prefix_kinds_strict_partial_cover()` on
// every chain fixture. `EnvMetadataTagKind` carries two cells,
// so the strict interval `[2, cardinality - 2] = [2, 0]` on the
// support-cardinality scalar is empty — no chain can observe
// `>= 2` cells AND leave `>= 2` cells unobserved simultaneously.
// Trait-uniform pin of the lift's vacuously-`false` polarity at
// the chain env-prefix sub-axis, matching
// `AxisHistogram::has_strict_partial_cover`'s cardinality-`2`
// scan one altitude down and the two other vacuously-`false`
// altitudes in the projection:
// `layer_kinds_strict_partial_cover_chain_altitude_is_vacuously_false_pointwise`
// (cardinality-`3` layer-kind sub-axis) and
// `kinds_strict_partial_cover_diff_altitude_is_vacuously_false_pointwise`
// (cardinality-`3` diff altitude). Distinguishes this chain sub-
// axis from the tier altitude and the chain file-format sub-
// axis, where cardinality `>= 4` opens a strict-interior
// witness. Env-prefix sub-axis carries the *tightest* vacuously-
// `false` polarity in the projection — the interval closes two
// cardinality steps below the reachability threshold.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
assert!(
!slice.env_prefix_kinds_strict_partial_cover(),
"env_prefix_kinds_strict_partial_cover must read false on every \
EnvMetadataTagKind (cardinality-2) chain — the strict interior \
is unreachable on cardinality-`<= 3` axes",
);
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_empty_chain_is_false() {
// Empty-chain boundary: the empty chain observes zero cells, so
// the "at least two observed" half of the conjunction fails
// uniformly — `env_prefix_kinds_strict_partial_cover` reads
// `false`. Matches `has_strict_partial_cover` reading `false` on
// the empty histogram one altitude down. Peer of
// `env_prefix_kinds_any_observed_empty_chain_is_false`,
// `env_prefix_kinds_full_cover_empty_chain_is_false`,
// `env_prefix_kinds_singular_support_empty_chain_is_false`, and
// `env_prefix_kinds_singular_gap_empty_chain_is_false` on the
// same polarity of the coverage-support partition.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_strict_partial_cover());
assert!(!empty.env_prefix_kinds_any_observed());
assert!(!empty.env_prefix_kinds_singular_support());
assert!(!empty.env_prefix_kinds_singular_gap());
assert!(!empty.env_prefix_kinds_full_cover());
}
#[test]
fn env_prefix_kinds_strict_partial_cover_no_env_layers_is_false() {
// Cross-sub-axis divergence pin against
// `layer_kinds_strict_partial_cover_empty_chain_is_false`: on
// the env-prefix sub-axis the *non-empty-chain / empty-
// histogram* boundary ALSO reads `false`. A chain of only
// Defaults / File layers is non-empty but has an empty env-
// prefix histogram, so zero cells are observed and the "at
// least two observed" half fails uniformly. Matches
// `env_prefix_kinds_singular_gap_no_env_layers_is_false`,
// `env_prefix_kinds_singular_support_no_env_layers_is_false`,
// `env_prefix_kinds_any_observed_no_env_layers_is_false`, and
// `env_prefix_kinds_full_cover_no_env_layers_is_false` on the
// same-shape fixtures.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert_eq!(
slice.layer_kind_histogram().count(ConfigSourceKind::Env),
0,
"fixture must have zero Env layers",
);
assert!(!slice.env_prefix_kinds_strict_partial_cover());
assert!(!slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_balanced());
assert!(!slice.env_prefix_kinds_full_cover());
assert!(!slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_singular_gap());
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_singleton_support_is_false() {
// Singleton-support pin: every env layer carries the same
// prefix polarity, so the support cardinality is `1` (not
// `>= 2`) — the "at least two observed" half fails uniformly.
// Direct witness of the strict disjointness
// `env_prefix_kinds_singular_support ⇒
// !env_prefix_kinds_strict_partial_cover`. Two witnesses on the
// two-cell env-prefix axis — one for each cell — collapsed into
// one test since both fire the same polarity by the two-cell-
// axis coincidence.
let prefixed = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let bare = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
for chain in [prefixed, bare] {
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_strict_partial_cover());
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_uniform_cover_is_false() {
// Uniform-cover pin: both env-prefix cells contribute at least
// one env layer, so zero cells are unobserved — the "at least
// two unobserved" half fails uniformly. Direct witness of the
// strict disjointness `env_prefix_kinds_full_cover ⇒
// !env_prefix_kinds_strict_partial_cover` on every axis. Peer
// of `file_formats_strict_partial_cover_uniform_cover_is_false`
// on the file-format sub-axis,
// `layer_kinds_strict_partial_cover_uniform_cover_is_false` on
// the layer-kind sub-axis, and
// `tiers_strict_partial_cover_uniform_cover_is_false` on the
// tier altitude.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kinds_full_cover());
assert!(!slice.env_prefix_kinds_strict_partial_cover());
}
#[test]
fn env_prefix_kinds_strict_partial_cover_implies_env_prefix_kinds_any_observed_pointwise() {
// Subsumption pin: `env_prefix_kinds_strict_partial_cover() ⇒
// env_prefix_kinds_any_observed()` on every axis with cardinality
// `>= 4`. On the cardinality-`2` `EnvMetadataTagKind` axis the
// antecedent never fires so the implication holds vacuously; the
// pin still walks every fixture to catch any future implementation
// that would erroneously fire the antecedent. Peer of
// `file_formats_strict_partial_cover_implies_file_formats_any_observed_pointwise`
// on the file-format sub-axis and
// `layer_kinds_strict_partial_cover_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_strict_partial_cover() {
assert!(
slice.env_prefix_kinds_any_observed(),
"strict-partial-cover chain must be any-observed",
);
}
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_implies_not_env_prefix_kinds_singular_support_pointwise()
{
// Disjointness pin: `env_prefix_kinds_strict_partial_cover() ⇒
// !env_prefix_kinds_singular_support()` on every axis. A strict-
// interior chain has `>= 2` observed cells; a singleton support
// has exactly `1`. Peer of
// `file_formats_strict_partial_cover_implies_not_file_formats_singular_support_pointwise`
// on the file-format sub-axis and
// `layer_kinds_strict_partial_cover_implies_not_layer_kinds_singular_support_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_strict_partial_cover() {
assert!(
!slice.env_prefix_kinds_singular_support(),
"strict-partial-cover chain cannot be singular-support",
);
}
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_implies_not_env_prefix_kinds_singular_gap_pointwise() {
// Disjointness pin: `env_prefix_kinds_strict_partial_cover() ⇒
// !env_prefix_kinds_singular_gap()` on every axis. A strict-
// interior chain has `>= 2` unobserved cells; a singleton gap
// has exactly `1`. Peer of
// `file_formats_strict_partial_cover_implies_not_file_formats_singular_gap_pointwise`
// on the file-format sub-axis and
// `layer_kinds_strict_partial_cover_implies_not_layer_kinds_singular_gap_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_strict_partial_cover() {
assert!(
!slice.env_prefix_kinds_singular_gap(),
"strict-partial-cover chain cannot be singular-gap",
);
}
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_implies_not_env_prefix_kinds_full_cover_pointwise() {
// Disjointness pin: `env_prefix_kinds_strict_partial_cover() ⇒
// !env_prefix_kinds_full_cover()` on every axis. A strict-
// interior chain has `>= 2` unobserved cells; a full cover has
// zero. Peer of
// `file_formats_strict_partial_cover_implies_not_file_formats_full_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_strict_partial_cover_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_strict_partial_cover() {
assert!(
!slice.env_prefix_kinds_full_cover(),
"strict-partial-cover chain cannot be full-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_any_observed_negation_implies_not_env_prefix_kinds_strict_partial_cover_pointwise()
{
// Contrapositive: `!env_prefix_kinds_any_observed() ⇒
// !env_prefix_kinds_strict_partial_cover()` on every axis. If no
// cell was observed, the "at least two observed" half of the
// conjunction fails uniformly — the strict-interior predicate
// fails. Peer of
// `file_formats_any_observed_negation_implies_not_file_formats_strict_partial_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_any_observed_negation_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if !slice.env_prefix_kinds_any_observed() {
assert!(
!slice.env_prefix_kinds_strict_partial_cover(),
"empty-support chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk() {
// Parity against the exact hand-rolled strict-partial-cover walk
// this lift replaces: walk every cell of the histogram and count
// how many carry a zero count and how many carry a positive
// count; the strict-partial-cover predicate reads `true` iff at
// least two cells are zero AND at least two cells are positive.
// On the cardinality-`2` `EnvMetadataTagKind` axis this is
// unreachable — both sides read `false` on every fixture. Peer
// of
// `file_formats_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk`
// on the file-format sub-axis,
// `layer_kinds_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk`
// on the layer-kind sub-axis,
// `tiers_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk`
// on the tier altitude, and
// `kinds_strict_partial_cover_agrees_with_open_coded_dual_at_least_two_walk`
// on the diff altitude — closing the parity discipline at the
// sixth and final altitude / sub-axis in the projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_strict_partial_cover();
let hist = slice.env_prefix_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros >= 2 && nonzeros >= 2;
assert_eq!(via_seam, hand_rolled);
}
}
#[test]
fn env_prefix_kinds_partition_covers_every_chain_pointwise() {
// Trichotomy closure pin at the chain env-prefix sub-axis:
// exactly one of `(!env_prefix_kinds_any_observed,
// env_prefix_kinds_singular_support ∧
// !env_prefix_kinds_singular_gap,
// env_prefix_kinds_strict_partial_cover,
// env_prefix_kinds_singular_gap ∧
// !env_prefix_kinds_singular_support,
// env_prefix_kinds_full_cover)` fires per chain. With this lift
// the 5-corner support-cardinality partition is jointly
// exhaustive AND pairwise disjoint on every chain fixture. On
// the cardinality-`2` `EnvMetadataTagKind` axis the strict-
// interior corner is structurally empty AND the two singular
// corners coincide pointwise
// (`singular_support ⇔ singular_gap`), so this pin *uniquely*
// canonicalises the singular row by asserting the coincidence
// and folding both singular predicates into one active corner
// that fires exactly on chains observing exactly one env-prefix
// cell. Peer of
// `file_formats_partition_covers_every_chain_pointwise` on the
// file-format sub-axis (where the strict-interior corner
// carries witnesses and every corner is disjoint by cardinality),
// `layer_kinds_partition_covers_every_chain_pointwise` on the
// layer-kind sub-axis (where the strict-interior corner is
// structurally empty but the two singular corners are strictly
// disjoint by the cardinality-`3` axis), and
// `tiers_partition_covers_every_map_pointwise` /
// `kinds_partition_covers_every_diff_pointwise` on the peer
// altitudes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let empty = !slice.env_prefix_kinds_any_observed();
let sup = slice.env_prefix_kinds_singular_support();
let strict = slice.env_prefix_kinds_strict_partial_cover();
let gap = slice.env_prefix_kinds_singular_gap();
let full = slice.env_prefix_kinds_full_cover();
// Two-cell-axis coincidence: singular_support ⇔ singular_gap.
assert_eq!(
sup, gap,
"singular_support ({sup}) and singular_gap ({gap}) must coincide on \
the two-cell env-prefix axis",
);
// Strict-interior corner is structurally empty on the two-
// cell axis — every chain fires exactly one of the four
// remaining corners `{empty, singular (sup ⇔ gap), full}`.
assert!(
!strict,
"strict-partial-cover corner must be structurally empty on the \
two-cell env-prefix axis",
);
let singular = sup && gap;
let fires = u8::from(empty) + u8::from(singular) + u8::from(full);
assert_eq!(
fires, 1,
"exactly one of (empty, singular, full_cover) must fire per chain on \
the two-cell env-prefix axis — observed {fires}",
);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_low_support — low-support-
// env-prefix-kinds boolean predicate on the env-prefix sub-axis
// of the chain altitude, lifting `has_low_support` from the
// histogram surface and closing the "low-support across
// altitudes" projection sideways to the fifth and final
// altitude / sub-axis. `EnvMetadataTagKind` cardinality-`2`
// axis: the low-magnitude corner coincides pointwise with
// `!full_cover` (equivalent to the union of the empty-histogram
// and singleton-support corners with the two-cell-axis
// coincidence folding `singular_support ⇔ singular_gap`); every
// chain except the uniform two-kind cover reads `true`. Routed
// through the shared `AxisHistogram::has_low_support` primitive
// one altitude down. ----
#[test]
fn env_prefix_kinds_low_support_matches_env_prefix_kind_histogram_has_low_support_pointwise() {
// Routing pin: `env_prefix_kinds_low_support` routes through
// `env_prefix_kind_histogram().has_low_support()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-
// prefix sub-axis peer of
// `file_formats_low_support_matches_file_format_histogram_has_low_support_pointwise`
// on the file-format sub-axis,
// `layer_kinds_low_support_matches_layer_kind_histogram_has_low_support_pointwise`
// on the layer-kind sub-axis,
// `tiers_low_support_matches_tier_histogram_has_low_support_pointwise`
// on the tier altitude, and
// `kinds_low_support_matches_kind_histogram_has_low_support_pointwise`
// on the diff altitude, closing the "low-support across
// altitudes" projection at the fifth and final altitude /
// sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().has_low_support();
assert_eq!(slice.env_prefix_kinds_low_support(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_low_support_matches_defining_union_of_low_boundaries_pointwise() {
// Defining-union-of-low-boundaries disjunction:
// `env_prefix_kinds_low_support() ⇔ !env_prefix_kinds_any_observed()
// || env_prefix_kinds_singular_support()` on every fixture. Pins
// the predicate against the two-way disjunction on the two named
// histogram-side peers consumers reach for when they open-code
// the low-magnitude corner as "empty OR singleton-support". Peer
// of
// `file_formats_low_support_matches_defining_union_of_low_boundaries_pointwise`
// on the file-format sub-axis and
// `layer_kinds_low_support_matches_defining_union_of_low_boundaries_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_low_support();
let via_disj =
!slice.env_prefix_kinds_any_observed() || slice.env_prefix_kinds_singular_support();
assert_eq!(
via_seam, via_disj,
"env_prefix_kinds_low_support ({via_seam}) must agree with \
!env_prefix_kinds_any_observed || env_prefix_kinds_singular_support \
({via_disj})",
);
}
}
#[test]
fn env_prefix_kinds_low_support_agrees_with_present_env_prefix_kinds_count_at_most_one_pointwise()
{
// Support-scalar at-most-one form:
// `env_prefix_kinds_low_support() ==
// (present_env_prefix_kinds_count() <= 1)` on every fixture. The
// support-side surfacing of the same boolean, without allocating
// the `Vec<EnvMetadataTagKind>`. Peer of
// `file_formats_low_support_agrees_with_present_file_formats_count_at_most_one_pointwise`
// on the file-format sub-axis and
// `layer_kinds_low_support_agrees_with_present_layer_kinds_count_at_most_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_low_support();
let count = slice.present_env_prefix_kinds_count();
assert_eq!(
via_seam,
count <= 1,
"env_prefix_kinds_low_support ({via_seam}) must agree with \
present_env_prefix_kinds_count() <= 1 (count={count})",
);
}
}
#[test]
fn env_prefix_kinds_low_support_agrees_with_present_env_prefix_kinds_len_at_most_one_pointwise()
{
// Support-`Vec` at-most-one form:
// `env_prefix_kinds_low_support() ==
// (present_env_prefix_kinds().len() <= 1)` on every fixture.
// Pins the predicate against the support-`Vec` form consumers
// reach for when they already hold the support vector — the
// allocating open-coding this lift replaces. Peer of
// `file_formats_low_support_agrees_with_present_file_formats_len_at_most_one_pointwise`
// on the file-format sub-axis and
// `layer_kinds_low_support_agrees_with_present_layer_kinds_len_at_most_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_low_support();
let via_vec = slice.present_env_prefix_kinds().len() <= 1;
assert_eq!(
via_seam, via_vec,
"env_prefix_kinds_low_support ({via_seam}) must agree with \
present_env_prefix_kinds().len() <= 1 ({via_vec})",
);
}
}
#[test]
fn env_prefix_kinds_low_support_agrees_with_absent_env_prefix_kinds_count_at_least_axis_cardinality_minus_one_pointwise()
{
// Coverage-gap-scalar at-least-axis-cardinality-minus-one form:
// `env_prefix_kinds_low_support() == (absent_env_prefix_kinds_count()
// >= axis_cardinality::<EnvMetadataTagKind>() - 1)` on every
// fixture. The coverage-gap-side surfacing of the same boolean
// via the `present + absent == axis_cardinality` invariant. Peer
// of
// `file_formats_low_support_agrees_with_absent_file_formats_count_at_least_axis_cardinality_minus_one_pointwise`
// on the file-format sub-axis and
// `layer_kinds_low_support_agrees_with_absent_layer_kinds_count_at_least_axis_cardinality_minus_one_pointwise`
// on the layer-kind sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_low_support();
let gap = slice.absent_env_prefix_kinds_count();
let via_gap = gap >= crate::axis_cardinality::<EnvMetadataTagKind>() - 1;
assert_eq!(
via_seam, via_gap,
"env_prefix_kinds_low_support ({via_seam}) must agree with \
absent_env_prefix_kinds_count() >= axis_cardinality - 1 ({via_gap}, gap={gap})",
);
}
}
#[test]
fn env_prefix_kinds_low_support_empty_chain_is_true() {
// Empty-chain boundary: zero observed cells satisfy the "at
// most one observed" clause vacuously —
// `env_prefix_kinds_low_support` reads `true`. Matches
// `has_low_support` reading `true` on the empty histogram one
// altitude down. Diverges from
// `env_prefix_kinds_any_observed`'s,
// `env_prefix_kinds_full_cover`'s,
// `env_prefix_kinds_singular_support`'s, and
// `env_prefix_kinds_singular_gap`'s empty-chain `false` polarity
// — the low-support boundary strictly *includes* the empty
// chain by folding the "no observation" case into the low-
// magnitude corner. Peer of
// `layer_kinds_low_support_empty_chain_is_true` on the layer-
// kind sub-axis and
// `file_formats_low_support_empty_chain_is_true` on the file-
// format sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.env_prefix_kinds_low_support());
assert!(!empty.env_prefix_kinds_any_observed());
assert!(!empty.env_prefix_kinds_singular_support());
assert!(!empty.env_prefix_kinds_singular_gap());
assert!(!empty.env_prefix_kinds_full_cover());
assert!(!empty.env_prefix_kinds_strict_partial_cover());
}
#[test]
fn env_prefix_kinds_low_support_no_env_layers_is_true() {
// Non-empty-chain / empty-histogram boundary the env-prefix
// sub-axis pins that the layer-kind sub-axis does *not*. A
// chain of only `Defaults` / `File` layers is non-empty but has
// no `Some` env_prefix_kind projection, so the histogram is
// empty and the "at most one observed" clause holds vacuously
// — `env_prefix_kinds_low_support` reads `true`. Cross-sub-axis
// divergence pin against `layer_kinds_low_support`: on the same
// fixtures the layer-kind sub-axis observes at least one
// layer-kind cell (Defaults / File) so the low-support corner
// is narrower there. Matches
// `file_formats_low_support_no_recognized_files_is_true` on the
// file-format sub-axis one axis over — both sub-axes pin the
// wider empty-histogram boundary that the layer-kind sub-axis
// does not.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert!(!slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_low_support());
}
}
#[test]
fn env_prefix_kinds_low_support_singleton_support_is_true() {
// Singleton-support pin: every env layer carries the same
// prefix polarity, so the support cardinality is `1` (at most
// `1`) — `env_prefix_kinds_low_support` reads `true`. Direct
// witness of the subsumption `env_prefix_kinds_singular_support
// ⇒ env_prefix_kinds_low_support`: every singleton-support
// chain lands on the low-magnitude corner by the union-of-low-
// boundaries disjunction. Two witnesses on the two-cell axis
// — one for each cell (Prefixed and Bare) — collapsed into one
// test since both fire the same polarity by the two-cell-axis
// coincidence. Also witnesses the two-cell tightening
// `env_prefix_kinds_singular_gap ⇒ env_prefix_kinds_low_support`
// (both singular predicates coincide pointwise on the two-cell
// axis and both subsume into the low-magnitude corner). Peer of
// `layer_kinds_low_support_singleton_support_is_true` on the
// layer-kind sub-axis and
// `file_formats_low_support_singleton_support_is_true` on the
// file-format sub-axis.
let prefixed = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let bare = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
for chain in [prefixed, bare] {
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_singular_gap());
assert!(slice.env_prefix_kinds_low_support());
}
}
#[test]
fn env_prefix_kinds_low_support_uniform_cover_is_false() {
// Uniform-cover pin: both env-prefix cells contribute at least
// one env layer, so the support cardinality is `2` (violates
// `<= 1`) — `env_prefix_kinds_low_support` reads `false`.
// Direct witness of the disjointness
// `env_prefix_kinds_full_cover ⇒ !env_prefix_kinds_low_support`
// on every cardinality-`>= 2` axis, tightened on the two-cell
// env-prefix axis into the equivalence
// `env_prefix_kinds_low_support ⇔ !env_prefix_kinds_full_cover`
// — the uniform two-kind cover is the *unique* `false` side of
// the low-support boundary on the two-cell axis. Peer of
// `layer_kinds_low_support_uniform_cover_is_false` on the
// layer-kind sub-axis and
// `file_formats_low_support_uniform_cover_is_false` on the
// file-format sub-axis.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kinds_full_cover());
assert!(!slice.env_prefix_kinds_low_support());
}
#[test]
fn env_prefix_kinds_low_support_implies_not_env_prefix_kinds_full_cover_pointwise() {
// Disjointness pin: `env_prefix_kinds_low_support() ⇒
// !env_prefix_kinds_full_cover()` on every axis with
// cardinality `>= 2`. Low support has size `<= 1`; full cover
// has size `axis_cardinality >= 2`. Peer of
// `layer_kinds_low_support_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis and
// `file_formats_low_support_implies_not_file_formats_full_cover_pointwise`
// on the file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_low_support() {
assert!(
!slice.env_prefix_kinds_full_cover(),
"low-support chain cannot be full-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_low_support_implies_not_env_prefix_kinds_strict_partial_cover_pointwise() {
// Disjointness pin: `env_prefix_kinds_low_support() ⇒
// !env_prefix_kinds_strict_partial_cover()` always. The strict
// interior requires `>= 2` observed cells; low support has
// `<= 1`. On the cardinality-`2` `EnvMetadataTagKind` axis the
// consequent holds vacuously (the strict interior is
// structurally empty on the two-cell axis, so
// `!env_prefix_kinds_strict_partial_cover` reads `true` on every
// chain), matching
// `layer_kinds_low_support_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the cardinality-`3` layer-kind sub-axis where the same
// implication also holds vacuously (the strict interior is
// unreachable). Contrasts with
// `file_formats_low_support_implies_not_file_formats_strict_partial_cover_pointwise`
// on the cardinality-`4` file-format sub-axis where the
// consequent is meaningfully constrained AND the antecedent is
// reachable — the two-format partial cover fixture is a
// `strict_partial_cover=true, low_support=false` witness. The
// env-prefix sub-axis carries the *tightest* vacuously-true
// consequent in the projection — the strict interval closes
// two cardinality steps below the reachability threshold, so
// the strict-interior disjointness carries no non-vacuous
// witness here.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_low_support() {
assert!(
!slice.env_prefix_kinds_strict_partial_cover(),
"low-support chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_any_observed_negation_implies_env_prefix_kinds_low_support_pointwise() {
// Subsumption pin: `!env_prefix_kinds_any_observed() ⇒
// env_prefix_kinds_low_support()` on every axis. If no cell was
// observed, the "at most one observed" clause holds vacuously.
// Peer of
// `layer_kinds_any_observed_negation_implies_layer_kinds_low_support_pointwise`
// on the layer-kind sub-axis and
// `file_formats_any_observed_negation_implies_file_formats_low_support_pointwise`
// on the file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if !slice.env_prefix_kinds_any_observed() {
assert!(
slice.env_prefix_kinds_low_support(),
"empty-support chain must be low-support",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_support_implies_env_prefix_kinds_low_support_pointwise() {
// Subsumption pin: `env_prefix_kinds_singular_support() ⇒
// env_prefix_kinds_low_support()` on every axis. A singleton-
// support chain lands on the low-magnitude corner by the union-
// of-low-boundaries disjunction. Peer of
// `layer_kinds_singular_support_implies_layer_kinds_low_support_pointwise`
// on the layer-kind sub-axis and
// `file_formats_singular_support_implies_file_formats_low_support_pointwise`
// on the file-format sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_support() {
assert!(
slice.env_prefix_kinds_low_support(),
"singular-support chain must be low-support",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_gap_implies_env_prefix_kinds_low_support_pointwise() {
// Cardinality-`2` two-cell-axis coincidence pin: on the two-
// cell env-prefix axis `singular_gap ⇔ singular_support`, so
// `env_prefix_kinds_singular_gap() ⇒ env_prefix_kinds_low_support()`
// holds by folding through the singular-support subsumption
// above. Does NOT lift to the cardinality-`>= 3` sub-axes
// ([`Self::layer_kinds_low_support`] on the cardinality-`3`
// layer-kind sub-axis and [`Self::file_formats_low_support`] on
// the cardinality-`4` file-format sub-axis) where singular-gap
// sits at support cardinality `axis_cardinality - 1 >= 2` on
// the wrong side of the low-support boundary — those sub-axes
// pin the strict disjointness `low_support ⇒ !singular_gap`
// instead. This lift carries the *unique* two-cell-axis
// tightening of the singular-gap / low-support relationship
// into a same-sided subsumption.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_gap() {
assert!(
slice.env_prefix_kinds_low_support(),
"singular-gap chain must be low-support on the two-cell env-prefix axis",
);
}
}
}
#[test]
fn env_prefix_kinds_low_support_equivalent_to_not_env_prefix_kinds_full_cover_pointwise() {
// Cardinality-`2` two-cell-axis tightening pin:
// `env_prefix_kinds_low_support() ⇔ !env_prefix_kinds_full_cover()`
// on every fixture. Unique tightening of the general
// disjointness `low_support ⇒ !full_cover` (documented at every
// altitude / sub-axis) into an equivalence on the two-cell
// axis, since the strict interior is structurally empty and
// every non-full-cover chain sits at support cardinality `0`
// or `1` (both `<= 1`) — the low-magnitude corner and the
// full-cover corner partition the two-cell axis exhaustively.
// Cross-sub-axis divergence from
// `layer_kinds_low_support_implies_not_layer_kinds_full_cover_pointwise`
// and
// `file_formats_low_support_implies_not_file_formats_full_cover_pointwise`:
// the same equivalence does not lift to the cardinality-`3`
// layer-kind sub-axis (two-kind partial covers sit on the
// `!low_support ∧ !full_cover` middle interval) or the
// cardinality-`4` file-format sub-axis (two-format and three-
// format partial covers sit on the same middle interval).
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_low_support();
let via_negation = !slice.env_prefix_kinds_full_cover();
assert_eq!(
via_seam, via_negation,
"env_prefix_kinds_low_support ({via_seam}) must equal \
!env_prefix_kinds_full_cover ({via_negation}) on the two-cell axis",
);
}
}
#[test]
fn env_prefix_kinds_low_support_agrees_with_open_coded_at_most_one_positive_walk() {
// Parity against the exact hand-rolled at-most-one-positive
// walk this lift replaces: walk every cell of the histogram
// and count how many carry a positive count; the low-support
// predicate reads `true` iff at most one cell carries a
// positive count. Peer of
// `layer_kinds_low_support_agrees_with_open_coded_at_most_one_positive_walk`
// on the layer-kind sub-axis and
// `file_formats_low_support_agrees_with_open_coded_at_most_one_positive_walk`
// on the file-format sub-axis, closing the parity discipline
// at the fifth and final altitude / sub-axis in the "low-
// support across altitudes" projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_low_support();
let hist = slice.env_prefix_kind_histogram();
let positives = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = positives <= 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_high_support —
// high-support-env-prefix-kinds boolean predicate on the env-
// prefix sub-axis of the chain altitude, closing the "high-
// support across altitudes" projection at the fifth and
// final altitude / sub-axis. Routed through the shared
// `AxisHistogram::has_high_support` primitive one altitude
// down. Degenerate on the cardinality-`2` `EnvMetadataTagKind`
// axis: `env_prefix_kinds_high_support ⇔
// env_prefix_kinds_full_cover` (the *unique* two-cell-axis
// collapse — the dual-singular-collapse excision fires on
// every singular-gap chain, so the high-magnitude corner
// tracks the full-cover corner exactly). The strict-interior
// middle leg is vacuously empty, so the magnitude-direction
// ternary degenerates to the dual partition — matches the
// layer-kind sub-axis and the diff altitude and diverges
// from the tier altitude and the file-format sub-axis. ----
#[test]
fn env_prefix_kinds_high_support_matches_env_prefix_kind_histogram_has_high_support_pointwise()
{
// Routing pin: `env_prefix_kinds_high_support` routes through
// `env_prefix_kind_histogram().has_high_support()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-
// prefix sub-axis peer of
// `file_formats_high_support_matches_file_format_histogram_has_high_support_pointwise`
// on the file-format sub-axis,
// `layer_kinds_high_support_matches_layer_kind_histogram_has_high_support_pointwise`
// on the layer-kind sub-axis,
// `tiers_high_support_matches_tier_histogram_has_high_support_pointwise`
// on the tier altitude, and
// `kinds_high_support_matches_kind_histogram_has_high_support_pointwise`
// on the diff altitude, closing the "high-support across
// altitudes" projection at the fifth and final altitude /
// sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().has_high_support();
assert_eq!(slice.env_prefix_kinds_high_support(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise()
{
// Defining strict-singular-gap-or-full-cover form:
// `env_prefix_kinds_high_support() ⇔ env_prefix_kinds_full_cover()
// || (env_prefix_kinds_singular_gap() &&
// !env_prefix_kinds_singular_support())`. Pins the predicate
// against the three-way disjunction on three named histogram-
// side peers consumers reach for when they open-code the high-
// magnitude corner as a boolean fold over the full-cover and
// strict singleton-gap boundaries. The
// `!env_prefix_kinds_singular_support()` excision *fires* on
// the cardinality-`2` env-prefix axis (when
// `env_prefix_kinds_singular_gap` fires, support size `1` —
// the dual-singular-collapse), so the disjunction reduces
// pointwise to `env_prefix_kinds_full_cover` at this sub-axis
// — a strict divergence from the layer-kind sub-axis and the
// file-format sub-axis where the excision is vacuous. Peer of
// `file_formats_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise`
// on the file-format sub-axis,
// `layer_kinds_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise`
// on the layer-kind sub-axis,
// `tiers_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise`
// on the tier altitude, and
// `kinds_high_support_matches_defining_strict_singular_gap_or_full_cover_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_high_support();
let via_union = slice.env_prefix_kinds_full_cover()
|| (slice.env_prefix_kinds_singular_gap()
&& !slice.env_prefix_kinds_singular_support());
assert_eq!(
via_seam, via_union,
"env_prefix_kinds_high_support ({via_seam}) must agree with \
env_prefix_kinds_full_cover || (env_prefix_kinds_singular_gap && !env_prefix_kinds_singular_support) ({via_union})",
);
}
}
#[test]
fn env_prefix_kinds_high_support_agrees_with_absent_env_prefix_kinds_count_at_most_one_and_support_at_least_two_pointwise()
{
// Coverage-gap-scalar dual-interval surface:
// `env_prefix_kinds_high_support() ==
// (absent_env_prefix_kinds_count() <= 1 &&
// present_env_prefix_kinds_count() >= 2)` on every fixture. The
// coverage-gap-side surfacing of the same boolean, without
// allocating either `Vec<EnvMetadataTagKind>`. On the
// cardinality-`2` axis both clauses coincide pointwise (both
// read `true` iff full cover), so the dual-interval collapses
// to a single boolean — the two-cell-axis tightening of the
// dual-interval into the full-cover corner. Peer of
// `file_formats_high_support_agrees_with_absent_file_formats_count_at_most_one_and_support_at_least_two_pointwise`
// on the file-format sub-axis,
// `layer_kinds_high_support_agrees_with_absent_layer_kinds_count_at_most_one_and_support_at_least_two_pointwise`
// on the layer-kind sub-axis,
// `tiers_high_support_agrees_with_absent_tiers_count_at_most_one_and_support_at_least_two_pointwise`
// on the tier altitude, and
// `kinds_high_support_agrees_with_absent_kinds_count_at_most_one_and_support_at_least_two_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_high_support();
let gap = slice.absent_env_prefix_kinds_count();
let support = slice.present_env_prefix_kinds_count();
let via_scalar = gap <= 1 && support >= 2;
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_high_support ({via_seam}) must agree with \
absent_env_prefix_kinds_count <= 1 && present_env_prefix_kinds_count >= 2 \
(gap={gap}, support={support})",
);
}
}
#[test]
fn env_prefix_kinds_high_support_agrees_with_present_env_prefix_kinds_count_plus_one_at_least_axis_cardinality_pointwise()
{
// Support-scalar dual-interval form:
// `env_prefix_kinds_high_support() ==
// (present_env_prefix_kinds_count() + 1 >=
// axis_cardinality::<EnvMetadataTagKind>() &&
// present_env_prefix_kinds_count() >= 2)` on every fixture. The
// support-side surfacing of the same boolean — a high-
// magnitude fold observes at least `axis_cardinality - 1`
// cells; the `>= 2` clause excises the cardinality-`2`
// singleton where the dual-singular-collapse fires. On the
// cardinality-`2` axis the excision clause fires (the
// `+ 1 >= axis_cardinality` clause holds at support size `1`
// but the `>= 2` clause excises), so only full-cover chains
// satisfy both clauses — the two-cell-axis collapse onto the
// full-cover corner reads through the excision. Dual of the
// coverage-gap-scalar surface on the complementary side of the
// same partition via the `present + absent == axis_cardinality`
// invariant. Peer of
// `file_formats_high_support_agrees_with_present_file_formats_count_plus_one_at_least_axis_cardinality_pointwise`
// on the file-format sub-axis,
// `layer_kinds_high_support_agrees_with_present_layer_kinds_count_plus_one_at_least_axis_cardinality_pointwise`
// on the layer-kind sub-axis,
// `tiers_high_support_agrees_with_contributing_tiers_count_plus_one_at_least_axis_cardinality_pointwise`
// on the tier altitude, and
// `kinds_high_support_agrees_with_present_kinds_count_plus_one_at_least_axis_cardinality_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_high_support();
let support = slice.present_env_prefix_kinds_count();
let via_scalar =
support + 1 >= crate::axis_cardinality::<EnvMetadataTagKind>() && support >= 2;
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_high_support ({via_seam}) must agree with \
present_env_prefix_kinds_count + 1 >= axis_cardinality && \
present_env_prefix_kinds_count >= 2 (support={support})",
);
}
}
#[test]
fn env_prefix_kinds_high_support_agrees_with_present_env_prefix_kinds_len_at_least_axis_cardinality_minus_one_pointwise()
{
// Support-`Vec` dual-length form:
// `env_prefix_kinds_high_support() ==
// (present_env_prefix_kinds().len() + 1 >=
// axis_cardinality::<EnvMetadataTagKind>() &&
// present_env_prefix_kinds().len() >= 2)` on every fixture.
// Pins the predicate against the `Vec<EnvMetadataTagKind>`
// length form consumers reach for when they already hold the
// support vector. Allocating peer of the support-scalar dual-
// interval surface one pin over. Peer of
// `file_formats_high_support_agrees_with_present_file_formats_len_at_least_axis_cardinality_minus_one_pointwise`
// on the file-format sub-axis,
// `layer_kinds_high_support_agrees_with_present_layer_kinds_len_at_least_axis_cardinality_minus_one_pointwise`
// on the layer-kind sub-axis,
// `tiers_high_support_agrees_with_contributing_tiers_len_at_least_axis_cardinality_minus_one_pointwise`
// on the tier altitude, and
// `kinds_high_support_agrees_with_present_kinds_len_at_least_axis_cardinality_minus_one_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_high_support();
let len = slice.present_env_prefix_kinds().len();
let via_vec = len + 1 >= crate::axis_cardinality::<EnvMetadataTagKind>() && len >= 2;
assert_eq!(
via_seam, via_vec,
"env_prefix_kinds_high_support ({via_seam}) must agree with \
present_env_prefix_kinds().len() dual-interval ({via_vec}, len={len})",
);
}
}
#[test]
fn env_prefix_kinds_high_support_empty_chain_is_false() {
// Empty-chain boundary: the empty chain observes zero cells,
// so every cell is unobserved (two zeros on the cardinality-
// `2` axis) — the "at least two observed" clause fails and
// `env_prefix_kinds_high_support` reads `false`. Matches
// `has_high_support` reading `false` on the empty histogram
// one altitude down for every cardinality-`>= 2` axis. Direct
// witness of the disjointness `env_prefix_kinds_low_support ⇒
// !env_prefix_kinds_high_support` on the empty-chain corner —
// the empty chain sits at the *bottom* of the magnitude
// interval, not the top. Orthogonal polarity to
// `env_prefix_kinds_low_support` reading `true` on the empty
// chain — the two magnitude corners partition the two-cell
// env-prefix axis exhaustively (the strict-interior middle leg
// is structurally empty). Peer of
// `file_formats_high_support_empty_chain_is_false` on the
// file-format sub-axis,
// `layer_kinds_high_support_empty_chain_is_false` on the
// layer-kind sub-axis,
// `tiers_high_support_empty_map_is_false` on the tier
// altitude, and `kinds_high_support_empty_diff_is_false` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_high_support());
assert!(empty.env_prefix_kinds_low_support());
assert!(!empty.env_prefix_kinds_any_observed());
assert!(!empty.env_prefix_kinds_singular_support());
assert!(!empty.env_prefix_kinds_singular_gap());
assert!(!empty.env_prefix_kinds_full_cover());
assert!(!empty.env_prefix_kinds_strict_partial_cover());
}
#[test]
fn env_prefix_kinds_high_support_no_env_layers_is_false() {
// Non-empty-chain / empty-histogram boundary the env-prefix
// sub-axis pins that the layer-kind sub-axis does *not*. A
// chain of only `Defaults` / `File` layers is non-empty but
// has no `Some` env_prefix_kind projection, so the histogram
// is empty (two zeros on the cardinality-`2` axis) — the "at
// most one unobserved" clause fails and
// `env_prefix_kinds_high_support` reads `false`. Cross-sub-
// axis divergence pin against `layer_kinds_high_support`: on
// the same fixtures the layer-kind sub-axis observes at least
// one layer-kind cell (Defaults / File) so the high-support
// corner may fire there (when both Defaults and File
// contribute), but the env-prefix sub-axis's narrower high-
// magnitude corner does not. Matches
// `file_formats_high_support_no_recognized_files_is_false` on
// the file-format sub-axis one axis over — both sub-axes pin
// the wider empty-histogram boundary that the layer-kind sub-
// axis does not.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.nix")),
ConfigSource::File(PathBuf::from("/b.lisp")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert!(!slice.env_prefix_kinds_any_observed());
assert!(!slice.env_prefix_kinds_high_support());
assert!(slice.env_prefix_kinds_low_support());
}
}
#[test]
fn env_prefix_kinds_high_support_singleton_support_is_false() {
// Singleton-support pin — the *unique* two-cell-axis dual-
// singular-collapse witness. Every env layer carries the same
// prefix polarity, so the support cardinality is `1` — on the
// cardinality-`2` axis this leaves exactly one unobserved
// cell (the strict singular-gap boundary coincides with the
// strict singular-support boundary) — but the "at least two
// observed" clause fails and `env_prefix_kinds_high_support`
// reads `false`. Direct witness of the disjointness
// `env_prefix_kinds_singular_support ⇒
// !env_prefix_kinds_high_support` on every cardinality-`>= 2`
// axis, AND of the two-cell-axis-specific divergence
// `env_prefix_kinds_singular_gap ⇏ env_prefix_kinds_high_support`
// (which the cardinality-`>= 3` sub-axes contradict — on
// those axes singular-gap subsumes into high-support). Two
// witnesses on the two-cell axis — one for each cell
// (Prefixed and Bare) — collapsed into one test since both
// fire the same polarity by the two-cell-axis coincidence.
// Peer of `file_formats_high_support_singleton_support_is_false`
// on the file-format sub-axis,
// `layer_kinds_high_support_singleton_support_is_false` on
// the layer-kind sub-axis,
// `tiers_high_support_singleton_support_is_false` on the tier
// altitude, and `kinds_high_support_singleton_support_is_false`
// on the diff altitude.
let prefixed = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let bare = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
for chain in [prefixed, bare] {
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_singular_gap());
assert!(!slice.env_prefix_kinds_high_support());
}
}
#[test]
fn env_prefix_kinds_high_support_uniform_cover_is_true() {
// Uniform-cover pin: both env-prefix cells contribute at least
// one env layer, so the support cardinality is `2` (no
// unobserved cells) — `env_prefix_kinds_full_cover` fires and
// both the "at most one unobserved" *and* "at least two
// observed" clauses hold. Direct witness of the strict
// subsumption `env_prefix_kinds_full_cover ⇒
// env_prefix_kinds_high_support` on every cardinality-`>= 2`
// axis, tightened on the two-cell env-prefix axis into the
// equivalence `env_prefix_kinds_high_support ⇔
// env_prefix_kinds_full_cover` — the uniform two-kind cover
// is the *unique* `true` side of the high-support boundary on
// the two-cell axis. Peer of
// `file_formats_high_support_uniform_cover_is_true` on the
// file-format sub-axis,
// `layer_kinds_high_support_uniform_cover_is_true` on the
// layer-kind sub-axis,
// `tiers_high_support_uniform_cover_is_true` on the tier
// altitude, and `kinds_high_support_uniform_cover_is_true`
// on the diff altitude.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kinds_full_cover());
assert!(slice.env_prefix_kinds_high_support());
}
#[test]
fn env_prefix_kinds_high_support_implies_not_env_prefix_kinds_low_support_pointwise() {
// Disjointness pin: `env_prefix_kinds_high_support() ⇒
// !env_prefix_kinds_low_support()` on every axis with
// cardinality `>= 2`. High support has size `>= 2`; low
// support has size `<= 1`. The two magnitude corners sit at
// opposite ends of the support-cardinality interval on every
// non-degenerate axis. Pins the strict pairwise disjointness
// of the magnitude-direction ternary's two magnitude legs at
// the env-prefix sub-axis. Peer of
// `file_formats_high_support_implies_not_file_formats_low_support_pointwise`
// on the file-format sub-axis,
// `layer_kinds_high_support_implies_not_layer_kinds_low_support_pointwise`
// on the layer-kind sub-axis,
// `tiers_high_support_implies_not_tiers_low_support_pointwise`
// on the tier altitude, and
// `kinds_high_support_implies_not_kinds_low_support_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_high_support() {
assert!(
!slice.env_prefix_kinds_low_support(),
"high-support chain cannot be low-support on a \
cardinality >= 2 axis",
);
}
}
}
#[test]
fn env_prefix_kinds_high_support_implies_not_env_prefix_kinds_strict_partial_cover_pointwise() {
// Disjointness pin: `env_prefix_kinds_high_support() ⇒
// !env_prefix_kinds_strict_partial_cover()` always. The strict
// interior requires `>= 2` unobserved cells; high support has
// `<= 1`. On the cardinality-`2` `EnvMetadataTagKind` axis
// the consequent holds vacuously (the strict interior is
// structurally empty on the two-cell axis, so
// `!env_prefix_kinds_strict_partial_cover` reads `true` on
// every chain), matching
// `layer_kinds_high_support_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the cardinality-`3` layer-kind sub-axis where the same
// implication also holds vacuously (the strict interior is
// unreachable). Contrasts with
// `file_formats_high_support_implies_not_file_formats_strict_partial_cover_pointwise`
// on the cardinality-`4` file-format sub-axis where the
// consequent is meaningfully constrained AND the antecedent is
// reachable — the two-format partial cover fixture is a
// `strict_partial_cover=true, high_support=false` witness. The
// env-prefix sub-axis carries the *tightest* vacuously-true
// consequent in the projection — the strict interval closes
// two cardinality steps below the reachability threshold, so
// the strict-interior disjointness carries no non-vacuous
// witness here.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_high_support() {
assert!(
!slice.env_prefix_kinds_strict_partial_cover(),
"high-support chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_high_support_implies_env_prefix_kinds_any_observed_pointwise() {
// Subsumption pin: `env_prefix_kinds_high_support() ⇒
// env_prefix_kinds_any_observed()` on every axis with
// cardinality `>= 2`. High support has size `>= 2 >= 1`, so
// at least one cell was observed. The empty chain and every
// empty-histogram non-empty chain sit on the disjoint
// `!env_prefix_kinds_any_observed` boundary at the bottom of
// the magnitude interval — every high-support chain observes
// at least one env-prefix cell. Peer of
// `file_formats_high_support_implies_file_formats_any_observed_pointwise`
// on the file-format sub-axis,
// `layer_kinds_high_support_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis,
// `tiers_high_support_implies_tiers_any_observed_pointwise`
// on the tier altitude, and
// `kinds_high_support_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_high_support() {
assert!(
slice.env_prefix_kinds_any_observed(),
"high-support chain must observe at least one cell",
);
}
}
}
#[test]
fn env_prefix_kinds_full_cover_implies_env_prefix_kinds_high_support_pointwise() {
// Subsumption pin: `env_prefix_kinds_full_cover() ⇒
// env_prefix_kinds_high_support()` on every axis. The full-
// cover corner always sits inside the high-magnitude corner
// via the `is_full_cover()` disjunct on the bridge. Direct
// witness of the strict subsumption between the top coverage-
// support boundary and the top magnitude corner at the env-
// prefix sub-axis. Tightened on the two-cell env-prefix axis
// into an equivalence — pinned separately by
// `env_prefix_kinds_high_support_equivalent_to_env_prefix_kinds_full_cover_pointwise`
// one pin over. Peer of
// `file_formats_full_cover_implies_file_formats_high_support_pointwise`
// on the file-format sub-axis,
// `layer_kinds_full_cover_implies_layer_kinds_high_support_pointwise`
// on the layer-kind sub-axis,
// `tiers_full_cover_implies_tiers_high_support_pointwise`
// on the tier altitude, and
// `kinds_full_cover_implies_kinds_high_support_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_full_cover() {
assert!(
slice.env_prefix_kinds_high_support(),
"full-cover chain must be high-support",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_gap_negation_implies_by_high_support_disjointness_pointwise() {
// Cardinality-`2` two-cell-axis divergence pin: on the two-
// cell env-prefix axis the singular-gap boundary coincides
// with the singular-support boundary (the dual-singular-
// collapse), so the excision clause
// `!env_prefix_kinds_singular_support` in the defining
// disjunction excises the singular-gap disjunct — every
// singular-gap chain lands on the low-magnitude corner, not
// the high-magnitude corner. Direct witness of the *unique*
// two-cell-axis divergence from the general subsumption
// `singular_gap ⇒ high_support` (which holds on the
// cardinality-`>= 3` sub-axes
// [`Self::layer_kinds_high_support`] and
// [`Self::file_formats_high_support`]). Pins the disjointness
// `env_prefix_kinds_singular_gap() ⇒
// !env_prefix_kinds_high_support()` on this axis — the
// opposite polarity of the general subsumption at every
// cardinality-`>= 3` altitude / sub-axis in the projection.
// The env-prefix sub-axis carries the *unique* two-cell-axis
// divergence in the "high-support across altitudes"
// projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_gap() {
assert!(
!slice.env_prefix_kinds_high_support(),
"singular-gap chain must NOT be high-support on the two-cell env-prefix axis \
(dual-singular-collapse excision fires)",
);
}
}
}
#[test]
fn env_prefix_kinds_high_support_equivalent_to_env_prefix_kinds_full_cover_pointwise() {
// Cardinality-`2` two-cell-axis tightening pin:
// `env_prefix_kinds_high_support() ⇔
// env_prefix_kinds_full_cover()` on every fixture. Unique
// tightening of the general subsumption `full_cover ⇒
// high_support` (documented at every altitude / sub-axis) into
// an equivalence on the two-cell axis, since the singular-gap
// boundary coincides with the singular-support boundary and
// the excision clause excises the singular-gap disjunct — the
// high-magnitude corner exactly tracks the full-cover corner.
// Symmetric peer of
// `env_prefix_kinds_low_support_equivalent_to_not_env_prefix_kinds_full_cover_pointwise`
// on the opposite magnitude leg — both magnitude corners
// reduce to the full-cover / not-full-cover partition on the
// two-cell env-prefix axis. Cross-sub-axis divergence from
// `layer_kinds_full_cover_implies_layer_kinds_high_support_pointwise`
// and
// `file_formats_full_cover_implies_file_formats_high_support_pointwise`:
// the same equivalence does not lift to the cardinality-`3`
// layer-kind sub-axis (two-kind partial covers sit on the
// `high_support ∧ !full_cover` middle interval) or the
// cardinality-`4` file-format sub-axis (three-format partial
// covers sit on the same middle interval).
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_high_support();
let via_full = slice.env_prefix_kinds_full_cover();
assert_eq!(
via_seam, via_full,
"env_prefix_kinds_high_support ({via_seam}) must equal \
env_prefix_kinds_full_cover ({via_full}) on the two-cell axis",
);
}
}
#[test]
fn env_prefix_kinds_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise()
{
// Ternary partition pin: `(env_prefix_kinds_low_support,
// env_prefix_kinds_strict_partial_cover,
// env_prefix_kinds_high_support)` is a strict partition on
// every axis with cardinality `>= 2` (every env-prefix
// implementor today). Exactly one leg fires on every chain —
// the magnitude-direction ternary of the 5-corner support-
// cardinality partition, folding the two singular-cardinality
// boundaries into the two magnitude corners and naming the
// boundary-free strict interior separately. At the env-prefix
// sub-axis the middle leg is vacuously `false` on the
// cardinality-`2` axis (the strict-interior interval `[2, 0]`
// is empty), so the ternary degenerates to the dual partition
// `(low_support, high_support)` — matching the layer-kind sub-
// axis and the diff altitude on their cardinality-`3` axes
// where the middle leg is also vacuously empty, and diverging
// from the tier altitude and the file-format sub-axis where
// the cardinality-`4` axis inhabits every leg. Peer of
// `file_formats_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise`
// on the file-format sub-axis,
// `layer_kinds_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise`
// on the layer-kind sub-axis,
// `tiers_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise`
// on the tier altitude, and
// `kinds_low_support_strict_partial_cover_high_support_form_ternary_partition_pointwise`
// on the diff altitude, and of the trait-uniform pin
// `axis_histogram_has_low_support_has_strict_partial_cover_has_high_support_form_strict_ternary_partition_for_every_closed_axis_implementor`
// one altitude down.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let low = slice.env_prefix_kinds_low_support();
let mid = slice.env_prefix_kinds_strict_partial_cover();
let high = slice.env_prefix_kinds_high_support();
let count = usize::from(low) + usize::from(mid) + usize::from(high);
assert_eq!(
count, 1,
"exactly one of (low_support, strict_partial_cover, \
high_support) must fire (low={low}, mid={mid}, \
high={high})",
);
}
}
#[test]
fn env_prefix_kinds_high_support_agrees_with_open_coded_at_most_one_zero_walk() {
// Parity against the exact hand-rolled high-support walk this
// lift replaces on the two-cell env-prefix axis: walk every
// cell of the histogram and count how many carry a zero
// count; the high-support predicate reads `true` iff at most
// one cell is a zero *and* at least two cells are nonzero —
// on the cardinality-`2` axis the dual-singular-collapse
// excision is *load-bearing* here: at support size `1` there
// is exactly one zero cell (the `zeros <= 1` clause holds)
// but only one nonzero cell (the `nonzeros >= 2` clause
// fails), so the two clauses together excise the singleton-
// support / singleton-gap case. Mirrors the parity pin
// `env_prefix_kinds_low_support_agrees_with_open_coded_at_most_one_positive_walk`
// on the opposite magnitude leg. Peer of
// `file_formats_high_support_agrees_with_open_coded_at_most_one_zero_walk`
// on the file-format sub-axis,
// `layer_kinds_high_support_agrees_with_open_coded_at_most_one_zero_walk`
// on the layer-kind sub-axis,
// `tiers_high_support_agrees_with_open_coded_at_most_one_zero_walk`
// on the tier altitude, and
// `kinds_high_support_agrees_with_open_coded_at_most_one_zero_walk`
// on the diff altitude, closing the parity discipline at the
// fifth and final altitude / sub-axis in the "high-support
// across altitudes" projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_high_support();
let hist = slice.env_prefix_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros <= 1 && nonzeros >= 2;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_singular — singular-
// near-boundary boolean predicate on the env-prefix sub-axis
// of the chain altitude, closing the "singular across
// altitudes" projection at the fifth and final altitude /
// sub-axis. On the cardinality-`2` `EnvMetadataTagKind` axis
// the distance-from-boundary ternary degenerates to the dual
// partition and the two singular boundaries coincide (the
// dual-singular-collapse). ──
#[test]
fn env_prefix_kinds_singular_matches_env_prefix_kind_histogram_has_singular_pointwise() {
// Routing pin: `env_prefix_kinds_singular` routes through
// `env_prefix_kind_histogram().has_singular()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-
// prefix sub-axis peer of
// `file_formats_singular_matches_file_format_histogram_has_singular_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_matches_layer_kind_histogram_has_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_matches_tier_histogram_has_singular_pointwise`
// on the tier altitude, and
// `kinds_singular_matches_kind_histogram_has_singular_pointwise`
// on the diff altitude — closing the routing discipline at
// the fifth and final altitude / sub-axis in the "singular
// across altitudes" projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().has_singular();
assert_eq!(slice.env_prefix_kinds_singular(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_singular_matches_defining_union_of_singular_boundaries_pointwise() {
// Defining union-of-singular-boundaries form:
// `env_prefix_kinds_singular() ⇔
// env_prefix_kinds_singular_support() ||
// env_prefix_kinds_singular_gap()`. Pins the predicate against
// the two-way disjunction on two named histogram-side peers
// consumers reach for when they open-code the singular near-
// boundary corner as a boolean fold over the two singular-
// cardinality boundaries. On the cardinality-`2` env-prefix
// axis the two disjuncts coincide pointwise (the dual-
// singular-collapse `singular_support ⇔ singular_gap`) so the
// union reads `singular ⇔ singular_support ⇔ singular_gap` —
// the *unique* two-cell-axis three-way collapse in the
// projection. Peer of
// `file_formats_singular_matches_defining_union_of_singular_boundaries_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_matches_defining_union_of_singular_boundaries_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_matches_defining_union_of_singular_boundaries_pointwise`
// on the tier altitude, and
// `kinds_singular_matches_defining_union_of_singular_boundaries_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular();
let via_union =
slice.env_prefix_kinds_singular_support() || slice.env_prefix_kinds_singular_gap();
assert_eq!(
via_seam, via_union,
"env_prefix_kinds_singular ({via_seam}) must agree with \
env_prefix_kinds_singular_support || env_prefix_kinds_singular_gap ({via_union})",
);
}
}
#[test]
fn env_prefix_kinds_singular_agrees_with_any_observed_and_not_full_cover_on_cardinality_two_pointwise()
{
// Partial-cover-minus-strict-interior form reduced on the
// cardinality-`2` env-prefix axis: `env_prefix_kinds_singular()
// ⇔ env_prefix_kinds_any_observed() &&
// !env_prefix_kinds_full_cover()`. The strict interior of the
// env-prefix axis is *vacuously empty* (interval `[2,
// cardinality - 2] = [2, 0]`), so the middle-leg fold reads
// through the partial-cover slice without a strict-interior
// excision. Matches the layer-kind sub-axis's degenerate
// reduction on its cardinality-`3` axis and diverges from the
// tier altitude and file-format sub-axis which carry a load-
// bearing strict-interior excision on their cardinality-`4`
// axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular();
let via_slice =
slice.env_prefix_kinds_any_observed() && !slice.env_prefix_kinds_full_cover();
assert_eq!(
via_seam, via_slice,
"env_prefix_kinds_singular ({via_seam}) must agree with \
env_prefix_kinds_any_observed && !env_prefix_kinds_full_cover ({via_slice})",
);
}
}
#[test]
fn env_prefix_kinds_singular_agrees_with_any_observed_and_low_support_on_cardinality_two_pointwise()
{
// Cross-projection tightening on the cardinality-`2` env-
// prefix axis: `env_prefix_kinds_singular() ⇔
// env_prefix_kinds_any_observed() &&
// env_prefix_kinds_low_support()`. Folds the two-cell-axis
// equivalence `env_prefix_kinds_low_support ⇔
// !env_prefix_kinds_full_cover` through the reduced form
// above, reading the singular near-boundary corner off the
// magnitude-direction ternary's bottom leg on this sub-axis.
// The *unique* two-cell-axis cross-projection tightening
// between the distance-from-boundary and magnitude-direction
// ternaries, unavailable at any cardinality-`>= 3` altitude /
// sub-axis where the strict interior separates the
// `low_support ∧ !full_cover` middle from the singular near-
// boundary corner.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular();
let via_slice =
slice.env_prefix_kinds_any_observed() && slice.env_prefix_kinds_low_support();
assert_eq!(
via_seam, via_slice,
"env_prefix_kinds_singular ({via_seam}) must agree with \
env_prefix_kinds_any_observed && env_prefix_kinds_low_support ({via_slice})",
);
}
}
#[test]
fn env_prefix_kinds_singular_agrees_with_present_env_prefix_kinds_count_dual_equality_pointwise()
{
// Support-scalar dual-equality surface:
// `env_prefix_kinds_singular() ==
// (present_env_prefix_kinds_count() == 1 ||
// present_env_prefix_kinds_count() ==
// axis_cardinality::<crate::EnvMetadataTagKind>() - 1)` on
// every fixture. The support-side surfacing of the same
// boolean, without allocating either
// `Vec<crate::EnvMetadataTagKind>`. On the cardinality-`2`
// env-prefix axis the two thresholds coincide `1 == 1 =
// cardinality - 1` and the disjunction reads the same scalar
// equality twice — the *unique* two-cell-axis collapse of
// the dual-equality form onto a single equality. Peer of
// `file_formats_singular_agrees_with_present_file_formats_count_dual_equality_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_agrees_with_present_layer_kinds_count_dual_equality_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_agrees_with_contributing_tiers_count_dual_equality_pointwise`
// on the tier altitude, and
// `kinds_singular_agrees_with_present_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular();
let support = slice.present_env_prefix_kinds_count();
let via_scalar = support == 1
|| support == crate::axis_cardinality::<crate::EnvMetadataTagKind>() - 1;
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_singular ({via_seam}) must agree with \
present_env_prefix_kinds_count == 1 || present_env_prefix_kinds_count == cardinality - 1 \
({via_scalar}, support={support})",
);
}
}
#[test]
fn env_prefix_kinds_singular_agrees_with_present_and_absent_env_prefix_kinds_count_dual_equality_pointwise()
{
// Dual-scalar equality surface: `env_prefix_kinds_singular()
// == (present_env_prefix_kinds_count() == 1 ||
// absent_env_prefix_kinds_count() == 1)` on every fixture. The
// `present + absent == axis_cardinality` invariant restated on
// the two named cardinality peers, without allocating either
// `Vec<crate::EnvMetadataTagKind>`. On the cardinality-`2`
// env-prefix axis the two disjuncts coincide pointwise
// (`present == 1 ⇔ absent == 1` via the invariant). Peer of
// the histogram-side dual-scalar equality form
// `hist.distinct_cells() == 1 || hist.unobserved_cells() == 1`
// pinned one altitude down. Peer of
// `file_formats_singular_agrees_with_present_and_absent_file_formats_count_dual_equality_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_agrees_with_present_and_absent_layer_kinds_count_dual_equality_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_agrees_with_contributing_and_absent_tiers_count_dual_equality_pointwise`
// on the tier altitude, and
// `kinds_singular_agrees_with_present_and_absent_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular();
let support = slice.present_env_prefix_kinds_count();
let gap = slice.absent_env_prefix_kinds_count();
let via_scalar = support == 1 || gap == 1;
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_singular ({via_seam}) must agree with \
present_env_prefix_kinds_count == 1 || absent_env_prefix_kinds_count == 1 \
({via_scalar}, support={support}, gap={gap})",
);
}
}
#[test]
fn env_prefix_kinds_singular_dual_singular_collapse_pointwise() {
// Two-cell-axis dual-singular-collapse pin: on the
// cardinality-`2` env-prefix axis
// `env_prefix_kinds_singular_support ⇔
// env_prefix_kinds_singular_gap ⇔
// env_prefix_kinds_singular` — the three predicates coincide
// pointwise. Direct witness of the *unique* two-cell-axis
// three-way collapse in the projection: the two singular
// boundaries themselves coincide (support cardinalities `1`
// and `axis_cardinality - 1 = 1` are the same), so the
// defining union of the two singular disjuncts reduces to
// each disjunct individually. Does NOT lift to the
// cardinality-`>= 3` sub-axes where singular-support and
// singular-gap are strictly disjoint.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let sup = slice.env_prefix_kinds_singular_support();
let gap = slice.env_prefix_kinds_singular_gap();
let sing = slice.env_prefix_kinds_singular();
assert_eq!(
sup, gap,
"on cardinality-2 axis singular_support ({sup}) must \
coincide with singular_gap ({gap})",
);
assert_eq!(
sing, sup,
"on cardinality-2 axis singular ({sing}) must coincide \
with singular_support ({sup})",
);
}
}
#[test]
fn env_prefix_kinds_singular_empty_chain_is_false() {
// Empty-chain boundary: the empty chain observes zero cells,
// so every cell is unobserved (two zeros on the cardinality-
// `2` axis) — neither `env_prefix_kinds_singular_support`
// (nonzeros `== 1`) nor `env_prefix_kinds_singular_gap`
// (zeros `== 1`) fires. `env_prefix_kinds_singular` reads
// `false`. Matches `has_singular` reading `false` on the
// empty histogram one altitude down for every cardinality-
// `>= 2` axis. The empty chain sits on the disjoint bottom
// coverage boundary of the distance-from-boundary ternary
// partition, carried by `has_boundary` (via
// `!env_prefix_kinds_any_observed`) instead. Peer of
// `file_formats_singular_empty_chain_is_false` on the file-
// format sub-axis and `layer_kinds_singular_empty_chain_is_false`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_empty_map_is_false` on the tier altitude,
// and `kinds_singular_empty_diff_is_false` on the diff
// altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_singular());
assert!(!empty.env_prefix_kinds_any_observed());
assert!(!empty.env_prefix_kinds_singular_support());
assert!(!empty.env_prefix_kinds_singular_gap());
}
#[test]
fn env_prefix_kinds_singular_no_env_layers_is_false() {
// Non-empty-chain / empty-histogram boundary the env-prefix
// sub-axis pins that the layer-kind sub-axis does *not*. A
// chain of only `Defaults` / `File` layers is non-empty but
// has no `Some` env-prefix projection, so the histogram is
// empty (two zeros on the cardinality-`2` axis) — neither
// `env_prefix_kinds_singular_support` nor
// `env_prefix_kinds_singular_gap` fires and
// `env_prefix_kinds_singular` reads `false`. Cross-sub-axis
// divergence pin against `layer_kinds_singular`: on the same
// fixtures the layer-kind sub-axis observes at least one
// layer-kind cell (Defaults / File) so the singular near-
// boundary corner can fire there, but the env-prefix sub-
// axis's narrower singular corner does not. Matches
// `file_formats_singular_no_recognized_files_is_false` on the
// file-format sub-axis pattern for empty-histogram non-empty-
// chain fixtures.
let fixtures: [Vec<ConfigSource>; 3] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(slice.env_prefix_kind_histogram().is_empty());
assert!(!slice.env_prefix_kinds_any_observed());
assert!(!slice.env_prefix_kinds_singular());
assert!(!slice.env_prefix_kinds_singular_support());
assert!(!slice.env_prefix_kinds_singular_gap());
}
}
#[test]
fn env_prefix_kinds_singular_prefixed_only_is_true() {
// Singleton-support (prefixed-only) pin: a chain of only
// prefixed env layers observes the single
// `EnvMetadataTagKind::Prefixed` cell, so the support
// cardinality is `1` (one unobserved cell — `Bare` — on the
// cardinality-`2` axis). On the cardinality-`2` env-prefix
// axis BOTH `env_prefix_kinds_singular_support` AND
// `env_prefix_kinds_singular_gap` fire (the dual-singular-
// collapse), so `env_prefix_kinds_singular` reads `true`.
// Direct witness of BOTH direction subsumptions
// `env_prefix_kinds_singular_support ⇒
// env_prefix_kinds_singular` and
// `env_prefix_kinds_singular_gap ⇒
// env_prefix_kinds_singular` simultaneously on the same
// fixture — the two subsumptions coincide pointwise on the
// cardinality-`2` env-prefix axis.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_singular_gap());
assert!(slice.env_prefix_kinds_singular());
}
#[test]
fn env_prefix_kinds_singular_bare_only_is_true() {
// Singleton-support (bare-only) pin — the dual of the
// prefixed-only pin above: a chain of only bare env layers
// observes the single `EnvMetadataTagKind::Bare` cell, so
// the support cardinality is `1` (one unobserved cell —
// `Prefixed` — on the cardinality-`2` axis). On the
// cardinality-`2` env-prefix axis BOTH
// `env_prefix_kinds_singular_support` AND
// `env_prefix_kinds_singular_gap` fire (the dual-singular-
// collapse), so `env_prefix_kinds_singular` reads `true`.
// Pins both bare and prefixed sides of the singleton-
// support fixture as witnesses of the singular near-
// boundary corner on this sub-axis.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_singular_gap());
assert!(slice.env_prefix_kinds_singular());
}
#[test]
fn env_prefix_kinds_singular_sample_chain_is_true() {
// Singleton-support (sample-chain) pin: `sample_chain`
// carries two `.yaml` file layers plus one prefixed env
// layer, so the env-prefix histogram observes only the
// `Prefixed` cell — support cardinality `1` (one unobserved
// cell on the cardinality-`2` axis). Both singular boundaries
// fire (the dual-singular-collapse) and
// `env_prefix_kinds_singular` reads `true`. Reuses the
// canonical sample fixture to keep this pin in lockstep with
// the singleton-support pins on
// `env_prefix_kinds_singular_support` and
// `env_prefix_kinds_singular_gap` at the same test fixture.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_singular_gap());
assert!(slice.env_prefix_kinds_singular());
}
#[test]
fn env_prefix_kinds_singular_uniform_cover_is_false() {
// Uniform-cover pin: every `EnvMetadataTagKind` cell
// contributes at least one env layer, so the support
// cardinality is `2` (no unobserved cells on the cardinality-
// `2` axis) — `env_prefix_kinds_singular_gap` fails (`zeros
// == 0 ≠ 1`) and `env_prefix_kinds_singular_support` fails
// (`nonzeros == 2 ≠ 1`). `env_prefix_kinds_singular` reads
// `false`. The full-cover boundary sits at the top of the
// coverage interval, one of the two boundary corners carried
// by `has_boundary` (via `env_prefix_kinds_full_cover`) in
// the distance ternary — disjoint from the singular near-
// boundary corner. Peer of
// `file_formats_singular_uniform_cover_is_false` on the file-
// format sub-axis and `layer_kinds_singular_uniform_cover_is_false`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_uniform_cover_is_false` on the tier
// altitude, and `kinds_singular_uniform_cover_is_false` on
// the diff altitude.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kinds_full_cover());
assert!(!slice.env_prefix_kinds_singular());
}
#[test]
fn env_prefix_kinds_singular_support_implies_env_prefix_kinds_singular_pointwise() {
// Subsumption pin: `env_prefix_kinds_singular_support() ⇒
// env_prefix_kinds_singular()` on every axis via the
// `env_prefix_kinds_singular_support` disjunct of the defining
// union. The singleton-support boundary always sits inside
// the singular near-boundary corner. Direct witness of one
// leg of the union bridge. Tightened on the cardinality-`2`
// env-prefix axis into the equivalence
// `env_prefix_kinds_singular_support ⇔
// env_prefix_kinds_singular` by the dual-singular-collapse.
// Peer of
// `file_formats_singular_support_implies_file_formats_singular_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_support_implies_layer_kinds_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_support_implies_tiers_singular_pointwise`
// on the tier altitude, and
// `kinds_singular_support_implies_kinds_singular_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_support() {
assert!(
slice.env_prefix_kinds_singular(),
"singular-support chain must be singular",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_gap_implies_env_prefix_kinds_singular_pointwise() {
// Subsumption pin: `env_prefix_kinds_singular_gap() ⇒
// env_prefix_kinds_singular()` on every axis via the
// `env_prefix_kinds_singular_gap` disjunct of the defining
// union. The singleton-gap boundary always sits inside the
// singular near-boundary corner. Direct witness of the other
// leg of the union bridge. Tightened on the cardinality-`2`
// env-prefix axis into the equivalence
// `env_prefix_kinds_singular_gap ⇔
// env_prefix_kinds_singular` by the dual-singular-collapse.
// Peer of
// `file_formats_singular_gap_implies_file_formats_singular_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_gap_implies_layer_kinds_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_gap_implies_tiers_singular_pointwise` on
// the tier altitude, and
// `kinds_singular_gap_implies_kinds_singular_pointwise` on
// the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular_gap() {
assert!(
slice.env_prefix_kinds_singular(),
"singular-gap chain must be singular",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_implies_env_prefix_kinds_any_observed_pointwise() {
// Subsumption pin: `env_prefix_kinds_singular() ⇒
// env_prefix_kinds_any_observed()` on every axis with
// cardinality `>= 2`. Both disjuncts require at least one
// observed cell (`singular_support` has nonzeros `>= 1`;
// `singular_gap` has nonzeros `= cardinality - 1 >= 1`). The
// empty chain AND every empty-histogram non-empty chain sit
// on the disjoint `!env_prefix_kinds_any_observed` boundary
// at the bottom coverage boundary — every singular chain
// observes at least one env-prefix cell. Peer of
// `file_formats_singular_implies_file_formats_any_observed_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_implies_tiers_any_observed_pointwise` on
// the tier altitude, and
// `kinds_singular_implies_kinds_any_observed_pointwise` on
// the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular() {
assert!(
slice.env_prefix_kinds_any_observed(),
"singular chain must observe at least one cell",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_implies_not_env_prefix_kinds_full_cover_pointwise() {
// Disjointness pin: `env_prefix_kinds_singular() ⇒
// !env_prefix_kinds_full_cover()` on every axis with
// cardinality `>= 2`. `env_prefix_kinds_singular_support`
// has support `1 < cardinality`;
// `env_prefix_kinds_singular_gap` has support `cardinality
// - 1 < cardinality`. The full-cover corner sits at the top
// coverage boundary — one of the two boundary corners
// disjoint from the singular near-boundary corner. Peer of
// `file_formats_singular_implies_not_file_formats_full_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_implies_not_tiers_full_cover_pointwise` on
// the tier altitude, and
// `kinds_singular_implies_not_kinds_full_cover_pointwise` on
// the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular() {
assert!(
!slice.env_prefix_kinds_full_cover(),
"singular chain cannot be full-cover on a \
cardinality >= 2 axis",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_implies_not_env_prefix_kinds_strict_partial_cover_pointwise() {
// Disjointness pin: `env_prefix_kinds_singular() ⇒
// !env_prefix_kinds_strict_partial_cover()` always. The two
// named corners of the distance-from-boundary ternary
// partition are pairwise disjoint. On the cardinality-`2`
// `EnvMetadataTagKind` axis this holds *vacuously* — the
// strict interior is structurally empty (the strict interval
// `[2, cardinality - 2] = [2, 0]` is empty), so
// `!env_prefix_kinds_strict_partial_cover` reads `true` on
// every chain regardless of `env_prefix_kinds_singular`. The
// env-prefix sub-axis carries the *tightest* vacuously-true
// consequent in the projection — two cardinality steps below
// the reachability threshold, matching the layer-kind sub-
// axis's and the diff altitude's vacuously-`true` consequent
// on their cardinality-`3` axes (one cardinality step below
// the threshold) and diverging from the tier altitude's and
// the file-format sub-axis's non-vacuous consequent on their
// cardinality-`4` axes. Peer of
// `file_formats_singular_implies_not_file_formats_strict_partial_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_singular_implies_not_kinds_strict_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular() {
assert!(
!slice.env_prefix_kinds_strict_partial_cover(),
"singular chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_implies_env_prefix_kinds_low_support_on_cardinality_two_pointwise()
{
// Two-cell-axis cross-projection subsumption pin:
// `env_prefix_kinds_singular() ⇒
// env_prefix_kinds_low_support()` on the cardinality-`2`
// env-prefix axis by folding the equivalence
// `env_prefix_kinds_singular ⇔ (env_prefix_kinds_any_observed
// && env_prefix_kinds_low_support)` through the low-support
// conjunct. The *unique* two-cell-axis cross-projection
// subsumption between the distance-from-boundary and
// magnitude-direction ternaries — every singular chain lands
// on the low-magnitude corner of the parallel magnitude
// partition on this sub-axis. Does NOT lift to the
// cardinality-`>= 3` sub-axes where the singleton-gap
// boundary sits on the `high_support` side of the magnitude
// partition (support cardinality `axis_cardinality - 1 >= 2`)
// and the singular near-boundary corner spans both magnitude
// legs.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular() {
assert!(
slice.env_prefix_kinds_low_support(),
"singular chain must land on low-support on the \
cardinality-2 env-prefix axis",
);
}
}
}
#[test]
fn env_prefix_kinds_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise() {
// Ternary partition pin at the chain env-prefix sub-axis:
// exactly one of the three legs
// `(!env_prefix_kinds_any_observed ||
// env_prefix_kinds_full_cover,
// env_prefix_kinds_singular,
// env_prefix_kinds_strict_partial_cover)`
// fires on every chain — the distance-from-boundary ternary
// of the 5-corner support-cardinality partition, folding the
// two boundary corners (empty/empty-histogram and full-cover)
// into `has_boundary`, the two singular near-boundary corners
// into `has_singular`, and the boundary-free strict interior
// into `has_strict_partial_cover`. On the cardinality-`2`
// `EnvMetadataTagKind` axis the third leg is vacuously empty
// and the ternary degenerates to the dual partition
// `(has_boundary, has_singular)` pointwise — the *tightest*
// degenerate distance ternary in the projection, matching
// the layer-kind sub-axis's and the diff altitude's
// degenerate two-way partition on their cardinality-`3` axes
// and diverging from the tier altitude's and the file-format
// sub-axis's non-vacuous three-leg partition on their
// cardinality-`4` axes. Peer of the trait-uniform pin
// `axis_histogram_has_boundary_has_singular_has_strict_partial_cover_form_strict_ternary_partition_for_every_closed_axis_implementor`
// one altitude down, of
// `file_formats_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise`
// on the tier altitude, and
// `kinds_boundary_and_kinds_singular_and_kinds_strict_partial_cover_form_ternary_partition_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let boundary =
!slice.env_prefix_kinds_any_observed() || slice.env_prefix_kinds_full_cover();
let singular = slice.env_prefix_kinds_singular();
let strict = slice.env_prefix_kinds_strict_partial_cover();
let count = usize::from(boundary) + usize::from(singular) + usize::from(strict);
assert_eq!(
count, 1,
"exactly one of (boundary, singular, strict_partial_cover) \
must fire (boundary={boundary}, singular={singular}, \
strict={strict})",
);
}
}
#[test]
fn env_prefix_kinds_singular_bridges_support_cardinality_class_is_singular_pointwise() {
// Cross-surface bridge law: `env_prefix_kinds_singular() ==
// env_prefix_kind_histogram().support_cardinality_class().is_singular()`
// on every fixture. The class-side projection lands on
// `SupportCardinalityClass::SingularSupport` or
// `SupportCardinalityClass::SingularGap` exactly when the
// histogram-side disjunction fires, and
// `SupportCardinalityClass::is_singular` reads `true` on
// either variant. Peer of the histogram-side bridge
// `axis_histogram_has_singular_agrees_with_class_is_singular_for_every_closed_axis_implementor`
// one altitude down, closing the (histogram, class) duality
// on the singular near-boundary leg at the chain env-prefix
// sub-axis. Peer of
// `file_formats_singular_bridges_support_cardinality_class_is_singular_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_bridges_support_cardinality_class_is_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_bridges_support_cardinality_class_is_singular_pointwise`
// on the tier altitude, and
// `kinds_singular_bridges_support_cardinality_class_is_singular_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular();
let via_class = slice
.env_prefix_kind_histogram()
.support_cardinality_class()
.is_singular();
assert_eq!(
via_seam, via_class,
"env_prefix_kinds_singular ({via_seam}) must agree with \
env_prefix_kind_histogram().support_cardinality_class().is_singular() \
({via_class})",
);
}
}
#[test]
fn env_prefix_kinds_singular_agrees_with_open_coded_singular_boundary_walk() {
// Parity against the exact hand-rolled singular walk this
// lift replaces on cardinality-`>= 2` axes: walk every cell
// of the histogram and count how many carry a zero count
// and how many carry a nonzero count; the singular predicate
// reads `true` iff exactly one cell is nonzero (singular
// support) or exactly one cell is a zero (singular gap). On
// the cardinality-`2` env-prefix axis the two conditions
// coincide pointwise (`nonzeros == 1 ⇔ zeros == 1` via the
// `nonzeros + zeros == 2` invariant), so the disjunction
// reads the same clause twice. Mirrors the parity pins
// `env_prefix_kinds_singular_support_agrees_with_open_coded_exactly_one_positive_walk`
// and `env_prefix_kinds_singular_gap_agrees_with_open_coded_exactly_one_zero_walk`
// on the two singular-cardinality boundaries the union folds.
// Peer of
// `file_formats_singular_agrees_with_open_coded_singular_boundary_walk`
// on the file-format sub-axis and
// `layer_kinds_singular_agrees_with_open_coded_singular_boundary_walk`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_agrees_with_open_coded_singular_boundary_walk`
// on the tier altitude, and
// `kinds_singular_agrees_with_open_coded_singular_boundary_walk`
// on the diff altitude — closing the parity discipline at
// the fifth and final altitude / sub-axis in the "singular
// across altitudes" projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_singular();
let hist = slice.env_prefix_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = nonzeros == 1 || zeros == 1;
assert_eq!(via_seam, hand_rolled);
}
}
// ── env_prefix_kinds_boundary coverage — the boundary-env-prefix-
// kinds top-leg corner of the distance-from-boundary ternary
// partition `(has_boundary, has_singular, has_strict_partial_cover)`
// at the chain env-prefix sub-axis, closing the "boundary across
// altitudes" projection at the fifth and final altitude / sub-axis.
// On the cardinality-`2` `EnvMetadataTagKind` axis the distance
// ternary degenerates to the dual partition and the two
// boundary-and-singular corners exhaust the fixture space
// pointwise. The env-prefix projection is a partial function, so
// the empty-histogram disjunct fires on every no-env-layers non-
// empty-chain fixture as well as on the truly empty chain.
// ──
#[test]
fn env_prefix_kinds_boundary_matches_env_prefix_kind_histogram_has_boundary_pointwise() {
// Routing pin: `env_prefix_kinds_boundary` routes through
// `env_prefix_kind_histogram().has_boundary()`, so the two seams
// must stay pointwise equivalent under every fixture. Catches
// any future drift where either implementation stops projecting
// through the shared cube-native primitive. Env-prefix sub-axis
// peer of
// `file_formats_boundary_matches_file_format_histogram_has_boundary_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_matches_layer_kind_histogram_has_boundary_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_matches_tier_histogram_has_boundary_pointwise`
// on the tier altitude, and
// `kinds_boundary_matches_kind_histogram_has_boundary_pointwise`
// on the diff altitude — closing the routing discipline at the
// fifth and final altitude / sub-axis in the "boundary across
// altitudes" projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().has_boundary();
assert_eq!(slice.env_prefix_kinds_boundary(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_boundary_matches_defining_union_of_coverage_boundaries_pointwise() {
// Defining union-of-coverage-boundaries form:
// `env_prefix_kinds_boundary() ⇔ !env_prefix_kinds_any_observed()
// || env_prefix_kinds_full_cover()`. Pins the predicate against
// the two-way disjunction on the two named coverage-boundary
// peers consumers reach for when they open-code the boundary
// corner as a boolean fold over the two extreme coverage
// cardinalities. Peer of
// `file_formats_boundary_matches_defining_union_of_coverage_boundaries_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_matches_defining_union_of_coverage_boundaries_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_matches_defining_union_of_coverage_boundaries_pointwise`
// on the tier altitude, and
// `kinds_boundary_matches_defining_union_of_coverage_boundaries_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_boundary();
let via_union =
!slice.env_prefix_kinds_any_observed() || slice.env_prefix_kinds_full_cover();
assert_eq!(
via_seam, via_union,
"env_prefix_kinds_boundary ({via_seam}) must agree with \
!env_prefix_kinds_any_observed || env_prefix_kinds_full_cover ({via_union})",
);
}
}
#[test]
fn env_prefix_kinds_boundary_agrees_with_present_env_prefix_kinds_count_dual_equality_pointwise()
{
// Support-scalar dual-equality surface:
// `env_prefix_kinds_boundary() ==
// (present_env_prefix_kinds_count() == 0 ||
// present_env_prefix_kinds_count() ==
// axis_cardinality::<crate::EnvMetadataTagKind>())` on every
// fixture. The support-side surfacing of the same boolean,
// without allocating either `Vec<crate::EnvMetadataTagKind>`.
// The two equalities are strictly disjoint (`0 != 2 =
// cardinality` on the env-prefix axis). Peer of
// `file_formats_boundary_agrees_with_present_file_formats_count_dual_equality_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_agrees_with_present_layer_kinds_count_dual_equality_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_agrees_with_contributing_tiers_count_dual_equality_pointwise`
// on the tier altitude, and
// `kinds_boundary_agrees_with_present_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_boundary();
let support = slice.present_env_prefix_kinds_count();
let via_scalar =
support == 0 || support == crate::axis_cardinality::<crate::EnvMetadataTagKind>();
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_boundary ({via_seam}) must agree with \
present_env_prefix_kinds_count == 0 || present_env_prefix_kinds_count == cardinality \
({via_scalar}, support={support})",
);
}
}
#[test]
fn env_prefix_kinds_boundary_agrees_with_present_and_absent_env_prefix_kinds_count_dual_equality_pointwise()
{
// Dual-scalar equality surface: `env_prefix_kinds_boundary() ==
// (present_env_prefix_kinds_count() == 0 ||
// absent_env_prefix_kinds_count() == 0)` on every fixture. The
// `present + absent == axis_cardinality` invariant restated on
// the two named cardinality peers, without allocating either
// `Vec<crate::EnvMetadataTagKind>`. Peer of the histogram-side
// dual-scalar equality form `hist.distinct_cells() == 0 ||
// hist.unobserved_cells() == 0` pinned one altitude down. Peer
// of
// `file_formats_boundary_agrees_with_present_and_absent_file_formats_count_dual_equality_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_agrees_with_present_and_absent_layer_kinds_count_dual_equality_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_agrees_with_contributing_and_absent_tiers_count_dual_equality_pointwise`
// on the tier altitude, and
// `kinds_boundary_agrees_with_present_and_absent_kinds_count_dual_equality_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_boundary();
let support = slice.present_env_prefix_kinds_count();
let gap = slice.absent_env_prefix_kinds_count();
let via_scalar = support == 0 || gap == 0;
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_boundary ({via_seam}) must agree with \
present_env_prefix_kinds_count == 0 || absent_env_prefix_kinds_count == 0 \
({via_scalar}, support={support}, gap={gap})",
);
}
}
#[test]
fn env_prefix_kinds_boundary_empty_chain_is_true() {
// Empty-chain boundary: the empty chain observes zero cells, so
// every cell is unobserved (two zeros on the cardinality-`2`
// axis) — the scan sees no nonzero cell and falls through to
// `true`. `env_prefix_kinds_boundary` reads `true`. Matches
// `has_boundary` reading `true` on the empty histogram one
// altitude down. Direct witness of the subsumption
// `!env_prefix_kinds_any_observed ⇒ env_prefix_kinds_boundary`
// via the empty-chain disjunct. Peer of
// `file_formats_boundary_empty_chain_is_true` on the file-format
// sub-axis and `layer_kinds_boundary_empty_chain_is_true` on
// the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_empty_map_is_true` on the tier altitude, and
// `kinds_boundary_empty_diff_is_true` on the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.env_prefix_kinds_boundary());
assert!(!empty.env_prefix_kinds_any_observed());
}
#[test]
fn env_prefix_kinds_boundary_no_env_layers_is_true() {
// Non-empty-chain / empty-histogram boundary the env-prefix sub-
// axis pins that the layer-kind sub-axis does *not*. A chain of
// only `Defaults` / `File` layers is non-empty but has no `Some`
// env-prefix projection, so the histogram is empty (two zeros on
// the cardinality-`2` axis) — the scan sees no nonzero cell and
// falls through to `true`. `env_prefix_kinds_boundary` reads
// `true` via the empty-histogram disjunct. Cross-sub-axis
// divergence pin against `layer_kinds_boundary`: on the same
// fixtures the layer-kind sub-axis observes at least one layer-
// kind cell (Defaults / File) with partial support, so
// `layer_kinds_boundary` typically reads `false` — the narrower
// env-prefix boundary still fires via the partial-function
// projection's empty-histogram case. Matches
// `file_formats_boundary_no_recognized_files_is_true` on the
// file-format sub-axis pattern for empty-histogram non-empty-
// chain fixtures. Peer of
// `env_prefix_kinds_singular_no_env_layers_is_false` via the
// disjoint-corner relationship — the singular near-boundary
// corner does not fire on the same fixture that sits on the
// boundary corner.
let fixtures: [Vec<ConfigSource>; 3] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(slice.env_prefix_kind_histogram().is_empty());
assert!(!slice.env_prefix_kinds_any_observed());
assert!(slice.env_prefix_kinds_boundary());
}
}
#[test]
fn env_prefix_kinds_boundary_singleton_support_is_false() {
// Singleton-support pin: `sample_chain()` observes only
// `Prefixed` (two `.yaml` file layers + one prefixed env layer),
// so the env-prefix support cardinality is `1` (one nonzero and
// one zero on the cardinality-`2` axis) — the scan sees a
// nonzero cell *and* a zero cell and returns `false`.
// `env_prefix_kinds_boundary` reads `false`. Direct witness of
// the disjointness `env_prefix_kinds_singular ⇒
// !env_prefix_kinds_boundary` via the mixed-parity witness. On
// the cardinality-`2` axis the singleton-support boundary IS
// the singular near-boundary corner (the dual-singular-collapse
// `singular_support ⇔ singular_gap`), so this fixture also
// witnesses `env_prefix_kinds_singular = true`. Peer of
// `file_formats_boundary_singleton_support_is_false` on the
// file-format sub-axis and
// `layer_kinds_boundary_singleton_support_is_false` on the
// layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_singleton_support_is_false` on the tier
// altitude, and `kinds_boundary_singleton_support_is_false` on
// the diff altitude.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(!slice.env_prefix_kinds_boundary());
assert!(slice.env_prefix_kinds_singular());
}
#[test]
fn env_prefix_kinds_boundary_uniform_cover_is_true() {
// Uniform-cover pin: every `EnvMetadataTagKind` cell contributes
// at least one env layer, so the support cardinality is `2` (no
// unobserved cells on the cardinality-`2` axis) — the scan sees
// only nonzero cells and falls through to `true`.
// `env_prefix_kinds_boundary` reads `true`. Direct witness of
// the subsumption `env_prefix_kinds_full_cover ⇒
// env_prefix_kinds_boundary` via the full-cover disjunct. Peer
// of `file_formats_boundary_uniform_cover_is_true` on the file-
// format sub-axis and `layer_kinds_boundary_uniform_cover_is_true`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_uniform_cover_is_true` on the tier altitude,
// and `kinds_boundary_uniform_cover_is_true` on the diff
// altitude.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kinds_full_cover());
assert!(slice.env_prefix_kinds_boundary());
}
#[test]
fn env_prefix_kinds_not_any_observed_implies_env_prefix_kinds_boundary_pointwise() {
// Subsumption pin: `!env_prefix_kinds_any_observed() ⇒
// env_prefix_kinds_boundary()` always via the bottom-boundary
// disjunct of the defining union. The empty chain AND every
// empty-histogram non-empty chain (no-env-layers) sit inside
// the boundary corner. Peer of
// `file_formats_not_any_observed_implies_file_formats_boundary_pointwise`
// on the file-format sub-axis and
// `layer_kinds_not_any_observed_implies_layer_kinds_boundary_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_not_any_observed_implies_tiers_boundary_pointwise` on
// the tier altitude, and
// `kinds_not_any_observed_implies_kinds_boundary_pointwise` on
// the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if !slice.env_prefix_kinds_any_observed() {
assert!(
slice.env_prefix_kinds_boundary(),
"empty-histogram chain must be on boundary",
);
}
}
}
#[test]
fn env_prefix_kinds_full_cover_implies_env_prefix_kinds_boundary_pointwise() {
// Subsumption pin: `env_prefix_kinds_full_cover() ⇒
// env_prefix_kinds_boundary()` always via the top-boundary
// disjunct of the defining union. The full-cover chain always
// sits inside the boundary corner. Peer of
// `file_formats_full_cover_implies_file_formats_boundary_pointwise`
// on the file-format sub-axis and
// `layer_kinds_full_cover_implies_layer_kinds_boundary_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_full_cover_implies_tiers_boundary_pointwise` on the
// tier altitude, and
// `kinds_full_cover_implies_kinds_boundary_pointwise` on the
// diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_full_cover() {
assert!(
slice.env_prefix_kinds_boundary(),
"full-cover chain must be on boundary",
);
}
}
}
#[test]
fn env_prefix_kinds_boundary_implies_not_env_prefix_kinds_singular_pointwise() {
// Disjointness pin: `env_prefix_kinds_boundary() ⇒
// !env_prefix_kinds_singular()` on every axis with cardinality
// `>= 2`. The two boundary cardinalities (`0` and `cardinality`)
// sit strictly outside the two singular cardinalities (`1` and
// `cardinality - 1`) — the boundary corner and the singular
// near-boundary corner are pairwise disjoint legs of the
// distance ternary. Peer of
// `file_formats_boundary_implies_not_file_formats_singular_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_implies_not_layer_kinds_singular_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_implies_not_tiers_singular_pointwise` on the
// tier altitude, and
// `kinds_boundary_implies_not_kinds_singular_pointwise` on the
// diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_boundary() {
assert!(
!slice.env_prefix_kinds_singular(),
"boundary chain cannot be singular on a cardinality \
>= 2 axis",
);
}
}
}
#[test]
fn env_prefix_kinds_boundary_implies_not_env_prefix_kinds_strict_partial_cover_pointwise() {
// Disjointness pin: `env_prefix_kinds_boundary() ⇒
// !env_prefix_kinds_strict_partial_cover()` always. The strict-
// interior interval `[2, cardinality - 2]` never contains the
// two boundary cardinalities `0` and `cardinality` — the third
// pairwise-disjointness leg of the distance ternary. Holds
// *vacuously* on the cardinality-`2` env-prefix axis — the
// strict interior is structurally empty (the strict interval
// `[2, cardinality - 2] = [2, 0]` is empty), so
// `!env_prefix_kinds_strict_partial_cover` reads `true` on
// every chain regardless of `env_prefix_kinds_boundary`. The
// env-prefix sub-axis carries the *tightest* vacuously-true
// consequent in the projection — two cardinality steps below
// the reachability threshold, matching the layer-kind sub-
// axis's and the diff altitude's vacuously-`true` consequent
// on their cardinality-`3` axes and diverging from the tier
// altitude's and the file-format sub-axis's non-vacuous
// consequent on their cardinality-`4` axes. Peer of
// `file_formats_boundary_implies_not_file_formats_strict_partial_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_implies_not_layer_kinds_strict_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_implies_not_tiers_strict_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_boundary_implies_not_kinds_strict_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_boundary() {
assert!(
!slice.env_prefix_kinds_strict_partial_cover(),
"boundary chain cannot be strict-partial-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_boundary_env_prefix_kinds_singular_env_prefix_kinds_strict_partial_cover_form_ternary_partition_pointwise()
{
// Ternary partition pin at the chain env-prefix sub-axis via the
// named seam: exactly one of the three legs
// `(env_prefix_kinds_boundary, env_prefix_kinds_singular,
// env_prefix_kinds_strict_partial_cover)` fires on every chain —
// the distance-from-boundary ternary of the 5-corner support-
// cardinality partition. On the cardinality-`2`
// `EnvMetadataTagKind` axis the third leg is vacuously empty
// and the ternary degenerates pointwise to the dual
// `(env_prefix_kinds_boundary, env_prefix_kinds_singular)` —
// the *tightest* degenerate distance ternary in the projection,
// matching the layer-kind sub-axis and the diff altitude on
// their cardinality-`3` axes and diverging from the tier
// altitude and the file-format sub-axis where the cardinality-
// `4` axis inhabits every leg. The `env_prefix_kinds_boundary`
// seam now names the top leg of the ternary directly at the
// surface, replacing the open-coded `!env_prefix_kinds_any_observed
// || env_prefix_kinds_full_cover` disjunction used by the
// sibling
// `env_prefix_kinds_boundary_singular_strict_partial_cover_form_ternary_partition_pointwise`
// pin (still kept alongside as the open-coded parity witness).
// Peer of
// `file_formats_boundary_file_formats_singular_file_formats_strict_partial_cover_form_ternary_partition_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_layer_kinds_singular_layer_kinds_strict_partial_cover_form_ternary_partition_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_tiers_singular_tiers_strict_partial_cover_form_ternary_partition_pointwise`
// on the tier altitude, and
// `kinds_boundary_kinds_singular_kinds_strict_partial_cover_form_ternary_partition_pointwise`
// on the diff altitude — closing the "boundary across altitudes"
// named-seam partition discipline at the fifth and final
// altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let boundary = slice.env_prefix_kinds_boundary();
let singular = slice.env_prefix_kinds_singular();
let strict = slice.env_prefix_kinds_strict_partial_cover();
let count = usize::from(boundary) + usize::from(singular) + usize::from(strict);
assert_eq!(
count, 1,
"exactly one of (boundary, singular, strict_partial_cover) \
must fire (boundary={boundary}, singular={singular}, \
strict={strict})",
);
}
}
#[test]
fn env_prefix_kinds_boundary_and_env_prefix_kinds_partial_cover_form_strict_bipartition_pointwise()
{
// Strict-bipartition pin at the chain env-prefix sub-axis:
// `env_prefix_kinds_boundary` and its complement
// `env_prefix_kinds_any_observed && !env_prefix_kinds_full_cover`
// (the partial-cover strict interior at the env-prefix sub-
// axis) are pointwise complementary — exactly one fires on
// every chain. The named boundary corner is the exact
// complement of the partial-cover strict interior. Peer of the
// histogram-side bipartition law
// `axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`
// one altitude down,
// `file_formats_boundary_and_file_formats_partial_cover_form_strict_bipartition_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_and_layer_kinds_partial_cover_form_strict_bipartition_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_and_tiers_partial_cover_form_strict_bipartition_pointwise`
// on the tier altitude, and
// `kinds_boundary_and_kinds_partial_cover_form_strict_bipartition_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let boundary = slice.env_prefix_kinds_boundary();
let partial =
slice.env_prefix_kinds_any_observed() && !slice.env_prefix_kinds_full_cover();
let count = usize::from(boundary) + usize::from(partial);
assert_eq!(
count, 1,
"exactly one of (boundary, partial_cover) must fire \
(boundary={boundary}, partial={partial})",
);
}
}
#[test]
fn env_prefix_kinds_boundary_iff_not_env_prefix_kinds_singular_on_cardinality_two_pointwise() {
// Two-cell-axis boundary/singular exhaustion pin:
// `env_prefix_kinds_boundary ⇔ !env_prefix_kinds_singular` on
// the cardinality-`2` env-prefix axis. On this axis the strict
// interior of the distance ternary is structurally empty (the
// strict interval `[2, cardinality - 2] = [2, 0]` is empty), so
// the ternary degenerates to a bipartition and the boundary
// corner is exactly the complement of the singular near-
// boundary corner. The *unique* two-cell-axis collapse of the
// ternary partition onto a strict bipartition through the
// singular leg — the peer of the (structurally identical)
// collapse at the layer-kind sub-axis and the diff altitude on
// their cardinality-`3` axes (also degenerate through the
// vacuous strict interior). Does NOT lift to the cardinality-`4`
// sub-axes (tier altitude, file-format sub-axis) where the
// strict interior is reachable and every chain landing on the
// strict interior reads
// `boundary=false, singular=false, strict_partial_cover=true`.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let boundary = slice.env_prefix_kinds_boundary();
let singular = slice.env_prefix_kinds_singular();
assert_eq!(
boundary, !singular,
"on the cardinality-2 env-prefix axis boundary ({boundary}) \
must equal !singular ({singular})",
);
}
}
#[test]
fn env_prefix_kinds_boundary_bridges_support_cardinality_class_is_boundary_pointwise() {
// Cross-surface bridge law: `env_prefix_kinds_boundary() ==
// env_prefix_kind_histogram().support_cardinality_class().is_boundary()`
// on every fixture. The class-side projection lands on
// `SupportCardinalityClass::Empty` or
// `SupportCardinalityClass::FullCover` exactly when the
// histogram-side disjunction fires, and
// `SupportCardinalityClass::is_boundary` reads `true` on either
// variant. Peer of the histogram-side bridge
// `axis_histogram_has_boundary_agrees_with_class_is_boundary_for_every_closed_axis_implementor`
// one altitude down, closing the (histogram, class) duality on
// the boundary leg at the chain env-prefix sub-axis. Peer of
// `file_formats_boundary_bridges_support_cardinality_class_is_boundary_pointwise`
// on the file-format sub-axis and
// `layer_kinds_boundary_bridges_support_cardinality_class_is_boundary_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_bridges_support_cardinality_class_is_boundary_pointwise`
// on the tier altitude, and
// `kinds_boundary_bridges_support_cardinality_class_is_boundary_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_boundary();
let via_class = slice
.env_prefix_kind_histogram()
.support_cardinality_class()
.is_boundary();
assert_eq!(
via_seam, via_class,
"env_prefix_kinds_boundary ({via_seam}) must agree with \
env_prefix_kind_histogram().support_cardinality_class().is_boundary() \
({via_class})",
);
}
}
#[test]
fn env_prefix_kinds_boundary_agrees_with_open_coded_uniform_parity_walk() {
// Parity against the exact hand-rolled boundary walk this lift
// replaces on cardinality-`>= 1` axes: walk every cell of the
// histogram and count how many carry a zero count and how many
// carry a nonzero count; the boundary predicate reads `true`
// iff every cell is zero (empty) or every cell is nonzero (full
// cover) — i.e. not both a zero *and* a nonzero cell appear.
// Peer of
// `file_formats_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the file-format sub-axis and
// `layer_kinds_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the tier altitude, and
// `kinds_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the diff altitude — closing the parity discipline at the
// fifth and final altitude / sub-axis in the "boundary across
// altitudes" projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_boundary();
let hist = slice.env_prefix_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros == 0 || nonzeros == 0;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_partial_cover — partial-
// cover-env-prefix-kinds boolean predicate on the env-prefix
// sub-axis of the chain altitude, closing the "partial-cover
// across altitudes" projection at the fifth and final altitude
// / sub-axis. Cardinality-`2` reachability: singleton-support
// chains on the `true` side (the two singular near-boundary
// corners collapse onto one via the dual-singular-collapse);
// the empty chain, every empty-histogram non-empty chain, and
// every uniform two-kind cover on the `false` side. The
// strict-interior middle leg `env_prefix_kinds_strict_partial_cover`
// is vacuously empty here, so the coverage-trichotomy middle
// leg collapses onto the singular near-boundary corner —
// `partial_cover ⇔ singular` pointwise on this two-cell axis.
// Middle-leg peer of `env_prefix_kinds_boundary` /
// `layer_kinds_partial_cover` / `file_formats_partial_cover` /
// `tiers_partial_cover` / `kinds_partial_cover`. ──
#[test]
fn env_prefix_kinds_partial_cover_matches_env_prefix_kind_histogram_has_partial_cover_pointwise()
{
// Routing pin: `env_prefix_kinds_partial_cover` routes through
// `env_prefix_kind_histogram().has_partial_cover()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-
// prefix sub-axis peer of
// `file_formats_partial_cover_matches_file_format_histogram_has_partial_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_matches_layer_kind_histogram_has_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_matches_tier_histogram_has_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_matches_kind_histogram_has_partial_cover_pointwise`
// on the diff altitude, closing the "partial-cover across
// altitudes" projection across every altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().has_partial_cover();
assert_eq!(slice.env_prefix_kinds_partial_cover(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_partial_cover_matches_defining_conjunction_of_negations_pointwise() {
// Defining conjunction-of-negations form:
// `env_prefix_kinds_partial_cover() ⇔ env_prefix_kinds_any_observed() &&
// !env_prefix_kinds_full_cover()`. Pins the predicate against
// the two-way conjunction on the two named coverage-boundary
// peers consumers reach for when they open-code the middle-leg
// corner as a boolean fold over the two extreme coverage
// cardinalities. The middle-leg-fold peer of the two boundary
// corners — the exact expression used verbatim by the pre-
// existing bipartition-law pin
// `env_prefix_kinds_boundary_and_env_prefix_kinds_partial_cover_form_strict_bipartition_pointwise`.
// Peer of
// `file_formats_partial_cover_matches_defining_conjunction_of_negations_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_matches_defining_conjunction_of_negations_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_matches_defining_conjunction_of_negations_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_matches_defining_conjunction_of_negations_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_partial_cover();
let via_conjunction =
slice.env_prefix_kinds_any_observed() && !slice.env_prefix_kinds_full_cover();
assert_eq!(
via_seam, via_conjunction,
"env_prefix_kinds_partial_cover ({via_seam}) must agree with \
env_prefix_kinds_any_observed && !env_prefix_kinds_full_cover \
({via_conjunction})",
);
}
}
#[test]
fn env_prefix_kinds_partial_cover_agrees_with_present_env_prefix_kinds_count_strict_interval_pointwise()
{
// Support-scalar strict-interval surface:
// `env_prefix_kinds_partial_cover() == (0 < present_env_prefix_kinds_count()
// && present_env_prefix_kinds_count() <
// axis_cardinality::<crate::EnvMetadataTagKind>())` on every
// fixture. The support-side surfacing of the same boolean,
// without allocating `Vec<crate::EnvMetadataTagKind>`. On the
// cardinality-`2` env-prefix axis the strict interval `(0,
// cardinality) = (0, 2)` contains only the singleton
// cardinality `1`, so the scalar test degenerates to
// `present_env_prefix_kinds_count() == 1`. Peer of
// `file_formats_partial_cover_agrees_with_present_file_formats_count_strict_interval_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_agrees_with_present_layer_kinds_count_strict_interval_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_agrees_with_contributing_tiers_count_strict_interval_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_agrees_with_present_kinds_count_strict_interval_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_partial_cover();
let support = slice.present_env_prefix_kinds_count();
let via_scalar =
0 < support && support < crate::axis_cardinality::<crate::EnvMetadataTagKind>();
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_partial_cover ({via_seam}) must agree with \
0 < present_env_prefix_kinds_count < cardinality \
({via_scalar}, support={support})",
);
}
}
#[test]
fn env_prefix_kinds_partial_cover_agrees_with_absent_env_prefix_kinds_count_strict_interval_pointwise()
{
// Coverage-gap dual-scalar strict-interval surface:
// `env_prefix_kinds_partial_cover() == (0 < absent_env_prefix_kinds_count()
// && absent_env_prefix_kinds_count() <
// axis_cardinality::<crate::EnvMetadataTagKind>())` on every
// fixture. The `present + absent == axis_cardinality`
// invariant restated on the two named cardinality peers,
// without allocating `Vec<crate::EnvMetadataTagKind>`. Peer
// of the histogram-side dual-scalar strict-interval form
// `0 < hist.unobserved_cells() && hist.unobserved_cells() <
// axis_cardinality::<A>()` pinned one altitude down. Peer of
// `file_formats_partial_cover_agrees_with_absent_file_formats_count_strict_interval_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_agrees_with_absent_layer_kinds_count_strict_interval_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_agrees_with_absent_tiers_count_strict_interval_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_agrees_with_absent_kinds_count_strict_interval_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_partial_cover();
let gap = slice.absent_env_prefix_kinds_count();
let via_scalar =
0 < gap && gap < crate::axis_cardinality::<crate::EnvMetadataTagKind>();
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_partial_cover ({via_seam}) must agree with \
0 < absent_env_prefix_kinds_count < cardinality \
({via_scalar}, gap={gap})",
);
}
}
#[test]
fn env_prefix_kinds_partial_cover_agrees_with_present_and_absent_env_prefix_kinds_count_both_positive_pointwise()
{
// Mixed-side dual-scalar non-emptiness surface:
// `env_prefix_kinds_partial_cover() == (present_env_prefix_kinds_count() > 0
// && absent_env_prefix_kinds_count() > 0)` on every fixture.
// The direct histogram-surface `distinct_cells > 0 &&
// unobserved_cells > 0` pin restated at the chain env-prefix
// sub-axis — the boolean asking "did the chain see at least
// one env-prefix kind *and* miss at least one env-prefix
// kind?" against the two named cardinality peers, without
// allocating either `Vec<crate::EnvMetadataTagKind>`. Peer of
// the sibling `env_prefix_kinds_boundary` dual-scalar equality
// form `present_env_prefix_kinds_count == 0 ||
// absent_env_prefix_kinds_count == 0` (its exact strict-
// complement) one seam over on the coverage-trichotomy
// bipartition. Peer of
// `file_formats_partial_cover_agrees_with_present_and_absent_file_formats_count_both_positive_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_agrees_with_present_and_absent_layer_kinds_count_both_positive_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_agrees_with_contributing_and_absent_tiers_count_both_positive_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_agrees_with_present_and_absent_kinds_count_both_positive_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_partial_cover();
let support = slice.present_env_prefix_kinds_count();
let gap = slice.absent_env_prefix_kinds_count();
let via_scalar = support > 0 && gap > 0;
assert_eq!(
via_seam, via_scalar,
"env_prefix_kinds_partial_cover ({via_seam}) must agree with \
present_env_prefix_kinds_count > 0 && absent_env_prefix_kinds_count > 0 \
({via_scalar}, support={support}, gap={gap})",
);
}
}
#[test]
fn env_prefix_kinds_partial_cover_empty_chain_is_false() {
// Empty-chain partial-cover: the empty chain observes zero
// cells, so every cell is unobserved (two zeros on the
// cardinality-`2` axis) — the scan sees no nonzero cell and
// falls through to `false`. `env_prefix_kinds_partial_cover`
// reads `false`. Matches `has_partial_cover` reading `false`
// on the empty histogram one altitude down. Direct witness of
// the disjointness `!env_prefix_kinds_any_observed ⇒
// !env_prefix_kinds_partial_cover` via the empty-chain
// disjunct of `env_prefix_kinds_boundary`. Peer of
// `file_formats_partial_cover_empty_chain_is_false` on the
// file-format sub-axis and
// `layer_kinds_partial_cover_empty_chain_is_false` on the
// layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_empty_map_is_false` on the tier
// altitude, and `kinds_partial_cover_empty_diff_is_false` on
// the diff altitude.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(!empty.env_prefix_kinds_partial_cover());
assert!(!empty.env_prefix_kinds_any_observed());
assert!(empty.env_prefix_kinds_boundary());
}
#[test]
fn env_prefix_kinds_partial_cover_no_env_layers_is_false() {
// Non-empty-chain / empty-histogram partial-cover — the env-
// prefix sub-axis cross-sub-axis divergence pin against the
// layer-kind sub-axis. A chain of only `Defaults` / `File`
// layers is non-empty but has no `Some` env-prefix projection
// (the `ConfigSource::env_prefix_kind` map is a partial
// function returning `None` on Defaults / File), so the
// histogram is empty (two zeros on the cardinality-`2` axis)
// — the scan sees no nonzero cell and falls through to
// `false`. `env_prefix_kinds_partial_cover` reads `false` via
// the empty-histogram case. Direct divergence pin against
// `layer_kinds_partial_cover`: on the same fixtures the
// layer-kind sub-axis observes at least one layer-kind cell
// (Defaults / File) at partial support and typically reads
// `layer_kinds_partial_cover = true`, while the env-prefix
// sub-axis's partial-cover middle leg silently drops out via
// the empty-histogram case of the strict-complement
// `env_prefix_kinds_boundary` corner. Peer of
// `env_prefix_kinds_boundary_no_env_layers_is_true` via the
// disjoint-corner relationship — every no-env-layers chain
// sits on `env_prefix_kinds_boundary = true`, so the
// bipartition still holds. Peer of
// `file_formats_partial_cover_no_recognized_files_is_false`
// on the sister partial-function sub-axis at the file-format
// altitude — the two partial-function projections carry the
// same empty-histogram convention on their respective non-
// empty-chain fixtures.
let fixtures: [Vec<ConfigSource>; 3] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.toml")),
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(slice.env_prefix_kind_histogram().is_empty());
assert!(!slice.env_prefix_kinds_any_observed());
assert!(!slice.env_prefix_kinds_partial_cover());
assert!(slice.env_prefix_kinds_boundary());
}
}
#[test]
fn env_prefix_kinds_partial_cover_prefixed_only_is_true() {
// Singleton-support pin on the prefixed side: every env layer
// carries a non-empty prefix, so `Prefixed` is the sole
// observed cell out of two — support cardinality `1`, so
// `env_prefix_kinds_partial_cover` reads `true`. Direct
// witness of the subsumption
// `env_prefix_kinds_singular_support ⇒
// env_prefix_kinds_partial_cover` via the mixed-parity
// witness. On the cardinality-`2` axis the singleton-support
// boundary IS the singular near-boundary corner (the dual-
// singular-collapse `singular_support ⇔ singular_gap`), so
// this fixture also witnesses `env_prefix_kinds_singular =
// true`. Peer of
// `env_prefix_kinds_singular_support_prefixed_only_is_true`
// on the singular-support boundary corner one seam over.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_partial_cover());
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_singular());
}
#[test]
fn env_prefix_kinds_partial_cover_bare_only_is_true() {
// Singleton-support pin on the bare side: every env layer
// carries the empty prefix, so `Bare` is the sole observed
// cell — support cardinality `1`, so
// `env_prefix_kinds_partial_cover` reads `true`. Symmetric
// sister of `env_prefix_kinds_partial_cover_prefixed_only_is_true`
// on the two-cell env-prefix axis: both singletons sit on
// the (`any_observed`=true, `partial_cover`=true,
// `singular`=true, `full_cover`=false) polarity quadruple.
// Peer of `env_prefix_kinds_singular_support_bare_only_is_true`
// on the singular-support boundary corner one seam over.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_partial_cover());
assert!(slice.env_prefix_kinds_singular_support());
assert!(slice.env_prefix_kinds_singular());
}
#[test]
fn env_prefix_kinds_partial_cover_sample_chain_is_true() {
// Direct pin against `sample_chain()`: two `.yaml` file layers
// + one prefixed env layer (`"APP_"`). `Prefixed` is the sole
// observed env-prefix cell (Bare has count `0`) — the env-
// prefix sub-axis reads support cardinality `1`, so
// `env_prefix_kinds_partial_cover` reads `true`. Peer of
// `file_formats_partial_cover_singleton_support_is_true` on
// the sister sub-axis of the same fixture (Yaml the sole
// observed file-format cell); cross-sub-axis divergence from
// `layer_kinds_partial_cover` on the same fixture, where
// support is `2` (File + Env) — the sample chain sits on the
// partial-cover middle leg on all three projection sub-axes,
// but via different distance-ternary corners at each.
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_partial_cover());
assert!(slice.env_prefix_kinds_singular());
}
#[test]
fn env_prefix_kinds_partial_cover_uniform_cover_is_false() {
// Uniform-cover pin: one Prefixed env + one Bare env layer,
// so both cells of `EnvMetadataTagKind::ALL` receive equal
// counts — support cardinality is `2` (no unobserved cells on
// the cardinality-`2` axis), so the single-pass scan sees
// only nonzero cells and falls through to `false`.
// `env_prefix_kinds_partial_cover` reads `false`. Direct
// witness of the disjointness
// `env_prefix_kinds_full_cover ⇒ !env_prefix_kinds_partial_cover`
// via the full-cover boundary of `env_prefix_kinds_boundary`.
// Peer of `file_formats_partial_cover_uniform_cover_is_false`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_uniform_cover_is_false` on the
// layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_uniform_cover_is_false` on the tier
// altitude, and `kinds_partial_cover_uniform_cover_is_false`
// on the diff altitude.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kinds_full_cover());
assert!(!slice.env_prefix_kinds_partial_cover());
}
#[test]
fn env_prefix_kinds_partial_cover_and_env_prefix_kinds_boundary_form_strict_bipartition_pointwise()
{
// Strict-bipartition pin at the chain env-prefix sub-axis
// *with the named seam*: `env_prefix_kinds_partial_cover` and
// `env_prefix_kinds_boundary` are pointwise complementary —
// exactly one fires on every chain. The named partial-cover
// corner is the exact complement of the named boundary
// corner. Peer of the pre-existing pin
// `env_prefix_kinds_boundary_and_env_prefix_kinds_partial_cover_form_strict_bipartition_pointwise`
// (kept alongside as the open-coded parity witness against
// `env_prefix_kinds_any_observed && !env_prefix_kinds_full_cover`),
// and peer of the histogram-side bipartition law
// `axis_histogram_has_boundary_and_has_partial_cover_form_strict_bipartition_for_every_closed_axis_implementor`
// one altitude down. The `env_prefix_kinds_partial_cover`
// seam now names the middle leg of the coverage trichotomy
// directly at the surface, replacing the open-coded
// conjunction-of-negations expression used by the pre-
// existing pin. Peer of
// `file_formats_partial_cover_and_file_formats_boundary_form_strict_bipartition_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_and_layer_kinds_boundary_form_strict_bipartition_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_and_tiers_boundary_form_strict_bipartition_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_and_kinds_boundary_form_strict_bipartition_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let partial = slice.env_prefix_kinds_partial_cover();
let boundary = slice.env_prefix_kinds_boundary();
let count = usize::from(partial) + usize::from(boundary);
assert_eq!(
count, 1,
"exactly one of (partial_cover, boundary) must fire \
(partial={partial}, boundary={boundary})",
);
}
}
#[test]
fn env_prefix_kinds_partial_cover_implies_env_prefix_kinds_any_observed_pointwise() {
// Subsumption pin: `env_prefix_kinds_partial_cover() ⇒
// env_prefix_kinds_any_observed()` always via the "at least
// one observed" half of the defining conjunction. Every
// partial-cover chain observes at least one cell — the
// middle-leg corner sits on the `true` side of the any-
// observed boundary. Peer of
// `file_formats_partial_cover_implies_file_formats_any_observed_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_implies_layer_kinds_any_observed_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_implies_tiers_any_observed_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_implies_kinds_any_observed_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_partial_cover() {
assert!(
slice.env_prefix_kinds_any_observed(),
"partial-cover chain must observe at least one cell",
);
}
}
}
#[test]
fn env_prefix_kinds_partial_cover_implies_not_env_prefix_kinds_full_cover_pointwise() {
// Subsumption pin: `env_prefix_kinds_partial_cover() ⇒
// !env_prefix_kinds_full_cover()` always via the "at least
// one unobserved" half of the defining conjunction. Every
// partial-cover chain misses at least one cell — the middle-
// leg corner sits strictly below the full-cover top boundary.
// Peer of
// `file_formats_partial_cover_implies_not_file_formats_full_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_implies_not_layer_kinds_full_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_implies_not_tiers_full_cover_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_implies_not_kinds_full_cover_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_partial_cover() {
assert!(
!slice.env_prefix_kinds_full_cover(),
"partial-cover chain cannot be full-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_singular_implies_env_prefix_kinds_partial_cover_pointwise() {
// Subsumption pin: `env_prefix_kinds_singular() ⇒
// env_prefix_kinds_partial_cover()` always on cardinality-
// `>= 2` axes. The union of the two singular-side
// subsumptions lands the middle-leg singular corners inside
// the partial-cover middle leg. On the cardinality-`2` env-
// prefix axis this subsumption is a *strict equivalence* via
// the vacuously-`false` strict interior (documented on the
// separate `env_prefix_kinds_partial_cover_iff_env_prefix_kinds_singular_on_cardinality_two_pointwise`
// pin below). Peer of
// `file_formats_singular_implies_file_formats_partial_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_singular_implies_layer_kinds_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_singular_implies_tiers_partial_cover_pointwise` on
// the tier altitude, and
// `kinds_singular_implies_kinds_partial_cover_pointwise` on
// the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_singular() {
assert!(
slice.env_prefix_kinds_partial_cover(),
"singular chain must be partial-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_strict_partial_cover_implies_env_prefix_kinds_partial_cover_pointwise() {
// Subsumption pin: `env_prefix_kinds_strict_partial_cover() ⇒
// env_prefix_kinds_partial_cover()` always. The strict
// interior sits inside the partial-cover middle leg by
// definition. Direct pin of the histogram-side subsumption
// `has_strict_partial_cover ⇒ has_partial_cover` one altitude
// down. **Vacuously-`true`** at the env-prefix sub-axis on
// the cardinality-`2` axis — the strict interior is
// structurally empty (the strict interval `[2, cardinality
// - 2] = [2, 0]` is empty), the *tightest* vacuously-`true`
// antecedent in the projection. Matches the layer-kind sub-
// axis and the diff altitude on their cardinality-`3` axes
// (also vacuously-true through their empty strict interior)
// and diverges from the tier altitude and the file-format
// sub-axis where the cardinality-`4` axis inhabits both
// consequent and antecedent `true` non-vacuously. Peer of
// `file_formats_strict_partial_cover_implies_file_formats_partial_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_strict_partial_cover_implies_layer_kinds_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_strict_partial_cover_implies_tiers_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_strict_partial_cover_implies_kinds_partial_cover_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kinds_strict_partial_cover() {
assert!(
slice.env_prefix_kinds_partial_cover(),
"strict-partial-cover chain must be partial-cover",
);
}
}
}
#[test]
fn env_prefix_kinds_partial_cover_iff_env_prefix_kinds_singular_on_cardinality_two_pointwise() {
// Two-cell-axis partial_cover/singular equivalence pin:
// `env_prefix_kinds_partial_cover ⇔ env_prefix_kinds_singular`
// on the cardinality-`2` env-prefix axis. On this axis the
// strict interior of the coverage trichotomy is structurally
// empty (the strict interval `[2, cardinality - 2] = [2, 0]`
// is empty), so the partial-cover middle leg collapses onto
// the singular near-boundary corner. The *unique* two-cell-
// axis tightening of the general subsumption `singular ⇒
// partial_cover` (documented at every altitude / sub-axis)
// into an equivalence — the peer of the (structurally
// identical) collapse at the layer-kind sub-axis and the
// diff altitude on their cardinality-`3` axes (also
// degenerate through the vacuous strict interior). Does NOT
// lift to the cardinality-`4` sub-axes (tier altitude, file-
// format sub-axis) where the strict interior is reachable
// and every chain landing on the strict interior reads
// `partial_cover=true, singular=false, strict_partial_cover=true`.
// Symmetric dual of
// `env_prefix_kinds_boundary_iff_not_env_prefix_kinds_singular_on_cardinality_two_pointwise`
// one seam over on the strict-bipartition
// `(env_prefix_kinds_boundary, env_prefix_kinds_partial_cover)`.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let partial = slice.env_prefix_kinds_partial_cover();
let singular = slice.env_prefix_kinds_singular();
assert_eq!(
partial, singular,
"on the cardinality-2 env-prefix axis partial_cover ({partial}) \
must equal singular ({singular})",
);
}
}
#[test]
fn env_prefix_kinds_partial_cover_and_env_prefix_kinds_any_observed_negation_and_env_prefix_kinds_full_cover_form_coverage_trichotomy_pointwise()
{
// Coverage-trichotomy partition pin at the chain env-prefix
// sub-axis: exactly one of the three legs
// `(!env_prefix_kinds_any_observed, env_prefix_kinds_partial_cover,
// env_prefix_kinds_full_cover)` fires on every chain — the
// coverage trichotomy of the `(is_empty, has_partial_cover,
// is_full_cover)` histogram-side partition restated at the
// chain env-prefix sub-axis. Peer of the trait-uniform pin
// `axis_histogram_coverage_trichotomy_partitions_every_histogram_for_every_closed_axis_implementor`
// one altitude down. The `env_prefix_kinds_partial_cover`
// seam now carries the middle leg of this partition directly
// at the surface, folding the open-coded expression
// `env_prefix_kinds_any_observed && !env_prefix_kinds_full_cover`
// (the surface used verbatim by the pre-existing bipartition-
// law pin
// `env_prefix_kinds_boundary_and_env_prefix_kinds_partial_cover_form_strict_bipartition_pointwise`)
// into one named boolean. Peer of
// `file_formats_partial_cover_and_file_formats_any_observed_negation_and_file_formats_full_cover_form_coverage_trichotomy_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_and_layer_kinds_any_observed_negation_and_layer_kinds_full_cover_form_coverage_trichotomy_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_and_tiers_any_observed_negation_and_tiers_full_cover_form_coverage_trichotomy_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_and_kinds_any_observed_negation_and_kinds_full_cover_form_coverage_trichotomy_pointwise`
// on the diff altitude — closing the coverage-trichotomy
// partition law at the fifth and final altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let empty = !slice.env_prefix_kinds_any_observed();
let partial = slice.env_prefix_kinds_partial_cover();
let full = slice.env_prefix_kinds_full_cover();
let count = usize::from(empty) + usize::from(partial) + usize::from(full);
assert_eq!(
count, 1,
"exactly one of (!any_observed, partial_cover, full_cover) \
must fire (empty={empty}, partial={partial}, full={full})",
);
}
}
#[test]
fn env_prefix_kinds_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise()
{
// Cross-surface bridge law:
// `env_prefix_kinds_partial_cover() ==
// env_prefix_kind_histogram().support_cardinality_class().is_partial_cover()`
// on every fixture. The class-side projection lands on
// `SupportCardinalityClass::SingularSupport`,
// `SupportCardinalityClass::StrictPartialCover`, or
// `SupportCardinalityClass::SingularGap` exactly when the
// histogram-side conjunction fires, and
// `SupportCardinalityClass::is_partial_cover` reads `true`
// on any of the three variants. Peer of the histogram-side
// bridge
// `axis_histogram_support_cardinality_class_is_partial_cover_agrees_with_histogram_has_partial_cover_for_every_closed_axis_implementor`
// one altitude down, closing the (histogram, class) duality
// on the partial-cover middle leg at the chain env-prefix
// sub-axis. Peer of
// `file_formats_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise`
// on the tier altitude, and
// `kinds_partial_cover_bridges_support_cardinality_class_is_partial_cover_pointwise`
// on the diff altitude — closing the (histogram, class)
// duality on the partial-cover middle leg at the fifth and
// final altitude / sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_partial_cover();
let via_class = slice
.env_prefix_kind_histogram()
.support_cardinality_class()
.is_partial_cover();
assert_eq!(
via_seam, via_class,
"env_prefix_kinds_partial_cover ({via_seam}) must agree with \
env_prefix_kind_histogram().support_cardinality_class().is_partial_cover() \
({via_class})",
);
}
}
#[test]
fn env_prefix_kinds_partial_cover_agrees_with_open_coded_mixed_parity_walk() {
// Parity against the exact hand-rolled partial-cover walk
// this lift replaces on cardinality-`>= 2` axes: walk every
// cell of the histogram and count how many carry a zero
// count and how many carry a nonzero count; the partial-
// cover predicate reads `true` iff *both* a zero cell *and*
// a nonzero cell appear. Mirrors the parity pin
// `env_prefix_kinds_boundary_agrees_with_open_coded_uniform_parity_walk`
// on the strict-complement top-leg projection — the two
// parity walks are pointwise complementary on every
// cardinality-`>= 1` axis. Peer of
// `file_formats_partial_cover_agrees_with_open_coded_mixed_parity_walk`
// on the file-format sub-axis and
// `layer_kinds_partial_cover_agrees_with_open_coded_mixed_parity_walk`
// on the layer-kind sub-axis of the same chain altitude,
// `tiers_partial_cover_agrees_with_open_coded_mixed_parity_walk`
// on the tier altitude, and
// `kinds_partial_cover_agrees_with_open_coded_mixed_parity_walk`
// on the diff altitude — closing the parity discipline at
// the fifth and final altitude / sub-axis in the "partial-
// cover across altitudes" projection.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_partial_cover();
let hist = slice.env_prefix_kind_histogram();
let zeros = hist.iter().filter(|(_, c)| *c == 0).count();
let nonzeros = hist.iter().filter(|(_, c)| *c > 0).count();
let hand_rolled = zeros > 0 && nonzeros > 0;
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSourceChain::env_prefix_kind_spread — scalar-dispersion
// peer on the env-prefix-presence sub-axis of the chain
// altitude, fusing peak_env_prefix_kind_count and
// trough_env_prefix_kind_count into one dispersion scalar and
// closing the "spread across altitudes" projection sideways to
// the third chain-altitude sub-axis ----
#[test]
fn env_prefix_kind_spread_matches_env_prefix_kind_histogram_spread_pointwise() {
// The scalar-dispersion pin: `env_prefix_kind_spread` routes
// through `env_prefix_kind_histogram().spread()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Direct sister of
// `file_format_spread_matches_file_format_histogram_spread_pointwise`
// and `layer_kind_spread_matches_layer_kind_histogram_spread_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tier_spread_matches_tier_histogram_spread_pointwise` on the
// tier altitude, and
// `kind_spread_matches_kind_histogram_spread_pointwise` on the
// diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let via_histogram = chain.as_slice().env_prefix_kind_histogram().spread();
assert_eq!(chain.as_slice().env_prefix_kind_spread(), via_histogram);
}
}
#[test]
fn env_prefix_kind_spread_equals_peak_minus_trough_pointwise() {
// The fused-pair pin: `env_prefix_kind_spread ==
// peak_env_prefix_kind_count - trough_env_prefix_kind_count` on
// every fixture. The subtraction is underflow-safe because
// `peak_env_prefix_kind_count() >=
// trough_env_prefix_kind_count()` holds structurally on every
// chain (lifted from the trait-uniform `peak_count >=
// trough_count` law on AxisHistogram); this pin asserts the
// monotonicity invariant explicitly at every fixture so any
// future refactor that swaps the operands fails visibly. Peer
// of `file_format_spread_equals_peak_minus_trough_pointwise`
// and `layer_kind_spread_equals_peak_minus_trough_pointwise`
// on the sister sub-axes of the same chain altitude,
// `tier_spread_equals_peak_minus_trough_pointwise` on the tier
// altitude, and `kind_spread_equals_peak_minus_trough_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let peak = slice.peak_env_prefix_kind_count();
let trough = slice.trough_env_prefix_kind_count();
assert!(
peak >= trough,
"peak={peak} must be >= trough={trough} on every chain",
);
assert_eq!(slice.env_prefix_kind_spread(), peak - trough);
}
}
#[test]
fn env_prefix_kind_spread_sample_chain_is_zero() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one Env layer with prefix `"APP_"`. Prefixed is the sole
// observed env-prefix kind (present == {Prefixed}), so peak ==
// trough == 1 and the spread is 0 — the singleton-support
// balanced-boundary through the seam. Reads the paired
// `(peak_env_prefix_kind_count, trough_env_prefix_kind_count,
// env_prefix_kind_spread)` dispersion triple as `(1, 1, 0)`.
// Cross-sub-axis divergence pin against
// `layer_kind_spread_sample_chain_is_one`: on the same
// `sample_chain()` fixture, the layer-kind sub-axis reads spread
// 1 (File dominant at 2, Env recessive at 1) while the env-
// prefix sub-axis reads spread 0 (only Prefixed observed).
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.peak_env_prefix_kind_count(), 1);
assert_eq!(slice.trough_env_prefix_kind_count(), 1);
assert_eq!(slice.env_prefix_kind_spread(), 0);
}
#[test]
fn env_prefix_kind_spread_bare_majority_is_two() {
// Direct pin against a bare-majority chain: three empty-prefix
// Env layers + one prefixed Env layer + one Defaults + one
// File. Bare dominant at 3, Prefixed recessive at 1 — the
// spread is 2. Reads the paired `(peak_env_prefix_kind_count,
// trough_env_prefix_kind_count, env_prefix_kind_spread)`
// dispersion triple as `(3, 1, 2)`. Cross-verified against
// `hist.spread() == 2` at the same observation site — the
// fused-pair spread projection reads through the seam.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.peak_env_prefix_kind_count(), 3);
assert_eq!(slice.trough_env_prefix_kind_count(), 1);
assert_eq!(slice.env_prefix_kind_spread(), 2);
assert_eq!(slice.env_prefix_kind_histogram().spread(), 2);
}
#[test]
fn env_prefix_kind_spread_empty_chain_is_zero() {
// An empty chain has no env layers and therefore zero spread —
// reads `0` per the AxisHistogram::spread empty convention one
// altitude down; the `(peak_env_prefix_kind_count,
// trough_env_prefix_kind_count, env_prefix_kind_spread)` triple
// reads `(0, 0, 0)` uniformly on empty. Peer of
// `file_format_spread_empty_chain_is_zero` and
// `layer_kind_spread_empty_chain_is_zero` on the sister sub-
// axes, `tier_spread_empty_map_is_zero` on the tier altitude,
// and `kind_spread_empty_diff_is_zero` on the diff altitude.
let empty: [ConfigSource; 0] = [];
assert_eq!(empty.peak_env_prefix_kind_count(), 0);
assert_eq!(empty.trough_env_prefix_kind_count(), 0);
assert_eq!(empty.env_prefix_kind_spread(), 0);
}
#[test]
fn env_prefix_kind_spread_no_env_layers_is_zero() {
// The non-empty-chain / empty-histogram boundary the env-prefix
// sub-axis pins that the layer-kind sub-axis does *not*, and
// that agrees with the file-format sub-axis. A chain of only
// `Defaults` / `File` layers is non-empty but has no `Some`
// env_prefix_kind projection, so the histogram is empty and
// `env_prefix_kind_spread` reads zero — the vacuous-uniformity
// boundary reads through the seam. Distinguishing pin against
// the layer-kind sub-axis `layer_kind_spread` idiom: on those
// same chains, `layer_kind_spread` reads a nonzero dispersion
// (Defaults / File layers still contribute to the layer-kind
// histogram) while `env_prefix_kind_spread` reads zero. Unlike
// the file-format sub-axis's no-recognized-files boundary, the
// env-prefix sub-axis's no-env-layers boundary is exactly
// `layer_kind_histogram().count(ConfigSourceKind::Env) == 0`:
// every `Env` entry projects to a `Some` cell regardless of
// prefix value, so no `Env` entry is silently dropped by the
// projection.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
assert!(!chain.is_empty(), "fixture must be non-empty");
assert!(
chain.as_slice().env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert_eq!(chain.as_slice().env_prefix_kind_spread(), 0);
}
}
#[test]
fn env_prefix_kind_spread_singleton_support_is_zero() {
// Singleton-support pin: every env layer lands on the same
// env-prefix kind, so the dominant kind is both peak and trough
// of the support, and the spread is zero — the balanced-env-
// prefixes boundary on the singleton-support side. Direct
// construction: three prefixed Env layers, present ==
// {Prefixed}. Peer of
// `file_format_spread_singleton_support_is_zero` and
// `layer_kind_spread_singleton_support_is_zero` on the sister
// sub-axes and `tier_spread_singleton_support_is_zero` on the
// tier altitude.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert_eq!(slice.env_prefix_kind_spread(), 0);
}
#[test]
fn env_prefix_kind_spread_uniform_cover_is_zero() {
// Uniform-cover pin: every observed kind contributes the same
// nonzero count (one env layer per kind here — a full-cover
// chain with uniform count 1 per cell), so peak == trough == 1
// and the spread is zero — the balanced-env-prefixes boundary
// on the uniform-cover side. Peer of
// `file_format_spread_uniform_cover_is_zero` and
// `layer_kind_spread_uniform_cover_is_zero` on the sister sub-
// axes and `tier_spread_uniform_cover_is_zero` on the tier
// altitude.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kind_histogram().is_full_cover());
assert_eq!(slice.peak_env_prefix_kind_count(), 1);
assert_eq!(slice.trough_env_prefix_kind_count(), 1);
assert_eq!(slice.env_prefix_kind_spread(), 0);
}
#[test]
fn env_prefix_kind_spread_is_zero_iff_peak_equals_trough() {
// Structural-skew boundary: `env_prefix_kind_spread() == 0` iff
// `peak_env_prefix_kind_count() == trough_env_prefix_kind_count()`
// — the scalar-pair form of the balanced-env-prefixes
// predicate. On every fixture, the predicate agrees with the
// equality of the fused modal-count pair. Peer of
// `file_format_spread_is_zero_iff_peak_equals_trough` and
// `layer_kind_spread_is_zero_iff_peak_equals_trough` on the
// sister sub-axes and
// `tier_spread_is_zero_iff_peak_equals_trough` on the tier
// altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let spread_zero = slice.env_prefix_kind_spread() == 0;
let peak_eq_trough =
slice.peak_env_prefix_kind_count() == slice.trough_env_prefix_kind_count();
assert_eq!(
spread_zero,
peak_eq_trough,
"env_prefix_kind_spread() == 0 iff peak == trough \
(spread={s}, peak={p}, trough={t})",
s = slice.env_prefix_kind_spread(),
p = slice.peak_env_prefix_kind_count(),
t = slice.trough_env_prefix_kind_count(),
);
}
}
#[test]
fn env_prefix_kind_spread_agrees_with_modal_pair_equality_on_nonempty_histogram() {
// Cross-surface pin: on every chain with a non-empty env-
// prefix histogram, `env_prefix_kind_spread() == 0` agrees
// with `dominant_env_prefix_kind() ==
// recessive_env_prefix_kind()` — the modal-pair equality form
// of the balanced-env-prefixes predicate. Both branches reduce
// to `Some(first) == Some(first)` on singleton-support and
// uniform-cover chains, and to `false` on skewed chains. Peer
// of `file_format_spread_agrees_with_modal_pair_equality_on_nonempty_histogram`
// on the file-format sub-axis. Cross-sub-axis divergence from
// `layer_kind_spread_agrees_with_modal_pair_equality_on_nonempty_chain`:
// the layer-kind sub-axis quantifies over non-empty chains,
// but the env-prefix sub-axis must quantify over chains with a
// non-empty histogram — a non-empty chain of only Defaults /
// File entries has both `dominant_env_prefix_kind() == None ==
// recessive_env_prefix_kind()` (trivial-equal side) and
// `env_prefix_kind_spread() == 0` (empty-histogram side), so
// the non-empty-chain quantifier would include the empty-
// histogram case as a trivial-equal agreement; the non-empty-
// histogram quantifier excludes it as a distinct boundary.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.env_prefix_kind_histogram().is_empty() {
continue;
}
let spread_zero = slice.env_prefix_kind_spread() == 0;
let dom_eq_rec = slice.dominant_env_prefix_kind() == slice.recessive_env_prefix_kind();
assert_eq!(
spread_zero, dom_eq_rec,
"on non-empty-histogram chain, env_prefix_kind_spread() == 0 iff \
dominant_env_prefix_kind() == recessive_env_prefix_kind()",
);
}
}
#[test]
fn env_prefix_kind_spread_bounded_above_by_peak_env_prefix_kind_count() {
// Structural bound: `env_prefix_kind_spread() <=
// peak_env_prefix_kind_count()` on every fixture — the trough
// is non-negative, so the subtraction is bounded above by the
// minuend. Lifted from the trait-uniform `spread() <=
// peak_count()` law on AxisHistogram. Peer of
// `file_format_spread_bounded_above_by_peak_file_format_count`
// and `layer_kind_spread_bounded_above_by_peak_layer_kind_count`
// on the sister sub-axes,
// `tier_spread_bounded_above_by_peak_tier_count` on the tier
// altitude, and `kind_spread_bounded_above_by_peak_kind_count`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
assert!(
slice.env_prefix_kind_spread() <= slice.peak_env_prefix_kind_count(),
"env_prefix_kind_spread()={s} must be <= \
peak_env_prefix_kind_count()={p}",
s = slice.env_prefix_kind_spread(),
p = slice.peak_env_prefix_kind_count(),
);
}
}
#[test]
fn env_prefix_kind_spread_equals_peak_iff_histogram_is_empty() {
// Equality-case pin of the `env_prefix_kind_spread <=
// peak_env_prefix_kind_count` bound: equality holds iff the
// trough is zero, which by `trough_env_prefix_kind_count == 0
// <=> env_prefix_kind_histogram().is_empty()` (the env-prefix
// sub-axis's zero-trough boundary — the env-prefix histogram
// is empty exactly when no `Env` layer contributes) holds iff
// the histogram is empty. Cross-sub-axis divergence pin
// against `layer_kind_spread_equals_peak_iff_chain_is_empty`:
// on the layer-kind sub-axis, the equality-case coincides with
// `self.as_ref().is_empty()`; on the env-prefix sub-axis, it
// coincides with `env_prefix_kind_histogram().is_empty()` —
// the stricter boundary. Agreement with
// `file_format_spread_equals_peak_iff_histogram_is_empty` on
// the file-format sub-axis. Peer of
// `tier_spread_equals_peak_iff_map_is_empty` on the tier
// altitude and `kind_spread_equals_peak_iff_diff_is_empty` on
// the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let equal = slice.env_prefix_kind_spread() == slice.peak_env_prefix_kind_count();
assert_eq!(
equal,
slice.env_prefix_kind_histogram().is_empty(),
"env_prefix_kind_spread == peak_env_prefix_kind_count iff \
env_prefix_kind_histogram is empty (spread={s}, peak={p}, \
hist_empty={e})",
s = slice.env_prefix_kind_spread(),
p = slice.peak_env_prefix_kind_count(),
e = slice.env_prefix_kind_histogram().is_empty(),
);
}
}
#[test]
fn env_prefix_kind_spread_bounded_above_by_histogram_total() {
// Composition bound: `env_prefix_kind_spread() <=
// env_prefix_kind_histogram().total()` on every fixture —
// chaining `env_prefix_kind_spread <= peak_env_prefix_kind_count`
// (previous pin) with `peak_env_prefix_kind_count <=
// env_prefix_kind_histogram().total()` (documented on
// `peak_env_prefix_kind_count`). Cross-sub-axis divergence
// from `layer_kind_spread_bounded_above_by_len`: the layer-
// kind sub-axis's histogram total equals the chain length
// (every entry projects to one cell), so the layer-kind sub-
// axis composes to `self.as_ref().len()`; the env-prefix sub-
// axis's histogram total equals the env-layer count (strictly
// ≤ chain length), so the env-prefix sub-axis composes to
// `env_prefix_kind_histogram().total()` — the tighter bound.
// Agreement with
// `file_format_spread_bounded_above_by_histogram_total` on the
// file-format sub-axis, but with the strict-equality identity
// `env_prefix_kind_histogram().total() ==
// layer_kind_histogram().count(ConfigSourceKind::Env)` (every
// Env layer contributes) rather than the inequality bound the
// file-format histogram carries.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let hist_total = slice.env_prefix_kind_histogram().total();
assert!(
slice.env_prefix_kind_spread() <= hist_total,
"env_prefix_kind_spread()={s} must be <= \
env_prefix_kind_histogram().total()={t}",
s = slice.env_prefix_kind_spread(),
t = hist_total,
);
}
}
#[test]
fn env_prefix_kind_spread_singleton_support_multi_layer_is_zero() {
// Direct pin at a 5-layer singleton-support Prefixed-only
// chain — present == {Prefixed}, peak == trough == 5, spread
// == 0. The scalar peer of the singleton-support cell
// degenerate `dominant_env_prefix_kind() ==
// recessive_env_prefix_kind()` — the dispersion triple reads
// `(5, 5, 0)`, distinct from the 3-layer fixture in
// `env_prefix_kind_spread_singleton_support_is_zero` so any
// misread that reintroduces the `peak - trough` inline idiom
// as `peak` alone silently underflows on a fixture at a
// different peak. Peer of
// `file_format_spread_singleton_support_multi_layer_is_zero`
// and `layer_kind_spread_singleton_support_multi_layer_is_zero`
// on the sister sub-axes and
// `tier_spread_singleton_support_multi_leaf_is_zero` on the
// tier altitude.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env("EXTRA_".to_owned()),
ConfigSource::Env("MORE_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert_eq!(slice.peak_env_prefix_kind_count(), 5);
assert_eq!(slice.trough_env_prefix_kind_count(), 5);
assert_eq!(slice.env_prefix_kind_spread(), 0);
}
#[test]
fn env_prefix_kind_spread_agrees_with_open_coded_max_minus_min_walk() {
// Parity against the exact `hist.iter().map(|(_, c)| c).max()
// .unwrap_or(0) - hist.iter().filter(|&(_, c)| c > 0)
// .map(|(_, c)| c).min().unwrap_or(0)` walk this lift replaces
// — both the named seam and the hand-rolled max-minus-min-
// over-support must pointwise agree over every fixture. The
// `filter(|(_, c)| c > 0)` step on the min side is the load-
// bearing seam: the naive `.min()` over the full axis would
// silently pick zero-count absent cells on any non-full-cover
// chain, shadowing the trough-of-support the seam surfaces —
// and once the trough shadows to zero, the spread coincides
// with the peak alone, silently overreporting the dispersion.
// Peer of `file_format_spread_agrees_with_open_coded_max_minus_min_walk`
// and `layer_kind_spread_agrees_with_open_coded_max_minus_min_walk`
// on the sister sub-axes,
// `tier_spread_agrees_with_open_coded_max_minus_min_walk` on
// the tier altitude, and
// `kind_spread_agrees_with_open_coded_max_minus_min_walk` on
// the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kind_spread();
let hist = slice.env_prefix_kind_histogram();
let peak = hist.iter().map(|(_, c)| c).max().unwrap_or(0);
let trough = hist
.iter()
.map(|(_, c)| c)
.filter(|&c| c > 0)
.min()
.unwrap_or(0);
assert_eq!(via_seam, peak - trough);
}
}
// ---- ConfigSourceChain::env_prefix_kinds_balanced — balanced-
// boolean predicate on the env-prefix-presence sub-axis of the
// chain altitude, fusing the (peak, trough, spread) scalar
// dispersion triple's balanced boundary into one named boolean
// predicate and closing the "balanced across altitudes"
// projection across every sub-axis of the chain surface ----
#[test]
fn env_prefix_kinds_balanced_matches_env_prefix_kind_histogram_is_uniform_count_pointwise() {
// The routing pin: `env_prefix_kinds_balanced` routes through
// `env_prefix_kind_histogram().is_uniform_count()`, so the two
// seams must stay pointwise equivalent under every fixture.
// Catches any future drift where either implementation stops
// projecting through the shared cube-native primitive. Env-prefix
// sub-axis peer of
// `file_formats_balanced_matches_file_format_histogram_is_uniform_count_pointwise`
// and
// `layer_kinds_balanced_matches_layer_kind_histogram_is_uniform_count_pointwise`
// on the sister sub-axes,
// `tiers_balanced_matches_tier_histogram_is_uniform_count_pointwise`
// on the tier altitude, and
// `kinds_balanced_matches_kind_histogram_is_uniform_count_pointwise`
// on the diff altitude.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_histogram = slice.env_prefix_kind_histogram().is_uniform_count();
assert_eq!(slice.env_prefix_kinds_balanced(), via_histogram);
}
}
#[test]
fn env_prefix_kinds_balanced_agrees_with_env_prefix_kind_spread_zero_pointwise() {
// The defining equivalence on the scalar-spread surface at the
// env-prefix sub-axis: `env_prefix_kinds_balanced() ==
// (env_prefix_kind_spread() == 0)` on every fixture. The
// balanced-boundary of the fused `(peak_env_prefix_kind_count,
// trough_env_prefix_kind_count, env_prefix_kind_spread)`
// dispersion triple as a named boolean predicate. Lifted from the
// trait-uniform `is_uniform_count() == (spread() == 0)` law on
// AxisHistogram. Peer of
// `file_formats_balanced_agrees_with_file_format_spread_zero_pointwise`
// and `layer_kinds_balanced_agrees_with_layer_kind_spread_zero_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let balanced = slice.env_prefix_kinds_balanced();
let spread_zero = slice.env_prefix_kind_spread() == 0;
assert_eq!(
balanced,
spread_zero,
"env_prefix_kinds_balanced ({balanced}) must agree with \
env_prefix_kind_spread == 0 (spread={s}) for chain",
s = slice.env_prefix_kind_spread(),
);
}
}
#[test]
fn env_prefix_kinds_balanced_agrees_with_peak_equals_trough_pointwise() {
// The structural form on the underlying scalar pair:
// `env_prefix_kinds_balanced() == (peak_env_prefix_kind_count()
// == trough_env_prefix_kind_count())` on every fixture. Pins the
// balanced-env-prefix-kinds predicate against the direct scalar-
// pair equality form. Peer of
// `file_formats_balanced_agrees_with_peak_equals_trough_pointwise`
// and `layer_kinds_balanced_agrees_with_peak_equals_trough_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let balanced = slice.env_prefix_kinds_balanced();
let peak = slice.peak_env_prefix_kind_count();
let trough = slice.trough_env_prefix_kind_count();
assert_eq!(
balanced,
peak == trough,
"env_prefix_kinds_balanced ({balanced}) must agree with \
peak_env_prefix_kind_count == trough_env_prefix_kind_count \
({peak} == {trough}) for chain",
);
}
}
#[test]
fn env_prefix_kinds_balanced_agrees_with_modal_pair_equality_pointwise() {
// The modal-pair form: `env_prefix_kinds_balanced() ==
// (dominant_env_prefix_kind() == recessive_env_prefix_kind())` on
// every fixture — including the empty-histogram chain where both
// branches reduce to `None == None`, every singleton-support
// chain where both reduce to `Some(k) == Some(k)`, every uniform
// per-kind chain where both reduce to `Some(first) == Some(first)`
// (after declaration-order tie-break on both sides), and every
// skewed chain where both read `false`. Cross-sub-axis divergence
// pin against
// `env_prefix_kind_spread_agrees_with_modal_pair_equality_on_nonempty_histogram`:
// the balanced predicate agrees with the modal-pair equality
// universally over the fixture set (both branches read `true` on
// the empty-histogram trivial-equal case), while the scalar-
// spread agreement pin quantifies over non-empty-histogram chains
// only. Peer of
// `file_formats_balanced_agrees_with_modal_pair_equality_pointwise`
// and `layer_kinds_balanced_agrees_with_modal_pair_equality_pointwise`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let balanced = slice.env_prefix_kinds_balanced();
let modal_pair_equal =
slice.dominant_env_prefix_kind() == slice.recessive_env_prefix_kind();
assert_eq!(
balanced, modal_pair_equal,
"env_prefix_kinds_balanced ({balanced}) must agree with \
dominant_env_prefix_kind == recessive_env_prefix_kind for \
chain",
);
}
}
#[test]
fn env_prefix_kinds_balanced_empty_chain_is_true() {
// Vacuous-uniformity boundary: the empty chain has no observed
// cells, so the universal "every observed cell carries the same
// count" reads `true` over the empty support — matching
// AxisHistogram::is_uniform_count's empty convention one altitude
// down and `env_prefix_kind_spread == 0` on the empty case. Peer
// of `file_formats_balanced_empty_chain_is_true` and
// `layer_kinds_balanced_empty_chain_is_true` on the sister sub-
// axes and `env_prefix_kind_spread_empty_chain_is_zero` on the
// scalar-spread surface at the same sub-axis.
let empty: [ConfigSource; 0] = [];
assert!(empty.is_empty());
assert!(empty.env_prefix_kinds_balanced());
assert_eq!(empty.env_prefix_kind_spread(), 0);
}
#[test]
fn env_prefix_kinds_balanced_no_env_layers_is_true() {
// The non-empty-chain / empty-histogram vacuous-uniformity
// boundary the env-prefix sub-axis pins that the layer-kind sub-
// axis does *not*, and that agrees with the file-format sub-axis.
// A chain of only `Defaults` / `File` layers is non-empty but has
// no `Some` env_prefix_kind projection, so the histogram is empty
// and `env_prefix_kinds_balanced` reads `true` — the vacuous-
// uniformity boundary reads through the seam. Distinguishing pin
// against `layer_kinds_balanced`: on those same chains,
// `layer_kinds_balanced` reads `false` when the layer-kind
// histogram is skewed (Defaults / File layers still contribute to
// the layer-kind histogram at differing counts) while
// `env_prefix_kinds_balanced` reads `true`. Unlike the file-
// format sub-axis's no-recognized-files boundary, the env-prefix
// sub-axis's no-env-layers boundary is exactly
// `layer_kind_histogram().count(ConfigSourceKind::Env) == 0`:
// every `Env` entry projects to a `Some` cell regardless of
// prefix value, so no `Env` entry is silently dropped by the
// projection.
let fixtures: [Vec<ConfigSource>; 4] = [
vec![ConfigSource::Defaults],
vec![ConfigSource::File(PathBuf::from("/a.yaml"))],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.toml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
],
vec![
ConfigSource::File(PathBuf::from("/a.unknown")),
ConfigSource::File(PathBuf::from("/b.nix")),
ConfigSource::Defaults,
],
];
for chain in &fixtures {
let slice = chain.as_slice();
assert!(!slice.is_empty(), "fixture must be non-empty");
assert!(
slice.env_prefix_kind_histogram().is_empty(),
"fixture must have empty env-prefix histogram",
);
assert!(slice.env_prefix_kinds_balanced());
}
}
#[test]
fn env_prefix_kinds_balanced_singleton_support_is_true() {
// Singleton-support pin: every env layer lands on the same env-
// prefix kind, so the one observed kind's count is both the peak
// and the trough — trivially balanced. Peer of
// `file_formats_balanced_singleton_support_is_true` and
// `layer_kinds_balanced_singleton_support_is_true` on the sister
// sub-axes and `env_prefix_kind_spread_singleton_support_is_zero`
// on the scalar-spread surface at the same sub-axis.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.present_env_prefix_kinds().len(), 1);
assert!(slice.env_prefix_kinds_balanced());
}
#[test]
fn env_prefix_kinds_balanced_uniform_cover_is_true() {
// Uniform-cover pin: every observed kind contributes the same
// nonzero count (one env layer per kind here — a full-cover chain
// with uniform count 1 per cell), so peak == trough == 1 and the
// balanced-env-prefix-kinds predicate reads `true`. Peer of
// `file_formats_balanced_uniform_cover_is_true` and
// `layer_kinds_balanced_uniform_cover_is_true` on the sister sub-
// axes and `env_prefix_kind_spread_uniform_cover_is_zero` on the
// scalar-spread surface at the same sub-axis.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let slice = chain.as_slice();
assert!(slice.env_prefix_kind_histogram().is_full_cover());
assert!(slice.env_prefix_kinds_balanced());
}
#[test]
fn env_prefix_kinds_balanced_bare_majority_is_false() {
// Direct pin against a bare-majority chain: three bare Env layers
// + one prefixed Env + one File + one Defaults. Bare dominant at
// 3, Prefixed recessive at 1 — spread == 2, so
// `env_prefix_kinds_balanced` reads `false`. Peer of
// `file_formats_balanced_toml_majority_is_false` and
// `layer_kinds_balanced_env_majority_is_false` on the sister
// sub-axes on the boolean side and
// `env_prefix_kind_spread_bare_majority_is_two` on the scalar-
// spread surface at the same sub-axis.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
];
let slice = chain.as_slice();
assert_eq!(slice.env_prefix_kind_spread(), 2);
assert!(!slice.env_prefix_kinds_balanced());
}
#[test]
fn env_prefix_kinds_balanced_sample_chain_is_true() {
// Direct pin against `sample_chain()`: two `.yaml` file layers +
// one prefixed Env layer. Prefixed is the sole observed env-
// prefix kind (only one Env layer contributes), so peak ==
// trough == 1 and `env_prefix_kinds_balanced` reads `true` — the
// singleton-support degenerate. Cross-sub-axis divergence pin
// against `layer_kinds_balanced_sample_chain_is_false`: on the
// same fixture, the layer-kind sub-axis reads `false` (File
// dominant at 2, Env recessive at 1) while the env-prefix sub-
// axis reads `true` (only Prefixed observed). Agreement with
// `file_formats_balanced_sample_chain_is_true` on the file-
// format sub-axis (only Yaml observed).
let chain = sample_chain();
let slice = chain.as_slice();
assert_eq!(slice.env_prefix_kind_spread(), 0);
assert!(slice.env_prefix_kinds_balanced());
}
#[test]
fn env_prefix_kinds_balanced_singleton_support_multi_layer_is_true() {
// Singleton-support multi-layer pin: 5 Env layers all on the same
// env-prefix kind — peak == trough == 5, balanced reads `true`.
// Distinct peak from the 3-layer singleton fixture above so any
// misread that reintroduces an `env_prefix_kind_spread == 0`
// inline idiom silently underflows on a fixture at a different
// peak. Peer of
// `file_formats_balanced_singleton_support_multi_layer_is_true`
// and `layer_kinds_balanced_singleton_support_multi_layer_is_true`
// on the sister sub-axes and
// `env_prefix_kind_spread_singleton_support_multi_layer_is_zero`
// on the scalar-spread surface at the same sub-axis.
let chain = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("TOBIRA_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
ConfigSource::Env("EXTRA_".to_owned()),
ConfigSource::Env("MORE_".to_owned()),
];
let slice = chain.as_slice();
assert_eq!(slice.peak_env_prefix_kind_count(), 5);
assert_eq!(slice.trough_env_prefix_kind_count(), 5);
assert!(slice.env_prefix_kinds_balanced());
}
#[test]
fn env_prefix_kinds_balanced_implies_at_most_one_present_kind_or_uniform_cover() {
// Structural characterization: on every fixture,
// `env_prefix_kinds_balanced` holds when the chain's env-prefix
// support size is 0 or 1, or every observed kind carries the same
// nonzero count. Direct witness of the trait-uniform
// `distinct_cells() <= 1 ⇒ is_uniform_count()` law on
// AxisHistogram, lifted to the env-prefix sub-axis of the chain
// altitude. Peer of
// `file_formats_balanced_implies_at_most_one_present_format_or_uniform_cover`
// and `layer_kinds_balanced_implies_at_most_one_present_kind_or_uniform_cover`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if slice.present_env_prefix_kinds().len() <= 1 {
assert!(
slice.env_prefix_kinds_balanced(),
"chain with present_env_prefix_kinds.len() = {} must be \
env_prefix_kinds_balanced",
slice.present_env_prefix_kinds().len(),
);
}
}
}
#[test]
fn env_prefix_kinds_balanced_false_implies_env_prefix_kind_histogram_is_nonempty() {
// Contrapositive of the vacuous-uniformity implication:
// `!env_prefix_kinds_balanced() ⇒
// !env_prefix_kind_histogram().is_empty()`. A skewed chain has
// at least two distinct positive counts on the env-prefix
// histogram, so the histogram is non-empty. Cross-sub-axis
// divergence pin against
// `layer_kinds_balanced_false_implies_chain_is_nonempty`: on the
// layer-kind sub-axis, the contrapositive falls on
// `!self.as_ref().is_empty()`; on the env-prefix sub-axis, it
// falls on the stricter `!env_prefix_kind_histogram().is_empty()`
// — a non-empty chain of only Defaults / File layers has an
// empty env-prefix histogram and is `env_prefix_kinds_balanced`,
// so the chain-non-empty implication would fail on those
// fixtures. Agreement with
// `file_formats_balanced_false_implies_file_format_histogram_is_nonempty`
// on the sister sub-axis.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if !slice.env_prefix_kinds_balanced() {
assert!(
!slice.env_prefix_kind_histogram().is_empty(),
"non-balanced chain must have non-empty env-prefix \
histogram",
);
}
}
}
#[test]
fn env_prefix_kinds_balanced_false_implies_at_least_two_present_env_prefix_kinds() {
// Contrapositive of the singleton-support implication:
// `!env_prefix_kinds_balanced() ⇒
// present_env_prefix_kinds().len() >= 2`. A skewed chain
// observes at least two distinct kinds with differing counts.
// Lifted from the trait-uniform `!is_uniform_count() ⇒
// distinct_cells() >= 2` law on AxisHistogram. On the two-cell
// env-prefix axis this is tight: `!env_prefix_kinds_balanced` ⇒
// `present_env_prefix_kinds().len() == 2` (both cells nonzero,
// and any skew implies the two cells fired at different counts).
// Peer of
// `file_formats_balanced_false_implies_at_least_two_present_file_formats`
// and `layer_kinds_balanced_false_implies_at_least_two_present_layer_kinds`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
if !slice.env_prefix_kinds_balanced() {
assert!(
slice.present_env_prefix_kinds().len() >= 2,
"non-balanced chain must observe >= 2 present env \
prefix kinds (was {})",
slice.present_env_prefix_kinds().len(),
);
}
}
}
#[test]
fn env_prefix_kinds_balanced_agrees_with_open_coded_uniform_walk() {
// Parity against the exact hand-rolled uniform-count walk this
// lift replaces: pull the nonzero counts and check they all
// agree. Empty support reads `true` vacuously. Mirrors the
// parity pins
// `file_formats_balanced_agrees_with_open_coded_uniform_walk`
// and `layer_kinds_balanced_agrees_with_open_coded_uniform_walk`
// on the sister sub-axes.
for chain in recessive_env_prefix_kind_fixtures() {
let slice = chain.as_slice();
let via_seam = slice.env_prefix_kinds_balanced();
let hist = slice.env_prefix_kind_histogram();
let mut nonzero = hist.iter().map(|(_, c)| c).filter(|&c| c > 0);
let hand_rolled = match nonzero.next() {
None => true,
Some(first) => nonzero.all(|c| c == first),
};
assert_eq!(via_seam, hand_rolled);
}
}
// ---- ConfigSource::env_prefix_kind ----
#[test]
fn env_prefix_kind_classifies_empty_prefix_as_bare() {
// The empty-prefix Env layer is the chain-side projection of the
// figment::providers::Env::raw shape — its env_prefix_kind must
// read EnvMetadataTagKind::Bare. Pins the per-cell projection on
// the bare side of the kind axis.
let s = ConfigSource::Env(String::new());
assert_eq!(s.env_prefix_kind(), Some(EnvMetadataTagKind::Bare));
}
#[test]
fn env_prefix_kind_classifies_non_empty_prefix_as_prefixed() {
// Every non-empty prefix Env layer projects to
// EnvMetadataTagKind::Prefixed — the chain-side projection of
// figment::providers::Env::prefixed. Across ASCII-case and
// long-prefix shapes the kind axis only carries the
// prefixed/bare partition; case and length do not influence it.
for prefix in [
"MYAPP_",
"x_",
"MixedCase_",
"very_long_prefix_with_underscores_",
"A",
] {
let s = ConfigSource::Env(prefix.to_owned());
assert_eq!(
s.env_prefix_kind(),
Some(EnvMetadataTagKind::Prefixed),
"non-empty prefix {prefix:?} must classify as Prefixed",
);
}
}
#[test]
fn env_prefix_kind_is_none_for_non_env_sources() {
// Defaults and File layers carry no env-prefix shape at all —
// env_prefix_kind must read None on every non-Env source.
assert_eq!(ConfigSource::Defaults.env_prefix_kind(), None);
assert_eq!(
ConfigSource::File(PathBuf::from("/etc/app.yaml")).env_prefix_kind(),
None,
);
assert_eq!(
ConfigSource::File(PathBuf::from("/etc/app.unknownext")).env_prefix_kind(),
None,
);
}
#[test]
fn env_prefix_kind_partitions_env_variants_pointwise() {
// Exhaustive on the EnvMetadataTagKind::ALL slice: every kind
// must be reached by at least one Env layer (Bare via empty
// prefix, Prefixed via any non-empty prefix), and the partition
// is disjoint on the Env-source side (no Env layer projects to
// two cells, no kind is unreachable). Together with
// [`env_prefix_kind_is_none_for_non_env_sources`] this closes
// the per-cell projection law.
let mut reached: Vec<EnvMetadataTagKind> = Vec::new();
for layer in [
ConfigSource::Env(String::new()),
ConfigSource::Env("X_".to_owned()),
] {
let k = layer
.env_prefix_kind()
.expect("every Env layer must project to Some");
assert!(
!reached.contains(&k),
"env_prefix_kind must not project two Env layers to the same kind in this sample",
);
reached.push(k);
}
for kind in EnvMetadataTagKind::ALL {
assert!(
reached.contains(kind),
"EnvMetadataTagKind::{kind:?} must be reachable from some Env layer",
);
}
}
#[test]
fn env_prefix_kind_agrees_with_figment_env_metadata_tag_kind() {
// Cross-surface commutativity: the chain-side projection
// ConfigSource::Env(prefix).env_prefix_kind() must agree pointwise
// with the figment-side projection that goes through
// env_metadata_name (the canonical figment::Metadata::name shape
// for the recorded prefix) and strip_env_metadata_name (the
// parse), then takes EnvMetadataTag::kind. The two surfaces
// converge on one EnvMetadataTagKind axis by construction — a
// future divergence (a figment env shape that one surface
// recognizes and the other does not) surfaces here.
for prefix in ["", "APP_", "MYAPP_", "x_", "MixedCase_"] {
let chain_side = ConfigSource::Env(prefix.to_owned())
.env_prefix_kind()
.expect("every Env layer projects through env_prefix_kind");
let figment_side =
ConfigSource::strip_env_metadata_name(&ConfigSource::env_metadata_name(prefix))
.map(EnvMetadataTag::kind)
.expect("env_metadata_name round-trips through strip_env_metadata_name");
assert_eq!(
chain_side, figment_side,
"env_prefix_kind({prefix:?}) must agree with the figment-side EnvMetadataTag::kind",
);
}
}
// ---- ConfigSourceChain::env_prefix_kind_histogram ----
#[test]
fn env_prefix_kind_histogram_counts_each_kind_pointwise() {
// Concrete pin on the (chain → EnvMetadataTagKind tally)
// projection. `sample_chain()` carries one Env("APP_") layer
// (and two File layers + zero Defaults), so the histogram must
// read 1 Prefixed, 0 Bare. The File and Defaults entries project
// to None through env_prefix_kind() and contribute to no cell.
let chain = sample_chain();
let hist = chain.as_slice().env_prefix_kind_histogram();
assert_eq!(hist.count(EnvMetadataTagKind::Prefixed), 1);
assert_eq!(hist.count(EnvMetadataTagKind::Bare), 0);
// total() equals the count of Env entries — here 1.
assert_eq!(hist.total(), 1);
}
#[test]
fn env_prefix_kind_histogram_covers_every_kind() {
// A chain with one Env layer per kind (empty-prefix → Bare,
// non-empty → Prefixed) must produce a histogram with exactly
// one observation per EnvMetadataTagKind cell — total equals
// EnvMetadataTagKind::ALL cardinality. Pins the uniform-cover
// law on the env-prefix-presence axis.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
let hist = chain.as_slice().env_prefix_kind_histogram();
for kind in EnvMetadataTagKind::ALL.iter().copied() {
assert_eq!(
hist.count(kind),
1,
"uniform-cover chain must read 1 on every EnvMetadataTagKind cell ({kind:?})",
);
}
assert_eq!(hist.total(), EnvMetadataTagKind::ALL.len());
}
#[test]
fn env_prefix_kind_histogram_empty_chain_is_zero_on_every_cell() {
// Empty-chain law on the env-prefix-presence axis: every cell
// reads zero, total is zero, is_empty() is true. Pins the
// monoid identity at the chain-shape boundary on the third
// chain-level histogram surface.
let chain: [ConfigSource; 0] = [];
let hist = chain.env_prefix_kind_histogram();
for kind in EnvMetadataTagKind::ALL.iter().copied() {
assert_eq!(
hist.count(kind),
0,
"empty chain must read zero on every EnvMetadataTagKind cell ({kind:?})",
);
}
assert_eq!(hist.total(), 0);
assert!(hist.is_empty());
}
#[test]
fn env_prefix_kind_histogram_ignores_defaults_and_file_layers() {
// Defaults and File entries carry no env-prefix shape and
// project to None through `env_prefix_kind()`; they must not
// contribute to any EnvMetadataTagKind cell regardless of how
// many chain entries of those kinds are present, regardless of
// file extension recognition.
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/etc/app.yaml")),
ConfigSource::File(PathBuf::from("/etc/app.unknownext")),
];
let hist = chain.as_slice().env_prefix_kind_histogram();
for kind in EnvMetadataTagKind::ALL.iter().copied() {
assert_eq!(
hist.count(kind),
0,
"Defaults/File-only chain must read zero on every \
EnvMetadataTagKind cell ({kind:?})",
);
}
assert_eq!(hist.total(), 0);
assert!(hist.is_empty());
}
#[test]
fn env_prefix_kind_histogram_agrees_with_open_coded_per_kind_count() {
// The lift collapses the per-cell
// `iter().filter_map(env_prefix_kind).filter(|k| *k == X).count()`
// loop the typescape doc-strings promised — pin pointwise
// equivalence over the typed env-prefix-presence axis across
// chains of mixed kinds, mixed prefix shapes, and chains with
// zero, one, or many env layers so a future regression in
// either side surfaces here.
let chains = [
Vec::new(),
vec![ConfigSource::Defaults],
sample_chain(),
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("A_".to_owned()),
ConfigSource::Env("B_".to_owned()),
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &chains {
let hist = chain.as_slice().env_prefix_kind_histogram();
for kind in EnvMetadataTagKind::ALL.iter().copied() {
let manual = chain
.iter()
.filter_map(ConfigSource::env_prefix_kind)
.filter(|k| *k == kind)
.count();
assert_eq!(
hist.count(kind),
manual,
"env_prefix_kind_histogram({kind:?}) must equal the open-coded \
filter_map+filter count over chain of length {}",
chain.len(),
);
}
}
}
#[test]
fn env_prefix_kind_histogram_iter_yields_declaration_order() {
// The dense per-cell iteration must yield the
// EnvMetadataTagKind::ALL declaration order (Prefixed, Bare)
// regardless of the chain's observation order — observation
// order does not leak into the histogram's value-side
// iteration. Peer to
// `file_format_histogram_iter_yields_format_all_declaration_order`
// on the file-format axis and
// `layer_kind_histogram_iter_yields_declaration_order` on the
// layer-kind axis.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("LATER_".to_owned()),
ConfigSource::Env(String::new()),
];
let pairs: Vec<(EnvMetadataTagKind, usize)> = chain
.as_slice()
.env_prefix_kind_histogram()
.iter()
.collect();
let values: Vec<EnvMetadataTagKind> = pairs.iter().map(|(k, _)| *k).collect();
assert_eq!(values, EnvMetadataTagKind::ALL.to_vec());
}
#[test]
fn env_prefix_kind_histogram_equals_axis_histogram_over_env_prefix_kind_projection() {
// Pin equivalence to the generic
// `crate::axis_histogram(self.iter().filter_map(ConfigSource::env_prefix_kind))`
// shape the trait-default method routes through — the lift
// must not silently re-implement the per-cell count loop on a
// parallel surface. Pointwise equality on every
// EnvMetadataTagKind cell.
let chains = [
sample_chain(),
vec![
ConfigSource::Defaults,
ConfigSource::Defaults,
ConfigSource::Env("X_".to_owned()),
],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("A_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
],
];
for chain in &chains {
let lifted = chain.as_slice().env_prefix_kind_histogram();
let generic =
crate::axis_histogram(chain.iter().filter_map(ConfigSource::env_prefix_kind));
for kind in EnvMetadataTagKind::ALL.iter().copied() {
assert_eq!(
lifted.count(kind),
generic.count(kind),
"env_prefix_kind_histogram must equal \
axis_histogram(env_prefix_kind-projection) on {kind:?} \
over chain of length {}",
chain.len(),
);
}
}
}
#[test]
fn layer_kind_histogram_dominant_cell_picks_majority_kind() {
// Cross-surface pin: the
// [`crate::AxisHistogram::dominant_cell`] projection composes
// with the chain-level [`Self::layer_kind_histogram`] to read
// "the dominant layer kind in this chain" at one method-call
// site. `sample_chain()` is two File layers + one Env layer
// (no Defaults), so the dominant kind must be File.
let chain = sample_chain();
assert_eq!(
chain.as_slice().layer_kind_histogram().dominant_cell(),
Some(ConfigSourceKind::File),
);
}
#[test]
fn file_format_histogram_dominant_cell_picks_majority_format() {
// Cross-surface pin on the file-format axis: a chain of three
// `.yaml` + one `.toml` File layers has dominant Format = Yaml
// (strict majority — no tie-breaking required). Env / Defaults
// entries do not contribute (project to None through
// `file_format()`), so the dominant cell of the file-format
// histogram is decided by the File-only sub-slice.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.toml")),
];
assert_eq!(
chain.as_slice().file_format_histogram().dominant_cell(),
Some(Format::Yaml),
);
}
#[test]
fn env_prefix_kind_histogram_dominant_cell_for_mixed_prefix_chain() {
// Cross-surface pin on the env-prefix-presence axis: a chain
// with two `Env(prefix)` (one bare, one prefixed) has
// dominant_cell tied; tie-breaking by `EnvMetadataTagKind::ALL`
// declaration order (Prefixed, Bare) yields Prefixed. Pinned
// here so the documented declaration-order tie-break is
// structurally visible at the chain surface, not just the
// generic `AxisHistogram` surface.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
assert_eq!(
chain.as_slice().env_prefix_kind_histogram().dominant_cell(),
Some(EnvMetadataTagKind::Prefixed),
);
// Sanity: a chain dominated by bare-prefix Env layers picks
// Bare. Pin the strict-majority case alongside the tie case so
// both halves of the projection are concretely named.
let bare_majority = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("X_".to_owned()),
];
assert_eq!(
bare_majority
.as_slice()
.env_prefix_kind_histogram()
.dominant_cell(),
Some(EnvMetadataTagKind::Bare),
);
}
#[test]
fn chain_histograms_dominant_cell_is_none_on_empty_chain() {
// Empty-chain composition: every chain-level histogram
// (layer_kind / file_format / env_prefix_kind) over an empty
// chain is the all-zero histogram, so `dominant_cell` reads
// None at all three surfaces. Pins the cross-surface
// empty-history convention at one site.
let chain: [ConfigSource; 0] = [];
assert_eq!(chain.layer_kind_histogram().dominant_cell(), None);
assert_eq!(chain.file_format_histogram().dominant_cell(), None);
assert_eq!(chain.env_prefix_kind_histogram().dominant_cell(), None);
}
#[test]
fn layer_kind_histogram_distinct_cells_counts_observed_kinds() {
// Cross-surface pin: the
// [`crate::AxisHistogram::distinct_cells`] projection composes
// with [`Self::layer_kind_histogram`] to read "how many
// distinct layer kinds did this chain contain?" at one
// method-call site. `sample_chain()` is two File layers + one
// Env layer (no Defaults), so distinct_cells = 2 (File, Env).
let chain = sample_chain();
assert_eq!(chain.as_slice().layer_kind_histogram().distinct_cells(), 2);
// Singleton-kind chain: every layer is Defaults, so
// distinct_cells = 1 — the support is the single observed cell.
let defaults_only = vec![ConfigSource::Defaults, ConfigSource::Defaults];
assert_eq!(
defaults_only
.as_slice()
.layer_kind_histogram()
.distinct_cells(),
1,
);
// Axis-cover chain: one layer per kind covers the whole
// [`ConfigSourceKind::ALL`] axis, so distinct_cells equals the
// axis cardinality — the maximum-coverage witness. Reads
// through the named predicate [`AxisHistogram::is_full_cover`]
// — the boolean form of `distinct_cells == axis_cardinality`
// — so the typed full-cover question reaches the chain-level
// histogram without re-deriving the equality at the call site.
let axis_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/etc/app.yaml")),
];
assert!(axis_cover.as_slice().layer_kind_histogram().is_full_cover(),);
}
#[test]
fn file_format_histogram_distinct_cells_counts_observed_formats() {
// Cross-surface pin on the file-format axis: distinct_cells
// counts the *recognized* formats observed in the chain. Env /
// Defaults / unrecognized-extension File entries project to
// None through `file_format()` so they do not contribute, and
// duplicate entries on the same format collapse to one
// distinct cell — the support cardinality is bounded by the
// axis cardinality, not by the layer count.
use crate::discovery::Format;
// Three .yaml + one .toml + Env + Defaults → distinct file
// formats observed = 2 (Yaml, Toml).
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.toml")),
];
let hist = chain.as_slice().file_format_histogram();
assert_eq!(hist.distinct_cells(), 2);
// Companion bound: distinct_cells <= axis_cardinality::<Format>().
assert!(hist.distinct_cells() <= crate::axis_cardinality::<Format>());
// Companion bound: distinct_cells <= total.
assert!(hist.distinct_cells() <= hist.total());
// Env-only chain: no File layer contributes to the format
// histogram, so distinct_cells = 0 — the empty-support
// witness even though the chain is non-empty.
let env_only = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env(String::new()),
];
assert_eq!(
env_only.as_slice().file_format_histogram().distinct_cells(),
0,
);
}
#[test]
fn env_prefix_kind_histogram_distinct_cells_counts_observed_prefix_kinds() {
// Cross-surface pin on the env-prefix-presence axis: a chain
// with both a bare and a prefixed Env layer has distinct_cells
// = 2 — the full axis is covered. A chain with only prefixed
// Env layers reads 1; a File/Defaults-only chain reads 0.
let both = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
// The full-cover witness on the env-prefix axis — reads
// through the named [`AxisHistogram::is_full_cover`] predicate
// rather than the open-coded `distinct_cells ==
// axis_cardinality` equality.
assert!(both.as_slice().env_prefix_kind_histogram().is_full_cover(),);
let prefixed_only = vec![
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("APP_".to_owned()),
ConfigSource::Env("OTHER_".to_owned()),
];
assert_eq!(
prefixed_only
.as_slice()
.env_prefix_kind_histogram()
.distinct_cells(),
1,
);
let no_env = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/x.yaml")),
];
assert_eq!(
no_env
.as_slice()
.env_prefix_kind_histogram()
.distinct_cells(),
0,
);
}
#[test]
fn layer_kind_histogram_recessive_cell_picks_minority_kind() {
// Cross-surface pin: the
// [`crate::AxisHistogram::recessive_cell`] projection composes
// with [`Self::layer_kind_histogram`] to read "the rarest
// observed layer kind in this chain" at one method-call site.
// `sample_chain()` is two File layers + one Env layer (no
// Defaults), so the rarest observed kind is Env. Defaults
// does not appear in the chain (count 0) and is excluded from
// the argmin per the recessive_cell zero-cell-exclusion rule
// — the projection picks the rarest *observed* kind, not the
// overall minimum.
let chain = sample_chain();
assert_eq!(
chain.as_slice().layer_kind_histogram().recessive_cell(),
Some(ConfigSourceKind::Env),
);
}
#[test]
fn file_format_histogram_recessive_cell_picks_minority_format() {
// Cross-surface pin on the file-format axis: a chain of three
// `.yaml` + one `.toml` File layers has rarest observed
// Format = Toml (strict minimum — no tie-breaking required).
// Env / Defaults entries do not contribute (project to None
// through `file_format()`) and the unobserved Lisp / Nix
// formats are at count 0 and excluded from the argmin per
// the recessive_cell zero-cell-exclusion rule.
use crate::discovery::Format;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.toml")),
];
assert_eq!(
chain.as_slice().file_format_histogram().recessive_cell(),
Some(Format::Toml),
);
}
#[test]
fn env_prefix_kind_histogram_recessive_cell_for_mixed_prefix_chain() {
// Cross-surface pin on the env-prefix-presence axis: a chain
// with two `Env(prefix)` (one bare, one prefixed) has
// recessive_cell tied at count 1; tie-breaking by
// `EnvMetadataTagKind::ALL` declaration order (Prefixed,
// Bare) yields Prefixed — identical to `dominant_cell` on
// the same tied input. The two projections coincide on every
// uniform histogram; the pair witnesses that agreement here.
let chain = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("APP_".to_owned()),
];
assert_eq!(
chain
.as_slice()
.env_prefix_kind_histogram()
.recessive_cell(),
Some(EnvMetadataTagKind::Prefixed),
);
// Strict-minority case: a chain dominated by bare-prefix Env
// layers picks Prefixed as the rarest observed cell. Pin the
// strict-minimum case alongside the tie case so both halves
// of the projection are concretely named.
let bare_majority = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
ConfigSource::Env("X_".to_owned()),
];
assert_eq!(
bare_majority
.as_slice()
.env_prefix_kind_histogram()
.recessive_cell(),
Some(EnvMetadataTagKind::Prefixed),
);
}
#[test]
fn chain_histograms_recessive_cell_is_none_on_empty_chain() {
// Empty-chain composition: every chain-level histogram
// (layer_kind / file_format / env_prefix_kind) over an empty
// chain is the all-zero histogram, so `recessive_cell` reads
// None at all three surfaces. Peer to
// `chain_histograms_dominant_cell_is_none_on_empty_chain` —
// the two projections share the same empty-history
// convention.
let chain: [ConfigSource; 0] = [];
assert_eq!(chain.layer_kind_histogram().recessive_cell(), None);
assert_eq!(chain.file_format_histogram().recessive_cell(), None);
assert_eq!(chain.env_prefix_kind_histogram().recessive_cell(), None);
}
#[test]
fn chain_histograms_dominant_and_recessive_agree_on_uniform_singleton_chain() {
// Cross-surface boundary pin: every chain over which a
// chain-level histogram resolves to a single observed cell —
// a Defaults-only chain on layer_kind, a `.yaml`-only chain
// on file_format, a Bare-only Env chain on
// env_prefix_kind — has `dominant_cell == recessive_cell`,
// both pointing at the single observed cell. Peer to the
// cube-side
// `axis_histogram_dominant_and_recessive_agree_on_uniform_axis_cover_for_every_implementor`
// pin — the histogram-side agreement holds on every
// *singleton-support* histogram, not just on the
// axis-cover histograms; pin the chain-side witness here so
// the discipline is named at both surfaces.
use crate::discovery::Format;
// layer_kind: Defaults-only chain → both projections = Defaults.
let defaults_only = vec![ConfigSource::Defaults, ConfigSource::Defaults];
let layer_hist = defaults_only.as_slice().layer_kind_histogram();
assert_eq!(layer_hist.dominant_cell(), Some(ConfigSourceKind::Defaults));
assert_eq!(layer_hist.recessive_cell(), layer_hist.dominant_cell());
// file_format: `.yaml`-only chain → both = Yaml.
let yaml_only = vec![
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
];
let format_hist = yaml_only.as_slice().file_format_histogram();
assert_eq!(format_hist.dominant_cell(), Some(Format::Yaml));
assert_eq!(format_hist.recessive_cell(), format_hist.dominant_cell());
// env_prefix_kind: Bare-only Env chain → both = Bare.
let bare_only = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let env_hist = bare_only.as_slice().env_prefix_kind_histogram();
assert_eq!(env_hist.dominant_cell(), Some(EnvMetadataTagKind::Bare));
assert_eq!(env_hist.recessive_cell(), env_hist.dominant_cell());
}
#[test]
fn chain_histograms_spread_is_zero_on_empty_chain() {
// Empty-chain composition: every chain-level histogram
// (layer_kind / file_format / env_prefix_kind) over an empty
// chain is the all-zero histogram, so `spread` reads 0 at
// all three surfaces — peer to the
// `chain_histograms_dominant_cell_is_none_on_empty_chain`,
// `chain_histograms_recessive_cell_is_none_on_empty_chain`,
// and `chain_histograms_distinct_cells_is_zero_on_empty_chain`
// empty-history conventions. Pins the cross-surface
// empty-history convention for the spread scalar at one site.
let chain: [ConfigSource; 0] = [];
assert_eq!(chain.layer_kind_histogram().spread(), 0);
assert_eq!(chain.file_format_histogram().spread(), 0);
assert_eq!(chain.env_prefix_kind_histogram().spread(), 0);
}
#[test]
fn layer_kind_histogram_spread_reads_distribution_skew() {
// Cross-surface pin: composing [`crate::AxisHistogram::spread`]
// with [`Self::layer_kind_histogram`] reads "how unevenly did
// this chain distribute observations across the observed layer
// kinds?" at one method-call site.
//
// `sample_chain()` has two File layers and one Env layer (no
// Defaults); observed support = {File, Env} with counts
// (File: 2, Env: 1) → peak 2, trough 1, spread 1 — the
// canonical strict-skew shape on a binary observed support.
let chain = sample_chain();
let hist = chain.as_slice().layer_kind_histogram();
assert_eq!(hist.peak_count(), 2);
assert_eq!(hist.trough_count(), 1);
assert_eq!(hist.spread(), 1);
// Singleton-support chain: a Defaults-only chain has one
// observed cell (peak = trough = chain length), spread = 0
// — the structural "balanced observation" boundary on the
// singleton-support shape.
let defaults_only = vec![ConfigSource::Defaults, ConfigSource::Defaults];
assert_eq!(defaults_only.as_slice().layer_kind_histogram().spread(), 0);
// Axis-cover chain (one layer per kind): every cell at 1,
// peak = trough = 1, spread = 0 — the structural balanced
// observation boundary on the maximum-coverage shape.
let axis_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/etc/app.yaml")),
];
assert_eq!(axis_cover.as_slice().layer_kind_histogram().spread(), 0);
}
#[test]
fn layer_kind_histogram_unobserved_lists_unused_layer_kinds() {
// Cross-surface pin: the [`crate::AxisHistogram::unobserved`]
// projection composes with [`Self::layer_kind_histogram`] to
// read "which layer kinds did this chain never realize?" at
// one method-call site. `sample_chain()` is two File layers
// + one Env layer (no Defaults), so the unobserved kinds are
// exactly {Defaults} — the strict-subset coverage-gap case.
use crate::cube::axis_cardinality;
use std::collections::HashSet;
let chain = sample_chain();
let gap: HashSet<ConfigSourceKind> = chain
.as_slice()
.layer_kind_histogram()
.unobserved()
.collect();
assert_eq!(gap, HashSet::from([ConfigSourceKind::Defaults]));
// Defaults-only chain → unobserved = {Env, File}: the dual
// case where the support is the singleton {Defaults} and the
// coverage gap is the rest of the axis.
let defaults_only = vec![ConfigSource::Defaults, ConfigSource::Defaults];
let defaults_gap: HashSet<ConfigSourceKind> = defaults_only
.as_slice()
.layer_kind_histogram()
.unobserved()
.collect();
assert_eq!(
defaults_gap,
HashSet::from([ConfigSourceKind::Env, ConfigSourceKind::File]),
);
// Full-axis cover chain → unobserved is empty: every layer
// kind appears at least once, so there is no coverage gap.
// The dual boundary of the empty-chain case (which is pinned
// in `chain_histograms_unobserved_is_full_axis_on_empty_chain`
// below).
let axis_cover = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/x.yaml")),
];
assert_eq!(
axis_cover
.as_slice()
.layer_kind_histogram()
.unobserved()
.count(),
0,
);
assert_eq!(
axis_cover
.as_slice()
.layer_kind_histogram()
.distinct_cells(),
axis_cardinality::<ConfigSourceKind>(),
);
}
#[test]
fn file_format_histogram_unobserved_lists_unused_formats() {
// Cross-surface pin on the file-format axis: a chain of three
// `.yaml` + one `.toml` File layers + an Env + Defaults has
// observed file-format support {Yaml, Toml}, so the
// coverage gap is the unobserved formats {Lisp, Nix} — the
// strict-subset case. Env / Defaults entries project to
// None through `file_format()` and contribute nothing to the
// histogram total, so they do not enter the support.
use crate::discovery::Format;
use std::collections::HashSet;
let chain = vec![
ConfigSource::Defaults,
ConfigSource::Env("APP_".to_owned()),
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::File(PathBuf::from("/b.yaml")),
ConfigSource::File(PathBuf::from("/c.yaml")),
ConfigSource::File(PathBuf::from("/d.toml")),
];
let gap: HashSet<Format> = chain
.as_slice()
.file_format_histogram()
.unobserved()
.collect();
assert_eq!(gap, HashSet::from([Format::Lisp, Format::Nix]));
// Env-only chain → file_format support is empty, so
// unobserved = full axis = {Yaml, Toml, Lisp, Nix}. Peer to
// the empty-histogram boundary on the cube side: an all-zero
// histogram has every cell unobserved.
let env_only = vec![ConfigSource::Env(String::new())];
let env_only_gap: HashSet<Format> = env_only
.as_slice()
.file_format_histogram()
.unobserved()
.collect();
assert_eq!(env_only_gap, Format::ALL.iter().copied().collect());
}
#[test]
fn env_prefix_kind_histogram_unobserved_lists_unused_prefix_kinds() {
// Cross-surface pin on the env-prefix-presence axis: a
// Bare-only Env chain has env_prefix_kind support {Bare}, so
// the coverage gap is {Prefixed} — the strict-subset case
// peer to the singleton-support pin on `layer_kind_histogram`.
// The dual chain (Prefixed-only) closes the symmetric case.
use std::collections::HashSet;
let bare_only = vec![
ConfigSource::Env(String::new()),
ConfigSource::Env(String::new()),
];
let bare_gap: HashSet<EnvMetadataTagKind> = bare_only
.as_slice()
.env_prefix_kind_histogram()
.unobserved()
.collect();
assert_eq!(bare_gap, HashSet::from([EnvMetadataTagKind::Prefixed]));
let prefixed_only = vec![
ConfigSource::Env("A_".to_owned()),
ConfigSource::Env("B_".to_owned()),
];
let prefixed_gap: HashSet<EnvMetadataTagKind> = prefixed_only
.as_slice()
.env_prefix_kind_histogram()
.unobserved()
.collect();
assert_eq!(prefixed_gap, HashSet::from([EnvMetadataTagKind::Bare]));
// No-Env chain (Defaults + File only) → empty support, so
// unobserved is the full env-prefix-kind axis.
let no_env = vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/x.yaml")),
];
let no_env_gap: HashSet<EnvMetadataTagKind> = no_env
.as_slice()
.env_prefix_kind_histogram()
.unobserved()
.collect();
assert_eq!(
no_env_gap,
EnvMetadataTagKind::ALL.iter().copied().collect(),
);
}
#[test]
fn chain_histograms_unobserved_is_full_axis_on_empty_chain() {
// Empty-chain composition: every chain-level histogram
// (layer_kind / file_format / env_prefix_kind) over an empty
// chain is the all-zero histogram, so `unobserved` iterates
// the full axis at all three surfaces. Peer to
// `chain_histograms_dominant_cell_is_none_on_empty_chain` and
// `chain_histograms_distinct_cells_is_zero_on_empty_chain`:
// the empty-history convention is named at the coverage-gap
// surface as well, with the tight boundary witness
// (`unobserved_cells` reaches every cell because every cell is
// unobserved). Reads through the named scalar
// [`AxisHistogram::unobserved_cells`] — the structural
// complement of [`AxisHistogram::distinct_cells`] over the
// closed axis — rather than the open-coded
// `unobserved().count()` chain.
use crate::cube::axis_cardinality;
let chain: [ConfigSource; 0] = [];
assert_eq!(
chain.layer_kind_histogram().unobserved_cells(),
axis_cardinality::<ConfigSourceKind>(),
);
assert_eq!(
chain.file_format_histogram().unobserved_cells(),
axis_cardinality::<crate::discovery::Format>(),
);
assert_eq!(
chain.env_prefix_kind_histogram().unobserved_cells(),
axis_cardinality::<EnvMetadataTagKind>(),
);
}
#[test]
fn chain_histograms_distinct_cells_is_zero_on_empty_chain() {
// Empty-chain composition: every chain-level histogram
// (layer_kind / file_format / env_prefix_kind) over an empty
// chain is the all-zero histogram, so distinct_cells = 0 at
// all three surfaces. Peer to the
// chain_histograms_dominant_cell_is_none_on_empty_chain pin —
// pins the cross-surface empty-history convention for the
// support-cardinality projection at one site.
let chain: [ConfigSource; 0] = [];
assert_eq!(chain.layer_kind_histogram().distinct_cells(), 0);
assert_eq!(chain.file_format_histogram().distinct_cells(), 0);
assert_eq!(chain.env_prefix_kind_histogram().distinct_cells(), 0);
}
#[test]
fn env_prefix_kind_histogram_total_equals_env_layer_count() {
// Cross-histogram invariant — STRICT equality (no inequality
// bound, unlike the file-format histogram): every Env layer
// projects to a Some cell on env_prefix_kind (empty-prefix →
// Bare, non-empty → Prefixed), so the histogram total is
// exactly the Env count in the layer-kind histogram regardless
// of prefix shape. Pins the stronger structural law between the
// chain's third and first aggregate projections.
let chains: [Vec<ConfigSource>; 5] = [
sample_chain(),
vec![],
vec![ConfigSource::Defaults, ConfigSource::Defaults],
vec![
ConfigSource::Env(String::new()),
ConfigSource::Env("A_".to_owned()),
ConfigSource::Env("B_".to_owned()),
ConfigSource::Env(String::new()),
],
vec![
ConfigSource::Defaults,
ConfigSource::File(PathBuf::from("/a.yaml")),
ConfigSource::Env("E_".to_owned()),
ConfigSource::File(PathBuf::from("/b.unknownext")),
ConfigSource::Env(String::new()),
],
];
for chain in &chains {
let env_kind_count = chain
.as_slice()
.layer_kind_histogram()
.count(ConfigSourceKind::Env);
let env_prefix_total = chain.as_slice().env_prefix_kind_histogram().total();
assert_eq!(
env_prefix_total,
env_kind_count,
"env_prefix_kind_histogram total ({env_prefix_total}) must equal \
layer_kind_histogram(Env) ({env_kind_count}) over chain of length {}",
chain.len(),
);
}
}
// ---- ConfigSourceKind / ConfigSource::kind ----
#[test]
fn kind_classifies_defaults() {
assert_eq!(ConfigSource::Defaults.kind(), ConfigSourceKind::Defaults);
}
#[test]
fn kind_classifies_env_regardless_of_prefix() {
// Inner prefix does not influence kind — every Env variant maps
// to ConfigSourceKind::Env, including the empty-prefix case.
for prefix in ["", "MYAPP_", "X_", "very_long_prefix_with_underscores_"] {
let s = ConfigSource::Env(prefix.to_owned());
assert_eq!(s.kind(), ConfigSourceKind::Env);
}
}
#[test]
fn kind_classifies_file_regardless_of_path() {
// Inner path does not influence kind — every File variant maps
// to ConfigSourceKind::File, including bare and deep paths.
for path in ["/etc/app.yaml", "rel.toml", "/very/deep/path/cfg.lisp"] {
let s = ConfigSource::File(PathBuf::from(path));
assert_eq!(s.kind(), ConfigSourceKind::File);
}
}
#[test]
fn kind_partitions_every_constructible_variant() {
// Every ConfigSource maps to exactly one ConfigSourceKind. Pins
// the partition contract that ConfigSource::kind is a total
// function over the variant space; a new variant added to
// ConfigSource forces a kind assignment in the exhaustive
// match (compile-time), and this test pins that the partition
// is a function (no source maps to two kinds).
let cases: [(ConfigSource, ConfigSourceKind); 3] = [
(ConfigSource::Defaults, ConfigSourceKind::Defaults),
(ConfigSource::Env("X_".to_owned()), ConfigSourceKind::Env),
(
ConfigSource::File(PathBuf::from("/x")),
ConfigSourceKind::File,
),
];
for (src, expected) in &cases {
assert_eq!(src.kind(), *expected);
}
// Distinct sources of the same kind collapse to the same kind
// (the kind discriminant is data-free).
assert_eq!(
ConfigSource::Env("A_".to_owned()).kind(),
ConfigSource::Env("B_".to_owned()).kind(),
);
assert_eq!(
ConfigSource::File(PathBuf::from("/a")).kind(),
ConfigSource::File(PathBuf::from("/b")).kind(),
);
}
#[test]
fn kind_agrees_with_is_predicates_pointwise() {
// The kind() / is_*() pair must agree on every constructible
// variant — kind is the closed-enum lift of the three booleans.
for src in [
ConfigSource::Defaults,
ConfigSource::Env("X_".to_owned()),
ConfigSource::File(PathBuf::from("/x")),
] {
assert_eq!(src.is_defaults(), src.kind() == ConfigSourceKind::Defaults);
assert_eq!(src.is_env(), src.kind() == ConfigSourceKind::Env);
assert_eq!(src.is_file(), src.kind() == ConfigSourceKind::File);
}
}
#[test]
fn config_source_kind_is_copy_and_hashable() {
// Trait-bounds parity with sibling typescape primitives
// (AttributionRule, AttributionConfidence, FigmentSourceTag,
// FigmentNameTag, EnvMetadataTag). Iterates ConfigSourceKind::ALL
// so a future variant landing extends the parity check without
// editing this test.
use std::collections::HashSet;
let mut set: HashSet<ConfigSourceKind> = ConfigSourceKind::ALL.iter().copied().collect();
set.insert(ConfigSourceKind::Defaults); // duplicate
assert_eq!(set.len(), ConfigSourceKind::ALL.len());
// Copy: rebind without move.
let k = ConfigSourceKind::Env;
let k2 = k;
let k3 = k;
assert_eq!(k, k2);
assert_eq!(k2, k3);
}
// ---- ConfigSourceKind::ALL tests ----
#[test]
fn config_source_kind_all_has_no_duplicates() {
// The constant is a set, not a multiset: every variant appears
// at most once. Pins the "no double-listed kind" invariant the
// typescape relies on so consumers iterating ALL never see a
// ghost kind contributing twice to a partition tally over the
// ConfigSource / AttributionRule layer-kind projection.
use std::collections::HashSet;
let unique: HashSet<ConfigSourceKind> = ConfigSourceKind::ALL.iter().copied().collect();
assert_eq!(
unique.len(),
ConfigSourceKind::ALL.len(),
"ConfigSourceKind::ALL must contain no duplicates",
);
}
#[test]
fn config_source_kind_all_covers_every_constructible_variant() {
// Mutual-cover statement: the canonical sample table covers every
// ConfigSourceKind variant exactly once via ConfigSource::kind,
// and ALL equals the same set. A future ConfigSource variant
// landing forces a kind() arm (compile-time, exhaustive match)
// and a sample-table row (here); this test fails until ALL is
// extended in lockstep, catching forgotten ALL updates.
use std::collections::HashSet;
let produced: HashSet<ConfigSourceKind> = [
ConfigSource::Defaults,
ConfigSource::Env("X_".to_owned()),
ConfigSource::File(PathBuf::from("/x")),
]
.iter()
.map(ConfigSource::kind)
.collect();
let listed: HashSet<ConfigSourceKind> = ConfigSourceKind::ALL.iter().copied().collect();
assert_eq!(
produced, listed,
"ConfigSourceKind::ALL must equal the kind set produced by ConfigSource::kind",
);
}
#[test]
fn config_source_kind_all_cardinality_matches_variant_count() {
// Stronger statement of the prior test on the cardinality axis:
// ALL.len() must equal the variant count of the closed partition
// (three: Defaults, Env, File). Stated through the constant
// rather than an inline literal so a future variant landing
// forces a sample-table row + an ALL entry in lockstep.
let produced_count = [
ConfigSource::Defaults,
ConfigSource::Env(String::new()),
ConfigSource::File(PathBuf::from("/x")),
]
.iter()
.map(ConfigSource::kind)
.collect::<std::collections::HashSet<_>>()
.len();
assert_eq!(
ConfigSourceKind::ALL.len(),
produced_count,
"ALL.len() must equal the canonical kind-partition cardinality",
);
}
#[test]
fn config_source_kind_all_iterates_in_declaration_order() {
// The constant lists variants in the same order as the enum's
// declaration arms (Defaults, Env, File). Iteration order is
// observable — consumers (alerting policies, dashboards, miette
// diagnostic renderers) that rely on a stable ordering for
// priority/severity can route on it.
assert_eq!(
ConfigSourceKind::ALL,
&[
ConfigSourceKind::Defaults,
ConfigSourceKind::Env,
ConfigSourceKind::File,
],
"ALL must list variants in declaration order",
);
}
#[test]
fn config_source_kind_as_str_yields_canonical_lowercase_names() {
// Concrete-position pin on ConfigSourceKind::as_str. The
// trait-uniform round-trip test in cube::tests pins labels
// equal pairwise under from_canonical_str, but this test pins
// the literal string values themselves so a future rename
// (e.g. capitalizing "Env", prefixing "layer-env", switching
// "defaults" to "default" — colliding with ConfigTierKind's
// "default" label across axes) fails here before drifting
// through the trait-uniform round-trip law and the
// operator-facing rendering surface.
assert_eq!(ConfigSourceKind::Defaults.as_str(), "defaults");
assert_eq!(ConfigSourceKind::Env.as_str(), "env");
assert_eq!(ConfigSourceKind::File.as_str(), "file");
}
#[test]
fn config_source_kind_from_canonical_str_round_trips_through_trait() {
// Pin the trait-default `from_canonical_str` parse on
// ConfigSourceKind: each canonical lowercase name parses back
// to its variant via the ClosedAxisLabel default impl. The
// canonical-only trait parse is the round-trip dual of
// `as_str`; this pin sits at the ConfigSourceKind site so a
// future override of `from_canonical_str` (none today) is
// still held to the law. Composes with the cross-axis
// distinctness pin in
// `config_source_kind_as_str_yields_canonical_lowercase_names`:
// the three canonical names ("defaults", "env", "file") are
// disjoint from the four ConfigTierKind labels ("bare",
// "discovered", "default", "custom"), so an operator-facing
// surface that routes a string label through both parsers
// sequentially returns at most one Some(_), never both.
use crate::ClosedAxisLabel;
for k in ConfigSourceKind::ALL.iter().copied() {
assert_eq!(
<ConfigSourceKind as ClosedAxisLabel>::from_canonical_str(k.as_str()),
Some(k),
"trait from_canonical_str must round-trip for {k:?}",
);
}
// Case-insensitive parse: the default impl uses
// `eq_ignore_ascii_case`, so mixed-case forms an operator
// might type in an env var or CLI flag reach the same variant.
assert_eq!(
<ConfigSourceKind as ClosedAxisLabel>::from_canonical_str("DEFAULTS"),
Some(ConfigSourceKind::Defaults),
);
assert_eq!(
<ConfigSourceKind as ClosedAxisLabel>::from_canonical_str("Env"),
Some(ConfigSourceKind::Env),
);
assert_eq!(
<ConfigSourceKind as ClosedAxisLabel>::from_canonical_str("FILE"),
Some(ConfigSourceKind::File),
);
// Unrecognized strings return None — the parse is closed over
// `ConfigSourceKind::ALL` and rejects anything else, including
// the singular form of "defaults" (a one-character drift).
assert_eq!(
<ConfigSourceKind as ClosedAxisLabel>::from_canonical_str("default"),
None,
);
assert_eq!(
<ConfigSourceKind as ClosedAxisLabel>::from_canonical_str("http"),
None,
);
}
#[test]
fn config_source_kind_all_covers_every_attribution_rule_layer_kind() {
// Cross-axis coverage: every AttributionRule's layer_kind() is a
// ConfigSourceKind that appears in ALL. Pins the structural
// alignment between the rule space's layer-kind projection and
// the layer-kind universe — a future rule landing with a
// layer_kind that ALL doesn't list fails this test before any
// observation site can silently bucket it as "unknown".
use std::collections::HashSet;
let rule_kinds: HashSet<ConfigSourceKind> = crate::error::AttributionRule::ALL
.iter()
.map(|r| r.layer_kind())
.collect();
let listed: HashSet<ConfigSourceKind> = ConfigSourceKind::ALL.iter().copied().collect();
assert!(
rule_kinds.is_subset(&listed),
"every AttributionRule::layer_kind() must appear in ConfigSourceKind::ALL: \
rule_kinds={rule_kinds:?}, listed={listed:?}",
);
}
#[test]
fn config_source_kind_ord_matches_all_declaration_order() {
// The derived Ord on ConfigSourceKind is declaration-order lex
// over ALL: `Defaults < Env < File`. A BTreeMap keyed on the
// layer-kind axis (per-kind attribution histograms, per-kind
// failure-rate dashboards, attestation manifests recording the
// layer-kind cardinality mix of a recorded chain) emits rows in
// that order deterministically without a hand-rolled comparator
// at the renderer.
//
// Two-leg pin: (1) ALL is a strictly-increasing chain under Ord,
// (2) cmp/partial_cmp agree with the array-index lex over ALL on
// every pair (and reflexivity holds).
use std::cmp::Ordering;
for window in ConfigSourceKind::ALL.windows(2) {
assert!(
window[0] < window[1],
"ConfigSourceKind::ALL must be strictly increasing under Ord, \
but {:?} >= {:?}",
window[0],
window[1],
);
}
for (i, &a) in ConfigSourceKind::ALL.iter().enumerate() {
for (j, &b) in ConfigSourceKind::ALL.iter().enumerate() {
let expected = i.cmp(&j);
assert_eq!(
a.cmp(&b),
expected,
"ConfigSourceKind::cmp must match ALL-index lex for ({a:?}, {b:?})",
);
assert_eq!(
a.partial_cmp(&b),
Some(expected),
"ConfigSourceKind::partial_cmp must agree with cmp for ({a:?}, {b:?})",
);
if i == j {
assert_eq!(a.cmp(&b), Ordering::Equal, "Ord must be reflexive on {a:?}",);
}
}
}
}
#[test]
fn config_source_kind_btreemap_emits_in_declaration_order() {
// The compounding payoff of the Ord derive at a typed consumer
// site: a BTreeMap<ConfigSourceKind, _> emits keys in
// declaration order on `iter()` / `into_iter()` regardless of
// insertion order, matching `ConfigSourceKind::ALL`. Idiom-peer
// of the same pin on FormatProvenance (commit `2c7654c`) and on
// FormatMetadataTag (commit `fc0051e`).
use std::collections::BTreeMap;
let mut counts: BTreeMap<ConfigSourceKind, u32> = BTreeMap::new();
counts.insert(ConfigSourceKind::File, 3);
counts.insert(ConfigSourceKind::Defaults, 1);
counts.insert(ConfigSourceKind::Env, 2);
let observed: Vec<ConfigSourceKind> = counts.keys().copied().collect();
assert_eq!(
observed,
ConfigSourceKind::ALL.to_vec(),
"BTreeMap<ConfigSourceKind, _> must emit keys in ALL declaration order",
);
}
#[test]
fn config_source_kind_display_matches_as_str() {
// Display writes the canonical lowercase label as_str returns,
// byte-for-byte. The two surfaces stay aligned by construction
// — a future rename of either must update the other in lockstep.
for k in ConfigSourceKind::ALL.iter().copied() {
assert_eq!(
format!("{k}"),
k.as_str(),
"Display must agree with as_str for {k:?}",
);
}
}
#[test]
fn config_source_kind_from_str_round_trips_over_every_variant() {
// Display → FromStr identity round-trip over every variant.
// FromStr lowers through ClosedAxisLabel::from_canonical_str,
// so any future override of that trait method is held to this
// law at the inherent FromStr surface as well.
for k in ConfigSourceKind::ALL {
let rendered = k.to_string();
let parsed: ConfigSourceKind = rendered
.parse()
.expect("FromStr must round-trip Display output");
assert_eq!(parsed, *k, "FromStr must round-trip {k:?}");
}
}
#[test]
fn config_source_kind_from_str_is_case_insensitive() {
// FromStr lowers through ClosedAxisLabel::from_canonical_str
// which uses eq_ignore_ascii_case over ALL — uppercase and
// mixed-case scalars an operator might type into an env var or
// CLI flag parse pointwise to the same variant.
assert_eq!(
"DEFAULTS".parse::<ConfigSourceKind>().unwrap(),
ConfigSourceKind::Defaults,
);
assert_eq!(
"Env".parse::<ConfigSourceKind>().unwrap(),
ConfigSourceKind::Env,
);
assert_eq!(
"FILE".parse::<ConfigSourceKind>().unwrap(),
ConfigSourceKind::File,
);
}
#[test]
fn config_source_kind_from_str_unknown_kind_error_carries_label_verbatim() {
// Unrecognized labels reject through ShikumiError::Parse with
// the offending substring embedded verbatim in the rendered
// message — same verbatim-rejection discipline as
// FormatProvenance's FromStr surface (commit `2c7654c`) and
// ParseFormatCoordinatesError (commit `06a2f42`).
for bad in &["default", "http", "vault", "", " env"] {
let err = bad
.parse::<ConfigSourceKind>()
.expect_err("non-canonical label must reject");
let rendered = err.to_string();
assert!(
rendered.contains(bad),
"rendered error must contain the offending label verbatim: \
input={bad:?}, rendered={rendered:?}",
);
}
}
#[test]
fn config_source_kind_serde_yaml_round_trips_over_every_variant() {
// Serde Serialize → Deserialize identity round-trip over every
// variant through serde_yaml. Closes the (Serialize, Deserialize)
// idiom-peer of the (Display, FromStr) stdlib pair on the layer-
// kind axis. A consumer struct holding a ConfigSourceKind field
// under #[derive(Serialize, Deserialize)] (e.g. an attestation
// manifest recording the layer-kind of a failing attribution)
// round-trips without a consumer-side rename helper.
for k in ConfigSourceKind::ALL {
let yaml = serde_yaml::to_string(k).expect("Serialize must succeed");
let parsed: ConfigSourceKind =
serde_yaml::from_str(&yaml).expect("Deserialize must accept Serialize output");
assert_eq!(parsed, *k, "serde_yaml round-trip must preserve {k:?}");
}
}
#[test]
fn config_source_kind_serde_json_round_trips_over_every_variant() {
// Serde Serialize → Deserialize identity round-trip over every
// variant through serde_json. The two formats render the
// canonical scalar identically modulo wire ceremony (YAML's
// bare scalar vs. JSON's quoted string), so the round-trip law
// composes pointwise — a future divergence in either Serialize
// impl surfaces here.
for k in ConfigSourceKind::ALL {
let json = serde_json::to_string(k).expect("Serialize must succeed");
let parsed: ConfigSourceKind =
serde_json::from_str(&json).expect("Deserialize must accept Serialize output");
assert_eq!(parsed, *k, "serde_json round-trip must preserve {k:?}");
}
}
#[test]
fn config_source_kind_serde_yaml_is_case_insensitive() {
// Deserialize lowers through FromStr which lowers through
// ClosedAxisLabel::from_canonical_str (eq_ignore_ascii_case),
// so uppercase or mixed-case scalars parse pointwise. A
// manifest field authored by an operator typing the canonical
// name with different casing parses without a consumer-side
// case-fold helper.
let cases: &[(&str, ConfigSourceKind)] = &[
("Defaults", ConfigSourceKind::Defaults),
("ENV", ConfigSourceKind::Env),
("File", ConfigSourceKind::File),
];
for (input, expected) in cases {
let parsed: ConfigSourceKind =
serde_yaml::from_str(input).expect("case-insensitive Deserialize must succeed");
assert_eq!(
parsed, *expected,
"serde_yaml must parse case-insensitively for input {input:?}",
);
}
}
#[test]
fn config_source_kind_serde_yaml_unknown_kind_error_carries_label_verbatim() {
// An unrecognized layer-kind label surfaces at the serde error
// site with the offending substring verbatim in the rendered
// message, lifted through ShikumiError::Parse's Display impl.
// Same verbatim-rejection discipline as FormatProvenance's
// serde surface (commit `2c7654c`) and Format's serde surface
// (commit `b56b121`).
for bad in &["http", "vault", "default", "configmap"] {
let err = serde_yaml::from_str::<ConfigSourceKind>(bad)
.expect_err("non-canonical label must reject");
let rendered = err.to_string();
assert!(
rendered.contains(bad),
"rendered serde error must contain the offending label verbatim: \
input={bad:?}, rendered={rendered:?}",
);
}
}
// ---- env_metadata_name / strip_env_metadata_name ----
#[test]
fn env_metadata_name_empty_prefix_yields_bare_shape() {
// Mirrors figment's `Env::raw()` shape (no backtick wrapper).
assert_eq!(
ConfigSource::env_metadata_name(""),
"environment variable(s)"
);
}
#[test]
fn env_metadata_name_uppercases_prefix_to_match_figment() {
// figment uppercases the prefix when emitting metadata; the
// constructor must match that discipline so round-trip works
// regardless of the casing the user passed to `with_env`.
assert_eq!(
ConfigSource::env_metadata_name("myapp_"),
"`MYAPP_` environment variable(s)"
);
assert_eq!(
ConfigSource::env_metadata_name("MyApp_"),
"`MYAPP_` environment variable(s)"
);
assert_eq!(
ConfigSource::env_metadata_name("APP_"),
"`APP_` environment variable(s)"
);
}
#[test]
fn strip_env_metadata_name_recognizes_prefixed_shape() {
let tag = ConfigSource::strip_env_metadata_name("`MYAPP_` environment variable(s)");
assert_eq!(tag, Some(EnvMetadataTag::Prefixed("MYAPP_")));
}
#[test]
fn strip_env_metadata_name_recognizes_bare_shape() {
let tag = ConfigSource::strip_env_metadata_name("environment variable(s)");
assert_eq!(tag, Some(EnvMetadataTag::Bare));
}
#[test]
fn strip_env_metadata_name_accepts_singular_form() {
// The recognition contract says `contains("environment variable")`,
// so figment's `(s)` parens are optional from the parser's POV.
let tag = ConfigSource::strip_env_metadata_name("`X_` environment variable");
assert_eq!(tag, Some(EnvMetadataTag::Prefixed("X_")));
}
#[test]
fn strip_env_metadata_name_rejects_unrelated_strings() {
for name in [
"",
"/etc/app/app.yaml",
"lisp: /etc/app.lisp",
"nix: /etc/app.nix",
"yaml",
"`MYAPP_` something else",
"envvar `X_` typo",
] {
assert!(
ConfigSource::strip_env_metadata_name(name).is_none(),
"unrelated metadata name `{name}` must not match env tag"
);
}
}
#[test]
fn env_metadata_name_round_trip_for_prefixed_form() {
// The constructor and inverse must compose to identity on the
// prefix (modulo case-folding, which figment performs).
for prefix in ["MYAPP_", "TOBIRA_", "X_", "FOO_BAR_"] {
let name = ConfigSource::env_metadata_name(prefix);
let tag = ConfigSource::strip_env_metadata_name(&name)
.expect("constructor output must round-trip through inverse");
assert_eq!(tag, EnvMetadataTag::Prefixed(prefix));
}
}
#[test]
fn env_metadata_name_round_trip_for_bare_form() {
let name = ConfigSource::env_metadata_name("");
let tag = ConfigSource::strip_env_metadata_name(&name).expect("bare must round-trip");
assert_eq!(tag, EnvMetadataTag::Bare);
}
#[test]
fn strip_env_metadata_name_borrows_into_input() {
// The prefix slice must be a sub-borrow of the input, not a
// fresh allocation — observable via pointer arithmetic.
let name = ConfigSource::env_metadata_name("MYAPP_");
let EnvMetadataTag::Prefixed(prefix) =
ConfigSource::strip_env_metadata_name(&name).expect("prefixed shape must match")
else {
panic!("expected prefixed variant");
};
let name_start = name.as_ptr() as usize;
let name_end = name_start + name.len();
let prefix_start = prefix.as_ptr() as usize;
assert!(
prefix_start >= name_start && prefix_start < name_end,
"prefix must borrow into input"
);
}
#[test]
fn strip_env_metadata_name_round_trips_through_figment_emission() {
// Pin the contract that figment's `Env` provider emits the
// exact shape this primitive recognizes. If figment changes
// its emission, this test breaks before the resolver does.
use figment::Provider;
for prefix in ["MYAPP_", "TOBIRA_", "X_"] {
let env = figment::providers::Env::prefixed(prefix);
let md = env.metadata();
let name: &str = md.name.as_ref();
let tag = ConfigSource::strip_env_metadata_name(name)
.expect("figment Env metadata-name must match env-tag shape");
assert_eq!(tag, EnvMetadataTag::Prefixed(prefix));
}
}
#[test]
fn env_metadata_name_matches_figment_emission_byte_for_byte() {
// Stronger invariant: shikumi's constructor produces the same
// bytes figment emits, so the cross-side contract holds at the
// level of equality, not just recognition.
use figment::Provider;
for prefix in ["MYAPP_", "TOBIRA_", "X_"] {
let figment_name = figment::providers::Env::prefixed(prefix)
.metadata()
.name
.into_owned();
let shikumi_name = ConfigSource::env_metadata_name(prefix);
assert_eq!(
figment_name, shikumi_name,
"shikumi's env_metadata_name must match figment's emission"
);
}
}
#[test]
fn strip_env_metadata_name_disjoint_from_format_strip() {
// The two strip-name primitives must partition the metadata-name
// space cleanly — a Format tag must never be misrecognized as an
// env tag, and vice versa.
use crate::discovery::Format;
for f in Format::ALL.iter().filter(|f| f.has_shikumi_provider()) {
let name = f.metadata_name(Path::new("/etc/app.cfg"));
assert!(
ConfigSource::strip_env_metadata_name(&name).is_none(),
"format tag `{name}` must not be recognized as env tag"
);
}
for prefix in ["MYAPP_", ""] {
let name = ConfigSource::env_metadata_name(prefix);
assert!(
Format::strip_metadata_name(&name).is_none(),
"env tag `{name}` must not be recognized as format tag"
);
}
}
// ---- FigmentSourceTag::classify ----
#[test]
fn figment_source_tag_classifies_file_path() {
let src = figment::Source::File(PathBuf::from("/etc/app/app.yaml"));
let tag = FigmentSourceTag::classify(&src).expect("File source must classify");
assert_eq!(tag, FigmentSourceTag::File(Path::new("/etc/app/app.yaml")));
assert_eq!(tag.as_file_path(), Some(Path::new("/etc/app/app.yaml")));
assert!(!tag.is_code());
assert_eq!(tag.as_custom(), None);
}
#[test]
fn figment_source_tag_classifies_code_location() {
// Source::Code carries a `&'static Location<'static>`; constructing
// one via `Location::caller()` works inside `#[track_caller]`-ish
// paths but is fiddly outside them. Use the Serialized provider
// (which figment tags with `Source::Code`) to obtain a real one.
use figment::Provider;
let provider = figment::providers::Serialized::defaults(serde_json::json!({"k": "v"}));
let md = provider.metadata();
let src = md.source.as_ref().expect("Serialized attaches a source");
let tag = FigmentSourceTag::classify(src).expect("Code source must classify");
assert!(
matches!(tag, FigmentSourceTag::Code(_)),
"expected Code variant, got {tag:?}"
);
assert!(tag.is_code());
assert_eq!(tag.as_file_path(), None);
assert_eq!(tag.as_custom(), None);
}
#[test]
fn figment_source_tag_classifies_custom() {
let src = figment::Source::Custom("ftp://configs.example.com/app.yaml".to_owned());
let tag = FigmentSourceTag::classify(&src).expect("Custom source must classify");
assert_eq!(
tag,
FigmentSourceTag::Custom("ftp://configs.example.com/app.yaml")
);
assert_eq!(tag.as_custom(), Some("ftp://configs.example.com/app.yaml"));
assert!(!tag.is_code());
assert_eq!(tag.as_file_path(), None);
}
#[test]
fn figment_source_tag_borrows_into_input_for_file() {
// The path slice must be a sub-borrow of the input PathBuf, not a
// fresh allocation — observable via pointer arithmetic.
let src = figment::Source::File(PathBuf::from("/etc/app/app.yaml"));
let FigmentSourceTag::File(borrowed) =
FigmentSourceTag::classify(&src).expect("File classify")
else {
panic!("expected File variant");
};
let figment::Source::File(ref owned) = src else {
unreachable!()
};
let owned_start = owned.as_os_str().as_encoded_bytes().as_ptr() as usize;
let owned_end = owned_start + owned.as_os_str().as_encoded_bytes().len();
let borrowed_start = borrowed.as_os_str().as_encoded_bytes().as_ptr() as usize;
assert!(
borrowed_start >= owned_start && borrowed_start < owned_end,
"path must borrow into source"
);
}
#[test]
fn figment_source_tag_borrows_into_input_for_custom() {
let src = figment::Source::Custom("vault://kv/app".to_owned());
let FigmentSourceTag::Custom(c) =
FigmentSourceTag::classify(&src).expect("Custom classify")
else {
panic!("expected Custom variant");
};
let figment::Source::Custom(ref s) = src else {
unreachable!()
};
let s_start = s.as_ptr() as usize;
let s_end = s_start + s.len();
let c_start = c.as_ptr() as usize;
assert!(
c_start >= s_start && c_start < s_end,
"custom slice must borrow into source"
);
}
#[test]
fn figment_source_tag_classify_round_trips_through_yaml_provider() {
// Pin the cross-side contract that figment's YAML file provider
// attaches a Source::File which classifies as
// FigmentSourceTag::File(<path>). If figment changes the shape it
// attaches to file-based providers, this test breaks before the
// resolver does.
use figment::providers::Format as _;
let dir = tempfile::TempDir::new().unwrap();
let file = dir.path().join("c.yaml");
std::fs::write(&file, "k: v\n").unwrap();
let figment = figment::Figment::new().merge(figment::providers::Yaml::file(&file));
let value: figment::value::Value = figment.find_value("k").unwrap();
let tag = figment.get_metadata(value.tag()).unwrap();
let src = tag.source.as_ref().expect("Yaml::file attaches a source");
let classified = FigmentSourceTag::classify(src).expect("Yaml file source must classify");
assert_eq!(classified, FigmentSourceTag::File(file.as_path()));
}
#[test]
fn figment_source_tag_classify_round_trips_through_serialized_provider() {
// The Serialized provider — which `ProviderChain::with_defaults`
// routes through — must attach a Source::Code that classifies
// as FigmentSourceTag::Code(_). Pinning this end-to-end ensures
// resolve_failing_source's `Code → defaults` arm stays honest.
use figment::Provider;
let prov = figment::providers::Serialized::defaults(serde_json::json!({"name": "default"}));
let md = prov.metadata();
let src = md
.source
.as_ref()
.expect("Serialized attaches a Source::Code");
let tag = FigmentSourceTag::classify(src).expect("Code source must classify");
assert!(tag.is_code(), "Serialized must classify as Code");
}
#[test]
fn figment_source_tag_variants_are_disjoint() {
// Each Source variant must classify into exactly one
// FigmentSourceTag variant — no Source can claim two tags at once.
let file_src = figment::Source::File(PathBuf::from("/x"));
let custom_src = figment::Source::Custom("c".to_owned());
let file_tag = FigmentSourceTag::classify(&file_src).unwrap();
let custom_tag = FigmentSourceTag::classify(&custom_src).unwrap();
assert!(file_tag.as_file_path().is_some() && !file_tag.is_code());
assert!(file_tag.as_custom().is_none());
assert!(custom_tag.as_custom().is_some() && !custom_tag.is_code());
assert!(custom_tag.as_file_path().is_none());
}
// ---- FigmentNameTag::classify ----
#[test]
fn figment_name_tag_classifies_format_metadata_name() {
// shikumi-built provider's "<format>: <path>" shape must
// route to the Format variant for every Format whose
// has_shikumi_provider() is true.
use crate::discovery::Format;
let path = Path::new("/etc/app/app.cfg");
for f in Format::ALL.iter().filter(|f| f.has_shikumi_provider()) {
let name = f.metadata_name(path);
let tag = FigmentNameTag::classify(&name).expect("format tag must classify");
let inner = tag.as_format().expect("expected Format variant");
assert_eq!(inner.format, *f);
assert_eq!(inner.path, path);
assert!(tag.as_env().is_none(), "Format must not also be Env");
}
}
#[test]
fn figment_name_tag_classifies_env_prefixed() {
let name = ConfigSource::env_metadata_name("MYAPP_");
let tag = FigmentNameTag::classify(&name).expect("env-prefixed must classify");
assert_eq!(tag, FigmentNameTag::Env(EnvMetadataTag::Prefixed("MYAPP_")));
assert_eq!(tag.as_env(), Some(EnvMetadataTag::Prefixed("MYAPP_")));
assert!(tag.as_format().is_none(), "Env must not also be Format");
}
#[test]
fn figment_name_tag_classifies_env_bare() {
let name = ConfigSource::env_metadata_name("");
let tag = FigmentNameTag::classify(&name).expect("env-bare must classify");
assert_eq!(tag, FigmentNameTag::Env(EnvMetadataTag::Bare));
assert_eq!(tag.as_env(), Some(EnvMetadataTag::Bare));
assert!(tag.as_format().is_none());
}
#[test]
fn figment_name_tag_returns_none_for_unrelated() {
for name in [
"",
"/etc/app/app.yaml", // figment Yaml provider's name shape
"/var/lib/app.toml",
"default", // figment Serialized's typical name
"yaml", // bare format token, missing colon-space
"json: /x.cfg", // recognized format token but Json is not a Format
"envvar `X_`", // env-shaped but missing the literal substring
] {
assert!(
FigmentNameTag::classify(name).is_none(),
"unrelated metadata name `{name}` must not classify"
);
}
}
#[test]
fn figment_name_tag_variants_are_disjoint() {
// Every recognized name must classify into exactly one
// FigmentNameTag variant — no name can claim both Format and
// Env. Mirrors the FigmentSourceTag disjointness invariant on
// the source axis, and pins the disjointness contract that
// `classify`'s sequential dispatch relies on.
use crate::discovery::Format;
for f in Format::ALL.iter().filter(|f| f.has_shikumi_provider()) {
let name = f.metadata_name(Path::new("/etc/app.cfg"));
let tag = FigmentNameTag::classify(&name).expect("format tag classifies");
assert!(tag.as_format().is_some());
assert!(tag.as_env().is_none());
}
for prefix in ["MYAPP_", ""] {
let name = ConfigSource::env_metadata_name(prefix);
let tag = FigmentNameTag::classify(&name).expect("env tag classifies");
assert!(tag.as_env().is_some());
assert!(tag.as_format().is_none());
}
}
#[test]
fn figment_name_tag_format_borrows_into_input() {
// The path slice inside the Format envelope must be a
// sub-borrow of the input metadata-name string — Path::new
// preserves the byte borrow.
use crate::discovery::Format;
let name = Format::Nix.metadata_name(Path::new("/etc/app/app.nix"));
let tag = FigmentNameTag::classify(&name).expect("classify");
let FigmentNameTag::Format(inner) = tag else {
panic!("expected Format variant");
};
let name_start = name.as_ptr() as usize;
let name_end = name_start + name.len();
let path_bytes = inner.path.as_os_str().as_encoded_bytes();
let path_start = path_bytes.as_ptr() as usize;
assert!(
path_start >= name_start && path_start < name_end,
"Format.path must borrow into input"
);
}
#[test]
fn figment_name_tag_env_borrows_into_input() {
let name = ConfigSource::env_metadata_name("BORROW_");
let tag = FigmentNameTag::classify(&name).expect("classify");
let FigmentNameTag::Env(EnvMetadataTag::Prefixed(prefix)) = tag else {
panic!("expected Env(Prefixed) variant");
};
let name_start = name.as_ptr() as usize;
let name_end = name_start + name.len();
let prefix_start = prefix.as_ptr() as usize;
assert!(
prefix_start >= name_start && prefix_start < name_end,
"Env(Prefixed) must borrow into input"
);
}
#[test]
fn figment_name_tag_round_trips_through_figment_env_emission() {
// Pin the cross-side contract: figment's Env provider emits
// exactly the shape FigmentNameTag::Env recognizes. If figment
// changes its emission, this test breaks before the resolver
// does.
use figment::Provider;
for prefix in ["MYAPP_", "TOBIRA_", "X_"] {
let env = figment::providers::Env::prefixed(prefix);
let md = env.metadata();
let name: &str = md.name.as_ref();
let tag = FigmentNameTag::classify(name).expect("figment Env name must classify");
assert_eq!(tag, FigmentNameTag::Env(EnvMetadataTag::Prefixed(prefix)));
}
}
#[test]
fn figment_name_tag_round_trips_through_format_emission() {
// The complementary cross-side contract: every shikumi-built
// provider variant's emitted metadata-name classifies as
// FigmentNameTag::Format with the same format and path.
use crate::discovery::Format;
for f in Format::ALL.iter().filter(|f| f.has_shikumi_provider()) {
let path = Path::new("/etc/app/app.cfg");
let name = f.metadata_name(path);
let tag = FigmentNameTag::classify(&name).expect("format-emitted name classifies");
let inner = tag.as_format().expect("Format variant");
assert_eq!(inner.format, *f);
assert_eq!(inner.path, path);
}
}
#[test]
fn figment_name_tag_is_copy_and_hashable() {
use std::collections::HashSet;
// Copy: rebind without move.
let n1 = ConfigSource::env_metadata_name("X_");
let t1 = FigmentNameTag::classify(&n1).unwrap();
let t2 = t1;
let t3 = t1;
assert_eq!(t1, t2);
assert_eq!(t2, t3);
// Hash: distinct shapes hash to distinct buckets in a HashSet.
let mut set = HashSet::new();
let np = ConfigSource::env_metadata_name("MYAPP_");
let nb = ConfigSource::env_metadata_name("");
let nf = crate::discovery::Format::Nix.metadata_name(Path::new("/a.nix"));
set.insert(FigmentNameTag::classify(&np).unwrap());
set.insert(FigmentNameTag::classify(&nb).unwrap());
set.insert(FigmentNameTag::classify(&nf).unwrap());
assert_eq!(set.len(), 3);
}
// ---- FigmentSourceKind / FigmentSourceTag::kind ----
#[test]
fn figment_source_kind_classifies_each_variant() {
// The forward map is exhaustive: every FigmentSourceTag variant
// pins to exactly one FigmentSourceKind. Pairs with the
// `kind_partitions_every_constructible_variant` style on
// ConfigSource → ConfigSourceKind.
let file_src = figment::Source::File(PathBuf::from("/etc/app/app.yaml"));
let file_tag = FigmentSourceTag::classify(&file_src).unwrap();
assert_eq!(file_tag.kind(), FigmentSourceKind::File);
// Source::Code arrives via the Serialized provider.
use figment::Provider;
let prov = figment::providers::Serialized::defaults(serde_json::json!({"k": "v"}));
let md = prov.metadata();
let code_src = md.source.as_ref().unwrap();
let code_tag = FigmentSourceTag::classify(code_src).unwrap();
assert_eq!(code_tag.kind(), FigmentSourceKind::Code);
let custom_src = figment::Source::Custom("vault://kv/app".to_owned());
let custom_tag = FigmentSourceTag::classify(&custom_src).unwrap();
assert_eq!(custom_tag.kind(), FigmentSourceKind::Custom);
}
#[test]
fn figment_source_kind_is_data_free() {
// Inner data does not influence kind — every File maps to
// FigmentSourceKind::File regardless of path; Custom regardless
// of string. Mirrors `kind_classifies_file_regardless_of_path`
// on the ConfigSource side.
for path in ["/a", "/very/long/path/to/cfg.yaml", "rel.toml"] {
let src = figment::Source::File(PathBuf::from(path));
assert_eq!(
FigmentSourceTag::classify(&src).unwrap().kind(),
FigmentSourceKind::File,
);
}
for s in ["", "a", "vault://kv/x", "ftp://configs"] {
let src = figment::Source::Custom(s.to_owned());
assert_eq!(
FigmentSourceTag::classify(&src).unwrap().kind(),
FigmentSourceKind::Custom,
);
}
}
#[test]
fn figment_source_kind_agrees_with_predicates_pointwise() {
// The kind() / is_*() pair must agree on every constructible
// tag variant — kind is the closed-enum lift of the open-coded
// booleans.
use figment::Provider;
let file_src = figment::Source::File(PathBuf::from("/x"));
let custom_src = figment::Source::Custom("c".to_owned());
let prov = figment::providers::Serialized::defaults(serde_json::json!({"k": "v"}));
let md = prov.metadata();
let code_src = md.source.as_ref().unwrap();
for tag in [
FigmentSourceTag::classify(&file_src).unwrap(),
FigmentSourceTag::classify(code_src).unwrap(),
FigmentSourceTag::classify(&custom_src).unwrap(),
] {
assert_eq!(tag.is_code(), tag.kind() == FigmentSourceKind::Code);
assert_eq!(
tag.as_file_path().is_some(),
tag.kind() == FigmentSourceKind::File,
);
assert_eq!(
tag.as_custom().is_some(),
tag.kind() == FigmentSourceKind::Custom,
);
// Kind-side predicates agree pointwise with the tag-side
// predicates.
assert_eq!(tag.kind().is_file(), tag.kind() == FigmentSourceKind::File);
assert_eq!(tag.kind().is_code(), tag.kind() == FigmentSourceKind::Code);
assert_eq!(
tag.kind().is_custom(),
tag.kind() == FigmentSourceKind::Custom,
);
}
}
#[test]
fn figment_source_kind_is_static_and_copy_and_hashable() {
// The discriminant is `'static` (no lifetime parameter) so it
// can cross thread boundaries the borrowed tag cannot. Trait
// bounds match the sibling typescape primitives
// (ConfigSourceKind, AttributionRule, AttributionConfidence,
// AttributionAxis).
use std::collections::HashSet;
let mut set: HashSet<FigmentSourceKind> = HashSet::new();
for k in FigmentSourceKind::ALL.iter().copied() {
set.insert(k);
}
set.insert(FigmentSourceKind::File); // duplicate
assert_eq!(set.len(), FigmentSourceKind::ALL.len());
// Copy: rebind without move.
let k = FigmentSourceKind::Code;
let k2 = k;
let k3 = k;
assert_eq!(k, k2);
assert_eq!(k2, k3);
// Send + Sync + 'static — observable by inserting into a static
// bound: a HashSet<K> requires K: Hash + Eq, and the set itself
// is movable across threads since K has no lifetime.
fn assert_static<T: 'static>() {}
assert_static::<FigmentSourceKind>();
}
#[test]
fn figment_source_kind_partitions_disjointly() {
// Each FigmentSourceTag must classify into exactly one
// FigmentSourceKind — no tag claims two kinds at once. Mirrors
// the disjointness invariants on FigmentSourceTag (the borrowed
// form) and ConfigSource (the shikumi-side form).
use figment::Provider;
let prov = figment::providers::Serialized::defaults(serde_json::json!({"k": "v"}));
let md = prov.metadata();
let cases: [(FigmentSourceTag<'_>, FigmentSourceKind); 3] = [
(
FigmentSourceTag::File(Path::new("/x")),
FigmentSourceKind::File,
),
(
FigmentSourceTag::Code(
md.source
.as_ref()
.and_then(figment::Source::code_location)
.unwrap(),
),
FigmentSourceKind::Code,
),
(FigmentSourceTag::Custom("c"), FigmentSourceKind::Custom),
];
for (tag, expected) in cases {
assert_eq!(tag.kind(), expected);
// Distinct tags of the same kind collapse to the same kind
// (the kind discriminant is data-free).
}
assert_eq!(
FigmentSourceTag::File(Path::new("/a")).kind(),
FigmentSourceTag::File(Path::new("/b")).kind(),
);
}
#[test]
fn figment_source_tag_attribution_axis_is_always_metadata_source() {
// Structural law: every FigmentSourceTag classification sits on
// the metadata.source axis. This is the cross-primitive bridge
// between FigmentSourceTag and AttributionAxis — peers with
// FigmentNameTag's implicit always-MetadataName placement.
use crate::AttributionAxis;
use figment::Provider;
let file_src = figment::Source::File(PathBuf::from("/etc/app.yaml"));
let custom_src = figment::Source::Custom("c".to_owned());
let prov = figment::providers::Serialized::defaults(serde_json::json!({"k": "v"}));
let md = prov.metadata();
let code_src = md.source.as_ref().unwrap();
for tag in [
FigmentSourceTag::classify(&file_src).unwrap(),
FigmentSourceTag::classify(code_src).unwrap(),
FigmentSourceTag::classify(&custom_src).unwrap(),
] {
assert_eq!(tag.attribution_axis(), AttributionAxis::MetadataSource);
}
}
#[test]
fn figment_source_kind_round_trips_through_classify() {
// End-to-end: classify a real figment::Source, project to kind,
// and confirm the kind matches the originating Source variant.
// Pins the cross-side contract that classify + kind agree with
// figment's own variant taxonomy.
let file = figment::Source::File(PathBuf::from("/x.yaml"));
let custom = figment::Source::Custom("y".to_owned());
assert_eq!(
FigmentSourceTag::classify(&file).unwrap().kind(),
FigmentSourceKind::File,
);
assert_eq!(
FigmentSourceTag::classify(&custom).unwrap().kind(),
FigmentSourceKind::Custom,
);
}
// ---- FigmentSourceKind::ALL cover / partition / order ----
/// Canonical sample table covering every `FigmentSourceTag` variant
/// once, with the kind each must classify into. Sources for the
/// `figment_source_kind_all_*` cover/partition tests below — peer
/// to the inline `[(Tag, Kind); 3]` cases in
/// `figment_source_kind_partitions_disjointly`.
fn canonical_figment_source_kind_samples() -> Vec<(figment::Source, FigmentSourceKind)> {
use figment::Provider;
let prov = figment::providers::Serialized::defaults(serde_json::json!({"k": "v"}));
let code_src = prov.metadata().source.expect("Serialized attaches Source");
vec![
(
figment::Source::File(PathBuf::from("/etc/app/app.yaml")),
FigmentSourceKind::File,
),
(code_src, FigmentSourceKind::Code),
(
figment::Source::Custom("vault://kv/app".to_owned()),
FigmentSourceKind::Custom,
),
]
}
#[test]
fn figment_source_kind_all_has_no_duplicates() {
// The constant must be a set — no variant listed twice. Pins
// the typescape discipline shared with `Format::ALL`,
// `ShikumiErrorKind::ALL`, `AttributionRule::ALL`,
// `ConfigSourceKind::ALL`, `FieldPathLocalization::ALL`,
// `FormatProvenance::ALL`, `AttributionAxis::ALL`, and
// `AttributionConfidence::ALL`: the closed-enum `ALL` constant
// is a deduplicated `'static` slice.
use std::collections::HashSet;
let set: HashSet<FigmentSourceKind> = FigmentSourceKind::ALL.iter().copied().collect();
assert_eq!(
set.len(),
FigmentSourceKind::ALL.len(),
"FigmentSourceKind::ALL must contain no duplicates; got: {:?}",
FigmentSourceKind::ALL,
);
}
#[test]
fn figment_source_kind_all_covers_every_constructible_tag() {
// Subset cover: every kind produced by FigmentSourceTag::kind
// over the canonical sample table must lie in
// FigmentSourceKind::ALL. Pins the cross-axis cover law: the
// tag space cannot manufacture a kind outside the declared kind
// enumeration. A future tag variant that adds a new kind class
// must extend FigmentSourceKind and its ALL in the same commit;
// otherwise this test fails.
use std::collections::HashSet;
let declared: HashSet<FigmentSourceKind> = FigmentSourceKind::ALL.iter().copied().collect();
let observed: HashSet<FigmentSourceKind> = canonical_figment_source_kind_samples()
.iter()
.map(|(src, _)| FigmentSourceTag::classify(src).unwrap().kind())
.collect();
assert!(
observed.is_subset(&declared),
"FigmentSourceTag::kind image must lie in FigmentSourceKind::ALL; \
observed: {observed:?}, declared: {declared:?}",
);
}
#[test]
fn figment_source_kind_all_equals_tag_kind_image() {
// Tight equality (stronger than subset cover): every variant
// in FigmentSourceKind::ALL must be witnessed by at least one
// tag's kind() — no orphan variant in the declared kind space
// lacks a producing tag. Today the three kind variants are all
// reached (File by Source::File, Code by Source::Code via the
// Serialized provider, Custom by Source::Custom); this test
// pins that contract.
use std::collections::HashSet;
let declared: HashSet<FigmentSourceKind> = FigmentSourceKind::ALL.iter().copied().collect();
let observed: HashSet<FigmentSourceKind> = canonical_figment_source_kind_samples()
.iter()
.map(|(src, _)| FigmentSourceTag::classify(src).unwrap().kind())
.collect();
assert_eq!(
observed, declared,
"FigmentSourceTag::kind image must equal FigmentSourceKind::ALL",
);
}
#[test]
fn figment_source_kind_all_cardinality_matches_partition() {
// The constant's cardinality must equal the number of distinct
// kind cells produced by the tag space — pins that ALL is
// sized to the partition, not to a stale hand-typed count. A
// future variant added to FigmentSourceKind without a tag that
// witnesses it (or vice versa) breaks this equality.
use std::collections::HashSet;
let cells: HashSet<FigmentSourceKind> = canonical_figment_source_kind_samples()
.iter()
.map(|(src, _)| FigmentSourceTag::classify(src).unwrap().kind())
.collect();
assert_eq!(
FigmentSourceKind::ALL.len(),
cells.len(),
"FigmentSourceKind::ALL cardinality must match partition cell count",
);
}
#[test]
fn figment_source_kind_all_declaration_order_is_file_code_custom() {
// Pin declaration order. Consumers (diagnostics legends,
// attestation manifests, dashboard column orderings) that
// iterate ALL get a stable order; reordering the slice is a
// breaking change that must show up here.
assert_eq!(
FigmentSourceKind::ALL,
&[
FigmentSourceKind::File,
FigmentSourceKind::Code,
FigmentSourceKind::Custom,
],
);
}
#[test]
fn figment_source_kind_all_partition_is_file_xor_code_xor_custom() {
// Boolean partition: `is_file` / `is_code` / `is_custom` over a
// tag sliced by each kind cell must agree with the cell's
// identity. Pins that FigmentSourceKind::ALL is a partition of
// the tag space's kind image — every tag lands in exactly one
// cell, and the boolean accessors agree pointwise.
let samples = canonical_figment_source_kind_samples();
for kind in FigmentSourceKind::ALL.iter().copied() {
let witnessing_src = samples
.iter()
.find(|(src, _)| FigmentSourceTag::classify(src).unwrap().kind() == kind)
.map(|(src, _)| src)
.expect("every kind cell must be witnessed by some tag");
let tag = FigmentSourceTag::classify(witnessing_src).unwrap();
match kind {
FigmentSourceKind::File => {
assert!(tag.kind().is_file());
assert!(!tag.kind().is_code());
assert!(!tag.kind().is_custom());
}
FigmentSourceKind::Code => {
assert!(tag.kind().is_code());
assert!(!tag.kind().is_file());
assert!(!tag.kind().is_custom());
}
FigmentSourceKind::Custom => {
assert!(tag.kind().is_custom());
assert!(!tag.kind().is_file());
assert!(!tag.kind().is_code());
}
}
}
}
#[test]
fn figment_source_kind_all_iterates_in_declaration_order() {
// Sanity: iteration over ALL yields variants in the same order
// as the slice literal. Peer to `config_source_kind_all_iterates_in_declaration_order`
// on the shikumi-side kind axis.
let collected: Vec<FigmentSourceKind> = FigmentSourceKind::ALL.to_vec();
assert_eq!(
collected,
vec![
FigmentSourceKind::File,
FigmentSourceKind::Code,
FigmentSourceKind::Custom,
],
);
}
#[test]
fn figment_source_kind_as_str_yields_canonical_lowercase_names() {
// Concrete-position pin on FigmentSourceKind::as_str. The
// trait-uniform round-trip test in cube::tests pins labels
// equal pairwise under from_canonical_str, but this test pins
// the literal string values themselves so a future rename
// (e.g. capitalizing "Code", prefixing "figment-file",
// switching "custom" to "raw") fails here before drifting
// through the trait-uniform round-trip law and the
// operator-facing rendering surface. The `"file"` label
// intentionally coincides with `ConfigSourceKind::File`'s
// label by typescape design: the two axes meet at the
// shikumi-file-layer ↔ figment-File-source resolution
// boundary, joined as a cube cell in
// `AttributionSourceKindCoordinates`.
assert_eq!(FigmentSourceKind::File.as_str(), "file");
assert_eq!(FigmentSourceKind::Code.as_str(), "code");
assert_eq!(FigmentSourceKind::Custom.as_str(), "custom");
}
#[test]
fn figment_source_kind_from_canonical_str_round_trips_through_trait() {
// Pin the trait-default `from_canonical_str` parse on
// FigmentSourceKind: each canonical lowercase name parses back
// to its variant via the ClosedAxisLabel default impl. The
// canonical-only trait parse is the round-trip dual of
// `as_str`; this pin sits at the FigmentSourceKind site so a
// future override of `from_canonical_str` (none today) is
// still held to the law. Mixed-case forms an operator might
// type in an env var or CLI flag (`"File"`, `"CODE"`,
// `"Custom"`) round-trip case-insensitively. Unrecognized
// strings — including `"code "` (trailing whitespace) and
// `"fil"` (a one-character drift from `"file"`) — reject.
use crate::ClosedAxisLabel;
for k in FigmentSourceKind::ALL.iter().copied() {
assert_eq!(
<FigmentSourceKind as ClosedAxisLabel>::from_canonical_str(k.as_str()),
Some(k),
"trait from_canonical_str must round-trip for {k:?}",
);
}
assert_eq!(
<FigmentSourceKind as ClosedAxisLabel>::from_canonical_str("File"),
Some(FigmentSourceKind::File),
);
assert_eq!(
<FigmentSourceKind as ClosedAxisLabel>::from_canonical_str("CODE"),
Some(FigmentSourceKind::Code),
);
assert_eq!(
<FigmentSourceKind as ClosedAxisLabel>::from_canonical_str("Custom"),
Some(FigmentSourceKind::Custom),
);
assert_eq!(
<FigmentSourceKind as ClosedAxisLabel>::from_canonical_str("code "),
None,
);
assert_eq!(
<FigmentSourceKind as ClosedAxisLabel>::from_canonical_str("fil"),
None,
);
}
#[test]
fn figment_source_kind_all_attribution_axis_image_is_metadata_source() {
// Cross-primitive cover law: every kind in FigmentSourceKind::ALL
// — when projected back through a witnessing tag's
// `attribution_axis()` — must lie on AttributionAxis::MetadataSource.
// Pins the structural law `figment_source_tag_attribution_axis_is_always_metadata_source`
// from the perspective of the kind axis: the figment-Source-axis
// kind partition is a sub-partition of the metadata.source
// attribution axis. Mirrors how `AttributionConfidence::ALL`
// pins its image in `failing_source_attribution_confidence_image_lies_in_all`.
use crate::AttributionAxis;
use std::collections::HashSet;
let samples = canonical_figment_source_kind_samples();
let observed: HashSet<AttributionAxis> = FigmentSourceKind::ALL
.iter()
.copied()
.map(|kind| {
let (src, _) = samples
.iter()
.find(|(src, _)| FigmentSourceTag::classify(src).unwrap().kind() == kind)
.expect("every kind cell must be witnessed");
FigmentSourceTag::classify(src).unwrap().attribution_axis()
})
.collect();
assert_eq!(
observed,
HashSet::from([AttributionAxis::MetadataSource]),
"every FigmentSourceKind variant projects to AttributionAxis::MetadataSource",
);
}
#[test]
fn figment_source_kind_ord_matches_all_declaration_order() {
// The derived Ord on FigmentSourceKind is declaration-order lex
// over ALL: `File < Code < Custom`. A BTreeMap keyed on the
// figment-Source-axis kind (per-kind attribution histograms,
// per-kind failure-rate dashboards, attestation manifests
// recording the figment-Source-axis kind cardinality mix) emits
// rows in that order deterministically without a hand-rolled
// comparator at the renderer.
//
// Two-leg pin: (1) ALL is a strictly-increasing chain under Ord,
// (2) cmp/partial_cmp agree with the array-index lex over ALL on
// every pair (and reflexivity holds). Idiom-peer of the same pin
// on ConfigSourceKind (commit `e0b96d1`).
use std::cmp::Ordering;
for window in FigmentSourceKind::ALL.windows(2) {
assert!(
window[0] < window[1],
"FigmentSourceKind::ALL must be strictly increasing under Ord, \
but {:?} >= {:?}",
window[0],
window[1],
);
}
for (i, &a) in FigmentSourceKind::ALL.iter().enumerate() {
for (j, &b) in FigmentSourceKind::ALL.iter().enumerate() {
let expected = i.cmp(&j);
assert_eq!(
a.cmp(&b),
expected,
"FigmentSourceKind::cmp must match ALL-index lex for ({a:?}, {b:?})",
);
assert_eq!(
a.partial_cmp(&b),
Some(expected),
"FigmentSourceKind::partial_cmp must agree with cmp for ({a:?}, {b:?})",
);
if i == j {
assert_eq!(a.cmp(&b), Ordering::Equal, "Ord must be reflexive on {a:?}",);
}
}
}
}
#[test]
fn figment_source_kind_btreemap_emits_in_declaration_order() {
// The compounding payoff of the Ord derive at a typed consumer
// site: a BTreeMap<FigmentSourceKind, _> emits keys in
// declaration order on `iter()` / `into_iter()` regardless of
// insertion order, matching `FigmentSourceKind::ALL`. Idiom-peer
// of the same pin on ConfigSourceKind (commit `e0b96d1`) and on
// FormatProvenance (commit `2c7654c`).
use std::collections::BTreeMap;
let mut counts: BTreeMap<FigmentSourceKind, u32> = BTreeMap::new();
counts.insert(FigmentSourceKind::Custom, 3);
counts.insert(FigmentSourceKind::File, 1);
counts.insert(FigmentSourceKind::Code, 2);
let observed: Vec<FigmentSourceKind> = counts.keys().copied().collect();
assert_eq!(
observed,
FigmentSourceKind::ALL.to_vec(),
"BTreeMap<FigmentSourceKind, _> must emit keys in ALL declaration order",
);
}
#[test]
fn figment_source_kind_display_matches_as_str() {
// Display writes the canonical lowercase label as_str returns,
// byte-for-byte. The two surfaces stay aligned by construction
// — a future rename of either must update the other in
// lockstep. Idiom-peer of the same pin on ConfigSourceKind
// (commit `e0b96d1`).
for k in FigmentSourceKind::ALL.iter().copied() {
assert_eq!(
format!("{k}"),
k.as_str(),
"Display must agree with as_str for {k:?}",
);
}
}
#[test]
fn figment_source_kind_from_str_round_trips_over_every_variant() {
// Display → FromStr identity round-trip over every variant.
// FromStr lowers through ClosedAxisLabel::from_canonical_str,
// so any future override of that trait method is held to this
// law at the inherent FromStr surface as well.
for k in FigmentSourceKind::ALL {
let rendered = k.to_string();
let parsed: FigmentSourceKind = rendered
.parse()
.expect("FromStr must round-trip Display output");
assert_eq!(parsed, *k, "FromStr must round-trip {k:?}");
}
}
#[test]
fn figment_source_kind_from_str_is_case_insensitive() {
// FromStr lowers through ClosedAxisLabel::from_canonical_str
// which uses eq_ignore_ascii_case over ALL — uppercase and
// mixed-case scalars an operator might type into an env var or
// CLI flag parse pointwise to the same variant.
assert_eq!(
"FILE".parse::<FigmentSourceKind>().unwrap(),
FigmentSourceKind::File,
);
assert_eq!(
"Code".parse::<FigmentSourceKind>().unwrap(),
FigmentSourceKind::Code,
);
assert_eq!(
"CuStOm".parse::<FigmentSourceKind>().unwrap(),
FigmentSourceKind::Custom,
);
}
#[test]
fn figment_source_kind_from_str_unknown_kind_error_carries_label_verbatim() {
// Unrecognized labels reject through ShikumiError::Parse with
// the offending substring embedded verbatim in the rendered
// message — same verbatim-rejection discipline as
// ConfigSourceKind's FromStr surface (commit `e0b96d1`),
// FormatProvenance's FromStr surface (commit `2c7654c`), and
// ParseFormatCoordinatesError (commit `06a2f42`).
for bad in &["files", "raw", "url", "", " code"] {
let err = bad
.parse::<FigmentSourceKind>()
.expect_err("non-canonical label must reject");
let rendered = err.to_string();
assert!(
rendered.contains(bad),
"rendered error must contain the offending label verbatim: \
input={bad:?}, rendered={rendered:?}",
);
}
}
#[test]
fn figment_source_kind_serde_yaml_round_trips_over_every_variant() {
// Serde Serialize → Deserialize identity round-trip over every
// variant through serde_yaml. Closes the (Serialize, Deserialize)
// idiom-peer of the (Display, FromStr) stdlib pair on the
// figment-Source-axis kind primitive. A consumer struct holding
// a FigmentSourceKind field under
// #[derive(Serialize, Deserialize)] (e.g. an attestation manifest
// recording the figment-Source kind of a failing attribution)
// round-trips without a consumer-side rename helper.
for k in FigmentSourceKind::ALL {
let yaml = serde_yaml::to_string(k).expect("Serialize must succeed");
let parsed: FigmentSourceKind =
serde_yaml::from_str(&yaml).expect("Deserialize must accept Serialize output");
assert_eq!(parsed, *k, "serde_yaml round-trip must preserve {k:?}");
}
}
#[test]
fn figment_source_kind_serde_json_round_trips_over_every_variant() {
// Serde Serialize → Deserialize identity round-trip over every
// variant through serde_json. The two formats render the
// canonical scalar identically modulo wire ceremony (YAML's
// bare scalar vs. JSON's quoted string), so the round-trip law
// composes pointwise — a future divergence in either Serialize
// impl surfaces here.
for k in FigmentSourceKind::ALL {
let json = serde_json::to_string(k).expect("Serialize must succeed");
let parsed: FigmentSourceKind =
serde_json::from_str(&json).expect("Deserialize must accept Serialize output");
assert_eq!(parsed, *k, "serde_json round-trip must preserve {k:?}");
}
}
#[test]
fn figment_source_kind_serde_yaml_is_case_insensitive() {
// Deserialize lowers through FromStr which lowers through
// ClosedAxisLabel::from_canonical_str (eq_ignore_ascii_case),
// so uppercase or mixed-case scalars parse pointwise. A
// manifest field authored by an operator typing the canonical
// name with different casing parses without a consumer-side
// case-fold helper.
let cases: &[(&str, FigmentSourceKind)] = &[
("File", FigmentSourceKind::File),
("CODE", FigmentSourceKind::Code),
("Custom", FigmentSourceKind::Custom),
];
for (input, expected) in cases {
let parsed: FigmentSourceKind =
serde_yaml::from_str(input).expect("case-insensitive Deserialize must succeed");
assert_eq!(
parsed, *expected,
"serde_yaml must parse case-insensitively for input {input:?}",
);
}
}
#[test]
fn figment_source_kind_serde_yaml_unknown_kind_error_carries_label_verbatim() {
// An unrecognized figment-Source-axis kind label surfaces at
// the serde error site with the offending substring verbatim in
// the rendered message, lifted through ShikumiError::Parse's
// Display impl. Same verbatim-rejection discipline as
// ConfigSourceKind's serde surface (commit `e0b96d1`) and
// FormatProvenance's serde surface (commit `2c7654c`).
for bad in &["files", "raw", "url", "configmap"] {
let err = serde_yaml::from_str::<FigmentSourceKind>(bad)
.expect_err("non-canonical label must reject");
let rendered = err.to_string();
assert!(
rendered.contains(bad),
"rendered serde error must contain the offending label verbatim: \
input={bad:?}, rendered={rendered:?}",
);
}
}
#[test]
fn figment_name_tag_kind_ord_matches_all_declaration_order() {
// The derived Ord on FigmentNameTagKind is declaration-order
// lex over ALL: `Format < Env`. A BTreeMap keyed on the
// figment-Name-axis kind (per-kind attribution histograms,
// per-kind failure-rate dashboards, attestation manifests
// recording the figment-Name-axis kind cardinality mix) emits
// rows in that order deterministically without a hand-rolled
// comparator at the renderer.
//
// Two-leg pin: (1) ALL is a strictly-increasing chain under
// Ord, (2) cmp/partial_cmp agree with the array-index lex over
// ALL on every pair (and reflexivity holds). Idiom-peer of the
// same pin on FigmentSourceKind (commit `5df265c`) and
// ConfigSourceKind (commit `e0b96d1`).
use std::cmp::Ordering;
for window in FigmentNameTagKind::ALL.windows(2) {
assert!(
window[0] < window[1],
"FigmentNameTagKind::ALL must be strictly increasing under Ord, \
but {:?} >= {:?}",
window[0],
window[1],
);
}
for (i, &a) in FigmentNameTagKind::ALL.iter().enumerate() {
for (j, &b) in FigmentNameTagKind::ALL.iter().enumerate() {
let expected = i.cmp(&j);
assert_eq!(
a.cmp(&b),
expected,
"FigmentNameTagKind::cmp must match ALL-index lex for ({a:?}, {b:?})",
);
assert_eq!(
a.partial_cmp(&b),
Some(expected),
"FigmentNameTagKind::partial_cmp must agree with cmp for ({a:?}, {b:?})",
);
if i == j {
assert_eq!(a.cmp(&b), Ordering::Equal, "Ord must be reflexive on {a:?}",);
}
}
}
}
#[test]
fn figment_name_tag_kind_btreemap_emits_in_declaration_order() {
// The compounding payoff of the Ord derive at a typed consumer
// site: a BTreeMap<FigmentNameTagKind, _> emits keys in
// declaration order on `iter()` / `into_iter()` regardless of
// insertion order, matching `FigmentNameTagKind::ALL`.
// Idiom-peer of the same pin on FigmentSourceKind
// (commit `5df265c`) and ConfigSourceKind (commit `e0b96d1`).
use std::collections::BTreeMap;
let mut counts: BTreeMap<FigmentNameTagKind, u32> = BTreeMap::new();
counts.insert(FigmentNameTagKind::Env, 2);
counts.insert(FigmentNameTagKind::Format, 1);
let observed: Vec<FigmentNameTagKind> = counts.keys().copied().collect();
assert_eq!(
observed,
FigmentNameTagKind::ALL.to_vec(),
"BTreeMap<FigmentNameTagKind, _> must emit keys in ALL declaration order",
);
}
#[test]
fn figment_name_tag_kind_display_matches_as_str() {
// Display writes the canonical lowercase label as_str returns,
// byte-for-byte. The two surfaces stay aligned by construction
// — a future rename of either must update the other in
// lockstep. Idiom-peer of the same pin on FigmentSourceKind
// (commit `5df265c`).
for k in FigmentNameTagKind::ALL.iter().copied() {
assert_eq!(
format!("{k}"),
k.as_str(),
"Display must agree with as_str for {k:?}",
);
}
}
#[test]
fn figment_name_tag_kind_from_str_round_trips_over_every_variant() {
// Display → FromStr identity round-trip over every variant.
// FromStr lowers through ClosedAxisLabel::from_canonical_str,
// so any future override of that trait method is held to this
// law at the inherent FromStr surface as well.
for k in FigmentNameTagKind::ALL {
let rendered = k.to_string();
let parsed: FigmentNameTagKind = rendered
.parse()
.expect("FromStr must round-trip Display output");
assert_eq!(parsed, *k, "FromStr must round-trip {k:?}");
}
}
#[test]
fn figment_name_tag_kind_from_str_is_case_insensitive() {
// FromStr lowers through ClosedAxisLabel::from_canonical_str
// which uses eq_ignore_ascii_case over ALL — uppercase and
// mixed-case scalars an operator might type into an env var or
// CLI flag parse pointwise to the same variant.
assert_eq!(
"FORMAT".parse::<FigmentNameTagKind>().unwrap(),
FigmentNameTagKind::Format,
);
assert_eq!(
"Env".parse::<FigmentNameTagKind>().unwrap(),
FigmentNameTagKind::Env,
);
assert_eq!(
"FoRmAt".parse::<FigmentNameTagKind>().unwrap(),
FigmentNameTagKind::Format,
);
}
#[test]
fn figment_name_tag_kind_from_str_unknown_kind_error_carries_label_verbatim() {
// Unrecognized labels reject through ShikumiError::Parse with
// the offending substring embedded verbatim in the rendered
// message — same verbatim-rejection discipline as
// FigmentSourceKind's FromStr surface (commit `5df265c`),
// ConfigSourceKind's FromStr surface (commit `e0b96d1`),
// FormatProvenance's FromStr surface (commit `2c7654c`), and
// ParseFormatCoordinatesError (commit `06a2f42`).
for bad in &["formats", "envs", "raw", "", " env"] {
let err = bad
.parse::<FigmentNameTagKind>()
.expect_err("non-canonical label must reject");
let rendered = err.to_string();
assert!(
rendered.contains(bad),
"rendered error must contain the offending label verbatim: \
input={bad:?}, rendered={rendered:?}",
);
}
}
#[test]
fn figment_name_tag_kind_serde_yaml_round_trips_over_every_variant() {
// Serde Serialize → Deserialize identity round-trip over every
// variant through serde_yaml. Closes the (Serialize, Deserialize)
// idiom-peer of the (Display, FromStr) stdlib pair on the
// figment-Name-axis kind primitive. A consumer struct holding
// a FigmentNameTagKind field under
// #[derive(Serialize, Deserialize)] (e.g. an attestation
// manifest recording the figment-Name kind of a failing
// attribution) round-trips without a consumer-side rename
// helper.
for k in FigmentNameTagKind::ALL {
let yaml = serde_yaml::to_string(k).expect("Serialize must succeed");
let parsed: FigmentNameTagKind =
serde_yaml::from_str(&yaml).expect("Deserialize must accept Serialize output");
assert_eq!(parsed, *k, "serde_yaml round-trip must preserve {k:?}");
}
}
#[test]
fn figment_name_tag_kind_serde_json_round_trips_over_every_variant() {
// Serde Serialize → Deserialize identity round-trip over every
// variant through serde_json. The two formats render the
// canonical scalar identically modulo wire ceremony (YAML's
// bare scalar vs. JSON's quoted string), so the round-trip
// law composes pointwise — a future divergence in either
// Serialize impl surfaces here.
for k in FigmentNameTagKind::ALL {
let json = serde_json::to_string(k).expect("Serialize must succeed");
let parsed: FigmentNameTagKind =
serde_json::from_str(&json).expect("Deserialize must accept Serialize output");
assert_eq!(parsed, *k, "serde_json round-trip must preserve {k:?}");
}
}
#[test]
fn figment_name_tag_kind_serde_yaml_is_case_insensitive() {
// Deserialize lowers through FromStr which lowers through
// ClosedAxisLabel::from_canonical_str (eq_ignore_ascii_case),
// so uppercase or mixed-case scalars parse pointwise. A
// manifest field authored by an operator typing the canonical
// name with different casing parses without a consumer-side
// case-fold helper.
let cases: &[(&str, FigmentNameTagKind)] = &[
("Format", FigmentNameTagKind::Format),
("ENV", FigmentNameTagKind::Env),
("FoRmAt", FigmentNameTagKind::Format),
];
for (input, expected) in cases {
let parsed: FigmentNameTagKind =
serde_yaml::from_str(input).expect("case-insensitive Deserialize must succeed");
assert_eq!(
parsed, *expected,
"serde_yaml must parse case-insensitively for input {input:?}",
);
}
}
#[test]
fn figment_name_tag_kind_serde_yaml_unknown_kind_error_carries_label_verbatim() {
// An unrecognized figment-Name-axis kind label surfaces at the
// serde error site with the offending substring verbatim in
// the rendered message, lifted through ShikumiError::Parse's
// Display impl. Same verbatim-rejection discipline as
// FigmentSourceKind's serde surface (commit `5df265c`),
// ConfigSourceKind's serde surface (commit `e0b96d1`), and
// FormatProvenance's serde surface (commit `2c7654c`).
for bad in &["formats", "envs", "raw", "configmap"] {
let err = serde_yaml::from_str::<FigmentNameTagKind>(bad)
.expect_err("non-canonical label must reject");
let rendered = err.to_string();
assert!(
rendered.contains(bad),
"rendered serde error must contain the offending label verbatim: \
input={bad:?}, rendered={rendered:?}",
);
}
}
#[test]
fn env_metadata_tag_kind_ord_matches_all_declaration_order() {
// The derived Ord on EnvMetadataTagKind is declaration-order
// lex over ALL: `Prefixed < Bare`. A BTreeMap keyed on the
// env-name sub-axis kind (per-kind attribution histograms,
// per-kind failure-rate dashboards, attestation manifests
// recording the env-name sub-axis kind cardinality mix of a
// recorded chain) emits rows in that order deterministically
// without a hand-rolled comparator at the renderer.
//
// Two-leg pin: (1) ALL is a strictly-increasing chain under
// Ord, (2) cmp/partial_cmp agree with the array-index lex
// over ALL on every pair (and reflexivity holds). Idiom-peer
// of the same pin on FigmentNameTagKind (commit `64a47e7`),
// FigmentSourceKind (commit `5df265c`), and ConfigSourceKind
// (commit `e0b96d1`).
use std::cmp::Ordering;
for window in EnvMetadataTagKind::ALL.windows(2) {
assert!(
window[0] < window[1],
"EnvMetadataTagKind::ALL must be strictly increasing under Ord, \
but {:?} >= {:?}",
window[0],
window[1],
);
}
for (i, &a) in EnvMetadataTagKind::ALL.iter().enumerate() {
for (j, &b) in EnvMetadataTagKind::ALL.iter().enumerate() {
let expected = i.cmp(&j);
assert_eq!(
a.cmp(&b),
expected,
"EnvMetadataTagKind::cmp must match ALL-index lex for ({a:?}, {b:?})",
);
assert_eq!(
a.partial_cmp(&b),
Some(expected),
"EnvMetadataTagKind::partial_cmp must agree with cmp for ({a:?}, {b:?})",
);
if i == j {
assert_eq!(a.cmp(&b), Ordering::Equal, "Ord must be reflexive on {a:?}",);
}
}
}
}
#[test]
fn env_metadata_tag_kind_btreemap_emits_in_declaration_order() {
// The compounding payoff of the Ord derive at a typed consumer
// site: a BTreeMap<EnvMetadataTagKind, _> emits keys in
// declaration order on `iter()` / `into_iter()` regardless of
// insertion order, matching `EnvMetadataTagKind::ALL`.
// Idiom-peer of the same pin on FigmentNameTagKind
// (commit `64a47e7`), FigmentSourceKind (commit `5df265c`),
// and ConfigSourceKind (commit `e0b96d1`).
use std::collections::BTreeMap;
let mut counts: BTreeMap<EnvMetadataTagKind, u32> = BTreeMap::new();
counts.insert(EnvMetadataTagKind::Bare, 2);
counts.insert(EnvMetadataTagKind::Prefixed, 1);
let observed: Vec<EnvMetadataTagKind> = counts.keys().copied().collect();
assert_eq!(
observed,
EnvMetadataTagKind::ALL.to_vec(),
"BTreeMap<EnvMetadataTagKind, _> must emit keys in ALL declaration order",
);
}
#[test]
fn env_metadata_tag_kind_display_matches_as_str() {
// Display writes the canonical lowercase label as_str returns,
// byte-for-byte. The two surfaces stay aligned by construction
// — a future rename of either must update the other in
// lockstep. Idiom-peer of the same pin on FigmentNameTagKind
// (commit `64a47e7`) and FigmentSourceKind (commit `5df265c`).
for k in EnvMetadataTagKind::ALL.iter().copied() {
assert_eq!(
format!("{k}"),
k.as_str(),
"Display must agree with as_str for {k:?}",
);
}
}
#[test]
fn env_metadata_tag_kind_from_str_round_trips_over_every_variant() {
// Display → FromStr identity round-trip over every variant.
// FromStr lowers through ClosedAxisLabel::from_canonical_str,
// so any future override of that trait method is held to this
// law at the inherent FromStr surface as well.
for k in EnvMetadataTagKind::ALL {
let rendered = k.to_string();
let parsed: EnvMetadataTagKind = rendered
.parse()
.expect("FromStr must round-trip Display output");
assert_eq!(parsed, *k, "FromStr must round-trip {k:?}");
}
}
#[test]
fn env_metadata_tag_kind_from_str_is_case_insensitive() {
// FromStr lowers through ClosedAxisLabel::from_canonical_str
// which uses eq_ignore_ascii_case over ALL — uppercase and
// mixed-case scalars an operator might type into an env var
// or CLI flag parse pointwise to the same variant.
assert_eq!(
"PREFIXED".parse::<EnvMetadataTagKind>().unwrap(),
EnvMetadataTagKind::Prefixed,
);
assert_eq!(
"Bare".parse::<EnvMetadataTagKind>().unwrap(),
EnvMetadataTagKind::Bare,
);
assert_eq!(
"PrEfIxEd".parse::<EnvMetadataTagKind>().unwrap(),
EnvMetadataTagKind::Prefixed,
);
assert_eq!(
"bArE".parse::<EnvMetadataTagKind>().unwrap(),
EnvMetadataTagKind::Bare,
);
}
#[test]
fn env_metadata_tag_kind_from_str_unknown_kind_error_carries_label_verbatim() {
// Unrecognized labels reject through ShikumiError::Parse with
// the offending substring embedded verbatim in the rendered
// message — same verbatim-rejection discipline as
// FigmentNameTagKind's FromStr surface (commit `64a47e7`),
// FigmentSourceKind's FromStr surface (commit `5df265c`),
// ConfigSourceKind's FromStr surface (commit `e0b96d1`),
// FormatProvenance's FromStr surface (commit `2c7654c`), and
// ParseFormatCoordinatesError (commit `06a2f42`).
for bad in &["pref", "raw", "naked", "", " bare"] {
let err = bad
.parse::<EnvMetadataTagKind>()
.expect_err("non-canonical label must reject");
let rendered = err.to_string();
assert!(
rendered.contains(bad),
"rendered error must contain the offending label verbatim: \
input={bad:?}, rendered={rendered:?}",
);
}
}
#[test]
fn env_metadata_tag_kind_serde_yaml_round_trips_over_every_variant() {
// Serde Serialize → Deserialize identity round-trip over every
// variant through serde_yaml. Closes the (Serialize, Deserialize)
// idiom-peer of the (Display, FromStr) stdlib pair on the
// env-name sub-axis kind primitive. A consumer struct holding
// an EnvMetadataTagKind field under
// #[derive(Serialize, Deserialize)] (e.g. an attestation
// manifest recording the env-name sub-axis kind of a failing
// attribution) round-trips without a consumer-side rename
// helper.
for k in EnvMetadataTagKind::ALL {
let yaml = serde_yaml::to_string(k).expect("Serialize must succeed");
let parsed: EnvMetadataTagKind =
serde_yaml::from_str(&yaml).expect("Deserialize must accept Serialize output");
assert_eq!(parsed, *k, "serde_yaml round-trip must preserve {k:?}");
}
}
#[test]
fn env_metadata_tag_kind_serde_json_round_trips_over_every_variant() {
// Serde Serialize → Deserialize identity round-trip over every
// variant through serde_json. The two formats render the
// canonical scalar identically modulo wire ceremony (YAML's
// bare scalar vs. JSON's quoted string), so the round-trip
// law composes pointwise — a future divergence in either
// Serialize impl surfaces here.
for k in EnvMetadataTagKind::ALL {
let json = serde_json::to_string(k).expect("Serialize must succeed");
let parsed: EnvMetadataTagKind =
serde_json::from_str(&json).expect("Deserialize must accept Serialize output");
assert_eq!(parsed, *k, "serde_json round-trip must preserve {k:?}");
}
}
#[test]
fn env_metadata_tag_kind_serde_yaml_is_case_insensitive() {
// Deserialize lowers through FromStr which lowers through
// ClosedAxisLabel::from_canonical_str (eq_ignore_ascii_case),
// so uppercase or mixed-case scalars parse pointwise. A
// manifest field authored by an operator typing the canonical
// name with different casing parses without a consumer-side
// case-fold helper.
let cases: &[(&str, EnvMetadataTagKind)] = &[
("Prefixed", EnvMetadataTagKind::Prefixed),
("BARE", EnvMetadataTagKind::Bare),
("PrEfIxEd", EnvMetadataTagKind::Prefixed),
("bArE", EnvMetadataTagKind::Bare),
];
for (input, expected) in cases {
let parsed: EnvMetadataTagKind =
serde_yaml::from_str(input).expect("case-insensitive Deserialize must succeed");
assert_eq!(
parsed, *expected,
"serde_yaml must parse case-insensitively for input {input:?}",
);
}
}
#[test]
fn env_metadata_tag_kind_serde_yaml_unknown_kind_error_carries_label_verbatim() {
// An unrecognized env-name sub-axis kind label surfaces at
// the serde error site with the offending substring verbatim
// in the rendered message, lifted through
// ShikumiError::Parse's Display impl. Same verbatim-rejection
// discipline as FigmentNameTagKind's serde surface
// (commit `64a47e7`), FigmentSourceKind's serde surface
// (commit `5df265c`), ConfigSourceKind's serde surface
// (commit `e0b96d1`), and FormatProvenance's serde surface
// (commit `2c7654c`).
for bad in &["pref", "raw", "naked", "envvar"] {
let err = serde_yaml::from_str::<EnvMetadataTagKind>(bad)
.expect_err("non-canonical label must reject");
let rendered = err.to_string();
assert!(
rendered.contains(bad),
"rendered serde error must contain the offending label verbatim: \
input={bad:?}, rendered={rendered:?}",
);
}
}
#[test]
fn env_metadata_tag_kind_serde_yaml_emission_is_bare_scalar() {
// Concrete-position pin on EnvMetadataTagKind's YAML
// emission: both variants render as a bare lowercase scalar
// (no quotes, no tag prefix). Routes through
// Serializer::collect_str → Display → as_str, so the wire
// shape is exactly `format!("{k}")` followed by serde_yaml's
// newline terminator. Pins the serde idiom-peer of the
// Display surface byte-for-byte at concrete positions across
// both variants. Idiom-peer of
// `secret_ref_shape_serde_yaml_emission_is_bare_scalar`
// (commit `8a84bb6`).
assert_eq!(
serde_yaml::to_string(&EnvMetadataTagKind::Prefixed).unwrap(),
"prefixed\n",
);
assert_eq!(
serde_yaml::to_string(&EnvMetadataTagKind::Bare).unwrap(),
"bare\n",
);
}
#[test]
fn figment_name_tag_yaml_provider_emission_is_unrecognized() {
// figment's built-in Yaml provider attaches the file path as
// metadata.name. That shape is not a name-axis tag — it
// belongs to the source-axis (Source::File). FigmentNameTag
// must report None so the resolver falls through to
// source-axis dispatch.
use figment::providers::Format as _;
let dir = tempfile::TempDir::new().unwrap();
let file = dir.path().join("c.yaml");
std::fs::write(&file, "k: v\n").unwrap();
let figment = figment::Figment::new().merge(figment::providers::Yaml::file(&file));
let value: figment::value::Value = figment.find_value("k").unwrap();
let md = figment.get_metadata(value.tag()).unwrap();
let name: &str = md.name.as_ref();
assert!(
FigmentNameTag::classify(name).is_none(),
"Yaml provider's path-shaped name `{name}` must NOT classify as a name-axis tag"
);
}
// ---- FigmentNameTagKind / FigmentNameTag::kind ----
//
// The (FigmentNameTag → FigmentNameTagKind) lift closes the
// figment-metadata kind universe under one typescape primitive set:
// the figment-Source axis was already projected to a `'static`
// discriminant (FigmentSourceKind via FigmentSourceTag::kind); the
// figment-`Metadata::name` axis now has its symmetric peer. Tests
// mirror the FigmentSourceKind suite pointwise.
/// Canonical sample table covering every `FigmentNameTag` variant
/// once, with the kind each must classify into. Source for the
/// `figment_name_tag_kind_all_*` cover/partition tests below — peer
/// to `canonical_figment_source_kind_samples` on the figment-Source
/// axis.
fn canonical_figment_name_tag_kind_samples() -> Vec<(String, FigmentNameTagKind)> {
vec![
(
crate::discovery::Format::Lisp.metadata_name(Path::new("/etc/app/app.lisp")),
FigmentNameTagKind::Format,
),
(
crate::discovery::Format::Nix.metadata_name(Path::new("/etc/app/app.nix")),
FigmentNameTagKind::Format,
),
(
ConfigSource::env_metadata_name("MYAPP_"),
FigmentNameTagKind::Env,
),
(ConfigSource::env_metadata_name(""), FigmentNameTagKind::Env),
]
}
#[test]
fn figment_name_tag_kind_classifies_each_variant() {
// The forward map FigmentNameTag → FigmentNameTagKind is
// exhaustive: every variant pins to exactly one kind. Mirrors
// `figment_source_kind_classifies_each_variant` on the
// figment-Source axis.
let lisp_name = crate::discovery::Format::Lisp.metadata_name(Path::new("/a.lisp"));
let lisp_tag = FigmentNameTag::classify(&lisp_name).unwrap();
assert_eq!(lisp_tag.kind(), FigmentNameTagKind::Format);
let nix_name = crate::discovery::Format::Nix.metadata_name(Path::new("/a.nix"));
let nix_tag = FigmentNameTag::classify(&nix_name).unwrap();
assert_eq!(nix_tag.kind(), FigmentNameTagKind::Format);
let prefixed = ConfigSource::env_metadata_name("APP_");
let prefixed_tag = FigmentNameTag::classify(&prefixed).unwrap();
assert_eq!(prefixed_tag.kind(), FigmentNameTagKind::Env);
let bare = ConfigSource::env_metadata_name("");
let bare_tag = FigmentNameTag::classify(&bare).unwrap();
assert_eq!(bare_tag.kind(), FigmentNameTagKind::Env);
}
#[test]
fn figment_name_tag_kind_is_data_free() {
// Inner data does not influence kind — every Format variant
// maps to FigmentNameTagKind::Format regardless of the inner
// FormatMetadataTag's format or path; every Env variant maps
// to FigmentNameTagKind::Env regardless of the inner
// EnvMetadataTag's prefix / bare distinction. Mirrors
// `figment_source_kind_is_data_free` on the figment-Source axis.
for (format, path) in [
(crate::discovery::Format::Lisp, "/a.lisp"),
(crate::discovery::Format::Lisp, "/very/long/path/to/x.lisp"),
(crate::discovery::Format::Nix, "rel.nix"),
] {
let name = format.metadata_name(Path::new(path));
let tag = FigmentNameTag::classify(&name).unwrap();
assert_eq!(tag.kind(), FigmentNameTagKind::Format);
}
for prefix in ["MYAPP_", "TOBIRA_", "X_", ""] {
let name = ConfigSource::env_metadata_name(prefix);
let tag = FigmentNameTag::classify(&name).unwrap();
assert_eq!(tag.kind(), FigmentNameTagKind::Env);
}
}
#[test]
fn figment_name_tag_kind_agrees_with_as_predicates_pointwise() {
// The kind() / as_format() / as_env() pair must agree on every
// constructible tag variant — kind is the closed-enum lift of
// the two `as_*` projection predicates. Mirrors
// `figment_source_kind_agrees_with_predicates_pointwise` on the
// figment-Source axis.
for (name, _) in canonical_figment_name_tag_kind_samples() {
let tag = FigmentNameTag::classify(&name).unwrap();
assert_eq!(
tag.as_format().is_some(),
tag.kind() == FigmentNameTagKind::Format,
);
assert_eq!(
tag.as_env().is_some(),
tag.kind() == FigmentNameTagKind::Env,
);
// Kind-side predicates agree pointwise with the as_* tag
// projections.
assert_eq!(
tag.kind().is_format(),
tag.kind() == FigmentNameTagKind::Format,
);
assert_eq!(tag.kind().is_env(), tag.kind() == FigmentNameTagKind::Env);
}
}
#[test]
fn figment_name_tag_attribution_axis_is_always_metadata_name() {
// Structural law: every FigmentNameTag classification sits on
// the metadata.name axis. This is the cross-primitive bridge
// between FigmentNameTag and AttributionAxis — symmetric peer
// of `figment_source_tag_attribution_axis_is_always_metadata_source`
// on the figment-Source axis.
use crate::AttributionAxis;
for (name, _) in canonical_figment_name_tag_kind_samples() {
let tag = FigmentNameTag::classify(&name).unwrap();
assert_eq!(tag.attribution_axis(), AttributionAxis::MetadataName);
}
}
#[test]
fn figment_name_tag_kind_is_static_and_copy_and_hashable() {
// The discriminant is `'static` (no lifetime parameter) so it
// can cross thread boundaries the borrowed tag cannot. Trait
// bounds match the sibling typescape primitives
// (FigmentSourceKind, ConfigSourceKind, AttributionRule,
// AttributionConfidence, AttributionAxis).
fn assert_static<T: 'static>() {}
use std::collections::HashSet;
let mut set: HashSet<FigmentNameTagKind> =
FigmentNameTagKind::ALL.iter().copied().collect();
set.insert(FigmentNameTagKind::Format); // duplicate
assert_eq!(set.len(), FigmentNameTagKind::ALL.len());
// Copy: rebind without move.
let k = FigmentNameTagKind::Env;
let k2 = k;
let k3 = k;
assert_eq!(k, k2);
assert_eq!(k2, k3);
// 'static — observable by inserting into a static bound.
assert_static::<FigmentNameTagKind>();
}
#[test]
fn figment_name_tag_kind_all_has_no_duplicates() {
// The constant must be a set — no variant listed twice. Pins
// the typescape discipline shared with FigmentSourceKind::ALL
// and the other closed-enum kind axes.
use std::collections::HashSet;
let set: HashSet<FigmentNameTagKind> = FigmentNameTagKind::ALL.iter().copied().collect();
assert_eq!(
set.len(),
FigmentNameTagKind::ALL.len(),
"FigmentNameTagKind::ALL must contain no duplicates; got: {:?}",
FigmentNameTagKind::ALL,
);
}
#[test]
fn figment_name_tag_kind_all_covers_every_constructible_tag() {
// Subset cover: every kind produced by FigmentNameTag::kind
// over the canonical sample table must lie in
// FigmentNameTagKind::ALL. A future tag variant that adds a new
// kind class must extend FigmentNameTagKind and its ALL in the
// same commit; otherwise this test fails.
use std::collections::HashSet;
let declared: HashSet<FigmentNameTagKind> =
FigmentNameTagKind::ALL.iter().copied().collect();
let observed: HashSet<FigmentNameTagKind> = canonical_figment_name_tag_kind_samples()
.iter()
.map(|(name, _)| FigmentNameTag::classify(name).unwrap().kind())
.collect();
assert!(
observed.is_subset(&declared),
"FigmentNameTag::kind image must lie in FigmentNameTagKind::ALL; \
observed: {observed:?}, declared: {declared:?}",
);
}
#[test]
fn figment_name_tag_kind_all_equals_tag_kind_image() {
// Tight equality (stronger than subset cover): every variant
// in FigmentNameTagKind::ALL must be witnessed by at least one
// tag's kind() — no orphan variant in the declared kind space
// lacks a producing tag.
use std::collections::HashSet;
let declared: HashSet<FigmentNameTagKind> =
FigmentNameTagKind::ALL.iter().copied().collect();
let observed: HashSet<FigmentNameTagKind> = canonical_figment_name_tag_kind_samples()
.iter()
.map(|(name, _)| FigmentNameTag::classify(name).unwrap().kind())
.collect();
assert_eq!(
observed, declared,
"FigmentNameTag::kind image must equal FigmentNameTagKind::ALL",
);
}
#[test]
fn figment_name_tag_kind_all_declaration_order_is_format_env() {
// Pin declaration order. Consumers (diagnostics legends,
// attestation manifests, dashboard column orderings) that
// iterate ALL get a stable order; reordering the slice is a
// breaking change that must show up here.
assert_eq!(
FigmentNameTagKind::ALL,
&[FigmentNameTagKind::Format, FigmentNameTagKind::Env],
);
}
#[test]
fn figment_name_tag_kind_all_partition_is_format_xor_env() {
// Boolean partition: `is_format` / `is_env` over a tag sliced
// by each kind cell must agree with the cell's identity.
let samples = canonical_figment_name_tag_kind_samples();
for kind in FigmentNameTagKind::ALL.iter().copied() {
let witnessing_name = samples
.iter()
.find(|(name, _)| FigmentNameTag::classify(name).unwrap().kind() == kind)
.map(|(name, _)| name)
.expect("every kind cell must be witnessed by some tag");
let tag = FigmentNameTag::classify(witnessing_name).unwrap();
match kind {
FigmentNameTagKind::Format => {
assert!(tag.kind().is_format());
assert!(!tag.kind().is_env());
}
FigmentNameTagKind::Env => {
assert!(tag.kind().is_env());
assert!(!tag.kind().is_format());
}
}
}
}
#[test]
fn figment_name_tag_kind_as_str_yields_canonical_lowercase_names() {
// Concrete-position pin on FigmentNameTagKind::as_str. The
// trait-uniform round-trip test in cube::tests pins labels
// equal pairwise under from_canonical_str, but this test pins
// the literal string values themselves so a future rename
// (e.g. capitalizing "Env", prefixing "name-format") fails here
// before drifting through the trait-uniform round-trip law and
// the operator-facing rendering surface. The `"env"` label
// intentionally coincides with `ConfigSourceKind::Env`'s label
// by typescape design: the two axes meet at the shikumi-env-
// layer ↔ figment-Env-name resolution boundary.
assert_eq!(FigmentNameTagKind::Format.as_str(), "format");
assert_eq!(FigmentNameTagKind::Env.as_str(), "env");
}
#[test]
fn figment_name_tag_kind_from_canonical_str_round_trips_through_trait() {
// Pin the trait-default `from_canonical_str` parse on
// FigmentNameTagKind: each canonical lowercase name parses back
// to its variant via the ClosedAxisLabel default impl. Mixed-
// case forms an operator might type round-trip case-insensitively.
use crate::ClosedAxisLabel;
for k in FigmentNameTagKind::ALL.iter().copied() {
assert_eq!(
<FigmentNameTagKind as ClosedAxisLabel>::from_canonical_str(k.as_str()),
Some(k),
"trait from_canonical_str must round-trip for {k:?}",
);
}
assert_eq!(
<FigmentNameTagKind as ClosedAxisLabel>::from_canonical_str("Format"),
Some(FigmentNameTagKind::Format),
);
assert_eq!(
<FigmentNameTagKind as ClosedAxisLabel>::from_canonical_str("ENV"),
Some(FigmentNameTagKind::Env),
);
// Unrecognized strings — including the trailing-whitespace
// case and a one-character drift — reject.
assert_eq!(
<FigmentNameTagKind as ClosedAxisLabel>::from_canonical_str("env "),
None,
);
assert_eq!(
<FigmentNameTagKind as ClosedAxisLabel>::from_canonical_str("forma"),
None,
);
}
#[test]
fn figment_name_tag_kind_all_attribution_axis_image_is_metadata_name() {
// Cross-primitive cover law: every kind in FigmentNameTagKind::ALL
// — when projected back through a witnessing tag's
// `attribution_axis()` — must lie on AttributionAxis::MetadataName.
// Pins the structural law `figment_name_tag_attribution_axis_is_always_metadata_name`
// from the perspective of the kind axis: the figment-name-axis
// kind partition is a sub-partition of the metadata.name
// attribution axis. Symmetric peer of
// `figment_source_kind_all_attribution_axis_image_is_metadata_source`
// on the figment-Source axis.
use crate::AttributionAxis;
use std::collections::HashSet;
let samples = canonical_figment_name_tag_kind_samples();
let observed: HashSet<AttributionAxis> = FigmentNameTagKind::ALL
.iter()
.copied()
.map(|kind| {
let (name, _) = samples
.iter()
.find(|(name, _)| FigmentNameTag::classify(name).unwrap().kind() == kind)
.expect("every kind cell must be witnessed");
FigmentNameTag::classify(name).unwrap().attribution_axis()
})
.collect();
assert_eq!(
observed,
HashSet::from([AttributionAxis::MetadataName]),
"every FigmentNameTagKind variant projects to AttributionAxis::MetadataName",
);
}
#[test]
fn figment_name_tag_kind_round_trips_through_figment_env_emission() {
// End-to-end: classify a real figment::providers::Env-emitted
// metadata-name through FigmentNameTag, project to kind, and
// confirm the kind matches FigmentNameTagKind::Env. Pins the
// cross-side contract that figment's Env emission lands on the
// Env kind cell.
use figment::Provider;
for prefix in ["MYAPP_", "TOBIRA_", "X_"] {
let env = figment::providers::Env::prefixed(prefix);
let md = env.metadata();
let name: &str = md.name.as_ref();
let tag = FigmentNameTag::classify(name).expect("figment Env name must classify");
assert_eq!(tag.kind(), FigmentNameTagKind::Env);
}
}
#[test]
fn figment_name_tag_kind_round_trips_through_format_emission() {
// End-to-end: every shikumi-built provider variant's emitted
// metadata-name classifies via FigmentNameTag::Format and
// projects to FigmentNameTagKind::Format. Pins the cross-side
// contract that shikumi's own emissions land on the Format
// kind cell.
use crate::discovery::Format;
for f in Format::ALL.iter().filter(|f| f.has_shikumi_provider()) {
let name = f.metadata_name(Path::new("/etc/app/app.cfg"));
let tag = FigmentNameTag::classify(&name).expect("format-emitted name classifies");
assert_eq!(tag.kind(), FigmentNameTagKind::Format);
}
}
// ---- EnvMetadataTagKind / EnvMetadataTag::kind ----
//
// The (EnvMetadataTag → EnvMetadataTagKind) lift closes the
// figment-metadata kind universe on the third sub-axis: the
// outer figment-Source axis was projected to a `'static`
// discriminant via FigmentSourceTag::kind → FigmentSourceKind, the
// outer figment-Name axis via FigmentNameTag::kind →
// FigmentNameTagKind, and the inner env-name sub-axis (inside
// FigmentNameTag::Env) now lifts to EnvMetadataTagKind. Tests
// mirror the FigmentNameTagKind suite pointwise.
/// Canonical sample table covering every `EnvMetadataTag` variant
/// once, with the kind each must classify into. Source for the
/// `env_metadata_tag_kind_all_*` cover/partition tests below — peer
/// to `canonical_figment_name_tag_kind_samples` on the figment-Name
/// axis.
fn canonical_env_metadata_tag_kind_samples() -> Vec<(String, EnvMetadataTagKind)> {
vec![
(
ConfigSource::env_metadata_name("MYAPP_"),
EnvMetadataTagKind::Prefixed,
),
(
ConfigSource::env_metadata_name("TOBIRA_"),
EnvMetadataTagKind::Prefixed,
),
(
ConfigSource::env_metadata_name(""),
EnvMetadataTagKind::Bare,
),
]
}
#[test]
fn env_metadata_tag_kind_classifies_each_variant() {
// The forward map EnvMetadataTag → EnvMetadataTagKind is
// exhaustive: every variant pins to exactly one kind. Mirrors
// `figment_name_tag_kind_classifies_each_variant` on the
// figment-Name axis.
let prefixed_name = ConfigSource::env_metadata_name("APP_");
let prefixed = ConfigSource::strip_env_metadata_name(&prefixed_name)
.expect("prefixed env metadata classifies");
assert_eq!(prefixed.kind(), EnvMetadataTagKind::Prefixed);
let bare_name = ConfigSource::env_metadata_name("");
let bare = ConfigSource::strip_env_metadata_name(&bare_name)
.expect("bare env metadata classifies");
assert_eq!(bare.kind(), EnvMetadataTagKind::Bare);
}
#[test]
fn env_metadata_tag_kind_is_data_free() {
// Inner data does not influence kind — every Prefixed variant
// maps to EnvMetadataTagKind::Prefixed regardless of the inner
// borrowed prefix slice. Mirrors `figment_name_tag_kind_is_data_free`
// on the figment-Name axis.
for prefix in ["MYAPP_", "TOBIRA_", "X_", "VERY_LONG_PREFIX_"] {
let tag = EnvMetadataTag::Prefixed(prefix);
assert_eq!(tag.kind(), EnvMetadataTagKind::Prefixed);
}
// The Bare variant has no inner data; the projection is constant.
assert_eq!(EnvMetadataTag::Bare.kind(), EnvMetadataTagKind::Bare);
}
#[test]
fn env_metadata_tag_kind_agrees_with_predicates_pointwise() {
// The kind() projection must agree with the kind-side
// `is_prefixed` / `is_bare` predicates pointwise on every
// constructible tag variant. Mirrors
// `figment_name_tag_kind_agrees_with_as_predicates_pointwise`
// on the figment-Name axis.
for (name, _) in canonical_env_metadata_tag_kind_samples() {
let tag = ConfigSource::strip_env_metadata_name(&name)
.expect("canonical sample must classify as env metadata");
assert_eq!(
tag.kind().is_prefixed(),
tag.kind() == EnvMetadataTagKind::Prefixed,
);
assert_eq!(tag.kind().is_bare(), tag.kind() == EnvMetadataTagKind::Bare,);
}
}
#[test]
fn env_metadata_tag_kind_is_static_and_copy_and_hashable() {
// The discriminant is `'static` (no lifetime parameter) so it
// can cross thread boundaries the borrowed tag cannot. Trait
// bounds match the sibling typescape primitives
// (FigmentNameTagKind, FigmentSourceKind, ConfigSourceKind,
// AttributionRule, AttributionConfidence, AttributionAxis).
fn assert_static<T: 'static>() {}
use std::collections::HashSet;
let mut set: HashSet<EnvMetadataTagKind> =
EnvMetadataTagKind::ALL.iter().copied().collect();
set.insert(EnvMetadataTagKind::Prefixed); // duplicate
assert_eq!(set.len(), EnvMetadataTagKind::ALL.len());
// Copy: rebind without move.
let k = EnvMetadataTagKind::Bare;
let k2 = k;
let k3 = k;
assert_eq!(k, k2);
assert_eq!(k2, k3);
// 'static — observable by inserting into a static bound.
assert_static::<EnvMetadataTagKind>();
}
#[test]
fn env_metadata_tag_kind_all_has_no_duplicates() {
// The constant must be a set — no variant listed twice. Pins
// the typescape discipline shared with FigmentNameTagKind::ALL,
// FigmentSourceKind::ALL, and the other closed-enum kind axes.
use std::collections::HashSet;
let set: HashSet<EnvMetadataTagKind> = EnvMetadataTagKind::ALL.iter().copied().collect();
assert_eq!(
set.len(),
EnvMetadataTagKind::ALL.len(),
"EnvMetadataTagKind::ALL must contain no duplicates; got: {:?}",
EnvMetadataTagKind::ALL,
);
}
#[test]
fn env_metadata_tag_kind_all_covers_every_constructible_tag() {
// Subset cover: every kind produced by EnvMetadataTag::kind
// over the canonical sample table must lie in
// EnvMetadataTagKind::ALL. A future tag variant that adds a new
// kind class must extend EnvMetadataTagKind and its ALL in the
// same commit; otherwise this test fails.
use std::collections::HashSet;
let declared: HashSet<EnvMetadataTagKind> =
EnvMetadataTagKind::ALL.iter().copied().collect();
let observed: HashSet<EnvMetadataTagKind> = canonical_env_metadata_tag_kind_samples()
.iter()
.map(|(name, _)| {
ConfigSource::strip_env_metadata_name(name)
.expect("canonical sample must classify as env metadata")
.kind()
})
.collect();
assert!(
observed.is_subset(&declared),
"EnvMetadataTag::kind image must lie in EnvMetadataTagKind::ALL; \
observed: {observed:?}, declared: {declared:?}",
);
}
#[test]
fn env_metadata_tag_kind_all_equals_tag_kind_image() {
// Tight equality (stronger than subset cover): every variant
// in EnvMetadataTagKind::ALL must be witnessed by at least one
// tag's kind() — no orphan variant in the declared kind space
// lacks a producing tag.
use std::collections::HashSet;
let declared: HashSet<EnvMetadataTagKind> =
EnvMetadataTagKind::ALL.iter().copied().collect();
let observed: HashSet<EnvMetadataTagKind> = canonical_env_metadata_tag_kind_samples()
.iter()
.map(|(name, _)| {
ConfigSource::strip_env_metadata_name(name)
.expect("canonical sample must classify as env metadata")
.kind()
})
.collect();
assert_eq!(
observed, declared,
"EnvMetadataTag::kind image must equal EnvMetadataTagKind::ALL",
);
}
#[test]
fn env_metadata_tag_kind_all_declaration_order_is_prefixed_bare() {
// Pin declaration order. Consumers (diagnostics legends,
// attestation manifests, dashboard column orderings) that
// iterate ALL get a stable order; reordering the slice is a
// breaking change that must show up here.
assert_eq!(
EnvMetadataTagKind::ALL,
&[EnvMetadataTagKind::Prefixed, EnvMetadataTagKind::Bare],
);
}
#[test]
fn env_metadata_tag_kind_all_partition_is_prefixed_xor_bare() {
// Boolean partition: `is_prefixed` / `is_bare` over a tag
// sliced by each kind cell must agree with the cell's identity.
let samples = canonical_env_metadata_tag_kind_samples();
for kind in EnvMetadataTagKind::ALL.iter().copied() {
let witnessing_name = samples
.iter()
.find(|(name, _)| {
ConfigSource::strip_env_metadata_name(name)
.expect("sample must classify")
.kind()
== kind
})
.map(|(name, _)| name)
.expect("every kind cell must be witnessed by some tag");
let tag = ConfigSource::strip_env_metadata_name(witnessing_name)
.expect("witness must classify");
match kind {
EnvMetadataTagKind::Prefixed => {
assert!(tag.kind().is_prefixed());
assert!(!tag.kind().is_bare());
}
EnvMetadataTagKind::Bare => {
assert!(tag.kind().is_bare());
assert!(!tag.kind().is_prefixed());
}
}
}
}
#[test]
fn env_metadata_tag_kind_as_str_yields_canonical_lowercase_names() {
// Concrete-position pin on EnvMetadataTagKind::as_str. The
// trait-uniform round-trip test in cube::tests pins labels
// equal pairwise under from_canonical_str, but this test pins
// the literal string values themselves so a future rename
// (e.g. capitalizing "Prefixed", prefixing "env-prefixed")
// fails here before drifting through the trait-uniform
// round-trip law and the operator-facing rendering surface.
assert_eq!(EnvMetadataTagKind::Prefixed.as_str(), "prefixed");
assert_eq!(EnvMetadataTagKind::Bare.as_str(), "bare");
}
#[test]
fn env_metadata_tag_kind_from_canonical_str_round_trips_through_trait() {
// Pin the trait-default `from_canonical_str` parse on
// EnvMetadataTagKind: each canonical lowercase name parses
// back to its variant via the ClosedAxisLabel default impl.
// Mixed-case forms an operator might type round-trip
// case-insensitively.
use crate::ClosedAxisLabel;
for k in EnvMetadataTagKind::ALL.iter().copied() {
assert_eq!(
<EnvMetadataTagKind as ClosedAxisLabel>::from_canonical_str(k.as_str()),
Some(k),
"trait from_canonical_str must round-trip for {k:?}",
);
}
assert_eq!(
<EnvMetadataTagKind as ClosedAxisLabel>::from_canonical_str("Prefixed"),
Some(EnvMetadataTagKind::Prefixed),
);
assert_eq!(
<EnvMetadataTagKind as ClosedAxisLabel>::from_canonical_str("BARE"),
Some(EnvMetadataTagKind::Bare),
);
// Unrecognized strings — including a trailing-whitespace case
// and a one-character drift — reject.
assert_eq!(
<EnvMetadataTagKind as ClosedAxisLabel>::from_canonical_str("bare "),
None,
);
assert_eq!(
<EnvMetadataTagKind as ClosedAxisLabel>::from_canonical_str("prefixe"),
None,
);
assert_eq!(
<EnvMetadataTagKind as ClosedAxisLabel>::from_canonical_str(""),
None,
);
}
#[test]
fn env_metadata_tag_kind_pairs_with_figment_name_tag_kind_env() {
// Cross-primitive bridge: when a FigmentNameTag is the Env
// variant, the inner EnvMetadataTag's kind classifies the
// env sub-shape. Pins the structural law that the
// (FigmentNameTagKind::Env → EnvMetadataTagKind) refinement
// path covers every env-shaped metadata-name observation.
for (name, expected_env_kind) in canonical_env_metadata_tag_kind_samples() {
let outer = FigmentNameTag::classify(&name)
.expect("canonical env metadata classifies via FigmentNameTag");
assert_eq!(outer.kind(), FigmentNameTagKind::Env);
let inner = outer
.as_env()
.expect("Env variant must expose inner EnvMetadataTag");
assert_eq!(inner.kind(), expected_env_kind);
}
}
#[test]
fn env_metadata_tag_kind_round_trips_through_figment_env_emission() {
// End-to-end: classify a real figment::providers::Env-emitted
// metadata-name through EnvMetadataTag::kind, and confirm the
// kind matches EnvMetadataTagKind::Prefixed for prefixed
// emissions. Pins the cross-side contract that figment's
// prefixed Env emission lands on the Prefixed kind cell.
use figment::Provider;
for prefix in ["MYAPP_", "TOBIRA_", "X_"] {
let env = figment::providers::Env::prefixed(prefix);
let md = env.metadata();
let name: &str = md.name.as_ref();
let tag = ConfigSource::strip_env_metadata_name(name)
.expect("figment prefixed Env name must classify as env metadata");
assert_eq!(tag.kind(), EnvMetadataTagKind::Prefixed);
}
}
}