edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 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 | # THE TWO ROOTS (lane-av1clipprobe). This script validates `$EC_FIXTURES`, |
| 50 | # defaulting to `$ROOT/fixtures`. The gates used to read `$ROOT/fixtures` |
| 51 | # UNCONDITIONALLY, so pointing EC_FIXTURES at a library elsewhere printed |
| 52 | # `resolve 0 missing` and `GREEN` here while every clip gate skipped -- a green |
| 53 | # preflight over gates reading a tree nobody validated. The clip-reading gates |
| 54 | # now resolve through the same precedence this script does (EC_FIXTURES first, |
| 55 | # `$ROOT/fixtures` otherwise: `crates/ec-av1/src/library_fixture.rs`), so the |
| 56 | # verdict below and the bytes the tests read are the same tree in every |
| 57 | # combination, and mode (i) below fires exactly when the gates will skip. |
| 58 | |
| 59 | |
| 60 | |
| 61 | ROOT= |
| 62 | MANIFEST=/scripts/fixture-library.tsv |
| 63 | FIXTURES= |
| 64 | REQUIRE= |
| 65 | # Code-shape invariants fail only when explicitly made fatal: `scripts/ |
| 66 | # verify-fixture-library.sh --strict` or EC_FIXTURE_SHAPE_STRICT=1. The default |
| 67 | # flips to fatal when the last live violation is fixed. |
| 68 | SHAPE= |
| 69 | # `--strict` on the command line is the same switch, so the default can be |
| 70 | # flipped with a one-character edit the moment the last shape violation lands. |
| 71 | case " " in |
| 72 | *" --strict "*) SHAPE=1 ;; |
| 73 | esac |
| 74 | LINK_SCRIPT=/scripts/link-fixtures.sh |
| 75 | |
| 76 | fail=0 |
| 77 | shape_fail=0 |
| 78 | shape_violations=0 |
| 79 | |
| 80 | |
| 81 | |
| 82 | # The gates' root is the SAME string, by the reconciliation documented above -- |
| 83 | # printed here so a reader comparing this verdict against a gate's SKIP line |
| 84 | # never has to guess which of two directories the two sides meant. |
| 85 | |
| 86 | |
| 87 | # --- SHAPE --------------------------------------------------------------- |
| 88 | if [; then |
| 89 | |
| 90 | |
| 91 | fi |
| 92 | rows= |
| 93 | if [; then |
| 94 | |
| 95 | |
| 96 | fi |
| 97 | malformed= |
| 98 | if [; then |
| 99 | |
| 100 | |
| 101 | |
| 102 | fi |
| 103 | |
| 104 | |
| 105 | # --- ROOT MODE (i) -------------------------------------------------------- |
| 106 | root_present=1 |
| 107 | [ || root_present=0 |
| 108 | if [; then |
| 109 | tag=SKIP |
| 110 | [ && tag=FAIL |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | if [; then |
| 116 | |
| 117 | else |
| 118 | |
| 119 | fi |
| 120 | [ && fail=1 |
| 121 | fi |
| 122 | |
| 123 | # --- RESOLVE -------------------------------------------------------------- |
| 124 | missing=() |
| 125 | empty=() |
| 126 | while ; do |
| 127 | case in |
| 128 | \#* | '') continue ;; |
| 129 | esac |
| 130 | case in |
| 131 | absent-pin) continue ;; # known gap, reported as a finding |
| 132 | esac |
| 133 | case in |
| 134 | fixtures) abs= ;; |
| 135 | fixtures/*) abs=/ ;; |
| 136 | *) abs=/ ;; |
| 137 | esac |
| 138 | if [; then |
| 139 | missing+=(" <- (, generator: )") |
| 140 | elif [ && [; then |
| 141 | empty+=(" <- (, generator: )") |
| 142 | fi |
| 143 | done |
| 144 | |
| 145 | if && [; then |
| 146 | if [; then |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | fail=1 |
| 152 | else |
| 153 | |
| 154 | |
| 155 | |
| 156 | fi |
| 157 | fi |
| 158 | if ; then |
| 159 | if [; then |
| 160 | |
| 161 | |
| 162 | fail=1 |
| 163 | else |
| 164 | |
| 165 | |
| 166 | fi |
| 167 | fi |
| 168 | |
| 169 | |
| 170 | # --- FINDINGS (not failures, but stated) --------------------------------- |
| 171 | no_prov= |
| 172 | absent= |
| 173 | if [; then |
| 174 | n= |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | fi |
| 180 | if [; then |
| 181 | |
| 182 | |
| 183 | fi |
| 184 | |
| 185 | # --- HARD INVARIANT 1: the forbidden root-fixture shape --------------------- |
| 186 | # `concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/<file>")` names a |
| 187 | # ROOT-level committed pin through the gitignored `fixtures/`. No committed pin |
| 188 | # can satisfy it, so on any clean checkout or runner the gate silently skips -- |
| 189 | # the worst shape in the class (the film-grain instance combined it with |
| 190 | # `.unwrap()`, so a clean checkout PANICKED instead). A root SUBDIRECTORY |
| 191 | # (`fixtures/audio`, `fixtures/vectors/...`) is a different thing: those are |
| 192 | # produced by a generator named in the manifest, so they are not forbidden here. |
| 193 | # Comments are stripped first: a doc comment that REPRODUCES the forbidden |
| 194 | # literal to explain what was fixed is prose, not code, and a grep cannot tell |
| 195 | # the difference. One such comment in crates/ec-av1 read as a live violation for |
| 196 | # a whole round (found by the lane that fixed the real ones). |
| 197 | forbidden= |
| 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 | # POSITIVE CONTROL. A comment-stripping bug makes this scan match NOTHING, and |
| 232 | # "no violations" would then be indistinguishable from a scanner that is blind. |
| 233 | # So before trusting the result, plant a known forbidden literal in a scratch |
| 234 | # file and require the scanner to catch it. A scanner that cannot find a literal |
| 235 | # it is looking at is broken, not clean. |
| 236 | control= |
| 237 | |
| 238 | control_hit= |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | if [; then |
| 248 | |
| 249 | |
| 250 | |
| 251 | shape_fail=1 |
| 252 | fail=1 |
| 253 | else |
| 254 | |
| 255 | fi |
| 256 | |
| 257 | if [; then |
| 258 | if [; then |
| 259 | |
| 260 | |
| 261 | | |
| 262 | |
| 263 | |
| 264 | shape_fail=1 |
| 265 | else |
| 266 | |
| 267 | |
| 268 | | |
| 269 | fi |
| 270 | else |
| 271 | |
| 272 | fi |
| 273 | |
| 274 | # --- HARD INVARIANT 2: every committed pin is present AND tracked ----------- |
| 275 | # A pin on disk but untracked is lost when the machine's scratchpad is reaped, |
| 276 | # and its gate then skips GREEN. `tracked` is computed at generation time in a |
| 277 | # git tree; a runner host has no .git, so it asserts the committed value. |
| 278 | untracked= |
| 279 | if [; then |
| 280 | if [; then |
| 281 | |
| 282 | | |
| 283 | |
| 284 | |
| 285 | |
| 286 | shape_fail=1 |
| 287 | else |
| 288 | |
| 289 | | |
| 290 | fi |
| 291 | else |
| 292 | |
| 293 | fi |
| 294 | |
| 295 | # --- HARD INVARIANT 3: the .gitignore negation is intact -------------------- |
| 296 | if ! ; then |
| 297 | |
| 298 | |
| 299 | shape_fail=1 |
| 300 | else |
| 301 | |
| 302 | if [; then |
| 303 | shadowed= |
| 304 | |
| 305 | |
| 306 | |
| 307 | if [; then |
| 308 | |
| 309 | | |
| 310 | shape_fail=1 |
| 311 | else |
| 312 | |
| 313 | fi |
| 314 | else |
| 315 | |
| 316 | fi |
| 317 | fi |
| 318 | |
| 319 | # --- HARD INVARIANT 4: the pin-reading GATE census ------------------------- |
| 320 | # The per-pin invariant is blind to a gate that reads N pins through a root |
| 321 | # literal plus a runtime name list, and to a gate that only asserts inside a |
| 322 | # helper. scripts/pin-gate-audit.py resolves the root literal, enumerates the |
| 323 | # runtime names, checks each against a tracked committed copy, and classifies |
| 324 | # assertions through the helper CALL GRAPH. Counts are printed, not summarised. |
| 325 | if ! ; then |
| 326 | |
| 327 | fail=1 |
| 328 | else |
| 329 | selftest_out= |
| 330 | audit= |
| 331 | if [ && [; then |
| 332 | |
| 333 | fail=1 |
| 334 | fi |
| 335 | | |
| 336 | # The census's own POSITIVE CONTROL. Losing a gate to a doc comment is |
| 337 | # SILENT -- the count drops and nothing goes red -- so a control that only |
| 338 | # proved "the scanner finds a bad literal" would not catch it. This one |
| 339 | # plants the exact shape: a comment reproducing the forbidden literal |
| 340 | # inside a gate that reads crate_pin. |
| 341 | if ! ; then |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | fail=1 |
| 347 | else |
| 348 | |
| 349 | fi |
| 350 | badrows= |
| 351 | bardir= |
| 352 | absent= |
| 353 | if [ || [; then |
| 354 | if [; then |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | shape_fail=1 |
| 363 | else |
| 364 | |
| 365 | |
| 366 | |
| 367 | fi |
| 368 | else |
| 369 | |
| 370 | fi |
| 371 | # assertless gates are printed, never failed: a #[ignore]d gate that asserts |
| 372 | # nothing is a finding for its owner, not a preflight failure. |
| 373 | | |
| 374 | fi |
| 375 | |
| 376 | # --- RECOVERED-PIN SELF-VALIDATION ----------------------------------------- |
| 377 | # A recovered witness is the historical bytes; a re-encode is a DIFFERENT stream. |
| 378 | # Hashing what is on disk against the recorded sha256 is the half a shell |
| 379 | # preflight can decide. The other half is behavioural and needs the gate: |
| 380 | # `pinned_golden7` records non_last_ref_hits 0->2 in its own doc, and the |
| 381 | # recovered pin reproduces exactly that; only running the gate proves it. |
| 382 | badsum=0 |
| 383 | while ; do |
| 384 | case in |
| 385 | \#* | '') continue ;; |
| 386 | esac |
| 387 | [ || continue |
| 388 | abs=/ |
| 389 | if [; then |
| 390 | |
| 391 | fail=1 |
| 392 | continue |
| 393 | fi |
| 394 | have= |
| 395 | if [; then |
| 396 | |
| 397 | |
| 398 | fail=1 |
| 399 | badsum= |
| 400 | fi |
| 401 | done |
| 402 | [ && |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | # --- VECTORS ------------------------------------------------------------- |
| 408 | vec_rows= |
| 409 | vec_missing= |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | # --- DRIFT ---------------------------------------------------------------- |
| 415 | regen= |
| 416 | patch= |
| 417 | |
| 418 | if ! ; then |
| 419 | |
| 420 | |
| 421 | fi |
| 422 | # The `tracked` column is COMMITTED provenance: it is computed in a git tree. |
| 423 | # A runner host has no .git, so a regeneration there cannot recompute it and |
| 424 | # would emit 'no-git' for every committed pin -- a drift on all 37 pin rows that |
| 425 | # says nothing about the host's library. Off-git the column is normalised on both |
| 426 | # sides, and the tracked invariant falls back to the committed value (as its own |
| 427 | # message already says). |
| 428 | |
| 429 | OFFGIT=0 |
| 430 | [ || OFFGIT=1 |
| 431 | if ! ; then |
| 432 | if [; then |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | fail=1 |
| 441 | else |
| 442 | |
| 443 | |
| 444 | |
| 445 | fi |
| 446 | else |
| 447 | |
| 448 | fi |
| 449 | |
| 450 | if [; then |
| 451 | |
| 452 | |
| 453 | fi |
| 454 | if [ && [; then |
| 455 | |
| 456 | |
| 457 | fi |
| 458 | # The shape tally is always printed, fatal only under EC_FIXTURE_SHAPE_STRICT. |
| 459 | for; do ; done |
| 460 | |
| 461 | | && shape_violations= |
| 462 | # lane-av1clipprobe: the last word of this script used to be a bare `GREEN` |
| 463 | # even when mode (i) had just been reported a few lines above -- so a reader |
| 464 | # who read only the verdict read GREEN over a tree whose fixture root does not |
| 465 | # exist, which is the same false green as a gate that skipped. The verdict now |
| 466 | # says which it is: findings reported (not failed, because |
| 467 | # EC_REQUIRE_FIXTURES is unset) versus a clean pass. `EC_REQUIRE_FIXTURES=1` |
| 468 | # turns the first into the RED above. |
| 469 | if [; then |
| 470 | |
| 471 | |
| 472 | |
| 473 | else |
| 474 | |
| 475 | fi |