tatara_process/boundary.rs
1//! Boundary conditions — predicates that gate phase transitions.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::flux_resource::FluxResource;
7
8/// Boundary specification — preconditions gate Running,
9/// postconditions gate Running → Attested.
10#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
11#[serde(rename_all = "camelCase")]
12pub struct Boundary {
13 #[serde(default)]
14 pub preconditions: Vec<Condition>,
15 #[serde(default)]
16 pub postconditions: Vec<Condition>,
17 /// Max time before VERIFY fails — parsed as a `go`-style duration.
18 /// Empty = controller default (15m).
19 #[serde(default, skip_serializing_if = "Option::is_none")]
20 pub timeout: Option<String>,
21}
22
23impl Boundary {
24 /// True iff at least one [`Condition`] in
25 /// `preconditions ∪ postconditions` carries the given
26 /// [`ConditionKind`] — the ONE substrate primitive that owns the
27 /// (closed-set discriminator, boundary-condition presence) probe on
28 /// this typed surface.
29 ///
30 /// # Semantics
31 ///
32 /// The two condition vectors are unioned: a caller asking "does this
33 /// spec name a `ClosedLoopAuth` predicate anywhere" doesn't care
34 /// whether the operator authored it on the pre- or post-condition
35 /// side. A boundary with the given kind on ONLY preconditions returns
36 /// `true`; a boundary with the given kind on ONLY postconditions
37 /// returns `true`; a boundary with neither returns `false`.
38 ///
39 /// # Sibling to [`crate::intent::Intent::has`] + [`crate::lifetime::Lifetime::has`]
40 ///
41 /// Same shape, same axis, third instance in the workspace-wide
42 /// closed-set-driven presence-probe algebra. `Intent::has` +
43 /// `Lifetime::has` publish the same `(&self, K) -> bool` signature
44 /// where `K` is the discriminator's `Kind` (auto-derived through
45 /// `#[derive(DeriveClosedSet)]`). A future normalization at that
46 /// probe shape (a widened return carrying the matching Condition
47 /// ref, a debug-build assertion on pre/post drift, a fleet-wide
48 /// warn on redundant duplicates) lands at ONE site per surface
49 /// and every downstream `<xxx>-<kind>` require-tag family +
50 /// closed-set audit dispatcher picks it up mechanically.
51 ///
52 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_condition_kind`]
53 ///
54 /// Same signature `(ConditionKind) -> bool`, same union body
55 /// (`preconditions.has_kind(k) || postconditions.has_kind(k)`), on
56 /// the sugar-surface type [`crate::ephemeral::EphemeralSpec`] whose
57 /// pre/post condition vectors live directly on the struct rather
58 /// than inside a nested [`Boundary`] slot. Both methods compose
59 /// against the ONE slice-level substrate primitive
60 /// [`ConditionSliceExt::has_kind`] — a regression at the per-slice
61 /// walk fails at that primitive's tests rather than as silent drift
62 /// at either struct-level union caller. The ephemeral require-tag
63 /// classifier reaches its `condition-<kind>` prefix family through
64 /// the peer method byte-for-byte symmetrical with the point
65 /// surface's `condition-<kind>` family that composes through this
66 /// method.
67 ///
68 /// # Compounding
69 ///
70 /// The point-domain require-tag surface in
71 /// `tatara-reconciler::bin::tatara-check` composes this primitive
72 /// with the closed-set `FromStr` autoderived on [`ConditionKind`]
73 /// through the `strip_and_classify_prefixed_kind` substrate to
74 /// publish a `condition-<kind>` prefix family byte-for-byte
75 /// symmetrical with `intent-<kind>` + `lifetime-<kind>`. A future
76 /// [`ConditionKind`] variant added to `ALL` reaches every downstream
77 /// (require-tag classifier, coherence check, editor completion
78 /// provider) through the SAME closed-set walk with no per-caller
79 /// edit.
80 ///
81 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition preserves
82 /// proofs — the presence-probe body lives at ONE substrate site so
83 /// every downstream `condition-<kind>` requires-tag surface,
84 /// closed-set audit dispatcher, and future variant addition binds
85 /// through the SAME shape). THEORY.md §VI.1 (generation over
86 /// composition — a ninth [`ConditionKind`] variant lands at ONE
87 /// `ALL` entry + ONE `as_str` arm and the presence probe picks it
88 /// up mechanically without further per-consumer edits).
89 #[must_use]
90 pub fn has_condition_kind(&self, kind: ConditionKind) -> bool {
91 self.has_precondition_kind(kind) || self.has_postcondition_kind(kind)
92 }
93
94 /// True iff at least one [`Condition`] in `self.preconditions`
95 /// carries the given [`ConditionKind`] — the precondition-side arm
96 /// of the (precondition, postcondition, condition-union) triad on
97 /// [`Boundary`], sibling to [`Self::has_postcondition_kind`] and
98 /// half-composition of [`Self::has_condition_kind`].
99 ///
100 /// Thin typed delegate to [`ConditionSliceExt::has_kind`] over
101 /// [`Self::preconditions`]. Peer of [`Self::has_postcondition_kind`]
102 /// on the (precondition, postcondition) partition of the boundary's
103 /// two condition-vector slots; both peers compose against the SAME
104 /// slice-level substrate primitive and their `||` composition is
105 /// [`Self::has_condition_kind`]. A regression that swapped the
106 /// slice at either arm (a copy-paste that pointed the precondition
107 /// probe at `self.postconditions`, an inline `.iter().any` closure
108 /// body that outlasted the lift) surfaces at the composition-law
109 /// pin `boundary_has_condition_kind_composes_precondition_and_postcondition_arms`
110 /// rather than as silent classifier drift at every downstream
111 /// `precondition-<kind>` require-tag callsite.
112 ///
113 /// # Why lift
114 ///
115 /// Pre-lift the point-domain `precondition-<kind>` require-tag
116 /// classifier in `tatara-reconciler::bin::tatara-check` reached the
117 /// precondition-side slice through direct field access
118 /// (`spec.boundary.preconditions.has_kind(k)`) while its sibling
119 /// `condition-<kind>` classifier routed through the named
120 /// [`Self::has_condition_kind`] primitive. The asymmetry meant a
121 /// future normalization at the presence-probe shape (a widened
122 /// return carrying the matching [`Condition`] ref, a debug-build
123 /// assertion on redundant duplicates, a fleet-wide warn on
124 /// pre-only ClosedLoopAuth authoring) would land at the union
125 /// primitive but bypass the two half-slice classifiers. Post-lift
126 /// the (precondition, postcondition, condition-union) triad lives
127 /// at ONE typed algebra surface on [`Boundary`], with the
128 /// `condition-<K> = precondition-<K> ∨ postcondition-<K>`
129 /// composition law pinned as a first-class typed invariant
130 /// (see the composition-pin test in this module) rather than a
131 /// per-caller discipline.
132 ///
133 /// # Semantics
134 ///
135 /// Returns `true` iff `self.preconditions.iter().any(|c| c.kind ==
136 /// kind)`. Ignores `self.postconditions` — an operator who authored
137 /// the kind on ONLY postconditions gets `false` from this probe and
138 /// `true` from [`Self::has_postcondition_kind`]. The two half-slice
139 /// arms partition the (kind, side) matrix exhaustively across the
140 /// four states (kind absent both, pre-only, post-only, both).
141 ///
142 /// # Sibling to [`crate::ephemeral::EphemeralSpec::has_precondition_kind`]
143 ///
144 /// Same shape, same axis, third and fourth methods in the
145 /// workspace-wide `has_(pre|post)condition_kind` two-surface
146 /// family. [`crate::ephemeral::EphemeralSpec::has_precondition_kind`]
147 /// composes byte-identical `preconditions.has_kind(k)` semantics on
148 /// the sugar-surface type's direct `preconditions: Vec<Condition>`
149 /// field, so both surfaces publish a `precondition-<kind>` require-
150 /// tag prefix family byte-for-byte symmetrical (point surface
151 /// through this method, ephemeral surface through its peer).
152 ///
153 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
154 /// preserves proofs — the per-slice presence-probe body lives at
155 /// ONE substrate site so every downstream `precondition-<kind>`
156 /// require-tag surface, closed-set audit dispatcher, and future
157 /// variant addition binds through the SAME shape). THEORY.md §VI.1
158 /// (generation over composition — the union primitive
159 /// [`Self::has_condition_kind`] emerges from the composition of
160 /// its two half-slice arms rather than as a hand-authored `||`
161 /// closure at every downstream consumer).
162 #[must_use]
163 pub fn has_precondition_kind(&self, kind: ConditionKind) -> bool {
164 self.preconditions.has_kind(kind)
165 }
166
167 /// True iff at least one [`Condition`] in `self.postconditions`
168 /// carries the given [`ConditionKind`] — the postcondition-side arm
169 /// of the (precondition, postcondition, condition-union) triad on
170 /// [`Boundary`], sibling to [`Self::has_precondition_kind`] and
171 /// half-composition of [`Self::has_condition_kind`].
172 ///
173 /// Thin typed delegate to [`ConditionSliceExt::has_kind`] over
174 /// [`Self::postconditions`]. Peer of [`Self::has_precondition_kind`]
175 /// on the (precondition, postcondition) partition of the boundary's
176 /// two condition-vector slots. See [`Self::has_precondition_kind`]
177 /// for the full rationale — the two methods share ONE lift
178 /// motivation, ONE fail-before-pass-after composition-law pin, and
179 /// ONE two-surface parity contract with the ephemeral sugar type
180 /// via [`crate::ephemeral::EphemeralSpec::has_postcondition_kind`].
181 #[must_use]
182 pub fn has_postcondition_kind(&self, kind: ConditionKind) -> bool {
183 self.postconditions.has_kind(kind)
184 }
185
186 /// Returns the first [`Condition`] in
187 /// `preconditions ∪ postconditions` carrying the given
188 /// [`ConditionKind`], searching preconditions first — the
189 /// widened peer of [`Self::has_condition_kind`] one refinement
190 /// higher on the presence-probe algebra.
191 ///
192 /// # Sibling to [`Self::has_condition_kind`]
193 ///
194 /// Same axis, one refinement wider: `has_condition_kind` collapses
195 /// the return to a `bool` (`find_condition_kind(k).is_some()`);
196 /// this method returns the matching `&Condition` so consumers can
197 /// read [`Condition::params`] (the `probeImage`, the `expression`,
198 /// the `flakeRef`) at the presence probe's own callsite without
199 /// re-walking the two condition vectors. Pinned by the composition
200 /// law `has_condition_kind(K) == find_condition_kind(K).is_some()`
201 /// at [`Boundary`]'s substrate-delegation test.
202 ///
203 /// # Semantics — precondition takes precedence
204 ///
205 /// Walks [`Self::preconditions`] first, then [`Self::postconditions`]:
206 /// a kind authored on BOTH sides returns the precondition-side
207 /// [`Condition`]. Callers that need the postcondition-side match
208 /// specifically reach for [`Self::find_postcondition_kind`]; callers
209 /// that need every match across both sides walk the two vectors
210 /// directly. Composition law: `find_condition_kind(K) ==
211 /// find_precondition_kind(K).or_else(|| find_postcondition_kind(K))`,
212 /// pinned as a first-class typed invariant.
213 ///
214 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::find_condition_kind`]
215 ///
216 /// Same signature `(ConditionKind) -> Option<&Condition>`, same
217 /// precondition-first body, on the sugar-surface type whose
218 /// pre/post condition vectors live directly on the struct. Both
219 /// methods compose against the SAME slice-level substrate primitive
220 /// [`ConditionSliceExt::find_kind`] — a regression at the per-slice
221 /// walk fails at that primitive's tests rather than as silent drift
222 /// at either struct-level widened caller.
223 ///
224 /// # Compounding
225 ///
226 /// A future diagnostic consumer (an operator-facing "condition
227 /// {kind} matched on {side} with params.{key}={value}" message
228 /// emitted by the require-tag classifier, a coherence check that
229 /// verifies "every `ClosedLoopAuth` postcondition carries a
230 /// non-empty `probeImage`" by inspecting the returned
231 /// `&Condition.params`, an editor completion listing which
232 /// params-keys appear on the present kind) reaches for the
233 /// matching [`Condition`] through this ONE method rather than
234 /// re-walking the two vectors with `iter().find(...)` at the
235 /// callsite. The presence-probe axis now carries both refinements
236 /// (bool via `has_condition_kind`, `&Condition` via
237 /// `find_condition_kind`) at ONE typed algebra surface per struct.
238 ///
239 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
240 /// preserves proofs — the widened return lives at ONE substrate
241 /// site so every downstream diagnostic consumer + coherence check
242 /// binds through the SAME shape rather than restating the
243 /// `.iter().find(|c| c.kind == K)` closure body).
244 #[must_use]
245 pub fn find_condition_kind(&self, kind: ConditionKind) -> Option<&Condition> {
246 self.find_precondition_kind(kind)
247 .or_else(|| self.find_postcondition_kind(kind))
248 }
249
250 /// Returns the first [`Condition`] in [`Self::preconditions`]
251 /// carrying the given [`ConditionKind`], or `None` — the
252 /// precondition-side arm of the (precondition, postcondition,
253 /// condition-union) widened triad on [`Boundary`]. Thin typed
254 /// delegate to [`ConditionSliceExt::find_kind`] over
255 /// [`Self::preconditions`].
256 ///
257 /// Peer of [`Self::find_postcondition_kind`] on the (precondition,
258 /// postcondition) partition of the boundary's two condition-vector
259 /// slots; both peers compose against the SAME slice-level substrate
260 /// primitive and their `or_else` composition is
261 /// [`Self::find_condition_kind`]. Byte-identical semantics to
262 /// [`Self::has_precondition_kind`] with a widened `Option<&Condition>`
263 /// return rather than a `bool`.
264 #[must_use]
265 pub fn find_precondition_kind(&self, kind: ConditionKind) -> Option<&Condition> {
266 self.preconditions.find_kind(kind)
267 }
268
269 /// Returns the first [`Condition`] in [`Self::postconditions`]
270 /// carrying the given [`ConditionKind`], or `None` — the
271 /// postcondition-side arm of the (precondition, postcondition,
272 /// condition-union) widened triad on [`Boundary`]. Thin typed
273 /// delegate to [`ConditionSliceExt::find_kind`] over
274 /// [`Self::postconditions`].
275 ///
276 /// Peer of [`Self::find_precondition_kind`] on the (precondition,
277 /// postcondition) partition of the boundary's two condition-vector
278 /// slots. See [`Self::find_precondition_kind`] for the full
279 /// rationale — the two methods share ONE lift motivation, ONE
280 /// fail-before-pass-after composition-law pin, and ONE two-surface
281 /// parity contract with the ephemeral sugar type via
282 /// [`crate::ephemeral::EphemeralSpec::find_postcondition_kind`].
283 #[must_use]
284 pub fn find_postcondition_kind(&self, kind: ConditionKind) -> Option<&Condition> {
285 self.postconditions.find_kind(kind)
286 }
287
288 /// Returns an iterator over every [`Condition`] in
289 /// `preconditions ∪ postconditions` carrying the given
290 /// [`ConditionKind`], walking preconditions first — the
291 /// widened peer of [`Self::find_condition_kind`] one refinement
292 /// higher on the presence-probe algebra. Byte-for-byte
293 /// equivalent to
294 /// `self.iter_precondition_kind(kind).chain(self.iter_postcondition_kind(kind))`.
295 ///
296 /// # Sibling to [`Self::find_condition_kind`]
297 ///
298 /// Same axis, one refinement wider: `find_condition_kind`
299 /// collapses the return to the FIRST match (yielding
300 /// `Option<&Condition>`); this method yields every match across
301 /// both sides. Pinned by the composition law
302 /// `find_condition_kind(K) == iter_condition_kind(K).next()` at
303 /// [`Boundary`]'s substrate-delegation test — the two refinements
304 /// share ONE walk order by construction (preconditions first,
305 /// then postconditions), so a regression that reversed the
306 /// [`Chain`](std::iter::Chain) order or narrowed the union to an
307 /// intersection surfaces HERE at the substrate boundary rather
308 /// than as silent skew between the first-match and stream
309 /// refinements downstream consumers reach through.
310 ///
311 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::iter_condition_kind`]
312 ///
313 /// Same signature `(ConditionKind) -> Chain<KindMatches<'_>,
314 /// KindMatches<'_>>`, same precondition-first chain body, on the
315 /// sugar-surface type whose pre/post condition vectors live
316 /// directly on the struct. Both methods compose against the SAME
317 /// slice-level substrate primitive [`ConditionSliceExt::iter_kind`]
318 /// — a regression at the per-slice walk fails at that primitive's
319 /// tests rather than as silent drift at either struct-level
320 /// widened caller.
321 ///
322 /// # Compounding
323 ///
324 /// A future coherence check that enforces "each
325 /// [`ConditionKind`] appears at most once across
326 /// preconditions ∪ postconditions" reads
327 /// `boundary.iter_condition_kind(k).nth(1).is_none()` at ONE
328 /// call site rather than restating the count-with-filter closure
329 /// body over the two vector slots. A future diagnostic
330 /// enumerating every match (an operator-facing "N ClosedLoopAuth
331 /// conditions matched, listing sides + params" message emitted
332 /// by the require-tag classifier) reaches this ONE method
333 /// through `boundary.iter_condition_kind(k).collect()` rather
334 /// than chaining two half-slice walks at the callsite.
335 /// The presence-probe axis on [`Boundary`] now carries three
336 /// refinements (bool via `has_condition_kind`,
337 /// `Option<&Condition>` via `find_condition_kind`,
338 /// `impl Iterator<Item = &Condition>` via
339 /// `iter_condition_kind`) at ONE typed algebra surface, byte-
340 /// for-byte peer of the same triad on
341 /// [`crate::ephemeral::EphemeralSpec`].
342 ///
343 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
344 /// preserves proofs — the widened stream lives at ONE substrate
345 /// site so every downstream diagnostic + coherence consumer binds
346 /// through the SAME shape rather than restating the two-half
347 /// chain body).
348 pub fn iter_condition_kind(
349 &self,
350 kind: ConditionKind,
351 ) -> std::iter::Chain<KindMatches<'_>, KindMatches<'_>> {
352 self.iter_precondition_kind(kind)
353 .chain(self.iter_postcondition_kind(kind))
354 }
355
356 /// Returns an iterator over every [`Condition`] in
357 /// [`Self::preconditions`] carrying the given [`ConditionKind`]
358 /// — the precondition-side arm of the (precondition,
359 /// postcondition, condition-union) iterator triad on
360 /// [`Boundary`]. Thin typed delegate to
361 /// [`ConditionSliceExt::iter_kind`] over [`Self::preconditions`].
362 ///
363 /// Peer of [`Self::iter_postcondition_kind`] on the (precondition,
364 /// postcondition) partition of the boundary's two condition-vector
365 /// slots; both peers compose against the SAME slice-level substrate
366 /// primitive and their [`Chain`](std::iter::Chain) composition is
367 /// [`Self::iter_condition_kind`]. Byte-identical semantics to
368 /// [`Self::find_precondition_kind`] with a widened stream return
369 /// rather than only the first match.
370 pub fn iter_precondition_kind(&self, kind: ConditionKind) -> KindMatches<'_> {
371 self.preconditions.iter_kind(kind)
372 }
373
374 /// Returns an iterator over every [`Condition`] in
375 /// [`Self::postconditions`] carrying the given [`ConditionKind`]
376 /// — the postcondition-side arm of the (precondition,
377 /// postcondition, condition-union) iterator triad on
378 /// [`Boundary`]. Thin typed delegate to
379 /// [`ConditionSliceExt::iter_kind`] over
380 /// [`Self::postconditions`].
381 ///
382 /// Peer of [`Self::iter_precondition_kind`] on the (precondition,
383 /// postcondition) partition of the boundary's two condition-vector
384 /// slots. See [`Self::iter_precondition_kind`] for the full
385 /// rationale — the two methods share ONE lift motivation, ONE
386 /// fail-before-pass-after composition-law pin, and ONE
387 /// two-surface parity contract with the ephemeral sugar type via
388 /// [`crate::ephemeral::EphemeralSpec::iter_postcondition_kind`].
389 pub fn iter_postcondition_kind(&self, kind: ConditionKind) -> KindMatches<'_> {
390 self.postconditions.iter_kind(kind)
391 }
392
393 /// Number of [`Condition`]s in `preconditions ∪ postconditions`
394 /// carrying the given [`ConditionKind`] — the scalar cardinality
395 /// arm of the (precondition, postcondition, condition-union)
396 /// count triad on [`Boundary`]. Composed as
397 /// `count_precondition_kind(k) + count_postcondition_kind(k)` —
398 /// the ONE SUM-composed arm on the presence-probe algebra
399 /// (distinct from `has_condition_kind`'s `||` union,
400 /// `find_condition_kind`'s `or_else` first-match, and
401 /// `iter_condition_kind`'s `Chain` stream).
402 ///
403 /// # Sibling to [`Self::iter_condition_kind`]
404 ///
405 /// Same axis, one refinement lower on the cardinality projection:
406 /// `iter_condition_kind` yields the whole match stream across both
407 /// sides; this method collapses that stream to its cardinality
408 /// without materializing any intermediate [`Vec`]. Composition law
409 /// `count_condition_kind(K) == iter_condition_kind(K).count()`
410 /// pinned as a first-class typed invariant at the substrate-
411 /// delegation test.
412 ///
413 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::count_condition_kind`]
414 ///
415 /// Same signature `(ConditionKind) -> usize`, same SUM body, on
416 /// the sugar-surface type whose pre/post condition vectors live
417 /// directly on the struct. Both methods compose against the SAME
418 /// slice-level substrate primitive [`ConditionSliceExt::count_kind`]
419 /// — a regression at the per-slice count fails at that primitive's
420 /// tests rather than as silent drift at either struct-level union
421 /// caller.
422 ///
423 /// # Compounding
424 ///
425 /// A future coherence check that enforces "each [`ConditionKind`]
426 /// appears at most once across preconditions ∪ postconditions"
427 /// reads `boundary.count_condition_kind(k) <= 1` at ONE call site.
428 /// A future require-tag classifier arm that surfaces multiplicity
429 /// to the operator (a hypothetical `condition-count-<kind>` prefix
430 /// family, an audit dump reporting "N ClosedLoopAuth conditions
431 /// matched") reaches this ONE method rather than restating the
432 /// `.iter_condition_kind(k).count()` chain body at the callsite.
433 /// The presence-probe axis on [`Boundary`] now carries FOUR
434 /// refinements (bool via `has_condition_kind`, `Option<&Condition>`
435 /// via `find_condition_kind`, `impl Iterator<Item = &Condition>`
436 /// via `iter_condition_kind`, `usize` via `count_condition_kind`)
437 /// at ONE typed algebra surface per struct, byte-for-byte peer of
438 /// the same tetrad on [`crate::ephemeral::EphemeralSpec`].
439 ///
440 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
441 /// preserves proofs — the scalar cardinality lives at ONE
442 /// substrate site so every downstream diagnostic + coherence
443 /// consumer binds through the SAME shape rather than restating
444 /// the two-half sum body).
445 #[must_use]
446 pub fn count_condition_kind(&self, kind: ConditionKind) -> usize {
447 self.count_precondition_kind(kind) + self.count_postcondition_kind(kind)
448 }
449
450 /// Number of [`Condition`]s in [`Self::preconditions`] carrying
451 /// the given [`ConditionKind`] — the precondition-side arm of the
452 /// (precondition, postcondition, condition-union) count triad on
453 /// [`Boundary`]. Thin typed delegate to
454 /// [`ConditionSliceExt::count_kind`] over [`Self::preconditions`].
455 ///
456 /// Peer of [`Self::count_postcondition_kind`] on the (precondition,
457 /// postcondition) partition of the boundary's two condition-vector
458 /// slots; both peers compose against the SAME slice-level substrate
459 /// primitive and their `+` composition is
460 /// [`Self::count_condition_kind`]. Byte-identical semantics to
461 /// [`Self::iter_precondition_kind`] with the scalar `usize`
462 /// cardinality projection rather than the widened stream.
463 #[must_use]
464 pub fn count_precondition_kind(&self, kind: ConditionKind) -> usize {
465 self.preconditions.count_kind(kind)
466 }
467
468 /// Number of [`Condition`]s in [`Self::postconditions`] carrying
469 /// the given [`ConditionKind`] — the postcondition-side arm of
470 /// the (precondition, postcondition, condition-union) count triad
471 /// on [`Boundary`]. Thin typed delegate to
472 /// [`ConditionSliceExt::count_kind`] over
473 /// [`Self::postconditions`].
474 ///
475 /// Peer of [`Self::count_precondition_kind`]. See that method for
476 /// the full rationale — the two methods share ONE lift motivation,
477 /// ONE fail-before-pass-after composition-law pin, and ONE
478 /// two-surface parity contract with the ephemeral sugar type via
479 /// [`crate::ephemeral::EphemeralSpec::count_postcondition_kind`].
480 #[must_use]
481 pub fn count_postcondition_kind(&self, kind: ConditionKind) -> usize {
482 self.postconditions.count_kind(kind)
483 }
484
485 /// The set of [`ConditionKind`] variants that appear at least once in
486 /// `preconditions ∪ postconditions`, projected in
487 /// [`ConditionKind::ALL`] order — the closed-set-inversion refinement
488 /// on the presence-probe algebra (distinct axis from the four point-
489 /// probe refinements: bool via [`Self::has_condition_kind`],
490 /// `Option<&Condition>` via [`Self::find_condition_kind`],
491 /// `impl Iterator<Item = &Condition>` via [`Self::iter_condition_kind`],
492 /// `usize` via [`Self::count_condition_kind`]).
493 ///
494 /// # Composed body
495 ///
496 /// `ConditionKind::ALL.into_iter().filter(|k|
497 /// self.has_condition_kind(*k)).collect()` — a thin projection over
498 /// the closed set composed against the two-slice union primitive
499 /// [`Self::has_condition_kind`]. Equivalent to the set-union of
500 /// [`Self::distinct_precondition_kinds`] and
501 /// [`Self::distinct_postcondition_kinds`] projected in canonical
502 /// [`ConditionKind::ALL`] order (the union composition law pinned by
503 /// the substrate testkit macro [`crate::assert_surface_union_composition_laws`]).
504 ///
505 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::distinct_condition_kinds`]
506 ///
507 /// Same signature `(&Self) -> Vec<ConditionKind>`, same closed-set-
508 /// inversion body, on the sugar-surface type whose pre/post condition
509 /// vectors live directly on the struct. Both methods compose against
510 /// the SAME slice-level substrate primitive
511 /// [`ConditionSliceExt::distinct_kinds`] via the two-slice union
512 /// composed through [`Self::has_condition_kind`] — a regression at
513 /// the per-slice walk fails at that primitive's tests rather than as
514 /// silent drift at either struct-level union caller.
515 ///
516 /// # Sibling to the four point-probe refinements
517 ///
518 /// FIFTH refinement on the boundary-surface presence-probe algebra,
519 /// distinct in axis from the other four: `has_condition_kind` /
520 /// `find_condition_kind` / `iter_condition_kind` /
521 /// `count_condition_kind` fix a [`ConditionKind`] and vary the return
522 /// type; this refinement INVERTS the axis by fixing the boundary and
523 /// varying over [`ConditionKind::ALL`]. The composition law
524 /// `distinct_condition_kinds().contains(&k) == has_condition_kind(k)`
525 /// for every `k ∈ ConditionKind::ALL` binds the closed-set-inversion
526 /// probe to the point probe at the (precondition, postcondition,
527 /// condition-union) triad.
528 ///
529 /// # Compounding
530 ///
531 /// A future coherence check that enforces "every process boundary
532 /// carries at least ONE distinct kind" (a warning surfaced when
533 /// `spec.boundary.distinct_condition_kinds().is_empty()`) reaches
534 /// this ONE method rather than paying for the eight-way sweep with
535 /// `has_condition_kind` at every callsite. A future require-tag
536 /// classifier that surfaces the distinct-set cardinality as a scalar
537 /// (a hypothetical `condition-kinds-distinct-<n>` prefix family, an
538 /// audit dump reporting "boundary carries N distinct kinds") reaches
539 /// this ONE method through `.distinct_condition_kinds().len()`
540 /// rather than restating the closed-set-inverted filter idiom at
541 /// every callsite.
542 ///
543 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition preserves
544 /// proofs — the closed-set-inversion aggregate is a typed projection
545 /// of [`Self::has_condition_kind`] over [`ConditionKind::ALL`], and
546 /// every downstream aggregate consumer binds through the SAME shape).
547 /// THEORY.md §VI.1 (generation over composition — a new
548 /// [`ConditionKind`] variant added to `ALL` reaches this method
549 /// mechanically through the closed-set walk).
550 #[must_use]
551 pub fn distinct_condition_kinds(&self) -> Vec<ConditionKind> {
552 ConditionKind::ALL
553 .into_iter()
554 .filter(|k| self.has_condition_kind(*k))
555 .collect()
556 }
557
558 /// The set of [`ConditionKind`] variants appearing at least once in
559 /// [`Self::preconditions`], projected in [`ConditionKind::ALL`]
560 /// order — the precondition-side arm of the (precondition,
561 /// postcondition, condition-union) distinct-set triad on
562 /// [`Boundary`]. Thin typed delegate to
563 /// [`ConditionSliceExt::distinct_kinds`] over
564 /// [`Self::preconditions`].
565 ///
566 /// Peer of [`Self::distinct_postcondition_kinds`] on the
567 /// (precondition, postcondition) partition of the boundary's two
568 /// condition-vector slots; both peers compose against the SAME
569 /// slice-level substrate primitive and their canonical set-union
570 /// (projected in [`ConditionKind::ALL`] order) is
571 /// [`Self::distinct_condition_kinds`].
572 #[must_use]
573 pub fn distinct_precondition_kinds(&self) -> Vec<ConditionKind> {
574 self.preconditions.distinct_kinds()
575 }
576
577 /// The set of [`ConditionKind`] variants appearing at least once in
578 /// [`Self::postconditions`], projected in [`ConditionKind::ALL`]
579 /// order — the postcondition-side arm of the (precondition,
580 /// postcondition, condition-union) distinct-set triad on
581 /// [`Boundary`]. Thin typed delegate to
582 /// [`ConditionSliceExt::distinct_kinds`] over
583 /// [`Self::postconditions`].
584 ///
585 /// Peer of [`Self::distinct_precondition_kinds`]. See that method
586 /// for the full rationale — the two methods share ONE lift
587 /// motivation, ONE fail-before-pass-after composition-law pin, and
588 /// ONE two-surface parity contract with the ephemeral sugar type
589 /// via [`crate::ephemeral::EphemeralSpec::distinct_postcondition_kinds`].
590 #[must_use]
591 pub fn distinct_postcondition_kinds(&self) -> Vec<ConditionKind> {
592 self.postconditions.distinct_kinds()
593 }
594
595 /// Zero-allocation iterator peer of [`Self::distinct_condition_kinds`]
596 /// — the condition-union arm of the (precondition, postcondition,
597 /// condition-union) closed-set-inversion iterator triad on
598 /// [`Boundary`]. Walks [`ConditionKind::ALL`] in canonical order and
599 /// yields every [`ConditionKind`] appearing at least once in
600 /// `preconditions ∪ postconditions`, WITHOUT materializing an
601 /// intermediate `Vec<ConditionKind>`.
602 ///
603 /// Composed body:
604 /// `ConditionKind::ALL.iter().copied().filter(|&k|
605 /// self.has_condition_kind(k))` — a thin projection over the closed
606 /// set composed against the two-slice union primitive
607 /// [`Self::has_condition_kind`], byte-identical to the trait-level
608 /// [`ConditionSliceExt::iter_distinct_kinds`] but reaching through
609 /// the boundary's two-slice union rather than a single slice.
610 /// Equivalent to `self.distinct_condition_kinds().into_iter()` without
611 /// the intermediate heap allocation.
612 ///
613 /// Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::iter_distinct_condition_kinds`].
614 /// Sibling to the three-slice `iter_*_condition_kinds` triad —
615 /// `iter_distinct_condition_kinds` walks the union, the two half-
616 /// slice arms `iter_distinct_precondition_kinds` and
617 /// `iter_distinct_postcondition_kinds` walk each side alone. See
618 /// [`Self::distinct_condition_kinds`] for the full rationale on the
619 /// closed-set-inversion aggregate.
620 pub fn iter_distinct_condition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
621 ConditionKind::ALL
622 .iter()
623 .copied()
624 .filter(|&k| self.has_condition_kind(k))
625 }
626
627 /// Zero-allocation iterator peer of
628 /// [`Self::distinct_precondition_kinds`] — the precondition-side arm
629 /// of the (precondition, postcondition, condition-union) closed-set-
630 /// inversion iterator triad on [`Boundary`]. Thin typed delegate to
631 /// [`ConditionSliceExt::iter_distinct_kinds`] over
632 /// [`Self::preconditions`].
633 pub fn iter_distinct_precondition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
634 self.preconditions.iter_distinct_kinds()
635 }
636
637 /// Zero-allocation iterator peer of
638 /// [`Self::distinct_postcondition_kinds`] — the postcondition-side
639 /// arm of the (precondition, postcondition, condition-union) closed-
640 /// set-inversion iterator triad on [`Boundary`]. Thin typed delegate
641 /// to [`ConditionSliceExt::iter_distinct_kinds`] over
642 /// [`Self::postconditions`].
643 pub fn iter_distinct_postcondition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
644 self.postconditions.iter_distinct_kinds()
645 }
646
647 /// Scalar cardinality of the [`ConditionKind`] set appearing at
648 /// least once in `preconditions ∪ postconditions` — the
649 /// condition-union arm of the (precondition, postcondition,
650 /// condition-union) distinct-kind-count triad on [`Boundary`].
651 ///
652 /// # Composed body
653 ///
654 /// `ConditionKind::ALL.iter().filter(|k|
655 /// self.has_condition_kind(**k)).count()` — a thin projection over
656 /// the closed set composed against the two-slice union primitive
657 /// [`Self::has_condition_kind`], byte-identical to the trait-level
658 /// [`ConditionSliceExt::distinct_kind_count`] but reaching through
659 /// the boundary's two-slice union rather than a single slice.
660 /// Equivalent to `self.distinct_condition_kinds().len()` without
661 /// materializing the intermediate `Vec<ConditionKind>`.
662 ///
663 /// # Sibling to [`Self::distinct_condition_kinds`]
664 ///
665 /// Scalar projection of the closed-set-inversion widened primitive
666 /// on the boundary-union surface — where `distinct_condition_kinds`
667 /// returns the SET, `distinct_condition_kind_count` collapses it to
668 /// its cardinality. Byte-for-byte peer of the point-domain scalar
669 /// projection [`ConditionSliceExt::distinct_kind_count`] one
670 /// struct-layer down, and of the peer surface sugar
671 /// [`crate::ephemeral::EphemeralSpec::distinct_condition_kind_count`]
672 /// one struct-layer sideways.
673 ///
674 /// # Compounding
675 ///
676 /// A future coherence check that enforces "every process boundary
677 /// carries at least ONE distinct kind" now reads
678 /// `spec.boundary.distinct_condition_kind_count() > 0` at ONE call
679 /// site rather than paying for
680 /// `spec.boundary.distinct_condition_kinds().len() > 0` (with its
681 /// intermediate heap allocation) or the eight-way `has_*_kind`
682 /// sweep at the callsite. A future require-tag classifier arm that
683 /// publishes the distinct-set cardinality as a scalar (a
684 /// hypothetical `condition-kinds-distinct-<n>` prefix family)
685 /// reaches this ONE primitive without allocating.
686 ///
687 /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
688 /// preserves proofs (the scalar cardinality composes the SAME
689 /// closed-set walk on both this boundary surface and the
690 /// slice-level substrate primitive). THEORY.md §VI.1 — generation
691 /// over composition (a new [`ConditionKind`] variant added to
692 /// `ALL` reaches this primitive mechanically through the closed-set
693 /// walk).
694 #[must_use]
695 pub fn distinct_condition_kind_count(&self) -> usize {
696 ConditionKind::ALL
697 .iter()
698 .filter(|k| self.has_condition_kind(**k))
699 .count()
700 }
701
702 /// Scalar cardinality of the [`ConditionKind`] set appearing at
703 /// least once in [`Self::preconditions`] — the precondition-side
704 /// arm of the (precondition, postcondition, condition-union)
705 /// distinct-kind-count triad on [`Boundary`]. Thin typed delegate
706 /// to [`ConditionSliceExt::distinct_kind_count`] over
707 /// [`Self::preconditions`].
708 ///
709 /// Peer of [`Self::distinct_postcondition_kind_count`] on the
710 /// (precondition, postcondition) partition of the boundary's two
711 /// condition-vector slots; both peers compose against the SAME
712 /// slice-level substrate primitive so a regression at the per-slice
713 /// closed-set walk fails at that primitive's tests rather than as
714 /// silent drift at either struct-level scalar-cardinality arm.
715 #[must_use]
716 pub fn distinct_precondition_kind_count(&self) -> usize {
717 self.preconditions.distinct_kind_count()
718 }
719
720 /// Scalar cardinality of the [`ConditionKind`] set appearing at
721 /// least once in [`Self::postconditions`] — the postcondition-side
722 /// arm of the (precondition, postcondition, condition-union)
723 /// distinct-kind-count triad on [`Boundary`]. Thin typed delegate
724 /// to [`ConditionSliceExt::distinct_kind_count`] over
725 /// [`Self::postconditions`].
726 ///
727 /// Peer of [`Self::distinct_precondition_kind_count`]. See that
728 /// method for the full rationale — the two methods share ONE lift
729 /// motivation, ONE fail-before-pass-after composition-law pin, and
730 /// ONE two-surface parity contract with the ephemeral sugar type
731 /// via
732 /// [`crate::ephemeral::EphemeralSpec::distinct_postcondition_kind_count`].
733 #[must_use]
734 pub fn distinct_postcondition_kind_count(&self) -> usize {
735 self.postconditions.distinct_kind_count()
736 }
737
738 /// The set of [`ConditionKind`] variants that do NOT appear in
739 /// `preconditions ∪ postconditions`, projected in
740 /// [`ConditionKind::ALL`] order — the closed-set-inversion
741 /// COMPLEMENT of [`Self::distinct_condition_kinds`] on the
742 /// (precondition, postcondition, condition-union) missing-set triad.
743 ///
744 /// # Composed body
745 ///
746 /// `ConditionKind::ALL.into_iter().filter(|k|
747 /// !self.has_condition_kind(*k)).collect()` — a thin projection
748 /// over the closed set composed against the two-slice union
749 /// primitive [`Self::has_condition_kind`] under a negated
750 /// predicate. Equivalent to the SET-INTERSECTION of
751 /// [`Self::missing_precondition_kinds`] and
752 /// [`Self::missing_postcondition_kinds`] projected in canonical
753 /// [`ConditionKind::ALL`] order — a kind is missing from the
754 /// union iff it is missing from BOTH half-slices (the union-
755 /// composition law pinned by the substrate testkit macro
756 /// [`crate::assert_surface_union_composition_laws`]).
757 ///
758 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::missing_condition_kinds`]
759 ///
760 /// Same signature `(&Self) -> Vec<ConditionKind>`, same closed-set-
761 /// complement body, on the sugar-surface type. Both methods compose
762 /// against the SAME slice-level substrate primitive
763 /// [`ConditionSliceExt::missing_kinds`] via the two-slice union
764 /// composed through [`Self::has_condition_kind`] — a regression at
765 /// the per-slice walk fails at that primitive's tests rather than
766 /// as silent drift at either struct-level complement caller.
767 ///
768 /// # Sibling to [`Self::distinct_condition_kinds`]
769 ///
770 /// SIXTH refinement on the boundary-surface presence-probe algebra,
771 /// on the SAME closed-set-inversion axis as `distinct_condition_kinds`
772 /// but under a NEGATED point-probe. The composition law
773 /// `missing_condition_kinds().contains(&k) ==
774 /// !has_condition_kind(k)` for every `k ∈ ConditionKind::ALL`
775 /// binds the complement to the point probe at the triad — and the
776 /// two widened primitives PARTITION `ConditionKind::ALL` (their
777 /// union covers `ALL`, their intersection is empty, their
778 /// cardinalities sum to `ALL.len()`).
779 ///
780 /// # Compounding
781 ///
782 /// A future coherence check that enforces "every process boundary
783 /// carries a [`ConditionKind::JobAttested`] postcondition" surfaces
784 /// the operator-facing gap diagnostic
785 /// `spec.boundary.postconditions.missing_kinds()` verbatim (naming
786 /// EVERY kind absent from postconditions in canonical order). A
787 /// future operator-facing "boundary is MISSING [JobAttested,
788 /// ClosedLoopAuth]" audit dump reads this ONE method rather than
789 /// restating the negated closed-set walk at every consumer. A
790 /// hypothetical `condition-kinds-missing-<n>` require-tag classifier
791 /// prefix family that publishes the missing-set cardinality as a
792 /// scalar reaches `.missing_condition_kinds().len()`.
793 ///
794 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
795 /// preserves proofs — the closed-set complement is a typed
796 /// projection of [`Self::has_condition_kind`] over
797 /// [`ConditionKind::ALL`] under negation, and every downstream
798 /// gap-analysis consumer binds through the SAME shape).
799 /// THEORY.md §VI.1 (generation over composition — a new
800 /// [`ConditionKind`] variant added to `ALL` reaches this method
801 /// mechanically through the closed-set walk).
802 #[must_use]
803 pub fn missing_condition_kinds(&self) -> Vec<ConditionKind> {
804 ConditionKind::ALL
805 .into_iter()
806 .filter(|k| !self.has_condition_kind(*k))
807 .collect()
808 }
809
810 /// The set of [`ConditionKind`] variants that do NOT appear in
811 /// [`Self::preconditions`], projected in [`ConditionKind::ALL`]
812 /// order — the precondition-side arm of the (precondition,
813 /// postcondition, condition-union) missing-set triad on
814 /// [`Boundary`]. Thin typed delegate to
815 /// [`ConditionSliceExt::missing_kinds`] over
816 /// [`Self::preconditions`].
817 ///
818 /// Peer of [`Self::missing_postcondition_kinds`] on the
819 /// (precondition, postcondition) partition of the boundary's two
820 /// condition-vector slots; both peers compose against the SAME
821 /// slice-level substrate primitive and their SET-INTERSECTION
822 /// (projected in [`ConditionKind::ALL`] order) is
823 /// [`Self::missing_condition_kinds`].
824 #[must_use]
825 pub fn missing_precondition_kinds(&self) -> Vec<ConditionKind> {
826 self.preconditions.missing_kinds()
827 }
828
829 /// The set of [`ConditionKind`] variants that do NOT appear in
830 /// [`Self::postconditions`], projected in [`ConditionKind::ALL`]
831 /// order — the postcondition-side arm of the (precondition,
832 /// postcondition, condition-union) missing-set triad on
833 /// [`Boundary`]. Thin typed delegate to
834 /// [`ConditionSliceExt::missing_kinds`] over
835 /// [`Self::postconditions`].
836 ///
837 /// Peer of [`Self::missing_precondition_kinds`]. See that method
838 /// for the full rationale — the two methods share ONE lift
839 /// motivation, ONE fail-before-pass-after composition-law pin, and
840 /// ONE two-surface parity contract with the ephemeral sugar type
841 /// via [`crate::ephemeral::EphemeralSpec::missing_postcondition_kinds`].
842 #[must_use]
843 pub fn missing_postcondition_kinds(&self) -> Vec<ConditionKind> {
844 self.postconditions.missing_kinds()
845 }
846
847 /// Zero-allocation iterator peer of [`Self::missing_condition_kinds`]
848 /// — the condition-union arm of the (precondition, postcondition,
849 /// condition-union) closed-set-complement iterator triad on
850 /// [`Boundary`]. Walks [`ConditionKind::ALL`] in canonical order and
851 /// yields every [`ConditionKind`] that does NOT appear in
852 /// `preconditions ∪ postconditions`, WITHOUT materializing an
853 /// intermediate `Vec<ConditionKind>`.
854 ///
855 /// Composed body:
856 /// `ConditionKind::ALL.iter().copied().filter(|&k|
857 /// !self.has_condition_kind(k))` — a thin projection over the closed
858 /// set composed against the two-slice union primitive
859 /// [`Self::has_condition_kind`] under a NEGATED predicate, byte-
860 /// identical to the trait-level
861 /// [`ConditionSliceExt::iter_missing_kinds`] but reaching through
862 /// the boundary's two-slice union rather than a single slice.
863 /// Equivalent to `self.missing_condition_kinds().into_iter()` without
864 /// the intermediate heap allocation.
865 ///
866 /// Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::iter_missing_condition_kinds`].
867 /// Sibling to the three-slice `iter_missing_*_kinds` triad and to the
868 /// closed-set-INVERSION peer [`Self::iter_distinct_condition_kinds`] —
869 /// the two iterators PARTITION `ConditionKind::ALL` under the
870 /// `has_condition_kind` union probe. See
871 /// [`Self::missing_condition_kinds`] for the full rationale on the
872 /// closed-set-complement aggregate.
873 pub fn iter_missing_condition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
874 ConditionKind::ALL
875 .iter()
876 .copied()
877 .filter(|&k| !self.has_condition_kind(k))
878 }
879
880 /// Zero-allocation iterator peer of
881 /// [`Self::missing_precondition_kinds`] — the precondition-side arm
882 /// of the (precondition, postcondition, condition-union) closed-set-
883 /// complement iterator triad on [`Boundary`]. Thin typed delegate to
884 /// [`ConditionSliceExt::iter_missing_kinds`] over
885 /// [`Self::preconditions`].
886 pub fn iter_missing_precondition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
887 self.preconditions.iter_missing_kinds()
888 }
889
890 /// Zero-allocation iterator peer of
891 /// [`Self::missing_postcondition_kinds`] — the postcondition-side arm
892 /// of the (precondition, postcondition, condition-union) closed-set-
893 /// complement iterator triad on [`Boundary`]. Thin typed delegate to
894 /// [`ConditionSliceExt::iter_missing_kinds`] over
895 /// [`Self::postconditions`].
896 pub fn iter_missing_postcondition_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
897 self.postconditions.iter_missing_kinds()
898 }
899
900 /// Scalar cardinality of the [`ConditionKind`] set NOT appearing in
901 /// `preconditions ∪ postconditions` — the condition-union arm of the
902 /// (precondition, postcondition, condition-union) missing-kind-count
903 /// triad on [`Boundary`].
904 ///
905 /// # Composed body
906 ///
907 /// `ConditionKind::ALL.iter().filter(|k|
908 /// !self.has_condition_kind(**k)).count()` — a thin projection over
909 /// the closed set composed against the two-slice union primitive
910 /// [`Self::has_condition_kind`] under a NEGATED predicate, byte-
911 /// identical to the trait-level
912 /// [`ConditionSliceExt::missing_kind_count`] but reaching through
913 /// the boundary's two-slice union rather than a single slice.
914 /// Equivalent to `self.missing_condition_kinds().len()` without
915 /// materializing the intermediate `Vec<ConditionKind>`.
916 ///
917 /// # Sibling to [`Self::missing_condition_kinds`] /
918 /// [`Self::distinct_condition_kind_count`]
919 ///
920 /// Scalar projection of the closed-set-complement widened primitive
921 /// on the boundary-union surface — where `missing_condition_kinds`
922 /// returns the SET, `missing_condition_kind_count` collapses it to
923 /// its cardinality. Byte-for-byte peer of the point-domain scalar
924 /// projection [`ConditionSliceExt::missing_kind_count`] one struct-
925 /// layer down, and of the peer surface sugar
926 /// [`crate::ephemeral::EphemeralSpec::missing_condition_kind_count`]
927 /// one struct-layer sideways.
928 ///
929 /// The scalar-partition composition law
930 /// `distinct_condition_kind_count() + missing_condition_kind_count()
931 /// == ConditionKind::ALL.len()` binds this method's return to its
932 /// distinct-side peer through the closed-set cardinality — the
933 /// scalar consequence of the widened-primitive partition law that
934 /// [`assert_slice_refinement_composition_laws`] pins on each slice
935 /// and that [`crate::assert_surface_union_composition_laws`] lifts
936 /// to the two-slice union.
937 ///
938 /// # Compounding
939 ///
940 /// A future coherence check that enforces "every process boundary
941 /// carries EVERY [`ConditionKind`] under some slot" now reads
942 /// `spec.boundary.missing_condition_kind_count() == 0` at ONE call
943 /// site rather than paying for
944 /// `spec.boundary.missing_condition_kinds().is_empty()` (with its
945 /// intermediate heap allocation) or the eight-way negated `has_*_kind`
946 /// sweep at the callsite. A future require-tag classifier arm that
947 /// publishes the missing-set cardinality as a scalar (a hypothetical
948 /// `condition-kinds-missing-<n>` prefix family) reaches this ONE
949 /// primitive without allocating.
950 ///
951 /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
952 /// preserves proofs (the scalar cardinality composes the SAME
953 /// closed-set walk under negation on both this boundary surface and
954 /// the slice-level substrate primitive). THEORY.md §VI.1 —
955 /// generation over composition (a new [`ConditionKind`] variant
956 /// added to `ALL` reaches this primitive mechanically through the
957 /// closed-set walk).
958 #[must_use]
959 pub fn missing_condition_kind_count(&self) -> usize {
960 ConditionKind::ALL
961 .iter()
962 .filter(|k| !self.has_condition_kind(**k))
963 .count()
964 }
965
966 /// Scalar cardinality of the [`ConditionKind`] set NOT appearing in
967 /// [`Self::preconditions`] — the precondition-side arm of the
968 /// (precondition, postcondition, condition-union) missing-kind-count
969 /// triad on [`Boundary`]. Thin typed delegate to
970 /// [`ConditionSliceExt::missing_kind_count`] over
971 /// [`Self::preconditions`].
972 ///
973 /// Peer of [`Self::missing_postcondition_kind_count`] on the
974 /// (precondition, postcondition) partition of the boundary's two
975 /// condition-vector slots; both peers compose against the SAME
976 /// slice-level substrate primitive so a regression at the per-slice
977 /// negated closed-set walk fails at that primitive's tests rather
978 /// than as silent drift at either struct-level scalar-cardinality
979 /// arm.
980 #[must_use]
981 pub fn missing_precondition_kind_count(&self) -> usize {
982 self.preconditions.missing_kind_count()
983 }
984
985 /// Scalar cardinality of the [`ConditionKind`] set NOT appearing in
986 /// [`Self::postconditions`] — the postcondition-side arm of the
987 /// (precondition, postcondition, condition-union) missing-kind-count
988 /// triad on [`Boundary`]. Thin typed delegate to
989 /// [`ConditionSliceExt::missing_kind_count`] over
990 /// [`Self::postconditions`].
991 ///
992 /// Peer of [`Self::missing_precondition_kind_count`]. See that
993 /// method for the full rationale — the two methods share ONE lift
994 /// motivation, ONE fail-before-pass-after composition-law pin, and
995 /// ONE two-surface parity contract with the ephemeral sugar type
996 /// via
997 /// [`crate::ephemeral::EphemeralSpec::missing_postcondition_kind_count`].
998 #[must_use]
999 pub fn missing_postcondition_kind_count(&self) -> usize {
1000 self.postconditions.missing_kind_count()
1001 }
1002
1003 /// Earliest [`ConditionKind::ALL`] entry present in
1004 /// `preconditions ∪ postconditions`, or `None` when neither side
1005 /// populates any variant — the union arm of the (precondition,
1006 /// postcondition, condition-union) first-distinct-kind triad on
1007 /// [`Boundary`].
1008 ///
1009 /// # Composed body
1010 ///
1011 /// `ConditionKind::ALL.iter().copied().find(|k|
1012 /// self.has_condition_kind(*k))` — a closed-set walk composed
1013 /// against the two-slice union primitive
1014 /// [`Self::has_condition_kind`] that SHORT-CIRCUITS at the earliest
1015 /// match. Byte-identical to the trait-level
1016 /// [`ConditionSliceExt::first_distinct_kind`] but reaching through
1017 /// the boundary's two-slice union rather than a single slice.
1018 /// Equivalent to `self.distinct_condition_kinds().first().copied()`
1019 /// without materializing the intermediate `Vec<ConditionKind>`.
1020 ///
1021 /// # Sibling to [`Self::distinct_condition_kinds`] /
1022 /// [`Self::distinct_condition_kind_count`]
1023 ///
1024 /// Third scalar projection of the closed-set-inversion widened
1025 /// primitive on the boundary-union surface: `distinct_condition_kinds`
1026 /// returns the SET, `distinct_condition_kind_count` collapses it to
1027 /// its cardinality, and `first_distinct_condition_kind` collapses
1028 /// it to its earliest element. Byte-for-byte peer of the point-domain
1029 /// scalar projection [`ConditionSliceExt::first_distinct_kind`] one
1030 /// struct-layer down, and of the peer surface sugar
1031 /// [`crate::ephemeral::EphemeralSpec::first_distinct_condition_kind`]
1032 /// one struct-layer sideways.
1033 ///
1034 /// # Compounding
1035 ///
1036 /// A future coherence check that surfaces "boundary starts with
1037 /// PromQL" reads `spec.boundary.first_distinct_condition_kind() ==
1038 /// Some(ConditionKind::PromQL)` at ONE call site rather than
1039 /// paying for `spec.boundary.distinct_condition_kinds().first() ==
1040 /// Some(&ConditionKind::PromQL)` (with its intermediate heap
1041 /// allocation) or the eight-way `has_*_kind` sweep at the callsite.
1042 /// A future require-tag classifier arm that publishes the earliest
1043 /// distinct kind as a scalar
1044 /// (`condition-kinds-first-distinct-<kind>`) reaches this ONE
1045 /// primitive without allocating.
1046 ///
1047 /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
1048 /// preserves proofs (the earliest-element projection composes the
1049 /// SAME closed-set walk on both this boundary surface and the
1050 /// slice-level substrate primitive under short-circuit semantics).
1051 /// THEORY.md §VI.1 — generation over composition (a new
1052 /// [`ConditionKind`] variant added to `ALL` reaches this primitive
1053 /// mechanically through the closed-set walk).
1054 #[must_use]
1055 pub fn first_distinct_condition_kind(&self) -> Option<ConditionKind> {
1056 ConditionKind::ALL
1057 .iter()
1058 .copied()
1059 .find(|k| self.has_condition_kind(*k))
1060 }
1061
1062 /// Earliest [`ConditionKind::ALL`] entry present in
1063 /// [`Self::preconditions`], or `None` when preconditions carry no
1064 /// matching kind — the precondition-side arm of the (precondition,
1065 /// postcondition, condition-union) first-distinct-kind triad on
1066 /// [`Boundary`]. Thin typed delegate to
1067 /// [`ConditionSliceExt::first_distinct_kind`] over
1068 /// [`Self::preconditions`].
1069 ///
1070 /// Peer of [`Self::first_distinct_postcondition_kind`] on the
1071 /// (precondition, postcondition) partition of the boundary's two
1072 /// condition-vector slots; both peers compose against the SAME
1073 /// slice-level substrate primitive so a regression at the per-slice
1074 /// short-circuit walk fails at that primitive's tests rather than
1075 /// as silent drift at either struct-level arm.
1076 #[must_use]
1077 pub fn first_distinct_precondition_kind(&self) -> Option<ConditionKind> {
1078 self.preconditions.first_distinct_kind()
1079 }
1080
1081 /// Earliest [`ConditionKind::ALL`] entry present in
1082 /// [`Self::postconditions`], or `None` when postconditions carry no
1083 /// matching kind — the postcondition-side arm of the (precondition,
1084 /// postcondition, condition-union) first-distinct-kind triad on
1085 /// [`Boundary`]. Thin typed delegate to
1086 /// [`ConditionSliceExt::first_distinct_kind`] over
1087 /// [`Self::postconditions`].
1088 ///
1089 /// Peer of [`Self::first_distinct_precondition_kind`]. See that
1090 /// method for the full rationale — the two methods share ONE lift
1091 /// motivation, ONE fail-before-pass-after composition-law pin, and
1092 /// ONE two-surface parity contract with the ephemeral sugar type
1093 /// via
1094 /// [`crate::ephemeral::EphemeralSpec::first_distinct_postcondition_kind`].
1095 #[must_use]
1096 pub fn first_distinct_postcondition_kind(&self) -> Option<ConditionKind> {
1097 self.postconditions.first_distinct_kind()
1098 }
1099
1100 /// Earliest [`ConditionKind::ALL`] entry ABSENT from
1101 /// `preconditions ∪ postconditions`, or `None` when the union
1102 /// carries every variant — the union arm of the (precondition,
1103 /// postcondition, condition-union) first-missing-kind triad on
1104 /// [`Boundary`].
1105 ///
1106 /// # Composed body
1107 ///
1108 /// `ConditionKind::ALL.iter().copied().find(|k|
1109 /// !self.has_condition_kind(*k))` — a closed-set walk composed
1110 /// against the two-slice union primitive
1111 /// [`Self::has_condition_kind`] under a NEGATED predicate that
1112 /// SHORT-CIRCUITS at the earliest empty slot. Byte-identical to the
1113 /// trait-level [`ConditionSliceExt::first_missing_kind`] but
1114 /// reaching through the boundary's two-slice union rather than a
1115 /// single slice. Equivalent to
1116 /// `self.missing_condition_kinds().first().copied()` without
1117 /// materializing the intermediate `Vec<ConditionKind>`.
1118 ///
1119 /// # Sibling to [`Self::missing_condition_kinds`] /
1120 /// [`Self::missing_condition_kind_count`]
1121 ///
1122 /// Third scalar projection of the closed-set-complement widened
1123 /// primitive on the boundary-union surface. Byte-for-byte peer of
1124 /// [`Self::first_distinct_condition_kind`] one axis over under a
1125 /// negated predicate: where `first_distinct_condition_kind` scalar-
1126 /// projects the closed-set-INVERSION widened primitive onto its
1127 /// earliest element, this method scalar-projects the closed-set-
1128 /// COMPLEMENT widened primitive onto its earliest element.
1129 ///
1130 /// # Compounding
1131 ///
1132 /// A future coherence check that surfaces "boundary starts missing
1133 /// ProcessPhase" reads `spec.boundary.first_missing_condition_kind()
1134 /// == Some(ConditionKind::ProcessPhase)` at ONE call site rather
1135 /// than paying for `spec.boundary.missing_condition_kinds().first()
1136 /// == Some(&ConditionKind::ProcessPhase)` (with its intermediate
1137 /// heap allocation). An operator-facing "first still-unfilled
1138 /// closed-loop kind" audit reaches this ONE substrate site rather
1139 /// than restating the negated closed-set walk at every consumer.
1140 ///
1141 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1142 /// preserves proofs — the complement-earliest-element projection
1143 /// composes the SAME closed-set walk on both this boundary surface
1144 /// and the slice-level substrate primitive under short-circuit
1145 /// semantics with a negated predicate). THEORY.md §VI.1
1146 /// (generation over composition — a new [`ConditionKind`] variant
1147 /// added to `ALL` reaches this primitive mechanically through the
1148 /// closed-set walk).
1149 #[must_use]
1150 pub fn first_missing_condition_kind(&self) -> Option<ConditionKind> {
1151 ConditionKind::ALL
1152 .iter()
1153 .copied()
1154 .find(|k| !self.has_condition_kind(*k))
1155 }
1156
1157 /// Earliest [`ConditionKind::ALL`] entry ABSENT from
1158 /// [`Self::preconditions`], or `None` when preconditions carry
1159 /// every variant — the precondition-side arm of the (precondition,
1160 /// postcondition, condition-union) first-missing-kind triad on
1161 /// [`Boundary`]. Thin typed delegate to
1162 /// [`ConditionSliceExt::first_missing_kind`] over
1163 /// [`Self::preconditions`].
1164 ///
1165 /// Peer of [`Self::first_missing_postcondition_kind`] on the
1166 /// (precondition, postcondition) partition of the boundary's two
1167 /// condition-vector slots; both peers compose against the SAME
1168 /// slice-level substrate primitive so a regression at the per-slice
1169 /// negated short-circuit walk fails at that primitive's tests
1170 /// rather than as silent drift at either struct-level arm.
1171 #[must_use]
1172 pub fn first_missing_precondition_kind(&self) -> Option<ConditionKind> {
1173 self.preconditions.first_missing_kind()
1174 }
1175
1176 /// Earliest [`ConditionKind::ALL`] entry ABSENT from
1177 /// [`Self::postconditions`], or `None` when postconditions carry
1178 /// every variant — the postcondition-side arm of the (precondition,
1179 /// postcondition, condition-union) first-missing-kind triad on
1180 /// [`Boundary`]. Thin typed delegate to
1181 /// [`ConditionSliceExt::first_missing_kind`] over
1182 /// [`Self::postconditions`].
1183 ///
1184 /// Peer of [`Self::first_missing_precondition_kind`]. See that
1185 /// method for the full rationale — the two methods share ONE lift
1186 /// motivation, ONE fail-before-pass-after composition-law pin, and
1187 /// ONE two-surface parity contract with the ephemeral sugar type
1188 /// via
1189 /// [`crate::ephemeral::EphemeralSpec::first_missing_postcondition_kind`].
1190 #[must_use]
1191 pub fn first_missing_postcondition_kind(&self) -> Option<ConditionKind> {
1192 self.postconditions.first_missing_kind()
1193 }
1194
1195 /// Latest [`ConditionKind::ALL`] entry present in
1196 /// `preconditions ∪ postconditions`, or `None` when neither side
1197 /// populates any variant — the union arm of the (precondition,
1198 /// postcondition, condition-union) last-distinct-kind triad on
1199 /// [`Boundary`].
1200 ///
1201 /// # Composed body
1202 ///
1203 /// `ConditionKind::ALL.iter().rev().copied().find(|k|
1204 /// self.has_condition_kind(*k))` — a REVERSED closed-set walk
1205 /// composed against the two-slice union primitive
1206 /// [`Self::has_condition_kind`] that SHORT-CIRCUITS at the latest
1207 /// match. Byte-identical to the trait-level
1208 /// [`ConditionSliceExt::last_distinct_kind`] but reaching through
1209 /// the boundary's two-slice union rather than a single slice.
1210 /// Equivalent to `self.distinct_condition_kinds().last().copied()`
1211 /// without materializing the intermediate `Vec<ConditionKind>`.
1212 ///
1213 /// # Sibling to [`Self::first_distinct_condition_kind`]
1214 ///
1215 /// Time-reversed peer of the earliest-element scalar projection
1216 /// under the SAME two-slice union predicate. Together with
1217 /// `first_distinct_condition_kind` and the two `_missing_*` peers
1218 /// the four scalar-endpoint projections close the "endpoint of
1219 /// closed-set-inversion/complement widened primitive" refinement
1220 /// axis on the boundary-union surface.
1221 ///
1222 /// # Compounding
1223 ///
1224 /// A future coherence check that surfaces "boundary ends with
1225 /// ClosedLoopAuth" reads `spec.boundary.last_distinct_condition_kind()
1226 /// == Some(ConditionKind::ClosedLoopAuth)` at ONE call site rather
1227 /// than paying for `spec.boundary.distinct_condition_kinds().last()
1228 /// == Some(&…)` with its intermediate heap allocation. A future
1229 /// require-tag classifier arm that publishes the latest distinct
1230 /// kind as a scalar (`condition-kinds-last-distinct-<kind>`) reaches
1231 /// this ONE primitive without allocating.
1232 ///
1233 /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
1234 /// preserves proofs (the latest-element projection composes the
1235 /// SAME reversed closed-set walk on both this boundary surface and
1236 /// the slice-level substrate primitive under short-circuit
1237 /// semantics). THEORY.md §VI.1 — generation over composition (a
1238 /// new [`ConditionKind`] variant added to `ALL` reaches this
1239 /// primitive mechanically through the reversed closed-set walk).
1240 #[must_use]
1241 pub fn last_distinct_condition_kind(&self) -> Option<ConditionKind> {
1242 ConditionKind::ALL
1243 .iter()
1244 .rev()
1245 .copied()
1246 .find(|k| self.has_condition_kind(*k))
1247 }
1248
1249 /// Latest [`ConditionKind::ALL`] entry present in
1250 /// [`Self::preconditions`], or `None` when preconditions carry no
1251 /// matching kind — the precondition-side arm of the (precondition,
1252 /// postcondition, condition-union) last-distinct-kind triad on
1253 /// [`Boundary`]. Thin typed delegate to
1254 /// [`ConditionSliceExt::last_distinct_kind`] over
1255 /// [`Self::preconditions`].
1256 ///
1257 /// Peer of [`Self::last_distinct_postcondition_kind`] on the
1258 /// (precondition, postcondition) partition of the boundary's two
1259 /// condition-vector slots; both peers compose against the SAME
1260 /// slice-level substrate primitive so a regression at the per-
1261 /// slice REVERSED short-circuit walk fails at that primitive's
1262 /// tests rather than as silent drift at either struct-level arm.
1263 #[must_use]
1264 pub fn last_distinct_precondition_kind(&self) -> Option<ConditionKind> {
1265 self.preconditions.last_distinct_kind()
1266 }
1267
1268 /// Latest [`ConditionKind::ALL`] entry present in
1269 /// [`Self::postconditions`], or `None` when postconditions carry
1270 /// no matching kind — the postcondition-side arm of the
1271 /// (precondition, postcondition, condition-union) last-distinct-
1272 /// kind triad on [`Boundary`]. Thin typed delegate to
1273 /// [`ConditionSliceExt::last_distinct_kind`] over
1274 /// [`Self::postconditions`].
1275 ///
1276 /// Peer of [`Self::last_distinct_precondition_kind`]. See that
1277 /// method for the full rationale — the two methods share ONE lift
1278 /// motivation, ONE fail-before-pass-after composition-law pin, and
1279 /// ONE two-surface parity contract with the ephemeral sugar type
1280 /// via
1281 /// [`crate::ephemeral::EphemeralSpec::last_distinct_postcondition_kind`].
1282 #[must_use]
1283 pub fn last_distinct_postcondition_kind(&self) -> Option<ConditionKind> {
1284 self.postconditions.last_distinct_kind()
1285 }
1286
1287 /// Latest [`ConditionKind::ALL`] entry ABSENT from
1288 /// `preconditions ∪ postconditions`, or `None` when the union
1289 /// carries every variant — the union arm of the (precondition,
1290 /// postcondition, condition-union) last-missing-kind triad on
1291 /// [`Boundary`].
1292 ///
1293 /// # Composed body
1294 ///
1295 /// `ConditionKind::ALL.iter().rev().copied().find(|k|
1296 /// !self.has_condition_kind(*k))` — a REVERSED closed-set walk
1297 /// composed against the two-slice union primitive
1298 /// [`Self::has_condition_kind`] under a NEGATED predicate that
1299 /// SHORT-CIRCUITS at the latest empty slot. Byte-identical to the
1300 /// trait-level [`ConditionSliceExt::last_missing_kind`] but
1301 /// reaching through the boundary's two-slice union rather than a
1302 /// single slice. Equivalent to
1303 /// `self.missing_condition_kinds().last().copied()` without
1304 /// materializing the intermediate `Vec<ConditionKind>`.
1305 ///
1306 /// # Sibling to [`Self::first_missing_condition_kind`]
1307 ///
1308 /// Time-reversed peer of the earliest-element scalar projection
1309 /// under the SAME negated two-slice union predicate. Fourth
1310 /// scalar projection on the closed-set-complement axis on the
1311 /// boundary-union surface (first, count, missing_kinds already
1312 /// shipped; this method closes the endpoint pair on the
1313 /// complement side).
1314 ///
1315 /// # Compounding
1316 ///
1317 /// A future coherence check that surfaces "boundary is latest-
1318 /// missing PromQL" reads
1319 /// `spec.boundary.last_missing_condition_kind() ==
1320 /// Some(ConditionKind::PromQL)` at ONE call site rather than
1321 /// paying for `spec.boundary.missing_condition_kinds().last()`
1322 /// with its intermediate heap allocation. An operator-facing
1323 /// "last still-unfilled closed-loop kind" audit reaches this ONE
1324 /// substrate site rather than restating the negated reversed
1325 /// closed-set walk at every consumer.
1326 ///
1327 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1328 /// preserves proofs — the complement-latest-element projection
1329 /// composes the SAME reversed closed-set walk on both this
1330 /// boundary surface and the slice-level substrate primitive
1331 /// under short-circuit semantics with a negated predicate).
1332 /// THEORY.md §VI.1 (generation over composition — a new
1333 /// [`ConditionKind`] variant added to `ALL` reaches this
1334 /// primitive mechanically through the reversed closed-set walk).
1335 #[must_use]
1336 pub fn last_missing_condition_kind(&self) -> Option<ConditionKind> {
1337 ConditionKind::ALL
1338 .iter()
1339 .rev()
1340 .copied()
1341 .find(|k| !self.has_condition_kind(*k))
1342 }
1343
1344 /// Latest [`ConditionKind::ALL`] entry ABSENT from
1345 /// [`Self::preconditions`], or `None` when preconditions carry
1346 /// every variant — the precondition-side arm of the (precondition,
1347 /// postcondition, condition-union) last-missing-kind triad on
1348 /// [`Boundary`]. Thin typed delegate to
1349 /// [`ConditionSliceExt::last_missing_kind`] over
1350 /// [`Self::preconditions`].
1351 ///
1352 /// Peer of [`Self::last_missing_postcondition_kind`] on the
1353 /// (precondition, postcondition) partition of the boundary's two
1354 /// condition-vector slots; both peers compose against the SAME
1355 /// slice-level substrate primitive so a regression at the per-
1356 /// slice negated REVERSED short-circuit walk fails at that
1357 /// primitive's tests rather than as silent drift at either
1358 /// struct-level arm.
1359 #[must_use]
1360 pub fn last_missing_precondition_kind(&self) -> Option<ConditionKind> {
1361 self.preconditions.last_missing_kind()
1362 }
1363
1364 /// Latest [`ConditionKind::ALL`] entry ABSENT from
1365 /// [`Self::postconditions`], or `None` when postconditions carry
1366 /// every variant — the postcondition-side arm of the (precondition,
1367 /// postcondition, condition-union) last-missing-kind triad on
1368 /// [`Boundary`]. Thin typed delegate to
1369 /// [`ConditionSliceExt::last_missing_kind`] over
1370 /// [`Self::postconditions`].
1371 ///
1372 /// Peer of [`Self::last_missing_precondition_kind`]. See that
1373 /// method for the full rationale — the two methods share ONE lift
1374 /// motivation, ONE fail-before-pass-after composition-law pin, and
1375 /// ONE two-surface parity contract with the ephemeral sugar type
1376 /// via
1377 /// [`crate::ephemeral::EphemeralSpec::last_missing_postcondition_kind`].
1378 #[must_use]
1379 pub fn last_missing_postcondition_kind(&self) -> Option<ConditionKind> {
1380 self.postconditions.last_missing_kind()
1381 }
1382
1383 /// `true` iff `preconditions ∪ postconditions` carries every
1384 /// [`ConditionKind::ALL`] variant at least once — the union arm
1385 /// of the (precondition, postcondition, condition-union)
1386 /// saturation-predicate triad on [`Boundary`].
1387 ///
1388 /// # Composed body
1389 ///
1390 /// `ConditionKind::ALL.iter().all(|k| self.has_condition_kind(*k))`
1391 /// — a SHORT-CIRCUITING closed-set walk composed against the
1392 /// two-slice union primitive [`Self::has_condition_kind`], byte-
1393 /// identical to the trait-level [`ConditionSliceExt::is_kind_saturated`]
1394 /// but reaching through the boundary's two-slice union rather than
1395 /// a single slice. Equivalent to `self.missing_condition_kinds()
1396 /// .is_empty()` without materializing the `Vec<ConditionKind>`, and
1397 /// to `self.missing_condition_kind_count() == 0` without paying for
1398 /// the counter walk on every arm.
1399 ///
1400 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::is_condition_kind_saturated`]
1401 ///
1402 /// Byte-identical signature `(&Self) -> bool`, byte-identical
1403 /// closed-set-walk body, on the sugar-surface type whose pre/post
1404 /// condition vectors live directly on the struct. Both methods
1405 /// compose against the SAME slice-level substrate primitive
1406 /// [`ConditionSliceExt::is_kind_saturated`] via the two-slice
1407 /// union composed through [`Self::has_condition_kind`] — a
1408 /// regression at the per-slice `all` short-circuit fails at that
1409 /// primitive's tests rather than as silent drift at either
1410 /// struct-level saturation caller.
1411 ///
1412 /// Theory anchor: THEORY.md §II.1 invariant 5 — composition
1413 /// preserves proofs (the saturation-endpoint projection composes
1414 /// the SAME closed-set walk on both this boundary surface and the
1415 /// slice-level substrate primitive under short-circuit semantics).
1416 /// THEORY.md §VI.1 — generation over composition (a new
1417 /// [`ConditionKind`] variant added to `ALL` reaches this primitive
1418 /// mechanically through the `all` short-circuit).
1419 #[must_use]
1420 pub fn is_condition_kind_saturated(&self) -> bool {
1421 ConditionKind::ALL
1422 .iter()
1423 .all(|k| self.has_condition_kind(*k))
1424 }
1425
1426 /// `true` iff [`Self::preconditions`] carries every
1427 /// [`ConditionKind::ALL`] variant at least once — the precondition-
1428 /// side arm of the (precondition, postcondition, condition-union)
1429 /// saturation-predicate triad on [`Boundary`]. Thin typed delegate
1430 /// to [`ConditionSliceExt::is_kind_saturated`] over
1431 /// [`Self::preconditions`].
1432 ///
1433 /// Peer of [`Self::is_postcondition_kind_saturated`] on the
1434 /// (precondition, postcondition) partition of the boundary's two
1435 /// condition-vector slots; both peers compose against the SAME
1436 /// slice-level substrate primitive so a regression at the per-
1437 /// slice `all` short-circuit fails at that primitive's tests
1438 /// rather than as silent drift at either struct-level arm.
1439 #[must_use]
1440 pub fn is_precondition_kind_saturated(&self) -> bool {
1441 self.preconditions.is_kind_saturated()
1442 }
1443
1444 /// `true` iff [`Self::postconditions`] carries every
1445 /// [`ConditionKind::ALL`] variant at least once — the postcondition-
1446 /// side arm of the (precondition, postcondition, condition-union)
1447 /// saturation-predicate triad on [`Boundary`]. Thin typed delegate
1448 /// to [`ConditionSliceExt::is_kind_saturated`] over
1449 /// [`Self::postconditions`].
1450 ///
1451 /// Peer of [`Self::is_precondition_kind_saturated`]. See that
1452 /// method for the full rationale — the two methods share ONE lift
1453 /// motivation, ONE fail-before-pass-after composition-law pin, and
1454 /// ONE two-surface parity contract with the ephemeral sugar type
1455 /// via
1456 /// [`crate::ephemeral::EphemeralSpec::is_postcondition_kind_saturated`].
1457 #[must_use]
1458 pub fn is_postcondition_kind_saturated(&self) -> bool {
1459 self.postconditions.is_kind_saturated()
1460 }
1461
1462 /// `true` iff `preconditions ∪ postconditions` is MISSING at least
1463 /// one [`ConditionKind::ALL`] variant — the union arm of the
1464 /// (precondition, postcondition, condition-union) at-least-one
1465 /// halfspace triad on [`Boundary`], byte-for-byte peer of the
1466 /// saturation-predicate triad
1467 /// [`Self::is_condition_kind_saturated`] under a definitional
1468 /// negation.
1469 ///
1470 /// # Composed body
1471 ///
1472 /// `!self.is_condition_kind_saturated()` — the definitional
1473 /// negation of the two-slice union saturation primitive. The
1474 /// underlying `ConditionKind::ALL.iter().all(has_condition_kind)`
1475 /// walk returns `false` at the FIRST missing kind (yielding `true`
1476 /// here) WITHOUT materializing
1477 /// [`Self::missing_condition_kinds`]'s `Vec` and WITHOUT walking
1478 /// every entry to build [`Self::missing_condition_kind_count`]'s
1479 /// scalar. Strictly cheaper than either widened primitive on every
1480 /// partially-populated arm.
1481 ///
1482 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_any_missing_condition_kind`]
1483 ///
1484 /// Byte-identical signature `(&Self) -> bool`, byte-identical
1485 /// `!self.is_condition_kind_saturated()` body, on the sugar-surface
1486 /// type whose pre/post condition vectors live directly on the
1487 /// struct. Both methods compose against the SAME slice-level
1488 /// substrate primitive [`ConditionSliceExt::has_any_missing_kind`]
1489 /// via the two-slice union composed through
1490 /// [`Self::is_condition_kind_saturated`] — a regression at the
1491 /// per-slice `all` short-circuit fails at that primitive's tests
1492 /// rather than as silent drift at either struct-level at-least-one
1493 /// halfspace caller.
1494 ///
1495 /// # Compounding
1496 ///
1497 /// A `has-any-missing-kind` require-tag classifier arm — byte-
1498 /// for-byte peer of the tagged-union `has-any-missing-kind`
1499 /// classifier one struct-layer up + the saturation-predicate
1500 /// triad's negated dual — reaches this primitive at ONE call
1501 /// site rather than negating `boundary.is_condition_kind_saturated()`
1502 /// at the callsite or restating
1503 /// `boundary.missing_condition_kind_count() > 0` (which walks
1504 /// every slot to count) or
1505 /// `!boundary.missing_condition_kinds().is_empty()` (which
1506 /// allocates the Vec before the negated emptiness check).
1507 ///
1508 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1509 /// preserves proofs — the at-least-one halfspace projection
1510 /// composes the SAME two-slice union negation on both this
1511 /// boundary surface and the slice-level substrate primitive under
1512 /// definitional negation). THEORY.md §VI.1 (generation over
1513 /// composition — a new [`ConditionKind`] variant reaches both
1514 /// surfaces' at-least-one halfspace triads mechanically through
1515 /// the delegated union primitive).
1516 #[must_use]
1517 pub fn has_any_missing_condition_kind(&self) -> bool {
1518 !self.is_condition_kind_saturated()
1519 }
1520
1521 /// `true` iff [`Self::preconditions`] is MISSING at least one
1522 /// [`ConditionKind::ALL`] variant — the precondition-side arm of
1523 /// the (precondition, postcondition, condition-union) at-least-
1524 /// one halfspace triad on [`Boundary`]. Thin typed delegate to
1525 /// [`ConditionSliceExt::has_any_missing_kind`] over
1526 /// [`Self::preconditions`].
1527 ///
1528 /// Peer of [`Self::has_any_missing_postcondition_kind`] on the
1529 /// (precondition, postcondition) partition of the boundary's two
1530 /// condition-vector slots; both peers compose against the SAME
1531 /// slice-level substrate primitive so a regression at the per-
1532 /// slice `all` short-circuit under negation fails at that
1533 /// primitive's tests rather than as silent drift at either
1534 /// struct-level arm.
1535 #[must_use]
1536 pub fn has_any_missing_precondition_kind(&self) -> bool {
1537 self.preconditions.has_any_missing_kind()
1538 }
1539
1540 /// `true` iff [`Self::postconditions`] is MISSING at least one
1541 /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
1542 /// the (precondition, postcondition, condition-union) at-least-
1543 /// one halfspace triad on [`Boundary`]. Thin typed delegate to
1544 /// [`ConditionSliceExt::has_any_missing_kind`] over
1545 /// [`Self::postconditions`].
1546 ///
1547 /// Peer of [`Self::has_any_missing_precondition_kind`]. See that
1548 /// method for the full rationale — the two methods share ONE lift
1549 /// motivation, ONE fail-before-pass-after composition-law pin, and
1550 /// ONE two-surface parity contract with the ephemeral sugar type
1551 /// via
1552 /// [`crate::ephemeral::EphemeralSpec::has_any_missing_postcondition_kind`].
1553 #[must_use]
1554 pub fn has_any_missing_postcondition_kind(&self) -> bool {
1555 self.postconditions.has_any_missing_kind()
1556 }
1557
1558 /// `true` iff `preconditions ∪ postconditions` carries at least one
1559 /// [`ConditionKind::ALL`] variant — the union arm of the
1560 /// (precondition, postcondition, condition-union) at-least-one
1561 /// halfspace triad on [`Boundary`] on the closed-set-inversion
1562 /// axis, byte-for-byte peer of the at-least-one halfspace triad
1563 /// [`Self::has_any_missing_condition_kind`] on the closed-set-
1564 /// complement axis.
1565 ///
1566 /// # Composed body
1567 ///
1568 /// `ConditionKind::ALL.iter().copied().any(|k|
1569 /// self.has_condition_kind(k))` — a SHORT-CIRCUITING closed-set
1570 /// walk under the two-slice union primitive
1571 /// [`Self::has_condition_kind`]. The walk returns `true` at the
1572 /// FIRST kind present in EITHER slice WITHOUT materializing
1573 /// [`Self::distinct_condition_kinds`]'s `Vec` and WITHOUT walking
1574 /// every kind to build [`Self::distinct_condition_kind_count`]'s
1575 /// scalar. Strictly cheaper than either widened primitive on every
1576 /// non-empty arm because the walk short-circuits at the first
1577 /// populated kind rather than paying for the Vec allocation or the
1578 /// full cardinality count.
1579 ///
1580 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_any_distinct_condition_kind`]
1581 ///
1582 /// Byte-identical signature `(&Self) -> bool`, byte-identical
1583 /// `ConditionKind::ALL.iter().copied().any(|k|
1584 /// self.has_condition_kind(k))` body, on the sugar-surface type
1585 /// whose pre/post condition vectors live directly on the struct.
1586 /// Both methods compose against the SAME slice-level substrate
1587 /// primitive [`ConditionSliceExt::has_any_distinct_kind`] via the
1588 /// two-slice union through [`Self::has_condition_kind`] — a
1589 /// regression at the per-slice `any` short-circuit fails at that
1590 /// primitive's tests rather than as silent drift at either struct-
1591 /// level at-least-one halfspace caller.
1592 ///
1593 /// # Compounding
1594 ///
1595 /// A `has-any-distinct-condition-kind` require-tag classifier arm
1596 /// — byte-for-byte peer of the tagged-union `has-any-populated-
1597 /// kind` classifier one struct-layer up + the at-least-one
1598 /// halfspace triad's closed-set-inversion peer — reaches this
1599 /// primitive at ONE call site rather than restating
1600 /// `boundary.distinct_condition_kind_count() > 0` (which walks
1601 /// every kind to count) or
1602 /// `!boundary.distinct_condition_kinds().is_empty()` (which
1603 /// allocates the Vec before the negated emptiness check).
1604 ///
1605 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1606 /// preserves proofs — the at-least-one halfspace projection
1607 /// composes the SAME closed-set walk on both this boundary surface
1608 /// and the slice-level substrate primitive under short-circuit
1609 /// semantics). THEORY.md §VI.1 (generation over composition — a
1610 /// new [`ConditionKind`] variant reaches both surfaces' at-least-
1611 /// one halfspace triads mechanically through the delegated union
1612 /// primitive).
1613 #[must_use]
1614 pub fn has_any_distinct_condition_kind(&self) -> bool {
1615 ConditionKind::ALL
1616 .iter()
1617 .copied()
1618 .any(|k| self.has_condition_kind(k))
1619 }
1620
1621 /// `true` iff [`Self::preconditions`] carries at least one
1622 /// [`ConditionKind::ALL`] variant — the precondition-side arm of
1623 /// the (precondition, postcondition, condition-union) at-least-one
1624 /// halfspace triad on [`Boundary`] on the closed-set-inversion
1625 /// axis. Thin typed delegate to
1626 /// [`ConditionSliceExt::has_any_distinct_kind`] over
1627 /// [`Self::preconditions`].
1628 ///
1629 /// Peer of [`Self::has_any_distinct_postcondition_kind`] on the
1630 /// (precondition, postcondition) partition of the boundary's two
1631 /// condition-vector slots; both peers compose against the SAME
1632 /// slice-level substrate primitive so a regression at the per-
1633 /// slice `any` short-circuit fails at that primitive's tests
1634 /// rather than as silent drift at either struct-level arm.
1635 #[must_use]
1636 pub fn has_any_distinct_precondition_kind(&self) -> bool {
1637 self.preconditions.has_any_distinct_kind()
1638 }
1639
1640 /// `true` iff [`Self::postconditions`] carries at least one
1641 /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
1642 /// the (precondition, postcondition, condition-union) at-least-one
1643 /// halfspace triad on [`Boundary`] on the closed-set-inversion
1644 /// axis. Thin typed delegate to
1645 /// [`ConditionSliceExt::has_any_distinct_kind`] over
1646 /// [`Self::postconditions`].
1647 ///
1648 /// Peer of [`Self::has_any_distinct_precondition_kind`]. See that
1649 /// method for the full rationale — the two methods share ONE lift
1650 /// motivation, ONE fail-before-pass-after composition-law pin, and
1651 /// ONE two-surface parity contract with the ephemeral sugar type
1652 /// via
1653 /// [`crate::ephemeral::EphemeralSpec::has_any_distinct_postcondition_kind`].
1654 #[must_use]
1655 pub fn has_any_distinct_postcondition_kind(&self) -> bool {
1656 self.postconditions.has_any_distinct_kind()
1657 }
1658
1659 /// `true` iff `preconditions ∪ postconditions` carries EXACTLY
1660 /// ONE [`ConditionKind::ALL`] variant — the union arm of the
1661 /// (precondition, postcondition, condition-union) cardinality-mid-
1662 /// endpoint triad on [`Boundary`] closing the singleton-coverage
1663 /// arm on the closed-set-inversion axis on the union of the two
1664 /// condition slots. The Boolean cardinality-mid-endpoint fast-
1665 /// path peer of [`Self::has_any_distinct_condition_kind`] (≥1
1666 /// halfspace) on the union axis: where the at-least-one halfspace
1667 /// predicate answers "is ANY kind covered by the union?",
1668 /// `has_unique_distinct_condition_kind` answers "is EXACTLY ONE
1669 /// kind covered by the union?".
1670 ///
1671 /// Composed body: constructs a two-step-short-circuit walk over
1672 /// [`ConditionKind::ALL`] under the [`Self::has_condition_kind`]
1673 /// union primitive — pulls up to two hits off the filtered
1674 /// iterator; the primitive returns `true` iff the first is
1675 /// [`Some`] and the second is [`None`]. Byte-for-byte peer of
1676 /// [`ConditionSliceExt::has_unique_distinct_kind`] one slice-
1677 /// layer down, lifted to compose against
1678 /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1679 /// against a single slice's `has_kind`. A regression at the union
1680 /// primitive fails at the slice-level substrate tests + the union
1681 /// composition-law tests rather than as silent drift here.
1682 ///
1683 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_unique_distinct_condition_kind`]
1684 ///
1685 /// Byte-identical signature `(&Self) -> bool`, byte-identical
1686 /// two-step short-circuit body composed against the ephemeral
1687 /// surface's own union primitive. Both methods compose against
1688 /// the SAME slice-level substrate primitive
1689 /// [`ConditionSliceExt::has_unique_distinct_kind`] via the
1690 /// two-slice union — a regression at the per-slice singleton-
1691 /// coverage walk fails at that primitive's tests rather than as
1692 /// silent drift at either struct-level singleton-coverage caller.
1693 ///
1694 /// # Sibling to [`Self::has_unique_missing_condition_kind`]
1695 ///
1696 /// Closed-set-inversion peer of the cardinality-mid-endpoint on
1697 /// the closed-set-complement axis at the boundary union struct
1698 /// layer — where `has_unique_missing_condition_kind` returns
1699 /// `true` iff the union is one kind AWAY from covered (missing
1700 /// EXACTLY one), `has_unique_distinct_condition_kind` returns
1701 /// `true` iff the union covers EXACTLY one kind (the singleton-
1702 /// coverage arm). Both compose against a two-step-short-circuit
1703 /// walk over [`ConditionKind::ALL`] under
1704 /// [`Self::has_condition_kind`] (this primitive) vs
1705 /// `!has_condition_kind` (the missing peer).
1706 ///
1707 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1708 /// preserves proofs — the cardinality-mid-endpoint projection on
1709 /// the closed-set-inversion axis composes the SAME two-step
1710 /// short-circuit walk under a two-slice union on both this
1711 /// boundary surface and the ephemeral surface). THEORY.md §VI.1
1712 /// (generation over composition — a new [`ConditionKind`]
1713 /// variant reaches both surfaces' cardinality-mid-endpoint triads
1714 /// mechanically through the delegated union primitive).
1715 #[must_use]
1716 pub fn has_unique_distinct_condition_kind(&self) -> bool {
1717 let mut it = ConditionKind::ALL
1718 .iter()
1719 .copied()
1720 .filter(|k| self.has_condition_kind(*k));
1721 it.next().is_some() && it.next().is_none()
1722 }
1723
1724 /// `true` iff [`Self::preconditions`] carries EXACTLY ONE
1725 /// [`ConditionKind::ALL`] variant — the precondition-side arm of
1726 /// the (precondition, postcondition, condition-union)
1727 /// cardinality-mid-endpoint triad on [`Boundary`] on the closed-
1728 /// set-inversion axis. Thin typed delegate to
1729 /// [`ConditionSliceExt::has_unique_distinct_kind`] over
1730 /// [`Self::preconditions`].
1731 ///
1732 /// Peer of [`Self::has_unique_distinct_postcondition_kind`] on the
1733 /// (precondition, postcondition) partition of the boundary's two
1734 /// condition-vector slots; both peers compose against the SAME
1735 /// slice-level substrate primitive so a regression at the per-
1736 /// slice two-step short-circuit walk fails at that primitive's
1737 /// tests rather than as silent drift at either struct-level arm.
1738 #[must_use]
1739 pub fn has_unique_distinct_precondition_kind(&self) -> bool {
1740 self.preconditions.has_unique_distinct_kind()
1741 }
1742
1743 /// `true` iff [`Self::postconditions`] carries EXACTLY ONE
1744 /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
1745 /// the (precondition, postcondition, condition-union)
1746 /// cardinality-mid-endpoint triad on [`Boundary`] on the closed-
1747 /// set-inversion axis. Thin typed delegate to
1748 /// [`ConditionSliceExt::has_unique_distinct_kind`] over
1749 /// [`Self::postconditions`].
1750 ///
1751 /// Peer of [`Self::has_unique_distinct_precondition_kind`]. See
1752 /// that method for the full rationale — the two methods share ONE
1753 /// lift motivation, ONE fail-before-pass-after composition-law
1754 /// pin, and ONE two-surface parity contract with the ephemeral
1755 /// sugar type via
1756 /// [`crate::ephemeral::EphemeralSpec::has_unique_distinct_postcondition_kind`].
1757 #[must_use]
1758 pub fn has_unique_distinct_postcondition_kind(&self) -> bool {
1759 self.postconditions.has_unique_distinct_kind()
1760 }
1761
1762 /// `true` iff `preconditions ∪ postconditions` is MISSING EXACTLY
1763 /// ONE [`ConditionKind::ALL`] variant — the union arm of the
1764 /// (precondition, postcondition, condition-union) cardinality-mid-
1765 /// endpoint triad on [`Boundary`] closing the "one hole remaining"
1766 /// near-saturation-endpoint on the union of the two condition
1767 /// slots. The near-saturation-endpoint Boolean fast-path peer of
1768 /// [`Self::is_condition_kind_saturated`] on the union axis: where
1769 /// the saturation-endpoint predicate answers "is the union covered
1770 /// by every ALL variant?", `has_unique_missing_condition_kind`
1771 /// answers "is the union one kind away from covered?".
1772 ///
1773 /// Composed body: constructs a two-step-short-circuit walk over
1774 /// [`ConditionKind::ALL`] under the [`Self::has_condition_kind`]
1775 /// union primitive negated — the first missing union arm surfaces,
1776 /// then the walk short-circuits at the second. Byte-for-byte peer
1777 /// of [`ConditionSliceExt::has_unique_missing_kind`] one slice-
1778 /// layer down, lifted to compose against
1779 /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1780 /// against a single slice's `has_kind`. A regression at the union
1781 /// primitive fails at the slice-level substrate tests + the union
1782 /// composition-law tests rather than as silent drift here.
1783 ///
1784 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_unique_missing_condition_kind`]
1785 ///
1786 /// Byte-identical signature `(&Self) -> bool`, byte-identical
1787 /// two-step short-circuit body composed against the ephemeral
1788 /// surface's own union primitive. Both methods compose against
1789 /// the SAME slice-level substrate primitive
1790 /// [`ConditionSliceExt::has_unique_missing_kind`] via the two-
1791 /// slice union — a regression at the per-slice near-saturation-
1792 /// endpoint walk fails at that primitive's tests rather than as
1793 /// silent drift at either struct-level near-saturation caller.
1794 ///
1795 /// # Compounding
1796 ///
1797 /// A future operator-facing "one kind away from saturated" gap-
1798 /// analysis diagnostic reads
1799 /// `boundary.has_unique_missing_condition_kind()` at ONE call site
1800 /// rather than restating either `boundary.missing_condition_kind_count() == 1`
1801 /// (which walks every slot to count) or
1802 /// `boundary.missing_condition_kinds().len() == 1` (which
1803 /// allocates the Vec). A `has-unique-missing-condition-kind`
1804 /// require-tag classifier arm reaches this primitive at ONE
1805 /// substrate call — byte-for-byte peer of the tagged-union
1806 /// `has-unique-missing-kind` classifier one struct-layer up.
1807 ///
1808 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1809 /// preserves proofs — the cardinality-mid-endpoint projection on
1810 /// the missing axis composes the SAME two-step short-circuit walk
1811 /// under a two-slice union negation on both this boundary surface
1812 /// and the ephemeral surface). THEORY.md §VI.1 (generation over
1813 /// composition — a new [`ConditionKind`] variant reaches both
1814 /// surfaces' cardinality-mid-endpoint triads mechanically through
1815 /// the delegated union primitive).
1816 #[must_use]
1817 pub fn has_unique_missing_condition_kind(&self) -> bool {
1818 let mut it = ConditionKind::ALL
1819 .iter()
1820 .copied()
1821 .filter(|k| !self.has_condition_kind(*k));
1822 it.next().is_some() && it.next().is_none()
1823 }
1824
1825 /// `true` iff [`Self::preconditions`] is MISSING EXACTLY ONE
1826 /// [`ConditionKind::ALL`] variant — the precondition-side arm of
1827 /// the (precondition, postcondition, condition-union) cardinality-
1828 /// mid-endpoint triad on [`Boundary`]. Thin typed delegate to
1829 /// [`ConditionSliceExt::has_unique_missing_kind`] over
1830 /// [`Self::preconditions`].
1831 ///
1832 /// Peer of [`Self::has_unique_missing_postcondition_kind`] on the
1833 /// (precondition, postcondition) partition of the boundary's two
1834 /// condition-vector slots; both peers compose against the SAME
1835 /// slice-level substrate primitive so a regression at the per-
1836 /// slice two-step short-circuit walk under negation fails at that
1837 /// primitive's tests rather than as silent drift at either
1838 /// struct-level arm.
1839 #[must_use]
1840 pub fn has_unique_missing_precondition_kind(&self) -> bool {
1841 self.preconditions.has_unique_missing_kind()
1842 }
1843
1844 /// `true` iff [`Self::postconditions`] is MISSING EXACTLY ONE
1845 /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
1846 /// the (precondition, postcondition, condition-union) cardinality-
1847 /// mid-endpoint triad on [`Boundary`]. Thin typed delegate to
1848 /// [`ConditionSliceExt::has_unique_missing_kind`] over
1849 /// [`Self::postconditions`].
1850 ///
1851 /// Peer of [`Self::has_unique_missing_precondition_kind`]. See
1852 /// that method for the full rationale — the two methods share ONE
1853 /// lift motivation, ONE fail-before-pass-after composition-law
1854 /// pin, and ONE two-surface parity contract with the ephemeral
1855 /// sugar type via
1856 /// [`crate::ephemeral::EphemeralSpec::has_unique_missing_postcondition_kind`].
1857 #[must_use]
1858 pub fn has_unique_missing_postcondition_kind(&self) -> bool {
1859 self.postconditions.has_unique_missing_kind()
1860 }
1861
1862 /// `true` iff `preconditions ∪ postconditions` is MISSING AT
1863 /// LEAST TWO [`ConditionKind::ALL`] variants — the union arm of
1864 /// the (precondition, postcondition, condition-union) cardinality-
1865 /// many-arm triad on [`Boundary`] closing the "≥ 2 holes
1866 /// remaining" arm on the union of the two condition slots. The
1867 /// many-arm Boolean fast-path peer of
1868 /// [`Self::has_unique_missing_condition_kind`] (=1 arm) and
1869 /// [`Self::is_condition_kind_saturated`] (=0 arm) on the union
1870 /// axis, closing the {0, 1, ≥2} trichotomy at the union struct
1871 /// layer.
1872 ///
1873 /// Composed body: constructs a two-step-short-circuit walk over
1874 /// [`ConditionKind::ALL`] under the [`Self::has_condition_kind`]
1875 /// union primitive negated — pulls up to two hits off the
1876 /// filtered iterator; the primitive returns `true` iff BOTH the
1877 /// first and the second are [`Some`]. Byte-for-byte peer of
1878 /// [`ConditionSliceExt::has_multiple_missing_kinds`] one slice-
1879 /// layer down, lifted to compose against
1880 /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1881 /// against a single slice's `has_kind`. A regression at the union
1882 /// primitive fails at the slice-level substrate tests + the union
1883 /// composition-law tests rather than as silent drift here.
1884 ///
1885 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_multiple_missing_condition_kind`]
1886 ///
1887 /// Byte-identical signature `(&Self) -> bool`, byte-identical
1888 /// two-step short-circuit body composed against the ephemeral
1889 /// surface's own union primitive. Both methods compose against
1890 /// the SAME slice-level substrate primitive
1891 /// [`ConditionSliceExt::has_multiple_missing_kinds`] via the two-
1892 /// slice union — a regression at the per-slice many-arm walk
1893 /// fails at that primitive's tests rather than as silent drift at
1894 /// either struct-level many-missing caller.
1895 ///
1896 /// # Compounding
1897 ///
1898 /// A future operator-facing "≥ 2 dependencies still unfulfilled"
1899 /// gap-analysis diagnostic reads
1900 /// `boundary.has_multiple_missing_condition_kind()` at ONE call
1901 /// site rather than restating
1902 /// `boundary.missing_condition_kind_count() >= 2` (which walks
1903 /// every slot to count) or
1904 /// `boundary.missing_condition_kinds().len() >= 2` (which
1905 /// allocates the Vec). A `has-multiple-missing-condition-kind`
1906 /// require-tag classifier arm reaches this primitive at ONE
1907 /// substrate call — byte-for-byte peer of the tagged-union
1908 /// `has-multiple-missing-kinds` classifier one struct-layer up.
1909 ///
1910 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
1911 /// preserves proofs — the cardinality-many-arm projection on the
1912 /// missing axis composes the SAME two-step short-circuit walk
1913 /// under a two-slice union negation on both this boundary surface
1914 /// and the ephemeral surface). THEORY.md §VI.1 (generation over
1915 /// composition — a new [`ConditionKind`] variant reaches both
1916 /// surfaces' cardinality-many-arm triads mechanically through the
1917 /// delegated union primitive).
1918 #[must_use]
1919 pub fn has_multiple_missing_condition_kind(&self) -> bool {
1920 let mut it = ConditionKind::ALL
1921 .iter()
1922 .copied()
1923 .filter(|k| !self.has_condition_kind(*k));
1924 it.next().is_some() && it.next().is_some()
1925 }
1926
1927 /// `true` iff [`Self::preconditions`] is MISSING AT LEAST TWO
1928 /// [`ConditionKind::ALL`] variants — the precondition-side arm of
1929 /// the (precondition, postcondition, condition-union) cardinality-
1930 /// many-arm triad on [`Boundary`]. Thin typed delegate to
1931 /// [`ConditionSliceExt::has_multiple_missing_kinds`] over
1932 /// [`Self::preconditions`].
1933 ///
1934 /// Peer of [`Self::has_multiple_missing_postcondition_kind`] on
1935 /// the (precondition, postcondition) partition of the boundary's
1936 /// two condition-vector slots; both peers compose against the
1937 /// SAME slice-level substrate primitive so a regression at the
1938 /// per-slice two-step short-circuit walk under negation fails at
1939 /// that primitive's tests rather than as silent drift at either
1940 /// struct-level arm.
1941 #[must_use]
1942 pub fn has_multiple_missing_precondition_kind(&self) -> bool {
1943 self.preconditions.has_multiple_missing_kinds()
1944 }
1945
1946 /// `true` iff [`Self::postconditions`] is MISSING AT LEAST TWO
1947 /// [`ConditionKind::ALL`] variants — the postcondition-side arm of
1948 /// the (precondition, postcondition, condition-union) cardinality-
1949 /// many-arm triad on [`Boundary`]. Thin typed delegate to
1950 /// [`ConditionSliceExt::has_multiple_missing_kinds`] over
1951 /// [`Self::postconditions`].
1952 ///
1953 /// Peer of [`Self::has_multiple_missing_precondition_kind`]. See
1954 /// that method for the full rationale — the two methods share ONE
1955 /// lift motivation, ONE fail-before-pass-after composition-law
1956 /// pin, and ONE two-surface parity contract with the ephemeral
1957 /// sugar type via
1958 /// [`crate::ephemeral::EphemeralSpec::has_multiple_missing_postcondition_kind`].
1959 #[must_use]
1960 pub fn has_multiple_missing_postcondition_kind(&self) -> bool {
1961 self.postconditions.has_multiple_missing_kinds()
1962 }
1963
1964 /// `true` iff `preconditions ∪ postconditions` is MISSING AT MOST
1965 /// ONE [`ConditionKind::ALL`] variant — the union arm of the
1966 /// (precondition, postcondition, condition-union) cardinality
1967 /// "≤ 1" triad on [`Boundary`] closing the "at most one hole
1968 /// remaining" arm on the union of the two condition slots. The
1969 /// Boolean cardinality "≤ 1" negation peer of
1970 /// [`Self::has_multiple_missing_condition_kind`] (≥ 2 many-arm)
1971 /// under the definitional negation
1972 /// `!has_multiple_missing_condition_kind`, and the trichotomy-
1973 /// union peer of [`Self::is_condition_kind_saturated`] (=0
1974 /// zero-arm) OR [`Self::has_unique_missing_condition_kind`] (=1
1975 /// mid-endpoint) — the arrangement space where the boundary is
1976 /// SATURATED-OR-NEAR-SATURATED (zero or exactly one kind missing
1977 /// across the union of the two slices).
1978 ///
1979 /// Composed body: `!self.has_multiple_missing_condition_kind()` —
1980 /// a definitional negation of the many-arm union primitive. Short-
1981 /// circuits transitively through
1982 /// [`Self::has_multiple_missing_condition_kind`]'s two-step short-
1983 /// circuit walk over [`ConditionKind::ALL`] under negated
1984 /// [`Self::has_condition_kind`] — returns `true` as soon as the
1985 /// many-arm walk stops with fewer than two missing hits, WITHOUT
1986 /// materializing [`Self::missing_condition_kinds`]'s `Vec` and
1987 /// WITHOUT walking every slot to build
1988 /// [`Self::missing_condition_kind_count`]'s scalar. Byte-for-byte
1989 /// peer of [`ConditionSliceExt::has_at_most_one_missing_kind`] one
1990 /// slice-layer down, lifted to compose against
1991 /// [`Self::has_condition_kind`]'s pre-OR-post union rather than
1992 /// against a single slice's `has_kind`. A regression at the union
1993 /// primitive fails at the slice-level substrate tests + the union
1994 /// composition-law tests rather than as silent drift here.
1995 ///
1996 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_at_most_one_missing_condition_kind`]
1997 ///
1998 /// Byte-identical signature `(&Self) -> bool`, byte-identical
1999 /// definitional-negation body composed against the ephemeral
2000 /// surface's own many-arm union primitive. Both methods compose
2001 /// against the SAME slice-level substrate primitive
2002 /// [`ConditionSliceExt::has_at_most_one_missing_kind`] via the
2003 /// two-slice union — a regression at the per-slice "≤ 1" negation
2004 /// fails at that primitive's tests rather than as silent drift at
2005 /// either struct-level near-saturation-or-saturated caller.
2006 ///
2007 /// # Compounding
2008 ///
2009 /// A future operator-facing "at most one dependency still
2010 /// unfulfilled" gap-analysis diagnostic reads
2011 /// `boundary.has_at_most_one_missing_condition_kind()` at ONE call
2012 /// site rather than restating
2013 /// `boundary.missing_condition_kind_count() <= 1` (which walks every
2014 /// slot to count) or `boundary.missing_condition_kinds().len() <= 1`
2015 /// (which allocates the Vec) or the union of the two Booleans
2016 /// `boundary.is_condition_kind_saturated() ||
2017 /// boundary.has_unique_missing_condition_kind()` (which walks the
2018 /// closed-set-complement scan twice). A `has-at-most-one-missing-
2019 /// condition-kind` require-tag classifier arm reaches this
2020 /// primitive at ONE substrate call — byte-for-byte peer of the
2021 /// tagged-union `has-at-most-one-missing-kind` classifier one
2022 /// struct-layer up, closing the {0, 1, ≥ 2, ≤ 1} cardinality-
2023 /// Boolean grid on the missing axis at the Boundary struct layer
2024 /// alongside its sibling `has-multiple-missing-condition-kind`
2025 /// under the Boolean negation axis.
2026 ///
2027 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2028 /// preserves proofs — the cardinality "≤ 1" projection on the
2029 /// missing axis composes the SAME definitional negation of the
2030 /// many-arm two-step short-circuit walk on both this boundary
2031 /// surface and the ephemeral surface). THEORY.md §VI.1 (generation
2032 /// over composition — a new [`ConditionKind`] variant reaches both
2033 /// surfaces' cardinality "≤ 1" triads mechanically through the
2034 /// delegated union primitive).
2035 #[must_use]
2036 pub fn has_at_most_one_missing_condition_kind(&self) -> bool {
2037 !self.has_multiple_missing_condition_kind()
2038 }
2039
2040 /// `true` iff [`Self::preconditions`] is MISSING AT MOST ONE
2041 /// [`ConditionKind::ALL`] variant — the precondition-side arm of
2042 /// the (precondition, postcondition, condition-union) cardinality
2043 /// "≤ 1" triad on [`Boundary`]. Thin typed delegate to
2044 /// [`ConditionSliceExt::has_at_most_one_missing_kind`] over
2045 /// [`Self::preconditions`].
2046 ///
2047 /// Peer of [`Self::has_at_most_one_missing_postcondition_kind`]
2048 /// on the (precondition, postcondition) partition of the boundary's
2049 /// two condition-vector slots; both peers compose against the SAME
2050 /// slice-level substrate primitive so a regression at the per-
2051 /// slice "≤ 1" negation of the many-arm walk fails at that
2052 /// primitive's tests rather than as silent drift at either
2053 /// struct-level arm.
2054 #[must_use]
2055 pub fn has_at_most_one_missing_precondition_kind(&self) -> bool {
2056 self.preconditions.has_at_most_one_missing_kind()
2057 }
2058
2059 /// `true` iff [`Self::postconditions`] is MISSING AT MOST ONE
2060 /// [`ConditionKind::ALL`] variant — the postcondition-side arm of
2061 /// the (precondition, postcondition, condition-union) cardinality
2062 /// "≤ 1" triad on [`Boundary`]. Thin typed delegate to
2063 /// [`ConditionSliceExt::has_at_most_one_missing_kind`] over
2064 /// [`Self::postconditions`].
2065 ///
2066 /// Peer of [`Self::has_at_most_one_missing_precondition_kind`].
2067 /// See that method for the full rationale — the two methods share
2068 /// ONE lift motivation, ONE fail-before-pass-after composition-
2069 /// law pin, and ONE two-surface parity contract with the
2070 /// ephemeral sugar type via
2071 /// [`crate::ephemeral::EphemeralSpec::has_at_most_one_missing_postcondition_kind`].
2072 #[must_use]
2073 pub fn has_at_most_one_missing_postcondition_kind(&self) -> bool {
2074 self.postconditions.has_at_most_one_missing_kind()
2075 }
2076
2077 /// `true` iff `preconditions ∪ postconditions` carries NO
2078 /// [`Condition`] with the given [`ConditionKind`] — the union arm
2079 /// of the (precondition, postcondition, condition-union)
2080 /// per-kind-complement triad on [`Boundary`], definitional
2081 /// negation of [`Self::has_condition_kind`].
2082 ///
2083 /// # Composed body
2084 ///
2085 /// `!self.has_condition_kind(kind)` — the definitional negation
2086 /// of the two-slice union primitive. Equivalent to the AND of the
2087 /// two half-slice per-kind-complement arms
2088 /// (`self.lacks_precondition_kind(k) && self.lacks_postcondition_kind(k)`),
2089 /// by the boolean identity `!(a || b) == !a && !b`. Both forms
2090 /// return `true` iff BOTH slices lack the addressed kind; the
2091 /// composed body chosen here short-circuits through the union
2092 /// primitive so a regression at the per-slice presence probe fails
2093 /// at that primitive's tests rather than as silent drift at either
2094 /// half-slice complement arm. Equivalent to
2095 /// `self.missing_condition_kinds().contains(&kind)` without
2096 /// materializing the closed-set-complement Vec at every callsite.
2097 ///
2098 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::lacks_condition_kind`]
2099 ///
2100 /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
2101 /// byte-identical `!self.has_condition_kind(kind)` body, on the
2102 /// sugar-surface type whose pre/post condition vectors live
2103 /// directly on the struct. Both methods compose against the SAME
2104 /// slice-level substrate primitive
2105 /// [`ConditionSliceExt::lacks_kind`] via the two-slice union
2106 /// composed through [`Self::has_condition_kind`] — a regression
2107 /// at the per-slice negation fails at that primitive's tests
2108 /// rather than as silent drift at either struct-level complement
2109 /// caller.
2110 ///
2111 /// # Compounding
2112 ///
2113 /// A `lacks-<kind>` require-tag classifier arm — byte-for-byte
2114 /// peer of the tagged-union `lacks-<kind>` classifier one struct-
2115 /// layer up + the future `condition-<kind>` require-tag family's
2116 /// negated dual — reaches this primitive at ONE call site rather
2117 /// than negating `boundary.has_condition_kind(k)` at the callsite
2118 /// or restating `boundary.missing_condition_kinds().contains(&k)`
2119 /// with its allocation.
2120 ///
2121 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2122 /// preserves proofs — the per-kind closed-set-complement
2123 /// projection composes the SAME two-slice union negation on both
2124 /// this boundary surface and the slice-level substrate primitive
2125 /// under definitional negation). THEORY.md §VI.1 (generation over
2126 /// composition — a new [`ConditionKind`] variant reaches both
2127 /// surfaces' complement-triads mechanically through the delegated
2128 /// union primitive).
2129 #[must_use]
2130 pub fn lacks_condition_kind(&self, kind: ConditionKind) -> bool {
2131 !self.has_condition_kind(kind)
2132 }
2133
2134 /// `true` iff [`Self::preconditions`] carries NO [`Condition`]
2135 /// with the given [`ConditionKind`] — the precondition-side arm
2136 /// of the (precondition, postcondition, condition-union)
2137 /// per-kind-complement triad on [`Boundary`]. Thin typed delegate
2138 /// to [`ConditionSliceExt::lacks_kind`] over
2139 /// [`Self::preconditions`].
2140 ///
2141 /// Peer of [`Self::lacks_postcondition_kind`] on the (precondition,
2142 /// postcondition) partition of the boundary's two condition-vector
2143 /// slots; both peers compose against the SAME slice-level substrate
2144 /// primitive so a regression at the per-slice negation fails at
2145 /// that primitive's tests rather than as silent drift at either
2146 /// struct-level arm.
2147 #[must_use]
2148 pub fn lacks_precondition_kind(&self, kind: ConditionKind) -> bool {
2149 self.preconditions.lacks_kind(kind)
2150 }
2151
2152 /// `true` iff [`Self::postconditions`] carries NO [`Condition`]
2153 /// with the given [`ConditionKind`] — the postcondition-side arm
2154 /// of the (precondition, postcondition, condition-union)
2155 /// per-kind-complement triad on [`Boundary`]. Thin typed delegate
2156 /// to [`ConditionSliceExt::lacks_kind`] over
2157 /// [`Self::postconditions`].
2158 ///
2159 /// Peer of [`Self::lacks_precondition_kind`]. See that method for
2160 /// the full rationale — the two methods share ONE lift motivation,
2161 /// ONE fail-before-pass-after composition-law pin, and ONE
2162 /// two-surface parity contract with the ephemeral sugar type via
2163 /// [`crate::ephemeral::EphemeralSpec::lacks_postcondition_kind`].
2164 #[must_use]
2165 pub fn lacks_postcondition_kind(&self, kind: ConditionKind) -> bool {
2166 self.postconditions.lacks_kind(kind)
2167 }
2168
2169 /// `true` iff `preconditions ∪ postconditions` carries at least
2170 /// one [`Condition`] with the given [`ConditionKind`] AND carries
2171 /// no [`Condition`] whose kind is anything OTHER than `kind` — the
2172 /// union arm of the (precondition, postcondition, condition-union)
2173 /// kind-scoped strict-refinement triad on [`Boundary`], byte-for-
2174 /// byte peer of the per-kind presence probe
2175 /// [`Self::has_condition_kind`] under the well-formed-diagonal
2176 /// refinement.
2177 ///
2178 /// # Composed body
2179 ///
2180 /// A FUSED short-circuit closed-set walk over
2181 /// [`ConditionKind::ALL`] under [`Self::has_condition_kind`] that
2182 /// returns `false` at the EARLIEST kind whose presence spans
2183 /// either slice's populated set and is NOT `kind`, and returns
2184 /// `true` iff the sweep completes with `kind` seen as the sole
2185 /// distinct populated kind. Strictly cheaper than the widened
2186 /// composition
2187 /// `boundary.distinct_condition_kinds() == vec![kind]` (which
2188 /// allocates the distinct-kind Vec before the equality test) or
2189 /// the (pre, post) AND-of-strict-refinement
2190 /// `boundary.preconditions.has_only_kind(kind)
2191 /// && boundary.postconditions.has_only_kind(kind)` (which is
2192 /// TOO STRICT — a single-slice-populated arrangement whose empty
2193 /// side returns `false` fails this AND but IS well-formed on the
2194 /// union).
2195 ///
2196 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::has_only_condition_kind`]
2197 ///
2198 /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
2199 /// byte-identical fused-closed-set-walk body, on the sugar-surface
2200 /// type whose pre/post condition vectors live directly on the
2201 /// struct. Both methods compose against the SAME slice-level
2202 /// substrate primitive [`ConditionSliceExt::has_only_kind`] via
2203 /// the two-slice union composed through
2204 /// [`Self::has_condition_kind`] — a regression at the per-slice
2205 /// fused walk fails at that primitive's tests rather than as
2206 /// silent drift at either struct-level kind-scoped-strict-
2207 /// refinement caller.
2208 ///
2209 /// # Compounding
2210 ///
2211 /// A future coherence check verifying "every attested closed-loop
2212 /// probe Process carries ONLY `ClosedLoopAuth` postconditions on
2213 /// the union of pre + post" reads
2214 /// `boundary.has_only_condition_kind(ConditionKind::ClosedLoopAuth)`
2215 /// at ONE call site rather than restating either widened
2216 /// composition. A `has-only-<kind>` require-tag classifier arm
2217 /// reaches this primitive at ONE substrate call — byte-for-byte
2218 /// peer of the tagged-union `has-only-<kind>` classifier one
2219 /// struct-layer up, closing the kind-scoped strict-refinement
2220 /// grid on the well-formed-diagonal arm at the Boundary struct
2221 /// layer alongside its sibling `has-<kind>` under the per-kind
2222 /// presence-probe axis.
2223 ///
2224 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2225 /// preserves proofs — the kind-scoped strict-refinement projection
2226 /// composes the SAME fused short-circuit closed-set walk under
2227 /// [`Self::has_condition_kind`] on both this boundary surface and
2228 /// the ephemeral surface). THEORY.md §VI.1 (generation over
2229 /// composition — a new [`ConditionKind`] variant reaches both
2230 /// surfaces' kind-scoped strict-refinement triads mechanically
2231 /// through the delegated union primitive).
2232 #[must_use]
2233 pub fn has_only_condition_kind(&self, kind: ConditionKind) -> bool {
2234 let mut saw_kind = false;
2235 for k in ConditionKind::ALL {
2236 if !self.has_condition_kind(k) {
2237 continue;
2238 }
2239 if k == kind {
2240 saw_kind = true;
2241 } else {
2242 return false;
2243 }
2244 }
2245 saw_kind
2246 }
2247
2248 /// `true` iff [`Self::preconditions`] carries at least one
2249 /// [`Condition`] with the given [`ConditionKind`] AND carries no
2250 /// [`Condition`] whose kind is anything OTHER than `kind` — the
2251 /// precondition-side arm of the (precondition, postcondition,
2252 /// condition-union) kind-scoped strict-refinement triad on
2253 /// [`Boundary`]. Thin typed delegate to
2254 /// [`ConditionSliceExt::has_only_kind`] over
2255 /// [`Self::preconditions`].
2256 ///
2257 /// Peer of [`Self::has_only_postcondition_kind`] on the
2258 /// (precondition, postcondition) partition of the boundary's two
2259 /// condition-vector slots; both peers compose against the SAME
2260 /// slice-level substrate primitive so a regression at the per-
2261 /// slice fused walk fails at that primitive's tests rather than
2262 /// as silent drift at either struct-level arm.
2263 #[must_use]
2264 pub fn has_only_precondition_kind(&self, kind: ConditionKind) -> bool {
2265 self.preconditions.has_only_kind(kind)
2266 }
2267
2268 /// `true` iff [`Self::postconditions`] carries at least one
2269 /// [`Condition`] with the given [`ConditionKind`] AND carries no
2270 /// [`Condition`] whose kind is anything OTHER than `kind` — the
2271 /// postcondition-side arm of the (precondition, postcondition,
2272 /// condition-union) kind-scoped strict-refinement triad on
2273 /// [`Boundary`]. Thin typed delegate to
2274 /// [`ConditionSliceExt::has_only_kind`] over
2275 /// [`Self::postconditions`].
2276 ///
2277 /// Peer of [`Self::has_only_precondition_kind`]. See that method
2278 /// for the full rationale — the two methods share ONE lift
2279 /// motivation, ONE fail-before-pass-after composition-law pin,
2280 /// and ONE two-surface parity contract with the ephemeral sugar
2281 /// type via
2282 /// [`crate::ephemeral::EphemeralSpec::has_only_postcondition_kind`].
2283 #[must_use]
2284 pub fn has_only_postcondition_kind(&self, kind: ConditionKind) -> bool {
2285 self.postconditions.has_only_kind(kind)
2286 }
2287
2288 /// `true` iff `preconditions ∪ postconditions` carries NO
2289 /// [`Condition`] with the given [`ConditionKind`] AND carries at
2290 /// least one [`Condition`] for every OTHER [`ConditionKind`] — the
2291 /// union arm of the (precondition, postcondition, condition-union)
2292 /// kind-scoped strict-refinement triad on [`Boundary`] specialized
2293 /// to the MISSING axis, byte-for-byte peer of the populated-axis
2294 /// [`Self::has_only_condition_kind`] under closed-set complement.
2295 ///
2296 /// # Composed body
2297 ///
2298 /// A FUSED short-circuit closed-set walk over
2299 /// [`ConditionKind::ALL`] under [`Self::has_condition_kind`] that
2300 /// skips every populated kind, returns `false` at the EARLIEST
2301 /// kind whose absence spans both slices' missing sets and is NOT
2302 /// `kind`, and returns `true` iff the sweep completes with `kind`
2303 /// seen as the sole missing kind. Strictly cheaper than the
2304 /// widened composition
2305 /// `boundary.missing_condition_kinds() == vec![kind]` (which
2306 /// allocates the missing-kind Vec before the equality test) or
2307 /// the (pre AND post) AND-of-strict-refinement
2308 /// `boundary.preconditions.lacks_only_kind(kind)
2309 /// && boundary.postconditions.lacks_only_kind(kind)` (which is
2310 /// TOO STRICT — a single-slice-populated arrangement whose empty
2311 /// side returns `false` fails this AND but IS well-formed on the
2312 /// union).
2313 ///
2314 /// # Peer on the ephemeral surface — [`crate::ephemeral::EphemeralSpec::lacks_only_condition_kind`]
2315 ///
2316 /// Byte-identical signature `(&Self, ConditionKind) -> bool`,
2317 /// byte-identical fused-closed-set-walk body under complement, on
2318 /// the ephemeral sugar surface whose pre/post condition vectors
2319 /// live inline. Both methods compose against the SAME slice-level
2320 /// substrate primitive [`ConditionSliceExt::lacks_only_kind`] via
2321 /// the two-slice union composed through
2322 /// [`Self::has_condition_kind`] — a regression at the per-slice
2323 /// fused walk under complement fails at that primitive's tests
2324 /// rather than as silent drift at either struct-level kind-scoped-
2325 /// strict-refinement-on-missing caller.
2326 ///
2327 /// # Compounding
2328 ///
2329 /// A future coherence check verifying "every partially-attested
2330 /// closed-loop probe Process is missing ONLY the `ClosedLoopAuth`
2331 /// postcondition" reads
2332 /// `boundary.lacks_only_condition_kind(ConditionKind::ClosedLoopAuth)`
2333 /// at ONE call site rather than restating either widened
2334 /// composition. A `lacks-only-<kind>` require-tag classifier arm
2335 /// reaches this primitive at ONE substrate call — byte-for-byte
2336 /// peer of the tagged-union `lacks-only-<kind>` classifier one
2337 /// struct-layer up, CLOSING the kind-scoped strict-refinement 2x2
2338 /// grid on the Boundary struct layer alongside its populated-axis
2339 /// peer [`Self::has_only_condition_kind`].
2340 ///
2341 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
2342 /// preserves proofs — the kind-scoped strict-refinement projection
2343 /// on the missing axis composes the SAME fused short-circuit
2344 /// closed-set walk under [`Self::has_condition_kind`] on both this
2345 /// boundary surface and the ephemeral surface). THEORY.md §VI.1
2346 /// (generation over composition — a new [`ConditionKind`] variant
2347 /// reaches both surfaces' kind-scoped strict-refinement-on-missing
2348 /// triads mechanically through the delegated union primitive).
2349 #[must_use]
2350 pub fn lacks_only_condition_kind(&self, kind: ConditionKind) -> bool {
2351 let mut saw_kind = false;
2352 for k in ConditionKind::ALL {
2353 if self.has_condition_kind(k) {
2354 continue;
2355 }
2356 if k == kind {
2357 saw_kind = true;
2358 } else {
2359 return false;
2360 }
2361 }
2362 saw_kind
2363 }
2364
2365 /// `true` iff [`Self::preconditions`] carries NO [`Condition`]
2366 /// with the given [`ConditionKind`] AND carries at least one
2367 /// [`Condition`] for every OTHER [`ConditionKind`] — the
2368 /// precondition-side arm of the (precondition, postcondition,
2369 /// condition-union) kind-scoped strict-refinement-on-missing triad
2370 /// on [`Boundary`]. Thin typed delegate to
2371 /// [`ConditionSliceExt::lacks_only_kind`] over
2372 /// [`Self::preconditions`].
2373 ///
2374 /// Peer of [`Self::lacks_only_postcondition_kind`] on the
2375 /// (precondition, postcondition) partition of the boundary's two
2376 /// condition-vector slots; both peers compose against the SAME
2377 /// slice-level substrate primitive so a regression at the per-
2378 /// slice fused walk under complement fails at that primitive's
2379 /// tests rather than as silent drift at either struct-level arm.
2380 #[must_use]
2381 pub fn lacks_only_precondition_kind(&self, kind: ConditionKind) -> bool {
2382 self.preconditions.lacks_only_kind(kind)
2383 }
2384
2385 /// `true` iff [`Self::postconditions`] carries NO [`Condition`]
2386 /// with the given [`ConditionKind`] AND carries at least one
2387 /// [`Condition`] for every OTHER [`ConditionKind`] — the
2388 /// postcondition-side arm of the (precondition, postcondition,
2389 /// condition-union) kind-scoped strict-refinement-on-missing triad
2390 /// on [`Boundary`]. Thin typed delegate to
2391 /// [`ConditionSliceExt::lacks_only_kind`] over
2392 /// [`Self::postconditions`].
2393 ///
2394 /// Peer of [`Self::lacks_only_precondition_kind`]. See that method
2395 /// for the full rationale — the two methods share ONE lift
2396 /// motivation, ONE fail-before-pass-after composition-law pin,
2397 /// and ONE two-surface parity contract with the ephemeral sugar
2398 /// type via
2399 /// [`crate::ephemeral::EphemeralSpec::lacks_only_postcondition_kind`].
2400 #[must_use]
2401 pub fn lacks_only_postcondition_kind(&self, kind: ConditionKind) -> bool {
2402 self.postconditions.lacks_only_kind(kind)
2403 }
2404}
2405
2406/// Slice-level `(ConditionKind, presence)` probe on any `&[Condition]`
2407/// — the ONE substrate primitive that owns the
2408/// `.iter().any(|c| c.kind == K)` walk shape both current production
2409/// sites hand-authored past the ★★ PRIME-DIRECTIVE ≥ 2 duplication
2410/// threshold. Callers compose the two-half union at their site
2411/// ([`Boundary::has_condition_kind`] on `preconditions ∪
2412/// postconditions`) or on ONE half only (the ephemeral require-tag
2413/// classifier's `closed-loop-auth` arm on `spec.postconditions`) —
2414/// the primitive owns ONLY the per-slice walk, so the composition
2415/// choice stays typed at the caller.
2416///
2417/// # Why lift
2418///
2419/// Pre-lift the `.iter().any(|c| c.kind == K)` walk lived
2420/// hand-authored at THREE production sites: twice inside
2421/// [`Boundary::has_condition_kind`]'s union (pre + post), once at
2422/// `evaluate_ephemeral_require_tag`'s `closed-loop-auth` arm in
2423/// `tatara-reconciler::bin::tatara-check` (with `matches!` sugar
2424/// instead of `==`, but the same predicate). The (`&[Condition]`,
2425/// `ConditionKind`) → `bool` shape is the substrate primitive: a
2426/// future consumer that walks a `Vec<Condition>` (a coherence check
2427/// that verifies "every `ClosedLoopAuth` postcondition carries an
2428/// `issuer` param key", an editor completion listing which
2429/// [`ConditionKind`] arms appear on ONE side only, a hypothetical
2430/// `postcondition-<kind>` require-tag prefix family that dispatches
2431/// on `postconditions` alone — the peer of the existing
2432/// `condition-<kind>` family that dispatches on the pre ∪ post union
2433/// via [`Boundary::has_condition_kind`]) reaches this ONE primitive
2434/// through `slice.has_kind(k)` instead of restating the `.iter().any`
2435/// closure body.
2436///
2437/// # Sibling to [`Boundary::has_condition_kind`]
2438///
2439/// Same axis, one refinement lower: `Boundary::has_condition_kind` is
2440/// the two-slice-union probe; `has_kind` here is the one-slice probe
2441/// the union composes twice. A future normalization at the presence
2442/// probe shape (widening the return to `Option<&Condition>` for
2443/// deeper diagnostics, adding a debug-build assertion on redundant
2444/// duplicates, switching to a linear scan that also counts matches)
2445/// lands at ONE site here — both [`Boundary::has_condition_kind`] +
2446/// every downstream `slice.has_kind(K)` callsite pick it up
2447/// mechanically.
2448///
2449/// # Compounding
2450///
2451/// [`Self::find_kind`] is the widened primitive returning
2452/// `Option<&Condition>` that both `has_kind` (`self.find_kind(k).
2453/// is_some()`, the default body) and future diagnostic consumers
2454/// compose against. A `has_kind_matching(|&Condition| -> bool)`
2455/// predicate extension similarly lands as ONE new default method on
2456/// this trait — the closed-set discriminator case becomes `has_kind(k)
2457/// == self.has_kind_matching(|c| c.kind == k)` by construction, so a
2458/// regression that drifted one from the other becomes structurally
2459/// impossible past the trait boundary.
2460///
2461/// Theory anchor: THEORY.md §II.1 invariant 5 — composition preserves
2462/// proofs; the per-slice walk lives at ONE substrate site so the
2463/// two-half union in [`Boundary`] and the one-half probe on
2464/// [`crate::ephemeral::EphemeralSpec::postconditions`] compose
2465/// through the SAME primitive. THEORY.md §VI.1 — generation over
2466/// composition; a future `Vec<Condition>` consumer reaches the
2467/// primitive through `slice.has_kind(k)` with no per-caller
2468/// restatement of the `.iter().any(|c| c.kind == K)` closure body.
2469pub trait ConditionSliceExt {
2470 /// Returns an iterator yielding every [`Condition`] in this slice
2471 /// whose [`Condition::kind`] equals `kind`, in slice order — the
2472 /// ONE widened primitive on the slice-level presence-probe axis
2473 /// that both [`Self::find_kind`] (via the default
2474 /// `iter_kind(k).next()` body) and [`Self::has_kind`] (via the
2475 /// transitive `find_kind(k).is_some()` default) compose against.
2476 ///
2477 /// # Sibling to [`Self::find_kind`]
2478 ///
2479 /// One refinement wider: `find_kind` collapses the return to
2480 /// `Option<&Condition>` (yielding only the earliest match);
2481 /// `iter_kind` returns the whole match stream so callers can
2482 /// [`count`](Iterator::count) it, [`collect`](Iterator::collect)
2483 /// it into a `Vec<&Condition>`, ask for the
2484 /// [`nth`](Iterator::nth) element, or compose it with any other
2485 /// std iterator adaptor without re-walking the slice. The default
2486 /// body of `find_kind` is `self.iter_kind(kind).next()` — the
2487 /// two methods share ONE walk semantics by construction, so a
2488 /// regression that drifted the first-match probe from the
2489 /// widened stream becomes structurally impossible past the
2490 /// trait boundary.
2491 ///
2492 /// # Semantics
2493 ///
2494 /// Yields `&c` for each `c` in this slice with `c.kind == kind`,
2495 /// in slice order — a slice that carries multiple matches yields
2496 /// each in turn (the composition law
2497 /// `find_kind(k) == iter_kind(k).next()` binds the first match
2498 /// to the earliest position). An empty slice, or a slice with no
2499 /// matching kind, yields nothing. Byte-for-byte equivalent to
2500 /// `self.iter().filter(|c| c.kind == kind)`.
2501 ///
2502 /// # Compounding
2503 ///
2504 /// A future coherence check that verifies "each
2505 /// [`ConditionKind`] appears at most once per side" reads
2506 /// `slice.iter_kind(k).nth(1).is_none()` at ONE call site
2507 /// rather than restating the count-with-filter closure body.
2508 /// A future diagnostic that enumerates every match of a kind
2509 /// (an operator-facing "3 PromQL preconditions matched" message,
2510 /// an audit dump listing every match of a repeated kind) reaches
2511 /// this ONE primitive through `slice.iter_kind(k).collect()`
2512 /// rather than re-walking the slice with `.iter().filter(...)`
2513 /// at the callsite. The presence-probe axis now carries three
2514 /// refinements (bool via `has_kind`, `Option<&Condition>` via
2515 /// `find_kind`, `impl Iterator<Item = &Condition>` via
2516 /// `iter_kind`) at ONE typed algebra surface — every downstream
2517 /// consumer picks the coarsest one that answers its question and
2518 /// the coarser ones stay compositionally derived from this
2519 /// primitive.
2520 fn iter_kind(&self, kind: ConditionKind) -> KindMatches<'_>;
2521
2522 /// Returns the first [`Condition`] in this slice that carries the
2523 /// given [`ConditionKind`], or `None` if none matches. Default
2524 /// body: `self.iter_kind(kind).next()` — a thin projection of the
2525 /// widened primitive [`Self::iter_kind`] onto its first element.
2526 /// The composition law `find_kind(k) == iter_kind(k).next()`
2527 /// binds the first-match probe to the widened stream at the
2528 /// trait's default body.
2529 ///
2530 /// # Sibling to [`Self::has_kind`]
2531 ///
2532 /// One refinement wider: `has_kind` collapses the return to a
2533 /// `bool`; `find_kind` returns the matching `&Condition` so
2534 /// callers can read [`Condition::params`] without re-walking the
2535 /// slice. The default body of `has_kind` is
2536 /// `self.find_kind(kind).is_some()` — the two methods share ONE
2537 /// walk semantics by construction. Byte-for-byte equivalent to
2538 /// `self.iter().find(|c| c.kind == kind)`.
2539 fn find_kind(&self, kind: ConditionKind) -> Option<&Condition> {
2540 self.iter_kind(kind).next()
2541 }
2542
2543 /// True iff at least one [`Condition`] in this slice carries the
2544 /// given [`ConditionKind`]. Default body: `self.find_kind(kind).
2545 /// is_some()`. The single-slice presence probe both
2546 /// [`Boundary::has_condition_kind`] (twice, in a union) and the
2547 /// ephemeral `closed-loop-auth` require-tag arm (once, on
2548 /// postconditions only) compose against.
2549 fn has_kind(&self, kind: ConditionKind) -> bool {
2550 self.find_kind(kind).is_some()
2551 }
2552
2553 /// Number of [`Condition`]s in this slice carrying the given
2554 /// [`ConditionKind`] — the scalar cardinality refinement on the
2555 /// slice-level presence-probe axis. Default body:
2556 /// `self.iter_kind(kind).count()` — a thin projection of the
2557 /// widened primitive [`Self::iter_kind`] onto its cardinality.
2558 ///
2559 /// # Sibling to [`Self::iter_kind`] / [`Self::find_kind`] / [`Self::has_kind`]
2560 ///
2561 /// Fourth refinement on the presence-probe algebra: `iter_kind`
2562 /// yields the whole match stream, `find_kind` collapses it to the
2563 /// first match, `has_kind` collapses that to a `bool`, and
2564 /// `count_kind` collapses the stream to its cardinality without
2565 /// materializing any intermediate [`Vec`] or `Option`. The
2566 /// composition laws
2567 /// `count_kind(k) == iter_kind(k).count()`,
2568 /// `has_kind(k) == (count_kind(k) > 0)`, and
2569 /// `find_kind(k).is_some() == (count_kind(k) > 0)`
2570 /// share ONE walk semantics by construction; a regression that
2571 /// drifted the cardinality probe from the widened stream becomes
2572 /// structurally impossible past the trait boundary.
2573 ///
2574 /// # Semantics
2575 ///
2576 /// Returns `self.iter().filter(|c| c.kind == kind).count()` — a
2577 /// slice that carries multiple matches returns that count, an
2578 /// empty slice or a slice with no matching kind returns `0`.
2579 ///
2580 /// # Compounding
2581 ///
2582 /// A future coherence check that verifies "each [`ConditionKind`]
2583 /// appears at most once per side" now reads
2584 /// `slice.count_kind(k) <= 1` at ONE call site rather than
2585 /// restating either `slice.iter_kind(k).nth(1).is_none()` or the
2586 /// `iter_kind(k).count() <= 1` idiom. A future require-tag
2587 /// classifier arm that surfaces multiplicity to the operator
2588 /// (a hypothetical `condition-count-<kind>` prefix family that
2589 /// publishes the raw cardinality, an audit dump reporting "3
2590 /// PromQL preconditions matched") reaches this ONE primitive
2591 /// through `slice.count_kind(k)` rather than restating the
2592 /// `.iter_kind(k).count()` chain body at the callsite. The
2593 /// presence-probe axis now carries FOUR refinements at ONE typed
2594 /// algebra surface — every downstream consumer picks the coarsest
2595 /// one that answers its question and the coarser ones stay
2596 /// compositionally derived from [`Self::iter_kind`].
2597 fn count_kind(&self, kind: ConditionKind) -> usize {
2598 self.iter_kind(kind).count()
2599 }
2600
2601 /// The set of [`ConditionKind`] variants that appear at least once in
2602 /// this slice, projected in [`ConditionKind::ALL`] order — the
2603 /// closed-set-inversion refinement on the slice-level presence-probe
2604 /// axis. Default body: `ConditionKind::ALL.into_iter().filter(|k|
2605 /// self.has_kind(*k)).collect()` — a thin projection over the closed
2606 /// set that composes against [`Self::has_kind`] per variant.
2607 ///
2608 /// # Sibling to [`Self::has_kind`] / [`Self::find_kind`] / [`Self::iter_kind`] / [`Self::count_kind`]
2609 ///
2610 /// FIFTH refinement on the presence-probe algebra, distinct in axis
2611 /// from the other four: `has_kind` / `find_kind` / `iter_kind` /
2612 /// `count_kind` fix a [`ConditionKind`] and vary the return type
2613 /// (bool / `Option<&Condition>` / `impl Iterator<Item = &Condition>` /
2614 /// `usize`); this refinement INVERTS the axis by fixing the slice and
2615 /// varying over [`ConditionKind::ALL`], returning the SET of present
2616 /// kinds. The composition law
2617 /// `distinct_kinds().contains(&k) == has_kind(k)` for every
2618 /// `k ∈ ConditionKind::ALL` binds the closed-set-inversion probe to
2619 /// the point probe at the trait's default body.
2620 ///
2621 /// # Semantics — canonical subsequence of [`ConditionKind::ALL`]
2622 ///
2623 /// Returns a `Vec<ConditionKind>` whose elements appear in
2624 /// [`ConditionKind::ALL`] order with no duplicates. A slice that
2625 /// carries the same [`ConditionKind`] at multiple positions
2626 /// contributes ONE entry to the returned set (the closed-set
2627 /// projection collapses multiplicity — a caller that needs the
2628 /// per-kind cardinality reaches for [`Self::count_kind`]). An
2629 /// empty slice, or a slice with no matching kind under any
2630 /// [`ConditionKind::ALL`] variant, returns an empty vec.
2631 ///
2632 /// # Why closed-set-inversion is a distinct axis
2633 ///
2634 /// The other four refinements answer "for THIS kind, how does the
2635 /// slice populate the probe's return type?"; this refinement
2636 /// answers "for THIS slice, which kinds appear at least once?".
2637 /// A consumer that needs to enumerate every present kind for an
2638 /// audit dump (`"boundary carries [PromQL, ClosedLoopAuth]"`), a
2639 /// coherence check that verifies "every process's boundary carries
2640 /// at least ONE of {`JobAttested`, `ClosedLoopAuth`}", or a
2641 /// require-tag family that surfaces the distinct-set as a whole
2642 /// (`condition-kinds-distinct-count`) reaches this refinement
2643 /// rather than paying for a per-kind sweep with `has_kind` at the
2644 /// callsite. The point probe stays composable one axis over
2645 /// (`slice.has_kind(k)` for a fixed `k`); the aggregate refinement
2646 /// lives at the same trait, one axis away.
2647 ///
2648 /// # Compounding
2649 ///
2650 /// A future coherence check that enforces "every boundary carries
2651 /// at least ONE distinct kind" (a warning surfaced when
2652 /// `boundary.distinct_condition_kinds().is_empty()`) reaches this
2653 /// ONE primitive rather than paying for the eight-way
2654 /// `for k in ConditionKind::ALL { if boundary.has_condition_kind(k)
2655 /// { return true; } }` sweep at every callsite. A future require-
2656 /// tag classifier arm that publishes the distinct-set cardinality
2657 /// as a scalar (a hypothetical `condition-kinds-distinct-<n>`
2658 /// prefix family, an audit dump reporting "boundary carries N
2659 /// distinct kinds") reaches this ONE primitive through
2660 /// `boundary.distinct_condition_kinds().len()` rather than
2661 /// restating the closed-set-inverted `.iter().filter(...).count()`
2662 /// idiom at every callsite. The presence-probe axis now carries
2663 /// FIVE refinements at ONE typed algebra surface — the four point-
2664 /// probes fixing a kind AND the ONE closed-set-inversion probe
2665 /// fixing a slice — every downstream consumer picks the one that
2666 /// answers its question and the others stay compositionally
2667 /// derived from the single-source-of-truth widened primitive.
2668 ///
2669 /// # Theory grounding
2670 ///
2671 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2672 /// The closed-set-inversion projection lives at ONE substrate
2673 /// site as a typed projection of [`Self::has_kind`] over the
2674 /// closed set [`ConditionKind::ALL`]. Every downstream aggregate
2675 /// consumer binds through the SAME shape rather than restating
2676 /// the ALL-filter closure body.
2677 /// - THEORY.md §VI.1 — generation over composition. A new
2678 /// [`ConditionKind`] variant added to `ALL` reaches this
2679 /// primitive mechanically (the closed-set walk picks up the new
2680 /// entry) and every downstream consumer sees the wider set
2681 /// without further per-caller edit.
2682 fn distinct_kinds(&self) -> Vec<ConditionKind> {
2683 self.iter_distinct_kinds().collect()
2684 }
2685
2686 /// Zero-allocation iterator peer of [`Self::distinct_kinds`] — walk
2687 /// [`ConditionKind::ALL`] in canonical order and yield every
2688 /// [`ConditionKind`] whose corresponding slot on this slice is
2689 /// populated (at least one [`Condition`] with that kind), WITHOUT
2690 /// materializing an intermediate [`Vec<ConditionKind>`].
2691 ///
2692 /// Default body:
2693 /// `ConditionKind::ALL.iter().copied().filter(|&k| self.has_kind(k))`.
2694 /// The composition law
2695 /// `distinct_kinds() == iter_distinct_kinds().collect::<Vec<_>>()`
2696 /// holds by construction — [`Self::distinct_kinds`]'s default body IS
2697 /// `self.iter_distinct_kinds().collect()`, so a caller that overrides
2698 /// the widened Vec primitive with a divergent walk simultaneously
2699 /// drifts both surfaces (surfacing at the substrate testkit
2700 /// [`assert_slice_refinement_composition_laws`] which pins the Vec
2701 /// projection equals `iter().collect()`).
2702 ///
2703 /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
2704 ///
2705 /// Load-bearing iterator peer of the slice-level closed-set-inversion
2706 /// axis — where `distinct_kinds` returns the SET (heap-allocated
2707 /// `Vec`, canonical `ConditionKind::ALL` order) and
2708 /// `distinct_kind_count` scalar-projects its cardinality,
2709 /// `iter_distinct_kinds` opens the walk as a `Copy` iterator so
2710 /// consumers that need a short-circuiting fold (`.any(|k| pred(k))`,
2711 /// `.find(|&k| pred(k))`, `.take_while(|k| pred(k))`, `.map(|k|
2712 /// project(k))`) avoid the intermediate allocation entirely.
2713 ///
2714 /// # Peer to [`crate::tagged_union::TaggedUnion::iter_populated_kinds`]
2715 ///
2716 /// Same shape at the peer axis one struct layer up: where
2717 /// `iter_populated_kinds` opens the closed-set-inversion walk on the
2718 /// tagged-union parent-level presence-probe axis,
2719 /// `iter_distinct_kinds` opens the closed-set-inversion walk on the
2720 /// slice-level presence-probe axis. Both close the "load-bearing
2721 /// iterator" refinement at two adjacent typescape sites through the
2722 /// SAME `<CLOSED_SET>::ALL.iter().copied().filter(|&k| has_probe(k))`
2723 /// composition body under a POSITIVE point-probe.
2724 ///
2725 /// # Compounding future consumers
2726 ///
2727 /// - Every scalar closed-set-inversion peer already at the trait
2728 /// (`distinct_kind_count`, `first_distinct_kind`,
2729 /// `last_distinct_kind`, `unique_distinct_kind`,
2730 /// `has_any_distinct_kind`) folds a specialization of
2731 /// `ConditionKind::ALL.iter().filter(|k| self.has_kind(**k))` —
2732 /// they can compose over `iter_distinct_kinds()` at ONE substrate
2733 /// site rather than restating the closed-set walk body per peer.
2734 /// - A downstream diagnostic composer (an operator-facing "boundary
2735 /// carries: [{}]" message that streams the label list into a
2736 /// `write!` buffer) reads `slice.iter_distinct_kinds().map(|k|
2737 /// k.label())` and folds through `itertools::join` without the
2738 /// allocation `Vec<ConditionKind> -> String` pays.
2739 ///
2740 /// # Theory grounding
2741 ///
2742 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2743 /// The load-bearing iterator projection lives at ONE substrate
2744 /// site; every downstream aggregate consumer refines it through a
2745 /// standard-library iterator fold rather than restating the
2746 /// [`ConditionKind::ALL`]-walk closure body.
2747 /// - THEORY.md §VI.1 — generation over composition. A new
2748 /// [`ConditionKind`] variant added to `ALL` reaches the walk
2749 /// mechanically (the closed-set filter picks up the new entry) and
2750 /// every downstream fold sees the wider set without further
2751 /// per-caller edit.
2752 fn iter_distinct_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
2753 ConditionKind::ALL
2754 .iter()
2755 .copied()
2756 .filter(|&k| self.has_kind(k))
2757 }
2758
2759 /// Scalar cardinality projection of [`Self::distinct_kinds`] onto
2760 /// its `.len()` — the number of [`ConditionKind`] variants that
2761 /// appear at least once in this slice. Default body:
2762 /// `ConditionKind::ALL.iter().filter(|k| self.has_kind(**k)).count()`
2763 /// — a closed-set walk that composes against [`Self::has_kind`] per
2764 /// variant WITHOUT materializing an intermediate `Vec<ConditionKind>`.
2765 /// A slice that carries the same [`ConditionKind`] at multiple
2766 /// positions contributes `1` to the count (the closed-set projection
2767 /// collapses multiplicity — a caller that needs the per-kind
2768 /// cardinality reaches for [`Self::count_kind`]).
2769 ///
2770 /// # Sibling to [`Self::distinct_kinds`]
2771 ///
2772 /// Scalar projection of the closed-set-inversion widened primitive
2773 /// — where `distinct_kinds` returns the SET (a `Vec<ConditionKind>`
2774 /// in canonical [`ConditionKind::ALL`] order), `distinct_kind_count`
2775 /// collapses that set to its cardinality. The composition law
2776 /// `distinct_kind_count() == distinct_kinds().len()` binds the
2777 /// scalar projection to the widened primitive at the trait's
2778 /// default body and is swept substrate-wide by
2779 /// [`assert_slice_refinement_composition_laws`] as its sixth arm.
2780 ///
2781 /// # Peer to [`crate::tagged_union::TaggedUnion::populated_kind_count`]
2782 ///
2783 /// Same shape at the peer axis one struct layer up: where
2784 /// `populated_kind_count` scalar-projects `populated_kinds` on the
2785 /// tagged-union parent-level closed-set-inversion axis,
2786 /// `distinct_kind_count` scalar-projects `distinct_kinds` on the
2787 /// slice-level closed-set-inversion axis. The two primitives close
2788 /// the scalar-cardinality refinement at two adjacent typescape
2789 /// sites — one per closed-set-addressed slice-level refinement,
2790 /// one per closed-set-addressed tagged-union parent-level
2791 /// refinement — through the SAME `ClosedSet::ALL`-walk shape.
2792 ///
2793 /// # Compounding future consumers
2794 ///
2795 /// - A future coherence check that enforces "every boundary carries
2796 /// at least ONE distinct kind" now reads
2797 /// `slice.distinct_kind_count() > 0` at ONE call site rather than
2798 /// paying for `slice.distinct_kinds().len() > 0` (with its
2799 /// intermediate heap allocation) or the eight-way sweep with
2800 /// `has_kind` at the callsite.
2801 /// - A future require-tag classifier arm that surfaces the
2802 /// distinct-set cardinality as a scalar (a hypothetical
2803 /// `condition-kinds-distinct-<n>` prefix family named in
2804 /// [`Self::distinct_kinds`]'s doc-comment as a compounding-future
2805 /// consumer) reaches this ONE primitive without allocating.
2806 /// - A future audit dump reporting "boundary carries N distinct
2807 /// kinds" reaches `slice.distinct_kind_count()` directly rather
2808 /// than restating the `.iter().filter(...).count()` closure body.
2809 ///
2810 /// # Theory grounding
2811 ///
2812 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2813 /// The scalar cardinality lives at ONE substrate site as a typed
2814 /// projection of [`Self::distinct_kinds`] onto its `.len()`, and
2815 /// the default body composes against [`Self::has_kind`] over the
2816 /// closed set [`ConditionKind::ALL`] byte-identically to
2817 /// `distinct_kinds` without the intermediate `Vec`. Every
2818 /// downstream aggregate consumer binds through the SAME shape
2819 /// rather than paying for the allocation to reach the
2820 /// cardinality.
2821 /// - THEORY.md §VI.1 — generation over composition. A new
2822 /// [`ConditionKind`] variant added to `ALL` reaches this
2823 /// primitive mechanically (the closed-set walk picks up the new
2824 /// entry) and every downstream consumer sees the wider
2825 /// cardinality without further per-caller edit.
2826 fn distinct_kind_count(&self) -> usize {
2827 self.iter_distinct_kinds().count()
2828 }
2829
2830 /// The set of [`ConditionKind`] variants that do NOT appear in this
2831 /// slice, projected in [`ConditionKind::ALL`] order — the closed-
2832 /// set-inversion COMPLEMENT of [`Self::distinct_kinds`]. Default
2833 /// body: `ConditionKind::ALL.into_iter().filter(|k|
2834 /// !self.has_kind(*k)).collect()` — a thin projection over the
2835 /// closed set that composes against [`Self::has_kind`] per variant
2836 /// under a negated predicate.
2837 ///
2838 /// # Sibling to [`Self::distinct_kinds`]
2839 ///
2840 /// Complement peer of the closed-set-inversion widened primitive on
2841 /// the slice-level presence-probe axis. Where `distinct_kinds`
2842 /// returns the SET of kinds that DO appear at least once,
2843 /// `missing_kinds` returns the SET of kinds that DO NOT appear.
2844 /// Both walk [`ConditionKind::ALL`] in canonical order and compose
2845 /// against the same [`Self::has_kind`] point probe. The two
2846 /// widened primitives PARTITION [`ConditionKind::ALL`]: their union
2847 /// equals `ConditionKind::ALL`, their intersection is empty, and
2848 /// their cardinalities sum to `ConditionKind::ALL.len()` — three
2849 /// composition laws pinned as the seventh, eighth, and ninth arms
2850 /// of the substrate testkit
2851 /// [`assert_slice_refinement_composition_laws`].
2852 ///
2853 /// # Peer to [`crate::tagged_union::TaggedUnion::populated_kinds`]'s
2854 /// hypothetical `unpopulated_kinds` complement
2855 ///
2856 /// Same shape at the peer axis one struct layer up: fixing the
2857 /// parent-side carrier and inverting the presence probe over the
2858 /// closed set. The two primitives close the "closed-set complement"
2859 /// refinement at two adjacent typescape sites — one per closed-set-
2860 /// addressed slice-level refinement (this primitive), one per
2861 /// closed-set-addressed tagged-union parent-level refinement (a
2862 /// symmetric future addition).
2863 ///
2864 /// # Semantics — canonical subsequence of [`ConditionKind::ALL`]
2865 ///
2866 /// Returns a `Vec<ConditionKind>` whose elements appear in
2867 /// [`ConditionKind::ALL`] order with no duplicates. An empty slice
2868 /// returns `ConditionKind::ALL.to_vec()` (every kind is missing).
2869 /// A slice that carries every variant returns an empty vec (no kind
2870 /// is missing). A slice that carries the same [`ConditionKind`] at
2871 /// multiple positions still contributes ZERO entries to the missing
2872 /// set at that kind (the closed-set complement is a SET operation —
2873 /// multiplicity on the present side is irrelevant to absence on the
2874 /// missing side).
2875 ///
2876 /// # Compounding future consumers
2877 ///
2878 /// - A future coherence check that enforces "every process boundary
2879 /// carries a [`ConditionKind::JobAttested`] postcondition" now
2880 /// surfaces the operator-facing diagnostic
2881 /// `spec.boundary.postconditions.missing_kinds()` verbatim
2882 /// (naming EVERY kind absent from postconditions in canonical
2883 /// order) rather than reaching for `!has_kind(JobAttested)` at a
2884 /// per-kind callsite and paying to re-author the diagnostic list.
2885 /// - An operator-facing "boundary is MISSING [JobAttested,
2886 /// ClosedLoopAuth]" audit dump reads
2887 /// `boundary.postconditions.missing_kinds()` directly at ONE call
2888 /// site rather than restating the negated closed-set walk at
2889 /// every consumer.
2890 /// - A fleet-wide gap analysis ("which processes are missing a
2891 /// `ClosedLoopAuth` postcondition") reaches this ONE primitive
2892 /// through `spec.boundary.postconditions.missing_kinds()
2893 /// .contains(&ConditionKind::ClosedLoopAuth)` rather than paying
2894 /// for the negated `.has_kind` sweep at every callsite.
2895 /// - A hypothetical `condition-kinds-missing-<n>` require-tag
2896 /// classifier prefix family that publishes the missing-set
2897 /// cardinality as a scalar reads
2898 /// [`Self::missing_kind_count`] (the scalar-cardinality peer of
2899 /// this widened primitive) without allocating.
2900 ///
2901 /// # Theory grounding
2902 ///
2903 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2904 /// The closed-set complement lives at ONE substrate site as a
2905 /// typed projection of [`Self::has_kind`] over the closed set
2906 /// [`ConditionKind::ALL`] under negation. Every downstream gap-
2907 /// analysis consumer binds through the SAME shape rather than
2908 /// restating the negated ALL-filter closure body.
2909 /// - THEORY.md §VI.1 — generation over composition. A new
2910 /// [`ConditionKind`] variant added to `ALL` reaches this
2911 /// primitive mechanically (the closed-set walk picks up the new
2912 /// entry on the missing side WITHOUT further per-caller edit —
2913 /// any slice that doesn't yet populate the new kind sees it
2914 /// listed as missing at every downstream callsite).
2915 fn missing_kinds(&self) -> Vec<ConditionKind> {
2916 self.iter_missing_kinds().collect()
2917 }
2918
2919 /// Zero-allocation iterator peer of [`Self::missing_kinds`] — walk
2920 /// [`ConditionKind::ALL`] in canonical order and yield every
2921 /// [`ConditionKind`] whose corresponding slot on this slice is EMPTY
2922 /// (no [`Condition`] in the slice carries that kind), WITHOUT
2923 /// materializing an intermediate [`Vec<ConditionKind>`].
2924 ///
2925 /// Default body:
2926 /// `ConditionKind::ALL.iter().copied().filter(|&k| !self.has_kind(k))`.
2927 /// The composition law
2928 /// `missing_kinds() == iter_missing_kinds().collect::<Vec<_>>()`
2929 /// holds by construction — [`Self::missing_kinds`]'s default body IS
2930 /// `self.iter_missing_kinds().collect()`, so a caller that overrides
2931 /// the widened Vec primitive with a divergent walk simultaneously
2932 /// drifts both surfaces (surfacing at the substrate testkit
2933 /// [`assert_slice_refinement_composition_laws`] which pins the Vec
2934 /// projection equals `iter().collect()`).
2935 ///
2936 /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
2937 ///
2938 /// Load-bearing iterator peer of the slice-level closed-set-complement
2939 /// axis — where `missing_kinds` returns the SET (heap-allocated `Vec`,
2940 /// canonical `ConditionKind::ALL` order) and `missing_kind_count`
2941 /// scalar-projects its cardinality, `iter_missing_kinds` opens the
2942 /// walk as a `Copy` iterator so consumers that need a short-
2943 /// circuiting fold avoid the intermediate allocation entirely.
2944 ///
2945 /// # Peer to [`Self::iter_distinct_kinds`]
2946 ///
2947 /// Closed-set-COMPLEMENT peer under a NEGATED point-probe. The two
2948 /// iterators PARTITION `ConditionKind::ALL`:
2949 /// `iter_distinct_kinds().chain(iter_missing_kinds()).collect::<HashSet<_>>()`
2950 /// equals `ConditionKind::ALL.iter().copied().collect()`, and the two
2951 /// iterators yield disjoint element sets.
2952 ///
2953 /// # Peer to [`crate::tagged_union::TaggedUnion::iter_missing_kinds`]
2954 ///
2955 /// Same shape at the peer axis one struct layer up: where
2956 /// `iter_missing_kinds` on the tagged-union parent opens the closed-
2957 /// set-complement walk under a negated `has` point-probe, this method
2958 /// opens the SAME walk on the slice-level presence-probe axis under a
2959 /// negated `has_kind` point-probe. Both close the "load-bearing
2960 /// iterator on the complement side" refinement at two adjacent
2961 /// typescape sites through the SAME
2962 /// `<CLOSED_SET>::ALL.iter().copied().filter(|&k| !has_probe(k))`
2963 /// composition body.
2964 ///
2965 /// # Compounding future consumers
2966 ///
2967 /// - Every scalar closed-set-complement peer already at the trait
2968 /// (`missing_kind_count`, `first_missing_kind`, `last_missing_kind`,
2969 /// `unique_missing_kind`, `is_kind_saturated`,
2970 /// `has_any_missing_kind`, `has_unique_missing_kind`,
2971 /// `has_multiple_missing_kinds`, `has_at_most_one_missing_kind`)
2972 /// folds a specialization of
2973 /// `ConditionKind::ALL.iter().filter(|k| !self.has_kind(**k))` —
2974 /// they can compose over `iter_missing_kinds()` at ONE substrate
2975 /// site rather than restating the closed-set walk body per peer.
2976 /// - A downstream diagnostic composer (an operator-facing "still
2977 /// missing: [{}]" message that streams the label list into a
2978 /// `write!` buffer on the partially-populated arm) reads
2979 /// `slice.iter_missing_kinds().map(|k| k.label())` and folds through
2980 /// `itertools::join` without the allocation `Vec<ConditionKind> ->
2981 /// String` pays.
2982 ///
2983 /// # Theory grounding
2984 ///
2985 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
2986 /// The load-bearing iterator projection on the complement side
2987 /// lives at ONE substrate site, byte-for-byte symmetrical with
2988 /// [`Self::iter_distinct_kinds`] under a negated `has_kind`
2989 /// predicate.
2990 /// - THEORY.md §VI.1 — generation over composition. A new
2991 /// [`ConditionKind`] variant added to `ALL` reaches the walk
2992 /// mechanically (the closed-set filter picks up the new entry on
2993 /// the missing side) and every downstream fold sees the wider
2994 /// complement without further per-caller edit.
2995 fn iter_missing_kinds(&self) -> impl Iterator<Item = ConditionKind> + '_ {
2996 ConditionKind::ALL
2997 .iter()
2998 .copied()
2999 .filter(|&k| !self.has_kind(k))
3000 }
3001
3002 /// Scalar cardinality projection of [`Self::missing_kinds`] onto its
3003 /// `.len()` — the number of [`ConditionKind`] variants that do NOT
3004 /// appear in this slice. Default body:
3005 /// `ConditionKind::ALL.iter().filter(|k| !self.has_kind(**k)).count()`
3006 /// — a closed-set walk composed against [`Self::has_kind`] per variant
3007 /// under a NEGATED point-probe, WITHOUT materializing the intermediate
3008 /// `Vec<ConditionKind>` a caller reaching only for the scalar
3009 /// cardinality otherwise pays for. An empty slice returns
3010 /// `ConditionKind::ALL.len()` (every kind is missing); a slice
3011 /// carrying every variant returns `0` (no kind is missing).
3012 ///
3013 /// # Sibling to [`Self::missing_kinds`] / [`Self::distinct_kind_count`]
3014 ///
3015 /// Scalar projection of the closed-set-complement widened primitive
3016 /// — where `missing_kinds` returns the SET (a `Vec<ConditionKind>`
3017 /// in canonical [`ConditionKind::ALL`] order), `missing_kind_count`
3018 /// collapses that set to its cardinality. The composition law
3019 /// `missing_kind_count() == missing_kinds().len()` binds the scalar
3020 /// projection to the widened primitive at the trait's default body
3021 /// and is swept substrate-wide by
3022 /// [`assert_slice_refinement_composition_laws`] as its scalar-
3023 /// cardinality-complement arm.
3024 ///
3025 /// Byte-for-byte peer of [`Self::distinct_kind_count`] one axis over
3026 /// (under a negated `has_kind` predicate): where `distinct_kind_count`
3027 /// scalar-projects the closed-set-INVERSION widened primitive
3028 /// `distinct_kinds`, this method scalar-projects the closed-set-
3029 /// COMPLEMENT widened primitive `missing_kinds`. The two scalar
3030 /// projections PARTITION the closed-set cardinality:
3031 /// `distinct_kind_count() + missing_kind_count() ==
3032 /// ConditionKind::ALL.len()` — the scalar consequence of the
3033 /// `(distinct_kinds, missing_kinds)` partition law that
3034 /// [`assert_slice_refinement_composition_laws`] pins at the
3035 /// widened-primitive layer.
3036 ///
3037 /// # Peer to [`crate::tagged_union::TaggedUnion::populated_kind_count`]'s
3038 /// hypothetical complement peer
3039 ///
3040 /// Same shape at the peer axis one struct layer up: fixing the
3041 /// slice-side carrier and inverting the presence probe over the
3042 /// closed set under a negated predicate. The two primitives close
3043 /// the "closed-set-complement scalar cardinality" refinement at
3044 /// two adjacent typescape sites — one per closed-set-addressed
3045 /// slice-level refinement (this primitive), one per closed-set-
3046 /// addressed tagged-union parent-level refinement (a symmetric
3047 /// future addition).
3048 ///
3049 /// # Compounding future consumers
3050 ///
3051 /// - A future coherence check that enforces "every process boundary
3052 /// carries EVERY [`ConditionKind`] under some slot" now reads
3053 /// `spec.boundary.postconditions.missing_kind_count() == 0` at
3054 /// ONE call site rather than paying for
3055 /// `spec.boundary.postconditions.missing_kinds().is_empty()`
3056 /// (with its intermediate heap allocation) or the eight-way
3057 /// negated sweep with `has_kind` at the callsite.
3058 /// - A future require-tag classifier arm that surfaces the missing-
3059 /// set cardinality as a scalar (the exact
3060 /// `condition-kinds-missing-<n>` require-tag classifier prefix
3061 /// family called out in [`Self::missing_kinds`]'s doc-comment as
3062 /// a hypothetical compounding-future consumer) reaches this ONE
3063 /// primitive without allocating.
3064 /// - A future gap-analysis dashboard reporting "boundary is missing
3065 /// N of {N_TOTAL} distinct kinds" reaches
3066 /// `slice.missing_kind_count()` directly rather than restating the
3067 /// negated `.iter().filter(...).count()` closure body.
3068 ///
3069 /// # Theory grounding
3070 ///
3071 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3072 /// The scalar cardinality lives at ONE substrate site as a typed
3073 /// projection of [`Self::missing_kinds`] onto its `.len()`, and
3074 /// the default body composes against [`Self::has_kind`] over the
3075 /// closed set [`ConditionKind::ALL`] under negation byte-
3076 /// identically to `missing_kinds` without the intermediate `Vec`.
3077 /// Every downstream aggregate consumer binds through the SAME
3078 /// shape rather than paying for the allocation to reach the
3079 /// cardinality.
3080 /// - THEORY.md §VI.1 — generation over composition. A new
3081 /// [`ConditionKind`] variant added to `ALL` reaches this primitive
3082 /// mechanically (the closed-set walk picks up the new entry on
3083 /// the missing side WITHOUT further per-caller edit — any slice
3084 /// that doesn't yet populate the new kind sees the cardinality
3085 /// rise by one at every downstream callsite).
3086 fn missing_kind_count(&self) -> usize {
3087 self.iter_missing_kinds().count()
3088 }
3089
3090 /// Short-circuiting `Option<ConditionKind>` peer of
3091 /// [`Self::distinct_kinds`] — the FIRST [`ConditionKind`] variant
3092 /// present in this slice, in canonical [`ConditionKind::ALL`] order,
3093 /// or `None` when the slice carries no matching kind. Default body:
3094 /// `ConditionKind::ALL.iter().copied().find(|k| self.has_kind(*k))`
3095 /// — a closed-set walk composed against [`Self::has_kind`] per
3096 /// variant that SHORT-CIRCUITS at the earliest match.
3097 ///
3098 /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
3099 ///
3100 /// Third refinement on the closed-set-inversion axis, `Option<ConditionKind>`-
3101 /// valued: `distinct_kinds` returns the SET, `distinct_kind_count`
3102 /// scalar-projects the cardinality, and `first_distinct_kind`
3103 /// scalar-projects the SET onto its earliest element. The composition
3104 /// law `first_distinct_kind() == distinct_kinds().first().copied()`
3105 /// binds the earliest-element projection to the widened primitive at
3106 /// the trait's default body — pinned substrate-wide by
3107 /// [`assert_slice_refinement_composition_laws`] as its
3108 /// earliest-element-inversion arm. Both coarser projections agree on
3109 /// emptiness: `first_distinct_kind().is_none() ==
3110 /// (distinct_kind_count() == 0)`.
3111 ///
3112 /// # Peer to [`crate::tagged_union::TaggedUnion::first_populated_kind`]
3113 ///
3114 /// Same shape at the peer axis one struct layer up: fixing the
3115 /// carrier and short-circuiting on the earliest [`ConditionKind::ALL`]
3116 /// hit under [`Self::has_kind`]. `TaggedUnion::first_populated_kind`
3117 /// walks the tagged-union parent's closed set; `first_distinct_kind`
3118 /// here walks [`ConditionKind::ALL`] on the slice-level presence-probe
3119 /// axis. The two primitives close the "earliest-element scalar-
3120 /// projection of the closed-set-inversion widened primitive"
3121 /// refinement at two adjacent typescape sites — one per closed-set-
3122 /// addressed slice-level refinement (this primitive), one per closed-
3123 /// set-addressed tagged-union parent-level refinement.
3124 ///
3125 /// # Semantics
3126 ///
3127 /// Returns `Some(k)` where `k` is the earliest [`ConditionKind::ALL`]
3128 /// entry with `self.has_kind(k) == true`, or `None` when no kind is
3129 /// present. An empty slice returns `None`. A slice carrying multiple
3130 /// variants returns the earliest one in [`ConditionKind::ALL`] order
3131 /// — a strictly more informative projection than
3132 /// `distinct_kinds().first().copied()` without materializing the
3133 /// intermediate `Vec<ConditionKind>` the widened primitive
3134 /// otherwise pays for.
3135 ///
3136 /// # Compounding future consumers
3137 ///
3138 /// - An operator-facing "first present kind" diagnostic on an audit
3139 /// dump that names ONE kind rather than the full set reaches this
3140 /// ONE substrate site rather than paying for
3141 /// `slice.distinct_kinds().first().copied()` (with its
3142 /// intermediate heap allocation).
3143 /// - A `first-distinct-<kind>` require-tag classifier arm reads this
3144 /// primitive with no allocation, byte-for-byte symmetrical with
3145 /// `slice.has_kind(kind)` under a closed-set-inversion projection.
3146 /// - A fast-path branch that discriminates "empty" from "any
3147 /// populated" reads `slice.first_distinct_kind().is_some()` at ONE
3148 /// call site rather than allocating a `Vec<ConditionKind>` through
3149 /// `!distinct_kinds().is_empty()` or paying for the full
3150 /// `distinct_kind_count() > 0` walk.
3151 ///
3152 /// # Theory grounding
3153 ///
3154 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs. The
3155 /// earliest-element projection lives at ONE substrate site as a
3156 /// typed projection of [`Self::has_kind`] over the closed set
3157 /// [`ConditionKind::ALL`] under short-circuit walk semantics.
3158 /// - THEORY.md §VI.1 — generation over composition. A new
3159 /// [`ConditionKind`] variant added to `ALL` reaches this primitive
3160 /// mechanically (the closed-set walk picks up the new entry) —
3161 /// every downstream consumer sees the wider earliest-hit projection
3162 /// without further per-caller edit.
3163 fn first_distinct_kind(&self) -> Option<ConditionKind> {
3164 self.iter_distinct_kinds().next()
3165 }
3166
3167 /// Short-circuiting `Option<ConditionKind>` peer of
3168 /// [`Self::missing_kinds`] — the FIRST [`ConditionKind`] variant
3169 /// ABSENT from this slice, in canonical [`ConditionKind::ALL`] order,
3170 /// or `None` when the slice carries every variant. Default body:
3171 /// `ConditionKind::ALL.iter().copied().find(|k| !self.has_kind(*k))`
3172 /// — a closed-set walk composed against [`Self::has_kind`] per
3173 /// variant under NEGATION with SHORT-CIRCUIT at the earliest empty
3174 /// slot.
3175 ///
3176 /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
3177 ///
3178 /// Third refinement on the closed-set-complement axis,
3179 /// `Option<ConditionKind>`-valued: `missing_kinds` returns the SET,
3180 /// `missing_kind_count` scalar-projects the cardinality, and
3181 /// `first_missing_kind` scalar-projects the SET onto its earliest
3182 /// element. The composition law
3183 /// `first_missing_kind() == missing_kinds().first().copied()` binds
3184 /// the earliest-element projection to the widened primitive at the
3185 /// trait's default body — pinned substrate-wide by
3186 /// [`assert_slice_refinement_composition_laws`] as its
3187 /// earliest-element-complement arm. Both coarser projections agree
3188 /// on saturation: `first_missing_kind().is_none() ==
3189 /// (missing_kind_count() == 0)`.
3190 ///
3191 /// # Peer to [`Self::first_distinct_kind`]
3192 ///
3193 /// Closed-set-complement peer of the closed-set-inversion earliest-
3194 /// element primitive under a negated `has_kind` predicate. The two
3195 /// primitives PARTITION [`ConditionKind::ALL`]'s earliest-element
3196 /// projection: at least one of `first_distinct_kind()` and
3197 /// `first_missing_kind()` is `Some` on any non-degenerate closed set
3198 /// (both are `Some` iff `1 ≤ distinct_kind_count() <
3199 /// ConditionKind::ALL.len()`; only the distinct-side is `Some` on a
3200 /// saturated slice; only the missing-side is `Some` on an empty
3201 /// slice).
3202 ///
3203 /// # Peer to [`crate::tagged_union::TaggedUnion::first_missing_kind`]
3204 ///
3205 /// Same shape at the peer axis one struct layer up under a negated
3206 /// predicate. The two primitives close the "earliest-element scalar-
3207 /// projection of the closed-set-complement widened primitive"
3208 /// refinement at two adjacent typescape sites — one per closed-set-
3209 /// addressed slice-level refinement (this primitive), one per closed-
3210 /// set-addressed tagged-union parent-level refinement.
3211 ///
3212 /// # Semantics
3213 ///
3214 /// An empty slice returns `Some(ConditionKind::ALL[0])` (every kind
3215 /// missing, first hit is index 0). A slice populating exactly `k`
3216 /// returns `Some(ConditionKind::ALL[0])` if `k != ALL[0]`, else
3217 /// `Some(ALL[1])` (the earliest non-`k` entry). A saturated slice
3218 /// carrying every variant returns `None`.
3219 ///
3220 /// # Compounding future consumers
3221 ///
3222 /// - An operator-facing "first still-unfilled kind" diagnostic on a
3223 /// partially-populated boundary reads
3224 /// `boundary.postconditions.first_missing_kind()` at ONE substrate
3225 /// site — a strictly-more-informative projection than
3226 /// `!has_kind(JobAttested)` at a per-kind callsite for a fleet-wide
3227 /// "which processes are missing at least one closed-loop kind"
3228 /// audit.
3229 /// - A `first-missing-<kind>` require-tag classifier arm reads this
3230 /// primitive with no allocation, byte-for-byte symmetrical with
3231 /// `slice.first_distinct_kind()`.
3232 /// - A fast-path branch that discriminates "saturated" from "at least
3233 /// one missing" reads `slice.first_missing_kind().is_some()` at ONE
3234 /// call site rather than allocating through
3235 /// `!missing_kinds().is_empty()` or paying for the full
3236 /// `missing_kind_count() > 0` walk.
3237 ///
3238 /// # Theory grounding
3239 ///
3240 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs. The
3241 /// complement-earliest-element projection lives at ONE substrate
3242 /// site as a typed projection of [`Self::has_kind`] over the
3243 /// closed set [`ConditionKind::ALL`] under negation with short-
3244 /// circuit walk semantics.
3245 /// - THEORY.md §VI.1 — generation over composition. A new
3246 /// [`ConditionKind`] variant added to `ALL` reaches this primitive
3247 /// mechanically (the closed-set walk picks up the new entry on the
3248 /// missing side) — every downstream consumer sees the wider
3249 /// complement's earliest hit without further per-caller edit.
3250 fn first_missing_kind(&self) -> Option<ConditionKind> {
3251 self.iter_missing_kinds().next()
3252 }
3253
3254 /// Short-circuiting `Option<ConditionKind>` peer of
3255 /// [`Self::distinct_kinds`] — the LAST [`ConditionKind`] variant
3256 /// present in this slice, in canonical [`ConditionKind::ALL`]
3257 /// order, or `None` when the slice carries no variant. Default
3258 /// body: `ConditionKind::ALL.iter().rev().copied().find(|k|
3259 /// self.has_kind(*k))` — a REVERSED closed-set walk composed
3260 /// against [`Self::has_kind`] per variant that SHORT-CIRCUITS at
3261 /// the latest hit.
3262 ///
3263 /// # Sibling to [`Self::distinct_kinds`] /
3264 /// [`Self::distinct_kind_count`] / [`Self::first_distinct_kind`]
3265 ///
3266 /// Fourth refinement on the closed-set-inversion axis and second
3267 /// scalar `Option<ConditionKind>` projection: `distinct_kinds`
3268 /// returns the SET, `distinct_kind_count` scalar-projects the
3269 /// cardinality, `first_distinct_kind` scalar-projects the SET
3270 /// onto its earliest element, and `last_distinct_kind` scalar-
3271 /// projects the SET onto its latest element. The composition law
3272 /// `last_distinct_kind() == distinct_kinds().last().copied()`
3273 /// binds the latest-element projection to the widened primitive
3274 /// at the trait's default body — pinned substrate-wide by
3275 /// [`assert_slice_refinement_composition_laws`] as its
3276 /// latest-element-inversion arm. Both scalar projections agree on
3277 /// emptiness: `last_distinct_kind().is_none() ==
3278 /// first_distinct_kind().is_none() == distinct_kinds().is_empty()`.
3279 ///
3280 /// # Peer to [`Self::first_distinct_kind`]
3281 ///
3282 /// Time-reversed peer under the SAME `has_kind` predicate: where
3283 /// `first_distinct_kind` walks [`ConditionKind::ALL`] forward and
3284 /// SHORT-CIRCUITS at the earliest hit, this primitive walks the
3285 /// SAME closed set in reverse and SHORT-CIRCUITS at the latest
3286 /// hit. The two primitives close the "endpoint scalar-projection
3287 /// of the closed-set-inversion widened primitive" refinement pair
3288 /// at one substrate site — one per endpoint. On a slice with
3289 /// exactly one distinct kind both projections agree; on a slice
3290 /// with distinct-kind-count ≥ 2 they yield distinct results
3291 /// (the earliest and latest elements of the closed-set-inversion
3292 /// respectively).
3293 ///
3294 /// # Semantics
3295 ///
3296 /// An empty slice returns `None` (no kind present, no hit on any
3297 /// walk direction). A slice populating exactly `k` returns
3298 /// `Some(k)` (single hit; earliest = latest). A saturated slice
3299 /// carrying every variant returns `Some(ConditionKind::ALL.last()
3300 /// .unwrap())` (the last ALL entry hits at the earliest walk step
3301 /// of the reversed walk).
3302 ///
3303 /// # Compounding future consumers
3304 ///
3305 /// - A `last-distinct-<kind>` require-tag classifier arm reads
3306 /// the latest-populated kind through this ONE substrate
3307 /// primitive with no allocation, byte-for-byte symmetrical with
3308 /// the earliest-hit `slice.first_distinct_kind()` peer.
3309 /// - A future coherence check that surfaces "boundary ends with
3310 /// ClosedLoopAuth" reads
3311 /// `spec.boundary.postconditions.last_distinct_kind() ==
3312 /// Some(ConditionKind::ClosedLoopAuth)` at ONE call site rather
3313 /// than paying for `spec.boundary.postconditions
3314 /// .distinct_kinds().last() == Some(&…)` with its intermediate
3315 /// heap allocation.
3316 /// - Combined with [`Self::first_distinct_kind`], operator
3317 /// diagnostics that render a "populated-kind range" summary
3318 /// (`first..=last` on the closed-set-inversion projection) read
3319 /// the two endpoints through TWO substrate primitives at
3320 /// symmetric shapes without allocating.
3321 ///
3322 /// # Theory grounding
3323 ///
3324 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3325 /// The latest-element projection lives at ONE substrate site as
3326 /// a typed projection of [`Self::has_kind`] over the closed set
3327 /// [`ConditionKind::ALL`] under REVERSED short-circuit walk
3328 /// semantics; byte-for-byte peer of the earliest-element
3329 /// projection under FORWARD walk semantics.
3330 /// - THEORY.md §VI.1 — generation over composition. A new
3331 /// [`ConditionKind`] variant added to `ALL` reaches this
3332 /// primitive mechanically (the reversed closed-set walk picks
3333 /// up the new entry at the appropriate position) — every
3334 /// downstream consumer sees the wider latest-hit projection
3335 /// without further per-caller edit.
3336 fn last_distinct_kind(&self) -> Option<ConditionKind> {
3337 self.iter_distinct_kinds().last()
3338 }
3339
3340 /// Short-circuiting `Option<ConditionKind>` peer of
3341 /// [`Self::missing_kinds`] — the LAST [`ConditionKind`] variant
3342 /// ABSENT from this slice, in canonical [`ConditionKind::ALL`]
3343 /// order, or `None` when the slice carries every variant. Default
3344 /// body: `ConditionKind::ALL.iter().rev().copied().find(|k|
3345 /// !self.has_kind(*k))` — a REVERSED closed-set walk composed
3346 /// against [`Self::has_kind`] per variant under NEGATION with
3347 /// SHORT-CIRCUIT at the latest empty slot.
3348 ///
3349 /// # Sibling to [`Self::missing_kinds`] /
3350 /// [`Self::missing_kind_count`] / [`Self::first_missing_kind`]
3351 ///
3352 /// Fourth refinement on the closed-set-complement axis and second
3353 /// scalar `Option<ConditionKind>` projection: `missing_kinds`
3354 /// returns the SET, `missing_kind_count` scalar-projects the
3355 /// cardinality, `first_missing_kind` scalar-projects the SET onto
3356 /// its earliest element, and `last_missing_kind` scalar-projects
3357 /// the SET onto its latest element. The composition law
3358 /// `last_missing_kind() == missing_kinds().last().copied()` binds
3359 /// the latest-element projection to the widened primitive at the
3360 /// trait's default body — pinned substrate-wide by
3361 /// [`assert_slice_refinement_composition_laws`] as its
3362 /// latest-element-complement arm. Both scalar projections agree
3363 /// on saturation: `last_missing_kind().is_none() ==
3364 /// first_missing_kind().is_none() == missing_kinds().is_empty()`.
3365 ///
3366 /// # Peer to [`Self::first_missing_kind`]
3367 ///
3368 /// Time-reversed peer under the SAME negated `has_kind` predicate:
3369 /// where `first_missing_kind` walks [`ConditionKind::ALL`] forward
3370 /// under negation and SHORT-CIRCUITS at the earliest empty slot,
3371 /// this primitive walks the SAME closed set in reverse and SHORT-
3372 /// CIRCUITS at the latest empty slot. The two primitives close
3373 /// the "endpoint scalar-projection of the closed-set-complement
3374 /// widened primitive" refinement pair at one substrate site.
3375 ///
3376 /// # Peer to [`Self::last_distinct_kind`]
3377 ///
3378 /// Closed-set-complement peer of the closed-set-inversion latest-
3379 /// element primitive under a NEGATED `has_kind` predicate. Along
3380 /// with [`Self::first_distinct_kind`] and [`Self::first_missing_kind`]
3381 /// the four scalar-endpoint projections partition the endpoint
3382 /// axis into (present, absent) × (earliest, latest) — every
3383 /// endpoint-addressable coherence check reads ONE of the four at
3384 /// ONE call site, never the full `Vec<ConditionKind>` walk.
3385 ///
3386 /// # Semantics
3387 ///
3388 /// An empty slice returns `Some(ConditionKind::ALL.last().unwrap())`
3389 /// (every kind missing, latest hit is the last ALL entry). A slice
3390 /// populating exactly `k` returns `Some(ALL.last().unwrap())` if
3391 /// `k != ALL.last().unwrap()`, else `Some(ALL[ALL.len() - 2])` (the
3392 /// latest non-`k` entry). A saturated slice carrying every variant
3393 /// returns `None`.
3394 ///
3395 /// # Compounding future consumers
3396 ///
3397 /// - An operator-facing "last still-unfilled kind" diagnostic on a
3398 /// partially-populated boundary reads
3399 /// `boundary.postconditions.last_missing_kind()` at ONE substrate
3400 /// site — a strictly-more-informative projection than
3401 /// `!has_kind(ClosedLoopAuth)` at a per-kind callsite for a
3402 /// fleet-wide "which processes are latest-missing a specific
3403 /// closed-loop kind" audit.
3404 /// - A `last-missing-<kind>` require-tag classifier arm reads this
3405 /// primitive with no allocation, byte-for-byte symmetrical with
3406 /// the earliest-hit `slice.first_missing_kind()` peer.
3407 /// - Combined with [`Self::first_missing_kind`], a coherence check
3408 /// that renders a "missing-kind range" summary reads the two
3409 /// endpoints through TWO substrate primitives at symmetric
3410 /// shapes without allocating through `missing_kinds()`.
3411 ///
3412 /// # Theory grounding
3413 ///
3414 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3415 /// The complement-latest-element projection lives at ONE
3416 /// substrate site as a typed projection of [`Self::has_kind`]
3417 /// over the closed set [`ConditionKind::ALL`] under negation
3418 /// with REVERSED short-circuit walk semantics; byte-for-byte
3419 /// peer of the complement-earliest-element projection under
3420 /// FORWARD walk semantics.
3421 /// - THEORY.md §VI.1 — generation over composition. A new
3422 /// [`ConditionKind`] variant added to `ALL` reaches this
3423 /// primitive mechanically (the reversed closed-set walk picks
3424 /// up the new entry on the missing side at the appropriate
3425 /// position) — every downstream consumer sees the wider
3426 /// complement's latest hit without further per-caller edit.
3427 fn last_missing_kind(&self) -> Option<ConditionKind> {
3428 self.iter_missing_kinds().last()
3429 }
3430
3431 /// Boolean saturation predicate on the closed-set-inversion axis —
3432 /// `true` iff EVERY [`ConditionKind::ALL`] variant appears at least
3433 /// once in this slice (equivalently, [`Self::missing_kinds`] is
3434 /// empty).
3435 ///
3436 /// Default body:
3437 /// `ConditionKind::ALL.iter().all(|k| self.has_kind(*k))` — a
3438 /// SHORT-CIRCUITING closed-set walk composed against [`Self::has_kind`]
3439 /// per variant that returns `false` at the FIRST missing kind,
3440 /// WITHOUT materializing [`Self::missing_kinds`]'s `Vec` and WITHOUT
3441 /// walking every entry to build [`Self::missing_kind_count`]'s
3442 /// scalar. Strictly cheaper than either widened primitive on every
3443 /// partially-populated arm (returns at the first empty slot rather
3444 /// than sweeping the full closed set).
3445 ///
3446 /// # Peer to [`crate::tagged_union::TaggedUnion::is_saturated`]
3447 ///
3448 /// Slice-level peer of the tagged-union parent-level saturation
3449 /// predicate one struct-layer up: where `is_saturated` names the
3450 /// tagged-union arm where every `<Self::Kind as ClosedSet>::ALL`
3451 /// slot is populated, `is_kind_saturated` names the slice arm where
3452 /// every [`ConditionKind::ALL`] variant appears at least once. Both
3453 /// short-circuit at the first missing entry under the SAME
3454 /// `<CLOSED_SET>::ALL.iter().all(has)` walk shape at two adjacent
3455 /// typescape sites.
3456 ///
3457 /// # Sibling to [`Self::missing_kind_count`] / [`Self::missing_kinds`]
3458 ///
3459 /// Boolean cardinality-endpoint peer of the scalar cardinality
3460 /// primitive on the closed-set-complement axis — where
3461 /// `missing_kind_count` returns the FULL scalar (any `usize` in
3462 /// `0..=ConditionKind::ALL.len()`), `is_kind_saturated` collapses
3463 /// that scalar to its zero-arm Boolean projection. The composition
3464 /// law `is_kind_saturated() == (missing_kind_count() == 0)` binds
3465 /// the Boolean projection to the scalar primitive at the trait's
3466 /// default body — swept substrate-wide by
3467 /// [`assert_slice_refinement_composition_laws`] as its
3468 /// saturation-endpoint arm.
3469 ///
3470 /// # Semantics
3471 ///
3472 /// An empty slice returns `false` (no kind is populated). A slice
3473 /// carrying a strict subset of [`ConditionKind::ALL`] returns
3474 /// `false`. A slice that carries every variant at least once
3475 /// (multiplicity is irrelevant) returns `true` — the SOLE arm
3476 /// where `is_kind_saturated` returns `true`.
3477 ///
3478 /// # Compounding future consumers
3479 ///
3480 /// - A future coherence check that enforces "every process boundary
3481 /// exhaustively covers every [`ConditionKind`]" reads
3482 /// `boundary.postconditions.is_kind_saturated()` at ONE call site
3483 /// — one short-circuit walk, no allocation, no scalar equality
3484 /// comparison against `ConditionKind::ALL.len()`.
3485 /// - An `is-kind-saturated` require-tag classifier arm reaches this
3486 /// primitive with no allocation, byte-for-byte peer of the
3487 /// tagged-union `is-saturated` classifier one struct-layer up.
3488 /// - A fleet-wide gap-analysis dashboard fast-path that discriminates
3489 /// "boundary spans every kind" from "boundary is missing some
3490 /// kind" reads `boundary.postconditions.is_kind_saturated()` at
3491 /// ONE call site rather than restating either
3492 /// `boundary.postconditions.missing_kind_count() == 0` (which
3493 /// walks every slot to count) or
3494 /// `boundary.postconditions.missing_kinds().is_empty()` (which
3495 /// allocates the Vec before the emptiness check).
3496 ///
3497 /// # Theory grounding
3498 ///
3499 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3500 /// The saturation-endpoint projection lives at ONE substrate
3501 /// site as a typed short-circuiting closed-set walk
3502 /// `ConditionKind::ALL.iter().all(has_kind)`. Every downstream
3503 /// consumer binds through the SAME shape rather than restating
3504 /// the `== ConditionKind::ALL.len()` scalar composition body.
3505 /// - THEORY.md §VI.1 — generation over composition. A new
3506 /// [`ConditionKind`] variant added to `ALL` reaches this
3507 /// primitive mechanically through the `all` short-circuit — a
3508 /// slice that was previously saturated is no longer saturated
3509 /// at every downstream callsite unless it also carries the new
3510 /// variant.
3511 fn is_kind_saturated(&self) -> bool {
3512 self.iter_missing_kinds().next().is_none()
3513 }
3514
3515 /// Boolean at-least-one halfspace peer of [`Self::has_any_missing_kind`]
3516 /// on the closed-set-inversion axis — `true` iff AT LEAST ONE
3517 /// [`ConditionKind::ALL`] variant appears at least once in this slice
3518 /// (equivalently, [`Self::distinct_kinds`] is non-empty,
3519 /// [`Self::distinct_kind_count`] `> 0`, and
3520 /// [`Self::first_distinct_kind`] is `Some`).
3521 ///
3522 /// Default body: `ConditionKind::ALL.iter().copied().any(|k|
3523 /// self.has_kind(k))` — a SHORT-CIRCUITING closed-set walk that
3524 /// returns `true` at the FIRST populated kind WITHOUT materializing
3525 /// [`Self::distinct_kinds`]'s `Vec`, WITHOUT walking every slot to
3526 /// build [`Self::distinct_kind_count`]'s scalar, and WITHOUT
3527 /// allocating the closed-set-inversion scan. Strictly cheaper than
3528 /// either widened primitive on every non-empty arm because the walk
3529 /// short-circuits at the first `has_kind` hit rather than paying
3530 /// for the Vec allocation or the full cardinality count.
3531 ///
3532 /// # Peer to [`crate::tagged_union::TaggedUnion::has_any_populated_kind`]
3533 ///
3534 /// Slice-level peer of the tagged-union parent-level at-least-one
3535 /// halfspace predicate one struct-layer up: where
3536 /// [`crate::tagged_union::TaggedUnion::has_any_populated_kind`]
3537 /// answers "is ANY slot on the tagged-union parent occupied?",
3538 /// `has_any_distinct_kind` answers "does ANY kind appear in AT
3539 /// LEAST ONE condition of the slice?". Both compose against a
3540 /// SHORT-CIRCUITING closed-set walk under the SAME `has` /
3541 /// `has_kind` predicate at two adjacent typescape sites — the two
3542 /// primitives close the at-least-one halfspace on the closed-set-
3543 /// inversion axis at both struct layers under the SAME shape.
3544 ///
3545 /// # Sibling to [`Self::has_any_missing_kind`]
3546 ///
3547 /// Closed-set-inversion peer of the at-least-one halfspace on the
3548 /// closed-set-complement axis — where `has_any_missing_kind`
3549 /// returns `true` iff at least one kind is ABSENT,
3550 /// `has_any_distinct_kind` returns `true` iff at least one kind is
3551 /// PRESENT. Together with their zero-arm endpoints
3552 /// ([`Self::is_kind_saturated`] on the missing axis and the empty-
3553 /// slice endpoint on the distinct axis), the two Booleans partition
3554 /// the (distinct, missing) product: a slice is EMPTY iff neither
3555 /// `has_any_distinct_kind()` nor `is_kind_saturated()` returns
3556 /// `true`; a slice is SATURATED iff both `has_any_distinct_kind()`
3557 /// returns `true` and `has_any_missing_kind()` returns `false`; a
3558 /// slice is PARTIALLY POPULATED iff both `has_any_distinct_kind()`
3559 /// and `has_any_missing_kind()` return `true`.
3560 ///
3561 /// # Sibling to [`Self::distinct_kinds`] / [`Self::distinct_kind_count`]
3562 ///
3563 /// Boolean at-least-one halfspace peer of the widened + scalar
3564 /// closed-set-inversion primitives — where `distinct_kinds` returns
3565 /// the FULL distinct SET and `distinct_kind_count` returns its
3566 /// cardinality, `has_any_distinct_kind` collapses either the
3567 /// widened primitive to its non-emptiness Boolean or the scalar to
3568 /// its `>= 1` halfspace Boolean. The composition laws
3569 /// `has_any_distinct_kind() == !distinct_kinds().is_empty()` and
3570 /// `has_any_distinct_kind() == (distinct_kind_count() > 0)` bind
3571 /// this Boolean projection to the widened + scalar primitives at
3572 /// the trait's default body — strictly cheaper than either widened
3573 /// primitive on every non-empty arm because the walk short-circuits
3574 /// at the first populated kind on the has-side walk rather than
3575 /// allocating the closed-set-inversion scan or walking every slot
3576 /// to build the scalar cardinality.
3577 ///
3578 /// # Semantics
3579 ///
3580 /// An empty slice returns `false` — the SOLE arm on which
3581 /// `has_any_distinct_kind` returns `false`. A slice carrying any
3582 /// [`ConditionKind`] at least once returns `true` (a single-
3583 /// populated slice, a partially-populated slice, and a saturated
3584 /// slice all return `true`).
3585 ///
3586 /// # Compounding future consumers
3587 ///
3588 /// - A fleet-wide "any coverage at all" fast-path that discriminates
3589 /// "the slice carries at least one closed-set kind" from "the
3590 /// slice is empty" reads
3591 /// `boundary.postconditions.has_any_distinct_kind()` at ONE call
3592 /// site rather than restating `distinct_kind_count() > 0` (which
3593 /// walks every slot to count) or `!distinct_kinds().is_empty()`
3594 /// (which allocates the Vec before the negated emptiness check).
3595 /// - A `has-any-distinct-kind` require-tag classifier arm reaches
3596 /// this primitive with no allocation, byte-for-byte peer of the
3597 /// tagged-union `has-any-populated-kind` classifier one struct-
3598 /// layer up under the SAME `any(has)` short-circuit shape.
3599 /// - A coherence check that flags "any process boundary whose
3600 /// postcondition slice covers at least one [`ConditionKind`]"
3601 /// reads `boundary.postconditions.has_any_distinct_kind()` at
3602 /// ONE substrate primitive per test rather than restating the
3603 /// `.iter().copied().any(|k| slice.has_kind(k))` body at every
3604 /// callsite.
3605 ///
3606 /// # Theory grounding
3607 ///
3608 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3609 /// The at-least-one halfspace projection on the closed-set-
3610 /// inversion axis lives at ONE substrate site as a typed short-
3611 /// circuiting closed-set walk `ConditionKind::ALL.iter().any(
3612 /// has_kind)`. Every downstream consumer whose semantic reading
3613 /// is "at least one kind is present" reads through this
3614 /// primitive rather than paying for the widened primitive's Vec
3615 /// allocation.
3616 /// - THEORY.md §VI.1 — generation over composition. A new
3617 /// [`ConditionKind`] variant added to `ALL` reaches this
3618 /// primitive mechanically through the `any` short-circuit — an
3619 /// empty slice (returning `false` here) that later picks up the
3620 /// new variant returns `true` at every downstream `has-any-
3621 /// distinct-kind` callsite.
3622 fn has_any_distinct_kind(&self) -> bool {
3623 self.iter_distinct_kinds().next().is_some()
3624 }
3625
3626 /// Boolean cardinality-mid-endpoint peer of
3627 /// [`Self::has_any_distinct_kind`] on the closed-set-inversion
3628 /// axis — `true` iff EXACTLY ONE [`ConditionKind::ALL`] variant
3629 /// appears at least once in this slice (equivalently,
3630 /// [`Self::distinct_kind_count`] `== 1`,
3631 /// [`Self::distinct_kinds`]`.len() == 1`, and
3632 /// [`Self::first_distinct_kind`] equals
3633 /// [`Self::last_distinct_kind`] and is [`Some`]).
3634 ///
3635 /// Default body: a two-step-short-circuit closed-set walk over
3636 /// [`Self::iter_distinct_kinds`] — pulls up to two hits off the
3637 /// load-bearing distinct iterator; the primitive returns `true`
3638 /// iff the first hit is [`Some`] and the second is [`None`],
3639 /// WITHOUT materializing [`Self::distinct_kinds`]'s `Vec` and
3640 /// WITHOUT walking every slot to build
3641 /// [`Self::distinct_kind_count`]'s scalar. Short-circuits at the
3642 /// second distinct kind — strictly cheaper than either widened
3643 /// primitive on every arm with `≥ 2` distinct kinds.
3644 ///
3645 /// # Peer to [`crate::tagged_union::TaggedUnion::has_unique_populated_kind`]
3646 ///
3647 /// Slice-level peer of the tagged-union parent-level
3648 /// cardinality-mid-endpoint predicate one struct-layer up: where
3649 /// [`crate::tagged_union::TaggedUnion::has_unique_populated_kind`]
3650 /// answers "is EXACTLY ONE slot on the tagged-union parent
3651 /// occupied?", `has_unique_distinct_kind` answers "does EXACTLY
3652 /// ONE kind appear in AT LEAST ONE condition of the slice?". Both
3653 /// compose against a two-step-short-circuit walk under the SAME
3654 /// presence predicate (`has(kind)` / `has_kind(kind)`) at two
3655 /// adjacent typescape sites — the two primitives close the
3656 /// exactly-one-arm on the closed-set-inversion axis at both
3657 /// struct layers under the SAME shape.
3658 ///
3659 /// # Sibling to [`Self::has_unique_missing_kind`]
3660 ///
3661 /// Closed-set-inversion peer of the cardinality-mid-endpoint on
3662 /// the closed-set-complement axis — where
3663 /// `has_unique_missing_kind` returns `true` iff exactly one kind
3664 /// is ABSENT (the near-saturation-endpoint arm),
3665 /// `has_unique_distinct_kind` returns `true` iff exactly one kind
3666 /// is PRESENT (the singleton-coverage arm). Both close the
3667 /// exactly-one arm on their respective axis under the SAME
3668 /// two-step short-circuit walk shape via the load-bearing
3669 /// iterator peer.
3670 ///
3671 /// # Semantics
3672 ///
3673 /// An empty slice returns `false` (0 distinct, not 1). A slice
3674 /// carrying a single [`ConditionKind`] (with any multiplicity)
3675 /// returns `true` — the SOLE arm where
3676 /// `has_unique_distinct_kind` returns `true` on any `N ≥ 2`
3677 /// closed set. A slice carrying `K ≥ 2` distinct kinds returns
3678 /// `false`. A saturated slice returns `false` on `N ≥ 2` closed
3679 /// sets (every kind present, not exactly 1).
3680 ///
3681 /// # Compounding future consumers
3682 ///
3683 /// - A fleet-wide "singleton coverage" fast-path that
3684 /// discriminates "the slice carries exactly one ALL variant"
3685 /// from every other cardinality reads
3686 /// `boundary.postconditions.has_unique_distinct_kind()` at ONE
3687 /// call site — one two-step short-circuit walk, no allocation,
3688 /// no scalar equality against `1`, byte-for-byte peer of the
3689 /// tagged-union `has-unique-populated-kind` classifier one
3690 /// struct-layer up under the SAME two-step short-circuit shape.
3691 /// - A `has-unique-distinct-kind` require-tag classifier arm
3692 /// reaches this primitive with no allocation.
3693 /// - A future singleton-coverage diagnostic that prints "the SOLE
3694 /// [`ConditionKind`] covered by this Boundary" pairs
3695 /// `has_unique_distinct_kind()` with
3696 /// [`Self::first_distinct_kind`] to name the SOLE distinct kind
3697 /// without allocating [`Self::distinct_kinds`]'s `Vec`.
3698 ///
3699 /// # Theory grounding
3700 ///
3701 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3702 /// The cardinality-mid-endpoint projection on the closed-set-
3703 /// inversion axis lives at ONE substrate site as a typed
3704 /// two-step-short-circuit fold through the load-bearing
3705 /// [`Self::iter_distinct_kinds`] iterator — byte-for-byte peer
3706 /// of `distinct_kind_count()` composed against `== 1`, but with
3707 /// a second-distinct-slot short-circuit that the scalar counter
3708 /// primitive does not offer.
3709 /// - THEORY.md §VI.1 — generation over composition. A new
3710 /// [`ConditionKind`] variant added to `ALL` reaches this
3711 /// primitive mechanically through the short-circuit walk — a
3712 /// slice previously at the singleton-coverage arm (returned
3713 /// `true` here) that also picks up the new variant now has
3714 /// TWO distinct kinds and returns `false`.
3715 fn has_unique_distinct_kind(&self) -> bool {
3716 let mut it = self.iter_distinct_kinds();
3717 it.next().is_some() && it.next().is_none()
3718 }
3719
3720 /// Boolean at-least-one halfspace peer of [`Self::is_kind_saturated`]
3721 /// on the closed-set-complement axis — `true` iff AT LEAST ONE
3722 /// [`ConditionKind::ALL`] variant appears zero times in this slice
3723 /// (equivalently, [`Self::missing_kinds`] is non-empty,
3724 /// [`Self::missing_kind_count`] `> 0`, [`Self::first_missing_kind`]
3725 /// is `Some`).
3726 ///
3727 /// Default body: `!self.is_kind_saturated()` — a definitional
3728 /// negation of the saturation-endpoint primitive. Short-circuits
3729 /// transitively through [`Self::is_kind_saturated`]'s
3730 /// `ConditionKind::ALL.iter().all(has_kind)` composition: the
3731 /// underlying `all` walk returns `false` at the FIRST missing kind
3732 /// (yielding `true` here) WITHOUT materializing
3733 /// [`Self::missing_kinds`]'s `Vec`, WITHOUT walking every slot to
3734 /// build [`Self::missing_kind_count`]'s scalar, and WITHOUT
3735 /// allocating the closed-set-complement scan. Strictly cheaper
3736 /// than either widened primitive on every partially-populated arm.
3737 ///
3738 /// # Peer to [`crate::tagged_union::TaggedUnion::has_any_missing_kind`]
3739 ///
3740 /// Slice-level peer of the tagged-union parent-level at-least-one
3741 /// halfspace predicate one struct-layer up: where
3742 /// [`crate::tagged_union::TaggedUnion::has_any_missing_kind`]
3743 /// answers "is ANY slot on the tagged-union parent empty?",
3744 /// `has_any_missing_kind` answers "does ANY kind appear in NO
3745 /// condition of the slice?". Both compose against their
3746 /// saturation-endpoint primitive under a definitional negation
3747 /// (`!is_saturated` / `!is_kind_saturated`) at two adjacent
3748 /// typescape sites — the two primitives close the at-least-one
3749 /// halfspace on the closed-set-complement axis at both struct
3750 /// layers under the SAME shape.
3751 ///
3752 /// # Sibling to [`Self::is_kind_saturated`]
3753 ///
3754 /// Boolean at-least-one halfspace peer of the zero-arm saturation-
3755 /// endpoint primitive on the closed-set-complement axis — where
3756 /// `is_kind_saturated` returns `true` iff `missing_kind_count == 0`,
3757 /// `has_any_missing_kind` returns its Boolean-negation: `true` iff
3758 /// `missing_kind_count >= 1`. Together the two Booleans partition
3759 /// the missing-cardinality closed set: exactly one of
3760 /// `is_kind_saturated()` and `has_any_missing_kind()` is `true`
3761 /// for every slice. The definitional negation law
3762 /// `has_any_missing_kind() == !is_kind_saturated()` is pinned as a
3763 /// first-class typed invariant by the trait's own default body and
3764 /// swept substrate-wide by
3765 /// [`assert_slice_refinement_composition_laws`] as its at-least-
3766 /// one halfspace arm.
3767 ///
3768 /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
3769 ///
3770 /// Boolean at-least-one halfspace peer of the widened + scalar
3771 /// closed-set-complement primitives — where `missing_kinds` returns
3772 /// the FULL missing SET (a `Vec<ConditionKind>` of every absent
3773 /// kind) and `missing_kind_count` returns its cardinality
3774 /// (a `usize` in `0..=ConditionKind::ALL.len()`),
3775 /// `has_any_missing_kind` collapses either the widened primitive
3776 /// to its non-emptiness Boolean or the scalar to its `>= 1`
3777 /// halfspace Boolean. The composition laws
3778 /// `has_any_missing_kind() == !missing_kinds().is_empty()` and
3779 /// `has_any_missing_kind() == (missing_kind_count() > 0)` bind
3780 /// this Boolean projection to the widened + scalar primitives at
3781 /// the trait's default body — strictly cheaper than either widened
3782 /// primitive on every partially-populated arm because the negation
3783 /// short-circuits at the first missing kind on the has-side walk
3784 /// rather than allocating the closed-set-complement scan or
3785 /// walking every slot to build the scalar cardinality.
3786 ///
3787 /// # Semantics
3788 ///
3789 /// An empty slice returns `true` (every kind is missing — the
3790 /// fully-missing endpoint). A slice carrying a strict subset of
3791 /// [`ConditionKind::ALL`] returns `true`. A saturated slice
3792 /// returns `false` — the SOLE arm on which `has_any_missing_kind`
3793 /// returns `false`, byte-for-byte peer of the SOLE arm on which
3794 /// `is_kind_saturated` returns `true`.
3795 ///
3796 /// # Compounding future consumers
3797 ///
3798 /// - A fleet-wide "gap present" fast-path that discriminates "some
3799 /// kind is missing" from "every kind is present" reads
3800 /// `boundary.postconditions.has_any_missing_kind()` at ONE call
3801 /// site rather than negating `is_kind_saturated()` at the
3802 /// callsite or restating `missing_kind_count() > 0` (which walks
3803 /// every slot to count) or `!missing_kinds().is_empty()` (which
3804 /// allocates the Vec before the negated emptiness check).
3805 /// - A `has-any-missing-kind` require-tag classifier arm reaches
3806 /// this primitive with no allocation, byte-for-byte peer of the
3807 /// tagged-union `has-any-missing-kind` classifier one struct-
3808 /// layer up under the SAME `!is_saturated` definitional negation
3809 /// shape.
3810 /// - A coherence check that flags "any process boundary with a
3811 /// missing [`ConditionKind`]" reads
3812 /// `boundary.postconditions.has_any_missing_kind()` at ONE
3813 /// substrate primitive per test rather than restating the
3814 /// negation body at every callsite.
3815 ///
3816 /// # Theory grounding
3817 ///
3818 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3819 /// The at-least-one halfspace projection lives at ONE substrate
3820 /// site as a definitional negation of
3821 /// [`Self::is_kind_saturated`]. Every downstream consumer whose
3822 /// semantic reading is "at least one kind is absent" reads
3823 /// through this primitive rather than negating `is_kind_saturated`
3824 /// at every callsite or paying for the widened primitive's Vec
3825 /// allocation.
3826 /// - THEORY.md §VI.1 — generation over composition. A new
3827 /// [`ConditionKind`] variant added to `ALL` reaches this
3828 /// primitive mechanically through the delegated
3829 /// `is_kind_saturated` — a slice that was previously saturated
3830 /// (returned `false` here) picks up the new missing variant and
3831 /// returns `true` at every downstream `has-any-missing-kind`
3832 /// callsite unless it also carries the new variant.
3833 fn has_any_missing_kind(&self) -> bool {
3834 !self.is_kind_saturated()
3835 }
3836
3837 /// Boolean cardinality-mid-endpoint peer of
3838 /// [`Self::has_any_missing_kind`] on the closed-set-complement
3839 /// axis — `true` iff EXACTLY ONE [`ConditionKind::ALL`] variant
3840 /// appears zero times in this slice (equivalently,
3841 /// [`Self::missing_kind_count`] `== 1`,
3842 /// [`Self::missing_kinds`]`.len() == 1`, and
3843 /// [`Self::first_missing_kind`] equals
3844 /// [`Self::last_missing_kind`] and is [`Some`]).
3845 ///
3846 /// Default body: a two-step-short-circuit closed-set walk over
3847 /// [`ConditionKind::ALL`] under a negated [`Self::has_kind`]
3848 /// predicate. Pulls up to two hits off the filtered iterator; the
3849 /// primitive returns `true` iff the first hit is [`Some`] and the
3850 /// second is [`None`], WITHOUT materializing
3851 /// [`Self::missing_kinds`]'s `Vec` and WITHOUT walking every slot
3852 /// to build [`Self::missing_kind_count`]'s scalar. Short-circuits
3853 /// at the SECOND missing kind — strictly cheaper than either
3854 /// widened primitive on every arm with `≥ 2` missing kinds.
3855 ///
3856 /// # Peer to [`crate::tagged_union::TaggedUnion::has_unique_missing_kind`]
3857 ///
3858 /// Slice-level peer of the tagged-union parent-level
3859 /// cardinality-mid-endpoint predicate one struct-layer up: where
3860 /// [`crate::tagged_union::TaggedUnion::has_unique_missing_kind`]
3861 /// answers "is EXACTLY ONE slot on the tagged-union parent
3862 /// empty?", `has_unique_missing_kind` answers "does EXACTLY ONE
3863 /// kind appear in NO condition of the slice?". Both compose
3864 /// against a two-step-short-circuit closed-set walk under a
3865 /// negated presence predicate (`!has(kind)` / `!has_kind(kind)`)
3866 /// at two adjacent typescape sites — the two primitives close the
3867 /// exactly-one-arm on the closed-set-complement axis at both
3868 /// struct layers under the SAME shape.
3869 ///
3870 /// # Sibling to the Boolean missing-cardinality trichotomy
3871 ///
3872 /// Second arm of the `{0, 1, ≥2}` cardinality trichotomy on the
3873 /// missing axis, closing the natural partition alongside
3874 /// [`Self::is_kind_saturated`] (zero-arm) and (once its slice-
3875 /// level peer lands) the many-arm predicate. Every slice
3876 /// satisfies EXACTLY ONE of the three Boolean projections — the
3877 /// three primitives partition `0..=ConditionKind::ALL.len()` at
3878 /// 0, 1, and ≥ 2 respectively. The composition law
3879 /// `has_unique_missing_kind() == (missing_kind_count() == 1)`
3880 /// binds the Boolean projection to the scalar primitive at the
3881 /// trait's default body — swept substrate-wide by
3882 /// [`assert_slice_refinement_composition_laws`] as its
3883 /// cardinality-mid-endpoint arm.
3884 ///
3885 /// # Semantics
3886 ///
3887 /// An empty slice returns `false` on any `N ≥ 2` closed set (every
3888 /// kind is missing — the fully-missing endpoint, `N` missing not
3889 /// `1`). A slice carrying `K` distinct kinds for `1 ≤ K ≤ N-2` on
3890 /// `N ≥ 3` closed sets returns `false` (`N - K ≥ 2` kinds missing).
3891 /// A slice at the near-saturation arm (carrying every kind except
3892 /// exactly one) returns `true` — the SOLE arrangement where
3893 /// `has_unique_missing_kind` returns `true`. A saturated slice
3894 /// returns `false` (zero missing).
3895 ///
3896 /// # Compounding future consumers
3897 ///
3898 /// - An operator-facing "one kind away from saturated" fast-path
3899 /// discriminator on the near-saturation arm reads
3900 /// `boundary.postconditions.has_unique_missing_kind()` at ONE
3901 /// call site — one two-step short-circuit walk, no allocation,
3902 /// no scalar equality against `1`, byte-for-byte peer of the
3903 /// tagged-union `has-unique-missing-kind` classifier one struct-
3904 /// layer up under the SAME two-step short-circuit shape.
3905 /// - A `has-unique-missing-kind` require-tag classifier arm
3906 /// reaches this primitive with no allocation, byte-for-byte
3907 /// peer of the tagged-union `has-unique-missing-kind` classifier
3908 /// one struct-layer up.
3909 /// - A future gap-analysis diagnostic that prints "one remaining
3910 /// ConditionKind not covered by this Boundary" pairs
3911 /// `has_unique_missing_kind()` with
3912 /// [`Self::first_missing_kind`] to name the SOLE remaining hole
3913 /// without allocating [`Self::missing_kinds`]'s `Vec`.
3914 ///
3915 /// # Theory grounding
3916 ///
3917 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
3918 /// The cardinality-mid-endpoint projection on the missing axis
3919 /// lives at ONE substrate site as a typed two-step-short-
3920 /// circuit walk over [`ConditionKind::ALL`] under negated
3921 /// [`Self::has_kind`] — byte-for-byte peer of
3922 /// `missing_kind_count()` composed against `== 1`, but with a
3923 /// second-missing-slot short-circuit that the scalar counter
3924 /// primitive does not offer.
3925 /// - THEORY.md §VI.1 — generation over composition. A new
3926 /// [`ConditionKind`] variant added to `ALL` reaches this
3927 /// primitive mechanically through the short-circuit walk — a
3928 /// slice previously at the near-saturation arm (returned `true`
3929 /// here) that omits the new variant now has TWO missing kinds
3930 /// and returns `false`; a slice previously at the
3931 /// saturated-except-one-of-two arm on an `N == 2` closed set
3932 /// remains at the near-saturation arm on `N ≥ 3` iff it
3933 /// picks up every OTHER variant.
3934 fn has_unique_missing_kind(&self) -> bool {
3935 let mut it = self.iter_missing_kinds();
3936 it.next().is_some() && it.next().is_none()
3937 }
3938
3939 /// Boolean cardinality "≥ 2" many-arm peer of
3940 /// [`Self::has_unique_missing_kind`] on the closed-set-complement
3941 /// axis — `true` iff AT LEAST TWO [`ConditionKind::ALL`] variants
3942 /// appear zero times in this slice (equivalently,
3943 /// [`Self::missing_kind_count`] `>= 2` and
3944 /// [`Self::missing_kinds`]`.len() >= 2`).
3945 ///
3946 /// Default body: a two-step-short-circuit closed-set walk over
3947 /// [`ConditionKind::ALL`] under a negated [`Self::has_kind`]
3948 /// predicate. Pulls up to two hits off the filtered iterator; the
3949 /// primitive returns `true` iff BOTH the first and the second are
3950 /// [`Some`], WITHOUT materializing [`Self::missing_kinds`]'s `Vec`
3951 /// and WITHOUT walking every slot to build
3952 /// [`Self::missing_kind_count`]'s scalar. Short-circuits at the
3953 /// second missing kind — strictly cheaper than either widened
3954 /// primitive on every arm with `≥ 2` missing kinds. Byte-for-byte
3955 /// peer of [`crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`]
3956 /// under the (populated, missing) complement axis one struct-
3957 /// layer up.
3958 ///
3959 /// # Peer to [`crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`]
3960 ///
3961 /// Slice-level peer of the tagged-union parent-level cardinality
3962 /// many-arm predicate one struct-layer up: where
3963 /// [`crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`]
3964 /// answers "are AT LEAST TWO slots on the tagged-union parent
3965 /// empty?", `has_multiple_missing_kinds` answers "do AT LEAST TWO
3966 /// kinds appear in NO condition of the slice?". Both compose
3967 /// against a two-step-short-circuit closed-set walk under a
3968 /// negated presence predicate (`!has(kind)` / `!has_kind(kind)`)
3969 /// at two adjacent typescape sites — the two primitives close the
3970 /// at-least-two arm on the closed-set-complement axis at both
3971 /// struct layers under the SAME shape.
3972 ///
3973 /// # Sibling to the Boolean missing-cardinality trichotomy
3974 ///
3975 /// Third and final arm of the `{0, 1, ≥2}` cardinality trichotomy
3976 /// on the missing axis at the slice level, closing the natural
3977 /// partition alongside [`Self::is_kind_saturated`] (zero-arm) and
3978 /// [`Self::has_unique_missing_kind`] (one-arm). Every slice
3979 /// satisfies EXACTLY ONE of the three Boolean projections — the
3980 /// three primitives partition `0..=ConditionKind::ALL.len()` at
3981 /// 0, 1, and ≥ 2 respectively. The composition law
3982 /// `has_multiple_missing_kinds() == (missing_kind_count() >= 2)`
3983 /// binds the Boolean projection to the scalar primitive at the
3984 /// trait's default body — swept substrate-wide by
3985 /// [`assert_slice_refinement_composition_laws`] as its
3986 /// cardinality-many-arm arm.
3987 ///
3988 /// # Semantics
3989 ///
3990 /// An empty slice returns `true` on any `N ≥ 2` closed set (every
3991 /// kind is missing — the fully-missing endpoint, `N ≥ 2` missing).
3992 /// A slice carrying `K` distinct kinds for `1 ≤ K ≤ N-2` on
3993 /// `N ≥ 3` closed sets returns `true` (`N - K ≥ 2` kinds missing).
3994 /// A slice at the near-saturation arm (carrying every kind except
3995 /// exactly one) returns `false` — the SOLE-missing arrangement
3996 /// where `has_multiple_missing_kinds` returns `false` (exactly
3997 /// one missing, not ≥ 2). A saturated slice returns `false`
3998 /// (zero missing).
3999 ///
4000 /// # Compounding future consumers
4001 ///
4002 /// - An operator-facing "≥ 2 dependencies still unfulfilled" fast-
4003 /// path discriminator on the many-missing arm reads
4004 /// `boundary.postconditions.has_multiple_missing_kinds()` at ONE
4005 /// call site — one two-step short-circuit walk, no allocation,
4006 /// no scalar comparison against `>= 2`, byte-for-byte peer of
4007 /// the tagged-union `has-multiple-missing-kinds` classifier one
4008 /// struct-layer up under the SAME two-step short-circuit shape.
4009 /// - A `has-multiple-missing-kinds` require-tag classifier arm
4010 /// reaches this primitive with no allocation, byte-for-byte
4011 /// peer of the tagged-union `has-multiple-missing-kinds`
4012 /// classifier one struct-layer up.
4013 /// - A future coverage-gap diagnostic that says "≥ 2 remaining
4014 /// ConditionKinds not covered by this Boundary" reads
4015 /// `has_multiple_missing_kinds()` at ONE call site without
4016 /// allocating [`Self::missing_kinds`]'s `Vec`.
4017 ///
4018 /// # Theory grounding
4019 ///
4020 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4021 /// The cardinality-many-arm projection on the missing axis
4022 /// lives at ONE substrate site as a typed two-step-short-
4023 /// circuit walk over [`ConditionKind::ALL`] under negated
4024 /// [`Self::has_kind`] — byte-for-byte peer of
4025 /// `missing_kind_count()` composed against `>= 2`, but with a
4026 /// second-missing-slot short-circuit that the scalar counter
4027 /// primitive does not offer.
4028 /// - THEORY.md §VI.1 — generation over composition. A new
4029 /// [`ConditionKind`] variant added to `ALL` reaches this
4030 /// primitive mechanically through the short-circuit walk — a
4031 /// slice previously at the near-saturation arm (returned
4032 /// `false` here) that omits the new variant now has TWO missing
4033 /// kinds and flips to `true`; a slice previously at the
4034 /// saturated arm on an `N == 2` closed set that omits the new
4035 /// variant flips from `false` to `true` (`1 ≥ 2` false → `1`
4036 /// missing on `N == 3`, but this workspace has `N == 8`, so
4037 /// the flip surfaces well before the endpoint).
4038 fn has_multiple_missing_kinds(&self) -> bool {
4039 let mut it = self.iter_missing_kinds();
4040 it.next().is_some() && it.next().is_some()
4041 }
4042
4043 /// Boolean cardinality "≤ 1" negation peer of
4044 /// [`Self::has_multiple_missing_kinds`] on the closed-set-complement
4045 /// axis — `true` iff AT MOST ONE [`ConditionKind::ALL`] variant
4046 /// appears zero times in this slice (equivalently,
4047 /// [`Self::missing_kind_count`] `<= 1` and
4048 /// [`Self::missing_kinds`]`.len() <= 1`). Names the arm where the
4049 /// slice is SATURATED-OR-NEAR-SATURATED (zero or exactly one kind
4050 /// missing).
4051 ///
4052 /// Default body: `!self.has_multiple_missing_kinds()` — a
4053 /// definitional Boolean negation of the many-arm primitive. Short-
4054 /// circuits transitively through
4055 /// [`Self::has_multiple_missing_kinds`]'s two-step short-circuit
4056 /// closed-set walk: returns `true` as soon as the many-arm walk
4057 /// stops with fewer than two missing hits, WITHOUT materializing
4058 /// [`Self::missing_kinds`]'s `Vec` and WITHOUT walking every slot to
4059 /// build [`Self::missing_kind_count`]'s scalar. Byte-for-byte peer
4060 /// of [`crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`]
4061 /// under the (populated, missing) complement axis one struct-layer
4062 /// up, both composed as the same definitional negation of their
4063 /// respective many-arm primitives.
4064 ///
4065 /// # Peer to [`crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`]
4066 ///
4067 /// Slice-level peer of the tagged-union parent-level cardinality
4068 /// "≤ 1" predicate one struct-layer up: where
4069 /// [`crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`]
4070 /// answers "does the tagged-union parent have AT MOST ONE empty
4071 /// slot?", `has_at_most_one_missing_kind` answers "do AT MOST ONE
4072 /// kind appear in NO condition of the slice?". Both compose as the
4073 /// definitional Boolean negation of their many-arm primitive
4074 /// (`!has_multiple_missing_kinds()`) at two adjacent typescape
4075 /// sites — the two primitives close the "≤ 1" arm on the closed-
4076 /// set-complement axis at both struct layers under the SAME shape.
4077 ///
4078 /// # Sibling to the Boolean missing-cardinality pentachotomy
4079 ///
4080 /// Fourth arm of the `{0, 1, ≥1, ≤1, ≥2}` Boolean-cardinality
4081 /// pentachotomy on the missing axis at the slice level, closing
4082 /// the Boolean-negation grid alongside
4083 /// [`Self::is_kind_saturated`] (=0 zero-arm),
4084 /// [`Self::has_unique_missing_kind`] (=1 mid-endpoint),
4085 /// [`Self::has_any_missing_kind`] (≥1 halfspace), and
4086 /// [`Self::has_multiple_missing_kinds`] (≥2 many-arm). The
4087 /// {≤1, ≥2} pair sit on the Boolean-negation axis:
4088 /// `has_at_most_one_missing_kind == !has_multiple_missing_kinds` on
4089 /// every arm. The {0, 1} union arm sits on the trichotomy-union
4090 /// axis: `has_at_most_one_missing_kind == is_kind_saturated ||
4091 /// has_unique_missing_kind` on every arm. Both composition laws
4092 /// bind the "≤ 1" Boolean projection to the sibling primitives at
4093 /// the trait's default body — swept substrate-wide by
4094 /// [`assert_slice_refinement_composition_laws`] as its "≤ 1" arm.
4095 ///
4096 /// # Semantics
4097 ///
4098 /// An empty slice returns `false` on any `N ≥ 2` closed set
4099 /// (every kind is missing — `N ≥ 2` missing, not `≤ 1`).
4100 /// A slice carrying `K` distinct kinds for `1 ≤ K ≤ N-2` on `N ≥ 3`
4101 /// closed sets returns `false` (`N - K ≥ 2` kinds missing).
4102 /// A slice at the near-saturation arm (carrying every kind except
4103 /// exactly one) returns `true` (exactly 1 missing, `≤ 1`). A
4104 /// saturated slice returns `true` (0 missing, `≤ 1`) — the union
4105 /// of the two "≤ 1" arms (`=0` and `=1`) is exactly the
4106 /// arrangement space where the primitive returns `true`.
4107 ///
4108 /// # Compounding future consumers
4109 ///
4110 /// - An operator-facing "at most one dependency still unfulfilled"
4111 /// fast-path discriminator on the near-saturated / saturated
4112 /// arms reads `boundary.postconditions.has_at_most_one_missing_kind()`
4113 /// at ONE call site — one bit-flip on the many-arm's two-step
4114 /// short-circuit walk, no allocation, no scalar comparison
4115 /// against `<= 1`, byte-for-byte peer of the tagged-union
4116 /// `has-at-most-one-missing-kind` classifier one struct-layer up
4117 /// under the SAME `!has_multiple_missing_kinds` definitional
4118 /// negation shape.
4119 /// - A `has-at-most-one-missing-kind` require-tag classifier arm
4120 /// reaches this primitive with no allocation, closing the
4121 /// {0, 1, ≥ 2, ≤ 1} cardinality-Boolean grid on the missing axis
4122 /// at the slice level alongside its sibling
4123 /// `has-multiple-missing-kinds` under the Boolean negation axis.
4124 /// - A future coverage-gap diagnostic that says "at most one
4125 /// remaining ConditionKind not covered by this Boundary" reads
4126 /// `has_at_most_one_missing_kind()` at ONE call site without
4127 /// allocating [`Self::missing_kinds`]'s `Vec`.
4128 ///
4129 /// # Theory grounding
4130 ///
4131 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4132 /// The cardinality "≤ 1" projection on the missing axis lives
4133 /// at ONE substrate site as the definitional Boolean negation
4134 /// of [`Self::has_multiple_missing_kinds`]; the three composition
4135 /// forms (`!has_multiple_missing_kinds()`, `missing_kind_count() <= 1`,
4136 /// and `is_kind_saturated() || has_unique_missing_kind()`)
4137 /// compose through the SAME two-step-short-circuit walk shape
4138 /// one negation up, byte-for-byte identical on every arm.
4139 /// - THEORY.md §VI.1 — generation over composition. A new
4140 /// [`ConditionKind`] variant added to `ALL` reaches this
4141 /// primitive mechanically through the delegated
4142 /// [`Self::has_multiple_missing_kinds`] — a slice previously at
4143 /// the near-saturation arm (returned `true` here) that omits the
4144 /// new variant now has TWO missing kinds and flips to `false`.
4145 fn has_at_most_one_missing_kind(&self) -> bool {
4146 !self.has_multiple_missing_kinds()
4147 }
4148
4149 /// Boolean per-kind complement of [`Self::has_kind`] — `true` iff
4150 /// NO [`Condition`] in this slice carries the given
4151 /// [`ConditionKind`] (equivalently, the kind is a member of
4152 /// [`Self::missing_kinds`]).
4153 ///
4154 /// Default body: `!self.has_kind(kind)` — a definitional negation
4155 /// of the presence-probe primitive. Short-circuits transitively
4156 /// through [`Self::has_kind`]'s composition down to
4157 /// [`Self::iter_kind`]: `!self.find_kind(kind).is_some()` returns
4158 /// as soon as any match is found (yielding `false`) without
4159 /// walking the rest of the slice, WITHOUT materializing
4160 /// [`Self::missing_kinds`]'s `Vec` per-kind for a per-kind
4161 /// question, and WITHOUT allocating the closed-set-complement scan.
4162 ///
4163 /// # Peer to [`crate::tagged_union::TaggedUnion::lacks`]
4164 ///
4165 /// Slice-level peer of the tagged-union parent-level closed-set-
4166 /// complement predicate one struct-layer up: where
4167 /// [`crate::tagged_union::TaggedUnion::lacks`] answers "is THIS
4168 /// kind's slot on the tagged-union parent empty?", `lacks_kind`
4169 /// answers "does THIS kind appear in NO condition of the slice?".
4170 /// Both compose against their per-kind presence primitive under a
4171 /// definitional negation (`!has(kind)` / `!has_kind(kind)`) at two
4172 /// adjacent typescape sites — the two primitives close the
4173 /// closed-set-complement invariant on the per-kind axis at both
4174 /// struct layers under the SAME shape.
4175 ///
4176 /// # Sibling to [`Self::has_kind`]
4177 ///
4178 /// Boolean per-kind complement peer of the point-probe primitive
4179 /// on the closed-set-complement axis — where `has_kind` returns
4180 /// `true` iff the addressed kind appears at least once,
4181 /// `lacks_kind` returns its negation: `true` iff the addressed kind
4182 /// appears zero times. Together the two Booleans partition the
4183 /// (slice, kind) matrix at the slice-level presence-probe axis:
4184 /// exactly one of `has_kind(k)` and `lacks_kind(k)` is `true` for
4185 /// every `k ∈ ConditionKind::ALL`. The definitional complement law
4186 /// `lacks_kind(k) == !has_kind(k)` is pinned as a first-class typed
4187 /// invariant by the trait's own default body and swept substrate-
4188 /// wide by [`assert_slice_refinement_composition_laws`] as its
4189 /// per-kind-complement arm.
4190 ///
4191 /// # Sibling to [`Self::missing_kinds`] / [`Self::missing_kind_count`]
4192 ///
4193 /// Per-kind Boolean projection of the closed-set-complement
4194 /// widened + scalar primitives — where `missing_kinds` returns the
4195 /// FULL missing-set (a `Vec<ConditionKind>` of every absent kind)
4196 /// and `missing_kind_count` returns its cardinality (a `usize` in
4197 /// `0..=ConditionKind::ALL.len()`), `lacks_kind` collapses the
4198 /// missing-set to its per-kind membership Boolean for ONE
4199 /// addressed kind. The composition law
4200 /// `lacks_kind(k) == missing_kinds().contains(&k)` binds this
4201 /// Boolean projection to the widened closed-set-complement
4202 /// primitive at the trait's default body — strictly cheaper than
4203 /// the widened primitive on every per-kind question because the
4204 /// negation short-circuits at the first match on the has-side
4205 /// walk rather than allocating the closed-set-complement scan.
4206 ///
4207 /// # Semantics
4208 ///
4209 /// An empty slice returns `true` for every [`ConditionKind`] (no
4210 /// kind appears, so every kind is lacked). A slice carrying kind
4211 /// `k` at any position returns `false` for `lacks_kind(k)` and
4212 /// `true` for `lacks_kind(k')` for every `k' ≠ k` (single-kind
4213 /// coverage). A saturated slice (every kind appears at least once)
4214 /// returns `false` on every arm — the SOLE arrangement where the
4215 /// primitive returns `false` for every kind.
4216 ///
4217 /// # Compounding future consumers
4218 ///
4219 /// - A `lacks-<kind>` require-tag classifier arm reaches this
4220 /// primitive with no allocation, byte-for-byte peer of the
4221 /// tagged-union `lacks-<kind>` classifier one struct-layer up
4222 /// under the SAME `!has(kind)` definitional negation shape.
4223 /// - A dependency-satisfaction coherence check that enforces "no
4224 /// process boundary lacks a `ClosedLoopAuth` postcondition" reads
4225 /// `boundary.postconditions.lacks_kind(ConditionKind::ClosedLoopAuth)`
4226 /// at ONE call site rather than negating
4227 /// `boundary.postconditions.has_kind(ConditionKind::ClosedLoopAuth)`
4228 /// at the callsite or materializing the closed-set complement
4229 /// with `missing_kinds().contains(&k)`.
4230 /// - A "still missing: <kind>" diagnostic that reports the FIRST
4231 /// unmet postcondition kind reads `slice.lacks_kind(k)` inside a
4232 /// `ConditionKind::ALL` fold at ONE substrate primitive per test
4233 /// rather than restating the negation body at every callsite.
4234 ///
4235 /// # Theory grounding
4236 ///
4237 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4238 /// The per-kind closed-set-complement projection lives at ONE
4239 /// substrate site as a definitional negation of [`Self::has_kind`].
4240 /// Every downstream consumer whose semantic reading is "the
4241 /// missing set contains THIS kind" reads through this primitive
4242 /// rather than negating `has_kind` at every callsite or paying
4243 /// for the closed-set-complement scan.
4244 /// - THEORY.md §VI.1 — generation over composition. A new
4245 /// [`ConditionKind`] variant added to `ALL` reaches this
4246 /// primitive mechanically through the delegated `has_kind` —
4247 /// every downstream `lacks-<kind>` classifier arm sees the wider
4248 /// kind set without further per-caller edit.
4249 fn lacks_kind(&self, kind: ConditionKind) -> bool {
4250 !self.has_kind(kind)
4251 }
4252
4253 /// Kind-scoped strict refinement of [`Self::has_kind`] — `true` iff
4254 /// the given `kind` appears in the slice AND no OTHER
4255 /// [`ConditionKind`] appears alongside it. The "exactly this one
4256 /// variant is present" predicate at the slice level.
4257 ///
4258 /// Default body: a FUSED short-circuit closed-set walk over
4259 /// [`ConditionKind::ALL`] under [`Self::has_kind`] that returns
4260 /// `false` at the EARLIEST populated slot whose kind is NOT
4261 /// `kind`, and returns `true` iff the sweep completes with `kind`
4262 /// seen as the sole populated slot. Byte-for-byte cheaper than
4263 /// either widened composition
4264 /// `self.distinct_kinds() == vec![kind]` (which allocates the
4265 /// distinct-kind Vec before the equality test) or
4266 /// `self.has_kind(kind) && self.distinct_kind_count() == 1` (which
4267 /// walks the closed-set twice) on every arm where the slice
4268 /// carries a populated kind that isn't `kind`.
4269 ///
4270 /// # Peer to [`crate::tagged_union::TaggedUnion::has_only`]
4271 ///
4272 /// Slice-level peer of the tagged-union parent-level kind-scoped
4273 /// strict-refinement predicate one struct-layer up: where
4274 /// [`crate::tagged_union::TaggedUnion::has_only`] answers "is THIS
4275 /// kind's slot on the tagged-union parent the sole populated
4276 /// slot?", `has_only_kind` answers "is THIS kind the sole distinct
4277 /// kind appearing in the slice?". Both primitives compose the SAME
4278 /// fused short-circuit closed-set walk under a per-kind
4279 /// [`Self::has_kind`] / `TaggedUnion::has` predicate at two
4280 /// adjacent typescape sites — the two primitives close the
4281 /// kind-scoped strict-refinement invariant on the well-formed
4282 /// (1-of-N populated) arm at both struct layers under the SAME
4283 /// shape.
4284 ///
4285 /// # Sibling to [`Self::has_kind`]
4286 ///
4287 /// Kind-scoped strict-refinement peer of the point-probe primitive
4288 /// on the closed-set-inversion axis — where `has_kind(k)` returns
4289 /// `true` iff `k` appears at least once (multiplicity ignored),
4290 /// `has_only_kind(k)` refines that to the strictly stricter
4291 /// predicate "k appears AND no other kind appears". The
4292 /// implication chain `has_only_kind(k) ⟹ has_kind(k)` is a
4293 /// definitional consequence of the fused walk's `saw_kind = true`
4294 /// arm; the reverse is FALSE on any partially-populated slice
4295 /// where a second kind lives alongside `k`. The composition law
4296 /// `has_only_kind(k) == (distinct_kinds() == vec![k])` binds this
4297 /// primitive to the widened closed-set-inversion primitive at the
4298 /// trait's default body — swept substrate-wide by
4299 /// [`assert_slice_refinement_composition_laws`] as its kind-scoped
4300 /// strict-refinement arm.
4301 ///
4302 /// # Truth table on the slice-level closed-set-inversion contract
4303 ///
4304 /// For a slice with `ConditionKind::ALL` of cardinality `N ≥ 2`
4305 /// and a fixed argument `kind`:
4306 ///
4307 /// - Empty slice (0 conditions, distinct-kind set empty): `false`
4308 /// on any `N ≥ 2` — no kind appears, so `kind` isn't the sole
4309 /// populated kind.
4310 /// - Single-populated slice with populated kind `p` (1 condition,
4311 /// distinct-kind set `{p}`): `has_only_kind(kind) == (kind == p)`.
4312 /// - Duplicate-populated slice with kind `p` at every position
4313 /// (multiplicity > 1, distinct-kind set `{p}`): still
4314 /// `has_only_kind(kind) == (kind == p)` — MULTIPLICITY IS
4315 /// IGNORED on the populated side (byte-for-byte with `has_kind`'s
4316 /// multiplicity behavior).
4317 /// - Two-kinds slice with kinds `{p, q}` where `p != q` (distinct-
4318 /// kind set `{p, q}`): `false` for every kind — the strict
4319 /// refinement fails at the earliest walk step that hits the
4320 /// second kind.
4321 /// - Saturated slice (every kind appears): `false` for every kind
4322 /// on any `N ≥ 2` — N distinct kinds populate, so no single
4323 /// kind is "only".
4324 ///
4325 /// # Kind-domain exhaustivity
4326 ///
4327 /// A slice satisfies `has_only_kind(k)` for AT MOST one `k`, since
4328 /// two distinct kinds cannot both be the sole distinct populated
4329 /// kind. On the well-formed arm the count is exactly 1 (the
4330 /// addressed populated kind); on every other arm the count is 0.
4331 /// This kind-domain exhaustivity law binds the argument-scoped
4332 /// projection to the parent-scoped cardinality primitive
4333 /// `distinct_kind_count() == 1` at the composition-law surface.
4334 ///
4335 /// # Compounding future consumers
4336 ///
4337 /// - A `has-only-<kind>` require-tag classifier arm reaches this
4338 /// primitive with no allocation, byte-for-byte peer of the
4339 /// tagged-union `has-only-<kind>` classifier one struct-layer up
4340 /// under the SAME fused short-circuit walk shape.
4341 /// - A coherence check verifying "every ephemeral spec whose
4342 /// postconditions carry ONLY `ClosedLoopAuth` (no
4343 /// `JobAttested`, no `Cel`, ...) is a well-formed closed-loop
4344 /// probe" reads
4345 /// `spec.postconditions.has_only_kind(ConditionKind::ClosedLoopAuth)`
4346 /// at ONE call site — strictly cheaper than reaching for the
4347 /// widened composition on every well-formed-diagonal question.
4348 /// - An operator-facing "unambiguously kind=<k>" diagnostic on
4349 /// the slice-level probe reads `slice.has_only_kind(k)` after
4350 /// `first_distinct_kind` names the sole populated kind — one
4351 /// fused walk, no allocation, no `Option<ConditionKind>`
4352 /// construction.
4353 ///
4354 /// # Theory grounding
4355 ///
4356 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4357 /// The kind-scoped strict-refinement projection lives at ONE
4358 /// substrate site as a fused short-circuit walk over
4359 /// [`ConditionKind::ALL`] under [`Self::has_kind`] with early
4360 /// exit on the first populated slot whose kind is not `kind` —
4361 /// byte-for-byte cheaper than the widened composition
4362 /// `distinct_kinds() == vec![kind]`, semantically identical on
4363 /// every arm.
4364 /// - THEORY.md §VI.1 — generation over composition. A new
4365 /// [`ConditionKind`] variant added to `ALL` reaches this
4366 /// primitive mechanically through the fused walk — every
4367 /// downstream `has-only-<kind>` classifier arm sees the wider
4368 /// kind set without further per-caller edit.
4369 fn has_only_kind(&self, kind: ConditionKind) -> bool {
4370 let mut saw_kind = false;
4371 for k in ConditionKind::ALL {
4372 if !self.has_kind(k) {
4373 continue;
4374 }
4375 if k == kind {
4376 saw_kind = true;
4377 } else {
4378 return false;
4379 }
4380 }
4381 saw_kind
4382 }
4383
4384 /// Kind-scoped strict refinement of [`Self::lacks_kind`] — `true` iff
4385 /// the given `kind` does NOT appear in the slice AND every OTHER
4386 /// [`ConditionKind`] DOES appear at least once. The "exactly this
4387 /// one variant is the sole hole" predicate at the slice level.
4388 ///
4389 /// Default body: a FUSED short-circuit closed-set walk over
4390 /// [`ConditionKind::ALL`] under [`Self::has_kind`] that skips every
4391 /// populated slot, returns `false` at the EARLIEST missing slot
4392 /// whose kind is NOT `kind`, and returns `true` iff the sweep
4393 /// completes with `kind` seen as the sole missing slot. Byte-for-
4394 /// byte cheaper than either widened composition
4395 /// `self.missing_kinds() == vec![kind]` (which allocates the
4396 /// missing-kind Vec before the equality test) or
4397 /// `self.lacks_kind(kind) && self.missing_kind_count() == 1` (which
4398 /// walks the closed-set-complement scan twice) on every arm where
4399 /// the slice carries a missing kind that isn't `kind`.
4400 ///
4401 /// # Peer to [`crate::tagged_union::TaggedUnion::lacks_only`]
4402 ///
4403 /// Slice-level peer of the tagged-union parent-level kind-scoped
4404 /// strict-refinement predicate on the missing axis one struct-layer
4405 /// up: where
4406 /// [`crate::tagged_union::TaggedUnion::lacks_only`] answers "is THIS
4407 /// kind's slot on the tagged-union parent the sole empty slot?",
4408 /// `lacks_only_kind` answers "is THIS kind the sole missing kind
4409 /// from the slice's distinct set?". Both primitives compose the
4410 /// SAME fused short-circuit closed-set walk under a per-kind
4411 /// [`Self::has_kind`] / `TaggedUnion::has` predicate at two adjacent
4412 /// typescape sites — the two primitives close the kind-scoped
4413 /// strict-refinement invariant on the near-saturation-diagonal
4414 /// (`N-1`-of-N populated with the sole hole at `kind`) arm at both
4415 /// struct layers under the SAME shape.
4416 ///
4417 /// # Sibling to [`Self::has_only_kind`]
4418 ///
4419 /// Closed-set-complement mirror of the well-formed-diagonal
4420 /// strict-refinement primitive on the populated axis — where
4421 /// `has_only_kind(k)` returns `true` iff `k` is the sole distinct
4422 /// populated kind, `lacks_only_kind(k)` returns `true` iff `k` is
4423 /// the sole missing kind. Together the two peers CLOSE the
4424 /// (populated, missing) × (subset, equal) 2x2 kind-scoped
4425 /// strict-refinement grid at the slice level alongside `has_kind`
4426 /// (populated subset) and `lacks_kind` (missing subset).
4427 ///
4428 /// # Truth table on the slice-level closed-set-complement contract
4429 ///
4430 /// For a slice with `ConditionKind::ALL` of cardinality `N ≥ 2`
4431 /// and a fixed argument `kind`:
4432 ///
4433 /// - Empty slice (0 conditions, distinct-kind set empty,
4434 /// missing-kind set == ALL): `false` on any `N ≥ 2` — every kind
4435 /// is missing, so `kind` is NOT the sole missing kind.
4436 /// - Single-populated slice with populated kind `p` (1 condition,
4437 /// missing-kind set == `ALL \ {p}`): `false` on any `N ≥ 3`
4438 /// (`N - 1 ≥ 2` missing kinds, no sole missing kind); on `N == 2`
4439 /// the missing set is `{q}` where `q ≠ p`, so
4440 /// `lacks_only_kind(kind) == (kind == q)`.
4441 /// - Near-saturation slice with populated kinds `ALL \ {q}` (each
4442 /// kind except `q` populated, missing set `{q}`): the SOLE `true`
4443 /// arm — `lacks_only_kind(kind) == (kind == q)`.
4444 /// - Saturated slice (every kind appears): `false` on every kind —
4445 /// no kind is missing, so no kind is the sole missing kind.
4446 /// - Multiplicity is ignored on the populated side: a slice
4447 /// carrying `k` at every position still has an empty missing set,
4448 /// or a missing set `{k'}` where `k' ≠ k`, byte-for-byte with
4449 /// the single-populated arrangement.
4450 ///
4451 /// # Kind-domain exhaustivity
4452 ///
4453 /// A slice satisfies `lacks_only_kind(k)` for AT MOST one `k`,
4454 /// since two distinct kinds cannot both be the sole missing kind.
4455 /// On the near-saturation arm the count is exactly 1 (the sole
4456 /// missing kind); on every other arm the count is 0. This
4457 /// kind-domain exhaustivity law binds the argument-scoped
4458 /// projection to the parent-scoped cardinality primitive
4459 /// `missing_kind_count() == 1` at the composition-law surface.
4460 ///
4461 /// # Compounding future consumers
4462 ///
4463 /// - A `lacks-only-<kind>` require-tag classifier arm reaches this
4464 /// primitive with no allocation, byte-for-byte peer of the
4465 /// tagged-union `lacks-only-<kind>` classifier one struct-layer
4466 /// up under the SAME fused short-circuit walk shape.
4467 /// - A "one dependency short: <kind>" diagnostic on the aggregate
4468 /// boundary check reads
4469 /// `slice.lacks_only_kind(k)` at ONE call site — one fused
4470 /// short-circuit walk, no allocation, strictly cheaper than
4471 /// `slice.first_missing_kind() == Some(k) && slice.missing_kind_count() == 1`
4472 /// which walks the closed-set-complement scan twice.
4473 /// - A coherence check that verifies "the near-saturation slice
4474 /// from an `all_but_one_kind_of(k)` factory is unambiguously
4475 /// missing kind `k`" reads `slice.lacks_only_kind(k)` at ONE
4476 /// site — the strongest structural pin on the missing-side
4477 /// well-formed diagonal.
4478 ///
4479 /// # Theory grounding
4480 ///
4481 /// - THEORY.md §II.1 invariant 5 — composition preserves proofs.
4482 /// The kind-scoped strict-refinement projection on the missing
4483 /// axis lives at ONE substrate site as a fused short-circuit
4484 /// walk over [`ConditionKind::ALL`] under [`Self::has_kind`]
4485 /// with early exit on the first missing slot whose kind is not
4486 /// `kind` — byte-for-byte peer of [`Self::has_only_kind`]'s
4487 /// fused walk under complement, semantically identical to
4488 /// `first_missing_kind() == Some(kind) && missing_kind_count() == 1`
4489 /// on every arm.
4490 /// - THEORY.md §VI.1 — generation over composition. A new
4491 /// [`ConditionKind`] variant added to `ALL` reaches this
4492 /// primitive mechanically through the delegated `has_kind` walk
4493 /// — every downstream `lacks-only-<kind>` classifier arm sees
4494 /// the wider kind set without further per-caller edit.
4495 fn lacks_only_kind(&self, kind: ConditionKind) -> bool {
4496 let mut saw_kind = false;
4497 for k in ConditionKind::ALL {
4498 if self.has_kind(k) {
4499 continue;
4500 }
4501 if k == kind {
4502 saw_kind = true;
4503 } else {
4504 return false;
4505 }
4506 }
4507 saw_kind
4508 }
4509}
4510
4511/// Iterator yielded by [`ConditionSliceExt::iter_kind`] — the widened
4512/// primitive on the slice-level presence-probe axis. Wraps a
4513/// [`std::slice::Iter`] over `Condition` values with a
4514/// [`ConditionKind`] discriminator; [`Iterator::next`] short-circuits
4515/// via [`std::iter::Iterator::find`] on the wrapped iterator so the
4516/// filter walk is byte-identical to `self.iter().filter(|c| c.kind ==
4517/// kind).next()` without paying for the anonymous-closure type
4518/// erasure a chained-adapter return position would carry.
4519///
4520/// # Why a named type
4521///
4522/// [`ConditionSliceExt::iter_kind`] returns this concrete type rather
4523/// than `impl Iterator<Item = &Condition>` so downstream consumers
4524/// (a fleet-wide audit dump that stores match streams in a struct
4525/// field, a coherence check that composes the iterator against
4526/// [`std::iter::Chain`] across pre-/post-conditions) name the
4527/// primitive's return without pulling in RPITIT's unnameable
4528/// per-callsite type. [`Boundary::iter_condition_kind`] and
4529/// [`crate::ephemeral::EphemeralSpec::iter_condition_kind`] chain two
4530/// [`KindMatches`] iterators via [`Iterator::chain`] — the resulting
4531/// [`std::iter::Chain<KindMatches<'_>, KindMatches<'_>>`] is itself
4532/// a standard nameable type.
4533pub struct KindMatches<'a> {
4534 inner: std::slice::Iter<'a, Condition>,
4535 kind: ConditionKind,
4536}
4537
4538impl<'a> Iterator for KindMatches<'a> {
4539 type Item = &'a Condition;
4540
4541 fn next(&mut self) -> Option<Self::Item> {
4542 self.inner.by_ref().find(|c| c.kind == self.kind)
4543 }
4544}
4545
4546impl ConditionSliceExt for [Condition] {
4547 fn iter_kind(&self, kind: ConditionKind) -> KindMatches<'_> {
4548 KindMatches {
4549 inner: self.iter(),
4550 kind,
4551 }
4552 }
4553}
4554
4555/// Generic slice-level substrate testkit — pins the FOUR composition
4556/// laws that bind the [`ConditionSliceExt`] refinement algebra
4557/// (`iter_kind` → `find_kind` → `has_kind` → `count_kind`) at ONE
4558/// call site per authored arrangement, sweeping [`ConditionKind::ALL`].
4559///
4560/// The [`ConditionSliceExt`] trait publishes four refinements on the
4561/// slice-level presence-probe axis:
4562///
4563/// | refinement | return type | default body |
4564/// |------------|-------------|-------------------------------------|
4565/// | `iter_kind`| [`KindMatches`] | (widened primitive, required) |
4566/// | `find_kind`| `Option<&Condition>` | `self.iter_kind(k).next()` |
4567/// | `has_kind` | `bool` | `self.find_kind(k).is_some()` |
4568/// | `count_kind`| `usize` | `self.iter_kind(k).count()` |
4569///
4570/// The three coarser refinements are typed projections of the widened
4571/// primitive by construction. The composition laws that bind them
4572/// (and therefore surface any implementor that overrode a default
4573/// with a divergent walk shape — a stored-length cache that drifted,
4574/// a `.rev().find(...)` returning trailing-first, a `.step_by(2)`
4575/// artifact from a copy-paste of `iter_kind`) sweep at ONE typed
4576/// substrate site through this primitive:
4577///
4578/// 1. **`find ↔ iter`**: `find_kind(k) == iter_kind(k).next()` — the
4579/// first-match probe equals the widened stream's first yield.
4580/// 2. **`count ↔ iter`**: `count_kind(k) == iter_kind(k).count()` —
4581/// the cardinality probe equals the widened stream's yield count.
4582/// 3. **`has ↔ find`**: `has_kind(k) == find_kind(k).is_some()` —
4583/// the presence bit equals the first-match probe's `is_some()`.
4584/// 4. **`has ↔ count`**: `has_kind(k) == (count_kind(k) > 0)` — the
4585/// presence bit equals the cardinality's positivity test (the
4586/// dual composition path from `has` back to the widened primitive
4587/// that doesn't go through `find`).
4588///
4589/// Pre-lift each composition law lived at its own hand-authored
4590/// nested-`for` loop test in [`tatara_process::boundary`] tests
4591/// (`condition_slice_find_kind_equals_iter_kind_next`,
4592/// `condition_slice_count_kind_equals_iter_kind_count`,
4593/// `condition_slice_has_kind_equals_find_kind_is_some`,
4594/// `condition_slice_has_and_find_equal_count_greater_than_zero`) —
4595/// four sibling test bodies whose only per-law knobs were the
4596/// projection functions being bridged. Post-lift each authored
4597/// arrangement (empty, single-element, dual-populated, duplicate-
4598/// populated) pins ALL FOUR laws through ONE
4599/// `assert_slice_refinement_composition_laws(slice)` call whose body
4600/// is the substrate primitive's own sweep.
4601///
4602/// The primitive binds `<S: ConditionSliceExt + ?Sized>` so both a
4603/// bare `&[Condition]` and any future implementor of the trait
4604/// (a wrapper type with additional invariants, an alternative slice
4605/// projection over a builder's staging Vec) picks up the four-law
4606/// composition contract through ONE call site. `?Sized` lets the
4607/// caller pass `slice.as_slice()` or `&owned[..]` without an
4608/// intermediate reference dance.
4609///
4610/// # Compounding
4611///
4612/// A FIFTH refinement added to [`ConditionSliceExt`] (a hypothetical
4613/// `nth_kind(k, n) -> Option<&Condition>` for indexed match access,
4614/// a `distinct_kinds()` aggregate that returns which kinds appear at
4615/// least once, a `has_kind_matching(pred)` closure-based predicate
4616/// probe) lands its composition-law pins as ONE new arm inside this
4617/// primitive's sweep body. Every downstream test that already reaches
4618/// this primitive picks up the fifth-refinement pin mechanically —
4619/// no per-arrangement author-time enumeration of the new law across
4620/// the four sibling composition-law sites, no re-authored `for kind
4621/// in ConditionKind::ALL { … }` sweep at every consumer.
4622///
4623/// Symmetrical shape to
4624/// [`crate::tagged_union::assert_find_agrees_with_has`] on the
4625/// tagged-union parent axis: both project a widened-refinement /
4626/// coarser-refinement composition law contract onto ONE typed
4627/// substrate call site, both bind `<T: /* refinement carrier */>`
4628/// generically, both sweep the addressed closed set
4629/// ([`ConditionKind::ALL`] here, `<T::Kind as ClosedSet>::ALL`
4630/// there). The two primitives close the "refinement axis composes"
4631/// invariant at two adjacent typescape sites — one per closed-set-
4632/// addressed slice-level refinement, one per closed-set-addressed
4633/// tagged-union parent-level refinement.
4634///
4635/// Theory anchor: THEORY.md §II.1 invariant 5 — composition preserves
4636/// proofs. The four coarser refinements are typed projections of the
4637/// widened primitive, and this substrate primitive turns each
4638/// projection's composition law from doc-prose into a first-class
4639/// typed theorem provable generically over any
4640/// `S: ConditionSliceExt + ?Sized`. THEORY.md §VI.1 — generation over
4641/// composition; a new [`ConditionKind`] variant added to `ALL` reaches
4642/// every downstream composition-law consumer through the SAME
4643/// closed-set sweep with no per-caller edit.
4644#[track_caller]
4645pub fn assert_slice_refinement_composition_laws<S>(slice: &S)
4646where
4647 S: ConditionSliceExt + ?Sized,
4648{
4649 let distinct = slice.distinct_kinds();
4650 for kind in ConditionKind::ALL {
4651 let find_result = slice.find_kind(kind);
4652 let has_result = slice.has_kind(kind);
4653 let count_result = slice.count_kind(kind);
4654 let iter_next_kind = slice.iter_kind(kind).next().map(|c| c.kind);
4655 let iter_count = slice.iter_kind(kind).count();
4656
4657 // find ↔ iter
4658 assert_eq!(
4659 find_result.map(|c| c.kind),
4660 iter_next_kind,
4661 "find_kind({kind:?}) drifted from iter_kind({kind:?}).next()",
4662 );
4663 // count ↔ iter
4664 assert_eq!(
4665 count_result, iter_count,
4666 "count_kind({kind:?}) drifted from iter_kind({kind:?}).count()",
4667 );
4668 // has ↔ find
4669 assert_eq!(
4670 has_result,
4671 find_result.is_some(),
4672 "has_kind({kind:?}) drifted from find_kind({kind:?}).is_some()",
4673 );
4674 // has ↔ count
4675 assert_eq!(
4676 has_result,
4677 count_result > 0,
4678 "has_kind({kind:?}) drifted from (count_kind({kind:?}) > 0)",
4679 );
4680 // distinct ↔ has (per-kind membership on the closed-set-inversion axis)
4681 assert_eq!(
4682 distinct.contains(&kind),
4683 has_result,
4684 "distinct_kinds().contains({kind:?}) drifted from has_kind({kind:?})",
4685 );
4686 }
4687
4688 // distinct ↔ ALL-filter (canonical subsequence — closed-set-inversion
4689 // walks ConditionKind::ALL in order, filters by has_kind, dedups by
4690 // construction). A regression that (a) returned duplicates (a naive
4691 // `.iter().map(|c| c.kind).collect()` override that skipped dedup),
4692 // (b) drifted the walk order from ConditionKind::ALL to slice-encounter
4693 // order, or (c) returned a superset containing absent kinds surfaces
4694 // HERE at the substrate boundary.
4695 let canonical: Vec<ConditionKind> = ConditionKind::ALL
4696 .into_iter()
4697 .filter(|k| slice.has_kind(*k))
4698 .collect();
4699 assert_eq!(
4700 distinct, canonical,
4701 "distinct_kinds() must yield ConditionKind::ALL-ordered subsequence of kinds where has_kind is true (no duplicates, canonical order)",
4702 );
4703
4704 // iter_distinct_kinds ↔ distinct_kinds — the load-bearing iterator
4705 // peer of the closed-set-inversion widened primitive. `distinct_kinds`'s
4706 // default body IS `self.iter_distinct_kinds().collect()`, so the
4707 // composition law `distinct_kinds() ==
4708 // iter_distinct_kinds().collect::<Vec<_>>()` holds by construction —
4709 // a regression that overrode either surface with a divergent walk
4710 // (short-circuit skipping a kind, drifting the walk order from
4711 // ConditionKind::ALL, forgetting the `has_kind` filter, or divergent
4712 // yield sequences between repeated invocations) surfaces HERE at the
4713 // substrate boundary, not as silent skew between the iter-based fold
4714 // callsite and the Vec-based callsite. Symmetrical to the tagged-union
4715 // parent-level substrate testkit
4716 // `assert_iter_populated_kinds_matches_populated_kinds` under a
4717 // POSITIVE point-probe.
4718 let via_iter_distinct: Vec<ConditionKind> = slice.iter_distinct_kinds().collect();
4719 assert_eq!(
4720 via_iter_distinct, distinct,
4721 "iter_distinct_kinds().collect::<Vec<_>>() drifted from distinct_kinds()",
4722 );
4723 let via_iter_distinct_again: Vec<ConditionKind> = slice.iter_distinct_kinds().collect();
4724 assert_eq!(
4725 via_iter_distinct, via_iter_distinct_again,
4726 "iter_distinct_kinds() must be pure over &self — repeated collect diverged",
4727 );
4728
4729 // distinct_kind_count ↔ distinct_kinds.len() — the scalar
4730 // cardinality projection of the closed-set-inversion widened
4731 // primitive. A regression that overrode `distinct_kind_count` to
4732 // skip a kind, double-count a slot, or drift the walk from
4733 // `ConditionKind::ALL` surfaces HERE at the substrate boundary,
4734 // not as silent drift at every downstream `distinct-count-<n>`
4735 // require-tag classifier or audit-dump callsite.
4736 assert_eq!(
4737 slice.distinct_kind_count(),
4738 distinct.len(),
4739 "distinct_kind_count() drifted from distinct_kinds().len()",
4740 );
4741
4742 // missing ↔ has (per-kind complement on the closed-set-inversion
4743 // axis). Byte-for-byte peer to the `distinct ↔ has` arm above: the
4744 // present-side widened primitive `distinct_kinds` binds to
4745 // `has_kind` via `contains(&k) == has_kind(k)`; the missing-side
4746 // widened primitive `missing_kinds` binds via
4747 // `contains(&k) == !has_kind(k)` — the SAME point-probe primitive
4748 // reached under a negated predicate. A regression that overrode
4749 // `missing_kinds` to omit the negation (returning `distinct_kinds`
4750 // instead), inverted the wrong side, or dropped a variant surfaces
4751 // HERE.
4752 let missing = slice.missing_kinds();
4753 for kind in ConditionKind::ALL {
4754 assert_eq!(
4755 missing.contains(&kind),
4756 !slice.has_kind(kind),
4757 "missing_kinds().contains({kind:?}) drifted from !has_kind({kind:?})",
4758 );
4759 }
4760
4761 // missing ↔ ALL-filter (canonical subsequence — closed-set
4762 // complement walks ConditionKind::ALL in order, filters by
4763 // !has_kind, dedups by construction). Peer to the `distinct ↔
4764 // ALL-filter` arm above; catches ordering + dedup drift on the
4765 // complement side that the per-kind membership arm cannot detect
4766 // on its own.
4767 let canonical_missing: Vec<ConditionKind> = ConditionKind::ALL
4768 .into_iter()
4769 .filter(|k| !slice.has_kind(*k))
4770 .collect();
4771 assert_eq!(
4772 missing, canonical_missing,
4773 "missing_kinds() must yield ConditionKind::ALL-ordered subsequence of kinds where has_kind is false (no duplicates, canonical order)",
4774 );
4775
4776 // iter_missing_kinds ↔ missing_kinds — the load-bearing iterator peer
4777 // of the closed-set-complement widened primitive on the missing side.
4778 // `missing_kinds`'s default body IS `self.iter_missing_kinds().collect()`,
4779 // so the composition law
4780 // `missing_kinds() == iter_missing_kinds().collect::<Vec<_>>()` holds by
4781 // construction. Byte-for-byte peer of the `iter_distinct_kinds ↔
4782 // distinct_kinds` arm above under a NEGATED point-probe: a regression
4783 // that dropped the negation (returning `iter_distinct_kinds`), skipped
4784 // a kind on the complement side, or drifted the walk from
4785 // `ConditionKind::ALL` surfaces HERE at the substrate boundary.
4786 // Symmetrical to the tagged-union parent-level substrate testkit
4787 // `assert_iter_missing_kinds_matches_missing_kinds` under a NEGATED
4788 // point-probe.
4789 let via_iter_missing: Vec<ConditionKind> = slice.iter_missing_kinds().collect();
4790 assert_eq!(
4791 via_iter_missing, missing,
4792 "iter_missing_kinds().collect::<Vec<_>>() drifted from missing_kinds()",
4793 );
4794 let via_iter_missing_again: Vec<ConditionKind> = slice.iter_missing_kinds().collect();
4795 assert_eq!(
4796 via_iter_missing, via_iter_missing_again,
4797 "iter_missing_kinds() must be pure over &self — repeated collect diverged",
4798 );
4799
4800 // (distinct, missing) partition ConditionKind::ALL — three peer
4801 // laws that bind the closed-set-inversion widened primitive
4802 // `distinct_kinds` to its complement peer `missing_kinds`:
4803 //
4804 // 1. Disjoint: every kind appears in AT MOST one of the two sets.
4805 // 2. Covering: every kind appears in AT LEAST one of the two sets
4806 // (equivalent to the union covering ConditionKind::ALL).
4807 // 3. Cardinality partition: `distinct.len() + missing.len() ==
4808 // ConditionKind::ALL.len()` — the scalar consequence of (1) +
4809 // (2) that a caller reaching for the cardinality peer would
4810 // otherwise pay for the two allocations at every callsite.
4811 for kind in ConditionKind::ALL {
4812 assert!(
4813 !(distinct.contains(&kind) && missing.contains(&kind)),
4814 "(distinct_kinds, missing_kinds) partition invariant violated — both contain {kind:?}",
4815 );
4816 assert!(
4817 distinct.contains(&kind) || missing.contains(&kind),
4818 "(distinct_kinds, missing_kinds) partition invariant violated — neither contains {kind:?}",
4819 );
4820 }
4821 assert_eq!(
4822 distinct.len() + missing.len(),
4823 ConditionKind::ALL.len(),
4824 "(distinct_kinds, missing_kinds) cardinality partition drift — sum {} ≠ ConditionKind::ALL.len() {}",
4825 distinct.len() + missing.len(),
4826 ConditionKind::ALL.len(),
4827 );
4828
4829 // missing_kind_count ↔ missing_kinds.len() — the scalar cardinality
4830 // projection of the closed-set-complement widened primitive. A
4831 // regression that overrode `missing_kind_count` to drop the
4832 // negation (returning `distinct_kind_count`), skip a kind, double-
4833 // count a slot, or drift the walk from `ConditionKind::ALL`
4834 // surfaces HERE at the substrate boundary, not as silent drift at
4835 // every downstream `condition-kinds-missing-<n>` require-tag
4836 // classifier or gap-analysis-dashboard callsite.
4837 assert_eq!(
4838 slice.missing_kind_count(),
4839 missing.len(),
4840 "missing_kind_count() drifted from missing_kinds().len()",
4841 );
4842
4843 // (distinct_kind_count, missing_kind_count) partition
4844 // ConditionKind::ALL's cardinality — the scalar consequence of the
4845 // widened-primitive partition law `distinct ∪ missing == ALL,
4846 // disjoint` above. A regression that (a) drifted the scalar
4847 // cardinality peer from the widened primitive on either side or
4848 // (b) drifted the partition invariant surfaces HERE at ONE typed
4849 // arm rather than as silent drift at every scalar-cardinality
4850 // callsite that reaches for the sum.
4851 assert_eq!(
4852 slice.distinct_kind_count() + slice.missing_kind_count(),
4853 ConditionKind::ALL.len(),
4854 "(distinct_kind_count, missing_kind_count) scalar partition drift — sum {} ≠ ConditionKind::ALL.len() {}",
4855 slice.distinct_kind_count() + slice.missing_kind_count(),
4856 ConditionKind::ALL.len(),
4857 );
4858
4859 // first_distinct_kind ↔ distinct_kinds.first().copied() — the
4860 // earliest-element scalar projection of the closed-set-inversion
4861 // widened primitive. Peer of `distinct_kind_count ↔ distinct_kinds
4862 // .len()` on the scalar-projection axis: where the cardinality peer
4863 // collapses the SET to its length, the earliest-element peer
4864 // collapses the SET to its first element. A regression that
4865 // overrode `first_distinct_kind` to skip a kind, drift the walk
4866 // from ConditionKind::ALL, forget the short-circuit (returning
4867 // the LAST hit), or diverge from the widened primitive's canonical
4868 // ordering surfaces HERE at the substrate boundary, not as silent
4869 // drift at every downstream `first-distinct-<kind>` require-tag
4870 // classifier callsite.
4871 assert_eq!(
4872 slice.first_distinct_kind(),
4873 distinct.first().copied(),
4874 "first_distinct_kind() drifted from distinct_kinds().first().copied()",
4875 );
4876
4877 // first_missing_kind ↔ missing_kinds.first().copied() — the
4878 // earliest-element scalar projection of the closed-set-complement
4879 // widened primitive. Byte-for-byte peer of `first_distinct_kind`
4880 // one axis over under a negated predicate: where
4881 // `first_distinct_kind` scalar-projects the closed-set-INVERSION
4882 // widened primitive onto its earliest element, this arm scalar-
4883 // projects the closed-set-COMPLEMENT widened primitive onto its
4884 // earliest element. A regression that overrode `first_missing_kind`
4885 // to drop the negation (returning `first_distinct_kind`), skip a
4886 // kind, drift the walk from ConditionKind::ALL, or forget the
4887 // short-circuit (returning the LAST missing hit) surfaces HERE at
4888 // the substrate boundary, not as silent drift at every downstream
4889 // `first-missing-<kind>` require-tag classifier callsite.
4890 assert_eq!(
4891 slice.first_missing_kind(),
4892 missing.first().copied(),
4893 "first_missing_kind() drifted from missing_kinds().first().copied()",
4894 );
4895
4896 // last_distinct_kind ↔ distinct_kinds.last().copied() — the
4897 // latest-element scalar projection of the closed-set-inversion
4898 // widened primitive. Time-reversed peer of `first_distinct_kind
4899 // ↔ distinct_kinds.first().copied()` under the SAME `has_kind`
4900 // predicate but with the closed-set walk reversed: where the
4901 // earliest-element peer picks the smallest ALL index that hits,
4902 // this arm picks the LARGEST. A regression that overrode
4903 // `last_distinct_kind` to skip a kind, drift the walk direction
4904 // (returning `first_distinct_kind`), forget the short-circuit
4905 // (returning `distinct_kinds().rev().next()` allocation), or
4906 // diverge from the widened primitive's canonical ordering
4907 // surfaces HERE at the substrate boundary, not as silent drift
4908 // at every downstream `last-distinct-<kind>` require-tag
4909 // classifier callsite.
4910 assert_eq!(
4911 slice.last_distinct_kind(),
4912 distinct.last().copied(),
4913 "last_distinct_kind() drifted from distinct_kinds().last().copied()",
4914 );
4915
4916 // last_missing_kind ↔ missing_kinds.last().copied() — the
4917 // latest-element scalar projection of the closed-set-complement
4918 // widened primitive. Byte-for-byte peer of `last_distinct_kind`
4919 // one axis over under a NEGATED predicate: where
4920 // `last_distinct_kind` scalar-projects the closed-set-INVERSION
4921 // widened primitive onto its LATEST element, this arm scalar-
4922 // projects the closed-set-COMPLEMENT widened primitive onto its
4923 // LATEST element. A regression that overrode `last_missing_kind`
4924 // to drop the negation (returning `last_distinct_kind`), reverse
4925 // the walk direction (returning `first_missing_kind`), skip a
4926 // kind, or forget the short-circuit surfaces HERE at the
4927 // substrate boundary, not as silent drift at every downstream
4928 // `last-missing-<kind>` require-tag classifier callsite.
4929 assert_eq!(
4930 slice.last_missing_kind(),
4931 missing.last().copied(),
4932 "last_missing_kind() drifted from missing_kinds().last().copied()",
4933 );
4934
4935 // is_kind_saturated ↔ (missing_kind_count == 0) — the Boolean
4936 // saturation-endpoint projection of the closed-set-complement
4937 // scalar cardinality. Peer of `first_missing_kind ↔ missing_kinds
4938 // .first().copied()` on the endpoint-projection axis: where the
4939 // earliest-element peer collapses the missing SET to its first
4940 // element, this Boolean peer collapses the missing scalar to its
4941 // zero-arm test. A regression that overrode `is_kind_saturated` to
4942 // drop the negation (returning `slice.is_empty()`), skip a kind,
4943 // or drift the walk from `ConditionKind::ALL` surfaces HERE at
4944 // the substrate boundary, not as silent drift at every downstream
4945 // `is-kind-saturated` require-tag classifier or fleet-wide gap-
4946 // analysis dashboard callsite. Byte-for-byte peer of
4947 // `crate::tagged_union::TaggedUnion::is_saturated` one struct-
4948 // layer up under the same `<CLOSED_SET>::ALL.iter().all(has)`
4949 // short-circuit shape.
4950 assert_eq!(
4951 slice.is_kind_saturated(),
4952 slice.missing_kind_count() == 0,
4953 "is_kind_saturated() drifted from (missing_kind_count() == 0)",
4954 );
4955 assert_eq!(
4956 slice.is_kind_saturated(),
4957 missing.is_empty(),
4958 "is_kind_saturated() drifted from missing_kinds().is_empty()",
4959 );
4960
4961 // has_any_missing_kind ↔ !is_kind_saturated — the Boolean at-
4962 // least-one halfspace projection of the closed-set-complement
4963 // scalar cardinality. Peer of `is_kind_saturated ↔
4964 // (missing_kind_count == 0)` on the Boolean-negation axis: where
4965 // the saturation-endpoint peer tests the zero-arm, this at-least-
4966 // one halfspace peer tests its negation. Together the two Booleans
4967 // partition the missing-cardinality closed set — exactly one is
4968 // `true` for every slice. A regression that overrode
4969 // `has_any_missing_kind` to drop the negation (returning
4970 // `is_kind_saturated`), skip a kind, or drift the walk from
4971 // `ConditionKind::ALL` surfaces HERE at the substrate boundary,
4972 // not as silent drift at every downstream `has-any-missing-kind`
4973 // require-tag classifier or fleet-wide gap-analysis dashboard
4974 // callsite. Byte-for-byte peer of
4975 // `crate::tagged_union::TaggedUnion::has_any_missing_kind` one
4976 // struct-layer up under the SAME `!is_saturated` definitional
4977 // negation shape. Also pins the widened composition laws
4978 // `has_any_missing_kind() == (missing_kind_count() > 0)` and
4979 // `has_any_missing_kind() == !missing_kinds().is_empty()` at every
4980 // slice — binds the at-least-one halfspace Boolean projection to
4981 // the widened + scalar closed-set-complement primitives without
4982 // paying for the Vec allocation.
4983 assert_eq!(
4984 slice.has_any_missing_kind(),
4985 !slice.is_kind_saturated(),
4986 "has_any_missing_kind() drifted from !is_kind_saturated()",
4987 );
4988 assert_eq!(
4989 slice.has_any_missing_kind(),
4990 slice.missing_kind_count() > 0,
4991 "has_any_missing_kind() drifted from (missing_kind_count() > 0)",
4992 );
4993 assert_eq!(
4994 slice.has_any_missing_kind(),
4995 !missing.is_empty(),
4996 "has_any_missing_kind() drifted from !missing_kinds().is_empty()",
4997 );
4998
4999 // has_any_distinct_kind ↔ (distinct_kind_count > 0) — the Boolean
5000 // at-least-one halfspace projection of the closed-set-inversion
5001 // scalar cardinality. Peer of `has_any_missing_kind ↔
5002 // !is_kind_saturated` on the axis-parity axis: where the at-least-
5003 // one halfspace peer on the closed-set-complement axis tests the
5004 // ≥ 1 arm on the missing scalar, this at-least-one halfspace peer
5005 // on the closed-set-inversion axis tests the ≥ 1 arm on the
5006 // distinct scalar. A regression that overrode `has_any_distinct_kind`
5007 // to drop the short-circuit, skip a kind, or drift the walk from
5008 // `ConditionKind::ALL` surfaces HERE at the substrate boundary, not
5009 // as silent drift at every downstream `has-any-distinct-kind`
5010 // require-tag classifier or fleet-wide coverage-analysis dashboard
5011 // callsite. Byte-for-byte peer of
5012 // `crate::tagged_union::TaggedUnion::has_any_populated_kind` one
5013 // struct-layer up under the SAME `any(has)` short-circuit shape.
5014 // Also pins the widened composition law `has_any_distinct_kind() ==
5015 // !distinct_kinds().is_empty()` at every slice — binds the at-
5016 // least-one halfspace Boolean projection to the widened primitive
5017 // without paying for the Vec allocation.
5018 assert_eq!(
5019 slice.has_any_distinct_kind(),
5020 slice.distinct_kind_count() > 0,
5021 "has_any_distinct_kind() drifted from (distinct_kind_count() > 0)",
5022 );
5023 assert_eq!(
5024 slice.has_any_distinct_kind(),
5025 !distinct.is_empty(),
5026 "has_any_distinct_kind() drifted from !distinct_kinds().is_empty()",
5027 );
5028 assert_eq!(
5029 slice.has_any_distinct_kind(),
5030 slice.first_distinct_kind().is_some(),
5031 "has_any_distinct_kind() drifted from first_distinct_kind().is_some()",
5032 );
5033
5034 // has_unique_distinct_kind ↔ (distinct_kind_count == 1) — the
5035 // Boolean cardinality-mid-endpoint projection of the closed-set-
5036 // inversion scalar cardinality. Peer of `has_unique_missing_kind
5037 // ↔ (missing_kind_count == 1)` (=1 mid-endpoint on the missing
5038 // axis) on the axis-parity axis: where the missing-axis peer
5039 // tests the exactly-one arm on the missing scalar, this
5040 // distinct-axis peer tests the exactly-one arm on the distinct
5041 // scalar. A regression that overrode `has_unique_distinct_kind`
5042 // to drop the second-slot short-circuit (returning any at-least-
5043 // one arm), skip a kind, drift the walk from `ConditionKind::ALL`,
5044 // or conflate with `has_any_distinct_kind` (the ≥ 1 halfspace)
5045 // surfaces HERE at the substrate boundary, not as silent drift at
5046 // every downstream `has-unique-distinct-kind` require-tag
5047 // classifier or singleton-coverage diagnostic callsite. Byte-for-
5048 // byte peer of `crate::tagged_union::TaggedUnion::has_unique_populated_kind`
5049 // one struct-layer up under the SAME two-step short-circuit walk
5050 // shape. Also pins the widened composition law
5051 // `has_unique_distinct_kind() == (distinct_kinds().len() == 1)`
5052 // at every slice — binds the cardinality-mid-endpoint Boolean
5053 // projection to the widened + scalar closed-set-inversion
5054 // primitives without paying for the Vec allocation on the ≥ 2-
5055 // distinct arms (where the short-circuit fires).
5056 assert_eq!(
5057 slice.has_unique_distinct_kind(),
5058 slice.distinct_kind_count() == 1,
5059 "has_unique_distinct_kind() drifted from (distinct_kind_count() == 1)",
5060 );
5061 assert_eq!(
5062 slice.has_unique_distinct_kind(),
5063 distinct.len() == 1,
5064 "has_unique_distinct_kind() drifted from (distinct_kinds().len() == 1)",
5065 );
5066
5067 // has_unique_missing_kind ↔ (missing_kind_count == 1) — the
5068 // Boolean cardinality-mid-endpoint projection of the closed-set-
5069 // complement scalar cardinality. Peer of `has_any_missing_kind ↔
5070 // !is_kind_saturated` on the Boolean-projection axis: where the
5071 // at-least-one halfspace peer tests the ≥ 1 arm on the missing
5072 // scalar, this cardinality-mid-endpoint peer tests the exactly-
5073 // one arm. Together with `is_kind_saturated` (zero-arm) and the
5074 // future many-arm peer, the three Booleans partition the missing-
5075 // cardinality closed set at 0, 1, and ≥ 2 respectively. A
5076 // regression that overrode `has_unique_missing_kind` to drop the
5077 // second-slot short-circuit (returning any partial-populated
5078 // arm), skip a kind, drift the walk from `ConditionKind::ALL`, or
5079 // conflate with `is_kind_saturated` (the zero-arm) surfaces HERE
5080 // at the substrate boundary, not as silent drift at every
5081 // downstream `has-unique-missing-kind` require-tag classifier or
5082 // near-saturation-endpoint diagnostic callsite. Byte-for-byte
5083 // peer of `crate::tagged_union::TaggedUnion::has_unique_missing_kind`
5084 // one struct-layer up under the SAME two-step short-circuit
5085 // walk shape. Also pins the widened composition law
5086 // `has_unique_missing_kind() == (missing_kinds().len() == 1)` at
5087 // every slice — binds the cardinality-mid-endpoint Boolean
5088 // projection to the widened + scalar closed-set-complement
5089 // primitives without paying for the Vec allocation on the ≥ 2-
5090 // missing arms (where the short-circuit fires).
5091 assert_eq!(
5092 slice.has_unique_missing_kind(),
5093 slice.missing_kind_count() == 1,
5094 "has_unique_missing_kind() drifted from (missing_kind_count() == 1)",
5095 );
5096 assert_eq!(
5097 slice.has_unique_missing_kind(),
5098 missing.len() == 1,
5099 "has_unique_missing_kind() drifted from (missing_kinds().len() == 1)",
5100 );
5101
5102 // has_multiple_missing_kinds ↔ (missing_kind_count >= 2) — the
5103 // Boolean cardinality many-arm projection of the closed-set-
5104 // complement scalar cardinality. Peer of `has_any_missing_kind ↔
5105 // !is_kind_saturated` (≥ 1 halfspace) and `has_unique_missing_kind
5106 // ↔ (missing_kind_count == 1)` (= 1 mid-endpoint) on the Boolean-
5107 // projection axis: where those peers test the ≥ 1 and = 1 arms on
5108 // the missing scalar, this many-arm peer tests the ≥ 2 arm.
5109 // Together with `is_kind_saturated` (zero-arm) and
5110 // `has_unique_missing_kind` (one-arm), the three Booleans
5111 // partition the missing-cardinality closed set at 0, 1, and ≥ 2
5112 // respectively — every slice satisfies EXACTLY ONE of the three
5113 // projections. A regression that overrode `has_multiple_missing_kinds`
5114 // to drop the second-slot short-circuit (returning `true` on any
5115 // ≥ 1-missing arm), skip a kind, drift the walk from
5116 // `ConditionKind::ALL`, or conflate with `has_any_missing_kind`
5117 // (the ≥ 1 halfspace) surfaces HERE at the substrate boundary,
5118 // not as silent drift at every downstream
5119 // `has-multiple-missing-kinds` require-tag classifier or
5120 // coverage-gap diagnostic callsite. Byte-for-byte peer of
5121 // `crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`
5122 // one struct-layer up under the SAME two-step short-circuit walk
5123 // shape. Also pins the widened composition law
5124 // `has_multiple_missing_kinds() == (missing_kinds().len() >= 2)`
5125 // at every slice — binds the cardinality-many-arm Boolean
5126 // projection to the widened + scalar closed-set-complement
5127 // primitives without paying for the Vec allocation on the ≥ 2-
5128 // missing arms (where the short-circuit fires) or the full-slot
5129 // walk on the scalar counter.
5130 assert_eq!(
5131 slice.has_multiple_missing_kinds(),
5132 slice.missing_kind_count() >= 2,
5133 "has_multiple_missing_kinds() drifted from (missing_kind_count() >= 2)",
5134 );
5135 assert_eq!(
5136 slice.has_multiple_missing_kinds(),
5137 missing.len() >= 2,
5138 "has_multiple_missing_kinds() drifted from (missing_kinds().len() >= 2)",
5139 );
5140
5141 // has_at_most_one_missing_kind ↔ !has_multiple_missing_kinds — the
5142 // Boolean cardinality "≤ 1" negation projection of the many-arm
5143 // primitive on the closed-set-complement axis. Peer of
5144 // `has_multiple_missing_kinds ↔ (missing_kind_count >= 2)` (≥ 2
5145 // many-arm) under the definitional Boolean negation
5146 // `!(≥ 2) == (≤ 1)`. Together with `is_kind_saturated` (=0
5147 // zero-arm) and `has_unique_missing_kind` (=1 mid-endpoint), the
5148 // "≤ 1" primitive collapses to the trichotomy-union
5149 // `is_kind_saturated() || has_unique_missing_kind()` — a
5150 // regression that overrode `has_at_most_one_missing_kind` to drop
5151 // the definitional negation (returning `has_multiple_missing_kinds`
5152 // itself), swap the wrong side, or drift the walk from the
5153 // many-arm primitive surfaces HERE at the substrate boundary, not
5154 // as silent drift at every downstream
5155 // `has-at-most-one-missing-kind` require-tag classifier or near-
5156 // saturation-or-saturated gap-analysis diagnostic callsite. Byte-
5157 // for-byte peer of
5158 // `crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`
5159 // one struct-layer up under the SAME `!has_multiple_missing_kinds`
5160 // definitional negation shape. Also pins the widened composition
5161 // laws
5162 // `has_at_most_one_missing_kind() == (missing_kind_count() <= 1)`
5163 // and `has_at_most_one_missing_kind() == (missing_kinds().len() <= 1)`
5164 // at every slice — binds the "≤ 1" Boolean projection to the
5165 // widened + scalar closed-set-complement primitives without paying
5166 // for the Vec allocation on the ≤ 1-missing arms (where the
5167 // negated short-circuit fires immediately after the many-arm walk
5168 // stops) or the full-slot walk on the scalar counter. Also pins
5169 // the trichotomy-union composition law
5170 // `has_at_most_one_missing_kind() == is_kind_saturated() ||
5171 // has_unique_missing_kind()` at every slice — surfaces any
5172 // implementor that drifted the trichotomy union operator from
5173 // `||` to `&&` or that broke one of the two arm primitives while
5174 // leaving the "≤ 1" negation of the many-arm intact.
5175 assert_eq!(
5176 slice.has_at_most_one_missing_kind(),
5177 !slice.has_multiple_missing_kinds(),
5178 "has_at_most_one_missing_kind() drifted from !has_multiple_missing_kinds()",
5179 );
5180 assert_eq!(
5181 slice.has_at_most_one_missing_kind(),
5182 slice.missing_kind_count() <= 1,
5183 "has_at_most_one_missing_kind() drifted from (missing_kind_count() <= 1)",
5184 );
5185 assert_eq!(
5186 slice.has_at_most_one_missing_kind(),
5187 missing.len() <= 1,
5188 "has_at_most_one_missing_kind() drifted from (missing_kinds().len() <= 1)",
5189 );
5190 assert_eq!(
5191 slice.has_at_most_one_missing_kind(),
5192 slice.is_kind_saturated() || slice.has_unique_missing_kind(),
5193 "has_at_most_one_missing_kind() drifted from (is_kind_saturated() || has_unique_missing_kind())",
5194 );
5195
5196 // lacks_kind ↔ !has_kind — the Boolean per-kind complement
5197 // projection on the closed-set-complement axis. Peer of
5198 // `is_kind_saturated ↔ (missing_kind_count == 0)` on the Boolean-
5199 // projection axis: where the saturation-endpoint peer collapses
5200 // the whole missing scalar to its zero-arm test, this per-kind
5201 // peer collapses the whole missing SET to its per-kind membership
5202 // Boolean for ONE addressed kind. A regression that overrode
5203 // `lacks_kind` to drop the negation (returning `has_kind`), swap
5204 // the wrong side, or drift the walk from `has_kind` surfaces HERE
5205 // at the substrate boundary, not as silent drift at every
5206 // downstream `lacks-<kind>` require-tag classifier or
5207 // dependency-satisfaction coherence check callsite. Byte-for-byte
5208 // peer of `crate::tagged_union::TaggedUnion::lacks` one struct-
5209 // layer up under the SAME `!has(kind)` definitional negation
5210 // shape. Also pins the widened composition law
5211 // `lacks_kind(k) == missing_kinds().contains(&k)` at every arm —
5212 // binds the per-kind Boolean projection to the widened closed-set-
5213 // complement primitive without paying for the Vec allocation.
5214 for kind in ConditionKind::ALL {
5215 assert_eq!(
5216 slice.lacks_kind(kind),
5217 !slice.has_kind(kind),
5218 "lacks_kind({kind:?}) drifted from !has_kind({kind:?})",
5219 );
5220 assert_eq!(
5221 slice.lacks_kind(kind),
5222 missing.contains(&kind),
5223 "lacks_kind({kind:?}) drifted from missing_kinds().contains(&{kind:?})",
5224 );
5225 }
5226
5227 // has_only_kind(k) ↔ (distinct_kinds() == vec![k]) — the kind-
5228 // scoped strict-refinement projection on the closed-set-inversion
5229 // axis. Peer of `lacks_kind ↔ !has_kind` under a symmetrical
5230 // refinement axis: where `lacks_kind` refines `has_kind` under a
5231 // definitional negation (per-kind Boolean complement),
5232 // `has_only_kind` refines it under a well-formed-diagonal
5233 // strengthening (per-kind Boolean AND
5234 // `distinct_kind_count() == 1`). Together the two peers occupy
5235 // the (weaken, strengthen) axes of the per-kind projection on the
5236 // closed-set-inversion widened primitive at the slice level.
5237 // A regression that overrode `has_only_kind` to drop the fused-
5238 // walk short-circuit (returning `has_kind` — TOO LOOSE, admits
5239 // multi-kind slices) or to drop the `saw_kind` arm (returning
5240 // `distinct_kind_count() <= 1` — TOO LOOSE, admits the empty
5241 // slice as well-formed) surfaces HERE at the substrate boundary,
5242 // not as silent drift at every downstream `has-only-<kind>`
5243 // require-tag classifier or well-formed-diagonal coherence check
5244 // callsite. Byte-for-byte peer of
5245 // `crate::tagged_union::TaggedUnion::has_only` one struct-layer
5246 // up under the SAME fused short-circuit closed-set walk shape.
5247 // Also pins the widened composition laws
5248 // `has_only_kind(k) == (distinct_kinds() == vec![k])`,
5249 // `has_only_kind(k) == (has_kind(k) && distinct_kind_count() == 1)`,
5250 // and the kind-domain exhaustivity law "AT MOST ONE `k` satisfies
5251 // `has_only_kind(k)` on any slice".
5252 let mut has_only_hits = 0usize;
5253 for kind in ConditionKind::ALL {
5254 let expected_widened = distinct == vec![kind];
5255 assert_eq!(
5256 slice.has_only_kind(kind),
5257 expected_widened,
5258 "has_only_kind({kind:?}) drifted from (distinct_kinds() == vec![{kind:?}])",
5259 );
5260 assert_eq!(
5261 slice.has_only_kind(kind),
5262 slice.has_kind(kind) && slice.distinct_kind_count() == 1,
5263 "has_only_kind({kind:?}) drifted from (has_kind({kind:?}) && distinct_kind_count() == 1)",
5264 );
5265 // Strict-refinement of `has_kind`: has_only_kind(k) ⟹ has_kind(k).
5266 if slice.has_only_kind(kind) {
5267 assert!(
5268 slice.has_kind(kind),
5269 "has_only_kind({kind:?}) implies has_kind({kind:?})",
5270 );
5271 has_only_hits += 1;
5272 }
5273 }
5274 // Kind-domain exhaustivity — AT MOST ONE `k` satisfies
5275 // `has_only_kind(k)` on any slice.
5276 assert!(
5277 has_only_hits <= 1,
5278 "has_only_kind(k) satisfied by more than one kind (count={has_only_hits}) — kind-domain exhaustivity violated",
5279 );
5280 // has_only_kind(k) for SOME k ⟺ distinct_kind_count() == 1 — the
5281 // kind-domain-exhaustivity ⟺ well-formed-diagonal pin.
5282 assert_eq!(
5283 has_only_hits == 1,
5284 slice.distinct_kind_count() == 1,
5285 "has_only_kind holds for some kind iff distinct_kind_count() == 1",
5286 );
5287
5288 // lacks_only_kind(k) ↔ (missing_kinds() == vec![k]) — the kind-
5289 // scoped strict-refinement projection on the closed-set-complement
5290 // axis. Byte-for-byte peer of `has_only_kind` under complement:
5291 // where `has_only_kind` refines `has_kind` under a well-formed-
5292 // diagonal strengthening on the populated axis, `lacks_only_kind`
5293 // refines `lacks_kind` under the same strengthening on the missing
5294 // axis — the closed-set-complement mirror closes the (populated,
5295 // missing) × (subset, equal) 2x2 kind-scoped strict-refinement grid
5296 // at the slice level alongside `has_kind` / `lacks_kind` /
5297 // `has_only_kind`. A regression that overrode `lacks_only_kind` to
5298 // drop the fused-walk short-circuit (returning `lacks_kind` — TOO
5299 // LOOSE, admits multi-missing-kind slices) or to drop the
5300 // `saw_kind` arm (returning `missing_kind_count() <= 1` — TOO
5301 // LOOSE, admits the saturated slice as well-formed on the missing
5302 // axis) surfaces HERE at the substrate boundary, not as silent
5303 // drift at every downstream `lacks-only-<kind>` require-tag
5304 // classifier or near-saturation-diagonal coherence check callsite.
5305 // Byte-for-byte peer of `crate::tagged_union::TaggedUnion::lacks_only`
5306 // one struct-layer up under the SAME fused short-circuit closed-set
5307 // walk shape. Also pins the widened composition laws
5308 // `lacks_only_kind(k) == (missing_kinds() == vec![k])`,
5309 // `lacks_only_kind(k) == (lacks_kind(k) && missing_kind_count() == 1)`,
5310 // and the kind-domain exhaustivity law "AT MOST ONE `k` satisfies
5311 // `lacks_only_kind(k)` on any slice".
5312 let mut lacks_only_hits = 0usize;
5313 for kind in ConditionKind::ALL {
5314 let expected_widened = missing == vec![kind];
5315 assert_eq!(
5316 slice.lacks_only_kind(kind),
5317 expected_widened,
5318 "lacks_only_kind({kind:?}) drifted from (missing_kinds() == vec![{kind:?}])",
5319 );
5320 assert_eq!(
5321 slice.lacks_only_kind(kind),
5322 slice.lacks_kind(kind) && slice.missing_kind_count() == 1,
5323 "lacks_only_kind({kind:?}) drifted from (lacks_kind({kind:?}) && missing_kind_count() == 1)",
5324 );
5325 // Strict-refinement of `lacks_kind`: lacks_only_kind(k) ⟹ lacks_kind(k).
5326 if slice.lacks_only_kind(kind) {
5327 assert!(
5328 slice.lacks_kind(kind),
5329 "lacks_only_kind({kind:?}) implies lacks_kind({kind:?})",
5330 );
5331 lacks_only_hits += 1;
5332 }
5333 }
5334 // Kind-domain exhaustivity — AT MOST ONE `k` satisfies
5335 // `lacks_only_kind(k)` on any slice.
5336 assert!(
5337 lacks_only_hits <= 1,
5338 "lacks_only_kind(k) satisfied by more than one kind (count={lacks_only_hits}) — kind-domain exhaustivity violated",
5339 );
5340 // lacks_only_kind(k) for SOME k ⟺ missing_kind_count() == 1 — the
5341 // kind-domain-exhaustivity ⟺ near-saturation-diagonal pin.
5342 assert_eq!(
5343 lacks_only_hits == 1,
5344 slice.missing_kind_count() == 1,
5345 "lacks_only_kind holds for some kind iff missing_kind_count() == 1",
5346 );
5347 // lacks_only_kind(k) ⟺ has_unique_missing_kind && first_missing_kind() == Some(k)
5348 // — kind-domain agreement with the arg-less unique-missing predicate.
5349 for kind in ConditionKind::ALL {
5350 assert_eq!(
5351 slice.lacks_only_kind(kind),
5352 slice.has_unique_missing_kind() && slice.first_missing_kind() == Some(kind),
5353 "lacks_only_kind({kind:?}) drifted from (has_unique_missing_kind() && first_missing_kind() == Some({kind:?}))",
5354 );
5355 }
5356
5357 // -------- Load-bearing iterator fold: scalar peers ------------------
5358 //
5359 // Every scalar closed-set peer folds through the load-bearing
5360 // iterator peer at ONE substrate site — a regression that overrides
5361 // ANY scalar peer with a divergent walk (short-circuit skipping a
5362 // kind, forgetting the negation on the complement side, drifting
5363 // from `ConditionKind::ALL` order, ignoring the load-bearing
5364 // iterator entirely with a duplicate closed-set walk of its own)
5365 // surfaces at THIS arm rather than as silent skew between the
5366 // scalar callsite and the iterator callsite at every downstream
5367 // consumer.
5368 //
5369 // Complements the Vec-based composition arms above (`distinct_kinds
5370 // ↔ iter_distinct_kinds`, `distinct_kind_count ↔ distinct_kinds`)
5371 // by binding each scalar peer DIRECTLY to the iterator surface —
5372 // catches an override that specializes ONE scalar peer with a
5373 // divergent walk while leaving the Vec-based intermediate coherent,
5374 // which the transitive `scalar ↔ Vec ↔ iter` composition arms
5375 // cannot detect on their own.
5376 //
5377 // Peer of tagged-union parent-level substrate testkit
5378 // `crate::tagged_union::assert_scalar_peers_fold_through_iter_kinds`.
5379 //
5380 // -------- Distinct side (folds through iter_distinct_kinds) ---------
5381 assert_eq!(
5382 slice.first_distinct_kind(),
5383 slice.iter_distinct_kinds().next(),
5384 "first_distinct_kind() drifted from iter_distinct_kinds().next()",
5385 );
5386 assert_eq!(
5387 slice.last_distinct_kind(),
5388 slice.iter_distinct_kinds().last(),
5389 "last_distinct_kind() drifted from iter_distinct_kinds().last()",
5390 );
5391 assert_eq!(
5392 slice.has_any_distinct_kind(),
5393 slice.iter_distinct_kinds().next().is_some(),
5394 "has_any_distinct_kind() drifted from iter_distinct_kinds().next().is_some()",
5395 );
5396 let via_iter_unique_distinct = {
5397 let mut it = slice.iter_distinct_kinds();
5398 it.next().is_some() && it.next().is_none()
5399 };
5400 assert_eq!(
5401 slice.has_unique_distinct_kind(),
5402 via_iter_unique_distinct,
5403 "has_unique_distinct_kind() drifted from iter_distinct_kinds() two-step short-circuit",
5404 );
5405 // -------- Missing side (folds through iter_missing_kinds) -----------
5406 assert_eq!(
5407 slice.first_missing_kind(),
5408 slice.iter_missing_kinds().next(),
5409 "first_missing_kind() drifted from iter_missing_kinds().next()",
5410 );
5411 assert_eq!(
5412 slice.last_missing_kind(),
5413 slice.iter_missing_kinds().last(),
5414 "last_missing_kind() drifted from iter_missing_kinds().last()",
5415 );
5416 assert_eq!(
5417 slice.is_kind_saturated(),
5418 slice.iter_missing_kinds().next().is_none(),
5419 "is_kind_saturated() drifted from iter_missing_kinds().next().is_none()",
5420 );
5421 let via_iter_unique_missing = {
5422 let mut it = slice.iter_missing_kinds();
5423 it.next().is_some() && it.next().is_none()
5424 };
5425 assert_eq!(
5426 slice.has_unique_missing_kind(),
5427 via_iter_unique_missing,
5428 "has_unique_missing_kind() drifted from iter_missing_kinds() two-step short-circuit",
5429 );
5430 let via_iter_multi_missing = {
5431 let mut it = slice.iter_missing_kinds();
5432 it.next().is_some() && it.next().is_some()
5433 };
5434 assert_eq!(
5435 slice.has_multiple_missing_kinds(),
5436 via_iter_multi_missing,
5437 "has_multiple_missing_kinds() drifted from iter_missing_kinds() two-step short-circuit",
5438 );
5439}
5440
5441/// Substrate testkit macro — pins the FOUR union composition laws that
5442/// bind the (precondition, postcondition, union) refinement triads on
5443/// any authored surface exposing the 12-method (has / find / iter /
5444/// count) × (pre / post / union) `_kind` matrix. Sweeps
5445/// [`ConditionKind::ALL`] at ONE call site per authored arrangement.
5446///
5447/// # The four surface-level union composition laws
5448///
5449/// Where the slice-level substrate primitive
5450/// [`assert_slice_refinement_composition_laws`] pins the algebra that
5451/// binds the four refinements *on a single slice* (`iter_kind` →
5452/// `find_kind` → `has_kind` → `count_kind`), this macro pins the peer
5453/// algebra one struct-layer up: each refinement's union arm on a
5454/// two-slice surface (a [`Boundary`] with `preconditions` +
5455/// `postconditions`, an [`crate::ephemeral::EphemeralSpec`] with the
5456/// same eponymous field pair) composes from its two half-slice arms
5457/// through a specific monoid operator baked into the refinement's return
5458/// type:
5459///
5460/// | refinement | half-slice arms | union composition |
5461/// |------------|---------------------------------------------|---------------------------------------|
5462/// | `has_*_kind` | `has_precondition_kind`, `has_postcondition_kind` | `pre \|\| post` (bool OR) |
5463/// | `find_*_kind` | `find_precondition_kind`, `find_postcondition_kind` | `pre.or(post)` (first-Some) |
5464/// | `iter_*_kind` | `iter_precondition_kind`, `iter_postcondition_kind` | `pre.chain(post)` (stream concat) |
5465/// | `count_*_kind` | `count_precondition_kind`, `count_postcondition_kind` | `pre + post` (cardinality SUM) |
5466///
5467/// # Why lift
5468///
5469/// Pre-lift each surface-level union composition law lived at its own
5470/// hand-authored nested-`for` loop test on each of the two surfaces —
5471/// EIGHT sibling test bodies (`boundary_has_condition_kind_composes_precondition_and_postcondition_arms`,
5472/// `find_condition_kind_triad_delegates_to_slice_find_kind`,
5473/// `iter_condition_kind_triad_delegates_to_slice_iter_kind`,
5474/// `boundary_count_condition_kind_triad_delegates_and_sums_slice_count_kind`
5475/// on the [`Boundary`] surface, byte-for-byte peers on the
5476/// [`crate::ephemeral::EphemeralSpec`] surface) whose only per-law knobs
5477/// were the projection functions being bridged and the composition
5478/// operator (`\|\|` / `Option::or` / `Iterator::chain` / `+`) applied
5479/// on top. Post-lift each authored `(preconditions, postconditions)`
5480/// arrangement pins ALL FOUR union composition laws through ONE
5481/// `assert_surface_union_composition_laws!(surface)` call whose body
5482/// is the substrate primitive's own sweep, no per-surface author-time
5483/// enumeration.
5484///
5485/// # Why a macro rather than a `pub fn`
5486///
5487/// [`Boundary`] and [`crate::ephemeral::EphemeralSpec`] expose the
5488/// twelve methods as *inherent* methods with matching signatures. A
5489/// generic `pub fn assert_surface_union_composition_laws<B: T>(&B)`
5490/// would need a trait `T` publishing those same twelve methods, and
5491/// implementing that trait on either surface would collide with the
5492/// eponymous inherent methods at method resolution — the trait
5493/// impl would either duplicate the inherent-method bodies verbatim
5494/// (defeating the lift) or require renaming the trait methods with a
5495/// `_ext` suffix (introducing a parallel API surface). A macro
5496/// duck-types at expansion time and hits the inherent methods
5497/// directly, so both surfaces stay bound through the SAME
5498/// `_kind`-suffixed method names their non-generic callers already
5499/// reach for, and the pattern generalizes to any future surface that
5500/// grows the same twelve-method matrix (an `AplicacaoBoundary` typed
5501/// wrapper, a `PoolBoundary` gate-carrier at
5502/// [`crate::pool`], the boundary slot on a
5503/// hypothetical `AttestationBoundary` receipt-envelope surface) with
5504/// ONE macro invocation per authored arrangement rather than a per-
5505/// surface re-authored sweep over the four laws.
5506///
5507/// # Compounding
5508///
5509/// A FIFTH union refinement added to the (has, find, iter, count)
5510/// tetrad (a hypothetical `first_params_of_kind(k) -> Option<&Value>`
5511/// projection combining `find_condition_kind(k).map(|c| &c.params)` at
5512/// real reconciler callsites, a `distinct_kinds() -> impl Iterator<Item
5513/// = ConditionKind>` aggregate returning which kinds appear at least
5514/// once on either side, a `has_kind_matching(pred)` closure-based
5515/// predicate probe) lands its composition-law pin as ONE new arm
5516/// inside this macro's body. Every downstream test that already reaches
5517/// this macro picks up the fifth-refinement pin mechanically — no per-
5518/// arrangement author-time enumeration of the new law across the four
5519/// sibling composition-law sites on each of the two surfaces, no
5520/// re-authored `for kind in ConditionKind::ALL { … }` sweep at every
5521/// consumer.
5522///
5523/// Symmetrical shape to [`assert_slice_refinement_composition_laws`]
5524/// one layer below: both project a widened-refinement / coarser-
5525/// refinement composition law contract onto ONE typed substrate call
5526/// site, both sweep the addressed closed set [`ConditionKind::ALL`],
5527/// both surface any implementor that overrode the union arm with a
5528/// divergent composition operator (an `&&` inlined where `\|\|` is
5529/// required, a `pre - post` inlined where `pre + post` is required,
5530/// a `zip` inlined where `chain` is required, a `and_then` inlined
5531/// where `or_else` is required) as a first-class typed test failure
5532/// rather than as silent operator-facing drift at the
5533/// `condition-<kind>` / `precondition-<kind>` / `postcondition-<kind>`
5534/// require-tag classifier surfaces downstream.
5535///
5536/// # Theory grounding
5537///
5538/// - THEORY.md §II.1 invariant 5 — composition preserves proofs. Each
5539/// union arm is a typed projection of its two half-slice peers via
5540/// a specific monoid operator, and this substrate macro turns each
5541/// projection's composition law from doc-prose into a first-class
5542/// typed theorem provable against any surface exposing the twelve
5543/// `_kind`-suffixed inherent methods.
5544/// - THEORY.md §VI.1 — generation over composition. A new
5545/// [`ConditionKind`] variant added to `ALL` reaches every downstream
5546/// union-composition-law consumer through the SAME closed-set sweep
5547/// with no per-caller edit; a new surface (a typed wrapper carrying
5548/// the same twelve methods) picks up all four union composition-law
5549/// pins through ONE macro invocation per authored arrangement.
5550///
5551/// # Usage
5552///
5553/// ```ignore
5554/// // Point surface.
5555/// let mut b = Boundary::default();
5556/// b.preconditions.push(condition_with(ConditionKind::PromQL));
5557/// b.postconditions.push(condition_with(ConditionKind::ClosedLoopAuth));
5558/// assert_surface_union_composition_laws!(b);
5559///
5560/// // Ephemeral surface (peer, same primitive).
5561/// let mut spec = empty_ephemeral();
5562/// spec.postconditions.push(cond(ConditionKind::JobAttested));
5563/// assert_surface_union_composition_laws!(spec);
5564/// ```
5565#[macro_export]
5566macro_rules! assert_surface_union_composition_laws {
5567 ($surface:expr) => {{
5568 let __surface = &$surface;
5569 // Hoist distinct_* out of the per-kind loop — closed-set-inversion
5570 // refinements return the WHOLE distinct-set per call, so a single
5571 // computation per surface backs the per-kind membership arm inside
5572 // the loop AND the canonical-order equality after it.
5573 let __distinct_pre_kinds = __surface.distinct_precondition_kinds();
5574 let __distinct_post_kinds = __surface.distinct_postcondition_kinds();
5575 let __distinct_union_kinds = __surface.distinct_condition_kinds();
5576 let __missing_pre_kinds = __surface.missing_precondition_kinds();
5577 let __missing_post_kinds = __surface.missing_postcondition_kinds();
5578 let __missing_union_kinds = __surface.missing_condition_kinds();
5579 for __kind in $crate::boundary::ConditionKind::ALL {
5580 // has: union == pre || post (bool OR)
5581 let __has_via_arms =
5582 __surface.has_precondition_kind(__kind) || __surface.has_postcondition_kind(__kind);
5583 ::core::assert_eq!(
5584 __surface.has_condition_kind(__kind),
5585 __has_via_arms,
5586 "surface union has arm drifted from OR of half-slice arms for {:?}",
5587 __kind,
5588 );
5589 // find: union == pre.or(post) (first-Some, kind projection)
5590 let __find_via_arms = __surface
5591 .find_precondition_kind(__kind)
5592 .or(__surface.find_postcondition_kind(__kind))
5593 .map(|c| c.kind);
5594 ::core::assert_eq!(
5595 __surface.find_condition_kind(__kind).map(|c| c.kind),
5596 __find_via_arms,
5597 "surface union find arm drifted from precondition.or(postcondition) for {:?}",
5598 __kind,
5599 );
5600 // iter: union == chain(pre, post) (stream concat, kind projection)
5601 let __iter_via_arms: ::std::vec::Vec<_> = __surface
5602 .iter_precondition_kind(__kind)
5603 .chain(__surface.iter_postcondition_kind(__kind))
5604 .map(|c| c.kind)
5605 .collect();
5606 let __iter_via_union: ::std::vec::Vec<_> = __surface
5607 .iter_condition_kind(__kind)
5608 .map(|c| c.kind)
5609 .collect();
5610 ::core::assert_eq!(
5611 __iter_via_union,
5612 __iter_via_arms,
5613 "surface union iter arm drifted from chain(pre, post) for {:?}",
5614 __kind,
5615 );
5616 // count: union == pre + post (cardinality SUM)
5617 ::core::assert_eq!(
5618 __surface.count_condition_kind(__kind),
5619 __surface.count_precondition_kind(__kind)
5620 + __surface.count_postcondition_kind(__kind),
5621 "surface union count arm drifted from SUM of half-slice arms for {:?}",
5622 __kind,
5623 );
5624 // distinct: union.contains(k) == pre.contains(k) || post.contains(k)
5625 // (set-union membership per kind on the closed-set-inversion axis)
5626 ::core::assert_eq!(
5627 __distinct_union_kinds.contains(&__kind),
5628 __distinct_pre_kinds.contains(&__kind)
5629 || __distinct_post_kinds.contains(&__kind),
5630 "surface distinct union arm drifted from OR-membership of half-slice distinct arms for {:?}",
5631 __kind,
5632 );
5633 // missing: union.contains(k) == pre.contains(k) && post.contains(k)
5634 // (set-INTERSECTION membership per kind — a kind is missing
5635 // from the union iff it is missing from BOTH half-slices,
5636 // dual of the distinct-set OR composition).
5637 ::core::assert_eq!(
5638 __missing_union_kinds.contains(&__kind),
5639 __missing_pre_kinds.contains(&__kind)
5640 && __missing_post_kinds.contains(&__kind),
5641 "surface missing union arm drifted from AND-membership of half-slice missing arms for {:?}",
5642 __kind,
5643 );
5644 // missing ↔ has: union.contains(k) == !has_condition_kind(k)
5645 // — binds the missing-set primitive to the point-probe
5646 // primitive on the surface under a negated predicate.
5647 ::core::assert_eq!(
5648 __missing_union_kinds.contains(&__kind),
5649 !__surface.has_condition_kind(__kind),
5650 "surface missing union arm drifted from !has_condition_kind for {:?}",
5651 __kind,
5652 );
5653 // lacks: union == pre && post (bool AND — dual of `has`'s
5654 // `pre || post` OR under `!(a || b) == !a && !b`). A kind is
5655 // lacked from the union iff BOTH half-slices lack it — the
5656 // per-kind Boolean-projection peer of the missing-set
5657 // intersection membership arm above (which composes the SAME
5658 // AND over the closed-set-complement Vecs); this arm
5659 // composes it over the per-slice per-kind negation
5660 // primitives without materializing either side's missing-
5661 // set Vec. A regression that (a) drifted the union operator
5662 // to `||` (widening the intersection to a union),
5663 // (b) dropped the negation on one side, or (c) inverted the
5664 // wrong slice on the point probe surfaces HERE at the
5665 // substrate boundary, not as silent drift at every
5666 // downstream `lacks-<kind>` require-tag classifier callsite.
5667 let __lacks_via_arms =
5668 __surface.lacks_precondition_kind(__kind) && __surface.lacks_postcondition_kind(__kind);
5669 ::core::assert_eq!(
5670 __surface.lacks_condition_kind(__kind),
5671 __lacks_via_arms,
5672 "surface union lacks arm drifted from AND of half-slice lacks arms for {:?}",
5673 __kind,
5674 );
5675 // lacks ↔ has: union == !has_condition_kind(k) — the
5676 // definitional complement law binds the per-kind Boolean-
5677 // complement primitive on the surface to the point-probe
5678 // primitive under negation. Peer of the `missing ↔ has`
5679 // arm above one refinement lower: the closed-set-complement
5680 // Vec's per-kind membership equals the per-kind Boolean
5681 // complement, both equal `!has_condition_kind(k)`. A
5682 // regression that overrode `lacks_condition_kind` to drop
5683 // the negation, drift the underlying union primitive, or
5684 // return `has_condition_kind` surfaces HERE.
5685 ::core::assert_eq!(
5686 __surface.lacks_condition_kind(__kind),
5687 !__surface.has_condition_kind(__kind),
5688 "surface union lacks arm drifted from !has_condition_kind for {:?}",
5689 __kind,
5690 );
5691 }
5692 // distinct: union == canonical(pre ∪ post) — closed-set-inversion
5693 // set-union projected in ConditionKind::ALL order. A regression that
5694 // (a) reversed the walk order (post-then-pre), (b) preserved
5695 // slice-encounter order rather than ConditionKind::ALL order, or
5696 // (c) narrowed the union to an intersection surfaces HERE at the
5697 // substrate boundary (the per-kind membership arm above catches
5698 // membership drift; this arm catches ordering + dedup drift the
5699 // membership arm cannot detect on its own).
5700 let __expected_distinct_union: ::std::vec::Vec<_> =
5701 $crate::boundary::ConditionKind::ALL
5702 .into_iter()
5703 .filter(|__k| {
5704 __distinct_pre_kinds.contains(__k)
5705 || __distinct_post_kinds.contains(__k)
5706 })
5707 .collect();
5708 ::core::assert_eq!(
5709 __distinct_union_kinds, __expected_distinct_union,
5710 "surface distinct union arm drifted from canonical ConditionKind::ALL-ordered set-union of half-slice distinct arms",
5711 );
5712 // missing: union == canonical(pre ∩ post) — closed-set-inversion
5713 // set-INTERSECTION projected in ConditionKind::ALL order. Dual
5714 // of the distinct union canonical-order arm above. A regression
5715 // that (a) reversed the walk order, (b) widened the intersection
5716 // to a union (returning kinds missing from either side rather
5717 // than both), or (c) preserved slice-encounter order rather
5718 // than ConditionKind::ALL order surfaces HERE at the substrate
5719 // boundary.
5720 let __expected_missing_union: ::std::vec::Vec<_> =
5721 $crate::boundary::ConditionKind::ALL
5722 .into_iter()
5723 .filter(|__k| {
5724 __missing_pre_kinds.contains(__k)
5725 && __missing_post_kinds.contains(__k)
5726 })
5727 .collect();
5728 ::core::assert_eq!(
5729 __missing_union_kinds, __expected_missing_union,
5730 "surface missing union arm drifted from canonical ConditionKind::ALL-ordered set-INTERSECTION of half-slice missing arms",
5731 );
5732 }};
5733}
5734
5735/// A single boundary predicate.
5736#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
5737#[serde(rename_all = "camelCase")]
5738pub struct Condition {
5739 pub kind: ConditionKind,
5740 /// Kind-specific payload (free-form JSON).
5741 #[serde(default)]
5742 #[schemars(schema_with = "crate::schema_helpers::preserve_unknown_object")]
5743 pub params: serde_json::Value,
5744}
5745
5746#[derive(
5747 Clone,
5748 Copy,
5749 Debug,
5750 PartialEq,
5751 Eq,
5752 Hash,
5753 Serialize,
5754 Deserialize,
5755 JsonSchema,
5756 tatara_closed_set::DeriveClosedSet,
5757)]
5758#[serde(rename_all = "PascalCase")]
5759#[closed_set(via = "as_str", display, generate_unknown)]
5760pub enum ConditionKind {
5761 /// Another Process must be in a given phase.
5762 /// `params`: `{ "processRef": "...", "namespace": "...", "phase": "Attested" }`
5763 ProcessPhase,
5764 /// FluxCD `Kustomization.status.conditions[type=Ready]` must be `True`.
5765 /// `params`: `{ "name": "...", "namespace": "flux-system" }`
5766 KustomizationHealthy,
5767 /// FluxCD `HelmRelease.status.conditions[type=Ready]` must be `True`.
5768 /// `params`: `{ "name": "...", "namespace": "..." }`
5769 HelmReleaseReleased,
5770 /// Prometheus query — truthy scalar required.
5771 /// `params`: `{ "query": "..." }`
5772 PromQL,
5773 /// CEL expression over a scoped object set.
5774 /// `params`: `{ "expression": "..." }`
5775 Cel,
5776 /// Nix evaluation equality check.
5777 /// `params`: `{ "flakeRef": "...", "attribute": "...", "expect": "..." }`
5778 NixEval,
5779 /// A Kubernetes Job must complete successfully and its emitted BLAKE3
5780 /// receipt must verify.
5781 /// `params`: `{ "name": "...", "namespace": "...", "expectReceipt": true }`
5782 JobAttested,
5783 /// Closed-loop authentication probe — the canonical postcondition for
5784 /// any system that can produce credentials for its own client under
5785 /// test. The probe Job (rendered by the VERIFY handler) fetches a
5786 /// fresh secret from `issuer` (a Service inside the same namespace),
5787 /// presents it to `consumer` (another Service in the same namespace),
5788 /// and verifies that `consumer` authenticated successfully against
5789 /// `jwk_source` (the issuer's published JWK endpoint).
5790 ///
5791 /// The Job emits a three-pillar BLAKE3 receipt that the reconciler
5792 /// chains into `status.attestation`. This turns "the gateway↔SaaS
5793 /// loop holds" from an assertion into a theorem provable for every
5794 /// ephemeral run.
5795 ///
5796 /// `params`:
5797 /// ```json
5798 /// {
5799 /// "issuer": { "service": "demo-app-issuer",
5800 /// "port": 8080,
5801 /// "secretPath": "/v2/get-secret-value" },
5802 /// "consumer": { "service": "demo-app-gateway",
5803 /// "port": 8000,
5804 /// "authPath": "/api/v3/auth" },
5805 /// "jwkSource":{ "service": "demo-app-issuer",
5806 /// "port": 8080,
5807 /// "path": "/.well-known/jwks.json" },
5808 /// "probeImage": "ghcr.io/pleme-io/closed-loop-probe:0.1.0",
5809 /// "timeoutSeconds": 120
5810 /// }
5811 /// ```
5812 ClosedLoopAuth,
5813}
5814
5815impl ConditionKind {
5816 /// The closed set of boundary-condition kinds the reconciler honors.
5817 /// Single source of truth that drives the `as_str` / Display /
5818 /// `FromStr` triad on this enum and the `stub_message` lift of the
5819 /// "not yet implemented" arms the reconciler used to hand-roll three
5820 /// times. Adding a 9th variant lands at one `ALL` entry + one `as_str`
5821 /// arm + one `stub_message` arm — exhaustively checked by the
5822 /// compiler (the array literal forces arity).
5823 ///
5824 /// Sibling closed-set lifts: [`crate::phase::ProcessPhase::ALL`],
5825 /// [`crate::signal::ProcessSignal::ALL`], [`crate::intent::IntentKind::ALL`],
5826 /// [`crate::lifetime::LifetimeKind::ALL`].
5827 pub const ALL: [Self; 8] = [
5828 Self::ProcessPhase,
5829 Self::KustomizationHealthy,
5830 Self::HelmReleaseReleased,
5831 Self::PromQL,
5832 Self::Cel,
5833 Self::NixEval,
5834 Self::JobAttested,
5835 Self::ClosedLoopAuth,
5836 ];
5837
5838 /// Canonical PascalCase wire-format projection — matches the serde
5839 /// `rename_all = "PascalCase"` output verbatim. Used by Display
5840 /// (single source of truth), by `FromStr` to identify the variant
5841 /// from its annotation / status-field representation, and by
5842 /// operator-facing diagnostics that need the kind name without
5843 /// re-serializing the enum through serde_json. Pinned by
5844 /// `condition_kind_as_str_matches_serde`.
5845 pub const fn as_str(self) -> &'static str {
5846 match self {
5847 Self::ProcessPhase => "ProcessPhase",
5848 Self::KustomizationHealthy => "KustomizationHealthy",
5849 Self::HelmReleaseReleased => "HelmReleaseReleased",
5850 Self::PromQL => "PromQL",
5851 Self::Cel => "Cel",
5852 Self::NixEval => "NixEval",
5853 Self::JobAttested => "JobAttested",
5854 Self::ClosedLoopAuth => "ClosedLoopAuth",
5855 }
5856 }
5857
5858 /// The operator-facing "evaluator not yet implemented" message for
5859 /// stub kinds — `Some` iff this kind has no live evaluator wired in
5860 /// `tatara-reconciler::boundary`. ONE site owns the per-kind stub
5861 /// string; the reconciler's dispatch reaches for this projection
5862 /// instead of hand-rolling three parallel `Unknown(...)` strings.
5863 ///
5864 /// A future variant added as a live evaluator returns `None`; a
5865 /// future variant added as a stub returns `Some("<kind> evaluator
5866 /// not yet implemented")` — both reachable through one match
5867 /// instead of three identical-shape arms drifting in parallel.
5868 pub const fn stub_message(self) -> Option<&'static str> {
5869 match self {
5870 Self::PromQL => Some("PromQL evaluator not yet implemented"),
5871 Self::Cel => Some("CEL evaluator not yet implemented"),
5872 Self::NixEval => Some("NixEval evaluator not yet implemented"),
5873 Self::ProcessPhase
5874 | Self::KustomizationHealthy
5875 | Self::HelmReleaseReleased
5876 | Self::JobAttested
5877 | Self::ClosedLoopAuth => None,
5878 }
5879 }
5880
5881 /// True iff this kind has no live evaluator (its [`Self::stub_message`]
5882 /// is `Some`). Pairs with the reconciler's `evaluate` dispatch — a
5883 /// stub kind unconditionally yields `Satisfaction::Unknown`.
5884 pub const fn is_stub(self) -> bool {
5885 self.stub_message().is_some()
5886 }
5887
5888 /// The [`FluxResource`] variant this condition kind fetches from
5889 /// the K8s API server, or `None` for non-Flux-fetching kinds — the
5890 /// typed projection owning the (ConditionKind → FluxResource)
5891 /// association every reconciler `evaluate` dispatch arm and every
5892 /// future coherence check binds through.
5893 ///
5894 /// Pre-lift the association was open-coded at TWO adjacent
5895 /// `evaluate` arms in `tatara-reconciler::boundary::evaluate` past
5896 /// the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold — each arm
5897 /// hand-authored a `(FluxResource::X.api_version(),
5898 /// FluxResource::X.kind())` pair as the two `&str` slots the
5899 /// pre-lift `evaluate_flux_ready(api_version: &str, kind: &str)`
5900 /// signature required. Post-lift the mapping lives at ONE typed
5901 /// projection here, the callee accepts a typed
5902 /// [`FluxResource`] slot (invalid `(apiVersion, kind)` pairings
5903 /// like Kustomization's apiVersion paired with HelmRelease's kind
5904 /// become unrepresentable), and the two `evaluate` arms collapse
5905 /// onto ONE `KustomizationHealthy | HelmReleaseReleased` OR-arm
5906 /// that reads the FluxResource variant from `.flux_resource()`.
5907 ///
5908 /// A future ConditionKind that fetches a fourth Flux resource
5909 /// variant (a hypothetical `BucketSynced` kind against a Flux
5910 /// `Bucket` source) lands as ONE new arm here + ONE new variant
5911 /// on [`FluxResource`] + ONE OR-pattern extension at the
5912 /// reconciler dispatch — no hand-authored `(apiVersion, kind)`
5913 /// pair at the callsite, no widening of the callee's signature.
5914 ///
5915 /// The three current non-Flux-fetching arms return `None`:
5916 /// - `ProcessPhase` fetches a tatara `Process` (through its own
5917 /// [`crate::api_version`] + [`crate::PROCESS_KIND`] pair, not
5918 /// a Flux `(apiVersion, kind)`).
5919 /// - `JobAttested` / `ClosedLoopAuth` fetch a `batch/v1::Job` +
5920 /// an optional receipt `v1::ConfigMap`, both K8s built-ins
5921 /// (not Flux resources).
5922 /// - `PromQL` / `Cel` / `NixEval` are stub evaluators
5923 /// ([`Self::is_stub`]) — no cluster fetch at all.
5924 ///
5925 /// Theory anchor: THEORY.md §II.1 invariant 5 (composition
5926 /// preserves proofs — the (ConditionKind → FluxResource)
5927 /// association lives at ONE typed algebra projection here, not
5928 /// at every reconciler dispatch arm).
5929 pub const fn flux_resource(self) -> Option<FluxResource> {
5930 match self {
5931 Self::KustomizationHealthy => Some(FluxResource::Kustomization),
5932 Self::HelmReleaseReleased => Some(FluxResource::HelmRelease),
5933 Self::ProcessPhase
5934 | Self::PromQL
5935 | Self::Cel
5936 | Self::NixEval
5937 | Self::JobAttested
5938 | Self::ClosedLoopAuth => None,
5939 }
5940 }
5941}
5942
5943// `impl fmt::Display for ConditionKind` + `impl FromStr for
5944// ConditionKind` + `impl tatara_lisp::ClosedSet for ConditionKind` +
5945// `pub struct UnknownConditionKind(pub String)` are generated by
5946// `#[derive(tatara_closed_set::DeriveClosedSet)]` + `#[closed_set(via =
5947// "as_str", display, generate_unknown)]` on the enum declaration above.
5948// The auto-derived label `"condition kind"` matches the prior hand-
5949// rolled `#[error("unknown condition kind: {0}")]` verbatim. The
5950// inherent `as_str` projection stays load-bearing — the PascalCase
5951// wire-format that matches the serde rename + the CRD `enum:` listing
5952// verbatim (notably preserving `PromQL`'s consecutive caps that heck
5953// would have lowercased) — while the trait method `label` gives
5954// generic consumers a STABLE name across the 36+ workspace-wide
5955// closed-set implementors.
5956
5957#[cfg(test)]
5958mod tests {
5959 use super::*;
5960 use serde_json::json;
5961
5962 #[test]
5963 fn serde_process_phase_condition() {
5964 let c = Condition {
5965 kind: ConditionKind::ProcessPhase,
5966 params: json!({ "processRef": "secret-injection", "phase": "Attested" }),
5967 };
5968 let yaml = serde_yaml::to_string(&c).unwrap();
5969 assert!(yaml.contains("kind: ProcessPhase"));
5970 assert!(yaml.contains("processRef: secret-injection"));
5971 }
5972
5973 #[test]
5974 fn serde_closed_loop_auth_condition() {
5975 let c = Condition {
5976 kind: ConditionKind::ClosedLoopAuth,
5977 params: json!({
5978 "issuer": { "service": "demo-app-issuer", "port": 8080 },
5979 "consumer": { "service": "demo-app-gateway", "port": 8000 },
5980 "probeImage": "ghcr.io/pleme-io/closed-loop-probe:0.1.0",
5981 }),
5982 };
5983 let yaml = serde_yaml::to_string(&c).unwrap();
5984 assert!(yaml.contains("kind: ClosedLoopAuth"));
5985 assert!(yaml.contains("probeImage: ghcr.io/pleme-io/closed-loop-probe:0.1.0"));
5986 let back: Condition = serde_yaml::from_str(&yaml).unwrap();
5987 assert_eq!(back.kind, ConditionKind::ClosedLoopAuth);
5988 }
5989
5990 #[test]
5991 fn serde_job_attested_condition() {
5992 let c = Condition {
5993 kind: ConditionKind::JobAttested,
5994 params: json!({ "name": "seed-job", "namespace": "demo-test" }),
5995 };
5996 let yaml = serde_yaml::to_string(&c).unwrap();
5997 assert!(yaml.contains("kind: JobAttested"));
5998 }
5999
6000 // ── closed-set algebra contracts (ALL × as_str × FromStr × stub_message) ─
6001
6002 /// Structural well-formedness of [`ConditionKind`] as a
6003 /// [`tatara_lisp::ClosedSet`] implementor — the workspace-wide
6004 /// testkit lift that pins all three structural invariants (`ALL`
6005 /// is non-empty, every variant round-trips through `label ↔
6006 /// parse_label`, labels are pairwise distinct, `""` is outside the
6007 /// closed set) at ONE call site. Replaces the hand-derived
6008 /// `condition_kind_all_is_unique_and_complete` +
6009 /// `condition_kind_roundtrip_via_as_str` + the empty-input arm of
6010 /// `unknown_condition_kind_errors`. `FromStr` delegates to
6011 /// `<Self as tatara_closed_set::ClosedSet>::parse_label`, so this helper
6012 /// exercises the same code path the reconciler hits when parsing a
6013 /// CRD `enum:`-validated value back to the typed kind.
6014 #[test]
6015 fn condition_kind_is_well_formed_closed_set() {
6016 tatara_closed_set::assert_closed_set_well_formed::<ConditionKind>();
6017 }
6018
6019 /// CANONICAL-KEY CONTRACT: `as_str` matches serde's PascalCase
6020 /// output verbatim for every variant. A future variant rename
6021 /// (or an `as_str` arm typo) lands here at one site. The probe
6022 /// confirmed `PromQL` survives `rename_all = "PascalCase"` as
6023 /// `"PromQL"` (heck preserves consecutive caps in the leading
6024 /// word), so this contract is the operator-facing pin.
6025 #[test]
6026 fn condition_kind_as_str_matches_serde() {
6027 crate::tagged_union::assert_label_matches_serde_serialization::<ConditionKind>();
6028 }
6029
6030 /// The Display impl IS `as_str` — pinning this lets future
6031 /// callers reach for either projection without drift. If a
6032 /// reviewer accidentally re-introduces an inline match in
6033 /// Display, this fails the moment a variant rename touches one
6034 /// site but not the other.
6035 #[test]
6036 fn condition_kind_display_matches_as_str() {
6037 crate::tagged_union::assert_display_matches_label::<ConditionKind>();
6038 }
6039
6040 /// `FromStr` rejects strings that aren't in the canonical
6041 /// projection — lowercased / typo / unrelated — and the error
6042 /// echoes the input verbatim so the operator-facing diagnostic
6043 /// carries the offending value, not a normalized form. The
6044 /// empty-input arm is pinned by
6045 /// [`condition_kind_is_well_formed_closed_set`] via the
6046 /// `tatara_lisp::ClosedSet` testkit; the cases here pin the
6047 /// verbatim-echo contract on the [`UnknownConditionKind`]
6048 /// newtype, which the trait's `make_unknown` can't see.
6049 #[test]
6050 fn unknown_condition_kind_errors() {
6051 use std::str::FromStr;
6052 for bad in ["processPhase", "PROMQL", "Promql", "Bogus"] {
6053 let err = ConditionKind::from_str(bad).unwrap_err();
6054 assert_eq!(err.0, bad, "error payload should echo input verbatim");
6055 }
6056 }
6057
6058 /// STUB CONTRACT: the three placeholder evaluators
6059 /// (PromQL / Cel / NixEval) are exactly the set whose
6060 /// `stub_message` is `Some`. The five live evaluators return
6061 /// `None`. A future variant promoted from stub → live must drop
6062 /// its `stub_message` arm; a new stub must add one. Both
6063 /// transitions land at this test by sweeping ALL.
6064 #[test]
6065 fn condition_kind_stub_set_matches_stubs() {
6066 use ConditionKind::*;
6067 for kind in ConditionKind::ALL {
6068 let expected_is_stub = matches!(kind, PromQL | Cel | NixEval);
6069 assert_eq!(
6070 kind.is_stub(),
6071 expected_is_stub,
6072 "is_stub disagreed for {kind:?}",
6073 );
6074 assert_eq!(
6075 kind.stub_message().is_some(),
6076 expected_is_stub,
6077 "stub_message disagreed for {kind:?}",
6078 );
6079 }
6080 }
6081
6082 /// Pin the exact stub strings so a rename of the operator-facing
6083 /// "not yet implemented" message lands at one site (here) instead
6084 /// of three parallel inline strings in the reconciler.
6085 #[test]
6086 fn condition_kind_stub_messages_are_pinned() {
6087 assert_eq!(
6088 ConditionKind::PromQL.stub_message(),
6089 Some("PromQL evaluator not yet implemented"),
6090 );
6091 assert_eq!(
6092 ConditionKind::Cel.stub_message(),
6093 Some("CEL evaluator not yet implemented"),
6094 );
6095 assert_eq!(
6096 ConditionKind::NixEval.stub_message(),
6097 Some("NixEval evaluator not yet implemented"),
6098 );
6099 }
6100
6101 // ── (ConditionKind → FluxResource) typed projection contracts ────
6102
6103 /// The two Flux-fetching kinds project to their canonical
6104 /// [`FluxResource`] variants. A future ConditionKind rename or
6105 /// FluxResource variant rename that skewed the projection at ONE
6106 /// arm surfaces here.
6107 #[test]
6108 fn kustomization_healthy_projects_to_flux_resource_kustomization() {
6109 assert_eq!(
6110 ConditionKind::KustomizationHealthy.flux_resource(),
6111 Some(FluxResource::Kustomization),
6112 );
6113 }
6114
6115 #[test]
6116 fn helm_release_released_projects_to_flux_resource_helm_release() {
6117 assert_eq!(
6118 ConditionKind::HelmReleaseReleased.flux_resource(),
6119 Some(FluxResource::HelmRelease),
6120 );
6121 }
6122
6123 /// The six non-Flux-fetching kinds project to `None`. Sweeps
6124 /// `ConditionKind::ALL` filtering by `flux_resource().is_none()`
6125 /// so a new variant added without a `flux_resource` arm surfaces
6126 /// at rustc's non-exhaustive-match gate BEFORE this test even
6127 /// runs; a new variant added with a hand-coded `Some(...)` arm
6128 /// that shouldn't fetch Flux surfaces here.
6129 #[test]
6130 fn non_flux_fetching_kinds_project_to_none() {
6131 use ConditionKind::*;
6132 let non_flux: Vec<_> = ConditionKind::ALL
6133 .iter()
6134 .copied()
6135 .filter(|k| k.flux_resource().is_none())
6136 .collect();
6137 assert_eq!(
6138 non_flux,
6139 vec![
6140 ProcessPhase,
6141 PromQL,
6142 Cel,
6143 NixEval,
6144 JobAttested,
6145 ClosedLoopAuth
6146 ],
6147 );
6148 }
6149
6150 /// Every variant of [`ConditionKind`] whose `flux_resource()` is
6151 /// `Some` uniquely names its FluxResource variant (no two
6152 /// ConditionKind arms may fetch the SAME FluxResource — that
6153 /// would signal a redundant closed-set entry). Peers the
6154 /// `every_variants_api_version_and_kind_are_distinct_across_the_closed_set`
6155 /// pin on the sibling [`FluxResource`] closed set.
6156 #[test]
6157 fn flux_resource_projection_is_injective_on_the_some_arms() {
6158 let mut seen = std::collections::HashSet::new();
6159 for k in ConditionKind::ALL {
6160 if let Some(fr) = k.flux_resource() {
6161 assert!(
6162 seen.insert(fr),
6163 "duplicate FluxResource projection at {k:?}: {fr:?}",
6164 );
6165 }
6166 }
6167 }
6168
6169 /// `flux_resource` is `const fn` — the projection is reachable
6170 /// at compile time. A regression that dropped the `const`
6171 /// qualifier would fail-loudly here rather than as a wrong-slot
6172 /// runtime dispatch at every consumer callsite.
6173 #[test]
6174 fn flux_resource_projection_is_const_fn_reachable() {
6175 const K: Option<FluxResource> = ConditionKind::KustomizationHealthy.flux_resource();
6176 const H: Option<FluxResource> = ConditionKind::HelmReleaseReleased.flux_resource();
6177 const P: Option<FluxResource> = ConditionKind::ProcessPhase.flux_resource();
6178 assert_eq!(K, Some(FluxResource::Kustomization));
6179 assert_eq!(H, Some(FluxResource::HelmRelease));
6180 assert_eq!(P, None);
6181 }
6182
6183 // ── Boundary::has_condition_kind substrate pins ──────────────────
6184 //
6185 // Fail-before-pass-after granularity: `Boundary::has_condition_kind`
6186 // did not exist before this commit — the (preconditions +
6187 // postconditions .iter().any(|c| c.kind == K)) union-probe shape
6188 // lived hand-authored inline at the ephemeral require-tag surface
6189 // (`spec.postconditions.iter().any(|c| matches!(c.kind, K))`, sans
6190 // the pre-condition side). The lift places the closed-set-driven
6191 // presence probe on ONE substrate site so the point-domain
6192 // `condition-<kind>` prefix family in `tatara-check` composes it
6193 // through `strip_and_classify_prefixed_kind` byte-for-byte
6194 // symmetrical with `intent-<kind>` (via `Intent::has`) +
6195 // `lifetime-<kind>` (via `Lifetime::has`) — third instance in the
6196 // workspace closed-set-driven presence-probe algebra.
6197
6198 fn condition_with(kind: ConditionKind) -> Condition {
6199 Condition {
6200 kind,
6201 params: json!({}),
6202 }
6203 }
6204
6205 /// EMPTY-BOUNDARY pin — a default [`Boundary`] (no preconditions,
6206 /// no postconditions) returns `false` for EVERY [`ConditionKind`].
6207 /// Sweep `ConditionKind::ALL` so a new variant added without a
6208 /// matching arm in the presence probe surfaces at rustc's
6209 /// exhaustiveness gate on the ALL literal (arity forced by
6210 /// `[Self; 8]`) rather than as a silent false-positive at every
6211 /// downstream `condition-<kind>` require-tag callsite.
6212 #[test]
6213 fn has_condition_kind_returns_false_on_empty_boundary_for_every_kind() {
6214 let b = Boundary::default();
6215 for kind in ConditionKind::ALL {
6216 assert!(
6217 !b.has_condition_kind(kind),
6218 "default boundary must return false for {kind:?}",
6219 );
6220 }
6221 }
6222
6223 /// POSTCONDITION-only pin — a boundary that carries the kind on
6224 /// ONLY postconditions returns `true` for that kind, `false` for
6225 /// every other variant. Sweep the ALL × ALL cross so a regression
6226 /// that (a) hard-coded the arm to a single kind (silently
6227 /// returning true for every populated boundary regardless of
6228 /// which kind was queried), (b) skipped the postcondition side of
6229 /// the union (silently returning false when the kind lived
6230 /// post-only), or (c) matched on Condition::params instead of
6231 /// Condition::kind fails HERE at the substrate primitive.
6232 #[test]
6233 fn has_condition_kind_reads_postconditions_per_kind() {
6234 for populated in ConditionKind::ALL {
6235 let mut b = Boundary::default();
6236 b.postconditions.push(condition_with(populated));
6237 for query in ConditionKind::ALL {
6238 let expected = query == populated;
6239 assert_eq!(
6240 b.has_condition_kind(query),
6241 expected,
6242 "postcondition populated={populated:?}: query {query:?} drifted",
6243 );
6244 }
6245 }
6246 }
6247
6248 /// PRECONDITION-only pin — mirrors the postcondition sweep on the
6249 /// other half of the union. Locks the union semantics on both
6250 /// halves separately so a regression that dropped the
6251 /// pre-condition side of the OR fails here even though the
6252 /// postcondition-side pin above passes.
6253 #[test]
6254 fn has_condition_kind_reads_preconditions_per_kind() {
6255 for populated in ConditionKind::ALL {
6256 let mut b = Boundary::default();
6257 b.preconditions.push(condition_with(populated));
6258 for query in ConditionKind::ALL {
6259 let expected = query == populated;
6260 assert_eq!(
6261 b.has_condition_kind(query),
6262 expected,
6263 "precondition populated={populated:?}: query {query:?} drifted",
6264 );
6265 }
6266 }
6267 }
6268
6269 /// UNION pin — a kind that appears on preconditions returns
6270 /// `true` even when postconditions carries a DIFFERENT kind, and
6271 /// vice versa. Pins the OR-composition of the two halves so a
6272 /// regression that collapsed the union to an intersection (AND)
6273 /// silently reclassifies pre-only or post-only kinds as absent.
6274 #[test]
6275 fn has_condition_kind_unions_pre_and_post_condition_arms() {
6276 let mut b = Boundary::default();
6277 b.preconditions
6278 .push(condition_with(ConditionKind::KustomizationHealthy));
6279 b.postconditions
6280 .push(condition_with(ConditionKind::ClosedLoopAuth));
6281 assert!(
6282 b.has_condition_kind(ConditionKind::KustomizationHealthy),
6283 "pre-only kind must resolve through the union",
6284 );
6285 assert!(
6286 b.has_condition_kind(ConditionKind::ClosedLoopAuth),
6287 "post-only kind must resolve through the union",
6288 );
6289 assert!(
6290 !b.has_condition_kind(ConditionKind::PromQL),
6291 "an absent kind must return false even with populated halves",
6292 );
6293 }
6294
6295 // ── ConditionSliceExt::has_kind substrate pins ────────────────────
6296 //
6297 // Fail-before-pass-after granularity: `ConditionSliceExt::has_kind`
6298 // did not exist before this commit — the `(&[Condition],
6299 // ConditionKind) -> bool` walk shape lived hand-authored inline at
6300 // THREE production sites (twice inside `Boundary::has_condition_kind`
6301 // on `preconditions` ∪ `postconditions`, once at the ephemeral
6302 // require-tag classifier's `closed-loop-auth` arm on
6303 // `spec.postconditions` in `tatara-reconciler::bin::tatara-check`,
6304 // with `matches!` sugar instead of `==` but the same predicate).
6305 // The lift places the per-slice presence probe on ONE substrate site
6306 // so the two-half union at `Boundary` and the one-half probe at the
6307 // ephemeral surface compose against the SAME primitive rather than
6308 // restating the `.iter().any(|c| c.kind == K)` closure body.
6309
6310 /// EMPTY-SLICE pin — an empty `&[Condition]` returns `false` for
6311 /// EVERY [`ConditionKind`]. Sweep `ConditionKind::ALL` so a new
6312 /// variant added without a matching arm in the primitive surfaces
6313 /// at rustc's exhaustiveness gate on the ALL literal (arity forced
6314 /// by `[Self; 8]`) rather than as a silent false-positive at every
6315 /// downstream callsite composing this primitive.
6316 #[test]
6317 fn condition_slice_has_kind_returns_false_on_empty_slice_for_every_kind() {
6318 let empty: &[Condition] = &[];
6319 for kind in ConditionKind::ALL {
6320 assert!(
6321 !empty.has_kind(kind),
6322 "empty slice must return false for {kind:?}",
6323 );
6324 }
6325 }
6326
6327 /// PER-VARIANT pin — a single-element slice returns `true` for
6328 /// exactly the kind it carries, `false` for every other variant.
6329 /// Sweep the ALL × ALL cross so a regression that (a) hard-coded
6330 /// the arm to a single kind (silently returning true for every
6331 /// populated slice regardless of query kind), or (b) matched on
6332 /// [`Condition::params`] instead of [`Condition::kind`] fails HERE
6333 /// at the substrate primitive.
6334 #[test]
6335 fn condition_slice_has_kind_reads_kind_field_per_variant() {
6336 for populated in ConditionKind::ALL {
6337 let slice = [condition_with(populated)];
6338 for query in ConditionKind::ALL {
6339 let expected = query == populated;
6340 assert_eq!(
6341 slice.has_kind(query),
6342 expected,
6343 "populated={populated:?}: query {query:?} drifted",
6344 );
6345 }
6346 }
6347 }
6348
6349 /// MULTI-ENTRY pin — a slice with multiple entries returns `true`
6350 /// for every kind that appears at any position (existential
6351 /// quantifier over the slice), `false` for kinds that appear at
6352 /// no position. Locks the `any` semantics so a regression that
6353 /// collapsed to a `first`-only probe (`slice.first().map_or(false,
6354 /// |c| c.kind == kind)`) fails here even though the single-element
6355 /// per-variant pin above passes.
6356 #[test]
6357 fn condition_slice_has_kind_scans_beyond_the_first_position() {
6358 let slice = [
6359 condition_with(ConditionKind::KustomizationHealthy),
6360 condition_with(ConditionKind::ClosedLoopAuth),
6361 condition_with(ConditionKind::JobAttested),
6362 ];
6363 for present in [
6364 ConditionKind::KustomizationHealthy,
6365 ConditionKind::ClosedLoopAuth,
6366 ConditionKind::JobAttested,
6367 ] {
6368 assert!(
6369 slice.has_kind(present),
6370 "kind at any position must resolve true: {present:?}",
6371 );
6372 }
6373 for absent in [
6374 ConditionKind::ProcessPhase,
6375 ConditionKind::HelmReleaseReleased,
6376 ConditionKind::PromQL,
6377 ConditionKind::Cel,
6378 ConditionKind::NixEval,
6379 ] {
6380 assert!(
6381 !slice.has_kind(absent),
6382 "kind absent from the slice must resolve false: {absent:?}",
6383 );
6384 }
6385 }
6386
6387 /// COMPOSITION pin — [`Boundary::has_condition_kind`] equals the OR
6388 /// of the two half-slice probes at EVERY (populated arrangement,
6389 /// query) pair on `ConditionKind::ALL`. Locks the (union-probe =
6390 /// pre.has_kind ∨ post.has_kind) composition contract at ONE test
6391 /// so a regression that (a) dropped the `||` (silently narrowing
6392 /// the union to an intersection, or to one side only), or
6393 /// (b) hand-authored the union with a divergent walk shape (e.g.
6394 /// summing counts, comparing lengths) surfaces HERE at the
6395 /// composition boundary rather than as silent classifier drift at
6396 /// every downstream `condition-<kind>` require-tag callsite.
6397 #[test]
6398 fn boundary_has_condition_kind_equals_or_of_half_slice_probes() {
6399 for pre_kind in ConditionKind::ALL {
6400 for post_kind in ConditionKind::ALL {
6401 let mut b = Boundary::default();
6402 b.preconditions.push(condition_with(pre_kind));
6403 b.postconditions.push(condition_with(post_kind));
6404 for query in ConditionKind::ALL {
6405 let expected =
6406 b.preconditions.has_kind(query) || b.postconditions.has_kind(query);
6407 assert_eq!(
6408 b.has_condition_kind(query),
6409 expected,
6410 "union drifted: pre={pre_kind:?} post={post_kind:?} query={query:?}",
6411 );
6412 }
6413 }
6414 }
6415 }
6416
6417 // ── Boundary::has_(pre|post)condition_kind substrate pins ────────
6418 //
6419 // Fail-before-pass-after granularity: the two half-slice arms did
6420 // not exist before this commit — the point-domain `precondition-
6421 // <kind>` and `postcondition-<kind>` require-tag classifiers in
6422 // `tatara-reconciler::bin::tatara-check` reached the two condition
6423 // slices through direct field access
6424 // (`spec.boundary.preconditions.has_kind(k)`), bypassing the named
6425 // [`Boundary`] primitive surface that the union-probe
6426 // [`Boundary::has_condition_kind`] already routed through. The
6427 // lift closes the (precondition, postcondition, union) triad on
6428 // ONE typed algebra surface so a future normalization at the
6429 // presence-probe shape lands at ONE site for all three arms.
6430
6431 /// EMPTY-BOUNDARY pin (precondition arm) — a default [`Boundary`]
6432 /// returns `false` for EVERY [`ConditionKind`] on the precondition
6433 /// side. Sweep `ConditionKind::ALL` so a new variant added without
6434 /// a matching arm on the probe surfaces at rustc's exhaustiveness
6435 /// gate on the ALL literal (arity forced by `[Self; 8]`) rather
6436 /// than as a silent false-positive at every downstream
6437 /// `precondition-<kind>` require-tag callsite.
6438 #[test]
6439 fn has_precondition_kind_returns_false_on_empty_boundary_for_every_kind() {
6440 let b = Boundary::default();
6441 for kind in ConditionKind::ALL {
6442 assert!(
6443 !b.has_precondition_kind(kind),
6444 "default boundary must return false on precondition arm for {kind:?}",
6445 );
6446 }
6447 }
6448
6449 /// EMPTY-BOUNDARY pin (postcondition arm) — sibling of the
6450 /// precondition-arm empty pin above on the other half of the
6451 /// (precondition, postcondition) partition. Locks the empty-slice
6452 /// arm return on the postcondition side so a regression that
6453 /// wired the postcondition arm to the precondition slice surfaces
6454 /// HERE at fail-before-pass-after granularity.
6455 #[test]
6456 fn has_postcondition_kind_returns_false_on_empty_boundary_for_every_kind() {
6457 let b = Boundary::default();
6458 for kind in ConditionKind::ALL {
6459 assert!(
6460 !b.has_postcondition_kind(kind),
6461 "default boundary must return false on postcondition arm for {kind:?}",
6462 );
6463 }
6464 }
6465
6466 /// SLICE-SELECTIVITY pin (precondition arm) — a boundary with a
6467 /// kind on the precondition side ONLY resolves `true` at
6468 /// `has_precondition_kind` and `false` at `has_postcondition_kind`.
6469 /// Locks the (side-select, kind-select) partition so a regression
6470 /// that pointed the precondition arm at `self.postconditions` (a
6471 /// copy-paste from the sibling arm) surfaces HERE rather than as
6472 /// silent classifier drift at every downstream
6473 /// `precondition-<kind>` require-tag callsite.
6474 #[test]
6475 fn has_precondition_kind_reads_preconditions_slice_only() {
6476 for populated in ConditionKind::ALL {
6477 let mut b = Boundary::default();
6478 b.preconditions.push(condition_with(populated));
6479 for query in ConditionKind::ALL {
6480 let expected_pre = query == populated;
6481 assert_eq!(
6482 b.has_precondition_kind(query),
6483 expected_pre,
6484 "precondition-only populated={populated:?}: query {query:?} drifted \
6485 on precondition arm",
6486 );
6487 assert!(
6488 !b.has_postcondition_kind(query),
6489 "precondition-only populated={populated:?}: query {query:?} must \
6490 return false on postcondition arm (postconditions is empty)",
6491 );
6492 }
6493 }
6494 }
6495
6496 /// SLICE-SELECTIVITY pin (postcondition arm) — mirror of the
6497 /// precondition-only sweep on the other half. Locks the sibling
6498 /// arm's binding to `self.postconditions` so a regression that
6499 /// pointed the postcondition arm at `self.preconditions` fails
6500 /// HERE even though the precondition-arm pin above passes.
6501 #[test]
6502 fn has_postcondition_kind_reads_postconditions_slice_only() {
6503 for populated in ConditionKind::ALL {
6504 let mut b = Boundary::default();
6505 b.postconditions.push(condition_with(populated));
6506 for query in ConditionKind::ALL {
6507 let expected_post = query == populated;
6508 assert_eq!(
6509 b.has_postcondition_kind(query),
6510 expected_post,
6511 "postcondition-only populated={populated:?}: query {query:?} \
6512 drifted on postcondition arm",
6513 );
6514 assert!(
6515 !b.has_precondition_kind(query),
6516 "postcondition-only populated={populated:?}: query {query:?} must \
6517 return false on precondition arm (preconditions is empty)",
6518 );
6519 }
6520 }
6521 }
6522
6523 /// COMPOSITION-LAW pin — [`Boundary::has_condition_kind`] equals
6524 /// `has_precondition_kind(k) || has_postcondition_kind(k)` at
6525 /// EVERY (pre-populated, post-populated, query) triple on
6526 /// `ConditionKind::ALL`. This is the load-bearing invariant that
6527 /// makes the (precondition, postcondition, union) triad on
6528 /// [`Boundary`] a first-class typed algebra rather than a
6529 /// per-caller discipline: the two half-slice arms + the union arm
6530 /// compose exactly as `union == pre ∨ post`, and every downstream
6531 /// `condition-<K> = precondition-<K> ∨ postcondition-<K>` classifier
6532 /// invariant on `tatara-reconciler::bin::tatara-check` inherits it
6533 /// mechanically. A regression that (a) dropped the composition (by
6534 /// re-inlining `.has_kind(kind)` bodies on the union arm), or
6535 /// (b) drifted ONE of the two half-slice arms without updating the
6536 /// other, surfaces HERE rather than as silent per-side classifier
6537 /// drift at the require-tag surfaces.
6538 #[test]
6539 fn boundary_has_condition_kind_composes_precondition_and_postcondition_arms() {
6540 for pre_kind in ConditionKind::ALL {
6541 for post_kind in ConditionKind::ALL {
6542 let mut b = Boundary::default();
6543 b.preconditions.push(condition_with(pre_kind));
6544 b.postconditions.push(condition_with(post_kind));
6545 for query in ConditionKind::ALL {
6546 let via_arms =
6547 b.has_precondition_kind(query) || b.has_postcondition_kind(query);
6548 assert_eq!(
6549 b.has_condition_kind(query),
6550 via_arms,
6551 "union arm drifted from OR of half-slice arms: \
6552 pre={pre_kind:?} post={post_kind:?} query={query:?}",
6553 );
6554 }
6555 }
6556 }
6557 }
6558
6559 /// SUBSTRATE-DELEGATION pin — the two half-slice arms delegate
6560 /// verbatim to [`ConditionSliceExt::has_kind`] on the underlying
6561 /// [`Vec<Condition>`] slice, no inline reimplementation. Sweep the
6562 /// full `ConditionKind::ALL` × `ConditionKind::ALL` cross so a
6563 /// regression that inlined a divergent walk (`.iter().find(_).
6564 /// is_some()`, an `.any(|c| matches!(c.kind, K))` that missed a
6565 /// variant) at either arm surfaces HERE at the substrate
6566 /// boundary rather than as silent skew between the struct-level
6567 /// arm and the slice-level primitive downstream consumers reach
6568 /// through.
6569 #[test]
6570 fn has_precondition_and_postcondition_kind_delegate_to_slice_has_kind() {
6571 for populated in ConditionKind::ALL {
6572 let mut b = Boundary::default();
6573 b.preconditions.push(condition_with(populated));
6574 b.postconditions.push(condition_with(populated));
6575 for query in ConditionKind::ALL {
6576 assert_eq!(
6577 b.has_precondition_kind(query),
6578 b.preconditions.has_kind(query),
6579 "precondition arm must delegate to preconditions.has_kind: \
6580 populated={populated:?} query={query:?}",
6581 );
6582 assert_eq!(
6583 b.has_postcondition_kind(query),
6584 b.postconditions.has_kind(query),
6585 "postcondition arm must delegate to postconditions.has_kind: \
6586 populated={populated:?} query={query:?}",
6587 );
6588 }
6589 }
6590 }
6591
6592 // ── ConditionSliceExt::find_kind substrate pins + widened triad ──
6593 //
6594 // Fail-before-pass-after granularity: `ConditionSliceExt::find_kind`
6595 // + its three struct-level peers (`Boundary::find_(pre|post)?
6596 // condition_kind`) did not exist before this commit — the existing
6597 // `has_*_kind` triad collapses the return to `bool`, losing the
6598 // matching `&Condition` a future diagnostic consumer (an operator-
6599 // facing "found on {pre|post}conditions at param.probeImage=X"
6600 // message, a coherence check verifying "every ClosedLoopAuth
6601 // postcondition carries a non-empty probeImage", an editor
6602 // completion listing params-keys per present kind) needs. The lift
6603 // widens the primitive to `Option<&Condition>` and re-anchors
6604 // `has_kind` as a default composed from it, so the two refinements
6605 // share ONE walk semantics by construction.
6606
6607 /// EMPTY-SLICE pin — an empty `&[Condition]` returns `None` from
6608 /// `find_kind` for EVERY [`ConditionKind`]. Sweep
6609 /// `ConditionKind::ALL` so a new variant added without a matching
6610 /// arm in the primitive surfaces at rustc's exhaustiveness gate on
6611 /// the ALL literal (arity forced by `[Self; 8]`) rather than as a
6612 /// silent false-`Some` at every downstream widened callsite.
6613 #[test]
6614 fn condition_slice_find_kind_returns_none_on_empty_slice_for_every_kind() {
6615 let empty: &[Condition] = &[];
6616 for kind in ConditionKind::ALL {
6617 assert!(
6618 empty.find_kind(kind).is_none(),
6619 "empty slice must return None for {kind:?}",
6620 );
6621 }
6622 }
6623
6624 /// PER-VARIANT pin — a single-element slice returns `Some` with
6625 /// the matching kind for exactly the kind it carries, `None` for
6626 /// every other variant. Sweep the ALL × ALL cross so a regression
6627 /// that (a) hard-coded the arm to a single kind (silently returning
6628 /// `Some` for every populated slice regardless of query kind), or
6629 /// (b) matched on [`Condition::params`] instead of [`Condition::kind`]
6630 /// fails HERE at the substrate primitive.
6631 #[test]
6632 fn condition_slice_find_kind_reads_kind_field_per_variant() {
6633 for populated in ConditionKind::ALL {
6634 let slice = [condition_with(populated)];
6635 for query in ConditionKind::ALL {
6636 let hit = slice.find_kind(query);
6637 if query == populated {
6638 assert_eq!(
6639 hit.map(|c| c.kind),
6640 Some(populated),
6641 "populated={populated:?}: query {query:?} must return Some",
6642 );
6643 } else {
6644 assert!(
6645 hit.is_none(),
6646 "populated={populated:?}: query {query:?} must return None",
6647 );
6648 }
6649 }
6650 }
6651 }
6652
6653 /// FIRST-MATCH pin — a slice with the same kind at MULTIPLE
6654 /// positions returns the earliest by position. Locks the `.iter().
6655 /// find(...)` semantics so a regression that collapsed to a
6656 /// `.last()` walk (returning the trailing match) or a `.rev().
6657 /// find(...)` walk (returning the last-inserted match) surfaces
6658 /// HERE, since diagnostic consumers reading `find_kind(K).unwrap().
6659 /// params` expect the FIRST occurrence's params-payload not the
6660 /// last.
6661 #[test]
6662 fn condition_slice_find_kind_returns_first_position_on_duplicate_kinds() {
6663 // Two ClosedLoopAuth entries with distinct params — a first-
6664 // match walk resolves to the leading entry's params-payload.
6665 let first = Condition {
6666 kind: ConditionKind::ClosedLoopAuth,
6667 params: json!({ "probeImage": "first" }),
6668 };
6669 let second = Condition {
6670 kind: ConditionKind::ClosedLoopAuth,
6671 params: json!({ "probeImage": "second" }),
6672 };
6673 let slice = [first, second];
6674 let hit = slice
6675 .find_kind(ConditionKind::ClosedLoopAuth)
6676 .expect("populated slice must resolve Some on the matching kind");
6677 assert_eq!(
6678 hit.params
6679 .get("probeImage")
6680 .and_then(serde_json::Value::as_str),
6681 Some("first"),
6682 "find_kind must return the FIRST position's Condition on duplicate kinds",
6683 );
6684 }
6685
6686 /// SLICE-LEVEL DELEGATION pin (has ↔ find) — [`ConditionSliceExt::has_kind`]
6687 /// equals `find_kind(k).is_some()` at EVERY (populated arrangement,
6688 /// query) pair on `ConditionKind::ALL`. Turns the trait doc's
6689 /// "compounding" note ("the closed-set discriminator case becomes
6690 /// `has_kind(k) == self.find_kind(k).is_some()` by construction")
6691 /// into a first-class typed test invariant: a future consumer
6692 /// that overrode the default `has_kind` body with a divergent walk
6693 /// shape (a `.iter().any(...)` that missed a variant, a `.count() >
6694 /// 0` predicate on a filtered clone) surfaces HERE at the substrate
6695 /// boundary rather than as silent skew between the two refinements
6696 /// downstream consumers reach through.
6697 #[test]
6698 fn condition_slice_has_kind_equals_find_kind_is_some() {
6699 for pre_kind in ConditionKind::ALL {
6700 for post_kind in ConditionKind::ALL {
6701 let slice = [condition_with(pre_kind), condition_with(post_kind)];
6702 for query in ConditionKind::ALL {
6703 assert_eq!(
6704 slice.has_kind(query),
6705 slice.find_kind(query).is_some(),
6706 "slice-level has/find refinement bridge drifted: \
6707 pre={pre_kind:?} post={post_kind:?} query={query:?}",
6708 );
6709 }
6710 }
6711 }
6712 }
6713
6714 /// SUBSTRATE-DELEGATION pin (find-triad) — the three widened
6715 /// `find_*_kind` methods on [`Boundary`] delegate verbatim to
6716 /// [`ConditionSliceExt::find_kind`] on the underlying
6717 /// [`Vec<Condition>`] slices, no inline reimplementation. The
6718 /// `find_condition_kind` union walks preconditions first then
6719 /// postconditions via `Option::or_else`. Sweep
6720 /// `ConditionKind::ALL × ConditionKind::ALL × ConditionKind::ALL`
6721 /// so a regression that (a) inlined a divergent walk at either
6722 /// half-slice arm, (b) reversed the union walk order (postcondition
6723 /// first), or (c) collapsed `or_else` to `and_then` (silently
6724 /// narrowing the union to an intersection) surfaces HERE at the
6725 /// substrate boundary rather than as silent skew between the
6726 /// struct-level widened arms and the slice-level primitive.
6727 #[test]
6728 fn find_condition_kind_triad_delegates_to_slice_find_kind() {
6729 for pre_kind in ConditionKind::ALL {
6730 for post_kind in ConditionKind::ALL {
6731 let mut b = Boundary::default();
6732 b.preconditions.push(condition_with(pre_kind));
6733 b.postconditions.push(condition_with(post_kind));
6734 for query in ConditionKind::ALL {
6735 let via_pre = b.preconditions.find_kind(query);
6736 let via_post = b.postconditions.find_kind(query);
6737 assert_eq!(
6738 b.find_precondition_kind(query).map(|c| c.kind),
6739 via_pre.map(|c| c.kind),
6740 "precondition find arm must delegate to preconditions.find_kind: \
6741 pre={pre_kind:?} post={post_kind:?} query={query:?}",
6742 );
6743 assert_eq!(
6744 b.find_postcondition_kind(query).map(|c| c.kind),
6745 via_post.map(|c| c.kind),
6746 "postcondition find arm must delegate to postconditions.find_kind: \
6747 pre={pre_kind:?} post={post_kind:?} query={query:?}",
6748 );
6749 let expected_union = via_pre.or(via_post).map(|c| c.kind);
6750 assert_eq!(
6751 b.find_condition_kind(query).map(|c| c.kind),
6752 expected_union,
6753 "union find arm must equal precondition.or_else(postcondition): \
6754 pre={pre_kind:?} post={post_kind:?} query={query:?}",
6755 );
6756 }
6757 }
6758 }
6759 }
6760
6761 /// PRECONDITION-PRECEDENCE pin — a kind authored on BOTH sides
6762 /// returns the precondition-side [`Condition`] from
6763 /// `find_condition_kind`. Uses two params-distinguishable
6764 /// [`Condition`]s so a regression that reversed the walk order
6765 /// (postcondition first) surfaces at the returned params payload
6766 /// rather than silently at the presence bit (which is `true` on
6767 /// both walk orders).
6768 #[test]
6769 fn find_condition_kind_returns_precondition_side_on_dual_populated() {
6770 let mut b = Boundary::default();
6771 b.preconditions.push(Condition {
6772 kind: ConditionKind::ClosedLoopAuth,
6773 params: json!({ "side": "pre" }),
6774 });
6775 b.postconditions.push(Condition {
6776 kind: ConditionKind::ClosedLoopAuth,
6777 params: json!({ "side": "post" }),
6778 });
6779 let hit = b
6780 .find_condition_kind(ConditionKind::ClosedLoopAuth)
6781 .expect("dual-populated boundary must resolve Some");
6782 assert_eq!(
6783 hit.params.get("side").and_then(serde_json::Value::as_str),
6784 Some("pre"),
6785 "find_condition_kind must walk preconditions first: dual-populated kind \
6786 returned postcondition-side Condition rather than precondition-side",
6787 );
6788 }
6789
6790 /// STRUCT-LEVEL DELEGATION pin (has ↔ find) — the three
6791 /// [`Boundary`] `has_*_kind` arms equal their widened peers'
6792 /// `.is_some()` projection at EVERY (pre-populated, post-populated,
6793 /// query) triple on `ConditionKind::ALL`. The three widened
6794 /// `find_*_kind` arms are the load-bearing primitives; the three
6795 /// `has_*_kind` arms are their bool projections. Byte-for-byte
6796 /// re-anchors the composition-law pin
6797 /// `boundary_has_condition_kind_composes_precondition_and_postcondition_arms`
6798 /// through the widened axis so a future consumer that reads
6799 /// `has_condition_kind` as sugar for `find_condition_kind(k).
6800 /// is_some()` (rather than as `has_precondition_kind ||
6801 /// has_postcondition_kind`) stays typed against the SAME truth
6802 /// table.
6803 #[test]
6804 fn boundary_has_triad_equals_find_triad_is_some_projection() {
6805 for pre_kind in ConditionKind::ALL {
6806 for post_kind in ConditionKind::ALL {
6807 let mut b = Boundary::default();
6808 b.preconditions.push(condition_with(pre_kind));
6809 b.postconditions.push(condition_with(post_kind));
6810 for query in ConditionKind::ALL {
6811 assert_eq!(
6812 b.has_precondition_kind(query),
6813 b.find_precondition_kind(query).is_some(),
6814 "precondition has/find bridge drifted: \
6815 pre={pre_kind:?} post={post_kind:?} query={query:?}",
6816 );
6817 assert_eq!(
6818 b.has_postcondition_kind(query),
6819 b.find_postcondition_kind(query).is_some(),
6820 "postcondition has/find bridge drifted: \
6821 pre={pre_kind:?} post={post_kind:?} query={query:?}",
6822 );
6823 assert_eq!(
6824 b.has_condition_kind(query),
6825 b.find_condition_kind(query).is_some(),
6826 "union has/find bridge drifted: \
6827 pre={pre_kind:?} post={post_kind:?} query={query:?}",
6828 );
6829 }
6830 }
6831 }
6832 }
6833
6834 // ── ConditionSliceExt::iter_kind substrate pins + widened triad ──
6835 //
6836 // Fail-before-pass-after granularity: `ConditionSliceExt::iter_kind`
6837 // + its three struct-level peers (`Boundary::iter_(pre|post|)?
6838 // condition_kind`) did not exist before this commit — the existing
6839 // `find_*_kind` triad collapses the return to `Option<&Condition>`
6840 // (yielding only the FIRST match), losing the full match stream a
6841 // future coherence check ("each ConditionKind appears at most
6842 // once per side" — `iter_kind(k).nth(1).is_none()`) or diagnostic
6843 // consumer ("N ClosedLoopAuth postconditions matched, listing
6844 // every param.probeImage" — `iter_kind(k).collect()`) needs. The
6845 // lift widens the primitive to `KindMatches<'_>` (a named
6846 // Iterator<Item = &Condition>) and re-anchors `find_kind` as a
6847 // default composed from it (`self.iter_kind(kind).next()`), so
6848 // the three refinements share ONE walk semantics by construction.
6849
6850 /// EMPTY-SLICE pin (iter) — an empty `&[Condition]` yields
6851 /// nothing from `iter_kind` for EVERY [`ConditionKind`]. Sweep
6852 /// `ConditionKind::ALL` so a new variant added without a matching
6853 /// arm in the primitive surfaces at rustc's exhaustiveness gate
6854 /// on the ALL literal rather than as a silent phantom-yield at
6855 /// every downstream widened callsite.
6856 #[test]
6857 fn condition_slice_iter_kind_yields_nothing_on_empty_slice_for_every_kind() {
6858 let empty: &[Condition] = &[];
6859 for kind in ConditionKind::ALL {
6860 assert_eq!(
6861 empty.iter_kind(kind).count(),
6862 0,
6863 "empty slice must yield nothing on iter_kind for {kind:?}",
6864 );
6865 }
6866 }
6867
6868 /// PER-VARIANT pin (iter) — a single-element slice yields exactly
6869 /// that element on the matching kind and nothing on every other
6870 /// kind. Sweep the ALL × ALL cross so a regression that (a)
6871 /// hard-coded the filter predicate to a single kind (silently
6872 /// yielding on every populated slice regardless of query kind),
6873 /// or (b) matched on [`Condition::params`] instead of
6874 /// [`Condition::kind`] fails HERE at the substrate primitive.
6875 #[test]
6876 fn condition_slice_iter_kind_reads_kind_field_per_variant() {
6877 for populated in ConditionKind::ALL {
6878 let slice = [condition_with(populated)];
6879 for query in ConditionKind::ALL {
6880 let collected: Vec<_> = slice.iter_kind(query).map(|c| c.kind).collect();
6881 if query == populated {
6882 assert_eq!(
6883 collected,
6884 vec![populated],
6885 "populated={populated:?}: query {query:?} must yield [populated]",
6886 );
6887 } else {
6888 assert!(
6889 collected.is_empty(),
6890 "populated={populated:?}: query {query:?} must yield nothing",
6891 );
6892 }
6893 }
6894 }
6895 }
6896
6897 /// ALL-MATCHES pin — a slice with the same kind at MULTIPLE
6898 /// positions yields EVERY match in slice order (not just the
6899 /// first). Uses params-distinguishable [`Condition`]s so a
6900 /// regression that (a) collapsed to a single-match walk
6901 /// (`.iter().find(...)` yielding only the earliest and
6902 /// terminating), (b) reversed the yield order (`.rev().filter`
6903 /// yielding trailing-first), or (c) de-duplicated by kind (an
6904 /// erroneous `HashSet::insert`-gated walk) surfaces HERE at the
6905 /// params payload rather than silently at a downstream
6906 /// count-based coherence check.
6907 #[test]
6908 fn condition_slice_iter_kind_yields_every_match_in_slice_order_on_duplicates() {
6909 let first = Condition {
6910 kind: ConditionKind::ClosedLoopAuth,
6911 params: json!({ "probeImage": "first" }),
6912 };
6913 let middle = Condition {
6914 kind: ConditionKind::PromQL,
6915 params: json!({ "query": "up" }),
6916 };
6917 let second_cla = Condition {
6918 kind: ConditionKind::ClosedLoopAuth,
6919 params: json!({ "probeImage": "second" }),
6920 };
6921 let slice = [first, middle, second_cla];
6922 let hits: Vec<_> = slice
6923 .iter_kind(ConditionKind::ClosedLoopAuth)
6924 .map(|c| {
6925 c.params
6926 .get("probeImage")
6927 .and_then(serde_json::Value::as_str)
6928 .unwrap_or_default()
6929 .to_owned()
6930 })
6931 .collect();
6932 assert_eq!(
6933 hits,
6934 vec!["first".to_owned(), "second".to_owned()],
6935 "iter_kind must yield every match in slice order (not just the first)",
6936 );
6937 // The interleaved non-matching kind is skipped: two hits, not three.
6938 assert_eq!(
6939 slice.iter_kind(ConditionKind::ClosedLoopAuth).count(),
6940 2,
6941 "iter_kind must skip non-matching kinds, not include them in the stream",
6942 );
6943 }
6944
6945 /// SLICE-LEVEL DELEGATION pin (find ↔ iter) — the trait's default
6946 /// `find_kind` body equals `iter_kind(k).next()` at EVERY
6947 /// (populated arrangement, query) pair on `ConditionKind::ALL`.
6948 /// Turns the trait doc's composition-law note
6949 /// ("`find_kind(k) == iter_kind(k).next()` by construction")
6950 /// into a first-class typed test invariant: a future implementor
6951 /// that overrode the default `find_kind` body with a divergent
6952 /// walk shape (a `.iter().rev().find(...)` returning trailing-
6953 /// first, a hand-rolled loop that walked past the first match)
6954 /// surfaces HERE at the substrate boundary rather than as silent
6955 /// skew between the two refinements downstream consumers reach
6956 /// through.
6957 #[test]
6958 fn condition_slice_find_kind_equals_iter_kind_next() {
6959 for pre_kind in ConditionKind::ALL {
6960 for post_kind in ConditionKind::ALL {
6961 let slice = [condition_with(pre_kind), condition_with(post_kind)];
6962 for query in ConditionKind::ALL {
6963 assert_eq!(
6964 slice.find_kind(query).map(|c| c.kind),
6965 slice.iter_kind(query).next().map(|c| c.kind),
6966 "slice-level find/iter refinement bridge drifted: \
6967 pre={pre_kind:?} post={post_kind:?} query={query:?}",
6968 );
6969 }
6970 }
6971 }
6972 }
6973
6974 /// SUBSTRATE-DELEGATION pin (Boundary iter-triad) — the three
6975 /// widened `iter_*_kind` methods on [`Boundary`] delegate verbatim
6976 /// to [`ConditionSliceExt::iter_kind`] on the underlying
6977 /// [`Vec<Condition>`] slices, no inline reimplementation. The
6978 /// `iter_condition_kind` union chains preconditions first then
6979 /// postconditions via [`Iterator::chain`]. Sweep
6980 /// `ConditionKind::ALL × ConditionKind::ALL × ConditionKind::ALL`
6981 /// so a regression that (a) inlined a divergent walk at either
6982 /// half-slice arm, (b) reversed the chain order (postcondition
6983 /// first — walk-order regression on the union), or (c) collapsed
6984 /// the chain to a `.zip(...)` (silently narrowing the union to
6985 /// an intersection-by-position) surfaces HERE at the substrate
6986 /// boundary rather than as silent skew between the struct-level
6987 /// widened arms and the slice-level primitive.
6988 #[test]
6989 fn iter_condition_kind_triad_delegates_to_slice_iter_kind() {
6990 for pre_kind in ConditionKind::ALL {
6991 for post_kind in ConditionKind::ALL {
6992 let mut b = Boundary::default();
6993 b.preconditions.push(condition_with(pre_kind));
6994 b.postconditions.push(condition_with(post_kind));
6995 for query in ConditionKind::ALL {
6996 let via_pre: Vec<_> =
6997 b.preconditions.iter_kind(query).map(|c| c.kind).collect();
6998 let via_post: Vec<_> =
6999 b.postconditions.iter_kind(query).map(|c| c.kind).collect();
7000 assert_eq!(
7001 b.iter_precondition_kind(query)
7002 .map(|c| c.kind)
7003 .collect::<Vec<_>>(),
7004 via_pre,
7005 "precondition iter arm must delegate to preconditions.iter_kind: \
7006 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7007 );
7008 assert_eq!(
7009 b.iter_postcondition_kind(query)
7010 .map(|c| c.kind)
7011 .collect::<Vec<_>>(),
7012 via_post,
7013 "postcondition iter arm must delegate to postconditions.iter_kind: \
7014 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7015 );
7016 let mut expected_union = via_pre.clone();
7017 expected_union.extend(via_post.iter().copied());
7018 assert_eq!(
7019 b.iter_condition_kind(query)
7020 .map(|c| c.kind)
7021 .collect::<Vec<_>>(),
7022 expected_union,
7023 "union iter arm must chain precondition ⨟ postcondition: \
7024 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7025 );
7026 }
7027 }
7028 }
7029 }
7030
7031 /// STRUCT-LEVEL DELEGATION pin (find ↔ iter on Boundary) — the
7032 /// three [`Boundary`] `find_*_kind` arms equal their widened
7033 /// peers' `.next()` projection at EVERY (pre-populated,
7034 /// post-populated, query) triple on `ConditionKind::ALL`. Byte-
7035 /// for-byte re-anchors the composition-law pin
7036 /// `find_condition_kind == iter_condition_kind.next()` through
7037 /// the widened axis on the parent surface — a future consumer
7038 /// that reads `find_condition_kind(k)` as sugar for
7039 /// `iter_condition_kind(k).next()` stays typed against the SAME
7040 /// truth table on both the slice-level and struct-level layers.
7041 #[test]
7042 fn boundary_find_triad_equals_iter_triad_next_projection() {
7043 for pre_kind in ConditionKind::ALL {
7044 for post_kind in ConditionKind::ALL {
7045 let mut b = Boundary::default();
7046 b.preconditions.push(condition_with(pre_kind));
7047 b.postconditions.push(condition_with(post_kind));
7048 for query in ConditionKind::ALL {
7049 assert_eq!(
7050 b.find_precondition_kind(query).map(|c| c.kind),
7051 b.iter_precondition_kind(query).next().map(|c| c.kind),
7052 "precondition find/iter bridge drifted: \
7053 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7054 );
7055 assert_eq!(
7056 b.find_postcondition_kind(query).map(|c| c.kind),
7057 b.iter_postcondition_kind(query).next().map(|c| c.kind),
7058 "postcondition find/iter bridge drifted: \
7059 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7060 );
7061 assert_eq!(
7062 b.find_condition_kind(query).map(|c| c.kind),
7063 b.iter_condition_kind(query).next().map(|c| c.kind),
7064 "union find/iter bridge drifted: \
7065 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7066 );
7067 }
7068 }
7069 }
7070 }
7071
7072 /// PRECONDITION-PRECEDENCE pin (iter) — a kind authored on BOTH
7073 /// sides yields precondition-side matches FIRST in the union
7074 /// chain. Uses params-distinguishable [`Condition`]s so a
7075 /// regression that (a) reversed the chain order on the widened
7076 /// axis (postcondition first), (b) interleaved the two sides,
7077 /// or (c) collapsed the chain to a `.zip(...)` fails at the
7078 /// returned params-payload sequence rather than silently at the
7079 /// count.
7080 #[test]
7081 fn iter_condition_kind_yields_preconditions_before_postconditions_on_dual_populated() {
7082 let mut b = Boundary::default();
7083 b.preconditions.push(Condition {
7084 kind: ConditionKind::ClosedLoopAuth,
7085 params: json!({ "side": "pre-1" }),
7086 });
7087 b.preconditions.push(Condition {
7088 kind: ConditionKind::ClosedLoopAuth,
7089 params: json!({ "side": "pre-2" }),
7090 });
7091 b.postconditions.push(Condition {
7092 kind: ConditionKind::ClosedLoopAuth,
7093 params: json!({ "side": "post-1" }),
7094 });
7095 let sides: Vec<_> = b
7096 .iter_condition_kind(ConditionKind::ClosedLoopAuth)
7097 .map(|c| {
7098 c.params
7099 .get("side")
7100 .and_then(serde_json::Value::as_str)
7101 .unwrap_or_default()
7102 .to_owned()
7103 })
7104 .collect();
7105 assert_eq!(
7106 sides,
7107 vec!["pre-1".to_owned(), "pre-2".to_owned(), "post-1".to_owned(),],
7108 "iter_condition_kind must yield every precondition-side match before any \
7109 postcondition-side match (chain order pinned by two-surface parity contract)",
7110 );
7111 }
7112
7113 // ----- count_kind — scalar cardinality refinement --------------------
7114 //
7115 // The `count_kind` fourth refinement collapses the widened
7116 // `iter_kind` stream to its cardinality without materializing an
7117 // intermediate `Vec` or `Option`. Distinct composition law from the
7118 // three prior refinements: `count_condition_kind` SUMS pre + post
7119 // (rather than OR-ing them via `has`, or_else-ing them via `find`,
7120 // or Chain-ing them via `iter`). The tests below pin (a) the default
7121 // trait body against the primitive `iter_kind(k).count()`, (b) the
7122 // slice-level composition laws `has_kind(k) == (count_kind(k) > 0)`
7123 // and `find_kind(k).is_some() == (count_kind(k) > 0)`, (c) the
7124 // struct-level SUM composition on both `Boundary` half-slice arms,
7125 // and (d) the two-surface parity contract with
7126 // `EphemeralSpec::count_(pre|post|)condition_kind` (in ephemeral.rs).
7127
7128 /// EMPTY-SLICE pin (count) — an empty `&[Condition]` returns `0`
7129 /// from `count_kind` for EVERY [`ConditionKind`]. Sweep
7130 /// `ConditionKind::ALL` so a new variant added without a matching
7131 /// arm surfaces at rustc's exhaustiveness gate on the ALL literal
7132 /// rather than as silent phantom-cardinality at every downstream
7133 /// count callsite.
7134 #[test]
7135 fn condition_slice_count_kind_returns_zero_on_empty_slice_for_every_kind() {
7136 let empty: &[Condition] = &[];
7137 for kind in ConditionKind::ALL {
7138 assert_eq!(
7139 empty.count_kind(kind),
7140 0,
7141 "empty slice must count 0 for {kind:?}",
7142 );
7143 }
7144 }
7145
7146 /// PER-VARIANT pin (count) — a single-element slice returns `1`
7147 /// on the matching kind and `0` on every other kind. Sweep ALL ×
7148 /// ALL so a regression that (a) hard-coded the filter predicate
7149 /// to a single kind (silently counting every populated slice
7150 /// regardless of query), or (b) matched on [`Condition::params`]
7151 /// instead of [`Condition::kind`] fails HERE at the substrate
7152 /// primitive.
7153 #[test]
7154 fn condition_slice_count_kind_reads_kind_field_per_variant() {
7155 for populated in ConditionKind::ALL {
7156 let slice = [condition_with(populated)];
7157 for query in ConditionKind::ALL {
7158 let expected = if query == populated { 1 } else { 0 };
7159 assert_eq!(
7160 slice.count_kind(query),
7161 expected,
7162 "populated={populated:?} query={query:?} \
7163 must count {expected}",
7164 );
7165 }
7166 }
7167 }
7168
7169 /// DUPLICATES pin (count) — a slice with the same kind at
7170 /// MULTIPLE positions returns the exact match count (not `1`, not
7171 /// a de-duplicated `1`). A regression that (a) short-circuited on
7172 /// the first match (an `.iter().find(...)` yielding `0`/`1` sugar
7173 /// on the count arm), or (b) de-duplicated by kind (an erroneous
7174 /// `HashSet::insert`-gated walk that swallowed repeats) surfaces
7175 /// HERE at the cardinality boundary rather than silently at a
7176 /// downstream count-based coherence check.
7177 #[test]
7178 fn condition_slice_count_kind_counts_every_match_on_duplicates() {
7179 let slice = [
7180 Condition {
7181 kind: ConditionKind::ClosedLoopAuth,
7182 params: json!({ "probeImage": "first" }),
7183 },
7184 Condition {
7185 kind: ConditionKind::PromQL,
7186 params: json!({ "query": "up" }),
7187 },
7188 Condition {
7189 kind: ConditionKind::ClosedLoopAuth,
7190 params: json!({ "probeImage": "second" }),
7191 },
7192 ];
7193 assert_eq!(slice.count_kind(ConditionKind::ClosedLoopAuth), 2);
7194 assert_eq!(slice.count_kind(ConditionKind::PromQL), 1);
7195 for kind in ConditionKind::ALL {
7196 if matches!(kind, ConditionKind::ClosedLoopAuth | ConditionKind::PromQL) {
7197 continue;
7198 }
7199 assert_eq!(
7200 slice.count_kind(kind),
7201 0,
7202 "non-populated kind {kind:?} must count 0",
7203 );
7204 }
7205 }
7206
7207 /// SLICE-LEVEL DELEGATION pin (count ↔ iter) — the trait's
7208 /// default `count_kind` body equals `iter_kind(k).count()` at
7209 /// EVERY (populated arrangement, query) pair on
7210 /// `ConditionKind::ALL`. Turns the trait doc's composition-law
7211 /// note (`count_kind(k) == iter_kind(k).count()` by construction)
7212 /// into a first-class typed invariant: a future implementor that
7213 /// overrode the default `count_kind` body with a divergent walk
7214 /// shape (a stored-length cache that drifted, a `.step_by(2)`
7215 /// artefact from a copy-paste of `iter_kind`) surfaces HERE.
7216 #[test]
7217 fn condition_slice_count_kind_equals_iter_kind_count() {
7218 for pre_kind in ConditionKind::ALL {
7219 for post_kind in ConditionKind::ALL {
7220 let slice = [condition_with(pre_kind), condition_with(post_kind)];
7221 for query in ConditionKind::ALL {
7222 assert_eq!(
7223 slice.count_kind(query),
7224 slice.iter_kind(query).count(),
7225 "count/iter bridge drifted: pre={pre_kind:?} \
7226 post={post_kind:?} query={query:?}",
7227 );
7228 }
7229 }
7230 }
7231 }
7232
7233 /// SLICE-LEVEL DELEGATION pin (count ↔ has ↔ find) — the two
7234 /// composition laws
7235 /// `has_kind(k) == (count_kind(k) > 0)` and
7236 /// `find_kind(k).is_some() == (count_kind(k) > 0)`
7237 /// hold at every (populated, populated, query) triple on
7238 /// `ConditionKind::ALL`. Sweeps both refinement bridges at ONE
7239 /// site so a regression at the count primitive that drifted from
7240 /// the presence bit or the first-match probe surfaces HERE.
7241 #[test]
7242 fn condition_slice_has_and_find_equal_count_greater_than_zero() {
7243 for pre_kind in ConditionKind::ALL {
7244 for post_kind in ConditionKind::ALL {
7245 let slice = [condition_with(pre_kind), condition_with(post_kind)];
7246 for query in ConditionKind::ALL {
7247 let count = slice.count_kind(query);
7248 assert_eq!(
7249 slice.has_kind(query),
7250 count > 0,
7251 "has/count bridge drifted: pre={pre_kind:?} \
7252 post={post_kind:?} query={query:?}",
7253 );
7254 assert_eq!(
7255 slice.find_kind(query).is_some(),
7256 count > 0,
7257 "find/count bridge drifted: pre={pre_kind:?} \
7258 post={post_kind:?} query={query:?}",
7259 );
7260 }
7261 }
7262 }
7263 }
7264
7265 /// SUBSTRATE-DELEGATION pin (Boundary count-triad) — the three
7266 /// widened `count_*_kind` methods on [`Boundary`] delegate
7267 /// verbatim to [`ConditionSliceExt::count_kind`] on the
7268 /// underlying [`Vec<Condition>`] slices. The
7269 /// `count_condition_kind` union SUMS preconditions and
7270 /// postconditions (distinct from the `iter_condition_kind`
7271 /// [`Chain`](std::iter::Chain), `find_condition_kind`
7272 /// [`Option::or_else`], and `has_condition_kind` `||`
7273 /// compositions on the same axis). Sweep `ConditionKind::ALL ×
7274 /// ConditionKind::ALL × ConditionKind::ALL` so a regression that
7275 /// (a) inlined a divergent count at either half-slice arm, (b)
7276 /// subtracted rather than summed, or (c) collapsed the sum to
7277 /// [`std::cmp::max`] (silently narrowing the union to a max-per-
7278 /// side probe) surfaces HERE at the substrate boundary.
7279 #[test]
7280 fn boundary_count_condition_kind_triad_delegates_and_sums_slice_count_kind() {
7281 for pre_kind in ConditionKind::ALL {
7282 for post_kind in ConditionKind::ALL {
7283 let mut b = Boundary::default();
7284 b.preconditions.push(condition_with(pre_kind));
7285 b.postconditions.push(condition_with(post_kind));
7286 for query in ConditionKind::ALL {
7287 let via_pre = b.preconditions.count_kind(query);
7288 let via_post = b.postconditions.count_kind(query);
7289 assert_eq!(
7290 b.count_precondition_kind(query),
7291 via_pre,
7292 "boundary precondition count arm must delegate: \
7293 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7294 );
7295 assert_eq!(
7296 b.count_postcondition_kind(query),
7297 via_post,
7298 "boundary postcondition count arm must delegate: \
7299 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7300 );
7301 assert_eq!(
7302 b.count_condition_kind(query),
7303 via_pre + via_post,
7304 "boundary union count arm must SUM pre + post: \
7305 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7306 );
7307 }
7308 }
7309 }
7310 }
7311
7312 /// STRUCT-LEVEL DELEGATION pin (count ↔ iter on Boundary) — the
7313 /// three [`Boundary`] `count_*_kind` arms equal their widened
7314 /// peers' `.count()` projection at EVERY (pre-populated, post-
7315 /// populated, query) triple on `ConditionKind::ALL`. Re-anchors
7316 /// the composition-law pin
7317 /// `count_condition_kind == iter_condition_kind.count()` through
7318 /// the cardinality axis on the parent surface — a future consumer
7319 /// that reads `count_condition_kind(k)` as sugar for
7320 /// `iter_condition_kind(k).count()` stays typed against the SAME
7321 /// truth table on both the slice-level and struct-level layers.
7322 /// Also pins the sum-composition round-trip through the widened
7323 /// stream: the union arm's SUM equals the chained stream's count.
7324 #[test]
7325 fn boundary_count_triad_equals_iter_triad_count_projection() {
7326 for pre_kind in ConditionKind::ALL {
7327 for post_kind in ConditionKind::ALL {
7328 let mut b = Boundary::default();
7329 b.preconditions.push(condition_with(pre_kind));
7330 b.preconditions.push(condition_with(pre_kind));
7331 b.postconditions.push(condition_with(post_kind));
7332 for query in ConditionKind::ALL {
7333 assert_eq!(
7334 b.count_precondition_kind(query),
7335 b.iter_precondition_kind(query).count(),
7336 "precondition count/iter bridge drifted: \
7337 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7338 );
7339 assert_eq!(
7340 b.count_postcondition_kind(query),
7341 b.iter_postcondition_kind(query).count(),
7342 "postcondition count/iter bridge drifted: \
7343 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7344 );
7345 assert_eq!(
7346 b.count_condition_kind(query),
7347 b.iter_condition_kind(query).count(),
7348 "union count/iter bridge drifted: \
7349 pre={pre_kind:?} post={post_kind:?} query={query:?}",
7350 );
7351 }
7352 }
7353 }
7354 }
7355
7356 // ── ConditionSliceExt::distinct_kinds — closed-set-inversion axis ──
7357 //
7358 // The fifth refinement on the slice-level presence-probe algebra
7359 // inverts the axis: the four point-probe refinements (has, find,
7360 // iter, count) fix a [`ConditionKind`] and vary the return type;
7361 // `distinct_kinds` fixes the slice and varies over
7362 // [`ConditionKind::ALL`], returning the SET of present kinds
7363 // projected in [`ConditionKind::ALL`] order with no duplicates.
7364 // The composition-law arms in `assert_slice_refinement_composition_laws`
7365 // pin the fifth refinement against `has_kind` per variant AND
7366 // against the canonical ALL-order equality; the four dedicated
7367 // behavior tests below pin the returned VALUE per authored
7368 // arrangement (empty, single-element populated, dual-populated,
7369 // duplicate-populated).
7370
7371 /// EMPTY-SLICE pin — an empty slice returns an empty `Vec` on
7372 /// `distinct_kinds`, distinct from every populated arrangement.
7373 /// Locks the zero-element identity so a regression that (a)
7374 /// returned `ConditionKind::ALL.to_vec()` (the wrong direction of
7375 /// the closed-set walk), (b) returned a placeholder `[ProcessPhase]`
7376 /// vec (a copy-paste of the first-variant default in a `impl
7377 /// Default` for a hypothetical `KindSet` wrapper) surfaces HERE.
7378 #[test]
7379 fn condition_slice_distinct_kinds_returns_empty_vec_on_empty_slice() {
7380 let empty: &[Condition] = &[];
7381 assert_eq!(
7382 empty.distinct_kinds(),
7383 Vec::<ConditionKind>::new(),
7384 "empty slice must return empty distinct-kinds vec",
7385 );
7386 }
7387
7388 /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
7389 /// the addressed kind returns `[kind]` — a single-element vec
7390 /// containing exactly that kind. Sweep `ConditionKind::ALL` so a
7391 /// new variant added without a matching arm in the closed-set walk
7392 /// surfaces at rustc's exhaustiveness gate on the ALL literal
7393 /// (arity forced by `[Self; 8]`) rather than as a silent false-
7394 /// negative at every downstream `distinct_condition_kinds`
7395 /// callsite. Locks the closed-set-inversion probe body against a
7396 /// regression that (a) always returned `[ProcessPhase]` regardless
7397 /// of the actual kind, (b) collapsed `distinct_kinds` to
7398 /// `iter_kind(<first ALL variant>).map(|c| c.kind).collect()`
7399 /// (silently filtering to only ProcessPhase matches).
7400 #[test]
7401 fn condition_slice_distinct_kinds_returns_single_element_vec_per_variant() {
7402 for populated in ConditionKind::ALL {
7403 let slice = [condition_with(populated)];
7404 assert_eq!(
7405 slice.distinct_kinds(),
7406 vec![populated],
7407 "single-populated slice must return exactly [{populated:?}] on distinct_kinds",
7408 );
7409 }
7410 }
7411
7412 /// DEDUP pin — a slice with the SAME kind at multiple positions
7413 /// (three interleaved with distinct kinds) returns a distinct-set
7414 /// containing that kind exactly ONCE. The closed-set-inversion
7415 /// projection collapses multiplicity — a caller that needs the
7416 /// per-kind cardinality reaches for `count_kind`; this refinement
7417 /// returns the PRESENCE set. A regression that (a) omitted the
7418 /// dedup and returned `[ClosedLoopAuth, PromQL, ClosedLoopAuth,
7419 /// PromQL, ClosedLoopAuth]` (byte-identical to
7420 /// `slice.iter().map(|c| c.kind).collect()` — the wrong closed-
7421 /// set walk direction), (b) counted every duplicate as a distinct
7422 /// entry via a `.collect::<HashSet<_>>()` without canonicalizing
7423 /// order surfaces HERE.
7424 #[test]
7425 fn condition_slice_distinct_kinds_deduplicates_and_yields_canonical_all_order() {
7426 let interleaved = [
7427 Condition {
7428 kind: ConditionKind::ClosedLoopAuth,
7429 params: json!({ "probeImage": "first" }),
7430 },
7431 Condition {
7432 kind: ConditionKind::PromQL,
7433 params: json!({ "query": "up" }),
7434 },
7435 Condition {
7436 kind: ConditionKind::ClosedLoopAuth,
7437 params: json!({ "probeImage": "second" }),
7438 },
7439 Condition {
7440 kind: ConditionKind::PromQL,
7441 params: json!({ "query": "healthy" }),
7442 },
7443 Condition {
7444 kind: ConditionKind::ClosedLoopAuth,
7445 params: json!({ "probeImage": "third" }),
7446 },
7447 ];
7448 // Canonical ConditionKind::ALL order: PromQL is at position 3,
7449 // ClosedLoopAuth at position 7 in the ALL array. So PromQL comes
7450 // FIRST in the distinct-set even though ClosedLoopAuth appears
7451 // FIRST in the slice — the closed-set-inversion walk is
7452 // ordered by ConditionKind::ALL, not by slice-encounter order.
7453 assert_eq!(
7454 interleaved.distinct_kinds(),
7455 vec![ConditionKind::PromQL, ConditionKind::ClosedLoopAuth],
7456 "interleaved-duplicate slice must dedup AND order by ConditionKind::ALL, not by slice-encounter order",
7457 );
7458 }
7459
7460 /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7461 /// variant returns `ConditionKind::ALL.to_vec()` on `distinct_kinds`.
7462 /// The closed-set-inversion probe covers the full closed set at ONE
7463 /// call site — a regression that missed one variant in the walk
7464 /// (skipping the FIRST or LAST `ALL` entry via a `[1..]` or
7465 /// `[..ALL.len() - 1]` slice bug in the closed-set walk) surfaces
7466 /// HERE.
7467 #[test]
7468 fn condition_slice_distinct_kinds_covers_full_closed_set_on_saturated_slice() {
7469 let saturated: Vec<Condition> =
7470 ConditionKind::ALL.into_iter().map(condition_with).collect();
7471 assert_eq!(
7472 saturated.as_slice().distinct_kinds(),
7473 ConditionKind::ALL.to_vec(),
7474 "slice containing every ConditionKind must return ConditionKind::ALL as its distinct-set",
7475 );
7476 }
7477
7478 // ── distinct_kind_count — slice-level scalar-cardinality pins ──────
7479 //
7480 // The trait-level scalar-cardinality projection of the closed-set-
7481 // inversion widened primitive: `distinct_kind_count()` collapses
7482 // `distinct_kinds()` to its cardinality without materializing the
7483 // intermediate `Vec<ConditionKind>`. Composition law
7484 // `distinct_kind_count() == distinct_kinds().len()` pinned as the
7485 // sixth arm of the substrate testkit primitive
7486 // [`assert_slice_refinement_composition_laws`].
7487
7488 /// ZERO-ELEMENT pin — an empty slice returns `0` on
7489 /// `distinct_kind_count`, byte-for-byte with `distinct_kinds().len()`
7490 /// on the same slice. Locks the zero-element identity so a
7491 /// regression that (a) returned `ConditionKind::ALL.len()` (the
7492 /// wrong direction of the closed-set walk — every kind counted
7493 /// regardless of presence), (b) returned a placeholder `1` (a
7494 /// copy-paste of a single-slot factory's cardinality), or (c) drifted
7495 /// off `distinct_kinds().len()` surfaces HERE.
7496 #[test]
7497 fn condition_slice_distinct_kind_count_returns_zero_on_empty_slice() {
7498 let empty: &[Condition] = &[];
7499 assert_eq!(
7500 empty.distinct_kind_count(),
7501 0,
7502 "empty slice must return 0 on distinct_kind_count",
7503 );
7504 assert_eq!(
7505 empty.distinct_kind_count(),
7506 empty.distinct_kinds().len(),
7507 "empty slice distinct_kind_count must equal distinct_kinds().len()",
7508 );
7509 }
7510
7511 /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
7512 /// the addressed kind returns `1` on `distinct_kind_count` — the
7513 /// single-slot diagonal cardinality. Sweep [`ConditionKind::ALL`]
7514 /// so a regression that (a) always returned `0` regardless of the
7515 /// actual kind, (b) always returned `ConditionKind::ALL.len()`
7516 /// (missed the `filter` step), or (c) collapsed the walk to a
7517 /// single fixed variant surfaces HERE.
7518 #[test]
7519 fn condition_slice_distinct_kind_count_returns_one_per_variant() {
7520 for populated in ConditionKind::ALL {
7521 let slice = [condition_with(populated)];
7522 assert_eq!(
7523 slice.distinct_kind_count(),
7524 1,
7525 "single-populated slice must return 1 on distinct_kind_count for {populated:?}",
7526 );
7527 assert_eq!(
7528 slice.distinct_kind_count(),
7529 slice.distinct_kinds().len(),
7530 "single-populated distinct_kind_count must equal distinct_kinds().len() for {populated:?}",
7531 );
7532 }
7533 }
7534
7535 /// DEDUP pin — a slice with the SAME kind at multiple positions
7536 /// (three interleaved with distinct kinds — two `PromQL`, three
7537 /// `ClosedLoopAuth`) returns `2` on `distinct_kind_count` (the
7538 /// scalar cardinality of the DISTINCT presence set, byte-for-byte
7539 /// with `distinct_kinds().len()` on the same slice). Locks the
7540 /// closed-set projection against a regression that (a) counted
7541 /// every occurrence (returning `5` — byte-identical to
7542 /// `slice.len()`), (b) omitted the dedup and returned `5` via
7543 /// `.iter().map(|c| c.kind).count()`.
7544 #[test]
7545 fn condition_slice_distinct_kind_count_dedups_across_duplicates() {
7546 let interleaved = [
7547 Condition {
7548 kind: ConditionKind::ClosedLoopAuth,
7549 params: json!({ "probeImage": "first" }),
7550 },
7551 Condition {
7552 kind: ConditionKind::PromQL,
7553 params: json!({ "query": "up" }),
7554 },
7555 Condition {
7556 kind: ConditionKind::ClosedLoopAuth,
7557 params: json!({ "probeImage": "second" }),
7558 },
7559 Condition {
7560 kind: ConditionKind::PromQL,
7561 params: json!({ "query": "healthy" }),
7562 },
7563 Condition {
7564 kind: ConditionKind::ClosedLoopAuth,
7565 params: json!({ "probeImage": "third" }),
7566 },
7567 ];
7568 assert_eq!(
7569 interleaved.distinct_kind_count(),
7570 2,
7571 "interleaved-duplicate slice must return 2 on distinct_kind_count (PromQL + ClosedLoopAuth)",
7572 );
7573 assert_eq!(
7574 interleaved.distinct_kind_count(),
7575 interleaved.distinct_kinds().len(),
7576 "interleaved-duplicate distinct_kind_count must equal distinct_kinds().len()",
7577 );
7578 }
7579
7580 /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7581 /// variant returns `ConditionKind::ALL.len()` on `distinct_kind_count`.
7582 /// The scalar cardinality projection covers the full closed set at
7583 /// ONE call site — a regression that missed one variant in the walk
7584 /// (skipping the FIRST or LAST `ALL` entry via a `[1..]` or
7585 /// `[..ALL.len() - 1]` slice bug in the closed-set walk) surfaces
7586 /// HERE.
7587 #[test]
7588 fn condition_slice_distinct_kind_count_covers_full_closed_set_on_saturated_slice() {
7589 let saturated: Vec<Condition> =
7590 ConditionKind::ALL.into_iter().map(condition_with).collect();
7591 assert_eq!(
7592 saturated.as_slice().distinct_kind_count(),
7593 ConditionKind::ALL.len(),
7594 "slice containing every ConditionKind must return ConditionKind::ALL.len() on distinct_kind_count",
7595 );
7596 assert_eq!(
7597 saturated.as_slice().distinct_kind_count(),
7598 saturated.as_slice().distinct_kinds().len(),
7599 "saturated distinct_kind_count must equal distinct_kinds().len()",
7600 );
7601 }
7602
7603 // ── ConditionSliceExt::missing_kinds — closed-set-complement axis ──
7604 //
7605 // The complement peer of `distinct_kinds` on the closed-set-
7606 // inversion axis: `missing_kinds` returns the SET of kinds that
7607 // do NOT appear in the slice, in canonical [`ConditionKind::ALL`]
7608 // order. The four tests below pin each authored arrangement's
7609 // returned VALUE (empty, single-populated, saturated, interleaved-
7610 // duplicate); the composition-law arms in
7611 // `assert_slice_refinement_composition_laws` pin the closed-set-
7612 // partition invariants against `distinct_kinds` and `has_kind`.
7613
7614 /// EMPTY-SLICE pin — an empty slice returns
7615 /// `ConditionKind::ALL.to_vec()` on `missing_kinds` (every kind is
7616 /// missing). Locks the maximum-cardinality identity on the
7617 /// complement side, byte-for-byte dual to the empty-slice arm of
7618 /// `distinct_kinds` (which returns an empty vec). A regression that
7619 /// returned an empty vec (forgot the negation) or a placeholder
7620 /// `[ProcessPhase]` (a copy-paste of the first-variant default)
7621 /// surfaces HERE.
7622 #[test]
7623 fn condition_slice_missing_kinds_returns_full_closed_set_on_empty_slice() {
7624 let empty: &[Condition] = &[];
7625 assert_eq!(
7626 empty.missing_kinds(),
7627 ConditionKind::ALL.to_vec(),
7628 "empty slice must return ConditionKind::ALL on missing_kinds (every kind is missing)",
7629 );
7630 }
7631
7632 /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
7633 /// the addressed kind returns `ConditionKind::ALL` MINUS that kind
7634 /// on `missing_kinds`. Sweep [`ConditionKind::ALL`] so a regression
7635 /// that (a) returned an empty vec regardless of the kind, (b)
7636 /// returned the full ALL vec (forgot to filter), or (c) inverted
7637 /// the negation and returned only the addressed kind surfaces HERE.
7638 #[test]
7639 fn condition_slice_missing_kinds_returns_all_minus_populated_kind() {
7640 for populated in ConditionKind::ALL {
7641 let slice = [condition_with(populated)];
7642 let expected: Vec<_> = ConditionKind::ALL
7643 .into_iter()
7644 .filter(|k| *k != populated)
7645 .collect();
7646 assert_eq!(
7647 slice.missing_kinds(),
7648 expected,
7649 "single-populated slice must return ConditionKind::ALL minus {populated:?} on missing_kinds",
7650 );
7651 }
7652 }
7653
7654 /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7655 /// variant returns an empty vec on `missing_kinds` (no kind is
7656 /// missing). Dual of the empty-slice arm above; a regression that
7657 /// returned the full ALL vec regardless of population or inverted
7658 /// the presence direction surfaces HERE.
7659 #[test]
7660 fn condition_slice_missing_kinds_returns_empty_vec_on_saturated_slice() {
7661 let saturated: Vec<Condition> =
7662 ConditionKind::ALL.into_iter().map(condition_with).collect();
7663 assert_eq!(
7664 saturated.as_slice().missing_kinds(),
7665 Vec::<ConditionKind>::new(),
7666 "slice containing every ConditionKind must return empty vec on missing_kinds",
7667 );
7668 }
7669
7670 /// DEDUP pin — a slice with the SAME kind at multiple positions
7671 /// (three ClosedLoopAuth, two PromQL, none of the other six)
7672 /// returns those SIX absent kinds on `missing_kinds`, in canonical
7673 /// [`ConditionKind::ALL`] order — multiplicity on the present side
7674 /// is irrelevant to the complement. A regression that (a) counted
7675 /// duplicates as decreasing the missing set (a `saturating_sub`
7676 /// bug in a cardinality-tracking override), (b) yielded the
7677 /// missing set in slice-encounter order (which is undefined when
7678 /// no positions carry the missing kind — a subtle failure mode
7679 /// that must yield the ALL-ordered subsequence regardless)
7680 /// surfaces HERE.
7681 #[test]
7682 fn condition_slice_missing_kinds_yields_canonical_all_order_on_duplicates() {
7683 let interleaved = [
7684 Condition {
7685 kind: ConditionKind::ClosedLoopAuth,
7686 params: json!({ "probeImage": "first" }),
7687 },
7688 Condition {
7689 kind: ConditionKind::PromQL,
7690 params: json!({ "query": "up" }),
7691 },
7692 Condition {
7693 kind: ConditionKind::ClosedLoopAuth,
7694 params: json!({ "probeImage": "second" }),
7695 },
7696 Condition {
7697 kind: ConditionKind::PromQL,
7698 params: json!({ "query": "healthy" }),
7699 },
7700 Condition {
7701 kind: ConditionKind::ClosedLoopAuth,
7702 params: json!({ "probeImage": "third" }),
7703 },
7704 ];
7705 let expected: Vec<_> = ConditionKind::ALL
7706 .into_iter()
7707 .filter(|k| *k != ConditionKind::PromQL && *k != ConditionKind::ClosedLoopAuth)
7708 .collect();
7709 assert_eq!(
7710 interleaved.missing_kinds(),
7711 expected,
7712 "interleaved-duplicate slice must return canonical ALL-ordered complement of {{PromQL, ClosedLoopAuth}}",
7713 );
7714 }
7715
7716 // ── ConditionSliceExt::missing_kind_count — scalar cardinality pins ─
7717 //
7718 // Scalar-cardinality peer of the closed-set-complement widened
7719 // primitive `missing_kinds`: `missing_kind_count()` collapses the
7720 // set to its cardinality without allocating. The composition law
7721 // `missing_kind_count() == missing_kinds().len()` is pinned as the
7722 // scalar-cardinality-complement arm of
7723 // `assert_slice_refinement_composition_laws`. The three tests below
7724 // pin each authored arrangement's returned VALUE (empty, single-
7725 // populated, saturated) directly against `missing_kinds().len()`.
7726
7727 /// EMPTY-SLICE pin — an empty slice returns
7728 /// `ConditionKind::ALL.len()` on `missing_kind_count`, byte-for-byte
7729 /// with `missing_kinds().len()`. Locks the maximum-cardinality
7730 /// identity on the complement side; dual of the empty-slice arm on
7731 /// `distinct_kind_count` which returns `0`. A regression that
7732 /// forgot the negation, returned `0` (the distinct-kind-count
7733 /// identity on empty), or returned the wrong constant surfaces
7734 /// HERE.
7735 #[test]
7736 fn condition_slice_missing_kind_count_returns_full_closed_set_on_empty_slice() {
7737 let empty: &[Condition] = &[];
7738 assert_eq!(
7739 empty.missing_kind_count(),
7740 ConditionKind::ALL.len(),
7741 "empty slice must return ConditionKind::ALL.len() on missing_kind_count",
7742 );
7743 assert_eq!(
7744 empty.missing_kind_count(),
7745 empty.missing_kinds().len(),
7746 "empty slice missing_kind_count must equal missing_kinds().len()",
7747 );
7748 }
7749
7750 /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
7751 /// the addressed kind returns `ConditionKind::ALL.len() - 1` on
7752 /// `missing_kind_count` (every OTHER kind is missing). Sweep
7753 /// [`ConditionKind::ALL`] so a regression that returned `0` (forgot
7754 /// to negate), `ConditionKind::ALL.len()` (forgot the populated
7755 /// kind), or a per-kind constant surfaces HERE.
7756 #[test]
7757 fn condition_slice_missing_kind_count_returns_all_minus_one_per_variant() {
7758 for populated in ConditionKind::ALL {
7759 let slice = [condition_with(populated)];
7760 assert_eq!(
7761 slice.missing_kind_count(),
7762 ConditionKind::ALL.len() - 1,
7763 "single-populated slice must return ConditionKind::ALL.len() - 1 on missing_kind_count for {populated:?}",
7764 );
7765 assert_eq!(
7766 slice.missing_kind_count(),
7767 slice.missing_kinds().len(),
7768 "single-populated missing_kind_count must equal missing_kinds().len() for {populated:?}",
7769 );
7770 }
7771 }
7772
7773 /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7774 /// variant returns `0` on `missing_kind_count` (no kind is missing).
7775 /// Dual of the empty-slice arm above; a regression that returned
7776 /// `ConditionKind::ALL.len()` regardless of population or inverted
7777 /// the presence direction surfaces HERE.
7778 #[test]
7779 fn condition_slice_missing_kind_count_returns_zero_on_saturated_slice() {
7780 let saturated: Vec<Condition> =
7781 ConditionKind::ALL.into_iter().map(condition_with).collect();
7782 assert_eq!(
7783 saturated.as_slice().missing_kind_count(),
7784 0,
7785 "slice containing every ConditionKind must return 0 on missing_kind_count",
7786 );
7787 assert_eq!(
7788 saturated.as_slice().missing_kind_count(),
7789 saturated.as_slice().missing_kinds().len(),
7790 "saturated missing_kind_count must equal missing_kinds().len()",
7791 );
7792 }
7793
7794 // ── ConditionSliceExt::is_kind_saturated — Boolean saturation pins ─
7795 //
7796 // Short-circuiting Boolean saturation-endpoint peer of the closed-set-
7797 // complement widened + scalar primitives: `is_kind_saturated()`
7798 // returns `true` iff every ConditionKind::ALL variant appears at
7799 // least once in the slice, WITHOUT allocating `missing_kinds` or
7800 // walking every entry to build `missing_kind_count`. The composition
7801 // laws `is_kind_saturated() == (missing_kind_count() == 0)` and
7802 // `is_kind_saturated() == missing_kinds().is_empty()` are pinned as
7803 // the saturation-endpoint arm of
7804 // `assert_slice_refinement_composition_laws`. Byte-for-byte peer of
7805 // `crate::tagged_union::TaggedUnion::is_saturated` one struct-layer
7806 // up under the SAME `<CLOSED_SET>::ALL.iter().all(has)` short-
7807 // circuit walk shape.
7808
7809 /// EMPTY-SLICE pin — an empty slice returns `false` on
7810 /// `is_kind_saturated` (every kind is missing).
7811 #[test]
7812 fn condition_slice_is_kind_saturated_returns_false_on_empty_slice() {
7813 let empty: &[Condition] = &[];
7814 assert!(
7815 !empty.is_kind_saturated(),
7816 "empty slice must return false on is_kind_saturated",
7817 );
7818 assert_eq!(
7819 empty.is_kind_saturated(),
7820 empty.missing_kind_count() == 0,
7821 "empty is_kind_saturated must equal (missing_kind_count() == 0)",
7822 );
7823 }
7824
7825 /// SINGLE-KIND pin — a slice populating exactly one variant returns
7826 /// `false` on any [`ConditionKind::ALL`] closed set with `N ≥ 2`
7827 /// (the other `N - 1` variants are missing).
7828 #[test]
7829 fn condition_slice_is_kind_saturated_returns_false_on_single_kind_slice() {
7830 assert!(
7831 ConditionKind::ALL.len() >= 2,
7832 "test assumes ConditionKind::ALL has ≥ 2 variants",
7833 );
7834 for populated in ConditionKind::ALL {
7835 let slice = [condition_with(populated)];
7836 assert!(
7837 !slice.is_kind_saturated(),
7838 "single-populated slice with {populated:?} must return false on is_kind_saturated",
7839 );
7840 assert_eq!(
7841 slice.is_kind_saturated(),
7842 slice.missing_kind_count() == 0,
7843 "single-populated is_kind_saturated must equal (missing_kind_count() == 0) for {populated:?}",
7844 );
7845 }
7846 }
7847
7848 /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
7849 /// variant returns `true` on `is_kind_saturated` — the SOLE arm
7850 /// where the primitive returns `true`.
7851 #[test]
7852 fn condition_slice_is_kind_saturated_returns_true_on_saturated_slice() {
7853 let saturated: Vec<Condition> =
7854 ConditionKind::ALL.into_iter().map(condition_with).collect();
7855 assert!(
7856 saturated.as_slice().is_kind_saturated(),
7857 "slice containing every ConditionKind must return true on is_kind_saturated",
7858 );
7859 assert_eq!(
7860 saturated.as_slice().is_kind_saturated(),
7861 saturated.as_slice().missing_kind_count() == 0,
7862 "saturated is_kind_saturated must equal (missing_kind_count() == 0)",
7863 );
7864 assert_eq!(
7865 saturated.as_slice().is_kind_saturated(),
7866 saturated.as_slice().missing_kinds().is_empty(),
7867 "saturated is_kind_saturated must equal missing_kinds().is_empty()",
7868 );
7869 }
7870
7871 /// DUPLICATE-COVERAGE pin — a slice that carries every
7872 /// [`ConditionKind`] variant multiple times still returns `true`
7873 /// (multiplicity is irrelevant to the saturation predicate on the
7874 /// closed-set-inversion axis).
7875 #[test]
7876 fn condition_slice_is_kind_saturated_ignores_multiplicity() {
7877 let mut doubled: Vec<Condition> = Vec::new();
7878 for k in ConditionKind::ALL {
7879 doubled.push(condition_with(k));
7880 doubled.push(condition_with(k));
7881 }
7882 assert!(
7883 doubled.as_slice().is_kind_saturated(),
7884 "slice carrying every ConditionKind twice must return true on is_kind_saturated",
7885 );
7886 }
7887
7888 // ── ConditionSliceExt::has_any_distinct_kind — at-least-one halfspace pins ──
7889 //
7890 // Boolean at-least-one halfspace peer of `has_any_missing_kind` on
7891 // the closed-set-inversion axis: `has_any_distinct_kind()` returns
7892 // `true` iff AT LEAST ONE `ConditionKind::ALL` variant appears at
7893 // least once in the slice, via a SHORT-CIRCUITING closed-set walk
7894 // `ConditionKind::ALL.iter().copied().any(|k| self.has_kind(k))`
7895 // that returns `true` at the FIRST populated kind. The composition
7896 // laws `has_any_distinct_kind() == (distinct_kind_count() > 0)`,
7897 // `has_any_distinct_kind() == !distinct_kinds().is_empty()`, and
7898 // `has_any_distinct_kind() == first_distinct_kind().is_some()` are
7899 // pinned as the at-least-one halfspace arm of
7900 // `assert_slice_refinement_composition_laws` on the closed-set-
7901 // inversion axis. Byte-for-byte peer of
7902 // `crate::tagged_union::TaggedUnion::has_any_populated_kind` one
7903 // struct-layer up under the SAME `any(has)` short-circuit shape.
7904
7905 /// EMPTY-SLICE pin — an empty slice returns `false` on
7906 /// `has_any_distinct_kind` (no kind is present) — the SOLE arm
7907 /// where the primitive returns `false`. Dual of the empty-slice
7908 /// arm on `has_any_missing_kind` (which returns `true`).
7909 #[test]
7910 fn condition_slice_has_any_distinct_kind_returns_false_on_empty_slice() {
7911 let empty: &[Condition] = &[];
7912 assert!(
7913 !empty.has_any_distinct_kind(),
7914 "empty slice must return false on has_any_distinct_kind",
7915 );
7916 assert_eq!(
7917 empty.has_any_distinct_kind(),
7918 empty.distinct_kind_count() > 0,
7919 "empty has_any_distinct_kind must equal (distinct_kind_count() > 0)",
7920 );
7921 assert_eq!(
7922 empty.has_any_distinct_kind(),
7923 !empty.distinct_kinds().is_empty(),
7924 "empty has_any_distinct_kind must equal !distinct_kinds().is_empty()",
7925 );
7926 assert_eq!(
7927 empty.has_any_distinct_kind(),
7928 empty.first_distinct_kind().is_some(),
7929 "empty has_any_distinct_kind must equal first_distinct_kind().is_some()",
7930 );
7931 }
7932
7933 /// SINGLE-KIND pin — a slice populating exactly one variant
7934 /// returns `true` on `has_any_distinct_kind` for every
7935 /// [`ConditionKind`] (a single element contributes one distinct
7936 /// kind, ≥ 1). Also pins the composition law
7937 /// `has_any_distinct_kind() == (distinct_kind_count() > 0)` at
7938 /// the single-populated arm.
7939 #[test]
7940 fn condition_slice_has_any_distinct_kind_returns_true_on_single_kind_slice() {
7941 for populated in ConditionKind::ALL {
7942 let slice = [condition_with(populated)];
7943 assert!(
7944 slice.has_any_distinct_kind(),
7945 "single-populated slice with {populated:?} must return true on has_any_distinct_kind",
7946 );
7947 assert_eq!(
7948 slice.has_any_distinct_kind(),
7949 slice.distinct_kind_count() > 0,
7950 "single-populated has_any_distinct_kind must equal (distinct_kind_count() > 0) for {populated:?}",
7951 );
7952 }
7953 }
7954
7955 /// FULL-COVERAGE pin — a slice that carries every
7956 /// [`ConditionKind`] variant returns `true` on
7957 /// `has_any_distinct_kind`. Dual of the FULL-COVERAGE arm on
7958 /// `has_any_missing_kind` (which returns `false`) — the two
7959 /// Booleans DISAGREE on the saturated arm.
7960 #[test]
7961 fn condition_slice_has_any_distinct_kind_returns_true_on_saturated_slice() {
7962 let saturated: Vec<Condition> =
7963 ConditionKind::ALL.into_iter().map(condition_with).collect();
7964 assert!(
7965 saturated.as_slice().has_any_distinct_kind(),
7966 "slice containing every ConditionKind must return true on has_any_distinct_kind",
7967 );
7968 assert_eq!(
7969 saturated.as_slice().has_any_distinct_kind(),
7970 !saturated.as_slice().distinct_kinds().is_empty(),
7971 "saturated has_any_distinct_kind must equal !distinct_kinds().is_empty()",
7972 );
7973 }
7974
7975 /// DUPLICATE-COVERAGE pin — a slice that carries the SAME
7976 /// [`ConditionKind`] multiple times still returns `true`
7977 /// (multiplicity is irrelevant to the at-least-one halfspace
7978 /// predicate on the closed-set-inversion axis, byte-for-byte peer
7979 /// of the closed-set-complement halfspace arm).
7980 #[test]
7981 fn condition_slice_has_any_distinct_kind_ignores_multiplicity() {
7982 for k in ConditionKind::ALL {
7983 let doubled: Vec<Condition> = vec![condition_with(k), condition_with(k)];
7984 assert!(
7985 doubled.as_slice().has_any_distinct_kind(),
7986 "slice carrying {k:?} twice must return true on has_any_distinct_kind",
7987 );
7988 }
7989 }
7990
7991 // ── ConditionSliceExt::has_unique_distinct_kind — cardinality-mid-endpoint pins ──
7992 //
7993 // Boolean cardinality-mid-endpoint peer of `has_any_distinct_kind`
7994 // on the closed-set-inversion axis: returns `true` iff EXACTLY
7995 // ONE `ConditionKind::ALL` variant appears at least once in the
7996 // slice. Body folds through the load-bearing
7997 // `iter_distinct_kinds` iterator under a two-step short-circuit;
7998 // strictly cheaper than `distinct_kind_count() == 1` (which walks
7999 // every slot) and `distinct_kinds().len() == 1` (which allocates
8000 // the Vec) on every arm with ≥ 2 distinct kinds. The composition
8001 // laws `has_unique_distinct_kind() == (distinct_kind_count() == 1)`
8002 // and `has_unique_distinct_kind() == (distinct_kinds().len() == 1)`
8003 // are pinned as the cardinality-mid-endpoint arm of
8004 // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8005 // of `crate::tagged_union::TaggedUnion::has_unique_populated_kind`
8006 // one struct-layer up under the SAME two-step short-circuit walk
8007 // shape.
8008
8009 /// EMPTY-SLICE pin — an empty slice returns `false` on
8010 /// `has_unique_distinct_kind` (zero distinct, not exactly 1).
8011 /// Also pins the composition law `has_unique_distinct_kind() ==
8012 /// (distinct_kind_count() == 1)` at zero-distinct.
8013 #[test]
8014 fn condition_slice_has_unique_distinct_kind_returns_false_on_empty_slice() {
8015 let empty: &[Condition] = &[];
8016 assert!(
8017 !empty.has_unique_distinct_kind(),
8018 "empty slice must return false on has_unique_distinct_kind (0 distinct, not exactly 1)",
8019 );
8020 assert_eq!(
8021 empty.has_unique_distinct_kind(),
8022 empty.distinct_kind_count() == 1,
8023 "empty has_unique_distinct_kind must equal (distinct_kind_count() == 1)",
8024 );
8025 }
8026
8027 /// SINGLE-KIND pin — a slice populating exactly one variant
8028 /// returns `true` on `has_unique_distinct_kind` for every
8029 /// [`ConditionKind`] — the SOLE arrangement where the primitive
8030 /// returns `true` on any `N ≥ 2` closed set (the singleton-
8031 /// coverage arm). Also pins the widened composition law
8032 /// `has_unique_distinct_kind() == (distinct_kinds().len() == 1)`.
8033 #[test]
8034 fn condition_slice_has_unique_distinct_kind_returns_true_on_single_kind_slice() {
8035 for populated in ConditionKind::ALL {
8036 let slice = [condition_with(populated)];
8037 assert!(
8038 slice.has_unique_distinct_kind(),
8039 "single-populated slice with {populated:?} must return true on has_unique_distinct_kind",
8040 );
8041 assert_eq!(
8042 slice.has_unique_distinct_kind(),
8043 slice.distinct_kind_count() == 1,
8044 "single-populated has_unique_distinct_kind must equal (distinct_kind_count() == 1) for {populated:?}",
8045 );
8046 assert_eq!(
8047 slice.has_unique_distinct_kind(),
8048 slice.distinct_kinds().len() == 1,
8049 "single-populated has_unique_distinct_kind must equal (distinct_kinds().len() == 1) for {populated:?}",
8050 );
8051 assert_eq!(
8052 slice.first_distinct_kind(),
8053 Some(populated),
8054 "single-populated first_distinct_kind must name the SOLE covered kind for {populated:?}",
8055 );
8056 }
8057 }
8058
8059 /// SATURATED pin — a slice carrying every [`ConditionKind`]
8060 /// returns `false` on `has_unique_distinct_kind` on any `N ≥ 2`
8061 /// closed set (`N` distinct, not exactly 1). Dual of the
8062 /// SATURATED arm on `has_any_distinct_kind` which returns `true`
8063 /// — the two Booleans DISAGREE on the saturated arm.
8064 #[test]
8065 fn condition_slice_has_unique_distinct_kind_returns_false_on_saturated_slice() {
8066 assert!(
8067 ConditionKind::ALL.len() >= 2,
8068 "test assumes ConditionKind::ALL has ≥ 2 variants",
8069 );
8070 let saturated: Vec<Condition> =
8071 ConditionKind::ALL.into_iter().map(condition_with).collect();
8072 assert!(
8073 !saturated.as_slice().has_unique_distinct_kind(),
8074 "saturated slice must return false on has_unique_distinct_kind ({} distinct, not exactly 1)",
8075 ConditionKind::ALL.len(),
8076 );
8077 assert_eq!(
8078 saturated.as_slice().has_unique_distinct_kind(),
8079 saturated.as_slice().distinct_kind_count() == 1,
8080 "saturated has_unique_distinct_kind must equal (distinct_kind_count() == 1)",
8081 );
8082 }
8083
8084 /// TWO-POPULATED pin — a slice carrying exactly two distinct
8085 /// [`ConditionKind`] variants returns `false` on
8086 /// `has_unique_distinct_kind` (2 distinct, not exactly 1). Pins
8087 /// the SECOND-slot short-circuit boundary — a regression that
8088 /// dropped the second-slot check (returning `true` on any
8089 /// at-least-one arm) surfaces HERE. Only meaningful on `N ≥ 2`
8090 /// closed sets.
8091 #[test]
8092 fn condition_slice_has_unique_distinct_kind_returns_false_on_two_populated_slice() {
8093 assert!(
8094 ConditionKind::ALL.len() >= 2,
8095 "test assumes ConditionKind::ALL has ≥ 2 variants",
8096 );
8097 for i in 0..ConditionKind::ALL.len() {
8098 for j in (i + 1)..ConditionKind::ALL.len() {
8099 let two_populated: Vec<Condition> = vec![
8100 condition_with(ConditionKind::ALL[i]),
8101 condition_with(ConditionKind::ALL[j]),
8102 ];
8103 let slice = two_populated.as_slice();
8104 assert!(
8105 !slice.has_unique_distinct_kind(),
8106 "two-populated slice (kinds at index {i} and {j}) must return false on has_unique_distinct_kind (2 distinct, not exactly 1)",
8107 );
8108 assert_eq!(
8109 slice.has_unique_distinct_kind(),
8110 slice.distinct_kind_count() == 1,
8111 "two-populated has_unique_distinct_kind must equal (distinct_kind_count() == 1) for kinds=({i}, {j})",
8112 );
8113 }
8114 }
8115 }
8116
8117 /// MULTIPLICITY pin — a slice carrying the SAME [`ConditionKind`]
8118 /// multiple times still returns `true` (multiplicity is
8119 /// irrelevant to the cardinality-mid-endpoint projection on the
8120 /// closed-set-inversion axis — one distinct kind regardless of
8121 /// repetition count, byte-for-byte peer of the at-least-one
8122 /// halfspace arm's multiplicity pin).
8123 #[test]
8124 fn condition_slice_has_unique_distinct_kind_ignores_multiplicity() {
8125 for k in ConditionKind::ALL {
8126 let doubled: Vec<Condition> = vec![condition_with(k), condition_with(k)];
8127 assert!(
8128 doubled.as_slice().has_unique_distinct_kind(),
8129 "slice carrying {k:?} twice must return true on has_unique_distinct_kind (still 1 distinct)",
8130 );
8131 let tripled: Vec<Condition> =
8132 vec![condition_with(k), condition_with(k), condition_with(k)];
8133 assert!(
8134 tripled.as_slice().has_unique_distinct_kind(),
8135 "slice carrying {k:?} three times must return true on has_unique_distinct_kind (still 1 distinct)",
8136 );
8137 }
8138 }
8139
8140 // ── ConditionSliceExt::has_any_missing_kind — at-least-one halfspace pins ──
8141 //
8142 // Boolean at-least-one halfspace peer of `is_kind_saturated`:
8143 // `has_any_missing_kind()` returns `true` iff AT LEAST ONE
8144 // `ConditionKind::ALL` variant appears zero times in the slice,
8145 // byte-for-byte with `!is_kind_saturated()` via the definitional
8146 // negation in the trait's default body. The composition laws
8147 // `has_any_missing_kind() == !is_kind_saturated()`,
8148 // `has_any_missing_kind() == (missing_kind_count() > 0)`, and
8149 // `has_any_missing_kind() == !missing_kinds().is_empty()` are
8150 // pinned as the at-least-one halfspace arm of
8151 // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8152 // of `crate::tagged_union::TaggedUnion::has_any_missing_kind` one
8153 // struct-layer up under the SAME `!is_saturated` definitional
8154 // negation shape.
8155
8156 /// EMPTY-SLICE pin — an empty slice returns `true` on
8157 /// `has_any_missing_kind` (every kind is missing, so at least one
8158 /// is). Dual of the empty-slice arm on `is_kind_saturated` (which
8159 /// returns `false`).
8160 #[test]
8161 fn condition_slice_has_any_missing_kind_returns_true_on_empty_slice() {
8162 let empty: &[Condition] = &[];
8163 assert!(
8164 empty.has_any_missing_kind(),
8165 "empty slice must return true on has_any_missing_kind",
8166 );
8167 assert_eq!(
8168 empty.has_any_missing_kind(),
8169 !empty.is_kind_saturated(),
8170 "empty has_any_missing_kind must equal !is_kind_saturated()",
8171 );
8172 assert_eq!(
8173 empty.has_any_missing_kind(),
8174 empty.missing_kind_count() > 0,
8175 "empty has_any_missing_kind must equal (missing_kind_count() > 0)",
8176 );
8177 }
8178
8179 /// SINGLE-KIND pin — a slice populating exactly one variant
8180 /// returns `true` on any `ConditionKind::ALL` closed set with
8181 /// `N ≥ 2` (the other `N - 1` variants are missing).
8182 #[test]
8183 fn condition_slice_has_any_missing_kind_returns_true_on_single_kind_slice() {
8184 assert!(
8185 ConditionKind::ALL.len() >= 2,
8186 "test assumes ConditionKind::ALL has ≥ 2 variants",
8187 );
8188 for populated in ConditionKind::ALL {
8189 let slice = [condition_with(populated)];
8190 assert!(
8191 slice.has_any_missing_kind(),
8192 "single-populated slice with {populated:?} must return true on has_any_missing_kind",
8193 );
8194 assert_eq!(
8195 slice.has_any_missing_kind(),
8196 !slice.is_kind_saturated(),
8197 "single-populated has_any_missing_kind must equal !is_kind_saturated() for {populated:?}",
8198 );
8199 }
8200 }
8201
8202 /// FULL-COVERAGE pin — a slice that carries every
8203 /// [`ConditionKind`] variant returns `false` on
8204 /// `has_any_missing_kind` — the SOLE arm where the primitive
8205 /// returns `false`, byte-for-byte peer of the SOLE arm on which
8206 /// `is_kind_saturated` returns `true`.
8207 #[test]
8208 fn condition_slice_has_any_missing_kind_returns_false_on_saturated_slice() {
8209 let saturated: Vec<Condition> =
8210 ConditionKind::ALL.into_iter().map(condition_with).collect();
8211 assert!(
8212 !saturated.as_slice().has_any_missing_kind(),
8213 "slice containing every ConditionKind must return false on has_any_missing_kind",
8214 );
8215 assert_eq!(
8216 saturated.as_slice().has_any_missing_kind(),
8217 !saturated.as_slice().is_kind_saturated(),
8218 "saturated has_any_missing_kind must equal !is_kind_saturated()",
8219 );
8220 assert_eq!(
8221 saturated.as_slice().has_any_missing_kind(),
8222 !saturated.as_slice().missing_kinds().is_empty(),
8223 "saturated has_any_missing_kind must equal !missing_kinds().is_empty()",
8224 );
8225 }
8226
8227 /// DUPLICATE-COVERAGE pin — a slice that carries every
8228 /// [`ConditionKind`] variant multiple times still returns `false`
8229 /// (multiplicity is irrelevant to the at-least-one halfspace
8230 /// predicate on the closed-set-complement axis, byte-for-byte peer
8231 /// of the saturation-predicate arm).
8232 #[test]
8233 fn condition_slice_has_any_missing_kind_ignores_multiplicity() {
8234 let mut doubled: Vec<Condition> = Vec::new();
8235 for k in ConditionKind::ALL {
8236 doubled.push(condition_with(k));
8237 doubled.push(condition_with(k));
8238 }
8239 assert!(
8240 !doubled.as_slice().has_any_missing_kind(),
8241 "slice carrying every ConditionKind twice must return false on has_any_missing_kind",
8242 );
8243 }
8244
8245 // ── ConditionSliceExt::has_unique_missing_kind — near-saturation-endpoint pins ─
8246 //
8247 // Boolean cardinality-mid-endpoint peer of `has_any_missing_kind`
8248 // on the closed-set-complement axis: `has_unique_missing_kind()`
8249 // returns `true` iff EXACTLY ONE ConditionKind::ALL variant
8250 // appears zero times in the slice. Default body is a two-step-
8251 // short-circuit walk over ConditionKind::ALL under a negated
8252 // `has_kind` predicate — pulls up to two hits off the filtered
8253 // iterator, returns `true` iff the first is Some and the second
8254 // is None. Short-circuits at the SECOND missing kind — strictly
8255 // cheaper than `missing_kind_count() == 1` (which walks every
8256 // slot) and `missing_kinds().len() == 1` (which allocates the
8257 // Vec) on every arm with ≥ 2 missing kinds. The composition laws
8258 // `has_unique_missing_kind() == (missing_kind_count() == 1)` and
8259 // `has_unique_missing_kind() == (missing_kinds().len() == 1)`
8260 // are pinned as the cardinality-mid-endpoint arm of
8261 // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8262 // of `crate::tagged_union::TaggedUnion::has_unique_missing_kind`
8263 // one struct-layer up under the SAME two-step short-circuit walk
8264 // shape.
8265
8266 /// EMPTY-SLICE pin — an empty slice returns `false` on
8267 /// `has_unique_missing_kind` on any `N ≥ 2` closed set (every
8268 /// kind is missing — the fully-missing endpoint, `N` missing not
8269 /// `1`).
8270 #[test]
8271 fn condition_slice_has_unique_missing_kind_returns_false_on_empty_slice() {
8272 assert!(
8273 ConditionKind::ALL.len() >= 2,
8274 "test assumes ConditionKind::ALL has ≥ 2 variants",
8275 );
8276 let empty: &[Condition] = &[];
8277 assert!(
8278 !empty.has_unique_missing_kind(),
8279 "empty slice must return false on has_unique_missing_kind (all N kinds missing, not exactly 1)",
8280 );
8281 assert_eq!(
8282 empty.has_unique_missing_kind(),
8283 empty.missing_kind_count() == 1,
8284 "empty has_unique_missing_kind must equal (missing_kind_count() == 1)",
8285 );
8286 }
8287
8288 /// SINGLE-KIND pin — a slice populating exactly one variant
8289 /// returns `false` on any `N ≥ 3` closed set (`N - 1 ≥ 2` kinds
8290 /// missing). On the degenerate `N == 2` closed set (which no
8291 /// production `ConditionKind` reaches; this workspace has
8292 /// `N == 8`) it would return `true`, so the pin gates on
8293 /// `N ≥ 3`.
8294 #[test]
8295 fn condition_slice_has_unique_missing_kind_returns_false_on_single_kind_slice() {
8296 if ConditionKind::ALL.len() < 3 {
8297 return;
8298 }
8299 for populated in ConditionKind::ALL {
8300 let slice = [condition_with(populated)];
8301 assert!(
8302 !slice.has_unique_missing_kind(),
8303 "single-populated slice with {populated:?} must return false on has_unique_missing_kind on N ≥ 3 closed sets ({} kinds missing, not exactly 1)",
8304 ConditionKind::ALL.len() - 1,
8305 );
8306 assert_eq!(
8307 slice.has_unique_missing_kind(),
8308 slice.missing_kind_count() == 1,
8309 "single-populated has_unique_missing_kind must equal (missing_kind_count() == 1) for {populated:?}",
8310 );
8311 }
8312 }
8313
8314 /// NEAR-SATURATION-ENDPOINT pin — a slice carrying every
8315 /// [`ConditionKind`] EXCEPT exactly one returns `true` on
8316 /// `has_unique_missing_kind`. Sweeps ConditionKind::ALL; each
8317 /// arrangement omits one variant and populates the other `N - 1`.
8318 /// This is the SOLE arrangement where the primitive returns
8319 /// `true`. Also pins the widened composition law
8320 /// `has_unique_missing_kind() == (missing_kinds().len() == 1)`.
8321 #[test]
8322 fn condition_slice_has_unique_missing_kind_returns_true_on_near_saturation_endpoint() {
8323 for omitted in ConditionKind::ALL {
8324 let near_saturated: Vec<Condition> = ConditionKind::ALL
8325 .into_iter()
8326 .filter(|k| *k != omitted)
8327 .map(condition_with)
8328 .collect();
8329 let slice = near_saturated.as_slice();
8330 assert!(
8331 slice.has_unique_missing_kind(),
8332 "near-saturation-endpoint slice (omitting {omitted:?}) must return true on has_unique_missing_kind",
8333 );
8334 assert_eq!(
8335 slice.has_unique_missing_kind(),
8336 slice.missing_kind_count() == 1,
8337 "near-saturation-endpoint has_unique_missing_kind must equal (missing_kind_count() == 1) for omitted={omitted:?}",
8338 );
8339 assert_eq!(
8340 slice.has_unique_missing_kind(),
8341 slice.missing_kinds().len() == 1,
8342 "near-saturation-endpoint has_unique_missing_kind must equal (missing_kinds().len() == 1) for omitted={omitted:?}",
8343 );
8344 assert_eq!(
8345 slice.first_missing_kind(),
8346 Some(omitted),
8347 "near-saturation-endpoint first_missing_kind must name the SOLE remaining hole for omitted={omitted:?}",
8348 );
8349 }
8350 }
8351
8352 /// SATURATED pin — a slice carrying every [`ConditionKind`]
8353 /// variant returns `false` on `has_unique_missing_kind` (zero
8354 /// missing, not exactly one). Dual of the SATURATED arm on
8355 /// `is_kind_saturated` which returns `true`. Also pins the
8356 /// composition law `has_unique_missing_kind() ==
8357 /// (missing_kind_count() == 1)` at zero-missing.
8358 #[test]
8359 fn condition_slice_has_unique_missing_kind_returns_false_on_saturated_slice() {
8360 let saturated: Vec<Condition> =
8361 ConditionKind::ALL.into_iter().map(condition_with).collect();
8362 assert!(
8363 !saturated.as_slice().has_unique_missing_kind(),
8364 "slice containing every ConditionKind must return false on has_unique_missing_kind (0 missing, not exactly 1)",
8365 );
8366 assert_eq!(
8367 saturated.as_slice().has_unique_missing_kind(),
8368 saturated.as_slice().missing_kind_count() == 1,
8369 "saturated has_unique_missing_kind must equal (missing_kind_count() == 1)",
8370 );
8371 }
8372
8373 /// TWO-MISSING pin — a slice populating exactly `N - 2` variants
8374 /// returns `false` on `has_unique_missing_kind` (2 missing, not
8375 /// exactly 1). Pins the SECOND-slot short-circuit boundary — a
8376 /// regression that dropped the second-slot check (returning `true`
8377 /// on any partial-populated arm) surfaces HERE. Only meaningful
8378 /// on `N ≥ 2` closed sets.
8379 #[test]
8380 fn condition_slice_has_unique_missing_kind_returns_false_on_two_missing_slice() {
8381 assert!(
8382 ConditionKind::ALL.len() >= 2,
8383 "test assumes ConditionKind::ALL has ≥ 2 variants",
8384 );
8385 for i in 0..ConditionKind::ALL.len() {
8386 for j in (i + 1)..ConditionKind::ALL.len() {
8387 let two_missing: Vec<Condition> = ConditionKind::ALL
8388 .into_iter()
8389 .enumerate()
8390 .filter(|(k, _)| *k != i && *k != j)
8391 .map(|(_, k)| condition_with(k))
8392 .collect();
8393 let slice = two_missing.as_slice();
8394 assert!(
8395 !slice.has_unique_missing_kind(),
8396 "two-missing slice (omitting index {i} and {j}) must return false on has_unique_missing_kind (2 missing, not exactly 1)",
8397 );
8398 assert_eq!(
8399 slice.has_unique_missing_kind(),
8400 slice.missing_kind_count() == 1,
8401 "two-missing has_unique_missing_kind must equal (missing_kind_count() == 1) for omitted=({i}, {j})",
8402 );
8403 }
8404 }
8405 }
8406
8407 /// MULTIPLICITY pin — a slice at the near-saturation-endpoint
8408 /// with each populated kind duplicated still returns `true`
8409 /// (multiplicity is irrelevant to the cardinality-mid-endpoint
8410 /// projection on the closed-set-complement axis, byte-for-byte
8411 /// peer of the saturation-predicate arm).
8412 #[test]
8413 fn condition_slice_has_unique_missing_kind_ignores_multiplicity() {
8414 for omitted in ConditionKind::ALL {
8415 let mut doubled: Vec<Condition> = Vec::new();
8416 for k in ConditionKind::ALL {
8417 if k != omitted {
8418 doubled.push(condition_with(k));
8419 doubled.push(condition_with(k));
8420 }
8421 }
8422 assert!(
8423 doubled.as_slice().has_unique_missing_kind(),
8424 "near-saturation-endpoint slice with each populated kind duplicated (omitting {omitted:?}) must return true on has_unique_missing_kind",
8425 );
8426 }
8427 }
8428
8429 // ── ConditionSliceExt::has_multiple_missing_kinds — many-arm pins ──
8430 //
8431 // Boolean cardinality "≥ 2" many-arm peer of
8432 // `has_unique_missing_kind` on the closed-set-complement axis:
8433 // `has_multiple_missing_kinds()` returns `true` iff AT LEAST TWO
8434 // `ConditionKind::ALL` variants appear zero times in the slice.
8435 // Third and final arm of the {0, 1, ≥2} trichotomy on the missing
8436 // axis at the slice level (0-arm: `is_kind_saturated`; 1-arm:
8437 // `has_unique_missing_kind`; ≥ 2-arm: this primitive). Body
8438 // short-circuits at the second missing kind — strictly cheaper
8439 // than `missing_kind_count() >= 2` (which walks every slot) and
8440 // `missing_kinds().len() >= 2` (which allocates the Vec) on every
8441 // arm with ≥ 2 missing kinds. The composition laws
8442 // `has_multiple_missing_kinds() == (missing_kind_count() >= 2)`
8443 // and `has_multiple_missing_kinds() == (missing_kinds().len() >= 2)`
8444 // are pinned as the cardinality-many-arm arm of
8445 // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8446 // of `crate::tagged_union::TaggedUnion::has_multiple_missing_kinds`
8447 // one struct-layer up under the SAME two-step short-circuit walk
8448 // shape.
8449
8450 /// EMPTY-SLICE pin — an empty slice returns `true` on
8451 /// `has_multiple_missing_kinds` on any `N ≥ 2` closed set (every
8452 /// kind is missing — the fully-missing endpoint, `N ≥ 2`
8453 /// missing).
8454 #[test]
8455 fn condition_slice_has_multiple_missing_kinds_returns_true_on_empty_slice() {
8456 assert!(
8457 ConditionKind::ALL.len() >= 2,
8458 "test assumes ConditionKind::ALL has ≥ 2 variants",
8459 );
8460 let empty: &[Condition] = &[];
8461 assert!(
8462 empty.has_multiple_missing_kinds(),
8463 "empty slice must return true on has_multiple_missing_kinds (all N ≥ 2 kinds missing)",
8464 );
8465 assert_eq!(
8466 empty.has_multiple_missing_kinds(),
8467 empty.missing_kind_count() >= 2,
8468 "empty has_multiple_missing_kinds must equal (missing_kind_count() >= 2)",
8469 );
8470 }
8471
8472 /// SINGLE-KIND pin — a slice populating exactly one variant
8473 /// returns `true` on any `N ≥ 3` closed set (`N - 1 ≥ 2` kinds
8474 /// missing). On the degenerate `N == 2` closed set (which no
8475 /// production `ConditionKind` reaches; this workspace has
8476 /// `N == 8`) it would return `false`, so the pin gates on
8477 /// `N ≥ 3`.
8478 #[test]
8479 fn condition_slice_has_multiple_missing_kinds_returns_true_on_single_kind_slice() {
8480 if ConditionKind::ALL.len() < 3 {
8481 return;
8482 }
8483 for populated in ConditionKind::ALL {
8484 let slice = [condition_with(populated)];
8485 assert!(
8486 slice.has_multiple_missing_kinds(),
8487 "single-populated slice with {populated:?} must return true on has_multiple_missing_kinds on N ≥ 3 closed sets ({} kinds missing, ≥ 2)",
8488 ConditionKind::ALL.len() - 1,
8489 );
8490 assert_eq!(
8491 slice.has_multiple_missing_kinds(),
8492 slice.missing_kind_count() >= 2,
8493 "single-populated has_multiple_missing_kinds must equal (missing_kind_count() >= 2) for {populated:?}",
8494 );
8495 }
8496 }
8497
8498 /// NEAR-SATURATION-ENDPOINT pin — a slice carrying every
8499 /// [`ConditionKind`] EXCEPT exactly one returns `false` on
8500 /// `has_multiple_missing_kinds` (exactly one missing, not ≥ 2).
8501 /// The SOLE-missing arrangement where the many-arm primitive
8502 /// returns `false` — the definitional boundary between the
8503 /// = 1 mid-endpoint and the ≥ 2 many-arm on the missing axis.
8504 /// Also pins the widened composition law
8505 /// `has_multiple_missing_kinds() == (missing_kinds().len() >= 2)`.
8506 #[test]
8507 fn condition_slice_has_multiple_missing_kinds_returns_false_on_near_saturation_endpoint() {
8508 for omitted in ConditionKind::ALL {
8509 let near_saturated: Vec<Condition> = ConditionKind::ALL
8510 .into_iter()
8511 .filter(|k| *k != omitted)
8512 .map(condition_with)
8513 .collect();
8514 let slice = near_saturated.as_slice();
8515 assert!(
8516 !slice.has_multiple_missing_kinds(),
8517 "near-saturation-endpoint slice (omitting {omitted:?}) must return false on has_multiple_missing_kinds (1 missing, not ≥ 2)",
8518 );
8519 assert_eq!(
8520 slice.has_multiple_missing_kinds(),
8521 slice.missing_kind_count() >= 2,
8522 "near-saturation-endpoint has_multiple_missing_kinds must equal (missing_kind_count() >= 2) for omitted={omitted:?}",
8523 );
8524 assert_eq!(
8525 slice.has_multiple_missing_kinds(),
8526 slice.missing_kinds().len() >= 2,
8527 "near-saturation-endpoint has_multiple_missing_kinds must equal (missing_kinds().len() >= 2) for omitted={omitted:?}",
8528 );
8529 }
8530 }
8531
8532 /// SATURATED pin — a slice carrying every [`ConditionKind`]
8533 /// variant returns `false` on `has_multiple_missing_kinds` (zero
8534 /// missing, not ≥ 2). Dual of the SATURATED arm on
8535 /// `is_kind_saturated` which returns `true`. Also pins the
8536 /// composition law `has_multiple_missing_kinds() ==
8537 /// (missing_kind_count() >= 2)` at zero-missing.
8538 #[test]
8539 fn condition_slice_has_multiple_missing_kinds_returns_false_on_saturated_slice() {
8540 let saturated: Vec<Condition> =
8541 ConditionKind::ALL.into_iter().map(condition_with).collect();
8542 assert!(
8543 !saturated.as_slice().has_multiple_missing_kinds(),
8544 "slice containing every ConditionKind must return false on has_multiple_missing_kinds (0 missing, not ≥ 2)",
8545 );
8546 assert_eq!(
8547 saturated.as_slice().has_multiple_missing_kinds(),
8548 saturated.as_slice().missing_kind_count() >= 2,
8549 "saturated has_multiple_missing_kinds must equal (missing_kind_count() >= 2)",
8550 );
8551 }
8552
8553 /// TWO-MISSING pin — a slice populating exactly `N - 2` variants
8554 /// returns `true` on `has_multiple_missing_kinds` (exactly 2
8555 /// missing, the SECOND-slot boundary of the ≥ 2 arm). Pins the
8556 /// second-slot short-circuit — a regression that dropped the
8557 /// second-slot check (returning `true` on any ≥ 1-missing arm,
8558 /// conflating with `has_any_missing_kind`) would still pass here,
8559 /// so this pin is complemented by the NEAR-SATURATION-ENDPOINT
8560 /// pin which distinguishes the =1 arm from the ≥ 2 arm.
8561 /// Only meaningful on `N ≥ 2` closed sets.
8562 #[test]
8563 fn condition_slice_has_multiple_missing_kinds_returns_true_on_two_missing_slice() {
8564 assert!(
8565 ConditionKind::ALL.len() >= 2,
8566 "test assumes ConditionKind::ALL has ≥ 2 variants",
8567 );
8568 for i in 0..ConditionKind::ALL.len() {
8569 for j in (i + 1)..ConditionKind::ALL.len() {
8570 let two_missing: Vec<Condition> = ConditionKind::ALL
8571 .into_iter()
8572 .enumerate()
8573 .filter(|(k, _)| *k != i && *k != j)
8574 .map(|(_, k)| condition_with(k))
8575 .collect();
8576 let slice = two_missing.as_slice();
8577 assert!(
8578 slice.has_multiple_missing_kinds(),
8579 "two-missing slice (omitting index {i} and {j}) must return true on has_multiple_missing_kinds (2 missing, ≥ 2)",
8580 );
8581 assert_eq!(
8582 slice.has_multiple_missing_kinds(),
8583 slice.missing_kind_count() >= 2,
8584 "two-missing has_multiple_missing_kinds must equal (missing_kind_count() >= 2) for omitted=({i}, {j})",
8585 );
8586 }
8587 }
8588 }
8589
8590 /// MULTIPLICITY pin — a slice at the empty-endpoint duplicated
8591 /// remains empty (nothing to duplicate), while a slice at a
8592 /// K-populated arm with each populated kind duplicated still
8593 /// returns `true` on any `N ≥ K + 2` — multiplicity is
8594 /// irrelevant to the cardinality many-arm projection on the
8595 /// closed-set-complement axis, byte-for-byte peer of the
8596 /// saturation-predicate arm. Sweeps the near-two-missing
8597 /// arrangement (each pair-omitted arm, doubled populated) on
8598 /// `N ≥ 2` closed sets.
8599 #[test]
8600 fn condition_slice_has_multiple_missing_kinds_ignores_multiplicity() {
8601 assert!(
8602 ConditionKind::ALL.len() >= 2,
8603 "test assumes ConditionKind::ALL has ≥ 2 variants",
8604 );
8605 for i in 0..ConditionKind::ALL.len() {
8606 for j in (i + 1)..ConditionKind::ALL.len() {
8607 let mut doubled: Vec<Condition> = Vec::new();
8608 for (idx, kind) in ConditionKind::ALL.into_iter().enumerate() {
8609 if idx != i && idx != j {
8610 doubled.push(condition_with(kind));
8611 doubled.push(condition_with(kind));
8612 }
8613 }
8614 assert!(
8615 doubled.as_slice().has_multiple_missing_kinds(),
8616 "two-missing slice (omitting index {i} and {j}) with each populated kind duplicated must return true on has_multiple_missing_kinds",
8617 );
8618 }
8619 }
8620 }
8621
8622 // ── ConditionSliceExt::has_at_most_one_missing_kind — "≤ 1" pins ─
8623 //
8624 // Boolean cardinality "≤ 1" negation peer of
8625 // `has_multiple_missing_kinds` on the closed-set-complement axis:
8626 // `has_at_most_one_missing_kind()` returns `true` iff AT MOST ONE
8627 // `ConditionKind::ALL` variant appears zero times in the slice.
8628 // Definitional negation of the many-arm primitive
8629 // (`!has_multiple_missing_kinds`), and trichotomy-union of the
8630 // zero-arm + one-arm primitives (`is_kind_saturated ||
8631 // has_unique_missing_kind`). Body short-circuits transitively
8632 // through the many-arm walk — strictly cheaper than
8633 // `missing_kind_count() <= 1` (which walks every slot) and
8634 // `missing_kinds().len() <= 1` (which allocates the Vec) on every
8635 // arm. The composition laws
8636 // `has_at_most_one_missing_kind() == !has_multiple_missing_kinds()`,
8637 // `has_at_most_one_missing_kind() == (missing_kind_count() <= 1)`,
8638 // `has_at_most_one_missing_kind() == (missing_kinds().len() <= 1)`,
8639 // and `has_at_most_one_missing_kind() == is_kind_saturated() ||
8640 // has_unique_missing_kind()` are pinned as the "≤ 1" arm of
8641 // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8642 // of `crate::tagged_union::TaggedUnion::has_at_most_one_missing_kind`
8643 // one struct-layer up under the SAME `!has_multiple_missing_kinds`
8644 // definitional negation shape.
8645
8646 /// EMPTY-SLICE pin — an empty slice returns `false` on
8647 /// `has_at_most_one_missing_kind` on any `N ≥ 2` closed set
8648 /// (every kind is missing — `N ≥ 2` missing, not `≤ 1`). Dual of
8649 /// the empty-slice arm on `has_multiple_missing_kinds` which
8650 /// returns `true`.
8651 #[test]
8652 fn condition_slice_has_at_most_one_missing_kind_returns_false_on_empty_slice() {
8653 assert!(
8654 ConditionKind::ALL.len() >= 2,
8655 "test assumes ConditionKind::ALL has ≥ 2 variants",
8656 );
8657 let empty: &[Condition] = &[];
8658 assert!(
8659 !empty.has_at_most_one_missing_kind(),
8660 "empty slice must return false on has_at_most_one_missing_kind (all N ≥ 2 kinds missing, not ≤ 1)",
8661 );
8662 assert_eq!(
8663 empty.has_at_most_one_missing_kind(),
8664 empty.missing_kind_count() <= 1,
8665 "empty has_at_most_one_missing_kind must equal (missing_kind_count() <= 1)",
8666 );
8667 }
8668
8669 /// SINGLE-KIND pin — a slice populating exactly one variant
8670 /// returns `false` on any `N ≥ 3` closed set (`N - 1 ≥ 2` kinds
8671 /// missing, not `≤ 1`). On the degenerate `N == 2` closed set it
8672 /// would return `true` (exactly 1 missing), so the pin gates on
8673 /// `N ≥ 3` — this workspace has `N == 8`.
8674 #[test]
8675 fn condition_slice_has_at_most_one_missing_kind_returns_false_on_single_kind_slice() {
8676 if ConditionKind::ALL.len() < 3 {
8677 return;
8678 }
8679 for populated in ConditionKind::ALL {
8680 let slice = [condition_with(populated)];
8681 assert!(
8682 !slice.has_at_most_one_missing_kind(),
8683 "single-populated slice with {populated:?} must return false on has_at_most_one_missing_kind on N ≥ 3 closed sets ({} kinds missing, not ≤ 1)",
8684 ConditionKind::ALL.len() - 1,
8685 );
8686 assert_eq!(
8687 slice.has_at_most_one_missing_kind(),
8688 slice.missing_kind_count() <= 1,
8689 "single-populated has_at_most_one_missing_kind must equal (missing_kind_count() <= 1) for {populated:?}",
8690 );
8691 }
8692 }
8693
8694 /// NEAR-SATURATION-ENDPOINT pin — a slice carrying every
8695 /// [`ConditionKind`] EXCEPT exactly one returns `true` on
8696 /// `has_at_most_one_missing_kind` (exactly 1 missing, `≤ 1`).
8697 /// The `= 1` mid-endpoint arm of the trichotomy union — one of
8698 /// the two arrangement classes where the "≤ 1" primitive
8699 /// returns `true`. Also pins the widened composition laws
8700 /// `has_at_most_one_missing_kind() == (missing_kinds().len() <= 1)`
8701 /// and `has_at_most_one_missing_kind() == !has_multiple_missing_kinds()`
8702 /// and the trichotomy-union composition law
8703 /// `has_at_most_one_missing_kind() == is_kind_saturated() ||
8704 /// has_unique_missing_kind()`.
8705 #[test]
8706 fn condition_slice_has_at_most_one_missing_kind_returns_true_on_near_saturation_endpoint() {
8707 for omitted in ConditionKind::ALL {
8708 let near_saturated: Vec<Condition> = ConditionKind::ALL
8709 .into_iter()
8710 .filter(|k| *k != omitted)
8711 .map(condition_with)
8712 .collect();
8713 let slice = near_saturated.as_slice();
8714 assert!(
8715 slice.has_at_most_one_missing_kind(),
8716 "near-saturation-endpoint slice (omitting {omitted:?}) must return true on has_at_most_one_missing_kind (1 missing, ≤ 1)",
8717 );
8718 assert_eq!(
8719 slice.has_at_most_one_missing_kind(),
8720 !slice.has_multiple_missing_kinds(),
8721 "near-saturation-endpoint has_at_most_one_missing_kind must equal !has_multiple_missing_kinds() for omitted={omitted:?}",
8722 );
8723 assert_eq!(
8724 slice.has_at_most_one_missing_kind(),
8725 slice.missing_kind_count() <= 1,
8726 "near-saturation-endpoint has_at_most_one_missing_kind must equal (missing_kind_count() <= 1) for omitted={omitted:?}",
8727 );
8728 assert_eq!(
8729 slice.has_at_most_one_missing_kind(),
8730 slice.missing_kinds().len() <= 1,
8731 "near-saturation-endpoint has_at_most_one_missing_kind must equal (missing_kinds().len() <= 1) for omitted={omitted:?}",
8732 );
8733 assert_eq!(
8734 slice.has_at_most_one_missing_kind(),
8735 slice.is_kind_saturated() || slice.has_unique_missing_kind(),
8736 "near-saturation-endpoint has_at_most_one_missing_kind must equal (is_kind_saturated() || has_unique_missing_kind()) for omitted={omitted:?}",
8737 );
8738 }
8739 }
8740
8741 /// SATURATED pin — a slice carrying every [`ConditionKind`]
8742 /// variant returns `true` on `has_at_most_one_missing_kind` (0
8743 /// missing, `≤ 1`). The `= 0` zero-arm of the trichotomy union
8744 /// — the OTHER arrangement class where the "≤ 1" primitive
8745 /// returns `true`. Dual of the SATURATED arm on
8746 /// `has_multiple_missing_kinds` which returns `false`.
8747 #[test]
8748 fn condition_slice_has_at_most_one_missing_kind_returns_true_on_saturated_slice() {
8749 let saturated: Vec<Condition> =
8750 ConditionKind::ALL.into_iter().map(condition_with).collect();
8751 assert!(
8752 saturated.as_slice().has_at_most_one_missing_kind(),
8753 "slice containing every ConditionKind must return true on has_at_most_one_missing_kind (0 missing, ≤ 1)",
8754 );
8755 assert_eq!(
8756 saturated.as_slice().has_at_most_one_missing_kind(),
8757 saturated.as_slice().missing_kind_count() <= 1,
8758 "saturated has_at_most_one_missing_kind must equal (missing_kind_count() <= 1)",
8759 );
8760 assert_eq!(
8761 saturated.as_slice().has_at_most_one_missing_kind(),
8762 saturated.as_slice().is_kind_saturated()
8763 || saturated.as_slice().has_unique_missing_kind(),
8764 "saturated has_at_most_one_missing_kind must equal (is_kind_saturated() || has_unique_missing_kind())",
8765 );
8766 }
8767
8768 /// TWO-MISSING pin — a slice populating exactly `N - 2` variants
8769 /// returns `false` on `has_at_most_one_missing_kind` (exactly 2
8770 /// missing, not `≤ 1`). The SECOND-slot boundary between the
8771 /// "≤ 1" arm and the "≥ 2" arm — a regression that dropped the
8772 /// negation (returning `has_multiple_missing_kinds` itself),
8773 /// swapped the wrong side, or drifted the trichotomy union
8774 /// operator from `||` to `&&` surfaces HERE.
8775 #[test]
8776 fn condition_slice_has_at_most_one_missing_kind_returns_false_on_two_missing_slice() {
8777 assert!(
8778 ConditionKind::ALL.len() >= 2,
8779 "test assumes ConditionKind::ALL has ≥ 2 variants",
8780 );
8781 for i in 0..ConditionKind::ALL.len() {
8782 for j in (i + 1)..ConditionKind::ALL.len() {
8783 let two_missing: Vec<Condition> = ConditionKind::ALL
8784 .into_iter()
8785 .enumerate()
8786 .filter(|(k, _)| *k != i && *k != j)
8787 .map(|(_, k)| condition_with(k))
8788 .collect();
8789 let slice = two_missing.as_slice();
8790 assert!(
8791 !slice.has_at_most_one_missing_kind(),
8792 "two-missing slice (omitting index {i} and {j}) must return false on has_at_most_one_missing_kind (2 missing, not ≤ 1)",
8793 );
8794 assert_eq!(
8795 slice.has_at_most_one_missing_kind(),
8796 slice.missing_kind_count() <= 1,
8797 "two-missing has_at_most_one_missing_kind must equal (missing_kind_count() <= 1) for omitted=({i}, {j})",
8798 );
8799 }
8800 }
8801 }
8802
8803 /// MULTIPLICITY pin — a slice at a K-populated arm with each
8804 /// populated kind duplicated still returns the same "≤ 1"
8805 /// Boolean as its single-copy peer — multiplicity is irrelevant
8806 /// to the cardinality "≤ 1" projection on the closed-set-
8807 /// complement axis, byte-for-byte peer of
8808 /// `has_multiple_missing_kinds`'s multiplicity behavior.
8809 #[test]
8810 fn condition_slice_has_at_most_one_missing_kind_ignores_multiplicity() {
8811 // Near-saturation arm doubled — every populated kind
8812 // doubled, exactly one variant omitted; still returns true.
8813 for omitted in ConditionKind::ALL {
8814 let mut doubled: Vec<Condition> = Vec::new();
8815 for k in ConditionKind::ALL {
8816 if k != omitted {
8817 doubled.push(condition_with(k));
8818 doubled.push(condition_with(k));
8819 }
8820 }
8821 assert!(
8822 doubled.as_slice().has_at_most_one_missing_kind(),
8823 "near-saturation slice (omitting {omitted:?}) with each populated kind duplicated must return true on has_at_most_one_missing_kind",
8824 );
8825 }
8826 }
8827
8828 // ── ConditionSliceExt::lacks_kind — per-kind complement pins ──────
8829 //
8830 // Boolean per-kind closed-set-complement peer of `has_kind`:
8831 // `lacks_kind(k)` returns `true` iff NO Condition in the slice
8832 // carries the addressed kind, byte-for-byte with `!has_kind(k)`
8833 // via the definitional negation in the trait's default body.
8834 // The composition laws `lacks_kind(k) == !has_kind(k)` and
8835 // `lacks_kind(k) == missing_kinds().contains(&k)` are pinned as
8836 // the per-kind-complement arm of
8837 // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8838 // of `crate::tagged_union::TaggedUnion::lacks` one struct-layer up
8839 // under the SAME `!has(kind)` definitional negation shape.
8840
8841 /// EMPTY-SLICE pin — an empty slice returns `true` for every
8842 /// [`ConditionKind`] on `lacks_kind` (no kind appears, so every
8843 /// kind is lacked). Dual of the empty-slice arm on `has_kind`
8844 /// (which returns `false` for every kind). Sweeps
8845 /// [`ConditionKind::ALL`] so a regression that dropped the
8846 /// negation, returned `false` (the has-kind identity on empty),
8847 /// or drifted to a per-kind constant surfaces HERE.
8848 #[test]
8849 fn condition_slice_lacks_kind_returns_true_on_empty_slice_for_every_kind() {
8850 let empty: &[Condition] = &[];
8851 for kind in ConditionKind::ALL {
8852 assert!(
8853 empty.lacks_kind(kind),
8854 "empty slice must return true on lacks_kind for {kind:?}",
8855 );
8856 assert_eq!(
8857 empty.lacks_kind(kind),
8858 !empty.has_kind(kind),
8859 "empty lacks_kind must equal !has_kind for {kind:?}",
8860 );
8861 }
8862 }
8863
8864 /// SINGLE-KIND pin — a slice with EXACTLY ONE `Condition` carrying
8865 /// the addressed kind returns `false` on `lacks_kind` for the
8866 /// populated kind and `true` for every OTHER kind. Sweeps
8867 /// [`ConditionKind::ALL`] × [`ConditionKind::ALL`] so a regression
8868 /// that swapped the wrong side, drifted the negation, or drifted
8869 /// the walk from `has_kind` surfaces HERE. Also pins the
8870 /// composition law `lacks_kind(k) == !has_kind(k)` per-kind.
8871 #[test]
8872 fn condition_slice_lacks_kind_returns_true_on_every_missing_kind() {
8873 for populated in ConditionKind::ALL {
8874 let slice = [condition_with(populated)];
8875 for probe in ConditionKind::ALL {
8876 let expected_lacks = probe != populated;
8877 assert_eq!(
8878 slice.as_slice().lacks_kind(probe),
8879 expected_lacks,
8880 "single-populated slice with {populated:?} must return {expected_lacks} on lacks_kind({probe:?})",
8881 );
8882 assert_eq!(
8883 slice.as_slice().lacks_kind(probe),
8884 !slice.as_slice().has_kind(probe),
8885 "single-populated lacks_kind({probe:?}) must equal !has_kind({probe:?}) for populated={populated:?}",
8886 );
8887 }
8888 }
8889 }
8890
8891 /// SATURATED pin — a slice carrying every [`ConditionKind`] variant
8892 /// returns `false` on `lacks_kind` for every arm (the SOLE
8893 /// arrangement where the primitive returns `false` for every kind).
8894 /// Dual of the SATURATED arm on `is_kind_saturated` which returns
8895 /// `true`. Pins the composition law `lacks_kind(k) ==
8896 /// missing_kinds().contains(&k)` per-kind against the empty missing
8897 /// set.
8898 #[test]
8899 fn condition_slice_lacks_kind_returns_false_on_saturated_slice_for_every_kind() {
8900 let saturated: Vec<Condition> =
8901 ConditionKind::ALL.into_iter().map(condition_with).collect();
8902 let missing = saturated.as_slice().missing_kinds();
8903 for kind in ConditionKind::ALL {
8904 assert!(
8905 !saturated.as_slice().lacks_kind(kind),
8906 "saturated slice must return false on lacks_kind for {kind:?}",
8907 );
8908 assert_eq!(
8909 saturated.as_slice().lacks_kind(kind),
8910 missing.contains(&kind),
8911 "saturated lacks_kind({kind:?}) must equal missing_kinds().contains(&{kind:?})",
8912 );
8913 }
8914 }
8915
8916 /// MULTIPLICITY pin — a slice carrying the addressed kind multiple
8917 /// times still returns `false` on `lacks_kind` for that kind
8918 /// (multiplicity is irrelevant to the per-kind Boolean-complement
8919 /// projection on the closed-set-complement axis, byte-for-byte
8920 /// with `has_kind`'s multiplicity behavior).
8921 #[test]
8922 fn condition_slice_lacks_kind_ignores_multiplicity_on_the_populated_side() {
8923 for populated in ConditionKind::ALL {
8924 let slice = [
8925 condition_with(populated),
8926 condition_with(populated),
8927 condition_with(populated),
8928 ];
8929 assert!(
8930 !slice.as_slice().lacks_kind(populated),
8931 "duplicate-populated slice with {populated:?} must return false on lacks_kind for {populated:?}",
8932 );
8933 }
8934 }
8935
8936 // ── ConditionSliceExt::has_only_kind — kind-scoped strict-refinement pins ─
8937 //
8938 // Boolean `(kind, "AND no other kind")` refinement of the closed-
8939 // set-inversion widened primitive `distinct_kinds`:
8940 // `has_only_kind(k)` returns `true` iff `k` is the SOLE distinct
8941 // populated kind AND appears at least once. Fused-walk over
8942 // `ConditionKind::ALL` under `has_kind` — strictly cheaper than
8943 // reaching for either `has_kind(k) && distinct_kind_count() == 1`
8944 // or `distinct_kinds() == vec![k]` composition on every arm where
8945 // a second kind lives alongside `k`. The composition law
8946 // `has_only_kind(k) == (distinct_kinds() == vec![k])` is pinned
8947 // as the kind-scoped strict-refinement arm of
8948 // `assert_slice_refinement_composition_laws`. Byte-for-byte peer
8949 // of `crate::tagged_union::TaggedUnion::has_only` one struct-layer
8950 // up under the SAME fused short-circuit closed-set walk shape.
8951
8952 /// EMPTY-SLICE pin — an empty slice returns `false` on
8953 /// `has_only_kind` for every arm (no kind is populated, so no
8954 /// kind is "only"). Pins the composition law `has_only_kind(k)
8955 /// == (distinct_kinds() == vec![k])` on the zero-distinct
8956 /// arrangement's empty distinct-set: `[] != vec![k]` for every k,
8957 /// so both sides yield `false`.
8958 #[test]
8959 fn condition_slice_has_only_kind_returns_false_on_empty_slice() {
8960 let empty: &[Condition] = &[];
8961 for kind in ConditionKind::ALL {
8962 assert!(
8963 !empty.has_only_kind(kind),
8964 "empty slice must return false on has_only_kind for {kind:?}",
8965 );
8966 assert_eq!(
8967 empty.has_only_kind(kind),
8968 empty.distinct_kinds() == vec![kind],
8969 "empty has_only_kind({kind:?}) must equal (distinct_kinds() == vec![{kind:?}])",
8970 );
8971 }
8972 }
8973
8974 /// SINGLE-KIND pin — a slice with EXACTLY ONE `Condition` carrying
8975 /// the addressed kind returns `true` on `has_only_kind` for the
8976 /// populated kind and `false` for every OTHER kind. Sweeps
8977 /// [`ConditionKind::ALL`] × [`ConditionKind::ALL`] so a regression
8978 /// that swapped the wrong side, drifted the fused walk, or
8979 /// confused the strict-refinement axis with the point-probe axis
8980 /// (returning `has_kind` — TOO LOOSE) surfaces HERE. Also pins the
8981 /// composition law `has_only_kind(k) == (distinct_kinds() ==
8982 /// vec![k])` per-kind against the singleton distinct-set.
8983 #[test]
8984 fn condition_slice_has_only_kind_returns_true_on_single_populated_kind() {
8985 for populated in ConditionKind::ALL {
8986 let slice = [condition_with(populated)];
8987 for probe in ConditionKind::ALL {
8988 let expected = probe == populated;
8989 assert_eq!(
8990 slice.as_slice().has_only_kind(probe),
8991 expected,
8992 "single-populated slice with {populated:?} must return {expected} on has_only_kind({probe:?})",
8993 );
8994 assert_eq!(
8995 slice.as_slice().has_only_kind(probe),
8996 slice.as_slice().distinct_kinds() == vec![probe],
8997 "single-populated has_only_kind({probe:?}) must equal (distinct_kinds() == vec![{probe:?}]) for populated={populated:?}",
8998 );
8999 }
9000 }
9001 }
9002
9003 /// MULTIPLICITY pin — a slice carrying the addressed kind multiple
9004 /// times still returns `true` on `has_only_kind` for that kind
9005 /// (multiplicity is irrelevant to the kind-scoped strict-
9006 /// refinement projection on the closed-set-inversion axis, byte-
9007 /// for-byte with `has_kind`'s multiplicity behavior). Pins that
9008 /// the fused walk under `has_kind` inherits the multiplicity-blind
9009 /// semantics without a special-case on the count.
9010 #[test]
9011 fn condition_slice_has_only_kind_ignores_multiplicity_on_the_populated_side() {
9012 for populated in ConditionKind::ALL {
9013 let slice = [
9014 condition_with(populated),
9015 condition_with(populated),
9016 condition_with(populated),
9017 ];
9018 for probe in ConditionKind::ALL {
9019 let expected = probe == populated;
9020 assert_eq!(
9021 slice.as_slice().has_only_kind(probe),
9022 expected,
9023 "duplicate-populated slice with {populated:?} must return {expected} on has_only_kind({probe:?})",
9024 );
9025 }
9026 }
9027 }
9028
9029 /// TWO-KINDS pin — a slice carrying two DIFFERENT kinds returns
9030 /// `false` on `has_only_kind` for EVERY arm (the "some other kind
9031 /// is present" clause fails at the fused walk's earliest step
9032 /// that hits the second kind, regardless of which kind is
9033 /// addressed). Sweeps [`ConditionKind::ALL`] × [`ConditionKind::ALL`]
9034 /// (skipping equal pairs since a two-distinct-kinds slice requires
9035 /// `p != q`) so a regression that dropped the fused walk's early-
9036 /// exit surfaces at every off-diagonal (p, q) pair.
9037 #[test]
9038 fn condition_slice_has_only_kind_returns_false_on_two_kinds_slice() {
9039 for p in ConditionKind::ALL {
9040 for q in ConditionKind::ALL {
9041 if p == q {
9042 continue;
9043 }
9044 let slice = [condition_with(p), condition_with(q)];
9045 for probe in ConditionKind::ALL {
9046 assert!(
9047 !slice.as_slice().has_only_kind(probe),
9048 "two-kinds slice with {{{p:?}, {q:?}}} must return false on has_only_kind for {probe:?}",
9049 );
9050 }
9051 }
9052 }
9053 }
9054
9055 /// SATURATED pin — a slice carrying every [`ConditionKind`] variant
9056 /// returns `false` on `has_only_kind` for every arm (N distinct
9057 /// kinds populate, so no single kind is "only"). Dual of the
9058 /// SATURATED arm on `is_kind_saturated` which returns `true` for
9059 /// the SAME arrangement. Pins the composition law `has_only_kind(k)
9060 /// == (has_kind(k) && distinct_kind_count() == 1)` per-kind against
9061 /// the saturated `distinct_kind_count() == N`.
9062 #[test]
9063 fn condition_slice_has_only_kind_returns_false_on_saturated_slice() {
9064 let saturated: Vec<Condition> =
9065 ConditionKind::ALL.into_iter().map(condition_with).collect();
9066 for kind in ConditionKind::ALL {
9067 assert!(
9068 !saturated.as_slice().has_only_kind(kind),
9069 "saturated slice must return false on has_only_kind for {kind:?}",
9070 );
9071 assert_eq!(
9072 saturated.as_slice().has_only_kind(kind),
9073 saturated.as_slice().has_kind(kind)
9074 && saturated.as_slice().distinct_kind_count() == 1,
9075 "saturated has_only_kind({kind:?}) must equal (has_kind && distinct_kind_count == 1)",
9076 );
9077 }
9078 }
9079
9080 // ── ConditionSliceExt::lacks_only_kind — kind-scoped strict-
9081 // refinement on the closed-set-complement (missing) axis ─
9082 //
9083 // Byte-for-byte peer of `has_only_kind` under complement: fused
9084 // short-circuit walk over `ConditionKind::ALL` under `has_kind`
9085 // that skips populated slots, returns `false` at the earliest
9086 // missing slot whose kind is NOT `kind`, and returns `true` iff
9087 // the sweep completes with `kind` seen as the sole missing slot.
9088 // The composition laws
9089 // `lacks_only_kind(k) == (missing_kinds() == vec![k])` and
9090 // `lacks_only_kind(k) == (lacks_kind(k) && missing_kind_count() == 1)`
9091 // are pinned as the closed-set-complement kind-scoped strict-
9092 // refinement arms of `assert_slice_refinement_composition_laws`.
9093
9094 /// EMPTY-SLICE pin — every kind is missing (missing set == ALL),
9095 /// so no kind is "only" missing on any `N ≥ 2` closed set. Returns
9096 /// `false` on every arm.
9097 #[test]
9098 fn condition_slice_lacks_only_kind_returns_false_on_empty_slice() {
9099 let empty: &[Condition] = &[];
9100 for kind in ConditionKind::ALL {
9101 assert!(
9102 !empty.lacks_only_kind(kind),
9103 "empty slice must return false on lacks_only_kind for {kind:?}",
9104 );
9105 assert_eq!(
9106 empty.lacks_only_kind(kind),
9107 empty.missing_kinds() == vec![kind],
9108 "empty lacks_only_kind({kind:?}) must equal (missing_kinds() == vec![{kind:?}])",
9109 );
9110 }
9111 }
9112
9113 /// NEAR-SATURATION pin — a slice covering every kind except one
9114 /// returns `true` on `lacks_only_kind(omitted)` and `false` on
9115 /// every other kind. The sole `true` arm on the well-formed
9116 /// missing diagonal.
9117 #[test]
9118 fn condition_slice_lacks_only_kind_returns_true_on_near_saturation_slice() {
9119 for omitted in ConditionKind::ALL {
9120 let slice: Vec<Condition> = ConditionKind::ALL
9121 .into_iter()
9122 .filter(|k| *k != omitted)
9123 .map(condition_with)
9124 .collect();
9125 for kind in ConditionKind::ALL {
9126 let expected = kind == omitted;
9127 assert_eq!(
9128 slice.as_slice().lacks_only_kind(kind),
9129 expected,
9130 "near-saturation slice omitted={omitted:?} must return {expected} on lacks_only_kind for {kind:?}",
9131 );
9132 assert_eq!(
9133 slice.as_slice().lacks_only_kind(kind),
9134 slice.as_slice().missing_kinds() == vec![kind],
9135 "near-saturation lacks_only_kind({kind:?}) must equal (missing_kinds() == vec![{kind:?}]) for omitted={omitted:?}",
9136 );
9137 }
9138 }
9139 }
9140
9141 /// MULTIPLICITY pin — a slice carrying every kind except one, with
9142 /// the populated kinds each duplicated, ignores multiplicity on
9143 /// the populated side (byte-for-byte with `has_kind`'s multiplicity
9144 /// behavior). Returns `true` on `lacks_only_kind(omitted)`.
9145 #[test]
9146 fn condition_slice_lacks_only_kind_ignores_multiplicity_on_the_populated_side() {
9147 for omitted in ConditionKind::ALL {
9148 let mut slice: Vec<Condition> = Vec::new();
9149 for k in ConditionKind::ALL {
9150 if k != omitted {
9151 slice.push(condition_with(k));
9152 slice.push(condition_with(k));
9153 }
9154 }
9155 for kind in ConditionKind::ALL {
9156 let expected = kind == omitted;
9157 assert_eq!(
9158 slice.as_slice().lacks_only_kind(kind),
9159 expected,
9160 "duplicate-populated near-saturation slice omitted={omitted:?} must return {expected} on lacks_only_kind for {kind:?}",
9161 );
9162 }
9163 }
9164 }
9165
9166 /// TWO-MISSING pin — a slice omitting exactly two kinds returns
9167 /// `false` on every arm; the strict refinement fails at the
9168 /// earliest walk step that hits the second missing kind. On
9169 /// `ConditionKind::ALL` of cardinality `N`, `N ≥ 3` is required
9170 /// for a two-missing arrangement to exist.
9171 #[test]
9172 fn condition_slice_lacks_only_kind_returns_false_on_two_missing_slice() {
9173 assert!(
9174 ConditionKind::ALL.len() >= 3,
9175 "two-missing arrangement requires N ≥ 3",
9176 );
9177 // Slice carries every kind except the first two of ALL.
9178 let slice: Vec<Condition> = ConditionKind::ALL
9179 .into_iter()
9180 .skip(2)
9181 .map(condition_with)
9182 .collect();
9183 for kind in ConditionKind::ALL {
9184 assert!(
9185 !slice.as_slice().lacks_only_kind(kind),
9186 "two-missing slice must return false on lacks_only_kind for {kind:?}",
9187 );
9188 assert_eq!(
9189 slice.as_slice().lacks_only_kind(kind),
9190 slice.as_slice().missing_kinds() == vec![kind],
9191 "two-missing lacks_only_kind({kind:?}) must equal (missing_kinds() == vec![{kind:?}])",
9192 );
9193 }
9194 }
9195
9196 /// SATURATED pin — every kind populated, no kind missing, no kind
9197 /// is "only" missing. Returns `false` on every arm.
9198 #[test]
9199 fn condition_slice_lacks_only_kind_returns_false_on_saturated_slice() {
9200 let saturated: Vec<Condition> =
9201 ConditionKind::ALL.into_iter().map(condition_with).collect();
9202 for kind in ConditionKind::ALL {
9203 assert!(
9204 !saturated.as_slice().lacks_only_kind(kind),
9205 "saturated slice must return false on lacks_only_kind for {kind:?}",
9206 );
9207 assert_eq!(
9208 saturated.as_slice().lacks_only_kind(kind),
9209 saturated.as_slice().lacks_kind(kind)
9210 && saturated.as_slice().missing_kind_count() == 1,
9211 "saturated lacks_only_kind({kind:?}) must equal (lacks_kind && missing_kind_count == 1)",
9212 );
9213 }
9214 }
9215
9216 // ── ConditionSliceExt::first_distinct_kind — earliest-element pins ─
9217 //
9218 // Short-circuiting Option<ConditionKind> peer of the closed-set-
9219 // inversion widened primitive `distinct_kinds`: `first_distinct_kind()`
9220 // returns the earliest present kind in canonical ConditionKind::ALL
9221 // order without materializing the intermediate Vec<ConditionKind>.
9222 // The composition law `first_distinct_kind() == distinct_kinds()
9223 // .first().copied()` is pinned as the earliest-element-inversion arm
9224 // of `assert_slice_refinement_composition_laws`.
9225
9226 /// EMPTY-SLICE pin — an empty slice returns `None` on
9227 /// `first_distinct_kind`, byte-for-byte with
9228 /// `distinct_kinds().first().copied()`.
9229 #[test]
9230 fn condition_slice_first_distinct_kind_returns_none_on_empty_slice() {
9231 let empty: &[Condition] = &[];
9232 assert_eq!(
9233 empty.first_distinct_kind(),
9234 None,
9235 "empty slice must return None on first_distinct_kind",
9236 );
9237 assert_eq!(
9238 empty.first_distinct_kind(),
9239 empty.distinct_kinds().first().copied(),
9240 "empty first_distinct_kind must equal distinct_kinds().first().copied()",
9241 );
9242 }
9243
9244 /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
9245 /// the addressed kind returns `Some(that_kind)` on
9246 /// `first_distinct_kind`.
9247 #[test]
9248 fn condition_slice_first_distinct_kind_returns_populated_variant() {
9249 for populated in ConditionKind::ALL {
9250 let slice = [condition_with(populated)];
9251 assert_eq!(
9252 slice.first_distinct_kind(),
9253 Some(populated),
9254 "single-populated slice must return Some({populated:?}) on first_distinct_kind",
9255 );
9256 assert_eq!(
9257 slice.first_distinct_kind(),
9258 slice.distinct_kinds().first().copied(),
9259 "single-populated first_distinct_kind must equal distinct_kinds().first().copied() for {populated:?}",
9260 );
9261 }
9262 }
9263
9264 /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
9265 /// variant returns `Some(ConditionKind::ALL[0])` on
9266 /// `first_distinct_kind` (the first ALL entry hits at the earliest
9267 /// walk step).
9268 #[test]
9269 fn condition_slice_first_distinct_kind_returns_first_all_on_saturated_slice() {
9270 let saturated: Vec<Condition> =
9271 ConditionKind::ALL.into_iter().map(condition_with).collect();
9272 assert_eq!(
9273 saturated.as_slice().first_distinct_kind(),
9274 Some(ConditionKind::ALL[0]),
9275 "saturated slice must return Some(ConditionKind::ALL[0]) on first_distinct_kind",
9276 );
9277 assert_eq!(
9278 saturated.as_slice().first_distinct_kind(),
9279 saturated.as_slice().distinct_kinds().first().copied(),
9280 "saturated first_distinct_kind must equal distinct_kinds().first().copied()",
9281 );
9282 }
9283
9284 // ── ConditionSliceExt::first_missing_kind — earliest-element pins ──
9285
9286 /// EMPTY-SLICE pin — an empty slice returns
9287 /// `Some(ConditionKind::ALL[0])` on `first_missing_kind` (every
9288 /// kind missing, first hit is index 0). Dual of the empty-slice arm
9289 /// on `first_distinct_kind` which returns `None`.
9290 #[test]
9291 fn condition_slice_first_missing_kind_returns_first_all_on_empty_slice() {
9292 let empty: &[Condition] = &[];
9293 assert_eq!(
9294 empty.first_missing_kind(),
9295 Some(ConditionKind::ALL[0]),
9296 "empty slice must return Some(ConditionKind::ALL[0]) on first_missing_kind",
9297 );
9298 assert_eq!(
9299 empty.first_missing_kind(),
9300 empty.missing_kinds().first().copied(),
9301 "empty first_missing_kind must equal missing_kinds().first().copied()",
9302 );
9303 }
9304
9305 /// PER-VARIANT pin — a slice populating exactly `k` returns
9306 /// `Some(ALL[0])` if `k != ALL[0]`, else `Some(ALL[1])` (the earliest
9307 /// non-`k` entry).
9308 #[test]
9309 fn condition_slice_first_missing_kind_returns_earliest_absent_variant() {
9310 for populated in ConditionKind::ALL {
9311 let slice = [condition_with(populated)];
9312 let expected = ConditionKind::ALL.into_iter().find(|k| *k != populated);
9313 assert_eq!(
9314 slice.first_missing_kind(),
9315 expected,
9316 "single-populated slice must return earliest ALL entry != {populated:?} on first_missing_kind",
9317 );
9318 assert_eq!(
9319 slice.first_missing_kind(),
9320 slice.missing_kinds().first().copied(),
9321 "single-populated first_missing_kind must equal missing_kinds().first().copied() for {populated:?}",
9322 );
9323 }
9324 }
9325
9326 /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
9327 /// variant returns `None` on `first_missing_kind` (no kind missing).
9328 #[test]
9329 fn condition_slice_first_missing_kind_returns_none_on_saturated_slice() {
9330 let saturated: Vec<Condition> =
9331 ConditionKind::ALL.into_iter().map(condition_with).collect();
9332 assert_eq!(
9333 saturated.as_slice().first_missing_kind(),
9334 None,
9335 "saturated slice must return None on first_missing_kind",
9336 );
9337 assert_eq!(
9338 saturated.as_slice().first_missing_kind(),
9339 saturated.as_slice().missing_kinds().first().copied(),
9340 "saturated first_missing_kind must equal missing_kinds().first().copied()",
9341 );
9342 }
9343
9344 // ── ConditionSliceExt::last_distinct_kind — latest-element pins ────
9345 //
9346 // Short-circuiting Option<ConditionKind> peer of the closed-set-
9347 // inversion widened primitive `distinct_kinds` on the LATEST-hit
9348 // side: `last_distinct_kind()` returns the latest present kind in
9349 // canonical ConditionKind::ALL order via a REVERSED walk with no
9350 // intermediate Vec<ConditionKind> allocation. The composition law
9351 // `last_distinct_kind() == distinct_kinds().last().copied()` is
9352 // pinned as the latest-element-inversion arm of
9353 // `assert_slice_refinement_composition_laws`.
9354
9355 /// EMPTY-SLICE pin — an empty slice returns `None` on
9356 /// `last_distinct_kind`, byte-for-byte with
9357 /// `distinct_kinds().last().copied()` (both scalar endpoints agree
9358 /// on emptiness).
9359 #[test]
9360 fn condition_slice_last_distinct_kind_returns_none_on_empty_slice() {
9361 let empty: &[Condition] = &[];
9362 assert_eq!(
9363 empty.last_distinct_kind(),
9364 None,
9365 "empty slice must return None on last_distinct_kind",
9366 );
9367 assert_eq!(
9368 empty.last_distinct_kind(),
9369 empty.distinct_kinds().last().copied(),
9370 "empty last_distinct_kind must equal distinct_kinds().last().copied()",
9371 );
9372 }
9373
9374 /// PER-VARIANT pin — a slice with EXACTLY ONE `Condition` carrying
9375 /// the addressed kind returns `Some(that_kind)` on
9376 /// `last_distinct_kind` (single hit; earliest = latest endpoint).
9377 #[test]
9378 fn condition_slice_last_distinct_kind_returns_populated_variant() {
9379 for populated in ConditionKind::ALL {
9380 let slice = [condition_with(populated)];
9381 assert_eq!(
9382 slice.last_distinct_kind(),
9383 Some(populated),
9384 "single-populated slice must return Some({populated:?}) on last_distinct_kind",
9385 );
9386 assert_eq!(
9387 slice.last_distinct_kind(),
9388 slice.distinct_kinds().last().copied(),
9389 "single-populated last_distinct_kind must equal distinct_kinds().last().copied() for {populated:?}",
9390 );
9391 // On single-populated slice both endpoint projections agree.
9392 assert_eq!(
9393 slice.last_distinct_kind(),
9394 slice.first_distinct_kind(),
9395 "single-populated last_distinct_kind must equal first_distinct_kind for {populated:?} (single hit ⇒ earliest = latest)",
9396 );
9397 }
9398 }
9399
9400 /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
9401 /// variant returns `Some(*ConditionKind::ALL.last().unwrap())` on
9402 /// `last_distinct_kind` (the last ALL entry hits at the earliest
9403 /// walk step of the REVERSED walk).
9404 #[test]
9405 fn condition_slice_last_distinct_kind_returns_last_all_on_saturated_slice() {
9406 let saturated: Vec<Condition> =
9407 ConditionKind::ALL.into_iter().map(condition_with).collect();
9408 let last_all = ConditionKind::ALL.last().copied();
9409 assert_eq!(
9410 saturated.as_slice().last_distinct_kind(),
9411 last_all,
9412 "saturated slice must return Some(*ConditionKind::ALL.last().unwrap()) on last_distinct_kind",
9413 );
9414 assert_eq!(
9415 saturated.as_slice().last_distinct_kind(),
9416 saturated.as_slice().distinct_kinds().last().copied(),
9417 "saturated last_distinct_kind must equal distinct_kinds().last().copied()",
9418 );
9419 }
9420
9421 // ── ConditionSliceExt::last_missing_kind — latest-element pins ─────
9422
9423 /// EMPTY-SLICE pin — an empty slice returns
9424 /// `Some(*ConditionKind::ALL.last().unwrap())` on `last_missing_kind`
9425 /// (every kind missing, latest hit is the last ALL entry). Dual of
9426 /// the empty-slice arm on `last_distinct_kind` which returns `None`.
9427 #[test]
9428 fn condition_slice_last_missing_kind_returns_last_all_on_empty_slice() {
9429 let empty: &[Condition] = &[];
9430 let last_all = ConditionKind::ALL.last().copied();
9431 assert_eq!(
9432 empty.last_missing_kind(),
9433 last_all,
9434 "empty slice must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_kind",
9435 );
9436 assert_eq!(
9437 empty.last_missing_kind(),
9438 empty.missing_kinds().last().copied(),
9439 "empty last_missing_kind must equal missing_kinds().last().copied()",
9440 );
9441 }
9442
9443 /// PER-VARIANT pin — a slice populating exactly `k` returns
9444 /// `Some(*ALL.last().unwrap())` if `k != ALL.last().unwrap()`, else
9445 /// `Some(ALL[ALL.len() - 2])` (the latest ALL entry != `k`).
9446 #[test]
9447 fn condition_slice_last_missing_kind_returns_latest_absent_variant() {
9448 for populated in ConditionKind::ALL {
9449 let slice = [condition_with(populated)];
9450 let expected = ConditionKind::ALL
9451 .into_iter()
9452 .rev()
9453 .find(|k| *k != populated);
9454 assert_eq!(
9455 slice.last_missing_kind(),
9456 expected,
9457 "single-populated slice must return latest ALL entry != {populated:?} on last_missing_kind",
9458 );
9459 assert_eq!(
9460 slice.last_missing_kind(),
9461 slice.missing_kinds().last().copied(),
9462 "single-populated last_missing_kind must equal missing_kinds().last().copied() for {populated:?}",
9463 );
9464 }
9465 }
9466
9467 /// FULL-COVERAGE pin — a slice that carries every [`ConditionKind`]
9468 /// variant returns `None` on `last_missing_kind` (no kind missing).
9469 #[test]
9470 fn condition_slice_last_missing_kind_returns_none_on_saturated_slice() {
9471 let saturated: Vec<Condition> =
9472 ConditionKind::ALL.into_iter().map(condition_with).collect();
9473 assert_eq!(
9474 saturated.as_slice().last_missing_kind(),
9475 None,
9476 "saturated slice must return None on last_missing_kind",
9477 );
9478 assert_eq!(
9479 saturated.as_slice().last_missing_kind(),
9480 saturated.as_slice().missing_kinds().last().copied(),
9481 "saturated last_missing_kind must equal missing_kinds().last().copied()",
9482 );
9483 }
9484
9485 // ── Boundary distinct-set triad — substrate-delegation pins ────────
9486 //
9487 // The (precondition, postcondition, condition-union) distinct-set
9488 // triad on [`Boundary`] delegates to the slice-level substrate
9489 // primitive [`ConditionSliceExt::distinct_kinds`] on each half-slice
9490 // and composes the union via [`Self::has_condition_kind`] over
9491 // [`ConditionKind::ALL`]. The dedicated tests below pin each arm's
9492 // delegation shape; the substrate testkit macro
9493 // `assert_surface_union_composition_laws` (extended in this commit
9494 // with the closed-set-inversion arm) pins the union composition law
9495 // against the two half-slice arms in canonical ALL-order.
9496
9497 /// SUBSTRATE-DELEGATION pin (Boundary distinct-kind-count triad)
9498 /// — the three `distinct_*_kind_count` methods on [`Boundary`]
9499 /// delegate to the slice-level substrate primitive
9500 /// [`ConditionSliceExt::distinct_kind_count`] over the two
9501 /// `Vec<Condition>` slots (precondition + postcondition) and
9502 /// compose the union scalar via
9503 /// `ConditionKind::ALL.filter(|k| has_condition_kind(*k)).count()`.
9504 /// Sweep `ConditionKind::ALL × ConditionKind::ALL` so a regression
9505 /// that (a) inlined a divergent closed-set walk at either half-slice
9506 /// arm, (b) reversed the union walk order, or (c) narrowed the
9507 /// union to an intersection surfaces HERE. Also pins the
9508 /// composition law
9509 /// `distinct_*_kind_count() == distinct_*_kinds().len()` at each
9510 /// arm — a regression that overrode the scalar projection to skip a
9511 /// kind or double-count a slot fails HERE.
9512 #[test]
9513 fn distinct_condition_kind_count_triad_delegates_and_matches_distinct_kinds_len() {
9514 // Empty boundary — every arm returns 0.
9515 let b = Boundary::default();
9516 for kind in ConditionKind::ALL {
9517 assert_eq!(
9518 b.distinct_precondition_kind_count(),
9519 0,
9520 "empty boundary must return 0 on distinct_precondition_kind_count, kind={kind:?}",
9521 );
9522 assert_eq!(
9523 b.distinct_postcondition_kind_count(),
9524 0,
9525 "empty boundary must return 0 on distinct_postcondition_kind_count, kind={kind:?}",
9526 );
9527 assert_eq!(
9528 b.distinct_condition_kind_count(),
9529 0,
9530 "empty boundary must return 0 on distinct_condition_kind_count, kind={kind:?}",
9531 );
9532 }
9533
9534 for pre_kind in ConditionKind::ALL {
9535 for post_kind in ConditionKind::ALL {
9536 let mut b = Boundary::default();
9537 b.preconditions.push(condition_with(pre_kind));
9538 b.postconditions.push(condition_with(post_kind));
9539
9540 assert_eq!(
9541 b.distinct_precondition_kind_count(),
9542 b.preconditions.distinct_kind_count(),
9543 "Boundary::distinct_precondition_kind_count must delegate verbatim to \
9544 preconditions.distinct_kind_count() for pre={pre_kind:?} post={post_kind:?}",
9545 );
9546 assert_eq!(
9547 b.distinct_precondition_kind_count(),
9548 b.distinct_precondition_kinds().len(),
9549 "Boundary::distinct_precondition_kind_count must equal \
9550 distinct_precondition_kinds().len() for pre={pre_kind:?} post={post_kind:?}",
9551 );
9552 assert_eq!(
9553 b.distinct_postcondition_kind_count(),
9554 b.postconditions.distinct_kind_count(),
9555 "Boundary::distinct_postcondition_kind_count must delegate verbatim to \
9556 postconditions.distinct_kind_count() for pre={pre_kind:?} post={post_kind:?}",
9557 );
9558 assert_eq!(
9559 b.distinct_postcondition_kind_count(),
9560 b.distinct_postcondition_kinds().len(),
9561 "Boundary::distinct_postcondition_kind_count must equal \
9562 distinct_postcondition_kinds().len() for pre={pre_kind:?} post={post_kind:?}",
9563 );
9564 let expected_union_count = if pre_kind == post_kind { 1 } else { 2 };
9565 assert_eq!(
9566 b.distinct_condition_kind_count(),
9567 expected_union_count,
9568 "Boundary::distinct_condition_kind_count must count distinct union kinds \
9569 for pre={pre_kind:?} post={post_kind:?}",
9570 );
9571 assert_eq!(
9572 b.distinct_condition_kind_count(),
9573 b.distinct_condition_kinds().len(),
9574 "Boundary::distinct_condition_kind_count must equal \
9575 distinct_condition_kinds().len() for pre={pre_kind:?} post={post_kind:?}",
9576 );
9577 }
9578 }
9579 }
9580
9581 /// SUBSTRATE-DELEGATION pin (Boundary distinct-set triad) — the
9582 /// three `distinct_*_kinds` methods on [`Boundary`] delegate to the
9583 /// slice-level substrate primitive over the two `Vec<Condition>`
9584 /// slots (precondition + postcondition) and compose the union via
9585 /// `ConditionKind::ALL.filter(|k| has_condition_kind(*k))`. Sweep
9586 /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9587 /// (a) inlined a divergent closed-set walk at either half-slice
9588 /// arm, (b) reversed the union walk order, or (c) narrowed the
9589 /// union to an intersection surfaces HERE.
9590 #[test]
9591 fn distinct_condition_kinds_triad_delegates_to_slice_distinct_kinds() {
9592 for pre_kind in ConditionKind::ALL {
9593 for post_kind in ConditionKind::ALL {
9594 let mut b = Boundary::default();
9595 b.preconditions.push(condition_with(pre_kind));
9596 b.postconditions.push(condition_with(post_kind));
9597
9598 assert_eq!(
9599 b.distinct_precondition_kinds(),
9600 b.preconditions.distinct_kinds(),
9601 "Boundary::distinct_precondition_kinds must delegate verbatim to \
9602 preconditions.distinct_kinds() for pre={pre_kind:?} post={post_kind:?}",
9603 );
9604 assert_eq!(
9605 b.distinct_postcondition_kinds(),
9606 b.postconditions.distinct_kinds(),
9607 "Boundary::distinct_postcondition_kinds must delegate verbatim to \
9608 postconditions.distinct_kinds() for pre={pre_kind:?} post={post_kind:?}",
9609 );
9610 let expected_union: Vec<_> = ConditionKind::ALL
9611 .into_iter()
9612 .filter(|k| pre_kind == *k || post_kind == *k)
9613 .collect();
9614 assert_eq!(
9615 b.distinct_condition_kinds(),
9616 expected_union,
9617 "Boundary::distinct_condition_kinds must equal ConditionKind::ALL-ordered \
9618 set-union of the two half-slice distinct-sets for pre={pre_kind:?} post={post_kind:?}",
9619 );
9620 }
9621 }
9622 }
9623
9624 /// SUBSTRATE-DELEGATION pin (Boundary distinct-set ITERATOR triad) —
9625 /// the three `iter_distinct_*_condition_kinds` methods on [`Boundary`]
9626 /// delegate to the slice-level substrate primitive
9627 /// [`ConditionSliceExt::iter_distinct_kinds`] over the two
9628 /// `Vec<Condition>` slots (precondition + postcondition) and compose
9629 /// the union via `ConditionKind::ALL.iter().copied().filter(|&k|
9630 /// has_condition_kind(k))`. Byte-for-byte peer of
9631 /// [`distinct_condition_kinds_triad_delegates_to_slice_distinct_kinds`]
9632 /// on the iterator side — the two tests share ONE closed-set walk
9633 /// semantics and pin the composition law
9634 /// `iter_distinct_*_condition_kinds().collect::<Vec<_>>() ==
9635 /// distinct_*_condition_kinds()` for every arm across
9636 /// `ConditionKind::ALL × ConditionKind::ALL`. A regression that
9637 /// materialized the Vec then re-iterated it (round-trip through the
9638 /// heap), drifted the yield order, or diverged from the widened
9639 /// primitive on any arm surfaces HERE.
9640 #[test]
9641 fn iter_distinct_condition_kinds_triad_delegates_to_slice_iter_distinct_kinds() {
9642 for pre_kind in ConditionKind::ALL {
9643 for post_kind in ConditionKind::ALL {
9644 let mut b = Boundary::default();
9645 b.preconditions.push(condition_with(pre_kind));
9646 b.postconditions.push(condition_with(post_kind));
9647
9648 let pre_via_iter: Vec<_> = b.iter_distinct_precondition_kinds().collect();
9649 let pre_via_vec = b.distinct_precondition_kinds();
9650 assert_eq!(
9651 pre_via_iter, pre_via_vec,
9652 "Boundary::iter_distinct_precondition_kinds().collect() drifted from \
9653 distinct_precondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9654 );
9655 let post_via_iter: Vec<_> = b.iter_distinct_postcondition_kinds().collect();
9656 let post_via_vec = b.distinct_postcondition_kinds();
9657 assert_eq!(
9658 post_via_iter, post_via_vec,
9659 "Boundary::iter_distinct_postcondition_kinds().collect() drifted from \
9660 distinct_postcondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9661 );
9662 let union_via_iter: Vec<_> = b.iter_distinct_condition_kinds().collect();
9663 let union_via_vec = b.distinct_condition_kinds();
9664 assert_eq!(
9665 union_via_iter, union_via_vec,
9666 "Boundary::iter_distinct_condition_kinds().collect() drifted from \
9667 distinct_condition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9668 );
9669 }
9670 }
9671 }
9672
9673 /// SUBSTRATE-DELEGATION pin (Boundary missing-set ITERATOR triad) —
9674 /// the three `iter_missing_*_condition_kinds` methods on [`Boundary`]
9675 /// delegate to the slice-level substrate primitive
9676 /// [`ConditionSliceExt::iter_missing_kinds`] over the two
9677 /// `Vec<Condition>` slots (precondition + postcondition) and compose
9678 /// the union via `ConditionKind::ALL.iter().copied().filter(|&k|
9679 /// !has_condition_kind(k))`. Peer of
9680 /// [`iter_distinct_condition_kinds_triad_delegates_to_slice_iter_distinct_kinds`]
9681 /// on the missing side under a NEGATED point-probe.
9682 #[test]
9683 fn iter_missing_condition_kinds_triad_delegates_to_slice_iter_missing_kinds() {
9684 // Empty boundary — every iter arm yields ConditionKind::ALL.
9685 let b = Boundary::default();
9686 let all: Vec<_> = ConditionKind::ALL.to_vec();
9687 assert_eq!(
9688 b.iter_missing_precondition_kinds().collect::<Vec<_>>(),
9689 all,
9690 "empty boundary must yield ConditionKind::ALL on iter_missing_precondition_kinds",
9691 );
9692 assert_eq!(
9693 b.iter_missing_postcondition_kinds().collect::<Vec<_>>(),
9694 all,
9695 "empty boundary must yield ConditionKind::ALL on iter_missing_postcondition_kinds",
9696 );
9697 assert_eq!(
9698 b.iter_missing_condition_kinds().collect::<Vec<_>>(),
9699 all,
9700 "empty boundary must yield ConditionKind::ALL on iter_missing_condition_kinds",
9701 );
9702
9703 for pre_kind in ConditionKind::ALL {
9704 for post_kind in ConditionKind::ALL {
9705 let mut b = Boundary::default();
9706 b.preconditions.push(condition_with(pre_kind));
9707 b.postconditions.push(condition_with(post_kind));
9708
9709 let pre_via_iter: Vec<_> = b.iter_missing_precondition_kinds().collect();
9710 let pre_via_vec = b.missing_precondition_kinds();
9711 assert_eq!(
9712 pre_via_iter, pre_via_vec,
9713 "Boundary::iter_missing_precondition_kinds().collect() drifted from \
9714 missing_precondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9715 );
9716 let post_via_iter: Vec<_> = b.iter_missing_postcondition_kinds().collect();
9717 let post_via_vec = b.missing_postcondition_kinds();
9718 assert_eq!(
9719 post_via_iter, post_via_vec,
9720 "Boundary::iter_missing_postcondition_kinds().collect() drifted from \
9721 missing_postcondition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9722 );
9723 let union_via_iter: Vec<_> = b.iter_missing_condition_kinds().collect();
9724 let union_via_vec = b.missing_condition_kinds();
9725 assert_eq!(
9726 union_via_iter, union_via_vec,
9727 "Boundary::iter_missing_condition_kinds().collect() drifted from \
9728 missing_condition_kinds() for pre={pre_kind:?} post={post_kind:?}",
9729 );
9730 }
9731 }
9732 }
9733
9734 /// SUBSTRATE-DELEGATION pin (Boundary missing-set triad) — the
9735 /// three `missing_*_kinds` methods on [`Boundary`] delegate to the
9736 /// slice-level substrate primitive
9737 /// [`ConditionSliceExt::missing_kinds`] over the two
9738 /// `Vec<Condition>` slots (precondition + postcondition) and
9739 /// compose the union via
9740 /// `ConditionKind::ALL.filter(|k| !has_condition_kind(*k))`. Sweep
9741 /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9742 /// (a) inlined a divergent closed-set walk at either half-slice
9743 /// arm, (b) reversed the union walk order, (c) widened the union
9744 /// intersection to a union (a `||` inlined where `&&` is required
9745 /// on the missing side), or (d) forgot the negation surfaces HERE.
9746 /// Also pins the empty-boundary edge case: every arm returns
9747 /// `ConditionKind::ALL.to_vec()` on an empty boundary.
9748 #[test]
9749 fn missing_condition_kinds_triad_delegates_to_slice_missing_kinds() {
9750 // Empty boundary — every arm returns ConditionKind::ALL (nothing
9751 // is populated, so every kind is missing on all three slots).
9752 let b = Boundary::default();
9753 let all_kinds = ConditionKind::ALL.to_vec();
9754 assert_eq!(
9755 b.missing_precondition_kinds(),
9756 all_kinds,
9757 "empty boundary must return ConditionKind::ALL on missing_precondition_kinds",
9758 );
9759 assert_eq!(
9760 b.missing_postcondition_kinds(),
9761 all_kinds,
9762 "empty boundary must return ConditionKind::ALL on missing_postcondition_kinds",
9763 );
9764 assert_eq!(
9765 b.missing_condition_kinds(),
9766 all_kinds,
9767 "empty boundary must return ConditionKind::ALL on missing_condition_kinds",
9768 );
9769
9770 for pre_kind in ConditionKind::ALL {
9771 for post_kind in ConditionKind::ALL {
9772 let mut b = Boundary::default();
9773 b.preconditions.push(condition_with(pre_kind));
9774 b.postconditions.push(condition_with(post_kind));
9775
9776 assert_eq!(
9777 b.missing_precondition_kinds(),
9778 b.preconditions.missing_kinds(),
9779 "Boundary::missing_precondition_kinds must delegate verbatim to \
9780 preconditions.missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
9781 );
9782 assert_eq!(
9783 b.missing_postcondition_kinds(),
9784 b.postconditions.missing_kinds(),
9785 "Boundary::missing_postcondition_kinds must delegate verbatim to \
9786 postconditions.missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
9787 );
9788 // Union: a kind is missing from the union iff it is
9789 // missing from BOTH half-slices (SET-INTERSECTION).
9790 let expected_union: Vec<_> = ConditionKind::ALL
9791 .into_iter()
9792 .filter(|k| pre_kind != *k && post_kind != *k)
9793 .collect();
9794 assert_eq!(
9795 b.missing_condition_kinds(),
9796 expected_union,
9797 "Boundary::missing_condition_kinds must equal ConditionKind::ALL-ordered \
9798 set-INTERSECTION of the two half-slice missing-sets for pre={pre_kind:?} post={post_kind:?}",
9799 );
9800 // Partition invariant: distinct ∪ missing == ALL, disjoint.
9801 let distinct = b.distinct_condition_kinds();
9802 let missing = b.missing_condition_kinds();
9803 for kind in ConditionKind::ALL {
9804 assert!(
9805 distinct.contains(&kind) ^ missing.contains(&kind),
9806 "(distinct, missing) partition violated on {kind:?} for pre={pre_kind:?} post={post_kind:?}",
9807 );
9808 }
9809 assert_eq!(
9810 distinct.len() + missing.len(),
9811 ConditionKind::ALL.len(),
9812 "Boundary (distinct, missing) cardinality partition drift for pre={pre_kind:?} post={post_kind:?}",
9813 );
9814 }
9815 }
9816 }
9817
9818 /// SUBSTRATE-DELEGATION pin (Boundary missing-kind-count triad) —
9819 /// the three `missing_*_kind_count` methods on [`Boundary`] delegate
9820 /// to the slice-level substrate primitive
9821 /// [`ConditionSliceExt::missing_kind_count`] over the two
9822 /// `Vec<Condition>` slots (precondition + postcondition) and
9823 /// compose the union via
9824 /// `ConditionKind::ALL.iter().filter(|k|
9825 /// !self.has_condition_kind(**k)).count()`. Sweep
9826 /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9827 /// (a) inlined a divergent negated closed-set walk at either half-
9828 /// slice arm, (b) dropped the negation on the union arm, or (c)
9829 /// drifted from the widened-primitive length surfaces HERE. Also
9830 /// pins the scalar-partition invariant
9831 /// `distinct_kind_count + missing_kind_count == ConditionKind::ALL.len()`
9832 /// per arrangement.
9833 #[test]
9834 fn missing_condition_kind_count_triad_delegates_to_slice_missing_kind_count() {
9835 // Empty boundary — every arm returns ConditionKind::ALL.len()
9836 // (nothing is populated, so every kind is missing on all three
9837 // slots).
9838 let b = Boundary::default();
9839 let total = ConditionKind::ALL.len();
9840 assert_eq!(
9841 b.missing_precondition_kind_count(),
9842 total,
9843 "empty boundary must return ConditionKind::ALL.len() on missing_precondition_kind_count",
9844 );
9845 assert_eq!(
9846 b.missing_postcondition_kind_count(),
9847 total,
9848 "empty boundary must return ConditionKind::ALL.len() on missing_postcondition_kind_count",
9849 );
9850 assert_eq!(
9851 b.missing_condition_kind_count(),
9852 total,
9853 "empty boundary must return ConditionKind::ALL.len() on missing_condition_kind_count",
9854 );
9855
9856 for pre_kind in ConditionKind::ALL {
9857 for post_kind in ConditionKind::ALL {
9858 let mut b = Boundary::default();
9859 b.preconditions.push(condition_with(pre_kind));
9860 b.postconditions.push(condition_with(post_kind));
9861
9862 // Half-slice arms delegate byte-for-byte to the slice
9863 // substrate primitive.
9864 assert_eq!(
9865 b.missing_precondition_kind_count(),
9866 b.preconditions.missing_kind_count(),
9867 "Boundary::missing_precondition_kind_count must delegate verbatim to \
9868 preconditions.missing_kind_count() for pre={pre_kind:?} post={post_kind:?}",
9869 );
9870 assert_eq!(
9871 b.missing_postcondition_kind_count(),
9872 b.postconditions.missing_kind_count(),
9873 "Boundary::missing_postcondition_kind_count must delegate verbatim to \
9874 postconditions.missing_kind_count() for pre={pre_kind:?} post={post_kind:?}",
9875 );
9876 // Union arm equals missing_condition_kinds().len() — the
9877 // scalar cardinality of the two-slice intersection.
9878 assert_eq!(
9879 b.missing_condition_kind_count(),
9880 b.missing_condition_kinds().len(),
9881 "Boundary::missing_condition_kind_count must equal missing_condition_kinds().len() \
9882 for pre={pre_kind:?} post={post_kind:?}",
9883 );
9884 // Scalar-partition invariant: distinct + missing == ALL.
9885 assert_eq!(
9886 b.distinct_condition_kind_count() + b.missing_condition_kind_count(),
9887 ConditionKind::ALL.len(),
9888 "Boundary (distinct, missing) scalar partition drift for pre={pre_kind:?} post={post_kind:?}",
9889 );
9890 }
9891 }
9892 }
9893
9894 /// SUBSTRATE-DELEGATION pin (Boundary first-distinct-kind triad) —
9895 /// the three `first_distinct_*_kind` methods on [`Boundary`]
9896 /// delegate to the slice-level substrate primitive
9897 /// [`ConditionSliceExt::first_distinct_kind`] over the two
9898 /// `Vec<Condition>` slots (precondition + postcondition) and
9899 /// compose the union via `ConditionKind::ALL.iter().copied()
9900 /// .find(|k| has_condition_kind(*k))`. Sweep
9901 /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9902 /// inlined a divergent short-circuit walk at either half-slice arm,
9903 /// reversed the walk order, or dropped the short-circuit surfaces
9904 /// HERE. Also pins the composition law `first_distinct_*_kind() ==
9905 /// distinct_*_kinds().first().copied()` at each arm.
9906 #[test]
9907 fn first_distinct_condition_kind_triad_delegates_to_slice_first_distinct_kind() {
9908 // Empty boundary — every arm returns None.
9909 let b = Boundary::default();
9910 assert_eq!(
9911 b.first_distinct_precondition_kind(),
9912 None,
9913 "empty boundary must return None on first_distinct_precondition_kind",
9914 );
9915 assert_eq!(
9916 b.first_distinct_postcondition_kind(),
9917 None,
9918 "empty boundary must return None on first_distinct_postcondition_kind",
9919 );
9920 assert_eq!(
9921 b.first_distinct_condition_kind(),
9922 None,
9923 "empty boundary must return None on first_distinct_condition_kind",
9924 );
9925
9926 for pre_kind in ConditionKind::ALL {
9927 for post_kind in ConditionKind::ALL {
9928 let mut b = Boundary::default();
9929 b.preconditions.push(condition_with(pre_kind));
9930 b.postconditions.push(condition_with(post_kind));
9931
9932 assert_eq!(
9933 b.first_distinct_precondition_kind(),
9934 b.preconditions.first_distinct_kind(),
9935 "Boundary::first_distinct_precondition_kind must delegate verbatim to \
9936 preconditions.first_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
9937 );
9938 assert_eq!(
9939 b.first_distinct_precondition_kind(),
9940 b.distinct_precondition_kinds().first().copied(),
9941 "Boundary::first_distinct_precondition_kind must equal \
9942 distinct_precondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
9943 );
9944 assert_eq!(
9945 b.first_distinct_postcondition_kind(),
9946 b.postconditions.first_distinct_kind(),
9947 "Boundary::first_distinct_postcondition_kind must delegate verbatim to \
9948 postconditions.first_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
9949 );
9950 assert_eq!(
9951 b.first_distinct_postcondition_kind(),
9952 b.distinct_postcondition_kinds().first().copied(),
9953 "Boundary::first_distinct_postcondition_kind must equal \
9954 distinct_postcondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
9955 );
9956 let expected_union = ConditionKind::ALL
9957 .into_iter()
9958 .find(|k| pre_kind == *k || post_kind == *k);
9959 assert_eq!(
9960 b.first_distinct_condition_kind(),
9961 expected_union,
9962 "Boundary::first_distinct_condition_kind must equal earliest ALL entry \
9963 populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
9964 );
9965 assert_eq!(
9966 b.first_distinct_condition_kind(),
9967 b.distinct_condition_kinds().first().copied(),
9968 "Boundary::first_distinct_condition_kind must equal \
9969 distinct_condition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
9970 );
9971 }
9972 }
9973 }
9974
9975 /// SUBSTRATE-DELEGATION pin (Boundary first-missing-kind triad) —
9976 /// the three `first_missing_*_kind` methods on [`Boundary`]
9977 /// delegate to the slice-level substrate primitive
9978 /// [`ConditionSliceExt::first_missing_kind`] over the two
9979 /// `Vec<Condition>` slots (precondition + postcondition) and
9980 /// compose the union via `ConditionKind::ALL.iter().copied()
9981 /// .find(|k| !has_condition_kind(*k))`. Sweep
9982 /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
9983 /// dropped the negation or drifted the short-circuit walk surfaces
9984 /// HERE. Also pins the composition law `first_missing_*_kind() ==
9985 /// missing_*_kinds().first().copied()` at each arm.
9986 #[test]
9987 fn first_missing_condition_kind_triad_delegates_to_slice_first_missing_kind() {
9988 // Empty boundary — every arm returns Some(ConditionKind::ALL[0]).
9989 let b = Boundary::default();
9990 let first = Some(ConditionKind::ALL[0]);
9991 assert_eq!(
9992 b.first_missing_precondition_kind(),
9993 first,
9994 "empty boundary must return Some(ConditionKind::ALL[0]) on first_missing_precondition_kind",
9995 );
9996 assert_eq!(
9997 b.first_missing_postcondition_kind(),
9998 first,
9999 "empty boundary must return Some(ConditionKind::ALL[0]) on first_missing_postcondition_kind",
10000 );
10001 assert_eq!(
10002 b.first_missing_condition_kind(),
10003 first,
10004 "empty boundary must return Some(ConditionKind::ALL[0]) on first_missing_condition_kind",
10005 );
10006
10007 for pre_kind in ConditionKind::ALL {
10008 for post_kind in ConditionKind::ALL {
10009 let mut b = Boundary::default();
10010 b.preconditions.push(condition_with(pre_kind));
10011 b.postconditions.push(condition_with(post_kind));
10012
10013 assert_eq!(
10014 b.first_missing_precondition_kind(),
10015 b.preconditions.first_missing_kind(),
10016 "Boundary::first_missing_precondition_kind must delegate verbatim to \
10017 preconditions.first_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10018 );
10019 assert_eq!(
10020 b.first_missing_precondition_kind(),
10021 b.missing_precondition_kinds().first().copied(),
10022 "Boundary::first_missing_precondition_kind must equal \
10023 missing_precondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
10024 );
10025 assert_eq!(
10026 b.first_missing_postcondition_kind(),
10027 b.postconditions.first_missing_kind(),
10028 "Boundary::first_missing_postcondition_kind must delegate verbatim to \
10029 postconditions.first_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10030 );
10031 assert_eq!(
10032 b.first_missing_postcondition_kind(),
10033 b.missing_postcondition_kinds().first().copied(),
10034 "Boundary::first_missing_postcondition_kind must equal \
10035 missing_postcondition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
10036 );
10037 let expected_union = ConditionKind::ALL
10038 .into_iter()
10039 .find(|k| pre_kind != *k && post_kind != *k);
10040 assert_eq!(
10041 b.first_missing_condition_kind(),
10042 expected_union,
10043 "Boundary::first_missing_condition_kind must equal earliest ALL entry \
10044 NOT populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
10045 );
10046 assert_eq!(
10047 b.first_missing_condition_kind(),
10048 b.missing_condition_kinds().first().copied(),
10049 "Boundary::first_missing_condition_kind must equal \
10050 missing_condition_kinds().first().copied() for pre={pre_kind:?} post={post_kind:?}",
10051 );
10052 }
10053 }
10054 }
10055
10056 /// SUBSTRATE-DELEGATION pin (Boundary last-distinct-kind triad)
10057 /// — the three `last_distinct_*_kind` methods on [`Boundary`]
10058 /// delegate to the slice-level substrate primitive
10059 /// [`ConditionSliceExt::last_distinct_kind`] over the two
10060 /// `Vec<Condition>` slots (precondition + postcondition) and
10061 /// compose the union via `ConditionKind::ALL.iter().rev().copied()
10062 /// .find(|k| has_condition_kind(*k))`. Sweep
10063 /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
10064 /// (a) forgot to reverse the walk (returning `first_distinct_*_kind`),
10065 /// (b) inlined a divergent closed-set walk at either half-slice
10066 /// arm, or (c) narrowed the union to an intersection surfaces
10067 /// HERE. Also pins the composition law `last_distinct_*_kind() ==
10068 /// distinct_*_kinds().last().copied()` at each arm.
10069 #[test]
10070 fn last_distinct_condition_kind_triad_delegates_to_slice_last_distinct_kind() {
10071 // Empty boundary — every arm returns None.
10072 let b = Boundary::default();
10073 assert_eq!(
10074 b.last_distinct_precondition_kind(),
10075 None,
10076 "empty boundary must return None on last_distinct_precondition_kind",
10077 );
10078 assert_eq!(
10079 b.last_distinct_postcondition_kind(),
10080 None,
10081 "empty boundary must return None on last_distinct_postcondition_kind",
10082 );
10083 assert_eq!(
10084 b.last_distinct_condition_kind(),
10085 None,
10086 "empty boundary must return None on last_distinct_condition_kind",
10087 );
10088
10089 for pre_kind in ConditionKind::ALL {
10090 for post_kind in ConditionKind::ALL {
10091 let mut b = Boundary::default();
10092 b.preconditions.push(condition_with(pre_kind));
10093 b.postconditions.push(condition_with(post_kind));
10094
10095 assert_eq!(
10096 b.last_distinct_precondition_kind(),
10097 b.preconditions.last_distinct_kind(),
10098 "Boundary::last_distinct_precondition_kind must delegate verbatim to \
10099 preconditions.last_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
10100 );
10101 assert_eq!(
10102 b.last_distinct_precondition_kind(),
10103 b.distinct_precondition_kinds().last().copied(),
10104 "Boundary::last_distinct_precondition_kind must equal \
10105 distinct_precondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
10106 );
10107 assert_eq!(
10108 b.last_distinct_postcondition_kind(),
10109 b.postconditions.last_distinct_kind(),
10110 "Boundary::last_distinct_postcondition_kind must delegate verbatim to \
10111 postconditions.last_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
10112 );
10113 assert_eq!(
10114 b.last_distinct_postcondition_kind(),
10115 b.distinct_postcondition_kinds().last().copied(),
10116 "Boundary::last_distinct_postcondition_kind must equal \
10117 distinct_postcondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
10118 );
10119 let expected_union = ConditionKind::ALL
10120 .into_iter()
10121 .rev()
10122 .find(|k| pre_kind == *k || post_kind == *k);
10123 assert_eq!(
10124 b.last_distinct_condition_kind(),
10125 expected_union,
10126 "Boundary::last_distinct_condition_kind must equal latest ALL entry \
10127 populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
10128 );
10129 assert_eq!(
10130 b.last_distinct_condition_kind(),
10131 b.distinct_condition_kinds().last().copied(),
10132 "Boundary::last_distinct_condition_kind must equal \
10133 distinct_condition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
10134 );
10135 }
10136 }
10137 }
10138
10139 /// SUBSTRATE-DELEGATION pin (Boundary last-missing-kind triad) —
10140 /// the three `last_missing_*_kind` methods on [`Boundary`]
10141 /// delegate to the slice-level substrate primitive
10142 /// [`ConditionSliceExt::last_missing_kind`] over the two
10143 /// `Vec<Condition>` slots (precondition + postcondition) and
10144 /// compose the union via `ConditionKind::ALL.iter().rev().copied()
10145 /// .find(|k| !has_condition_kind(*k))`. Sweep
10146 /// `ConditionKind::ALL × ConditionKind::ALL` so a regression that
10147 /// dropped the negation or forgot the reversed short-circuit walk
10148 /// surfaces HERE. Also pins the composition law `last_missing_*_kind()
10149 /// == missing_*_kinds().last().copied()` at each arm.
10150 #[test]
10151 fn last_missing_condition_kind_triad_delegates_to_slice_last_missing_kind() {
10152 // Empty boundary — every arm returns Some(*ConditionKind::ALL.last().unwrap()).
10153 let b = Boundary::default();
10154 let last = ConditionKind::ALL.last().copied();
10155 assert_eq!(
10156 b.last_missing_precondition_kind(),
10157 last,
10158 "empty boundary must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_precondition_kind",
10159 );
10160 assert_eq!(
10161 b.last_missing_postcondition_kind(),
10162 last,
10163 "empty boundary must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_postcondition_kind",
10164 );
10165 assert_eq!(
10166 b.last_missing_condition_kind(),
10167 last,
10168 "empty boundary must return Some(*ConditionKind::ALL.last().unwrap()) on last_missing_condition_kind",
10169 );
10170
10171 for pre_kind in ConditionKind::ALL {
10172 for post_kind in ConditionKind::ALL {
10173 let mut b = Boundary::default();
10174 b.preconditions.push(condition_with(pre_kind));
10175 b.postconditions.push(condition_with(post_kind));
10176
10177 assert_eq!(
10178 b.last_missing_precondition_kind(),
10179 b.preconditions.last_missing_kind(),
10180 "Boundary::last_missing_precondition_kind must delegate verbatim to \
10181 preconditions.last_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10182 );
10183 assert_eq!(
10184 b.last_missing_precondition_kind(),
10185 b.missing_precondition_kinds().last().copied(),
10186 "Boundary::last_missing_precondition_kind must equal \
10187 missing_precondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
10188 );
10189 assert_eq!(
10190 b.last_missing_postcondition_kind(),
10191 b.postconditions.last_missing_kind(),
10192 "Boundary::last_missing_postcondition_kind must delegate verbatim to \
10193 postconditions.last_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10194 );
10195 assert_eq!(
10196 b.last_missing_postcondition_kind(),
10197 b.missing_postcondition_kinds().last().copied(),
10198 "Boundary::last_missing_postcondition_kind must equal \
10199 missing_postcondition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
10200 );
10201 let expected_union = ConditionKind::ALL
10202 .into_iter()
10203 .rev()
10204 .find(|k| pre_kind != *k && post_kind != *k);
10205 assert_eq!(
10206 b.last_missing_condition_kind(),
10207 expected_union,
10208 "Boundary::last_missing_condition_kind must equal latest ALL entry \
10209 NOT populated by either half-slice for pre={pre_kind:?} post={post_kind:?}",
10210 );
10211 assert_eq!(
10212 b.last_missing_condition_kind(),
10213 b.missing_condition_kinds().last().copied(),
10214 "Boundary::last_missing_condition_kind must equal \
10215 missing_condition_kinds().last().copied() for pre={pre_kind:?} post={post_kind:?}",
10216 );
10217 }
10218 }
10219 }
10220
10221 /// SUBSTRATE-DELEGATION pin (Boundary saturation-predicate triad)
10222 /// — the three `is_*_kind_saturated` methods on [`Boundary`]
10223 /// delegate to the slice-level substrate primitive
10224 /// [`ConditionSliceExt::is_kind_saturated`] over the two
10225 /// `Vec<Condition>` slots (precondition + postcondition) and
10226 /// compose the union via `ConditionKind::ALL.iter().all(|k|
10227 /// has_condition_kind(*k))`. Sweeps the empty boundary (every arm
10228 /// returns `false`), a single-populated-per-side arrangement (both
10229 /// per-slice arms return `false` on any `N ≥ 2` closed set; the
10230 /// union returns `false` unless the two kinds are distinct AND
10231 /// `N == 2`), and the saturated boundary (both slices carry every
10232 /// [`ConditionKind`], every arm returns `true`). Also pins the
10233 /// composition law `is_*_kind_saturated() ==
10234 /// missing_*_kinds().is_empty()` at each arm — a regression that
10235 /// dropped the `all` short-circuit, drifted the walk from
10236 /// `ConditionKind::ALL`, or negated the wrong side surfaces HERE.
10237 #[test]
10238 fn is_condition_kind_saturated_triad_delegates_to_slice_is_kind_saturated() {
10239 // Empty boundary — every arm returns false; missing_*_kinds
10240 // covers the full closed set on every arm.
10241 let b = Boundary::default();
10242 assert!(
10243 !b.is_precondition_kind_saturated(),
10244 "empty boundary must return false on is_precondition_kind_saturated",
10245 );
10246 assert!(
10247 !b.is_postcondition_kind_saturated(),
10248 "empty boundary must return false on is_postcondition_kind_saturated",
10249 );
10250 assert!(
10251 !b.is_condition_kind_saturated(),
10252 "empty boundary must return false on is_condition_kind_saturated",
10253 );
10254 assert_eq!(
10255 b.is_precondition_kind_saturated(),
10256 b.missing_precondition_kinds().is_empty(),
10257 "empty is_precondition_kind_saturated must equal missing_precondition_kinds().is_empty()",
10258 );
10259
10260 // Single-populated per side — every per-slice arm returns
10261 // false on any N ≥ 2 closed set; the union returns false too
10262 // (needs every ALL kind covered).
10263 for pre_kind in ConditionKind::ALL {
10264 for post_kind in ConditionKind::ALL {
10265 let mut b = Boundary::default();
10266 b.preconditions.push(condition_with(pre_kind));
10267 b.postconditions.push(condition_with(post_kind));
10268 assert_eq!(
10269 b.is_precondition_kind_saturated(),
10270 b.preconditions.is_kind_saturated(),
10271 "Boundary::is_precondition_kind_saturated must delegate verbatim to \
10272 preconditions.is_kind_saturated() for pre={pre_kind:?} post={post_kind:?}",
10273 );
10274 assert_eq!(
10275 b.is_postcondition_kind_saturated(),
10276 b.postconditions.is_kind_saturated(),
10277 "Boundary::is_postcondition_kind_saturated must delegate verbatim to \
10278 postconditions.is_kind_saturated() for pre={pre_kind:?} post={post_kind:?}",
10279 );
10280 let expected_union = ConditionKind::ALL
10281 .iter()
10282 .all(|k| pre_kind == *k || post_kind == *k);
10283 assert_eq!(
10284 b.is_condition_kind_saturated(),
10285 expected_union,
10286 "Boundary::is_condition_kind_saturated must equal all-ALL-covered-by-either-slice \
10287 for pre={pre_kind:?} post={post_kind:?}",
10288 );
10289 assert_eq!(
10290 b.is_condition_kind_saturated(),
10291 b.missing_condition_kinds().is_empty(),
10292 "Boundary::is_condition_kind_saturated must equal missing_condition_kinds().is_empty() \
10293 for pre={pre_kind:?} post={post_kind:?}",
10294 );
10295 }
10296 }
10297
10298 // Saturated boundary — both slices carry every ConditionKind
10299 // at least once, every arm returns true.
10300 let mut b = Boundary::default();
10301 for k in ConditionKind::ALL {
10302 b.preconditions.push(condition_with(k));
10303 b.postconditions.push(condition_with(k));
10304 }
10305 assert!(
10306 b.is_precondition_kind_saturated(),
10307 "saturated boundary must return true on is_precondition_kind_saturated",
10308 );
10309 assert!(
10310 b.is_postcondition_kind_saturated(),
10311 "saturated boundary must return true on is_postcondition_kind_saturated",
10312 );
10313 assert!(
10314 b.is_condition_kind_saturated(),
10315 "saturated boundary must return true on is_condition_kind_saturated",
10316 );
10317 }
10318
10319 /// SUBSTRATE-DELEGATION pin (Boundary at-least-one halfspace
10320 /// triad) — the three `has_any_missing_*_condition_kind` methods
10321 /// on [`Boundary`] delegate to the slice-level substrate primitive
10322 /// [`ConditionSliceExt::has_any_missing_kind`] over the two
10323 /// `Vec<Condition>` slots (precondition + postcondition) and
10324 /// compose the union via `!self.is_condition_kind_saturated()`.
10325 /// Sweeps the empty boundary (every arm returns `true`), a single-
10326 /// populated-per-side arrangement (both per-slice arms return
10327 /// `true` on any `N ≥ 2` closed set; the union returns `true`
10328 /// unless the two kinds together cover every ALL variant), and
10329 /// the saturated boundary (both slices carry every
10330 /// [`ConditionKind`], every arm returns `false`). Also pins the
10331 /// composition law `has_any_missing_*_condition_kind() ==
10332 /// !is_*_condition_kind_saturated()` at each arm — a regression
10333 /// that dropped the negation, drifted the underlying saturation
10334 /// primitive, or negated the wrong side surfaces HERE.
10335 #[test]
10336 fn has_any_missing_condition_kind_triad_delegates_to_slice_has_any_missing_kind() {
10337 // Empty boundary — every arm returns true (every kind is
10338 // missing from every slice + from the union).
10339 let b = Boundary::default();
10340 assert!(
10341 b.has_any_missing_precondition_kind(),
10342 "empty boundary must return true on has_any_missing_precondition_kind",
10343 );
10344 assert!(
10345 b.has_any_missing_postcondition_kind(),
10346 "empty boundary must return true on has_any_missing_postcondition_kind",
10347 );
10348 assert!(
10349 b.has_any_missing_condition_kind(),
10350 "empty boundary must return true on has_any_missing_condition_kind",
10351 );
10352 assert_eq!(
10353 b.has_any_missing_condition_kind(),
10354 !b.is_condition_kind_saturated(),
10355 "empty has_any_missing_condition_kind must equal !is_condition_kind_saturated()",
10356 );
10357
10358 // Single-populated per side — sweep ALL × ALL. Every per-slice
10359 // arm returns true on any N ≥ 2 closed set; the union returns
10360 // true unless the two kinds together cover every ALL variant.
10361 for pre_kind in ConditionKind::ALL {
10362 for post_kind in ConditionKind::ALL {
10363 let mut b = Boundary::default();
10364 b.preconditions.push(condition_with(pre_kind));
10365 b.postconditions.push(condition_with(post_kind));
10366 assert_eq!(
10367 b.has_any_missing_precondition_kind(),
10368 b.preconditions.has_any_missing_kind(),
10369 "Boundary::has_any_missing_precondition_kind must delegate verbatim to \
10370 preconditions.has_any_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10371 );
10372 assert_eq!(
10373 b.has_any_missing_postcondition_kind(),
10374 b.postconditions.has_any_missing_kind(),
10375 "Boundary::has_any_missing_postcondition_kind must delegate verbatim to \
10376 postconditions.has_any_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10377 );
10378 let expected_union = !ConditionKind::ALL
10379 .iter()
10380 .all(|k| pre_kind == *k || post_kind == *k);
10381 assert_eq!(
10382 b.has_any_missing_condition_kind(),
10383 expected_union,
10384 "Boundary::has_any_missing_condition_kind must equal \
10385 !all-ALL-covered-by-either-slice \
10386 for pre={pre_kind:?} post={post_kind:?}",
10387 );
10388 assert_eq!(
10389 b.has_any_missing_condition_kind(),
10390 !b.is_condition_kind_saturated(),
10391 "Boundary::has_any_missing_condition_kind must equal \
10392 !is_condition_kind_saturated() for pre={pre_kind:?} post={post_kind:?}",
10393 );
10394 }
10395 }
10396
10397 // Saturated boundary — both slices carry every ConditionKind
10398 // at least once, every arm returns false.
10399 let mut b = Boundary::default();
10400 for k in ConditionKind::ALL {
10401 b.preconditions.push(condition_with(k));
10402 b.postconditions.push(condition_with(k));
10403 }
10404 assert!(
10405 !b.has_any_missing_precondition_kind(),
10406 "saturated boundary must return false on has_any_missing_precondition_kind",
10407 );
10408 assert!(
10409 !b.has_any_missing_postcondition_kind(),
10410 "saturated boundary must return false on has_any_missing_postcondition_kind",
10411 );
10412 assert!(
10413 !b.has_any_missing_condition_kind(),
10414 "saturated boundary must return false on has_any_missing_condition_kind",
10415 );
10416 }
10417
10418 /// SUBSTRATE-DELEGATION pin (Boundary at-least-one halfspace triad
10419 /// on the closed-set-inversion axis) — the three
10420 /// `has_any_distinct_*_condition_kind` methods on [`Boundary`]
10421 /// delegate to the slice-level substrate primitive
10422 /// [`ConditionSliceExt::has_any_distinct_kind`] over the two
10423 /// `Vec<Condition>` slots (precondition + postcondition) and
10424 /// compose the union via a SHORT-CIRCUITING closed-set walk over
10425 /// [`ConditionKind::ALL`] under [`Boundary::has_condition_kind`].
10426 /// Sweeps the empty boundary (every arm returns `false` — no kind
10427 /// present in either slice), a single-populated-per-side
10428 /// arrangement (every per-slice arm returns `true`, the union
10429 /// returns `true`), a single-populated-precondition-only
10430 /// arrangement (precondition arm `true`, postcondition arm
10431 /// `false`, union `true`), and the saturated boundary (every arm
10432 /// returns `true`). Also pins the composition law
10433 /// `has_any_distinct_*_condition_kind() ==
10434 /// (distinct_*_condition_kind_count() > 0)` at each arm — a
10435 /// regression that dropped the short-circuit, drifted the
10436 /// underlying `has_condition_kind` predicate, or negated the wrong
10437 /// side surfaces HERE.
10438 #[test]
10439 fn has_any_distinct_condition_kind_triad_delegates_to_slice_has_any_distinct_kind() {
10440 // Empty boundary — every arm returns false (no kind present
10441 // in either slice; distinct_kind_count == 0 in both).
10442 let b = Boundary::default();
10443 assert!(
10444 !b.has_any_distinct_precondition_kind(),
10445 "empty boundary must return false on has_any_distinct_precondition_kind",
10446 );
10447 assert!(
10448 !b.has_any_distinct_postcondition_kind(),
10449 "empty boundary must return false on has_any_distinct_postcondition_kind",
10450 );
10451 assert!(
10452 !b.has_any_distinct_condition_kind(),
10453 "empty boundary must return false on has_any_distinct_condition_kind",
10454 );
10455
10456 // Single-populated per side — sweep ALL × ALL. Every per-slice
10457 // arm returns true; the union returns true.
10458 for pre_kind in ConditionKind::ALL {
10459 for post_kind in ConditionKind::ALL {
10460 let mut b = Boundary::default();
10461 b.preconditions.push(condition_with(pre_kind));
10462 b.postconditions.push(condition_with(post_kind));
10463 assert_eq!(
10464 b.has_any_distinct_precondition_kind(),
10465 b.preconditions.has_any_distinct_kind(),
10466 "Boundary::has_any_distinct_precondition_kind must delegate verbatim to \
10467 preconditions.has_any_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
10468 );
10469 assert_eq!(
10470 b.has_any_distinct_postcondition_kind(),
10471 b.postconditions.has_any_distinct_kind(),
10472 "Boundary::has_any_distinct_postcondition_kind must delegate verbatim to \
10473 postconditions.has_any_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
10474 );
10475 assert!(
10476 b.has_any_distinct_precondition_kind(),
10477 "single-populated preconditions must return true on has_any_distinct_precondition_kind for pre={pre_kind:?}",
10478 );
10479 assert!(
10480 b.has_any_distinct_postcondition_kind(),
10481 "single-populated postconditions must return true on has_any_distinct_postcondition_kind for post={post_kind:?}",
10482 );
10483 assert!(
10484 b.has_any_distinct_condition_kind(),
10485 "single-populated-per-side must return true on has_any_distinct_condition_kind for pre={pre_kind:?} post={post_kind:?}",
10486 );
10487 }
10488 }
10489
10490 // Single-populated precondition only — precondition arm true,
10491 // postcondition arm false, union true.
10492 for pre_kind in ConditionKind::ALL {
10493 let mut b = Boundary::default();
10494 b.preconditions.push(condition_with(pre_kind));
10495 assert!(
10496 b.has_any_distinct_precondition_kind(),
10497 "pre-only boundary must return true on has_any_distinct_precondition_kind for pre={pre_kind:?}",
10498 );
10499 assert!(
10500 !b.has_any_distinct_postcondition_kind(),
10501 "pre-only boundary must return false on has_any_distinct_postcondition_kind for pre={pre_kind:?}",
10502 );
10503 assert!(
10504 b.has_any_distinct_condition_kind(),
10505 "pre-only boundary must return true on has_any_distinct_condition_kind for pre={pre_kind:?}",
10506 );
10507 }
10508
10509 // Saturated boundary — both slices carry every ConditionKind
10510 // at least once; every arm returns true.
10511 let mut b = Boundary::default();
10512 for k in ConditionKind::ALL {
10513 b.preconditions.push(condition_with(k));
10514 b.postconditions.push(condition_with(k));
10515 }
10516 assert!(
10517 b.has_any_distinct_precondition_kind(),
10518 "saturated boundary must return true on has_any_distinct_precondition_kind",
10519 );
10520 assert!(
10521 b.has_any_distinct_postcondition_kind(),
10522 "saturated boundary must return true on has_any_distinct_postcondition_kind",
10523 );
10524 assert!(
10525 b.has_any_distinct_condition_kind(),
10526 "saturated boundary must return true on has_any_distinct_condition_kind",
10527 );
10528 }
10529
10530 /// SUBSTRATE-DELEGATION pin (Boundary singleton-coverage triad on
10531 /// the closed-set-inversion axis) — the three
10532 /// `has_unique_distinct_*_condition_kind` methods on [`Boundary`]
10533 /// delegate to the slice-level substrate primitive
10534 /// [`ConditionSliceExt::has_unique_distinct_kind`] over the two
10535 /// `Vec<Condition>` slots (precondition + postcondition) and
10536 /// compose the union via a two-step-short-circuit walk over
10537 /// [`ConditionKind::ALL`] under [`Boundary::has_condition_kind`].
10538 /// Sweeps the empty boundary (every arm returns `false` — 0
10539 /// distinct, not exactly 1), single-populated-per-side sweeping
10540 /// ALL × ALL (every per-slice arm returns `true`; the union
10541 /// returns `true` iff the two kinds coincide OR N == 1), and the
10542 /// saturated boundary (every arm returns `false` on N ≥ 2 — N
10543 /// distinct, not exactly 1). Also pins the composition law
10544 /// `has_unique_distinct_*_condition_kind() ==
10545 /// (distinct_*_condition_kind_count() == 1)` at each arm — a
10546 /// regression that dropped the second-slot short-circuit, drifted
10547 /// the underlying `has_kind` predicate, or conflated with
10548 /// `has_any_distinct_kind` surfaces HERE.
10549 #[test]
10550 fn has_unique_distinct_condition_kind_triad_delegates_to_slice_has_unique_distinct_kind() {
10551 // Empty boundary — every arm returns false (0 distinct, not
10552 // exactly 1).
10553 let b = Boundary::default();
10554 assert!(
10555 !b.has_unique_distinct_precondition_kind(),
10556 "empty boundary must return false on has_unique_distinct_precondition_kind",
10557 );
10558 assert!(
10559 !b.has_unique_distinct_postcondition_kind(),
10560 "empty boundary must return false on has_unique_distinct_postcondition_kind",
10561 );
10562 assert!(
10563 !b.has_unique_distinct_condition_kind(),
10564 "empty boundary must return false on has_unique_distinct_condition_kind",
10565 );
10566 assert_eq!(
10567 b.has_unique_distinct_condition_kind(),
10568 b.distinct_condition_kind_count() == 1,
10569 "empty has_unique_distinct_condition_kind must equal (distinct_condition_kind_count() == 1)",
10570 );
10571
10572 // Single-populated per side — sweep ALL × ALL. Every per-
10573 // slice arm returns true; the union returns true iff the two
10574 // populated kinds coincide (union covers 1 kind) OR the
10575 // closed set is degenerate (N == 1). On this workspace's
10576 // N == 8 the union returns true iff pre_kind == post_kind.
10577 for pre_kind in ConditionKind::ALL {
10578 for post_kind in ConditionKind::ALL {
10579 let mut b = Boundary::default();
10580 b.preconditions.push(condition_with(pre_kind));
10581 b.postconditions.push(condition_with(post_kind));
10582 assert_eq!(
10583 b.has_unique_distinct_precondition_kind(),
10584 b.preconditions.has_unique_distinct_kind(),
10585 "Boundary::has_unique_distinct_precondition_kind must delegate verbatim to \
10586 preconditions.has_unique_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
10587 );
10588 assert_eq!(
10589 b.has_unique_distinct_postcondition_kind(),
10590 b.postconditions.has_unique_distinct_kind(),
10591 "Boundary::has_unique_distinct_postcondition_kind must delegate verbatim to \
10592 postconditions.has_unique_distinct_kind() for pre={pre_kind:?} post={post_kind:?}",
10593 );
10594 assert!(
10595 b.has_unique_distinct_precondition_kind(),
10596 "single-populated preconditions must return true on has_unique_distinct_precondition_kind for pre={pre_kind:?}",
10597 );
10598 assert!(
10599 b.has_unique_distinct_postcondition_kind(),
10600 "single-populated postconditions must return true on has_unique_distinct_postcondition_kind for post={post_kind:?}",
10601 );
10602 let covered_count = ConditionKind::ALL
10603 .into_iter()
10604 .filter(|k| *k == pre_kind || *k == post_kind)
10605 .count();
10606 let expected_union = covered_count == 1;
10607 assert_eq!(
10608 b.has_unique_distinct_condition_kind(),
10609 expected_union,
10610 "Boundary::has_unique_distinct_condition_kind must equal \
10611 (covered-ALL-count == 1) for pre={pre_kind:?} post={post_kind:?}",
10612 );
10613 assert_eq!(
10614 b.has_unique_distinct_condition_kind(),
10615 b.distinct_condition_kind_count() == 1,
10616 "Boundary::has_unique_distinct_condition_kind must equal \
10617 (distinct_condition_kind_count() == 1) for pre={pre_kind:?} post={post_kind:?}",
10618 );
10619 }
10620 }
10621
10622 // Single-populated precondition only — precondition arm true,
10623 // postcondition arm false, union true (1 distinct kind).
10624 for pre_kind in ConditionKind::ALL {
10625 let mut b = Boundary::default();
10626 b.preconditions.push(condition_with(pre_kind));
10627 assert!(
10628 b.has_unique_distinct_precondition_kind(),
10629 "pre-only boundary must return true on has_unique_distinct_precondition_kind for pre={pre_kind:?}",
10630 );
10631 assert!(
10632 !b.has_unique_distinct_postcondition_kind(),
10633 "pre-only boundary must return false on has_unique_distinct_postcondition_kind for pre={pre_kind:?}",
10634 );
10635 assert!(
10636 b.has_unique_distinct_condition_kind(),
10637 "pre-only boundary must return true on has_unique_distinct_condition_kind for pre={pre_kind:?}",
10638 );
10639 assert_eq!(
10640 b.has_unique_distinct_condition_kind(),
10641 b.distinct_condition_kind_count() == 1,
10642 "pre-only has_unique_distinct_condition_kind must equal (distinct_condition_kind_count() == 1) for pre={pre_kind:?}",
10643 );
10644 }
10645
10646 // Saturated boundary — every arm returns false on N ≥ 2 (N
10647 // distinct, not exactly 1).
10648 if ConditionKind::ALL.len() >= 2 {
10649 let mut b = Boundary::default();
10650 for k in ConditionKind::ALL {
10651 b.preconditions.push(condition_with(k));
10652 b.postconditions.push(condition_with(k));
10653 }
10654 assert!(
10655 !b.has_unique_distinct_precondition_kind(),
10656 "saturated boundary must return false on has_unique_distinct_precondition_kind",
10657 );
10658 assert!(
10659 !b.has_unique_distinct_postcondition_kind(),
10660 "saturated boundary must return false on has_unique_distinct_postcondition_kind",
10661 );
10662 assert!(
10663 !b.has_unique_distinct_condition_kind(),
10664 "saturated boundary must return false on has_unique_distinct_condition_kind",
10665 );
10666 }
10667 }
10668
10669 /// SUBSTRATE-DELEGATION pin (Boundary cardinality-mid-endpoint
10670 /// triad) — the three `has_unique_missing_*_condition_kind`
10671 /// methods on [`Boundary`] delegate to the slice-level substrate
10672 /// primitive [`ConditionSliceExt::has_unique_missing_kind`] over
10673 /// the two `Vec<Condition>` slots (precondition + postcondition)
10674 /// and compose the union via a two-step-short-circuit walk over
10675 /// [`ConditionKind::ALL`] under negated
10676 /// [`Boundary::has_condition_kind`]. Sweeps the empty boundary
10677 /// (every arm returns `false` — all N missing, not exactly 1),
10678 /// the near-saturation-endpoint (each slice carries every
10679 /// [`ConditionKind`] except one — every per-slice arm returns
10680 /// `true`; the union returns `true` iff BOTH slices omit the SAME
10681 /// kind), the saturated boundary (every arm returns `false` — 0
10682 /// missing), and a single-populated-per-side arrangement (every
10683 /// per-slice arm returns `false` on any `N ≥ 3` closed set; the
10684 /// union returns `true` only when the two kinds together leave
10685 /// exactly one kind uncovered). Also pins the composition law
10686 /// `has_unique_missing_*_condition_kind() ==
10687 /// (missing_*_condition_kind_count() == 1)` at each arm — a
10688 /// regression that dropped the second-slot short-circuit, drifted
10689 /// the underlying `has_kind` predicate, or conflated with
10690 /// `is_kind_saturated` surfaces HERE.
10691 #[test]
10692 fn has_unique_missing_condition_kind_triad_delegates_to_slice_has_unique_missing_kind() {
10693 // Empty boundary — every arm returns false (all N missing,
10694 // not exactly 1) on any N ≥ 2 closed set.
10695 assert!(
10696 ConditionKind::ALL.len() >= 2,
10697 "test assumes ConditionKind::ALL has ≥ 2 variants",
10698 );
10699 let b = Boundary::default();
10700 assert!(
10701 !b.has_unique_missing_precondition_kind(),
10702 "empty boundary must return false on has_unique_missing_precondition_kind",
10703 );
10704 assert!(
10705 !b.has_unique_missing_postcondition_kind(),
10706 "empty boundary must return false on has_unique_missing_postcondition_kind",
10707 );
10708 assert!(
10709 !b.has_unique_missing_condition_kind(),
10710 "empty boundary must return false on has_unique_missing_condition_kind",
10711 );
10712 assert_eq!(
10713 b.has_unique_missing_condition_kind(),
10714 b.missing_condition_kind_count() == 1,
10715 "empty has_unique_missing_condition_kind must equal (missing_condition_kind_count() == 1)",
10716 );
10717
10718 // Single-populated per side — sweep ALL × ALL on N ≥ 3 closed
10719 // sets. Every per-slice arm returns false (N - 1 ≥ 2 kinds
10720 // missing per slice); the union returns true iff the two kinds
10721 // together leave exactly one ALL variant uncovered.
10722 if ConditionKind::ALL.len() >= 3 {
10723 for pre_kind in ConditionKind::ALL {
10724 for post_kind in ConditionKind::ALL {
10725 let mut b = Boundary::default();
10726 b.preconditions.push(condition_with(pre_kind));
10727 b.postconditions.push(condition_with(post_kind));
10728 assert_eq!(
10729 b.has_unique_missing_precondition_kind(),
10730 b.preconditions.has_unique_missing_kind(),
10731 "Boundary::has_unique_missing_precondition_kind must delegate verbatim to \
10732 preconditions.has_unique_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10733 );
10734 assert_eq!(
10735 b.has_unique_missing_postcondition_kind(),
10736 b.postconditions.has_unique_missing_kind(),
10737 "Boundary::has_unique_missing_postcondition_kind must delegate verbatim to \
10738 postconditions.has_unique_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
10739 );
10740 let uncovered = ConditionKind::ALL
10741 .into_iter()
10742 .filter(|k| *k != pre_kind && *k != post_kind)
10743 .count();
10744 let expected_union = uncovered == 1;
10745 assert_eq!(
10746 b.has_unique_missing_condition_kind(),
10747 expected_union,
10748 "Boundary::has_unique_missing_condition_kind must equal \
10749 (uncovered-ALL-count == 1) for pre={pre_kind:?} post={post_kind:?}",
10750 );
10751 assert_eq!(
10752 b.has_unique_missing_condition_kind(),
10753 b.missing_condition_kind_count() == 1,
10754 "Boundary::has_unique_missing_condition_kind must equal \
10755 (missing_condition_kind_count() == 1) for pre={pre_kind:?} post={post_kind:?}",
10756 );
10757 }
10758 }
10759 }
10760
10761 // Near-saturation-endpoint per side — each slice carries
10762 // every ConditionKind except one; every per-slice arm returns
10763 // true. The union returns true iff BOTH slices omit the SAME
10764 // kind (otherwise the two omissions are covered by each
10765 // other and the union is saturated).
10766 for pre_omit in ConditionKind::ALL {
10767 for post_omit in ConditionKind::ALL {
10768 let mut b = Boundary::default();
10769 for k in ConditionKind::ALL {
10770 if k != pre_omit {
10771 b.preconditions.push(condition_with(k));
10772 }
10773 if k != post_omit {
10774 b.postconditions.push(condition_with(k));
10775 }
10776 }
10777 assert!(
10778 b.has_unique_missing_precondition_kind(),
10779 "near-saturation-endpoint precondition slice (omitting {pre_omit:?}) must return true on has_unique_missing_precondition_kind",
10780 );
10781 assert!(
10782 b.has_unique_missing_postcondition_kind(),
10783 "near-saturation-endpoint postcondition slice (omitting {post_omit:?}) must return true on has_unique_missing_postcondition_kind",
10784 );
10785 let expected_union = pre_omit == post_omit;
10786 assert_eq!(
10787 b.has_unique_missing_condition_kind(),
10788 expected_union,
10789 "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:?}",
10790 );
10791 assert_eq!(
10792 b.has_unique_missing_condition_kind(),
10793 b.missing_condition_kind_count() == 1,
10794 "Boundary::has_unique_missing_condition_kind must equal (missing_condition_kind_count() == 1) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
10795 );
10796 }
10797 }
10798
10799 // Saturated boundary — every arm returns false (0 missing,
10800 // not exactly 1).
10801 let mut b = Boundary::default();
10802 for k in ConditionKind::ALL {
10803 b.preconditions.push(condition_with(k));
10804 b.postconditions.push(condition_with(k));
10805 }
10806 assert!(
10807 !b.has_unique_missing_precondition_kind(),
10808 "saturated boundary must return false on has_unique_missing_precondition_kind",
10809 );
10810 assert!(
10811 !b.has_unique_missing_postcondition_kind(),
10812 "saturated boundary must return false on has_unique_missing_postcondition_kind",
10813 );
10814 assert!(
10815 !b.has_unique_missing_condition_kind(),
10816 "saturated boundary must return false on has_unique_missing_condition_kind",
10817 );
10818 }
10819
10820 /// SUBSTRATE-DELEGATION pin (Boundary cardinality-many-arm triad)
10821 /// — the three `has_multiple_missing_*_condition_kind` methods on
10822 /// [`Boundary`] delegate to the slice-level substrate primitive
10823 /// [`ConditionSliceExt::has_multiple_missing_kinds`] over the two
10824 /// `Vec<Condition>` slots (precondition + postcondition) and
10825 /// compose the union via a two-step-short-circuit walk over
10826 /// [`ConditionKind::ALL`] under negated
10827 /// [`Boundary::has_condition_kind`]. Sweeps the empty boundary
10828 /// (every arm returns `true` — all N missing, ≥ 2), the near-
10829 /// saturation-endpoint (each slice carries every
10830 /// [`ConditionKind`] except one — every per-slice arm returns
10831 /// `false`; the union returns `true` iff the two slices omit
10832 /// DIFFERENT kinds), the saturated boundary (every arm returns
10833 /// `false` — 0 missing), and a single-populated-per-side
10834 /// arrangement (every per-slice arm returns `true` on any `N ≥ 3`
10835 /// closed set; the union returns `true` when the two kinds
10836 /// together leave ≥ 2 kinds uncovered). Also pins the composition
10837 /// law `has_multiple_missing_*_condition_kind() ==
10838 /// (missing_*_condition_kind_count() >= 2)` at each arm — a
10839 /// regression that dropped the second-slot short-circuit, drifted
10840 /// the underlying `has_kind` predicate, or conflated with
10841 /// `has_any_missing_kind` surfaces HERE.
10842 #[test]
10843 fn has_multiple_missing_condition_kind_triad_delegates_to_slice_has_multiple_missing_kinds() {
10844 // Empty boundary — every arm returns true (all N missing,
10845 // ≥ 2) on any N ≥ 2 closed set.
10846 assert!(
10847 ConditionKind::ALL.len() >= 2,
10848 "test assumes ConditionKind::ALL has ≥ 2 variants",
10849 );
10850 let b = Boundary::default();
10851 assert!(
10852 b.has_multiple_missing_precondition_kind(),
10853 "empty boundary must return true on has_multiple_missing_precondition_kind",
10854 );
10855 assert!(
10856 b.has_multiple_missing_postcondition_kind(),
10857 "empty boundary must return true on has_multiple_missing_postcondition_kind",
10858 );
10859 assert!(
10860 b.has_multiple_missing_condition_kind(),
10861 "empty boundary must return true on has_multiple_missing_condition_kind",
10862 );
10863 assert_eq!(
10864 b.has_multiple_missing_condition_kind(),
10865 b.missing_condition_kind_count() >= 2,
10866 "empty has_multiple_missing_condition_kind must equal (missing_condition_kind_count() >= 2)",
10867 );
10868
10869 // Single-populated per side — sweep ALL × ALL on N ≥ 3 closed
10870 // sets. Every per-slice arm returns true (N - 1 ≥ 2 kinds
10871 // missing per slice); the union returns true iff the two
10872 // kinds together leave ≥ 2 ALL variants uncovered.
10873 if ConditionKind::ALL.len() >= 3 {
10874 for pre_kind in ConditionKind::ALL {
10875 for post_kind in ConditionKind::ALL {
10876 let mut b = Boundary::default();
10877 b.preconditions.push(condition_with(pre_kind));
10878 b.postconditions.push(condition_with(post_kind));
10879 assert_eq!(
10880 b.has_multiple_missing_precondition_kind(),
10881 b.preconditions.has_multiple_missing_kinds(),
10882 "Boundary::has_multiple_missing_precondition_kind must delegate verbatim to \
10883 preconditions.has_multiple_missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
10884 );
10885 assert_eq!(
10886 b.has_multiple_missing_postcondition_kind(),
10887 b.postconditions.has_multiple_missing_kinds(),
10888 "Boundary::has_multiple_missing_postcondition_kind must delegate verbatim to \
10889 postconditions.has_multiple_missing_kinds() for pre={pre_kind:?} post={post_kind:?}",
10890 );
10891 let uncovered = ConditionKind::ALL
10892 .into_iter()
10893 .filter(|k| *k != pre_kind && *k != post_kind)
10894 .count();
10895 let expected_union = uncovered >= 2;
10896 assert_eq!(
10897 b.has_multiple_missing_condition_kind(),
10898 expected_union,
10899 "Boundary::has_multiple_missing_condition_kind must equal \
10900 (uncovered-ALL-count >= 2) for pre={pre_kind:?} post={post_kind:?}",
10901 );
10902 assert_eq!(
10903 b.has_multiple_missing_condition_kind(),
10904 b.missing_condition_kind_count() >= 2,
10905 "Boundary::has_multiple_missing_condition_kind must equal \
10906 (missing_condition_kind_count() >= 2) for pre={pre_kind:?} post={post_kind:?}",
10907 );
10908 }
10909 }
10910 }
10911
10912 // Near-saturation-endpoint per side — each slice carries
10913 // every ConditionKind except one; every per-slice arm returns
10914 // false (exactly 1 missing per slice, not ≥ 2). The union
10915 // returns true iff the two slices omit DIFFERENT kinds
10916 // (otherwise both omissions coincide and the union has
10917 // exactly 1 missing, not ≥ 2).
10918 for pre_omit in ConditionKind::ALL {
10919 for post_omit in ConditionKind::ALL {
10920 let mut b = Boundary::default();
10921 for k in ConditionKind::ALL {
10922 if k != pre_omit {
10923 b.preconditions.push(condition_with(k));
10924 }
10925 if k != post_omit {
10926 b.postconditions.push(condition_with(k));
10927 }
10928 }
10929 assert!(
10930 !b.has_multiple_missing_precondition_kind(),
10931 "near-saturation-endpoint precondition slice (omitting {pre_omit:?}) must return false on has_multiple_missing_precondition_kind",
10932 );
10933 assert!(
10934 !b.has_multiple_missing_postcondition_kind(),
10935 "near-saturation-endpoint postcondition slice (omitting {post_omit:?}) must return false on has_multiple_missing_postcondition_kind",
10936 );
10937 // Union: pre-only-missing = {pre_omit}, post-only-
10938 // missing = {post_omit}. Union missing = both
10939 // omissions ∩ each other only when they coincide.
10940 let expected_union = false;
10941 assert_eq!(
10942 b.has_multiple_missing_condition_kind(),
10943 expected_union,
10944 "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:?}",
10945 );
10946 assert_eq!(
10947 b.has_multiple_missing_condition_kind(),
10948 b.missing_condition_kind_count() >= 2,
10949 "Boundary::has_multiple_missing_condition_kind must equal (missing_condition_kind_count() >= 2) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
10950 );
10951 }
10952 }
10953
10954 // Saturated boundary — every arm returns false (0 missing,
10955 // not ≥ 2).
10956 let mut b = Boundary::default();
10957 for k in ConditionKind::ALL {
10958 b.preconditions.push(condition_with(k));
10959 b.postconditions.push(condition_with(k));
10960 }
10961 assert!(
10962 !b.has_multiple_missing_precondition_kind(),
10963 "saturated boundary must return false on has_multiple_missing_precondition_kind",
10964 );
10965 assert!(
10966 !b.has_multiple_missing_postcondition_kind(),
10967 "saturated boundary must return false on has_multiple_missing_postcondition_kind",
10968 );
10969 assert!(
10970 !b.has_multiple_missing_condition_kind(),
10971 "saturated boundary must return false on has_multiple_missing_condition_kind",
10972 );
10973 }
10974
10975 /// SUBSTRATE-DELEGATION pin (Boundary cardinality "≤ 1" triad) —
10976 /// the three `has_at_most_one_missing_*_condition_kind` methods on
10977 /// [`Boundary`] delegate to the slice-level substrate primitive
10978 /// [`ConditionSliceExt::has_at_most_one_missing_kind`] over the
10979 /// two `Vec<Condition>` slots (precondition + postcondition) and
10980 /// compose the union via
10981 /// `!self.has_multiple_missing_condition_kind()` — a definitional
10982 /// negation of the many-arm union primitive. Sweeps the empty
10983 /// boundary (every arm returns `false` — `N ≥ 2` missing, not
10984 /// `≤ 1`), the near-saturation-endpoint (each slice carries
10985 /// every [`ConditionKind`] except one — every per-slice arm
10986 /// returns `true`; the union returns `true` — since the union of
10987 /// two near-saturated slices always has `≤ 1` missing), the
10988 /// saturated boundary (every arm returns `true` — 0 missing,
10989 /// `≤ 1`), and a single-populated-per-side arrangement (every
10990 /// per-slice arm returns `false` on any `N ≥ 3` closed set; the
10991 /// union returns `true` iff the two kinds together leave `≤ 1`
10992 /// kind uncovered — the near-saturation-endpoint of the union
10993 /// axis). Also pins the composition law
10994 /// `has_at_most_one_missing_*_condition_kind() ==
10995 /// (missing_*_condition_kind_count() <= 1)` at each arm — a
10996 /// regression that dropped the definitional negation (returning
10997 /// `has_multiple_missing_condition_kind` itself), swapped the
10998 /// wrong side, or drifted the trichotomy union operator from
10999 /// `||` to `&&` surfaces HERE.
11000 #[test]
11001 fn has_at_most_one_missing_condition_kind_triad_delegates_to_slice_has_at_most_one_missing_kind(
11002 ) {
11003 // Empty boundary — every arm returns false (all N missing,
11004 // not ≤ 1) on any N ≥ 2 closed set.
11005 assert!(
11006 ConditionKind::ALL.len() >= 2,
11007 "test assumes ConditionKind::ALL has ≥ 2 variants",
11008 );
11009 let b = Boundary::default();
11010 assert!(
11011 !b.has_at_most_one_missing_precondition_kind(),
11012 "empty boundary must return false on has_at_most_one_missing_precondition_kind",
11013 );
11014 assert!(
11015 !b.has_at_most_one_missing_postcondition_kind(),
11016 "empty boundary must return false on has_at_most_one_missing_postcondition_kind",
11017 );
11018 assert!(
11019 !b.has_at_most_one_missing_condition_kind(),
11020 "empty boundary must return false on has_at_most_one_missing_condition_kind",
11021 );
11022 assert_eq!(
11023 b.has_at_most_one_missing_condition_kind(),
11024 b.missing_condition_kind_count() <= 1,
11025 "empty has_at_most_one_missing_condition_kind must equal (missing_condition_kind_count() <= 1)",
11026 );
11027
11028 // Single-populated per side — sweep ALL × ALL on N ≥ 3
11029 // closed sets. Every per-slice arm returns false (N - 1 ≥ 2
11030 // kinds missing per slice, not ≤ 1); the union returns true
11031 // iff the two kinds together leave ≤ 1 ALL variant
11032 // uncovered — the near-saturation-endpoint of the union
11033 // axis.
11034 if ConditionKind::ALL.len() >= 3 {
11035 for pre_kind in ConditionKind::ALL {
11036 for post_kind in ConditionKind::ALL {
11037 let mut b = Boundary::default();
11038 b.preconditions.push(condition_with(pre_kind));
11039 b.postconditions.push(condition_with(post_kind));
11040 assert_eq!(
11041 b.has_at_most_one_missing_precondition_kind(),
11042 b.preconditions.has_at_most_one_missing_kind(),
11043 "Boundary::has_at_most_one_missing_precondition_kind must delegate verbatim to \
11044 preconditions.has_at_most_one_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
11045 );
11046 assert_eq!(
11047 b.has_at_most_one_missing_postcondition_kind(),
11048 b.postconditions.has_at_most_one_missing_kind(),
11049 "Boundary::has_at_most_one_missing_postcondition_kind must delegate verbatim to \
11050 postconditions.has_at_most_one_missing_kind() for pre={pre_kind:?} post={post_kind:?}",
11051 );
11052 let uncovered = ConditionKind::ALL
11053 .into_iter()
11054 .filter(|k| *k != pre_kind && *k != post_kind)
11055 .count();
11056 let expected_union = uncovered <= 1;
11057 assert_eq!(
11058 b.has_at_most_one_missing_condition_kind(),
11059 expected_union,
11060 "Boundary::has_at_most_one_missing_condition_kind must equal \
11061 (uncovered-ALL-count <= 1) for pre={pre_kind:?} post={post_kind:?}",
11062 );
11063 assert_eq!(
11064 b.has_at_most_one_missing_condition_kind(),
11065 !b.has_multiple_missing_condition_kind(),
11066 "Boundary::has_at_most_one_missing_condition_kind must equal \
11067 !has_multiple_missing_condition_kind() for pre={pre_kind:?} post={post_kind:?}",
11068 );
11069 assert_eq!(
11070 b.has_at_most_one_missing_condition_kind(),
11071 b.missing_condition_kind_count() <= 1,
11072 "Boundary::has_at_most_one_missing_condition_kind must equal \
11073 (missing_condition_kind_count() <= 1) for pre={pre_kind:?} post={post_kind:?}",
11074 );
11075 }
11076 }
11077 }
11078
11079 // Near-saturation-endpoint per side — each slice carries
11080 // every ConditionKind except one; every per-slice arm returns
11081 // true (exactly 1 missing per slice, ≤ 1). The union has ≤ 1
11082 // missing whether or not the two omissions coincide, so the
11083 // union is always true on this arm.
11084 for pre_omit in ConditionKind::ALL {
11085 for post_omit in ConditionKind::ALL {
11086 let mut b = Boundary::default();
11087 for k in ConditionKind::ALL {
11088 if k != pre_omit {
11089 b.preconditions.push(condition_with(k));
11090 }
11091 if k != post_omit {
11092 b.postconditions.push(condition_with(k));
11093 }
11094 }
11095 assert!(
11096 b.has_at_most_one_missing_precondition_kind(),
11097 "near-saturation-endpoint precondition slice (omitting {pre_omit:?}) must return true on has_at_most_one_missing_precondition_kind",
11098 );
11099 assert!(
11100 b.has_at_most_one_missing_postcondition_kind(),
11101 "near-saturation-endpoint postcondition slice (omitting {post_omit:?}) must return true on has_at_most_one_missing_postcondition_kind",
11102 );
11103 assert!(
11104 b.has_at_most_one_missing_condition_kind(),
11105 "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:?}",
11106 );
11107 assert_eq!(
11108 b.has_at_most_one_missing_condition_kind(),
11109 b.missing_condition_kind_count() <= 1,
11110 "Boundary::has_at_most_one_missing_condition_kind must equal (missing_condition_kind_count() <= 1) for pre_omit={pre_omit:?} post_omit={post_omit:?}",
11111 );
11112 }
11113 }
11114
11115 // Saturated boundary — every arm returns true (0 missing,
11116 // ≤ 1).
11117 let mut b = Boundary::default();
11118 for k in ConditionKind::ALL {
11119 b.preconditions.push(condition_with(k));
11120 b.postconditions.push(condition_with(k));
11121 }
11122 assert!(
11123 b.has_at_most_one_missing_precondition_kind(),
11124 "saturated boundary must return true on has_at_most_one_missing_precondition_kind",
11125 );
11126 assert!(
11127 b.has_at_most_one_missing_postcondition_kind(),
11128 "saturated boundary must return true on has_at_most_one_missing_postcondition_kind",
11129 );
11130 assert!(
11131 b.has_at_most_one_missing_condition_kind(),
11132 "saturated boundary must return true on has_at_most_one_missing_condition_kind",
11133 );
11134 }
11135
11136 /// SUBSTRATE-DELEGATION pin (Boundary per-kind-complement triad) —
11137 /// the three `lacks_*_condition_kind` methods on [`Boundary`]
11138 /// delegate to the slice-level substrate primitive
11139 /// [`ConditionSliceExt::lacks_kind`] over the two `Vec<Condition>`
11140 /// slots (precondition + postcondition) and compose the union via
11141 /// `!self.has_condition_kind(kind)`. Sweeps the empty boundary
11142 /// (every arm returns `true` for every kind), a single-populated-
11143 /// per-side arrangement (per-slice arms return `false` on the
11144 /// populated kind + `true` on every other kind; the union returns
11145 /// `false` iff EITHER slice populates the addressed kind), and the
11146 /// saturated boundary (both slices carry every [`ConditionKind`],
11147 /// every arm returns `false` for every kind). Also pins the
11148 /// composition laws `lacks_*_condition_kind(k) ==
11149 /// !has_*_condition_kind(k)` at each arm AND `lacks_condition_kind(k)
11150 /// == lacks_precondition_kind(k) && lacks_postcondition_kind(k)`
11151 /// (the union AND-composition dual of `has`'s OR-composition) — a
11152 /// regression that dropped the negation, drifted the union operator
11153 /// to `||`, or negated the wrong side surfaces HERE.
11154 #[test]
11155 fn lacks_condition_kind_triad_delegates_to_slice_lacks_kind() {
11156 // Empty boundary — every arm returns true on every kind.
11157 let b = Boundary::default();
11158 for kind in ConditionKind::ALL {
11159 assert!(
11160 b.lacks_precondition_kind(kind),
11161 "empty boundary must return true on lacks_precondition_kind for {kind:?}",
11162 );
11163 assert!(
11164 b.lacks_postcondition_kind(kind),
11165 "empty boundary must return true on lacks_postcondition_kind for {kind:?}",
11166 );
11167 assert!(
11168 b.lacks_condition_kind(kind),
11169 "empty boundary must return true on lacks_condition_kind for {kind:?}",
11170 );
11171 assert_eq!(
11172 b.lacks_condition_kind(kind),
11173 !b.has_condition_kind(kind),
11174 "empty lacks_condition_kind must equal !has_condition_kind for {kind:?}",
11175 );
11176 }
11177
11178 // Single-populated per side — sweep ALL × ALL, then probe every
11179 // ConditionKind on the (pre, post, union) triad.
11180 for pre_kind in ConditionKind::ALL {
11181 for post_kind in ConditionKind::ALL {
11182 let mut b = Boundary::default();
11183 b.preconditions.push(condition_with(pre_kind));
11184 b.postconditions.push(condition_with(post_kind));
11185 for probe in ConditionKind::ALL {
11186 assert_eq!(
11187 b.lacks_precondition_kind(probe),
11188 b.preconditions.lacks_kind(probe),
11189 "Boundary::lacks_precondition_kind must delegate verbatim to preconditions.lacks_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11190 );
11191 assert_eq!(
11192 b.lacks_postcondition_kind(probe),
11193 b.postconditions.lacks_kind(probe),
11194 "Boundary::lacks_postcondition_kind must delegate verbatim to postconditions.lacks_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11195 );
11196 let expected_union = pre_kind != probe && post_kind != probe;
11197 assert_eq!(
11198 b.lacks_condition_kind(probe),
11199 expected_union,
11200 "Boundary::lacks_condition_kind must equal all-ALL-absent-in-both-slices for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11201 );
11202 assert_eq!(
11203 b.lacks_condition_kind(probe),
11204 !b.has_condition_kind(probe),
11205 "Boundary::lacks_condition_kind must equal !has_condition_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11206 );
11207 assert_eq!(
11208 b.lacks_condition_kind(probe),
11209 b.lacks_precondition_kind(probe)
11210 && b.lacks_postcondition_kind(probe),
11211 "Boundary::lacks_condition_kind must equal AND-of-half-slice-arms for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11212 );
11213 }
11214 }
11215 }
11216
11217 // Saturated boundary — both slices carry every ConditionKind,
11218 // every arm returns false on every kind.
11219 let mut b = Boundary::default();
11220 for k in ConditionKind::ALL {
11221 b.preconditions.push(condition_with(k));
11222 b.postconditions.push(condition_with(k));
11223 }
11224 for kind in ConditionKind::ALL {
11225 assert!(
11226 !b.lacks_precondition_kind(kind),
11227 "saturated boundary must return false on lacks_precondition_kind for {kind:?}",
11228 );
11229 assert!(
11230 !b.lacks_postcondition_kind(kind),
11231 "saturated boundary must return false on lacks_postcondition_kind for {kind:?}",
11232 );
11233 assert!(
11234 !b.lacks_condition_kind(kind),
11235 "saturated boundary must return false on lacks_condition_kind for {kind:?}",
11236 );
11237 }
11238 }
11239
11240 /// TRIAD delegation pin — the (precondition, postcondition,
11241 /// condition-union) kind-scoped strict-refinement triad on
11242 /// [`Boundary`] agrees byte-for-byte with the slice-level
11243 /// substrate primitive [`ConditionSliceExt::has_only_kind`] on
11244 /// every authored arrangement.
11245 ///
11246 /// Sweeps [`ConditionKind::ALL`] × [`ConditionKind::ALL`] over
11247 /// single-populated-per-side arrangements (the well-formed
11248 /// diagonal), probing every [`ConditionKind`] at the union arm
11249 /// against the DERIVED oracle
11250 /// `boundary.distinct_condition_kinds() == vec![probe]` — a
11251 /// regression at the union arm's fused walk (dropping the
11252 /// short-circuit, swapping the `saw_kind` arm, mis-composing the
11253 /// `||` union at [`Boundary::has_condition_kind`]) surfaces HERE
11254 /// rather than as silent drift at every downstream `has-only-
11255 /// <kind>` require-tag classifier or well-formed-diagonal
11256 /// coherence check callsite. Also pins the per-slice arms
11257 /// delegate verbatim to
11258 /// [`ConditionSliceExt::has_only_kind`] over the corresponding
11259 /// half-slice.
11260 #[test]
11261 fn has_only_condition_kind_triad_delegates_to_slice_has_only_kind() {
11262 // Empty boundary — every arm returns false on every kind
11263 // (no kind is populated, so no kind is "only").
11264 let b = Boundary::default();
11265 for kind in ConditionKind::ALL {
11266 assert!(
11267 !b.has_only_precondition_kind(kind),
11268 "empty boundary must return false on has_only_precondition_kind for {kind:?}",
11269 );
11270 assert!(
11271 !b.has_only_postcondition_kind(kind),
11272 "empty boundary must return false on has_only_postcondition_kind for {kind:?}",
11273 );
11274 assert!(
11275 !b.has_only_condition_kind(kind),
11276 "empty boundary must return false on has_only_condition_kind for {kind:?}",
11277 );
11278 }
11279
11280 // Single-populated per side — sweep ALL × ALL, then probe
11281 // every ConditionKind on the (pre, post, union) triad. The
11282 // union arm returns `true` iff the addressed kind matches
11283 // BOTH the (nonempty) pre kind AND the (nonempty) post kind;
11284 // any (pre_kind, post_kind) with `pre_kind != post_kind`
11285 // yields `false` on every union arm.
11286 for pre_kind in ConditionKind::ALL {
11287 for post_kind in ConditionKind::ALL {
11288 let mut b = Boundary::default();
11289 b.preconditions.push(condition_with(pre_kind));
11290 b.postconditions.push(condition_with(post_kind));
11291 for probe in ConditionKind::ALL {
11292 assert_eq!(
11293 b.has_only_precondition_kind(probe),
11294 b.preconditions.has_only_kind(probe),
11295 "Boundary::has_only_precondition_kind must delegate verbatim to preconditions.has_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11296 );
11297 assert_eq!(
11298 b.has_only_postcondition_kind(probe),
11299 b.postconditions.has_only_kind(probe),
11300 "Boundary::has_only_postcondition_kind must delegate verbatim to postconditions.has_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11301 );
11302 let expected_union = pre_kind == probe && post_kind == probe;
11303 assert_eq!(
11304 b.has_only_condition_kind(probe),
11305 expected_union,
11306 "Boundary::has_only_condition_kind must equal (pre_kind == probe && post_kind == probe) for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11307 );
11308 assert_eq!(
11309 b.has_only_condition_kind(probe),
11310 b.distinct_condition_kinds() == vec![probe],
11311 "Boundary::has_only_condition_kind({probe:?}) must equal (distinct_condition_kinds() == vec![{probe:?}]) for pre={pre_kind:?} post={post_kind:?}",
11312 );
11313 }
11314 }
11315 }
11316
11317 // Single-side-only populated — a boundary with a condition on
11318 // ONE side and NOTHING on the other: the union carries a
11319 // singleton distinct set. The single-slice AND-of-strict-
11320 // refinement fails on the empty side (`empty.has_only_kind(k)
11321 // == false`), but the union arm returns `true` for the
11322 // populated kind — pins that the union arm reaches the union
11323 // primitive, not the (pre AND post) AND-composition.
11324 for populated in ConditionKind::ALL {
11325 let mut b = Boundary::default();
11326 b.preconditions.push(condition_with(populated));
11327 for probe in ConditionKind::ALL {
11328 let expected = probe == populated;
11329 assert_eq!(
11330 b.has_only_condition_kind(probe),
11331 expected,
11332 "pre-only boundary populated={populated:?} must return {expected} on has_only_condition_kind({probe:?})",
11333 );
11334 assert_eq!(
11335 b.has_only_condition_kind(probe),
11336 b.distinct_condition_kinds() == vec![probe],
11337 "pre-only boundary populated={populated:?} must agree with distinct_condition_kinds() == vec![{probe:?}]",
11338 );
11339 }
11340 let mut b = Boundary::default();
11341 b.postconditions.push(condition_with(populated));
11342 for probe in ConditionKind::ALL {
11343 let expected = probe == populated;
11344 assert_eq!(
11345 b.has_only_condition_kind(probe),
11346 expected,
11347 "post-only boundary populated={populated:?} must return {expected} on has_only_condition_kind({probe:?})",
11348 );
11349 assert_eq!(
11350 b.has_only_condition_kind(probe),
11351 b.distinct_condition_kinds() == vec![probe],
11352 "post-only boundary populated={populated:?} must agree with distinct_condition_kinds() == vec![{probe:?}]",
11353 );
11354 }
11355 }
11356
11357 // Saturated boundary — both slices carry every ConditionKind,
11358 // every arm returns false on every kind (N distinct kinds, no
11359 // kind is "only").
11360 let mut b = Boundary::default();
11361 for k in ConditionKind::ALL {
11362 b.preconditions.push(condition_with(k));
11363 b.postconditions.push(condition_with(k));
11364 }
11365 for kind in ConditionKind::ALL {
11366 assert!(
11367 !b.has_only_precondition_kind(kind),
11368 "saturated boundary must return false on has_only_precondition_kind for {kind:?}",
11369 );
11370 assert!(
11371 !b.has_only_postcondition_kind(kind),
11372 "saturated boundary must return false on has_only_postcondition_kind for {kind:?}",
11373 );
11374 assert!(
11375 !b.has_only_condition_kind(kind),
11376 "saturated boundary must return false on has_only_condition_kind for {kind:?}",
11377 );
11378 }
11379 }
11380
11381 /// TRIAD delegation pin — the (precondition, postcondition,
11382 /// condition-union) kind-scoped strict-refinement-on-missing triad
11383 /// on [`Boundary`] agrees byte-for-byte with the slice-level
11384 /// substrate primitive [`ConditionSliceExt::lacks_only_kind`] on
11385 /// every authored arrangement.
11386 ///
11387 /// Sweeps [`ConditionKind::ALL`] × [`ConditionKind::ALL`] over
11388 /// single-populated-per-side arrangements + near-saturation-per-
11389 /// side arrangements (the union arm's well-formed missing
11390 /// diagonal), probing every [`ConditionKind`] at the union arm
11391 /// against the DERIVED oracle
11392 /// `boundary.missing_condition_kinds() == vec![probe]` — a
11393 /// regression at the union arm's fused walk (dropping the
11394 /// short-circuit, swapping the `saw_kind` arm, mis-composing the
11395 /// `has_condition_kind` complement) surfaces HERE rather than as
11396 /// silent drift at every downstream `lacks-only-<kind>` require-
11397 /// tag classifier or near-saturation-diagonal coherence check
11398 /// callsite. Also pins the per-slice arms delegate verbatim to
11399 /// [`ConditionSliceExt::lacks_only_kind`] over the corresponding
11400 /// half-slice.
11401 #[test]
11402 fn lacks_only_condition_kind_triad_delegates_to_slice_lacks_only_kind() {
11403 // Empty boundary — every kind is missing from the union
11404 // (2 ≥ N missing on any N ≥ 2), so no kind is "only" missing.
11405 let b = Boundary::default();
11406 for kind in ConditionKind::ALL {
11407 assert_eq!(
11408 b.lacks_only_precondition_kind(kind),
11409 b.preconditions.lacks_only_kind(kind),
11410 "empty boundary lacks_only_precondition_kind must delegate to preconditions.lacks_only_kind for {kind:?}",
11411 );
11412 assert_eq!(
11413 b.lacks_only_postcondition_kind(kind),
11414 b.postconditions.lacks_only_kind(kind),
11415 "empty boundary lacks_only_postcondition_kind must delegate to postconditions.lacks_only_kind for {kind:?}",
11416 );
11417 assert!(
11418 !b.lacks_only_condition_kind(kind),
11419 "empty boundary must return false on lacks_only_condition_kind for {kind:?} (every kind is missing on N ≥ 2)",
11420 );
11421 }
11422
11423 // Single-populated per side — sweep ALL × ALL, then probe
11424 // every ConditionKind on the (pre, post, union) triad. The
11425 // per-slice arms return `false` (on N ≥ 3 the slice has ≥ 2
11426 // missing kinds; on N == 2 the missing set is single-element
11427 // but only for the OTHER kind). The union arm returns `false`
11428 // for every kind on N ≥ 3 — the union missing set has size
11429 // `N - |{pre, post}|` which is ≥ 2 whenever N ≥ 3, or size 1
11430 // iff pre != post (union covers both), or size N - 1 iff
11431 // pre == post.
11432 for pre_kind in ConditionKind::ALL {
11433 for post_kind in ConditionKind::ALL {
11434 let mut b = Boundary::default();
11435 b.preconditions.push(condition_with(pre_kind));
11436 b.postconditions.push(condition_with(post_kind));
11437 for probe in ConditionKind::ALL {
11438 assert_eq!(
11439 b.lacks_only_precondition_kind(probe),
11440 b.preconditions.lacks_only_kind(probe),
11441 "Boundary::lacks_only_precondition_kind must delegate verbatim to preconditions.lacks_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11442 );
11443 assert_eq!(
11444 b.lacks_only_postcondition_kind(probe),
11445 b.postconditions.lacks_only_kind(probe),
11446 "Boundary::lacks_only_postcondition_kind must delegate verbatim to postconditions.lacks_only_kind for pre={pre_kind:?} post={post_kind:?} probe={probe:?}",
11447 );
11448 assert_eq!(
11449 b.lacks_only_condition_kind(probe),
11450 b.missing_condition_kinds() == vec![probe],
11451 "Boundary::lacks_only_condition_kind({probe:?}) must equal (missing_condition_kinds() == vec![{probe:?}]) for pre={pre_kind:?} post={post_kind:?}",
11452 );
11453 }
11454 }
11455 }
11456
11457 // Near-saturation per side — build a boundary whose preconditions
11458 // carry every kind except one, sweep every "omitted" kind for the
11459 // pre side, then probe the per-slice arm. On the well-formed
11460 // near-saturation diagonal (missing == {omitted}),
11461 // preconditions.lacks_only_kind(omitted) == true; every other
11462 // arm is false.
11463 for omitted in ConditionKind::ALL {
11464 let mut b = Boundary::default();
11465 for k in ConditionKind::ALL {
11466 if k != omitted {
11467 b.preconditions.push(condition_with(k));
11468 b.postconditions.push(condition_with(k));
11469 }
11470 }
11471 for probe in ConditionKind::ALL {
11472 let expected = probe == omitted;
11473 assert_eq!(
11474 b.lacks_only_precondition_kind(probe),
11475 expected,
11476 "near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_precondition_kind({probe:?})",
11477 );
11478 assert_eq!(
11479 b.lacks_only_postcondition_kind(probe),
11480 expected,
11481 "near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_postcondition_kind({probe:?})",
11482 );
11483 assert_eq!(
11484 b.lacks_only_condition_kind(probe),
11485 expected,
11486 "near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_condition_kind({probe:?})",
11487 );
11488 assert_eq!(
11489 b.lacks_only_condition_kind(probe),
11490 b.missing_condition_kinds() == vec![probe],
11491 "near-saturation boundary omitted={omitted:?} must agree with missing_condition_kinds() == vec![{probe:?}]",
11492 );
11493 }
11494 }
11495
11496 // Single-side-only near-saturation — a boundary whose ONE side
11497 // carries every kind except one, the OTHER side empty: the
11498 // empty side is missing every kind (per-slice `lacks_only_kind`
11499 // returns false on N ≥ 2), but the union covers everything the
11500 // populated side does, so the union missing set is still
11501 // `{omitted}` and the union arm returns `true` for `omitted`.
11502 // Pins that the union arm reaches the union primitive, not the
11503 // (pre AND post) AND-composition (which would fail on the
11504 // empty side).
11505 for omitted in ConditionKind::ALL {
11506 let mut b = Boundary::default();
11507 for k in ConditionKind::ALL {
11508 if k != omitted {
11509 b.preconditions.push(condition_with(k));
11510 }
11511 }
11512 for probe in ConditionKind::ALL {
11513 let expected = probe == omitted;
11514 assert_eq!(
11515 b.lacks_only_condition_kind(probe),
11516 expected,
11517 "pre-only near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_condition_kind({probe:?})",
11518 );
11519 assert_eq!(
11520 b.lacks_only_condition_kind(probe),
11521 b.missing_condition_kinds() == vec![probe],
11522 "pre-only near-saturation boundary omitted={omitted:?} must agree with missing_condition_kinds() == vec![{probe:?}]",
11523 );
11524 }
11525 let mut b = Boundary::default();
11526 for k in ConditionKind::ALL {
11527 if k != omitted {
11528 b.postconditions.push(condition_with(k));
11529 }
11530 }
11531 for probe in ConditionKind::ALL {
11532 let expected = probe == omitted;
11533 assert_eq!(
11534 b.lacks_only_condition_kind(probe),
11535 expected,
11536 "post-only near-saturation boundary omitted={omitted:?} must return {expected} on lacks_only_condition_kind({probe:?})",
11537 );
11538 }
11539 }
11540
11541 // Saturated boundary — every kind populated in the union, so
11542 // no kind is missing, so `lacks_only_kind` returns false on
11543 // every arm.
11544 let mut b = Boundary::default();
11545 for k in ConditionKind::ALL {
11546 b.preconditions.push(condition_with(k));
11547 b.postconditions.push(condition_with(k));
11548 }
11549 for kind in ConditionKind::ALL {
11550 assert!(
11551 !b.lacks_only_precondition_kind(kind),
11552 "saturated boundary must return false on lacks_only_precondition_kind for {kind:?}",
11553 );
11554 assert!(
11555 !b.lacks_only_postcondition_kind(kind),
11556 "saturated boundary must return false on lacks_only_postcondition_kind for {kind:?}",
11557 );
11558 assert!(
11559 !b.lacks_only_condition_kind(kind),
11560 "saturated boundary must return false on lacks_only_condition_kind for {kind:?}",
11561 );
11562 }
11563 }
11564
11565 // ── assert_slice_refinement_composition_laws — substrate testkit ──
11566 //
11567 // The substrate testkit primitive
11568 // [`assert_slice_refinement_composition_laws`] pins the FOUR
11569 // composition laws that bind the [`ConditionSliceExt`] refinement
11570 // algebra (find ↔ iter, count ↔ iter, has ↔ find, has ↔ count) at
11571 // ONE call site per authored arrangement, sweeping
11572 // [`ConditionKind::ALL`]. The four hand-authored slice-level
11573 // composition-law tests above
11574 // (`condition_slice_find_kind_equals_iter_kind_next`,
11575 // `condition_slice_count_kind_equals_iter_kind_count`,
11576 // `condition_slice_has_kind_equals_find_kind_is_some`,
11577 // `condition_slice_has_and_find_equal_count_greater_than_zero`)
11578 // stay as first-class per-law drift-arm pins; this substrate
11579 // testkit is the compound-lift primitive that binds all four
11580 // laws through ONE typed sweep so a future FIFTH refinement's
11581 // composition law picks up its pin as ONE new arm inside the
11582 // primitive's body rather than as ONE new sibling test at every
11583 // downstream author-time enumeration.
11584
11585 /// SUBSTRATE PANEL pin — the substrate testkit primitive
11586 /// [`assert_slice_refinement_composition_laws`] passes on the
11587 /// FOUR canonical authored arrangements the trait's downstream
11588 /// consumers reach for: the empty slice (every refinement returns
11589 /// its zero-element identity), a single-element populated slice
11590 /// (every refinement returns the addressed match's projection),
11591 /// a dual-populated slice with distinct kinds (every refinement
11592 /// probes the kind field per element), and a duplicate-populated
11593 /// slice with the same kind at multiple positions (the widened
11594 /// primitive `iter_kind` yields every match; `find_kind` collapses
11595 /// to the first; `count_kind` returns the exact cardinality;
11596 /// `has_kind` returns true). Sweeping the four arrangements at
11597 /// ONE call site pins that every composition law holds regardless
11598 /// of the widened primitive's yield structure.
11599 #[test]
11600 fn slice_refinement_composition_laws_hold_across_authored_arrangements() {
11601 let empty: &[Condition] = &[];
11602 assert_slice_refinement_composition_laws(empty);
11603
11604 for populated in ConditionKind::ALL {
11605 let single = [condition_with(populated)];
11606 assert_slice_refinement_composition_laws(single.as_slice());
11607 }
11608
11609 for pre_kind in ConditionKind::ALL {
11610 for post_kind in ConditionKind::ALL {
11611 let dual = [condition_with(pre_kind), condition_with(post_kind)];
11612 assert_slice_refinement_composition_laws(dual.as_slice());
11613 }
11614 }
11615
11616 for populated in ConditionKind::ALL {
11617 let duplicates = [
11618 condition_with(populated),
11619 condition_with(populated),
11620 condition_with(populated),
11621 ];
11622 assert_slice_refinement_composition_laws(duplicates.as_slice());
11623 }
11624 }
11625
11626 /// SUBSTRATE PANEL pin (params-distinguishable duplicates) — the
11627 /// substrate primitive holds on a slice that carries duplicate
11628 /// kinds interleaved with a distinct kind, byte-for-byte peer of
11629 /// the standalone `condition_slice_iter_kind_yields_every_match_in_slice_order_on_duplicates`
11630 /// / `condition_slice_count_kind_counts_every_match_on_duplicates`
11631 /// arrangement. Confirms the four composition laws hold when
11632 /// the widened primitive's yield stream is genuinely multi-element
11633 /// AND the addressed kind is interleaved with a non-matching kind
11634 /// (the union structural case that the diagonal-and-corners sweep
11635 /// above doesn't reach).
11636 #[test]
11637 fn slice_refinement_composition_laws_hold_on_interleaved_duplicates() {
11638 let interleaved = [
11639 Condition {
11640 kind: ConditionKind::ClosedLoopAuth,
11641 params: json!({ "probeImage": "first" }),
11642 },
11643 Condition {
11644 kind: ConditionKind::PromQL,
11645 params: json!({ "query": "up" }),
11646 },
11647 Condition {
11648 kind: ConditionKind::ClosedLoopAuth,
11649 params: json!({ "probeImage": "second" }),
11650 },
11651 Condition {
11652 kind: ConditionKind::PromQL,
11653 params: json!({ "query": "healthy" }),
11654 },
11655 Condition {
11656 kind: ConditionKind::ClosedLoopAuth,
11657 params: json!({ "probeImage": "third" }),
11658 },
11659 ];
11660 assert_slice_refinement_composition_laws(interleaved.as_slice());
11661 }
11662
11663 // ── assert_surface_union_composition_laws — substrate testkit ────
11664 //
11665 // The substrate testkit macro
11666 // [`crate::assert_surface_union_composition_laws`] pins the FOUR
11667 // union composition laws (has: OR, find: or_else, iter: chain,
11668 // count: SUM) that bind the (pre, post, union) refinement triads
11669 // on the [`Boundary`] surface at ONE call site per authored
11670 // arrangement, sweeping [`ConditionKind::ALL`]. The four hand-
11671 // authored point-surface composition-law tests above
11672 // (`boundary_has_condition_kind_composes_precondition_and_postcondition_arms`,
11673 // `find_condition_kind_triad_delegates_to_slice_find_kind`,
11674 // `iter_condition_kind_triad_delegates_to_slice_iter_kind`,
11675 // `boundary_count_condition_kind_triad_delegates_and_sums_slice_count_kind`)
11676 // stay as first-class per-law drift-arm pins; this substrate
11677 // testkit macro is the compound-lift primitive that binds all
11678 // four union composition laws through ONE typed sweep so a
11679 // future FIFTH union refinement picks up its composition-law
11680 // pin as ONE new arm inside the macro body rather than as ONE
11681 // new sibling test at every downstream author-time
11682 // enumeration on each of the two surfaces.
11683
11684 /// SUBSTRATE PANEL pin — the substrate testkit macro
11685 /// [`crate::assert_surface_union_composition_laws`] passes on
11686 /// [`Boundary`] for the four canonical authored arrangements the
11687 /// surface's downstream consumers reach for: the empty boundary
11688 /// (every union arm returns its zero-element identity), a
11689 /// precondition-only populated boundary (every union arm equals
11690 /// its precondition arm, postcondition arm is empty), a
11691 /// postcondition-only populated boundary (mirror), and a dual-
11692 /// populated boundary sweeping `ALL × ALL` (both half-slice arms
11693 /// contribute; the union monoid operator applies). Sweeping the
11694 /// four arrangements at ONE call site pins every union
11695 /// composition law holds regardless of the arrangement's per-
11696 /// half fill pattern.
11697 #[test]
11698 fn boundary_surface_union_composition_laws_hold_across_authored_arrangements() {
11699 let empty = Boundary::default();
11700 crate::assert_surface_union_composition_laws!(empty);
11701
11702 for populated in ConditionKind::ALL {
11703 let mut pre_only = Boundary::default();
11704 pre_only.preconditions.push(condition_with(populated));
11705 crate::assert_surface_union_composition_laws!(pre_only);
11706
11707 let mut post_only = Boundary::default();
11708 post_only.postconditions.push(condition_with(populated));
11709 crate::assert_surface_union_composition_laws!(post_only);
11710 }
11711
11712 for pre_kind in ConditionKind::ALL {
11713 for post_kind in ConditionKind::ALL {
11714 let mut dual = Boundary::default();
11715 dual.preconditions.push(condition_with(pre_kind));
11716 dual.postconditions.push(condition_with(post_kind));
11717 crate::assert_surface_union_composition_laws!(dual);
11718 }
11719 }
11720 }
11721
11722 /// SUBSTRATE PANEL pin (params-distinguishable duplicates) — the
11723 /// substrate macro holds on a [`Boundary`] whose two half-slices
11724 /// each carry duplicates of the same kind at multiple positions,
11725 /// interleaved with a distinct kind. The scenario reaches every
11726 /// union arm at its non-degenerate composition: `has` still
11727 /// resolves `true` on both halves (OR is not the discriminating
11728 /// bit), `find` yields the FIRST-precondition-side match
11729 /// (`or_else` walk order), `iter` yields every match with the
11730 /// full pre-then-post chain order (five total matches across the
11731 /// two halves), `count` returns the SUM (five). A regression that
11732 /// (a) collapsed `find`'s `or_else` to `and_then` (silently
11733 /// narrowing to intersection), (b) collapsed `iter`'s `chain` to
11734 /// `zip` (silently truncating to `min(pre, post)`), or (c)
11735 /// collapsed `count`'s SUM to `max` (silently narrowing the
11736 /// cardinality) surfaces HERE — the four laws are pinned
11737 /// simultaneously and any single-arm regression fails one of
11738 /// the four asserts.
11739 #[test]
11740 fn boundary_surface_union_composition_laws_hold_on_interleaved_duplicates() {
11741 let mut b = Boundary::default();
11742 b.preconditions.push(Condition {
11743 kind: ConditionKind::ClosedLoopAuth,
11744 params: json!({ "side": "pre-1" }),
11745 });
11746 b.preconditions.push(Condition {
11747 kind: ConditionKind::PromQL,
11748 params: json!({ "query": "up" }),
11749 });
11750 b.preconditions.push(Condition {
11751 kind: ConditionKind::ClosedLoopAuth,
11752 params: json!({ "side": "pre-2" }),
11753 });
11754 b.postconditions.push(Condition {
11755 kind: ConditionKind::PromQL,
11756 params: json!({ "query": "healthy" }),
11757 });
11758 b.postconditions.push(Condition {
11759 kind: ConditionKind::ClosedLoopAuth,
11760 params: json!({ "side": "post-1" }),
11761 });
11762 crate::assert_surface_union_composition_laws!(b);
11763 }
11764}