@boyingliu01/xp-gate 0.38.125 → 0.38.126

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 (58) hide show
  1. package/adapters/gate-3.sh +34 -1
  2. package/adapters/gate-7.sh +15 -6
  3. package/bin/xp-gate.js +24 -0
  4. package/build-integrity/gate-10.ts +33 -8
  5. package/gate-3.sh +34 -1
  6. package/gate-registry.sh +3 -1
  7. package/hooks/deploy-manifest.sh +1 -0
  8. package/hooks/gate-3.sh +34 -1
  9. package/hooks/gate-entries/gate-1-entry.sh +35 -24
  10. package/hooks/gate-entries/gate-5-entry.sh +55 -19
  11. package/hooks/gate-entries/gate-6-entry.sh +15 -6
  12. package/hooks/gate-registry.sh +3 -1
  13. package/hooks/lib/gate-status.sh +164 -0
  14. package/hooks/lib/jscpd-run.sh +9 -1
  15. package/hooks/lib/native-path.sh +54 -0
  16. package/hooks/lib/toolchain-path.sh +38 -0
  17. package/hooks/pre-push +13 -4
  18. package/lib/__tests__/arch.test.js +7 -1
  19. package/lib/__tests__/audit-skip-reasons.test.ts +143 -0
  20. package/lib/__tests__/check-tools-list.test.js +155 -0
  21. package/lib/__tests__/doctor-tool-delegation.test.js +156 -0
  22. package/lib/__tests__/install-tools-repair.test.js +263 -0
  23. package/lib/__tests__/language-capability.test.js +27 -0
  24. package/lib/__tests__/tool-audit-collect.test.js +184 -0
  25. package/lib/__tests__/tool-audit-fixtures.js +87 -0
  26. package/lib/__tests__/tool-audit-latest.test.js +84 -0
  27. package/lib/__tests__/tool-audit.test.js +428 -0
  28. package/lib/deploy-manifest.js +1 -0
  29. package/lib/doctor-tool-checks.js +129 -0
  30. package/lib/doctor.js +15 -46
  31. package/lib/gate-audit.ts +80 -0
  32. package/lib/gate-runner.js +5 -0
  33. package/lib/language-capability-surfaces.js +70 -6
  34. package/lib/language-capability.js +3 -0
  35. package/lib/language-tools.js +409 -93
  36. package/lib/mattpocock-license-verdict.json +1 -1
  37. package/lib/tool-audit.js +729 -0
  38. package/package.json +1 -1
  39. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  40. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  41. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  42. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  43. package/plugins/dsh/package.json +1 -1
  44. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  45. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  46. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  47. package/plugins/dsh/src/skills.test.ts +9 -0
  48. package/plugins/opencode/package.json +1 -1
  49. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  50. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  51. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  52. package/plugins/qoder/plugin.json +1 -1
  53. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  54. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  55. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  56. package/skills/delphi-review/AGENTS.md +1 -1
  57. package/skills/sprint-flow/AGENTS.md +1 -1
  58. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -822,4 +822,37 @@ fi
822
822
  # Reading only CC_WARNINGS meant every ratchet block recorded issues_found=0 —
823
823
  # the gate failed while the journal claimed nothing was found.
824
824
  CC_ISSUES="${CC_VIOLATIONS:-${CC_WARNINGS:-0}}"
825
- record_gate_audit "gate-3" "complexity" "$GATE_3_STATUS" "$CC_ISSUES" "$GATE_3_START" "ccn_threshold=${CCN_THRESHOLD:-5}${GATE_3_DETAIL:+ $GATE_3_DETAIL}"
825
+ # Shared verdict helpers (append-with-de-duplication, strongest-verdict rule).
826
+ _GATE_STATUS_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" 2>/dev/null && pwd)/gate-status.sh"
827
+ if [ -r "$_GATE_STATUS_LIB" ]; then
828
+ # shellcheck source=/dev/null
829
+ . "$_GATE_STATUS_LIB"
830
+ fi
831
+ unset _GATE_STATUS_LIB
832
+
833
+ # The audit detail must say WHY when the gate skipped.
834
+ #
835
+ # This used to record only `ccn_threshold=<n>` plus whatever GATE_3_DETAIL held.
836
+ # GATE_3_DETAIL carries configuration and mode facts (mode=ratchet, verifier=
837
+ # MISSING), never a skip reason -- those live in GATE_3_REASON. Measured
838
+ # 2026-11-24: 26 of 34 gate-3 rows were SKIP and every one of them recorded
839
+ # "ccn_threshold=5", which is not a reason. A reader could not tell "no added
840
+ # PowerShell files" from "documentation project" from "the gate is broken".
841
+ #
842
+ # A SKIP with no reason is the exact defect githooks/AGENTS.md names, so the
843
+ # reason is now appended when the gate did not run.
844
+ _g3_audit_detail="ccn_threshold=${CCN_THRESHOLD:-5}"
845
+ if [ -n "${GATE_3_DETAIL:-}" ]; then
846
+ xp_gate_detail_append _g3_audit_detail "$GATE_3_DETAIL"
847
+ fi
848
+ if [ "$GATE_3_STATUS" = "SKIP" ]; then
849
+ if [ -n "${GATE_3_REASON:-}" ]; then
850
+ xp_gate_detail_append _g3_audit_detail "skip_reason=${GATE_3_REASON}"
851
+ else
852
+ # Fail loudly in the record rather than leaving a blank: an unexplained skip
853
+ # must be visible as a defect, not read as a normal run.
854
+ xp_gate_detail_append _g3_audit_detail "skip_reason=UNRECORDED"
855
+ fi
856
+ fi
857
+ record_gate_audit "gate-3" "complexity" "$GATE_3_STATUS" "$CC_ISSUES" "$GATE_3_START" "$_g3_audit_detail"
858
+ unset _g3_audit_detail
@@ -40,15 +40,24 @@ else
40
40
  # shellcheck disable=SC2034
