@biffo/cli 0.295.0 → 0.295.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/verify.sh +146 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.295.0",
3
+ "version": "0.295.2",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/scripts/verify.sh CHANGED
@@ -821,10 +821,129 @@ PG_TEST_DSN="${BIFFO_TEST_PG_DSN:-${TABSII_TEST_PG_DSN:-}}"
821
821
  # `.claude/`. A gate that runs a stale nested checkout's copy of a test would
822
822
  # fail a push over code that is not being pushed -- and the first such false
823
823
  # positive is what teaches people to reach for BIFFO_SKIP_VERIFY.
824
+ #
825
+ # Delegate to a per-repo `scripts/rls-pg-test-discovery.sh` when one exists,
826
+ # UNIONED with the find below rather than replacing it (#1618). Measured on
827
+ # tabsii-platform: CI's own discovery script (tabsii-platform#936) finds 116
828
+ # modules under its RLS lane's root by the `test_*_pg.py` convention PLUS one
829
+ # named exception -- a matrix file authored before the convention existed --
830
+ # while this repo-wide find alone found 121, missing that exception because
831
+ # it does not, and must not, match the convention. The other 6 of the 121 sit
832
+ # outside the RLS lane's root entirely; their own docstrings say they exist to
833
+ # be picked up by verify.sh's repo-wide run and deliberately outside the RLS
834
+ # lane's scope. Neither find can replace the other: collapsing to the
835
+ # delegate's list would narrow verify.sh below its own job (every
836
+ # Postgres-dependent test in the repo, not just one lane's slice of it);
837
+ # collapsing to the find would keep missing the one named exception, which is
838
+ # exactly the defect this issue reports. A hand-maintained list here would be
839
+ # a second copy of that exception, free to drift from the first the way
840
+ # #1362's other 11 instances did -- the delegate script is the one place it
841
+ # is recorded.
842
+ #
843
+ # Detected OUTSIDE this function, in plain variables assigned once below, not
844
+ # inside it: this function is invoked as `$(pg_test_modules)` further down,
845
+ # which runs it in a SUBSHELL, and a status flag set inside it (e.g. "the
846
+ # delegate failed closed") would die with that subshell -- exactly the trap
847
+ # `checkout_health` documents above, for the same reason.
848
+ PG_RLS_DISCOVERY_SCRIPT="scripts/rls-pg-test-discovery.sh"
849
+ PG_DELEGATED_MODULES=""
850
+ PG_DELEGATE_FAILED=""
851
+ PG_DELEGATE_FAILED_REASON=""
852
+ if [ -f "$PG_RLS_DISCOVERY_SCRIPT" ]; then
853
+ # No pipe on this assignment -- `$?` right after it must reflect the
854
+ # DELEGATE's exit status, not a downstream formatter's. The script fails
855
+ # CLOSED on purpose when its own root turns up nothing (its own comment:
856
+ # "the lane would run nothing"), and that is a real gap, not an empty repo
857
+ # -- #1363's shape is a discovery finding nothing reading as "nothing to
858
+ # run", and this is exactly where it would hide.
859
+ PG_DELEGATED_MODULES=$(sh "$PG_RLS_DISCOVERY_SCRIPT" 2>/dev/null)
860
+ _pg_delegate_status=$?
861
+ # A present delegate is an assertion that this repo has Postgres tests to
862
+ # discover -- so empty output is its own gap, distinct from a non-zero
863
+ # exit, and must fail closed too (#1646). Relying only on the exit code
864
+ # made this guard only as strong as every delegate's OWN discipline;
865
+ # tabsii-platform's real script happens to `exit 1` on empty via `set -eu`,
866
+ # but verify.sh is template-owned and distributed to repos free to write a
867
+ # delegate that exits 0 with nothing -- exactly the #1363 shape ("finds
868
+ # nothing" reading as "nothing to run") this whole block exists to close,
869
+ # just one layer further in. The two causes are reported with DIFFERENT
870
+ # text below so a reader can tell "the delegate is broken" from "the
871
+ # delegate ran fine and asserted zero", which are different facts.
872
+ if [ "$_pg_delegate_status" -ne 0 ]; then
873
+ PG_DELEGATE_FAILED=1
874
+ PG_DELEGATE_FAILED_REASON="$PG_RLS_DISCOVERY_SCRIPT exited non-zero"
875
+ else
876
+ # Byte-length-zero is not the only way a delegate hands back nothing
877
+ # (#1647): a lone whitespace line is not empty by `[ -z ]`, and the old
878
+ # `grep -v '^$'` filter downstream only drops a truly-empty line, so that
879
+ # noise survived, got counted as "1 module(s) total", and the run ended
880
+ # `verify passed` -- a manufactured non-zero count is worse than an
881
+ # honest zero because it reads as coverage. Trim every line first; a
882
+ # line that is blank ONCE TRIMMED asserts nothing more than a genuinely
883
+ # empty one does, so it collapses to the SAME existing wording below
884
+ # rather than inventing a fourth message for a distinction with no new
885
+ # information.
886
+ _pg_delegate_trimmed=$(printf '%s\n' "$PG_DELEGATED_MODULES" \
887
+ | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | grep -v '^$')
888
+ if [ -z "$_pg_delegate_trimmed" ]; then
889
+ PG_DELEGATE_FAILED=1
890
+ PG_DELEGATE_FAILED_REASON="the declared delegate returned no modules"
891
+ PG_DELEGATED_MODULES=""
892
+ else
893
+ # What survives trimming is a CLAIM, not yet a module: the delegate is
894
+ # asserting each line names a real, readable test file, and that claim
895
+ # is checked here rather than trusted (#1647). This is deliberately
896
+ # broader than a whitespace fix -- it closes a stale path, a typo, a
897
+ # comment line, a directory, or a trailing-space path in the SAME move,
898
+ # because all of them are the same underlying defect: a line the
899
+ # delegate printed that does not resolve to a file. A mixture of valid
900
+ # and invalid lines is NOT filtered down to the valid ones -- silently
901
+ # dropping the bad half would manufacture a count from whatever
902
+ # happened to exist, the same untrustworthy-denominator failure this
903
+ # issue reports, just with real paths standing in for whitespace. Fail
904
+ # loudly instead and name what did not resolve: a declared delegate
905
+ # naming a file that does not exist is a defect in THAT repo's
906
+ # discovery script, and should be fixed there, not quietly tolerated
907
+ # here.
908
+ _pg_delegate_valid=""
909
+ _pg_delegate_invalid=""
910
+ _pg_saved_ifs=$IFS
911
+ IFS='
912
+ '
913
+ set -f
914
+ for _pg_line in $_pg_delegate_trimmed; do
915
+ if [ -f "$_pg_line" ] && [ -r "$_pg_line" ]; then
916
+ _pg_delegate_valid="$_pg_delegate_valid$_pg_line
917
+ "
918
+ else
919
+ _pg_delegate_invalid="$_pg_delegate_invalid$_pg_line
920
+ "
921
+ fi
922
+ done
923
+ set +f
924
+ IFS=$_pg_saved_ifs
925
+ if [ -n "$_pg_delegate_invalid" ]; then
926
+ PG_DELEGATE_FAILED=1
927
+ PG_DELEGATE_FAILED_REASON="the declared delegate returned a path that is not a readable file: $(printf '%s' "$_pg_delegate_invalid" | tr '\n' ' ' | sed 's/ *$//')"
928
+ PG_DELEGATED_MODULES=""
929
+ else
930
+ PG_DELEGATED_MODULES="$_pg_delegate_valid"
931
+ fi
932
+ fi
933
+ fi
934
+ fi
935
+
824
936
  pg_test_modules() {
825
- find . -name 'test_*_pg.py' \
826
- -not -path "*/node_modules/*" -not -path "*/.venv/*" \
827
- -not -path "*/.worktrees/*" -not -path "*/.claude/*" -not -path "*/.git/*" 2>/dev/null | sort
937
+ {
938
+ [ -n "$PG_DELEGATED_MODULES" ] && printf '%s\n' "$PG_DELEGATED_MODULES"
939
+ # Normalised to match the delegate's own path style (no leading `./`) so
940
+ # the union below actually dedupes overlapping modules instead of
941
+ # counting each one twice under two different-looking paths.
942
+ find . -name 'test_*_pg.py' \
943
+ -not -path "*/node_modules/*" -not -path "*/.venv/*" \
944
+ -not -path "*/.worktrees/*" -not -path "*/.claude/*" -not -path "*/.git/*" 2>/dev/null \
945
+ | sed 's|^\./||'
946
+ } | grep -v '^$' | sort -u
828
947
  }
