@boyingliu01/xp-gate 0.38.9 → 0.38.11
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.
- package/adapters/shell.sh +87 -2
- package/hooks/gate-entries/gate-0-entry.sh +48 -3
- package/hooks/gate-entries/gate-12-entry.sh +20 -1
- package/hooks/gate-entries/gate-5-entry.sh +56 -2
- package/hooks/pre-commit +40 -0
- package/lib/__tests__/baseline-completeness.test.js +264 -0
- package/lib/baseline.js +265 -86
- package/lib/mattpocock-license-verdict.json +1 -1
- package/mock-policy/AGENTS.md +85 -83
- package/mutation/AGENTS.md +87 -61
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/ralph-loop/SKILL.md +1 -1
- package/plugins/claude-code/skills/ralph-loop/references/components.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +3 -3
- package/plugins/claude-code/skills/sprint-flow/__tests__/sprint-flow.test.cjs +25 -7
- package/plugins/claude-code/skills/sprint-flow/references/phase-overview.md +3 -3
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/ralph-loop/SKILL.md +1 -1
- package/plugins/dsh/skills/ralph-loop/references/components.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +3 -3
- package/plugins/dsh/skills/sprint-flow/__tests__/sprint-flow.test.cjs +25 -7
- package/plugins/dsh/skills/sprint-flow/references/phase-overview.md +3 -3
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/ralph-loop/SKILL.md +1 -1
- package/plugins/opencode/skills/ralph-loop/references/components.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +3 -3
- package/plugins/opencode/skills/sprint-flow/__tests__/sprint-flow.test.cjs +25 -7
- package/plugins/opencode/skills/sprint-flow/references/phase-overview.md +3 -3
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/ralph-loop/SKILL.md +1 -1
- package/plugins/qoder/skills/ralph-loop/references/components.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +3 -3
- package/plugins/qoder/skills/sprint-flow/__tests__/sprint-flow.test.cjs +25 -7
- package/plugins/qoder/skills/sprint-flow/references/phase-overview.md +3 -3
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/principles/AGENTS.md +103 -97
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/ralph-loop/SKILL.md +1 -1
- package/skills/ralph-loop/references/components.md +1 -1
- package/skills/sprint-flow/AGENTS.md +3 -3
- package/skills/sprint-flow/references/phase-overview.md +3 -3
- package/skills/test-specification-alignment/AGENTS.md +1 -1
package/adapters/shell.sh
CHANGED
|
@@ -155,6 +155,49 @@ _shell_test_files() {
|
|
|
155
155
|
-not -path './dist/*' 2>/dev/null | sort
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
# Resolve the bats binary the same way typescript.sh resolves its tools.
|
|
159
|
+
#
|
|
160
|
+
# The previous implementation asked `command -v bats` and nothing else. bats is a
|
|
161
|
+
# devDependency, so a real install puts it at node_modules/.bin/bats -- which is
|
|
162
|
+
# NOT on PATH when a git hook runs (git does not source the shell profile, and
|
|
163
|
+
# npm only adds node_modules/.bin for `npm run` scripts). The probe therefore
|
|
164
|
+
# failed on every real commit, the adapter printed "bats not available", returned
|
|
165
|
+
# 0, and Gate 5 recorded a PASS for a suite that was installed and never ran.
|
|
166
|
+
#
|
|
167
|
+
# Measured on this repo: `command -v bats` was empty while
|
|
168
|
+
# node_modules/.bin/bats existed and was executable. The existing
|
|
169
|
+
# adapter-shell-tests.test.bats could not see this because every case prepends a
|
|
170
|
+
# fake bats directory to PATH -- it tested a condition that does not hold in
|
|
171
|
+
# production.
|
|
172
|
+
#
|
|
173
|
+
# Search order mirrors typescript.sh `_local_bin`: the project's own
|
|
174
|
+
# node_modules/.bin first, then a bounded walk up through ancestors because npm
|
|
175
|
+
# hoists to the workspace root. Then, and only then, PATH -- so a globally
|
|
176
|
+
# installed bats still works and explicitly breaking the local one cannot silently
|
|
177
|
+
# resolve to something else. Nothing outside the checkout is required.
|
|
178
|
+
_shell_resolve_bats() {
|
|
179
|
+
local dir depth=0
|
|
180
|
+
if [ -x "node_modules/.bin/bats" ]; then
|
|
181
|
+
printf '%s\n' "node_modules/.bin/bats"
|
|
182
|
+
return 0
|
|
183
|
+
fi
|
|
184
|
+
dir="$(pwd)"
|
|
185
|
+
while [ "$depth" -lt 6 ]; do
|
|
186
|
+
depth=$((depth + 1))
|
|
187
|
+
[ "$dir" = "/" ] && break
|
|
188
|
+
dir="$(dirname "$dir")"
|
|
189
|
+
if [ -x "$dir/node_modules/.bin/bats" ]; then
|
|
190
|
+
printf '%s\n' "$dir/node_modules/.bin/bats"
|
|
191
|
+
return 0
|
|
192
|
+
fi
|
|
193
|
+
done
|
|
194
|
+
if command -v bats >/dev/null 2>&1; then
|
|
195
|
+
command -v bats
|
|
196
|
+
return 0
|
|
197
|
+
fi
|
|
198
|
+
return 1
|
|
199
|
+
}
|
|
200
|
+
|
|
158
201
|
run_tests() {
|
|
159
202
|
local suites
|
|
160
203
|
suites="$(_shell_test_files)"
|
|
@@ -166,7 +209,8 @@ run_tests() {
|
|
|
166
209
|
return 0
|
|
167
210
|
fi
|
|
168
211
|
|
|
169
|
-
|
|
212
|
+
local bats_bin
|
|
213
|
+
if ! bats_bin="$(_shell_resolve_bats)"; then
|
|
170
214
|
echo "bats not available, skipping shell test suite (install: npm i -D bats)"
|
|
171
215
|
return 0
|
|
172
216
|
fi
|
|
@@ -175,8 +219,16 @@ run_tests() {
|
|
|
175
219
|
count="$(printf '%s\n' "$suites" | wc -l | tr -d ' ')"
|
|
176
220
|
echo "Running Shell tests (${count} .bats suite(s))..."
|
|
177
221
|
|
|
222
|
+
# Report where bats came from: a locally resolved binary is the common case and
|
|
223
|
+
# making it visible is what turns "the gate ran the suite" into something a
|
|
224
|
+
# reader can verify rather than assume.
|
|
225
|
+
case "$bats_bin" in
|
|
226
|
+
/*) ;;
|
|
227
|
+
*) echo " using ${bats_bin}" ;;
|
|
228
|
+
esac
|
|
229
|
+
|
|
178
230
|
# shellcheck disable=SC2086 # word-splitting is the point: one arg per suite
|
|
179
|
-
|
|
231
|
+
"$bats_bin" $suites
|
|
180
232
|
return $?
|
|
181
233
|
}
|
|
182
234
|
|
|
@@ -186,3 +238,36 @@ run_coverage() {
|
|
|
186
238
|
echo "Shell coverage not available"
|
|
187
239
|
return 0
|
|
188
240
|
}
|
|
241
|
+
|
|
242
|
+
# Declare that this language's test suite is executed elsewhere (CI), so the
|
|
243
|
+
# commit-time gate must not run it.
|
|
244
|
+
#
|
|
245
|
+
# This is a capability DECLARATION in the #794 sense, not a language-name check
|
|
246
|
+
# in the gate: the adapter is the component that knows its own toolchain, and a
|
|
247
|
+
# list of names can only ever cover the languages someone remembered.
|
|
248
|
+
#
|
|
249
|
+
# Why it is needed at all: `run_tests` has no selection. `_shell_test_files`
|
|
250
|
+
# discovers every *.bats in the repo -- 284 here, measured -- and bats runs all of
|
|
251
|
+
# them. That was invisible because the old `command -v bats` probe failed on every
|
|
252
|
+
# real hook run and returned 0 before reaching the run; once the probe was fixed
|
|
253
|
+
# (see `_shell_resolve_bats`), a commit touching only shell.sh sat with no output
|
|
254
|
+
# for 100s+ and had to be killed, while the same hook on an empty index finished
|
|
255
|
+
# in well under 100s.
|
|
256
|
+
#
|
|
257
|
+
# The suites do still run: CI's `bats-contracts` job, sharded across runners.
|
|
258
|
+
# quality-gates.yml is explicit about not wanting a second copy in the local hook
|
|
259
|
+
# ("do not re-add a silent copy here"), because running them serially measured
|
|
260
|
+
# 18m47s of a 22m24s job. So the gate reports the delegation rather than silently
|
|
261
|
+
# dropping the check -- "not checked here" must stay distinguishable from
|
|
262
|
+
# "checked and clean", and the reader is told where it IS checked.
|
|
263
|
+
#
|
|
264
|
+
# Direct callers are unaffected: this only tells the gate whether to call
|
|
265
|
+
# `run_tests`; it does not disable the function.
|
|
266
|
+
tests_delegated_to_ci() {
|
|
267
|
+
return 0
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
# Where the delegation goes, so the gate can name it instead of saying "skipped".
|
|
271
|
+
tests_delegated_to_ci_target() {
|
|
272
|
+
echo "CI bats-contracts job (scripts/run-bats-ci.cjs)"
|
|
273
|
+
}
|
|
@@ -411,7 +411,51 @@ sync-version left a drifted checkout under a green Gate 0.
|
|
|
411
411
|
# Build tooling is source for `has_source` (it is code) but not for
|
|
412
412
|
# `has_real_source` (it needs no VERSION bump) -- so `continue` here
|
|
413
413
|
# skips only the second flag, keeping the single extension list below.
|
|
414
|
-
|
|
414
|
+
#
|
|
415
|
+
# #806 G0a: `githooks/gate-entries/*` was missing. Gate bodies live there
|
|
416
|
+
# and are the same kind of code as `githooks/adapters/*` -- both change
|
|
417
|
+
# what the gates DO, neither changes the shipped package's behaviour -- so
|
|
418
|
+
# leaving it out meant an adapter edit passed while a gate-logic edit
|
|
419
|
+
# demanded a VERSION bump. The only ways through were a real bump (which
|
|
420
|
+
# pollutes the version history with changes users cannot observe) or
|
|
421
|
+
# SKIP_VERSION_CHECK=1 (which bypasses the gate instead of satisfying it);
|
|
422
|
+
# the second was used repeatedly, which is how the asymmetry was found.
|
|
423
|
+
#
|
|
424
|
+
# A path prefix exempts everything beneath it, so these tests pin the
|
|
425
|
+
# boundary from both sides: gate-entries passes, and real source under
|
|
426
|
+
# other paths (including a `.sh` outside these prefixes) still blocks.
|
|
427
|
+
#
|
|
428
|
+
# #806 G0b: a skill's `scripts/` and `__tests__/` are the machinery that
|
|
429
|
+
# produces confidence in the skill -- changing them changes no behaviour a
|
|
430
|
+
# user experiences, exactly like the directories above.
|
|
431
|
+
#
|
|
432
|
+
# Deliberately NOT `skills/*`: sync-package-content.js:79 copies the whole
|
|
433
|
+
# of skills/ into the published package, and SKILL.md plus references/ ARE
|
|
434
|
+
# what the agent follows after install. Exempting the whole tree would let
|
|
435
|
+
# a change to shipped behaviour land without appearing anywhere in version
|
|
436
|
+
# history. Exempt the mechanics, not the instructions -- so these patterns
|
|
437
|
+
# anchor on the scripts/ and __tests__/ segments, never on `skills/*`.
|
|
438
|
+
src/npm-package/adapters/*|src/npm-package/scripts/*|src/npm-package/hooks/*|scripts/*|githooks/adapters/*|githooks/gate-entries/*|skills/*/scripts/*|skills/*/__tests__/*)
|
|
439
|
+
has_source=true
|
|
440
|
+
continue
|
|
441
|
+
;;
|
|
442
|
+
# #806 G0c: test files, anywhere. 684 are tracked across src/, githooks/,
|
|
443
|
+
# scripts/, plugins/ and skills/, and npm ships 261 of them -- the `files`
|
|
444
|
+
# list names directories such as `lib/` and `hooks/`, and the prefix drags
|
|
445
|
+
# their `__tests__/` along. So a test IS in the package, the same argument
|
|
446
|
+
# that exempted a skill's scripts/ and __tests__/ above.
|
|
447
|
+
#
|
|
448
|
+
# What a test asserts is not what a user experiences, and a version number
|
|
449
|
+
# promises a behaviour change. Requiring a bump for test edits trains
|
|
450
|
+
# maintainers to either inflate the version history or reach for
|
|
451
|
+
# SKIP_VERSION_CHECK=1 -- both were observed.
|
|
452
|
+
#
|
|
453
|
+
# Two conventions must both match, because this repo uses both: a
|
|
454
|
+
# `__tests__/` directory (src/, githooks/) and a sibling `*.test.*` file
|
|
455
|
+
# (scripts/, skills/). Anchored on full segments and the dotted infix, not
|
|
456
|
+
# a `*test*` substring -- `contest.cjs` and `latest.cjs` are real modules
|
|
457
|
+
# and stay gated (pinned by name in the tests).
|
|
458
|
+
*/__tests__/*|*.test.*)
|
|
415
459
|
has_source=true
|
|
416
460
|
continue
|
|
417
461
|
;;
|
|
@@ -468,8 +512,9 @@ Before committing:
|
|
|
468
512
|
2. Add entry to CHANGELOG.md
|
|
469
513
|
3. Run: node scripts/sync-version.cjs
|
|
470
514
|
|
|
471
|
-
Build-tooling-only changes (adapters/, scripts/, hooks
|
|
472
|
-
|
|
515
|
+
Build-tooling-only changes (adapters/, gate-entries/, scripts/, hooks/, and a
|
|
516
|
+
skill's scripts/ or __tests__/) need NO version bump and pass this gate
|
|
517
|
+
automatically — no marker required.
|
|
473
518
|
|
|
474
519
|
If you genuinely must land production source without a version bump, the
|
|
475
520
|
supported escape hatch is the env var (a message prefix cannot work here
|
|
@@ -29,17 +29,36 @@
|
|
|
29
29
|
gate_12_run() {
|
|
30
30
|
if ! gate_enabled 12; then
|
|
31
31
|
echo "⏭️ SKIPPED - Gate 12: File hygiene (not selected by XP_GATE_ONLY_GATE)"
|
|
32
|
+
# No GATE_12_DETAIL here (removed with #806 G12a): pre-commit's blocking-exit
|
|
33
|
+
# journal reads GATE_<id>_DETAIL, but only on a blocking exit, and Gate 12 is
|
|
34
|
+
# non-blocking -- so a detail variable for this gate is write-only. Gate 0/1
|
|
35
|
+
# populate one legitimately because they CAN block.
|
|
32
36
|
GATE_12_STATUS="SKIP"
|
|
33
|
-
GATE_12_DETAIL="not_selected"
|
|
34
37
|
return 0
|
|
35
38
|
fi
|
|
36
39
|
|
|
37
40
|
if [ -f "$GATE_DIR/gate-12-file-hygiene.sh" ]; then
|
|
38
41
|
source "$GATE_DIR/gate-12-file-hygiene.sh"
|
|
39
42
|
elif [ -f "$(git rev-parse --show-toplevel 2>/dev/null)/githooks/gate-12-file-hygiene.sh" ]; then
|
|
43
|
+
# shellcheck source=/dev/null
|
|
44
|
+
# Above: the path is only known at runtime (git rev-parse), so shellcheck
|
|
45
|
+
# cannot follow it and reports SC1090/SC1091. The guard on the preceding
|
|
46
|
+
# `elif` already proves the file exists, so this is a static-analysis
|
|
47
|
+
# limitation, not an unchecked source.
|
|
40
48
|
source "$(git rev-parse --show-toplevel)/githooks/gate-12-file-hygiene.sh"
|
|
41
49
|
else
|
|
50
|
+
# #806 G12a: this arm printed SKIPPED and stopped there, so GATE_12_STATUS kept
|
|
51
|
+
# whatever the driver left in it -- measured PASS -- and record_gate_audit was
|
|
52
|
+
# never called, meaning the gate left NO journal line at all. A gate that wrote
|
|
53
|
+
# nothing is indistinguishable from a gate the chain never contained, and the
|
|
54
|
+
# operator was told "SKIPPED" while the machine recorded a pass.
|
|
55
|
+
#
|
|
56
|
+
# Same family as #806 G1a (Gate 1's four SKIP sites) and #806 D2 (Gate 0's
|
|
57
|
+
# --skip-version-check arm): the words said SKIP, the state said PASS.
|
|
42
58
|
echo "⏭️ SKIPPED - Gate 12: File Hygiene (gate-12-file-hygiene.sh not found)"
|
|
59
|
+
GATE_12_STATUS="SKIP"
|
|
60
|
+
GATE_12_START=$(gate_start_ms)
|
|
61
|
+
record_gate_audit "gate-12" "file-hygiene" "$GATE_12_STATUS" "0" "$GATE_12_START"
|
|
43
62
|
fi
|
|
44
63
|
# ============================================================================
|
|
45
64
|
return 0
|
|
@@ -626,6 +626,16 @@ else
|
|
|
626
626
|
# Route to appropriate test runner via adapter
|
|
627
627
|
for CURRENT_LANG in $PROJECT_LANGS; do
|
|
628
628
|
ADAPTER_FILE=$(resolve_adapter_path "$CURRENT_LANG")
|
|
629
|
+
# Drop declarations left behind by the PREVIOUS adapter before sourcing this
|
|
630
|
+
# one. Adapters are sourced into one shell, so a function one adapter defines
|
|
631
|
+
# stays callable while the next language is being handled -- measured: after
|
|
632
|
+
# shell.sh declared its delegation, powershell was reported as delegating too,
|
|
633
|
+
# even though powershell.sh declares nothing. The consequence is not cosmetic:
|
|
634
|
+
# a stale "yes" removes test verification for a language that never asked for
|
|
635
|
+
# it, which is the exact failure mode the declaration's default is meant to
|
|
636
|
+
# prevent. `unset -f` on an absent function is a no-op, so this is safe for
|
|
637
|
+
# adapters that declare nothing.
|
|
638
|
+
unset -f tests_delegated_to_ci tests_delegated_to_ci_target coverage_runs_tests 2>/dev/null || true
|
|
629
639
|
if [ "${CURRENT_LANG}" != "unknown" ] && [ -n "$ADAPTER_FILE" ]; then
|
|
630
640
|
if source "$ADAPTER_FILE" 2>/dev/null; then
|
|
631
641
|
# TypeScript: vitest with smart test selection
|
|
@@ -819,7 +829,28 @@ else
|
|
|
819
829
|
# declare it runs the tests here as well. Double-running costs time; not
|
|
820
830
|
# running them would cost verification, and #794's precedent is that the
|
|
821
831
|
# slower mistake is the acceptable one for an undeclared adapter.
|
|
822
|
-
|
|
832
|
+
# An adapter may declare that its suite runs elsewhere. Checked FIRST,
|
|
833
|
+
# because for such an adapter the question below ("does coverage also run
|
|
834
|
+
# the tests?") is moot -- neither branch may call run_tests.
|
|
835
|
+
#
|
|
836
|
+
# Why this exists for shell specifically: `run_tests` has no selection and
|
|
837
|
+
# discovers every *.bats in the repo (284, measured), so calling it here is
|
|
838
|
+
# a multi-hour commit. That was masked by a failing `command -v bats`
|
|
839
|
+
# probe that returned 0 before the run; once the probe was fixed, a
|
|
840
|
+
# shell.sh-only commit hung with no output for 100s+ and had to be killed.
|
|
841
|
+
#
|
|
842
|
+
# The report line is required, not decorative: removing the run must not
|
|
843
|
+
# make the check indistinguishable from one that passed, and the reader
|
|
844
|
+
# has to be told where it IS verified (CI's sharded bats-contracts job,
|
|
845
|
+
# per quality-gates.yml -- "do not re-add a silent copy here").
|
|
846
|
+
if adapter_delegates_tests_to_ci; then
|
|
847
|
+
local _delegated_to
|
|
848
|
+
_delegated_to="$(adapter_test_delegation_target)"
|
|
849
|
+
echo "ℹ️ ${CURRENT_LANG}: tests run in ${_delegated_to}, not at commit time."
|
|
850
|
+
echo " Not checked by this gate -- verified on push/PR instead."
|
|
851
|
+
GATE_5_DETAIL="${GATE_5_DETAIL:+${GATE_5_DETAIL}; }${CURRENT_LANG}: tests delegated to ${_delegated_to}"
|
|
852
|
+
DELEGATED_LANGS="${DELEGATED_LANGS:+${DELEGATED_LANGS} }${CURRENT_LANG}"
|
|
853
|
+
elif adapter_declares_coverage_runs_tests; then
|
|
823
854
|
echo "ℹ️ ${CURRENT_LANG}: coverage run includes the tests — deferring test execution to a single pass."
|
|
824
855
|
TESTS_DEFERRED=true
|
|
825
856
|
else
|
|
@@ -1520,7 +1551,30 @@ else
|
|
|
1520
1551
|
;;
|
|
1521
1552
|
"powershell")
|
|
1522
1553
|
COVERAGE_ENFORCED=true
|
|
1523
|
-
|
|
1554
|
+
# #806 G5a: a repo with no Pester tests can never produce coverage.xml, yet
|
|
1555
|
+
# the branch below demanded one and BLOCKED -- refusing every commit that
|
|
1556
|
+
# touched a .ps1 on evidence the repo could not supply. The gate even printed
|
|
1557
|
+
# "No Pester tests found" earlier in the same run, then blocked for the
|
|
1558
|
+
# missing artifact anyway.
|
|
1559
|
+
#
|
|
1560
|
+
# "There are no tests to run" and "tests ran but coverage is missing" are
|
|
1561
|
+
# different states and must not collapse into one verdict. The first is SKIP
|
|
1562
|
+
# with a reason; the second stays fail-closed (#570: an unavailable
|
|
1563
|
+
# measurement is not a pass). Detection uses the same *.Tests.ps1 convention
|
|
1564
|
+
# the rest of Gate 5 uses, so a repo that acquires tests automatically gets
|
|
1565
|
+
# enforcement back -- there is nothing to remember to flip.
|
|
1566
|
+
if ! find . \( -name '*.Tests.ps1' -o -name '*.Tests.psm1' \) \
|
|
1567
|
+
-not -path './node_modules/*' -not -path './.git/*' \
|
|
1568
|
+
-print -quit 2>/dev/null | grep -q .; then
|
|
1569
|
+
echo "⏭️ SKIPPED - PowerShell coverage: no Pester tests in this project (*.Tests.ps1)"
|
|
1570
|
+
echo " Nothing can produce coverage.xml here, so the floor is not applicable."
|
|
1571
|
+
echo " This is NOT a pass: add Pester tests and coverage is enforced again."
|
|
1572
|
+
if [ -n "$(printf '%s' "${GATE_5_STATUS:-}")" ] && [ "$GATE_5_STATUS" = "PASS" ]; then
|
|
1573
|
+
GATE_5_STATUS="SKIP"
|
|
1574
|
+
fi
|
|
1575
|
+
GATE_5_DETAIL="powershell: no Pester tests (coverage not applicable)"
|
|
1576
|
+
COVERAGE_ENFORCED=false
|
|
1577
|
+
elif [ -f "coverage.xml" ]; then
|
|
1524
1578
|
# The threshold is passed INTO node: the verdict used to be computed
|
|
1525
1579
|
# against a hard-coded 80 inside the script, so a project that configured
|
|
1526
1580
|
# a different floor got a verdict about a number it never set (#570).
|
package/hooks/pre-commit
CHANGED
|
@@ -370,6 +370,46 @@ adapter_declares_coverage_runs_tests() {
|
|
|
370
370
|
( coverage_runs_tests ) >/dev/null 2>&1
|
|
371
371
|
}
|
|
372
372
|
|
|
373
|
+
# Ask the adapter whether its test suite is executed somewhere else (CI), so the
|
|
374
|
+
# commit-time gate must not run it.
|
|
375
|
+
#
|
|
376
|
+
# Same shape and same reasoning as `adapter_declares_coverage_runs_tests` above,
|
|
377
|
+
# and the asymmetry is again the whole design: a wrong "yes" removes test
|
|
378
|
+
# verification from the commit, so the default for an undeclared adapter is to
|
|
379
|
+
# RUN the tests. The reason the shell adapter declares it is measurable, not
|
|
380
|
+
# stylistic -- its `run_tests` has no selection and discovers every *.bats in the
|
|
381
|
+
# repo (284 here), which is a multi-hour job at commit time.
|
|
382
|
+
#
|
|
383
|
+
# What the declaration must NOT do is make the skip silent. Callers report where
|
|
384
|
+
# the suite actually runs; see gate-5's delegation branch.
|
|
385
|
+
adapter_delegates_tests_to_ci() {
|
|
386
|
+
local scope="${1:-}"
|
|
387
|
+
if [ -n "$scope" ]; then
|
|
388
|
+
(
|
|
389
|
+
# shellcheck disable=SC2086 # $scope is a single command name, deliberately unquoted for eval-free invocation
|
|
390
|
+
$scope >/dev/null 2>&1 || exit 1
|
|
391
|
+
command -v tests_delegated_to_ci >/dev/null 2>&1 || exit 1
|
|
392
|
+
tests_delegated_to_ci >/dev/null 2>&1
|
|
393
|
+
)
|
|
394
|
+
return $?
|
|
395
|
+
fi
|
|
396
|
+
command -v tests_delegated_to_ci >/dev/null 2>&1 || return 1
|
|
397
|
+
( tests_delegated_to_ci ) >/dev/null 2>&1
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
# Where a delegating adapter's suite runs, for the report line.
|
|
401
|
+
adapter_test_delegation_target() {
|
|
402
|
+
if command -v tests_delegated_to_ci_target >/dev/null 2>&1; then
|
|
403
|
+
local target
|
|
404
|
+
target="$( tests_delegated_to_ci_target 2>/dev/null )"
|
|
405
|
+
if [ -n "$target" ]; then
|
|
406
|
+
printf '%s\n' "$target"
|
|
407
|
+
return 0
|
|
408
|
+
fi
|
|
409
|
+
fi
|
|
410
|
+
printf '%s\n' "CI"
|
|
411
|
+
}
|
|
412
|
+
|
|
373
413
|
# Gate scripts directory — falls back to project githooks if ADAPTER_DIR doesn't have them.
|
|
374
414
|
# #505: the probe file and the tier order come from the generated data file, so
|
|
375
415
|
# this cascade cannot drift from what doctor.js reports.
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-152 Baseline CLI handler
|
|
3
|
+
* @intent `xp-gate baseline create` silently recorded NOTHING for TypeScript.
|
|
4
|
+
* It built one command line from every source file and passed it as argv:
|
|
5
|
+
* measured in this repo, 652 files and 31,917 characters, against a
|
|
6
|
+
* Windows command-line limit around 8,191. The call therefore always
|
|
7
|
+
* failed, and the failure was swallowed by a bare `catch {}` whose comment
|
|
8
|
+
* said "ESLint unavailable — skip". The resulting baseline contained zero
|
|
9
|
+
* eslint entries and 70 shellcheck ones, so Gate 1 compared every TS/JS
|
|
10
|
+
* file against a baseline of nothing.
|
|
11
|
+
*
|
|
12
|
+
* That is the worst possible shape for a baseline: it looks authoritative,
|
|
13
|
+
* it is committed and regenerated, and it silently waves through exactly
|
|
14
|
+
* the language this package is written in.
|
|
15
|
+
*
|
|
16
|
+
* Three separate defects, each sufficient to produce the empty result:
|
|
17
|
+
* 1. one argv for all files (fails over the platform limit);
|
|
18
|
+
* 2. a thrown error treated as "tool unavailable" — the two states
|
|
19
|
+
* ("found nothing" and "could not evaluate") were indistinguishable;
|
|
20
|
+
* 3. a `"undefined"` key written when a result could not be matched to a
|
|
21
|
+
* file, inflating the entry count by one and making the file count
|
|
22
|
+
* disagree with the number of real files.
|
|
23
|
+
* @covers AC-BASELINE-01 AC-BASELINE-02 AC-BASELINE-03
|
|
24
|
+
*/
|
|
25
|
+
const path = require('path');
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const os = require('os');
|
|
28
|
+
|
|
29
|
+
const { execFileSync } = require('child_process');
|
|
30
|
+
|
|
31
|
+
const { createBaseline } = require('../baseline.js');
|
|
32
|
+
|
|
33
|
+
describe('baseline completeness — a language must not vanish silently', () => {
|
|
34
|
+
let tmpDir;
|
|
35
|
+
const originalCwd = process.cwd;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create a fake linter in node_modules/.bin, in the shape the PLATFORM actually
|
|
39
|
+
* uses.
|
|
40
|
+
*
|
|
41
|
+
* On Windows cmd.exe cannot execute an extensionless POSIX sh wrapper at all --
|
|
42
|
+
* not even by absolute path -- so npm installs a `.cmd` launcher next to it and
|
|
43
|
+
* that is what a shell command resolves. A stub written only as `eslint` would
|
|
44
|
+
* therefore test a layout that never exists on this platform, and the test would
|
|
45
|
+
* fail for a reason unrelated to the defect under examination.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} binDir node_modules/.bin
|
|
48
|
+
* @param {string} name tool name
|
|
49
|
+
* @param {string} jsBody statements to run, as JS
|
|
50
|
+
*/
|
|
51
|
+
function writeLintStub(binDir, name, jsBody) {
|
|
52
|
+
const js = `#!/usr/bin/env node\n${jsBody}\n`;
|
|
53
|
+
if (process.platform === 'win32') {
|
|
54
|
+
const cmdPath = path.join(binDir, `${name}.cmd`);
|
|
55
|
+
// A .cmd shim that hands the script to node, mirroring npm's own launcher.
|
|
56
|
+
const jsPath = path.join(binDir, `${name}-stub.js`);
|
|
57
|
+
fs.writeFileSync(jsPath, js);
|
|
58
|
+
fs.writeFileSync(cmdPath, `@node "%~dp0${name}-stub.js" %*\r\n`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const stub = path.join(binDir, name);
|
|
62
|
+
fs.writeFileSync(stub, js);
|
|
63
|
+
fs.chmodSync(stub, 0o755);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'baseline-completeness-'));
|
|
68
|
+
process.cwd = () => tmpDir;
|
|
69
|
+
// `findFilesByExt` enumerates with `git ls-files`, so a fixture that is not a
|
|
70
|
+
// git work tree yields NO files and the linter is never invoked. Without this
|
|
71
|
+
// the tests would pass vacuously: the very code path under test would never
|
|
72
|
+
// run, and silence would look like success -- the same defect one level up.
|
|
73
|
+
execFileSync('git', ['init', '-q'], { cwd: tmpDir });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Stage the fixture so `git ls-files` reports it. Files are only visible to the
|
|
78
|
+
* baseline once tracked, which is also true of the real project.
|
|
79
|
+
*/
|
|
80
|
+
function trackAll() {
|
|
81
|
+
execFileSync('git', ['add', '-A', '-f'], { cwd: tmpDir });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
afterEach(() => {
|
|
85
|
+
process.cwd = originalCwd;
|
|
86
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('AC-BASELINE-01: many files do not become one over-long argv', async () => {
|
|
90
|
+
// Enough files that a single concatenated command line would exceed the
|
|
91
|
+
// platform limit. If the implementation still builds one argv, this is
|
|
92
|
+
// exactly the case that failed in the real repo.
|
|
93
|
+
const srcDir = path.join(tmpDir, 'src');
|
|
94
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
95
|
+
const names = [];
|
|
96
|
+
for (let i = 0; i < 400; i++) {
|
|
97
|
+
const name = `src/file-with-a-long-descriptive-name-${String(i).padStart(4, '0')}.ts`;
|
|
98
|
+
fs.writeFileSync(path.join(tmpDir, name), 'export const x = 1;\n');
|
|
99
|
+
names.push(name);
|
|
100
|
+
}
|
|
101
|
+
fs.writeFileSync(path.join(tmpDir, 'eslint.config.js'), 'module.exports = [];\n');
|
|
102
|
+
fs.writeFileSync(
|
|
103
|
+
path.join(tmpDir, 'package.json'),
|
|
104
|
+
JSON.stringify({ name: 'x', version: '1.0.0' })
|
|
105
|
+
);
|
|
106
|
+
// A stand-in linter: it records the argv it received, then answers with a
|
|
107
|
+
// JSON array. The real one is not needed to test how the command is built.
|
|
108
|
+
const binDir = path.join(tmpDir, 'node_modules', '.bin');
|
|
109
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
110
|
+
writeLintStub(
|
|
111
|
+
binDir,
|
|
112
|
+
'eslint',
|
|
113
|
+
"const fs=require('fs');\n" +
|
|
114
|
+
'fs.appendFileSync(process.env.ARGV_LOG, process.argv.length + "\\n");\n' +
|
|
115
|
+
'process.stdout.write("[]");'
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const logPath = path.join(tmpDir, 'argv.log');
|
|
119
|
+
const prev = process.env.ARGV_LOG;
|
|
120
|
+
process.env.ARGV_LOG = logPath;
|
|
121
|
+
try {
|
|
122
|
+
trackAll();
|
|
123
|
+
await createBaseline();
|
|
124
|
+
} finally {
|
|
125
|
+
if (prev === undefined) delete process.env.ARGV_LOG;
|
|
126
|
+
else process.env.ARGV_LOG = prev;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const invocations = fs.existsSync(logPath)
|
|
130
|
+
? fs.readFileSync(logPath, 'utf8').trim().split('\n').filter(Boolean).map(Number)
|
|
131
|
+
: [];
|
|
132
|
+
// The stub MUST have run. A test that only checks "no invocation was too
|
|
133
|
+
// large" passes vacuously when nothing ran at all -- and nothing running is
|
|
134
|
+
// precisely the old defect (the linter was found, the call failed, the
|
|
135
|
+
// failure was swallowed). Verified: against the pre-fix code this assertion
|
|
136
|
+
// is what goes red; the size bound alone stayed green.
|
|
137
|
+
expect(invocations.length).toBeGreaterThan(0);
|
|
138
|
+
// 400 files at 100 per batch -> 4 calls (the observed count, not a guess).
|
|
139
|
+
expect(invocations.length).toBeGreaterThanOrEqual(2);
|
|
140
|
+
for (const argc of invocations) {
|
|
141
|
+
expect(argc).toBeLessThanOrEqual(200);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('AC-BASELINE-02: an evaluation failure is not recorded as an empty result', async () => {
|
|
146
|
+
// The linter exists but errors out. The baseline must not quietly claim the
|
|
147
|
+
// language is clean — that is "did not evaluate" written as "found nothing".
|
|
148
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), { recursive: true });
|
|
149
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'a.ts'), 'export const x = 1;\n');
|
|
150
|
+
fs.writeFileSync(path.join(tmpDir, 'eslint.config.js'), 'module.exports = [];\n');
|
|
151
|
+
fs.writeFileSync(
|
|
152
|
+
path.join(tmpDir, 'package.json'),
|
|
153
|
+
JSON.stringify({ name: 'x', version: '1.0.0' })
|
|
154
|
+
);
|
|
155
|
+
const binDir = path.join(tmpDir, 'node_modules', '.bin');
|
|
156
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
157
|
+
writeLintStub(binDir, 'eslint', 'process.stderr.write("boom");process.exit(2);');
|
|
158
|
+
|
|
159
|
+
const warnings = [];
|
|
160
|
+
const origWarn = console.warn;
|
|
161
|
+
const origError = console.error;
|
|
162
|
+
console.warn = (...a) => warnings.push(a.join(' '));
|
|
163
|
+
console.error = (...a) => warnings.push(a.join(' '));
|
|
164
|
+
let result;
|
|
165
|
+
try {
|
|
166
|
+
trackAll();
|
|
167
|
+
result = await createBaseline();
|
|
168
|
+
} finally {
|
|
169
|
+
console.warn = origWarn;
|
|
170
|
+
console.error = origError;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const keys = Object.keys(result).filter(k => k !== 'undefined');
|
|
174
|
+
expect(keys.length).toBe(0);
|
|
175
|
+
// The failure has to be visible: silence is what made this defect survive.
|
|
176
|
+
expect(warnings.join('\n')).toMatch(/eslint/i);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('AC-BASELINE-03: no "undefined" key is ever written', async () => {
|
|
180
|
+
// Written when a tool's result could not be matched back to a file. It made
|
|
181
|
+
// `Object.keys(baseline).length` disagree with the number of real files, so
|
|
182
|
+
// "71 files tracked" was reported for 70.
|
|
183
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), { recursive: true });
|
|
184
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'a.ts'), 'export const x = 1;\n');
|
|
185
|
+
fs.writeFileSync(path.join(tmpDir, 'eslint.config.js'), 'module.exports = [];\n');
|
|
186
|
+
fs.writeFileSync(
|
|
187
|
+
path.join(tmpDir, 'package.json'),
|
|
188
|
+
JSON.stringify({ name: 'x', version: '1.0.0' })
|
|
189
|
+
);
|
|
190
|
+
const binDir = path.join(tmpDir, 'node_modules', '.bin');
|
|
191
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
192
|
+
// A result whose path matches NO discovered file -- the exact input that
|
|
193
|
+
// produced the bogus key.
|
|
194
|
+
const ranMarker = path.join(tmpDir, 'ran.marker');
|
|
195
|
+
writeLintStub(
|
|
196
|
+
binDir,
|
|
197
|
+
'eslint',
|
|
198
|
+
`require('fs').writeFileSync(${JSON.stringify(ranMarker)}, 'ran');` +
|
|
199
|
+
'process.stdout.write(JSON.stringify([{filePath:"/nowhere/ghost.ts",warningCount:3,errorCount:0}]));'
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
trackAll();
|
|
203
|
+
const result = await createBaseline();
|
|
204
|
+
// The stub must actually have been invoked. Otherwise the linter never ran,
|
|
205
|
+
// no unmatched result was ever produced, and "no undefined key" would hold
|
|
206
|
+
// for a reason that has nothing to do with the defect -- verified against the
|
|
207
|
+
// pre-fix code, where this assertion is required for the test to go red.
|
|
208
|
+
expect(fs.existsSync(ranMarker)).toBe(true);
|
|
209
|
+
expect(Object.keys(result)).not.toContain('undefined');
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe('local binary resolution — the launcher must be executable', () => {
|
|
214
|
+
// Measured on Windows, all four forms against the same installed tool:
|
|
215
|
+
// 'node_modules/.bin/eslint' -> "'node_modules' is not recognized"
|
|
216
|
+
// 'node node_modules/.bin/eslint' -> SyntaxError (POSIX sh wrapper)
|
|
217
|
+
// 'node_modules/.bin/eslint.cmd' -> "'node_modules' is not recognized"
|
|
218
|
+
// absolute path to eslint.cmd -> works
|
|
219
|
+
// So resolution has to yield an ABSOLUTE path and the platform's launcher.
|
|
220
|
+
let tmpDir;
|
|
221
|
+
const originalCwd = process.cwd;
|
|
222
|
+
|
|
223
|
+
beforeEach(() => {
|
|
224
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'baseline-bin-'));
|
|
225
|
+
process.cwd = () => tmpDir;
|
|
226
|
+
fs.mkdirSync(path.join(tmpDir, 'node_modules', '.bin'), { recursive: true });
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
afterEach(() => {
|
|
230
|
+
process.cwd = originalCwd;
|
|
231
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('AC-BASELINE-04: returns an absolute path to the platform launcher', async () => {
|
|
235
|
+
const { resolveLocalBin } = require('../baseline.js');
|
|
236
|
+
const binDir = path.join(tmpDir, 'node_modules', '.bin');
|
|
237
|
+
const expected = process.platform === 'win32'
|
|
238
|
+
? path.join(binDir, 'eslint.cmd')
|
|
239
|
+
: path.join(binDir, 'eslint');
|
|
240
|
+
fs.writeFileSync(expected, process.platform === 'win32' ? '@echo off\r\n' : '#!/bin/sh\n');
|
|
241
|
+
|
|
242
|
+
const resolved = resolveLocalBin('eslint');
|
|
243
|
+
expect(resolved).toBe(expected);
|
|
244
|
+
expect(path.isAbsolute(resolved)).toBe(true);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('AC-BASELINE-04: a relative path is never returned', async () => {
|
|
248
|
+
const { resolveLocalBin } = require('../baseline.js');
|
|
249
|
+
const binDir = path.join(tmpDir, 'node_modules', '.bin');
|
|
250
|
+
const name = process.platform === 'win32' ? 'eslint.cmd' : 'eslint';
|
|
251
|
+
fs.writeFileSync(path.join(binDir, name), 'x');
|
|
252
|
+
|
|
253
|
+
const resolved = resolveLocalBin('eslint');
|
|
254
|
+
// The old code returned the literal relative string "node_modules/.bin/eslint",
|
|
255
|
+
// which cmd.exe rejects even when the file exists.
|
|
256
|
+
expect(resolved).not.toBe('node_modules/.bin/eslint');
|
|
257
|
+
expect(path.isAbsolute(resolved)).toBe(true);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('AC-BASELINE-04: an absent tool resolves to null, not a broken path', async () => {
|
|
261
|
+
const { resolveLocalBin } = require('../baseline.js');
|
|
262
|
+
expect(resolveLocalBin('definitely-not-installed')).toBeNull();
|
|
263
|
+
});
|
|
264
|
+
});
|