41
41
  GATE_7_SCANNED_FILES=$(printf '%s\n' "$IAC_FILES" | sed -n '/./p' | wc -l | tr -d '[:space:]')
42
42
  # Run IaC adapter. Resolution follows the documented 3-tier convention
43
- # (adapter-common.sh): global ~/.config/xp-gate/adapters -> project
44
- # githooks/adapters -> script dir. The old cwd-only test silently SKIPped
45
- # IaC security in every consumer repo without an in-repo githooks/ dir,
46
- # even with the adapter installed globally (e2e sweep 2026-10-17; pinned
47
- # by __tests__/gate-7-adapter-resolution.test.bats).
43
+ # (adapter-common.sh HOOK_ADAPTER_DIR_TIERS), which is PROJECT FIRST:
44
+ # project githooks/adapters -> global ~/.config/xp-gate/adapters -> script dir.
45
+ #
46
+ # This list used to be in the OPPOSITE order while the comment above it already
47
+ # described the correct one, so the code and its own documentation disagreed and
48
+ # only the code ran. Measured consequence: a repo carrying its own
49
+ # githooks/adapters/iac.sh was bypassed outright whenever a global install
50
+ # existed -- the probe printed "fake checkov ran" instead of the project
51
+ # adapter. That is the "stale adapter overrides fresh" trap AGENTS.md warns
52
+ # about, and the damage is not that a stale copy is older: it silently changes
53
+ # the VERDICT, so a repository cannot decide how it is checked.
54
+ #
55
+ # The global tier still exists and is still reachable -- it is the FALLBACK now
56
+ # (pinned by tests 1 and 3 of __tests__/gate-7-adapter-resolution.test.bats).
48
57
  IAC_ADAPTER=""
49
58
  for _candidate in \
50
- "$HOME/.config/xp-gate/adapters/iac.sh" \
51
59
  "githooks/adapters/iac.sh" \
60
+ "$HOME/.config/xp-gate/adapters/iac.sh" \
52
61
  "${SCRIPT_DIR:-}/adapters/iac.sh"; do
53
62
  if [ -n "$_candidate" ] && [ -f "$_candidate" ]; then
54
63
  IAC_ADAPTER="$_candidate"
package/bin/xp-gate.js CHANGED
@@ -671,12 +671,36 @@ function handleAuditStats(auditPath) {
671
671
  }
672
672
  printStatsTable(stats);
673
673
  printAnomalies(evalGateAuditModule('m.computeAnomalies()'));
674
+ printSkipReasons(evalGateAuditModule('m.computeSkipReasons()'));
674
675
  } catch (err) {
675
676
  console.error('Error computing stats:', err.message);
676
677
  process.exit(1);
677
678
  }
678
679
  }
679
680
 
681
+ /**
682
+ * Print WHY gates skipped, grouped by reason.
683
+ *
684
+ * The per-gate table above shows an execution rate; it cannot show whether a
685
+ * gate that never ran was healthy ("nothing to check"), misconfigured
686
+ * ("checker_missing") or broken. Those call for different actions and used to
687
+ * look identical. Reasons come from the `detail` field the gates already write.
688
+ */
689
+ function printSkipReasons(buckets) {
690
+ console.log('');
691
+ if (!buckets || buckets.length === 0) {
692
+ console.log('Skip reasons : none recorded (no SKIP rows)');
693
+ return;
694
+ }
695
+ const total = buckets.reduce((n, b) => n + b.count, 0);
696
+ console.log(`Skip reasons (${total} SKIP row(s)):`);
697
+ for (const b of buckets) {
698
+ const gates = b.gates.map((g) => `${g.gate_id}×${g.count}`).join(', ');
699
+ console.log(` ${String(b.count).padStart(4)} ${b.reason}`);
700
+ if (gates) console.log(` ${gates}`);
701
+ }
702
+ }
703
+
680
704
  /**
681
705
  * Print the audit-health summary. `total` is the ledger-integrity number CI
682
706
  * gates on (xp-gate audit --check); the components explain where it comes from.
@@ -139,6 +139,38 @@ function compileFailureMessage(err: ExecFailure): string {
139
139
  }
140
140
 
141
141
  /** Reasons tsc cannot run at all; null means it is usable. */
