@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/hooks/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/hooks/gate-registry.sh
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
# name|number|impl|blocks
|
|
51
51
|
GATE_REGISTRY_ROWS=(
|
|
52
52
|
"version-consistency|0|inline|YES"
|
|
53
|
-
"code-quality|1|inline|
|
|
53
|
+
"code-quality|1|inline|YES"
|
|
54
54
|
"duplicate-code|2|inline|NO"
|
|
55
55
|
"complexity|3|gate-3.sh|YES"
|
|
56
56
|
"principles|4|gate-4.sh|YES"
|
|
@@ -58,7 +58,7 @@ GATE_REGISTRY_ROWS=(
|
|
|
58
58
|
"architecture|6|inline|YES"
|
|
59
59
|
"iac-security|7|gate-7.sh|YES"
|
|
60
60
|
"secret-scanning|8|gate-8.sh|YES"
|
|
61
|
-
"build-integrity|9|inline|
|
|
61
|
+
"build-integrity|9|inline|YES"
|
|
62
62
|
"sast|10|gate-10.sh|YES"
|
|
63
63
|
"sprint-flow|11|sprint-gate.sh|YES"
|
|
64
64
|
"file-hygiene|12|gate-12-file-hygiene.sh|NO"
|
|
@@ -24,8 +24,8 @@ HOOK_GATE_PROBE="gate-3.sh"
|
|
|
24
24
|
# Consumed by the sourcing parent, not here.
|
|
25
25
|
# shellcheck disable=SC2034
|
|
26
26
|
HOOK_ADAPTER_DIR_TIERS=(
|
|
27
|
-
'global|GLOBAL_ADAPTER_DIR|adapter-common.sh'
|
|
28
27
|
'project|PROJECT_GITHOOKS|adapter-common.sh'
|
|
28
|
+
'global|GLOBAL_ADAPTER_DIR|adapter-common.sh'
|
|
29
29
|
'script|SCRIPT_DIR|adapter-common.sh'
|
|
30
30
|
)
|
|
31
31
|
|
|
@@ -49,12 +49,15 @@ classify_test_skip() {
|
|
|
49
49
|
# silent pass.
|
|
50
50
|
#
|
|
51
51
|
# $1 = the source text to inspect (usually the staged file content).
|
|
52
|
+
# Read to END rather than exiting on the first match: an early `exit` closes stdin
|
|
53
|
+
# on the upstream pipeline, and under the hook's `set -o pipefail` the resulting
|
|
54
|
+
# SIGPIPE (141) would be misread as "no match" (#774).
|
|
52
55
|
is_skip_justified() {
|
|
53
56
|
printf '%s\n' "$1" \
|
|
54
57
|
| grep -oE '@skip-justified:[[:space:]]*[^[:space:]*].*' \
|
|
55
58
|
| sed 's/^@skip-justified:[[:space:]]*//' \
|
|
56
59
|
| tr -d '\r' \
|
|
57
|
-
| awk 'length($0) >= 10 { found = 1
|
|
60
|
+
| awk 'length($0) >= 10 { found = 1 } END { exit(found ? 0 : 1) }'
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
# Files whose basename marks them as a test. Shared with classify_deleted_tests so
|
|
@@ -270,10 +273,13 @@ classify_weak_assertions() {
|
|
|
270
273
|
# hatch from becoming the default.
|
|
271
274
|
#
|
|
272
275
|
# $1 = the source text to inspect.
|
|
276
|
+
# Read to END rather than exiting on the first match: an early `exit` closes stdin
|
|
277
|
+
# on the upstream pipeline, and under the hook's `set -o pipefail` the resulting
|
|
278
|
+
# SIGPIPE (141) would be misread as "no match" (#774).
|
|
273
279
|
is_assertion_justified() {
|
|
274
280
|
printf '%s\n' "$1" \
|
|
275
281
|
| grep -oE '@assertion-justified:[[:space:]]*[^[:space:]*].*' \
|
|
276
282
|
| sed 's/^@assertion-justified:[[:space:]]*//' \
|
|
277
283
|
| tr -d '\r' \
|
|
278
|
-
| awk 'length($0) >= 10 { found = 1
|
|
284
|
+
| awk 'length($0) >= 10 { found = 1 } END { exit(found ? 0 : 1) }'
|
|
279
285
|
}
|
package/hooks/lib/ccn-ratchet.sh
CHANGED
|
@@ -262,6 +262,7 @@ evaluate_ccn_ratchet() {
|
|
|
262
262
|
# bare double-quote pair that the shell re-pairs across the awk text. The
|
|
263
263
|
# anonymous marker is therefore passed in as a -v value, not written inline.
|
|
264
264
|
$2 ~ /^[0-9]+$/ {
|
|
265
|
+
graded++
|
|
265
266
|
ccn = $2 + 0
|
|
266
267
|
n2 = split($6, parts, "@")
|
|
267
268
|
name = parts[1]
|
|
@@ -288,5 +289,14 @@ evaluate_ccn_ratchet() {
|
|
|
288
289
|
else printf "OK %s CCN=%d\n", name, ccn
|
|
289
290
|
}
|
|
290
291
|
}
|
|
292
|
+
END {
|
|
293
|
+
# Zero parsable rows means "unverified", never "clean". Before this the
|
|
294
|
+
# verdict came back empty, every counter read 0, and Gate 3 graded a tree
|
|
295
|
+
# nobody measured as compliant (#683). Header-only output, a separator
|
|
296
|
+
# line, and a genuinely empty scan all mean the same thing: no number was
|
|
297
|
+
# read, so no verdict may be claimed.
|
|
298
|
+
if (graded == 0)
|
|
299
|
+
printf "UNVERIFIED no parsable CCN row (lizard produced no measurable function)\n"
|
|
300
|
+
}
|
|
291
301
|
'
|
|
292
302
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Layer-baseline comparison for Gate 6's layer check.
|
|
4
|
+
*
|
|
5
|
+
* Reads findings on stdin (one per line, fields separated by real TABs) and a
|
|
6
|
+
* JSON ledger as argv[2], and writes the findings that are NOT in the ledger.
|
|
7
|
+
*
|
|
8
|
+
* Exit 4 when the ledger exists but cannot be parsed. The caller treats that as
|
|
9
|
+
* BLOCK (fail-closed): a ledger that silently reads as empty would turn every
|
|
10
|
+
* accepted violation back into a new one, and the next natural response — re-run
|
|
11
|
+
* with a bigger baseline — quietly launders the debt.
|
|
12
|
+
*
|
|
13
|
+
* Why this is a file and not an inline `node -e`: the first version embedded
|
|
14
|
+
* this in bash single quotes, and the TAB separators ended up inside a JSON
|
|
15
|
+
* string literal, which JSON.parse rejects (raw control character). The error
|
|
16
|
+
* was then swallowed by `2>/dev/null`, so the ratchet silently reset on every
|
|
17
|
+
* run. Three levels of quoting is where that hid; one level is enough.
|
|
18
|
+
*
|
|
19
|
+
* Ledger shape:
|
|
20
|
+
* { "accepted": [ { "file", "from", "to", "imports" }, ... ] }
|
|
21
|
+
*
|
|
22
|
+
* A plain tab-joined string is also accepted for entries, so hand-written and
|
|
23
|
+
* generated ledgers both work.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
'use strict';
|
|
27
|
+
|
|
28
|
+
const fs = require('fs');
|
|
29
|
+
|
|
30
|
+
const SEVERITY_EXIT_UNREADABLE = 4;
|
|
31
|
+
|
|
32
|
+
/** Normalise one ledger entry to the tab-joined form used on stdin. */
|
|
33
|
+
function toKey(entry) {
|
|
34
|
+
if (typeof entry === 'string') {
|
|
35
|
+
return entry;
|
|
36
|
+
}
|
|
37
|
+
if (entry && typeof entry === 'object') {
|
|
38
|
+
return [entry.file, entry.from, entry.to, entry.imports].join('\t');
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Read and validate the ledger. Throws when it cannot be used. */
|
|
44
|
+
function readLedger(path) {
|
|
45
|
+
const raw = fs.readFileSync(path, 'utf8');
|
|
46
|
+
const parsed = JSON.parse(raw);
|
|
47
|
+
const accepted = Array.isArray(parsed.accepted) ? parsed.accepted : [];
|
|
48
|
+
return new Set(accepted.map(toKey).filter(Boolean));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Split stdin into findings and drop the baselined ones. */
|
|
52
|
+
function filterFindings(raw, known) {
|
|
53
|
+
return raw
|
|
54
|
+
.split('\n')
|
|
55
|
+
.filter(Boolean)
|
|
56
|
+
.filter(line => !known.has(line));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function main() {
|
|
60
|
+
const ledgerPath = process.argv[2];
|
|
61
|
+
if (!ledgerPath) {
|
|
62
|
+
process.stderr.write('usage: layer-baseline.cjs <ledger.json> < findings\n');
|
|
63
|
+
process.exit(SEVERITY_EXIT_UNREADABLE);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let known;
|
|
68
|
+
try {
|
|
69
|
+
known = readLedger(ledgerPath);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
process.stderr.write(`layer-baseline unreadable: ${err.message}\n`);
|
|
72
|
+
process.exit(SEVERITY_EXIT_UNREADABLE);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let raw = '';
|
|
77
|
+
process.stdin.setEncoding('utf8');
|
|
78
|
+
process.stdin.on('data', chunk => {
|
|
79
|
+
raw += chunk;
|
|
80
|
+
});
|
|
81
|
+
process.stdin.on('end', () => {
|
|
82
|
+
process.stdout.write(filterFindings(raw, known).join('\n'));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
main();
|
|
87
|
+
|
|
88
|
+
module.exports = { toKey, readLedger, filterFindings };
|
package/hooks/lib/typecheck.sh
CHANGED
|
@@ -56,12 +56,35 @@ resolve_typecheck_command() {
|
|
|
56
56
|
return 0
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
# Runs tsc, preferring the locally installed compiler over npx.
|
|
60
|
+
#
|
|
61
|
+
# `npx tsc --version` measured 1941 ms here against 234 ms for
|
|
62
|
+
# `node node_modules/typescript/bin/tsc --version` -- identical output, 1.7 s of
|
|
63
|
+
# package resolution in between. typecheck.sh called `npx tsc` at five sites and
|
|
64
|
+
# a single commit reaches several of them, so the whole typecheck half of Gate 1
|
|
65
|
+
# paid that toll repeatedly. pre-commit:4324-4345 already made exactly this
|
|
66
|
+
# change for archlint ("measured: 1909 ms via npx vs 319 ms direct"); typecheck
|
|
67
|
+
# never got it.
|
|
68
|
+
#
|
|
69
|
+
# npx stays as the fallback so a consumer repo with no local install behaves
|
|
70
|
+
# exactly as before. Nothing is cached: resolving a path is a couple of `test -f`
|
|
71
|
+
# calls, and a cache would have to be invalidated whenever node_modules changes.
|
|
72
|
+
_tsc_command() {
|
|
73
|
+
if [ -f "node_modules/typescript/bin/tsc" ] && command -v node >/dev/null 2>&1; then
|
|
74
|
+
node "node_modules/typescript/bin/tsc" "$@"
|
|
75
|
+
return $?
|
|
76
|
+
fi
|
|
77
|
+
# The fallback stays a real `npx` call. Rewording this line into a recursive
|
|
78
|
+
# _tsc_command call is a stack overflow, not a fallback.
|
|
79
|
+
npx tsc "$@"
|
|
80
|
+
}
|
|
81
|
+
|
|
59
82
|
# The #293 extra pass: projects commonly exclude test files from tsconfig.json, so
|
|
60
83
|
# their type errors accumulate silently. Only meaningful for the tsc fallback —
|
|
61
84
|
# a project checker covers the files its own config declares.
|
|
62
85
|
run_test_file_pass() {
|
|
63
86
|
local has_tests_in_tsc=false
|
|
64
|
-
if
|
|
87
|
+
if _tsc_command --noEmit --skipLibCheck --listFiles 2>/dev/null | grep -qE '__tests__/|\.test\.ts|\.spec\.ts'; then
|
|
65
88
|
has_tests_in_tsc=true
|
|
66
89
|
fi
|
|
67
90
|
[ "$has_tests_in_tsc" = false ] || return 0
|
|
@@ -69,7 +92,7 @@ run_test_file_pass() {
|
|
|
69
92
|
local test_pass_exit=0
|
|
70
93
|
if [ -f "tsconfig.tests.json" ]; then
|
|
71
94
|
echo "Checking test files with tsconfig.tests.json..."
|
|
72
|
-
|
|
95
|
+
_tsc_command --noEmit --project tsconfig.tests.json 2>&1 | head -30
|
|
73
96
|
test_pass_exit=${PIPESTATUS[0]}
|
|
74
97
|
else
|
|
75
98
|
echo "Checking test files for type errors..."
|
|
@@ -81,7 +104,7 @@ run_test_file_pass() {
|
|
|
81
104
|
cfg.include.push('src/**/__tests__/**','src/**/*.test.ts','src/**/*.spec.ts');
|
|
82
105
|
require('fs').writeFileSync('$temp_tsconfig', JSON.stringify(cfg, null, 2));
|
|
83
106
|
" 2>/dev/null
|
|
84
|
-
|
|
107
|
+
_tsc_command --noEmit --project "$temp_tsconfig" --skipLibCheck 2>&1 | head -30
|
|
85
108
|
test_pass_exit=${PIPESTATUS[0]}
|
|
86
109
|
rm -f "$temp_tsconfig"
|
|
87
110
|
fi
|
|
@@ -122,7 +145,7 @@ run_typescript_typecheck() {
|
|
|
122
145
|
|
|
123
146
|
# Verify tsc is the real compiler (npx may fetch the deprecated tsc@2.0.4 placeholder).
|
|
124
147
|
local tsc_version
|
|
125
|
-
tsc_version=$(
|
|
148
|
+
tsc_version=$(_tsc_command --version 2>&1)
|
|
126
149
|
if ! echo "$tsc_version" | grep -q "Version"; then
|
|
127
150
|
echo "ℹ️ SKIP - tsc not properly installed ($tsc_version)"
|
|
128
151
|
echo "Install typescript (npm install typescript --save-dev) for type checking."
|
|
@@ -135,7 +158,7 @@ run_typescript_typecheck() {
|
|
|
135
158
|
fi
|
|
136
159
|
|
|
137
160
|
echo "Running TypeScript static analysis ($tsc_version)..."
|
|
138
|
-
|
|
161
|
+
_tsc_command --noEmit --skipLibCheck 2>&1 | head -30
|
|
139
162
|
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
|
|
140
163
|
echo ""
|
|
141
164
|
echo "❌ BLOCKED - TYPE ERRORS detected"
|