hezarfen_rag
Clone
https://git.tahinli.com/Hezarfen/hezarfen_rag.git
0 watching0 forksPython2.4 MiB184b84dAhmet Kaan Gümüş2 months ago189 commits
| 1 | #!/usr/bin/env bash |
| 2 | # The LOCAL full gate: the "special path" where this machine proves the |
| 3 | # suite instead of a GitHub runner. |
| 4 | # |
| 5 | # Why it exists: the same suite is ~30s here and HANGS on a 2-core runner |
| 6 | # (measured: run 35297989416 sat at 7% for 73 minutes until it was cancelled |
| 7 | # by hand, and every push since 2026-09-17 17:54 burned 1h-3h20m the same |
| 8 | # way). When you have run this script, commit the `Local-Gate:` trailer it |
| 9 | # prints (`--amend` writes it for you) and the push carries proof: the |
| 10 | # workflow's "Decide test gate" step verifies the trailer against HEAD^{tree} |
| 11 | # and then skips the runner suite, so CI only builds, packs, uploads and deploys this run's artifact. |
| 12 | # |
| 13 | # Default path (nothing here): push without a trailer and GitHub runs |
| 14 | # everything, suite included. Nothing is mandatory; this is the fast lane. |
| 15 | # |
| 16 | # What it runs — exactly the command CI's gate runs: |
| 17 | # |
| 18 | # python -u -m pytest tests/unit -q \ |
| 19 | # -o faulthandler_timeout=120 -o faulthandler_exit_on_timeout=True |
| 20 | # |
| 21 | # (with --scope F: ... -k F), wrapped in `timeout --foreground 600`. Both |
| 22 | # bounds are measured, not guessed: the worst GREEN CI Test step was 41s |
| 23 | # (runs 35248848296, 35246056805, 35235114053 — all 41s) and this machine |
| 24 | # runs the whole suite in 32s, so a single test older than 120s and a step |
| 25 | # older than 600s are hangs, not slow tests. faulthandler names the hang |
| 26 | # (all-thread traceback, then exit 1); `timeout` is the backstop for a hang |
| 27 | # faulthandler's timer thread cannot observe. |
| 28 | # |
| 29 | # On success it writes .git/local-gate/<tree-sha>.ok (inside .git, so it is |
| 30 | # never committed) holding the tree, the timestamp, the scope, the counts |
| 31 | # parsed from pytest's summary line and the exact command. Re-running for the |
| 32 | # same tree is a no-op that just re-prints the trailer — the stamp IS the |
| 33 | # proof, so `--force` is the only way to pay for the suite twice. |
| 34 | # |
| 35 | # The trailer is printed only for a FULL run on a CLEAN tree: a --scope run |
| 36 | # is quick iteration, and a dirty tree cannot be described by a tree sha. |
| 37 | # Either one still prints the counts; it just makes no claim about a commit. |
| 38 | # A scoped run stamps .git/local-gate/<tree-sha>.<scope>.ok — its own file, so |
| 39 | # it can neither clobber the full-suite stamp nor be read back as one. |
| 40 | # |
| 41 | # Prerequisites: a virtualenv with CI's dependency set (see the recipe the |
| 42 | # script prints when something is missing). Checked first, so a mysterious |
| 43 | # failure 90 seconds in is not possible. |
| 44 | # |
| 45 | # Usage: |
| 46 | # scripts/gate-local.sh # full gate (reuses a stamp if it exists) |
| 47 | # scripts/gate-local.sh --force # full gate, even if already stamped |
| 48 | # scripts/gate-local.sh --scope eval # quick iteration (pytest -k, no trailer) |
| 49 | # scripts/gate-local.sh --amend # full gate, then append the |
| 50 | # # trailer to the HEAD commit |
| 51 | # |
| 52 | # Environment: |
| 53 | # GATE_PYTHON interpreter to use (default: .venv/bin/python) |
| 54 | # GATE_STEP_TIMEOUT shell bound for the suite, seconds (default: 600) |
| 55 | # GATE_TEST_TIMEOUT faulthandler per-test bound, seconds (default: 120) |
| 56 | |
| 57 | |
| 58 | here= |
| 59 | |
| 60 | |
| 61 | scope="" |
| 62 | amend=0 |
| 63 | force=0 |
| 64 | while [; do |
| 65 | case "" in |
| 66 | --scope) |
| 67 | [ || { ; ; } |
| 68 | scope= |
| 69 | |
| 70 | ;; |
| 71 | --amend) |
| 72 | amend=1 |
| 73 | |
| 74 | ;; |
| 75 | --force) |
| 76 | force=1 |
| 77 | |
| 78 | ;; |
| 79 | -h|--help) |
| 80 | | |
| 81 | |
| 82 | ;; |
| 83 | *) |
| 84 | |
| 85 | |
| 86 | ;; |
| 87 | esac |
| 88 | done |
| 89 | |
| 90 | py= |
| 91 | step_timeout= |
| 92 | test_timeout= |
| 93 | |
| 94 | # ── Record what this run is ───────────────────────────────────────────────── |
| 95 | tree= |
| 96 | head= |
| 97 | stamp_dir=/local-gate |
| 98 | |
| 99 | |
| 100 | if [; then |
| 101 | scope_label= |
| 102 | else |
| 103 | scope_label=full |
| 104 | fi |
| 105 | |
| 106 | # Stamps are keyed by tree AND scope. A scoped run gets its own file so it can |
| 107 | # never overwrite the full-suite stamp (the trailer is a claim about the whole |
| 108 | # suite, and the pre-push hook checks `scope: full`) — and never be mistaken |
| 109 | # for it on the next run. |
| 110 | if [; then |
| 111 | safe_scope= |
| 112 | stamp=/..ok |
| 113 | log=/..log |
| 114 | else |
| 115 | stamp=/.ok |
| 116 | log=/.log |
| 117 | fi |
| 118 | |
| 119 | dirty=no |
| 120 | if [; then |
| 121 | dirty=yes |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | fi |
| 128 | |
| 129 | # The tail both paths share: print (and optionally amend in) the trailer. |
| 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 | # Already proven on this exact tree (and this scope): the stamp IS the |
| 175 | # evidence, so re-running the suite would only burn half a minute to arrive at |
| 176 | # the same line. A --scope request only ever matches its OWN stamp, so it can |
| 177 | # never be answered with (or overwrite) a full-suite proof. |
| 178 | if [ && [ && [; then |
| 179 | scope_label= |
| 180 | passed= |
| 181 | seconds= |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | fi |
| 187 | |
| 188 | # ── Prerequisites ─────────────────────────────────────────────────────────── |
| 189 | # Each says what is missing and the exact command that fixes it: a mysterious |
| 190 | # failure 90 seconds in is worse than not starting. |
| 191 | [ || { |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | } |
| 204 | |
| 205 | missing= |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | if [; then |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | fi |
| 234 | |
| 235 | pytest_opts=(-o "faulthandler_timeout=" -o faulthandler_exit_on_timeout=True) |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | # ── The suite ─────────────────────────────────────────────────────────────── |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | # The gate itself, byte for byte what CI's Test step runs (only the runner's |
| 265 | # bare `python` becomes this venv's interpreter). `timeout --foreground` keeps |
| 266 | # the process attached to this terminal and unbuffered: the progress dot line |
| 267 | # and the faulthandler dump survive the kill. |
| 268 | if [; then |
| 269 | |
| 270 | |
| 271 | |
| 272 | else |
| 273 | |
| 274 | |
| 275 | |
| 276 | fi |
| 277 | |
| 278 | # ── Parse pytest's summary line ───────────────────────────────────────────── |
| 279 | # Shape: `1387 passed, 34 skipped, 32 warnings, 542 subtests passed in 32.31s`. |
| 280 | # The `(^|, )` anchor is what keeps "542 subtests passed" out of the `passed` |
| 281 | # count, and anchoring on the trailing `in Xs` picks the summary line rather |
| 282 | # than a test that printed a similar sentence. |
| 283 | summary= |
| 284 | if [; then |
| 285 | summary= |
| 286 | fi |
| 287 | if [; then |
| 288 | |
| 289 | |
| 290 | fi |
| 291 | |
| 292 | # Every parse is `|| true`: "0 failed" simply does not appear in the summary |
| 293 | # line, and a bare `grep -oE` with no match exits 1 — which, under |
| 294 | # `set -e` + pipefail, would abort a run that passed. |
| 295 | |
| 296 | |
| 297 | |
| 298 | passed= |
| 299 | skipped= |
| 300 | failed= |
| 301 | errors= |
| 302 | subtests= |
| 303 | duration= |
| 304 | if [; then |
| 305 | |
| 306 | |
| 307 | fi |
| 308 | seconds= |
| 309 | counts=" passed, failed, skipped ( subtests passed)" |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | if [; then |
| 316 | |
| 317 | |
| 318 | fi |
| 319 | |
| 320 | # ── The stamp ─────────────────────────────────────────────────────────────── |
| 321 | { |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | for; do |
| 334 | |
| 335 | done |
| 336 | } |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 |