142
+ /**
143
+ * The placeholder `npx tsc` runs when TypeScript is installed nowhere. Measured
144
+ * 2026-11-23: it prints this banner and **exits 0**, so an exit-code-only probe
145
+ * calls it a working tsc. The probe succeeds while its evidence says the
146
+ * opposite -- this repo's recurring defect shape.
147
+ */
148
+ const NPX_TSC_STUB_MARKER = 'This is not the tsc command you are looking for';
149
+
150
+ /** Did the npx fallback run npm's placeholder? Only it can, so a resolved tsc
151
+ * script is never rejected for printing the phrase by coincidence. */
152
+ function isNpxTscPlaceholder(resolvedTsc: string | null, result: { stdout?: unknown; stderr?: unknown }): boolean {
153
+ if (resolvedTsc !== null) return false;
154
+ return `${String(result.stdout || '')}\n${String(result.stderr || '')}`.includes(NPX_TSC_STUB_MARKER);
155
+ }
156
+
157
+ /** Probe whether tsc works: a skip REASON, or null when usable. Split out of
158
+ * `tscSkipReason` because inline it measured CCN 3 -> 5 against the baseline of
159
+ * 3 -- the ratchet was right that this is two jobs. */
160
+ async function probeTscUsability(projectRoot: string, resolvedTsc: string | null): Promise<string | null> {
161
+ let result: { stdout?: unknown; stderr?: unknown };
162
+ try {
163
+ const probe = tscProbeInvocation(projectRoot, resolvedTsc);
164
+ result = await execFileAsync(probe.cmd, probe.args, probe.opts);
165
+ } catch {
166
+ return 'tsc is not available on PATH';
167
+ }
168
+ if (isNpxTscPlaceholder(resolvedTsc, result)) {
169
+ return 'tsc is not installed (npx resolved to its placeholder)';
170
+ }
171
+ return null;
172
+ }
173
+
142
174
  const tscSkipReason = async (projectRoot: string): Promise<string | null> => {
143
175
  const tsconfigPath = path.join(projectRoot, 'tsconfig.json');
144
176
  try {
@@ -146,14 +178,7 @@ const tscSkipReason = async (projectRoot: string): Promise<string | null> => {
146
178
  } catch {
147
179
  return 'No tsconfig.json found in project root';
148
180
  }
149
- const resolvedTsc = findTscBinary(projectRoot);
150
- try {
151
- const probe = tscProbeInvocation(projectRoot, resolvedTsc);
152
- await execFileAsync(probe.cmd, probe.args, probe.opts);
153
- } catch {
154
- return 'tsc is not available on PATH';
155
- }
156
- return null;
181
+ return probeTscUsability(projectRoot, findTscBinary(projectRoot));
157
182
  };
158
183
 
159
184
  /** Run the compile itself and map its failure modes onto gate statuses. */
package/gate-3.sh CHANGED
@@ -822,4 +822,37 @@ fi
822
822
  # Reading only CC_WARNINGS meant every ratchet block recorded issues_found=0 —
823
823
  # the gate failed while the journal claimed nothing was found.
824
824
  CC_ISSUES="${CC_VIOLATIONS:-${CC_WARNINGS:-0}}"
825
- record_gate_audit "gate-3" "complexity" "$GATE_3_STATUS" "$CC_ISSUES" "$GATE_3_START" "ccn_threshold=${CCN_THRESHOLD:-5}${GATE_3_DETAIL:+ $GATE_3_DETAIL}"
825
+ # Shared verdict helpers (append-with-de-duplication, strongest-verdict rule).
826
+ _GATE_STATUS_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" 2>/dev/null && pwd)/gate-status.sh"
827
+ if [ -r "$_GATE_STATUS_LIB" ]; then
828
+ # shellcheck source=/dev/null
829
+ . "$_GATE_STATUS_LIB"
830
+ fi
831
+ unset _GATE_STATUS_LIB
832
+
833
+ # The audit detail must say WHY when the gate skipped.
834
+ #
835
+ # This used to record only `ccn_threshold=<n>` plus whatever GATE_3_DETAIL held.
836
+ # GATE_3_DETAIL carries configuration and mode facts (mode=ratchet, verifier=
837
+ # MISSING), never a skip reason -- those live in GATE_3_REASON. Measured
838
+ # 2026-11-24: 26 of 34 gate-3 rows were SKIP and every one of them recorded
839
+ # "ccn_threshold=5", which is not a reason. A reader could not tell "no added
840
+ # PowerShell files" from "documentation project" from "the gate is broken".
841
+ #
842
+ # A SKIP with no reason is the exact defect githooks/AGENTS.md names, so the
843
+ # reason is now appended when the gate did not run.
844
+ _g3_audit_detail="ccn_threshold=${CCN_THRESHOLD:-5}"
845
+ if [ -n "${GATE_3_DETAIL:-}" ]; then
846
+ xp_gate_detail_append _g3_audit_detail "$GATE_3_DETAIL"
847
+ fi
848
+ if [ "$GATE_3_STATUS" = "SKIP" ]; then
849
+ if [ -n "${GATE_3_REASON:-}" ]; then
850
+ xp_gate_detail_append _g3_audit_detail "skip_reason=${GATE_3_REASON}"
851
+ else
852
+ # Fail loudly in the record rather than leaving a blank: an unexplained skip
853
+ # must be visible as a defect, not read as a normal run.
854
+ xp_gate_detail_append _g3_audit_detail "skip_reason=UNRECORDED"
855
+ fi
856
+ fi
857
+ record_gate_audit "gate-3" "complexity" "$GATE_3_STATUS" "$CC_ISSUES" "$GATE_3_START" "$_g3_audit_detail"
858
+ unset _g3_audit_detail
package/gate-registry.sh CHANGED
@@ -54,7 +54,7 @@
54
54
  # already reads.
55
55
  #
56
56
  # Numbers are POSITIONAL LABELS, never identities, and nothing here orders them
57
- # numerically — pre-push numbers are strings (M, M2, ML, UI, MW, S). Do not add
57
+ # numerically — pre-push numbers are strings (M, ML, UI, MW, S). Do not add
58
58
  # `-gt`/`-lt`/`$((` logic against this field;
59
59
  # scripts/__tests__/gate-identity-cross-surface.test.cjs greps for it.
60
60
  #
@@ -94,6 +94,8 @@ GATE_REGISTRY_ROWS=(
94
94
  # deciding its own execution order and skip semantics. Before this the
95
95
  # registry knew nothing about half the gates this project runs (#769).
96
96
  "mutation|M|inline|YES|pre-push"
97
+ "mock-layering|ML|inline|YES|pre-push"
98
+ "ui-sprint|UI|inline|YES|pre-push"
97
99
  "code-walkthrough|MW|inline|YES|pre-push"
98
100
  "prepush-sprint|S|sprint-gate.sh|YES|pre-push"
99
101
  )
@@ -86,6 +86,7 @@ DEPLOY_MODULE_FILES=(
86
86
  'lib/file-classifier.sh'
87
87
  'lib/gate-12-blob-scan.awk'
88
88
  'lib/gate-5c-alignment.sh'
89
+ 'lib/gate-status.sh'
89
90
  'lib/java-test-selection.sh'
90
91
  'lib/jscpd-run.sh'
91
92
  'lib/layer-baseline.cjs'
package/hooks/gate-3.sh CHANGED
@@ -822,4 +822,37 @@ fi
822
822
  # Reading only CC_WARNINGS meant every ratchet block recorded issues_found=0 —
823
823
  # the gate failed while the journal claimed nothing was found.
824
824
  CC_ISSUES="${CC_VIOLATIONS:-${CC_WARNINGS:-0}}"
825
- record_gate_audit "gate-3" "complexity" "$GATE_3_STATUS" "$CC_ISSUES" "$GATE_3_START" "ccn_threshold=${CCN_THRESHOLD:-5}${GATE_3_DETAIL:+ $GATE_3_DETAIL}"
825
+ # Shared verdict helpers (append-with-de-duplication, strongest-verdict rule).
826
+ _GATE_STATUS_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" 2>/dev/null && pwd)/gate-status.sh"
827
+ if [ -r "$_GATE_STATUS_LIB" ]; then
828
+ # shellcheck source=/dev/null
829
+ . "$_GATE_STATUS_LIB"
830
+ fi
831
+ unset _GATE_STATUS_LIB
832
+
833
+ # The audit detail must say WHY when the gate skipped.
834
+ #
835
+ # This used to record only `ccn_threshold=<n>` plus whatever GATE_3_DETAIL held.
836
+ # GATE_3_DETAIL carries configuration and mode facts (mode=ratchet, verifier=
837
+ # MISSING), never a skip reason -- those live in GATE_3_REASON. Measured
838
+ # 2026-11-24: 26 of 34 gate-3 rows were SKIP and every one of them recorded
839
+ # "ccn_threshold=5", which is not a reason. A reader could not tell "no added
840
+ # PowerShell files" from "documentation project" from "the gate is broken".
841
+ #
842
+ # A SKIP with no reason is the exact defect githooks/AGENTS.md names, so the
843
+ # reason is now appended when the gate did not run.
844
+ _g3_audit_detail="ccn_threshold=${CCN_THRESHOLD:-5}"
845
+ if [ -n "${GATE_3_DETAIL:-}" ]; then
846
+ xp_gate_detail_append _g3_audit_detail "$GATE_3_DETAIL"
847
+ fi
848
+ if [ "$GATE_3_STATUS" = "SKIP" ]; then
849
+ if [ -n "${GATE_3_REASON:-}" ]; then
850
+ xp_gate_detail_append _g3_audit_detail "skip_reason=${GATE_3_REASON}"
851
+ else
852
+ # Fail loudly in the record rather than leaving a blank: an unexplained skip
853
+ # must be visible as a defect, not read as a normal run.
854
+ xp_gate_detail_append _g3_audit_detail "skip_reason=UNRECORDED"
855
+ fi
856
+ fi
857
+ record_gate_audit "gate-3" "complexity" "$GATE_3_STATUS" "$CC_ISSUES" "$GATE_3_START" "$_g3_audit_detail"
858
+ unset _g3_audit_detail
@@ -51,6 +51,17 @@ _shell_changed_files() {
51
51
  # Gate body. `return` is used instead of `exit` so the driver decides to
52
52
  # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
53
53
  # here, and why sub-shell exits are deliberately left as `exit`.
54
+ # Shared verdict rules: a gate that walks several languages carries the
55
+ # STRONGEST verdict any of them produced, never the last one written.
56
+ # Measured 2026-11-24: gate-1 recorded 0 PASS and 19 WARN, every warning being
57
+ # "PSSA module not installed" -- so an eslint pass could never be the verdict.
58
+ _GATE_STATUS_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" && pwd)/gate-status.sh"
59
+ if [ -r "$_GATE_STATUS_LIB" ]; then
60
+ # shellcheck source=/dev/null
61
+ . "$_GATE_STATUS_LIB"
62
+ fi
63
+ unset _GATE_STATUS_LIB
64
+
54
65
  gate_1_run() {
55
66
  2>&1 echo ""
56
67
  2>&1 echo "→ Gate 1: Code Quality (static analysis + linting)..."
@@ -299,7 +310,7 @@ else
299
310
  # `── Checking python ──`, while the run reported success. Record the
300
311
  # skip and let the loop continue.
301
312
  GATE_1_STATUS="SKIP"
302
- GATE_1_DETAIL="typescript: biome not installed"
313
+ xp_gate_detail_append GATE_1_DETAIL "typescript: biome not installed"
303
314
  continue
304
315
  fi
305
316
  if [ "$BIOME_STATUS" -ne 0 ]; then
@@ -392,7 +403,7 @@ else
392
403
  # journal recorded "passed" for a check that never ran. The Java branch ten
393
404
  # lines away sets WARN for the same situation; this is the same decision.
394
405
  GATE_1_STATUS="SKIP"
395
- GATE_1_DETAIL="python: ruff not installed"
406
+ xp_gate_detail_append GATE_1_DETAIL "python: ruff not installed"
396
407
  else
397
408
  # Run Ruff (includes syntax check, linting)
398
409
  echo "Running Ruff linting (syntax + lint)..."
@@ -567,7 +578,7 @@ else
567
578
  # driving gate_1_run with golangci-lint absent: the skip printed and
568
579
  # GATE_1_STATUS stayed "PASS" with an empty DETAIL.
569
580
  GATE_1_STATUS="SKIP"
570
- GATE_1_DETAIL="go: golangci-lint not installed"
581
+ xp_gate_detail_append GATE_1_DETAIL "go: golangci-lint not installed"
571
582
  else
572
583
  # #534: run golangci-lint over ONLY the staged .go files (incremental),
573
584
  # not the whole repo. `golangci-lint run` with no args scans every package
@@ -702,8 +713,8 @@ else
702
713
  ADAPTER_FILE=$(resolve_adapter_path "$CURRENT_LANG")
703
714
  if [ -z "$ADAPTER_FILE" ] || ! source "$ADAPTER_FILE" 2>/dev/null; then
704
715
  echo "⚠️ WARN - Java adapter not found (code quality NOT verified)"
705
- GATE_1_STATUS="WARN"
706
- GATE_1_DETAIL="java: adapter missing"
716
+ xp_gate_status_escalate GATE_1_STATUS "WARN"
717
+ xp_gate_detail_append GATE_1_DETAIL "java: adapter missing"
707
718
  else
708
719
  JAVA_G1_EXIT=0
709
720
  # `|| JAVA_G1_EXIT=$?` (not a bare assignment): under a set -e consumer a
@@ -736,13 +747,13 @@ else
736
747
  ;;
737
748
  3)
738
749
  echo "⚠️ WARN - Java code quality NOT verified (engine unavailable or downgraded)"
739
- GATE_1_STATUS="WARN"
740
- GATE_1_DETAIL="java: ${JAVA_G1_REASON:-unavailable (warn)}"
750
+ xp_gate_status_escalate GATE_1_STATUS "WARN"
751
+ xp_gate_detail_append GATE_1_DETAIL "java: ${JAVA_G1_REASON:-unavailable (warn)}"
741
752
  ;;
742
753
  *)
743
754
  echo "⚠️ WARN - Java code quality NOT verified (unexpected verdict $JAVA_G1_EXIT)"
744
- GATE_1_STATUS="WARN"
745
- GATE_1_DETAIL="java: unexpected verdict $JAVA_G1_EXIT"
755
+ xp_gate_status_escalate GATE_1_STATUS "WARN"
756
+ xp_gate_detail_append GATE_1_DETAIL "java: unexpected verdict $JAVA_G1_EXIT"
746
757
  ;;
747
758
  esac
748
759
  fi
@@ -758,8 +769,8 @@ else
758
769
  POWERSHELL_ADAPTER=$(resolve_adapter_path "powershell")
759
770
  if [ -z "$POWERSHELL_ADAPTER" ]; then
760
771
  echo "⚠️ WARN - PowerShell adapter not found (code quality NOT verified)"
761
- GATE_1_STATUS="WARN"
762
- GATE_1_DETAIL="powershell: adapter missing"
772
+ xp_gate_status_escalate GATE_1_STATUS "WARN"
773
+ xp_gate_detail_append GATE_1_DETAIL "powershell: adapter missing"
763
774
  else
764
775
  PS_G1_EXIT=0
765
776
  # Subshell: reasons cross as `XP_G1_REASON: ...` stdout lines, exactly
@@ -789,24 +800,24 @@ else
789
800
  echo " Rules: $PS_RULES"
790
801
  fi
791
802
  GATE_1_STATUS="BLOCK"
792
- GATE_1_DETAIL="powershell: PSScriptAnalyzer findings${PS_RULES:+ ($PS_RULES)}"
803
+ xp_gate_detail_append GATE_1_DETAIL "powershell: PSScriptAnalyzer findings${PS_RULES:+ ($PS_RULES)}"
793
804
  return 1
794
805
  ;;
795
806
  2)
796
807
  echo "❌ BLOCKED - PowerShell static analysis unusable (fail-closed): ${PS_G1_REASON:-unknown}"
797
808
  GATE_1_STATUS="BLOCK"
798
- GATE_1_DETAIL="powershell: ${PS_G1_REASON:-unusable}"
809
+ xp_gate_detail_append GATE_1_DETAIL "powershell: ${PS_G1_REASON:-unusable}"
799
810
  return 1
800
811
  ;;
801
812
  3)
