@biffo/cli 0.176.2 → 0.176.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -100,15 +100,53 @@ SKIPPED=""
100
100
  # out. An override that only forces on would leave no way to escape a suite that
101
101
  # has quietly grown past the threshold.
102
102
  PYTEST_BUDGET_SECONDS="${BIFFO_VERIFY_PYTEST_BUDGET:-15}"
103
+ # How long a measurement is trusted before being re-taken. Only ever matters for
104
+ # a `slow` verdict; a `fast` one is re-measured by every run that uses it.
105
+ PYTEST_MAX_AGE_DAYS="${BIFFO_VERIFY_PYTEST_MAX_AGE_DAYS:-7}"
103
106
  PYTEST="${BIFFO_VERIFY_PYTEST:-}"
104
107
 
105
108
  # Cached per directory, because timing the suite to decide whether to run the
106
109
  # suite would cost exactly what it is trying to save. The cache lives with the
107
110
  # repo, not in $HOME, so it cannot leak a fast verdict from one repo to another.
111
+ # Where the measurement lives.
112
+ #
113
+ # NOT in the working tree. The first version wrote `$_d/.pytest-duration` and
114
+ # was gitignored in biffo-template only -- .gitignore is not a synced file, so
115
+ # every other repo in the estate grew an untracked `?? services/api/.pytest-duration`
116
+ # the moment the gate ran. A cache that dirties `git status` in fifteen repos is
117
+ # a defect regardless of what it caches.
118
+ #
119
+ # The git common dir is outside every working tree, shared by all worktrees of a
120
+ # clone (they run the same suite), and cannot be committed by accident. Keyed by
121
+ # the directory measured, so a root suite and services/api do not collide.
122
+ pytest_cache_file() {
123
+ _cd=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)/biffo-verify
124
+ mkdir -p "$_cd" 2>/dev/null || true
125
+ printf '%s/pytest-%s' "$_cd" "$(printf '%s' "$1" | tr '/.' '__')"
126
+ }
127
+
128
+ # Record what a real run actually took. The gate runs pytest whenever it believes
129
+ # the suite is fast, so it observes the true duration every single time -- and
130
+ # throwing that away was the whole bug. A suite that grows past the budget now
131
+ # excludes itself on the next push, for free and exactly.
132
+ pytest_record() {
133
+ [ -n "${2:-}" ] || return 0
134
+ printf '%s\n' "$2" > "$(pytest_cache_file "$1")" 2>/dev/null || true
135
+ }
136
+
108
137
  pytest_is_fast() {
109
138
  _d="$1"
110
- _cache="$_d/.pytest-duration"
111
- if [ -f "$_cache" ]; then
139
+ _cache=$(pytest_cache_file "$_d")
140
+ # Age matters in ONE direction. A `fast` verdict is re-confirmed by every run
141
+ # (pytest_record), so it cannot go stale. A `slow` verdict is never re-tested,
142
+ # because the whole point of it is that the suite does not run -- so a suite
143
+ # that has since been split or sped up stays excluded for ever. Expiry is what
144
+ # gives it a way back in.
145
+ if [ -f "$_cache" ] && [ -n "$(find "$_cache" -mtime "-$PYTEST_MAX_AGE_DAYS" 2>/dev/null)" ]; then
146
+ _secs=$(cat "$_cache" 2>/dev/null)
147
+ elif [ -f "$_cache" ] && [ -n "$LIST" ]; then
148
+ # Expired, and --list must not run a suite to answer a question. Use the
149
+ # stale value rather than guessing: it is evidence, just old.
112
150
  _secs=$(cat "$_cache" 2>/dev/null)
113
151
  elif [ -n "$LIST" ]; then
114
152
  # --list must not run a test suite to answer a question about the repo, so
@@ -134,7 +172,7 @@ pytest_is_fast() {
134
172
  timeout "$((PYTEST_BUDGET_SECONDS * 4))" uv run --directory "$_d" pytest -q >/dev/null 2>&1 || true
135
173
  fi
136
174
  _secs=$(($(date +%s) - _start))
137
- echo "$_secs" > "$_cache" 2>/dev/null || true
175
+ printf '%s\n' "$_secs" > "$_cache" 2>/dev/null || true
138
176
  fi
139
177
  [ "${_secs:-9999}" -le "$PYTEST_BUDGET_SECONDS" ]
140
178
  }
@@ -246,9 +284,11 @@ run_check() {
246
284
  return 0
247
285
  fi
248
286
  start=$(date +%s)
287
+ LAST_CHECK_SECONDS=""
249
288
  if "$@" >"/tmp/biffo-verify.$$" 2>&1; then
250
289
  PASSED="$PASSED $name"
251
- printf ' \033[32mOK\033[0m %-16s %ss\n' "$name" "$(($(date +%s) - start))"
290
+ LAST_CHECK_SECONDS=$(($(date +%s) - start))
291
+ printf ' \033[32mOK\033[0m %-16s %ss\n' "$name" "$LAST_CHECK_SECONDS"
252
292
  else
253
293
  FAILED="$FAILED $name"
254
294
  printf ' \033[31mFAIL\033[0m %-16s %ss\n' "$name" "$(($(date +%s) - start))"
@@ -305,7 +345,14 @@ if [ -n "$PY_DIRS" ]; then
305
345
  if [ "$PYTEST" = "0" ]; then
306
346
  skip "pytest$suffix" "excluded by BIFFO_VERIFY_PYTEST=0"
307
347
  elif [ -n "$PYTEST" ] || pytest_is_fast "."; then
308
- ci_has "pytest" && run_check "pytest$suffix" uv run pytest -q
348
+ if ci_has "pytest"; then
349
+ run_check "pytest$suffix" uv run pytest -q
350
+ # Re-confirm the verdict from what the run actually took. This is the
351
+ # invalidation that costs nothing: the gate has just measured the
352
+ # suite, so a suite that has grown past the budget excludes itself on
353
+ # the next push rather than slowing every push for ever.
354
+ pytest_record "." "$LAST_CHECK_SECONDS"
355
+ fi
309
356
  else
310
357
  skip "pytest$suffix" "suite is slower than ${PYTEST_BUDGET_SECONDS}s - CI keeps it"
311
358
  fi
@@ -317,7 +364,10 @@ if [ -n "$PY_DIRS" ]; then
317
364
  if [ "$PYTEST" = "0" ]; then
318
365
  skip "pytest$suffix" "excluded by BIFFO_VERIFY_PYTEST=0"
319
366
  elif [ -n "$PYTEST" ] || pytest_is_fast "$d"; then
320
- ci_has "pytest" && run_check "pytest$suffix" uv run --directory "$d" pytest -q
367
+ if ci_has "pytest"; then
368
+ run_check "pytest$suffix" uv run --directory "$d" pytest -q
369
+ pytest_record "$d" "$LAST_CHECK_SECONDS"
370
+ fi
321
371
  else
322
372
  skip "pytest$suffix" "suite is slower than ${PYTEST_BUDGET_SECONDS}s - CI keeps it"
323
373
  fi
@@ -100,15 +100,53 @@ SKIPPED=""
100
100
  # out. An override that only forces on would leave no way to escape a suite that
101
101
  # has quietly grown past the threshold.
102
102
  PYTEST_BUDGET_SECONDS="${BIFFO_VERIFY_PYTEST_BUDGET:-15}"
103
+ # How long a measurement is trusted before being re-taken. Only ever matters for
104
+ # a `slow` verdict; a `fast` one is re-measured by every run that uses it.
105
+ PYTEST_MAX_AGE_DAYS="${BIFFO_VERIFY_PYTEST_MAX_AGE_DAYS:-7}"
103
106
  PYTEST="${BIFFO_VERIFY_PYTEST:-}"
104
107
 
105
108
  # Cached per directory, because timing the suite to decide whether to run the
106
109
  # suite would cost exactly what it is trying to save. The cache lives with the
107
110
  # repo, not in $HOME, so it cannot leak a fast verdict from one repo to another.
111
+ # Where the measurement lives.
112
+ #
113
+ # NOT in the working tree. The first version wrote `$_d/.pytest-duration` and
114
+ # was gitignored in biffo-template only -- .gitignore is not a synced file, so
115
+ # every other repo in the estate grew an untracked `?? services/api/.pytest-duration`
116
+ # the moment the gate ran. A cache that dirties `git status` in fifteen repos is
117
+ # a defect regardless of what it caches.
118
+ #
119
+ # The git common dir is outside every working tree, shared by all worktrees of a
120
+ # clone (they run the same suite), and cannot be committed by accident. Keyed by
121
+ # the directory measured, so a root suite and services/api do not collide.
122
+ pytest_cache_file() {
123
+ _cd=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)/biffo-verify
124
+ mkdir -p "$_cd" 2>/dev/null || true
125
+ printf '%s/pytest-%s' "$_cd" "$(printf '%s' "$1" | tr '/.' '__')"
126
+ }
127
+
128
+ # Record what a real run actually took. The gate runs pytest whenever it believes
129
+ # the suite is fast, so it observes the true duration every single time -- and
130
+ # throwing that away was the whole bug. A suite that grows past the budget now
131
+ # excludes itself on the next push, for free and exactly.
132
+ pytest_record() {
133
+ [ -n "${2:-}" ] || return 0
134
+ printf '%s\n' "$2" > "$(pytest_cache_file "$1")" 2>/dev/null || true
135
+ }
136
+
108
137
  pytest_is_fast() {
109
138
  _d="$1"
110
- _cache="$_d/.pytest-duration"
111
- if [ -f "$_cache" ]; then
139
+ _cache=$(pytest_cache_file "$_d")
140
+ # Age matters in ONE direction. A `fast` verdict is re-confirmed by every run
141
+ # (pytest_record), so it cannot go stale. A `slow` verdict is never re-tested,
142
+ # because the whole point of it is that the suite does not run -- so a suite
143
+ # that has since been split or sped up stays excluded for ever. Expiry is what
144
+ # gives it a way back in.
145
+ if [ -f "$_cache" ] && [ -n "$(find "$_cache" -mtime "-$PYTEST_MAX_AGE_DAYS" 2>/dev/null)" ]; then
146
+ _secs=$(cat "$_cache" 2>/dev/null)
147
+ elif [ -f "$_cache" ] && [ -n "$LIST" ]; then
148
+ # Expired, and --list must not run a suite to answer a question. Use the
149
+ # stale value rather than guessing: it is evidence, just old.
112
150
  _secs=$(cat "$_cache" 2>/dev/null)
113
151
  elif [ -n "$LIST" ]; then
114
152
  # --list must not run a test suite to answer a question about the repo, so
@@ -134,7 +172,7 @@ pytest_is_fast() {
134
172
  timeout "$((PYTEST_BUDGET_SECONDS * 4))" uv run --directory "$_d" pytest -q >/dev/null 2>&1 || true
135
173
  fi
136
174
  _secs=$(($(date +%s) - _start))
137
- echo "$_secs" > "$_cache" 2>/dev/null || true
175
+ printf '%s\n' "$_secs" > "$_cache" 2>/dev/null || true
138
176
  fi
139
177
  [ "${_secs:-9999}" -le "$PYTEST_BUDGET_SECONDS" ]
140
178
  }
@@ -246,9 +284,11 @@ run_check() {
246
284
  return 0
247
285
  fi
248
286
  start=$(date +%s)
287
+ LAST_CHECK_SECONDS=""
249
288
  if "$@" >"/tmp/biffo-verify.$$" 2>&1; then
250
289
  PASSED="$PASSED $name"
251
- printf ' \033[32mOK\033[0m %-16s %ss\n' "$name" "$(($(date +%s) - start))"
290
+ LAST_CHECK_SECONDS=$(($(date +%s) - start))
291
+ printf ' \033[32mOK\033[0m %-16s %ss\n' "$name" "$LAST_CHECK_SECONDS"
252
292
  else
253
293
  FAILED="$FAILED $name"
254
294
  printf ' \033[31mFAIL\033[0m %-16s %ss\n' "$name" "$(($(date +%s) - start))"
@@ -305,7 +345,14 @@ if [ -n "$PY_DIRS" ]; then
305
345
  if [ "$PYTEST" = "0" ]; then
306
346
  skip "pytest$suffix" "excluded by BIFFO_VERIFY_PYTEST=0"
307
347
  elif [ -n "$PYTEST" ] || pytest_is_fast "."; then
308
- ci_has "pytest" && run_check "pytest$suffix" uv run pytest -q
348
+ if ci_has "pytest"; then
349
+ run_check "pytest$suffix" uv run pytest -q
350
+ # Re-confirm the verdict from what the run actually took. This is the
351
+ # invalidation that costs nothing: the gate has just measured the
352
+ # suite, so a suite that has grown past the budget excludes itself on
353
+ # the next push rather than slowing every push for ever.
354
+ pytest_record "." "$LAST_CHECK_SECONDS"
355
+ fi
309
356
  else
310
357
  skip "pytest$suffix" "suite is slower than ${PYTEST_BUDGET_SECONDS}s - CI keeps it"
311
358
  fi
@@ -317,7 +364,10 @@ if [ -n "$PY_DIRS" ]; then
317
364
  if [ "$PYTEST" = "0" ]; then
318
365
  skip "pytest$suffix" "excluded by BIFFO_VERIFY_PYTEST=0"
319
366
  elif [ -n "$PYTEST" ] || pytest_is_fast "$d"; then
320
- ci_has "pytest" && run_check "pytest$suffix" uv run --directory "$d" pytest -q
367
+ if ci_has "pytest"; then
368
+ run_check "pytest$suffix" uv run --directory "$d" pytest -q
369
+ pytest_record "$d" "$LAST_CHECK_SECONDS"
370
+ fi
321
371
  else
322
372
  skip "pytest$suffix" "suite is slower than ${PYTEST_BUDGET_SECONDS}s - CI keeps it"
323
373
  fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.176.2",
3
+ "version": "0.176.3",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",