@biffo/cli 0.383.0 → 0.385.0

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.
@@ -154,10 +154,26 @@ fi
154
154
  # deliberate escape hatch AGENTS.md section 7 requires for loosening a gate --
155
155
  # in the open, not by reaching for `--no-verify` and skipping every other check
156
156
  # too.
157
+ #
158
+ # Pre-push ONLY, the lane is also SCOPED to the diff (see verify.sh): the full
159
+ # suite outgrew the fleet's 900s push timeout, and CI still runs all of it as
160
+ # the required check. `BIFFO_PGTEST_PREPUSH=1` marks this as a pre-push run
161
+ # (smaller budget); `BIFFO_PGTEST_CHANGED_FILES` names the changed paths;
162
+ # `BIFFO_PGTEST_SCOPE=none` means the diff is provably irrelevant, so the lane
163
+ # is not run. A hand-run `biffo verify` sets none of these and runs everything.
157
164
  if [ -z "${BIFFO_SKIP_PGTEST:-}" ] && [ -n "$REFS_FILE" ]; then
158
- if sh scripts/biffo.sh pgtest-diff-check <"$REFS_FILE"; then
159
- export BIFFO_PGTEST_DIFF_RELEVANT=1
160
- fi
165
+ PGTEST_LIST_FILE=$(mktemp) || PGTEST_LIST_FILE=""
166
+ trap 'rm -f "$REFS_FILE" "$PGTEST_LIST_FILE"' EXIT HUP INT TERM
167
+ export BIFFO_PGTEST_PREPUSH=1
168
+ BIFFO_PGTEST_DIFF_LIST_FILE="$PGTEST_LIST_FILE" sh scripts/biffo.sh pgtest-diff-check <"$REFS_FILE"
169
+ pgtest_status=$?
170
+ case "$pgtest_status" in
171
+ 0)
172
+ export BIFFO_PGTEST_DIFF_RELEVANT=1
173
+ [ -n "$PGTEST_LIST_FILE" ] && export BIFFO_PGTEST_CHANGED_FILES="$PGTEST_LIST_FILE"
174
+ ;;
175
+ 1) export BIFFO_PGTEST_SCOPE=none ;;
176
+ esac
161
177
  fi
162
178
 
163
179
  # Through the version-pinned CLI since #1109, so a repo cannot run a gate two
@@ -154,10 +154,26 @@ fi
154
154
  # deliberate escape hatch AGENTS.md section 7 requires for loosening a gate --
155
155
  # in the open, not by reaching for `--no-verify` and skipping every other check
156
156
  # too.
157
+ #
158
+ # Pre-push ONLY, the lane is also SCOPED to the diff (see verify.sh): the full
159
+ # suite outgrew the fleet's 900s push timeout, and CI still runs all of it as
160
+ # the required check. `BIFFO_PGTEST_PREPUSH=1` marks this as a pre-push run
161
+ # (smaller budget); `BIFFO_PGTEST_CHANGED_FILES` names the changed paths;
162
+ # `BIFFO_PGTEST_SCOPE=none` means the diff is provably irrelevant, so the lane
163
+ # is not run. A hand-run `biffo verify` sets none of these and runs everything.
157
164
  if [ -z "${BIFFO_SKIP_PGTEST:-}" ] && [ -n "$REFS_FILE" ]; then
158
- if sh scripts/biffo.sh pgtest-diff-check <"$REFS_FILE"; then
159
- export BIFFO_PGTEST_DIFF_RELEVANT=1
160
- fi
165
+ PGTEST_LIST_FILE=$(mktemp) || PGTEST_LIST_FILE=""
166
+ trap 'rm -f "$REFS_FILE" "$PGTEST_LIST_FILE"' EXIT HUP INT TERM
167
+ export BIFFO_PGTEST_PREPUSH=1
168
+ BIFFO_PGTEST_DIFF_LIST_FILE="$PGTEST_LIST_FILE" sh scripts/biffo.sh pgtest-diff-check <"$REFS_FILE"
169
+ pgtest_status=$?
170
+ case "$pgtest_status" in
171
+ 0)
172
+ export BIFFO_PGTEST_DIFF_RELEVANT=1
173
+ [ -n "$PGTEST_LIST_FILE" ] && export BIFFO_PGTEST_CHANGED_FILES="$PGTEST_LIST_FILE"
174
+ ;;
175
+ 1) export BIFFO_PGTEST_SCOPE=none ;;
176
+ esac
161
177
  fi
