@boyingliu01/xp-gate 0.38.4 → 0.38.6

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.
Files changed (64) hide show
  1. package/adapters/gate-10.sh +478 -0
  2. package/adapters/gate-12-file-hygiene.sh +315 -0
  3. package/adapters/gate-13-compiler-strictness.sh +1443 -0
  4. package/adapters/gate-6-layers.sh +375 -0
  5. package/adapters/gate-8.sh +13 -1
  6. package/adapters/iac.sh +60 -27
  7. package/adapters/shell.sh +50 -2
  8. package/build-integrity/gate-10.ts +63 -4
  9. package/gate-12-file-hygiene.sh +15 -7
  10. package/gate-8.sh +13 -1
  11. package/hooks/gate-12-file-hygiene.sh +15 -7
  12. package/hooks/gate-8.sh +13 -1
  13. package/hooks/gate-entries/gate-1-entry.sh +44 -3
  14. package/hooks/gate-entries/gate-10-entry.sh +7 -0
  15. package/hooks/gate-entries/gate-11-entry.sh +7 -0
  16. package/hooks/gate-entries/gate-12-entry.sh +7 -0
  17. package/hooks/gate-entries/gate-12b-entry.sh +7 -0
  18. package/hooks/gate-entries/gate-12c-entry.sh +7 -0
  19. package/hooks/gate-entries/gate-13-entry.sh +7 -0
  20. package/hooks/gate-entries/gate-5-entry.sh +56 -2
  21. package/hooks/gate-entries/gate-6-entry.sh +93 -2
  22. package/hooks/gate-entries/gate-7-entry.sh +7 -0
  23. package/hooks/gate-entries/gate-8-entry.sh +7 -0
  24. package/hooks/gate-entries/gate-9-entry.sh +7 -0
  25. package/hooks/post-commit +9 -0
  26. package/hooks/pre-push +11 -2
  27. package/lib/mattpocock-license-verdict.json +1 -1
  28. package/mock-policy/AGENTS.md +1 -1
  29. package/mutation/AGENTS.md +1 -1
  30. package/package.json +1 -1
  31. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  32. package/plugins/claude-code/bin/xp-gate-version-check.sh +6 -0
  33. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  34. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  35. package/plugins/claude-code/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
  36. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  37. package/plugins/dsh/package.json +1 -1
  38. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  39. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  40. package/plugins/dsh/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
  41. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  42. package/plugins/opencode/package.json +1 -1
  43. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  44. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  45. package/plugins/opencode/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
  46. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  47. package/plugins/qoder/plugin.json +1 -1
  48. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  49. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  50. package/plugins/qoder/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +23 -1
  51. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  52. package/principles/AGENTS.md +1 -1
  53. package/scripts/generate-mirrors.cjs +85 -28
  54. package/scripts/sync-package-content.js +5 -0
  55. package/skills/delphi-review/AGENTS.md +1 -1
  56. package/skills/sprint-flow/AGENTS.md +1 -1
  57. package/skills/test-specification-alignment/AGENTS.md +1 -1
  58. package/build-integrity/__tests__/ccn-refactor-gate10.test.ts +0 -133
  59. package/build-integrity/__tests__/gate-10.test.ts +0 -340
  60. package/build-integrity/__tests__/import-resolver.test.ts +0 -747
  61. package/build-integrity/__tests__/orchestrator.test.ts +0 -302
  62. package/build-integrity/__tests__/quote-masker.test.ts +0 -177
  63. package/skills/sprint-flow/__tests__/sprint-flow.test.cjs +0 -457
  64. package/skills/sprint-flow/__tests__/verify-sprint-state.test.bats +0 -48
@@ -199,7 +199,15 @@ fi
199
199
 
200
200
  # --- Check 5: YAML/JSON syntax validation (Issue #351) ---
201
201
  # Only check staged YAML/JSON files that have changes
202
- YAML_JSON_ERRORS=""
202
+ #
203
+ # #772: these were accumulated into a space-separated STRING and re-split with an
204
+ # unquoted `for f in $YAML_JSON_ERRORS`. Parser messages contain spaces, so one
205
+ # broken file printed as a run of fake "filenames" -- PyYAML's
206
+ # "while parsing a flow sequence" became five entries. The list under
207
+ # "YAML/JSON syntax errors:" reads as the set of files to go fix, so the split
208
+ # sent the reader hunting for files that do not exist. Arrays keep each entry
209
+ # whole no matter what the message contains.
210
+ YAML_JSON_ERRORS=()
203
211
  YAML_JSON_CHECK_COUNT=0
204
212
 
205
213
  # Detect available validators
@@ -241,7 +249,7 @@ except Exception:
241
249
  pass
242
250
  " 2>&1)
243
251
  if [ $? -ne 0 ] && [ -n "$YAML_ERROR" ]; then
244
- YAML_JSON_ERRORS="$YAML_JSON_ERRORS $file(yaml:$YAML_ERROR)"
252
+ YAML_JSON_ERRORS+=("$file(yaml:$YAML_ERROR)")
245
253
  fi
246
254
  fi
247
255
  ;;
@@ -252,12 +260,12 @@ except Exception:
252
260
  let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>{try{JSON.parse(d)}catch(e){console.log(e.message.split('\\n')[0]);process.exit(1)}})
253
261
  " 2>&1)
254
262
  if [ $? -ne 0 ] && [ -n "$JSON_ERROR" ]; then