802
813
  echo "⚠️ WARN - PowerShell code quality NOT verified: ${PS_G1_REASON:-engine unavailable}"
803
- GATE_1_STATUS="WARN"
804
- GATE_1_DETAIL="powershell: ${PS_G1_REASON:-engine unavailable}"
814
+ xp_gate_status_escalate GATE_1_STATUS "WARN"
815
+ xp_gate_detail_append GATE_1_DETAIL "powershell: ${PS_G1_REASON:-engine unavailable}"
805
816
  ;;
806
817
  *)
807
818
  echo "⚠️ WARN - PowerShell code quality NOT verified (unexpected verdict $PS_G1_EXIT)"
808
- GATE_1_STATUS="WARN"
809
- GATE_1_DETAIL="powershell: unexpected verdict $PS_G1_EXIT"
819
+ xp_gate_status_escalate GATE_1_STATUS "WARN"
820
+ xp_gate_detail_append GATE_1_DETAIL "powershell: unexpected verdict $PS_G1_EXIT"
810
821
  ;;
811
822
  esac
812
823
  fi
@@ -934,7 +945,7 @@ else
934
945
  1)
935
946
  echo "❌ BLOCKED - ${CURRENT_LANG} code quality violations (fix or add suppressions)"
936
947
  GATE_1_STATUS="BLOCK"
