@boyingliu01/xp-gate 0.37.2 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapter-common.sh +12 -2
- package/adapters/csharp.sh +73 -2
- package/adapters/dart.sh +13 -0
- package/adapters/go.sh +5 -0
- package/adapters/iac.sh +46 -3
- package/adapters/java.sh +6 -0
- package/adapters/kotlin.sh +6 -0
- package/adapters/shell.sh +119 -34
- package/adapters/swift.sh +6 -0
- package/adapters/typescript.sh +98 -34
- package/bin/xp-gate.js +48 -2
- package/gate-10.sh +99 -26
- package/gate-12-file-hygiene.sh +13 -1
- package/gate-registry.sh +197 -0
- package/gates/common-process.ts +36 -7
- package/gates/gate-9.ts +17 -8
- package/gates/python-health.ts +215 -24
- package/hooks/adapter-common.sh +12 -2
- package/hooks/deploy-manifest.sh +100 -0
- package/hooks/gate-10.sh +99 -26
- package/hooks/gate-12-file-hygiene.sh +13 -1
- package/hooks/gate-driver.sh +120 -0
- package/hooks/gate-entries/gate-0-entry.sh +825 -0
- package/hooks/gate-entries/gate-1-entry.sh +767 -0
- package/hooks/gate-entries/gate-10-entry.sh +52 -0
- package/hooks/gate-entries/gate-11-entry.sh +120 -0
- package/hooks/gate-entries/gate-12-entry.sh +44 -0
- package/hooks/gate-entries/gate-12b-entry.sh +178 -0
- package/hooks/gate-entries/gate-12c-entry.sh +80 -0
- package/hooks/gate-entries/gate-13-entry.sh +584 -0
- package/hooks/gate-entries/gate-2-entry.sh +199 -0
- package/hooks/gate-entries/gate-3-entry.sh +53 -0
- package/hooks/gate-entries/gate-4-entry.sh +46 -0
- package/hooks/gate-entries/gate-5-entry.sh +1729 -0
- package/hooks/gate-entries/gate-6-entry.sh +658 -0
- package/hooks/gate-entries/gate-7-entry.sh +41 -0
- package/hooks/gate-entries/gate-8-entry.sh +33 -0
- package/hooks/gate-entries/gate-9-entry.sh +307 -0
- package/hooks/gate-entries/subdir-restore.sh +27 -0
- package/hooks/gate-registry.sh +51 -15
- package/hooks/hook-module-resolution.sh +73 -0
- package/hooks/install.sh +135 -0
- package/hooks/lib/now-ms.sh +55 -19
- package/hooks/lib/toolchain-path.sh +50 -6
- package/hooks/pre-commit +256 -5091
- package/hooks/pre-push +212 -25
- package/lib/__tests__/arch-config-template.test.js +190 -0
- package/lib/__tests__/baseline-shell-scope.test.js +60 -0
- package/lib/__tests__/crap-cli.test.js +14 -3
- package/lib/__tests__/deploy-manifest-check-wired.test.js +138 -0
- package/lib/__tests__/deploy-manifest-completeness.test.js +151 -0
- package/lib/__tests__/deploy-manifest-consumers-adapter-uninstall.test.js +40 -0
- package/lib/__tests__/deploy-manifest-consumers-no-private-lists.test.js +74 -0
- package/lib/__tests__/deploy-manifest-projection.test.js +66 -0
- package/lib/__tests__/deploy-manifest-shell-parity.test.js +108 -0
- package/lib/__tests__/deploy-manifest.test.js +97 -0
- package/lib/__tests__/doctor.test.js +51 -7
- package/lib/__tests__/gate-coverage.test.js +79 -12
- package/lib/__tests__/gate-numbering.test.js +28 -1
- package/lib/__tests__/install-sh-deploy-manifest.test.js +80 -0
- package/lib/__tests__/mirror-sync.test.js +45 -3
- package/lib/__tests__/npm-package.test.js +10 -7
- package/lib/__tests__/sastd-client.test.js +452 -0
- package/lib/__tests__/shared-utils-copyHooks-manifest.test.js +69 -0
- package/lib/__tests__/sprint-status-rework.test.js +1 -0
- package/lib/arch-config-template.js +87 -0
- package/lib/baseline.js +54 -2
- package/lib/deploy-manifest.js +174 -0
- package/lib/doctor.js +46 -14
- package/lib/gate-capability.js +291 -0
- package/lib/gate-coverage.js +194 -74
- package/lib/gate-identity.js +349 -0
- package/lib/gate-runner.js +11 -1
- package/lib/hook-module-resolution.js +27 -0
- package/lib/init.js +72 -5
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/sastd-client.js +534 -0
- package/lib/shared-utils.js +31 -9
- package/lib/uninstall.js +10 -7
- package/lib/update-hooks.js +27 -18
- package/mock-policy/AGENTS.md +1 -1
- package/mutation/AGENTS.md +1 -1
- package/package.json +3 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- package/principles/AGENTS.md +1 -1
- package/principles/__tests__/analyzer.test.ts +2 -1
- package/principles/__tests__/config-enforcement.test.ts +1 -0
- package/principles/__tests__/types.test.ts +1 -0
- package/principles/adapters/base.ts +14 -1
- package/principles/adapters/duplication.ts +134 -0
- package/principles/rules/__tests__/clean-code/large-file.test.ts +2 -1
- package/principles/rules/clean-code/code-duplication.ts +75 -9
- package/principles/types.ts +39 -0
- package/scripts/__tests__/check-mattpocock-license.test.js +36 -3
- package/scripts/__tests__/sync-package-content.test.js +12 -2
- package/scripts/generate-mirrors.cjs +125 -0
- package/scripts/sync-package-content.js +64 -20
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +2 -2
- package/adapters/gate-9.sh +0 -245
- package/gate-9.sh +0 -245
- package/hooks/gate-9.sh +0 -245
package/gates/python-health.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
import {
|
|
9
9
|
isToolAvailable, runTool,
|
|
10
10
|
} from './common';
|
|
11
|
+
import fs from 'fs';
|
|
12
|
+
import path from 'path';
|
|
11
13
|
|
|
12
14
|
// ── Types ──
|
|
13
15
|
|
|
@@ -18,6 +20,11 @@ export interface PythonHealthResult {
|
|
|
18
20
|
environment: { type: 'system' | 'venv' | 'conda' | 'pyenv' | 'uv'; path: string | null };
|
|
19
21
|
tools: Array<{ name: string; available: boolean; version: string; required: boolean }>;
|
|
20
22
|
issues: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Whether the project showed any Python signal. When false, `tools` entries were
|
|
25
|
+
* NOT probed and must not be read as "not installed" (#782 / REQ-GATE-PROBE-SHORTCUT).
|
|
26
|
+
*/
|
|
27
|
+
toolProbesRan: boolean;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
// ── Python Tool Registry (sync with language-tools.js LANGUAGE_REGISTRY.python) ──
|
|
@@ -25,6 +32,137 @@ export interface PythonHealthResult {
|
|
|
25
32
|
const PYTHON_REQUIRED_TOOLS = ['mypy', 'pytest'];
|
|
26
33
|
const PYTHON_OPTIONAL_TOOLS = ['ruff', 'flake8', 'black'];
|
|
27
34
|
|
|
35
|
+
// ── Python Signal Detection ──
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Files whose presence declares "this is a Python project", independent of whether
|
|
39
|
+
* any `.py` file currently exists. A freshly-scaffolded project, or one whose
|
|
40
|
+
* Python sources are generated/ignored, still needs its tool diagnostics.
|
|
41
|
+
*/
|
|
42
|
+
const PYTHON_MARKER_FILES = [
|
|
43
|
+
'pyproject.toml',
|
|
44
|
+
'requirements.txt',
|
|
45
|
+
'requirements-dev.txt',
|
|
46
|
+
'setup.py',
|
|
47
|
+
'setup.cfg',
|
|
48
|
+
'Pipfile',
|
|
49
|
+
'poetry.lock',
|
|
50
|
+
'uv.lock',
|
|
51
|
+
'.python-version',
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/** Directories never worth walking when looking for a `.py` file. */
|
|
55
|
+
const SIGNAL_SKIP_DIRS = new Set([
|
|
56
|
+
'node_modules', '.git', '.venv', 'venv', '__pycache__',
|
|
57
|
+
'.stryker-tmp', 'dist', 'build', '.tox', '.mypy_cache', '.pytest_cache',
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const SIGNAL_MAX_DEPTH = 4;
|
|
61
|
+
const SIGNAL_MAX_ENTRIES = 5000;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Virtualenv directory names. Their presence alone is a Python signal even with
|
|
65
|
+
* no marker file, common for `python -m venv .venv`-only setups.
|
|
66
|
+
*/
|
|
67
|
+
const VENV_DIR_NAMES = ['.venv', 'venv'];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Does this project show any sign of being Python at all?
|
|
71
|
+
*
|
|
72
|
+
* This exists to answer the ONE question that must be asked BEFORE paying for
|
|
73
|
+
* tool probes: "is there anything here for Python tooling to check?" On a
|
|
74
|
+
* JavaScript/TypeScript project the answer is no, yet `checkPythonHealth` used to
|
|
75
|
+
* probe mypy/pytest/ruff/flake8/black anyway — measured 3.2 s on this repo, where
|
|
76
|
+
* those probes cannot possibly produce information about the code.
|
|
77
|
+
*
|
|
78
|
+
* The predicate is deliberately BROAD (marker file OR any `.py` file OR a Python
|
|
79
|
+
* venv directory), because the failure mode of a too-narrow predicate is
|
|
80
|
+
* "claimed to check Python, checked nothing" — the worst defect class in this
|
|
81
|
+
* repo. A false positive only costs the old behaviour.
|
|
82
|
+
*
|
|
83
|
+
* Note on scope: this is a signal about the PROJECT, not about the change set —
|
|
84
|
+
* the right question here, because python-health reports environment health rather
|
|
85
|
+
* than scanning specific files. A project with ANY Python anywhere (this repo has
|
|
86
|
+
* a real `tests/*.py` suite plus `githooks/lib/prepush-score.py`) correctly keeps
|
|
87
|
+
* full diagnostics. The saving lands on genuinely single-language consumer
|
|
88
|
+
* projects, which is the common case and the one the measurement fixture models.
|
|
89
|
+
* Gitignored scratch trees cannot trigger it: any dot-directory is skipped.
|
|
90
|
+
*
|
|
91
|
+
* @param cwd project root to inspect; defaults to process.cwd()
|
|
92
|
+
*/
|
|
93
|
+
export function hasPythonSignal(cwd?: string): boolean {
|
|
94
|
+
const root = cwd || process.cwd();
|
|
95
|
+
return hasMarkerFile(root) || hasVenvDir(root) || containsPythonFile(root);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Is any marker file present? An unreadable root is not evidence either way. */
|
|
99
|
+
function hasMarkerFile(root: string): boolean {
|
|
100
|
+
return PYTHON_MARKER_FILES.some((marker) => {
|
|
101
|
+
try {
|
|
102
|
+
return fs.existsSync(path.join(root, marker));
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Is a virtualenv directory present? Only the signal matters here, so an
|
|
111
|
+
* unreadable root still counts as a hit rather than being silently skipped.
|
|
112
|
+
*/
|
|
113
|
+
function hasVenvDir(root: string): boolean {
|
|
114
|
+
return VENV_DIR_NAMES.some((venv) => {
|
|
115
|
+
try {
|
|
116
|
+
return fs.existsSync(path.join(root, venv));
|
|
117
|
+
} catch {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Should this directory be skipped during the .py walk? */
|
|
124
|
+
function shouldSkipDir(entry: import('fs').Dirent): boolean {
|
|
125
|
+
return SIGNAL_SKIP_DIRS.has(entry.name) || entry.name.startsWith('.');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** A non-directory entry is a hit only if it is a .py file. */
|
|
129
|
+
function isPythonFileEntry(entry: import('fs').Dirent): boolean {
|
|
130
|
+
return !entry.isDirectory() && entry.name.endsWith('.py');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* One directory level: does this directory or any descendant hold a .py file?
|
|
135
|
+
* Split from containsPythonFile so the bounds and the traversal stay separately
|
|
136
|
+
* readable, and bounded by depth and entry count so a pathological tree cannot
|
|
137
|
+
* make a gate hang.
|
|
138
|
+
*/
|
|
139
|
+
function walkForPythonFile(dir: string, depth: number, counter: { seen: number }): boolean {
|
|
140
|
+
if (depth > SIGNAL_MAX_DEPTH || counter.seen > SIGNAL_MAX_ENTRIES) return false;
|
|
141
|
+
let entries: import('fs').Dirent[];
|
|
142
|
+
try {
|
|
143
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
for (const entry of entries) {
|
|
148
|
+
counter.seen += 1;
|
|
149
|
+
if (counter.seen > SIGNAL_MAX_ENTRIES) return false;
|
|
150
|
+
if (isPythonFileEntry(entry)) return true;
|
|
151
|
+
if (entry.isDirectory() && !shouldSkipDir(entry) && walkForPythonFile(path.join(dir, entry.name), depth + 1, counter)) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Look for any .py file under root. Returns false on a read error: "could not
|
|
160
|
+
* look" must never be reported as "definitely not Python".
|
|
161
|
+
*/
|
|
162
|
+
function containsPythonFile(root: string): boolean {
|
|
163
|
+
return walkForPythonFile(root, 0, { seen: 0 });
|
|
164
|
+
}
|
|
165
|
+
|
|
28
166
|
// ── Python Detection ──
|
|
29
167
|
|
|
30
168
|
/**
|
|
@@ -172,8 +310,65 @@ function checkPythonTool(
|
|
|
172
310
|
return { name, available: false, version: '' };
|
|
173
311
|
}
|
|
174
312
|
|
|
313
|
+
/**
|
|
314
|
+
* Build the "never probed" tool list.
|
|
315
|
+
*
|
|
316
|
+
* The report SHAPE must not change when the probes are skipped: every tool is
|
|
317
|
+
* still listed, just as not-probed rather than probed-and-missing. Returning an
|
|
318
|
+
* empty array would be a silent lie to any consumer that counts tools.
|
|
319
|
+
*/
|
|
320
|
+
function unprobedTools(): PythonHealthResult['tools'] {
|
|
321
|
+
const entry = (name: string, required: boolean) => ({ name, available: false, version: '', required });
|
|
322
|
+
return [
|
|
323
|
+
...PYTHON_REQUIRED_TOOLS.map(n => entry(n, true)),
|
|
324
|
+
...PYTHON_OPTIONAL_TOOLS.map(n => entry(n, false)),
|
|
325
|
+
];
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Resolve the Python tool list, honouring the input short-circuit (#782, P0-A).
|
|
330
|
+
*
|
|
331
|
+
* Probing mypy/pytest/ruff/flake8/black costs ~2.6 s of subprocess starts
|
|
332
|
+
* (measured on this machine: 547+550+291+807+394 ms) and tells you nothing about
|
|
333
|
+
* a project with no Python in it. The signal question is free, so it goes first.
|
|
334
|
+
*/
|
|
335
|
+
function resolvePythonTools(
|
|
336
|
+
pythonExe: string,
|
|
337
|
+
cwd: string | undefined,
|
|
338
|
+
pythonSignal: boolean,
|
|
339
|
+
): { tools: PythonHealthResult['tools']; missingRequired: PythonHealthResult['tools'] } {
|
|
340
|
+
const tools = pythonSignal ? checkTools(pythonExe, cwd) : unprobedTools();
|
|
341
|
+
return { tools, missingRequired: tools.filter(t => t.required && !t.available) };
|
|
342
|
+
}
|
|
343
|
+
|
|
175
344
|
// ── Main Health Check ──
|
|
176
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Check the Python version, pip, and virtualenv, appending an issue for each
|
|
348
|
+
* one that is missing or below minimum.
|
|
349
|
+
*/
|
|
350
|
+
function inspectEnvironment(
|
|
351
|
+
python: { exe: string; version: string },
|
|
352
|
+
cwd: string | undefined,
|
|
353
|
+
issues: string[],
|
|
354
|
+
): { pip: PythonHealthResult['pip']; environment: PythonHealthResult['environment'] } {
|
|
355
|
+
if (!checkPythonVersion(python.version)) {
|
|
356
|
+
issues.push(`Python ${python.version} < 3.8.0 minimum. Upgrade recommended.`);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const pip = detectPip(python.exe);
|
|
360
|
+
if (!pip.available) {
|
|
361
|
+
issues.push(`pip not available. Install: ${python.exe} -m ensurepip`);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const environment = detectEnvironment(cwd);
|
|
365
|
+
if (environment.type === 'system') {
|
|
366
|
+
issues.push('No virtual environment detected. Consider using venv/conda/uv.');
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return { pip, environment };
|
|
370
|
+
}
|
|
371
|
+
|
|
177
372
|
/**
|
|
178
373
|
* Run comprehensive Python environment health check.
|
|
179
374
|
*/
|
|
@@ -191,38 +386,32 @@ export function checkPythonHealth(cwd?: string): PythonHealthResult {
|
|
|
191
386
|
environment: { type: 'system', path: null },
|
|
192
387
|
tools: [],
|
|
193
388
|
issues,
|
|
389
|
+
// Python itself is absent, so no tool could have been probed.
|
|
390
|
+
toolProbesRan: false,
|
|
194
391
|
};
|
|
195
392
|
}
|
|
196
393
|
|
|
197
|
-
// 2.
|
|
198
|
-
|
|
199
|
-
issues.push(`Python ${python.version} < 3.8.0 minimum. Upgrade recommended.`);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// 3. Detect pip
|
|
203
|
-
const pip = detectPip(python.exe);
|
|
204
|
-
if (!pip.available) {
|
|
205
|
-
issues.push(`pip not available. Install: ${python.exe} -m ensurepip`);
|
|
206
|
-
}
|
|
394
|
+
// 2-4. Version, pip, and virtualenv — each appends its own issue if unhappy.
|
|
395
|
+
const { pip, environment } = inspectEnvironment(python, cwd, issues);
|
|
207
396
|
|
|
208
|
-
//
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
issues.push('No virtual environment detected. Consider using venv/conda/uv.');
|
|
212
|
-
}
|
|
397
|
+
// 5. Check tools (input short-circuit — see resolvePythonTools)
|
|
398
|
+
const pythonSignal = hasPythonSignal(cwd);
|
|
399
|
+
const { tools, missingRequired } = resolvePythonTools(python.exe, cwd, pythonSignal);
|
|
213
400
|
|
|
214
|
-
//
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (missingRequired.length > 0) {
|
|
401
|
+
// Only report missing tools when the project is actually Python — otherwise this
|
|
402
|
+
// is a non-signal, and telling a TS project to install mypy is noise.
|
|
403
|
+
if (missingRequired.length > 0 && pythonSignal) {
|
|
218
404
|
const names = missingRequired.map(t => t.name).join(', ');
|
|
219
405
|
issues.push(`Required tools missing: ${names}. Install: ${python.exe} -m pip install ${names}`);
|
|
220
406
|
}
|
|
221
407
|
|
|
408
|
+
// `missingRequired` counts only when it was actually PROBED. On a non-Python
|
|
409
|
+
// project the tools are unknown-and-irrelevant, not missing: counting them would
|
|
410
|
+
// report "unhealthy" for a repo that has nothing for Python tooling to check.
|
|
222
411
|
const healthy = issues.filter(i => i.includes('not found') || i.includes('minimum')).length === 0
|
|
223
|
-
&& missingRequired.length === 0;
|
|
412
|
+
&& (!pythonSignal || missingRequired.length === 0);
|
|
224
413
|
|
|
225
|
-
return { healthy, python, pip, environment, tools, issues };
|
|
414
|
+
return { healthy, python, pip, environment, tools, issues, toolProbesRan: pythonSignal };
|
|
226
415
|
}
|
|
227
416
|
|
|
228
417
|
// ── CLI Entry Point ──
|
|
@@ -241,11 +430,13 @@ if (process.argv.includes('--run')) {
|
|
|
241
430
|
console.log('');
|
|
242
431
|
|
|
243
432
|
if (result.tools.length > 0) {
|
|
244
|
-
|
|
433
|
+
const probed = result.toolProbesRan;
|
|
434
|
+
console.log(probed ? ' Tools:' : ' Tools: (not probed — no Python signal in this project)');
|
|
245
435
|
for (const t of result.tools) {
|
|
246
|
-
const icon = t.available ? '✅' : (t.required ? '❌' : '⚠️');
|
|
436
|
+
const icon = probed ? (t.available ? '✅' : (t.required ? '❌' : '⚠️')) : '·';
|
|
247
437
|
const req = t.required ? '(required)' : '(optional)';
|
|
248
|
-
|
|
438
|
+
const state = probed ? (t.available ? t.version : 'not installed') : 'skipped';
|
|
439
|
+
console.log(` ${icon} ${t.name} ${state} ${req}`);
|
|
249
440
|
}
|
|
250
441
|
console.log('');
|
|
251
442
|
}
|
package/hooks/adapter-common.sh
CHANGED
|
@@ -225,7 +225,15 @@ require_tool() {
|
|
|
225
225
|
return 0
|
|
226
226
|
fi
|
|
227
227
|
|
|
228
|
-
|
|
228
|
+
# Project-local node_modules/.bin. This replaces an `npx --no-install <tool>
|
|
229
|
+
# --version` probe: `--no-install` does prevent the package from being
|
|
230
|
+
# INSTALLED, but it still asks the registry every time (measured: 697 ms on a
|
|
231
|
+
# cache miss, 105 ms revalidating on a hit), inside a pre-commit hook. And once
|
|
232
|
+
# any earlier misuse populates the npx cache the same probe returns rc=0 for a
|
|
233
|
+
# tool the project never depended on, so the answer can be corrupted, not just
|
|
234
|
+
# slow. Checking the directory the tool would actually live in is both cheaper
|
|
235
|
+
# and honest. See docs/incidents/2026-11-09-command-could-not-run-*.
|
|
236
|
+
if [ -x "node_modules/.bin/$tool_name" ]; then
|
|
229
237
|
return 0
|
|
230
238
|
fi
|
|
231
239
|
|
|
@@ -289,7 +297,9 @@ detect_mutation_testable() {
|
|
|
289
297
|
if [ -f "package.json" ] && grep -qE '"@stryker-mutator[^"]*"' package.json 2>/dev/null; then
|
|
290
298
|
return 0
|
|
291
299
|
fi
|
|
292
|
-
|
|
300
|
+
# Project-local install. Replaces `npx --no-install stryker --version`, which
|
|
301
|
+
# still queried the registry on every call (see require_tool above).
|
|
302
|
+
if [ -x "node_modules/.bin/stryker" ]; then
|
|
293
303
|
return 0
|
|
294
304
|
fi
|
|
295
305
|
# Legacy config files (backwards compatibility — deprecated)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# GENERATED FILE — DO NOT EDIT.
|
|
3
|
+
# Source of truth: src/npm-package/lib/deploy-manifest.js
|
|
4
|
+
# Regenerate: node scripts/generate-deploy-manifest.cjs
|
|
5
|
+
#
|
|
6
|
+
# 部署文件清单的 shell 投影(REQ-DEPLOY-001,#789 根因②)。install.sh
|
|
7
|
+
# 无法 require JS,只能 source 本投影。JS 模块是唯一事实源;手改本文件
|
|
8
|
+
# 会让 install.sh 与 doctor/Node 消费方(直接读 JS 模块)不一致——
|
|
9
|
+
# 正是 #495/#500 的双投影漂移教训。
|
|
10
|
+
#
|
|
11
|
+
# 每个 DEPLOY_* 常量被 sourcing 父进程(install.sh)消费,非本文件。
|
|
12
|
+
# A linter checking this file alone cannot see that consumer, so each
|
|
13
|
+
# declaration carries a scoped directive (#548). Generated, not hand-added.
|
|
14
|
+
|
|
15
|
+
# 随 hook 部署到 hooks 目标目录的脚本(平铺,无子目录)。
|
|
16
|
+
# Consumed by the sourcing parent, not here.
|
|
17
|
+
# shellcheck disable=SC2034
|
|
18
|
+
DEPLOY_HOOK_FILES=(
|
|
19
|
+
'pre-commit'
|
|
20
|
+
'pre-push'
|
|
21
|
+
'post-commit'
|
|
22
|
+
'post-merge'
|
|
23
|
+
'hook-module-resolution.sh'
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# 门禁脚本全集(10 个 gate-*.sh + sprint-gate.sh)。部署目标依链路而异:
|
|
27
|
+
# 全局 copyAdapters → adapters/;项目内 install.sh → .git/hooks/。
|
|
28
|
+
# Consumed by the sourcing parent, not here.
|
|
29
|
+
# shellcheck disable=SC2034
|
|
30
|
+
DEPLOY_GATE_FILES=(
|
|
31
|
+
'gate-3.sh'
|
|
32
|
+
'gate-4.sh'
|
|
33
|
+
'gate-6-layers.sh'
|
|
34
|
+
'gate-7.sh'
|
|
35
|
+
'gate-8.sh'
|
|
36
|
+
'gate-10.sh'
|
|
37
|
+
'gate-12-file-hygiene.sh'
|
|
38
|
+
'gate-13-compiler-strictness.sh'
|
|
39
|
+
'gate-registry.sh'
|
|
40
|
+
'sprint-gate.sh'
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# 适配器基础设施与 hooks/lib(单独字段,部署目标不同)。
|
|
44
|
+
# Consumed by the sourcing parent, not here.
|
|
45
|
+
# shellcheck disable=SC2034
|
|
46
|
+
DEPLOY_ADAPTER_COMMON='adapter-common.sh'
|
|
47
|
+
DEPLOY_HOOKS_LIB='lib'
|
|
48
|
+
|
|
49
|
+
# 非 hook 模块全集(lib/* 逐个列出,加 adapter-common.sh、deploy-manifest.sh、
|
|
50
|
+
# install.sh)——REQ-DEPLOY-002。
|
|
51
|
+
#
|
|
52
|
+
# 这里刻意逐文件列出,而不是给一个 `lib` 目录名让安装器自己 glob。目录名形态
|
|
53
|
+
# 让「清单是否完整」无法通过读清单来回答:装到用户磁盘上的文件可能没有任何
|
|
54
|
+
# 清单条目,于是「都在清单里」永远为真。逐文件列出使清单成为真正的安装计划。
|
|
55
|
+
# Consumed by the sourcing parent, not here.
|
|
56
|
+
# shellcheck disable=SC2034
|
|
57
|
+
DEPLOY_MODULE_FILES=(
|
|
58
|
+
'adapter-common.sh'
|
|
59
|
+
'deploy-manifest.sh'
|
|
60
|
+
'install.sh'
|
|
61
|
+
'gate-driver.sh'
|
|
62
|
+
'gate-entries/gate-0-entry.sh'
|
|
63
|
+
'gate-entries/gate-1-entry.sh'
|
|
64
|
+
'gate-entries/gate-2-entry.sh'
|
|
65
|
+
'gate-entries/gate-3-entry.sh'
|
|
66
|
+
'gate-entries/gate-4-entry.sh'
|
|
67
|
+
'gate-entries/gate-5-entry.sh'
|
|
68
|
+
'gate-entries/gate-6-entry.sh'
|
|
69
|
+
'gate-entries/gate-7-entry.sh'
|
|
70
|
+
'gate-entries/gate-8-entry.sh'
|
|
71
|
+
'gate-entries/gate-9-entry.sh'
|
|
72
|
+
'gate-entries/gate-10-entry.sh'
|
|
73
|
+
'gate-entries/gate-11-entry.sh'
|
|
74
|
+
'gate-entries/gate-12-entry.sh'
|
|
75
|
+
'gate-entries/gate-12b-entry.sh'
|
|
76
|
+
'gate-entries/gate-12c-entry.sh'
|
|
77
|
+
'gate-entries/gate-13-entry.sh'
|
|
78
|
+
'gate-entries/subdir-restore.sh'
|
|
79
|
+
'lib/Measure-PowerShellComplexity.ps1'
|
|
80
|
+
'lib/assertion-quality.sh'
|
|
81
|
+
'lib/audit-sanitize.sh'
|
|
82
|
+
'lib/ccn-ratchet.sh'
|
|
83
|
+
'lib/coverage-total.sh'
|
|
84
|
+
'lib/diff-coverage.sh'
|
|
85
|
+
'lib/docs-only.sh'
|
|
86
|
+
'lib/gate-5c-alignment.sh'
|
|
87
|
+
'lib/java-test-selection.sh'
|
|
88
|
+
'lib/jscpd-run.sh'
|
|
89
|
+
'lib/layer-baseline.cjs'
|
|
90
|
+
'lib/native-path.sh'
|
|
91
|
+
'lib/now-ms.sh'
|
|
92
|
+
'lib/prepush-score.py'
|
|
93
|
+
'lib/python-incremental-typecheck.sh'
|
|
94
|
+
'lib/python-test-selection.sh'
|
|
95
|
+
'lib/sprint-gate-report.sh'
|
|
96
|
+
'lib/test-failure.sh'
|
|
97
|
+
'lib/toolchain-path.sh'
|
|
98
|
+
'lib/typecheck.sh'
|
|
99
|
+
'lib/validate-code-walkthrough.cjs'
|
|
100
|
+
)
|
package/hooks/gate-10.sh
CHANGED
|
@@ -40,10 +40,11 @@ GATE_10_SCANNED_FILES=0
|
|
|
40
40
|
# GATE_10_SEMGREP_PATH records what actually happened, so a reader of the report
|
|
41
41
|
# can tell a fast run from a degraded one without timing it.
|
|
42
42
|
#
|
|
43
|
-
# The daemon
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
43
|
+
# The daemon exists but is NOT the default. It is opt-in via XP_GATE_SASTD=on,
|
|
44
|
+
# and `auto` resolves to direct on purpose -- see the `auto` case below, which
|
|
45
|
+
# records the measurement that made the default a direct scan. Everything here is
|
|
46
|
+
# a switch plus a report field; with the default settings the gate behaves exactly
|
|
47
|
+
# as it did before the daemon was written.
|
|
47
48
|
# ---------------------------------------------------------------------------
|
|
48
49
|
# Consumed by the sourcing parent (pre-commit report JSON), not here.
|
|
49
50
|
# shellcheck disable=SC2034
|
|
@@ -62,28 +63,24 @@ case "${XP_GATE_SASTD:-direct}" in
|
|
|
62
63
|
GATE_10_SEMGREP_PATH="direct"
|
|
63
64
|
;;
|
|
64
65
|
auto)
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
#
|
|
66
|
+
# `auto` deliberately does NOT select the daemon. It was meant to mean "use one
|
|
67
|
+
# if available", but measurement killed that default: with Gate 10's real
|
|
68
|
+
# ruleset (p/security-audit, 225 rules) the daemon saves ~20% in steady state
|
|
69
|
+
# (6.6-6.9s -> 5.2-5.4s) and is SLOWER end to end (10.5s -> 14.6s), because each
|
|
70
|
+
# gate run is a fresh process that pays the daemon's own startup without
|
|
71
|
+
# amortising it over a second call. Making that the automatic choice would tax
|
|
72
|
+
# every user for a benefit most of them never see.
|
|
73
|
+
#
|
|
74
|
+
# `auto` therefore behaves as "off" but says so through the `path` field, and it
|
|
75
|
+
# never sets degraded -- a plain direct run is not a degraded run.
|
|
74
76
|
GATE_10_SEMGREP_PATH="direct"
|
|
75
77
|
;;
|
|
76
78
|
on|1|true)
|
|
77
|
-
# The user asserted a daemon SHOULD be here
|
|
78
|
-
#
|
|
79
|
+
# Opt-in only. The user asserted a daemon SHOULD be here; whether one actually
|
|
80
|
+
# answers can only be known after the probe, so the degrade flag is set there.
|
|
81
|
+
# Setting it at parse time would report a failure before anything has failed.
|
|
79
82
|
# This is the branch that must never become "skip the scan and call it a pass".
|
|
80
|
-
GATE_10_SEMGREP_PATH="
|
|
81
|
-
GATE_10_SASTD_DEGRADED=1
|
|
82
|
-
# stderr, not stdout: this file is SOURCED by pre-commit, so stdout belongs to
|
|
83
|
-
# the parent's report stream. A notice written there would land inside output
|
|
84
|
-
# that another consumer may parse. stderr still reaches the developer's
|
|
85
|
-
# terminal, which is the only audience a notice needs.
|
|
86
|
-
echo " ℹ️ sastd requested but not available — using direct semgrep (degraded)" >&2
|
|
83
|
+
GATE_10_SEMGREP_PATH="daemon"
|
|
87
84
|
;;
|
|
88
85
|
*)
|
|
89
86
|
# An unrecognised value is a configuration mistake, not a reason to scan
|
|
@@ -251,8 +248,85 @@ EOF
|
|
|
251
248
|
fi
|
|
252
249
|
SEMGREP_TIMEOUT_S="${XP_GATE_SEMGREP_TIMEOUT:-180}"
|
|
253
250
|
SEMGREP_TIMED_OUT=false
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
SEMGREP_STDOUT_FILE=$(mktemp)
|
|
252
|
+
SEMGREP_EXIT=0
|
|
253
|
+
SEMGREP_OUTPUT=""
|
|
254
|
+
|
|
255
|
+
# Daemon path (E3). One long-lived semgrep process, so its ~2.5s import tax is
|
|
256
|
+
# paid once per machine instead of once per gate run: direct 3.8-4.0s vs daemon
|
|
257
|
+
# hot 2.1-2.3s measured on this repo.
|
|
258
|
+
#
|
|
259
|
+
# A SWITCHED path, never a replacement: every failure below falls through to
|
|
260
|
+
# the direct scan. The daemon may make this gate SLOWER; it must never make it
|
|
261
|
+
# greener (#518/#559).
|
|
262
|
+
if [ "$GATE_10_SEMGREP_PATH" = "daemon" ] && command -v node >/dev/null 2>&1; then
|
|
263
|
+
# The protocol carries exactly ONE config. Counting rather than overwriting
|
|
264
|
+
# matters: the previous loop kept only the last --config, so a repo with two
|
|
265
|
+
# would have been scanned with one and reported on as if fully checked.
|
|
266
|
+
rules_for_daemon=""
|
|
267
|
+
config_count=0
|
|
268
|
+
for _arg in "${SEMGREP_RULES[@]}"; do
|
|
269
|
+
case "$_arg" in
|
|
270
|
+
--config=*)
|
|
271
|
+
rules_for_daemon="${_arg#--config=}"
|
|
272
|
+
config_count=$((config_count + 1))
|
|
273
|
+
;;
|
|
274
|
+
esac
|
|
275
|
+
done
|
|
276
|
+
# Anything the protocol cannot express exactly is left to the direct path
|
|
277
|
+
# rather than approximated:
|
|
278
|
+
# - more than one config (nothing would report the dropped one);
|
|
279
|
+
# - p/csharp (Gate 10 adds it for C# repos);
|
|
280
|
+
# - "auto" (semgrep's own rule selection, not a spec we can pass through);
|
|
281
|
+
# - anything with a comma, which is semgrep's multi-config shorthand;
|
|
282
|
+
# - a remote URL, which the daemon would resolve against its own cwd and
|
|
283
|
+
# registry cache instead of the one the CLI would have used.
|
|
284
|
+
if [ "$config_count" -ne 1 ]; then
|
|
285
|
+
rules_for_daemon=""
|
|
286
|
+
fi
|
|
287
|
+
case "$rules_for_daemon" in
|
|
288
|
+
*p/csharp*|*","*|*"://"*|auto|"") rules_for_daemon="" ;;
|
|
289
|
+
esac
|
|
290
|
+
if [ -n "$rules_for_daemon" ]; then
|
|
291
|
+
daemon_roots=$(printf '%s\n' "${SEMGREP_ARGS[@]}" | grep -v '^--include=' || true)
|
|
292
|
+
# ARGV TRAP: under `node -e` there is NO script path in argv, so the first
|
|
293
|
+
# user argument is argv[1]. Indexing it as argv[2] passes undefined as the
|
|
294
|
+
# config, semgrep raises a python TypeError, and the gate "degrades" for a
|
|
295
|
+
# reason unrelated to the daemon -- which is how this looked like a flaky
|
|
296
|
+
# integration instead of an off-by-one.
|
|
297
|
+
# shellcheck disable=SC2086 # one argv entry per scanning root: word splitting is intended
|
|
298
|
+
if DAEMON_JSON=$(XP_GATE_SASTD=on node -e 'const NL = String.fromCharCode(10);
|
|
299
|
+
const { requestScan } = require(process.argv[1]);
|
|
300
|
+
requestScan({ config: process.argv[2], roots: process.argv.slice(3) }).then((r) => {
|
|
301
|
+
if (!r.ok) { process.stderr.write("SASTD_UNAVAILABLE: " + r.error + NL); process.exit(3); }
|
|
302
|
+
process.stdout.write(JSON.stringify(r.payload));
|
|
303
|
+
}).catch((e) => { process.stderr.write("SASTD_UNAVAILABLE: " + e.message + NL); process.exit(3); });' "$(cd "$GATE_DIR/../src/npm-package/lib" 2>/dev/null && pwd -W)/sastd-client.js" "$rules_for_daemon" $daemon_roots 2>"$SEMGREP_STDOUT_FILE.stderr"); then
|
|
304
|
+
printf '%s' "$DAEMON_JSON" > "$SEMGREP_STDOUT_FILE"
|
|
305
|
+
SEMGREP_OUTPUT=$(cat "$SEMGREP_STDOUT_FILE.stderr" 2>/dev/null || true)
|
|
306
|
+
rm -f "$SEMGREP_STDOUT_FILE.stderr"
|
|
307
|
+
else
|
|
308
|
+
SEMGREP_EXIT=$?
|
|
309
|
+
rm -f "$SEMGREP_STDOUT_FILE.stderr"
|
|
310
|
+
: > "$SEMGREP_STDOUT_FILE"
|
|
311
|
+
case "${XP_GATE_SASTD:-direct}" in
|
|
312
|
+
on|1|true)
|
|
313
|
+
# Consumed by the sourcing parent (pre-commit report JSON), not here.
|
|
314
|
+
# shellcheck disable=SC2034
|
|
315
|
+
GATE_10_SASTD_DEGRADED=1
|
|
316
|
+
echo " ⚠️ sastd requested but unavailable — using direct semgrep (degraded)" >&2
|
|
317
|
+
;;
|
|
318
|
+
*)
|
|
319
|
+
echo " ℹ️ sastd unavailable — using direct semgrep" >&2
|
|
320
|
+
;;
|
|
321
|
+
esac
|
|
322
|
+
GATE_10_SEMGREP_PATH="direct"
|
|
323
|
+
fi
|
|
324
|
+
else
|
|
325
|
+
GATE_10_SEMGREP_PATH="direct"
|
|
326
|
+
fi
|
|
327
|
+
fi
|
|
328
|
+
|
|
329
|
+
if [ "$GATE_10_SEMGREP_PATH" = "direct" ] && command -v timeout >/dev/null 2>&1; then
|
|
256
330
|
SEMGREP_OUTPUT=$(timeout -k 10 "$SEMGREP_TIMEOUT_S" \
|
|
257
331
|
"$SEMGREP_CMD" scan "${SEMGREP_RULES[@]}" --json --disable-version-check \
|
|
258
332
|
"${SEMGREP_ARGS[@]}" 2>&1 >"$SEMGREP_STDOUT_FILE")
|
|
@@ -266,13 +340,12 @@ EOF
|
|
|
266
340
|
case "$SEMGREP_EXIT" in
|
|
267
341
|
124|137) SEMGREP_TIMED_OUT=true ;;
|
|
268
342
|
esac
|
|
269
|
-
|
|
343
|
+
elif [ "$GATE_10_SEMGREP_PATH" = "direct" ]; then
|
|
270
344
|
# No `timeout` on this platform (stock macOS). Say so: an unbounded run
|
|
271
345
|
# nobody mentioned is exactly how #559 stayed invisible for a whole
|
|
272
346
|
# release. The scan still runs -- refusing to scan would be a worse
|
|
273
347
|
# trade -- but the unbounded window is now stated.
|
|
274
348
|
echo " ⚠️ 'timeout' command not available — semgrep runs UNBOUNDED (install coreutils or set up gtimeout)"
|
|
275
|
-
SEMGREP_STDOUT_FILE=$(mktemp)
|
|
276
349
|
SEMGREP_OUTPUT=$("$SEMGREP_CMD" scan "${SEMGREP_RULES[@]}" --json --disable-version-check \
|
|
277
350
|
"${SEMGREP_ARGS[@]}" 2>&1 >"$SEMGREP_STDOUT_FILE")
|
|
278
351
|
SEMGREP_EXIT=$?
|
|
@@ -15,7 +15,19 @@ GATE_12_START=$(gate_start_ms)
|
|
|
15
15
|
MAX_FILE_SIZE_BYTES="${XP_GATE_MAX_FILE_SIZE:-1048576}" # 1MB default
|
|
16
16
|
|
|
17
17
|
# Get list of staged files (excluding deleted files)
|
|
18
|
-
|
|
18
|
+
#
|
|
19
|
+
# Third-party trees are excluded. In a fresh `git init` fixture the CI's
|
|
20
|
+
# "First Commit Gates" job does `git add -A` before committing, so every
|
|
21
|
+
# node_modules/ file becomes staged — and third-party packages legitimately
|
|
22
|
+
# CONTAIN `<<<<<<<` text as documentation (semver/README.md, various NOTICE.txt).
|
|
23
|
+
# Gate 12 then reported "merge conflict markers detected" for files no author
|
|
24
|
+
# wrote, blocking the fixture commit, on every commit for months. A hygiene check
|
|
25
|
+
# that reads vendored documentation as a conflict is not finding anything.
|
|
26
|
+
#
|
|
27
|
+
# This is the same class as the __pycache__ filter in check-hook-mirror.sh (#587):
|
|
28
|
+
# build/dependency artefacts are not project source and must not be judged as it.
|
|
29
|
+
STAGED_FILES=$(git diff --cached --name-only --diff-filter=d 2>/dev/null \
|
|
30
|
+
| grep -vE '(^|/)(node_modules|\.stryker-tmp|vendor)/' || true)
|
|
19
31
|
|
|
20
32
|
if [ -z "$STAGED_FILES" ]; then
|
|
21
33
|
echo " ℹ️ No staged files — skipping"
|