255
- YAML_JSON_ERRORS="$YAML_JSON_ERRORS $file(json:$JSON_ERROR)"
263
+ YAML_JSON_ERRORS+=("$file(json:$JSON_ERROR)")
256
264
  fi
257
265
  elif [ "$JSON_CMD" = "jq" ]; then
258
266
  JSON_ERROR=$(git show ":$file" 2>/dev/null | jq empty 2>&1)
259
267
  if [ $? -ne 0 ] && [ -n "$JSON_ERROR" ]; then
260
- YAML_JSON_ERRORS="$YAML_JSON_ERRORS $file(json:syntax error)"
268
+ YAML_JSON_ERRORS+=("$file(json:syntax error)")
261
269
  fi
262
270
  fi
263
271
  ;;
@@ -266,9 +274,9 @@ done <<EOF
266
274
  $CHANGED_YAML_JSON
267
275
  EOF
268
276
 
269
- if [ -n "$YAML_JSON_ERRORS" ]; then
277
+ if [ "${#YAML_JSON_ERRORS[@]}" -gt 0 ]; then
270
278
  echo " ❌ YAML/JSON syntax errors:"
271
- for f in $YAML_JSON_ERRORS; do
279
+ for f in "${YAML_JSON_ERRORS[@]}"; do
272
280
  echo " - $f"
273
281
  done
274
282
  HYGIENE_ISSUES=$((HYGIENE_ISSUES + 1))
@@ -289,7 +297,7 @@ if [ "$HYGIENE_ISSUES" -eq 0 ]; then
289
297
  GATE_12_STATUS="PASS"
290
298
  else
291
299
  # Hard blocks: conflict markers + YAML/JSON syntax errors
292
- if [ -n "$CONFLICT_MARKER_FILES" ] || [ -n "$YAML_JSON_ERRORS" ]; then
300
+ if [ -n "$CONFLICT_MARKER_FILES" ] || [ "${#YAML_JSON_ERRORS[@]}" -gt 0 ]; then
293
301
  echo ""
294
302
  echo "❌ BLOCKED - File hygiene violations must be fixed before commit."
295
303
  GATE_12_STATUS="BLOCK"
package/gate-8.sh CHANGED
@@ -348,7 +348,19 @@ if command -v detect-secrets-hook >/dev/null 2>&1 && [ -f ".secrets.baseline" ];
348
348
  fi
349
349
  # Temp cleanup is owned by the gate8_cleanup trap; no rm here.
350
350
  else
351
- echo " ⚠️ detect-secrets-hook unavailable (install: pip install -e \".[dev]\") — gitleaks only."
351
+ # #793: this branch used to blame the tool unconditionally. Both "the hook is
352
+ # not installed" and "the baseline file is missing" land here, so a repo with
353
+ # detect-secrets 1.5.52 on PATH was told to run `pip install -e ".[dev]"` --
354
+ # correct-looking advice that changes nothing, while the file actually missing
355
+ # (the committed `.secrets.baseline`) was never named. The two have different
356
+ # remedies and only one of them is an install, so they are split here.
357
+ if command -v detect-secrets-hook >/dev/null 2>&1; then
358
+ echo " ⚠️ detect-secrets-hook is installed but .secrets.baseline is missing."
359
+ echo " Generate it once with: detect-secrets scan > .secrets.baseline"
360
+ echo " (gitleaks still ran.)"
361
+ else
362
+ echo " ⚠️ detect-secrets-hook unavailable (install: pip install -e \".[dev]\") — gitleaks only."
363
+ fi
352
364
  fi
353
365
 
354
366
  record_gate_audit "gate-8" "secret-scanning" "$GATE_8_STATUS" "0" "$GATE_8_START"
@@ -199,7 +199,15 @@ fi
199
199
 
200
200
  # --- Check 5: YAML/JSON syntax validation (Issue #351) ---
201
201
  # Only check staged YAML/JSON files that have changes
202
- YAML_JSON_ERRORS=""
202
+ #
203
+ # #772: these were accumulated into a space-separated STRING and re-split with an
204
+ # unquoted `for f in $YAML_JSON_ERRORS`. Parser messages contain spaces, so one
205
+ # broken file printed as a run of fake "filenames" -- PyYAML's
206
+ # "while parsing a flow sequence" became five entries. The list under
207
+ # "YAML/JSON syntax errors:" reads as the set of files to go fix, so the split
208
+ # sent the reader hunting for files that do not exist. Arrays keep each entry
209
+ # whole no matter what the message contains.
210
+ YAML_JSON_ERRORS=()
203
211
  YAML_JSON_CHECK_COUNT=0
204
212
 
205
213
  # Detect available validators
@@ -241,7 +249,7 @@ except Exception:
241
249
  pass
242
250
  " 2>&1)
243
251
  if [ $? -ne 0 ] && [ -n "$YAML_ERROR" ]; then
244
- YAML_JSON_ERRORS="$YAML_JSON_ERRORS $file(yaml:$YAML_ERROR)"
252
+ YAML_JSON_ERRORS+=("$file(yaml:$YAML_ERROR)")
245
253
  fi
246
254
  fi
247
255
  ;;
@@ -252,12 +260,12 @@ except Exception:
252
260
  let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>{try{JSON.parse(d)}catch(e){console.log(e.message.split('\\n')[0]);process.exit(1)}})
253
261
  " 2>&1)
254
262
  if [ $? -ne 0 ] && [ -n "$JSON_ERROR" ]; then
255
- YAML_JSON_ERRORS="$YAML_JSON_ERRORS $file(json:$JSON_ERROR)"
263
+ YAML_JSON_ERRORS+=("$file(json:$JSON_ERROR)")
256
264
  fi
