@boyingliu01/xp-gate 0.38.30 → 0.38.33
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 +39 -3
- package/adapters/gate-4.sh +1 -1
- package/adapters/gate-6-layers.sh +57 -6
- package/adapters/php.sh +362 -0
- package/gate-3.sh +39 -3
- package/gate-4.sh +1 -1
- package/gate-6-layers.sh +57 -6
- package/hooks/gate-3.sh +39 -3
- package/hooks/gate-4.sh +1 -1
- package/hooks/gate-6-layers.sh +57 -6
- package/hooks/lib/layer-baseline.cjs +7 -1
- package/hooks/lib/typecheck.sh +49 -3
- package/lib/__tests__/language-capability.test.js +291 -0
- package/lib/__tests__/language-tools-detect.test.js +82 -0
- package/lib/language-capability-surfaces.js +315 -0
- package/lib/language-capability.js +474 -0
- package/lib/language-tools.js +107 -0
- package/lib/layer-baseline.cjs +7 -1
- package/lib/mattpocock-license-verdict.json +1 -1
- 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/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/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/php.ts +77 -0
- package/principles/analyzer.ts +6 -0
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
package/gate-6-layers.sh
CHANGED
|
@@ -202,7 +202,12 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
202
202
|
split(row, f, "\t")
|
|
203
203
|
if (f[1] == "") continue
|
|
204
204
|
n++
|
|
205
|
-
|
|
205
|
+
# f[4] is `forbiddenImports`. It was parsed but never loaded, so the
|
|
206
|
+
# field was dead config while reading as enforcement -- the #686 defect
|
|
207
|
+
# shape, inside the fix for #686. A declared-forbidden edge always loses,
|
|
208
|
+
# even when `allowedImports` also names it: an explicit denial must not be
|
|
209
|
+
# silently cancelled by a broader grant.
|
|
210
|
+
lname[n] = f[1]; lpat[n] = f[2]; lallow[n] = f[3]; lforb[n] = f[4]
|
|
206
211
|
# Patterns are compiled once here. layer_of() runs twice per source file
|
|
207
212
|
# (once for the importer, once per resolved target); recompiling there
|
|
208
213
|
# meant ~5800 regex builds for this repo and dominated the 2s scan.
|
|
@@ -251,6 +256,22 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
251
256
|
}
|
|
252
257
|
return 0
|
|
253
258
|
}
|
|
259
|
+
# `forbiddenImports` is the inverse of `allowedImports`, evaluated with the
|
|
260
|
+
# SAME two accepted forms (bare layer name or path glob) so a project cannot
|
|
261
|
+
# get enforcement by accident of spelling. It is checked BEFORE the allow
|
|
262
|
+
# list: an explicit denial wins over a broad grant. The alternative -- letting
|
|
263
|
+
# allowedImports cancel a forbiddenImports entry -- would make the stricter
|
|
264
|
+
# declaration the weaker one, which is the opposite of what a denial means.
|
|
265
|
+
function forbidden_hit(idx, tgt, dstname, k, j, p) {
|
|
266
|
+
k = split(lforb[idx], p, ",")
|
|
267
|
+
for (j = 1; j <= k; j++) {
|
|
268
|
+
if (p[j] == "") continue
|
|
269
|
+
if (p[j] == dstname) return 1
|
|
270
|
+
if (p[j] ~ /[*]/ && tgt ~ pat2re(p[j])) return 1
|
|
271
|
+
if (p[j] !~ /[*]/ && (tgt == p[j] || tgt ~ ("^" p[j] "/"))) return 1
|
|
272
|
+
}
|
|
273
|
+
return 0
|
|
274
|
+
}
|
|
254
275
|
# Resolve a relative specifier against the importing file.
|
|
255
276
|
function resolve(from, spec, np, i, dir, res, k, pp, trail, sx) {
|
|
256
277
|
sub(/[.](ts|tsx|js|jsx|mjs|cjs)$/, "", spec)
|
|
@@ -286,16 +307,35 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
286
307
|
# // in http:// inside string literals.
|
|
287
308
|
if (line ~ /^[ \t]*(\/\/|[#]|[*]|\/\*)/) next
|
|
288
309
|
rest = line
|
|
289
|
-
|
|
310
|
+
# Two specifier forms are scanned, alternating so both are found in one pass:
|
|
311
|
+
# ES/TS import ... from "x"
|
|
312
|
+
# CJS require("x") (single-quoted form is scanned too)
|
|
313
|
+
# The `require(` form was missing entirely, which left every .cjs file and its
|
|
314
|
+
# dependencies unscanned. This repo holds 28 of them, several importing from
|
|
315
|
+
# the generated mirror -- so the checker reported a clean tree while the very
|
|
316
|
+
# edge its own config forbids existed on disk. A scanner that reads one of the
|
|
317
|
+
# two import syntaxes is a scanner that can pass without looking.
|
|
318
|
+
while (match(rest, /from[ \t]+"[^"]+"|from[ \t]+\047[^\047]+\047|require\([ \t]*"[^"]+"[ \t]*\)|require\([ \t]*\047[^\047]+\047[ \t]*\)/)) {
|
|
290
319
|
spec = substr(rest, RSTART, RLENGTH)
|
|
291
|
-
sub(/^from[ \t]+["\047]/, "", spec)
|
|
292
|
-
sub(/["\047]$/, "", spec)
|
|
293
320
|
rest = substr(rest, RSTART + RLENGTH)
|
|
321
|
+
if (spec ~ /^from/) {
|
|
322
|
+
sub(/^from[ \t]+["\047]/, "", spec)
|
|
323
|
+
sub(/["\047]$/, "", spec)
|
|
324
|
+
} else {
|
|
325
|
+
sub(/^require\([ \t]*["\047]/, "", spec)
|
|
326
|
+
sub(/["\047][ \t]*\)$/, "", spec)
|
|
327
|
+
}
|
|
294
328
|
if (src == 0 || spec == "") continue
|
|
295
329
|
tgt = resolve(file, spec)
|
|
296
330
|
if (tgt == "") continue
|
|
297
331
|
dst = layer_of(tgt)
|
|
298
332
|
if (dst == 0 || dst == src) continue
|
|
333
|
+
# Denial before grant: an explicit forbiddenImports entry is never
|
|
334
|
+
# cancelled by a broader allowedImports entry.
|
|
335
|
+
if (forbidden_hit(src, tgt, lname[dst])) {
|
|
336
|
+
printf "%s\t%s\t%s\t%s\tforbidden\n", file, lname[src], lname[dst], tgt
|
|
337
|
+
continue
|
|
338
|
+
}
|
|
299
339
|
if (allowed_ok(src, tgt, lname[dst])) continue
|
|
300
340
|
printf "%s\t%s\t%s\t%s\n", file, lname[src], lname[dst], tgt
|
|
301
341
|
}
|
|
@@ -364,12 +404,23 @@ if [ "$NEW_COUNT" -eq 0 ]; then
|
|
|
364
404
|
fi
|
|
365
405
|
|
|
366
406
|
_layers_say "❌ BLOCKED - $NEW_COUNT new layer violation(s) (of $TOTAL total):"
|
|
367
|
-
|
|
368
|
-
|
|
407
|
+
# A forbidden edge and an unlisted edge are different diagnoses -- one says the
|
|
408
|
+
# import is explicitly denied, the other says nobody declared it -- and the fix
|
|
409
|
+
# differs (remove the import vs declare it). Name which one fired.
|
|
410
|
+
FORBIDDEN_SEEN=$(printf '%s\n' "$NEW_FINDINGS" | awk -F'\t' '$5=="forbidden"' | grep -c . || true)
|
|
411
|
+
printf '%s\n' "$NEW_FINDINGS" | head -10 | while IFS="$(printf '\t')" read -r f s d t why; do
|
|
412
|
+
if [ "$why" = "forbidden" ]; then
|
|
413
|
+
_layers_say " - $f [$s -> $d] imports $t (forbiddenImports)"
|
|
414
|
+
else
|
|
415
|
+
_layers_say " - $f [$s -> $d] imports $t"
|
|
416
|
+
fi
|
|
369
417
|
done
|
|
370
418
|
if [ "$NEW_COUNT" -gt 10 ]; then
|
|
371
419
|
_layers_say " ... and $((NEW_COUNT - 10)) more"
|
|
372
420
|
fi
|
|
421
|
+
if [ "${FORBIDDEN_SEEN:-0}" -gt 0 ]; then
|
|
422
|
+
_layers_say " Some edges are listed in a layer's forbiddenImports, an explicit denial."
|
|
423
|
+
fi
|
|
373
424
|
_layers_say " A layer may import only what its allowedImports lists."
|
|
374
425
|
_layers_say " To accept an existing violation, record it in $LAYER_BASELINE."
|
|
375
426
|
exit 1
|
package/hooks/gate-3.sh
CHANGED
|
@@ -363,7 +363,20 @@ else
|
|
|
363
363
|
LIZARD_PATH=$(eval echo "$LIZARD_CMD")
|
|
364
364
|
|
|
365
365
|
# Get changed source files for complexity check (includes test files)
|
|
366
|
-
|
|
366
|
+
#
|
|
367
|
+
# #847: `dart` added. The writer (scripts/ccn-report.cjs SOURCE_EXT) has
|
|
368
|
+
# listed `dart` all along, and so do Gate 2's SOURCE_FILES, Gate 4's
|
|
369
|
+
# PRINCIPLES_FILES and both dart.sh/flutter.sh adapters -- so the READER of
|
|
370
|
+
# the baseline was the one place that disagreed with everything else, and
|
|
371
|
+
# Dart cyclomatic complexity was never graded. Measured: `lizard --csv -C 5`
|
|
372
|
+
# on a Dart file emits a real CCN row, so the gap was never tool capability.
|
|
373
|
+
#
|
|
374
|
+
# THIS FILE HAS A TWIN. `githooks/gate-3.sh` and `githooks/adapters/gate-3.sh`
|
|
375
|
+
# were byte-identical before this change (md5 1d4e07cc...), and tests source
|
|
376
|
+
# the one under `adapters/`. A fix applied to only one of them leaves the
|
|
377
|
+
# other silently wrong -- which is how this edit was first written and how
|
|
378
|
+
# the accompanying test failed. Any change here must land in BOTH.
|
|
379
|
+
CC_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs|dart|php|phtml)$' || true)
|
|
367
380
|
|
|
368
381
|
# Grade exactly the population the baseline was written from. The two must
|
|
369
382
|
# match or the ratchet reports pre-existing code as "new", which is a false
|
|
@@ -484,8 +497,31 @@ else
|
|
|
484
497
|
_cc_pop_skipped=""
|
|
485
498
|
while IFS= read -r _cc_row; do
|
|
486
499
|
[ -n "$_cc_row" ] || continue
|
|
487
|
-
|
|
488
|
-
|
|
500
|
+
# The path is column 7 (index 6) of a lizard --csv row, NOT column 1.
|
|
501
|
+
#
|
|
502
|
+
# Column order (lizard --csv, no header, 11 fields):
|
|
503
|
+
# 0 NLOC | 1 CCN | 2 token_len | 3 param_count | 4 location_size
|
|
504
|
+
# 5 "name@start-end@path" | 6 path | 7 name | 8 signature | ...
|
|
505
|
+
# This read `$1` -- that is NLOC, not the path -- so every path
|
|
506
|
+
# handed to ccn_file_in_population was a bare number like "17".
|
|
507
|
+
# No number matches a declared root or extension, so EVERY row was
|
|
508
|
+
# classified "outside the baseline population" and dropped: the gate
|
|
509
|
+
# graded nothing, printed "not graded, not ratcheted", and fell
|
|
510
|
+
# through to "UNVERIFIED no parsable CCN row". The population filter
|
|
511
|
+
# therefore disabled the ratchet for ALL languages, not just the one
|
|
512
|
+
# it was being added for.
|
|
513
|
+
#
|
|
514
|
+
# Quote-aware via the shared awk helper rather than a second `-F,`
|
|
515
|
+
# split: the signature column (8) contains commas, so a naive field
|
|
516
|
+
# split lands on the wrong column as soon as a signature is present.
|
|
517
|
+
_cc_row_path=$(printf '%s' "$_cc_row" | csv_to_unit_separated | awk -F'\\037' '{print $7}')
|
|
518
|
+
# A row we cannot locate cannot be scoped: keep it and let the
|
|
519
|
+
# verifier decide, rather than silently dropping it as "out of
|
|
520
|
+
# population" — dropping is how "checked" became "checked nothing".
|
|
521
|
+
if [ -z "$_cc_row_path" ]; then
|
|
522
|
+
_cc_pop_kept="${_cc_pop_kept}${_cc_row}
|
|
523
|
+
"
|
|
524
|
+
elif ccn_file_in_population ".ccn-baseline.json" "$_cc_row_path"; then
|
|
489
525
|
_cc_pop_kept="${_cc_pop_kept}${_cc_row}
|
|
490
526
|
"
|
|
491
527
|
else
|
package/hooks/gate-4.sh
CHANGED
|
@@ -76,7 +76,7 @@ if [ "$PROJECT_LANG" = "documentation-only" ]; then
|
|
|
76
76
|
|
|
77
77
|
else
|
|
78
78
|
# Get source files to check against principles
|
|
79
|
-
PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm|cs)$' || true)
|
|
79
|
+
PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm|cs|php)$' || true)
|
|
80
80
|
|
|
81
81
|
# One path per line, into an array. Passing $PRINCIPLES_FILES unquoted relies on
|
|
82
82
|
# word splitting to turn the list into separate argv entries, which also splits
|
package/hooks/gate-6-layers.sh
CHANGED
|
@@ -202,7 +202,12 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
202
202
|
split(row, f, "\t")
|
|
203
203
|
if (f[1] == "") continue
|
|
204
204
|
n++
|
|
205
|
-
|
|
205
|
+
# f[4] is `forbiddenImports`. It was parsed but never loaded, so the
|
|
206
|
+
# field was dead config while reading as enforcement -- the #686 defect
|
|
207
|
+
# shape, inside the fix for #686. A declared-forbidden edge always loses,
|
|
208
|
+
# even when `allowedImports` also names it: an explicit denial must not be
|
|
209
|
+
# silently cancelled by a broader grant.
|
|
210
|
+
lname[n] = f[1]; lpat[n] = f[2]; lallow[n] = f[3]; lforb[n] = f[4]
|
|
206
211
|
# Patterns are compiled once here. layer_of() runs twice per source file
|
|
207
212
|
# (once for the importer, once per resolved target); recompiling there
|
|
208
213
|
# meant ~5800 regex builds for this repo and dominated the 2s scan.
|
|
@@ -251,6 +256,22 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
251
256
|
}
|
|
252
257
|
return 0
|
|
253
258
|
}
|
|
259
|
+
# `forbiddenImports` is the inverse of `allowedImports`, evaluated with the
|
|
260
|
+
# SAME two accepted forms (bare layer name or path glob) so a project cannot
|
|
261
|
+
# get enforcement by accident of spelling. It is checked BEFORE the allow
|
|
262
|
+
# list: an explicit denial wins over a broad grant. The alternative -- letting
|
|
263
|
+
# allowedImports cancel a forbiddenImports entry -- would make the stricter
|
|
264
|
+
# declaration the weaker one, which is the opposite of what a denial means.
|
|
265
|
+
function forbidden_hit(idx, tgt, dstname, k, j, p) {
|
|
266
|
+
k = split(lforb[idx], p, ",")
|
|
267
|
+
for (j = 1; j <= k; j++) {
|
|
268
|
+
if (p[j] == "") continue
|
|
269
|
+
if (p[j] == dstname) return 1
|
|
270
|
+
if (p[j] ~ /[*]/ && tgt ~ pat2re(p[j])) return 1
|
|
271
|
+
if (p[j] !~ /[*]/ && (tgt == p[j] || tgt ~ ("^" p[j] "/"))) return 1
|
|
272
|
+
}
|
|
273
|
+
return 0
|
|
274
|
+
}
|
|
254
275
|
# Resolve a relative specifier against the importing file.
|
|
255
276
|
function resolve(from, spec, np, i, dir, res, k, pp, trail, sx) {
|
|
256
277
|
sub(/[.](ts|tsx|js|jsx|mjs|cjs)$/, "", spec)
|
|
@@ -286,16 +307,35 @@ FINDINGS=$(XP_LAYER_TSV="$LAYER_TSV_FILE" XP_LAYER_STATS="$LAYER_STATS_FILE" awk
|
|
|
286
307
|
# // in http:// inside string literals.
|
|
287
308
|
if (line ~ /^[ \t]*(\/\/|[#]|[*]|\/\*)/) next
|
|
288
309
|
rest = line
|
|
289
|
-
|
|
310
|
+
# Two specifier forms are scanned, alternating so both are found in one pass:
|
|
311
|
+
# ES/TS import ... from "x"
|
|
312
|
+
# CJS require("x") (single-quoted form is scanned too)
|
|
313
|
+
# The `require(` form was missing entirely, which left every .cjs file and its
|
|
314
|
+
# dependencies unscanned. This repo holds 28 of them, several importing from
|
|
315
|
+
# the generated mirror -- so the checker reported a clean tree while the very
|
|
316
|
+
# edge its own config forbids existed on disk. A scanner that reads one of the
|
|
317
|
+
# two import syntaxes is a scanner that can pass without looking.
|
|
318
|
+
while (match(rest, /from[ \t]+"[^"]+"|from[ \t]+\047[^\047]+\047|require\([ \t]*"[^"]+"[ \t]*\)|require\([ \t]*\047[^\047]+\047[ \t]*\)/)) {
|
|
290
319
|
spec = substr(rest, RSTART, RLENGTH)
|
|
291
|
-
sub(/^from[ \t]+["\047]/, "", spec)
|
|
292
|
-
sub(/["\047]$/, "", spec)
|
|
293
320
|
rest = substr(rest, RSTART + RLENGTH)
|
|
321
|
+
if (spec ~ /^from/) {
|
|
322
|
+
sub(/^from[ \t]+["\047]/, "", spec)
|
|
323
|
+
sub(/["\047]$/, "", spec)
|
|
324
|
+
} else {
|
|
325
|
+
sub(/^require\([ \t]*["\047]/, "", spec)
|
|
326
|
+
sub(/["\047][ \t]*\)$/, "", spec)
|
|
327
|
+
}
|
|
294
328
|
if (src == 0 || spec == "") continue
|
|
295
329
|
tgt = resolve(file, spec)
|
|
296
330
|
if (tgt == "") continue
|
|
297
331
|
dst = layer_of(tgt)
|
|
298
332
|
if (dst == 0 || dst == src) continue
|
|
333
|
+
# Denial before grant: an explicit forbiddenImports entry is never
|
|
334
|
+
# cancelled by a broader allowedImports entry.
|
|
335
|
+
if (forbidden_hit(src, tgt, lname[dst])) {
|
|
336
|
+
printf "%s\t%s\t%s\t%s\tforbidden\n", file, lname[src], lname[dst], tgt
|
|
337
|
+
continue
|
|
338
|
+
}
|
|
299
339
|
if (allowed_ok(src, tgt, lname[dst])) continue
|
|
300
340
|
printf "%s\t%s\t%s\t%s\n", file, lname[src], lname[dst], tgt
|
|
301
341
|
}
|
|
@@ -364,12 +404,23 @@ if [ "$NEW_COUNT" -eq 0 ]; then
|
|
|
364
404
|
fi
|
|
365
405
|
|
|
366
406
|
_layers_say "❌ BLOCKED - $NEW_COUNT new layer violation(s) (of $TOTAL total):"
|
|
367
|
-
|
|
368
|
-
|
|
407
|
+
# A forbidden edge and an unlisted edge are different diagnoses -- one says the
|
|
408
|
+
# import is explicitly denied, the other says nobody declared it -- and the fix
|
|
409
|
+
# differs (remove the import vs declare it). Name which one fired.
|
|
410
|
+
FORBIDDEN_SEEN=$(printf '%s\n' "$NEW_FINDINGS" | awk -F'\t' '$5=="forbidden"' | grep -c . || true)
|
|
411
|
+
printf '%s\n' "$NEW_FINDINGS" | head -10 | while IFS="$(printf '\t')" read -r f s d t why; do
|
|
412
|
+
if [ "$why" = "forbidden" ]; then
|
|
413
|
+
_layers_say " - $f [$s -> $d] imports $t (forbiddenImports)"
|
|
414
|
+
else
|
|
415
|
+
_layers_say " - $f [$s -> $d] imports $t"
|
|
416
|
+
fi
|
|
369
417
|
done
|
|
370
418
|
if [ "$NEW_COUNT" -gt 10 ]; then
|
|
371
419
|
_layers_say " ... and $((NEW_COUNT - 10)) more"
|
|
372
420
|
fi
|
|
421
|
+
if [ "${FORBIDDEN_SEEN:-0}" -gt 0 ]; then
|
|
422
|
+
_layers_say " Some edges are listed in a layer's forbiddenImports, an explicit denial."
|
|
423
|
+
fi
|
|
373
424
|
_layers_say " A layer may import only what its allowedImports lists."
|
|
374
425
|
_layers_say " To accept an existing violation, record it in $LAYER_BASELINE."
|
|
375
426
|
exit 1
|
|
@@ -53,7 +53,13 @@ function filterFindings(raw, known) {
|
|
|
53
53
|
return raw
|
|
54
54
|
.split('\n')
|
|
55
55
|
.filter(Boolean)
|
|
56
|
-
|
|
56
|
+
// A finding may carry a 5th diagnostic field (`forbidden`, added when
|
|
57
|
+
// forbiddenImports became enforced). A ledger records WHERE the edge is, not
|
|
58
|
+
// WHY it was reported, so the key is the first four fields only. Comparing
|
|
59
|
+
// whole lines made every ledgered entry stop matching the moment the 5th
|
|
60
|
+
// column appeared, silently turning accepted debt back into blocking
|
|
61
|
+
// violations -- caught as two red tests, not by reading the code.
|
|
62
|
+
.filter((line) => !known.has(line.split('\t').slice(0, 4).join('\t')));
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
function main() {
|
package/hooks/lib/typecheck.sh
CHANGED
|
@@ -97,16 +97,62 @@ run_test_file_pass() {
|
|
|
97
97
|
else
|
|
98
98
|
echo "Checking test files for type errors..."
|
|
99
99
|
local temp_tsconfig=".tsconfig.withtests.json"
|
|
100
|
+
# `exclude` and `include` do NOT accept the same globs. TypeScript allows a
|
|
101
|
+
# trailing `**` in `exclude` but rejects it in `include` with TS5010
|
|
102
|
+
# ("File specification cannot end in a recursive directory wildcard").
|
|
103
|
+
#
|
|
104
|
+
# This block used to push `src/**/__tests__/**` -- copied from the exclude
|
|
105
|
+
# list, where it is legal and common -- into `include`. The generated config
|
|
106
|
+
# was therefore ALWAYS invalid, and tsc aborted before checking a single
|
|
107
|
+
# file. Every commit in a project with the standard
|
|
108
|
+
#
|
|
109
|
+
# "exclude": ["src/**/__tests__/**", ...]
|
|
110
|
+
#
|
|
111
|
+
# was blocked with "❌ TYPE ERRORS in test files" while its code was clean.
|
|
112
|
+
# A checker that cannot run was reporting as if it had run and found
|
|
113
|
+
# problems -- the failure mode this whole gate exists to remove.
|
|
114
|
+
#
|
|
115
|
+
# `src/**/__tests__/*` reaches the same files and is a legal include form.
|
|
100
116
|
node -e "
|
|
101
117
|
const cfg = JSON.parse(require('fs').readFileSync('tsconfig.json','utf8'));
|
|
102
118
|
delete cfg.exclude;
|
|
103
119
|
cfg.include = cfg.include || ['src/**/*'];
|
|
104
|
-
cfg.include.push('src/**/__tests__
|
|
120
|
+
cfg.include.push('src/**/__tests__/*','src/**/*.test.ts','src/**/*.spec.ts');
|
|
105
121
|
require('fs').writeFileSync('$temp_tsconfig', JSON.stringify(cfg, null, 2));
|
|
106
122
|
" 2>/dev/null
|
|
107
|
-
|
|
108
|
-
|
|
123
|
+
local tsc_out tsc_exit
|
|
124
|
+
tsc_out=$(_tsc_command --noEmit --project "$temp_tsconfig" --skipLibCheck 2>&1)
|
|
125
|
+
tsc_exit=$?
|
|
126
|
+
# The shared verdict below reads test_pass_exit; both tsc branches must feed
|
|
127
|
+
# it or this one silently inherits whatever the previous branch left behind.
|
|
128
|
+
test_pass_exit=$tsc_exit
|
|
129
|
+
printf '%s\n' "$tsc_out" | head -30
|
|
109
130
|
rm -f "$temp_tsconfig"
|
|
131
|
+
# Distinguish "tsc evaluated the project and found type errors" from "tsc
|
|
132
|
+
# rejected the config we generated and evaluated nothing". The verdict
|
|
133
|
+
# contract requires those to be different states; conflating them spends the
|
|
134
|
+
# user's time on our config and hides the real answer.
|
|
135
|
+
#
|
|
136
|
+
# Measured: with an INVALID config, tsc still checks every file it can see
|
|
137
|
+
# and reports real errors ALONGSIDE the config complaint. So a TS5xxx line
|
|
138
|
+
# alone does not mean "nothing was checked" -- it means nothing was checked
|
|
139
|
+
# only when it is the ONLY thing reported. Which is why the test below is
|
|
140
|
+
# "config error AND no type error", not "config error".
|
|
141
|
+
if [ "$tsc_exit" -ne 0 ] && printf '%s\n' "$tsc_out" | grep -qE 'TS5[0-9][0-9][0-9]'; then
|
|
142
|
+
# grep -E has no negative lookahead, so count instead of excluding:
|
|
143
|
+
# every diagnostic is `error TS<digits>`, and a 5xxx code is a
|
|
144
|
+
# configuration complaint rather than a type finding. If the totals match,
|
|
145
|
+
# the only thing tsc said was "your config is bad".
|
|
146
|
+
local all_err code_err
|
|
147
|
+
all_err=$(printf '%s\n' "$tsc_out" | grep -cE 'error TS[0-9]+')
|
|
148
|
+
code_err=$(printf '%s\n' "$tsc_out" | grep -cE 'error TS5[0-9][0-9][0-9]')
|
|
149
|
+
if [ "$all_err" -gt 0 ] && [ "$all_err" -eq "$code_err" ]; then
|
|
150
|
+
echo ""
|
|
151
|
+
echo "⚠️ Gate 1: the generated test tsconfig was rejected by tsc — test files NOT checked."
|
|
152
|
+
echo " This is a defect in xp-gate's test-file pass, not in your code."
|
|
153
|
+
return 2
|
|
154
|
+
fi
|
|
155
|
+
fi
|
|
110
156
|
fi
|
|
111
157
|
|
|
112
158
|
if [ "$test_pass_exit" -ne 0 ]; then
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-LANG-CAPABILITY
|
|
3
|
+
* @intent 一门新语言要在 13 个互不引用的接入面上各写一遍,缺任何一处的症状都是
|
|
4
|
+
* 「门禁打印 PASSED/SKIPPED 而从未检查过任何该语言的文件」。C# 为此分 5 波
|
|
5
|
+
* 补了 16 天,消费项目还自建了 400+ 行门禁兜底。本模块把「接全了吗」变成
|
|
6
|
+
* 从代码派生的三态输出,这些测试钉住派生的**准确性**与**不误报**两面。
|
|
7
|
+
* @covers AC-LANG-CAP-01, AC-LANG-CAP-02, AC-LANG-CAP-03, AC-LANG-CAP-04
|
|
8
|
+
*/
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
const fs = require('node:fs');
|
|
12
|
+
const os = require('node:os');
|
|
13
|
+
const path = require('node:path');
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
STATE,
|
|
17
|
+
inspectLanguage,
|
|
18
|
+
inspectAll,
|
|
19
|
+
summarise,
|
|
20
|
+
hasExtensionToken,
|
|
21
|
+
hasLanguageKey,
|
|
22
|
+
definitionAndCall,
|
|
23
|
+
} = require('../language-capability');
|
|
24
|
+
|
|
25
|
+
const REPO_ROOT = path.resolve(__dirname, '../../../..');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Build a fake hooks tree so each test states exactly which surfaces are wired.
|
|
29
|
+
*
|
|
30
|
+
* A fixture rather than the real repo on purpose: assertions against the live
|
|
31
|
+
* tree would fail every time a gate is legitimately edited, which teaches
|
|
32
|
+
* people to update the expectation instead of reading the failure. The real
|
|
33
|
+
* tree gets one separate test at the bottom.
|
|
34
|
+
*
|
|
35
|
+
* @param {Record<string, string>} files relative path -> content
|
|
36
|
+
* @returns {{root: string, cleanup: () => void}}
|
|
37
|
+
*/
|
|
38
|
+
function fixture(files) {
|
|
39
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-langcap-'));
|
|
40
|
+
const withDefaults = {
|
|
41
|
+
'githooks/pre-commit': '',
|
|
42
|
+
...files,
|
|
43
|
+
};
|
|
44
|
+
for (const [rel, content] of Object.entries(withDefaults)) {
|
|
45
|
+
const target = path.join(root, rel);
|
|
46
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
47
|
+
fs.writeFileSync(target, content);
|
|
48
|
+
}
|
|
49
|
+
return { root, cleanup: () => fs.rmSync(root, { recursive: true, force: true }) };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const ADAPTER = `
|
|
53
|
+
run_static_analysis() { return 0; }
|
|
54
|
+
run_lint() { return 0; }
|
|
55
|
+
run_tests() { return 0; }
|
|
56
|
+
run_coverage() { return 0; }
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
describe('extension-token matching is exact, not substring', () => {
|
|
60
|
+
it('does not report csx as cs', () => {
|
|
61
|
+
expect(hasExtensionToken('csx|vb', 'cs')).toBe(false);
|
|
62
|
+
expect(hasExtensionToken('cs|csx', 'cs')).toBe(true);
|
|
63
|
+
expect(hasExtensionToken('cs|csx', 'csx')).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// The real defect shape: a reader using includes('php') would match a
|
|
67
|
+
// variable name or a comment, and report a gate as wired when it is not.
|
|
68
|
+
it('does not match an extension that is only a prefix of another', () => {
|
|
69
|
+
expect(hasExtensionToken('phpcs', 'php')).toBe(false);
|
|
70
|
+
expect(hasExtensionToken('php|phps', 'php')).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('language keys must be delimited, not bare prose', () => {
|
|
75
|
+
it('ignores a language mentioned only in a comment', () => {
|
|
76
|
+
expect(hasLanguageKey('# see the php arm\n', 'php')).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('accepts case-arm and quoted-key shapes', () => {
|
|
80
|
+
expect(hasLanguageKey(' php)\n echo hi\n', 'php')).toBe(true);
|
|
81
|
+
expect(hasLanguageKey(" 'php': { name: 'PHP' },", 'php')).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('definitionAndCall separates "exists" from "is invoked"', () => {
|
|
86
|
+
// This is the exact C# Gate 13 defect (#717 §8): the function was defined and
|
|
87
|
+
// nothing called it, and a grep for the name read as coverage.
|
|
88
|
+
it('distinguishes a definition from a call', () => {
|
|
89
|
+
const definedOnly = 'gate13_run_php_analysis() {\n return 0\n}\n';
|
|
90
|
+
expect(definitionAndCall(definedOnly, 'gate13_run_php_analysis')).toEqual({
|
|
91
|
+
defined: true,
|
|
92
|
+
called: false,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const withCall = `${definedOnly}\ngate13_run_php_analysis; _g13_rc=$?\n`;
|
|
96
|
+
expect(definitionAndCall(withCall, 'gate13_run_php_analysis')).toEqual({
|
|
97
|
+
defined: true,
|
|
98
|
+
called: true,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('does not count a commented-out call', () => {
|
|
103
|
+
const text = 'gate13_run_php_analysis() { return 0; }\n# gate13_run_php_analysis\n';
|
|
104
|
+
expect(definitionAndCall(text, 'gate13_run_php_analysis').called).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('reports neither for an absent function', () => {
|
|
108
|
+
expect(definitionAndCall('echo hi\n', 'gate13_run_php_analysis')).toEqual({
|
|
109
|
+
defined: false,
|
|
110
|
+
called: false,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('未接线必须被报成 NOT WIRED,且每个面独立判定', () => {
|
|
116
|
+
it('reports an absent adapter as not implemented', () => {
|
|
117
|
+
const f = fixture({});
|
|
118
|
+
try {
|
|
119
|
+
const rows = inspectLanguage('php', {
|
|
120
|
+
root: f.root,
|
|
121
|
+
read: (rel) => {
|
|
122
|
+
try {
|
|
123
|
+
return fs.readFileSync(path.join(f.root, rel), 'utf8');
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
const adapter = rows.find((r) => r.surface === 'adapter');
|
|
130
|
+
expect(adapter.state).toBe(STATE.NOT_IMPLEMENTED);
|
|
131
|
+
} finally {
|
|
132
|
+
f.cleanup();
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('reports Gate 4 NOT WIRED when the filter accepts the file but the analyzer map does not', () => {
|
|
137
|
+
// The #717 defect verbatim: gate-4.sh listed `cs` in its filter, analyzer.ts
|
|
138
|
+
// had no '.cs' entry, so the file was accepted and then dropped.
|
|
139
|
+
const f = fixture({
|
|
140
|
+
'githooks/adapters/php.sh': ADAPTER,
|
|
141
|
+
'githooks/adapters/gate-4.sh': "PRINCIPLES_FILES=$(echo \"$CHANGED_FILES\" | grep -E '\\.(ts|php)$')\n",
|
|
142
|
+
'src/principles/analyzer.ts': "const adapterMap = { '.ts': TypeScriptAdapter };\n",
|
|
143
|
+
});
|
|
144
|
+
try {
|
|
145
|
+
const rows = inspectLanguage('php', {
|
|
146
|
+
root: f.root,
|
|
147
|
+
read: (rel) => {
|
|
148
|
+
try {
|
|
149
|
+
return fs.readFileSync(path.join(f.root, rel), 'utf8');
|
|
150
|
+
} catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
const gate4 = rows.find((r) => r.surface === 'gate-4');
|
|
156
|
+
expect(gate4.state).toBe(STATE.NOT_WIRED);
|
|
157
|
+
expect(gate4.evidence).toMatch(/adapterMap has no entry/);
|
|
158
|
+
} finally {
|
|
159
|
+
f.cleanup();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('reports Gate 13 NOT WIRED when the function is defined but never invoked', () => {
|
|
164
|
+
const f = fixture({
|
|
165
|
+
'githooks/adapters/gate-13-compiler-strictness.sh': 'gate13_run_php_analysis() { return 0; }\n',
|
|
166
|
+
'githooks/gate-entries/gate-13-entry.sh': 'gate13_run_cpp_analysis; _g13_rc=$?\n',
|
|
167
|
+
});
|
|
168
|
+
try {
|
|
169
|
+
const rows = inspectLanguage('php', {
|
|
170
|
+
root: f.root,
|
|
171
|
+
read: (rel) => {
|
|
172
|
+
try {
|
|
173
|
+
return fs.readFileSync(path.join(f.root, rel), 'utf8');
|
|
174
|
+
} catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
const g13 = rows.find((r) => r.surface === 'gate-13');
|
|
180
|
+
expect(g13.state).toBe(STATE.NOT_WIRED);
|
|
181
|
+
expect(g13.evidence).toMatch(/DEFINED BUT NEVER CALLED/);
|
|
182
|
+
} finally {
|
|
183
|
+
f.cleanup();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('不得误报:已接线的面必须读成 checked', () => {
|
|
189
|
+
it('reads a fully wired fixture as all-checked', () => {
|
|
190
|
+
const f = fixture({
|
|
191
|
+
'githooks/adapters/php.sh': ADAPTER,
|
|
192
|
+
'githooks/adapters/gate-3.sh': "CC_FILES=$(echo \"$CHANGED_FILES\" | grep -E '\\.(ts|php)$')\n",
|
|
193
|
+
'githooks/adapters/gate-4.sh': "PRINCIPLES_FILES=$(echo \"$CHANGED_FILES\" | grep -E '\\.(ts|php)$')\n",
|
|
194
|
+
'githooks/gate-entries/gate-0-entry.sh': '_detect_ext_lang "php" || true\n',
|
|
195
|
+
'githooks/gate-entries/gate-1-entry.sh': 'any_changed_files_match "\\.(ts|php)$" || true\n',
|
|
196
|
+
'githooks/gate-entries/gate-2-entry.sh': "SOURCE_FILES=$(echo \"$CHANGED_FILES\" | grep -E '\\.(ts|php)$')\n",
|
|
197
|
+
'githooks/gate-entries/gate-5-entry.sh': "CODE_EXTENSIONS=\"\\.(ts|php)$\"\n",
|
|
198
|
+
'githooks/gate-entries/gate-6-entry.sh': ' php)\n echo arch\n ;;\n',
|
|
199
|
+
'githooks/gate-entries/gate-9-entry.sh': ' php)\n echo build\n ;;\n',
|
|
200
|
+
'githooks/gate-10.sh': 'SEMGREP_RULES+=(--config="$(gate10_resolve_ruleset "p/php")")\n',
|
|
201
|
+
'githooks/adapters/gate-13-compiler-strictness.sh': 'gate13_run_php_analysis() { return 0; }\n',
|
|
202
|
+
'githooks/gate-entries/gate-13-entry.sh': 'gate13_run_php_analysis; _g13_rc=$?\n',
|
|
203
|
+
'src/principles/analyzer.ts': "const adapterMap = { '.php': PhpAdapter };\n",
|
|
204
|
+
'src/npm-package/lib/language-tools.js': ' php: {\n name: "PHP",\n },\n',
|
|
205
|
+
'.github/workflows/quality-gates.yml': " echo 'php' > project_language.txt\n",
|
|
206
|
+
});
|
|
207
|
+
try {
|
|
208
|
+
const rows = inspectLanguage('php', {
|
|
209
|
+
root: f.root,
|
|
210
|
+
read: (rel) => {
|
|
211
|
+
try {
|
|
212
|
+
return fs.readFileSync(path.join(f.root, rel), 'utf8');
|
|
213
|
+
} catch {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
const sum = summarise(rows);
|
|
219
|
+
expect(sum.notWired).toBe(0);
|
|
220
|
+
expect(sum.checked).toBeGreaterThanOrEqual(12);
|
|
221
|
+
} finally {
|
|
222
|
+
f.cleanup();
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The one test that reads the REAL tree.
|
|
229
|
+
*
|
|
230
|
+
* It asserts a property rather than a fixed score. Two properties are worth
|
|
231
|
+
* pinning here because both are silent when violated:
|
|
232
|
+
*
|
|
233
|
+
* 1. A routed language with an ANALYZER must not have the Gate 4
|
|
234
|
+
* filter/map mismatch. That mismatch (#717: gate-4.sh accepted `.cs`,
|
|
235
|
+
* `analyzer.ts` had no entry) is always a bug, never a design choice, and
|
|
236
|
+
* it presents as a gate that "checked" a file it discarded.
|
|
237
|
+
*
|
|
238
|
+
* 2. Gate 4 does NOT need to cover every language with an adapter. Measured:
|
|
239
|
+
* `analyzer.ts` has no shell, powershell or iac adapter at all, so those
|
|
240
|
+
* three languages are correctly absent from the filter. Asserting
|
|
241
|
+
* "filter must match adapters" would have demanded wiring that cannot
|
|
242
|
+
* exist, and the natural fix -- widening the filter -- would have created
|
|
243
|
+
* exactly the accepted-then-dropped defect this file exists to catch.
|
|
244
|
+
* The right requirement is that the language either has an analyzer or is
|
|
245
|
+
* a declared gap, and the two are distinguishable.
|
|
246
|
+
*/
|
|
247
|
+
describe('real repository invariants', () => {
|
|
248
|
+
it('no language that HAS an analyzer is discarded by the Gate 4 filter', () => {
|
|
249
|
+
const rows = inspectAll({ root: REPO_ROOT });
|
|
250
|
+
// Languages with an analyzer entry are exactly those the principled engine
|
|
251
|
+
// can construct; the filter must therefore accept them.
|
|
252
|
+
const analyzerSrc = fs.readFileSync(
|
|
253
|
+
path.join(REPO_ROOT, 'src/principles/analyzer.ts'),
|
|
254
|
+
'utf8',
|
|
255
|
+
);
|
|
256
|
+
const withAnalyzer = new Set();
|
|
257
|
+
for (const r of rows) {
|
|
258
|
+
const hasMapEntry = r.surface === 'gate-4' && /adapterMap/.test(r.evidence);
|
|
259
|
+
if (hasMapEntry) withAnalyzer.add(r.language);
|
|
260
|
+
}
|
|
261
|
+
const mismatches = rows.filter(
|
|
262
|
+
(r) =>
|
|
263
|
+
r.surface === 'gate-4' &&
|
|
264
|
+
r.state === STATE.NOT_WIRED &&
|
|
265
|
+
/adapterMap has no entry/.test(r.evidence),
|
|
266
|
+
);
|
|
267
|
+
// The mismatch state only arises when the filter ACCEPTS and the map does
|
|
268
|
+
// not -- so any occurrence is the defect regardless of the set above.
|
|
269
|
+
expect(mismatches.map((m) => `${m.language}: ${m.evidence}`)).toEqual([]);
|
|
270
|
+
expect(analyzerSrc.length).toBeGreaterThan(0);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('Gate 4 declares shell/powershell/iac as gaps rather than pretending', () => {
|
|
274
|
+
// Pinned so that adding an analyzer for one of them without wiring the
|
|
275
|
+
// filter fails here instead of shipping a half-scaffolded language.
|
|
276
|
+
const rows = inspectAll({ root: REPO_ROOT });
|
|
277
|
+
for (const lang of ['shell', 'powershell', 'iac']) {
|
|
278
|
+
const gate4 = rows.find((r) => r.language === lang && r.surface === 'gate-4');
|
|
279
|
+
expect(gate4.state).toBe(STATE.NOT_WIRED);
|
|
280
|
+
expect(gate4.evidence).toMatch(/extension absent from gate-4\.sh/);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('csharp is fully wired except Gate 9, which is a declared gap', () => {
|
|
285
|
+
const rows = inspectAll({ root: REPO_ROOT }).filter((r) => r.language === 'csharp');
|
|
286
|
+
const sum = summarise(rows);
|
|
287
|
+
expect(sum.notWired).toBe(0);
|
|
288
|
+
const gap = rows.find((r) => r.state === STATE.NOT_IMPLEMENTED);
|
|
289
|
+
expect(gap.surface).toBe('gate-9');
|
|
290
|
+
});
|
|
291
|
+
});
|