@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
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quote/comment masker for Gate 10's import scanner (#759).
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `gate-10.ts` when that file crossed the 1050-line limit that
|
|
5
|
+
* Gate 4's `clean-code.large-file` rule enforces. The masker is a self-contained
|
|
6
|
+
* state machine over a string, so the split is along a real seam rather than an
|
|
7
|
+
* arbitrary line count: nothing here knows about imports, files or gates.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Replace quotes/comments that are not code-level delimiters with a sentinel.
|
|
12
|
+
*
|
|
13
|
+
* Walks the source tracking whether it is currently inside a string, template
|
|
14
|
+
* literal, line comment or block comment. Creatures encountered at the top level
|
|
15
|
+
* (depth 0) are left ALONE — those are real delimiters and the scanner needs
|
|
16
|
+
* them. Anything encountered while already inside a literal or comment is text,
|
|
17
|
+
* and every quote-like character in there becomes `QUOTE_SENTINEL` so the
|
|
18
|
+
* import regexes cannot close a match against it.
|
|
19
|
+
*
|
|
20
|
+
* Length is preserved exactly (one character in, one character out), newlines
|
|
21
|
+
* included, so line/column positions in the masked source match the original.
|
|
22
|
+
*
|
|
23
|
+
* Not a parser: it does not understand regex literals. That limitation can only
|
|
24
|
+
* cause a MISS (a region left unmasked), never a false violation, and pulling a
|
|
25
|
+
* real tokenizer into a check with a sub-second budget is not worth it (#640).
|
|
26
|
+
* If a regex literal ever produces a phantom violation, that is the signal to
|
|
27
|
+
* replace this with a proper lexer.
|
|
28
|
+
*/
|
|
29
|
+
const QUOTE_SENTINEL = '\u0000';
|
|
30
|
+
|
|
31
|
+
/** Mutable state threaded through the masking handlers. */
|
|
32
|
+
interface MaskState {
|
|
33
|
+
readonly content: string;
|
|
34
|
+
readonly out: string[];
|
|
35
|
+
i: number;
|
|
36
|
+
mode: MaskMode;
|
|
37
|
+
/** One brace depth per open `${...}`; a stack, because interpolations nest. */
|
|
38
|
+
interpolationDepths: number[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** What the masker is currently inside of. `code` is depth 0. */
|
|
42
|
+
type MaskMode = 'code' | 'single' | 'double' | 'template' | 'line-comment' | 'block-comment';
|
|
43
|
+
|
|
44
|
+
/** The delimiter that closes a plain literal mode. */
|
|
45
|
+
function literalCloser(mode: MaskMode): string {
|
|
46
|
+
if (mode === 'single') return "'";
|
|
47
|
+
if (mode === 'double') return '"';
|
|
48
|
+
return '`';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Emit one character, keeping newlines so line numbers stay aligned. */
|
|
52
|
+
function emitText(state: MaskState, ch: string): void {
|
|
53
|
+
state.out.push(ch === '\n' ? '\n' : ' ');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Handle a character while inside a `//` comment. */
|
|
57
|
+
function stepLineComment(state: MaskState): void {
|
|
58
|
+
const ch = state.content[state.i];
|
|
59
|
+
if (ch === '\n') {
|
|
60
|
+
state.out.push('\n');
|
|
61
|
+
state.mode = 'code';
|
|
62
|
+
} else {
|
|
63
|
+
state.out.push(' ');
|
|
64
|
+
}
|
|
65
|
+
state.i += 1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Handle a character while inside a `/* ... *\/` comment. */
|
|
69
|
+
function stepBlockComment(state: MaskState): void {
|
|
70
|
+
const { content, i } = state;
|
|
71
|
+
if (content[i] === '*' && content[i + 1] === '/') {
|
|
72
|
+
state.out.push(' ');
|
|
73
|
+
state.i += 2;
|
|
74
|
+
state.mode = 'code';
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
emitText(state, content[i]);
|
|
78
|
+
state.i += 1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Handle an escape sequence inside a literal: both characters are text.
|
|
83
|
+
*
|
|
84
|
+
* The backslash is emitted as a space and the escaped character as the quote
|
|
85
|
+
* sentinel, so neither slot can be read as a quote.
|
|
86
|
+
*
|
|
87
|
+
* A NEWLINE must survive here. `\` immediately followed by a newline is a legal
|
|
88
|
+
* line continuation inside a string literal, and emitting a space for it
|
|
89
|
+
* deleted a line from the masked source — every import reported after that
|
|
90
|
+
* point then carried a line number one too low. Measured: a two-line string
|
|
91
|
+
* followed by an import on line 3 reported `line: 2`. Line numbers are the one
|
|
92
|
+
* thing the masker promises to preserve, so this is a correctness bug, not a
|
|
93
|
+
* cosmetic one.
|
|
94
|
+
*
|
|
95
|
+
* Emitting the sentinel TWICE (one per character) is a provably equivalent
|
|
96
|
+
* mutation — a mutation run kept every test green. Either way neither slot
|
|
97
|
+
* equals a quote, so the state machine cannot be closed early, which is the
|
|
98
|
+
* only property that matters. Recorded so the next reader does not "fix" one
|
|
99
|
+
* form into the other and believe it changed something.
|
|
100
|
+
*/
|
|
101
|
+
function stepEscape(state: MaskState): void {
|
|
102
|
+
const escaped = state.content[state.i + 1];
|
|
103
|
+
state.out.push(' ');
|
|
104
|
+
// A trailing backslash at EOF (a truncated file, or one that simply ends
|
|
105
|
+
// mid-escape) used to push TWO characters while advancing past a ONE-char
|
|
106
|
+
// remainder, so the output came out one character LONGER than the input —
|
|
107
|
+
// breaking the length invariant every line number depends on. Measured on
|
|
108
|
+
// `const e = 'a<BS>` (13 chars) producing 14. Push only what exists.
|
|
109
|
+
if (escaped !== undefined) {
|
|
110
|
+
state.out.push(escaped === '\n' ? '\n' : QUOTE_SENTINEL);
|
|
111
|
+
}
|
|
112
|
+
state.i += 2;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Handle a character inside a literal or template. Returns false when not consumed. */
|
|
116
|
+
function stepLiteral(state: MaskState): boolean {
|
|
117
|
+
const { content, i, mode } = state;
|
|
118
|
+
const ch = content[i];
|
|
119
|
+
|
|
120
|
+
if (ch === '\\') {
|
|
121
|
+
stepEscape(state);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if (ch === literalCloser(mode)) {
|
|
125
|
+
// Closing delimiter of a real literal: keep it, back to code.
|
|
126
|
+
state.out.push(ch);
|
|
127
|
+
state.i += 1;
|
|
128
|
+
state.mode = 'code';
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (mode === 'template' && ch === '$' && content[i + 1] === '{') {
|
|
132
|
+
// Interpolation body is code again. Emit `$` and `{` as themselves and push
|
|
133
|
+
// a fresh brace depth for the matching `}`.
|
|
134
|
+
//
|
|
135
|
+
// A single integer counter CANNOT do this: an interpolation may itself open
|
|
136
|
+
// a nested template whose interpolation must return to the INNER template
|
|
137
|
+
// when it closes, not to code. Overwriting the counter on entry made the
|
|
138
|
+
// inner `}` look like the close of the outer one, so `` `${`${x}`}` `` left
|
|
139
|
+
// the masker in template mode and every real import after it was masked —
|
|
140
|
+
// measured before this was a stack: `extractImports` returned `[]` for a
|
|
141
|
+
// file whose only import was perfectly valid.
|
|
142
|
+
state.out.push('$', '{');
|
|
143
|
+
state.i += 2;
|
|
144
|
+
state.interpolationDepths.push(0);
|
|
145
|
+
state.mode = 'code';
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
// Text: a quote-like character here must not be usable by the regexes.
|
|
149
|
+
const isQuoteLike = ch === "'" || ch === '"' || ch === '`';
|
|
150
|
+
state.out.push(isQuoteLike ? QUOTE_SENTINEL : ch);
|
|
151
|
+
state.i += 1;
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Handle a `/` that may open a comment. Returns false when it does not. */
|
|
156
|
+
function stepCommentOpen(state: MaskState): boolean {
|
|
157
|
+
const { content, i } = state;
|
|
158
|
+
if (content[i] !== '/') return false;
|
|
159
|
+
const kind = content[i + 1];
|
|
160
|
+
if (kind === '/') {
|
|
161
|
+
state.out.push(' ');
|
|
162
|
+
state.i += 2;
|
|
163
|
+
state.mode = 'line-comment';
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
if (kind === '*') {
|
|
167
|
+
state.out.push(' ');
|
|
168
|
+
state.i += 2;
|
|
169
|
+
state.mode = 'block-comment';
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Handle a quote that opens a literal. Returns false when it does not. */
|
|
176
|
+
function stepQuoteOpen(state: MaskState): boolean {
|
|
177
|
+
const ch = state.content[state.i];
|
|
178
|
+
const opened: MaskMode | null =
|
|
179
|
+
ch === "'" ? 'single' : ch === '"' ? 'double' : ch === '`' ? 'template' : null;
|
|
180
|
+
if (opened === null) return false;
|
|
181
|
+
state.out.push(ch);
|
|
182
|
+
state.i += 1;
|
|
183
|
+
state.mode = opened;
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Track `{`/`}` while inside a `${ ... }` interpolation. Returns true when the
|
|
189
|
+
* interpolation closed and the masker went back to template text.
|
|
190
|
+
*/
|
|
191
|
+
function stepInterpolationBrace(state: MaskState): boolean {
|
|
192
|
+
const stack = state.interpolationDepths;
|
|
193
|
+
// Depth 0 means we are not inside any interpolation at all.
|
|
194
|
+
if (stack.length === 0) return false;
|
|
195
|
+
const ch = state.content[state.i];
|
|
196
|
+
if (ch === '{') {
|
|
197
|
+
stack[stack.length - 1] += 1;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
if (ch !== '}') return false;
|
|
201
|
+
if (stack[stack.length - 1] > 0) {
|
|
202
|
+
stack[stack.length - 1] -= 1;
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
// This `}` closes the innermost interpolation: resume the template that owns
|
|
206
|
+
// it. Popping (rather than zeroing a counter) is what makes nesting correct.
|
|
207
|
+
stack.pop();
|
|
208
|
+
state.out.push('}');
|
|
209
|
+
state.i += 1;
|
|
210
|
+
state.mode = 'template';
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Handle one character in code (depth 0). */
|
|
215
|
+
function stepCode(state: MaskState): void {
|
|
216
|
+
if (stepCommentOpen(state) || stepQuoteOpen(state)) return;
|
|
217
|
+
if (stepInterpolationBrace(state)) return;
|
|
218
|
+
state.out.push(state.content[state.i]);
|
|
219
|
+
state.i += 1;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Handlers by mode; `code` is the fallthrough. */
|
|
223
|
+
const MASK_STEPS: Record<MaskMode, (state: MaskState) => void> = {
|
|
224
|
+
code: stepCode,
|
|
225
|
+
single: (s) => void stepLiteral(s),
|
|
226
|
+
double: (s) => void stepLiteral(s),
|
|
227
|
+
template: (s) => void stepLiteral(s),
|
|
228
|
+
'line-comment': stepLineComment,
|
|
229
|
+
'block-comment': stepBlockComment,
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Blank out everything that is not code, keeping every character position in
|
|
234
|
+
* place: string/template bodies and comments become spaces (newlines survive),
|
|
235
|
+
* and every quote-like character inside them becomes `QUOTE_SENTINEL`. The
|
|
236
|
+
* import regexes then cannot match text that only looks like an import.
|
|
237
|
+
*/
|
|
238
|
+
export function maskTextQuotes(content: string): string {
|
|
239
|
+
const state: MaskState = {
|
|
240
|
+
content,
|
|
241
|
+
out: [],
|
|
242
|
+
i: 0,
|
|
243
|
+
mode: 'code',
|
|
244
|
+
interpolationDepths: [],
|
|
245
|
+
};
|
|
246
|
+
while (state.i < content.length) {
|
|
247
|
+
MASK_STEPS[state.mode](state);
|
|
248
|
+
}
|
|
249
|
+
return state.out.join('');
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Test-only view of the masker.
|
|
254
|
+
*
|
|
255
|
+
* `maskTextQuotes` is the only new algorithm in #759 and it makes three
|
|
256
|
+
* properties that `extractImports` can honour only by accident: output length
|
|
257
|
+
* equals input length, the newline count is unchanged (line numbers come from
|
|
258
|
+
* it), and no raw quote survives inside masked text in a way the import regexes
|
|
259
|
+
* could use. Asserting those directly is what turns the masker's contract into
|
|
260
|
+
* a fail-fast check instead of a behaviour inferred from a dozen indirect
|
|
261
|
+
* import assertions. Kept behind an explicit name so production callers do not
|
|
262
|
+
* reach for it.
|
|
263
|
+
*/
|
|
264
|
+
export function maskTextQuotesForTest(content: string): string {
|
|
265
|
+
return maskTextQuotes(content);
|
|
266
|
+
}
|
package/gate-10.sh
CHANGED
|
@@ -28,6 +28,72 @@ GATE_10_REASON=""
|
|
|
28
28
|
# shellcheck disable=SC2034
|
|
29
29
|
GATE_10_SCANNED_FILES=0
|
|
30
30
|
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
# Which path runs semgrep: the sastd daemon (fast) or a direct invocation.
|
|
33
|
+
#
|
|
34
|
+
# A direct `semgrep scan` costs ~9s on Windows, and the bill is almost entirely
|
|
35
|
+
# Python import tax: `--version` alone takes 4-5s because semgrep's CLI eagerly
|
|
36
|
+
# imports commands.ci -> app.auth -> telemetry -> opentelemetry -> requests ->
|
|
37
|
+
# urllib3. Paying that once per machine in a resident process is the point of
|
|
38
|
+
# sastd (measured: a second in-process import costs 0ms).
|
|
39
|
+
#
|
|
40
|
+
# GATE_10_SEMGREP_PATH records what actually happened, so a reader of the report
|
|
41
|
+
# can tell a fast run from a degraded one without timing it.
|
|
42
|
+
#
|
|
43
|
+
# The daemon does not exist yet (that is E2/E3). Until it does, EVERY value of
|
|
44
|
+
# XP_GATE_SASTD resolves to "direct", which is what makes shipping E1 a no-op:
|
|
45
|
+
# the switch, the degrade flag and the tests land first so the fast path is added
|
|
46
|
+
# onto a base that is already proven to behave exactly as today.
|
|
47
|
+
# ---------------------------------------------------------------------------
|
|
48
|
+
# Consumed by the sourcing parent (pre-commit report JSON), not here.
|
|
49
|
+
# shellcheck disable=SC2034
|
|
50
|
+
GATE_10_SEMGREP_PATH="direct"
|
|
51
|
+
# Set to 1 when sastd was requested but unusable, so "we fell back" is a fact in
|
|
52
|
+
# the report rather than an inference from a missing log line. Never set when the
|
|
53
|
+
# daemon was not requested at all -- a plain direct run is not a degraded run.
|
|
54
|
+
# Consumed by the sourcing parent (pre-commit report JSON), not here.
|
|
55
|
+
# shellcheck disable=SC2034
|
|
56
|
+
GATE_10_SASTD_DEGRADED=0
|
|
57
|
+
|
|
58
|
+
# shellcheck disable=SC2034
|
|
59
|
+
case "${XP_GATE_SASTD:-direct}" in
|
|
60
|
+
off|direct|0|false|"")
|
|
61
|
+
# Explicitly or implicitly off: the direct path. Not a degradation.
|
|
62
|
+
GATE_10_SEMGREP_PATH="direct"
|
|
63
|
+
;;
|
|
64
|
+
auto)
|
|
65
|
+
# "Use the daemon if one is available, otherwise just scan." Absence of a
|
|
66
|
+
# daemon is the normal state for most users, not a fault, so `auto` does NOT
|
|
67
|
+
# set the degraded flag -- marking it would make every ordinary run look
|
|
68
|
+
# degraded the moment E2 lands and train readers to ignore the flag.
|
|
69
|
+
# E2 MUST add a probe INSIDE this branch rather than flipping the value:
|
|
70
|
+
# a daemon that is ABSENT keeps degraded=0 (normal), but a daemon that is
|
|
71
|
+
# PRESENT BUT UNUSABLE must set degraded=1 -- otherwise `auto` silently
|
|
72
|
+
# swallows the same failure `on` reports. Get that distinction right here;
|
|
73
|
+
# it is the whole reason the two branches are separate.
|
|
74
|
+
GATE_10_SEMGREP_PATH="direct"
|
|
75
|
+
;;
|
|
76
|
+
on|1|true)
|
|
77
|
+
# The user asserted a daemon SHOULD be here. If it is not, that is a
|
|
78
|
+
# degradation worth reporting: their configuration is not being honoured.
|
|
79
|
+
# This is the branch that must never become "skip the scan and call it a pass".
|
|
80
|
+
GATE_10_SEMGREP_PATH="direct"
|
|
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
|
|
87
|
+
;;
|
|
88
|
+
*)
|
|
89
|
+
# An unrecognised value is a configuration mistake, not a reason to scan
|
|
90
|
+
# less. Use the direct path and name the value so it can be fixed.
|
|
91
|
+
GATE_10_SEMGREP_PATH="direct"
|
|
92
|
+
GATE_10_SASTD_DEGRADED=1
|
|
93
|
+
echo " ⚠️ XP_GATE_SASTD='${XP_GATE_SASTD}' is not recognised (expected off|auto|on) — using direct semgrep" >&2
|
|
94
|
+
;;
|
|
95
|
+
esac
|
|
96
|
+
|
|
31
97
|
# Semgrep availability check
|
|
32
98
|
SEMGREP_CMD=""
|
|
33
99
|
if command -v semgrep >/dev/null 2>&1; then
|
package/gate-12-file-hygiene.sh
CHANGED
|
@@ -86,6 +86,19 @@ if [ -n "$TRAILING_WS_FILES" ]; then
|
|
|
86
86
|
fi
|
|
87
87
|
|
|
88
88
|
# --- Check 2: Missing EOF newline ---
|
|
89
|
+
# Reads the LAST BYTE from the raw blob. The previous form captured the content
|
|
90
|
+
# with $(...) and then asked for its final character: command substitution
|
|
91
|
+
# strips every trailing newline, so a file that ends correctly produced its last
|
|
92
|
+
# visible character — never empty — and was reported as missing its newline.
|
|
93
|
+
# Every staged text file was a false positive, which is how a check that always
|
|
94
|
+
# fires looks exactly like a strict check. `git show | tail -c 1` keeps the byte.
|
|
95
|
+
file_missing_eof_newline() {
|
|
96
|
+
local last_byte
|
|
97
|
+
last_byte=$(git show ":$1" 2>/dev/null | tail -c 1)
|
|
98
|
+
# Empty output means the blob is empty: there is no line to terminate.
|
|
99
|
+
[ -n "$last_byte" ]
|
|
100
|
+
}
|
|
101
|
+
|
|
89
102
|
NO_EOF_NEWLINE_FILES=""
|
|
90
103
|
if [ "${GATE_12_DOCS_ONLY:-false}" != true ]; then
|
|
91
104
|
while IFS= read -r file; do
|
|
@@ -94,13 +107,8 @@ while IFS= read -r file; do
|
|
|
94
107
|
if is_binary_staged_file "$file"; then
|
|
95
108
|
continue
|
|
96
109
|
fi
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if [ -n "$FILE_CONTENT" ]; then
|
|
100
|
-
LAST_CHAR=$(printf '%s' "$FILE_CONTENT" | tail -c 1)
|
|
101
|
-
if [ "$LAST_CHAR" != "" ]; then
|
|
102
|
-
NO_EOF_NEWLINE_FILES="$NO_EOF_NEWLINE_FILES $file"
|
|
103
|
-
fi
|
|
110
|
+
if file_missing_eof_newline "$file"; then
|
|
111
|
+
NO_EOF_NEWLINE_FILES="$NO_EOF_NEWLINE_FILES $file"
|
|
104
112
|
fi
|
|
105
113
|
done <<EOF
|
|
106
114
|
$STAGED_FILES
|
|
@@ -1201,6 +1201,79 @@ EOF
|
|
|
1201
1201
|
# detection and gates drift apart.
|
|
1202
1202
|
# ============================================================================
|
|
1203
1203
|
|
|
1204
|
+
# The strictness flag set for C#, decided by tier.
|
|
1205
|
+
#
|
|
1206
|
+
# Why this exists: unlike the C/C++/Java paths, the C# path used to run a bare
|
|
1207
|
+
# `dotnet build`, which inherits whatever the project happens to declare. A
|
|
1208
|
+
# project with `<TreatWarningsAsErrors>false</TreatWarningsAsErrors>` -- or one
|
|
1209
|
+
# that simply never set it, which is the common case -- sailed through with real
|
|
1210
|
+
# warnings. Measured on a fixture holding an unused field and an instance method
|
|
1211
|
+
# that could be static: "1 warning, 0 errors, build succeeded". The gate saw a
|
|
1212
|
+
# warning it could not act on, because it decides BLOCK from the build's exit
|
|
1213
|
+
# code. A strictness gate that depends on the audited project having declared
|
|
1214
|
+
# strictness is not a gate; it is a mirror.
|
|
1215
|
+
#
|
|
1216
|
+
# Passing these on the command line overrides the project-level properties --
|
|
1217
|
+
# measured: a project declaring TreatWarningsAsErrors=false still failed the
|
|
1218
|
+
# build once -warnaserror was passed. So this does not force downstream projects
|
|
1219
|
+
# to edit their own files.
|
|
1220
|
+
#
|
|
1221
|
+
# DELIBERATELY NOT INCLUDED -- these change compilation semantics rather than
|
|
1222
|
+
# raising the bar on existing code, and the C/C++/Java paths have no equivalent:
|
|
1223
|
+
#
|
|
1224
|
+
# -p:Nullable=enable
|
|
1225
|
+
# Turns on nullable *reference type* analysis, i.e. it opts the project
|
|
1226
|
+
# into a language feature it never asked for. Measured: a project without
|
|
1227
|
+
# it reports CS8632 ("nullable reference types only inside #nullable
|
|
1228
|
+
# context"); with it, the same line becomes CS8603 (possible null return).
|
|
1229
|
+
# Gating a legacy codebase on warnings it cannot even parse today is
|
|
1230
|
+
# exactly the false-BLOCK this gate must not produce.
|
|
1231
|
+
#
|
|
1232
|
+
# -p:EnforceCodeStyleInBuild=true
|
|
1233
|
+
# Measured to emit ZERO IDE diagnostics on a project with no .editorconfig
|
|
1234
|
+
# and no explicit analyzer reference -- it only amplifies configuration the
|
|
1235
|
+
# project already has, so it contributes nothing for the projects that most
|
|
1236
|
+
# need the gate and is a no-op for the rest.
|
|
1237
|
+
#
|
|
1238
|
+
# Tiers mirror the C++/Java paths:
|
|
1239
|
+
# balanced (default) -- warnings are errors at the highest meaningful warning
|
|
1240
|
+
# level, with the recommended analyzer set.
|
|
1241
|
+
# strict -- balanced plus every rule that is only suggestion/hidden
|
|
1242
|
+
# by default promoted via AnalysisMode. Measured to add
|
|
1243
|
+
# CA1707 (identifier contains underscore), which balanced
|
|
1244
|
+
# does not report at all.
|
|
1245
|
+
# warn-only -- no promotion (the caller downgrades the verdict to WARN
|
|
1246
|
+
# on its own, so an empty flag set is correct here).
|
|
1247
|
+
#
|
|
1248
|
+
# ANALYSISLEVEL IS NOT REDUNDANT with -warnaserror: the latter only promotes
|
|
1249
|
+
# compiler diagnostics (CS*), while analyzer rules (CA*) take their severity from
|
|
1250
|
+
# AnalysisLevel. Measured on the fixture above: -warnaserror alone caught CS0414
|
|
1251
|
+
# only; adding AnalysisLevel also caught CA1822. Passing one without the other
|
|
1252
|
+
# blocks half of what this gate is for.
|
|
1253
|
+
#
|
|
1254
|
+
# WARNINGLEVEL=9999 is intentional and safe: csc accepts /warn:N for N > 4 --
|
|
1255
|
+
# measured /warn:4, /warn:9, /warn:100, /warn:9999 and /warn:999999 all compile
|
|
1256
|
+
# identically with no CS1900. Only /warn:0 suppresses; there is no upper bound.
|
|
1257
|
+
# 9999 is used instead of 4 so that any warning level a future SDK introduces is
|
|
1258
|
+
# covered without this file needing a change.
|
|
1259
|
+
gate13_csharp_flags() {
|
|
1260
|
+
local tier="${1:-balanced}"
|
|
1261
|
+
|
|
1262
|
+
if [ "$tier" = "warn-only" ]; then
|
|
1263
|
+
printf '%s\n' ""
|
|
1264
|
+
return 0
|
|
1265
|
+
fi
|
|
1266
|
+
|
|
1267
|
+
local base="-warnaserror -p:WarningLevel=9999 -p:AnalysisLevel=latest-recommended"
|
|
1268
|
+
|
|
1269
|
+
if [ "$tier" = "strict" ]; then
|
|
1270
|
+
printf '%s %s\n' "$base" "-p:AnalysisMode=AllEnabledByDefault"
|
|
1271
|
+
return 0
|
|
1272
|
+
fi
|
|
1273
|
+
|
|
1274
|
+
printf '%s\n' "$base"
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1204
1277
|
# Locate the .NET SDK exactly as adapters/csharp.sh does.
|
|
1205
1278
|
gate13_csharp_dotnet() {
|
|
1206
1279
|
local d
|
|
@@ -1280,7 +1353,14 @@ gate13_csharp_changed_warning_count() {
|
|
|
1280
1353
|
# dies with MSB1003 whenever the project sits in a subdirectory, emitting no
|
|
1281
1354
|
# diagnostics at all.
|
|
1282
1355
|
entry=$(gate13_csharp_entry_point) || return 1
|
|
1283
|
-
|
|
1356
|
+
|
|
1357
|
+
# Strictness flags come from OUTSIDE the project, so the gate does not depend
|
|
1358
|
+
# on the audited repository having declared them. Empty in the warn-only tier.
|
|
1359
|
+
local flags
|
|
1360
|
+
flags=$(gate13_csharp_flags "$(gate13_resolve_tier)")
|
|
1361
|
+
|
|
1362
|
+
# shellcheck disable=SC2086 # $flags is a deliberately word-split flag list
|
|
1363
|
+
out=$("$dotnet" build "$entry" --nologo --no-incremental -clp:NoSummary $flags 2>&1)
|
|
1284
1364
|
|
|
1285
1365
|
# Report distinct CHANGED FILES, not diagnostic instances: the caller speaks in
|
|
1286
1366
|
# files ("N changed C# file(s) carry compiler warnings"), and one file with two
|
package/gate-3.sh
CHANGED
|
@@ -350,7 +350,7 @@ else
|
|
|
350
350
|
}
|
|
351
351
|
|
|
352
352
|
CCN_THRESHOLD=$(resolve_ccn_threshold)
|
|
353
|
-
|
|
353
|
+
|
|
354
354
|
# Check lizard availability
|
|
355
355
|
LIZARD_CMD=""
|
|
356
356
|
if command -v lizard > /dev/null 2>&1; then
|
|
@@ -358,10 +358,10 @@ else
|
|
|
358
358
|
elif [ -f ~/.local/bin/lizard ]; then
|
|
359
359
|
LIZARD_CMD=~/.local/bin/lizard
|
|
360
360
|
fi
|
|
361
|
-
|
|
361
|
+
|
|
362
362
|
if [ -n "$LIZARD_CMD" ]; then
|
|
363
363
|
LIZARD_PATH=$(eval echo "$LIZARD_CMD")
|
|
364
|
-
|
|
364
|
+
|
|
365
365
|
# Get changed source files for complexity check (includes test files)
|
|
366
366
|
CC_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs)$' || true)
|
|
367
367
|
|
|
@@ -398,7 +398,7 @@ else
|
|
|
398
398
|
|
|
399
399
|
if [ -n "$CC_FILES" ]; then
|
|
400
400
|
echo "Checking complexity for source files..."
|
|
401
|
-
|
|
401
|
+
|
|
402
402
|
# Run lizard in chunks. Two reasons, both load-bearing:
|
|
403
403
|
# - One path per line, into an array. Unquoted $CC_FILES relied on word
|
|
404
404
|
# splitting, which also splits any path containing a space -- handing
|
|
@@ -595,7 +595,17 @@ CC_POP_EOF
|
|
|
595
595
|
# contain a function. If it produces rows, lizard works and the input
|
|
596
596
|
# simply had no functions (SKIP, `no_functions_in_input`); if it does not,
|
|
597
597
|
# the tool really is broken (WARN, `lizard_output_unparsable`).
|
|
598
|
-
|
|
598
|
+
#
|
|
599
|
+
# #774: the probe must read the WHOLE stream. It used to `exit` on the
|
|
600
|
+
# first matching row, which left `printf` writing into a closed pipe; under
|
|
601
|
+
# the hook's `set -o pipefail` the pipeline then reported SIGPIPE (141)
|
|
602
|
+
# instead of awk's 0, and a run with 26 above-threshold functions announced
|
|
603
|
+
# itself as "no functions (pure data module)". Measured: the flip happens
|
|
604
|
+
# once the CSV exceeds the 64 KB pipe buffer -- 24 changed source files were
|
|
605
|
+
# enough -- and it is timing-dependent, so the same commit could pass or
|
|
606
|
+
# skip. Counting through to END also drops the dependency on how much stdin
|
|
607
|
+
# happened to be buffered.
|
|
608
|
+
if ! printf '%s\n' "$CC_CSV_FLAT" | awk -F, 'NF > 1 && $2 ~ /^[0-9]+$/ { found = 1 }
|
|
599
609
|
END { exit(found ? 0 : 1) }'; then
|
|
600
610
|
_lizard_probe_dir=$(mktemp -d 2>/dev/null || echo "${TMPDIR:-/tmp}")
|
|
601
611
|
_lizard_probe_file="$_lizard_probe_dir/xp-gate-lizard-probe.py"
|