@boyingliu01/xp-gate 0.37.3 → 0.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapter-common.sh +12 -2
- package/adapters/csharp.sh +73 -2
- package/adapters/dart.sh +13 -0
- package/adapters/go.sh +5 -0
- package/adapters/iac.sh +46 -3
- package/adapters/java.sh +6 -0
- package/adapters/kotlin.sh +6 -0
- package/adapters/shell.sh +119 -34
- package/adapters/swift.sh +6 -0
- package/adapters/typescript.sh +98 -34
- package/bin/xp-gate.js +48 -2
- package/gate-10.sh +99 -26
- package/gate-12-file-hygiene.sh +13 -1
- package/gate-registry.sh +197 -0
- package/gates/python-health.ts +67 -29
- package/hooks/adapter-common.sh +12 -2
- package/hooks/deploy-manifest.sh +100 -0
- package/hooks/gate-10.sh +99 -26
- package/hooks/gate-12-file-hygiene.sh +13 -1
- package/hooks/gate-driver.sh +120 -0
- package/hooks/gate-entries/gate-0-entry.sh +825 -0
- package/hooks/gate-entries/gate-1-entry.sh +767 -0
- package/hooks/gate-entries/gate-10-entry.sh +52 -0
- package/hooks/gate-entries/gate-11-entry.sh +120 -0
- package/hooks/gate-entries/gate-12-entry.sh +44 -0
- package/hooks/gate-entries/gate-12b-entry.sh +178 -0
- package/hooks/gate-entries/gate-12c-entry.sh +80 -0
- package/hooks/gate-entries/gate-13-entry.sh +584 -0
- package/hooks/gate-entries/gate-2-entry.sh +199 -0
- package/hooks/gate-entries/gate-3-entry.sh +53 -0
- package/hooks/gate-entries/gate-4-entry.sh +46 -0
- package/hooks/gate-entries/gate-5-entry.sh +1729 -0
- package/hooks/gate-entries/gate-6-entry.sh +658 -0
- package/hooks/gate-entries/gate-7-entry.sh +41 -0
- package/hooks/gate-entries/gate-8-entry.sh +33 -0
- package/hooks/gate-entries/gate-9-entry.sh +307 -0
- package/hooks/gate-entries/subdir-restore.sh +27 -0
- package/hooks/gate-registry.sh +51 -15
- package/hooks/hook-module-resolution.sh +73 -0
- package/hooks/install.sh +135 -0
- package/hooks/lib/now-ms.sh +55 -19
- package/hooks/lib/toolchain-path.sh +50 -6
- package/hooks/pre-commit +256 -5091
- package/hooks/pre-push +212 -25
- package/lib/__tests__/arch-config-template.test.js +190 -0
- package/lib/__tests__/baseline-shell-scope.test.js +60 -0
- package/lib/__tests__/crap-cli.test.js +14 -3
- package/lib/__tests__/deploy-manifest-check-wired.test.js +138 -0
- package/lib/__tests__/deploy-manifest-completeness.test.js +151 -0
- package/lib/__tests__/deploy-manifest-consumers-adapter-uninstall.test.js +40 -0
- package/lib/__tests__/deploy-manifest-consumers-no-private-lists.test.js +74 -0
- package/lib/__tests__/deploy-manifest-projection.test.js +66 -0
- package/lib/__tests__/deploy-manifest-shell-parity.test.js +108 -0
- package/lib/__tests__/deploy-manifest.test.js +97 -0
- package/lib/__tests__/doctor.test.js +51 -7
- package/lib/__tests__/gate-coverage.test.js +79 -12
- package/lib/__tests__/gate-numbering.test.js +28 -1
- package/lib/__tests__/install-sh-deploy-manifest.test.js +80 -0
- package/lib/__tests__/mirror-sync.test.js +45 -3
- package/lib/__tests__/npm-package.test.js +10 -7
- package/lib/__tests__/sastd-client.test.js +514 -0
- package/lib/__tests__/shared-utils-copyHooks-manifest.test.js +69 -0
- package/lib/__tests__/sprint-status-rework.test.js +1 -0
- package/lib/arch-config-template.js +87 -0
- package/lib/baseline.js +54 -2
- package/lib/deploy-manifest.js +174 -0
- package/lib/doctor.js +46 -14
- package/lib/gate-capability.js +291 -0
- package/lib/gate-coverage.js +194 -74
- package/lib/gate-identity.js +349 -0
- package/lib/gate-runner.js +11 -1
- package/lib/hook-module-resolution.js +27 -0
- package/lib/init.js +72 -5
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/sastd-client.js +572 -0
- package/lib/shared-utils.js +31 -9
- package/lib/uninstall.js +10 -7
- package/lib/update-hooks.js +27 -18
- package/mock-policy/AGENTS.md +1 -1
- package/mutation/AGENTS.md +1 -1
- package/package.json +3 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/principles/AGENTS.md +1 -1
- package/principles/__tests__/analyzer.test.ts +2 -1
- package/principles/__tests__/config-enforcement.test.ts +1 -0
- package/principles/__tests__/types.test.ts +1 -0
- package/principles/adapters/base.ts +14 -1
- package/principles/adapters/duplication.ts +134 -0
- package/principles/rules/__tests__/clean-code/large-file.test.ts +2 -1
- package/principles/rules/clean-code/code-duplication.ts +75 -9
- package/principles/types.ts +39 -0
- package/scripts/__tests__/check-mattpocock-license.test.js +36 -3
- package/scripts/__tests__/sync-package-content.test.js +12 -2
- package/scripts/generate-mirrors.cjs +125 -0
- package/scripts/sync-package-content.js +64 -20
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
- package/adapters/gate-9.sh +0 -245
- package/gate-9.sh +0 -245
- package/hooks/gate-9.sh +0 -245
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# ============================================================================
|
|
3
|
+
# gate-13 entry — extracted from pre-commit by scripts/extract-gates.cjs
|
|
4
|
+
#
|
|
5
|
+
# WHY THIS FILE EXISTS (#798)
|
|
6
|
+
# The gate order used to BE the physical order of blocks in a 6341-line
|
|
7
|
+
# hook, so changing the order meant moving thousands of lines. An attempt at
|
|
8
|
+
# that also moved the hook epilogue, after which every gate past Gate 13
|
|
9
|
+
# silently stopped running while `bash -n`, a line count and five ordering
|
|
10
|
+
# tests all passed. Gate 5a stopped blocking and only a behavioural test
|
|
11
|
+
# noticed. With one file per gate, order is a list of names in
|
|
12
|
+
# pre-commit's GATE_ORDER and cannot detach a body from its position.
|
|
13
|
+
#
|
|
14
|
+
# THE BODY BELOW IS A BYTE-EXACT SLICE of the original block. It is wrapped
|
|
15
|
+
# in a function so the gate keeps its own variable scope, and is called from
|
|
16
|
+
# pre-commit at the point the driver reaches it. Edit the gate here from now
|
|
17
|
+
# on - there is no copy left in the hook.
|
|
18
|
+
# ============================================================================
|
|
19
|
+
|
|
20
|
+
# ============================================================================
|
|
21
|
+
# Gate body. `return` is used instead of `exit` so the driver decides to
|
|
22
|
+
# stop: see scripts/wrap-gate-entries.cjs for why the two are equivalent
|
|
23
|
+
# here, and why sub-shell exits are deliberately left as `exit`.
|
|
24
|
+
generate_quality_report() {
|
|
25
|
+
local HISTORY_FILE=".quality-history.jsonl"
|
|
26
|
+
local COMMIT_HASH
|
|
27
|
+
local TIMESTAMP
|
|
28
|
+
local BRANCH
|
|
29
|
+
local PASSED_COUNT=0
|
|
30
|
+
# #680: the gate list is the single source of truth. TOTAL_GATES, the scoring
|
|
31
|
+
# loop, the console table and the JSON `overall` block all derive from it.
|
|
32
|
+
#
|
|
33
|
+
# Gate 13 was added in v0.35.x with only its execution and JSON write -- these
|
|
34
|
+
# three sites kept saying "12". A machine with no C/C++ compiler therefore saw
|
|
35
|
+
# `10.0/10 effective`, `gatesWarned: 0` and a table that stopped at Gate 12,
|
|
36
|
+
# while the JSON `gates` object held 13 keys. "Compiler strictness was never
|
|
37
|
+
# checked" and "compiler reported zero warnings" rendered identically, which is
|
|
38
|
+
# the same silent-success pattern as #561/#570/#585.
|
|
39
|
+
#
|
|
40
|
+
# Adding a gate now means editing ALL_GATE_NUMBERS + ONE table row. Nothing
|
|
41
|
+
# else carries a count.
|
|
42
|
+
local ALL_GATE_NUMBERS="1 2 3 4 5 6 7 8 9 10 11 12 13"
|
|
43
|
+
local TOTAL_GATES=0
|
|
44
|
+
local _g
|
|
45
|
+
for _g in $ALL_GATE_NUMBERS; do TOTAL_GATES=$((TOTAL_GATES + 1)); done
|
|
46
|
+
local SKIP_COUNT=0
|
|
47
|
+
local WARN_COUNT=0
|
|
48
|
+
local NONPASS_COUNT=0
|
|
49
|
+
|
|
50
|
+
# #711: capture the probe output first, then fall back — never `|| echo` a
|
|
51
|
+
# command whose stdout is only shown on success.
|
|
52
|
+
#
|
|
53
|
+
# On a repository with no commits yet, `git rev-parse --abbrev-ref HEAD`
|
|
54
|
+
# PRINTS "HEAD" and then exits non-zero. With `$(cmd || echo unknown)` the
|
|
55
|
+
# captured value becomes "HEAD\nunknown" — two lines — and it is embedded
|
|
56
|
+
# verbatim into the JSON report as `"branch": "HEAD\nunknown"`, which is not
|
|
57
|
+
# valid JSON (a raw newline cannot appear inside a string literal).
|
|
58
|
+
#
|
|
59
|
+
# Gate 12 then reads that report on the NEXT commit and BLOCKS with
|
|
60
|
+
# "YAML/JSON syntax errors" against a file the gate itself wrote. The first
|
|
61
|
+
# commit of every freshly-initialised consumer repo therefore fails once for a
|
|
62
|
+
# reason that has nothing to do with the user's change.
|
|
63
|
+
COMMIT_HASH=$(git rev-parse HEAD 2>/dev/null) || COMMIT_HASH=""
|
|
64
|
+
[ -n "$COMMIT_HASH" ] || COMMIT_HASH="unknown"
|
|
65
|
+
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || BRANCH=""
|
|
66
|
+
# A detached HEAD reports the literal word "HEAD"; keep it (it is the truth)
|
|
67
|
+
# but never allow a multi-line value into the report.
|
|
68
|
+
BRANCH=$(printf '%s' "$BRANCH" | tr -d '\r\n')
|
|
69
|
+
[ -n "$BRANCH" ] || BRANCH="unknown"
|
|
70
|
+
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
71
|
+
|
|
72
|
+
# Scoring per #507 S3: SKIP removes a gate from the denominator (a missing
|
|
73
|
+
# tool must not drag the score down -- that was the "honest but punishing"
|
|
74
|
+
# old behavior), WARN stays in the denominator but never counts as passed,
|
|
75
|
+
# and FAIL/BLOCK count as non-passing items like before. NONPASS tracks
|
|
76
|
+
# non-passing gates INSIDE the effective denominator only -- a skipped gate
|
|
77
|
+
# is out of scope, not a failure.
|
|
78
|
+
local gate_status gate_default
|
|
79
|
+
# #536: a WARN means the check could not run (typically tool_not_installed)
|
|
80
|
+
# -- degraded coverage, kept in the denominator but flagged separately so a
|
|
81
|
+
# degraded gate is never confused with a real PASS.
|
|
82
|
+
local DEGRADED_COUNT=0
|
|
83
|
+
# The report's gatesDegraded is a superset: DEGRADED plus WARN (#536), because
|
|
84
|
+
# both mean "this gate could not fully verify what it was asked to". Kept
|
|
85
|
+
# separate from the scoring loop's DEGRADED_COUNT above so the two statuses stay
|
|
86
|
+
# distinct where that distinction is load-bearing (#599-10).
|
|
87
|
+
local REPORT_DEGRADED_COUNT=0
|
|
88
|
+
local DEGRADED_JSON=""
|
|
89
|
+
local FAIL_COUNT=0
|
|
90
|
+
local FAILED_JSON=""
|
|
91
|
+
for gate in $ALL_GATE_NUMBERS; do
|
|
92
|
+
local status_var="GATE_${gate}_STATUS"
|
|
93
|
+
# Default mirrors the JSON report rendering below EXACTLY (gates 1-11
|
|
94
|
+
# PASS, gate 12 WARN): a gate that never assigned a status is "not
|
|
95
|
+
# applicable" and must render and score identically. A previous scoring
|
|
96
|
+
# default of FAIL produced self-contradictory reports -- the gate showed
|
|
97
|
+
# PASS in JSON but scored as FAIL (#507 Delphi round-1 A-MAJOR-2).
|
|
98
|
+
# Default direction is "did not run", never "passed": an unassigned status
|
|
99
|
+
# is a gate that never reached a verdict, and scoring it PASS both claims a
|
|
100
|
+
# success that did not happen and hides the gap in the effective rate.
|
|
101
|
+
#
|
|
102
|
+
# Gate 13 defaults to SKIP like the rest: it is only WARN when the toolchain
|
|
103
|
+
# is missing and the gate explicitly says so, and Gate 12 is the one gate
|
|
104
|
+
# whose "no verdict" is still a warning rather than "not applicable".
|
|
105
|
+
if [ "$gate" -eq 12 ]; then gate_default="WARN"; else gate_default="SKIP"; fi
|
|
106
|
+
gate_status="${!status_var:-$gate_default}"
|
|
107
|
+
case "$gate_status" in
|
|
108
|
+
PASS) PASSED_COUNT=$((PASSED_COUNT + 1)) ;;
|
|
109
|
+
SKIP) SKIP_COUNT=$((SKIP_COUNT + 1)) ;;
|
|
110
|
+
# #536: a WARN gate ran but could not fully do its job, so the REPORT's
|
|
111
|
+
# gatesDegraded must include it -- that field answers "how much of this run
|
|
112
|
+
# could actually verify what it was asked to". The scoring loop's
|
|
113
|
+
# DEGRADED_COUNT deliberately does NOT include it: a plain WARN must stay
|
|
114
|
+
# distinguishable from a gate that reported DEGRADED (#599-10), or the two
|
|
115
|
+
# statuses become one and neither is worth anything.
|
|
116
|
+
WARN) REPORT_DEGRADED_COUNT=$((REPORT_DEGRADED_COUNT + 1)); WARN_COUNT=$((WARN_COUNT + 1)); NONPASS_COUNT=$((NONPASS_COUNT + 1)) ;;
|
|
117
|
+
# #574: DEGRADED is a status a gate really produces -- Gate 5 reports it
|
|
118
|
+
# when coverage could not be measured honestly instead of claiming PASS.
|
|
119
|
+
# It had no arm here, so it fell into the catch-all below and counted as a
|
|
120
|
+
# HARD FAILURE: the gate was punished for telling the truth about itself.
|
|
121
|
+
# It must also feed WARN_COUNT, because the FAIL predicate is
|
|
122
|
+
# (NONPASS_COUNT - WARN_COUNT) > 0; adding only NONPASS_COUNT would turn
|
|
123
|
+
# every honest DEGRADED run into FAIL.
|
|
124
|
+
DEGRADED) DEGRADED_COUNT=$((DEGRADED_COUNT + 1)); REPORT_DEGRADED_COUNT=$((REPORT_DEGRADED_COUNT + 1)); WARN_COUNT=$((WARN_COUNT + 1)); NONPASS_COUNT=$((NONPASS_COUNT + 1)); DEGRADED_JSON="${DEGRADED_JSON:+$DEGRADED_JSON, }\"gate${gate}\"" ;;
|
|
125
|
+
*) FAIL_COUNT=$((FAIL_COUNT + 1)); NONPASS_COUNT=$((NONPASS_COUNT + 1)); FAILED_JSON="${FAILED_JSON:+$FAILED_JSON, }\"gate${gate}\"" ;;
|
|
126
|
+
esac
|
|
127
|
+
done
|
|
128
|
+
|
|
129
|
+
local EFFECTIVE_TOTAL=$((TOTAL_GATES - SKIP_COUNT))
|
|
130
|
+
local VERDICT="PASS"
|
|
131
|
+
if [ "$EFFECTIVE_TOTAL" -eq 0 ]; then
|
|
132
|
+
VERDICT="SKIP-ALL" # every gate skipped: never report a fake 10/10
|
|
133
|
+
elif [ "$NONPASS_COUNT" -gt 0 ]; then
|
|
134
|
+
if [ "$((NONPASS_COUNT - WARN_COUNT))" -gt 0 ]; then
|
|
135
|
+
VERDICT="FAIL" # at least one FAIL/BLOCK among the effective gates
|
|
136
|
+
else
|
|
137
|
+
VERDICT="WARN" # all effective gates passed or warned; warns forbid PASS
|
|
138
|
+
fi
|
|
139
|
+
elif [ "$SKIP_COUNT" -gt 0 ]; then
|
|
140
|
+
# #575: PARTIAL. Something passed, but not everything ran, and "PASS" reads
|
|
141
|
+
# as a statement about the commit — not about the fraction of the pipeline
|
|
142
|
+
# that happened to execute. A docs-only commit runs 3 of 12 gates and used
|
|
143
|
+
# to report `verdict: PASS`, which is a claim the run did not support.
|
|
144
|
+
# This is deliberately NOT FAIL: nothing failed. It is also not SKIP-ALL,
|
|
145
|
+
# which means no gate ran at all. Naming the gap is the whole point.
|
|
146
|
+
VERDICT="PARTIAL"
|
|
147
|
+
fi
|
|
148
|
+
|
|
149
|
+
local SCORE=0
|
|
150
|
+
if [ "$EFFECTIVE_TOTAL" -eq 0 ]; then
|
|
151
|
+
SCORE="N/A"
|
|
152
|
+
else
|
|
153
|
+
# Single awk path (#507 Delphi round-1 B-MAJOR-2): bc's scale=1 truncates
|
|
154
|
+
# the DIVISION before multiplying (8/9 -> 0.8, *10 -> 8.0) while awk
|
|
155
|
+
# rounds the final result (8.9) -- the same commit scored differently on
|
|
156
|
+
# machines with and without bc. awk(1) is POSIX-guaranteed: one code path,
|
|
157
|
+
# one score.
|
|
158
|
+
SCORE=$(awk "BEGIN {printf \"%.1f\", ($PASSED_COUNT / $EFFECTIVE_TOTAL) * 10}")
|
|
159
|
+
fi
|
|
160
|
+
local EFFECTIVE_PASS_RATE="N/A"
|
|
161
|
+
if [ "$EFFECTIVE_TOTAL" -gt 0 ]; then
|
|
162
|
+
EFFECTIVE_PASS_RATE=$(awk "BEGIN {printf \"%.1f\", ($PASSED_COUNT / $EFFECTIVE_TOTAL) * 100}")
|
|
163
|
+
fi
|
|
164
|
+
|
|
165
|
+
# #564: `score` above divides by the EFFECTIVE total, so a SKIPped gate leaves
|
|
166
|
+
# the denominator instead of counting against it. Arithmetic on that formula:
|
|
167
|
+
# 1 passed / 11 skipped is 1/1 -> 10.0, identical to 10 passed / 2 skipped.
|
|
168
|
+
# .quality-history.jsonl shows Gate 3 running in 7% of runs and Gate 4 in 8%,
|
|
169
|
+
# every one of them recording score 10 -- skipping work raised the score.
|
|
170
|
+
#
|
|
171
|
+
# The effective view answers a real question ("of the gates that could run,
|
|
172
|
+
# how many passed?"), so it stays. What was missing is the denominator being
|
|
173
|
+
# visible, and a score that counts skips against the run. `scoreAllGates`
|
|
174
|
+
# divides by TOTAL_GATES, so a skipped gate costs exactly what a failed one
|
|
175
|
+
# costs in that view; `gatesRan` says how much of the suite was exercised.
|
|
176
|
+
# `score` keeps its current value and meaning so dashboard/ and
|
|
177
|
+
# .quality-history.jsonl consumers do not break (#507 already made it
|
|
178
|
+
# number-or-null; this stays within that contract).
|
|
179
|
+
local GATES_RAN=$EFFECTIVE_TOTAL
|
|
180
|
+
local SCORE_ALL="N/A"
|
|
181
|
+
if [ "$TOTAL_GATES" -gt 0 ]; then
|
|
182
|
+
SCORE_ALL=$(awk "BEGIN {printf \"%.1f\", ($PASSED_COUNT / $TOTAL_GATES) * 10}")
|
|
183
|
+
fi
|
|
184
|
+
local SCORE_ALL_JSON="$SCORE_ALL"
|
|
185
|
+
[ "$SCORE_ALL_JSON" = "N/A" ] && SCORE_ALL_JSON="null"
|
|
186
|
+
# JSON bodies need a number or null -- a literal N/A breaks every consumer.
|
|
187
|
+
local SCORE_JSON="$SCORE"
|
|
188
|
+
[ "$SCORE_JSON" = "N/A" ] && SCORE_JSON="null"
|
|
189
|
+
# Same for the pass rate: numeric like `score`, not a quoted string --
|
|
190
|
+
# mixed types in one object broke consumers (#507 Delphi round-1 B-minor-6).
|
|
191
|
+
local EFFECTIVE_PASS_RATE_JSON="$EFFECTIVE_PASS_RATE"
|
|
192
|
+
[ "$EFFECTIVE_PASS_RATE_JSON" = "N/A" ] && EFFECTIVE_PASS_RATE_JSON="null"
|
|
193
|
+
|
|
194
|
+
local BS_PASSED=0
|
|
195
|
+
local BS_BLOCKED=0
|
|
196
|
+
if [ -n "$BOY_SCOUT_OUTPUT" ]; then
|
|
197
|
+
BS_PASSED=$(echo "$BOY_SCOUT_OUTPUT" | grep -o '"passedFiles": [0-9]*' | grep -o '[0-9]*' || echo "0")
|
|
198
|
+
BS_BLOCKED=$(echo "$BOY_SCOUT_OUTPUT" | grep -o '"blockedFiles": [0-9]*' | grep -o '[0-9]*' || echo "0")
|
|
199
|
+
fi
|
|
200
|
+
|
|
201
|
+
local COV_PCT="${COVERAGE_PERCENT:-N/A}"
|
|
202
|
+
|
|
203
|
+
# ── Build failed-tests list from TESTS_OUTPUT (Gate 5) ──────────────────────────────
|
|
204
|
+
local FAILED_TESTS_JSON="[]"
|
|
205
|
+
if [ -n "$TESTS_OUTPUT" ] && echo "$TESTS_OUTPUT" | grep -qi "fail\|error\|FAILED"; then
|
|
206
|
+
# Extract failure lines: "FAIL src/foo.test.ts" or " ✗ test name"
|
|
207
|
+
local FAIL_LINES
|
|
208
|
+
# errexit/pipefail-safe: grep returns 1 on zero matches (see #489) and this
|
|
209
|
+
# function is also sourced by consumer wrappers that may enable errexit
|
|
210
|
+
FAIL_LINES=$(echo "$TESTS_OUTPUT" | grep -E "^\s*(FAIL|✗|failed|AssertionError)" | sed -n '1,10p' | \
|
|
211
|
+
sed 's/"/\\"/g' | awk '{ printf "%s%s%s", sep, "\"", $0; sep="," }') || true
|
|
212
|
+
if [ -n "$FAIL_LINES" ]; then
|
|
213
|
+
FAILED_TESTS_JSON="[$FAIL_LINES]"
|
|
214
|
+
fi
|
|
215
|
+
fi
|
|
216
|
+
|
|
217
|
+
# ── Branch-level quality status file ─────────────────────────────────────────────
|
|
218
|
+
local STATUS_DIR=".xp-gate/quality-status"
|
|
219
|
+
local REPORT_FILE="${STATUS_DIR}/${BRANCH}.json"
|
|
220
|
+
mkdir -p "$(dirname "$REPORT_FILE")"
|
|
221
|
+
|
|
222
|
+
# ── #537: per-language coverage matrix ───────────────────────────────────────
|
|
223
|
+
# Answers "was this dimension actually measured for this language?" instead of
|
|
224
|
+
# letting every SKIP read as a pass. Built by whitelist splicing (the same
|
|
225
|
+
# technique as DEGRADED_JSON above) rather than jq, because jq is an OPTIONAL
|
|
226
|
+
# dependency here (see the `command -v jq` guard earlier in this file) and a
|
|
227
|
+
# missing jq must not silently cost us the whole matrix.
|
|
228
|
+
#
|
|
229
|
+
# Safety: every spliced value is one of the five enum literals below — no
|
|
230
|
+
# quotes, backslashes or newlines can reach the JSON. Language names are
|
|
231
|
+
# whitelisted too, and a name that fails the whitelist is reported in
|
|
232
|
+
# coverageWarnings instead of being silently dropped.
|
|
233
|
+
local COVERAGE_MATRIX_JSON=""
|
|
234
|
+
local COVERAGE_WARNINGS_JSON=""
|
|
235
|
+
local _cm_lang _cm_g3 _cm_g4 _cm_g6 _cm_entry
|
|
236
|
+
for _cm_lang in $PROJECT_LANGS; do
|
|
237
|
+
if ! echo "$_cm_lang" | grep -qE '^[a-z][a-z0-9+]*$'; then
|
|
238
|
+
COVERAGE_WARNINGS_JSON="${COVERAGE_WARNINGS_JSON:+$COVERAGE_WARNINGS_JSON, }\"unsupported_language_name\""
|
|
239
|
+
continue
|
|
240
|
+
fi
|
|
241
|
+
_cm_g3=$(classify_coverage_reason "${GATE_3_REASON:-}" "${GATE_3_STATUS:-SKIP}")
|
|
242
|
+
_cm_g4=$(classify_coverage_reason "${GATE_4_REASON:-}" "${GATE_4_STATUS:-SKIP}")
|
|
243
|
+
# Gate 6 reason for this language — extracted so the rule is testable
|
|
244
|
+
# rather than inlined (see coverage_g6_reason_for below).
|
|
245
|
+
_cm_g6_reason=$(coverage_g6_reason_for "$_cm_lang")
|
|
246
|
+
_cm_g6=$(classify_coverage_reason "$_cm_g6_reason" "${GATE_6_STATUS:-SKIP}")
|
|
247
|
+
_cm_entry="\"${_cm_lang}\": {\"gate3_complexity\": \"${_cm_g3}\", \"gate4_principles\": \"${_cm_g4}\", \"gate6_architecture\": \"${_cm_g6}\"}"
|
|
248
|
+
COVERAGE_MATRIX_JSON="${COVERAGE_MATRIX_JSON:+$COVERAGE_MATRIX_JSON, }${_cm_entry}"
|
|
249
|
+
done
|
|
250
|
+
local LANGUAGES_SOURCE
|
|
251
|
+
LANGUAGES_SOURCE=$(resolve_languages_source "${_RESOLVED_LANG_OVERRIDE:-}" "${_CONFIG_LANGS:-}" "${PROJECT_LANGS:-}")
|
|
252
|
+
|
|
253
|
+
# #798 step 1: per-gate durations, emitted from the single table that
|
|
254
|
+
# record_gate_audit fills. See gate_timings_json for why an unmeasured gate is
|
|
255
|
+
# absent rather than 0.
|
|
256
|
+
local GATE_TIMINGS_JSON
|
|
257
|
+
GATE_TIMINGS_JSON=$(gate_timings_json)
|
|
258
|
+
|
|
259
|
+
cat > "$REPORT_FILE" << ENDJSON
|
|
260
|
+
{
|
|
261
|
+
"reportVersion": "2.0",
|
|
262
|
+
"generatedAt": "$TIMESTAMP",
|
|
263
|
+
"branch": "$BRANCH",
|
|
264
|
+
"commit": "$COMMIT_HASH",
|
|
265
|
+
"language": "${PROJECT_LANGS:-${PROJECT_LANG:-unknown}}",
|
|
266
|
+
"overall": {
|
|
267
|
+
"gatesPassed": $PASSED_COUNT,
|
|
268
|
+
"gatesTotal": $TOTAL_GATES,
|
|
269
|
+
"gatesSkipped": $SKIP_COUNT,
|
|
270
|
+
"gatesWarned": $WARN_COUNT,
|
|
271
|
+
"gatesFailed": $FAIL_COUNT,
|
|
272
|
+
"failedGates": [$FAILED_JSON],
|
|
273
|
+
"gatesDegraded": $REPORT_DEGRADED_COUNT,
|
|
274
|
+
"degradedGates": [$DEGRADED_JSON],
|
|
275
|
+
"gatesEffective": $EFFECTIVE_TOTAL,
|
|
276
|
+
"effectivePassRate": $EFFECTIVE_PASS_RATE_JSON,
|
|
277
|
+
"gatesRan": $GATES_RAN,
|
|
278
|
+
"scoreAllGates": $SCORE_ALL_JSON,
|
|
279
|
+
"score": $SCORE_JSON,
|
|
280
|
+
"verdict": "$VERDICT"
|
|
281
|
+
},
|
|
282
|
+
"languagesSource": "${LANGUAGES_SOURCE}",
|
|
283
|
+
"gateTimings": {${GATE_TIMINGS_JSON}},
|
|
284
|
+
"coverageMatrix": {${COVERAGE_MATRIX_JSON}},
|
|
285
|
+
"coverageWarnings": [${COVERAGE_WARNINGS_JSON}],
|
|
286
|
+
"gates": {
|
|
287
|
+
"gate1_static_analysis": {
|
|
288
|
+
"name": "Code Quality (Static + Lint + Shell)",
|
|
289
|
+
"status": "${GATE_1_STATUS:-SKIP}",
|
|
290
|
+
"tool": "${GATE_1_TOOL:-auto}"
|
|
291
|
+
},
|
|
292
|
+
"gate2_dup_code": {
|
|
293
|
+
"name": "Duplicate Code",
|
|
294
|
+
"status": "${GATE_2_STATUS:-SKIP}",
|
|
295
|
+
"metric": "similarity <= 5%"
|
|
296
|
+
},
|
|
297
|
+
"gate3_complexity": {
|
|
298
|
+
"name": "Cyclomatic Complexity",
|
|
299
|
+
"status": "${GATE_3_STATUS:-SKIP}",
|
|
300
|
+
"reason": "${GATE_3_REASON:-}",
|
|
301
|
+
"threshold": "${CCN_THRESHOLD:-5}",
|
|
302
|
+
"blockThreshold": "${CCN_THRESHOLD:-5}",
|
|
303
|
+
"warnings": ${CC_WARNINGS:-0}
|
|
304
|
+
},
|
|
305
|
+
"gate4_principles": {
|
|
306
|
+
"name": "Clean Code + SOLID",
|
|
307
|
+
"status": "${GATE_4_STATUS:-SKIP}",
|
|
308
|
+
"reason": "${GATE_4_REASON:-}",
|
|
309
|
+
"warnings": ${WARNING_COUNT:-0}
|
|
310
|
+
},
|
|
311
|
+
"gate5_tests": {
|
|
312
|
+
"name": "Tests + Coverage",
|
|
313
|
+
"status": "${GATE_5_STATUS:-SKIP}",
|
|
314
|
+
"reason": "${GATE_5_DETAIL:-}",
|
|
315
|
+
"thresholds": { "lines": ${COVERAGE_THRESHOLD}, "functions": null, "branches": null, "statements": null },
|
|
316
|
+
"threshold_source": "${COVERAGE_THRESHOLD_SOURCE}",
|
|
317
|
+
"actual": { "coverage": "${COV_PCT}", "applies_to": "${GATE_5_COVERAGE_APPLIES_TO:-project}" },
|
|
318
|
+
"failedTests": $FAILED_TESTS_JSON
|
|
319
|
+
},
|
|
320
|
+
"gate6_arch_boyscout": {
|
|
321
|
+
"name": "Architecture + Boy Scout Rule",
|
|
322
|
+
"status": "${GATE_6_STATUS:-SKIP}",
|
|
323
|
+
"reason": "${GATE_6_REASON:-}",
|
|
324
|
+
"boyScoutPassed": $BS_PASSED,
|
|
325
|
+
"boyScoutBlocked": $BS_BLOCKED
|
|
326
|
+
},
|
|
327
|
+
"gate7_iac_security": {
|
|
328
|
+
"name": "IaC Security Scanning",
|
|
329
|
+
"status": "${GATE_7_STATUS:-SKIP}",
|
|
330
|
+
"scanned_files": ${GATE_7_SCANNED_FILES:-0},
|
|
331
|
+
"tools": "checkov, hadolint, kube-score, tflint"
|
|
332
|
+
},
|
|
333
|
+
"gate8_secret_scanning": {
|
|
334
|
+
"name": "Secret Scanning",
|
|
335
|
+
"status": "${GATE_8_STATUS:-SKIP}",
|
|
336
|
+
"tool": "gitleaks"
|
|
337
|
+
},
|
|
338
|
+
"gate9_build_integrity": {
|
|
339
|
+
"name": "Build Integrity",
|
|
340
|
+
"status": "${GATE_9_STATUS:-SKIP}",
|
|
341
|
+
"tool": "tsc + npm pack + import check"
|
|
342
|
+
},
|
|
343
|
+
"gate10_sast": {
|
|
344
|
+
"name": "SAST Security Scan",
|
|
345
|
+
"status": "${GATE_10_STATUS:-SKIP}",
|
|
346
|
+
"reason": "${GATE_10_REASON:-}",
|
|
347
|
+
"scanned_files": ${GATE_10_SCANNED_FILES:-0},
|
|
348
|
+
"path": "${GATE_10_SEMGREP_PATH:-direct}",
|
|
349
|
+
"degraded": ${GATE_10_SASTD_DEGRADED:-0},
|
|
350
|
+
"tool": "semgrep"
|
|
351
|
+
},
|
|
352
|
+
"gate11_sprint_flow": {
|
|
353
|
+
"name": "Sprint Flow Enforcement",
|
|
354
|
+
"status": "${GATE_11_STATUS:-SKIP}",
|
|
355
|
+
"tool": "sprint-gate.sh"
|
|
356
|
+
},
|
|
357
|
+
"gate12_file_hygiene": {
|
|
358
|
+
"name": "File Hygiene Check",
|
|
359
|
+
"status": "${GATE_12_STATUS:-WARN}",
|
|
360
|
+
"tool": "gate-12-file-hygiene.sh"
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
ENDJSON
|
|
365
|
+
|
|
366
|
+
# ── Gate 13 injection (tail append; no existing line above is modified) ────
|
|
367
|
+
# The heredoc is closed deliberately before Gate 13 so this sprint ADDS lines
|
|
368
|
+
# instead of editing gates 0-12's report block, keeping the two branches'
|
|
369
|
+
# hunks disjoint. Scores are recomputed over 13 gates afterwards.
|
|
370
|
+
if [ -n "${GATE_13_STATUS:-}" ] && [ -f "$REPORT_FILE" ]; then
|
|
371
|
+
_XP_G13="$REPORT_FILE" _XP_G13S="$GATE_13_STATUS" node -e "
|
|
372
|
+
const fs=require('fs'),p=process.env._XP_G13;
|
|
373
|
+
try{
|
|
374
|
+
const j=JSON.parse(fs.readFileSync(p,'utf8'));
|
|
375
|
+
j.gates=j.gates||{};
|
|
376
|
+
j.gates.gate13_compiler_strictness={name:'Compiler Strictness',status:process.env._XP_G13S,tool:'gate-13-compiler-strictness.sh'};
|
|
377
|
+
fs.writeFileSync(p,JSON.stringify(j,null,2)+'\n');
|
|
378
|
+
}catch(e){}
|
|
379
|
+
" 2>/dev/null || true
|
|
380
|
+
fi
|
|
381
|
+
|
|
382
|
+
# ── Persistent per-run report (Issue #101) ────────────────────────────────────────
|
|
383
|
+
local REPORTS_DIR=".xp-gate/reports/pre-commit"
|
|
384
|
+
local REPORT_TS
|
|
385
|
+
REPORT_TS=$(date -u +"%Y-%m-%d-%H%M%S")
|
|
386
|
+
local PERSISTED_REPORT_FILE="${REPORTS_DIR}/${REPORT_TS}.json"
|
|
387
|
+
mkdir -p "$REPORTS_DIR"
|
|
388
|
+
# #640 / #798: `duration_ms` is wall-clock time from hook entry to report write.
|
|
389
|
+
# Emitted only when measurable -- an absent field is honest, a 0 is not.
|
|
390
|
+
#
|
|
391
|
+
# #798 replaced the /proc/uptime fraction parser that produced this field: it
|
|
392
|
+
# truncated the fractional seconds (`331154.04` -> `33115404`, i.e. 10x small)
|
|
393
|
+
# and reported 21,754 ms for a run that measured 199,000 ms. Both ends now come
|
|
394
|
+
# from now_ms, the same clock, and the subtraction stays in BASH because the
|
|
395
|
+
# value is a bash-side timestamp.
|
|
396
|
+
#
|
|
397
|
+
# LOWER-BOUND CHECK (#798): a hook cannot have run for less time than the gates
|
|
398
|
+
# inside it already consumed. When the computed duration is smaller than the
|
|
399
|
+
# largest per-gate duration, the arithmetic is wrong somewhere -- publish null
|
|
400
|
+
# rather than a number that would send every optimisation decision the wrong
|
|
401
|
+
# way. "宁可没有数,也不要有一个会让所有优化决策跑偏的数."
|
|
402
|
+
local _XP_DURATION_MS=""
|
|
403
|
+
local _XP_NOW_MS=""
|
|
404
|
+
_XP_NOW_MS=$(now_ms)
|
|
405
|
+
case "$_XP_NOW_MS" in
|
|
406
|
+
''|*[!0-9]*) _XP_NOW_MS="" ;;
|
|
407
|
+
esac
|
|
408
|
+
case "$_XP_HOOK_START_MS" in
|
|
409
|
+
''|*[!0-9]*) _XP_HOOK_START_MS="" ;;
|
|
410
|
+
esac
|
|
411
|
+
if [ -n "$_XP_NOW_MS" ] && [ -n "$_XP_HOOK_START_MS" ] && [ "$_XP_NOW_MS" -gt "$_XP_HOOK_START_MS" ]; then
|
|
412
|
+
_XP_DURATION_MS=$(( _XP_NOW_MS - _XP_HOOK_START_MS ))
|
|
413
|
+
fi
|
|
414
|
+
# LOWER-BOUND CHECK (#798): the hook cannot have run for less than its own
|
|
415
|
+
# longest gate. This catches a clock that changed units or a poisoned start
|
|
416
|
+
# before the number reaches .quality-history.jsonl, where it becomes the basis
|
|
417
|
+
# for "are the gates getting slower?". Rejecting to null is deliberate: a
|
|
418
|
+
# wrong number is worse than no number, because it is acted upon.
|
|
419
|
+
local _XP_DURATION_FLOOR=""
|
|
420
|
+
local _xp_floor_n
|
|
421
|
+
for _xp_floor_n in \
|
|
422
|
+
"${GATE_1_ELAPSED:-}" "${GATE_2_ELAPSED:-}" "${GATE_3_ELAPSED:-}" \
|
|
423
|
+
"${GATE_4_ELAPSED:-}" "${GATE_5_ELAPSED:-}" "${GATE_6_ELAPSED:-}" \
|
|
424
|
+
"${GATE_7_ELAPSED:-}" "${GATE_8_ELAPSED:-}" "${GATE_9_ELAPSED:-}" \
|
|
425
|
+
"${GATE_10_ELAPSED:-}" "${GATE_11_ELAPSED:-}" "${GATE_12_ELAPSED:-}" \
|
|
426
|
+
"${GATE_13_ELAPSED:-}"; do
|
|
427
|
+
case "$_xp_floor_n" in
|
|
428
|
+
''|*[!0-9]*) continue ;;
|
|
429
|
+
esac
|
|
430
|
+
if [ "$_xp_floor_n" -gt "${_XP_DURATION_FLOOR:-0}" ]; then
|
|
431
|
+
_XP_DURATION_FLOOR="$_xp_floor_n"
|
|
432
|
+
fi
|
|
433
|
+
done
|
|
434
|
+
unset _xp_floor_n
|
|
435
|
+
case "$_XP_DURATION_FLOOR" in
|
|
436
|
+
''|*[!0-9]*) _XP_DURATION_FLOOR="" ;;
|
|
437
|
+
esac
|
|
438
|
+
if [ -n "$_XP_DURATION_MS" ] && [ -n "$_XP_DURATION_FLOOR" ] \
|
|
439
|
+
&& [ "$_XP_DURATION_MS" -lt "$_XP_DURATION_FLOOR" ]; then
|
|
440
|
+
# Contradiction: the whole is smaller than one of its parts. Report nothing.
|
|
441
|
+
echo " ⚠️ duration_ms rejected: measured ${_XP_DURATION_MS}ms is below the longest gate (${_XP_DURATION_FLOOR}ms) — recording null." >&2
|
|
442
|
+
_XP_DURATION_MS=""
|
|
443
|
+
fi
|
|
444
|
+
_XP_RF="$REPORT_FILE" _XP_PRF="$PERSISTED_REPORT_FILE" _XP_TS="$TIMESTAMP" _XP_BR="$BRANCH" _XP_CH="$COMMIT_HASH" _XP_CF="${CHANGED_FILES:-}" _XP_DUR="$_XP_DURATION_MS" node -e "const fs=require('fs');const e=process.env;const br=JSON.parse(fs.readFileSync(e._XP_RF,'utf8'));const cf=(e._XP_CF||'').split('\n').filter(f=>f);const r={timestamp:e._XP_TS,trigger:'pre-commit',branch:e._XP_BR,commit:e._XP_CH,changed_files:cf,overall:br.overall||{},gates:br.gates||{},warnings:[],errors:[]};const d=Number(e._XP_DUR);if(Number.isFinite(d)&&d>0){r.duration_ms=d;}fs.writeFileSync(e._XP_PRF,JSON.stringify(r,null,2)+'\n');" 2>/dev/null || cp "$REPORT_FILE" "$PERSISTED_REPORT_FILE"
|
|
445
|
+
|
|
446
|
+
# ── History append (unchanged — append-only for trend) ────────────────────────────
|
|
447
|
+
local GATES_JSON="{"
|
|
448
|
+
GATES_JSON="${GATES_JSON}\"gate1\":{\"status\":\"${GATE_1_STATUS:-SKIP}\",\"name\":\"Code Quality\"},"
|
|
449
|
+
GATES_JSON="${GATES_JSON}\"gate2\":{\"status\":\"${GATE_2_STATUS:-SKIP}\",\"name\":\"Duplicate Code\"},"
|
|
450
|
+
GATES_JSON="${GATES_JSON}\"gate3\":{\"status\":\"${GATE_3_STATUS:-SKIP}\",\"name\":\"Complexity\",\"warnings\":${CC_WARNINGS:-0}},"
|
|
451
|
+
GATES_JSON="${GATES_JSON}\"gate4\":{\"status\":\"${GATE_4_STATUS:-SKIP}\",\"name\":\"Principles\",\"warnings\":${WARNING_COUNT:-0}},"
|
|
452
|
+
GATES_JSON="${GATES_JSON}\"gate5\":{\"status\":\"${GATE_5_STATUS:-SKIP}\",\"name\":\"Tests+Coverage\",\"coverage\":\"${COV_PCT}\"},"
|
|
453
|
+
GATES_JSON="${GATES_JSON}\"gate6\":{\"status\":\"${GATE_6_STATUS:-SKIP}\",\"name\":\"Architecture+BoyScout\",\"bsBlocked\":${BS_BLOCKED}},"
|
|
454
|
+
GATES_JSON="${GATES_JSON}\"gate7\":{\"status\":\"${GATE_7_STATUS:-SKIP}\",\"name\":\"IaC Security\"},"
|
|
455
|
+
GATES_JSON="${GATES_JSON}\"gate8\":{\"status\":\"${GATE_8_STATUS:-SKIP}\",\"name\":\"Secret Scanning\"},"
|
|
456
|
+
GATES_JSON="${GATES_JSON}\"gate9\":{\"status\":\"${GATE_9_STATUS:-SKIP}\",\"name\":\"Build Integrity\"},"
|
|
457
|
+
GATES_JSON="${GATES_JSON}\"gate10\":{\"status\":\"${GATE_10_STATUS:-SKIP}\",\"name\":\"SAST Security\"},"
|
|
458
|
+
GATES_JSON="${GATES_JSON}\"gate11\":{\"status\":\"${GATE_11_STATUS:-SKIP}\",\"name\":\"Sprint Flow\"},"
|
|
459
|
+
GATES_JSON="${GATES_JSON}\"gate12\":{\"status\":\"${GATE_12_STATUS:-WARN}\",\"name\":\"File Hygiene\"}}"
|
|
460
|
+
|
|
461
|
+
echo "{\"timestamp\":\"$TIMESTAMP\",\"commit\":\"$COMMIT_HASH\",\"branch\":\"$BRANCH\",\"score\":$SCORE_JSON,\"passed\":$PASSED_COUNT,\"total\":$TOTAL_GATES,\"effectiveTotal\":$EFFECTIVE_TOTAL,\"effectivePassRate\":$EFFECTIVE_PASS_RATE_JSON,\"skipCount\":$SKIP_COUNT,\"verdict\":\"$VERDICT\",\"gates\":$GATES_JSON,\"coverage\":\"$COV_PCT\",\"complexityWarnings\":${CC_WARNINGS:-0},\"principleWarnings\":${WARNING_COUNT:-0},\"boyScoutBlocked\":${BS_BLOCKED}}" >> "$HISTORY_FILE"
|
|
462
|
+
|
|
463
|
+
# ── Console output ────────────────────────────────────────────────────────
|
|
464
|
+
echo ""
|
|
465
|
+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
466
|
+
echo " 📊 Quality Report — $TIMESTAMP"
|
|
467
|
+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
468
|
+
echo ""
|
|
469
|
+
printf " %-45s %s\n" "Gate 1: Code Quality" "${GATE_1_STATUS:-SKIP}"
|
|
470
|
+
printf " %-45s %s\n" "Gate 2: Duplicate Code" "${GATE_2_STATUS:-SKIP}"
|
|
471
|
+
printf " %-45s %s (warnings: ${CC_WARNINGS:-0})\n" "Gate 3: Complexity" "${GATE_3_STATUS:-SKIP}"
|
|
472
|
+
printf " %-45s %s (warnings: ${WARNING_COUNT:-0})\n" "Gate 4: Principles" "${GATE_4_STATUS:-SKIP}"
|
|
473
|
+
# #665: a subset run's percentage describes a SUBSET, not the project, and the
|
|
474
|
+
# global floor was not applied. Printing the bare number next to a PASS reads as
|
|
475
|
+
# "29% passed an 82% floor". Say which population the number came from.
|
|
476
|
+
if [ "${GATE_5_COVERAGE_APPLIES_TO:-project}" = "subset" ]; then
|
|
477
|
+
printf " %-45s %s (coverage: ${COV_PCT}%%, subset run -- global floor not checked)\n" "Gate 5: Tests + Coverage" "${GATE_5_STATUS:-SKIP}"
|
|
478
|
+
else
|
|
479
|
+
printf " %-45s %s (coverage: ${COV_PCT}%%)\n" "Gate 5: Tests + Coverage" "${GATE_5_STATUS:-SKIP}"
|
|
480
|
+
fi
|
|
481
|
+
printf " %-45s %s\n" "Gate 6: Architecture + Boy Scout" "${GATE_6_STATUS:-SKIP}"
|
|
482
|
+
printf " %-45s %s\n" "Gate 7: IaC Security" "${GATE_7_STATUS:-SKIP}"
|
|
483
|
+
printf " %-45s %s\n" "Gate 8: Secret Scanning" "${GATE_8_STATUS:-SKIP}"
|
|
484
|
+
printf " %-45s %s\n" "Gate 9: Build Integrity" "${GATE_9_STATUS:-SKIP}"
|
|
485
|
+
printf " %-45s %s\n" "Gate 10: SAST Security" "${GATE_10_STATUS:-SKIP}"
|
|
486
|
+
printf " %-45s %s\n" "Gate 11: Sprint Flow" "${GATE_11_STATUS:-SKIP}"
|
|
487
|
+
printf " %-45s %s\n" "Gate 12: File Hygiene" "${GATE_12_STATUS:-WARN}"
|
|
488
|
+
# #680: Gate 13 ran and could block, but had no row here -- the table is what a
|
|
489
|
+
# human reads, so a gate missing from it reads as a gate that does not exist.
|
|
490
|
+
printf " %-45s %s\n" "Gate 13: Compiler Strictness" "${GATE_13_STATUS:-SKIP}"
|
|
491
|
+
echo ""
|
|
492
|
+
# #564: both views in one line. The effective score answers "of the gates that
|
|
493
|
+
# could run, how many passed"; the all-gates score counts a skip against the
|
|
494
|
+
# run. Printing only the first let a 1-of-12 run read as 10.0/10.
|
|
495
|
+
echo " Overall Score: $SCORE/10 effective | $SCORE_ALL/10 of all gates ($GATES_RAN/$TOTAL_GATES ran, $SKIP_COUNT skipped, verdict: $VERDICT)"
|
|
496
|
+
echo " Branch status: $REPORT_FILE"
|
|
497
|
+
echo " Run report: $PERSISTED_REPORT_FILE"
|
|
498
|
+
echo " History saved: $HISTORY_FILE"
|
|
499
|
+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
500
|
+
echo ""
|
|
501
|
+
# AI-friendly common footer: tells LLM agents how to fix issues instead of bypassing
|
|
502
|
+
echo " ── AI AGENT DIRECTIVE ──"
|
|
503
|
+
echo " If any gate FAILED above:"
|
|
504
|
+
echo " - Each error includes a file path and rule identifier"
|
|
505
|
+
echo " - Fix each issue, then re-run: git commit"
|
|
506
|
+
echo " - Do NOT use --no-verify — bypassed commits block sprint progression"
|
|
507
|
+
echo " ─────────────────────────"
|
|
508
|
+
echo ""
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
gate_13_run() {
|
|
512
|
+
GATE_13_STATUS="SKIP"
|
|
513
|
+
if [ "${XP_GATE_DISABLE_13:-}" = "1" ]; then
|
|
514
|
+
echo "⏭️ SKIPPED - Gate 13: Compiler Strictness (XP_GATE_DISABLE_13=1)"
|
|
515
|
+
GATE_13_STATUS="SKIP"
|
|
516
|
+
elif [ -f "$GATE_DIR/gate-13-compiler-strictness.sh" ] || [ -f "$(git rev-parse --show-toplevel 2>/dev/null)/githooks/gate-13-compiler-strictness.sh" ]; then
|
|
517
|
+
echo "⚙️ Gate 13: Compiler Strictness Check..."
|
|
518
|
+
GATE13_START=$(gate_start_ms)
|
|
519
|
+
(
|
|
520
|
+
# Each stage runs inside the subshell so its shell state cannot leak back
|
|
521
|
+
# into pre-commit. Verdicts are reduced to the WORST code seen:
|
|
522
|
+
# FAIL/BLOCK (1/2) always win; WARN (3) only beats PASS (0).
|
|
523
|
+
_g13_script="$GATE_DIR/gate-13-compiler-strictness.sh"
|
|
524
|
+
[ -f "$_g13_script" ] || _g13_script="$(git rev-parse --show-toplevel)/githooks/gate-13-compiler-strictness.sh"
|
|
525
|
+
# shellcheck source=/dev/null
|
|
526
|
+
. "$_g13_script"
|
|
527
|
+
|
|
528
|
+
_g13_worst=0
|
|
529
|
+
_g13_rc=0
|
|
530
|
+
_g13_note() {
|
|
531
|
+
case "$1" in
|
|
532
|
+
1|2) _g13_worst=$1 ;;
|
|
533
|
+
3) [ "$_g13_worst" -eq 0 ] && _g13_worst=3 ;;
|
|
534
|
+
esac
|
|
535
|
+
return 0
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
gate13_run_cpp_analysis; _g13_rc=$?; _g13_note "$_g13_rc"
|
|
539
|
+
gate13_run_java_analysis; _g13_rc=$?; _g13_note "$_g13_rc"
|
|
540
|
+
# #717: C# joins the same reduce-the-worst loop. Without this call the
|
|
541
|
+
# function would exist but never execute -- the "silently skipped" shape
|
|
542
|
+
# #717 is about, one level up.
|
|
543
|
+
gate13_run_csharp_analysis; _g13_rc=$?; _g13_note "$_g13_rc"
|
|
544
|
+
gate13_run_analyzer; _g13_rc=$?; _g13_note "$_g13_rc"
|
|
545
|
+
|
|
546
|
+
exit "$_g13_worst"
|
|
547
|
+
)
|
|
548
|
+
GATE_13_RC=$?
|
|
549
|
+
GATE13_END=$(now_ms)
|
|
550
|
+
GATE_13_DURATION=$(( (GATE13_END - GATE13_START) / 1000 ))
|
|
551
|
+
case "$GATE_13_RC" in
|
|
552
|
+
0) GATE_13_STATUS="PASS" ;;
|
|
553
|
+
1) GATE_13_STATUS="FAIL" ;;
|
|
554
|
+
2) GATE_13_STATUS="BLOCK" ;;
|
|
555
|
+
*) GATE_13_STATUS="WARN" ;;
|
|
556
|
+
esac
|
|
557
|
+
echo " Gate 13 ($GATE_13_STATUS) completed in ${GATE_13_DURATION}s"
|
|
558
|
+
record_gate_audit "gate-13" "compiler-strictness" "$GATE_13_STATUS" "0" "$GATE13_START"
|
|
559
|
+
# Every other gate blocks by exiting immediately (e.g. Gate 1's
|
|
560
|
+
# "❌ BLOCKED ... exit 1"); there is no aggregate-then-exit shared with
|
|
561
|
+
# gates 0-12, so Gate 13 must do the same or its FAIL would only be cosmetic
|
|
562
|
+
# in the report while the commit sails through.
|
|
563
|
+
if [ "$GATE_13_STATUS" = "FAIL" ] || [ "$GATE_13_STATUS" = "BLOCK" ]; then
|
|
564
|
+
echo ""
|
|
565
|
+
echo "❌ BLOCKED - Gate 13: Compiler Strictness (${GATE_13_STATUS})"
|
|
566
|
+
echo " Fix the compiler findings above. To record pre-existing warnings:"
|
|
567
|
+
echo " xp-gate compiler-baseline create"
|
|
568
|
+
echo " To relax strictness: XP_GATE_COMPILER_STRICTNESS=warn-only"
|
|
569
|
+
echo " Emergency only: XP_GATE_DISABLE_13=1"
|
|
570
|
+
return 1
|
|
571
|
+
fi
|
|
572
|
+
else
|
|
573
|
+
echo "⏭️ SKIPPED - Gate 13: Compiler Strictness (gate-13-compiler-strictness.sh not found)"
|
|
574
|
+
GATE_13_STATUS="SKIP"
|
|
575
|
+
fi
|
|
576
|
+
echo ""
|
|
577
|
+
# ============================================================================
|
|
578
|
+
|
|
579
|
+
return 0
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
# Called by pre-commit's ordered driver.
|
|
584
|
+
|