@boyingliu01/xp-gate 0.38.10 → 0.38.12
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/gate-registry.sh +13 -0
- package/hooks/gate-entries/gate-10-entry.sh +11 -0
- package/hooks/gate-entries/gate-12b-entry.sh +15 -0
- package/hooks/gate-entries/gate-12c-entry.sh +9 -19
- package/hooks/gate-entries/gate-13-entry.sh +20 -0
- package/hooks/gate-entries/gate-7-entry.sh +15 -1
- package/hooks/gate-entries/gate-8-entry.sh +7 -0
- package/hooks/gate-registry.sh +13 -0
- package/lib/__tests__/baseline-completeness.test.js +264 -0
- package/lib/__tests__/detect-deps-dsh-profile.test.js +177 -3
- package/lib/baseline.js +265 -86
- package/lib/detect-deps.js +8 -3
- package/lib/doctor.js +9 -5
- package/lib/gate-runner.js +14 -0
- package/lib/install-skill.js +15 -9
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/shared-paths.js +44 -8
- 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/sprint-flow/AGENTS.md +1 -1
- 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/sprint-flow/AGENTS.md +1 -1
- 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/sprint-flow/AGENTS.md +1 -1
- 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/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
package/gate-registry.sh
CHANGED
|
@@ -76,6 +76,19 @@ GATE_REGISTRY_ROWS=(
|
|
|
76
76
|
"sast|10|gate-10.sh|YES|pre-commit"
|
|
77
77
|
"sprint-flow|11|sprint-gate.sh|YES|pre-commit"
|
|
78
78
|
"file-hygiene|12|gate-12-file-hygiene.sh|NO|pre-commit"
|
|
79
|
+
# 12b and 12c were named in XP_GATE_ORDER and their bodies ran, but they had
|
|
80
|
+
# no row here. Everything that reads the registry therefore could not see them:
|
|
81
|
+
# `gate-list` and `gate-capability` omitted both, so nothing told a user the
|
|
82
|
+
# mirror-parity or probe-discipline checks existed. The project's own rule is
|
|
83
|
+
# explicit -- "an unregistered gate still runs ... the registry row is what
|
|
84
|
+
# makes it real" -- so the fix is the row, not prose elsewhere.
|
|
85
|
+
#
|
|
86
|
+
# `gate.sh` is the deciding file for both: each entry sources the real work
|
|
87
|
+
# from scripts/ (check-hook-mirror.sh, check-no-npx-probe.sh), and neither can
|
|
88
|
+
# run standalone in the sense the column asks about -- they need the staged
|
|
89
|
+
# change set the driver assembles.
|
|
90
|
+
"mirror-parity|12b|inline|NO|pre-commit"
|
|
91
|
+
"probe-discipline|12c|inline|NO|pre-commit"
|
|
79
92
|
"compiler-strictness|13|gate-13-compiler-strictness.sh|YES|pre-commit"
|
|
80
93
|
# pre-push. Registering these is identity bookkeeping only — pre-push keeps
|
|
81
94
|
# deciding its own execution order and skip semantics. Before this the
|
|
@@ -27,10 +27,19 @@
|
|
|
27
27
|
# stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
|
|
28
28
|
# here, and why sub-shell exits are deliberately left as `exit`.
|
|
29
29
|
gate_10_run() {
|
|
30
|
+
# #806 G10x: the SKIP arm below set GATE_10_STATUS and returned without a journal
|
|
31
|
+
# line. The gate's real work is delegated to $GATE_DIR/gate-10.sh, which records
|
|
32
|
+
# its own verdict -- so every path that does NOT reach it (deselected, script
|
|
33
|
+
# missing, nothing to scan) left no trace at all. Measured: `xp-gate audit` holds
|
|
34
|
+
# thousands of gate-10 rows and none of them came from these three arms, which
|
|
35
|
+
# made "skipped" and "never ran" the same thing. One start stamp, recorded in
|
|
36
|
+
# each arm that returns before the delegate.
|
|
37
|
+
GATE_10_START=$(gate_start_ms)
|
|
30
38
|
if ! gate_enabled 10; then
|
|
31
39
|
echo "⏭️ SKIPPED - Gate 10: SAST security (not selected by XP_GATE_ONLY_GATE)"
|
|
32
40
|
GATE_10_STATUS="SKIP"
|
|
33
41
|
GATE_10_DETAIL="not_selected"
|
|
42
|
+
record_gate_audit "gate-10" "sast" "$GATE_10_STATUS" "0" "$GATE_10_START"
|
|
34
43
|
return 0
|
|
35
44
|
fi
|
|
36
45
|
|
|
@@ -41,6 +50,7 @@ if any_changed_files_match "\.(ts|tsx|js|jsx|py|go|java|kt|cpp|c|swift|m|dart|sh
|
|
|
41
50
|
echo "⏭️ SKIPPED - SAST (gate-10.sh not found)"
|
|
42
51
|
GATE_10_STATUS="SKIP"
|
|
43
52
|
GATE_10_REASON="gate_script_missing"
|
|
53
|
+
record_gate_audit "gate-10" "sast" "$GATE_10_STATUS" "0" "$GATE_10_START"
|
|
44
54
|
fi
|
|
45
55
|
else
|
|
46
56
|
echo "⏭️ SKIPPED - No code files changed, skipping SAST scan."
|
|
@@ -48,6 +58,7 @@ else
|
|
|
48
58
|
# reason so the quality report never renders this path as a PASS claim.
|
|
49
59
|
GATE_10_STATUS="SKIP"
|
|
50
60
|
GATE_10_REASON="no_code_files_changed"
|
|
61
|
+
record_gate_audit "gate-10" "sast" "$GATE_10_STATUS" "0" "$GATE_10_START"
|
|
51
62
|
fi
|
|
52
63
|
# ============================================================================
|
|
53
64
|
return 0
|
|
@@ -34,10 +34,19 @@
|
|
|
34
34
|
# stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
|
|
35
35
|
# here, and why sub-shell exits are deliberately left as `exit`.
|
|
36
36
|
gate_12b_run() {
|
|
37
|
+
# #806 G12b: this body set GATE_12B_STATUS and never recorded it. Nothing in the
|
|
38
|
+
# repository reads that variable either, so the gate's verdict went nowhere: it
|
|
39
|
+
# could block a commit (that path does `return 1`, which the driver turns into an
|
|
40
|
+
# exit status) but a PASS or a SKIP left no journal line at all. `xp-gate audit`
|
|
41
|
+
# therefore showed 12 / 13 and never 12b, making "ran and passed" indistinguishable
|
|
42
|
+
# from "does not exist" -- the defect family the githooks AGENTS.md records for
|
|
43
|
+
# four other gates. One start stamp, recorded on every exit path below.
|
|
44
|
+
GATE_12B_START=$(gate_start_ms)
|
|
37
45
|
if ! gate_enabled 12b; then
|
|
38
46
|
echo "⏭️ SKIPPED - Gate 12b: Vendor exclusion (not selected by XP_GATE_ONLY_GATE)"
|
|
39
47
|
GATE_12B_STATUS="SKIP"
|
|
40
48
|
GATE_12B_DETAIL="not_selected"
|
|
49
|
+
record_gate_audit "gate-12b" "mirror-parity" "$GATE_12B_STATUS" "0" "$GATE_12B_START"
|
|
41
50
|
return 0
|
|
42
51
|
fi
|
|
43
52
|
|
|
@@ -176,6 +185,12 @@ if [ -n "$MIRROR_STAGED" ] && printf '%s
|
|
|
176
185
|
fi
|
|
177
186
|
fi
|
|
178
187
|
fi
|
|
188
|
+
# Reached only when nothing blocked, so this is the PASS record. The blocking
|
|
189
|
+
# arms `return 1` before getting here, which is deliberate: the driver turns
|
|
190
|
+
# that into the hook's exit status, and an audit line written after an exit
|
|
191
|
+
# would never run (the same dead-assignment trap the block above documents).
|
|
192
|
+
GATE_12B_STATUS="PASS"
|
|
193
|
+
record_gate_audit "gate-12b" "mirror-parity" "$GATE_12B_STATUS" "0" "$GATE_12B_START"
|
|
179
194
|
return 0
|
|
180
195
|
}
|
|
181
196
|
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
# stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
|
|
23
23
|
# here, and why sub-shell exits are deliberately left as `exit`.
|
|
24
24
|
gate_12c_run() {
|
|
25
|
+
# #806 G12c: same defect as 12b -- the body set GATE_12C_STATUS and no consumer
|
|
26
|
+
# ever read it, so a PASS or SKIP left no journal line. `xp-gate audit` showed
|
|
27
|
+
# 12 and 13 but never 12c. One start stamp, recorded on every exit path below.
|
|
28
|
+
GATE_12C_START=$(gate_start_ms)
|
|
25
29
|
# Gate 12c: probe discipline
|
|
26
30
|
#
|
|
27
31
|
# A command that could not RUN is not a command that found problems. The hooks
|
|
@@ -40,6 +44,7 @@ if ! gate_enabled 12c; then
|
|
|
40
44
|
echo "⏭️ SKIPPED - Gate 12c: Worktree hygiene (not selected by XP_GATE_ONLY_GATE)"
|
|
41
45
|
GATE_12C_STATUS="SKIP"
|
|
42
46
|
GATE_12C_DETAIL="not_selected"
|
|
47
|
+
record_gate_audit "gate-12c" "probe-discipline" "$GATE_12C_STATUS" "0" "$GATE_12C_START"
|
|
43
48
|
return 0
|
|
44
49
|
fi
|
|
45
50
|
|
|
@@ -59,26 +64,11 @@ if printf '%s\n' "$STAGED_FILES" 2>/dev/null | grep -qE '^githooks/(adapters/|li
|
|
|
59
64
|
fi
|
|
60
65
|
fi
|
|
61
66
|
fi
|
|
62
|
-
# ============================================================================
|
|
63
67
|
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
# -Wparentheses and -Wclass-memaccess on an innocuous-looking file; bare `javac`
|
|
69
|
-
# reports NOTHING for a raw type where `-Xlint:all` reports [rawtypes].
|
|
70
|
-
#
|
|
71
|
-
# Verdicts: 0 PASS, 1 FAIL (new findings -> blocked), 2 BLOCK (ran but output
|
|
72
|
-
# untrustworthy), 3 WARN (tool absent / cross-compiling / timeout / warn-only).
|
|
73
|
-
# A missing compiler is a SKIP-class WARN per the project convention, NOT a block.
|
|
74
|
-
#
|
|
75
|
-
# Escape hatches: XP_GATE_DISABLE_13=1 (kill switch),
|
|
76
|
-
# XP_GATE_COMPILER_STRICTNESS=strict|balanced|warn-only,
|
|
77
|
-
# XP_GATE_COMPILER_ANALYZER=1 (gcc -fanalyzer, C only, opt-in).
|
|
78
|
-
# Design: docs/plans/2026-10-26-gate-13-compiler-strictness-design.md
|
|
79
|
-
#
|
|
80
|
-
# NOTE: this block is a TAIL APPEND after Gate 12 and intentionally touches no
|
|
81
|
-
# line of the gates above it.
|
|
68
|
+
# Nothing blocked, so this is the PASS record (see the note in 12b's body for
|
|
69
|
+
# why blocking paths return before reaching here).
|
|
70
|
+
GATE_12C_STATUS="PASS"
|
|
71
|
+
record_gate_audit "gate-12c" "probe-discipline" "$GATE_12C_STATUS" "0" "$GATE_12C_START"
|
|
82
72
|
return 0
|
|
83
73
|
}
|
|
84
74
|
|
|
@@ -509,6 +509,26 @@ ENDJSON
|
|
|
509
509
|
}
|
|
510
510
|
|
|
511
511
|
gate_13_run() {
|
|
512
|
+
# Design rationale. This block used to sit at the bottom of gate-12c-entry.sh,
|
|
513
|
+
# where it documented a different gate: the reasoning was invisible to whoever
|
|
514
|
+
# edits this file, and gate 12c carried 20 lines of prose about a gate it does
|
|
515
|
+
# not run. Moved here unchanged.
|
|
516
|
+
#
|
|
517
|
+
# The compiler is the first and cheapest static analyser for a compiled language
|
|
518
|
+
# and XP-Gate never used it as one: cpp.sh only runs clang-tidy/cppcheck over the
|
|
519
|
+
# first 20 files, and Gate 9's build-integrity half is TypeScript-and-Maven only.
|
|
520
|
+
# A measured `g++ -Wall -Wextra` pass reports -Wnon-virtual-dtor, -Wreorder,
|
|
521
|
+
# -Wparentheses and -Wclass-memaccess on an innocuous-looking file; bare `javac`
|
|
522
|
+
# reports NOTHING for a raw type where `-Xlint:all` reports [rawtypes].
|
|
523
|
+
#
|
|
524
|
+
# Verdicts: 0 PASS, 1 FAIL (new findings -> blocked), 2 BLOCK (ran but output
|
|
525
|
+
# untrustworthy), 3 WARN (tool absent / cross-compiling / timeout / warn-only).
|
|
526
|
+
# A missing compiler is a SKIP-class WARN per the project convention, NOT a block.
|
|
527
|
+
#
|
|
528
|
+
# Escape hatches: XP_GATE_DISABLE_13=1 (kill switch),
|
|
529
|
+
# XP_GATE_COMPILER_STRICTNESS=strict|balanced|warn-only,
|
|
530
|
+
# XP_GATE_COMPILER_ANALYZER=1 (gcc -fanalyzer, C only, opt-in).
|
|
531
|
+
# Design: docs/plans/2026-10-26-gate-13-compiler-strictness-design.md
|
|
512
532
|
if ! gate_enabled 13; then
|
|
513
533
|
echo "⏭️ SKIPPED - Gate 13: Compiler strictness (not selected by XP_GATE_ONLY_GATE)"
|
|
514
534
|
GATE_13_STATUS="SKIP"
|
|
@@ -26,17 +26,31 @@
|
|
|
26
26
|
# stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
|
|
27
27
|
# here, and why sub-shell exits are deliberately left as `exit`.
|
|
28
28
|
gate_7_run() {
|
|
29
|
+
# #806 G7x: two defects in one small body.
|
|
30
|
+
#
|
|
31
|
+
# (a) Every path that did not reach $GATE_DIR/gate-7.sh -- deselect, and "no IaC
|
|
32
|
+
# files changed" -- returned without a journal line, so `xp-gate audit`
|
|
33
|
+
# could not distinguish "skipped" from "never ran".
|
|
34
|
+
# (b) The no-IaC arm printed "✅ PASSED". Nothing was scanned: there was nothing
|
|
35
|
+
# to scan. This is the exact wording rule this project keeps re-learning --
|
|
36
|
+
# "not checked" must never be printed as "passed". It is now SKIP with a
|
|
37
|
+
# reason, matching Gate 10's #536 precedent for the same situation.
|
|
38
|
+
GATE_7_START=$(gate_start_ms)
|
|
29
39
|
if ! gate_enabled 7; then
|
|
30
40
|
echo "⏭️ SKIPPED - Gate 7: IaC security (not selected by XP_GATE_ONLY_GATE)"
|
|
31
41
|
GATE_7_STATUS="SKIP"
|
|
32
42
|
GATE_7_DETAIL="not_selected"
|
|
43
|
+
record_gate_audit "gate-7" "iac-security" "$GATE_7_STATUS" "0" "$GATE_7_START"
|
|
33
44
|
return 0
|
|
34
45
|
fi
|
|
35
46
|
|
|
36
47
|
if any_changed_files_match "\.tf$" "\.tfvars$" "Dockerfile" "\.kube/" "\.ya?ml$"; then
|
|
37
48
|
source "$GATE_DIR/gate-7.sh"
|
|
38
49
|
else
|
|
39
|
-
echo "
|
|
50
|
+
echo "⏭️ SKIPPED - No IaC files changed, skipping Gate 7."
|
|
51
|
+
GATE_7_STATUS="SKIP"
|
|
52
|
+
GATE_7_REASON="no_iac_files_changed"
|
|
53
|
+
record_gate_audit "gate-7" "iac-security" "$GATE_7_STATUS" "0" "$GATE_7_START"
|
|
40
54
|
fi
|
|
41
55
|
return 0
|
|
42
56
|
}
|
|
@@ -24,10 +24,17 @@
|
|
|
24
24
|
# stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
|
|
25
25
|
# here, and why sub-shell exits are deliberately left as `exit`.
|
|
26
26
|
gate_8_run() {
|
|
27
|
+
# #806 G8x: the deselect arm set GATE_8_STATUS and returned without a journal
|
|
28
|
+
# line. This is the fail-closed security gate, so an unrecorded skip is the worst
|
|
29
|
+
# place to have one: "secret scanning was not selected" and "secret scanning does
|
|
30
|
+
# not exist in this chain" must not look the same. The delegate
|
|
31
|
+
# ($GATE_DIR/gate-8.sh) records its own verdicts; only this arm was silent.
|
|
32
|
+
GATE_8_START=$(gate_start_ms)
|
|
27
33
|
if ! gate_enabled 8; then
|
|
28
34
|
echo "⏭️ SKIPPED - Gate 8: Secret scanning (not selected by XP_GATE_ONLY_GATE)"
|
|
29
35
|
GATE_8_STATUS="SKIP"
|
|
30
36
|
GATE_8_DETAIL="not_selected"
|
|
37
|
+
record_gate_audit "gate-8" "secret-scanning" "$GATE_8_STATUS" "0" "$GATE_8_START"
|
|
31
38
|
return 0
|
|
32
39
|
fi
|
|
33
40
|
|
package/hooks/gate-registry.sh
CHANGED
|
@@ -76,6 +76,19 @@ GATE_REGISTRY_ROWS=(
|
|
|
76
76
|
"sast|10|gate-10.sh|YES|pre-commit"
|
|
77
77
|
"sprint-flow|11|sprint-gate.sh|YES|pre-commit"
|
|
78
78
|
"file-hygiene|12|gate-12-file-hygiene.sh|NO|pre-commit"
|
|
79
|
+
# 12b and 12c were named in XP_GATE_ORDER and their bodies ran, but they had
|
|
80
|
+
# no row here. Everything that reads the registry therefore could not see them:
|
|
81
|
+
# `gate-list` and `gate-capability` omitted both, so nothing told a user the
|
|
82
|
+
# mirror-parity or probe-discipline checks existed. The project's own rule is
|
|
83
|
+
# explicit -- "an unregistered gate still runs ... the registry row is what
|
|
84
|
+
# makes it real" -- so the fix is the row, not prose elsewhere.
|
|
85
|
+
#
|
|
86
|
+
# `gate.sh` is the deciding file for both: each entry sources the real work
|
|
87
|
+
# from scripts/ (check-hook-mirror.sh, check-no-npx-probe.sh), and neither can
|
|
88
|
+
# run standalone in the sense the column asks about -- they need the staged
|
|
89
|
+
# change set the driver assembles.
|
|
90
|
+
"mirror-parity|12b|inline|NO|pre-commit"
|
|
91
|
+
"probe-discipline|12c|inline|NO|pre-commit"
|
|
79
92
|
"compiler-strictness|13|gate-13-compiler-strictness.sh|YES|pre-commit"
|
|
80
93
|
# pre-push. Registering these is identity bookkeeping only — pre-push keeps
|
|
81
94
|
# deciding its own execution order and skip semantics. Before this the
|
|
@@ -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
|
+
});
|