257
265
  elif [ "$JSON_CMD" = "jq" ]; then
258
266
  JSON_ERROR=$(git show ":$file" 2>/dev/null | jq empty 2>&1)
259
267
  if [ $? -ne 0 ] && [ -n "$JSON_ERROR" ]; then
260
- YAML_JSON_ERRORS="$YAML_JSON_ERRORS $file(json:syntax error)"
268
+ YAML_JSON_ERRORS+=("$file(json:syntax error)")
261
269
  fi
262
270
  fi
263
271
  ;;
@@ -266,9 +274,9 @@ done <<EOF
266
274
  $CHANGED_YAML_JSON
267
275
  EOF
268
276
 
269
- if [ -n "$YAML_JSON_ERRORS" ]; then
277
+ if [ "${#YAML_JSON_ERRORS[@]}" -gt 0 ]; then
270
278
  echo " ❌ YAML/JSON syntax errors:"
271
- for f in $YAML_JSON_ERRORS; do
279
+ for f in "${YAML_JSON_ERRORS[@]}"; do
272
280
  echo " - $f"
273
281
  done
274
282
  HYGIENE_ISSUES=$((HYGIENE_ISSUES + 1))
@@ -289,7 +297,7 @@ if [ "$HYGIENE_ISSUES" -eq 0 ]; then
289
297
  GATE_12_STATUS="PASS"
290
298
  else
291
299
  # Hard blocks: conflict markers + YAML/JSON syntax errors
292
- if [ -n "$CONFLICT_MARKER_FILES" ] || [ -n "$YAML_JSON_ERRORS" ]; then
300
+ if [ -n "$CONFLICT_MARKER_FILES" ] || [ "${#YAML_JSON_ERRORS[@]}" -gt 0 ]; then
293
301
  echo ""
294
302
  echo "❌ BLOCKED - File hygiene violations must be fixed before commit."
295
303
  GATE_12_STATUS="BLOCK"
package/hooks/gate-8.sh CHANGED
@@ -348,7 +348,19 @@ if command -v detect-secrets-hook >/dev/null 2>&1 && [ -f ".secrets.baseline" ];
348
348
  fi
349
349
  # Temp cleanup is owned by the gate8_cleanup trap; no rm here.
350
350
  else
351
- echo " ⚠️ detect-secrets-hook unavailable (install: pip install -e \".[dev]\") — gitleaks only."
351
+ # #793: this branch used to blame the tool unconditionally. Both "the hook is
352
+ # not installed" and "the baseline file is missing" land here, so a repo with
353
+ # detect-secrets 1.5.52 on PATH was told to run `pip install -e ".[dev]"` --
354
+ # correct-looking advice that changes nothing, while the file actually missing
355
+ # (the committed `.secrets.baseline`) was never named. The two have different
356
+ # remedies and only one of them is an install, so they are split here.
357
+ if command -v detect-secrets-hook >/dev/null 2>&1; then
358
+ echo " ⚠️ detect-secrets-hook is installed but .secrets.baseline is missing."
359
+ echo " Generate it once with: detect-secrets scan > .secrets.baseline"
360
+ echo " (gitleaks still ran.)"
361
+ else
362
+ echo " ⚠️ detect-secrets-hook unavailable (install: pip install -e \".[dev]\") — gitleaks only."
363
+ fi
352
364
  fi
353
365
 
354
366
  record_gate_audit "gate-8" "secret-scanning" "$GATE_8_STATUS" "0" "$GATE_8_START"
@@ -22,6 +22,32 @@
22
22
  # Combination of: Old Gates 1 (Static), Gate 2 (Linting), Gate 5 (Shell Check)
23
23
  # v0.14.3+ (Issue #312): Skip if no code files changed
24
24
  # ============================================================================
25
+ # Select the CHANGED files that the shell arm must lint, one per line.
26
+ #
27
+ # A file is a shell script when its name ends in .sh/.bash, OR when its first
28
+ # line carries a bash/sh shebang. The shebang arm is what reaches `pre-commit`,
29
+ # `pre-push`, `post-commit` and `post-merge`: they have no extension and are the
30
+ # largest shell programs in this repository, so the previous extension-only
31
+ # filter (`grep '\.sh$'`) made them structurally exempt from the gate. The same
32
+ # rule is implemented in githooks/adapters/shell.sh -- keep the two in step.
33
+ #
34
+ # Only files that exist in the work tree are returned: a deleted file cannot be
35
+ # linted, and passing it to shellcheck would turn a deletion into a failure.
36
+ _shell_changed_files() {
37
+ local f first
38
+ for f in $CHANGED_FILES; do
39
+ [ -f "$f" ] || continue
40
+ case "$f" in
41
+ *.sh|*.bash) echo "$f"; continue ;;
42
+ esac
43
+ # No shell extension: accept only a shell shebang on line 1.
44
+ first="$(sed -n '1p' "$f" 2>/dev/null || true)"
45
+ case "$first" in
46
+ '#!'*bash*|'#!'*'/sh'|'#!'*' sh'|'#!'*'env sh'*) echo "$f" ;;
47
+ esac
48
+ done
49
+ }
50
+
25
51
  # Gate body. `return` is used instead of `exit` so the driver decides to
26
52
  # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
27
53
  # here, and why sub-shell exits are deliberately left as `exit`.
@@ -241,8 +267,16 @@ else
241
267
  # scripts/check-no-npx-probe.sh fails the build if the npx rung returns.
