@boyingliu01/xp-gate 0.38.4 → 0.38.5
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-10.sh +478 -0
- package/adapters/gate-12-file-hygiene.sh +315 -0
- package/adapters/gate-13-compiler-strictness.sh +1443 -0
- package/adapters/gate-6-layers.sh +375 -0
- package/adapters/gate-8.sh +13 -1
- package/adapters/iac.sh +60 -27
- package/adapters/shell.sh +50 -2
- package/build-integrity/gate-10.ts +44 -3
- package/gate-12-file-hygiene.sh +15 -7
- package/gate-8.sh +13 -1
- package/hooks/gate-12-file-hygiene.sh +15 -7
- package/hooks/gate-8.sh +13 -1
- package/hooks/gate-entries/gate-1-entry.sh +44 -3
- package/hooks/gate-entries/gate-5-entry.sh +8 -0
- package/hooks/post-commit +9 -0
- package/hooks/pre-push +11 -2
- package/lib/mattpocock-license-verdict.json +1 -1
- package/mock-policy/AGENTS.md +1 -1
- package/mutation/AGENTS.md +1 -1
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/bin/xp-gate-version-check.sh +6 -0
- 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/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -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/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -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/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -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/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/principles/AGENTS.md +1 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# ============================================================================
|
|
3
|
+
# GATE 6 (layers): Layer Boundary Enforcement
|
|
4
|
+
#
|
|
5
|
+
# ── WHY THIS EXISTS ─────────────────────────────────────────────────────────
|
|
6
|
+
# `architecture.yaml` has declared layer boundaries since 2026-04, and Gate 6
|
|
7
|
+
# has never enforced them. #16 found the config schema didn't match archlint;
|
|
8
|
+
# the fix at the time was to stop passing `--config`, which made `layers:` dead
|
|
9
|
+
# config forever. #686 documented the resulting false green, and #728 measured
|
|
10
|
+
# that archlint 0.16.0's own `layer_violation` detector returns zero findings
|
|
11
|
+
# under every configuration (-A, -d, enabled: true, globs, exact paths).
|
|
12
|
+
#
|
|
13
|
+
# So the config was never wrong in the way the issue titles suggest. Nothing
|
|
14
|
+
# ever read it. This script reads it.
|
|
15
|
+
#
|
|
16
|
+
# Design: docs/plans/2026-11-07-gate-6-layer-enforcement-design.md
|
|
17
|
+
# Issues: #686 (dead config exposed), #691 (ARCH-04 layer direction rules),
|
|
18
|
+
# #728 (archlint detector is a no-op)
|
|
19
|
+
#
|
|
20
|
+
# ── WHY NOT ARCHLINT ────────────────────────────────────────────────────────
|
|
21
|
+
# #728 is not a configuration bug we can wait out: the detector is listed,
|
|
22
|
+
# enable-able, and produces no output. Depending on it means the gate's verdict
|
|
23
|
+
# is a statement about archlint, not about the code.
|
|
24
|
+
#
|
|
25
|
+
# A second reason is scope. The iteration-speed design (O4) shrinks archlint to
|
|
26
|
+
# a per-directory scope, but a layer violation is *by definition* an edge
|
|
27
|
+
# between two directories. An incremental scan structurally cannot see it. This
|
|
28
|
+
# checker always builds the whole-repo graph, and is cheap enough to afford it.
|
|
29
|
+
#
|
|
30
|
+
# ── VERDICT CONTRACT (inherited from pre-commit's java.sh / powershell.sh) ──
|
|
31
|
+
# 0 = PASS no layer violations
|
|
32
|
+
# 1 = FAIL new violations on this change (commit blocked)
|
|
33
|
+
# 2 = BLOCK config present but unusable (fail-closed)
|
|
34
|
+
# 3 = WARN no layer config declared, or violations only in baseline
|
|
35
|
+
#
|
|
36
|
+
# ── PERFORMANCE ─────────────────────────────────────────────────────────────
|
|
37
|
+
# One awk pass over the tree. No subprocess per file, no network, no cache to
|
|
38
|
+
# invalidate.
|
|
39
|
+
# ============================================================================
|
|
40
|
+
|
|
41
|
+
set -uo pipefail
|
|
42
|
+
|
|
43
|
+
LAYER_CONFIG="${XP_GATE_LAYER_CONFIG:-architecture.yaml}"
|
|
44
|
+
LAYER_BASELINE="${XP_GATE_LAYER_BASELINE:-.layer-baseline.json}"
|
|
45
|
+
LAYER_SCAN_ROOT="${XP_GATE_LAYER_SCAN_ROOT:-.}"
|
|
46
|
+
LAYER_REASON=""
|
|
47
|
+
|
|
48
|
+
# ─── Output helpers ─────────────────────────────────────────────────────────
|
|
49
|
+
_layers_say() { echo " $*"; }
|
|
50
|
+
|
|
51
|
+
_layers_verdict() {
|
|
52
|
+
local code="$1" text="$2" reason="${3:-}"
|
|
53
|
+
_layers_say "$text"
|
|
54
|
+
if [ -n "$reason" ]; then
|
|
55
|
+
_layers_say " reason: $reason"
|
|
56
|
+
LAYER_REASON="$reason"
|
|
57
|
+
fi
|
|
58
|
+
exit "$code"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# ─── 1. No config → WARN, never a silent pass ───────────────────────────────
|
|
62
|
+
# The whole defect class here began with "no config means nothing to check, and
|
|
63
|
+
# nothing to check means success".
|
|
64
|
+
if [ ! -f "$LAYER_CONFIG" ]; then
|
|
65
|
+
_layers_verdict 3 \
|
|
66
|
+
"⚠️ No layer config ($LAYER_CONFIG) — layer boundaries NOT checked." \
|
|
67
|
+
"no_layer_config"
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
# ─── 2. Parse layers into a TSV: name, pattern, allowed, forbidden ──────────
|
|
71
|
+
LAYER_TSV=$(awk '
|
|
72
|
+
function trim(s) { gsub(/^[ \t]+|[ \t]+$/, "", s); return s }
|
|
73
|
+
function unq(s) { s = trim(s); gsub(/^["\047]|["\047]$/, "", s); return s }
|
|
74
|
+
# Split a YAML flow/block list into a comma-joined string of unquoted items.
|
|
75
|
+
function clean(v, k,i,p,out) {
|
|
76
|
+
v = trim(v); sub(/#.*$/, "", v); v = trim(v)
|
|
77
|
+
sub(/^\[/, "", v); sub(/\]$/, "", v)
|
|
78
|
+
k = split(v, p, ","); out = ""
|
|
79
|
+
for (i = 1; i <= k; i++) {
|
|
80
|
+
p[i] = unq(p[i])
|
|
81
|
+
if (p[i] != "") out = (out == "" ? p[i] : out "," p[i])
|
|
82
|
+
}
|
|
83
|
+
return out
|
|
84
|
+
}
|
|
85
|
+
# awk initialises every variable to "" rather than 0. `layerindent < 0` on an
|
|
86
|
+
# unset variable compares a string to a number and never fires, so the layer
|
|
87
|
+
# indent was never recorded and every layer was silently skipped — the same
|
|
88
|
+
# class of defect this gate exists to catch. Initialise explicitly.
|
|
89
|
+
# Emit one row per pattern so a layer can own several directories. Patterns
|
|
90
|
+
# are matched independently and longest-pattern-wins still resolves nesting.
|
|
91
|
+
# A layer with no pattern is emitted with an empty column: it can never match
|
|
92
|
+
# a file, and the scanner zero-classified guard reports that instead of
|
|
93
|
+
# treating it as clean.
|
|
94
|
+
function flush( k, i, p) {
|
|
95
|
+
if (name == "") return
|
|
96
|
+
k = split(pattern, p, ",")
|
|
97
|
+
if (k == 0) { print name "\t\t" allowed "\t" forbidden; name = ""; return }
|
|
98
|
+
for (i = 1; i <= k; i++) {
|
|
99
|
+
if (p[i] == "") continue
|
|
100
|
+
print name "\t" p[i] "\t" allowed "\t" forbidden
|
|
101
|
+
}
|
|
102
|
+
name = ""
|
|
103
|
+
}
|
|
104
|
+
BEGIN {
|
|
105
|
+
inlayers = 0; layerindent = -1
|
|
106
|
+
name = ""; pattern = ""; allowed = ""; forbidden = ""
|
|
107
|
+
}
|
|
108
|
+
/^[ \t]*#/ { next }
|
|
109
|
+
/^[ \t]*$/ { next }
|
|
110
|
+
{
|
|
111
|
+
line = $0
|
|
112
|
+
match(line, /^[ \t]*/); indent = RLENGTH
|
|
113
|
+
body = trim(line)
|
|
114
|
+
if (!inlayers) { if (body == "layers:") inlayers = 1; next }
|
|
115
|
+
# A key at indent 0 ends the layers block.
|
|
116
|
+
if (indent == 0) exit
|
|
117
|
+
if (layerindent < 0) layerindent = indent
|
|
118
|
+
# A \"<name>:\" line at the layer indent starts a new layer record.
|
|
119
|
+
# Supports both the map form (domain:) and an explicit name: field.
|
|
120
|
+
if (indent == layerindent && body ~ /^[A-Za-z0-9_-]+:[ \t]*$/) {
|
|
121
|
+
flush()
|
|
122
|
+
name = substr(body, 1, index(body, ":") - 1)
|
|
123
|
+
next
|
|
124
|
+
}
|
|
125
|
+
if (indent == layerindent && body ~ /^- /) { next }
|
|
126
|
+
if (name == "") next
|
|
127
|
+
if (body ~ /^name:/) { name = unq(substr(body, 6)) }
|
|
128
|
+
# `pattern:` and `patterns:` are both accepted. The singular form is the one
|
|
129
|
+
# the first tests happened to write; a layer that owns a directory plus a
|
|
130
|
+
# shared root needs more than one pattern, which is why `patterns:` occurs
|
|
131
|
+
# naturally. Accepting only one of the two made a correct config parse to an
|
|
132
|
+
# empty pattern list, which then matched no file and reported "0 violations"
|
|
133
|
+
# — the silent-pass shape this gate exists to remove.
|
|
134
|
+
else if (body ~ /^patterns?:/) { pattern = clean(substr(body, index(body, ":") + 1)) }
|
|
135
|
+
else if (body ~ /^allowedImports:/ || body ~ /^allowed_imports:/) { allowed = clean(substr(body, index(body, ":") + 1)) }
|
|
136
|
+
else if (body ~ /^forbiddenImports:/ || body ~ /^forbidden_imports:/) { forbidden = clean(substr(body, index(body, ":") + 1)) }
|
|
137
|
+
}
|
|
138
|
+
END { flush() }
|
|
139
|
+
' "$LAYER_CONFIG" 2>/dev/null)
|
|
140
|
+
|
|
141
|
+
# ─── 3. Config present but unparseable → BLOCK (fail-closed) ───────────────
|
|
142
|
+
if [ -z "$LAYER_TSV" ]; then
|
|
143
|
+
_layers_verdict 2 \
|
|
144
|
+
"❌ BLOCKED - $LAYER_CONFIG exists but declares no usable layers." \
|
|
145
|
+
"layer_config_unparsable"
|
|
146
|
+
fi
|
|
147
|
+
|
|
148
|
+
LAYER_COUNT=$(printf '%s\n' "$LAYER_TSV" | grep -c . || true)
|
|
149
|
+
|
|
150
|
+
# ─── 4. Collect source files ────────────────────────────────────────────────
|
|
151
|
+
# Via git rather than find: `git ls-files` honours .gitignore by construction
|
|
152
|
+
# (no node_modules/dist/coverage exclusions to keep in sync with the ignore
|
|
153
|
+
# rules) and is faster on Windows — 0.5s vs 6.5s on this repo.
|
|
154
|
+
#
|
|
155
|
+
# Both tracked AND untracked-but-not-ignored files are included. A staged-only
|
|
156
|
+
# view would be wrong twice over: untracked files are exactly what an agent has
|
|
157
|
+
# just authored (the moment the check matters most), and `--cached` also misses
|
|
158
|
+
# a violation introduced in a file the commit does not touch. Layer membership
|
|
159
|
+
# is a property of the tree, not of the diff.
|
|
160
|
+
#
|
|
161
|
+
# Fallback to find for non-git fixtures (the BATS suite uses bare temp dirs).
|
|
162
|
+
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
163
|
+
FILE_LIST=$(git ls-files --cached --others --exclude-standard -- \
|
|
164
|
+
'*.ts' '*.tsx' '*.js' '*.jsx' '*.mjs' '*.cjs' 2>/dev/null \
|
|
165
|
+
| grep -v '^\.layer-fixture' || true)
|
|
166
|
+
else
|
|
167
|
+
FILE_LIST=$(find "$LAYER_SCAN_ROOT" -type f \
|
|
168
|
+
\( -name '*.ts' -o -name '*.tsx' -o -name '*.js' -o -name '*.jsx' \
|
|
169
|
+
-o -name '*.mjs' -o -name '*.cjs' \) \
|
|
170
|
+
-not -path '*/node_modules/*' -not -path '*/.git/*' \
|
|
171
|
+
-not -path '*/dist/*' -not -path '*/coverage/*' \
|
|
172
|
+
-not -path '*/.stryker-tmp/*' -not -path '*/.layer-fixture*' 2>/dev/null | sed 's|^\./||')
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
if [ -z "$FILE_LIST" ]; then
|
|
176
|
+
_layers_verdict 3 \
|
|
177
|
+
"⚠️ No source files under $LAYER_SCAN_ROOT — layer boundaries NOT checked." \
|
|
178
|
+
"no_source_files"
|
|
179
|
+
fi
|
|
180
|
+
|
|
181
|
+
# ─── 5. Scan imports and classify violations ────────────────────────────────
|
|
182
|
+
LAYER_TSV_FILE="${TMPDIR:-/tmp}/xp-layer-tsv.$$"
|
|
183
|
+
printf '%s\n' "$LAYER_TSV" > "$LAYER_TSV_FILE"
|
|
184
|
+
|
|
185
|
+
# Side channel for the scan's own bookkeeping (files seen / files classified).
|
|
186
|
+
# Defaults to 0/0 so a scan that dies before writing it reads as "classified
|
|
187
|
+
# nothing", which lands on the WARN path rather than a silent pass.
|
|
188
|
+
LAYER_STATS_FILE="${TMPDIR:-/tmp}/xp-layer-stats.$$"
|
|
189
|
+
: > "$LAYER_STATS_FILE"
|
|
190
|
+
LAYER_CLASSIFIED_FILES=0
|
|
191
|
+
LAYER_CLASSIFIED=0
|
|
192
|
+
|
|
193
|
+
# The file list goes in as ARGV, not on stdin: awk builds FILENAME from ARGV,
|
|
194
|
+
# and a stdin-driven loop leaves FILENAME empty — every file would be assigned
|
|
195
|
+
# layer 0 and the scan would report a clean tree. That is exactly the failure
|
|
196
|
+
# mode this gate exists to prevent, so the plumbing has to be right first.
|
|
197
|
+
FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk '
|
|
198
|
+
BEGIN {
|
|
199
|
+
n = 0
|
|
200
|
+
while ((getline row < ENVIRON["XP_LAYER_TSV"]) > 0) {
|
|
201
|
+
if (row == "") continue
|
|
202
|
+
split(row, f, "\t")
|
|
203
|
+
if (f[1] == "") continue
|
|
204
|
+
n++
|
|
205
|
+
lname[n] = f[1]; lpat[n] = f[2]; lallow[n] = f[3]
|
|
206
|
+
# Patterns are compiled once here. layer_of() runs twice per source file
|
|
207
|
+
# (once for the importer, once per resolved target); recompiling there
|
|
208
|
+
# meant ~5800 regex builds for this repo and dominated the 2s scan.
|
|
209
|
+
lre[n] = pat2re(f[2])
|
|
210
|
+
llen[n] = length(f[2])
|
|
211
|
+
}
|
|
212
|
+
close(ENVIRON["XP_LAYER_TSV"])
|
|
213
|
+
if (n == 0) { print "LAYER_TABLE_EMPTY" > "/dev/stderr"; exit 3 }
|
|
214
|
+
}
|
|
215
|
+
function pat2re(p, s) {
|
|
216
|
+
s = p
|
|
217
|
+
gsub(/[.]/, "\\.", s)
|
|
218
|
+
gsub(/[*][*]/, "\001", s)
|
|
219
|
+
gsub(/[*]/, "[^/]*", s)
|
|
220
|
+
gsub(/\001/, ".*", s)
|
|
221
|
+
return "^" s "$"
|
|
222
|
+
}
|
|
223
|
+
# Membership is decided by the LONGEST matching pattern, so a nested layer
|
|
224
|
+
# beats its parent regardless of declaration order. First-match-wins would
|
|
225
|
+
# make the verdict depend on YAML ordering.
|
|
226
|
+
function layer_of(path, best, blen, i) {
|
|
227
|
+
best = 0; blen = -1
|
|
228
|
+
for (i = 1; i <= n; i++) {
|
|
229
|
+
if (llen[i] > blen && path ~ lre[i]) { blen = llen[i]; best = i }
|
|
230
|
+
}
|
|
231
|
+
return best
|
|
232
|
+
}
|
|
233
|
+
function in_csv(list, val, k, j, p) {
|
|
234
|
+
k = split(list, p, ",")
|
|
235
|
+
for (j = 1; j <= k; j++) if (p[j] == val) return 1
|
|
236
|
+
return 0
|
|
237
|
+
}
|
|
238
|
+
# `allowedImports` is written as path globs in this config ("src/shared/**")
|
|
239
|
+
# but reads naturally as layer names ("domain"). Accept both: a path glob is
|
|
240
|
+
# matched against the resolved target path, a bare identifier against the
|
|
241
|
+
# destination layer name. Supporting only one form silently misreports every
|
|
242
|
+
# edge that used the other, which is how an allow-list turns into a false
|
|
243
|
+
# accusation.
|
|
244
|
+
function allowed_ok(idx, tgt, dstname, k, j, p) {
|
|
245
|
+
k = split(lallow[idx], p, ",")
|
|
246
|
+
for (j = 1; j <= k; j++) {
|
|
247
|
+
if (p[j] == "") continue
|
|
248
|
+
if (p[j] == dstname) return 1
|
|
249
|
+
if (p[j] ~ /[*]/ && tgt ~ pat2re(p[j])) return 1
|
|
250
|
+
if (p[j] !~ /[*]/ && (tgt == p[j] || tgt ~ ("^" p[j] "/"))) return 1
|
|
251
|
+
}
|
|
252
|
+
return 0
|
|
253
|
+
}
|
|
254
|
+
# Resolve a relative specifier against the importing file.
|
|
255
|
+
function resolve(from, spec, np, i, dir, res, k, pp, trail, sx) {
|
|
256
|
+
sub(/[.](ts|tsx|js|jsx|mjs|cjs)$/, "", spec)
|
|
257
|
+
if (spec !~ /^[.][.]?\//) return ""
|
|
258
|
+
np = split(from, sx, "/")
|
|
259
|
+
dir = ""
|
|
260
|
+
for (i = 1; i < np; i++) dir = (dir == "" ? sx[i] : dir "/" sx[i])
|
|
261
|
+
res = dir
|
|
262
|
+
trail = spec
|
|
263
|
+
while (trail ~ /^[.][.]?\//) {
|
|
264
|
+
if (trail ~ /^[.]\//) { trail = substr(trail, 3); continue }
|
|
265
|
+
trail = substr(trail, 4)
|
|
266
|
+
if (res == "") return ""
|
|
267
|
+
k = split(res, pp, "/"); res = ""
|
|
268
|
+
for (i = 1; i < k; i++) res = (res == "" ? pp[i] : res "/" pp[i])
|
|
269
|
+
}
|
|
270
|
+
return (res == "" ? trail : res "/" trail)
|
|
271
|
+
}
|
|
272
|
+
FNR == 1 {
|
|
273
|
+
file = FILENAME
|
|
274
|
+
sub(/^[.][/]/, "", file)
|
|
275
|
+
src = layer_of(file)
|
|
276
|
+
# Classified-file accounting (#REVIEW-R5): a run where the config declares
|
|
277
|
+
# layers but no file matches any of them is indistinguishable from a clean
|
|
278
|
+
# tree, and reporting that as PASS is how "declared but unenforced" survives
|
|
279
|
+
# one level deeper. Count both sides so the verdict can tell them apart.
|
|
280
|
+
seen++
|
|
281
|
+
if (src != 0) classified++
|
|
282
|
+
}
|
|
283
|
+
{
|
|
284
|
+
line = $0
|
|
285
|
+
# Skip whole-line comments only. A trailing-comment strip would eat the
|
|
286
|
+
# // in http:// inside string literals.
|
|
287
|
+
if (line ~ /^[ \t]*(\/\/|[#]|[*]|\/\*)/) next
|
|
288
|
+
rest = line
|
|
289
|
+
while (match(rest, /from[ \t]+"[^"]+"|from[ \t]+\047[^\047]+\047/)) {
|
|
290
|
+
spec = substr(rest, RSTART, RLENGTH)
|
|
291
|
+
sub(/^from[ \t]+["\047]/, "", spec)
|
|
292
|
+
sub(/["\047]$/, "", spec)
|
|
293
|
+
rest = substr(rest, RSTART + RLENGTH)
|
|
294
|
+
if (src == 0 || spec == "") continue
|
|
295
|
+
tgt = resolve(file, spec)
|
|
296
|
+
if (tgt == "") continue
|
|
297
|
+
dst = layer_of(tgt)
|
|
298
|
+
if (dst == 0 || dst == src) continue
|
|
299
|
+
if (allowed_ok(src, tgt, lname[dst])) continue
|
|
300
|
+
printf "%s\t%s\t%s\t%s\n", file, lname[src], lname[dst], tgt
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
END {
|
|
304
|
+
# Classified-file counts go to a side file, not stdout: stdout is the
|
|
305
|
+
# findings stream the verdict reads, and mixing a summary line into it would
|
|
306
|
+
# be parsed as a violation.
|
|
307
|
+
if (ENVIRON["XP_LAYER_STATS"]) {
|
|
308
|
+
printf "%d %d\n", seen, classified > ENVIRON["XP_LAYER_STATS"]
|
|
309
|
+
close(ENVIRON["XP_LAYER_STATS"])
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
' $FILE_LIST 2>/dev/null)
|
|
313
|
+
rm -f "$LAYER_TSV_FILE"
|
|
314
|
+
|
|
315
|
+
if [ -s "$LAYER_STATS_FILE" ]; then
|
|
316
|
+
read -r LAYER_CLASSIFIED_FILES LAYER_CLASSIFIED < "$LAYER_STATS_FILE" || true
|
|
317
|
+
fi
|
|
318
|
+
rm -f "$LAYER_STATS_FILE"
|
|
319
|
+
case "$LAYER_CLASSIFIED_FILES" in ''|*[!0-9]*) LAYER_CLASSIFIED_FILES=0 ;; esac
|
|
320
|
+
case "$LAYER_CLASSIFIED" in ''|*[!0-9]*) LAYER_CLASSIFIED=0 ;; esac
|
|
321
|
+
|
|
322
|
+
# ─── 6. Verdict ─────────────────────────────────────────────────────────────
|
|
323
|
+
if [ -z "$FINDINGS" ]; then
|
|
324
|
+
# Zero findings means one of two very different things: every classified file
|
|
325
|
+
# obeyed the rules, or NO FILE was classified at all because the config and the
|
|
326
|
+
# tree disagree. The first is a pass; the second is a config/reality drift and
|
|
327
|
+
# calling it a pass is the "declared but unenforced" defect Gate 6 exists to
|
|
328
|
+
# catch. Tell them apart before saying anything good.
|
|
329
|
+
if [ "$LAYER_CLASSIFIED" -eq 0 ]; then
|
|
330
|
+
_layers_verdict 3 \
|
|
331
|
+
"⚠️ 0 of $LAYER_CLASSIFIED_FILES scanned file(s) match any of the $LAYER_COUNT declared layer(s) — nothing was actually checked." \
|
|
332
|
+
"layer_config_matches_no_files" \
|
|
333
|
+
" Declared patterns are checked against repo-relative paths." \
|
|
334
|
+
" A config for a different layout than this tree will never enforce anything."
|
|
335
|
+
fi
|
|
336
|
+
_layers_verdict 0 \
|
|
337
|
+
"✅ Layer boundaries verified ($LAYER_COUNT layers, $LAYER_CLASSIFIED file(s) classified, 0 violations)." \
|
|
338
|
+
"layers_checked"
|
|
339
|
+
fi
|
|
340
|
+
TOTAL=$(printf '%s\n' "$FINDINGS" | grep -c . || true)
|
|
341
|
+
|
|
342
|
+
# Ratchet: a recorded baseline is a debt ledger, not an amnesty.
|
|
343
|
+
# The comparison lives in its own file rather than inline: three levels of
|
|
344
|
+
# quoting (bash single quotes -> node source -> JSON) is where the tab-in-JSON
|
|
345
|
+
# bug hid, and a baseline that fails to parse must not be read as "no
|
|
346
|
+
# baseline" — that would make a broken ledger look like a fresh start.
|
|
347
|
+
if [ -f "$LAYER_BASELINE" ] && command -v node >/dev/null 2>&1; then
|
|
348
|
+
NEW_FINDINGS=$(printf '%s\n' "$FINDINGS" | node "$(dirname "$0")/lib/layer-baseline.cjs" "$LAYER_BASELINE" 2>/dev/null)
|
|
349
|
+
if [ $? -eq 4 ]; then
|
|
350
|
+
_layers_verdict 2 \
|
|
351
|
+
"❌ BLOCKED - $LAYER_BASELINE exists but cannot be parsed (fail-closed)." \
|
|
352
|
+
"layer_baseline_unreadable"
|
|
353
|
+
fi
|
|
354
|
+
else
|
|
355
|
+
NEW_FINDINGS="$FINDINGS"
|
|
356
|
+
fi
|
|
357
|
+
|
|
358
|
+
NEW_COUNT=$(printf '%s\n' "$NEW_FINDINGS" | grep -c . || true)
|
|
359
|
+
|
|
360
|
+
if [ "$NEW_COUNT" -eq 0 ]; then
|
|
361
|
+
_layers_verdict 3 \
|
|
362
|
+
"⚠️ $TOTAL layer violation(s), all in baseline — no new violations." \
|
|
363
|
+
"layers_checked_baselined"
|
|
364
|
+
fi
|
|
365
|
+
|
|
366
|
+
_layers_say "❌ BLOCKED - $NEW_COUNT new layer violation(s) (of $TOTAL total):"
|
|
367
|
+
printf '%s\n' "$NEW_FINDINGS" | head -10 | while IFS="$(printf '\t')" read -r f s d t; do
|
|
368
|
+
_layers_say " - $f [$s -> $d] imports $t"
|
|
369
|
+
done
|
|
370
|
+
if [ "$NEW_COUNT" -gt 10 ]; then
|
|
371
|
+
_layers_say " ... and $((NEW_COUNT - 10)) more"
|
|
372
|
+
fi
|
|
373
|
+
_layers_say " A layer may import only what its allowedImports lists."
|
|
374
|
+
_layers_say " To accept an existing violation, record it in $LAYER_BASELINE."
|
|
375
|
+
exit 1
|
package/adapters/gate-8.sh
CHANGED
|
@@ -348,7 +348,19 @@ if command -v detect-secrets-hook >/dev/null 2>&1 && [ -f ".secrets.baseline" ];
|
|
|
348
348
|
fi
|
|
349
349
|
# Temp cleanup is owned by the gate8_cleanup trap; no rm here.
|
|
350
350
|
else
|
|
351
|
-
|
|
351
|
+
# #793: this branch used to blame the tool unconditionally. Both "the hook is
|
|
352
|
+
# not installed" and "the baseline file is missing" land here, so a repo with
|
|
353
|
+
# detect-secrets 1.5.52 on PATH was told to run `pip install -e ".[dev]"` --
|
|
354
|
+
# correct-looking advice that changes nothing, while the file actually missing
|
|
355
|
+
# (the committed `.secrets.baseline`) was never named. The two have different
|
|
356
|
+
# remedies and only one of them is an install, so they are split here.
|
|
357
|
+
if command -v detect-secrets-hook >/dev/null 2>&1; then
|
|
358
|
+
echo " ⚠️ detect-secrets-hook is installed but .secrets.baseline is missing."
|
|
359
|
+
echo " Generate it once with: detect-secrets scan > .secrets.baseline"
|
|
360
|
+
echo " (gitleaks still ran.)"
|
|
361
|
+
else
|
|
362
|
+
echo " ⚠️ detect-secrets-hook unavailable (install: pip install -e \".[dev]\") — gitleaks only."
|
|
363
|
+
fi
|
|
352
364
|
fi
|
|
353
365
|
|
|
354
366
|
record_gate_audit "gate-8" "secret-scanning" "$GATE_8_STATUS" "0" "$GATE_8_START"
|
package/adapters/iac.sh
CHANGED
|
@@ -152,19 +152,68 @@ run_static_analysis() {
|
|
|
152
152
|
# Record a checkov run's exit status and flag a crash. Codes 0 and 1 are
|
|
153
153
|
# normal (1 = findings); anything else, or any traceback in the log, is the
|
|
154
154
|
# tool failing rather than reporting.
|
|
155
|
+
#
|
|
156
|
+
# $2 is how many FILES this run covered, not how many runs happened. Since
|
|
157
|
+
# one launch can now scan a whole batch (#805), counting launches would make
|
|
158
|
+
# a 3-file commit report "1 file(s) scanned" — true about processes, false
|
|
159
|
+
# about coverage, and the completion message is what a reader trusts when
|
|
160
|
+
# deciding whether the gate looked at everything.
|
|
155
161
|
record_checkov_run() {
|
|
156
|
-
local status=$1
|
|
157
|
-
checkov_scan_count=$((checkov_scan_count +
|
|
162
|
+
local status=$1 covered=${2:-1}
|
|
163
|
+
checkov_scan_count=$((checkov_scan_count + covered))
|
|
158
164
|
# #803: a checkov run counts as a completed scan even when it reports a
|
|
159
165
|
# failure — the point of this counter is "a scanner looked", which is what
|
|
160
166
|
# distinguishes a clean scan from a missing toolchain.
|
|
161
167
|
iac_scans_completed=$((iac_scans_completed + 1))
|
|
162
168
|
if [ "$status" -ne 0 ] && [ "$status" -ne 1 ]; then
|
|
169
|
+
# Batching makes the crash LESS specific but never less visible: one
|
|
170
|
+
# status covers the whole batch, so a crash distrusted all of it. Saying
|
|
171
|
+
# "on a batch of N" is honest about that; naming one file would imply we
|
|
172
|
+
# know which one failed, which a batched call cannot tell us.
|
|
163
173
|
CHECKOV_CRASHED=1
|
|
164
|
-
echo " ⚠️ checkov exited $status on $file — the scanner failed, this is not a finding"
|
|
174
|
+
echo " ⚠️ checkov exited $status on a batch of $covered file(s) — the scanner failed, this is not a finding"
|
|
165
175
|
fi
|
|
166
176
|
}
|
|
167
177
|
|
|
178
|
+
# Run checkov once per BATCH of same-framework files instead of once per file.
|
|
179
|
+
#
|
|
180
|
+
# Measured 2026-11-15 (Windows/Git Bash, load 2.2-4.9 of 8 cores): checkov's
|
|
181
|
+
# cost is python startup + framework import, not scanning. Three real
|
|
182
|
+
# workflows cost 106.2 s as three launches and 30.6 s as one, for the same
|
|
183
|
+
# 300 checks. A 4-line file still cost 19.9 s, which is the proof that the
|
|
184
|
+
# constant dominates.
|
|
185
|
+
#
|
|
186
|
+
# The argument form matters and is NOT obvious: `--file A --file B` scans only
|
|
187
|
+
# A (verified — it reported 116 checks, the single-file count), while
|
|
188
|
+
# `--file A B` scans both, per checkov's documented `-f FILE [FILE ...]`
|
|
189
|
+
# signature. So the paths must be expanded into ONE --file list.
|
|
190
|
+
#
|
|
191
|
+
# Only files that exist are passed: the old loop skipped missing ones
|
|
192
|
+
# individually, and handing checkov a path that disappeared between detection
|
|
193
|
+
# and scanning would turn a benign race into a scanner error.
|
|
194
|
+
scan_checkov_batch() {
|
|
195
|
+
local framework_arg=$1
|
|
196
|
+
shift
|
|
197
|
+
local batch=""
|
|
198
|
+
local covered=0
|
|
199
|
+
local file
|
|
200
|
+
for file in "$@"; do
|
|
201
|
+
if [ -f "$file" ]; then
|
|
202
|
+
batch="$batch $file"
|
|
203
|
+
covered=$((covered + 1))
|
|
204
|
+
fi
|
|
205
|
+
done
|
|
206
|
+
[ "$covered" -gt 0 ] || return 0
|
|
207
|
+
# Intentional word splitting: checkov takes the file list positionally
|
|
208
|
+
# after ONE --file, and each path here has already been through the
|
|
209
|
+
# adapter's own detection (no spaces in the glob patterns it produces).
|
|
210
|
+
# shellcheck disable=SC2086
|
|
211
|
+
"$checkov_bin" --file $batch $checkov_args $framework_arg >> "$checkov_log" 2>&1
|
|
212
|
+
local status=$?
|
|
213
|
+
record_checkov_run "$status" "$covered"
|
|
214
|
+
return 0
|
|
215
|
+
}
|
|
216
|
+
|
|
168
217
|
# Run checkov on all detected IaC files
|
|
169
218
|
local tf_files=$(echo "$iac_files" | grep "TERRAFORM:" | sed 's/TERRAFORM://')
|
|
170
219
|
local k8s_files=$(echo "$iac_files" | grep "KUBERNETES:" | sed 's/KUBERNETES://')
|
|
@@ -172,12 +221,8 @@ run_static_analysis() {
|
|
|
172
221
|
|
|
173
222
|
if [ -n "$tf_files" ]; then
|
|
174
223
|
echo "Scanning Terraform files..."
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
"$checkov_bin" --file "$file" $checkov_args >> "$checkov_log" 2>&1
|
|
178
|
-
record_checkov_run $? "$file"
|
|
179
|
-
fi
|
|
180
|
-
done
|
|
224
|
+
# shellcheck disable=SC2086
|
|
225
|
+
scan_checkov_batch "" $tf_files
|
|
181
226
|
fi
|
|
182
227
|
|
|
183
228
|
if [ -n "$k8s_files" ]; then
|
|
@@ -193,33 +238,21 @@ run_static_analysis() {
|
|
|
193
238
|
|
|
194
239
|
if [ -n "$k8s_only" ]; then
|
|
195
240
|
echo "Scanning Kubernetes manifests..."
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
"$checkov_bin" --file "$file" $checkov_args --framework kubernetes >> "$checkov_log" 2>&1
|
|
199
|
-
record_checkov_run $? "$file"
|
|
200
|
-
fi
|
|
201
|
-
done
|
|
241
|
+
# shellcheck disable=SC2086
|
|
242
|
+
scan_checkov_batch "--framework kubernetes" $k8s_only
|
|
202
243
|
fi
|
|
203
244
|
|
|
204
245
|
if [ -n "$gh_files" ]; then
|
|
205
246
|
echo "Scanning GitHub Actions workflows..."
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
"$checkov_bin" --file "$file" $checkov_args --framework github_actions >> "$checkov_log" 2>&1
|
|
209
|
-
record_checkov_run $? "$file"
|
|
210
|
-
fi
|
|
211
|
-
done
|
|
247
|
+
# shellcheck disable=SC2086
|
|
248
|
+
scan_checkov_batch "--framework github_actions" $gh_files
|
|
212
249
|
fi
|
|
213
250
|
fi
|
|
214
251
|
|
|
215
252
|
if [ -n "$docker_files" ]; then
|
|
216
253
|
echo "Scanning Dockerfiles..."
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
"$checkov_bin" --file "$file" $checkov_args >> "$checkov_log" 2>&1
|
|
220
|
-
record_checkov_run $? "$file"
|
|
221
|
-
fi
|
|
222
|
-
done
|
|
254
|
+
# shellcheck disable=SC2086
|
|
255
|
+
scan_checkov_batch "" $docker_files
|
|
223
256
|
fi
|
|
224
257
|
|
|
225
258
|
# Print captured output then check for failures
|
package/adapters/shell.sh
CHANGED
|
@@ -88,8 +88,56 @@ run_static_analysis() {
|
|
|
88
88
|
echo "Running Shell static analysis on ${#files[@]} script(s)..."
|
|
89
89
|
# Each path is passed as its own argument (Bash 3.2 compatible: no mapfile),
|
|
90
90
|
# so a path containing spaces cannot be split into two bogus arguments.
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
#
|
|
92
|
+
# The verdict is TIERED, because a flat exit status made every finding block
|
|
93
|
+
# equally. Measured on this repository: 2 error-level, 74 warning-level, 150
|
|
94
|
+
# info-level and 182 style-level findings. An unused-variable warning and an
|
|
95
|
+
# unparseable script are not the same problem, and treating them the same is
|
|
96
|
+
# how a gate ends up switched off or routed around.
|
|
97
|
+
#
|
|
98
|
+
# error level (which includes every parse failure) -> BLOCK
|
|
99
|
+
# warning / note / style -> reported, not blocking
|
|
100
|
+
#
|
|
101
|
+
# The tier is read from the LEVEL, not from the code range. SC1xxx was tried
|
|
102
|
+
# first and is wrong: this repository's four SC1xxx findings are all SC1003
|
|
103
|
+
# ("want to escape a single quote?") at NOTE level, so a code-range test would
|
|
104
|
+
# have blocked on a suggestion. A real parse failure (SC1073/SC1123/SC1072)
|
|
105
|
+
# always arrives at error level anyway, so keying on the level covers it.
|
|
106
|
+
#
|
|
107
|
+
# The output is captured so the class can be read before deciding, and is
|
|
108
|
+
# re-printed either way: a tier that does not block must still be VISIBLE, or
|
|
109
|
+
# it is indistinguishable from a tier that does not exist.
|
|
110
|
+
local out=""
|
|
111
|
+
out="$(shellcheck -f gcc "${files[@]}" 2>&1)"
|
|
112
|
+
local status=$?
|
|
113
|
+
|
|
114
|
+
# Print the analyser's own output on BOTH paths. Real shellcheck prints nothing
|
|
115
|
+
# when it is clean, so this costs nothing there; but it keeps whatever the tool
|
|
116
|
+
# did say (a version banner, a notice, a wrapper's narration) visible instead of
|
|
117
|
+
# silently swallowed by the capture. Dropping it on the success path made the
|
|
118
|
+
# adapter look like it had not invoked anything at all.
|
|
119
|
+
[ -n "$out" ] && printf '%s\n' "$out"
|
|
120
|
+
|
|
121
|
+
[ "$status" -eq 0 ] && return 0
|
|
122
|
+
|
|
123
|
+
# Error level: real defects, and the level every parse failure lands on. The
|
|
124
|
+
# message names the parse case separately because "the file was not analysed"
|
|
125
|
+
# and "the file was analysed and has a defect" need different responses.
|
|
126
|
+
if printf '%s\n' "$out" | grep -qE ': error: '; then
|
|
127
|
+
if printf '%s\n' "$out" | grep -qE '\[SC(1072|1073|1123|1009)\]'; then
|
|
128
|
+
echo "❌ Shell analysis could not PARSE the file(s) -- they were not fully checked." >&2
|
|
129
|
+
echo " Fix the parse failure first: no other shell verdict about them is trustworthy." >&2
|
|
130
|
+
else
|
|
131
|
+
echo "❌ Shell errors found (blocking)." >&2
|
|
132
|
+
fi
|
|
133
|
+
return 1
|
|
134
|
+
fi
|
|
135
|
+
|
|
136
|
+
# Warnings and below: reported above, not blocking.
|
|
137
|
+
local soft
|
|
138
|
+
soft="$(printf '%s\n' "$out" | grep -cE ': (warning|note): ' || true)"
|
|
139
|
+
echo "⚠️ ${soft:-0} shell warning(s)/note(s) reported above (not blocking)."
|
|
140
|
+
return 0
|
|
93
141
|
}
|
|
94
142
|
|
|
95
143
|
run_lint() {
|
|
@@ -605,6 +605,36 @@ async function packPrecondition(projectRoot: string): Promise<string | null> {
|
|
|
605
605
|
if (!pkgJson.files || !Array.isArray(pkgJson.files)) {
|
|
606
606
|
return 'package.json has no files field — skipping pack check';
|
|
607
607
|
}
|
|
608
|
+
// #786: a `files` allowlist that names an output directory (`dist`, `lib`,
|
|
609
|
+
// `build`) describes an artifact a BUILD produces, not something already in the
|
|
610
|
+
// tree. With `noEmit` in tsconfig -- a normal choice when a bundler or a
|
|
611
|
+
// separate build step owns the output -- nothing writes that directory, so
|
|
612
|
+
// `npm pack` ships only package.json, `inspectPackedFiles` reports "only
|
|
613
|
+
// package.json included", and the gate BLOCKS forever with no way out.
|
|
614
|
+
//
|
|
615
|
+
// Absent artifacts are therefore a SKIP with the reason spelled out, not a
|
|
616
|
+
// FAIL. This gate's subject is build integrity, and it cannot judge a package
|
|
617
|
+
// whose inputs were never built. The message also has to name the remedy --
|
|
618
|
+
// "build first" is the whole fix, and the old text never said it.
|
|
619
|
+
const declaredEntries = (pkgJson.files as unknown[]).filter(
|
|
620
|
+
(entry): entry is string =>
|
|
621
|
+
typeof entry === 'string' && entry !== '' && !entry.startsWith('!') && !entry.includes('*')
|
|
622
|
+
);
|
|
623
|
+
if (declaredEntries.length > 0) {
|
|
624
|
+
const presence = await Promise.all(
|
|
625
|
+
declaredEntries.map(async (entry) => {
|
|
626
|
+
try {
|
|
627
|
+
await fs.access(path.join(projectRoot, entry));
|
|
628
|
+
return true;
|
|
629
|
+
} catch {
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
})
|
|
633
|
+
);
|
|
634
|
+
if (!presence.some(Boolean)) {
|
|
635
|
+
return `package.json files entries (${declaredEntries.join(', ')}) do not exist on disk — run the build that produces them, then re-run`;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
608
638
|
return null;
|
|
609
639
|
}
|
|
610
640
|
|
|
@@ -760,13 +790,24 @@ export function parseGate10Args(args: string[]): Gate10Args {
|
|
|
760
790
|
|
|
761
791
|
for (let i = 0; i < args.length; i++) {
|
|
762
792
|
const arg = args[i];
|
|
793
|
+
// `else if` chains count as nesting depth, which put this function one over
|
|
794
|
+
// the limit (5 > 4) and blocked every commit that touched this file until it
|
|
795
|
+
// cleared -- the rule for files at ≤5 warnings is "clear to zero", not "do
|
|
796
|
+
// not increase". Each branch is independent, so `continue` states that
|
|
797
|
+
// directly and keeps the depth at 2.
|
|
763
798
|
if (arg === '--help' || arg === '-h') {
|
|
764
799
|
help = true;
|
|
765
|
-
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
if (arg === '--changed-files') {
|
|
766
803
|
changedFilesStr = args[++i] || '';
|
|
767
|
-
|
|
804
|
+
continue;
|
|
805
|
+
}
|
|
806
|
+
if (arg === '--project-root') {
|
|
768
807
|
projectRoot = args[++i] || process.cwd();
|
|
769
|
-
|
|
808
|
+
continue;
|
|
809
|
+
}
|
|
810
|
+
if (arg === '--timeout') {
|
|
770
811
|
timeoutMs = parseInt(args[++i] || '60000', 10);
|
|
771
812
|
}
|
|
772
813
|
}
|