937
- GATE_1_DETAIL="${CURRENT_LANG}: analyzer findings"
948
+ xp_gate_detail_append GATE_1_DETAIL "${CURRENT_LANG}: analyzer findings"
938
949
  return 1
939
950
  ;;
940
951
  2)
@@ -947,18 +958,18 @@ else
947
958
  echo " A tool that could not run is not a clean tree. Install the toolchain,"
948
959
  echo " or set the adapter's documented escape valve if you accept the risk."
949
960
  GATE_1_STATUS="BLOCK"
950
- GATE_1_DETAIL="${CURRENT_LANG}: ${G1A_REASON:-unusable}"
961
+ xp_gate_detail_append GATE_1_DETAIL "${CURRENT_LANG}: ${G1A_REASON:-unusable}"
951
962
  return 1
952
963
  ;;
953
964
  3)
954
965
  echo "⚠️ WARN - ${CURRENT_LANG} code quality NOT verified: ${G1A_REASON:-adapter reported a non-blocking skip}"
955
- GATE_1_STATUS="WARN"
956
- GATE_1_DETAIL="${CURRENT_LANG}: ${G1A_REASON:-unavailable (warn)}"
966
+ xp_gate_status_escalate GATE_1_STATUS "WARN"
967
+ xp_gate_detail_append GATE_1_DETAIL "${CURRENT_LANG}: ${G1A_REASON:-unavailable (warn)}"
957
968
  ;;