242
268
  BIOME_ARGV=(biome)
243
269
  fi
244
- # shellcheck disable=SC2086 # BIOME_ARGV may hold a multi-token form on purpose
245
- BIOME_OUT=$(cd "$TS_PROJECT_DIR" && ${BIOME_ARGV[@]} check --staged . 2>&1)
270
+ # Quoted expansion. The array holds exactly one path token (either the
271
+ # bare word `biome` or an absolute node_modules path), and that path can
272
+ # contain spaces -- a project checked out under "C:/My Projects/..." is
273
+ # ordinary on Windows. Unquoted, `${BIOME_ARGV[@]}` re-splits it into
274
+ # several arguments, so biome would be invoked as a different command and
275
+ # exit 127; the 127 branch below reads that as "biome absent" and SKIPs.
276
+ # The old `disable=SC2086 # may hold a multi-token form` was inaccurate:
277
+ # every assignment site above sets a single element or an empty array,
278
+ # so no multi-token form exists to protect.
279
+ BIOME_OUT=$(cd "$TS_PROJECT_DIR" && "${BIOME_ARGV[@]}" check --staged . 2>&1)
246
280
  BIOME_STATUS=$?
247
281
  if [ "$BIOME_STATUS" -eq 127 ]; then
248
282
  # 127 is the shell's own "command not found": biome is genuinely absent.
@@ -524,7 +558,14 @@ else
524
558
  shell)
525
559
  # Shell: check staged shell files only. Installed hook adapters are infrastructure,
526
560
  # not project changes, and should not be linted on unrelated commits.
527
- SHELL_FILES=$(echo "$CHANGED_FILES" | grep '\.sh$' || true)
561
+ #
562
+ # The filter used to be `grep '\.sh$'`, which cannot match the extensionless
563
+ # hooks -- `pre-commit`, `pre-push`, `post-commit`, `post-merge` -- and those are
564
+ # the two largest shell programs in this repository. A file that cannot enter the
565
+ # gate cannot fail it, so the biggest shell code in the repo was structurally
566
+ # exempt. Same rule as githooks/adapters/shell.sh: a .sh/.bash name, OR a shell
567
+ # shebang on the first line for the extensionless cases.
568
+ SHELL_FILES="$(_shell_changed_files)"
528
569
 
529
570
  if [ -z "$SHELL_FILES" ]; then
530
571
  echo "✅ PASSED - No staged shell scripts to check."
@@ -27,6 +27,13 @@
27
27
  # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
28
28
  # here, and why sub-shell exits are deliberately left as `exit`.