829
948
 
830
949
  # Assert the lane EXERCISED something, not merely that pytest exited 0.
@@ -981,6 +1100,30 @@ pg_test_run() {
981
1100
 
982
1101
  _pg_modules=$(pg_test_modules)
983
1102
 
1103
+ # Print the denominator, not just the verdict -- a discovery step that finds
1104
+ # nothing must never merely read as "nothing to run" (#1363). Scoped to repos
1105
+ # that actually have a delegate script: printing it everywhere would add a
1106
+ # line to every repo with no RLS lane at all, for a union that is trivially
1107
+ # just the find() below in all of them.
1108
+ if [ -n "$PG_RLS_DISCOVERY_SCRIPT" ] && [ -f "$PG_RLS_DISCOVERY_SCRIPT" ] && [ -z "$LIST" ]; then
1109
+ printf '\033[90m pg-test discovery: %s module(s) total (scripts/rls-pg-test-discovery.sh unioned with repo-wide find)\033[0m\n' \
1110
+ "$(printf '%s\n' "$_pg_modules" | grep -c .)"
1111
+ fi
1112
+
1113
+ # The delegate script fails CLOSED by design when it finds zero under its own
1114
+ # root (see above) -- that is a real gap in a repo that declares an RLS lane,
1115
+ # not "this repo has no Postgres tests", and #1363's shape is exactly a
1116
+ # discovery-finds-nothing case reading as fine. Reported as its own failure,
1117
+ # distinct from and in addition to whatever the union below decides about the
1118
+ # repo-wide picture, because the two are different facts: "the declared
1119
+ # discovery is broken" and "here is what verify.sh found anyway".
1120
+ if [ -n "$PG_DELEGATE_FAILED" ] && [ -z "$LIST" ]; then
1121
+ FAILED="$FAILED pg-test-discovery"
1122
+ printf ' \033[31mFAIL\033[0m %-16s %s\n' "pg-test-discovery" "$PG_DELEGATE_FAILED_REASON"
1123
+ printf ' \033[31m%s\033[0m\n' \
1124
+ "this repo declares an RLS discovery script, so it finding zero modules is a gap, not an empty repo (#1618)"
1125
+ fi
1126
+
984
1127
  # Provision the database rather than requiring the operator to remember.
985
1128
  #
986
1129
  # A gate that only runs when you exported the right variable is a gate that runs