Skip to main content

tatara_process/
boundary.rs

1//! Boundary conditions — predicates that gate phase transitions.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::flux_resource::FluxResource;
7
8/// Boundary specification — preconditions gate Running,
9/// postconditions gate Running → Attested.
10#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
11#[serde(rename_all = "camelCase")]
12pub struct Boundary {
13    #[serde(default)]
14    pub preconditions: Vec<Condition>,
15    #[serde(default)]
16    pub postconditions: Vec<Condition>,
17    /// Max time before VERIFY fails — parsed as a `go`-style duration.
18    /// Empty = controller default (15m).
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    pub timeout: Option<String>,
21}
22
23impl Boundary {
24    /// True iff at least one [`Condition`] in
25    /// `preconditions ∪ postconditions` carries the given
26    /// [`ConditionKind`] — the ONE substrate primitive that owns the
27    /// (closed-set discriminator, boundary-condition presence) probe on
28    /// this typed surface.
29    ///
30    /// # Semantics
31    ///
32    /// The two condition vectors are unioned: a caller asking "does this
33    /// spec name a `ClosedLoopAuth` predicate anywhere" doesn't care
34    /// whether the operator authored it on the pre- or post-condition
35    /// side. A boundary with the given kind on ONLY preconditions returns
36    /// `true`; a boundary with the given kind on ONLY postconditions
37    /// returns `true`; a boundary with neither returns `false`.
38    ///
39    /// # Sibling to [`crate::intent::Intent::has`] + [`crate::lifetime::Lifetime::has`]
40    ///
41    /// Same shape, same axis, third instance in the workspace-wide
42    /// closed-set-driven presence-probe algebra. `Intent::has` +
43    /// `Lifetime::has` publish the same `(&self, K) -> bool` signature
44    /// where `K` is the discriminator's `Kind` (auto-derived through
45    /// `#[derive(DeriveClosedSet)]`). A future normalization at that
46    /// probe shape (a widened return carrying the matching Condition
47    /// ref, a debug-build assertion on pre/post drift, a fleet-wide
48    /// warn on redundant duplicates) lands at ONE site per surface
49    /// and every downstream `<xxx>-<kind>` require-tag family +
50    /// closed-set audit dispatcher picks it up mechanically.
51    ///
52    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_condition_kind`]
53    ///
54    /// Same signature `(ConditionKind) -> bool`, same union body
55    /// (`preconditions.has_kind(k) || postconditions.has_kind(k)`), on
56    /// the sugar-surface type [`crate::ephemeral::EphemeralSpec`] whose
57    /// pre/post condition vectors live directly on the struct rather
58    /// than inside a nested [`Boundary`] slot. Both methods compose
59    /// against the ONE slice-level substrate primitive
60    /// [`ConditionSliceExt::has_kind`] — a regression at the per-slice
61    /// walk fails at that primitive's tests rather than as silent drift
62    /// at either struct-level union caller. The ephemeral require-tag
63    /// classifier reaches its `condition-<kind>` prefix family through
64    /// the peer method byte-for-byte symmetrical with the point
65    /// surface's `condition-<kind>` family that composes through this
66    /// method.
67    ///
68    /// # Compounding
69    ///
70    /// The point-domain require-tag surface in
71    /// `tatara-reconciler::bin::tatara-check` composes this primitive
72    /// with the closed-set `FromStr` autoderived on [`ConditionKind`]
73    /// through the `strip_and_classify_prefixed_kind` substrate to
74    /// publish a `condition-<kind>` prefix family byte-for-byte
75    /// symmetrical with `intent-<kind>` + `lifetime-<kind>`. A future
76    /// [`ConditionKind`] variant added to `ALL` reaches every downstream
77    /// (require-tag classifier, coherence check, editor completion
78    /// provider) through the SAME closed-set walk with no per-caller
79    /// edit.
80    ///
81    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition preserves
82    /// proofs — the presence-probe body lives at ONE substrate site so
83    /// every downstream `condition-<kind>` requires-tag surface,
84    /// closed-set audit dispatcher, and future variant addition binds
85    /// through the SAME shape). THEORY.md §VI.1 (generation over
86    /// composition — a ninth [`ConditionKind`] variant lands at ONE
87    /// `ALL` entry + ONE `as_str` arm and the presence probe picks it
88    /// up mechanically without further per-consumer edits).
89    #[must_use]
90    pub fn has_condition_kind(&self, kind: ConditionKind) -> bool {
91        self.has_precondition_kind(kind) || self.has_postcondition_kind(kind)
92    }
93
94    /// True iff at least one [`Condition`] in `self.preconditions`
95    /// carries the given [`ConditionKind`] — the precondition-side arm
96    /// of the (precondition, postcondition, condition-union) triad on
97    /// [`Boundary`], sibling to [`Self::has_postcondition_kind`] and
98    /// half-composition of [`Self::has_condition_kind`].
99    ///
100    /// Thin typed delegate to [`ConditionSliceExt::has_kind`] over
101    /// [`Self::preconditions`]. Peer of [`Self::has_postcondition_kind`]
102    /// on the (precondition, postcondition) partition of the boundary's
103    /// two condition-vector slots; both peers compose against the SAME
104    /// slice-level substrate primitive and their `||` composition is
105    /// [`Self::has_condition_kind`]. A regression that swapped the
106    /// slice at either arm (a copy-paste that pointed the precondition
107    /// probe at `self.postconditions`, an inline `.iter().any` closure
108    /// body that outlasted the lift) surfaces at the composition-law
109    /// pin `boundary_has_condition_kind_composes_precondition_and_postcondition_arms`
110    /// rather than as silent classifier drift at every downstream
111    /// `precondition-<kind>` require-tag callsite.
112    ///
113    /// # Why lift
114    ///
115    /// Pre-lift the point-domain `precondition-<kind>` require-tag
116    /// classifier in `tatara-reconciler::bin::tatara-check` reached the
117    /// precondition-side slice through direct field access
118    /// (`spec.boundary.preconditions.has_kind(k)`) while its sibling
119    /// `condition-<kind>` classifier routed through the named
120    /// [`Self::has_condition_kind`] primitive. The asymmetry meant a
121    /// future normalization at the presence-probe shape (a widened
122    /// return carrying the matching [`Condition`] ref, a debug-build
123    /// assertion on redundant duplicates, a fleet-wide warn on
124    /// pre-only ClosedLoopAuth authoring) would land at the union
125    /// primitive but bypass the two half-slice classifiers. Post-lift
126    /// the (precondition, postcondition, condition-union) triad lives
127    /// at ONE typed algebra surface on [`Boundary`], with the
128    /// `condition-<K> = precondition-<K> ∨ postcondition-<K>`
129    /// composition law pinned as a first-class typed invariant
130    /// (see the composition-pin test in this module) rather than a
131    /// per-caller discipline.
132    ///
133    /// # Semantics
134    ///
135    /// Returns `true` iff `self.preconditions.iter().any(|c| c.kind ==
136    /// kind)`. Ignores `self.postconditions` — an operator who authored
137    /// the kind on ONLY postconditions gets `false` from this probe and
138    /// `true` from [`Self::has_postcondition_kind`]. The two half-slice
139    /// arms partition the (kind, side) matrix exhaustively across the
140    /// four states (kind absent both, pre-only, post-only, both).
141    ///
142    /// # Sibling to [`crate::ephemeral::EphemeralSpec::has_precondition_kind`]
143    ///
144    /// Same shape, same axis, third and fourth methods in the
145    /// workspace-wide `has_(pre|post)condition_kind` two-surface
146    /// family. [`crate::ephemeral::EphemeralSpec::has_precondition_kind`]
147    /// composes byte-identical `preconditions.has_kind(k)` semantics on
148    /// the sugar-surface type's direct `preconditions: Vec<Condition>`
149    /// field, so both surfaces publish a `precondition-<kind>` require-
150    /// tag prefix family byte-for-byte symmetrical (point surface
151    /// through this method, ephemeral surface through its peer).
152    ///
153    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
154    /// preserves proofs — the per-slice presence-probe body lives at
155    /// ONE substrate site so every downstream `precondition-<kind>`
156    /// require-tag surface, closed-set audit dispatcher, and future
157    /// variant addition binds through the SAME shape). THEORY.md §VI.1
158    /// (generation over composition — the union primitive
159    /// [`Self::has_condition_kind`] emerges from the composition of
160    /// its two half-slice arms rather than as a hand-authored `||`
161    /// closure at every downstream consumer).
162    #[must_use]
163    pub fn has_precondition_kind(&self, kind: ConditionKind) -> bool {
164        self.preconditions.has_kind(kind)
165    }
166
167    /// True iff at least one [`Condition`] in `self.postconditions`
168    /// carries the given [`ConditionKind`] — the postcondition-side arm
169    /// of the (precondition, postcondition, condition-union) triad on
170    /// [`Boundary`], sibling to [`Self::has_precondition_kind`] and
171    /// half-composition of [`Self::has_condition_kind`].
172    ///
173    /// Thin typed delegate to [`ConditionSliceExt::has_kind`] over
174    /// [`Self::postconditions`]. Peer of [`Self::has_precondition_kind`]
175    /// on the (precondition, postcondition) partition of the boundary's
176    /// two condition-vector slots. See [`Self::has_precondition_kind`]
177    /// for the full rationale — the two methods share ONE lift
178    /// motivation, ONE fail-before-pass-after composition-law pin, and
179    /// ONE two-surface parity contract with the ephemeral sugar type
180    /// via [`crate::ephemeral::EphemeralSpec::has_postcondition_kind`].
181    #[must_use]
182    pub fn has_postcondition_kind(&self, kind: ConditionKind) -> bool {
183        self.postconditions.has_kind(kind)
184    }
185
186    /// Returns the first [`Condition`] in
187    /// `preconditions ∪ postconditions` carrying the given
188    /// [`ConditionKind`], searching preconditions first — the
189    /// widened peer of [`Self::has_condition_kind`] one refinement
190    /// higher on the presence-probe algebra.
191    ///
192    /// # Sibling to [`Self::has_condition_kind`]
193    ///
194    /// Same axis, one refinement wider: `has_condition_kind` collapses
195    /// the return to a `bool` (`find_condition_kind(k).is_some()`);
196    /// this method returns the matching `&Condition` so consumers can
197    /// read [`Condition::params`] (the `probeImage`, the `expression`,
198    /// the `flakeRef`) at the presence probe's own callsite without
199    /// re-walking the two condition vectors. Pinned by the composition
200    /// law `has_condition_kind(K) == find_condition_kind(K).is_some()`
201    /// at [`Boundary`]'s substrate-delegation test.
202    ///
203    /// # Semantics — precondition takes precedence
204    ///
205    /// Walks [`Self::preconditions`] first, then [`Self::postconditions`]:
206    /// a kind authored on BOTH sides returns the precondition-side
207    /// [`Condition`]. Callers that need the postcondition-side match
208    /// specifically reach for [`Self::find_postcondition_kind`]; callers
209    /// that need every match across both sides walk the two vectors
210    /// directly. Composition law: `find_condition_kind(K) ==
211    /// find_precondition_kind(K).or_else(|| find_postcondition_kind(K))`,
212    /// pinned as a first-class typed invariant.
213    ///
214    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::find_condition_kind`]
215    ///
216    /// Same signature `(ConditionKind) -> Option<&Condition>`, same
217    /// precondition-first body, on the sugar-surface type whose
218    /// pre/post condition vectors live directly on the struct. Both
219    /// methods compose against the SAME slice-level substrate primitive
220    /// [`ConditionSliceExt::find_kind`] — a regression at the per-slice
221    /// walk fails at that primitive's tests rather than as silent drift
222    /// at either struct-level widened caller.
223    ///
224    /// # Compounding
225    ///
226    /// A future diagnostic consumer (an operator-facing "condition
227    /// {kind} matched on {side} with params.{key}={value}" message
228    /// emitted by the require-tag classifier, a coherence check that
229    /// verifies "every `ClosedLoopAuth` postcondition carries a
230    /// non-empty `probeImage`" by inspecting the returned
231    /// `&Condition.params`, an editor completion listing which
232    /// params-keys appear on the present kind) reaches for the
233    /// matching [`Condition`] through this ONE method rather than
234    /// re-walking the two vectors with `iter().find(...)` at the
235    /// callsite. The presence-probe axis now carries both refinements
236    /// (bool via `has_condition_kind`, `&Condition` via
237    /// `find_condition_kind`) at ONE typed algebra surface per struct.
238    ///
239    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
240    /// preserves proofs — the widened return lives at ONE substrate
241    /// site so every downstream diagnostic consumer + coherence check
242    /// binds through the SAME shape rather than restating the
243    /// `.iter().find(|c| c.kind == K)` closure body).
244    #[must_use]
245    pub fn find_condition_kind(&self, kind: ConditionKind) -> Option<&Condition> {
246        self.find_precondition_kind(kind)
247            .or_else(|| self.find_postcondition_kind(kind))
248    }
249
250    /// Returns the first [`Condition`] in [`Self::preconditions`]
251    /// carrying the given [`ConditionKind`], or `None` — the
252    /// precondition-side arm of the (precondition, postcondition,
253    /// condition-union) widened triad on [`Boundary`]. Thin typed
254    /// delegate to [`ConditionSliceExt::find_kind`] over
255    /// [`Self::preconditions`].
256    ///
257    /// Peer of [`Self::find_postcondition_kind`] on the (precondition,
258    /// postcondition) partition of the boundary's two condition-vector
259    /// slots; both peers compose against the SAME slice-level substrate
260    /// primitive and their `or_else` composition is
261    /// [`Self::find_condition_kind`]. Byte-identical semantics to
262    /// [`Self::has_precondition_kind`] with a widened `Option<&Condition>`
263    /// return rather than a `bool`.
264    #[must_use]
265    pub fn find_precondition_kind(&self, kind: ConditionKind) -> Option<&Condition> {
266        self.preconditions.find_kind(kind)
267    }
268
269    /// Returns the first [`Condition`] in [`Self::postconditions`]
270    /// carrying the given [`ConditionKind`], or `None` — the
271    /// postcondition-side arm of the (precondition, postcondition,
272    /// condition-union) widened triad on [`Boundary`]. Thin typed
273    /// delegate to [`ConditionSliceExt::find_kind`] over
274    /// [`Self::postconditions`].
275    ///
276    /// Peer of [`Self::find_precondition_kind`] on the (precondition,
277    /// postcondition) partition of the boundary's two condition-vector
278    /// slots. See [`Self::find_precondition_kind`] for the full
279    /// rationale — the two methods share ONE lift motivation, ONE
280    /// fail-before-pass-after composition-law pin, and ONE two-surface
281    /// parity contract with the ephemeral sugar type via
282    /// [`crate::ephemeral::EphemeralSpec::find_postcondition_kind`].
283    #[must_use]
284    pub fn find_postcondition_kind(&self, kind: ConditionKind) -> Option<&Condition> {
285        self.postconditions.find_kind(kind)
286    }
287
288    /// Returns an iterator over every [`Condition`] in
289    /// `preconditions ∪ postconditions` carrying the given
290    /// [`ConditionKind`], walking preconditions first — the
291    /// widened peer of [`Self::find_condition_kind`] one refinement
292    /// higher on the presence-probe algebra. Byte-for-byte
293    /// equivalent to
294    /// `self.iter_precondition_kind(kind).chain(self.iter_postcondition_kind(kind))`.
295    ///
296    /// # Sibling to [`Self::find_condition_kind`]
297    ///
298    /// Same axis, one refinement wider: `find_condition_kind`
299    /// collapses the return to the FIRST match (yielding
300    /// `Option<&Condition>`); this method yields every match across
301    /// both sides. Pinned by the composition law
302    /// `find_condition_kind(K) == iter_condition_kind(K).next()` at
303    /// [`Boundary`]'s substrate-delegation test — the two refinements
304    /// share ONE walk order by construction (preconditions first,
305    /// then postconditions), so a regression that reversed the
306    /// [`Chain`](std::iter::Chain) order or narrowed the union to an
307    /// intersection surfaces HERE at the substrate boundary rather
308    /// than as silent skew between the first-match and stream
309    /// refinements downstream consumers reach through.
310    ///
311    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::iter_condition_kind`]
312    ///
313    /// Same signature `(ConditionKind) -> Chain<KindMatches<'_>,
314    /// KindMatches<'_>>`, same precondition-first chain body, on the
315    /// sugar-surface type whose pre/post condition vectors live
316    /// directly on the struct. Both methods compose against the SAME
317    /// slice-level substrate primitive [`ConditionSliceExt::iter_kind`]
318    /// — a regression at the per-slice walk fails at that primitive's
319    /// tests rather than as silent drift at either struct-level
320    /// widened caller.
321    ///
322    /// # Compounding
323    ///
324    /// A future coherence check that enforces "each
325    /// [`ConditionKind`] appears at most once across
326    /// preconditions ∪ postconditions" reads
327    /// `boundary.iter_condition_kind(k).nth(1).is_none()` at ONE
328    /// call site rather than restating the count-with-filter closure
329    /// body over the two vector slots. A future diagnostic
330    /// enumerating every match (an operator-facing "N ClosedLoopAuth
331    /// conditions matched, listing sides + params" message emitted
332    /// by the require-tag classifier) reaches this ONE method
333    /// through `boundary.iter_condition_kind(k).collect()` rather
334    /// than chaining two half-slice walks at the callsite.
335    /// The presence-probe axis on [`Boundary`] now carries three
336    /// refinements (bool via `has_condition_kind`,
337    /// `Option<&Condition>` via `find_condition_kind`,
338    /// `impl Iterator<Item = &Condition>` via
339    /// `iter_condition_kind`) at ONE typed algebra surface, byte-
340    /// for-byte peer of the same triad on
341    /// [`crate::ephemeral::EphemeralSpec`].
342    ///
343    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
344    /// preserves proofs — the widened stream lives at ONE substrate
345    /// site so every downstream diagnostic + coherence consumer binds
346    /// through the SAME shape rather than restating the two-half
347    /// chain body).
348    pub fn iter_condition_kind(
349        &self,
350        kind: ConditionKind,
351    ) -> std::iter::Chain<KindMatches<'_>, KindMatches<'_>> {
352        self.iter_precondition_kind(kind)
353            .chain(self.iter_postcondition_kind(kind))
354    }
355
356    /// Returns an iterator over every [`Condition`] in
357    /// [`Self::preconditions`] carrying the given [`ConditionKind`]
358    /// — the precondition-side arm of the (precondition,
359    /// postcondition, condition-union) iterator triad on
360    /// [`Boundary`]. Thin typed delegate to
361    /// [`ConditionSliceExt::iter_kind`] over [`Self::preconditions`].
362    ///
363    /// Peer of [`Self::iter_postcondition_kind`] on the (precondition,
364    /// postcondition) partition of the boundary's two condition-vector
365    /// slots; both peers compose against the SAME slice-level substrate
366    /// primitive and their [`Chain`](std::iter::Chain) composition is
367    /// [`Self::iter_condition_kind`]. Byte-identical semantics to
368    /// [`Self::find_precondition_kind`] with a widened stream return
369    /// rather than only the first match.
370    pub fn iter_precondition_kind(&self, kind: ConditionKind) -> KindMatches<'_> {
371        self.preconditions.iter_kind(kind)
372    }
373
374    /// Returns an iterator over every [`Condition`] in
375    /// [`Self::postconditions`] carrying the given [`ConditionKind`]
376    /// — the postcondition-side arm of the (precondition,
377    /// postcondition, condition-union) iterator triad on
378    /// [`Boundary`]. Thin typed delegate to
379    /// [`ConditionSliceExt::iter_kind`] over
380    /// [`Self::postconditions`].
381    ///
382    /// Peer of [`Self::iter_precondition_kind`] on the (precondition,
383    /// postcondition) partition of the boundary's two condition-vector
384    /// slots. See [`Self::iter_precondition_kind`] for the full
385    /// rationale — the two methods share ONE lift motivation, ONE
386    /// fail-before-pass-after composition-law pin, and ONE
387    /// two-surface parity contract with the ephemeral sugar type via
388    /// [`crate::ephemeral::EphemeralSpec::iter_postcondition_kind`].
389    pub fn iter_postcondition_kind(&self, kind: ConditionKind) -> KindMatches<'_> {
390        self.postconditions.iter_kind(kind)
391    }
392
393    /// Number of [`Condition`]s in `preconditions ∪ postconditions`
394    /// carrying the given [`ConditionKind`] — the scalar cardinality
395    /// arm of the (precondition, postcondition, condition-union)
396    /// count triad on [`Boundary`]. Composed as
397    /// `count_precondition_kind(k) + count_postcondition_kind(k)` —
398    /// the ONE SUM-composed arm on the presence-probe algebra
399    /// (distinct from `has_condition_kind`'s `||` union,
400    /// `find_condition_kind`'s `or_else` first-match, and
401    /// `iter_condition_kind`'s `Chain` stream).
402    ///
403    /// # Sibling to [`Self::iter_condition_kind`]
404    ///
405    /// Same axis, one refinement lower on the cardinality projection:
406    /// `iter_condition_kind` yields the whole match stream across both
407    /// sides; this method collapses that stream to its cardinality
408    /// without materializing any intermediate [`Vec`]. Composition law
409    /// `count_condition_kind(K) == iter_condition_kind(K).count()`
410    /// pinned as a first-class typed invariant at the substrate-
411    /// delegation test.
412    ///
413    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::count_condition_kind`]
414    ///
415    /// Same signature `(ConditionKind) -> usize`, same SUM body, on
416    /// the sugar-surface type whose pre/post condition vectors live
417    /// directly on the struct. Both methods compose against the SAME
418    /// slice-level substrate primitive [`ConditionSliceExt::count_kind`]
419    /// — a regression at the per-slice count fails at that primitive's
420    /// tests rather than as silent drift at either struct-level union
421    /// caller.
422    ///
423    /// # Compounding
424    ///
425    /// A future coherence check that enforces "each [`ConditionKind`]
426    /// appears at most once across preconditions ∪ postconditions"
427    /// reads `boundary.count_condition_kind(k) <= 1` at ONE call site.
428    /// A future require-tag classifier arm that surfaces multiplicity
429    /// to the operator (a hypothetical `condition-count-<kind>` prefix
430    /// family, an audit dump reporting "N ClosedLoopAuth conditions
431    /// matched") reaches this ONE method rather than restating the
432    /// `.iter_condition_kind(k).count()` chain body at the callsite.
433    /// The presence-probe axis on [`Boundary`] now carries FOUR
434    /// refinements (bool via `has_condition_kind`, `Option<&Condition>`
435    /// via `find_condition_kind`, `impl Iterator<Item = &Condition>`
436    /// via `iter_condition_kind`, `usize` via `count_condition_kind`)
437    /// at ONE typed algebra surface per struct, byte-for-byte peer of
438    /// the same tetrad on [`crate::ephemeral::EphemeralSpec`].
439    ///
440    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
441    /// preserves proofs — the scalar cardinality lives at ONE
442    /// substrate site so every downstream diagnostic + coherence
443    /// consumer binds through the SAME shape rather than restating
444    /// the two-half sum body).
445    #[must_use]
446    pub fn count_condition_kind(&self, kind: ConditionKind) -> usize {
447        self.count_precondition_kind(kind) + self.count_postcondition_kind(kind)
448    }
449
450    /// Number of [`Condition`]s in [`Self::preconditions`] carrying
451    /// the given [`ConditionKind`] — the precondition-side arm of the
452    /// (precondition, postcondition, condition-union) count triad on
453    /// [`Boundary`]. Thin typed delegate to
454    /// [`ConditionSliceExt::count_kind`] over [`Self::preconditions`].
455    ///
456    /// Peer of [`Self::count_postcondition_kind`] on the (precondition,
457    /// postcondition) partition of the boundary's two condition-vector
458    /// slots; both peers compose against the SAME slice-level substrate
459    /// primitive and their `+` composition is
460    /// [`Self::count_condition_kind`]. Byte-identical semantics to
461    /// [`Self::iter_precondition_kind`] with the scalar `usize`
462    /// cardinality projection rather than the widened stream.
463    #[must_use]
464    pub fn count_precondition_kind(&self, kind: ConditionKind) -> usize {
465        self.preconditions.count_kind(kind)
466    }
467
468    /// Number of [`Condition`]s in [`Self::postconditions`] carrying
469    /// the given [`ConditionKind`] — the postcondition-side arm of
470    /// the (precondition, postcondition, condition-union) count triad
471    /// on [`Boundary`]. Thin typed delegate to
472    /// [`ConditionSliceExt::count_kind`] over
473    /// [`Self::postconditions`].
474    ///
475    /// Peer of [`Self::count_precondition_kind`]. See that method for
476    /// the full rationale — the two methods share ONE lift motivation,
477    /// ONE fail-before-pass-after composition-law pin, and ONE
478    /// two-surface parity contract with the ephemeral sugar type via
479    /// [`crate::ephemeral::EphemeralSpec::count_postcondition_kind`].
480    #[must_use]
481    pub fn count_postcondition_kind(&self, kind: ConditionKind) -> usize {
482        self.postconditions.count_kind(kind)
483    }
484
485    /// The set of [`ConditionKind`] variants that appear at least once in
486    /// `preconditions ∪ postconditions`, projected in
487    /// [`ConditionKind::ALL`] order — the closed-set-inversion refinement
488    /// on the presence-probe algebra (distinct axis from the four point-
489    /// probe refinements: bool via [`Self::has_condition_kind`],
490    /// `Option<&Condition>` via [`Self::find_condition_kind`],
491    /// `impl Iterator<Item = &Condition>` via [`Self::iter_condition_kind`],
492    /// `usize` via [`Self::count_condition_kind`]).
493    ///
494    /// # Composed body
495    ///
496    /// `ConditionKind::ALL.into_iter().filter(|k|
497    /// self.has_condition_kind(*k)).collect()` — a thin projection over
498    /// the closed set composed against the two-slice union primitive
499    /// [`Self::has_condition_kind`]. Equivalent to the set-union of
500    /// [`Self::distinct_precondition_kinds`] and
501    /// [`Self::distinct_postcondition_kinds`] projected in canonical
502    /// [`ConditionKind::ALL`] order (the union composition law pinned by
503    /// the substrate testkit macro [`crate::assert_surface_union_composition_laws`]).
504    ///
505    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::distinct_condition_kinds`]
506    ///
507    /// Same signature `(&Self) -> Vec<ConditionKind>`, same closed-set-
508    /// inversion body, on the sugar-surface type whose pre/post condition
509    /// vectors live directly on the struct. Both methods compose against
510    /// the SAME slice-level substrate primitive
511    /// [`ConditionSliceExt::distinct_kinds`] via the two-slice union
512    /// composed through [`Self::has_condition_kind`] — a regression at
513    /// the per-slice walk fails at that primitive's tests rather than as
514    /// silent drift at either struct-level union caller.
515    ///
516    /// # Sibling to the four point-probe refinements
517    ///
518    /// FIFTH refinement on the boundary-surface presence-probe algebra,
519    /// distinct in axis from the other four: `has_condition_kind` /
520    /// `find_condition_kind` / `iter_condition_kind` /
521    /// `count_condition_kind` fix a [`ConditionKind`] and vary the return
522    /// type; this refinement INVERTS the axis by fixing the boundary and
523    /// varying over [`ConditionKind::ALL`]. The composition law
524    /// `distinct_condition_kinds().contains(&k) == has_condition_kind(k)`
525    /// for every `k ∈ ConditionKind::ALL` binds the closed-set-inversion
526    /// probe to the point probe at the (precondition, postcondition,
527    /// condition-union) triad.
528    ///
529    /// # Compounding
530    ///
531    /// A future coherence check that enforces "every process boundary
532    /// carries at least ONE distinct kind" (a warning surfaced when
533    /// `spec.boundary.distinct_condition_kinds().is_empty()`) reaches
534    /// this ONE method rather than paying for the eight-way sweep with
535    /// `has_condition_kind` at every callsite. A future require-tag
536    /// classifier that surfaces the distinct-set cardinality as a scalar
537    /// (a hypothetical `condition-kinds-distinct-<n>` prefix family, an
538    /// audit dump reporting "boundary carries N distinct kinds") reaches
539    /// this ONE method through `.distinct_condition_kinds().len()`
540    /// rather than restating the closed-set-inverted filter idiom at
541    /// every callsite.
542    ///
543    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition preserves
544    /// proofs — the closed-set-inversion aggregate is a typed projection
545    /// of [`Self::has_condition_kind`] over [`ConditionKind::ALL`], and
546    /// every downstream aggregate consumer binds through the SAME shape).
547    /// THEORY.md §VI.1 (generation over composition — a new
548    /// [`ConditionKind`] variant added to `ALL` reaches this method
549    /// mechanically through the closed-set walk).
550    #[must_use]
551    pub fn distinct_condition_kinds(&self) -> Vec<ConditionKind> {
552        ConditionKind::ALL
553            .into_iter()
554            .filter(|k| self.has_condition_kind(*k))
555            .collect()
556    }
557
558    /// The set of [`ConditionKind`] variants appearing at least once in
559    /// [`Self::preconditions`], projected in [`ConditionKind::ALL`]
560    /// order — the precondition-side arm of the (precondition,
561    /// postcondition, condition-union) distinct-set triad on
562    /// [`Boundary`]. Thin typed delegate to
563    /// [`ConditionSliceExt::distinct_kinds`] over
564    /// [`Self::preconditions`].
565    ///
566    /// Peer of [`Self::distinct_postcondition_kinds`] on the
567    /// (precondition, postcondition) partition of the boundary's two
568    /// condition-vector slots; both peers compose against the SAME
569    /// slice-level substrate primitive and their canonical set-union
570    /// (projected in [`ConditionKind::ALL`] order) is
571    /// [`Self::distinct_condition_kinds`].
572    #[must_use]
573    pub fn distinct_precondition_kinds(&self) -> Vec<ConditionKind> {
574        self.preconditions.distinct_kinds()
575    }
576
577    /// The set of [`ConditionKind`] variants appearing at least once in
578    /// [`Self::postconditions`], projected in [`ConditionKind::ALL`]
579    /// order — the postcondition-side arm of the (precondition,
580    /// postcondition, condition-union) distinct-set triad on
581    /// [`Boundary`]. Thin typed delegate to
582    /// [`ConditionSliceExt::distinct_kinds`] over
583    /// [`Self::postconditions`].
584    ///
585    /// Peer of [`Self::distinct_precondition_kinds`]. See that method
586    /// for the full rationale — the two methods share ONE lift
587    /// motivation, ONE fail-before-pass-after composition-law pin, and
588    /// ONE two-surface parity contract with the ephemeral sugar type
589    /// via [`crate::ephemeral::EphemeralSpec::distinct_postcondition_kinds`].
590    #[must_use]
591    pub fn distinct_postcondition_kinds(&self) -> Vec<ConditionKind> {
592        self.postconditions.distinct_kinds()
593    }
594
595    /// Zero-allocation iterator peer of [`Self::distinct_condition_kinds`]
596    /// — the condition-union arm of the (precondition, postcondition,
597    /// condition-union) closed-set-inversion iterator triad on
598    /// [`Boundary`]. Walks [`ConditionKind::ALL`] in canonical order and
599    /// yields every [`ConditionKind`] appearing at least once in
600    /// `preconditions ∪ postconditions`, WITHOUT materializing an
601    /// intermediate `Vec<ConditionKind>`.
602    ///
603    /// Composed body:
604    /// `ConditionKind::ALL.iter().copied().filter(|&k|
605    /// self.has_condition_kind(k))` — a thin projection over the closed
606    /// set composed against the two-slice union primitive
607    /// [`Self::has_condition_kind`], byte-identical to the trait-level
608    /// [`ConditionSliceExt::iter_distinct_kinds`] but reaching through
609    /// the boundary's two-slice union rather than a single slice.
610    /// Equivalent to `self.distinct_condition_kinds().into_iter()` without
611    /// the intermediate heap allocation.
612    ///
613    /// Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::iter_distinct_condition_kinds`].
614    /// Sibling to the three-slice `iter_*_condition_kinds` triad —
615    /// `iter_distinct_condition_kinds` walks the union, the two half-
616    /// slice arms `iter_distinct_precondition_kinds` and
617    /// `iter_distinct_postcondition_kinds` walk each side alone. See
618    /// [`Self::distinct_condition_kinds`] for the full rationale on the
619    /// closed-set-inversion aggregate.
620    pub fn iter_distinct_condition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
621        ConditionKind::ALL
622            .iter()
623            .copied()
624            .filter(|&k| self.has_condition_kind(k))
625    }
626
627    /// Zero-allocation iterator peer of
628    /// [`Self::distinct_precondition_kinds`] — the precondition-side arm
629    /// of the (precondition, postcondition, condition-union) closed-set-
630    /// inversion iterator triad on [`Boundary`]. Thin typed delegate to
631    /// [`ConditionSliceExt::iter_distinct_kinds`] over
632    /// [`Self::preconditions`].
633    pub fn iter_distinct_precondition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
634        self.preconditions.iter_distinct_kinds()
635    }
636
637    /// Zero-allocation iterator peer of
638    /// [`Self::distinct_postcondition_kinds`] — the postcondition-side
639    /// arm of the (precondition, postcondition, condition-union) closed-
640    /// set-inversion iterator triad on [`Boundary`]. Thin typed delegate
641    /// to [`ConditionSliceExt::iter_distinct_kinds`] over
642    /// [`Self::postconditions`].
643    pub fn iter_distinct_postcondition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
644        self.postconditions.iter_distinct_kinds()
645    }
646
647    /// Scalar cardinality of the [`ConditionKind`] set appearing at
648    /// least once in `preconditions ∪ postconditions` — the
649    /// condition-union arm of the (precondition, postcondition,
650    /// condition-union) distinct-kind-count triad on [`Boundary`].
651    ///
652    /// # Composed body
653    ///
654    /// `ConditionKind::ALL.iter().filter(|k|
655    /// self.has_condition_kind(**k)).count()` — a thin projection over
656    /// the closed set composed against the two-slice union primitive
657    /// [`Self::has_condition_kind`], byte-identical to the trait-level
658    /// [`ConditionSliceExt::distinct_kind_count`] but reaching through
659    /// the boundary's two-slice union rather than a single slice.
660    /// Equivalent to `self.distinct_condition_kinds().len()` without
661    /// materializing the intermediate `Vec<ConditionKind>`.
662    ///
663    /// # Sibling to [`Self::distinct_condition_kinds`]
664    ///
665    /// Scalar projection of the closed-set-inversion widened primitive
666    /// on the boundary-union surface — where `distinct_condition_kinds`
667    /// returns the SET, `distinct_condition_kind_count` collapses it to
668    /// its cardinality. Byte-for-byte peer of the point-domain scalar
669    /// projection [`ConditionSliceExt::distinct_kind_count`] one
670    /// struct-layer down, and of the peer surface sugar
671    /// [`crate::ephemeral::EphemeralSpec::distinct_condition_kind_count`]
672    /// one struct-layer sideways.
673    ///
674    /// # Compounding
675    ///
676    /// A future coherence check that enforces "every process boundary
677    /// carries at least ONE distinct kind" now reads
678    /// `spec.boundary.distinct_condition_kind_count() > 0` at ONE call
679    /// site rather than paying for
680    /// `spec.boundary.distinct_condition_kinds().len() > 0` (with its
681    /// intermediate heap allocation) or the eight-way `has_*_kind`
682    /// sweep at the callsite. A future require-tag classifier arm that
683    /// publishes the distinct-set cardinality as a scalar (a
684    /// hypothetical `condition-kinds-distinct-<n>` prefix family)
685    /// reaches this ONE primitive without allocating.
686    ///
687    /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
688    /// preserves proofs (the scalar cardinality composes the SAME
689    /// closed-set walk on both this boundary surface and the
690    /// slice-level substrate primitive). THEORY.md §VI.1 — generation
691    /// over composition (a new [`ConditionKind`] variant added to
692    /// `ALL` reaches this primitive mechanically through the closed-set
693    /// walk).
694    #[must_use]
695    pub fn distinct_condition_kind_count(&self) -> usize {
696        ConditionKind::ALL
697            .iter()
698            .filter(|k| self.has_condition_kind(**k))
699            .count()
700    }
701
702    /// Scalar cardinality of the [`ConditionKind`] set appearing at
703    /// least once in [`Self::preconditions`] — the precondition-side
704    /// arm of the (precondition, postcondition, condition-union)
705    /// distinct-kind-count triad on [`Boundary`]. Thin typed delegate
706    /// to [`ConditionSliceExt::distinct_kind_count`] over
707    /// [`Self::preconditions`].
708    ///
709    /// Peer of [`Self::distinct_postcondition_kind_count`] on the
710    /// (precondition, postcondition) partition of the boundary's two
711    /// condition-vector slots; both peers compose against the SAME
712    /// slice-level substrate primitive so a regression at the per-slice
713    /// closed-set walk fails at that primitive's tests rather than as
714    /// silent drift at either struct-level scalar-cardinality arm.
715    #[must_use]
716    pub fn distinct_precondition_kind_count(&self) -> usize {
717        self.preconditions.distinct_kind_count()
718    }
719
720    /// Scalar cardinality of the [`ConditionKind`] set appearing at
721    /// least once in [`Self::postconditions`] — the postcondition-side
722    /// arm of the (precondition, postcondition, condition-union)
723    /// distinct-kind-count triad on [`Boundary`]. Thin typed delegate
724    /// to [`ConditionSliceExt::distinct_kind_count`] over
725    /// [`Self::postconditions`].
726    ///
727    /// Peer of [`Self::distinct_precondition_kind_count`]. See that
728    /// method for the full rationale — the two methods share ONE lift
729    /// motivation, ONE fail-before-pass-after composition-law pin, and
730    /// ONE two-surface parity contract with the ephemeral sugar type
731    /// via
732    /// [`crate::ephemeral::EphemeralSpec::distinct_postcondition_kind_count`].
733    #[must_use]
734    pub fn distinct_postcondition_kind_count(&self) -> usize {
735        self.postconditions.distinct_kind_count()
736    }
737
738    /// The set of [`ConditionKind`] variants that do NOT appear in
739    /// `preconditions ∪ postconditions`, projected in
740    /// [`ConditionKind::ALL`] order — the closed-set-inversion
741    /// COMPLEMENT of [`Self::distinct_condition_kinds`] on the
742    /// (precondition, postcondition, condition-union) missing-set triad.
743    ///
744    /// # Composed body
745    ///
746    /// `ConditionKind::ALL.into_iter().filter(|k|
747    /// !self.has_condition_kind(*k)).collect()` — a thin projection
748    /// over the closed set composed against the two-slice union
749    /// primitive [`Self::has_condition_kind`] under a negated
750    /// predicate. Equivalent to the SET-INTERSECTION of
751    /// [`Self::missing_precondition_kinds`] and
752    /// [`Self::missing_postcondition_kinds`] projected in canonical
753    /// [`ConditionKind::ALL`] order — a kind is missing from the
754    /// union iff it is missing from BOTH half-slices (the union-
755    /// composition law pinned by the substrate testkit macro
756    /// [`crate::assert_surface_union_composition_laws`]).
757    ///
758    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::missing_condition_kinds`]
759    ///
760    /// Same signature `(&Self) -> Vec<ConditionKind>`, same closed-set-
761    /// complement body, on the sugar-surface type. Both methods compose
762    /// against the SAME slice-level substrate primitive
763    /// [`ConditionSliceExt::missing_kinds`] via the two-slice union
764    /// composed through [`Self::has_condition_kind`] — a regression at
765    /// the per-slice walk fails at that primitive's tests rather than
766    /// as silent drift at either struct-level complement caller.
767    ///
768    /// # Sibling to [`Self::distinct_condition_kinds`]
769    ///
770    /// SIXTH refinement on the boundary-surface presence-probe algebra,
771    /// on the SAME closed-set-inversion axis as `distinct_condition_kinds`
772    /// but under a NEGATED point-probe. The composition law
773    /// `missing_condition_kinds().contains(&k) ==
774    /// !has_condition_kind(k)` for every `k ∈ ConditionKind::ALL`
775    /// binds the complement to the point probe at the triad — and the
776    /// two widened primitives PARTITION `ConditionKind::ALL` (their
777    /// union covers `ALL`, their intersection is empty, their
778    /// cardinalities sum to `ALL.len()`).
779    ///
780    /// # Compounding
781    ///
782    /// A future coherence check that enforces "every process boundary
783    /// carries a [`ConditionKind::JobAttested`] postcondition" surfaces
784    /// the operator-facing gap diagnostic
785    /// `spec.boundary.postconditions.missing_kinds()` verbatim (naming
786    /// EVERY kind absent from postconditions in canonical order). A
787    /// future operator-facing "boundary is MISSING [JobAttested,
788    /// ClosedLoopAuth]" audit dump reads this ONE method rather than
789    /// restating the negated closed-set walk at every consumer. A
790    /// hypothetical `condition-kinds-missing-<n>` require-tag classifier
791    /// prefix family that publishes the missing-set cardinality as a
792    /// scalar reaches `.missing_condition_kinds().len()`.
793    ///
794    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
795    /// preserves proofs — the closed-set complement is a typed
796    /// projection of [`Self::has_condition_kind`] over
797    /// [`ConditionKind::ALL`] under negation, and every downstream
798    /// gap-analysis consumer binds through the SAME shape).
799    /// THEORY.md §VI.1 (generation over composition — a new
800    /// [`ConditionKind`] variant added to `ALL` reaches this method
801    /// mechanically through the closed-set walk).
802    #[must_use]
803    pub fn missing_condition_kinds(&self) -> Vec<ConditionKind> {
804        ConditionKind::ALL
805            .into_iter()
806            .filter(|k| !self.has_condition_kind(*k))
807            .collect()
808    }
809
810    /// The set of [`ConditionKind`] variants that do NOT appear in
811    /// [`Self::preconditions`], projected in [`ConditionKind::ALL`]
812    /// order — the precondition-side arm of the (precondition,
813    /// postcondition, condition-union) missing-set triad on
814    /// [`Boundary`]. Thin typed delegate to
815    /// [`ConditionSliceExt::missing_kinds`] over
816    /// [`Self::preconditions`].
817    ///
818    /// Peer of [`Self::missing_postcondition_kinds`] on the
819    /// (precondition, postcondition) partition of the boundary's two
820    /// condition-vector slots; both peers compose against the SAME
821    /// slice-level substrate primitive and their SET-INTERSECTION
822    /// (projected in [`ConditionKind::ALL`] order) is
823    /// [`Self::missing_condition_kinds`].
824    #[must_use]
825    pub fn missing_precondition_kinds(&self) -> Vec<ConditionKind> {
826        self.preconditions.missing_kinds()
827    }
828
829    /// The set of [`ConditionKind`] variants that do NOT appear in
830    /// [`Self::postconditions`], projected in [`ConditionKind::ALL`]
831    /// order — the postcondition-side arm of the (precondition,
832    /// postcondition, condition-union) missing-set triad on
833    /// [`Boundary`]. Thin typed delegate to
834    /// [`ConditionSliceExt::missing_kinds`] over
835    /// [`Self::postconditions`].
836    ///
837    /// Peer of [`Self::missing_precondition_kinds`]. See that method
838    /// for the full rationale — the two methods share ONE lift
839    /// motivation, ONE fail-before-pass-after composition-law pin, and
840    /// ONE two-surface parity contract with the ephemeral sugar type
841    /// via [`crate::ephemeral::EphemeralSpec::missing_postcondition_kinds`].
842    #[must_use]
843    pub fn missing_postcondition_kinds(&self) -> Vec<ConditionKind> {
844        self.postconditions.missing_kinds()
845    }
846
847    /// Zero-allocation iterator peer of [`Self::missing_condition_kinds`]
848    /// — the condition-union arm of the (precondition, postcondition,
849    /// condition-union) closed-set-complement iterator triad on
850    /// [`Boundary`]. Walks [`ConditionKind::ALL`] in canonical order and
851    /// yields every [`ConditionKind`] that does NOT appear in
852    /// `preconditions ∪ postconditions`, WITHOUT materializing an
853    /// intermediate `Vec<ConditionKind>`.
854    ///
855    /// Composed body:
856    /// `ConditionKind::ALL.iter().copied().filter(|&k|
857    /// !self.has_condition_kind(k))` — a thin projection over the closed
858    /// set composed against the two-slice union primitive
859    /// [`Self::has_condition_kind`] under a NEGATED predicate, byte-
860    /// identical to the trait-level
861    /// [`ConditionSliceExt::iter_missing_kinds`] but reaching through
862    /// the boundary's two-slice union rather than a single slice.
863    /// Equivalent to `self.missing_condition_kinds().into_iter()` without
864    /// the intermediate heap allocation.
865    ///
866    /// Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::iter_missing_condition_kinds`].
867    /// Sibling to the three-slice `iter_missing_*_kinds` triad and to the
868    /// closed-set-INVERSION peer [`Self::iter_distinct_condition_kinds`] —
869    /// the two iterators PARTITION `ConditionKind::ALL` under the
870    /// `has_condition_kind` union probe. See
871    /// [`Self::missing_condition_kinds`] for the full rationale on the
872    /// closed-set-complement aggregate.
873    pub fn iter_missing_condition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
874        ConditionKind::ALL
875            .iter()
876            .copied()
877            .filter(|&k| !self.has_condition_kind(k))
878    }
879
880    /// Zero-allocation iterator peer of
881    /// [`Self::missing_precondition_kinds`] — the precondition-side arm
882    /// of the (precondition, postcondition, condition-union) closed-set-
883    /// complement iterator triad on [`Boundary`]. Thin typed delegate to
884    /// [`ConditionSliceExt::iter_missing_kinds`] over
885    /// [`Self::preconditions`].
886    pub fn iter_missing_precondition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
887        self.preconditions.iter_missing_kinds()
888    }
889
890    /// Zero-allocation iterator peer of
891    /// [`Self::missing_postcondition_kinds`] — the postcondition-side arm
892    /// of the (precondition, postcondition, condition-union) closed-set-
893    /// complement iterator triad on [`Boundary`]. Thin typed delegate to
894    /// [`ConditionSliceExt::iter_missing_kinds`] over
895    /// [`Self::postconditions`].
896    pub fn iter_missing_postcondition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
897        self.postconditions.iter_missing_kinds()
898    }
899
900    /// Scalar cardinality of the [`ConditionKind`] set NOT appearing in
901    /// `preconditions ∪ postconditions` — the condition-union arm of the
902    /// (precondition, postcondition, condition-union) missing-kind-count
903    /// triad on [`Boundary`].
904    ///
905    /// # Composed body
906    ///
907    /// `ConditionKind::ALL.iter().filter(|k|
908    /// !self.has_condition_kind(**k)).count()` — a thin projection over
909    /// the closed set composed against the two-slice union primitive
910    /// [`Self::has_condition_kind`] under a NEGATED predicate, byte-
911    /// identical to the trait-level
912    /// [`ConditionSliceExt::missing_kind_count`] but reaching through
913    /// the boundary's two-slice union rather than a single slice.
914    /// Equivalent to `self.missing_condition_kinds().len()` without
915    /// materializing the intermediate `Vec<ConditionKind>`.
916    ///
917    /// # Sibling to [`Self::missing_condition_kinds`] /
918    /// [`Self::distinct_condition_kind_count`]
919    ///
920    /// Scalar projection of the closed-set-complement widened primitive
921    /// on the boundary-union surface — where `missing_condition_kinds`
922    /// returns the SET, `missing_condition_kind_count` collapses it to
923    /// its cardinality. Byte-for-byte peer of the point-domain scalar
924    /// projection [`ConditionSliceExt::missing_kind_count`] one struct-
925    /// layer down, and of the peer surface sugar
926    /// [`crate::ephemeral::EphemeralSpec::missing_condition_kind_count`]
927    /// one struct-layer sideways.
928    ///
929    /// The scalar-partition composition law
930    /// `distinct_condition_kind_count() + missing_condition_kind_count()
931    /// == ConditionKind::ALL.len()` binds this method's return to its
932    /// distinct-side peer through the closed-set cardinality — the
933    /// scalar consequence of the widened-primitive partition law that
934    /// [`assert_slice_refinement_composition_laws`] pins on each slice
935    /// and that [`crate::assert_surface_union_composition_laws`] lifts
936    /// to the two-slice union.
937    ///
938    /// # Compounding
939    ///
940    /// A future coherence check that enforces "every process boundary
941    /// carries EVERY [`ConditionKind`] under some slot" now reads
942    /// `spec.boundary.missing_condition_kind_count() == 0` at ONE call
943    /// site rather than paying for
944    /// `spec.boundary.missing_condition_kinds().is_empty()` (with its
945    /// intermediate heap allocation) or the eight-way negated `has_*_kind`
946    /// sweep at the callsite. A future require-tag classifier arm that
947    /// publishes the missing-set cardinality as a scalar (a hypothetical
948    /// `condition-kinds-missing-<n>` prefix family) reaches this ONE
949    /// primitive without allocating.
950    ///
951    /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
952    /// preserves proofs (the scalar cardinality composes the SAME
953    /// closed-set walk under negation on both this boundary surface and
954    /// the slice-level substrate primitive). THEORY.md §VI.1 —
955    /// generation over composition (a new [`ConditionKind`] variant
956    /// added to `ALL` reaches this primitive mechanically through the
957    /// closed-set walk).
958    #[must_use]
959    pub fn missing_condition_kind_count(&self) -> usize {
960        ConditionKind::ALL
961            .iter()
962            .filter(|k| !self.has_condition_kind(**k))
963            .count()
964    }
965
966    /// Scalar cardinality of the [`ConditionKind`] set NOT appearing in
967    /// [`Self::preconditions`] — the precondition-side arm of the
968    /// (precondition, postcondition, condition-union) missing-kind-count
969    /// triad on [`Boundary`]. Thin typed delegate to
970    /// [`ConditionSliceExt::missing_kind_count`] over
971    /// [`Self::preconditions`].
972    ///
973    /// Peer of [`Self::missing_postcondition_kind_count`] on the
974    /// (precondition, postcondition) partition of the boundary's two
975    /// condition-vector slots; both peers compose against the SAME
976    /// slice-level substrate primitive so a regression at the per-slice
977    /// negated closed-set walk fails at that primitive's tests rather
978    /// than as silent drift at either struct-level scalar-cardinality
979    /// arm.
980    #[must_use]
981    pub fn missing_precondition_kind_count(&self) -> usize {
982        self.preconditions.missing_kind_count()
983    }
984
985    /// Scalar cardinality of the [`ConditionKind`] set NOT appearing in
986    /// [`Self::postconditions`] — the postcondition-side arm of the
987    /// (precondition, postcondition, condition-union) missing-kind-count
988    /// triad on [`Boundary`]. Thin typed delegate to
989    /// [`ConditionSliceExt::missing_kind_count`] over
990    /// [`Self::postconditions`].
991    ///
992    /// Peer of [`Self::missing_precondition_kind_count`]. See that
993    /// method for the full rationale — the two methods share ONE lift
994    /// motivation, ONE fail-before-pass-after composition-law pin, and
995    /// ONE two-surface parity contract with the ephemeral sugar type
996    /// via
997    /// [`crate::ephemeral::EphemeralSpec::missing_postcondition_kind_count`].
998    #[must_use]
999    pub fn missing_postcondition_kind_count(&self) -> usize {
1000        self.postconditions.missing_kind_count()
1001    }
1002
1003    /// Earliest [`ConditionKind::ALL`] entry present in
1004    /// `preconditions ∪ postconditions`, or `None` when neither side
1005    /// populates any variant — the union arm of the (precondition,
1006    /// postcondition, condition-union) first-distinct-kind triad on
1007    /// [`Boundary`].
1008    ///
1009    /// # Composed body
1010    ///
1011    /// `ConditionKind::ALL.iter().copied().find(|k|
1012    /// self.has_condition_kind(*k))` — a closed-set walk composed
1013    /// against the two-slice union primitive
1014    /// [`Self::has_condition_kind`] that SHORT-CIRCUITS at the earliest
1015    /// match. Byte-identical to the trait-level
1016    /// [`ConditionSliceExt::first_distinct_kind`] but reaching through
1017    /// the boundary's two-slice union rather than a single slice.
1018    /// Equivalent to `self.distinct_condition_kinds().first().copied()`
1019    /// without materializing the intermediate `Vec<ConditionKind>`.
1020    ///
1021    /// # Sibling to [`Self::distinct_condition_kinds`] /
1022    /// [`Self::distinct_condition_kind_count`]
1023    ///
1024    /// Third scalar projection of the closed-set-inversion widened
1025    /// primitive on the boundary-union surface: `distinct_condition_kinds`
1026    /// returns the SET, `distinct_condition_kind_count` collapses it to
1027    /// its cardinality, and `first_distinct_condition_kind` collapses
1028    /// it to its earliest element. Byte-for-byte peer of the point-domain
1029    /// scalar projection [`ConditionSliceExt::first_distinct_kind`] one
1030    /// struct-layer down, and of the peer surface sugar
1031    /// [`crate::ephemeral::EphemeralSpec::first_distinct_condition_kind`]
1032    /// one struct-layer sideways.
1033    ///
1034    /// # Compounding
1035    ///
1036    /// A future coherence check that surfaces "boundary starts with
1037    /// PromQL" reads `spec.boundary.first_distinct_condition_kind() ==
1038    /// Some(ConditionKind::PromQL)` at ONE call site rather than
1039    /// paying for `spec.boundary.distinct_condition_kinds().first() ==
1040    /// Some(&ConditionKind::PromQL)` (with its intermediate heap
1041    /// allocation) or the eight-way `has_*_kind` sweep at the callsite.
1042    /// A future require-tag classifier arm that publishes the earliest
1043    /// distinct kind as a scalar
1044    /// (`condition-kinds-first-distinct-<kind>`) reaches this ONE
1045    /// primitive without allocating.
1046    ///
1047    /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
1048    /// preserves proofs (the earliest-element projection composes the
1049    /// SAME closed-set walk on both this boundary surface and the
1050    /// slice-level substrate primitive under short-circuit semantics).
1051    /// THEORY.md §VI.1 — generation over composition (a new
1052    /// [`ConditionKind`] variant added to `ALL` reaches this primitive
1053    /// mechanically through the closed-set walk).
1054    #[must_use]
1055    pub fn first_distinct_condition_kind(&self) -> Option<ConditionKind> {
1056        ConditionKind::ALL
1057            .iter()
1058            .copied()
1059            .find(|k| self.has_condition_kind(*k))
1060    }
1061
1062    /// Earliest [`ConditionKind::ALL`] entry present in
1063    /// [`Self::preconditions`], or `None` when preconditions carry no
1064    /// matching kind — the precondition-side arm of the (precondition,
1065    /// postcondition, condition-union) first-distinct-kind triad on
1066    /// [`Boundary`]. Thin typed delegate to
1067    /// [`ConditionSliceExt::first_distinct_kind`] over
1068    /// [`Self::preconditions`].
1069    ///
1070    /// Peer of [`Self::first_distinct_postcondition_kind`] on the
1071    /// (precondition, postcondition) partition of the boundary's two
1072    /// condition-vector slots; both peers compose against the SAME
1073    /// slice-level substrate primitive so a regression at the per-slice
1074    /// short-circuit walk fails at that primitive's tests rather than
1075    /// as silent drift at either struct-level arm.
1076    #[must_use]
1077    pub fn first_distinct_precondition_kind(&self) -> Option<ConditionKind> {
1078        self.preconditions.first_distinct_kind()
1079    }
1080
1081    /// Earliest [`ConditionKind::ALL`] entry present in
1082    /// [`Self::postconditions`], or `None` when postconditions carry no
1083    /// matching kind — the postcondition-side arm of the (precondition,
1084    /// postcondition, condition-union) first-distinct-kind triad on
1085    /// [`Boundary`]. Thin typed delegate to
1086    /// [`ConditionSliceExt::first_distinct_kind`] over
1087    /// [`Self::postconditions`].
1088    ///
1089    /// Peer of [`Self::first_distinct_precondition_kind`]. See that
1090    /// method for the full rationale — the two methods share ONE lift
1091    /// motivation, ONE fail-before-pass-after composition-law pin, and
1092    /// ONE two-surface parity contract with the ephemeral sugar type
1093    /// via
1094    /// [`crate::ephemeral::EphemeralSpec::first_distinct_postcondition_kind`].
1095    #[must_use]
1096    pub fn first_distinct_postcondition_kind(&self) -> Option<ConditionKind> {
1097        self.postconditions.first_distinct_kind()
1098    }
1099
1100    /// Earliest [`ConditionKind::ALL`] entry ABSENT from
1101    /// `preconditions ∪ postconditions`, or `None` when the union
1102    /// carries every variant — the union arm of the (precondition,
1103    /// postcondition, condition-union) first-missing-kind triad on
1104    /// [`Boundary`].
1105    ///
1106    /// # Composed body
1107    ///
1108    /// `ConditionKind::ALL.iter().copied().find(|k|
1109    /// !self.has_condition_kind(*k))` — a closed-set walk composed
1110    /// against the two-slice union primitive
1111    /// [`Self::has_condition_kind`] under a NEGATED predicate that
1112    /// SHORT-CIRCUITS at the earliest empty slot. Byte-identical to the
1113    /// trait-level [`ConditionSliceExt::first_missing_kind`] but
1114    /// reaching through the boundary's two-slice union rather than a
1115    /// single slice. Equivalent to
1116    /// `self.missing_condition_kinds().first().copied()` without
1117    /// materializing the intermediate `Vec<ConditionKind>`.
1118    ///
1119    /// # Sibling to [`Self::missing_condition_kinds`] /
1120    /// [`Self::missing_condition_kind_count`]
1121    ///
1122    /// Third scalar projection of the closed-set-complement widened
1123    /// primitive on the boundary-union surface. Byte-for-byte peer of
1124    /// [`Self::first_distinct_condition_kind`] one axis over under a
1125    /// negated predicate: where `first_distinct_condition_kind` scalar-
1126    /// projects the closed-set-INVERSION widened primitive onto its
1127    /// earliest element, this method scalar-projects the closed-set-
1128    /// COMPLEMENT widened primitive onto its earliest element.
1129    ///
1130    /// # Compounding
1131    ///
1132    /// A future coherence check that surfaces "boundary starts missing
1133    /// ProcessPhase" reads `spec.boundary.first_missing_condition_kind()
1134    /// == Some(ConditionKind::ProcessPhase)` at ONE call site rather
1135    /// than paying for `spec.boundary.missing_condition_kinds().first()
1136    /// == Some(&ConditionKind::ProcessPhase)` (with its intermediate
1137    /// heap allocation). An operator-facing "first still-unfilled
1138    /// closed-loop kind" audit reaches this ONE substrate site rather
1139    /// than restating the negated closed-set walk at every consumer.
1140    ///
1141    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1142    /// preserves proofs — the complement-earliest-element projection
1143    /// composes the SAME closed-set walk on both this boundary surface
1144    /// and the slice-level substrate primitive under short-circuit
1145    /// semantics with a negated predicate). THEORY.md §VI.1
1146    /// (generation over composition — a new [`ConditionKind`] variant
1147    /// added to `ALL` reaches this primitive mechanically through the
1148    /// closed-set walk).
1149    #[must_use]
1150    pub fn first_missing_condition_kind(&self) -> Option<ConditionKind> {
1151        ConditionKind::ALL
1152            .iter()
1153            .copied()
1154            .find(|k| !self.has_condition_kind(*k))
1155    }
1156
1157    /// Earliest [`ConditionKind::ALL`] entry ABSENT from
1158    /// [`Self::preconditions`], or `None` when preconditions carry
1159    /// every variant — the precondition-side arm of the (precondition,
1160    /// postcondition, condition-union) first-missing-kind triad on
1161    /// [`Boundary`]. Thin typed delegate to
1162    /// [`ConditionSliceExt::first_missing_kind`] over
1163    /// [`Self::preconditions`].
1164    ///
1165    /// Peer of [`Self::first_missing_postcondition_kind`] on the
1166    /// (precondition, postcondition) partition of the boundary's two
1167    /// condition-vector slots; both peers compose against the SAME
1168    /// slice-level substrate primitive so a regression at the per-slice
1169    /// negated short-circuit walk fails at that primitive's tests
1170    /// rather than as silent drift at either struct-level arm.
1171    #[must_use]
1172    pub fn first_missing_precondition_kind(&self) -> Option<ConditionKind> {
1173        self.preconditions.first_missing_kind()
1174    }
1175
1176    /// Earliest [`ConditionKind::ALL`] entry ABSENT from
1177    /// [`Self::postconditions`], or `None` when postconditions carry
1178    /// every variant — the postcondition-side arm of the (precondition,
1179    /// postcondition, condition-union) first-missing-kind triad on
1180    /// [`Boundary`]. Thin typed delegate to
1181    /// [`ConditionSliceExt::first_missing_kind`] over
1182    /// [`Self::postconditions`].
1183    ///
1184    /// Peer of [`Self::first_missing_precondition_kind`]. See that
1185    /// method for the full rationale — the two methods share ONE lift
1186    /// motivation, ONE fail-before-pass-after composition-law pin, and
1187    /// ONE two-surface parity contract with the ephemeral sugar type
1188    /// via
1189    /// [`crate::ephemeral::EphemeralSpec::first_missing_postcondition_kind`].
1190    #[must_use]
1191    pub fn first_missing_postcondition_kind(&self) -> Option<ConditionKind> {
1192        self.postconditions.first_missing_kind()
1193    }
1194
1195    /// Latest [`ConditionKind::ALL`] entry present in
1196    /// `preconditions ∪ postconditions`, or `None` when neither side
1197    /// populates any variant — the union arm of the (precondition,
1198    /// postcondition, condition-union) last-distinct-kind triad on
1199    /// [`Boundary`].
1200    ///
1201    /// # Composed body
1202    ///
1203    /// `ConditionKind::ALL.iter().rev().copied().find(|k|
1204    /// self.has_condition_kind(*k))` — a REVERSED closed-set walk
1205    /// composed against the two-slice union primitive
1206    /// [`Self::has_condition_kind`] that SHORT-CIRCUITS at the latest
1207    /// match. Byte-identical to the trait-level
1208    /// [`ConditionSliceExt::last_distinct_kind`] but reaching through
1209    /// the boundary's two-slice union rather than a single slice.
1210    /// Equivalent to `self.distinct_condition_kinds().last().copied()`
1211    /// without materializing the intermediate `Vec<ConditionKind>`.
1212    ///
1213    /// # Sibling to [`Self::first_distinct_condition_kind`]
1214    ///
1215    /// Time-reversed peer of the earliest-element scalar projection
1216    /// under the SAME two-slice union predicate. Together with
1217    /// `first_distinct_condition_kind` and the two `_missing_*` peers
1218    /// the four scalar-endpoint projections close the "endpoint of
1219    /// closed-set-inversion/complement widened primitive" refinement
1220    /// axis on the boundary-union surface.
1221    ///
1222    /// # Compounding
1223    ///
1224    /// A future coherence check that surfaces "boundary ends with
1225    /// ClosedLoopAuth" reads `spec.boundary.last_distinct_condition_kind()
1226    /// == Some(ConditionKind::ClosedLoopAuth)` at ONE call site rather
1227    /// than paying for `spec.boundary.distinct_condition_kinds().last()
1228    /// == Some(&…)` with its intermediate heap allocation. A future
1229    /// require-tag classifier arm that publishes the latest distinct
1230    /// kind as a scalar (`condition-kinds-last-distinct-<kind>`) reaches
1231    /// this ONE primitive without allocating.
1232    ///
1233    /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
1234    /// preserves proofs (the latest-element projection composes the
1235    /// SAME reversed closed-set walk on both this boundary surface and
1236    /// the slice-level substrate primitive under short-circuit
1237    /// semantics). THEORY.md §VI.1 — generation over composition (a
1238    /// new [`ConditionKind`] variant added to `ALL` reaches this
1239    /// primitive mechanically through the reversed closed-set walk).
1240    #[must_use]
1241    pub fn last_distinct_condition_kind(&self) -> Option<ConditionKind> {
1242        ConditionKind::ALL
1243            .iter()
1244            .rev()
1245            .copied()
1246            .find(|k| self.has_condition_kind(*k))
1247    }
1248
1249    /// Latest [`ConditionKind::ALL`] entry present in
1250    /// [`Self::preconditions`], or `None` when preconditions carry no
1251    /// matching kind — the precondition-side arm of the (precondition,
1252    /// postcondition, condition-union) last-distinct-kind triad on
1253    /// [`Boundary`]. Thin typed delegate to
1254    /// [`ConditionSliceExt::last_distinct_kind`] over
1255    /// [`Self::preconditions`].
1256    ///
1257    /// Peer of [`Self::last_distinct_postcondition_kind`] on the
1258    /// (precondition, postcondition) partition of the boundary's two
1259    /// condition-vector slots; both peers compose against the SAME
1260    /// slice-level substrate primitive so a regression at the per-
1261    /// slice REVERSED short-circuit walk fails at that primitive's
1262    /// tests rather than as silent drift at either struct-level arm.
1263    #[must_use]
1264    pub fn last_distinct_precondition_kind(&self) -> Option<ConditionKind> {
1265        self.preconditions.last_distinct_kind()
1266    }
1267
1268    /// Latest [`ConditionKind::ALL`] entry present in
1269    /// [`Self::postconditions`], or `None` when postconditions carry
1270    /// no matching kind — the postcondition-side arm of the
1271    /// (precondition, postcondition, condition-union) last-distinct-
1272    /// kind triad on [`Boundary`]. Thin typed delegate to
1273    /// [`ConditionSliceExt::last_distinct_kind`] over
1274    /// [`Self::postconditions`].
1275    ///
1276    /// Peer of [`Self::last_distinct_precondition_kind`]. See that
1277    /// method for the full rationale — the two methods share ONE lift
1278    /// motivation, ONE fail-before-pass-after composition-law pin, and
1279    /// ONE two-surface parity contract with the ephemeral sugar type
1280    /// via
1281    /// [`crate::ephemeral::EphemeralSpec::last_distinct_postcondition_kind`].
1282    #[must_use]
1283    pub fn last_distinct_postcondition_kind(&self) -> Option<ConditionKind> {
1284        self.postconditions.last_distinct_kind()
1285    }
1286
1287    /// Latest [`ConditionKind::ALL`] entry ABSENT from
1288    /// `preconditions ∪ postconditions`, or `None` when the union
1289    /// carries every variant — the union arm of the (precondition,
1290    /// postcondition, condition-union) last-missing-kind triad on
1291    /// [`Boundary`].
1292    ///
1293    /// # Composed body
1294    ///
1295    /// `ConditionKind::ALL.iter().rev().copied().find(|k|
1296    /// !self.has_condition_kind(*k))` — a REVERSED closed-set walk
1297    /// composed against the two-slice union primitive
1298    /// [`Self::has_condition_kind`] under a NEGATED predicate that
1299    /// SHORT-CIRCUITS at the latest empty slot. Byte-identical to the
1300    /// trait-level [`ConditionSliceExt::last_missing_kind`] but
1301    /// reaching through the boundary's two-slice union rather than a
1302    /// single slice. Equivalent to
1303    /// `self.missing_condition_kinds().last().copied()` without
1304    /// materializing the intermediate `Vec<ConditionKind>`.
1305    ///
1306    /// # Sibling to [`Self::first_missing_condition_kind`]
1307    ///
1308    /// Time-reversed peer of the earliest-element scalar projection
1309    /// under the SAME negated two-slice union predicate. Fourth
1310    /// scalar projection on the closed-set-complement axis on the
1311    /// boundary-union surface (first, count, missing_kinds already
1312    /// shipped; this method closes the endpoint pair on the
1313    /// complement side).
1314    ///
1315    /// # Compounding
1316    ///
1317    /// A future coherence check that surfaces "boundary is latest-
1318    /// missing PromQL" reads
1319    /// `spec.boundary.last_missing_condition_kind() ==
1320    /// Some(ConditionKind::PromQL)` at ONE call site rather than
1321    /// paying for `spec.boundary.missing_condition_kinds().last()`
1322    /// with its intermediate heap allocation. An operator-facing
1323    /// "last still-unfilled closed-loop kind" audit reaches this ONE
1324    /// substrate site rather than restating the negated reversed
1325    /// closed-set walk at every consumer.
1326    ///
1327    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1328    /// preserves proofs — the complement-latest-element projection
1329    /// composes the SAME reversed closed-set walk on both this
1330    /// boundary surface and the slice-level substrate primitive
1331    /// under short-circuit semantics with a negated predicate).
1332    /// THEORY.md §VI.1 (generation over composition — a new
1333    /// [`ConditionKind`] variant added to `ALL` reaches this
1334    /// primitive mechanically through the reversed closed-set walk).
1335    #[must_use]
1336    pub fn last_missing_condition_kind(&self) -> Option<ConditionKind> {
1337        ConditionKind::ALL
1338            .iter()
1339            .rev()
1340            .copied()
1341            .find(|k| !self.has_condition_kind(*k))
1342    }
1343
1344    /// Latest [`ConditionKind::ALL`] entry ABSENT from
1345    /// [`Self::preconditions`], or `None` when preconditions carry
1346    /// every variant — the precondition-side arm of the (precondition,
1347    /// postcondition, condition-union) last-missing-kind triad on
1348    /// [`Boundary`]. Thin typed delegate to
1349    /// [`ConditionSliceExt::last_missing_kind`] over
1350    /// [`Self::preconditions`].
1351    ///
1352    /// Peer of [`Self::last_missing_postcondition_kind`] on the
1353    /// (precondition, postcondition) partition of the boundary's two
1354    /// condition-vector slots; both peers compose against the SAME
1355    /// slice-level substrate primitive so a regression at the per-
1356    /// slice negated REVERSED short-circuit walk fails at that
1357    /// primitive's tests rather than as silent drift at either
1358    /// struct-level arm.
1359    #[must_use]
1360    pub fn last_missing_precondition_kind(&self) -> Option<ConditionKind> {
1361        self.preconditions.last_missing_kind()
1362    }
1363
1364    /// Latest [`ConditionKind::ALL`] entry ABSENT from
1365    /// [`Self::postconditions`], or `None` when postconditions carry
1366    /// every variant — the postcondition-side arm of the (precondition,
1367    /// postcondition, condition-union) last-missing-kind triad on
1368    /// [`Boundary`]. Thin typed delegate to
1369    /// [`ConditionSliceExt::last_missing_kind`] over
1370    /// [`Self::postconditions`].
1371    ///
1372    /// Peer of [`Self::last_missing_precondition_kind`]. See that
1373    /// method for the full rationale — the two methods share ONE lift
1374    /// motivation, ONE fail-before-pass-after composition-law pin, and
1375    /// ONE two-surface parity contract with the ephemeral sugar type
1376    /// via
1377    /// [`crate::ephemeral::EphemeralSpec::last_missing_postcondition_kind`].
1378    #[must_use]
1379    pub fn last_missing_postcondition_kind(&self) -> Option<ConditionKind> {
1380        self.postconditions.last_missing_kind()
1381    }
1382
1383    /// `true` iff `preconditions ∪ postconditions` carries every
1384    /// [`ConditionKind::ALL`] variant at least once — the union arm
1385    /// of the (precondition, postcondition, condition-union)
1386    /// saturation-predicate triad on [`Boundary`].
1387    ///
1388    /// # Composed body
1389    ///
1390    /// `ConditionKind::ALL.iter().all(|k| self.has_condition_kind(*k))`
1391    /// — a SHORT-CIRCUITING closed-set walk composed against the
1392    /// two-slice union primitive [`Self::has_condition_kind`], byte-
1393    /// identical to the trait-level [`ConditionSliceExt::is_kind_saturated`]
1394    /// but reaching through the boundary's two-slice union rather than
1395    /// a single slice. Equivalent to `self.missing_condition_kinds()
1396    /// .is_empty()` without materializing the `Vec<ConditionKind>`, and
1397    /// to `self.missing_condition_kind_count() == 0` without paying for
1398    /// the counter walk on every arm.
1399    ///
1400    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::is_condition_kind_saturated`]
1401    ///
1402    /// Byte-identical signature `(&Self) -> bool`, byte-identical
1403    /// closed-set-walk body, on the sugar-surface type whose pre/post
1404    /// condition vectors live directly on the struct. Both methods
1405    /// compose against the SAME slice-level substrate primitive
1406    /// [`ConditionSliceExt::is_kind_saturated`] via the two-slice
1407    /// union composed through [`Self::has_condition_kind`] — a
1408    /// regression at the per-slice `all` short-circuit fails at that
1409    /// primitive's tests rather than as silent drift at either
1410    /// struct-level saturation caller.
1411    ///
1412    /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
1413    /// preserves proofs (the saturation-endpoint projection composes
1414    /// the SAME closed-set walk on both this boundary surface and the
1415    /// slice-level substrate primitive under short-circuit semantics).
1416    /// THEORY.md §VI.1 — generation over composition (a new
1417    /// [`ConditionKind`] variant added to `ALL` reaches this primitive
1418    /// mechanically through the `all` short-circuit).
1419    #[must_use]
1420    pub fn is_condition_kind_saturated(&self) -> bool {
1421        ConditionKind::ALL
1422            .iter()
1423            .all(|k| self.has_condition_kind(*k))
1424    }
1425
1426    /// `true` iff [`Self::preconditions`] carries every
1427    /// [`ConditionKind::ALL`] variant at least once — the precondition-
1428    /// side arm of the (precondition, postcondition, condition-union)
1429    /// saturation-predicate triad on [`Boundary`]. Thin typed delegate
1430    /// to [`ConditionSliceExt::is_kind_saturated`] over
1431    /// [`Self::preconditions`].
1432    ///
1433    /// Peer of [`Self::is_postcondition_kind_saturated`] on the
1434    /// (precondition, postcondition) partition of the boundary's two
1435    /// condition-vector slots; both peers compose against the SAME
1436    /// slice-level substrate primitive so a regression at the per-
1437    /// slice `all` short-circuit fails at that primitive's tests
1438    /// rather than as silent drift at either struct-level arm.
1439    #[must_use]
1440    pub fn is_precondition_kind_saturated(&self) -> bool {
1441        self.preconditions.is_kind_saturated()
1442    }
1443
1444    /// `true` iff [`Self::postconditions`] carries every
1445    /// [`ConditionKind::ALL`] variant at least once — the postcondition-
1446    /// side arm of the (precondition, postcondition, condition-union)
1447    /// saturation-predicate triad on [`Boundary`]. Thin typed delegate
1448    /// to [`ConditionSliceExt::is_kind_saturated`] over
1449    /// [`Self::postconditions`].
1450    ///
1451    /// Peer of [`Self::is_precondition_kind_saturated`]. See that
1452    /// method for the full rationale — the two methods share ONE lift
1453    /// motivation, ONE fail-before-pass-after composition-law pin, and
1454    /// ONE two-surface parity contract with the ephemeral sugar type
1455    /// via
1456    /// [`crate::ephemeral::EphemeralSpec::is_postcondition_kind_saturated`].
1457    #[must_use]
1458    pub fn is_postcondition_kind_saturated(&self) -> bool {
1459        self.postconditions.is_kind_saturated()
1460    }
1461
1462    /// `true` iff `preconditions ∪ postconditions` is MISSING at least
1463    /// one [`ConditionKind::ALL`] variant — the union arm of the
1464    /// (precondition, postcondition, condition-union) at-least-one
1465    /// halfspace triad on [`Boundary`], byte-for-byte peer of the
1466    /// saturation-predicate triad
1467    /// [`Self::is_condition_kind_saturated`] under a definitional
1468    /// negation.
1469    ///
1470    /// # Composed body
1471    ///
1472    /// `!self.is_condition_kind_saturated()` — the definitional
1473    /// negation of the two-slice union saturation primitive. The
1474    /// underlying `ConditionKind::ALL.iter().all(has_condition_kind)`
1475    /// walk returns `false` at the FIRST missing kind (yielding `true`
1476    /// here) WITHOUT materializing
1477    /// [`Self::missing_condition_kinds`]'s `Vec` and WITHOUT walking
1478    /// every entry to build [`Self::missing_condition_kind_count`]'s
1479    /// scalar. Strictly cheaper than either widened primitive on every
1480    /// partially-populated arm.
1481    ///
1482    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_any_missing_condition_kind`]
1483    ///
1484    /// Byte-identical signature `(&Self) -> bool`, byte-identical
1485    /// `!self.is_condition_kind_saturated()` body, on the sugar-surface
1486    /// type whose pre/post condition vectors live directly on the
1487    /// struct. Both methods compose against the SAME slice-level
1488    /// substrate primitive [`ConditionSliceExt::has_any_missing_kind`]
1489    /// via the two-slice union composed through
1490    /// [`Self::is_condition_kind_saturated`] — a regression at the
1491    /// per-slice `all` short-circuit fails at that primitive's tests
1492    /// rather than as silent drift at either struct-level at-least-one
1493    /// halfspace caller.
1494    ///
1495    /// # Compounding
1496    ///
1497    /// A `has-any-missing-kind` require-tag classifier arm — byte-
1498    /// for-byte peer of the tagged-union `has-any-missing-kind`
1499    /// classifier one struct-layer up + the saturation-predicate
1500    /// triad's negated dual — reaches this primitive at ONE call
1501    /// site rather than negating `boundary.is_condition_kind_saturated()`
1502    /// at the callsite or restating
1503    /// `boundary.missing_condition_kind_count() > 0` (which walks
1504    /// every slot to count) or
1505    /// `!boundary.missing_condition_kinds().is_empty()` (which
1506    /// allocates the Vec before the negated emptiness check).
1507    ///
1508    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1509    /// preserves proofs — the at-least-one halfspace projection
1510    /// composes the SAME two-slice union negation on both this
1511    /// boundary surface and the slice-level substrate primitive under
1512    /// definitional negation). THEORY.md §VI.1 (generation over
1513    /// composition — a new [`ConditionKind`] variant reaches both
1514    /// surfaces' at-least-one halfspace triads mechanically through
1515    /// the delegated union primitive).
1516    #[must_use]
1517    pub fn has_any_missing_condition_kind(&self) -> bool {
1518        !self.is_condition_kind_saturated()
1519    }
1520
1521    /// `true` iff [`Self::preconditions`] is MISSING at least one
1522    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
1523    /// the (precondition, postcondition, condition-union) at-least-
1524    /// one halfspace triad on [`Boundary`]. Thin typed delegate to
1525    /// [`ConditionSliceExt::has_any_missing_kind`] over
1526    /// [`Self::preconditions`].
1527    ///
1528    /// Peer of [`Self::has_any_missing_postcondition_kind`] on the
1529    /// (precondition, postcondition) partition of the boundary's two
1530    /// condition-vector slots; both peers compose against the SAME
1531    /// slice-level substrate primitive so a regression at the per-
1532    /// slice `all` short-circuit under negation fails at that
1533    /// primitive's tests rather than as silent drift at either
1534    /// struct-level arm.
1535    #[must_use]
1536    pub fn has_any_missing_precondition_kind(&self) -> bool {
1537        self.preconditions.has_any_missing_kind()
1538    }
1539
1540    /// `true` iff [`Self::postconditions`] is MISSING at least one
1541    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
1542    /// the (precondition, postcondition, condition-union) at-least-
1543    /// one halfspace triad on [`Boundary`]. Thin typed delegate to
1544    /// [`ConditionSliceExt::has_any_missing_kind`] over
1545    /// [`Self::postconditions`].
1546    ///
1547    /// Peer of [`Self::has_any_missing_precondition_kind`]. See that
1548    /// method for the full rationale — the two methods share ONE lift
1549    /// motivation, ONE fail-before-pass-after composition-law pin, and
1550    /// ONE two-surface parity contract with the ephemeral sugar type
1551    /// via
1552    /// [`crate::ephemeral::EphemeralSpec::has_any_missing_postcondition_kind`].
1553    #[must_use]
1554    pub fn has_any_missing_postcondition_kind(&self) -> bool {
1555        self.postconditions.has_any_missing_kind()
1556    }
1557
1558    /// `true` iff `preconditions ∪ postconditions` carries at least one
1559    /// [`ConditionKind::ALL`] variant — the union arm of the
1560    /// (precondition, postcondition, condition-union) at-least-one
1561    /// halfspace triad on [`Boundary`] on the closed-set-inversion
1562    /// axis, byte-for-byte peer of the at-least-one halfspace triad
1563    /// [`Self::has_any_missing_condition_kind`] on the closed-set-
1564    /// complement axis.
1565    ///
1566    /// # Composed body
1567    ///
1568    /// `ConditionKind::ALL.iter().copied().any(|k|
1569    /// self.has_condition_kind(k))` — a SHORT-CIRCUITING closed-set
1570    /// walk under the two-slice union primitive
1571    /// [`Self::has_condition_kind`]. The walk returns `true` at the
1572    /// FIRST kind present in EITHER slice WITHOUT materializing
1573    /// [`Self::distinct_condition_kinds`]'s `Vec` and WITHOUT walking
1574    /// every kind to build [`Self::distinct_condition_kind_count`]'s
1575    /// scalar. Strictly cheaper than either widened primitive on every
1576    /// non-empty arm because the walk short-circuits at the first
1577    /// populated kind rather than paying for the Vec allocation or the
1578    /// full cardinality count.
1579    ///
1580    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_any_distinct_condition_kind`]
1581    ///
1582    /// Byte-identical signature `(&Self) -> bool`, byte-identical
1583    /// `ConditionKind::ALL.iter().copied().any(|k|
1584    /// self.has_condition_kind(k))` body, on the sugar-surface type
1585    /// whose pre/post condition vectors live directly on the struct.
1586    /// Both methods compose against the SAME slice-level substrate
1587    /// primitive [`ConditionSliceExt::has_any_distinct_kind`] via the
1588    /// two-slice union through [`Self::has_condition_kind`] — a
1589    /// regression at the per-slice `any` short-circuit fails at that
1590    /// primitive's tests rather than as silent drift at either struct-
1591    /// level at-least-one halfspace caller.
1592    ///
1593    /// # Compounding
1594    ///
1595    /// A `has-any-distinct-condition-kind` require-tag classifier arm
1596    /// — byte-for-byte peer of the tagged-union `has-any-populated-
1597    /// kind` classifier one struct-layer up + the at-least-one
1598    /// halfspace triad's closed-set-inversion peer — reaches this
1599    /// primitive at ONE call site rather than restating
1600    /// `boundary.distinct_condition_kind_count() > 0` (which walks
1601    /// every kind to count) or
1602    /// `!boundary.distinct_condition_kinds().is_empty()` (which
1603    /// allocates the Vec before the negated emptiness check).
1604    ///
1605    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1606    /// preserves proofs — the at-least-one halfspace projection
1607    /// composes the SAME closed-set walk on both this boundary surface
1608    /// and the slice-level substrate primitive under short-circuit
1609    /// semantics). THEORY.md §VI.1 (generation over composition — a
1610    /// new [`ConditionKind`] variant reaches both surfaces' at-least-
1611    /// one halfspace triads mechanically through the delegated union
1612    /// primitive).
1613    #[must_use]
1614    pub fn has_any_distinct_condition_kind(&self) -> bool {
1615        ConditionKind::ALL
1616            .iter()
1617            .copied()
1618            .any(|k| self.has_condition_kind(k))
1619    }
1620
1621    /// `true` iff [`Self::preconditions`] carries at least one
1622    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
1623    /// the (precondition, postcondition, condition-union) at-least-one
1624    /// halfspace triad on [`Boundary`] on the closed-set-inversion
1625    /// axis. Thin typed delegate to
1626    /// [`ConditionSliceExt::has_any_distinct_kind`] over
1627    /// [`Self::preconditions`].
1628    ///
1629    /// Peer of [`Self::has_any_distinct_postcondition_kind`] on the
1630    /// (precondition, postcondition) partition of the boundary's two
1631    /// condition-vector slots; both peers compose against the SAME
1632    /// slice-level substrate primitive so a regression at the per-
1633    /// slice `any` short-circuit fails at that primitive's tests
1634    /// rather than as silent drift at either struct-level arm.
1635    #[must_use]
1636    pub fn has_any_distinct_precondition_kind(&self) -> bool {
1637        self.preconditions.has_any_distinct_kind()
1638    }
1639
1640    /// `true` iff [`Self::postconditions`] carries at least one
1641    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
1642    /// the (precondition, postcondition, condition-union) at-least-one
1643    /// halfspace triad on [`Boundary`] on the closed-set-inversion
1644    /// axis. Thin typed delegate to
1645    /// [`ConditionSliceExt::has_any_distinct_kind`] over
1646    /// [`Self::postconditions`].
1647    ///
1648    /// Peer of [`Self::has_any_distinct_precondition_kind`]. See that
1649    /// method for the full rationale — the two methods share ONE lift
1650    /// motivation, ONE fail-before-pass-after composition-law pin, and
1651    /// ONE two-surface parity contract with the ephemeral sugar type
1652    /// via
1653    /// [`crate::ephemeral::EphemeralSpec::has_any_distinct_postcondition_kind`].
1654    #[must_use]
1655    pub fn has_any_distinct_postcondition_kind(&self) -> bool {
1656        self.postconditions.has_any_distinct_kind()
1657    }
1658
1659    /// `true` iff `preconditions ∪ postconditions` carries EXACTLY
1660    /// ONE [`ConditionKind::ALL`] variant — the union arm of the
1661    /// (precondition, postcondition, condition-union) cardinality-mid-
1662    /// endpoint triad on [`Boundary`] closing the singleton-coverage
1663    /// arm on the closed-set-inversion axis on the union of the two
1664    /// condition slots. The Boolean cardinality-mid-endpoint fast-
1665    /// path peer of [`Self::has_any_distinct_condition_kind`] (≥1
1666    /// halfspace) on the union axis: where the at-least-one halfspace
1667    /// predicate answers "is ANY kind covered by the union?",
1668    /// `has_unique_distinct_condition_kind` answers "is EXACTLY ONE
1669    /// kind covered by the union?".
1670    ///
1671    /// Composed body: constructs a two-step-short-circuit walk over
1672    /// [`ConditionKind::ALL`] under the [`Self::has_condition_kind`]
1673    /// union primitive — pulls up to two hits off the filtered
1674    /// iterator; the primitive returns `true` iff the first is
1675    /// [`Some`] and the second is [`None`]. Byte-for-byte peer of
1676    /// [`ConditionSliceExt::has_unique_distinct_kind`] one slice-
1677    /// layer down, lifted to compose against
1678    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1679    /// against a single slice's `has_kind`. A regression at the union
1680    /// primitive fails at the slice-level substrate tests + the union
1681    /// composition-law tests rather than as silent drift here.
1682    ///
1683    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_unique_distinct_condition_kind`]
1684    ///
1685    /// Byte-identical signature `(&Self) -> bool`, byte-identical
1686    /// two-step short-circuit body composed against the ephemeral
1687    /// surface's own union primitive. Both methods compose against
1688    /// the SAME slice-level substrate primitive
1689    /// [`ConditionSliceExt::has_unique_distinct_kind`] via the
1690    /// two-slice union — a regression at the per-slice singleton-
1691    /// coverage walk fails at that primitive's tests rather than as
1692    /// silent drift at either struct-level singleton-coverage caller.
1693    ///
1694    /// # Sibling to [`Self::has_unique_missing_condition_kind`]
1695    ///
1696    /// Closed-set-inversion peer of the cardinality-mid-endpoint on
1697    /// the closed-set-complement axis at the boundary union struct
1698    /// layer — where `has_unique_missing_condition_kind` returns
1699    /// `true` iff the union is one kind AWAY from covered (missing
1700    /// EXACTLY one), `has_unique_distinct_condition_kind` returns
1701    /// `true` iff the union covers EXACTLY one kind (the singleton-
1702    /// coverage arm). Both compose against a two-step-short-circuit
1703    /// walk over [`ConditionKind::ALL`] under
1704    /// [`Self::has_condition_kind`] (this primitive) vs
1705    /// `!has_condition_kind` (the missing peer).
1706    ///
1707    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1708    /// preserves proofs — the cardinality-mid-endpoint projection on
1709    /// the closed-set-inversion axis composes the SAME two-step
1710    /// short-circuit walk under a two-slice union on both this
1711    /// boundary surface and the ephemeral surface). THEORY.md §VI.1
1712    /// (generation over composition — a new [`ConditionKind`]
1713    /// variant reaches both surfaces' cardinality-mid-endpoint triads
1714    /// mechanically through the delegated union primitive).
1715    #[must_use]
1716    pub fn has_unique_distinct_condition_kind(&self) -> bool {
1717        let mut it = ConditionKind::ALL
1718            .iter()
1719            .copied()
1720            .filter(|k| self.has_condition_kind(*k));
1721        it.next().is_some() && it.next().is_none()
1722    }
1723
1724    /// `true` iff [`Self::preconditions`] carries EXACTLY ONE
1725    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
1726    /// the (precondition, postcondition, condition-union)
1727    /// cardinality-mid-endpoint triad on [`Boundary`] on the closed-
1728    /// set-inversion axis. Thin typed delegate to
1729    /// [`ConditionSliceExt::has_unique_distinct_kind`] over
1730    /// [`Self::preconditions`].
1731    ///
1732    /// Peer of [`Self::has_unique_distinct_postcondition_kind`] on the
1733    /// (precondition, postcondition) partition of the boundary's two
1734    /// condition-vector slots; both peers compose against the SAME
1735    /// slice-level substrate primitive so a regression at the per-
1736    /// slice two-step short-circuit walk fails at that primitive's
1737    /// tests rather than as silent drift at either struct-level arm.
1738    #[must_use]
1739    pub fn has_unique_distinct_precondition_kind(&self) -> bool {
1740        self.preconditions.has_unique_distinct_kind()
1741    }
1742
1743    /// `true` iff [`Self::postconditions`] carries EXACTLY ONE
1744    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
1745    /// the (precondition, postcondition, condition-union)
1746    /// cardinality-mid-endpoint triad on [`Boundary`] on the closed-
1747    /// set-inversion axis. Thin typed delegate to
1748    /// [`ConditionSliceExt::has_unique_distinct_kind`] over
1749    /// [`Self::postconditions`].
1750    ///
1751    /// Peer of [`Self::has_unique_distinct_precondition_kind`]. See
1752    /// that method for the full rationale — the two methods share ONE
1753    /// lift motivation, ONE fail-before-pass-after composition-law
1754    /// pin, and ONE two-surface parity contract with the ephemeral
1755    /// sugar type via
1756    /// [`crate::ephemeral::EphemeralSpec::has_unique_distinct_postcondition_kind`].
1757    #[must_use]
1758    pub fn has_unique_distinct_postcondition_kind(&self) -> bool {
1759        self.postconditions.has_unique_distinct_kind()
1760    }
1761
1762    /// The SOLE [`ConditionKind::ALL`] variant covered by
1763    /// `preconditions ∪ postconditions`, or `None` when the union
1764    /// covers 0 or ≥ 2 kinds — the union arm of the (precondition,
1765    /// postcondition, condition-union) exactly-one-hit witnessing
1766    /// triad on [`Boundary`] closing the singleton-coverage witness on
1767    /// the closed-set-inversion axis on the union of the two condition
1768    /// slots. Witnessing scalar peer of
1769    /// [`Self::has_unique_distinct_condition_kind`] (=1 predicate) on
1770    /// the union axis: where the Boolean predicate answers "does the
1771    /// union cover EXACTLY one kind?", `unique_distinct_condition_kind`
1772    /// returns `Some(k)` naming that SOLE kind (or `None` on the 0 or
1773    /// ≥ 2 arms).
1774    ///
1775    /// # Composed body
1776    ///
1777    /// A two-step-short-circuit walk over [`ConditionKind::ALL`] under
1778    /// the [`Self::has_condition_kind`] union primitive — pull the
1779    /// first hit; return `Some(first)` iff the second hit is [`None`],
1780    /// else `None`. Byte-for-byte peer of
1781    /// [`ConditionSliceExt::unique_distinct_kind`] one slice-layer
1782    /// down, lifted to compose against
1783    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1784    /// against a single slice's `has_kind`. A regression at the union
1785    /// primitive fails at the slice-level substrate tests + the union
1786    /// composition-law tests rather than as silent drift here.
1787    ///
1788    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::unique_distinct_condition_kind`]
1789    ///
1790    /// Byte-identical signature `(&Self) -> Option<ConditionKind>`,
1791    /// byte-identical two-step short-circuit body composed against the
1792    /// ephemeral surface's own union primitive. Both methods compose
1793    /// against the SAME slice-level substrate primitive
1794    /// [`ConditionSliceExt::unique_distinct_kind`] via the two-slice
1795    /// union — a regression at the per-slice singleton-coverage
1796    /// witnessing walk fails at that primitive's tests rather than as
1797    /// silent drift at either struct-level singleton-coverage caller.
1798    ///
1799    /// # Sibling to [`Self::unique_missing_condition_kind`]
1800    ///
1801    /// Closed-set-inversion peer of the exactly-one-hit witness on the
1802    /// closed-set-complement axis at the boundary union struct layer —
1803    /// where `unique_missing_condition_kind` names the SOLE kind AWAY
1804    /// from covered, `unique_distinct_condition_kind` names the SOLE
1805    /// kind covered. Both compose against a two-step-short-circuit walk
1806    /// over [`ConditionKind::ALL`] under [`Self::has_condition_kind`]
1807    /// (this primitive) vs `!has_condition_kind` (the missing peer).
1808    ///
1809    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1810    /// preserves proofs — the exactly-one-hit witnessing projection on
1811    /// the closed-set-inversion axis composes the SAME two-step short-
1812    /// circuit walk under a two-slice union on both this boundary
1813    /// surface and the ephemeral surface). THEORY.md §VI.1 (generation
1814    /// over composition — a new [`ConditionKind`] variant reaches both
1815    /// surfaces' unique-distinct-kind triads mechanically through the
1816    /// delegated union primitive).
1817    #[must_use]
1818    pub fn unique_distinct_condition_kind(&self) -> Option<ConditionKind> {
1819        let mut it = ConditionKind::ALL
1820            .iter()
1821            .copied()
1822            .filter(|k| self.has_condition_kind(*k));
1823        let first = it.next()?;
1824        match it.next() {
1825            None => Some(first),
1826            Some(_) => None,
1827        }
1828    }
1829
1830    /// The SOLE [`ConditionKind::ALL`] variant covered by
1831    /// [`Self::preconditions`], or `None` when preconditions cover 0
1832    /// or ≥ 2 kinds — the precondition-side arm of the (precondition,
1833    /// postcondition, condition-union) exactly-one-hit witnessing
1834    /// triad on [`Boundary`] on the closed-set-inversion axis. Thin
1835    /// typed delegate to [`ConditionSliceExt::unique_distinct_kind`]
1836    /// over [`Self::preconditions`].
1837    ///
1838    /// Peer of [`Self::unique_distinct_postcondition_kind`] on the
1839    /// (precondition, postcondition) partition of the boundary's two
1840    /// condition-vector slots; both peers compose against the SAME
1841    /// slice-level substrate primitive so a regression at the per-
1842    /// slice two-step short-circuit witnessing walk fails at that
1843    /// primitive's tests rather than as silent drift at either
1844    /// struct-level arm.
1845    #[must_use]
1846    pub fn unique_distinct_precondition_kind(&self) -> Option<ConditionKind> {
1847        self.preconditions.unique_distinct_kind()
1848    }
1849
1850    /// The SOLE [`ConditionKind::ALL`] variant covered by
1851    /// [`Self::postconditions`], or `None` when postconditions cover 0
1852    /// or ≥ 2 kinds — the postcondition-side arm of the (precondition,
1853    /// postcondition, condition-union) exactly-one-hit witnessing
1854    /// triad on [`Boundary`] on the closed-set-inversion axis. Thin
1855    /// typed delegate to [`ConditionSliceExt::unique_distinct_kind`]
1856    /// over [`Self::postconditions`].
1857    ///
1858    /// Peer of [`Self::unique_distinct_precondition_kind`]. See that
1859    /// method for the full rationale — the two methods share ONE lift
1860    /// motivation, ONE fail-before-pass-after composition-law pin, and
1861    /// ONE two-surface parity contract with the ephemeral sugar type
1862    /// via
1863    /// [`crate::ephemeral::EphemeralSpec::unique_distinct_postcondition_kind`].
1864    #[must_use]
1865    pub fn unique_distinct_postcondition_kind(&self) -> Option<ConditionKind> {
1866        self.postconditions.unique_distinct_kind()
1867    }
1868
1869    /// `true` iff `preconditions ∪ postconditions` COVERS AT LEAST
1870    /// TWO [`ConditionKind::ALL`] variants — the union arm of the
1871    /// (precondition, postcondition, condition-union) cardinality-
1872    /// many-arm triad on [`Boundary`] closing the "≥ 2 kinds covered"
1873    /// arm on the union of the two condition slots. The many-arm
1874    /// Boolean fast-path peer of
1875    /// [`Self::has_unique_distinct_condition_kind`] (=1 arm) and
1876    /// [`Self::has_any_distinct_condition_kind`] (≥1 halfspace) on the
1877    /// union axis, closing the {0, 1, ≥2} trichotomy on the distinct
1878    /// axis at the union struct layer.
1879    ///
1880    /// Composed body: constructs a two-step-short-circuit walk over
1881    /// [`ConditionKind::ALL`] under the [`Self::has_condition_kind`]
1882    /// union primitive — pulls up to two hits off the filtered
1883    /// iterator; the primitive returns `true` iff BOTH the first and
1884    /// the second are [`Some`]. Byte-for-byte peer of
1885    /// [`ConditionSliceExt::has_multiple_distinct_kinds`] one slice-
1886    /// layer down, lifted to compose against
1887    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1888    /// against a single slice's `has_kind`. A regression at the union
1889    /// primitive fails at the slice-level substrate tests + the union
1890    /// composition-law tests rather than as silent drift here.
1891    ///
1892    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_multiple_distinct_condition_kind`]
1893    ///
1894    /// Byte-identical signature `(&Self) -> bool`, byte-identical
1895    /// two-step short-circuit body composed against the ephemeral
1896    /// surface's own union primitive. Both methods compose against
1897    /// the SAME slice-level substrate primitive
1898    /// [`ConditionSliceExt::has_multiple_distinct_kinds`] via the
1899    /// two-slice union — a regression at the per-slice many-arm walk
1900    /// fails at that primitive's tests rather than as silent drift at
1901    /// either struct-level many-distinct caller.
1902    ///
1903    /// # Sibling to [`Self::has_multiple_missing_condition_kind`]
1904    ///
1905    /// Closed-set-inversion peer of the cardinality-many-arm on the
1906    /// closed-set-complement axis at the boundary union struct layer
1907    /// — where `has_multiple_missing_condition_kind` returns `true`
1908    /// iff the union has ≥ 2 kinds ABSENT, `has_multiple_distinct_condition_kind`
1909    /// returns `true` iff the union covers ≥ 2 kinds. Both compose
1910    /// against a two-step-short-circuit walk over [`ConditionKind::ALL`]
1911    /// under [`Self::has_condition_kind`] (this primitive) vs
1912    /// `!has_condition_kind` (the missing peer).
1913    ///
1914    /// # Compounding
1915    ///
1916    /// A future operator-facing "≥ 2 dependencies covered" fast-path
1917    /// diagnostic reads `boundary.has_multiple_distinct_condition_kind()`
1918    /// at ONE call site rather than restating
1919    /// `boundary.distinct_condition_kind_count() >= 2` (which walks
1920    /// every slot to count) or
1921    /// `boundary.distinct_condition_kinds().len() >= 2` (which
1922    /// allocates the Vec). A `has-multiple-distinct-condition-kind`
1923    /// require-tag classifier arm reaches this primitive at ONE
1924    /// substrate call — byte-for-byte peer of the tagged-union
1925    /// `has-multiple-populated-kinds` classifier one struct-layer up.
1926    ///
1927    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1928    /// preserves proofs — the cardinality-many-arm projection on the
1929    /// closed-set-inversion axis composes the SAME two-step short-
1930    /// circuit walk under a two-slice union on both this boundary
1931    /// surface and the ephemeral surface). THEORY.md §VI.1
1932    /// (generation over composition — a new [`ConditionKind`]
1933    /// variant reaches both surfaces' cardinality-many-arm triads
1934    /// mechanically through the delegated union primitive).
1935    #[must_use]
1936    pub fn has_multiple_distinct_condition_kind(&self) -> bool {
1937        let mut it = ConditionKind::ALL
1938            .iter()
1939            .copied()
1940            .filter(|k| self.has_condition_kind(*k));
1941        it.next().is_some() && it.next().is_some()
1942    }
1943
1944    /// `true` iff [`Self::preconditions`] carries AT LEAST TWO
1945    /// [`ConditionKind::ALL`] variants — the precondition-side arm of
1946    /// the (precondition, postcondition, condition-union) cardinality-
1947    /// many-arm triad on [`Boundary`] on the closed-set-inversion axis.
1948    /// Thin typed delegate to
1949    /// [`ConditionSliceExt::has_multiple_distinct_kinds`] over
1950    /// [`Self::preconditions`].
1951    ///
1952    /// Peer of [`Self::has_multiple_distinct_postcondition_kind`] on
1953    /// the (precondition, postcondition) partition of the boundary's
1954    /// two condition-vector slots; both peers compose against the
1955    /// SAME slice-level substrate primitive so a regression at the
1956    /// per-slice two-step short-circuit walk fails at that primitive's
1957    /// tests rather than as silent drift at either struct-level arm.
1958    #[must_use]
1959    pub fn has_multiple_distinct_precondition_kind(&self) -> bool {
1960        self.preconditions.has_multiple_distinct_kinds()
1961    }
1962
1963    /// `true` iff [`Self::postconditions`] carries AT LEAST TWO
1964    /// [`ConditionKind::ALL`] variants — the postcondition-side arm of
1965    /// the (precondition, postcondition, condition-union) cardinality-
1966    /// many-arm triad on [`Boundary`] on the closed-set-inversion axis.
1967    /// Thin typed delegate to
1968    /// [`ConditionSliceExt::has_multiple_distinct_kinds`] over
1969    /// [`Self::postconditions`].
1970    ///
1971    /// Peer of [`Self::has_multiple_distinct_precondition_kind`]. See
1972    /// that method for the full rationale — the two methods share ONE
1973    /// lift motivation, ONE fail-before-pass-after composition-law
1974    /// pin, and ONE two-surface parity contract with the ephemeral
1975    /// sugar type via
1976    /// [`crate::ephemeral::EphemeralSpec::has_multiple_distinct_postcondition_kind`].
1977    #[must_use]
1978    pub fn has_multiple_distinct_postcondition_kind(&self) -> bool {
1979        self.postconditions.has_multiple_distinct_kinds()
1980    }
1981
1982    /// `true` iff `preconditions ∪ postconditions` carries AT MOST ONE
1983    /// [`ConditionKind::ALL`] variant — the union arm of the
1984    /// (precondition, postcondition, condition-union) cardinality
1985    /// "≤ 1" triad on [`Boundary`] closing the "at most one kind
1986    /// covered" arm on the union of the two condition slots on the
1987    /// closed-set-inversion axis. The Boolean cardinality "≤ 1"
1988    /// negation peer of [`Self::has_multiple_distinct_condition_kind`]
1989    /// (≥ 2 many-arm) under the definitional negation
1990    /// `!has_multiple_distinct_condition_kind`, and the trichotomy-
1991    /// union peer of `!has_any_distinct_condition_kind` (=0 empty-
1992    /// endpoint) OR [`Self::has_unique_distinct_condition_kind`] (=1
1993    /// mid-endpoint) — the arrangement space where the boundary is
1994    /// EMPTY-OR-SINGLETON on the union (zero or exactly one kind
1995    /// present across the union of the two slices).
1996    ///
1997    /// Composed body: `!self.has_multiple_distinct_condition_kind()` —
1998    /// a definitional negation of the many-arm union primitive. Short-
1999    /// circuits transitively through
2000    /// [`Self::has_multiple_distinct_condition_kind`]'s two-step
2001    /// short-circuit walk over [`ConditionKind::ALL`] under
2002    /// [`Self::has_condition_kind`] — returns `true` as soon as the
2003    /// many-arm walk stops with fewer than two distinct hits, WITHOUT
2004    /// materializing [`Self::distinct_condition_kinds`]'s `Vec` and
2005    /// WITHOUT walking every slot to build
2006    /// [`Self::distinct_condition_kind_count`]'s scalar. Byte-for-byte
2007    /// peer of [`ConditionSliceExt::has_at_most_one_distinct_kind`]
2008    /// one slice-layer down, lifted to compose against
2009    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
2010    /// against a single slice's `has_kind`. A regression at the union
2011    /// primitive fails at the slice-level substrate tests + the union
2012    /// composition-law tests rather than as silent drift here.
2013    ///
2014    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_at_most_one_distinct_condition_kind`]
2015    ///
2016    /// Byte-identical signature `(&Self) -> bool`, byte-identical
2017    /// definitional-negation body composed against the ephemeral
2018    /// surface's own many-arm union primitive. Both methods compose
2019    /// against the SAME slice-level substrate primitive
2020    /// [`ConditionSliceExt::has_at_most_one_distinct_kind`] via the
2021    /// two-slice union — a regression at the per-slice "≤ 1" negation
2022    /// fails at that primitive's tests rather than as silent drift at
2023    /// either struct-level empty-or-singleton caller.
2024    ///
2025    /// # Peer to [`Self::has_at_most_one_missing_condition_kind`]
2026    ///
2027    /// Axis-parity mirror of the closed-set-complement "≤ 1" negation
2028    /// peer on the union struct layer — where
2029    /// `has_at_most_one_missing_condition_kind` tests "at most one
2030    /// kind MISSING across the union" (near-saturation-or-saturated),
2031    /// this primitive tests "at most one kind PRESENT across the
2032    /// union" (empty-or-singleton). Both compose the same
2033    /// definitional negation shape (`!has_multiple_*_condition_kind()`)
2034    /// at the union struct layer — the two primitives close the "≤ 1"
2035    /// arm on both the closed-set-complement and closed-set-inversion
2036    /// axes at the union struct layer under the SAME shape.
2037    ///
2038    /// # Compounding
2039    ///
2040    /// A future operator-facing "at most one dependency currently
2041    /// covered" coverage-analysis diagnostic reads
2042    /// `boundary.has_at_most_one_distinct_condition_kind()` at ONE
2043    /// call site rather than restating
2044    /// `boundary.distinct_condition_kind_count() <= 1` (which walks
2045    /// every slot to count) or
2046    /// `boundary.distinct_condition_kinds().len() <= 1` (which
2047    /// allocates the Vec). A `has-at-most-one-distinct-condition-kind`
2048    /// require-tag classifier arm reaches this primitive at ONE
2049    /// substrate call — byte-for-byte peer of the tagged-union
2050    /// `has-at-most-one-populated-kind` classifier one struct-layer
2051    /// up, closing the {0, 1, ≥ 2, ≤ 1} cardinality-Boolean grid on
2052    /// the distinct axis at the Boundary struct layer alongside its
2053    /// sibling `has-multiple-distinct-condition-kind` under the
2054    /// Boolean negation axis.
2055    ///
2056    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2057    /// preserves proofs — the cardinality "≤ 1" projection on the
2058    /// distinct axis composes the SAME definitional negation of the
2059    /// many-arm two-step short-circuit walk on both this boundary
2060    /// surface and the ephemeral surface). THEORY.md §VI.1 (generation
2061    /// over composition — a new [`ConditionKind`] variant reaches both
2062    /// surfaces' cardinality "≤ 1" triads mechanically through the
2063    /// delegated union primitive).
2064    #[must_use]
2065    pub fn has_at_most_one_distinct_condition_kind(&self) -> bool {
2066        !self.has_multiple_distinct_condition_kind()
2067    }
2068
2069    /// `true` iff [`Self::preconditions`] carries AT MOST ONE
2070    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
2071    /// the (precondition, postcondition, condition-union) cardinality
2072    /// "≤ 1" triad on [`Boundary`] on the closed-set-inversion axis.
2073    /// Thin typed delegate to
2074    /// [`ConditionSliceExt::has_at_most_one_distinct_kind`] over
2075    /// [`Self::preconditions`].
2076    ///
2077    /// Peer of [`Self::has_at_most_one_distinct_postcondition_kind`]
2078    /// on the (precondition, postcondition) partition of the boundary's
2079    /// two condition-vector slots; both peers compose against the SAME
2080    /// slice-level substrate primitive so a regression at the per-
2081    /// slice "≤ 1" negation of the many-arm walk fails at that
2082    /// primitive's tests rather than as silent drift at either
2083    /// struct-level arm.
2084    #[must_use]
2085    pub fn has_at_most_one_distinct_precondition_kind(&self) -> bool {
2086        self.preconditions.has_at_most_one_distinct_kind()
2087    }
2088
2089    /// `true` iff [`Self::postconditions`] carries AT MOST ONE
2090    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
2091    /// the (precondition, postcondition, condition-union) cardinality
2092    /// "≤ 1" triad on [`Boundary`] on the closed-set-inversion axis.
2093    /// Thin typed delegate to
2094    /// [`ConditionSliceExt::has_at_most_one_distinct_kind`] over
2095    /// [`Self::postconditions`].
2096    ///
2097    /// Peer of [`Self::has_at_most_one_distinct_precondition_kind`].
2098    /// See that method for the full rationale — the two methods share
2099    /// ONE lift motivation, ONE fail-before-pass-after composition-
2100    /// law pin, and ONE two-surface parity contract with the
2101    /// ephemeral sugar type via
2102    /// [`crate::ephemeral::EphemeralSpec::has_at_most_one_distinct_postcondition_kind`].
2103    #[must_use]
2104    pub fn has_at_most_one_distinct_postcondition_kind(&self) -> bool {
2105        self.postconditions.has_at_most_one_distinct_kind()
2106    }
2107
2108    /// `true` iff `preconditions ∪ postconditions` carries NO
2109    /// [`ConditionKind::ALL`] variant — the union arm of the
2110    /// (precondition, postcondition, condition-union) cardinality zero-
2111    /// endpoint triad on [`Boundary`] closing the "no kind covered"
2112    /// endpoint on the union of the two condition slots on the closed-
2113    /// set-inversion axis. The zero-endpoint Boolean fast-path peer of
2114    /// [`Self::has_any_distinct_condition_kind`] under a definitional
2115    /// negation, and the axis-parity mirror of
2116    /// [`Self::is_condition_kind_saturated`] on the closed-set-inversion
2117    /// axis at the union struct layer — where the saturation-endpoint
2118    /// predicate answers "does the union carry EVERY ALL variant?", this
2119    /// primitive answers "does the union carry NO ALL variant?".
2120    ///
2121    /// Composed body: `!self.has_any_distinct_condition_kind()` — a
2122    /// definitional negation of the at-least-one halfspace union
2123    /// primitive. Short-circuits transitively through
2124    /// [`Self::has_any_distinct_condition_kind`]'s short-circuiting
2125    /// closed-set walk over [`ConditionKind::ALL`] under
2126    /// [`Self::has_condition_kind`] — returns `false` at the FIRST
2127    /// present kind on either slice (yielding `false` here) WITHOUT
2128    /// materializing [`Self::distinct_condition_kinds`]'s `Vec` and
2129    /// WITHOUT walking every slot to build
2130    /// [`Self::distinct_condition_kind_count`]'s scalar. Byte-for-byte
2131    /// peer of [`ConditionSliceExt::is_kind_empty`] one slice-layer
2132    /// down, lifted to compose against [`Self::has_condition_kind`]'s
2133    /// pre-OR-post union rather than against a single slice's
2134    /// `has_kind`. A regression at the union primitive fails at the
2135    /// slice-level substrate tests + the union composition-law tests
2136    /// rather than as silent drift here.
2137    ///
2138    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::is_condition_kind_empty`]
2139    ///
2140    /// Byte-identical signature `(&Self) -> bool`, byte-identical
2141    /// definitional-negation body composed against the ephemeral
2142    /// surface's own at-least-one halfspace union primitive. Both
2143    /// methods compose against the SAME slice-level substrate primitive
2144    /// [`ConditionSliceExt::is_kind_empty`] via the two-slice union — a
2145    /// regression at the per-slice zero-endpoint fails at that
2146    /// primitive's tests rather than as silent drift at either
2147    /// struct-level empty caller.
2148    ///
2149    /// # Peer to [`Self::is_condition_kind_saturated`]
2150    ///
2151    /// Axis-parity mirror of the closed-set-complement saturation-
2152    /// endpoint peer on the union struct layer — where
2153    /// `is_condition_kind_saturated` tests "every kind PRESENT across
2154    /// the union" (missing_kind_count == 0), this primitive tests "no
2155    /// kind PRESENT across the union" (distinct_kind_count == 0). Both
2156    /// name a cardinality-endpoint on their respective axis under the
2157    /// same union struct layer — the two primitives close the zero-arm
2158    /// on both the closed-set-complement and closed-set-inversion axes
2159    /// at the union struct layer under symmetric shapes. Together with
2160    /// the intermediate arms `has_unique_distinct_condition_kind` (=1)
2161    /// and `has_multiple_distinct_condition_kind` (≥ 2), the four
2162    /// Booleans partition the distinct-cardinality closed set on the
2163    /// union at 0, 1, and ≥ 2 respectively.
2164    ///
2165    /// # Compounding
2166    ///
2167    /// A future operator-facing "no dependency currently covered"
2168    /// coverage-gap diagnostic reads
2169    /// `boundary.is_condition_kind_empty()` at ONE call site rather
2170    /// than restating `boundary.distinct_condition_kind_count() == 0`
2171    /// (which walks every slot to count),
2172    /// `boundary.distinct_condition_kinds().is_empty()` (which
2173    /// allocates the Vec), or negating
2174    /// `boundary.has_any_distinct_condition_kind()` at the callsite. An
2175    /// `is-condition-kind-empty` require-tag classifier arm reaches
2176    /// this primitive at ONE substrate call — byte-for-byte peer of
2177    /// the tagged-union `is-empty` classifier one struct-layer up,
2178    /// closing the {0, 1, ≥ 2, ≤ 1} cardinality-Boolean grid on the
2179    /// distinct axis at the Boundary struct layer alongside its sibling
2180    /// `has-any-distinct-condition-kind` under the Boolean negation
2181    /// axis.
2182    ///
2183    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2184    /// preserves proofs — the cardinality zero-endpoint projection on
2185    /// the distinct axis composes the SAME definitional negation of
2186    /// the at-least-one halfspace short-circuit walk on both this
2187    /// boundary surface and the ephemeral surface). THEORY.md §VI.1
2188    /// (generation over composition — a new [`ConditionKind`] variant
2189    /// reaches both surfaces' cardinality zero-endpoint triads
2190    /// mechanically through the delegated union primitive).
2191    #[must_use]
2192    pub fn is_condition_kind_empty(&self) -> bool {
2193        !self.has_any_distinct_condition_kind()
2194    }
2195
2196    /// `true` iff [`Self::preconditions`] carries NO
2197    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
2198    /// the (precondition, postcondition, condition-union) cardinality
2199    /// zero-endpoint triad on [`Boundary`] on the closed-set-inversion
2200    /// axis. Thin typed delegate to [`ConditionSliceExt::is_kind_empty`]
2201    /// over [`Self::preconditions`].
2202    ///
2203    /// Peer of [`Self::is_postcondition_kind_empty`] on the
2204    /// (precondition, postcondition) partition of the boundary's two
2205    /// condition-vector slots; both peers compose against the SAME
2206    /// slice-level substrate primitive so a regression at the per-slice
2207    /// zero-endpoint short-circuit fails at that primitive's tests
2208    /// rather than as silent drift at either struct-level arm.
2209    #[must_use]
2210    pub fn is_precondition_kind_empty(&self) -> bool {
2211        self.preconditions.is_kind_empty()
2212    }
2213
2214    /// `true` iff [`Self::postconditions`] carries NO
2215    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
2216    /// the (precondition, postcondition, condition-union) cardinality
2217    /// zero-endpoint triad on [`Boundary`] on the closed-set-inversion
2218    /// axis. Thin typed delegate to [`ConditionSliceExt::is_kind_empty`]
2219    /// over [`Self::postconditions`].
2220    ///
2221    /// Peer of [`Self::is_precondition_kind_empty`]. See that method
2222    /// for the full rationale — the two methods share ONE lift
2223    /// motivation, ONE fail-before-pass-after composition-law pin, and
2224    /// ONE two-surface parity contract with the ephemeral sugar type
2225    /// via
2226    /// [`crate::ephemeral::EphemeralSpec::is_postcondition_kind_empty`].
2227    #[must_use]
2228    pub fn is_postcondition_kind_empty(&self) -> bool {
2229        self.postconditions.is_kind_empty()
2230    }
2231
2232    /// `true` iff `preconditions ∪ postconditions` carries AT LEAST ONE
2233    /// [`ConditionKind::ALL`] variant AND is MISSING AT LEAST ONE
2234    /// [`ConditionKind::ALL`] variant — the union arm of the
2235    /// (precondition, postcondition, condition-union) parent-state
2236    /// middle-arm triad on [`Boundary`] closing the trichotomy
2237    /// (empty, partially covered, saturated) on the union axis
2238    /// alongside [`Self::is_condition_kind_empty`] (=0 zero-endpoint on
2239    /// the distinct axis) and [`Self::is_condition_kind_saturated`]
2240    /// (=0 zero-endpoint on the missing axis).
2241    ///
2242    /// # Composed body
2243    ///
2244    /// `self.has_any_distinct_condition_kind() && self.has_any_missing_condition_kind()`
2245    /// — the paired at-least-one-halfspace composition. Short-circuits
2246    /// transitively through the two at-least-one halfspace union
2247    /// primitives, each of which walks
2248    /// `ConditionKind::ALL.iter().any(has_condition_kind)` under a
2249    /// polarity — WITHOUT materializing
2250    /// [`Self::distinct_condition_kinds`] or
2251    /// [`Self::missing_condition_kinds`]'s `Vec`s and WITHOUT walking
2252    /// every slot to build the paired scalar counters. Byte-for-byte
2253    /// cheaper than the widened negation-of-both-endpoints composition
2254    /// `!self.is_condition_kind_empty() && !self.is_condition_kind_saturated()`
2255    /// on every partially-covered arm because each halfspace short-
2256    /// circuits at the first present / missing hit rather than paying
2257    /// two separate `ALL`-length walks.
2258    ///
2259    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::is_condition_kind_partially_covered`]
2260    ///
2261    /// Byte-identical signature `(&Self) -> bool`, byte-identical
2262    /// paired-halfspace body, on the sugar-surface type whose pre/post
2263    /// condition vectors live directly on the struct. Both methods
2264    /// compose against the SAME slice-level substrate primitive
2265    /// [`ConditionSliceExt::is_kind_partially_covered`] via the
2266    /// two-slice union composed through
2267    /// [`Self::has_condition_kind`] — a regression at the per-slice
2268    /// fused short-circuit walk fails at that primitive's tests rather
2269    /// than as silent drift at either struct-level middle-arm caller.
2270    ///
2271    /// # Compounding
2272    ///
2273    /// A boundary-progress "some kinds covered, some pending"
2274    /// diagnostic on a Boundary reads
2275    /// `boundary.is_condition_kind_partially_covered()` at ONE call
2276    /// site rather than composing
2277    /// `!boundary.is_condition_kind_empty() && !boundary.is_condition_kind_saturated()`
2278    /// (two closed-set walks) or
2279    /// `boundary.distinct_condition_kind_count() > 0 && boundary.missing_condition_kind_count() > 0`
2280    /// (two counter walks with no short-circuit). An `is-condition-
2281    /// kind-partially-covered` require-tag classifier arm reaches this
2282    /// primitive at ONE substrate call — byte-for-byte peer of the
2283    /// tagged-union `is-partially-populated` classifier one struct-
2284    /// layer up under the SAME parent-state middle-arm shape.
2285    ///
2286    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2287    /// preserves proofs — the parent-state middle-arm projection
2288    /// composes the SAME paired-halfspace body on both this boundary
2289    /// surface and the ephemeral surface). THEORY.md §VI.1 (generation
2290    /// over composition — a new [`ConditionKind`] variant reaches both
2291    /// surfaces' parent-state middle-arm triads mechanically through
2292    /// the delegated union primitive).
2293    #[must_use]
2294    pub fn is_condition_kind_partially_covered(&self) -> bool {
2295        self.has_any_distinct_condition_kind() && self.has_any_missing_condition_kind()
2296    }
2297
2298    /// `true` iff [`Self::preconditions`] carries AT LEAST ONE
2299    /// [`ConditionKind::ALL`] variant AND is MISSING AT LEAST ONE
2300    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
2301    /// the (precondition, postcondition, condition-union) parent-state
2302    /// middle-arm triad on [`Boundary`]. Thin typed delegate to
2303    /// [`ConditionSliceExt::is_kind_partially_covered`] over
2304    /// [`Self::preconditions`].
2305    ///
2306    /// Peer of [`Self::is_postcondition_kind_partially_covered`] on the
2307    /// (precondition, postcondition) partition of the boundary's two
2308    /// condition-vector slots; both peers compose against the SAME
2309    /// slice-level substrate primitive so a regression at the per-slice
2310    /// fused short-circuit walk fails at that primitive's tests rather
2311    /// than as silent drift at either struct-level arm.
2312    #[must_use]
2313    pub fn is_precondition_kind_partially_covered(&self) -> bool {
2314        self.preconditions.is_kind_partially_covered()
2315    }
2316
2317    /// `true` iff [`Self::postconditions`] carries AT LEAST ONE
2318    /// [`ConditionKind::ALL`] variant AND is MISSING AT LEAST ONE
2319    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
2320    /// the (precondition, postcondition, condition-union) parent-state
2321    /// middle-arm triad on [`Boundary`]. Thin typed delegate to
2322    /// [`ConditionSliceExt::is_kind_partially_covered`] over
2323    /// [`Self::postconditions`].
2324    ///
2325    /// Peer of [`Self::is_precondition_kind_partially_covered`]. See
2326    /// that method for the full rationale — the two methods share ONE
2327    /// lift motivation, ONE fail-before-pass-after composition-law pin,
2328    /// and ONE two-surface parity contract with the ephemeral sugar
2329    /// type via
2330    /// [`crate::ephemeral::EphemeralSpec::is_postcondition_kind_partially_covered`].
2331    #[must_use]
2332    pub fn is_postcondition_kind_partially_covered(&self) -> bool {
2333        self.postconditions.is_kind_partially_covered()
2334    }
2335
2336    /// `true` iff `preconditions ∪ postconditions` is MISSING EXACTLY
2337    /// ONE [`ConditionKind::ALL`] variant — the union arm of the
2338    /// (precondition, postcondition, condition-union) cardinality-mid-
2339    /// endpoint triad on [`Boundary`] closing the "one hole remaining"
2340    /// near-saturation-endpoint on the union of the two condition
2341    /// slots. The near-saturation-endpoint Boolean fast-path peer of
2342    /// [`Self::is_condition_kind_saturated`] on the union axis: where
2343    /// the saturation-endpoint predicate answers "is the union covered
2344    /// by every ALL variant?", `has_unique_missing_condition_kind`
2345    /// answers "is the union one kind away from covered?".
2346    ///
2347    /// Composed body: constructs a two-step-short-circuit walk over
2348    /// [`ConditionKind::ALL`] under the [`Self::has_condition_kind`]
2349    /// union primitive negated — the first missing union arm surfaces,
2350    /// then the walk short-circuits at the second. Byte-for-byte peer
2351    /// of [`ConditionSliceExt::has_unique_missing_kind`] one slice-
2352    /// layer down, lifted to compose against
2353    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
2354    /// against a single slice's `has_kind`. A regression at the union
2355    /// primitive fails at the slice-level substrate tests + the union
2356    /// composition-law tests rather than as silent drift here.
2357    ///
2358    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_unique_missing_condition_kind`]
2359    ///
2360    /// Byte-identical signature `(&Self) -> bool`, byte-identical
2361    /// two-step short-circuit body composed against the ephemeral
2362    /// surface's own union primitive. Both methods compose against
2363    /// the SAME slice-level substrate primitive
2364    /// [`ConditionSliceExt::has_unique_missing_kind`] via the two-
2365    /// slice union — a regression at the per-slice near-saturation-
2366    /// endpoint walk fails at that primitive's tests rather than as
2367    /// silent drift at either struct-level near-saturation caller.
2368    ///
2369    /// # Compounding
2370    ///
2371    /// A future operator-facing "one kind away from saturated" gap-
2372    /// analysis diagnostic reads
2373    /// `boundary.has_unique_missing_condition_kind()` at ONE call site
2374    /// rather than restating either `boundary.missing_condition_kind_count() == 1`
2375    /// (which walks every slot to count) or
2376    /// `boundary.missing_condition_kinds().len() == 1` (which
2377    /// allocates the Vec). A `has-unique-missing-condition-kind`
2378    /// require-tag classifier arm reaches this primitive at ONE
2379    /// substrate call — byte-for-byte peer of the tagged-union
2380    /// `has-unique-missing-kind` classifier one struct-layer up.
2381    ///
2382    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2383    /// preserves proofs — the cardinality-mid-endpoint projection on
2384    /// the missing axis composes the SAME two-step short-circuit walk
2385    /// under a two-slice union negation on both this boundary surface
2386    /// and the ephemeral surface). THEORY.md §VI.1 (generation over
2387    /// composition — a new [`ConditionKind`] variant reaches both
2388    /// surfaces' cardinality-mid-endpoint triads mechanically through
2389    /// the delegated union primitive).
2390    #[must_use]
2391    pub fn has_unique_missing_condition_kind(&self) -> bool {
2392        let mut it = ConditionKind::ALL
2393            .iter()
2394            .copied()
2395            .filter(|k| !self.has_condition_kind(*k));
2396        it.next().is_some() && it.next().is_none()
2397    }
2398
2399    /// `true` iff [`Self::preconditions`] is MISSING EXACTLY ONE
2400    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
2401    /// the (precondition, postcondition, condition-union) cardinality-
2402    /// mid-endpoint triad on [`Boundary`]. Thin typed delegate to
2403    /// [`ConditionSliceExt::has_unique_missing_kind`] over
2404    /// [`Self::preconditions`].
2405    ///
2406    /// Peer of [`Self::has_unique_missing_postcondition_kind`] on the
2407    /// (precondition, postcondition) partition of the boundary's two
2408    /// condition-vector slots; both peers compose against the SAME
2409    /// slice-level substrate primitive so a regression at the per-
2410    /// slice two-step short-circuit walk under negation fails at that
2411    /// primitive's tests rather than as silent drift at either
2412    /// struct-level arm.
2413    #[must_use]
2414    pub fn has_unique_missing_precondition_kind(&self) -> bool {
2415        self.preconditions.has_unique_missing_kind()
2416    }
2417
2418    /// `true` iff [`Self::postconditions`] is MISSING EXACTLY ONE
2419    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
2420    /// the (precondition, postcondition, condition-union) cardinality-
2421    /// mid-endpoint triad on [`Boundary`]. Thin typed delegate to
2422    /// [`ConditionSliceExt::has_unique_missing_kind`] over
2423    /// [`Self::postconditions`].
2424    ///
2425    /// Peer of [`Self::has_unique_missing_precondition_kind`]. See
2426    /// that method for the full rationale — the two methods share ONE
2427    /// lift motivation, ONE fail-before-pass-after composition-law
2428    /// pin, and ONE two-surface parity contract with the ephemeral
2429    /// sugar type via
2430    /// [`crate::ephemeral::EphemeralSpec::has_unique_missing_postcondition_kind`].
2431    #[must_use]
2432    pub fn has_unique_missing_postcondition_kind(&self) -> bool {
2433        self.postconditions.has_unique_missing_kind()
2434    }
2435
2436    /// The SOLE [`ConditionKind::ALL`] variant ABSENT from
2437    /// `preconditions ∪ postconditions`, or `None` when the union is
2438    /// missing 0 or ≥ 2 kinds — the union arm of the (precondition,
2439    /// postcondition, condition-union) exactly-one-missing witnessing
2440    /// triad on [`Boundary`] closing the near-saturation witness on
2441    /// the closed-set-complement axis on the union of the two
2442    /// condition slots. Witnessing scalar peer of
2443    /// [`Self::has_unique_missing_condition_kind`] (=1 predicate) on
2444    /// the union axis: where the Boolean predicate answers "is the
2445    /// union one kind AWAY from covered?", `unique_missing_condition_kind`
2446    /// returns `Some(k)` naming that SOLE remaining hole (or `None` on
2447    /// the 0 or ≥ 2 arms).
2448    ///
2449    /// # Composed body
2450    ///
2451    /// A two-step-short-circuit walk over [`ConditionKind::ALL`] under
2452    /// a NEGATED [`Self::has_condition_kind`] union primitive — pull
2453    /// the first hit; return `Some(first)` iff the second hit is
2454    /// [`None`], else `None`. Byte-for-byte peer of
2455    /// [`ConditionSliceExt::unique_missing_kind`] one slice-layer
2456    /// down, lifted to compose against the two-slice union rather than
2457    /// against a single slice's `has_kind`. A regression at the union
2458    /// primitive fails at the slice-level substrate tests + the union
2459    /// composition-law tests rather than as silent drift here.
2460    ///
2461    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::unique_missing_condition_kind`]
2462    ///
2463    /// Byte-identical signature `(&Self) -> Option<ConditionKind>`,
2464    /// byte-identical two-step short-circuit body composed against the
2465    /// ephemeral surface's own union primitive. Both methods compose
2466    /// against the SAME slice-level substrate primitive
2467    /// [`ConditionSliceExt::unique_missing_kind`] via the two-slice
2468    /// union — a regression at the per-slice near-saturation
2469    /// witnessing walk fails at that primitive's tests rather than as
2470    /// silent drift at either struct-level near-saturation caller.
2471    ///
2472    /// # Sibling to [`Self::unique_distinct_condition_kind`]
2473    ///
2474    /// Closed-set-complement peer of the exactly-one-hit witness on
2475    /// the closed-set-inversion axis at the boundary union struct
2476    /// layer — where `unique_distinct_condition_kind` names the SOLE
2477    /// kind COVERED, `unique_missing_condition_kind` names the SOLE
2478    /// kind ABSENT. Both compose against a two-step-short-circuit walk
2479    /// over [`ConditionKind::ALL`] under [`Self::has_condition_kind`]
2480    /// vs `!has_condition_kind` (this primitive).
2481    ///
2482    /// # Compounding
2483    ///
2484    /// A future gap-analysis diagnostic that names "one remaining
2485    /// [`ConditionKind`] not covered by this Boundary" reads
2486    /// `boundary.unique_missing_condition_kind()` at ONE call site —
2487    /// the WITNESS + the exactly-one predicate composed at ONE short-
2488    /// circuit walk, rather than pairing the Boolean
2489    /// [`Self::has_unique_missing_condition_kind`] with
2490    /// [`Self::first_missing_condition_kind`] at TWO independent walks
2491    /// whose agreement is a coincidence.
2492    ///
2493    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2494    /// preserves proofs — the complement-exactly-one-hit witnessing
2495    /// projection composes the SAME two-step short-circuit walk under
2496    /// a two-slice union negation on both this boundary surface and
2497    /// the ephemeral surface). THEORY.md §VI.1 (generation over
2498    /// composition — a new [`ConditionKind`] variant reaches both
2499    /// surfaces' unique-missing-kind triads mechanically through the
2500    /// delegated union primitive).
2501    #[must_use]
2502    pub fn unique_missing_condition_kind(&self) -> Option<ConditionKind> {
2503        let mut it = ConditionKind::ALL
2504            .iter()
2505            .copied()
2506            .filter(|k| !self.has_condition_kind(*k));
2507        let first = it.next()?;
2508        match it.next() {
2509            None => Some(first),
2510            Some(_) => None,
2511        }
2512    }
2513
2514    /// The SOLE [`ConditionKind::ALL`] variant ABSENT from
2515    /// [`Self::preconditions`], or `None` when preconditions are
2516    /// missing 0 or ≥ 2 kinds — the precondition-side arm of the
2517    /// (precondition, postcondition, condition-union) exactly-one-
2518    /// missing witnessing triad on [`Boundary`]. Thin typed delegate
2519    /// to [`ConditionSliceExt::unique_missing_kind`] over
2520    /// [`Self::preconditions`].
2521    ///
2522    /// Peer of [`Self::unique_missing_postcondition_kind`] on the
2523    /// (precondition, postcondition) partition of the boundary's two
2524    /// condition-vector slots; both peers compose against the SAME
2525    /// slice-level substrate primitive so a regression at the per-
2526    /// slice two-step short-circuit witnessing walk under negation
2527    /// fails at that primitive's tests rather than as silent drift at
2528    /// either struct-level arm.
2529    #[must_use]
2530    pub fn unique_missing_precondition_kind(&self) -> Option<ConditionKind> {
2531        self.preconditions.unique_missing_kind()
2532    }
2533
2534    /// The SOLE [`ConditionKind::ALL`] variant ABSENT from
2535    /// [`Self::postconditions`], or `None` when postconditions are
2536    /// missing 0 or ≥ 2 kinds — the postcondition-side arm of the
2537    /// (precondition, postcondition, condition-union) exactly-one-
2538    /// missing witnessing triad on [`Boundary`]. Thin typed delegate
2539    /// to [`ConditionSliceExt::unique_missing_kind`] over
2540    /// [`Self::postconditions`].
2541    ///
2542    /// Peer of [`Self::unique_missing_precondition_kind`]. See that
2543    /// method for the full rationale — the two methods share ONE lift
2544    /// motivation, ONE fail-before-pass-after composition-law pin, and
2545    /// ONE two-surface parity contract with the ephemeral sugar type
2546    /// via
2547    /// [`crate::ephemeral::EphemeralSpec::unique_missing_postcondition_kind`].
2548    #[must_use]
2549    pub fn unique_missing_postcondition_kind(&self) -> Option<ConditionKind> {
2550        self.postconditions.unique_missing_kind()
2551    }
2552
2553    /// `true` iff `preconditions ∪ postconditions` is MISSING AT
2554    /// LEAST TWO [`ConditionKind::ALL`] variants — the union arm of
2555    /// the (precondition, postcondition, condition-union) cardinality-
2556    /// many-arm triad on [`Boundary`] closing the "≥ 2 holes
2557    /// remaining" arm on the union of the two condition slots. The
2558    /// many-arm Boolean fast-path peer of
2559    /// [`Self::has_unique_missing_condition_kind`] (=1 arm) and
2560    /// [`Self::is_condition_kind_saturated`] (=0 arm) on the union
2561    /// axis, closing the {0, 1, ≥2} trichotomy at the union struct
2562    /// layer.
2563    ///
2564    /// Composed body: constructs a two-step-short-circuit walk over
2565    /// [`ConditionKind::ALL`] under the [`Self::has_condition_kind`]
2566    /// union primitive negated — pulls up to two hits off the
2567    /// filtered iterator; the primitive returns `true` iff BOTH the
2568    /// first and the second are [`Some`]. Byte-for-byte peer of
2569    /// [`ConditionSliceExt::has_multiple_missing_kinds`] one slice-
2570    /// layer down, lifted to compose against
2571    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
2572    /// against a single slice's `has_kind`. A regression at the union
2573    /// primitive fails at the slice-level substrate tests + the union
2574    /// composition-law tests rather than as silent drift here.
2575    ///
2576    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_multiple_missing_condition_kind`]
2577    ///
2578    /// Byte-identical signature `(&Self) -> bool`, byte-identical
2579    /// two-step short-circuit body composed against the ephemeral
2580    /// surface's own union primitive. Both methods compose against
2581    /// the SAME slice-level substrate primitive
2582    /// [`ConditionSliceExt::has_multiple_missing_kinds`] via the two-
2583    /// slice union — a regression at the per-slice many-arm walk
2584    /// fails at that primitive's tests rather than as silent drift at
2585    /// either struct-level many-missing caller.
2586    ///
2587    /// # Compounding
2588    ///
2589    /// A future operator-facing "≥ 2 dependencies still unfulfilled"
2590    /// gap-analysis diagnostic reads
2591    /// `boundary.has_multiple_missing_condition_kind()` at ONE call
2592    /// site rather than restating
2593    /// `boundary.missing_condition_kind_count() >= 2` (which walks
2594    /// every slot to count) or
2595    /// `boundary.missing_condition_kinds().len() >= 2` (which
2596    /// allocates the Vec). A `has-multiple-missing-condition-kind`
2597    /// require-tag classifier arm reaches this primitive at ONE
2598    /// substrate call — byte-for-byte peer of the tagged-union
2599    /// `has-multiple-missing-kinds` classifier one struct-layer up.
2600    ///
2601    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2602    /// preserves proofs — the cardinality-many-arm projection on the
2603    /// missing axis composes the SAME two-step short-circuit walk
2604    /// under a two-slice union negation on both this boundary surface
2605    /// and the ephemeral surface). THEORY.md §VI.1 (generation over
2606    /// composition — a new [`ConditionKind`] variant reaches both
2607    /// surfaces' cardinality-many-arm triads mechanically through the
2608    /// delegated union primitive).
2609    #[must_use]
2610    pub fn has_multiple_missing_condition_kind(&self) -> bool {
2611        let mut it = ConditionKind::ALL
2612            .iter()
2613            .copied()
2614            .filter(|k| !self.has_condition_kind(*k));
2615        it.next().is_some() && it.next().is_some()
2616    }
2617
2618    /// `true` iff [`Self::preconditions`] is MISSING AT LEAST TWO
2619    /// [`ConditionKind::ALL`] variants — the precondition-side arm of
2620    /// the (precondition, postcondition, condition-union) cardinality-
2621    /// many-arm triad on [`Boundary`]. Thin typed delegate to
2622    /// [`ConditionSliceExt::has_multiple_missing_kinds`] over
2623    /// [`Self::preconditions`].
2624    ///
2625    /// Peer of [`Self::has_multiple_missing_postcondition_kind`] on
2626    /// the (precondition, postcondition) partition of the boundary's
2627    /// two condition-vector slots; both peers compose against the
2628    /// SAME slice-level substrate primitive so a regression at the
2629    /// per-slice two-step short-circuit walk under negation fails at
2630    /// that primitive's tests rather than as silent drift at either
2631    /// struct-level arm.
2632    #[must_use]
2633    pub fn has_multiple_missing_precondition_kind(&self) -> bool {
2634        self.preconditions.has_multiple_missing_kinds()
2635    }
2636
2637    /// `true` iff [`Self::postconditions`] is MISSING AT LEAST TWO
2638    /// [`ConditionKind::ALL`] variants — the postcondition-side arm of
2639    /// the (precondition, postcondition, condition-union) cardinality-
2640    /// many-arm triad on [`Boundary`]. Thin typed delegate to
2641    /// [`ConditionSliceExt::has_multiple_missing_kinds`] over
2642    /// [`Self::postconditions`].
2643    ///
2644    /// Peer of [`Self::has_multiple_missing_precondition_kind`]. See
2645    /// that method for the full rationale — the two methods share ONE
2646    /// lift motivation, ONE fail-before-pass-after composition-law
2647    /// pin, and ONE two-surface parity contract with the ephemeral
2648    /// sugar type via
2649    /// [`crate::ephemeral::EphemeralSpec::has_multiple_missing_postcondition_kind`].
2650    #[must_use]
2651    pub fn has_multiple_missing_postcondition_kind(&self) -> bool {
2652        self.postconditions.has_multiple_missing_kinds()
2653    }
2654
2655    /// `true` iff `preconditions ∪ postconditions` is MISSING AT MOST
2656    /// ONE [`ConditionKind::ALL`] variant — the union arm of the
2657    /// (precondition, postcondition, condition-union) cardinality
2658    /// "≤ 1" triad on [`Boundary`] closing the "at most one hole
2659    /// remaining" arm on the union of the two condition slots. The
2660    /// Boolean cardinality "≤ 1" negation peer of
2661    /// [`Self::has_multiple_missing_condition_kind`] (≥ 2 many-arm)
2662    /// under the definitional negation
2663    /// `!has_multiple_missing_condition_kind`, and the trichotomy-
2664    /// union peer of [`Self::is_condition_kind_saturated`] (=0
2665    /// zero-arm) OR [`Self::has_unique_missing_condition_kind`] (=1
2666    /// mid-endpoint) — the arrangement space where the boundary is
2667    /// SATURATED-OR-NEAR-SATURATED (zero or exactly one kind missing
2668    /// across the union of the two slices).
2669    ///
2670    /// Composed body: `!self.has_multiple_missing_condition_kind()` —
2671    /// a definitional negation of the many-arm union primitive. Short-
2672    /// circuits transitively through
2673    /// [`Self::has_multiple_missing_condition_kind`]'s two-step short-
2674    /// circuit walk over [`ConditionKind::ALL`] under negated
2675    /// [`Self::has_condition_kind`] — returns `true` as soon as the
2676    /// many-arm walk stops with fewer than two missing hits, WITHOUT
2677    /// materializing [`Self::missing_condition_kinds`]'s `Vec` and
2678    /// WITHOUT walking every slot to build
2679    /// [`Self::missing_condition_kind_count`]'s scalar. Byte-for-byte
2680    /// peer of [`ConditionSliceExt::has_at_most_one_missing_kind`] one
2681    /// slice-layer down, lifted to compose against
2682    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
2683    /// against a single slice's `has_kind`. A regression at the union
2684    /// primitive fails at the slice-level substrate tests + the union
2685    /// composition-law tests rather than as silent drift here.
2686    ///
2687    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_at_most_one_missing_condition_kind`]
2688    ///
2689    /// Byte-identical signature `(&Self) -> bool`, byte-identical
2690    /// definitional-negation body composed against the ephemeral
2691    /// surface's own many-arm union primitive. Both methods compose
2692    /// against the SAME slice-level substrate primitive
2693    /// [`ConditionSliceExt::has_at_most_one_missing_kind`] via the
2694    /// two-slice union — a regression at the per-slice "≤ 1" negation
2695    /// fails at that primitive's tests rather than as silent drift at
2696    /// either struct-level near-saturation-or-saturated caller.
2697    ///
2698    /// # Compounding
2699    ///
2700    /// A future operator-facing "at most one dependency still
2701    /// unfulfilled" gap-analysis diagnostic reads
2702    /// `boundary.has_at_most_one_missing_condition_kind()` at ONE call
2703    /// site rather than restating
2704    /// `boundary.missing_condition_kind_count() <= 1` (which walks every
2705    /// slot to count) or `boundary.missing_condition_kinds().len() <= 1`
2706    /// (which allocates the Vec) or the union of the two Booleans
2707    /// `boundary.is_condition_kind_saturated() ||
2708    /// boundary.has_unique_missing_condition_kind()` (which walks the
2709    /// closed-set-complement scan twice). A `has-at-most-one-missing-
2710    /// condition-kind` require-tag classifier arm reaches this
2711    /// primitive at ONE substrate call — byte-for-byte peer of the
2712    /// tagged-union `has-at-most-one-missing-kind` classifier one
2713    /// struct-layer up, closing the {0, 1, ≥ 2, ≤ 1} cardinality-
2714    /// Boolean grid on the missing axis at the Boundary struct layer
2715    /// alongside its sibling `has-multiple-missing-condition-kind`
2716    /// under the Boolean negation axis.
2717    ///
2718    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2719    /// preserves proofs — the cardinality "≤ 1" projection on the
2720    /// missing axis composes the SAME definitional negation of the
2721    /// many-arm two-step short-circuit walk on both this boundary
2722    /// surface and the ephemeral surface). THEORY.md §VI.1 (generation
2723    /// over composition — a new [`ConditionKind`] variant reaches both
2724    /// surfaces' cardinality "≤ 1" triads mechanically through the
2725    /// delegated union primitive).
2726    #[must_use]
2727    pub fn has_at_most_one_missing_condition_kind(&self) -> bool {
2728        !self.has_multiple_missing_condition_kind()
2729    }
2730
2731    /// `true` iff [`Self::preconditions`] is MISSING AT MOST ONE
2732    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
2733    /// the (precondition, postcondition, condition-union) cardinality
2734    /// "≤ 1" triad on [`Boundary`]. Thin typed delegate to
2735    /// [`ConditionSliceExt::has_at_most_one_missing_kind`] over
2736    /// [`Self::preconditions`].
2737    ///
2738    /// Peer of [`Self::has_at_most_one_missing_postcondition_kind`]
2739    /// on the (precondition, postcondition) partition of the boundary's
2740    /// two condition-vector slots; both peers compose against the SAME
2741    /// slice-level substrate primitive so a regression at the per-
2742    /// slice "≤ 1" negation of the many-arm walk fails at that
2743    /// primitive's tests rather than as silent drift at either
2744    /// struct-level arm.
2745    #[must_use]
2746    pub fn has_at_most_one_missing_precondition_kind(&self) -> bool {
2747        self.preconditions.has_at_most_one_missing_kind()
2748    }
2749
2750    /// `true` iff [`Self::postconditions`] is MISSING AT MOST ONE
2751    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
2752    /// the (precondition, postcondition, condition-union) cardinality
2753    /// "≤ 1" triad on [`Boundary`]. Thin typed delegate to
2754    /// [`ConditionSliceExt::has_at_most_one_missing_kind`] over
2755    /// [`Self::postconditions`].
2756    ///
2757    /// Peer of [`Self::has_at_most_one_missing_precondition_kind`].
2758    /// See that method for the full rationale — the two methods share
2759    /// ONE lift motivation, ONE fail-before-pass-after composition-
2760    /// law pin, and ONE two-surface parity contract with the
2761    /// ephemeral sugar type via
2762    /// [`crate::ephemeral::EphemeralSpec::has_at_most_one_missing_postcondition_kind`].
2763    #[must_use]
2764    pub fn has_at_most_one_missing_postcondition_kind(&self) -> bool {
2765        self.postconditions.has_at_most_one_missing_kind()
2766    }
2767
2768    /// `true` iff `preconditions ∪ postconditions` carries NO
2769    /// [`Condition`] with the given [`ConditionKind`] — the union arm
2770    /// of the (precondition, postcondition, condition-union)
2771    /// per-kind-complement triad on [`Boundary`], definitional
2772    /// negation of [`Self::has_condition_kind`].
2773    ///
2774    /// # Composed body
2775    ///
2776    /// `!self.has_condition_kind(kind)` — the definitional negation
2777    /// of the two-slice union primitive. Equivalent to the AND of the
2778    /// two half-slice per-kind-complement arms
2779    /// (`self.lacks_precondition_kind(k) && self.lacks_postcondition_kind(k)`),
2780    /// by the boolean identity `!(a || b) == !a && !b`. Both forms
2781    /// return `true` iff BOTH slices lack the addressed kind; the
2782    /// composed body chosen here short-circuits through the union
2783    /// primitive so a regression at the per-slice presence probe fails
2784    /// at that primitive's tests rather than as silent drift at either
2785    /// half-slice complement arm. Equivalent to
2786    /// `self.missing_condition_kinds().contains(&kind)` without
2787    /// materializing the closed-set-complement Vec at every callsite.
2788    ///
2789    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::lacks_condition_kind`]
2790    ///
2791    /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
2792    /// byte-identical `!self.has_condition_kind(kind)` body, on the
2793    /// sugar-surface type whose pre/post condition vectors live
2794    /// directly on the struct. Both methods compose against the SAME
2795    /// slice-level substrate primitive
2796    /// [`ConditionSliceExt::lacks_kind`] via the two-slice union
2797    /// composed through [`Self::has_condition_kind`] — a regression
2798    /// at the per-slice negation fails at that primitive's tests
2799    /// rather than as silent drift at either struct-level complement
2800    /// caller.
2801    ///
2802    /// # Compounding
2803    ///
2804    /// A `lacks-<kind>` require-tag classifier arm — byte-for-byte
2805    /// peer of the tagged-union `lacks-<kind>` classifier one struct-
2806    /// layer up + the future `condition-<kind>` require-tag family's
2807    /// negated dual — reaches this primitive at ONE call site rather
2808    /// than negating `boundary.has_condition_kind(k)` at the callsite
2809    /// or restating `boundary.missing_condition_kinds().contains(&k)`
2810    /// with its allocation.
2811    ///
2812    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2813    /// preserves proofs — the per-kind closed-set-complement
2814    /// projection composes the SAME two-slice union negation on both
2815    /// this boundary surface and the slice-level substrate primitive
2816    /// under definitional negation). THEORY.md §VI.1 (generation over
2817    /// composition — a new [`ConditionKind`] variant reaches both
2818    /// surfaces' complement-triads mechanically through the delegated
2819    /// union primitive).
2820    #[must_use]
2821    pub fn lacks_condition_kind(&self, kind: ConditionKind) -> bool {
2822        !self.has_condition_kind(kind)
2823    }
2824
2825    /// `true` iff [`Self::preconditions`] carries NO [`Condition`]
2826    /// with the given [`ConditionKind`] — the precondition-side arm
2827    /// of the (precondition, postcondition, condition-union)
2828    /// per-kind-complement triad on [`Boundary`]. Thin typed delegate
2829    /// to [`ConditionSliceExt::lacks_kind`] over
2830    /// [`Self::preconditions`].
2831    ///
2832    /// Peer of [`Self::lacks_postcondition_kind`] on the (precondition,
2833    /// postcondition) partition of the boundary's two condition-vector
2834    /// slots; both peers compose against the SAME slice-level substrate
2835    /// primitive so a regression at the per-slice negation fails at
2836    /// that primitive's tests rather than as silent drift at either
2837    /// struct-level arm.
2838    #[must_use]
2839    pub fn lacks_precondition_kind(&self, kind: ConditionKind) -> bool {
2840        self.preconditions.lacks_kind(kind)
2841    }
2842
2843    /// `true` iff [`Self::postconditions`] carries NO [`Condition`]
2844    /// with the given [`ConditionKind`] — the postcondition-side arm
2845    /// of the (precondition, postcondition, condition-union)
2846    /// per-kind-complement triad on [`Boundary`]. Thin typed delegate
2847    /// to [`ConditionSliceExt::lacks_kind`] over
2848    /// [`Self::postconditions`].
2849    ///
2850    /// Peer of [`Self::lacks_precondition_kind`]. See that method for
2851    /// the full rationale — the two methods share ONE lift motivation,
2852    /// ONE fail-before-pass-after composition-law pin, and ONE
2853    /// two-surface parity contract with the ephemeral sugar type via
2854    /// [`crate::ephemeral::EphemeralSpec::lacks_postcondition_kind`].
2855    #[must_use]
2856    pub fn lacks_postcondition_kind(&self, kind: ConditionKind) -> bool {
2857        self.postconditions.lacks_kind(kind)
2858    }
2859
2860    /// `true` iff `preconditions ∪ postconditions` carries at least
2861    /// one [`Condition`] with the given [`ConditionKind`] AND carries
2862    /// no [`Condition`] whose kind is anything OTHER than `kind` — the
2863    /// union arm of the (precondition, postcondition, condition-union)
2864    /// kind-scoped strict-refinement triad on [`Boundary`], byte-for-
2865    /// byte peer of the per-kind presence probe
2866    /// [`Self::has_condition_kind`] under the well-formed-diagonal
2867    /// refinement.
2868    ///
2869    /// # Composed body
2870    ///
2871    /// A FUSED short-circuit closed-set walk over
2872    /// [`ConditionKind::ALL`] under [`Self::has_condition_kind`] that
2873    /// returns `false` at the EARLIEST kind whose presence spans
2874    /// either slice's populated set and is NOT `kind`, and returns
2875    /// `true` iff the sweep completes with `kind` seen as the sole
2876    /// distinct populated kind. Strictly cheaper than the widened
2877    /// composition
2878    /// `boundary.distinct_condition_kinds() == vec![kind]` (which
2879    /// allocates the distinct-kind Vec before the equality test) or
2880    /// the (pre, post) AND-of-strict-refinement
2881    /// `boundary.preconditions.has_only_kind(kind)
2882    ///     && boundary.postconditions.has_only_kind(kind)` (which is
2883    /// TOO STRICT — a single-slice-populated arrangement whose empty
2884    /// side returns `false` fails this AND but IS well-formed on the
2885    /// union).
2886    ///
2887    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_only_condition_kind`]
2888    ///
2889    /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
2890    /// byte-identical fused-closed-set-walk body, on the sugar-surface
2891    /// type whose pre/post condition vectors live directly on the
2892    /// struct. Both methods compose against the SAME slice-level
2893    /// substrate primitive [`ConditionSliceExt::has_only_kind`] via
2894    /// the two-slice union composed through
2895    /// [`Self::has_condition_kind`] — a regression at the per-slice
2896    /// fused walk fails at that primitive's tests rather than as
2897    /// silent drift at either struct-level kind-scoped-strict-
2898    /// refinement caller.
2899    ///
2900    /// # Compounding
2901    ///
2902    /// A future coherence check verifying "every attested closed-loop
2903    /// probe Process carries ONLY `ClosedLoopAuth` postconditions on
2904    /// the union of pre + post" reads
2905    /// `boundary.has_only_condition_kind(ConditionKind::ClosedLoopAuth)`
2906    /// at ONE call site rather than restating either widened
2907    /// composition. A `has-only-<kind>` require-tag classifier arm
2908    /// reaches this primitive at ONE substrate call — byte-for-byte
2909    /// peer of the tagged-union `has-only-<kind>` classifier one
2910    /// struct-layer up, closing the kind-scoped strict-refinement
2911    /// grid on the well-formed-diagonal arm at the Boundary struct
2912    /// layer alongside its sibling `has-<kind>` under the per-kind
2913    /// presence-probe axis.
2914    ///
2915    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2916    /// preserves proofs — the kind-scoped strict-refinement projection
2917    /// composes the SAME fused short-circuit closed-set walk under
2918    /// [`Self::has_condition_kind`] on both this boundary surface and
2919    /// the ephemeral surface). THEORY.md §VI.1 (generation over
2920    /// composition — a new [`ConditionKind`] variant reaches both
2921    /// surfaces' kind-scoped strict-refinement triads mechanically
2922    /// through the delegated union primitive).
2923    #[must_use]
2924    pub fn has_only_condition_kind(&self, kind: ConditionKind) -> bool {
2925        let mut saw_kind = false;
2926        for k in ConditionKind::ALL {
2927            if !self.has_condition_kind(k) {
2928                continue;
2929            }
2930            if k == kind {
2931                saw_kind = true;
2932            } else {
2933                return false;
2934            }
2935        }
2936        saw_kind
2937    }
2938
2939    /// `true` iff [`Self::preconditions`] carries at least one
2940    /// [`Condition`] with the given [`ConditionKind`] AND carries no
2941    /// [`Condition`] whose kind is anything OTHER than `kind` — the
2942    /// precondition-side arm of the (precondition, postcondition,
2943    /// condition-union) kind-scoped strict-refinement triad on
2944    /// [`Boundary`]. Thin typed delegate to
2945    /// [`ConditionSliceExt::has_only_kind`] over
2946    /// [`Self::preconditions`].
2947    ///
2948    /// Peer of [`Self::has_only_postcondition_kind`] on the
2949    /// (precondition, postcondition) partition of the boundary's two
2950    /// condition-vector slots; both peers compose against the SAME
2951    /// slice-level substrate primitive so a regression at the per-
2952    /// slice fused walk fails at that primitive's tests rather than
2953    /// as silent drift at either struct-level arm.
2954    #[must_use]
2955    pub fn has_only_precondition_kind(&self, kind: ConditionKind) -> bool {
2956        self.preconditions.has_only_kind(kind)
2957    }
2958
2959    /// `true` iff [`Self::postconditions`] carries at least one
2960    /// [`Condition`] with the given [`ConditionKind`] AND carries no
2961    /// [`Condition`] whose kind is anything OTHER than `kind` — the
2962    /// postcondition-side arm of the (precondition, postcondition,
2963    /// condition-union) kind-scoped strict-refinement triad on
2964    /// [`Boundary`]. Thin typed delegate to
2965    /// [`ConditionSliceExt::has_only_kind`] over
2966    /// [`Self::postconditions`].
2967    ///
2968    /// Peer of [`Self::has_only_precondition_kind`]. See that method
2969    /// for the full rationale — the two methods share ONE lift
2970    /// motivation, ONE fail-before-pass-after composition-law pin,
2971    /// and ONE two-surface parity contract with the ephemeral sugar
2972    /// type via
2973    /// [`crate::ephemeral::EphemeralSpec::has_only_postcondition_kind`].
2974    #[must_use]
2975    pub fn has_only_postcondition_kind(&self, kind: ConditionKind) -> bool {
2976        self.postconditions.has_only_kind(kind)
2977    }
2978
2979    /// `true` iff `preconditions ∪ postconditions` carries NO
2980    /// [`Condition`] with the given [`ConditionKind`] AND carries at
2981    /// least one [`Condition`] for every OTHER [`ConditionKind`] — the
2982    /// union arm of the (precondition, postcondition, condition-union)
2983    /// kind-scoped strict-refinement triad on [`Boundary`] specialized
2984    /// to the MISSING axis, byte-for-byte peer of the populated-axis
2985    /// [`Self::has_only_condition_kind`] under closed-set complement.
2986    ///
2987    /// # Composed body
2988    ///
2989    /// A FUSED short-circuit closed-set walk over
2990    /// [`ConditionKind::ALL`] under [`Self::has_condition_kind`] that
2991    /// skips every populated kind, returns `false` at the EARLIEST
2992    /// kind whose absence spans both slices' missing sets and is NOT
2993    /// `kind`, and returns `true` iff the sweep completes with `kind`
2994    /// seen as the sole missing kind. Strictly cheaper than the
2995    /// widened composition
2996    /// `boundary.missing_condition_kinds() == vec![kind]` (which
2997    /// allocates the missing-kind Vec before the equality test) or
2998    /// the (pre AND post) AND-of-strict-refinement
2999    /// `boundary.preconditions.lacks_only_kind(kind)
3000    ///     && boundary.postconditions.lacks_only_kind(kind)` (which is
3001    /// TOO STRICT — a single-slice-populated arrangement whose empty
3002    /// side returns `false` fails this AND but IS well-formed on the
3003    /// union).
3004    ///
3005    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::lacks_only_condition_kind`]
3006    ///
3007    /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
3008    /// byte-identical fused-closed-set-walk body under complement, on
3009    /// the ephemeral sugar surface whose pre/post condition vectors
3010    /// live inline. Both methods compose against the SAME slice-level
3011    /// substrate primitive [`ConditionSliceExt::lacks_only_kind`] via
3012    /// the two-slice union composed through
3013    /// [`Self::has_condition_kind`] — a regression at the per-slice
3014    /// fused walk under complement fails at that primitive's tests
3015    /// rather than as silent drift at either struct-level kind-scoped-
3016    /// strict-refinement-on-missing caller.
3017    ///
3018    /// # Compounding
3019    ///
3020    /// A future coherence check verifying "every partially-attested
3021    /// closed-loop probe Process is missing ONLY the `ClosedLoopAuth`
3022    /// postcondition" reads
3023    /// `boundary.lacks_only_condition_kind(ConditionKind::ClosedLoopAuth)`
3024    /// at ONE call site rather than restating either widened
3025    /// composition. A `lacks-only-<kind>` require-tag classifier arm
3026    /// reaches this primitive at ONE substrate call — byte-for-byte
3027    /// peer of the tagged-union `lacks-only-<kind>` classifier one
3028    /// struct-layer up, CLOSING the kind-scoped strict-refinement 2x2
3029    /// grid on the Boundary struct layer alongside its populated-axis
3030    /// peer [`Self::has_only_condition_kind`].
3031    ///
3032    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
3033    /// preserves proofs — the kind-scoped strict-refinement projection
3034    /// on the missing axis composes the SAME fused short-circuit
3035    /// closed-set walk under [`Self::has_condition_kind`] on both this
3036    /// boundary surface and the ephemeral surface). THEORY.md §VI.1
3037    /// (generation over composition — a new [`ConditionKind`] variant
3038    /// reaches both surfaces' kind-scoped strict-refinement-on-missing
3039    /// triads mechanically through the delegated union primitive).
3040    #[must_use]
3041    pub fn lacks_only_condition_kind(&self, kind: ConditionKind) -> bool {
3042        let mut saw_kind = false;
3043        for k in ConditionKind::ALL {
3044            if self.has_condition_kind(k) {
3045                continue;
3046            }
3047            if k == kind {
3048                saw_kind = true;
3049            } else {
3050                return false;
3051            }
3052        }
3053        saw_kind
3054    }
3055
3056    /// `true` iff [`Self::preconditions`] carries NO [`Condition`]
3057    /// with the given [`ConditionKind`] AND carries at least one
3058    /// [`Condition`] for every OTHER [`ConditionKind`] — the
3059    /// precondition-side arm of the (precondition, postcondition,
3060    /// condition-union) kind-scoped strict-refinement-on-missing triad
3061    /// on [`Boundary`]. Thin typed delegate to
3062    /// [`ConditionSliceExt::lacks_only_kind`] over
3063    /// [`Self::preconditions`].
3064    ///
3065    /// Peer of [`Self::lacks_only_postcondition_kind`] on the
3066    /// (precondition, postcondition) partition of the boundary's two
3067    /// condition-vector slots; both peers compose against the SAME
3068    /// slice-level substrate primitive so a regression at the per-
3069    /// slice fused walk under complement fails at that primitive's
3070    /// tests rather than as silent drift at either struct-level arm.
3071    #[must_use]
3072    pub fn lacks_only_precondition_kind(&self, kind: ConditionKind) -> bool {
3073        self.preconditions.lacks_only_kind(kind)
3074    }
3075
3076    /// `true` iff [`Self::postconditions`] carries NO [`Condition`]
3077    /// with the given [`ConditionKind`] AND carries at least one
3078    /// [`Condition`] for every OTHER [`ConditionKind`] — the
3079    /// postcondition-side arm of the (precondition, postcondition,
3080    /// condition-union) kind-scoped strict-refinement-on-missing triad
3081    /// on [`Boundary`]. Thin typed delegate to
3082    /// [`ConditionSliceExt::lacks_only_kind`] over
3083    /// [`Self::postconditions`].
3084    ///
3085    /// Peer of [`Self::lacks_only_precondition_kind`]. See that method
3086    /// for the full rationale — the two methods share ONE lift
3087    /// motivation, ONE fail-before-pass-after composition-law pin,
3088    /// and ONE two-surface parity contract with the ephemeral sugar
3089    /// type via
3090    /// [`crate::ephemeral::EphemeralSpec::lacks_only_postcondition_kind`].
3091    #[must_use]
3092    pub fn lacks_only_postcondition_kind(&self, kind: ConditionKind) -> bool {
3093        self.postconditions.lacks_only_kind(kind)
3094    }
3095
3096    /// `true` iff `preconditions ∪ postconditions` carries AT LEAST
3097    /// TWO [`Condition`] values with the given [`ConditionKind`] —
3098    /// the union arm of the (precondition, postcondition, condition-
3099    /// union) per-kind cardinality "≥ 2" many-arm triad on
3100    /// [`Boundary`]. Composes a two-step-short-circuit walk over the
3101    /// chained per-kind iterator [`Self::iter_condition_kind`], which
3102    /// itself chains [`ConditionSliceExt::iter_kind`] over
3103    /// [`Self::preconditions`] then [`Self::postconditions`].
3104    ///
3105    /// Composed body: pulls up to two hits off the chained per-kind
3106    /// iterator; returns `true` iff BOTH the first and the second are
3107    /// [`Some`]. Byte-for-byte peer of
3108    /// [`ConditionSliceExt::has_multiple_of_kind`] one slice-layer
3109    /// down, lifted to compose against the two-slice chain rather
3110    /// than a single slice's `iter_kind`. A regression at either
3111    /// per-slice many-arm walk fails at that primitive's substrate
3112    /// tests + the union composition-law tests rather than as silent
3113    /// drift here.
3114    ///
3115    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_multiple_of_condition_kind`]
3116    ///
3117    /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
3118    /// byte-identical two-step short-circuit body composed against
3119    /// the ephemeral surface's own chained per-kind iterator. Both
3120    /// methods compose against the SAME slice-level substrate
3121    /// primitive [`ConditionSliceExt::has_multiple_of_kind`] via the
3122    /// two-slice chain — a regression at the per-slice many-arm walk
3123    /// fails at that primitive's tests rather than as silent drift
3124    /// at either struct-level `has-multiple-of-<kind>` caller.
3125    ///
3126    /// # Compounding
3127    ///
3128    /// A future operator-facing "duplicate boundary condition
3129    /// detected" audit reads
3130    /// `boundary.has_multiple_of_condition_kind(ConditionKind::ProcessPhase)`
3131    /// at ONE call site rather than restating
3132    /// `boundary.count_condition_kind(kind) >= 2` (which walks every
3133    /// slot on both slices to count) or the pre + post OR-composition
3134    /// with hand-authored short-circuit at every classifier arm.
3135    ///
3136    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
3137    /// preserves proofs — the per-kind cardinality-many-arm projection
3138    /// composes the SAME two-step short-circuit walk over the two-
3139    /// slice chain on both this boundary surface and the ephemeral
3140    /// surface). THEORY.md §VI.1 (generation over composition —
3141    /// a new [`ConditionKind`] variant reaches both surfaces'
3142    /// per-kind-many-arm triads mechanically through the delegated
3143    /// chained iterator).
3144    #[must_use]
3145    pub fn has_multiple_of_condition_kind(&self, kind: ConditionKind) -> bool {
3146        let mut it = self.iter_condition_kind(kind);
3147        it.next().is_some() && it.next().is_some()
3148    }
3149
3150    /// `true` iff [`Self::preconditions`] carries AT LEAST TWO
3151    /// [`Condition`] values with the given [`ConditionKind`] — the
3152    /// precondition-side arm of the (precondition, postcondition,
3153    /// condition-union) per-kind cardinality "≥ 2" many-arm triad
3154    /// on [`Boundary`]. Thin typed delegate to
3155    /// [`ConditionSliceExt::has_multiple_of_kind`] over
3156    /// [`Self::preconditions`].
3157    ///
3158    /// Peer of [`Self::has_multiple_of_postcondition_kind`] on the
3159    /// (precondition, postcondition) partition of the boundary's two
3160    /// condition-vector slots; both peers compose against the SAME
3161    /// slice-level substrate primitive so a regression at the per-
3162    /// slice two-step short-circuit walk fails at that primitive's
3163    /// tests rather than as silent drift at either struct-level arm.
3164    #[must_use]
3165    pub fn has_multiple_of_precondition_kind(&self, kind: ConditionKind) -> bool {
3166        self.preconditions.has_multiple_of_kind(kind)
3167    }
3168
3169    /// `true` iff [`Self::postconditions`] carries AT LEAST TWO
3170    /// [`Condition`] values with the given [`ConditionKind`] — the
3171    /// postcondition-side arm of the (precondition, postcondition,
3172    /// condition-union) per-kind cardinality "≥ 2" many-arm triad
3173    /// on [`Boundary`]. Thin typed delegate to
3174    /// [`ConditionSliceExt::has_multiple_of_kind`] over
3175    /// [`Self::postconditions`].
3176    ///
3177    /// Peer of [`Self::has_multiple_of_precondition_kind`]. See that
3178    /// method for the full rationale — the two methods share ONE
3179    /// lift motivation, ONE fail-before-pass-after composition-law
3180    /// pin, and ONE two-surface parity contract with the ephemeral
3181    /// sugar type via
3182    /// [`crate::ephemeral::EphemeralSpec::has_multiple_of_postcondition_kind`].
3183    #[must_use]
3184    pub fn has_multiple_of_postcondition_kind(&self, kind: ConditionKind) -> bool {
3185        self.postconditions.has_multiple_of_kind(kind)
3186    }
3187
3188    /// `true` iff `preconditions ∪ postconditions` carries EXACTLY
3189    /// ONE [`Condition`] with the given [`ConditionKind`] — the union
3190    /// arm of the (precondition, postcondition, condition-union) per-
3191    /// kind cardinality "= 1" mid-endpoint triad on [`Boundary`].
3192    /// Composes a two-step-short-circuit walk over the chained per-
3193    /// kind iterator [`Self::iter_condition_kind`], which itself
3194    /// chains [`ConditionSliceExt::iter_kind`] over
3195    /// [`Self::preconditions`] then [`Self::postconditions`].
3196    ///
3197    /// Composed body: pulls up to two hits off the chained per-kind
3198    /// iterator; returns `true` iff the first is [`Some`] AND the
3199    /// second is [`None`]. Byte-for-byte peer of
3200    /// [`ConditionSliceExt::has_unique_of_kind`] one slice-layer
3201    /// down, lifted to compose against the two-slice chain rather
3202    /// than a single slice's `iter_kind`. Middle arm of the {= 0,
3203    /// = 1, ≥ 2} per-kind cardinality Boolean trichotomy at the
3204    /// union level: alongside [`Self::lacks_condition_kind`] (= 0)
3205    /// and [`Self::has_multiple_of_condition_kind`] (≥ 2), the three
3206    /// Booleans PARTITION the per-kind cardinality scalar's non-
3207    /// negative-integer arms — EXACTLY ONE fires on any `(boundary,
3208    /// kind)` pair.
3209    ///
3210    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_unique_of_condition_kind`]
3211    ///
3212    /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
3213    /// byte-identical two-step short-circuit body composed against
3214    /// the ephemeral surface's own chained per-kind iterator. Both
3215    /// methods compose against the SAME slice-level substrate
3216    /// primitive [`ConditionSliceExt::has_unique_of_kind`] via the
3217    /// two-slice chain — a regression at the per-slice mid-endpoint
3218    /// walk fails at that primitive's tests rather than as silent
3219    /// drift at either struct-level `has-unique-of-<kind>` caller.
3220    ///
3221    /// # Compounding
3222    ///
3223    /// A future operator-facing "singleton boundary condition
3224    /// detected" audit reads
3225    /// `boundary.has_unique_of_condition_kind(ConditionKind::ProcessPhase)`
3226    /// at ONE call site rather than restating
3227    /// `boundary.count_condition_kind(kind) == 1` (which walks every
3228    /// slot on both slices to count) or the pre + post disjoint-arm
3229    /// OR-composition with hand-authored short-circuit at every
3230    /// classifier arm.
3231    ///
3232    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
3233    /// preserves proofs — the per-kind cardinality-mid-endpoint
3234    /// projection composes the SAME two-step short-circuit walk
3235    /// over the two-slice chain on both this boundary surface and
3236    /// the ephemeral surface). THEORY.md §VI.1 (generation over
3237    /// composition — a new [`ConditionKind`] variant reaches both
3238    /// surfaces' per-kind-mid-endpoint triads mechanically through
3239    /// the delegated chained iterator).
3240    #[must_use]
3241    pub fn has_unique_of_condition_kind(&self, kind: ConditionKind) -> bool {
3242        let mut it = self.iter_condition_kind(kind);
3243        it.next().is_some() && it.next().is_none()
3244    }
3245
3246    /// `true` iff [`Self::preconditions`] carries EXACTLY ONE
3247    /// [`Condition`] with the given [`ConditionKind`] — the
3248    /// precondition-side arm of the (precondition, postcondition,
3249    /// condition-union) per-kind cardinality "= 1" mid-endpoint triad
3250    /// on [`Boundary`]. Thin typed delegate to
3251    /// [`ConditionSliceExt::has_unique_of_kind`] over
3252    /// [`Self::preconditions`].
3253    ///
3254    /// Peer of [`Self::has_unique_of_postcondition_kind`] on the
3255    /// (precondition, postcondition) partition of the boundary's two
3256    /// condition-vector slots; both peers compose against the SAME
3257    /// slice-level substrate primitive so a regression at the per-
3258    /// slice two-step short-circuit walk fails at that primitive's
3259    /// tests rather than as silent drift at either struct-level arm.
3260    #[must_use]
3261    pub fn has_unique_of_precondition_kind(&self, kind: ConditionKind) -> bool {
3262        self.preconditions.has_unique_of_kind(kind)
3263    }
3264
3265    /// `true` iff [`Self::postconditions`] carries EXACTLY ONE
3266    /// [`Condition`] with the given [`ConditionKind`] — the
3267    /// postcondition-side arm of the (precondition, postcondition,
3268    /// condition-union) per-kind cardinality "= 1" mid-endpoint triad
3269    /// on [`Boundary`]. Thin typed delegate to
3270    /// [`ConditionSliceExt::has_unique_of_kind`] over
3271    /// [`Self::postconditions`].
3272    ///
3273    /// Peer of [`Self::has_unique_of_precondition_kind`]. See that
3274    /// method for the full rationale — the two methods share ONE
3275    /// lift motivation, ONE fail-before-pass-after composition-law
3276    /// pin, and ONE two-surface parity contract with the ephemeral
3277    /// sugar type via
3278    /// [`crate::ephemeral::EphemeralSpec::has_unique_of_postcondition_kind`].
3279    #[must_use]
3280    pub fn has_unique_of_postcondition_kind(&self, kind: ConditionKind) -> bool {
3281        self.postconditions.has_unique_of_kind(kind)
3282    }
3283
3284    /// `true` iff `preconditions ∪ postconditions` carries AT MOST
3285    /// ONE [`Condition`] with the given [`ConditionKind`] — the
3286    /// union arm of the (precondition, postcondition, condition-
3287    /// union) per-kind cardinality "≤ 1" negation triad on
3288    /// [`Boundary`]. Closes the {= 0, = 1, ≥ 1, ≥ 2, ≤ 1} Boolean-
3289    /// cardinality grid on the per-kind axis at the union level
3290    /// alongside its sibling [`Self::has_multiple_of_condition_kind`]
3291    /// (≥ 2 many-arm) under the definitional negation
3292    /// `!(≥ 2) == (≤ 1)`. Composes a two-step-short-circuit walk over
3293    /// the chained per-kind iterator [`Self::iter_condition_kind`]
3294    /// via the definitional negation
3295    /// `!self.has_multiple_of_condition_kind(kind)`.
3296    ///
3297    /// Composed body: `!self.has_multiple_of_condition_kind(kind)` —
3298    /// a definitional Boolean negation of the union many-arm
3299    /// primitive. Short-circuits transitively through
3300    /// [`Self::has_multiple_of_condition_kind`]'s two-step short-
3301    /// circuit walk over the chained per-kind iterator: returns
3302    /// `true` as soon as the many-arm walk stops with fewer than
3303    /// two matches, WITHOUT walking every slot to build
3304    /// [`Self::count_condition_kind`]'s scalar. Byte-for-byte peer
3305    /// of [`ConditionSliceExt::has_at_most_one_of_kind`] one slice-
3306    /// layer down, lifted to compose against the two-slice chain
3307    /// rather than a single slice's `iter_kind`.
3308    ///
3309    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_at_most_one_of_condition_kind`]
3310    ///
3311    /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
3312    /// byte-identical definitional-negation body composed against
3313    /// the ephemeral surface's own chained per-kind iterator. Both
3314    /// methods compose against the SAME slice-level substrate
3315    /// primitive [`ConditionSliceExt::has_at_most_one_of_kind`] via
3316    /// the two-slice chain — a regression at the per-slice negation
3317    /// walk fails at that primitive's tests rather than as silent
3318    /// drift at either struct-level `has-at-most-one-of-<kind>`
3319    /// caller.
3320    ///
3321    /// # Compounding
3322    ///
3323    /// A future authoring-time linter that surfaces "boundary
3324    /// condition slice union has no duplicates for kind K" reads
3325    /// `boundary.has_at_most_one_of_condition_kind(K)` at ONE call
3326    /// site rather than restating
3327    /// `!boundary.has_multiple_of_condition_kind(K)` or
3328    /// `boundary.count_condition_kind(K) <= 1` (which walks every
3329    /// slot on both slices to count) at every callsite. A future
3330    /// operator-facing "no-duplicate-of-kind" postcondition-well-
3331    /// formedness check that allows either absence (0 matches) or a
3332    /// single reference (1 match) but rejects duplicates reads this
3333    /// primitive with a single call.
3334    ///
3335    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
3336    /// preserves proofs — the per-kind cardinality-"≤ 1" projection
3337    /// composes the SAME definitional negation shape over the two-
3338    /// slice chain on both this boundary surface and the ephemeral
3339    /// surface). THEORY.md §VI.1 (generation over composition — a
3340    /// new [`ConditionKind`] variant reaches both surfaces' per-
3341    /// kind-"≤ 1" triads mechanically through the delegated chained
3342    /// iterator).
3343    #[must_use]
3344    pub fn has_at_most_one_of_condition_kind(&self, kind: ConditionKind) -> bool {
3345        !self.has_multiple_of_condition_kind(kind)
3346    }
3347
3348    /// `true` iff [`Self::preconditions`] carries AT MOST ONE
3349    /// [`Condition`] with the given [`ConditionKind`] — the
3350    /// precondition-side arm of the (precondition, postcondition,
3351    /// condition-union) per-kind cardinality "≤ 1" negation triad
3352    /// on [`Boundary`]. Thin typed delegate to
3353    /// [`ConditionSliceExt::has_at_most_one_of_kind`] over
3354    /// [`Self::preconditions`].
3355    ///
3356    /// Peer of [`Self::has_at_most_one_of_postcondition_kind`] on
3357    /// the (precondition, postcondition) partition of the
3358    /// boundary's two condition-vector slots; both peers compose
3359    /// against the SAME slice-level substrate primitive so a
3360    /// regression at the per-slice definitional negation walk fails
3361    /// at that primitive's tests rather than as silent drift at
3362    /// either struct-level arm.
3363    #[must_use]
3364    pub fn has_at_most_one_of_precondition_kind(&self, kind: ConditionKind) -> bool {
3365        self.preconditions.has_at_most_one_of_kind(kind)
3366    }
3367
3368    /// `true` iff [`Self::postconditions`] carries AT MOST ONE
3369    /// [`Condition`] with the given [`ConditionKind`] — the
3370    /// postcondition-side arm of the (precondition, postcondition,
3371    /// condition-union) per-kind cardinality "≤ 1" negation triad
3372    /// on [`Boundary`]. Thin typed delegate to
3373    /// [`ConditionSliceExt::has_at_most_one_of_kind`] over
3374    /// [`Self::postconditions`].
3375    ///
3376    /// Peer of [`Self::has_at_most_one_of_precondition_kind`]. See
3377    /// that method for the full rationale — the two methods share
3378    /// ONE lift motivation, ONE fail-before-pass-after composition-
3379    /// law pin, and ONE two-surface parity contract with the
3380    /// ephemeral sugar type via
3381    /// [`crate::ephemeral::EphemeralSpec::has_at_most_one_of_postcondition_kind`].
3382    #[must_use]
3383    pub fn has_at_most_one_of_postcondition_kind(&self, kind: ConditionKind) -> bool {
3384        self.postconditions.has_at_most_one_of_kind(kind)
3385    }
3386
3387    /// Returns the unique [`Condition`] with the given
3388    /// [`ConditionKind`] in `preconditions ∪ postconditions`, or
3389    /// [`None`] if zero or `≥ 2` such [`Condition`]s exist — the
3390    /// union arm of the (precondition, postcondition, condition-
3391    /// union) `Option<&Condition>`-witnessing peer of the Boolean
3392    /// [`Self::has_unique_of_condition_kind`] on the per-kind
3393    /// cardinality "= 1" mid-endpoint at the boundary level.
3394    /// Composed body: a two-step short-circuit walk over the chained
3395    /// per-kind iterator [`Self::iter_condition_kind`] — pulls at
3396    /// most two matches from the pre-then-post chain, returns the
3397    /// first iff no second exists. Byte-for-byte peer of
3398    /// [`ConditionSliceExt::unique_of_kind`] one slice-layer down,
3399    /// lifted to compose against the two-slice chain rather than a
3400    /// single slice's `iter_kind`.
3401    ///
3402    /// Composition laws:
3403    /// - `has_unique_of_condition_kind(k) == unique_of_condition_kind(k).is_some()`
3404    /// - `unique_of_condition_kind(k).map(|c| c.kind) == Some(k)` iff
3405    ///   `has_unique_of_condition_kind(k)`, else `None`.
3406    ///
3407    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::unique_of_condition_kind`]
3408    ///
3409    /// Byte-identical signature `(&Self, ConditionKind) ->
3410    /// Option<&Condition>`, byte-identical two-step short-circuit
3411    /// body composed against the ephemeral surface's own chained
3412    /// per-kind iterator. Both methods compose against the SAME
3413    /// slice-level substrate primitive
3414    /// [`ConditionSliceExt::unique_of_kind`] via the two-slice
3415    /// chain — a regression at the per-slice witness walk fails at
3416    /// that primitive's tests rather than as silent drift at either
3417    /// struct-level `unique-of-<kind>` caller.
3418    ///
3419    /// # Compounding
3420    ///
3421    /// A future coherence check that inspects "the unique
3422    /// [`ConditionKind::ClosedLoopAuth`] postcondition's `issuer`
3423    /// param" reads
3424    /// `boundary.unique_of_condition_kind(ConditionKind::ClosedLoopAuth)`
3425    /// at ONE call site rather than restating
3426    /// `if boundary.has_unique_of_condition_kind(k) { boundary.find_condition_kind(k) } else { None }`
3427    /// (which walks the chain twice) or the pre + post disjoint-arm
3428    /// composition at every classifier arm.
3429    ///
3430    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
3431    /// preserves proofs — the per-kind `Option<&Condition>`
3432    /// witnessing refinement composes the SAME two-step short-
3433    /// circuit walk over the two-slice chain on both this boundary
3434    /// surface and the ephemeral surface). THEORY.md §VI.1
3435    /// (generation over composition — a new [`ConditionKind`]
3436    /// variant reaches both surfaces' per-kind-witness triads
3437    /// mechanically through the delegated chained iterator).
3438    #[must_use]
3439    pub fn unique_of_condition_kind(&self, kind: ConditionKind) -> Option<&Condition> {
3440        let mut it = self.iter_condition_kind(kind);
3441        let first = it.next()?;
3442        match it.next() {
3443            None => Some(first),
3444            Some(_) => None,
3445        }
3446    }
3447
3448    /// Returns the unique [`Condition`] with the given
3449    /// [`ConditionKind`] in [`Self::preconditions`], or [`None`] if
3450    /// zero or `≥ 2` such [`Condition`]s exist — the precondition-
3451    /// side arm of the (precondition, postcondition, condition-
3452    /// union) `Option<&Condition>`-witnessing peer triad on
3453    /// [`Boundary`]. Thin typed delegate to
3454    /// [`ConditionSliceExt::unique_of_kind`] over
3455    /// [`Self::preconditions`].
3456    ///
3457    /// Peer of [`Self::unique_of_postcondition_kind`] on the
3458    /// (precondition, postcondition) partition of the boundary's two
3459    /// condition-vector slots; both peers compose against the SAME
3460    /// slice-level substrate primitive so a regression at the per-
3461    /// slice two-step short-circuit walk fails at that primitive's
3462    /// tests rather than as silent drift at either struct-level arm.
3463    #[must_use]
3464    pub fn unique_of_precondition_kind(&self, kind: ConditionKind) -> Option<&Condition> {
3465        self.preconditions.unique_of_kind(kind)
3466    }
3467
3468    /// Returns the unique [`Condition`] with the given
3469    /// [`ConditionKind`] in [`Self::postconditions`], or [`None`] if
3470    /// zero or `≥ 2` such [`Condition`]s exist — the postcondition-
3471    /// side arm of the (precondition, postcondition, condition-
3472    /// union) `Option<&Condition>`-witnessing peer triad on
3473    /// [`Boundary`]. Thin typed delegate to
3474    /// [`ConditionSliceExt::unique_of_kind`] over
3475    /// [`Self::postconditions`].
3476    ///
3477    /// Peer of [`Self::unique_of_precondition_kind`]. See that method
3478    /// for the full rationale — the two methods share ONE lift
3479    /// motivation, ONE fail-before-pass-after composition-law pin,
3480    /// and ONE two-surface parity contract with the ephemeral sugar
3481    /// type via
3482    /// [`crate::ephemeral::EphemeralSpec::unique_of_postcondition_kind`].
3483    #[must_use]
3484    pub fn unique_of_postcondition_kind(&self, kind: ConditionKind) -> Option<&Condition> {
3485        self.postconditions.unique_of_kind(kind)
3486    }
3487}
3488
3489/// Slice-level `(ConditionKind, presence)` probe on any `&[Condition]`
3490/// — the ONE substrate primitive that owns the
3491/// `.iter().any(|c| c.kind == K)` walk shape both current production
3492/// sites hand-authored past the ★★ PRIME-DIRECTIVE ≥ 2 duplication
3493/// threshold. Callers compose the two-half union at their site
3494/// ([`Boundary::has_condition_kind`] on `preconditions ∪
3495/// postconditions`) or on ONE half only (the ephemeral require-tag
3496/// classifier's `closed-loop-auth` arm on `spec.postconditions`) —
3497/// the primitive owns ONLY the per-slice walk, so the composition
3498/// choice stays typed at the caller.
3499///
3500/// # Why lift
3501///
3502/// Pre-lift the `.iter().any(|c| c.kind == K)` walk lived
3503/// hand-authored at THREE production sites: twice inside
3504/// [`Boundary::has_condition_kind`]'s union (pre + post), once at
3505/// `evaluate_ephemeral_require_tag`'s `closed-loop-auth` arm in
3506/// `tatara-reconciler::bin::tatara-check` (with `matches!` sugar
3507/// instead of `==`, but the same predicate). The (`&[Condition]`,
3508/// `ConditionKind`) → `bool` shape is the substrate primitive: a
3509/// future consumer that walks a `Vec<Condition>` (a coherence check
3510/// that verifies "every `ClosedLoopAuth` postcondition carries an
3511/// `issuer` param key", an editor completion listing which
3512/// [`ConditionKind`] arms appear on ONE side only, a hypothetical
3513/// `postcondition-<kind>` require-tag prefix family that dispatches
3514/// on `postconditions` alone — the peer of the existing
3515/// `condition-<kind>` family that dispatches on the pre ∪ post union
3516/// via [`Boundary::has_condition_kind`]) reaches this ONE primitive
3517/// through `slice.has_kind(k)` instead of restating the `.iter().any`
3518/// closure body.
3519///
3520/// # Sibling to [`Boundary::has_condition_kind`]
3521///
3522/// Same axis, one refinement lower: `Boundary::has_condition_kind` is
3523/// the two-slice-union probe; `has_kind` here is the one-slice probe
3524/// the union composes twice. A future normalization at the presence
3525/// probe shape (widening the return to `Option<&Condition>` for
3526/// deeper diagnostics, adding a debug-build assertion on redundant
3527/// duplicates, switching to a linear scan that also counts matches)
3528/// lands at ONE site here — both [`Boundary::has_condition_kind`] +
3529/// every downstream `slice.has_kind(K)` callsite pick it up
3530/// mechanically.
3531///
3532/// # Compounding
3533///
3534/// [`Self::find_kind`] is the widened primitive returning
3535/// `Option<&Condition>` that both `has_kind` (`self.find_kind(k).
3536/// is_some()`, the default body) and future diagnostic consumers
3537/// compose against. A `has_kind_matching(|&Condition| -> bool)`
3538/// predicate extension similarly lands as ONE new default method on
3539/// this trait — the closed-set discriminator case becomes `has_kind(k)
3540/// == self.has_kind_matching(|c| c.kind == k)` by construction, so a
3541/// regression that drifted one from the other becomes structurally
3542/// impossible past the trait boundary.
3543///
3544/// Theory anchor: THEORY.md §II.1 invariant 5 — composition preserves
3545/// proofs; the per-slice walk lives at ONE substrate site so the
3546/// two-half union in [`Boundary`] and the one-half probe on
3547/// [`crate::ephemeral::EphemeralSpec::postconditions`] compose
3548/// through the SAME primitive. THEORY.md §VI.1 — generation over
3549/// composition; a future `Vec<Condition>` consumer reaches the
3550/// primitive through `slice.has_kind(k)` with no per-caller
3551/// restatement of the `.iter().any(|c| c.kind == K)` closure body.
3552pub trait ConditionSliceExt {
3553    /// Returns an iterator yielding every [`Condition`] in this slice
3554    /// whose [`Condition::kind`] equals `kind`, in slice order — the
3555    /// ONE widened primitive on the slice-level presence-probe axis
3556    /// that both [`Self::find_kind`] (via the default
3557    /// `iter_kind(k).next()` body) and [`Self::has_kind`] (via the
3558    /// transitive `find_kind(k).is_some()` default) compose against.
3559    ///
3560    /// # Sibling to [`Self::find_kind`]
3561    ///
3562    /// One refinement wider: `find_kind` collapses the return to
3563    /// `Option<&Condition>` (yielding only the earliest match);
3564    /// `iter_kind` returns the whole match stream so callers can
3565    /// [`count`](Iterator::count) it, [`collect`](Iterator::collect)
3566    /// it into a `Vec<&Condition>`, ask for the
3567    /// [`nth`](Iterator::nth) element, or compose it with any other
3568    /// std iterator adaptor without re-walking the slice. The default
3569    /// body of `find_kind` is `self.iter_kind(kind).next()` — the
3570    /// two methods share ONE walk semantics by construction, so a
3571    /// regression that drifted the first-match probe from the
3572    /// widened stream becomes structurally impossible past the
3573    /// trait boundary.
3574    ///
3575    /// # Semantics
3576    ///
3577    /// Yields `&c` for each `c` in this slice with `c.kind == kind`,
3578    /// in slice order — a slice that carries multiple matches yields
3579    /// each in turn (the composition law
3580    /// `find_kind(k) == iter_kind(k).next()` binds the first match
3581    /// to the earliest position). An empty slice, or a slice with no
3582    /// matching kind, yields nothing. Byte-for-byte equivalent to
3583    /// `self.iter().filter(|c| c.kind == kind)`.
3584    ///
3585    /// # Compounding
3586    ///
3587    /// A future coherence check that verifies "each
3588    /// [`ConditionKind`] appears at most once per side" reads
3589    /// `slice.iter_kind(k).nth(1).is_none()` at ONE call site
3590    /// rather than restating the count-with-filter closure body.
3591    /// A future diagnostic that enumerates every match of a kind
3592    /// (an operator-facing "3 PromQL preconditions matched" message,
3593    /// an audit dump listing every match of a repeated kind) reaches
3594    /// this ONE primitive through `slice.iter_kind(k).collect()`
3595    /// rather than re-walking the slice with `.iter().filter(...)`
3596    /// at the callsite. The presence-probe axis now carries three
3597    /// refinements (bool via `has_kind`, `Option<&Condition>` via
3598    /// `find_kind`, `impl Iterator<Item = &Condition>` via
3599    /// `iter_kind`) at ONE typed algebra surface — every downstream
3600    /// consumer picks the coarsest one that answers its question and
3601    /// the coarser ones stay compositionally derived from this
3602    /// primitive.
3603    fn iter_kind(&self, kind: ConditionKind) -> KindMatches<'_>;
3604
3605    /// Returns the first [`Condition`] in this slice that carries the
3606    /// given [`ConditionKind`], or `None` if none matches. Default
3607    /// body: `self.iter_kind(kind).next()` — a thin projection of the
3608    /// widened primitive [`Self::iter_kind`] onto its first element.
3609    /// The composition law `find_kind(k) == iter_kind(k).next()`
3610    /// binds the first-match probe to the widened stream at the
3611    /// trait's default body.
3612    ///
3613    /// # Sibling to [`Self::has_kind`]
3614    ///
3615    /// One refinement wider: `has_kind` collapses the return to a
3616    /// `bool`; `find_kind` returns the matching `&Condition` so
3617    /// callers can read [`Condition::params`] without re-walking the
3618    /// slice. The default body of `has_kind` is
3619    /// `self.find_kind(kind).is_some()` — the two methods share ONE
3620    /// walk semantics by construction. Byte-for-byte equivalent to
3621    /// `self.iter().find(|c| c.kind == kind)`.
3622    fn find_kind(&self, kind: ConditionKind) -> Option<&Condition> {
3623        self.iter_kind(kind).next()
3624    }
3625
3626    /// True iff at least one [`Condition`] in this slice carries the
3627    /// given [`ConditionKind`]. Default body: `self.find_kind(kind).
3628    /// is_some()`. The single-slice presence probe both
3629    /// [`Boundary::has_condition_kind`] (twice, in a union) and the
3630    /// ephemeral `closed-loop-auth` require-tag arm (once, on
3631    /// postconditions only) compose against.
3632    fn has_kind(&self, kind: ConditionKind) -> bool {
3633        self.find_kind(kind).is_some()
3634    }
3635
3636    /// Number of [`Condition`]s in this slice carrying the given
3637    /// [`ConditionKind`] — the scalar cardinality refinement on the
3638    /// slice-level presence-probe axis. Default body:
3639    /// `self.iter_kind(kind).count()` — a thin projection of the
3640    /// widened primitive [`Self::iter_kind`] onto its cardinality.
3641    ///
3642    /// # Sibling to [`Self::iter_kind`] / [`Self::find_kind`] / [`Self::has_kind`]
3643    ///
3644    /// Fourth refinement on the presence-probe algebra: `iter_kind`
3645    /// yields the whole match stream, `find_kind` collapses it to the
3646    /// first match, `has_kind` collapses that to a `bool`, and
3647    /// `count_kind` collapses the stream to its cardinality without
3648    /// materializing any intermediate [`Vec`] or `Option`. The
3649    /// composition laws
3650    /// `count_kind(k) == iter_kind(k).count()`,
3651    /// `has_kind(k) == (count_kind(k) > 0)`, and
3652    /// `find_kind(k).is_some() == (count_kind(k) > 0)`
3653    /// share ONE walk semantics by construction; a regression that
3654    /// drifted the cardinality probe from the widened stream becomes
3655    /// structurally impossible past the trait boundary.
3656    ///
3657    /// # Semantics
3658    ///
3659    /// Returns `self.iter().filter(|c| c.kind == kind).count()` — a
3660    /// slice that carries multiple matches returns that count, an
3661    /// empty slice or a slice with no matching kind returns `0`.
3662    ///
3663    /// # Compounding
3664    ///
3665    /// A future coherence check that verifies "each [`ConditionKind`]
3666    /// appears at most once per side" now reads
3667    /// `slice.count_kind(k) <= 1` at ONE call site rather than
3668    /// restating either `slice.iter_kind(k).nth(1).is_none()` or the
3669    /// `iter_kind(k).count() <= 1` idiom. A future require-tag
3670    /// classifier arm that surfaces multiplicity to the operator
3671    /// (a hypothetical `condition-count-<kind>` prefix family that
3672    /// publishes the raw cardinality, an audit dump reporting "3
3673    /// PromQL preconditions matched") reaches this ONE primitive
3674    /// through `slice.count_kind(k)` rather than restating the
3675    /// `.iter_kind(k).count()` chain body at the callsite. The
3676    /// presence-probe axis now carries FOUR refinements at ONE typed
3677    /// algebra surface — every downstream consumer picks the coarsest
3678    /// one that answers its question and the coarser ones stay
3679    /// compositionally derived from [`Self::iter_kind`].
3680    fn count_kind(&self, kind: ConditionKind) -> usize {
3681        self.iter_kind(kind).count()
3682    }
3683
3684    /// The set of [`ConditionKind`] variants that appear at least once in
3685    /// this slice, projected in [`ConditionKind::ALL`] order — the
3686    /// closed-set-inversion refinement on the slice-level presence-probe
3687    /// axis. Default body: `ConditionKind::ALL.into_iter().filter(|k|
3688    /// self.has_kind(*k)).collect()` — a thin projection over the closed
3689    /// set that composes against [`Self::has_kind`] per variant.
3690    ///
3691    /// # Sibling to [`Self::has_kind`] / [`Self::find_kind`] / [`Self::iter_kind`] / [`Self::count_kind`]
3692    ///
3693    /// FIFTH refinement on the presence-probe algebra, distinct in axis
3694    /// from the other four: `has_kind` / `find_kind` / `iter_kind` /
3695    /// `count_kind` fix a [`ConditionKind`] and vary the return type
3696    /// (bool / `Option<&Condition>` / `impl Iterator<Item = &Condition>` /
3697    /// `usize`); this refinement INVERTS the axis by fixing the slice and
3698    /// varying over [`ConditionKind::ALL`], returning the SET of present
3699    /// kinds. The composition law
3700    /// `distinct_kinds().contains(&k) == has_kind(k)` for every
3701    /// `k ∈ ConditionKind::ALL` binds the closed-set-inversion probe to
3702    /// the point probe at the trait's default body.
3703    ///
3704    /// # Semantics — canonical subsequence of [`ConditionKind::ALL`]
3705    ///
3706    /// Returns a `Vec<ConditionKind>` whose elements appear in
3707    /// [`ConditionKind::ALL`] order with no duplicates. A slice that
3708    /// carries the same [`ConditionKind`] at multiple positions
3709    /// contributes ONE entry to the returned set (the closed-set
3710    /// projection collapses multiplicity — a caller that needs the
3711    /// per-kind cardinality reaches for [`Self::count_kind`]). An
3712    /// empty slice, or a slice with no matching kind under any
3713    /// [`ConditionKind::ALL`] variant, returns an empty vec.
3714    ///
3715    /// # Why closed-set-inversion is a distinct axis
3716    ///
3717    /// The other four refinements answer "for THIS kind, how does the
3718    /// slice populate the probe's return type?"; this refinement
3719    /// answers "for THIS slice, which kinds appear at least once?".
3720    /// A consumer that needs to enumerate every present kind for an
3721    /// audit dump (`"boundary carries [PromQL, ClosedLoopAuth]"`), a
3722    /// coherence check that verifies "every process's boundary carries
3723    /// at least ONE of {`JobAttested`, `ClosedLoopAuth`}", or a
3724    /// require-tag family that surfaces the distinct-set as a whole
3725    /// (`condition-kinds-distinct-count`) reaches this refinement
3726    /// rather than paying for a per-kind sweep with `has_kind` at the
3727    /// callsite. The point probe stays composable one axis over
3728    /// (`slice.has_kind(k)` for a fixed `k`); the aggregate refinement
3729    /// lives at the same trait, one axis away.
3730    ///
3731    /// # Compounding
3732    ///
3733    /// A future coherence check that enforces "every boundary carries
3734    /// at least ONE distinct kind" (a warning surfaced when
3735    /// `boundary.distinct_condition_kinds().is_empty()`) reaches this
3736    /// ONE primitive rather than paying for the eight-way
3737    /// `for k in ConditionKind::ALL { if boundary.has_condition_kind(k)
3738    /// { return true; } }` sweep at every callsite. A future require-
3739    /// tag classifier arm that publishes the distinct-set cardinality
3740    /// as a scalar (a hypothetical `condition-kinds-distinct-<n>`
3741    /// prefix family, an audit dump reporting "boundary carries N
3742    /// distinct kinds") reaches this ONE primitive through
3743    /// `boundary.distinct_condition_kinds().len()` rather than
3744    /// restating the closed-set-inverted `.iter().filter(...).count()`
3745    /// idiom at every callsite. The presence-probe axis now carries
3746    /// FIVE refinements at ONE typed algebra surface — the four point-
3747    /// probes fixing a kind AND the ONE closed-set-inversion probe
3748    /// fixing a slice — every downstream consumer picks the one that
3749    /// answers its question and the others stay compositionally
3750    /// derived from the single-source-of-truth widened primitive.
3751    ///
3752    /// # Theory grounding
3753    ///
3754    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3755    ///   The closed-set-inversion projection lives at ONE substrate
3756    ///   site as a typed projection of [`Self::has_kind`] over the
3757    ///   closed set [`ConditionKind::ALL`]. Every downstream aggregate
3758    ///   consumer binds through the SAME shape rather than restating
3759    ///   the ALL-filter closure body.
3760    /// - THEORY.md §VI.1 — generation over composition. A new
3761    ///   [`ConditionKind`] variant added to `ALL` reaches this
3762    ///   primitive mechanically (the closed-set walk picks up the new
3763    ///   entry) and every downstream consumer sees the wider set
3764    ///   without further per-caller edit.
3765    fn distinct_kinds(&self) -> Vec<ConditionKind> {
3766        self.iter_distinct_kinds().collect()
3767    }
3768
3769    /// Zero-allocation iterator peer of [`Self::distinct_kinds`] — walk
3770    /// [`ConditionKind::ALL`] in canonical order and yield every
3771    /// [`ConditionKind`] whose corresponding slot on this slice is
3772    /// populated (at least one [`Condition`] with that kind), WITHOUT
3773    /// materializing an intermediate [`Vec<ConditionKind>`].
3774    ///
3775    /// Default body:
3776    /// `ConditionKind::ALL.iter().copied().filter(|&k| self.has_kind(k))`.
3777    /// The composition law
3778    /// `distinct_kinds() == iter_distinct_kinds().collect::<Vec<_>>()`
3779    /// holds by construction — [`Self::distinct_kinds`]'s default body IS
3780    /// `self.iter_distinct_kinds().collect()`, so a caller that overrides
3781    /// the widened Vec primitive with a divergent walk simultaneously
3782    /// drifts both surfaces (surfacing at the substrate testkit
3783    /// [`assert_slice_refinement_composition_laws`] which pins the Vec
3784    /// projection equals `iter().collect()`).
3785    ///
3786    /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
3787    ///
3788    /// Load-bearing iterator peer of the slice-level closed-set-inversion
3789    /// axis — where `distinct_kinds` returns the SET (heap-allocated
3790    /// `Vec`, canonical `ConditionKind::ALL` order) and
3791    /// `distinct_kind_count` scalar-projects its cardinality,
3792    /// `iter_distinct_kinds` opens the walk as a `Copy` iterator so
3793    /// consumers that need a short-circuiting fold (`.any(|k| pred(k))`,
3794    /// `.find(|&k| pred(k))`, `.take_while(|k| pred(k))`, `.map(|k|
3795    /// project(k))`) avoid the intermediate allocation entirely.
3796    ///
3797    /// # Peer to [`crate::tagged_union::TaggedUnion::iter_populated_kinds`]
3798    ///
3799    /// Same shape at the peer axis one struct layer up: where
3800    /// `iter_populated_kinds` opens the closed-set-inversion walk on the
3801    /// tagged-union parent-level presence-probe axis,
3802    /// `iter_distinct_kinds` opens the closed-set-inversion walk on the
3803    /// slice-level presence-probe axis. Both close the "load-bearing
3804    /// iterator" refinement at two adjacent typescape sites through the
3805    /// SAME `<CLOSED_SET>::ALL.iter().copied().filter(|&k| has_probe(k))`
3806    /// composition body under a POSITIVE point-probe.
3807    ///
3808    /// # Compounding future consumers
3809    ///
3810    /// - Every scalar closed-set-inversion peer already at the trait
3811    ///   (`distinct_kind_count`, `first_distinct_kind`,
3812    ///   `last_distinct_kind`, `unique_distinct_kind`,
3813    ///   `has_any_distinct_kind`) folds a specialization of
3814    ///   `ConditionKind::ALL.iter().filter(|k| self.has_kind(**k))` —
3815    ///   they can compose over `iter_distinct_kinds()` at ONE substrate
3816    ///   site rather than restating the closed-set walk body per peer.
3817    /// - A downstream diagnostic composer (an operator-facing "boundary
3818    ///   carries: [{}]" message that streams the label list into a
3819    ///   `write!` buffer) reads `slice.iter_distinct_kinds().map(|k|
3820    ///   k.label())` and folds through `itertools::join` without the
3821    ///   allocation `Vec<ConditionKind> -> String` pays.
3822    ///
3823    /// # Theory grounding
3824    ///
3825    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3826    ///   The load-bearing iterator projection lives at ONE substrate
3827    ///   site; every downstream aggregate consumer refines it through a
3828    ///   standard-library iterator fold rather than restating the
3829    ///   [`ConditionKind::ALL`]-walk closure body.
3830    /// - THEORY.md §VI.1 — generation over composition. A new
3831    ///   [`ConditionKind`] variant added to `ALL` reaches the walk
3832    ///   mechanically (the closed-set filter picks up the new entry) and
3833    ///   every downstream fold sees the wider set without further
3834    ///   per-caller edit.
3835    fn iter_distinct_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
3836        ConditionKind::ALL
3837            .iter()
3838            .copied()
3839            .filter(|&k| self.has_kind(k))
3840    }
3841
3842    /// Scalar cardinality projection of [`Self::distinct_kinds`] onto
3843    /// its `.len()` — the number of [`ConditionKind`] variants that
3844    /// appear at least once in this slice. Default body:
3845    /// `ConditionKind::ALL.iter().filter(|k| self.has_kind(**k)).count()`
3846    /// — a closed-set walk that composes against [`Self::has_kind`] per
3847    /// variant WITHOUT materializing an intermediate `Vec<ConditionKind>`.
3848    /// A slice that carries the same [`ConditionKind`] at multiple
3849    /// positions contributes `1` to the count (the closed-set projection
3850    /// collapses multiplicity — a caller that needs the per-kind
3851    /// cardinality reaches for [`Self::count_kind`]).
3852    ///
3853    /// # Sibling to [`Self::distinct_kinds`]
3854    ///
3855    /// Scalar projection of the closed-set-inversion widened primitive
3856    /// — where `distinct_kinds` returns the SET (a `Vec<ConditionKind>`
3857    /// in canonical [`ConditionKind::ALL`] order), `distinct_kind_count`
3858    /// collapses that set to its cardinality. The composition law
3859    /// `distinct_kind_count() == distinct_kinds().len()` binds the
3860    /// scalar projection to the widened primitive at the trait's
3861    /// default body and is swept substrate-wide by
3862    /// [`assert_slice_refinement_composition_laws`] as its sixth arm.
3863    ///
3864    /// # Peer to [`crate::tagged_union::TaggedUnion::populated_kind_count`]
3865    ///
3866    /// Same shape at the peer axis one struct layer up: where
3867    /// `populated_kind_count` scalar-projects `populated_kinds` on the
3868    /// tagged-union parent-level closed-set-inversion axis,
3869    /// `distinct_kind_count` scalar-projects `distinct_kinds` on the
3870    /// slice-level closed-set-inversion axis. The two primitives close
3871    /// the scalar-cardinality refinement at two adjacent typescape
3872    /// sites — one per closed-set-addressed slice-level refinement,
3873    /// one per closed-set-addressed tagged-union parent-level
3874    /// refinement — through the SAME `ClosedSet::ALL`-walk shape.
3875    ///
3876    /// # Compounding future consumers
3877    ///
3878    /// - A future coherence check that enforces "every boundary carries
3879    ///   at least ONE distinct kind" now reads
3880    ///   `slice.distinct_kind_count() > 0` at ONE call site rather than
3881    ///   paying for `slice.distinct_kinds().len() > 0` (with its
3882    ///   intermediate heap allocation) or the eight-way sweep with
3883    ///   `has_kind` at the callsite.
3884    /// - A future require-tag classifier arm that surfaces the
3885    ///   distinct-set cardinality as a scalar (a hypothetical
3886    ///   `condition-kinds-distinct-<n>` prefix family named in
3887    ///   [`Self::distinct_kinds`]'s doc-comment as a compounding-future
3888    ///   consumer) reaches this ONE primitive without allocating.
3889    /// - A future audit dump reporting "boundary carries N distinct
3890    ///   kinds" reaches `slice.distinct_kind_count()` directly rather
3891    ///   than restating the `.iter().filter(...).count()` closure body.
3892    ///
3893    /// # Theory grounding
3894    ///
3895    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3896    ///   The scalar cardinality lives at ONE substrate site as a typed
3897    ///   projection of [`Self::distinct_kinds`] onto its `.len()`, and
3898    ///   the default body composes against [`Self::has_kind`] over the
3899    ///   closed set [`ConditionKind::ALL`] byte-identically to
3900    ///   `distinct_kinds` without the intermediate `Vec`. Every
3901    ///   downstream aggregate consumer binds through the SAME shape
3902    ///   rather than paying for the allocation to reach the
3903    ///   cardinality.
3904    /// - THEORY.md §VI.1 — generation over composition. A new
3905    ///   [`ConditionKind`] variant added to `ALL` reaches this
3906    ///   primitive mechanically (the closed-set walk picks up the new
3907    ///   entry) and every downstream consumer sees the wider
3908    ///   cardinality without further per-caller edit.
3909    fn distinct_kind_count(&self) -> usize {
3910        self.iter_distinct_kinds().count()
3911    }
3912
3913    /// The set of [`ConditionKind`] variants that do NOT appear in this
3914    /// slice, projected in [`ConditionKind::ALL`] order — the closed-
3915    /// set-inversion COMPLEMENT of [`Self::distinct_kinds`]. Default
3916    /// body: `ConditionKind::ALL.into_iter().filter(|k|
3917    /// !self.has_kind(*k)).collect()` — a thin projection over the
3918    /// closed set that composes against [`Self::has_kind`] per variant
3919    /// under a negated predicate.
3920    ///
3921    /// # Sibling to [`Self::distinct_kinds`]
3922    ///
3923    /// Complement peer of the closed-set-inversion widened primitive on
3924    /// the slice-level presence-probe axis. Where `distinct_kinds`
3925    /// returns the SET of kinds that DO appear at least once,
3926    /// `missing_kinds` returns the SET of kinds that DO NOT appear.
3927    /// Both walk [`ConditionKind::ALL`] in canonical order and compose
3928    /// against the same [`Self::has_kind`] point probe. The two
3929    /// widened primitives PARTITION [`ConditionKind::ALL`]: their union
3930    /// equals `ConditionKind::ALL`, their intersection is empty, and
3931    /// their cardinalities sum to `ConditionKind::ALL.len()` — three
3932    /// composition laws pinned as the seventh, eighth, and ninth arms
3933    /// of the substrate testkit
3934    /// [`assert_slice_refinement_composition_laws`].
3935    ///
3936    /// # Peer to [`crate::tagged_union::TaggedUnion::populated_kinds`]'s
3937    /// hypothetical `unpopulated_kinds` complement
3938    ///
3939    /// Same shape at the peer axis one struct layer up: fixing the
3940    /// parent-side carrier and inverting the presence probe over the
3941    /// closed set. The two primitives close the "closed-set complement"
3942    /// refinement at two adjacent typescape sites — one per closed-set-
3943    /// addressed slice-level refinement (this primitive), one per
3944    /// closed-set-addressed tagged-union parent-level refinement (a
3945    /// symmetric future addition).
3946    ///
3947    /// # Semantics — canonical subsequence of [`ConditionKind::ALL`]
3948    ///
3949    /// Returns a `Vec<ConditionKind>` whose elements appear in
3950    /// [`ConditionKind::ALL`] order with no duplicates. An empty slice
3951    /// returns `ConditionKind::ALL.to_vec()` (every kind is missing).
3952    /// A slice that carries every variant returns an empty vec (no kind
3953    /// is missing). A slice that carries the same [`ConditionKind`] at
3954    /// multiple positions still contributes ZERO entries to the missing
3955    /// set at that kind (the closed-set complement is a SET operation —
3956    /// multiplicity on the present side is irrelevant to absence on the
3957    /// missing side).
3958    ///
3959    /// # Compounding future consumers
3960    ///
3961    /// - A future coherence check that enforces "every process boundary
3962    ///   carries a [`ConditionKind::JobAttested`] postcondition" now
3963    ///   surfaces the operator-facing diagnostic
3964    ///   `spec.boundary.postconditions.missing_kinds()` verbatim
3965    ///   (naming EVERY kind absent from postconditions in canonical
3966    ///   order) rather than reaching for `!has_kind(JobAttested)` at a
3967    ///   per-kind callsite and paying to re-author the diagnostic list.
3968    /// - An operator-facing "boundary is MISSING [JobAttested,
3969    ///   ClosedLoopAuth]" audit dump reads
3970    ///   `boundary.postconditions.missing_kinds()` directly at ONE call
3971    ///   site rather than restating the negated closed-set walk at
3972    ///   every consumer.
3973    /// - A fleet-wide gap analysis ("which processes are missing a
3974    ///   `ClosedLoopAuth` postcondition") reaches this ONE primitive
3975    ///   through `spec.boundary.postconditions.missing_kinds()
3976    ///   .contains(&ConditionKind::ClosedLoopAuth)` rather than paying
3977    ///   for the negated `.has_kind` sweep at every callsite.
3978    /// - A hypothetical `condition-kinds-missing-<n>` require-tag
3979    ///   classifier prefix family that publishes the missing-set
3980    ///   cardinality as a scalar reads
3981    ///   [`Self::missing_kind_count`] (the scalar-cardinality peer of
3982    ///   this widened primitive) without allocating.
3983    ///
3984    /// # Theory grounding
3985    ///
3986    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3987    ///   The closed-set complement lives at ONE substrate site as a
3988    ///   typed projection of [`Self::has_kind`] over the closed set
3989    ///   [`ConditionKind::ALL`] under negation. Every downstream gap-
3990    ///   analysis consumer binds through the SAME shape rather than
3991    ///   restating the negated ALL-filter closure body.
3992    /// - THEORY.md §VI.1 — generation over composition. A new
3993    ///   [`ConditionKind`] variant added to `ALL` reaches this
3994    ///   primitive mechanically (the closed-set walk picks up the new
3995    ///   entry on the missing side WITHOUT further per-caller edit —
3996    ///   any slice that doesn't yet populate the new kind sees it
3997    ///   listed as missing at every downstream callsite).
3998    fn missing_kinds(&self) -> Vec<ConditionKind> {
3999        self.iter_missing_kinds().collect()
4000    }
4001
4002    /// Zero-allocation iterator peer of [`Self::missing_kinds`] — walk
4003    /// [`ConditionKind::ALL`] in canonical order and yield every
4004    /// [`ConditionKind`] whose corresponding slot on this slice is EMPTY
4005    /// (no [`Condition`] in the slice carries that kind), WITHOUT
4006    /// materializing an intermediate [`Vec<ConditionKind>`].
4007    ///
4008    /// Default body:
4009    /// `ConditionKind::ALL.iter().copied().filter(|&k| !self.has_kind(k))`.
4010    /// The composition law
4011    /// `missing_kinds() == iter_missing_kinds().collect::<Vec<_>>()`
4012    /// holds by construction — [`Self::missing_kinds`]'s default body IS
4013    /// `self.iter_missing_kinds().collect()`, so a caller that overrides
4014    /// the widened Vec primitive with a divergent walk simultaneously
4015    /// drifts both surfaces (surfacing at the substrate testkit
4016    /// [`assert_slice_refinement_composition_laws`] which pins the Vec
4017    /// projection equals `iter().collect()`).
4018    ///
4019    /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
4020    ///
4021    /// Load-bearing iterator peer of the slice-level closed-set-complement
4022    /// axis — where `missing_kinds` returns the SET (heap-allocated `Vec`,
4023    /// canonical `ConditionKind::ALL` order) and `missing_kind_count`
4024    /// scalar-projects its cardinality, `iter_missing_kinds` opens the
4025    /// walk as a `Copy` iterator so consumers that need a short-
4026    /// circuiting fold avoid the intermediate allocation entirely.
4027    ///
4028    /// # Peer to [`Self::iter_distinct_kinds`]
4029    ///
4030    /// Closed-set-COMPLEMENT peer under a NEGATED point-probe. The two
4031    /// iterators PARTITION `ConditionKind::ALL`:
4032    /// `iter_distinct_kinds().chain(iter_missing_kinds()).collect::<HashSet<_>>()`
4033    /// equals `ConditionKind::ALL.iter().copied().collect()`, and the two
4034    /// iterators yield disjoint element sets.
4035    ///
4036    /// # Peer to [`crate::tagged_union::TaggedUnion::iter_missing_kinds`]
4037    ///
4038    /// Same shape at the peer axis one struct layer up: where
4039    /// `iter_missing_kinds` on the tagged-union parent opens the closed-
4040    /// set-complement walk under a negated `has` point-probe, this method
4041    /// opens the SAME walk on the slice-level presence-probe axis under a
4042    /// negated `has_kind` point-probe. Both close the "load-bearing
4043    /// iterator on the complement side" refinement at two adjacent
4044    /// typescape sites through the SAME
4045    /// `<CLOSED_SET>::ALL.iter().copied().filter(|&k| !has_probe(k))`
4046    /// composition body.
4047    ///
4048    /// # Compounding future consumers
4049    ///
4050    /// - Every scalar closed-set-complement peer already at the trait
4051    ///   (`missing_kind_count`, `first_missing_kind`, `last_missing_kind`,
4052    ///   `unique_missing_kind`, `is_kind_saturated`,
4053    ///   `has_any_missing_kind`, `has_unique_missing_kind`,
4054    ///   `has_multiple_missing_kinds`, `has_at_most_one_missing_kind`)
4055    ///   folds a specialization of
4056    ///   `ConditionKind::ALL.iter().filter(|k| !self.has_kind(**k))` —
4057    ///   they can compose over `iter_missing_kinds()` at ONE substrate
4058    ///   site rather than restating the closed-set walk body per peer.
4059    /// - A downstream diagnostic composer (an operator-facing "still
4060    ///   missing: [{}]" message that streams the label list into a
4061    ///   `write!` buffer on the partially-populated arm) reads
4062    ///   `slice.iter_missing_kinds().map(|k| k.label())` and folds through
4063    ///   `itertools::join` without the allocation `Vec<ConditionKind> ->
4064    ///   String` pays.
4065    ///
4066    /// # Theory grounding
4067    ///
4068    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4069    ///   The load-bearing iterator projection on the complement side
4070    ///   lives at ONE substrate site, byte-for-byte symmetrical with
4071    ///   [`Self::iter_distinct_kinds`] under a negated `has_kind`
4072    ///   predicate.
4073    /// - THEORY.md §VI.1 — generation over composition. A new
4074    ///   [`ConditionKind`] variant added to `ALL` reaches the walk
4075    ///   mechanically (the closed-set filter picks up the new entry on
4076    ///   the missing side) and every downstream fold sees the wider
4077    ///   complement without further per-caller edit.
4078    fn iter_missing_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
4079        ConditionKind::ALL
4080            .iter()
4081            .copied()
4082            .filter(|&k| !self.has_kind(k))
4083    }
4084
4085    /// Scalar cardinality projection of [`Self::missing_kinds`] onto its
4086    /// `.len()` — the number of [`ConditionKind`] variants that do NOT
4087    /// appear in this slice. Default body:
4088    /// `ConditionKind::ALL.iter().filter(|k| !self.has_kind(**k)).count()`
4089    /// — a closed-set walk composed against [`Self::has_kind`] per variant
4090    /// under a NEGATED point-probe, WITHOUT materializing the intermediate
4091    /// `Vec<ConditionKind>` a caller reaching only for the scalar
4092    /// cardinality otherwise pays for. An empty slice returns
4093    /// `ConditionKind::ALL.len()` (every kind is missing); a slice
4094    /// carrying every variant returns `0` (no kind is missing).
4095    ///
4096    /// # Sibling to [`Self::missing_kinds`] / [`Self::distinct_kind_count`]
4097    ///
4098    /// Scalar projection of the closed-set-complement widened primitive
4099    /// — where `missing_kinds` returns the SET (a `Vec<ConditionKind>`
4100    /// in canonical [`ConditionKind::ALL`] order), `missing_kind_count`
4101    /// collapses that set to its cardinality. The composition law
4102    /// `missing_kind_count() == missing_kinds().len()` binds the scalar
4103    /// projection to the widened primitive at the trait's default body
4104    /// and is swept substrate-wide by
4105    /// [`assert_slice_refinement_composition_laws`] as its scalar-
4106    /// cardinality-complement arm.
4107    ///
4108    /// Byte-for-byte peer of [`Self::distinct_kind_count`] one axis over
4109    /// (under a negated `has_kind` predicate): where `distinct_kind_count`
4110    /// scalar-projects the closed-set-INVERSION widened primitive
4111    /// `distinct_kinds`, this method scalar-projects the closed-set-
4112    /// COMPLEMENT widened primitive `missing_kinds`. The two scalar
4113    /// projections PARTITION the closed-set cardinality:
4114    /// `distinct_kind_count() + missing_kind_count() ==
4115    /// ConditionKind::ALL.len()` — the scalar consequence of the
4116    /// `(distinct_kinds, missing_kinds)` partition law that
4117    /// [`assert_slice_refinement_composition_laws`] pins at the
4118    /// widened-primitive layer.
4119    ///
4120    /// # Peer to [`crate::tagged_union::TaggedUnion::populated_kind_count`]'s
4121    /// hypothetical complement peer
4122    ///
4123    /// Same shape at the peer axis one struct layer up: fixing the
4124    /// slice-side carrier and inverting the presence probe over the
4125    /// closed set under a negated predicate. The two primitives close
4126    /// the "closed-set-complement scalar cardinality" refinement at
4127    /// two adjacent typescape sites — one per closed-set-addressed
4128    /// slice-level refinement (this primitive), one per closed-set-
4129    /// addressed tagged-union parent-level refinement (a symmetric
4130    /// future addition).
4131    ///
4132    /// # Compounding future consumers
4133    ///
4134    /// - A future coherence check that enforces "every process boundary
4135    ///   carries EVERY [`ConditionKind`] under some slot" now reads
4136    ///   `spec.boundary.postconditions.missing_kind_count() == 0` at
4137    ///   ONE call site rather than paying for
4138    ///   `spec.boundary.postconditions.missing_kinds().is_empty()`
4139    ///   (with its intermediate heap allocation) or the eight-way
4140    ///   negated sweep with `has_kind` at the callsite.
4141    /// - A future require-tag classifier arm that surfaces the missing-
4142    ///   set cardinality as a scalar (the exact
4143    ///   `condition-kinds-missing-<n>` require-tag classifier prefix
4144    ///   family called out in [`Self::missing_kinds`]'s doc-comment as
4145    ///   a hypothetical compounding-future consumer) reaches this ONE
4146    ///   primitive without allocating.
4147    /// - A future gap-analysis dashboard reporting "boundary is missing
4148    ///   N of {N_TOTAL} distinct kinds" reaches
4149    ///   `slice.missing_kind_count()` directly rather than restating the
4150    ///   negated `.iter().filter(...).count()` closure body.
4151    ///
4152    /// # Theory grounding
4153    ///
4154    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4155    ///   The scalar cardinality lives at ONE substrate site as a typed
4156    ///   projection of [`Self::missing_kinds`] onto its `.len()`, and
4157    ///   the default body composes against [`Self::has_kind`] over the
4158    ///   closed set [`ConditionKind::ALL`] under negation byte-
4159    ///   identically to `missing_kinds` without the intermediate `Vec`.
4160    ///   Every downstream aggregate consumer binds through the SAME
4161    ///   shape rather than paying for the allocation to reach the
4162    ///   cardinality.
4163    /// - THEORY.md §VI.1 — generation over composition. A new
4164    ///   [`ConditionKind`] variant added to `ALL` reaches this primitive
4165    ///   mechanically (the closed-set walk picks up the new entry on
4166    ///   the missing side WITHOUT further per-caller edit — any slice
4167    ///   that doesn't yet populate the new kind sees the cardinality
4168    ///   rise by one at every downstream callsite).
4169    fn missing_kind_count(&self) -> usize {
4170        self.iter_missing_kinds().count()
4171    }
4172
4173    /// Short-circuiting `Option<ConditionKind>` peer of
4174    /// [`Self::distinct_kinds`] — the FIRST [`ConditionKind`] variant
4175    /// present in this slice, in canonical [`ConditionKind::ALL`] order,
4176    /// or `None` when the slice carries no matching kind. Default body:
4177    /// `ConditionKind::ALL.iter().copied().find(|k| self.has_kind(*k))`
4178    /// — a closed-set walk composed against [`Self::has_kind`] per
4179    /// variant that SHORT-CIRCUITS at the earliest match.
4180    ///
4181    /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
4182    ///
4183    /// Third refinement on the closed-set-inversion axis, `Option<ConditionKind>`-
4184    /// valued: `distinct_kinds` returns the SET, `distinct_kind_count`
4185    /// scalar-projects the cardinality, and `first_distinct_kind`
4186    /// scalar-projects the SET onto its earliest element. The composition
4187    /// law `first_distinct_kind() == distinct_kinds().first().copied()`
4188    /// binds the earliest-element projection to the widened primitive at
4189    /// the trait's default body — pinned substrate-wide by
4190    /// [`assert_slice_refinement_composition_laws`] as its
4191    /// earliest-element-inversion arm. Both coarser projections agree on
4192    /// emptiness: `first_distinct_kind().is_none() ==
4193    /// (distinct_kind_count() == 0)`.
4194    ///
4195    /// # Peer to [`crate::tagged_union::TaggedUnion::first_populated_kind`]
4196    ///
4197    /// Same shape at the peer axis one struct layer up: fixing the
4198    /// carrier and short-circuiting on the earliest [`ConditionKind::ALL`]
4199    /// hit under [`Self::has_kind`]. `TaggedUnion::first_populated_kind`
4200    /// walks the tagged-union parent's closed set; `first_distinct_kind`
4201    /// here walks [`ConditionKind::ALL`] on the slice-level presence-probe
4202    /// axis. The two primitives close the "earliest-element scalar-
4203    /// projection of the closed-set-inversion widened primitive"
4204    /// refinement at two adjacent typescape sites — one per closed-set-
4205    /// addressed slice-level refinement (this primitive), one per closed-
4206    /// set-addressed tagged-union parent-level refinement.
4207    ///
4208    /// # Semantics
4209    ///
4210    /// Returns `Some(k)` where `k` is the earliest [`ConditionKind::ALL`]
4211    /// entry with `self.has_kind(k) == true`, or `None` when no kind is
4212    /// present. An empty slice returns `None`. A slice carrying multiple
4213    /// variants returns the earliest one in [`ConditionKind::ALL`] order
4214    /// — a strictly more informative projection than
4215    /// `distinct_kinds().first().copied()` without materializing the
4216    /// intermediate `Vec<ConditionKind>` the widened primitive
4217    /// otherwise pays for.
4218    ///
4219    /// # Compounding future consumers
4220    ///
4221    /// - An operator-facing "first present kind" diagnostic on an audit
4222    ///   dump that names ONE kind rather than the full set reaches this
4223    ///   ONE substrate site rather than paying for
4224    ///   `slice.distinct_kinds().first().copied()` (with its
4225    ///   intermediate heap allocation).
4226    /// - A `first-distinct-<kind>` require-tag classifier arm reads this
4227    ///   primitive with no allocation, byte-for-byte symmetrical with
4228    ///   `slice.has_kind(kind)` under a closed-set-inversion projection.
4229    /// - A fast-path branch that discriminates "empty" from "any
4230    ///   populated" reads `slice.first_distinct_kind().is_some()` at ONE
4231    ///   call site rather than allocating a `Vec<ConditionKind>` through
4232    ///   `!distinct_kinds().is_empty()` or paying for the full
4233    ///   `distinct_kind_count() > 0` walk.
4234    ///
4235    /// # Theory grounding
4236    ///
4237    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs. The
4238    ///   earliest-element projection lives at ONE substrate site as a
4239    ///   typed projection of [`Self::has_kind`] over the closed set
4240    ///   [`ConditionKind::ALL`] under short-circuit walk semantics.
4241    /// - THEORY.md §VI.1 — generation over composition. A new
4242    ///   [`ConditionKind`] variant added to `ALL` reaches this primitive
4243    ///   mechanically (the closed-set walk picks up the new entry) —
4244    ///   every downstream consumer sees the wider earliest-hit projection
4245    ///   without further per-caller edit.
4246    fn first_distinct_kind(&self) -> Option<ConditionKind> {
4247        self.iter_distinct_kinds().next()
4248    }
4249
4250    /// Short-circuiting `Option<ConditionKind>` peer of
4251    /// [`Self::missing_kinds`] — the FIRST [`ConditionKind`] variant
4252    /// ABSENT from this slice, in canonical [`ConditionKind::ALL`] order,
4253    /// or `None` when the slice carries every variant. Default body:
4254    /// `ConditionKind::ALL.iter().copied().find(|k| !self.has_kind(*k))`
4255    /// — a closed-set walk composed against [`Self::has_kind`] per
4256    /// variant under NEGATION with SHORT-CIRCUIT at the earliest empty
4257    /// slot.
4258    ///
4259    /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
4260    ///
4261    /// Third refinement on the closed-set-complement axis,
4262    /// `Option<ConditionKind>`-valued: `missing_kinds` returns the SET,
4263    /// `missing_kind_count` scalar-projects the cardinality, and
4264    /// `first_missing_kind` scalar-projects the SET onto its earliest
4265    /// element. The composition law
4266    /// `first_missing_kind() == missing_kinds().first().copied()` binds
4267    /// the earliest-element projection to the widened primitive at the
4268    /// trait's default body — pinned substrate-wide by
4269    /// [`assert_slice_refinement_composition_laws`] as its
4270    /// earliest-element-complement arm. Both coarser projections agree
4271    /// on saturation: `first_missing_kind().is_none() ==
4272    /// (missing_kind_count() == 0)`.
4273    ///
4274    /// # Peer to [`Self::first_distinct_kind`]
4275    ///
4276    /// Closed-set-complement peer of the closed-set-inversion earliest-
4277    /// element primitive under a negated `has_kind` predicate. The two
4278    /// primitives PARTITION [`ConditionKind::ALL`]'s earliest-element
4279    /// projection: at least one of `first_distinct_kind()` and
4280    /// `first_missing_kind()` is `Some` on any non-degenerate closed set
4281    /// (both are `Some` iff `1 ≤ distinct_kind_count() <
4282    /// ConditionKind::ALL.len()`; only the distinct-side is `Some` on a
4283    /// saturated slice; only the missing-side is `Some` on an empty
4284    /// slice).
4285    ///
4286    /// # Peer to [`crate::tagged_union::TaggedUnion::first_missing_kind`]
4287    ///
4288    /// Same shape at the peer axis one struct layer up under a negated
4289    /// predicate. The two primitives close the "earliest-element scalar-
4290    /// projection of the closed-set-complement widened primitive"
4291    /// refinement at two adjacent typescape sites — one per closed-set-
4292    /// addressed slice-level refinement (this primitive), one per closed-
4293    /// set-addressed tagged-union parent-level refinement.
4294    ///
4295    /// # Semantics
4296    ///
4297    /// An empty slice returns `Some(ConditionKind::ALL[0])` (every kind
4298    /// missing, first hit is index 0). A slice populating exactly `k`
4299    /// returns `Some(ConditionKind::ALL[0])` if `k != ALL[0]`, else
4300    /// `Some(ALL[1])` (the earliest non-`k` entry). A saturated slice
4301    /// carrying every variant returns `None`.
4302    ///
4303    /// # Compounding future consumers
4304    ///
4305    /// - An operator-facing "first still-unfilled kind" diagnostic on a
4306    ///   partially-populated boundary reads
4307    ///   `boundary.postconditions.first_missing_kind()` at ONE substrate
4308    ///   site — a strictly-more-informative projection than
4309    ///   `!has_kind(JobAttested)` at a per-kind callsite for a fleet-wide
4310    ///   "which processes are missing at least one closed-loop kind"
4311    ///   audit.
4312    /// - A `first-missing-<kind>` require-tag classifier arm reads this
4313    ///   primitive with no allocation, byte-for-byte symmetrical with
4314    ///   `slice.first_distinct_kind()`.
4315    /// - A fast-path branch that discriminates "saturated" from "at least
4316    ///   one missing" reads `slice.first_missing_kind().is_some()` at ONE
4317    ///   call site rather than allocating through
4318    ///   `!missing_kinds().is_empty()` or paying for the full
4319    ///   `missing_kind_count() > 0` walk.
4320    ///
4321    /// # Theory grounding
4322    ///
4323    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs. The
4324    ///   complement-earliest-element projection lives at ONE substrate
4325    ///   site as a typed projection of [`Self::has_kind`] over the
4326    ///   closed set [`ConditionKind::ALL`] under negation with short-
4327    ///   circuit walk semantics.
4328    /// - THEORY.md §VI.1 — generation over composition. A new
4329    ///   [`ConditionKind`] variant added to `ALL` reaches this primitive
4330    ///   mechanically (the closed-set walk picks up the new entry on the
4331    ///   missing side) — every downstream consumer sees the wider
4332    ///   complement's earliest hit without further per-caller edit.
4333    fn first_missing_kind(&self) -> Option<ConditionKind> {
4334        self.iter_missing_kinds().next()
4335    }
4336
4337    /// Short-circuiting `Option<ConditionKind>` peer of
4338    /// [`Self::distinct_kinds`] — the LAST [`ConditionKind`] variant
4339    /// present in this slice, in canonical [`ConditionKind::ALL`]
4340    /// order, or `None` when the slice carries no variant. Default
4341    /// body: `ConditionKind::ALL.iter().rev().copied().find(|k|
4342    /// self.has_kind(*k))` — a REVERSED closed-set walk composed
4343    /// against [`Self::has_kind`] per variant that SHORT-CIRCUITS at
4344    /// the latest hit.
4345    ///
4346    /// # Sibling to [`Self::distinct_kinds`] /
4347    /// [`Self::distinct_kind_count`] / [`Self::first_distinct_kind`]
4348    ///
4349    /// Fourth refinement on the closed-set-inversion axis and second
4350    /// scalar `Option<ConditionKind>` projection: `distinct_kinds`
4351    /// returns the SET, `distinct_kind_count` scalar-projects the
4352    /// cardinality, `first_distinct_kind` scalar-projects the SET
4353    /// onto its earliest element, and `last_distinct_kind` scalar-
4354    /// projects the SET onto its latest element. The composition law
4355    /// `last_distinct_kind() == distinct_kinds().last().copied()`
4356    /// binds the latest-element projection to the widened primitive
4357    /// at the trait's default body — pinned substrate-wide by
4358    /// [`assert_slice_refinement_composition_laws`] as its
4359    /// latest-element-inversion arm. Both scalar projections agree on
4360    /// emptiness: `last_distinct_kind().is_none() ==
4361    /// first_distinct_kind().is_none() == distinct_kinds().is_empty()`.
4362    ///
4363    /// # Peer to [`Self::first_distinct_kind`]
4364    ///
4365    /// Time-reversed peer under the SAME `has_kind` predicate: where
4366    /// `first_distinct_kind` walks [`ConditionKind::ALL`] forward and
4367    /// SHORT-CIRCUITS at the earliest hit, this primitive walks the
4368    /// SAME closed set in reverse and SHORT-CIRCUITS at the latest
4369    /// hit. The two primitives close the "endpoint scalar-projection
4370    /// of the closed-set-inversion widened primitive" refinement pair
4371    /// at one substrate site — one per endpoint. On a slice with
4372    /// exactly one distinct kind both projections agree; on a slice
4373    /// with distinct-kind-count ≥ 2 they yield distinct results
4374    /// (the earliest and latest elements of the closed-set-inversion
4375    /// respectively).
4376    ///
4377    /// # Semantics
4378    ///
4379    /// An empty slice returns `None` (no kind present, no hit on any
4380    /// walk direction). A slice populating exactly `k` returns
4381    /// `Some(k)` (single hit; earliest = latest). A saturated slice
4382    /// carrying every variant returns `Some(ConditionKind::ALL.last()
4383    /// .unwrap())` (the last ALL entry hits at the earliest walk step
4384    /// of the reversed walk).
4385    ///
4386    /// # Compounding future consumers
4387    ///
4388    /// - A `last-distinct-<kind>` require-tag classifier arm reads
4389    ///   the latest-populated kind through this ONE substrate
4390    ///   primitive with no allocation, byte-for-byte symmetrical with
4391    ///   the earliest-hit `slice.first_distinct_kind()` peer.
4392    /// - A future coherence check that surfaces "boundary ends with
4393    ///   ClosedLoopAuth" reads
4394    ///   `spec.boundary.postconditions.last_distinct_kind() ==
4395    ///   Some(ConditionKind::ClosedLoopAuth)` at ONE call site rather
4396    ///   than paying for `spec.boundary.postconditions
4397    ///   .distinct_kinds().last() == Some(&…)` with its intermediate
4398    ///   heap allocation.
4399    /// - Combined with [`Self::first_distinct_kind`], operator
4400    ///   diagnostics that render a "populated-kind range" summary
4401    ///   (`first..=last` on the closed-set-inversion projection) read
4402    ///   the two endpoints through TWO substrate primitives at
4403    ///   symmetric shapes without allocating.
4404    ///
4405    /// # Theory grounding
4406    ///
4407    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4408    ///   The latest-element projection lives at ONE substrate site as
4409    ///   a typed projection of [`Self::has_kind`] over the closed set
4410    ///   [`ConditionKind::ALL`] under REVERSED short-circuit walk
4411    ///   semantics; byte-for-byte peer of the earliest-element
4412    ///   projection under FORWARD walk semantics.
4413    /// - THEORY.md §VI.1 — generation over composition. A new
4414    ///   [`ConditionKind`] variant added to `ALL` reaches this
4415    ///   primitive mechanically (the reversed closed-set walk picks
4416    ///   up the new entry at the appropriate position) — every
4417    ///   downstream consumer sees the wider latest-hit projection
4418    ///   without further per-caller edit.
4419    fn last_distinct_kind(&self) -> Option<ConditionKind> {
4420        self.iter_distinct_kinds().last()
4421    }
4422
4423    /// Short-circuiting `Option<ConditionKind>` peer of
4424    /// [`Self::missing_kinds`] — the LAST [`ConditionKind`] variant
4425    /// ABSENT from this slice, in canonical [`ConditionKind::ALL`]
4426    /// order, or `None` when the slice carries every variant. Default
4427    /// body: `ConditionKind::ALL.iter().rev().copied().find(|k|
4428    /// !self.has_kind(*k))` — a REVERSED closed-set walk composed
4429    /// against [`Self::has_kind`] per variant under NEGATION with
4430    /// SHORT-CIRCUIT at the latest empty slot.
4431    ///
4432    /// # Sibling to [`Self::missing_kinds`] /
4433    /// [`Self::missing_kind_count`] / [`Self::first_missing_kind`]
4434    ///
4435    /// Fourth refinement on the closed-set-complement axis and second
4436    /// scalar `Option<ConditionKind>` projection: `missing_kinds`
4437    /// returns the SET, `missing_kind_count` scalar-projects the
4438    /// cardinality, `first_missing_kind` scalar-projects the SET onto
4439    /// its earliest element, and `last_missing_kind` scalar-projects
4440    /// the SET onto its latest element. The composition law
4441    /// `last_missing_kind() == missing_kinds().last().copied()` binds
4442    /// the latest-element projection to the widened primitive at the
4443    /// trait's default body — pinned substrate-wide by
4444    /// [`assert_slice_refinement_composition_laws`] as its
4445    /// latest-element-complement arm. Both scalar projections agree
4446    /// on saturation: `last_missing_kind().is_none() ==
4447    /// first_missing_kind().is_none() == missing_kinds().is_empty()`.
4448    ///
4449    /// # Peer to [`Self::first_missing_kind`]
4450    ///
4451    /// Time-reversed peer under the SAME negated `has_kind` predicate:
4452    /// where `first_missing_kind` walks [`ConditionKind::ALL`] forward
4453    /// under negation and SHORT-CIRCUITS at the earliest empty slot,
4454    /// this primitive walks the SAME closed set in reverse and SHORT-
4455    /// CIRCUITS at the latest empty slot. The two primitives close
4456    /// the "endpoint scalar-projection of the closed-set-complement
4457    /// widened primitive" refinement pair at one substrate site.
4458    ///
4459    /// # Peer to [`Self::last_distinct_kind`]
4460    ///
4461    /// Closed-set-complement peer of the closed-set-inversion latest-
4462    /// element primitive under a NEGATED `has_kind` predicate. Along
4463    /// with [`Self::first_distinct_kind`] and [`Self::first_missing_kind`]
4464    /// the four scalar-endpoint projections partition the endpoint
4465    /// axis into (present, absent) × (earliest, latest) — every
4466    /// endpoint-addressable coherence check reads ONE of the four at
4467    /// ONE call site, never the full `Vec<ConditionKind>` walk.
4468    ///
4469    /// # Semantics
4470    ///
4471    /// An empty slice returns `Some(ConditionKind::ALL.last().unwrap())`
4472    /// (every kind missing, latest hit is the last ALL entry). A slice
4473    /// populating exactly `k` returns `Some(ALL.last().unwrap())` if
4474    /// `k != ALL.last().unwrap()`, else `Some(ALL[ALL.len() - 2])` (the
4475    /// latest non-`k` entry). A saturated slice carrying every variant
4476    /// returns `None`.
4477    ///
4478    /// # Compounding future consumers
4479    ///
4480    /// - An operator-facing "last still-unfilled kind" diagnostic on a
4481    ///   partially-populated boundary reads
4482    ///   `boundary.postconditions.last_missing_kind()` at ONE substrate
4483    ///   site — a strictly-more-informative projection than
4484    ///   `!has_kind(ClosedLoopAuth)` at a per-kind callsite for a
4485    ///   fleet-wide "which processes are latest-missing a specific
4486    ///   closed-loop kind" audit.
4487    /// - A `last-missing-<kind>` require-tag classifier arm reads this
4488    ///   primitive with no allocation, byte-for-byte symmetrical with
4489    ///   the earliest-hit `slice.first_missing_kind()` peer.
4490    /// - Combined with [`Self::first_missing_kind`], a coherence check
4491    ///   that renders a "missing-kind range" summary reads the two
4492    ///   endpoints through TWO substrate primitives at symmetric
4493    ///   shapes without allocating through `missing_kinds()`.
4494    ///
4495    /// # Theory grounding
4496    ///
4497    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4498    ///   The complement-latest-element projection lives at ONE
4499    ///   substrate site as a typed projection of [`Self::has_kind`]
4500    ///   over the closed set [`ConditionKind::ALL`] under negation
4501    ///   with REVERSED short-circuit walk semantics; byte-for-byte
4502    ///   peer of the complement-earliest-element projection under
4503    ///   FORWARD walk semantics.
4504    /// - THEORY.md §VI.1 — generation over composition. A new
4505    ///   [`ConditionKind`] variant added to `ALL` reaches this
4506    ///   primitive mechanically (the reversed closed-set walk picks
4507    ///   up the new entry on the missing side at the appropriate
4508    ///   position) — every downstream consumer sees the wider
4509    ///   complement's latest hit without further per-caller edit.
4510    fn last_missing_kind(&self) -> Option<ConditionKind> {
4511        self.iter_missing_kinds().last()
4512    }
4513
4514    /// Boolean saturation predicate on the closed-set-inversion axis —
4515    /// `true` iff EVERY [`ConditionKind::ALL`] variant appears at least
4516    /// once in this slice (equivalently, [`Self::missing_kinds`] is
4517    /// empty).
4518    ///
4519    /// Default body:
4520    /// `ConditionKind::ALL.iter().all(|k| self.has_kind(*k))` — a
4521    /// SHORT-CIRCUITING closed-set walk composed against [`Self::has_kind`]
4522    /// per variant that returns `false` at the FIRST missing kind,
4523    /// WITHOUT materializing [`Self::missing_kinds`]'s `Vec` and WITHOUT
4524    /// walking every entry to build [`Self::missing_kind_count`]'s
4525    /// scalar. Strictly cheaper than either widened primitive on every
4526    /// partially-populated arm (returns at the first empty slot rather
4527    /// than sweeping the full closed set).
4528    ///
4529    /// # Peer to [`crate::tagged_union::TaggedUnion::is_saturated`]
4530    ///
4531    /// Slice-level peer of the tagged-union parent-level saturation
4532    /// predicate one struct-layer up: where `is_saturated` names the
4533    /// tagged-union arm where every `<Self::Kind as ClosedSet>::ALL`
4534    /// slot is populated, `is_kind_saturated` names the slice arm where
4535    /// every [`ConditionKind::ALL`] variant appears at least once. Both
4536    /// short-circuit at the first missing entry under the SAME
4537    /// `<CLOSED_SET>::ALL.iter().all(has)` walk shape at two adjacent
4538    /// typescape sites.
4539    ///
4540    /// # Sibling to [`Self::missing_kind_count`] / [`Self::missing_kinds`]
4541    ///
4542    /// Boolean cardinality-endpoint peer of the scalar cardinality
4543    /// primitive on the closed-set-complement axis — where
4544    /// `missing_kind_count` returns the FULL scalar (any `usize` in
4545    /// `0..=ConditionKind::ALL.len()`), `is_kind_saturated` collapses
4546    /// that scalar to its zero-arm Boolean projection. The composition
4547    /// law `is_kind_saturated() == (missing_kind_count() == 0)` binds
4548    /// the Boolean projection to the scalar primitive at the trait's
4549    /// default body — swept substrate-wide by
4550    /// [`assert_slice_refinement_composition_laws`] as its
4551    /// saturation-endpoint arm.
4552    ///
4553    /// # Semantics
4554    ///
4555    /// An empty slice returns `false` (no kind is populated). A slice
4556    /// carrying a strict subset of [`ConditionKind::ALL`] returns
4557    /// `false`. A slice that carries every variant at least once
4558    /// (multiplicity is irrelevant) returns `true` — the SOLE arm
4559    /// where `is_kind_saturated` returns `true`.
4560    ///
4561    /// # Compounding future consumers
4562    ///
4563    /// - A future coherence check that enforces "every process boundary
4564    ///   exhaustively covers every [`ConditionKind`]" reads
4565    ///   `boundary.postconditions.is_kind_saturated()` at ONE call site
4566    ///   — one short-circuit walk, no allocation, no scalar equality
4567    ///   comparison against `ConditionKind::ALL.len()`.
4568    /// - An `is-kind-saturated` require-tag classifier arm reaches this
4569    ///   primitive with no allocation, byte-for-byte peer of the
4570    ///   tagged-union `is-saturated` classifier one struct-layer up.
4571    /// - A fleet-wide gap-analysis dashboard fast-path that discriminates
4572    ///   "boundary spans every kind" from "boundary is missing some
4573    ///   kind" reads `boundary.postconditions.is_kind_saturated()` at
4574    ///   ONE call site rather than restating either
4575    ///   `boundary.postconditions.missing_kind_count() == 0` (which
4576    ///   walks every slot to count) or
4577    ///   `boundary.postconditions.missing_kinds().is_empty()` (which
4578    ///   allocates the Vec before the emptiness check).
4579    ///
4580    /// # Theory grounding
4581    ///
4582    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4583    ///   The saturation-endpoint projection lives at ONE substrate
4584    ///   site as a typed short-circuiting closed-set walk
4585    ///   `ConditionKind::ALL.iter().all(has_kind)`. Every downstream
4586    ///   consumer binds through the SAME shape rather than restating
4587    ///   the `== ConditionKind::ALL.len()` scalar composition body.
4588    /// - THEORY.md §VI.1 — generation over composition. A new
4589    ///   [`ConditionKind`] variant added to `ALL` reaches this
4590    ///   primitive mechanically through the `all` short-circuit — a
4591    ///   slice that was previously saturated is no longer saturated
4592    ///   at every downstream callsite unless it also carries the new
4593    ///   variant.
4594    fn is_kind_saturated(&self) -> bool {
4595        self.iter_missing_kinds().next().is_none()
4596    }
4597
4598    /// Boolean cardinality zero-endpoint peer of [`Self::is_kind_saturated`]
4599    /// on the closed-set-inversion axis — `true` iff NO
4600    /// [`ConditionKind::ALL`] variant appears in this slice (equivalently,
4601    /// [`Self::distinct_kinds`] is empty, [`Self::distinct_kind_count`]
4602    /// `== 0`, and [`Self::first_distinct_kind`] is [`None`]).
4603    ///
4604    /// Default body: `self.iter_distinct_kinds().next().is_none()` — a
4605    /// SHORT-CIRCUITING closed-set walk composed against the load-bearing
4606    /// distinct iterator that returns `true` iff the first hit is [`None`],
4607    /// WITHOUT materializing [`Self::distinct_kinds`]'s `Vec`, WITHOUT
4608    /// walking every slot to build [`Self::distinct_kind_count`]'s scalar,
4609    /// and WITHOUT allocating the closed-set-inversion scan. Strictly
4610    /// cheaper than either widened primitive on every arm because the
4611    /// walk short-circuits at the first present kind on the has-side
4612    /// walk rather than paying for the Vec allocation or the full
4613    /// cardinality count.
4614    ///
4615    /// # Peer to [`crate::tagged_union::TaggedUnion::is_empty`]
4616    ///
4617    /// Slice-level peer of the tagged-union parent-level zero-endpoint
4618    /// predicate one struct-layer up: where
4619    /// [`crate::tagged_union::TaggedUnion::is_empty`] answers "is EVERY
4620    /// slot on the tagged-union parent empty?", `is_kind_empty` answers
4621    /// "does NO kind appear in ANY condition of the slice?". Both
4622    /// short-circuit at the first present entry under the SAME
4623    /// `<CLOSED_SET>::ALL.iter().any(has)`-then-negate walk shape at two
4624    /// adjacent typescape sites — the two primitives close the zero-
4625    /// endpoint on the closed-set-inversion axis at both struct layers
4626    /// under the SAME shape.
4627    ///
4628    /// # Sibling to [`Self::is_kind_saturated`]
4629    ///
4630    /// Axis-parity mirror of the closed-set-complement saturation-
4631    /// endpoint primitive on the closed-set-inversion axis — where
4632    /// `is_kind_saturated` returns `true` iff `missing_kind_count == 0`
4633    /// (every kind PRESENT), `is_kind_empty` returns `true` iff
4634    /// `distinct_kind_count == 0` (every kind ABSENT). Together the two
4635    /// Booleans name the (empty, saturated) endpoints of the
4636    /// (distinct, missing) partition: a slice is EMPTY iff
4637    /// `is_kind_empty()` returns `true` (equivalently, `is_kind_saturated
4638    /// == false` AND no partial-populated arm applies); a slice is
4639    /// SATURATED iff `is_kind_saturated()` returns `true`. On any `N ≥ 1`
4640    /// closed set, at most ONE of the two returns `true`; on `N == 0`
4641    /// closed sets both return `true` vacuously. Byte-for-byte peer of
4642    /// the tagged-union `is_empty` / `is_saturated` sibling pair one
4643    /// struct-layer up.
4644    ///
4645    /// # Sibling to [`Self::has_any_distinct_kind`]
4646    ///
4647    /// Boolean zero-endpoint peer of the at-least-one halfspace primitive
4648    /// on the closed-set-inversion axis — where `has_any_distinct_kind`
4649    /// returns `true` iff at least one kind is PRESENT, `is_kind_empty`
4650    /// returns its Boolean-negation: `true` iff `distinct_kind_count == 0`.
4651    /// Together the two Booleans partition the distinct-cardinality
4652    /// closed set: exactly one of `is_kind_empty()` and
4653    /// `has_any_distinct_kind()` is `true` for every slice. The
4654    /// definitional negation law `is_kind_empty() == !has_any_distinct_kind()`
4655    /// is pinned as a first-class typed invariant by
4656    /// [`assert_slice_refinement_composition_laws`] as its zero-endpoint
4657    /// arm on the distinct axis, byte-for-byte peer of the missing-axis
4658    /// pin `has_any_missing_kind() == !is_kind_saturated()`.
4659    ///
4660    /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
4661    ///
4662    /// Boolean zero-endpoint peer of the widened + scalar closed-set-
4663    /// inversion primitives — where `distinct_kinds` returns the FULL
4664    /// distinct SET and `distinct_kind_count` returns its cardinality,
4665    /// `is_kind_empty` collapses either the widened primitive to its
4666    /// emptiness Boolean or the scalar to its `== 0` cardinality-endpoint
4667    /// Boolean. The composition laws
4668    /// `is_kind_empty() == distinct_kinds().is_empty()` and
4669    /// `is_kind_empty() == (distinct_kind_count() == 0)` bind this
4670    /// Boolean projection to the widened + scalar primitives at the
4671    /// trait's default body — strictly cheaper than either widened
4672    /// primitive on every non-empty arm because the walk short-circuits
4673    /// at the first present kind rather than allocating the closed-set-
4674    /// inversion scan or walking every slot to build the scalar
4675    /// cardinality.
4676    ///
4677    /// # Semantics
4678    ///
4679    /// An empty slice returns `true` — the SOLE arm where `is_kind_empty`
4680    /// returns `true` on any `N ≥ 1` closed set, byte-for-byte peer of
4681    /// the SOLE arm where `is_kind_saturated` returns `true` (a slice
4682    /// carrying every variant at least once). A slice carrying a strict
4683    /// subset of [`ConditionKind::ALL`] returns `false`. A saturated
4684    /// slice returns `false` on `N ≥ 1` closed sets. Multiplicity is
4685    /// irrelevant on both sides — the predicate collapses to the
4686    /// distinct-set's emptiness.
4687    ///
4688    /// # Compounding future consumers
4689    ///
4690    /// - A fleet-wide "no coverage at all" fast-path that discriminates
4691    ///   "the slice is empty" from "the slice carries at least one kind"
4692    ///   reads `boundary.postconditions.is_kind_empty()` at ONE call site
4693    ///   rather than restating `distinct_kind_count() == 0` (which walks
4694    ///   every slot to count), `distinct_kinds().is_empty()` (which
4695    ///   allocates the Vec before the emptiness check), or negating
4696    ///   `has_any_distinct_kind()` at the callsite.
4697    /// - An `is-kind-empty` require-tag classifier arm reaches this
4698    ///   primitive with no allocation, byte-for-byte peer of the
4699    ///   tagged-union `is-empty` classifier one struct-layer up under
4700    ///   the SAME zero-endpoint short-circuit shape.
4701    /// - A coherence check that flags "any process boundary whose
4702    ///   postcondition slice is empty" reads
4703    ///   `boundary.postconditions.is_kind_empty()` at ONE substrate
4704    ///   primitive per test rather than restating the emptiness body at
4705    ///   every callsite.
4706    ///
4707    /// # Theory grounding
4708    ///
4709    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4710    ///   The zero-endpoint projection on the closed-set-inversion axis
4711    ///   lives at ONE substrate site as a short-circuiting closed-set
4712    ///   walk over the load-bearing distinct iterator. Every downstream
4713    ///   consumer whose semantic reading is "no kind is present" reads
4714    ///   through this primitive rather than paying for the widened
4715    ///   primitive's Vec allocation, the scalar counter's full-slot
4716    ///   walk, or the negation-at-callsite of the at-least-one halfspace
4717    ///   primitive.
4718    /// - THEORY.md §VI.1 — generation over composition. A new
4719    ///   [`ConditionKind`] variant added to `ALL` reaches this primitive
4720    ///   mechanically through the load-bearing distinct iterator — an
4721    ///   empty slice (returning `true` here) that later picks up any
4722    ///   variant flips to `false` at every downstream `is-kind-empty`
4723    ///   callsite. Byte-for-byte symmetrical with the wider-set
4724    ///   propagation on `is_kind_saturated` under the (distinct, missing)
4725    ///   axis-parity.
4726    fn is_kind_empty(&self) -> bool {
4727        self.iter_distinct_kinds().next().is_none()
4728    }
4729
4730    /// Boolean cardinality parent-state middle-arm peer of
4731    /// [`Self::is_kind_empty`] and [`Self::is_kind_saturated`] on the
4732    /// closed-set-partition axis — `true` iff AT LEAST ONE
4733    /// [`ConditionKind::ALL`] variant appears at least once in this slice
4734    /// AND AT LEAST ONE [`ConditionKind::ALL`] variant is absent from every
4735    /// condition (equivalently, `0 < distinct_kind_count < ConditionKind::ALL.len()`
4736    /// and `0 < missing_kind_count < ConditionKind::ALL.len()`).
4737    ///
4738    /// Default body: a FUSED short-circuit closed-set walk over
4739    /// [`ConditionKind::ALL`] that flips a two-bit `(has_present,
4740    /// has_missing)` witness on each kind under [`Self::has_kind`] and
4741    /// returns `true` at the FIRST kind whose flip closes both bits,
4742    /// WITHOUT materializing [`Self::distinct_kinds`] or
4743    /// [`Self::missing_kinds`], WITHOUT walking every slot to build
4744    /// [`Self::distinct_kind_count`] or [`Self::missing_kind_count`],
4745    /// and WITHOUT allocating a two-Vec negation-of-both-endpoints
4746    /// composition at the callsite. Byte-for-byte cheaper than the
4747    /// widened negation composition
4748    /// `!self.is_kind_empty() && !self.is_kind_saturated()` (which pays
4749    /// two separate `ALL`-length short-circuit walks on saturated /
4750    /// empty arms) on every arm where the FIRST and SECOND slot kinds
4751    /// bracket the closed set on opposite bits — the fused walk exits
4752    /// on the SECOND slot of `ConditionKind::ALL` whenever the two
4753    /// pass-side bits close, cheaper than either widened primitive on
4754    /// the mid-arm sweep.
4755    ///
4756    /// # Peer to [`crate::tagged_union::TaggedUnion::is_partially_populated`]
4757    ///
4758    /// Slice-level peer of the tagged-union parent-level middle-arm
4759    /// predicate one struct-layer up: where
4760    /// [`crate::tagged_union::TaggedUnion::is_partially_populated`]
4761    /// answers "is SOME slot on the tagged-union parent occupied AND
4762    /// SOME slot missing?", `is_kind_partially_covered` answers "does
4763    /// SOME kind appear in AT LEAST ONE condition of the slice AND SOME
4764    /// kind APPEAR IN NONE?". Both compose against a FUSED
4765    /// short-circuit closed-set walk under the SAME presence predicate
4766    /// (`has(kind)` / `has_kind(kind)`) at two adjacent typescape sites
4767    /// — the two primitives close the parent-state middle-arm on the
4768    /// closed-set partition at both struct layers under the SAME shape.
4769    /// The trichotomy partition law
4770    /// `usize::from(is_kind_empty()) +
4771    /// usize::from(is_kind_partially_covered()) +
4772    /// usize::from(is_kind_saturated()) == 1` on any `N ≥ 1` closed
4773    /// set is pinned as a first-class typed invariant by
4774    /// [`assert_slice_refinement_composition_laws`] as its parent-state
4775    /// trichotomy arm, byte-for-byte peer of
4776    /// [`crate::tagged_union::assert_is_partially_populated_matches_cardinality`]
4777    /// one struct-layer up.
4778    ///
4779    /// # Sibling to [`Self::is_kind_empty`] / [`Self::is_kind_saturated`]
4780    ///
4781    /// Third and final arm of the `(empty, partially covered, saturated)`
4782    /// parent-state trichotomy on the closed-set-partition axis at the
4783    /// slice level, closing the natural partition alongside
4784    /// `is_kind_empty` (=0 zero-endpoint on the distinct axis) and
4785    /// `is_kind_saturated` (=0 zero-endpoint on the missing axis).
4786    /// Every slice satisfies EXACTLY ONE of the three Boolean
4787    /// projections on any `N ≥ 1` closed set — the three primitives
4788    /// partition the (distinct_kind_count, missing_kind_count) product
4789    /// at (0, N), (open interval, open interval), and (N, 0)
4790    /// respectively.
4791    ///
4792    /// # Composition laws
4793    ///
4794    /// - `is_kind_partially_covered() == !is_kind_empty() && !is_kind_saturated()`
4795    ///   — the negation-of-both-endpoints composition, at the trait
4796    ///   default body's SAME fused short-circuit walk.
4797    /// - `is_kind_partially_covered() == has_any_distinct_kind() && has_any_missing_kind()`
4798    ///   — the paired at-least-one-halfspace composition binding this
4799    ///   Boolean projection to the at-least-one halfspace peers on both
4800    ///   axes.
4801    /// - `is_kind_partially_covered() == (distinct_kind_count() > 0 && missing_kind_count() > 0)`
4802    ///   — the paired scalar-projection composition binding this
4803    ///   Boolean projection to the widened + scalar peers on both axes.
4804    ///
4805    /// # Semantics
4806    ///
4807    /// An empty slice returns `false` (0 distinct + N missing hits the
4808    /// `is_kind_empty` arm, not the middle arm). A slice carrying a
4809    /// strict subset of [`ConditionKind::ALL`] returns `true` on any
4810    /// `N ≥ 2` closed set (some kind present, some absent). A saturated
4811    /// slice returns `false` (N distinct + 0 missing hits the
4812    /// `is_kind_saturated` arm, not the middle arm). Multiplicity is
4813    /// irrelevant on both sides — the predicate collapses to
4814    /// non-emptiness of both the distinct SET and the missing SET.
4815    ///
4816    /// # Compounding future consumers
4817    ///
4818    /// - A boundary-progress "some kinds covered, some pending"
4819    ///   diagnostic on a Boundary slice reads
4820    ///   `boundary.postconditions.is_kind_partially_covered()` at ONE
4821    ///   substrate site — the exact "in-flight coverage" arm — rather
4822    ///   than composing
4823    ///   `!boundary.postconditions.is_kind_empty() && !boundary.postconditions.is_kind_saturated()`
4824    ///   (two closed-set walks) or
4825    ///   `boundary.postconditions.distinct_kind_count() > 0 && boundary.postconditions.missing_kind_count() > 0`
4826    ///   (two counter walks with no short-circuit).
4827    /// - A fleet-wide "mixed coverage" fast-path that discriminates
4828    ///   "partial" from "empty or saturated" reads this primitive with
4829    ///   ONE fused short-circuit walk, strictly cheaper than either
4830    ///   widened composition.
4831    /// - An `is-kind-partially-covered` require-tag classifier arm
4832    ///   reaches this primitive at ONE call site, byte-for-byte
4833    ///   symmetrical with the sibling `is-kind-empty` /
4834    ///   `is-kind-saturated` arms on the closed parent-state trichotomy.
4835    ///
4836    /// # Theory grounding
4837    ///
4838    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4839    ///   The parent-state middle-arm projection on the closed-set
4840    ///   partition lives at ONE substrate site as a FUSED short-circuit
4841    ///   walk over `ConditionKind::ALL` under [`Self::has_kind`] with
4842    ///   early exit on the first observed present/missing pair —
4843    ///   byte-for-byte cheaper than the widened negation-of-both-
4844    ///   endpoints composition, and semantically identical on every
4845    ///   arm. The trichotomy partition law
4846    ///   `is_kind_empty + is_kind_partially_covered + is_kind_saturated == 1`
4847    ///   lives at ONE substrate site inside the composition-law
4848    ///   testkit's per-arm sweep — pinned across every production
4849    ///   slice at compile time via the trait's default body
4850    ///   composition, not per-slice.
4851    /// - THEORY.md §VI.1 — generation over composition. A new
4852    ///   [`ConditionKind`] variant added to `ALL` reaches this primitive
4853    ///   mechanically through the fused walk — the trichotomy holds
4854    ///   on the widened kind set without further per-caller edit
4855    ///   (a slice previously at the middle arm continues to satisfy
4856    ///   it if it does not add the new variant; a previously-saturated
4857    ///   slice that leaves the new variant missing becomes partially
4858    ///   covered at every downstream callsite).
4859    fn is_kind_partially_covered(&self) -> bool {
4860        let mut has_present = false;
4861        let mut has_missing = false;
4862        for k in ConditionKind::ALL {
4863            if self.has_kind(k) {
4864                has_present = true;
4865            } else {
4866                has_missing = true;
4867            }
4868            if has_present && has_missing {
4869                return true;
4870            }
4871        }
4872        false
4873    }
4874
4875    /// Boolean at-least-one halfspace peer of [`Self::has_any_missing_kind`]
4876    /// on the closed-set-inversion axis — `true` iff AT LEAST ONE
4877    /// [`ConditionKind::ALL`] variant appears at least once in this slice
4878    /// (equivalently, [`Self::distinct_kinds`] is non-empty,
4879    /// [`Self::distinct_kind_count`] `> 0`, and
4880    /// [`Self::first_distinct_kind`] is `Some`).
4881    ///
4882    /// Default body: `ConditionKind::ALL.iter().copied().any(|k|
4883    /// self.has_kind(k))` — a SHORT-CIRCUITING closed-set walk that
4884    /// returns `true` at the FIRST populated kind WITHOUT materializing
4885    /// [`Self::distinct_kinds`]'s `Vec`, WITHOUT walking every slot to
4886    /// build [`Self::distinct_kind_count`]'s scalar, and WITHOUT
4887    /// allocating the closed-set-inversion scan. Strictly cheaper than
4888    /// either widened primitive on every non-empty arm because the walk
4889    /// short-circuits at the first `has_kind` hit rather than paying
4890    /// for the Vec allocation or the full cardinality count.
4891    ///
4892    /// # Peer to [`crate::tagged_union::TaggedUnion::has_any_populated_kind`]
4893    ///
4894    /// Slice-level peer of the tagged-union parent-level at-least-one
4895    /// halfspace predicate one struct-layer up: where
4896    /// [`crate::tagged_union::TaggedUnion::has_any_populated_kind`]
4897    /// answers "is ANY slot on the tagged-union parent occupied?",
4898    /// `has_any_distinct_kind` answers "does ANY kind appear in AT
4899    /// LEAST ONE condition of the slice?". Both compose against a
4900    /// SHORT-CIRCUITING closed-set walk under the SAME `has` /
4901    /// `has_kind` predicate at two adjacent typescape sites — the two
4902    /// primitives close the at-least-one halfspace on the closed-set-
4903    /// inversion axis at both struct layers under the SAME shape.
4904    ///
4905    /// # Sibling to [`Self::has_any_missing_kind`]
4906    ///
4907    /// Closed-set-inversion peer of the at-least-one halfspace on the
4908    /// closed-set-complement axis — where `has_any_missing_kind`
4909    /// returns `true` iff at least one kind is ABSENT,
4910    /// `has_any_distinct_kind` returns `true` iff at least one kind is
4911    /// PRESENT. Together with their zero-arm endpoints
4912    /// ([`Self::is_kind_saturated`] on the missing axis and the empty-
4913    /// slice endpoint on the distinct axis), the two Booleans partition
4914    /// the (distinct, missing) product: a slice is EMPTY iff neither
4915    /// `has_any_distinct_kind()` nor `is_kind_saturated()` returns
4916    /// `true`; a slice is SATURATED iff both `has_any_distinct_kind()`
4917    /// returns `true` and `has_any_missing_kind()` returns `false`; a
4918    /// slice is PARTIALLY POPULATED iff both `has_any_distinct_kind()`
4919    /// and `has_any_missing_kind()` return `true`.
4920    ///
4921    /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
4922    ///
4923    /// Boolean at-least-one halfspace peer of the widened + scalar
4924    /// closed-set-inversion primitives — where `distinct_kinds` returns
4925    /// the FULL distinct SET and `distinct_kind_count` returns its
4926    /// cardinality, `has_any_distinct_kind` collapses either the
4927    /// widened primitive to its non-emptiness Boolean or the scalar to
4928    /// its `>= 1` halfspace Boolean. The composition laws
4929    /// `has_any_distinct_kind() == !distinct_kinds().is_empty()` and
4930    /// `has_any_distinct_kind() == (distinct_kind_count() > 0)` bind
4931    /// this Boolean projection to the widened + scalar primitives at
4932    /// the trait's default body — strictly cheaper than either widened
4933    /// primitive on every non-empty arm because the walk short-circuits
4934    /// at the first populated kind on the has-side walk rather than
4935    /// allocating the closed-set-inversion scan or walking every slot
4936    /// to build the scalar cardinality.
4937    ///
4938    /// # Semantics
4939    ///
4940    /// An empty slice returns `false` — the SOLE arm on which
4941    /// `has_any_distinct_kind` returns `false`. A slice carrying any
4942    /// [`ConditionKind`] at least once returns `true` (a single-
4943    /// populated slice, a partially-populated slice, and a saturated
4944    /// slice all return `true`).
4945    ///
4946    /// # Compounding future consumers
4947    ///
4948    /// - A fleet-wide "any coverage at all" fast-path that discriminates
4949    ///   "the slice carries at least one closed-set kind" from "the
4950    ///   slice is empty" reads
4951    ///   `boundary.postconditions.has_any_distinct_kind()` at ONE call
4952    ///   site rather than restating `distinct_kind_count() > 0` (which
4953    ///   walks every slot to count) or `!distinct_kinds().is_empty()`
4954    ///   (which allocates the Vec before the negated emptiness check).
4955    /// - A `has-any-distinct-kind` require-tag classifier arm reaches
4956    ///   this primitive with no allocation, byte-for-byte peer of the
4957    ///   tagged-union `has-any-populated-kind` classifier one struct-
4958    ///   layer up under the SAME `any(has)` short-circuit shape.
4959    /// - A coherence check that flags "any process boundary whose
4960    ///   postcondition slice covers at least one [`ConditionKind`]"
4961    ///   reads `boundary.postconditions.has_any_distinct_kind()` at
4962    ///   ONE substrate primitive per test rather than restating the
4963    ///   `.iter().copied().any(|k| slice.has_kind(k))` body at every
4964    ///   callsite.
4965    ///
4966    /// # Theory grounding
4967    ///
4968    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4969    ///   The at-least-one halfspace projection on the closed-set-
4970    ///   inversion axis lives at ONE substrate site as a typed short-
4971    ///   circuiting closed-set walk `ConditionKind::ALL.iter().any(
4972    ///   has_kind)`. Every downstream consumer whose semantic reading
4973    ///   is "at least one kind is present" reads through this
4974    ///   primitive rather than paying for the widened primitive's Vec
4975    ///   allocation.
4976    /// - THEORY.md §VI.1 — generation over composition. A new
4977    ///   [`ConditionKind`] variant added to `ALL` reaches this
4978    ///   primitive mechanically through the `any` short-circuit — an
4979    ///   empty slice (returning `false` here) that later picks up the
4980    ///   new variant returns `true` at every downstream `has-any-
4981    ///   distinct-kind` callsite.
4982    fn has_any_distinct_kind(&self) -> bool {
4983        self.iter_distinct_kinds().next().is_some()
4984    }
4985
4986    /// Boolean cardinality-mid-endpoint peer of
4987    /// [`Self::has_any_distinct_kind`] on the closed-set-inversion
4988    /// axis — `true` iff EXACTLY ONE [`ConditionKind::ALL`] variant
4989    /// appears at least once in this slice (equivalently,
4990    /// [`Self::distinct_kind_count`] `== 1`,
4991    /// [`Self::distinct_kinds`]`.len() == 1`, and
4992    /// [`Self::first_distinct_kind`] equals
4993    /// [`Self::last_distinct_kind`] and is [`Some`]).
4994    ///
4995    /// Default body: a two-step-short-circuit closed-set walk over
4996    /// [`Self::iter_distinct_kinds`] — pulls up to two hits off the
4997    /// load-bearing distinct iterator; the primitive returns `true`
4998    /// iff the first hit is [`Some`] and the second is [`None`],
4999    /// WITHOUT materializing [`Self::distinct_kinds`]'s `Vec` and
5000    /// WITHOUT walking every slot to build
5001    /// [`Self::distinct_kind_count`]'s scalar. Short-circuits at the
5002    /// second distinct kind — strictly cheaper than either widened
5003    /// primitive on every arm with `≥ 2` distinct kinds.
5004    ///
5005    /// # Peer to [`crate::tagged_union::TaggedUnion::has_unique_populated_kind`]
5006    ///
5007    /// Slice-level peer of the tagged-union parent-level
5008    /// cardinality-mid-endpoint predicate one struct-layer up: where
5009    /// [`crate::tagged_union::TaggedUnion::has_unique_populated_kind`]
5010    /// answers "is EXACTLY ONE slot on the tagged-union parent
5011    /// occupied?", `has_unique_distinct_kind` answers "does EXACTLY
5012    /// ONE kind appear in AT LEAST ONE condition of the slice?". Both
5013    /// compose against a two-step-short-circuit walk under the SAME
5014    /// presence predicate (`has(kind)` / `has_kind(kind)`) at two
5015    /// adjacent typescape sites — the two primitives close the
5016    /// exactly-one-arm on the closed-set-inversion axis at both
5017    /// struct layers under the SAME shape.
5018    ///
5019    /// # Sibling to [`Self::has_unique_missing_kind`]
5020    ///
5021    /// Closed-set-inversion peer of the cardinality-mid-endpoint on
5022    /// the closed-set-complement axis — where
5023    /// `has_unique_missing_kind` returns `true` iff exactly one kind
5024    /// is ABSENT (the near-saturation-endpoint arm),
5025    /// `has_unique_distinct_kind` returns `true` iff exactly one kind
5026    /// is PRESENT (the singleton-coverage arm). Both close the
5027    /// exactly-one arm on their respective axis under the SAME
5028    /// two-step short-circuit walk shape via the load-bearing
5029    /// iterator peer.
5030    ///
5031    /// # Semantics
5032    ///
5033    /// An empty slice returns `false` (0 distinct, not 1). A slice
5034    /// carrying a single [`ConditionKind`] (with any multiplicity)
5035    /// returns `true` — the SOLE arm where
5036    /// `has_unique_distinct_kind` returns `true` on any `N ≥ 2`
5037    /// closed set. A slice carrying `K ≥ 2` distinct kinds returns
5038    /// `false`. A saturated slice returns `false` on `N ≥ 2` closed
5039    /// sets (every kind present, not exactly 1).
5040    ///
5041    /// # Compounding future consumers
5042    ///
5043    /// - A fleet-wide "singleton coverage" fast-path that
5044    ///   discriminates "the slice carries exactly one ALL variant"
5045    ///   from every other cardinality reads
5046    ///   `boundary.postconditions.has_unique_distinct_kind()` at ONE
5047    ///   call site — one two-step short-circuit walk, no allocation,
5048    ///   no scalar equality against `1`, byte-for-byte peer of the
5049    ///   tagged-union `has-unique-populated-kind` classifier one
5050    ///   struct-layer up under the SAME two-step short-circuit shape.
5051    /// - A `has-unique-distinct-kind` require-tag classifier arm
5052    ///   reaches this primitive with no allocation.
5053    /// - A future singleton-coverage diagnostic that prints "the SOLE
5054    ///   [`ConditionKind`] covered by this Boundary" pairs
5055    ///   `has_unique_distinct_kind()` with
5056    ///   [`Self::first_distinct_kind`] to name the SOLE distinct kind
5057    ///   without allocating [`Self::distinct_kinds`]'s `Vec`.
5058    ///
5059    /// # Theory grounding
5060    ///
5061    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
5062    ///   The cardinality-mid-endpoint projection on the closed-set-
5063    ///   inversion axis lives at ONE substrate site as a typed
5064    ///   two-step-short-circuit fold through the load-bearing
5065    ///   [`Self::iter_distinct_kinds`] iterator — byte-for-byte peer
5066    ///   of `distinct_kind_count()` composed against `== 1`, but with
5067    ///   a second-distinct-slot short-circuit that the scalar counter
5068    ///   primitive does not offer.
5069    /// - THEORY.md §VI.1 — generation over composition. A new
5070    ///   [`ConditionKind`] variant added to `ALL` reaches this
5071    ///   primitive mechanically through the short-circuit walk — a
5072    ///   slice previously at the singleton-coverage arm (returned
5073    ///   `true` here) that also picks up the new variant now has
5074    ///   TWO distinct kinds and returns `false`.
5075    fn has_unique_distinct_kind(&self) -> bool {
5076        let mut it = self.iter_distinct_kinds();
5077        it.next().is_some() && it.next().is_none()
5078    }
5079
5080    /// Witnessing `Option<ConditionKind>` peer of
5081    /// [`Self::has_unique_distinct_kind`] on the closed-set-inversion
5082    /// axis — `Some(k)` iff `k` is the SOLE [`ConditionKind::ALL`]
5083    /// variant appearing at least once in this slice, else `None`.
5084    ///
5085    /// Default body: a two-step-short-circuit fold through
5086    /// [`Self::iter_distinct_kinds`] — pull the first hit; return
5087    /// `Some(first)` iff the second hit is [`None`], else `None`.
5088    /// Byte-for-byte peer of
5089    /// [`crate::tagged_union::TaggedUnion::unique_populated_kind`]
5090    /// one struct-layer up under the SAME `iter_populated_kinds`
5091    /// two-step short-circuit shape, and the WITNESSING scalar peer of
5092    /// the Boolean [`Self::has_unique_distinct_kind`] predicate at the
5093    /// SAME two-step short-circuit shape.
5094    ///
5095    /// # Sibling to [`Self::first_distinct_kind`] / [`Self::last_distinct_kind`]
5096    ///
5097    /// FIFTH refinement on the closed-set-inversion axis under exactly-
5098    /// one-hit semantics, `Option<ConditionKind>`-valued: together with
5099    /// [`Self::first_distinct_kind`] and [`Self::last_distinct_kind`]
5100    /// the three primitives project [`Self::distinct_kinds`] onto its
5101    /// cardinality-conditioned scalar identity on the present side. The
5102    /// composition laws
5103    /// `unique_distinct_kind().is_some() == (distinct_kind_count() == 1)`
5104    /// and (on the `Some` arm) `unique_distinct_kind() ==
5105    /// first_distinct_kind() == last_distinct_kind()` bind the exactly-
5106    /// one scalar identity to the widened primitives at the trait's
5107    /// default body.
5108    ///
5109    /// # Peer to [`Self::unique_missing_kind`]
5110    ///
5111    /// Closed-set-inversion peer of the exactly-one-hit scalar on the
5112    /// closed-set-complement axis — where `unique_missing_kind` names
5113    /// the SOLE ABSENT kind, `unique_distinct_kind` names the SOLE
5114    /// PRESENT kind. The two primitives close the (present, absent) x
5115    /// (endpoint, exactly-one) 2x3 scalar-Option grid on the slice
5116    /// level under the SAME two-step short-circuit shape via the
5117    /// load-bearing iterator peers.
5118    ///
5119    /// # Semantics
5120    ///
5121    /// An empty slice returns `None` (0 distinct, not 1). A slice
5122    /// carrying a single [`ConditionKind`] (with any multiplicity)
5123    /// returns `Some(k)` — the SOLE arm where `unique_distinct_kind`
5124    /// returns `Some` on any `N ≥ 2` closed set. A slice carrying `K ≥ 2`
5125    /// distinct kinds returns `None`. A saturated slice returns `None`
5126    /// on `N ≥ 2` closed sets.
5127    ///
5128    /// # Compounding future consumers
5129    ///
5130    /// - A future singleton-coverage diagnostic that prints "the SOLE
5131    ///   [`ConditionKind`] covered by this Boundary is X" reads
5132    ///   `boundary.postconditions.unique_distinct_kind()` at ONE call
5133    ///   site — the WITNESS + the exactly-one predicate composed at
5134    ///   ONE short-circuit walk, rather than pairing the Boolean
5135    ///   [`Self::has_unique_distinct_kind`] with [`Self::first_distinct_kind`]
5136    ///   at TWO independent walks whose agreement is a coincidence.
5137    /// - A `unique-distinct-<kind>` require-tag classifier arm reads
5138    ///   this primitive with no allocation, byte-for-byte symmetrical
5139    ///   with `slice.unique_missing_kind()`.
5140    /// - A fast-path branch that discriminates "exactly one kind
5141    ///   covered" from "0 or ≥ 2 covered" reads
5142    ///   `slice.unique_distinct_kind().is_some()` at ONE call site.
5143    ///
5144    /// # Theory grounding
5145    ///
5146    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
5147    ///   The exactly-one-hit witnessing projection on the closed-set-
5148    ///   inversion axis lives at ONE substrate site as a typed two-
5149    ///   step-short-circuit fold through the load-bearing
5150    ///   [`Self::iter_distinct_kinds`] iterator — byte-for-byte peer of
5151    ///   the tagged-union [`crate::tagged_union::TaggedUnion::unique_populated_kind`]
5152    ///   under the SAME iterator shape.
5153    /// - THEORY.md §VI.1 — generation over composition. A new
5154    ///   [`ConditionKind`] variant added to `ALL` reaches this
5155    ///   primitive mechanically through the short-circuit walk — a
5156    ///   slice previously at the singleton-coverage arm (returned
5157    ///   `Some(k)` here) that also picks up the new variant now has
5158    ///   TWO distinct kinds and returns `None`.
5159    fn unique_distinct_kind(&self) -> Option<ConditionKind> {
5160        let mut it = self.iter_distinct_kinds();
5161        let first = it.next()?;
5162        match it.next() {
5163            None => Some(first),
5164            Some(_) => None,
5165        }
5166    }
5167
5168    /// Boolean cardinality many-arm peer of
5169    /// [`Self::has_unique_distinct_kind`] on the closed-set-inversion
5170    /// axis — `true` iff AT LEAST TWO [`ConditionKind::ALL`] variants
5171    /// appear at least once in this slice (equivalently,
5172    /// [`Self::distinct_kind_count`] `>= 2` and
5173    /// [`Self::distinct_kinds`]`.len() >= 2`).
5174    ///
5175    /// Default body: a two-step-short-circuit closed-set walk over
5176    /// [`Self::iter_distinct_kinds`] — pulls up to two hits off the
5177    /// load-bearing distinct iterator; the primitive returns `true`
5178    /// iff BOTH the first and the second are [`Some`], WITHOUT
5179    /// materializing [`Self::distinct_kinds`]'s `Vec` and WITHOUT
5180    /// walking every slot to build [`Self::distinct_kind_count`]'s
5181    /// scalar. Short-circuits at the second distinct kind — strictly
5182    /// cheaper than either widened primitive on every arm with `≥ 2`
5183    /// distinct kinds. Byte-for-byte peer of
5184    /// [`crate::tagged_union::TaggedUnion::has_multiple_populated_kinds`]
5185    /// under the (populated, missing) inversion axis one struct-layer
5186    /// up.
5187    ///
5188    /// # Peer to [`crate::tagged_union::TaggedUnion::has_multiple_populated_kinds`]
5189    ///
5190    /// Slice-level peer of the tagged-union parent-level cardinality
5191    /// many-arm predicate one struct-layer up: where
5192    /// [`crate::tagged_union::TaggedUnion::has_multiple_populated_kinds`]
5193    /// answers "are AT LEAST TWO slots on the tagged-union parent
5194    /// occupied?", `has_multiple_distinct_kinds` answers "do AT LEAST
5195    /// TWO kinds appear in AT LEAST ONE condition of the slice?". Both
5196    /// compose against a two-step-short-circuit closed-set walk under
5197    /// a presence predicate (`has(kind)` / `has_kind(kind)`) at two
5198    /// adjacent typescape sites — the two primitives close the at-
5199    /// least-two arm on the closed-set-inversion axis at both struct
5200    /// layers under the SAME shape.
5201    ///
5202    /// # Sibling to the Boolean distinct-cardinality trichotomy
5203    ///
5204    /// Third and final arm of the `{0, 1, ≥2}` cardinality trichotomy
5205    /// on the distinct axis at the slice level, closing the natural
5206    /// partition alongside the zero-arm (the empty-distinct endpoint,
5207    /// reached via `!has_any_distinct_kind()`) and
5208    /// [`Self::has_unique_distinct_kind`] (one-arm). Every slice
5209    /// satisfies EXACTLY ONE of the three Boolean projections — the
5210    /// three primitives partition `0..=ConditionKind::ALL.len()` at 0,
5211    /// 1, and ≥ 2 respectively. The composition law
5212    /// `has_multiple_distinct_kinds() == (distinct_kind_count() >= 2)`
5213    /// binds the Boolean projection to the scalar primitive at the
5214    /// trait's default body — swept substrate-wide by
5215    /// [`assert_slice_refinement_composition_laws`] as its
5216    /// distinct-cardinality-many-arm arm.
5217    ///
5218    /// # Semantics
5219    ///
5220    /// An empty slice returns `false` (0 distinct, not ≥ 2). A slice
5221    /// carrying a single [`ConditionKind`] (with any multiplicity)
5222    /// returns `false` (1 distinct, not ≥ 2). A slice carrying `K ≥ 2`
5223    /// distinct kinds returns `true`. A saturated slice returns `true`
5224    /// on any `N ≥ 2` closed set (every kind present, ≥ 2 ≥ 2).
5225    ///
5226    /// # Compounding future consumers
5227    ///
5228    /// - An operator-facing "≥ 2 dependencies covered" fast-path
5229    ///   discriminator on the many-distinct arm reads
5230    ///   `boundary.postconditions.has_multiple_distinct_kinds()` at
5231    ///   ONE call site — one two-step short-circuit walk, no
5232    ///   allocation, no scalar comparison against `>= 2`, byte-for-
5233    ///   byte peer of the tagged-union `has-multiple-populated-kinds`
5234    ///   classifier one struct-layer up under the SAME two-step
5235    ///   short-circuit shape.
5236    /// - A `has-multiple-distinct-kinds` require-tag classifier arm
5237    ///   reaches this primitive with no allocation, byte-for-byte
5238    ///   peer of the tagged-union `has-multiple-populated-kinds`
5239    ///   classifier one struct-layer up.
5240    /// - A future multi-coverage diagnostic that prints "≥ 2 distinct
5241    ///   ConditionKinds covered by this Boundary" reads
5242    ///   `has_multiple_distinct_kinds()` at ONE call site without
5243    ///   allocating [`Self::distinct_kinds`]'s `Vec`.
5244    ///
5245    /// # Theory grounding
5246    ///
5247    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
5248    ///   The cardinality-many-arm projection on the distinct axis
5249    ///   lives at ONE substrate site as a typed two-step-short-circuit
5250    ///   fold through the load-bearing [`Self::iter_distinct_kinds`]
5251    ///   iterator — byte-for-byte peer of `distinct_kind_count()`
5252    ///   composed against `>= 2`, but with a second-distinct-slot
5253    ///   short-circuit that the scalar counter primitive does not
5254    ///   offer.
5255    /// - THEORY.md §VI.1 — generation over composition. A new
5256    ///   [`ConditionKind`] variant added to `ALL` reaches this
5257    ///   primitive mechanically through the short-circuit walk — a
5258    ///   slice previously at the singleton-coverage arm (returned
5259    ///   `false` here) that also picks up the new variant now has TWO
5260    ///   distinct kinds and flips to `true`.
5261    fn has_multiple_distinct_kinds(&self) -> bool {
5262        let mut it = self.iter_distinct_kinds();
5263        it.next().is_some() && it.next().is_some()
5264    }
5265
5266    /// Boolean cardinality "≤ 1" negation peer of
5267    /// [`Self::has_multiple_distinct_kinds`] on the closed-set-inversion
5268    /// axis — `true` iff AT MOST ONE [`ConditionKind::ALL`] variant
5269    /// appears at least once in this slice (equivalently,
5270    /// [`Self::distinct_kind_count`] `<= 1` and
5271    /// [`Self::distinct_kinds`]`.len() <= 1`). Closes the {0, 1, ≥2, ≤1}
5272    /// Boolean-negation grid on the distinct axis at the slice level
5273    /// alongside its sibling `has_multiple_distinct_kinds` (≥ 2 many-
5274    /// arm) under the definitional negation `!(≥ 2) == (≤ 1)`, and
5275    /// alongside `!has_any_distinct_kind` (=0 empty-endpoint) OR
5276    /// `has_unique_distinct_kind` (=1 mid-endpoint) as the trichotomy-
5277    /// union arm. Names the arrangement space where the slice is
5278    /// EMPTY-OR-SINGLETON (zero or exactly one distinct kind).
5279    ///
5280    /// Default body: `!self.has_multiple_distinct_kinds()` — a
5281    /// definitional Boolean negation of the many-arm primitive. Short-
5282    /// circuits transitively through
5283    /// [`Self::has_multiple_distinct_kinds`]'s two-step short-circuit
5284    /// walk over [`Self::iter_distinct_kinds`]: returns `true` as soon
5285    /// as the many-arm walk stops with fewer than two distinct hits,
5286    /// WITHOUT materializing [`Self::distinct_kinds`]'s `Vec` and
5287    /// WITHOUT walking every slot to build
5288    /// [`Self::distinct_kind_count`]'s scalar. Byte-for-byte peer of
5289    /// [`crate::tagged_union::TaggedUnion::has_at_most_one_populated_kind`]
5290    /// under the (populated, missing) inversion axis one struct-layer
5291    /// up, both composed as the same definitional negation of their
5292    /// respective many-arm primitives.
5293    ///
5294    /// # Peer to [`crate::tagged_union::TaggedUnion::has_at_most_one_populated_kind`]
5295    ///
5296    /// Slice-level peer of the tagged-union parent-level cardinality
5297    /// "≤ 1" predicate one struct-layer up: where
5298    /// [`crate::tagged_union::TaggedUnion::has_at_most_one_populated_kind`]
5299    /// answers "does the tagged-union parent have AT MOST ONE occupied
5300    /// slot?", `has_at_most_one_distinct_kind` answers "do AT MOST ONE
5301    /// kind appear in AT LEAST ONE condition of the slice?". Both
5302    /// compose as the definitional Boolean negation of their many-arm
5303    /// primitive (`!has_multiple_populated_kinds()` /
5304    /// `!has_multiple_distinct_kinds()`) at two adjacent typescape
5305    /// sites — the two primitives close the "≤ 1" arm on the closed-
5306    /// set-inversion axis at both struct layers under the SAME shape.
5307    ///
5308    /// # Peer to [`Self::has_at_most_one_missing_kind`]
5309    ///
5310    /// Axis-parity mirror of the closed-set-complement "≤ 1" negation
5311    /// peer at the slice level — where `has_at_most_one_missing_kind`
5312    /// tests "at most one kind MISSING" (near-saturation-or-saturated),
5313    /// `has_at_most_one_distinct_kind` tests "at most one kind
5314    /// PRESENT" (empty-or-singleton). Both compose the same
5315    /// definitional negation shape (`!has_multiple_*_kinds()`) at the
5316    /// slice-level trait's default body — the two primitives close the
5317    /// "≤ 1" arm on both the closed-set-complement and closed-set-
5318    /// inversion axes at the SAME struct layer under the SAME shape.
5319    ///
5320    /// # Sibling to the Boolean distinct-cardinality tetrachotomy
5321    ///
5322    /// Fourth arm of the `{0, ≥1, 1, ≥2, ≤1}` Boolean-cardinality
5323    /// closure on the distinct axis at the slice level, closing the
5324    /// Boolean-negation grid alongside `!has_any_distinct_kind` (=0
5325    /// zero-arm reached via [`Self::has_any_distinct_kind`]),
5326    /// [`Self::has_unique_distinct_kind`] (=1 mid-endpoint),
5327    /// [`Self::has_any_distinct_kind`] (≥1 halfspace), and
5328    /// [`Self::has_multiple_distinct_kinds`] (≥2 many-arm). The
5329    /// {≤1, ≥2} pair sit on the Boolean-negation axis:
5330    /// `has_at_most_one_distinct_kind == !has_multiple_distinct_kinds`
5331    /// on every arm. The {0, 1} union arm sits on the trichotomy-union
5332    /// axis: `has_at_most_one_distinct_kind == !has_any_distinct_kind
5333    /// || has_unique_distinct_kind` on every arm. Both composition laws
5334    /// bind the "≤ 1" Boolean projection to the sibling primitives at
5335    /// the trait's default body — swept substrate-wide by
5336    /// [`assert_slice_refinement_composition_laws`] as its distinct-
5337    /// axis "≤ 1" arm.
5338    ///
5339    /// # Semantics
5340    ///
5341    /// An empty slice returns `true` (0 distinct, `≤ 1`) — the dual of
5342    /// the empty-slice arm on [`Self::has_at_most_one_missing_kind`]
5343    /// which returns `false` on `N ≥ 2` closed sets (empty means every
5344    /// kind missing, `N ≥ 2` missing, not `≤ 1`). A slice carrying a
5345    /// single [`ConditionKind`] (with any multiplicity) returns `true`
5346    /// (1 distinct, `≤ 1`) — the singleton arm on the distinct axis.
5347    /// A slice carrying `K ≥ 2` distinct kinds returns `false`. A
5348    /// saturated slice returns `false` on any `N ≥ 2` closed set
5349    /// (every kind present, `N ≥ 2` distinct, not `≤ 1`) — the union of
5350    /// the two "≤ 1" arms (`=0` and `=1`) is exactly the arrangement
5351    /// space where the primitive returns `true`.
5352    ///
5353    /// # Compounding future consumers
5354    ///
5355    /// - An operator-facing "at most one dependency currently covered"
5356    ///   fast-path discriminator on the empty / singleton-coverage arms
5357    ///   reads `boundary.postconditions.has_at_most_one_distinct_kind()`
5358    ///   at ONE call site — one bit-flip on the many-arm's two-step
5359    ///   short-circuit walk, no allocation, no scalar comparison
5360    ///   against `<= 1`, byte-for-byte peer of the tagged-union
5361    ///   `has-at-most-one-populated-kind` classifier one struct-layer
5362    ///   up under the SAME `!has_multiple_populated_kinds` definitional
5363    ///   negation shape.
5364    /// - A `has-at-most-one-distinct-kind` require-tag classifier arm
5365    ///   reaches this primitive with no allocation, closing the
5366    ///   {0, 1, ≥ 2, ≤ 1} cardinality-Boolean grid on the distinct axis
5367    ///   at the slice level alongside its sibling
5368    ///   `has-multiple-distinct-kinds` under the Boolean negation axis
5369    ///   and the missing-axis peer `has-at-most-one-missing-kind` under
5370    ///   the closed-set-inversion axis.
5371    /// - A future under-coverage diagnostic that says "at most one
5372    ///   ConditionKind covered by this Boundary" reads
5373    ///   `has_at_most_one_distinct_kind()` at ONE call site without
5374    ///   allocating [`Self::distinct_kinds`]'s `Vec`.
5375    ///
5376    /// # Theory grounding
5377    ///
5378    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
5379    ///   The cardinality "≤ 1" projection on the distinct axis lives
5380    ///   at ONE substrate site as the definitional Boolean negation
5381    ///   of [`Self::has_multiple_distinct_kinds`]; the three composition
5382    ///   forms (`!has_multiple_distinct_kinds()`,
5383    ///   `distinct_kind_count() <= 1`, and `!has_any_distinct_kind() ||
5384    ///   has_unique_distinct_kind()`) compose through the SAME two-
5385    ///   step-short-circuit walk shape one negation up, byte-for-byte
5386    ///   identical on every arm.
5387    /// - THEORY.md §VI.1 — generation over composition. A new
5388    ///   [`ConditionKind`] variant added to `ALL` reaches this
5389    ///   primitive mechanically through the delegated
5390    ///   [`Self::has_multiple_distinct_kinds`] — a slice previously at
5391    ///   the singleton arm (returned `true` here) that also picks up
5392    ///   the new variant now has TWO distinct kinds and flips to
5393    ///   `false`.
5394    fn has_at_most_one_distinct_kind(&self) -> bool {
5395        !self.has_multiple_distinct_kinds()
5396    }
5397
5398    /// Boolean at-least-one halfspace peer of [`Self::is_kind_saturated`]
5399    /// on the closed-set-complement axis — `true` iff AT LEAST ONE
5400    /// [`ConditionKind::ALL`] variant appears zero times in this slice
5401    /// (equivalently, [`Self::missing_kinds`] is non-empty,
5402    /// [`Self::missing_kind_count`] `> 0`, [`Self::first_missing_kind`]
5403    /// is `Some`).
5404    ///
5405    /// Default body: `!self.is_kind_saturated()` — a definitional
5406    /// negation of the saturation-endpoint primitive. Short-circuits
5407    /// transitively through [`Self::is_kind_saturated`]'s
5408    /// `ConditionKind::ALL.iter().all(has_kind)` composition: the
5409    /// underlying `all` walk returns `false` at the FIRST missing kind
5410    /// (yielding `true` here) WITHOUT materializing
5411    /// [`Self::missing_kinds`]'s `Vec`, WITHOUT walking every slot to
5412    /// build [`Self::missing_kind_count`]'s scalar, and WITHOUT
5413    /// allocating the closed-set-complement scan. Strictly cheaper
5414    /// than either widened primitive on every partially-populated arm.
5415    ///
5416    /// # Peer to [`crate::tagged_union::TaggedUnion::has_any_missing_kind`]
5417    ///
5418    /// Slice-level peer of the tagged-union parent-level at-least-one
5419    /// halfspace predicate one struct-layer up: where
5420    /// [`crate::tagged_union::TaggedUnion::has_any_missing_kind`]
5421    /// answers "is ANY slot on the tagged-union parent empty?",
5422    /// `has_any_missing_kind` answers "does ANY kind appear in NO
5423    /// condition of the slice?". Both compose against their
5424    /// saturation-endpoint primitive under a definitional negation
5425    /// (`!is_saturated` / `!is_kind_saturated`) at two adjacent
5426    /// typescape sites — the two primitives close the at-least-one
5427    /// halfspace on the closed-set-complement axis at both struct
5428    /// layers under the SAME shape.
5429    ///
5430    /// # Sibling to [`Self::is_kind_saturated`]
5431    ///
5432    /// Boolean at-least-one halfspace peer of the zero-arm saturation-
5433    /// endpoint primitive on the closed-set-complement axis — where
5434    /// `is_kind_saturated` returns `true` iff `missing_kind_count == 0`,
5435    /// `has_any_missing_kind` returns its Boolean-negation: `true` iff
5436    /// `missing_kind_count >= 1`. Together the two Booleans partition
5437    /// the missing-cardinality closed set: exactly one of
5438    /// `is_kind_saturated()` and `has_any_missing_kind()` is `true`
5439    /// for every slice. The definitional negation law
5440    /// `has_any_missing_kind() == !is_kind_saturated()` is pinned as a
5441    /// first-class typed invariant by the trait's own default body and
5442    /// swept substrate-wide by
5443    /// [`assert_slice_refinement_composition_laws`] as its at-least-
5444    /// one halfspace arm.
5445    ///
5446    /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
5447    ///
5448    /// Boolean at-least-one halfspace peer of the widened + scalar
5449    /// closed-set-complement primitives — where `missing_kinds` returns
5450    /// the FULL missing SET (a `Vec<ConditionKind>` of every absent
5451    /// kind) and `missing_kind_count` returns its cardinality
5452    /// (a `usize` in `0..=ConditionKind::ALL.len()`),
5453    /// `has_any_missing_kind` collapses either the widened primitive
5454    /// to its non-emptiness Boolean or the scalar to its `>= 1`
5455    /// halfspace Boolean. The composition laws
5456    /// `has_any_missing_kind() == !missing_kinds().is_empty()` and
5457    /// `has_any_missing_kind() == (missing_kind_count() > 0)` bind
5458    /// this Boolean projection to the widened + scalar primitives at
5459    /// the trait's default body — strictly cheaper than either widened
5460    /// primitive on every partially-populated arm because the negation
5461    /// short-circuits at the first missing kind on the has-side walk
5462    /// rather than allocating the closed-set-complement scan or
5463    /// walking every slot to build the scalar cardinality.
5464    ///
5465    /// # Semantics
5466    ///
5467    /// An empty slice returns `true` (every kind is missing — the
5468    /// fully-missing endpoint). A slice carrying a strict subset of
5469    /// [`ConditionKind::ALL`] returns `true`. A saturated slice
5470    /// returns `false` — the SOLE arm on which `has_any_missing_kind`
5471    /// returns `false`, byte-for-byte peer of the SOLE arm on which
5472    /// `is_kind_saturated` returns `true`.
5473    ///
5474    /// # Compounding future consumers
5475    ///
5476    /// - A fleet-wide "gap present" fast-path that discriminates "some
5477    ///   kind is missing" from "every kind is present" reads
5478    ///   `boundary.postconditions.has_any_missing_kind()` at ONE call
5479    ///   site rather than negating `is_kind_saturated()` at the
5480    ///   callsite or restating `missing_kind_count() > 0` (which walks
5481    ///   every slot to count) or `!missing_kinds().is_empty()` (which
5482    ///   allocates the Vec before the negated emptiness check).
5483    /// - A `has-any-missing-kind` require-tag classifier arm reaches
5484    ///   this primitive with no allocation, byte-for-byte peer of the
5485    ///   tagged-union `has-any-missing-kind` classifier one struct-
5486    ///   layer up under the SAME `!is_saturated` definitional negation
5487    ///   shape.
5488    /// - A coherence check that flags "any process boundary with a
5489    ///   missing [`ConditionKind`]" reads
5490    ///   `boundary.postconditions.has_any_missing_kind()` at ONE
5491    ///   substrate primitive per test rather than restating the
5492    ///   negation body at every callsite.
5493    ///
5494    /// # Theory grounding
5495    ///
5496    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
5497    ///   The at-least-one halfspace projection lives at ONE substrate
5498    ///   site as a definitional negation of
5499    ///   [`Self::is_kind_saturated`]. Every downstream consumer whose
5500    ///   semantic reading is "at least one kind is absent" reads
5501    ///   through this primitive rather than negating `is_kind_saturated`
5502    ///   at every callsite or paying for the widened primitive's Vec
5503    ///   allocation.
5504    /// - THEORY.md §VI.1 — generation over composition. A new
5505    ///   [`ConditionKind`] variant added to `ALL` reaches this
5506    ///   primitive mechanically through the delegated
5507    ///   `is_kind_saturated` — a slice that was previously saturated
5508    ///   (returned `false` here) picks up the new missing variant and
5509    ///   returns `true` at every downstream `has-any-missing-kind`
5510    ///   callsite unless it also carries the new variant.
5511    fn has_any_missing_kind(&self) -> bool {
5512        !self.is_kind_saturated()
5513    }
5514
5515    /// Boolean cardinality-mid-endpoint peer of
5516    /// [`Self::has_any_missing_kind`] on the closed-set-complement
5517    /// axis — `true` iff EXACTLY ONE [`ConditionKind::ALL`] variant
5518    /// appears zero times in this slice (equivalently,
5519    /// [`Self::missing_kind_count`] `== 1`,
5520    /// [`Self::missing_kinds`]`.len() == 1`, and
5521    /// [`Self::first_missing_kind`] equals
5522    /// [`Self::last_missing_kind`] and is [`Some`]).
5523    ///
5524    /// Default body: a two-step-short-circuit closed-set walk over
5525    /// [`ConditionKind::ALL`] under a negated [`Self::has_kind`]
5526    /// predicate. Pulls up to two hits off the filtered iterator; the
5527    /// primitive returns `true` iff the first hit is [`Some`] and the
5528    /// second is [`None`], WITHOUT materializing
5529    /// [`Self::missing_kinds`]'s `Vec` and WITHOUT walking every slot
5530    /// to build [`Self::missing_kind_count`]'s scalar. Short-circuits
5531    /// at the SECOND missing kind — strictly cheaper than either
5532    /// widened primitive on every arm with `≥ 2` missing kinds.
5533    ///
5534    /// # Peer to [`crate::tagged_union::TaggedUnion::has_unique_missing_kind`]
5535    ///
5536    /// Slice-level peer of the tagged-union parent-level
5537    /// cardinality-mid-endpoint predicate one struct-layer up: where
5538    /// [`crate::tagged_union::TaggedUnion::has_unique_missing_kind`]
5539    /// answers "is EXACTLY ONE slot on the tagged-union parent
5540    /// empty?", `has_unique_missing_kind` answers "does EXACTLY ONE
5541    /// kind appear in NO condition of the slice?". Both compose
5542    /// against a two-step-short-circuit closed-set walk under a
5543    /// negated presence predicate (`!has(kind)` / `!has_kind(kind)`)
5544    /// at two adjacent typescape sites — the two primitives close the
5545    /// exactly-one-arm on the closed-set-complement axis at both
5546    /// struct layers under the SAME shape.
5547    ///
5548    /// # Sibling to the Boolean missing-cardinality trichotomy
5549    ///
5550    /// Second arm of the `{0, 1, ≥2}` cardinality trichotomy on the
5551    /// missing axis, closing the natural partition alongside
5552    /// [`Self::is_kind_saturated`] (zero-arm) and (once its slice-
5553    /// level peer lands) the many-arm predicate. Every slice
5554    /// satisfies EXACTLY ONE of the three Boolean projections — the
5555    /// three primitives partition `0..=ConditionKind::ALL.len()` at
5556    /// 0, 1, and ≥ 2 respectively. The composition law
5557    /// `has_unique_missing_kind() == (missing_kind_count() == 1)`
5558    /// binds the Boolean projection to the scalar primitive at the
5559    /// trait's default body — swept substrate-wide by
5560    /// [`assert_slice_refinement_composition_laws`] as its
5561    /// cardinality-mid-endpoint arm.
5562    ///
5563    /// # Semantics
5564    ///
5565    /// An empty slice returns `false` on any `N ≥ 2` closed set (every
5566    /// kind is missing — the fully-missing endpoint, `N` missing not
5567    /// `1`). A slice carrying `K` distinct kinds for `1 ≤ K ≤ N-2` on
5568    /// `N ≥ 3` closed sets returns `false` (`N - K ≥ 2` kinds missing).
5569    /// A slice at the near-saturation arm (carrying every kind except
5570    /// exactly one) returns `true` — the SOLE arrangement where
5571    /// `has_unique_missing_kind` returns `true`. A saturated slice
5572    /// returns `false` (zero missing).
5573    ///
5574    /// # Compounding future consumers
5575    ///
5576    /// - An operator-facing "one kind away from saturated" fast-path
5577    ///   discriminator on the near-saturation arm reads
5578    ///   `boundary.postconditions.has_unique_missing_kind()` at ONE
5579    ///   call site — one two-step short-circuit walk, no allocation,
5580    ///   no scalar equality against `1`, byte-for-byte peer of the
5581    ///   tagged-union `has-unique-missing-kind` classifier one struct-
5582    ///   layer up under the SAME two-step short-circuit shape.
5583    /// - A `has-unique-missing-kind` require-tag classifier arm
5584    ///   reaches this primitive with no allocation, byte-for-byte
5585    ///   peer of the tagged-union `has-unique-missing-kind` classifier
5586    ///   one struct-layer up.
5587    /// - A future gap-analysis diagnostic that prints "one remaining
5588    ///   ConditionKind not covered by this Boundary" pairs
5589    ///   `has_unique_missing_kind()` with
5590    ///   [`Self::first_missing_kind`] to name the SOLE remaining hole
5591    ///   without allocating [`Self::missing_kinds`]'s `Vec`.
5592    ///
5593    /// # Theory grounding
5594    ///
5595    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
5596    ///   The cardinality-mid-endpoint projection on the missing axis
5597    ///   lives at ONE substrate site as a typed two-step-short-
5598    ///   circuit walk over [`ConditionKind::ALL`] under negated
5599    ///   [`Self::has_kind`] — byte-for-byte peer of
5600    ///   `missing_kind_count()` composed against `== 1`, but with a
5601    ///   second-missing-slot short-circuit that the scalar counter
5602    ///   primitive does not offer.
5603    /// - THEORY.md §VI.1 — generation over composition. A new
5604    ///   [`ConditionKind`] variant added to `ALL` reaches this
5605    ///   primitive mechanically through the short-circuit walk — a
5606    ///   slice previously at the near-saturation arm (returned `true`
5607    ///   here) that omits the new variant now has TWO missing kinds
5608    ///   and returns `false`; a slice previously at the
5609    ///   saturated-except-one-of-two arm on an `N == 2` closed set
5610    ///   remains at the near-saturation arm on `N ≥ 3` iff it
5611    ///   picks up every OTHER variant.
5612    fn has_unique_missing_kind(&self) -> bool {
5613        let mut it = self.iter_missing_kinds();
5614        it.next().is_some() && it.next().is_none()
5615    }
5616
5617    /// Witnessing `Option<ConditionKind>` peer of
5618    /// [`Self::has_unique_missing_kind`] on the closed-set-complement
5619    /// axis — `Some(k)` iff `k` is the SOLE [`ConditionKind::ALL`]
5620    /// variant ABSENT from this slice, else `None`.
5621    ///
5622    /// Default body: a two-step-short-circuit fold through
5623    /// [`Self::iter_missing_kinds`] — pull the first hit; return
5624    /// `Some(first)` iff the second hit is [`None`], else `None`.
5625    /// Byte-for-byte peer of
5626    /// [`crate::tagged_union::TaggedUnion::unique_missing_kind`] one
5627    /// struct-layer up under the SAME `iter_missing_kinds` two-step
5628    /// short-circuit shape, and the WITNESSING scalar peer of the
5629    /// Boolean [`Self::has_unique_missing_kind`] predicate at the SAME
5630    /// two-step short-circuit shape.
5631    ///
5632    /// # Sibling to [`Self::first_missing_kind`] / [`Self::last_missing_kind`]
5633    ///
5634    /// FIFTH refinement on the closed-set-complement axis under
5635    /// exactly-one-hit semantics, `Option<ConditionKind>`-valued:
5636    /// together with [`Self::first_missing_kind`] and
5637    /// [`Self::last_missing_kind`] the three primitives project
5638    /// [`Self::missing_kinds`] onto its cardinality-conditioned scalar
5639    /// identity on the absent side. The composition laws
5640    /// `unique_missing_kind().is_some() == (missing_kind_count() == 1)`
5641    /// and (on the `Some` arm) `unique_missing_kind() ==
5642    /// first_missing_kind() == last_missing_kind()` bind the exactly-
5643    /// one scalar identity to the widened primitives at the trait's
5644    /// default body.
5645    ///
5646    /// # Peer to [`Self::unique_distinct_kind`]
5647    ///
5648    /// Closed-set-complement peer of the exactly-one-hit scalar on the
5649    /// closed-set-inversion axis — where `unique_distinct_kind` names
5650    /// the SOLE PRESENT kind, `unique_missing_kind` names the SOLE
5651    /// ABSENT kind. The two primitives close the (present, absent) x
5652    /// (endpoint, exactly-one) 2x3 scalar-Option grid on the slice
5653    /// level under the SAME two-step short-circuit shape via the
5654    /// load-bearing iterator peers on the two opposite sides.
5655    ///
5656    /// # Semantics
5657    ///
5658    /// An empty slice returns `None` on any `N ≥ 2` closed set (every
5659    /// kind is missing — the fully-missing endpoint, `N` missing not
5660    /// `1`). A slice at the near-saturation arm (carrying every kind
5661    /// except exactly one) returns `Some(the-lone-empty)` — the SOLE
5662    /// arm where `unique_missing_kind` returns `Some` on any `N ≥ 3`
5663    /// closed set. A saturated slice returns `None` (zero missing).
5664    ///
5665    /// # Compounding future consumers
5666    ///
5667    /// - An operator-facing "one dependency still unfulfilled: X"
5668    ///   diagnostic on the near-saturation arm reads
5669    ///   `boundary.postconditions.unique_missing_kind()` at ONE call
5670    ///   site — the WITNESS + the exactly-one predicate composed at
5671    ///   ONE short-circuit walk, rather than pairing the Boolean
5672    ///   [`Self::has_unique_missing_kind`] with [`Self::first_missing_kind`]
5673    ///   at TWO independent walks whose agreement is a coincidence.
5674    /// - A `unique-missing-<kind>` require-tag classifier arm reads
5675    ///   this primitive with no allocation, byte-for-byte symmetrical
5676    ///   with `slice.unique_distinct_kind()`.
5677    /// - A fast-path branch that discriminates "exactly one kind
5678    ///   still missing" from "0 or ≥ 2 still missing" reads
5679    ///   `slice.unique_missing_kind().is_some()` at ONE call site.
5680    ///
5681    /// # Theory grounding
5682    ///
5683    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
5684    ///   The complement-exactly-one-hit witnessing projection lives at
5685    ///   ONE substrate site as a typed two-step-short-circuit fold
5686    ///   through the load-bearing [`Self::iter_missing_kinds`] iterator
5687    ///   — byte-for-byte peer of the tagged-union
5688    ///   [`crate::tagged_union::TaggedUnion::unique_missing_kind`]
5689    ///   under the SAME iterator shape.
5690    /// - THEORY.md §VI.1 — generation over composition. A new
5691    ///   [`ConditionKind`] variant added to `ALL` reaches this
5692    ///   primitive mechanically on the missing side.
5693    fn unique_missing_kind(&self) -> Option<ConditionKind> {
5694        let mut it = self.iter_missing_kinds();
5695        let first = it.next()?;
5696        match it.next() {
5697            None => Some(first),
5698            Some(_) => None,
5699        }
5700    }
5701
5702    /// Boolean cardinality "≥ 2" many-arm peer of
5703    /// [`Self::has_unique_missing_kind`] on the closed-set-complement
5704    /// axis — `true` iff AT LEAST TWO [`ConditionKind::ALL`] variants
5705    /// appear zero times in this slice (equivalently,
5706    /// [`Self::missing_kind_count`] `>= 2` and
5707    /// [`Self::missing_kinds`]`.len() >= 2`).
5708    ///
5709    /// Default body: a two-step-short-circuit closed-set walk over
5710    /// [`ConditionKind::ALL`] under a negated [`Self::has_kind`]
5711    /// predicate. Pulls up to two hits off the filtered iterator; the
5712    /// primitive returns `true` iff BOTH the first and the second are
5713    /// [`Some`], WITHOUT materializing [`Self::missing_kinds`]'s `Vec`
5714    /// and WITHOUT walking every slot to build
5715    /// [`Self::missing_kind_count`]'s scalar. Short-circuits at the
5716    /// second missing kind — strictly cheaper than either widened
5717    /// primitive on every arm with `≥ 2` missing kinds. Byte-for-byte
5718    /// peer of [`crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`]
5719    /// under the (populated, missing) complement axis one struct-
5720    /// layer up.
5721    ///
5722    /// # Peer to [`crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`]
5723    ///
5724    /// Slice-level peer of the tagged-union parent-level cardinality
5725    /// many-arm predicate one struct-layer up: where
5726    /// [`crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`]
5727    /// answers "are AT LEAST TWO slots on the tagged-union parent
5728    /// empty?", `has_multiple_missing_kinds` answers "do AT LEAST TWO
5729    /// kinds appear in NO condition of the slice?". Both compose
5730    /// against a two-step-short-circuit closed-set walk under a
5731    /// negated presence predicate (`!has(kind)` / `!has_kind(kind)`)
5732    /// at two adjacent typescape sites — the two primitives close the
5733    /// at-least-two arm on the closed-set-complement axis at both
5734    /// struct layers under the SAME shape.
5735    ///
5736    /// # Sibling to the Boolean missing-cardinality trichotomy
5737    ///
5738    /// Third and final arm of the `{0, 1, ≥2}` cardinality trichotomy
5739    /// on the missing axis at the slice level, closing the natural
5740    /// partition alongside [`Self::is_kind_saturated`] (zero-arm) and
5741    /// [`Self::has_unique_missing_kind`] (one-arm). Every slice
5742    /// satisfies EXACTLY ONE of the three Boolean projections — the
5743    /// three primitives partition `0..=ConditionKind::ALL.len()` at
5744    /// 0, 1, and ≥ 2 respectively. The composition law
5745    /// `has_multiple_missing_kinds() == (missing_kind_count() >= 2)`
5746    /// binds the Boolean projection to the scalar primitive at the
5747    /// trait's default body — swept substrate-wide by
5748    /// [`assert_slice_refinement_composition_laws`] as its
5749    /// cardinality-many-arm arm.
5750    ///
5751    /// # Semantics
5752    ///
5753    /// An empty slice returns `true` on any `N ≥ 2` closed set (every
5754    /// kind is missing — the fully-missing endpoint, `N ≥ 2` missing).
5755    /// A slice carrying `K` distinct kinds for `1 ≤ K ≤ N-2` on
5756    /// `N ≥ 3` closed sets returns `true` (`N - K ≥ 2` kinds missing).
5757    /// A slice at the near-saturation arm (carrying every kind except
5758    /// exactly one) returns `false` — the SOLE-missing arrangement
5759    /// where `has_multiple_missing_kinds` returns `false` (exactly
5760    /// one missing, not ≥ 2). A saturated slice returns `false`
5761    /// (zero missing).
5762    ///
5763    /// # Compounding future consumers
5764    ///
5765    /// - An operator-facing "≥ 2 dependencies still unfulfilled" fast-
5766    ///   path discriminator on the many-missing arm reads
5767    ///   `boundary.postconditions.has_multiple_missing_kinds()` at ONE
5768    ///   call site — one two-step short-circuit walk, no allocation,
5769    ///   no scalar comparison against `>= 2`, byte-for-byte peer of
5770    ///   the tagged-union `has-multiple-missing-kinds` classifier one
5771    ///   struct-layer up under the SAME two-step short-circuit shape.
5772    /// - A `has-multiple-missing-kinds` require-tag classifier arm
5773    ///   reaches this primitive with no allocation, byte-for-byte
5774    ///   peer of the tagged-union `has-multiple-missing-kinds`
5775    ///   classifier one struct-layer up.
5776    /// - A future coverage-gap diagnostic that says "≥ 2 remaining
5777    ///   ConditionKinds not covered by this Boundary" reads
5778    ///   `has_multiple_missing_kinds()` at ONE call site without
5779    ///   allocating [`Self::missing_kinds`]'s `Vec`.
5780    ///
5781    /// # Theory grounding
5782    ///
5783    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
5784    ///   The cardinality-many-arm projection on the missing axis
5785    ///   lives at ONE substrate site as a typed two-step-short-
5786    ///   circuit walk over [`ConditionKind::ALL`] under negated
5787    ///   [`Self::has_kind`] — byte-for-byte peer of
5788    ///   `missing_kind_count()` composed against `>= 2`, but with a
5789    ///   second-missing-slot short-circuit that the scalar counter
5790    ///   primitive does not offer.
5791    /// - THEORY.md §VI.1 — generation over composition. A new
5792    ///   [`ConditionKind`] variant added to `ALL` reaches this
5793    ///   primitive mechanically through the short-circuit walk — a
5794    ///   slice previously at the near-saturation arm (returned
5795    ///   `false` here) that omits the new variant now has TWO missing
5796    ///   kinds and flips to `true`; a slice previously at the
5797    ///   saturated arm on an `N == 2` closed set that omits the new
5798    ///   variant flips from `false` to `true` (`1 ≥ 2` false → `1`
5799    ///   missing on `N == 3`, but this workspace has `N == 8`, so
5800    ///   the flip surfaces well before the endpoint).
5801    fn has_multiple_missing_kinds(&self) -> bool {
5802        let mut it = self.iter_missing_kinds();
5803        it.next().is_some() && it.next().is_some()
5804    }
5805
5806    /// Boolean cardinality "≤ 1" negation peer of
5807    /// [`Self::has_multiple_missing_kinds`] on the closed-set-complement
5808    /// axis — `true` iff AT MOST ONE [`ConditionKind::ALL`] variant
5809    /// appears zero times in this slice (equivalently,
5810    /// [`Self::missing_kind_count`] `<= 1` and
5811    /// [`Self::missing_kinds`]`.len() <= 1`). Names the arm where the
5812    /// slice is SATURATED-OR-NEAR-SATURATED (zero or exactly one kind
5813    /// missing).
5814    ///
5815    /// Default body: `!self.has_multiple_missing_kinds()` — a
5816    /// definitional Boolean negation of the many-arm primitive. Short-
5817    /// circuits transitively through
5818    /// [`Self::has_multiple_missing_kinds`]'s two-step short-circuit
5819    /// closed-set walk: returns `true` as soon as the many-arm walk
5820    /// stops with fewer than two missing hits, WITHOUT materializing
5821    /// [`Self::missing_kinds`]'s `Vec` and WITHOUT walking every slot to
5822    /// build [`Self::missing_kind_count`]'s scalar. Byte-for-byte peer
5823    /// of [`crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`]
5824    /// under the (populated, missing) complement axis one struct-layer
5825    /// up, both composed as the same definitional negation of their
5826    /// respective many-arm primitives.
5827    ///
5828    /// # Peer to [`crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`]
5829    ///
5830    /// Slice-level peer of the tagged-union parent-level cardinality
5831    /// "≤ 1" predicate one struct-layer up: where
5832    /// [`crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`]
5833    /// answers "does the tagged-union parent have AT MOST ONE empty
5834    /// slot?", `has_at_most_one_missing_kind` answers "do AT MOST ONE
5835    /// kind appear in NO condition of the slice?". Both compose as the
5836    /// definitional Boolean negation of their many-arm primitive
5837    /// (`!has_multiple_missing_kinds()`) at two adjacent typescape
5838    /// sites — the two primitives close the "≤ 1" arm on the closed-
5839    /// set-complement axis at both struct layers under the SAME shape.
5840    ///
5841    /// # Sibling to the Boolean missing-cardinality pentachotomy
5842    ///
5843    /// Fourth arm of the `{0, 1, ≥1, ≤1, ≥2}` Boolean-cardinality
5844    /// pentachotomy on the missing axis at the slice level, closing
5845    /// the Boolean-negation grid alongside
5846    /// [`Self::is_kind_saturated`] (=0 zero-arm),
5847    /// [`Self::has_unique_missing_kind`] (=1 mid-endpoint),
5848    /// [`Self::has_any_missing_kind`] (≥1 halfspace), and
5849    /// [`Self::has_multiple_missing_kinds`] (≥2 many-arm). The
5850    /// {≤1, ≥2} pair sit on the Boolean-negation axis:
5851    /// `has_at_most_one_missing_kind == !has_multiple_missing_kinds` on
5852    /// every arm. The {0, 1} union arm sits on the trichotomy-union
5853    /// axis: `has_at_most_one_missing_kind == is_kind_saturated ||
5854    /// has_unique_missing_kind` on every arm. Both composition laws
5855    /// bind the "≤ 1" Boolean projection to the sibling primitives at
5856    /// the trait's default body — swept substrate-wide by
5857    /// [`assert_slice_refinement_composition_laws`] as its "≤ 1" arm.
5858    ///
5859    /// # Semantics
5860    ///
5861    /// An empty slice returns `false` on any `N ≥ 2` closed set
5862    /// (every kind is missing — `N ≥ 2` missing, not `≤ 1`).
5863    /// A slice carrying `K` distinct kinds for `1 ≤ K ≤ N-2` on `N ≥ 3`
5864    /// closed sets returns `false` (`N - K ≥ 2` kinds missing).
5865    /// A slice at the near-saturation arm (carrying every kind except
5866    /// exactly one) returns `true` (exactly 1 missing, `≤ 1`). A
5867    /// saturated slice returns `true` (0 missing, `≤ 1`) — the union
5868    /// of the two "≤ 1" arms (`=0` and `=1`) is exactly the
5869    /// arrangement space where the primitive returns `true`.
5870    ///
5871    /// # Compounding future consumers
5872    ///
5873    /// - An operator-facing "at most one dependency still unfulfilled"
5874    ///   fast-path discriminator on the near-saturated / saturated
5875    ///   arms reads `boundary.postconditions.has_at_most_one_missing_kind()`
5876    ///   at ONE call site — one bit-flip on the many-arm's two-step
5877    ///   short-circuit walk, no allocation, no scalar comparison
5878    ///   against `<= 1`, byte-for-byte peer of the tagged-union
5879    ///   `has-at-most-one-missing-kind` classifier one struct-layer up
5880    ///   under the SAME `!has_multiple_missing_kinds` definitional
5881    ///   negation shape.
5882    /// - A `has-at-most-one-missing-kind` require-tag classifier arm
5883    ///   reaches this primitive with no allocation, closing the
5884    ///   {0, 1, ≥ 2, ≤ 1} cardinality-Boolean grid on the missing axis
5885    ///   at the slice level alongside its sibling
5886    ///   `has-multiple-missing-kinds` under the Boolean negation axis.
5887    /// - A future coverage-gap diagnostic that says "at most one
5888    ///   remaining ConditionKind not covered by this Boundary" reads
5889    ///   `has_at_most_one_missing_kind()` at ONE call site without
5890    ///   allocating [`Self::missing_kinds`]'s `Vec`.
5891    ///
5892    /// # Theory grounding
5893    ///
5894    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
5895    ///   The cardinality "≤ 1" projection on the missing axis lives
5896    ///   at ONE substrate site as the definitional Boolean negation
5897    ///   of [`Self::has_multiple_missing_kinds`]; the three composition
5898    ///   forms (`!has_multiple_missing_kinds()`, `missing_kind_count() <= 1`,
5899    ///   and `is_kind_saturated() || has_unique_missing_kind()`)
5900    ///   compose through the SAME two-step-short-circuit walk shape
5901    ///   one negation up, byte-for-byte identical on every arm.
5902    /// - THEORY.md §VI.1 — generation over composition. A new
5903    ///   [`ConditionKind`] variant added to `ALL` reaches this
5904    ///   primitive mechanically through the delegated
5905    ///   [`Self::has_multiple_missing_kinds`] — a slice previously at
5906    ///   the near-saturation arm (returned `true` here) that omits the
5907    ///   new variant now has TWO missing kinds and flips to `false`.
5908    fn has_at_most_one_missing_kind(&self) -> bool {
5909        !self.has_multiple_missing_kinds()
5910    }
5911
5912    /// Boolean per-kind complement of [`Self::has_kind`] — `true` iff
5913    /// NO [`Condition`] in this slice carries the given
5914    /// [`ConditionKind`] (equivalently, the kind is a member of
5915    /// [`Self::missing_kinds`]).
5916    ///
5917    /// Default body: `!self.has_kind(kind)` — a definitional negation
5918    /// of the presence-probe primitive. Short-circuits transitively
5919    /// through [`Self::has_kind`]'s composition down to
5920    /// [`Self::iter_kind`]: `!self.find_kind(kind).is_some()` returns
5921    /// as soon as any match is found (yielding `false`) without
5922    /// walking the rest of the slice, WITHOUT materializing
5923    /// [`Self::missing_kinds`]'s `Vec` per-kind for a per-kind
5924    /// question, and WITHOUT allocating the closed-set-complement scan.
5925    ///
5926    /// # Peer to [`crate::tagged_union::TaggedUnion::lacks`]
5927    ///
5928    /// Slice-level peer of the tagged-union parent-level closed-set-
5929    /// complement predicate one struct-layer up: where
5930    /// [`crate::tagged_union::TaggedUnion::lacks`] answers "is THIS
5931    /// kind's slot on the tagged-union parent empty?", `lacks_kind`
5932    /// answers "does THIS kind appear in NO condition of the slice?".
5933    /// Both compose against their per-kind presence primitive under a
5934    /// definitional negation (`!has(kind)` / `!has_kind(kind)`) at two
5935    /// adjacent typescape sites — the two primitives close the
5936    /// closed-set-complement invariant on the per-kind axis at both
5937    /// struct layers under the SAME shape.
5938    ///
5939    /// # Sibling to [`Self::has_kind`]
5940    ///
5941    /// Boolean per-kind complement peer of the point-probe primitive
5942    /// on the closed-set-complement axis — where `has_kind` returns
5943    /// `true` iff the addressed kind appears at least once,
5944    /// `lacks_kind` returns its negation: `true` iff the addressed kind
5945    /// appears zero times. Together the two Booleans partition the
5946    /// (slice, kind) matrix at the slice-level presence-probe axis:
5947    /// exactly one of `has_kind(k)` and `lacks_kind(k)` is `true` for
5948    /// every `k ∈ ConditionKind::ALL`. The definitional complement law
5949    /// `lacks_kind(k) == !has_kind(k)` is pinned as a first-class typed
5950    /// invariant by the trait's own default body and swept substrate-
5951    /// wide by [`assert_slice_refinement_composition_laws`] as its
5952    /// per-kind-complement arm.
5953    ///
5954    /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
5955    ///
5956    /// Per-kind Boolean projection of the closed-set-complement
5957    /// widened + scalar primitives — where `missing_kinds` returns the
5958    /// FULL missing-set (a `Vec<ConditionKind>` of every absent kind)
5959    /// and `missing_kind_count` returns its cardinality (a `usize` in
5960    /// `0..=ConditionKind::ALL.len()`), `lacks_kind` collapses the
5961    /// missing-set to its per-kind membership Boolean for ONE
5962    /// addressed kind. The composition law
5963    /// `lacks_kind(k) == missing_kinds().contains(&k)` binds this
5964    /// Boolean projection to the widened closed-set-complement
5965    /// primitive at the trait's default body — strictly cheaper than
5966    /// the widened primitive on every per-kind question because the
5967    /// negation short-circuits at the first match on the has-side
5968    /// walk rather than allocating the closed-set-complement scan.
5969    ///
5970    /// # Semantics
5971    ///
5972    /// An empty slice returns `true` for every [`ConditionKind`] (no
5973    /// kind appears, so every kind is lacked). A slice carrying kind
5974    /// `k` at any position returns `false` for `lacks_kind(k)` and
5975    /// `true` for `lacks_kind(k')` for every `k' ≠ k` (single-kind
5976    /// coverage). A saturated slice (every kind appears at least once)
5977    /// returns `false` on every arm — the SOLE arrangement where the
5978    /// primitive returns `false` for every kind.
5979    ///
5980    /// # Compounding future consumers
5981    ///
5982    /// - A `lacks-<kind>` require-tag classifier arm reaches this
5983    ///   primitive with no allocation, byte-for-byte peer of the
5984    ///   tagged-union `lacks-<kind>` classifier one struct-layer up
5985    ///   under the SAME `!has(kind)` definitional negation shape.
5986    /// - A dependency-satisfaction coherence check that enforces "no
5987    ///   process boundary lacks a `ClosedLoopAuth` postcondition" reads
5988    ///   `boundary.postconditions.lacks_kind(ConditionKind::ClosedLoopAuth)`
5989    ///   at ONE call site rather than negating
5990    ///   `boundary.postconditions.has_kind(ConditionKind::ClosedLoopAuth)`
5991    ///   at the callsite or materializing the closed-set complement
5992    ///   with `missing_kinds().contains(&k)`.
5993    /// - A "still missing: <kind>" diagnostic that reports the FIRST
5994    ///   unmet postcondition kind reads `slice.lacks_kind(k)` inside a
5995    ///   `ConditionKind::ALL` fold at ONE substrate primitive per test
5996    ///   rather than restating the negation body at every callsite.
5997    ///
5998    /// # Theory grounding
5999    ///
6000    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
6001    ///   The per-kind closed-set-complement projection lives at ONE
6002    ///   substrate site as a definitional negation of [`Self::has_kind`].
6003    ///   Every downstream consumer whose semantic reading is "the
6004    ///   missing set contains THIS kind" reads through this primitive
6005    ///   rather than negating `has_kind` at every callsite or paying
6006    ///   for the closed-set-complement scan.
6007    /// - THEORY.md §VI.1 — generation over composition. A new
6008    ///   [`ConditionKind`] variant added to `ALL` reaches this
6009    ///   primitive mechanically through the delegated `has_kind` —
6010    ///   every downstream `lacks-<kind>` classifier arm sees the wider
6011    ///   kind set without further per-caller edit.
6012    fn lacks_kind(&self, kind: ConditionKind) -> bool {
6013        !self.has_kind(kind)
6014    }
6015
6016    /// Kind-scoped strict refinement of [`Self::has_kind`] — `true` iff
6017    /// the given `kind` appears in the slice AND no OTHER
6018    /// [`ConditionKind`] appears alongside it. The "exactly this one
6019    /// variant is present" predicate at the slice level.
6020    ///
6021    /// Default body: a FUSED short-circuit closed-set walk over
6022    /// [`ConditionKind::ALL`] under [`Self::has_kind`] that returns
6023    /// `false` at the EARLIEST populated slot whose kind is NOT
6024    /// `kind`, and returns `true` iff the sweep completes with `kind`
6025    /// seen as the sole populated slot. Byte-for-byte cheaper than
6026    /// either widened composition
6027    /// `self.distinct_kinds() == vec![kind]` (which allocates the
6028    /// distinct-kind Vec before the equality test) or
6029    /// `self.has_kind(kind) && self.distinct_kind_count() == 1` (which
6030    /// walks the closed-set twice) on every arm where the slice
6031    /// carries a populated kind that isn't `kind`.
6032    ///
6033    /// # Peer to [`crate::tagged_union::TaggedUnion::has_only`]
6034    ///
6035    /// Slice-level peer of the tagged-union parent-level kind-scoped
6036    /// strict-refinement predicate one struct-layer up: where
6037    /// [`crate::tagged_union::TaggedUnion::has_only`] answers "is THIS
6038    /// kind's slot on the tagged-union parent the sole populated
6039    /// slot?", `has_only_kind` answers "is THIS kind the sole distinct
6040    /// kind appearing in the slice?". Both primitives compose the SAME
6041    /// fused short-circuit closed-set walk under a per-kind
6042    /// [`Self::has_kind`] / `TaggedUnion::has` predicate at two
6043    /// adjacent typescape sites — the two primitives close the
6044    /// kind-scoped strict-refinement invariant on the well-formed
6045    /// (1-of-N populated) arm at both struct layers under the SAME
6046    /// shape.
6047    ///
6048    /// # Sibling to [`Self::has_kind`]
6049    ///
6050    /// Kind-scoped strict-refinement peer of the point-probe primitive
6051    /// on the closed-set-inversion axis — where `has_kind(k)` returns
6052    /// `true` iff `k` appears at least once (multiplicity ignored),
6053    /// `has_only_kind(k)` refines that to the strictly stricter
6054    /// predicate "k appears AND no other kind appears". The
6055    /// implication chain `has_only_kind(k) ⟹ has_kind(k)` is a
6056    /// definitional consequence of the fused walk's `saw_kind = true`
6057    /// arm; the reverse is FALSE on any partially-populated slice
6058    /// where a second kind lives alongside `k`. The composition law
6059    /// `has_only_kind(k) == (distinct_kinds() == vec![k])` binds this
6060    /// primitive to the widened closed-set-inversion primitive at the
6061    /// trait's default body — swept substrate-wide by
6062    /// [`assert_slice_refinement_composition_laws`] as its kind-scoped
6063    /// strict-refinement arm.
6064    ///
6065    /// # Truth table on the slice-level closed-set-inversion contract
6066    ///
6067    /// For a slice with `ConditionKind::ALL` of cardinality `N ≥ 2`
6068    /// and a fixed argument `kind`:
6069    ///
6070    /// - Empty slice (0 conditions, distinct-kind set empty): `false`
6071    ///   on any `N ≥ 2` — no kind appears, so `kind` isn't the sole
6072    ///   populated kind.
6073    /// - Single-populated slice with populated kind `p` (1 condition,
6074    ///   distinct-kind set `{p}`): `has_only_kind(kind) == (kind == p)`.
6075    /// - Duplicate-populated slice with kind `p` at every position
6076    ///   (multiplicity > 1, distinct-kind set `{p}`): still
6077    ///   `has_only_kind(kind) == (kind == p)` — MULTIPLICITY IS
6078    ///   IGNORED on the populated side (byte-for-byte with `has_kind`'s
6079    ///   multiplicity behavior).
6080    /// - Two-kinds slice with kinds `{p, q}` where `p != q` (distinct-
6081    ///   kind set `{p, q}`): `false` for every kind — the strict
6082    ///   refinement fails at the earliest walk step that hits the
6083    ///   second kind.
6084    /// - Saturated slice (every kind appears): `false` for every kind
6085    ///   on any `N ≥ 2` — N distinct kinds populate, so no single
6086    ///   kind is "only".
6087    ///
6088    /// # Kind-domain exhaustivity
6089    ///
6090    /// A slice satisfies `has_only_kind(k)` for AT MOST one `k`, since
6091    /// two distinct kinds cannot both be the sole distinct populated
6092    /// kind. On the well-formed arm the count is exactly 1 (the
6093    /// addressed populated kind); on every other arm the count is 0.
6094    /// This kind-domain exhaustivity law binds the argument-scoped
6095    /// projection to the parent-scoped cardinality primitive
6096    /// `distinct_kind_count() == 1` at the composition-law surface.
6097    ///
6098    /// # Compounding future consumers
6099    ///
6100    /// - A `has-only-<kind>` require-tag classifier arm reaches this
6101    ///   primitive with no allocation, byte-for-byte peer of the
6102    ///   tagged-union `has-only-<kind>` classifier one struct-layer up
6103    ///   under the SAME fused short-circuit walk shape.
6104    /// - A coherence check verifying "every ephemeral spec whose
6105    ///   postconditions carry ONLY `ClosedLoopAuth` (no
6106    ///   `JobAttested`, no `Cel`, ...) is a well-formed closed-loop
6107    ///   probe" reads
6108    ///   `spec.postconditions.has_only_kind(ConditionKind::ClosedLoopAuth)`
6109    ///   at ONE call site — strictly cheaper than reaching for the
6110    ///   widened composition on every well-formed-diagonal question.
6111    /// - An operator-facing "unambiguously kind=<k>" diagnostic on
6112    ///   the slice-level probe reads `slice.has_only_kind(k)` after
6113    ///   `first_distinct_kind` names the sole populated kind — one
6114    ///   fused walk, no allocation, no `Option<ConditionKind>`
6115    ///   construction.
6116    ///
6117    /// # Theory grounding
6118    ///
6119    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
6120    ///   The kind-scoped strict-refinement projection lives at ONE
6121    ///   substrate site as a fused short-circuit walk over
6122    ///   [`ConditionKind::ALL`] under [`Self::has_kind`] with early
6123    ///   exit on the first populated slot whose kind is not `kind` —
6124    ///   byte-for-byte cheaper than the widened composition
6125    ///   `distinct_kinds() == vec![kind]`, semantically identical on
6126    ///   every arm.
6127    /// - THEORY.md §VI.1 — generation over composition. A new
6128    ///   [`ConditionKind`] variant added to `ALL` reaches this
6129    ///   primitive mechanically through the fused walk — every
6130    ///   downstream `has-only-<kind>` classifier arm sees the wider
6131    ///   kind set without further per-caller edit.
6132    fn has_only_kind(&self, kind: ConditionKind) -> bool {
6133        let mut saw_kind = false;
6134        for k in ConditionKind::ALL {
6135            if !self.has_kind(k) {
6136                continue;
6137            }
6138            if k == kind {
6139                saw_kind = true;
6140            } else {
6141                return false;
6142            }
6143        }
6144        saw_kind
6145    }
6146
6147    /// Kind-scoped strict refinement of [`Self::lacks_kind`] — `true` iff
6148    /// the given `kind` does NOT appear in the slice AND every OTHER
6149    /// [`ConditionKind`] DOES appear at least once. The "exactly this
6150    /// one variant is the sole hole" predicate at the slice level.
6151    ///
6152    /// Default body: a FUSED short-circuit closed-set walk over
6153    /// [`ConditionKind::ALL`] under [`Self::has_kind`] that skips every
6154    /// populated slot, returns `false` at the EARLIEST missing slot
6155    /// whose kind is NOT `kind`, and returns `true` iff the sweep
6156    /// completes with `kind` seen as the sole missing slot. Byte-for-
6157    /// byte cheaper than either widened composition
6158    /// `self.missing_kinds() == vec![kind]` (which allocates the
6159    /// missing-kind Vec before the equality test) or
6160    /// `self.lacks_kind(kind) && self.missing_kind_count() == 1` (which
6161    /// walks the closed-set-complement scan twice) on every arm where
6162    /// the slice carries a missing kind that isn't `kind`.
6163    ///
6164    /// # Peer to [`crate::tagged_union::TaggedUnion::lacks_only`]
6165    ///
6166    /// Slice-level peer of the tagged-union parent-level kind-scoped
6167    /// strict-refinement predicate on the missing axis one struct-layer
6168    /// up: where
6169    /// [`crate::tagged_union::TaggedUnion::lacks_only`] answers "is THIS
6170    /// kind's slot on the tagged-union parent the sole empty slot?",
6171    /// `lacks_only_kind` answers "is THIS kind the sole missing kind
6172    /// from the slice's distinct set?". Both primitives compose the
6173    /// SAME fused short-circuit closed-set walk under a per-kind
6174    /// [`Self::has_kind`] / `TaggedUnion::has` predicate at two adjacent
6175    /// typescape sites — the two primitives close the kind-scoped
6176    /// strict-refinement invariant on the near-saturation-diagonal
6177    /// (`N-1`-of-N populated with the sole hole at `kind`) arm at both
6178    /// struct layers under the SAME shape.
6179    ///
6180    /// # Sibling to [`Self::has_only_kind`]
6181    ///
6182    /// Closed-set-complement mirror of the well-formed-diagonal
6183    /// strict-refinement primitive on the populated axis — where
6184    /// `has_only_kind(k)` returns `true` iff `k` is the sole distinct
6185    /// populated kind, `lacks_only_kind(k)` returns `true` iff `k` is
6186    /// the sole missing kind. Together the two peers CLOSE the
6187    /// (populated, missing) × (subset, equal) 2x2 kind-scoped
6188    /// strict-refinement grid at the slice level alongside `has_kind`
6189    /// (populated subset) and `lacks_kind` (missing subset).
6190    ///
6191    /// # Truth table on the slice-level closed-set-complement contract
6192    ///
6193    /// For a slice with `ConditionKind::ALL` of cardinality `N ≥ 2`
6194    /// and a fixed argument `kind`:
6195    ///
6196    /// - Empty slice (0 conditions, distinct-kind set empty,
6197    ///   missing-kind set == ALL): `false` on any `N ≥ 2` — every kind
6198    ///   is missing, so `kind` is NOT the sole missing kind.
6199    /// - Single-populated slice with populated kind `p` (1 condition,
6200    ///   missing-kind set == `ALL \ {p}`): `false` on any `N ≥ 3`
6201    ///   (`N - 1 ≥ 2` missing kinds, no sole missing kind); on `N == 2`
6202    ///   the missing set is `{q}` where `q ≠ p`, so
6203    ///   `lacks_only_kind(kind) == (kind == q)`.
6204    /// - Near-saturation slice with populated kinds `ALL \ {q}` (each
6205    ///   kind except `q` populated, missing set `{q}`): the SOLE `true`
6206    ///   arm — `lacks_only_kind(kind) == (kind == q)`.
6207    /// - Saturated slice (every kind appears): `false` on every kind —
6208    ///   no kind is missing, so no kind is the sole missing kind.
6209    /// - Multiplicity is ignored on the populated side: a slice
6210    ///   carrying `k` at every position still has an empty missing set,
6211    ///   or a missing set `{k'}` where `k' ≠ k`, byte-for-byte with
6212    ///   the single-populated arrangement.
6213    ///
6214    /// # Kind-domain exhaustivity
6215    ///
6216    /// A slice satisfies `lacks_only_kind(k)` for AT MOST one `k`,
6217    /// since two distinct kinds cannot both be the sole missing kind.
6218    /// On the near-saturation arm the count is exactly 1 (the sole
6219    /// missing kind); on every other arm the count is 0. This
6220    /// kind-domain exhaustivity law binds the argument-scoped
6221    /// projection to the parent-scoped cardinality primitive
6222    /// `missing_kind_count() == 1` at the composition-law surface.
6223    ///
6224    /// # Compounding future consumers
6225    ///
6226    /// - A `lacks-only-<kind>` require-tag classifier arm reaches this
6227    ///   primitive with no allocation, byte-for-byte peer of the
6228    ///   tagged-union `lacks-only-<kind>` classifier one struct-layer
6229    ///   up under the SAME fused short-circuit walk shape.
6230    /// - A "one dependency short: <kind>" diagnostic on the aggregate
6231    ///   boundary check reads
6232    ///   `slice.lacks_only_kind(k)` at ONE call site — one fused
6233    ///   short-circuit walk, no allocation, strictly cheaper than
6234    ///   `slice.first_missing_kind() == Some(k) && slice.missing_kind_count() == 1`
6235    ///   which walks the closed-set-complement scan twice.
6236    /// - A coherence check that verifies "the near-saturation slice
6237    ///   from an `all_but_one_kind_of(k)` factory is unambiguously
6238    ///   missing kind `k`" reads `slice.lacks_only_kind(k)` at ONE
6239    ///   site — the strongest structural pin on the missing-side
6240    ///   well-formed diagonal.
6241    ///
6242    /// # Theory grounding
6243    ///
6244    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
6245    ///   The kind-scoped strict-refinement projection on the missing
6246    ///   axis lives at ONE substrate site as a fused short-circuit
6247    ///   walk over [`ConditionKind::ALL`] under [`Self::has_kind`]
6248    ///   with early exit on the first missing slot whose kind is not
6249    ///   `kind` — byte-for-byte peer of [`Self::has_only_kind`]'s
6250    ///   fused walk under complement, semantically identical to
6251    ///   `first_missing_kind() == Some(kind) && missing_kind_count() == 1`
6252    ///   on every arm.
6253    /// - THEORY.md §VI.1 — generation over composition. A new
6254    ///   [`ConditionKind`] variant added to `ALL` reaches this
6255    ///   primitive mechanically through the delegated `has_kind` walk
6256    ///   — every downstream `lacks-only-<kind>` classifier arm sees
6257    ///   the wider kind set without further per-caller edit.
6258    fn lacks_only_kind(&self, kind: ConditionKind) -> bool {
6259        let mut saw_kind = false;
6260        for k in ConditionKind::ALL {
6261            if self.has_kind(k) {
6262                continue;
6263            }
6264            if k == kind {
6265                saw_kind = true;
6266            } else {
6267                return false;
6268            }
6269        }
6270        saw_kind
6271    }
6272
6273    /// Boolean cardinality "≥ 2" many-arm peer of [`Self::has_kind`]
6274    /// (≥ 1) and [`Self::lacks_kind`] (= 0) on the per-kind count axis
6275    /// — `true` iff AT LEAST TWO [`Condition`] values with the given
6276    /// `kind` appear in this slice (equivalently,
6277    /// [`Self::count_kind`]`(kind) >= 2` and
6278    /// [`Self::iter_kind`]`(kind).count() >= 2`).
6279    ///
6280    /// Default body: a two-step-short-circuit walk over
6281    /// [`Self::iter_kind`]`(kind)` — pulls up to two hits off the
6282    /// load-bearing per-kind iterator; the primitive returns `true`
6283    /// iff BOTH the first and the second are [`Some`], WITHOUT
6284    /// walking every slot to build [`Self::count_kind`]'s scalar.
6285    /// Short-circuits at the second matching condition — strictly
6286    /// cheaper than [`Self::count_kind`]`(kind) >= 2` on every arm
6287    /// with `≥ 2` matches. Byte-for-byte peer of
6288    /// [`Self::has_multiple_distinct_kinds`] under the (distinct-
6289    /// kinds axis, per-kind matches axis) parity: both compose the
6290    /// SAME two-step short-circuit shape one iterator over.
6291    ///
6292    /// # Sibling to [`Self::lacks_kind`] / [`Self::has_kind`] / [`Self::count_kind`]
6293    ///
6294    /// Many-arm on the per-kind count axis alongside
6295    /// [`Self::lacks_kind`] (= 0 zero-endpoint) and
6296    /// [`Self::has_kind`] (≥ 1 halfspace) — the three Booleans
6297    /// project [`Self::count_kind`]`(kind)`'s scalar onto its
6298    /// {= 0, ≥ 1, ≥ 2} arms. The composition law
6299    /// `has_multiple_of_kind(k) == (count_kind(k) >= 2)` binds the
6300    /// per-kind many-arm Boolean projection to the scalar counter
6301    /// primitive at the trait's default body — swept substrate-wide
6302    /// by [`assert_slice_refinement_composition_laws`] as its per-
6303    /// kind many-arm arm.
6304    ///
6305    /// # Semantics
6306    ///
6307    /// An empty slice returns `false` on every kind (0 matches, not
6308    /// `≥ 2`). A slice carrying `kind` exactly once (with any other
6309    /// kinds in any multiplicity) returns `false` on THAT kind (1
6310    /// match). A slice carrying `kind` two or more times returns
6311    /// `true` on THAT kind. Multiplicity of OTHER kinds is
6312    /// irrelevant — the primitive projects the slice onto the per-
6313    /// kind count axis for the queried kind alone.
6314    ///
6315    /// # Compounding future consumers
6316    ///
6317    /// - A boundary-well-formedness coherence check that rejects a
6318    ///   Process whose preconditions carry duplicate
6319    ///   [`ConditionKind::ProcessPhase`] entries reads
6320    ///   `boundary.preconditions.has_multiple_of_kind(ConditionKind::ProcessPhase)`
6321    ///   at ONE call site — one two-step short-circuit walk, no
6322    ///   allocation, no scalar comparison against `>= 2`.
6323    /// - A `has-multiple-of-<kind>` require-tag classifier arm reads
6324    ///   this primitive with no allocation, byte-for-byte peer of the
6325    ///   whole-slice `has-multiple-distinct-kinds` classifier one
6326    ///   axis over under the SAME two-step short-circuit shape.
6327    /// - A fleet-wide "duplicate condition detected" audit dump reads
6328    ///   `ConditionKind::ALL.into_iter().filter(|k|
6329    ///   slice.has_multiple_of_kind(*k))` at ONE call site.
6330    ///
6331    /// # Theory grounding
6332    ///
6333    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
6334    ///   The per-kind cardinality-many-arm projection on the count
6335    ///   axis lives at ONE substrate site as a typed two-step-short-
6336    ///   circuit fold through the load-bearing [`Self::iter_kind`]
6337    ///   iterator — byte-for-byte peer of `count_kind(kind)` composed
6338    ///   against `>= 2`, but with a second-match short-circuit that
6339    ///   the scalar counter primitive does not offer.
6340    /// - THEORY.md §VI.1 — generation over composition. A new
6341    ///   [`ConditionKind`] variant added to `ALL` reaches this
6342    ///   primitive mechanically through the per-kind iterator — a
6343    ///   slice previously containing no conditions of the new kind
6344    ///   returns `false` on it here, and picks up `true` the moment
6345    ///   an operator authors a second matching condition.
6346    fn has_multiple_of_kind(&self, kind: ConditionKind) -> bool {
6347        let mut it = self.iter_kind(kind);
6348        it.next().is_some() && it.next().is_some()
6349    }
6350
6351    /// Boolean cardinality "= 1" middle-arm peer of [`Self::lacks_kind`]
6352    /// (= 0) and [`Self::has_multiple_of_kind`] (≥ 2) on the per-kind
6353    /// count axis — `true` iff EXACTLY ONE [`Condition`] with the given
6354    /// `kind` appears in this slice (equivalently,
6355    /// [`Self::count_kind`]`(kind) == 1` and
6356    /// [`Self::iter_kind`]`(kind).count() == 1`). Closes the {= 0,
6357    /// = 1, ≥ 2} per-kind cardinality Boolean trichotomy at the slice
6358    /// level; every state maps to EXACTLY ONE of the three arms.
6359    ///
6360    /// Default body: a two-step-short-circuit walk over
6361    /// [`Self::iter_kind`]`(kind)` — pulls up to two hits off the load-
6362    /// bearing per-kind iterator; the primitive returns `true` iff the
6363    /// first is [`Some`] AND the second is [`None`], WITHOUT walking
6364    /// every slot to build [`Self::count_kind`]'s scalar. Short-
6365    /// circuits at the second matching condition — strictly cheaper
6366    /// than [`Self::count_kind`]`(kind) == 1` on every arm with `≥ 2`
6367    /// matches (the primitive returns `false` on the second hit
6368    /// without pulling further). Byte-for-byte peer of
6369    /// [`Self::has_multiple_of_kind`] under the (= 1, ≥ 2) count-axis
6370    /// duality: both compose the SAME two-step short-circuit walk
6371    /// shape, differing only in the second-hit predicate
6372    /// ([`Option::is_none`] here vs [`Option::is_some`] on the many-
6373    /// arm peer).
6374    ///
6375    /// # Sibling to [`Self::lacks_kind`] / [`Self::has_kind`] /
6376    /// [`Self::has_multiple_of_kind`] / [`Self::count_kind`]
6377    ///
6378    /// Middle arm on the per-kind count trichotomy alongside
6379    /// [`Self::lacks_kind`] (= 0 zero-endpoint) and
6380    /// [`Self::has_multiple_of_kind`] (≥ 2 many-arm) — the three
6381    /// Booleans PARTITION the per-kind cardinality scalar's non-
6382    /// negative-integer arms: EXACTLY ONE of the three returns `true`
6383    /// on any given `(slice, kind)` pair. Peer of the tagged-union
6384    /// parent-level [`crate::tagged_union::TaggedUnion::has_unique_populated_kind`]
6385    /// on the whole-parent count axis one struct layer up (single
6386    /// populated slot vs single condition of a given kind). The
6387    /// composition laws
6388    /// `has_unique_of_kind(k) == (count_kind(k) == 1)`,
6389    /// `has_unique_of_kind(k) == (iter_kind(k).count() == 1)`, and
6390    /// `has_unique_of_kind(k) == { iter_kind(k) two-step short-circuit }`
6391    /// bind the per-kind mid-endpoint Boolean projection to the
6392    /// scalar counter primitive at the trait's default body — swept
6393    /// substrate-wide by [`assert_slice_refinement_composition_laws`]
6394    /// as its per-kind mid-endpoint arm alongside the existing per-
6395    /// kind many-arm pin.
6396    ///
6397    /// # Semantics
6398    ///
6399    /// An empty slice returns `false` on every kind (0 matches, not
6400    /// `= 1`). A slice carrying `kind` exactly once (with any other
6401    /// kinds in any multiplicity) returns `true` on THAT kind. A
6402    /// slice carrying `kind` two or more times returns `false` on
6403    /// THAT kind. Multiplicity of OTHER kinds is irrelevant — the
6404    /// primitive projects the slice onto the per-kind count axis for
6405    /// the queried kind alone. Together with `lacks_kind` and
6406    /// `has_multiple_of_kind`, the three arms cover every non-
6407    /// negative multiplicity: `lacks_kind(k)` ↔ 0 matches,
6408    /// `has_unique_of_kind(k)` ↔ 1 match, `has_multiple_of_kind(k)`
6409    /// ↔ ≥ 2 matches.
6410    ///
6411    /// # Compounding future consumers
6412    ///
6413    /// - A boundary-well-formedness coherence check that enforces
6414    ///   "every Process's preconditions carry EXACTLY ONE
6415    ///   [`ConditionKind::ProcessPhase`] entry" reads
6416    ///   `boundary.preconditions.has_unique_of_kind(ConditionKind::ProcessPhase)`
6417    ///   at ONE call site — one two-step short-circuit walk, no
6418    ///   allocation, no scalar comparison against `== 1`.
6419    /// - A `has-unique-of-<kind>` require-tag classifier arm reads
6420    ///   this primitive with no allocation, byte-for-byte peer of
6421    ///   `has-multiple-of-<kind>` under the SAME two-step short-
6422    ///   circuit shape.
6423    /// - A fleet-wide "exactly-one-of-kind detected" audit dump reads
6424    ///   `ConditionKind::ALL.into_iter().filter(|k|
6425    ///   slice.has_unique_of_kind(*k))` at ONE call site.
6426    /// - A future authoring-time linter that surfaces "operator
6427    ///   intended a singleton condition but ended up with 0 or ≥ 2
6428    ///   entries" reaches the three-arm partition through
6429    ///   `!slice.has_unique_of_kind(k)` for the negative arm and
6430    ///   drills down to the specific missing/duplicate case through
6431    ///   `slice.lacks_kind(k)` or `slice.has_multiple_of_kind(k)`
6432    ///   without restating the walk.
6433    ///
6434    /// # Theory grounding
6435    ///
6436    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
6437    ///   The per-kind cardinality-mid-endpoint projection on the
6438    ///   count axis lives at ONE substrate site as a typed two-step-
6439    ///   short-circuit fold through the load-bearing [`Self::iter_kind`]
6440    ///   iterator — byte-for-byte peer of `count_kind(kind)` composed
6441    ///   against `== 1`, but with a second-match short-circuit that
6442    ///   the scalar counter primitive does not offer.
6443    /// - THEORY.md §VI.1 — generation over composition. A new
6444    ///   [`ConditionKind`] variant added to `ALL` reaches this
6445    ///   primitive mechanically through the per-kind iterator — a
6446    ///   slice previously containing no conditions of the new kind
6447    ///   returns `false` on it here, and picks up `true` the moment
6448    ///   an operator authors exactly ONE matching condition (and
6449    ///   returns to `false` the moment a second one appears).
6450    fn has_unique_of_kind(&self, kind: ConditionKind) -> bool {
6451        let mut it = self.iter_kind(kind);
6452        it.next().is_some() && it.next().is_none()
6453    }
6454
6455    /// Boolean cardinality "≤ 1" negation peer of
6456    /// [`Self::has_multiple_of_kind`] on the per-kind count axis —
6457    /// `true` iff AT MOST ONE [`Condition`] with the given `kind`
6458    /// appears in this slice (equivalently, [`Self::count_kind`]
6459    /// `(kind) <= 1` and [`Self::iter_kind`]`(kind).count() <= 1`).
6460    /// Closes the {= 0, = 1, ≥ 1, ≥ 2, ≤ 1} Boolean-cardinality grid
6461    /// on the per-kind axis at the slice level alongside its sibling
6462    /// [`Self::has_multiple_of_kind`] (≥ 2 many-arm) under the
6463    /// definitional negation `!(≥ 2) == (≤ 1)`, and alongside
6464    /// `!has_kind` (= 0 zero-endpoint) OR [`Self::has_unique_of_kind`]
6465    /// (= 1 mid-endpoint) as the trichotomy-union arm. Names the
6466    /// per-kind arrangement space where the slice is
6467    /// EMPTY-OR-SINGLETON for that kind (zero or exactly one match).
6468    ///
6469    /// Default body: `!self.has_multiple_of_kind(kind)` — a
6470    /// definitional Boolean negation of the many-arm primitive.
6471    /// Short-circuits transitively through
6472    /// [`Self::has_multiple_of_kind`]'s two-step short-circuit walk
6473    /// over [`Self::iter_kind`]: returns `true` as soon as the many-
6474    /// arm walk stops with fewer than two matches, WITHOUT walking
6475    /// every slot to build [`Self::count_kind`]'s scalar. Strictly
6476    /// cheaper than [`Self::count_kind`]`(kind) <= 1` on every arm
6477    /// with `≥ 2` matches (short-circuits at the second hit rather
6478    /// than counting further). Byte-for-byte peer of
6479    /// [`Self::has_at_most_one_distinct_kind`] and
6480    /// [`Self::has_at_most_one_missing_kind`] under the (distinct,
6481    /// missing, per-kind) parity: all three compose the SAME
6482    /// definitional negation shape (`!has_multiple_*`) at the slice-
6483    /// level trait's default body, differing only in the many-arm
6484    /// primitive they negate.
6485    ///
6486    /// # Peer to [`Self::has_at_most_one_distinct_kind`] / [`Self::has_at_most_one_missing_kind`]
6487    ///
6488    /// Third axis of the slice-level "≤ 1" negation triad. The
6489    /// distinct-axis peer negates the "≥ 2 distinct kinds present"
6490    /// many-arm; the missing-axis peer negates the "≥ 2 kinds
6491    /// missing" many-arm; this per-kind peer negates the "≥ 2
6492    /// matches of a specific kind" many-arm. Together the three
6493    /// close the "≤ 1" arm on every cardinality axis
6494    /// (distinct-kind, missing-kind, per-kind count) at the SAME
6495    /// slice-level trait under the SAME definitional negation shape.
6496    ///
6497    /// # Sibling to the per-kind Boolean cardinality tetrachotomy
6498    ///
6499    /// Fourth arm of the `{= 0, ≥ 1, = 1, ≥ 2, ≤ 1}` Boolean-
6500    /// cardinality closure on the per-kind axis at the slice level,
6501    /// closing the Boolean-negation grid alongside
6502    /// [`Self::lacks_kind`] (= 0 zero-endpoint),
6503    /// [`Self::has_unique_of_kind`] (= 1 mid-endpoint),
6504    /// [`Self::has_kind`] (≥ 1 halfspace), and
6505    /// [`Self::has_multiple_of_kind`] (≥ 2 many-arm). The {≤ 1, ≥ 2}
6506    /// pair sit on the Boolean-negation axis:
6507    /// `has_at_most_one_of_kind(k) == !has_multiple_of_kind(k)` on
6508    /// every arm. The {0, 1} union arm sits on the trichotomy-union
6509    /// axis: `has_at_most_one_of_kind(k) == lacks_kind(k) ||
6510    /// has_unique_of_kind(k)` on every arm. Both composition laws
6511    /// bind the per-kind "≤ 1" Boolean projection to the sibling
6512    /// primitives at the trait's default body — swept substrate-wide
6513    /// by [`assert_slice_refinement_composition_laws`] as its per-
6514    /// kind "≤ 1" arm alongside the existing per-kind zero-endpoint,
6515    /// mid-endpoint, halfspace, and many-arm pins.
6516    ///
6517    /// # Semantics
6518    ///
6519    /// An empty slice returns `true` on every kind (0 matches, `≤ 1`).
6520    /// A slice carrying `kind` exactly once (with any other kinds in
6521    /// any multiplicity) returns `true` on THAT kind. A slice
6522    /// carrying `kind` two or more times returns `false` on THAT
6523    /// kind. Multiplicity of OTHER kinds is irrelevant — the
6524    /// primitive projects the slice onto the per-kind count axis for
6525    /// the queried kind alone. Together with `lacks_kind` and
6526    /// `has_unique_of_kind`, the "≤ 1" arm equals their union:
6527    /// `has_at_most_one_of_kind(k) ↔ lacks_kind(k) ∨
6528    /// has_unique_of_kind(k)`.
6529    ///
6530    /// # Compounding future consumers
6531    ///
6532    /// - A boundary-well-formedness coherence check that enforces
6533    ///   "every Process's preconditions carry AT MOST ONE
6534    ///   [`ConditionKind::ProcessPhase`] entry" (allowing zero, but
6535    ///   rejecting duplicates) reads
6536    ///   `boundary.preconditions.has_at_most_one_of_kind(ConditionKind::ProcessPhase)`
6537    ///   at ONE call site — one bit-flip on the many-arm's two-step
6538    ///   short-circuit walk, no allocation, no scalar comparison
6539    ///   against `<= 1`. Byte-for-byte peer of the same coherence
6540    ///   check phrased with `!slice.has_multiple_of_kind(k)` at the
6541    ///   callsite, but reads the intent as "at most one" directly.
6542    /// - A `has-at-most-one-of-<kind>` require-tag classifier arm
6543    ///   reaches this primitive with no allocation, closing the
6544    ///   {= 0, = 1, ≥ 1, ≥ 2, ≤ 1} cardinality-Boolean grid on the
6545    ///   per-kind axis at the slice level alongside its sibling
6546    ///   `has-multiple-of-<kind>` under the Boolean negation axis.
6547    /// - A fleet-wide "no duplicate condition of kind detected"
6548    ///   audit dump reads `ConditionKind::ALL.into_iter().filter(|k|
6549    ///   slice.has_at_most_one_of_kind(*k))` at ONE call site
6550    ///   without materializing the negation at every callsite.
6551    /// - A future authoring-time linter that surfaces "operator's
6552    ///   condition slice has no duplicates for any kind" reads
6553    ///   `ConditionKind::ALL.into_iter().all(|k|
6554    ///   slice.has_at_most_one_of_kind(k))` — the whole-slice "no
6555    ///   kind is duplicated" projection composes through the SAME
6556    ///   substrate primitive without restating the negation.
6557    ///
6558    /// # Theory grounding
6559    ///
6560    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
6561    ///   The per-kind cardinality "≤ 1" projection lives at ONE
6562    ///   substrate site as the definitional Boolean negation of
6563    ///   [`Self::has_multiple_of_kind`]; the three composition forms
6564    ///   (`!has_multiple_of_kind(k)`, `count_kind(k) <= 1`, and
6565    ///   `lacks_kind(k) || has_unique_of_kind(k)`) compose through
6566    ///   the SAME two-step-short-circuit walk shape one negation up,
6567    ///   byte-for-byte identical on every arm.
6568    /// - THEORY.md §VI.1 — generation over composition. A new
6569    ///   [`ConditionKind`] variant added to `ALL` reaches this
6570    ///   primitive mechanically through the delegated
6571    ///   [`Self::has_multiple_of_kind`] — a slice previously at the
6572    ///   empty or singleton arm (returned `true` here) that picks up
6573    ///   a second condition of the new variant now has TWO matches
6574    ///   and flips to `false`.
6575    fn has_at_most_one_of_kind(&self, kind: ConditionKind) -> bool {
6576        !self.has_multiple_of_kind(kind)
6577    }
6578
6579    /// Returns the unique [`Condition`] of the given [`ConditionKind`]
6580    /// in this slice, or [`None`] if zero or more than one such
6581    /// [`Condition`] exists — the `Option<&Condition>` witnessing
6582    /// refinement of the Boolean [`Self::has_unique_of_kind`] on the
6583    /// per-kind count axis at the slice level. Default body: a two-
6584    /// step short-circuit walk over [`Self::iter_kind`] — pulls at
6585    /// most two matches, returns the first iff no second exists.
6586    ///
6587    /// # Sibling to [`Self::has_unique_of_kind`]
6588    ///
6589    /// One refinement wider: `has_unique_of_kind` collapses the return
6590    /// to a `bool`; `unique_of_kind` returns the matching
6591    /// `&Condition` so callers can read [`Condition::params`] without
6592    /// a two-pass has+find dance. The composition laws
6593    /// `has_unique_of_kind(k) == unique_of_kind(k).is_some()` and
6594    /// `unique_of_kind(k).map(|c| c.kind) == Some(k)` (when
6595    /// `has_unique_of_kind(k)`, else `None`) bind the Boolean
6596    /// projection to the widened witness at the trait's default body.
6597    ///
6598    /// # Peer to [`Self::unique_distinct_kind`] / [`Self::unique_missing_kind`]
6599    ///
6600    /// Third `Option`-witnessing peer on the slice-level Boolean
6601    /// mid-endpoint algebra: `unique_distinct_kind` witnesses the
6602    /// singleton-populated-distinct arm (`Option<ConditionKind>`),
6603    /// `unique_missing_kind` witnesses the singleton-missing arm
6604    /// (`Option<ConditionKind>`), and this per-kind peer witnesses
6605    /// the singleton-per-kind arm (`Option<&Condition>`). All three
6606    /// collapse `has_unique_*` Booleans to a single-walk `Option`
6607    /// witness of the singleton arm; a regression that drifted any
6608    /// witness from its Boolean sibling surfaces at the substrate's
6609    /// composition-law testkit.
6610    ///
6611    /// # Semantics
6612    ///
6613    /// An empty slice returns [`None`] on every kind. A slice
6614    /// carrying `kind` exactly once returns `Some(&c)` for that `c`.
6615    /// A slice carrying `kind` two or more times returns [`None`]
6616    /// (multiple witnesses collapse to no witness — the
6617    /// `Option<&Condition>` refinement expresses "there is exactly
6618    /// one match, and here it is" as a single type-carried
6619    /// invariant). Multiplicity of other kinds is irrelevant.
6620    ///
6621    /// # Compounding
6622    ///
6623    /// A coherence check that verifies "if exactly one
6624    /// [`ConditionKind::PromQL`] precondition, its params must
6625    /// contain `expr`" reads
6626    /// `slice.unique_of_kind(ConditionKind::PromQL).map(check_params)`
6627    /// at ONE call site — one walk, no allocation, no two-pass
6628    /// `has_unique_of_kind` + `find_kind` dance that would walk the
6629    /// slice twice. A future operator-facing diagnostic that surfaces
6630    /// "the unique JobAttested condition's params" reads
6631    /// `spec.postconditions.unique_of_kind(JobAttested)` and unwraps
6632    /// the params directly — a two-pass phrase leaves the singleton
6633    /// invariant implicit; this peer carries it in the return type.
6634    ///
6635    /// # Theory grounding
6636    ///
6637    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
6638    ///   The `Option<&Condition>` witnessing refinement lives at ONE
6639    ///   substrate site as a two-step short-circuit walk over
6640    ///   [`Self::iter_kind`]; the composition law
6641    ///   `has_unique_of_kind(k) == unique_of_kind(k).is_some()` binds
6642    ///   the Boolean projection to the widened witness at the trait's
6643    ///   default body.
6644    /// - THEORY.md §VI.1 — generation over composition. A new
6645    ///   [`ConditionKind`] variant reaches this primitive
6646    ///   mechanically through the delegated [`Self::iter_kind`] with
6647    ///   no per-caller edit.
6648    fn unique_of_kind(&self, kind: ConditionKind) -> Option<&Condition> {
6649        let mut it = self.iter_kind(kind);
6650        let first = it.next()?;
6651        match it.next() {
6652            None => Some(first),
6653            Some(_) => None,
6654        }
6655    }
6656}
6657
6658/// Iterator yielded by [`ConditionSliceExt::iter_kind`] — the widened
6659/// primitive on the slice-level presence-probe axis. Wraps a
6660/// [`std::slice::Iter`] over `Condition` values with a
6661/// [`ConditionKind`] discriminator; [`Iterator::next`] short-circuits
6662/// via [`std::iter::Iterator::find`] on the wrapped iterator so the
6663/// filter walk is byte-identical to `self.iter().filter(|c| c.kind ==
6664/// kind).next()` without paying for the anonymous-closure type
6665/// erasure a chained-adapter return position would carry.
6666///
6667/// # Why a named type
6668///
6669/// [`ConditionSliceExt::iter_kind`] returns this concrete type rather
6670/// than `impl Iterator<Item = &Condition>` so downstream consumers
6671/// (a fleet-wide audit dump that stores match streams in a struct
6672/// field, a coherence check that composes the iterator against
6673/// [`std::iter::Chain`] across pre-/post-conditions) name the
6674/// primitive's return without pulling in RPITIT's unnameable
6675/// per-callsite type. [`Boundary::iter_condition_kind`] and
6676/// [`crate::ephemeral::EphemeralSpec::iter_condition_kind`] chain two
6677/// [`KindMatches`] iterators via [`Iterator::chain`] — the resulting
6678/// [`std::iter::Chain<KindMatches<'_>, KindMatches<'_>>`] is itself
6679/// a standard nameable type.
6680pub struct KindMatches<'a> {
6681    inner: std::slice::Iter<'a, Condition>,
6682    kind: ConditionKind,
6683}
6684
6685impl<'a> Iterator for KindMatches<'a> {
6686    type Item = &'a Condition;
6687
6688    fn next(&mut self) -> Option<Self::Item> {
6689        self.inner.by_ref().find(|c| c.kind == self.kind)
6690    }
6691}
6692
6693impl ConditionSliceExt for [Condition] {
6694    fn iter_kind(&self, kind: ConditionKind) -> KindMatches<'_> {
6695        KindMatches {
6696            inner: self.iter(),
6697            kind,
6698        }
6699    }
6700}
6701
6702/// Generic slice-level substrate testkit — pins the FOUR composition
6703/// laws that bind the [`ConditionSliceExt`] refinement algebra
6704/// (`iter_kind` → `find_kind` → `has_kind` → `count_kind`) at ONE
6705/// call site per authored arrangement, sweeping [`ConditionKind::ALL`].
6706///
6707/// The [`ConditionSliceExt`] trait publishes four refinements on the
6708/// slice-level presence-probe axis:
6709///
6710/// | refinement | return type | default body                        |
6711/// |------------|-------------|-------------------------------------|
6712/// | `iter_kind`| [`KindMatches`]      | (widened primitive, required)      |
6713/// | `find_kind`| `Option<&Condition>` | `self.iter_kind(k).next()`         |
6714/// | `has_kind` | `bool`               | `self.find_kind(k).is_some()`      |
6715/// | `count_kind`| `usize`             | `self.iter_kind(k).count()`        |
6716///
6717/// The three coarser refinements are typed projections of the widened
6718/// primitive by construction. The composition laws that bind them
6719/// (and therefore surface any implementor that overrode a default
6720/// with a divergent walk shape — a stored-length cache that drifted,
6721/// a `.rev().find(...)` returning trailing-first, a `.step_by(2)`
6722/// artifact from a copy-paste of `iter_kind`) sweep at ONE typed
6723/// substrate site through this primitive:
6724///
6725/// 1. **`find ↔ iter`**: `find_kind(k) == iter_kind(k).next()` — the
6726///    first-match probe equals the widened stream's first yield.
6727/// 2. **`count ↔ iter`**: `count_kind(k) == iter_kind(k).count()` —
6728///    the cardinality probe equals the widened stream's yield count.
6729/// 3. **`has ↔ find`**: `has_kind(k) == find_kind(k).is_some()` —
6730///    the presence bit equals the first-match probe's `is_some()`.
6731/// 4. **`has ↔ count`**: `has_kind(k) == (count_kind(k) > 0)` — the
6732///    presence bit equals the cardinality's positivity test (the
6733///    dual composition path from `has` back to the widened primitive
6734///    that doesn't go through `find`).
6735///
6736/// Pre-lift each composition law lived at its own hand-authored
6737/// nested-`for` loop test in [`tatara_process::boundary`] tests
6738/// (`condition_slice_find_kind_equals_iter_kind_next`,
6739/// `condition_slice_count_kind_equals_iter_kind_count`,
6740/// `condition_slice_has_kind_equals_find_kind_is_some`,
6741/// `condition_slice_has_and_find_equal_count_greater_than_zero`) —
6742/// four sibling test bodies whose only per-law knobs were the
6743/// projection functions being bridged. Post-lift each authored
6744/// arrangement (empty, single-element, dual-populated, duplicate-
6745/// populated) pins ALL FOUR laws through ONE
6746/// `assert_slice_refinement_composition_laws(slice)` call whose body
6747/// is the substrate primitive's own sweep.
6748///
6749/// The primitive binds `<S: ConditionSliceExt + ?Sized>` so both a
6750/// bare `&[Condition]` and any future implementor of the trait
6751/// (a wrapper type with additional invariants, an alternative slice
6752/// projection over a builder's staging Vec) picks up the four-law
6753/// composition contract through ONE call site. `?Sized` lets the
6754/// caller pass `slice.as_slice()` or `&owned[..]` without an
6755/// intermediate reference dance.
6756///
6757/// # Compounding
6758///
6759/// A FIFTH refinement added to [`ConditionSliceExt`] (a hypothetical
6760/// `nth_kind(k, n) -> Option<&Condition>` for indexed match access,
6761/// a `distinct_kinds()` aggregate that returns which kinds appear at
6762/// least once, a `has_kind_matching(pred)` closure-based predicate
6763/// probe) lands its composition-law pins as ONE new arm inside this
6764/// primitive's sweep body. Every downstream test that already reaches
6765/// this primitive picks up the fifth-refinement pin mechanically —
6766/// no per-arrangement author-time enumeration of the new law across
6767/// the four sibling composition-law sites, no re-authored `for kind
6768/// in ConditionKind::ALL { … }` sweep at every consumer.
6769///
6770/// Symmetrical shape to
6771/// [`crate::tagged_union::assert_find_agrees_with_has`] on the
6772/// tagged-union parent axis: both project a widened-refinement /
6773/// coarser-refinement composition law contract onto ONE typed
6774/// substrate call site, both bind `<T: /* refinement carrier */>`
6775/// generically, both sweep the addressed closed set
6776/// ([`ConditionKind::ALL`] here, `<T::Kind as ClosedSet>::ALL`
6777/// there). The two primitives close the "refinement axis composes"
6778/// invariant at two adjacent typescape sites — one per closed-set-
6779/// addressed slice-level refinement, one per closed-set-addressed
6780/// tagged-union parent-level refinement.
6781///
6782/// Theory anchor: THEORY.md §II.1 invariant 5 — composition preserves
6783/// proofs. The four coarser refinements are typed projections of the
6784/// widened primitive, and this substrate primitive turns each
6785/// projection's composition law from doc-prose into a first-class
6786/// typed theorem provable generically over any
6787/// `S: ConditionSliceExt + ?Sized`. THEORY.md §VI.1 — generation over
6788/// composition; a new [`ConditionKind`] variant added to `ALL` reaches
6789/// every downstream composition-law consumer through the SAME
6790/// closed-set sweep with no per-caller edit.
6791#[track_caller]
6792pub fn assert_slice_refinement_composition_laws<S>(slice: &S)
6793where
6794    S: ConditionSliceExt + ?Sized,
6795{
6796    let distinct = slice.distinct_kinds();
6797    for kind in ConditionKind::ALL {
6798        let find_result = slice.find_kind(kind);
6799        let has_result = slice.has_kind(kind);
6800        let count_result = slice.count_kind(kind);
6801        let iter_next_kind = slice.iter_kind(kind).next().map(|c| c.kind);
6802        let iter_count = slice.iter_kind(kind).count();
6803
6804        // find ↔ iter
6805        assert_eq!(
6806            find_result.map(|c| c.kind),
6807            iter_next_kind,
6808            "find_kind({kind:?}) drifted from iter_kind({kind:?}).next()",
6809        );
6810        // count ↔ iter
6811        assert_eq!(
6812            count_result, iter_count,
6813            "count_kind({kind:?}) drifted from iter_kind({kind:?}).count()",
6814        );
6815        // has ↔ find
6816        assert_eq!(
6817            has_result,
6818            find_result.is_some(),
6819            "has_kind({kind:?}) drifted from find_kind({kind:?}).is_some()",
6820        );
6821        // has ↔ count
6822        assert_eq!(
6823            has_result,
6824            count_result > 0,
6825            "has_kind({kind:?}) drifted from (count_kind({kind:?}) > 0)",
6826        );
6827        // distinct ↔ has (per-kind membership on the closed-set-inversion axis)
6828        assert_eq!(
6829            distinct.contains(&kind),
6830            has_result,
6831            "distinct_kinds().contains({kind:?}) drifted from has_kind({kind:?})",
6832        );
6833
6834        // has_multiple_of_kind ↔ (count_kind >= 2) — the Boolean
6835        // cardinality many-arm projection on the per-kind count axis.
6836        // Peer of `has ↔ (count > 0)` above under the {=0, ≥1, ≥2}
6837        // per-kind count trichotomy; the per-kind many-arm sits at the
6838        // ≥ 2 arm. A regression that dropped the second-match short-
6839        // circuit (returning any ≥ 1 arm), swapped the sides, or
6840        // conflated with the whole-slice `has_multiple_distinct_kinds`
6841        // (one axis over) surfaces HERE at the substrate boundary, not
6842        // as silent drift at every downstream `has-multiple-of-<kind>`
6843        // require-tag classifier or fleet-wide duplicate-condition
6844        // audit callsite. Byte-for-byte peer of
6845        // `has_multiple_distinct_kinds ↔ (distinct_kind_count >= 2)`
6846        // one axis over under the SAME two-step short-circuit walk
6847        // shape via the per-kind iterator instead of the distinct
6848        // iterator.
6849        let via_iter_multi_kind = {
6850            let mut it = slice.iter_kind(kind);
6851            it.next().is_some() && it.next().is_some()
6852        };
6853        assert_eq!(
6854            slice.has_multiple_of_kind(kind),
6855            count_result >= 2,
6856            "has_multiple_of_kind({kind:?}) drifted from (count_kind({kind:?}) >= 2)",
6857        );
6858        assert_eq!(
6859            slice.has_multiple_of_kind(kind),
6860            iter_count >= 2,
6861            "has_multiple_of_kind({kind:?}) drifted from (iter_kind({kind:?}).count() >= 2)",
6862        );
6863        assert_eq!(
6864            slice.has_multiple_of_kind(kind),
6865            via_iter_multi_kind,
6866            "has_multiple_of_kind({kind:?}) drifted from iter_kind({kind:?}) two-step short-circuit",
6867        );
6868
6869        // has_unique_of_kind ↔ (count_kind == 1) — the Boolean
6870        // cardinality mid-endpoint projection on the per-kind count
6871        // axis. Middle arm of the {=0, =1, ≥2} per-kind count
6872        // trichotomy alongside `lacks_kind` (=0) and
6873        // `has_multiple_of_kind` (≥2); the three Booleans partition
6874        // every non-negative multiplicity — EXACTLY ONE fires on any
6875        // given `(slice, kind)` pair. A regression that dropped the
6876        // second-match short-circuit (returning any ≥ 1 arm as
6877        // `true`), inverted the second-hit predicate (returning `true`
6878        // on `≥ 2` matches), or conflated with `has_unique_populated_kind`
6879        // (one struct layer up on the tagged-union parent axis)
6880        // surfaces HERE at the substrate boundary, not as silent drift
6881        // at every downstream `has-unique-of-<kind>` require-tag
6882        // classifier or fleet-wide singleton-condition audit callsite.
6883        // Byte-for-byte peer of `has_multiple_of_kind ↔ (count_kind
6884        // >= 2)` above under the SAME two-step short-circuit walk
6885        // shape via the per-kind iterator.
6886        let via_iter_unique_kind = {
6887            let mut it = slice.iter_kind(kind);
6888            it.next().is_some() && it.next().is_none()
6889        };
6890        assert_eq!(
6891            slice.has_unique_of_kind(kind),
6892            count_result == 1,
6893            "has_unique_of_kind({kind:?}) drifted from (count_kind({kind:?}) == 1)",
6894        );
6895        assert_eq!(
6896            slice.has_unique_of_kind(kind),
6897            iter_count == 1,
6898            "has_unique_of_kind({kind:?}) drifted from (iter_kind({kind:?}).count() == 1)",
6899        );
6900        assert_eq!(
6901            slice.has_unique_of_kind(kind),
6902            via_iter_unique_kind,
6903            "has_unique_of_kind({kind:?}) drifted from iter_kind({kind:?}) two-step short-circuit",
6904        );
6905
6906        // unique_of_kind ↔ has_unique_of_kind — the Option<&Condition>
6907        // witnessing refinement of the Boolean mid-endpoint. Three
6908        // composition laws bind the witness to its siblings:
6909        //   (1) has_unique_of_kind(k) == unique_of_kind(k).is_some()
6910        //   (2) unique_of_kind(k).map(|c| c.kind) == Some(k) iff
6911        //       has_unique_of_kind(k) else None (the witness carries
6912        //       the queried kind by construction)
6913        //   (3) unique_of_kind(k) points at the SAME &Condition
6914        //       find_kind(k) returned on the singleton arm (both
6915        //       yield the earliest — and only — match)
6916        // A regression that dropped the second-match short-circuit
6917        // (returning `Some(first)` on any `≥ 1` arm), inverted the
6918        // second-hit predicate (returning `None` on the singleton
6919        // arm), or returned a non-matching `&Condition` (swapped
6920        // slots on the two-slice chain lift) surfaces HERE at the
6921        // substrate boundary rather than as silent drift at every
6922        // downstream witness callsite. Byte-for-byte peer of
6923        // `has_unique_of_kind ↔ iter_kind two-step short-circuit` above
6924        // under the SAME two-step short-circuit walk shape — this arm
6925        // additionally pins the yielded `&Condition` identity, which
6926        // the Boolean projection loses.
6927        let unique_result = slice.unique_of_kind(kind);
6928        assert_eq!(
6929            unique_result.is_some(),
6930            slice.has_unique_of_kind(kind),
6931            "unique_of_kind({kind:?}).is_some() drifted from has_unique_of_kind({kind:?})",
6932        );
6933        assert_eq!(
6934            unique_result.map(|c| c.kind),
6935            if slice.has_unique_of_kind(kind) {
6936                Some(kind)
6937            } else {
6938                None
6939            },
6940            "unique_of_kind({kind:?}).map(|c| c.kind) must yield Some({kind:?}) iff \
6941             has_unique_of_kind, else None",
6942        );
6943        // Pointer-identity witness — the singleton match returned by
6944        // `unique_of_kind` is the same allocation `find_kind` yields.
6945        assert_eq!(
6946            unique_result.map(|c| c as *const Condition),
6947            if slice.has_unique_of_kind(kind) {
6948                find_result.map(|c| c as *const Condition)
6949            } else {
6950                None
6951            },
6952            "unique_of_kind({kind:?}) must point at the same &Condition as \
6953             find_kind({kind:?}) on the singleton arm",
6954        );
6955
6956        // Trichotomy partition pin — EXACTLY ONE of {lacks_kind,
6957        // has_unique_of_kind, has_multiple_of_kind} fires on any
6958        // (slice, kind) pair. A regression that broke exclusivity
6959        // (two arms fire simultaneously on some kind) or coverage
6960        // (no arm fires on some kind) surfaces HERE, not as silent
6961        // drift at every downstream three-arm classifier callsite.
6962        let arms_true = [
6963            slice.lacks_kind(kind),
6964            slice.has_unique_of_kind(kind),
6965            slice.has_multiple_of_kind(kind),
6966        ]
6967        .into_iter()
6968        .filter(|&b| b)
6969        .count();
6970        assert_eq!(
6971            arms_true, 1,
6972            "per-kind count trichotomy {{lacks_kind, has_unique_of_kind, has_multiple_of_kind}} \
6973             must have EXACTLY one arm true for {kind:?}, got {arms_true}",
6974        );
6975    }
6976
6977    // distinct ↔ ALL-filter (canonical subsequence — closed-set-inversion
6978    // walks ConditionKind::ALL in order, filters by has_kind, dedups by
6979    // construction). A regression that (a) returned duplicates (a naive
6980    // `.iter().map(|c| c.kind).collect()` override that skipped dedup),
6981    // (b) drifted the walk order from ConditionKind::ALL to slice-encounter
6982    // order, or (c) returned a superset containing absent kinds surfaces
6983    // HERE at the substrate boundary.
6984    let canonical: Vec<ConditionKind> = ConditionKind::ALL
6985        .into_iter()
6986        .filter(|k| slice.has_kind(*k))
6987        .collect();
6988    assert_eq!(
6989        distinct, canonical,
6990        "distinct_kinds() must yield ConditionKind::ALL-ordered subsequence of kinds where has_kind is true (no duplicates, canonical order)",
6991    );
6992
6993    // iter_distinct_kinds ↔ distinct_kinds — the load-bearing iterator
6994    // peer of the closed-set-inversion widened primitive. `distinct_kinds`'s
6995    // default body IS `self.iter_distinct_kinds().collect()`, so the
6996    // composition law `distinct_kinds() ==
6997    // iter_distinct_kinds().collect::<Vec<_>>()` holds by construction —
6998    // a regression that overrode either surface with a divergent walk
6999    // (short-circuit skipping a kind, drifting the walk order from
7000    // ConditionKind::ALL, forgetting the `has_kind` filter, or divergent
7001    // yield sequences between repeated invocations) surfaces HERE at the
7002    // substrate boundary, not as silent skew between the iter-based fold
7003    // callsite and the Vec-based callsite. Symmetrical to the tagged-union
7004    // parent-level substrate testkit
7005    // `assert_iter_populated_kinds_matches_populated_kinds` under a
7006    // POSITIVE point-probe.
7007    let via_iter_distinct: Vec<ConditionKind> = slice.iter_distinct_kinds().collect();
7008    assert_eq!(
7009        via_iter_distinct, distinct,
7010        "iter_distinct_kinds().collect::<Vec<_>>() drifted from distinct_kinds()",
7011    );
7012    let via_iter_distinct_again: Vec<ConditionKind> = slice.iter_distinct_kinds().collect();
7013    assert_eq!(
7014        via_iter_distinct, via_iter_distinct_again,
7015        "iter_distinct_kinds() must be pure over &self — repeated collect diverged",
7016    );
7017
7018    // distinct_kind_count ↔ distinct_kinds.len() — the scalar
7019    // cardinality projection of the closed-set-inversion widened
7020    // primitive. A regression that overrode `distinct_kind_count` to
7021    // skip a kind, double-count a slot, or drift the walk from
7022    // `ConditionKind::ALL` surfaces HERE at the substrate boundary,
7023    // not as silent drift at every downstream `distinct-count-<n>`
7024    // require-tag classifier or audit-dump callsite.
7025    assert_eq!(
7026        slice.distinct_kind_count(),
7027        distinct.len(),
7028        "distinct_kind_count() drifted from distinct_kinds().len()",
7029    );
7030
7031    // missing ↔ has (per-kind complement on the closed-set-inversion
7032    // axis). Byte-for-byte peer to the `distinct ↔ has` arm above: the
7033    // present-side widened primitive `distinct_kinds` binds to
7034    // `has_kind` via `contains(&k) == has_kind(k)`; the missing-side
7035    // widened primitive `missing_kinds` binds via
7036    // `contains(&k) == !has_kind(k)` — the SAME point-probe primitive
7037    // reached under a negated predicate. A regression that overrode
7038    // `missing_kinds` to omit the negation (returning `distinct_kinds`
7039    // instead), inverted the wrong side, or dropped a variant surfaces
7040    // HERE.
7041    let missing = slice.missing_kinds();
7042    for kind in ConditionKind::ALL {
7043        assert_eq!(
7044            missing.contains(&kind),
7045            !slice.has_kind(kind),
7046            "missing_kinds().contains({kind:?}) drifted from !has_kind({kind:?})",
7047        );
7048    }
7049
7050    // missing ↔ ALL-filter (canonical subsequence — closed-set
7051    // complement walks ConditionKind::ALL in order, filters by
7052    // !has_kind, dedups by construction). Peer to the `distinct ↔
7053    // ALL-filter` arm above; catches ordering + dedup drift on the
7054    // complement side that the per-kind membership arm cannot detect
7055    // on its own.
7056    let canonical_missing: Vec<ConditionKind> = ConditionKind::ALL
7057        .into_iter()
7058        .filter(|k| !slice.has_kind(*k))
7059        .collect();
7060    assert_eq!(
7061        missing, canonical_missing,
7062        "missing_kinds() must yield ConditionKind::ALL-ordered subsequence of kinds where has_kind is false (no duplicates, canonical order)",
7063    );
7064
7065    // iter_missing_kinds ↔ missing_kinds — the load-bearing iterator peer
7066    // of the closed-set-complement widened primitive on the missing side.
7067    // `missing_kinds`'s default body IS `self.iter_missing_kinds().collect()`,
7068    // so the composition law
7069    // `missing_kinds() == iter_missing_kinds().collect::<Vec<_>>()` holds by
7070    // construction. Byte-for-byte peer of the `iter_distinct_kinds ↔
7071    // distinct_kinds` arm above under a NEGATED point-probe: a regression
7072    // that dropped the negation (returning `iter_distinct_kinds`), skipped
7073    // a kind on the complement side, or drifted the walk from
7074    // `ConditionKind::ALL` surfaces HERE at the substrate boundary.
7075    // Symmetrical to the tagged-union parent-level substrate testkit
7076    // `assert_iter_missing_kinds_matches_missing_kinds` under a NEGATED
7077    // point-probe.
7078    let via_iter_missing: Vec<ConditionKind> = slice.iter_missing_kinds().collect();
7079    assert_eq!(
7080        via_iter_missing, missing,
7081        "iter_missing_kinds().collect::<Vec<_>>() drifted from missing_kinds()",
7082    );
7083    let via_iter_missing_again: Vec<ConditionKind> = slice.iter_missing_kinds().collect();
7084    assert_eq!(
7085        via_iter_missing, via_iter_missing_again,
7086        "iter_missing_kinds() must be pure over &self — repeated collect diverged",
7087    );
7088
7089    // (distinct, missing) partition ConditionKind::ALL — three peer
7090    // laws that bind the closed-set-inversion widened primitive
7091    // `distinct_kinds` to its complement peer `missing_kinds`:
7092    //
7093    // 1. Disjoint: every kind appears in AT MOST one of the two sets.
7094    // 2. Covering: every kind appears in AT LEAST one of the two sets
7095    //    (equivalent to the union covering ConditionKind::ALL).
7096    // 3. Cardinality partition: `distinct.len() + missing.len() ==
7097    //    ConditionKind::ALL.len()` — the scalar consequence of (1) +
7098    //    (2) that a caller reaching for the cardinality peer would
7099    //    otherwise pay for the two allocations at every callsite.
7100    for kind in ConditionKind::ALL {
7101        assert!(
7102            !(distinct.contains(&kind) && missing.contains(&kind)),
7103            "(distinct_kinds, missing_kinds) partition invariant violated — both contain {kind:?}",
7104        );
7105        assert!(
7106            distinct.contains(&kind) || missing.contains(&kind),
7107            "(distinct_kinds, missing_kinds) partition invariant violated — neither contains {kind:?}",
7108        );
7109    }
7110    assert_eq!(
7111        distinct.len() + missing.len(),
7112        ConditionKind::ALL.len(),
7113        "(distinct_kinds, missing_kinds) cardinality partition drift — sum {} ≠ ConditionKind::ALL.len() {}",
7114        distinct.len() + missing.len(),
7115        ConditionKind::ALL.len(),
7116    );
7117
7118    // missing_kind_count ↔ missing_kinds.len() — the scalar cardinality
7119    // projection of the closed-set-complement widened primitive. A
7120    // regression that overrode `missing_kind_count` to drop the
7121    // negation (returning `distinct_kind_count`), skip a kind, double-
7122    // count a slot, or drift the walk from `ConditionKind::ALL`
7123    // surfaces HERE at the substrate boundary, not as silent drift at
7124    // every downstream `condition-kinds-missing-<n>` require-tag
7125    // classifier or gap-analysis-dashboard callsite.
7126    assert_eq!(
7127        slice.missing_kind_count(),
7128        missing.len(),
7129        "missing_kind_count() drifted from missing_kinds().len()",
7130    );
7131
7132    // (distinct_kind_count, missing_kind_count) partition
7133    // ConditionKind::ALL's cardinality — the scalar consequence of the
7134    // widened-primitive partition law `distinct ∪ missing == ALL,
7135    // disjoint` above. A regression that (a) drifted the scalar
7136    // cardinality peer from the widened primitive on either side or
7137    // (b) drifted the partition invariant surfaces HERE at ONE typed
7138    // arm rather than as silent drift at every scalar-cardinality
7139    // callsite that reaches for the sum.
7140    assert_eq!(
7141        slice.distinct_kind_count() + slice.missing_kind_count(),
7142        ConditionKind::ALL.len(),
7143        "(distinct_kind_count, missing_kind_count) scalar partition drift — sum {} ≠ ConditionKind::ALL.len() {}",
7144        slice.distinct_kind_count() + slice.missing_kind_count(),
7145        ConditionKind::ALL.len(),
7146    );
7147
7148    // first_distinct_kind ↔ distinct_kinds.first().copied() — the
7149    // earliest-element scalar projection of the closed-set-inversion
7150    // widened primitive. Peer of `distinct_kind_count ↔ distinct_kinds
7151    // .len()` on the scalar-projection axis: where the cardinality peer
7152    // collapses the SET to its length, the earliest-element peer
7153    // collapses the SET to its first element. A regression that
7154    // overrode `first_distinct_kind` to skip a kind, drift the walk
7155    // from ConditionKind::ALL, forget the short-circuit (returning
7156    // the LAST hit), or diverge from the widened primitive's canonical
7157    // ordering surfaces HERE at the substrate boundary, not as silent
7158    // drift at every downstream `first-distinct-<kind>` require-tag
7159    // classifier callsite.
7160    assert_eq!(
7161        slice.first_distinct_kind(),
7162        distinct.first().copied(),
7163        "first_distinct_kind() drifted from distinct_kinds().first().copied()",
7164    );
7165
7166    // first_missing_kind ↔ missing_kinds.first().copied() — the
7167    // earliest-element scalar projection of the closed-set-complement
7168    // widened primitive. Byte-for-byte peer of `first_distinct_kind`
7169    // one axis over under a negated predicate: where
7170    // `first_distinct_kind` scalar-projects the closed-set-INVERSION
7171    // widened primitive onto its earliest element, this arm scalar-
7172    // projects the closed-set-COMPLEMENT widened primitive onto its
7173    // earliest element. A regression that overrode `first_missing_kind`
7174    // to drop the negation (returning `first_distinct_kind`), skip a
7175    // kind, drift the walk from ConditionKind::ALL, or forget the
7176    // short-circuit (returning the LAST missing hit) surfaces HERE at
7177    // the substrate boundary, not as silent drift at every downstream
7178    // `first-missing-<kind>` require-tag classifier callsite.
7179    assert_eq!(
7180        slice.first_missing_kind(),
7181        missing.first().copied(),
7182        "first_missing_kind() drifted from missing_kinds().first().copied()",
7183    );
7184
7185    // last_distinct_kind ↔ distinct_kinds.last().copied() — the
7186    // latest-element scalar projection of the closed-set-inversion
7187    // widened primitive. Time-reversed peer of `first_distinct_kind
7188    // ↔ distinct_kinds.first().copied()` under the SAME `has_kind`
7189    // predicate but with the closed-set walk reversed: where the
7190    // earliest-element peer picks the smallest ALL index that hits,
7191    // this arm picks the LARGEST. A regression that overrode
7192    // `last_distinct_kind` to skip a kind, drift the walk direction
7193    // (returning `first_distinct_kind`), forget the short-circuit
7194    // (returning `distinct_kinds().rev().next()` allocation), or
7195    // diverge from the widened primitive's canonical ordering
7196    // surfaces HERE at the substrate boundary, not as silent drift
7197    // at every downstream `last-distinct-<kind>` require-tag
7198    // classifier callsite.
7199    assert_eq!(
7200        slice.last_distinct_kind(),
7201        distinct.last().copied(),
7202        "last_distinct_kind() drifted from distinct_kinds().last().copied()",
7203    );
7204
7205    // last_missing_kind ↔ missing_kinds.last().copied() — the
7206    // latest-element scalar projection of the closed-set-complement
7207    // widened primitive. Byte-for-byte peer of `last_distinct_kind`
7208    // one axis over under a NEGATED predicate: where
7209    // `last_distinct_kind` scalar-projects the closed-set-INVERSION
7210    // widened primitive onto its LATEST element, this arm scalar-
7211    // projects the closed-set-COMPLEMENT widened primitive onto its
7212    // LATEST element. A regression that overrode `last_missing_kind`
7213    // to drop the negation (returning `last_distinct_kind`), reverse
7214    // the walk direction (returning `first_missing_kind`), skip a
7215    // kind, or forget the short-circuit surfaces HERE at the
7216    // substrate boundary, not as silent drift at every downstream
7217    // `last-missing-<kind>` require-tag classifier callsite.
7218    assert_eq!(
7219        slice.last_missing_kind(),
7220        missing.last().copied(),
7221        "last_missing_kind() drifted from missing_kinds().last().copied()",
7222    );
7223
7224    // is_kind_saturated ↔ (missing_kind_count == 0) — the Boolean
7225    // saturation-endpoint projection of the closed-set-complement
7226    // scalar cardinality. Peer of `first_missing_kind ↔ missing_kinds
7227    // .first().copied()` on the endpoint-projection axis: where the
7228    // earliest-element peer collapses the missing SET to its first
7229    // element, this Boolean peer collapses the missing scalar to its
7230    // zero-arm test. A regression that overrode `is_kind_saturated` to
7231    // drop the negation (returning `slice.is_empty()`), skip a kind,
7232    // or drift the walk from `ConditionKind::ALL` surfaces HERE at
7233    // the substrate boundary, not as silent drift at every downstream
7234    // `is-kind-saturated` require-tag classifier or fleet-wide gap-
7235    // analysis dashboard callsite. Byte-for-byte peer of
7236    // `crate::tagged_union::TaggedUnion::is_saturated` one struct-
7237    // layer up under the same `<CLOSED_SET>::ALL.iter().all(has)`
7238    // short-circuit shape.
7239    assert_eq!(
7240        slice.is_kind_saturated(),
7241        slice.missing_kind_count() == 0,
7242        "is_kind_saturated() drifted from (missing_kind_count() == 0)",
7243    );
7244    assert_eq!(
7245        slice.is_kind_saturated(),
7246        missing.is_empty(),
7247        "is_kind_saturated() drifted from missing_kinds().is_empty()",
7248    );
7249
7250    // is_kind_empty ↔ (distinct_kind_count == 0) — the Boolean cardinality
7251    // zero-endpoint projection of the closed-set-inversion scalar
7252    // cardinality. Axis-parity mirror of `is_kind_saturated ↔
7253    // (missing_kind_count == 0)` on the closed-set-inversion axis: where
7254    // the saturation-endpoint peer collapses the missing scalar to its
7255    // zero-arm test, this zero-endpoint peer collapses the distinct
7256    // scalar to its zero-arm test. Together the two Booleans name the
7257    // (empty, saturated) endpoints of the (distinct, missing)
7258    // partition — on any `N ≥ 1` closed set at most ONE of
7259    // `is_kind_empty()` and `is_kind_saturated()` returns `true`; on the
7260    // `N == 0` closed set both return `true` vacuously. Also pins the
7261    // definitional negation `is_kind_empty() == !has_any_distinct_kind()`
7262    // binding this zero-endpoint Boolean projection to the at-least-one
7263    // halfspace peer on the SAME distinct axis. A regression that
7264    // overrode `is_kind_empty` to drop the negation (returning
7265    // `has_any_distinct_kind`), swap the wrong side (returning
7266    // `is_kind_saturated`), skip a kind, or drift the walk from
7267    // `ConditionKind::ALL` surfaces HERE at the substrate boundary, not
7268    // as silent drift at every downstream `is-kind-empty` require-tag
7269    // classifier or fleet-wide empty-coverage dashboard callsite. Byte-
7270    // for-byte peer of `crate::tagged_union::TaggedUnion::is_empty` one
7271    // struct-layer up under the SAME zero-endpoint short-circuit shape.
7272    assert_eq!(
7273        slice.is_kind_empty(),
7274        slice.distinct_kind_count() == 0,
7275        "is_kind_empty() drifted from (distinct_kind_count() == 0)",
7276    );
7277    assert_eq!(
7278        slice.is_kind_empty(),
7279        distinct.is_empty(),
7280        "is_kind_empty() drifted from distinct_kinds().is_empty()",
7281    );
7282    assert_eq!(
7283        slice.is_kind_empty(),
7284        !slice.has_any_distinct_kind(),
7285        "is_kind_empty() drifted from !has_any_distinct_kind()",
7286    );
7287    assert_eq!(
7288        slice.is_kind_empty(),
7289        slice.iter_distinct_kinds().next().is_none(),
7290        "is_kind_empty() drifted from iter_distinct_kinds().next().is_none()",
7291    );
7292    assert_eq!(
7293        slice.is_kind_empty(),
7294        slice.first_distinct_kind().is_none(),
7295        "is_kind_empty() drifted from first_distinct_kind().is_none()",
7296    );
7297
7298    // is_kind_partially_covered ↔ !is_kind_empty && !is_kind_saturated —
7299    // the Boolean cardinality parent-state middle-arm projection on the
7300    // closed-set partition. Third and final arm of the trichotomy
7301    // (empty, partially covered, saturated) at the slice level,
7302    // closing the natural partition alongside `is_kind_empty` (=0
7303    // zero-endpoint on the distinct axis) and `is_kind_saturated`
7304    // (=0 zero-endpoint on the missing axis). Together the three
7305    // Booleans partition the (distinct_kind_count, missing_kind_count)
7306    // product at (0, N), (open, open), and (N, 0) respectively — on
7307    // any `N ≥ 1` closed set at most ONE returns `true`; the vacuous
7308    // `N == 0` case is impossible here because `ConditionKind::ALL`
7309    // carries ≥ 1 variant by construction. A regression that
7310    // overrode `is_kind_partially_covered` to drop one bit of the
7311    // fused walk (returning `has_any_distinct_kind` — TOO LOOSE,
7312    // admits saturated slices as partial), forget the pair short-
7313    // circuit (returning a scalar comparison
7314    // `distinct_kind_count > 0 && distinct_kind_count < ALL.len()`
7315    // that walks every slot), or swap the wrong side (returning
7316    // `is_kind_empty || is_kind_saturated` — the negation of the
7317    // middle-arm on any `N ≥ 1` closed set) surfaces HERE at the
7318    // substrate boundary, not as silent drift at every downstream
7319    // `is-kind-partially-covered` require-tag classifier or mixed-
7320    // coverage diagnostic callsite. Byte-for-byte peer of
7321    // `crate::tagged_union::TaggedUnion::is_partially_populated` one
7322    // struct-layer up under the SAME fused short-circuit walk shape,
7323    // and byte-for-byte peer of the trichotomy partition law
7324    // `is_empty + is_partially_populated + is_saturated == 1`
7325    // pinned one struct-layer up by
7326    // `crate::tagged_union::assert_is_partially_populated_matches_cardinality`.
7327    // Also pins the paired-halfspace composition
7328    // `is_kind_partially_covered() == has_any_distinct_kind() &&
7329    // has_any_missing_kind()` and the paired-scalar composition
7330    // `is_kind_partially_covered() == (distinct_kind_count() > 0 &&
7331    // missing_kind_count() > 0)` binding this Boolean projection to the
7332    // at-least-one halfspace + scalar peers on BOTH axes.
7333    assert_eq!(
7334        slice.is_kind_partially_covered(),
7335        !slice.is_kind_empty() && !slice.is_kind_saturated(),
7336        "is_kind_partially_covered() drifted from (!is_kind_empty() && !is_kind_saturated())",
7337    );
7338    assert_eq!(
7339        slice.is_kind_partially_covered(),
7340        slice.has_any_distinct_kind() && slice.has_any_missing_kind(),
7341        "is_kind_partially_covered() drifted from (has_any_distinct_kind() && has_any_missing_kind())",
7342    );
7343    assert_eq!(
7344        slice.is_kind_partially_covered(),
7345        slice.distinct_kind_count() > 0 && slice.missing_kind_count() > 0,
7346        "is_kind_partially_covered() drifted from (distinct_kind_count() > 0 && missing_kind_count() > 0)",
7347    );
7348    // Trichotomy partition law — EXACTLY ONE of
7349    // `is_kind_empty`, `is_kind_partially_covered`, `is_kind_saturated`
7350    // returns `true` on any `N ≥ 1` closed set. Byte-for-byte peer of
7351    // `is_empty + is_partially_populated + is_saturated == 1` one
7352    // struct-layer up.
7353    assert_eq!(
7354        usize::from(slice.is_kind_empty())
7355            + usize::from(slice.is_kind_partially_covered())
7356            + usize::from(slice.is_kind_saturated()),
7357        1,
7358        "trichotomy partition law violated — is_kind_empty + is_kind_partially_covered + is_kind_saturated must equal 1 (got {} + {} + {} = {})",
7359        usize::from(slice.is_kind_empty()),
7360        usize::from(slice.is_kind_partially_covered()),
7361        usize::from(slice.is_kind_saturated()),
7362        usize::from(slice.is_kind_empty())
7363            + usize::from(slice.is_kind_partially_covered())
7364            + usize::from(slice.is_kind_saturated()),
7365    );
7366
7367    // has_any_missing_kind ↔ !is_kind_saturated — the Boolean at-
7368    // least-one halfspace projection of the closed-set-complement
7369    // scalar cardinality. Peer of `is_kind_saturated ↔
7370    // (missing_kind_count == 0)` on the Boolean-negation axis: where
7371    // the saturation-endpoint peer tests the zero-arm, this at-least-
7372    // one halfspace peer tests its negation. Together the two Booleans
7373    // partition the missing-cardinality closed set — exactly one is
7374    // `true` for every slice. A regression that overrode
7375    // `has_any_missing_kind` to drop the negation (returning
7376    // `is_kind_saturated`), skip a kind, or drift the walk from
7377    // `ConditionKind::ALL` surfaces HERE at the substrate boundary,
7378    // not as silent drift at every downstream `has-any-missing-kind`
7379    // require-tag classifier or fleet-wide gap-analysis dashboard
7380    // callsite. Byte-for-byte peer of
7381    // `crate::tagged_union::TaggedUnion::has_any_missing_kind` one
7382    // struct-layer up under the SAME `!is_saturated` definitional
7383    // negation shape. Also pins the widened composition laws
7384    // `has_any_missing_kind() == (missing_kind_count() > 0)` and
7385    // `has_any_missing_kind() == !missing_kinds().is_empty()` at every
7386    // slice — binds the at-least-one halfspace Boolean projection to
7387    // the widened + scalar closed-set-complement primitives without
7388    // paying for the Vec allocation.
7389    assert_eq!(
7390        slice.has_any_missing_kind(),
7391        !slice.is_kind_saturated(),
7392        "has_any_missing_kind() drifted from !is_kind_saturated()",
7393    );
7394    assert_eq!(
7395        slice.has_any_missing_kind(),
7396        slice.missing_kind_count() > 0,
7397        "has_any_missing_kind() drifted from (missing_kind_count() > 0)",
7398    );
7399    assert_eq!(
7400        slice.has_any_missing_kind(),
7401        !missing.is_empty(),
7402        "has_any_missing_kind() drifted from !missing_kinds().is_empty()",
7403    );
7404
7405    // has_any_distinct_kind ↔ (distinct_kind_count > 0) — the Boolean
7406    // at-least-one halfspace projection of the closed-set-inversion
7407    // scalar cardinality. Peer of `has_any_missing_kind ↔
7408    // !is_kind_saturated` on the axis-parity axis: where the at-least-
7409    // one halfspace peer on the closed-set-complement axis tests the
7410    // ≥ 1 arm on the missing scalar, this at-least-one halfspace peer
7411    // on the closed-set-inversion axis tests the ≥ 1 arm on the
7412    // distinct scalar. A regression that overrode `has_any_distinct_kind`
7413    // to drop the short-circuit, skip a kind, or drift the walk from
7414    // `ConditionKind::ALL` surfaces HERE at the substrate boundary, not
7415    // as silent drift at every downstream `has-any-distinct-kind`
7416    // require-tag classifier or fleet-wide coverage-analysis dashboard
7417    // callsite. Byte-for-byte peer of
7418    // `crate::tagged_union::TaggedUnion::has_any_populated_kind` one
7419    // struct-layer up under the SAME `any(has)` short-circuit shape.
7420    // Also pins the widened composition law `has_any_distinct_kind() ==
7421    // !distinct_kinds().is_empty()` at every slice — binds the at-
7422    // least-one halfspace Boolean projection to the widened primitive
7423    // without paying for the Vec allocation.
7424    assert_eq!(
7425        slice.has_any_distinct_kind(),
7426        slice.distinct_kind_count() > 0,
7427        "has_any_distinct_kind() drifted from (distinct_kind_count() > 0)",
7428    );
7429    assert_eq!(
7430        slice.has_any_distinct_kind(),
7431        !distinct.is_empty(),
7432        "has_any_distinct_kind() drifted from !distinct_kinds().is_empty()",
7433    );
7434    assert_eq!(
7435        slice.has_any_distinct_kind(),
7436        slice.first_distinct_kind().is_some(),
7437        "has_any_distinct_kind() drifted from first_distinct_kind().is_some()",
7438    );
7439
7440    // has_unique_distinct_kind ↔ (distinct_kind_count == 1) — the
7441    // Boolean cardinality-mid-endpoint projection of the closed-set-
7442    // inversion scalar cardinality. Peer of `has_unique_missing_kind
7443    // ↔ (missing_kind_count == 1)` (=1 mid-endpoint on the missing
7444    // axis) on the axis-parity axis: where the missing-axis peer
7445    // tests the exactly-one arm on the missing scalar, this
7446    // distinct-axis peer tests the exactly-one arm on the distinct
7447    // scalar. A regression that overrode `has_unique_distinct_kind`
7448    // to drop the second-slot short-circuit (returning any at-least-
7449    // one arm), skip a kind, drift the walk from `ConditionKind::ALL`,
7450    // or conflate with `has_any_distinct_kind` (the ≥ 1 halfspace)
7451    // surfaces HERE at the substrate boundary, not as silent drift at
7452    // every downstream `has-unique-distinct-kind` require-tag
7453    // classifier or singleton-coverage diagnostic callsite. Byte-for-
7454    // byte peer of `crate::tagged_union::TaggedUnion::has_unique_populated_kind`
7455    // one struct-layer up under the SAME two-step short-circuit walk
7456    // shape. Also pins the widened composition law
7457    // `has_unique_distinct_kind() == (distinct_kinds().len() == 1)`
7458    // at every slice — binds the cardinality-mid-endpoint Boolean
7459    // projection to the widened + scalar closed-set-inversion
7460    // primitives without paying for the Vec allocation on the ≥ 2-
7461    // distinct arms (where the short-circuit fires).
7462    assert_eq!(
7463        slice.has_unique_distinct_kind(),
7464        slice.distinct_kind_count() == 1,
7465        "has_unique_distinct_kind() drifted from (distinct_kind_count() == 1)",
7466    );
7467    assert_eq!(
7468        slice.has_unique_distinct_kind(),
7469        distinct.len() == 1,
7470        "has_unique_distinct_kind() drifted from (distinct_kinds().len() == 1)",
7471    );
7472
7473    // has_multiple_distinct_kinds ↔ (distinct_kind_count >= 2) — the
7474    // Boolean cardinality many-arm projection of the closed-set-
7475    // inversion scalar cardinality. Peer of `has_any_distinct_kind ↔
7476    // !distinct_kinds.is_empty()` (≥ 1 halfspace) and
7477    // `has_unique_distinct_kind ↔ (distinct_kind_count == 1)` (= 1
7478    // mid-endpoint) on the Boolean-projection axis: where those peers
7479    // test the ≥ 1 and = 1 arms on the distinct scalar, this many-arm
7480    // peer tests the ≥ 2 arm. Together with the empty-endpoint
7481    // (`!has_any_distinct_kind`) and `has_unique_distinct_kind`, the
7482    // three Booleans partition the distinct-cardinality closed set at
7483    // 0, 1, and ≥ 2 respectively — every slice satisfies EXACTLY ONE
7484    // of the three projections. A regression that overrode
7485    // `has_multiple_distinct_kinds` to drop the second-slot short-
7486    // circuit (returning `true` on any ≥ 1-distinct arm), skip a
7487    // kind, drift the walk from `ConditionKind::ALL`, or conflate
7488    // with `has_any_distinct_kind` (the ≥ 1 halfspace) surfaces HERE
7489    // at the substrate boundary, not as silent drift at every
7490    // downstream `has-multiple-distinct-kinds` require-tag classifier
7491    // or multi-coverage diagnostic callsite. Byte-for-byte peer of
7492    // `crate::tagged_union::TaggedUnion::has_multiple_populated_kinds`
7493    // one struct-layer up under the SAME two-step short-circuit walk
7494    // shape. Also pins the widened composition law
7495    // `has_multiple_distinct_kinds() == (distinct_kinds().len() >= 2)`
7496    // at every slice — binds the cardinality-many-arm Boolean
7497    // projection to the widened + scalar closed-set-inversion
7498    // primitives without paying for the Vec allocation on the ≥ 2-
7499    // distinct arms (where the short-circuit fires) or the full-slot
7500    // walk on the scalar counter.
7501    assert_eq!(
7502        slice.has_multiple_distinct_kinds(),
7503        slice.distinct_kind_count() >= 2,
7504        "has_multiple_distinct_kinds() drifted from (distinct_kind_count() >= 2)",
7505    );
7506    assert_eq!(
7507        slice.has_multiple_distinct_kinds(),
7508        distinct.len() >= 2,
7509        "has_multiple_distinct_kinds() drifted from (distinct_kinds().len() >= 2)",
7510    );
7511
7512    // has_at_most_one_distinct_kind ↔ !has_multiple_distinct_kinds —
7513    // the Boolean cardinality "≤ 1" negation projection of the many-
7514    // arm primitive on the closed-set-inversion axis. Peer of
7515    // `has_multiple_distinct_kinds ↔ (distinct_kind_count >= 2)` (≥ 2
7516    // many-arm) under the definitional Boolean negation
7517    // `!(≥ 2) == (≤ 1)`. Together with `!has_any_distinct_kind` (=0
7518    // empty-endpoint reached via `has_any_distinct_kind`) and
7519    // `has_unique_distinct_kind` (=1 mid-endpoint), the "≤ 1"
7520    // primitive collapses to the trichotomy-union
7521    // `!has_any_distinct_kind() || has_unique_distinct_kind()` — a
7522    // regression that overrode `has_at_most_one_distinct_kind` to drop
7523    // the definitional negation (returning `has_multiple_distinct_kinds`
7524    // itself), swap the wrong side, or drift the walk from the
7525    // many-arm primitive surfaces HERE at the substrate boundary, not
7526    // as silent drift at every downstream
7527    // `has-at-most-one-distinct-kind` require-tag classifier or
7528    // empty-or-singleton coverage-analysis diagnostic callsite. Byte-
7529    // for-byte peer of
7530    // `crate::tagged_union::TaggedUnion::has_at_most_one_populated_kind`
7531    // one struct-layer up under the SAME `!has_multiple_populated_kinds`
7532    // definitional negation shape. Axis-parity mirror of the closed-
7533    // set-complement "≤ 1" negation peer
7534    // `has_at_most_one_missing_kind ↔ !has_multiple_missing_kinds` at
7535    // the same slice-level trait. Also pins the widened composition
7536    // laws
7537    // `has_at_most_one_distinct_kind() == (distinct_kind_count() <= 1)`
7538    // and `has_at_most_one_distinct_kind() == (distinct_kinds().len() <= 1)`
7539    // at every slice — binds the "≤ 1" Boolean projection to the
7540    // widened + scalar closed-set-inversion primitives without paying
7541    // for the Vec allocation on the ≤ 1-distinct arms (where the
7542    // negated short-circuit fires immediately after the many-arm walk
7543    // stops) or the full-slot walk on the scalar counter. Also pins
7544    // the trichotomy-union composition law
7545    // `has_at_most_one_distinct_kind() == !has_any_distinct_kind() ||
7546    // has_unique_distinct_kind()` at every slice — surfaces any
7547    // implementor that drifted the trichotomy union operator from
7548    // `||` to `&&` or that broke one of the two arm primitives while
7549    // leaving the "≤ 1" negation of the many-arm intact.
7550    assert_eq!(
7551        slice.has_at_most_one_distinct_kind(),
7552        !slice.has_multiple_distinct_kinds(),
7553        "has_at_most_one_distinct_kind() drifted from !has_multiple_distinct_kinds()",
7554    );
7555    assert_eq!(
7556        slice.has_at_most_one_distinct_kind(),
7557        slice.distinct_kind_count() <= 1,
7558        "has_at_most_one_distinct_kind() drifted from (distinct_kind_count() <= 1)",
7559    );
7560    assert_eq!(
7561        slice.has_at_most_one_distinct_kind(),
7562        distinct.len() <= 1,
7563        "has_at_most_one_distinct_kind() drifted from (distinct_kinds().len() <= 1)",
7564    );
7565    assert_eq!(
7566        slice.has_at_most_one_distinct_kind(),
7567        !slice.has_any_distinct_kind() || slice.has_unique_distinct_kind(),
7568        "has_at_most_one_distinct_kind() drifted from (!has_any_distinct_kind() || has_unique_distinct_kind())",
7569    );
7570
7571    // has_unique_missing_kind ↔ (missing_kind_count == 1) — the
7572    // Boolean cardinality-mid-endpoint projection of the closed-set-
7573    // complement scalar cardinality. Peer of `has_any_missing_kind ↔
7574    // !is_kind_saturated` on the Boolean-projection axis: where the
7575    // at-least-one halfspace peer tests the ≥ 1 arm on the missing
7576    // scalar, this cardinality-mid-endpoint peer tests the exactly-
7577    // one arm. Together with `is_kind_saturated` (zero-arm) and the
7578    // future many-arm peer, the three Booleans partition the missing-
7579    // cardinality closed set at 0, 1, and ≥ 2 respectively. A
7580    // regression that overrode `has_unique_missing_kind` to drop the
7581    // second-slot short-circuit (returning any partial-populated
7582    // arm), skip a kind, drift the walk from `ConditionKind::ALL`, or
7583    // conflate with `is_kind_saturated` (the zero-arm) surfaces HERE
7584    // at the substrate boundary, not as silent drift at every
7585    // downstream `has-unique-missing-kind` require-tag classifier or
7586    // near-saturation-endpoint diagnostic callsite. Byte-for-byte
7587    // peer of `crate::tagged_union::TaggedUnion::has_unique_missing_kind`
7588    // one struct-layer up under the SAME two-step short-circuit
7589    // walk shape. Also pins the widened composition law
7590    // `has_unique_missing_kind() == (missing_kinds().len() == 1)` at
7591    // every slice — binds the cardinality-mid-endpoint Boolean
7592    // projection to the widened + scalar closed-set-complement
7593    // primitives without paying for the Vec allocation on the ≥ 2-
7594    // missing arms (where the short-circuit fires).
7595    assert_eq!(
7596        slice.has_unique_missing_kind(),
7597        slice.missing_kind_count() == 1,
7598        "has_unique_missing_kind() drifted from (missing_kind_count() == 1)",
7599    );
7600    assert_eq!(
7601        slice.has_unique_missing_kind(),
7602        missing.len() == 1,
7603        "has_unique_missing_kind() drifted from (missing_kinds().len() == 1)",
7604    );
7605
7606    // has_multiple_missing_kinds ↔ (missing_kind_count >= 2) — the
7607    // Boolean cardinality many-arm projection of the closed-set-
7608    // complement scalar cardinality. Peer of `has_any_missing_kind ↔
7609    // !is_kind_saturated` (≥ 1 halfspace) and `has_unique_missing_kind
7610    // ↔ (missing_kind_count == 1)` (= 1 mid-endpoint) on the Boolean-
7611    // projection axis: where those peers test the ≥ 1 and = 1 arms on
7612    // the missing scalar, this many-arm peer tests the ≥ 2 arm.
7613    // Together with `is_kind_saturated` (zero-arm) and
7614    // `has_unique_missing_kind` (one-arm), the three Booleans
7615    // partition the missing-cardinality closed set at 0, 1, and ≥ 2
7616    // respectively — every slice satisfies EXACTLY ONE of the three
7617    // projections. A regression that overrode `has_multiple_missing_kinds`
7618    // to drop the second-slot short-circuit (returning `true` on any
7619    // ≥ 1-missing arm), skip a kind, drift the walk from
7620    // `ConditionKind::ALL`, or conflate with `has_any_missing_kind`
7621    // (the ≥ 1 halfspace) surfaces HERE at the substrate boundary,
7622    // not as silent drift at every downstream
7623    // `has-multiple-missing-kinds` require-tag classifier or
7624    // coverage-gap diagnostic callsite. Byte-for-byte peer of
7625    // `crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`
7626    // one struct-layer up under the SAME two-step short-circuit walk
7627    // shape. Also pins the widened composition law
7628    // `has_multiple_missing_kinds() == (missing_kinds().len() >= 2)`
7629    // at every slice — binds the cardinality-many-arm Boolean
7630    // projection to the widened + scalar closed-set-complement
7631    // primitives without paying for the Vec allocation on the ≥ 2-
7632    // missing arms (where the short-circuit fires) or the full-slot
7633    // walk on the scalar counter.
7634    assert_eq!(
7635        slice.has_multiple_missing_kinds(),
7636        slice.missing_kind_count() >= 2,
7637        "has_multiple_missing_kinds() drifted from (missing_kind_count() >= 2)",
7638    );
7639    assert_eq!(
7640        slice.has_multiple_missing_kinds(),
7641        missing.len() >= 2,
7642        "has_multiple_missing_kinds() drifted from (missing_kinds().len() >= 2)",
7643    );
7644
7645    // has_at_most_one_missing_kind ↔ !has_multiple_missing_kinds — the
7646    // Boolean cardinality "≤ 1" negation projection of the many-arm
7647    // primitive on the closed-set-complement axis. Peer of
7648    // `has_multiple_missing_kinds ↔ (missing_kind_count >= 2)` (≥ 2
7649    // many-arm) under the definitional Boolean negation
7650    // `!(≥ 2) == (≤ 1)`. Together with `is_kind_saturated` (=0
7651    // zero-arm) and `has_unique_missing_kind` (=1 mid-endpoint), the
7652    // "≤ 1" primitive collapses to the trichotomy-union
7653    // `is_kind_saturated() || has_unique_missing_kind()` — a
7654    // regression that overrode `has_at_most_one_missing_kind` to drop
7655    // the definitional negation (returning `has_multiple_missing_kinds`
7656    // itself), swap the wrong side, or drift the walk from the
7657    // many-arm primitive surfaces HERE at the substrate boundary, not
7658    // as silent drift at every downstream
7659    // `has-at-most-one-missing-kind` require-tag classifier or near-
7660    // saturation-or-saturated gap-analysis diagnostic callsite. Byte-
7661    // for-byte peer of
7662    // `crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`
7663    // one struct-layer up under the SAME `!has_multiple_missing_kinds`
7664    // definitional negation shape. Also pins the widened composition
7665    // laws
7666    // `has_at_most_one_missing_kind() == (missing_kind_count() <= 1)`
7667    // and `has_at_most_one_missing_kind() == (missing_kinds().len() <= 1)`
7668    // at every slice — binds the "≤ 1" Boolean projection to the
7669    // widened + scalar closed-set-complement primitives without paying
7670    // for the Vec allocation on the ≤ 1-missing arms (where the
7671    // negated short-circuit fires immediately after the many-arm walk
7672    // stops) or the full-slot walk on the scalar counter. Also pins
7673    // the trichotomy-union composition law
7674    // `has_at_most_one_missing_kind() == is_kind_saturated() ||
7675    // has_unique_missing_kind()` at every slice — surfaces any
7676    // implementor that drifted the trichotomy union operator from
7677    // `||` to `&&` or that broke one of the two arm primitives while
7678    // leaving the "≤ 1" negation of the many-arm intact.
7679    assert_eq!(
7680        slice.has_at_most_one_missing_kind(),
7681        !slice.has_multiple_missing_kinds(),
7682        "has_at_most_one_missing_kind() drifted from !has_multiple_missing_kinds()",
7683    );
7684    assert_eq!(
7685        slice.has_at_most_one_missing_kind(),
7686        slice.missing_kind_count() <= 1,
7687        "has_at_most_one_missing_kind() drifted from (missing_kind_count() <= 1)",
7688    );
7689    assert_eq!(
7690        slice.has_at_most_one_missing_kind(),
7691        missing.len() <= 1,
7692        "has_at_most_one_missing_kind() drifted from (missing_kinds().len() <= 1)",
7693    );
7694    assert_eq!(
7695        slice.has_at_most_one_missing_kind(),
7696        slice.is_kind_saturated() || slice.has_unique_missing_kind(),
7697        "has_at_most_one_missing_kind() drifted from (is_kind_saturated() || has_unique_missing_kind())",
7698    );
7699
7700    // lacks_kind ↔ !has_kind — the Boolean per-kind complement
7701    // projection on the closed-set-complement axis. Peer of
7702    // `is_kind_saturated ↔ (missing_kind_count == 0)` on the Boolean-
7703    // projection axis: where the saturation-endpoint peer collapses
7704    // the whole missing scalar to its zero-arm test, this per-kind
7705    // peer collapses the whole missing SET to its per-kind membership
7706    // Boolean for ONE addressed kind. A regression that overrode
7707    // `lacks_kind` to drop the negation (returning `has_kind`), swap
7708    // the wrong side, or drift the walk from `has_kind` surfaces HERE
7709    // at the substrate boundary, not as silent drift at every
7710    // downstream `lacks-<kind>` require-tag classifier or
7711    // dependency-satisfaction coherence check callsite. Byte-for-byte
7712    // peer of `crate::tagged_union::TaggedUnion::lacks` one struct-
7713    // layer up under the SAME `!has(kind)` definitional negation
7714    // shape. Also pins the widened composition law
7715    // `lacks_kind(k) == missing_kinds().contains(&k)` at every arm —
7716    // binds the per-kind Boolean projection to the widened closed-set-
7717    // complement primitive without paying for the Vec allocation.
7718    for kind in ConditionKind::ALL {
7719        assert_eq!(
7720            slice.lacks_kind(kind),
7721            !slice.has_kind(kind),
7722            "lacks_kind({kind:?}) drifted from !has_kind({kind:?})",
7723        );
7724        assert_eq!(
7725            slice.lacks_kind(kind),
7726            missing.contains(&kind),
7727            "lacks_kind({kind:?}) drifted from missing_kinds().contains(&{kind:?})",
7728        );
7729    }
7730
7731    // has_only_kind(k) ↔ (distinct_kinds() == vec![k]) — the kind-
7732    // scoped strict-refinement projection on the closed-set-inversion
7733    // axis. Peer of `lacks_kind ↔ !has_kind` under a symmetrical
7734    // refinement axis: where `lacks_kind` refines `has_kind` under a
7735    // definitional negation (per-kind Boolean complement),
7736    // `has_only_kind` refines it under a well-formed-diagonal
7737    // strengthening (per-kind Boolean AND
7738    // `distinct_kind_count() == 1`). Together the two peers occupy
7739    // the (weaken, strengthen) axes of the per-kind projection on the
7740    // closed-set-inversion widened primitive at the slice level.
7741    // A regression that overrode `has_only_kind` to drop the fused-
7742    // walk short-circuit (returning `has_kind` — TOO LOOSE, admits
7743    // multi-kind slices) or to drop the `saw_kind` arm (returning
7744    // `distinct_kind_count() <= 1` — TOO LOOSE, admits the empty
7745    // slice as well-formed) surfaces HERE at the substrate boundary,
7746    // not as silent drift at every downstream `has-only-<kind>`
7747    // require-tag classifier or well-formed-diagonal coherence check
7748    // callsite. Byte-for-byte peer of
7749    // `crate::tagged_union::TaggedUnion::has_only` one struct-layer
7750    // up under the SAME fused short-circuit closed-set walk shape.
7751    // Also pins the widened composition laws
7752    // `has_only_kind(k) == (distinct_kinds() == vec![k])`,
7753    // `has_only_kind(k) == (has_kind(k) && distinct_kind_count() == 1)`,
7754    // and the kind-domain exhaustivity law "AT MOST ONE `k` satisfies
7755    // `has_only_kind(k)` on any slice".
7756    let mut has_only_hits = 0usize;
7757    for kind in ConditionKind::ALL {
7758        let expected_widened = distinct == vec![kind];
7759        assert_eq!(
7760            slice.has_only_kind(kind),
7761            expected_widened,
7762            "has_only_kind({kind:?}) drifted from (distinct_kinds() == vec![{kind:?}])",
7763        );
7764        assert_eq!(
7765            slice.has_only_kind(kind),
7766            slice.has_kind(kind) && slice.distinct_kind_count() == 1,
7767            "has_only_kind({kind:?}) drifted from (has_kind({kind:?}) && distinct_kind_count() == 1)",
7768        );
7769        // Strict-refinement of `has_kind`: has_only_kind(k) ⟹ has_kind(k).
7770        if slice.has_only_kind(kind) {
7771            assert!(
7772                slice.has_kind(kind),
7773                "has_only_kind({kind:?}) implies has_kind({kind:?})",
7774            );
7775            has_only_hits += 1;
7776        }
7777    }
7778    // Kind-domain exhaustivity — AT MOST ONE `k` satisfies
7779    // `has_only_kind(k)` on any slice.
7780    assert!(
7781        has_only_hits <= 1,
7782        "has_only_kind(k) satisfied by more than one kind (count={has_only_hits}) — kind-domain exhaustivity violated",
7783    );
7784    // has_only_kind(k) for SOME k ⟺ distinct_kind_count() == 1 — the
7785    // kind-domain-exhaustivity ⟺ well-formed-diagonal pin.
7786    assert_eq!(
7787        has_only_hits == 1,
7788        slice.distinct_kind_count() == 1,
7789        "has_only_kind holds for some kind iff distinct_kind_count() == 1",
7790    );
7791
7792    // lacks_only_kind(k) ↔ (missing_kinds() == vec![k]) — the kind-
7793    // scoped strict-refinement projection on the closed-set-complement
7794    // axis. Byte-for-byte peer of `has_only_kind` under complement:
7795    // where `has_only_kind` refines `has_kind` under a well-formed-
7796    // diagonal strengthening on the populated axis, `lacks_only_kind`
7797    // refines `lacks_kind` under the same strengthening on the missing
7798    // axis — the closed-set-complement mirror closes the (populated,
7799    // missing) × (subset, equal) 2x2 kind-scoped strict-refinement grid
7800    // at the slice level alongside `has_kind` / `lacks_kind` /
7801    // `has_only_kind`. A regression that overrode `lacks_only_kind` to
7802    // drop the fused-walk short-circuit (returning `lacks_kind` — TOO
7803    // LOOSE, admits multi-missing-kind slices) or to drop the
7804    // `saw_kind` arm (returning `missing_kind_count() <= 1` — TOO
7805    // LOOSE, admits the saturated slice as well-formed on the missing
7806    // axis) surfaces HERE at the substrate boundary, not as silent
7807    // drift at every downstream `lacks-only-<kind>` require-tag
7808    // classifier or near-saturation-diagonal coherence check callsite.
7809    // Byte-for-byte peer of `crate::tagged_union::TaggedUnion::lacks_only`
7810    // one struct-layer up under the SAME fused short-circuit closed-set
7811    // walk shape. Also pins the widened composition laws
7812    // `lacks_only_kind(k) == (missing_kinds() == vec![k])`,
7813    // `lacks_only_kind(k) == (lacks_kind(k) && missing_kind_count() == 1)`,
7814    // and the kind-domain exhaustivity law "AT MOST ONE `k` satisfies
7815    // `lacks_only_kind(k)` on any slice".
7816    let mut lacks_only_hits = 0usize;
7817    for kind in ConditionKind::ALL {
7818        let expected_widened = missing == vec![kind];
7819        assert_eq!(
7820            slice.lacks_only_kind(kind),
7821            expected_widened,
7822            "lacks_only_kind({kind:?}) drifted from (missing_kinds() == vec![{kind:?}])",
7823        );
7824        assert_eq!(
7825            slice.lacks_only_kind(kind),
7826            slice.lacks_kind(kind) && slice.missing_kind_count() == 1,
7827            "lacks_only_kind({kind:?}) drifted from (lacks_kind({kind:?}) && missing_kind_count() == 1)",
7828        );
7829        // Strict-refinement of `lacks_kind`: lacks_only_kind(k) ⟹ lacks_kind(k).
7830        if slice.lacks_only_kind(kind) {
7831            assert!(
7832                slice.lacks_kind(kind),
7833                "lacks_only_kind({kind:?}) implies lacks_kind({kind:?})",
7834            );
7835            lacks_only_hits += 1;
7836        }
7837    }
7838    // Kind-domain exhaustivity — AT MOST ONE `k` satisfies
7839    // `lacks_only_kind(k)` on any slice.
7840    assert!(
7841        lacks_only_hits <= 1,
7842        "lacks_only_kind(k) satisfied by more than one kind (count={lacks_only_hits}) — kind-domain exhaustivity violated",
7843    );
7844    // lacks_only_kind(k) for SOME k ⟺ missing_kind_count() == 1 — the
7845    // kind-domain-exhaustivity ⟺ near-saturation-diagonal pin.
7846    assert_eq!(
7847        lacks_only_hits == 1,
7848        slice.missing_kind_count() == 1,
7849        "lacks_only_kind holds for some kind iff missing_kind_count() == 1",
7850    );
7851    // lacks_only_kind(k) ⟺ has_unique_missing_kind && first_missing_kind() == Some(k)
7852    // — kind-domain agreement with the arg-less unique-missing predicate.
7853    for kind in ConditionKind::ALL {
7854        assert_eq!(
7855            slice.lacks_only_kind(kind),
7856            slice.has_unique_missing_kind() && slice.first_missing_kind() == Some(kind),
7857            "lacks_only_kind({kind:?}) drifted from (has_unique_missing_kind() && first_missing_kind() == Some({kind:?}))",
7858        );
7859    }
7860
7861    // -------- Load-bearing iterator fold: scalar peers ------------------
7862    //
7863    // Every scalar closed-set peer folds through the load-bearing
7864    // iterator peer at ONE substrate site — a regression that overrides
7865    // ANY scalar peer with a divergent walk (short-circuit skipping a
7866    // kind, forgetting the negation on the complement side, drifting
7867    // from `ConditionKind::ALL` order, ignoring the load-bearing
7868    // iterator entirely with a duplicate closed-set walk of its own)
7869    // surfaces at THIS arm rather than as silent skew between the
7870    // scalar callsite and the iterator callsite at every downstream
7871    // consumer.
7872    //
7873    // Complements the Vec-based composition arms above (`distinct_kinds
7874    // ↔ iter_distinct_kinds`, `distinct_kind_count ↔ distinct_kinds`)
7875    // by binding each scalar peer DIRECTLY to the iterator surface —
7876    // catches an override that specializes ONE scalar peer with a
7877    // divergent walk while leaving the Vec-based intermediate coherent,
7878    // which the transitive `scalar ↔ Vec ↔ iter` composition arms
7879    // cannot detect on their own.
7880    //
7881    // Peer of tagged-union parent-level substrate testkit
7882    // `crate::tagged_union::assert_scalar_peers_fold_through_iter_kinds`.
7883    //
7884    // -------- Distinct side (folds through iter_distinct_kinds) ---------
7885    assert_eq!(
7886        slice.first_distinct_kind(),
7887        slice.iter_distinct_kinds().next(),
7888        "first_distinct_kind() drifted from iter_distinct_kinds().next()",
7889    );
7890    assert_eq!(
7891        slice.last_distinct_kind(),
7892        slice.iter_distinct_kinds().last(),
7893        "last_distinct_kind() drifted from iter_distinct_kinds().last()",
7894    );
7895    assert_eq!(
7896        slice.has_any_distinct_kind(),
7897        slice.iter_distinct_kinds().next().is_some(),
7898        "has_any_distinct_kind() drifted from iter_distinct_kinds().next().is_some()",
7899    );
7900    let via_iter_unique_distinct = {
7901        let mut it = slice.iter_distinct_kinds();
7902        it.next().is_some() && it.next().is_none()
7903    };
7904    assert_eq!(
7905        slice.has_unique_distinct_kind(),
7906        via_iter_unique_distinct,
7907        "has_unique_distinct_kind() drifted from iter_distinct_kinds() two-step short-circuit",
7908    );
7909    // -------- Missing side (folds through iter_missing_kinds) -----------
7910    assert_eq!(
7911        slice.first_missing_kind(),
7912        slice.iter_missing_kinds().next(),
7913        "first_missing_kind() drifted from iter_missing_kinds().next()",
7914    );
7915    assert_eq!(
7916        slice.last_missing_kind(),
7917        slice.iter_missing_kinds().last(),
7918        "last_missing_kind() drifted from iter_missing_kinds().last()",
7919    );
7920    assert_eq!(
7921        slice.is_kind_saturated(),
7922        slice.iter_missing_kinds().next().is_none(),
7923        "is_kind_saturated() drifted from iter_missing_kinds().next().is_none()",
7924    );
7925    let via_iter_unique_missing = {
7926        let mut it = slice.iter_missing_kinds();
7927        it.next().is_some() && it.next().is_none()
7928    };
7929    assert_eq!(
7930        slice.has_unique_missing_kind(),
7931        via_iter_unique_missing,
7932        "has_unique_missing_kind() drifted from iter_missing_kinds() two-step short-circuit",
7933    );
7934    let via_iter_multi_missing = {
7935        let mut it = slice.iter_missing_kinds();
7936        it.next().is_some() && it.next().is_some()
7937    };
7938    assert_eq!(
7939        slice.has_multiple_missing_kinds(),
7940        via_iter_multi_missing,
7941        "has_multiple_missing_kinds() drifted from iter_missing_kinds() two-step short-circuit",
7942    );
7943}
7944
7945/// Substrate testkit macro — pins the FOUR union composition laws that
7946/// bind the (precondition, postcondition, union) refinement triads on
7947/// any authored surface exposing the 12-method (has / find / iter /
7948/// count) × (pre / post / union) `_kind` matrix. Sweeps
7949/// [`ConditionKind::ALL`] at ONE call site per authored arrangement.
7950///
7951/// # The four surface-level union composition laws
7952///
7953/// Where the slice-level substrate primitive
7954/// [`assert_slice_refinement_composition_laws`] pins the algebra that
7955/// binds the four refinements *on a single slice* (`iter_kind` →
7956/// `find_kind` → `has_kind` → `count_kind`), this macro pins the peer
7957/// algebra one struct-layer up: each refinement's union arm on a
7958/// two-slice surface (a [`Boundary`] with `preconditions` +
7959/// `postconditions`, an [`crate::ephemeral::EphemeralSpec`] with the
7960/// same eponymous field pair) composes from its two half-slice arms
7961/// through a specific monoid operator baked into the refinement's return
7962/// type:
7963///
7964/// | refinement | half-slice arms                             | union composition                     |
7965/// |------------|---------------------------------------------|---------------------------------------|
7966/// | `has_*_kind`   | `has_precondition_kind`, `has_postcondition_kind`     | `pre \|\| post` (bool OR)             |
7967/// | `find_*_kind`  | `find_precondition_kind`, `find_postcondition_kind`   | `pre.or(post)` (first-Some)           |
7968/// | `iter_*_kind`  | `iter_precondition_kind`, `iter_postcondition_kind`   | `pre.chain(post)` (stream concat)     |
7969/// | `count_*_kind` | `count_precondition_kind`, `count_postcondition_kind` | `pre + post` (cardinality SUM)        |
7970///
7971/// # Why lift
7972///
7973/// Pre-lift each surface-level union composition law lived at its own
7974/// hand-authored nested-`for` loop test on each of the two surfaces —
7975/// EIGHT sibling test bodies (`boundary_has_condition_kind_composes_precondition_and_postcondition_arms`,
7976/// `find_condition_kind_triad_delegates_to_slice_find_kind`,
7977/// `iter_condition_kind_triad_delegates_to_slice_iter_kind`,
7978/// `boundary_count_condition_kind_triad_delegates_and_sums_slice_count_kind`
7979/// on the [`Boundary`] surface, byte-for-byte peers on the
7980/// [`crate::ephemeral::EphemeralSpec`] surface) whose only per-law knobs
7981/// were the projection functions being bridged and the composition
7982/// operator (`\|\|` / `Option::or` / `Iterator::chain` / `+`) applied
7983/// on top. Post-lift each authored `(preconditions, postconditions)`
7984/// arrangement pins ALL FOUR union composition laws through ONE
7985/// `assert_surface_union_composition_laws!(surface)` call whose body
7986/// is the substrate primitive's own sweep, no per-surface author-time
7987/// enumeration.
7988///
7989/// # Why a macro rather than a `pub fn`
7990///
7991/// [`Boundary`] and [`crate::ephemeral::EphemeralSpec`] expose the
7992/// twelve methods as *inherent* methods with matching signatures. A
7993/// generic `pub fn assert_surface_union_composition_laws<B: T>(&B)`
7994/// would need a trait `T` publishing those same twelve methods, and
7995/// implementing that trait on either surface would collide with the
7996/// eponymous inherent methods at method resolution — the trait
7997/// impl would either duplicate the inherent-method bodies verbatim
7998/// (defeating the lift) or require renaming the trait methods with a
7999/// `_ext` suffix (introducing a parallel API surface). A macro
8000/// duck-types at expansion time and hits the inherent methods
8001/// directly, so both surfaces stay bound through the SAME
8002/// `_kind`-suffixed method names their non-generic callers already
8003/// reach for, and the pattern generalizes to any future surface that
8004/// grows the same twelve-method matrix (an `AplicacaoBoundary` typed
8005/// wrapper, a `PoolBoundary` gate-carrier at
8006/// [`crate::pool`], the boundary slot on a
8007/// hypothetical `AttestationBoundary` receipt-envelope surface) with
8008/// ONE macro invocation per authored arrangement rather than a per-
8009/// surface re-authored sweep over the four laws.
8010///
8011/// # Compounding
8012///
8013/// A FIFTH union refinement added to the (has, find, iter, count)
8014/// tetrad (a hypothetical `first_params_of_kind(k) -> Option<&Value>`
8015/// projection combining `find_condition_kind(k).map(|c| &c.params)` at
8016/// real reconciler callsites, a `distinct_kinds() -> impl Iterator<Item
8017/// = ConditionKind>` aggregate returning which kinds appear at least
8018/// once on either side, a `has_kind_matching(pred)` closure-based
8019/// predicate probe) lands its composition-law pin as ONE new arm
8020/// inside this macro's body. Every downstream test that already reaches
8021/// this macro picks up the fifth-refinement pin mechanically — no per-
8022/// arrangement author-time enumeration of the new law across the four
8023/// sibling composition-law sites on each of the two surfaces, no
8024/// re-authored `for kind in ConditionKind::ALL { … }` sweep at every
8025/// consumer.
8026///
8027/// Symmetrical shape to [`assert_slice_refinement_composition_laws`]
8028/// one layer below: both project a widened-refinement / coarser-
8029/// refinement composition law contract onto ONE typed substrate call
8030/// site, both sweep the addressed closed set [`ConditionKind::ALL`],
8031/// both surface any implementor that overrode the union arm with a
8032/// divergent composition operator (an `&&` inlined where `\|\|` is
8033/// required, a `pre - post` inlined where `pre + post` is required,
8034/// a `zip` inlined where `chain` is required, a `and_then` inlined
8035/// where `or_else` is required) as a first-class typed test failure
8036/// rather than as silent operator-facing drift at the
8037/// `condition-<kind>` / `precondition-<kind>` / `postcondition-<kind>`
8038/// require-tag classifier surfaces downstream.
8039///
8040/// # Theory grounding
8041///
8042/// - THEORY.md §II.1 invariant 5 — composition preserves proofs. Each
8043///   union arm is a typed projection of its two half-slice peers via
8044///   a specific monoid operator, and this substrate macro turns each
8045///   projection's composition law from doc-prose into a first-class
8046///   typed theorem provable against any surface exposing the twelve
8047///   `_kind`-suffixed inherent methods.
8048/// - THEORY.md §VI.1 — generation over composition. A new
8049///   [`ConditionKind`] variant added to `ALL` reaches every downstream
8050///   union-composition-law consumer through the SAME closed-set sweep
8051///   with no per-caller edit; a new surface (a typed wrapper carrying
8052///   the same twelve methods) picks up all four union composition-law
8053///   pins through ONE macro invocation per authored arrangement.
8054///
8055/// # Usage
8056///
8057/// ```ignore
8058/// // Point surface.
8059/// let mut b = Boundary::default();
8060/// b.preconditions.push(condition_with(ConditionKind::PromQL));
8061/// b.postconditions.push(condition_with(ConditionKind::ClosedLoopAuth));
8062/// assert_surface_union_composition_laws!(b);
8063///
8064/// // Ephemeral surface (peer, same primitive).
8065/// let mut spec = empty_ephemeral();
8066/// spec.postconditions.push(cond(ConditionKind::JobAttested));
8067/// assert_surface_union_composition_laws!(spec);
8068/// ```
8069#[macro_export]
8070macro_rules! assert_surface_union_composition_laws {
8071    ($surface:expr) => {{
8072        let __surface = &$surface;
8073        // Hoist distinct_* out of the per-kind loop — closed-set-inversion
8074        // refinements return the WHOLE distinct-set per call, so a single
8075        // computation per surface backs the per-kind membership arm inside
8076        // the loop AND the canonical-order equality after it.
8077        let __distinct_pre_kinds = __surface.distinct_precondition_kinds();
8078        let __distinct_post_kinds = __surface.distinct_postcondition_kinds();
8079        let __distinct_union_kinds = __surface.distinct_condition_kinds();
8080        let __missing_pre_kinds = __surface.missing_precondition_kinds();
8081        let __missing_post_kinds = __surface.missing_postcondition_kinds();
8082        let __missing_union_kinds = __surface.missing_condition_kinds();
8083        for __kind in $crate::boundary::ConditionKind::ALL {
8084            // has: union == pre || post (bool OR)
8085            let __has_via_arms =
8086                __surface.has_precondition_kind(__kind) || __surface.has_postcondition_kind(__kind);
8087            ::core::assert_eq!(
8088                __surface.has_condition_kind(__kind),
8089                __has_via_arms,
8090                "surface union has arm drifted from OR of half-slice arms for {:?}",
8091                __kind,
8092            );
8093            // find: union == pre.or(post) (first-Some, kind projection)
8094            let __find_via_arms = __surface
8095                .find_precondition_kind(__kind)
8096                .or(__surface.find_postcondition_kind(__kind))
8097                .map(|c| c.kind);
8098            ::core::assert_eq!(
8099                __surface.find_condition_kind(__kind).map(|c| c.kind),
8100                __find_via_arms,
8101                "surface union find arm drifted from precondition.or(postcondition) for {:?}",
8102                __kind,
8103            );
8104            // iter: union == chain(pre, post) (stream concat, kind projection)
8105            let __iter_via_arms: ::std::vec::Vec<_> = __surface
8106                .iter_precondition_kind(__kind)
8107                .chain(__surface.iter_postcondition_kind(__kind))
8108                .map(|c| c.kind)
8109                .collect();
8110            let __iter_via_union: ::std::vec::Vec<_> = __surface
8111                .iter_condition_kind(__kind)
8112                .map(|c| c.kind)
8113                .collect();
8114            ::core::assert_eq!(
8115                __iter_via_union,
8116                __iter_via_arms,
8117                "surface union iter arm drifted from chain(pre, post) for {:?}",
8118                __kind,
8119            );
8120            // count: union == pre + post (cardinality SUM)
8121            ::core::assert_eq!(
8122                __surface.count_condition_kind(__kind),
8123                __surface.count_precondition_kind(__kind)
8124                    + __surface.count_postcondition_kind(__kind),
8125                "surface union count arm drifted from SUM of half-slice arms for {:?}",
8126                __kind,
8127            );
8128            // distinct: union.contains(k) == pre.contains(k) || post.contains(k)
8129            // (set-union membership per kind on the closed-set-inversion axis)
8130            ::core::assert_eq!(
8131                __distinct_union_kinds.contains(&__kind),
8132                __distinct_pre_kinds.contains(&__kind)
8133                    || __distinct_post_kinds.contains(&__kind),
8134                "surface distinct union arm drifted from OR-membership of half-slice distinct arms for {:?}",
8135                __kind,
8136            );
8137            // missing: union.contains(k) == pre.contains(k) && post.contains(k)
8138            // (set-INTERSECTION membership per kind — a kind is missing
8139            // from the union iff it is missing from BOTH half-slices,
8140            // dual of the distinct-set OR composition).
8141            ::core::assert_eq!(
8142                __missing_union_kinds.contains(&__kind),
8143                __missing_pre_kinds.contains(&__kind)
8144                    && __missing_post_kinds.contains(&__kind),
8145                "surface missing union arm drifted from AND-membership of half-slice missing arms for {:?}",
8146                __kind,
8147            );
8148            // missing ↔ has: union.contains(k) == !has_condition_kind(k)
8149            // — binds the missing-set primitive to the point-probe
8150            // primitive on the surface under a negated predicate.
8151            ::core::assert_eq!(
8152                __missing_union_kinds.contains(&__kind),
8153                !__surface.has_condition_kind(__kind),
8154                "surface missing union arm drifted from !has_condition_kind for {:?}",
8155                __kind,
8156            );
8157            // lacks: union == pre && post (bool AND — dual of `has`'s
8158            // `pre || post` OR under `!(a || b) == !a && !b`). A kind is
8159            // lacked from the union iff BOTH half-slices lack it — the
8160            // per-kind Boolean-projection peer of the missing-set
8161            // intersection membership arm above (which composes the SAME
8162            // AND over the closed-set-complement Vecs); this arm
8163            // composes it over the per-slice per-kind negation
8164            // primitives without materializing either side's missing-
8165            // set Vec. A regression that (a) drifted the union operator
8166            // to `||` (widening the intersection to a union),
8167            // (b) dropped the negation on one side, or (c) inverted the
8168            // wrong slice on the point probe surfaces HERE at the
8169            // substrate boundary, not as silent drift at every
8170            // downstream `lacks-<kind>` require-tag classifier callsite.
8171            let __lacks_via_arms =
8172                __surface.lacks_precondition_kind(__kind) && __surface.lacks_postcondition_kind(__kind);
8173            ::core::assert_eq!(
8174                __surface.lacks_condition_kind(__kind),
8175                __lacks_via_arms,
8176                "surface union lacks arm drifted from AND of half-slice lacks arms for {:?}",
8177                __kind,
8178            );
8179            // lacks ↔ has: union == !has_condition_kind(k) — the
8180            // definitional complement law binds the per-kind Boolean-
8181            // complement primitive on the surface to the point-probe
8182            // primitive under negation. Peer of the `missing ↔ has`
8183            // arm above one refinement lower: the closed-set-complement
8184            // Vec's per-kind membership equals the per-kind Boolean
8185            // complement, both equal `!has_condition_kind(k)`. A
8186            // regression that overrode `lacks_condition_kind` to drop
8187            // the negation, drift the underlying union primitive, or
8188            // return `has_condition_kind` surfaces HERE.
8189            ::core::assert_eq!(
8190                __surface.lacks_condition_kind(__kind),
8191                !__surface.has_condition_kind(__kind),
8192                "surface union lacks arm drifted from !has_condition_kind for {:?}",
8193                __kind,
8194            );
8195        }
8196        // distinct: union == canonical(pre ∪ post) — closed-set-inversion
8197        // set-union projected in ConditionKind::ALL order. A regression that
8198        // (a) reversed the walk order (post-then-pre), (b) preserved
8199        // slice-encounter order rather than ConditionKind::ALL order, or
8200        // (c) narrowed the union to an intersection surfaces HERE at the
8201        // substrate boundary (the per-kind membership arm above catches
8202        // membership drift; this arm catches ordering + dedup drift the
8203        // membership arm cannot detect on its own).
8204        let __expected_distinct_union: ::std::vec::Vec<_> =
8205            $crate::boundary::ConditionKind::ALL
8206                .into_iter()
8207                .filter(|__k| {
8208                    __distinct_pre_kinds.contains(__k)
8209                        || __distinct_post_kinds.contains(__k)
8210                })
8211                .collect();
8212        ::core::assert_eq!(
8213            __distinct_union_kinds, __expected_distinct_union,
8214            "surface distinct union arm drifted from canonical ConditionKind::ALL-ordered set-union of half-slice distinct arms",
8215        );
8216        // missing: union == canonical(pre ∩ post) — closed-set-inversion
8217        // set-INTERSECTION projected in ConditionKind::ALL order. Dual
8218        // of the distinct union canonical-order arm above. A regression
8219        // that (a) reversed the walk order, (b) widened the intersection
8220        // to a union (returning kinds missing from either side rather
8221        // than both), or (c) preserved slice-encounter order rather
8222        // than ConditionKind::ALL order surfaces HERE at the substrate
8223        // boundary.
8224        let __expected_missing_union: ::std::vec::Vec<_> =
8225            $crate::boundary::ConditionKind::ALL
8226                .into_iter()
8227                .filter(|__k| {
8228                    __missing_pre_kinds.contains(__k)
8229                        && __missing_post_kinds.contains(__k)
8230                })
8231                .collect();
8232        ::core::assert_eq!(
8233            __missing_union_kinds, __expected_missing_union,
8234            "surface missing union arm drifted from canonical ConditionKind::ALL-ordered set-INTERSECTION of half-slice missing arms",
8235        );
8236    }};
8237}
8238
8239/// A single boundary predicate.
8240#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
8241#[serde(rename_all = "camelCase")]
8242pub struct Condition {
8243    pub kind: ConditionKind,
8244    /// Kind-specific payload (free-form JSON).
8245    #[serde(default)]
8246    #[schemars(schema_with = "crate::schema_helpers::preserve_unknown_object")]
8247    pub params: serde_json::Value,
8248}
8249
8250#[derive(
8251    Clone,
8252    Copy,
8253    Debug,
8254    PartialEq,
8255    Eq,
8256    Hash,
8257    Serialize,
8258    Deserialize,
8259    JsonSchema,
8260    tatara_closed_set::DeriveClosedSet,
8261)]
8262#[serde(rename_all = "PascalCase")]
8263#[closed_set(via = "as_str", display, generate_unknown)]
8264pub enum ConditionKind {
8265    /// Another Process must be in a given phase.
8266    /// `params`: `{ "processRef": "...", "namespace": "...", "phase": "Attested" }`
8267    ProcessPhase,
8268    /// FluxCD `Kustomization.status.conditions[type=Ready]` must be `True`.
8269    /// `params`: `{ "name": "...", "namespace": "flux-system" }`
8270    KustomizationHealthy,
8271    /// FluxCD `HelmRelease.status.conditions[type=Ready]` must be `True`.
8272    /// `params`: `{ "name": "...", "namespace": "..." }`
8273    HelmReleaseReleased,
8274    /// Prometheus query — truthy scalar required.
8275    /// `params`: `{ "query": "..." }`
8276    PromQL,
8277    /// CEL expression over a scoped object set.
8278    /// `params`: `{ "expression": "..." }`
8279    Cel,
8280    /// Nix evaluation equality check.
8281    /// `params`: `{ "flakeRef": "...", "attribute": "...", "expect": "..." }`
8282    NixEval,
8283    /// A Kubernetes Job must complete successfully and its emitted BLAKE3
8284    /// receipt must verify.
8285    /// `params`: `{ "name": "...", "namespace": "...", "expectReceipt": true }`
8286    JobAttested,
8287    /// Closed-loop authentication probe — the canonical postcondition for
8288    /// any system that can produce credentials for its own client under
8289    /// test. The probe Job (rendered by the VERIFY handler) fetches a
8290    /// fresh secret from `issuer` (a Service inside the same namespace),
8291    /// presents it to `consumer` (another Service in the same namespace),
8292    /// and verifies that `consumer` authenticated successfully against
8293    /// `jwk_source` (the issuer's published JWK endpoint).
8294    ///
8295    /// The Job emits a three-pillar BLAKE3 receipt that the reconciler
8296    /// chains into `status.attestation`. This turns "the gateway↔SaaS
8297    /// loop holds" from an assertion into a theorem provable for every
8298    /// ephemeral run.
8299    ///
8300    /// `params`:
8301    /// ```json
8302    /// {
8303    ///   "issuer":   { "service": "demo-app-issuer",
8304    ///                 "port": 8080,
8305    ///                 "secretPath": "/v2/get-secret-value" },
8306    ///   "consumer": { "service": "demo-app-gateway",
8307    ///                 "port": 8000,
8308    ///                 "authPath": "/api/v3/auth" },
8309    ///   "jwkSource":{ "service": "demo-app-issuer",
8310    ///                 "port": 8080,
8311    ///                 "path": "/.well-known/jwks.json" },
8312    ///   "probeImage": "ghcr.io/pleme-io/closed-loop-probe:0.1.0",
8313    ///   "timeoutSeconds": 120
8314    /// }
8315    /// ```
8316    ClosedLoopAuth,
8317}
8318
8319impl ConditionKind {
8320    /// The closed set of boundary-condition kinds the reconciler honors.
8321    /// Single source of truth that drives the `as_str` / Display /
8322    /// `FromStr` triad on this enum and the `stub_message` lift of the
8323    /// "not yet implemented" arms the reconciler used to hand-roll three
8324    /// times. Adding a 9th variant lands at one `ALL` entry + one `as_str`
8325    /// arm + one `stub_message` arm — exhaustively checked by the
8326    /// compiler (the array literal forces arity).
8327    ///
8328    /// Sibling closed-set lifts: [`crate::phase::ProcessPhase::ALL`],
8329    /// [`crate::signal::ProcessSignal::ALL`], [`crate::intent::IntentKind::ALL`],
8330    /// [`crate::lifetime::LifetimeKind::ALL`].
8331    pub const ALL: [Self; 8] = [
8332        Self::ProcessPhase,
8333        Self::KustomizationHealthy,
8334        Self::HelmReleaseReleased,
8335        Self::PromQL,
8336        Self::Cel,
8337        Self::NixEval,
8338        Self::JobAttested,
8339        Self::ClosedLoopAuth,
8340    ];
8341
8342    /// Canonical PascalCase wire-format projection — matches the serde
8343    /// `rename_all = "PascalCase"` output verbatim. Used by Display
8344    /// (single source of truth), by `FromStr` to identify the variant
8345    /// from its annotation / status-field representation, and by
8346    /// operator-facing diagnostics that need the kind name without
8347    /// re-serializing the enum through serde_json. Pinned by
8348    /// `condition_kind_as_str_matches_serde`.
8349    pub const fn as_str(self) -> &'static str {
8350        match self {
8351            Self::ProcessPhase => "ProcessPhase",
8352            Self::KustomizationHealthy => "KustomizationHealthy",
8353            Self::HelmReleaseReleased => "HelmReleaseReleased",
8354            Self::PromQL => "PromQL",
8355            Self::Cel => "Cel",
8356            Self::NixEval => "NixEval",
8357            Self::JobAttested => "JobAttested",
8358            Self::ClosedLoopAuth => "ClosedLoopAuth",
8359        }
8360    }
8361
8362    /// The operator-facing "evaluator not yet implemented" message for
8363    /// stub kinds — `Some` iff this kind has no live evaluator wired in
8364    /// `tatara-reconciler::boundary`. ONE site owns the per-kind stub
8365    /// string; the reconciler's dispatch reaches for this projection
8366    /// instead of hand-rolling three parallel `Unknown(...)` strings.
8367    ///
8368    /// A future variant added as a live evaluator returns `None`; a
8369    /// future variant added as a stub returns `Some("<kind> evaluator
8370    /// not yet implemented")` — both reachable through one match
8371    /// instead of three identical-shape arms drifting in parallel.
8372    pub const fn stub_message(self) -> Option<&'static str> {
8373        match self {
8374            Self::PromQL => Some("PromQL evaluator not yet implemented"),
8375            Self::Cel => Some("CEL evaluator not yet implemented"),
8376            Self::NixEval => Some("NixEval evaluator not yet implemented"),
8377            Self::ProcessPhase
8378            | Self::KustomizationHealthy
8379            | Self::HelmReleaseReleased
8380            | Self::JobAttested
8381            | Self::ClosedLoopAuth => None,
8382        }
8383    }
8384
8385    /// True iff this kind has no live evaluator (its [`Self::stub_message`]
8386    /// is `Some`). Pairs with the reconciler's `evaluate` dispatch — a
8387    /// stub kind unconditionally yields `Satisfaction::Unknown`.
8388    pub const fn is_stub(self) -> bool {
8389        self.stub_message().is_some()
8390    }
8391
8392    /// The [`FluxResource`] variant this condition kind fetches from
8393    /// the K8s API server, or `None` for non-Flux-fetching kinds — the
8394    /// typed projection owning the (ConditionKind → FluxResource)
8395    /// association every reconciler `evaluate` dispatch arm and every
8396    /// future coherence check binds through.
8397    ///
8398    /// Pre-lift the association was open-coded at TWO adjacent
8399    /// `evaluate` arms in `tatara-reconciler::boundary::evaluate` past
8400    /// the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold — each arm
8401    /// hand-authored a `(FluxResource::X.api_version(),
8402    /// FluxResource::X.kind())` pair as the two `&str` slots the
8403    /// pre-lift `evaluate_flux_ready(api_version: &str, kind: &str)`
8404    /// signature required. Post-lift the mapping lives at ONE typed
8405    /// projection here, the callee accepts a typed
8406    /// [`FluxResource`] slot (invalid `(apiVersion, kind)` pairings
8407    /// like Kustomization's apiVersion paired with HelmRelease's kind
8408    /// become unrepresentable), and the two `evaluate` arms collapse
8409    /// onto ONE `KustomizationHealthy | HelmReleaseReleased` OR-arm
8410    /// that reads the FluxResource variant from `.flux_resource()`.
8411    ///
8412    /// A future ConditionKind that fetches a fourth Flux resource
8413    /// variant (a hypothetical `BucketSynced` kind against a Flux
8414    /// `Bucket` source) lands as ONE new arm here + ONE new variant
8415    /// on [`FluxResource`] + ONE OR-pattern extension at the
8416    /// reconciler dispatch — no hand-authored `(apiVersion, kind)`
8417    /// pair at the callsite, no widening of the callee's signature.
8418    ///
8419    /// The three current non-Flux-fetching arms return `None`:
8420    /// - `ProcessPhase` fetches a tatara `Process` (through its own
8421    ///   [`crate::api_version`] + [`crate::PROCESS_KIND`] pair, not
8422    ///   a Flux `(apiVersion, kind)`).
8423    /// - `JobAttested` / `ClosedLoopAuth` fetch a `batch/v1::Job` +
8424    ///   an optional receipt `v1::ConfigMap`, both K8s built-ins
8425    ///   (not Flux resources).
8426    /// - `PromQL` / `Cel` / `NixEval` are stub evaluators
8427    ///   ([`Self::is_stub`]) — no cluster fetch at all.
8428    ///
8429    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
8430    /// preserves proofs — the (ConditionKind → FluxResource)
8431    /// association lives at ONE typed algebra projection here, not
8432    /// at every reconciler dispatch arm).
8433    pub const fn flux_resource(self) -> Option<FluxResource> {
8434        match self {
8435            Self::KustomizationHealthy => Some(FluxResource::Kustomization),
8436            Self::HelmReleaseReleased => Some(FluxResource::HelmRelease),
8437            Self::ProcessPhase
8438            | Self::PromQL
8439            | Self::Cel
8440            | Self::NixEval
8441            | Self::JobAttested
8442            | Self::ClosedLoopAuth => None,
8443        }
8444    }
8445}
8446
8447// `impl fmt::Display for ConditionKind` + `impl FromStr for
8448// ConditionKind` + `impl tatara_lisp::ClosedSet for ConditionKind` +
8449// `pub struct UnknownConditionKind(pub String)` are generated by
8450// `#[derive(tatara_closed_set::DeriveClosedSet)]` + `#[closed_set(via =
8451// "as_str", display, generate_unknown)]` on the enum declaration above.
8452// The auto-derived label `"condition kind"` matches the prior hand-
8453// rolled `#[error("unknown condition kind: {0}")]` verbatim. The
8454// inherent `as_str` projection stays load-bearing — the PascalCase
8455// wire-format that matches the serde rename + the CRD `enum:` listing
8456// verbatim (notably preserving `PromQL`'s consecutive caps that heck
8457// would have lowercased) — while the trait method `label` gives
8458// generic consumers a STABLE name across the 36+ workspace-wide
8459// closed-set implementors.
8460
8461#[cfg(test)]
8462mod tests {
8463    use super::*;
8464    use serde_json::json;
8465
8466    #[test]
8467    fn serde_process_phase_condition() {
8468        let c = Condition {
8469            kind: ConditionKind::ProcessPhase,
8470            params: json!({ "processRef": "secret-injection", "phase": "Attested" }),
8471        };
8472        let yaml = serde_yaml::to_string(&c).unwrap();
8473        assert!(yaml.contains("kind: ProcessPhase"));
8474        assert!(yaml.contains("processRef: secret-injection"));
8475    }
8476
8477    #[test]
8478    fn serde_closed_loop_auth_condition() {
8479        let c = Condition {
8480            kind: ConditionKind::ClosedLoopAuth,
8481            params: json!({
8482                "issuer":   { "service": "demo-app-issuer", "port": 8080 },
8483                "consumer": { "service": "demo-app-gateway", "port": 8000 },
8484                "probeImage": "ghcr.io/pleme-io/closed-loop-probe:0.1.0",
8485            }),
8486        };
8487        let yaml = serde_yaml::to_string(&c).unwrap();
8488        assert!(yaml.contains("kind: ClosedLoopAuth"));
8489        assert!(yaml.contains("probeImage: ghcr.io/pleme-io/closed-loop-probe:0.1.0"));
8490        let back: Condition = serde_yaml::from_str(&yaml).unwrap();
8491        assert_eq!(back.kind, ConditionKind::ClosedLoopAuth);
8492    }
8493
8494    #[test]
8495    fn serde_job_attested_condition() {
8496        let c = Condition {
8497            kind: ConditionKind::JobAttested,
8498            params: json!({ "name": "seed-job", "namespace": "demo-test" }),
8499        };
8500        let yaml = serde_yaml::to_string(&c).unwrap();
8501        assert!(yaml.contains("kind: JobAttested"));
8502    }
8503
8504    // ── closed-set algebra contracts (ALL × as_str × FromStr × stub_message) ─
8505
8506    /// Structural well-formedness of [`ConditionKind`] as a
8507    /// [`tatara_lisp::ClosedSet`] implementor — the workspace-wide
8508    /// testkit lift that pins all three structural invariants (`ALL`
8509    /// is non-empty, every variant round-trips through `label ↔
8510    /// parse_label`, labels are pairwise distinct, `""` is outside the
8511    /// closed set) at ONE call site. Replaces the hand-derived
8512    /// `condition_kind_all_is_unique_and_complete` +
8513    /// `condition_kind_roundtrip_via_as_str` + the empty-input arm of
8514    /// `unknown_condition_kind_errors`. `FromStr` delegates to
8515    /// `<Self as tatara_closed_set::ClosedSet>::parse_label`, so this helper
8516    /// exercises the same code path the reconciler hits when parsing a
8517    /// CRD `enum:`-validated value back to the typed kind.
8518    #[test]
8519    fn condition_kind_is_well_formed_closed_set() {
8520        tatara_closed_set::assert_closed_set_well_formed::<ConditionKind>();
8521    }
8522
8523    /// CANONICAL-KEY CONTRACT: `as_str` matches serde's PascalCase
8524    /// output verbatim for every variant. A future variant rename
8525    /// (or an `as_str` arm typo) lands here at one site. The probe
8526    /// confirmed `PromQL` survives `rename_all = "PascalCase"` as
8527    /// `"PromQL"` (heck preserves consecutive caps in the leading
8528    /// word), so this contract is the operator-facing pin.
8529    #[test]
8530    fn condition_kind_as_str_matches_serde() {
8531        crate::tagged_union::assert_label_matches_serde_serialization::<ConditionKind>();
8532    }
8533
8534    /// The Display impl IS `as_str` — pinning this lets future
8535    /// callers reach for either projection without drift. If a
8536    /// reviewer accidentally re-introduces an inline match in
8537    /// Display, this fails the moment a variant rename touches one
8538    /// site but not the other.
8539    #[test]
8540    fn condition_kind_display_matches_as_str() {
8541        crate::tagged_union::assert_display_matches_label::<ConditionKind>();
8542    }
8543
8544    /// `FromStr` rejects strings that aren't in the canonical
8545    /// projection — lowercased / typo / unrelated — and the error
8546    /// echoes the input verbatim so the operator-facing diagnostic
8547    /// carries the offending value, not a normalized form. The
8548    /// empty-input arm is pinned by
8549    /// [`condition_kind_is_well_formed_closed_set`] via the
8550    /// `tatara_lisp::ClosedSet` testkit; the cases here pin the
8551    /// verbatim-echo contract on the [`UnknownConditionKind`]
8552    /// newtype, which the trait's `make_unknown` can't see.
8553    #[test]
8554    fn unknown_condition_kind_errors() {
8555        use std::str::FromStr;
8556        for bad in ["processPhase", "PROMQL", "Promql", "Bogus"] {
8557            let err = ConditionKind::from_str(bad).unwrap_err();
8558            assert_eq!(err.0, bad, "error payload should echo input verbatim");
8559        }
8560    }
8561
8562    /// STUB CONTRACT: the three placeholder evaluators
8563    /// (PromQL / Cel / NixEval) are exactly the set whose
8564    /// `stub_message` is `Some`. The five live evaluators return
8565    /// `None`. A future variant promoted from stub → live must drop
8566    /// its `stub_message` arm; a new stub must add one. Both
8567    /// transitions land at this test by sweeping ALL.
8568    #[test]
8569    fn condition_kind_stub_set_matches_stubs() {
8570        use ConditionKind::*;
8571        for kind in ConditionKind::ALL {
8572            let expected_is_stub = matches!(kind, PromQL | Cel | NixEval);
8573            assert_eq!(
8574                kind.is_stub(),
8575                expected_is_stub,
8576                "is_stub disagreed for {kind:?}",
8577            );
8578            assert_eq!(
8579                kind.stub_message().is_some(),
8580                expected_is_stub,
8581                "stub_message disagreed for {kind:?}",
8582            );
8583        }
8584    }
8585
8586    /// Pin the exact stub strings so a rename of the operator-facing
8587    /// "not yet implemented" message lands at one site (here) instead
8588    /// of three parallel inline strings in the reconciler.
8589    #[test]
8590    fn condition_kind_stub_messages_are_pinned() {
8591        assert_eq!(
8592            ConditionKind::PromQL.stub_message(),
8593            Some("PromQL evaluator not yet implemented"),
8594        );
8595        assert_eq!(
8596            ConditionKind::Cel.stub_message(),
8597            Some("CEL evaluator not yet implemented"),
8598        );
8599        assert_eq!(
8600            ConditionKind::NixEval.stub_message(),
8601            Some("NixEval evaluator not yet implemented"),
8602        );
8603    }
8604
8605    // ── (ConditionKind → FluxResource) typed projection contracts ────
8606
8607    /// The two Flux-fetching kinds project to their canonical
8608    /// [`FluxResource`] variants. A future ConditionKind rename or
8609    /// FluxResource variant rename that skewed the projection at ONE
8610    /// arm surfaces here.
8611    #[test]
8612    fn kustomization_healthy_projects_to_flux_resource_kustomization() {
8613        assert_eq!(
8614            ConditionKind::KustomizationHealthy.flux_resource(),
8615            Some(FluxResource::Kustomization),
8616        );
8617    }
8618
8619    #[test]
8620    fn helm_release_released_projects_to_flux_resource_helm_release() {
8621        assert_eq!(
8622            ConditionKind::HelmReleaseReleased.flux_resource(),
8623            Some(FluxResource::HelmRelease),
8624        );
8625    }
8626
8627    /// The six non-Flux-fetching kinds project to `None`. Sweeps
8628    /// `ConditionKind::ALL` filtering by `flux_resource().is_none()`
8629    /// so a new variant added without a `flux_resource` arm surfaces
8630    /// at rustc's non-exhaustive-match gate BEFORE this test even
8631    /// runs; a new variant added with a hand-coded `Some(...)` arm
8632    /// that shouldn't fetch Flux surfaces here.
8633    #[test]
8634    fn non_flux_fetching_kinds_project_to_none() {
8635        use ConditionKind::*;
8636        let non_flux: Vec<_> = ConditionKind::ALL
8637            .iter()
8638            .copied()
8639            .filter(|k| k.flux_resource().is_none())
8640            .collect();
8641        assert_eq!(
8642            non_flux,
8643            vec![
8644                ProcessPhase,
8645                PromQL,
8646                Cel,
8647                NixEval,
8648                JobAttested,
8649                ClosedLoopAuth
8650            ],
8651        );
8652    }
8653
8654    /// Every variant of [`ConditionKind`] whose `flux_resource()` is
8655    /// `Some` uniquely names its FluxResource variant (no two
8656    /// ConditionKind arms may fetch the SAME FluxResource — that
8657    /// would signal a redundant closed-set entry). Peers the
8658    /// `every_variants_api_version_and_kind_are_distinct_across_the_closed_set`
8659    /// pin on the sibling [`FluxResource`] closed set.
8660    #[test]
8661    fn flux_resource_projection_is_injective_on_the_some_arms() {
8662        let mut seen = std::collections::HashSet::new();
8663        for k in ConditionKind::ALL {
8664            if let Some(fr) = k.flux_resource() {
8665                assert!(
8666                    seen.insert(fr),
8667                    "duplicate FluxResource projection at {k:?}: {fr:?}",
8668                );
8669            }
8670        }
8671    }
8672
8673    /// `flux_resource` is `const fn` — the projection is reachable
8674    /// at compile time. A regression that dropped the `const`
8675    /// qualifier would fail-loudly here rather than as a wrong-slot
8676    /// runtime dispatch at every consumer callsite.
8677    #[test]
8678    fn flux_resource_projection_is_const_fn_reachable() {
8679        const K: Option<FluxResource> = ConditionKind::KustomizationHealthy.flux_resource();
8680        const H: Option<FluxResource> = ConditionKind::HelmReleaseReleased.flux_resource();
8681        const P: Option<FluxResource> = ConditionKind::ProcessPhase.flux_resource();
8682        assert_eq!(K, Some(FluxResource::Kustomization));
8683        assert_eq!(H, Some(FluxResource::HelmRelease));
8684        assert_eq!(P, None);
8685    }
8686
8687    // ── Boundary::has_condition_kind substrate pins ──────────────────
8688    //
8689    // Fail-before-pass-after granularity: `Boundary::has_condition_kind`
8690    // did not exist before this commit — the (preconditions +
8691    // postconditions .iter().any(|c| c.kind == K)) union-probe shape
8692    // lived hand-authored inline at the ephemeral require-tag surface
8693    // (`spec.postconditions.iter().any(|c| matches!(c.kind, K))`, sans
8694    // the pre-condition side). The lift places the closed-set-driven
8695    // presence probe on ONE substrate site so the point-domain
8696    // `condition-<kind>` prefix family in `tatara-check` composes it
8697    // through `strip_and_classify_prefixed_kind` byte-for-byte
8698    // symmetrical with `intent-<kind>` (via `Intent::has`) +
8699    // `lifetime-<kind>` (via `Lifetime::has`) — third instance in the
8700    // workspace closed-set-driven presence-probe algebra.
8701
8702    fn condition_with(kind: ConditionKind) -> Condition {
8703        Condition {
8704            kind,
8705            params: json!({}),
8706        }
8707    }
8708
8709    /// EMPTY-BOUNDARY pin — a default [`Boundary`] (no preconditions,
8710    /// no postconditions) returns `false` for EVERY [`ConditionKind`].
8711    /// Sweep `ConditionKind::ALL` so a new variant added without a
8712    /// matching arm in the presence probe surfaces at rustc's
8713    /// exhaustiveness gate on the ALL literal (arity forced by
8714    /// `[Self; 8]`) rather than as a silent false-positive at every
8715    /// downstream `condition-<kind>` require-tag callsite.
8716    #[test]
8717    fn has_condition_kind_returns_false_on_empty_boundary_for_every_kind() {
8718        let b = Boundary::default();
8719        for kind in ConditionKind::ALL {
8720            assert!(
8721                !b.has_condition_kind(kind),
8722                "default boundary must return false for {kind:?}",
8723            );
8724        }
8725    }
8726
8727    /// POSTCONDITION-only pin — a boundary that carries the kind on
8728    /// ONLY postconditions returns `true` for that kind, `false` for
8729    /// every other variant. Sweep the ALL × ALL cross so a regression
8730    /// that (a) hard-coded the arm to a single kind (silently
8731    /// returning true for every populated boundary regardless of
8732    /// which kind was queried), (b) skipped the postcondition side of
8733    /// the union (silently returning false when the kind lived
8734    /// post-only), or (c) matched on Condition::params instead of
8735    /// Condition::kind fails HERE at the substrate primitive.
8736    #[test]
8737    fn has_condition_kind_reads_postconditions_per_kind() {
8738        for populated in ConditionKind::ALL {
8739            let mut b = Boundary::default();
8740            b.postconditions.push(condition_with(populated));
8741            for query in ConditionKind::ALL {
8742                let expected = query == populated;
8743                assert_eq!(
8744                    b.has_condition_kind(query),
8745                    expected,
8746                    "postcondition populated={populated:?}: query {query:?} drifted",
8747                );
8748            }
8749        }
8750    }
8751
8752    /// PRECONDITION-only pin — mirrors the postcondition sweep on the
8753    /// other half of the union. Locks the union semantics on both
8754    /// halves separately so a regression that dropped the
8755    /// pre-condition side of the OR fails here even though the
8756    /// postcondition-side pin above passes.
8757    #[test]
8758    fn has_condition_kind_reads_preconditions_per_kind() {
8759        for populated in ConditionKind::ALL {
8760            let mut b = Boundary::default();
8761            b.preconditions.push(condition_with(populated));
8762            for query in ConditionKind::ALL {
8763                let expected = query == populated;
8764                assert_eq!(
8765                    b.has_condition_kind(query),
8766                    expected,
8767                    "precondition populated={populated:?}: query {query:?} drifted",
8768                );
8769            }
8770        }
8771    }
8772
8773    /// UNION pin — a kind that appears on preconditions returns
8774    /// `true` even when postconditions carries a DIFFERENT kind, and
8775    /// vice versa. Pins the OR-composition of the two halves so a
8776    /// regression that collapsed the union to an intersection (AND)
8777    /// silently reclassifies pre-only or post-only kinds as absent.
8778    #[test]
8779    fn has_condition_kind_unions_pre_and_post_condition_arms() {
8780        let mut b = Boundary::default();
8781        b.preconditions
8782            .push(condition_with(ConditionKind::KustomizationHealthy));
8783        b.postconditions
8784            .push(condition_with(ConditionKind::ClosedLoopAuth));
8785        assert!(
8786            b.has_condition_kind(ConditionKind::KustomizationHealthy),
8787            "pre-only kind must resolve through the union",
8788        );
8789        assert!(
8790            b.has_condition_kind(ConditionKind::ClosedLoopAuth),
8791            "post-only kind must resolve through the union",
8792        );
8793        assert!(
8794            !b.has_condition_kind(ConditionKind::PromQL),
8795            "an absent kind must return false even with populated halves",
8796        );
8797    }
8798
8799    // ── ConditionSliceExt::has_kind substrate pins ────────────────────
8800    //
8801    // Fail-before-pass-after granularity: `ConditionSliceExt::has_kind`
8802    // did not exist before this commit — the `(&[Condition],
8803    // ConditionKind) -> bool` walk shape lived hand-authored inline at
8804    // THREE production sites (twice inside `Boundary::has_condition_kind`
8805    // on `preconditions` ∪ `postconditions`, once at the ephemeral
8806    // require-tag classifier's `closed-loop-auth` arm on
8807    // `spec.postconditions` in `tatara-reconciler::bin::tatara-check`,
8808    // with `matches!` sugar instead of `==` but the same predicate).
8809    // The lift places the per-slice presence probe on ONE substrate site
8810    // so the two-half union at `Boundary` and the one-half probe at the
8811    // ephemeral surface compose against the SAME primitive rather than
8812    // restating the `.iter().any(|c| c.kind == K)` closure body.
8813
8814    /// EMPTY-SLICE pin — an empty `&[Condition]` returns `false` for
8815    /// EVERY [`ConditionKind`]. Sweep `ConditionKind::ALL` so a new
8816    /// variant added without a matching arm in the primitive surfaces
8817    /// at rustc's exhaustiveness gate on the ALL literal (arity forced
8818    /// by `[Self; 8]`) rather than as a silent false-positive at every
8819    /// downstream callsite composing this primitive.
8820    #[test]
8821    fn condition_slice_has_kind_returns_false_on_empty_slice_for_every_kind() {
8822        let empty: &[Condition] = &[];
8823        for kind in ConditionKind::ALL {
8824            assert!(
8825                !empty.has_kind(kind),
8826                "empty slice must return false for {kind:?}",
8827            );
8828        }
8829    }
8830
8831    /// PER-VARIANT pin — a single-element slice returns `true` for
8832    /// exactly the kind it carries, `false` for every other variant.
8833    /// Sweep the ALL × ALL cross so a regression that (a) hard-coded
8834    /// the arm to a single kind (silently returning true for every
8835    /// populated slice regardless of query kind), or (b) matched on
8836    /// [`Condition::params`] instead of [`Condition::kind`] fails HERE
8837    /// at the substrate primitive.
8838    #[test]
8839    fn condition_slice_has_kind_reads_kind_field_per_variant() {
8840        for populated in ConditionKind::ALL {
8841            let slice = [condition_with(populated)];
8842            for query in ConditionKind::ALL {
8843                let expected = query == populated;
8844                assert_eq!(
8845                    slice.has_kind(query),
8846                    expected,
8847                    "populated={populated:?}: query {query:?} drifted",
8848                );
8849            }
8850        }
8851    }
8852
8853    /// MULTI-ENTRY pin — a slice with multiple entries returns `true`
8854    /// for every kind that appears at any position (existential
8855    /// quantifier over the slice), `false` for kinds that appear at
8856    /// no position. Locks the `any` semantics so a regression that
8857    /// collapsed to a `first`-only probe (`slice.first().map_or(false,
8858    /// |c| c.kind == kind)`) fails here even though the single-element
8859    /// per-variant pin above passes.
8860    #[test]
8861    fn condition_slice_has_kind_scans_beyond_the_first_position() {
8862        let slice = [
8863            condition_with(ConditionKind::KustomizationHealthy),
8864            condition_with(ConditionKind::ClosedLoopAuth),
8865            condition_with(ConditionKind::JobAttested),
8866        ];
8867        for present in [
8868            ConditionKind::KustomizationHealthy,
8869            ConditionKind::ClosedLoopAuth,
8870            ConditionKind::JobAttested,
8871        ] {
8872            assert!(
8873                slice.has_kind(present),
8874                "kind at any position must resolve true: {present:?}",
8875            );
8876        }
8877        for absent in [
8878            ConditionKind::ProcessPhase,
8879            ConditionKind::HelmReleaseReleased,
8880            ConditionKind::PromQL,
8881            ConditionKind::Cel,
8882            ConditionKind::NixEval,
8883        ] {
8884            assert!(
8885                !slice.has_kind(absent),
8886                "kind absent from the slice must resolve false: {absent:?}",
8887            );
8888        }
8889    }
8890
8891    /// COMPOSITION pin — [`Boundary::has_condition_kind`] equals the OR
8892    /// of the two half-slice probes at EVERY (populated arrangement,
8893    /// query) pair on `ConditionKind::ALL`. Locks the (union-probe =
8894    /// pre.has_kind ∨ post.has_kind) composition contract at ONE test
8895    /// so a regression that (a) dropped the `||` (silently narrowing
8896    /// the union to an intersection, or to one side only), or
8897    /// (b) hand-authored the union with a divergent walk shape (e.g.
8898    /// summing counts, comparing lengths) surfaces HERE at the
8899    /// composition boundary rather than as silent classifier drift at
8900    /// every downstream `condition-<kind>` require-tag callsite.
8901    #[test]
8902    fn boundary_has_condition_kind_equals_or_of_half_slice_probes() {
8903        for pre_kind in ConditionKind::ALL {
8904            for post_kind in ConditionKind::ALL {
8905                let mut b = Boundary::default();
8906                b.preconditions.push(condition_with(pre_kind));
8907                b.postconditions.push(condition_with(post_kind));
8908                for query in ConditionKind::ALL {
8909                    let expected =
8910                        b.preconditions.has_kind(query) || b.postconditions.has_kind(query);
8911                    assert_eq!(
8912                        b.has_condition_kind(query),
8913                        expected,
8914                        "union drifted: pre={pre_kind:?} post={post_kind:?} query={query:?}",
8915                    );
8916                }
8917            }
8918        }
8919    }
8920
8921    // ── Boundary::has_(pre|post)condition_kind substrate pins ────────
8922    //
8923    // Fail-before-pass-after granularity: the two half-slice arms did
8924    // not exist before this commit — the point-domain `precondition-
8925    // <kind>` and `postcondition-<kind>` require-tag classifiers in
8926    // `tatara-reconciler::bin::tatara-check` reached the two condition
8927    // slices through direct field access
8928    // (`spec.boundary.preconditions.has_kind(k)`), bypassing the named
8929    // [`Boundary`] primitive surface that the union-probe
8930    // [`Boundary::has_condition_kind`] already routed through. The
8931    // lift closes the (precondition, postcondition, union) triad on
8932    // ONE typed algebra surface so a future normalization at the
8933    // presence-probe shape lands at ONE site for all three arms.
8934
8935    /// EMPTY-BOUNDARY pin (precondition arm) — a default [`Boundary`]
8936    /// returns `false` for EVERY [`ConditionKind`] on the precondition
8937    /// side. Sweep `ConditionKind::ALL` so a new variant added without
8938    /// a matching arm on the probe surfaces at rustc's exhaustiveness
8939    /// gate on the ALL literal (arity forced by `[Self; 8]`) rather
8940    /// than as a silent false-positive at every downstream
8941    /// `precondition-<kind>` require-tag callsite.
8942    #[test]
8943    fn has_precondition_kind_returns_false_on_empty_boundary_for_every_kind() {
8944        let b = Boundary::default();
8945        for kind in ConditionKind::ALL {
8946            assert!(
8947                !b.has_precondition_kind(kind),
8948                "default boundary must return false on precondition arm for {kind:?}",
8949            );
8950        }
8951    }
8952
8953    /// EMPTY-BOUNDARY pin (postcondition arm) — sibling of the
8954    /// precondition-arm empty pin above on the other half of the
8955    /// (precondition, postcondition) partition. Locks the empty-slice
8956    /// arm return on the postcondition side so a regression that
8957    /// wired the postcondition arm to the precondition slice surfaces
8958    /// HERE at fail-before-pass-after granularity.
8959    #[test]
8960    fn has_postcondition_kind_returns_false_on_empty_boundary_for_every_kind() {
8961        let b = Boundary::default();
8962        for kind in ConditionKind::ALL {
8963            assert!(
8964                !b.has_postcondition_kind(kind),
8965                "default boundary must return false on postcondition arm for {kind:?}",
8966            );
8967        }
8968    }
8969
8970    /// SLICE-SELECTIVITY pin (precondition arm) — a boundary with a
8971    /// kind on the precondition side ONLY resolves `true` at
8972    /// `has_precondition_kind` and `false` at `has_postcondition_kind`.
8973    /// Locks the (side-select, kind-select) partition so a regression
8974    /// that pointed the precondition arm at `self.postconditions` (a
8975    /// copy-paste from the sibling arm) surfaces HERE rather than as
8976    /// silent classifier drift at every downstream
8977    /// `precondition-<kind>` require-tag callsite.
8978    #[test]
8979    fn has_precondition_kind_reads_preconditions_slice_only() {
8980        for populated in ConditionKind::ALL {
8981            let mut b = Boundary::default();
8982            b.preconditions.push(condition_with(populated));
8983            for query in ConditionKind::ALL {
8984                let expected_pre = query == populated;
8985                assert_eq!(
8986                    b.has_precondition_kind(query),
8987                    expected_pre,
8988                    "precondition-only populated={populated:?}: query {query:?} drifted \
8989                     on precondition arm",
8990                );
8991                assert!(
8992                    !b.has_postcondition_kind(query),
8993                    "precondition-only populated={populated:?}: query {query:?} must \
8994                     return false on postcondition arm (postconditions is empty)",
8995                );
8996            }
8997        }
8998    }
8999
9000    /// SLICE-SELECTIVITY pin (postcondition arm) — mirror of the
9001    /// precondition-only sweep on the other half. Locks the sibling
9002    /// arm's binding to `self.postconditions` so a regression that
9003    /// pointed the postcondition arm at `self.preconditions` fails
9004    /// HERE even though the precondition-arm pin above passes.
9005    #[test]
9006    fn has_postcondition_kind_reads_postconditions_slice_only() {
9007        for populated in ConditionKind::ALL {
9008            let mut b = Boundary::default();
9009            b.postconditions.push(condition_with(populated));
9010            for query in ConditionKind::ALL {
9011                let expected_post = query == populated;
9012                assert_eq!(
9013                    b.has_postcondition_kind(query),
9014                    expected_post,
9015                    "postcondition-only populated={populated:?}: query {query:?} \
9016                     drifted on postcondition arm",
9017                );
9018                assert!(
9019                    !b.has_precondition_kind(query),
9020                    "postcondition-only populated={populated:?}: query {query:?} must \
9021                     return false on precondition arm (preconditions is empty)",
9022                );
9023            }
9024        }
9025    }
9026
9027    /// COMPOSITION-LAW pin — [`Boundary::has_condition_kind`] equals
9028    /// `has_precondition_kind(k) || has_postcondition_kind(k)` at
9029    /// EVERY (pre-populated, post-populated, query) triple on
9030    /// `ConditionKind::ALL`. This is the load-bearing invariant that
9031    /// makes the (precondition, postcondition, union) triad on
9032    /// [`Boundary`] a first-class typed algebra rather than a
9033    /// per-caller discipline: the two half-slice arms + the union arm
9034    /// compose exactly as `union == pre ∨ post`, and every downstream
9035    /// `condition-<K> = precondition-<K> ∨ postcondition-<K>` classifier
9036    /// invariant on `tatara-reconciler::bin::tatara-check` inherits it
9037    /// mechanically. A regression that (a) dropped the composition (by
9038    /// re-inlining `.has_kind(kind)` bodies on the union arm), or
9039    /// (b) drifted ONE of the two half-slice arms without updating the
9040    /// other, surfaces HERE rather than as silent per-side classifier
9041    /// drift at the require-tag surfaces.
9042    #[test]
9043    fn boundary_has_condition_kind_composes_precondition_and_postcondition_arms() {
9044        for pre_kind in ConditionKind::ALL {
9045            for post_kind in ConditionKind::ALL {
9046                let mut b = Boundary::default();
9047                b.preconditions.push(condition_with(pre_kind));
9048                b.postconditions.push(condition_with(post_kind));
9049                for query in ConditionKind::ALL {
9050                    let via_arms =
9051                        b.has_precondition_kind(query) || b.has_postcondition_kind(query);
9052                    assert_eq!(
9053                        b.has_condition_kind(query),
9054                        via_arms,
9055                        "union arm drifted from OR of half-slice arms: \
9056                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9057                    );
9058                }
9059            }
9060        }
9061    }
9062
9063    /// SUBSTRATE-DELEGATION pin — the two half-slice arms delegate
9064    /// verbatim to [`ConditionSliceExt::has_kind`] on the underlying
9065    /// [`Vec<Condition>`] slice, no inline reimplementation. Sweep the
9066    /// full `ConditionKind::ALL` × `ConditionKind::ALL` cross so a
9067    /// regression that inlined a divergent walk (`.iter().find(_).
9068    /// is_some()`, an `.any(|c| matches!(c.kind, K))` that missed a
9069    /// variant) at either arm surfaces HERE at the substrate
9070    /// boundary rather than as silent skew between the struct-level
9071    /// arm and the slice-level primitive downstream consumers reach
9072    /// through.
9073    #[test]
9074    fn has_precondition_and_postcondition_kind_delegate_to_slice_has_kind() {
9075        for populated in ConditionKind::ALL {
9076            let mut b = Boundary::default();
9077            b.preconditions.push(condition_with(populated));
9078            b.postconditions.push(condition_with(populated));
9079            for query in ConditionKind::ALL {
9080                assert_eq!(
9081                    b.has_precondition_kind(query),
9082                    b.preconditions.has_kind(query),
9083                    "precondition arm must delegate to preconditions.has_kind: \
9084                     populated={populated:?} query={query:?}",
9085                );
9086                assert_eq!(
9087                    b.has_postcondition_kind(query),
9088                    b.postconditions.has_kind(query),
9089                    "postcondition arm must delegate to postconditions.has_kind: \
9090                     populated={populated:?} query={query:?}",
9091                );
9092            }
9093        }
9094    }
9095
9096    // ── ConditionSliceExt::find_kind substrate pins + widened triad ──
9097    //
9098    // Fail-before-pass-after granularity: `ConditionSliceExt::find_kind`
9099    // + its three struct-level peers (`Boundary::find_(pre|post)?
9100    // condition_kind`) did not exist before this commit — the existing
9101    // `has_*_kind` triad collapses the return to `bool`, losing the
9102    // matching `&Condition` a future diagnostic consumer (an operator-
9103    // facing "found on {pre|post}conditions at param.probeImage=X"
9104    // message, a coherence check verifying "every ClosedLoopAuth
9105    // postcondition carries a non-empty probeImage", an editor
9106    // completion listing params-keys per present kind) needs. The lift
9107    // widens the primitive to `Option<&Condition>` and re-anchors
9108    // `has_kind` as a default composed from it, so the two refinements
9109    // share ONE walk semantics by construction.
9110
9111    /// EMPTY-SLICE pin — an empty `&[Condition]` returns `None` from
9112    /// `find_kind` for EVERY [`ConditionKind`]. Sweep
9113    /// `ConditionKind::ALL` so a new variant added without a matching
9114    /// arm in the primitive surfaces at rustc's exhaustiveness gate on
9115    /// the ALL literal (arity forced by `[Self; 8]`) rather than as a
9116    /// silent false-`Some` at every downstream widened callsite.
9117    #[test]
9118    fn condition_slice_find_kind_returns_none_on_empty_slice_for_every_kind() {
9119        let empty: &[Condition] = &[];
9120        for kind in ConditionKind::ALL {
9121            assert!(
9122                empty.find_kind(kind).is_none(),
9123                "empty slice must return None for {kind:?}",
9124            );
9125        }
9126    }
9127
9128    /// PER-VARIANT pin — a single-element slice returns `Some` with
9129    /// the matching kind for exactly the kind it carries, `None` for
9130    /// every other variant. Sweep the ALL × ALL cross so a regression
9131    /// that (a) hard-coded the arm to a single kind (silently returning
9132    /// `Some` for every populated slice regardless of query kind), or
9133    /// (b) matched on [`Condition::params`] instead of [`Condition::kind`]
9134    /// fails HERE at the substrate primitive.
9135    #[test]
9136    fn condition_slice_find_kind_reads_kind_field_per_variant() {
9137        for populated in ConditionKind::ALL {
9138            let slice = [condition_with(populated)];
9139            for query in ConditionKind::ALL {
9140                let hit = slice.find_kind(query);
9141                if query == populated {
9142                    assert_eq!(
9143                        hit.map(|c| c.kind),
9144                        Some(populated),
9145                        "populated={populated:?}: query {query:?} must return Some",
9146                    );
9147                } else {
9148                    assert!(
9149                        hit.is_none(),
9150                        "populated={populated:?}: query {query:?} must return None",
9151                    );
9152                }
9153            }
9154        }
9155    }
9156
9157    /// FIRST-MATCH pin — a slice with the same kind at MULTIPLE
9158    /// positions returns the earliest by position. Locks the `.iter().
9159    /// find(...)` semantics so a regression that collapsed to a
9160    /// `.last()` walk (returning the trailing match) or a `.rev().
9161    /// find(...)` walk (returning the last-inserted match) surfaces
9162    /// HERE, since diagnostic consumers reading `find_kind(K).unwrap().
9163    /// params` expect the FIRST occurrence's params-payload not the
9164    /// last.
9165    #[test]
9166    fn condition_slice_find_kind_returns_first_position_on_duplicate_kinds() {
9167        // Two ClosedLoopAuth entries with distinct params — a first-
9168        // match walk resolves to the leading entry's params-payload.
9169        let first = Condition {
9170            kind: ConditionKind::ClosedLoopAuth,
9171            params: json!({ "probeImage": "first" }),
9172        };
9173        let second = Condition {
9174            kind: ConditionKind::ClosedLoopAuth,
9175            params: json!({ "probeImage": "second" }),
9176        };
9177        let slice = [first, second];
9178        let hit = slice
9179            .find_kind(ConditionKind::ClosedLoopAuth)
9180            .expect("populated slice must resolve Some on the matching kind");
9181        assert_eq!(
9182            hit.params
9183                .get("probeImage")
9184                .and_then(serde_json::Value::as_str),
9185            Some("first"),
9186            "find_kind must return the FIRST position's Condition on duplicate kinds",
9187        );
9188    }
9189
9190    /// SLICE-LEVEL DELEGATION pin (has ↔ find) — [`ConditionSliceExt::has_kind`]
9191    /// equals `find_kind(k).is_some()` at EVERY (populated arrangement,
9192    /// query) pair on `ConditionKind::ALL`. Turns the trait doc's
9193    /// "compounding" note ("the closed-set discriminator case becomes
9194    /// `has_kind(k) == self.find_kind(k).is_some()` by construction")
9195    /// into a first-class typed test invariant: a future consumer
9196    /// that overrode the default `has_kind` body with a divergent walk
9197    /// shape (a `.iter().any(...)` that missed a variant, a `.count() >
9198    /// 0` predicate on a filtered clone) surfaces HERE at the substrate
9199    /// boundary rather than as silent skew between the two refinements
9200    /// downstream consumers reach through.
9201    #[test]
9202    fn condition_slice_has_kind_equals_find_kind_is_some() {
9203        for pre_kind in ConditionKind::ALL {
9204            for post_kind in ConditionKind::ALL {
9205                let slice = [condition_with(pre_kind), condition_with(post_kind)];
9206                for query in ConditionKind::ALL {
9207                    assert_eq!(
9208                        slice.has_kind(query),
9209                        slice.find_kind(query).is_some(),
9210                        "slice-level has/find refinement bridge drifted: \
9211                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9212                    );
9213                }
9214            }
9215        }
9216    }
9217
9218    /// SUBSTRATE-DELEGATION pin (find-triad) — the three widened
9219    /// `find_*_kind` methods on [`Boundary`] delegate verbatim to
9220    /// [`ConditionSliceExt::find_kind`] on the underlying
9221    /// [`Vec<Condition>`] slices, no inline reimplementation. The
9222    /// `find_condition_kind` union walks preconditions first then
9223    /// postconditions via `Option::or_else`. Sweep
9224    /// `ConditionKind::ALL × ConditionKind::ALL × ConditionKind::ALL`
9225    /// so a regression that (a) inlined a divergent walk at either
9226    /// half-slice arm, (b) reversed the union walk order (postcondition
9227    /// first), or (c) collapsed `or_else` to `and_then` (silently
9228    /// narrowing the union to an intersection) surfaces HERE at the
9229    /// substrate boundary rather than as silent skew between the
9230    /// struct-level widened arms and the slice-level primitive.
9231    #[test]
9232    fn find_condition_kind_triad_delegates_to_slice_find_kind() {
9233        for pre_kind in ConditionKind::ALL {
9234            for post_kind in ConditionKind::ALL {
9235                let mut b = Boundary::default();
9236                b.preconditions.push(condition_with(pre_kind));
9237                b.postconditions.push(condition_with(post_kind));
9238                for query in ConditionKind::ALL {
9239                    let via_pre = b.preconditions.find_kind(query);
9240                    let via_post = b.postconditions.find_kind(query);
9241                    assert_eq!(
9242                        b.find_precondition_kind(query).map(|c| c.kind),
9243                        via_pre.map(|c| c.kind),
9244                        "precondition find arm must delegate to preconditions.find_kind: \
9245                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9246                    );
9247                    assert_eq!(
9248                        b.find_postcondition_kind(query).map(|c| c.kind),
9249                        via_post.map(|c| c.kind),
9250                        "postcondition find arm must delegate to postconditions.find_kind: \
9251                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9252                    );
9253                    let expected_union = via_pre.or(via_post).map(|c| c.kind);
9254                    assert_eq!(
9255                        b.find_condition_kind(query).map(|c| c.kind),
9256                        expected_union,
9257                        "union find arm must equal precondition.or_else(postcondition): \
9258                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9259                    );
9260                }
9261            }
9262        }
9263    }
9264
9265    /// PRECONDITION-PRECEDENCE pin — a kind authored on BOTH sides
9266    /// returns the precondition-side [`Condition`] from
9267    /// `find_condition_kind`. Uses two params-distinguishable
9268    /// [`Condition`]s so a regression that reversed the walk order
9269    /// (postcondition first) surfaces at the returned params payload
9270    /// rather than silently at the presence bit (which is `true` on
9271    /// both walk orders).
9272    #[test]
9273    fn find_condition_kind_returns_precondition_side_on_dual_populated() {
9274        let mut b = Boundary::default();
9275        b.preconditions.push(Condition {
9276            kind: ConditionKind::ClosedLoopAuth,
9277            params: json!({ "side": "pre" }),
9278        });
9279        b.postconditions.push(Condition {
9280            kind: ConditionKind::ClosedLoopAuth,
9281            params: json!({ "side": "post" }),
9282        });
9283        let hit = b
9284            .find_condition_kind(ConditionKind::ClosedLoopAuth)
9285            .expect("dual-populated boundary must resolve Some");
9286        assert_eq!(
9287            hit.params.get("side").and_then(serde_json::Value::as_str),
9288            Some("pre"),
9289            "find_condition_kind must walk preconditions first: dual-populated kind \
9290             returned postcondition-side Condition rather than precondition-side",
9291        );
9292    }
9293
9294    /// STRUCT-LEVEL DELEGATION pin (has ↔ find) — the three
9295    /// [`Boundary`] `has_*_kind` arms equal their widened peers'
9296    /// `.is_some()` projection at EVERY (pre-populated, post-populated,
9297    /// query) triple on `ConditionKind::ALL`. The three widened
9298    /// `find_*_kind` arms are the load-bearing primitives; the three
9299    /// `has_*_kind` arms are their bool projections. Byte-for-byte
9300    /// re-anchors the composition-law pin
9301    /// `boundary_has_condition_kind_composes_precondition_and_postcondition_arms`
9302    /// through the widened axis so a future consumer that reads
9303    /// `has_condition_kind` as sugar for `find_condition_kind(k).
9304    /// is_some()` (rather than as `has_precondition_kind ||
9305    /// has_postcondition_kind`) stays typed against the SAME truth
9306    /// table.
9307    #[test]
9308    fn boundary_has_triad_equals_find_triad_is_some_projection() {
9309        for pre_kind in ConditionKind::ALL {
9310            for post_kind in ConditionKind::ALL {
9311                let mut b = Boundary::default();
9312                b.preconditions.push(condition_with(pre_kind));
9313                b.postconditions.push(condition_with(post_kind));
9314                for query in ConditionKind::ALL {
9315                    assert_eq!(
9316                        b.has_precondition_kind(query),
9317                        b.find_precondition_kind(query).is_some(),
9318                        "precondition has/find bridge drifted: \
9319                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9320                    );
9321                    assert_eq!(
9322                        b.has_postcondition_kind(query),
9323                        b.find_postcondition_kind(query).is_some(),
9324                        "postcondition has/find bridge drifted: \
9325                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9326                    );
9327                    assert_eq!(
9328                        b.has_condition_kind(query),
9329                        b.find_condition_kind(query).is_some(),
9330                        "union has/find bridge drifted: \
9331                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9332                    );
9333                }
9334            }
9335        }
9336    }
9337
9338    // ── ConditionSliceExt::iter_kind substrate pins + widened triad ──
9339    //
9340    // Fail-before-pass-after granularity: `ConditionSliceExt::iter_kind`
9341    // + its three struct-level peers (`Boundary::iter_(pre|post|)?
9342    // condition_kind`) did not exist before this commit — the existing
9343    // `find_*_kind` triad collapses the return to `Option<&Condition>`
9344    // (yielding only the FIRST match), losing the full match stream a
9345    // future coherence check ("each ConditionKind appears at most
9346    // once per side" — `iter_kind(k).nth(1).is_none()`) or diagnostic
9347    // consumer ("N ClosedLoopAuth postconditions matched, listing
9348    // every param.probeImage" — `iter_kind(k).collect()`) needs. The
9349    // lift widens the primitive to `KindMatches<'_>` (a named
9350    // Iterator<Item = &Condition>) and re-anchors `find_kind` as a
9351    // default composed from it (`self.iter_kind(kind).next()`), so
9352    // the three refinements share ONE walk semantics by construction.
9353
9354    /// EMPTY-SLICE pin (iter) — an empty `&[Condition]` yields
9355    /// nothing from `iter_kind` for EVERY [`ConditionKind`]. Sweep
9356    /// `ConditionKind::ALL` so a new variant added without a matching
9357    /// arm in the primitive surfaces at rustc's exhaustiveness gate
9358    /// on the ALL literal rather than as a silent phantom-yield at
9359    /// every downstream widened callsite.
9360    #[test]
9361    fn condition_slice_iter_kind_yields_nothing_on_empty_slice_for_every_kind() {
9362        let empty: &[Condition] = &[];
9363        for kind in ConditionKind::ALL {
9364            assert_eq!(
9365                empty.iter_kind(kind).count(),
9366                0,
9367                "empty slice must yield nothing on iter_kind for {kind:?}",
9368            );
9369        }
9370    }
9371
9372    /// PER-VARIANT pin (iter) — a single-element slice yields exactly
9373    /// that element on the matching kind and nothing on every other
9374    /// kind. Sweep the ALL × ALL cross so a regression that (a)
9375    /// hard-coded the filter predicate to a single kind (silently
9376    /// yielding on every populated slice regardless of query kind),
9377    /// or (b) matched on [`Condition::params`] instead of
9378    /// [`Condition::kind`] fails HERE at the substrate primitive.
9379    #[test]
9380    fn condition_slice_iter_kind_reads_kind_field_per_variant() {
9381        for populated in ConditionKind::ALL {
9382            let slice = [condition_with(populated)];
9383            for query in ConditionKind::ALL {
9384                let collected: Vec<_> = slice.iter_kind(query).map(|c| c.kind).collect();
9385                if query == populated {
9386                    assert_eq!(
9387                        collected,
9388                        vec![populated],
9389                        "populated={populated:?}: query {query:?} must yield [populated]",
9390                    );
9391                } else {
9392                    assert!(
9393                        collected.is_empty(),
9394                        "populated={populated:?}: query {query:?} must yield nothing",
9395                    );
9396                }
9397            }
9398        }
9399    }
9400
9401    /// ALL-MATCHES pin — a slice with the same kind at MULTIPLE
9402    /// positions yields EVERY match in slice order (not just the
9403    /// first). Uses params-distinguishable [`Condition`]s so a
9404    /// regression that (a) collapsed to a single-match walk
9405    /// (`.iter().find(...)` yielding only the earliest and
9406    /// terminating), (b) reversed the yield order (`.rev().filter`
9407    /// yielding trailing-first), or (c) de-duplicated by kind (an
9408    /// erroneous `HashSet::insert`-gated walk) surfaces HERE at the
9409    /// params payload rather than silently at a downstream
9410    /// count-based coherence check.
9411    #[test]
9412    fn condition_slice_iter_kind_yields_every_match_in_slice_order_on_duplicates() {
9413        let first = Condition {
9414            kind: ConditionKind::ClosedLoopAuth,
9415            params: json!({ "probeImage": "first" }),
9416        };
9417        let middle = Condition {
9418            kind: ConditionKind::PromQL,
9419            params: json!({ "query": "up" }),
9420        };
9421        let second_cla = Condition {
9422            kind: ConditionKind::ClosedLoopAuth,
9423            params: json!({ "probeImage": "second" }),
9424        };
9425        let slice = [first, middle, second_cla];
9426        let hits: Vec<_> = slice
9427            .iter_kind(ConditionKind::ClosedLoopAuth)
9428            .map(|c| {
9429                c.params
9430                    .get("probeImage")
9431                    .and_then(serde_json::Value::as_str)
9432                    .unwrap_or_default()
9433                    .to_owned()
9434            })
9435            .collect();
9436        assert_eq!(
9437            hits,
9438            vec!["first".to_owned(), "second".to_owned()],
9439            "iter_kind must yield every match in slice order (not just the first)",
9440        );
9441        // The interleaved non-matching kind is skipped: two hits, not three.
9442        assert_eq!(
9443            slice.iter_kind(ConditionKind::ClosedLoopAuth).count(),
9444            2,
9445            "iter_kind must skip non-matching kinds, not include them in the stream",
9446        );
9447    }
9448
9449    /// SLICE-LEVEL DELEGATION pin (find ↔ iter) — the trait's default
9450    /// `find_kind` body equals `iter_kind(k).next()` at EVERY
9451    /// (populated arrangement, query) pair on `ConditionKind::ALL`.
9452    /// Turns the trait doc's composition-law note
9453    /// ("`find_kind(k) == iter_kind(k).next()` by construction")
9454    /// into a first-class typed test invariant: a future implementor
9455    /// that overrode the default `find_kind` body with a divergent
9456    /// walk shape (a `.iter().rev().find(...)` returning trailing-
9457    /// first, a hand-rolled loop that walked past the first match)
9458    /// surfaces HERE at the substrate boundary rather than as silent
9459    /// skew between the two refinements downstream consumers reach
9460    /// through.
9461    #[test]
9462    fn condition_slice_find_kind_equals_iter_kind_next() {
9463        for pre_kind in ConditionKind::ALL {
9464            for post_kind in ConditionKind::ALL {
9465                let slice = [condition_with(pre_kind), condition_with(post_kind)];
9466                for query in ConditionKind::ALL {
9467                    assert_eq!(
9468                        slice.find_kind(query).map(|c| c.kind),
9469                        slice.iter_kind(query).next().map(|c| c.kind),
9470                        "slice-level find/iter refinement bridge drifted: \
9471                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9472                    );
9473                }
9474            }
9475        }
9476    }
9477
9478    /// SUBSTRATE-DELEGATION pin (Boundary iter-triad) — the three
9479    /// widened `iter_*_kind` methods on [`Boundary`] delegate verbatim
9480    /// to [`ConditionSliceExt::iter_kind`] on the underlying
9481    /// [`Vec<Condition>`] slices, no inline reimplementation. The
9482    /// `iter_condition_kind` union chains preconditions first then
9483    /// postconditions via [`Iterator::chain`]. Sweep
9484    /// `ConditionKind::ALL × ConditionKind::ALL × ConditionKind::ALL`
9485    /// so a regression that (a) inlined a divergent walk at either
9486    /// half-slice arm, (b) reversed the chain order (postcondition
9487    /// first — walk-order regression on the union), or (c) collapsed
9488    /// the chain to a `.zip(...)` (silently narrowing the union to
9489    /// an intersection-by-position) surfaces HERE at the substrate
9490    /// boundary rather than as silent skew between the struct-level
9491    /// widened arms and the slice-level primitive.
9492    #[test]
9493    fn iter_condition_kind_triad_delegates_to_slice_iter_kind() {
9494        for pre_kind in ConditionKind::ALL {
9495            for post_kind in ConditionKind::ALL {
9496                let mut b = Boundary::default();
9497                b.preconditions.push(condition_with(pre_kind));
9498                b.postconditions.push(condition_with(post_kind));
9499                for query in ConditionKind::ALL {
9500                    let via_pre: Vec<_> =
9501                        b.preconditions.iter_kind(query).map(|c| c.kind).collect();
9502                    let via_post: Vec<_> =
9503                        b.postconditions.iter_kind(query).map(|c| c.kind).collect();
9504                    assert_eq!(
9505                        b.iter_precondition_kind(query)
9506                            .map(|c| c.kind)
9507                            .collect::<Vec<_>>(),
9508                        via_pre,
9509                        "precondition iter arm must delegate to preconditions.iter_kind: \
9510                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9511                    );
9512                    assert_eq!(
9513                        b.iter_postcondition_kind(query)
9514                            .map(|c| c.kind)
9515                            .collect::<Vec<_>>(),
9516                        via_post,
9517                        "postcondition iter arm must delegate to postconditions.iter_kind: \
9518                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9519                    );
9520                    let mut expected_union = via_pre.clone();
9521                    expected_union.extend(via_post.iter().copied());
9522                    assert_eq!(
9523                        b.iter_condition_kind(query)
9524                            .map(|c| c.kind)
9525                            .collect::<Vec<_>>(),
9526                        expected_union,
9527                        "union iter arm must chain precondition ⨟ postcondition: \
9528                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9529                    );
9530                }
9531            }
9532        }
9533    }
9534
9535    /// STRUCT-LEVEL DELEGATION pin (find ↔ iter on Boundary) — the
9536    /// three [`Boundary`] `find_*_kind` arms equal their widened
9537    /// peers' `.next()` projection at EVERY (pre-populated,
9538    /// post-populated, query) triple on `ConditionKind::ALL`. Byte-
9539    /// for-byte re-anchors the composition-law pin
9540    /// `find_condition_kind == iter_condition_kind.next()` through
9541    /// the widened axis on the parent surface — a future consumer
9542    /// that reads `find_condition_kind(k)` as sugar for
9543    /// `iter_condition_kind(k).next()` stays typed against the SAME
9544    /// truth table on both the slice-level and struct-level layers.
9545    #[test]
9546    fn boundary_find_triad_equals_iter_triad_next_projection() {
9547        for pre_kind in ConditionKind::ALL {
9548            for post_kind in ConditionKind::ALL {
9549                let mut b = Boundary::default();
9550                b.preconditions.push(condition_with(pre_kind));
9551                b.postconditions.push(condition_with(post_kind));
9552                for query in ConditionKind::ALL {
9553                    assert_eq!(
9554                        b.find_precondition_kind(query).map(|c| c.kind),
9555                        b.iter_precondition_kind(query).next().map(|c| c.kind),
9556                        "precondition find/iter bridge drifted: \
9557                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9558                    );
9559                    assert_eq!(
9560                        b.find_postcondition_kind(query).map(|c| c.kind),
9561                        b.iter_postcondition_kind(query).next().map(|c| c.kind),
9562                        "postcondition find/iter bridge drifted: \
9563                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9564                    );
9565                    assert_eq!(
9566                        b.find_condition_kind(query).map(|c| c.kind),
9567                        b.iter_condition_kind(query).next().map(|c| c.kind),
9568                        "union find/iter bridge drifted: \
9569                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9570                    );
9571                }
9572            }
9573        }
9574    }
9575
9576    /// PRECONDITION-PRECEDENCE pin (iter) — a kind authored on BOTH
9577    /// sides yields precondition-side matches FIRST in the union
9578    /// chain. Uses params-distinguishable [`Condition`]s so a
9579    /// regression that (a) reversed the chain order on the widened
9580    /// axis (postcondition first), (b) interleaved the two sides,
9581    /// or (c) collapsed the chain to a `.zip(...)` fails at the
9582    /// returned params-payload sequence rather than silently at the
9583    /// count.
9584    #[test]
9585    fn iter_condition_kind_yields_preconditions_before_postconditions_on_dual_populated() {
9586        let mut b = Boundary::default();
9587        b.preconditions.push(Condition {
9588            kind: ConditionKind::ClosedLoopAuth,
9589            params: json!({ "side": "pre-1" }),
9590        });
9591        b.preconditions.push(Condition {
9592            kind: ConditionKind::ClosedLoopAuth,
9593            params: json!({ "side": "pre-2" }),
9594        });
9595        b.postconditions.push(Condition {
9596            kind: ConditionKind::ClosedLoopAuth,
9597            params: json!({ "side": "post-1" }),
9598        });
9599        let sides: Vec<_> = b
9600            .iter_condition_kind(ConditionKind::ClosedLoopAuth)
9601            .map(|c| {
9602                c.params
9603                    .get("side")
9604                    .and_then(serde_json::Value::as_str)
9605                    .unwrap_or_default()
9606                    .to_owned()
9607            })
9608            .collect();
9609        assert_eq!(
9610            sides,
9611            vec!["pre-1".to_owned(), "pre-2".to_owned(), "post-1".to_owned(),],
9612            "iter_condition_kind must yield every precondition-side match before any \
9613             postcondition-side match (chain order pinned by two-surface parity contract)",
9614        );
9615    }
9616
9617    // ----- count_kind — scalar cardinality refinement --------------------
9618    //
9619    // The `count_kind` fourth refinement collapses the widened
9620    // `iter_kind` stream to its cardinality without materializing an
9621    // intermediate `Vec` or `Option`. Distinct composition law from the
9622    // three prior refinements: `count_condition_kind` SUMS pre + post
9623    // (rather than OR-ing them via `has`, or_else-ing them via `find`,
9624    // or Chain-ing them via `iter`). The tests below pin (a) the default
9625    // trait body against the primitive `iter_kind(k).count()`, (b) the
9626    // slice-level composition laws `has_kind(k) == (count_kind(k) > 0)`
9627    // and `find_kind(k).is_some() == (count_kind(k) > 0)`, (c) the
9628    // struct-level SUM composition on both `Boundary` half-slice arms,
9629    // and (d) the two-surface parity contract with
9630    // `EphemeralSpec::count_(pre|post|)condition_kind` (in ephemeral.rs).
9631
9632    /// EMPTY-SLICE pin (count) — an empty `&[Condition]` returns `0`
9633    /// from `count_kind` for EVERY [`ConditionKind`]. Sweep
9634    /// `ConditionKind::ALL` so a new variant added without a matching
9635    /// arm surfaces at rustc's exhaustiveness gate on the ALL literal
9636    /// rather than as silent phantom-cardinality at every downstream
9637    /// count callsite.
9638    #[test]
9639    fn condition_slice_count_kind_returns_zero_on_empty_slice_for_every_kind() {
9640        let empty: &[Condition] = &[];
9641        for kind in ConditionKind::ALL {
9642            assert_eq!(
9643                empty.count_kind(kind),
9644                0,
9645                "empty slice must count 0 for {kind:?}",
9646            );
9647        }
9648    }
9649
9650    /// PER-VARIANT pin (count) — a single-element slice returns `1`
9651    /// on the matching kind and `0` on every other kind. Sweep ALL ×
9652    /// ALL so a regression that (a) hard-coded the filter predicate
9653    /// to a single kind (silently counting every populated slice
9654    /// regardless of query), or (b) matched on [`Condition::params`]
9655    /// instead of [`Condition::kind`] fails HERE at the substrate
9656    /// primitive.
9657    #[test]
9658    fn condition_slice_count_kind_reads_kind_field_per_variant() {
9659        for populated in ConditionKind::ALL {
9660            let slice = [condition_with(populated)];
9661            for query in ConditionKind::ALL {
9662                let expected = if query == populated { 1 } else { 0 };
9663                assert_eq!(
9664                    slice.count_kind(query),
9665                    expected,
9666                    "populated={populated:?} query={query:?} \
9667                     must count {expected}",
9668                );
9669            }
9670        }
9671    }
9672
9673    /// DUPLICATES pin (count) — a slice with the same kind at
9674    /// MULTIPLE positions returns the exact match count (not `1`, not
9675    /// a de-duplicated `1`). A regression that (a) short-circuited on
9676    /// the first match (an `.iter().find(...)` yielding `0`/`1` sugar
9677    /// on the count arm), or (b) de-duplicated by kind (an erroneous
9678    /// `HashSet::insert`-gated walk that swallowed repeats) surfaces
9679    /// HERE at the cardinality boundary rather than silently at a
9680    /// downstream count-based coherence check.
9681    #[test]
9682    fn condition_slice_count_kind_counts_every_match_on_duplicates() {
9683        let slice = [
9684            Condition {
9685                kind: ConditionKind::ClosedLoopAuth,
9686                params: json!({ "probeImage": "first" }),
9687            },
9688            Condition {
9689                kind: ConditionKind::PromQL,
9690                params: json!({ "query": "up" }),
9691            },
9692            Condition {
9693                kind: ConditionKind::ClosedLoopAuth,
9694                params: json!({ "probeImage": "second" }),
9695            },
9696        ];
9697        assert_eq!(slice.count_kind(ConditionKind::ClosedLoopAuth), 2);
9698        assert_eq!(slice.count_kind(ConditionKind::PromQL), 1);
9699        for kind in ConditionKind::ALL {
9700            if matches!(kind, ConditionKind::ClosedLoopAuth | ConditionKind::PromQL) {
9701                continue;
9702            }
9703            assert_eq!(
9704                slice.count_kind(kind),
9705                0,
9706                "non-populated kind {kind:?} must count 0",
9707            );
9708        }
9709    }
9710
9711    /// SLICE-LEVEL DELEGATION pin (count ↔ iter) — the trait's
9712    /// default `count_kind` body equals `iter_kind(k).count()` at
9713    /// EVERY (populated arrangement, query) pair on
9714    /// `ConditionKind::ALL`. Turns the trait doc's composition-law
9715    /// note (`count_kind(k) == iter_kind(k).count()` by construction)
9716    /// into a first-class typed invariant: a future implementor that
9717    /// overrode the default `count_kind` body with a divergent walk
9718    /// shape (a stored-length cache that drifted, a `.step_by(2)`
9719    /// artefact from a copy-paste of `iter_kind`) surfaces HERE.
9720    #[test]
9721    fn condition_slice_count_kind_equals_iter_kind_count() {
9722        for pre_kind in ConditionKind::ALL {
9723            for post_kind in ConditionKind::ALL {
9724                let slice = [condition_with(pre_kind), condition_with(post_kind)];
9725                for query in ConditionKind::ALL {
9726                    assert_eq!(
9727                        slice.count_kind(query),
9728                        slice.iter_kind(query).count(),
9729                        "count/iter bridge drifted: pre={pre_kind:?} \
9730                         post={post_kind:?} query={query:?}",
9731                    );
9732                }
9733            }
9734        }
9735    }
9736
9737    /// SLICE-LEVEL DELEGATION pin (count ↔ has ↔ find) — the two
9738    /// composition laws
9739    /// `has_kind(k) == (count_kind(k) > 0)` and
9740    /// `find_kind(k).is_some() == (count_kind(k) > 0)`
9741    /// hold at every (populated, populated, query) triple on
9742    /// `ConditionKind::ALL`. Sweeps both refinement bridges at ONE
9743    /// site so a regression at the count primitive that drifted from
9744    /// the presence bit or the first-match probe surfaces HERE.
9745    #[test]
9746    fn condition_slice_has_and_find_equal_count_greater_than_zero() {
9747        for pre_kind in ConditionKind::ALL {
9748            for post_kind in ConditionKind::ALL {
9749                let slice = [condition_with(pre_kind), condition_with(post_kind)];
9750                for query in ConditionKind::ALL {
9751                    let count = slice.count_kind(query);
9752                    assert_eq!(
9753                        slice.has_kind(query),
9754                        count > 0,
9755                        "has/count bridge drifted: pre={pre_kind:?} \
9756                         post={post_kind:?} query={query:?}",
9757                    );
9758                    assert_eq!(
9759                        slice.find_kind(query).is_some(),
9760                        count > 0,
9761                        "find/count bridge drifted: pre={pre_kind:?} \
9762                         post={post_kind:?} query={query:?}",
9763                    );
9764                }
9765            }
9766        }
9767    }
9768
9769    /// SUBSTRATE-DELEGATION pin (Boundary count-triad) — the three
9770    /// widened `count_*_kind` methods on [`Boundary`] delegate
9771    /// verbatim to [`ConditionSliceExt::count_kind`] on the
9772    /// underlying [`Vec<Condition>`] slices. The
9773    /// `count_condition_kind` union SUMS preconditions and
9774    /// postconditions (distinct from the `iter_condition_kind`
9775    /// [`Chain`](std::iter::Chain), `find_condition_kind`
9776    /// [`Option::or_else`], and `has_condition_kind` `||`
9777    /// compositions on the same axis). Sweep `ConditionKind::ALL ×
9778    /// ConditionKind::ALL × ConditionKind::ALL` so a regression that
9779    /// (a) inlined a divergent count at either half-slice arm, (b)
9780    /// subtracted rather than summed, or (c) collapsed the sum to
9781    /// [`std::cmp::max`] (silently narrowing the union to a max-per-
9782    /// side probe) surfaces HERE at the substrate boundary.
9783    #[test]
9784    fn boundary_count_condition_kind_triad_delegates_and_sums_slice_count_kind() {
9785        for pre_kind in ConditionKind::ALL {
9786            for post_kind in ConditionKind::ALL {
9787                let mut b = Boundary::default();
9788                b.preconditions.push(condition_with(pre_kind));
9789                b.postconditions.push(condition_with(post_kind));
9790                for query in ConditionKind::ALL {
9791                    let via_pre = b.preconditions.count_kind(query);
9792                    let via_post = b.postconditions.count_kind(query);
9793                    assert_eq!(
9794                        b.count_precondition_kind(query),
9795                        via_pre,
9796                        "boundary precondition count arm must delegate: \
9797                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9798                    );
9799                    assert_eq!(
9800                        b.count_postcondition_kind(query),
9801                        via_post,
9802                        "boundary postcondition count arm must delegate: \
9803                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9804                    );
9805                    assert_eq!(
9806                        b.count_condition_kind(query),
9807                        via_pre + via_post,
9808                        "boundary union count arm must SUM pre + post: \
9809                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9810                    );
9811                }
9812            }
9813        }
9814    }
9815
9816    /// STRUCT-LEVEL DELEGATION pin (count ↔ iter on Boundary) — the
9817    /// three [`Boundary`] `count_*_kind` arms equal their widened
9818    /// peers' `.count()` projection at EVERY (pre-populated, post-
9819    /// populated, query) triple on `ConditionKind::ALL`. Re-anchors
9820    /// the composition-law pin
9821    /// `count_condition_kind == iter_condition_kind.count()` through
9822    /// the cardinality axis on the parent surface — a future consumer
9823    /// that reads `count_condition_kind(k)` as sugar for
9824    /// `iter_condition_kind(k).count()` stays typed against the SAME
9825    /// truth table on both the slice-level and struct-level layers.
9826    /// Also pins the sum-composition round-trip through the widened
9827    /// stream: the union arm's SUM equals the chained stream's count.
9828    #[test]
9829    fn boundary_count_triad_equals_iter_triad_count_projection() {
9830        for pre_kind in ConditionKind::ALL {
9831            for post_kind in ConditionKind::ALL {
9832                let mut b = Boundary::default();
9833                b.preconditions.push(condition_with(pre_kind));
9834                b.preconditions.push(condition_with(pre_kind));
9835                b.postconditions.push(condition_with(post_kind));
9836                for query in ConditionKind::ALL {
9837                    assert_eq!(
9838                        b.count_precondition_kind(query),
9839                        b.iter_precondition_kind(query).count(),
9840                        "precondition count/iter bridge drifted: \
9841                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9842                    );
9843                    assert_eq!(
9844                        b.count_postcondition_kind(query),
9845                        b.iter_postcondition_kind(query).count(),
9846                        "postcondition count/iter bridge drifted: \
9847                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9848                    );
9849                    assert_eq!(
9850                        b.count_condition_kind(query),
9851                        b.iter_condition_kind(query).count(),
9852                        "union count/iter bridge drifted: \
9853                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
9854                    );
9855                }
9856            }
9857        }
9858    }
9859
9860    // ── ConditionSliceExt::distinct_kinds — closed-set-inversion axis ──
9861    //
9862    // The fifth refinement on the slice-level presence-probe algebra
9863    // inverts the axis: the four point-probe refinements (has, find,
9864    // iter, count) fix a [`ConditionKind`] and vary the return type;
9865    // `distinct_kinds` fixes the slice and varies over
9866    // [`ConditionKind::ALL`], returning the SET of present kinds
9867    // projected in [`ConditionKind::ALL`] order with no duplicates.
9868    // The composition-law arms in `assert_slice_refinement_composition_laws`
9869    // pin the fifth refinement against `has_kind` per variant AND
9870    // against the canonical ALL-order equality; the four dedicated
9871    // behavior tests below pin the returned VALUE per authored
9872    // arrangement (empty, single-element populated, dual-populated,
9873    // duplicate-populated).
9874
9875    /// EMPTY-SLICE pin — an empty slice returns an empty `Vec` on
9876    /// `distinct_kinds`, distinct from every populated arrangement.
9877    /// Locks the zero-element identity so a regression that (a)
9878    /// returned `ConditionKind::ALL.to_vec()` (the wrong direction of
9879    /// the closed-set walk), (b) returned a placeholder `[ProcessPhase]`
9880    /// vec (a copy-paste of the first-variant default in a `impl
9881    /// Default` for a hypothetical `KindSet` wrapper) surfaces HERE.
9882    #[test]
9883    fn condition_slice_distinct_kinds_returns_empty_vec_on_empty_slice() {
9884        let empty: &[Condition] = &[];
9885        assert_eq!(
9886            empty.distinct_kinds(),
9887            Vec::<ConditionKind>::new(),
9888            "empty slice must return empty distinct-kinds vec",
9889        );
9890    }
9891
9892    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
9893    /// the addressed kind returns `[kind]` — a single-element vec
9894    /// containing exactly that kind. Sweep `ConditionKind::ALL` so a
9895    /// new variant added without a matching arm in the closed-set walk
9896    /// surfaces at rustc's exhaustiveness gate on the ALL literal
9897    /// (arity forced by `[Self; 8]`) rather than as a silent false-
9898    /// negative at every downstream `distinct_condition_kinds`
9899    /// callsite. Locks the closed-set-inversion probe body against a
9900    /// regression that (a) always returned `[ProcessPhase]` regardless
9901    /// of the actual kind, (b) collapsed `distinct_kinds` to
9902    /// `iter_kind(<first ALL variant>).map(|c| c.kind).collect()`
9903    /// (silently filtering to only ProcessPhase matches).
9904    #[test]
9905    fn condition_slice_distinct_kinds_returns_single_element_vec_per_variant() {
9906        for populated in ConditionKind::ALL {
9907            let slice = [condition_with(populated)];
9908            assert_eq!(
9909                slice.distinct_kinds(),
9910                vec![populated],
9911                "single-populated slice must return exactly [{populated:?}] on distinct_kinds",
9912            );
9913        }
9914    }
9915
9916    /// DEDUP pin — a slice with the SAME kind at multiple positions
9917    /// (three interleaved with distinct kinds) returns a distinct-set
9918    /// containing that kind exactly ONCE. The closed-set-inversion
9919    /// projection collapses multiplicity — a caller that needs the
9920    /// per-kind cardinality reaches for `count_kind`; this refinement
9921    /// returns the PRESENCE set. A regression that (a) omitted the
9922    /// dedup and returned `[ClosedLoopAuth, PromQL, ClosedLoopAuth,
9923    /// PromQL, ClosedLoopAuth]` (byte-identical to
9924    /// `slice.iter().map(|c| c.kind).collect()` — the wrong closed-
9925    /// set walk direction), (b) counted every duplicate as a distinct
9926    /// entry via a `.collect::<HashSet<_>>()` without canonicalizing
9927    /// order surfaces HERE.
9928    #[test]
9929    fn condition_slice_distinct_kinds_deduplicates_and_yields_canonical_all_order() {
9930        let interleaved = [
9931            Condition {
9932                kind: ConditionKind::ClosedLoopAuth,
9933                params: json!({ "probeImage": "first" }),
9934            },
9935            Condition {
9936                kind: ConditionKind::PromQL,
9937                params: json!({ "query": "up" }),
9938            },
9939            Condition {
9940                kind: ConditionKind::ClosedLoopAuth,
9941                params: json!({ "probeImage": "second" }),
9942            },
9943            Condition {
9944                kind: ConditionKind::PromQL,
9945                params: json!({ "query": "healthy" }),
9946            },
9947            Condition {
9948                kind: ConditionKind::ClosedLoopAuth,
9949                params: json!({ "probeImage": "third" }),
9950            },
9951        ];
9952        // Canonical ConditionKind::ALL order: PromQL is at position 3,
9953        // ClosedLoopAuth at position 7 in the ALL array. So PromQL comes
9954        // FIRST in the distinct-set even though ClosedLoopAuth appears
9955        // FIRST in the slice — the closed-set-inversion walk is
9956        // ordered by ConditionKind::ALL, not by slice-encounter order.
9957        assert_eq!(
9958            interleaved.distinct_kinds(),
9959            vec![ConditionKind::PromQL, ConditionKind::ClosedLoopAuth],
9960            "interleaved-duplicate slice must dedup AND order by ConditionKind::ALL, not by slice-encounter order",
9961        );
9962    }
9963
9964    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
9965    /// variant returns `ConditionKind::ALL.to_vec()` on `distinct_kinds`.
9966    /// The closed-set-inversion probe covers the full closed set at ONE
9967    /// call site — a regression that missed one variant in the walk
9968    /// (skipping the FIRST or LAST `ALL` entry via a `[1..]` or
9969    /// `[..ALL.len() - 1]` slice bug in the closed-set walk) surfaces
9970    /// HERE.
9971    #[test]
9972    fn condition_slice_distinct_kinds_covers_full_closed_set_on_saturated_slice() {
9973        let saturated: Vec<Condition> =
9974            ConditionKind::ALL.into_iter().map(condition_with).collect();
9975        assert_eq!(
9976            saturated.as_slice().distinct_kinds(),
9977            ConditionKind::ALL.to_vec(),
9978            "slice containing every ConditionKind must return ConditionKind::ALL as its distinct-set",
9979        );
9980    }
9981
9982    // ── distinct_kind_count — slice-level scalar-cardinality pins ──────
9983    //
9984    // The trait-level scalar-cardinality projection of the closed-set-
9985    // inversion widened primitive: `distinct_kind_count()` collapses
9986    // `distinct_kinds()` to its cardinality without materializing the
9987    // intermediate `Vec<ConditionKind>`. Composition law
9988    // `distinct_kind_count() == distinct_kinds().len()` pinned as the
9989    // sixth arm of the substrate testkit primitive
9990    // [`assert_slice_refinement_composition_laws`].
9991
9992    /// ZERO-ELEMENT pin — an empty slice returns `0` on
9993    /// `distinct_kind_count`, byte-for-byte with `distinct_kinds().len()`
9994    /// on the same slice. Locks the zero-element identity so a
9995    /// regression that (a) returned `ConditionKind::ALL.len()` (the
9996    /// wrong direction of the closed-set walk — every kind counted
9997    /// regardless of presence), (b) returned a placeholder `1` (a
9998    /// copy-paste of a single-slot factory's cardinality), or (c) drifted
9999    /// off `distinct_kinds().len()` surfaces HERE.
10000    #[test]
10001    fn condition_slice_distinct_kind_count_returns_zero_on_empty_slice() {
10002        let empty: &[Condition] = &[];
10003        assert_eq!(
10004            empty.distinct_kind_count(),
10005            0,
10006            "empty slice must return 0 on distinct_kind_count",
10007        );
10008        assert_eq!(
10009            empty.distinct_kind_count(),
10010            empty.distinct_kinds().len(),
10011            "empty slice distinct_kind_count must equal distinct_kinds().len()",
10012        );
10013    }
10014
10015    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
10016    /// the addressed kind returns `1` on `distinct_kind_count` — the
10017    /// single-slot diagonal cardinality. Sweep [`ConditionKind::ALL`]
10018    /// so a regression that (a) always returned `0` regardless of the
10019    /// actual kind, (b) always returned `ConditionKind::ALL.len()`
10020    /// (missed the `filter` step), or (c) collapsed the walk to a
10021    /// single fixed variant surfaces HERE.
10022    #[test]
10023    fn condition_slice_distinct_kind_count_returns_one_per_variant() {
10024        for populated in ConditionKind::ALL {
10025            let slice = [condition_with(populated)];
10026            assert_eq!(
10027                slice.distinct_kind_count(),
10028                1,
10029                "single-populated slice must return 1 on distinct_kind_count for {populated:?}",
10030            );
10031            assert_eq!(
10032                slice.distinct_kind_count(),
10033                slice.distinct_kinds().len(),
10034                "single-populated distinct_kind_count must equal distinct_kinds().len() for {populated:?}",
10035            );
10036        }
10037    }
10038
10039    /// DEDUP pin — a slice with the SAME kind at multiple positions
10040    /// (three interleaved with distinct kinds — two `PromQL`, three
10041    /// `ClosedLoopAuth`) returns `2` on `distinct_kind_count` (the
10042    /// scalar cardinality of the DISTINCT presence set, byte-for-byte
10043    /// with `distinct_kinds().len()` on the same slice). Locks the
10044    /// closed-set projection against a regression that (a) counted
10045    /// every occurrence (returning `5` — byte-identical to
10046    /// `slice.len()`), (b) omitted the dedup and returned `5` via
10047    /// `.iter().map(|c| c.kind).count()`.
10048    #[test]
10049    fn condition_slice_distinct_kind_count_dedups_across_duplicates() {
10050        let interleaved = [
10051            Condition {
10052                kind: ConditionKind::ClosedLoopAuth,
10053                params: json!({ "probeImage": "first" }),
10054            },
10055            Condition {
10056                kind: ConditionKind::PromQL,
10057                params: json!({ "query": "up" }),
10058            },
10059            Condition {
10060                kind: ConditionKind::ClosedLoopAuth,
10061                params: json!({ "probeImage": "second" }),
10062            },
10063            Condition {
10064                kind: ConditionKind::PromQL,
10065                params: json!({ "query": "healthy" }),
10066            },
10067            Condition {
10068                kind: ConditionKind::ClosedLoopAuth,
10069                params: json!({ "probeImage": "third" }),
10070            },
10071        ];
10072        assert_eq!(
10073            interleaved.distinct_kind_count(),
10074            2,
10075            "interleaved-duplicate slice must return 2 on distinct_kind_count (PromQL + ClosedLoopAuth)",
10076        );
10077        assert_eq!(
10078            interleaved.distinct_kind_count(),
10079            interleaved.distinct_kinds().len(),
10080            "interleaved-duplicate distinct_kind_count must equal distinct_kinds().len()",
10081        );
10082    }
10083
10084    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
10085    /// variant returns `ConditionKind::ALL.len()` on `distinct_kind_count`.
10086    /// The scalar cardinality projection covers the full closed set at
10087    /// ONE call site — a regression that missed one variant in the walk
10088    /// (skipping the FIRST or LAST `ALL` entry via a `[1..]` or
10089    /// `[..ALL.len() - 1]` slice bug in the closed-set walk) surfaces
10090    /// HERE.
10091    #[test]
10092    fn condition_slice_distinct_kind_count_covers_full_closed_set_on_saturated_slice() {
10093        let saturated: Vec<Condition> =
10094            ConditionKind::ALL.into_iter().map(condition_with).collect();
10095        assert_eq!(
10096            saturated.as_slice().distinct_kind_count(),
10097            ConditionKind::ALL.len(),
10098            "slice containing every ConditionKind must return ConditionKind::ALL.len() on distinct_kind_count",
10099        );
10100        assert_eq!(
10101            saturated.as_slice().distinct_kind_count(),
10102            saturated.as_slice().distinct_kinds().len(),
10103            "saturated distinct_kind_count must equal distinct_kinds().len()",
10104        );
10105    }
10106
10107    // ── ConditionSliceExt::missing_kinds — closed-set-complement axis ──
10108    //
10109    // The complement peer of `distinct_kinds` on the closed-set-
10110    // inversion axis: `missing_kinds` returns the SET of kinds that
10111    // do NOT appear in the slice, in canonical [`ConditionKind::ALL`]
10112    // order. The four tests below pin each authored arrangement's
10113    // returned VALUE (empty, single-populated, saturated, interleaved-
10114    // duplicate); the composition-law arms in
10115    // `assert_slice_refinement_composition_laws` pin the closed-set-
10116    // partition invariants against `distinct_kinds` and `has_kind`.
10117
10118    /// EMPTY-SLICE pin — an empty slice returns
10119    /// `ConditionKind::ALL.to_vec()` on `missing_kinds` (every kind is
10120    /// missing). Locks the maximum-cardinality identity on the
10121    /// complement side, byte-for-byte dual to the empty-slice arm of
10122    /// `distinct_kinds` (which returns an empty vec). A regression that
10123    /// returned an empty vec (forgot the negation) or a placeholder
10124    /// `[ProcessPhase]` (a copy-paste of the first-variant default)
10125    /// surfaces HERE.
10126    #[test]
10127    fn condition_slice_missing_kinds_returns_full_closed_set_on_empty_slice() {
10128        let empty: &[Condition] = &[];
10129        assert_eq!(
10130            empty.missing_kinds(),
10131            ConditionKind::ALL.to_vec(),
10132            "empty slice must return ConditionKind::ALL on missing_kinds (every kind is missing)",
10133        );
10134    }
10135
10136    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
10137    /// the addressed kind returns `ConditionKind::ALL` MINUS that kind
10138    /// on `missing_kinds`. Sweep [`ConditionKind::ALL`] so a regression
10139    /// that (a) returned an empty vec regardless of the kind, (b)
10140    /// returned the full ALL vec (forgot to filter), or (c) inverted
10141    /// the negation and returned only the addressed kind surfaces HERE.
10142    #[test]
10143    fn condition_slice_missing_kinds_returns_all_minus_populated_kind() {
10144        for populated in ConditionKind::ALL {
10145            let slice = [condition_with(populated)];
10146            let expected: Vec<_> = ConditionKind::ALL
10147                .into_iter()
10148                .filter(|k| *k != populated)
10149                .collect();
10150            assert_eq!(
10151                slice.missing_kinds(),
10152                expected,
10153                "single-populated slice must return ConditionKind::ALL minus {populated:?} on missing_kinds",
10154            );
10155        }
10156    }
10157
10158    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
10159    /// variant returns an empty vec on `missing_kinds` (no kind is
10160    /// missing). Dual of the empty-slice arm above; a regression that
10161    /// returned the full ALL vec regardless of population or inverted
10162    /// the presence direction surfaces HERE.
10163    #[test]
10164    fn condition_slice_missing_kinds_returns_empty_vec_on_saturated_slice() {
10165        let saturated: Vec<Condition> =
10166            ConditionKind::ALL.into_iter().map(condition_with).collect();
10167        assert_eq!(
10168            saturated.as_slice().missing_kinds(),
10169            Vec::<ConditionKind>::new(),
10170            "slice containing every ConditionKind must return empty vec on missing_kinds",
10171        );
10172    }
10173
10174    /// DEDUP pin — a slice with the SAME kind at multiple positions
10175    /// (three ClosedLoopAuth, two PromQL, none of the other six)
10176    /// returns those SIX absent kinds on `missing_kinds`, in canonical
10177    /// [`ConditionKind::ALL`] order — multiplicity on the present side
10178    /// is irrelevant to the complement. A regression that (a) counted
10179    /// duplicates as decreasing the missing set (a `saturating_sub`
10180    /// bug in a cardinality-tracking override), (b) yielded the
10181    /// missing set in slice-encounter order (which is undefined when
10182    /// no positions carry the missing kind — a subtle failure mode
10183    /// that must yield the ALL-ordered subsequence regardless)
10184    /// surfaces HERE.
10185    #[test]
10186    fn condition_slice_missing_kinds_yields_canonical_all_order_on_duplicates() {
10187        let interleaved = [
10188            Condition {
10189                kind: ConditionKind::ClosedLoopAuth,
10190                params: json!({ "probeImage": "first" }),
10191            },
10192            Condition {
10193                kind: ConditionKind::PromQL,
10194                params: json!({ "query": "up" }),
10195            },
10196            Condition {
10197                kind: ConditionKind::ClosedLoopAuth,
10198                params: json!({ "probeImage": "second" }),
10199            },
10200            Condition {
10201                kind: ConditionKind::PromQL,
10202                params: json!({ "query": "healthy" }),
10203            },
10204            Condition {
10205                kind: ConditionKind::ClosedLoopAuth,
10206                params: json!({ "probeImage": "third" }),
10207            },
10208        ];
10209        let expected: Vec<_> = ConditionKind::ALL
10210            .into_iter()
10211            .filter(|k| *k != ConditionKind::PromQL && *k != ConditionKind::ClosedLoopAuth)
10212            .collect();
10213        assert_eq!(
10214            interleaved.missing_kinds(),
10215            expected,
10216            "interleaved-duplicate slice must return canonical ALL-ordered complement of {{PromQL, ClosedLoopAuth}}",
10217        );
10218    }
10219
10220    // ── ConditionSliceExt::missing_kind_count — scalar cardinality pins ─
10221    //
10222    // Scalar-cardinality peer of the closed-set-complement widened
10223    // primitive `missing_kinds`: `missing_kind_count()` collapses the
10224    // set to its cardinality without allocating. The composition law
10225    // `missing_kind_count() == missing_kinds().len()` is pinned as the
10226    // scalar-cardinality-complement arm of
10227    // `assert_slice_refinement_composition_laws`. The three tests below
10228    // pin each authored arrangement's returned VALUE (empty, single-
10229    // populated, saturated) directly against `missing_kinds().len()`.
10230
10231    /// EMPTY-SLICE pin — an empty slice returns
10232    /// `ConditionKind::ALL.len()` on `missing_kind_count`, byte-for-byte
10233    /// with `missing_kinds().len()`. Locks the maximum-cardinality
10234    /// identity on the complement side; dual of the empty-slice arm on
10235    /// `distinct_kind_count` which returns `0`. A regression that
10236    /// forgot the negation, returned `0` (the distinct-kind-count
10237    /// identity on empty), or returned the wrong constant surfaces
10238    /// HERE.
10239    #[test]
10240    fn condition_slice_missing_kind_count_returns_full_closed_set_on_empty_slice() {
10241        let empty: &[Condition] = &[];
10242        assert_eq!(
10243            empty.missing_kind_count(),
10244            ConditionKind::ALL.len(),
10245            "empty slice must return ConditionKind::ALL.len() on missing_kind_count",
10246        );
10247        assert_eq!(
10248            empty.missing_kind_count(),
10249            empty.missing_kinds().len(),
10250            "empty slice missing_kind_count must equal missing_kinds().len()",
10251        );
10252    }
10253
10254    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
10255    /// the addressed kind returns `ConditionKind::ALL.len() - 1` on
10256    /// `missing_kind_count` (every OTHER kind is missing). Sweep
10257    /// [`ConditionKind::ALL`] so a regression that returned `0` (forgot
10258    /// to negate), `ConditionKind::ALL.len()` (forgot the populated
10259    /// kind), or a per-kind constant surfaces HERE.
10260    #[test]
10261    fn condition_slice_missing_kind_count_returns_all_minus_one_per_variant() {
10262        for populated in ConditionKind::ALL {
10263            let slice = [condition_with(populated)];
10264            assert_eq!(
10265                slice.missing_kind_count(),
10266                ConditionKind::ALL.len() - 1,
10267                "single-populated slice must return ConditionKind::ALL.len() - 1 on missing_kind_count for {populated:?}",
10268            );
10269            assert_eq!(
10270                slice.missing_kind_count(),
10271                slice.missing_kinds().len(),
10272                "single-populated missing_kind_count must equal missing_kinds().len() for {populated:?}",
10273            );
10274        }
10275    }
10276
10277    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
10278    /// variant returns `0` on `missing_kind_count` (no kind is missing).
10279    /// Dual of the empty-slice arm above; a regression that returned
10280    /// `ConditionKind::ALL.len()` regardless of population or inverted
10281    /// the presence direction surfaces HERE.
10282    #[test]
10283    fn condition_slice_missing_kind_count_returns_zero_on_saturated_slice() {
10284        let saturated: Vec<Condition> =
10285            ConditionKind::ALL.into_iter().map(condition_with).collect();
10286        assert_eq!(
10287            saturated.as_slice().missing_kind_count(),
10288            0,
10289            "slice containing every ConditionKind must return 0 on missing_kind_count",
10290        );
10291        assert_eq!(
10292            saturated.as_slice().missing_kind_count(),
10293            saturated.as_slice().missing_kinds().len(),
10294            "saturated missing_kind_count must equal missing_kinds().len()",
10295        );
10296    }
10297
10298    // ── ConditionSliceExt::is_kind_saturated — Boolean saturation pins ─
10299    //
10300    // Short-circuiting Boolean saturation-endpoint peer of the closed-set-
10301    // complement widened + scalar primitives: `is_kind_saturated()`
10302    // returns `true` iff every ConditionKind::ALL variant appears at
10303    // least once in the slice, WITHOUT allocating `missing_kinds` or
10304    // walking every entry to build `missing_kind_count`. The composition
10305    // laws `is_kind_saturated() == (missing_kind_count() == 0)` and
10306    // `is_kind_saturated() == missing_kinds().is_empty()` are pinned as
10307    // the saturation-endpoint arm of
10308    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer of
10309    // `crate::tagged_union::TaggedUnion::is_saturated` one struct-layer
10310    // up under the SAME `<CLOSED_SET>::ALL.iter().all(has)` short-
10311    // circuit walk shape.
10312
10313    /// EMPTY-SLICE pin — an empty slice returns `false` on
10314    /// `is_kind_saturated` (every kind is missing).
10315    #[test]
10316    fn condition_slice_is_kind_saturated_returns_false_on_empty_slice() {
10317        let empty: &[Condition] = &[];
10318        assert!(
10319            !empty.is_kind_saturated(),
10320            "empty slice must return false on is_kind_saturated",
10321        );
10322        assert_eq!(
10323            empty.is_kind_saturated(),
10324            empty.missing_kind_count() == 0,
10325            "empty is_kind_saturated must equal (missing_kind_count() == 0)",
10326        );
10327    }
10328
10329    /// SINGLE-KIND pin — a slice populating exactly one variant returns
10330    /// `false` on any [`ConditionKind::ALL`] closed set with `N ≥ 2`
10331    /// (the other `N - 1` variants are missing).
10332    #[test]
10333    fn condition_slice_is_kind_saturated_returns_false_on_single_kind_slice() {
10334        assert!(
10335            ConditionKind::ALL.len() >= 2,
10336            "test assumes ConditionKind::ALL has ≥ 2 variants",
10337        );
10338        for populated in ConditionKind::ALL {
10339            let slice = [condition_with(populated)];
10340            assert!(
10341                !slice.is_kind_saturated(),
10342                "single-populated slice with {populated:?} must return false on is_kind_saturated",
10343            );
10344            assert_eq!(
10345                slice.is_kind_saturated(),
10346                slice.missing_kind_count() == 0,
10347                "single-populated is_kind_saturated must equal (missing_kind_count() == 0) for {populated:?}",
10348            );
10349        }
10350    }
10351
10352    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
10353    /// variant returns `true` on `is_kind_saturated` — the SOLE arm
10354    /// where the primitive returns `true`.
10355    #[test]
10356    fn condition_slice_is_kind_saturated_returns_true_on_saturated_slice() {
10357        let saturated: Vec<Condition> =
10358            ConditionKind::ALL.into_iter().map(condition_with).collect();
10359        assert!(
10360            saturated.as_slice().is_kind_saturated(),
10361            "slice containing every ConditionKind must return true on is_kind_saturated",
10362        );
10363        assert_eq!(
10364            saturated.as_slice().is_kind_saturated(),
10365            saturated.as_slice().missing_kind_count() == 0,
10366            "saturated is_kind_saturated must equal (missing_kind_count() == 0)",
10367        );
10368        assert_eq!(
10369            saturated.as_slice().is_kind_saturated(),
10370            saturated.as_slice().missing_kinds().is_empty(),
10371            "saturated is_kind_saturated must equal missing_kinds().is_empty()",
10372        );
10373    }
10374
10375    /// DUPLICATE-COVERAGE pin — a slice that carries every
10376    /// [`ConditionKind`] variant multiple times still returns `true`
10377    /// (multiplicity is irrelevant to the saturation predicate on the
10378    /// closed-set-inversion axis).
10379    #[test]
10380    fn condition_slice_is_kind_saturated_ignores_multiplicity() {
10381        let mut doubled: Vec<Condition> = Vec::new();
10382        for k in ConditionKind::ALL {
10383            doubled.push(condition_with(k));
10384            doubled.push(condition_with(k));
10385        }
10386        assert!(
10387            doubled.as_slice().is_kind_saturated(),
10388            "slice carrying every ConditionKind twice must return true on is_kind_saturated",
10389        );
10390    }
10391
10392    // ── ConditionSliceExt::has_any_distinct_kind — at-least-one halfspace pins ──
10393    //
10394    // Boolean at-least-one halfspace peer of `has_any_missing_kind` on
10395    // the closed-set-inversion axis: `has_any_distinct_kind()` returns
10396    // `true` iff AT LEAST ONE `ConditionKind::ALL` variant appears at
10397    // least once in the slice, via a SHORT-CIRCUITING closed-set walk
10398    // `ConditionKind::ALL.iter().copied().any(|k| self.has_kind(k))`
10399    // that returns `true` at the FIRST populated kind. The composition
10400    // laws `has_any_distinct_kind() == (distinct_kind_count() > 0)`,
10401    // `has_any_distinct_kind() == !distinct_kinds().is_empty()`, and
10402    // `has_any_distinct_kind() == first_distinct_kind().is_some()` are
10403    // pinned as the at-least-one halfspace arm of
10404    // `assert_slice_refinement_composition_laws` on the closed-set-
10405    // inversion axis. Byte-for-byte peer of
10406    // `crate::tagged_union::TaggedUnion::has_any_populated_kind` one
10407    // struct-layer up under the SAME `any(has)` short-circuit shape.
10408
10409    /// EMPTY-SLICE pin — an empty slice returns `false` on
10410    /// `has_any_distinct_kind` (no kind is present) — the SOLE arm
10411    /// where the primitive returns `false`. Dual of the empty-slice
10412    /// arm on `has_any_missing_kind` (which returns `true`).
10413    #[test]
10414    fn condition_slice_has_any_distinct_kind_returns_false_on_empty_slice() {
10415        let empty: &[Condition] = &[];
10416        assert!(
10417            !empty.has_any_distinct_kind(),
10418            "empty slice must return false on has_any_distinct_kind",
10419        );
10420        assert_eq!(
10421            empty.has_any_distinct_kind(),
10422            empty.distinct_kind_count() > 0,
10423            "empty has_any_distinct_kind must equal (distinct_kind_count() > 0)",
10424        );
10425        assert_eq!(
10426            empty.has_any_distinct_kind(),
10427            !empty.distinct_kinds().is_empty(),
10428            "empty has_any_distinct_kind must equal !distinct_kinds().is_empty()",
10429        );
10430        assert_eq!(
10431            empty.has_any_distinct_kind(),
10432            empty.first_distinct_kind().is_some(),
10433            "empty has_any_distinct_kind must equal first_distinct_kind().is_some()",
10434        );
10435    }
10436
10437    /// SINGLE-KIND pin — a slice populating exactly one variant
10438    /// returns `true` on `has_any_distinct_kind` for every
10439    /// [`ConditionKind`] (a single element contributes one distinct
10440    /// kind, ≥ 1). Also pins the composition law
10441    /// `has_any_distinct_kind() == (distinct_kind_count() > 0)` at
10442    /// the single-populated arm.
10443    #[test]
10444    fn condition_slice_has_any_distinct_kind_returns_true_on_single_kind_slice() {
10445        for populated in ConditionKind::ALL {
10446            let slice = [condition_with(populated)];
10447            assert!(
10448                slice.has_any_distinct_kind(),
10449                "single-populated slice with {populated:?} must return true on has_any_distinct_kind",
10450            );
10451            assert_eq!(
10452                slice.has_any_distinct_kind(),
10453                slice.distinct_kind_count() > 0,
10454                "single-populated has_any_distinct_kind must equal (distinct_kind_count() > 0) for {populated:?}",
10455            );
10456        }
10457    }
10458
10459    /// FULL-COVERAGE pin — a slice that carries every
10460    /// [`ConditionKind`] variant returns `true` on
10461    /// `has_any_distinct_kind`. Dual of the FULL-COVERAGE arm on
10462    /// `has_any_missing_kind` (which returns `false`) — the two
10463    /// Booleans DISAGREE on the saturated arm.
10464    #[test]
10465    fn condition_slice_has_any_distinct_kind_returns_true_on_saturated_slice() {
10466        let saturated: Vec<Condition> =
10467            ConditionKind::ALL.into_iter().map(condition_with).collect();
10468        assert!(
10469            saturated.as_slice().has_any_distinct_kind(),
10470            "slice containing every ConditionKind must return true on has_any_distinct_kind",
10471        );
10472        assert_eq!(
10473            saturated.as_slice().has_any_distinct_kind(),
10474            !saturated.as_slice().distinct_kinds().is_empty(),
10475            "saturated has_any_distinct_kind must equal !distinct_kinds().is_empty()",
10476        );
10477    }
10478
10479    /// DUPLICATE-COVERAGE pin — a slice that carries the SAME
10480    /// [`ConditionKind`] multiple times still returns `true`
10481    /// (multiplicity is irrelevant to the at-least-one halfspace
10482    /// predicate on the closed-set-inversion axis, byte-for-byte peer
10483    /// of the closed-set-complement halfspace arm).
10484    #[test]
10485    fn condition_slice_has_any_distinct_kind_ignores_multiplicity() {
10486        for k in ConditionKind::ALL {
10487            let doubled: Vec<Condition> = vec![condition_with(k), condition_with(k)];
10488            assert!(
10489                doubled.as_slice().has_any_distinct_kind(),
10490                "slice carrying {k:?} twice must return true on has_any_distinct_kind",
10491            );
10492        }
10493    }
10494
10495    // ── ConditionSliceExt::has_unique_distinct_kind — cardinality-mid-endpoint pins ──
10496    //
10497    // Boolean cardinality-mid-endpoint peer of `has_any_distinct_kind`
10498    // on the closed-set-inversion axis: returns `true` iff EXACTLY
10499    // ONE `ConditionKind::ALL` variant appears at least once in the
10500    // slice. Body folds through the load-bearing
10501    // `iter_distinct_kinds` iterator under a two-step short-circuit;
10502    // strictly cheaper than `distinct_kind_count() == 1` (which walks
10503    // every slot) and `distinct_kinds().len() == 1` (which allocates
10504    // the Vec) on every arm with ≥ 2 distinct kinds. The composition
10505    // laws `has_unique_distinct_kind() == (distinct_kind_count() == 1)`
10506    // and `has_unique_distinct_kind() == (distinct_kinds().len() == 1)`
10507    // are pinned as the cardinality-mid-endpoint arm of
10508    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
10509    // of `crate::tagged_union::TaggedUnion::has_unique_populated_kind`
10510    // one struct-layer up under the SAME two-step short-circuit walk
10511    // shape.
10512
10513    /// EMPTY-SLICE pin — an empty slice returns `false` on
10514    /// `has_unique_distinct_kind` (zero distinct, not exactly 1).
10515    /// Also pins the composition law `has_unique_distinct_kind() ==
10516    /// (distinct_kind_count() == 1)` at zero-distinct.
10517    #[test]
10518    fn condition_slice_has_unique_distinct_kind_returns_false_on_empty_slice() {
10519        let empty: &[Condition] = &[];
10520        assert!(
10521            !empty.has_unique_distinct_kind(),
10522            "empty slice must return false on has_unique_distinct_kind (0 distinct, not exactly 1)",
10523        );
10524        assert_eq!(
10525            empty.has_unique_distinct_kind(),
10526            empty.distinct_kind_count() == 1,
10527            "empty has_unique_distinct_kind must equal (distinct_kind_count() == 1)",
10528        );
10529    }
10530
10531    /// SINGLE-KIND pin — a slice populating exactly one variant
10532    /// returns `true` on `has_unique_distinct_kind` for every
10533    /// [`ConditionKind`] — the SOLE arrangement where the primitive
10534    /// returns `true` on any `N ≥ 2` closed set (the singleton-
10535    /// coverage arm). Also pins the widened composition law
10536    /// `has_unique_distinct_kind() == (distinct_kinds().len() == 1)`.
10537    #[test]
10538    fn condition_slice_has_unique_distinct_kind_returns_true_on_single_kind_slice() {
10539        for populated in ConditionKind::ALL {
10540            let slice = [condition_with(populated)];
10541            assert!(
10542                slice.has_unique_distinct_kind(),
10543                "single-populated slice with {populated:?} must return true on has_unique_distinct_kind",
10544            );
10545            assert_eq!(
10546                slice.has_unique_distinct_kind(),
10547                slice.distinct_kind_count() == 1,
10548                "single-populated has_unique_distinct_kind must equal (distinct_kind_count() == 1) for {populated:?}",
10549            );
10550            assert_eq!(
10551                slice.has_unique_distinct_kind(),
10552                slice.distinct_kinds().len() == 1,
10553                "single-populated has_unique_distinct_kind must equal (distinct_kinds().len() == 1) for {populated:?}",
10554            );
10555            assert_eq!(
10556                slice.first_distinct_kind(),
10557                Some(populated),
10558                "single-populated first_distinct_kind must name the SOLE covered kind for {populated:?}",
10559            );
10560        }
10561    }
10562
10563    /// SATURATED pin — a slice carrying every [`ConditionKind`]
10564    /// returns `false` on `has_unique_distinct_kind` on any `N ≥ 2`
10565    /// closed set (`N` distinct, not exactly 1). Dual of the
10566    /// SATURATED arm on `has_any_distinct_kind` which returns `true`
10567    /// — the two Booleans DISAGREE on the saturated arm.
10568    #[test]
10569    fn condition_slice_has_unique_distinct_kind_returns_false_on_saturated_slice() {
10570        assert!(
10571            ConditionKind::ALL.len() >= 2,
10572            "test assumes ConditionKind::ALL has ≥ 2 variants",
10573        );
10574        let saturated: Vec<Condition> =
10575            ConditionKind::ALL.into_iter().map(condition_with).collect();
10576        assert!(
10577            !saturated.as_slice().has_unique_distinct_kind(),
10578            "saturated slice must return false on has_unique_distinct_kind ({} distinct, not exactly 1)",
10579            ConditionKind::ALL.len(),
10580        );
10581        assert_eq!(
10582            saturated.as_slice().has_unique_distinct_kind(),
10583            saturated.as_slice().distinct_kind_count() == 1,
10584            "saturated has_unique_distinct_kind must equal (distinct_kind_count() == 1)",
10585        );
10586    }
10587
10588    /// TWO-POPULATED pin — a slice carrying exactly two distinct
10589    /// [`ConditionKind`] variants returns `false` on
10590    /// `has_unique_distinct_kind` (2 distinct, not exactly 1). Pins
10591    /// the SECOND-slot short-circuit boundary — a regression that
10592    /// dropped the second-slot check (returning `true` on any
10593    /// at-least-one arm) surfaces HERE. Only meaningful on `N ≥ 2`
10594    /// closed sets.
10595    #[test]
10596    fn condition_slice_has_unique_distinct_kind_returns_false_on_two_populated_slice() {
10597        assert!(
10598            ConditionKind::ALL.len() >= 2,
10599            "test assumes ConditionKind::ALL has ≥ 2 variants",
10600        );
10601        for i in 0..ConditionKind::ALL.len() {
10602            for j in (i + 1)..ConditionKind::ALL.len() {
10603                let two_populated: Vec<Condition> = vec![
10604                    condition_with(ConditionKind::ALL[i]),
10605                    condition_with(ConditionKind::ALL[j]),
10606                ];
10607                let slice = two_populated.as_slice();
10608                assert!(
10609                    !slice.has_unique_distinct_kind(),
10610                    "two-populated slice (kinds at index {i} and {j}) must return false on has_unique_distinct_kind (2 distinct, not exactly 1)",
10611                );
10612                assert_eq!(
10613                    slice.has_unique_distinct_kind(),
10614                    slice.distinct_kind_count() == 1,
10615                    "two-populated has_unique_distinct_kind must equal (distinct_kind_count() == 1) for kinds=({i}, {j})",
10616                );
10617            }
10618        }
10619    }
10620
10621    /// MULTIPLICITY pin — a slice carrying the SAME [`ConditionKind`]
10622    /// multiple times still returns `true` (multiplicity is
10623    /// irrelevant to the cardinality-mid-endpoint projection on the
10624    /// closed-set-inversion axis — one distinct kind regardless of
10625    /// repetition count, byte-for-byte peer of the at-least-one
10626    /// halfspace arm's multiplicity pin).
10627    #[test]
10628    fn condition_slice_has_unique_distinct_kind_ignores_multiplicity() {
10629        for k in ConditionKind::ALL {
10630            let doubled: Vec<Condition> = vec![condition_with(k), condition_with(k)];
10631            assert!(
10632                doubled.as_slice().has_unique_distinct_kind(),
10633                "slice carrying {k:?} twice must return true on has_unique_distinct_kind (still 1 distinct)",
10634            );
10635            let tripled: Vec<Condition> =
10636                vec![condition_with(k), condition_with(k), condition_with(k)];
10637            assert!(
10638                tripled.as_slice().has_unique_distinct_kind(),
10639                "slice carrying {k:?} three times must return true on has_unique_distinct_kind (still 1 distinct)",
10640            );
10641        }
10642    }
10643
10644    // ── ConditionSliceExt::has_multiple_distinct_kinds — cardinality-many-arm pins ──
10645    //
10646    // Boolean cardinality many-arm peer of `has_unique_distinct_kind`
10647    // on the closed-set-inversion axis: `has_multiple_distinct_kinds()`
10648    // returns `true` iff AT LEAST TWO `ConditionKind::ALL` variants
10649    // appear at least once in the slice, byte-for-byte with a two-step-
10650    // short-circuit walk over `iter_distinct_kinds`. The composition
10651    // laws `has_multiple_distinct_kinds() == (distinct_kind_count() >= 2)`
10652    // and `has_multiple_distinct_kinds() == (distinct_kinds().len() >= 2)`
10653    // are pinned as the cardinality-many-arm arm of
10654    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer of
10655    // `crate::tagged_union::TaggedUnion::has_multiple_populated_kinds`
10656    // one struct-layer up under the SAME two-step short-circuit walk
10657    // shape.
10658
10659    /// EMPTY-SLICE pin — an empty slice returns `false` on
10660    /// `has_multiple_distinct_kinds` (0 distinct, not ≥ 2). Dual of
10661    /// the empty-slice arm on `has_multiple_missing_kinds` which
10662    /// returns `true`. Also pins the composition law
10663    /// `has_multiple_distinct_kinds() == (distinct_kind_count() >= 2)`
10664    /// at zero-distinct.
10665    #[test]
10666    fn condition_slice_has_multiple_distinct_kinds_returns_false_on_empty_slice() {
10667        let empty: &[Condition] = &[];
10668        assert!(
10669            !empty.has_multiple_distinct_kinds(),
10670            "empty slice must return false on has_multiple_distinct_kinds (0 distinct, not ≥ 2)",
10671        );
10672        assert_eq!(
10673            empty.has_multiple_distinct_kinds(),
10674            empty.distinct_kind_count() >= 2,
10675            "empty has_multiple_distinct_kinds must equal (distinct_kind_count() >= 2)",
10676        );
10677    }
10678
10679    /// SINGLE-KIND pin — a slice populating exactly one variant
10680    /// returns `false` on `has_multiple_distinct_kinds` (1 distinct,
10681    /// not ≥ 2). The SOLE-populated arrangement where the many-arm
10682    /// primitive returns `false` alongside the empty-endpoint — the
10683    /// definitional boundary between the =1 mid-endpoint and the ≥ 2
10684    /// many-arm on the distinct axis. Also pins the widened
10685    /// composition law
10686    /// `has_multiple_distinct_kinds() == (distinct_kinds().len() >= 2)`.
10687    #[test]
10688    fn condition_slice_has_multiple_distinct_kinds_returns_false_on_single_kind_slice() {
10689        for populated in ConditionKind::ALL {
10690            let slice = [condition_with(populated)];
10691            assert!(
10692                !slice.has_multiple_distinct_kinds(),
10693                "single-populated slice with {populated:?} must return false on has_multiple_distinct_kinds (1 distinct, not ≥ 2)",
10694            );
10695            assert_eq!(
10696                slice.has_multiple_distinct_kinds(),
10697                slice.distinct_kind_count() >= 2,
10698                "single-populated has_multiple_distinct_kinds must equal (distinct_kind_count() >= 2) for {populated:?}",
10699            );
10700            assert_eq!(
10701                slice.has_multiple_distinct_kinds(),
10702                slice.distinct_kinds().len() >= 2,
10703                "single-populated has_multiple_distinct_kinds must equal (distinct_kinds().len() >= 2) for {populated:?}",
10704            );
10705        }
10706    }
10707
10708    /// SATURATED pin — a slice carrying every [`ConditionKind`]
10709    /// variant returns `true` on `has_multiple_distinct_kinds` on any
10710    /// `N ≥ 2` closed set (`N` distinct, ≥ 2). Dual of the SATURATED
10711    /// arm on `has_unique_distinct_kind` which returns `false` on
10712    /// `N ≥ 2`.
10713    #[test]
10714    fn condition_slice_has_multiple_distinct_kinds_returns_true_on_saturated_slice() {
10715        assert!(
10716            ConditionKind::ALL.len() >= 2,
10717            "test assumes ConditionKind::ALL has ≥ 2 variants",
10718        );
10719        let saturated: Vec<Condition> =
10720            ConditionKind::ALL.into_iter().map(condition_with).collect();
10721        assert!(
10722            saturated.as_slice().has_multiple_distinct_kinds(),
10723            "saturated slice must return true on has_multiple_distinct_kinds ({} distinct, ≥ 2)",
10724            ConditionKind::ALL.len(),
10725        );
10726        assert_eq!(
10727            saturated.as_slice().has_multiple_distinct_kinds(),
10728            saturated.as_slice().distinct_kind_count() >= 2,
10729            "saturated has_multiple_distinct_kinds must equal (distinct_kind_count() >= 2)",
10730        );
10731    }
10732
10733    /// TWO-POPULATED pin — a slice carrying exactly two distinct
10734    /// [`ConditionKind`] variants returns `true` on
10735    /// `has_multiple_distinct_kinds` (2 distinct, ≥ 2). Pins the
10736    /// SECOND-slot boundary of the ≥ 2 arm — a regression that
10737    /// dropped the second-slot short-circuit (conflating with the
10738    /// at-least-one halfspace, returning `true` on any partial
10739    /// arrangement) would still pass here; complemented by the
10740    /// SINGLE-KIND pin which distinguishes the =1 arm from the ≥ 2
10741    /// arm. Only meaningful on `N ≥ 2` closed sets.
10742    #[test]
10743    fn condition_slice_has_multiple_distinct_kinds_returns_true_on_two_populated_slice() {
10744        assert!(
10745            ConditionKind::ALL.len() >= 2,
10746            "test assumes ConditionKind::ALL has ≥ 2 variants",
10747        );
10748        for i in 0..ConditionKind::ALL.len() {
10749            for j in (i + 1)..ConditionKind::ALL.len() {
10750                let two_populated: Vec<Condition> = vec![
10751                    condition_with(ConditionKind::ALL[i]),
10752                    condition_with(ConditionKind::ALL[j]),
10753                ];
10754                let slice = two_populated.as_slice();
10755                assert!(
10756                    slice.has_multiple_distinct_kinds(),
10757                    "two-populated slice (kinds at index {i} and {j}) must return true on has_multiple_distinct_kinds (2 distinct, ≥ 2)",
10758                );
10759                assert_eq!(
10760                    slice.has_multiple_distinct_kinds(),
10761                    slice.distinct_kind_count() >= 2,
10762                    "two-populated has_multiple_distinct_kinds must equal (distinct_kind_count() >= 2) for kinds=({i}, {j})",
10763                );
10764            }
10765        }
10766    }
10767
10768    /// MULTIPLICITY pin — a slice carrying the SAME [`ConditionKind`]
10769    /// multiple times still returns `false` on
10770    /// `has_multiple_distinct_kinds` (multiplicity is irrelevant to
10771    /// the cardinality-many-arm projection on the closed-set-inversion
10772    /// axis — one distinct kind regardless of repetition count).
10773    #[test]
10774    fn condition_slice_has_multiple_distinct_kinds_ignores_multiplicity() {
10775        for k in ConditionKind::ALL {
10776            let doubled: Vec<Condition> = vec![condition_with(k), condition_with(k)];
10777            assert!(
10778                !doubled.as_slice().has_multiple_distinct_kinds(),
10779                "slice carrying {k:?} twice must return false on has_multiple_distinct_kinds (still 1 distinct)",
10780            );
10781            let tripled: Vec<Condition> =
10782                vec![condition_with(k), condition_with(k), condition_with(k)];
10783            assert!(
10784                !tripled.as_slice().has_multiple_distinct_kinds(),
10785                "slice carrying {k:?} three times must return false on has_multiple_distinct_kinds (still 1 distinct)",
10786            );
10787        }
10788    }
10789
10790    // ── ConditionSliceExt::has_multiple_of_kind — per-kind "≥ 2" pins ─
10791    //
10792    // Boolean cardinality "≥ 2" many-arm peer of `has_kind` (≥ 1) and
10793    // `lacks_kind` (= 0) on the per-kind count axis:
10794    // `has_multiple_of_kind(k)` returns `true` iff AT LEAST TWO
10795    // `Condition` values with kind `k` appear in the slice. Composes
10796    // through a two-step short-circuit walk over `iter_kind(k)` —
10797    // byte-for-byte peer of `has_multiple_distinct_kinds` one axis
10798    // over (whole-slice distinct kinds vs per-kind matches). The
10799    // composition laws `has_multiple_of_kind(k) == (count_kind(k) >= 2)`,
10800    // `has_multiple_of_kind(k) == (iter_kind(k).count() >= 2)`, and
10801    // `has_multiple_of_kind(k) == { iter_kind(k) two-step short-circuit }`
10802    // are pinned as the per-kind many-arm of
10803    // `assert_slice_refinement_composition_laws`. Detects duplicate
10804    // conditions of a specific kind — the substrate primitive that a
10805    // future boundary-well-formedness coherence check (reject a
10806    // Process whose preconditions carry duplicate `ProcessPhase`
10807    // entries) or `has-multiple-of-<kind>` require-tag classifier
10808    // arm reaches through with no allocation.
10809
10810    /// EMPTY-SLICE pin — an empty slice returns `false` on
10811    /// `has_multiple_of_kind` for EVERY kind (0 matches, not ≥ 2).
10812    /// Also pins the composition law
10813    /// `has_multiple_of_kind(k) == (count_kind(k) >= 2)` at zero-count
10814    /// for every kind.
10815    #[test]
10816    fn condition_slice_has_multiple_of_kind_returns_false_on_empty_slice() {
10817        let empty: &[Condition] = &[];
10818        for k in ConditionKind::ALL {
10819            assert!(
10820                !empty.has_multiple_of_kind(k),
10821                "empty slice must return false on has_multiple_of_kind({k:?}) (0 matches, not ≥ 2)",
10822            );
10823            assert_eq!(
10824                empty.has_multiple_of_kind(k),
10825                empty.count_kind(k) >= 2,
10826                "empty has_multiple_of_kind({k:?}) must equal (count_kind({k:?}) >= 2)",
10827            );
10828        }
10829    }
10830
10831    /// COUNT-AXIS pin — sweeps a range of per-kind multiplicities
10832    /// (0, 1, 2, 3) and asserts the primitive equals
10833    /// `count_kind(k) >= 2` at each arm. Pins the transition from
10834    /// the =1 (single-match) arm where the primitive returns
10835    /// `false` to the =2 (duplicate) arm where it returns `true`.
10836    /// Also pins per-kind independence: multiplicity of OTHER kinds
10837    /// is irrelevant.
10838    #[test]
10839    fn condition_slice_has_multiple_of_kind_tracks_count_kind_ge_two() {
10840        for target in ConditionKind::ALL {
10841            for target_multiplicity in [0usize, 1, 2, 3] {
10842                // Build a slice with `target` repeated
10843                // `target_multiplicity` times, plus one instance of
10844                // every OTHER kind. `has_multiple_of_kind(target)`
10845                // must depend only on `target_multiplicity`.
10846                let mut slice: Vec<Condition> = Vec::new();
10847                for _ in 0..target_multiplicity {
10848                    slice.push(condition_with(target));
10849                }
10850                for other in ConditionKind::ALL {
10851                    if other != target {
10852                        slice.push(condition_with(other));
10853                    }
10854                }
10855                let s = slice.as_slice();
10856
10857                assert_eq!(
10858                    s.has_multiple_of_kind(target),
10859                    target_multiplicity >= 2,
10860                    "has_multiple_of_kind({target:?}) with multiplicity {target_multiplicity} \
10861                     must equal ({target_multiplicity} >= 2)",
10862                );
10863                assert_eq!(
10864                    s.has_multiple_of_kind(target),
10865                    s.count_kind(target) >= 2,
10866                    "has_multiple_of_kind({target:?}) drifted from (count_kind >= 2) at \
10867                     multiplicity {target_multiplicity}",
10868                );
10869                assert_eq!(
10870                    s.has_multiple_of_kind(target),
10871                    s.iter_kind(target).count() >= 2,
10872                    "has_multiple_of_kind({target:?}) drifted from (iter_kind.count() >= 2) \
10873                     at multiplicity {target_multiplicity}",
10874                );
10875
10876                // OTHER kinds appear exactly once; their many-arm
10877                // stays `false` regardless of `target`'s multiplicity.
10878                for other in ConditionKind::ALL {
10879                    if other != target {
10880                        assert!(
10881                            !s.has_multiple_of_kind(other),
10882                            "other kind {other:?} present once must return false on \
10883                             has_multiple_of_kind (target={target:?} mult={target_multiplicity})",
10884                        );
10885                    }
10886                }
10887            }
10888        }
10889    }
10890
10891    // ── ConditionSliceExt::has_unique_of_kind — per-kind "= 1" pins ─
10892    //
10893    // Boolean cardinality "= 1" mid-endpoint peer of `lacks_kind`
10894    // (= 0) and `has_multiple_of_kind` (≥ 2) on the per-kind count
10895    // axis: `has_unique_of_kind(k)` returns `true` iff EXACTLY ONE
10896    // `Condition` value with kind `k` appears in the slice. Composes
10897    // through a two-step short-circuit walk over `iter_kind(k)` —
10898    // byte-for-byte peer of `has_multiple_of_kind` under the
10899    // (= 1, ≥ 2) count-axis duality (both walk the same iterator,
10900    // differing only in the second-hit predicate: `is_none` here vs
10901    // `is_some` on the many-arm peer). Closes the {= 0, = 1, ≥ 2}
10902    // per-kind cardinality Boolean trichotomy at the slice level:
10903    // EXACTLY ONE of {lacks_kind, has_unique_of_kind,
10904    // has_multiple_of_kind} fires on any `(slice, kind)` pair, pinned
10905    // as the per-kind trichotomy partition arm of
10906    // `assert_slice_refinement_composition_laws` alongside the per-
10907    // kind mid-endpoint composition-law arms
10908    // `has_unique_of_kind(k) == (count_kind(k) == 1)`,
10909    // `has_unique_of_kind(k) == (iter_kind(k).count() == 1)`, and
10910    // `has_unique_of_kind(k) == { iter_kind(k) two-step short-circuit }`.
10911    // Detects singleton conditions of a specific kind — the substrate
10912    // primitive that a future boundary-well-formedness coherence
10913    // check (enforce a Process's preconditions carry EXACTLY ONE
10914    // `ProcessPhase` entry) or `has-unique-of-<kind>` require-tag
10915    // classifier arm reaches through with no allocation.
10916
10917    /// EMPTY-SLICE pin — an empty slice returns `false` on
10918    /// `has_unique_of_kind` for EVERY kind (0 matches, not = 1).
10919    /// Also pins the composition law
10920    /// `has_unique_of_kind(k) == (count_kind(k) == 1)` at zero-count
10921    /// for every kind.
10922    #[test]
10923    fn condition_slice_has_unique_of_kind_returns_false_on_empty_slice() {
10924        let empty: &[Condition] = &[];
10925        for k in ConditionKind::ALL {
10926            assert!(
10927                !empty.has_unique_of_kind(k),
10928                "empty slice must return false on has_unique_of_kind({k:?}) (0 matches, not = 1)",
10929            );
10930            assert_eq!(
10931                empty.has_unique_of_kind(k),
10932                empty.count_kind(k) == 1,
10933                "empty has_unique_of_kind({k:?}) must equal (count_kind({k:?}) == 1)",
10934            );
10935        }
10936    }
10937
10938    /// COUNT-AXIS pin — sweeps a range of per-kind multiplicities
10939    /// (0, 1, 2, 3) and asserts the primitive equals
10940    /// `count_kind(k) == 1` at each arm. Pins the transition from
10941    /// the =0 (empty) arm where the primitive returns `false`
10942    /// through the =1 (singleton) arm where it returns `true` back
10943    /// to the =2 (duplicate) arm where it returns `false`. Also
10944    /// pins per-kind independence: multiplicity of OTHER kinds
10945    /// (each present exactly once) leaves the mid-endpoint of every
10946    /// other kind at `true` regardless of `target`'s multiplicity.
10947    #[test]
10948    fn condition_slice_has_unique_of_kind_tracks_count_kind_eq_one() {
10949        for target in ConditionKind::ALL {
10950            for target_multiplicity in [0usize, 1, 2, 3] {
10951                // Build a slice with `target` repeated
10952                // `target_multiplicity` times, plus one instance of
10953                // every OTHER kind. `has_unique_of_kind(target)`
10954                // must depend only on `target_multiplicity`.
10955                let mut slice: Vec<Condition> = Vec::new();
10956                for _ in 0..target_multiplicity {
10957                    slice.push(condition_with(target));
10958                }
10959                for other in ConditionKind::ALL {
10960                    if other != target {
10961                        slice.push(condition_with(other));
10962                    }
10963                }
10964                let s = slice.as_slice();
10965
10966                assert_eq!(
10967                    s.has_unique_of_kind(target),
10968                    target_multiplicity == 1,
10969                    "has_unique_of_kind({target:?}) with multiplicity {target_multiplicity} \
10970                     must equal ({target_multiplicity} == 1)",
10971                );
10972                assert_eq!(
10973                    s.has_unique_of_kind(target),
10974                    s.count_kind(target) == 1,
10975                    "has_unique_of_kind({target:?}) drifted from (count_kind == 1) at \
10976                     multiplicity {target_multiplicity}",
10977                );
10978                assert_eq!(
10979                    s.has_unique_of_kind(target),
10980                    s.iter_kind(target).count() == 1,
10981                    "has_unique_of_kind({target:?}) drifted from (iter_kind.count() == 1) \
10982                     at multiplicity {target_multiplicity}",
10983                );
10984
10985                // OTHER kinds appear exactly once; their mid-endpoint
10986                // stays `true` regardless of `target`'s multiplicity.
10987                for other in ConditionKind::ALL {
10988                    if other != target {
10989                        assert!(
10990                            s.has_unique_of_kind(other),
10991                            "other kind {other:?} present once must return true on \
10992                             has_unique_of_kind (target={target:?} mult={target_multiplicity})",
10993                        );
10994                    }
10995                }
10996
10997                // Per-kind cardinality Boolean trichotomy pin —
10998                // EXACTLY ONE of {lacks_kind, has_unique_of_kind,
10999                // has_multiple_of_kind} fires on `(s, target)`. The
11000                // slice-level closure of the {=0, =1, ≥2} arms.
11001                let arms_true = [
11002                    s.lacks_kind(target),
11003                    s.has_unique_of_kind(target),
11004                    s.has_multiple_of_kind(target),
11005                ]
11006                .into_iter()
11007                .filter(|&b| b)
11008                .count();
11009                assert_eq!(
11010                    arms_true, 1,
11011                    "per-kind trichotomy for target={target:?} at mult={target_multiplicity} \
11012                     must have EXACTLY one arm true, got {arms_true}",
11013                );
11014            }
11015        }
11016    }
11017
11018    // ── ConditionSliceExt::has_at_most_one_of_kind — per-kind "≤ 1" pins ─
11019    //
11020    // Boolean cardinality "≤ 1" negation peer of `has_multiple_of_kind`
11021    // (≥ 2) on the per-kind count axis: `has_at_most_one_of_kind(k)`
11022    // returns `true` iff AT MOST ONE `Condition` value with kind `k`
11023    // appears in the slice, byte-for-byte with
11024    // `!has_multiple_of_kind(k)` via the definitional negation in the
11025    // trait's default body. Closes the {= 0, = 1, ≥ 1, ≥ 2, ≤ 1}
11026    // Boolean-cardinality grid on the per-kind axis. The composition
11027    // laws
11028    // `has_at_most_one_of_kind(k) == !has_multiple_of_kind(k)`,
11029    // `has_at_most_one_of_kind(k) == (count_kind(k) <= 1)`,
11030    // `has_at_most_one_of_kind(k) == (iter_kind(k).count() <= 1)`, and
11031    // `has_at_most_one_of_kind(k) == lacks_kind(k) || has_unique_of_kind(k)`
11032    // bind the per-kind "≤ 1" projection to the widened + scalar +
11033    // trichotomy-union primitives. Axis-parity peer of the distinct-
11034    // and missing-axis "≤ 1" negations
11035    // (`has_at_most_one_distinct_kind ↔ !has_multiple_distinct_kinds`,
11036    // `has_at_most_one_missing_kind ↔ !has_multiple_missing_kinds`)
11037    // at the same slice-level trait under the SAME definitional
11038    // negation shape.
11039
11040    /// EMPTY-SLICE pin — an empty slice returns `true` on
11041    /// `has_at_most_one_of_kind` for EVERY kind (0 matches, `≤ 1`).
11042    /// Also pins the composition law
11043    /// `has_at_most_one_of_kind(k) == !has_multiple_of_kind(k)` at
11044    /// zero-count for every kind and the trichotomy-union law
11045    /// `has_at_most_one_of_kind(k) == lacks_kind(k) ||
11046    /// has_unique_of_kind(k)` (=0 arm, `lacks_kind` fires).
11047    #[test]
11048    fn condition_slice_has_at_most_one_of_kind_returns_true_on_empty_slice() {
11049        let empty: &[Condition] = &[];
11050        for k in ConditionKind::ALL {
11051            assert!(
11052                empty.has_at_most_one_of_kind(k),
11053                "empty slice must return true on has_at_most_one_of_kind({k:?}) (0 matches, ≤ 1)",
11054            );
11055            assert_eq!(
11056                empty.has_at_most_one_of_kind(k),
11057                !empty.has_multiple_of_kind(k),
11058                "empty has_at_most_one_of_kind({k:?}) must equal !has_multiple_of_kind({k:?})",
11059            );
11060            assert_eq!(
11061                empty.has_at_most_one_of_kind(k),
11062                empty.count_kind(k) <= 1,
11063                "empty has_at_most_one_of_kind({k:?}) must equal (count_kind({k:?}) <= 1)",
11064            );
11065            assert_eq!(
11066                empty.has_at_most_one_of_kind(k),
11067                empty.lacks_kind(k) || empty.has_unique_of_kind(k),
11068                "empty has_at_most_one_of_kind({k:?}) must equal \
11069                 (lacks_kind({k:?}) || has_unique_of_kind({k:?}))",
11070            );
11071        }
11072    }
11073
11074    /// COUNT-AXIS pin — sweeps a range of per-kind multiplicities
11075    /// (0, 1, 2, 3) and asserts the primitive equals
11076    /// `count_kind(k) <= 1` at each arm. Pins the transition from
11077    /// the =1 (singleton) arm where the primitive returns `true` to
11078    /// the =2 (duplicate) arm where it returns `false`, byte-for-byte
11079    /// with the definitional negation of `has_multiple_of_kind` at
11080    /// each multiplicity. Also pins per-kind independence: multiplicity
11081    /// of OTHER kinds (each present exactly once) leaves the "≤ 1"
11082    /// arm of every other kind at `true` regardless of `target`'s
11083    /// multiplicity.
11084    #[test]
11085    fn condition_slice_has_at_most_one_of_kind_tracks_count_kind_le_one() {
11086        for target in ConditionKind::ALL {
11087            for target_multiplicity in [0usize, 1, 2, 3] {
11088                // Build a slice with `target` repeated
11089                // `target_multiplicity` times, plus one instance of
11090                // every OTHER kind. `has_at_most_one_of_kind(target)`
11091                // must depend only on `target_multiplicity`.
11092                let mut slice: Vec<Condition> = Vec::new();
11093                for _ in 0..target_multiplicity {
11094                    slice.push(condition_with(target));
11095                }
11096                for other in ConditionKind::ALL {
11097                    if other != target {
11098                        slice.push(condition_with(other));
11099                    }
11100                }
11101                let s = slice.as_slice();
11102
11103                assert_eq!(
11104                    s.has_at_most_one_of_kind(target),
11105                    target_multiplicity <= 1,
11106                    "has_at_most_one_of_kind({target:?}) with multiplicity {target_multiplicity} \
11107                     must equal ({target_multiplicity} <= 1)",
11108                );
11109                assert_eq!(
11110                    s.has_at_most_one_of_kind(target),
11111                    !s.has_multiple_of_kind(target),
11112                    "has_at_most_one_of_kind({target:?}) drifted from !has_multiple_of_kind at \
11113                     multiplicity {target_multiplicity}",
11114                );
11115                assert_eq!(
11116                    s.has_at_most_one_of_kind(target),
11117                    s.count_kind(target) <= 1,
11118                    "has_at_most_one_of_kind({target:?}) drifted from (count_kind <= 1) at \
11119                     multiplicity {target_multiplicity}",
11120                );
11121                assert_eq!(
11122                    s.has_at_most_one_of_kind(target),
11123                    s.iter_kind(target).count() <= 1,
11124                    "has_at_most_one_of_kind({target:?}) drifted from (iter_kind.count() <= 1) \
11125                     at multiplicity {target_multiplicity}",
11126                );
11127                // Trichotomy-union arm: {= 0} ∪ {= 1} == {≤ 1}.
11128                assert_eq!(
11129                    s.has_at_most_one_of_kind(target),
11130                    s.lacks_kind(target) || s.has_unique_of_kind(target),
11131                    "has_at_most_one_of_kind({target:?}) drifted from \
11132                     (lacks_kind || has_unique_of_kind) at multiplicity {target_multiplicity}",
11133                );
11134
11135                // OTHER kinds appear exactly once; their "≤ 1" arm
11136                // stays `true` regardless of `target`'s multiplicity.
11137                for other in ConditionKind::ALL {
11138                    if other != target {
11139                        assert!(
11140                            s.has_at_most_one_of_kind(other),
11141                            "other kind {other:?} present once must return true on \
11142                             has_at_most_one_of_kind (target={target:?} mult={target_multiplicity})",
11143                        );
11144                    }
11145                }
11146
11147                // Boolean tetrachotomy pin — for a given per-kind
11148                // multiplicity, {has_at_most_one_of_kind,
11149                // has_multiple_of_kind} PARTITION the count axis
11150                // under the definitional negation (EXACTLY ONE fires
11151                // on any `(s, target)` pair). Also verifies the
11152                // relationship with the {= 0, = 1, ≥ 2} trichotomy:
11153                // `has_at_most_one_of_kind` fires iff either
11154                // `lacks_kind` or `has_unique_of_kind` fires.
11155                let at_most_one = s.has_at_most_one_of_kind(target);
11156                let multiple = s.has_multiple_of_kind(target);
11157                assert_ne!(
11158                    at_most_one, multiple,
11159                    "per-kind {{≤1, ≥2}} Boolean-negation partition for target={target:?} at \
11160                     mult={target_multiplicity} must fire EXACTLY one arm",
11161                );
11162            }
11163        }
11164    }
11165
11166    // ── ConditionSliceExt::has_at_most_one_distinct_kind — "≤ 1" pins ─
11167    //
11168    // Boolean cardinality "≤ 1" negation peer of
11169    // `has_multiple_distinct_kinds` on the closed-set-inversion axis:
11170    // `has_at_most_one_distinct_kind()` returns `true` iff AT MOST ONE
11171    // `ConditionKind::ALL` variant appears at least once in the slice,
11172    // byte-for-byte with `!has_multiple_distinct_kinds()` via the
11173    // definitional negation in the trait's default body. The
11174    // composition laws
11175    // `has_at_most_one_distinct_kind() == !has_multiple_distinct_kinds()`,
11176    // `has_at_most_one_distinct_kind() == (distinct_kind_count() <= 1)`,
11177    // `has_at_most_one_distinct_kind() == (distinct_kinds().len() <= 1)`,
11178    // and `has_at_most_one_distinct_kind() == !has_any_distinct_kind() ||
11179    // has_unique_distinct_kind()` are pinned as the distinct-axis
11180    // "≤ 1" arm of `assert_slice_refinement_composition_laws`. Byte-
11181    // for-byte peer of
11182    // `crate::tagged_union::TaggedUnion::has_at_most_one_populated_kind`
11183    // one struct-layer up under the SAME `!has_multiple_populated_kinds`
11184    // definitional negation shape. Axis-parity mirror of the closed-
11185    // set-complement "≤ 1" negation peer
11186    // `has_at_most_one_missing_kind ↔ !has_multiple_missing_kinds` at
11187    // the same slice-level trait.
11188
11189    /// EMPTY-SLICE pin — an empty slice returns `true` on
11190    /// `has_at_most_one_distinct_kind` (0 distinct, `≤ 1`). Dual of
11191    /// the empty-slice arm on `has_at_most_one_missing_kind` which
11192    /// returns `false` on `N ≥ 2` closed sets (empty means every kind
11193    /// missing, `N ≥ 2` missing, not `≤ 1`). Also pins the composition
11194    /// law `has_at_most_one_distinct_kind() == (distinct_kind_count() <= 1)`
11195    /// at zero-distinct.
11196    #[test]
11197    fn condition_slice_has_at_most_one_distinct_kind_returns_true_on_empty_slice() {
11198        let empty: &[Condition] = &[];
11199        assert!(
11200            empty.has_at_most_one_distinct_kind(),
11201            "empty slice must return true on has_at_most_one_distinct_kind (0 distinct, ≤ 1)",
11202        );
11203        assert_eq!(
11204            empty.has_at_most_one_distinct_kind(),
11205            empty.distinct_kind_count() <= 1,
11206            "empty has_at_most_one_distinct_kind must equal (distinct_kind_count() <= 1)",
11207        );
11208    }
11209
11210    /// SINGLE-KIND pin — a slice populating exactly one variant
11211    /// returns `true` on `has_at_most_one_distinct_kind` (1 distinct,
11212    /// `≤ 1`). The singleton arm on the distinct-axis "≤ 1" primitive
11213    /// — the definitional boundary between the =1 mid-endpoint and the
11214    /// ≥ 2 many-arm on the distinct axis, where the "≤ 1" negation
11215    /// still fires. Also pins the widened composition law
11216    /// `has_at_most_one_distinct_kind() == (distinct_kinds().len() <= 1)`
11217    /// and the trichotomy-union arm
11218    /// `has_at_most_one_distinct_kind() == !has_any_distinct_kind() ||
11219    /// has_unique_distinct_kind()`.
11220    #[test]
11221    fn condition_slice_has_at_most_one_distinct_kind_returns_true_on_single_kind_slice() {
11222        for populated in ConditionKind::ALL {
11223            let slice = [condition_with(populated)];
11224            assert!(
11225                slice.has_at_most_one_distinct_kind(),
11226                "single-populated slice with {populated:?} must return true on has_at_most_one_distinct_kind (1 distinct, ≤ 1)",
11227            );
11228            assert_eq!(
11229                slice.has_at_most_one_distinct_kind(),
11230                !slice.has_multiple_distinct_kinds(),
11231                "single-populated has_at_most_one_distinct_kind must equal !has_multiple_distinct_kinds() for {populated:?}",
11232            );
11233            assert_eq!(
11234                slice.has_at_most_one_distinct_kind(),
11235                slice.distinct_kind_count() <= 1,
11236                "single-populated has_at_most_one_distinct_kind must equal (distinct_kind_count() <= 1) for {populated:?}",
11237            );
11238            assert_eq!(
11239                slice.has_at_most_one_distinct_kind(),
11240                slice.distinct_kinds().len() <= 1,
11241                "single-populated has_at_most_one_distinct_kind must equal (distinct_kinds().len() <= 1) for {populated:?}",
11242            );
11243            assert_eq!(
11244                slice.has_at_most_one_distinct_kind(),
11245                !slice.has_any_distinct_kind() || slice.has_unique_distinct_kind(),
11246                "single-populated has_at_most_one_distinct_kind must equal (!has_any_distinct_kind() || has_unique_distinct_kind()) for {populated:?}",
11247            );
11248        }
11249    }
11250
11251    /// SATURATED pin — a slice carrying every [`ConditionKind`]
11252    /// variant returns `false` on `has_at_most_one_distinct_kind` on
11253    /// any `N ≥ 2` closed set (`N` distinct, not `≤ 1`). Dual of the
11254    /// SATURATED arm on `has_at_most_one_missing_kind` which returns
11255    /// `true` on `N ≥ 2` (0 missing, `≤ 1`).
11256    #[test]
11257    fn condition_slice_has_at_most_one_distinct_kind_returns_false_on_saturated_slice() {
11258        assert!(
11259            ConditionKind::ALL.len() >= 2,
11260            "test assumes ConditionKind::ALL has ≥ 2 variants",
11261        );
11262        let saturated: Vec<Condition> =
11263            ConditionKind::ALL.into_iter().map(condition_with).collect();
11264        assert!(
11265            !saturated.as_slice().has_at_most_one_distinct_kind(),
11266            "saturated slice must return false on has_at_most_one_distinct_kind ({} distinct, not ≤ 1)",
11267            ConditionKind::ALL.len(),
11268        );
11269        assert_eq!(
11270            saturated.as_slice().has_at_most_one_distinct_kind(),
11271            saturated.as_slice().distinct_kind_count() <= 1,
11272            "saturated has_at_most_one_distinct_kind must equal (distinct_kind_count() <= 1)",
11273        );
11274        assert_eq!(
11275            saturated.as_slice().has_at_most_one_distinct_kind(),
11276            !saturated.as_slice().has_any_distinct_kind()
11277                || saturated.as_slice().has_unique_distinct_kind(),
11278            "saturated has_at_most_one_distinct_kind must equal (!has_any_distinct_kind() || has_unique_distinct_kind())",
11279        );
11280    }
11281
11282    /// TWO-POPULATED pin — a slice carrying exactly two distinct
11283    /// [`ConditionKind`] variants returns `false` on
11284    /// `has_at_most_one_distinct_kind` (2 distinct, not `≤ 1`). Pins
11285    /// the SECOND-slot boundary of the negation of the ≥ 2 arm — a
11286    /// regression that dropped the second-slot short-circuit on the
11287    /// many-arm primitive (returning `false` on any partial-populated
11288    /// arrangement, which negates to `true` here) would still pass
11289    /// here; complemented by the SATURATED pin which distinguishes the
11290    /// N-distinct arm from the 2-distinct arm. Only meaningful on
11291    /// `N ≥ 2` closed sets.
11292    #[test]
11293    fn condition_slice_has_at_most_one_distinct_kind_returns_false_on_two_populated_slice() {
11294        assert!(
11295            ConditionKind::ALL.len() >= 2,
11296            "test assumes ConditionKind::ALL has ≥ 2 variants",
11297        );
11298        for i in 0..ConditionKind::ALL.len() {
11299            for j in (i + 1)..ConditionKind::ALL.len() {
11300                let two_populated: Vec<Condition> = vec![
11301                    condition_with(ConditionKind::ALL[i]),
11302                    condition_with(ConditionKind::ALL[j]),
11303                ];
11304                let slice = two_populated.as_slice();
11305                assert!(
11306                    !slice.has_at_most_one_distinct_kind(),
11307                    "two-populated slice (kinds at index {i} and {j}) must return false on has_at_most_one_distinct_kind (2 distinct, not ≤ 1)",
11308                );
11309                assert_eq!(
11310                    slice.has_at_most_one_distinct_kind(),
11311                    slice.distinct_kind_count() <= 1,
11312                    "two-populated has_at_most_one_distinct_kind must equal (distinct_kind_count() <= 1) for kinds=({i}, {j})",
11313                );
11314            }
11315        }
11316    }
11317
11318    /// MULTIPLICITY pin — a slice carrying the SAME [`ConditionKind`]
11319    /// multiple times still returns `true` on
11320    /// `has_at_most_one_distinct_kind` (multiplicity is irrelevant to
11321    /// the "≤ 1" projection on the closed-set-inversion axis — one
11322    /// distinct kind regardless of repetition count, `≤ 1`).
11323    #[test]
11324    fn condition_slice_has_at_most_one_distinct_kind_ignores_multiplicity() {
11325        for k in ConditionKind::ALL {
11326            let doubled: Vec<Condition> = vec![condition_with(k), condition_with(k)];
11327            assert!(
11328                doubled.as_slice().has_at_most_one_distinct_kind(),
11329                "slice carrying {k:?} twice must return true on has_at_most_one_distinct_kind (still 1 distinct, ≤ 1)",
11330            );
11331            let tripled: Vec<Condition> =
11332                vec![condition_with(k), condition_with(k), condition_with(k)];
11333            assert!(
11334                tripled.as_slice().has_at_most_one_distinct_kind(),
11335                "slice carrying {k:?} three times must return true on has_at_most_one_distinct_kind (still 1 distinct, ≤ 1)",
11336            );
11337        }
11338    }
11339
11340    // ── ConditionSliceExt::is_kind_empty — zero-endpoint pins ──
11341    //
11342    // Boolean cardinality zero-endpoint peer of `is_kind_saturated` on
11343    // the closed-set-inversion axis: `is_kind_empty()` returns `true`
11344    // iff NO `ConditionKind::ALL` variant appears in the slice, byte-
11345    // for-byte with `self.iter_distinct_kinds().next().is_none()` in
11346    // the trait's default body. The composition laws
11347    // `is_kind_empty() == !has_any_distinct_kind()`,
11348    // `is_kind_empty() == (distinct_kind_count() == 0)`,
11349    // `is_kind_empty() == distinct_kinds().is_empty()`, and
11350    // `is_kind_empty() == iter_distinct_kinds().next().is_none()` are
11351    // pinned as the zero-endpoint arm on the distinct axis of
11352    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer of
11353    // `crate::tagged_union::TaggedUnion::is_empty` one struct-layer up
11354    // under the SAME zero-endpoint short-circuit shape. Axis-parity
11355    // mirror of `is_kind_saturated` on the closed-set-inversion axis
11356    // at the same slice-level trait.
11357
11358    /// EMPTY-SLICE pin — an empty slice returns `true` on
11359    /// `is_kind_empty` (0 distinct, = 0). The SOLE arm on any `N ≥ 1`
11360    /// closed set where `is_kind_empty` returns `true`, byte-for-byte
11361    /// peer of the SOLE arm on which `is_kind_saturated` returns `true`
11362    /// (a slice carrying every variant at least once) — the (empty,
11363    /// saturated) endpoint pair. Also pins the composition law
11364    /// `is_kind_empty() == (distinct_kind_count() == 0)` and
11365    /// `is_kind_empty() == distinct_kinds().is_empty()` at the zero
11366    /// endpoint.
11367    #[test]
11368    fn condition_slice_is_kind_empty_returns_true_on_empty_slice() {
11369        let empty: &[Condition] = &[];
11370        assert!(
11371            empty.is_kind_empty(),
11372            "empty slice must return true on is_kind_empty (0 distinct, = 0)",
11373        );
11374        assert_eq!(
11375            empty.is_kind_empty(),
11376            empty.distinct_kind_count() == 0,
11377            "empty is_kind_empty must equal (distinct_kind_count() == 0)",
11378        );
11379        assert_eq!(
11380            empty.is_kind_empty(),
11381            empty.distinct_kinds().is_empty(),
11382            "empty is_kind_empty must equal distinct_kinds().is_empty()",
11383        );
11384        assert_eq!(
11385            empty.is_kind_empty(),
11386            !empty.has_any_distinct_kind(),
11387            "empty is_kind_empty must equal !has_any_distinct_kind()",
11388        );
11389    }
11390
11391    /// SINGLE-KIND pin — a slice populating exactly one variant
11392    /// returns `false` on `is_kind_empty` (1 distinct, not = 0). Dual
11393    /// of the single-kind arm on `has_any_distinct_kind` which returns
11394    /// `true` on any single-populated slice, and pinned complement of
11395    /// the single-kind arm on `has_at_most_one_distinct_kind` which
11396    /// returns `true` (1 distinct is `≤ 1` but not `= 0`).
11397    #[test]
11398    fn condition_slice_is_kind_empty_returns_false_on_single_kind_slice() {
11399        for populated in ConditionKind::ALL {
11400            let slice = [condition_with(populated)];
11401            assert!(
11402                !slice.is_kind_empty(),
11403                "single-populated slice with {populated:?} must return false on is_kind_empty (1 distinct, not = 0)",
11404            );
11405            assert_eq!(
11406                slice.is_kind_empty(),
11407                slice.distinct_kind_count() == 0,
11408                "single-populated is_kind_empty must equal (distinct_kind_count() == 0) for {populated:?}",
11409            );
11410            assert_eq!(
11411                slice.is_kind_empty(),
11412                !slice.has_any_distinct_kind(),
11413                "single-populated is_kind_empty must equal !has_any_distinct_kind() for {populated:?}",
11414            );
11415        }
11416    }
11417
11418    /// SATURATED pin — a slice carrying every [`ConditionKind`]
11419    /// variant returns `false` on `is_kind_empty` on any `N ≥ 1`
11420    /// closed set (`N` distinct, not `= 0`). Dual of the SATURATED
11421    /// arm on `is_kind_saturated` which returns `true` (0 missing,
11422    /// `= 0` on the closed-set-complement axis) — the two Booleans
11423    /// name the two OPPOSITE endpoints of the (distinct, missing)
11424    /// partition on any non-trivial closed set.
11425    #[test]
11426    fn condition_slice_is_kind_empty_returns_false_on_saturated_slice() {
11427        assert!(
11428            !ConditionKind::ALL.is_empty(),
11429            "test assumes ConditionKind::ALL has ≥ 1 variants",
11430        );
11431        let saturated: Vec<Condition> =
11432            ConditionKind::ALL.into_iter().map(condition_with).collect();
11433        assert!(
11434            !saturated.as_slice().is_kind_empty(),
11435            "saturated slice must return false on is_kind_empty ({} distinct, not = 0)",
11436            ConditionKind::ALL.len(),
11437        );
11438        assert_eq!(
11439            saturated.as_slice().is_kind_empty(),
11440            saturated.as_slice().distinct_kind_count() == 0,
11441            "saturated is_kind_empty must equal (distinct_kind_count() == 0)",
11442        );
11443        assert!(
11444            !saturated.as_slice().is_kind_empty() && saturated.as_slice().is_kind_saturated(),
11445            "saturated slice must return false on is_kind_empty AND true on is_kind_saturated — the (empty, saturated) endpoint pair partitions ALL",
11446        );
11447    }
11448
11449    /// TWO-POPULATED pin — a slice carrying exactly two distinct
11450    /// [`ConditionKind`] variants returns `false` on `is_kind_empty`
11451    /// (2 distinct, not `= 0`). Only meaningful on `N ≥ 2` closed
11452    /// sets.
11453    #[test]
11454    fn condition_slice_is_kind_empty_returns_false_on_two_populated_slice() {
11455        assert!(
11456            ConditionKind::ALL.len() >= 2,
11457            "test assumes ConditionKind::ALL has ≥ 2 variants",
11458        );
11459        for i in 0..ConditionKind::ALL.len() {
11460            for j in (i + 1)..ConditionKind::ALL.len() {
11461                let two_populated: Vec<Condition> = vec![
11462                    condition_with(ConditionKind::ALL[i]),
11463                    condition_with(ConditionKind::ALL[j]),
11464                ];
11465                let slice = two_populated.as_slice();
11466                assert!(
11467                    !slice.is_kind_empty(),
11468                    "two-populated slice (kinds at index {i} and {j}) must return false on is_kind_empty (2 distinct, not = 0)",
11469                );
11470                assert_eq!(
11471                    slice.is_kind_empty(),
11472                    slice.distinct_kind_count() == 0,
11473                    "two-populated is_kind_empty must equal (distinct_kind_count() == 0) for kinds=({i}, {j})",
11474                );
11475            }
11476        }
11477    }
11478
11479    /// MULTIPLICITY pin — a slice carrying the SAME [`ConditionKind`]
11480    /// multiple times still returns `false` on `is_kind_empty` (still
11481    /// 1 distinct regardless of repetition count, `> 0`). Complement
11482    /// of the empty-slice arm — the zero-endpoint fires strictly on
11483    /// zero-distinct slices, never on any non-empty arrangement.
11484    #[test]
11485    fn condition_slice_is_kind_empty_returns_false_regardless_of_multiplicity() {
11486        for k in ConditionKind::ALL {
11487            let doubled: Vec<Condition> = vec![condition_with(k), condition_with(k)];
11488            assert!(
11489                !doubled.as_slice().is_kind_empty(),
11490                "slice carrying {k:?} twice must return false on is_kind_empty (1 distinct, not = 0)",
11491            );
11492            let tripled: Vec<Condition> =
11493                vec![condition_with(k), condition_with(k), condition_with(k)];
11494            assert!(
11495                !tripled.as_slice().is_kind_empty(),
11496                "slice carrying {k:?} three times must return false on is_kind_empty (1 distinct, not = 0)",
11497            );
11498        }
11499    }
11500
11501    // ── ConditionSliceExt::is_kind_partially_covered — middle-arm pins ──
11502    //
11503    // Boolean cardinality parent-state middle-arm peer of
11504    // `is_kind_empty` (=0 zero-endpoint on the distinct axis) and
11505    // `is_kind_saturated` (=0 zero-endpoint on the missing axis):
11506    // `is_kind_partially_covered()` returns `true` iff AT LEAST ONE
11507    // `ConditionKind::ALL` variant is PRESENT AND AT LEAST ONE is
11508    // ABSENT, byte-for-byte with `!is_kind_empty() && !is_kind_saturated()`
11509    // via the negation-of-both-endpoints composition — but composed
11510    // through a FUSED short-circuit walk that can exit on the SECOND
11511    // `ConditionKind::ALL` slot when the two bits close. The
11512    // composition laws
11513    // `is_kind_partially_covered() == !is_kind_empty() && !is_kind_saturated()`,
11514    // `is_kind_partially_covered() == has_any_distinct_kind() && has_any_missing_kind()`,
11515    // `is_kind_partially_covered() == (distinct_kind_count() > 0 && missing_kind_count() > 0)`,
11516    // and the trichotomy partition law
11517    // `is_kind_empty + is_kind_partially_covered + is_kind_saturated == 1`
11518    // are pinned as the parent-state trichotomy arm of
11519    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer of
11520    // `crate::tagged_union::TaggedUnion::is_partially_populated` one
11521    // struct-layer up under the SAME fused short-circuit walk shape.
11522
11523    /// EMPTY-SLICE pin — an empty slice returns `false` on
11524    /// `is_kind_partially_covered` (0 distinct + N missing hits the
11525    /// `is_kind_empty` arm, not the middle arm). Dual of the empty-
11526    /// slice arm on `is_kind_empty` which returns `true` — the two
11527    /// primitives partition the zero-distinct endpoint.
11528    #[test]
11529    fn condition_slice_is_kind_partially_covered_returns_false_on_empty_slice() {
11530        let empty: &[Condition] = &[];
11531        assert!(
11532            !empty.is_kind_partially_covered(),
11533            "empty slice must return false on is_kind_partially_covered (0 distinct hits is_kind_empty)",
11534        );
11535        assert_eq!(
11536            empty.is_kind_partially_covered(),
11537            !empty.is_kind_empty() && !empty.is_kind_saturated(),
11538            "empty is_kind_partially_covered must equal (!is_kind_empty() && !is_kind_saturated())",
11539        );
11540        assert_eq!(
11541            empty.is_kind_partially_covered(),
11542            empty.has_any_distinct_kind() && empty.has_any_missing_kind(),
11543            "empty is_kind_partially_covered must equal (has_any_distinct_kind() && has_any_missing_kind())",
11544        );
11545    }
11546
11547    /// SATURATED pin — a slice carrying every [`ConditionKind`] variant
11548    /// returns `false` on `is_kind_partially_covered` on any `N ≥ 1`
11549    /// closed set (N distinct + 0 missing hits the `is_kind_saturated`
11550    /// arm, not the middle arm). Dual of the SATURATED arm on
11551    /// `is_kind_saturated` which returns `true`.
11552    #[test]
11553    fn condition_slice_is_kind_partially_covered_returns_false_on_saturated_slice() {
11554        assert!(
11555            !ConditionKind::ALL.is_empty(),
11556            "test assumes ConditionKind::ALL has ≥ 1 variants",
11557        );
11558        let saturated: Vec<Condition> =
11559            ConditionKind::ALL.into_iter().map(condition_with).collect();
11560        assert!(
11561            !saturated.as_slice().is_kind_partially_covered(),
11562            "saturated slice must return false on is_kind_partially_covered (0 missing hits is_kind_saturated)",
11563        );
11564        assert_eq!(
11565            saturated.as_slice().is_kind_partially_covered(),
11566            !saturated.as_slice().is_kind_empty() && !saturated.as_slice().is_kind_saturated(),
11567            "saturated is_kind_partially_covered must equal (!is_kind_empty() && !is_kind_saturated())",
11568        );
11569    }
11570
11571    /// SINGLE-KIND pin — a slice populating exactly one variant on any
11572    /// `N ≥ 2` closed set returns `true` on `is_kind_partially_covered`
11573    /// (1 distinct + N-1 missing sits in the (open, open) product).
11574    /// The SOLE arm where the middle predicate FIRST fires on a well-
11575    /// formed slice one step away from empty.
11576    #[test]
11577    fn condition_slice_is_kind_partially_covered_returns_true_on_single_kind_slice() {
11578        assert!(
11579            ConditionKind::ALL.len() >= 2,
11580            "test assumes ConditionKind::ALL has ≥ 2 variants",
11581        );
11582        for populated in ConditionKind::ALL {
11583            let slice = [condition_with(populated)];
11584            assert!(
11585                slice.is_kind_partially_covered(),
11586                "single-populated slice with {populated:?} must return true on is_kind_partially_covered (1 distinct + N-1 missing)",
11587            );
11588            assert_eq!(
11589                slice.is_kind_partially_covered(),
11590                slice.has_any_distinct_kind() && slice.has_any_missing_kind(),
11591                "single-populated is_kind_partially_covered must equal (has_any_distinct_kind() && has_any_missing_kind()) for {populated:?}",
11592            );
11593            assert_eq!(
11594                slice.is_kind_partially_covered(),
11595                slice.distinct_kind_count() > 0 && slice.missing_kind_count() > 0,
11596                "single-populated is_kind_partially_covered must equal (distinct_kind_count() > 0 && missing_kind_count() > 0) for {populated:?}",
11597            );
11598        }
11599    }
11600
11601    /// MULTIPLICITY pin — a slice carrying the SAME [`ConditionKind`]
11602    /// multiple times still returns `true` on
11603    /// `is_kind_partially_covered` on any `N ≥ 2` closed set
11604    /// (multiplicity is irrelevant — one distinct kind + N-1 missing).
11605    /// Complement of the empty-slice arm — the middle predicate collapses
11606    /// to non-emptiness of both the distinct SET and the missing SET.
11607    #[test]
11608    fn condition_slice_is_kind_partially_covered_ignores_multiplicity() {
11609        assert!(
11610            ConditionKind::ALL.len() >= 2,
11611            "test assumes ConditionKind::ALL has ≥ 2 variants",
11612        );
11613        for k in ConditionKind::ALL {
11614            let doubled: Vec<Condition> = vec![condition_with(k), condition_with(k)];
11615            assert!(
11616                doubled.as_slice().is_kind_partially_covered(),
11617                "slice carrying {k:?} twice must return true on is_kind_partially_covered (still 1 distinct + N-1 missing)",
11618            );
11619            let tripled: Vec<Condition> =
11620                vec![condition_with(k), condition_with(k), condition_with(k)];
11621            assert!(
11622                tripled.as_slice().is_kind_partially_covered(),
11623                "slice carrying {k:?} three times must return true on is_kind_partially_covered (still 1 distinct + N-1 missing)",
11624            );
11625        }
11626    }
11627
11628    /// TRICHOTOMY PARTITION pin — EXACTLY ONE of `is_kind_empty`,
11629    /// `is_kind_partially_covered`, and `is_kind_saturated` returns
11630    /// `true` on any `N ≥ 1` closed set across every representative
11631    /// arrangement (empty, single-populated, near-saturated,
11632    /// saturated). Byte-for-byte peer of the tagged-union parent-state
11633    /// trichotomy `is_empty + is_partially_populated + is_saturated == 1`
11634    /// one struct-layer up. The most load-bearing composition law on
11635    /// the closed-set partition — a regression that broke ONE arm
11636    /// (leaving the other two intact) surfaces HERE at ONE substrate
11637    /// test rather than as silent skew at the classifier callsite.
11638    #[test]
11639    fn condition_slice_partition_trichotomy_holds_on_every_arrangement() {
11640        assert!(
11641            ConditionKind::ALL.len() >= 2,
11642            "test assumes ConditionKind::ALL has ≥ 2 variants",
11643        );
11644        // Empty arm.
11645        let empty: &[Condition] = &[];
11646        assert_eq!(
11647            usize::from(empty.is_kind_empty())
11648                + usize::from(empty.is_kind_partially_covered())
11649                + usize::from(empty.is_kind_saturated()),
11650            1,
11651            "trichotomy partition violated on empty slice",
11652        );
11653        // Single-populated arm.
11654        for k in ConditionKind::ALL {
11655            let slice = [condition_with(k)];
11656            assert_eq!(
11657                usize::from(slice.is_kind_empty())
11658                    + usize::from(slice.is_kind_partially_covered())
11659                    + usize::from(slice.is_kind_saturated()),
11660                1,
11661                "trichotomy partition violated on single-populated slice with {k:?}",
11662            );
11663        }
11664        // Saturated arm.
11665        let saturated: Vec<Condition> =
11666            ConditionKind::ALL.into_iter().map(condition_with).collect();
11667        assert_eq!(
11668            usize::from(saturated.as_slice().is_kind_empty())
11669                + usize::from(saturated.as_slice().is_kind_partially_covered())
11670                + usize::from(saturated.as_slice().is_kind_saturated()),
11671            1,
11672            "trichotomy partition violated on saturated slice",
11673        );
11674        // Near-saturated arm (every kind except one) — meaningful on N ≥ 2.
11675        for omit in ConditionKind::ALL {
11676            let near_sat: Vec<Condition> = ConditionKind::ALL
11677                .into_iter()
11678                .filter(|k| *k != omit)
11679                .map(condition_with)
11680                .collect();
11681            assert_eq!(
11682                usize::from(near_sat.as_slice().is_kind_empty())
11683                    + usize::from(near_sat.as_slice().is_kind_partially_covered())
11684                    + usize::from(near_sat.as_slice().is_kind_saturated()),
11685                1,
11686                "trichotomy partition violated on near-saturated slice omitting {omit:?}",
11687            );
11688        }
11689    }
11690
11691    // ── ConditionSliceExt::has_any_missing_kind — at-least-one halfspace pins ──
11692    //
11693    // Boolean at-least-one halfspace peer of `is_kind_saturated`:
11694    // `has_any_missing_kind()` returns `true` iff AT LEAST ONE
11695    // `ConditionKind::ALL` variant appears zero times in the slice,
11696    // byte-for-byte with `!is_kind_saturated()` via the definitional
11697    // negation in the trait's default body. The composition laws
11698    // `has_any_missing_kind() == !is_kind_saturated()`,
11699    // `has_any_missing_kind() == (missing_kind_count() > 0)`, and
11700    // `has_any_missing_kind() == !missing_kinds().is_empty()` are
11701    // pinned as the at-least-one halfspace arm of
11702    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
11703    // of `crate::tagged_union::TaggedUnion::has_any_missing_kind` one
11704    // struct-layer up under the SAME `!is_saturated` definitional
11705    // negation shape.
11706
11707    /// EMPTY-SLICE pin — an empty slice returns `true` on
11708    /// `has_any_missing_kind` (every kind is missing, so at least one
11709    /// is). Dual of the empty-slice arm on `is_kind_saturated` (which
11710    /// returns `false`).
11711    #[test]
11712    fn condition_slice_has_any_missing_kind_returns_true_on_empty_slice() {
11713        let empty: &[Condition] = &[];
11714        assert!(
11715            empty.has_any_missing_kind(),
11716            "empty slice must return true on has_any_missing_kind",
11717        );
11718        assert_eq!(
11719            empty.has_any_missing_kind(),
11720            !empty.is_kind_saturated(),
11721            "empty has_any_missing_kind must equal !is_kind_saturated()",
11722        );
11723        assert_eq!(
11724            empty.has_any_missing_kind(),
11725            empty.missing_kind_count() > 0,
11726            "empty has_any_missing_kind must equal (missing_kind_count() > 0)",
11727        );
11728    }
11729
11730    /// SINGLE-KIND pin — a slice populating exactly one variant
11731    /// returns `true` on any `ConditionKind::ALL` closed set with
11732    /// `N ≥ 2` (the other `N - 1` variants are missing).
11733    #[test]
11734    fn condition_slice_has_any_missing_kind_returns_true_on_single_kind_slice() {
11735        assert!(
11736            ConditionKind::ALL.len() >= 2,
11737            "test assumes ConditionKind::ALL has ≥ 2 variants",
11738        );
11739        for populated in ConditionKind::ALL {
11740            let slice = [condition_with(populated)];
11741            assert!(
11742                slice.has_any_missing_kind(),
11743                "single-populated slice with {populated:?} must return true on has_any_missing_kind",
11744            );
11745            assert_eq!(
11746                slice.has_any_missing_kind(),
11747                !slice.is_kind_saturated(),
11748                "single-populated has_any_missing_kind must equal !is_kind_saturated() for {populated:?}",
11749            );
11750        }
11751    }
11752
11753    /// FULL-COVERAGE pin — a slice that carries every
11754    /// [`ConditionKind`] variant returns `false` on
11755    /// `has_any_missing_kind` — the SOLE arm where the primitive
11756    /// returns `false`, byte-for-byte peer of the SOLE arm on which
11757    /// `is_kind_saturated` returns `true`.
11758    #[test]
11759    fn condition_slice_has_any_missing_kind_returns_false_on_saturated_slice() {
11760        let saturated: Vec<Condition> =
11761            ConditionKind::ALL.into_iter().map(condition_with).collect();
11762        assert!(
11763            !saturated.as_slice().has_any_missing_kind(),
11764            "slice containing every ConditionKind must return false on has_any_missing_kind",
11765        );
11766        assert_eq!(
11767            saturated.as_slice().has_any_missing_kind(),
11768            !saturated.as_slice().is_kind_saturated(),
11769            "saturated has_any_missing_kind must equal !is_kind_saturated()",
11770        );
11771        assert_eq!(
11772            saturated.as_slice().has_any_missing_kind(),
11773            !saturated.as_slice().missing_kinds().is_empty(),
11774            "saturated has_any_missing_kind must equal !missing_kinds().is_empty()",
11775        );
11776    }
11777
11778    /// DUPLICATE-COVERAGE pin — a slice that carries every
11779    /// [`ConditionKind`] variant multiple times still returns `false`
11780    /// (multiplicity is irrelevant to the at-least-one halfspace
11781    /// predicate on the closed-set-complement axis, byte-for-byte peer
11782    /// of the saturation-predicate arm).
11783    #[test]
11784    fn condition_slice_has_any_missing_kind_ignores_multiplicity() {
11785        let mut doubled: Vec<Condition> = Vec::new();
11786        for k in ConditionKind::ALL {
11787            doubled.push(condition_with(k));
11788            doubled.push(condition_with(k));
11789        }
11790        assert!(
11791            !doubled.as_slice().has_any_missing_kind(),
11792            "slice carrying every ConditionKind twice must return false on has_any_missing_kind",
11793        );
11794    }
11795
11796    // ── ConditionSliceExt::has_unique_missing_kind — near-saturation-endpoint pins ─
11797    //
11798    // Boolean cardinality-mid-endpoint peer of `has_any_missing_kind`
11799    // on the closed-set-complement axis: `has_unique_missing_kind()`
11800    // returns `true` iff EXACTLY ONE ConditionKind::ALL variant
11801    // appears zero times in the slice. Default body is a two-step-
11802    // short-circuit walk over ConditionKind::ALL under a negated
11803    // `has_kind` predicate — pulls up to two hits off the filtered
11804    // iterator, returns `true` iff the first is Some and the second
11805    // is None. Short-circuits at the SECOND missing kind — strictly
11806    // cheaper than `missing_kind_count() == 1` (which walks every
11807    // slot) and `missing_kinds().len() == 1` (which allocates the
11808    // Vec) on every arm with ≥ 2 missing kinds. The composition laws
11809    // `has_unique_missing_kind() == (missing_kind_count() == 1)` and
11810    // `has_unique_missing_kind() == (missing_kinds().len() == 1)`
11811    // are pinned as the cardinality-mid-endpoint arm of
11812    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
11813    // of `crate::tagged_union::TaggedUnion::has_unique_missing_kind`
11814    // one struct-layer up under the SAME two-step short-circuit walk
11815    // shape.
11816
11817    /// EMPTY-SLICE pin — an empty slice returns `false` on
11818    /// `has_unique_missing_kind` on any `N ≥ 2` closed set (every
11819    /// kind is missing — the fully-missing endpoint, `N` missing not
11820    /// `1`).
11821    #[test]
11822    fn condition_slice_has_unique_missing_kind_returns_false_on_empty_slice() {
11823        assert!(
11824            ConditionKind::ALL.len() >= 2,
11825            "test assumes ConditionKind::ALL has ≥ 2 variants",
11826        );
11827        let empty: &[Condition] = &[];
11828        assert!(
11829            !empty.has_unique_missing_kind(),
11830            "empty slice must return false on has_unique_missing_kind (all N kinds missing, not exactly 1)",
11831        );
11832        assert_eq!(
11833            empty.has_unique_missing_kind(),
11834            empty.missing_kind_count() == 1,
11835            "empty has_unique_missing_kind must equal (missing_kind_count() == 1)",
11836        );
11837    }
11838
11839    /// SINGLE-KIND pin — a slice populating exactly one variant
11840    /// returns `false` on any `N ≥ 3` closed set (`N - 1 ≥ 2` kinds
11841    /// missing). On the degenerate `N == 2` closed set (which no
11842    /// production `ConditionKind` reaches; this workspace has
11843    /// `N == 8`) it would return `true`, so the pin gates on
11844    /// `N ≥ 3`.
11845    #[test]
11846    fn condition_slice_has_unique_missing_kind_returns_false_on_single_kind_slice() {
11847        if ConditionKind::ALL.len() < 3 {
11848            return;
11849        }
11850        for populated in ConditionKind::ALL {
11851            let slice = [condition_with(populated)];
11852            assert!(
11853                !slice.has_unique_missing_kind(),
11854                "single-populated slice with {populated:?} must return false on has_unique_missing_kind on N ≥ 3 closed sets ({} kinds missing, not exactly 1)",
11855                ConditionKind::ALL.len() - 1,
11856            );
11857            assert_eq!(
11858                slice.has_unique_missing_kind(),
11859                slice.missing_kind_count() == 1,
11860                "single-populated has_unique_missing_kind must equal (missing_kind_count() == 1) for {populated:?}",
11861            );
11862        }
11863    }
11864
11865    /// NEAR-SATURATION-ENDPOINT pin — a slice carrying every
11866    /// [`ConditionKind`] EXCEPT exactly one returns `true` on
11867    /// `has_unique_missing_kind`. Sweeps ConditionKind::ALL; each
11868    /// arrangement omits one variant and populates the other `N - 1`.
11869    /// This is the SOLE arrangement where the primitive returns
11870    /// `true`. Also pins the widened composition law
11871    /// `has_unique_missing_kind() == (missing_kinds().len() == 1)`.
11872    #[test]
11873    fn condition_slice_has_unique_missing_kind_returns_true_on_near_saturation_endpoint() {
11874        for omitted in ConditionKind::ALL {
11875            let near_saturated: Vec<Condition> = ConditionKind::ALL
11876                .into_iter()
11877                .filter(|k| *k != omitted)
11878                .map(condition_with)
11879                .collect();
11880            let slice = near_saturated.as_slice();
11881            assert!(
11882                slice.has_unique_missing_kind(),
11883                "near-saturation-endpoint slice (omitting {omitted:?}) must return true on has_unique_missing_kind",
11884            );
11885            assert_eq!(
11886                slice.has_unique_missing_kind(),
11887                slice.missing_kind_count() == 1,
11888                "near-saturation-endpoint has_unique_missing_kind must equal (missing_kind_count() == 1) for omitted={omitted:?}",
11889            );
11890            assert_eq!(
11891                slice.has_unique_missing_kind(),
11892                slice.missing_kinds().len() == 1,
11893                "near-saturation-endpoint has_unique_missing_kind must equal (missing_kinds().len() == 1) for omitted={omitted:?}",
11894            );
11895            assert_eq!(
11896                slice.first_missing_kind(),
11897                Some(omitted),
11898                "near-saturation-endpoint first_missing_kind must name the SOLE remaining hole for omitted={omitted:?}",
11899            );
11900        }
11901    }
11902
11903    /// SATURATED pin — a slice carrying every [`ConditionKind`]
11904    /// variant returns `false` on `has_unique_missing_kind` (zero
11905    /// missing, not exactly one). Dual of the SATURATED arm on
11906    /// `is_kind_saturated` which returns `true`. Also pins the
11907    /// composition law `has_unique_missing_kind() ==
11908    /// (missing_kind_count() == 1)` at zero-missing.
11909    #[test]
11910    fn condition_slice_has_unique_missing_kind_returns_false_on_saturated_slice() {
11911        let saturated: Vec<Condition> =
11912            ConditionKind::ALL.into_iter().map(condition_with).collect();
11913        assert!(
11914            !saturated.as_slice().has_unique_missing_kind(),
11915            "slice containing every ConditionKind must return false on has_unique_missing_kind (0 missing, not exactly 1)",
11916        );
11917        assert_eq!(
11918            saturated.as_slice().has_unique_missing_kind(),
11919            saturated.as_slice().missing_kind_count() == 1,
11920            "saturated has_unique_missing_kind must equal (missing_kind_count() == 1)",
11921        );
11922    }
11923
11924    /// TWO-MISSING pin — a slice populating exactly `N - 2` variants
11925    /// returns `false` on `has_unique_missing_kind` (2 missing, not
11926    /// exactly 1). Pins the SECOND-slot short-circuit boundary — a
11927    /// regression that dropped the second-slot check (returning `true`
11928    /// on any partial-populated arm) surfaces HERE. Only meaningful
11929    /// on `N ≥ 2` closed sets.
11930    #[test]
11931    fn condition_slice_has_unique_missing_kind_returns_false_on_two_missing_slice() {
11932        assert!(
11933            ConditionKind::ALL.len() >= 2,
11934            "test assumes ConditionKind::ALL has ≥ 2 variants",
11935        );
11936        for i in 0..ConditionKind::ALL.len() {
11937            for j in (i + 1)..ConditionKind::ALL.len() {
11938                let two_missing: Vec<Condition> = ConditionKind::ALL
11939                    .into_iter()
11940                    .enumerate()
11941                    .filter(|(k, _)| *k != i && *k != j)
11942                    .map(|(_, k)| condition_with(k))
11943                    .collect();
11944                let slice = two_missing.as_slice();
11945                assert!(
11946                    !slice.has_unique_missing_kind(),
11947                    "two-missing slice (omitting index {i} and {j}) must return false on has_unique_missing_kind (2 missing, not exactly 1)",
11948                );
11949                assert_eq!(
11950                    slice.has_unique_missing_kind(),
11951                    slice.missing_kind_count() == 1,
11952                    "two-missing has_unique_missing_kind must equal (missing_kind_count() == 1) for omitted=({i}, {j})",
11953                );
11954            }
11955        }
11956    }
11957
11958    /// MULTIPLICITY pin — a slice at the near-saturation-endpoint
11959    /// with each populated kind duplicated still returns `true`
11960    /// (multiplicity is irrelevant to the cardinality-mid-endpoint
11961    /// projection on the closed-set-complement axis, byte-for-byte
11962    /// peer of the saturation-predicate arm).
11963    #[test]
11964    fn condition_slice_has_unique_missing_kind_ignores_multiplicity() {
11965        for omitted in ConditionKind::ALL {
11966            let mut doubled: Vec<Condition> = Vec::new();
11967            for k in ConditionKind::ALL {
11968                if k != omitted {
11969                    doubled.push(condition_with(k));
11970                    doubled.push(condition_with(k));
11971                }
11972            }
11973            assert!(
11974                doubled.as_slice().has_unique_missing_kind(),
11975                "near-saturation-endpoint slice with each populated kind duplicated (omitting {omitted:?}) must return true on has_unique_missing_kind",
11976            );
11977        }
11978    }
11979
11980    // ── ConditionSliceExt::has_multiple_missing_kinds — many-arm pins ──
11981    //
11982    // Boolean cardinality "≥ 2" many-arm peer of
11983    // `has_unique_missing_kind` on the closed-set-complement axis:
11984    // `has_multiple_missing_kinds()` returns `true` iff AT LEAST TWO
11985    // `ConditionKind::ALL` variants appear zero times in the slice.
11986    // Third and final arm of the {0, 1, ≥2} trichotomy on the missing
11987    // axis at the slice level (0-arm: `is_kind_saturated`; 1-arm:
11988    // `has_unique_missing_kind`; ≥ 2-arm: this primitive). Body
11989    // short-circuits at the second missing kind — strictly cheaper
11990    // than `missing_kind_count() >= 2` (which walks every slot) and
11991    // `missing_kinds().len() >= 2` (which allocates the Vec) on every
11992    // arm with ≥ 2 missing kinds. The composition laws
11993    // `has_multiple_missing_kinds() == (missing_kind_count() >= 2)`
11994    // and `has_multiple_missing_kinds() == (missing_kinds().len() >= 2)`
11995    // are pinned as the cardinality-many-arm arm of
11996    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
11997    // of `crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`
11998    // one struct-layer up under the SAME two-step short-circuit walk
11999    // shape.
12000
12001    /// EMPTY-SLICE pin — an empty slice returns `true` on
12002    /// `has_multiple_missing_kinds` on any `N ≥ 2` closed set (every
12003    /// kind is missing — the fully-missing endpoint, `N ≥ 2`
12004    /// missing).
12005    #[test]
12006    fn condition_slice_has_multiple_missing_kinds_returns_true_on_empty_slice() {
12007        assert!(
12008            ConditionKind::ALL.len() >= 2,
12009            "test assumes ConditionKind::ALL has ≥ 2 variants",
12010        );
12011        let empty: &[Condition] = &[];
12012        assert!(
12013            empty.has_multiple_missing_kinds(),
12014            "empty slice must return true on has_multiple_missing_kinds (all N ≥ 2 kinds missing)",
12015        );
12016        assert_eq!(
12017            empty.has_multiple_missing_kinds(),
12018            empty.missing_kind_count() >= 2,
12019            "empty has_multiple_missing_kinds must equal (missing_kind_count() >= 2)",
12020        );
12021    }
12022
12023    /// SINGLE-KIND pin — a slice populating exactly one variant
12024    /// returns `true` on any `N ≥ 3` closed set (`N - 1 ≥ 2` kinds
12025    /// missing). On the degenerate `N == 2` closed set (which no
12026    /// production `ConditionKind` reaches; this workspace has
12027    /// `N == 8`) it would return `false`, so the pin gates on
12028    /// `N ≥ 3`.
12029    #[test]
12030    fn condition_slice_has_multiple_missing_kinds_returns_true_on_single_kind_slice() {
12031        if ConditionKind::ALL.len() < 3 {
12032            return;
12033        }
12034        for populated in ConditionKind::ALL {
12035            let slice = [condition_with(populated)];
12036            assert!(
12037                slice.has_multiple_missing_kinds(),
12038                "single-populated slice with {populated:?} must return true on has_multiple_missing_kinds on N ≥ 3 closed sets ({} kinds missing, ≥ 2)",
12039                ConditionKind::ALL.len() - 1,
12040            );
12041            assert_eq!(
12042                slice.has_multiple_missing_kinds(),
12043                slice.missing_kind_count() >= 2,
12044                "single-populated has_multiple_missing_kinds must equal (missing_kind_count() >= 2) for {populated:?}",
12045            );
12046        }
12047    }
12048
12049    /// NEAR-SATURATION-ENDPOINT pin — a slice carrying every
12050    /// [`ConditionKind`] EXCEPT exactly one returns `false` on
12051    /// `has_multiple_missing_kinds` (exactly one missing, not ≥ 2).
12052    /// The SOLE-missing arrangement where the many-arm primitive
12053    /// returns `false` — the definitional boundary between the
12054    /// = 1 mid-endpoint and the ≥ 2 many-arm on the missing axis.
12055    /// Also pins the widened composition law
12056    /// `has_multiple_missing_kinds() == (missing_kinds().len() >= 2)`.
12057    #[test]
12058    fn condition_slice_has_multiple_missing_kinds_returns_false_on_near_saturation_endpoint() {
12059        for omitted in ConditionKind::ALL {
12060            let near_saturated: Vec<Condition> = ConditionKind::ALL
12061                .into_iter()
12062                .filter(|k| *k != omitted)
12063                .map(condition_with)
12064                .collect();
12065            let slice = near_saturated.as_slice();
12066            assert!(
12067                !slice.has_multiple_missing_kinds(),
12068                "near-saturation-endpoint slice (omitting {omitted:?}) must return false on has_multiple_missing_kinds (1 missing, not ≥ 2)",
12069            );
12070            assert_eq!(
12071                slice.has_multiple_missing_kinds(),
12072                slice.missing_kind_count() >= 2,
12073                "near-saturation-endpoint has_multiple_missing_kinds must equal (missing_kind_count() >= 2) for omitted={omitted:?}",
12074            );
12075            assert_eq!(
12076                slice.has_multiple_missing_kinds(),
12077                slice.missing_kinds().len() >= 2,
12078                "near-saturation-endpoint has_multiple_missing_kinds must equal (missing_kinds().len() >= 2) for omitted={omitted:?}",
12079            );
12080        }
12081    }
12082
12083    /// SATURATED pin — a slice carrying every [`ConditionKind`]
12084    /// variant returns `false` on `has_multiple_missing_kinds` (zero
12085    /// missing, not ≥ 2). Dual of the SATURATED arm on
12086    /// `is_kind_saturated` which returns `true`. Also pins the
12087    /// composition law `has_multiple_missing_kinds() ==
12088    /// (missing_kind_count() >= 2)` at zero-missing.
12089    #[test]
12090    fn condition_slice_has_multiple_missing_kinds_returns_false_on_saturated_slice() {
12091        let saturated: Vec<Condition> =
12092            ConditionKind::ALL.into_iter().map(condition_with).collect();
12093        assert!(
12094            !saturated.as_slice().has_multiple_missing_kinds(),
12095            "slice containing every ConditionKind must return false on has_multiple_missing_kinds (0 missing, not ≥ 2)",
12096        );
12097        assert_eq!(
12098            saturated.as_slice().has_multiple_missing_kinds(),
12099            saturated.as_slice().missing_kind_count() >= 2,
12100            "saturated has_multiple_missing_kinds must equal (missing_kind_count() >= 2)",
12101        );
12102    }
12103
12104    /// TWO-MISSING pin — a slice populating exactly `N - 2` variants
12105    /// returns `true` on `has_multiple_missing_kinds` (exactly 2
12106    /// missing, the SECOND-slot boundary of the ≥ 2 arm). Pins the
12107    /// second-slot short-circuit — a regression that dropped the
12108    /// second-slot check (returning `true` on any ≥ 1-missing arm,
12109    /// conflating with `has_any_missing_kind`) would still pass here,
12110    /// so this pin is complemented by the NEAR-SATURATION-ENDPOINT
12111    /// pin which distinguishes the =1 arm from the ≥ 2 arm.
12112    /// Only meaningful on `N ≥ 2` closed sets.
12113    #[test]
12114    fn condition_slice_has_multiple_missing_kinds_returns_true_on_two_missing_slice() {
12115        assert!(
12116            ConditionKind::ALL.len() >= 2,
12117            "test assumes ConditionKind::ALL has ≥ 2 variants",
12118        );
12119        for i in 0..ConditionKind::ALL.len() {
12120            for j in (i + 1)..ConditionKind::ALL.len() {
12121                let two_missing: Vec<Condition> = ConditionKind::ALL
12122                    .into_iter()
12123                    .enumerate()
12124                    .filter(|(k, _)| *k != i && *k != j)
12125                    .map(|(_, k)| condition_with(k))
12126                    .collect();
12127                let slice = two_missing.as_slice();
12128                assert!(
12129                    slice.has_multiple_missing_kinds(),
12130                    "two-missing slice (omitting index {i} and {j}) must return true on has_multiple_missing_kinds (2 missing, ≥ 2)",
12131                );
12132                assert_eq!(
12133                    slice.has_multiple_missing_kinds(),
12134                    slice.missing_kind_count() >= 2,
12135                    "two-missing has_multiple_missing_kinds must equal (missing_kind_count() >= 2) for omitted=({i}, {j})",
12136                );
12137            }
12138        }
12139    }
12140
12141    /// MULTIPLICITY pin — a slice at the empty-endpoint duplicated
12142    /// remains empty (nothing to duplicate), while a slice at a
12143    /// K-populated arm with each populated kind duplicated still
12144    /// returns `true` on any `N ≥ K + 2` — multiplicity is
12145    /// irrelevant to the cardinality many-arm projection on the
12146    /// closed-set-complement axis, byte-for-byte peer of the
12147    /// saturation-predicate arm. Sweeps the near-two-missing
12148    /// arrangement (each pair-omitted arm, doubled populated) on
12149    /// `N ≥ 2` closed sets.
12150    #[test]
12151    fn condition_slice_has_multiple_missing_kinds_ignores_multiplicity() {
12152        assert!(
12153            ConditionKind::ALL.len() >= 2,
12154            "test assumes ConditionKind::ALL has ≥ 2 variants",
12155        );
12156        for i in 0..ConditionKind::ALL.len() {
12157            for j in (i + 1)..ConditionKind::ALL.len() {
12158                let mut doubled: Vec<Condition> = Vec::new();
12159                for (idx, kind) in ConditionKind::ALL.into_iter().enumerate() {
12160                    if idx != i && idx != j {
12161                        doubled.push(condition_with(kind));
12162                        doubled.push(condition_with(kind));
12163                    }
12164                }
12165                assert!(
12166                    doubled.as_slice().has_multiple_missing_kinds(),
12167                    "two-missing slice (omitting index {i} and {j}) with each populated kind duplicated must return true on has_multiple_missing_kinds",
12168                );
12169            }
12170        }
12171    }
12172
12173    // ── ConditionSliceExt::has_at_most_one_missing_kind — "≤ 1" pins ─
12174    //
12175    // Boolean cardinality "≤ 1" negation peer of
12176    // `has_multiple_missing_kinds` on the closed-set-complement axis:
12177    // `has_at_most_one_missing_kind()` returns `true` iff AT MOST ONE
12178    // `ConditionKind::ALL` variant appears zero times in the slice.
12179    // Definitional negation of the many-arm primitive
12180    // (`!has_multiple_missing_kinds`), and trichotomy-union of the
12181    // zero-arm + one-arm primitives (`is_kind_saturated ||
12182    // has_unique_missing_kind`). Body short-circuits transitively
12183    // through the many-arm walk — strictly cheaper than
12184    // `missing_kind_count() <= 1` (which walks every slot) and
12185    // `missing_kinds().len() <= 1` (which allocates the Vec) on every
12186    // arm. The composition laws
12187    // `has_at_most_one_missing_kind() == !has_multiple_missing_kinds()`,
12188    // `has_at_most_one_missing_kind() == (missing_kind_count() <= 1)`,
12189    // `has_at_most_one_missing_kind() == (missing_kinds().len() <= 1)`,
12190    // and `has_at_most_one_missing_kind() == is_kind_saturated() ||
12191    // has_unique_missing_kind()` are pinned as the "≤ 1" arm of
12192    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
12193    // of `crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`
12194    // one struct-layer up under the SAME `!has_multiple_missing_kinds`
12195    // definitional negation shape.
12196
12197    /// EMPTY-SLICE pin — an empty slice returns `false` on
12198    /// `has_at_most_one_missing_kind` on any `N ≥ 2` closed set
12199    /// (every kind is missing — `N ≥ 2` missing, not `≤ 1`). Dual of
12200    /// the empty-slice arm on `has_multiple_missing_kinds` which
12201    /// returns `true`.
12202    #[test]
12203    fn condition_slice_has_at_most_one_missing_kind_returns_false_on_empty_slice() {
12204        assert!(
12205            ConditionKind::ALL.len() >= 2,
12206            "test assumes ConditionKind::ALL has ≥ 2 variants",
12207        );
12208        let empty: &[Condition] = &[];
12209        assert!(
12210            !empty.has_at_most_one_missing_kind(),
12211            "empty slice must return false on has_at_most_one_missing_kind (all N ≥ 2 kinds missing, not ≤ 1)",
12212        );
12213        assert_eq!(
12214            empty.has_at_most_one_missing_kind(),
12215            empty.missing_kind_count() <= 1,
12216            "empty has_at_most_one_missing_kind must equal (missing_kind_count() <= 1)",
12217        );
12218    }
12219
12220    /// SINGLE-KIND pin — a slice populating exactly one variant
12221    /// returns `false` on any `N ≥ 3` closed set (`N - 1 ≥ 2` kinds
12222    /// missing, not `≤ 1`). On the degenerate `N == 2` closed set it
12223    /// would return `true` (exactly 1 missing), so the pin gates on
12224    /// `N ≥ 3` — this workspace has `N == 8`.
12225    #[test]
12226    fn condition_slice_has_at_most_one_missing_kind_returns_false_on_single_kind_slice() {
12227        if ConditionKind::ALL.len() < 3 {
12228            return;
12229        }
12230        for populated in ConditionKind::ALL {
12231            let slice = [condition_with(populated)];
12232            assert!(
12233                !slice.has_at_most_one_missing_kind(),
12234                "single-populated slice with {populated:?} must return false on has_at_most_one_missing_kind on N ≥ 3 closed sets ({} kinds missing, not ≤ 1)",
12235                ConditionKind::ALL.len() - 1,
12236            );
12237            assert_eq!(
12238                slice.has_at_most_one_missing_kind(),
12239                slice.missing_kind_count() <= 1,
12240                "single-populated has_at_most_one_missing_kind must equal (missing_kind_count() <= 1) for {populated:?}",
12241            );
12242        }
12243    }
12244
12245    /// NEAR-SATURATION-ENDPOINT pin — a slice carrying every
12246    /// [`ConditionKind`] EXCEPT exactly one returns `true` on
12247    /// `has_at_most_one_missing_kind` (exactly 1 missing, `≤ 1`).
12248    /// The `= 1` mid-endpoint arm of the trichotomy union — one of
12249    /// the two arrangement classes where the "≤ 1" primitive
12250    /// returns `true`. Also pins the widened composition laws
12251    /// `has_at_most_one_missing_kind() == (missing_kinds().len() <= 1)`
12252    /// and `has_at_most_one_missing_kind() == !has_multiple_missing_kinds()`
12253    /// and the trichotomy-union composition law
12254    /// `has_at_most_one_missing_kind() == is_kind_saturated() ||
12255    /// has_unique_missing_kind()`.
12256    #[test]
12257    fn condition_slice_has_at_most_one_missing_kind_returns_true_on_near_saturation_endpoint() {
12258        for omitted in ConditionKind::ALL {
12259            let near_saturated: Vec<Condition> = ConditionKind::ALL
12260                .into_iter()
12261                .filter(|k| *k != omitted)
12262                .map(condition_with)
12263                .collect();
12264            let slice = near_saturated.as_slice();
12265            assert!(
12266                slice.has_at_most_one_missing_kind(),
12267                "near-saturation-endpoint slice (omitting {omitted:?}) must return true on has_at_most_one_missing_kind (1 missing, ≤ 1)",
12268            );
12269            assert_eq!(
12270                slice.has_at_most_one_missing_kind(),
12271                !slice.has_multiple_missing_kinds(),
12272                "near-saturation-endpoint has_at_most_one_missing_kind must equal !has_multiple_missing_kinds() for omitted={omitted:?}",
12273            );
12274            assert_eq!(
12275                slice.has_at_most_one_missing_kind(),
12276                slice.missing_kind_count() <= 1,
12277                "near-saturation-endpoint has_at_most_one_missing_kind must equal (missing_kind_count() <= 1) for omitted={omitted:?}",
12278            );
12279            assert_eq!(
12280                slice.has_at_most_one_missing_kind(),
12281                slice.missing_kinds().len() <= 1,
12282                "near-saturation-endpoint has_at_most_one_missing_kind must equal (missing_kinds().len() <= 1) for omitted={omitted:?}",
12283            );
12284            assert_eq!(
12285                slice.has_at_most_one_missing_kind(),
12286                slice.is_kind_saturated() || slice.has_unique_missing_kind(),
12287                "near-saturation-endpoint has_at_most_one_missing_kind must equal (is_kind_saturated() || has_unique_missing_kind()) for omitted={omitted:?}",
12288            );
12289        }
12290    }
12291
12292    /// SATURATED pin — a slice carrying every [`ConditionKind`]
12293    /// variant returns `true` on `has_at_most_one_missing_kind` (0
12294    /// missing, `≤ 1`). The `= 0` zero-arm of the trichotomy union
12295    /// — the OTHER arrangement class where the "≤ 1" primitive
12296    /// returns `true`. Dual of the SATURATED arm on
12297    /// `has_multiple_missing_kinds` which returns `false`.
12298    #[test]
12299    fn condition_slice_has_at_most_one_missing_kind_returns_true_on_saturated_slice() {
12300        let saturated: Vec<Condition> =
12301            ConditionKind::ALL.into_iter().map(condition_with).collect();
12302        assert!(
12303            saturated.as_slice().has_at_most_one_missing_kind(),
12304            "slice containing every ConditionKind must return true on has_at_most_one_missing_kind (0 missing, ≤ 1)",
12305        );
12306        assert_eq!(
12307            saturated.as_slice().has_at_most_one_missing_kind(),
12308            saturated.as_slice().missing_kind_count() <= 1,
12309            "saturated has_at_most_one_missing_kind must equal (missing_kind_count() <= 1)",
12310        );
12311        assert_eq!(
12312            saturated.as_slice().has_at_most_one_missing_kind(),
12313            saturated.as_slice().is_kind_saturated()
12314                || saturated.as_slice().has_unique_missing_kind(),
12315            "saturated has_at_most_one_missing_kind must equal (is_kind_saturated() || has_unique_missing_kind())",
12316        );
12317    }
12318
12319    /// TWO-MISSING pin — a slice populating exactly `N - 2` variants
12320    /// returns `false` on `has_at_most_one_missing_kind` (exactly 2
12321    /// missing, not `≤ 1`). The SECOND-slot boundary between the
12322    /// "≤ 1" arm and the "≥ 2" arm — a regression that dropped the
12323    /// negation (returning `has_multiple_missing_kinds` itself),
12324    /// swapped the wrong side, or drifted the trichotomy union
12325    /// operator from `||` to `&&` surfaces HERE.
12326    #[test]
12327    fn condition_slice_has_at_most_one_missing_kind_returns_false_on_two_missing_slice() {
12328        assert!(
12329            ConditionKind::ALL.len() >= 2,
12330            "test assumes ConditionKind::ALL has ≥ 2 variants",
12331        );
12332        for i in 0..ConditionKind::ALL.len() {
12333            for j in (i + 1)..ConditionKind::ALL.len() {
12334                let two_missing: Vec<Condition> = ConditionKind::ALL
12335                    .into_iter()
12336                    .enumerate()
12337                    .filter(|(k, _)| *k != i && *k != j)
12338                    .map(|(_, k)| condition_with(k))
12339                    .collect();
12340                let slice = two_missing.as_slice();
12341                assert!(
12342                    !slice.has_at_most_one_missing_kind(),
12343                    "two-missing slice (omitting index {i} and {j}) must return false on has_at_most_one_missing_kind (2 missing, not ≤ 1)",
12344                );
12345                assert_eq!(
12346                    slice.has_at_most_one_missing_kind(),
12347                    slice.missing_kind_count() <= 1,
12348                    "two-missing has_at_most_one_missing_kind must equal (missing_kind_count() <= 1) for omitted=({i}, {j})",
12349                );
12350            }
12351        }
12352    }
12353
12354    /// MULTIPLICITY pin — a slice at a K-populated arm with each
12355    /// populated kind duplicated still returns the same "≤ 1"
12356    /// Boolean as its single-copy peer — multiplicity is irrelevant
12357    /// to the cardinality "≤ 1" projection on the closed-set-
12358    /// complement axis, byte-for-byte peer of
12359    /// `has_multiple_missing_kinds`'s multiplicity behavior.
12360    #[test]
12361    fn condition_slice_has_at_most_one_missing_kind_ignores_multiplicity() {
12362        // Near-saturation arm doubled — every populated kind
12363        // doubled, exactly one variant omitted; still returns true.
12364        for omitted in ConditionKind::ALL {
12365            let mut doubled: Vec<Condition> = Vec::new();
12366            for k in ConditionKind::ALL {
12367                if k != omitted {
12368                    doubled.push(condition_with(k));
12369                    doubled.push(condition_with(k));
12370                }
12371            }
12372            assert!(
12373                doubled.as_slice().has_at_most_one_missing_kind(),
12374                "near-saturation slice (omitting {omitted:?}) with each populated kind duplicated must return true on has_at_most_one_missing_kind",
12375            );
12376        }
12377    }
12378
12379    // ── ConditionSliceExt::lacks_kind — per-kind complement pins ──────
12380    //
12381    // Boolean per-kind closed-set-complement peer of `has_kind`:
12382    // `lacks_kind(k)` returns `true` iff NO Condition in the slice
12383    // carries the addressed kind, byte-for-byte with `!has_kind(k)`
12384    // via the definitional negation in the trait's default body.
12385    // The composition laws `lacks_kind(k) == !has_kind(k)` and
12386    // `lacks_kind(k) == missing_kinds().contains(&k)` are pinned as
12387    // the per-kind-complement arm of
12388    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
12389    // of `crate::tagged_union::TaggedUnion::lacks` one struct-layer up
12390    // under the SAME `!has(kind)` definitional negation shape.
12391
12392    /// EMPTY-SLICE pin — an empty slice returns `true` for every
12393    /// [`ConditionKind`] on `lacks_kind` (no kind appears, so every
12394    /// kind is lacked). Dual of the empty-slice arm on `has_kind`
12395    /// (which returns `false` for every kind). Sweeps
12396    /// [`ConditionKind::ALL`] so a regression that dropped the
12397    /// negation, returned `false` (the has-kind identity on empty),
12398    /// or drifted to a per-kind constant surfaces HERE.
12399    #[test]
12400    fn condition_slice_lacks_kind_returns_true_on_empty_slice_for_every_kind() {
12401        let empty: &[Condition] = &[];
12402        for kind in ConditionKind::ALL {
12403            assert!(
12404                empty.lacks_kind(kind),
12405                "empty slice must return true on lacks_kind for {kind:?}",
12406            );
12407            assert_eq!(
12408                empty.lacks_kind(kind),
12409                !empty.has_kind(kind),
12410                "empty lacks_kind must equal !has_kind for {kind:?}",
12411            );
12412        }
12413    }
12414
12415    /// SINGLE-KIND pin — a slice with EXACTLY ONE `Condition` carrying
12416    /// the addressed kind returns `false` on `lacks_kind` for the
12417    /// populated kind and `true` for every OTHER kind. Sweeps
12418    /// [`ConditionKind::ALL`] × [`ConditionKind::ALL`] so a regression
12419    /// that swapped the wrong side, drifted the negation, or drifted
12420    /// the walk from `has_kind` surfaces HERE. Also pins the
12421    /// composition law `lacks_kind(k) == !has_kind(k)` per-kind.
12422    #[test]
12423    fn condition_slice_lacks_kind_returns_true_on_every_missing_kind() {
12424        for populated in ConditionKind::ALL {
12425            let slice = [condition_with(populated)];
12426            for probe in ConditionKind::ALL {
12427                let expected_lacks = probe != populated;
12428                assert_eq!(
12429                    slice.as_slice().lacks_kind(probe),
12430                    expected_lacks,
12431                    "single-populated slice with {populated:?} must return {expected_lacks} on lacks_kind({probe:?})",
12432                );
12433                assert_eq!(
12434                    slice.as_slice().lacks_kind(probe),
12435                    !slice.as_slice().has_kind(probe),
12436                    "single-populated lacks_kind({probe:?}) must equal !has_kind({probe:?}) for populated={populated:?}",
12437                );
12438            }
12439        }
12440    }
12441
12442    /// SATURATED pin — a slice carrying every [`ConditionKind`] variant
12443    /// returns `false` on `lacks_kind` for every arm (the SOLE
12444    /// arrangement where the primitive returns `false` for every kind).
12445    /// Dual of the SATURATED arm on `is_kind_saturated` which returns
12446    /// `true`. Pins the composition law `lacks_kind(k) ==
12447    /// missing_kinds().contains(&k)` per-kind against the empty missing
12448    /// set.
12449    #[test]
12450    fn condition_slice_lacks_kind_returns_false_on_saturated_slice_for_every_kind() {
12451        let saturated: Vec<Condition> =
12452            ConditionKind::ALL.into_iter().map(condition_with).collect();
12453        let missing = saturated.as_slice().missing_kinds();
12454        for kind in ConditionKind::ALL {
12455            assert!(
12456                !saturated.as_slice().lacks_kind(kind),
12457                "saturated slice must return false on lacks_kind for {kind:?}",
12458            );
12459            assert_eq!(
12460                saturated.as_slice().lacks_kind(kind),
12461                missing.contains(&kind),
12462                "saturated lacks_kind({kind:?}) must equal missing_kinds().contains(&{kind:?})",
12463            );
12464        }
12465    }
12466
12467    /// MULTIPLICITY pin — a slice carrying the addressed kind multiple
12468    /// times still returns `false` on `lacks_kind` for that kind
12469    /// (multiplicity is irrelevant to the per-kind Boolean-complement
12470    /// projection on the closed-set-complement axis, byte-for-byte
12471    /// with `has_kind`'s multiplicity behavior).
12472    #[test]
12473    fn condition_slice_lacks_kind_ignores_multiplicity_on_the_populated_side() {
12474        for populated in ConditionKind::ALL {
12475            let slice = [
12476                condition_with(populated),
12477                condition_with(populated),
12478                condition_with(populated),
12479            ];
12480            assert!(
12481                !slice.as_slice().lacks_kind(populated),
12482                "duplicate-populated slice with {populated:?} must return false on lacks_kind for {populated:?}",
12483            );
12484        }
12485    }
12486
12487    // ── ConditionSliceExt::has_only_kind — kind-scoped strict-refinement pins ─
12488    //
12489    // Boolean `(kind, "AND no other kind")` refinement of the closed-
12490    // set-inversion widened primitive `distinct_kinds`:
12491    // `has_only_kind(k)` returns `true` iff `k` is the SOLE distinct
12492    // populated kind AND appears at least once. Fused-walk over
12493    // `ConditionKind::ALL` under `has_kind` — strictly cheaper than
12494    // reaching for either `has_kind(k) && distinct_kind_count() == 1`
12495    // or `distinct_kinds() == vec![k]` composition on every arm where
12496    // a second kind lives alongside `k`. The composition law
12497    // `has_only_kind(k) == (distinct_kinds() == vec![k])` is pinned
12498    // as the kind-scoped strict-refinement arm of
12499    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
12500    // of `crate::tagged_union::TaggedUnion::has_only` one struct-layer
12501    // up under the SAME fused short-circuit closed-set walk shape.
12502
12503    /// EMPTY-SLICE pin — an empty slice returns `false` on
12504    /// `has_only_kind` for every arm (no kind is populated, so no
12505    /// kind is "only"). Pins the composition law `has_only_kind(k)
12506    /// == (distinct_kinds() == vec![k])` on the zero-distinct
12507    /// arrangement's empty distinct-set: `[] != vec![k]` for every k,
12508    /// so both sides yield `false`.
12509    #[test]
12510    fn condition_slice_has_only_kind_returns_false_on_empty_slice() {
12511        let empty: &[Condition] = &[];
12512        for kind in ConditionKind::ALL {
12513            assert!(
12514                !empty.has_only_kind(kind),
12515                "empty slice must return false on has_only_kind for {kind:?}",
12516            );
12517            assert_eq!(
12518                empty.has_only_kind(kind),
12519                empty.distinct_kinds() == vec![kind],
12520                "empty has_only_kind({kind:?}) must equal (distinct_kinds() == vec![{kind:?}])",
12521            );
12522        }
12523    }
12524
12525    /// SINGLE-KIND pin — a slice with EXACTLY ONE `Condition` carrying
12526    /// the addressed kind returns `true` on `has_only_kind` for the
12527    /// populated kind and `false` for every OTHER kind. Sweeps
12528    /// [`ConditionKind::ALL`] × [`ConditionKind::ALL`] so a regression
12529    /// that swapped the wrong side, drifted the fused walk, or
12530    /// confused the strict-refinement axis with the point-probe axis
12531    /// (returning `has_kind` — TOO LOOSE) surfaces HERE. Also pins the
12532    /// composition law `has_only_kind(k) == (distinct_kinds() ==
12533    /// vec![k])` per-kind against the singleton distinct-set.
12534    #[test]
12535    fn condition_slice_has_only_kind_returns_true_on_single_populated_kind() {
12536        for populated in ConditionKind::ALL {
12537            let slice = [condition_with(populated)];
12538            for probe in ConditionKind::ALL {
12539                let expected = probe == populated;
12540                assert_eq!(
12541                    slice.as_slice().has_only_kind(probe),
12542                    expected,
12543                    "single-populated slice with {populated:?} must return {expected} on has_only_kind({probe:?})",
12544                );
12545                assert_eq!(
12546                    slice.as_slice().has_only_kind(probe),
12547                    slice.as_slice().distinct_kinds() == vec![probe],
12548                    "single-populated has_only_kind({probe:?}) must equal (distinct_kinds() == vec![{probe:?}]) for populated={populated:?}",
12549                );
12550            }
12551        }
12552    }
12553
12554    /// MULTIPLICITY pin — a slice carrying the addressed kind multiple
12555    /// times still returns `true` on `has_only_kind` for that kind
12556    /// (multiplicity is irrelevant to the kind-scoped strict-
12557    /// refinement projection on the closed-set-inversion axis, byte-
12558    /// for-byte with `has_kind`'s multiplicity behavior). Pins that
12559    /// the fused walk under `has_kind` inherits the multiplicity-blind
12560    /// semantics without a special-case on the count.
12561    #[test]
12562    fn condition_slice_has_only_kind_ignores_multiplicity_on_the_populated_side() {
12563        for populated in ConditionKind::ALL {
12564            let slice = [
12565                condition_with(populated),
12566                condition_with(populated),
12567                condition_with(populated),
12568            ];
12569            for probe in ConditionKind::ALL {
12570                let expected = probe == populated;
12571                assert_eq!(
12572                    slice.as_slice().has_only_kind(probe),
12573                    expected,
12574                    "duplicate-populated slice with {populated:?} must return {expected} on has_only_kind({probe:?})",
12575                );
12576            }
12577        }
12578    }
12579
12580    /// TWO-KINDS pin — a slice carrying two DIFFERENT kinds returns
12581    /// `false` on `has_only_kind` for EVERY arm (the "some other kind
12582    /// is present" clause fails at the fused walk's earliest step
12583    /// that hits the second kind, regardless of which kind is
12584    /// addressed). Sweeps [`ConditionKind::ALL`] × [`ConditionKind::ALL`]
12585    /// (skipping equal pairs since a two-distinct-kinds slice requires
12586    /// `p != q`) so a regression that dropped the fused walk's early-
12587    /// exit surfaces at every off-diagonal (p, q) pair.
12588    #[test]
12589    fn condition_slice_has_only_kind_returns_false_on_two_kinds_slice() {
12590        for p in ConditionKind::ALL {
12591            for q in ConditionKind::ALL {
12592                if p == q {
12593                    continue;
12594                }
12595                let slice = [condition_with(p), condition_with(q)];
12596                for probe in ConditionKind::ALL {
12597                    assert!(
12598                        !slice.as_slice().has_only_kind(probe),
12599                        "two-kinds slice with {{{p:?}, {q:?}}} must return false on has_only_kind for {probe:?}",
12600                    );
12601                }
12602            }
12603        }
12604    }
12605
12606    /// SATURATED pin — a slice carrying every [`ConditionKind`] variant
12607    /// returns `false` on `has_only_kind` for every arm (N distinct
12608    /// kinds populate, so no single kind is "only"). Dual of the
12609    /// SATURATED arm on `is_kind_saturated` which returns `true` for
12610    /// the SAME arrangement. Pins the composition law `has_only_kind(k)
12611    /// == (has_kind(k) && distinct_kind_count() == 1)` per-kind against
12612    /// the saturated `distinct_kind_count() == N`.
12613    #[test]
12614    fn condition_slice_has_only_kind_returns_false_on_saturated_slice() {
12615        let saturated: Vec<Condition> =
12616            ConditionKind::ALL.into_iter().map(condition_with).collect();
12617        for kind in ConditionKind::ALL {
12618            assert!(
12619                !saturated.as_slice().has_only_kind(kind),
12620                "saturated slice must return false on has_only_kind for {kind:?}",
12621            );
12622            assert_eq!(
12623                saturated.as_slice().has_only_kind(kind),
12624                saturated.as_slice().has_kind(kind)
12625                    && saturated.as_slice().distinct_kind_count() == 1,
12626                "saturated has_only_kind({kind:?}) must equal (has_kind && distinct_kind_count == 1)",
12627            );
12628        }
12629    }
12630
12631    // ── ConditionSliceExt::lacks_only_kind — kind-scoped strict-
12632    // refinement on the closed-set-complement (missing) axis ─
12633    //
12634    // Byte-for-byte peer of `has_only_kind` under complement: fused
12635    // short-circuit walk over `ConditionKind::ALL` under `has_kind`
12636    // that skips populated slots, returns `false` at the earliest
12637    // missing slot whose kind is NOT `kind`, and returns `true` iff
12638    // the sweep completes with `kind` seen as the sole missing slot.
12639    // The composition laws
12640    // `lacks_only_kind(k) == (missing_kinds() == vec![k])` and
12641    // `lacks_only_kind(k) == (lacks_kind(k) && missing_kind_count() == 1)`
12642    // are pinned as the closed-set-complement kind-scoped strict-
12643    // refinement arms of `assert_slice_refinement_composition_laws`.
12644
12645    /// EMPTY-SLICE pin — every kind is missing (missing set == ALL),
12646    /// so no kind is "only" missing on any `N ≥ 2` closed set. Returns
12647    /// `false` on every arm.
12648    #[test]
12649    fn condition_slice_lacks_only_kind_returns_false_on_empty_slice() {
12650        let empty: &[Condition] = &[];
12651        for kind in ConditionKind::ALL {
12652            assert!(
12653                !empty.lacks_only_kind(kind),
12654                "empty slice must return false on lacks_only_kind for {kind:?}",
12655            );
12656            assert_eq!(
12657                empty.lacks_only_kind(kind),
12658                empty.missing_kinds() == vec![kind],
12659                "empty lacks_only_kind({kind:?}) must equal (missing_kinds() == vec![{kind:?}])",
12660            );
12661        }
12662    }
12663
12664    /// NEAR-SATURATION pin — a slice covering every kind except one
12665    /// returns `true` on `lacks_only_kind(omitted)` and `false` on
12666    /// every other kind. The sole `true` arm on the well-formed
12667    /// missing diagonal.
12668    #[test]
12669    fn condition_slice_lacks_only_kind_returns_true_on_near_saturation_slice() {
12670        for omitted in ConditionKind::ALL {
12671            let slice: Vec<Condition> = ConditionKind::ALL
12672                .into_iter()
12673                .filter(|k| *k != omitted)
12674                .map(condition_with)
12675                .collect();
12676            for kind in ConditionKind::ALL {
12677                let expected = kind == omitted;
12678                assert_eq!(
12679                    slice.as_slice().lacks_only_kind(kind),
12680                    expected,
12681                    "near-saturation slice omitted={omitted:?} must return {expected} on lacks_only_kind for {kind:?}",
12682                );
12683                assert_eq!(
12684                    slice.as_slice().lacks_only_kind(kind),
12685                    slice.as_slice().missing_kinds() == vec![kind],
12686                    "near-saturation lacks_only_kind({kind:?}) must equal (missing_kinds() == vec![{kind:?}]) for omitted={omitted:?}",
12687                );
12688            }
12689        }
12690    }
12691
12692    /// MULTIPLICITY pin — a slice carrying every kind except one, with
12693    /// the populated kinds each duplicated, ignores multiplicity on
12694    /// the populated side (byte-for-byte with `has_kind`'s multiplicity
12695    /// behavior). Returns `true` on `lacks_only_kind(omitted)`.
12696    #[test]
12697    fn condition_slice_lacks_only_kind_ignores_multiplicity_on_the_populated_side() {
12698        for omitted in ConditionKind::ALL {
12699            let mut slice: Vec<Condition> = Vec::new();
12700            for k in ConditionKind::ALL {
12701                if k != omitted {
12702                    slice.push(condition_with(k));
12703                    slice.push(condition_with(k));
12704                }
12705            }
12706            for kind in ConditionKind::ALL {
12707                let expected = kind == omitted;
12708                assert_eq!(
12709                    slice.as_slice().lacks_only_kind(kind),
12710                    expected,
12711                    "duplicate-populated near-saturation slice omitted={omitted:?} must return {expected} on lacks_only_kind for {kind:?}",
12712                );
12713            }
12714        }
12715    }
12716
12717    /// TWO-MISSING pin — a slice omitting exactly two kinds returns
12718    /// `false` on every arm; the strict refinement fails at the
12719    /// earliest walk step that hits the second missing kind. On
12720    /// `ConditionKind::ALL` of cardinality `N`, `N ≥ 3` is required
12721    /// for a two-missing arrangement to exist.
12722    #[test]
12723    fn condition_slice_lacks_only_kind_returns_false_on_two_missing_slice() {
12724        assert!(
12725            ConditionKind::ALL.len() >= 3,
12726            "two-missing arrangement requires N ≥ 3",
12727        );
12728        // Slice carries every kind except the first two of ALL.
12729        let slice: Vec<Condition> = ConditionKind::ALL
12730            .into_iter()
12731            .skip(2)
12732            .map(condition_with)
12733            .collect();
12734        for kind in ConditionKind::ALL {
12735            assert!(
12736                !slice.as_slice().lacks_only_kind(kind),
12737                "two-missing slice must return false on lacks_only_kind for {kind:?}",
12738            );
12739            assert_eq!(
12740                slice.as_slice().lacks_only_kind(kind),
12741                slice.as_slice().missing_kinds() == vec![kind],
12742                "two-missing lacks_only_kind({kind:?}) must equal (missing_kinds() == vec![{kind:?}])",
12743            );
12744        }
12745    }
12746
12747    /// SATURATED pin — every kind populated, no kind missing, no kind
12748    /// is "only" missing. Returns `false` on every arm.
12749    #[test]
12750    fn condition_slice_lacks_only_kind_returns_false_on_saturated_slice() {
12751        let saturated: Vec<Condition> =
12752            ConditionKind::ALL.into_iter().map(condition_with).collect();
12753        for kind in ConditionKind::ALL {
12754            assert!(
12755                !saturated.as_slice().lacks_only_kind(kind),
12756                "saturated slice must return false on lacks_only_kind for {kind:?}",
12757            );
12758            assert_eq!(
12759                saturated.as_slice().lacks_only_kind(kind),
12760                saturated.as_slice().lacks_kind(kind)
12761                    && saturated.as_slice().missing_kind_count() == 1,
12762                "saturated lacks_only_kind({kind:?}) must equal (lacks_kind && missing_kind_count == 1)",
12763            );
12764        }
12765    }
12766
12767    // ── ConditionSliceExt::first_distinct_kind — earliest-element pins ─
12768    //
12769    // Short-circuiting Option<ConditionKind> peer of the closed-set-
12770    // inversion widened primitive `distinct_kinds`: `first_distinct_kind()`
12771    // returns the earliest present kind in canonical ConditionKind::ALL
12772    // order without materializing the intermediate Vec<ConditionKind>.
12773    // The composition law `first_distinct_kind() == distinct_kinds()
12774    // .first().copied()` is pinned as the earliest-element-inversion arm
12775    // of `assert_slice_refinement_composition_laws`.
12776
12777    /// EMPTY-SLICE pin — an empty slice returns `None` on
12778    /// `first_distinct_kind`, byte-for-byte with
12779    /// `distinct_kinds().first().copied()`.
12780    #[test]
12781    fn condition_slice_first_distinct_kind_returns_none_on_empty_slice() {
12782        let empty: &[Condition] = &[];
12783        assert_eq!(
12784            empty.first_distinct_kind(),
12785            None,
12786            "empty slice must return None on first_distinct_kind",
12787        );
12788        assert_eq!(
12789            empty.first_distinct_kind(),
12790            empty.distinct_kinds().first().copied(),
12791            "empty first_distinct_kind must equal distinct_kinds().first().copied()",
12792        );
12793    }
12794
12795    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
12796    /// the addressed kind returns `Some(that_kind)` on
12797    /// `first_distinct_kind`.
12798    #[test]
12799    fn condition_slice_first_distinct_kind_returns_populated_variant() {
12800        for populated in ConditionKind::ALL {
12801            let slice = [condition_with(populated)];
12802            assert_eq!(
12803                slice.first_distinct_kind(),
12804                Some(populated),
12805                "single-populated slice must return Some({populated:?}) on first_distinct_kind",
12806            );
12807            assert_eq!(
12808                slice.first_distinct_kind(),
12809                slice.distinct_kinds().first().copied(),
12810                "single-populated first_distinct_kind must equal distinct_kinds().first().copied() for {populated:?}",
12811            );
12812        }
12813    }
12814
12815    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
12816    /// variant returns `Some(ConditionKind::ALL[0])` on
12817    /// `first_distinct_kind` (the first ALL entry hits at the earliest
12818    /// walk step).
12819    #[test]
12820    fn condition_slice_first_distinct_kind_returns_first_all_on_saturated_slice() {
12821        let saturated: Vec<Condition> =
12822            ConditionKind::ALL.into_iter().map(condition_with).collect();
12823        assert_eq!(
12824            saturated.as_slice().first_distinct_kind(),
12825            Some(ConditionKind::ALL[0]),
12826            "saturated slice must return Some(ConditionKind::ALL[0]) on first_distinct_kind",
12827        );
12828        assert_eq!(
12829            saturated.as_slice().first_distinct_kind(),
12830            saturated.as_slice().distinct_kinds().first().copied(),
12831            "saturated first_distinct_kind must equal distinct_kinds().first().copied()",
12832        );
12833    }
12834
12835    // ── ConditionSliceExt::first_missing_kind — earliest-element pins ──
12836
12837    /// EMPTY-SLICE pin — an empty slice returns
12838    /// `Some(ConditionKind::ALL[0])` on `first_missing_kind` (every
12839    /// kind missing, first hit is index 0). Dual of the empty-slice arm
12840    /// on `first_distinct_kind` which returns `None`.
12841    #[test]
12842    fn condition_slice_first_missing_kind_returns_first_all_on_empty_slice() {
12843        let empty: &[Condition] = &[];
12844        assert_eq!(
12845            empty.first_missing_kind(),
12846            Some(ConditionKind::ALL[0]),
12847            "empty slice must return Some(ConditionKind::ALL[0]) on first_missing_kind",
12848        );
12849        assert_eq!(
12850            empty.first_missing_kind(),
12851            empty.missing_kinds().first().copied(),
12852            "empty first_missing_kind must equal missing_kinds().first().copied()",
12853        );
12854    }
12855
12856    /// PER-VARIANT pin — a slice populating exactly `k` returns
12857    /// `Some(ALL[0])` if `k != ALL[0]`, else `Some(ALL[1])` (the earliest
12858    /// non-`k` entry).
12859    #[test]
12860    fn condition_slice_first_missing_kind_returns_earliest_absent_variant() {
12861        for populated in ConditionKind::ALL {
12862            let slice = [condition_with(populated)];
12863            let expected = ConditionKind::ALL.into_iter().find(|k| *k != populated);
12864            assert_eq!(
12865                slice.first_missing_kind(),
12866                expected,
12867                "single-populated slice must return earliest ALL entry != {populated:?} on first_missing_kind",
12868            );
12869            assert_eq!(
12870                slice.first_missing_kind(),
12871                slice.missing_kinds().first().copied(),
12872                "single-populated first_missing_kind must equal missing_kinds().first().copied() for {populated:?}",
12873            );
12874        }
12875    }
12876
12877    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
12878    /// variant returns `None` on `first_missing_kind` (no kind missing).
12879    #[test]
12880    fn condition_slice_first_missing_kind_returns_none_on_saturated_slice() {
12881        let saturated: Vec<Condition> =
12882            ConditionKind::ALL.into_iter().map(condition_with).collect();
12883        assert_eq!(
12884            saturated.as_slice().first_missing_kind(),
12885            None,
12886            "saturated slice must return None on first_missing_kind",
12887        );
12888        assert_eq!(
12889            saturated.as_slice().first_missing_kind(),
12890            saturated.as_slice().missing_kinds().first().copied(),
12891            "saturated first_missing_kind must equal missing_kinds().first().copied()",
12892        );
12893    }
12894
12895    // ── ConditionSliceExt::last_distinct_kind — latest-element pins ────
12896    //
12897    // Short-circuiting Option<ConditionKind> peer of the closed-set-
12898    // inversion widened primitive `distinct_kinds` on the LATEST-hit
12899    // side: `last_distinct_kind()` returns the latest present kind in
12900    // canonical ConditionKind::ALL order via a REVERSED walk with no
12901    // intermediate Vec<ConditionKind> allocation. The composition law
12902    // `last_distinct_kind() == distinct_kinds().last().copied()` is
12903    // pinned as the latest-element-inversion arm of
12904    // `assert_slice_refinement_composition_laws`.
12905
12906    /// EMPTY-SLICE pin — an empty slice returns `None` on
12907    /// `last_distinct_kind`, byte-for-byte with
12908    /// `distinct_kinds().last().copied()` (both scalar endpoints agree
12909    /// on emptiness).
12910    #[test]
12911    fn condition_slice_last_distinct_kind_returns_none_on_empty_slice() {
12912        let empty: &[Condition] = &[];
12913        assert_eq!(
12914            empty.last_distinct_kind(),
12915            None,
12916            "empty slice must return None on last_distinct_kind",
12917        );
12918        assert_eq!(
12919            empty.last_distinct_kind(),
12920            empty.distinct_kinds().last().copied(),
12921            "empty last_distinct_kind must equal distinct_kinds().last().copied()",
12922        );
12923    }
12924
12925    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
12926    /// the addressed kind returns `Some(that_kind)` on
12927    /// `last_distinct_kind` (single hit; earliest = latest endpoint).
12928    #[test]
12929    fn condition_slice_last_distinct_kind_returns_populated_variant() {
12930        for populated in ConditionKind::ALL {
12931            let slice = [condition_with(populated)];
12932            assert_eq!(
12933                slice.last_distinct_kind(),
12934                Some(populated),
12935                "single-populated slice must return Some({populated:?}) on last_distinct_kind",
12936            );
12937            assert_eq!(
12938                slice.last_distinct_kind(),
12939                slice.distinct_kinds().last().copied(),
12940                "single-populated last_distinct_kind must equal distinct_kinds().last().copied() for {populated:?}",
12941            );
12942            // On single-populated slice both endpoint projections agree.
12943            assert_eq!(
12944                slice.last_distinct_kind(),
12945                slice.first_distinct_kind(),
12946                "single-populated last_distinct_kind must equal first_distinct_kind for {populated:?} (single hit ⇒ earliest = latest)",
12947            );
12948        }
12949    }
12950
12951    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
12952    /// variant returns `Some(*ConditionKind::ALL.last().unwrap())` on
12953    /// `last_distinct_kind` (the last ALL entry hits at the earliest
12954    /// walk step of the REVERSED walk).
12955    #[test]
12956    fn condition_slice_last_distinct_kind_returns_last_all_on_saturated_slice() {
12957        let saturated: Vec<Condition> =
12958            ConditionKind::ALL.into_iter().map(condition_with).collect();
12959        let last_all = ConditionKind::ALL.last().copied();
12960        assert_eq!(
12961            saturated.as_slice().last_distinct_kind(),
12962            last_all,
12963            "saturated slice must return Some(*ConditionKind::ALL.last().unwrap()) on last_distinct_kind",
12964        );
12965        assert_eq!(
12966            saturated.as_slice().last_distinct_kind(),
12967            saturated.as_slice().distinct_kinds().last().copied(),
12968            "saturated last_distinct_kind must equal distinct_kinds().last().copied()",
12969        );
12970    }
12971
12972    // ── ConditionSliceExt::last_missing_kind — latest-element pins ─────
12973
12974    /// EMPTY-SLICE pin — an empty slice returns
12975    /// `Some(*ConditionKind::ALL.last().unwrap())` on `last_missing_kind`
12976    /// (every kind missing, latest hit is the last ALL entry). Dual of
12977    /// the empty-slice arm on `last_distinct_kind` which returns `None`.
12978    #[test]
12979    fn condition_slice_last_missing_kind_returns_last_all_on_empty_slice() {
12980        let empty: &[Condition] = &[];
12981        let last_all = ConditionKind::ALL.last().copied();
12982        assert_eq!(
12983            empty.last_missing_kind(),
12984            last_all,
12985            "empty slice must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_kind",
12986        );
12987        assert_eq!(
12988            empty.last_missing_kind(),
12989            empty.missing_kinds().last().copied(),
12990            "empty last_missing_kind must equal missing_kinds().last().copied()",
12991        );
12992    }
12993
12994    /// PER-VARIANT pin — a slice populating exactly `k` returns
12995    /// `Some(*ALL.last().unwrap())` if `k != ALL.last().unwrap()`, else
12996    /// `Some(ALL[ALL.len() - 2])` (the latest ALL entry != `k`).
12997    #[test]
12998    fn condition_slice_last_missing_kind_returns_latest_absent_variant() {
12999        for populated in ConditionKind::ALL {
13000            let slice = [condition_with(populated)];
13001            let expected = ConditionKind::ALL
13002                .into_iter()
13003                .rev()
13004                .find(|k| *k != populated);
13005            assert_eq!(
13006                slice.last_missing_kind(),
13007                expected,
13008                "single-populated slice must return latest ALL entry != {populated:?} on last_missing_kind",
13009            );
13010            assert_eq!(
13011                slice.last_missing_kind(),
13012                slice.missing_kinds().last().copied(),
13013                "single-populated last_missing_kind must equal missing_kinds().last().copied() for {populated:?}",
13014            );
13015        }
13016    }
13017
13018    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
13019    /// variant returns `None` on `last_missing_kind` (no kind missing).
13020    #[test]
13021    fn condition_slice_last_missing_kind_returns_none_on_saturated_slice() {
13022        let saturated: Vec<Condition> =
13023            ConditionKind::ALL.into_iter().map(condition_with).collect();
13024        assert_eq!(
13025            saturated.as_slice().last_missing_kind(),
13026            None,
13027            "saturated slice must return None on last_missing_kind",
13028        );
13029        assert_eq!(
13030            saturated.as_slice().last_missing_kind(),
13031            saturated.as_slice().missing_kinds().last().copied(),
13032            "saturated last_missing_kind must equal missing_kinds().last().copied()",
13033        );
13034    }
13035
13036    // ── Boundary distinct-set triad — substrate-delegation pins ────────
13037    //
13038    // The (precondition, postcondition, condition-union) distinct-set
13039    // triad on [`Boundary`] delegates to the slice-level substrate
13040    // primitive [`ConditionSliceExt::distinct_kinds`] on each half-slice
13041    // and composes the union via [`Self::has_condition_kind`] over
13042    // [`ConditionKind::ALL`]. The dedicated tests below pin each arm's
13043    // delegation shape; the substrate testkit macro
13044    // `assert_surface_union_composition_laws` (extended in this commit
13045    // with the closed-set-inversion arm) pins the union composition law
13046    // against the two half-slice arms in canonical ALL-order.
13047
13048    /// SUBSTRATE-DELEGATION pin (Boundary distinct-kind-count triad)
13049    /// — the three `distinct_*_kind_count` methods on [`Boundary`]
13050    /// delegate to the slice-level substrate primitive
13051    /// [`ConditionSliceExt::distinct_kind_count`] over the two
13052    /// `Vec<Condition>` slots (precondition + postcondition) and
13053    /// compose the union scalar via
13054    /// `ConditionKind::ALL.filter(|k| has_condition_kind(*k)).count()`.
13055    /// Sweep `ConditionKind::ALL × ConditionKind::ALL` so a regression
13056    /// that (a) inlined a divergent closed-set walk at either half-slice
13057    /// arm, (b) reversed the union walk order, or (c) narrowed the
13058    /// union to an intersection surfaces HERE. Also pins the
13059    /// composition law
13060    /// `distinct_*_kind_count() == distinct_*_kinds().len()` at each
13061    /// arm — a regression that overrode the scalar projection to skip a
13062    /// kind or double-count a slot fails HERE.
13063    #[test]
13064    fn distinct_condition_kind_count_triad_delegates_and_matches_distinct_kinds_len() {
13065        // Empty boundary — every arm returns 0.
13066        let b = Boundary::default();
13067        for kind in ConditionKind::ALL {
13068            assert_eq!(
13069                b.distinct_precondition_kind_count(),
13070                0,
13071                "empty boundary must return 0 on distinct_precondition_kind_count, kind={kind:?}",
13072            );
13073            assert_eq!(
13074                b.distinct_postcondition_kind_count(),
13075                0,
13076                "empty boundary must return 0 on distinct_postcondition_kind_count, kind={kind:?}",
13077            );
13078            assert_eq!(
13079                b.distinct_condition_kind_count(),
13080                0,
13081                "empty boundary must return 0 on distinct_condition_kind_count, kind={kind:?}",
13082            );
13083        }
13084
13085        for pre_kind in ConditionKind::ALL {
13086            for post_kind in ConditionKind::ALL {
13087                let mut b = Boundary::default();
13088                b.preconditions.push(condition_with(pre_kind));
13089                b.postconditions.push(condition_with(post_kind));
13090
13091                assert_eq!(
13092                    b.distinct_precondition_kind_count(),
13093                    b.preconditions.distinct_kind_count(),
13094                    "Boundary::distinct_precondition_kind_count must delegate verbatim to \
13095                     preconditions.distinct_kind_count() for pre={pre_kind:?} post={post_kind:?}",
13096                );
13097                assert_eq!(
13098                    b.distinct_precondition_kind_count(),
13099                    b.distinct_precondition_kinds().len(),
13100                    "Boundary::distinct_precondition_kind_count must equal \
13101                     distinct_precondition_kinds().len() for pre={pre_kind:?} post={post_kind:?}",
13102                );
13103                assert_eq!(
13104                    b.distinct_postcondition_kind_count(),
13105                    b.postconditions.distinct_kind_count(),
13106                    "Boundary::distinct_postcondition_kind_count must delegate verbatim to \
13107                     postconditions.distinct_kind_count() for pre={pre_kind:?} post={post_kind:?}",
13108                );
13109                assert_eq!(
13110                    b.distinct_postcondition_kind_count(),
13111                    b.distinct_postcondition_kinds().len(),
13112                    "Boundary::distinct_postcondition_kind_count must equal \
13113                     distinct_postcondition_kinds().len() for pre={pre_kind:?} post={post_kind:?}",
13114                );
13115                let expected_union_count = if pre_kind == post_kind { 1 } else { 2 };
13116                assert_eq!(
13117                    b.distinct_condition_kind_count(),
13118                    expected_union_count,
13119                    "Boundary::distinct_condition_kind_count must count distinct union kinds \
13120                     for pre={pre_kind:?} post={post_kind:?}",
13121                );
13122                assert_eq!(
13123                    b.distinct_condition_kind_count(),
13124                    b.distinct_condition_kinds().len(),
13125                    "Boundary::distinct_condition_kind_count must equal \
13126                     distinct_condition_kinds().len() for pre={pre_kind:?} post={post_kind:?}",
13127                );
13128            }
13129        }
13130    }
13131
13132    /// SUBSTRATE-DELEGATION pin (Boundary distinct-set triad) — the
13133    /// three `distinct_*_kinds` methods on [`Boundary`] delegate to the
13134    /// slice-level substrate primitive over the two `Vec<Condition>`
13135    /// slots (precondition + postcondition) and compose the union via
13136    /// `ConditionKind::ALL.filter(|k| has_condition_kind(*k))`. Sweep
13137    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
13138    /// (a) inlined a divergent closed-set walk at either half-slice
13139    /// arm, (b) reversed the union walk order, or (c) narrowed the
13140    /// union to an intersection surfaces HERE.
13141    #[test]
13142    fn distinct_condition_kinds_triad_delegates_to_slice_distinct_kinds() {
13143        for pre_kind in ConditionKind::ALL {
13144            for post_kind in ConditionKind::ALL {
13145                let mut b = Boundary::default();
13146                b.preconditions.push(condition_with(pre_kind));
13147                b.postconditions.push(condition_with(post_kind));
13148
13149                assert_eq!(
13150                    b.distinct_precondition_kinds(),
13151                    b.preconditions.distinct_kinds(),
13152                    "Boundary::distinct_precondition_kinds must delegate verbatim to \
13153                     preconditions.distinct_kinds() for pre={pre_kind:?} post={post_kind:?}",
13154                );
13155                assert_eq!(
13156                    b.distinct_postcondition_kinds(),
13157                    b.postconditions.distinct_kinds(),
13158                    "Boundary::distinct_postcondition_kinds must delegate verbatim to \
13159                     postconditions.distinct_kinds() for pre={pre_kind:?} post={post_kind:?}",
13160                );
13161                let expected_union: Vec<_> = ConditionKind::ALL
13162                    .into_iter()
13163                    .filter(|k| pre_kind == *k || post_kind == *k)
13164                    .collect();
13165                assert_eq!(
13166                    b.distinct_condition_kinds(),
13167                    expected_union,
13168                    "Boundary::distinct_condition_kinds must equal ConditionKind::ALL-ordered \
13169                     set-union of the two half-slice distinct-sets for pre={pre_kind:?} post={post_kind:?}",
13170                );
13171            }
13172        }
13173    }
13174
13175    /// SUBSTRATE-DELEGATION pin (Boundary distinct-set ITERATOR triad) —
13176    /// the three `iter_distinct_*_condition_kinds` methods on [`Boundary`]
13177    /// delegate to the slice-level substrate primitive
13178    /// [`ConditionSliceExt::iter_distinct_kinds`] over the two
13179    /// `Vec<Condition>` slots (precondition + postcondition) and compose
13180    /// the union via `ConditionKind::ALL.iter().copied().filter(|&k|
13181    /// has_condition_kind(k))`. Byte-for-byte peer of
13182    /// [`distinct_condition_kinds_triad_delegates_to_slice_distinct_kinds`]
13183    /// on the iterator side — the two tests share ONE closed-set walk
13184    /// semantics and pin the composition law
13185    /// `iter_distinct_*_condition_kinds().collect::<Vec<_>>() ==
13186    /// distinct_*_condition_kinds()` for every arm across
13187    /// `ConditionKind::ALL × ConditionKind::ALL`. A regression that
13188    /// materialized the Vec then re-iterated it (round-trip through the
13189    /// heap), drifted the yield order, or diverged from the widened
13190    /// primitive on any arm surfaces HERE.
13191    #[test]
13192    fn iter_distinct_condition_kinds_triad_delegates_to_slice_iter_distinct_kinds() {
13193        for pre_kind in ConditionKind::ALL {
13194            for post_kind in ConditionKind::ALL {
13195                let mut b = Boundary::default();
13196                b.preconditions.push(condition_with(pre_kind));
13197                b.postconditions.push(condition_with(post_kind));
13198
13199                let pre_via_iter: Vec<_> = b.iter_distinct_precondition_kinds().collect();
13200                let pre_via_vec = b.distinct_precondition_kinds();
13201                assert_eq!(
13202                    pre_via_iter, pre_via_vec,
13203                    "Boundary::iter_distinct_precondition_kinds().collect() drifted from \
13204                     distinct_precondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
13205                );
13206                let post_via_iter: Vec<_> = b.iter_distinct_postcondition_kinds().collect();
13207                let post_via_vec = b.distinct_postcondition_kinds();
13208                assert_eq!(
13209                    post_via_iter, post_via_vec,
13210                    "Boundary::iter_distinct_postcondition_kinds().collect() drifted from \
13211                     distinct_postcondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
13212                );
13213                let union_via_iter: Vec<_> = b.iter_distinct_condition_kinds().collect();
13214                let union_via_vec = b.distinct_condition_kinds();
13215                assert_eq!(
13216                    union_via_iter, union_via_vec,
13217                    "Boundary::iter_distinct_condition_kinds().collect() drifted from \
13218                     distinct_condition_kinds() for pre={pre_kind:?} post={post_kind:?}",
13219                );
13220            }
13221        }
13222    }
13223
13224    /// SUBSTRATE-DELEGATION pin (Boundary missing-set ITERATOR triad) —
13225    /// the three `iter_missing_*_condition_kinds` methods on [`Boundary`]
13226    /// delegate to the slice-level substrate primitive
13227    /// [`ConditionSliceExt::iter_missing_kinds`] over the two
13228    /// `Vec<Condition>` slots (precondition + postcondition) and compose
13229    /// the union via `ConditionKind::ALL.iter().copied().filter(|&k|
13230    /// !has_condition_kind(k))`. Peer of
13231    /// [`iter_distinct_condition_kinds_triad_delegates_to_slice_iter_distinct_kinds`]
13232    /// on the missing side under a NEGATED point-probe.
13233    #[test]
13234    fn iter_missing_condition_kinds_triad_delegates_to_slice_iter_missing_kinds() {
13235        // Empty boundary — every iter arm yields ConditionKind::ALL.
13236        let b = Boundary::default();
13237        let all: Vec<_> = ConditionKind::ALL.to_vec();
13238        assert_eq!(
13239            b.iter_missing_precondition_kinds().collect::<Vec<_>>(),
13240            all,
13241            "empty boundary must yield ConditionKind::ALL on iter_missing_precondition_kinds",
13242        );
13243        assert_eq!(
13244            b.iter_missing_postcondition_kinds().collect::<Vec<_>>(),
13245            all,
13246            "empty boundary must yield ConditionKind::ALL on iter_missing_postcondition_kinds",
13247        );
13248        assert_eq!(
13249            b.iter_missing_condition_kinds().collect::<Vec<_>>(),
13250            all,
13251            "empty boundary must yield ConditionKind::ALL on iter_missing_condition_kinds",
13252        );
13253
13254        for pre_kind in ConditionKind::ALL {
13255            for post_kind in ConditionKind::ALL {
13256                let mut b = Boundary::default();
13257                b.preconditions.push(condition_with(pre_kind));
13258                b.postconditions.push(condition_with(post_kind));
13259
13260                let pre_via_iter: Vec<_> = b.iter_missing_precondition_kinds().collect();
13261                let pre_via_vec = b.missing_precondition_kinds();
13262                assert_eq!(
13263                    pre_via_iter, pre_via_vec,
13264                    "Boundary::iter_missing_precondition_kinds().collect() drifted from \
13265                     missing_precondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
13266                );
13267                let post_via_iter: Vec<_> = b.iter_missing_postcondition_kinds().collect();
13268                let post_via_vec = b.missing_postcondition_kinds();
13269                assert_eq!(
13270                    post_via_iter, post_via_vec,
13271                    "Boundary::iter_missing_postcondition_kinds().collect() drifted from \
13272                     missing_postcondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
13273                );
13274                let union_via_iter: Vec<_> = b.iter_missing_condition_kinds().collect();
13275                let union_via_vec = b.missing_condition_kinds();
13276                assert_eq!(
13277                    union_via_iter, union_via_vec,
13278                    "Boundary::iter_missing_condition_kinds().collect() drifted from \
13279                     missing_condition_kinds() for pre={pre_kind:?} post={post_kind:?}",
13280                );
13281            }
13282        }
13283    }
13284
13285    /// SUBSTRATE-DELEGATION pin (Boundary missing-set triad) — the
13286    /// three `missing_*_kinds` methods on [`Boundary`] delegate to the
13287    /// slice-level substrate primitive
13288    /// [`ConditionSliceExt::missing_kinds`] over the two
13289    /// `Vec<Condition>` slots (precondition + postcondition) and
13290    /// compose the union via
13291    /// `ConditionKind::ALL.filter(|k| !has_condition_kind(*k))`. Sweep
13292    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
13293    /// (a) inlined a divergent closed-set walk at either half-slice
13294    /// arm, (b) reversed the union walk order, (c) widened the union
13295    /// intersection to a union (a `||` inlined where `&&` is required
13296    /// on the missing side), or (d) forgot the negation surfaces HERE.
13297    /// Also pins the empty-boundary edge case: every arm returns
13298    /// `ConditionKind::ALL.to_vec()` on an empty boundary.
13299    #[test]
13300    fn missing_condition_kinds_triad_delegates_to_slice_missing_kinds() {
13301        // Empty boundary — every arm returns ConditionKind::ALL (nothing
13302        // is populated, so every kind is missing on all three slots).
13303        let b = Boundary::default();
13304        let all_kinds = ConditionKind::ALL.to_vec();
13305        assert_eq!(
13306            b.missing_precondition_kinds(),
13307            all_kinds,
13308            "empty boundary must return ConditionKind::ALL on missing_precondition_kinds",
13309        );
13310        assert_eq!(
13311            b.missing_postcondition_kinds(),
13312            all_kinds,
13313            "empty boundary must return ConditionKind::ALL on missing_postcondition_kinds",
13314        );
13315        assert_eq!(
13316            b.missing_condition_kinds(),
13317            all_kinds,
13318            "empty boundary must return ConditionKind::ALL on missing_condition_kinds",
13319        );
13320
13321        for pre_kind in ConditionKind::ALL {
13322            for post_kind in ConditionKind::ALL {
13323                let mut b = Boundary::default();
13324                b.preconditions.push(condition_with(pre_kind));
13325                b.postconditions.push(condition_with(post_kind));
13326
13327                assert_eq!(
13328                    b.missing_precondition_kinds(),
13329                    b.preconditions.missing_kinds(),
13330                    "Boundary::missing_precondition_kinds must delegate verbatim to \
13331                     preconditions.missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
13332                );
13333                assert_eq!(
13334                    b.missing_postcondition_kinds(),
13335                    b.postconditions.missing_kinds(),
13336                    "Boundary::missing_postcondition_kinds must delegate verbatim to \
13337                     postconditions.missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
13338                );
13339                // Union: a kind is missing from the union iff it is
13340                // missing from BOTH half-slices (SET-INTERSECTION).
13341                let expected_union: Vec<_> = ConditionKind::ALL
13342                    .into_iter()
13343                    .filter(|k| pre_kind != *k && post_kind != *k)
13344                    .collect();
13345                assert_eq!(
13346                    b.missing_condition_kinds(),
13347                    expected_union,
13348                    "Boundary::missing_condition_kinds must equal ConditionKind::ALL-ordered \
13349                     set-INTERSECTION of the two half-slice missing-sets for pre={pre_kind:?} post={post_kind:?}",
13350                );
13351                // Partition invariant: distinct ∪ missing == ALL, disjoint.
13352                let distinct = b.distinct_condition_kinds();
13353                let missing = b.missing_condition_kinds();
13354                for kind in ConditionKind::ALL {
13355                    assert!(
13356                        distinct.contains(&kind) ^ missing.contains(&kind),
13357                        "(distinct, missing) partition violated on {kind:?} for pre={pre_kind:?} post={post_kind:?}",
13358                    );
13359                }
13360                assert_eq!(
13361                    distinct.len() + missing.len(),
13362                    ConditionKind::ALL.len(),
13363                    "Boundary (distinct, missing) cardinality partition drift for pre={pre_kind:?} post={post_kind:?}",
13364                );
13365            }
13366        }
13367    }
13368
13369    /// SUBSTRATE-DELEGATION pin (Boundary missing-kind-count triad) —
13370    /// the three `missing_*_kind_count` methods on [`Boundary`] delegate
13371    /// to the slice-level substrate primitive
13372    /// [`ConditionSliceExt::missing_kind_count`] over the two
13373    /// `Vec<Condition>` slots (precondition + postcondition) and
13374    /// compose the union via
13375    /// `ConditionKind::ALL.iter().filter(|k|
13376    /// !self.has_condition_kind(**k)).count()`. Sweep
13377    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
13378    /// (a) inlined a divergent negated closed-set walk at either half-
13379    /// slice arm, (b) dropped the negation on the union arm, or (c)
13380    /// drifted from the widened-primitive length surfaces HERE. Also
13381    /// pins the scalar-partition invariant
13382    /// `distinct_kind_count + missing_kind_count == ConditionKind::ALL.len()`
13383    /// per arrangement.
13384    #[test]
13385    fn missing_condition_kind_count_triad_delegates_to_slice_missing_kind_count() {
13386        // Empty boundary — every arm returns ConditionKind::ALL.len()
13387        // (nothing is populated, so every kind is missing on all three
13388        // slots).
13389        let b = Boundary::default();
13390        let total = ConditionKind::ALL.len();
13391        assert_eq!(
13392            b.missing_precondition_kind_count(),
13393            total,
13394            "empty boundary must return ConditionKind::ALL.len() on missing_precondition_kind_count",
13395        );
13396        assert_eq!(
13397            b.missing_postcondition_kind_count(),
13398            total,
13399            "empty boundary must return ConditionKind::ALL.len() on missing_postcondition_kind_count",
13400        );
13401        assert_eq!(
13402            b.missing_condition_kind_count(),
13403            total,
13404            "empty boundary must return ConditionKind::ALL.len() on missing_condition_kind_count",
13405        );
13406
13407        for pre_kind in ConditionKind::ALL {
13408            for post_kind in ConditionKind::ALL {
13409                let mut b = Boundary::default();
13410                b.preconditions.push(condition_with(pre_kind));
13411                b.postconditions.push(condition_with(post_kind));
13412
13413                // Half-slice arms delegate byte-for-byte to the slice
13414                // substrate primitive.
13415                assert_eq!(
13416                    b.missing_precondition_kind_count(),
13417                    b.preconditions.missing_kind_count(),
13418                    "Boundary::missing_precondition_kind_count must delegate verbatim to \
13419                     preconditions.missing_kind_count() for pre={pre_kind:?} post={post_kind:?}",
13420                );
13421                assert_eq!(
13422                    b.missing_postcondition_kind_count(),
13423                    b.postconditions.missing_kind_count(),
13424                    "Boundary::missing_postcondition_kind_count must delegate verbatim to \
13425                     postconditions.missing_kind_count() for pre={pre_kind:?} post={post_kind:?}",
13426                );
13427                // Union arm equals missing_condition_kinds().len() — the
13428                // scalar cardinality of the two-slice intersection.
13429                assert_eq!(
13430                    b.missing_condition_kind_count(),
13431                    b.missing_condition_kinds().len(),
13432                    "Boundary::missing_condition_kind_count must equal missing_condition_kinds().len() \
13433                     for pre={pre_kind:?} post={post_kind:?}",
13434                );
13435                // Scalar-partition invariant: distinct + missing == ALL.
13436                assert_eq!(
13437                    b.distinct_condition_kind_count() + b.missing_condition_kind_count(),
13438                    ConditionKind::ALL.len(),
13439                    "Boundary (distinct, missing) scalar partition drift for pre={pre_kind:?} post={post_kind:?}",
13440                );
13441            }
13442        }
13443    }
13444
13445    /// SUBSTRATE-DELEGATION pin (Boundary first-distinct-kind triad) —
13446    /// the three `first_distinct_*_kind` methods on [`Boundary`]
13447    /// delegate to the slice-level substrate primitive
13448    /// [`ConditionSliceExt::first_distinct_kind`] over the two
13449    /// `Vec<Condition>` slots (precondition + postcondition) and
13450    /// compose the union via `ConditionKind::ALL.iter().copied()
13451    /// .find(|k| has_condition_kind(*k))`. Sweep
13452    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
13453    /// inlined a divergent short-circuit walk at either half-slice arm,
13454    /// reversed the walk order, or dropped the short-circuit surfaces
13455    /// HERE. Also pins the composition law `first_distinct_*_kind() ==
13456    /// distinct_*_kinds().first().copied()` at each arm.
13457    #[test]
13458    fn first_distinct_condition_kind_triad_delegates_to_slice_first_distinct_kind() {
13459        // Empty boundary — every arm returns None.
13460        let b = Boundary::default();
13461        assert_eq!(
13462            b.first_distinct_precondition_kind(),
13463            None,
13464            "empty boundary must return None on first_distinct_precondition_kind",
13465        );
13466        assert_eq!(
13467            b.first_distinct_postcondition_kind(),
13468            None,
13469            "empty boundary must return None on first_distinct_postcondition_kind",
13470        );
13471        assert_eq!(
13472            b.first_distinct_condition_kind(),
13473            None,
13474            "empty boundary must return None on first_distinct_condition_kind",
13475        );
13476
13477        for pre_kind in ConditionKind::ALL {
13478            for post_kind in ConditionKind::ALL {
13479                let mut b = Boundary::default();
13480                b.preconditions.push(condition_with(pre_kind));
13481                b.postconditions.push(condition_with(post_kind));
13482
13483                assert_eq!(
13484                    b.first_distinct_precondition_kind(),
13485                    b.preconditions.first_distinct_kind(),
13486                    "Boundary::first_distinct_precondition_kind must delegate verbatim to \
13487                     preconditions.first_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
13488                );
13489                assert_eq!(
13490                    b.first_distinct_precondition_kind(),
13491                    b.distinct_precondition_kinds().first().copied(),
13492                    "Boundary::first_distinct_precondition_kind must equal \
13493                     distinct_precondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
13494                );
13495                assert_eq!(
13496                    b.first_distinct_postcondition_kind(),
13497                    b.postconditions.first_distinct_kind(),
13498                    "Boundary::first_distinct_postcondition_kind must delegate verbatim to \
13499                     postconditions.first_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
13500                );
13501                assert_eq!(
13502                    b.first_distinct_postcondition_kind(),
13503                    b.distinct_postcondition_kinds().first().copied(),
13504                    "Boundary::first_distinct_postcondition_kind must equal \
13505                     distinct_postcondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
13506                );
13507                let expected_union = ConditionKind::ALL
13508                    .into_iter()
13509                    .find(|k| pre_kind == *k || post_kind == *k);
13510                assert_eq!(
13511                    b.first_distinct_condition_kind(),
13512                    expected_union,
13513                    "Boundary::first_distinct_condition_kind must equal earliest ALL entry \
13514                     populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
13515                );
13516                assert_eq!(
13517                    b.first_distinct_condition_kind(),
13518                    b.distinct_condition_kinds().first().copied(),
13519                    "Boundary::first_distinct_condition_kind must equal \
13520                     distinct_condition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
13521                );
13522            }
13523        }
13524    }
13525
13526    /// SUBSTRATE-DELEGATION pin (Boundary first-missing-kind triad) —
13527    /// the three `first_missing_*_kind` methods on [`Boundary`]
13528    /// delegate to the slice-level substrate primitive
13529    /// [`ConditionSliceExt::first_missing_kind`] over the two
13530    /// `Vec<Condition>` slots (precondition + postcondition) and
13531    /// compose the union via `ConditionKind::ALL.iter().copied()
13532    /// .find(|k| !has_condition_kind(*k))`. Sweep
13533    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
13534    /// dropped the negation or drifted the short-circuit walk surfaces
13535    /// HERE. Also pins the composition law `first_missing_*_kind() ==
13536    /// missing_*_kinds().first().copied()` at each arm.
13537    #[test]
13538    fn first_missing_condition_kind_triad_delegates_to_slice_first_missing_kind() {
13539        // Empty boundary — every arm returns Some(ConditionKind::ALL[0]).
13540        let b = Boundary::default();
13541        let first = Some(ConditionKind::ALL[0]);
13542        assert_eq!(
13543            b.first_missing_precondition_kind(),
13544            first,
13545            "empty boundary must return Some(ConditionKind::ALL[0]) on first_missing_precondition_kind",
13546        );
13547        assert_eq!(
13548            b.first_missing_postcondition_kind(),
13549            first,
13550            "empty boundary must return Some(ConditionKind::ALL[0]) on first_missing_postcondition_kind",
13551        );
13552        assert_eq!(
13553            b.first_missing_condition_kind(),
13554            first,
13555            "empty boundary must return Some(ConditionKind::ALL[0]) on first_missing_condition_kind",
13556        );
13557
13558        for pre_kind in ConditionKind::ALL {
13559            for post_kind in ConditionKind::ALL {
13560                let mut b = Boundary::default();
13561                b.preconditions.push(condition_with(pre_kind));
13562                b.postconditions.push(condition_with(post_kind));
13563
13564                assert_eq!(
13565                    b.first_missing_precondition_kind(),
13566                    b.preconditions.first_missing_kind(),
13567                    "Boundary::first_missing_precondition_kind must delegate verbatim to \
13568                     preconditions.first_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
13569                );
13570                assert_eq!(
13571                    b.first_missing_precondition_kind(),
13572                    b.missing_precondition_kinds().first().copied(),
13573                    "Boundary::first_missing_precondition_kind must equal \
13574                     missing_precondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
13575                );
13576                assert_eq!(
13577                    b.first_missing_postcondition_kind(),
13578                    b.postconditions.first_missing_kind(),
13579                    "Boundary::first_missing_postcondition_kind must delegate verbatim to \
13580                     postconditions.first_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
13581                );
13582                assert_eq!(
13583                    b.first_missing_postcondition_kind(),
13584                    b.missing_postcondition_kinds().first().copied(),
13585                    "Boundary::first_missing_postcondition_kind must equal \
13586                     missing_postcondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
13587                );
13588                let expected_union = ConditionKind::ALL
13589                    .into_iter()
13590                    .find(|k| pre_kind != *k && post_kind != *k);
13591                assert_eq!(
13592                    b.first_missing_condition_kind(),
13593                    expected_union,
13594                    "Boundary::first_missing_condition_kind must equal earliest ALL entry \
13595                     NOT populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
13596                );
13597                assert_eq!(
13598                    b.first_missing_condition_kind(),
13599                    b.missing_condition_kinds().first().copied(),
13600                    "Boundary::first_missing_condition_kind must equal \
13601                     missing_condition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
13602                );
13603            }
13604        }
13605    }
13606
13607    /// SUBSTRATE-DELEGATION pin (Boundary last-distinct-kind triad)
13608    /// — the three `last_distinct_*_kind` methods on [`Boundary`]
13609    /// delegate to the slice-level substrate primitive
13610    /// [`ConditionSliceExt::last_distinct_kind`] over the two
13611    /// `Vec<Condition>` slots (precondition + postcondition) and
13612    /// compose the union via `ConditionKind::ALL.iter().rev().copied()
13613    /// .find(|k| has_condition_kind(*k))`. Sweep
13614    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
13615    /// (a) forgot to reverse the walk (returning `first_distinct_*_kind`),
13616    /// (b) inlined a divergent closed-set walk at either half-slice
13617    /// arm, or (c) narrowed the union to an intersection surfaces
13618    /// HERE. Also pins the composition law `last_distinct_*_kind() ==
13619    /// distinct_*_kinds().last().copied()` at each arm.
13620    #[test]
13621    fn last_distinct_condition_kind_triad_delegates_to_slice_last_distinct_kind() {
13622        // Empty boundary — every arm returns None.
13623        let b = Boundary::default();
13624        assert_eq!(
13625            b.last_distinct_precondition_kind(),
13626            None,
13627            "empty boundary must return None on last_distinct_precondition_kind",
13628        );
13629        assert_eq!(
13630            b.last_distinct_postcondition_kind(),
13631            None,
13632            "empty boundary must return None on last_distinct_postcondition_kind",
13633        );
13634        assert_eq!(
13635            b.last_distinct_condition_kind(),
13636            None,
13637            "empty boundary must return None on last_distinct_condition_kind",
13638        );
13639
13640        for pre_kind in ConditionKind::ALL {
13641            for post_kind in ConditionKind::ALL {
13642                let mut b = Boundary::default();
13643                b.preconditions.push(condition_with(pre_kind));
13644                b.postconditions.push(condition_with(post_kind));
13645
13646                assert_eq!(
13647                    b.last_distinct_precondition_kind(),
13648                    b.preconditions.last_distinct_kind(),
13649                    "Boundary::last_distinct_precondition_kind must delegate verbatim to \
13650                     preconditions.last_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
13651                );
13652                assert_eq!(
13653                    b.last_distinct_precondition_kind(),
13654                    b.distinct_precondition_kinds().last().copied(),
13655                    "Boundary::last_distinct_precondition_kind must equal \
13656                     distinct_precondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
13657                );
13658                assert_eq!(
13659                    b.last_distinct_postcondition_kind(),
13660                    b.postconditions.last_distinct_kind(),
13661                    "Boundary::last_distinct_postcondition_kind must delegate verbatim to \
13662                     postconditions.last_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
13663                );
13664                assert_eq!(
13665                    b.last_distinct_postcondition_kind(),
13666                    b.distinct_postcondition_kinds().last().copied(),
13667                    "Boundary::last_distinct_postcondition_kind must equal \
13668                     distinct_postcondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
13669                );
13670                let expected_union = ConditionKind::ALL
13671                    .into_iter()
13672                    .rev()
13673                    .find(|k| pre_kind == *k || post_kind == *k);
13674                assert_eq!(
13675                    b.last_distinct_condition_kind(),
13676                    expected_union,
13677                    "Boundary::last_distinct_condition_kind must equal latest ALL entry \
13678                     populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
13679                );
13680                assert_eq!(
13681                    b.last_distinct_condition_kind(),
13682                    b.distinct_condition_kinds().last().copied(),
13683                    "Boundary::last_distinct_condition_kind must equal \
13684                     distinct_condition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
13685                );
13686            }
13687        }
13688    }
13689
13690    /// SUBSTRATE-DELEGATION pin (Boundary last-missing-kind triad) —
13691    /// the three `last_missing_*_kind` methods on [`Boundary`]
13692    /// delegate to the slice-level substrate primitive
13693    /// [`ConditionSliceExt::last_missing_kind`] over the two
13694    /// `Vec<Condition>` slots (precondition + postcondition) and
13695    /// compose the union via `ConditionKind::ALL.iter().rev().copied()
13696    /// .find(|k| !has_condition_kind(*k))`. Sweep
13697    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
13698    /// dropped the negation or forgot the reversed short-circuit walk
13699    /// surfaces HERE. Also pins the composition law `last_missing_*_kind()
13700    /// == missing_*_kinds().last().copied()` at each arm.
13701    #[test]
13702    fn last_missing_condition_kind_triad_delegates_to_slice_last_missing_kind() {
13703        // Empty boundary — every arm returns Some(*ConditionKind::ALL.last().unwrap()).
13704        let b = Boundary::default();
13705        let last = ConditionKind::ALL.last().copied();
13706        assert_eq!(
13707            b.last_missing_precondition_kind(),
13708            last,
13709            "empty boundary must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_precondition_kind",
13710        );
13711        assert_eq!(
13712            b.last_missing_postcondition_kind(),
13713            last,
13714            "empty boundary must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_postcondition_kind",
13715        );
13716        assert_eq!(
13717            b.last_missing_condition_kind(),
13718            last,
13719            "empty boundary must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_condition_kind",
13720        );
13721
13722        for pre_kind in ConditionKind::ALL {
13723            for post_kind in ConditionKind::ALL {
13724                let mut b = Boundary::default();
13725                b.preconditions.push(condition_with(pre_kind));
13726                b.postconditions.push(condition_with(post_kind));
13727
13728                assert_eq!(
13729                    b.last_missing_precondition_kind(),
13730                    b.preconditions.last_missing_kind(),
13731                    "Boundary::last_missing_precondition_kind must delegate verbatim to \
13732                     preconditions.last_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
13733                );
13734                assert_eq!(
13735                    b.last_missing_precondition_kind(),
13736                    b.missing_precondition_kinds().last().copied(),
13737                    "Boundary::last_missing_precondition_kind must equal \
13738                     missing_precondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
13739                );
13740                assert_eq!(
13741                    b.last_missing_postcondition_kind(),
13742                    b.postconditions.last_missing_kind(),
13743                    "Boundary::last_missing_postcondition_kind must delegate verbatim to \
13744                     postconditions.last_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
13745                );
13746                assert_eq!(
13747                    b.last_missing_postcondition_kind(),
13748                    b.missing_postcondition_kinds().last().copied(),
13749                    "Boundary::last_missing_postcondition_kind must equal \
13750                     missing_postcondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
13751                );
13752                let expected_union = ConditionKind::ALL
13753                    .into_iter()
13754                    .rev()
13755                    .find(|k| pre_kind != *k && post_kind != *k);
13756                assert_eq!(
13757                    b.last_missing_condition_kind(),
13758                    expected_union,
13759                    "Boundary::last_missing_condition_kind must equal latest ALL entry \
13760                     NOT populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
13761                );
13762                assert_eq!(
13763                    b.last_missing_condition_kind(),
13764                    b.missing_condition_kinds().last().copied(),
13765                    "Boundary::last_missing_condition_kind must equal \
13766                     missing_condition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
13767                );
13768            }
13769        }
13770    }
13771
13772    /// SUBSTRATE-DELEGATION pin (Boundary saturation-predicate triad)
13773    /// — the three `is_*_kind_saturated` methods on [`Boundary`]
13774    /// delegate to the slice-level substrate primitive
13775    /// [`ConditionSliceExt::is_kind_saturated`] over the two
13776    /// `Vec<Condition>` slots (precondition + postcondition) and
13777    /// compose the union via `ConditionKind::ALL.iter().all(|k|
13778    /// has_condition_kind(*k))`. Sweeps the empty boundary (every arm
13779    /// returns `false`), a single-populated-per-side arrangement (both
13780    /// per-slice arms return `false` on any `N ≥ 2` closed set; the
13781    /// union returns `false` unless the two kinds are distinct AND
13782    /// `N == 2`), and the saturated boundary (both slices carry every
13783    /// [`ConditionKind`], every arm returns `true`). Also pins the
13784    /// composition law `is_*_kind_saturated() ==
13785    /// missing_*_kinds().is_empty()` at each arm — a regression that
13786    /// dropped the `all` short-circuit, drifted the walk from
13787    /// `ConditionKind::ALL`, or negated the wrong side surfaces HERE.
13788    #[test]
13789    fn is_condition_kind_saturated_triad_delegates_to_slice_is_kind_saturated() {
13790        // Empty boundary — every arm returns false; missing_*_kinds
13791        // covers the full closed set on every arm.
13792        let b = Boundary::default();
13793        assert!(
13794            !b.is_precondition_kind_saturated(),
13795            "empty boundary must return false on is_precondition_kind_saturated",
13796        );
13797        assert!(
13798            !b.is_postcondition_kind_saturated(),
13799            "empty boundary must return false on is_postcondition_kind_saturated",
13800        );
13801        assert!(
13802            !b.is_condition_kind_saturated(),
13803            "empty boundary must return false on is_condition_kind_saturated",
13804        );
13805        assert_eq!(
13806            b.is_precondition_kind_saturated(),
13807            b.missing_precondition_kinds().is_empty(),
13808            "empty is_precondition_kind_saturated must equal missing_precondition_kinds().is_empty()",
13809        );
13810
13811        // Single-populated per side — every per-slice arm returns
13812        // false on any N ≥ 2 closed set; the union returns false too
13813        // (needs every ALL kind covered).
13814        for pre_kind in ConditionKind::ALL {
13815            for post_kind in ConditionKind::ALL {
13816                let mut b = Boundary::default();
13817                b.preconditions.push(condition_with(pre_kind));
13818                b.postconditions.push(condition_with(post_kind));
13819                assert_eq!(
13820                    b.is_precondition_kind_saturated(),
13821                    b.preconditions.is_kind_saturated(),
13822                    "Boundary::is_precondition_kind_saturated must delegate verbatim to \
13823                     preconditions.is_kind_saturated() for pre={pre_kind:?} post={post_kind:?}",
13824                );
13825                assert_eq!(
13826                    b.is_postcondition_kind_saturated(),
13827                    b.postconditions.is_kind_saturated(),
13828                    "Boundary::is_postcondition_kind_saturated must delegate verbatim to \
13829                     postconditions.is_kind_saturated() for pre={pre_kind:?} post={post_kind:?}",
13830                );
13831                let expected_union = ConditionKind::ALL
13832                    .iter()
13833                    .all(|k| pre_kind == *k || post_kind == *k);
13834                assert_eq!(
13835                    b.is_condition_kind_saturated(),
13836                    expected_union,
13837                    "Boundary::is_condition_kind_saturated must equal all-ALL-covered-by-either-slice \
13838                     for pre={pre_kind:?} post={post_kind:?}",
13839                );
13840                assert_eq!(
13841                    b.is_condition_kind_saturated(),
13842                    b.missing_condition_kinds().is_empty(),
13843                    "Boundary::is_condition_kind_saturated must equal missing_condition_kinds().is_empty() \
13844                     for pre={pre_kind:?} post={post_kind:?}",
13845                );
13846            }
13847        }
13848
13849        // Saturated boundary — both slices carry every ConditionKind
13850        // at least once, every arm returns true.
13851        let mut b = Boundary::default();
13852        for k in ConditionKind::ALL {
13853            b.preconditions.push(condition_with(k));
13854            b.postconditions.push(condition_with(k));
13855        }
13856        assert!(
13857            b.is_precondition_kind_saturated(),
13858            "saturated boundary must return true on is_precondition_kind_saturated",
13859        );
13860        assert!(
13861            b.is_postcondition_kind_saturated(),
13862            "saturated boundary must return true on is_postcondition_kind_saturated",
13863        );
13864        assert!(
13865            b.is_condition_kind_saturated(),
13866            "saturated boundary must return true on is_condition_kind_saturated",
13867        );
13868    }
13869
13870    /// SUBSTRATE-DELEGATION pin (Boundary at-least-one halfspace
13871    /// triad) — the three `has_any_missing_*_condition_kind` methods
13872    /// on [`Boundary`] delegate to the slice-level substrate primitive
13873    /// [`ConditionSliceExt::has_any_missing_kind`] over the two
13874    /// `Vec<Condition>` slots (precondition + postcondition) and
13875    /// compose the union via `!self.is_condition_kind_saturated()`.
13876    /// Sweeps the empty boundary (every arm returns `true`), a single-
13877    /// populated-per-side arrangement (both per-slice arms return
13878    /// `true` on any `N ≥ 2` closed set; the union returns `true`
13879    /// unless the two kinds together cover every ALL variant), and
13880    /// the saturated boundary (both slices carry every
13881    /// [`ConditionKind`], every arm returns `false`). Also pins the
13882    /// composition law `has_any_missing_*_condition_kind() ==
13883    /// !is_*_condition_kind_saturated()` at each arm — a regression
13884    /// that dropped the negation, drifted the underlying saturation
13885    /// primitive, or negated the wrong side surfaces HERE.
13886    #[test]
13887    fn has_any_missing_condition_kind_triad_delegates_to_slice_has_any_missing_kind() {
13888        // Empty boundary — every arm returns true (every kind is
13889        // missing from every slice + from the union).
13890        let b = Boundary::default();
13891        assert!(
13892            b.has_any_missing_precondition_kind(),
13893            "empty boundary must return true on has_any_missing_precondition_kind",
13894        );
13895        assert!(
13896            b.has_any_missing_postcondition_kind(),
13897            "empty boundary must return true on has_any_missing_postcondition_kind",
13898        );
13899        assert!(
13900            b.has_any_missing_condition_kind(),
13901            "empty boundary must return true on has_any_missing_condition_kind",
13902        );
13903        assert_eq!(
13904            b.has_any_missing_condition_kind(),
13905            !b.is_condition_kind_saturated(),
13906            "empty has_any_missing_condition_kind must equal !is_condition_kind_saturated()",
13907        );
13908
13909        // Single-populated per side — sweep ALL × ALL. Every per-slice
13910        // arm returns true on any N ≥ 2 closed set; the union returns
13911        // true unless the two kinds together cover every ALL variant.
13912        for pre_kind in ConditionKind::ALL {
13913            for post_kind in ConditionKind::ALL {
13914                let mut b = Boundary::default();
13915                b.preconditions.push(condition_with(pre_kind));
13916                b.postconditions.push(condition_with(post_kind));
13917                assert_eq!(
13918                    b.has_any_missing_precondition_kind(),
13919                    b.preconditions.has_any_missing_kind(),
13920                    "Boundary::has_any_missing_precondition_kind must delegate verbatim to \
13921                     preconditions.has_any_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
13922                );
13923                assert_eq!(
13924                    b.has_any_missing_postcondition_kind(),
13925                    b.postconditions.has_any_missing_kind(),
13926                    "Boundary::has_any_missing_postcondition_kind must delegate verbatim to \
13927                     postconditions.has_any_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
13928                );
13929                let expected_union = !ConditionKind::ALL
13930                    .iter()
13931                    .all(|k| pre_kind == *k || post_kind == *k);
13932                assert_eq!(
13933                    b.has_any_missing_condition_kind(),
13934                    expected_union,
13935                    "Boundary::has_any_missing_condition_kind must equal \
13936                     !all-ALL-covered-by-either-slice \
13937                     for pre={pre_kind:?} post={post_kind:?}",
13938                );
13939                assert_eq!(
13940                    b.has_any_missing_condition_kind(),
13941                    !b.is_condition_kind_saturated(),
13942                    "Boundary::has_any_missing_condition_kind must equal \
13943                     !is_condition_kind_saturated() for pre={pre_kind:?} post={post_kind:?}",
13944                );
13945            }
13946        }
13947
13948        // Saturated boundary — both slices carry every ConditionKind
13949        // at least once, every arm returns false.
13950        let mut b = Boundary::default();
13951        for k in ConditionKind::ALL {
13952            b.preconditions.push(condition_with(k));
13953            b.postconditions.push(condition_with(k));
13954        }
13955        assert!(
13956            !b.has_any_missing_precondition_kind(),
13957            "saturated boundary must return false on has_any_missing_precondition_kind",
13958        );
13959        assert!(
13960            !b.has_any_missing_postcondition_kind(),
13961            "saturated boundary must return false on has_any_missing_postcondition_kind",
13962        );
13963        assert!(
13964            !b.has_any_missing_condition_kind(),
13965            "saturated boundary must return false on has_any_missing_condition_kind",
13966        );
13967    }
13968
13969    /// SUBSTRATE-DELEGATION pin (Boundary at-least-one halfspace triad
13970    /// on the closed-set-inversion axis) — the three
13971    /// `has_any_distinct_*_condition_kind` methods on [`Boundary`]
13972    /// delegate to the slice-level substrate primitive
13973    /// [`ConditionSliceExt::has_any_distinct_kind`] over the two
13974    /// `Vec<Condition>` slots (precondition + postcondition) and
13975    /// compose the union via a SHORT-CIRCUITING closed-set walk over
13976    /// [`ConditionKind::ALL`] under [`Boundary::has_condition_kind`].
13977    /// Sweeps the empty boundary (every arm returns `false` — no kind
13978    /// present in either slice), a single-populated-per-side
13979    /// arrangement (every per-slice arm returns `true`, the union
13980    /// returns `true`), a single-populated-precondition-only
13981    /// arrangement (precondition arm `true`, postcondition arm
13982    /// `false`, union `true`), and the saturated boundary (every arm
13983    /// returns `true`). Also pins the composition law
13984    /// `has_any_distinct_*_condition_kind() ==
13985    /// (distinct_*_condition_kind_count() > 0)` at each arm — a
13986    /// regression that dropped the short-circuit, drifted the
13987    /// underlying `has_condition_kind` predicate, or negated the wrong
13988    /// side surfaces HERE.
13989    #[test]
13990    fn has_any_distinct_condition_kind_triad_delegates_to_slice_has_any_distinct_kind() {
13991        // Empty boundary — every arm returns false (no kind present
13992        // in either slice; distinct_kind_count == 0 in both).
13993        let b = Boundary::default();
13994        assert!(
13995            !b.has_any_distinct_precondition_kind(),
13996            "empty boundary must return false on has_any_distinct_precondition_kind",
13997        );
13998        assert!(
13999            !b.has_any_distinct_postcondition_kind(),
14000            "empty boundary must return false on has_any_distinct_postcondition_kind",
14001        );
14002        assert!(
14003            !b.has_any_distinct_condition_kind(),
14004            "empty boundary must return false on has_any_distinct_condition_kind",
14005        );
14006
14007        // Single-populated per side — sweep ALL × ALL. Every per-slice
14008        // arm returns true; the union returns true.
14009        for pre_kind in ConditionKind::ALL {
14010            for post_kind in ConditionKind::ALL {
14011                let mut b = Boundary::default();
14012                b.preconditions.push(condition_with(pre_kind));
14013                b.postconditions.push(condition_with(post_kind));
14014                assert_eq!(
14015                    b.has_any_distinct_precondition_kind(),
14016                    b.preconditions.has_any_distinct_kind(),
14017                    "Boundary::has_any_distinct_precondition_kind must delegate verbatim to \
14018                     preconditions.has_any_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
14019                );
14020                assert_eq!(
14021                    b.has_any_distinct_postcondition_kind(),
14022                    b.postconditions.has_any_distinct_kind(),
14023                    "Boundary::has_any_distinct_postcondition_kind must delegate verbatim to \
14024                     postconditions.has_any_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
14025                );
14026                assert!(
14027                    b.has_any_distinct_precondition_kind(),
14028                    "single-populated preconditions must return true on has_any_distinct_precondition_kind for pre={pre_kind:?}",
14029                );
14030                assert!(
14031                    b.has_any_distinct_postcondition_kind(),
14032                    "single-populated postconditions must return true on has_any_distinct_postcondition_kind for post={post_kind:?}",
14033                );
14034                assert!(
14035                    b.has_any_distinct_condition_kind(),
14036                    "single-populated-per-side must return true on has_any_distinct_condition_kind for pre={pre_kind:?} post={post_kind:?}",
14037                );
14038            }
14039        }
14040
14041        // Single-populated precondition only — precondition arm true,
14042        // postcondition arm false, union true.
14043        for pre_kind in ConditionKind::ALL {
14044            let mut b = Boundary::default();
14045            b.preconditions.push(condition_with(pre_kind));
14046            assert!(
14047                b.has_any_distinct_precondition_kind(),
14048                "pre-only boundary must return true on has_any_distinct_precondition_kind for pre={pre_kind:?}",
14049            );
14050            assert!(
14051                !b.has_any_distinct_postcondition_kind(),
14052                "pre-only boundary must return false on has_any_distinct_postcondition_kind for pre={pre_kind:?}",
14053            );
14054            assert!(
14055                b.has_any_distinct_condition_kind(),
14056                "pre-only boundary must return true on has_any_distinct_condition_kind for pre={pre_kind:?}",
14057            );
14058        }
14059
14060        // Saturated boundary — both slices carry every ConditionKind
14061        // at least once; every arm returns true.
14062        let mut b = Boundary::default();
14063        for k in ConditionKind::ALL {
14064            b.preconditions.push(condition_with(k));
14065            b.postconditions.push(condition_with(k));
14066        }
14067        assert!(
14068            b.has_any_distinct_precondition_kind(),
14069            "saturated boundary must return true on has_any_distinct_precondition_kind",
14070        );
14071        assert!(
14072            b.has_any_distinct_postcondition_kind(),
14073            "saturated boundary must return true on has_any_distinct_postcondition_kind",
14074        );
14075        assert!(
14076            b.has_any_distinct_condition_kind(),
14077            "saturated boundary must return true on has_any_distinct_condition_kind",
14078        );
14079    }
14080
14081    /// SUBSTRATE-DELEGATION pin (Boundary singleton-coverage triad on
14082    /// the closed-set-inversion axis) — the three
14083    /// `has_unique_distinct_*_condition_kind` methods on [`Boundary`]
14084    /// delegate to the slice-level substrate primitive
14085    /// [`ConditionSliceExt::has_unique_distinct_kind`] over the two
14086    /// `Vec<Condition>` slots (precondition + postcondition) and
14087    /// compose the union via a two-step-short-circuit walk over
14088    /// [`ConditionKind::ALL`] under [`Boundary::has_condition_kind`].
14089    /// Sweeps the empty boundary (every arm returns `false` — 0
14090    /// distinct, not exactly 1), single-populated-per-side sweeping
14091    /// ALL × ALL (every per-slice arm returns `true`; the union
14092    /// returns `true` iff the two kinds coincide OR N == 1), and the
14093    /// saturated boundary (every arm returns `false` on N ≥ 2 — N
14094    /// distinct, not exactly 1). Also pins the composition law
14095    /// `has_unique_distinct_*_condition_kind() ==
14096    /// (distinct_*_condition_kind_count() == 1)` at each arm — a
14097    /// regression that dropped the second-slot short-circuit, drifted
14098    /// the underlying `has_kind` predicate, or conflated with
14099    /// `has_any_distinct_kind` surfaces HERE.
14100    #[test]
14101    fn has_unique_distinct_condition_kind_triad_delegates_to_slice_has_unique_distinct_kind() {
14102        // Empty boundary — every arm returns false (0 distinct, not
14103        // exactly 1).
14104        let b = Boundary::default();
14105        assert!(
14106            !b.has_unique_distinct_precondition_kind(),
14107            "empty boundary must return false on has_unique_distinct_precondition_kind",
14108        );
14109        assert!(
14110            !b.has_unique_distinct_postcondition_kind(),
14111            "empty boundary must return false on has_unique_distinct_postcondition_kind",
14112        );
14113        assert!(
14114            !b.has_unique_distinct_condition_kind(),
14115            "empty boundary must return false on has_unique_distinct_condition_kind",
14116        );
14117        assert_eq!(
14118            b.has_unique_distinct_condition_kind(),
14119            b.distinct_condition_kind_count() == 1,
14120            "empty has_unique_distinct_condition_kind must equal (distinct_condition_kind_count() == 1)",
14121        );
14122
14123        // Single-populated per side — sweep ALL × ALL. Every per-
14124        // slice arm returns true; the union returns true iff the two
14125        // populated kinds coincide (union covers 1 kind) OR the
14126        // closed set is degenerate (N == 1). On this workspace's
14127        // N == 8 the union returns true iff pre_kind == post_kind.
14128        for pre_kind in ConditionKind::ALL {
14129            for post_kind in ConditionKind::ALL {
14130                let mut b = Boundary::default();
14131                b.preconditions.push(condition_with(pre_kind));
14132                b.postconditions.push(condition_with(post_kind));
14133                assert_eq!(
14134                    b.has_unique_distinct_precondition_kind(),
14135                    b.preconditions.has_unique_distinct_kind(),
14136                    "Boundary::has_unique_distinct_precondition_kind must delegate verbatim to \
14137                     preconditions.has_unique_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
14138                );
14139                assert_eq!(
14140                    b.has_unique_distinct_postcondition_kind(),
14141                    b.postconditions.has_unique_distinct_kind(),
14142                    "Boundary::has_unique_distinct_postcondition_kind must delegate verbatim to \
14143                     postconditions.has_unique_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
14144                );
14145                assert!(
14146                    b.has_unique_distinct_precondition_kind(),
14147                    "single-populated preconditions must return true on has_unique_distinct_precondition_kind for pre={pre_kind:?}",
14148                );
14149                assert!(
14150                    b.has_unique_distinct_postcondition_kind(),
14151                    "single-populated postconditions must return true on has_unique_distinct_postcondition_kind for post={post_kind:?}",
14152                );
14153                let covered_count = ConditionKind::ALL
14154                    .into_iter()
14155                    .filter(|k| *k == pre_kind || *k == post_kind)
14156                    .count();
14157                let expected_union = covered_count == 1;
14158                assert_eq!(
14159                    b.has_unique_distinct_condition_kind(),
14160                    expected_union,
14161                    "Boundary::has_unique_distinct_condition_kind must equal \
14162                     (covered-ALL-count == 1) for pre={pre_kind:?} post={post_kind:?}",
14163                );
14164                assert_eq!(
14165                    b.has_unique_distinct_condition_kind(),
14166                    b.distinct_condition_kind_count() == 1,
14167                    "Boundary::has_unique_distinct_condition_kind must equal \
14168                     (distinct_condition_kind_count() == 1) for pre={pre_kind:?} post={post_kind:?}",
14169                );
14170            }
14171        }
14172
14173        // Single-populated precondition only — precondition arm true,
14174        // postcondition arm false, union true (1 distinct kind).
14175        for pre_kind in ConditionKind::ALL {
14176            let mut b = Boundary::default();
14177            b.preconditions.push(condition_with(pre_kind));
14178            assert!(
14179                b.has_unique_distinct_precondition_kind(),
14180                "pre-only boundary must return true on has_unique_distinct_precondition_kind for pre={pre_kind:?}",
14181            );
14182            assert!(
14183                !b.has_unique_distinct_postcondition_kind(),
14184                "pre-only boundary must return false on has_unique_distinct_postcondition_kind for pre={pre_kind:?}",
14185            );
14186            assert!(
14187                b.has_unique_distinct_condition_kind(),
14188                "pre-only boundary must return true on has_unique_distinct_condition_kind for pre={pre_kind:?}",
14189            );
14190            assert_eq!(
14191                b.has_unique_distinct_condition_kind(),
14192                b.distinct_condition_kind_count() == 1,
14193                "pre-only has_unique_distinct_condition_kind must equal (distinct_condition_kind_count() == 1) for pre={pre_kind:?}",
14194            );
14195        }
14196
14197        // Saturated boundary — every arm returns false on N ≥ 2 (N
14198        // distinct, not exactly 1).
14199        if ConditionKind::ALL.len() >= 2 {
14200            let mut b = Boundary::default();
14201            for k in ConditionKind::ALL {
14202                b.preconditions.push(condition_with(k));
14203                b.postconditions.push(condition_with(k));
14204            }
14205            assert!(
14206                !b.has_unique_distinct_precondition_kind(),
14207                "saturated boundary must return false on has_unique_distinct_precondition_kind",
14208            );
14209            assert!(
14210                !b.has_unique_distinct_postcondition_kind(),
14211                "saturated boundary must return false on has_unique_distinct_postcondition_kind",
14212            );
14213            assert!(
14214                !b.has_unique_distinct_condition_kind(),
14215                "saturated boundary must return false on has_unique_distinct_condition_kind",
14216            );
14217        }
14218    }
14219
14220    /// SUBSTRATE-DELEGATION pin (Boundary cardinality-many-arm triad
14221    /// on the closed-set-inversion axis) — the three
14222    /// `has_multiple_distinct_*_condition_kind` methods on [`Boundary`]
14223    /// delegate to the slice-level substrate primitive
14224    /// [`ConditionSliceExt::has_multiple_distinct_kinds`] over the two
14225    /// `Vec<Condition>` slots (precondition + postcondition) and
14226    /// compose the union via a two-step-short-circuit walk over
14227    /// [`ConditionKind::ALL`] under [`Boundary::has_condition_kind`].
14228    /// Sweeps the empty boundary (every arm returns `false` — 0
14229    /// distinct, not ≥ 2), a single-populated-per-side arrangement
14230    /// (every per-slice arm returns `false` — 1 distinct per slice;
14231    /// the union returns `true` iff the two kinds DIFFER, otherwise
14232    /// both coincide and the union has exactly 1 distinct), and the
14233    /// saturated boundary (every arm returns `true` on `N ≥ 2` — N
14234    /// distinct, ≥ 2). Also pins the composition law
14235    /// `has_multiple_distinct_*_condition_kind() ==
14236    /// (distinct_*_condition_kind_count() >= 2)` at each arm — a
14237    /// regression that dropped the second-slot short-circuit, drifted
14238    /// the underlying `has_kind` predicate, or conflated with
14239    /// `has_any_distinct_kind` surfaces HERE.
14240    #[test]
14241    fn has_multiple_distinct_condition_kind_triad_delegates_to_slice_has_multiple_distinct_kinds() {
14242        // Empty boundary — every arm returns false (0 distinct, not
14243        // ≥ 2).
14244        let b = Boundary::default();
14245        assert!(
14246            !b.has_multiple_distinct_precondition_kind(),
14247            "empty boundary must return false on has_multiple_distinct_precondition_kind",
14248        );
14249        assert!(
14250            !b.has_multiple_distinct_postcondition_kind(),
14251            "empty boundary must return false on has_multiple_distinct_postcondition_kind",
14252        );
14253        assert!(
14254            !b.has_multiple_distinct_condition_kind(),
14255            "empty boundary must return false on has_multiple_distinct_condition_kind",
14256        );
14257        assert_eq!(
14258            b.has_multiple_distinct_condition_kind(),
14259            b.distinct_condition_kind_count() >= 2,
14260            "empty has_multiple_distinct_condition_kind must equal (distinct_condition_kind_count() >= 2)",
14261        );
14262
14263        // Single-populated per side — sweep ALL × ALL on N ≥ 2 closed
14264        // sets. Every per-slice arm returns false (1 distinct per
14265        // slice, not ≥ 2); the union returns true iff the two kinds
14266        // DIFFER (covering 2 distinct), otherwise both coincide and
14267        // the union has exactly 1 distinct.
14268        assert!(
14269            ConditionKind::ALL.len() >= 2,
14270            "test assumes ConditionKind::ALL has ≥ 2 variants",
14271        );
14272        for pre_kind in ConditionKind::ALL {
14273            for post_kind in ConditionKind::ALL {
14274                let mut b = Boundary::default();
14275                b.preconditions.push(condition_with(pre_kind));
14276                b.postconditions.push(condition_with(post_kind));
14277                assert_eq!(
14278                    b.has_multiple_distinct_precondition_kind(),
14279                    b.preconditions.has_multiple_distinct_kinds(),
14280                    "Boundary::has_multiple_distinct_precondition_kind must delegate verbatim to \
14281                     preconditions.has_multiple_distinct_kinds() for pre={pre_kind:?} post={post_kind:?}",
14282                );
14283                assert_eq!(
14284                    b.has_multiple_distinct_postcondition_kind(),
14285                    b.postconditions.has_multiple_distinct_kinds(),
14286                    "Boundary::has_multiple_distinct_postcondition_kind must delegate verbatim to \
14287                     postconditions.has_multiple_distinct_kinds() for pre={pre_kind:?} post={post_kind:?}",
14288                );
14289                assert!(
14290                    !b.has_multiple_distinct_precondition_kind(),
14291                    "single-populated preconditions must return false on has_multiple_distinct_precondition_kind for pre={pre_kind:?}",
14292                );
14293                assert!(
14294                    !b.has_multiple_distinct_postcondition_kind(),
14295                    "single-populated postconditions must return false on has_multiple_distinct_postcondition_kind for post={post_kind:?}",
14296                );
14297                let covered_count = ConditionKind::ALL
14298                    .into_iter()
14299                    .filter(|k| *k == pre_kind || *k == post_kind)
14300                    .count();
14301                let expected_union = covered_count >= 2;
14302                assert_eq!(
14303                    b.has_multiple_distinct_condition_kind(),
14304                    expected_union,
14305                    "Boundary::has_multiple_distinct_condition_kind must equal \
14306                     (covered-ALL-count >= 2) for pre={pre_kind:?} post={post_kind:?}",
14307                );
14308                assert_eq!(
14309                    b.has_multiple_distinct_condition_kind(),
14310                    b.distinct_condition_kind_count() >= 2,
14311                    "Boundary::has_multiple_distinct_condition_kind must equal \
14312                     (distinct_condition_kind_count() >= 2) for pre={pre_kind:?} post={post_kind:?}",
14313                );
14314            }
14315        }
14316
14317        // Saturated boundary — every arm returns true on N ≥ 2 (N
14318        // distinct, ≥ 2).
14319        let mut b = Boundary::default();
14320        for k in ConditionKind::ALL {
14321            b.preconditions.push(condition_with(k));
14322            b.postconditions.push(condition_with(k));
14323        }
14324        assert!(
14325            b.has_multiple_distinct_precondition_kind(),
14326            "saturated boundary must return true on has_multiple_distinct_precondition_kind",
14327        );
14328        assert!(
14329            b.has_multiple_distinct_postcondition_kind(),
14330            "saturated boundary must return true on has_multiple_distinct_postcondition_kind",
14331        );
14332        assert!(
14333            b.has_multiple_distinct_condition_kind(),
14334            "saturated boundary must return true on has_multiple_distinct_condition_kind",
14335        );
14336    }
14337
14338    /// SUBSTRATE-DELEGATION pin (Boundary cardinality "≤ 1" triad on
14339    /// the closed-set-inversion axis) — the three
14340    /// `has_at_most_one_distinct_*_condition_kind` methods on
14341    /// [`Boundary`] delegate to the slice-level substrate primitive
14342    /// [`ConditionSliceExt::has_at_most_one_distinct_kind`] over the
14343    /// two `Vec<Condition>` slots (precondition + postcondition) and
14344    /// compose the union via a definitional negation of the many-arm
14345    /// two-step-short-circuit walk over [`ConditionKind::ALL`] under
14346    /// [`Boundary::has_condition_kind`]. Sweeps the empty boundary
14347    /// (every arm returns `true` — 0 distinct, `≤ 1`), a single-
14348    /// populated-per-side arrangement (every per-slice arm returns
14349    /// `true` — 1 distinct per slice, `≤ 1`; the union returns `true`
14350    /// iff the two kinds COINCIDE, otherwise the union has 2 distinct
14351    /// and drops to `false`), and the saturated boundary (every arm
14352    /// returns `false` on `N ≥ 2` — N distinct, not `≤ 1`). Also pins
14353    /// the composition law `has_at_most_one_distinct_*_condition_kind()
14354    /// == !has_multiple_distinct_*_condition_kind()` and the widened
14355    /// composition law
14356    /// `has_at_most_one_distinct_*_condition_kind() ==
14357    /// (distinct_*_condition_kind_count() <= 1)` at each arm — a
14358    /// regression that dropped the definitional negation, drifted the
14359    /// underlying `has_kind` predicate, or swapped the wrong side of
14360    /// the negation surfaces HERE.
14361    #[test]
14362    fn has_at_most_one_distinct_condition_kind_triad_delegates_to_slice_has_at_most_one_distinct_kind(
14363    ) {
14364        // Empty boundary — every arm returns true (0 distinct, ≤ 1).
14365        let b = Boundary::default();
14366        assert!(
14367            b.has_at_most_one_distinct_precondition_kind(),
14368            "empty boundary must return true on has_at_most_one_distinct_precondition_kind",
14369        );
14370        assert!(
14371            b.has_at_most_one_distinct_postcondition_kind(),
14372            "empty boundary must return true on has_at_most_one_distinct_postcondition_kind",
14373        );
14374        assert!(
14375            b.has_at_most_one_distinct_condition_kind(),
14376            "empty boundary must return true on has_at_most_one_distinct_condition_kind",
14377        );
14378        assert_eq!(
14379            b.has_at_most_one_distinct_condition_kind(),
14380            b.distinct_condition_kind_count() <= 1,
14381            "empty has_at_most_one_distinct_condition_kind must equal (distinct_condition_kind_count() <= 1)",
14382        );
14383
14384        // Single-populated per side — sweep ALL × ALL on N ≥ 2 closed
14385        // sets. Every per-slice arm returns true (1 distinct per
14386        // slice, ≤ 1); the union returns true iff the two kinds
14387        // COINCIDE (union has 1 distinct kind), otherwise the union
14388        // has 2 distinct kinds and drops to false.
14389        assert!(
14390            ConditionKind::ALL.len() >= 2,
14391            "test assumes ConditionKind::ALL has ≥ 2 variants",
14392        );
14393        for pre_kind in ConditionKind::ALL {
14394            for post_kind in ConditionKind::ALL {
14395                let mut b = Boundary::default();
14396                b.preconditions.push(condition_with(pre_kind));
14397                b.postconditions.push(condition_with(post_kind));
14398                assert_eq!(
14399                    b.has_at_most_one_distinct_precondition_kind(),
14400                    b.preconditions.has_at_most_one_distinct_kind(),
14401                    "Boundary::has_at_most_one_distinct_precondition_kind must delegate verbatim to \
14402                     preconditions.has_at_most_one_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
14403                );
14404                assert_eq!(
14405                    b.has_at_most_one_distinct_postcondition_kind(),
14406                    b.postconditions.has_at_most_one_distinct_kind(),
14407                    "Boundary::has_at_most_one_distinct_postcondition_kind must delegate verbatim to \
14408                     postconditions.has_at_most_one_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
14409                );
14410                assert!(
14411                    b.has_at_most_one_distinct_precondition_kind(),
14412                    "single-populated preconditions must return true on has_at_most_one_distinct_precondition_kind for pre={pre_kind:?}",
14413                );
14414                assert!(
14415                    b.has_at_most_one_distinct_postcondition_kind(),
14416                    "single-populated postconditions must return true on has_at_most_one_distinct_postcondition_kind for post={post_kind:?}",
14417                );
14418                let covered_count = ConditionKind::ALL
14419                    .into_iter()
14420                    .filter(|k| *k == pre_kind || *k == post_kind)
14421                    .count();
14422                let expected_union = covered_count <= 1;
14423                assert_eq!(
14424                    b.has_at_most_one_distinct_condition_kind(),
14425                    expected_union,
14426                    "Boundary::has_at_most_one_distinct_condition_kind must equal \
14427                     (covered-ALL-count <= 1) for pre={pre_kind:?} post={post_kind:?}",
14428                );
14429                assert_eq!(
14430                    b.has_at_most_one_distinct_condition_kind(),
14431                    !b.has_multiple_distinct_condition_kind(),
14432                    "Boundary::has_at_most_one_distinct_condition_kind must equal \
14433                     !has_multiple_distinct_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
14434                );
14435                assert_eq!(
14436                    b.has_at_most_one_distinct_condition_kind(),
14437                    b.distinct_condition_kind_count() <= 1,
14438                    "Boundary::has_at_most_one_distinct_condition_kind must equal \
14439                     (distinct_condition_kind_count() <= 1) for pre={pre_kind:?} post={post_kind:?}",
14440                );
14441            }
14442        }
14443
14444        // Saturated boundary — every arm returns false on N ≥ 2 (N
14445        // distinct, not ≤ 1).
14446        let mut b = Boundary::default();
14447        for k in ConditionKind::ALL {
14448            b.preconditions.push(condition_with(k));
14449            b.postconditions.push(condition_with(k));
14450        }
14451        assert!(
14452            !b.has_at_most_one_distinct_precondition_kind(),
14453            "saturated boundary must return false on has_at_most_one_distinct_precondition_kind",
14454        );
14455        assert!(
14456            !b.has_at_most_one_distinct_postcondition_kind(),
14457            "saturated boundary must return false on has_at_most_one_distinct_postcondition_kind",
14458        );
14459        assert!(
14460            !b.has_at_most_one_distinct_condition_kind(),
14461            "saturated boundary must return false on has_at_most_one_distinct_condition_kind",
14462        );
14463    }
14464
14465    /// SUBSTRATE-DELEGATION pin (Boundary cardinality zero-endpoint
14466    /// triad) — the three `is_*_condition_kind_empty` methods on
14467    /// [`Boundary`] delegate to the slice-level substrate primitive
14468    /// [`ConditionSliceExt::is_kind_empty`] over the two
14469    /// `Vec<Condition>` slots (precondition + postcondition) and
14470    /// compose the union via a definitional negation of the at-least-
14471    /// one halfspace primitive
14472    /// [`Boundary::has_any_distinct_condition_kind`]. Sweeps the empty
14473    /// boundary (every arm returns `true` — 0 distinct, `= 0`), a
14474    /// single-populated-per-side arrangement (every per-slice arm
14475    /// returns `false` — 1 distinct, not `= 0`; the union also returns
14476    /// `false`), and the saturated boundary (every arm returns `false`
14477    /// — every kind PRESENT, not `= 0`). Also pins the composition
14478    /// laws `is_*_condition_kind_empty() ==
14479    /// (distinct_*_condition_kind_count() == 0)` and
14480    /// `is_condition_kind_empty() == !has_any_distinct_condition_kind()`
14481    /// at each arm — a regression that dropped the definitional
14482    /// negation, drifted the underlying `has_kind` predicate, or
14483    /// swapped the wrong side of the negation surfaces HERE.
14484    #[test]
14485    fn is_condition_kind_empty_triad_delegates_to_slice_is_kind_empty() {
14486        // Empty boundary — every arm returns true (0 distinct, = 0).
14487        let b = Boundary::default();
14488        assert!(
14489            b.is_precondition_kind_empty(),
14490            "empty boundary must return true on is_precondition_kind_empty",
14491        );
14492        assert!(
14493            b.is_postcondition_kind_empty(),
14494            "empty boundary must return true on is_postcondition_kind_empty",
14495        );
14496        assert!(
14497            b.is_condition_kind_empty(),
14498            "empty boundary must return true on is_condition_kind_empty",
14499        );
14500        assert_eq!(
14501            b.is_condition_kind_empty(),
14502            b.distinct_condition_kind_count() == 0,
14503            "empty is_condition_kind_empty must equal (distinct_condition_kind_count() == 0)",
14504        );
14505        assert_eq!(
14506            b.is_condition_kind_empty(),
14507            !b.has_any_distinct_condition_kind(),
14508            "empty is_condition_kind_empty must equal !has_any_distinct_condition_kind()",
14509        );
14510
14511        // Single-populated per side — every per-slice arm returns
14512        // false (1 distinct per slice, not = 0); the union always
14513        // returns false (≥ 1 kind PRESENT across the union).
14514        assert!(
14515            !ConditionKind::ALL.is_empty(),
14516            "test assumes ConditionKind::ALL has ≥ 1 variants",
14517        );
14518        for pre_kind in ConditionKind::ALL {
14519            for post_kind in ConditionKind::ALL {
14520                let mut b = Boundary::default();
14521                b.preconditions.push(condition_with(pre_kind));
14522                b.postconditions.push(condition_with(post_kind));
14523                assert_eq!(
14524                    b.is_precondition_kind_empty(),
14525                    b.preconditions.is_kind_empty(),
14526                    "Boundary::is_precondition_kind_empty must delegate verbatim to \
14527                     preconditions.is_kind_empty() for pre={pre_kind:?} post={post_kind:?}",
14528                );
14529                assert_eq!(
14530                    b.is_postcondition_kind_empty(),
14531                    b.postconditions.is_kind_empty(),
14532                    "Boundary::is_postcondition_kind_empty must delegate verbatim to \
14533                     postconditions.is_kind_empty() for pre={pre_kind:?} post={post_kind:?}",
14534                );
14535                assert!(
14536                    !b.is_precondition_kind_empty(),
14537                    "single-populated preconditions must return false on is_precondition_kind_empty for pre={pre_kind:?}",
14538                );
14539                assert!(
14540                    !b.is_postcondition_kind_empty(),
14541                    "single-populated postconditions must return false on is_postcondition_kind_empty for post={post_kind:?}",
14542                );
14543                assert!(
14544                    !b.is_condition_kind_empty(),
14545                    "single-populated union must return false on is_condition_kind_empty for pre={pre_kind:?} post={post_kind:?}",
14546                );
14547                assert_eq!(
14548                    b.is_condition_kind_empty(),
14549                    !b.has_any_distinct_condition_kind(),
14550                    "Boundary::is_condition_kind_empty must equal !has_any_distinct_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
14551                );
14552                assert_eq!(
14553                    b.is_condition_kind_empty(),
14554                    b.distinct_condition_kind_count() == 0,
14555                    "Boundary::is_condition_kind_empty must equal (distinct_condition_kind_count() == 0) for pre={pre_kind:?} post={post_kind:?}",
14556                );
14557            }
14558        }
14559
14560        // Saturated boundary — every arm returns false on N ≥ 1 (all
14561        // kinds PRESENT across the union, not = 0).
14562        let mut b = Boundary::default();
14563        for k in ConditionKind::ALL {
14564            b.preconditions.push(condition_with(k));
14565            b.postconditions.push(condition_with(k));
14566        }
14567        assert!(
14568            !b.is_precondition_kind_empty(),
14569            "saturated boundary must return false on is_precondition_kind_empty",
14570        );
14571        assert!(
14572            !b.is_postcondition_kind_empty(),
14573            "saturated boundary must return false on is_postcondition_kind_empty",
14574        );
14575        assert!(
14576            !b.is_condition_kind_empty(),
14577            "saturated boundary must return false on is_condition_kind_empty",
14578        );
14579    }
14580
14581    /// SUBSTRATE-DELEGATION pin (Boundary parent-state middle-arm
14582    /// triad) — the three `is_*_condition_kind_partially_covered`
14583    /// methods on [`Boundary`] delegate to the slice-level substrate
14584    /// primitive [`ConditionSliceExt::is_kind_partially_covered`] over
14585    /// the two `Vec<Condition>` slots (precondition + postcondition)
14586    /// and compose the union via the paired-halfspace body
14587    /// `has_any_distinct_condition_kind() && has_any_missing_condition_kind()`.
14588    /// Sweeps the empty boundary (every arm returns `false` — 0
14589    /// distinct hits the empty arm, not the middle arm), the saturated
14590    /// boundary (every arm returns `false` on any `N ≥ 1` — 0 missing
14591    /// hits the saturated arm, not the middle arm), and single-
14592    /// populated-per-side arrangements on any `N ≥ 2` closed set
14593    /// (every per-slice arm returns `true` when the slice carries a
14594    /// single populated kind; the union returns `true` iff the two
14595    /// kinds leave at least one uncovered). Also pins the trichotomy
14596    /// partition law `is_condition_kind_empty +
14597    /// is_condition_kind_partially_covered + is_condition_kind_saturated
14598    /// == 1` at each arm — a regression that dropped one bit of the
14599    /// paired-halfspace walk, drifted the underlying `has_condition_kind`
14600    /// predicate, or swapped the wrong sides of the composition
14601    /// surfaces HERE.
14602    #[test]
14603    fn is_condition_kind_partially_covered_triad_delegates_to_slice_is_kind_partially_covered() {
14604        // Empty boundary — every arm returns false on any N ≥ 1
14605        // closed set (0 distinct hits the empty arm).
14606        assert!(
14607            !ConditionKind::ALL.is_empty(),
14608            "test assumes ConditionKind::ALL has ≥ 1 variants",
14609        );
14610        let b = Boundary::default();
14611        assert!(
14612            !b.is_precondition_kind_partially_covered(),
14613            "empty boundary must return false on is_precondition_kind_partially_covered",
14614        );
14615        assert!(
14616            !b.is_postcondition_kind_partially_covered(),
14617            "empty boundary must return false on is_postcondition_kind_partially_covered",
14618        );
14619        assert!(
14620            !b.is_condition_kind_partially_covered(),
14621            "empty boundary must return false on is_condition_kind_partially_covered",
14622        );
14623        assert_eq!(
14624            b.is_condition_kind_partially_covered(),
14625            b.has_any_distinct_condition_kind() && b.has_any_missing_condition_kind(),
14626            "empty is_condition_kind_partially_covered must equal (has_any_distinct_condition_kind() && has_any_missing_condition_kind())",
14627        );
14628
14629        // Single-populated per side — every per-slice arm returns true
14630        // on any N ≥ 2 closed set (1 distinct + N-1 missing sits in
14631        // the (open, open) product); the union returns true iff the
14632        // pre+post kinds leave at least one ALL variant uncovered.
14633        if ConditionKind::ALL.len() >= 2 {
14634            for pre_kind in ConditionKind::ALL {
14635                for post_kind in ConditionKind::ALL {
14636                    let mut b = Boundary::default();
14637                    b.preconditions.push(condition_with(pre_kind));
14638                    b.postconditions.push(condition_with(post_kind));
14639                    assert_eq!(
14640                        b.is_precondition_kind_partially_covered(),
14641                        b.preconditions.is_kind_partially_covered(),
14642                        "Boundary::is_precondition_kind_partially_covered must delegate verbatim to \
14643                         preconditions.is_kind_partially_covered() for pre={pre_kind:?} post={post_kind:?}",
14644                    );
14645                    assert_eq!(
14646                        b.is_postcondition_kind_partially_covered(),
14647                        b.postconditions.is_kind_partially_covered(),
14648                        "Boundary::is_postcondition_kind_partially_covered must delegate verbatim to \
14649                         postconditions.is_kind_partially_covered() for pre={pre_kind:?} post={post_kind:?}",
14650                    );
14651                    assert!(
14652                        b.is_precondition_kind_partially_covered(),
14653                        "single-populated preconditions must return true on is_precondition_kind_partially_covered for pre={pre_kind:?}",
14654                    );
14655                    assert!(
14656                        b.is_postcondition_kind_partially_covered(),
14657                        "single-populated postconditions must return true on is_postcondition_kind_partially_covered for post={post_kind:?}",
14658                    );
14659                    // Union arm — the two kinds cover {pre, post},
14660                    // partial iff the union leaves ≥ 1 ALL variant
14661                    // uncovered, which on N ≥ 2 is always true when
14662                    // pre==post; and when pre!=post, the union is
14663                    // partial iff |ALL| >= 3 (two covered leaves N-2
14664                    // uncovered).
14665                    let covered_count = if pre_kind == post_kind { 1 } else { 2 };
14666                    let expected_union = ConditionKind::ALL.len() > covered_count;
14667                    assert_eq!(
14668                        b.is_condition_kind_partially_covered(),
14669                        expected_union,
14670                        "Boundary::is_condition_kind_partially_covered must equal \
14671                         (ConditionKind::ALL.len() > covered-kinds-count) for pre={pre_kind:?} post={post_kind:?}",
14672                    );
14673                    // Trichotomy partition on the union axis.
14674                    assert_eq!(
14675                        usize::from(b.is_condition_kind_empty())
14676                            + usize::from(b.is_condition_kind_partially_covered())
14677                            + usize::from(b.is_condition_kind_saturated()),
14678                        1,
14679                        "Boundary union trichotomy partition violated for pre={pre_kind:?} post={post_kind:?}",
14680                    );
14681                }
14682            }
14683        }
14684
14685        // Saturated boundary — every arm returns false on any N ≥ 1
14686        // closed set (0 missing hits the saturated arm).
14687        let mut b = Boundary::default();
14688        for k in ConditionKind::ALL {
14689            b.preconditions.push(condition_with(k));
14690            b.postconditions.push(condition_with(k));
14691        }
14692        assert!(
14693            !b.is_precondition_kind_partially_covered(),
14694            "saturated boundary must return false on is_precondition_kind_partially_covered",
14695        );
14696        assert!(
14697            !b.is_postcondition_kind_partially_covered(),
14698            "saturated boundary must return false on is_postcondition_kind_partially_covered",
14699        );
14700        assert!(
14701            !b.is_condition_kind_partially_covered(),
14702            "saturated boundary must return false on is_condition_kind_partially_covered",
14703        );
14704        assert_eq!(
14705            usize::from(b.is_condition_kind_empty())
14706                + usize::from(b.is_condition_kind_partially_covered())
14707                + usize::from(b.is_condition_kind_saturated()),
14708            1,
14709            "Boundary union trichotomy partition violated on saturated boundary",
14710        );
14711    }
14712
14713    /// SUBSTRATE-DELEGATION pin (Boundary cardinality-mid-endpoint
14714    /// triad) — the three `has_unique_missing_*_condition_kind`
14715    /// methods on [`Boundary`] delegate to the slice-level substrate
14716    /// primitive [`ConditionSliceExt::has_unique_missing_kind`] over
14717    /// the two `Vec<Condition>` slots (precondition + postcondition)
14718    /// and compose the union via a two-step-short-circuit walk over
14719    /// [`ConditionKind::ALL`] under negated
14720    /// [`Boundary::has_condition_kind`]. Sweeps the empty boundary
14721    /// (every arm returns `false` — all N missing, not exactly 1),
14722    /// the near-saturation-endpoint (each slice carries every
14723    /// [`ConditionKind`] except one — every per-slice arm returns
14724    /// `true`; the union returns `true` iff BOTH slices omit the SAME
14725    /// kind), the saturated boundary (every arm returns `false` — 0
14726    /// missing), and a single-populated-per-side arrangement (every
14727    /// per-slice arm returns `false` on any `N ≥ 3` closed set; the
14728    /// union returns `true` only when the two kinds together leave
14729    /// exactly one kind uncovered). Also pins the composition law
14730    /// `has_unique_missing_*_condition_kind() ==
14731    /// (missing_*_condition_kind_count() == 1)` at each arm — a
14732    /// regression that dropped the second-slot short-circuit, drifted
14733    /// the underlying `has_kind` predicate, or conflated with
14734    /// `is_kind_saturated` surfaces HERE.
14735    #[test]
14736    fn has_unique_missing_condition_kind_triad_delegates_to_slice_has_unique_missing_kind() {
14737        // Empty boundary — every arm returns false (all N missing,
14738        // not exactly 1) on any N ≥ 2 closed set.
14739        assert!(
14740            ConditionKind::ALL.len() >= 2,
14741            "test assumes ConditionKind::ALL has ≥ 2 variants",
14742        );
14743        let b = Boundary::default();
14744        assert!(
14745            !b.has_unique_missing_precondition_kind(),
14746            "empty boundary must return false on has_unique_missing_precondition_kind",
14747        );
14748        assert!(
14749            !b.has_unique_missing_postcondition_kind(),
14750            "empty boundary must return false on has_unique_missing_postcondition_kind",
14751        );
14752        assert!(
14753            !b.has_unique_missing_condition_kind(),
14754            "empty boundary must return false on has_unique_missing_condition_kind",
14755        );
14756        assert_eq!(
14757            b.has_unique_missing_condition_kind(),
14758            b.missing_condition_kind_count() == 1,
14759            "empty has_unique_missing_condition_kind must equal (missing_condition_kind_count() == 1)",
14760        );
14761
14762        // Single-populated per side — sweep ALL × ALL on N ≥ 3 closed
14763        // sets. Every per-slice arm returns false (N - 1 ≥ 2 kinds
14764        // missing per slice); the union returns true iff the two kinds
14765        // together leave exactly one ALL variant uncovered.
14766        if ConditionKind::ALL.len() >= 3 {
14767            for pre_kind in ConditionKind::ALL {
14768                for post_kind in ConditionKind::ALL {
14769                    let mut b = Boundary::default();
14770                    b.preconditions.push(condition_with(pre_kind));
14771                    b.postconditions.push(condition_with(post_kind));
14772                    assert_eq!(
14773                        b.has_unique_missing_precondition_kind(),
14774                        b.preconditions.has_unique_missing_kind(),
14775                        "Boundary::has_unique_missing_precondition_kind must delegate verbatim to \
14776                         preconditions.has_unique_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
14777                    );
14778                    assert_eq!(
14779                        b.has_unique_missing_postcondition_kind(),
14780                        b.postconditions.has_unique_missing_kind(),
14781                        "Boundary::has_unique_missing_postcondition_kind must delegate verbatim to \
14782                         postconditions.has_unique_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
14783                    );
14784                    let uncovered = ConditionKind::ALL
14785                        .into_iter()
14786                        .filter(|k| *k != pre_kind && *k != post_kind)
14787                        .count();
14788                    let expected_union = uncovered == 1;
14789                    assert_eq!(
14790                        b.has_unique_missing_condition_kind(),
14791                        expected_union,
14792                        "Boundary::has_unique_missing_condition_kind must equal \
14793                         (uncovered-ALL-count == 1) for pre={pre_kind:?} post={post_kind:?}",
14794                    );
14795                    assert_eq!(
14796                        b.has_unique_missing_condition_kind(),
14797                        b.missing_condition_kind_count() == 1,
14798                        "Boundary::has_unique_missing_condition_kind must equal \
14799                         (missing_condition_kind_count() == 1) for pre={pre_kind:?} post={post_kind:?}",
14800                    );
14801                }
14802            }
14803        }
14804
14805        // Near-saturation-endpoint per side — each slice carries
14806        // every ConditionKind except one; every per-slice arm returns
14807        // true. The union returns true iff BOTH slices omit the SAME
14808        // kind (otherwise the two omissions are covered by each
14809        // other and the union is saturated).
14810        for pre_omit in ConditionKind::ALL {
14811            for post_omit in ConditionKind::ALL {
14812                let mut b = Boundary::default();
14813                for k in ConditionKind::ALL {
14814                    if k != pre_omit {
14815                        b.preconditions.push(condition_with(k));
14816                    }
14817                    if k != post_omit {
14818                        b.postconditions.push(condition_with(k));
14819                    }
14820                }
14821                assert!(
14822                    b.has_unique_missing_precondition_kind(),
14823                    "near-saturation-endpoint precondition slice (omitting {pre_omit:?}) must return true on has_unique_missing_precondition_kind",
14824                );
14825                assert!(
14826                    b.has_unique_missing_postcondition_kind(),
14827                    "near-saturation-endpoint postcondition slice (omitting {post_omit:?}) must return true on has_unique_missing_postcondition_kind",
14828                );
14829                let expected_union = pre_omit == post_omit;
14830                assert_eq!(
14831                    b.has_unique_missing_condition_kind(),
14832                    expected_union,
14833                    "Boundary::has_unique_missing_condition_kind on both-slices-near-saturated must equal (pre_omit == post_omit) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
14834                );
14835                assert_eq!(
14836                    b.has_unique_missing_condition_kind(),
14837                    b.missing_condition_kind_count() == 1,
14838                    "Boundary::has_unique_missing_condition_kind must equal (missing_condition_kind_count() == 1) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
14839                );
14840            }
14841        }
14842
14843        // Saturated boundary — every arm returns false (0 missing,
14844        // not exactly 1).
14845        let mut b = Boundary::default();
14846        for k in ConditionKind::ALL {
14847            b.preconditions.push(condition_with(k));
14848            b.postconditions.push(condition_with(k));
14849        }
14850        assert!(
14851            !b.has_unique_missing_precondition_kind(),
14852            "saturated boundary must return false on has_unique_missing_precondition_kind",
14853        );
14854        assert!(
14855            !b.has_unique_missing_postcondition_kind(),
14856            "saturated boundary must return false on has_unique_missing_postcondition_kind",
14857        );
14858        assert!(
14859            !b.has_unique_missing_condition_kind(),
14860            "saturated boundary must return false on has_unique_missing_condition_kind",
14861        );
14862    }
14863
14864    /// SUBSTRATE-DELEGATION pin (Boundary cardinality-many-arm triad)
14865    /// — the three `has_multiple_missing_*_condition_kind` methods on
14866    /// [`Boundary`] delegate to the slice-level substrate primitive
14867    /// [`ConditionSliceExt::has_multiple_missing_kinds`] over the two
14868    /// `Vec<Condition>` slots (precondition + postcondition) and
14869    /// compose the union via a two-step-short-circuit walk over
14870    /// [`ConditionKind::ALL`] under negated
14871    /// [`Boundary::has_condition_kind`]. Sweeps the empty boundary
14872    /// (every arm returns `true` — all N missing, ≥ 2), the near-
14873    /// saturation-endpoint (each slice carries every
14874    /// [`ConditionKind`] except one — every per-slice arm returns
14875    /// `false`; the union returns `true` iff the two slices omit
14876    /// DIFFERENT kinds), the saturated boundary (every arm returns
14877    /// `false` — 0 missing), and a single-populated-per-side
14878    /// arrangement (every per-slice arm returns `true` on any `N ≥ 3`
14879    /// closed set; the union returns `true` when the two kinds
14880    /// together leave ≥ 2 kinds uncovered). Also pins the composition
14881    /// law `has_multiple_missing_*_condition_kind() ==
14882    /// (missing_*_condition_kind_count() >= 2)` at each arm — a
14883    /// regression that dropped the second-slot short-circuit, drifted
14884    /// the underlying `has_kind` predicate, or conflated with
14885    /// `has_any_missing_kind` surfaces HERE.
14886    #[test]
14887    fn has_multiple_missing_condition_kind_triad_delegates_to_slice_has_multiple_missing_kinds() {
14888        // Empty boundary — every arm returns true (all N missing,
14889        // ≥ 2) on any N ≥ 2 closed set.
14890        assert!(
14891            ConditionKind::ALL.len() >= 2,
14892            "test assumes ConditionKind::ALL has ≥ 2 variants",
14893        );
14894        let b = Boundary::default();
14895        assert!(
14896            b.has_multiple_missing_precondition_kind(),
14897            "empty boundary must return true on has_multiple_missing_precondition_kind",
14898        );
14899        assert!(
14900            b.has_multiple_missing_postcondition_kind(),
14901            "empty boundary must return true on has_multiple_missing_postcondition_kind",
14902        );
14903        assert!(
14904            b.has_multiple_missing_condition_kind(),
14905            "empty boundary must return true on has_multiple_missing_condition_kind",
14906        );
14907        assert_eq!(
14908            b.has_multiple_missing_condition_kind(),
14909            b.missing_condition_kind_count() >= 2,
14910            "empty has_multiple_missing_condition_kind must equal (missing_condition_kind_count() >= 2)",
14911        );
14912
14913        // Single-populated per side — sweep ALL × ALL on N ≥ 3 closed
14914        // sets. Every per-slice arm returns true (N - 1 ≥ 2 kinds
14915        // missing per slice); the union returns true iff the two
14916        // kinds together leave ≥ 2 ALL variants uncovered.
14917        if ConditionKind::ALL.len() >= 3 {
14918            for pre_kind in ConditionKind::ALL {
14919                for post_kind in ConditionKind::ALL {
14920                    let mut b = Boundary::default();
14921                    b.preconditions.push(condition_with(pre_kind));
14922                    b.postconditions.push(condition_with(post_kind));
14923                    assert_eq!(
14924                        b.has_multiple_missing_precondition_kind(),
14925                        b.preconditions.has_multiple_missing_kinds(),
14926                        "Boundary::has_multiple_missing_precondition_kind must delegate verbatim to \
14927                         preconditions.has_multiple_missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
14928                    );
14929                    assert_eq!(
14930                        b.has_multiple_missing_postcondition_kind(),
14931                        b.postconditions.has_multiple_missing_kinds(),
14932                        "Boundary::has_multiple_missing_postcondition_kind must delegate verbatim to \
14933                         postconditions.has_multiple_missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
14934                    );
14935                    let uncovered = ConditionKind::ALL
14936                        .into_iter()
14937                        .filter(|k| *k != pre_kind && *k != post_kind)
14938                        .count();
14939                    let expected_union = uncovered >= 2;
14940                    assert_eq!(
14941                        b.has_multiple_missing_condition_kind(),
14942                        expected_union,
14943                        "Boundary::has_multiple_missing_condition_kind must equal \
14944                         (uncovered-ALL-count >= 2) for pre={pre_kind:?} post={post_kind:?}",
14945                    );
14946                    assert_eq!(
14947                        b.has_multiple_missing_condition_kind(),
14948                        b.missing_condition_kind_count() >= 2,
14949                        "Boundary::has_multiple_missing_condition_kind must equal \
14950                         (missing_condition_kind_count() >= 2) for pre={pre_kind:?} post={post_kind:?}",
14951                    );
14952                }
14953            }
14954        }
14955
14956        // Near-saturation-endpoint per side — each slice carries
14957        // every ConditionKind except one; every per-slice arm returns
14958        // false (exactly 1 missing per slice, not ≥ 2). The union
14959        // returns true iff the two slices omit DIFFERENT kinds
14960        // (otherwise both omissions coincide and the union has
14961        // exactly 1 missing, not ≥ 2).
14962        for pre_omit in ConditionKind::ALL {
14963            for post_omit in ConditionKind::ALL {
14964                let mut b = Boundary::default();
14965                for k in ConditionKind::ALL {
14966                    if k != pre_omit {
14967                        b.preconditions.push(condition_with(k));
14968                    }
14969                    if k != post_omit {
14970                        b.postconditions.push(condition_with(k));
14971                    }
14972                }
14973                assert!(
14974                    !b.has_multiple_missing_precondition_kind(),
14975                    "near-saturation-endpoint precondition slice (omitting {pre_omit:?}) must return false on has_multiple_missing_precondition_kind",
14976                );
14977                assert!(
14978                    !b.has_multiple_missing_postcondition_kind(),
14979                    "near-saturation-endpoint postcondition slice (omitting {post_omit:?}) must return false on has_multiple_missing_postcondition_kind",
14980                );
14981                // Union: pre-only-missing = {pre_omit}, post-only-
14982                // missing = {post_omit}. Union missing = both
14983                // omissions ∩ each other only when they coincide.
14984                let expected_union = false;
14985                assert_eq!(
14986                    b.has_multiple_missing_condition_kind(),
14987                    expected_union,
14988                    "Boundary::has_multiple_missing_condition_kind on both-slices-near-saturated must always be false (union missing ≤ 1) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
14989                );
14990                assert_eq!(
14991                    b.has_multiple_missing_condition_kind(),
14992                    b.missing_condition_kind_count() >= 2,
14993                    "Boundary::has_multiple_missing_condition_kind must equal (missing_condition_kind_count() >= 2) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
14994                );
14995            }
14996        }
14997
14998        // Saturated boundary — every arm returns false (0 missing,
14999        // not ≥ 2).
15000        let mut b = Boundary::default();
15001        for k in ConditionKind::ALL {
15002            b.preconditions.push(condition_with(k));
15003            b.postconditions.push(condition_with(k));
15004        }
15005        assert!(
15006            !b.has_multiple_missing_precondition_kind(),
15007            "saturated boundary must return false on has_multiple_missing_precondition_kind",
15008        );
15009        assert!(
15010            !b.has_multiple_missing_postcondition_kind(),
15011            "saturated boundary must return false on has_multiple_missing_postcondition_kind",
15012        );
15013        assert!(
15014            !b.has_multiple_missing_condition_kind(),
15015            "saturated boundary must return false on has_multiple_missing_condition_kind",
15016        );
15017    }
15018
15019    /// SUBSTRATE-DELEGATION pin (Boundary cardinality "≤ 1" triad) —
15020    /// the three `has_at_most_one_missing_*_condition_kind` methods on
15021    /// [`Boundary`] delegate to the slice-level substrate primitive
15022    /// [`ConditionSliceExt::has_at_most_one_missing_kind`] over the
15023    /// two `Vec<Condition>` slots (precondition + postcondition) and
15024    /// compose the union via
15025    /// `!self.has_multiple_missing_condition_kind()` — a definitional
15026    /// negation of the many-arm union primitive. Sweeps the empty
15027    /// boundary (every arm returns `false` — `N ≥ 2` missing, not
15028    /// `≤ 1`), the near-saturation-endpoint (each slice carries
15029    /// every [`ConditionKind`] except one — every per-slice arm
15030    /// returns `true`; the union returns `true` — since the union of
15031    /// two near-saturated slices always has `≤ 1` missing), the
15032    /// saturated boundary (every arm returns `true` — 0 missing,
15033    /// `≤ 1`), and a single-populated-per-side arrangement (every
15034    /// per-slice arm returns `false` on any `N ≥ 3` closed set; the
15035    /// union returns `true` iff the two kinds together leave `≤ 1`
15036    /// kind uncovered — the near-saturation-endpoint of the union
15037    /// axis). Also pins the composition law
15038    /// `has_at_most_one_missing_*_condition_kind() ==
15039    /// (missing_*_condition_kind_count() <= 1)` at each arm — a
15040    /// regression that dropped the definitional negation (returning
15041    /// `has_multiple_missing_condition_kind` itself), swapped the
15042    /// wrong side, or drifted the trichotomy union operator from
15043    /// `||` to `&&` surfaces HERE.
15044    #[test]
15045    fn has_at_most_one_missing_condition_kind_triad_delegates_to_slice_has_at_most_one_missing_kind(
15046    ) {
15047        // Empty boundary — every arm returns false (all N missing,
15048        // not ≤ 1) on any N ≥ 2 closed set.
15049        assert!(
15050            ConditionKind::ALL.len() >= 2,
15051            "test assumes ConditionKind::ALL has ≥ 2 variants",
15052        );
15053        let b = Boundary::default();
15054        assert!(
15055            !b.has_at_most_one_missing_precondition_kind(),
15056            "empty boundary must return false on has_at_most_one_missing_precondition_kind",
15057        );
15058        assert!(
15059            !b.has_at_most_one_missing_postcondition_kind(),
15060            "empty boundary must return false on has_at_most_one_missing_postcondition_kind",
15061        );
15062        assert!(
15063            !b.has_at_most_one_missing_condition_kind(),
15064            "empty boundary must return false on has_at_most_one_missing_condition_kind",
15065        );
15066        assert_eq!(
15067            b.has_at_most_one_missing_condition_kind(),
15068            b.missing_condition_kind_count() <= 1,
15069            "empty has_at_most_one_missing_condition_kind must equal (missing_condition_kind_count() <= 1)",
15070        );
15071
15072        // Single-populated per side — sweep ALL × ALL on N ≥ 3
15073        // closed sets. Every per-slice arm returns false (N - 1 ≥ 2
15074        // kinds missing per slice, not ≤ 1); the union returns true
15075        // iff the two kinds together leave ≤ 1 ALL variant
15076        // uncovered — the near-saturation-endpoint of the union
15077        // axis.
15078        if ConditionKind::ALL.len() >= 3 {
15079            for pre_kind in ConditionKind::ALL {
15080                for post_kind in ConditionKind::ALL {
15081                    let mut b = Boundary::default();
15082                    b.preconditions.push(condition_with(pre_kind));
15083                    b.postconditions.push(condition_with(post_kind));
15084                    assert_eq!(
15085                        b.has_at_most_one_missing_precondition_kind(),
15086                        b.preconditions.has_at_most_one_missing_kind(),
15087                        "Boundary::has_at_most_one_missing_precondition_kind must delegate verbatim to \
15088                         preconditions.has_at_most_one_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
15089                    );
15090                    assert_eq!(
15091                        b.has_at_most_one_missing_postcondition_kind(),
15092                        b.postconditions.has_at_most_one_missing_kind(),
15093                        "Boundary::has_at_most_one_missing_postcondition_kind must delegate verbatim to \
15094                         postconditions.has_at_most_one_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
15095                    );
15096                    let uncovered = ConditionKind::ALL
15097                        .into_iter()
15098                        .filter(|k| *k != pre_kind && *k != post_kind)
15099                        .count();
15100                    let expected_union = uncovered <= 1;
15101                    assert_eq!(
15102                        b.has_at_most_one_missing_condition_kind(),
15103                        expected_union,
15104                        "Boundary::has_at_most_one_missing_condition_kind must equal \
15105                         (uncovered-ALL-count <= 1) for pre={pre_kind:?} post={post_kind:?}",
15106                    );
15107                    assert_eq!(
15108                        b.has_at_most_one_missing_condition_kind(),
15109                        !b.has_multiple_missing_condition_kind(),
15110                        "Boundary::has_at_most_one_missing_condition_kind must equal \
15111                         !has_multiple_missing_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
15112                    );
15113                    assert_eq!(
15114                        b.has_at_most_one_missing_condition_kind(),
15115                        b.missing_condition_kind_count() <= 1,
15116                        "Boundary::has_at_most_one_missing_condition_kind must equal \
15117                         (missing_condition_kind_count() <= 1) for pre={pre_kind:?} post={post_kind:?}",
15118                    );
15119                }
15120            }
15121        }
15122
15123        // Near-saturation-endpoint per side — each slice carries
15124        // every ConditionKind except one; every per-slice arm returns
15125        // true (exactly 1 missing per slice, ≤ 1). The union has ≤ 1
15126        // missing whether or not the two omissions coincide, so the
15127        // union is always true on this arm.
15128        for pre_omit in ConditionKind::ALL {
15129            for post_omit in ConditionKind::ALL {
15130                let mut b = Boundary::default();
15131                for k in ConditionKind::ALL {
15132                    if k != pre_omit {
15133                        b.preconditions.push(condition_with(k));
15134                    }
15135                    if k != post_omit {
15136                        b.postconditions.push(condition_with(k));
15137                    }
15138                }
15139                assert!(
15140                    b.has_at_most_one_missing_precondition_kind(),
15141                    "near-saturation-endpoint precondition slice (omitting {pre_omit:?}) must return true on has_at_most_one_missing_precondition_kind",
15142                );
15143                assert!(
15144                    b.has_at_most_one_missing_postcondition_kind(),
15145                    "near-saturation-endpoint postcondition slice (omitting {post_omit:?}) must return true on has_at_most_one_missing_postcondition_kind",
15146                );
15147                assert!(
15148                    b.has_at_most_one_missing_condition_kind(),
15149                    "Boundary::has_at_most_one_missing_condition_kind on both-slices-near-saturated must always be true (union missing ≤ 1) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
15150                );
15151                assert_eq!(
15152                    b.has_at_most_one_missing_condition_kind(),
15153                    b.missing_condition_kind_count() <= 1,
15154                    "Boundary::has_at_most_one_missing_condition_kind must equal (missing_condition_kind_count() <= 1) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
15155                );
15156            }
15157        }
15158
15159        // Saturated boundary — every arm returns true (0 missing,
15160        // ≤ 1).
15161        let mut b = Boundary::default();
15162        for k in ConditionKind::ALL {
15163            b.preconditions.push(condition_with(k));
15164            b.postconditions.push(condition_with(k));
15165        }
15166        assert!(
15167            b.has_at_most_one_missing_precondition_kind(),
15168            "saturated boundary must return true on has_at_most_one_missing_precondition_kind",
15169        );
15170        assert!(
15171            b.has_at_most_one_missing_postcondition_kind(),
15172            "saturated boundary must return true on has_at_most_one_missing_postcondition_kind",
15173        );
15174        assert!(
15175            b.has_at_most_one_missing_condition_kind(),
15176            "saturated boundary must return true on has_at_most_one_missing_condition_kind",
15177        );
15178    }
15179
15180    /// SUBSTRATE-DELEGATION pin (Boundary per-kind-complement triad) —
15181    /// the three `lacks_*_condition_kind` methods on [`Boundary`]
15182    /// delegate to the slice-level substrate primitive
15183    /// [`ConditionSliceExt::lacks_kind`] over the two `Vec<Condition>`
15184    /// slots (precondition + postcondition) and compose the union via
15185    /// `!self.has_condition_kind(kind)`. Sweeps the empty boundary
15186    /// (every arm returns `true` for every kind), a single-populated-
15187    /// per-side arrangement (per-slice arms return `false` on the
15188    /// populated kind + `true` on every other kind; the union returns
15189    /// `false` iff EITHER slice populates the addressed kind), and the
15190    /// saturated boundary (both slices carry every [`ConditionKind`],
15191    /// every arm returns `false` for every kind). Also pins the
15192    /// composition laws `lacks_*_condition_kind(k) ==
15193    /// !has_*_condition_kind(k)` at each arm AND `lacks_condition_kind(k)
15194    /// == lacks_precondition_kind(k) && lacks_postcondition_kind(k)`
15195    /// (the union AND-composition dual of `has`'s OR-composition) — a
15196    /// regression that dropped the negation, drifted the union operator
15197    /// to `||`, or negated the wrong side surfaces HERE.
15198    #[test]
15199    fn lacks_condition_kind_triad_delegates_to_slice_lacks_kind() {
15200        // Empty boundary — every arm returns true on every kind.
15201        let b = Boundary::default();
15202        for kind in ConditionKind::ALL {
15203            assert!(
15204                b.lacks_precondition_kind(kind),
15205                "empty boundary must return true on lacks_precondition_kind for {kind:?}",
15206            );
15207            assert!(
15208                b.lacks_postcondition_kind(kind),
15209                "empty boundary must return true on lacks_postcondition_kind for {kind:?}",
15210            );
15211            assert!(
15212                b.lacks_condition_kind(kind),
15213                "empty boundary must return true on lacks_condition_kind for {kind:?}",
15214            );
15215            assert_eq!(
15216                b.lacks_condition_kind(kind),
15217                !b.has_condition_kind(kind),
15218                "empty lacks_condition_kind must equal !has_condition_kind for {kind:?}",
15219            );
15220        }
15221
15222        // Single-populated per side — sweep ALL × ALL, then probe every
15223        // ConditionKind on the (pre, post, union) triad.
15224        for pre_kind in ConditionKind::ALL {
15225            for post_kind in ConditionKind::ALL {
15226                let mut b = Boundary::default();
15227                b.preconditions.push(condition_with(pre_kind));
15228                b.postconditions.push(condition_with(post_kind));
15229                for probe in ConditionKind::ALL {
15230                    assert_eq!(
15231                        b.lacks_precondition_kind(probe),
15232                        b.preconditions.lacks_kind(probe),
15233                        "Boundary::lacks_precondition_kind must delegate verbatim to preconditions.lacks_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15234                    );
15235                    assert_eq!(
15236                        b.lacks_postcondition_kind(probe),
15237                        b.postconditions.lacks_kind(probe),
15238                        "Boundary::lacks_postcondition_kind must delegate verbatim to postconditions.lacks_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15239                    );
15240                    let expected_union = pre_kind != probe && post_kind != probe;
15241                    assert_eq!(
15242                        b.lacks_condition_kind(probe),
15243                        expected_union,
15244                        "Boundary::lacks_condition_kind must equal all-ALL-absent-in-both-slices for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15245                    );
15246                    assert_eq!(
15247                        b.lacks_condition_kind(probe),
15248                        !b.has_condition_kind(probe),
15249                        "Boundary::lacks_condition_kind must equal !has_condition_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15250                    );
15251                    assert_eq!(
15252                        b.lacks_condition_kind(probe),
15253                        b.lacks_precondition_kind(probe)
15254                            && b.lacks_postcondition_kind(probe),
15255                        "Boundary::lacks_condition_kind must equal AND-of-half-slice-arms for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15256                    );
15257                }
15258            }
15259        }
15260
15261        // Saturated boundary — both slices carry every ConditionKind,
15262        // every arm returns false on every kind.
15263        let mut b = Boundary::default();
15264        for k in ConditionKind::ALL {
15265            b.preconditions.push(condition_with(k));
15266            b.postconditions.push(condition_with(k));
15267        }
15268        for kind in ConditionKind::ALL {
15269            assert!(
15270                !b.lacks_precondition_kind(kind),
15271                "saturated boundary must return false on lacks_precondition_kind for {kind:?}",
15272            );
15273            assert!(
15274                !b.lacks_postcondition_kind(kind),
15275                "saturated boundary must return false on lacks_postcondition_kind for {kind:?}",
15276            );
15277            assert!(
15278                !b.lacks_condition_kind(kind),
15279                "saturated boundary must return false on lacks_condition_kind for {kind:?}",
15280            );
15281        }
15282    }
15283
15284    /// TRIAD delegation pin — the (precondition, postcondition,
15285    /// condition-union) kind-scoped strict-refinement triad on
15286    /// [`Boundary`] agrees byte-for-byte with the slice-level
15287    /// substrate primitive [`ConditionSliceExt::has_only_kind`] on
15288    /// every authored arrangement.
15289    ///
15290    /// Sweeps [`ConditionKind::ALL`] × [`ConditionKind::ALL`] over
15291    /// single-populated-per-side arrangements (the well-formed
15292    /// diagonal), probing every [`ConditionKind`] at the union arm
15293    /// against the DERIVED oracle
15294    /// `boundary.distinct_condition_kinds() == vec![probe]` — a
15295    /// regression at the union arm's fused walk (dropping the
15296    /// short-circuit, swapping the `saw_kind` arm, mis-composing the
15297    /// `||` union at [`Boundary::has_condition_kind`]) surfaces HERE
15298    /// rather than as silent drift at every downstream `has-only-
15299    /// <kind>` require-tag classifier or well-formed-diagonal
15300    /// coherence check callsite. Also pins the per-slice arms
15301    /// delegate verbatim to
15302    /// [`ConditionSliceExt::has_only_kind`] over the corresponding
15303    /// half-slice.
15304    #[test]
15305    fn has_only_condition_kind_triad_delegates_to_slice_has_only_kind() {
15306        // Empty boundary — every arm returns false on every kind
15307        // (no kind is populated, so no kind is "only").
15308        let b = Boundary::default();
15309        for kind in ConditionKind::ALL {
15310            assert!(
15311                !b.has_only_precondition_kind(kind),
15312                "empty boundary must return false on has_only_precondition_kind for {kind:?}",
15313            );
15314            assert!(
15315                !b.has_only_postcondition_kind(kind),
15316                "empty boundary must return false on has_only_postcondition_kind for {kind:?}",
15317            );
15318            assert!(
15319                !b.has_only_condition_kind(kind),
15320                "empty boundary must return false on has_only_condition_kind for {kind:?}",
15321            );
15322        }
15323
15324        // Single-populated per side — sweep ALL × ALL, then probe
15325        // every ConditionKind on the (pre, post, union) triad. The
15326        // union arm returns `true` iff the addressed kind matches
15327        // BOTH the (nonempty) pre kind AND the (nonempty) post kind;
15328        // any (pre_kind, post_kind) with `pre_kind != post_kind`
15329        // yields `false` on every union arm.
15330        for pre_kind in ConditionKind::ALL {
15331            for post_kind in ConditionKind::ALL {
15332                let mut b = Boundary::default();
15333                b.preconditions.push(condition_with(pre_kind));
15334                b.postconditions.push(condition_with(post_kind));
15335                for probe in ConditionKind::ALL {
15336                    assert_eq!(
15337                        b.has_only_precondition_kind(probe),
15338                        b.preconditions.has_only_kind(probe),
15339                        "Boundary::has_only_precondition_kind must delegate verbatim to preconditions.has_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15340                    );
15341                    assert_eq!(
15342                        b.has_only_postcondition_kind(probe),
15343                        b.postconditions.has_only_kind(probe),
15344                        "Boundary::has_only_postcondition_kind must delegate verbatim to postconditions.has_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15345                    );
15346                    let expected_union = pre_kind == probe && post_kind == probe;
15347                    assert_eq!(
15348                        b.has_only_condition_kind(probe),
15349                        expected_union,
15350                        "Boundary::has_only_condition_kind must equal (pre_kind == probe && post_kind == probe) for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15351                    );
15352                    assert_eq!(
15353                        b.has_only_condition_kind(probe),
15354                        b.distinct_condition_kinds() == vec![probe],
15355                        "Boundary::has_only_condition_kind({probe:?}) must equal (distinct_condition_kinds() == vec![{probe:?}]) for pre={pre_kind:?} post={post_kind:?}",
15356                    );
15357                }
15358            }
15359        }
15360
15361        // Single-side-only populated — a boundary with a condition on
15362        // ONE side and NOTHING on the other: the union carries a
15363        // singleton distinct set. The single-slice AND-of-strict-
15364        // refinement fails on the empty side (`empty.has_only_kind(k)
15365        // == false`), but the union arm returns `true` for the
15366        // populated kind — pins that the union arm reaches the union
15367        // primitive, not the (pre AND post) AND-composition.
15368        for populated in ConditionKind::ALL {
15369            let mut b = Boundary::default();
15370            b.preconditions.push(condition_with(populated));
15371            for probe in ConditionKind::ALL {
15372                let expected = probe == populated;
15373                assert_eq!(
15374                    b.has_only_condition_kind(probe),
15375                    expected,
15376                    "pre-only boundary populated={populated:?} must return {expected} on has_only_condition_kind({probe:?})",
15377                );
15378                assert_eq!(
15379                    b.has_only_condition_kind(probe),
15380                    b.distinct_condition_kinds() == vec![probe],
15381                    "pre-only boundary populated={populated:?} must agree with distinct_condition_kinds() == vec![{probe:?}]",
15382                );
15383            }
15384            let mut b = Boundary::default();
15385            b.postconditions.push(condition_with(populated));
15386            for probe in ConditionKind::ALL {
15387                let expected = probe == populated;
15388                assert_eq!(
15389                    b.has_only_condition_kind(probe),
15390                    expected,
15391                    "post-only boundary populated={populated:?} must return {expected} on has_only_condition_kind({probe:?})",
15392                );
15393                assert_eq!(
15394                    b.has_only_condition_kind(probe),
15395                    b.distinct_condition_kinds() == vec![probe],
15396                    "post-only boundary populated={populated:?} must agree with distinct_condition_kinds() == vec![{probe:?}]",
15397                );
15398            }
15399        }
15400
15401        // Saturated boundary — both slices carry every ConditionKind,
15402        // every arm returns false on every kind (N distinct kinds, no
15403        // kind is "only").
15404        let mut b = Boundary::default();
15405        for k in ConditionKind::ALL {
15406            b.preconditions.push(condition_with(k));
15407            b.postconditions.push(condition_with(k));
15408        }
15409        for kind in ConditionKind::ALL {
15410            assert!(
15411                !b.has_only_precondition_kind(kind),
15412                "saturated boundary must return false on has_only_precondition_kind for {kind:?}",
15413            );
15414            assert!(
15415                !b.has_only_postcondition_kind(kind),
15416                "saturated boundary must return false on has_only_postcondition_kind for {kind:?}",
15417            );
15418            assert!(
15419                !b.has_only_condition_kind(kind),
15420                "saturated boundary must return false on has_only_condition_kind for {kind:?}",
15421            );
15422        }
15423    }
15424
15425    /// TRIAD delegation pin — the (precondition, postcondition,
15426    /// condition-union) kind-scoped strict-refinement-on-missing triad
15427    /// on [`Boundary`] agrees byte-for-byte with the slice-level
15428    /// substrate primitive [`ConditionSliceExt::lacks_only_kind`] on
15429    /// every authored arrangement.
15430    ///
15431    /// Sweeps [`ConditionKind::ALL`] × [`ConditionKind::ALL`] over
15432    /// single-populated-per-side arrangements + near-saturation-per-
15433    /// side arrangements (the union arm's well-formed missing
15434    /// diagonal), probing every [`ConditionKind`] at the union arm
15435    /// against the DERIVED oracle
15436    /// `boundary.missing_condition_kinds() == vec![probe]` — a
15437    /// regression at the union arm's fused walk (dropping the
15438    /// short-circuit, swapping the `saw_kind` arm, mis-composing the
15439    /// `has_condition_kind` complement) surfaces HERE rather than as
15440    /// silent drift at every downstream `lacks-only-<kind>` require-
15441    /// tag classifier or near-saturation-diagonal coherence check
15442    /// callsite. Also pins the per-slice arms delegate verbatim to
15443    /// [`ConditionSliceExt::lacks_only_kind`] over the corresponding
15444    /// half-slice.
15445    #[test]
15446    fn lacks_only_condition_kind_triad_delegates_to_slice_lacks_only_kind() {
15447        // Empty boundary — every kind is missing from the union
15448        // (2 ≥ N missing on any N ≥ 2), so no kind is "only" missing.
15449        let b = Boundary::default();
15450        for kind in ConditionKind::ALL {
15451            assert_eq!(
15452                b.lacks_only_precondition_kind(kind),
15453                b.preconditions.lacks_only_kind(kind),
15454                "empty boundary lacks_only_precondition_kind must delegate to preconditions.lacks_only_kind for {kind:?}",
15455            );
15456            assert_eq!(
15457                b.lacks_only_postcondition_kind(kind),
15458                b.postconditions.lacks_only_kind(kind),
15459                "empty boundary lacks_only_postcondition_kind must delegate to postconditions.lacks_only_kind for {kind:?}",
15460            );
15461            assert!(
15462                !b.lacks_only_condition_kind(kind),
15463                "empty boundary must return false on lacks_only_condition_kind for {kind:?} (every kind is missing on N ≥ 2)",
15464            );
15465        }
15466
15467        // Single-populated per side — sweep ALL × ALL, then probe
15468        // every ConditionKind on the (pre, post, union) triad. The
15469        // per-slice arms return `false` (on N ≥ 3 the slice has ≥ 2
15470        // missing kinds; on N == 2 the missing set is single-element
15471        // but only for the OTHER kind). The union arm returns `false`
15472        // for every kind on N ≥ 3 — the union missing set has size
15473        // `N - |{pre, post}|` which is ≥ 2 whenever N ≥ 3, or size 1
15474        // iff pre != post (union covers both), or size N - 1 iff
15475        // pre == post.
15476        for pre_kind in ConditionKind::ALL {
15477            for post_kind in ConditionKind::ALL {
15478                let mut b = Boundary::default();
15479                b.preconditions.push(condition_with(pre_kind));
15480                b.postconditions.push(condition_with(post_kind));
15481                for probe in ConditionKind::ALL {
15482                    assert_eq!(
15483                        b.lacks_only_precondition_kind(probe),
15484                        b.preconditions.lacks_only_kind(probe),
15485                        "Boundary::lacks_only_precondition_kind must delegate verbatim to preconditions.lacks_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15486                    );
15487                    assert_eq!(
15488                        b.lacks_only_postcondition_kind(probe),
15489                        b.postconditions.lacks_only_kind(probe),
15490                        "Boundary::lacks_only_postcondition_kind must delegate verbatim to postconditions.lacks_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
15491                    );
15492                    assert_eq!(
15493                        b.lacks_only_condition_kind(probe),
15494                        b.missing_condition_kinds() == vec![probe],
15495                        "Boundary::lacks_only_condition_kind({probe:?}) must equal (missing_condition_kinds() == vec![{probe:?}]) for pre={pre_kind:?} post={post_kind:?}",
15496                    );
15497                }
15498            }
15499        }
15500
15501        // Near-saturation per side — build a boundary whose preconditions
15502        // carry every kind except one, sweep every "omitted" kind for the
15503        // pre side, then probe the per-slice arm. On the well-formed
15504        // near-saturation diagonal (missing == {omitted}),
15505        // preconditions.lacks_only_kind(omitted) == true; every other
15506        // arm is false.
15507        for omitted in ConditionKind::ALL {
15508            let mut b = Boundary::default();
15509            for k in ConditionKind::ALL {
15510                if k != omitted {
15511                    b.preconditions.push(condition_with(k));
15512                    b.postconditions.push(condition_with(k));
15513                }
15514            }
15515            for probe in ConditionKind::ALL {
15516                let expected = probe == omitted;
15517                assert_eq!(
15518                    b.lacks_only_precondition_kind(probe),
15519                    expected,
15520                    "near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_precondition_kind({probe:?})",
15521                );
15522                assert_eq!(
15523                    b.lacks_only_postcondition_kind(probe),
15524                    expected,
15525                    "near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_postcondition_kind({probe:?})",
15526                );
15527                assert_eq!(
15528                    b.lacks_only_condition_kind(probe),
15529                    expected,
15530                    "near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_condition_kind({probe:?})",
15531                );
15532                assert_eq!(
15533                    b.lacks_only_condition_kind(probe),
15534                    b.missing_condition_kinds() == vec![probe],
15535                    "near-saturation boundary omitted={omitted:?} must agree with missing_condition_kinds() == vec![{probe:?}]",
15536                );
15537            }
15538        }
15539
15540        // Single-side-only near-saturation — a boundary whose ONE side
15541        // carries every kind except one, the OTHER side empty: the
15542        // empty side is missing every kind (per-slice `lacks_only_kind`
15543        // returns false on N ≥ 2), but the union covers everything the
15544        // populated side does, so the union missing set is still
15545        // `{omitted}` and the union arm returns `true` for `omitted`.
15546        // Pins that the union arm reaches the union primitive, not the
15547        // (pre AND post) AND-composition (which would fail on the
15548        // empty side).
15549        for omitted in ConditionKind::ALL {
15550            let mut b = Boundary::default();
15551            for k in ConditionKind::ALL {
15552                if k != omitted {
15553                    b.preconditions.push(condition_with(k));
15554                }
15555            }
15556            for probe in ConditionKind::ALL {
15557                let expected = probe == omitted;
15558                assert_eq!(
15559                    b.lacks_only_condition_kind(probe),
15560                    expected,
15561                    "pre-only near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_condition_kind({probe:?})",
15562                );
15563                assert_eq!(
15564                    b.lacks_only_condition_kind(probe),
15565                    b.missing_condition_kinds() == vec![probe],
15566                    "pre-only near-saturation boundary omitted={omitted:?} must agree with missing_condition_kinds() == vec![{probe:?}]",
15567                );
15568            }
15569            let mut b = Boundary::default();
15570            for k in ConditionKind::ALL {
15571                if k != omitted {
15572                    b.postconditions.push(condition_with(k));
15573                }
15574            }
15575            for probe in ConditionKind::ALL {
15576                let expected = probe == omitted;
15577                assert_eq!(
15578                    b.lacks_only_condition_kind(probe),
15579                    expected,
15580                    "post-only near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_condition_kind({probe:?})",
15581                );
15582            }
15583        }
15584
15585        // Saturated boundary — every kind populated in the union, so
15586        // no kind is missing, so `lacks_only_kind` returns false on
15587        // every arm.
15588        let mut b = Boundary::default();
15589        for k in ConditionKind::ALL {
15590            b.preconditions.push(condition_with(k));
15591            b.postconditions.push(condition_with(k));
15592        }
15593        for kind in ConditionKind::ALL {
15594            assert!(
15595                !b.lacks_only_precondition_kind(kind),
15596                "saturated boundary must return false on lacks_only_precondition_kind for {kind:?}",
15597            );
15598            assert!(
15599                !b.lacks_only_postcondition_kind(kind),
15600                "saturated boundary must return false on lacks_only_postcondition_kind for {kind:?}",
15601            );
15602            assert!(
15603                !b.lacks_only_condition_kind(kind),
15604                "saturated boundary must return false on lacks_only_condition_kind for {kind:?}",
15605            );
15606        }
15607    }
15608
15609    // ── assert_slice_refinement_composition_laws — substrate testkit ──
15610    //
15611    // The substrate testkit primitive
15612    // [`assert_slice_refinement_composition_laws`] pins the FOUR
15613    // composition laws that bind the [`ConditionSliceExt`] refinement
15614    // algebra (find ↔ iter, count ↔ iter, has ↔ find, has ↔ count) at
15615    // ONE call site per authored arrangement, sweeping
15616    // [`ConditionKind::ALL`]. The four hand-authored slice-level
15617    // composition-law tests above
15618    // (`condition_slice_find_kind_equals_iter_kind_next`,
15619    // `condition_slice_count_kind_equals_iter_kind_count`,
15620    // `condition_slice_has_kind_equals_find_kind_is_some`,
15621    // `condition_slice_has_and_find_equal_count_greater_than_zero`)
15622    // stay as first-class per-law drift-arm pins; this substrate
15623    // testkit is the compound-lift primitive that binds all four
15624    // laws through ONE typed sweep so a future FIFTH refinement's
15625    // composition law picks up its pin as ONE new arm inside the
15626    // primitive's body rather than as ONE new sibling test at every
15627    // downstream author-time enumeration.
15628
15629    /// SUBSTRATE PANEL pin — the substrate testkit primitive
15630    /// [`assert_slice_refinement_composition_laws`] passes on the
15631    /// FOUR canonical authored arrangements the trait's downstream
15632    /// consumers reach for: the empty slice (every refinement returns
15633    /// its zero-element identity), a single-element populated slice
15634    /// (every refinement returns the addressed match's projection),
15635    /// a dual-populated slice with distinct kinds (every refinement
15636    /// probes the kind field per element), and a duplicate-populated
15637    /// slice with the same kind at multiple positions (the widened
15638    /// primitive `iter_kind` yields every match; `find_kind` collapses
15639    /// to the first; `count_kind` returns the exact cardinality;
15640    /// `has_kind` returns true). Sweeping the four arrangements at
15641    /// ONE call site pins that every composition law holds regardless
15642    /// of the widened primitive's yield structure.
15643    #[test]
15644    fn slice_refinement_composition_laws_hold_across_authored_arrangements() {
15645        let empty: &[Condition] = &[];
15646        assert_slice_refinement_composition_laws(empty);
15647
15648        for populated in ConditionKind::ALL {
15649            let single = [condition_with(populated)];
15650            assert_slice_refinement_composition_laws(single.as_slice());
15651        }
15652
15653        for pre_kind in ConditionKind::ALL {
15654            for post_kind in ConditionKind::ALL {
15655                let dual = [condition_with(pre_kind), condition_with(post_kind)];
15656                assert_slice_refinement_composition_laws(dual.as_slice());
15657            }
15658        }
15659
15660        for populated in ConditionKind::ALL {
15661            let duplicates = [
15662                condition_with(populated),
15663                condition_with(populated),
15664                condition_with(populated),
15665            ];
15666            assert_slice_refinement_composition_laws(duplicates.as_slice());
15667        }
15668    }
15669
15670    /// SUBSTRATE PANEL pin (params-distinguishable duplicates) — the
15671    /// substrate primitive holds on a slice that carries duplicate
15672    /// kinds interleaved with a distinct kind, byte-for-byte peer of
15673    /// the standalone `condition_slice_iter_kind_yields_every_match_in_slice_order_on_duplicates`
15674    /// / `condition_slice_count_kind_counts_every_match_on_duplicates`
15675    /// arrangement. Confirms the four composition laws hold when
15676    /// the widened primitive's yield stream is genuinely multi-element
15677    /// AND the addressed kind is interleaved with a non-matching kind
15678    /// (the union structural case that the diagonal-and-corners sweep
15679    /// above doesn't reach).
15680    #[test]
15681    fn slice_refinement_composition_laws_hold_on_interleaved_duplicates() {
15682        let interleaved = [
15683            Condition {
15684                kind: ConditionKind::ClosedLoopAuth,
15685                params: json!({ "probeImage": "first" }),
15686            },
15687            Condition {
15688                kind: ConditionKind::PromQL,
15689                params: json!({ "query": "up" }),
15690            },
15691            Condition {
15692                kind: ConditionKind::ClosedLoopAuth,
15693                params: json!({ "probeImage": "second" }),
15694            },
15695            Condition {
15696                kind: ConditionKind::PromQL,
15697                params: json!({ "query": "healthy" }),
15698            },
15699            Condition {
15700                kind: ConditionKind::ClosedLoopAuth,
15701                params: json!({ "probeImage": "third" }),
15702            },
15703        ];
15704        assert_slice_refinement_composition_laws(interleaved.as_slice());
15705    }
15706
15707    // ── assert_surface_union_composition_laws — substrate testkit ────
15708    //
15709    // The substrate testkit macro
15710    // [`crate::assert_surface_union_composition_laws`] pins the FOUR
15711    // union composition laws (has: OR, find: or_else, iter: chain,
15712    // count: SUM) that bind the (pre, post, union) refinement triads
15713    // on the [`Boundary`] surface at ONE call site per authored
15714    // arrangement, sweeping [`ConditionKind::ALL`]. The four hand-
15715    // authored point-surface composition-law tests above
15716    // (`boundary_has_condition_kind_composes_precondition_and_postcondition_arms`,
15717    // `find_condition_kind_triad_delegates_to_slice_find_kind`,
15718    // `iter_condition_kind_triad_delegates_to_slice_iter_kind`,
15719    // `boundary_count_condition_kind_triad_delegates_and_sums_slice_count_kind`)
15720    // stay as first-class per-law drift-arm pins; this substrate
15721    // testkit macro is the compound-lift primitive that binds all
15722    // four union composition laws through ONE typed sweep so a
15723    // future FIFTH union refinement picks up its composition-law
15724    // pin as ONE new arm inside the macro body rather than as ONE
15725    // new sibling test at every downstream author-time
15726    // enumeration on each of the two surfaces.
15727
15728    /// SUBSTRATE PANEL pin — the substrate testkit macro
15729    /// [`crate::assert_surface_union_composition_laws`] passes on
15730    /// [`Boundary`] for the four canonical authored arrangements the
15731    /// surface's downstream consumers reach for: the empty boundary
15732    /// (every union arm returns its zero-element identity), a
15733    /// precondition-only populated boundary (every union arm equals
15734    /// its precondition arm, postcondition arm is empty), a
15735    /// postcondition-only populated boundary (mirror), and a dual-
15736    /// populated boundary sweeping `ALL × ALL` (both half-slice arms
15737    /// contribute; the union monoid operator applies). Sweeping the
15738    /// four arrangements at ONE call site pins every union
15739    /// composition law holds regardless of the arrangement's per-
15740    /// half fill pattern.
15741    #[test]
15742    fn boundary_surface_union_composition_laws_hold_across_authored_arrangements() {
15743        let empty = Boundary::default();
15744        crate::assert_surface_union_composition_laws!(empty);
15745
15746        for populated in ConditionKind::ALL {
15747            let mut pre_only = Boundary::default();
15748            pre_only.preconditions.push(condition_with(populated));
15749            crate::assert_surface_union_composition_laws!(pre_only);
15750
15751            let mut post_only = Boundary::default();
15752            post_only.postconditions.push(condition_with(populated));
15753            crate::assert_surface_union_composition_laws!(post_only);
15754        }
15755
15756        for pre_kind in ConditionKind::ALL {
15757            for post_kind in ConditionKind::ALL {
15758                let mut dual = Boundary::default();
15759                dual.preconditions.push(condition_with(pre_kind));
15760                dual.postconditions.push(condition_with(post_kind));
15761                crate::assert_surface_union_composition_laws!(dual);
15762            }
15763        }
15764    }
15765
15766    /// SUBSTRATE PANEL pin (params-distinguishable duplicates) — the
15767    /// substrate macro holds on a [`Boundary`] whose two half-slices
15768    /// each carry duplicates of the same kind at multiple positions,
15769    /// interleaved with a distinct kind. The scenario reaches every
15770    /// union arm at its non-degenerate composition: `has` still
15771    /// resolves `true` on both halves (OR is not the discriminating
15772    /// bit), `find` yields the FIRST-precondition-side match
15773    /// (`or_else` walk order), `iter` yields every match with the
15774    /// full pre-then-post chain order (five total matches across the
15775    /// two halves), `count` returns the SUM (five). A regression that
15776    /// (a) collapsed `find`'s `or_else` to `and_then` (silently
15777    /// narrowing to intersection), (b) collapsed `iter`'s `chain` to
15778    /// `zip` (silently truncating to `min(pre, post)`), or (c)
15779    /// collapsed `count`'s SUM to `max` (silently narrowing the
15780    /// cardinality) surfaces HERE — the four laws are pinned
15781    /// simultaneously and any single-arm regression fails one of
15782    /// the four asserts.
15783    #[test]
15784    fn boundary_surface_union_composition_laws_hold_on_interleaved_duplicates() {
15785        let mut b = Boundary::default();
15786        b.preconditions.push(Condition {
15787            kind: ConditionKind::ClosedLoopAuth,
15788            params: json!({ "side": "pre-1" }),
15789        });
15790        b.preconditions.push(Condition {
15791            kind: ConditionKind::PromQL,
15792            params: json!({ "query": "up" }),
15793        });
15794        b.preconditions.push(Condition {
15795            kind: ConditionKind::ClosedLoopAuth,
15796            params: json!({ "side": "pre-2" }),
15797        });
15798        b.postconditions.push(Condition {
15799            kind: ConditionKind::PromQL,
15800            params: json!({ "query": "healthy" }),
15801        });
15802        b.postconditions.push(Condition {
15803            kind: ConditionKind::ClosedLoopAuth,
15804            params: json!({ "side": "post-1" }),
15805        });
15806        crate::assert_surface_union_composition_laws!(b);
15807    }
15808
15809    /// SUBSTRATE-DELEGATION pin (Boundary unique-distinct-kind
15810    /// witnessing triad on the closed-set-inversion axis) — the three
15811    /// `unique_distinct_*_condition_kind` methods on [`Boundary`]
15812    /// delegate to the slice-level substrate primitive
15813    /// [`ConditionSliceExt::unique_distinct_kind`] over the two
15814    /// `Vec<Condition>` slots (precondition + postcondition) and
15815    /// compose the union via a two-step-short-circuit walk over
15816    /// [`ConditionKind::ALL`] under [`Boundary::has_condition_kind`].
15817    /// Sweep `ConditionKind::ALL × ConditionKind::ALL` so a regression
15818    /// that (a) dropped the second-hit short-circuit (returning
15819    /// `Some(first)` on a two-distinct union), (b) inlined a divergent
15820    /// closed-set walk at either half-slice arm, or (c) diverged the
15821    /// witness scalar from the Boolean predicate surfaces HERE. Also
15822    /// pins the composition laws `unique_distinct_*_kind().is_some() ==
15823    /// has_unique_distinct_*_kind()` and (on the `Some` arm)
15824    /// `unique_distinct_*_kind() == first_distinct_*_kind() ==
15825    /// last_distinct_*_kind()` at each arm.
15826    #[test]
15827    fn unique_distinct_condition_kind_triad_delegates_to_slice_unique_distinct_kind() {
15828        // Empty boundary — every arm returns None.
15829        let b = Boundary::default();
15830        assert_eq!(
15831            b.unique_distinct_precondition_kind(),
15832            None,
15833            "empty boundary must return None on unique_distinct_precondition_kind",
15834        );
15835        assert_eq!(
15836            b.unique_distinct_postcondition_kind(),
15837            None,
15838            "empty boundary must return None on unique_distinct_postcondition_kind",
15839        );
15840        assert_eq!(
15841            b.unique_distinct_condition_kind(),
15842            None,
15843            "empty boundary must return None on unique_distinct_condition_kind",
15844        );
15845
15846        for pre_kind in ConditionKind::ALL {
15847            for post_kind in ConditionKind::ALL {
15848                let mut b = Boundary::default();
15849                b.preconditions.push(condition_with(pre_kind));
15850                b.postconditions.push(condition_with(post_kind));
15851
15852                assert_eq!(
15853                    b.unique_distinct_precondition_kind(),
15854                    b.preconditions.unique_distinct_kind(),
15855                    "Boundary::unique_distinct_precondition_kind must delegate verbatim to \
15856                     preconditions.unique_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
15857                );
15858                assert_eq!(
15859                    b.unique_distinct_precondition_kind(),
15860                    Some(pre_kind),
15861                    "Boundary::unique_distinct_precondition_kind must equal Some(pre_kind) on \
15862                     single-populated preconditions for pre={pre_kind:?} post={post_kind:?}",
15863                );
15864                assert_eq!(
15865                    b.unique_distinct_postcondition_kind(),
15866                    b.postconditions.unique_distinct_kind(),
15867                    "Boundary::unique_distinct_postcondition_kind must delegate verbatim to \
15868                     postconditions.unique_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
15869                );
15870                assert_eq!(
15871                    b.unique_distinct_postcondition_kind(),
15872                    Some(post_kind),
15873                    "Boundary::unique_distinct_postcondition_kind must equal Some(post_kind) on \
15874                     single-populated postconditions for pre={pre_kind:?} post={post_kind:?}",
15875                );
15876
15877                // Union arm: Some(k) iff the union covers exactly one kind.
15878                let covered: Vec<ConditionKind> = ConditionKind::ALL
15879                    .into_iter()
15880                    .filter(|k| pre_kind == *k || post_kind == *k)
15881                    .collect();
15882                let expected_union = if covered.len() == 1 {
15883                    Some(covered[0])
15884                } else {
15885                    None
15886                };
15887                assert_eq!(
15888                    b.unique_distinct_condition_kind(),
15889                    expected_union,
15890                    "Boundary::unique_distinct_condition_kind must equal Some(k) iff the \
15891                     ALL-entries covered by either half-slice sum to exactly one for \
15892                     pre={pre_kind:?} post={post_kind:?}",
15893                );
15894
15895                // Boolean-witness composition laws.
15896                assert_eq!(
15897                    b.unique_distinct_condition_kind().is_some(),
15898                    b.has_unique_distinct_condition_kind(),
15899                    "unique_distinct_condition_kind().is_some() must equal \
15900                     has_unique_distinct_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
15901                );
15902                assert_eq!(
15903                    b.unique_distinct_precondition_kind().is_some(),
15904                    b.has_unique_distinct_precondition_kind(),
15905                    "unique_distinct_precondition_kind().is_some() must equal \
15906                     has_unique_distinct_precondition_kind() for pre={pre_kind:?} post={post_kind:?}",
15907                );
15908                assert_eq!(
15909                    b.unique_distinct_postcondition_kind().is_some(),
15910                    b.has_unique_distinct_postcondition_kind(),
15911                    "unique_distinct_postcondition_kind().is_some() must equal \
15912                     has_unique_distinct_postcondition_kind() for pre={pre_kind:?} post={post_kind:?}",
15913                );
15914
15915                // Endpoint-agreement — on Some, first == last == unique.
15916                if let Some(k) = b.unique_distinct_condition_kind() {
15917                    assert_eq!(
15918                        b.first_distinct_condition_kind(),
15919                        Some(k),
15920                        "unique_distinct_condition_kind() Some arm must equal \
15921                         first_distinct_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
15922                    );
15923                    assert_eq!(
15924                        b.last_distinct_condition_kind(),
15925                        Some(k),
15926                        "unique_distinct_condition_kind() Some arm must equal \
15927                         last_distinct_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
15928                    );
15929                }
15930            }
15931        }
15932
15933        // Saturated boundary — every arm returns None on N ≥ 2.
15934        if ConditionKind::ALL.len() >= 2 {
15935            let mut b = Boundary::default();
15936            for k in ConditionKind::ALL {
15937                b.preconditions.push(condition_with(k));
15938                b.postconditions.push(condition_with(k));
15939            }
15940            assert_eq!(
15941                b.unique_distinct_precondition_kind(),
15942                None,
15943                "saturated boundary must return None on unique_distinct_precondition_kind",
15944            );
15945            assert_eq!(
15946                b.unique_distinct_postcondition_kind(),
15947                None,
15948                "saturated boundary must return None on unique_distinct_postcondition_kind",
15949            );
15950            assert_eq!(
15951                b.unique_distinct_condition_kind(),
15952                None,
15953                "saturated boundary must return None on unique_distinct_condition_kind",
15954            );
15955        }
15956    }
15957
15958    /// SUBSTRATE-DELEGATION pin (Boundary unique-missing-kind
15959    /// witnessing triad on the closed-set-complement axis) — the three
15960    /// `unique_missing_*_condition_kind` methods on [`Boundary`]
15961    /// delegate to the slice-level substrate primitive
15962    /// [`ConditionSliceExt::unique_missing_kind`] over the two
15963    /// `Vec<Condition>` slots (precondition + postcondition) and
15964    /// compose the union via a two-step-short-circuit walk over
15965    /// [`ConditionKind::ALL`] under a NEGATED
15966    /// [`Boundary::has_condition_kind`]. Sweep `ConditionKind::ALL ×
15967    /// ConditionKind::ALL` so a regression that dropped the negation,
15968    /// dropped the second-hit short-circuit, or diverged the witness
15969    /// scalar from the Boolean predicate surfaces HERE. Also pins the
15970    /// composition laws `unique_missing_*_kind().is_some() ==
15971    /// has_unique_missing_*_kind()` and (on the `Some` arm)
15972    /// `unique_missing_*_kind() == first_missing_*_kind() ==
15973    /// last_missing_*_kind()` at each arm.
15974    #[test]
15975    fn unique_missing_condition_kind_triad_delegates_to_slice_unique_missing_kind() {
15976        // Empty boundary — every arm returns None on N ≥ 2 (every
15977        // kind missing, not exactly 1).
15978        let b = Boundary::default();
15979        if ConditionKind::ALL.len() >= 2 {
15980            assert_eq!(
15981                b.unique_missing_precondition_kind(),
15982                None,
15983                "empty boundary must return None on unique_missing_precondition_kind \
15984                 on any N ≥ 2 closed set",
15985            );
15986            assert_eq!(
15987                b.unique_missing_postcondition_kind(),
15988                None,
15989                "empty boundary must return None on unique_missing_postcondition_kind \
15990                 on any N ≥ 2 closed set",
15991            );
15992            assert_eq!(
15993                b.unique_missing_condition_kind(),
15994                None,
15995                "empty boundary must return None on unique_missing_condition_kind \
15996                 on any N ≥ 2 closed set",
15997            );
15998        }
15999
16000        for pre_kind in ConditionKind::ALL {
16001            for post_kind in ConditionKind::ALL {
16002                let mut b = Boundary::default();
16003                b.preconditions.push(condition_with(pre_kind));
16004                b.postconditions.push(condition_with(post_kind));
16005
16006                assert_eq!(
16007                    b.unique_missing_precondition_kind(),
16008                    b.preconditions.unique_missing_kind(),
16009                    "Boundary::unique_missing_precondition_kind must delegate verbatim to \
16010                     preconditions.unique_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
16011                );
16012                assert_eq!(
16013                    b.unique_missing_postcondition_kind(),
16014                    b.postconditions.unique_missing_kind(),
16015                    "Boundary::unique_missing_postcondition_kind must delegate verbatim to \
16016                     postconditions.unique_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
16017                );
16018
16019                // Union arm: Some(k) iff the union is missing exactly one kind.
16020                let missing: Vec<ConditionKind> = ConditionKind::ALL
16021                    .into_iter()
16022                    .filter(|k| pre_kind != *k && post_kind != *k)
16023                    .collect();
16024                let expected_union = if missing.len() == 1 {
16025                    Some(missing[0])
16026                } else {
16027                    None
16028                };
16029                assert_eq!(
16030                    b.unique_missing_condition_kind(),
16031                    expected_union,
16032                    "Boundary::unique_missing_condition_kind must equal Some(k) iff the \
16033                     ALL-entries NOT covered by either half-slice sum to exactly one for \
16034                     pre={pre_kind:?} post={post_kind:?}",
16035                );
16036
16037                // Boolean-witness composition laws.
16038                assert_eq!(
16039                    b.unique_missing_condition_kind().is_some(),
16040                    b.has_unique_missing_condition_kind(),
16041                    "unique_missing_condition_kind().is_some() must equal \
16042                     has_unique_missing_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
16043                );
16044                assert_eq!(
16045                    b.unique_missing_precondition_kind().is_some(),
16046                    b.has_unique_missing_precondition_kind(),
16047                    "unique_missing_precondition_kind().is_some() must equal \
16048                     has_unique_missing_precondition_kind() for pre={pre_kind:?} post={post_kind:?}",
16049                );
16050                assert_eq!(
16051                    b.unique_missing_postcondition_kind().is_some(),
16052                    b.has_unique_missing_postcondition_kind(),
16053                    "unique_missing_postcondition_kind().is_some() must equal \
16054                     has_unique_missing_postcondition_kind() for pre={pre_kind:?} post={post_kind:?}",
16055                );
16056
16057                // Endpoint-agreement — on Some, first == last == unique.
16058                if let Some(k) = b.unique_missing_condition_kind() {
16059                    assert_eq!(
16060                        b.first_missing_condition_kind(),
16061                        Some(k),
16062                        "unique_missing_condition_kind() Some arm must equal \
16063                         first_missing_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
16064                    );
16065                    assert_eq!(
16066                        b.last_missing_condition_kind(),
16067                        Some(k),
16068                        "unique_missing_condition_kind() Some arm must equal \
16069                         last_missing_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
16070                    );
16071                }
16072            }
16073        }
16074
16075        // Saturated boundary — every arm returns None (zero missing).
16076        let mut b = Boundary::default();
16077        for k in ConditionKind::ALL {
16078            b.preconditions.push(condition_with(k));
16079            b.postconditions.push(condition_with(k));
16080        }
16081        assert_eq!(
16082            b.unique_missing_precondition_kind(),
16083            None,
16084            "saturated boundary must return None on unique_missing_precondition_kind",
16085        );
16086        assert_eq!(
16087            b.unique_missing_postcondition_kind(),
16088            None,
16089            "saturated boundary must return None on unique_missing_postcondition_kind",
16090        );
16091        assert_eq!(
16092            b.unique_missing_condition_kind(),
16093            None,
16094            "saturated boundary must return None on unique_missing_condition_kind",
16095        );
16096
16097        // Near-saturation arm: exactly one ALL entry missing on each
16098        // side (achieved by populating every kind except `hole`).
16099        for hole in ConditionKind::ALL {
16100            let mut b = Boundary::default();
16101            for k in ConditionKind::ALL {
16102                if k != hole {
16103                    b.preconditions.push(condition_with(k));
16104                    b.postconditions.push(condition_with(k));
16105                }
16106            }
16107            assert_eq!(
16108                b.unique_missing_precondition_kind(),
16109                Some(hole),
16110                "near-saturation boundary must return Some(hole={hole:?}) on unique_missing_precondition_kind",
16111            );
16112            assert_eq!(
16113                b.unique_missing_postcondition_kind(),
16114                Some(hole),
16115                "near-saturation boundary must return Some(hole={hole:?}) on unique_missing_postcondition_kind",
16116            );
16117            assert_eq!(
16118                b.unique_missing_condition_kind(),
16119                Some(hole),
16120                "near-saturation boundary must return Some(hole={hole:?}) on unique_missing_condition_kind",
16121            );
16122        }
16123    }
16124
16125    /// SUBSTRATE-DELEGATION pin (Boundary per-kind cardinality "≥ 2"
16126    /// many-arm triad on the count axis) — the three
16127    /// `has_multiple_of_*_condition_kind` methods on [`Boundary`]
16128    /// delegate to the slice-level substrate primitive
16129    /// [`ConditionSliceExt::has_multiple_of_kind`] over the two
16130    /// `Vec<Condition>` slots (precondition + postcondition) and
16131    /// compose the union via a two-step-short-circuit walk over the
16132    /// chained per-kind iterator [`Boundary::iter_condition_kind`].
16133    /// Sweeps: (a) the empty boundary (every arm returns `false` on
16134    /// every kind — 0 matches, not ≥ 2); (b) a
16135    /// single-populated-per-side arrangement where each per-slice
16136    /// arm returns `false` (1 match per slice) but the union returns
16137    /// `true` iff the two kinds COINCIDE (2 matches on the shared
16138    /// kind); (c) a double-populated postcondition (post arm returns
16139    /// `true`, pre arm returns `false`, union returns `true`); (d)
16140    /// the saturated-doubled boundary (every arm returns `true` on
16141    /// every kind — every slice carries every kind twice). Also pins
16142    /// the composition law
16143    /// `has_multiple_of_*_condition_kind(k) ==
16144    ///  (count_*_condition_kind(k) >= 2)` at each arm.
16145    #[test]
16146    fn has_multiple_of_condition_kind_triad_delegates_to_slice_has_multiple_of_kind() {
16147        // Empty boundary — every arm returns false on every kind.
16148        let b = Boundary::default();
16149        for kind in ConditionKind::ALL {
16150            assert!(
16151                !b.has_multiple_of_precondition_kind(kind),
16152                "empty boundary must return false on has_multiple_of_precondition_kind({kind:?})",
16153            );
16154            assert!(
16155                !b.has_multiple_of_postcondition_kind(kind),
16156                "empty boundary must return false on has_multiple_of_postcondition_kind({kind:?})",
16157            );
16158            assert!(
16159                !b.has_multiple_of_condition_kind(kind),
16160                "empty boundary must return false on has_multiple_of_condition_kind({kind:?})",
16161            );
16162            assert_eq!(
16163                b.has_multiple_of_condition_kind(kind),
16164                b.count_condition_kind(kind) >= 2,
16165                "empty has_multiple_of_condition_kind({kind:?}) must equal \
16166                 (count_condition_kind >= 2)",
16167            );
16168        }
16169
16170        // Single-populated-per-side sweep — per-slice arms stay
16171        // false; union goes true iff pre and post carry the SAME
16172        // kind (chain sums to 2 matches on the shared kind).
16173        for pre_kind in ConditionKind::ALL {
16174            for post_kind in ConditionKind::ALL {
16175                let mut b = Boundary::default();
16176                b.preconditions.push(condition_with(pre_kind));
16177                b.postconditions.push(condition_with(post_kind));
16178
16179                assert_eq!(
16180                    b.has_multiple_of_precondition_kind(pre_kind),
16181                    b.preconditions.has_multiple_of_kind(pre_kind),
16182                    "Boundary::has_multiple_of_precondition_kind must delegate verbatim to \
16183                     preconditions.has_multiple_of_kind for pre={pre_kind:?} post={post_kind:?}",
16184                );
16185                assert_eq!(
16186                    b.has_multiple_of_postcondition_kind(post_kind),
16187                    b.postconditions.has_multiple_of_kind(post_kind),
16188                    "Boundary::has_multiple_of_postcondition_kind must delegate verbatim to \
16189                     postconditions.has_multiple_of_kind for pre={pre_kind:?} post={post_kind:?}",
16190                );
16191
16192                for query in ConditionKind::ALL {
16193                    assert!(
16194                        !b.has_multiple_of_precondition_kind(query),
16195                        "single-populated preconditions must return false on \
16196                         has_multiple_of_precondition_kind({query:?}) for \
16197                         pre={pre_kind:?} post={post_kind:?}",
16198                    );
16199                    assert!(
16200                        !b.has_multiple_of_postcondition_kind(query),
16201                        "single-populated postconditions must return false on \
16202                         has_multiple_of_postcondition_kind({query:?}) for \
16203                         pre={pre_kind:?} post={post_kind:?}",
16204                    );
16205                    let expected_union = pre_kind == query && post_kind == query;
16206                    assert_eq!(
16207                        b.has_multiple_of_condition_kind(query),
16208                        expected_union,
16209                        "Boundary::has_multiple_of_condition_kind({query:?}) must equal \
16210                         (pre_kind == query && post_kind == query) for \
16211                         pre={pre_kind:?} post={post_kind:?}",
16212                    );
16213                    assert_eq!(
16214                        b.has_multiple_of_condition_kind(query),
16215                        b.count_condition_kind(query) >= 2,
16216                        "Boundary::has_multiple_of_condition_kind({query:?}) drifted from \
16217                         (count_condition_kind >= 2) for pre={pre_kind:?} post={post_kind:?}",
16218                    );
16219                }
16220            }
16221        }
16222
16223        // Double-populated postcondition — post arm goes true on
16224        // the doubled kind, pre arm stays false, union goes true.
16225        for doubled in ConditionKind::ALL {
16226            let mut b = Boundary::default();
16227            b.postconditions.push(condition_with(doubled));
16228            b.postconditions.push(condition_with(doubled));
16229
16230            assert!(
16231                !b.has_multiple_of_precondition_kind(doubled),
16232                "empty preconditions must return false on has_multiple_of_precondition_kind \
16233                 for doubled={doubled:?}",
16234            );
16235            assert!(
16236                b.has_multiple_of_postcondition_kind(doubled),
16237                "doubled postconditions must return true on has_multiple_of_postcondition_kind \
16238                 for doubled={doubled:?}",
16239            );
16240            assert!(
16241                b.has_multiple_of_condition_kind(doubled),
16242                "doubled postconditions must return true on union has_multiple_of_condition_kind \
16243                 for doubled={doubled:?}",
16244            );
16245            for query in ConditionKind::ALL {
16246                if query != doubled {
16247                    assert!(
16248                        !b.has_multiple_of_condition_kind(query),
16249                        "other kind {query:?} must return false on union has_multiple_of_condition_kind \
16250                         when only {doubled:?} is doubled",
16251                    );
16252                }
16253            }
16254        }
16255
16256        // Saturated-doubled boundary — every arm returns true on
16257        // every kind (every slice carries every kind twice).
16258        let mut b = Boundary::default();
16259        for k in ConditionKind::ALL {
16260            b.preconditions.push(condition_with(k));
16261            b.preconditions.push(condition_with(k));
16262            b.postconditions.push(condition_with(k));
16263            b.postconditions.push(condition_with(k));
16264        }
16265        for kind in ConditionKind::ALL {
16266            assert!(
16267                b.has_multiple_of_precondition_kind(kind),
16268                "saturated-doubled boundary must return true on has_multiple_of_precondition_kind({kind:?})",
16269            );
16270            assert!(
16271                b.has_multiple_of_postcondition_kind(kind),
16272                "saturated-doubled boundary must return true on has_multiple_of_postcondition_kind({kind:?})",
16273            );
16274            assert!(
16275                b.has_multiple_of_condition_kind(kind),
16276                "saturated-doubled boundary must return true on has_multiple_of_condition_kind({kind:?})",
16277            );
16278        }
16279    }
16280
16281    /// Every arm of the (precondition, postcondition, condition-union)
16282    /// per-kind cardinality "= 1" mid-endpoint triad on [`Boundary`]
16283    /// delegates verbatim to the slice-level substrate primitive
16284    /// [`ConditionSliceExt::has_unique_of_kind`]. Sweeps four
16285    /// arrangements: (a) an empty boundary (every arm returns
16286    /// `false` on every kind); (b) a single-populated-per-side sweep
16287    /// where per-slice arms fire iff their kind equals `query`,
16288    /// while the union arm fires iff EXACTLY ONE of `{pre, post}`
16289    /// equals `query` (the other side either lacks the kind, giving
16290    /// 1 chain match, or shares it, giving 2 chain matches — only
16291    /// the disjoint-arm case yields `= 1`); (c) a double-populated
16292    /// postcondition (post arm returns `false` on the doubled kind
16293    /// as `≥ 2` matches, pre arm returns `false` on 0 matches,
16294    /// union returns `false` on `≥ 2` chain matches); (d) the
16295    /// saturated-singleton boundary (every kind appears exactly
16296    /// once on every slice — per-slice arms return `true` on every
16297    /// kind, union returns `false` on every kind as `= 2` chain
16298    /// matches). Also pins the composition law
16299    /// `has_unique_of_*_condition_kind(k) ==
16300    ///  (count_*_condition_kind(k) == 1)` at each arm and the
16301    /// trichotomy partition
16302    /// {lacks, has_unique_of, has_multiple_of}_condition_kind
16303    /// firing EXACTLY ONE arm at the union level.
16304    #[test]
16305    fn has_unique_of_condition_kind_triad_delegates_to_slice_has_unique_of_kind() {
16306        // Empty boundary — every arm returns false on every kind.
16307        let b = Boundary::default();
16308        for kind in ConditionKind::ALL {
16309            assert!(
16310                !b.has_unique_of_precondition_kind(kind),
16311                "empty boundary must return false on has_unique_of_precondition_kind({kind:?})",
16312            );
16313            assert!(
16314                !b.has_unique_of_postcondition_kind(kind),
16315                "empty boundary must return false on has_unique_of_postcondition_kind({kind:?})",
16316            );
16317            assert!(
16318                !b.has_unique_of_condition_kind(kind),
16319                "empty boundary must return false on has_unique_of_condition_kind({kind:?})",
16320            );
16321            assert_eq!(
16322                b.has_unique_of_condition_kind(kind),
16323                b.count_condition_kind(kind) == 1,
16324                "empty has_unique_of_condition_kind({kind:?}) must equal \
16325                 (count_condition_kind == 1)",
16326            );
16327        }
16328
16329        // Single-populated-per-side sweep — per-slice arm returns
16330        // true iff its side's kind equals `query`. Union arm returns
16331        // true iff EXACTLY ONE of `{pre, post}` equals `query`
16332        // (chain sums to 1 on the disjoint-arm case, 2 on shared,
16333        // 0 on unrelated).
16334        for pre_kind in ConditionKind::ALL {
16335            for post_kind in ConditionKind::ALL {
16336                let mut b = Boundary::default();
16337                b.preconditions.push(condition_with(pre_kind));
16338                b.postconditions.push(condition_with(post_kind));
16339
16340                for query in ConditionKind::ALL {
16341                    assert_eq!(
16342                        b.has_unique_of_precondition_kind(query),
16343                        b.preconditions.has_unique_of_kind(query),
16344                        "Boundary::has_unique_of_precondition_kind must delegate verbatim to \
16345                         preconditions.has_unique_of_kind for pre={pre_kind:?} \
16346                         post={post_kind:?} query={query:?}",
16347                    );
16348                    assert_eq!(
16349                        b.has_unique_of_postcondition_kind(query),
16350                        b.postconditions.has_unique_of_kind(query),
16351                        "Boundary::has_unique_of_postcondition_kind must delegate verbatim to \
16352                         postconditions.has_unique_of_kind for pre={pre_kind:?} \
16353                         post={post_kind:?} query={query:?}",
16354                    );
16355
16356                    let pre_hit = pre_kind == query;
16357                    let post_hit = post_kind == query;
16358                    let expected_union = pre_hit ^ post_hit;
16359                    assert_eq!(
16360                        b.has_unique_of_condition_kind(query),
16361                        expected_union,
16362                        "Boundary::has_unique_of_condition_kind({query:?}) must equal \
16363                         (pre_hit XOR post_hit) for pre={pre_kind:?} post={post_kind:?}",
16364                    );
16365                    assert_eq!(
16366                        b.has_unique_of_condition_kind(query),
16367                        b.count_condition_kind(query) == 1,
16368                        "Boundary::has_unique_of_condition_kind({query:?}) drifted from \
16369                         (count_condition_kind == 1) for pre={pre_kind:?} post={post_kind:?}",
16370                    );
16371
16372                    // Trichotomy partition pin at the union level.
16373                    let arms_true = [
16374                        b.lacks_condition_kind(query),
16375                        b.has_unique_of_condition_kind(query),
16376                        b.has_multiple_of_condition_kind(query),
16377                    ]
16378                    .into_iter()
16379                    .filter(|&x| x)
16380                    .count();
16381                    assert_eq!(
16382                        arms_true, 1,
16383                        "per-kind trichotomy at boundary union for query={query:?} \
16384                         (pre={pre_kind:?} post={post_kind:?}) must fire EXACTLY one \
16385                         arm, got {arms_true}",
16386                    );
16387                }
16388            }
16389        }
16390
16391        // Double-populated postcondition — post arm returns false
16392        // on the doubled kind (≥ 2 matches), pre arm returns false
16393        // (0 matches), union returns false (2 chain matches).
16394        for doubled in ConditionKind::ALL {
16395            let mut b = Boundary::default();
16396            b.postconditions.push(condition_with(doubled));
16397            b.postconditions.push(condition_with(doubled));
16398
16399            assert!(
16400                !b.has_unique_of_precondition_kind(doubled),
16401                "empty preconditions must return false on has_unique_of_precondition_kind \
16402                 for doubled={doubled:?}",
16403            );
16404            assert!(
16405                !b.has_unique_of_postcondition_kind(doubled),
16406                "doubled postconditions must return false on has_unique_of_postcondition_kind \
16407                 for doubled={doubled:?}",
16408            );
16409            assert!(
16410                !b.has_unique_of_condition_kind(doubled),
16411                "doubled postconditions must return false on union has_unique_of_condition_kind \
16412                 for doubled={doubled:?}",
16413            );
16414        }
16415
16416        // Saturated-singleton boundary — every kind appears exactly
16417        // once on every slice. Per-slice arms return true on every
16418        // kind; union returns false on every kind (= 2 chain matches).
16419        let mut b = Boundary::default();
16420        for k in ConditionKind::ALL {
16421            b.preconditions.push(condition_with(k));
16422            b.postconditions.push(condition_with(k));
16423        }
16424        for kind in ConditionKind::ALL {
16425            assert!(
16426                b.has_unique_of_precondition_kind(kind),
16427                "saturated-singleton boundary must return true on has_unique_of_precondition_kind({kind:?})",
16428            );
16429            assert!(
16430                b.has_unique_of_postcondition_kind(kind),
16431                "saturated-singleton boundary must return true on has_unique_of_postcondition_kind({kind:?})",
16432            );
16433            assert!(
16434                !b.has_unique_of_condition_kind(kind),
16435                "saturated-singleton boundary must return false on union has_unique_of_condition_kind({kind:?}) (2 chain matches)",
16436            );
16437        }
16438    }
16439
16440    // ── Boundary::has_at_most_one_of_(pre|post|)condition_kind triad ─
16441    //
16442    // Two-surface parity contract with
16443    // `EphemeralSpec::has_at_most_one_of_condition_kind` on the "≤ 1"
16444    // per-kind negation arm. Boundary composes against the slice-level
16445    // substrate primitive `ConditionSliceExt::has_at_most_one_of_kind`
16446    // via delegation on each side and via the definitional negation
16447    // of `has_multiple_of_condition_kind` on the union chain. The
16448    // union-level trichotomy-union arm equivalence
16449    // `has_at_most_one_of_condition_kind(k) == lacks_condition_kind(k)
16450    // || has_unique_of_condition_kind(k)` closes the {= 0, = 1, ≥ 1,
16451    // ≥ 2, ≤ 1} Boolean-cardinality grid on the per-kind axis at the
16452    // union level.
16453
16454    /// Boundary triad delegation + two-surface parity pin — sweeps
16455    /// every kind on every reachable arrangement of a single
16456    /// condition-per-side spec, asserts each per-slice arm delegates
16457    /// verbatim to the slice-level primitive, and asserts the union
16458    /// arm equals the {= 0, = 1} trichotomy-union `lacks ∨ has_unique`.
16459    /// Also pins the definitional-negation composition law
16460    /// `has_at_most_one_of_condition_kind(k) ==
16461    /// !has_multiple_of_condition_kind(k)` and the tetrachotomy
16462    /// partition (`{≤ 1, ≥ 2}` exactly one arm on every arrangement).
16463    /// Regression at any of these predicates or at the underlying
16464    /// slice-level primitive fails here.
16465    #[test]
16466    fn has_at_most_one_of_condition_kind_triad_delegates_to_slice_has_at_most_one_of_kind() {
16467        // Empty boundary — every arm returns true on every kind
16468        // (0 matches, `≤ 1`).
16469        let b = Boundary::default();
16470        for kind in ConditionKind::ALL {
16471            assert!(
16472                b.has_at_most_one_of_precondition_kind(kind),
16473                "empty boundary must return true on has_at_most_one_of_precondition_kind({kind:?})",
16474            );
16475            assert!(
16476                b.has_at_most_one_of_postcondition_kind(kind),
16477                "empty boundary must return true on has_at_most_one_of_postcondition_kind({kind:?})",
16478            );
16479            assert!(
16480                b.has_at_most_one_of_condition_kind(kind),
16481                "empty boundary must return true on has_at_most_one_of_condition_kind({kind:?})",
16482            );
16483            assert_eq!(
16484                b.has_at_most_one_of_condition_kind(kind),
16485                b.count_condition_kind(kind) <= 1,
16486                "empty has_at_most_one_of_condition_kind({kind:?}) must equal \
16487                 (count_condition_kind <= 1)",
16488            );
16489        }
16490
16491        // Single-populated-per-side sweep — every per-side arm
16492        // returns `true` for every query (each side has ≤ 1 match);
16493        // union returns `true` iff at most one of `{pre, post}`
16494        // equals `query` (chain sums to 0 or 1 on disjoint,
16495        // 2 on shared).
16496        for pre_kind in ConditionKind::ALL {
16497            for post_kind in ConditionKind::ALL {
16498                let mut b = Boundary::default();
16499                b.preconditions.push(condition_with(pre_kind));
16500                b.postconditions.push(condition_with(post_kind));
16501
16502                for query in ConditionKind::ALL {
16503                    assert_eq!(
16504                        b.has_at_most_one_of_precondition_kind(query),
16505                        b.preconditions.has_at_most_one_of_kind(query),
16506                        "Boundary::has_at_most_one_of_precondition_kind must delegate verbatim \
16507                         to preconditions.has_at_most_one_of_kind for pre={pre_kind:?} \
16508                         post={post_kind:?} query={query:?}",
16509                    );
16510                    assert_eq!(
16511                        b.has_at_most_one_of_postcondition_kind(query),
16512                        b.postconditions.has_at_most_one_of_kind(query),
16513                        "Boundary::has_at_most_one_of_postcondition_kind must delegate verbatim \
16514                         to postconditions.has_at_most_one_of_kind for pre={pre_kind:?} \
16515                         post={post_kind:?} query={query:?}",
16516                    );
16517
16518                    // Per-side arms are always `true` — each side
16519                    // holds at most one condition of any given kind
16520                    // in this arrangement.
16521                    assert!(
16522                        b.has_at_most_one_of_precondition_kind(query),
16523                        "single-per-side pre arm must return true for pre={pre_kind:?} \
16524                         post={post_kind:?} query={query:?}",
16525                    );
16526                    assert!(
16527                        b.has_at_most_one_of_postcondition_kind(query),
16528                        "single-per-side post arm must return true for pre={pre_kind:?} \
16529                         post={post_kind:?} query={query:?}",
16530                    );
16531
16532                    // Union arm — chain multiplicity is (pre_hit +
16533                    // post_hit); "≤ 1" fires iff the sum is 0 or 1,
16534                    // i.e. `!(pre_hit && post_hit)`.
16535                    let pre_hit = pre_kind == query;
16536                    let post_hit = post_kind == query;
16537                    let expected_union = !(pre_hit && post_hit);
16538                    assert_eq!(
16539                        b.has_at_most_one_of_condition_kind(query),
16540                        expected_union,
16541                        "Boundary::has_at_most_one_of_condition_kind({query:?}) must equal \
16542                         !(pre_hit && post_hit) for pre={pre_kind:?} post={post_kind:?}",
16543                    );
16544
16545                    // Definitional negation of the many-arm peer.
16546                    assert_eq!(
16547                        b.has_at_most_one_of_condition_kind(query),
16548                        !b.has_multiple_of_condition_kind(query),
16549                        "Boundary::has_at_most_one_of_condition_kind({query:?}) drifted from \
16550                         !has_multiple_of_condition_kind for pre={pre_kind:?} post={post_kind:?}",
16551                    );
16552
16553                    // Trichotomy-union arm: {= 0} ∪ {= 1} == {≤ 1}.
16554                    assert_eq!(
16555                        b.has_at_most_one_of_condition_kind(query),
16556                        b.lacks_condition_kind(query) || b.has_unique_of_condition_kind(query),
16557                        "Boundary::has_at_most_one_of_condition_kind({query:?}) drifted from \
16558                         (lacks || has_unique) trichotomy-union for pre={pre_kind:?} \
16559                         post={post_kind:?}",
16560                    );
16561
16562                    // Composition law with count.
16563                    assert_eq!(
16564                        b.has_at_most_one_of_condition_kind(query),
16565                        b.count_condition_kind(query) <= 1,
16566                        "Boundary::has_at_most_one_of_condition_kind({query:?}) drifted from \
16567                         (count_condition_kind <= 1) for pre={pre_kind:?} post={post_kind:?}",
16568                    );
16569
16570                    // {≤ 1, ≥ 2} Boolean-negation partition at the
16571                    // union level — EXACTLY ONE arm fires.
16572                    let at_most_one = b.has_at_most_one_of_condition_kind(query);
16573                    let multiple = b.has_multiple_of_condition_kind(query);
16574                    assert_ne!(
16575                        at_most_one, multiple,
16576                        "union {{≤ 1, ≥ 2}} Boolean-negation partition for query={query:?} \
16577                         (pre={pre_kind:?} post={post_kind:?}) must fire EXACTLY one arm",
16578                    );
16579                }
16580            }
16581        }
16582
16583        // Double-populated postcondition — post arm returns false
16584        // on the doubled kind (≥ 2 matches, not ≤ 1), pre arm returns
16585        // true (0 matches, ≤ 1), union returns false (2 chain
16586        // matches, not ≤ 1).
16587        for doubled in ConditionKind::ALL {
16588            let mut b = Boundary::default();
16589            b.postconditions.push(condition_with(doubled));
16590            b.postconditions.push(condition_with(doubled));
16591
16592            assert!(
16593                b.has_at_most_one_of_precondition_kind(doubled),
16594                "empty preconditions must return true on has_at_most_one_of_precondition_kind \
16595                 for doubled={doubled:?}",
16596            );
16597            assert!(
16598                !b.has_at_most_one_of_postcondition_kind(doubled),
16599                "doubled postconditions must return false on has_at_most_one_of_postcondition_kind \
16600                 for doubled={doubled:?}",
16601            );
16602            assert!(
16603                !b.has_at_most_one_of_condition_kind(doubled),
16604                "doubled postconditions must return false on union \
16605                 has_at_most_one_of_condition_kind for doubled={doubled:?}",
16606            );
16607        }
16608    }
16609
16610    // ── ConditionSliceExt::unique_of_kind + Boundary triad ──────────
16611    //
16612    // Slice-level `Option<&Condition>` witnessing peer of the Boolean
16613    // `has_unique_of_kind` on the per-kind count axis. Fills the
16614    // Boolean → Option refinement asymmetry: distinct-axis and
16615    // missing-axis witness peers (`unique_distinct_kind`,
16616    // `unique_missing_kind`) already exist as `Option<ConditionKind>`
16617    // returns; this closes the third axis with an `Option<&Condition>`
16618    // return that additionally carries pointer identity to the
16619    // matched slot. Boundary triad lifts to the two-slice chain via
16620    // a two-step short-circuit walk over `iter_condition_kind`.
16621
16622    /// EMPTY-SLICE pin — an empty `&[Condition]` returns [`None`]
16623    /// on every kind (0 matches, not = 1). Sweep [`ConditionKind::ALL`]
16624    /// so a new variant added without a matching arm surfaces at
16625    /// rustc's exhaustiveness gate on the ALL literal rather than
16626    /// as silent drift.
16627    #[test]
16628    fn condition_slice_unique_of_kind_returns_none_on_empty_slice_for_every_kind() {
16629        let slice: &[Condition] = &[];
16630        for kind in ConditionKind::ALL {
16631            assert!(
16632                slice.unique_of_kind(kind).is_none(),
16633                "empty slice must return None for unique_of_kind({kind:?})",
16634            );
16635            assert_eq!(
16636                slice.unique_of_kind(kind).is_some(),
16637                slice.has_unique_of_kind(kind),
16638                "empty slice unique_of_kind({kind:?}).is_some() must equal has_unique_of_kind",
16639            );
16640        }
16641    }
16642
16643    /// SINGLETON pin — a slice with EXACTLY ONE match of a kind
16644    /// returns `Some(&c)` for THAT kind pointing at the matched
16645    /// slot, and [`None`] for every OTHER kind. A slice with `≥ 2`
16646    /// matches of a kind returns [`None`] for THAT kind (the
16647    /// witness collapses to no witness on the many-arm).
16648    #[test]
16649    fn condition_slice_unique_of_kind_witnesses_singleton_and_collapses_on_duplicates() {
16650        // Singleton sweep — one condition per kind, in isolation.
16651        for populated in ConditionKind::ALL {
16652            let slice = vec![condition_with(populated)];
16653            for query in ConditionKind::ALL {
16654                let unique = slice.unique_of_kind(query);
16655                if query == populated {
16656                    let c = unique.expect("singleton match must be Some");
16657                    assert_eq!(
16658                        c.kind, populated,
16659                        "unique_of_kind({query:?}) yielded &Condition with wrong kind {:?}",
16660                        c.kind,
16661                    );
16662                    // Pointer identity: unique_of_kind on singleton
16663                    // yields the exact matched slot.
16664                    assert!(
16665                        std::ptr::eq(c, &slice[0]),
16666                        "unique_of_kind({query:?}) singleton must point at the matched slot",
16667                    );
16668                } else {
16669                    assert!(
16670                        unique.is_none(),
16671                        "unique_of_kind({query:?}) must be None on singleton-{populated:?} for \
16672                         non-matching query",
16673                    );
16674                }
16675                // Boolean composition-law pin.
16676                assert_eq!(
16677                    unique.is_some(),
16678                    slice.has_unique_of_kind(query),
16679                    "unique_of_kind({query:?}).is_some() must equal has_unique_of_kind on \
16680                     populated={populated:?}",
16681                );
16682            }
16683        }
16684
16685        // Doubled-kind sweep — two conditions of the same kind
16686        // collapse the witness to None (the many-arm).
16687        for doubled in ConditionKind::ALL {
16688            let slice = vec![condition_with(doubled), condition_with(doubled)];
16689            let unique = slice.unique_of_kind(doubled);
16690            assert!(
16691                unique.is_none(),
16692                "unique_of_kind({doubled:?}) on doubled-slice must collapse to None (≥ 2 matches)",
16693            );
16694            assert!(
16695                !slice.has_unique_of_kind(doubled),
16696                "has_unique_of_kind({doubled:?}) on doubled-slice must be false",
16697            );
16698            for query in ConditionKind::ALL {
16699                if query != doubled {
16700                    assert!(
16701                        slice.unique_of_kind(query).is_none(),
16702                        "unique_of_kind({query:?}) on doubled-{doubled:?} slice must be None for \
16703                         non-matching query",
16704                    );
16705                }
16706            }
16707        }
16708    }
16709
16710    /// Boundary triad — sweeps every `(pre_kind, post_kind, query)`
16711    /// arrangement of a single-condition-per-side spec, asserts each
16712    /// per-slice arm delegates verbatim to
16713    /// [`ConditionSliceExt::unique_of_kind`], and pins the union arm
16714    /// against the chained two-step short-circuit walk. Composition
16715    /// laws pinned: `unique_of_condition_kind(k).is_some() ==
16716    /// has_unique_of_condition_kind(k)`, `unique_of_condition_kind(k)
16717    /// .map(|c| c.kind) == Some(k) iff has_unique_of_condition_kind`.
16718    #[test]
16719    fn unique_of_condition_kind_triad_delegates_to_slice_unique_of_kind() {
16720        // Empty boundary — every arm returns None on every kind.
16721        let b = Boundary::default();
16722        for kind in ConditionKind::ALL {
16723            assert!(
16724                b.unique_of_precondition_kind(kind).is_none(),
16725                "empty boundary must return None on unique_of_precondition_kind({kind:?})",
16726            );
16727            assert!(
16728                b.unique_of_postcondition_kind(kind).is_none(),
16729                "empty boundary must return None on unique_of_postcondition_kind({kind:?})",
16730            );
16731            assert!(
16732                b.unique_of_condition_kind(kind).is_none(),
16733                "empty boundary must return None on unique_of_condition_kind({kind:?})",
16734            );
16735        }
16736
16737        // Single-populated-per-side sweep. Per-slice arms fire iff
16738        // that side's kind equals `query`; union arm fires iff
16739        // EXACTLY ONE of `{pre, post}` equals `query` (chain sums
16740        // to 1 on disjoint, 2 on shared).
16741        for pre_kind in ConditionKind::ALL {
16742            for post_kind in ConditionKind::ALL {
16743                let mut b = Boundary::default();
16744                b.preconditions.push(condition_with(pre_kind));
16745                b.postconditions.push(condition_with(post_kind));
16746
16747                for query in ConditionKind::ALL {
16748                    // Delegation pins — per-slice arms match slice
16749                    // primitive on identity of the &Condition.
16750                    assert_eq!(
16751                        b.unique_of_precondition_kind(query)
16752                            .map(|c| c as *const Condition),
16753                        b.preconditions
16754                            .unique_of_kind(query)
16755                            .map(|c| c as *const Condition),
16756                        "Boundary::unique_of_precondition_kind must delegate verbatim to \
16757                         preconditions.unique_of_kind for pre={pre_kind:?} post={post_kind:?} \
16758                         query={query:?}",
16759                    );
16760                    assert_eq!(
16761                        b.unique_of_postcondition_kind(query)
16762                            .map(|c| c as *const Condition),
16763                        b.postconditions
16764                            .unique_of_kind(query)
16765                            .map(|c| c as *const Condition),
16766                        "Boundary::unique_of_postcondition_kind must delegate verbatim to \
16767                         postconditions.unique_of_kind for pre={pre_kind:?} post={post_kind:?} \
16768                         query={query:?}",
16769                    );
16770
16771                    // Boolean-projection composition-law pin.
16772                    assert_eq!(
16773                        b.unique_of_condition_kind(query).is_some(),
16774                        b.has_unique_of_condition_kind(query),
16775                        "Boundary::unique_of_condition_kind({query:?}).is_some() drifted from \
16776                         has_unique_of_condition_kind for pre={pre_kind:?} post={post_kind:?}",
16777                    );
16778                    assert_eq!(
16779                        b.unique_of_condition_kind(query).map(|c| c.kind),
16780                        if b.has_unique_of_condition_kind(query) {
16781                            Some(query)
16782                        } else {
16783                            None
16784                        },
16785                        "Boundary::unique_of_condition_kind({query:?}).map(kind) must yield \
16786                         Some({query:?}) iff has_unique_of_condition_kind for pre={pre_kind:?} \
16787                         post={post_kind:?}",
16788                    );
16789
16790                    // Union-arm shape — chain multiplicity is
16791                    // (pre_hit + post_hit). Some iff sum == 1 (i.e.
16792                    // XOR); the yielded &Condition is the
16793                    // precondition slot when pre_hit && !post_hit,
16794                    // the postcondition slot when !pre_hit && post_hit.
16795                    let pre_hit = pre_kind == query;
16796                    let post_hit = post_kind == query;
16797                    let unique = b.unique_of_condition_kind(query);
16798                    let expected_some = pre_hit ^ post_hit;
16799                    assert_eq!(
16800                        unique.is_some(),
16801                        expected_some,
16802                        "Boundary::unique_of_condition_kind({query:?}).is_some() must equal \
16803                         (pre_hit XOR post_hit) for pre={pre_kind:?} post={post_kind:?}",
16804                    );
16805                    if pre_hit && !post_hit {
16806                        assert!(
16807                            std::ptr::eq(unique.unwrap(), &b.preconditions[0]),
16808                            "union arm must point at preconditions slot when pre-only for \
16809                             pre={pre_kind:?} post={post_kind:?} query={query:?}",
16810                        );
16811                    } else if post_hit && !pre_hit {
16812                        assert!(
16813                            std::ptr::eq(unique.unwrap(), &b.postconditions[0]),
16814                            "union arm must point at postconditions slot when post-only for \
16815                             pre={pre_kind:?} post={post_kind:?} query={query:?}",
16816                        );
16817                    }
16818                }
16819            }
16820        }
16821
16822        // Doubled-post sweep — union collapses to None on the
16823        // doubled kind (`≥ 2` chain matches, not `= 1`).
16824        for doubled in ConditionKind::ALL {
16825            let mut b = Boundary::default();
16826            b.postconditions.push(condition_with(doubled));
16827            b.postconditions.push(condition_with(doubled));
16828            assert!(
16829                b.unique_of_postcondition_kind(doubled).is_none(),
16830                "doubled postconditions must collapse unique_of_postcondition_kind({doubled:?}) \
16831                 to None",
16832            );
16833            assert!(
16834                b.unique_of_condition_kind(doubled).is_none(),
16835                "doubled postconditions must collapse union unique_of_condition_kind({doubled:?}) \
16836                 to None",
16837            );
16838        }
16839    }
16840}