@boyingliu01/xp-gate 0.38.29 → 0.38.32

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.
@@ -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
- lname[n] = f[1]; lpat[n] = f[2]; lallow[n] = f[3]
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
- while (match(rest, /from[ \t]+"[^"]+"|from[ \t]+\047[^\047]+\047/)) {
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
- 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"
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/adapters/iac.sh CHANGED
@@ -76,6 +76,112 @@ run_static_analysis() {
76
76
  echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
77
77
 
78
78
  local exit_code=0
79
+
80
+ # ── Parse/type validation, before the security scanners ────────────────────
81
+ #
82
+ # checkov and tflint are SECURITY scanners. They answer "is this configuration
83
+ # dangerous", never "is this configuration parseable" -- and a file nothing can
84
+ # parse has no dangers to report, so they pass it. Measured on a one-file
85
+ # fixture whose closing brace was missing:
86
+ #
87
+ # checkov: "Parsing errors: 1 / Error parsing file ...\bad.tf" exit 0
88
+ # adapter: "✅ PASSED - Language-specific code quality checks." exit 0
89
+ # terraform: "Error: Unclosed configuration block" exit 1
90
+ #
91
+ # So the gate reported a positive verdict for a file its own toolchain refuses
92
+ # to load. Gate 1 does exactly this parse step for TypeScript (tsc) and C++
93
+ # (the compiler); IaC was the gap.
94
+ #
95
+ # Scope is deliberately narrow:
96
+ # - only when .tf files are in the change set (input short-circuit first)
97
+ # - only when terraform is resolvable locally (no network -- a gate must
98
+ # never install what it was asked to detect)
99
+ # - `-backend=false` so init cannot reach for a remote state backend
100
+ # - a bounded timeout, and a failure to RUN is reported as such rather than
101
+ # scored as "found nothing"
102
+ # `iac_files` is the three-line TERRAFORM:/KUBERNETES:/DOCKER: summary that
103
+ # detect_iac_files returns; take the Terraform line and drop the prefix.
104
+ local _tf_list
105
+ _tf_list=$(printf '%s\n' "$iac_files" | sed -n 's/^TERRAFORM://p')
106
+ if [ -n "${_tf_list// /}" ] && command -v terraform >/dev/null 2>&1; then
107
+ local _tf_attempted=0 _tf_bad=0
108
+ local _tf_dir
109
+ # Validate once per distinct directory: terraform resolves a whole module
110
+ # directory, so validating file by file would re-init the same module N times
111
+ # and report the same error N times.
112
+ #
113
+ # The list is split on whitespace deliberately (detect_iac_files emits
114
+ # space-separated paths) but goes into an ARRAY rather than straight into a
115
+ # `for`, so each element stays one path and a directory name containing a
116
+ # space cannot become two. shellcheck's SC2086 is right that a bare unquoted
117
+ # expansion here would be a latent word-splitting bug.
118
+ local _tf_dirs=()
119
+ local _tf_f
120
+ while IFS= read -r _tf_f; do
121
+ [ -n "$_tf_f" ] || continue
122
+ local _tf_d
123
+ _tf_d=$(dirname "$_tf_f")
124
+ # Dedupe without relying on IFS: compare against what is already there.
125
+ local _tf_seen=0 _tf_e
126
+ for _tf_e in ${_tf_dirs[@]+"${_tf_dirs[@]}"}; do
127
+ [ "$_tf_e" = "$_tf_d" ] && { _tf_seen=1; break; }
128
+ done
129
+ [ "$_tf_seen" -eq 0 ] && _tf_dirs+=("$_tf_d")
130
+ done <<TFEOF
131
+ $(printf '%s\n' "$_tf_list" | tr ' ' '\n' | sed '/^$/d')
132
+ TFEOF
133
+ for _tf_dir in ${_tf_dirs[@]+"${_tf_dirs[@]}"}; do
134
+ [ -d "$_tf_dir" ] || continue
135
+ _tf_attempted=$((_tf_attempted + 1))
136
+ local _tf_out _tf_rc
137
+ # Validate FIRST, without init.
138
+ #
139
+ # `terraform validate` answers the parse/type question on its own; it only
140
+ # needs init to resolve the provider SCHEMA, and a file that does not parse
141
+ # never gets that far. Measured on the unclosed-block fixture:
142
+ #
143
+ # terraform validate, no init 0.27 s -> "Unclosed configuration block"
144
+ # terraform init + validate 4.8 s -> same answer
145
+ #
146
+ # So init was 94% of the cost of a verdict it did not influence. It is run
147
+ # only when validate says it cannot proceed without it ("Missing required
148
+ # provider" / "Module not installed" / an uninitialized-directory warning),
149
+ # which is the clean-file case where the provider schema really is needed.
150
+ #
151
+ # `-backend=false` keeps init off any remote state backend: a gate must
152
+ # never wait on the network.
153
+ if command -v timeout >/dev/null 2>&1; then
154
+ _tf_out=$( cd "$_tf_dir" && timeout 120 terraform validate -no-color 2>&1 )
155
+ _tf_rc=$?
156
+ if [ "$_tf_rc" -ne 0 ] && printf '%s' "$_tf_out" | grep -qiE 'must be initialized|Missing required provider|Module not installed|run .terraform init'; then
157
+ ( cd "$_tf_dir" && timeout 120 terraform init -backend=false -input=false -no-color >/dev/null 2>&1 )
158
+ _tf_out=$( cd "$_tf_dir" && timeout 120 terraform validate -no-color 2>&1 )
159
+ _tf_rc=$?
160
+ fi
161
+ else
162
+ _tf_out=$( cd "$_tf_dir" && terraform validate -no-color 2>&1 )
163
+ _tf_rc=$?
164
+ if [ "$_tf_rc" -ne 0 ] && printf '%s' "$_tf_out" | grep -qiE 'must be initialized|Missing required provider|Module not installed|run .terraform init'; then
165
+ ( cd "$_tf_dir" && terraform init -backend=false -input=false -no-color >/dev/null 2>&1 )
166
+ _tf_out=$( cd "$_tf_dir" && terraform validate -no-color 2>&1 )
167
+ _tf_rc=$?
168
+ fi
169
+ fi
170
+ if [ "$_tf_rc" -ne 0 ]; then
171
+ _tf_bad=$((_tf_bad + 1))
172
+ echo " ❌ terraform validate rejected $_tf_dir:"
173
+ printf '%s\n' "$_tf_out" | grep -vE '^\s*$' | head -12 | sed 's/^/ /'
174
+ fi
175
+ done
176
+ if [ "$_tf_attempted" -gt 0 ] && [ "$_tf_bad" -gt 0 ]; then
177
+ echo " ❌ $_tf_bad Terraform module(s) failed validation."
178
+ exit_code=1
179
+ fi
180
+ if [ "$_tf_attempted" -eq 0 ]; then
181
+ echo " ⚠️ .tf files staged but no containing directory could be resolved;"
182
+ echo " syntax validation did not run."
183
+ fi
184
+ fi
79
185
  # #803: counts scanner/file pairs that actually ran, independent of their
80
186
  # verdict. `exit_code == 0` answers "did anything fail?"; it cannot answer "did
81
187
  # anything run?", and using it for both made a clean scan indistinguishable from
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
- lname[n] = f[1]; lpat[n] = f[2]; lallow[n] = f[3]
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
- while (match(rest, /from[ \t]+"[^"]+"|from[ \t]+\047[^\047]+\047/)) {
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
- 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"
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
@@ -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
- lname[n] = f[1]; lpat[n] = f[2]; lallow[n] = f[3]
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
- while (match(rest, /from[ \t]+"[^"]+"|from[ \t]+\047[^\047]+\047/)) {
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
- 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"
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
- .filter(line => !known.has(line));
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() {
@@ -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__/**','src/**/*.test.ts','src/**/*.spec.ts');
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
- _tsc_command --noEmit --project "$temp_tsconfig" --skipLibCheck 2>&1 | head -30
108
- test_pass_exit=${PIPESTATUS[0]}
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
@@ -53,7 +53,13 @@ function filterFindings(raw, known) {
53
53
  return raw
54
54
  .split('\n')
55
55
  .filter(Boolean)
56
- .filter(line => !known.has(line));
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() {
@@ -2,6 +2,6 @@
2
2
  "verdict": "PASS",
3
3
  "license_type": "MIT",
4
4
  "sha256": "0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5",
5
- "checked_at": "2026-11-19T08:06:36.345Z",
5
+ "checked_at": "2026-11-19T09:52:42.581Z",
6
6
  "source": "network"
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/xp-gate",
3
- "version": "0.38.29",
3
+ "version": "0.38.32",
4
4
  "description": "AI-driven development workflow: 6 quality gates + Delphi review + Sprint Flow",
5
5
  "bin": {
6
6
  "xp-gate": "bin/xp-gate.js"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.38.29",
3
+ "version": "0.38.32",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Claude Code. Includes 12 pre-commit gates (Gate 0-11), 8 pre-push gates, Sprint Flow (6 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/opencode-plugin",
3
- "version": "0.38.29",
3
+ "version": "0.38.32",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "XP-Gate quality gates + AI workflow skills for OpenCode",
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.29.0
6
+ **Version:** 0.38.32.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.