edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBb207cf9Tahinli2 months ago3506 commits
| 1 | #!/usr/bin/env bash |
| 2 | # verify-fixture-library.sh — preflight: does the on-disk fixture library match |
| 3 | # what the tests actually reach for? |
| 4 | # |
| 5 | # CHECKS |
| 6 | # SHAPE the manifest exists, is non-empty, and every row has 5 columns |
| 7 | # RESOLVE every referenced path exists, and every referenced DIRECTORY is |
| 8 | # non-empty (a present-but-empty corpus is the same false green as |
| 9 | # an absent one) |
| 10 | # DRIFT regenerating the manifest from source reproduces the committed |
| 11 | # file -- so a host whose library is behind the code fails here |
| 12 | # instead of reporting a green suite full of SKIPs |
| 13 | # |
| 14 | # TWO FAILURE MODES ARE DISTINGUISHED, because they have different fixes: |
| 15 | # (i) the fixture ROOT itself is absent. Root `fixtures/` is .gitignore:2, |
| 16 | # so no linked worktree ever has it: every vector gate skips GREEN in |
| 17 | # every worktree run. Fix: link or provision the library, not the code. |
| 18 | # (ii) a path under a PRESENT root is absent (or an empty dir). Fix: the |
| 19 | # generator named in the row, or the pin is genuinely missing. |
| 20 | # |
| 21 | # ENFORCEMENT ENV: EC_REQUIRE_FIXTURES=1 -- the same env the per-crate `require_fixture` asserts |
| 22 | # honour, so one convention covers the fleet batch units and a local run: |
| 23 | # set -> any absent referenced path is RED, and the drift diff is RED |
| 24 | # unset -> the same findings are printed SKIP-shaped and the exit stays 0, |
| 25 | # so an unprepared local checkout is not blocked |
| 26 | # |
| 27 | # EXIT STATUS is the LIBRARY verdict: mode i, mode ii, or drift. The four |
| 28 | # code-shape invariants (forbidden root-fixture path, pin tracking, .gitignore |
| 29 | # negation, pin-reading gate census) are REPORTED with their own count and fail |
| 30 | # only under EC_FIXTURE_SHAPE_STRICT=1. That split is deliberate: a shape |
| 31 | # violation is a defect in a file this preflight does not own, and a batch that |
| 32 | # cannot start because another crate has two open lines helps nobody -- but the |
| 33 | # findings are printed, counted, and one env var away from being fatal, so |
| 34 | # nothing is hidden. Set EC_FIXTURE_SHAPE_STRICT=1 in a tree whose shape |
| 35 | # violations you intend to fix. |
| 36 | # |
| 37 | # Usage: scripts/verify-fixture-library.sh |
| 38 | # Env: EC_FIXTURES=<dir> fixture root, as every generator takes |
| 39 | # EC_REQUIRE_FIXTURES=1|0 enforcement (see above) |
| 40 | # |
| 41 | # ENUMERATION BLIND SPOT: the scan is grep-derived, so a fixture name that is |
| 42 | # not a string literal in the same file (a row of |
| 43 | # fixtures/real-library-manifest.tsv, a name in scripts/vectors.sha256, a |
| 44 | # format! interpolation) is not enumerated individually. Its parent directory |
| 45 | # is, and RESOLVE requires that directory to exist and be non-empty. This is a |
| 46 | # preflight against silent drift, not a proof that every byte a test reads is |
| 47 | # present. |
| 48 | |
| 49 | |
| 50 | |
| 51 | ROOT= |
| 52 | MANIFEST=/scripts/fixture-library.tsv |
| 53 | FIXTURES= |
| 54 | REQUIRE= |
| 55 | # Code-shape invariants fail only when explicitly made fatal: `scripts/ |
| 56 | # verify-fixture-library.sh --strict` or EC_FIXTURE_SHAPE_STRICT=1. The default |
| 57 | # flips to fatal when the last live violation is fixed. |
| 58 | SHAPE= |
| 59 | # `--strict` on the command line is the same switch, so the default can be |
| 60 | # flipped with a one-character edit the moment the last shape violation lands. |
| 61 | case " " in |
| 62 | *" --strict "*) SHAPE=1 ;; |
| 63 | esac |
| 64 | LINK_SCRIPT=/scripts/link-fixtures.sh |
| 65 | |
| 66 | fail=0 |
| 67 | shape_fail=0 |
| 68 | shape_violations=0 |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | # --- SHAPE --------------------------------------------------------------- |
| 74 | if [; then |
| 75 | |
| 76 | |
| 77 | fi |
| 78 | rows= |
| 79 | if [; then |
| 80 | |
| 81 | |
| 82 | fi |
| 83 | malformed= |
| 84 | if [; then |
| 85 | |
| 86 | |
| 87 | |
| 88 | fi |
| 89 | |
| 90 | |
| 91 | # --- ROOT MODE (i) -------------------------------------------------------- |
| 92 | root_present=1 |
| 93 | [ || root_present=0 |
| 94 | if [; then |
| 95 | tag=SKIP |
| 96 | [ && tag=FAIL |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | if [; then |
| 102 | |
| 103 | else |
| 104 | |
| 105 | fi |
| 106 | [ && fail=1 |
| 107 | fi |
| 108 | |
| 109 | # --- RESOLVE -------------------------------------------------------------- |
| 110 | missing=() |
| 111 | empty=() |
| 112 | while ; do |
| 113 | case in |
| 114 | \#* | '') continue ;; |
| 115 | esac |
| 116 | case in |
| 117 | absent-pin) continue ;; # known gap, reported as a finding |
| 118 | esac |
| 119 | case in |
| 120 | fixtures) abs= ;; |
| 121 | fixtures/*) abs=/ ;; |
| 122 | *) abs=/ ;; |
| 123 | esac |
| 124 | if [; then |
| 125 | missing+=(" <- (, generator: )") |
| 126 | elif [ && [; then |
| 127 | empty+=(" <- (, generator: )") |
| 128 | fi |
| 129 | done |
| 130 | |
| 131 | if && [; then |
| 132 | if [; then |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | fail=1 |
| 138 | else |
| 139 | |
| 140 | |
| 141 | |
| 142 | fi |
| 143 | fi |
| 144 | if ; then |
| 145 | if [; then |
| 146 | |
| 147 | |
| 148 | fail=1 |
| 149 | else |
| 150 | |
| 151 | |
| 152 | fi |
| 153 | fi |
| 154 | |
| 155 | |
| 156 | # --- FINDINGS (not failures, but stated) --------------------------------- |
| 157 | no_prov= |
| 158 | absent= |
| 159 | if [; then |
| 160 | n= |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | fi |
| 166 | if [; then |
| 167 | |
| 168 | |
| 169 | fi |
| 170 | |
| 171 | # --- HARD INVARIANT 1: the forbidden root-fixture shape --------------------- |
| 172 | # `concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/<file>")` names a |
| 173 | # ROOT-level committed pin through the gitignored `fixtures/`. No committed pin |
| 174 | # can satisfy it, so on any clean checkout or runner the gate silently skips -- |
| 175 | # the worst shape in the class (the film-grain instance combined it with |
| 176 | # `.unwrap()`, so a clean checkout PANICKED instead). A root SUBDIRECTORY |
| 177 | # (`fixtures/audio`, `fixtures/vectors/...`) is a different thing: those are |
| 178 | # produced by a generator named in the manifest, so they are not forbidden here. |
| 179 | # Comments are stripped first: a doc comment that REPRODUCES the forbidden |
| 180 | # literal to explain what was fixed is prose, not code, and a grep cannot tell |
| 181 | # the difference. One such comment in crates/ec-av1 read as a live violation for |
| 182 | # a whole round (found by the lane that fixed the real ones). |
| 183 | forbidden= |
| 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 | # POSITIVE CONTROL. A comment-stripping bug makes this scan match NOTHING, and |
| 209 | # "no violations" would then be indistinguishable from a scanner that is blind. |
| 210 | # So before trusting the result, plant a known forbidden literal in a scratch |
| 211 | # file and require the scanner to catch it. A scanner that cannot find a literal |
| 212 | # it is looking at is broken, not clean. |
| 213 | control= |
| 214 | |
| 215 | control_hit= |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | if [; then |
| 225 | |
| 226 | |
| 227 | |
| 228 | shape_fail=1 |
| 229 | fail=1 |
| 230 | else |
| 231 | |
| 232 | fi |
| 233 | |
| 234 | if [; then |
| 235 | if [; then |
| 236 | |
| 237 | |
| 238 | | |
| 239 | |
| 240 | |
| 241 | shape_fail=1 |
| 242 | else |
| 243 | |
| 244 | |
| 245 | | |
| 246 | fi |
| 247 | else |
| 248 | |
| 249 | fi |
| 250 | |
| 251 | # --- HARD INVARIANT 2: every committed pin is present AND tracked ----------- |
| 252 | # A pin on disk but untracked is lost when the machine's scratchpad is reaped, |
| 253 | # and its gate then skips GREEN. `tracked` is computed at generation time in a |
| 254 | # git tree; a runner host has no .git, so it asserts the committed value. |
| 255 | untracked= |
| 256 | if [; then |
| 257 | if [; then |
| 258 | |
| 259 | | |
| 260 | |
| 261 | |
| 262 | |
| 263 | shape_fail=1 |
| 264 | else |
| 265 | |
| 266 | | |
| 267 | fi |
| 268 | else |
| 269 | |
| 270 | fi |
| 271 | |
| 272 | # --- HARD INVARIANT 3: the .gitignore negation is intact -------------------- |
| 273 | if ! ; then |
| 274 | |
| 275 | |
| 276 | shape_fail=1 |
| 277 | else |
| 278 | |
| 279 | if [; then |
| 280 | shadowed= |
| 281 | |
| 282 | |
| 283 | |
| 284 | if [; then |
| 285 | |
| 286 | | |
| 287 | shape_fail=1 |
| 288 | else |
| 289 | |
| 290 | fi |
| 291 | else |
| 292 | |
| 293 | fi |
| 294 | fi |
| 295 | |
| 296 | # --- HARD INVARIANT 4: the pin-reading GATE census ------------------------- |
| 297 | # The per-pin invariant is blind to a gate that reads N pins through a root |
| 298 | # literal plus a runtime name list, and to a gate that only asserts inside a |
| 299 | # helper. scripts/pin-gate-audit.py resolves the root literal, enumerates the |
| 300 | # runtime names, checks each against a tracked committed copy, and classifies |
| 301 | # assertions through the helper CALL GRAPH. Counts are printed, not summarised. |
| 302 | if ! ; then |
| 303 | |
| 304 | fail=1 |
| 305 | else |
| 306 | selftest_out= |
| 307 | audit= |
| 308 | if [ && [; then |
| 309 | |
| 310 | fail=1 |
| 311 | fi |
| 312 | | |
| 313 | # The census's own POSITIVE CONTROL. Losing a gate to a doc comment is |
| 314 | # SILENT -- the count drops and nothing goes red -- so a control that only |
| 315 | # proved "the scanner finds a bad literal" would not catch it. This one |
| 316 | # plants the exact shape: a comment reproducing the forbidden literal |
| 317 | # inside a gate that reads crate_pin. |
| 318 | if ! ; then |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | fail=1 |
| 324 | else |
| 325 | |
| 326 | fi |
| 327 | badrows= |
| 328 | bardir= |
| 329 | absent= |
| 330 | if [ || [; then |
| 331 | if [; then |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | shape_fail=1 |
| 340 | else |
| 341 | |
| 342 | |
| 343 | |
| 344 | fi |
| 345 | else |
| 346 | |
| 347 | fi |
| 348 | # assertless gates are printed, never failed: a #[ignore]d gate that asserts |
| 349 | # nothing is a finding for its owner, not a preflight failure. |
| 350 | | |
| 351 | fi |
| 352 | |
| 353 | # --- RECOVERED-PIN SELF-VALIDATION ----------------------------------------- |
| 354 | # A recovered witness is the historical bytes; a re-encode is a DIFFERENT stream. |
| 355 | # Hashing what is on disk against the recorded sha256 is the half a shell |
| 356 | # preflight can decide. The other half is behavioural and needs the gate: |
| 357 | # `pinned_golden7` records non_last_ref_hits 0->2 in its own doc, and the |
| 358 | # recovered pin reproduces exactly that; only running the gate proves it. |
| 359 | badsum=0 |
| 360 | while ; do |
| 361 | case in |
| 362 | \#* | '') continue ;; |
| 363 | esac |
| 364 | [ || continue |
| 365 | abs=/ |
| 366 | if [; then |
| 367 | |
| 368 | fail=1 |
| 369 | continue |
| 370 | fi |
| 371 | have= |
| 372 | if [; then |
| 373 | |
| 374 | |
| 375 | fail=1 |
| 376 | badsum= |
| 377 | fi |
| 378 | done |
| 379 | [ && |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | # --- VECTORS ------------------------------------------------------------- |
| 385 | vec_rows= |
| 386 | vec_missing= |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | # --- DRIFT ---------------------------------------------------------------- |
| 392 | regen= |
| 393 | patch= |
| 394 | |
| 395 | if ! ; then |
| 396 | |
| 397 | |
| 398 | fi |
| 399 | # The `tracked` column is COMMITTED provenance: it is computed in a git tree. |
| 400 | # A runner host has no .git, so a regeneration there cannot recompute it and |
| 401 | # would emit 'no-git' for every committed pin -- a drift on all 37 pin rows that |
| 402 | # says nothing about the host's library. Off-git the column is normalised on both |
| 403 | # sides, and the tracked invariant falls back to the committed value (as its own |
| 404 | # message already says). |
| 405 | |
| 406 | OFFGIT=0 |
| 407 | [ || OFFGIT=1 |
| 408 | if ! ; then |
| 409 | if [; then |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | fail=1 |
| 418 | else |
| 419 | |
| 420 | |
| 421 | |
| 422 | fi |
| 423 | else |
| 424 | |
| 425 | fi |
| 426 | |
| 427 | if [; then |
| 428 | |
| 429 | |
| 430 | fi |
| 431 | if [ && [; then |
| 432 | |
| 433 | |
| 434 | fi |
| 435 | # The shape tally is always printed, fatal only under EC_FIXTURE_SHAPE_STRICT. |
| 436 | for; do ; done |
| 437 | |
| 438 | | && shape_violations= |
| 439 |