edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBbede77eTahinli2 months ago3534 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """pin-gate-audit.py — census of the gates that read a PINNED fixture. |
| 3 | |
| 4 | The r1 invariant was too weak: it matched only single-name call shapes |
| 5 | (`crate_pin("X")`, `pin_dir().join("X")`). It is blind to a much worse shape |
| 6 | that exists in the crate right now -- a gate that reads N pins through a |
| 7 | DIRECTORY literal plus a runtime-formatted name list: |
| 8 | |
| 9 | let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures"); |
| 10 | ["warp-mismatch", "warp-flake-5", ...].iter().map(|n| format!("{fixtures}/{n}.obu")) |
| 11 | |
| 12 | Fourteen names, none committed under the crate, so no clean tree and no runner |
| 13 | can satisfy them, and the gate is #[ignore]d -- a no-op that reports nothing. |
| 14 | A preflight that passes it is the silent shape again. |
| 15 | |
| 16 | This audit, for every `#[test]` fn in crates/*/src and crates/*/tests that |
| 17 | reaches for a fixture: |
| 18 | |
| 19 | * resolves the fixture ROOT literal (concat! or Path::new(env!).join chain) |
| 20 | * enumerates every runtime name built from that root |
| 21 | - a `[..].iter().map(|n| format!("{var}/{n}.obu"))` name list |
| 22 | - a `format!` naming the root variable directly |
| 23 | * for each name, checks the path under the ROOT (gitignored, so never tracked) |
| 24 | and under crates/<crate>/fixtures/ (the committed copy) |
| 25 | * counts pin-reading gates, how many resolve through a committed copy, and how |
| 26 | many do not -- printed as numbers, not prose |
| 27 | |
| 28 | ASSERTION CLASSIFICATION uses the helper CALL GRAPH, not the gate body: a gate |
| 29 | that delegates to a helper (the warp gate calls check_pinned_warp_stream, which |
| 30 | asserts all three planes per frame) is NOT a no-assert gate, and reading only the |
| 31 | body gets that wrong -- which is exactly the mistake that produced the |
| 32 | "asserts nothing" classification earlier today. |
| 33 | |
| 34 | Output (one record per line, tab separated fields): |
| 35 | GATE <file>:<line>\t<fn>\t<root-kind>\t<asserts:yes|no|via-helper NAME>\t<ignored:yes|no>\t<names> |
| 36 | NAME <file>:<line>\t<gate-fn>\t<name>\t<committed-copy:present|absent>\t<tracked:yes|no|->\t<exists-under-root:yes|no> |
| 37 | COUNT total=<n>\tcommitted=<n>\tuncommitted=<n>\tignored=<n>\tassertless=<n> |
| 38 | |
| 39 | Exit 0 always: the caller decides what is a failure. Set PIN_AUDIT_STRICT=1 to |
| 40 | exit 1 when any name lacks a tracked committed copy. |
| 41 | """ |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | = or |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | = |
| 56 | |
| 57 | continue |
| 58 | |
| 59 | |
| 60 | yield , |
| 61 | |
| 62 | |
| 63 | |
| 64 | """Yield (start_line, name, body, preceding_attrs) for every fn. |
| 65 | |
| 66 | The body runs from the `fn` line to the NEXT `fn` line rather than to a |
| 67 | brace-balanced end: brace counting over 39k lines of Rust miscounts the |
| 68 | moment one string literal or macro contains an unbalanced brace, and a |
| 69 | single bad walk swallows every gate after it. Over-capturing trailing |
| 70 | attributes of the next fn is harmless here -- attributes are read from the |
| 71 | lines immediately above the `fn` line, which this method never crosses. |
| 72 | """ |
| 73 | = |
| 74 | = |
| 75 | |
| 76 | = |
| 77 | |
| 78 | |
| 79 | |
| 80 | = |
| 81 | = |
| 82 | = - 1 |
| 83 | |
| 84 | |
| 85 | -= 1 |
| 86 | yield + 1, , , |
| 87 | |
| 88 | |
| 89 | = |
| 90 | |
| 91 | |
| 92 | = |
| 93 | |
| 94 | |
| 95 | |
| 96 | = |
| 97 | = |
| 98 | = |
| 99 | = |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | return |
| 105 | = |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | return |
| 111 | |
| 112 | |
| 113 | |
| 114 | = |
| 115 | |
| 116 | |
| 117 | |
| 118 | """A POSITIVE CONTROL for the census itself, in the exact shape that cost a |
| 119 | gate: a doc comment reproducing the forbidden root literal, sitting between |
| 120 | two gates, one of which reads crate_pin. |
| 121 | |
| 122 | It runs the REAL pipeline -- a synthetic crate written into the tree, the |
| 123 | normal scan, the normal records -- because a control that re-implements the |
| 124 | decision order would pass while the real path is broken, which is the failure |
| 125 | this control exists to catch. Losing a gate to a comment is SILENT: the |
| 126 | census count drops and nothing goes red, so only a control that asserts the |
| 127 | count can see it. |
| 128 | """ |
| 129 | # Build the synthetic tree in a temp dir and point the scan at it, so the |
| 130 | # control runs even where the staged tree is read-only. |
| 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 | continue |
| 170 | |
| 171 | continue |
| 172 | = |
| 173 | = |
| 174 | = |
| 175 | |
| 176 | = |
| 177 | = |
| 178 | |
| 179 | = not and not |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | return 0 |
| 187 | |
| 188 | = |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | = # fn name -> body (all fns in the tree) |
| 195 | |
| 196 | = |
| 197 | |
| 198 | |
| 199 | |
| 200 | = = = = = 0 |
| 201 | = |
| 202 | |
| 203 | |
| 204 | = |
| 205 | = |
| 206 | |
| 207 | |
| 208 | continue |
| 209 | # Match every shape on a COMMENT-STRIPPED body. A doc comment that |
| 210 | # reproduces a root literal to explain the shape it removed used to |
| 211 | # invent a gate here, the same blindness invariant 1 had. |
| 212 | = |
| 213 | = |
| 214 | = None |
| 215 | = |
| 216 | = None |
| 217 | = |
| 218 | |
| 219 | , = , None |
| 220 | = |
| 221 | |
| 222 | = |
| 223 | |
| 224 | = |
| 225 | = |
| 226 | = |
| 227 | |
| 228 | # The single-name shapes the FIRST invariant matched, kept so |
| 229 | # the census counts every pin-reading gate, not only the ones |
| 230 | # reached through a root literal. |
| 231 | = |
| 232 | = |
| 233 | # A gate that builds the pin name at runtime (crate_pin(&format!(..))) |
| 234 | # matches no single-name shape and would VANISH from the census -- |
| 235 | # the same blind spot in a new place. Surface it instead. |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | += |
| 243 | |
| 244 | |
| 245 | continue |
| 246 | += 1 |
| 247 | |
| 248 | += 1 |
| 249 | |
| 250 | |
| 251 | |
| 252 | = |
| 253 | = |
| 254 | = |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | += 1 |
| 260 | |
| 261 | += 1 |
| 262 | |
| 263 | |
| 264 | continue |
| 265 | |
| 266 | # the variable the root is bound to, if any |
| 267 | = |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | = |
| 274 | |
| 275 | # names: ONLY the two shapes that matter. |
| 276 | # (i) a runtime NAME LIST formatted against the root variable -- |
| 277 | # the shape the weak invariant was blind to |
| 278 | # (ii) a single file literal appended to the root |
| 279 | # Anything else (a format! over some other variable, a scratch dump |
| 280 | # path) is not a pin read and is left to the manifest scan. |
| 281 | = |
| 282 | |
| 283 | # The name list is bracketed, but comments sit between its |
| 284 | # items ("lane-rect r2: HORP strip ..."), so strip line |
| 285 | # comments before parsing the list and anchor on the format! |
| 286 | # that consumes it. |
| 287 | = |
| 288 | |
| 289 | = |
| 290 | |
| 291 | continue |
| 292 | = |
| 293 | |
| 294 | continue |
| 295 | = or |
| 296 | |
| 297 | |
| 298 | |
| 299 | = |
| 300 | # a lane dump under lanes/ is not a fixture and is not this gate |
| 301 | |
| 302 | |
| 303 | |
| 304 | continue |
| 305 | |
| 306 | # assertion classification through the CALL GRAPH |
| 307 | = in |
| 308 | = |
| 309 | |
| 310 | |
| 311 | = |
| 312 | |
| 313 | = True |
| 314 | = |
| 315 | break |
| 316 | = |
| 317 | |
| 318 | continue |
| 319 | += 1 |
| 320 | |
| 321 | += 1 |
| 322 | |
| 323 | += 1 |
| 324 | = |
| 325 | |
| 326 | = + |
| 327 | |
| 328 | |
| 329 | = |
| 330 | = |
| 331 | = |
| 332 | |
| 333 | = |
| 334 | = |
| 335 | = |
| 336 | = \ |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | += 1 |
| 345 | |
| 346 | += 1 |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | # a bare directory root feeding a runtime name list can never be |
| 352 | # satisfied by a committed tree |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | return 1 |
| 367 | return 0 |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 |