@boyingliu01/xp-gate 0.39.3 → 0.40.0
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-12-file-hygiene.sh +103 -15
- package/adapters/gate-6-layers.sh +158 -16
- package/gate-12-file-hygiene.sh +103 -15
- package/gate-6-layers.sh +158 -16
- package/hooks/gate-12-file-hygiene.sh +103 -15
- package/hooks/gate-6-layers.sh +158 -16
- package/hooks/gate-entries/gate-5-entry.sh +52 -2
- package/hooks/gate-entries/gate-6-entry.sh +86 -3
- package/hooks/lib/gate-12-blob-scan.awk +42 -2
- package/hooks/pre-commit +46 -2
- package/lib/gate-runner.js +52 -13
- package/mutation/init-baseline.ts +82 -26
- package/mutation/runners/mutmut-runner.ts +110 -26
- 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/scripts/prepack.cjs +39 -14
- 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/principles/adapters/function-body.ts +60 -0
- package/principles/adapters/typescript.ts +54 -4
- package/principles/config.ts +16 -3
- package/scripts/delphi-repo-tools.cjs +4 -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/hooks/gate-6-layers.sh
CHANGED
|
@@ -43,17 +43,24 @@ set -uo pipefail
|
|
|
43
43
|
LAYER_CONFIG="${XP_GATE_LAYER_CONFIG:-architecture.yaml}"
|
|
44
44
|
LAYER_BASELINE="${XP_GATE_LAYER_BASELINE:-.layer-baseline.json}"
|
|
45
45
|
LAYER_SCAN_ROOT="${XP_GATE_LAYER_SCAN_ROOT:-.}"
|
|
46
|
-
LAYER_REASON=""
|
|
47
46
|
|
|
48
47
|
# ─── Output helpers ─────────────────────────────────────────────────────────
|
|
49
48
|
_layers_say() { echo " $*"; }
|
|
50
49
|
|
|
51
|
-
_layers_verdict() {
|
|
50
|
+
function _layers_verdict() {
|
|
52
51
|
local code="$1" text="$2" reason="${3:-}"
|
|
53
|
-
|
|
52
|
+
# An empty text is deliberate on the blocking path: the violation lines were
|
|
53
|
+
# already printed, and this call exists only to attach the reason and the exit
|
|
54
|
+
# code. Printing the empty string would emit a blank indented line.
|
|
55
|
+
[ -n "$text" ] && _layers_say "$text"
|
|
56
|
+
# The reason reaches the gate entry through the printed line, not through a
|
|
57
|
+
# variable: this script runs as a child process, so nothing it assigns can be
|
|
58
|
+
# read by the caller. Storing it in LAYER_REASON as well made it a write-only
|
|
59
|
+
# global -- shellcheck SC2034, which this repository treats as a real defect
|
|
60
|
+
# rather than noise (the same signal that exposed GATE_6_LAYER_STATUS being
|
|
61
|
+
# assigned six times and read zero).
|
|
54
62
|
if [ -n "$reason" ]; then
|
|
55
63
|
_layers_say " reason: $reason"
|
|
56
|
-
LAYER_REASON="$reason"
|
|
57
64
|
fi
|
|
58
65
|
exit "$code"
|
|
59
66
|
}
|
|
@@ -71,7 +78,37 @@ fi
|
|
|
71
78
|
LAYER_TSV=$(awk '
|
|
72
79
|
function trim(s) { gsub(/^[ \t]+|[ \t]+$/, "", s); return s }
|
|
73
80
|
function unq(s) { s = trim(s); gsub(/^["\047]|["\047]$/, "", s); return s }
|
|
74
|
-
#
|
|
81
|
+
# #785: a YAML list has TWO spellings and this parser only understood one.
|
|
82
|
+
# allowedImports: [shared] # flow -- on the same line as the key
|
|
83
|
+
# allowedImports: # block -- items on the FOLLOWING lines
|
|
84
|
+
# - shared
|
|
85
|
+
# The block form parsed to an EMPTY string, i.e. an allow-list that permits
|
|
86
|
+
# nothing, so a repository using the standard spelling had every legal import
|
|
87
|
+
# reported as a violation. That direction is the expensive one: a gate that
|
|
88
|
+
# accuses compliant code gets baselined, and a baselined gate stops being read.
|
|
89
|
+
#
|
|
90
|
+
# `listkey` records which list a bare `- item` sequence belongs to. It is reset
|
|
91
|
+
# by any other key, so an item can never attach to the wrong list.
|
|
92
|
+
#
|
|
93
|
+
# list_value() takes the inline part (flow, or a one-line scalar) and records
|
|
94
|
+
# the key so that a following block sequence can be appended. It returns the
|
|
95
|
+
# same comma-joined form clean() produces, so downstream code is unchanged.
|
|
96
|
+
function list_value(which, rest, v) {
|
|
97
|
+
v = clean(rest)
|
|
98
|
+
listkey = (v == "" ? which : "")
|
|
99
|
+
return v
|
|
100
|
+
}
|
|
101
|
+
# Append one `- item` line to the list named by listkey.
|
|
102
|
+
function append_item(which, line, item, cur) {
|
|
103
|
+
item = unq(trim(substr(trim(line), 2)))
|
|
104
|
+
if (item == "") return
|
|
105
|
+
cur = (which == "pattern") ? pattern : (which == "allowed") ? allowed : forbidden
|
|
106
|
+
cur = (cur == "" ? item : cur "," item)
|
|
107
|
+
if (which == "pattern") pattern = cur
|
|
108
|
+
else if (which == "allowed") allowed = cur
|
|
109
|
+
else forbidden = cur
|
|
110
|
+
}
|
|
111
|
+
# Split a YAML flow list into a comma-joined string of unquoted items.
|
|
75
112
|
function clean(v, k,i,p,out) {
|
|
76
113
|
v = trim(v); sub(/#.*$/, "", v); v = trim(v)
|
|
77
114
|
sub(/^\[/, "", v); sub(/\]$/, "", v)
|
|
@@ -104,6 +141,7 @@ LAYER_TSV=$(awk '
|
|
|
104
141
|
BEGIN {
|
|
105
142
|
inlayers = 0; layerindent = -1
|
|
106
143
|
name = ""; pattern = ""; allowed = ""; forbidden = ""
|
|
144
|
+
listkey = ""
|
|
107
145
|
}
|
|
108
146
|
/^[ \t]*#/ { next }
|
|
109
147
|
/^[ \t]*$/ { next }
|
|
@@ -120,6 +158,7 @@ LAYER_TSV=$(awk '
|
|
|
120
158
|
if (indent == layerindent && body ~ /^[A-Za-z0-9_-]+:[ \t]*$/) {
|
|
121
159
|
flush()
|
|
122
160
|
name = substr(body, 1, index(body, ":") - 1)
|
|
161
|
+
listkey = ""
|
|
123
162
|
next
|
|
124
163
|
}
|
|
125
164
|
if (indent == layerindent && body ~ /^- /) { next }
|
|
@@ -131,9 +170,26 @@ LAYER_TSV=$(awk '
|
|
|
131
170
|
# naturally. Accepting only one of the two made a correct config parse to an
|
|
132
171
|
# empty pattern list, which then matched no file and reported "0 violations"
|
|
133
172
|
# — the silent-pass shape this gate exists to remove.
|
|
134
|
-
else if (body ~ /^patterns?:/) { pattern =
|
|
135
|
-
else if (body ~ /^allowedImports:/ || body ~ /^allowed_imports:/) { allowed =
|
|
136
|
-
else if (body ~ /^forbiddenImports:/ || body ~ /^forbidden_imports:/) { forbidden =
|
|
173
|
+
else if (body ~ /^patterns?:/) { pattern = list_value("pattern", substr(body, index(body, ":") + 1)) }
|
|
174
|
+
else if (body ~ /^allowedImports:/ || body ~ /^allowed_imports:/) { allowed = list_value("allowed", substr(body, index(body, ":") + 1)) }
|
|
175
|
+
else if (body ~ /^forbiddenImports:/ || body ~ /^forbidden_imports:/) { forbidden = list_value("forbidden", substr(body, index(body, ":") + 1)) }
|
|
176
|
+
else if (listkey != "" && body ~ /^- /) { append_item(listkey, body) }
|
|
177
|
+
# #785 follow-up (Delphi round 1, two experts independently): ANY other line
|
|
178
|
+
# ends the block sequence. Without this, an unrecognised key -- `notes:`,
|
|
179
|
+
# `description:`, a field added later -- left `listkey` pointing at the list
|
|
180
|
+
# above, and the items under that key were appended to it.
|
|
181
|
+
#
|
|
182
|
+
# Measured 2026-08-30 before the fix: `allowedImports:` block list followed by
|
|
183
|
+
# `notes:` + `- shared` silently added `shared` to the allow-list. Silent in
|
|
184
|
+
# that direction, and a DENIAL in the other, which is the worse half: a
|
|
185
|
+
# comment holding in a block list could deny an import that nobody forbade.
|
|
186
|
+
#
|
|
187
|
+
# Reset rather than "only when the line is not an item": an item belongs to
|
|
188
|
+
# the key that IMMEDIATELY precedes it, and a blank line or a comment between
|
|
189
|
+
# them ends the sequence in YAML too. (Blank and comment lines are skipped
|
|
190
|
+
# before this block, so they do not reset -- matching YAML, where they are
|
|
191
|
+
# not significant.)
|
|
192
|
+
else if (body ~ /^[A-Za-z0-9_-]+:/) { listkey = "" }
|
|
137
193
|
}
|
|
138
194
|
END { flush() }
|
|
139
195
|
' "$LAYER_CONFIG" 2>/dev/null)
|
|
@@ -194,6 +250,9 @@ LAYER_CLASSIFIED=0
|
|
|
194
250
|
# and a stdin-driven loop leaves FILENAME empty — every file would be assigned
|
|
195
251
|
# layer 0 and the scan would report a clean tree. That is exactly the failure
|
|
196
252
|
# mode this gate exists to prevent, so the plumbing has to be right first.
|
|
253
|
+
# shellcheck disable=SC2086 # $FILE_LIST MUST be word-split: awk builds FILENAME
|
|
254
|
+
# from ARGV, and one quoted argument would be treated as a single filename, which
|
|
255
|
+
# leaves every file unclassified (see the comment on FILENAME above).
|
|
197
256
|
FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk '
|
|
198
257
|
BEGIN {
|
|
199
258
|
n = 0
|
|
@@ -235,11 +294,76 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
235
294
|
}
|
|
236
295
|
return best
|
|
237
296
|
}
|
|
297
|
+
# #862: the same lookup for a RESOLVED IMPORT TARGET.
|
|
298
|
+
#
|
|
299
|
+
# resolve() strips the extension from a specifier, so `./router` arrives as
|
|
300
|
+
# `src/router` while a pattern that names a FILE keeps it (`src/router.js`).
|
|
301
|
+
# Matching only the literal form left every file-level boundary unenforced --
|
|
302
|
+
# and an unclassified target is not a violation, so the verdict was "0
|
|
303
|
+
# violations" over a real forbidden edge.
|
|
304
|
+
#
|
|
305
|
+
# A compiled pattern regex is therefore tried in both directions: as written,
|
|
306
|
+
# and against the extension-stripped target. Directory patterns
|
|
307
|
+
# (`src/lib/**`) end in a slash or a wildcard and match the first way, so they
|
|
308
|
+
# are unaffected.
|
|
309
|
+
function layer_of_target(tgt, best, k, j, cand, exts) {
|
|
310
|
+
best = layer_of(tgt)
|
|
311
|
+
if (best != 0) return best
|
|
312
|
+
# The target has NO extension (resolve() stripped it) while a FILE pattern
|
|
313
|
+
# keeps one -- so the candidate is the target WITH each possible extension,
|
|
314
|
+
# not the other way round. Getting this backwards looks equivalent and is
|
|
315
|
+
# not: there is nothing to strip from `src/router`.
|
|
316
|
+
if (tgt ~ /[.](ts|tsx|js|jsx|mjs|cjs)$/) return 0
|
|
317
|
+
exts = "ts tsx js jsx mjs cjs"
|
|
318
|
+
k = split(exts, E)
|
|
319
|
+
for (j = 1; j <= k; j++) {
|
|
320
|
+
cand = tgt "." E[j]
|
|
321
|
+
best = layer_of(cand)
|
|
322
|
+
if (best != 0) return best
|
|
323
|
+
}
|
|
324
|
+
return 0
|
|
325
|
+
}
|
|
238
326
|
function in_csv(list, val, k, j, p) {
|
|
239
327
|
k = split(list, p, ",")
|
|
240
328
|
for (j = 1; j <= k; j++) if (p[j] == val) return 1
|
|
241
329
|
return 0
|
|
242
330
|
}
|
|
331
|
+
# Does one list ENTRY describe this import? Two accepted forms, one answer.
|
|
332
|
+
#
|
|
333
|
+
# * a bare layer name -- matches the destination layer ("shared")
|
|
334
|
+
# * a path glob -- matched against the resolved target path
|
|
335
|
+
#
|
|
336
|
+
# #862: the resolved target has its EXTENSION STRIPPED (resolve() maps
|
|
337
|
+
# `./router` onto `src/router`), while a pattern naming a FILE keeps it
|
|
338
|
+
# (`src/router.js`). The two never compared equal, so a file-level boundary was
|
|
339
|
+
# never enforced -- and an unclassified target is not a violation, so the gate
|
|
340
|
+
# reported "0 violations" over a real forbidden edge. Directory patterns end in
|
|
341
|
+
# `/` or `/**` and were unaffected, which is why this survived: every example in
|
|
342
|
+
# the docs used a directory.
|
|
343
|
+
#
|
|
344
|
+
# Both spellings of the tail are tried, so a file pattern works whether the
|
|
345
|
+
# author wrote it with or without the extension.
|
|
346
|
+
function entry_matches(entry, tgt, dstname, stem) {
|
|
347
|
+
if (entry == dstname) return 1
|
|
348
|
+
if (entry ~ /[*]/) {
|
|
349
|
+
if (tgt ~ pat2re(entry)) return 1
|
|
350
|
+
stem = entry
|
|
351
|
+
if (sub(/[.](ts|tsx|js|jsx|mjs|cjs)$/, "", stem) && stem != entry) {
|
|
352
|
+
if (tgt ~ pat2re(stem)) return 1
|
|
353
|
+
}
|
|
354
|
+
return 0
|
|
355
|
+
}
|
|
356
|
+
if (tgt == entry || tgt ~ ("^" entry "/")) return 1
|
|
357
|
+
# A file pattern without a trailing slash: compare the extension-stripped
|
|
358
|
+
# target against the extension-stripped entry, and the target against the
|
|
359
|
+
# entry as written.
|
|
360
|
+
stem = entry
|
|
361
|
+
if (stem ~ /[.](ts|tsx|js|jsx|mjs|cjs)$/) {
|
|
362
|
+
sub(/[.](ts|tsx|js|jsx|mjs|cjs)$/, "", stem)
|
|
363
|
+
if (tgt == stem) return 1
|
|
364
|
+
}
|
|
365
|
+
return 0
|
|
366
|
+
}
|
|
243
367
|
# `allowedImports` is written as path globs in this config ("src/shared/**")
|
|
244
368
|
# but reads naturally as layer names ("domain"). Accept both: a path glob is
|
|
245
369
|
# matched against the resolved target path, a bare identifier against the
|
|
@@ -250,9 +374,7 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
250
374
|
k = split(lallow[idx], p, ",")
|
|
251
375
|
for (j = 1; j <= k; j++) {
|
|
252
376
|
if (p[j] == "") continue
|
|
253
|
-
if (p[j]
|
|
254
|
-
if (p[j] ~ /[*]/ && tgt ~ pat2re(p[j])) return 1
|
|
255
|
-
if (p[j] !~ /[*]/ && (tgt == p[j] || tgt ~ ("^" p[j] "/"))) return 1
|
|
377
|
+
if (entry_matches(p[j], tgt, dstname)) return 1
|
|
256
378
|
}
|
|
257
379
|
return 0
|
|
258
380
|
}
|
|
@@ -266,9 +388,7 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
266
388
|
k = split(lforb[idx], p, ",")
|
|
267
389
|
for (j = 1; j <= k; j++) {
|
|
268
390
|
if (p[j] == "") continue
|
|
269
|
-
if (p[j]
|
|
270
|
-
if (p[j] ~ /[*]/ && tgt ~ pat2re(p[j])) return 1
|
|
271
|
-
if (p[j] !~ /[*]/ && (tgt == p[j] || tgt ~ ("^" p[j] "/"))) return 1
|
|
391
|
+
if (entry_matches(p[j], tgt, dstname)) return 1
|
|
272
392
|
}
|
|
273
393
|
return 0
|
|
274
394
|
}
|
|
@@ -328,7 +448,11 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
328
448
|
if (src == 0 || spec == "") continue
|
|
329
449
|
tgt = resolve(file, spec)
|
|
330
450
|
if (tgt == "") continue
|
|
331
|
-
|
|
451
|
+
# #862: a FILE-level layer pattern keeps its extension while the resolved
|
|
452
|
+
# target does not, so membership is looked up through layer_of_target().
|
|
453
|
+
# An unclassified target is silently not a violation, which is how a real
|
|
454
|
+
# forbidden edge became "0 violations".
|
|
455
|
+
dst = layer_of_target(tgt)
|
|
332
456
|
if (dst == 0 || dst == src) continue
|
|
333
457
|
# Denial before grant: an explicit forbiddenImports entry is never
|
|
334
458
|
# cancelled by a broader allowedImports entry.
|
|
@@ -423,4 +547,22 @@ if [ "${FORBIDDEN_SEEN:-0}" -gt 0 ]; then
|
|
|
423
547
|
fi
|
|
424
548
|
_layers_say " A layer may import only what its allowedImports lists."
|
|
425
549
|
_layers_say " To accept an existing violation, record it in $LAYER_BASELINE."
|
|
426
|
-
exit 1
|
|
550
|
+
# #852: this block used a bare `exit 1`, so the exit-1 path was the ONE verdict
|
|
551
|
+
# that carried no `reason:` line. The gate entry recovers the reason by parsing
|
|
552
|
+
# `reason:` out of this output, so a real, measured layer BLOCK arrived at the
|
|
553
|
+
# report with an empty reason -- which then fell through to the
|
|
554
|
+
# "layers_config_not_enforced" placeholder and described the opposite situation
|
|
555
|
+
# (nothing measured, rather than a violation found).
|
|
556
|
+
#
|
|
557
|
+
# Going through _layers_verdict makes the reason structural: every exit code
|
|
558
|
+
# this script can produce now says why. A verdict without a reason is treated as
|
|
559
|
+
# a defect in this repository, and this was the last path that produced one.
|
|
560
|
+
#
|
|
561
|
+
# The edge kind is part of the reason because the two diagnoses differ: a
|
|
562
|
+
# forbidden edge must be removed, an unlisted one must be declared.
|
|
563
|
+
if [ "${FORBIDDEN_SEEN:-0}" -gt 0 ]; then
|
|
564
|
+
_layers_reason="layer_violation_forbidden_import"
|
|
565
|
+
else
|
|
566
|
+
_layers_reason="layer_violation_unlisted_import"
|
|
567
|
+
fi
|
|
568
|
+
_layers_verdict 1 "" "$_layers_reason"
|
|
@@ -1124,10 +1124,26 @@ else
|
|
|
1124
1124
|
fi
|
|
1125
1125
|
fi
|
|
1126
1126
|
else
|
|
1127
|
-
|
|
1127
|
+
# #830: 'assuming none to run' is a GUESS made from a failure to load the
|
|
1128
|
+
# adapter, and it was printed with a ✅ PASSED badge. A missing adapter is
|
|
1129
|
+
# precisely the case where the project's tests are not being run -- the
|
|
1130
|
+
# moment the verdict matters most -- so the honest label is SKIPPED with a
|
|
1131
|
+
# reason.
|
|
1132
|
+
#
|
|
1133
|
+
# A DEDICATED flag, not TESTS_SKIPPED. TESTS_SKIPPED also suppresses the
|
|
1134
|
+
# whole coverage stage (#312/#760), so reusing it here made an adapter that
|
|
1135
|
+
# failed to LOAD erase a coverage measurement the project still had. The
|
|
1136
|
+
# requirement is narrow: this arm may not claim PASS. Whether coverage is
|
|
1137
|
+
# evaluated is decided by the coverage stage's own evidence rule.
|
|
1138
|
+
echo "⏭️ SKIPPED - Could not source ${CURRENT_LANG} adapter for tests; NO tests were run."
|
|
1139
|
+
TESTS_NOT_RUN=true
|
|
1140
|
+
xp_gate_detail_append GATE_5_DETAIL "tests_not_run: ${CURRENT_LANG} adapter could not be sourced"
|
|
1128
1141
|
fi
|
|
1129
1142
|
else
|
|
1130
|
-
|
|
1143
|
+
# #830: same shape as the branch above -- no adapter means no test run.
|
|
1144
|
+
echo "⏭️ SKIPPED - No ${CURRENT_LANG} adapter found for tests; NO tests were run."
|
|
1145
|
+
TESTS_NOT_RUN=true
|
|
1146
|
+
xp_gate_detail_append GATE_5_DETAIL "tests_not_run: no ${CURRENT_LANG} adapter installed"
|
|
1131
1147
|
fi
|
|
1132
1148
|
done # end for CURRENT_LANG
|
|
1133
1149
|
|
|
@@ -2222,6 +2238,40 @@ else
|
|
|
2222
2238
|
# here -- absence of a failure is not a pass" and the summary line one inch
|
|
2223
2239
|
# below still read "Gate 5: Tests + Coverage PASS (coverage: N/A%)". The
|
|
2224
2240
|
# summary is what a reader keeps and what the journal records.
|
|
2241
|
+
# #830: an arm that could not load or find an adapter ran NO tests. Left alone
|
|
2242
|
+
# it reached the epilogue's "empty status means PASS" default and became a
|
|
2243
|
+
# pass, which is the one thing the verdict contract forbids: the absence of a
|
|
2244
|
+
# measurement scored as a clean one.
|
|
2245
|
+
#
|
|
2246
|
+
# Applied BEFORE the chain rather than inside it, because the epilogue's
|
|
2247
|
+
# `elif [ -z "$GATE_5_STATUS" ]` adjacency is itself pinned by a test (the
|
|
2248
|
+
# #554 regression guard). Setting the status here leaves that shape untouched
|
|
2249
|
+
# and keeps the demotion visible at the point where the verdict is decided.
|
|
2250
|
+
if [ "${TESTS_NOT_RUN:-false}" = "true" ] && [ -z "${GATE_5_STATUS:-}" ]; then
|
|
2251
|
+
GATE_5_STATUS="SKIP"
|
|
2252
|
+
xp_gate_detail_append GATE_5_DETAIL "tests_not_run: no adapter executed for this change set"
|
|
2253
|
+
fi
|
|
2254
|
+
# #800: TESTS_SKIPPED was consumed ONLY by the coverage stage, so an adapter
|
|
2255
|
+
# that declined to run (no test runner installed) still let the epilogue's
|
|
2256
|
+
# "empty status means PASS" default record a PASS. Measured 2026-11-29 on a
|
|
2257
|
+
# repo with no vitest:
|
|
2258
|
+
#
|
|
2259
|
+
# SKIP - No test runner installed locally (node_modules/.bin has no vitest or jest)
|
|
2260
|
+
# Gate 5: Tests + Coverage PASS (coverage: N/A%)
|
|
2261
|
+
#
|
|
2262
|
+
# The body printed the skip and the report said pass -- the verdict channel
|
|
2263
|
+
# dropped it. A skip is now carried into the gate's own status, with the
|
|
2264
|
+
# adapter's own sentence as the reason instead of a bare SKIP.
|
|
2265
|
+
#
|
|
2266
|
+
# Guarded on an EMPTY status so a language that really measured something
|
|
2267
|
+
# still speaks for the gate: this demotes the silent default, it does not
|
|
2268
|
+
# overwrite a verdict.
|
|
2269
|
+
if [ "${TESTS_SKIPPED:-false}" = "true" ] && [ "${TESTS_RAN_ANY:-false}" != "true" ] \
|
|
2270
|
+
&& [ -z "${GATE_5_STATUS:-}" ]; then
|
|
2271
|
+
GATE_5_STATUS="SKIP"
|
|
2272
|
+
xp_gate_detail_append GATE_5_DETAIL "tests_skipped: no test runner produced a result for this change set"
|
|
2273
|
+
fi
|
|
2274
|
+
|
|
2225
2275
|
if [ -n "${DELEGATED_LANGS:-}" ]; then
|
|
2226
2276
|
GATE_5_STATUS="SKIP"
|
|
2227
2277
|
# Pass ONLY the new fragment. This used to re-prepend the existing detail
|
|
@@ -24,6 +24,16 @@
|
|
|
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
|
+
# #852: reset the layer verdict channel. These are plain globals, not `local`,
|
|
28
|
+
# so a second invocation in the same shell inherits the first one's values --
|
|
29
|
+
# and the reason extraction below is a default (`${VAR:-...}`), which keeps a
|
|
30
|
+
# stale value instead of reading the fresh checker output. Every BATS case that
|
|
31
|
+
# reuses a fixture and any retry in the hook itself would report the previous
|
|
32
|
+
# run's reason. Clearing at entry makes each call's verdict its own.
|
|
33
|
+
GATE_6_LAYER_STATUS=""
|
|
34
|
+
GATE_6_LAYER_REASON=""
|
|
35
|
+
GATE_6_LAYER_CRASHED=0
|
|
36
|
+
GATE_6_LAYERS_WARNED=0
|
|
27
37
|
# Shared verdict rules: strongest verdict wins, details append.
|
|
28
38
|
_GATE_STATUS_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" && pwd)/gate-status.sh"
|
|
29
39
|
if [ -r "$_GATE_STATUS_LIB" ]; then
|
|
@@ -200,7 +210,18 @@ else
|
|
|
200
210
|
GATE_6_LAYER_CRASHED=1
|
|
201
211
|
;;
|
|
202
212
|
esac
|
|
203
|
-
|
|
213
|
+
# #852: capture the checker's OWN reason before falling back. The
|
|
214
|
+
# `${VAR:-...}` form below is a default, not an assignment -- it keeps
|
|
215
|
+
# whatever value the variable already held. gate_6_run() is a function and
|
|
216
|
+
# these are not `local`, so on the SECOND call in one shell (every BATS
|
|
217
|
+
# case that reuses the fixture, and the hook itself after any retry) the
|
|
218
|
+
# reason from the previous run won, and a fresh BLOCK was reported under
|
|
219
|
+
# the old reason. Clearing it first makes each call's reason its own.
|
|
220
|
+
_g6_reason_from_out=$(printf '%s\n' "$LAYER_OUT" | sed -n 's/^ *reason: *//p' | head -1)
|
|
221
|
+
if [ -n "$_g6_reason_from_out" ]; then
|
|
222
|
+
GATE_6_LAYER_REASON="$_g6_reason_from_out"
|
|
223
|
+
fi
|
|
224
|
+
unset _g6_reason_from_out
|
|
204
225
|
else
|
|
205
226
|
# The checker is missing, so the dimension is unmeasured — say so rather
|
|
206
227
|
# than letting the gate look like it covered layers.
|
|
@@ -621,6 +642,25 @@ CSARCHPROJ
|
|
|
621
642
|
fi
|
|
622
643
|
done
|
|
623
644
|
fi
|
|
645
|
+
# #852: GATE_6_LAYERS_UNCHECKED means "archlint's generic pass measured no
|
|
646
|
+
# layers", which is true whenever a config exists. It is NOT a statement
|
|
647
|
+
# about whether OUR checker measured them -- and the stamp above lands
|
|
648
|
+
# before this point, so a real, measured layer BLOCK was recorded as
|
|
649
|
+
# "layers_config_not_enforced" (reason) while the status was FAIL. The
|
|
650
|
+
# person reading the report then saw "unmeasured config" for a violation
|
|
651
|
+
# that had just been detected and printed.
|
|
652
|
+
#
|
|
653
|
+
# The checker's own reason wins whenever there is one. Only the languages
|
|
654
|
+
# still carrying the placeholder are rewritten; a more specific reason set
|
|
655
|
+
# by a language arm (tool missing, tests failed) is left alone, which is the
|
|
656
|
+
# same `-z` rule the block above uses.
|
|
657
|
+
if [ -n "${GATE_6_LAYER_REASON:-}" ] && [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
|
|
658
|
+
for _g6_lang in $PROJECT_LANGS; do
|
|
659
|
+
if [ "${GATE_6_REASON_BY_LANG[$_g6_lang]:-}" = "layers_config_not_enforced" ]; then
|
|
660
|
+
GATE_6_REASON_BY_LANG["$_g6_lang"]="$GATE_6_LAYER_REASON"
|
|
661
|
+
fi
|
|
662
|
+
done
|
|
663
|
+
fi
|
|
624
664
|
for _g6_lang in $PROJECT_LANGS; do
|
|
625
665
|
_g6_r=""
|
|
626
666
|
if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
|
|
@@ -751,7 +791,12 @@ else
|
|
|
751
791
|
# real source path stays unbudgeted. Exclude it and let the mirroring be
|
|
752
792
|
# governed by Mirror Parity in CI, which compares content rather than
|
|
753
793
|
# re-linting it. (See the same exclusion in adapters/powershell.sh.)
|
|
754
|
-
|
|
794
|
+
# The mutation corpus is DEFECT DATA, not product code: every fixture under
|
|
795
|
+
# tests/meta-gate/corpus/ carries the violation a gate is being asked to catch.
|
|
796
|
+
# Boy Scout requires zero warnings from new files, which those files cannot
|
|
797
|
+
# satisfy by construction -- a corpus with none would test nothing. Excluded here
|
|
798
|
+
# as well as in the CI workflow so the two surfaces agree about the population.
|
|
799
|
+
MIRROR_EXCLUDE="${MIRROR_PATH_FILTER}|^tests/meta-gate/corpus/"
|
|
755
800
|
# filter_project_paths also removes dependencies and build output (#649):
|
|
756
801
|
# a staged node_modules/ or dist/ file is not budgetable project code, and
|
|
757
802
|
# entering it in the Boy Scout baseline would budget a path nobody edits.
|
|
@@ -837,7 +882,45 @@ fi
|
|
|
837
882
|
record_gate_audit "gate-6" "architecture-boy-scout" "$GATE_6_STATUS" "${BS_BLOCKED:-0}" "$GATE_6_START" "${GATE_6_DETAIL:-${GATE_6_REASON:-}}"
|
|
838
883
|
|
|
839
884
|
# ============================================================================
|
|
840
|
-
|
|
885
|
+
# THE RETURN VALUE MUST AGREE WITH THE VERDICT (#852)
|
|
886
|
+
#
|
|
887
|
+
# This function used to end with an unconditional `return 0`. The driver blocks
|
|
888
|
+
# on the RETURN, not on GATE_6_STATUS, so every FAIL decided by an inner branch
|
|
889
|
+
# was recorded correctly and then discarded:
|
|
890
|
+
#
|
|
891
|
+
# measured 2026-11-29, forbiddenImports violation, XP_GATE_ONLY_GATE=6
|
|
892
|
+
# stdout : ❌ BLOCKED - 1 new layer violation(s) (of 1 total)
|
|
893
|
+
# report : Gate 6: Architecture + Boy Scout FAIL
|
|
894
|
+
# rc : 0 <- the commit was CREATED
|
|
895
|
+
#
|
|
896
|
+
# The layer case is the one that reached the journal in a reportable shape, but
|
|
897
|
+
# the bug is not specific to layers: any `GATE_6_STATUS="FAIL"` set by any arm
|
|
898
|
+
# was overridden by this single line. Deriving the return from the status is the
|
|
899
|
+
# only form that cannot be bypassed by adding a new arm.
|
|
900
|
+
#
|
|
901
|
+
# WARN and SKIP still return 0 -- they are not blocks, and returning non-zero
|
|
902
|
+
# would stop the chain for a gate that merely declined to measure something.
|
|
903
|
+
# The mapping lives here, once, instead of being restated per arm.
|
|
904
|
+
# The blocking states are ENUMERATED. Delphi round-1 (two experts) flagged that
|
|
905
|
+
# `*) return 0` made every FUTURE status non-blocking by default: a new status
|
|
906
|
+
# that should block, or a typo in an existing assignment, would silently reopen
|
|
907
|
+
# the fail-open this change closed. Enumerating means adding a status cannot pass
|
|
908
|
+
# silently -- the unrecognised arm below BLOCKS instead of assuming safety.
|
|
909
|
+
case "$GATE_6_STATUS" in
|
|
910
|
+
FAIL) return 1 ;;
|
|
911
|
+
PASS|WARN|SKIP) return 0 ;;
|
|
912
|
+
# FAIL CLOSED. Two of three seats in Delphi payload-A round 5 argued this
|
|
913
|
+
# independently, and they were right: the four statuses this file can produce are
|
|
914
|
+
# enumerated above, so an unrecognised value means the verdict channel and the
|
|
915
|
+
# mapping have DIVERGED. Waving that through with a warning restores the very
|
|
916
|
+
# fail-open #852 closed, for every status somebody adds later.
|
|
917
|
+
#
|
|
918
|
+
# The warning that returned 0 was the dangerous shape: it reads as diligence and
|
|
919
|
+
# behaves as a pass.
|
|
920
|
+
*) echo " ❌ [BLOCK:UNRECOGNISED_STATUS] Gate 6 produced status '${GATE_6_STATUS}' — not a known verdict."
|
|
921
|
+
echo " The gate and its status mapping have diverged; refusing to score this run as clean."
|
|
922
|
+
return 1 ;;
|
|
923
|
+
esac
|
|
841
924
|
}
|
|
842
925
|
|
|
843
926
|
|
|
@@ -44,14 +44,51 @@
|
|
|
44
44
|
# its last visible character and was flagged every single time.)
|
|
45
45
|
#
|
|
46
46
|
# Binary files are filtered out before this runs, so no body line contains a
|
|
47
|
-
# NUL
|
|
48
|
-
#
|
|
47
|
+
# NUL. That is the precondition for the binary filter; do not remove it.
|
|
48
|
+
#
|
|
49
|
+
# BYTES, NOT CHARACTERS (#863). The arithmetic subtracts from a size git
|
|
50
|
+
# reports in BYTES, so the per-line count must be bytes too. `length($0)` is
|
|
51
|
+
# bytes only in a single-byte locale: under C.UTF-8 gawk returns the CHARACTER
|
|
52
|
+
# count, so every non-ASCII line came up short and the file was reported as
|
|
53
|
+
# missing a final newline that was demonstrably there. Measured 2026-11-29 on a
|
|
54
|
+
# file whose last byte is 0a:
|
|
55
|
+
#
|
|
56
|
+
# LC_ALL=C.UTF-8 ... | awk -f gate-12-blob-scan.awk -> NOEOF: doc.md
|
|
57
|
+
# LC_ALL=C ... | awk -f gate-12-blob-scan.awk -> (nothing)
|
|
58
|
+
#
|
|
59
|
+
# Two verdicts for one input, decided by an environment variable.
|
|
60
|
+
#
|
|
61
|
+
# The fix lives in the CALLER (gate-12-file-hygiene.sh): the scanner is now
|
|
62
|
+
# always invoked with LC_ALL=C, so `length()` is bytes on every awk. That is
|
|
63
|
+
# the standard's own mitigation and it is portable across gawk / mawk /
|
|
64
|
+
# busybox -- a per-character UTF-8 width table was tried first and does not
|
|
65
|
+
# work: gawk offers no way to read a character's code point (sprintf("%d", c)
|
|
66
|
+
# yields 0), so the fallback path silently measured characters anyway.
|
|
67
|
+
#
|
|
68
|
+
# This comment stays because the invariant it states is what the caller must
|
|
69
|
+
# uphold: ANY future call site has to run this program under a byte locale.
|
|
49
70
|
# ============================================================================
|
|
50
71
|
|
|
72
|
+
# Refuse to run in a character-oriented locale rather than produce a wrong
|
|
73
|
+
# verdict. Detecting it here means a call site that forgets LC_ALL=C fails
|
|
74
|
+
# loudly instead of reporting phantom NOEOF lines on every non-ASCII file.
|
|
51
75
|
BEGIN {
|
|
52
76
|
nu = split(paths, U, "|")
|
|
53
77
|
ui = 1
|
|
54
78
|
ws = ""; noeof = ""; conf = ""
|
|
79
|
+
|
|
80
|
+
_PROBE = "\344\270\255"
|
|
81
|
+
if (length(_PROBE) != 3) {
|
|
82
|
+
printf "gate-12-blob-scan: awk is counting CHARACTERS, not bytes (locale %s).\n", ENVIRON["LC_ALL"]
|
|
83
|
+
print " This scanner compares against byte sizes from git; under a UTF-8 locale"
|
|
84
|
+
print " every non-ASCII file would be reported as missing its final newline."
|
|
85
|
+
print " Invoke it as: LC_ALL=C awk -f gate-12-blob-scan.awk"
|
|
86
|
+
print ""
|
|
87
|
+
# `exit` still runs the END block, which would print the three empty tags and
|
|
88
|
+
# look like a clean result. Guard the END block instead of relying on exit.
|
|
89
|
+
_REFUSED = 1
|
|
90
|
+
exit 3
|
|
91
|
+
}
|
|
55
92
|
}
|
|
56
93
|
|
|
57
94
|
# A lookup that failed is reported as "<name> missing" -- never a size line.
|
|
@@ -95,5 +132,8 @@ BEGIN {
|
|
|
95
132
|
}
|
|
96
133
|
|
|
97
134
|
END {
|
|
135
|
+
# A refused run prints nothing: emitting "WS:\nNOEOF:\nCONFLICT:" would read
|
|
136
|
+
# as a clean scan, which is the failure shape the refusal exists to prevent.
|
|
137
|
+
if (_REFUSED) exit 3
|
|
98
138
|
printf "WS:%s\nNOEOF:%s\nCONFLICT:%s\n", ws, noeof, conf
|
|
99
139
|
}
|
package/hooks/pre-commit
CHANGED
|
@@ -457,6 +457,38 @@ fi
|
|
|
457
457
|
# Ensure pipe failures propagate exit codes through | head/tail/grep
|
|
458
458
|
set -o pipefail
|
|
459
459
|
|
|
460
|
+
# #870: STOP GIT FROM C-ESCAPING NON-ASCII PATHS.
|
|
461
|
+
#
|
|
462
|
+
# `git diff --cached --name-only` applies core.quotePath=true by default, so
|
|
463
|
+
# 中文.js comes out as "\344\270\255\346\226\207.js" -- a quoted, escaped
|
|
464
|
+
# string rather than a path. Forty call sites in this chain feed that output to
|
|
465
|
+
# things that treat it as filenames, and the consequences compound:
|
|
466
|
+
#
|
|
467
|
+
# * the named file is never read, because the path does not exist;
|
|
468
|
+
# * scanners that abort on unreadable input skip the WHOLE batch, so an
|
|
469
|
+
# ordinary neighbour committed at the same time is not scanned either;
|
|
470
|
+
# * Gate 2 reads the abort as a run error and reports "Duplicate code"
|
|
471
|
+
# SKIPPED. One Chinese filename switches a gate off for its neighbours.
|
|
472
|
+
#
|
|
473
|
+
# The alternative was to add --no-quote-path handling to forty call sites and
|
|
474
|
+
# then hope no future call site is added without it. Setting it once here covers
|
|
475
|
+
# every current gate and everything the chain grows later, which is the same
|
|
476
|
+
# reasoning that put MIRROR_PATH_FILTER in one place.
|
|
477
|
+
#
|
|
478
|
+
# Applied as a config override for THIS process tree only (exported
|
|
479
|
+
# GIT_CONFIG_PARAMETERS is what child git invocations inherit); the user's
|
|
480
|
+
# repository configuration is not modified.
|
|
481
|
+
if git rev-parse --git-dir >/dev/null 2>&1; then
|
|
482
|
+
_xp_qqp=$(git -c core.quotePath=false config --get core.quotePath 2>/dev/null || true)
|
|
483
|
+
# GIT_CONFIG_COUNT/KEY/VALUE is the modern, quoting-safe form and is inherited
|
|
484
|
+
# by child git processes, unlike `-c` which only affects this invocation.
|
|
485
|
+
export GIT_CONFIG_COUNT=$(( ${GIT_CONFIG_COUNT:-0} + 1 ))
|
|
486
|
+
export GIT_CONFIG_KEY_$(( GIT_CONFIG_COUNT - 1 ))="core.quotePath"
|
|
487
|
+
export GIT_CONFIG_VALUE_$(( GIT_CONFIG_COUNT - 1 ))="false"
|
|
488
|
+
export GIT_CONFIG_COUNT
|
|
489
|
+
unset _xp_qqp
|
|
490
|
+
fi
|
|
491
|
+
|
|
460
492
|
# ============================================================================
|
|
461
493
|
# Helper Functions
|
|
462
494
|
# ============================================================================
|
|
@@ -556,8 +588,20 @@ parse_lcov_coverage() {
|
|
|
556
588
|
done < "$lcov_file"
|
|
557
589
|
|
|
558
590
|
if [ "$total_lines" -gt 0 ]; then
|
|
559
|
-
#
|
|
560
|
-
|
|
591
|
+
# #831: emit an INTEGER. This function's only consumers compare with test(1)'s
|
|
592
|
+
# -ge / -lt, which are integer comparisons; `printf "%.1f"` produced "100.0"
|
|
593
|
+
# and "85.5", and both fail those tests. Because the calls suppress stderr
|
|
594
|
+
# (`2>/dev/null`), the failure was NOT reported -- it landed in the same
|
|
595
|
+
# branch as "no number at all", so a project with 100% coverage was told its
|
|
596
|
+
# coverage could not be determined and blocked.
|
|
597
|
+
#
|
|
598
|
+
# Formatting here rather than at every call site: there are four consumers
|
|
599
|
+
# and they must not be able to disagree about the unit. Truncation (not
|
|
600
|
+
# rounding) is deliberate -- it can only ever understate coverage, so this
|
|
601
|
+
# change cannot push a repo above the floor that the old code would have
|
|
602
|
+
# kept below it.
|
|
603
|
+
awk "BEGIN {printf \"%d\", int(($covered_lines / $total_lines) * 100)}" 2>/dev/null \
|
|
604
|
+
|| echo "0"
|
|
561
605
|
else
|
|
562
606
|
echo "0"
|
|
563
607
|
fi
|