@boyingliu01/xp-gate 0.38.10 → 0.38.11

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.
@@ -0,0 +1,264 @@
1
+ /**
2
+ * @test REQ-152 Baseline CLI handler
3
+ * @intent `xp-gate baseline create` silently recorded NOTHING for TypeScript.
4
+ * It built one command line from every source file and passed it as argv:
5
+ * measured in this repo, 652 files and 31,917 characters, against a
6
+ * Windows command-line limit around 8,191. The call therefore always
7
+ * failed, and the failure was swallowed by a bare `catch {}` whose comment
8
+ * said "ESLint unavailable — skip". The resulting baseline contained zero
9
+ * eslint entries and 70 shellcheck ones, so Gate 1 compared every TS/JS
10
+ * file against a baseline of nothing.
11
+ *
12
+ * That is the worst possible shape for a baseline: it looks authoritative,
13
+ * it is committed and regenerated, and it silently waves through exactly
14
+ * the language this package is written in.
15
+ *
16
+ * Three separate defects, each sufficient to produce the empty result:
17
+ * 1. one argv for all files (fails over the platform limit);
18
+ * 2. a thrown error treated as "tool unavailable" — the two states
19
+ * ("found nothing" and "could not evaluate") were indistinguishable;
20
+ * 3. a `"undefined"` key written when a result could not be matched to a
21
+ * file, inflating the entry count by one and making the file count
22
+ * disagree with the number of real files.
23
+ * @covers AC-BASELINE-01 AC-BASELINE-02 AC-BASELINE-03
24
+ */
25
+ const path = require('path');
26
+ const fs = require('fs');
27
+ const os = require('os');
28
+
29
+ const { execFileSync } = require('child_process');
30
+
31
+ const { createBaseline } = require('../baseline.js');
32
+
33
+ describe('baseline completeness — a language must not vanish silently', () => {
34
+ let tmpDir;
35
+ const originalCwd = process.cwd;
36
+
37
+ /**
38
+ * Create a fake linter in node_modules/.bin, in the shape the PLATFORM actually
39
+ * uses.
40
+ *
41
+ * On Windows cmd.exe cannot execute an extensionless POSIX sh wrapper at all --
42
+ * not even by absolute path -- so npm installs a `.cmd` launcher next to it and
43
+ * that is what a shell command resolves. A stub written only as `eslint` would
44
+ * therefore test a layout that never exists on this platform, and the test would
45
+ * fail for a reason unrelated to the defect under examination.
46
+ *
47
+ * @param {string} binDir node_modules/.bin
48
+ * @param {string} name tool name
49
+ * @param {string} jsBody statements to run, as JS
50
+ */
51
+ function writeLintStub(binDir, name, jsBody) {
52
+ const js = `#!/usr/bin/env node\n${jsBody}\n`;
53
+ if (process.platform === 'win32') {
54
+ const cmdPath = path.join(binDir, `${name}.cmd`);
55
+ // A .cmd shim that hands the script to node, mirroring npm's own launcher.
56
+ const jsPath = path.join(binDir, `${name}-stub.js`);
57
+ fs.writeFileSync(jsPath, js);
58
+ fs.writeFileSync(cmdPath, `@node "%~dp0${name}-stub.js" %*\r\n`);
59
+ return;
60
+ }
61
+ const stub = path.join(binDir, name);
62
+ fs.writeFileSync(stub, js);
63
+ fs.chmodSync(stub, 0o755);
64
+ }
65
+
66
+ beforeEach(() => {
67
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'baseline-completeness-'));
68
+ process.cwd = () => tmpDir;
69
+ // `findFilesByExt` enumerates with `git ls-files`, so a fixture that is not a
70
+ // git work tree yields NO files and the linter is never invoked. Without this
71
+ // the tests would pass vacuously: the very code path under test would never
72
+ // run, and silence would look like success -- the same defect one level up.
73
+ execFileSync('git', ['init', '-q'], { cwd: tmpDir });
74
+ });
75
+
76
+ /**
77
+ * Stage the fixture so `git ls-files` reports it. Files are only visible to the
78
+ * baseline once tracked, which is also true of the real project.
79
+ */
80
+ function trackAll() {
81
+ execFileSync('git', ['add', '-A', '-f'], { cwd: tmpDir });
82
+ }
83
+
84
+ afterEach(() => {
85
+ process.cwd = originalCwd;
86
+ fs.rmSync(tmpDir, { recursive: true, force: true });
87
+ });
88
+
89
+ it('AC-BASELINE-01: many files do not become one over-long argv', async () => {
90
+ // Enough files that a single concatenated command line would exceed the
91
+ // platform limit. If the implementation still builds one argv, this is
92
+ // exactly the case that failed in the real repo.
93
+ const srcDir = path.join(tmpDir, 'src');
94
+ fs.mkdirSync(srcDir, { recursive: true });
95
+ const names = [];
96
+ for (let i = 0; i < 400; i++) {
97
+ const name = `src/file-with-a-long-descriptive-name-${String(i).padStart(4, '0')}.ts`;
98
+ fs.writeFileSync(path.join(tmpDir, name), 'export const x = 1;\n');
99
+ names.push(name);
100
+ }
101
+ fs.writeFileSync(path.join(tmpDir, 'eslint.config.js'), 'module.exports = [];\n');
102
+ fs.writeFileSync(
103
+ path.join(tmpDir, 'package.json'),
104
+ JSON.stringify({ name: 'x', version: '1.0.0' })
105
+ );
106
+ // A stand-in linter: it records the argv it received, then answers with a
107
+ // JSON array. The real one is not needed to test how the command is built.
108
+ const binDir = path.join(tmpDir, 'node_modules', '.bin');
109
+ fs.mkdirSync(binDir, { recursive: true });
110
+ writeLintStub(
111
+ binDir,
112
+ 'eslint',
113
+ "const fs=require('fs');\n" +
114
+ 'fs.appendFileSync(process.env.ARGV_LOG, process.argv.length + "\\n");\n' +
115
+ 'process.stdout.write("[]");'
116
+ );
117
+
118
+ const logPath = path.join(tmpDir, 'argv.log');
119
+ const prev = process.env.ARGV_LOG;
120
+ process.env.ARGV_LOG = logPath;
121
+ try {
122
+ trackAll();
123
+ await createBaseline();
124
+ } finally {
125
+ if (prev === undefined) delete process.env.ARGV_LOG;
126
+ else process.env.ARGV_LOG = prev;
127
+ }
128
+
129
+ const invocations = fs.existsSync(logPath)
130
+ ? fs.readFileSync(logPath, 'utf8').trim().split('\n').filter(Boolean).map(Number)
131
+ : [];
132
+ // The stub MUST have run. A test that only checks "no invocation was too
133
+ // large" passes vacuously when nothing ran at all -- and nothing running is
134
+ // precisely the old defect (the linter was found, the call failed, the
135
+ // failure was swallowed). Verified: against the pre-fix code this assertion
136
+ // is what goes red; the size bound alone stayed green.
137
+ expect(invocations.length).toBeGreaterThan(0);
138
+ // 400 files at 100 per batch -> 4 calls (the observed count, not a guess).
139
+ expect(invocations.length).toBeGreaterThanOrEqual(2);
140
+ for (const argc of invocations) {
141
+ expect(argc).toBeLessThanOrEqual(200);
142
+ }
143
+ });
144
+
145
+ it('AC-BASELINE-02: an evaluation failure is not recorded as an empty result', async () => {
146
+ // The linter exists but errors out. The baseline must not quietly claim the
147
+ // language is clean — that is "did not evaluate" written as "found nothing".
148
+ fs.mkdirSync(path.join(tmpDir, 'src'), { recursive: true });
149
+ fs.writeFileSync(path.join(tmpDir, 'src', 'a.ts'), 'export const x = 1;\n');
150
+ fs.writeFileSync(path.join(tmpDir, 'eslint.config.js'), 'module.exports = [];\n');
151
+ fs.writeFileSync(
152
+ path.join(tmpDir, 'package.json'),
153
+ JSON.stringify({ name: 'x', version: '1.0.0' })
154
+ );
155
+ const binDir = path.join(tmpDir, 'node_modules', '.bin');
156
+ fs.mkdirSync(binDir, { recursive: true });
157
+ writeLintStub(binDir, 'eslint', 'process.stderr.write("boom");process.exit(2);');
158
+
159
+ const warnings = [];
160
+ const origWarn = console.warn;
161
+ const origError = console.error;
162
+ console.warn = (...a) => warnings.push(a.join(' '));
163
+ console.error = (...a) => warnings.push(a.join(' '));
164
+ let result;
165
+ try {
166
+ trackAll();
167
+ result = await createBaseline();
168
+ } finally {
169
+ console.warn = origWarn;
170
+ console.error = origError;
171
+ }
172
+
173
+ const keys = Object.keys(result).filter(k => k !== 'undefined');
174
+ expect(keys.length).toBe(0);
175
+ // The failure has to be visible: silence is what made this defect survive.
176
+ expect(warnings.join('\n')).toMatch(/eslint/i);
177
+ });
178
+
179
+ it('AC-BASELINE-03: no "undefined" key is ever written', async () => {
180
+ // Written when a tool's result could not be matched back to a file. It made
181
+ // `Object.keys(baseline).length` disagree with the number of real files, so
182
+ // "71 files tracked" was reported for 70.
183
+ fs.mkdirSync(path.join(tmpDir, 'src'), { recursive: true });
184
+ fs.writeFileSync(path.join(tmpDir, 'src', 'a.ts'), 'export const x = 1;\n');
185
+ fs.writeFileSync(path.join(tmpDir, 'eslint.config.js'), 'module.exports = [];\n');
186
+ fs.writeFileSync(
187
+ path.join(tmpDir, 'package.json'),
188
+ JSON.stringify({ name: 'x', version: '1.0.0' })
189
+ );
190
+ const binDir = path.join(tmpDir, 'node_modules', '.bin');
191
+ fs.mkdirSync(binDir, { recursive: true });
192
+ // A result whose path matches NO discovered file -- the exact input that
193
+ // produced the bogus key.
194
+ const ranMarker = path.join(tmpDir, 'ran.marker');
195
+ writeLintStub(
196
+ binDir,
197
+ 'eslint',
198
+ `require('fs').writeFileSync(${JSON.stringify(ranMarker)}, 'ran');` +
199
+ 'process.stdout.write(JSON.stringify([{filePath:"/nowhere/ghost.ts",warningCount:3,errorCount:0}]));'
200
+ );
201
+
202
+ trackAll();
203
+ const result = await createBaseline();
204
+ // The stub must actually have been invoked. Otherwise the linter never ran,
205
+ // no unmatched result was ever produced, and "no undefined key" would hold
206
+ // for a reason that has nothing to do with the defect -- verified against the
207
+ // pre-fix code, where this assertion is required for the test to go red.
208
+ expect(fs.existsSync(ranMarker)).toBe(true);
209
+ expect(Object.keys(result)).not.toContain('undefined');
210
+ });
211
+ });
212
+
213
+ describe('local binary resolution — the launcher must be executable', () => {
214
+ // Measured on Windows, all four forms against the same installed tool:
215
+ // 'node_modules/.bin/eslint' -> "'node_modules' is not recognized"
216
+ // 'node node_modules/.bin/eslint' -> SyntaxError (POSIX sh wrapper)
217
+ // 'node_modules/.bin/eslint.cmd' -> "'node_modules' is not recognized"
218
+ // absolute path to eslint.cmd -> works
219
+ // So resolution has to yield an ABSOLUTE path and the platform's launcher.
220
+ let tmpDir;
221
+ const originalCwd = process.cwd;
222
+
223
+ beforeEach(() => {
224
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'baseline-bin-'));
225
+ process.cwd = () => tmpDir;
226
+ fs.mkdirSync(path.join(tmpDir, 'node_modules', '.bin'), { recursive: true });
227
+ });
228
+
229
+ afterEach(() => {
230
+ process.cwd = originalCwd;
231
+ fs.rmSync(tmpDir, { recursive: true, force: true });
232
+ });
233
+
234
+ it('AC-BASELINE-04: returns an absolute path to the platform launcher', async () => {
235
+ const { resolveLocalBin } = require('../baseline.js');
236
+ const binDir = path.join(tmpDir, 'node_modules', '.bin');
237
+ const expected = process.platform === 'win32'
238
+ ? path.join(binDir, 'eslint.cmd')
239
+ : path.join(binDir, 'eslint');
240
+ fs.writeFileSync(expected, process.platform === 'win32' ? '@echo off\r\n' : '#!/bin/sh\n');
241
+
242
+ const resolved = resolveLocalBin('eslint');
243
+ expect(resolved).toBe(expected);
244
+ expect(path.isAbsolute(resolved)).toBe(true);
245
+ });
246
+
247
+ it('AC-BASELINE-04: a relative path is never returned', async () => {
248
+ const { resolveLocalBin } = require('../baseline.js');
249
+ const binDir = path.join(tmpDir, 'node_modules', '.bin');
250
+ const name = process.platform === 'win32' ? 'eslint.cmd' : 'eslint';
251
+ fs.writeFileSync(path.join(binDir, name), 'x');
252
+
253
+ const resolved = resolveLocalBin('eslint');
254
+ // The old code returned the literal relative string "node_modules/.bin/eslint",
255
+ // which cmd.exe rejects even when the file exists.
256
+ expect(resolved).not.toBe('node_modules/.bin/eslint');
257
+ expect(path.isAbsolute(resolved)).toBe(true);
258
+ });
259
+
260
+ it('AC-BASELINE-04: an absent tool resolves to null, not a broken path', async () => {
261
+ const { resolveLocalBin } = require('../baseline.js');
262
+ expect(resolveLocalBin('definitely-not-installed')).toBeNull();
263
+ });
264
+ });
package/lib/baseline.js CHANGED
@@ -38,15 +38,164 @@ function parseArgs(subargs) {
38
38
  /**
39
39
  * Run a lint tool and return its JSON output.
40
40
  */
41
- function runToolJson(toolCmd, pipeToJsonFlag) {
42
- try {
43
- const cmd = `${toolCmd} ${pipeToJsonFlag}`;
44
- return execSync(cmd, { encoding: 'utf8', maxBuffer: 10 * 1024 * 1024 }).trim();
45
- } catch (e) {
46
- // Lint tools exit non-zero when they find issues - that's expected
47
- if (e.stdout) return e.stdout.trim();
48
- return '';
41
+ // How many paths to pass to a linter in one call.
42
+ //
43
+ // A single argv built from every source file is not a style problem, it is a
44
+ // correctness one: this repo has 652 TS/JS files and the joined list measured
45
+ // 31,917 characters against a Windows limit around 8,191. The call always failed,
46
+ // the failure was swallowed, and the baseline recorded zero eslint entries -- so
47
+ // Gate 1 compared every TS/JS file against a baseline of nothing.
48
+ //
49
+ // 100 paths keeps the argv in the low thousands of characters even for deep
50
+ // paths, well clear of the limit on every platform.
51
+ const LINT_BATCH_SIZE = 100;
52
+
53
+ /**
54
+ * Run a lint tool over a list of paths, in batches, and return its findings.
55
+ *
56
+ * Returns an object rather than a bare string so the caller can tell apart the
57
+ * two states that used to be identical: "the tool ran and found nothing" versus
58
+ * "the tool could not be evaluated". Collapsing them is how a baselining command
59
+ * reports success while having measured nothing.
60
+ *
61
+ * @param {string[]} files project-relative paths
62
+ * @param {(batch: string[]) => string} buildCmd builds the command line for a batch
63
+ * @param {string} jsonFlag flag that makes the tool emit JSON on stdout
64
+ * @returns {{results: any[], errors: string[]}} parsed per-batch results, or a
65
+ * list of failure messages. An empty `results` with a non-empty `errors` means
66
+ * "not evaluated", never "clean".
67
+ */
68
+ function runLintInBatches(files, buildCmd, jsonFlag) {
69
+ const results = [];
70
+ const errors = [];
71
+
72
+ for (let i = 0; i < files.length; i += LINT_BATCH_SIZE) {
73
+ const batch = files.slice(i, i + LINT_BATCH_SIZE);
74
+ let stdout;
75
+ try {
76
+ stdout = execSync(`${buildCmd(batch)} ${jsonFlag}`, {
77
+ encoding: 'utf8',
78
+ maxBuffer: 10 * 1024 * 1024,
79
+ });
80
+ } catch (e) {
81
+ // Non-zero exit is the tool's normal answer when it FOUND something, and
82
+ // its stdout still carries the JSON. Only an empty stdout is a failure.
83
+ stdout = e.stdout;
84
+ if (!stdout || !String(stdout).trim()) {
85
+ errors.push(formatToolFailure(e));
86
+ continue;
87
+ }
88
+ }
89
+ const trimmed = String(stdout).trim();
90
+ if (!trimmed) continue;
91
+ try {
92
+ const parsed = JSON.parse(trimmed);
93
+ if (Array.isArray(parsed)) results.push(...parsed);
94
+ } catch {
95
+ errors.push(`linter returned unparseable output for ${batch.length} file(s)`);
96
+ }
97
+ }
98
+
99
+ return { results, errors };
100
+ }
101
+
102
+ /**
103
+ * Resolve a tool installed in `node_modules/.bin` to something execSync can run.
104
+ *
105
+ * `fs.existsSync('node_modules/.bin/eslint')` is not enough on Windows, and the
106
+ * path it returns cannot be executed there at all. Measured on this machine:
107
+ *
108
+ * node_modules/.bin/eslint -> cmd.exe reports "'node_modules' is not
109
+ * recognized" (a relative path is not an
110
+ * executable name to cmd)
111
+ * node node_modules/.bin/eslint -> SyntaxError, because the extensionless
112
+ * entry is a POSIX sh wrapper
113
+ * node_modules/.bin/eslint.cmd -> same "not recognized" failure
114
+ * absolute path to eslint.cmd -> works (v10.3.0)
115
+ *
116
+ * So the resolution has to produce an ABSOLUTE path and pick the platform's
117
+ * launcher: `.cmd` on Windows, the bare script elsewhere.
118
+ *
119
+ * @param {string} name tool name, e.g. 'eslint'
120
+ * @param {string} [cwd] directory to resolve against
121
+ * @returns {string|null} absolute path to an executable, or null
122
+ */
123
+ function resolveLocalBin(name, cwd = process.cwd()) {
124
+ const binDir = path.join(cwd, 'node_modules', '.bin');
125
+ const candidates = process.platform === 'win32'
126
+ ? [`${name}.cmd`, name]
127
+ : [name];
128
+
129
+ for (const candidate of candidates) {
130
+ const full = path.join(binDir, candidate);
131
+ try {
132
+ if (fs.existsSync(full)) return full;
133
+ } catch {
134
+ // Unreadable candidate -- try the next one.
135
+ }
136
+ }
137
+ return null;
138
+ }
139
+
140
+ /**
141
+ * Format a resolved binary for use inside a shell command line.
142
+ *
143
+ * The path is quoted because node_modules can live under a directory with spaces
144
+ * ("C:\Program Files\..."), which would otherwise split into several args.
145
+ */
146
+ function quoteBin(bin) {
147
+ return `"${bin}"`;
148
+ }
149
+
150
+ /** One-line reason a tool run failed, from the error object execSync threw. */
151
+ function formatToolFailure(err) {
152
+ const stderr = err && err.stderr ? String(err.stderr).trim() : '';
153
+ if (stderr) {
154
+ // The Windows "command line is too long" case prints exactly this; naming it
155
+ // is what turns an invisible defect into a one-line diagnosis.
156
+ return stderr.split('\n')[0].trim();
49
157
  }
158
+ const msg = err && err.message ? String(err.message) : 'unknown error';
159
+ const status = err && typeof err.status === 'number' ? ` (exit ${err.status})` : '';
160
+ return `${msg.split('\n')[0].trim()}${status}`;
161
+ }
162
+
163
+ /**
164
+ * Report a linter that could not be evaluated.
165
+ *
166
+ * Silence is what let "TypeScript was never baselined" survive in this repo: the
167
+ * command printed a cheerful "✅ Baseline created" while 652 files had contributed
168
+ * nothing. A warning is the minimum contract -- the caller can still finish, but
169
+ * the user is told which language went unmeasured and why.
170
+ *
171
+ * @param {string} tool
172
+ * @param {string[]} errors
173
+ */
174
+ function recordFailures(tool, errors) {
175
+ if (!errors || errors.length === 0) return;
176
+ const unique = [...new Set(errors)];
177
+ const shown = unique.slice(0, 3).join('; ');
178
+ const more = unique.length > 3 ? ` (+${unique.length - 3} more)` : '';
179
+ console.warn(`⚠️ ${tool}: could not evaluate ${errors.length} batch(es) — ${shown}${more}`);
180
+ console.warn(` Files covered by a failed batch are absent from the baseline, not clean.`);
181
+ }
182
+
183
+ /**
184
+ * Match a linter's reported path back to one of the files we asked about.
185
+ *
186
+ * Returns null rather than undefined when nothing matches. The previous version
187
+ * used the result of `Array.prototype.find` as an object key, which stringifies
188
+ * an unmatched lookup to the literal key "undefined" -- one bogus baseline entry
189
+ * that made "71 files tracked" print for 70 real files.
190
+ *
191
+ * @param {string} reportedPath absolute or relative path from the tool
192
+ * @param {string[]} candidates the files handed to the tool
193
+ * @returns {string|null}
194
+ */
195
+ function matchResultToFile(reportedPath, candidates) {
196
+ if (!reportedPath) return null;
197
+ const normalized = String(reportedPath).replace(/\\/g, '/');
198
+ return candidates.find(f => normalized.endsWith(f)) || null;
50
199
  }
51
200
 
52
201
  /**
@@ -129,64 +278,84 @@ async function createBaseline() {
129
278
  // TypeScript/JavaScript — ESLint
130
279
  const tsFiles = findFilesByExt(['.ts', '.tsx', '.js', '.jsx']);
131
280
  if (tsFiles.length > 0) {
132
- try {
133
- const eslintConfigExists = fs.existsSync('.eslintrc.json') ||
134
- fs.existsSync('.eslintrc.js') ||
135
- fs.existsSync('.eslintrc.cjs') ||
136
- fs.existsSync('eslint.config.js');
137
- const eslintBin = fs.existsSync('node_modules/.bin/eslint') ? 'node_modules/.bin/eslint' : null;
138
-
139
- if (eslintConfigExists && (eslintBin || execSync('npx eslint --version', { encoding: 'utf8' }))) {
140
- const eslintCmd = eslintBin || 'npx eslint';
141
- const output = runToolJson(`${eslintCmd} ${tsFiles.join(' ')}`, '-f json --no-warn-ignored');
142
- if (output && output !== '[]') {
143
- const parsed = JSON.parse(output);
144
- for (const fileResult of parsed) {
145
- const relativePath = fileResult.filePath;
146
- const fileName = tsFiles.find(f => relativePath.endsWith(f));
147
- if (!fileName) continue;
148
-
149
- baseline[fileName] = {
150
- eslint: {
151
- warnings: fileResult.warningCount || 0,
152
- errors: fileResult.errorCount || 0,
153
- },
154
- totalWarnings: fileResult.warningCount || 0,
155
- lastAnalyzed: new Date().toISOString(),
156
- };
157
- }
158
- }
281
+ const eslintConfigExists = fs.existsSync('.eslintrc.json') ||
282
+ fs.existsSync('.eslintrc.js') ||
283
+ fs.existsSync('.eslintrc.cjs') ||
284
+ fs.existsSync('eslint.config.js');
285
+ const eslintBin = resolveLocalBin('eslint');
286
+
287
+ let eslintAvailable = Boolean(eslintBin);
288
+ if (!eslintAvailable) {
289
+ try {
290
+ execSync('npx eslint --version', { encoding: 'utf8', stdio: 'pipe' });
291
+ eslintAvailable = true;
292
+ } catch {
293
+ eslintAvailable = false;
159
294
  }
160
- } catch {
161
- // ESLint unavailable — skip
295
+ }
296
+
297
+ if (eslintConfigExists && eslintAvailable) {
298
+ const eslintCmd = eslintBin ? quoteBin(eslintBin) : 'npx eslint';
299
+ const { results, errors } = runLintInBatches(
300
+ tsFiles,
301
+ batch => `${eslintCmd} ${batch.map(f => `"${f}"`).join(' ')}`,
302
+ '-f json --no-warn-ignored'
303
+ );
304
+ recordFailures('eslint', errors);
305
+ for (const fileResult of results) {
306
+ const fileName = matchResultToFile(fileResult.filePath, tsFiles);
307
+ if (!fileName) continue;
308
+
309
+ baseline[fileName] = {
310
+ eslint: {
311
+ warnings: fileResult.warningCount || 0,
312
+ errors: fileResult.errorCount || 0,
313
+ },
314
+ totalWarnings: fileResult.warningCount || 0,
315
+ lastAnalyzed: new Date().toISOString(),
316
+ };
317
+ }
318
+ } else if (tsFiles.length > 0 && !eslintConfigExists) {
319
+ // Not a failure: a project without an eslint config has nothing to
320
+ // baseline. Staying quiet here is correct; the silent-catch defect was
321
+ // about masking errors, not about projects that legitimately have no tool.
162
322
  }
163
323
  }
164
324
 
165
325
  // Python — ruff
166
326
  const pyFiles = findFilesByExt(['.py']);
167
327
  if (pyFiles.length > 0) {
328
+ let ruffAvailable = false;
168
329
  try {
169
- execSync('ruff --version', { encoding: 'utf8' });
170
- const output = runToolJson(`ruff check ${pyFiles.join(' ')}`, '--output-format json');
171
- if (output && output !== '[]') {
172
- const parsed = JSON.parse(output);
173
- for (const fileResult of parsed) {
174
- if (!baseline[fileResult.file]) {
175
- const messages = fileResult.messages || [];
176
- baseline[fileResult.file] = {
177
- ruff: { warnings: messages.length, errors: 0 },
178
- totalWarnings: messages.length,
179
- lastAnalyzed: new Date().toISOString(),
180
- };
181
- } else {
182
- const messages = fileResult.messages || [];
183
- baseline[fileResult.file].ruff = { warnings: messages.length, errors: 0 };
184
- baseline[fileResult.file].totalWarnings += messages.length;
185
- }
330
+ execSync('ruff --version', { encoding: 'utf8', stdio: 'pipe' });
331
+ ruffAvailable = true;
332
+ } catch {
333
+ ruffAvailable = false;
334
+ }
335
+
336
+ if (ruffAvailable) {
337
+ const { results, errors } = runLintInBatches(
338
+ pyFiles,
339
+ batch => `ruff check ${batch.map(f => `"${f}"`).join(' ')}`,
340
+ '--output-format json'
341
+ );
342
+ recordFailures('ruff', errors);
343
+ for (const fileResult of results) {
344
+ // A result that names no file cannot be recorded against one. Skipping it
345
+ // is the fix for the literal "undefined" key this used to write.
346
+ if (!fileResult.file) continue;
347
+ const messages = fileResult.messages || [];
348
+ if (!baseline[fileResult.file]) {
349
+ baseline[fileResult.file] = {
350
+ ruff: { warnings: messages.length, errors: 0 },
351
+ totalWarnings: messages.length,
352
+ lastAnalyzed: new Date().toISOString(),
353
+ };
354
+ } else {
355
+ baseline[fileResult.file].ruff = { warnings: messages.length, errors: 0 };
356
+ baseline[fileResult.file].totalWarnings += messages.length;
186
357
  }
187
358
  }
188
- } catch {
189
- // Ruff unavailable — skip
190
359
  }
191
360
  }
192
361
 
@@ -232,39 +401,49 @@ async function createBaseline() {
232
401
  // Shell — shellcheck
233
402
  const shFiles = findShellScripts();
234
403
  if (shFiles.length > 0) {
404
+ let shAvailable = false;
235
405
  try {
236
- execSync('shellcheck --version', { encoding: 'utf8' });
237
- const output = runToolJson(`shellcheck -f json ${shFiles.join(' ')}`, '');
238
- if (output && output !== '[]') {
239
- const parsed = JSON.parse(output);
240
- const warningsByFile = {};
241
- for (const item of parsed) {
242
- const matchedFile = shFiles.find(f => item.file.endsWith(f));
243
- if (!matchedFile) continue;
244
- if (!warningsByFile[matchedFile]) {
245
- warningsByFile[matchedFile] = { warnings: 0, errors: 0 };
246
- }
247
- if (item.level === 'error') {
248
- warningsByFile[matchedFile].errors++;
249
- } else {
250
- warningsByFile[matchedFile].warnings++;
251
- }
406
+ execSync('shellcheck --version', { encoding: 'utf8', stdio: 'pipe' });
407
+ shAvailable = true;
408
+ } catch {
409
+ shAvailable = false;
410
+ }
411
+
412
+ if (shAvailable) {
413
+ // Same batching as the other tools: one argv for every shell script in the
414
+ // repo is the same platform-limit hazard, even though this repo happens to
415
+ // sit under the threshold today.
416
+ const { results, errors } = runLintInBatches(
417
+ shFiles,
418
+ batch => `shellcheck -f json ${batch.map(f => `"${f}"`).join(' ')}`,
419
+ ''
420
+ );
421
+ recordFailures('shellcheck', errors);
422
+ const warningsByFile = {};
423
+ for (const item of results) {
424
+ const matchedFile = matchResultToFile(item.file, shFiles);
425
+ if (!matchedFile) continue;
426
+ if (!warningsByFile[matchedFile]) {
427
+ warningsByFile[matchedFile] = { warnings: 0, errors: 0 };
252
428
  }
253
- for (const [file, counts] of Object.entries(warningsByFile)) {
254
- if (baseline[file]) {
255
- baseline[file].shellcheck = counts;
256
- baseline[file].totalWarnings += counts.warnings;
257
- } else {
258
- baseline[file] = {
259
- shellcheck: counts,
260
- totalWarnings: counts.warnings,
261
- lastAnalyzed: new Date().toISOString(),
262
- };
263
- }
429
+ if (item.level === 'error') {
430
+ warningsByFile[matchedFile].errors++;
431
+ } else {
432
+ warningsByFile[matchedFile].warnings++;
433
+ }
434
+ }
435
+ for (const [file, counts] of Object.entries(warningsByFile)) {
436
+ if (baseline[file]) {
437
+ baseline[file].shellcheck = counts;
438
+ baseline[file].totalWarnings += counts.warnings;
439
+ } else {
440
+ baseline[file] = {
441
+ shellcheck: counts,
442
+ totalWarnings: counts.warnings,
443
+ lastAnalyzed: new Date().toISOString(),
444
+ };
264
445
  }
265
446
  }
266
- } catch {
267
- // shellcheck unavailable — skip
268
447
  }
269
448
  }
270
449
 
@@ -468,4 +647,4 @@ Examples:
468
647
  }
469
648
  }
470
649
 
471
- module.exports = { handleBaseline, createBaseline, showBaseline, resetBaseline, diffBaseline, countBaselineByTool, compareBaselines, findShellScripts };
650
+ module.exports = { handleBaseline, createBaseline, showBaseline, resetBaseline, diffBaseline, countBaselineByTool, compareBaselines, findShellScripts, resolveLocalBin };
@@ -2,6 +2,6 @@
2
2
  "verdict": "PASS",
3
3
  "license_type": "MIT",
4
4
  "sha256": "0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5",
5
- "checked_at": "2026-11-18T02:40:10.620Z",
5
+ "checked_at": "2026-11-18T04:28:13.939Z",
6
6
  "source": "network"
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/xp-gate",
3
- "version": "0.38.10",
3
+ "version": "0.38.11",
4
4
  "description": "AI-driven development workflow: 6 quality gates + Delphi review + Sprint Flow",
5
5
  "bin": {
6
6
  "xp-gate": "bin/xp-gate.js"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.38.10",
3
+ "version": "0.38.11",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Claude Code. Includes 12 pre-commit gates (Gate 0-11), 8 pre-push gates, Sprint Flow (6 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/dsh-plugin-xp-gate",
3
- "version": "0.38.10",
3
+ "version": "0.38.11",
4
4
  "description": "XP-Gate deterministic quality gates + AI workflow skills as a DeepSeek Harness (DSH) native plugin: gate-check / gate-principles / gate-arch tools + 12 SKILL.md skills",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/opencode-plugin",
3
- "version": "0.38.10",
3
+ "version": "0.38.11",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "XP-Gate quality gates + AI workflow skills for OpenCode",
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.38.10",
3
+ "version": "0.38.11",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Qoder. Includes 12 pre-commit gates (Gate 0-11), 8 pre-push gates, Sprint Flow (6 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.10.0
6
+ **Version:** 0.38.11.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.