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` is MISSING 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 "one hole remaining"
1663    /// near-saturation-endpoint on the union of the two condition
1664    /// slots. The near-saturation-endpoint Boolean fast-path peer of
1665    /// [`Self::is_condition_kind_saturated`] on the union axis: where
1666    /// the saturation-endpoint predicate answers "is the union covered
1667    /// by every ALL variant?", `has_unique_missing_condition_kind`
1668    /// answers "is the union one kind away from covered?".
1669    ///
1670    /// Composed body: constructs a two-step-short-circuit walk over
1671    /// [`ConditionKind::ALL`] under the [`Self::has_condition_kind`]
1672    /// union primitive negated — the first missing union arm surfaces,
1673    /// then the walk short-circuits at the second. Byte-for-byte peer
1674    /// of [`ConditionSliceExt::has_unique_missing_kind`] one slice-
1675    /// layer down, lifted to compose against
1676    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1677    /// against a single slice's `has_kind`. A regression at the union
1678    /// primitive fails at the slice-level substrate tests + the union
1679    /// composition-law tests rather than as silent drift here.
1680    ///
1681    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_unique_missing_condition_kind`]
1682    ///
1683    /// Byte-identical signature `(&Self) -> bool`, byte-identical
1684    /// two-step short-circuit body composed against the ephemeral
1685    /// surface's own union primitive. Both methods compose against
1686    /// the SAME slice-level substrate primitive
1687    /// [`ConditionSliceExt::has_unique_missing_kind`] via the two-
1688    /// slice union — a regression at the per-slice near-saturation-
1689    /// endpoint walk fails at that primitive's tests rather than as
1690    /// silent drift at either struct-level near-saturation caller.
1691    ///
1692    /// # Compounding
1693    ///
1694    /// A future operator-facing "one kind away from saturated" gap-
1695    /// analysis diagnostic reads
1696    /// `boundary.has_unique_missing_condition_kind()` at ONE call site
1697    /// rather than restating either `boundary.missing_condition_kind_count() == 1`
1698    /// (which walks every slot to count) or
1699    /// `boundary.missing_condition_kinds().len() == 1` (which
1700    /// allocates the Vec). A `has-unique-missing-condition-kind`
1701    /// require-tag classifier arm reaches this primitive at ONE
1702    /// substrate call — byte-for-byte peer of the tagged-union
1703    /// `has-unique-missing-kind` classifier one struct-layer up.
1704    ///
1705    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1706    /// preserves proofs — the cardinality-mid-endpoint projection on
1707    /// the missing axis composes the SAME two-step short-circuit walk
1708    /// under a two-slice union negation on both this boundary surface
1709    /// and the ephemeral surface). THEORY.md §VI.1 (generation over
1710    /// composition — a new [`ConditionKind`] variant reaches both
1711    /// surfaces' cardinality-mid-endpoint triads mechanically through
1712    /// the delegated union primitive).
1713    #[must_use]
1714    pub fn has_unique_missing_condition_kind(&self) -> bool {
1715        let mut it = ConditionKind::ALL
1716            .iter()
1717            .copied()
1718            .filter(|k| !self.has_condition_kind(*k));
1719        it.next().is_some() && it.next().is_none()
1720    }
1721
1722    /// `true` iff [`Self::preconditions`] is MISSING EXACTLY ONE
1723    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
1724    /// the (precondition, postcondition, condition-union) cardinality-
1725    /// mid-endpoint triad on [`Boundary`]. Thin typed delegate to
1726    /// [`ConditionSliceExt::has_unique_missing_kind`] over
1727    /// [`Self::preconditions`].
1728    ///
1729    /// Peer of [`Self::has_unique_missing_postcondition_kind`] on the
1730    /// (precondition, postcondition) partition of the boundary's two
1731    /// condition-vector slots; both peers compose against the SAME
1732    /// slice-level substrate primitive so a regression at the per-
1733    /// slice two-step short-circuit walk under negation fails at that
1734    /// primitive's tests rather than as silent drift at either
1735    /// struct-level arm.
1736    #[must_use]
1737    pub fn has_unique_missing_precondition_kind(&self) -> bool {
1738        self.preconditions.has_unique_missing_kind()
1739    }
1740
1741    /// `true` iff [`Self::postconditions`] is MISSING EXACTLY ONE
1742    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
1743    /// the (precondition, postcondition, condition-union) cardinality-
1744    /// mid-endpoint triad on [`Boundary`]. Thin typed delegate to
1745    /// [`ConditionSliceExt::has_unique_missing_kind`] over
1746    /// [`Self::postconditions`].
1747    ///
1748    /// Peer of [`Self::has_unique_missing_precondition_kind`]. See
1749    /// that method for the full rationale — the two methods share ONE
1750    /// lift motivation, ONE fail-before-pass-after composition-law
1751    /// pin, and ONE two-surface parity contract with the ephemeral
1752    /// sugar type via
1753    /// [`crate::ephemeral::EphemeralSpec::has_unique_missing_postcondition_kind`].
1754    #[must_use]
1755    pub fn has_unique_missing_postcondition_kind(&self) -> bool {
1756        self.postconditions.has_unique_missing_kind()
1757    }
1758
1759    /// `true` iff `preconditions ∪ postconditions` is MISSING AT
1760    /// LEAST TWO [`ConditionKind::ALL`] variants — the union arm of
1761    /// the (precondition, postcondition, condition-union) cardinality-
1762    /// many-arm triad on [`Boundary`] closing the "≥ 2 holes
1763    /// remaining" arm on the union of the two condition slots. The
1764    /// many-arm Boolean fast-path peer of
1765    /// [`Self::has_unique_missing_condition_kind`] (=1 arm) and
1766    /// [`Self::is_condition_kind_saturated`] (=0 arm) on the union
1767    /// axis, closing the {0, 1, ≥2} trichotomy at the union struct
1768    /// layer.
1769    ///
1770    /// Composed body: constructs a two-step-short-circuit walk over
1771    /// [`ConditionKind::ALL`] under the [`Self::has_condition_kind`]
1772    /// union primitive negated — pulls up to two hits off the
1773    /// filtered iterator; the primitive returns `true` iff BOTH the
1774    /// first and the second are [`Some`]. Byte-for-byte peer of
1775    /// [`ConditionSliceExt::has_multiple_missing_kinds`] one slice-
1776    /// layer down, lifted to compose against
1777    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1778    /// against a single slice's `has_kind`. A regression at the union
1779    /// primitive fails at the slice-level substrate tests + the union
1780    /// composition-law tests rather than as silent drift here.
1781    ///
1782    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_multiple_missing_condition_kind`]
1783    ///
1784    /// Byte-identical signature `(&Self) -> bool`, byte-identical
1785    /// two-step short-circuit body composed against the ephemeral
1786    /// surface's own union primitive. Both methods compose against
1787    /// the SAME slice-level substrate primitive
1788    /// [`ConditionSliceExt::has_multiple_missing_kinds`] via the two-
1789    /// slice union — a regression at the per-slice many-arm walk
1790    /// fails at that primitive's tests rather than as silent drift at
1791    /// either struct-level many-missing caller.
1792    ///
1793    /// # Compounding
1794    ///
1795    /// A future operator-facing "≥ 2 dependencies still unfulfilled"
1796    /// gap-analysis diagnostic reads
1797    /// `boundary.has_multiple_missing_condition_kind()` at ONE call
1798    /// site rather than restating
1799    /// `boundary.missing_condition_kind_count() >= 2` (which walks
1800    /// every slot to count) or
1801    /// `boundary.missing_condition_kinds().len() >= 2` (which
1802    /// allocates the Vec). A `has-multiple-missing-condition-kind`
1803    /// require-tag classifier arm reaches this primitive at ONE
1804    /// substrate call — byte-for-byte peer of the tagged-union
1805    /// `has-multiple-missing-kinds` classifier one struct-layer up.
1806    ///
1807    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1808    /// preserves proofs — the cardinality-many-arm projection on the
1809    /// missing axis composes the SAME two-step short-circuit walk
1810    /// under a two-slice union negation on both this boundary surface
1811    /// and the ephemeral surface). THEORY.md §VI.1 (generation over
1812    /// composition — a new [`ConditionKind`] variant reaches both
1813    /// surfaces' cardinality-many-arm triads mechanically through the
1814    /// delegated union primitive).
1815    #[must_use]
1816    pub fn has_multiple_missing_condition_kind(&self) -> bool {
1817        let mut it = ConditionKind::ALL
1818            .iter()
1819            .copied()
1820            .filter(|k| !self.has_condition_kind(*k));
1821        it.next().is_some() && it.next().is_some()
1822    }
1823
1824    /// `true` iff [`Self::preconditions`] is MISSING AT LEAST TWO
1825    /// [`ConditionKind::ALL`] variants — the precondition-side arm of
1826    /// the (precondition, postcondition, condition-union) cardinality-
1827    /// many-arm triad on [`Boundary`]. Thin typed delegate to
1828    /// [`ConditionSliceExt::has_multiple_missing_kinds`] over
1829    /// [`Self::preconditions`].
1830    ///
1831    /// Peer of [`Self::has_multiple_missing_postcondition_kind`] on
1832    /// the (precondition, postcondition) partition of the boundary's
1833    /// two condition-vector slots; both peers compose against the
1834    /// SAME slice-level substrate primitive so a regression at the
1835    /// per-slice two-step short-circuit walk under negation fails at
1836    /// that primitive's tests rather than as silent drift at either
1837    /// struct-level arm.
1838    #[must_use]
1839    pub fn has_multiple_missing_precondition_kind(&self) -> bool {
1840        self.preconditions.has_multiple_missing_kinds()
1841    }
1842
1843    /// `true` iff [`Self::postconditions`] is MISSING AT LEAST TWO
1844    /// [`ConditionKind::ALL`] variants — the postcondition-side arm of
1845    /// the (precondition, postcondition, condition-union) cardinality-
1846    /// many-arm triad on [`Boundary`]. Thin typed delegate to
1847    /// [`ConditionSliceExt::has_multiple_missing_kinds`] over
1848    /// [`Self::postconditions`].
1849    ///
1850    /// Peer of [`Self::has_multiple_missing_precondition_kind`]. See
1851    /// that method for the full rationale — the two methods share ONE
1852    /// lift motivation, ONE fail-before-pass-after composition-law
1853    /// pin, and ONE two-surface parity contract with the ephemeral
1854    /// sugar type via
1855    /// [`crate::ephemeral::EphemeralSpec::has_multiple_missing_postcondition_kind`].
1856    #[must_use]
1857    pub fn has_multiple_missing_postcondition_kind(&self) -> bool {
1858        self.postconditions.has_multiple_missing_kinds()
1859    }
1860
1861    /// `true` iff `preconditions ∪ postconditions` is MISSING AT MOST
1862    /// ONE [`ConditionKind::ALL`] variant — the union arm of the
1863    /// (precondition, postcondition, condition-union) cardinality
1864    /// "≤ 1" triad on [`Boundary`] closing the "at most one hole
1865    /// remaining" arm on the union of the two condition slots. The
1866    /// Boolean cardinality "≤ 1" negation peer of
1867    /// [`Self::has_multiple_missing_condition_kind`] (≥ 2 many-arm)
1868    /// under the definitional negation
1869    /// `!has_multiple_missing_condition_kind`, and the trichotomy-
1870    /// union peer of [`Self::is_condition_kind_saturated`] (=0
1871    /// zero-arm) OR [`Self::has_unique_missing_condition_kind`] (=1
1872    /// mid-endpoint) — the arrangement space where the boundary is
1873    /// SATURATED-OR-NEAR-SATURATED (zero or exactly one kind missing
1874    /// across the union of the two slices).
1875    ///
1876    /// Composed body: `!self.has_multiple_missing_condition_kind()` —
1877    /// a definitional negation of the many-arm union primitive. Short-
1878    /// circuits transitively through
1879    /// [`Self::has_multiple_missing_condition_kind`]'s two-step short-
1880    /// circuit walk over [`ConditionKind::ALL`] under negated
1881    /// [`Self::has_condition_kind`] — returns `true` as soon as the
1882    /// many-arm walk stops with fewer than two missing hits, WITHOUT
1883    /// materializing [`Self::missing_condition_kinds`]'s `Vec` and
1884    /// WITHOUT walking every slot to build
1885    /// [`Self::missing_condition_kind_count`]'s scalar. Byte-for-byte
1886    /// peer of [`ConditionSliceExt::has_at_most_one_missing_kind`] one
1887    /// slice-layer down, lifted to compose against
1888    /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1889    /// against a single slice's `has_kind`. A regression at the union
1890    /// primitive fails at the slice-level substrate tests + the union
1891    /// composition-law tests rather than as silent drift here.
1892    ///
1893    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_at_most_one_missing_condition_kind`]
1894    ///
1895    /// Byte-identical signature `(&Self) -> bool`, byte-identical
1896    /// definitional-negation body composed against the ephemeral
1897    /// surface's own many-arm union primitive. Both methods compose
1898    /// against the SAME slice-level substrate primitive
1899    /// [`ConditionSliceExt::has_at_most_one_missing_kind`] via the
1900    /// two-slice union — a regression at the per-slice "≤ 1" negation
1901    /// fails at that primitive's tests rather than as silent drift at
1902    /// either struct-level near-saturation-or-saturated caller.
1903    ///
1904    /// # Compounding
1905    ///
1906    /// A future operator-facing "at most one dependency still
1907    /// unfulfilled" gap-analysis diagnostic reads
1908    /// `boundary.has_at_most_one_missing_condition_kind()` at ONE call
1909    /// site rather than restating
1910    /// `boundary.missing_condition_kind_count() <= 1` (which walks every
1911    /// slot to count) or `boundary.missing_condition_kinds().len() <= 1`
1912    /// (which allocates the Vec) or the union of the two Booleans
1913    /// `boundary.is_condition_kind_saturated() ||
1914    /// boundary.has_unique_missing_condition_kind()` (which walks the
1915    /// closed-set-complement scan twice). A `has-at-most-one-missing-
1916    /// condition-kind` require-tag classifier arm reaches this
1917    /// primitive at ONE substrate call — byte-for-byte peer of the
1918    /// tagged-union `has-at-most-one-missing-kind` classifier one
1919    /// struct-layer up, closing the {0, 1, ≥ 2, ≤ 1} cardinality-
1920    /// Boolean grid on the missing axis at the Boundary struct layer
1921    /// alongside its sibling `has-multiple-missing-condition-kind`
1922    /// under the Boolean negation axis.
1923    ///
1924    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1925    /// preserves proofs — the cardinality "≤ 1" projection on the
1926    /// missing axis composes the SAME definitional negation of the
1927    /// many-arm two-step short-circuit walk on both this boundary
1928    /// surface and the ephemeral surface). THEORY.md §VI.1 (generation
1929    /// over composition — a new [`ConditionKind`] variant reaches both
1930    /// surfaces' cardinality "≤ 1" triads mechanically through the
1931    /// delegated union primitive).
1932    #[must_use]
1933    pub fn has_at_most_one_missing_condition_kind(&self) -> bool {
1934        !self.has_multiple_missing_condition_kind()
1935    }
1936
1937    /// `true` iff [`Self::preconditions`] is MISSING AT MOST ONE
1938    /// [`ConditionKind::ALL`] variant — the precondition-side arm of
1939    /// the (precondition, postcondition, condition-union) cardinality
1940    /// "≤ 1" triad on [`Boundary`]. Thin typed delegate to
1941    /// [`ConditionSliceExt::has_at_most_one_missing_kind`] over
1942    /// [`Self::preconditions`].
1943    ///
1944    /// Peer of [`Self::has_at_most_one_missing_postcondition_kind`]
1945    /// on the (precondition, postcondition) partition of the boundary's
1946    /// two condition-vector slots; both peers compose against the SAME
1947    /// slice-level substrate primitive so a regression at the per-
1948    /// slice "≤ 1" negation of the many-arm walk fails at that
1949    /// primitive's tests rather than as silent drift at either
1950    /// struct-level arm.
1951    #[must_use]
1952    pub fn has_at_most_one_missing_precondition_kind(&self) -> bool {
1953        self.preconditions.has_at_most_one_missing_kind()
1954    }
1955
1956    /// `true` iff [`Self::postconditions`] is MISSING AT MOST ONE
1957    /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
1958    /// the (precondition, postcondition, condition-union) cardinality
1959    /// "≤ 1" triad on [`Boundary`]. Thin typed delegate to
1960    /// [`ConditionSliceExt::has_at_most_one_missing_kind`] over
1961    /// [`Self::postconditions`].
1962    ///
1963    /// Peer of [`Self::has_at_most_one_missing_precondition_kind`].
1964    /// See that method for the full rationale — the two methods share
1965    /// ONE lift motivation, ONE fail-before-pass-after composition-
1966    /// law pin, and ONE two-surface parity contract with the
1967    /// ephemeral sugar type via
1968    /// [`crate::ephemeral::EphemeralSpec::has_at_most_one_missing_postcondition_kind`].
1969    #[must_use]
1970    pub fn has_at_most_one_missing_postcondition_kind(&self) -> bool {
1971        self.postconditions.has_at_most_one_missing_kind()
1972    }
1973
1974    /// `true` iff `preconditions ∪ postconditions` carries NO
1975    /// [`Condition`] with the given [`ConditionKind`] — the union arm
1976    /// of the (precondition, postcondition, condition-union)
1977    /// per-kind-complement triad on [`Boundary`], definitional
1978    /// negation of [`Self::has_condition_kind`].
1979    ///
1980    /// # Composed body
1981    ///
1982    /// `!self.has_condition_kind(kind)` — the definitional negation
1983    /// of the two-slice union primitive. Equivalent to the AND of the
1984    /// two half-slice per-kind-complement arms
1985    /// (`self.lacks_precondition_kind(k) && self.lacks_postcondition_kind(k)`),
1986    /// by the boolean identity `!(a || b) == !a && !b`. Both forms
1987    /// return `true` iff BOTH slices lack the addressed kind; the
1988    /// composed body chosen here short-circuits through the union
1989    /// primitive so a regression at the per-slice presence probe fails
1990    /// at that primitive's tests rather than as silent drift at either
1991    /// half-slice complement arm. Equivalent to
1992    /// `self.missing_condition_kinds().contains(&kind)` without
1993    /// materializing the closed-set-complement Vec at every callsite.
1994    ///
1995    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::lacks_condition_kind`]
1996    ///
1997    /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
1998    /// byte-identical `!self.has_condition_kind(kind)` body, on the
1999    /// sugar-surface type whose pre/post condition vectors live
2000    /// directly on the struct. Both methods compose against the SAME
2001    /// slice-level substrate primitive
2002    /// [`ConditionSliceExt::lacks_kind`] via the two-slice union
2003    /// composed through [`Self::has_condition_kind`] — a regression
2004    /// at the per-slice negation fails at that primitive's tests
2005    /// rather than as silent drift at either struct-level complement
2006    /// caller.
2007    ///
2008    /// # Compounding
2009    ///
2010    /// A `lacks-<kind>` require-tag classifier arm — byte-for-byte
2011    /// peer of the tagged-union `lacks-<kind>` classifier one struct-
2012    /// layer up + the future `condition-<kind>` require-tag family's
2013    /// negated dual — reaches this primitive at ONE call site rather
2014    /// than negating `boundary.has_condition_kind(k)` at the callsite
2015    /// or restating `boundary.missing_condition_kinds().contains(&k)`
2016    /// with its allocation.
2017    ///
2018    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2019    /// preserves proofs — the per-kind closed-set-complement
2020    /// projection composes the SAME two-slice union negation on both
2021    /// this boundary surface and the slice-level substrate primitive
2022    /// under definitional negation). THEORY.md §VI.1 (generation over
2023    /// composition — a new [`ConditionKind`] variant reaches both
2024    /// surfaces' complement-triads mechanically through the delegated
2025    /// union primitive).
2026    #[must_use]
2027    pub fn lacks_condition_kind(&self, kind: ConditionKind) -> bool {
2028        !self.has_condition_kind(kind)
2029    }
2030
2031    /// `true` iff [`Self::preconditions`] carries NO [`Condition`]
2032    /// with the given [`ConditionKind`] — the precondition-side arm
2033    /// of the (precondition, postcondition, condition-union)
2034    /// per-kind-complement triad on [`Boundary`]. Thin typed delegate
2035    /// to [`ConditionSliceExt::lacks_kind`] over
2036    /// [`Self::preconditions`].
2037    ///
2038    /// Peer of [`Self::lacks_postcondition_kind`] on the (precondition,
2039    /// postcondition) partition of the boundary's two condition-vector
2040    /// slots; both peers compose against the SAME slice-level substrate
2041    /// primitive so a regression at the per-slice negation fails at
2042    /// that primitive's tests rather than as silent drift at either
2043    /// struct-level arm.
2044    #[must_use]
2045    pub fn lacks_precondition_kind(&self, kind: ConditionKind) -> bool {
2046        self.preconditions.lacks_kind(kind)
2047    }
2048
2049    /// `true` iff [`Self::postconditions`] carries NO [`Condition`]
2050    /// with the given [`ConditionKind`] — the postcondition-side arm
2051    /// of the (precondition, postcondition, condition-union)
2052    /// per-kind-complement triad on [`Boundary`]. Thin typed delegate
2053    /// to [`ConditionSliceExt::lacks_kind`] over
2054    /// [`Self::postconditions`].
2055    ///
2056    /// Peer of [`Self::lacks_precondition_kind`]. See that method for
2057    /// the full rationale — the two methods share ONE lift motivation,
2058    /// ONE fail-before-pass-after composition-law pin, and ONE
2059    /// two-surface parity contract with the ephemeral sugar type via
2060    /// [`crate::ephemeral::EphemeralSpec::lacks_postcondition_kind`].
2061    #[must_use]
2062    pub fn lacks_postcondition_kind(&self, kind: ConditionKind) -> bool {
2063        self.postconditions.lacks_kind(kind)
2064    }
2065
2066    /// `true` iff `preconditions ∪ postconditions` carries at least
2067    /// one [`Condition`] with the given [`ConditionKind`] AND carries
2068    /// no [`Condition`] whose kind is anything OTHER than `kind` — the
2069    /// union arm of the (precondition, postcondition, condition-union)
2070    /// kind-scoped strict-refinement triad on [`Boundary`], byte-for-
2071    /// byte peer of the per-kind presence probe
2072    /// [`Self::has_condition_kind`] under the well-formed-diagonal
2073    /// refinement.
2074    ///
2075    /// # Composed body
2076    ///
2077    /// A FUSED short-circuit closed-set walk over
2078    /// [`ConditionKind::ALL`] under [`Self::has_condition_kind`] that
2079    /// returns `false` at the EARLIEST kind whose presence spans
2080    /// either slice's populated set and is NOT `kind`, and returns
2081    /// `true` iff the sweep completes with `kind` seen as the sole
2082    /// distinct populated kind. Strictly cheaper than the widened
2083    /// composition
2084    /// `boundary.distinct_condition_kinds() == vec![kind]` (which
2085    /// allocates the distinct-kind Vec before the equality test) or
2086    /// the (pre, post) AND-of-strict-refinement
2087    /// `boundary.preconditions.has_only_kind(kind)
2088    ///     && boundary.postconditions.has_only_kind(kind)` (which is
2089    /// TOO STRICT — a single-slice-populated arrangement whose empty
2090    /// side returns `false` fails this AND but IS well-formed on the
2091    /// union).
2092    ///
2093    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_only_condition_kind`]
2094    ///
2095    /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
2096    /// byte-identical fused-closed-set-walk body, on the sugar-surface
2097    /// type whose pre/post condition vectors live directly on the
2098    /// struct. Both methods compose against the SAME slice-level
2099    /// substrate primitive [`ConditionSliceExt::has_only_kind`] via
2100    /// the two-slice union composed through
2101    /// [`Self::has_condition_kind`] — a regression at the per-slice
2102    /// fused walk fails at that primitive's tests rather than as
2103    /// silent drift at either struct-level kind-scoped-strict-
2104    /// refinement caller.
2105    ///
2106    /// # Compounding
2107    ///
2108    /// A future coherence check verifying "every attested closed-loop
2109    /// probe Process carries ONLY `ClosedLoopAuth` postconditions on
2110    /// the union of pre + post" reads
2111    /// `boundary.has_only_condition_kind(ConditionKind::ClosedLoopAuth)`
2112    /// at ONE call site rather than restating either widened
2113    /// composition. A `has-only-<kind>` require-tag classifier arm
2114    /// reaches this primitive at ONE substrate call — byte-for-byte
2115    /// peer of the tagged-union `has-only-<kind>` classifier one
2116    /// struct-layer up, closing the kind-scoped strict-refinement
2117    /// grid on the well-formed-diagonal arm at the Boundary struct
2118    /// layer alongside its sibling `has-<kind>` under the per-kind
2119    /// presence-probe axis.
2120    ///
2121    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2122    /// preserves proofs — the kind-scoped strict-refinement projection
2123    /// composes the SAME fused short-circuit closed-set walk under
2124    /// [`Self::has_condition_kind`] on both this boundary surface and
2125    /// the ephemeral surface). THEORY.md §VI.1 (generation over
2126    /// composition — a new [`ConditionKind`] variant reaches both
2127    /// surfaces' kind-scoped strict-refinement triads mechanically
2128    /// through the delegated union primitive).
2129    #[must_use]
2130    pub fn has_only_condition_kind(&self, kind: ConditionKind) -> bool {
2131        let mut saw_kind = false;
2132        for k in ConditionKind::ALL {
2133            if !self.has_condition_kind(k) {
2134                continue;
2135            }
2136            if k == kind {
2137                saw_kind = true;
2138            } else {
2139                return false;
2140            }
2141        }
2142        saw_kind
2143    }
2144
2145    /// `true` iff [`Self::preconditions`] carries at least one
2146    /// [`Condition`] with the given [`ConditionKind`] AND carries no
2147    /// [`Condition`] whose kind is anything OTHER than `kind` — the
2148    /// precondition-side arm of the (precondition, postcondition,
2149    /// condition-union) kind-scoped strict-refinement triad on
2150    /// [`Boundary`]. Thin typed delegate to
2151    /// [`ConditionSliceExt::has_only_kind`] over
2152    /// [`Self::preconditions`].
2153    ///
2154    /// Peer of [`Self::has_only_postcondition_kind`] on the
2155    /// (precondition, postcondition) partition of the boundary's two
2156    /// condition-vector slots; both peers compose against the SAME
2157    /// slice-level substrate primitive so a regression at the per-
2158    /// slice fused walk fails at that primitive's tests rather than
2159    /// as silent drift at either struct-level arm.
2160    #[must_use]
2161    pub fn has_only_precondition_kind(&self, kind: ConditionKind) -> bool {
2162        self.preconditions.has_only_kind(kind)
2163    }
2164
2165    /// `true` iff [`Self::postconditions`] carries at least one
2166    /// [`Condition`] with the given [`ConditionKind`] AND carries no
2167    /// [`Condition`] whose kind is anything OTHER than `kind` — the
2168    /// postcondition-side arm of the (precondition, postcondition,
2169    /// condition-union) kind-scoped strict-refinement triad on
2170    /// [`Boundary`]. Thin typed delegate to
2171    /// [`ConditionSliceExt::has_only_kind`] over
2172    /// [`Self::postconditions`].
2173    ///
2174    /// Peer of [`Self::has_only_precondition_kind`]. See that method
2175    /// for the full rationale — the two methods share ONE lift
2176    /// motivation, ONE fail-before-pass-after composition-law pin,
2177    /// and ONE two-surface parity contract with the ephemeral sugar
2178    /// type via
2179    /// [`crate::ephemeral::EphemeralSpec::has_only_postcondition_kind`].
2180    #[must_use]
2181    pub fn has_only_postcondition_kind(&self, kind: ConditionKind) -> bool {
2182        self.postconditions.has_only_kind(kind)
2183    }
2184
2185    /// `true` iff `preconditions ∪ postconditions` carries NO
2186    /// [`Condition`] with the given [`ConditionKind`] AND carries at
2187    /// least one [`Condition`] for every OTHER [`ConditionKind`] — the
2188    /// union arm of the (precondition, postcondition, condition-union)
2189    /// kind-scoped strict-refinement triad on [`Boundary`] specialized
2190    /// to the MISSING axis, byte-for-byte peer of the populated-axis
2191    /// [`Self::has_only_condition_kind`] under closed-set complement.
2192    ///
2193    /// # Composed body
2194    ///
2195    /// A FUSED short-circuit closed-set walk over
2196    /// [`ConditionKind::ALL`] under [`Self::has_condition_kind`] that
2197    /// skips every populated kind, returns `false` at the EARLIEST
2198    /// kind whose absence spans both slices' missing sets and is NOT
2199    /// `kind`, and returns `true` iff the sweep completes with `kind`
2200    /// seen as the sole missing kind. Strictly cheaper than the
2201    /// widened composition
2202    /// `boundary.missing_condition_kinds() == vec![kind]` (which
2203    /// allocates the missing-kind Vec before the equality test) or
2204    /// the (pre AND post) AND-of-strict-refinement
2205    /// `boundary.preconditions.lacks_only_kind(kind)
2206    ///     && boundary.postconditions.lacks_only_kind(kind)` (which is
2207    /// TOO STRICT — a single-slice-populated arrangement whose empty
2208    /// side returns `false` fails this AND but IS well-formed on the
2209    /// union).
2210    ///
2211    /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::lacks_only_condition_kind`]
2212    ///
2213    /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
2214    /// byte-identical fused-closed-set-walk body under complement, on
2215    /// the ephemeral sugar surface whose pre/post condition vectors
2216    /// live inline. Both methods compose against the SAME slice-level
2217    /// substrate primitive [`ConditionSliceExt::lacks_only_kind`] via
2218    /// the two-slice union composed through
2219    /// [`Self::has_condition_kind`] — a regression at the per-slice
2220    /// fused walk under complement fails at that primitive's tests
2221    /// rather than as silent drift at either struct-level kind-scoped-
2222    /// strict-refinement-on-missing caller.
2223    ///
2224    /// # Compounding
2225    ///
2226    /// A future coherence check verifying "every partially-attested
2227    /// closed-loop probe Process is missing ONLY the `ClosedLoopAuth`
2228    /// postcondition" reads
2229    /// `boundary.lacks_only_condition_kind(ConditionKind::ClosedLoopAuth)`
2230    /// at ONE call site rather than restating either widened
2231    /// composition. A `lacks-only-<kind>` require-tag classifier arm
2232    /// reaches this primitive at ONE substrate call — byte-for-byte
2233    /// peer of the tagged-union `lacks-only-<kind>` classifier one
2234    /// struct-layer up, CLOSING the kind-scoped strict-refinement 2x2
2235    /// grid on the Boundary struct layer alongside its populated-axis
2236    /// peer [`Self::has_only_condition_kind`].
2237    ///
2238    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2239    /// preserves proofs — the kind-scoped strict-refinement projection
2240    /// on the missing axis composes the SAME fused short-circuit
2241    /// closed-set walk under [`Self::has_condition_kind`] on both this
2242    /// boundary surface and the ephemeral surface). THEORY.md §VI.1
2243    /// (generation over composition — a new [`ConditionKind`] variant
2244    /// reaches both surfaces' kind-scoped strict-refinement-on-missing
2245    /// triads mechanically through the delegated union primitive).
2246    #[must_use]
2247    pub fn lacks_only_condition_kind(&self, kind: ConditionKind) -> bool {
2248        let mut saw_kind = false;
2249        for k in ConditionKind::ALL {
2250            if self.has_condition_kind(k) {
2251                continue;
2252            }
2253            if k == kind {
2254                saw_kind = true;
2255            } else {
2256                return false;
2257            }
2258        }
2259        saw_kind
2260    }
2261
2262    /// `true` iff [`Self::preconditions`] carries NO [`Condition`]
2263    /// with the given [`ConditionKind`] AND carries at least one
2264    /// [`Condition`] for every OTHER [`ConditionKind`] — the
2265    /// precondition-side arm of the (precondition, postcondition,
2266    /// condition-union) kind-scoped strict-refinement-on-missing triad
2267    /// on [`Boundary`]. Thin typed delegate to
2268    /// [`ConditionSliceExt::lacks_only_kind`] over
2269    /// [`Self::preconditions`].
2270    ///
2271    /// Peer of [`Self::lacks_only_postcondition_kind`] on the
2272    /// (precondition, postcondition) partition of the boundary's two
2273    /// condition-vector slots; both peers compose against the SAME
2274    /// slice-level substrate primitive so a regression at the per-
2275    /// slice fused walk under complement fails at that primitive's
2276    /// tests rather than as silent drift at either struct-level arm.
2277    #[must_use]
2278    pub fn lacks_only_precondition_kind(&self, kind: ConditionKind) -> bool {
2279        self.preconditions.lacks_only_kind(kind)
2280    }
2281
2282    /// `true` iff [`Self::postconditions`] carries NO [`Condition`]
2283    /// with the given [`ConditionKind`] AND carries at least one
2284    /// [`Condition`] for every OTHER [`ConditionKind`] — the
2285    /// postcondition-side arm of the (precondition, postcondition,
2286    /// condition-union) kind-scoped strict-refinement-on-missing triad
2287    /// on [`Boundary`]. Thin typed delegate to
2288    /// [`ConditionSliceExt::lacks_only_kind`] over
2289    /// [`Self::postconditions`].
2290    ///
2291    /// Peer of [`Self::lacks_only_precondition_kind`]. See that method
2292    /// for the full rationale — the two methods share ONE lift
2293    /// motivation, ONE fail-before-pass-after composition-law pin,
2294    /// and ONE two-surface parity contract with the ephemeral sugar
2295    /// type via
2296    /// [`crate::ephemeral::EphemeralSpec::lacks_only_postcondition_kind`].
2297    #[must_use]
2298    pub fn lacks_only_postcondition_kind(&self, kind: ConditionKind) -> bool {
2299        self.postconditions.lacks_only_kind(kind)
2300    }
2301}
2302
2303/// Slice-level `(ConditionKind, presence)` probe on any `&[Condition]`
2304/// — the ONE substrate primitive that owns the
2305/// `.iter().any(|c| c.kind == K)` walk shape both current production
2306/// sites hand-authored past the ★★ PRIME-DIRECTIVE ≥ 2 duplication
2307/// threshold. Callers compose the two-half union at their site
2308/// ([`Boundary::has_condition_kind`] on `preconditions ∪
2309/// postconditions`) or on ONE half only (the ephemeral require-tag
2310/// classifier's `closed-loop-auth` arm on `spec.postconditions`) —
2311/// the primitive owns ONLY the per-slice walk, so the composition
2312/// choice stays typed at the caller.
2313///
2314/// # Why lift
2315///
2316/// Pre-lift the `.iter().any(|c| c.kind == K)` walk lived
2317/// hand-authored at THREE production sites: twice inside
2318/// [`Boundary::has_condition_kind`]'s union (pre + post), once at
2319/// `evaluate_ephemeral_require_tag`'s `closed-loop-auth` arm in
2320/// `tatara-reconciler::bin::tatara-check` (with `matches!` sugar
2321/// instead of `==`, but the same predicate). The (`&[Condition]`,
2322/// `ConditionKind`) → `bool` shape is the substrate primitive: a
2323/// future consumer that walks a `Vec<Condition>` (a coherence check
2324/// that verifies "every `ClosedLoopAuth` postcondition carries an
2325/// `issuer` param key", an editor completion listing which
2326/// [`ConditionKind`] arms appear on ONE side only, a hypothetical
2327/// `postcondition-<kind>` require-tag prefix family that dispatches
2328/// on `postconditions` alone — the peer of the existing
2329/// `condition-<kind>` family that dispatches on the pre ∪ post union
2330/// via [`Boundary::has_condition_kind`]) reaches this ONE primitive
2331/// through `slice.has_kind(k)` instead of restating the `.iter().any`
2332/// closure body.
2333///
2334/// # Sibling to [`Boundary::has_condition_kind`]
2335///
2336/// Same axis, one refinement lower: `Boundary::has_condition_kind` is
2337/// the two-slice-union probe; `has_kind` here is the one-slice probe
2338/// the union composes twice. A future normalization at the presence
2339/// probe shape (widening the return to `Option<&Condition>` for
2340/// deeper diagnostics, adding a debug-build assertion on redundant
2341/// duplicates, switching to a linear scan that also counts matches)
2342/// lands at ONE site here — both [`Boundary::has_condition_kind`] +
2343/// every downstream `slice.has_kind(K)` callsite pick it up
2344/// mechanically.
2345///
2346/// # Compounding
2347///
2348/// [`Self::find_kind`] is the widened primitive returning
2349/// `Option<&Condition>` that both `has_kind` (`self.find_kind(k).
2350/// is_some()`, the default body) and future diagnostic consumers
2351/// compose against. A `has_kind_matching(|&Condition| -> bool)`
2352/// predicate extension similarly lands as ONE new default method on
2353/// this trait — the closed-set discriminator case becomes `has_kind(k)
2354/// == self.has_kind_matching(|c| c.kind == k)` by construction, so a
2355/// regression that drifted one from the other becomes structurally
2356/// impossible past the trait boundary.
2357///
2358/// Theory anchor: THEORY.md §II.1 invariant 5 — composition preserves
2359/// proofs; the per-slice walk lives at ONE substrate site so the
2360/// two-half union in [`Boundary`] and the one-half probe on
2361/// [`crate::ephemeral::EphemeralSpec::postconditions`] compose
2362/// through the SAME primitive. THEORY.md §VI.1 — generation over
2363/// composition; a future `Vec<Condition>` consumer reaches the
2364/// primitive through `slice.has_kind(k)` with no per-caller
2365/// restatement of the `.iter().any(|c| c.kind == K)` closure body.
2366pub trait ConditionSliceExt {
2367    /// Returns an iterator yielding every [`Condition`] in this slice
2368    /// whose [`Condition::kind`] equals `kind`, in slice order — the
2369    /// ONE widened primitive on the slice-level presence-probe axis
2370    /// that both [`Self::find_kind`] (via the default
2371    /// `iter_kind(k).next()` body) and [`Self::has_kind`] (via the
2372    /// transitive `find_kind(k).is_some()` default) compose against.
2373    ///
2374    /// # Sibling to [`Self::find_kind`]
2375    ///
2376    /// One refinement wider: `find_kind` collapses the return to
2377    /// `Option<&Condition>` (yielding only the earliest match);
2378    /// `iter_kind` returns the whole match stream so callers can
2379    /// [`count`](Iterator::count) it, [`collect`](Iterator::collect)
2380    /// it into a `Vec<&Condition>`, ask for the
2381    /// [`nth`](Iterator::nth) element, or compose it with any other
2382    /// std iterator adaptor without re-walking the slice. The default
2383    /// body of `find_kind` is `self.iter_kind(kind).next()` — the
2384    /// two methods share ONE walk semantics by construction, so a
2385    /// regression that drifted the first-match probe from the
2386    /// widened stream becomes structurally impossible past the
2387    /// trait boundary.
2388    ///
2389    /// # Semantics
2390    ///
2391    /// Yields `&c` for each `c` in this slice with `c.kind == kind`,
2392    /// in slice order — a slice that carries multiple matches yields
2393    /// each in turn (the composition law
2394    /// `find_kind(k) == iter_kind(k).next()` binds the first match
2395    /// to the earliest position). An empty slice, or a slice with no
2396    /// matching kind, yields nothing. Byte-for-byte equivalent to
2397    /// `self.iter().filter(|c| c.kind == kind)`.
2398    ///
2399    /// # Compounding
2400    ///
2401    /// A future coherence check that verifies "each
2402    /// [`ConditionKind`] appears at most once per side" reads
2403    /// `slice.iter_kind(k).nth(1).is_none()` at ONE call site
2404    /// rather than restating the count-with-filter closure body.
2405    /// A future diagnostic that enumerates every match of a kind
2406    /// (an operator-facing "3 PromQL preconditions matched" message,
2407    /// an audit dump listing every match of a repeated kind) reaches
2408    /// this ONE primitive through `slice.iter_kind(k).collect()`
2409    /// rather than re-walking the slice with `.iter().filter(...)`
2410    /// at the callsite. The presence-probe axis now carries three
2411    /// refinements (bool via `has_kind`, `Option<&Condition>` via
2412    /// `find_kind`, `impl Iterator<Item = &Condition>` via
2413    /// `iter_kind`) at ONE typed algebra surface — every downstream
2414    /// consumer picks the coarsest one that answers its question and
2415    /// the coarser ones stay compositionally derived from this
2416    /// primitive.
2417    fn iter_kind(&self, kind: ConditionKind) -> KindMatches<'_>;
2418
2419    /// Returns the first [`Condition`] in this slice that carries the
2420    /// given [`ConditionKind`], or `None` if none matches. Default
2421    /// body: `self.iter_kind(kind).next()` — a thin projection of the
2422    /// widened primitive [`Self::iter_kind`] onto its first element.
2423    /// The composition law `find_kind(k) == iter_kind(k).next()`
2424    /// binds the first-match probe to the widened stream at the
2425    /// trait's default body.
2426    ///
2427    /// # Sibling to [`Self::has_kind`]
2428    ///
2429    /// One refinement wider: `has_kind` collapses the return to a
2430    /// `bool`; `find_kind` returns the matching `&Condition` so
2431    /// callers can read [`Condition::params`] without re-walking the
2432    /// slice. The default body of `has_kind` is
2433    /// `self.find_kind(kind).is_some()` — the two methods share ONE
2434    /// walk semantics by construction. Byte-for-byte equivalent to
2435    /// `self.iter().find(|c| c.kind == kind)`.
2436    fn find_kind(&self, kind: ConditionKind) -> Option<&Condition> {
2437        self.iter_kind(kind).next()
2438    }
2439
2440    /// True iff at least one [`Condition`] in this slice carries the
2441    /// given [`ConditionKind`]. Default body: `self.find_kind(kind).
2442    /// is_some()`. The single-slice presence probe both
2443    /// [`Boundary::has_condition_kind`] (twice, in a union) and the
2444    /// ephemeral `closed-loop-auth` require-tag arm (once, on
2445    /// postconditions only) compose against.
2446    fn has_kind(&self, kind: ConditionKind) -> bool {
2447        self.find_kind(kind).is_some()
2448    }
2449
2450    /// Number of [`Condition`]s in this slice carrying the given
2451    /// [`ConditionKind`] — the scalar cardinality refinement on the
2452    /// slice-level presence-probe axis. Default body:
2453    /// `self.iter_kind(kind).count()` — a thin projection of the
2454    /// widened primitive [`Self::iter_kind`] onto its cardinality.
2455    ///
2456    /// # Sibling to [`Self::iter_kind`] / [`Self::find_kind`] / [`Self::has_kind`]
2457    ///
2458    /// Fourth refinement on the presence-probe algebra: `iter_kind`
2459    /// yields the whole match stream, `find_kind` collapses it to the
2460    /// first match, `has_kind` collapses that to a `bool`, and
2461    /// `count_kind` collapses the stream to its cardinality without
2462    /// materializing any intermediate [`Vec`] or `Option`. The
2463    /// composition laws
2464    /// `count_kind(k) == iter_kind(k).count()`,
2465    /// `has_kind(k) == (count_kind(k) > 0)`, and
2466    /// `find_kind(k).is_some() == (count_kind(k) > 0)`
2467    /// share ONE walk semantics by construction; a regression that
2468    /// drifted the cardinality probe from the widened stream becomes
2469    /// structurally impossible past the trait boundary.
2470    ///
2471    /// # Semantics
2472    ///
2473    /// Returns `self.iter().filter(|c| c.kind == kind).count()` — a
2474    /// slice that carries multiple matches returns that count, an
2475    /// empty slice or a slice with no matching kind returns `0`.
2476    ///
2477    /// # Compounding
2478    ///
2479    /// A future coherence check that verifies "each [`ConditionKind`]
2480    /// appears at most once per side" now reads
2481    /// `slice.count_kind(k) <= 1` at ONE call site rather than
2482    /// restating either `slice.iter_kind(k).nth(1).is_none()` or the
2483    /// `iter_kind(k).count() <= 1` idiom. A future require-tag
2484    /// classifier arm that surfaces multiplicity to the operator
2485    /// (a hypothetical `condition-count-<kind>` prefix family that
2486    /// publishes the raw cardinality, an audit dump reporting "3
2487    /// PromQL preconditions matched") reaches this ONE primitive
2488    /// through `slice.count_kind(k)` rather than restating the
2489    /// `.iter_kind(k).count()` chain body at the callsite. The
2490    /// presence-probe axis now carries FOUR refinements at ONE typed
2491    /// algebra surface — every downstream consumer picks the coarsest
2492    /// one that answers its question and the coarser ones stay
2493    /// compositionally derived from [`Self::iter_kind`].
2494    fn count_kind(&self, kind: ConditionKind) -> usize {
2495        self.iter_kind(kind).count()
2496    }
2497
2498    /// The set of [`ConditionKind`] variants that appear at least once in
2499    /// this slice, projected in [`ConditionKind::ALL`] order — the
2500    /// closed-set-inversion refinement on the slice-level presence-probe
2501    /// axis. Default body: `ConditionKind::ALL.into_iter().filter(|k|
2502    /// self.has_kind(*k)).collect()` — a thin projection over the closed
2503    /// set that composes against [`Self::has_kind`] per variant.
2504    ///
2505    /// # Sibling to [`Self::has_kind`] / [`Self::find_kind`] / [`Self::iter_kind`] / [`Self::count_kind`]
2506    ///
2507    /// FIFTH refinement on the presence-probe algebra, distinct in axis
2508    /// from the other four: `has_kind` / `find_kind` / `iter_kind` /
2509    /// `count_kind` fix a [`ConditionKind`] and vary the return type
2510    /// (bool / `Option<&Condition>` / `impl Iterator<Item = &Condition>` /
2511    /// `usize`); this refinement INVERTS the axis by fixing the slice and
2512    /// varying over [`ConditionKind::ALL`], returning the SET of present
2513    /// kinds. The composition law
2514    /// `distinct_kinds().contains(&k) == has_kind(k)` for every
2515    /// `k ∈ ConditionKind::ALL` binds the closed-set-inversion probe to
2516    /// the point probe at the trait's default body.
2517    ///
2518    /// # Semantics — canonical subsequence of [`ConditionKind::ALL`]
2519    ///
2520    /// Returns a `Vec<ConditionKind>` whose elements appear in
2521    /// [`ConditionKind::ALL`] order with no duplicates. A slice that
2522    /// carries the same [`ConditionKind`] at multiple positions
2523    /// contributes ONE entry to the returned set (the closed-set
2524    /// projection collapses multiplicity — a caller that needs the
2525    /// per-kind cardinality reaches for [`Self::count_kind`]). An
2526    /// empty slice, or a slice with no matching kind under any
2527    /// [`ConditionKind::ALL`] variant, returns an empty vec.
2528    ///
2529    /// # Why closed-set-inversion is a distinct axis
2530    ///
2531    /// The other four refinements answer "for THIS kind, how does the
2532    /// slice populate the probe's return type?"; this refinement
2533    /// answers "for THIS slice, which kinds appear at least once?".
2534    /// A consumer that needs to enumerate every present kind for an
2535    /// audit dump (`"boundary carries [PromQL, ClosedLoopAuth]"`), a
2536    /// coherence check that verifies "every process's boundary carries
2537    /// at least ONE of {`JobAttested`, `ClosedLoopAuth`}", or a
2538    /// require-tag family that surfaces the distinct-set as a whole
2539    /// (`condition-kinds-distinct-count`) reaches this refinement
2540    /// rather than paying for a per-kind sweep with `has_kind` at the
2541    /// callsite. The point probe stays composable one axis over
2542    /// (`slice.has_kind(k)` for a fixed `k`); the aggregate refinement
2543    /// lives at the same trait, one axis away.
2544    ///
2545    /// # Compounding
2546    ///
2547    /// A future coherence check that enforces "every boundary carries
2548    /// at least ONE distinct kind" (a warning surfaced when
2549    /// `boundary.distinct_condition_kinds().is_empty()`) reaches this
2550    /// ONE primitive rather than paying for the eight-way
2551    /// `for k in ConditionKind::ALL { if boundary.has_condition_kind(k)
2552    /// { return true; } }` sweep at every callsite. A future require-
2553    /// tag classifier arm that publishes the distinct-set cardinality
2554    /// as a scalar (a hypothetical `condition-kinds-distinct-<n>`
2555    /// prefix family, an audit dump reporting "boundary carries N
2556    /// distinct kinds") reaches this ONE primitive through
2557    /// `boundary.distinct_condition_kinds().len()` rather than
2558    /// restating the closed-set-inverted `.iter().filter(...).count()`
2559    /// idiom at every callsite. The presence-probe axis now carries
2560    /// FIVE refinements at ONE typed algebra surface — the four point-
2561    /// probes fixing a kind AND the ONE closed-set-inversion probe
2562    /// fixing a slice — every downstream consumer picks the one that
2563    /// answers its question and the others stay compositionally
2564    /// derived from the single-source-of-truth widened primitive.
2565    ///
2566    /// # Theory grounding
2567    ///
2568    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2569    ///   The closed-set-inversion projection lives at ONE substrate
2570    ///   site as a typed projection of [`Self::has_kind`] over the
2571    ///   closed set [`ConditionKind::ALL`]. Every downstream aggregate
2572    ///   consumer binds through the SAME shape rather than restating
2573    ///   the ALL-filter closure body.
2574    /// - THEORY.md §VI.1 — generation over composition. A new
2575    ///   [`ConditionKind`] variant added to `ALL` reaches this
2576    ///   primitive mechanically (the closed-set walk picks up the new
2577    ///   entry) and every downstream consumer sees the wider set
2578    ///   without further per-caller edit.
2579    fn distinct_kinds(&self) -> Vec<ConditionKind> {
2580        self.iter_distinct_kinds().collect()
2581    }
2582
2583    /// Zero-allocation iterator peer of [`Self::distinct_kinds`] — walk
2584    /// [`ConditionKind::ALL`] in canonical order and yield every
2585    /// [`ConditionKind`] whose corresponding slot on this slice is
2586    /// populated (at least one [`Condition`] with that kind), WITHOUT
2587    /// materializing an intermediate [`Vec<ConditionKind>`].
2588    ///
2589    /// Default body:
2590    /// `ConditionKind::ALL.iter().copied().filter(|&k| self.has_kind(k))`.
2591    /// The composition law
2592    /// `distinct_kinds() == iter_distinct_kinds().collect::<Vec<_>>()`
2593    /// holds by construction — [`Self::distinct_kinds`]'s default body IS
2594    /// `self.iter_distinct_kinds().collect()`, so a caller that overrides
2595    /// the widened Vec primitive with a divergent walk simultaneously
2596    /// drifts both surfaces (surfacing at the substrate testkit
2597    /// [`assert_slice_refinement_composition_laws`] which pins the Vec
2598    /// projection equals `iter().collect()`).
2599    ///
2600    /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
2601    ///
2602    /// Load-bearing iterator peer of the slice-level closed-set-inversion
2603    /// axis — where `distinct_kinds` returns the SET (heap-allocated
2604    /// `Vec`, canonical `ConditionKind::ALL` order) and
2605    /// `distinct_kind_count` scalar-projects its cardinality,
2606    /// `iter_distinct_kinds` opens the walk as a `Copy` iterator so
2607    /// consumers that need a short-circuiting fold (`.any(|k| pred(k))`,
2608    /// `.find(|&k| pred(k))`, `.take_while(|k| pred(k))`, `.map(|k|
2609    /// project(k))`) avoid the intermediate allocation entirely.
2610    ///
2611    /// # Peer to [`crate::tagged_union::TaggedUnion::iter_populated_kinds`]
2612    ///
2613    /// Same shape at the peer axis one struct layer up: where
2614    /// `iter_populated_kinds` opens the closed-set-inversion walk on the
2615    /// tagged-union parent-level presence-probe axis,
2616    /// `iter_distinct_kinds` opens the closed-set-inversion walk on the
2617    /// slice-level presence-probe axis. Both close the "load-bearing
2618    /// iterator" refinement at two adjacent typescape sites through the
2619    /// SAME `<CLOSED_SET>::ALL.iter().copied().filter(|&k| has_probe(k))`
2620    /// composition body under a POSITIVE point-probe.
2621    ///
2622    /// # Compounding future consumers
2623    ///
2624    /// - Every scalar closed-set-inversion peer already at the trait
2625    ///   (`distinct_kind_count`, `first_distinct_kind`,
2626    ///   `last_distinct_kind`, `unique_distinct_kind`,
2627    ///   `has_any_distinct_kind`) folds a specialization of
2628    ///   `ConditionKind::ALL.iter().filter(|k| self.has_kind(**k))` —
2629    ///   they can compose over `iter_distinct_kinds()` at ONE substrate
2630    ///   site rather than restating the closed-set walk body per peer.
2631    /// - A downstream diagnostic composer (an operator-facing "boundary
2632    ///   carries: [{}]" message that streams the label list into a
2633    ///   `write!` buffer) reads `slice.iter_distinct_kinds().map(|k|
2634    ///   k.label())` and folds through `itertools::join` without the
2635    ///   allocation `Vec<ConditionKind> -> String` pays.
2636    ///
2637    /// # Theory grounding
2638    ///
2639    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2640    ///   The load-bearing iterator projection lives at ONE substrate
2641    ///   site; every downstream aggregate consumer refines it through a
2642    ///   standard-library iterator fold rather than restating the
2643    ///   [`ConditionKind::ALL`]-walk closure body.
2644    /// - THEORY.md §VI.1 — generation over composition. A new
2645    ///   [`ConditionKind`] variant added to `ALL` reaches the walk
2646    ///   mechanically (the closed-set filter picks up the new entry) and
2647    ///   every downstream fold sees the wider set without further
2648    ///   per-caller edit.
2649    fn iter_distinct_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
2650        ConditionKind::ALL
2651            .iter()
2652            .copied()
2653            .filter(|&k| self.has_kind(k))
2654    }
2655
2656    /// Scalar cardinality projection of [`Self::distinct_kinds`] onto
2657    /// its `.len()` — the number of [`ConditionKind`] variants that
2658    /// appear at least once in this slice. Default body:
2659    /// `ConditionKind::ALL.iter().filter(|k| self.has_kind(**k)).count()`
2660    /// — a closed-set walk that composes against [`Self::has_kind`] per
2661    /// variant WITHOUT materializing an intermediate `Vec<ConditionKind>`.
2662    /// A slice that carries the same [`ConditionKind`] at multiple
2663    /// positions contributes `1` to the count (the closed-set projection
2664    /// collapses multiplicity — a caller that needs the per-kind
2665    /// cardinality reaches for [`Self::count_kind`]).
2666    ///
2667    /// # Sibling to [`Self::distinct_kinds`]
2668    ///
2669    /// Scalar projection of the closed-set-inversion widened primitive
2670    /// — where `distinct_kinds` returns the SET (a `Vec<ConditionKind>`
2671    /// in canonical [`ConditionKind::ALL`] order), `distinct_kind_count`
2672    /// collapses that set to its cardinality. The composition law
2673    /// `distinct_kind_count() == distinct_kinds().len()` binds the
2674    /// scalar projection to the widened primitive at the trait's
2675    /// default body and is swept substrate-wide by
2676    /// [`assert_slice_refinement_composition_laws`] as its sixth arm.
2677    ///
2678    /// # Peer to [`crate::tagged_union::TaggedUnion::populated_kind_count`]
2679    ///
2680    /// Same shape at the peer axis one struct layer up: where
2681    /// `populated_kind_count` scalar-projects `populated_kinds` on the
2682    /// tagged-union parent-level closed-set-inversion axis,
2683    /// `distinct_kind_count` scalar-projects `distinct_kinds` on the
2684    /// slice-level closed-set-inversion axis. The two primitives close
2685    /// the scalar-cardinality refinement at two adjacent typescape
2686    /// sites — one per closed-set-addressed slice-level refinement,
2687    /// one per closed-set-addressed tagged-union parent-level
2688    /// refinement — through the SAME `ClosedSet::ALL`-walk shape.
2689    ///
2690    /// # Compounding future consumers
2691    ///
2692    /// - A future coherence check that enforces "every boundary carries
2693    ///   at least ONE distinct kind" now reads
2694    ///   `slice.distinct_kind_count() > 0` at ONE call site rather than
2695    ///   paying for `slice.distinct_kinds().len() > 0` (with its
2696    ///   intermediate heap allocation) or the eight-way sweep with
2697    ///   `has_kind` at the callsite.
2698    /// - A future require-tag classifier arm that surfaces the
2699    ///   distinct-set cardinality as a scalar (a hypothetical
2700    ///   `condition-kinds-distinct-<n>` prefix family named in
2701    ///   [`Self::distinct_kinds`]'s doc-comment as a compounding-future
2702    ///   consumer) reaches this ONE primitive without allocating.
2703    /// - A future audit dump reporting "boundary carries N distinct
2704    ///   kinds" reaches `slice.distinct_kind_count()` directly rather
2705    ///   than restating the `.iter().filter(...).count()` closure body.
2706    ///
2707    /// # Theory grounding
2708    ///
2709    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2710    ///   The scalar cardinality lives at ONE substrate site as a typed
2711    ///   projection of [`Self::distinct_kinds`] onto its `.len()`, and
2712    ///   the default body composes against [`Self::has_kind`] over the
2713    ///   closed set [`ConditionKind::ALL`] byte-identically to
2714    ///   `distinct_kinds` without the intermediate `Vec`. Every
2715    ///   downstream aggregate consumer binds through the SAME shape
2716    ///   rather than paying for the allocation to reach the
2717    ///   cardinality.
2718    /// - THEORY.md §VI.1 — generation over composition. A new
2719    ///   [`ConditionKind`] variant added to `ALL` reaches this
2720    ///   primitive mechanically (the closed-set walk picks up the new
2721    ///   entry) and every downstream consumer sees the wider
2722    ///   cardinality without further per-caller edit.
2723    fn distinct_kind_count(&self) -> usize {
2724        ConditionKind::ALL
2725            .iter()
2726            .filter(|k| self.has_kind(**k))
2727            .count()
2728    }
2729
2730    /// The set of [`ConditionKind`] variants that do NOT appear in this
2731    /// slice, projected in [`ConditionKind::ALL`] order — the closed-
2732    /// set-inversion COMPLEMENT of [`Self::distinct_kinds`]. Default
2733    /// body: `ConditionKind::ALL.into_iter().filter(|k|
2734    /// !self.has_kind(*k)).collect()` — a thin projection over the
2735    /// closed set that composes against [`Self::has_kind`] per variant
2736    /// under a negated predicate.
2737    ///
2738    /// # Sibling to [`Self::distinct_kinds`]
2739    ///
2740    /// Complement peer of the closed-set-inversion widened primitive on
2741    /// the slice-level presence-probe axis. Where `distinct_kinds`
2742    /// returns the SET of kinds that DO appear at least once,
2743    /// `missing_kinds` returns the SET of kinds that DO NOT appear.
2744    /// Both walk [`ConditionKind::ALL`] in canonical order and compose
2745    /// against the same [`Self::has_kind`] point probe. The two
2746    /// widened primitives PARTITION [`ConditionKind::ALL`]: their union
2747    /// equals `ConditionKind::ALL`, their intersection is empty, and
2748    /// their cardinalities sum to `ConditionKind::ALL.len()` — three
2749    /// composition laws pinned as the seventh, eighth, and ninth arms
2750    /// of the substrate testkit
2751    /// [`assert_slice_refinement_composition_laws`].
2752    ///
2753    /// # Peer to [`crate::tagged_union::TaggedUnion::populated_kinds`]'s
2754    /// hypothetical `unpopulated_kinds` complement
2755    ///
2756    /// Same shape at the peer axis one struct layer up: fixing the
2757    /// parent-side carrier and inverting the presence probe over the
2758    /// closed set. The two primitives close the "closed-set complement"
2759    /// refinement at two adjacent typescape sites — one per closed-set-
2760    /// addressed slice-level refinement (this primitive), one per
2761    /// closed-set-addressed tagged-union parent-level refinement (a
2762    /// symmetric future addition).
2763    ///
2764    /// # Semantics — canonical subsequence of [`ConditionKind::ALL`]
2765    ///
2766    /// Returns a `Vec<ConditionKind>` whose elements appear in
2767    /// [`ConditionKind::ALL`] order with no duplicates. An empty slice
2768    /// returns `ConditionKind::ALL.to_vec()` (every kind is missing).
2769    /// A slice that carries every variant returns an empty vec (no kind
2770    /// is missing). A slice that carries the same [`ConditionKind`] at
2771    /// multiple positions still contributes ZERO entries to the missing
2772    /// set at that kind (the closed-set complement is a SET operation —
2773    /// multiplicity on the present side is irrelevant to absence on the
2774    /// missing side).
2775    ///
2776    /// # Compounding future consumers
2777    ///
2778    /// - A future coherence check that enforces "every process boundary
2779    ///   carries a [`ConditionKind::JobAttested`] postcondition" now
2780    ///   surfaces the operator-facing diagnostic
2781    ///   `spec.boundary.postconditions.missing_kinds()` verbatim
2782    ///   (naming EVERY kind absent from postconditions in canonical
2783    ///   order) rather than reaching for `!has_kind(JobAttested)` at a
2784    ///   per-kind callsite and paying to re-author the diagnostic list.
2785    /// - An operator-facing "boundary is MISSING [JobAttested,
2786    ///   ClosedLoopAuth]" audit dump reads
2787    ///   `boundary.postconditions.missing_kinds()` directly at ONE call
2788    ///   site rather than restating the negated closed-set walk at
2789    ///   every consumer.
2790    /// - A fleet-wide gap analysis ("which processes are missing a
2791    ///   `ClosedLoopAuth` postcondition") reaches this ONE primitive
2792    ///   through `spec.boundary.postconditions.missing_kinds()
2793    ///   .contains(&ConditionKind::ClosedLoopAuth)` rather than paying
2794    ///   for the negated `.has_kind` sweep at every callsite.
2795    /// - A hypothetical `condition-kinds-missing-<n>` require-tag
2796    ///   classifier prefix family that publishes the missing-set
2797    ///   cardinality as a scalar reads
2798    ///   [`Self::missing_kind_count`] (the scalar-cardinality peer of
2799    ///   this widened primitive) without allocating.
2800    ///
2801    /// # Theory grounding
2802    ///
2803    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2804    ///   The closed-set complement lives at ONE substrate site as a
2805    ///   typed projection of [`Self::has_kind`] over the closed set
2806    ///   [`ConditionKind::ALL`] under negation. Every downstream gap-
2807    ///   analysis consumer binds through the SAME shape rather than
2808    ///   restating the negated ALL-filter closure body.
2809    /// - THEORY.md §VI.1 — generation over composition. A new
2810    ///   [`ConditionKind`] variant added to `ALL` reaches this
2811    ///   primitive mechanically (the closed-set walk picks up the new
2812    ///   entry on the missing side WITHOUT further per-caller edit —
2813    ///   any slice that doesn't yet populate the new kind sees it
2814    ///   listed as missing at every downstream callsite).
2815    fn missing_kinds(&self) -> Vec<ConditionKind> {
2816        self.iter_missing_kinds().collect()
2817    }
2818
2819    /// Zero-allocation iterator peer of [`Self::missing_kinds`] — walk
2820    /// [`ConditionKind::ALL`] in canonical order and yield every
2821    /// [`ConditionKind`] whose corresponding slot on this slice is EMPTY
2822    /// (no [`Condition`] in the slice carries that kind), WITHOUT
2823    /// materializing an intermediate [`Vec<ConditionKind>`].
2824    ///
2825    /// Default body:
2826    /// `ConditionKind::ALL.iter().copied().filter(|&k| !self.has_kind(k))`.
2827    /// The composition law
2828    /// `missing_kinds() == iter_missing_kinds().collect::<Vec<_>>()`
2829    /// holds by construction — [`Self::missing_kinds`]'s default body IS
2830    /// `self.iter_missing_kinds().collect()`, so a caller that overrides
2831    /// the widened Vec primitive with a divergent walk simultaneously
2832    /// drifts both surfaces (surfacing at the substrate testkit
2833    /// [`assert_slice_refinement_composition_laws`] which pins the Vec
2834    /// projection equals `iter().collect()`).
2835    ///
2836    /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
2837    ///
2838    /// Load-bearing iterator peer of the slice-level closed-set-complement
2839    /// axis — where `missing_kinds` returns the SET (heap-allocated `Vec`,
2840    /// canonical `ConditionKind::ALL` order) and `missing_kind_count`
2841    /// scalar-projects its cardinality, `iter_missing_kinds` opens the
2842    /// walk as a `Copy` iterator so consumers that need a short-
2843    /// circuiting fold avoid the intermediate allocation entirely.
2844    ///
2845    /// # Peer to [`Self::iter_distinct_kinds`]
2846    ///
2847    /// Closed-set-COMPLEMENT peer under a NEGATED point-probe. The two
2848    /// iterators PARTITION `ConditionKind::ALL`:
2849    /// `iter_distinct_kinds().chain(iter_missing_kinds()).collect::<HashSet<_>>()`
2850    /// equals `ConditionKind::ALL.iter().copied().collect()`, and the two
2851    /// iterators yield disjoint element sets.
2852    ///
2853    /// # Peer to [`crate::tagged_union::TaggedUnion::iter_missing_kinds`]
2854    ///
2855    /// Same shape at the peer axis one struct layer up: where
2856    /// `iter_missing_kinds` on the tagged-union parent opens the closed-
2857    /// set-complement walk under a negated `has` point-probe, this method
2858    /// opens the SAME walk on the slice-level presence-probe axis under a
2859    /// negated `has_kind` point-probe. Both close the "load-bearing
2860    /// iterator on the complement side" refinement at two adjacent
2861    /// typescape sites through the SAME
2862    /// `<CLOSED_SET>::ALL.iter().copied().filter(|&k| !has_probe(k))`
2863    /// composition body.
2864    ///
2865    /// # Compounding future consumers
2866    ///
2867    /// - Every scalar closed-set-complement peer already at the trait
2868    ///   (`missing_kind_count`, `first_missing_kind`, `last_missing_kind`,
2869    ///   `unique_missing_kind`, `is_kind_saturated`,
2870    ///   `has_any_missing_kind`, `has_unique_missing_kind`,
2871    ///   `has_multiple_missing_kinds`, `has_at_most_one_missing_kind`)
2872    ///   folds a specialization of
2873    ///   `ConditionKind::ALL.iter().filter(|k| !self.has_kind(**k))` —
2874    ///   they can compose over `iter_missing_kinds()` at ONE substrate
2875    ///   site rather than restating the closed-set walk body per peer.
2876    /// - A downstream diagnostic composer (an operator-facing "still
2877    ///   missing: [{}]" message that streams the label list into a
2878    ///   `write!` buffer on the partially-populated arm) reads
2879    ///   `slice.iter_missing_kinds().map(|k| k.label())` and folds through
2880    ///   `itertools::join` without the allocation `Vec<ConditionKind> ->
2881    ///   String` pays.
2882    ///
2883    /// # Theory grounding
2884    ///
2885    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2886    ///   The load-bearing iterator projection on the complement side
2887    ///   lives at ONE substrate site, byte-for-byte symmetrical with
2888    ///   [`Self::iter_distinct_kinds`] under a negated `has_kind`
2889    ///   predicate.
2890    /// - THEORY.md §VI.1 — generation over composition. A new
2891    ///   [`ConditionKind`] variant added to `ALL` reaches the walk
2892    ///   mechanically (the closed-set filter picks up the new entry on
2893    ///   the missing side) and every downstream fold sees the wider
2894    ///   complement without further per-caller edit.
2895    fn iter_missing_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
2896        ConditionKind::ALL
2897            .iter()
2898            .copied()
2899            .filter(|&k| !self.has_kind(k))
2900    }
2901
2902    /// Scalar cardinality projection of [`Self::missing_kinds`] onto its
2903    /// `.len()` — the number of [`ConditionKind`] variants that do NOT
2904    /// appear in this slice. Default body:
2905    /// `ConditionKind::ALL.iter().filter(|k| !self.has_kind(**k)).count()`
2906    /// — a closed-set walk composed against [`Self::has_kind`] per variant
2907    /// under a NEGATED point-probe, WITHOUT materializing the intermediate
2908    /// `Vec<ConditionKind>` a caller reaching only for the scalar
2909    /// cardinality otherwise pays for. An empty slice returns
2910    /// `ConditionKind::ALL.len()` (every kind is missing); a slice
2911    /// carrying every variant returns `0` (no kind is missing).
2912    ///
2913    /// # Sibling to [`Self::missing_kinds`] / [`Self::distinct_kind_count`]
2914    ///
2915    /// Scalar projection of the closed-set-complement widened primitive
2916    /// — where `missing_kinds` returns the SET (a `Vec<ConditionKind>`
2917    /// in canonical [`ConditionKind::ALL`] order), `missing_kind_count`
2918    /// collapses that set to its cardinality. The composition law
2919    /// `missing_kind_count() == missing_kinds().len()` binds the scalar
2920    /// projection to the widened primitive at the trait's default body
2921    /// and is swept substrate-wide by
2922    /// [`assert_slice_refinement_composition_laws`] as its scalar-
2923    /// cardinality-complement arm.
2924    ///
2925    /// Byte-for-byte peer of [`Self::distinct_kind_count`] one axis over
2926    /// (under a negated `has_kind` predicate): where `distinct_kind_count`
2927    /// scalar-projects the closed-set-INVERSION widened primitive
2928    /// `distinct_kinds`, this method scalar-projects the closed-set-
2929    /// COMPLEMENT widened primitive `missing_kinds`. The two scalar
2930    /// projections PARTITION the closed-set cardinality:
2931    /// `distinct_kind_count() + missing_kind_count() ==
2932    /// ConditionKind::ALL.len()` — the scalar consequence of the
2933    /// `(distinct_kinds, missing_kinds)` partition law that
2934    /// [`assert_slice_refinement_composition_laws`] pins at the
2935    /// widened-primitive layer.
2936    ///
2937    /// # Peer to [`crate::tagged_union::TaggedUnion::populated_kind_count`]'s
2938    /// hypothetical complement peer
2939    ///
2940    /// Same shape at the peer axis one struct layer up: fixing the
2941    /// slice-side carrier and inverting the presence probe over the
2942    /// closed set under a negated predicate. The two primitives close
2943    /// the "closed-set-complement scalar cardinality" refinement at
2944    /// two adjacent typescape sites — one per closed-set-addressed
2945    /// slice-level refinement (this primitive), one per closed-set-
2946    /// addressed tagged-union parent-level refinement (a symmetric
2947    /// future addition).
2948    ///
2949    /// # Compounding future consumers
2950    ///
2951    /// - A future coherence check that enforces "every process boundary
2952    ///   carries EVERY [`ConditionKind`] under some slot" now reads
2953    ///   `spec.boundary.postconditions.missing_kind_count() == 0` at
2954    ///   ONE call site rather than paying for
2955    ///   `spec.boundary.postconditions.missing_kinds().is_empty()`
2956    ///   (with its intermediate heap allocation) or the eight-way
2957    ///   negated sweep with `has_kind` at the callsite.
2958    /// - A future require-tag classifier arm that surfaces the missing-
2959    ///   set cardinality as a scalar (the exact
2960    ///   `condition-kinds-missing-<n>` require-tag classifier prefix
2961    ///   family called out in [`Self::missing_kinds`]'s doc-comment as
2962    ///   a hypothetical compounding-future consumer) reaches this ONE
2963    ///   primitive without allocating.
2964    /// - A future gap-analysis dashboard reporting "boundary is missing
2965    ///   N of {N_TOTAL} distinct kinds" reaches
2966    ///   `slice.missing_kind_count()` directly rather than restating the
2967    ///   negated `.iter().filter(...).count()` closure body.
2968    ///
2969    /// # Theory grounding
2970    ///
2971    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2972    ///   The scalar cardinality lives at ONE substrate site as a typed
2973    ///   projection of [`Self::missing_kinds`] onto its `.len()`, and
2974    ///   the default body composes against [`Self::has_kind`] over the
2975    ///   closed set [`ConditionKind::ALL`] under negation byte-
2976    ///   identically to `missing_kinds` without the intermediate `Vec`.
2977    ///   Every downstream aggregate consumer binds through the SAME
2978    ///   shape rather than paying for the allocation to reach the
2979    ///   cardinality.
2980    /// - THEORY.md §VI.1 — generation over composition. A new
2981    ///   [`ConditionKind`] variant added to `ALL` reaches this primitive
2982    ///   mechanically (the closed-set walk picks up the new entry on
2983    ///   the missing side WITHOUT further per-caller edit — any slice
2984    ///   that doesn't yet populate the new kind sees the cardinality
2985    ///   rise by one at every downstream callsite).
2986    fn missing_kind_count(&self) -> usize {
2987        ConditionKind::ALL
2988            .iter()
2989            .filter(|k| !self.has_kind(**k))
2990            .count()
2991    }
2992
2993    /// Short-circuiting `Option<ConditionKind>` peer of
2994    /// [`Self::distinct_kinds`] — the FIRST [`ConditionKind`] variant
2995    /// present in this slice, in canonical [`ConditionKind::ALL`] order,
2996    /// or `None` when the slice carries no matching kind. Default body:
2997    /// `ConditionKind::ALL.iter().copied().find(|k| self.has_kind(*k))`
2998    /// — a closed-set walk composed against [`Self::has_kind`] per
2999    /// variant that SHORT-CIRCUITS at the earliest match.
3000    ///
3001    /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
3002    ///
3003    /// Third refinement on the closed-set-inversion axis, `Option<ConditionKind>`-
3004    /// valued: `distinct_kinds` returns the SET, `distinct_kind_count`
3005    /// scalar-projects the cardinality, and `first_distinct_kind`
3006    /// scalar-projects the SET onto its earliest element. The composition
3007    /// law `first_distinct_kind() == distinct_kinds().first().copied()`
3008    /// binds the earliest-element projection to the widened primitive at
3009    /// the trait's default body — pinned substrate-wide by
3010    /// [`assert_slice_refinement_composition_laws`] as its
3011    /// earliest-element-inversion arm. Both coarser projections agree on
3012    /// emptiness: `first_distinct_kind().is_none() ==
3013    /// (distinct_kind_count() == 0)`.
3014    ///
3015    /// # Peer to [`crate::tagged_union::TaggedUnion::first_populated_kind`]
3016    ///
3017    /// Same shape at the peer axis one struct layer up: fixing the
3018    /// carrier and short-circuiting on the earliest [`ConditionKind::ALL`]
3019    /// hit under [`Self::has_kind`]. `TaggedUnion::first_populated_kind`
3020    /// walks the tagged-union parent's closed set; `first_distinct_kind`
3021    /// here walks [`ConditionKind::ALL`] on the slice-level presence-probe
3022    /// axis. The two primitives close the "earliest-element scalar-
3023    /// projection of the closed-set-inversion widened primitive"
3024    /// refinement at two adjacent typescape sites — one per closed-set-
3025    /// addressed slice-level refinement (this primitive), one per closed-
3026    /// set-addressed tagged-union parent-level refinement.
3027    ///
3028    /// # Semantics
3029    ///
3030    /// Returns `Some(k)` where `k` is the earliest [`ConditionKind::ALL`]
3031    /// entry with `self.has_kind(k) == true`, or `None` when no kind is
3032    /// present. An empty slice returns `None`. A slice carrying multiple
3033    /// variants returns the earliest one in [`ConditionKind::ALL`] order
3034    /// — a strictly more informative projection than
3035    /// `distinct_kinds().first().copied()` without materializing the
3036    /// intermediate `Vec<ConditionKind>` the widened primitive
3037    /// otherwise pays for.
3038    ///
3039    /// # Compounding future consumers
3040    ///
3041    /// - An operator-facing "first present kind" diagnostic on an audit
3042    ///   dump that names ONE kind rather than the full set reaches this
3043    ///   ONE substrate site rather than paying for
3044    ///   `slice.distinct_kinds().first().copied()` (with its
3045    ///   intermediate heap allocation).
3046    /// - A `first-distinct-<kind>` require-tag classifier arm reads this
3047    ///   primitive with no allocation, byte-for-byte symmetrical with
3048    ///   `slice.has_kind(kind)` under a closed-set-inversion projection.
3049    /// - A fast-path branch that discriminates "empty" from "any
3050    ///   populated" reads `slice.first_distinct_kind().is_some()` at ONE
3051    ///   call site rather than allocating a `Vec<ConditionKind>` through
3052    ///   `!distinct_kinds().is_empty()` or paying for the full
3053    ///   `distinct_kind_count() > 0` walk.
3054    ///
3055    /// # Theory grounding
3056    ///
3057    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs. The
3058    ///   earliest-element projection lives at ONE substrate site as a
3059    ///   typed projection of [`Self::has_kind`] over the closed set
3060    ///   [`ConditionKind::ALL`] under short-circuit walk semantics.
3061    /// - THEORY.md §VI.1 — generation over composition. A new
3062    ///   [`ConditionKind`] variant added to `ALL` reaches this primitive
3063    ///   mechanically (the closed-set walk picks up the new entry) —
3064    ///   every downstream consumer sees the wider earliest-hit projection
3065    ///   without further per-caller edit.
3066    fn first_distinct_kind(&self) -> Option<ConditionKind> {
3067        ConditionKind::ALL
3068            .iter()
3069            .copied()
3070            .find(|k| self.has_kind(*k))
3071    }
3072
3073    /// Short-circuiting `Option<ConditionKind>` peer of
3074    /// [`Self::missing_kinds`] — the FIRST [`ConditionKind`] variant
3075    /// ABSENT from this slice, in canonical [`ConditionKind::ALL`] order,
3076    /// or `None` when the slice carries every variant. Default body:
3077    /// `ConditionKind::ALL.iter().copied().find(|k| !self.has_kind(*k))`
3078    /// — a closed-set walk composed against [`Self::has_kind`] per
3079    /// variant under NEGATION with SHORT-CIRCUIT at the earliest empty
3080    /// slot.
3081    ///
3082    /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
3083    ///
3084    /// Third refinement on the closed-set-complement axis,
3085    /// `Option<ConditionKind>`-valued: `missing_kinds` returns the SET,
3086    /// `missing_kind_count` scalar-projects the cardinality, and
3087    /// `first_missing_kind` scalar-projects the SET onto its earliest
3088    /// element. The composition law
3089    /// `first_missing_kind() == missing_kinds().first().copied()` binds
3090    /// the earliest-element projection to the widened primitive at the
3091    /// trait's default body — pinned substrate-wide by
3092    /// [`assert_slice_refinement_composition_laws`] as its
3093    /// earliest-element-complement arm. Both coarser projections agree
3094    /// on saturation: `first_missing_kind().is_none() ==
3095    /// (missing_kind_count() == 0)`.
3096    ///
3097    /// # Peer to [`Self::first_distinct_kind`]
3098    ///
3099    /// Closed-set-complement peer of the closed-set-inversion earliest-
3100    /// element primitive under a negated `has_kind` predicate. The two
3101    /// primitives PARTITION [`ConditionKind::ALL`]'s earliest-element
3102    /// projection: at least one of `first_distinct_kind()` and
3103    /// `first_missing_kind()` is `Some` on any non-degenerate closed set
3104    /// (both are `Some` iff `1 ≤ distinct_kind_count() <
3105    /// ConditionKind::ALL.len()`; only the distinct-side is `Some` on a
3106    /// saturated slice; only the missing-side is `Some` on an empty
3107    /// slice).
3108    ///
3109    /// # Peer to [`crate::tagged_union::TaggedUnion::first_missing_kind`]
3110    ///
3111    /// Same shape at the peer axis one struct layer up under a negated
3112    /// predicate. The two primitives close the "earliest-element scalar-
3113    /// projection of the closed-set-complement widened primitive"
3114    /// refinement at two adjacent typescape sites — one per closed-set-
3115    /// addressed slice-level refinement (this primitive), one per closed-
3116    /// set-addressed tagged-union parent-level refinement.
3117    ///
3118    /// # Semantics
3119    ///
3120    /// An empty slice returns `Some(ConditionKind::ALL[0])` (every kind
3121    /// missing, first hit is index 0). A slice populating exactly `k`
3122    /// returns `Some(ConditionKind::ALL[0])` if `k != ALL[0]`, else
3123    /// `Some(ALL[1])` (the earliest non-`k` entry). A saturated slice
3124    /// carrying every variant returns `None`.
3125    ///
3126    /// # Compounding future consumers
3127    ///
3128    /// - An operator-facing "first still-unfilled kind" diagnostic on a
3129    ///   partially-populated boundary reads
3130    ///   `boundary.postconditions.first_missing_kind()` at ONE substrate
3131    ///   site — a strictly-more-informative projection than
3132    ///   `!has_kind(JobAttested)` at a per-kind callsite for a fleet-wide
3133    ///   "which processes are missing at least one closed-loop kind"
3134    ///   audit.
3135    /// - A `first-missing-<kind>` require-tag classifier arm reads this
3136    ///   primitive with no allocation, byte-for-byte symmetrical with
3137    ///   `slice.first_distinct_kind()`.
3138    /// - A fast-path branch that discriminates "saturated" from "at least
3139    ///   one missing" reads `slice.first_missing_kind().is_some()` at ONE
3140    ///   call site rather than allocating through
3141    ///   `!missing_kinds().is_empty()` or paying for the full
3142    ///   `missing_kind_count() > 0` walk.
3143    ///
3144    /// # Theory grounding
3145    ///
3146    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs. The
3147    ///   complement-earliest-element projection lives at ONE substrate
3148    ///   site as a typed projection of [`Self::has_kind`] over the
3149    ///   closed set [`ConditionKind::ALL`] under negation with short-
3150    ///   circuit walk semantics.
3151    /// - THEORY.md §VI.1 — generation over composition. A new
3152    ///   [`ConditionKind`] variant added to `ALL` reaches this primitive
3153    ///   mechanically (the closed-set walk picks up the new entry on the
3154    ///   missing side) — every downstream consumer sees the wider
3155    ///   complement's earliest hit without further per-caller edit.
3156    fn first_missing_kind(&self) -> Option<ConditionKind> {
3157        ConditionKind::ALL
3158            .iter()
3159            .copied()
3160            .find(|k| !self.has_kind(*k))
3161    }
3162
3163    /// Short-circuiting `Option<ConditionKind>` peer of
3164    /// [`Self::distinct_kinds`] — the LAST [`ConditionKind`] variant
3165    /// present in this slice, in canonical [`ConditionKind::ALL`]
3166    /// order, or `None` when the slice carries no variant. Default
3167    /// body: `ConditionKind::ALL.iter().rev().copied().find(|k|
3168    /// self.has_kind(*k))` — a REVERSED closed-set walk composed
3169    /// against [`Self::has_kind`] per variant that SHORT-CIRCUITS at
3170    /// the latest hit.
3171    ///
3172    /// # Sibling to [`Self::distinct_kinds`] /
3173    /// [`Self::distinct_kind_count`] / [`Self::first_distinct_kind`]
3174    ///
3175    /// Fourth refinement on the closed-set-inversion axis and second
3176    /// scalar `Option<ConditionKind>` projection: `distinct_kinds`
3177    /// returns the SET, `distinct_kind_count` scalar-projects the
3178    /// cardinality, `first_distinct_kind` scalar-projects the SET
3179    /// onto its earliest element, and `last_distinct_kind` scalar-
3180    /// projects the SET onto its latest element. The composition law
3181    /// `last_distinct_kind() == distinct_kinds().last().copied()`
3182    /// binds the latest-element projection to the widened primitive
3183    /// at the trait's default body — pinned substrate-wide by
3184    /// [`assert_slice_refinement_composition_laws`] as its
3185    /// latest-element-inversion arm. Both scalar projections agree on
3186    /// emptiness: `last_distinct_kind().is_none() ==
3187    /// first_distinct_kind().is_none() == distinct_kinds().is_empty()`.
3188    ///
3189    /// # Peer to [`Self::first_distinct_kind`]
3190    ///
3191    /// Time-reversed peer under the SAME `has_kind` predicate: where
3192    /// `first_distinct_kind` walks [`ConditionKind::ALL`] forward and
3193    /// SHORT-CIRCUITS at the earliest hit, this primitive walks the
3194    /// SAME closed set in reverse and SHORT-CIRCUITS at the latest
3195    /// hit. The two primitives close the "endpoint scalar-projection
3196    /// of the closed-set-inversion widened primitive" refinement pair
3197    /// at one substrate site — one per endpoint. On a slice with
3198    /// exactly one distinct kind both projections agree; on a slice
3199    /// with distinct-kind-count ≥ 2 they yield distinct results
3200    /// (the earliest and latest elements of the closed-set-inversion
3201    /// respectively).
3202    ///
3203    /// # Semantics
3204    ///
3205    /// An empty slice returns `None` (no kind present, no hit on any
3206    /// walk direction). A slice populating exactly `k` returns
3207    /// `Some(k)` (single hit; earliest = latest). A saturated slice
3208    /// carrying every variant returns `Some(ConditionKind::ALL.last()
3209    /// .unwrap())` (the last ALL entry hits at the earliest walk step
3210    /// of the reversed walk).
3211    ///
3212    /// # Compounding future consumers
3213    ///
3214    /// - A `last-distinct-<kind>` require-tag classifier arm reads
3215    ///   the latest-populated kind through this ONE substrate
3216    ///   primitive with no allocation, byte-for-byte symmetrical with
3217    ///   the earliest-hit `slice.first_distinct_kind()` peer.
3218    /// - A future coherence check that surfaces "boundary ends with
3219    ///   ClosedLoopAuth" reads
3220    ///   `spec.boundary.postconditions.last_distinct_kind() ==
3221    ///   Some(ConditionKind::ClosedLoopAuth)` at ONE call site rather
3222    ///   than paying for `spec.boundary.postconditions
3223    ///   .distinct_kinds().last() == Some(&…)` with its intermediate
3224    ///   heap allocation.
3225    /// - Combined with [`Self::first_distinct_kind`], operator
3226    ///   diagnostics that render a "populated-kind range" summary
3227    ///   (`first..=last` on the closed-set-inversion projection) read
3228    ///   the two endpoints through TWO substrate primitives at
3229    ///   symmetric shapes without allocating.
3230    ///
3231    /// # Theory grounding
3232    ///
3233    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3234    ///   The latest-element projection lives at ONE substrate site as
3235    ///   a typed projection of [`Self::has_kind`] over the closed set
3236    ///   [`ConditionKind::ALL`] under REVERSED short-circuit walk
3237    ///   semantics; byte-for-byte peer of the earliest-element
3238    ///   projection under FORWARD walk semantics.
3239    /// - THEORY.md §VI.1 — generation over composition. A new
3240    ///   [`ConditionKind`] variant added to `ALL` reaches this
3241    ///   primitive mechanically (the reversed closed-set walk picks
3242    ///   up the new entry at the appropriate position) — every
3243    ///   downstream consumer sees the wider latest-hit projection
3244    ///   without further per-caller edit.
3245    fn last_distinct_kind(&self) -> Option<ConditionKind> {
3246        ConditionKind::ALL
3247            .iter()
3248            .rev()
3249            .copied()
3250            .find(|k| self.has_kind(*k))
3251    }
3252
3253    /// Short-circuiting `Option<ConditionKind>` peer of
3254    /// [`Self::missing_kinds`] — the LAST [`ConditionKind`] variant
3255    /// ABSENT from this slice, in canonical [`ConditionKind::ALL`]
3256    /// order, or `None` when the slice carries every variant. Default
3257    /// body: `ConditionKind::ALL.iter().rev().copied().find(|k|
3258    /// !self.has_kind(*k))` — a REVERSED closed-set walk composed
3259    /// against [`Self::has_kind`] per variant under NEGATION with
3260    /// SHORT-CIRCUIT at the latest empty slot.
3261    ///
3262    /// # Sibling to [`Self::missing_kinds`] /
3263    /// [`Self::missing_kind_count`] / [`Self::first_missing_kind`]
3264    ///
3265    /// Fourth refinement on the closed-set-complement axis and second
3266    /// scalar `Option<ConditionKind>` projection: `missing_kinds`
3267    /// returns the SET, `missing_kind_count` scalar-projects the
3268    /// cardinality, `first_missing_kind` scalar-projects the SET onto
3269    /// its earliest element, and `last_missing_kind` scalar-projects
3270    /// the SET onto its latest element. The composition law
3271    /// `last_missing_kind() == missing_kinds().last().copied()` binds
3272    /// the latest-element projection to the widened primitive at the
3273    /// trait's default body — pinned substrate-wide by
3274    /// [`assert_slice_refinement_composition_laws`] as its
3275    /// latest-element-complement arm. Both scalar projections agree
3276    /// on saturation: `last_missing_kind().is_none() ==
3277    /// first_missing_kind().is_none() == missing_kinds().is_empty()`.
3278    ///
3279    /// # Peer to [`Self::first_missing_kind`]
3280    ///
3281    /// Time-reversed peer under the SAME negated `has_kind` predicate:
3282    /// where `first_missing_kind` walks [`ConditionKind::ALL`] forward
3283    /// under negation and SHORT-CIRCUITS at the earliest empty slot,
3284    /// this primitive walks the SAME closed set in reverse and SHORT-
3285    /// CIRCUITS at the latest empty slot. The two primitives close
3286    /// the "endpoint scalar-projection of the closed-set-complement
3287    /// widened primitive" refinement pair at one substrate site.
3288    ///
3289    /// # Peer to [`Self::last_distinct_kind`]
3290    ///
3291    /// Closed-set-complement peer of the closed-set-inversion latest-
3292    /// element primitive under a NEGATED `has_kind` predicate. Along
3293    /// with [`Self::first_distinct_kind`] and [`Self::first_missing_kind`]
3294    /// the four scalar-endpoint projections partition the endpoint
3295    /// axis into (present, absent) × (earliest, latest) — every
3296    /// endpoint-addressable coherence check reads ONE of the four at
3297    /// ONE call site, never the full `Vec<ConditionKind>` walk.
3298    ///
3299    /// # Semantics
3300    ///
3301    /// An empty slice returns `Some(ConditionKind::ALL.last().unwrap())`
3302    /// (every kind missing, latest hit is the last ALL entry). A slice
3303    /// populating exactly `k` returns `Some(ALL.last().unwrap())` if
3304    /// `k != ALL.last().unwrap()`, else `Some(ALL[ALL.len() - 2])` (the
3305    /// latest non-`k` entry). A saturated slice carrying every variant
3306    /// returns `None`.
3307    ///
3308    /// # Compounding future consumers
3309    ///
3310    /// - An operator-facing "last still-unfilled kind" diagnostic on a
3311    ///   partially-populated boundary reads
3312    ///   `boundary.postconditions.last_missing_kind()` at ONE substrate
3313    ///   site — a strictly-more-informative projection than
3314    ///   `!has_kind(ClosedLoopAuth)` at a per-kind callsite for a
3315    ///   fleet-wide "which processes are latest-missing a specific
3316    ///   closed-loop kind" audit.
3317    /// - A `last-missing-<kind>` require-tag classifier arm reads this
3318    ///   primitive with no allocation, byte-for-byte symmetrical with
3319    ///   the earliest-hit `slice.first_missing_kind()` peer.
3320    /// - Combined with [`Self::first_missing_kind`], a coherence check
3321    ///   that renders a "missing-kind range" summary reads the two
3322    ///   endpoints through TWO substrate primitives at symmetric
3323    ///   shapes without allocating through `missing_kinds()`.
3324    ///
3325    /// # Theory grounding
3326    ///
3327    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3328    ///   The complement-latest-element projection lives at ONE
3329    ///   substrate site as a typed projection of [`Self::has_kind`]
3330    ///   over the closed set [`ConditionKind::ALL`] under negation
3331    ///   with REVERSED short-circuit walk semantics; byte-for-byte
3332    ///   peer of the complement-earliest-element projection under
3333    ///   FORWARD walk semantics.
3334    /// - THEORY.md §VI.1 — generation over composition. A new
3335    ///   [`ConditionKind`] variant added to `ALL` reaches this
3336    ///   primitive mechanically (the reversed closed-set walk picks
3337    ///   up the new entry on the missing side at the appropriate
3338    ///   position) — every downstream consumer sees the wider
3339    ///   complement's latest hit without further per-caller edit.
3340    fn last_missing_kind(&self) -> Option<ConditionKind> {
3341        ConditionKind::ALL
3342            .iter()
3343            .rev()
3344            .copied()
3345            .find(|k| !self.has_kind(*k))
3346    }
3347
3348    /// Boolean saturation predicate on the closed-set-inversion axis —
3349    /// `true` iff EVERY [`ConditionKind::ALL`] variant appears at least
3350    /// once in this slice (equivalently, [`Self::missing_kinds`] is
3351    /// empty).
3352    ///
3353    /// Default body:
3354    /// `ConditionKind::ALL.iter().all(|k| self.has_kind(*k))` — a
3355    /// SHORT-CIRCUITING closed-set walk composed against [`Self::has_kind`]
3356    /// per variant that returns `false` at the FIRST missing kind,
3357    /// WITHOUT materializing [`Self::missing_kinds`]'s `Vec` and WITHOUT
3358    /// walking every entry to build [`Self::missing_kind_count`]'s
3359    /// scalar. Strictly cheaper than either widened primitive on every
3360    /// partially-populated arm (returns at the first empty slot rather
3361    /// than sweeping the full closed set).
3362    ///
3363    /// # Peer to [`crate::tagged_union::TaggedUnion::is_saturated`]
3364    ///
3365    /// Slice-level peer of the tagged-union parent-level saturation
3366    /// predicate one struct-layer up: where `is_saturated` names the
3367    /// tagged-union arm where every `<Self::Kind as ClosedSet>::ALL`
3368    /// slot is populated, `is_kind_saturated` names the slice arm where
3369    /// every [`ConditionKind::ALL`] variant appears at least once. Both
3370    /// short-circuit at the first missing entry under the SAME
3371    /// `<CLOSED_SET>::ALL.iter().all(has)` walk shape at two adjacent
3372    /// typescape sites.
3373    ///
3374    /// # Sibling to [`Self::missing_kind_count`] / [`Self::missing_kinds`]
3375    ///
3376    /// Boolean cardinality-endpoint peer of the scalar cardinality
3377    /// primitive on the closed-set-complement axis — where
3378    /// `missing_kind_count` returns the FULL scalar (any `usize` in
3379    /// `0..=ConditionKind::ALL.len()`), `is_kind_saturated` collapses
3380    /// that scalar to its zero-arm Boolean projection. The composition
3381    /// law `is_kind_saturated() == (missing_kind_count() == 0)` binds
3382    /// the Boolean projection to the scalar primitive at the trait's
3383    /// default body — swept substrate-wide by
3384    /// [`assert_slice_refinement_composition_laws`] as its
3385    /// saturation-endpoint arm.
3386    ///
3387    /// # Semantics
3388    ///
3389    /// An empty slice returns `false` (no kind is populated). A slice
3390    /// carrying a strict subset of [`ConditionKind::ALL`] returns
3391    /// `false`. A slice that carries every variant at least once
3392    /// (multiplicity is irrelevant) returns `true` — the SOLE arm
3393    /// where `is_kind_saturated` returns `true`.
3394    ///
3395    /// # Compounding future consumers
3396    ///
3397    /// - A future coherence check that enforces "every process boundary
3398    ///   exhaustively covers every [`ConditionKind`]" reads
3399    ///   `boundary.postconditions.is_kind_saturated()` at ONE call site
3400    ///   — one short-circuit walk, no allocation, no scalar equality
3401    ///   comparison against `ConditionKind::ALL.len()`.
3402    /// - An `is-kind-saturated` require-tag classifier arm reaches this
3403    ///   primitive with no allocation, byte-for-byte peer of the
3404    ///   tagged-union `is-saturated` classifier one struct-layer up.
3405    /// - A fleet-wide gap-analysis dashboard fast-path that discriminates
3406    ///   "boundary spans every kind" from "boundary is missing some
3407    ///   kind" reads `boundary.postconditions.is_kind_saturated()` at
3408    ///   ONE call site rather than restating either
3409    ///   `boundary.postconditions.missing_kind_count() == 0` (which
3410    ///   walks every slot to count) or
3411    ///   `boundary.postconditions.missing_kinds().is_empty()` (which
3412    ///   allocates the Vec before the emptiness check).
3413    ///
3414    /// # Theory grounding
3415    ///
3416    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3417    ///   The saturation-endpoint projection lives at ONE substrate
3418    ///   site as a typed short-circuiting closed-set walk
3419    ///   `ConditionKind::ALL.iter().all(has_kind)`. Every downstream
3420    ///   consumer binds through the SAME shape rather than restating
3421    ///   the `== ConditionKind::ALL.len()` scalar composition body.
3422    /// - THEORY.md §VI.1 — generation over composition. A new
3423    ///   [`ConditionKind`] variant added to `ALL` reaches this
3424    ///   primitive mechanically through the `all` short-circuit — a
3425    ///   slice that was previously saturated is no longer saturated
3426    ///   at every downstream callsite unless it also carries the new
3427    ///   variant.
3428    fn is_kind_saturated(&self) -> bool {
3429        ConditionKind::ALL.iter().all(|k| self.has_kind(*k))
3430    }
3431
3432    /// Boolean at-least-one halfspace peer of [`Self::has_any_missing_kind`]
3433    /// on the closed-set-inversion axis — `true` iff AT LEAST ONE
3434    /// [`ConditionKind::ALL`] variant appears at least once in this slice
3435    /// (equivalently, [`Self::distinct_kinds`] is non-empty,
3436    /// [`Self::distinct_kind_count`] `> 0`, and
3437    /// [`Self::first_distinct_kind`] is `Some`).
3438    ///
3439    /// Default body: `ConditionKind::ALL.iter().copied().any(|k|
3440    /// self.has_kind(k))` — a SHORT-CIRCUITING closed-set walk that
3441    /// returns `true` at the FIRST populated kind WITHOUT materializing
3442    /// [`Self::distinct_kinds`]'s `Vec`, WITHOUT walking every slot to
3443    /// build [`Self::distinct_kind_count`]'s scalar, and WITHOUT
3444    /// allocating the closed-set-inversion scan. Strictly cheaper than
3445    /// either widened primitive on every non-empty arm because the walk
3446    /// short-circuits at the first `has_kind` hit rather than paying
3447    /// for the Vec allocation or the full cardinality count.
3448    ///
3449    /// # Peer to [`crate::tagged_union::TaggedUnion::has_any_populated_kind`]
3450    ///
3451    /// Slice-level peer of the tagged-union parent-level at-least-one
3452    /// halfspace predicate one struct-layer up: where
3453    /// [`crate::tagged_union::TaggedUnion::has_any_populated_kind`]
3454    /// answers "is ANY slot on the tagged-union parent occupied?",
3455    /// `has_any_distinct_kind` answers "does ANY kind appear in AT
3456    /// LEAST ONE condition of the slice?". Both compose against a
3457    /// SHORT-CIRCUITING closed-set walk under the SAME `has` /
3458    /// `has_kind` predicate at two adjacent typescape sites — the two
3459    /// primitives close the at-least-one halfspace on the closed-set-
3460    /// inversion axis at both struct layers under the SAME shape.
3461    ///
3462    /// # Sibling to [`Self::has_any_missing_kind`]
3463    ///
3464    /// Closed-set-inversion peer of the at-least-one halfspace on the
3465    /// closed-set-complement axis — where `has_any_missing_kind`
3466    /// returns `true` iff at least one kind is ABSENT,
3467    /// `has_any_distinct_kind` returns `true` iff at least one kind is
3468    /// PRESENT. Together with their zero-arm endpoints
3469    /// ([`Self::is_kind_saturated`] on the missing axis and the empty-
3470    /// slice endpoint on the distinct axis), the two Booleans partition
3471    /// the (distinct, missing) product: a slice is EMPTY iff neither
3472    /// `has_any_distinct_kind()` nor `is_kind_saturated()` returns
3473    /// `true`; a slice is SATURATED iff both `has_any_distinct_kind()`
3474    /// returns `true` and `has_any_missing_kind()` returns `false`; a
3475    /// slice is PARTIALLY POPULATED iff both `has_any_distinct_kind()`
3476    /// and `has_any_missing_kind()` return `true`.
3477    ///
3478    /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
3479    ///
3480    /// Boolean at-least-one halfspace peer of the widened + scalar
3481    /// closed-set-inversion primitives — where `distinct_kinds` returns
3482    /// the FULL distinct SET and `distinct_kind_count` returns its
3483    /// cardinality, `has_any_distinct_kind` collapses either the
3484    /// widened primitive to its non-emptiness Boolean or the scalar to
3485    /// its `>= 1` halfspace Boolean. The composition laws
3486    /// `has_any_distinct_kind() == !distinct_kinds().is_empty()` and
3487    /// `has_any_distinct_kind() == (distinct_kind_count() > 0)` bind
3488    /// this Boolean projection to the widened + scalar primitives at
3489    /// the trait's default body — strictly cheaper than either widened
3490    /// primitive on every non-empty arm because the walk short-circuits
3491    /// at the first populated kind on the has-side walk rather than
3492    /// allocating the closed-set-inversion scan or walking every slot
3493    /// to build the scalar cardinality.
3494    ///
3495    /// # Semantics
3496    ///
3497    /// An empty slice returns `false` — the SOLE arm on which
3498    /// `has_any_distinct_kind` returns `false`. A slice carrying any
3499    /// [`ConditionKind`] at least once returns `true` (a single-
3500    /// populated slice, a partially-populated slice, and a saturated
3501    /// slice all return `true`).
3502    ///
3503    /// # Compounding future consumers
3504    ///
3505    /// - A fleet-wide "any coverage at all" fast-path that discriminates
3506    ///   "the slice carries at least one closed-set kind" from "the
3507    ///   slice is empty" reads
3508    ///   `boundary.postconditions.has_any_distinct_kind()` at ONE call
3509    ///   site rather than restating `distinct_kind_count() > 0` (which
3510    ///   walks every slot to count) or `!distinct_kinds().is_empty()`
3511    ///   (which allocates the Vec before the negated emptiness check).
3512    /// - A `has-any-distinct-kind` require-tag classifier arm reaches
3513    ///   this primitive with no allocation, byte-for-byte peer of the
3514    ///   tagged-union `has-any-populated-kind` classifier one struct-
3515    ///   layer up under the SAME `any(has)` short-circuit shape.
3516    /// - A coherence check that flags "any process boundary whose
3517    ///   postcondition slice covers at least one [`ConditionKind`]"
3518    ///   reads `boundary.postconditions.has_any_distinct_kind()` at
3519    ///   ONE substrate primitive per test rather than restating the
3520    ///   `.iter().copied().any(|k| slice.has_kind(k))` body at every
3521    ///   callsite.
3522    ///
3523    /// # Theory grounding
3524    ///
3525    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3526    ///   The at-least-one halfspace projection on the closed-set-
3527    ///   inversion axis lives at ONE substrate site as a typed short-
3528    ///   circuiting closed-set walk `ConditionKind::ALL.iter().any(
3529    ///   has_kind)`. Every downstream consumer whose semantic reading
3530    ///   is "at least one kind is present" reads through this
3531    ///   primitive rather than paying for the widened primitive's Vec
3532    ///   allocation.
3533    /// - THEORY.md §VI.1 — generation over composition. A new
3534    ///   [`ConditionKind`] variant added to `ALL` reaches this
3535    ///   primitive mechanically through the `any` short-circuit — an
3536    ///   empty slice (returning `false` here) that later picks up the
3537    ///   new variant returns `true` at every downstream `has-any-
3538    ///   distinct-kind` callsite.
3539    fn has_any_distinct_kind(&self) -> bool {
3540        ConditionKind::ALL.iter().copied().any(|k| self.has_kind(k))
3541    }
3542
3543    /// Boolean at-least-one halfspace peer of [`Self::is_kind_saturated`]
3544    /// on the closed-set-complement axis — `true` iff AT LEAST ONE
3545    /// [`ConditionKind::ALL`] variant appears zero times in this slice
3546    /// (equivalently, [`Self::missing_kinds`] is non-empty,
3547    /// [`Self::missing_kind_count`] `> 0`, [`Self::first_missing_kind`]
3548    /// is `Some`).
3549    ///
3550    /// Default body: `!self.is_kind_saturated()` — a definitional
3551    /// negation of the saturation-endpoint primitive. Short-circuits
3552    /// transitively through [`Self::is_kind_saturated`]'s
3553    /// `ConditionKind::ALL.iter().all(has_kind)` composition: the
3554    /// underlying `all` walk returns `false` at the FIRST missing kind
3555    /// (yielding `true` here) WITHOUT materializing
3556    /// [`Self::missing_kinds`]'s `Vec`, WITHOUT walking every slot to
3557    /// build [`Self::missing_kind_count`]'s scalar, and WITHOUT
3558    /// allocating the closed-set-complement scan. Strictly cheaper
3559    /// than either widened primitive on every partially-populated arm.
3560    ///
3561    /// # Peer to [`crate::tagged_union::TaggedUnion::has_any_missing_kind`]
3562    ///
3563    /// Slice-level peer of the tagged-union parent-level at-least-one
3564    /// halfspace predicate one struct-layer up: where
3565    /// [`crate::tagged_union::TaggedUnion::has_any_missing_kind`]
3566    /// answers "is ANY slot on the tagged-union parent empty?",
3567    /// `has_any_missing_kind` answers "does ANY kind appear in NO
3568    /// condition of the slice?". Both compose against their
3569    /// saturation-endpoint primitive under a definitional negation
3570    /// (`!is_saturated` / `!is_kind_saturated`) at two adjacent
3571    /// typescape sites — the two primitives close the at-least-one
3572    /// halfspace on the closed-set-complement axis at both struct
3573    /// layers under the SAME shape.
3574    ///
3575    /// # Sibling to [`Self::is_kind_saturated`]
3576    ///
3577    /// Boolean at-least-one halfspace peer of the zero-arm saturation-
3578    /// endpoint primitive on the closed-set-complement axis — where
3579    /// `is_kind_saturated` returns `true` iff `missing_kind_count == 0`,
3580    /// `has_any_missing_kind` returns its Boolean-negation: `true` iff
3581    /// `missing_kind_count >= 1`. Together the two Booleans partition
3582    /// the missing-cardinality closed set: exactly one of
3583    /// `is_kind_saturated()` and `has_any_missing_kind()` is `true`
3584    /// for every slice. The definitional negation law
3585    /// `has_any_missing_kind() == !is_kind_saturated()` is pinned as a
3586    /// first-class typed invariant by the trait's own default body and
3587    /// swept substrate-wide by
3588    /// [`assert_slice_refinement_composition_laws`] as its at-least-
3589    /// one halfspace arm.
3590    ///
3591    /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
3592    ///
3593    /// Boolean at-least-one halfspace peer of the widened + scalar
3594    /// closed-set-complement primitives — where `missing_kinds` returns
3595    /// the FULL missing SET (a `Vec<ConditionKind>` of every absent
3596    /// kind) and `missing_kind_count` returns its cardinality
3597    /// (a `usize` in `0..=ConditionKind::ALL.len()`),
3598    /// `has_any_missing_kind` collapses either the widened primitive
3599    /// to its non-emptiness Boolean or the scalar to its `>= 1`
3600    /// halfspace Boolean. The composition laws
3601    /// `has_any_missing_kind() == !missing_kinds().is_empty()` and
3602    /// `has_any_missing_kind() == (missing_kind_count() > 0)` bind
3603    /// this Boolean projection to the widened + scalar primitives at
3604    /// the trait's default body — strictly cheaper than either widened
3605    /// primitive on every partially-populated arm because the negation
3606    /// short-circuits at the first missing kind on the has-side walk
3607    /// rather than allocating the closed-set-complement scan or
3608    /// walking every slot to build the scalar cardinality.
3609    ///
3610    /// # Semantics
3611    ///
3612    /// An empty slice returns `true` (every kind is missing — the
3613    /// fully-missing endpoint). A slice carrying a strict subset of
3614    /// [`ConditionKind::ALL`] returns `true`. A saturated slice
3615    /// returns `false` — the SOLE arm on which `has_any_missing_kind`
3616    /// returns `false`, byte-for-byte peer of the SOLE arm on which
3617    /// `is_kind_saturated` returns `true`.
3618    ///
3619    /// # Compounding future consumers
3620    ///
3621    /// - A fleet-wide "gap present" fast-path that discriminates "some
3622    ///   kind is missing" from "every kind is present" reads
3623    ///   `boundary.postconditions.has_any_missing_kind()` at ONE call
3624    ///   site rather than negating `is_kind_saturated()` at the
3625    ///   callsite or restating `missing_kind_count() > 0` (which walks
3626    ///   every slot to count) or `!missing_kinds().is_empty()` (which
3627    ///   allocates the Vec before the negated emptiness check).
3628    /// - A `has-any-missing-kind` require-tag classifier arm reaches
3629    ///   this primitive with no allocation, byte-for-byte peer of the
3630    ///   tagged-union `has-any-missing-kind` classifier one struct-
3631    ///   layer up under the SAME `!is_saturated` definitional negation
3632    ///   shape.
3633    /// - A coherence check that flags "any process boundary with a
3634    ///   missing [`ConditionKind`]" reads
3635    ///   `boundary.postconditions.has_any_missing_kind()` at ONE
3636    ///   substrate primitive per test rather than restating the
3637    ///   negation body at every callsite.
3638    ///
3639    /// # Theory grounding
3640    ///
3641    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3642    ///   The at-least-one halfspace projection lives at ONE substrate
3643    ///   site as a definitional negation of
3644    ///   [`Self::is_kind_saturated`]. Every downstream consumer whose
3645    ///   semantic reading is "at least one kind is absent" reads
3646    ///   through this primitive rather than negating `is_kind_saturated`
3647    ///   at every callsite or paying for the widened primitive's Vec
3648    ///   allocation.
3649    /// - THEORY.md §VI.1 — generation over composition. A new
3650    ///   [`ConditionKind`] variant added to `ALL` reaches this
3651    ///   primitive mechanically through the delegated
3652    ///   `is_kind_saturated` — a slice that was previously saturated
3653    ///   (returned `false` here) picks up the new missing variant and
3654    ///   returns `true` at every downstream `has-any-missing-kind`
3655    ///   callsite unless it also carries the new variant.
3656    fn has_any_missing_kind(&self) -> bool {
3657        !self.is_kind_saturated()
3658    }
3659
3660    /// Boolean cardinality-mid-endpoint peer of
3661    /// [`Self::has_any_missing_kind`] on the closed-set-complement
3662    /// axis — `true` iff EXACTLY ONE [`ConditionKind::ALL`] variant
3663    /// appears zero times in this slice (equivalently,
3664    /// [`Self::missing_kind_count`] `== 1`,
3665    /// [`Self::missing_kinds`]`.len() == 1`, and
3666    /// [`Self::first_missing_kind`] equals
3667    /// [`Self::last_missing_kind`] and is [`Some`]).
3668    ///
3669    /// Default body: a two-step-short-circuit closed-set walk over
3670    /// [`ConditionKind::ALL`] under a negated [`Self::has_kind`]
3671    /// predicate. Pulls up to two hits off the filtered iterator; the
3672    /// primitive returns `true` iff the first hit is [`Some`] and the
3673    /// second is [`None`], WITHOUT materializing
3674    /// [`Self::missing_kinds`]'s `Vec` and WITHOUT walking every slot
3675    /// to build [`Self::missing_kind_count`]'s scalar. Short-circuits
3676    /// at the SECOND missing kind — strictly cheaper than either
3677    /// widened primitive on every arm with `≥ 2` missing kinds.
3678    ///
3679    /// # Peer to [`crate::tagged_union::TaggedUnion::has_unique_missing_kind`]
3680    ///
3681    /// Slice-level peer of the tagged-union parent-level
3682    /// cardinality-mid-endpoint predicate one struct-layer up: where
3683    /// [`crate::tagged_union::TaggedUnion::has_unique_missing_kind`]
3684    /// answers "is EXACTLY ONE slot on the tagged-union parent
3685    /// empty?", `has_unique_missing_kind` answers "does EXACTLY ONE
3686    /// kind appear in NO condition of the slice?". Both compose
3687    /// against a two-step-short-circuit closed-set walk under a
3688    /// negated presence predicate (`!has(kind)` / `!has_kind(kind)`)
3689    /// at two adjacent typescape sites — the two primitives close the
3690    /// exactly-one-arm on the closed-set-complement axis at both
3691    /// struct layers under the SAME shape.
3692    ///
3693    /// # Sibling to the Boolean missing-cardinality trichotomy
3694    ///
3695    /// Second arm of the `{0, 1, ≥2}` cardinality trichotomy on the
3696    /// missing axis, closing the natural partition alongside
3697    /// [`Self::is_kind_saturated`] (zero-arm) and (once its slice-
3698    /// level peer lands) the many-arm predicate. Every slice
3699    /// satisfies EXACTLY ONE of the three Boolean projections — the
3700    /// three primitives partition `0..=ConditionKind::ALL.len()` at
3701    /// 0, 1, and ≥ 2 respectively. The composition law
3702    /// `has_unique_missing_kind() == (missing_kind_count() == 1)`
3703    /// binds the Boolean projection to the scalar primitive at the
3704    /// trait's default body — swept substrate-wide by
3705    /// [`assert_slice_refinement_composition_laws`] as its
3706    /// cardinality-mid-endpoint arm.
3707    ///
3708    /// # Semantics
3709    ///
3710    /// An empty slice returns `false` on any `N ≥ 2` closed set (every
3711    /// kind is missing — the fully-missing endpoint, `N` missing not
3712    /// `1`). A slice carrying `K` distinct kinds for `1 ≤ K ≤ N-2` on
3713    /// `N ≥ 3` closed sets returns `false` (`N - K ≥ 2` kinds missing).
3714    /// A slice at the near-saturation arm (carrying every kind except
3715    /// exactly one) returns `true` — the SOLE arrangement where
3716    /// `has_unique_missing_kind` returns `true`. A saturated slice
3717    /// returns `false` (zero missing).
3718    ///
3719    /// # Compounding future consumers
3720    ///
3721    /// - An operator-facing "one kind away from saturated" fast-path
3722    ///   discriminator on the near-saturation arm reads
3723    ///   `boundary.postconditions.has_unique_missing_kind()` at ONE
3724    ///   call site — one two-step short-circuit walk, no allocation,
3725    ///   no scalar equality against `1`, byte-for-byte peer of the
3726    ///   tagged-union `has-unique-missing-kind` classifier one struct-
3727    ///   layer up under the SAME two-step short-circuit shape.
3728    /// - A `has-unique-missing-kind` require-tag classifier arm
3729    ///   reaches this primitive with no allocation, byte-for-byte
3730    ///   peer of the tagged-union `has-unique-missing-kind` classifier
3731    ///   one struct-layer up.
3732    /// - A future gap-analysis diagnostic that prints "one remaining
3733    ///   ConditionKind not covered by this Boundary" pairs
3734    ///   `has_unique_missing_kind()` with
3735    ///   [`Self::first_missing_kind`] to name the SOLE remaining hole
3736    ///   without allocating [`Self::missing_kinds`]'s `Vec`.
3737    ///
3738    /// # Theory grounding
3739    ///
3740    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3741    ///   The cardinality-mid-endpoint projection on the missing axis
3742    ///   lives at ONE substrate site as a typed two-step-short-
3743    ///   circuit walk over [`ConditionKind::ALL`] under negated
3744    ///   [`Self::has_kind`] — byte-for-byte peer of
3745    ///   `missing_kind_count()` composed against `== 1`, but with a
3746    ///   second-missing-slot short-circuit that the scalar counter
3747    ///   primitive does not offer.
3748    /// - THEORY.md §VI.1 — generation over composition. A new
3749    ///   [`ConditionKind`] variant added to `ALL` reaches this
3750    ///   primitive mechanically through the short-circuit walk — a
3751    ///   slice previously at the near-saturation arm (returned `true`
3752    ///   here) that omits the new variant now has TWO missing kinds
3753    ///   and returns `false`; a slice previously at the
3754    ///   saturated-except-one-of-two arm on an `N == 2` closed set
3755    ///   remains at the near-saturation arm on `N ≥ 3` iff it
3756    ///   picks up every OTHER variant.
3757    fn has_unique_missing_kind(&self) -> bool {
3758        let mut it = ConditionKind::ALL
3759            .iter()
3760            .copied()
3761            .filter(|k| !self.has_kind(*k));
3762        it.next().is_some() && it.next().is_none()
3763    }
3764
3765    /// Boolean cardinality "≥ 2" many-arm peer of
3766    /// [`Self::has_unique_missing_kind`] on the closed-set-complement
3767    /// axis — `true` iff AT LEAST TWO [`ConditionKind::ALL`] variants
3768    /// appear zero times in this slice (equivalently,
3769    /// [`Self::missing_kind_count`] `>= 2` and
3770    /// [`Self::missing_kinds`]`.len() >= 2`).
3771    ///
3772    /// Default body: a two-step-short-circuit closed-set walk over
3773    /// [`ConditionKind::ALL`] under a negated [`Self::has_kind`]
3774    /// predicate. Pulls up to two hits off the filtered iterator; the
3775    /// primitive returns `true` iff BOTH the first and the second are
3776    /// [`Some`], WITHOUT materializing [`Self::missing_kinds`]'s `Vec`
3777    /// and WITHOUT walking every slot to build
3778    /// [`Self::missing_kind_count`]'s scalar. Short-circuits at the
3779    /// second missing kind — strictly cheaper than either widened
3780    /// primitive on every arm with `≥ 2` missing kinds. Byte-for-byte
3781    /// peer of [`crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`]
3782    /// under the (populated, missing) complement axis one struct-
3783    /// layer up.
3784    ///
3785    /// # Peer to [`crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`]
3786    ///
3787    /// Slice-level peer of the tagged-union parent-level cardinality
3788    /// many-arm predicate one struct-layer up: where
3789    /// [`crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`]
3790    /// answers "are AT LEAST TWO slots on the tagged-union parent
3791    /// empty?", `has_multiple_missing_kinds` answers "do AT LEAST TWO
3792    /// kinds appear in NO condition of the slice?". Both compose
3793    /// against a two-step-short-circuit closed-set walk under a
3794    /// negated presence predicate (`!has(kind)` / `!has_kind(kind)`)
3795    /// at two adjacent typescape sites — the two primitives close the
3796    /// at-least-two arm on the closed-set-complement axis at both
3797    /// struct layers under the SAME shape.
3798    ///
3799    /// # Sibling to the Boolean missing-cardinality trichotomy
3800    ///
3801    /// Third and final arm of the `{0, 1, ≥2}` cardinality trichotomy
3802    /// on the missing axis at the slice level, closing the natural
3803    /// partition alongside [`Self::is_kind_saturated`] (zero-arm) and
3804    /// [`Self::has_unique_missing_kind`] (one-arm). Every slice
3805    /// satisfies EXACTLY ONE of the three Boolean projections — the
3806    /// three primitives partition `0..=ConditionKind::ALL.len()` at
3807    /// 0, 1, and ≥ 2 respectively. The composition law
3808    /// `has_multiple_missing_kinds() == (missing_kind_count() >= 2)`
3809    /// binds the Boolean projection to the scalar primitive at the
3810    /// trait's default body — swept substrate-wide by
3811    /// [`assert_slice_refinement_composition_laws`] as its
3812    /// cardinality-many-arm arm.
3813    ///
3814    /// # Semantics
3815    ///
3816    /// An empty slice returns `true` on any `N ≥ 2` closed set (every
3817    /// kind is missing — the fully-missing endpoint, `N ≥ 2` missing).
3818    /// A slice carrying `K` distinct kinds for `1 ≤ K ≤ N-2` on
3819    /// `N ≥ 3` closed sets returns `true` (`N - K ≥ 2` kinds missing).
3820    /// A slice at the near-saturation arm (carrying every kind except
3821    /// exactly one) returns `false` — the SOLE-missing arrangement
3822    /// where `has_multiple_missing_kinds` returns `false` (exactly
3823    /// one missing, not ≥ 2). A saturated slice returns `false`
3824    /// (zero missing).
3825    ///
3826    /// # Compounding future consumers
3827    ///
3828    /// - An operator-facing "≥ 2 dependencies still unfulfilled" fast-
3829    ///   path discriminator on the many-missing arm reads
3830    ///   `boundary.postconditions.has_multiple_missing_kinds()` at ONE
3831    ///   call site — one two-step short-circuit walk, no allocation,
3832    ///   no scalar comparison against `>= 2`, byte-for-byte peer of
3833    ///   the tagged-union `has-multiple-missing-kinds` classifier one
3834    ///   struct-layer up under the SAME two-step short-circuit shape.
3835    /// - A `has-multiple-missing-kinds` require-tag classifier arm
3836    ///   reaches this primitive with no allocation, byte-for-byte
3837    ///   peer of the tagged-union `has-multiple-missing-kinds`
3838    ///   classifier one struct-layer up.
3839    /// - A future coverage-gap diagnostic that says "≥ 2 remaining
3840    ///   ConditionKinds not covered by this Boundary" reads
3841    ///   `has_multiple_missing_kinds()` at ONE call site without
3842    ///   allocating [`Self::missing_kinds`]'s `Vec`.
3843    ///
3844    /// # Theory grounding
3845    ///
3846    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3847    ///   The cardinality-many-arm projection on the missing axis
3848    ///   lives at ONE substrate site as a typed two-step-short-
3849    ///   circuit walk over [`ConditionKind::ALL`] under negated
3850    ///   [`Self::has_kind`] — byte-for-byte peer of
3851    ///   `missing_kind_count()` composed against `>= 2`, but with a
3852    ///   second-missing-slot short-circuit that the scalar counter
3853    ///   primitive does not offer.
3854    /// - THEORY.md §VI.1 — generation over composition. A new
3855    ///   [`ConditionKind`] variant added to `ALL` reaches this
3856    ///   primitive mechanically through the short-circuit walk — a
3857    ///   slice previously at the near-saturation arm (returned
3858    ///   `false` here) that omits the new variant now has TWO missing
3859    ///   kinds and flips to `true`; a slice previously at the
3860    ///   saturated arm on an `N == 2` closed set that omits the new
3861    ///   variant flips from `false` to `true` (`1 ≥ 2` false → `1`
3862    ///   missing on `N == 3`, but this workspace has `N == 8`, so
3863    ///   the flip surfaces well before the endpoint).
3864    fn has_multiple_missing_kinds(&self) -> bool {
3865        let mut it = ConditionKind::ALL
3866            .iter()
3867            .copied()
3868            .filter(|k| !self.has_kind(*k));
3869        it.next().is_some() && it.next().is_some()
3870    }
3871
3872    /// Boolean cardinality "≤ 1" negation peer of
3873    /// [`Self::has_multiple_missing_kinds`] on the closed-set-complement
3874    /// axis — `true` iff AT MOST ONE [`ConditionKind::ALL`] variant
3875    /// appears zero times in this slice (equivalently,
3876    /// [`Self::missing_kind_count`] `<= 1` and
3877    /// [`Self::missing_kinds`]`.len() <= 1`). Names the arm where the
3878    /// slice is SATURATED-OR-NEAR-SATURATED (zero or exactly one kind
3879    /// missing).
3880    ///
3881    /// Default body: `!self.has_multiple_missing_kinds()` — a
3882    /// definitional Boolean negation of the many-arm primitive. Short-
3883    /// circuits transitively through
3884    /// [`Self::has_multiple_missing_kinds`]'s two-step short-circuit
3885    /// closed-set walk: returns `true` as soon as the many-arm walk
3886    /// stops with fewer than two missing hits, WITHOUT materializing
3887    /// [`Self::missing_kinds`]'s `Vec` and WITHOUT walking every slot to
3888    /// build [`Self::missing_kind_count`]'s scalar. Byte-for-byte peer
3889    /// of [`crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`]
3890    /// under the (populated, missing) complement axis one struct-layer
3891    /// up, both composed as the same definitional negation of their
3892    /// respective many-arm primitives.
3893    ///
3894    /// # Peer to [`crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`]
3895    ///
3896    /// Slice-level peer of the tagged-union parent-level cardinality
3897    /// "≤ 1" predicate one struct-layer up: where
3898    /// [`crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`]
3899    /// answers "does the tagged-union parent have AT MOST ONE empty
3900    /// slot?", `has_at_most_one_missing_kind` answers "do AT MOST ONE
3901    /// kind appear in NO condition of the slice?". Both compose as the
3902    /// definitional Boolean negation of their many-arm primitive
3903    /// (`!has_multiple_missing_kinds()`) at two adjacent typescape
3904    /// sites — the two primitives close the "≤ 1" arm on the closed-
3905    /// set-complement axis at both struct layers under the SAME shape.
3906    ///
3907    /// # Sibling to the Boolean missing-cardinality pentachotomy
3908    ///
3909    /// Fourth arm of the `{0, 1, ≥1, ≤1, ≥2}` Boolean-cardinality
3910    /// pentachotomy on the missing axis at the slice level, closing
3911    /// the Boolean-negation grid alongside
3912    /// [`Self::is_kind_saturated`] (=0 zero-arm),
3913    /// [`Self::has_unique_missing_kind`] (=1 mid-endpoint),
3914    /// [`Self::has_any_missing_kind`] (≥1 halfspace), and
3915    /// [`Self::has_multiple_missing_kinds`] (≥2 many-arm). The
3916    /// {≤1, ≥2} pair sit on the Boolean-negation axis:
3917    /// `has_at_most_one_missing_kind == !has_multiple_missing_kinds` on
3918    /// every arm. The {0, 1} union arm sits on the trichotomy-union
3919    /// axis: `has_at_most_one_missing_kind == is_kind_saturated ||
3920    /// has_unique_missing_kind` on every arm. Both composition laws
3921    /// bind the "≤ 1" Boolean projection to the sibling primitives at
3922    /// the trait's default body — swept substrate-wide by
3923    /// [`assert_slice_refinement_composition_laws`] as its "≤ 1" arm.
3924    ///
3925    /// # Semantics
3926    ///
3927    /// An empty slice returns `false` on any `N ≥ 2` closed set
3928    /// (every kind is missing — `N ≥ 2` missing, not `≤ 1`).
3929    /// A slice carrying `K` distinct kinds for `1 ≤ K ≤ N-2` on `N ≥ 3`
3930    /// closed sets returns `false` (`N - K ≥ 2` kinds missing).
3931    /// A slice at the near-saturation arm (carrying every kind except
3932    /// exactly one) returns `true` (exactly 1 missing, `≤ 1`). A
3933    /// saturated slice returns `true` (0 missing, `≤ 1`) — the union
3934    /// of the two "≤ 1" arms (`=0` and `=1`) is exactly the
3935    /// arrangement space where the primitive returns `true`.
3936    ///
3937    /// # Compounding future consumers
3938    ///
3939    /// - An operator-facing "at most one dependency still unfulfilled"
3940    ///   fast-path discriminator on the near-saturated / saturated
3941    ///   arms reads `boundary.postconditions.has_at_most_one_missing_kind()`
3942    ///   at ONE call site — one bit-flip on the many-arm's two-step
3943    ///   short-circuit walk, no allocation, no scalar comparison
3944    ///   against `<= 1`, byte-for-byte peer of the tagged-union
3945    ///   `has-at-most-one-missing-kind` classifier one struct-layer up
3946    ///   under the SAME `!has_multiple_missing_kinds` definitional
3947    ///   negation shape.
3948    /// - A `has-at-most-one-missing-kind` require-tag classifier arm
3949    ///   reaches this primitive with no allocation, closing the
3950    ///   {0, 1, ≥ 2, ≤ 1} cardinality-Boolean grid on the missing axis
3951    ///   at the slice level alongside its sibling
3952    ///   `has-multiple-missing-kinds` under the Boolean negation axis.
3953    /// - A future coverage-gap diagnostic that says "at most one
3954    ///   remaining ConditionKind not covered by this Boundary" reads
3955    ///   `has_at_most_one_missing_kind()` at ONE call site without
3956    ///   allocating [`Self::missing_kinds`]'s `Vec`.
3957    ///
3958    /// # Theory grounding
3959    ///
3960    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3961    ///   The cardinality "≤ 1" projection on the missing axis lives
3962    ///   at ONE substrate site as the definitional Boolean negation
3963    ///   of [`Self::has_multiple_missing_kinds`]; the three composition
3964    ///   forms (`!has_multiple_missing_kinds()`, `missing_kind_count() <= 1`,
3965    ///   and `is_kind_saturated() || has_unique_missing_kind()`)
3966    ///   compose through the SAME two-step-short-circuit walk shape
3967    ///   one negation up, byte-for-byte identical on every arm.
3968    /// - THEORY.md §VI.1 — generation over composition. A new
3969    ///   [`ConditionKind`] variant added to `ALL` reaches this
3970    ///   primitive mechanically through the delegated
3971    ///   [`Self::has_multiple_missing_kinds`] — a slice previously at
3972    ///   the near-saturation arm (returned `true` here) that omits the
3973    ///   new variant now has TWO missing kinds and flips to `false`.
3974    fn has_at_most_one_missing_kind(&self) -> bool {
3975        !self.has_multiple_missing_kinds()
3976    }
3977
3978    /// Boolean per-kind complement of [`Self::has_kind`] — `true` iff
3979    /// NO [`Condition`] in this slice carries the given
3980    /// [`ConditionKind`] (equivalently, the kind is a member of
3981    /// [`Self::missing_kinds`]).
3982    ///
3983    /// Default body: `!self.has_kind(kind)` — a definitional negation
3984    /// of the presence-probe primitive. Short-circuits transitively
3985    /// through [`Self::has_kind`]'s composition down to
3986    /// [`Self::iter_kind`]: `!self.find_kind(kind).is_some()` returns
3987    /// as soon as any match is found (yielding `false`) without
3988    /// walking the rest of the slice, WITHOUT materializing
3989    /// [`Self::missing_kinds`]'s `Vec` per-kind for a per-kind
3990    /// question, and WITHOUT allocating the closed-set-complement scan.
3991    ///
3992    /// # Peer to [`crate::tagged_union::TaggedUnion::lacks`]
3993    ///
3994    /// Slice-level peer of the tagged-union parent-level closed-set-
3995    /// complement predicate one struct-layer up: where
3996    /// [`crate::tagged_union::TaggedUnion::lacks`] answers "is THIS
3997    /// kind's slot on the tagged-union parent empty?", `lacks_kind`
3998    /// answers "does THIS kind appear in NO condition of the slice?".
3999    /// Both compose against their per-kind presence primitive under a
4000    /// definitional negation (`!has(kind)` / `!has_kind(kind)`) at two
4001    /// adjacent typescape sites — the two primitives close the
4002    /// closed-set-complement invariant on the per-kind axis at both
4003    /// struct layers under the SAME shape.
4004    ///
4005    /// # Sibling to [`Self::has_kind`]
4006    ///
4007    /// Boolean per-kind complement peer of the point-probe primitive
4008    /// on the closed-set-complement axis — where `has_kind` returns
4009    /// `true` iff the addressed kind appears at least once,
4010    /// `lacks_kind` returns its negation: `true` iff the addressed kind
4011    /// appears zero times. Together the two Booleans partition the
4012    /// (slice, kind) matrix at the slice-level presence-probe axis:
4013    /// exactly one of `has_kind(k)` and `lacks_kind(k)` is `true` for
4014    /// every `k ∈ ConditionKind::ALL`. The definitional complement law
4015    /// `lacks_kind(k) == !has_kind(k)` is pinned as a first-class typed
4016    /// invariant by the trait's own default body and swept substrate-
4017    /// wide by [`assert_slice_refinement_composition_laws`] as its
4018    /// per-kind-complement arm.
4019    ///
4020    /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
4021    ///
4022    /// Per-kind Boolean projection of the closed-set-complement
4023    /// widened + scalar primitives — where `missing_kinds` returns the
4024    /// FULL missing-set (a `Vec<ConditionKind>` of every absent kind)
4025    /// and `missing_kind_count` returns its cardinality (a `usize` in
4026    /// `0..=ConditionKind::ALL.len()`), `lacks_kind` collapses the
4027    /// missing-set to its per-kind membership Boolean for ONE
4028    /// addressed kind. The composition law
4029    /// `lacks_kind(k) == missing_kinds().contains(&k)` binds this
4030    /// Boolean projection to the widened closed-set-complement
4031    /// primitive at the trait's default body — strictly cheaper than
4032    /// the widened primitive on every per-kind question because the
4033    /// negation short-circuits at the first match on the has-side
4034    /// walk rather than allocating the closed-set-complement scan.
4035    ///
4036    /// # Semantics
4037    ///
4038    /// An empty slice returns `true` for every [`ConditionKind`] (no
4039    /// kind appears, so every kind is lacked). A slice carrying kind
4040    /// `k` at any position returns `false` for `lacks_kind(k)` and
4041    /// `true` for `lacks_kind(k')` for every `k' ≠ k` (single-kind
4042    /// coverage). A saturated slice (every kind appears at least once)
4043    /// returns `false` on every arm — the SOLE arrangement where the
4044    /// primitive returns `false` for every kind.
4045    ///
4046    /// # Compounding future consumers
4047    ///
4048    /// - A `lacks-<kind>` require-tag classifier arm reaches this
4049    ///   primitive with no allocation, byte-for-byte peer of the
4050    ///   tagged-union `lacks-<kind>` classifier one struct-layer up
4051    ///   under the SAME `!has(kind)` definitional negation shape.
4052    /// - A dependency-satisfaction coherence check that enforces "no
4053    ///   process boundary lacks a `ClosedLoopAuth` postcondition" reads
4054    ///   `boundary.postconditions.lacks_kind(ConditionKind::ClosedLoopAuth)`
4055    ///   at ONE call site rather than negating
4056    ///   `boundary.postconditions.has_kind(ConditionKind::ClosedLoopAuth)`
4057    ///   at the callsite or materializing the closed-set complement
4058    ///   with `missing_kinds().contains(&k)`.
4059    /// - A "still missing: <kind>" diagnostic that reports the FIRST
4060    ///   unmet postcondition kind reads `slice.lacks_kind(k)` inside a
4061    ///   `ConditionKind::ALL` fold at ONE substrate primitive per test
4062    ///   rather than restating the negation body at every callsite.
4063    ///
4064    /// # Theory grounding
4065    ///
4066    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4067    ///   The per-kind closed-set-complement projection lives at ONE
4068    ///   substrate site as a definitional negation of [`Self::has_kind`].
4069    ///   Every downstream consumer whose semantic reading is "the
4070    ///   missing set contains THIS kind" reads through this primitive
4071    ///   rather than negating `has_kind` at every callsite or paying
4072    ///   for the closed-set-complement scan.
4073    /// - THEORY.md §VI.1 — generation over composition. A new
4074    ///   [`ConditionKind`] variant added to `ALL` reaches this
4075    ///   primitive mechanically through the delegated `has_kind` —
4076    ///   every downstream `lacks-<kind>` classifier arm sees the wider
4077    ///   kind set without further per-caller edit.
4078    fn lacks_kind(&self, kind: ConditionKind) -> bool {
4079        !self.has_kind(kind)
4080    }
4081
4082    /// Kind-scoped strict refinement of [`Self::has_kind`] — `true` iff
4083    /// the given `kind` appears in the slice AND no OTHER
4084    /// [`ConditionKind`] appears alongside it. The "exactly this one
4085    /// variant is present" predicate at the slice level.
4086    ///
4087    /// Default body: a FUSED short-circuit closed-set walk over
4088    /// [`ConditionKind::ALL`] under [`Self::has_kind`] that returns
4089    /// `false` at the EARLIEST populated slot whose kind is NOT
4090    /// `kind`, and returns `true` iff the sweep completes with `kind`
4091    /// seen as the sole populated slot. Byte-for-byte cheaper than
4092    /// either widened composition
4093    /// `self.distinct_kinds() == vec![kind]` (which allocates the
4094    /// distinct-kind Vec before the equality test) or
4095    /// `self.has_kind(kind) && self.distinct_kind_count() == 1` (which
4096    /// walks the closed-set twice) on every arm where the slice
4097    /// carries a populated kind that isn't `kind`.
4098    ///
4099    /// # Peer to [`crate::tagged_union::TaggedUnion::has_only`]
4100    ///
4101    /// Slice-level peer of the tagged-union parent-level kind-scoped
4102    /// strict-refinement predicate one struct-layer up: where
4103    /// [`crate::tagged_union::TaggedUnion::has_only`] answers "is THIS
4104    /// kind's slot on the tagged-union parent the sole populated
4105    /// slot?", `has_only_kind` answers "is THIS kind the sole distinct
4106    /// kind appearing in the slice?". Both primitives compose the SAME
4107    /// fused short-circuit closed-set walk under a per-kind
4108    /// [`Self::has_kind`] / `TaggedUnion::has` predicate at two
4109    /// adjacent typescape sites — the two primitives close the
4110    /// kind-scoped strict-refinement invariant on the well-formed
4111    /// (1-of-N populated) arm at both struct layers under the SAME
4112    /// shape.
4113    ///
4114    /// # Sibling to [`Self::has_kind`]
4115    ///
4116    /// Kind-scoped strict-refinement peer of the point-probe primitive
4117    /// on the closed-set-inversion axis — where `has_kind(k)` returns
4118    /// `true` iff `k` appears at least once (multiplicity ignored),
4119    /// `has_only_kind(k)` refines that to the strictly stricter
4120    /// predicate "k appears AND no other kind appears". The
4121    /// implication chain `has_only_kind(k) ⟹ has_kind(k)` is a
4122    /// definitional consequence of the fused walk's `saw_kind = true`
4123    /// arm; the reverse is FALSE on any partially-populated slice
4124    /// where a second kind lives alongside `k`. The composition law
4125    /// `has_only_kind(k) == (distinct_kinds() == vec![k])` binds this
4126    /// primitive to the widened closed-set-inversion primitive at the
4127    /// trait's default body — swept substrate-wide by
4128    /// [`assert_slice_refinement_composition_laws`] as its kind-scoped
4129    /// strict-refinement arm.
4130    ///
4131    /// # Truth table on the slice-level closed-set-inversion contract
4132    ///
4133    /// For a slice with `ConditionKind::ALL` of cardinality `N ≥ 2`
4134    /// and a fixed argument `kind`:
4135    ///
4136    /// - Empty slice (0 conditions, distinct-kind set empty): `false`
4137    ///   on any `N ≥ 2` — no kind appears, so `kind` isn't the sole
4138    ///   populated kind.
4139    /// - Single-populated slice with populated kind `p` (1 condition,
4140    ///   distinct-kind set `{p}`): `has_only_kind(kind) == (kind == p)`.
4141    /// - Duplicate-populated slice with kind `p` at every position
4142    ///   (multiplicity > 1, distinct-kind set `{p}`): still
4143    ///   `has_only_kind(kind) == (kind == p)` — MULTIPLICITY IS
4144    ///   IGNORED on the populated side (byte-for-byte with `has_kind`'s
4145    ///   multiplicity behavior).
4146    /// - Two-kinds slice with kinds `{p, q}` where `p != q` (distinct-
4147    ///   kind set `{p, q}`): `false` for every kind — the strict
4148    ///   refinement fails at the earliest walk step that hits the
4149    ///   second kind.
4150    /// - Saturated slice (every kind appears): `false` for every kind
4151    ///   on any `N ≥ 2` — N distinct kinds populate, so no single
4152    ///   kind is "only".
4153    ///
4154    /// # Kind-domain exhaustivity
4155    ///
4156    /// A slice satisfies `has_only_kind(k)` for AT MOST one `k`, since
4157    /// two distinct kinds cannot both be the sole distinct populated
4158    /// kind. On the well-formed arm the count is exactly 1 (the
4159    /// addressed populated kind); on every other arm the count is 0.
4160    /// This kind-domain exhaustivity law binds the argument-scoped
4161    /// projection to the parent-scoped cardinality primitive
4162    /// `distinct_kind_count() == 1` at the composition-law surface.
4163    ///
4164    /// # Compounding future consumers
4165    ///
4166    /// - A `has-only-<kind>` require-tag classifier arm reaches this
4167    ///   primitive with no allocation, byte-for-byte peer of the
4168    ///   tagged-union `has-only-<kind>` classifier one struct-layer up
4169    ///   under the SAME fused short-circuit walk shape.
4170    /// - A coherence check verifying "every ephemeral spec whose
4171    ///   postconditions carry ONLY `ClosedLoopAuth` (no
4172    ///   `JobAttested`, no `Cel`, ...) is a well-formed closed-loop
4173    ///   probe" reads
4174    ///   `spec.postconditions.has_only_kind(ConditionKind::ClosedLoopAuth)`
4175    ///   at ONE call site — strictly cheaper than reaching for the
4176    ///   widened composition on every well-formed-diagonal question.
4177    /// - An operator-facing "unambiguously kind=<k>" diagnostic on
4178    ///   the slice-level probe reads `slice.has_only_kind(k)` after
4179    ///   `first_distinct_kind` names the sole populated kind — one
4180    ///   fused walk, no allocation, no `Option<ConditionKind>`
4181    ///   construction.
4182    ///
4183    /// # Theory grounding
4184    ///
4185    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4186    ///   The kind-scoped strict-refinement projection lives at ONE
4187    ///   substrate site as a fused short-circuit walk over
4188    ///   [`ConditionKind::ALL`] under [`Self::has_kind`] with early
4189    ///   exit on the first populated slot whose kind is not `kind` —
4190    ///   byte-for-byte cheaper than the widened composition
4191    ///   `distinct_kinds() == vec![kind]`, semantically identical on
4192    ///   every arm.
4193    /// - THEORY.md §VI.1 — generation over composition. A new
4194    ///   [`ConditionKind`] variant added to `ALL` reaches this
4195    ///   primitive mechanically through the fused walk — every
4196    ///   downstream `has-only-<kind>` classifier arm sees the wider
4197    ///   kind set without further per-caller edit.
4198    fn has_only_kind(&self, kind: ConditionKind) -> bool {
4199        let mut saw_kind = false;
4200        for k in ConditionKind::ALL {
4201            if !self.has_kind(k) {
4202                continue;
4203            }
4204            if k == kind {
4205                saw_kind = true;
4206            } else {
4207                return false;
4208            }
4209        }
4210        saw_kind
4211    }
4212
4213    /// Kind-scoped strict refinement of [`Self::lacks_kind`] — `true` iff
4214    /// the given `kind` does NOT appear in the slice AND every OTHER
4215    /// [`ConditionKind`] DOES appear at least once. The "exactly this
4216    /// one variant is the sole hole" predicate at the slice level.
4217    ///
4218    /// Default body: a FUSED short-circuit closed-set walk over
4219    /// [`ConditionKind::ALL`] under [`Self::has_kind`] that skips every
4220    /// populated slot, returns `false` at the EARLIEST missing slot
4221    /// whose kind is NOT `kind`, and returns `true` iff the sweep
4222    /// completes with `kind` seen as the sole missing slot. Byte-for-
4223    /// byte cheaper than either widened composition
4224    /// `self.missing_kinds() == vec![kind]` (which allocates the
4225    /// missing-kind Vec before the equality test) or
4226    /// `self.lacks_kind(kind) && self.missing_kind_count() == 1` (which
4227    /// walks the closed-set-complement scan twice) on every arm where
4228    /// the slice carries a missing kind that isn't `kind`.
4229    ///
4230    /// # Peer to [`crate::tagged_union::TaggedUnion::lacks_only`]
4231    ///
4232    /// Slice-level peer of the tagged-union parent-level kind-scoped
4233    /// strict-refinement predicate on the missing axis one struct-layer
4234    /// up: where
4235    /// [`crate::tagged_union::TaggedUnion::lacks_only`] answers "is THIS
4236    /// kind's slot on the tagged-union parent the sole empty slot?",
4237    /// `lacks_only_kind` answers "is THIS kind the sole missing kind
4238    /// from the slice's distinct set?". Both primitives compose the
4239    /// SAME fused short-circuit closed-set walk under a per-kind
4240    /// [`Self::has_kind`] / `TaggedUnion::has` predicate at two adjacent
4241    /// typescape sites — the two primitives close the kind-scoped
4242    /// strict-refinement invariant on the near-saturation-diagonal
4243    /// (`N-1`-of-N populated with the sole hole at `kind`) arm at both
4244    /// struct layers under the SAME shape.
4245    ///
4246    /// # Sibling to [`Self::has_only_kind`]
4247    ///
4248    /// Closed-set-complement mirror of the well-formed-diagonal
4249    /// strict-refinement primitive on the populated axis — where
4250    /// `has_only_kind(k)` returns `true` iff `k` is the sole distinct
4251    /// populated kind, `lacks_only_kind(k)` returns `true` iff `k` is
4252    /// the sole missing kind. Together the two peers CLOSE the
4253    /// (populated, missing) × (subset, equal) 2x2 kind-scoped
4254    /// strict-refinement grid at the slice level alongside `has_kind`
4255    /// (populated subset) and `lacks_kind` (missing subset).
4256    ///
4257    /// # Truth table on the slice-level closed-set-complement contract
4258    ///
4259    /// For a slice with `ConditionKind::ALL` of cardinality `N ≥ 2`
4260    /// and a fixed argument `kind`:
4261    ///
4262    /// - Empty slice (0 conditions, distinct-kind set empty,
4263    ///   missing-kind set == ALL): `false` on any `N ≥ 2` — every kind
4264    ///   is missing, so `kind` is NOT the sole missing kind.
4265    /// - Single-populated slice with populated kind `p` (1 condition,
4266    ///   missing-kind set == `ALL \ {p}`): `false` on any `N ≥ 3`
4267    ///   (`N - 1 ≥ 2` missing kinds, no sole missing kind); on `N == 2`
4268    ///   the missing set is `{q}` where `q ≠ p`, so
4269    ///   `lacks_only_kind(kind) == (kind == q)`.
4270    /// - Near-saturation slice with populated kinds `ALL \ {q}` (each
4271    ///   kind except `q` populated, missing set `{q}`): the SOLE `true`
4272    ///   arm — `lacks_only_kind(kind) == (kind == q)`.
4273    /// - Saturated slice (every kind appears): `false` on every kind —
4274    ///   no kind is missing, so no kind is the sole missing kind.
4275    /// - Multiplicity is ignored on the populated side: a slice
4276    ///   carrying `k` at every position still has an empty missing set,
4277    ///   or a missing set `{k'}` where `k' ≠ k`, byte-for-byte with
4278    ///   the single-populated arrangement.
4279    ///
4280    /// # Kind-domain exhaustivity
4281    ///
4282    /// A slice satisfies `lacks_only_kind(k)` for AT MOST one `k`,
4283    /// since two distinct kinds cannot both be the sole missing kind.
4284    /// On the near-saturation arm the count is exactly 1 (the sole
4285    /// missing kind); on every other arm the count is 0. This
4286    /// kind-domain exhaustivity law binds the argument-scoped
4287    /// projection to the parent-scoped cardinality primitive
4288    /// `missing_kind_count() == 1` at the composition-law surface.
4289    ///
4290    /// # Compounding future consumers
4291    ///
4292    /// - A `lacks-only-<kind>` require-tag classifier arm reaches this
4293    ///   primitive with no allocation, byte-for-byte peer of the
4294    ///   tagged-union `lacks-only-<kind>` classifier one struct-layer
4295    ///   up under the SAME fused short-circuit walk shape.
4296    /// - A "one dependency short: <kind>" diagnostic on the aggregate
4297    ///   boundary check reads
4298    ///   `slice.lacks_only_kind(k)` at ONE call site — one fused
4299    ///   short-circuit walk, no allocation, strictly cheaper than
4300    ///   `slice.first_missing_kind() == Some(k) && slice.missing_kind_count() == 1`
4301    ///   which walks the closed-set-complement scan twice.
4302    /// - A coherence check that verifies "the near-saturation slice
4303    ///   from an `all_but_one_kind_of(k)` factory is unambiguously
4304    ///   missing kind `k`" reads `slice.lacks_only_kind(k)` at ONE
4305    ///   site — the strongest structural pin on the missing-side
4306    ///   well-formed diagonal.
4307    ///
4308    /// # Theory grounding
4309    ///
4310    /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4311    ///   The kind-scoped strict-refinement projection on the missing
4312    ///   axis lives at ONE substrate site as a fused short-circuit
4313    ///   walk over [`ConditionKind::ALL`] under [`Self::has_kind`]
4314    ///   with early exit on the first missing slot whose kind is not
4315    ///   `kind` — byte-for-byte peer of [`Self::has_only_kind`]'s
4316    ///   fused walk under complement, semantically identical to
4317    ///   `first_missing_kind() == Some(kind) && missing_kind_count() == 1`
4318    ///   on every arm.
4319    /// - THEORY.md §VI.1 — generation over composition. A new
4320    ///   [`ConditionKind`] variant added to `ALL` reaches this
4321    ///   primitive mechanically through the delegated `has_kind` walk
4322    ///   — every downstream `lacks-only-<kind>` classifier arm sees
4323    ///   the wider kind set without further per-caller edit.
4324    fn lacks_only_kind(&self, kind: ConditionKind) -> bool {
4325        let mut saw_kind = false;
4326        for k in ConditionKind::ALL {
4327            if self.has_kind(k) {
4328                continue;
4329            }
4330            if k == kind {
4331                saw_kind = true;
4332            } else {
4333                return false;
4334            }
4335        }
4336        saw_kind
4337    }
4338}
4339
4340/// Iterator yielded by [`ConditionSliceExt::iter_kind`] — the widened
4341/// primitive on the slice-level presence-probe axis. Wraps a
4342/// [`std::slice::Iter`] over `Condition` values with a
4343/// [`ConditionKind`] discriminator; [`Iterator::next`] short-circuits
4344/// via [`std::iter::Iterator::find`] on the wrapped iterator so the
4345/// filter walk is byte-identical to `self.iter().filter(|c| c.kind ==
4346/// kind).next()` without paying for the anonymous-closure type
4347/// erasure a chained-adapter return position would carry.
4348///
4349/// # Why a named type
4350///
4351/// [`ConditionSliceExt::iter_kind`] returns this concrete type rather
4352/// than `impl Iterator<Item = &Condition>` so downstream consumers
4353/// (a fleet-wide audit dump that stores match streams in a struct
4354/// field, a coherence check that composes the iterator against
4355/// [`std::iter::Chain`] across pre-/post-conditions) name the
4356/// primitive's return without pulling in RPITIT's unnameable
4357/// per-callsite type. [`Boundary::iter_condition_kind`] and
4358/// [`crate::ephemeral::EphemeralSpec::iter_condition_kind`] chain two
4359/// [`KindMatches`] iterators via [`Iterator::chain`] — the resulting
4360/// [`std::iter::Chain<KindMatches<'_>, KindMatches<'_>>`] is itself
4361/// a standard nameable type.
4362pub struct KindMatches<'a> {
4363    inner: std::slice::Iter<'a, Condition>,
4364    kind: ConditionKind,
4365}
4366
4367impl<'a> Iterator for KindMatches<'a> {
4368    type Item = &'a Condition;
4369
4370    fn next(&mut self) -> Option<Self::Item> {
4371        self.inner.by_ref().find(|c| c.kind == self.kind)
4372    }
4373}
4374
4375impl ConditionSliceExt for [Condition] {
4376    fn iter_kind(&self, kind: ConditionKind) -> KindMatches<'_> {
4377        KindMatches {
4378            inner: self.iter(),
4379            kind,
4380        }
4381    }
4382}
4383
4384/// Generic slice-level substrate testkit — pins the FOUR composition
4385/// laws that bind the [`ConditionSliceExt`] refinement algebra
4386/// (`iter_kind` → `find_kind` → `has_kind` → `count_kind`) at ONE
4387/// call site per authored arrangement, sweeping [`ConditionKind::ALL`].
4388///
4389/// The [`ConditionSliceExt`] trait publishes four refinements on the
4390/// slice-level presence-probe axis:
4391///
4392/// | refinement | return type | default body                        |
4393/// |------------|-------------|-------------------------------------|
4394/// | `iter_kind`| [`KindMatches`]      | (widened primitive, required)      |
4395/// | `find_kind`| `Option<&Condition>` | `self.iter_kind(k).next()`         |
4396/// | `has_kind` | `bool`               | `self.find_kind(k).is_some()`      |
4397/// | `count_kind`| `usize`             | `self.iter_kind(k).count()`        |
4398///
4399/// The three coarser refinements are typed projections of the widened
4400/// primitive by construction. The composition laws that bind them
4401/// (and therefore surface any implementor that overrode a default
4402/// with a divergent walk shape — a stored-length cache that drifted,
4403/// a `.rev().find(...)` returning trailing-first, a `.step_by(2)`
4404/// artifact from a copy-paste of `iter_kind`) sweep at ONE typed
4405/// substrate site through this primitive:
4406///
4407/// 1. **`find ↔ iter`**: `find_kind(k) == iter_kind(k).next()` — the
4408///    first-match probe equals the widened stream's first yield.
4409/// 2. **`count ↔ iter`**: `count_kind(k) == iter_kind(k).count()` —
4410///    the cardinality probe equals the widened stream's yield count.
4411/// 3. **`has ↔ find`**: `has_kind(k) == find_kind(k).is_some()` —
4412///    the presence bit equals the first-match probe's `is_some()`.
4413/// 4. **`has ↔ count`**: `has_kind(k) == (count_kind(k) > 0)` — the
4414///    presence bit equals the cardinality's positivity test (the
4415///    dual composition path from `has` back to the widened primitive
4416///    that doesn't go through `find`).
4417///
4418/// Pre-lift each composition law lived at its own hand-authored
4419/// nested-`for` loop test in [`tatara_process::boundary`] tests
4420/// (`condition_slice_find_kind_equals_iter_kind_next`,
4421/// `condition_slice_count_kind_equals_iter_kind_count`,
4422/// `condition_slice_has_kind_equals_find_kind_is_some`,
4423/// `condition_slice_has_and_find_equal_count_greater_than_zero`) —
4424/// four sibling test bodies whose only per-law knobs were the
4425/// projection functions being bridged. Post-lift each authored
4426/// arrangement (empty, single-element, dual-populated, duplicate-
4427/// populated) pins ALL FOUR laws through ONE
4428/// `assert_slice_refinement_composition_laws(slice)` call whose body
4429/// is the substrate primitive's own sweep.
4430///
4431/// The primitive binds `<S: ConditionSliceExt + ?Sized>` so both a
4432/// bare `&[Condition]` and any future implementor of the trait
4433/// (a wrapper type with additional invariants, an alternative slice
4434/// projection over a builder's staging Vec) picks up the four-law
4435/// composition contract through ONE call site. `?Sized` lets the
4436/// caller pass `slice.as_slice()` or `&owned[..]` without an
4437/// intermediate reference dance.
4438///
4439/// # Compounding
4440///
4441/// A FIFTH refinement added to [`ConditionSliceExt`] (a hypothetical
4442/// `nth_kind(k, n) -> Option<&Condition>` for indexed match access,
4443/// a `distinct_kinds()` aggregate that returns which kinds appear at
4444/// least once, a `has_kind_matching(pred)` closure-based predicate
4445/// probe) lands its composition-law pins as ONE new arm inside this
4446/// primitive's sweep body. Every downstream test that already reaches
4447/// this primitive picks up the fifth-refinement pin mechanically —
4448/// no per-arrangement author-time enumeration of the new law across
4449/// the four sibling composition-law sites, no re-authored `for kind
4450/// in ConditionKind::ALL { … }` sweep at every consumer.
4451///
4452/// Symmetrical shape to
4453/// [`crate::tagged_union::assert_find_agrees_with_has`] on the
4454/// tagged-union parent axis: both project a widened-refinement /
4455/// coarser-refinement composition law contract onto ONE typed
4456/// substrate call site, both bind `<T: /* refinement carrier */>`
4457/// generically, both sweep the addressed closed set
4458/// ([`ConditionKind::ALL`] here, `<T::Kind as ClosedSet>::ALL`
4459/// there). The two primitives close the "refinement axis composes"
4460/// invariant at two adjacent typescape sites — one per closed-set-
4461/// addressed slice-level refinement, one per closed-set-addressed
4462/// tagged-union parent-level refinement.
4463///
4464/// Theory anchor: THEORY.md §II.1 invariant 5 — composition preserves
4465/// proofs. The four coarser refinements are typed projections of the
4466/// widened primitive, and this substrate primitive turns each
4467/// projection's composition law from doc-prose into a first-class
4468/// typed theorem provable generically over any
4469/// `S: ConditionSliceExt + ?Sized`. THEORY.md §VI.1 — generation over
4470/// composition; a new [`ConditionKind`] variant added to `ALL` reaches
4471/// every downstream composition-law consumer through the SAME
4472/// closed-set sweep with no per-caller edit.
4473#[track_caller]
4474pub fn assert_slice_refinement_composition_laws<S>(slice: &S)
4475where
4476    S: ConditionSliceExt + ?Sized,
4477{
4478    let distinct = slice.distinct_kinds();
4479    for kind in ConditionKind::ALL {
4480        let find_result = slice.find_kind(kind);
4481        let has_result = slice.has_kind(kind);
4482        let count_result = slice.count_kind(kind);
4483        let iter_next_kind = slice.iter_kind(kind).next().map(|c| c.kind);
4484        let iter_count = slice.iter_kind(kind).count();
4485
4486        // find ↔ iter
4487        assert_eq!(
4488            find_result.map(|c| c.kind),
4489            iter_next_kind,
4490            "find_kind({kind:?}) drifted from iter_kind({kind:?}).next()",
4491        );
4492        // count ↔ iter
4493        assert_eq!(
4494            count_result, iter_count,
4495            "count_kind({kind:?}) drifted from iter_kind({kind:?}).count()",
4496        );
4497        // has ↔ find
4498        assert_eq!(
4499            has_result,
4500            find_result.is_some(),
4501            "has_kind({kind:?}) drifted from find_kind({kind:?}).is_some()",
4502        );
4503        // has ↔ count
4504        assert_eq!(
4505            has_result,
4506            count_result > 0,
4507            "has_kind({kind:?}) drifted from (count_kind({kind:?}) > 0)",
4508        );
4509        // distinct ↔ has (per-kind membership on the closed-set-inversion axis)
4510        assert_eq!(
4511            distinct.contains(&kind),
4512            has_result,
4513            "distinct_kinds().contains({kind:?}) drifted from has_kind({kind:?})",
4514        );
4515    }
4516
4517    // distinct ↔ ALL-filter (canonical subsequence — closed-set-inversion
4518    // walks ConditionKind::ALL in order, filters by has_kind, dedups by
4519    // construction). A regression that (a) returned duplicates (a naive
4520    // `.iter().map(|c| c.kind).collect()` override that skipped dedup),
4521    // (b) drifted the walk order from ConditionKind::ALL to slice-encounter
4522    // order, or (c) returned a superset containing absent kinds surfaces
4523    // HERE at the substrate boundary.
4524    let canonical: Vec<ConditionKind> = ConditionKind::ALL
4525        .into_iter()
4526        .filter(|k| slice.has_kind(*k))
4527        .collect();
4528    assert_eq!(
4529        distinct, canonical,
4530        "distinct_kinds() must yield ConditionKind::ALL-ordered subsequence of kinds where has_kind is true (no duplicates, canonical order)",
4531    );
4532
4533    // iter_distinct_kinds ↔ distinct_kinds — the load-bearing iterator
4534    // peer of the closed-set-inversion widened primitive. `distinct_kinds`'s
4535    // default body IS `self.iter_distinct_kinds().collect()`, so the
4536    // composition law `distinct_kinds() ==
4537    // iter_distinct_kinds().collect::<Vec<_>>()` holds by construction —
4538    // a regression that overrode either surface with a divergent walk
4539    // (short-circuit skipping a kind, drifting the walk order from
4540    // ConditionKind::ALL, forgetting the `has_kind` filter, or divergent
4541    // yield sequences between repeated invocations) surfaces HERE at the
4542    // substrate boundary, not as silent skew between the iter-based fold
4543    // callsite and the Vec-based callsite. Symmetrical to the tagged-union
4544    // parent-level substrate testkit
4545    // `assert_iter_populated_kinds_matches_populated_kinds` under a
4546    // POSITIVE point-probe.
4547    let via_iter_distinct: Vec<ConditionKind> = slice.iter_distinct_kinds().collect();
4548    assert_eq!(
4549        via_iter_distinct, distinct,
4550        "iter_distinct_kinds().collect::<Vec<_>>() drifted from distinct_kinds()",
4551    );
4552    let via_iter_distinct_again: Vec<ConditionKind> = slice.iter_distinct_kinds().collect();
4553    assert_eq!(
4554        via_iter_distinct, via_iter_distinct_again,
4555        "iter_distinct_kinds() must be pure over &self — repeated collect diverged",
4556    );
4557
4558    // distinct_kind_count ↔ distinct_kinds.len() — the scalar
4559    // cardinality projection of the closed-set-inversion widened
4560    // primitive. A regression that overrode `distinct_kind_count` to
4561    // skip a kind, double-count a slot, or drift the walk from
4562    // `ConditionKind::ALL` surfaces HERE at the substrate boundary,
4563    // not as silent drift at every downstream `distinct-count-<n>`
4564    // require-tag classifier or audit-dump callsite.
4565    assert_eq!(
4566        slice.distinct_kind_count(),
4567        distinct.len(),
4568        "distinct_kind_count() drifted from distinct_kinds().len()",
4569    );
4570
4571    // missing ↔ has (per-kind complement on the closed-set-inversion
4572    // axis). Byte-for-byte peer to the `distinct ↔ has` arm above: the
4573    // present-side widened primitive `distinct_kinds` binds to
4574    // `has_kind` via `contains(&k) == has_kind(k)`; the missing-side
4575    // widened primitive `missing_kinds` binds via
4576    // `contains(&k) == !has_kind(k)` — the SAME point-probe primitive
4577    // reached under a negated predicate. A regression that overrode
4578    // `missing_kinds` to omit the negation (returning `distinct_kinds`
4579    // instead), inverted the wrong side, or dropped a variant surfaces
4580    // HERE.
4581    let missing = slice.missing_kinds();
4582    for kind in ConditionKind::ALL {
4583        assert_eq!(
4584            missing.contains(&kind),
4585            !slice.has_kind(kind),
4586            "missing_kinds().contains({kind:?}) drifted from !has_kind({kind:?})",
4587        );
4588    }
4589
4590    // missing ↔ ALL-filter (canonical subsequence — closed-set
4591    // complement walks ConditionKind::ALL in order, filters by
4592    // !has_kind, dedups by construction). Peer to the `distinct ↔
4593    // ALL-filter` arm above; catches ordering + dedup drift on the
4594    // complement side that the per-kind membership arm cannot detect
4595    // on its own.
4596    let canonical_missing: Vec<ConditionKind> = ConditionKind::ALL
4597        .into_iter()
4598        .filter(|k| !slice.has_kind(*k))
4599        .collect();
4600    assert_eq!(
4601        missing, canonical_missing,
4602        "missing_kinds() must yield ConditionKind::ALL-ordered subsequence of kinds where has_kind is false (no duplicates, canonical order)",
4603    );
4604
4605    // iter_missing_kinds ↔ missing_kinds — the load-bearing iterator peer
4606    // of the closed-set-complement widened primitive on the missing side.
4607    // `missing_kinds`'s default body IS `self.iter_missing_kinds().collect()`,
4608    // so the composition law
4609    // `missing_kinds() == iter_missing_kinds().collect::<Vec<_>>()` holds by
4610    // construction. Byte-for-byte peer of the `iter_distinct_kinds ↔
4611    // distinct_kinds` arm above under a NEGATED point-probe: a regression
4612    // that dropped the negation (returning `iter_distinct_kinds`), skipped
4613    // a kind on the complement side, or drifted the walk from
4614    // `ConditionKind::ALL` surfaces HERE at the substrate boundary.
4615    // Symmetrical to the tagged-union parent-level substrate testkit
4616    // `assert_iter_missing_kinds_matches_missing_kinds` under a NEGATED
4617    // point-probe.
4618    let via_iter_missing: Vec<ConditionKind> = slice.iter_missing_kinds().collect();
4619    assert_eq!(
4620        via_iter_missing, missing,
4621        "iter_missing_kinds().collect::<Vec<_>>() drifted from missing_kinds()",
4622    );
4623    let via_iter_missing_again: Vec<ConditionKind> = slice.iter_missing_kinds().collect();
4624    assert_eq!(
4625        via_iter_missing, via_iter_missing_again,
4626        "iter_missing_kinds() must be pure over &self — repeated collect diverged",
4627    );
4628
4629    // (distinct, missing) partition ConditionKind::ALL — three peer
4630    // laws that bind the closed-set-inversion widened primitive
4631    // `distinct_kinds` to its complement peer `missing_kinds`:
4632    //
4633    // 1. Disjoint: every kind appears in AT MOST one of the two sets.
4634    // 2. Covering: every kind appears in AT LEAST one of the two sets
4635    //    (equivalent to the union covering ConditionKind::ALL).
4636    // 3. Cardinality partition: `distinct.len() + missing.len() ==
4637    //    ConditionKind::ALL.len()` — the scalar consequence of (1) +
4638    //    (2) that a caller reaching for the cardinality peer would
4639    //    otherwise pay for the two allocations at every callsite.
4640    for kind in ConditionKind::ALL {
4641        assert!(
4642            !(distinct.contains(&kind) && missing.contains(&kind)),
4643            "(distinct_kinds, missing_kinds) partition invariant violated — both contain {kind:?}",
4644        );
4645        assert!(
4646            distinct.contains(&kind) || missing.contains(&kind),
4647            "(distinct_kinds, missing_kinds) partition invariant violated — neither contains {kind:?}",
4648        );
4649    }
4650    assert_eq!(
4651        distinct.len() + missing.len(),
4652        ConditionKind::ALL.len(),
4653        "(distinct_kinds, missing_kinds) cardinality partition drift — sum {} ≠ ConditionKind::ALL.len() {}",
4654        distinct.len() + missing.len(),
4655        ConditionKind::ALL.len(),
4656    );
4657
4658    // missing_kind_count ↔ missing_kinds.len() — the scalar cardinality
4659    // projection of the closed-set-complement widened primitive. A
4660    // regression that overrode `missing_kind_count` to drop the
4661    // negation (returning `distinct_kind_count`), skip a kind, double-
4662    // count a slot, or drift the walk from `ConditionKind::ALL`
4663    // surfaces HERE at the substrate boundary, not as silent drift at
4664    // every downstream `condition-kinds-missing-<n>` require-tag
4665    // classifier or gap-analysis-dashboard callsite.
4666    assert_eq!(
4667        slice.missing_kind_count(),
4668        missing.len(),
4669        "missing_kind_count() drifted from missing_kinds().len()",
4670    );
4671
4672    // (distinct_kind_count, missing_kind_count) partition
4673    // ConditionKind::ALL's cardinality — the scalar consequence of the
4674    // widened-primitive partition law `distinct ∪ missing == ALL,
4675    // disjoint` above. A regression that (a) drifted the scalar
4676    // cardinality peer from the widened primitive on either side or
4677    // (b) drifted the partition invariant surfaces HERE at ONE typed
4678    // arm rather than as silent drift at every scalar-cardinality
4679    // callsite that reaches for the sum.
4680    assert_eq!(
4681        slice.distinct_kind_count() + slice.missing_kind_count(),
4682        ConditionKind::ALL.len(),
4683        "(distinct_kind_count, missing_kind_count) scalar partition drift — sum {} ≠ ConditionKind::ALL.len() {}",
4684        slice.distinct_kind_count() + slice.missing_kind_count(),
4685        ConditionKind::ALL.len(),
4686    );
4687
4688    // first_distinct_kind ↔ distinct_kinds.first().copied() — the
4689    // earliest-element scalar projection of the closed-set-inversion
4690    // widened primitive. Peer of `distinct_kind_count ↔ distinct_kinds
4691    // .len()` on the scalar-projection axis: where the cardinality peer
4692    // collapses the SET to its length, the earliest-element peer
4693    // collapses the SET to its first element. A regression that
4694    // overrode `first_distinct_kind` to skip a kind, drift the walk
4695    // from ConditionKind::ALL, forget the short-circuit (returning
4696    // the LAST hit), or diverge from the widened primitive's canonical
4697    // ordering surfaces HERE at the substrate boundary, not as silent
4698    // drift at every downstream `first-distinct-<kind>` require-tag
4699    // classifier callsite.
4700    assert_eq!(
4701        slice.first_distinct_kind(),
4702        distinct.first().copied(),
4703        "first_distinct_kind() drifted from distinct_kinds().first().copied()",
4704    );
4705
4706    // first_missing_kind ↔ missing_kinds.first().copied() — the
4707    // earliest-element scalar projection of the closed-set-complement
4708    // widened primitive. Byte-for-byte peer of `first_distinct_kind`
4709    // one axis over under a negated predicate: where
4710    // `first_distinct_kind` scalar-projects the closed-set-INVERSION
4711    // widened primitive onto its earliest element, this arm scalar-
4712    // projects the closed-set-COMPLEMENT widened primitive onto its
4713    // earliest element. A regression that overrode `first_missing_kind`
4714    // to drop the negation (returning `first_distinct_kind`), skip a
4715    // kind, drift the walk from ConditionKind::ALL, or forget the
4716    // short-circuit (returning the LAST missing hit) surfaces HERE at
4717    // the substrate boundary, not as silent drift at every downstream
4718    // `first-missing-<kind>` require-tag classifier callsite.
4719    assert_eq!(
4720        slice.first_missing_kind(),
4721        missing.first().copied(),
4722        "first_missing_kind() drifted from missing_kinds().first().copied()",
4723    );
4724
4725    // last_distinct_kind ↔ distinct_kinds.last().copied() — the
4726    // latest-element scalar projection of the closed-set-inversion
4727    // widened primitive. Time-reversed peer of `first_distinct_kind
4728    // ↔ distinct_kinds.first().copied()` under the SAME `has_kind`
4729    // predicate but with the closed-set walk reversed: where the
4730    // earliest-element peer picks the smallest ALL index that hits,
4731    // this arm picks the LARGEST. A regression that overrode
4732    // `last_distinct_kind` to skip a kind, drift the walk direction
4733    // (returning `first_distinct_kind`), forget the short-circuit
4734    // (returning `distinct_kinds().rev().next()` allocation), or
4735    // diverge from the widened primitive's canonical ordering
4736    // surfaces HERE at the substrate boundary, not as silent drift
4737    // at every downstream `last-distinct-<kind>` require-tag
4738    // classifier callsite.
4739    assert_eq!(
4740        slice.last_distinct_kind(),
4741        distinct.last().copied(),
4742        "last_distinct_kind() drifted from distinct_kinds().last().copied()",
4743    );
4744
4745    // last_missing_kind ↔ missing_kinds.last().copied() — the
4746    // latest-element scalar projection of the closed-set-complement
4747    // widened primitive. Byte-for-byte peer of `last_distinct_kind`
4748    // one axis over under a NEGATED predicate: where
4749    // `last_distinct_kind` scalar-projects the closed-set-INVERSION
4750    // widened primitive onto its LATEST element, this arm scalar-
4751    // projects the closed-set-COMPLEMENT widened primitive onto its
4752    // LATEST element. A regression that overrode `last_missing_kind`
4753    // to drop the negation (returning `last_distinct_kind`), reverse
4754    // the walk direction (returning `first_missing_kind`), skip a
4755    // kind, or forget the short-circuit surfaces HERE at the
4756    // substrate boundary, not as silent drift at every downstream
4757    // `last-missing-<kind>` require-tag classifier callsite.
4758    assert_eq!(
4759        slice.last_missing_kind(),
4760        missing.last().copied(),
4761        "last_missing_kind() drifted from missing_kinds().last().copied()",
4762    );
4763
4764    // is_kind_saturated ↔ (missing_kind_count == 0) — the Boolean
4765    // saturation-endpoint projection of the closed-set-complement
4766    // scalar cardinality. Peer of `first_missing_kind ↔ missing_kinds
4767    // .first().copied()` on the endpoint-projection axis: where the
4768    // earliest-element peer collapses the missing SET to its first
4769    // element, this Boolean peer collapses the missing scalar to its
4770    // zero-arm test. A regression that overrode `is_kind_saturated` to
4771    // drop the negation (returning `slice.is_empty()`), skip a kind,
4772    // or drift the walk from `ConditionKind::ALL` surfaces HERE at
4773    // the substrate boundary, not as silent drift at every downstream
4774    // `is-kind-saturated` require-tag classifier or fleet-wide gap-
4775    // analysis dashboard callsite. Byte-for-byte peer of
4776    // `crate::tagged_union::TaggedUnion::is_saturated` one struct-
4777    // layer up under the same `<CLOSED_SET>::ALL.iter().all(has)`
4778    // short-circuit shape.
4779    assert_eq!(
4780        slice.is_kind_saturated(),
4781        slice.missing_kind_count() == 0,
4782        "is_kind_saturated() drifted from (missing_kind_count() == 0)",
4783    );
4784    assert_eq!(
4785        slice.is_kind_saturated(),
4786        missing.is_empty(),
4787        "is_kind_saturated() drifted from missing_kinds().is_empty()",
4788    );
4789
4790    // has_any_missing_kind ↔ !is_kind_saturated — the Boolean at-
4791    // least-one halfspace projection of the closed-set-complement
4792    // scalar cardinality. Peer of `is_kind_saturated ↔
4793    // (missing_kind_count == 0)` on the Boolean-negation axis: where
4794    // the saturation-endpoint peer tests the zero-arm, this at-least-
4795    // one halfspace peer tests its negation. Together the two Booleans
4796    // partition the missing-cardinality closed set — exactly one is
4797    // `true` for every slice. A regression that overrode
4798    // `has_any_missing_kind` to drop the negation (returning
4799    // `is_kind_saturated`), skip a kind, or drift the walk from
4800    // `ConditionKind::ALL` surfaces HERE at the substrate boundary,
4801    // not as silent drift at every downstream `has-any-missing-kind`
4802    // require-tag classifier or fleet-wide gap-analysis dashboard
4803    // callsite. Byte-for-byte peer of
4804    // `crate::tagged_union::TaggedUnion::has_any_missing_kind` one
4805    // struct-layer up under the SAME `!is_saturated` definitional
4806    // negation shape. Also pins the widened composition laws
4807    // `has_any_missing_kind() == (missing_kind_count() > 0)` and
4808    // `has_any_missing_kind() == !missing_kinds().is_empty()` at every
4809    // slice — binds the at-least-one halfspace Boolean projection to
4810    // the widened + scalar closed-set-complement primitives without
4811    // paying for the Vec allocation.
4812    assert_eq!(
4813        slice.has_any_missing_kind(),
4814        !slice.is_kind_saturated(),
4815        "has_any_missing_kind() drifted from !is_kind_saturated()",
4816    );
4817    assert_eq!(
4818        slice.has_any_missing_kind(),
4819        slice.missing_kind_count() > 0,
4820        "has_any_missing_kind() drifted from (missing_kind_count() > 0)",
4821    );
4822    assert_eq!(
4823        slice.has_any_missing_kind(),
4824        !missing.is_empty(),
4825        "has_any_missing_kind() drifted from !missing_kinds().is_empty()",
4826    );
4827
4828    // has_any_distinct_kind ↔ (distinct_kind_count > 0) — the Boolean
4829    // at-least-one halfspace projection of the closed-set-inversion
4830    // scalar cardinality. Peer of `has_any_missing_kind ↔
4831    // !is_kind_saturated` on the axis-parity axis: where the at-least-
4832    // one halfspace peer on the closed-set-complement axis tests the
4833    // ≥ 1 arm on the missing scalar, this at-least-one halfspace peer
4834    // on the closed-set-inversion axis tests the ≥ 1 arm on the
4835    // distinct scalar. A regression that overrode `has_any_distinct_kind`
4836    // to drop the short-circuit, skip a kind, or drift the walk from
4837    // `ConditionKind::ALL` surfaces HERE at the substrate boundary, not
4838    // as silent drift at every downstream `has-any-distinct-kind`
4839    // require-tag classifier or fleet-wide coverage-analysis dashboard
4840    // callsite. Byte-for-byte peer of
4841    // `crate::tagged_union::TaggedUnion::has_any_populated_kind` one
4842    // struct-layer up under the SAME `any(has)` short-circuit shape.
4843    // Also pins the widened composition law `has_any_distinct_kind() ==
4844    // !distinct_kinds().is_empty()` at every slice — binds the at-
4845    // least-one halfspace Boolean projection to the widened primitive
4846    // without paying for the Vec allocation.
4847    assert_eq!(
4848        slice.has_any_distinct_kind(),
4849        slice.distinct_kind_count() > 0,
4850        "has_any_distinct_kind() drifted from (distinct_kind_count() > 0)",
4851    );
4852    assert_eq!(
4853        slice.has_any_distinct_kind(),
4854        !distinct.is_empty(),
4855        "has_any_distinct_kind() drifted from !distinct_kinds().is_empty()",
4856    );
4857    assert_eq!(
4858        slice.has_any_distinct_kind(),
4859        slice.first_distinct_kind().is_some(),
4860        "has_any_distinct_kind() drifted from first_distinct_kind().is_some()",
4861    );
4862
4863    // has_unique_missing_kind ↔ (missing_kind_count == 1) — the
4864    // Boolean cardinality-mid-endpoint projection of the closed-set-
4865    // complement scalar cardinality. Peer of `has_any_missing_kind ↔
4866    // !is_kind_saturated` on the Boolean-projection axis: where the
4867    // at-least-one halfspace peer tests the ≥ 1 arm on the missing
4868    // scalar, this cardinality-mid-endpoint peer tests the exactly-
4869    // one arm. Together with `is_kind_saturated` (zero-arm) and the
4870    // future many-arm peer, the three Booleans partition the missing-
4871    // cardinality closed set at 0, 1, and ≥ 2 respectively. A
4872    // regression that overrode `has_unique_missing_kind` to drop the
4873    // second-slot short-circuit (returning any partial-populated
4874    // arm), skip a kind, drift the walk from `ConditionKind::ALL`, or
4875    // conflate with `is_kind_saturated` (the zero-arm) surfaces HERE
4876    // at the substrate boundary, not as silent drift at every
4877    // downstream `has-unique-missing-kind` require-tag classifier or
4878    // near-saturation-endpoint diagnostic callsite. Byte-for-byte
4879    // peer of `crate::tagged_union::TaggedUnion::has_unique_missing_kind`
4880    // one struct-layer up under the SAME two-step short-circuit
4881    // walk shape. Also pins the widened composition law
4882    // `has_unique_missing_kind() == (missing_kinds().len() == 1)` at
4883    // every slice — binds the cardinality-mid-endpoint Boolean
4884    // projection to the widened + scalar closed-set-complement
4885    // primitives without paying for the Vec allocation on the ≥ 2-
4886    // missing arms (where the short-circuit fires).
4887    assert_eq!(
4888        slice.has_unique_missing_kind(),
4889        slice.missing_kind_count() == 1,
4890        "has_unique_missing_kind() drifted from (missing_kind_count() == 1)",
4891    );
4892    assert_eq!(
4893        slice.has_unique_missing_kind(),
4894        missing.len() == 1,
4895        "has_unique_missing_kind() drifted from (missing_kinds().len() == 1)",
4896    );
4897
4898    // has_multiple_missing_kinds ↔ (missing_kind_count >= 2) — the
4899    // Boolean cardinality many-arm projection of the closed-set-
4900    // complement scalar cardinality. Peer of `has_any_missing_kind ↔
4901    // !is_kind_saturated` (≥ 1 halfspace) and `has_unique_missing_kind
4902    // ↔ (missing_kind_count == 1)` (= 1 mid-endpoint) on the Boolean-
4903    // projection axis: where those peers test the ≥ 1 and = 1 arms on
4904    // the missing scalar, this many-arm peer tests the ≥ 2 arm.
4905    // Together with `is_kind_saturated` (zero-arm) and
4906    // `has_unique_missing_kind` (one-arm), the three Booleans
4907    // partition the missing-cardinality closed set at 0, 1, and ≥ 2
4908    // respectively — every slice satisfies EXACTLY ONE of the three
4909    // projections. A regression that overrode `has_multiple_missing_kinds`
4910    // to drop the second-slot short-circuit (returning `true` on any
4911    // ≥ 1-missing arm), skip a kind, drift the walk from
4912    // `ConditionKind::ALL`, or conflate with `has_any_missing_kind`
4913    // (the ≥ 1 halfspace) surfaces HERE at the substrate boundary,
4914    // not as silent drift at every downstream
4915    // `has-multiple-missing-kinds` require-tag classifier or
4916    // coverage-gap diagnostic callsite. Byte-for-byte peer of
4917    // `crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`
4918    // one struct-layer up under the SAME two-step short-circuit walk
4919    // shape. Also pins the widened composition law
4920    // `has_multiple_missing_kinds() == (missing_kinds().len() >= 2)`
4921    // at every slice — binds the cardinality-many-arm Boolean
4922    // projection to the widened + scalar closed-set-complement
4923    // primitives without paying for the Vec allocation on the ≥ 2-
4924    // missing arms (where the short-circuit fires) or the full-slot
4925    // walk on the scalar counter.
4926    assert_eq!(
4927        slice.has_multiple_missing_kinds(),
4928        slice.missing_kind_count() >= 2,
4929        "has_multiple_missing_kinds() drifted from (missing_kind_count() >= 2)",
4930    );
4931    assert_eq!(
4932        slice.has_multiple_missing_kinds(),
4933        missing.len() >= 2,
4934        "has_multiple_missing_kinds() drifted from (missing_kinds().len() >= 2)",
4935    );
4936
4937    // has_at_most_one_missing_kind ↔ !has_multiple_missing_kinds — the
4938    // Boolean cardinality "≤ 1" negation projection of the many-arm
4939    // primitive on the closed-set-complement axis. Peer of
4940    // `has_multiple_missing_kinds ↔ (missing_kind_count >= 2)` (≥ 2
4941    // many-arm) under the definitional Boolean negation
4942    // `!(≥ 2) == (≤ 1)`. Together with `is_kind_saturated` (=0
4943    // zero-arm) and `has_unique_missing_kind` (=1 mid-endpoint), the
4944    // "≤ 1" primitive collapses to the trichotomy-union
4945    // `is_kind_saturated() || has_unique_missing_kind()` — a
4946    // regression that overrode `has_at_most_one_missing_kind` to drop
4947    // the definitional negation (returning `has_multiple_missing_kinds`
4948    // itself), swap the wrong side, or drift the walk from the
4949    // many-arm primitive surfaces HERE at the substrate boundary, not
4950    // as silent drift at every downstream
4951    // `has-at-most-one-missing-kind` require-tag classifier or near-
4952    // saturation-or-saturated gap-analysis diagnostic callsite. Byte-
4953    // for-byte peer of
4954    // `crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`
4955    // one struct-layer up under the SAME `!has_multiple_missing_kinds`
4956    // definitional negation shape. Also pins the widened composition
4957    // laws
4958    // `has_at_most_one_missing_kind() == (missing_kind_count() <= 1)`
4959    // and `has_at_most_one_missing_kind() == (missing_kinds().len() <= 1)`
4960    // at every slice — binds the "≤ 1" Boolean projection to the
4961    // widened + scalar closed-set-complement primitives without paying
4962    // for the Vec allocation on the ≤ 1-missing arms (where the
4963    // negated short-circuit fires immediately after the many-arm walk
4964    // stops) or the full-slot walk on the scalar counter. Also pins
4965    // the trichotomy-union composition law
4966    // `has_at_most_one_missing_kind() == is_kind_saturated() ||
4967    // has_unique_missing_kind()` at every slice — surfaces any
4968    // implementor that drifted the trichotomy union operator from
4969    // `||` to `&&` or that broke one of the two arm primitives while
4970    // leaving the "≤ 1" negation of the many-arm intact.
4971    assert_eq!(
4972        slice.has_at_most_one_missing_kind(),
4973        !slice.has_multiple_missing_kinds(),
4974        "has_at_most_one_missing_kind() drifted from !has_multiple_missing_kinds()",
4975    );
4976    assert_eq!(
4977        slice.has_at_most_one_missing_kind(),
4978        slice.missing_kind_count() <= 1,
4979        "has_at_most_one_missing_kind() drifted from (missing_kind_count() <= 1)",
4980    );
4981    assert_eq!(
4982        slice.has_at_most_one_missing_kind(),
4983        missing.len() <= 1,
4984        "has_at_most_one_missing_kind() drifted from (missing_kinds().len() <= 1)",
4985    );
4986    assert_eq!(
4987        slice.has_at_most_one_missing_kind(),
4988        slice.is_kind_saturated() || slice.has_unique_missing_kind(),
4989        "has_at_most_one_missing_kind() drifted from (is_kind_saturated() || has_unique_missing_kind())",
4990    );
4991
4992    // lacks_kind ↔ !has_kind — the Boolean per-kind complement
4993    // projection on the closed-set-complement axis. Peer of
4994    // `is_kind_saturated ↔ (missing_kind_count == 0)` on the Boolean-
4995    // projection axis: where the saturation-endpoint peer collapses
4996    // the whole missing scalar to its zero-arm test, this per-kind
4997    // peer collapses the whole missing SET to its per-kind membership
4998    // Boolean for ONE addressed kind. A regression that overrode
4999    // `lacks_kind` to drop the negation (returning `has_kind`), swap
5000    // the wrong side, or drift the walk from `has_kind` surfaces HERE
5001    // at the substrate boundary, not as silent drift at every
5002    // downstream `lacks-<kind>` require-tag classifier or
5003    // dependency-satisfaction coherence check callsite. Byte-for-byte
5004    // peer of `crate::tagged_union::TaggedUnion::lacks` one struct-
5005    // layer up under the SAME `!has(kind)` definitional negation
5006    // shape. Also pins the widened composition law
5007    // `lacks_kind(k) == missing_kinds().contains(&k)` at every arm —
5008    // binds the per-kind Boolean projection to the widened closed-set-
5009    // complement primitive without paying for the Vec allocation.
5010    for kind in ConditionKind::ALL {
5011        assert_eq!(
5012            slice.lacks_kind(kind),
5013            !slice.has_kind(kind),
5014            "lacks_kind({kind:?}) drifted from !has_kind({kind:?})",
5015        );
5016        assert_eq!(
5017            slice.lacks_kind(kind),
5018            missing.contains(&kind),
5019            "lacks_kind({kind:?}) drifted from missing_kinds().contains(&{kind:?})",
5020        );
5021    }
5022
5023    // has_only_kind(k) ↔ (distinct_kinds() == vec![k]) — the kind-
5024    // scoped strict-refinement projection on the closed-set-inversion
5025    // axis. Peer of `lacks_kind ↔ !has_kind` under a symmetrical
5026    // refinement axis: where `lacks_kind` refines `has_kind` under a
5027    // definitional negation (per-kind Boolean complement),
5028    // `has_only_kind` refines it under a well-formed-diagonal
5029    // strengthening (per-kind Boolean AND
5030    // `distinct_kind_count() == 1`). Together the two peers occupy
5031    // the (weaken, strengthen) axes of the per-kind projection on the
5032    // closed-set-inversion widened primitive at the slice level.
5033    // A regression that overrode `has_only_kind` to drop the fused-
5034    // walk short-circuit (returning `has_kind` — TOO LOOSE, admits
5035    // multi-kind slices) or to drop the `saw_kind` arm (returning
5036    // `distinct_kind_count() <= 1` — TOO LOOSE, admits the empty
5037    // slice as well-formed) surfaces HERE at the substrate boundary,
5038    // not as silent drift at every downstream `has-only-<kind>`
5039    // require-tag classifier or well-formed-diagonal coherence check
5040    // callsite. Byte-for-byte peer of
5041    // `crate::tagged_union::TaggedUnion::has_only` one struct-layer
5042    // up under the SAME fused short-circuit closed-set walk shape.
5043    // Also pins the widened composition laws
5044    // `has_only_kind(k) == (distinct_kinds() == vec![k])`,
5045    // `has_only_kind(k) == (has_kind(k) && distinct_kind_count() == 1)`,
5046    // and the kind-domain exhaustivity law "AT MOST ONE `k` satisfies
5047    // `has_only_kind(k)` on any slice".
5048    let mut has_only_hits = 0usize;
5049    for kind in ConditionKind::ALL {
5050        let expected_widened = distinct == vec![kind];
5051        assert_eq!(
5052            slice.has_only_kind(kind),
5053            expected_widened,
5054            "has_only_kind({kind:?}) drifted from (distinct_kinds() == vec![{kind:?}])",
5055        );
5056        assert_eq!(
5057            slice.has_only_kind(kind),
5058            slice.has_kind(kind) && slice.distinct_kind_count() == 1,
5059            "has_only_kind({kind:?}) drifted from (has_kind({kind:?}) && distinct_kind_count() == 1)",
5060        );
5061        // Strict-refinement of `has_kind`: has_only_kind(k) ⟹ has_kind(k).
5062        if slice.has_only_kind(kind) {
5063            assert!(
5064                slice.has_kind(kind),
5065                "has_only_kind({kind:?}) implies has_kind({kind:?})",
5066            );
5067            has_only_hits += 1;
5068        }
5069    }
5070    // Kind-domain exhaustivity — AT MOST ONE `k` satisfies
5071    // `has_only_kind(k)` on any slice.
5072    assert!(
5073        has_only_hits <= 1,
5074        "has_only_kind(k) satisfied by more than one kind (count={has_only_hits}) — kind-domain exhaustivity violated",
5075    );
5076    // has_only_kind(k) for SOME k ⟺ distinct_kind_count() == 1 — the
5077    // kind-domain-exhaustivity ⟺ well-formed-diagonal pin.
5078    assert_eq!(
5079        has_only_hits == 1,
5080        slice.distinct_kind_count() == 1,
5081        "has_only_kind holds for some kind iff distinct_kind_count() == 1",
5082    );
5083
5084    // lacks_only_kind(k) ↔ (missing_kinds() == vec![k]) — the kind-
5085    // scoped strict-refinement projection on the closed-set-complement
5086    // axis. Byte-for-byte peer of `has_only_kind` under complement:
5087    // where `has_only_kind` refines `has_kind` under a well-formed-
5088    // diagonal strengthening on the populated axis, `lacks_only_kind`
5089    // refines `lacks_kind` under the same strengthening on the missing
5090    // axis — the closed-set-complement mirror closes the (populated,
5091    // missing) × (subset, equal) 2x2 kind-scoped strict-refinement grid
5092    // at the slice level alongside `has_kind` / `lacks_kind` /
5093    // `has_only_kind`. A regression that overrode `lacks_only_kind` to
5094    // drop the fused-walk short-circuit (returning `lacks_kind` — TOO
5095    // LOOSE, admits multi-missing-kind slices) or to drop the
5096    // `saw_kind` arm (returning `missing_kind_count() <= 1` — TOO
5097    // LOOSE, admits the saturated slice as well-formed on the missing
5098    // axis) surfaces HERE at the substrate boundary, not as silent
5099    // drift at every downstream `lacks-only-<kind>` require-tag
5100    // classifier or near-saturation-diagonal coherence check callsite.
5101    // Byte-for-byte peer of `crate::tagged_union::TaggedUnion::lacks_only`
5102    // one struct-layer up under the SAME fused short-circuit closed-set
5103    // walk shape. Also pins the widened composition laws
5104    // `lacks_only_kind(k) == (missing_kinds() == vec![k])`,
5105    // `lacks_only_kind(k) == (lacks_kind(k) && missing_kind_count() == 1)`,
5106    // and the kind-domain exhaustivity law "AT MOST ONE `k` satisfies
5107    // `lacks_only_kind(k)` on any slice".
5108    let mut lacks_only_hits = 0usize;
5109    for kind in ConditionKind::ALL {
5110        let expected_widened = missing == vec![kind];
5111        assert_eq!(
5112            slice.lacks_only_kind(kind),
5113            expected_widened,
5114            "lacks_only_kind({kind:?}) drifted from (missing_kinds() == vec![{kind:?}])",
5115        );
5116        assert_eq!(
5117            slice.lacks_only_kind(kind),
5118            slice.lacks_kind(kind) && slice.missing_kind_count() == 1,
5119            "lacks_only_kind({kind:?}) drifted from (lacks_kind({kind:?}) && missing_kind_count() == 1)",
5120        );
5121        // Strict-refinement of `lacks_kind`: lacks_only_kind(k) ⟹ lacks_kind(k).
5122        if slice.lacks_only_kind(kind) {
5123            assert!(
5124                slice.lacks_kind(kind),
5125                "lacks_only_kind({kind:?}) implies lacks_kind({kind:?})",
5126            );
5127            lacks_only_hits += 1;
5128        }
5129    }
5130    // Kind-domain exhaustivity — AT MOST ONE `k` satisfies
5131    // `lacks_only_kind(k)` on any slice.
5132    assert!(
5133        lacks_only_hits <= 1,
5134        "lacks_only_kind(k) satisfied by more than one kind (count={lacks_only_hits}) — kind-domain exhaustivity violated",
5135    );
5136    // lacks_only_kind(k) for SOME k ⟺ missing_kind_count() == 1 — the
5137    // kind-domain-exhaustivity ⟺ near-saturation-diagonal pin.
5138    assert_eq!(
5139        lacks_only_hits == 1,
5140        slice.missing_kind_count() == 1,
5141        "lacks_only_kind holds for some kind iff missing_kind_count() == 1",
5142    );
5143    // lacks_only_kind(k) ⟺ has_unique_missing_kind && first_missing_kind() == Some(k)
5144    // — kind-domain agreement with the arg-less unique-missing predicate.
5145    for kind in ConditionKind::ALL {
5146        assert_eq!(
5147            slice.lacks_only_kind(kind),
5148            slice.has_unique_missing_kind() && slice.first_missing_kind() == Some(kind),
5149            "lacks_only_kind({kind:?}) drifted from (has_unique_missing_kind() && first_missing_kind() == Some({kind:?}))",
5150        );
5151    }
5152}
5153
5154/// Substrate testkit macro — pins the FOUR union composition laws that
5155/// bind the (precondition, postcondition, union) refinement triads on
5156/// any authored surface exposing the 12-method (has / find / iter /
5157/// count) × (pre / post / union) `_kind` matrix. Sweeps
5158/// [`ConditionKind::ALL`] at ONE call site per authored arrangement.
5159///
5160/// # The four surface-level union composition laws
5161///
5162/// Where the slice-level substrate primitive
5163/// [`assert_slice_refinement_composition_laws`] pins the algebra that
5164/// binds the four refinements *on a single slice* (`iter_kind` →
5165/// `find_kind` → `has_kind` → `count_kind`), this macro pins the peer
5166/// algebra one struct-layer up: each refinement's union arm on a
5167/// two-slice surface (a [`Boundary`] with `preconditions` +
5168/// `postconditions`, an [`crate::ephemeral::EphemeralSpec`] with the
5169/// same eponymous field pair) composes from its two half-slice arms
5170/// through a specific monoid operator baked into the refinement's return
5171/// type:
5172///
5173/// | refinement | half-slice arms                             | union composition                     |
5174/// |------------|---------------------------------------------|---------------------------------------|
5175/// | `has_*_kind`   | `has_precondition_kind`, `has_postcondition_kind`     | `pre \|\| post` (bool OR)             |
5176/// | `find_*_kind`  | `find_precondition_kind`, `find_postcondition_kind`   | `pre.or(post)` (first-Some)           |
5177/// | `iter_*_kind`  | `iter_precondition_kind`, `iter_postcondition_kind`   | `pre.chain(post)` (stream concat)     |
5178/// | `count_*_kind` | `count_precondition_kind`, `count_postcondition_kind` | `pre + post` (cardinality SUM)        |
5179///
5180/// # Why lift
5181///
5182/// Pre-lift each surface-level union composition law lived at its own
5183/// hand-authored nested-`for` loop test on each of the two surfaces —
5184/// EIGHT sibling test bodies (`boundary_has_condition_kind_composes_precondition_and_postcondition_arms`,
5185/// `find_condition_kind_triad_delegates_to_slice_find_kind`,
5186/// `iter_condition_kind_triad_delegates_to_slice_iter_kind`,
5187/// `boundary_count_condition_kind_triad_delegates_and_sums_slice_count_kind`
5188/// on the [`Boundary`] surface, byte-for-byte peers on the
5189/// [`crate::ephemeral::EphemeralSpec`] surface) whose only per-law knobs
5190/// were the projection functions being bridged and the composition
5191/// operator (`\|\|` / `Option::or` / `Iterator::chain` / `+`) applied
5192/// on top. Post-lift each authored `(preconditions, postconditions)`
5193/// arrangement pins ALL FOUR union composition laws through ONE
5194/// `assert_surface_union_composition_laws!(surface)` call whose body
5195/// is the substrate primitive's own sweep, no per-surface author-time
5196/// enumeration.
5197///
5198/// # Why a macro rather than a `pub fn`
5199///
5200/// [`Boundary`] and [`crate::ephemeral::EphemeralSpec`] expose the
5201/// twelve methods as *inherent* methods with matching signatures. A
5202/// generic `pub fn assert_surface_union_composition_laws<B: T>(&B)`
5203/// would need a trait `T` publishing those same twelve methods, and
5204/// implementing that trait on either surface would collide with the
5205/// eponymous inherent methods at method resolution — the trait
5206/// impl would either duplicate the inherent-method bodies verbatim
5207/// (defeating the lift) or require renaming the trait methods with a
5208/// `_ext` suffix (introducing a parallel API surface). A macro
5209/// duck-types at expansion time and hits the inherent methods
5210/// directly, so both surfaces stay bound through the SAME
5211/// `_kind`-suffixed method names their non-generic callers already
5212/// reach for, and the pattern generalizes to any future surface that
5213/// grows the same twelve-method matrix (an `AplicacaoBoundary` typed
5214/// wrapper, a `PoolBoundary` gate-carrier at
5215/// [`crate::pool`], the boundary slot on a
5216/// hypothetical `AttestationBoundary` receipt-envelope surface) with
5217/// ONE macro invocation per authored arrangement rather than a per-
5218/// surface re-authored sweep over the four laws.
5219///
5220/// # Compounding
5221///
5222/// A FIFTH union refinement added to the (has, find, iter, count)
5223/// tetrad (a hypothetical `first_params_of_kind(k) -> Option<&Value>`
5224/// projection combining `find_condition_kind(k).map(|c| &c.params)` at
5225/// real reconciler callsites, a `distinct_kinds() -> impl Iterator<Item
5226/// = ConditionKind>` aggregate returning which kinds appear at least
5227/// once on either side, a `has_kind_matching(pred)` closure-based
5228/// predicate probe) lands its composition-law pin as ONE new arm
5229/// inside this macro's body. Every downstream test that already reaches
5230/// this macro picks up the fifth-refinement pin mechanically — no per-
5231/// arrangement author-time enumeration of the new law across the four
5232/// sibling composition-law sites on each of the two surfaces, no
5233/// re-authored `for kind in ConditionKind::ALL { … }` sweep at every
5234/// consumer.
5235///
5236/// Symmetrical shape to [`assert_slice_refinement_composition_laws`]
5237/// one layer below: both project a widened-refinement / coarser-
5238/// refinement composition law contract onto ONE typed substrate call
5239/// site, both sweep the addressed closed set [`ConditionKind::ALL`],
5240/// both surface any implementor that overrode the union arm with a
5241/// divergent composition operator (an `&&` inlined where `\|\|` is
5242/// required, a `pre - post` inlined where `pre + post` is required,
5243/// a `zip` inlined where `chain` is required, a `and_then` inlined
5244/// where `or_else` is required) as a first-class typed test failure
5245/// rather than as silent operator-facing drift at the
5246/// `condition-<kind>` / `precondition-<kind>` / `postcondition-<kind>`
5247/// require-tag classifier surfaces downstream.
5248///
5249/// # Theory grounding
5250///
5251/// - THEORY.md §II.1 invariant 5 — composition preserves proofs. Each
5252///   union arm is a typed projection of its two half-slice peers via
5253///   a specific monoid operator, and this substrate macro turns each
5254///   projection's composition law from doc-prose into a first-class
5255///   typed theorem provable against any surface exposing the twelve
5256///   `_kind`-suffixed inherent methods.
5257/// - THEORY.md §VI.1 — generation over composition. A new
5258///   [`ConditionKind`] variant added to `ALL` reaches every downstream
5259///   union-composition-law consumer through the SAME closed-set sweep
5260///   with no per-caller edit; a new surface (a typed wrapper carrying
5261///   the same twelve methods) picks up all four union composition-law
5262///   pins through ONE macro invocation per authored arrangement.
5263///
5264/// # Usage
5265///
5266/// ```ignore
5267/// // Point surface.
5268/// let mut b = Boundary::default();
5269/// b.preconditions.push(condition_with(ConditionKind::PromQL));
5270/// b.postconditions.push(condition_with(ConditionKind::ClosedLoopAuth));
5271/// assert_surface_union_composition_laws!(b);
5272///
5273/// // Ephemeral surface (peer, same primitive).
5274/// let mut spec = empty_ephemeral();
5275/// spec.postconditions.push(cond(ConditionKind::JobAttested));
5276/// assert_surface_union_composition_laws!(spec);
5277/// ```
5278#[macro_export]
5279macro_rules! assert_surface_union_composition_laws {
5280    ($surface:expr) => {{
5281        let __surface = &$surface;
5282        // Hoist distinct_* out of the per-kind loop — closed-set-inversion
5283        // refinements return the WHOLE distinct-set per call, so a single
5284        // computation per surface backs the per-kind membership arm inside
5285        // the loop AND the canonical-order equality after it.
5286        let __distinct_pre_kinds = __surface.distinct_precondition_kinds();
5287        let __distinct_post_kinds = __surface.distinct_postcondition_kinds();
5288        let __distinct_union_kinds = __surface.distinct_condition_kinds();
5289        let __missing_pre_kinds = __surface.missing_precondition_kinds();
5290        let __missing_post_kinds = __surface.missing_postcondition_kinds();
5291        let __missing_union_kinds = __surface.missing_condition_kinds();
5292        for __kind in $crate::boundary::ConditionKind::ALL {
5293            // has: union == pre || post (bool OR)
5294            let __has_via_arms =
5295                __surface.has_precondition_kind(__kind) || __surface.has_postcondition_kind(__kind);
5296            ::core::assert_eq!(
5297                __surface.has_condition_kind(__kind),
5298                __has_via_arms,
5299                "surface union has arm drifted from OR of half-slice arms for {:?}",
5300                __kind,
5301            );
5302            // find: union == pre.or(post) (first-Some, kind projection)
5303            let __find_via_arms = __surface
5304                .find_precondition_kind(__kind)
5305                .or(__surface.find_postcondition_kind(__kind))
5306                .map(|c| c.kind);
5307            ::core::assert_eq!(
5308                __surface.find_condition_kind(__kind).map(|c| c.kind),
5309                __find_via_arms,
5310                "surface union find arm drifted from precondition.or(postcondition) for {:?}",
5311                __kind,
5312            );
5313            // iter: union == chain(pre, post) (stream concat, kind projection)
5314            let __iter_via_arms: ::std::vec::Vec<_> = __surface
5315                .iter_precondition_kind(__kind)
5316                .chain(__surface.iter_postcondition_kind(__kind))
5317                .map(|c| c.kind)
5318                .collect();
5319            let __iter_via_union: ::std::vec::Vec<_> = __surface
5320                .iter_condition_kind(__kind)
5321                .map(|c| c.kind)
5322                .collect();
5323            ::core::assert_eq!(
5324                __iter_via_union,
5325                __iter_via_arms,
5326                "surface union iter arm drifted from chain(pre, post) for {:?}",
5327                __kind,
5328            );
5329            // count: union == pre + post (cardinality SUM)
5330            ::core::assert_eq!(
5331                __surface.count_condition_kind(__kind),
5332                __surface.count_precondition_kind(__kind)
5333                    + __surface.count_postcondition_kind(__kind),
5334                "surface union count arm drifted from SUM of half-slice arms for {:?}",
5335                __kind,
5336            );
5337            // distinct: union.contains(k) == pre.contains(k) || post.contains(k)
5338            // (set-union membership per kind on the closed-set-inversion axis)
5339            ::core::assert_eq!(
5340                __distinct_union_kinds.contains(&__kind),
5341                __distinct_pre_kinds.contains(&__kind)
5342                    || __distinct_post_kinds.contains(&__kind),
5343                "surface distinct union arm drifted from OR-membership of half-slice distinct arms for {:?}",
5344                __kind,
5345            );
5346            // missing: union.contains(k) == pre.contains(k) && post.contains(k)
5347            // (set-INTERSECTION membership per kind — a kind is missing
5348            // from the union iff it is missing from BOTH half-slices,
5349            // dual of the distinct-set OR composition).
5350            ::core::assert_eq!(
5351                __missing_union_kinds.contains(&__kind),
5352                __missing_pre_kinds.contains(&__kind)
5353                    && __missing_post_kinds.contains(&__kind),
5354                "surface missing union arm drifted from AND-membership of half-slice missing arms for {:?}",
5355                __kind,
5356            );
5357            // missing ↔ has: union.contains(k) == !has_condition_kind(k)
5358            // — binds the missing-set primitive to the point-probe
5359            // primitive on the surface under a negated predicate.
5360            ::core::assert_eq!(
5361                __missing_union_kinds.contains(&__kind),
5362                !__surface.has_condition_kind(__kind),
5363                "surface missing union arm drifted from !has_condition_kind for {:?}",
5364                __kind,
5365            );
5366            // lacks: union == pre && post (bool AND — dual of `has`'s
5367            // `pre || post` OR under `!(a || b) == !a && !b`). A kind is
5368            // lacked from the union iff BOTH half-slices lack it — the
5369            // per-kind Boolean-projection peer of the missing-set
5370            // intersection membership arm above (which composes the SAME
5371            // AND over the closed-set-complement Vecs); this arm
5372            // composes it over the per-slice per-kind negation
5373            // primitives without materializing either side's missing-
5374            // set Vec. A regression that (a) drifted the union operator
5375            // to `||` (widening the intersection to a union),
5376            // (b) dropped the negation on one side, or (c) inverted the
5377            // wrong slice on the point probe surfaces HERE at the
5378            // substrate boundary, not as silent drift at every
5379            // downstream `lacks-<kind>` require-tag classifier callsite.
5380            let __lacks_via_arms =
5381                __surface.lacks_precondition_kind(__kind) && __surface.lacks_postcondition_kind(__kind);
5382            ::core::assert_eq!(
5383                __surface.lacks_condition_kind(__kind),
5384                __lacks_via_arms,
5385                "surface union lacks arm drifted from AND of half-slice lacks arms for {:?}",
5386                __kind,
5387            );
5388            // lacks ↔ has: union == !has_condition_kind(k) — the
5389            // definitional complement law binds the per-kind Boolean-
5390            // complement primitive on the surface to the point-probe
5391            // primitive under negation. Peer of the `missing ↔ has`
5392            // arm above one refinement lower: the closed-set-complement
5393            // Vec's per-kind membership equals the per-kind Boolean
5394            // complement, both equal `!has_condition_kind(k)`. A
5395            // regression that overrode `lacks_condition_kind` to drop
5396            // the negation, drift the underlying union primitive, or
5397            // return `has_condition_kind` surfaces HERE.
5398            ::core::assert_eq!(
5399                __surface.lacks_condition_kind(__kind),
5400                !__surface.has_condition_kind(__kind),
5401                "surface union lacks arm drifted from !has_condition_kind for {:?}",
5402                __kind,
5403            );
5404        }
5405        // distinct: union == canonical(pre ∪ post) — closed-set-inversion
5406        // set-union projected in ConditionKind::ALL order. A regression that
5407        // (a) reversed the walk order (post-then-pre), (b) preserved
5408        // slice-encounter order rather than ConditionKind::ALL order, or
5409        // (c) narrowed the union to an intersection surfaces HERE at the
5410        // substrate boundary (the per-kind membership arm above catches
5411        // membership drift; this arm catches ordering + dedup drift the
5412        // membership arm cannot detect on its own).
5413        let __expected_distinct_union: ::std::vec::Vec<_> =
5414            $crate::boundary::ConditionKind::ALL
5415                .into_iter()
5416                .filter(|__k| {
5417                    __distinct_pre_kinds.contains(__k)
5418                        || __distinct_post_kinds.contains(__k)
5419                })
5420                .collect();
5421        ::core::assert_eq!(
5422            __distinct_union_kinds, __expected_distinct_union,
5423            "surface distinct union arm drifted from canonical ConditionKind::ALL-ordered set-union of half-slice distinct arms",
5424        );
5425        // missing: union == canonical(pre ∩ post) — closed-set-inversion
5426        // set-INTERSECTION projected in ConditionKind::ALL order. Dual
5427        // of the distinct union canonical-order arm above. A regression
5428        // that (a) reversed the walk order, (b) widened the intersection
5429        // to a union (returning kinds missing from either side rather
5430        // than both), or (c) preserved slice-encounter order rather
5431        // than ConditionKind::ALL order surfaces HERE at the substrate
5432        // boundary.
5433        let __expected_missing_union: ::std::vec::Vec<_> =
5434            $crate::boundary::ConditionKind::ALL
5435                .into_iter()
5436                .filter(|__k| {
5437                    __missing_pre_kinds.contains(__k)
5438                        && __missing_post_kinds.contains(__k)
5439                })
5440                .collect();
5441        ::core::assert_eq!(
5442            __missing_union_kinds, __expected_missing_union,
5443            "surface missing union arm drifted from canonical ConditionKind::ALL-ordered set-INTERSECTION of half-slice missing arms",
5444        );
5445    }};
5446}
5447
5448/// A single boundary predicate.
5449#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
5450#[serde(rename_all = "camelCase")]
5451pub struct Condition {
5452    pub kind: ConditionKind,
5453    /// Kind-specific payload (free-form JSON).
5454    #[serde(default)]
5455    #[schemars(schema_with = "crate::schema_helpers::preserve_unknown_object")]
5456    pub params: serde_json::Value,
5457}
5458
5459#[derive(
5460    Clone,
5461    Copy,
5462    Debug,
5463    PartialEq,
5464    Eq,
5465    Hash,
5466    Serialize,
5467    Deserialize,
5468    JsonSchema,
5469    tatara_closed_set::DeriveClosedSet,
5470)]
5471#[serde(rename_all = "PascalCase")]
5472#[closed_set(via = "as_str", display, generate_unknown)]
5473pub enum ConditionKind {
5474    /// Another Process must be in a given phase.
5475    /// `params`: `{ "processRef": "...", "namespace": "...", "phase": "Attested" }`
5476    ProcessPhase,
5477    /// FluxCD `Kustomization.status.conditions[type=Ready]` must be `True`.
5478    /// `params`: `{ "name": "...", "namespace": "flux-system" }`
5479    KustomizationHealthy,
5480    /// FluxCD `HelmRelease.status.conditions[type=Ready]` must be `True`.
5481    /// `params`: `{ "name": "...", "namespace": "..." }`
5482    HelmReleaseReleased,
5483    /// Prometheus query — truthy scalar required.
5484    /// `params`: `{ "query": "..." }`
5485    PromQL,
5486    /// CEL expression over a scoped object set.
5487    /// `params`: `{ "expression": "..." }`
5488    Cel,
5489    /// Nix evaluation equality check.
5490    /// `params`: `{ "flakeRef": "...", "attribute": "...", "expect": "..." }`
5491    NixEval,
5492    /// A Kubernetes Job must complete successfully and its emitted BLAKE3
5493    /// receipt must verify.
5494    /// `params`: `{ "name": "...", "namespace": "...", "expectReceipt": true }`
5495    JobAttested,
5496    /// Closed-loop authentication probe — the canonical postcondition for
5497    /// any system that can produce credentials for its own client under
5498    /// test. The probe Job (rendered by the VERIFY handler) fetches a
5499    /// fresh secret from `issuer` (a Service inside the same namespace),
5500    /// presents it to `consumer` (another Service in the same namespace),
5501    /// and verifies that `consumer` authenticated successfully against
5502    /// `jwk_source` (the issuer's published JWK endpoint).
5503    ///
5504    /// The Job emits a three-pillar BLAKE3 receipt that the reconciler
5505    /// chains into `status.attestation`. This turns "the gateway↔SaaS
5506    /// loop holds" from an assertion into a theorem provable for every
5507    /// ephemeral run.
5508    ///
5509    /// `params`:
5510    /// ```json
5511    /// {
5512    ///   "issuer":   { "service": "demo-app-issuer",
5513    ///                 "port": 8080,
5514    ///                 "secretPath": "/v2/get-secret-value" },
5515    ///   "consumer": { "service": "demo-app-gateway",
5516    ///                 "port": 8000,
5517    ///                 "authPath": "/api/v3/auth" },
5518    ///   "jwkSource":{ "service": "demo-app-issuer",
5519    ///                 "port": 8080,
5520    ///                 "path": "/.well-known/jwks.json" },
5521    ///   "probeImage": "ghcr.io/pleme-io/closed-loop-probe:0.1.0",
5522    ///   "timeoutSeconds": 120
5523    /// }
5524    /// ```
5525    ClosedLoopAuth,
5526}
5527
5528impl ConditionKind {
5529    /// The closed set of boundary-condition kinds the reconciler honors.
5530    /// Single source of truth that drives the `as_str` / Display /
5531    /// `FromStr` triad on this enum and the `stub_message` lift of the
5532    /// "not yet implemented" arms the reconciler used to hand-roll three
5533    /// times. Adding a 9th variant lands at one `ALL` entry + one `as_str`
5534    /// arm + one `stub_message` arm — exhaustively checked by the
5535    /// compiler (the array literal forces arity).
5536    ///
5537    /// Sibling closed-set lifts: [`crate::phase::ProcessPhase::ALL`],
5538    /// [`crate::signal::ProcessSignal::ALL`], [`crate::intent::IntentKind::ALL`],
5539    /// [`crate::lifetime::LifetimeKind::ALL`].
5540    pub const ALL: [Self; 8] = [
5541        Self::ProcessPhase,
5542        Self::KustomizationHealthy,
5543        Self::HelmReleaseReleased,
5544        Self::PromQL,
5545        Self::Cel,
5546        Self::NixEval,
5547        Self::JobAttested,
5548        Self::ClosedLoopAuth,
5549    ];
5550
5551    /// Canonical PascalCase wire-format projection — matches the serde
5552    /// `rename_all = "PascalCase"` output verbatim. Used by Display
5553    /// (single source of truth), by `FromStr` to identify the variant
5554    /// from its annotation / status-field representation, and by
5555    /// operator-facing diagnostics that need the kind name without
5556    /// re-serializing the enum through serde_json. Pinned by
5557    /// `condition_kind_as_str_matches_serde`.
5558    pub const fn as_str(self) -> &'static str {
5559        match self {
5560            Self::ProcessPhase => "ProcessPhase",
5561            Self::KustomizationHealthy => "KustomizationHealthy",
5562            Self::HelmReleaseReleased => "HelmReleaseReleased",
5563            Self::PromQL => "PromQL",
5564            Self::Cel => "Cel",
5565            Self::NixEval => "NixEval",
5566            Self::JobAttested => "JobAttested",
5567            Self::ClosedLoopAuth => "ClosedLoopAuth",
5568        }
5569    }
5570
5571    /// The operator-facing "evaluator not yet implemented" message for
5572    /// stub kinds — `Some` iff this kind has no live evaluator wired in
5573    /// `tatara-reconciler::boundary`. ONE site owns the per-kind stub
5574    /// string; the reconciler's dispatch reaches for this projection
5575    /// instead of hand-rolling three parallel `Unknown(...)` strings.
5576    ///
5577    /// A future variant added as a live evaluator returns `None`; a
5578    /// future variant added as a stub returns `Some("<kind> evaluator
5579    /// not yet implemented")` — both reachable through one match
5580    /// instead of three identical-shape arms drifting in parallel.
5581    pub const fn stub_message(self) -> Option<&'static str> {
5582        match self {
5583            Self::PromQL => Some("PromQL evaluator not yet implemented"),
5584            Self::Cel => Some("CEL evaluator not yet implemented"),
5585            Self::NixEval => Some("NixEval evaluator not yet implemented"),
5586            Self::ProcessPhase
5587            | Self::KustomizationHealthy
5588            | Self::HelmReleaseReleased
5589            | Self::JobAttested
5590            | Self::ClosedLoopAuth => None,
5591        }
5592    }
5593
5594    /// True iff this kind has no live evaluator (its [`Self::stub_message`]
5595    /// is `Some`). Pairs with the reconciler's `evaluate` dispatch — a
5596    /// stub kind unconditionally yields `Satisfaction::Unknown`.
5597    pub const fn is_stub(self) -> bool {
5598        self.stub_message().is_some()
5599    }
5600
5601    /// The [`FluxResource`] variant this condition kind fetches from
5602    /// the K8s API server, or `None` for non-Flux-fetching kinds — the
5603    /// typed projection owning the (ConditionKind → FluxResource)
5604    /// association every reconciler `evaluate` dispatch arm and every
5605    /// future coherence check binds through.
5606    ///
5607    /// Pre-lift the association was open-coded at TWO adjacent
5608    /// `evaluate` arms in `tatara-reconciler::boundary::evaluate` past
5609    /// the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold — each arm
5610    /// hand-authored a `(FluxResource::X.api_version(),
5611    /// FluxResource::X.kind())` pair as the two `&str` slots the
5612    /// pre-lift `evaluate_flux_ready(api_version: &str, kind: &str)`
5613    /// signature required. Post-lift the mapping lives at ONE typed
5614    /// projection here, the callee accepts a typed
5615    /// [`FluxResource`] slot (invalid `(apiVersion, kind)` pairings
5616    /// like Kustomization's apiVersion paired with HelmRelease's kind
5617    /// become unrepresentable), and the two `evaluate` arms collapse
5618    /// onto ONE `KustomizationHealthy | HelmReleaseReleased` OR-arm
5619    /// that reads the FluxResource variant from `.flux_resource()`.
5620    ///
5621    /// A future ConditionKind that fetches a fourth Flux resource
5622    /// variant (a hypothetical `BucketSynced` kind against a Flux
5623    /// `Bucket` source) lands as ONE new arm here + ONE new variant
5624    /// on [`FluxResource`] + ONE OR-pattern extension at the
5625    /// reconciler dispatch — no hand-authored `(apiVersion, kind)`
5626    /// pair at the callsite, no widening of the callee's signature.
5627    ///
5628    /// The three current non-Flux-fetching arms return `None`:
5629    /// - `ProcessPhase` fetches a tatara `Process` (through its own
5630    ///   [`crate::api_version`] + [`crate::PROCESS_KIND`] pair, not
5631    ///   a Flux `(apiVersion, kind)`).
5632    /// - `JobAttested` / `ClosedLoopAuth` fetch a `batch/v1::Job` +
5633    ///   an optional receipt `v1::ConfigMap`, both K8s built-ins
5634    ///   (not Flux resources).
5635    /// - `PromQL` / `Cel` / `NixEval` are stub evaluators
5636    ///   ([`Self::is_stub`]) — no cluster fetch at all.
5637    ///
5638    /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
5639    /// preserves proofs — the (ConditionKind → FluxResource)
5640    /// association lives at ONE typed algebra projection here, not
5641    /// at every reconciler dispatch arm).
5642    pub const fn flux_resource(self) -> Option<FluxResource> {
5643        match self {
5644            Self::KustomizationHealthy => Some(FluxResource::Kustomization),
5645            Self::HelmReleaseReleased => Some(FluxResource::HelmRelease),
5646            Self::ProcessPhase
5647            | Self::PromQL
5648            | Self::Cel
5649            | Self::NixEval
5650            | Self::JobAttested
5651            | Self::ClosedLoopAuth => None,
5652        }
5653    }
5654}
5655
5656// `impl fmt::Display for ConditionKind` + `impl FromStr for
5657// ConditionKind` + `impl tatara_lisp::ClosedSet for ConditionKind` +
5658// `pub struct UnknownConditionKind(pub String)` are generated by
5659// `#[derive(tatara_closed_set::DeriveClosedSet)]` + `#[closed_set(via =
5660// "as_str", display, generate_unknown)]` on the enum declaration above.
5661// The auto-derived label `"condition kind"` matches the prior hand-
5662// rolled `#[error("unknown condition kind: {0}")]` verbatim. The
5663// inherent `as_str` projection stays load-bearing — the PascalCase
5664// wire-format that matches the serde rename + the CRD `enum:` listing
5665// verbatim (notably preserving `PromQL`'s consecutive caps that heck
5666// would have lowercased) — while the trait method `label` gives
5667// generic consumers a STABLE name across the 36+ workspace-wide
5668// closed-set implementors.
5669
5670#[cfg(test)]
5671mod tests {
5672    use super::*;
5673    use serde_json::json;
5674
5675    #[test]
5676    fn serde_process_phase_condition() {
5677        let c = Condition {
5678            kind: ConditionKind::ProcessPhase,
5679            params: json!({ "processRef": "secret-injection", "phase": "Attested" }),
5680        };
5681        let yaml = serde_yaml::to_string(&c).unwrap();
5682        assert!(yaml.contains("kind: ProcessPhase"));
5683        assert!(yaml.contains("processRef: secret-injection"));
5684    }
5685
5686    #[test]
5687    fn serde_closed_loop_auth_condition() {
5688        let c = Condition {
5689            kind: ConditionKind::ClosedLoopAuth,
5690            params: json!({
5691                "issuer":   { "service": "demo-app-issuer", "port": 8080 },
5692                "consumer": { "service": "demo-app-gateway", "port": 8000 },
5693                "probeImage": "ghcr.io/pleme-io/closed-loop-probe:0.1.0",
5694            }),
5695        };
5696        let yaml = serde_yaml::to_string(&c).unwrap();
5697        assert!(yaml.contains("kind: ClosedLoopAuth"));
5698        assert!(yaml.contains("probeImage: ghcr.io/pleme-io/closed-loop-probe:0.1.0"));
5699        let back: Condition = serde_yaml::from_str(&yaml).unwrap();
5700        assert_eq!(back.kind, ConditionKind::ClosedLoopAuth);
5701    }
5702
5703    #[test]
5704    fn serde_job_attested_condition() {
5705        let c = Condition {
5706            kind: ConditionKind::JobAttested,
5707            params: json!({ "name": "seed-job", "namespace": "demo-test" }),
5708        };
5709        let yaml = serde_yaml::to_string(&c).unwrap();
5710        assert!(yaml.contains("kind: JobAttested"));
5711    }
5712
5713    // ── closed-set algebra contracts (ALL × as_str × FromStr × stub_message) ─
5714
5715    /// Structural well-formedness of [`ConditionKind`] as a
5716    /// [`tatara_lisp::ClosedSet`] implementor — the workspace-wide
5717    /// testkit lift that pins all three structural invariants (`ALL`
5718    /// is non-empty, every variant round-trips through `label ↔
5719    /// parse_label`, labels are pairwise distinct, `""` is outside the
5720    /// closed set) at ONE call site. Replaces the hand-derived
5721    /// `condition_kind_all_is_unique_and_complete` +
5722    /// `condition_kind_roundtrip_via_as_str` + the empty-input arm of
5723    /// `unknown_condition_kind_errors`. `FromStr` delegates to
5724    /// `<Self as tatara_closed_set::ClosedSet>::parse_label`, so this helper
5725    /// exercises the same code path the reconciler hits when parsing a
5726    /// CRD `enum:`-validated value back to the typed kind.
5727    #[test]
5728    fn condition_kind_is_well_formed_closed_set() {
5729        tatara_closed_set::assert_closed_set_well_formed::<ConditionKind>();
5730    }
5731
5732    /// CANONICAL-KEY CONTRACT: `as_str` matches serde's PascalCase
5733    /// output verbatim for every variant. A future variant rename
5734    /// (or an `as_str` arm typo) lands here at one site. The probe
5735    /// confirmed `PromQL` survives `rename_all = "PascalCase"` as
5736    /// `"PromQL"` (heck preserves consecutive caps in the leading
5737    /// word), so this contract is the operator-facing pin.
5738    #[test]
5739    fn condition_kind_as_str_matches_serde() {
5740        crate::tagged_union::assert_label_matches_serde_serialization::<ConditionKind>();
5741    }
5742
5743    /// The Display impl IS `as_str` — pinning this lets future
5744    /// callers reach for either projection without drift. If a
5745    /// reviewer accidentally re-introduces an inline match in
5746    /// Display, this fails the moment a variant rename touches one
5747    /// site but not the other.
5748    #[test]
5749    fn condition_kind_display_matches_as_str() {
5750        crate::tagged_union::assert_display_matches_label::<ConditionKind>();
5751    }
5752
5753    /// `FromStr` rejects strings that aren't in the canonical
5754    /// projection — lowercased / typo / unrelated — and the error
5755    /// echoes the input verbatim so the operator-facing diagnostic
5756    /// carries the offending value, not a normalized form. The
5757    /// empty-input arm is pinned by
5758    /// [`condition_kind_is_well_formed_closed_set`] via the
5759    /// `tatara_lisp::ClosedSet` testkit; the cases here pin the
5760    /// verbatim-echo contract on the [`UnknownConditionKind`]
5761    /// newtype, which the trait's `make_unknown` can't see.
5762    #[test]
5763    fn unknown_condition_kind_errors() {
5764        use std::str::FromStr;
5765        for bad in ["processPhase", "PROMQL", "Promql", "Bogus"] {
5766            let err = ConditionKind::from_str(bad).unwrap_err();
5767            assert_eq!(err.0, bad, "error payload should echo input verbatim");
5768        }
5769    }
5770
5771    /// STUB CONTRACT: the three placeholder evaluators
5772    /// (PromQL / Cel / NixEval) are exactly the set whose
5773    /// `stub_message` is `Some`. The five live evaluators return
5774    /// `None`. A future variant promoted from stub → live must drop
5775    /// its `stub_message` arm; a new stub must add one. Both
5776    /// transitions land at this test by sweeping ALL.
5777    #[test]
5778    fn condition_kind_stub_set_matches_stubs() {
5779        use ConditionKind::*;
5780        for kind in ConditionKind::ALL {
5781            let expected_is_stub = matches!(kind, PromQL | Cel | NixEval);
5782            assert_eq!(
5783                kind.is_stub(),
5784                expected_is_stub,
5785                "is_stub disagreed for {kind:?}",
5786            );
5787            assert_eq!(
5788                kind.stub_message().is_some(),
5789                expected_is_stub,
5790                "stub_message disagreed for {kind:?}",
5791            );
5792        }
5793    }
5794
5795    /// Pin the exact stub strings so a rename of the operator-facing
5796    /// "not yet implemented" message lands at one site (here) instead
5797    /// of three parallel inline strings in the reconciler.
5798    #[test]
5799    fn condition_kind_stub_messages_are_pinned() {
5800        assert_eq!(
5801            ConditionKind::PromQL.stub_message(),
5802            Some("PromQL evaluator not yet implemented"),
5803        );
5804        assert_eq!(
5805            ConditionKind::Cel.stub_message(),
5806            Some("CEL evaluator not yet implemented"),
5807        );
5808        assert_eq!(
5809            ConditionKind::NixEval.stub_message(),
5810            Some("NixEval evaluator not yet implemented"),
5811        );
5812    }
5813
5814    // ── (ConditionKind → FluxResource) typed projection contracts ────
5815
5816    /// The two Flux-fetching kinds project to their canonical
5817    /// [`FluxResource`] variants. A future ConditionKind rename or
5818    /// FluxResource variant rename that skewed the projection at ONE
5819    /// arm surfaces here.
5820    #[test]
5821    fn kustomization_healthy_projects_to_flux_resource_kustomization() {
5822        assert_eq!(
5823            ConditionKind::KustomizationHealthy.flux_resource(),
5824            Some(FluxResource::Kustomization),
5825        );
5826    }
5827
5828    #[test]
5829    fn helm_release_released_projects_to_flux_resource_helm_release() {
5830        assert_eq!(
5831            ConditionKind::HelmReleaseReleased.flux_resource(),
5832            Some(FluxResource::HelmRelease),
5833        );
5834    }
5835
5836    /// The six non-Flux-fetching kinds project to `None`. Sweeps
5837    /// `ConditionKind::ALL` filtering by `flux_resource().is_none()`
5838    /// so a new variant added without a `flux_resource` arm surfaces
5839    /// at rustc's non-exhaustive-match gate BEFORE this test even
5840    /// runs; a new variant added with a hand-coded `Some(...)` arm
5841    /// that shouldn't fetch Flux surfaces here.
5842    #[test]
5843    fn non_flux_fetching_kinds_project_to_none() {
5844        use ConditionKind::*;
5845        let non_flux: Vec<_> = ConditionKind::ALL
5846            .iter()
5847            .copied()
5848            .filter(|k| k.flux_resource().is_none())
5849            .collect();
5850        assert_eq!(
5851            non_flux,
5852            vec![
5853                ProcessPhase,
5854                PromQL,
5855                Cel,
5856                NixEval,
5857                JobAttested,
5858                ClosedLoopAuth
5859            ],
5860        );
5861    }
5862
5863    /// Every variant of [`ConditionKind`] whose `flux_resource()` is
5864    /// `Some` uniquely names its FluxResource variant (no two
5865    /// ConditionKind arms may fetch the SAME FluxResource — that
5866    /// would signal a redundant closed-set entry). Peers the
5867    /// `every_variants_api_version_and_kind_are_distinct_across_the_closed_set`
5868    /// pin on the sibling [`FluxResource`] closed set.
5869    #[test]
5870    fn flux_resource_projection_is_injective_on_the_some_arms() {
5871        let mut seen = std::collections::HashSet::new();
5872        for k in ConditionKind::ALL {
5873            if let Some(fr) = k.flux_resource() {
5874                assert!(
5875                    seen.insert(fr),
5876                    "duplicate FluxResource projection at {k:?}: {fr:?}",
5877                );
5878            }
5879        }
5880    }
5881
5882    /// `flux_resource` is `const fn` — the projection is reachable
5883    /// at compile time. A regression that dropped the `const`
5884    /// qualifier would fail-loudly here rather than as a wrong-slot
5885    /// runtime dispatch at every consumer callsite.
5886    #[test]
5887    fn flux_resource_projection_is_const_fn_reachable() {
5888        const K: Option<FluxResource> = ConditionKind::KustomizationHealthy.flux_resource();
5889        const H: Option<FluxResource> = ConditionKind::HelmReleaseReleased.flux_resource();
5890        const P: Option<FluxResource> = ConditionKind::ProcessPhase.flux_resource();
5891        assert_eq!(K, Some(FluxResource::Kustomization));
5892        assert_eq!(H, Some(FluxResource::HelmRelease));
5893        assert_eq!(P, None);
5894    }
5895
5896    // ── Boundary::has_condition_kind substrate pins ──────────────────
5897    //
5898    // Fail-before-pass-after granularity: `Boundary::has_condition_kind`
5899    // did not exist before this commit — the (preconditions +
5900    // postconditions .iter().any(|c| c.kind == K)) union-probe shape
5901    // lived hand-authored inline at the ephemeral require-tag surface
5902    // (`spec.postconditions.iter().any(|c| matches!(c.kind, K))`, sans
5903    // the pre-condition side). The lift places the closed-set-driven
5904    // presence probe on ONE substrate site so the point-domain
5905    // `condition-<kind>` prefix family in `tatara-check` composes it
5906    // through `strip_and_classify_prefixed_kind` byte-for-byte
5907    // symmetrical with `intent-<kind>` (via `Intent::has`) +
5908    // `lifetime-<kind>` (via `Lifetime::has`) — third instance in the
5909    // workspace closed-set-driven presence-probe algebra.
5910
5911    fn condition_with(kind: ConditionKind) -> Condition {
5912        Condition {
5913            kind,
5914            params: json!({}),
5915        }
5916    }
5917
5918    /// EMPTY-BOUNDARY pin — a default [`Boundary`] (no preconditions,
5919    /// no postconditions) returns `false` for EVERY [`ConditionKind`].
5920    /// Sweep `ConditionKind::ALL` so a new variant added without a
5921    /// matching arm in the presence probe surfaces at rustc's
5922    /// exhaustiveness gate on the ALL literal (arity forced by
5923    /// `[Self; 8]`) rather than as a silent false-positive at every
5924    /// downstream `condition-<kind>` require-tag callsite.
5925    #[test]
5926    fn has_condition_kind_returns_false_on_empty_boundary_for_every_kind() {
5927        let b = Boundary::default();
5928        for kind in ConditionKind::ALL {
5929            assert!(
5930                !b.has_condition_kind(kind),
5931                "default boundary must return false for {kind:?}",
5932            );
5933        }
5934    }
5935
5936    /// POSTCONDITION-only pin — a boundary that carries the kind on
5937    /// ONLY postconditions returns `true` for that kind, `false` for
5938    /// every other variant. Sweep the ALL × ALL cross so a regression
5939    /// that (a) hard-coded the arm to a single kind (silently
5940    /// returning true for every populated boundary regardless of
5941    /// which kind was queried), (b) skipped the postcondition side of
5942    /// the union (silently returning false when the kind lived
5943    /// post-only), or (c) matched on Condition::params instead of
5944    /// Condition::kind fails HERE at the substrate primitive.
5945    #[test]
5946    fn has_condition_kind_reads_postconditions_per_kind() {
5947        for populated in ConditionKind::ALL {
5948            let mut b = Boundary::default();
5949            b.postconditions.push(condition_with(populated));
5950            for query in ConditionKind::ALL {
5951                let expected = query == populated;
5952                assert_eq!(
5953                    b.has_condition_kind(query),
5954                    expected,
5955                    "postcondition populated={populated:?}: query {query:?} drifted",
5956                );
5957            }
5958        }
5959    }
5960
5961    /// PRECONDITION-only pin — mirrors the postcondition sweep on the
5962    /// other half of the union. Locks the union semantics on both
5963    /// halves separately so a regression that dropped the
5964    /// pre-condition side of the OR fails here even though the
5965    /// postcondition-side pin above passes.
5966    #[test]
5967    fn has_condition_kind_reads_preconditions_per_kind() {
5968        for populated in ConditionKind::ALL {
5969            let mut b = Boundary::default();
5970            b.preconditions.push(condition_with(populated));
5971            for query in ConditionKind::ALL {
5972                let expected = query == populated;
5973                assert_eq!(
5974                    b.has_condition_kind(query),
5975                    expected,
5976                    "precondition populated={populated:?}: query {query:?} drifted",
5977                );
5978            }
5979        }
5980    }
5981
5982    /// UNION pin — a kind that appears on preconditions returns
5983    /// `true` even when postconditions carries a DIFFERENT kind, and
5984    /// vice versa. Pins the OR-composition of the two halves so a
5985    /// regression that collapsed the union to an intersection (AND)
5986    /// silently reclassifies pre-only or post-only kinds as absent.
5987    #[test]
5988    fn has_condition_kind_unions_pre_and_post_condition_arms() {
5989        let mut b = Boundary::default();
5990        b.preconditions
5991            .push(condition_with(ConditionKind::KustomizationHealthy));
5992        b.postconditions
5993            .push(condition_with(ConditionKind::ClosedLoopAuth));
5994        assert!(
5995            b.has_condition_kind(ConditionKind::KustomizationHealthy),
5996            "pre-only kind must resolve through the union",
5997        );
5998        assert!(
5999            b.has_condition_kind(ConditionKind::ClosedLoopAuth),
6000            "post-only kind must resolve through the union",
6001        );
6002        assert!(
6003            !b.has_condition_kind(ConditionKind::PromQL),
6004            "an absent kind must return false even with populated halves",
6005        );
6006    }
6007
6008    // ── ConditionSliceExt::has_kind substrate pins ────────────────────
6009    //
6010    // Fail-before-pass-after granularity: `ConditionSliceExt::has_kind`
6011    // did not exist before this commit — the `(&[Condition],
6012    // ConditionKind) -> bool` walk shape lived hand-authored inline at
6013    // THREE production sites (twice inside `Boundary::has_condition_kind`
6014    // on `preconditions` ∪ `postconditions`, once at the ephemeral
6015    // require-tag classifier's `closed-loop-auth` arm on
6016    // `spec.postconditions` in `tatara-reconciler::bin::tatara-check`,
6017    // with `matches!` sugar instead of `==` but the same predicate).
6018    // The lift places the per-slice presence probe on ONE substrate site
6019    // so the two-half union at `Boundary` and the one-half probe at the
6020    // ephemeral surface compose against the SAME primitive rather than
6021    // restating the `.iter().any(|c| c.kind == K)` closure body.
6022
6023    /// EMPTY-SLICE pin — an empty `&[Condition]` returns `false` for
6024    /// EVERY [`ConditionKind`]. Sweep `ConditionKind::ALL` so a new
6025    /// variant added without a matching arm in the primitive surfaces
6026    /// at rustc's exhaustiveness gate on the ALL literal (arity forced
6027    /// by `[Self; 8]`) rather than as a silent false-positive at every
6028    /// downstream callsite composing this primitive.
6029    #[test]
6030    fn condition_slice_has_kind_returns_false_on_empty_slice_for_every_kind() {
6031        let empty: &[Condition] = &[];
6032        for kind in ConditionKind::ALL {
6033            assert!(
6034                !empty.has_kind(kind),
6035                "empty slice must return false for {kind:?}",
6036            );
6037        }
6038    }
6039
6040    /// PER-VARIANT pin — a single-element slice returns `true` for
6041    /// exactly the kind it carries, `false` for every other variant.
6042    /// Sweep the ALL × ALL cross so a regression that (a) hard-coded
6043    /// the arm to a single kind (silently returning true for every
6044    /// populated slice regardless of query kind), or (b) matched on
6045    /// [`Condition::params`] instead of [`Condition::kind`] fails HERE
6046    /// at the substrate primitive.
6047    #[test]
6048    fn condition_slice_has_kind_reads_kind_field_per_variant() {
6049        for populated in ConditionKind::ALL {
6050            let slice = [condition_with(populated)];
6051            for query in ConditionKind::ALL {
6052                let expected = query == populated;
6053                assert_eq!(
6054                    slice.has_kind(query),
6055                    expected,
6056                    "populated={populated:?}: query {query:?} drifted",
6057                );
6058            }
6059        }
6060    }
6061
6062    /// MULTI-ENTRY pin — a slice with multiple entries returns `true`
6063    /// for every kind that appears at any position (existential
6064    /// quantifier over the slice), `false` for kinds that appear at
6065    /// no position. Locks the `any` semantics so a regression that
6066    /// collapsed to a `first`-only probe (`slice.first().map_or(false,
6067    /// |c| c.kind == kind)`) fails here even though the single-element
6068    /// per-variant pin above passes.
6069    #[test]
6070    fn condition_slice_has_kind_scans_beyond_the_first_position() {
6071        let slice = [
6072            condition_with(ConditionKind::KustomizationHealthy),
6073            condition_with(ConditionKind::ClosedLoopAuth),
6074            condition_with(ConditionKind::JobAttested),
6075        ];
6076        for present in [
6077            ConditionKind::KustomizationHealthy,
6078            ConditionKind::ClosedLoopAuth,
6079            ConditionKind::JobAttested,
6080        ] {
6081            assert!(
6082                slice.has_kind(present),
6083                "kind at any position must resolve true: {present:?}",
6084            );
6085        }
6086        for absent in [
6087            ConditionKind::ProcessPhase,
6088            ConditionKind::HelmReleaseReleased,
6089            ConditionKind::PromQL,
6090            ConditionKind::Cel,
6091            ConditionKind::NixEval,
6092        ] {
6093            assert!(
6094                !slice.has_kind(absent),
6095                "kind absent from the slice must resolve false: {absent:?}",
6096            );
6097        }
6098    }
6099
6100    /// COMPOSITION pin — [`Boundary::has_condition_kind`] equals the OR
6101    /// of the two half-slice probes at EVERY (populated arrangement,
6102    /// query) pair on `ConditionKind::ALL`. Locks the (union-probe =
6103    /// pre.has_kind ∨ post.has_kind) composition contract at ONE test
6104    /// so a regression that (a) dropped the `||` (silently narrowing
6105    /// the union to an intersection, or to one side only), or
6106    /// (b) hand-authored the union with a divergent walk shape (e.g.
6107    /// summing counts, comparing lengths) surfaces HERE at the
6108    /// composition boundary rather than as silent classifier drift at
6109    /// every downstream `condition-<kind>` require-tag callsite.
6110    #[test]
6111    fn boundary_has_condition_kind_equals_or_of_half_slice_probes() {
6112        for pre_kind in ConditionKind::ALL {
6113            for post_kind in ConditionKind::ALL {
6114                let mut b = Boundary::default();
6115                b.preconditions.push(condition_with(pre_kind));
6116                b.postconditions.push(condition_with(post_kind));
6117                for query in ConditionKind::ALL {
6118                    let expected =
6119                        b.preconditions.has_kind(query) || b.postconditions.has_kind(query);
6120                    assert_eq!(
6121                        b.has_condition_kind(query),
6122                        expected,
6123                        "union drifted: pre={pre_kind:?} post={post_kind:?} query={query:?}",
6124                    );
6125                }
6126            }
6127        }
6128    }
6129
6130    // ── Boundary::has_(pre|post)condition_kind substrate pins ────────
6131    //
6132    // Fail-before-pass-after granularity: the two half-slice arms did
6133    // not exist before this commit — the point-domain `precondition-
6134    // <kind>` and `postcondition-<kind>` require-tag classifiers in
6135    // `tatara-reconciler::bin::tatara-check` reached the two condition
6136    // slices through direct field access
6137    // (`spec.boundary.preconditions.has_kind(k)`), bypassing the named
6138    // [`Boundary`] primitive surface that the union-probe
6139    // [`Boundary::has_condition_kind`] already routed through. The
6140    // lift closes the (precondition, postcondition, union) triad on
6141    // ONE typed algebra surface so a future normalization at the
6142    // presence-probe shape lands at ONE site for all three arms.
6143
6144    /// EMPTY-BOUNDARY pin (precondition arm) — a default [`Boundary`]
6145    /// returns `false` for EVERY [`ConditionKind`] on the precondition
6146    /// side. Sweep `ConditionKind::ALL` so a new variant added without
6147    /// a matching arm on the probe surfaces at rustc's exhaustiveness
6148    /// gate on the ALL literal (arity forced by `[Self; 8]`) rather
6149    /// than as a silent false-positive at every downstream
6150    /// `precondition-<kind>` require-tag callsite.
6151    #[test]
6152    fn has_precondition_kind_returns_false_on_empty_boundary_for_every_kind() {
6153        let b = Boundary::default();
6154        for kind in ConditionKind::ALL {
6155            assert!(
6156                !b.has_precondition_kind(kind),
6157                "default boundary must return false on precondition arm for {kind:?}",
6158            );
6159        }
6160    }
6161
6162    /// EMPTY-BOUNDARY pin (postcondition arm) — sibling of the
6163    /// precondition-arm empty pin above on the other half of the
6164    /// (precondition, postcondition) partition. Locks the empty-slice
6165    /// arm return on the postcondition side so a regression that
6166    /// wired the postcondition arm to the precondition slice surfaces
6167    /// HERE at fail-before-pass-after granularity.
6168    #[test]
6169    fn has_postcondition_kind_returns_false_on_empty_boundary_for_every_kind() {
6170        let b = Boundary::default();
6171        for kind in ConditionKind::ALL {
6172            assert!(
6173                !b.has_postcondition_kind(kind),
6174                "default boundary must return false on postcondition arm for {kind:?}",
6175            );
6176        }
6177    }
6178
6179    /// SLICE-SELECTIVITY pin (precondition arm) — a boundary with a
6180    /// kind on the precondition side ONLY resolves `true` at
6181    /// `has_precondition_kind` and `false` at `has_postcondition_kind`.
6182    /// Locks the (side-select, kind-select) partition so a regression
6183    /// that pointed the precondition arm at `self.postconditions` (a
6184    /// copy-paste from the sibling arm) surfaces HERE rather than as
6185    /// silent classifier drift at every downstream
6186    /// `precondition-<kind>` require-tag callsite.
6187    #[test]
6188    fn has_precondition_kind_reads_preconditions_slice_only() {
6189        for populated in ConditionKind::ALL {
6190            let mut b = Boundary::default();
6191            b.preconditions.push(condition_with(populated));
6192            for query in ConditionKind::ALL {
6193                let expected_pre = query == populated;
6194                assert_eq!(
6195                    b.has_precondition_kind(query),
6196                    expected_pre,
6197                    "precondition-only populated={populated:?}: query {query:?} drifted \
6198                     on precondition arm",
6199                );
6200                assert!(
6201                    !b.has_postcondition_kind(query),
6202                    "precondition-only populated={populated:?}: query {query:?} must \
6203                     return false on postcondition arm (postconditions is empty)",
6204                );
6205            }
6206        }
6207    }
6208
6209    /// SLICE-SELECTIVITY pin (postcondition arm) — mirror of the
6210    /// precondition-only sweep on the other half. Locks the sibling
6211    /// arm's binding to `self.postconditions` so a regression that
6212    /// pointed the postcondition arm at `self.preconditions` fails
6213    /// HERE even though the precondition-arm pin above passes.
6214    #[test]
6215    fn has_postcondition_kind_reads_postconditions_slice_only() {
6216        for populated in ConditionKind::ALL {
6217            let mut b = Boundary::default();
6218            b.postconditions.push(condition_with(populated));
6219            for query in ConditionKind::ALL {
6220                let expected_post = query == populated;
6221                assert_eq!(
6222                    b.has_postcondition_kind(query),
6223                    expected_post,
6224                    "postcondition-only populated={populated:?}: query {query:?} \
6225                     drifted on postcondition arm",
6226                );
6227                assert!(
6228                    !b.has_precondition_kind(query),
6229                    "postcondition-only populated={populated:?}: query {query:?} must \
6230                     return false on precondition arm (preconditions is empty)",
6231                );
6232            }
6233        }
6234    }
6235
6236    /// COMPOSITION-LAW pin — [`Boundary::has_condition_kind`] equals
6237    /// `has_precondition_kind(k) || has_postcondition_kind(k)` at
6238    /// EVERY (pre-populated, post-populated, query) triple on
6239    /// `ConditionKind::ALL`. This is the load-bearing invariant that
6240    /// makes the (precondition, postcondition, union) triad on
6241    /// [`Boundary`] a first-class typed algebra rather than a
6242    /// per-caller discipline: the two half-slice arms + the union arm
6243    /// compose exactly as `union == pre ∨ post`, and every downstream
6244    /// `condition-<K> = precondition-<K> ∨ postcondition-<K>` classifier
6245    /// invariant on `tatara-reconciler::bin::tatara-check` inherits it
6246    /// mechanically. A regression that (a) dropped the composition (by
6247    /// re-inlining `.has_kind(kind)` bodies on the union arm), or
6248    /// (b) drifted ONE of the two half-slice arms without updating the
6249    /// other, surfaces HERE rather than as silent per-side classifier
6250    /// drift at the require-tag surfaces.
6251    #[test]
6252    fn boundary_has_condition_kind_composes_precondition_and_postcondition_arms() {
6253        for pre_kind in ConditionKind::ALL {
6254            for post_kind in ConditionKind::ALL {
6255                let mut b = Boundary::default();
6256                b.preconditions.push(condition_with(pre_kind));
6257                b.postconditions.push(condition_with(post_kind));
6258                for query in ConditionKind::ALL {
6259                    let via_arms =
6260                        b.has_precondition_kind(query) || b.has_postcondition_kind(query);
6261                    assert_eq!(
6262                        b.has_condition_kind(query),
6263                        via_arms,
6264                        "union arm drifted from OR of half-slice arms: \
6265                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6266                    );
6267                }
6268            }
6269        }
6270    }
6271
6272    /// SUBSTRATE-DELEGATION pin — the two half-slice arms delegate
6273    /// verbatim to [`ConditionSliceExt::has_kind`] on the underlying
6274    /// [`Vec<Condition>`] slice, no inline reimplementation. Sweep the
6275    /// full `ConditionKind::ALL` × `ConditionKind::ALL` cross so a
6276    /// regression that inlined a divergent walk (`.iter().find(_).
6277    /// is_some()`, an `.any(|c| matches!(c.kind, K))` that missed a
6278    /// variant) at either arm surfaces HERE at the substrate
6279    /// boundary rather than as silent skew between the struct-level
6280    /// arm and the slice-level primitive downstream consumers reach
6281    /// through.
6282    #[test]
6283    fn has_precondition_and_postcondition_kind_delegate_to_slice_has_kind() {
6284        for populated in ConditionKind::ALL {
6285            let mut b = Boundary::default();
6286            b.preconditions.push(condition_with(populated));
6287            b.postconditions.push(condition_with(populated));
6288            for query in ConditionKind::ALL {
6289                assert_eq!(
6290                    b.has_precondition_kind(query),
6291                    b.preconditions.has_kind(query),
6292                    "precondition arm must delegate to preconditions.has_kind: \
6293                     populated={populated:?} query={query:?}",
6294                );
6295                assert_eq!(
6296                    b.has_postcondition_kind(query),
6297                    b.postconditions.has_kind(query),
6298                    "postcondition arm must delegate to postconditions.has_kind: \
6299                     populated={populated:?} query={query:?}",
6300                );
6301            }
6302        }
6303    }
6304
6305    // ── ConditionSliceExt::find_kind substrate pins + widened triad ──
6306    //
6307    // Fail-before-pass-after granularity: `ConditionSliceExt::find_kind`
6308    // + its three struct-level peers (`Boundary::find_(pre|post)?
6309    // condition_kind`) did not exist before this commit — the existing
6310    // `has_*_kind` triad collapses the return to `bool`, losing the
6311    // matching `&Condition` a future diagnostic consumer (an operator-
6312    // facing "found on {pre|post}conditions at param.probeImage=X"
6313    // message, a coherence check verifying "every ClosedLoopAuth
6314    // postcondition carries a non-empty probeImage", an editor
6315    // completion listing params-keys per present kind) needs. The lift
6316    // widens the primitive to `Option<&Condition>` and re-anchors
6317    // `has_kind` as a default composed from it, so the two refinements
6318    // share ONE walk semantics by construction.
6319
6320    /// EMPTY-SLICE pin — an empty `&[Condition]` returns `None` from
6321    /// `find_kind` for EVERY [`ConditionKind`]. Sweep
6322    /// `ConditionKind::ALL` so a new variant added without a matching
6323    /// arm in the primitive surfaces at rustc's exhaustiveness gate on
6324    /// the ALL literal (arity forced by `[Self; 8]`) rather than as a
6325    /// silent false-`Some` at every downstream widened callsite.
6326    #[test]
6327    fn condition_slice_find_kind_returns_none_on_empty_slice_for_every_kind() {
6328        let empty: &[Condition] = &[];
6329        for kind in ConditionKind::ALL {
6330            assert!(
6331                empty.find_kind(kind).is_none(),
6332                "empty slice must return None for {kind:?}",
6333            );
6334        }
6335    }
6336
6337    /// PER-VARIANT pin — a single-element slice returns `Some` with
6338    /// the matching kind for exactly the kind it carries, `None` for
6339    /// every other variant. Sweep the ALL × ALL cross so a regression
6340    /// that (a) hard-coded the arm to a single kind (silently returning
6341    /// `Some` for every populated slice regardless of query kind), or
6342    /// (b) matched on [`Condition::params`] instead of [`Condition::kind`]
6343    /// fails HERE at the substrate primitive.
6344    #[test]
6345    fn condition_slice_find_kind_reads_kind_field_per_variant() {
6346        for populated in ConditionKind::ALL {
6347            let slice = [condition_with(populated)];
6348            for query in ConditionKind::ALL {
6349                let hit = slice.find_kind(query);
6350                if query == populated {
6351                    assert_eq!(
6352                        hit.map(|c| c.kind),
6353                        Some(populated),
6354                        "populated={populated:?}: query {query:?} must return Some",
6355                    );
6356                } else {
6357                    assert!(
6358                        hit.is_none(),
6359                        "populated={populated:?}: query {query:?} must return None",
6360                    );
6361                }
6362            }
6363        }
6364    }
6365
6366    /// FIRST-MATCH pin — a slice with the same kind at MULTIPLE
6367    /// positions returns the earliest by position. Locks the `.iter().
6368    /// find(...)` semantics so a regression that collapsed to a
6369    /// `.last()` walk (returning the trailing match) or a `.rev().
6370    /// find(...)` walk (returning the last-inserted match) surfaces
6371    /// HERE, since diagnostic consumers reading `find_kind(K).unwrap().
6372    /// params` expect the FIRST occurrence's params-payload not the
6373    /// last.
6374    #[test]
6375    fn condition_slice_find_kind_returns_first_position_on_duplicate_kinds() {
6376        // Two ClosedLoopAuth entries with distinct params — a first-
6377        // match walk resolves to the leading entry's params-payload.
6378        let first = Condition {
6379            kind: ConditionKind::ClosedLoopAuth,
6380            params: json!({ "probeImage": "first" }),
6381        };
6382        let second = Condition {
6383            kind: ConditionKind::ClosedLoopAuth,
6384            params: json!({ "probeImage": "second" }),
6385        };
6386        let slice = [first, second];
6387        let hit = slice
6388            .find_kind(ConditionKind::ClosedLoopAuth)
6389            .expect("populated slice must resolve Some on the matching kind");
6390        assert_eq!(
6391            hit.params
6392                .get("probeImage")
6393                .and_then(serde_json::Value::as_str),
6394            Some("first"),
6395            "find_kind must return the FIRST position's Condition on duplicate kinds",
6396        );
6397    }
6398
6399    /// SLICE-LEVEL DELEGATION pin (has ↔ find) — [`ConditionSliceExt::has_kind`]
6400    /// equals `find_kind(k).is_some()` at EVERY (populated arrangement,
6401    /// query) pair on `ConditionKind::ALL`. Turns the trait doc's
6402    /// "compounding" note ("the closed-set discriminator case becomes
6403    /// `has_kind(k) == self.find_kind(k).is_some()` by construction")
6404    /// into a first-class typed test invariant: a future consumer
6405    /// that overrode the default `has_kind` body with a divergent walk
6406    /// shape (a `.iter().any(...)` that missed a variant, a `.count() >
6407    /// 0` predicate on a filtered clone) surfaces HERE at the substrate
6408    /// boundary rather than as silent skew between the two refinements
6409    /// downstream consumers reach through.
6410    #[test]
6411    fn condition_slice_has_kind_equals_find_kind_is_some() {
6412        for pre_kind in ConditionKind::ALL {
6413            for post_kind in ConditionKind::ALL {
6414                let slice = [condition_with(pre_kind), condition_with(post_kind)];
6415                for query in ConditionKind::ALL {
6416                    assert_eq!(
6417                        slice.has_kind(query),
6418                        slice.find_kind(query).is_some(),
6419                        "slice-level has/find refinement bridge drifted: \
6420                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6421                    );
6422                }
6423            }
6424        }
6425    }
6426
6427    /// SUBSTRATE-DELEGATION pin (find-triad) — the three widened
6428    /// `find_*_kind` methods on [`Boundary`] delegate verbatim to
6429    /// [`ConditionSliceExt::find_kind`] on the underlying
6430    /// [`Vec<Condition>`] slices, no inline reimplementation. The
6431    /// `find_condition_kind` union walks preconditions first then
6432    /// postconditions via `Option::or_else`. Sweep
6433    /// `ConditionKind::ALL × ConditionKind::ALL × ConditionKind::ALL`
6434    /// so a regression that (a) inlined a divergent walk at either
6435    /// half-slice arm, (b) reversed the union walk order (postcondition
6436    /// first), or (c) collapsed `or_else` to `and_then` (silently
6437    /// narrowing the union to an intersection) surfaces HERE at the
6438    /// substrate boundary rather than as silent skew between the
6439    /// struct-level widened arms and the slice-level primitive.
6440    #[test]
6441    fn find_condition_kind_triad_delegates_to_slice_find_kind() {
6442        for pre_kind in ConditionKind::ALL {
6443            for post_kind in ConditionKind::ALL {
6444                let mut b = Boundary::default();
6445                b.preconditions.push(condition_with(pre_kind));
6446                b.postconditions.push(condition_with(post_kind));
6447                for query in ConditionKind::ALL {
6448                    let via_pre = b.preconditions.find_kind(query);
6449                    let via_post = b.postconditions.find_kind(query);
6450                    assert_eq!(
6451                        b.find_precondition_kind(query).map(|c| c.kind),
6452                        via_pre.map(|c| c.kind),
6453                        "precondition find arm must delegate to preconditions.find_kind: \
6454                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6455                    );
6456                    assert_eq!(
6457                        b.find_postcondition_kind(query).map(|c| c.kind),
6458                        via_post.map(|c| c.kind),
6459                        "postcondition find arm must delegate to postconditions.find_kind: \
6460                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6461                    );
6462                    let expected_union = via_pre.or(via_post).map(|c| c.kind);
6463                    assert_eq!(
6464                        b.find_condition_kind(query).map(|c| c.kind),
6465                        expected_union,
6466                        "union find arm must equal precondition.or_else(postcondition): \
6467                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6468                    );
6469                }
6470            }
6471        }
6472    }
6473
6474    /// PRECONDITION-PRECEDENCE pin — a kind authored on BOTH sides
6475    /// returns the precondition-side [`Condition`] from
6476    /// `find_condition_kind`. Uses two params-distinguishable
6477    /// [`Condition`]s so a regression that reversed the walk order
6478    /// (postcondition first) surfaces at the returned params payload
6479    /// rather than silently at the presence bit (which is `true` on
6480    /// both walk orders).
6481    #[test]
6482    fn find_condition_kind_returns_precondition_side_on_dual_populated() {
6483        let mut b = Boundary::default();
6484        b.preconditions.push(Condition {
6485            kind: ConditionKind::ClosedLoopAuth,
6486            params: json!({ "side": "pre" }),
6487        });
6488        b.postconditions.push(Condition {
6489            kind: ConditionKind::ClosedLoopAuth,
6490            params: json!({ "side": "post" }),
6491        });
6492        let hit = b
6493            .find_condition_kind(ConditionKind::ClosedLoopAuth)
6494            .expect("dual-populated boundary must resolve Some");
6495        assert_eq!(
6496            hit.params.get("side").and_then(serde_json::Value::as_str),
6497            Some("pre"),
6498            "find_condition_kind must walk preconditions first: dual-populated kind \
6499             returned postcondition-side Condition rather than precondition-side",
6500        );
6501    }
6502
6503    /// STRUCT-LEVEL DELEGATION pin (has ↔ find) — the three
6504    /// [`Boundary`] `has_*_kind` arms equal their widened peers'
6505    /// `.is_some()` projection at EVERY (pre-populated, post-populated,
6506    /// query) triple on `ConditionKind::ALL`. The three widened
6507    /// `find_*_kind` arms are the load-bearing primitives; the three
6508    /// `has_*_kind` arms are their bool projections. Byte-for-byte
6509    /// re-anchors the composition-law pin
6510    /// `boundary_has_condition_kind_composes_precondition_and_postcondition_arms`
6511    /// through the widened axis so a future consumer that reads
6512    /// `has_condition_kind` as sugar for `find_condition_kind(k).
6513    /// is_some()` (rather than as `has_precondition_kind ||
6514    /// has_postcondition_kind`) stays typed against the SAME truth
6515    /// table.
6516    #[test]
6517    fn boundary_has_triad_equals_find_triad_is_some_projection() {
6518        for pre_kind in ConditionKind::ALL {
6519            for post_kind in ConditionKind::ALL {
6520                let mut b = Boundary::default();
6521                b.preconditions.push(condition_with(pre_kind));
6522                b.postconditions.push(condition_with(post_kind));
6523                for query in ConditionKind::ALL {
6524                    assert_eq!(
6525                        b.has_precondition_kind(query),
6526                        b.find_precondition_kind(query).is_some(),
6527                        "precondition has/find bridge drifted: \
6528                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6529                    );
6530                    assert_eq!(
6531                        b.has_postcondition_kind(query),
6532                        b.find_postcondition_kind(query).is_some(),
6533                        "postcondition has/find bridge drifted: \
6534                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6535                    );
6536                    assert_eq!(
6537                        b.has_condition_kind(query),
6538                        b.find_condition_kind(query).is_some(),
6539                        "union has/find bridge drifted: \
6540                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6541                    );
6542                }
6543            }
6544        }
6545    }
6546
6547    // ── ConditionSliceExt::iter_kind substrate pins + widened triad ──
6548    //
6549    // Fail-before-pass-after granularity: `ConditionSliceExt::iter_kind`
6550    // + its three struct-level peers (`Boundary::iter_(pre|post|)?
6551    // condition_kind`) did not exist before this commit — the existing
6552    // `find_*_kind` triad collapses the return to `Option<&Condition>`
6553    // (yielding only the FIRST match), losing the full match stream a
6554    // future coherence check ("each ConditionKind appears at most
6555    // once per side" — `iter_kind(k).nth(1).is_none()`) or diagnostic
6556    // consumer ("N ClosedLoopAuth postconditions matched, listing
6557    // every param.probeImage" — `iter_kind(k).collect()`) needs. The
6558    // lift widens the primitive to `KindMatches<'_>` (a named
6559    // Iterator<Item = &Condition>) and re-anchors `find_kind` as a
6560    // default composed from it (`self.iter_kind(kind).next()`), so
6561    // the three refinements share ONE walk semantics by construction.
6562
6563    /// EMPTY-SLICE pin (iter) — an empty `&[Condition]` yields
6564    /// nothing from `iter_kind` for EVERY [`ConditionKind`]. Sweep
6565    /// `ConditionKind::ALL` so a new variant added without a matching
6566    /// arm in the primitive surfaces at rustc's exhaustiveness gate
6567    /// on the ALL literal rather than as a silent phantom-yield at
6568    /// every downstream widened callsite.
6569    #[test]
6570    fn condition_slice_iter_kind_yields_nothing_on_empty_slice_for_every_kind() {
6571        let empty: &[Condition] = &[];
6572        for kind in ConditionKind::ALL {
6573            assert_eq!(
6574                empty.iter_kind(kind).count(),
6575                0,
6576                "empty slice must yield nothing on iter_kind for {kind:?}",
6577            );
6578        }
6579    }
6580
6581    /// PER-VARIANT pin (iter) — a single-element slice yields exactly
6582    /// that element on the matching kind and nothing on every other
6583    /// kind. Sweep the ALL × ALL cross so a regression that (a)
6584    /// hard-coded the filter predicate to a single kind (silently
6585    /// yielding on every populated slice regardless of query kind),
6586    /// or (b) matched on [`Condition::params`] instead of
6587    /// [`Condition::kind`] fails HERE at the substrate primitive.
6588    #[test]
6589    fn condition_slice_iter_kind_reads_kind_field_per_variant() {
6590        for populated in ConditionKind::ALL {
6591            let slice = [condition_with(populated)];
6592            for query in ConditionKind::ALL {
6593                let collected: Vec<_> = slice.iter_kind(query).map(|c| c.kind).collect();
6594                if query == populated {
6595                    assert_eq!(
6596                        collected,
6597                        vec![populated],
6598                        "populated={populated:?}: query {query:?} must yield [populated]",
6599                    );
6600                } else {
6601                    assert!(
6602                        collected.is_empty(),
6603                        "populated={populated:?}: query {query:?} must yield nothing",
6604                    );
6605                }
6606            }
6607        }
6608    }
6609
6610    /// ALL-MATCHES pin — a slice with the same kind at MULTIPLE
6611    /// positions yields EVERY match in slice order (not just the
6612    /// first). Uses params-distinguishable [`Condition`]s so a
6613    /// regression that (a) collapsed to a single-match walk
6614    /// (`.iter().find(...)` yielding only the earliest and
6615    /// terminating), (b) reversed the yield order (`.rev().filter`
6616    /// yielding trailing-first), or (c) de-duplicated by kind (an
6617    /// erroneous `HashSet::insert`-gated walk) surfaces HERE at the
6618    /// params payload rather than silently at a downstream
6619    /// count-based coherence check.
6620    #[test]
6621    fn condition_slice_iter_kind_yields_every_match_in_slice_order_on_duplicates() {
6622        let first = Condition {
6623            kind: ConditionKind::ClosedLoopAuth,
6624            params: json!({ "probeImage": "first" }),
6625        };
6626        let middle = Condition {
6627            kind: ConditionKind::PromQL,
6628            params: json!({ "query": "up" }),
6629        };
6630        let second_cla = Condition {
6631            kind: ConditionKind::ClosedLoopAuth,
6632            params: json!({ "probeImage": "second" }),
6633        };
6634        let slice = [first, middle, second_cla];
6635        let hits: Vec<_> = slice
6636            .iter_kind(ConditionKind::ClosedLoopAuth)
6637            .map(|c| {
6638                c.params
6639                    .get("probeImage")
6640                    .and_then(serde_json::Value::as_str)
6641                    .unwrap_or_default()
6642                    .to_owned()
6643            })
6644            .collect();
6645        assert_eq!(
6646            hits,
6647            vec!["first".to_owned(), "second".to_owned()],
6648            "iter_kind must yield every match in slice order (not just the first)",
6649        );
6650        // The interleaved non-matching kind is skipped: two hits, not three.
6651        assert_eq!(
6652            slice.iter_kind(ConditionKind::ClosedLoopAuth).count(),
6653            2,
6654            "iter_kind must skip non-matching kinds, not include them in the stream",
6655        );
6656    }
6657
6658    /// SLICE-LEVEL DELEGATION pin (find ↔ iter) — the trait's default
6659    /// `find_kind` body equals `iter_kind(k).next()` at EVERY
6660    /// (populated arrangement, query) pair on `ConditionKind::ALL`.
6661    /// Turns the trait doc's composition-law note
6662    /// ("`find_kind(k) == iter_kind(k).next()` by construction")
6663    /// into a first-class typed test invariant: a future implementor
6664    /// that overrode the default `find_kind` body with a divergent
6665    /// walk shape (a `.iter().rev().find(...)` returning trailing-
6666    /// first, a hand-rolled loop that walked past the first match)
6667    /// surfaces HERE at the substrate boundary rather than as silent
6668    /// skew between the two refinements downstream consumers reach
6669    /// through.
6670    #[test]
6671    fn condition_slice_find_kind_equals_iter_kind_next() {
6672        for pre_kind in ConditionKind::ALL {
6673            for post_kind in ConditionKind::ALL {
6674                let slice = [condition_with(pre_kind), condition_with(post_kind)];
6675                for query in ConditionKind::ALL {
6676                    assert_eq!(
6677                        slice.find_kind(query).map(|c| c.kind),
6678                        slice.iter_kind(query).next().map(|c| c.kind),
6679                        "slice-level find/iter refinement bridge drifted: \
6680                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6681                    );
6682                }
6683            }
6684        }
6685    }
6686
6687    /// SUBSTRATE-DELEGATION pin (Boundary iter-triad) — the three
6688    /// widened `iter_*_kind` methods on [`Boundary`] delegate verbatim
6689    /// to [`ConditionSliceExt::iter_kind`] on the underlying
6690    /// [`Vec<Condition>`] slices, no inline reimplementation. The
6691    /// `iter_condition_kind` union chains preconditions first then
6692    /// postconditions via [`Iterator::chain`]. Sweep
6693    /// `ConditionKind::ALL × ConditionKind::ALL × ConditionKind::ALL`
6694    /// so a regression that (a) inlined a divergent walk at either
6695    /// half-slice arm, (b) reversed the chain order (postcondition
6696    /// first — walk-order regression on the union), or (c) collapsed
6697    /// the chain to a `.zip(...)` (silently narrowing the union to
6698    /// an intersection-by-position) surfaces HERE at the substrate
6699    /// boundary rather than as silent skew between the struct-level
6700    /// widened arms and the slice-level primitive.
6701    #[test]
6702    fn iter_condition_kind_triad_delegates_to_slice_iter_kind() {
6703        for pre_kind in ConditionKind::ALL {
6704            for post_kind in ConditionKind::ALL {
6705                let mut b = Boundary::default();
6706                b.preconditions.push(condition_with(pre_kind));
6707                b.postconditions.push(condition_with(post_kind));
6708                for query in ConditionKind::ALL {
6709                    let via_pre: Vec<_> =
6710                        b.preconditions.iter_kind(query).map(|c| c.kind).collect();
6711                    let via_post: Vec<_> =
6712                        b.postconditions.iter_kind(query).map(|c| c.kind).collect();
6713                    assert_eq!(
6714                        b.iter_precondition_kind(query)
6715                            .map(|c| c.kind)
6716                            .collect::<Vec<_>>(),
6717                        via_pre,
6718                        "precondition iter arm must delegate to preconditions.iter_kind: \
6719                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6720                    );
6721                    assert_eq!(
6722                        b.iter_postcondition_kind(query)
6723                            .map(|c| c.kind)
6724                            .collect::<Vec<_>>(),
6725                        via_post,
6726                        "postcondition iter arm must delegate to postconditions.iter_kind: \
6727                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6728                    );
6729                    let mut expected_union = via_pre.clone();
6730                    expected_union.extend(via_post.iter().copied());
6731                    assert_eq!(
6732                        b.iter_condition_kind(query)
6733                            .map(|c| c.kind)
6734                            .collect::<Vec<_>>(),
6735                        expected_union,
6736                        "union iter arm must chain precondition ⨟ postcondition: \
6737                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6738                    );
6739                }
6740            }
6741        }
6742    }
6743
6744    /// STRUCT-LEVEL DELEGATION pin (find ↔ iter on Boundary) — the
6745    /// three [`Boundary`] `find_*_kind` arms equal their widened
6746    /// peers' `.next()` projection at EVERY (pre-populated,
6747    /// post-populated, query) triple on `ConditionKind::ALL`. Byte-
6748    /// for-byte re-anchors the composition-law pin
6749    /// `find_condition_kind == iter_condition_kind.next()` through
6750    /// the widened axis on the parent surface — a future consumer
6751    /// that reads `find_condition_kind(k)` as sugar for
6752    /// `iter_condition_kind(k).next()` stays typed against the SAME
6753    /// truth table on both the slice-level and struct-level layers.
6754    #[test]
6755    fn boundary_find_triad_equals_iter_triad_next_projection() {
6756        for pre_kind in ConditionKind::ALL {
6757            for post_kind in ConditionKind::ALL {
6758                let mut b = Boundary::default();
6759                b.preconditions.push(condition_with(pre_kind));
6760                b.postconditions.push(condition_with(post_kind));
6761                for query in ConditionKind::ALL {
6762                    assert_eq!(
6763                        b.find_precondition_kind(query).map(|c| c.kind),
6764                        b.iter_precondition_kind(query).next().map(|c| c.kind),
6765                        "precondition find/iter bridge drifted: \
6766                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6767                    );
6768                    assert_eq!(
6769                        b.find_postcondition_kind(query).map(|c| c.kind),
6770                        b.iter_postcondition_kind(query).next().map(|c| c.kind),
6771                        "postcondition find/iter bridge drifted: \
6772                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6773                    );
6774                    assert_eq!(
6775                        b.find_condition_kind(query).map(|c| c.kind),
6776                        b.iter_condition_kind(query).next().map(|c| c.kind),
6777                        "union find/iter bridge drifted: \
6778                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
6779                    );
6780                }
6781            }
6782        }
6783    }
6784
6785    /// PRECONDITION-PRECEDENCE pin (iter) — a kind authored on BOTH
6786    /// sides yields precondition-side matches FIRST in the union
6787    /// chain. Uses params-distinguishable [`Condition`]s so a
6788    /// regression that (a) reversed the chain order on the widened
6789    /// axis (postcondition first), (b) interleaved the two sides,
6790    /// or (c) collapsed the chain to a `.zip(...)` fails at the
6791    /// returned params-payload sequence rather than silently at the
6792    /// count.
6793    #[test]
6794    fn iter_condition_kind_yields_preconditions_before_postconditions_on_dual_populated() {
6795        let mut b = Boundary::default();
6796        b.preconditions.push(Condition {
6797            kind: ConditionKind::ClosedLoopAuth,
6798            params: json!({ "side": "pre-1" }),
6799        });
6800        b.preconditions.push(Condition {
6801            kind: ConditionKind::ClosedLoopAuth,
6802            params: json!({ "side": "pre-2" }),
6803        });
6804        b.postconditions.push(Condition {
6805            kind: ConditionKind::ClosedLoopAuth,
6806            params: json!({ "side": "post-1" }),
6807        });
6808        let sides: Vec<_> = b
6809            .iter_condition_kind(ConditionKind::ClosedLoopAuth)
6810            .map(|c| {
6811                c.params
6812                    .get("side")
6813                    .and_then(serde_json::Value::as_str)
6814                    .unwrap_or_default()
6815                    .to_owned()
6816            })
6817            .collect();
6818        assert_eq!(
6819            sides,
6820            vec!["pre-1".to_owned(), "pre-2".to_owned(), "post-1".to_owned(),],
6821            "iter_condition_kind must yield every precondition-side match before any \
6822             postcondition-side match (chain order pinned by two-surface parity contract)",
6823        );
6824    }
6825
6826    // ----- count_kind — scalar cardinality refinement --------------------
6827    //
6828    // The `count_kind` fourth refinement collapses the widened
6829    // `iter_kind` stream to its cardinality without materializing an
6830    // intermediate `Vec` or `Option`. Distinct composition law from the
6831    // three prior refinements: `count_condition_kind` SUMS pre + post
6832    // (rather than OR-ing them via `has`, or_else-ing them via `find`,
6833    // or Chain-ing them via `iter`). The tests below pin (a) the default
6834    // trait body against the primitive `iter_kind(k).count()`, (b) the
6835    // slice-level composition laws `has_kind(k) == (count_kind(k) > 0)`
6836    // and `find_kind(k).is_some() == (count_kind(k) > 0)`, (c) the
6837    // struct-level SUM composition on both `Boundary` half-slice arms,
6838    // and (d) the two-surface parity contract with
6839    // `EphemeralSpec::count_(pre|post|)condition_kind` (in ephemeral.rs).
6840
6841    /// EMPTY-SLICE pin (count) — an empty `&[Condition]` returns `0`
6842    /// from `count_kind` for EVERY [`ConditionKind`]. Sweep
6843    /// `ConditionKind::ALL` so a new variant added without a matching
6844    /// arm surfaces at rustc's exhaustiveness gate on the ALL literal
6845    /// rather than as silent phantom-cardinality at every downstream
6846    /// count callsite.
6847    #[test]
6848    fn condition_slice_count_kind_returns_zero_on_empty_slice_for_every_kind() {
6849        let empty: &[Condition] = &[];
6850        for kind in ConditionKind::ALL {
6851            assert_eq!(
6852                empty.count_kind(kind),
6853                0,
6854                "empty slice must count 0 for {kind:?}",
6855            );
6856        }
6857    }
6858
6859    /// PER-VARIANT pin (count) — a single-element slice returns `1`
6860    /// on the matching kind and `0` on every other kind. Sweep ALL ×
6861    /// ALL so a regression that (a) hard-coded the filter predicate
6862    /// to a single kind (silently counting every populated slice
6863    /// regardless of query), or (b) matched on [`Condition::params`]
6864    /// instead of [`Condition::kind`] fails HERE at the substrate
6865    /// primitive.
6866    #[test]
6867    fn condition_slice_count_kind_reads_kind_field_per_variant() {
6868        for populated in ConditionKind::ALL {
6869            let slice = [condition_with(populated)];
6870            for query in ConditionKind::ALL {
6871                let expected = if query == populated { 1 } else { 0 };
6872                assert_eq!(
6873                    slice.count_kind(query),
6874                    expected,
6875                    "populated={populated:?} query={query:?} \
6876                     must count {expected}",
6877                );
6878            }
6879        }
6880    }
6881
6882    /// DUPLICATES pin (count) — a slice with the same kind at
6883    /// MULTIPLE positions returns the exact match count (not `1`, not
6884    /// a de-duplicated `1`). A regression that (a) short-circuited on
6885    /// the first match (an `.iter().find(...)` yielding `0`/`1` sugar
6886    /// on the count arm), or (b) de-duplicated by kind (an erroneous
6887    /// `HashSet::insert`-gated walk that swallowed repeats) surfaces
6888    /// HERE at the cardinality boundary rather than silently at a
6889    /// downstream count-based coherence check.
6890    #[test]
6891    fn condition_slice_count_kind_counts_every_match_on_duplicates() {
6892        let slice = [
6893            Condition {
6894                kind: ConditionKind::ClosedLoopAuth,
6895                params: json!({ "probeImage": "first" }),
6896            },
6897            Condition {
6898                kind: ConditionKind::PromQL,
6899                params: json!({ "query": "up" }),
6900            },
6901            Condition {
6902                kind: ConditionKind::ClosedLoopAuth,
6903                params: json!({ "probeImage": "second" }),
6904            },
6905        ];
6906        assert_eq!(slice.count_kind(ConditionKind::ClosedLoopAuth), 2);
6907        assert_eq!(slice.count_kind(ConditionKind::PromQL), 1);
6908        for kind in ConditionKind::ALL {
6909            if matches!(kind, ConditionKind::ClosedLoopAuth | ConditionKind::PromQL) {
6910                continue;
6911            }
6912            assert_eq!(
6913                slice.count_kind(kind),
6914                0,
6915                "non-populated kind {kind:?} must count 0",
6916            );
6917        }
6918    }
6919
6920    /// SLICE-LEVEL DELEGATION pin (count ↔ iter) — the trait's
6921    /// default `count_kind` body equals `iter_kind(k).count()` at
6922    /// EVERY (populated arrangement, query) pair on
6923    /// `ConditionKind::ALL`. Turns the trait doc's composition-law
6924    /// note (`count_kind(k) == iter_kind(k).count()` by construction)
6925    /// into a first-class typed invariant: a future implementor that
6926    /// overrode the default `count_kind` body with a divergent walk
6927    /// shape (a stored-length cache that drifted, a `.step_by(2)`
6928    /// artefact from a copy-paste of `iter_kind`) surfaces HERE.
6929    #[test]
6930    fn condition_slice_count_kind_equals_iter_kind_count() {
6931        for pre_kind in ConditionKind::ALL {
6932            for post_kind in ConditionKind::ALL {
6933                let slice = [condition_with(pre_kind), condition_with(post_kind)];
6934                for query in ConditionKind::ALL {
6935                    assert_eq!(
6936                        slice.count_kind(query),
6937                        slice.iter_kind(query).count(),
6938                        "count/iter bridge drifted: pre={pre_kind:?} \
6939                         post={post_kind:?} query={query:?}",
6940                    );
6941                }
6942            }
6943        }
6944    }
6945
6946    /// SLICE-LEVEL DELEGATION pin (count ↔ has ↔ find) — the two
6947    /// composition laws
6948    /// `has_kind(k) == (count_kind(k) > 0)` and
6949    /// `find_kind(k).is_some() == (count_kind(k) > 0)`
6950    /// hold at every (populated, populated, query) triple on
6951    /// `ConditionKind::ALL`. Sweeps both refinement bridges at ONE
6952    /// site so a regression at the count primitive that drifted from
6953    /// the presence bit or the first-match probe surfaces HERE.
6954    #[test]
6955    fn condition_slice_has_and_find_equal_count_greater_than_zero() {
6956        for pre_kind in ConditionKind::ALL {
6957            for post_kind in ConditionKind::ALL {
6958                let slice = [condition_with(pre_kind), condition_with(post_kind)];
6959                for query in ConditionKind::ALL {
6960                    let count = slice.count_kind(query);
6961                    assert_eq!(
6962                        slice.has_kind(query),
6963                        count > 0,
6964                        "has/count bridge drifted: pre={pre_kind:?} \
6965                         post={post_kind:?} query={query:?}",
6966                    );
6967                    assert_eq!(
6968                        slice.find_kind(query).is_some(),
6969                        count > 0,
6970                        "find/count bridge drifted: pre={pre_kind:?} \
6971                         post={post_kind:?} query={query:?}",
6972                    );
6973                }
6974            }
6975        }
6976    }
6977
6978    /// SUBSTRATE-DELEGATION pin (Boundary count-triad) — the three
6979    /// widened `count_*_kind` methods on [`Boundary`] delegate
6980    /// verbatim to [`ConditionSliceExt::count_kind`] on the
6981    /// underlying [`Vec<Condition>`] slices. The
6982    /// `count_condition_kind` union SUMS preconditions and
6983    /// postconditions (distinct from the `iter_condition_kind`
6984    /// [`Chain`](std::iter::Chain), `find_condition_kind`
6985    /// [`Option::or_else`], and `has_condition_kind` `||`
6986    /// compositions on the same axis). Sweep `ConditionKind::ALL ×
6987    /// ConditionKind::ALL × ConditionKind::ALL` so a regression that
6988    /// (a) inlined a divergent count at either half-slice arm, (b)
6989    /// subtracted rather than summed, or (c) collapsed the sum to
6990    /// [`std::cmp::max`] (silently narrowing the union to a max-per-
6991    /// side probe) surfaces HERE at the substrate boundary.
6992    #[test]
6993    fn boundary_count_condition_kind_triad_delegates_and_sums_slice_count_kind() {
6994        for pre_kind in ConditionKind::ALL {
6995            for post_kind in ConditionKind::ALL {
6996                let mut b = Boundary::default();
6997                b.preconditions.push(condition_with(pre_kind));
6998                b.postconditions.push(condition_with(post_kind));
6999                for query in ConditionKind::ALL {
7000                    let via_pre = b.preconditions.count_kind(query);
7001                    let via_post = b.postconditions.count_kind(query);
7002                    assert_eq!(
7003                        b.count_precondition_kind(query),
7004                        via_pre,
7005                        "boundary precondition count arm must delegate: \
7006                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
7007                    );
7008                    assert_eq!(
7009                        b.count_postcondition_kind(query),
7010                        via_post,
7011                        "boundary postcondition count arm must delegate: \
7012                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
7013                    );
7014                    assert_eq!(
7015                        b.count_condition_kind(query),
7016                        via_pre + via_post,
7017                        "boundary union count arm must SUM pre + post: \
7018                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
7019                    );
7020                }
7021            }
7022        }
7023    }
7024
7025    /// STRUCT-LEVEL DELEGATION pin (count ↔ iter on Boundary) — the
7026    /// three [`Boundary`] `count_*_kind` arms equal their widened
7027    /// peers' `.count()` projection at EVERY (pre-populated, post-
7028    /// populated, query) triple on `ConditionKind::ALL`. Re-anchors
7029    /// the composition-law pin
7030    /// `count_condition_kind == iter_condition_kind.count()` through
7031    /// the cardinality axis on the parent surface — a future consumer
7032    /// that reads `count_condition_kind(k)` as sugar for
7033    /// `iter_condition_kind(k).count()` stays typed against the SAME
7034    /// truth table on both the slice-level and struct-level layers.
7035    /// Also pins the sum-composition round-trip through the widened
7036    /// stream: the union arm's SUM equals the chained stream's count.
7037    #[test]
7038    fn boundary_count_triad_equals_iter_triad_count_projection() {
7039        for pre_kind in ConditionKind::ALL {
7040            for post_kind in ConditionKind::ALL {
7041                let mut b = Boundary::default();
7042                b.preconditions.push(condition_with(pre_kind));
7043                b.preconditions.push(condition_with(pre_kind));
7044                b.postconditions.push(condition_with(post_kind));
7045                for query in ConditionKind::ALL {
7046                    assert_eq!(
7047                        b.count_precondition_kind(query),
7048                        b.iter_precondition_kind(query).count(),
7049                        "precondition count/iter bridge drifted: \
7050                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
7051                    );
7052                    assert_eq!(
7053                        b.count_postcondition_kind(query),
7054                        b.iter_postcondition_kind(query).count(),
7055                        "postcondition count/iter bridge drifted: \
7056                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
7057                    );
7058                    assert_eq!(
7059                        b.count_condition_kind(query),
7060                        b.iter_condition_kind(query).count(),
7061                        "union count/iter bridge drifted: \
7062                         pre={pre_kind:?} post={post_kind:?} query={query:?}",
7063                    );
7064                }
7065            }
7066        }
7067    }
7068
7069    // ── ConditionSliceExt::distinct_kinds — closed-set-inversion axis ──
7070    //
7071    // The fifth refinement on the slice-level presence-probe algebra
7072    // inverts the axis: the four point-probe refinements (has, find,
7073    // iter, count) fix a [`ConditionKind`] and vary the return type;
7074    // `distinct_kinds` fixes the slice and varies over
7075    // [`ConditionKind::ALL`], returning the SET of present kinds
7076    // projected in [`ConditionKind::ALL`] order with no duplicates.
7077    // The composition-law arms in `assert_slice_refinement_composition_laws`
7078    // pin the fifth refinement against `has_kind` per variant AND
7079    // against the canonical ALL-order equality; the four dedicated
7080    // behavior tests below pin the returned VALUE per authored
7081    // arrangement (empty, single-element populated, dual-populated,
7082    // duplicate-populated).
7083
7084    /// EMPTY-SLICE pin — an empty slice returns an empty `Vec` on
7085    /// `distinct_kinds`, distinct from every populated arrangement.
7086    /// Locks the zero-element identity so a regression that (a)
7087    /// returned `ConditionKind::ALL.to_vec()` (the wrong direction of
7088    /// the closed-set walk), (b) returned a placeholder `[ProcessPhase]`
7089    /// vec (a copy-paste of the first-variant default in a `impl
7090    /// Default` for a hypothetical `KindSet` wrapper) surfaces HERE.
7091    #[test]
7092    fn condition_slice_distinct_kinds_returns_empty_vec_on_empty_slice() {
7093        let empty: &[Condition] = &[];
7094        assert_eq!(
7095            empty.distinct_kinds(),
7096            Vec::<ConditionKind>::new(),
7097            "empty slice must return empty distinct-kinds vec",
7098        );
7099    }
7100
7101    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
7102    /// the addressed kind returns `[kind]` — a single-element vec
7103    /// containing exactly that kind. Sweep `ConditionKind::ALL` so a
7104    /// new variant added without a matching arm in the closed-set walk
7105    /// surfaces at rustc's exhaustiveness gate on the ALL literal
7106    /// (arity forced by `[Self; 8]`) rather than as a silent false-
7107    /// negative at every downstream `distinct_condition_kinds`
7108    /// callsite. Locks the closed-set-inversion probe body against a
7109    /// regression that (a) always returned `[ProcessPhase]` regardless
7110    /// of the actual kind, (b) collapsed `distinct_kinds` to
7111    /// `iter_kind(<first ALL variant>).map(|c| c.kind).collect()`
7112    /// (silently filtering to only ProcessPhase matches).
7113    #[test]
7114    fn condition_slice_distinct_kinds_returns_single_element_vec_per_variant() {
7115        for populated in ConditionKind::ALL {
7116            let slice = [condition_with(populated)];
7117            assert_eq!(
7118                slice.distinct_kinds(),
7119                vec![populated],
7120                "single-populated slice must return exactly [{populated:?}] on distinct_kinds",
7121            );
7122        }
7123    }
7124
7125    /// DEDUP pin — a slice with the SAME kind at multiple positions
7126    /// (three interleaved with distinct kinds) returns a distinct-set
7127    /// containing that kind exactly ONCE. The closed-set-inversion
7128    /// projection collapses multiplicity — a caller that needs the
7129    /// per-kind cardinality reaches for `count_kind`; this refinement
7130    /// returns the PRESENCE set. A regression that (a) omitted the
7131    /// dedup and returned `[ClosedLoopAuth, PromQL, ClosedLoopAuth,
7132    /// PromQL, ClosedLoopAuth]` (byte-identical to
7133    /// `slice.iter().map(|c| c.kind).collect()` — the wrong closed-
7134    /// set walk direction), (b) counted every duplicate as a distinct
7135    /// entry via a `.collect::<HashSet<_>>()` without canonicalizing
7136    /// order surfaces HERE.
7137    #[test]
7138    fn condition_slice_distinct_kinds_deduplicates_and_yields_canonical_all_order() {
7139        let interleaved = [
7140            Condition {
7141                kind: ConditionKind::ClosedLoopAuth,
7142                params: json!({ "probeImage": "first" }),
7143            },
7144            Condition {
7145                kind: ConditionKind::PromQL,
7146                params: json!({ "query": "up" }),
7147            },
7148            Condition {
7149                kind: ConditionKind::ClosedLoopAuth,
7150                params: json!({ "probeImage": "second" }),
7151            },
7152            Condition {
7153                kind: ConditionKind::PromQL,
7154                params: json!({ "query": "healthy" }),
7155            },
7156            Condition {
7157                kind: ConditionKind::ClosedLoopAuth,
7158                params: json!({ "probeImage": "third" }),
7159            },
7160        ];
7161        // Canonical ConditionKind::ALL order: PromQL is at position 3,
7162        // ClosedLoopAuth at position 7 in the ALL array. So PromQL comes
7163        // FIRST in the distinct-set even though ClosedLoopAuth appears
7164        // FIRST in the slice — the closed-set-inversion walk is
7165        // ordered by ConditionKind::ALL, not by slice-encounter order.
7166        assert_eq!(
7167            interleaved.distinct_kinds(),
7168            vec![ConditionKind::PromQL, ConditionKind::ClosedLoopAuth],
7169            "interleaved-duplicate slice must dedup AND order by ConditionKind::ALL, not by slice-encounter order",
7170        );
7171    }
7172
7173    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7174    /// variant returns `ConditionKind::ALL.to_vec()` on `distinct_kinds`.
7175    /// The closed-set-inversion probe covers the full closed set at ONE
7176    /// call site — a regression that missed one variant in the walk
7177    /// (skipping the FIRST or LAST `ALL` entry via a `[1..]` or
7178    /// `[..ALL.len() - 1]` slice bug in the closed-set walk) surfaces
7179    /// HERE.
7180    #[test]
7181    fn condition_slice_distinct_kinds_covers_full_closed_set_on_saturated_slice() {
7182        let saturated: Vec<Condition> =
7183            ConditionKind::ALL.into_iter().map(condition_with).collect();
7184        assert_eq!(
7185            saturated.as_slice().distinct_kinds(),
7186            ConditionKind::ALL.to_vec(),
7187            "slice containing every ConditionKind must return ConditionKind::ALL as its distinct-set",
7188        );
7189    }
7190
7191    // ── distinct_kind_count — slice-level scalar-cardinality pins ──────
7192    //
7193    // The trait-level scalar-cardinality projection of the closed-set-
7194    // inversion widened primitive: `distinct_kind_count()` collapses
7195    // `distinct_kinds()` to its cardinality without materializing the
7196    // intermediate `Vec<ConditionKind>`. Composition law
7197    // `distinct_kind_count() == distinct_kinds().len()` pinned as the
7198    // sixth arm of the substrate testkit primitive
7199    // [`assert_slice_refinement_composition_laws`].
7200
7201    /// ZERO-ELEMENT pin — an empty slice returns `0` on
7202    /// `distinct_kind_count`, byte-for-byte with `distinct_kinds().len()`
7203    /// on the same slice. Locks the zero-element identity so a
7204    /// regression that (a) returned `ConditionKind::ALL.len()` (the
7205    /// wrong direction of the closed-set walk — every kind counted
7206    /// regardless of presence), (b) returned a placeholder `1` (a
7207    /// copy-paste of a single-slot factory's cardinality), or (c) drifted
7208    /// off `distinct_kinds().len()` surfaces HERE.
7209    #[test]
7210    fn condition_slice_distinct_kind_count_returns_zero_on_empty_slice() {
7211        let empty: &[Condition] = &[];
7212        assert_eq!(
7213            empty.distinct_kind_count(),
7214            0,
7215            "empty slice must return 0 on distinct_kind_count",
7216        );
7217        assert_eq!(
7218            empty.distinct_kind_count(),
7219            empty.distinct_kinds().len(),
7220            "empty slice distinct_kind_count must equal distinct_kinds().len()",
7221        );
7222    }
7223
7224    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
7225    /// the addressed kind returns `1` on `distinct_kind_count` — the
7226    /// single-slot diagonal cardinality. Sweep [`ConditionKind::ALL`]
7227    /// so a regression that (a) always returned `0` regardless of the
7228    /// actual kind, (b) always returned `ConditionKind::ALL.len()`
7229    /// (missed the `filter` step), or (c) collapsed the walk to a
7230    /// single fixed variant surfaces HERE.
7231    #[test]
7232    fn condition_slice_distinct_kind_count_returns_one_per_variant() {
7233        for populated in ConditionKind::ALL {
7234            let slice = [condition_with(populated)];
7235            assert_eq!(
7236                slice.distinct_kind_count(),
7237                1,
7238                "single-populated slice must return 1 on distinct_kind_count for {populated:?}",
7239            );
7240            assert_eq!(
7241                slice.distinct_kind_count(),
7242                slice.distinct_kinds().len(),
7243                "single-populated distinct_kind_count must equal distinct_kinds().len() for {populated:?}",
7244            );
7245        }
7246    }
7247
7248    /// DEDUP pin — a slice with the SAME kind at multiple positions
7249    /// (three interleaved with distinct kinds — two `PromQL`, three
7250    /// `ClosedLoopAuth`) returns `2` on `distinct_kind_count` (the
7251    /// scalar cardinality of the DISTINCT presence set, byte-for-byte
7252    /// with `distinct_kinds().len()` on the same slice). Locks the
7253    /// closed-set projection against a regression that (a) counted
7254    /// every occurrence (returning `5` — byte-identical to
7255    /// `slice.len()`), (b) omitted the dedup and returned `5` via
7256    /// `.iter().map(|c| c.kind).count()`.
7257    #[test]
7258    fn condition_slice_distinct_kind_count_dedups_across_duplicates() {
7259        let interleaved = [
7260            Condition {
7261                kind: ConditionKind::ClosedLoopAuth,
7262                params: json!({ "probeImage": "first" }),
7263            },
7264            Condition {
7265                kind: ConditionKind::PromQL,
7266                params: json!({ "query": "up" }),
7267            },
7268            Condition {
7269                kind: ConditionKind::ClosedLoopAuth,
7270                params: json!({ "probeImage": "second" }),
7271            },
7272            Condition {
7273                kind: ConditionKind::PromQL,
7274                params: json!({ "query": "healthy" }),
7275            },
7276            Condition {
7277                kind: ConditionKind::ClosedLoopAuth,
7278                params: json!({ "probeImage": "third" }),
7279            },
7280        ];
7281        assert_eq!(
7282            interleaved.distinct_kind_count(),
7283            2,
7284            "interleaved-duplicate slice must return 2 on distinct_kind_count (PromQL + ClosedLoopAuth)",
7285        );
7286        assert_eq!(
7287            interleaved.distinct_kind_count(),
7288            interleaved.distinct_kinds().len(),
7289            "interleaved-duplicate distinct_kind_count must equal distinct_kinds().len()",
7290        );
7291    }
7292
7293    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7294    /// variant returns `ConditionKind::ALL.len()` on `distinct_kind_count`.
7295    /// The scalar cardinality projection covers the full closed set at
7296    /// ONE call site — a regression that missed one variant in the walk
7297    /// (skipping the FIRST or LAST `ALL` entry via a `[1..]` or
7298    /// `[..ALL.len() - 1]` slice bug in the closed-set walk) surfaces
7299    /// HERE.
7300    #[test]
7301    fn condition_slice_distinct_kind_count_covers_full_closed_set_on_saturated_slice() {
7302        let saturated: Vec<Condition> =
7303            ConditionKind::ALL.into_iter().map(condition_with).collect();
7304        assert_eq!(
7305            saturated.as_slice().distinct_kind_count(),
7306            ConditionKind::ALL.len(),
7307            "slice containing every ConditionKind must return ConditionKind::ALL.len() on distinct_kind_count",
7308        );
7309        assert_eq!(
7310            saturated.as_slice().distinct_kind_count(),
7311            saturated.as_slice().distinct_kinds().len(),
7312            "saturated distinct_kind_count must equal distinct_kinds().len()",
7313        );
7314    }
7315
7316    // ── ConditionSliceExt::missing_kinds — closed-set-complement axis ──
7317    //
7318    // The complement peer of `distinct_kinds` on the closed-set-
7319    // inversion axis: `missing_kinds` returns the SET of kinds that
7320    // do NOT appear in the slice, in canonical [`ConditionKind::ALL`]
7321    // order. The four tests below pin each authored arrangement's
7322    // returned VALUE (empty, single-populated, saturated, interleaved-
7323    // duplicate); the composition-law arms in
7324    // `assert_slice_refinement_composition_laws` pin the closed-set-
7325    // partition invariants against `distinct_kinds` and `has_kind`.
7326
7327    /// EMPTY-SLICE pin — an empty slice returns
7328    /// `ConditionKind::ALL.to_vec()` on `missing_kinds` (every kind is
7329    /// missing). Locks the maximum-cardinality identity on the
7330    /// complement side, byte-for-byte dual to the empty-slice arm of
7331    /// `distinct_kinds` (which returns an empty vec). A regression that
7332    /// returned an empty vec (forgot the negation) or a placeholder
7333    /// `[ProcessPhase]` (a copy-paste of the first-variant default)
7334    /// surfaces HERE.
7335    #[test]
7336    fn condition_slice_missing_kinds_returns_full_closed_set_on_empty_slice() {
7337        let empty: &[Condition] = &[];
7338        assert_eq!(
7339            empty.missing_kinds(),
7340            ConditionKind::ALL.to_vec(),
7341            "empty slice must return ConditionKind::ALL on missing_kinds (every kind is missing)",
7342        );
7343    }
7344
7345    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
7346    /// the addressed kind returns `ConditionKind::ALL` MINUS that kind
7347    /// on `missing_kinds`. Sweep [`ConditionKind::ALL`] so a regression
7348    /// that (a) returned an empty vec regardless of the kind, (b)
7349    /// returned the full ALL vec (forgot to filter), or (c) inverted
7350    /// the negation and returned only the addressed kind surfaces HERE.
7351    #[test]
7352    fn condition_slice_missing_kinds_returns_all_minus_populated_kind() {
7353        for populated in ConditionKind::ALL {
7354            let slice = [condition_with(populated)];
7355            let expected: Vec<_> = ConditionKind::ALL
7356                .into_iter()
7357                .filter(|k| *k != populated)
7358                .collect();
7359            assert_eq!(
7360                slice.missing_kinds(),
7361                expected,
7362                "single-populated slice must return ConditionKind::ALL minus {populated:?} on missing_kinds",
7363            );
7364        }
7365    }
7366
7367    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7368    /// variant returns an empty vec on `missing_kinds` (no kind is
7369    /// missing). Dual of the empty-slice arm above; a regression that
7370    /// returned the full ALL vec regardless of population or inverted
7371    /// the presence direction surfaces HERE.
7372    #[test]
7373    fn condition_slice_missing_kinds_returns_empty_vec_on_saturated_slice() {
7374        let saturated: Vec<Condition> =
7375            ConditionKind::ALL.into_iter().map(condition_with).collect();
7376        assert_eq!(
7377            saturated.as_slice().missing_kinds(),
7378            Vec::<ConditionKind>::new(),
7379            "slice containing every ConditionKind must return empty vec on missing_kinds",
7380        );
7381    }
7382
7383    /// DEDUP pin — a slice with the SAME kind at multiple positions
7384    /// (three ClosedLoopAuth, two PromQL, none of the other six)
7385    /// returns those SIX absent kinds on `missing_kinds`, in canonical
7386    /// [`ConditionKind::ALL`] order — multiplicity on the present side
7387    /// is irrelevant to the complement. A regression that (a) counted
7388    /// duplicates as decreasing the missing set (a `saturating_sub`
7389    /// bug in a cardinality-tracking override), (b) yielded the
7390    /// missing set in slice-encounter order (which is undefined when
7391    /// no positions carry the missing kind — a subtle failure mode
7392    /// that must yield the ALL-ordered subsequence regardless)
7393    /// surfaces HERE.
7394    #[test]
7395    fn condition_slice_missing_kinds_yields_canonical_all_order_on_duplicates() {
7396        let interleaved = [
7397            Condition {
7398                kind: ConditionKind::ClosedLoopAuth,
7399                params: json!({ "probeImage": "first" }),
7400            },
7401            Condition {
7402                kind: ConditionKind::PromQL,
7403                params: json!({ "query": "up" }),
7404            },
7405            Condition {
7406                kind: ConditionKind::ClosedLoopAuth,
7407                params: json!({ "probeImage": "second" }),
7408            },
7409            Condition {
7410                kind: ConditionKind::PromQL,
7411                params: json!({ "query": "healthy" }),
7412            },
7413            Condition {
7414                kind: ConditionKind::ClosedLoopAuth,
7415                params: json!({ "probeImage": "third" }),
7416            },
7417        ];
7418        let expected: Vec<_> = ConditionKind::ALL
7419            .into_iter()
7420            .filter(|k| *k != ConditionKind::PromQL && *k != ConditionKind::ClosedLoopAuth)
7421            .collect();
7422        assert_eq!(
7423            interleaved.missing_kinds(),
7424            expected,
7425            "interleaved-duplicate slice must return canonical ALL-ordered complement of {{PromQL, ClosedLoopAuth}}",
7426        );
7427    }
7428
7429    // ── ConditionSliceExt::missing_kind_count — scalar cardinality pins ─
7430    //
7431    // Scalar-cardinality peer of the closed-set-complement widened
7432    // primitive `missing_kinds`: `missing_kind_count()` collapses the
7433    // set to its cardinality without allocating. The composition law
7434    // `missing_kind_count() == missing_kinds().len()` is pinned as the
7435    // scalar-cardinality-complement arm of
7436    // `assert_slice_refinement_composition_laws`. The three tests below
7437    // pin each authored arrangement's returned VALUE (empty, single-
7438    // populated, saturated) directly against `missing_kinds().len()`.
7439
7440    /// EMPTY-SLICE pin — an empty slice returns
7441    /// `ConditionKind::ALL.len()` on `missing_kind_count`, byte-for-byte
7442    /// with `missing_kinds().len()`. Locks the maximum-cardinality
7443    /// identity on the complement side; dual of the empty-slice arm on
7444    /// `distinct_kind_count` which returns `0`. A regression that
7445    /// forgot the negation, returned `0` (the distinct-kind-count
7446    /// identity on empty), or returned the wrong constant surfaces
7447    /// HERE.
7448    #[test]
7449    fn condition_slice_missing_kind_count_returns_full_closed_set_on_empty_slice() {
7450        let empty: &[Condition] = &[];
7451        assert_eq!(
7452            empty.missing_kind_count(),
7453            ConditionKind::ALL.len(),
7454            "empty slice must return ConditionKind::ALL.len() on missing_kind_count",
7455        );
7456        assert_eq!(
7457            empty.missing_kind_count(),
7458            empty.missing_kinds().len(),
7459            "empty slice missing_kind_count must equal missing_kinds().len()",
7460        );
7461    }
7462
7463    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
7464    /// the addressed kind returns `ConditionKind::ALL.len() - 1` on
7465    /// `missing_kind_count` (every OTHER kind is missing). Sweep
7466    /// [`ConditionKind::ALL`] so a regression that returned `0` (forgot
7467    /// to negate), `ConditionKind::ALL.len()` (forgot the populated
7468    /// kind), or a per-kind constant surfaces HERE.
7469    #[test]
7470    fn condition_slice_missing_kind_count_returns_all_minus_one_per_variant() {
7471        for populated in ConditionKind::ALL {
7472            let slice = [condition_with(populated)];
7473            assert_eq!(
7474                slice.missing_kind_count(),
7475                ConditionKind::ALL.len() - 1,
7476                "single-populated slice must return ConditionKind::ALL.len() - 1 on missing_kind_count for {populated:?}",
7477            );
7478            assert_eq!(
7479                slice.missing_kind_count(),
7480                slice.missing_kinds().len(),
7481                "single-populated missing_kind_count must equal missing_kinds().len() for {populated:?}",
7482            );
7483        }
7484    }
7485
7486    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7487    /// variant returns `0` on `missing_kind_count` (no kind is missing).
7488    /// Dual of the empty-slice arm above; a regression that returned
7489    /// `ConditionKind::ALL.len()` regardless of population or inverted
7490    /// the presence direction surfaces HERE.
7491    #[test]
7492    fn condition_slice_missing_kind_count_returns_zero_on_saturated_slice() {
7493        let saturated: Vec<Condition> =
7494            ConditionKind::ALL.into_iter().map(condition_with).collect();
7495        assert_eq!(
7496            saturated.as_slice().missing_kind_count(),
7497            0,
7498            "slice containing every ConditionKind must return 0 on missing_kind_count",
7499        );
7500        assert_eq!(
7501            saturated.as_slice().missing_kind_count(),
7502            saturated.as_slice().missing_kinds().len(),
7503            "saturated missing_kind_count must equal missing_kinds().len()",
7504        );
7505    }
7506
7507    // ── ConditionSliceExt::is_kind_saturated — Boolean saturation pins ─
7508    //
7509    // Short-circuiting Boolean saturation-endpoint peer of the closed-set-
7510    // complement widened + scalar primitives: `is_kind_saturated()`
7511    // returns `true` iff every ConditionKind::ALL variant appears at
7512    // least once in the slice, WITHOUT allocating `missing_kinds` or
7513    // walking every entry to build `missing_kind_count`. The composition
7514    // laws `is_kind_saturated() == (missing_kind_count() == 0)` and
7515    // `is_kind_saturated() == missing_kinds().is_empty()` are pinned as
7516    // the saturation-endpoint arm of
7517    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer of
7518    // `crate::tagged_union::TaggedUnion::is_saturated` one struct-layer
7519    // up under the SAME `<CLOSED_SET>::ALL.iter().all(has)` short-
7520    // circuit walk shape.
7521
7522    /// EMPTY-SLICE pin — an empty slice returns `false` on
7523    /// `is_kind_saturated` (every kind is missing).
7524    #[test]
7525    fn condition_slice_is_kind_saturated_returns_false_on_empty_slice() {
7526        let empty: &[Condition] = &[];
7527        assert!(
7528            !empty.is_kind_saturated(),
7529            "empty slice must return false on is_kind_saturated",
7530        );
7531        assert_eq!(
7532            empty.is_kind_saturated(),
7533            empty.missing_kind_count() == 0,
7534            "empty is_kind_saturated must equal (missing_kind_count() == 0)",
7535        );
7536    }
7537
7538    /// SINGLE-KIND pin — a slice populating exactly one variant returns
7539    /// `false` on any [`ConditionKind::ALL`] closed set with `N ≥ 2`
7540    /// (the other `N - 1` variants are missing).
7541    #[test]
7542    fn condition_slice_is_kind_saturated_returns_false_on_single_kind_slice() {
7543        assert!(
7544            ConditionKind::ALL.len() >= 2,
7545            "test assumes ConditionKind::ALL has ≥ 2 variants",
7546        );
7547        for populated in ConditionKind::ALL {
7548            let slice = [condition_with(populated)];
7549            assert!(
7550                !slice.is_kind_saturated(),
7551                "single-populated slice with {populated:?} must return false on is_kind_saturated",
7552            );
7553            assert_eq!(
7554                slice.is_kind_saturated(),
7555                slice.missing_kind_count() == 0,
7556                "single-populated is_kind_saturated must equal (missing_kind_count() == 0) for {populated:?}",
7557            );
7558        }
7559    }
7560
7561    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7562    /// variant returns `true` on `is_kind_saturated` — the SOLE arm
7563    /// where the primitive returns `true`.
7564    #[test]
7565    fn condition_slice_is_kind_saturated_returns_true_on_saturated_slice() {
7566        let saturated: Vec<Condition> =
7567            ConditionKind::ALL.into_iter().map(condition_with).collect();
7568        assert!(
7569            saturated.as_slice().is_kind_saturated(),
7570            "slice containing every ConditionKind must return true on is_kind_saturated",
7571        );
7572        assert_eq!(
7573            saturated.as_slice().is_kind_saturated(),
7574            saturated.as_slice().missing_kind_count() == 0,
7575            "saturated is_kind_saturated must equal (missing_kind_count() == 0)",
7576        );
7577        assert_eq!(
7578            saturated.as_slice().is_kind_saturated(),
7579            saturated.as_slice().missing_kinds().is_empty(),
7580            "saturated is_kind_saturated must equal missing_kinds().is_empty()",
7581        );
7582    }
7583
7584    /// DUPLICATE-COVERAGE pin — a slice that carries every
7585    /// [`ConditionKind`] variant multiple times still returns `true`
7586    /// (multiplicity is irrelevant to the saturation predicate on the
7587    /// closed-set-inversion axis).
7588    #[test]
7589    fn condition_slice_is_kind_saturated_ignores_multiplicity() {
7590        let mut doubled: Vec<Condition> = Vec::new();
7591        for k in ConditionKind::ALL {
7592            doubled.push(condition_with(k));
7593            doubled.push(condition_with(k));
7594        }
7595        assert!(
7596            doubled.as_slice().is_kind_saturated(),
7597            "slice carrying every ConditionKind twice must return true on is_kind_saturated",
7598        );
7599    }
7600
7601    // ── ConditionSliceExt::has_any_distinct_kind — at-least-one halfspace pins ──
7602    //
7603    // Boolean at-least-one halfspace peer of `has_any_missing_kind` on
7604    // the closed-set-inversion axis: `has_any_distinct_kind()` returns
7605    // `true` iff AT LEAST ONE `ConditionKind::ALL` variant appears at
7606    // least once in the slice, via a SHORT-CIRCUITING closed-set walk
7607    // `ConditionKind::ALL.iter().copied().any(|k| self.has_kind(k))`
7608    // that returns `true` at the FIRST populated kind. The composition
7609    // laws `has_any_distinct_kind() == (distinct_kind_count() > 0)`,
7610    // `has_any_distinct_kind() == !distinct_kinds().is_empty()`, and
7611    // `has_any_distinct_kind() == first_distinct_kind().is_some()` are
7612    // pinned as the at-least-one halfspace arm of
7613    // `assert_slice_refinement_composition_laws` on the closed-set-
7614    // inversion axis. Byte-for-byte peer of
7615    // `crate::tagged_union::TaggedUnion::has_any_populated_kind` one
7616    // struct-layer up under the SAME `any(has)` short-circuit shape.
7617
7618    /// EMPTY-SLICE pin — an empty slice returns `false` on
7619    /// `has_any_distinct_kind` (no kind is present) — the SOLE arm
7620    /// where the primitive returns `false`. Dual of the empty-slice
7621    /// arm on `has_any_missing_kind` (which returns `true`).
7622    #[test]
7623    fn condition_slice_has_any_distinct_kind_returns_false_on_empty_slice() {
7624        let empty: &[Condition] = &[];
7625        assert!(
7626            !empty.has_any_distinct_kind(),
7627            "empty slice must return false on has_any_distinct_kind",
7628        );
7629        assert_eq!(
7630            empty.has_any_distinct_kind(),
7631            empty.distinct_kind_count() > 0,
7632            "empty has_any_distinct_kind must equal (distinct_kind_count() > 0)",
7633        );
7634        assert_eq!(
7635            empty.has_any_distinct_kind(),
7636            !empty.distinct_kinds().is_empty(),
7637            "empty has_any_distinct_kind must equal !distinct_kinds().is_empty()",
7638        );
7639        assert_eq!(
7640            empty.has_any_distinct_kind(),
7641            empty.first_distinct_kind().is_some(),
7642            "empty has_any_distinct_kind must equal first_distinct_kind().is_some()",
7643        );
7644    }
7645
7646    /// SINGLE-KIND pin — a slice populating exactly one variant
7647    /// returns `true` on `has_any_distinct_kind` for every
7648    /// [`ConditionKind`] (a single element contributes one distinct
7649    /// kind, ≥ 1). Also pins the composition law
7650    /// `has_any_distinct_kind() == (distinct_kind_count() > 0)` at
7651    /// the single-populated arm.
7652    #[test]
7653    fn condition_slice_has_any_distinct_kind_returns_true_on_single_kind_slice() {
7654        for populated in ConditionKind::ALL {
7655            let slice = [condition_with(populated)];
7656            assert!(
7657                slice.has_any_distinct_kind(),
7658                "single-populated slice with {populated:?} must return true on has_any_distinct_kind",
7659            );
7660            assert_eq!(
7661                slice.has_any_distinct_kind(),
7662                slice.distinct_kind_count() > 0,
7663                "single-populated has_any_distinct_kind must equal (distinct_kind_count() > 0) for {populated:?}",
7664            );
7665        }
7666    }
7667
7668    /// FULL-COVERAGE pin — a slice that carries every
7669    /// [`ConditionKind`] variant returns `true` on
7670    /// `has_any_distinct_kind`. Dual of the FULL-COVERAGE arm on
7671    /// `has_any_missing_kind` (which returns `false`) — the two
7672    /// Booleans DISAGREE on the saturated arm.
7673    #[test]
7674    fn condition_slice_has_any_distinct_kind_returns_true_on_saturated_slice() {
7675        let saturated: Vec<Condition> =
7676            ConditionKind::ALL.into_iter().map(condition_with).collect();
7677        assert!(
7678            saturated.as_slice().has_any_distinct_kind(),
7679            "slice containing every ConditionKind must return true on has_any_distinct_kind",
7680        );
7681        assert_eq!(
7682            saturated.as_slice().has_any_distinct_kind(),
7683            !saturated.as_slice().distinct_kinds().is_empty(),
7684            "saturated has_any_distinct_kind must equal !distinct_kinds().is_empty()",
7685        );
7686    }
7687
7688    /// DUPLICATE-COVERAGE pin — a slice that carries the SAME
7689    /// [`ConditionKind`] multiple times still returns `true`
7690    /// (multiplicity is irrelevant to the at-least-one halfspace
7691    /// predicate on the closed-set-inversion axis, byte-for-byte peer
7692    /// of the closed-set-complement halfspace arm).
7693    #[test]
7694    fn condition_slice_has_any_distinct_kind_ignores_multiplicity() {
7695        for k in ConditionKind::ALL {
7696            let doubled: Vec<Condition> = vec![condition_with(k), condition_with(k)];
7697            assert!(
7698                doubled.as_slice().has_any_distinct_kind(),
7699                "slice carrying {k:?} twice must return true on has_any_distinct_kind",
7700            );
7701        }
7702    }
7703
7704    // ── ConditionSliceExt::has_any_missing_kind — at-least-one halfspace pins ──
7705    //
7706    // Boolean at-least-one halfspace peer of `is_kind_saturated`:
7707    // `has_any_missing_kind()` returns `true` iff AT LEAST ONE
7708    // `ConditionKind::ALL` variant appears zero times in the slice,
7709    // byte-for-byte with `!is_kind_saturated()` via the definitional
7710    // negation in the trait's default body. The composition laws
7711    // `has_any_missing_kind() == !is_kind_saturated()`,
7712    // `has_any_missing_kind() == (missing_kind_count() > 0)`, and
7713    // `has_any_missing_kind() == !missing_kinds().is_empty()` are
7714    // pinned as the at-least-one halfspace arm of
7715    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
7716    // of `crate::tagged_union::TaggedUnion::has_any_missing_kind` one
7717    // struct-layer up under the SAME `!is_saturated` definitional
7718    // negation shape.
7719
7720    /// EMPTY-SLICE pin — an empty slice returns `true` on
7721    /// `has_any_missing_kind` (every kind is missing, so at least one
7722    /// is). Dual of the empty-slice arm on `is_kind_saturated` (which
7723    /// returns `false`).
7724    #[test]
7725    fn condition_slice_has_any_missing_kind_returns_true_on_empty_slice() {
7726        let empty: &[Condition] = &[];
7727        assert!(
7728            empty.has_any_missing_kind(),
7729            "empty slice must return true on has_any_missing_kind",
7730        );
7731        assert_eq!(
7732            empty.has_any_missing_kind(),
7733            !empty.is_kind_saturated(),
7734            "empty has_any_missing_kind must equal !is_kind_saturated()",
7735        );
7736        assert_eq!(
7737            empty.has_any_missing_kind(),
7738            empty.missing_kind_count() > 0,
7739            "empty has_any_missing_kind must equal (missing_kind_count() > 0)",
7740        );
7741    }
7742
7743    /// SINGLE-KIND pin — a slice populating exactly one variant
7744    /// returns `true` on any `ConditionKind::ALL` closed set with
7745    /// `N ≥ 2` (the other `N - 1` variants are missing).
7746    #[test]
7747    fn condition_slice_has_any_missing_kind_returns_true_on_single_kind_slice() {
7748        assert!(
7749            ConditionKind::ALL.len() >= 2,
7750            "test assumes ConditionKind::ALL has ≥ 2 variants",
7751        );
7752        for populated in ConditionKind::ALL {
7753            let slice = [condition_with(populated)];
7754            assert!(
7755                slice.has_any_missing_kind(),
7756                "single-populated slice with {populated:?} must return true on has_any_missing_kind",
7757            );
7758            assert_eq!(
7759                slice.has_any_missing_kind(),
7760                !slice.is_kind_saturated(),
7761                "single-populated has_any_missing_kind must equal !is_kind_saturated() for {populated:?}",
7762            );
7763        }
7764    }
7765
7766    /// FULL-COVERAGE pin — a slice that carries every
7767    /// [`ConditionKind`] variant returns `false` on
7768    /// `has_any_missing_kind` — the SOLE arm where the primitive
7769    /// returns `false`, byte-for-byte peer of the SOLE arm on which
7770    /// `is_kind_saturated` returns `true`.
7771    #[test]
7772    fn condition_slice_has_any_missing_kind_returns_false_on_saturated_slice() {
7773        let saturated: Vec<Condition> =
7774            ConditionKind::ALL.into_iter().map(condition_with).collect();
7775        assert!(
7776            !saturated.as_slice().has_any_missing_kind(),
7777            "slice containing every ConditionKind must return false on has_any_missing_kind",
7778        );
7779        assert_eq!(
7780            saturated.as_slice().has_any_missing_kind(),
7781            !saturated.as_slice().is_kind_saturated(),
7782            "saturated has_any_missing_kind must equal !is_kind_saturated()",
7783        );
7784        assert_eq!(
7785            saturated.as_slice().has_any_missing_kind(),
7786            !saturated.as_slice().missing_kinds().is_empty(),
7787            "saturated has_any_missing_kind must equal !missing_kinds().is_empty()",
7788        );
7789    }
7790
7791    /// DUPLICATE-COVERAGE pin — a slice that carries every
7792    /// [`ConditionKind`] variant multiple times still returns `false`
7793    /// (multiplicity is irrelevant to the at-least-one halfspace
7794    /// predicate on the closed-set-complement axis, byte-for-byte peer
7795    /// of the saturation-predicate arm).
7796    #[test]
7797    fn condition_slice_has_any_missing_kind_ignores_multiplicity() {
7798        let mut doubled: Vec<Condition> = Vec::new();
7799        for k in ConditionKind::ALL {
7800            doubled.push(condition_with(k));
7801            doubled.push(condition_with(k));
7802        }
7803        assert!(
7804            !doubled.as_slice().has_any_missing_kind(),
7805            "slice carrying every ConditionKind twice must return false on has_any_missing_kind",
7806        );
7807    }
7808
7809    // ── ConditionSliceExt::has_unique_missing_kind — near-saturation-endpoint pins ─
7810    //
7811    // Boolean cardinality-mid-endpoint peer of `has_any_missing_kind`
7812    // on the closed-set-complement axis: `has_unique_missing_kind()`
7813    // returns `true` iff EXACTLY ONE ConditionKind::ALL variant
7814    // appears zero times in the slice. Default body is a two-step-
7815    // short-circuit walk over ConditionKind::ALL under a negated
7816    // `has_kind` predicate — pulls up to two hits off the filtered
7817    // iterator, returns `true` iff the first is Some and the second
7818    // is None. Short-circuits at the SECOND missing kind — strictly
7819    // cheaper than `missing_kind_count() == 1` (which walks every
7820    // slot) and `missing_kinds().len() == 1` (which allocates the
7821    // Vec) on every arm with ≥ 2 missing kinds. The composition laws
7822    // `has_unique_missing_kind() == (missing_kind_count() == 1)` and
7823    // `has_unique_missing_kind() == (missing_kinds().len() == 1)`
7824    // are pinned as the cardinality-mid-endpoint arm of
7825    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
7826    // of `crate::tagged_union::TaggedUnion::has_unique_missing_kind`
7827    // one struct-layer up under the SAME two-step short-circuit walk
7828    // shape.
7829
7830    /// EMPTY-SLICE pin — an empty slice returns `false` on
7831    /// `has_unique_missing_kind` on any `N ≥ 2` closed set (every
7832    /// kind is missing — the fully-missing endpoint, `N` missing not
7833    /// `1`).
7834    #[test]
7835    fn condition_slice_has_unique_missing_kind_returns_false_on_empty_slice() {
7836        assert!(
7837            ConditionKind::ALL.len() >= 2,
7838            "test assumes ConditionKind::ALL has ≥ 2 variants",
7839        );
7840        let empty: &[Condition] = &[];
7841        assert!(
7842            !empty.has_unique_missing_kind(),
7843            "empty slice must return false on has_unique_missing_kind (all N kinds missing, not exactly 1)",
7844        );
7845        assert_eq!(
7846            empty.has_unique_missing_kind(),
7847            empty.missing_kind_count() == 1,
7848            "empty has_unique_missing_kind must equal (missing_kind_count() == 1)",
7849        );
7850    }
7851
7852    /// SINGLE-KIND pin — a slice populating exactly one variant
7853    /// returns `false` on any `N ≥ 3` closed set (`N - 1 ≥ 2` kinds
7854    /// missing). On the degenerate `N == 2` closed set (which no
7855    /// production `ConditionKind` reaches; this workspace has
7856    /// `N == 8`) it would return `true`, so the pin gates on
7857    /// `N ≥ 3`.
7858    #[test]
7859    fn condition_slice_has_unique_missing_kind_returns_false_on_single_kind_slice() {
7860        if ConditionKind::ALL.len() < 3 {
7861            return;
7862        }
7863        for populated in ConditionKind::ALL {
7864            let slice = [condition_with(populated)];
7865            assert!(
7866                !slice.has_unique_missing_kind(),
7867                "single-populated slice with {populated:?} must return false on has_unique_missing_kind on N ≥ 3 closed sets ({} kinds missing, not exactly 1)",
7868                ConditionKind::ALL.len() - 1,
7869            );
7870            assert_eq!(
7871                slice.has_unique_missing_kind(),
7872                slice.missing_kind_count() == 1,
7873                "single-populated has_unique_missing_kind must equal (missing_kind_count() == 1) for {populated:?}",
7874            );
7875        }
7876    }
7877
7878    /// NEAR-SATURATION-ENDPOINT pin — a slice carrying every
7879    /// [`ConditionKind`] EXCEPT exactly one returns `true` on
7880    /// `has_unique_missing_kind`. Sweeps ConditionKind::ALL; each
7881    /// arrangement omits one variant and populates the other `N - 1`.
7882    /// This is the SOLE arrangement where the primitive returns
7883    /// `true`. Also pins the widened composition law
7884    /// `has_unique_missing_kind() == (missing_kinds().len() == 1)`.
7885    #[test]
7886    fn condition_slice_has_unique_missing_kind_returns_true_on_near_saturation_endpoint() {
7887        for omitted in ConditionKind::ALL {
7888            let near_saturated: Vec<Condition> = ConditionKind::ALL
7889                .into_iter()
7890                .filter(|k| *k != omitted)
7891                .map(condition_with)
7892                .collect();
7893            let slice = near_saturated.as_slice();
7894            assert!(
7895                slice.has_unique_missing_kind(),
7896                "near-saturation-endpoint slice (omitting {omitted:?}) must return true on has_unique_missing_kind",
7897            );
7898            assert_eq!(
7899                slice.has_unique_missing_kind(),
7900                slice.missing_kind_count() == 1,
7901                "near-saturation-endpoint has_unique_missing_kind must equal (missing_kind_count() == 1) for omitted={omitted:?}",
7902            );
7903            assert_eq!(
7904                slice.has_unique_missing_kind(),
7905                slice.missing_kinds().len() == 1,
7906                "near-saturation-endpoint has_unique_missing_kind must equal (missing_kinds().len() == 1) for omitted={omitted:?}",
7907            );
7908            assert_eq!(
7909                slice.first_missing_kind(),
7910                Some(omitted),
7911                "near-saturation-endpoint first_missing_kind must name the SOLE remaining hole for omitted={omitted:?}",
7912            );
7913        }
7914    }
7915
7916    /// SATURATED pin — a slice carrying every [`ConditionKind`]
7917    /// variant returns `false` on `has_unique_missing_kind` (zero
7918    /// missing, not exactly one). Dual of the SATURATED arm on
7919    /// `is_kind_saturated` which returns `true`. Also pins the
7920    /// composition law `has_unique_missing_kind() ==
7921    /// (missing_kind_count() == 1)` at zero-missing.
7922    #[test]
7923    fn condition_slice_has_unique_missing_kind_returns_false_on_saturated_slice() {
7924        let saturated: Vec<Condition> =
7925            ConditionKind::ALL.into_iter().map(condition_with).collect();
7926        assert!(
7927            !saturated.as_slice().has_unique_missing_kind(),
7928            "slice containing every ConditionKind must return false on has_unique_missing_kind (0 missing, not exactly 1)",
7929        );
7930        assert_eq!(
7931            saturated.as_slice().has_unique_missing_kind(),
7932            saturated.as_slice().missing_kind_count() == 1,
7933            "saturated has_unique_missing_kind must equal (missing_kind_count() == 1)",
7934        );
7935    }
7936
7937    /// TWO-MISSING pin — a slice populating exactly `N - 2` variants
7938    /// returns `false` on `has_unique_missing_kind` (2 missing, not
7939    /// exactly 1). Pins the SECOND-slot short-circuit boundary — a
7940    /// regression that dropped the second-slot check (returning `true`
7941    /// on any partial-populated arm) surfaces HERE. Only meaningful
7942    /// on `N ≥ 2` closed sets.
7943    #[test]
7944    fn condition_slice_has_unique_missing_kind_returns_false_on_two_missing_slice() {
7945        assert!(
7946            ConditionKind::ALL.len() >= 2,
7947            "test assumes ConditionKind::ALL has ≥ 2 variants",
7948        );
7949        for i in 0..ConditionKind::ALL.len() {
7950            for j in (i + 1)..ConditionKind::ALL.len() {
7951                let two_missing: Vec<Condition> = ConditionKind::ALL
7952                    .into_iter()
7953                    .enumerate()
7954                    .filter(|(k, _)| *k != i && *k != j)
7955                    .map(|(_, k)| condition_with(k))
7956                    .collect();
7957                let slice = two_missing.as_slice();
7958                assert!(
7959                    !slice.has_unique_missing_kind(),
7960                    "two-missing slice (omitting index {i} and {j}) must return false on has_unique_missing_kind (2 missing, not exactly 1)",
7961                );
7962                assert_eq!(
7963                    slice.has_unique_missing_kind(),
7964                    slice.missing_kind_count() == 1,
7965                    "two-missing has_unique_missing_kind must equal (missing_kind_count() == 1) for omitted=({i}, {j})",
7966                );
7967            }
7968        }
7969    }
7970
7971    /// MULTIPLICITY pin — a slice at the near-saturation-endpoint
7972    /// with each populated kind duplicated still returns `true`
7973    /// (multiplicity is irrelevant to the cardinality-mid-endpoint
7974    /// projection on the closed-set-complement axis, byte-for-byte
7975    /// peer of the saturation-predicate arm).
7976    #[test]
7977    fn condition_slice_has_unique_missing_kind_ignores_multiplicity() {
7978        for omitted in ConditionKind::ALL {
7979            let mut doubled: Vec<Condition> = Vec::new();
7980            for k in ConditionKind::ALL {
7981                if k != omitted {
7982                    doubled.push(condition_with(k));
7983                    doubled.push(condition_with(k));
7984                }
7985            }
7986            assert!(
7987                doubled.as_slice().has_unique_missing_kind(),
7988                "near-saturation-endpoint slice with each populated kind duplicated (omitting {omitted:?}) must return true on has_unique_missing_kind",
7989            );
7990        }
7991    }
7992
7993    // ── ConditionSliceExt::has_multiple_missing_kinds — many-arm pins ──
7994    //
7995    // Boolean cardinality "≥ 2" many-arm peer of
7996    // `has_unique_missing_kind` on the closed-set-complement axis:
7997    // `has_multiple_missing_kinds()` returns `true` iff AT LEAST TWO
7998    // `ConditionKind::ALL` variants appear zero times in the slice.
7999    // Third and final arm of the {0, 1, ≥2} trichotomy on the missing
8000    // axis at the slice level (0-arm: `is_kind_saturated`; 1-arm:
8001    // `has_unique_missing_kind`; ≥ 2-arm: this primitive). Body
8002    // short-circuits at the second missing kind — strictly cheaper
8003    // than `missing_kind_count() >= 2` (which walks every slot) and
8004    // `missing_kinds().len() >= 2` (which allocates the Vec) on every
8005    // arm with ≥ 2 missing kinds. The composition laws
8006    // `has_multiple_missing_kinds() == (missing_kind_count() >= 2)`
8007    // and `has_multiple_missing_kinds() == (missing_kinds().len() >= 2)`
8008    // are pinned as the cardinality-many-arm arm of
8009    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8010    // of `crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`
8011    // one struct-layer up under the SAME two-step short-circuit walk
8012    // shape.
8013
8014    /// EMPTY-SLICE pin — an empty slice returns `true` on
8015    /// `has_multiple_missing_kinds` on any `N ≥ 2` closed set (every
8016    /// kind is missing — the fully-missing endpoint, `N ≥ 2`
8017    /// missing).
8018    #[test]
8019    fn condition_slice_has_multiple_missing_kinds_returns_true_on_empty_slice() {
8020        assert!(
8021            ConditionKind::ALL.len() >= 2,
8022            "test assumes ConditionKind::ALL has ≥ 2 variants",
8023        );
8024        let empty: &[Condition] = &[];
8025        assert!(
8026            empty.has_multiple_missing_kinds(),
8027            "empty slice must return true on has_multiple_missing_kinds (all N ≥ 2 kinds missing)",
8028        );
8029        assert_eq!(
8030            empty.has_multiple_missing_kinds(),
8031            empty.missing_kind_count() >= 2,
8032            "empty has_multiple_missing_kinds must equal (missing_kind_count() >= 2)",
8033        );
8034    }
8035
8036    /// SINGLE-KIND pin — a slice populating exactly one variant
8037    /// returns `true` on any `N ≥ 3` closed set (`N - 1 ≥ 2` kinds
8038    /// missing). On the degenerate `N == 2` closed set (which no
8039    /// production `ConditionKind` reaches; this workspace has
8040    /// `N == 8`) it would return `false`, so the pin gates on
8041    /// `N ≥ 3`.
8042    #[test]
8043    fn condition_slice_has_multiple_missing_kinds_returns_true_on_single_kind_slice() {
8044        if ConditionKind::ALL.len() < 3 {
8045            return;
8046        }
8047        for populated in ConditionKind::ALL {
8048            let slice = [condition_with(populated)];
8049            assert!(
8050                slice.has_multiple_missing_kinds(),
8051                "single-populated slice with {populated:?} must return true on has_multiple_missing_kinds on N ≥ 3 closed sets ({} kinds missing, ≥ 2)",
8052                ConditionKind::ALL.len() - 1,
8053            );
8054            assert_eq!(
8055                slice.has_multiple_missing_kinds(),
8056                slice.missing_kind_count() >= 2,
8057                "single-populated has_multiple_missing_kinds must equal (missing_kind_count() >= 2) for {populated:?}",
8058            );
8059        }
8060    }
8061
8062    /// NEAR-SATURATION-ENDPOINT pin — a slice carrying every
8063    /// [`ConditionKind`] EXCEPT exactly one returns `false` on
8064    /// `has_multiple_missing_kinds` (exactly one missing, not ≥ 2).
8065    /// The SOLE-missing arrangement where the many-arm primitive
8066    /// returns `false` — the definitional boundary between the
8067    /// = 1 mid-endpoint and the ≥ 2 many-arm on the missing axis.
8068    /// Also pins the widened composition law
8069    /// `has_multiple_missing_kinds() == (missing_kinds().len() >= 2)`.
8070    #[test]
8071    fn condition_slice_has_multiple_missing_kinds_returns_false_on_near_saturation_endpoint() {
8072        for omitted in ConditionKind::ALL {
8073            let near_saturated: Vec<Condition> = ConditionKind::ALL
8074                .into_iter()
8075                .filter(|k| *k != omitted)
8076                .map(condition_with)
8077                .collect();
8078            let slice = near_saturated.as_slice();
8079            assert!(
8080                !slice.has_multiple_missing_kinds(),
8081                "near-saturation-endpoint slice (omitting {omitted:?}) must return false on has_multiple_missing_kinds (1 missing, not ≥ 2)",
8082            );
8083            assert_eq!(
8084                slice.has_multiple_missing_kinds(),
8085                slice.missing_kind_count() >= 2,
8086                "near-saturation-endpoint has_multiple_missing_kinds must equal (missing_kind_count() >= 2) for omitted={omitted:?}",
8087            );
8088            assert_eq!(
8089                slice.has_multiple_missing_kinds(),
8090                slice.missing_kinds().len() >= 2,
8091                "near-saturation-endpoint has_multiple_missing_kinds must equal (missing_kinds().len() >= 2) for omitted={omitted:?}",
8092            );
8093        }
8094    }
8095
8096    /// SATURATED pin — a slice carrying every [`ConditionKind`]
8097    /// variant returns `false` on `has_multiple_missing_kinds` (zero
8098    /// missing, not ≥ 2). Dual of the SATURATED arm on
8099    /// `is_kind_saturated` which returns `true`. Also pins the
8100    /// composition law `has_multiple_missing_kinds() ==
8101    /// (missing_kind_count() >= 2)` at zero-missing.
8102    #[test]
8103    fn condition_slice_has_multiple_missing_kinds_returns_false_on_saturated_slice() {
8104        let saturated: Vec<Condition> =
8105            ConditionKind::ALL.into_iter().map(condition_with).collect();
8106        assert!(
8107            !saturated.as_slice().has_multiple_missing_kinds(),
8108            "slice containing every ConditionKind must return false on has_multiple_missing_kinds (0 missing, not ≥ 2)",
8109        );
8110        assert_eq!(
8111            saturated.as_slice().has_multiple_missing_kinds(),
8112            saturated.as_slice().missing_kind_count() >= 2,
8113            "saturated has_multiple_missing_kinds must equal (missing_kind_count() >= 2)",
8114        );
8115    }
8116
8117    /// TWO-MISSING pin — a slice populating exactly `N - 2` variants
8118    /// returns `true` on `has_multiple_missing_kinds` (exactly 2
8119    /// missing, the SECOND-slot boundary of the ≥ 2 arm). Pins the
8120    /// second-slot short-circuit — a regression that dropped the
8121    /// second-slot check (returning `true` on any ≥ 1-missing arm,
8122    /// conflating with `has_any_missing_kind`) would still pass here,
8123    /// so this pin is complemented by the NEAR-SATURATION-ENDPOINT
8124    /// pin which distinguishes the =1 arm from the ≥ 2 arm.
8125    /// Only meaningful on `N ≥ 2` closed sets.
8126    #[test]
8127    fn condition_slice_has_multiple_missing_kinds_returns_true_on_two_missing_slice() {
8128        assert!(
8129            ConditionKind::ALL.len() >= 2,
8130            "test assumes ConditionKind::ALL has ≥ 2 variants",
8131        );
8132        for i in 0..ConditionKind::ALL.len() {
8133            for j in (i + 1)..ConditionKind::ALL.len() {
8134                let two_missing: Vec<Condition> = ConditionKind::ALL
8135                    .into_iter()
8136                    .enumerate()
8137                    .filter(|(k, _)| *k != i && *k != j)
8138                    .map(|(_, k)| condition_with(k))
8139                    .collect();
8140                let slice = two_missing.as_slice();
8141                assert!(
8142                    slice.has_multiple_missing_kinds(),
8143                    "two-missing slice (omitting index {i} and {j}) must return true on has_multiple_missing_kinds (2 missing, ≥ 2)",
8144                );
8145                assert_eq!(
8146                    slice.has_multiple_missing_kinds(),
8147                    slice.missing_kind_count() >= 2,
8148                    "two-missing has_multiple_missing_kinds must equal (missing_kind_count() >= 2) for omitted=({i}, {j})",
8149                );
8150            }
8151        }
8152    }
8153
8154    /// MULTIPLICITY pin — a slice at the empty-endpoint duplicated
8155    /// remains empty (nothing to duplicate), while a slice at a
8156    /// K-populated arm with each populated kind duplicated still
8157    /// returns `true` on any `N ≥ K + 2` — multiplicity is
8158    /// irrelevant to the cardinality many-arm projection on the
8159    /// closed-set-complement axis, byte-for-byte peer of the
8160    /// saturation-predicate arm. Sweeps the near-two-missing
8161    /// arrangement (each pair-omitted arm, doubled populated) on
8162    /// `N ≥ 2` closed sets.
8163    #[test]
8164    fn condition_slice_has_multiple_missing_kinds_ignores_multiplicity() {
8165        assert!(
8166            ConditionKind::ALL.len() >= 2,
8167            "test assumes ConditionKind::ALL has ≥ 2 variants",
8168        );
8169        for i in 0..ConditionKind::ALL.len() {
8170            for j in (i + 1)..ConditionKind::ALL.len() {
8171                let mut doubled: Vec<Condition> = Vec::new();
8172                for (idx, kind) in ConditionKind::ALL.into_iter().enumerate() {
8173                    if idx != i && idx != j {
8174                        doubled.push(condition_with(kind));
8175                        doubled.push(condition_with(kind));
8176                    }
8177                }
8178                assert!(
8179                    doubled.as_slice().has_multiple_missing_kinds(),
8180                    "two-missing slice (omitting index {i} and {j}) with each populated kind duplicated must return true on has_multiple_missing_kinds",
8181                );
8182            }
8183        }
8184    }
8185
8186    // ── ConditionSliceExt::has_at_most_one_missing_kind — "≤ 1" pins ─
8187    //
8188    // Boolean cardinality "≤ 1" negation peer of
8189    // `has_multiple_missing_kinds` on the closed-set-complement axis:
8190    // `has_at_most_one_missing_kind()` returns `true` iff AT MOST ONE
8191    // `ConditionKind::ALL` variant appears zero times in the slice.
8192    // Definitional negation of the many-arm primitive
8193    // (`!has_multiple_missing_kinds`), and trichotomy-union of the
8194    // zero-arm + one-arm primitives (`is_kind_saturated ||
8195    // has_unique_missing_kind`). Body short-circuits transitively
8196    // through the many-arm walk — strictly cheaper than
8197    // `missing_kind_count() <= 1` (which walks every slot) and
8198    // `missing_kinds().len() <= 1` (which allocates the Vec) on every
8199    // arm. The composition laws
8200    // `has_at_most_one_missing_kind() == !has_multiple_missing_kinds()`,
8201    // `has_at_most_one_missing_kind() == (missing_kind_count() <= 1)`,
8202    // `has_at_most_one_missing_kind() == (missing_kinds().len() <= 1)`,
8203    // and `has_at_most_one_missing_kind() == is_kind_saturated() ||
8204    // has_unique_missing_kind()` are pinned as the "≤ 1" arm of
8205    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8206    // of `crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`
8207    // one struct-layer up under the SAME `!has_multiple_missing_kinds`
8208    // definitional negation shape.
8209
8210    /// EMPTY-SLICE pin — an empty slice returns `false` on
8211    /// `has_at_most_one_missing_kind` on any `N ≥ 2` closed set
8212    /// (every kind is missing — `N ≥ 2` missing, not `≤ 1`). Dual of
8213    /// the empty-slice arm on `has_multiple_missing_kinds` which
8214    /// returns `true`.
8215    #[test]
8216    fn condition_slice_has_at_most_one_missing_kind_returns_false_on_empty_slice() {
8217        assert!(
8218            ConditionKind::ALL.len() >= 2,
8219            "test assumes ConditionKind::ALL has ≥ 2 variants",
8220        );
8221        let empty: &[Condition] = &[];
8222        assert!(
8223            !empty.has_at_most_one_missing_kind(),
8224            "empty slice must return false on has_at_most_one_missing_kind (all N ≥ 2 kinds missing, not ≤ 1)",
8225        );
8226        assert_eq!(
8227            empty.has_at_most_one_missing_kind(),
8228            empty.missing_kind_count() <= 1,
8229            "empty has_at_most_one_missing_kind must equal (missing_kind_count() <= 1)",
8230        );
8231    }
8232
8233    /// SINGLE-KIND pin — a slice populating exactly one variant
8234    /// returns `false` on any `N ≥ 3` closed set (`N - 1 ≥ 2` kinds
8235    /// missing, not `≤ 1`). On the degenerate `N == 2` closed set it
8236    /// would return `true` (exactly 1 missing), so the pin gates on
8237    /// `N ≥ 3` — this workspace has `N == 8`.
8238    #[test]
8239    fn condition_slice_has_at_most_one_missing_kind_returns_false_on_single_kind_slice() {
8240        if ConditionKind::ALL.len() < 3 {
8241            return;
8242        }
8243        for populated in ConditionKind::ALL {
8244            let slice = [condition_with(populated)];
8245            assert!(
8246                !slice.has_at_most_one_missing_kind(),
8247                "single-populated slice with {populated:?} must return false on has_at_most_one_missing_kind on N ≥ 3 closed sets ({} kinds missing, not ≤ 1)",
8248                ConditionKind::ALL.len() - 1,
8249            );
8250            assert_eq!(
8251                slice.has_at_most_one_missing_kind(),
8252                slice.missing_kind_count() <= 1,
8253                "single-populated has_at_most_one_missing_kind must equal (missing_kind_count() <= 1) for {populated:?}",
8254            );
8255        }
8256    }
8257
8258    /// NEAR-SATURATION-ENDPOINT pin — a slice carrying every
8259    /// [`ConditionKind`] EXCEPT exactly one returns `true` on
8260    /// `has_at_most_one_missing_kind` (exactly 1 missing, `≤ 1`).
8261    /// The `= 1` mid-endpoint arm of the trichotomy union — one of
8262    /// the two arrangement classes where the "≤ 1" primitive
8263    /// returns `true`. Also pins the widened composition laws
8264    /// `has_at_most_one_missing_kind() == (missing_kinds().len() <= 1)`
8265    /// and `has_at_most_one_missing_kind() == !has_multiple_missing_kinds()`
8266    /// and the trichotomy-union composition law
8267    /// `has_at_most_one_missing_kind() == is_kind_saturated() ||
8268    /// has_unique_missing_kind()`.
8269    #[test]
8270    fn condition_slice_has_at_most_one_missing_kind_returns_true_on_near_saturation_endpoint() {
8271        for omitted in ConditionKind::ALL {
8272            let near_saturated: Vec<Condition> = ConditionKind::ALL
8273                .into_iter()
8274                .filter(|k| *k != omitted)
8275                .map(condition_with)
8276                .collect();
8277            let slice = near_saturated.as_slice();
8278            assert!(
8279                slice.has_at_most_one_missing_kind(),
8280                "near-saturation-endpoint slice (omitting {omitted:?}) must return true on has_at_most_one_missing_kind (1 missing, ≤ 1)",
8281            );
8282            assert_eq!(
8283                slice.has_at_most_one_missing_kind(),
8284                !slice.has_multiple_missing_kinds(),
8285                "near-saturation-endpoint has_at_most_one_missing_kind must equal !has_multiple_missing_kinds() for omitted={omitted:?}",
8286            );
8287            assert_eq!(
8288                slice.has_at_most_one_missing_kind(),
8289                slice.missing_kind_count() <= 1,
8290                "near-saturation-endpoint has_at_most_one_missing_kind must equal (missing_kind_count() <= 1) for omitted={omitted:?}",
8291            );
8292            assert_eq!(
8293                slice.has_at_most_one_missing_kind(),
8294                slice.missing_kinds().len() <= 1,
8295                "near-saturation-endpoint has_at_most_one_missing_kind must equal (missing_kinds().len() <= 1) for omitted={omitted:?}",
8296            );
8297            assert_eq!(
8298                slice.has_at_most_one_missing_kind(),
8299                slice.is_kind_saturated() || slice.has_unique_missing_kind(),
8300                "near-saturation-endpoint has_at_most_one_missing_kind must equal (is_kind_saturated() || has_unique_missing_kind()) for omitted={omitted:?}",
8301            );
8302        }
8303    }
8304
8305    /// SATURATED pin — a slice carrying every [`ConditionKind`]
8306    /// variant returns `true` on `has_at_most_one_missing_kind` (0
8307    /// missing, `≤ 1`). The `= 0` zero-arm of the trichotomy union
8308    /// — the OTHER arrangement class where the "≤ 1" primitive
8309    /// returns `true`. Dual of the SATURATED arm on
8310    /// `has_multiple_missing_kinds` which returns `false`.
8311    #[test]
8312    fn condition_slice_has_at_most_one_missing_kind_returns_true_on_saturated_slice() {
8313        let saturated: Vec<Condition> =
8314            ConditionKind::ALL.into_iter().map(condition_with).collect();
8315        assert!(
8316            saturated.as_slice().has_at_most_one_missing_kind(),
8317            "slice containing every ConditionKind must return true on has_at_most_one_missing_kind (0 missing, ≤ 1)",
8318        );
8319        assert_eq!(
8320            saturated.as_slice().has_at_most_one_missing_kind(),
8321            saturated.as_slice().missing_kind_count() <= 1,
8322            "saturated has_at_most_one_missing_kind must equal (missing_kind_count() <= 1)",
8323        );
8324        assert_eq!(
8325            saturated.as_slice().has_at_most_one_missing_kind(),
8326            saturated.as_slice().is_kind_saturated()
8327                || saturated.as_slice().has_unique_missing_kind(),
8328            "saturated has_at_most_one_missing_kind must equal (is_kind_saturated() || has_unique_missing_kind())",
8329        );
8330    }
8331
8332    /// TWO-MISSING pin — a slice populating exactly `N - 2` variants
8333    /// returns `false` on `has_at_most_one_missing_kind` (exactly 2
8334    /// missing, not `≤ 1`). The SECOND-slot boundary between the
8335    /// "≤ 1" arm and the "≥ 2" arm — a regression that dropped the
8336    /// negation (returning `has_multiple_missing_kinds` itself),
8337    /// swapped the wrong side, or drifted the trichotomy union
8338    /// operator from `||` to `&&` surfaces HERE.
8339    #[test]
8340    fn condition_slice_has_at_most_one_missing_kind_returns_false_on_two_missing_slice() {
8341        assert!(
8342            ConditionKind::ALL.len() >= 2,
8343            "test assumes ConditionKind::ALL has ≥ 2 variants",
8344        );
8345        for i in 0..ConditionKind::ALL.len() {
8346            for j in (i + 1)..ConditionKind::ALL.len() {
8347                let two_missing: Vec<Condition> = ConditionKind::ALL
8348                    .into_iter()
8349                    .enumerate()
8350                    .filter(|(k, _)| *k != i && *k != j)
8351                    .map(|(_, k)| condition_with(k))
8352                    .collect();
8353                let slice = two_missing.as_slice();
8354                assert!(
8355                    !slice.has_at_most_one_missing_kind(),
8356                    "two-missing slice (omitting index {i} and {j}) must return false on has_at_most_one_missing_kind (2 missing, not ≤ 1)",
8357                );
8358                assert_eq!(
8359                    slice.has_at_most_one_missing_kind(),
8360                    slice.missing_kind_count() <= 1,
8361                    "two-missing has_at_most_one_missing_kind must equal (missing_kind_count() <= 1) for omitted=({i}, {j})",
8362                );
8363            }
8364        }
8365    }
8366
8367    /// MULTIPLICITY pin — a slice at a K-populated arm with each
8368    /// populated kind duplicated still returns the same "≤ 1"
8369    /// Boolean as its single-copy peer — multiplicity is irrelevant
8370    /// to the cardinality "≤ 1" projection on the closed-set-
8371    /// complement axis, byte-for-byte peer of
8372    /// `has_multiple_missing_kinds`'s multiplicity behavior.
8373    #[test]
8374    fn condition_slice_has_at_most_one_missing_kind_ignores_multiplicity() {
8375        // Near-saturation arm doubled — every populated kind
8376        // doubled, exactly one variant omitted; still returns true.
8377        for omitted in ConditionKind::ALL {
8378            let mut doubled: Vec<Condition> = Vec::new();
8379            for k in ConditionKind::ALL {
8380                if k != omitted {
8381                    doubled.push(condition_with(k));
8382                    doubled.push(condition_with(k));
8383                }
8384            }
8385            assert!(
8386                doubled.as_slice().has_at_most_one_missing_kind(),
8387                "near-saturation slice (omitting {omitted:?}) with each populated kind duplicated must return true on has_at_most_one_missing_kind",
8388            );
8389        }
8390    }
8391
8392    // ── ConditionSliceExt::lacks_kind — per-kind complement pins ──────
8393    //
8394    // Boolean per-kind closed-set-complement peer of `has_kind`:
8395    // `lacks_kind(k)` returns `true` iff NO Condition in the slice
8396    // carries the addressed kind, byte-for-byte with `!has_kind(k)`
8397    // via the definitional negation in the trait's default body.
8398    // The composition laws `lacks_kind(k) == !has_kind(k)` and
8399    // `lacks_kind(k) == missing_kinds().contains(&k)` are pinned as
8400    // the per-kind-complement arm of
8401    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8402    // of `crate::tagged_union::TaggedUnion::lacks` one struct-layer up
8403    // under the SAME `!has(kind)` definitional negation shape.
8404
8405    /// EMPTY-SLICE pin — an empty slice returns `true` for every
8406    /// [`ConditionKind`] on `lacks_kind` (no kind appears, so every
8407    /// kind is lacked). Dual of the empty-slice arm on `has_kind`
8408    /// (which returns `false` for every kind). Sweeps
8409    /// [`ConditionKind::ALL`] so a regression that dropped the
8410    /// negation, returned `false` (the has-kind identity on empty),
8411    /// or drifted to a per-kind constant surfaces HERE.
8412    #[test]
8413    fn condition_slice_lacks_kind_returns_true_on_empty_slice_for_every_kind() {
8414        let empty: &[Condition] = &[];
8415        for kind in ConditionKind::ALL {
8416            assert!(
8417                empty.lacks_kind(kind),
8418                "empty slice must return true on lacks_kind for {kind:?}",
8419            );
8420            assert_eq!(
8421                empty.lacks_kind(kind),
8422                !empty.has_kind(kind),
8423                "empty lacks_kind must equal !has_kind for {kind:?}",
8424            );
8425        }
8426    }
8427
8428    /// SINGLE-KIND pin — a slice with EXACTLY ONE `Condition` carrying
8429    /// the addressed kind returns `false` on `lacks_kind` for the
8430    /// populated kind and `true` for every OTHER kind. Sweeps
8431    /// [`ConditionKind::ALL`] × [`ConditionKind::ALL`] so a regression
8432    /// that swapped the wrong side, drifted the negation, or drifted
8433    /// the walk from `has_kind` surfaces HERE. Also pins the
8434    /// composition law `lacks_kind(k) == !has_kind(k)` per-kind.
8435    #[test]
8436    fn condition_slice_lacks_kind_returns_true_on_every_missing_kind() {
8437        for populated in ConditionKind::ALL {
8438            let slice = [condition_with(populated)];
8439            for probe in ConditionKind::ALL {
8440                let expected_lacks = probe != populated;
8441                assert_eq!(
8442                    slice.as_slice().lacks_kind(probe),
8443                    expected_lacks,
8444                    "single-populated slice with {populated:?} must return {expected_lacks} on lacks_kind({probe:?})",
8445                );
8446                assert_eq!(
8447                    slice.as_slice().lacks_kind(probe),
8448                    !slice.as_slice().has_kind(probe),
8449                    "single-populated lacks_kind({probe:?}) must equal !has_kind({probe:?}) for populated={populated:?}",
8450                );
8451            }
8452        }
8453    }
8454
8455    /// SATURATED pin — a slice carrying every [`ConditionKind`] variant
8456    /// returns `false` on `lacks_kind` for every arm (the SOLE
8457    /// arrangement where the primitive returns `false` for every kind).
8458    /// Dual of the SATURATED arm on `is_kind_saturated` which returns
8459    /// `true`. Pins the composition law `lacks_kind(k) ==
8460    /// missing_kinds().contains(&k)` per-kind against the empty missing
8461    /// set.
8462    #[test]
8463    fn condition_slice_lacks_kind_returns_false_on_saturated_slice_for_every_kind() {
8464        let saturated: Vec<Condition> =
8465            ConditionKind::ALL.into_iter().map(condition_with).collect();
8466        let missing = saturated.as_slice().missing_kinds();
8467        for kind in ConditionKind::ALL {
8468            assert!(
8469                !saturated.as_slice().lacks_kind(kind),
8470                "saturated slice must return false on lacks_kind for {kind:?}",
8471            );
8472            assert_eq!(
8473                saturated.as_slice().lacks_kind(kind),
8474                missing.contains(&kind),
8475                "saturated lacks_kind({kind:?}) must equal missing_kinds().contains(&{kind:?})",
8476            );
8477        }
8478    }
8479
8480    /// MULTIPLICITY pin — a slice carrying the addressed kind multiple
8481    /// times still returns `false` on `lacks_kind` for that kind
8482    /// (multiplicity is irrelevant to the per-kind Boolean-complement
8483    /// projection on the closed-set-complement axis, byte-for-byte
8484    /// with `has_kind`'s multiplicity behavior).
8485    #[test]
8486    fn condition_slice_lacks_kind_ignores_multiplicity_on_the_populated_side() {
8487        for populated in ConditionKind::ALL {
8488            let slice = [
8489                condition_with(populated),
8490                condition_with(populated),
8491                condition_with(populated),
8492            ];
8493            assert!(
8494                !slice.as_slice().lacks_kind(populated),
8495                "duplicate-populated slice with {populated:?} must return false on lacks_kind for {populated:?}",
8496            );
8497        }
8498    }
8499
8500    // ── ConditionSliceExt::has_only_kind — kind-scoped strict-refinement pins ─
8501    //
8502    // Boolean `(kind, "AND no other kind")` refinement of the closed-
8503    // set-inversion widened primitive `distinct_kinds`:
8504    // `has_only_kind(k)` returns `true` iff `k` is the SOLE distinct
8505    // populated kind AND appears at least once. Fused-walk over
8506    // `ConditionKind::ALL` under `has_kind` — strictly cheaper than
8507    // reaching for either `has_kind(k) && distinct_kind_count() == 1`
8508    // or `distinct_kinds() == vec![k]` composition on every arm where
8509    // a second kind lives alongside `k`. The composition law
8510    // `has_only_kind(k) == (distinct_kinds() == vec![k])` is pinned
8511    // as the kind-scoped strict-refinement arm of
8512    // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8513    // of `crate::tagged_union::TaggedUnion::has_only` one struct-layer
8514    // up under the SAME fused short-circuit closed-set walk shape.
8515
8516    /// EMPTY-SLICE pin — an empty slice returns `false` on
8517    /// `has_only_kind` for every arm (no kind is populated, so no
8518    /// kind is "only"). Pins the composition law `has_only_kind(k)
8519    /// == (distinct_kinds() == vec![k])` on the zero-distinct
8520    /// arrangement's empty distinct-set: `[] != vec![k]` for every k,
8521    /// so both sides yield `false`.
8522    #[test]
8523    fn condition_slice_has_only_kind_returns_false_on_empty_slice() {
8524        let empty: &[Condition] = &[];
8525        for kind in ConditionKind::ALL {
8526            assert!(
8527                !empty.has_only_kind(kind),
8528                "empty slice must return false on has_only_kind for {kind:?}",
8529            );
8530            assert_eq!(
8531                empty.has_only_kind(kind),
8532                empty.distinct_kinds() == vec![kind],
8533                "empty has_only_kind({kind:?}) must equal (distinct_kinds() == vec![{kind:?}])",
8534            );
8535        }
8536    }
8537
8538    /// SINGLE-KIND pin — a slice with EXACTLY ONE `Condition` carrying
8539    /// the addressed kind returns `true` on `has_only_kind` for the
8540    /// populated kind and `false` for every OTHER kind. Sweeps
8541    /// [`ConditionKind::ALL`] × [`ConditionKind::ALL`] so a regression
8542    /// that swapped the wrong side, drifted the fused walk, or
8543    /// confused the strict-refinement axis with the point-probe axis
8544    /// (returning `has_kind` — TOO LOOSE) surfaces HERE. Also pins the
8545    /// composition law `has_only_kind(k) == (distinct_kinds() ==
8546    /// vec![k])` per-kind against the singleton distinct-set.
8547    #[test]
8548    fn condition_slice_has_only_kind_returns_true_on_single_populated_kind() {
8549        for populated in ConditionKind::ALL {
8550            let slice = [condition_with(populated)];
8551            for probe in ConditionKind::ALL {
8552                let expected = probe == populated;
8553                assert_eq!(
8554                    slice.as_slice().has_only_kind(probe),
8555                    expected,
8556                    "single-populated slice with {populated:?} must return {expected} on has_only_kind({probe:?})",
8557                );
8558                assert_eq!(
8559                    slice.as_slice().has_only_kind(probe),
8560                    slice.as_slice().distinct_kinds() == vec![probe],
8561                    "single-populated has_only_kind({probe:?}) must equal (distinct_kinds() == vec![{probe:?}]) for populated={populated:?}",
8562                );
8563            }
8564        }
8565    }
8566
8567    /// MULTIPLICITY pin — a slice carrying the addressed kind multiple
8568    /// times still returns `true` on `has_only_kind` for that kind
8569    /// (multiplicity is irrelevant to the kind-scoped strict-
8570    /// refinement projection on the closed-set-inversion axis, byte-
8571    /// for-byte with `has_kind`'s multiplicity behavior). Pins that
8572    /// the fused walk under `has_kind` inherits the multiplicity-blind
8573    /// semantics without a special-case on the count.
8574    #[test]
8575    fn condition_slice_has_only_kind_ignores_multiplicity_on_the_populated_side() {
8576        for populated in ConditionKind::ALL {
8577            let slice = [
8578                condition_with(populated),
8579                condition_with(populated),
8580                condition_with(populated),
8581            ];
8582            for probe in ConditionKind::ALL {
8583                let expected = probe == populated;
8584                assert_eq!(
8585                    slice.as_slice().has_only_kind(probe),
8586                    expected,
8587                    "duplicate-populated slice with {populated:?} must return {expected} on has_only_kind({probe:?})",
8588                );
8589            }
8590        }
8591    }
8592
8593    /// TWO-KINDS pin — a slice carrying two DIFFERENT kinds returns
8594    /// `false` on `has_only_kind` for EVERY arm (the "some other kind
8595    /// is present" clause fails at the fused walk's earliest step
8596    /// that hits the second kind, regardless of which kind is
8597    /// addressed). Sweeps [`ConditionKind::ALL`] × [`ConditionKind::ALL`]
8598    /// (skipping equal pairs since a two-distinct-kinds slice requires
8599    /// `p != q`) so a regression that dropped the fused walk's early-
8600    /// exit surfaces at every off-diagonal (p, q) pair.
8601    #[test]
8602    fn condition_slice_has_only_kind_returns_false_on_two_kinds_slice() {
8603        for p in ConditionKind::ALL {
8604            for q in ConditionKind::ALL {
8605                if p == q {
8606                    continue;
8607                }
8608                let slice = [condition_with(p), condition_with(q)];
8609                for probe in ConditionKind::ALL {
8610                    assert!(
8611                        !slice.as_slice().has_only_kind(probe),
8612                        "two-kinds slice with {{{p:?}, {q:?}}} must return false on has_only_kind for {probe:?}",
8613                    );
8614                }
8615            }
8616        }
8617    }
8618
8619    /// SATURATED pin — a slice carrying every [`ConditionKind`] variant
8620    /// returns `false` on `has_only_kind` for every arm (N distinct
8621    /// kinds populate, so no single kind is "only"). Dual of the
8622    /// SATURATED arm on `is_kind_saturated` which returns `true` for
8623    /// the SAME arrangement. Pins the composition law `has_only_kind(k)
8624    /// == (has_kind(k) && distinct_kind_count() == 1)` per-kind against
8625    /// the saturated `distinct_kind_count() == N`.
8626    #[test]
8627    fn condition_slice_has_only_kind_returns_false_on_saturated_slice() {
8628        let saturated: Vec<Condition> =
8629            ConditionKind::ALL.into_iter().map(condition_with).collect();
8630        for kind in ConditionKind::ALL {
8631            assert!(
8632                !saturated.as_slice().has_only_kind(kind),
8633                "saturated slice must return false on has_only_kind for {kind:?}",
8634            );
8635            assert_eq!(
8636                saturated.as_slice().has_only_kind(kind),
8637                saturated.as_slice().has_kind(kind)
8638                    && saturated.as_slice().distinct_kind_count() == 1,
8639                "saturated has_only_kind({kind:?}) must equal (has_kind && distinct_kind_count == 1)",
8640            );
8641        }
8642    }
8643
8644    // ── ConditionSliceExt::lacks_only_kind — kind-scoped strict-
8645    // refinement on the closed-set-complement (missing) axis ─
8646    //
8647    // Byte-for-byte peer of `has_only_kind` under complement: fused
8648    // short-circuit walk over `ConditionKind::ALL` under `has_kind`
8649    // that skips populated slots, returns `false` at the earliest
8650    // missing slot whose kind is NOT `kind`, and returns `true` iff
8651    // the sweep completes with `kind` seen as the sole missing slot.
8652    // The composition laws
8653    // `lacks_only_kind(k) == (missing_kinds() == vec![k])` and
8654    // `lacks_only_kind(k) == (lacks_kind(k) && missing_kind_count() == 1)`
8655    // are pinned as the closed-set-complement kind-scoped strict-
8656    // refinement arms of `assert_slice_refinement_composition_laws`.
8657
8658    /// EMPTY-SLICE pin — every kind is missing (missing set == ALL),
8659    /// so no kind is "only" missing on any `N ≥ 2` closed set. Returns
8660    /// `false` on every arm.
8661    #[test]
8662    fn condition_slice_lacks_only_kind_returns_false_on_empty_slice() {
8663        let empty: &[Condition] = &[];
8664        for kind in ConditionKind::ALL {
8665            assert!(
8666                !empty.lacks_only_kind(kind),
8667                "empty slice must return false on lacks_only_kind for {kind:?}",
8668            );
8669            assert_eq!(
8670                empty.lacks_only_kind(kind),
8671                empty.missing_kinds() == vec![kind],
8672                "empty lacks_only_kind({kind:?}) must equal (missing_kinds() == vec![{kind:?}])",
8673            );
8674        }
8675    }
8676
8677    /// NEAR-SATURATION pin — a slice covering every kind except one
8678    /// returns `true` on `lacks_only_kind(omitted)` and `false` on
8679    /// every other kind. The sole `true` arm on the well-formed
8680    /// missing diagonal.
8681    #[test]
8682    fn condition_slice_lacks_only_kind_returns_true_on_near_saturation_slice() {
8683        for omitted in ConditionKind::ALL {
8684            let slice: Vec<Condition> = ConditionKind::ALL
8685                .into_iter()
8686                .filter(|k| *k != omitted)
8687                .map(condition_with)
8688                .collect();
8689            for kind in ConditionKind::ALL {
8690                let expected = kind == omitted;
8691                assert_eq!(
8692                    slice.as_slice().lacks_only_kind(kind),
8693                    expected,
8694                    "near-saturation slice omitted={omitted:?} must return {expected} on lacks_only_kind for {kind:?}",
8695                );
8696                assert_eq!(
8697                    slice.as_slice().lacks_only_kind(kind),
8698                    slice.as_slice().missing_kinds() == vec![kind],
8699                    "near-saturation lacks_only_kind({kind:?}) must equal (missing_kinds() == vec![{kind:?}]) for omitted={omitted:?}",
8700                );
8701            }
8702        }
8703    }
8704
8705    /// MULTIPLICITY pin — a slice carrying every kind except one, with
8706    /// the populated kinds each duplicated, ignores multiplicity on
8707    /// the populated side (byte-for-byte with `has_kind`'s multiplicity
8708    /// behavior). Returns `true` on `lacks_only_kind(omitted)`.
8709    #[test]
8710    fn condition_slice_lacks_only_kind_ignores_multiplicity_on_the_populated_side() {
8711        for omitted in ConditionKind::ALL {
8712            let mut slice: Vec<Condition> = Vec::new();
8713            for k in ConditionKind::ALL {
8714                if k != omitted {
8715                    slice.push(condition_with(k));
8716                    slice.push(condition_with(k));
8717                }
8718            }
8719            for kind in ConditionKind::ALL {
8720                let expected = kind == omitted;
8721                assert_eq!(
8722                    slice.as_slice().lacks_only_kind(kind),
8723                    expected,
8724                    "duplicate-populated near-saturation slice omitted={omitted:?} must return {expected} on lacks_only_kind for {kind:?}",
8725                );
8726            }
8727        }
8728    }
8729
8730    /// TWO-MISSING pin — a slice omitting exactly two kinds returns
8731    /// `false` on every arm; the strict refinement fails at the
8732    /// earliest walk step that hits the second missing kind. On
8733    /// `ConditionKind::ALL` of cardinality `N`, `N ≥ 3` is required
8734    /// for a two-missing arrangement to exist.
8735    #[test]
8736    fn condition_slice_lacks_only_kind_returns_false_on_two_missing_slice() {
8737        assert!(
8738            ConditionKind::ALL.len() >= 3,
8739            "two-missing arrangement requires N ≥ 3",
8740        );
8741        // Slice carries every kind except the first two of ALL.
8742        let slice: Vec<Condition> = ConditionKind::ALL
8743            .into_iter()
8744            .skip(2)
8745            .map(condition_with)
8746            .collect();
8747        for kind in ConditionKind::ALL {
8748            assert!(
8749                !slice.as_slice().lacks_only_kind(kind),
8750                "two-missing slice must return false on lacks_only_kind for {kind:?}",
8751            );
8752            assert_eq!(
8753                slice.as_slice().lacks_only_kind(kind),
8754                slice.as_slice().missing_kinds() == vec![kind],
8755                "two-missing lacks_only_kind({kind:?}) must equal (missing_kinds() == vec![{kind:?}])",
8756            );
8757        }
8758    }
8759
8760    /// SATURATED pin — every kind populated, no kind missing, no kind
8761    /// is "only" missing. Returns `false` on every arm.
8762    #[test]
8763    fn condition_slice_lacks_only_kind_returns_false_on_saturated_slice() {
8764        let saturated: Vec<Condition> =
8765            ConditionKind::ALL.into_iter().map(condition_with).collect();
8766        for kind in ConditionKind::ALL {
8767            assert!(
8768                !saturated.as_slice().lacks_only_kind(kind),
8769                "saturated slice must return false on lacks_only_kind for {kind:?}",
8770            );
8771            assert_eq!(
8772                saturated.as_slice().lacks_only_kind(kind),
8773                saturated.as_slice().lacks_kind(kind)
8774                    && saturated.as_slice().missing_kind_count() == 1,
8775                "saturated lacks_only_kind({kind:?}) must equal (lacks_kind && missing_kind_count == 1)",
8776            );
8777        }
8778    }
8779
8780    // ── ConditionSliceExt::first_distinct_kind — earliest-element pins ─
8781    //
8782    // Short-circuiting Option<ConditionKind> peer of the closed-set-
8783    // inversion widened primitive `distinct_kinds`: `first_distinct_kind()`
8784    // returns the earliest present kind in canonical ConditionKind::ALL
8785    // order without materializing the intermediate Vec<ConditionKind>.
8786    // The composition law `first_distinct_kind() == distinct_kinds()
8787    // .first().copied()` is pinned as the earliest-element-inversion arm
8788    // of `assert_slice_refinement_composition_laws`.
8789
8790    /// EMPTY-SLICE pin — an empty slice returns `None` on
8791    /// `first_distinct_kind`, byte-for-byte with
8792    /// `distinct_kinds().first().copied()`.
8793    #[test]
8794    fn condition_slice_first_distinct_kind_returns_none_on_empty_slice() {
8795        let empty: &[Condition] = &[];
8796        assert_eq!(
8797            empty.first_distinct_kind(),
8798            None,
8799            "empty slice must return None on first_distinct_kind",
8800        );
8801        assert_eq!(
8802            empty.first_distinct_kind(),
8803            empty.distinct_kinds().first().copied(),
8804            "empty first_distinct_kind must equal distinct_kinds().first().copied()",
8805        );
8806    }
8807
8808    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
8809    /// the addressed kind returns `Some(that_kind)` on
8810    /// `first_distinct_kind`.
8811    #[test]
8812    fn condition_slice_first_distinct_kind_returns_populated_variant() {
8813        for populated in ConditionKind::ALL {
8814            let slice = [condition_with(populated)];
8815            assert_eq!(
8816                slice.first_distinct_kind(),
8817                Some(populated),
8818                "single-populated slice must return Some({populated:?}) on first_distinct_kind",
8819            );
8820            assert_eq!(
8821                slice.first_distinct_kind(),
8822                slice.distinct_kinds().first().copied(),
8823                "single-populated first_distinct_kind must equal distinct_kinds().first().copied() for {populated:?}",
8824            );
8825        }
8826    }
8827
8828    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
8829    /// variant returns `Some(ConditionKind::ALL[0])` on
8830    /// `first_distinct_kind` (the first ALL entry hits at the earliest
8831    /// walk step).
8832    #[test]
8833    fn condition_slice_first_distinct_kind_returns_first_all_on_saturated_slice() {
8834        let saturated: Vec<Condition> =
8835            ConditionKind::ALL.into_iter().map(condition_with).collect();
8836        assert_eq!(
8837            saturated.as_slice().first_distinct_kind(),
8838            Some(ConditionKind::ALL[0]),
8839            "saturated slice must return Some(ConditionKind::ALL[0]) on first_distinct_kind",
8840        );
8841        assert_eq!(
8842            saturated.as_slice().first_distinct_kind(),
8843            saturated.as_slice().distinct_kinds().first().copied(),
8844            "saturated first_distinct_kind must equal distinct_kinds().first().copied()",
8845        );
8846    }
8847
8848    // ── ConditionSliceExt::first_missing_kind — earliest-element pins ──
8849
8850    /// EMPTY-SLICE pin — an empty slice returns
8851    /// `Some(ConditionKind::ALL[0])` on `first_missing_kind` (every
8852    /// kind missing, first hit is index 0). Dual of the empty-slice arm
8853    /// on `first_distinct_kind` which returns `None`.
8854    #[test]
8855    fn condition_slice_first_missing_kind_returns_first_all_on_empty_slice() {
8856        let empty: &[Condition] = &[];
8857        assert_eq!(
8858            empty.first_missing_kind(),
8859            Some(ConditionKind::ALL[0]),
8860            "empty slice must return Some(ConditionKind::ALL[0]) on first_missing_kind",
8861        );
8862        assert_eq!(
8863            empty.first_missing_kind(),
8864            empty.missing_kinds().first().copied(),
8865            "empty first_missing_kind must equal missing_kinds().first().copied()",
8866        );
8867    }
8868
8869    /// PER-VARIANT pin — a slice populating exactly `k` returns
8870    /// `Some(ALL[0])` if `k != ALL[0]`, else `Some(ALL[1])` (the earliest
8871    /// non-`k` entry).
8872    #[test]
8873    fn condition_slice_first_missing_kind_returns_earliest_absent_variant() {
8874        for populated in ConditionKind::ALL {
8875            let slice = [condition_with(populated)];
8876            let expected = ConditionKind::ALL.into_iter().find(|k| *k != populated);
8877            assert_eq!(
8878                slice.first_missing_kind(),
8879                expected,
8880                "single-populated slice must return earliest ALL entry != {populated:?} on first_missing_kind",
8881            );
8882            assert_eq!(
8883                slice.first_missing_kind(),
8884                slice.missing_kinds().first().copied(),
8885                "single-populated first_missing_kind must equal missing_kinds().first().copied() for {populated:?}",
8886            );
8887        }
8888    }
8889
8890    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
8891    /// variant returns `None` on `first_missing_kind` (no kind missing).
8892    #[test]
8893    fn condition_slice_first_missing_kind_returns_none_on_saturated_slice() {
8894        let saturated: Vec<Condition> =
8895            ConditionKind::ALL.into_iter().map(condition_with).collect();
8896        assert_eq!(
8897            saturated.as_slice().first_missing_kind(),
8898            None,
8899            "saturated slice must return None on first_missing_kind",
8900        );
8901        assert_eq!(
8902            saturated.as_slice().first_missing_kind(),
8903            saturated.as_slice().missing_kinds().first().copied(),
8904            "saturated first_missing_kind must equal missing_kinds().first().copied()",
8905        );
8906    }
8907
8908    // ── ConditionSliceExt::last_distinct_kind — latest-element pins ────
8909    //
8910    // Short-circuiting Option<ConditionKind> peer of the closed-set-
8911    // inversion widened primitive `distinct_kinds` on the LATEST-hit
8912    // side: `last_distinct_kind()` returns the latest present kind in
8913    // canonical ConditionKind::ALL order via a REVERSED walk with no
8914    // intermediate Vec<ConditionKind> allocation. The composition law
8915    // `last_distinct_kind() == distinct_kinds().last().copied()` is
8916    // pinned as the latest-element-inversion arm of
8917    // `assert_slice_refinement_composition_laws`.
8918
8919    /// EMPTY-SLICE pin — an empty slice returns `None` on
8920    /// `last_distinct_kind`, byte-for-byte with
8921    /// `distinct_kinds().last().copied()` (both scalar endpoints agree
8922    /// on emptiness).
8923    #[test]
8924    fn condition_slice_last_distinct_kind_returns_none_on_empty_slice() {
8925        let empty: &[Condition] = &[];
8926        assert_eq!(
8927            empty.last_distinct_kind(),
8928            None,
8929            "empty slice must return None on last_distinct_kind",
8930        );
8931        assert_eq!(
8932            empty.last_distinct_kind(),
8933            empty.distinct_kinds().last().copied(),
8934            "empty last_distinct_kind must equal distinct_kinds().last().copied()",
8935        );
8936    }
8937
8938    /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
8939    /// the addressed kind returns `Some(that_kind)` on
8940    /// `last_distinct_kind` (single hit; earliest = latest endpoint).
8941    #[test]
8942    fn condition_slice_last_distinct_kind_returns_populated_variant() {
8943        for populated in ConditionKind::ALL {
8944            let slice = [condition_with(populated)];
8945            assert_eq!(
8946                slice.last_distinct_kind(),
8947                Some(populated),
8948                "single-populated slice must return Some({populated:?}) on last_distinct_kind",
8949            );
8950            assert_eq!(
8951                slice.last_distinct_kind(),
8952                slice.distinct_kinds().last().copied(),
8953                "single-populated last_distinct_kind must equal distinct_kinds().last().copied() for {populated:?}",
8954            );
8955            // On single-populated slice both endpoint projections agree.
8956            assert_eq!(
8957                slice.last_distinct_kind(),
8958                slice.first_distinct_kind(),
8959                "single-populated last_distinct_kind must equal first_distinct_kind for {populated:?} (single hit ⇒ earliest = latest)",
8960            );
8961        }
8962    }
8963
8964    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
8965    /// variant returns `Some(*ConditionKind::ALL.last().unwrap())` on
8966    /// `last_distinct_kind` (the last ALL entry hits at the earliest
8967    /// walk step of the REVERSED walk).
8968    #[test]
8969    fn condition_slice_last_distinct_kind_returns_last_all_on_saturated_slice() {
8970        let saturated: Vec<Condition> =
8971            ConditionKind::ALL.into_iter().map(condition_with).collect();
8972        let last_all = ConditionKind::ALL.last().copied();
8973        assert_eq!(
8974            saturated.as_slice().last_distinct_kind(),
8975            last_all,
8976            "saturated slice must return Some(*ConditionKind::ALL.last().unwrap()) on last_distinct_kind",
8977        );
8978        assert_eq!(
8979            saturated.as_slice().last_distinct_kind(),
8980            saturated.as_slice().distinct_kinds().last().copied(),
8981            "saturated last_distinct_kind must equal distinct_kinds().last().copied()",
8982        );
8983    }
8984
8985    // ── ConditionSliceExt::last_missing_kind — latest-element pins ─────
8986
8987    /// EMPTY-SLICE pin — an empty slice returns
8988    /// `Some(*ConditionKind::ALL.last().unwrap())` on `last_missing_kind`
8989    /// (every kind missing, latest hit is the last ALL entry). Dual of
8990    /// the empty-slice arm on `last_distinct_kind` which returns `None`.
8991    #[test]
8992    fn condition_slice_last_missing_kind_returns_last_all_on_empty_slice() {
8993        let empty: &[Condition] = &[];
8994        let last_all = ConditionKind::ALL.last().copied();
8995        assert_eq!(
8996            empty.last_missing_kind(),
8997            last_all,
8998            "empty slice must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_kind",
8999        );
9000        assert_eq!(
9001            empty.last_missing_kind(),
9002            empty.missing_kinds().last().copied(),
9003            "empty last_missing_kind must equal missing_kinds().last().copied()",
9004        );
9005    }
9006
9007    /// PER-VARIANT pin — a slice populating exactly `k` returns
9008    /// `Some(*ALL.last().unwrap())` if `k != ALL.last().unwrap()`, else
9009    /// `Some(ALL[ALL.len() - 2])` (the latest ALL entry != `k`).
9010    #[test]
9011    fn condition_slice_last_missing_kind_returns_latest_absent_variant() {
9012        for populated in ConditionKind::ALL {
9013            let slice = [condition_with(populated)];
9014            let expected = ConditionKind::ALL
9015                .into_iter()
9016                .rev()
9017                .find(|k| *k != populated);
9018            assert_eq!(
9019                slice.last_missing_kind(),
9020                expected,
9021                "single-populated slice must return latest ALL entry != {populated:?} on last_missing_kind",
9022            );
9023            assert_eq!(
9024                slice.last_missing_kind(),
9025                slice.missing_kinds().last().copied(),
9026                "single-populated last_missing_kind must equal missing_kinds().last().copied() for {populated:?}",
9027            );
9028        }
9029    }
9030
9031    /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
9032    /// variant returns `None` on `last_missing_kind` (no kind missing).
9033    #[test]
9034    fn condition_slice_last_missing_kind_returns_none_on_saturated_slice() {
9035        let saturated: Vec<Condition> =
9036            ConditionKind::ALL.into_iter().map(condition_with).collect();
9037        assert_eq!(
9038            saturated.as_slice().last_missing_kind(),
9039            None,
9040            "saturated slice must return None on last_missing_kind",
9041        );
9042        assert_eq!(
9043            saturated.as_slice().last_missing_kind(),
9044            saturated.as_slice().missing_kinds().last().copied(),
9045            "saturated last_missing_kind must equal missing_kinds().last().copied()",
9046        );
9047    }
9048
9049    // ── Boundary distinct-set triad — substrate-delegation pins ────────
9050    //
9051    // The (precondition, postcondition, condition-union) distinct-set
9052    // triad on [`Boundary`] delegates to the slice-level substrate
9053    // primitive [`ConditionSliceExt::distinct_kinds`] on each half-slice
9054    // and composes the union via [`Self::has_condition_kind`] over
9055    // [`ConditionKind::ALL`]. The dedicated tests below pin each arm's
9056    // delegation shape; the substrate testkit macro
9057    // `assert_surface_union_composition_laws` (extended in this commit
9058    // with the closed-set-inversion arm) pins the union composition law
9059    // against the two half-slice arms in canonical ALL-order.
9060
9061    /// SUBSTRATE-DELEGATION pin (Boundary distinct-kind-count triad)
9062    /// — the three `distinct_*_kind_count` methods on [`Boundary`]
9063    /// delegate to the slice-level substrate primitive
9064    /// [`ConditionSliceExt::distinct_kind_count`] over the two
9065    /// `Vec<Condition>` slots (precondition + postcondition) and
9066    /// compose the union scalar via
9067    /// `ConditionKind::ALL.filter(|k| has_condition_kind(*k)).count()`.
9068    /// Sweep `ConditionKind::ALL × ConditionKind::ALL` so a regression
9069    /// that (a) inlined a divergent closed-set walk at either half-slice
9070    /// arm, (b) reversed the union walk order, or (c) narrowed the
9071    /// union to an intersection surfaces HERE. Also pins the
9072    /// composition law
9073    /// `distinct_*_kind_count() == distinct_*_kinds().len()` at each
9074    /// arm — a regression that overrode the scalar projection to skip a
9075    /// kind or double-count a slot fails HERE.
9076    #[test]
9077    fn distinct_condition_kind_count_triad_delegates_and_matches_distinct_kinds_len() {
9078        // Empty boundary — every arm returns 0.
9079        let b = Boundary::default();
9080        for kind in ConditionKind::ALL {
9081            assert_eq!(
9082                b.distinct_precondition_kind_count(),
9083                0,
9084                "empty boundary must return 0 on distinct_precondition_kind_count, kind={kind:?}",
9085            );
9086            assert_eq!(
9087                b.distinct_postcondition_kind_count(),
9088                0,
9089                "empty boundary must return 0 on distinct_postcondition_kind_count, kind={kind:?}",
9090            );
9091            assert_eq!(
9092                b.distinct_condition_kind_count(),
9093                0,
9094                "empty boundary must return 0 on distinct_condition_kind_count, kind={kind:?}",
9095            );
9096        }
9097
9098        for pre_kind in ConditionKind::ALL {
9099            for post_kind in ConditionKind::ALL {
9100                let mut b = Boundary::default();
9101                b.preconditions.push(condition_with(pre_kind));
9102                b.postconditions.push(condition_with(post_kind));
9103
9104                assert_eq!(
9105                    b.distinct_precondition_kind_count(),
9106                    b.preconditions.distinct_kind_count(),
9107                    "Boundary::distinct_precondition_kind_count must delegate verbatim to \
9108                     preconditions.distinct_kind_count() for pre={pre_kind:?} post={post_kind:?}",
9109                );
9110                assert_eq!(
9111                    b.distinct_precondition_kind_count(),
9112                    b.distinct_precondition_kinds().len(),
9113                    "Boundary::distinct_precondition_kind_count must equal \
9114                     distinct_precondition_kinds().len() for pre={pre_kind:?} post={post_kind:?}",
9115                );
9116                assert_eq!(
9117                    b.distinct_postcondition_kind_count(),
9118                    b.postconditions.distinct_kind_count(),
9119                    "Boundary::distinct_postcondition_kind_count must delegate verbatim to \
9120                     postconditions.distinct_kind_count() for pre={pre_kind:?} post={post_kind:?}",
9121                );
9122                assert_eq!(
9123                    b.distinct_postcondition_kind_count(),
9124                    b.distinct_postcondition_kinds().len(),
9125                    "Boundary::distinct_postcondition_kind_count must equal \
9126                     distinct_postcondition_kinds().len() for pre={pre_kind:?} post={post_kind:?}",
9127                );
9128                let expected_union_count = if pre_kind == post_kind { 1 } else { 2 };
9129                assert_eq!(
9130                    b.distinct_condition_kind_count(),
9131                    expected_union_count,
9132                    "Boundary::distinct_condition_kind_count must count distinct union kinds \
9133                     for pre={pre_kind:?} post={post_kind:?}",
9134                );
9135                assert_eq!(
9136                    b.distinct_condition_kind_count(),
9137                    b.distinct_condition_kinds().len(),
9138                    "Boundary::distinct_condition_kind_count must equal \
9139                     distinct_condition_kinds().len() for pre={pre_kind:?} post={post_kind:?}",
9140                );
9141            }
9142        }
9143    }
9144
9145    /// SUBSTRATE-DELEGATION pin (Boundary distinct-set triad) — the
9146    /// three `distinct_*_kinds` methods on [`Boundary`] delegate to the
9147    /// slice-level substrate primitive over the two `Vec<Condition>`
9148    /// slots (precondition + postcondition) and compose the union via
9149    /// `ConditionKind::ALL.filter(|k| has_condition_kind(*k))`. Sweep
9150    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9151    /// (a) inlined a divergent closed-set walk at either half-slice
9152    /// arm, (b) reversed the union walk order, or (c) narrowed the
9153    /// union to an intersection surfaces HERE.
9154    #[test]
9155    fn distinct_condition_kinds_triad_delegates_to_slice_distinct_kinds() {
9156        for pre_kind in ConditionKind::ALL {
9157            for post_kind in ConditionKind::ALL {
9158                let mut b = Boundary::default();
9159                b.preconditions.push(condition_with(pre_kind));
9160                b.postconditions.push(condition_with(post_kind));
9161
9162                assert_eq!(
9163                    b.distinct_precondition_kinds(),
9164                    b.preconditions.distinct_kinds(),
9165                    "Boundary::distinct_precondition_kinds must delegate verbatim to \
9166                     preconditions.distinct_kinds() for pre={pre_kind:?} post={post_kind:?}",
9167                );
9168                assert_eq!(
9169                    b.distinct_postcondition_kinds(),
9170                    b.postconditions.distinct_kinds(),
9171                    "Boundary::distinct_postcondition_kinds must delegate verbatim to \
9172                     postconditions.distinct_kinds() for pre={pre_kind:?} post={post_kind:?}",
9173                );
9174                let expected_union: Vec<_> = ConditionKind::ALL
9175                    .into_iter()
9176                    .filter(|k| pre_kind == *k || post_kind == *k)
9177                    .collect();
9178                assert_eq!(
9179                    b.distinct_condition_kinds(),
9180                    expected_union,
9181                    "Boundary::distinct_condition_kinds must equal ConditionKind::ALL-ordered \
9182                     set-union of the two half-slice distinct-sets for pre={pre_kind:?} post={post_kind:?}",
9183                );
9184            }
9185        }
9186    }
9187
9188    /// SUBSTRATE-DELEGATION pin (Boundary distinct-set ITERATOR triad) —
9189    /// the three `iter_distinct_*_condition_kinds` methods on [`Boundary`]
9190    /// delegate to the slice-level substrate primitive
9191    /// [`ConditionSliceExt::iter_distinct_kinds`] over the two
9192    /// `Vec<Condition>` slots (precondition + postcondition) and compose
9193    /// the union via `ConditionKind::ALL.iter().copied().filter(|&k|
9194    /// has_condition_kind(k))`. Byte-for-byte peer of
9195    /// [`distinct_condition_kinds_triad_delegates_to_slice_distinct_kinds`]
9196    /// on the iterator side — the two tests share ONE closed-set walk
9197    /// semantics and pin the composition law
9198    /// `iter_distinct_*_condition_kinds().collect::<Vec<_>>() ==
9199    /// distinct_*_condition_kinds()` for every arm across
9200    /// `ConditionKind::ALL × ConditionKind::ALL`. A regression that
9201    /// materialized the Vec then re-iterated it (round-trip through the
9202    /// heap), drifted the yield order, or diverged from the widened
9203    /// primitive on any arm surfaces HERE.
9204    #[test]
9205    fn iter_distinct_condition_kinds_triad_delegates_to_slice_iter_distinct_kinds() {
9206        for pre_kind in ConditionKind::ALL {
9207            for post_kind in ConditionKind::ALL {
9208                let mut b = Boundary::default();
9209                b.preconditions.push(condition_with(pre_kind));
9210                b.postconditions.push(condition_with(post_kind));
9211
9212                let pre_via_iter: Vec<_> = b.iter_distinct_precondition_kinds().collect();
9213                let pre_via_vec = b.distinct_precondition_kinds();
9214                assert_eq!(
9215                    pre_via_iter, pre_via_vec,
9216                    "Boundary::iter_distinct_precondition_kinds().collect() drifted from \
9217                     distinct_precondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9218                );
9219                let post_via_iter: Vec<_> = b.iter_distinct_postcondition_kinds().collect();
9220                let post_via_vec = b.distinct_postcondition_kinds();
9221                assert_eq!(
9222                    post_via_iter, post_via_vec,
9223                    "Boundary::iter_distinct_postcondition_kinds().collect() drifted from \
9224                     distinct_postcondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9225                );
9226                let union_via_iter: Vec<_> = b.iter_distinct_condition_kinds().collect();
9227                let union_via_vec = b.distinct_condition_kinds();
9228                assert_eq!(
9229                    union_via_iter, union_via_vec,
9230                    "Boundary::iter_distinct_condition_kinds().collect() drifted from \
9231                     distinct_condition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9232                );
9233            }
9234        }
9235    }
9236
9237    /// SUBSTRATE-DELEGATION pin (Boundary missing-set ITERATOR triad) —
9238    /// the three `iter_missing_*_condition_kinds` methods on [`Boundary`]
9239    /// delegate to the slice-level substrate primitive
9240    /// [`ConditionSliceExt::iter_missing_kinds`] over the two
9241    /// `Vec<Condition>` slots (precondition + postcondition) and compose
9242    /// the union via `ConditionKind::ALL.iter().copied().filter(|&k|
9243    /// !has_condition_kind(k))`. Peer of
9244    /// [`iter_distinct_condition_kinds_triad_delegates_to_slice_iter_distinct_kinds`]
9245    /// on the missing side under a NEGATED point-probe.
9246    #[test]
9247    fn iter_missing_condition_kinds_triad_delegates_to_slice_iter_missing_kinds() {
9248        // Empty boundary — every iter arm yields ConditionKind::ALL.
9249        let b = Boundary::default();
9250        let all: Vec<_> = ConditionKind::ALL.to_vec();
9251        assert_eq!(
9252            b.iter_missing_precondition_kinds().collect::<Vec<_>>(),
9253            all,
9254            "empty boundary must yield ConditionKind::ALL on iter_missing_precondition_kinds",
9255        );
9256        assert_eq!(
9257            b.iter_missing_postcondition_kinds().collect::<Vec<_>>(),
9258            all,
9259            "empty boundary must yield ConditionKind::ALL on iter_missing_postcondition_kinds",
9260        );
9261        assert_eq!(
9262            b.iter_missing_condition_kinds().collect::<Vec<_>>(),
9263            all,
9264            "empty boundary must yield ConditionKind::ALL on iter_missing_condition_kinds",
9265        );
9266
9267        for pre_kind in ConditionKind::ALL {
9268            for post_kind in ConditionKind::ALL {
9269                let mut b = Boundary::default();
9270                b.preconditions.push(condition_with(pre_kind));
9271                b.postconditions.push(condition_with(post_kind));
9272
9273                let pre_via_iter: Vec<_> = b.iter_missing_precondition_kinds().collect();
9274                let pre_via_vec = b.missing_precondition_kinds();
9275                assert_eq!(
9276                    pre_via_iter, pre_via_vec,
9277                    "Boundary::iter_missing_precondition_kinds().collect() drifted from \
9278                     missing_precondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9279                );
9280                let post_via_iter: Vec<_> = b.iter_missing_postcondition_kinds().collect();
9281                let post_via_vec = b.missing_postcondition_kinds();
9282                assert_eq!(
9283                    post_via_iter, post_via_vec,
9284                    "Boundary::iter_missing_postcondition_kinds().collect() drifted from \
9285                     missing_postcondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9286                );
9287                let union_via_iter: Vec<_> = b.iter_missing_condition_kinds().collect();
9288                let union_via_vec = b.missing_condition_kinds();
9289                assert_eq!(
9290                    union_via_iter, union_via_vec,
9291                    "Boundary::iter_missing_condition_kinds().collect() drifted from \
9292                     missing_condition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9293                );
9294            }
9295        }
9296    }
9297
9298    /// SUBSTRATE-DELEGATION pin (Boundary missing-set triad) — the
9299    /// three `missing_*_kinds` methods on [`Boundary`] delegate to the
9300    /// slice-level substrate primitive
9301    /// [`ConditionSliceExt::missing_kinds`] over the two
9302    /// `Vec<Condition>` slots (precondition + postcondition) and
9303    /// compose the union via
9304    /// `ConditionKind::ALL.filter(|k| !has_condition_kind(*k))`. Sweep
9305    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9306    /// (a) inlined a divergent closed-set walk at either half-slice
9307    /// arm, (b) reversed the union walk order, (c) widened the union
9308    /// intersection to a union (a `||` inlined where `&&` is required
9309    /// on the missing side), or (d) forgot the negation surfaces HERE.
9310    /// Also pins the empty-boundary edge case: every arm returns
9311    /// `ConditionKind::ALL.to_vec()` on an empty boundary.
9312    #[test]
9313    fn missing_condition_kinds_triad_delegates_to_slice_missing_kinds() {
9314        // Empty boundary — every arm returns ConditionKind::ALL (nothing
9315        // is populated, so every kind is missing on all three slots).
9316        let b = Boundary::default();
9317        let all_kinds = ConditionKind::ALL.to_vec();
9318        assert_eq!(
9319            b.missing_precondition_kinds(),
9320            all_kinds,
9321            "empty boundary must return ConditionKind::ALL on missing_precondition_kinds",
9322        );
9323        assert_eq!(
9324            b.missing_postcondition_kinds(),
9325            all_kinds,
9326            "empty boundary must return ConditionKind::ALL on missing_postcondition_kinds",
9327        );
9328        assert_eq!(
9329            b.missing_condition_kinds(),
9330            all_kinds,
9331            "empty boundary must return ConditionKind::ALL on missing_condition_kinds",
9332        );
9333
9334        for pre_kind in ConditionKind::ALL {
9335            for post_kind in ConditionKind::ALL {
9336                let mut b = Boundary::default();
9337                b.preconditions.push(condition_with(pre_kind));
9338                b.postconditions.push(condition_with(post_kind));
9339
9340                assert_eq!(
9341                    b.missing_precondition_kinds(),
9342                    b.preconditions.missing_kinds(),
9343                    "Boundary::missing_precondition_kinds must delegate verbatim to \
9344                     preconditions.missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
9345                );
9346                assert_eq!(
9347                    b.missing_postcondition_kinds(),
9348                    b.postconditions.missing_kinds(),
9349                    "Boundary::missing_postcondition_kinds must delegate verbatim to \
9350                     postconditions.missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
9351                );
9352                // Union: a kind is missing from the union iff it is
9353                // missing from BOTH half-slices (SET-INTERSECTION).
9354                let expected_union: Vec<_> = ConditionKind::ALL
9355                    .into_iter()
9356                    .filter(|k| pre_kind != *k && post_kind != *k)
9357                    .collect();
9358                assert_eq!(
9359                    b.missing_condition_kinds(),
9360                    expected_union,
9361                    "Boundary::missing_condition_kinds must equal ConditionKind::ALL-ordered \
9362                     set-INTERSECTION of the two half-slice missing-sets for pre={pre_kind:?} post={post_kind:?}",
9363                );
9364                // Partition invariant: distinct ∪ missing == ALL, disjoint.
9365                let distinct = b.distinct_condition_kinds();
9366                let missing = b.missing_condition_kinds();
9367                for kind in ConditionKind::ALL {
9368                    assert!(
9369                        distinct.contains(&kind) ^ missing.contains(&kind),
9370                        "(distinct, missing) partition violated on {kind:?} for pre={pre_kind:?} post={post_kind:?}",
9371                    );
9372                }
9373                assert_eq!(
9374                    distinct.len() + missing.len(),
9375                    ConditionKind::ALL.len(),
9376                    "Boundary (distinct, missing) cardinality partition drift for pre={pre_kind:?} post={post_kind:?}",
9377                );
9378            }
9379        }
9380    }
9381
9382    /// SUBSTRATE-DELEGATION pin (Boundary missing-kind-count triad) —
9383    /// the three `missing_*_kind_count` methods on [`Boundary`] delegate
9384    /// to the slice-level substrate primitive
9385    /// [`ConditionSliceExt::missing_kind_count`] over the two
9386    /// `Vec<Condition>` slots (precondition + postcondition) and
9387    /// compose the union via
9388    /// `ConditionKind::ALL.iter().filter(|k|
9389    /// !self.has_condition_kind(**k)).count()`. Sweep
9390    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9391    /// (a) inlined a divergent negated closed-set walk at either half-
9392    /// slice arm, (b) dropped the negation on the union arm, or (c)
9393    /// drifted from the widened-primitive length surfaces HERE. Also
9394    /// pins the scalar-partition invariant
9395    /// `distinct_kind_count + missing_kind_count == ConditionKind::ALL.len()`
9396    /// per arrangement.
9397    #[test]
9398    fn missing_condition_kind_count_triad_delegates_to_slice_missing_kind_count() {
9399        // Empty boundary — every arm returns ConditionKind::ALL.len()
9400        // (nothing is populated, so every kind is missing on all three
9401        // slots).
9402        let b = Boundary::default();
9403        let total = ConditionKind::ALL.len();
9404        assert_eq!(
9405            b.missing_precondition_kind_count(),
9406            total,
9407            "empty boundary must return ConditionKind::ALL.len() on missing_precondition_kind_count",
9408        );
9409        assert_eq!(
9410            b.missing_postcondition_kind_count(),
9411            total,
9412            "empty boundary must return ConditionKind::ALL.len() on missing_postcondition_kind_count",
9413        );
9414        assert_eq!(
9415            b.missing_condition_kind_count(),
9416            total,
9417            "empty boundary must return ConditionKind::ALL.len() on missing_condition_kind_count",
9418        );
9419
9420        for pre_kind in ConditionKind::ALL {
9421            for post_kind in ConditionKind::ALL {
9422                let mut b = Boundary::default();
9423                b.preconditions.push(condition_with(pre_kind));
9424                b.postconditions.push(condition_with(post_kind));
9425
9426                // Half-slice arms delegate byte-for-byte to the slice
9427                // substrate primitive.
9428                assert_eq!(
9429                    b.missing_precondition_kind_count(),
9430                    b.preconditions.missing_kind_count(),
9431                    "Boundary::missing_precondition_kind_count must delegate verbatim to \
9432                     preconditions.missing_kind_count() for pre={pre_kind:?} post={post_kind:?}",
9433                );
9434                assert_eq!(
9435                    b.missing_postcondition_kind_count(),
9436                    b.postconditions.missing_kind_count(),
9437                    "Boundary::missing_postcondition_kind_count must delegate verbatim to \
9438                     postconditions.missing_kind_count() for pre={pre_kind:?} post={post_kind:?}",
9439                );
9440                // Union arm equals missing_condition_kinds().len() — the
9441                // scalar cardinality of the two-slice intersection.
9442                assert_eq!(
9443                    b.missing_condition_kind_count(),
9444                    b.missing_condition_kinds().len(),
9445                    "Boundary::missing_condition_kind_count must equal missing_condition_kinds().len() \
9446                     for pre={pre_kind:?} post={post_kind:?}",
9447                );
9448                // Scalar-partition invariant: distinct + missing == ALL.
9449                assert_eq!(
9450                    b.distinct_condition_kind_count() + b.missing_condition_kind_count(),
9451                    ConditionKind::ALL.len(),
9452                    "Boundary (distinct, missing) scalar partition drift for pre={pre_kind:?} post={post_kind:?}",
9453                );
9454            }
9455        }
9456    }
9457
9458    /// SUBSTRATE-DELEGATION pin (Boundary first-distinct-kind triad) —
9459    /// the three `first_distinct_*_kind` methods on [`Boundary`]
9460    /// delegate to the slice-level substrate primitive
9461    /// [`ConditionSliceExt::first_distinct_kind`] over the two
9462    /// `Vec<Condition>` slots (precondition + postcondition) and
9463    /// compose the union via `ConditionKind::ALL.iter().copied()
9464    /// .find(|k| has_condition_kind(*k))`. Sweep
9465    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9466    /// inlined a divergent short-circuit walk at either half-slice arm,
9467    /// reversed the walk order, or dropped the short-circuit surfaces
9468    /// HERE. Also pins the composition law `first_distinct_*_kind() ==
9469    /// distinct_*_kinds().first().copied()` at each arm.
9470    #[test]
9471    fn first_distinct_condition_kind_triad_delegates_to_slice_first_distinct_kind() {
9472        // Empty boundary — every arm returns None.
9473        let b = Boundary::default();
9474        assert_eq!(
9475            b.first_distinct_precondition_kind(),
9476            None,
9477            "empty boundary must return None on first_distinct_precondition_kind",
9478        );
9479        assert_eq!(
9480            b.first_distinct_postcondition_kind(),
9481            None,
9482            "empty boundary must return None on first_distinct_postcondition_kind",
9483        );
9484        assert_eq!(
9485            b.first_distinct_condition_kind(),
9486            None,
9487            "empty boundary must return None on first_distinct_condition_kind",
9488        );
9489
9490        for pre_kind in ConditionKind::ALL {
9491            for post_kind in ConditionKind::ALL {
9492                let mut b = Boundary::default();
9493                b.preconditions.push(condition_with(pre_kind));
9494                b.postconditions.push(condition_with(post_kind));
9495
9496                assert_eq!(
9497                    b.first_distinct_precondition_kind(),
9498                    b.preconditions.first_distinct_kind(),
9499                    "Boundary::first_distinct_precondition_kind must delegate verbatim to \
9500                     preconditions.first_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
9501                );
9502                assert_eq!(
9503                    b.first_distinct_precondition_kind(),
9504                    b.distinct_precondition_kinds().first().copied(),
9505                    "Boundary::first_distinct_precondition_kind must equal \
9506                     distinct_precondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
9507                );
9508                assert_eq!(
9509                    b.first_distinct_postcondition_kind(),
9510                    b.postconditions.first_distinct_kind(),
9511                    "Boundary::first_distinct_postcondition_kind must delegate verbatim to \
9512                     postconditions.first_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
9513                );
9514                assert_eq!(
9515                    b.first_distinct_postcondition_kind(),
9516                    b.distinct_postcondition_kinds().first().copied(),
9517                    "Boundary::first_distinct_postcondition_kind must equal \
9518                     distinct_postcondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
9519                );
9520                let expected_union = ConditionKind::ALL
9521                    .into_iter()
9522                    .find(|k| pre_kind == *k || post_kind == *k);
9523                assert_eq!(
9524                    b.first_distinct_condition_kind(),
9525                    expected_union,
9526                    "Boundary::first_distinct_condition_kind must equal earliest ALL entry \
9527                     populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
9528                );
9529                assert_eq!(
9530                    b.first_distinct_condition_kind(),
9531                    b.distinct_condition_kinds().first().copied(),
9532                    "Boundary::first_distinct_condition_kind must equal \
9533                     distinct_condition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
9534                );
9535            }
9536        }
9537    }
9538
9539    /// SUBSTRATE-DELEGATION pin (Boundary first-missing-kind triad) —
9540    /// the three `first_missing_*_kind` methods on [`Boundary`]
9541    /// delegate to the slice-level substrate primitive
9542    /// [`ConditionSliceExt::first_missing_kind`] over the two
9543    /// `Vec<Condition>` slots (precondition + postcondition) and
9544    /// compose the union via `ConditionKind::ALL.iter().copied()
9545    /// .find(|k| !has_condition_kind(*k))`. Sweep
9546    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9547    /// dropped the negation or drifted the short-circuit walk surfaces
9548    /// HERE. Also pins the composition law `first_missing_*_kind() ==
9549    /// missing_*_kinds().first().copied()` at each arm.
9550    #[test]
9551    fn first_missing_condition_kind_triad_delegates_to_slice_first_missing_kind() {
9552        // Empty boundary — every arm returns Some(ConditionKind::ALL[0]).
9553        let b = Boundary::default();
9554        let first = Some(ConditionKind::ALL[0]);
9555        assert_eq!(
9556            b.first_missing_precondition_kind(),
9557            first,
9558            "empty boundary must return Some(ConditionKind::ALL[0]) on first_missing_precondition_kind",
9559        );
9560        assert_eq!(
9561            b.first_missing_postcondition_kind(),
9562            first,
9563            "empty boundary must return Some(ConditionKind::ALL[0]) on first_missing_postcondition_kind",
9564        );
9565        assert_eq!(
9566            b.first_missing_condition_kind(),
9567            first,
9568            "empty boundary must return Some(ConditionKind::ALL[0]) on first_missing_condition_kind",
9569        );
9570
9571        for pre_kind in ConditionKind::ALL {
9572            for post_kind in ConditionKind::ALL {
9573                let mut b = Boundary::default();
9574                b.preconditions.push(condition_with(pre_kind));
9575                b.postconditions.push(condition_with(post_kind));
9576
9577                assert_eq!(
9578                    b.first_missing_precondition_kind(),
9579                    b.preconditions.first_missing_kind(),
9580                    "Boundary::first_missing_precondition_kind must delegate verbatim to \
9581                     preconditions.first_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
9582                );
9583                assert_eq!(
9584                    b.first_missing_precondition_kind(),
9585                    b.missing_precondition_kinds().first().copied(),
9586                    "Boundary::first_missing_precondition_kind must equal \
9587                     missing_precondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
9588                );
9589                assert_eq!(
9590                    b.first_missing_postcondition_kind(),
9591                    b.postconditions.first_missing_kind(),
9592                    "Boundary::first_missing_postcondition_kind must delegate verbatim to \
9593                     postconditions.first_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
9594                );
9595                assert_eq!(
9596                    b.first_missing_postcondition_kind(),
9597                    b.missing_postcondition_kinds().first().copied(),
9598                    "Boundary::first_missing_postcondition_kind must equal \
9599                     missing_postcondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
9600                );
9601                let expected_union = ConditionKind::ALL
9602                    .into_iter()
9603                    .find(|k| pre_kind != *k && post_kind != *k);
9604                assert_eq!(
9605                    b.first_missing_condition_kind(),
9606                    expected_union,
9607                    "Boundary::first_missing_condition_kind must equal earliest ALL entry \
9608                     NOT populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
9609                );
9610                assert_eq!(
9611                    b.first_missing_condition_kind(),
9612                    b.missing_condition_kinds().first().copied(),
9613                    "Boundary::first_missing_condition_kind must equal \
9614                     missing_condition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
9615                );
9616            }
9617        }
9618    }
9619
9620    /// SUBSTRATE-DELEGATION pin (Boundary last-distinct-kind triad)
9621    /// — the three `last_distinct_*_kind` methods on [`Boundary`]
9622    /// delegate to the slice-level substrate primitive
9623    /// [`ConditionSliceExt::last_distinct_kind`] over the two
9624    /// `Vec<Condition>` slots (precondition + postcondition) and
9625    /// compose the union via `ConditionKind::ALL.iter().rev().copied()
9626    /// .find(|k| has_condition_kind(*k))`. Sweep
9627    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9628    /// (a) forgot to reverse the walk (returning `first_distinct_*_kind`),
9629    /// (b) inlined a divergent closed-set walk at either half-slice
9630    /// arm, or (c) narrowed the union to an intersection surfaces
9631    /// HERE. Also pins the composition law `last_distinct_*_kind() ==
9632    /// distinct_*_kinds().last().copied()` at each arm.
9633    #[test]
9634    fn last_distinct_condition_kind_triad_delegates_to_slice_last_distinct_kind() {
9635        // Empty boundary — every arm returns None.
9636        let b = Boundary::default();
9637        assert_eq!(
9638            b.last_distinct_precondition_kind(),
9639            None,
9640            "empty boundary must return None on last_distinct_precondition_kind",
9641        );
9642        assert_eq!(
9643            b.last_distinct_postcondition_kind(),
9644            None,
9645            "empty boundary must return None on last_distinct_postcondition_kind",
9646        );
9647        assert_eq!(
9648            b.last_distinct_condition_kind(),
9649            None,
9650            "empty boundary must return None on last_distinct_condition_kind",
9651        );
9652
9653        for pre_kind in ConditionKind::ALL {
9654            for post_kind in ConditionKind::ALL {
9655                let mut b = Boundary::default();
9656                b.preconditions.push(condition_with(pre_kind));
9657                b.postconditions.push(condition_with(post_kind));
9658
9659                assert_eq!(
9660                    b.last_distinct_precondition_kind(),
9661                    b.preconditions.last_distinct_kind(),
9662                    "Boundary::last_distinct_precondition_kind must delegate verbatim to \
9663                     preconditions.last_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
9664                );
9665                assert_eq!(
9666                    b.last_distinct_precondition_kind(),
9667                    b.distinct_precondition_kinds().last().copied(),
9668                    "Boundary::last_distinct_precondition_kind must equal \
9669                     distinct_precondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
9670                );
9671                assert_eq!(
9672                    b.last_distinct_postcondition_kind(),
9673                    b.postconditions.last_distinct_kind(),
9674                    "Boundary::last_distinct_postcondition_kind must delegate verbatim to \
9675                     postconditions.last_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
9676                );
9677                assert_eq!(
9678                    b.last_distinct_postcondition_kind(),
9679                    b.distinct_postcondition_kinds().last().copied(),
9680                    "Boundary::last_distinct_postcondition_kind must equal \
9681                     distinct_postcondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
9682                );
9683                let expected_union = ConditionKind::ALL
9684                    .into_iter()
9685                    .rev()
9686                    .find(|k| pre_kind == *k || post_kind == *k);
9687                assert_eq!(
9688                    b.last_distinct_condition_kind(),
9689                    expected_union,
9690                    "Boundary::last_distinct_condition_kind must equal latest ALL entry \
9691                     populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
9692                );
9693                assert_eq!(
9694                    b.last_distinct_condition_kind(),
9695                    b.distinct_condition_kinds().last().copied(),
9696                    "Boundary::last_distinct_condition_kind must equal \
9697                     distinct_condition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
9698                );
9699            }
9700        }
9701    }
9702
9703    /// SUBSTRATE-DELEGATION pin (Boundary last-missing-kind triad) —
9704    /// the three `last_missing_*_kind` methods on [`Boundary`]
9705    /// delegate to the slice-level substrate primitive
9706    /// [`ConditionSliceExt::last_missing_kind`] over the two
9707    /// `Vec<Condition>` slots (precondition + postcondition) and
9708    /// compose the union via `ConditionKind::ALL.iter().rev().copied()
9709    /// .find(|k| !has_condition_kind(*k))`. Sweep
9710    /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9711    /// dropped the negation or forgot the reversed short-circuit walk
9712    /// surfaces HERE. Also pins the composition law `last_missing_*_kind()
9713    /// == missing_*_kinds().last().copied()` at each arm.
9714    #[test]
9715    fn last_missing_condition_kind_triad_delegates_to_slice_last_missing_kind() {
9716        // Empty boundary — every arm returns Some(*ConditionKind::ALL.last().unwrap()).
9717        let b = Boundary::default();
9718        let last = ConditionKind::ALL.last().copied();
9719        assert_eq!(
9720            b.last_missing_precondition_kind(),
9721            last,
9722            "empty boundary must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_precondition_kind",
9723        );
9724        assert_eq!(
9725            b.last_missing_postcondition_kind(),
9726            last,
9727            "empty boundary must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_postcondition_kind",
9728        );
9729        assert_eq!(
9730            b.last_missing_condition_kind(),
9731            last,
9732            "empty boundary must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_condition_kind",
9733        );
9734
9735        for pre_kind in ConditionKind::ALL {
9736            for post_kind in ConditionKind::ALL {
9737                let mut b = Boundary::default();
9738                b.preconditions.push(condition_with(pre_kind));
9739                b.postconditions.push(condition_with(post_kind));
9740
9741                assert_eq!(
9742                    b.last_missing_precondition_kind(),
9743                    b.preconditions.last_missing_kind(),
9744                    "Boundary::last_missing_precondition_kind must delegate verbatim to \
9745                     preconditions.last_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
9746                );
9747                assert_eq!(
9748                    b.last_missing_precondition_kind(),
9749                    b.missing_precondition_kinds().last().copied(),
9750                    "Boundary::last_missing_precondition_kind must equal \
9751                     missing_precondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
9752                );
9753                assert_eq!(
9754                    b.last_missing_postcondition_kind(),
9755                    b.postconditions.last_missing_kind(),
9756                    "Boundary::last_missing_postcondition_kind must delegate verbatim to \
9757                     postconditions.last_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
9758                );
9759                assert_eq!(
9760                    b.last_missing_postcondition_kind(),
9761                    b.missing_postcondition_kinds().last().copied(),
9762                    "Boundary::last_missing_postcondition_kind must equal \
9763                     missing_postcondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
9764                );
9765                let expected_union = ConditionKind::ALL
9766                    .into_iter()
9767                    .rev()
9768                    .find(|k| pre_kind != *k && post_kind != *k);
9769                assert_eq!(
9770                    b.last_missing_condition_kind(),
9771                    expected_union,
9772                    "Boundary::last_missing_condition_kind must equal latest ALL entry \
9773                     NOT populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
9774                );
9775                assert_eq!(
9776                    b.last_missing_condition_kind(),
9777                    b.missing_condition_kinds().last().copied(),
9778                    "Boundary::last_missing_condition_kind must equal \
9779                     missing_condition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
9780                );
9781            }
9782        }
9783    }
9784
9785    /// SUBSTRATE-DELEGATION pin (Boundary saturation-predicate triad)
9786    /// — the three `is_*_kind_saturated` methods on [`Boundary`]
9787    /// delegate to the slice-level substrate primitive
9788    /// [`ConditionSliceExt::is_kind_saturated`] over the two
9789    /// `Vec<Condition>` slots (precondition + postcondition) and
9790    /// compose the union via `ConditionKind::ALL.iter().all(|k|
9791    /// has_condition_kind(*k))`. Sweeps the empty boundary (every arm
9792    /// returns `false`), a single-populated-per-side arrangement (both
9793    /// per-slice arms return `false` on any `N ≥ 2` closed set; the
9794    /// union returns `false` unless the two kinds are distinct AND
9795    /// `N == 2`), and the saturated boundary (both slices carry every
9796    /// [`ConditionKind`], every arm returns `true`). Also pins the
9797    /// composition law `is_*_kind_saturated() ==
9798    /// missing_*_kinds().is_empty()` at each arm — a regression that
9799    /// dropped the `all` short-circuit, drifted the walk from
9800    /// `ConditionKind::ALL`, or negated the wrong side surfaces HERE.
9801    #[test]
9802    fn is_condition_kind_saturated_triad_delegates_to_slice_is_kind_saturated() {
9803        // Empty boundary — every arm returns false; missing_*_kinds
9804        // covers the full closed set on every arm.
9805        let b = Boundary::default();
9806        assert!(
9807            !b.is_precondition_kind_saturated(),
9808            "empty boundary must return false on is_precondition_kind_saturated",
9809        );
9810        assert!(
9811            !b.is_postcondition_kind_saturated(),
9812            "empty boundary must return false on is_postcondition_kind_saturated",
9813        );
9814        assert!(
9815            !b.is_condition_kind_saturated(),
9816            "empty boundary must return false on is_condition_kind_saturated",
9817        );
9818        assert_eq!(
9819            b.is_precondition_kind_saturated(),
9820            b.missing_precondition_kinds().is_empty(),
9821            "empty is_precondition_kind_saturated must equal missing_precondition_kinds().is_empty()",
9822        );
9823
9824        // Single-populated per side — every per-slice arm returns
9825        // false on any N ≥ 2 closed set; the union returns false too
9826        // (needs every ALL kind covered).
9827        for pre_kind in ConditionKind::ALL {
9828            for post_kind in ConditionKind::ALL {
9829                let mut b = Boundary::default();
9830                b.preconditions.push(condition_with(pre_kind));
9831                b.postconditions.push(condition_with(post_kind));
9832                assert_eq!(
9833                    b.is_precondition_kind_saturated(),
9834                    b.preconditions.is_kind_saturated(),
9835                    "Boundary::is_precondition_kind_saturated must delegate verbatim to \
9836                     preconditions.is_kind_saturated() for pre={pre_kind:?} post={post_kind:?}",
9837                );
9838                assert_eq!(
9839                    b.is_postcondition_kind_saturated(),
9840                    b.postconditions.is_kind_saturated(),
9841                    "Boundary::is_postcondition_kind_saturated must delegate verbatim to \
9842                     postconditions.is_kind_saturated() for pre={pre_kind:?} post={post_kind:?}",
9843                );
9844                let expected_union = ConditionKind::ALL
9845                    .iter()
9846                    .all(|k| pre_kind == *k || post_kind == *k);
9847                assert_eq!(
9848                    b.is_condition_kind_saturated(),
9849                    expected_union,
9850                    "Boundary::is_condition_kind_saturated must equal all-ALL-covered-by-either-slice \
9851                     for pre={pre_kind:?} post={post_kind:?}",
9852                );
9853                assert_eq!(
9854                    b.is_condition_kind_saturated(),
9855                    b.missing_condition_kinds().is_empty(),
9856                    "Boundary::is_condition_kind_saturated must equal missing_condition_kinds().is_empty() \
9857                     for pre={pre_kind:?} post={post_kind:?}",
9858                );
9859            }
9860        }
9861
9862        // Saturated boundary — both slices carry every ConditionKind
9863        // at least once, every arm returns true.
9864        let mut b = Boundary::default();
9865        for k in ConditionKind::ALL {
9866            b.preconditions.push(condition_with(k));
9867            b.postconditions.push(condition_with(k));
9868        }
9869        assert!(
9870            b.is_precondition_kind_saturated(),
9871            "saturated boundary must return true on is_precondition_kind_saturated",
9872        );
9873        assert!(
9874            b.is_postcondition_kind_saturated(),
9875            "saturated boundary must return true on is_postcondition_kind_saturated",
9876        );
9877        assert!(
9878            b.is_condition_kind_saturated(),
9879            "saturated boundary must return true on is_condition_kind_saturated",
9880        );
9881    }
9882
9883    /// SUBSTRATE-DELEGATION pin (Boundary at-least-one halfspace
9884    /// triad) — the three `has_any_missing_*_condition_kind` methods
9885    /// on [`Boundary`] delegate to the slice-level substrate primitive
9886    /// [`ConditionSliceExt::has_any_missing_kind`] over the two
9887    /// `Vec<Condition>` slots (precondition + postcondition) and
9888    /// compose the union via `!self.is_condition_kind_saturated()`.
9889    /// Sweeps the empty boundary (every arm returns `true`), a single-
9890    /// populated-per-side arrangement (both per-slice arms return
9891    /// `true` on any `N ≥ 2` closed set; the union returns `true`
9892    /// unless the two kinds together cover every ALL variant), and
9893    /// the saturated boundary (both slices carry every
9894    /// [`ConditionKind`], every arm returns `false`). Also pins the
9895    /// composition law `has_any_missing_*_condition_kind() ==
9896    /// !is_*_condition_kind_saturated()` at each arm — a regression
9897    /// that dropped the negation, drifted the underlying saturation
9898    /// primitive, or negated the wrong side surfaces HERE.
9899    #[test]
9900    fn has_any_missing_condition_kind_triad_delegates_to_slice_has_any_missing_kind() {
9901        // Empty boundary — every arm returns true (every kind is
9902        // missing from every slice + from the union).
9903        let b = Boundary::default();
9904        assert!(
9905            b.has_any_missing_precondition_kind(),
9906            "empty boundary must return true on has_any_missing_precondition_kind",
9907        );
9908        assert!(
9909            b.has_any_missing_postcondition_kind(),
9910            "empty boundary must return true on has_any_missing_postcondition_kind",
9911        );
9912        assert!(
9913            b.has_any_missing_condition_kind(),
9914            "empty boundary must return true on has_any_missing_condition_kind",
9915        );
9916        assert_eq!(
9917            b.has_any_missing_condition_kind(),
9918            !b.is_condition_kind_saturated(),
9919            "empty has_any_missing_condition_kind must equal !is_condition_kind_saturated()",
9920        );
9921
9922        // Single-populated per side — sweep ALL × ALL. Every per-slice
9923        // arm returns true on any N ≥ 2 closed set; the union returns
9924        // true unless the two kinds together cover every ALL variant.
9925        for pre_kind in ConditionKind::ALL {
9926            for post_kind in ConditionKind::ALL {
9927                let mut b = Boundary::default();
9928                b.preconditions.push(condition_with(pre_kind));
9929                b.postconditions.push(condition_with(post_kind));
9930                assert_eq!(
9931                    b.has_any_missing_precondition_kind(),
9932                    b.preconditions.has_any_missing_kind(),
9933                    "Boundary::has_any_missing_precondition_kind must delegate verbatim to \
9934                     preconditions.has_any_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
9935                );
9936                assert_eq!(
9937                    b.has_any_missing_postcondition_kind(),
9938                    b.postconditions.has_any_missing_kind(),
9939                    "Boundary::has_any_missing_postcondition_kind must delegate verbatim to \
9940                     postconditions.has_any_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
9941                );
9942                let expected_union = !ConditionKind::ALL
9943                    .iter()
9944                    .all(|k| pre_kind == *k || post_kind == *k);
9945                assert_eq!(
9946                    b.has_any_missing_condition_kind(),
9947                    expected_union,
9948                    "Boundary::has_any_missing_condition_kind must equal \
9949                     !all-ALL-covered-by-either-slice \
9950                     for pre={pre_kind:?} post={post_kind:?}",
9951                );
9952                assert_eq!(
9953                    b.has_any_missing_condition_kind(),
9954                    !b.is_condition_kind_saturated(),
9955                    "Boundary::has_any_missing_condition_kind must equal \
9956                     !is_condition_kind_saturated() for pre={pre_kind:?} post={post_kind:?}",
9957                );
9958            }
9959        }
9960
9961        // Saturated boundary — both slices carry every ConditionKind
9962        // at least once, every arm returns false.
9963        let mut b = Boundary::default();
9964        for k in ConditionKind::ALL {
9965            b.preconditions.push(condition_with(k));
9966            b.postconditions.push(condition_with(k));
9967        }
9968        assert!(
9969            !b.has_any_missing_precondition_kind(),
9970            "saturated boundary must return false on has_any_missing_precondition_kind",
9971        );
9972        assert!(
9973            !b.has_any_missing_postcondition_kind(),
9974            "saturated boundary must return false on has_any_missing_postcondition_kind",
9975        );
9976        assert!(
9977            !b.has_any_missing_condition_kind(),
9978            "saturated boundary must return false on has_any_missing_condition_kind",
9979        );
9980    }
9981
9982    /// SUBSTRATE-DELEGATION pin (Boundary at-least-one halfspace triad
9983    /// on the closed-set-inversion axis) — the three
9984    /// `has_any_distinct_*_condition_kind` methods on [`Boundary`]
9985    /// delegate to the slice-level substrate primitive
9986    /// [`ConditionSliceExt::has_any_distinct_kind`] over the two
9987    /// `Vec<Condition>` slots (precondition + postcondition) and
9988    /// compose the union via a SHORT-CIRCUITING closed-set walk over
9989    /// [`ConditionKind::ALL`] under [`Boundary::has_condition_kind`].
9990    /// Sweeps the empty boundary (every arm returns `false` — no kind
9991    /// present in either slice), a single-populated-per-side
9992    /// arrangement (every per-slice arm returns `true`, the union
9993    /// returns `true`), a single-populated-precondition-only
9994    /// arrangement (precondition arm `true`, postcondition arm
9995    /// `false`, union `true`), and the saturated boundary (every arm
9996    /// returns `true`). Also pins the composition law
9997    /// `has_any_distinct_*_condition_kind() ==
9998    /// (distinct_*_condition_kind_count() > 0)` at each arm — a
9999    /// regression that dropped the short-circuit, drifted the
10000    /// underlying `has_condition_kind` predicate, or negated the wrong
10001    /// side surfaces HERE.
10002    #[test]
10003    fn has_any_distinct_condition_kind_triad_delegates_to_slice_has_any_distinct_kind() {
10004        // Empty boundary — every arm returns false (no kind present
10005        // in either slice; distinct_kind_count == 0 in both).
10006        let b = Boundary::default();
10007        assert!(
10008            !b.has_any_distinct_precondition_kind(),
10009            "empty boundary must return false on has_any_distinct_precondition_kind",
10010        );
10011        assert!(
10012            !b.has_any_distinct_postcondition_kind(),
10013            "empty boundary must return false on has_any_distinct_postcondition_kind",
10014        );
10015        assert!(
10016            !b.has_any_distinct_condition_kind(),
10017            "empty boundary must return false on has_any_distinct_condition_kind",
10018        );
10019
10020        // Single-populated per side — sweep ALL × ALL. Every per-slice
10021        // arm returns true; the union returns true.
10022        for pre_kind in ConditionKind::ALL {
10023            for post_kind in ConditionKind::ALL {
10024                let mut b = Boundary::default();
10025                b.preconditions.push(condition_with(pre_kind));
10026                b.postconditions.push(condition_with(post_kind));
10027                assert_eq!(
10028                    b.has_any_distinct_precondition_kind(),
10029                    b.preconditions.has_any_distinct_kind(),
10030                    "Boundary::has_any_distinct_precondition_kind must delegate verbatim to \
10031                     preconditions.has_any_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
10032                );
10033                assert_eq!(
10034                    b.has_any_distinct_postcondition_kind(),
10035                    b.postconditions.has_any_distinct_kind(),
10036                    "Boundary::has_any_distinct_postcondition_kind must delegate verbatim to \
10037                     postconditions.has_any_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
10038                );
10039                assert!(
10040                    b.has_any_distinct_precondition_kind(),
10041                    "single-populated preconditions must return true on has_any_distinct_precondition_kind for pre={pre_kind:?}",
10042                );
10043                assert!(
10044                    b.has_any_distinct_postcondition_kind(),
10045                    "single-populated postconditions must return true on has_any_distinct_postcondition_kind for post={post_kind:?}",
10046                );
10047                assert!(
10048                    b.has_any_distinct_condition_kind(),
10049                    "single-populated-per-side must return true on has_any_distinct_condition_kind for pre={pre_kind:?} post={post_kind:?}",
10050                );
10051            }
10052        }
10053
10054        // Single-populated precondition only — precondition arm true,
10055        // postcondition arm false, union true.
10056        for pre_kind in ConditionKind::ALL {
10057            let mut b = Boundary::default();
10058            b.preconditions.push(condition_with(pre_kind));
10059            assert!(
10060                b.has_any_distinct_precondition_kind(),
10061                "pre-only boundary must return true on has_any_distinct_precondition_kind for pre={pre_kind:?}",
10062            );
10063            assert!(
10064                !b.has_any_distinct_postcondition_kind(),
10065                "pre-only boundary must return false on has_any_distinct_postcondition_kind for pre={pre_kind:?}",
10066            );
10067            assert!(
10068                b.has_any_distinct_condition_kind(),
10069                "pre-only boundary must return true on has_any_distinct_condition_kind for pre={pre_kind:?}",
10070            );
10071        }
10072
10073        // Saturated boundary — both slices carry every ConditionKind
10074        // at least once; every arm returns true.
10075        let mut b = Boundary::default();
10076        for k in ConditionKind::ALL {
10077            b.preconditions.push(condition_with(k));
10078            b.postconditions.push(condition_with(k));
10079        }
10080        assert!(
10081            b.has_any_distinct_precondition_kind(),
10082            "saturated boundary must return true on has_any_distinct_precondition_kind",
10083        );
10084        assert!(
10085            b.has_any_distinct_postcondition_kind(),
10086            "saturated boundary must return true on has_any_distinct_postcondition_kind",
10087        );
10088        assert!(
10089            b.has_any_distinct_condition_kind(),
10090            "saturated boundary must return true on has_any_distinct_condition_kind",
10091        );
10092    }
10093
10094    /// SUBSTRATE-DELEGATION pin (Boundary cardinality-mid-endpoint
10095    /// triad) — the three `has_unique_missing_*_condition_kind`
10096    /// methods on [`Boundary`] delegate to the slice-level substrate
10097    /// primitive [`ConditionSliceExt::has_unique_missing_kind`] over
10098    /// the two `Vec<Condition>` slots (precondition + postcondition)
10099    /// and compose the union via a two-step-short-circuit walk over
10100    /// [`ConditionKind::ALL`] under negated
10101    /// [`Boundary::has_condition_kind`]. Sweeps the empty boundary
10102    /// (every arm returns `false` — all N missing, not exactly 1),
10103    /// the near-saturation-endpoint (each slice carries every
10104    /// [`ConditionKind`] except one — every per-slice arm returns
10105    /// `true`; the union returns `true` iff BOTH slices omit the SAME
10106    /// kind), the saturated boundary (every arm returns `false` — 0
10107    /// missing), and a single-populated-per-side arrangement (every
10108    /// per-slice arm returns `false` on any `N ≥ 3` closed set; the
10109    /// union returns `true` only when the two kinds together leave
10110    /// exactly one kind uncovered). Also pins the composition law
10111    /// `has_unique_missing_*_condition_kind() ==
10112    /// (missing_*_condition_kind_count() == 1)` at each arm — a
10113    /// regression that dropped the second-slot short-circuit, drifted
10114    /// the underlying `has_kind` predicate, or conflated with
10115    /// `is_kind_saturated` surfaces HERE.
10116    #[test]
10117    fn has_unique_missing_condition_kind_triad_delegates_to_slice_has_unique_missing_kind() {
10118        // Empty boundary — every arm returns false (all N missing,
10119        // not exactly 1) on any N ≥ 2 closed set.
10120        assert!(
10121            ConditionKind::ALL.len() >= 2,
10122            "test assumes ConditionKind::ALL has ≥ 2 variants",
10123        );
10124        let b = Boundary::default();
10125        assert!(
10126            !b.has_unique_missing_precondition_kind(),
10127            "empty boundary must return false on has_unique_missing_precondition_kind",
10128        );
10129        assert!(
10130            !b.has_unique_missing_postcondition_kind(),
10131            "empty boundary must return false on has_unique_missing_postcondition_kind",
10132        );
10133        assert!(
10134            !b.has_unique_missing_condition_kind(),
10135            "empty boundary must return false on has_unique_missing_condition_kind",
10136        );
10137        assert_eq!(
10138            b.has_unique_missing_condition_kind(),
10139            b.missing_condition_kind_count() == 1,
10140            "empty has_unique_missing_condition_kind must equal (missing_condition_kind_count() == 1)",
10141        );
10142
10143        // Single-populated per side — sweep ALL × ALL on N ≥ 3 closed
10144        // sets. Every per-slice arm returns false (N - 1 ≥ 2 kinds
10145        // missing per slice); the union returns true iff the two kinds
10146        // together leave exactly one ALL variant uncovered.
10147        if ConditionKind::ALL.len() >= 3 {
10148            for pre_kind in ConditionKind::ALL {
10149                for post_kind in ConditionKind::ALL {
10150                    let mut b = Boundary::default();
10151                    b.preconditions.push(condition_with(pre_kind));
10152                    b.postconditions.push(condition_with(post_kind));
10153                    assert_eq!(
10154                        b.has_unique_missing_precondition_kind(),
10155                        b.preconditions.has_unique_missing_kind(),
10156                        "Boundary::has_unique_missing_precondition_kind must delegate verbatim to \
10157                         preconditions.has_unique_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10158                    );
10159                    assert_eq!(
10160                        b.has_unique_missing_postcondition_kind(),
10161                        b.postconditions.has_unique_missing_kind(),
10162                        "Boundary::has_unique_missing_postcondition_kind must delegate verbatim to \
10163                         postconditions.has_unique_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10164                    );
10165                    let uncovered = ConditionKind::ALL
10166                        .into_iter()
10167                        .filter(|k| *k != pre_kind && *k != post_kind)
10168                        .count();
10169                    let expected_union = uncovered == 1;
10170                    assert_eq!(
10171                        b.has_unique_missing_condition_kind(),
10172                        expected_union,
10173                        "Boundary::has_unique_missing_condition_kind must equal \
10174                         (uncovered-ALL-count == 1) for pre={pre_kind:?} post={post_kind:?}",
10175                    );
10176                    assert_eq!(
10177                        b.has_unique_missing_condition_kind(),
10178                        b.missing_condition_kind_count() == 1,
10179                        "Boundary::has_unique_missing_condition_kind must equal \
10180                         (missing_condition_kind_count() == 1) for pre={pre_kind:?} post={post_kind:?}",
10181                    );
10182                }
10183            }
10184        }
10185
10186        // Near-saturation-endpoint per side — each slice carries
10187        // every ConditionKind except one; every per-slice arm returns
10188        // true. The union returns true iff BOTH slices omit the SAME
10189        // kind (otherwise the two omissions are covered by each
10190        // other and the union is saturated).
10191        for pre_omit in ConditionKind::ALL {
10192            for post_omit in ConditionKind::ALL {
10193                let mut b = Boundary::default();
10194                for k in ConditionKind::ALL {
10195                    if k != pre_omit {
10196                        b.preconditions.push(condition_with(k));
10197                    }
10198                    if k != post_omit {
10199                        b.postconditions.push(condition_with(k));
10200                    }
10201                }
10202                assert!(
10203                    b.has_unique_missing_precondition_kind(),
10204                    "near-saturation-endpoint precondition slice (omitting {pre_omit:?}) must return true on has_unique_missing_precondition_kind",
10205                );
10206                assert!(
10207                    b.has_unique_missing_postcondition_kind(),
10208                    "near-saturation-endpoint postcondition slice (omitting {post_omit:?}) must return true on has_unique_missing_postcondition_kind",
10209                );
10210                let expected_union = pre_omit == post_omit;
10211                assert_eq!(
10212                    b.has_unique_missing_condition_kind(),
10213                    expected_union,
10214                    "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:?}",
10215                );
10216                assert_eq!(
10217                    b.has_unique_missing_condition_kind(),
10218                    b.missing_condition_kind_count() == 1,
10219                    "Boundary::has_unique_missing_condition_kind must equal (missing_condition_kind_count() == 1) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
10220                );
10221            }
10222        }
10223
10224        // Saturated boundary — every arm returns false (0 missing,
10225        // not exactly 1).
10226        let mut b = Boundary::default();
10227        for k in ConditionKind::ALL {
10228            b.preconditions.push(condition_with(k));
10229            b.postconditions.push(condition_with(k));
10230        }
10231        assert!(
10232            !b.has_unique_missing_precondition_kind(),
10233            "saturated boundary must return false on has_unique_missing_precondition_kind",
10234        );
10235        assert!(
10236            !b.has_unique_missing_postcondition_kind(),
10237            "saturated boundary must return false on has_unique_missing_postcondition_kind",
10238        );
10239        assert!(
10240            !b.has_unique_missing_condition_kind(),
10241            "saturated boundary must return false on has_unique_missing_condition_kind",
10242        );
10243    }
10244
10245    /// SUBSTRATE-DELEGATION pin (Boundary cardinality-many-arm triad)
10246    /// — the three `has_multiple_missing_*_condition_kind` methods on
10247    /// [`Boundary`] delegate to the slice-level substrate primitive
10248    /// [`ConditionSliceExt::has_multiple_missing_kinds`] over the two
10249    /// `Vec<Condition>` slots (precondition + postcondition) and
10250    /// compose the union via a two-step-short-circuit walk over
10251    /// [`ConditionKind::ALL`] under negated
10252    /// [`Boundary::has_condition_kind`]. Sweeps the empty boundary
10253    /// (every arm returns `true` — all N missing, ≥ 2), the near-
10254    /// saturation-endpoint (each slice carries every
10255    /// [`ConditionKind`] except one — every per-slice arm returns
10256    /// `false`; the union returns `true` iff the two slices omit
10257    /// DIFFERENT kinds), the saturated boundary (every arm returns
10258    /// `false` — 0 missing), and a single-populated-per-side
10259    /// arrangement (every per-slice arm returns `true` on any `N ≥ 3`
10260    /// closed set; the union returns `true` when the two kinds
10261    /// together leave ≥ 2 kinds uncovered). Also pins the composition
10262    /// law `has_multiple_missing_*_condition_kind() ==
10263    /// (missing_*_condition_kind_count() >= 2)` at each arm — a
10264    /// regression that dropped the second-slot short-circuit, drifted
10265    /// the underlying `has_kind` predicate, or conflated with
10266    /// `has_any_missing_kind` surfaces HERE.
10267    #[test]
10268    fn has_multiple_missing_condition_kind_triad_delegates_to_slice_has_multiple_missing_kinds() {
10269        // Empty boundary — every arm returns true (all N missing,
10270        // ≥ 2) on any N ≥ 2 closed set.
10271        assert!(
10272            ConditionKind::ALL.len() >= 2,
10273            "test assumes ConditionKind::ALL has ≥ 2 variants",
10274        );
10275        let b = Boundary::default();
10276        assert!(
10277            b.has_multiple_missing_precondition_kind(),
10278            "empty boundary must return true on has_multiple_missing_precondition_kind",
10279        );
10280        assert!(
10281            b.has_multiple_missing_postcondition_kind(),
10282            "empty boundary must return true on has_multiple_missing_postcondition_kind",
10283        );
10284        assert!(
10285            b.has_multiple_missing_condition_kind(),
10286            "empty boundary must return true on has_multiple_missing_condition_kind",
10287        );
10288        assert_eq!(
10289            b.has_multiple_missing_condition_kind(),
10290            b.missing_condition_kind_count() >= 2,
10291            "empty has_multiple_missing_condition_kind must equal (missing_condition_kind_count() >= 2)",
10292        );
10293
10294        // Single-populated per side — sweep ALL × ALL on N ≥ 3 closed
10295        // sets. Every per-slice arm returns true (N - 1 ≥ 2 kinds
10296        // missing per slice); the union returns true iff the two
10297        // kinds together leave ≥ 2 ALL variants uncovered.
10298        if ConditionKind::ALL.len() >= 3 {
10299            for pre_kind in ConditionKind::ALL {
10300                for post_kind in ConditionKind::ALL {
10301                    let mut b = Boundary::default();
10302                    b.preconditions.push(condition_with(pre_kind));
10303                    b.postconditions.push(condition_with(post_kind));
10304                    assert_eq!(
10305                        b.has_multiple_missing_precondition_kind(),
10306                        b.preconditions.has_multiple_missing_kinds(),
10307                        "Boundary::has_multiple_missing_precondition_kind must delegate verbatim to \
10308                         preconditions.has_multiple_missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
10309                    );
10310                    assert_eq!(
10311                        b.has_multiple_missing_postcondition_kind(),
10312                        b.postconditions.has_multiple_missing_kinds(),
10313                        "Boundary::has_multiple_missing_postcondition_kind must delegate verbatim to \
10314                         postconditions.has_multiple_missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
10315                    );
10316                    let uncovered = ConditionKind::ALL
10317                        .into_iter()
10318                        .filter(|k| *k != pre_kind && *k != post_kind)
10319                        .count();
10320                    let expected_union = uncovered >= 2;
10321                    assert_eq!(
10322                        b.has_multiple_missing_condition_kind(),
10323                        expected_union,
10324                        "Boundary::has_multiple_missing_condition_kind must equal \
10325                         (uncovered-ALL-count >= 2) for pre={pre_kind:?} post={post_kind:?}",
10326                    );
10327                    assert_eq!(
10328                        b.has_multiple_missing_condition_kind(),
10329                        b.missing_condition_kind_count() >= 2,
10330                        "Boundary::has_multiple_missing_condition_kind must equal \
10331                         (missing_condition_kind_count() >= 2) for pre={pre_kind:?} post={post_kind:?}",
10332                    );
10333                }
10334            }
10335        }
10336
10337        // Near-saturation-endpoint per side — each slice carries
10338        // every ConditionKind except one; every per-slice arm returns
10339        // false (exactly 1 missing per slice, not ≥ 2). The union
10340        // returns true iff the two slices omit DIFFERENT kinds
10341        // (otherwise both omissions coincide and the union has
10342        // exactly 1 missing, not ≥ 2).
10343        for pre_omit in ConditionKind::ALL {
10344            for post_omit in ConditionKind::ALL {
10345                let mut b = Boundary::default();
10346                for k in ConditionKind::ALL {
10347                    if k != pre_omit {
10348                        b.preconditions.push(condition_with(k));
10349                    }
10350                    if k != post_omit {
10351                        b.postconditions.push(condition_with(k));
10352                    }
10353                }
10354                assert!(
10355                    !b.has_multiple_missing_precondition_kind(),
10356                    "near-saturation-endpoint precondition slice (omitting {pre_omit:?}) must return false on has_multiple_missing_precondition_kind",
10357                );
10358                assert!(
10359                    !b.has_multiple_missing_postcondition_kind(),
10360                    "near-saturation-endpoint postcondition slice (omitting {post_omit:?}) must return false on has_multiple_missing_postcondition_kind",
10361                );
10362                // Union: pre-only-missing = {pre_omit}, post-only-
10363                // missing = {post_omit}. Union missing = both
10364                // omissions ∩ each other only when they coincide.
10365                let expected_union = false;
10366                assert_eq!(
10367                    b.has_multiple_missing_condition_kind(),
10368                    expected_union,
10369                    "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:?}",
10370                );
10371                assert_eq!(
10372                    b.has_multiple_missing_condition_kind(),
10373                    b.missing_condition_kind_count() >= 2,
10374                    "Boundary::has_multiple_missing_condition_kind must equal (missing_condition_kind_count() >= 2) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
10375                );
10376            }
10377        }
10378
10379        // Saturated boundary — every arm returns false (0 missing,
10380        // not ≥ 2).
10381        let mut b = Boundary::default();
10382        for k in ConditionKind::ALL {
10383            b.preconditions.push(condition_with(k));
10384            b.postconditions.push(condition_with(k));
10385        }
10386        assert!(
10387            !b.has_multiple_missing_precondition_kind(),
10388            "saturated boundary must return false on has_multiple_missing_precondition_kind",
10389        );
10390        assert!(
10391            !b.has_multiple_missing_postcondition_kind(),
10392            "saturated boundary must return false on has_multiple_missing_postcondition_kind",
10393        );
10394        assert!(
10395            !b.has_multiple_missing_condition_kind(),
10396            "saturated boundary must return false on has_multiple_missing_condition_kind",
10397        );
10398    }
10399
10400    /// SUBSTRATE-DELEGATION pin (Boundary cardinality "≤ 1" triad) —
10401    /// the three `has_at_most_one_missing_*_condition_kind` methods on
10402    /// [`Boundary`] delegate to the slice-level substrate primitive
10403    /// [`ConditionSliceExt::has_at_most_one_missing_kind`] over the
10404    /// two `Vec<Condition>` slots (precondition + postcondition) and
10405    /// compose the union via
10406    /// `!self.has_multiple_missing_condition_kind()` — a definitional
10407    /// negation of the many-arm union primitive. Sweeps the empty
10408    /// boundary (every arm returns `false` — `N ≥ 2` missing, not
10409    /// `≤ 1`), the near-saturation-endpoint (each slice carries
10410    /// every [`ConditionKind`] except one — every per-slice arm
10411    /// returns `true`; the union returns `true` — since the union of
10412    /// two near-saturated slices always has `≤ 1` missing), the
10413    /// saturated boundary (every arm returns `true` — 0 missing,
10414    /// `≤ 1`), and a single-populated-per-side arrangement (every
10415    /// per-slice arm returns `false` on any `N ≥ 3` closed set; the
10416    /// union returns `true` iff the two kinds together leave `≤ 1`
10417    /// kind uncovered — the near-saturation-endpoint of the union
10418    /// axis). Also pins the composition law
10419    /// `has_at_most_one_missing_*_condition_kind() ==
10420    /// (missing_*_condition_kind_count() <= 1)` at each arm — a
10421    /// regression that dropped the definitional negation (returning
10422    /// `has_multiple_missing_condition_kind` itself), swapped the
10423    /// wrong side, or drifted the trichotomy union operator from
10424    /// `||` to `&&` surfaces HERE.
10425    #[test]
10426    fn has_at_most_one_missing_condition_kind_triad_delegates_to_slice_has_at_most_one_missing_kind(
10427    ) {
10428        // Empty boundary — every arm returns false (all N missing,
10429        // not ≤ 1) on any N ≥ 2 closed set.
10430        assert!(
10431            ConditionKind::ALL.len() >= 2,
10432            "test assumes ConditionKind::ALL has ≥ 2 variants",
10433        );
10434        let b = Boundary::default();
10435        assert!(
10436            !b.has_at_most_one_missing_precondition_kind(),
10437            "empty boundary must return false on has_at_most_one_missing_precondition_kind",
10438        );
10439        assert!(
10440            !b.has_at_most_one_missing_postcondition_kind(),
10441            "empty boundary must return false on has_at_most_one_missing_postcondition_kind",
10442        );
10443        assert!(
10444            !b.has_at_most_one_missing_condition_kind(),
10445            "empty boundary must return false on has_at_most_one_missing_condition_kind",
10446        );
10447        assert_eq!(
10448            b.has_at_most_one_missing_condition_kind(),
10449            b.missing_condition_kind_count() <= 1,
10450            "empty has_at_most_one_missing_condition_kind must equal (missing_condition_kind_count() <= 1)",
10451        );
10452
10453        // Single-populated per side — sweep ALL × ALL on N ≥ 3
10454        // closed sets. Every per-slice arm returns false (N - 1 ≥ 2
10455        // kinds missing per slice, not ≤ 1); the union returns true
10456        // iff the two kinds together leave ≤ 1 ALL variant
10457        // uncovered — the near-saturation-endpoint of the union
10458        // axis.
10459        if ConditionKind::ALL.len() >= 3 {
10460            for pre_kind in ConditionKind::ALL {
10461                for post_kind in ConditionKind::ALL {
10462                    let mut b = Boundary::default();
10463                    b.preconditions.push(condition_with(pre_kind));
10464                    b.postconditions.push(condition_with(post_kind));
10465                    assert_eq!(
10466                        b.has_at_most_one_missing_precondition_kind(),
10467                        b.preconditions.has_at_most_one_missing_kind(),
10468                        "Boundary::has_at_most_one_missing_precondition_kind must delegate verbatim to \
10469                         preconditions.has_at_most_one_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10470                    );
10471                    assert_eq!(
10472                        b.has_at_most_one_missing_postcondition_kind(),
10473                        b.postconditions.has_at_most_one_missing_kind(),
10474                        "Boundary::has_at_most_one_missing_postcondition_kind must delegate verbatim to \
10475                         postconditions.has_at_most_one_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10476                    );
10477                    let uncovered = ConditionKind::ALL
10478                        .into_iter()
10479                        .filter(|k| *k != pre_kind && *k != post_kind)
10480                        .count();
10481                    let expected_union = uncovered <= 1;
10482                    assert_eq!(
10483                        b.has_at_most_one_missing_condition_kind(),
10484                        expected_union,
10485                        "Boundary::has_at_most_one_missing_condition_kind must equal \
10486                         (uncovered-ALL-count <= 1) for pre={pre_kind:?} post={post_kind:?}",
10487                    );
10488                    assert_eq!(
10489                        b.has_at_most_one_missing_condition_kind(),
10490                        !b.has_multiple_missing_condition_kind(),
10491                        "Boundary::has_at_most_one_missing_condition_kind must equal \
10492                         !has_multiple_missing_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
10493                    );
10494                    assert_eq!(
10495                        b.has_at_most_one_missing_condition_kind(),
10496                        b.missing_condition_kind_count() <= 1,
10497                        "Boundary::has_at_most_one_missing_condition_kind must equal \
10498                         (missing_condition_kind_count() <= 1) for pre={pre_kind:?} post={post_kind:?}",
10499                    );
10500                }
10501            }
10502        }
10503
10504        // Near-saturation-endpoint per side — each slice carries
10505        // every ConditionKind except one; every per-slice arm returns
10506        // true (exactly 1 missing per slice, ≤ 1). The union has ≤ 1
10507        // missing whether or not the two omissions coincide, so the
10508        // union is always true on this arm.
10509        for pre_omit in ConditionKind::ALL {
10510            for post_omit in ConditionKind::ALL {
10511                let mut b = Boundary::default();
10512                for k in ConditionKind::ALL {
10513                    if k != pre_omit {
10514                        b.preconditions.push(condition_with(k));
10515                    }
10516                    if k != post_omit {
10517                        b.postconditions.push(condition_with(k));
10518                    }
10519                }
10520                assert!(
10521                    b.has_at_most_one_missing_precondition_kind(),
10522                    "near-saturation-endpoint precondition slice (omitting {pre_omit:?}) must return true on has_at_most_one_missing_precondition_kind",
10523                );
10524                assert!(
10525                    b.has_at_most_one_missing_postcondition_kind(),
10526                    "near-saturation-endpoint postcondition slice (omitting {post_omit:?}) must return true on has_at_most_one_missing_postcondition_kind",
10527                );
10528                assert!(
10529                    b.has_at_most_one_missing_condition_kind(),
10530                    "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:?}",
10531                );
10532                assert_eq!(
10533                    b.has_at_most_one_missing_condition_kind(),
10534                    b.missing_condition_kind_count() <= 1,
10535                    "Boundary::has_at_most_one_missing_condition_kind must equal (missing_condition_kind_count() <= 1) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
10536                );
10537            }
10538        }
10539
10540        // Saturated boundary — every arm returns true (0 missing,
10541        // ≤ 1).
10542        let mut b = Boundary::default();
10543        for k in ConditionKind::ALL {
10544            b.preconditions.push(condition_with(k));
10545            b.postconditions.push(condition_with(k));
10546        }
10547        assert!(
10548            b.has_at_most_one_missing_precondition_kind(),
10549            "saturated boundary must return true on has_at_most_one_missing_precondition_kind",
10550        );
10551        assert!(
10552            b.has_at_most_one_missing_postcondition_kind(),
10553            "saturated boundary must return true on has_at_most_one_missing_postcondition_kind",
10554        );
10555        assert!(
10556            b.has_at_most_one_missing_condition_kind(),
10557            "saturated boundary must return true on has_at_most_one_missing_condition_kind",
10558        );
10559    }
10560
10561    /// SUBSTRATE-DELEGATION pin (Boundary per-kind-complement triad) —
10562    /// the three `lacks_*_condition_kind` methods on [`Boundary`]
10563    /// delegate to the slice-level substrate primitive
10564    /// [`ConditionSliceExt::lacks_kind`] over the two `Vec<Condition>`
10565    /// slots (precondition + postcondition) and compose the union via
10566    /// `!self.has_condition_kind(kind)`. Sweeps the empty boundary
10567    /// (every arm returns `true` for every kind), a single-populated-
10568    /// per-side arrangement (per-slice arms return `false` on the
10569    /// populated kind + `true` on every other kind; the union returns
10570    /// `false` iff EITHER slice populates the addressed kind), and the
10571    /// saturated boundary (both slices carry every [`ConditionKind`],
10572    /// every arm returns `false` for every kind). Also pins the
10573    /// composition laws `lacks_*_condition_kind(k) ==
10574    /// !has_*_condition_kind(k)` at each arm AND `lacks_condition_kind(k)
10575    /// == lacks_precondition_kind(k) && lacks_postcondition_kind(k)`
10576    /// (the union AND-composition dual of `has`'s OR-composition) — a
10577    /// regression that dropped the negation, drifted the union operator
10578    /// to `||`, or negated the wrong side surfaces HERE.
10579    #[test]
10580    fn lacks_condition_kind_triad_delegates_to_slice_lacks_kind() {
10581        // Empty boundary — every arm returns true on every kind.
10582        let b = Boundary::default();
10583        for kind in ConditionKind::ALL {
10584            assert!(
10585                b.lacks_precondition_kind(kind),
10586                "empty boundary must return true on lacks_precondition_kind for {kind:?}",
10587            );
10588            assert!(
10589                b.lacks_postcondition_kind(kind),
10590                "empty boundary must return true on lacks_postcondition_kind for {kind:?}",
10591            );
10592            assert!(
10593                b.lacks_condition_kind(kind),
10594                "empty boundary must return true on lacks_condition_kind for {kind:?}",
10595            );
10596            assert_eq!(
10597                b.lacks_condition_kind(kind),
10598                !b.has_condition_kind(kind),
10599                "empty lacks_condition_kind must equal !has_condition_kind for {kind:?}",
10600            );
10601        }
10602
10603        // Single-populated per side — sweep ALL × ALL, then probe every
10604        // ConditionKind on the (pre, post, union) triad.
10605        for pre_kind in ConditionKind::ALL {
10606            for post_kind in ConditionKind::ALL {
10607                let mut b = Boundary::default();
10608                b.preconditions.push(condition_with(pre_kind));
10609                b.postconditions.push(condition_with(post_kind));
10610                for probe in ConditionKind::ALL {
10611                    assert_eq!(
10612                        b.lacks_precondition_kind(probe),
10613                        b.preconditions.lacks_kind(probe),
10614                        "Boundary::lacks_precondition_kind must delegate verbatim to preconditions.lacks_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10615                    );
10616                    assert_eq!(
10617                        b.lacks_postcondition_kind(probe),
10618                        b.postconditions.lacks_kind(probe),
10619                        "Boundary::lacks_postcondition_kind must delegate verbatim to postconditions.lacks_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10620                    );
10621                    let expected_union = pre_kind != probe && post_kind != probe;
10622                    assert_eq!(
10623                        b.lacks_condition_kind(probe),
10624                        expected_union,
10625                        "Boundary::lacks_condition_kind must equal all-ALL-absent-in-both-slices for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10626                    );
10627                    assert_eq!(
10628                        b.lacks_condition_kind(probe),
10629                        !b.has_condition_kind(probe),
10630                        "Boundary::lacks_condition_kind must equal !has_condition_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10631                    );
10632                    assert_eq!(
10633                        b.lacks_condition_kind(probe),
10634                        b.lacks_precondition_kind(probe)
10635                            && b.lacks_postcondition_kind(probe),
10636                        "Boundary::lacks_condition_kind must equal AND-of-half-slice-arms for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10637                    );
10638                }
10639            }
10640        }
10641
10642        // Saturated boundary — both slices carry every ConditionKind,
10643        // every arm returns false on every kind.
10644        let mut b = Boundary::default();
10645        for k in ConditionKind::ALL {
10646            b.preconditions.push(condition_with(k));
10647            b.postconditions.push(condition_with(k));
10648        }
10649        for kind in ConditionKind::ALL {
10650            assert!(
10651                !b.lacks_precondition_kind(kind),
10652                "saturated boundary must return false on lacks_precondition_kind for {kind:?}",
10653            );
10654            assert!(
10655                !b.lacks_postcondition_kind(kind),
10656                "saturated boundary must return false on lacks_postcondition_kind for {kind:?}",
10657            );
10658            assert!(
10659                !b.lacks_condition_kind(kind),
10660                "saturated boundary must return false on lacks_condition_kind for {kind:?}",
10661            );
10662        }
10663    }
10664
10665    /// TRIAD delegation pin — the (precondition, postcondition,
10666    /// condition-union) kind-scoped strict-refinement triad on
10667    /// [`Boundary`] agrees byte-for-byte with the slice-level
10668    /// substrate primitive [`ConditionSliceExt::has_only_kind`] on
10669    /// every authored arrangement.
10670    ///
10671    /// Sweeps [`ConditionKind::ALL`] × [`ConditionKind::ALL`] over
10672    /// single-populated-per-side arrangements (the well-formed
10673    /// diagonal), probing every [`ConditionKind`] at the union arm
10674    /// against the DERIVED oracle
10675    /// `boundary.distinct_condition_kinds() == vec![probe]` — a
10676    /// regression at the union arm's fused walk (dropping the
10677    /// short-circuit, swapping the `saw_kind` arm, mis-composing the
10678    /// `||` union at [`Boundary::has_condition_kind`]) surfaces HERE
10679    /// rather than as silent drift at every downstream `has-only-
10680    /// <kind>` require-tag classifier or well-formed-diagonal
10681    /// coherence check callsite. Also pins the per-slice arms
10682    /// delegate verbatim to
10683    /// [`ConditionSliceExt::has_only_kind`] over the corresponding
10684    /// half-slice.
10685    #[test]
10686    fn has_only_condition_kind_triad_delegates_to_slice_has_only_kind() {
10687        // Empty boundary — every arm returns false on every kind
10688        // (no kind is populated, so no kind is "only").
10689        let b = Boundary::default();
10690        for kind in ConditionKind::ALL {
10691            assert!(
10692                !b.has_only_precondition_kind(kind),
10693                "empty boundary must return false on has_only_precondition_kind for {kind:?}",
10694            );
10695            assert!(
10696                !b.has_only_postcondition_kind(kind),
10697                "empty boundary must return false on has_only_postcondition_kind for {kind:?}",
10698            );
10699            assert!(
10700                !b.has_only_condition_kind(kind),
10701                "empty boundary must return false on has_only_condition_kind for {kind:?}",
10702            );
10703        }
10704
10705        // Single-populated per side — sweep ALL × ALL, then probe
10706        // every ConditionKind on the (pre, post, union) triad. The
10707        // union arm returns `true` iff the addressed kind matches
10708        // BOTH the (nonempty) pre kind AND the (nonempty) post kind;
10709        // any (pre_kind, post_kind) with `pre_kind != post_kind`
10710        // yields `false` on every union arm.
10711        for pre_kind in ConditionKind::ALL {
10712            for post_kind in ConditionKind::ALL {
10713                let mut b = Boundary::default();
10714                b.preconditions.push(condition_with(pre_kind));
10715                b.postconditions.push(condition_with(post_kind));
10716                for probe in ConditionKind::ALL {
10717                    assert_eq!(
10718                        b.has_only_precondition_kind(probe),
10719                        b.preconditions.has_only_kind(probe),
10720                        "Boundary::has_only_precondition_kind must delegate verbatim to preconditions.has_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10721                    );
10722                    assert_eq!(
10723                        b.has_only_postcondition_kind(probe),
10724                        b.postconditions.has_only_kind(probe),
10725                        "Boundary::has_only_postcondition_kind must delegate verbatim to postconditions.has_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10726                    );
10727                    let expected_union = pre_kind == probe && post_kind == probe;
10728                    assert_eq!(
10729                        b.has_only_condition_kind(probe),
10730                        expected_union,
10731                        "Boundary::has_only_condition_kind must equal (pre_kind == probe && post_kind == probe) for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10732                    );
10733                    assert_eq!(
10734                        b.has_only_condition_kind(probe),
10735                        b.distinct_condition_kinds() == vec![probe],
10736                        "Boundary::has_only_condition_kind({probe:?}) must equal (distinct_condition_kinds() == vec![{probe:?}]) for pre={pre_kind:?} post={post_kind:?}",
10737                    );
10738                }
10739            }
10740        }
10741
10742        // Single-side-only populated — a boundary with a condition on
10743        // ONE side and NOTHING on the other: the union carries a
10744        // singleton distinct set. The single-slice AND-of-strict-
10745        // refinement fails on the empty side (`empty.has_only_kind(k)
10746        // == false`), but the union arm returns `true` for the
10747        // populated kind — pins that the union arm reaches the union
10748        // primitive, not the (pre AND post) AND-composition.
10749        for populated in ConditionKind::ALL {
10750            let mut b = Boundary::default();
10751            b.preconditions.push(condition_with(populated));
10752            for probe in ConditionKind::ALL {
10753                let expected = probe == populated;
10754                assert_eq!(
10755                    b.has_only_condition_kind(probe),
10756                    expected,
10757                    "pre-only boundary populated={populated:?} must return {expected} on has_only_condition_kind({probe:?})",
10758                );
10759                assert_eq!(
10760                    b.has_only_condition_kind(probe),
10761                    b.distinct_condition_kinds() == vec![probe],
10762                    "pre-only boundary populated={populated:?} must agree with distinct_condition_kinds() == vec![{probe:?}]",
10763                );
10764            }
10765            let mut b = Boundary::default();
10766            b.postconditions.push(condition_with(populated));
10767            for probe in ConditionKind::ALL {
10768                let expected = probe == populated;
10769                assert_eq!(
10770                    b.has_only_condition_kind(probe),
10771                    expected,
10772                    "post-only boundary populated={populated:?} must return {expected} on has_only_condition_kind({probe:?})",
10773                );
10774                assert_eq!(
10775                    b.has_only_condition_kind(probe),
10776                    b.distinct_condition_kinds() == vec![probe],
10777                    "post-only boundary populated={populated:?} must agree with distinct_condition_kinds() == vec![{probe:?}]",
10778                );
10779            }
10780        }
10781
10782        // Saturated boundary — both slices carry every ConditionKind,
10783        // every arm returns false on every kind (N distinct kinds, no
10784        // kind is "only").
10785        let mut b = Boundary::default();
10786        for k in ConditionKind::ALL {
10787            b.preconditions.push(condition_with(k));
10788            b.postconditions.push(condition_with(k));
10789        }
10790        for kind in ConditionKind::ALL {
10791            assert!(
10792                !b.has_only_precondition_kind(kind),
10793                "saturated boundary must return false on has_only_precondition_kind for {kind:?}",
10794            );
10795            assert!(
10796                !b.has_only_postcondition_kind(kind),
10797                "saturated boundary must return false on has_only_postcondition_kind for {kind:?}",
10798            );
10799            assert!(
10800                !b.has_only_condition_kind(kind),
10801                "saturated boundary must return false on has_only_condition_kind for {kind:?}",
10802            );
10803        }
10804    }
10805
10806    /// TRIAD delegation pin — the (precondition, postcondition,
10807    /// condition-union) kind-scoped strict-refinement-on-missing triad
10808    /// on [`Boundary`] agrees byte-for-byte with the slice-level
10809    /// substrate primitive [`ConditionSliceExt::lacks_only_kind`] on
10810    /// every authored arrangement.
10811    ///
10812    /// Sweeps [`ConditionKind::ALL`] × [`ConditionKind::ALL`] over
10813    /// single-populated-per-side arrangements + near-saturation-per-
10814    /// side arrangements (the union arm's well-formed missing
10815    /// diagonal), probing every [`ConditionKind`] at the union arm
10816    /// against the DERIVED oracle
10817    /// `boundary.missing_condition_kinds() == vec![probe]` — a
10818    /// regression at the union arm's fused walk (dropping the
10819    /// short-circuit, swapping the `saw_kind` arm, mis-composing the
10820    /// `has_condition_kind` complement) surfaces HERE rather than as
10821    /// silent drift at every downstream `lacks-only-<kind>` require-
10822    /// tag classifier or near-saturation-diagonal coherence check
10823    /// callsite. Also pins the per-slice arms delegate verbatim to
10824    /// [`ConditionSliceExt::lacks_only_kind`] over the corresponding
10825    /// half-slice.
10826    #[test]
10827    fn lacks_only_condition_kind_triad_delegates_to_slice_lacks_only_kind() {
10828        // Empty boundary — every kind is missing from the union
10829        // (2 ≥ N missing on any N ≥ 2), so no kind is "only" missing.
10830        let b = Boundary::default();
10831        for kind in ConditionKind::ALL {
10832            assert_eq!(
10833                b.lacks_only_precondition_kind(kind),
10834                b.preconditions.lacks_only_kind(kind),
10835                "empty boundary lacks_only_precondition_kind must delegate to preconditions.lacks_only_kind for {kind:?}",
10836            );
10837            assert_eq!(
10838                b.lacks_only_postcondition_kind(kind),
10839                b.postconditions.lacks_only_kind(kind),
10840                "empty boundary lacks_only_postcondition_kind must delegate to postconditions.lacks_only_kind for {kind:?}",
10841            );
10842            assert!(
10843                !b.lacks_only_condition_kind(kind),
10844                "empty boundary must return false on lacks_only_condition_kind for {kind:?} (every kind is missing on N ≥ 2)",
10845            );
10846        }
10847
10848        // Single-populated per side — sweep ALL × ALL, then probe
10849        // every ConditionKind on the (pre, post, union) triad. The
10850        // per-slice arms return `false` (on N ≥ 3 the slice has ≥ 2
10851        // missing kinds; on N == 2 the missing set is single-element
10852        // but only for the OTHER kind). The union arm returns `false`
10853        // for every kind on N ≥ 3 — the union missing set has size
10854        // `N - |{pre, post}|` which is ≥ 2 whenever N ≥ 3, or size 1
10855        // iff pre != post (union covers both), or size N - 1 iff
10856        // pre == post.
10857        for pre_kind in ConditionKind::ALL {
10858            for post_kind in ConditionKind::ALL {
10859                let mut b = Boundary::default();
10860                b.preconditions.push(condition_with(pre_kind));
10861                b.postconditions.push(condition_with(post_kind));
10862                for probe in ConditionKind::ALL {
10863                    assert_eq!(
10864                        b.lacks_only_precondition_kind(probe),
10865                        b.preconditions.lacks_only_kind(probe),
10866                        "Boundary::lacks_only_precondition_kind must delegate verbatim to preconditions.lacks_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10867                    );
10868                    assert_eq!(
10869                        b.lacks_only_postcondition_kind(probe),
10870                        b.postconditions.lacks_only_kind(probe),
10871                        "Boundary::lacks_only_postcondition_kind must delegate verbatim to postconditions.lacks_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
10872                    );
10873                    assert_eq!(
10874                        b.lacks_only_condition_kind(probe),
10875                        b.missing_condition_kinds() == vec![probe],
10876                        "Boundary::lacks_only_condition_kind({probe:?}) must equal (missing_condition_kinds() == vec![{probe:?}]) for pre={pre_kind:?} post={post_kind:?}",
10877                    );
10878                }
10879            }
10880        }
10881
10882        // Near-saturation per side — build a boundary whose preconditions
10883        // carry every kind except one, sweep every "omitted" kind for the
10884        // pre side, then probe the per-slice arm. On the well-formed
10885        // near-saturation diagonal (missing == {omitted}),
10886        // preconditions.lacks_only_kind(omitted) == true; every other
10887        // arm is false.
10888        for omitted in ConditionKind::ALL {
10889            let mut b = Boundary::default();
10890            for k in ConditionKind::ALL {
10891                if k != omitted {
10892                    b.preconditions.push(condition_with(k));
10893                    b.postconditions.push(condition_with(k));
10894                }
10895            }
10896            for probe in ConditionKind::ALL {
10897                let expected = probe == omitted;
10898                assert_eq!(
10899                    b.lacks_only_precondition_kind(probe),
10900                    expected,
10901                    "near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_precondition_kind({probe:?})",
10902                );
10903                assert_eq!(
10904                    b.lacks_only_postcondition_kind(probe),
10905                    expected,
10906                    "near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_postcondition_kind({probe:?})",
10907                );
10908                assert_eq!(
10909                    b.lacks_only_condition_kind(probe),
10910                    expected,
10911                    "near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_condition_kind({probe:?})",
10912                );
10913                assert_eq!(
10914                    b.lacks_only_condition_kind(probe),
10915                    b.missing_condition_kinds() == vec![probe],
10916                    "near-saturation boundary omitted={omitted:?} must agree with missing_condition_kinds() == vec![{probe:?}]",
10917                );
10918            }
10919        }
10920
10921        // Single-side-only near-saturation — a boundary whose ONE side
10922        // carries every kind except one, the OTHER side empty: the
10923        // empty side is missing every kind (per-slice `lacks_only_kind`
10924        // returns false on N ≥ 2), but the union covers everything the
10925        // populated side does, so the union missing set is still
10926        // `{omitted}` and the union arm returns `true` for `omitted`.
10927        // Pins that the union arm reaches the union primitive, not the
10928        // (pre AND post) AND-composition (which would fail on the
10929        // empty side).
10930        for omitted in ConditionKind::ALL {
10931            let mut b = Boundary::default();
10932            for k in ConditionKind::ALL {
10933                if k != omitted {
10934                    b.preconditions.push(condition_with(k));
10935                }
10936            }
10937            for probe in ConditionKind::ALL {
10938                let expected = probe == omitted;
10939                assert_eq!(
10940                    b.lacks_only_condition_kind(probe),
10941                    expected,
10942                    "pre-only near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_condition_kind({probe:?})",
10943                );
10944                assert_eq!(
10945                    b.lacks_only_condition_kind(probe),
10946                    b.missing_condition_kinds() == vec![probe],
10947                    "pre-only near-saturation boundary omitted={omitted:?} must agree with missing_condition_kinds() == vec![{probe:?}]",
10948                );
10949            }
10950            let mut b = Boundary::default();
10951            for k in ConditionKind::ALL {
10952                if k != omitted {
10953                    b.postconditions.push(condition_with(k));
10954                }
10955            }
10956            for probe in ConditionKind::ALL {
10957                let expected = probe == omitted;
10958                assert_eq!(
10959                    b.lacks_only_condition_kind(probe),
10960                    expected,
10961                    "post-only near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_condition_kind({probe:?})",
10962                );
10963            }
10964        }
10965
10966        // Saturated boundary — every kind populated in the union, so
10967        // no kind is missing, so `lacks_only_kind` returns false on
10968        // every arm.
10969        let mut b = Boundary::default();
10970        for k in ConditionKind::ALL {
10971            b.preconditions.push(condition_with(k));
10972            b.postconditions.push(condition_with(k));
10973        }
10974        for kind in ConditionKind::ALL {
10975            assert!(
10976                !b.lacks_only_precondition_kind(kind),
10977                "saturated boundary must return false on lacks_only_precondition_kind for {kind:?}",
10978            );
10979            assert!(
10980                !b.lacks_only_postcondition_kind(kind),
10981                "saturated boundary must return false on lacks_only_postcondition_kind for {kind:?}",
10982            );
10983            assert!(
10984                !b.lacks_only_condition_kind(kind),
10985                "saturated boundary must return false on lacks_only_condition_kind for {kind:?}",
10986            );
10987        }
10988    }
10989
10990    // ── assert_slice_refinement_composition_laws — substrate testkit ──
10991    //
10992    // The substrate testkit primitive
10993    // [`assert_slice_refinement_composition_laws`] pins the FOUR
10994    // composition laws that bind the [`ConditionSliceExt`] refinement
10995    // algebra (find ↔ iter, count ↔ iter, has ↔ find, has ↔ count) at
10996    // ONE call site per authored arrangement, sweeping
10997    // [`ConditionKind::ALL`]. The four hand-authored slice-level
10998    // composition-law tests above
10999    // (`condition_slice_find_kind_equals_iter_kind_next`,
11000    // `condition_slice_count_kind_equals_iter_kind_count`,
11001    // `condition_slice_has_kind_equals_find_kind_is_some`,
11002    // `condition_slice_has_and_find_equal_count_greater_than_zero`)
11003    // stay as first-class per-law drift-arm pins; this substrate
11004    // testkit is the compound-lift primitive that binds all four
11005    // laws through ONE typed sweep so a future FIFTH refinement's
11006    // composition law picks up its pin as ONE new arm inside the
11007    // primitive's body rather than as ONE new sibling test at every
11008    // downstream author-time enumeration.
11009
11010    /// SUBSTRATE PANEL pin — the substrate testkit primitive
11011    /// [`assert_slice_refinement_composition_laws`] passes on the
11012    /// FOUR canonical authored arrangements the trait's downstream
11013    /// consumers reach for: the empty slice (every refinement returns
11014    /// its zero-element identity), a single-element populated slice
11015    /// (every refinement returns the addressed match's projection),
11016    /// a dual-populated slice with distinct kinds (every refinement
11017    /// probes the kind field per element), and a duplicate-populated
11018    /// slice with the same kind at multiple positions (the widened
11019    /// primitive `iter_kind` yields every match; `find_kind` collapses
11020    /// to the first; `count_kind` returns the exact cardinality;
11021    /// `has_kind` returns true). Sweeping the four arrangements at
11022    /// ONE call site pins that every composition law holds regardless
11023    /// of the widened primitive's yield structure.
11024    #[test]
11025    fn slice_refinement_composition_laws_hold_across_authored_arrangements() {
11026        let empty: &[Condition] = &[];
11027        assert_slice_refinement_composition_laws(empty);
11028
11029        for populated in ConditionKind::ALL {
11030            let single = [condition_with(populated)];
11031            assert_slice_refinement_composition_laws(single.as_slice());
11032        }
11033
11034        for pre_kind in ConditionKind::ALL {
11035            for post_kind in ConditionKind::ALL {
11036                let dual = [condition_with(pre_kind), condition_with(post_kind)];
11037                assert_slice_refinement_composition_laws(dual.as_slice());
11038            }
11039        }
11040
11041        for populated in ConditionKind::ALL {
11042            let duplicates = [
11043                condition_with(populated),
11044                condition_with(populated),
11045                condition_with(populated),
11046            ];
11047            assert_slice_refinement_composition_laws(duplicates.as_slice());
11048        }
11049    }
11050
11051    /// SUBSTRATE PANEL pin (params-distinguishable duplicates) — the
11052    /// substrate primitive holds on a slice that carries duplicate
11053    /// kinds interleaved with a distinct kind, byte-for-byte peer of
11054    /// the standalone `condition_slice_iter_kind_yields_every_match_in_slice_order_on_duplicates`
11055    /// / `condition_slice_count_kind_counts_every_match_on_duplicates`
11056    /// arrangement. Confirms the four composition laws hold when
11057    /// the widened primitive's yield stream is genuinely multi-element
11058    /// AND the addressed kind is interleaved with a non-matching kind
11059    /// (the union structural case that the diagonal-and-corners sweep
11060    /// above doesn't reach).
11061    #[test]
11062    fn slice_refinement_composition_laws_hold_on_interleaved_duplicates() {
11063        let interleaved = [
11064            Condition {
11065                kind: ConditionKind::ClosedLoopAuth,
11066                params: json!({ "probeImage": "first" }),
11067            },
11068            Condition {
11069                kind: ConditionKind::PromQL,
11070                params: json!({ "query": "up" }),
11071            },
11072            Condition {
11073                kind: ConditionKind::ClosedLoopAuth,
11074                params: json!({ "probeImage": "second" }),
11075            },
11076            Condition {
11077                kind: ConditionKind::PromQL,
11078                params: json!({ "query": "healthy" }),
11079            },
11080            Condition {
11081                kind: ConditionKind::ClosedLoopAuth,
11082                params: json!({ "probeImage": "third" }),
11083            },
11084        ];
11085        assert_slice_refinement_composition_laws(interleaved.as_slice());
11086    }
11087
11088    // ── assert_surface_union_composition_laws — substrate testkit ────
11089    //
11090    // The substrate testkit macro
11091    // [`crate::assert_surface_union_composition_laws`] pins the FOUR
11092    // union composition laws (has: OR, find: or_else, iter: chain,
11093    // count: SUM) that bind the (pre, post, union) refinement triads
11094    // on the [`Boundary`] surface at ONE call site per authored
11095    // arrangement, sweeping [`ConditionKind::ALL`]. The four hand-
11096    // authored point-surface composition-law tests above
11097    // (`boundary_has_condition_kind_composes_precondition_and_postcondition_arms`,
11098    // `find_condition_kind_triad_delegates_to_slice_find_kind`,
11099    // `iter_condition_kind_triad_delegates_to_slice_iter_kind`,
11100    // `boundary_count_condition_kind_triad_delegates_and_sums_slice_count_kind`)
11101    // stay as first-class per-law drift-arm pins; this substrate
11102    // testkit macro is the compound-lift primitive that binds all
11103    // four union composition laws through ONE typed sweep so a
11104    // future FIFTH union refinement picks up its composition-law
11105    // pin as ONE new arm inside the macro body rather than as ONE
11106    // new sibling test at every downstream author-time
11107    // enumeration on each of the two surfaces.
11108
11109    /// SUBSTRATE PANEL pin — the substrate testkit macro
11110    /// [`crate::assert_surface_union_composition_laws`] passes on
11111    /// [`Boundary`] for the four canonical authored arrangements the
11112    /// surface's downstream consumers reach for: the empty boundary
11113    /// (every union arm returns its zero-element identity), a
11114    /// precondition-only populated boundary (every union arm equals
11115    /// its precondition arm, postcondition arm is empty), a
11116    /// postcondition-only populated boundary (mirror), and a dual-
11117    /// populated boundary sweeping `ALL × ALL` (both half-slice arms
11118    /// contribute; the union monoid operator applies). Sweeping the
11119    /// four arrangements at ONE call site pins every union
11120    /// composition law holds regardless of the arrangement's per-
11121    /// half fill pattern.
11122    #[test]
11123    fn boundary_surface_union_composition_laws_hold_across_authored_arrangements() {
11124        let empty = Boundary::default();
11125        crate::assert_surface_union_composition_laws!(empty);
11126
11127        for populated in ConditionKind::ALL {
11128            let mut pre_only = Boundary::default();
11129            pre_only.preconditions.push(condition_with(populated));
11130            crate::assert_surface_union_composition_laws!(pre_only);
11131
11132            let mut post_only = Boundary::default();
11133            post_only.postconditions.push(condition_with(populated));
11134            crate::assert_surface_union_composition_laws!(post_only);
11135        }
11136
11137        for pre_kind in ConditionKind::ALL {
11138            for post_kind in ConditionKind::ALL {
11139                let mut dual = Boundary::default();
11140                dual.preconditions.push(condition_with(pre_kind));
11141                dual.postconditions.push(condition_with(post_kind));
11142                crate::assert_surface_union_composition_laws!(dual);
11143            }
11144        }
11145    }
11146
11147    /// SUBSTRATE PANEL pin (params-distinguishable duplicates) — the
11148    /// substrate macro holds on a [`Boundary`] whose two half-slices
11149    /// each carry duplicates of the same kind at multiple positions,
11150    /// interleaved with a distinct kind. The scenario reaches every
11151    /// union arm at its non-degenerate composition: `has` still
11152    /// resolves `true` on both halves (OR is not the discriminating
11153    /// bit), `find` yields the FIRST-precondition-side match
11154    /// (`or_else` walk order), `iter` yields every match with the
11155    /// full pre-then-post chain order (five total matches across the
11156    /// two halves), `count` returns the SUM (five). A regression that
11157    /// (a) collapsed `find`'s `or_else` to `and_then` (silently
11158    /// narrowing to intersection), (b) collapsed `iter`'s `chain` to
11159    /// `zip` (silently truncating to `min(pre, post)`), or (c)
11160    /// collapsed `count`'s SUM to `max` (silently narrowing the
11161    /// cardinality) surfaces HERE — the four laws are pinned
11162    /// simultaneously and any single-arm regression fails one of
11163    /// the four asserts.
11164    #[test]
11165    fn boundary_surface_union_composition_laws_hold_on_interleaved_duplicates() {
11166        let mut b = Boundary::default();
11167        b.preconditions.push(Condition {
11168            kind: ConditionKind::ClosedLoopAuth,
11169            params: json!({ "side": "pre-1" }),
11170        });
11171        b.preconditions.push(Condition {
11172            kind: ConditionKind::PromQL,
11173            params: json!({ "query": "up" }),
11174        });
11175        b.preconditions.push(Condition {
11176            kind: ConditionKind::ClosedLoopAuth,
11177            params: json!({ "side": "pre-2" }),
11178        });
11179        b.postconditions.push(Condition {
11180            kind: ConditionKind::PromQL,
11181            params: json!({ "query": "healthy" }),
11182        });
11183        b.postconditions.push(Condition {
11184            kind: ConditionKind::ClosedLoopAuth,
11185            params: json!({ "side": "post-1" }),
11186        });
11187        crate::assert_surface_union_composition_laws!(b);
11188    }
11189}