29
29
  gate_10_run() {
30
+ if ! gate_enabled 10; then
31
+ echo "⏭️ SKIPPED - Gate 10: SAST security (not selected by XP_GATE_ONLY_GATE)"
32
+ GATE_10_STATUS="SKIP"
33
+ GATE_10_DETAIL="not_selected"
34
+ return 0
35
+ fi
36
+
30
37
  if any_changed_files_match "\.(ts|tsx|js|jsx|py|go|java|kt|cpp|c|swift|m|dart|sh|ps1|psm1|cs|csx|fs|vb|rs|php|rb|lua|pl)$"; then
31
38
  if [ -f "$GATE_DIR/gate-10.sh" ]; then
32
39
  source "$GATE_DIR/gate-10.sh"
@@ -26,6 +26,13 @@
26
26
  # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
27
27
  # here, and why sub-shell exits are deliberately left as `exit`.
28
28
  gate_11_run() {
29
+ if ! gate_enabled 11; then
30
+ echo "⏭️ SKIPPED - Gate 11: Sprint flow (not selected by XP_GATE_ONLY_GATE)"
31
+ GATE_11_STATUS="SKIP"
32
+ GATE_11_DETAIL="not_selected"
33
+ return 0
34
+ fi
35
+
29
36
  GATE_11_START=$(gate_start_ms)
30
37
  GATE_11_STATUS="PASS"
31
38
 
@@ -27,6 +27,13 @@
27
27
  # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
28
28
  # here, and why sub-shell exits are deliberately left as `exit`.
29
29
  gate_12_run() {
30
+ if ! gate_enabled 12; then
31
+ echo "⏭️ SKIPPED - Gate 12: File hygiene (not selected by XP_GATE_ONLY_GATE)"
32
+ GATE_12_STATUS="SKIP"
33
+ GATE_12_DETAIL="not_selected"
34
+ return 0
35
+ fi
36
+
30
37
  if [ -f "$GATE_DIR/gate-12-file-hygiene.sh" ]; then
31
38
  source "$GATE_DIR/gate-12-file-hygiene.sh"
32
39
  elif [ -f "$(git rev-parse --show-toplevel 2>/dev/null)/githooks/gate-12-file-hygiene.sh" ]; then
@@ -34,6 +34,13 @@
34
34
  # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
35
35
  # here, and why sub-shell exits are deliberately left as `exit`.
36
36
  gate_12b_run() {
37
+ if ! gate_enabled 12b; then
38
+ echo "⏭️ SKIPPED - Gate 12b: Vendor exclusion (not selected by XP_GATE_ONLY_GATE)"
39
+ GATE_12B_STATUS="SKIP"
40
+ GATE_12B_DETAIL="not_selected"
41
+ return 0
42
+ fi
43
+
37
44
  MIRROR_STAGED=$(git diff --cached --name-only --diff-filter=ACMR 2>/dev/null || true)
38
45
  # `src/npm-package/` is in this filter because a mirror-only edit is the
39
46
  # dangerous direction, not the harmless one. Keying off the canonical paths
@@ -36,6 +36,13 @@ gate_12c_run() {
36
36
  # Scoped to commits that touch hook sources: the rule can only be broken by
37
37
  # editing one, and scanning 51 files on every docs-only commit is exactly the
38
38
  # fixed cost the input short-circuit convention exists to avoid.
39
+ if ! gate_enabled 12c; then
40
+ echo "⏭️ SKIPPED - Gate 12c: Worktree hygiene (not selected by XP_GATE_ONLY_GATE)"
41
+ GATE_12C_STATUS="SKIP"
42
+ GATE_12C_DETAIL="not_selected"
43
+ return 0
44
+ fi
45
+
39
46
  if printf '%s\n' "$STAGED_FILES" 2>/dev/null | grep -qE '^githooks/(adapters/|lib/|adapter-common\.sh|pre-commit|pre-push|post-commit|post-merge)'; then
40
47
  _probe_root="${PROJECT_ROOT:-}"
41
48
  if [ -n "$_probe_root" ] && [ -f "$_probe_root/scripts/check-no-npx-probe.sh" ]; then
@@ -509,6 +509,13 @@ ENDJSON
509
509
  }
510
510
 
511
511
  gate_13_run() {
512
+ if ! gate_enabled 13; then
513
+ echo "⏭️ SKIPPED - Gate 13: Compiler strictness (not selected by XP_GATE_ONLY_GATE)"
514
+ GATE_13_STATUS="SKIP"
515
+ GATE_13_DETAIL="not_selected"
516
+ return 0
517
+ fi
518
+
512
519
  GATE_13_STATUS="SKIP"
513
520
  if [ "${XP_GATE_DISABLE_13:-}" = "1" ]; then
514
521
  echo "⏭️ SKIPPED - Gate 13: Compiler Strictness (XP_GATE_DISABLE_13=1)"
@@ -322,6 +322,14 @@ else
322
322
  "${dir}/__tests__/${filename}.spec.${ext}"
323
323
  "tests/${filename}.test.${ext}"
324
324
  "tests/${filename}.spec.${ext}"
325
+ # #787: `test/` (singular) is as conventional as `tests/` (plural), and
326
+ # both live in the wild -- Jest silently accepts either, so a repo that
327
+ # picked the singular spelling was hard-BLOCKED on a file whose test was
328
+ # right there. The asymmetry made it read like a user error: identical
329
+ # content under tests/ passed, and only the path spelling decided the
330
+ # verdict, so "did you mean tests/" was not actionable advice.
331
+ "test/${filename}.test.${ext}"
332
+ "test/${filename}.spec.${ext}"
325
333
  )
326
334
 
327
335
  for pattern in "${patterns[@]}"; do
@@ -887,7 +895,25 @@ else
887
895
  # staged 42% never reached the threshold. The skip now also requires that no
888
896
  # coverage evidence is present.
889
897
  GATE_5_COVERAGE_EVIDENCE=false
890
- if [ -f "coverage/coverage-summary.json" ] || [ -f "coverage/coverage-final.json" ]; then
898
+ # #821: evidence must come FROM THE COMMIT, not from the working tree.
899
+ #
900
+ # This used to be a bare `-f` on the two report paths, so ANY leftover report
901
+ # counted -- e.g. coverage/coverage-summary.json left behind by an earlier local
902
+ # run over a different tree. Measured 2026-11-16 in this repo: a commit staging
903
+ # one test file under the bundled mirror was blocked with
904
+ # ❌ BLOCKED - TypeScript coverage 2% below 78% threshold
905
+ # and the identical commit passed once the leftover coverage/ directory was
906
+ # removed. The percentage described neither this commit nor this tree, and the
907
+ # working tree additionally carried a second workstream's uncommitted source.
908
+ #
909
+ # A report is evidence for this commit when the commit carries it. This keeps
910
+ # #601 intact -- that issue is about a STAGED report being ignored, and its
911
+ # fixtures stage the artefact with `git add -f` -- while refusing to answer
912
+ # "how well is this change tested" with a stale measurement of something else.
913
+ # `git cat-file -e :<path>` asks the INDEX (the commit being built) for the
914
+ # blob; a plain `-f` asks the directory.
915
+ if git cat-file -e ":coverage/coverage-summary.json" 2>/dev/null \
916
+ || git cat-file -e ":coverage/coverage-final.json" 2>/dev/null; then
891
917
  GATE_5_COVERAGE_EVIDENCE=true
892
918
  fi
893
919
  if [ "${TESTS_SKIPPED:-false}" = "true" ] && [ "${TESTS_RAN_ANY:-false}" != "true" ] \
@@ -1260,7 +1286,35 @@ else
1260
1286
  # #570: the report file is absent, so nothing was measured. Warning and
1261
1287
  # continuing made "delete coverage/coverage-summary.json" an effective way
1262
1288
  # to switch this gate off.
1263
- if [ "${PARTIAL_TEST_RUN:-false}" = "true" ]; then
1289
+ #
1290
+ # #823: but "absent" has two causes and only one of them is a problem.
1291
+ # Measured 2026-11-16 committing a comment-only fix to a gate script --
1292
+ # Gate 5 printed, in this order,
1293
+ # ✅ PASSED - No test or source files changed, skipping test run.
1294
+ # ℹ️ No TypeScript tests were selected — no TS coverage to evaluate.
1295
+ # ❌ BLOCKED - coverage/coverage-summary.json not found.
1296
+ # The gate established twice that it had nothing to measure, then demanded
1297
+ # a measurement. PARTIAL_TEST_RUN did not cover it because that flag means
1298
+ # "some tests ran"; here NO test was selected, so a commit touching nothing
1299
+ # but shell reached the strict arm of #570 and could only land with a Gate 0
1300
+ # version bump or a fabricated report.
1301
+ #
1302
+ # #570 stays intact: tests SELECTED but producing no report is still the
1303
+ # off-switch this must block. Only "nothing was selected" is exempt.
1304
+ #
1305
+ # The exemption keys on TESTS_SKIPPED ALONE, deliberately. The obvious
1306
+ # pairing -- `TESTS_SKIPPED && !TESTS_RAN_ANY` -- does not work, and the
1307
+ # probe that proved it is worth recording: on the reproduction above the
1308
+ # two flags read `skipped=true ran=true` at the same moment. TESTS_RAN_ANY
1309
+ # is set by the IaC arm when its run_tests prints "IaC tests not configured"
1310
+ # and returns 0 (gate-5-entry.sh:850-853, #760), because a runner DID
1311
+ # execute -- it just had nothing to test. So `!TESTS_RAN_ANY` is false for
1312
+ # any repo declaring iac, which is every repo using this gate the way this
1313
+ # one does. TESTS_SKIPPED is the precise signal: it is set only where the
1314
+ # test section concluded there was nothing to run.
1315
+ if [ "${TESTS_SKIPPED:-false}" = "true" ]; then
1316
+ echo "ℹ️ No tests were selected, so no coverage report was expected — skipping the coverage floor."
1317
+ elif [ "${PARTIAL_TEST_RUN:-false}" = "true" ]; then
1264
1318
  echo "⚠️ coverage/coverage-summary.json not found (subset test run) — not blocking."
1265
1319
  else
1266
1320
  echo "❌ BLOCKED - coverage/coverage-summary.json not found."
@@ -24,6 +24,13 @@
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
+ if ! gate_enabled 6; then
28
+ echo "⏭️ SKIPPED - Gate 6: Architecture & tech debt (not selected by XP_GATE_ONLY_GATE)"
29
+ GATE_6_STATUS="SKIP"
30
+ GATE_6_DETAIL="not_selected"
31
+ return 0
32
+ fi
33
+
27
34
  2>&1 echo ""
28
35
  2>&1 echo "→ Gate 6: Architecture & tech debt..."
29
36
  GATE_6_START=$(gate_start_ms)
@@ -50,6 +57,50 @@ else
50
57
  fi
51
58
  )
52
59
 
60
+ # ---------------------------------------------------------------------------
61
+ # Which tree does the verdict describe? The COMMIT, not the directory.
62
+ #
63
+ # `archlint diff <baseline>` makes its CURRENT argument default to "analyze the
64
+ # current working tree", so the pass/fail verdict included every uncommitted
65
+ # file in the checkout -- including files belonging to other work in progress.
66
+ # Measured 2026-11-11 in this repo: a worktree carrying 7 unstaged files put 217
67
+ # regressions / 122 files into the verdict, none of which the commit under
68
+ # review had touched. Two things then went wrong at once:
69
+ #
70
+ # 1. the block was attributed to the wrong author (a commit is blocked by
71
+ # someone else's editor buffer), and
72
+ # 2. the block message advised `archlint snapshot -o .architecture-baseline.json`
73
+ # -- correct for a genuine regression, but here it froze ANOTHER PERSON'S
74
+ # UNCOMMITTED WORK into the baseline as the accepted norm. Following the
75
+ # tool's own advice made the repo worse.
76
+ #
77
+ # A commit contains the index, so the index is the correct input. `git
78
+ # write-tree` + `git commit-tree` cheaply produce a commit object holding
79
+ # exactly the staged content; archlint accepts a git ref and analyzes a
80
+ # temporary worktree of it. The object is unreachable (no ref, no reflog entry)
81
+ # and is reclaimed by gc -- it never appears in the history being committed.
82
+ #
83
+ # Failure handling is deliberate: if the snapshot cannot be built, the gate
84
+ # falls back to the old worktree scan and SAYS SO, rather than skipping. A
85
+ # check that quietly stops checking is the #554/#562 lie; a wider-than-intended
86
+ # scope at least still checks something.
87
+ # ---------------------------------------------------------------------------
88
+ GATE_6_STAGED_SNAPSHOT=""
89
+ GATE_6_STAGED_SNAPSHOT_AVAILABLE=0
90
+
91
+ _gate6_snapshot() {
92
+ local _tree _commit
93
+ _tree=$(git -C "$PROJECT_ROOT" write-tree 2>/dev/null) || return 1
94
+ [ -n "$_tree" ] || return 1
95
+ # No parent: the content is all archlint reads, and a parentless commit
96
+ # cannot be confused with a real one if the object ever surfaces.
97
+ _commit=$(git -C "$PROJECT_ROOT" commit-tree "$_tree" -m "xp-gate: staged snapshot for Gate 6" 2>/dev/null) || return 1
98
+ [ -n "$_commit" ] || return 1
99
+ GATE_6_STAGED_SNAPSHOT="$_commit"
100
+ GATE_6_STAGED_SNAPSHOT_AVAILABLE=1
101
+ return 0
102
+ }
103
+
53
104
  # Check if architecture config exists (use $PROJECT_ROOT — hook may have cd'd to a subdir via ARCH-03)
54
105
  if [ -f "$PROJECT_ROOT/architecture.yaml" ] || [ -f "$PROJECT_ROOT/.architecturerc" ] || [ -f "$PROJECT_ROOT/.archlint.yaml" ]; then
55
106
  # #686: an `architecture.yaml` is NOT evidence that layer boundaries are
@@ -189,8 +240,48 @@ else
189
240
  ARCHLINT_OUTPUT=""
190
241
  ARCHLINT_EXIT=0
191
242
  elif [ -f "$PROJECT_ROOT/.architecture-baseline.json" ]; then
192
- ARCHLINT_OUTPUT=$(run_archlint diff .architecture-baseline.json --fail-on high 2>&1)
193
- ARCHLINT_EXIT=$?
243
+ # Scope the verdict to the COMMIT under review (see _gate6_snapshot).
244
+ if _gate6_snapshot; then
245
+ echo " 🔍 Scope: staged content (commit snapshot $(printf '%s' "$GATE_6_STAGED_SNAPSHOT" | cut -c1-8))"
246
+ ARCHLINT_OUTPUT=$(run_archlint diff .architecture-baseline.json "$GATE_6_STAGED_SNAPSHOT" --fail-on high 2>&1)
247
+ ARCHLINT_EXIT=$?
248
+ # #822: a snapshot that CANNOT BE ANALYSED is not a verdict.
249
+ #
250
+ # archlint analyzes a ref by creating a temporary worktree, and that
251
+ # step fails on its own: measured 2026-11-16, mid-commit, with other
252
+ # git processes holding the repo --
253
+ # error: Git command error: Failed to create worktree:
254
+ # fatal: Unable to create 'C:/Users/think/AppData/Local/Tem...'
255
+ # The exit code is non-zero for that, so the verdict branch below
256
+ # read it as "architecture violations detected" and printed advice to
257
+ # re-snapshot the baseline -- i.e. the tool never ran, and the gate
258
+ # blamed the author's code for it.
259
+ #
260
+ # Degrade to the worktree scan, exactly like a snapshot that could not
261
+ # be BUILT, and say so. Falling through to "violations" would be a
262
+ # false accusation; skipping silently would be a false pass.
263
+ #
264
+ # Matched on the MESSAGE, not on the exit code: measured 2026-11-16,
265
+ # archlint exits **1** for "Cannot resolve '<sha>'" and for
266
+ # "Failed to create worktree" alike, which is the same code it uses
267
+ # for real violations. There is no exit-code channel to tell "the
268
+ # analysis never ran" from "the analysis found problems", so the
269
+ # error text is the only usable signal. The project's exit>=2
270
+ # convention would be the right shape here, but archlint does not
271
+ # honour it and this gate cannot change that.
272
+ if printf '%s' "$ARCHLINT_OUTPUT" | grep -qE 'Failed to create worktree|Cannot resolve|Git command error'; then
273
+ echo " ⚠️ [WARN:SNAPSHOT_UNREADABLE] archlint could not materialise the snapshot worktree — retrying against the working tree."
274
+ ARCHLINT_OUTPUT=$(run_archlint diff .architecture-baseline.json --fail-on high 2>&1)
275
+ ARCHLINT_EXIT=$?
276
+ fi
277
+ else
278
+ # Snapshot unavailable (e.g. no git, or a read-only index). Fall back
279
+ # to the worktree scan rather than skipping: a wider scope still
280
+ # checks something, whereas a silent skip checks nothing.
281
+ echo " ⚠️ [WARN:SCOPED_TO_WORKTREE] could not snapshot the index — the verdict below covers the working tree, including uncommitted files that are NOT part of this commit."
282
+ ARCHLINT_OUTPUT=$(run_archlint diff .architecture-baseline.json --fail-on high 2>&1)
283
+ ARCHLINT_EXIT=$?
284
+ fi
194
285
  else
195
286
  ARCHLINT_OUTPUT=$(run_archlint scan . -f table --quiet 2>&1)
196
287
  ARCHLINT_EXIT=$?
@@ -26,6 +26,13 @@
26
26
  # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
27
27
  # here, and why sub-shell exits are deliberately left as `exit`.
28
28
  gate_7_run() {
29
+ if ! gate_enabled 7; then
30
+ echo "⏭️ SKIPPED - Gate 7: IaC security (not selected by XP_GATE_ONLY_GATE)"
31
+ GATE_7_STATUS="SKIP"
32
+ GATE_7_DETAIL="not_selected"
33
+ return 0
34
+ fi
35
+
29
36
  if any_changed_files_match "\.tf$" "\.tfvars$" "Dockerfile" "\.kube/" "\.ya?ml$"; then
30
37
  source "$GATE_DIR/gate-7.sh"
31
38
  else
@@ -24,6 +24,13 @@
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_8_run() {
27
+ if ! gate_enabled 8; then
28
+ echo "⏭️ SKIPPED - Gate 8: Secret scanning (not selected by XP_GATE_ONLY_GATE)"
29
+ GATE_8_STATUS="SKIP"
30
+ GATE_8_DETAIL="not_selected"
31
+ return 0
32
+ fi
33
+
27
34
  source "$GATE_DIR/gate-8.sh"
28
35
  return 0
29
36
  }
@@ -30,6 +30,13 @@ gate_9_run() {
30
30
  # project" -- which is exactly the silent-no-coverage path this sprint
31
31
  # removes. Verdict codes (mirror of the java.sh G1 contract):
32
32
  # 0=PASS 2=BLOCK(compile failed) 3=SKIP+WARN(reason printed)
33
+ if ! gate_enabled 9; then
34
+ echo "⏭️ SKIPPED - Gate 9: Build integrity (not selected by XP_GATE_ONLY_GATE)"
35
+ GATE_9_STATUS="SKIP"
36
+ GATE_9_DETAIL="not_selected"
37
+ return 0
38
+ fi
39
+
33
40
  resolve_build_integrity_timeout() {
34
41
  local file=".xp-gate/build-integrity-timeout" val=""
35
42
  if [ -f "$file" ]; then
package/hooks/post-commit CHANGED
@@ -38,6 +38,15 @@ head_commit="$(git rev-parse HEAD 2>/dev/null || true)"
38
38
  if [ -n "$toplevel" ] && [ -n "$head_commit" ] \
39
39
  && [ -f "$toplevel/src/npm-package/lib/gate-audit.ts" ]; then
40
40
  _pending="$toplevel/.xp-gate/audit.pending.jsonl"
41
+ # #810: `_flush` used to be defined ONLY inside the two tool branches below,
42
+ # while the drain loop at the bottom called it unconditionally. On a machine
43
+ # whose PATH carries neither node nor npx -- which is exactly when the audit
44
+ # cannot be flushed at all -- every commit (including each replayed commit of
45
+ # a rebase) printed `_flush: command not found` to stderr and silently lost
46
+ # the audit rows. The default makes "no usable runtime" an ordinary zero-row
47
+ # result instead of an error: the loop then exits after its two empty passes,
48
+ # which is the same observable behaviour as a flush that found nothing.
49
+ _flush() { echo 0; }
41
50
  if [ -f "$toplevel/node_modules/tsx/dist/cli.mjs" ] && command -v node >/dev/null 2>&1; then
42
51
  _flush() {
43
52
  node "$toplevel/node_modules/tsx/dist/cli.mjs" \
package/hooks/pre-push CHANGED
@@ -657,13 +657,18 @@ GATE_M_SKIP_KIND=""
657
657
  # copy of the order.
658
658
  HOOK_RESOLUTION_FILE="$SCRIPT_DIR/hook-module-resolution.sh"
659
659
 
660
+ # The `shellcheck source=` directive belongs in front of the whole `if`, not in
661
+ # front of one `elif` branch. ShellCheck can only attach a directive to a
662
+ # complete compound command; placed inside the branch it made the analyser
663
+ # abandon this `if` and every line after it -- 3 parse errors (SC1073/SC1123/
664
+ # SC1072) and ~990 lines of this hook that were never checked at all.
665
+ # shellcheck source=githooks/hook-module-resolution.sh
660
666
  if [ ! -f "$HOOK_RESOLUTION_FILE" ]; then
661
667
  echo "⚠️ hook-module-resolution.sh not found at $HOOK_RESOLUTION_FILE"
662
668
  echo " Run: xp-gate init (or reinstall the hooks)"
663
669
  echo "⚠️ Could not resolve adapter-common.sh. SKIP — Gate M."
664
670
  GATE_M_SKIP_REASON="hook-module-resolution.sh not found: $HOOK_RESOLUTION_FILE"
665
671
  GATE_M_SKIP_KIND="missing"
666
- # shellcheck source=githooks/hook-module-resolution.sh
667
672
  elif ! source "$HOOK_RESOLUTION_FILE" 2>/dev/null; then
668
673
  echo "⚠️ hook-module-resolution.sh is corrupt: $HOOK_RESOLUTION_FILE"
669
674
  echo " Run: node scripts/generate-hook-resolution.cjs (or reinstall)"
@@ -1189,7 +1194,11 @@ else
1189
1194
  # silently LOWER the density and weaken Gate M2. Equivalence with the old
1190
1195
  # loop was verified on 40 real test files plus overlap/edge fixtures (0
1191
1196
  # mismatches).
1192
- local _mock_content _mock_kw _mock_rest _mock_c
1197
+ # NOT `local`: this block runs at top level (inside a `for`, not a
1198
+ # function), where `local` is invalid (SC2168) -- bash prints
1199
+ # "local: can only be used in a function" and returns non-zero on every
1200
+ # iteration. The four names are file-scoped and each is assigned before
1201
+ # use below, so dropping the declaration changes no behaviour.
1193
1202
  _mock_content="$(cat "$test_file" 2>/dev/null)" || _mock_content=""
1194
1203
  MOCK_COUNT=0
1195
1204
  for _mock_kw in "jest.mock" "vi.mock" "jest.spyOn" "vi.spyOn" "jest.fn" "vi.fn" \
@@ -2,6 +2,6 @@
2
2
  "verdict": "PASS",
3
3
  "license_type": "MIT",
4
4
  "sha256": "0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5",
5
- "checked_at": "2026-11-14T23:06:48.655Z",
5
+ "checked_at": "2026-11-16T11:06:36.263Z",
6
6
  "source": "network"
7
7
  }
@@ -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.4.0
6
+ **Version:** 0.38.6.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Mock layering policy enforcement — Gate M3 of pre-push hook. Ensures integration tests use real implementations for internal dependencies, mock external dependencies, and annotate pending mocks with removal plans. Combines project scope scanning, mock decision engine, and per-file validation into a single pipeline.
@@ -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.4.0
6
+ **Version:** 0.38.6.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **Gate M** (incremental mutation testing) + **Gate M2** helpers (test-layer detection used by `src/mock-policy/`). Pre-push quality gate. TypeScript-only; uses Stryker.