@boyingliu01/xp-gate 0.38.78 → 0.38.80
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/gate-10.sh +16 -1
- package/adapters/gate-3.sh +20 -1
- package/adapters/gate-4.sh +16 -1
- package/gate-10.sh +16 -1
- package/gate-3.sh +20 -1
- package/gate-4.sh +16 -1
- package/gates/common.ts +18 -3
- package/gates/pbt-detect.ts +110 -30
- package/hooks/deploy-manifest.sh +1 -0
- package/hooks/gate-10.sh +16 -1
- package/hooks/gate-3.sh +20 -1
- package/hooks/gate-4.sh +16 -1
- package/hooks/lib/file-classifier.sh +77 -0
- package/lib/__tests__/crap.test.js +184 -0
- package/lib/__tests__/mirror-sync.test.js +83 -1
- package/lib/crap-cli.js +38 -3
- package/lib/crap.js +98 -7
- package/lib/deploy-manifest.js +1 -0
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/mirror-sync.js +93 -12
- package/package.json +1 -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/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-10.sh
CHANGED
|
@@ -271,7 +271,22 @@ else
|
|
|
271
271
|
# #547 finding 3: ps1|psm1 were missing, so a PowerShell-only commit never
|
|
272
272
|
# reached semgrep even when Gate 10 ran -- the SAST gate was simply absent
|
|
273
273
|
# for that language.
|
|
274
|
-
|
|
274
|
+
# #732: one shared extension list. This gate's literal had forgotten
|
|
275
|
+
# mjs/cjs/mts/cts, so a .cjs file was never a candidate and a SKIP for "no
|
|
276
|
+
# changed source files" was factually wrong about a file that HAD changed.
|
|
277
|
+
# Three places to look, in order: the driver's own resolution ($GATE_DIR),
|
|
278
|
+
# this file's own directory (covers a test that `source`s the gate directly,
|
|
279
|
+
# where no driver ran and $GATE_DIR is unset), and the repo root.
|
|
280
|
+
XP_FC_LIB="$GATE_DIR/lib/file-classifier.sh"
|
|
281
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/lib/file-classifier.sh"
|
|
282
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(git rev-parse --show-toplevel 2>/dev/null)/githooks/lib/file-classifier.sh"
|
|
283
|
+
if [ ! -f "$XP_FC_LIB" ]; then
|
|
284
|
+
echo "BLOCKED - source classifier missing (githooks/lib/file-classifier.sh); refusing to grade an unknown population."
|
|
285
|
+
return 1
|
|
286
|
+
fi
|
|
287
|
+
# shellcheck source=/dev/null
|
|
288
|
+
. "$XP_FC_LIB"
|
|
289
|
+
SEMGREP_FILES=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null | grep -E "$(xp_gate_ext_regex "$(xp_gate_source_exts semgrep)")" || true)
|
|
275
290
|
|
|
276
291
|
if [ -z "$SEMGREP_FILES" ]; then
|
|
277
292
|
echo " ⏭️ SKIPPED - SAST (no supported language files changed)"
|
package/adapters/gate-3.sh
CHANGED
|
@@ -376,7 +376,26 @@ else
|
|
|
376
376
|
# the one under `adapters/`. A fix applied to only one of them leaves the
|
|
377
377
|
# other silently wrong -- which is how this edit was first written and how
|
|
378
378
|
# the accompanying test failed. Any change here must land in BOTH.
|
|
379
|
-
|
|
379
|
+
# #732: the extension list lives in ONE place now. Four gates each wrote out
|
|
380
|
+
# their own literal, and all four had forgotten mjs/cjs/mts/cts -- so a .cjs
|
|
381
|
+
# build script was never a candidate for grading, and the gate's "no changed
|
|
382
|
+
# source files" SKIP was factually wrong about a file that HAD changed.
|
|
383
|
+
# Three places to look, in order: the driver's own resolution ($GATE_DIR),
|
|
384
|
+
# this file's own directory (covers a test that `source`s the gate directly,
|
|
385
|
+
# where no driver ran and $GATE_DIR is unset), and the repo root.
|
|
386
|
+
XP_FC_LIB="$GATE_DIR/lib/file-classifier.sh"
|
|
387
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/lib/file-classifier.sh"
|
|
388
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(git rev-parse --show-toplevel 2>/dev/null)/githooks/lib/file-classifier.sh"
|
|
389
|
+
# A missing library must not degrade into "no files": an empty pattern would
|
|
390
|
+
# match nothing and report a clean SKIP, which is the exact fail-open this
|
|
391
|
+
# change removes. Refuse instead.
|
|
392
|
+
if [ ! -f "$XP_FC_LIB" ]; then
|
|
393
|
+
echo "BLOCKED - source classifier missing (githooks/lib/file-classifier.sh); refusing to grade an unknown population."
|
|
394
|
+
return 1
|
|
395
|
+
fi
|
|
396
|
+
# shellcheck source=/dev/null
|
|
397
|
+
. "$XP_FC_LIB"
|
|
398
|
+
CC_FILES=$(echo "$CHANGED_FILES" | grep -E "$(xp_gate_ext_regex "$(xp_gate_source_exts ccn)")" || true)
|
|
380
399
|
|
|
381
400
|
# Grade exactly the population the baseline was written from. The two must
|
|
382
401
|
# match or the ratchet reports pre-existing code as "new", which is a false
|
package/adapters/gate-4.sh
CHANGED
|
@@ -76,7 +76,22 @@ if [ "$PROJECT_LANG" = "documentation-only" ]; then
|
|
|
76
76
|
|
|
77
77
|
else
|
|
78
78
|
# Get source files to check against principles
|
|
79
|
-
|
|
79
|
+
# #732: one shared extension list. This gate's literal had forgotten
|
|
80
|
+
# mjs/cjs/mts/cts, so a .cjs file was never a candidate and a SKIP for "no
|
|
81
|
+
# changed source files" was factually wrong about a file that HAD changed.
|
|
82
|
+
# Three places to look, in order: the driver's own resolution ($GATE_DIR),
|
|
83
|
+
# this file's own directory (covers a test that `source`s the gate directly,
|
|
84
|
+
# where no driver ran and $GATE_DIR is unset), and the repo root.
|
|
85
|
+
XP_FC_LIB="$GATE_DIR/lib/file-classifier.sh"
|
|
86
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/lib/file-classifier.sh"
|
|
87
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(git rev-parse --show-toplevel 2>/dev/null)/githooks/lib/file-classifier.sh"
|
|
88
|
+
if [ ! -f "$XP_FC_LIB" ]; then
|
|
89
|
+
echo "BLOCKED - source classifier missing (githooks/lib/file-classifier.sh); refusing to grade an unknown population."
|
|
90
|
+
return 1
|
|
91
|
+
fi
|
|
92
|
+
# shellcheck source=/dev/null
|
|
93
|
+
. "$XP_FC_LIB"
|
|
94
|
+
PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E "$(xp_gate_ext_regex "$(xp_gate_source_exts principles)")" || true)
|
|
80
95
|
|
|
81
96
|
# One path per line, into an array. Passing $PRINCIPLES_FILES unquoted relies on
|
|
82
97
|
# word splitting to turn the list into separate argv entries, which also splits
|
package/gate-10.sh
CHANGED
|
@@ -271,7 +271,22 @@ else
|
|
|
271
271
|
# #547 finding 3: ps1|psm1 were missing, so a PowerShell-only commit never
|
|
272
272
|
# reached semgrep even when Gate 10 ran -- the SAST gate was simply absent
|
|
273
273
|
# for that language.
|
|
274
|
-
|
|
274
|
+
# #732: one shared extension list. This gate's literal had forgotten
|
|
275
|
+
# mjs/cjs/mts/cts, so a .cjs file was never a candidate and a SKIP for "no
|
|
276
|
+
# changed source files" was factually wrong about a file that HAD changed.
|
|
277
|
+
# Three places to look, in order: the driver's own resolution ($GATE_DIR),
|
|
278
|
+
# this file's own directory (covers a test that `source`s the gate directly,
|
|
279
|
+
# where no driver ran and $GATE_DIR is unset), and the repo root.
|
|
280
|
+
XP_FC_LIB="$GATE_DIR/lib/file-classifier.sh"
|
|
281
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/lib/file-classifier.sh"
|
|
282
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(git rev-parse --show-toplevel 2>/dev/null)/githooks/lib/file-classifier.sh"
|
|
283
|
+
if [ ! -f "$XP_FC_LIB" ]; then
|
|
284
|
+
echo "BLOCKED - source classifier missing (githooks/lib/file-classifier.sh); refusing to grade an unknown population."
|
|
285
|
+
return 1
|
|
286
|
+
fi
|
|
287
|
+
# shellcheck source=/dev/null
|
|
288
|
+
. "$XP_FC_LIB"
|
|
289
|
+
SEMGREP_FILES=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null | grep -E "$(xp_gate_ext_regex "$(xp_gate_source_exts semgrep)")" || true)
|
|
275
290
|
|
|
276
291
|
if [ -z "$SEMGREP_FILES" ]; then
|
|
277
292
|
echo " ⏭️ SKIPPED - SAST (no supported language files changed)"
|
package/gate-3.sh
CHANGED
|
@@ -376,7 +376,26 @@ else
|
|
|
376
376
|
# the one under `adapters/`. A fix applied to only one of them leaves the
|
|
377
377
|
# other silently wrong -- which is how this edit was first written and how
|
|
378
378
|
# the accompanying test failed. Any change here must land in BOTH.
|
|
379
|
-
|
|
379
|
+
# #732: the extension list lives in ONE place now. Four gates each wrote out
|
|
380
|
+
# their own literal, and all four had forgotten mjs/cjs/mts/cts -- so a .cjs
|
|
381
|
+
# build script was never a candidate for grading, and the gate's "no changed
|
|
382
|
+
# source files" SKIP was factually wrong about a file that HAD changed.
|
|
383
|
+
# Three places to look, in order: the driver's own resolution ($GATE_DIR),
|
|
384
|
+
# this file's own directory (covers a test that `source`s the gate directly,
|
|
385
|
+
# where no driver ran and $GATE_DIR is unset), and the repo root.
|
|
386
|
+
XP_FC_LIB="$GATE_DIR/lib/file-classifier.sh"
|
|
387
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/lib/file-classifier.sh"
|
|
388
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(git rev-parse --show-toplevel 2>/dev/null)/githooks/lib/file-classifier.sh"
|
|
389
|
+
# A missing library must not degrade into "no files": an empty pattern would
|
|
390
|
+
# match nothing and report a clean SKIP, which is the exact fail-open this
|
|
391
|
+
# change removes. Refuse instead.
|
|
392
|
+
if [ ! -f "$XP_FC_LIB" ]; then
|
|
393
|
+
echo "BLOCKED - source classifier missing (githooks/lib/file-classifier.sh); refusing to grade an unknown population."
|
|
394
|
+
return 1
|
|
395
|
+
fi
|
|
396
|
+
# shellcheck source=/dev/null
|
|
397
|
+
. "$XP_FC_LIB"
|
|
398
|
+
CC_FILES=$(echo "$CHANGED_FILES" | grep -E "$(xp_gate_ext_regex "$(xp_gate_source_exts ccn)")" || true)
|
|
380
399
|
|
|
381
400
|
# Grade exactly the population the baseline was written from. The two must
|
|
382
401
|
# match or the ratchet reports pre-existing code as "new", which is a false
|
package/gate-4.sh
CHANGED
|
@@ -76,7 +76,22 @@ if [ "$PROJECT_LANG" = "documentation-only" ]; then
|
|
|
76
76
|
|
|
77
77
|
else
|
|
78
78
|
# Get source files to check against principles
|
|
79
|
-
|
|
79
|
+
# #732: one shared extension list. This gate's literal had forgotten
|
|
80
|
+
# mjs/cjs/mts/cts, so a .cjs file was never a candidate and a SKIP for "no
|
|
81
|
+
# changed source files" was factually wrong about a file that HAD changed.
|
|
82
|
+
# Three places to look, in order: the driver's own resolution ($GATE_DIR),
|
|
83
|
+
# this file's own directory (covers a test that `source`s the gate directly,
|
|
84
|
+
# where no driver ran and $GATE_DIR is unset), and the repo root.
|
|
85
|
+
XP_FC_LIB="$GATE_DIR/lib/file-classifier.sh"
|
|
86
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/lib/file-classifier.sh"
|
|
87
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(git rev-parse --show-toplevel 2>/dev/null)/githooks/lib/file-classifier.sh"
|
|
88
|
+
if [ ! -f "$XP_FC_LIB" ]; then
|
|
89
|
+
echo "BLOCKED - source classifier missing (githooks/lib/file-classifier.sh); refusing to grade an unknown population."
|
|
90
|
+
return 1
|
|
91
|
+
fi
|
|
92
|
+
# shellcheck source=/dev/null
|
|
93
|
+
. "$XP_FC_LIB"
|
|
94
|
+
PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E "$(xp_gate_ext_regex "$(xp_gate_source_exts principles)")" || true)
|
|
80
95
|
|
|
81
96
|
# One path per line, into an array. Passing $PRINCIPLES_FILES unquoted relies on
|
|
82
97
|
# word splitting to turn the list into separate argv entries, which also splits
|
package/gates/common.ts
CHANGED
|
@@ -190,11 +190,26 @@ export function getTempDir(): string {
|
|
|
190
190
|
* never a tool limitation: lizard reports the CCN 11-22 functions the issue
|
|
191
191
|
* names, and the gate dropped those files before lizard was invoked, so the
|
|
192
192
|
* report said "no source files to check" for a tree full of them.
|
|
193
|
+
*
|
|
194
|
+
* #732 is the same defect with a different four letters. mjs/cjs/mts/cts were
|
|
195
|
+
* missing, so a .cjs build script was never a candidate and Gate 3 answered
|
|
196
|
+
* "no source files to check" about a file that HAD changed. They lead the list
|
|
197
|
+
* because they are what this entry exists to keep.
|
|
198
|
+
*
|
|
199
|
+
* Must stay equivalent to XP_GATE_CCN_EXTS in githooks/lib/file-classifier.sh,
|
|
200
|
+
* which the commit-time hook uses. Pinned by gate-732-source-extensions.test.bats.
|
|
193
201
|
*/
|
|
194
|
-
const LIZARD_EXTENSIONS = /\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs)$/;
|
|
202
|
+
const LIZARD_EXTENSIONS = /\.(mjs|cjs|mts|cts|ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs|dart|php|phtml)$/;
|
|
195
203
|
|
|
196
|
-
/**
|
|
197
|
-
|
|
204
|
+
/**
|
|
205
|
+
* File extensions that semgrep supports.
|
|
206
|
+
*
|
|
207
|
+
* #732: mjs/cjs/mts/cts added. semgrep parses and flags them — measured 6
|
|
208
|
+
* ERROR-level findings on a real .mjs/.cjs fixture — so excluding them meant
|
|
209
|
+
* "the scanner never looked", which is not a verdict.
|
|
210
|
+
* Kept equivalent to XP_GATE_SEMGREP_EXTS in githooks/lib/file-classifier.sh.
|
|
211
|
+
*/
|
|
212
|
+
const SEMGREP_EXTENSIONS = /\.(mjs|cjs|mts|cts|ts|tsx|js|jsx|py|go|java|c|cpp|cs|rb|php|scala|swift|ps1|psm1)$/;
|
|
198
213
|
|
|
199
214
|
/** IaC file patterns. */
|
|
200
215
|
const IAC_PATTERN = /\.(tf|yaml|yml)$|Dockerfile/;
|
package/gates/pbt-detect.ts
CHANGED
|
@@ -43,19 +43,65 @@ const PBT_API_PATTERNS = [
|
|
|
43
43
|
/** Directories that never hold test sources worth scanning. */
|
|
44
44
|
const SKIPPED_DIRS = new Set(['node_modules', '.git', 'dist']);
|
|
45
45
|
|
|
46
|
-
/**
|
|
47
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Test-file suffixes recognised by the PBT scanner.
|
|
48
|
+
*
|
|
49
|
+
* #857: this used to be `['.test.ts', '.test.js', '.spec.ts', '.spec.js']`, which
|
|
50
|
+
* made every `.mjs`/`.cjs`/`.mts`/`.cts` test invisible. Those are not exotic —
|
|
51
|
+
* `.mjs`/`.cjs` are what Node tooling ships by default now, and `node --test` is
|
|
52
|
+
* built in, so `tests/*.test.mjs` is an ordinary layout. Measured on such a
|
|
53
|
+
* project with 14 test files: the scanner reported 0.
|
|
54
|
+
*
|
|
55
|
+
* Same root cause as #732 (an extension whitelist missing the module variants),
|
|
56
|
+
* but a different code path — fixing the gates' `grep -E` regexes there does not
|
|
57
|
+
* touch this constant. That is why it is pinned separately.
|
|
58
|
+
*/
|
|
59
|
+
const TEST_SUFFIXES = [
|
|
60
|
+
'.test.mjs', '.test.cjs', '.test.mts', '.test.cts',
|
|
61
|
+
'.spec.mjs', '.spec.cjs', '.spec.mts', '.spec.cts',
|
|
62
|
+
'.test.ts', '.test.js', '.test.tsx', '.test.jsx',
|
|
63
|
+
'.spec.ts', '.spec.js', '.spec.tsx', '.spec.jsx',
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Directories searched for test files, relative to the project root.
|
|
68
|
+
*
|
|
69
|
+
* #857: only `src` was scanned. A project following the equally common `tests/`
|
|
70
|
+
* convention reported zero test files even with ordinary `.test.js` names — the
|
|
71
|
+
* issue's own fixture was laid out that way, so correcting the suffixes alone
|
|
72
|
+
* would still have printed `Test files: 0`.
|
|
73
|
+
*/
|
|
74
|
+
const TEST_ROOTS = ['src', 'tests', 'test', '__tests__', 'lib'];
|
|
48
75
|
|
|
49
76
|
function isTestFileName(name: string): boolean {
|
|
50
77
|
return TEST_SUFFIXES.some(suffix => name.endsWith(suffix));
|
|
51
78
|
}
|
|
52
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Read a directory's entries, or [] when it cannot be read.
|
|
82
|
+
*
|
|
83
|
+
* Split out of scanDirectory to keep that function under the complexity ratchet:
|
|
84
|
+
* the try/catch added a branch to a function already at the recorded baseline,
|
|
85
|
+
* which the CCN gate rejected. A directory that cannot be read is skipped rather
|
|
86
|
+
* than thrown -- readdirSync fails on a permission error, a broken symlink, or a
|
|
87
|
+
* path deleted between the existsSync and the read, and one unreadable
|
|
88
|
+
* subdirectory must not take the whole scan down. Returning [] keeps the count
|
|
89
|
+
* honest for the directories that COULD be read.
|
|
90
|
+
*/
|
|
91
|
+
function readDirEntries(dir: string): fs.Dirent[] {
|
|
92
|
+
try {
|
|
93
|
+
return fs.readdirSync(dir, { withFileTypes: true });
|
|
94
|
+
} catch {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
53
99
|
/** Collect test files under `dir`, descending into subdirectories. */
|
|
54
100
|
function scanDirectory(dir: string, basePath?: string): string[] {
|
|
55
101
|
if (!fs.existsSync(dir)) return [];
|
|
56
102
|
|
|
57
103
|
const results: string[] = [];
|
|
58
|
-
for (const entry of
|
|
104
|
+
for (const entry of readDirEntries(dir)) {
|
|
59
105
|
if (entry.isDirectory()) {
|
|
60
106
|
if (!SKIPPED_DIRS.has(entry.name)) {
|
|
61
107
|
results.push(...scanDirectory(path.join(dir, entry.name), basePath ?? dir));
|
|
@@ -95,40 +141,36 @@ function detectPBTInFile(filePath: string): { hasPBT: boolean; frameworks: strin
|
|
|
95
141
|
}
|
|
96
142
|
}
|
|
97
143
|
|
|
98
|
-
// ── Main Analysis ──
|
|
99
|
-
|
|
100
144
|
/**
|
|
101
|
-
*
|
|
145
|
+
* Render the report text.
|
|
146
|
+
*
|
|
147
|
+
* Lifted out of detectPBT so the detector stays under the 50-line ceiling Gate 4
|
|
148
|
+
* enforces on clean code; the message list has its own branching and reads better
|
|
149
|
+
* as one place than as a tail of the detector.
|
|
102
150
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
151
|
+
function buildMessages(input: {
|
|
152
|
+
totalTests: number;
|
|
153
|
+
pbtTestFiles: string[];
|
|
154
|
+
coverage: number;
|
|
155
|
+
detected: boolean;
|
|
156
|
+
frameworks: string[];
|
|
157
|
+
}): string[] {
|
|
158
|
+
const { totalTests, pbtTestFiles, coverage, detected, frameworks } = input;
|
|
106
159
|
const messages: string[] = [];
|
|
107
|
-
|
|
108
|
-
// Find all test files
|
|
109
|
-
const testFiles = scanDirectory(srcDir);
|
|
110
|
-
const pbtTestFiles: string[] = [];
|
|
111
|
-
const allFrameworks = new Set<string>();
|
|
112
|
-
|
|
113
|
-
for (const testFile of testFiles) {
|
|
114
|
-
const result = detectPBTInFile(testFile);
|
|
115
|
-
if (result.hasPBT) {
|
|
116
|
-
pbtTestFiles.push(path.relative(dir, testFile).replace(/\\/g, '/'));
|
|
117
|
-
result.frameworks.forEach(fw => allFrameworks.add(fw));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const totalTests = testFiles.length;
|
|
122
|
-
const coverage = totalTests > 0 ? Math.round((pbtTestFiles.length / totalTests) * 100) : 0;
|
|
123
|
-
const detected = pbtTestFiles.length > 0;
|
|
124
|
-
|
|
125
|
-
// Build messages
|
|
126
160
|
messages.push('');
|
|
127
161
|
messages.push('━━━ Property-Based Testing Report ━━━');
|
|
128
162
|
messages.push('');
|
|
129
163
|
messages.push(` Test files: ${totalTests}`);
|
|
130
|
-
|
|
131
|
-
|
|
164
|
+
// #857: a 0% figure is a MEASUREMENT, and when nothing was scanned there is no
|
|
165
|
+
// measurement to report. Printing "0 (0%)" beside "No test files found" reads as
|
|
166
|
+
// "this project has no property tests" when the truth is "the scanner did not
|
|
167
|
+
// look" -- the same conflation as #732, one report away. Say it is not checked.
|
|
168
|
+
if (totalTests > 0) {
|
|
169
|
+
messages.push(` PBT files: ${pbtTestFiles.length} (${coverage}%)`);
|
|
170
|
+
} else {
|
|
171
|
+
messages.push(' PBT files: not measured (no test files were found to inspect)');
|
|
172
|
+
}
|
|
173
|
+
messages.push(` Frameworks: ${detected ? frameworks.join(', ') : 'none detected'}`);
|
|
132
174
|
messages.push('');
|
|
133
175
|
|
|
134
176
|
if (detected) {
|
|
@@ -148,6 +190,44 @@ export function detectPBT(cwd?: string): PBTReport {
|
|
|
148
190
|
messages.push(' ℹ️ No test files found.');
|
|
149
191
|
}
|
|
150
192
|
messages.push('');
|
|
193
|
+
return messages;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ── Main Analysis ──
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Analyze PBT usage in the project.
|
|
200
|
+
*/
|
|
201
|
+
export function detectPBT(cwd?: string): PBTReport {
|
|
202
|
+
const dir = cwd || process.cwd();
|
|
203
|
+
|
|
204
|
+
// Find all test files, across every conventional test root (#857). A Set keeps
|
|
205
|
+
// a file from being counted twice when roots nest, e.g. `tests/` under `src/`.
|
|
206
|
+
const testFiles = [...new Set(
|
|
207
|
+
TEST_ROOTS.flatMap(root => scanDirectory(path.join(dir, root))),
|
|
208
|
+
)];
|
|
209
|
+
const pbtTestFiles: string[] = [];
|
|
210
|
+
const allFrameworks = new Set<string>();
|
|
211
|
+
|
|
212
|
+
for (const testFile of testFiles) {
|
|
213
|
+
const result = detectPBTInFile(testFile);
|
|
214
|
+
if (result.hasPBT) {
|
|
215
|
+
pbtTestFiles.push(path.relative(dir, testFile).replace(/\\/g, '/'));
|
|
216
|
+
result.frameworks.forEach(fw => allFrameworks.add(fw));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const totalTests = testFiles.length;
|
|
221
|
+
const coverage = totalTests > 0 ? Math.round((pbtTestFiles.length / totalTests) * 100) : 0;
|
|
222
|
+
const detected = pbtTestFiles.length > 0;
|
|
223
|
+
|
|
224
|
+
const messages = buildMessages({
|
|
225
|
+
totalTests,
|
|
226
|
+
pbtTestFiles,
|
|
227
|
+
coverage,
|
|
228
|
+
detected,
|
|
229
|
+
frameworks: [...allFrameworks],
|
|
230
|
+
});
|
|
151
231
|
|
|
152
232
|
return { detected, frameworks: [...allFrameworks], testFiles, pbtTestFiles, coverage, messages };
|
|
153
233
|
}
|
package/hooks/deploy-manifest.sh
CHANGED
package/hooks/gate-10.sh
CHANGED
|
@@ -271,7 +271,22 @@ else
|
|
|
271
271
|
# #547 finding 3: ps1|psm1 were missing, so a PowerShell-only commit never
|
|
272
272
|
# reached semgrep even when Gate 10 ran -- the SAST gate was simply absent
|
|
273
273
|
# for that language.
|
|
274
|
-
|
|
274
|
+
# #732: one shared extension list. This gate's literal had forgotten
|
|
275
|
+
# mjs/cjs/mts/cts, so a .cjs file was never a candidate and a SKIP for "no
|
|
276
|
+
# changed source files" was factually wrong about a file that HAD changed.
|
|
277
|
+
# Three places to look, in order: the driver's own resolution ($GATE_DIR),
|
|
278
|
+
# this file's own directory (covers a test that `source`s the gate directly,
|
|
279
|
+
# where no driver ran and $GATE_DIR is unset), and the repo root.
|
|
280
|
+
XP_FC_LIB="$GATE_DIR/lib/file-classifier.sh"
|
|
281
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/lib/file-classifier.sh"
|
|
282
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(git rev-parse --show-toplevel 2>/dev/null)/githooks/lib/file-classifier.sh"
|
|
283
|
+
if [ ! -f "$XP_FC_LIB" ]; then
|
|
284
|
+
echo "BLOCKED - source classifier missing (githooks/lib/file-classifier.sh); refusing to grade an unknown population."
|
|
285
|
+
return 1
|
|
286
|
+
fi
|
|
287
|
+
# shellcheck source=/dev/null
|
|
288
|
+
. "$XP_FC_LIB"
|
|
289
|
+
SEMGREP_FILES=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null | grep -E "$(xp_gate_ext_regex "$(xp_gate_source_exts semgrep)")" || true)
|
|
275
290
|
|
|
276
291
|
if [ -z "$SEMGREP_FILES" ]; then
|
|
277
292
|
echo " ⏭️ SKIPPED - SAST (no supported language files changed)"
|
package/hooks/gate-3.sh
CHANGED
|
@@ -376,7 +376,26 @@ else
|
|
|
376
376
|
# the one under `adapters/`. A fix applied to only one of them leaves the
|
|
377
377
|
# other silently wrong -- which is how this edit was first written and how
|
|
378
378
|
# the accompanying test failed. Any change here must land in BOTH.
|
|
379
|
-
|
|
379
|
+
# #732: the extension list lives in ONE place now. Four gates each wrote out
|
|
380
|
+
# their own literal, and all four had forgotten mjs/cjs/mts/cts -- so a .cjs
|
|
381
|
+
# build script was never a candidate for grading, and the gate's "no changed
|
|
382
|
+
# source files" SKIP was factually wrong about a file that HAD changed.
|
|
383
|
+
# Three places to look, in order: the driver's own resolution ($GATE_DIR),
|
|
384
|
+
# this file's own directory (covers a test that `source`s the gate directly,
|
|
385
|
+
# where no driver ran and $GATE_DIR is unset), and the repo root.
|
|
386
|
+
XP_FC_LIB="$GATE_DIR/lib/file-classifier.sh"
|
|
387
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/lib/file-classifier.sh"
|
|
388
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(git rev-parse --show-toplevel 2>/dev/null)/githooks/lib/file-classifier.sh"
|
|
389
|
+
# A missing library must not degrade into "no files": an empty pattern would
|
|
390
|
+
# match nothing and report a clean SKIP, which is the exact fail-open this
|
|
391
|
+
# change removes. Refuse instead.
|
|
392
|
+
if [ ! -f "$XP_FC_LIB" ]; then
|
|
393
|
+
echo "BLOCKED - source classifier missing (githooks/lib/file-classifier.sh); refusing to grade an unknown population."
|
|
394
|
+
return 1
|
|
395
|
+
fi
|
|
396
|
+
# shellcheck source=/dev/null
|
|
397
|
+
. "$XP_FC_LIB"
|
|
398
|
+
CC_FILES=$(echo "$CHANGED_FILES" | grep -E "$(xp_gate_ext_regex "$(xp_gate_source_exts ccn)")" || true)
|
|
380
399
|
|
|
381
400
|
# Grade exactly the population the baseline was written from. The two must
|
|
382
401
|
# match or the ratchet reports pre-existing code as "new", which is a false
|
package/hooks/gate-4.sh
CHANGED
|
@@ -76,7 +76,22 @@ if [ "$PROJECT_LANG" = "documentation-only" ]; then
|
|
|
76
76
|
|
|
77
77
|
else
|
|
78
78
|
# Get source files to check against principles
|
|
79
|
-
|
|
79
|
+
# #732: one shared extension list. This gate's literal had forgotten
|
|
80
|
+
# mjs/cjs/mts/cts, so a .cjs file was never a candidate and a SKIP for "no
|
|
81
|
+
# changed source files" was factually wrong about a file that HAD changed.
|
|
82
|
+
# Three places to look, in order: the driver's own resolution ($GATE_DIR),
|
|
83
|
+
# this file's own directory (covers a test that `source`s the gate directly,
|
|
84
|
+
# where no driver ran and $GATE_DIR is unset), and the repo root.
|
|
85
|
+
XP_FC_LIB="$GATE_DIR/lib/file-classifier.sh"
|
|
86
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/lib/file-classifier.sh"
|
|
87
|
+
[ -f "$XP_FC_LIB" ] || XP_FC_LIB="$(git rev-parse --show-toplevel 2>/dev/null)/githooks/lib/file-classifier.sh"
|
|
88
|
+
if [ ! -f "$XP_FC_LIB" ]; then
|
|
89
|
+
echo "BLOCKED - source classifier missing (githooks/lib/file-classifier.sh); refusing to grade an unknown population."
|
|
90
|
+
return 1
|
|
91
|
+
fi
|
|
92
|
+
# shellcheck source=/dev/null
|
|
93
|
+
. "$XP_FC_LIB"
|
|
94
|
+
PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E "$(xp_gate_ext_regex "$(xp_gate_source_exts principles)")" || true)
|
|
80
95
|
|
|
81
96
|
# One path per line, into an array. Passing $PRINCIPLES_FILES unquoted relies on
|
|
82
97
|
# word splitting to turn the list into separate argv entries, which also splits
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# ============================================================================
|
|
3
|
+
# Shared source-file classification (#732)
|
|
4
|
+
#
|
|
5
|
+
# The extension list this file exports used to be written out four times, in
|
|
6
|
+
# four slightly different literals:
|
|
7
|
+
#
|
|
8
|
+
# gate-3.sh:366 (ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt)
|
|
9
|
+
# gate-4.sh:79 (ts|tsx|js|jsx|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm)
|
|
10
|
+
# gate-9.sh:45,47 (ts|tsx|js|jsx|py|go|java|c|cpp|cs|rb|php|scala|swift)
|
|
11
|
+
# gate-10.sh:69 (ts|tsx|js|jsx|py|go|java|c|cpp|cs|rb|php|scala|swift|ps1|psm1)
|
|
12
|
+
#
|
|
13
|
+
# Four literals means four chances to forget, and all four had already forgotten
|
|
14
|
+
# the same four extensions: mjs, cjs, mts, cts. Those are not exotic — .mjs/.cjs
|
|
15
|
+
# are what Node tooling ships by default now, and mts/cts are their TypeScript
|
|
16
|
+
# counterparts. Measured on a real repository with 14 in-scope .mjs/.cjs files:
|
|
17
|
+
# Gate 3 saw none of the 24 production functions above CCN 5 in them, and
|
|
18
|
+
# Gate 9/10 never handed the files to semgrep, which then flagged 6 ERROR-level
|
|
19
|
+
# findings when run on the same files directly.
|
|
20
|
+
#
|
|
21
|
+
# The gates did report SKIP, correctly, for the file list they were given. That
|
|
22
|
+
# is the whole problem: the file was never a candidate. "Not checked" and
|
|
23
|
+
# "checked and clean" must not be the same output.
|
|
24
|
+
#
|
|
25
|
+
# One list, one edit. Gates that need the population source this file.
|
|
26
|
+
#
|
|
27
|
+
# ASCII only.
|
|
28
|
+
# ============================================================================
|
|
29
|
+
|
|
30
|
+
# Every extension a JS/TS-family gate must consider.
|
|
31
|
+
#
|
|
32
|
+
# ORDER IS IRRELEVANT to the match, but the four ESM/CJS/ESM-TS/CTS entries are
|
|
33
|
+
# written first on purpose: they are the ones this list exists to keep, and a
|
|
34
|
+
# future reader adding to it should see them before anything else.
|
|
35
|
+
XP_GATE_JS_TS_EXTS='mjs|cjs|mts|cts|js|jsx|ts|tsx'
|
|
36
|
+
|
|
37
|
+
# Journals, source and script languages that Gate 4 (principles) can grade.
|
|
38
|
+
# Gate 4 runs a language-detecting walker rather than a per-language tool, so it
|
|
39
|
+
# legitimately covers more than Gate 3 (which needs a CCN-capable parser).
|
|
40
|
+
XP_GATE_PRINCIPLES_EXTS="${XP_GATE_JS_TS_EXTS}|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm|cs|php"
|
|
41
|
+
|
|
42
|
+
# Languages Gate 3 can measure complexity for. A parser is required, so this is
|
|
43
|
+
# narrower than the principle set; keep it that way rather than implying a tool
|
|
44
|
+
# exists where it does not.
|
|
45
|
+
XP_GATE_CCN_EXTS="${XP_GATE_JS_TS_EXTS}|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs|dart|php|phtml"
|
|
46
|
+
|
|
47
|
+
# What semgrep can parse (Gates 9 and 10). Powershell is here because semgrep
|
|
48
|
+
# has a p/... ruleset entry for it, unlike the CCN set above.
|
|
49
|
+
XP_GATE_SEMGREP_EXTS="${XP_GATE_JS_TS_EXTS}|py|go|java|c|cpp|cs|rb|php|scala|swift|ps1|psm1"
|
|
50
|
+
|
|
51
|
+
# Build the ERE a gate hands to `grep -E`: `\.(a|b|c)$`.
|
|
52
|
+
#
|
|
53
|
+
# Quoted deliberately. An unquoted expansion here would depend on the caller's
|
|
54
|
+
# IFS and on whether the set ever gains whitespace; capturing it in a variable
|
|
55
|
+
# and quoting lets a caller write `grep -E "$pat"` without surprises.
|
|
56
|
+
xp_gate_ext_regex() {
|
|
57
|
+
printf '\\.(%s)$' "$1"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# Print the source extensions for one gate's family.
|
|
61
|
+
#
|
|
62
|
+
# xp_gate_source_exts ccn|principles|semgrep
|
|
63
|
+
#
|
|
64
|
+
# An unknown family is an error rather than a silent empty list: a gate asking
|
|
65
|
+
# for a set that does not exist must not receive "no files", which is exactly the
|
|
66
|
+
# fail-open this file exists to remove.
|
|
67
|
+
xp_gate_source_exts() {
|
|
68
|
+
case "$1" in
|
|
69
|
+
ccn) printf '%s' "$XP_GATE_CCN_EXTS" ;;
|
|
70
|
+
principles) printf '%s' "$XP_GATE_PRINCIPLES_EXTS" ;;
|
|
71
|
+
semgrep) printf '%s' "$XP_GATE_SEMGREP_EXTS" ;;
|
|
72
|
+
*)
|
|
73
|
+
echo "xp_gate_source_exts: unknown family '$1' (expected ccn|principles|semgrep)" >&2
|
|
74
|
+
return 2
|
|
75
|
+
;;
|
|
76
|
+
esac
|
|
77
|
+
}
|