@boyingliu01/xp-gate 0.36.1 → 0.37.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/adapters/cpp.sh +78 -10
- package/adapters/csharp.sh +58 -3
- package/adapters/gate-3.sh +15 -5
- package/adapters/gate-8.sh +131 -9
- package/adapters/typescript.sh +32 -8
- package/build-integrity/__tests__/import-resolver.test.ts +257 -0
- package/build-integrity/__tests__/quote-masker.test.ts +177 -0
- package/build-integrity/gate-10.ts +127 -9
- package/build-integrity/quote-masker.ts +266 -0
- package/gate-10.sh +66 -0
- package/gate-12-file-hygiene.sh +15 -7
- package/gate-13-compiler-strictness.sh +81 -1
- package/gate-3.sh +15 -5
- package/gate-6-layers.sh +375 -0
- package/gate-8.sh +131 -9
- package/hooks/gate-10.sh +66 -0
- package/hooks/gate-12-file-hygiene.sh +15 -7
- package/hooks/gate-13-compiler-strictness.sh +81 -1
- package/hooks/gate-3.sh +15 -5
- package/hooks/gate-6-layers.sh +375 -0
- package/hooks/gate-8.sh +131 -9
- package/hooks/gate-registry.sh +2 -2
- package/hooks/hook-module-resolution.sh +1 -1
- package/hooks/lib/assertion-quality.sh +8 -2
- package/hooks/lib/ccn-ratchet.sh +10 -0
- package/hooks/lib/layer-baseline.cjs +88 -0
- package/hooks/lib/typecheck.sh +28 -5
- package/hooks/pre-commit +376 -53
- package/hooks/pre-push +46 -13
- package/lib/__tests__/agent-runtime-journal.test.js +1 -1
- package/lib/__tests__/arch.test.js +9 -0
- package/lib/__tests__/audit-cli-contract.test.ts +1 -1
- package/lib/__tests__/check-alignment-reasons.test.mjs +11 -1
- package/lib/__tests__/check-all-skip-accounting.test.js +1 -1
- package/lib/__tests__/detect-deps-gate-identity.test.js +135 -0
- package/lib/__tests__/detect-deps.test.js +2 -1
- package/lib/__tests__/doctor-469-hook-env.test.js +7 -1
- package/lib/__tests__/doctor-arch-tools.test.js +169 -0
- package/lib/__tests__/doctor-delphi.test.js +1 -1
- package/lib/__tests__/doctor-drift-round2.test.js +4 -1
- package/lib/__tests__/doctor-executed-surface.test.js +45 -24
- package/lib/__tests__/doctor-module-drift.test.js +13 -7
- package/lib/__tests__/doctor-module-resolution-parity.test.js +74 -2
- package/lib/__tests__/doctor-tui-skill-freshness.test.js +21 -6
- package/lib/__tests__/doctor.test.js +17 -0
- package/lib/__tests__/gate-runner-tsx-invocation.test.js +149 -0
- package/lib/__tests__/gate-runner.test.js +23 -7
- package/lib/__tests__/init-gitignore.test.js +204 -0
- package/lib/__tests__/init.test.js +24 -3
- package/lib/__tests__/language-tools-build-file-install.test.js +82 -0
- package/lib/__tests__/language-tools-detect.test.js +61 -0
- package/lib/__tests__/mirror-sync.test.js +2 -0
- package/lib/__tests__/phase-transition.test.js +19 -1
- package/lib/__tests__/sprint-status-rework.test.js +32 -12
- package/lib/__tests__/test-alignment-range-guard.test.ts +82 -0
- package/lib/__tests__/test-alignment.test.ts +13 -3
- package/lib/__tests__/update-skill.test.js +2 -2
- package/lib/detect-deps.js +7 -1
- package/lib/doctor.js +81 -17
- package/lib/gate-runner.js +101 -7
- package/lib/hook-module-resolution.js +18 -6
- package/lib/init.js +136 -1
- package/lib/language-tools.js +217 -1
- package/lib/layer-baseline.cjs +88 -0
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/principles.js +21 -6
- package/lib/test-alignment.ts +452 -55
- package/mock-policy/AGENTS.md +1 -1
- package/mutation/AGENTS.md +1 -1
- package/package.json +2 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +34 -24
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/delphi-review/INSTALL.md +29 -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/.delphi-config.json.example +34 -24
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/delphi-review/INSTALL.md +29 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/src/client.test.ts +1 -1
- package/plugins/dsh/src/command.test.ts +1 -1
- package/plugins/dsh/src/contract.test.ts +1 -1
- package/plugins/dsh/src/credentials.test.ts +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +34 -24
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/delphi-review/INSTALL.md +29 -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/.delphi-config.json.example +34 -24
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/delphi-review/INSTALL.md +29 -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__/config-arch-group.test.ts +106 -0
- package/principles/__tests__/config-enforcement.test.ts +1 -1
- package/principles/adapters/control-nesting.ts +572 -0
- package/principles/adapters/csharp.ts +73 -42
- package/principles/adapters/java.ts +9 -5
- package/principles/adapters/typescript.ts +138 -176
- package/principles/config.ts +37 -2
- package/principles/index.ts +57 -4
- package/principles/reporter.ts +99 -65
- package/principles/rules/arch/__tests__/dependency.test.ts +180 -0
- package/principles/rules/arch/__tests__/naming.test.ts +133 -0
- package/principles/rules/arch/__tests__/shared.test.ts +113 -0
- package/principles/rules/arch/dependency.ts +264 -0
- package/principles/rules/arch/naming.ts +188 -0
- package/principles/rules/arch/shared.ts +169 -0
- package/principles/rules/exports.ts +26 -0
- package/principles/rules/index.ts +11 -18
- package/scripts/__tests__/sync-package-content.test.js +23 -1
- package/scripts/sync-package-content.js +8 -2
- package/skills/delphi-review/.delphi-config.json.example +34 -24
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/delphi-review/INSTALL.md +29 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
package/adapters/cpp.sh
CHANGED
|
@@ -10,20 +10,88 @@ _detect_cpp_build() {
|
|
|
10
10
|
fi
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
# verdict codes consumed by Gate 1 (#776):
|
|
14
|
+
# 0 = clean 1 = ran and found diagnostics 2 = could not execute (fail-closed)
|
|
15
|
+
#
|
|
16
|
+
# The old body piped the analyzer into `sed` and then returned 0 unconditionally,
|
|
17
|
+
# so clang-tidy/cppcheck findings were *displayed and discarded*. Both tools exit
|
|
18
|
+
# non-zero when they have anything to report, which made that the only possible
|
|
19
|
+
# answer: a C/C++ project had no working Gate 1 at all, no matter what the hook
|
|
20
|
+
# did with the verdict. Hence: capture into a variable, keep the status, and use
|
|
21
|
+
# 2 -- not 1 -- for "no tooling", because "I could not run anything" must not be
|
|
22
|
+
# indistinguishable from "I ran it and it was clean".
|
|
13
23
|
run_static_analysis() {
|
|
24
|
+
local files out rc db
|
|
25
|
+
|
|
14
26
|
if command -v clang-tidy &>/dev/null; then
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
# Parentheses around the -o chain: without them `2>/dev/null` binds only to
|
|
28
|
+
# the last predicate and find still prints "No such file" noise for the rest.
|
|
29
|
+
files=$(find . \( -name '*.cpp' -o -name '*.cc' -o -name '*.cxx' -o -name '*.c' -o -name '*.h' -o -name '*.hpp' \) \
|
|
30
|
+
-not -path './.git/*' -not -path './build/*' 2>/dev/null | head -20)
|
|
31
|
+
if [ -z "$files" ]; then
|
|
32
|
+
echo "No C/C++ sources to analyse"
|
|
33
|
+
return 2
|
|
19
34
|
fi
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
# clang-tidy needs a compilation database to know the include paths, and it
|
|
36
|
+
# needs an explicit check set or it aborts with "no checks enabled" + usage.
|
|
37
|
+
# Both failure modes exit non-zero on a CLEAN tree, which under the fixed
|
|
38
|
+
# gate would be a false BLOCK rather than a false pass. Detect "the tool
|
|
39
|
+
# refused to run" and hand the job to cppcheck, which needs no database.
|
|
40
|
+
db=""
|
|
41
|
+
for candidate in compile_commands.json build/compile_commands.json; do
|
|
42
|
+
if [ -f "$candidate" ]; then db="$candidate"; break; fi
|
|
43
|
+
done
|
|
44
|
+
if [ -n "$db" ]; then
|
|
45
|
+
out=$(printf '%s\n' "$files" | xargs clang-tidy -p "$(dirname "$db")" 2>&1)
|
|
46
|
+
rc=$?
|
|
47
|
+
else
|
|
48
|
+
# No database: a fixed, conservative check set beats clang-tidy's defaults
|
|
49
|
+
# (which are empty). `bugprone-*` + `clang-analyzer-*` are the tiers that
|
|
50
|
+
# catch the same class of defect as a compiler with -Wall -Wextra without
|
|
51
|
+
# demanding a style config the project never agreed to.
|
|
52
|
+
out=$(printf '%s\n' "$files" | xargs clang-tidy \
|
|
53
|
+
--checks='-*,bugprone-*,clang-analyzer-*' -- 2>&1)
|
|
54
|
+
rc=$?
|
|
55
|
+
fi
|
|
56
|
+
printf '%s\n' "$out" | head -20
|
|
57
|
+
if printf '%s\n' "$out" | grep -q 'no compilation database\|No compilation database\|no checks enabled\|USAGE: clang-tidy'; then
|
|
58
|
+
echo "clang-tidy could not establish a usable configuration for this tree"
|
|
59
|
+
if command -v cppcheck &>/dev/null; then
|
|
60
|
+
echo " Falling back to cppcheck"
|
|
61
|
+
_cppcheck_run
|
|
62
|
+
return $?
|
|
63
|
+
fi
|
|
64
|
+
return 2
|
|
65
|
+
fi
|
|
66
|
+
return "$rc"
|
|
25
67
|
fi
|
|
26
|
-
|
|
68
|
+
|
|
69
|
+
if command -v cppcheck &>/dev/null; then
|
|
70
|
+
_cppcheck_run
|
|
71
|
+
return $?
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
echo "No C/C++ analysis tools (clang-tidy/cppcheck)"
|
|
75
|
+
return 2
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
# cppcheck exits 0 by default *even when it reports errors* -- the verdict has to
|
|
79
|
+
# be requested explicitly. --error-exitcode makes "found something" non-zero while
|
|
80
|
+
# leaving "ran fine" at 0, which is exactly the 0/1 split Gate 1 consumes. Only
|
|
81
|
+
# `error` severity trips it; `warning`/`style`/`performance` stay informational so
|
|
82
|
+
# that a first adoption of the gate is not flooded by false positives.
|
|
83
|
+
_cppcheck_run() {
|
|
84
|
+
local out rc
|
|
85
|
+
out=$(cppcheck --enable=warning,performance,portability --inline-suppr --quiet \
|
|
86
|
+
--error-exitcode=1 --suppress=missingIncludeSystem . 2>&1)
|
|
87
|
+
rc=$?
|
|
88
|
+
printf '%s\n' "$out" | head -20
|
|
89
|
+
# 1 = findings; anything else cppcheck-specific (e.g. 2 = internal error) is
|
|
90
|
+
# "could not execute" territory, which Gate 1 treats as fail-closed.
|
|
91
|
+
case "$rc" in
|
|
92
|
+
0|1) return "$rc" ;;
|
|
93
|
+
*) return 2 ;;
|
|
94
|
+
esac
|
|
27
95
|
}
|
|
28
96
|
|
|
29
97
|
run_lint() {
|
package/adapters/csharp.sh
CHANGED
|
@@ -211,6 +211,20 @@ run_tests() {
|
|
|
211
211
|
# Silently returning 0 here would let Gate 5 read "no coverage file" as "no
|
|
212
212
|
# coverage requirement". The output just tells the caller which artifact the
|
|
213
213
|
# gate is looking for; the threshold verdict stays with the caller.
|
|
214
|
+
# Newest coverage.cobertura.xml under $1, honouring an optional find time filter
|
|
215
|
+
# in $2. Extracted so the "which report is the current one" rule lives in one
|
|
216
|
+
# place: run_coverage and Gate 5's own discovery must agree, or the adapter and
|
|
217
|
+
# the gate will quote different numbers for the same run.
|
|
218
|
+
_csharp_newest_cobertura() {
|
|
219
|
+
local root="$1" time_filter="${2:-}"
|
|
220
|
+
# shellcheck disable=SC2086 # $time_filter is deliberately word-split
|
|
221
|
+
find "$root" -name "coverage.cobertura.xml" -type f $time_filter 2>/dev/null \
|
|
222
|
+
| while IFS= read -r f; do
|
|
223
|
+
printf '%s\t%s\n' "$(stat -c %Y "$f" 2>/dev/null || stat -f %m "$f" 2>/dev/null || echo 0)" "$f"
|
|
224
|
+
done \
|
|
225
|
+
| sort -rn | head -1 | cut -f2-
|
|
226
|
+
}
|
|
227
|
+
|
|
214
228
|
run_coverage() {
|
|
215
229
|
local dotnet_root dotnet
|
|
216
230
|
dotnet_root=$(_detect_dotnet_root) || { echo "No .NET project marker found"; return 0; }
|
|
@@ -223,16 +237,57 @@ run_coverage() {
|
|
|
223
237
|
return 2
|
|
224
238
|
fi
|
|
225
239
|
|
|
240
|
+
# A project that ships its own .runsettings must be honoured. Coverlet's
|
|
241
|
+
# defaults (IncludeTestAssembly=false, no Include filter) are wrong for any
|
|
242
|
+
# solution whose tests link the production sources via <Compile Include> rather
|
|
243
|
+
# than project-referencing them: the assembly under test IS the test assembly,
|
|
244
|
+
# so coverlet instruments nothing and writes a syntactically valid report with
|
|
245
|
+
# line-rate="0" and an EMPTY <packages/>. Gate 5 then blocks on "0% coverage"
|
|
246
|
+
# for a suite that measures 67% when run the project's own way -- a false
|
|
247
|
+
# negative that looks exactly like a real coverage failure.
|
|
248
|
+
#
|
|
249
|
+
# Measured on dsh-aot-runner: without --settings the report was
|
|
250
|
+
# `<coverage line-rate="0" ... lines-valid="0">` with `<packages />`; with the
|
|
251
|
+
# project's runsettings the same command produced line-rate="0.6724".
|
|
252
|
+
local settings_arg="" rs
|
|
253
|
+
for rs in tests/*/coverage.runsettings tests/coverage.runsettings \
|
|
254
|
+
coverage.runsettings .runsettings coverage/.runsettings; do
|
|
255
|
+
if [ -f "$rs" ]; then settings_arg="--settings $rs"; break; fi
|
|
256
|
+
done
|
|
257
|
+
if [ -z "$settings_arg" ]; then
|
|
258
|
+
# Fall back to any runsettings anywhere in the tree before giving up.
|
|
259
|
+
rs=$(find . -name '*.runsettings' -type f -not -path './.git/*' 2>/dev/null \
|
|
260
|
+
| while IFS= read -r f; do printf '%s\t%s\n' "$(stat -c %Y "$f" 2>/dev/null || stat -f %m "$f" 2>/dev/null || echo 0)" "$f"; done \
|
|
261
|
+
| sort -rn | head -1 | cut -f2-)
|
|
262
|
+
[ -n "$rs" ] && settings_arg="--settings $rs"
|
|
263
|
+
fi
|
|
264
|
+
if [ -n "$settings_arg" ]; then
|
|
265
|
+
echo " Using project runsettings: ${settings_arg#--settings }"
|
|
266
|
+
fi
|
|
267
|
+
|
|
226
268
|
echo "Collecting coverage: dotnet test --collect:\"XPlat Code Coverage\""
|
|
227
269
|
local out rc
|
|
228
|
-
|
|
270
|
+
# shellcheck disable=SC2086 # $settings_arg is deliberately word-split
|
|
271
|
+
out=$("$dotnet" test "$test_proj" --nologo --collect:"XPlat Code Coverage" $settings_arg 2>&1)
|
|
229
272
|
rc=$?
|
|
230
273
|
printf '%s\n' "$out" | sed -n '1,15p'
|
|
231
274
|
|
|
275
|
+
# #768: pick the report THIS run produced, not an arbitrary one.
|
|
276
|
+
#
|
|
277
|
+
# `find ... | sed -n '1p; 1q'` returned whichever directory the filesystem
|
|
278
|
+
# enumerated first. TestResults accumulates one <guid>/ per run, so after a
|
|
279
|
+
# second run the "first" hit can be an earlier run's report -- and when that run
|
|
280
|
+
# was from a different test target, its report legitimately says 0%. Measured on
|
|
281
|
+
# a real repo: live coverage was 67%, the adapter announced the stale 0% report,
|
|
282
|
+
# and Gate 5 blocked with "csharp coverage 0% below 80% threshold".
|
|
283
|
+
#
|
|
284
|
+
# Sort by modification time so "the report" means "the one just written". The
|
|
285
|
+
# stat arm is guarded for both GNU (-c) and BSD/macOS (-f) spellings, with 0 as
|
|
286
|
+
# a last resort so an unsupported stat cannot empty the list.
|
|
232
287
|
local report
|
|
233
|
-
report=$(
|
|
288
|
+
report=$(_csharp_newest_cobertura "$dotnet_root" "-newermt -10 minutes")
|
|
234
289
|
if [ -z "$report" ]; then
|
|
235
|
-
report=$(
|
|
290
|
+
report=$(_csharp_newest_cobertura "$dotnet_root" "")
|
|
236
291
|
fi
|
|
237
292
|
|
|
238
293
|
if [ -z "$report" ]; then
|
package/adapters/gate-3.sh
CHANGED
|
@@ -350,7 +350,7 @@ else
|
|
|
350
350
|
}
|
|
351
351
|
|
|
352
352
|
CCN_THRESHOLD=$(resolve_ccn_threshold)
|
|
353
|
-
|
|
353
|
+
|
|
354
354
|
# Check lizard availability
|
|
355
355
|
LIZARD_CMD=""
|
|
356
356
|
if command -v lizard > /dev/null 2>&1; then
|
|
@@ -358,10 +358,10 @@ else
|
|
|
358
358
|
elif [ -f ~/.local/bin/lizard ]; then
|
|
359
359
|
LIZARD_CMD=~/.local/bin/lizard
|
|
360
360
|
fi
|
|
361
|
-
|
|
361
|
+
|
|
362
362
|
if [ -n "$LIZARD_CMD" ]; then
|
|
363
363
|
LIZARD_PATH=$(eval echo "$LIZARD_CMD")
|
|
364
|
-
|
|
364
|
+
|
|
365
365
|
# Get changed source files for complexity check (includes test files)
|
|
366
366
|
CC_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs)$' || true)
|
|
367
367
|
|
|
@@ -398,7 +398,7 @@ else
|
|
|
398
398
|
|
|
399
399
|
if [ -n "$CC_FILES" ]; then
|
|
400
400
|
echo "Checking complexity for source files..."
|
|
401
|
-
|
|
401
|
+
|
|
402
402
|
# Run lizard in chunks. Two reasons, both load-bearing:
|
|
403
403
|
# - One path per line, into an array. Unquoted $CC_FILES relied on word
|
|
404
404
|
# splitting, which also splits any path containing a space -- handing
|
|
@@ -595,7 +595,17 @@ CC_POP_EOF
|
|
|
595
595
|
# contain a function. If it produces rows, lizard works and the input
|
|
596
596
|
# simply had no functions (SKIP, `no_functions_in_input`); if it does not,
|
|
597
597
|
# the tool really is broken (WARN, `lizard_output_unparsable`).
|
|
598
|
-
|
|
598
|
+
#
|
|
599
|
+
# #774: the probe must read the WHOLE stream. It used to `exit` on the
|
|
600
|
+
# first matching row, which left `printf` writing into a closed pipe; under
|
|
601
|
+
# the hook's `set -o pipefail` the pipeline then reported SIGPIPE (141)
|
|
602
|
+
# instead of awk's 0, and a run with 26 above-threshold functions announced
|
|
603
|
+
# itself as "no functions (pure data module)". Measured: the flip happens
|
|
604
|
+
# once the CSV exceeds the 64 KB pipe buffer -- 24 changed source files were
|
|
605
|
+
# enough -- and it is timing-dependent, so the same commit could pass or
|
|
606
|
+
# skip. Counting through to END also drops the dependency on how much stdin
|
|
607
|
+
# happened to be buffered.
|
|
608
|
+
if ! printf '%s\n' "$CC_CSV_FLAT" | awk -F, 'NF > 1 && $2 ~ /^[0-9]+$/ { found = 1 }
|
|
599
609
|
END { exit(found ? 0 : 1) }'; then
|
|
600
610
|
_lizard_probe_dir=$(mktemp -d 2>/dev/null || echo "${TMPDIR:-/tmp}")
|
|
601
611
|
_lizard_probe_file="$_lizard_probe_dir/xp-gate-lizard-probe.py"
|
package/adapters/gate-8.sh
CHANGED
|
@@ -11,6 +11,25 @@
|
|
|
11
11
|
2>&1 echo "→ Gate 8: Secret scanning (gitleaks + detect-secrets)..."
|
|
12
12
|
GATE_8_START=$(gate_start_ms)
|
|
13
13
|
|
|
14
|
+
# Temp files created below (the normalized-baseline copy and the hook output)
|
|
15
|
+
# are registered here and removed by this EXIT trap. Installed at FILE scope
|
|
16
|
+
# because a trap body runs at exit time, when a function-local variable is no
|
|
17
|
+
# longer visible — the first cleanup attempt called a function that read a
|
|
18
|
+
# function-local DS_BASELINE and therefore removed nothing.
|
|
19
|
+
#
|
|
20
|
+
# An ARRAY, not a space-separated string: `rm -f $LIST` word-splits, so a
|
|
21
|
+
# TMPDIR containing a space (`/c/Users/Some Name/...` is entirely ordinary on
|
|
22
|
+
# Windows) would be torn into fragments, none of which exist, and every gated
|
|
23
|
+
# commit would leak one temp file again — the exact failure this trap exists to
|
|
24
|
+
# prevent.
|
|
25
|
+
GATE8_TEMP=()
|
|
26
|
+
gate8_cleanup() {
|
|
27
|
+
if [ "${#GATE8_TEMP[@]}" -gt 0 ]; then
|
|
28
|
+
rm -f "${GATE8_TEMP[@]}" 2>/dev/null
|
|
29
|
+
fi
|
|
30
|
+
}
|
|
31
|
+
trap gate8_cleanup EXIT
|
|
32
|
+
|
|
14
33
|
# Gitleaks availability check
|
|
15
34
|
GITLEAKS_CMD=""
|
|
16
35
|
if command -v gitleaks >/dev/null 2>&1; then
|
|
@@ -196,35 +215,138 @@ fi
|
|
|
196
215
|
# both detect-secrets-hook and .secrets.baseline. The pipeline lives inside an
|
|
197
216
|
# if-condition (errexit-exempt); a non-zero hook exit lands in the else branch.
|
|
198
217
|
if command -v detect-secrets-hook >/dev/null 2>&1 && [ -f ".secrets.baseline" ]; then
|
|
218
|
+
# #735: normalize path separators BEFORE comparing against the baseline.
|
|
219
|
+
# detect-secrets writes backslash paths on Windows and forward slashes on
|
|
220
|
+
# Linux, and the baseline is committed, so the two forms fight: a Windows scan
|
|
221
|
+
# rewrites ~322 lines, a Linux run rewrites them back, and every commit
|
|
222
|
+
# carries a pure formatting diff. That destroys the only signal the baseline
|
|
223
|
+
# has - "did a NEW secret appear" - because a real new entry no longer stands
|
|
224
|
+
# out from churn. Normalizing HERE (not only in the repair hint) makes the
|
|
225
|
+
# comparison see one canonical form regardless of which platform last touched
|
|
226
|
+
# the file.
|
|
227
|
+
#
|
|
228
|
+
# Two traps had to be handled, both found by RUNNING it rather than reading it:
|
|
229
|
+
# (1) this script lives at different depths in the source tree
|
|
230
|
+
# (githooks/adapters/) and in the install (~/.config/xp-gate/adapters/), so
|
|
231
|
+
# a fixed ../../ silently resolved to nothing in the installed copy;
|
|
232
|
+
# (2) on Git Bash the resolved path is POSIX-style (/c/Users/...), and handing
|
|
233
|
+
# it to the native node.exe makes MSYS rewrite it into D:\c\Users\... -
|
|
234
|
+
# node then dies with MODULE_NOT_FOUND, which `|| true` swallowed. The
|
|
235
|
+
# gate looked patched and normalised nothing at all.
|
|
236
|
+
# Hence: probe several layouts, then cygpath the winner to a Windows path.
|
|
237
|
+
# Best-effort on purpose - a missing node or unparsable baseline must let the
|
|
238
|
+
# hook speak, never abort the gate silently.
|
|
239
|
+
ds_norm=""
|
|
240
|
+
ds_here="$(dirname "${BASH_SOURCE[0]}")"
|
|
241
|
+
for cand in "$ds_here/../../scripts/normalize-secrets-baseline.cjs" "$ds_here/../scripts/normalize-secrets-baseline.cjs" "$XP_GATE_HOME/scripts/normalize-secrets-baseline.cjs"; do
|
|
242
|
+
if [ -n "$cand" ] && [ -f "$cand" ]; then ds_norm="$cand"; break; fi
|
|
243
|
+
done
|
|
244
|
+
# Normalize a TEMP COPY, never the tracked file.
|
|
245
|
+
#
|
|
246
|
+
# The first version rewrote `.secrets.baseline` in place and did not re-stage
|
|
247
|
+
# it, so the commit still carried the mixed-separator version (#735 relocated
|
|
248
|
+
# rather than resolved) and every gated commit left a tracked file dirty for a
|
|
249
|
+
# reason the user never asked for. Comparing against a normalized copy leaves
|
|
250
|
+
# the working tree untouched and makes the guarantee unconditional: the
|
|
251
|
+
# comparison always sees one canonical form, whether or not the committed
|
|
252
|
+
# baseline is clean.
|
|
253
|
+
DS_BASELINE=".secrets.baseline"
|
|
254
|
+
# Every degradation path below prints WHY, including the two that are not
|
|
255
|
+
# failures: a missing normalizer or a missing node used to fall through in
|
|
256
|
+
# total silence, so the comparison ran on mixed separators and a resulting
|
|
257
|
+
# BLOCK read as "found secrets" with no way to connect it to the real cause.
|
|
258
|
+
# #735 is precisely about that mismatch, so it must never be invisible.
|
|
259
|
+
if [ -z "$ds_norm" ]; then
|
|
260
|
+
echo " ⚠️ baseline normalizer not found (looked next to the hook, in"
|
|
261
|
+
echo " ../scripts and \$XP_GATE_HOME/scripts) — comparing with the"
|
|
262
|
+
echo " committed separators; Windows/Linux baselines may disagree."
|
|
263
|
+
elif ! command -v node >/dev/null 2>&1; then
|
|
264
|
+
echo " ⚠️ node not found — cannot normalize the detect-secrets baseline;"
|
|
265
|
+
echo " comparing with the committed separators."
|
|
266
|
+
else
|
|
267
|
+
ds_norm_arg="$ds_norm"
|
|
268
|
+
if command -v cygpath >/dev/null 2>&1; then
|
|
269
|
+
ds_norm_arg="$(cygpath -w "$ds_norm" 2>/dev/null || printf '%s' "$ds_norm")"
|
|
270
|
+
fi
|
|
271
|
+
# The copy lives next to the original, not in $TMPDIR. Two different path
|
|
272
|
+
# dialects consume this one path: node.exe is native and needs a Windows
|
|
273
|
+
# form, while detect-secrets-hook is a Python script that resolves the path
|
|
274
|
+
# itself and REJECTS the Windows form ("Invalid path"). A bare filename in
|
|
275
|
+
# the current directory is the only spelling both accept, and it is also
|
|
276
|
+
# what `git add`/`git status` see, so the file is unmistakably temporary.
|
|
277
|
+
DS_BASELINE=".secrets.baseline.gate8.$$"
|
|
278
|
+
# Register BEFORE creating it. Registering after a successful `cp` leaves a
|
|
279
|
+
# window in which a signal or an errexit abort between the two lines leaves
|
|
280
|
+
# the copy on disk with nothing tracking it — the trap only removes what it
|
|
281
|
+
# knows about. rm -f on a name that was never created is a no-op, so the
|
|
282
|
+
# early registration costs nothing.
|
|
283
|
+
GATE8_TEMP+=("$DS_BASELINE")
|
|
284
|
+
if ! cp .secrets.baseline "$DS_BASELINE" 2>/dev/null; then
|
|
285
|
+
DS_BASELINE=".secrets.baseline"
|
|
286
|
+
fi
|
|
287
|
+
if [ "$DS_BASELINE" != ".secrets.baseline" ]; then
|
|
288
|
+
# NOT `>/dev/null 2>&1 || true`: that swallowed exit 2 (unparsable JSON)
|
|
289
|
+
# and any runtime throw, so the gate reported a clean comparison while the
|
|
290
|
+
# copy had never been normalized — the same "looked patched, did nothing"
|
|
291
|
+
# shape the path probing above exists to fix. A failure is now VISIBLE.
|
|
292
|
+
# `if !` rather than `cmd; rc=$?` because the enclosing hook may run under
|
|
293
|
+
# errexit, where a bare failing assignment would abort before the message
|
|
294
|
+
# could print.
|
|
295
|
+
if ! ds_norm_out="$(node "$ds_norm_arg" "$DS_BASELINE" 2>&1)"; then
|
|
296
|
+
echo " ⚠️ detect-secrets baseline NOT normalized; comparing with"
|
|
297
|
+
echo " whatever separators the committed file uses. Reason:"
|
|
298
|
+
printf '%s
|
|
299
|
+
' "$ds_norm_out" | sed 's/^/ /'
|
|
300
|
+
fi
|
|
301
|
+
fi
|
|
302
|
+
fi
|
|
303
|
+
# The normalized copy and the hook output are both temp files. The first
|
|
304
|
+
# version of this block removed neither DS_BASELINE (leaked one copy PER
|
|
305
|
+
# gated commit) nor DS_TMP on the early `exit 1` paths. They are registered in
|
|
306
|
+
# the global GATE8_TEMP list, which the EXIT trap installed at the top of this
|
|
307
|
+
# file cleans up — a trap calling a function that reads a FUNCTION-LOCAL
|
|
308
|
+
# variable sees an empty value at exit time, which is exactly how the first
|
|
309
|
+
# fix attempt silently cleaned nothing.
|
|
199
310
|
DS_TMP="$(dirname "$(mktemp -u)")/ds-output.$$"
|
|
311
|
+
GATE8_TEMP+=("$DS_TMP")
|
|
200
312
|
# #616: same scope split as the gitleaks call above. Under `--all` the index is
|
|
201
313
|
# usually empty, so piping `git diff --cached -z` into xargs fed the hook zero
|
|
202
314
|
# files and it reported success without reading anything.
|
|
203
315
|
if [ "${GATE_SCOPE:-diff}" = "all" ]; then
|
|
204
|
-
if git ls-files -z | xargs -0 detect-secrets-hook --baseline
|
|
316
|
+
if git ls-files -z | xargs -0 detect-secrets-hook --baseline "$DS_BASELINE" > "$DS_TMP" 2>&1; then
|
|
205
317
|
echo " ✅ detect-secrets PASSED - no new secrets beyond baseline (scope: --all)."
|
|
206
318
|
else
|
|
207
319
|
cat "$DS_TMP"
|
|
208
320
|
echo ""
|
|
209
321
|
echo " ❌ BLOCKED - detect-secrets found secrets not in .secrets.baseline."
|
|
210
|
-
echo " If these are false positives,
|
|
211
|
-
echo " detect-secrets scan --
|
|
212
|
-
|
|
322
|
+
echo " If these are false positives, mark them in the baseline:"
|
|
323
|
+
echo " detect-secrets scan --baseline .secrets.baseline && git add .secrets.baseline"
|
|
324
|
+
echo " (--update does not exist; detect-secrets exits with"
|
|
325
|
+
echo " \"unrecognized arguments: --update\".)"
|
|
326
|
+
echo " Then REVIEW the diff: scan --baseline re-scans the WHOLE tree, whereas"
|
|
327
|
+
echo " this gate only inspects changed files. A whole-tree scan can silently"
|
|
328
|
+
echo " drop the entries of files it no longer reaches, un-allowlisting a"
|
|
329
|
+
echo " historical finding. Commit the baseline alone so that stays visible."
|
|
213
330
|
exit 1
|
|
214
331
|
fi
|
|
215
332
|
elif git diff --cached --name-only --diff-filter=ACM -z \
|
|
216
|
-
| xargs -0 detect-secrets-hook --baseline
|
|
333
|
+
| xargs -0 detect-secrets-hook --baseline "$DS_BASELINE" > "$DS_TMP" 2>&1; then
|
|
217
334
|
echo " ✅ detect-secrets PASSED - no new secrets beyond baseline."
|
|
218
335
|
else
|
|
219
336
|
cat "$DS_TMP"
|
|
220
337
|
echo ""
|
|
221
338
|
echo " ❌ BLOCKED - detect-secrets found secrets not in .secrets.baseline."
|
|
222
|
-
echo " If these are false positives,
|
|
223
|
-
echo " detect-secrets scan --
|
|
224
|
-
|
|
339
|
+
echo " If these are false positives, mark them in the baseline:"
|
|
340
|
+
echo " detect-secrets scan --baseline .secrets.baseline && git add .secrets.baseline"
|
|
341
|
+
echo " (--update does not exist; detect-secrets exits with"
|
|
342
|
+
echo " \"unrecognized arguments: --update\".)"
|
|
343
|
+
echo " Then REVIEW the diff: scan --baseline re-scans the WHOLE tree, whereas"
|
|
344
|
+
echo " this gate only inspects changed files. A whole-tree scan can silently"
|
|
345
|
+
echo " drop the entries of files it no longer reaches, un-allowlisting a"
|
|
346
|
+
echo " historical finding. Commit the baseline alone so that stays visible."
|
|
225
347
|
exit 1
|
|
226
348
|
fi
|
|
227
|
-
rm
|
|
349
|
+
# Temp cleanup is owned by the gate8_cleanup trap; no rm here.
|
|
228
350
|
else
|
|
229
351
|
echo " ⚠️ detect-secrets-hook unavailable (install: pip install -e \".[dev]\") — gitleaks only."
|
|
230
352
|
fi
|
package/adapters/typescript.sh
CHANGED
|
@@ -33,8 +33,18 @@ run_lint() {
|
|
|
33
33
|
# Prefer Biome if biome.json/biome.jsonc exists (covers lint + format in one pass)
|
|
34
34
|
if [ -f "biome.json" ] || [ -f "biome.jsonc" ]; then
|
|
35
35
|
echo "Running Biome linting..."
|
|
36
|
-
|
|
36
|
+
# `$?` here is Biome's, and it has to be: this used to read
|
|
37
|
+
# npx biome check . 2>&1 | head -50
|
|
38
|
+
# local EXIT_CODE=$?
|
|
39
|
+
# and in a POSIX pipeline `$?` is the status of the LAST command -- `head` --
|
|
40
|
+
# so it was always 0. The failure branch below could never run and a project
|
|
41
|
+
# with Biome errors was told "PASSED". Capture the status first, then trim
|
|
42
|
+
# the output. This repo has no biome.json so its own commits never showed it;
|
|
43
|
+
# every downstream project using Biome was affected (#437).
|
|
44
|
+
local BIOME_OUTPUT
|
|
45
|
+
BIOME_OUTPUT=$(npx biome check . --no-errors-on-unmatched 2>&1)
|
|
37
46
|
local EXIT_CODE=$?
|
|
47
|
+
printf '%s\n' "$BIOME_OUTPUT" | head -50
|
|
38
48
|
if [ $EXIT_CODE -ne 0 ]; then
|
|
39
49
|
echo ""
|
|
40
50
|
echo "❌ Biome check failed"
|
|
@@ -45,16 +55,30 @@ run_lint() {
|
|
|
45
55
|
return 0
|
|
46
56
|
fi
|
|
47
57
|
|
|
48
|
-
# Fall back to ESLint if no Biome config exists
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
# Fall back to ESLint if no Biome config exists.
|
|
59
|
+
#
|
|
60
|
+
# #766: the flat-config era renamed and extended these files. `.mjs` is what
|
|
61
|
+
# `eslint --init` produces for an ESM project, and `.ts`/`.mts`/`.cts` appear in
|
|
62
|
+
# monorepos that share one config across packages -- none of them were probed,
|
|
63
|
+
# so a project whose ONLY config was `eslint.config.mjs` was told "No linter
|
|
64
|
+
# configuration found" and Gate 1 skipped linting entirely. That is a fail-open
|
|
65
|
+
# on the whole TypeScript arm, not a cosmetic gap.
|
|
66
|
+
#
|
|
67
|
+
# Kept as one list so the message below cannot drift from the probe. `--ext` is
|
|
68
|
+
# dropped: it is ignored under flat config (and warns), while the config itself
|
|
69
|
+
# owns the file set.
|
|
70
|
+
_eslint_configs=".eslintrc.json .eslintrc .eslintrc.js .eslintrc.cjs .eslintrc.yml .eslintrc.yaml eslint.config.js eslint.config.mjs eslint.config.cjs eslint.config.ts eslint.config.mts eslint.config.cts"
|
|
71
|
+
for _cfg in $_eslint_configs; do
|
|
72
|
+
if [ -f "$_cfg" ]; then
|
|
73
|
+
echo "Running ESLint linting (config: $_cfg)..."
|
|
74
|
+
npx eslint .
|
|
75
|
+
return $?
|
|
76
|
+
fi
|
|
77
|
+
done
|
|
54
78
|
|
|
55
79
|
echo "❌ BLOCKED - No linter configuration found for TypeScript project."
|
|
56
80
|
echo " TypeScript projects require a linter: either Biome (biome.json/biome.jsonc)"
|
|
57
|
-
echo " or ESLint (
|
|
81
|
+
echo " or ESLint (any of: $(printf '%s' "$_eslint_configs" | tr ' ' '/'))."
|
|
58
82
|
echo " Create one of these configuration files to enable linting."
|
|
59
83
|
return 1
|
|
60
84
|
}
|