958
969
  *)
959
970
  echo "⚠️ WARN - ${CURRENT_LANG} code quality NOT verified (unexpected verdict $G1_VERDICT)"
960
- GATE_1_STATUS="WARN"
961
- GATE_1_DETAIL="${CURRENT_LANG}: unexpected verdict $G1_VERDICT"
971
+ xp_gate_status_escalate GATE_1_STATUS "WARN"
972
+ xp_gate_detail_append GATE_1_DETAIL "${CURRENT_LANG}: unexpected verdict $G1_VERDICT"
962
973
  ;;
963
974
  esac
964
975
  else
@@ -969,7 +980,7 @@ else
969
980
  # journal. This is the arm that covers every language xp-gate has no
970
981
  # adapter for, so it was the single widest inherited-PASS hole in Gate 1.
971
982
  GATE_1_STATUS="SKIP"
972
- GATE_1_DETAIL="${CURRENT_LANG}: no adapter"
983
+ xp_gate_detail_append GATE_1_DETAIL "${CURRENT_LANG}: no adapter"
973
984
  fi
974
985
  ;;
975
986
  esac
@@ -165,6 +165,16 @@ _gate5_coverage_usable() {
165
165
  # stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
166
166
  # here, and why sub-shell exits are deliberately left as `exit`.
167
167
  gate_5_run() {
168
+ # Shared verdict rules: strongest verdict wins, details append.
169
+ # Loaded here because gate-5 walks PROJECT_LANGS and used to let the last
170
+ # language replace the reason of an earlier one (see githooks/lib/gate-status.sh).
171
+ _GATE_STATUS_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" && pwd)/gate-status.sh"
172
+ if [ -r "$_GATE_STATUS_LIB" ]; then
173
+ # shellcheck source=/dev/null
174
+ . "$_GATE_STATUS_LIB"
175
+ fi
176
+ unset _GATE_STATUS_LIB
177
+
168
178
  # GATE 5: Tests & Coverage Combined (Combines Old Gates 3 - Tests and 4 - Coverage)
169
179
  # Uses adapter system to run tests + coverage for language
170
180
  #
@@ -189,12 +199,12 @@ GATE_5_STATUS=""
189
199
  if ! gate_enabled 5; then
190
200
  echo "⏭️ SKIPPED - Gate 5: Tests & coverage (not selected by XP_GATE_ONLY_GATE)"
191
201
  GATE_5_STATUS="SKIP"
192
- GATE_5_DETAIL="not_selected"
202
+ xp_gate_detail_append GATE_5_DETAIL "not_selected"
193
203
 
194
204
  elif [ "$PROJECT_LANG" = "documentation-only" ] || [ "$DOCS_ONLY_COMMIT" = true ]; then
195
205
  echo "⏭️ SKIPPED - Tests & coverage (documentation-only commit — no code changed to test)."
196
206
  GATE_5_STATUS="SKIP"
197
- GATE_5_DETAIL="docs_only_change"
207
+ xp_gate_detail_append GATE_5_DETAIL "docs_only_change"
198
208
 
199
209
  else
200
210
  # ========================================================================
@@ -817,7 +827,7 @@ else
817
827
  TESTS_EXIT_CODE=0
818
828
  TESTS_SKIPPED=true
819
829
  GATE_5_STATUS="SKIP"
820
- GATE_5_DETAIL="no_code_files_changed"
830
+ xp_gate_detail_append GATE_5_DETAIL "no_code_files_changed"
821
831
  GATE_5_END=$(gate_start_ms)
822
832
  GATE_5_ELAPSED=$((GATE_5_END - GATE_5_START))
823
833
  echo " ⏱️ Gate 5: ${GATE_5_ELAPSED}ms (skipped — no code changes)"
@@ -1055,7 +1065,7 @@ else
1055
1065
  _delegated_to="$(adapter_test_delegation_target)"
1056
1066
  echo "ℹ️ ${CURRENT_LANG}: tests run in ${_delegated_to}, not at commit time."
1057
1067
  echo " Not checked by this gate -- verified on push/PR instead."
1058
- GATE_5_DETAIL="${GATE_5_DETAIL:+${GATE_5_DETAIL}; }${CURRENT_LANG}: tests delegated to ${_delegated_to}"
1068
+ xp_gate_detail_append GATE_5_DETAIL "${CURRENT_LANG}: tests delegated to ${_delegated_to}"
1059
1069
  DELEGATED_LANGS="${DELEGATED_LANGS:+${DELEGATED_LANGS} }${CURRENT_LANG}"
1060
1070
  elif adapter_declares_coverage_runs_tests; then
1061
1071
  echo "ℹ️ ${CURRENT_LANG}: coverage run includes the tests — deferring test execution to a single pass."
@@ -1075,7 +1085,7 @@ else
1075
1085
  # Deliberately NOT appended to DELEGATED_LANGS: that variable is reported
1076
1086
  # further down as "tests delegated to CI", and a coverage-run deferral is
1077
1087
  # not a CI delegation. Reusing it would relabel this case as the other.
1078
- GATE_5_DETAIL="${GATE_5_DETAIL:+${GATE_5_DETAIL}; }${CURRENT_LANG}: tests deferred to the coverage run"
1088
+ xp_gate_detail_append GATE_5_DETAIL "${CURRENT_LANG}: tests deferred to the coverage run"
1079
1089
  else
1080
1090
  TESTS_OUTPUT=$(run_without_git_context run_tests 2>&1)
1081
1091
  TESTS_EXIT_CODE=$?
@@ -1475,7 +1485,7 @@ else
1475
1485
  # empty -- and an empty status renders as SKIP, so the summary line
1476
1486
  # one inch below reported a skip for a commit that was blocked.
1477
1487
  GATE_5_STATUS="BLOCK"
1478
- GATE_5_DETAIL="coverage_below_floor: typescript coverage under the 80% floor"
1488
+ xp_gate_detail_append GATE_5_DETAIL "coverage_below_floor: typescript coverage under the 80% floor"
1479
1489
  echo "❌ BLOCKED - TypeScript coverage ${COVERAGE_PERCENT}% below ${COVERAGE_THRESHOLD:-80}% threshold"
1480
1490
  return 1
1481
1491
  fi
@@ -1620,7 +1630,7 @@ else
1620
1630
  # gate's status variable, so the assignment belongs here, at the call site.
1621
1631
  if ! enforce_python_coverage; then
1622
1632
  GATE_5_STATUS="BLOCK"
1623
- GATE_5_DETAIL="coverage_below_floor: python coverage under the 80% floor"
1633
+ xp_gate_detail_append GATE_5_DETAIL "coverage_below_floor: python coverage under the 80% floor"
1624
1634
  return 1
1625
1635
  fi
1626
1636
  ;;
@@ -1707,7 +1717,7 @@ else
1707
1717
  # empty -- and an empty status renders as SKIP, so the summary line
1708
1718
  # one inch below reported a skip for a commit that was blocked.
1709
1719
  GATE_5_STATUS="BLOCK"
1710
- GATE_5_DETAIL="coverage_below_floor: java coverage under the 80% floor"
1720
+ xp_gate_detail_append GATE_5_DETAIL "coverage_below_floor: java coverage under the 80% floor"
1711
1721
  echo "❌ BLOCKED - Java coverage ${COVERAGE_ROUNDED}% below ${COVERAGE_THRESHOLD:-80}% threshold"
1712
1722
  return 1
1713
1723
  fi
@@ -1792,7 +1802,7 @@ else
1792
1802
  # Record the verdict as well as printing it -- see the typescript branch
1793
1803
  # above for the measurement. An unassigned status renders as SKIP.
1794
1804
  GATE_5_STATUS="BLOCK"
1795
- GATE_5_DETAIL="coverage_below_floor: flutter/dart coverage under the 80% floor"
1805
+ xp_gate_detail_append GATE_5_DETAIL "coverage_below_floor: flutter/dart coverage under the 80% floor"
1796
1806
  echo "❌ BLOCKED - Flutter/Dart coverage ${COVERAGE_PERCENT}% below ${COVERAGE_THRESHOLD:-80}% threshold"
1797
1807
  return 1
1798
1808
  fi
@@ -1841,10 +1851,27 @@ else
1841
1851
  echo "⏭️ SKIPPED - PowerShell coverage: no Pester tests in this project (*.Tests.ps1)"
1842
1852
  echo " Nothing can produce coverage.xml here, so the floor is not applicable."
1843
1853
  echo " This is NOT a pass: add Pester tests and coverage is enforced again."
1844
- if [ -n "$(printf '%s' "${GATE_5_STATUS:-}")" ] && [ "$GATE_5_STATUS" = "PASS" ]; then
1854
+ # A language with nothing to measure must not speak for the ones that
1855
+ # DID measure something. Gate 5 walks PROJECT_LANGS in config order
1856
+ # (typescript, shell, powershell, iac), and this branch used to demote a
1857
+ # PASS that a previous language had genuinely produced:
1858
+ #
1859
+ # if [ "$GATE_5_STATUS" = "PASS" ]; then GATE_5_STATUS="SKIP"; fi
1860
+ #
1861
+ # Measured 2026-11-24 across 343 audit records: gate-5 has 0 PASS and 21
1862
+ # SKIP, all 13 explained skips reading "powershell: no Pester tests", in
1863
+ # a repo carrying thousands of TypeScript tests. The gate never enforced
1864
+ # anything -- because the last language to have nothing to do overwrote
1865
+ # the verdict of the one that did.
1866
+ #
1867
+ # The downgrade is therefore removed. When powershell is the ONLY
1868
+ # language that reported (nothing ran before it), the status is still
1869
+ # set below, so the "nothing to measure" state keeps its own verdict and
1870
+ # its own reason -- it simply may no longer erase someone else's.
1871
+ if [ -z "${GATE_5_STATUS:-}" ]; then
1845
1872
  GATE_5_STATUS="SKIP"
1846
1873
  fi
1847
- GATE_5_DETAIL="powershell: no Pester tests (coverage not applicable)"
1874
+ xp_gate_detail_append GATE_5_DETAIL "powershell: no Pester tests (coverage not applicable)"
1848
1875
  COVERAGE_ENFORCED=false
1849
1876
  elif [ -f "coverage.xml" ]; then
1850
1877
  # The threshold is passed INTO node: the verdict used to be computed
@@ -1888,7 +1915,7 @@ else
1888
1915
  # Record the verdict as well as printing it -- see the typescript branch
1889
1916
  # above for the measurement. An unassigned status renders as SKIP.
1890
1917
  GATE_5_STATUS="BLOCK"
1891
- GATE_5_DETAIL="coverage_below_floor: powershell coverage under the 80% floor"
1918
+ xp_gate_detail_append GATE_5_DETAIL "coverage_below_floor: powershell coverage under the 80% floor"
1892
1919
  echo "❌ BLOCKED - PowerShell coverage ${COVERAGE_PERCENT}% below ${COVERAGE_THRESHOLD:-80}% threshold"
1893
1920
  return 1
1894
1921
  fi
@@ -1942,7 +1969,7 @@ else
1942
1969
  echo " Nothing can produce a coverage report here, so the floor is not applicable."
1943
1970
  echo " This is NOT a pass: add tests and coverage is enforced again."
1944
1971
  GATE_5_STATUS="SKIP"
1945
- GATE_5_DETAIL="${CURRENT_LANG}: no test sources (coverage not applicable)"
1972
+ xp_gate_detail_append GATE_5_DETAIL "${CURRENT_LANG}: no test sources (coverage not applicable)"
1946
1973
  COVERAGE_ENFORCED=false
1947
1974
  else
1948
1975
  COVERAGE_ENFORCED=true
@@ -2048,7 +2075,7 @@ else
2048
2075
  # verdict that only reaches the console is a verdict the journal
2049
2076
  # contradicts.
2050
2077
  GATE_5_STATUS="BLOCK"
2051
- GATE_5_DETAIL="coverage_below_floor: ${CURRENT_LANG} ${COVERAGE_PERCENT}% < ${COVERAGE_THRESHOLD:-80}%"
2078
+ xp_gate_detail_append GATE_5_DETAIL "coverage_below_floor: ${CURRENT_LANG} ${COVERAGE_PERCENT}% < ${COVERAGE_THRESHOLD:-80}%"
2052
2079
  echo "❌ BLOCKED - ${CURRENT_LANG} coverage ${COVERAGE_PERCENT}% below ${COVERAGE_THRESHOLD:-80}% threshold"
2053
2080
  return 1
2054
2081
  fi
@@ -2077,7 +2104,7 @@ else
2077
2104
  # return. A verdict that only reaches the console is a verdict the journal
2078
2105
  # contradicts.
2079
2106
  GATE_5_STATUS="BLOCK"
2080
- GATE_5_DETAIL="coverage_not_determined: no standard report file for ${CURRENT_LANG}"
2107
+ xp_gate_detail_append GATE_5_DETAIL "coverage_not_determined: no standard report file for ${CURRENT_LANG}"
2081
2108
  return 1
2082
2109
  fi
2083
2110
  fi
@@ -2193,7 +2220,16 @@ else
2193
2220
  # summary is what a reader keeps and what the journal records.
2194
2221
  if [ -n "${DELEGATED_LANGS:-}" ]; then
2195
2222
  GATE_5_STATUS="SKIP"
2196
- GATE_5_DETAIL="${GATE_5_DETAIL:+${GATE_5_DETAIL}; }tests delegated to CI for: ${DELEGATED_LANGS}"
2223
+ # Pass ONLY the new fragment. This used to re-prepend the existing detail
2224
+ # (`${GATE_5_DETAIL:+${GATE_5_DETAIL}; }...`), so every earlier segment was
2225
+ # duplicated inside the fragment itself -- and since the append de-duplicates
2226
+ # whole segments, a fragment that ALREADY CONTAINS them is never equal to any
2227
+ # one of them and slips through. Measured: the persisted reason read
2228
+ #
2229
+ # shell: tests delegated ...; shell: tests delegated ...; powershell: ...
2230
+ #
2231
+ # -- the same sentence four times, unreadable.
2232
+ xp_gate_detail_append GATE_5_DETAIL "tests delegated to CI for: ${DELEGATED_LANGS}"
2197
2233
  elif [ -z "$GATE_5_STATUS" ]; then
2198
2234
  GATE_5_STATUS="PASS"
2199
2235
  fi
@@ -2215,7 +2251,7 @@ if [ "${PARTIAL_TEST_RUN:-false}" = "true" ]; then
2215
2251
  # Never overwrite a reason the branch itself recorded (docs_only_change,
2216
2252
  # no_code_files_changed, ...) -- those explain a different verdict.
2217
2253
  if [ -z "${GATE_5_DETAIL:-}" ] && [ "$GATE_5_STATUS" = "PASS" ]; then
2218
- GATE_5_DETAIL="partial_test_run_coverage_not_applicable"
2254
+ xp_gate_detail_append GATE_5_DETAIL "partial_test_run_coverage_not_applicable"
2219
2255
  fi
2220
2256
  else
2221
2257
  GATE_5_COVERAGE_APPLIES_TO="project"
@@ -2249,7 +2285,7 @@ fi
2249
2285
  # dominated by process-startup noise and would just add bytes.
2250
2286
  _g5_elapsed=$(( $(gate_start_ms) - GATE_5_START ))
2251
2287
  if [ "${_g5t_a:-0}" != "0" ] && [ "$_g5_elapsed" -ge 3000 ]; then
2252
- GATE_5_DETAIL="${GATE_5_DETAIL:-} seg=pre:${_g5t_focus}ms,5a:${_g5t_a}ms,5b:${_g5t_b}ms,5c:${_g5t_c}ms,total:${_g5_elapsed}ms"
2288
+ xp_gate_detail_append GATE_5_DETAIL " seg=pre:${_g5t_focus}ms,5a:${_g5t_a}ms,5b:${_g5t_b}ms,5c:${_g5t_c}ms,total:${_g5_elapsed}ms"
2253
2289
  fi
2254
2290
 
2255
2291
  record_gate_audit "gate-5" "tests-coverage" "$GATE_5_STATUS" "0" "$GATE_5_START" "${GATE_5_DETAIL:-}"
@@ -2345,7 +2381,7 @@ _gate5_go_coverage_arm() {
2345
2381
  # Record the verdict as well as printing it -- see the typescript branch
2346
2382
  # above for the measurement. An unassigned status renders as SKIP.
2347
2383
  GATE_5_STATUS="BLOCK"
2348
- GATE_5_DETAIL="coverage_below_floor: go coverage under the 80% floor"
2384
+ xp_gate_detail_append GATE_5_DETAIL "coverage_below_floor: go coverage under the 80% floor"
2349
2385
  echo "❌ BLOCKED - Go coverage ${total}% below ${COVERAGE_THRESHOLD:-80}% threshold"
2350
2386
  COV_EXIT=$((COV_EXIT || 1))
2351
2387
  return 1