1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
//! The shared runtime half of the `ROSTER` contract.
//!
//! Completeness is proved at compile time: the `roster!` macro builds the
//! constant and an exhaustive `match` from one list, so a variant missing
//! from the roster is `E0004` with the compiler naming it. Two properties
//! survive that proof and need running code:
//!
//! - a **duplicate** entry. A list that names one variant twice and still
//! names every other variant once leaves the witness exhaustive, so the
//! compiler has nothing to say about it.
//! - a **slug collision**. Two variants rendering the same string keep the
//! roster well-formed while making `FromStr` unable to return both, so
//! the parse round-trip stops being the inverse of the render.
//!
//! [`check`] takes the type's `as_str` as a function rather than going
//! through [`Display`](core::fmt::Display), so the checks run at the
//! no-alloc tier too — `to_string` would need an allocator the lean build
//! does not have.
use ;
/// Asserts the two runtime properties of a `ROSTER`, for one type.
///
/// `what` names the type in the failure message; `as_str` is the type's
/// canonical renderer.
pub
/// One vocabulary's extension entries, as gathered by
/// [`extension_entries_of`]: `(extension, the owning variant's Debug)`,
/// one pair per `(variant, alias)` combination.
type ExtensionEntries = Vec;
/// Gathers every `(extension, variant)` pair a roster's own
/// [`Format::extensions`](crate::container::Format::extensions)-shaped
/// method emits, for every named variant. Generic over the accessor
/// rather than the type, so the three call sites in
/// [`container_and_audio_and_image_extension_entries`] are one line each
/// with no hand-transcribed extension lists to drift from the real
/// `extensions()` tables.
/// The three extension-bearing vocabularies' entries, gathered
/// programmatically from their own `ROSTER` + `extensions()` — no hand
/// list of extensions here to drift from the real tables in
/// `container::Format`, `audio::ContainerFormat`, and `image::Format`
/// themselves.
/// Asserts no two *different* vocabularies in `rosters` claim the same
/// extension — `rosters` is `(vocabulary name, its extension entries)`.
///
/// findit's directory-walk filter unions every extension-bearing
/// vocabulary's `ROSTER` into one `BTreeSet<&str>` (its own module doc
/// calls this "ONE question being asked twice rather than two lists to be
/// searched in turn") to decide which files are offered to the demuxer.
/// That union is only sound if the same extension is never claimed by two
/// *different* formats that a consumer might need to tell apart — a
/// duplicate **within** one format's own alias list is fine
/// (`ContainerFormat::Alac` and `ContainerFormat::M4a` both legitimately
/// extend `.m4a`: one string, either reading is correct), but a duplicate
/// **across** vocabularies would make "which format is this extension"
/// ambiguous the moment a caller (present or future) needs that answer
/// rather than a plain yes/no. Only the *owning vocabulary* is compared
/// for exactly that reason — two variants of the SAME vocabulary sharing
/// an extension is outside this check's concern, by design.
///
/// Factored out of [`container_audio_image_extensions_are_disjoint`] so
/// [`disjointness_check_catches_a_synthetic_cross_vocabulary_collision`]
/// can drive the identical logic against a deliberately-colliding
/// synthetic dataset — a checker that has only ever run against clean
/// real data and was never proven to fire on a real collision is not yet
/// proven to fire at all.
/// Asserts `rosters`' gathered entry count for `vocab` is *exactly* the
/// sum of `expected_extensions_len` over that vocabulary's own `ROSTER` —
/// not `>=`, an exact match.
///
/// This is the general-purpose successor to spot-checking specific
/// aliases (`container_audio_image_extensions_are_disjoint`'s R2 version
/// checked four representative ones: `.m2ts`, `.aif`, `.oga`, `.ori`).
/// Codex R3's finding on that version: every one of those four happened
/// to be each variant's *second* `extensions()` entry, so a gatherer
/// regressed to `.iter().take(2)` per variant would still pass all four
/// checks while `.mts`/`.m2t`/`.aifc`/`.spx`/`.jpe`/`.hif` (third-or-later
/// entries at the time — `.hif` has since been excluded from every
/// roster outright, R8) silently vanished. A **count** cannot be fooled by *which*
/// entries a truncation drops — any drop, duplication, or off-by-one at
/// any position in any variant's list changes the sum, so this one
/// assertion subsumes what an unbounded number of spot-checks would
/// otherwise need to enumerate one alias at a time.
/// The runtime proof that the three extension-bearing vocabularies —
/// [`crate::container::Format`], [`crate::audio::ContainerFormat`], and
/// [`crate::image::Format`] — hold [`assert_extensions_disjoint`]'s
/// property today, the same way [`check`] proves within-roster
/// uniqueness. It is written to *report* an overlap rather than assume
/// there is none, per this crate's own honesty-over-silence convention: a
/// future roster addition that collides fails here with the offending
/// extension and both owning formats named, not with a silent
/// three-instead-of-four count somewhere downstream.
///
/// Every entry from every roster's `extensions()` is checked — not just
/// each type's `as_extension()` primary spelling — so a documented alias
/// (`container::Format::MpegTs`'s `.m2ts`, `audio::ContainerFormat::Aiff`'s
/// `.aifc`, …) colliding with another vocabulary would be caught here
/// too, not just a collision on the three primaries.
///
/// **Before trusting that**, this test asserts each vocabulary's gathered
/// entry count *exactly* matches summing `extensions().len()` directly
/// over its own `ROSTER` — see [`assert_exact_gathered_cardinality`]'s own
/// doc for why an exact count, not a handful of spot-checked aliases, is
/// what actually rules out a truncating gatherer. [`extension_entries_of`]
/// is the one place all the real `ROSTER` + `extensions()` data funnels
/// through before reaching [`assert_extensions_disjoint`]; a starved
/// gatherer would make the disjointness check below pass for the wrong
/// reason — *fewer* entries can only make a collision *less* likely to be
/// found, so "clean" from a starved gatherer looks identical to "clean"
/// from a complete one. This is the check that tells them apart, run
/// before the disjointness assertion so a starved gatherer fails here
/// first and names exactly how far off the count is.
///
/// Gated on `any(std, alloc)` — unlike [`check`], this one is not
/// tier-agnostic: all three vocabularies it names, plus the
/// `BTreeMap`/`String` bookkeeping, only exist at that tier. `roster_tests`
/// itself has no such gate (`check` must run at the no-alloc tier too), so
/// the gate lives on this function rather than the module.
/// Two synthetic vocabularies that exist for exactly one reason: to give
/// [`disjointness_check_catches_a_synthetic_cross_vocabulary_collision`] a
/// collision to drive through the *real* [`extension_entries_of`]
/// gathering path — synthetic `ROSTER` + accessor, not real container /
/// audio / image data.
///
/// **Each roster carries the colliding variant third**, behind two
/// decoys with distinct, non-colliding extensions
/// (`Decoy1`/`Decoy2` → `zzsynthetic-{a,b}-decoy{1,2}`, `Collider` →
/// `zzsynthetic-collision`). Codex R3's finding on the R2 version (a
/// single-variant roster per vocabulary): the collision was every
/// synthetic roster's *only* entry, so a gatherer regressed to
/// `.iter().take(1)` or `.take(2)` on the *roster* itself (as opposed to
/// per-variant `extensions()`, which [`assert_exact_gathered_cardinality`]
/// covers) would still carry the collision through untouched and this
/// test would keep passing — "one entry, positioned first" cannot
/// distinguish a gatherer that iterates the whole roster from one that
/// silently stops after N. Two unique, non-colliding entries ahead of the
/// collider close that gap: only a gatherer that genuinely walks the full
/// roster ever reaches the collision at all.
const SYNTHETIC_VOCAB_A_ROSTER: & = &;
const SYNTHETIC_VOCAB_B_ROSTER: & = &;
/// Proves [`assert_extensions_disjoint`] actually has teeth — and, unlike
/// the R1 version of this test, proves it **through the same gathering
/// path the real check uses**, not by calling
/// [`assert_extensions_disjoint`] directly with a hand-built collision.
///
/// Two rounds of Codex findings shaped this test's current construction:
/// - **R2**: the R1 version constructed pre-flattened `ExtensionEntries`
/// and skipped [`extension_entries_of`] entirely, so a regression in
/// the gatherer itself — the exact failure class R1 was fixing — would
/// have left both this test and the real disjointness test green.
/// Fixed by routing the synthetic collision through
/// [`extension_entries_of`] (via [`SyntheticVocabA`] / [`SyntheticVocabB`]
/// standing in for real roster types).
/// - **R3**: the R2 version's synthetic rosters had exactly one entry
/// each — the collider, first and only — so a gatherer that silently
/// stopped after the first roster item (or first two) would still
/// carry the collision through untouched, proving nothing about
/// whether the gatherer walks a *whole* roster. Fixed by giving each
/// synthetic roster two non-colliding decoys ahead of the collider —
/// see [`SyntheticVocabA`]'s own doc.
///
/// Fed a synthetic two-vocabulary dataset that deliberately collides on
/// one extension, it must panic and name both the extension and the two
/// owning `vocab::variant` pairs — "no collision found" and "incapable of
/// finding a collision" must not read identically from a green checkmark.