@boyingliu01/xp-gate 0.38.125 → 0.38.126
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/gate-3.sh +34 -1
- package/adapters/gate-7.sh +15 -6
- package/bin/xp-gate.js +24 -0
- package/build-integrity/gate-10.ts +33 -8
- package/gate-3.sh +34 -1
- package/gate-registry.sh +3 -1
- package/hooks/deploy-manifest.sh +1 -0
- package/hooks/gate-3.sh +34 -1
- package/hooks/gate-entries/gate-1-entry.sh +35 -24
- package/hooks/gate-entries/gate-5-entry.sh +55 -19
- package/hooks/gate-entries/gate-6-entry.sh +15 -6
- package/hooks/gate-registry.sh +3 -1
- package/hooks/lib/gate-status.sh +164 -0
- package/hooks/lib/jscpd-run.sh +9 -1
- package/hooks/lib/native-path.sh +54 -0
- package/hooks/lib/toolchain-path.sh +38 -0
- package/hooks/pre-push +13 -4
- package/lib/__tests__/arch.test.js +7 -1
- package/lib/__tests__/audit-skip-reasons.test.ts +143 -0
- package/lib/__tests__/check-tools-list.test.js +155 -0
- package/lib/__tests__/doctor-tool-delegation.test.js +156 -0
- package/lib/__tests__/install-tools-repair.test.js +263 -0
- package/lib/__tests__/language-capability.test.js +27 -0
- package/lib/__tests__/tool-audit-collect.test.js +184 -0
- package/lib/__tests__/tool-audit-fixtures.js +87 -0
- package/lib/__tests__/tool-audit-latest.test.js +84 -0
- package/lib/__tests__/tool-audit.test.js +428 -0
- package/lib/deploy-manifest.js +1 -0
- package/lib/doctor-tool-checks.js +129 -0
- package/lib/doctor.js +15 -46
- package/lib/gate-audit.ts +80 -0
- package/lib/gate-runner.js +5 -0
- package/lib/language-capability-surfaces.js +70 -6
- package/lib/language-capability.js +3 -0
- package/lib/language-tools.js +409 -93
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/tool-audit.js +729 -0
- 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/dsh/src/skills.test.ts +9 -0
- 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
|
@@ -24,6 +24,14 @@
|
|
|
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_6_run() {
|
|
27
|
+
# Shared verdict rules: strongest verdict wins, details append.
|
|
28
|
+
_GATE_STATUS_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" && pwd)/gate-status.sh"
|
|
29
|
+
if [ -r "$_GATE_STATUS_LIB" ]; then
|
|
30
|
+
# shellcheck source=/dev/null
|
|
31
|
+
. "$_GATE_STATUS_LIB"
|
|
32
|
+
fi
|
|
33
|
+
unset _GATE_STATUS_LIB
|
|
34
|
+
|
|
27
35
|
if ! gate_enabled 6; then
|
|
28
36
|
# Recorded, not merely printed: this arm set the status and returned with no
|
|
29
37
|
# journal line, so wherever XP_GATE_ONLY_GATE selects a subset, "deselected on
|
|
@@ -575,12 +583,13 @@ CSARCHPROJ
|
|
|
575
583
|
;;
|
|
576
584
|
*)
|
|
577
585
|
echo " ⏭️ SKIPPED - Architecture validation (not configured for $CURRENT_LANG)"
|
|
578
|
-
|
|
579
|
-
#
|
|
580
|
-
#
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
586
|
+
# Append rather than overwrite: languages are walked in config order, so
|
|
587
|
+
# the LAST language with no architecture detector used to replace the
|
|
588
|
+
# reason of a language that HAD one. Measured 2026-11-24: all 14 gate-6
|
|
589
|
+
# records in this repo said "not configured for iac", including runs where
|
|
590
|
+
# archlint genuinely executed for TypeScript -- the iac arm simply ran
|
|
591
|
+
# after it.
|
|
592
|
+
xp_gate_detail_append GATE_6_DETAIL "architecture_skipped: not configured for ${CURRENT_LANG}"
|
|
584
593
|
;;
|
|
585
594
|
esac
|
|
586
595
|
done # end for CURRENT_LANG (architecture)
|
package/hooks/gate-registry.sh
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
# already reads.
|
|
55
55
|
#
|
|
56
56
|
# Numbers are POSITIONAL LABELS, never identities, and nothing here orders them
|
|
57
|
-
# numerically — pre-push numbers are strings (M,
|
|
57
|
+
# numerically — pre-push numbers are strings (M, ML, UI, MW, S). Do not add
|
|
58
58
|
# `-gt`/`-lt`/`$((` logic against this field;
|
|
59
59
|
# scripts/__tests__/gate-identity-cross-surface.test.cjs greps for it.
|
|
60
60
|
#
|
|
@@ -94,6 +94,8 @@ GATE_REGISTRY_ROWS=(
|
|
|
94
94
|
# deciding its own execution order and skip semantics. Before this the
|
|
95
95
|
# registry knew nothing about half the gates this project runs (#769).
|
|
96
96
|
"mutation|M|inline|YES|pre-push"
|
|
97
|
+
"mock-layering|ML|inline|YES|pre-push"
|
|
98
|
+
"ui-sprint|UI|inline|YES|pre-push"
|
|
97
99
|
"code-walkthrough|MW|inline|YES|pre-push"
|
|
98
100
|
"prepush-sprint|S|sprint-gate.sh|YES|pre-push"
|
|
99
101
|
)
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Gate status severity: one rule for every gate that walks several languages.
|
|
3
|
+
#
|
|
4
|
+
# WHY THIS FILE EXISTS
|
|
5
|
+
# --------------------
|
|
6
|
+
# A gate that iterates `PROJECT_LANGS` collects one verdict per language. Two
|
|
7
|
+
# defects followed from letting each iteration write the gate's status directly:
|
|
8
|
+
#
|
|
9
|
+
# 1. LAST WRITER WINS. Languages are walked in config order
|
|
10
|
+
# (typescript, shell, powershell, iac). A language that had nothing to
|
|
11
|
+
# measure ran AFTER one that did, and overwrote its verdict.
|
|
12
|
+
#
|
|
13
|
+
# Measured 2026-11-24 over 343 audit records:
|
|
14
|
+
# gate-5 0 PASS / 21 SKIP -- all skips "powershell: no Pester tests",
|
|
15
|
+
# in a repo carrying thousands of TypeScript tests.
|
|
16
|
+
# gate-6 0 PASS / 14 SKIP -- all "not configured for iac", including
|
|
17
|
+
# runs where archlint genuinely executed for TypeScript.
|
|
18
|
+
# gate-1 0 PASS / 19 WARN -- all "PSSA module not installed", so a real
|
|
19
|
+
# eslint pass could never be the gate's verdict.
|
|
20
|
+
#
|
|
21
|
+
# 2. DOWNGRADE. A branch could LOWER an existing verdict, turning "checked and
|
|
22
|
+
# clean" into "not checked". That is the fail-open direction: it makes the
|
|
23
|
+
# gate quieter without making it correct.
|
|
24
|
+
#
|
|
25
|
+
# THE RULE
|
|
26
|
+
# --------
|
|
27
|
+
# Carry the strongest verdict any language produced.
|
|
28
|
+
#
|
|
29
|
+
# BLOCK > WARN > SKIP > PASS
|
|
30
|
+
#
|
|
31
|
+
# A gate reports the worst thing that happened to it, never the last. `PASS` is
|
|
32
|
+
# "checked and clean", so ANY other state outranks it: an incomplete check must
|
|
33
|
+
# never be presented as a clean one.
|
|
34
|
+
#
|
|
35
|
+
# `SKIP` outranks `PASS` but is outranked by `WARN`, because:
|
|
36
|
+
# - SKIP says nothing was verified, and a neighbour that DID verify something
|
|
37
|
+
# successfully must not mask that with a PASS;
|
|
38
|
+
# - WARN says something was verified and came back imperfect, which is more
|
|
39
|
+
# informative than "nothing happened" and must not be buried by a later
|
|
40
|
+
# SKIP.
|
|
41
|
+
#
|
|
42
|
+
# CALL CONTRACT (round-3 review, expert B)
|
|
43
|
+
# ----------------------------------------
|
|
44
|
+
# Both helpers modify a variable in the CALLER'S shell through `printf -v`. A
|
|
45
|
+
# call made inside a pipeline (`... | while read x; do xp_gate_detail_append ...`)
|
|
46
|
+
# or a command substitution runs in a SUBSHELL and the update is silently
|
|
47
|
+
# discarded -- same shape as the defect this file exists to fix, and harder to
|
|
48
|
+
# see because the line still runs.
|
|
49
|
+
#
|
|
50
|
+
# # WRONG: the update is lost
|
|
51
|
+
# printf '%s\n' "$list" | while read -r _x; do xp_gate_detail_append D "$_x"; done
|
|
52
|
+
#
|
|
53
|
+
# # RIGHT: keep it in the current shell
|
|
54
|
+
# while read -r _x; do xp_gate_detail_append D "$_x"; done <<< "$list"
|
|
55
|
+
#
|
|
56
|
+
# Audited 2026-11-24: every call site in githooks/ is in the current shell, and
|
|
57
|
+
# `gate-status-call-site.test.bats` fails if a new one appears inside a pipeline.
|
|
58
|
+
# Sourced, not executed. Callers keep their own GATE_N_* variables; this file
|
|
59
|
+
# only provides the comparison so the rule lives in one place.
|
|
60
|
+
#
|
|
61
|
+
# ASCII only: this file is sourced by hooks that run under many locales.
|
|
62
|
+
|
|
63
|
+
# Numeric rank for a gate status. Unknown/empty ranks as the weakest value so a
|
|
64
|
+
# typo can never silently outrank a real verdict.
|
|
65
|
+
xp_gate_status_rank() {
|
|
66
|
+
case "${1:-}" in
|
|
67
|
+
BLOCK) printf '4' ;;
|
|
68
|
+
WARN) printf '3' ;;
|
|
69
|
+
SKIP) printf '2' ;;
|
|
70
|
+
PASS) printf '1' ;;
|
|
71
|
+
*) printf '0' ;;
|
|
72
|
+
esac
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
# Escalate a gate status variable to at least `candidate`.
|
|
76
|
+
#
|
|
77
|
+
# Usage:
|
|
78
|
+
# xp_gate_status_escalate GATE_5_STATUS "WARN"
|
|
79
|
+
#
|
|
80
|
+
# Sets the named variable through indirect assignment, so callers do not have to
|
|
81
|
+
# restructure their existing code. An empty current value is treated as unset.
|
|
82
|
+
xp_gate_status_escalate() {
|
|
83
|
+
local _var="${1:?variable name required}"
|
|
84
|
+
local _candidate="${2:?candidate status required}"
|
|
85
|
+
local _current="${!_var:-}"
|
|
86
|
+
local _cur_rank _new_rank
|
|
87
|
+
_cur_rank=$(xp_gate_status_rank "$_current")
|
|
88
|
+
_new_rank=$(xp_gate_status_rank "$_candidate")
|
|
89
|
+
# An unrecognised candidate would rank 0 and could never win; refuse it
|
|
90
|
+
# loudly rather than producing a gate whose status silently never moves.
|
|
91
|
+
if [ "$_new_rank" = "0" ]; then
|
|
92
|
+
printf 'xp_gate_status_escalate: unknown status %q (expected PASS|SKIP|WARN|BLOCK)\n' \
|
|
93
|
+
"$_candidate" >&2
|
|
94
|
+
return 2
|
|
95
|
+
fi
|
|
96
|
+
if [ "$_new_rank" -gt "$_cur_rank" ]; then
|
|
97
|
+
printf -v "$_var" '%s' "$_candidate"
|
|
98
|
+
fi
|
|
99
|
+
return 0
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# Append a detail fragment without clobbering an earlier one.
|
|
103
|
+
#
|
|
104
|
+
# Detail is a DESCRIPTION, not a verdict: several languages may each have
|
|
105
|
+
# something to say, and replacing the earlier text is what made a skip reason
|
|
106
|
+
# unexplainable.
|
|
107
|
+
#
|
|
108
|
+
# SEPARATOR INJECTION (round-1 review, expert B): the first version joined with
|
|
109
|
+
# `; ` and de-duplicated by splitting on that same string. A fragment that
|
|
110
|
+
# CONTAINS `; ` was therefore split into pieces, never matched any single
|
|
111
|
+
# segment, and got appended every time -- and a later reader could not tell the
|
|
112
|
+
# pieces from separate reasons. Measured: appending "x; y" produced a value that
|
|
113
|
+
# re-appended itself as two segments.
|
|
114
|
+
#
|
|
115
|
+
# The fix is to keep the pieces unmistakable: a fragment's internal separators
|
|
116
|
+
# are neutralised on the way in, so the recorded text never contains the join
|
|
117
|
+
# separator. `; ` stays the human-readable join because every existing consumer
|
|
118
|
+
# parses the field that way.
|
|
119
|
+
#
|
|
120
|
+
# Usage:
|
|
121
|
+
# xp_gate_detail_append GATE_6_DETAIL "powershell: PSSA module not installed"
|
|
122
|
+
xp_gate_detail_append() {
|
|
123
|
+
local _var="${1:?variable name required}"
|
|
124
|
+
local _fragment="${2:-}"
|
|
125
|
+
# Whitespace-only is "no reason given", not a reason of spaces.
|
|
126
|
+
case "$_fragment" in
|
|
127
|
+
*[![:space:]]*) ;;
|
|
128
|
+
*) return 0 ;;
|
|
129
|
+
esac
|
|
130
|
+
# Flatten internal separators so one fragment is always one segment.
|
|
131
|
+
_fragment="${_fragment//; /, }"
|
|
132
|
+
|
|
133
|
+
local _current="${!_var:-}"
|
|
134
|
+
if [ -z "$_current" ]; then
|
|
135
|
+
printf -v "$_var" '%s' "$_fragment"
|
|
136
|
+
return 0
|
|
137
|
+
fi
|
|
138
|
+
# Compare whole segments. They cannot contain "; " after the flattening above,
|
|
139
|
+
# so the split is unambiguous.
|
|
140
|
+
local _segment _found=0
|
|
141
|
+
local _rest="$_current"
|
|
142
|
+
while [ -n "$_rest" ]; do
|
|
143
|
+
case "$_rest" in
|
|
144
|
+
*"; "*) _segment="${_rest%%; *}"; _rest="${_rest#*; }" ;;
|
|
145
|
+
*) _segment="$_rest"; _rest="" ;;
|
|
146
|
+
esac
|
|
147
|
+
if [ "$_segment" = "$_fragment" ]; then
|
|
148
|
+
_found=1
|
|
149
|
+
break
|
|
150
|
+
fi
|
|
151
|
+
done
|
|
152
|
+
if [ "$_found" -eq 1 ]; then
|
|
153
|
+
return 0
|
|
154
|
+
fi
|
|
155
|
+
printf -v "$_var" '%s; %s' "$_current" "$_fragment"
|
|
156
|
+
return 0
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
# A NOTE ON WHY THIS FILE EXISTS (kept with the code, not in a plan document)
|
|
160
|
+
# Three gates in this repo had never produced a PASS: gate-1, gate-5 and gate-6
|
|
161
|
+
# all reported the verdict of their LAST language instead of their strongest.
|
|
162
|
+
# Measured 2026-11-24 across 343 audit records. The rule is one line of policy
|
|
163
|
+
# (BLOCK > WARN > SKIP > PASS, with PASS never outranking anything) and it must
|
|
164
|
+
# not be re-derived per gate.
|
package/hooks/lib/jscpd-run.sh
CHANGED
|
@@ -35,10 +35,18 @@
|
|
|
35
35
|
# More findings about its own output than about the code it was asked to check,
|
|
36
36
|
# in a report nobody can act on. Every other build-output directory was already
|
|
37
37
|
# listed; the one this tool writes itself was the omission.
|
|
38
|
+
# `src/npm-package` joins for the same reason, and it was the largest remaining
|
|
39
|
+
# offender in that measurement (1923 files). It is a BYTE-IDENTICAL mirror of
|
|
40
|
+
# githooks/, plugins/ and skills/, regenerated at prepack -- two files that must
|
|
41
|
+
# be identical are not duplicated code, and a finding nobody can act on costs
|
|
42
|
+
# 28 s per run (measured 2026-11-24: `check 2` took 28.4 s and FAILED on exactly
|
|
43
|
+
# these pairs). Mirror drift is a real defect with its own gate (12b); Gate 2
|
|
44
|
+
# re-deriving it from line similarity is both wrong and slow.
|
|
45
|
+
#
|
|
38
46
|
# *.md joins the set for the same reason *.yaml did: duplicate detection is
|
|
39
47
|
# about CODE, and a prose document mirrored into several plugin directories is
|
|
40
48
|
# duplicate by design. Measured before: 581 of 1410 findings were skill docs
|
|
41
|
-
JSCPD_DEFAULT_IGNORE_PATTERNS='(^|/)(node_modules|dist|build|target|coverage|out|\.next|\.nuxt|vendor|\.xp-gate)/|\.log$|\.txt$|\.(ya?ml)$|golden|baseline\.json$|evidence|\.md$'
|
|
49
|
+
JSCPD_DEFAULT_IGNORE_PATTERNS='(^|/)(node_modules|dist|build|target|coverage|out|\.next|\.nuxt|vendor|\.xp-gate|src/npm-package)/|\.log$|\.txt$|\.(ya?ml)$|golden|baseline\.json$|evidence|\.md$'
|
|
42
50
|
|
|
43
51
|
# The BUILD-OUTPUT half of the set above, alone (#649).
|
|
44
52
|
#
|
package/hooks/lib/native-path.sh
CHANGED
|
@@ -50,6 +50,54 @@ native_path_applies() {
|
|
|
50
50
|
#
|
|
51
51
|
# @param {string} path path to convert
|
|
52
52
|
# @returns {string} native form, or the input unchanged
|
|
53
|
+
#
|
|
54
|
+
# A NATIVE Linux binary must not be handed a converted path (#WSL).
|
|
55
|
+
#
|
|
56
|
+
# The original implementation converted on ANY host where wslpath exists, without
|
|
57
|
+
# asking what the consumer is. On WSL that is always -- so a Linux node/tsx was
|
|
58
|
+
# given `\\wsl.localhost\Ubuntu-22.04\home\...`, which node rejects outright:
|
|
59
|
+
#
|
|
60
|
+
# TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module
|
|
61
|
+
# "/…/llmveto/%5C%5Cwsl.localhost%5C…%5Cgate-10.ts" must not include encoded "/"
|
|
62
|
+
#
|
|
63
|
+
# Measured on this host (single-variable A/B, same file, same tsx, only the path form
|
|
64
|
+
# differs): POSIX arg -> "Overall: PASS" (exit 0); wslpath-converted arg -> the error
|
|
65
|
+
# above (exit 1). Gate 9 therefore blocked EVERY commit with advice to fix type errors
|
|
66
|
+
# in a repository whose tsc passes.
|
|
67
|
+
#
|
|
68
|
+
# wslpath existing means "this is WSL", not "the consumer is Windows". Only the latter
|
|
69
|
+
# needs conversion, and the evidence is the consumer's own file header: a natively
|
|
70
|
+
# compiled Linux binary is ELF (7f 45 4c 46), a Windows one is PE (MZ). So conversion is
|
|
71
|
+
# skipped whenever the consumer is ELF — which on this host means node/tsx.
|
|
72
|
+
# NATIVE_PATH_CONSUMER=<name-or-path> names the consumer explicitly; unset or unknown
|
|
73
|
+
# falls through to the original "host needs conversion" rule, so no call site changes
|
|
74
|
+
# behaviour on hosts this patch does not cover (git-bash, real Windows).
|
|
75
|
+
#
|
|
76
|
+
# Same defect class as #581, which moved the failure from "path not found" to
|
|
77
|
+
# "invalid module specifier" without fixing either: on this host the conversion
|
|
78
|
+
# itself is what corrupts the path. The consumer's file header is the only
|
|
79
|
+
# evidence that distinguishes the two cases — wslpath existing means "this is
|
|
80
|
+
# WSL", never "this consumer is Windows".
|
|
81
|
+
_to_native_path_needs_conversion() {
|
|
82
|
+
local _bin="${1:-}" _head=""
|
|
83
|
+
case "$_bin" in
|
|
84
|
+
""|node|tsx|npm|npx|nodejs)
|
|
85
|
+
# Known native-on-WSL interpreters: never convert when the binary on this
|
|
86
|
+
# host is a Linux ELF. A Windows node.exe is caught by the ELF check below.
|
|
87
|
+
_bin="$(command -v node 2>/dev/null || true)"
|
|
88
|
+
;;
|
|
89
|
+
esac
|
|
90
|
+
if [ -n "$_bin" ] && [ -f "$_bin" ]; then
|
|
91
|
+
_head=$(head -c 4 "$_bin" 2>/dev/null | od -An -tx1 | tr -d ' \n')
|
|
92
|
+
# 7f454c46 = ELF (Linux/macOS native) -> needs no conversion. 4d5a = MZ (PE) -> needs it.
|
|
93
|
+
case "$_head" in
|
|
94
|
+
7f454c46*) return 1 ;;
|
|
95
|
+
4d5a*) return 0 ;;
|
|
96
|
+
esac
|
|
97
|
+
fi
|
|
98
|
+
native_path_applies
|
|
99
|
+
}
|
|
100
|
+
|
|
53
101
|
to_native_path() {
|
|
54
102
|
local _p="${1:-}"
|
|
55
103
|
[ -n "$_p" ] || return 0
|
|
@@ -60,6 +108,12 @@ to_native_path() {
|
|
|
60
108
|
*) printf '%s' "$_p"; return 0 ;;
|
|
61
109
|
esac
|
|
62
110
|
|
|
111
|
+
# A native binary must receive the POSIX path unchanged: conversion is the bug.
|
|
112
|
+
if ! _to_native_path_needs_conversion "${NATIVE_PATH_CONSUMER:-}"; then
|
|
113
|
+
printf '%s' "$_p"
|
|
114
|
+
return 0
|
|
115
|
+
fi
|
|
116
|
+
|
|
63
117
|
local _converted=""
|
|
64
118
|
if [ -n "${WSL_DISTRO_NAME:-}" ] && command -v wslpath >/dev/null 2>&1; then
|
|
65
119
|
_converted=$(wslpath -w "$_p" 2>/dev/null || true)
|
|
@@ -150,6 +150,23 @@ tool_is_available() {
|
|
|
150
150
|
# run.
|
|
151
151
|
_hit=$(find_tool_in_original_path "$_tool")
|
|
152
152
|
fi
|
|
153
|
+
if [ -z "$_hit" ]; then
|
|
154
|
+
# #843: the same user-bin tier `resolve_tool_path` searches.
|
|
155
|
+
#
|
|
156
|
+
# These two functions must agree on WHERE a tool may live, or the platform
|
|
157
|
+
# contradicts itself: `resolve_tool_path` finds ~/.local/bin/gitleaks and
|
|
158
|
+
# returns it, then `tool_is_available` fails to see the same file and the
|
|
159
|
+
# caller is told the tool is unusable. Measured 2026-11-24 with
|
|
160
|
+
# PATH=/usr/bin:/bin: gitleaks and lizard were resolved and then rejected.
|
|
161
|
+
local _user_bin
|
|
162
|
+
for _user_bin in "${HOME:-}/.local/bin" "${HOME:-}/bin"; do
|
|
163
|
+
[ -n "${HOME:-}" ] || continue
|
|
164
|
+
if [ -x "$_user_bin/$_tool" ]; then
|
|
165
|
+
_hit="$_user_bin/$_tool"
|
|
166
|
+
break
|
|
167
|
+
fi
|
|
168
|
+
done
|
|
169
|
+
fi
|
|
153
170
|
[ -n "$_hit" ] || return 1
|
|
154
171
|
|
|
155
172
|
# Found — now prove it is not a shim pointing at an unreachable interpreter.
|
|
@@ -276,6 +293,27 @@ resolve_tool_path() {
|
|
|
276
293
|
fi
|
|
277
294
|
done
|
|
278
295
|
|
|
296
|
+
# The user install directory (#843).
|
|
297
|
+
#
|
|
298
|
+
# `pip install --user`, `cargo install`, and most "download the release binary
|
|
299
|
+
# and put it somewhere" recipes land in ~/.local/bin. Whether it happens to be
|
|
300
|
+
# in PATH depends on the shell that started the hook, NOT on whether the tool
|
|
301
|
+
# is installed -- and the two diverge precisely in the environments that matter
|
|
302
|
+
# most: a git GUI, an IDE-spawned terminal, or a WSL session launched from
|
|
303
|
+
# Windows (measured: PATH=/usr/bin:/bin resolves none of gitleaks / lizard /
|
|
304
|
+
# semgrep, while all three are present and working in ~/.local/bin).
|
|
305
|
+
#
|
|
306
|
+
# Trusting PATH alone therefore reports an installed scanner as missing, and
|
|
307
|
+
# the reader's natural response -- install it again, or give up on the check --
|
|
308
|
+
# is wrong in both directions. #841 is the mirror image: a Windows shim can be
|
|
309
|
+
# FOUND through PATH while being unable to run.
|
|
310
|
+
for _d in "${HOME:-}/.local/bin/$_tool" "${HOME:-}/bin/$_tool"; do
|
|
311
|
+
if [ -n "${HOME:-}" ] && [ -x "$_d" ]; then
|
|
312
|
+
printf '%s\n' "$_d"
|
|
313
|
+
return 0
|
|
314
|
+
fi
|
|
315
|
+
done
|
|
316
|
+
|
|
279
317
|
return 1
|
|
280
318
|
}
|
|
281
319
|
|
package/hooks/pre-push
CHANGED
|
@@ -27,9 +27,15 @@ _LE_CR=$(tr -cd '\r' < "$0" | wc -c | tr -d '[:space:]'); test "${_LE_CR:-0}" -e
|
|
|
27
27
|
# Pre-push Hook: Gate 10 (Build Integrity) + M/M-Python/M-Go/M-Java/M-Kotlin (Mutation)
|
|
28
28
|
# + MW (Code Walkthrough) + S (Sprint Flow)
|
|
29
29
|
#
|
|
30
|
-
# M2 (mock density)
|
|
31
|
-
#
|
|
32
|
-
#
|
|
30
|
+
# M2 (mock density) was removed 2026-11-20: it had a registry row and a report
|
|
31
|
+
# row but no implementation, so it printed SKIP with no reason on every push and
|
|
32
|
+
# could never do otherwise.
|
|
33
|
+
#
|
|
34
|
+
# ML (mock layering) and UI (UI sprint gates) were NOT removed -- this note had
|
|
35
|
+
# them wrong. Both are still defined AND called below (`run_gate_m3` for ML, the
|
|
36
|
+
# UI block after it), so they run on every push. They are now registered in
|
|
37
|
+
# githooks/gate-registry.sh, because an unregistered gate still runs while being
|
|
38
|
+
# invisible to `gate-capability` and to anything else that reads the registry.
|
|
33
39
|
#
|
|
34
40
|
# DESIGN: Hook validates result/executes checks, Skill executes AI review
|
|
35
41
|
# No CLI skill invocation - avoids OpenCode architecture mismatch
|
|
@@ -874,7 +880,10 @@ else
|
|
|
874
880
|
|
|
875
881
|
if [[ -z "$MUTATION_SCRIPT" ]]; then
|
|
876
882
|
echo "⚠️ Gate M script not found. SKIP — Gate M."
|
|
877
|
-
|
|
883
|
+
# One assignment, not two: the first was immediately overwritten by the
|
|
884
|
+
# second and never reached the report, so it read like two distinct skip
|
|
885
|
+
# paths that both existed. The surviving string is the descriptive one --
|
|
886
|
+
# `skip_kind` already carries the machine-readable category.
|
|
878
887
|
GATE_M_SKIP_REASON="gate-m.ts not found in .xp-gate/modules, src/mutation, or global modules"
|
|
879
888
|
GATE_M_SKIP_KIND="module_missing"
|
|
880
889
|
else
|
|
@@ -193,7 +193,13 @@ describe('resolveArchlint', () => {
|
|
|
193
193
|
expect(fs.existsSync(resolved.script)).toBe(true);
|
|
194
194
|
const pkgDir = path.dirname(path.dirname(resolved.script));
|
|
195
195
|
const version = JSON.parse(fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8')).version;
|
|
196
|
-
|
|
196
|
+
// Assert against the REPO'S OWN DECLARATION rather than a literal: the
|
|
197
|
+
// invariant under test is "the pinned dependency wins over the registry",
|
|
198
|
+
// and a hardcoded range turned a routine dependency bump into a red test
|
|
199
|
+
// while saying nothing about that invariant.
|
|
200
|
+
const declared = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, 'package.json'), 'utf8'))
|
|
201
|
+
.devDependencies['@archlinter/cli'];
|
|
202
|
+
expect(version).toMatch(new RegExp(`^${declared.replace(/^[\^~]/, '').replace(/\./g, '\\.')}`));
|
|
197
203
|
});
|
|
198
204
|
|
|
199
205
|
it('falls back to the project\'s local node_modules when the own dependency is skipped', () => {
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-AUDIT-SKIP-REASON
|
|
3
|
+
* @intent 审计能回答"某个门禁为什么一次都没跑",而不只是"它没跑"。
|
|
4
|
+
*
|
|
5
|
+
* journal 本来就有原因:144 条 SKIP 里 142 条的 `detail` 有值。缺的是
|
|
6
|
+
* 把它们**当成一个整体读出来**的能力——`audit --stats` 只给每个门禁的
|
|
7
|
+
* pass% 与平均耗时,所以"执行率 0%"可见,**原因不可见**。
|
|
8
|
+
*
|
|
9
|
+
* 而这个区别决定读者的行动:
|
|
10
|
+
* - `no_iac_files_changed` → 健康,没事可做
|
|
11
|
+
* - `checker_missing` → 装错了,要修
|
|
12
|
+
* 两者在旧视图里是同一个样子。
|
|
13
|
+
*
|
|
14
|
+
* @covers AC-AUDIT-SKIP-REASON-04 AC-AUDIT-SKIP-REASON-05
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, it, expect } from 'vitest';
|
|
18
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
|
19
|
+
import { tmpdir } from 'node:os';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { computeSkipReasons } from '../gate-audit';
|
|
22
|
+
|
|
23
|
+
/** Build a journal from minimal entries; only the fields the reducer reads. */
|
|
24
|
+
function journal(entries: Array<Record<string, unknown>>): string {
|
|
25
|
+
const dir = mkdtempSync(join(tmpdir(), 'audit-skipreasons-'));
|
|
26
|
+
mkdirSync(join(dir, '.xp-gate'), { recursive: true });
|
|
27
|
+
writeFileSync(
|
|
28
|
+
join(dir, '.xp-gate', 'audit.jsonl'),
|
|
29
|
+
entries.map((e) => JSON.stringify(e)).join('\n') + '\n',
|
|
30
|
+
'utf8',
|
|
31
|
+
);
|
|
32
|
+
return dir;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function entry(gate: string, status: string, detail?: string): Record<string, unknown> {
|
|
36
|
+
return {
|
|
37
|
+
timestamp: '2026-11-24T00:00:00.000Z',
|
|
38
|
+
gate_id: gate,
|
|
39
|
+
gate_name: gate,
|
|
40
|
+
passed: status !== 'BLOCK',
|
|
41
|
+
issues_found: 0,
|
|
42
|
+
duration_ms: 10,
|
|
43
|
+
trigger: 'commit',
|
|
44
|
+
repo_path: '/repo',
|
|
45
|
+
commit_hash: 'abc',
|
|
46
|
+
gate_status: status,
|
|
47
|
+
...(detail === undefined ? {} : { detail }),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe('computeSkipReasons', () => {
|
|
52
|
+
/**
|
|
53
|
+
* @test REQ-AUDIT-SKIP-REASON
|
|
54
|
+
* @intent 按原因分组并计数,且列出用该原因跳过的门禁
|
|
55
|
+
* @covers AC-AUDIT-SKIP-REASON-04
|
|
56
|
+
*/
|
|
57
|
+
it('groups SKIP rows by reason with their gates', () => {
|
|
58
|
+
const dir = journal([
|
|
59
|
+
entry('gate-7', 'SKIP', 'no_iac_files_changed'),
|
|
60
|
+
entry('gate-7', 'SKIP', 'no_iac_files_changed'),
|
|
61
|
+
entry('gate-12b', 'SKIP', 'checker_missing'),
|
|
62
|
+
entry('gate-8', 'PASS'),
|
|
63
|
+
]);
|
|
64
|
+
try {
|
|
65
|
+
const buckets = computeSkipReasons(dir);
|
|
66
|
+
expect(buckets).toHaveLength(2);
|
|
67
|
+
expect(buckets[0].reason).toBe('no_iac_files_changed');
|
|
68
|
+
expect(buckets[0].count).toBe(2);
|
|
69
|
+
expect(buckets[0].gates).toEqual([{ gate_id: 'gate-7', count: 2 }]);
|
|
70
|
+
expect(buckets[1].reason).toBe('checker_missing');
|
|
71
|
+
} finally {
|
|
72
|
+
rmSync(dir, { recursive: true, force: true });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @test REQ-AUDIT-SKIP-REASON
|
|
78
|
+
* @intent 没有原因的 SKIP 必须单独成桶,不能被丢掉或并进别的桶
|
|
79
|
+
* @covers AC-AUDIT-SKIP-REASON-05
|
|
80
|
+
*/
|
|
81
|
+
it('keeps reason-less SKIP rows visible in their own bucket', () => {
|
|
82
|
+
const dir = journal([
|
|
83
|
+
entry('gate-6', 'SKIP'),
|
|
84
|
+
entry('gate-6', 'SKIP', ' '),
|
|
85
|
+
entry('gate-3', 'SKIP', 'no_source_files_changed'),
|
|
86
|
+
]);
|
|
87
|
+
try {
|
|
88
|
+
const buckets = computeSkipReasons(dir);
|
|
89
|
+
const none = buckets.find((b) => b.reason === '(no reason)');
|
|
90
|
+
// An unnamed skip is a finding, not a rounding error: it must be counted.
|
|
91
|
+
expect(none?.count).toBe(2);
|
|
92
|
+
} finally {
|
|
93
|
+
rmSync(dir, { recursive: true, force: true });
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @test REQ-AUDIT-SKIP-REASON
|
|
99
|
+
* @intent 非 SKIP 记录不得进入统计——否则"跳过原因"会被 PASS/WARN 的 detail 污染
|
|
100
|
+
* @covers AC-AUDIT-SKIP-REASON-06
|
|
101
|
+
*/
|
|
102
|
+
it('ignores detail from PASS and WARN rows', () => {
|
|
103
|
+
const dir = journal([
|
|
104
|
+
entry('gate-3', 'SKIP', 'ccn_threshold_exceeded'),
|
|
105
|
+
entry('gate-3', 'PASS', 'ccn_threshold=5'),
|
|
106
|
+
entry('gate-12', 'WARN', 'missing_eof_newline'),
|
|
107
|
+
]);
|
|
108
|
+
try {
|
|
109
|
+
const buckets = computeSkipReasons(dir);
|
|
110
|
+
expect(buckets).toHaveLength(1);
|
|
111
|
+
expect(buckets[0].reason).toBe('ccn_threshold_exceeded');
|
|
112
|
+
} finally {
|
|
113
|
+
rmSync(dir, { recursive: true, force: true });
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('computeSkipReasons: unexplained skips are named', () => {
|
|
119
|
+
/**
|
|
120
|
+
* @test REQ-AUDIT-SKIP-REASON
|
|
121
|
+
* @intent 未记录原因的 SKIP 必须被单独标记,而不是与有原因的跳过分在一列里。
|
|
122
|
+
* 门禁写了 `skip_reason=UNRECORDED` 表示"我跳过了但没记原因"——那是
|
|
123
|
+
* 缺陷,不是解释。汇总若把它当普通字符串,读者无法区分
|
|
124
|
+
* "26 条跳过都解释了" 与 "26 条里有 3 条没解释"。
|
|
125
|
+
* @covers AC-AUDIT-SKIP-REASON-07
|
|
126
|
+
*/
|
|
127
|
+
it('flags UNRECORDED and reason-less rows as unexplained', () => {
|
|
128
|
+
const dir = journal([
|
|
129
|
+
entry('gate-3', 'SKIP', 'ccn_threshold=5; skip_reason=UNRECORDED'),
|
|
130
|
+
entry('gate-5', 'SKIP', 'no_iac_files_changed'),
|
|
131
|
+
entry('gate-6', 'SKIP'),
|
|
132
|
+
]);
|
|
133
|
+
try {
|
|
134
|
+
const buckets = computeSkipReasons(dir);
|
|
135
|
+
const byReason = Object.fromEntries(buckets.map((b) => [b.reason, b]));
|
|
136
|
+
expect(byReason['ccn_threshold=5; skip_reason=UNRECORDED'].unexplained).toBe(true);
|
|
137
|
+
expect(byReason['no_iac_files_changed'].unexplained).toBe(false);
|
|
138
|
+
expect(byReason['(no reason)'].unexplained).toBe(true);
|
|
139
|
+
} finally {
|
|
140
|
+
rmSync(dir, { recursive: true, force: true });
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|