162
178
 
163
179
  # Through the version-pinned CLI since #1109, so a repo cannot run a gate two
package/dist/index.js CHANGED
@@ -731,7 +731,8 @@ function checkCoreOwnership({
731
731
  commitMessage = "",
732
732
  warnOnly = [],
733
733
  templateShippedPaths = null,
734
- upgradeCommitFiles = null
734
+ upgradeCommitFiles = null,
735
+ firstCommitIsUpgrade = false
735
736
  }) {
736
737
  const empty = {
737
738
  blocked: [],
@@ -742,7 +743,7 @@ function checkCoreOwnership({
742
743
  };
743
744
  if (!isInstance) return { skipped: "template", ...empty };
744
745
  let effectiveChangedFiles = changedFiles;
745
- if (branch.startsWith(UPGRADE_BRANCH_PREFIX)) {
746
+ if (branch.startsWith(UPGRADE_BRANCH_PREFIX) || firstCommitIsUpgrade) {
746
747
  const exempt = new Set(upgradeCommitFiles ?? []);
747
748
  effectiveChangedFiles = changedFiles.filter((f) => !exempt.has(f));
748
749
  if (effectiveChangedFiles.length === 0) return { skipped: "upgrade-branch", ...empty };
@@ -4056,7 +4057,10 @@ var coreUpgradeCommand = new Command3("upgrade").description("Three-way-merge te
4056
4057
  ).option(
4057
4058
  "--allow-dirty",
4058
4059
  "Compute the plan even with uncommitted changes in the instance tree (they become part of the merge)"
4059
- ).option("--base <branch>", "Base branch for the PR (defaults to the repo\u2019s default branch)").option("--remote <name>", "Git remote to push to and open the PR on (default: origin)").option(
4060
+ ).option("--base <branch>", "Base branch for the PR (defaults to the repo\u2019s default branch)").option(
4061
+ "--no-push",
4062
+ "With --apply, stop after the local commit and dependency install: no push, no PR, no GitHub token needed"
4063
+ ).option("--remote <name>", "Git remote to push to and open the PR on (default: origin)").option(
4060
4064
  "--reap",
4061
4065
  "Delete local branches previous upgrade runs left behind, once their PR has merged (#758)"
4062
4066
  ).action(
@@ -4077,6 +4081,7 @@ var coreUpgradeCommand = new Command3("upgrade").description("Three-way-merge te
4077
4081
  if (options.toTemplate) runOptions.theirsDir = resolve4(options.toTemplate);
4078
4082
  if (options.base) runOptions.base = options.base;
4079
4083
  if (options.remote) runOptions.remote = options.remote;
4084
+ if (options.push === false) runOptions.noPush = true;
4080
4085
  if (options.reap) runOptions.reap = true;
4081
4086
  await runCoreUpgrade(runOptions);
4082
4087
  } catch (err) {
@@ -4322,7 +4327,7 @@ async function applyAndOpenPr(options, deps, plan, migrations, fromVersion, toVe
4322
4327
  );
4323
4328
  }
4324
4329
  const { git } = deps;
4325
- const token = deps.resolveToken();
4330
+ const token = options.noPush ? "" : deps.resolveToken();
4326
4331
  if (!await git.isGitRepo(options.cwd)) {
4327
4332
  throw new Error(`${options.cwd} is not a git repository.`);
4328
4333
  }
@@ -4414,6 +4419,12 @@ async function buildCommitAndOpenPr(options, deps, plan, migrations, fromVersion
4414
4419
  const installOutcomes = await installInstanceDependencies(options.cwd, run);
4415
4420
  const installFailures = describeInstallFailures(installOutcomes);
4416
4421
  for (const message of installFailures) log.warn(message);
4422
+ if (options.noPush) {
4423
+ log.success(
4424
+ `Committed the upgrade on ${branch}; --no-push, so nothing was pushed and no PR was opened.`
4425
+ );
4426
+ return;
4427
+ }
4417
4428
  log.step(3, 4, `Pushing ${branch}`);
4418
4429
  const pushOpts = { token };
4419
4430
  if (options.remote) pushOpts.remote = options.remote;
@@ -14659,6 +14670,20 @@ async function resolveUpgradeCommitFiles(repoRoot, base, opts = {}, runner = def
14659
14670
  if (diff.exitCode !== 0) return null;
14660
14671
  return splitLines(diff.stdout);
14661
14672
  }
14673
+ var UPGRADE_COMMIT_SUBJECT = /^chore\(core\): upgrade template core \d+\.\d+\.\d+ -> \d+\.\d+\.\d+$/;
14674
+ async function firstCommitIsCliUpgrade(repoRoot, base, runner = defaultRunner2) {
14675
+ try {
14676
+ const rev = await runner(["rev-list", "--reverse", `${base}..HEAD`], repoRoot);
14677
+ if (rev.exitCode !== 0) return false;
14678
+ const first = splitLines(rev.stdout)[0];
14679
+ if (!first) return false;
14680
+ const msg = await runner(["log", "-1", "--format=%s", first], repoRoot);
14681
+ if (msg.exitCode !== 0) return false;
14682
+ return UPGRADE_COMMIT_SUBJECT.test(msg.stdout.trim());
14683
+ } catch {
14684
+ return false;
14685
+ }
14686
+ }
14662
14687
 
14663
14688
  // src/scripts/check-core-ownership.ts
14664
14689
  var LOCAL_UPGRADE_BASE = "origin/dev";
@@ -14718,7 +14743,8 @@ async function runOwnershipCheck(argv) {
14718
14743
  reject: false
14719
14744
  });
14720
14745
  const branch = resolveBranch(process.env, gitBranch);
14721
- const upgradeCommitFiles = branch.startsWith(UPGRADE_BRANCH_PREFIX) ? await resolveUpgradeCommitFiles(
14746
+ const firstCommitIsUpgrade = !staged && !branch.startsWith(UPGRADE_BRANCH_PREFIX) && ciBase !== null ? await firstCommitIsCliUpgrade(root, ciBase) : false;
14747
+ const upgradeCommitFiles = branch.startsWith(UPGRADE_BRANCH_PREFIX) || firstCommitIsUpgrade ? await resolveUpgradeCommitFiles(
14722
14748
  root,
14723
14749
  ciBase ?? LOCAL_UPGRADE_BASE,
14724
14750
  staged ? { stagedFallbackFiles: changedFiles } : {}
@@ -14737,6 +14763,7 @@ async function runOwnershipCheck(argv) {
14737
14763
  commitMessage,
14738
14764
  warnOnly: readDivergenceConfig(root).warnOnly,
14739
14765
  upgradeCommitFiles,
14766
+ firstCommitIsUpgrade,
14740
14767
  templateShippedPaths
14741
14768
  });
14742
14769
  if (result.knownOrphans.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.383.0",
3
+ "version": "0.385.0",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -89,7 +89,14 @@ while read -r _local_ref local_sha _remote_ref remote_sha; do
89
89
  continue
90
90
  fi
91
91
 
92
- if git diff --name-only "$range" 2>/dev/null | grep -qE "$PATTERN"; then
92
+ changed=$(git diff --name-only "$range" 2>/dev/null)
93
+ # Hand the changed paths to the hook so verify.sh can SCOPE the pre-push
94
+ # pg-test lane to this diff instead of running the whole suite. Optional:
95
+ # nothing is written unless the caller names a file.
96
+ if [ -n "${BIFFO_PGTEST_DIFF_LIST_FILE:-}" ] && [ -n "$changed" ]; then
97
+ printf '%s\n' "$changed" >>"$BIFFO_PGTEST_DIFF_LIST_FILE"
98
+ fi
99
+ if printf '%s\n' "$changed" | grep -qE "$PATTERN"; then
93
100
  echo hit >>"$RESULT_FILE"
94
101
  fi
95
102
  done
package/scripts/verify.sh CHANGED
@@ -908,7 +908,20 @@ fi
908
908
  # tests already passing before the kill, so it was slow, not failing
909
909
  # (tabsii-com/tabsii-platform#1463). Same doubling; not re-measured to
910
910
  # completion, so re-measure and tighten this comment when it next finishes.
911
- PG_TEST_BUDGET_SECONDS="${BIFFO_VERIFY_PG_BUDGET:-960}"
911
+ #
912
+ # Pre-push (#2420): the fleet kills a push at 900s, so a 960s lane budget could
913
+ # never report -- the push died first. The pre-push gate (`.githooks/pre-push`
914
+ # exports BIFFO_PGTEST_PREPUSH=1) therefore runs a diff-SCOPED module set under
915
+ # a budget strictly below 900s, and the full suite stays with CI and a
916
+ # hand-run `biffo verify` (960s, unchanged). Do not raise the pre-push number:
917
+ # scope the set instead.
918
+ PG_PREPUSH_BUDGET_SECONDS=600
919
+ if [ -n "${BIFFO_PGTEST_PREPUSH:-}" ]; then
920
+ PG_TEST_BUDGET_SECONDS="${BIFFO_VERIFY_PG_BUDGET:-$PG_PREPUSH_BUDGET_SECONDS}"
921
+ else
922
+ PG_TEST_BUDGET_SECONDS="${BIFFO_VERIFY_PG_BUDGET:-960}"
923
+ fi
924
+ PG_SCOPED_DESC=""
912
925
  PG_TEST_DSN="${BIFFO_TEST_PG_DSN:-${TABSII_TEST_PG_DSN:-}}"
913
926
 
914
927
  # `.claude/worktrees` is excluded alongside `.worktrees`, and finding out why
@@ -1153,6 +1166,11 @@ pg_test_run() {
1153
1166
  echo "so nothing below is a verdict on your change. Do not go looking for a"
1154
1167
  echo "bug on this evidence."
1155
1168
  echo ""
1169
+ if [ -n "$PG_SCOPED_DESC" ]; then
1170
+ echo "This was the pre-push SCOPED set (the full suite runs in CI):"
1171
+ printf '%s\n' "$PG_SCOPED_DESC"
1172
+ echo ""
1173
+ fi
1156
1174
  echo "Most likely the lane has simply outgrown its budget. Re-run with more:"
1157
1175
  echo " BIFFO_VERIFY_PG_BUDGET=$((PG_TEST_BUDGET_SECONDS * 2)) sh scripts/verify.sh"
1158
1176
  echo ""
@@ -1195,6 +1213,64 @@ pg_test_run() {
1195
1213
  return 0
1196
1214
  }
1197
1215
 
1216
+ # Pre-push scoping (#2420). Given the pushed diff's changed paths and the full
1217
+ # discovered module list, print the modules worth running now, one per line:
1218
+ # 1. every changed *_pg.py test file;
1219
+ # 2. the smoke set the repo declares in scripts/pg-test-smoke.txt (one path
1220
+ # per line, `#` comments allowed);
1221
+ # 3. for each changed db/imports/**.sql, the modules that mention a table it
1222
+ # CREATEs or ALTERs (grep over table names).
1223
+ # Runs in a subshell, so the human-readable "why" is rebuilt into
1224
+ # PG_SCOPED_DESC by the caller via pg_scope_describe.
1225
+ pg_scope_tables() {
1226
+ # table names created/altered in the changed SQL, schema/quotes stripped
1227
+ while IFS= read -r _f; do
1228
+ case "$_f" in
1229
+ */db/imports/*.sql | db/imports/*.sql) [ -f "$_f" ] || continue ;;
1230
+ *) continue ;;
1231
+ esac
1232
+ grep -iE '^[[:space:]]*(create|alter)[[:space:]]+table' "$_f" 2>/dev/null \
1233
+ | sed -E 's/--.*//; s/"//g' \
1234
+ | sed -E 's/^[[:space:]]*[Cc][Rr][Ee][Aa][Tt][Ee][[:space:]]+[Tt][Aa][Bb][Ll][Ee][[:space:]]+([Ii][Ff][[:space:]]+[Nn][Oo][Tt][[:space:]]+[Ee][Xx][Ii][Ss][Tt][Ss][[:space:]]+)?//; s/^[[:space:]]*[Aa][Ll][Tt][Ee][Rr][[:space:]]+[Tt][Aa][Bb][Ll][Ee][[:space:]]+([Ii][Ff][[:space:]]+[Ee][Xx][Ii][Ss][Tt][Ss][[:space:]]+)?([Oo][Nn][Ll][Yy][[:space:]]+)?//' \
1235
+ | awk '{print $1}' | sed -E 's/\(.*//; s/.*\.//; s/[;,]//g' | grep -E '^[A-Za-z_][A-Za-z0-9_]*$'
1236
+ done <"$1" | sort -u
1237
+ }
1238
+
1239
+ pg_scope_modules() {
1240
+ _sc_changed="$1"
1241
+ _sc_all="$2"
1242
+ {
1243
+ # 1. changed *_pg.py files that exist and were discovered
1244
+ grep -E '_pg\.py$' "$_sc_changed" 2>/dev/null | while IFS= read -r _f; do
1245
+ printf '%s\n' "$_sc_all" | grep -Fx -- "$_f"
1246
+ done
1247
+ # 2. declared smoke set
1248
+ if [ -f scripts/pg-test-smoke.txt ]; then
1249
+ sed 's/#.*//; s/^[[:space:]]*//; s/[[:space:]]*$//' scripts/pg-test-smoke.txt | grep -v '^$' \
1250
+ | while IFS= read -r _f; do
1251
+ [ -f "$_f" ] && printf '%s\n' "$_f"
1252
+ done
1253
+ fi
1254
+ # 3. modules referencing a table the changed DDL creates or alters
1255
+ _sc_tables=$(pg_scope_tables "$_sc_changed")
1256
+ if [ -n "$_sc_tables" ]; then
1257
+ printf '%s\n' "$_sc_all" | while IFS= read -r _m; do
1258
+ [ -f "$_m" ] && printf '%s\n' "$_sc_tables" | grep -qwFf - "$_m" 2>/dev/null && printf '%s\n' "$_m"
1259
+ done
1260
+ fi
1261
+ } | grep -v '^$' | sort -u
1262
+ }
1263
+
1264
+ pg_scope_describe() {
1265
+ _sd_changed="$1"
1266
+ _sd_all="$2"
1267
+ printf 'selected because changed: %s\n' \
1268
+ "$(grep -E '_pg\.py$' "$_sd_changed" 2>/dev/null | while IFS= read -r _f; do printf '%s\n' "$_sd_all" | grep -Fx -- "$_f"; done | tr '\n' ' ')"
1269
+ [ -f scripts/pg-test-smoke.txt ] && printf 'selected as declared smoke set: scripts/pg-test-smoke.txt\n'
1270
+ _sd_tables=$(pg_scope_tables "$_sd_changed" | tr '\n' ' ')
1271
+ [ -n "$_sd_tables" ] && printf 'selected because they reference tables from changed DDL: %s\n' "$_sd_tables"
1272
+ }
1273
+
1198
1274
  _pg_modules=$(pg_test_modules)
1199
1275
 
1200
1276
  # Print the denominator, not just the verdict -- a discovery step that finds
@@ -1334,7 +1410,28 @@ else
1334
1410
  "CI runs these as a required check; nothing local is checking them."
1335
1411
  fi
1336
1412
  else
1337
- _pg_rel=$(echo "$_pg_modules" | sed "s|^$_pg_dir/||" | tr '\n' ' ')
1413
+ _pg_run_modules="$_pg_modules"
1414
+ _pg_skip_lane=""
1415
+ if [ -z "$LIST" ] && [ -n "${BIFFO_PGTEST_PREPUSH:-}" ]; then
1416
+ if [ "${BIFFO_PGTEST_SCOPE:-}" = "none" ]; then
1417
+ _pg_skip_lane=1
1418
+ _pg_skip_msg="pre-push diff touches no db/imports/** or *_pg.py path (CI runs the full suite)"
1419
+ elif [ -n "${BIFFO_PGTEST_CHANGED_FILES:-}" ] && [ -f "$BIFFO_PGTEST_CHANGED_FILES" ]; then
1420
+ _pg_scoped=$(pg_scope_modules "$BIFFO_PGTEST_CHANGED_FILES" "$_pg_modules")
1421
+ if [ -z "$_pg_scoped" ]; then
1422
+ _pg_skip_lane=1
1423
+ _pg_skip_msg="pre-push scope selected no modules (no changed *_pg.py, no scripts/pg-test-smoke.txt entries, no referencing tests); CI runs the full suite"
1424
+ else
1425
+ _pg_run_modules="$_pg_scoped"
1426
+ PG_SCOPED_DESC="$(pg_scope_describe "$BIFFO_PGTEST_CHANGED_FILES" "$_pg_modules")
1427
+ modules: $(printf '%s\n' "$_pg_scoped" | tr '\n' ' ')"
1428
+ fi
1429
+ else
1430
+ printf ' \033[33m%s\033[0m\n' \
1431
+ "pre-push could not tell which paths changed: running the full pg-test suite under the ${PG_TEST_BUDGET_SECONDS}s pre-push budget"
1432
+ fi
1433
+ fi
1434
+ _pg_rel=$(echo "$_pg_run_modules" | sed "s|^$_pg_dir/||" | tr '\n' ' ')
1338
1435
  # Not a plain `run_check` call: `pg_test_run` returns THREE states (0 pass,
1339
1436
  # 1 real failure, 2 timed out/inconclusive -- see its own comment), and
1340
1437
  # `run_check` only ever sees pass/fail, so routing through it would collapse
@@ -1343,7 +1440,14 @@ else
1343
1440
  if [ -n "$LIST" ]; then
1344
1441
  # shellcheck disable=SC2086
1345
1442
  echo pg_test_run "$_pg_dir" "$_pg_rel"
1443
+ elif [ -n "$_pg_skip_lane" ]; then
1444
+ skip pg-test "$_pg_skip_msg"
1346
1445
  else
1446
+ if [ "$_pg_run_modules" != "$_pg_modules" ]; then
1447
+ printf '\033[90m pg-test scoped (pre-push): %s of %s module(s), budget %ss; CI and hand-run verify run all\033[0m\n' \
1448
+ "$(printf '%s\n' "$_pg_run_modules" | grep -c .)" "$(printf '%s\n' "$_pg_modules" | grep -c .)" "$PG_TEST_BUDGET_SECONDS"
1449
+ printf '%s\n' "$PG_SCOPED_DESC" | sed 's/^/ /'
1450
+ fi
1347
1451
  _pg_check_start=$(date +%s)
1348
1452
  _verify_track_tmp "/tmp/biffo-verify-pg-check.$$"
1349
1453
  # shellcheck disable=SC2086