@boyingliu01/xp-gate 0.38.74 → 0.38.75
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/bin/xp-gate.js +17 -1
- package/lib/__tests__/doctor-signature-stability.test.js +55 -0
- package/lib/__tests__/doctor.test.js +6 -1
- package/lib/__tests__/gate2-verdict.test.js +126 -0
- package/lib/__tests__/issue-566-sync-hooks-backup.test.js +23 -16
- package/lib/__tests__/jscpd-entry-resolution.test.js +143 -0
- package/lib/__tests__/tsx-resolution.test.js +89 -0
- package/lib/doctor.js +99 -3
- package/lib/gate-runner.js +275 -41
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/tsx-resolve.js +48 -0
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
package/bin/xp-gate.js
CHANGED
|
@@ -794,7 +794,23 @@ function handleAuditRecord(args, auditPath) {
|
|
|
794
794
|
function evalGateAuditModule(expr) {
|
|
795
795
|
const { execFileSync } = require('node:child_process');
|
|
796
796
|
const modulePath = path.join(__dirname, '..', 'lib', 'gate-audit.ts');
|
|
797
|
-
|
|
797
|
+
// Resolve tsx by searching upward instead of counting `..` segments (#817).
|
|
798
|
+
//
|
|
799
|
+
// Three `..` from `bin/` already reaches `<global>/node_modules`, so the old
|
|
800
|
+
// `path.join(__dirname, '..', '..', '..', 'node_modules', 'tsx', ...)` produced
|
|
801
|
+
// `<global>/node_modules/node_modules/tsx/dist/cli.mjs` -- a path that can never
|
|
802
|
+
// exist. `audit --check` then died with MODULE_NOT_FOUND on every global install,
|
|
803
|
+
// and it happens to be the command doctor recommends when audit evidence is
|
|
804
|
+
// missing, so the documented recovery path was the broken one.
|
|
805
|
+
const tsxCli = require('../lib/tsx-resolve').findTsxCliFrom(__dirname);
|
|
806
|
+
if (!tsxCli) {
|
|
807
|
+
// An install hint beats a MODULE_NOT_FOUND stack: the file is fine, the
|
|
808
|
+
// dependency is absent, and those need different actions from the user.
|
|
809
|
+
throw new Error(
|
|
810
|
+
'xp-gate: cannot locate tsx, which this command needs to load its TypeScript module. '
|
|
811
|
+
+ 'Install it with `npm i -g tsx`, or reinstall xp-gate (`npm i -g @boyingliu01/xp-gate`).',
|
|
812
|
+
);
|
|
813
|
+
}
|
|
798
814
|
const script = [
|
|
799
815
|
`import * as m from ${JSON.stringify(modulePath)};`,
|
|
800
816
|
`process.stdout.write(JSON.stringify(${expr}));`,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-doctor-signature 钩子归属判定不得依赖会漂移的描述性数字(#854)
|
|
3
|
+
* @intent 证明 `xp-gate doctor` 不再对完好钩子误报 Missing or not xp-gate。
|
|
4
|
+
* 修复前实测:SIGNATURES['pre-push'] 写的是 "Pre-push Hook — 8 gates:",
|
|
5
|
+
* 而实际横幅是 "Pre-push Hook: Gate 10 (Build Integrity) + M/..."。两者
|
|
6
|
+
* 从来没有匹配过,所以对任何正常安装这条检查恒为 FAIL —— 是误报,不是缺文件。
|
|
7
|
+
*
|
|
8
|
+
* 要点不是"把字符串改成现在这句",而是让签名不随门禁数量漂移:
|
|
9
|
+
* pre-commit 的签名如果把 "12 numbered gates" 也算进去,下次加一道门禁
|
|
10
|
+
* 就同样会恒 FAIL。签名只取稳定的身份前缀。
|
|
11
|
+
*
|
|
12
|
+
* @covers AC-DOCTOR-SIG-01, AC-DOCTOR-SIG-02, AC-DOCTOR-SIG-03
|
|
13
|
+
*/
|
|
14
|
+
const fs = require('node:fs');
|
|
15
|
+
const path = require('node:path');
|
|
16
|
+
const { getHookSignatures, isXpGateHookContent } = require('../doctor');
|
|
17
|
+
|
|
18
|
+
const REPO_ROOT = path.resolve(__dirname, '..', '..', '..', '..');
|
|
19
|
+
|
|
20
|
+
describe('#854 doctor hook signatures', () => {
|
|
21
|
+
it('recognises the real shipped pre-push hook', () => {
|
|
22
|
+
// End-to-end against the actual file. A signature that only matches a
|
|
23
|
+
// hand-written fixture in this test would still fail on every install.
|
|
24
|
+
const hookPath = path.join(REPO_ROOT, 'githooks', 'pre-push');
|
|
25
|
+
const content = fs.readFileSync(hookPath, 'utf8');
|
|
26
|
+
expect(isXpGateHookContent('pre-push', content)).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('recognises the real shipped pre-commit and post-merge hooks', () => {
|
|
30
|
+
for (const name of ['pre-commit', 'post-merge']) {
|
|
31
|
+
const content = fs.readFileSync(path.join(REPO_ROOT, 'githooks', name), 'utf8');
|
|
32
|
+
expect(isXpGateHookContent(name, content)).toBe(true);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('does not encode a gate COUNT in any signature', () => {
|
|
37
|
+
// A signature containing a number would break the moment a gate is added or
|
|
38
|
+
// removed, which is exactly how pre-push's "8 gates" rotted.
|
|
39
|
+
for (const [name, sig] of Object.entries(getHookSignatures())) {
|
|
40
|
+
expect(Number.isFinite(Number(sig.match(/\d+/)?.[0]))).toBe(false);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('still rejects a foreign hook that merely mentions xp-gate', () => {
|
|
45
|
+
// Loosening the signature must not make the check useless: the point of the
|
|
46
|
+
// check is to tell OUR hook from someone else's.
|
|
47
|
+
expect(isXpGateHookContent('pre-push', '#!/bin/bash\necho "some other tool"\n')).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('rejects an xp-gate hook placed under the wrong name', () => {
|
|
51
|
+
// Signatures are per-hook; a pre-commit file must not satisfy pre-push.
|
|
52
|
+
const preCommit = fs.readFileSync(path.join(REPO_ROOT, 'githooks', 'pre-commit'), 'utf8');
|
|
53
|
+
expect(isXpGateHookContent('pre-push', preCommit)).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -210,9 +210,14 @@ describe('doctor', () => {
|
|
|
210
210
|
|
|
211
211
|
function createXpGatePrePush(dir) {
|
|
212
212
|
fs.mkdirSync(dir, { recursive: true });
|
|
213
|
+
// Mirror the banner the shipped hook actually carries. The previous fixture used
|
|
214
|
+
// '# Pre-push Hook — 8 gates:', which no shipped hook has ever contained -- so
|
|
215
|
+
// these "healthy install" cases passed against a fixture while every real
|
|
216
|
+
// installation failed (#854). A fixture that disagrees with the product turns
|
|
217
|
+
// the test into a check on itself.
|
|
213
218
|
fs.writeFileSync(
|
|
214
219
|
path.join(dir, 'pre-push'),
|
|
215
|
-
'#!/bin/bash\n# Pre-push Hook
|
|
220
|
+
'#!/bin/bash\n# Pre-push Hook: Gate 10 (Build Integrity) + M (Mutation)\n'
|
|
216
221
|
);
|
|
217
222
|
}
|
|
218
223
|
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-gate2-verdict 重复代码门禁必须能判定失败(#853 的第二半)
|
|
3
|
+
* @intent 修好 jscpd 入口探测只解决了"工具崩溃",没有解决"门禁从不失败"。
|
|
4
|
+
* 实测:jscpd 在不传 --threshold 时即使发现 66.7% 的重复也返回 exit 0,
|
|
5
|
+
* 所以 `runJscpd` 直接转发它的退出码,Gate 2 对任何仓库都恒为 PASS。
|
|
6
|
+
*
|
|
7
|
+
* 这和 #853 是同一个症状的两个阶段:修复前是 `spawnSync npx ENOENT`
|
|
8
|
+
* (工具跑不起来),修复后变成"跑起来了但从不拦截"。只修路径会让门禁
|
|
9
|
+
* 从"崩溃"变成"静默通过"——后者更危险,因为它看起来是绿的。
|
|
10
|
+
*
|
|
11
|
+
* @covers AC-GATE2-VERDICT-01, AC-GATE2-VERDICT-02, AC-GATE2-VERDICT-03
|
|
12
|
+
*/
|
|
13
|
+
const fs = require('node:fs');
|
|
14
|
+
const path = require('node:path');
|
|
15
|
+
const os = require('node:os');
|
|
16
|
+
|
|
17
|
+
const { buildJscpdArgs } = require('../gate-runner');
|
|
18
|
+
|
|
19
|
+
let tmpDir;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-gate2-'));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
if (tmpDir && fs.existsSync(tmpDir)) {
|
|
27
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('#853 Gate 2 must be able to fail', () => {
|
|
32
|
+
it('passes a --threshold so jscpd can return non-zero', () => {
|
|
33
|
+
// Without this the gate can never block, whatever it finds.
|
|
34
|
+
const args = buildJscpdArgs({ targetPath: tmpDir });
|
|
35
|
+
const at = args.indexOf('--threshold');
|
|
36
|
+
expect(at).toBeGreaterThanOrEqual(0);
|
|
37
|
+
expect(Number(args[at + 1])).toBeGreaterThan(0);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('uses the same 15% the code-duplication principle rule uses', () => {
|
|
41
|
+
// Two gates judging "how much duplication is too much" must not disagree;
|
|
42
|
+
// a run that fails Gate 4 while passing Gate 2 teaches users the gates lie.
|
|
43
|
+
const args = buildJscpdArgs({ targetPath: tmpDir });
|
|
44
|
+
expect(args[args.indexOf('--threshold') + 1]).toBe('15');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('lets a project config own the threshold when it declares one', () => {
|
|
48
|
+
// jscpd reads `threshold` from its own config. Passing --threshold as well
|
|
49
|
+
// would override the project's value with ours, which is the same
|
|
50
|
+
// config-vs-CLI conflict that already cost the ignore list its entries.
|
|
51
|
+
fs.writeFileSync(
|
|
52
|
+
path.join(tmpDir, 'jscpd.conf.json'),
|
|
53
|
+
JSON.stringify({ threshold: 3, ignore: ['**/vendor/**'] }),
|
|
54
|
+
);
|
|
55
|
+
const args = buildJscpdArgs({ targetPath: tmpDir });
|
|
56
|
+
expect(args).toContain('--config');
|
|
57
|
+
expect(args).not.toContain('--threshold');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('honours a threshold declared in .jscpd.json, not just jscpd.conf.json', () => {
|
|
61
|
+
// jscpd reads several config filenames. Measured on jscpd 5.4.3 with a fixture
|
|
62
|
+
// at 66.7% duplication:
|
|
63
|
+
// .jscpd.json {threshold: 90} -> exit 0 (config respected)
|
|
64
|
+
// .jscpd.json {threshold: 90} + --threshold 15 -> exit 1 (CLI won)
|
|
65
|
+
// A project that sets 90 in .jscpd.json would have been overridden by our 15,
|
|
66
|
+
// silently taking the decision away from the project that declared it.
|
|
67
|
+
fs.writeFileSync(path.join(tmpDir, '.jscpd.json'), JSON.stringify({ threshold: 90 }));
|
|
68
|
+
const args = buildJscpdArgs({ targetPath: tmpDir });
|
|
69
|
+
expect(args).toContain('--config');
|
|
70
|
+
expect(args).not.toContain('--threshold');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('falls back to the default threshold when the config declares none', () => {
|
|
74
|
+
// A config that exists but says nothing about the threshold must still let the
|
|
75
|
+
// gate decide; otherwise Gate 2 would silently stop enforcing anything, which
|
|
76
|
+
// is the very defect this change exists to fix.
|
|
77
|
+
fs.writeFileSync(path.join(tmpDir, 'jscpd.conf.json'), JSON.stringify({ ignore: ['**/x/**'] }));
|
|
78
|
+
const args = buildJscpdArgs({ targetPath: tmpDir });
|
|
79
|
+
expect(args).toContain('--config');
|
|
80
|
+
expect(args[args.indexOf('--threshold') + 1]).toBe('15');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('ignores a DIRECTORY that happens to be named like a config file', () => {
|
|
84
|
+
// `--config <dir>` cannot work, so a stray directory must not be discovered as
|
|
85
|
+
// a config: it would turn the gate red for a reason that has nothing to do with
|
|
86
|
+
// duplication.
|
|
87
|
+
fs.mkdirSync(path.join(tmpDir, '.jscpd.json'));
|
|
88
|
+
const args = buildJscpdArgs({ targetPath: tmpDir });
|
|
89
|
+
expect(args).not.toContain('--config');
|
|
90
|
+
expect(args[args.indexOf('--threshold') + 1]).toBe('15');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('never applies the working directory config to an explicit target', () => {
|
|
94
|
+
// The stated rule is "an explicit --target decides". Measured before this was
|
|
95
|
+
// enforced: with only the xp-gate repo holding a jscpd.conf.json, a target with
|
|
96
|
+
// no config of its own still received `--config <xp-gate repo>/jscpd.conf.json`
|
|
97
|
+
// -- so `check 2 /other/repo` judged that repo by this repo's ignore list.
|
|
98
|
+
// The fixture keeps its own cwd config out of the picture by asserting on the
|
|
99
|
+
// config PATH rather than on presence.
|
|
100
|
+
const args = buildJscpdArgs({ targetPath: tmpDir });
|
|
101
|
+
const at = args.indexOf('--config');
|
|
102
|
+
if (at >= 0) {
|
|
103
|
+
expect(args[at + 1].startsWith(tmpDir)).toBe(true);
|
|
104
|
+
}
|
|
105
|
+
// A target with no config must never produce one of its own.
|
|
106
|
+
expect(args).not.toContain('--config');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('falls back to the default threshold when the config is malformed', () => {
|
|
110
|
+
// An unparseable config must not crash the gate or disable the threshold.
|
|
111
|
+
// Measured on jscpd 5.4.3: passing a corrupt --config makes jscpd exit 1 with
|
|
112
|
+
// "key must be a string at line 1 column 3" -- which the gate would report as
|
|
113
|
+
// "duplicate code found". A broken config must not read as a finding.
|
|
114
|
+
fs.writeFileSync(path.join(tmpDir, 'jscpd.conf.json'), '{ not valid json');
|
|
115
|
+
const args = buildJscpdArgs({ targetPath: tmpDir });
|
|
116
|
+
expect(args[args.indexOf('--threshold') + 1]).toBe('15');
|
|
117
|
+
expect(args).not.toContain('--config');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('does not pass a --config jscpd would reject', () => {
|
|
121
|
+
// Same rule, stated as the invariant: whatever --config we pass must parse.
|
|
122
|
+
fs.writeFileSync(path.join(tmpDir, 'jscpd.conf.json'), '{ not valid json');
|
|
123
|
+
const args = buildJscpdArgs({ targetPath: tmpDir });
|
|
124
|
+
expect(args).not.toContain('--config');
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -53,22 +53,29 @@ describe('doctor --sync-hooks keeps the previous version (#566)', () => {
|
|
|
53
53
|
* @param {{installedPrePush?: string}} [opts] content for the installed pre-push
|
|
54
54
|
*/
|
|
55
55
|
function makeLayout(opts = {}) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
// Wrap the fixture setup so a failure names the fixture that broke instead of
|
|
57
|
+
// surfacing later as "doctor reported the wrong thing". Without this, an
|
|
58
|
+
// unreadable tmpHome looks like a product defect in the assertion.
|
|
59
|
+
try {
|
|
60
|
+
const root = fs.mkdtempSync(path.join(tmpHome, `layout-${DESCRIBE_ID}-`));
|
|
61
|
+
const repoRoot = path.join(root, 'repo');
|
|
62
|
+
const repoHooks = path.join(repoRoot, 'githooks');
|
|
63
|
+
const installedHooks = path.join(root, 'installed-hooks');
|
|
64
|
+
fs.mkdirSync(repoHooks, { recursive: true });
|
|
65
|
+
fs.mkdirSync(installedHooks, { recursive: true });
|
|
66
|
+
|
|
67
|
+
// The canonical hook carries the xp-gate signature doctor looks for.
|
|
68
|
+
fs.writeFileSync(
|
|
69
|
+
path.join(repoHooks, 'pre-push'),
|
|
70
|
+
'#!/usr/bin/env bash\n# XP-Gate Pre-Push Hook\n# Pre-push Hook: Gate 10 (Build Integrity)\necho canonical\n',
|
|
71
|
+
);
|
|
72
|
+
if (opts.installedPrePush !== undefined) {
|
|
73
|
+
fs.writeFileSync(path.join(installedHooks, 'pre-push'), opts.installedPrePush);
|
|
74
|
+
}
|
|
75
|
+
return { root, repoRoot, repoHooks, installedHooks };
|
|
76
|
+
} catch (err) {
|
|
77
|
+
throw new Error(`fixture: could not build hook layout under ${tmpHome}: ${err.message}`);
|
|
70
78
|
}
|
|
71
|
-
return { root, repoRoot, repoHooks, installedHooks };
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
it('AC-599-13: overwriting an existing hook keeps a copy of the previous version', () => {
|
|
@@ -138,7 +145,7 @@ describe('doctor --sync-hooks keeps the previous version (#566)', () => {
|
|
|
138
145
|
});
|
|
139
146
|
|
|
140
147
|
it('AC-599-13: an identical file is not re-copied and leaves no backup', () => {
|
|
141
|
-
const canonical = '#!/usr/bin/env bash\n# XP-Gate Pre-Push Hook\n# Pre-push Hook
|
|
148
|
+
const canonical = '#!/usr/bin/env bash\n# XP-Gate Pre-Push Hook\n# Pre-push Hook: Gate 10 (Build Integrity)\necho canonical\n';
|
|
142
149
|
const { repoHooks, installedHooks } = makeLayout({ installedPrePush: canonical });
|
|
143
150
|
|
|
144
151
|
const { syncGlobalHooksFromRepo } = loadDoctor();
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-jscpd-entry 重复代码门禁必须能在全局安装下找到 jscpd(#853)
|
|
3
|
+
* @intent 证明 Gate 2 在 npm 全局安装 + 干净 fixture 下不再恒失败。修复前实测:
|
|
4
|
+
* `npmGlobalRoots` 的元素已经以 `node_modules` 结尾,`runJscpd` 又拼了一次,
|
|
5
|
+
* 于是探测的是 `<global>/npm/node_modules/node_modules/jscpd/bin/jscpd`,
|
|
6
|
+
* 而真实路径是 `<global>/npm/node_modules/jscpd`。entry 恒为 undefined,
|
|
7
|
+
* 落到 `npx --no-install jscpd` fallback,在 Windows 上报 spawnSync ENOENT。
|
|
8
|
+
*
|
|
9
|
+
* 第二个缺陷叠加:jscpd 5.x 把入口从 `bin/jscpd` 换成了 `run-jscpd.js`
|
|
10
|
+
* (package.json 的 bin 字段为 `{"jscpd": "./run-jscpd.js"}`)。硬编码
|
|
11
|
+
* `bin/jscpd` 在 5.x 上即便路径拼对了也找不到。
|
|
12
|
+
*
|
|
13
|
+
* @covers AC-JSCPD-ENTRY-01, AC-JSCPD-ENTRY-02, AC-JSCPD-ENTRY-03, AC-JSCPD-ENTRY-04
|
|
14
|
+
*/
|
|
15
|
+
const fs = require('node:fs');
|
|
16
|
+
const path = require('node:path');
|
|
17
|
+
const os = require('node:os');
|
|
18
|
+
const { findJscpdEntry, buildGlobalPrefixes } = require('../gate-runner');
|
|
19
|
+
|
|
20
|
+
let tmpDir;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-jscpd-'));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
if (tmpDir && fs.existsSync(tmpDir)) {
|
|
28
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Lay down a fake jscpd install whose package.json declares the given bin entry.
|
|
34
|
+
*
|
|
35
|
+
* The real 5.4.3 layout is reproduced faithfully: `run-jscpd.js` at the package
|
|
36
|
+
* root, no `bin/jscpd`. Getting this wrong would make the test pass against a
|
|
37
|
+
* layout that does not exist and never catch the regression it exists for.
|
|
38
|
+
*/
|
|
39
|
+
function plantJscpd(packageDir, binField) {
|
|
40
|
+
try {
|
|
41
|
+
fs.mkdirSync(packageDir, { recursive: true });
|
|
42
|
+
fs.writeFileSync(
|
|
43
|
+
path.join(packageDir, 'package.json'),
|
|
44
|
+
JSON.stringify({ name: 'jscpd', version: '5.4.3', bin: binField }, null, 2),
|
|
45
|
+
);
|
|
46
|
+
for (const rel of Object.values(binField)) {
|
|
47
|
+
const target = path.join(packageDir, rel);
|
|
48
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
49
|
+
fs.writeFileSync(target, '// fake jscpd' + String.fromCharCode(10));
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
throw new Error(`fixture: could not plant jscpd at ${packageDir}: ${err.message}`);
|
|
53
|
+
}
|
|
54
|
+
return packageDir;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe('#853 jscpd entry resolution', () => {
|
|
58
|
+
it('finds jscpd 5.x whose entry is run-jscpd.js, not bin/jscpd', () => {
|
|
59
|
+
// The exact 5.4.3 declaration. Hardcoding `bin/jscpd` cannot satisfy this.
|
|
60
|
+
const pkg = plantJscpd(path.join(tmpDir, 'node_modules', 'jscpd'), { jscpd: './run-jscpd.js' });
|
|
61
|
+
const entry = findJscpdEntry({ searchRoots: [tmpDir] });
|
|
62
|
+
expect(entry).toBe(path.join(pkg, 'run-jscpd.js'));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('finds a legacy jscpd whose entry is bin/jscpd', () => {
|
|
66
|
+
// 4.x layout must keep working; the fix must not trade one version for another.
|
|
67
|
+
const pkg = plantJscpd(path.join(tmpDir, 'node_modules', 'jscpd'), { jscpd: './bin/jscpd' });
|
|
68
|
+
const entry = findJscpdEntry({ searchRoots: [tmpDir] });
|
|
69
|
+
expect(entry).toBe(path.join(pkg, 'bin', 'jscpd'));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('does not append node_modules to a root that already ends with it', () => {
|
|
73
|
+
// This is the #853 doubling. A global npm prefix IS `<...>/npm/node_modules`,
|
|
74
|
+
// so probing `<...>/npm/node_modules/node_modules/jscpd` can never succeed.
|
|
75
|
+
const globalPrefix = path.join(tmpDir, 'npm', 'node_modules');
|
|
76
|
+
const pkg = plantJscpd(path.join(globalPrefix, 'jscpd'), { jscpd: './run-jscpd.js' });
|
|
77
|
+
const entry = findJscpdEntry({ searchRoots: [globalPrefix] });
|
|
78
|
+
expect(entry).toBe(path.join(pkg, 'run-jscpd.js'));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('follows an unusual bin field rather than assuming a filename', () => {
|
|
82
|
+
// A hardcoded filename silently breaks the next time upstream renames the
|
|
83
|
+
// entry point -- which is exactly how #853's second defect appeared.
|
|
84
|
+
const pkg = plantJscpd(path.join(tmpDir, 'node_modules', 'jscpd'), { jscpd: './dist/start.js' });
|
|
85
|
+
const entry = findJscpdEntry({ searchRoots: [tmpDir] });
|
|
86
|
+
expect(entry).toBe(path.join(pkg, 'dist', 'start.js'));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('finds jscpd in a POSIX global prefix (<prefix>/lib/node_modules)', () => {
|
|
90
|
+
// `path.dirname(process.execPath)` is `<prefix>/bin` on Linux and macOS, and a
|
|
91
|
+
// global jscpd there lives in `<prefix>/lib/node_modules` -- NOT in
|
|
92
|
+
// `<prefix>/bin/node_modules`. #853's own scenario was Windows, but a fix that
|
|
93
|
+
// only works there would leave the same bug on every Unix install.
|
|
94
|
+
const prefix = path.join(tmpDir, 'prefix');
|
|
95
|
+
const pkg = plantJscpd(path.join(prefix, 'lib', 'node_modules', 'jscpd'), { jscpd: './run-jscpd.js' });
|
|
96
|
+
const entry = findJscpdEntry({ searchRoots: [prefix] });
|
|
97
|
+
expect(entry).toBe(path.join(pkg, 'run-jscpd.js'));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('returns null when jscpd is genuinely absent', () => {
|
|
101
|
+
// "not installed" must stay distinguishable from "installed but unfindable":
|
|
102
|
+
// the first is a SKIP, the second was the bug.
|
|
103
|
+
expect(findJscpdEntry({ searchRoots: [tmpDir] })).toBeNull();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('never yields a relative prefix when the env vars are unset', () => {
|
|
107
|
+
// path.join('', 'npm') is the RELATIVE path 'npm'. Left in the list it would be
|
|
108
|
+
// resolved against the current directory, so an unset APPDATA/HOME would point
|
|
109
|
+
// the search at ./npm -- a directory that has nothing to do with any global
|
|
110
|
+
// install, and one an attacker-ish layout could populate.
|
|
111
|
+
const prefixes = buildGlobalPrefixes({ binDir: path.join(tmpDir, 'nodejs') });
|
|
112
|
+
expect(prefixes.length).toBeGreaterThan(0);
|
|
113
|
+
for (const p of prefixes) {
|
|
114
|
+
expect(path.isAbsolute(p)).toBe(true);
|
|
115
|
+
}
|
|
116
|
+
expect(prefixes).not.toContain('npm');
|
|
117
|
+
expect(prefixes).not.toContain('.npm-global');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('includes the APPDATA and home prefixes when those variables exist', () => {
|
|
121
|
+
const appData = path.join(tmpDir, 'appdata');
|
|
122
|
+
const home = path.join(tmpDir, 'home');
|
|
123
|
+
const prefixes = buildGlobalPrefixes({
|
|
124
|
+
binDir: path.join(tmpDir, 'nodejs'),
|
|
125
|
+
appData,
|
|
126
|
+
home,
|
|
127
|
+
});
|
|
128
|
+
expect(prefixes).toContain(path.join(appData, 'npm'));
|
|
129
|
+
expect(prefixes).toContain(path.join(home, '.npm-global'));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('ignores a half-written install with no resolvable entry file', () => {
|
|
133
|
+
// A package.json whose bin target does not exist would be spawned and fail
|
|
134
|
+
// with a message about missing files, reading as a gate defect not an install one.
|
|
135
|
+
const pkgDir = path.join(tmpDir, 'node_modules', 'jscpd');
|
|
136
|
+
fs.mkdirSync(pkgDir, { recursive: true });
|
|
137
|
+
fs.writeFileSync(
|
|
138
|
+
path.join(pkgDir, 'package.json'),
|
|
139
|
+
JSON.stringify({ name: 'jscpd', bin: { jscpd: './run-jscpd.js' } }),
|
|
140
|
+
);
|
|
141
|
+
expect(findJscpdEntry({ searchRoots: [tmpDir] })).toBeNull();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @test REQ-audit-cli 定位 tsx 时不得多拼一层 node_modules(#817)
|
|
3
|
+
* @intent 证明 `xp-gate audit --check` 在 npm 全局安装下不再 MODULE_NOT_FOUND。
|
|
4
|
+
* 修复前实测:`bin/xp-gate.js` 从 `bin/` 出发走三个 `..` 已经到达
|
|
5
|
+
* `<global>/node_modules`,再拼 `node_modules/tsx` 就变成
|
|
6
|
+
* `<global>/node_modules/node_modules/tsx/dist/cli.mjs`,必然不存在。
|
|
7
|
+
*
|
|
8
|
+
* 这不是"路径写错了"这么简单:`audit --check` 是 doctor 在缺审计证据时
|
|
9
|
+
* 推荐给用户的恢复路径,它一崩,用户就没有可用的恢复手段。
|
|
10
|
+
*
|
|
11
|
+
* @covers AC-TSX-RESOLVE-01, AC-TSX-RESOLVE-02, AC-TSX-RESOLVE-03
|
|
12
|
+
*/
|
|
13
|
+
const fs = require('node:fs');
|
|
14
|
+
const path = require('node:path');
|
|
15
|
+
const os = require('node:os');
|
|
16
|
+
const { findTsxCliFrom } = require('../tsx-resolve');
|
|
17
|
+
|
|
18
|
+
let tmpDir;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-tsxres-'));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
if (tmpDir && fs.existsSync(tmpDir)) {
|
|
26
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Plant a fake `tsx/dist/cli.mjs` under `root` and return its absolute path.
|
|
32
|
+
*
|
|
33
|
+
* Failing to plant is a fixture defect, so the error names the fixture rather
|
|
34
|
+
* than letting it surface later as "the resolver returned undefined", which
|
|
35
|
+
* would be read as a resolver bug.
|
|
36
|
+
*/
|
|
37
|
+
function plantTsx(root) {
|
|
38
|
+
const cli = path.join(root, 'node_modules', 'tsx', 'dist', 'cli.mjs');
|
|
39
|
+
try {
|
|
40
|
+
fs.mkdirSync(path.dirname(cli), { recursive: true });
|
|
41
|
+
fs.writeFileSync(cli, '// fake tsx cli' + String.fromCharCode(10));
|
|
42
|
+
} catch (err) {
|
|
43
|
+
throw new Error(`fixture: could not plant tsx at ${cli}: ${err.message}`);
|
|
44
|
+
}
|
|
45
|
+
return cli;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('#817 tsx resolution from the CLI entry point', () => {
|
|
49
|
+
it('finds the sibling tsx of a globally installed xp-gate', () => {
|
|
50
|
+
// Reproduce the real global layout:
|
|
51
|
+
// <prefix>/node_modules/@boyingliu01/xp-gate/bin
|
|
52
|
+
// <prefix>/node_modules/tsx/dist/cli.mjs
|
|
53
|
+
// The fix is to search UPWARD for node_modules rather than counting `..`.
|
|
54
|
+
const prefix = path.join(tmpDir, 'npm');
|
|
55
|
+
const pkgRoot = path.join(prefix, 'node_modules', '@boyingliu01', 'xp-gate');
|
|
56
|
+
fs.mkdirSync(path.join(pkgRoot, 'bin'), { recursive: true });
|
|
57
|
+
const expected = plantTsx(prefix);
|
|
58
|
+
const resolved = findTsxCliFrom(path.join(pkgRoot, 'bin'));
|
|
59
|
+
expect(resolved).toBe(expected);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('finds a tsx hoisted into the consumer project', () => {
|
|
63
|
+
// A local install hoists tsx next to the package under the same node_modules.
|
|
64
|
+
const project = path.join(tmpDir, 'project');
|
|
65
|
+
const pkgRoot = path.join(project, 'node_modules', '@boyingliu01', 'xp-gate');
|
|
66
|
+
fs.mkdirSync(path.join(pkgRoot, 'bin'), { recursive: true });
|
|
67
|
+
const expected = plantTsx(project);
|
|
68
|
+
expect(findTsxCliFrom(path.join(pkgRoot, 'bin'))).toBe(expected);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('never produces a doubled node_modules segment', () => {
|
|
72
|
+
// The exact #817 shape. Even when it resolves to nothing, the returned path
|
|
73
|
+
// must never contain node_modules/node_modules -- that is always a bug, and
|
|
74
|
+
// it is indistinguishable from "not installed" at the call site.
|
|
75
|
+
const prefix = path.join(tmpDir, 'npm');
|
|
76
|
+
const pkgRoot = path.join(prefix, 'node_modules', '@boyingliu01', 'xp-gate');
|
|
77
|
+
fs.mkdirSync(path.join(pkgRoot, 'bin'), { recursive: true });
|
|
78
|
+
const resolved = findTsxCliFrom(path.join(pkgRoot, 'bin'));
|
|
79
|
+
expect(resolved === null || !resolved.includes(`node_modules${path.sep}node_modules`)).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('returns null when tsx is genuinely absent, rather than a broken path', () => {
|
|
83
|
+
// The caller must be able to tell "not installed" (print an install hint)
|
|
84
|
+
// apart from "here is a path" (spawn it).
|
|
85
|
+
const pkgRoot = path.join(tmpDir, 'nowhere', 'bin');
|
|
86
|
+
fs.mkdirSync(pkgRoot, { recursive: true });
|
|
87
|
+
expect(findTsxCliFrom(pkgRoot)).toBeNull();
|
|
88
|
+
});
|
|
89
|
+
});
|
package/lib/doctor.js
CHANGED
|
@@ -62,14 +62,46 @@ function getPackageVersion() {
|
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Signature strings used to verify file ownership.
|
|
65
|
+
*
|
|
66
|
+
* Each must be a STABLE identity anchor -- text that says "this file is xp-gate's
|
|
67
|
+
* <hook>" and does not describe how many gates it runs or what they are called.
|
|
68
|
+
* Descriptive banners rot: `pre-push` was keyed on `'Pre-push Hook — 8 gates:'`,
|
|
69
|
+
* while the hook's actual banner reads `'Pre-push Hook: Gate 10 (Build
|
|
70
|
+
* Integrity) + M/...'`. The two never matched, so `doctor` reported
|
|
71
|
+
* "Missing or not xp-gate" for every healthy installation -- a false alarm that
|
|
72
|
+
* `--fix` could not clear because there was nothing to fix (#854).
|
|
73
|
+
*
|
|
74
|
+
* The same trap sits in the sibling signatures: `pre-commit`'s banner continues
|
|
75
|
+
* " - 12 numbered gates (Gate 0–11)", so a signature that included that span
|
|
76
|
+
* would break the day a gate is added. Anchor before the count, not through it.
|
|
65
77
|
*/
|
|
66
78
|
const SIGNATURES = {
|
|
67
79
|
'pre-commit': 'OpenCode Quality Gates - Pre-Commit Hook',
|
|
68
|
-
'pre-push': 'Pre-push Hook
|
|
80
|
+
'pre-push': 'Pre-push Hook:',
|
|
69
81
|
'post-merge': 'XP-Gate VERSION sync hook',
|
|
70
82
|
'adapter-common.sh': 'detect_project_lang()'
|
|
71
83
|
};
|
|
72
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Contents that identify an xp-gate hook even when its banner wording changed.
|
|
87
|
+
*
|
|
88
|
+
* The banner is documentation and is expected to be edited; ownership should
|
|
89
|
+
* survive that. These are markers of the hook's actual machinery, which any
|
|
90
|
+
* xp-gate hook carries and no unrelated script would.
|
|
91
|
+
*/
|
|
92
|
+
const OWNERSHIP_MARKERS = [
|
|
93
|
+
'XP-Gate',
|
|
94
|
+
'xp-gate',
|
|
95
|
+
'_LE_CR', // the #546 line-ending self-check every shipped hook begins with
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
/** Banner prefixes per hook: how a hook announces its own identity. */
|
|
99
|
+
const BANNER_SELF_ID = {
|
|
100
|
+
'pre-commit': 'Pre-Commit Hook',
|
|
101
|
+
'pre-push': 'Pre-push Hook',
|
|
102
|
+
'post-merge': 'post-merge',
|
|
103
|
+
};
|
|
104
|
+
|
|
73
105
|
/**
|
|
74
106
|
* Hard timeout for all execSync calls in doctor diagnostics.
|
|
75
107
|
* Prevents hanging subprocesses (e.g., missing CLI tools on Windows)
|
|
@@ -248,6 +280,23 @@ function checkSpawnCapability(checks) {
|
|
|
248
280
|
return 0;
|
|
249
281
|
}
|
|
250
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Read a hook file's text, or null when it is absent or unreadable.
|
|
285
|
+
*
|
|
286
|
+
* Returning null rather than throwing keeps the caller's decision in one place:
|
|
287
|
+
* absence is a FAIL, not an exception.
|
|
288
|
+
*
|
|
289
|
+
* @param {string} hookPath
|
|
290
|
+
* @returns {string|null}
|
|
291
|
+
*/
|
|
292
|
+
function readHookContent(hookPath) {
|
|
293
|
+
try {
|
|
294
|
+
return fs.readFileSync(hookPath, 'utf8');
|
|
295
|
+
} catch {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
251
300
|
function isXpGateFile(filePath, signature) {
|
|
252
301
|
if (!fs.existsSync(filePath)) return false;
|
|
253
302
|
try {
|
|
@@ -258,6 +307,46 @@ function isXpGateFile(filePath, signature) {
|
|
|
258
307
|
}
|
|
259
308
|
}
|
|
260
309
|
|
|
310
|
+
/**
|
|
311
|
+
* The table of hook-ownership signatures, exposed so tests can assert the
|
|
312
|
+
* invariant that keeps #854 from recurring: no signature may embed a count.
|
|
313
|
+
*
|
|
314
|
+
* @returns {Record<string, string>}
|
|
315
|
+
*/
|
|
316
|
+
function getHookSignatures() {
|
|
317
|
+
return { ...SIGNATURES };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Decide whether `content` is xp-gate's hook for `hookName`.
|
|
322
|
+
*
|
|
323
|
+
* Two things are checked, in order:
|
|
324
|
+
*
|
|
325
|
+
* 1. The hook's own signature, so a pre-commit file cannot satisfy pre-push.
|
|
326
|
+
* 2. A banner-independent ownership marker, but only when the file ALSO announces
|
|
327
|
+
* itself as this hook (`BANNER_SELF_ID`) and carries xp-gate machinery.
|
|
328
|
+
*
|
|
329
|
+
* The second exists because keying on a descriptive banner is what rotted: the
|
|
330
|
+
* banner is documentation and gets edited, while the check quietly turned every
|
|
331
|
+
* healthy install into "Missing or not xp-gate". Requiring a self-announcement is
|
|
332
|
+
* what keeps the looser test honest -- merely MENTIONING a hook name is not
|
|
333
|
+
* enough, and it has to be: `githooks/pre-commit` refers to `pre-push` twice in
|
|
334
|
+
* its comments, so a bare `content.includes(hookName)` accepted the wrong file.
|
|
335
|
+
*
|
|
336
|
+
* @param {string} hookName
|
|
337
|
+
* @param {string} content
|
|
338
|
+
* @returns {boolean}
|
|
339
|
+
*/
|
|
340
|
+
function isXpGateHookContent(hookName, content) {
|
|
341
|
+
if (typeof content !== 'string' || content.length === 0) return false;
|
|
342
|
+
const signature = SIGNATURES[hookName];
|
|
343
|
+
if (!signature) return false;
|
|
344
|
+
if (content.includes(signature)) return true;
|
|
345
|
+
const announcesItself = BANNER_SELF_ID[hookName];
|
|
346
|
+
if (!announcesItself || !content.includes(announcesItself)) return false;
|
|
347
|
+
return OWNERSHIP_MARKERS.some((marker) => content.includes(marker));
|
|
348
|
+
}
|
|
349
|
+
|
|
261
350
|
function getConfig() {
|
|
262
351
|
if (!fs.existsSync(CONFIG_FILE())) return null;
|
|
263
352
|
try {
|
|
@@ -1752,7 +1841,14 @@ function syncGlobalHooksFromRepo(ctx = {}) {
|
|
|
1752
1841
|
*/
|
|
1753
1842
|
function checkSingleHook(hooksDir, name, signature, label, checks) {
|
|
1754
1843
|
const hookPath = path.join(hooksDir, name);
|
|
1755
|
-
|
|
1844
|
+
// Read once and let the ownership check see the content: isXpGateHookContent
|
|
1845
|
+
// also accepts a banner-independent ownership marker, so a reworded banner no
|
|
1846
|
+
// longer turns every healthy install into "Missing or not xp-gate" (#854).
|
|
1847
|
+
const content = readHookContent(hookPath);
|
|
1848
|
+
const owned = content !== null
|
|
1849
|
+
? isXpGateHookContent(name, content)
|
|
1850
|
+
: isXpGateFile(hookPath, signature);
|
|
1851
|
+
if (!fs.existsSync(hookPath) || !owned) {
|
|
1756
1852
|
checks.push({ name: `${label}: ${name}`, status: 'FAIL', detail: 'Missing or not xp-gate' });
|
|
1757
1853
|
return 1;
|
|
1758
1854
|
}
|
|
@@ -3767,7 +3863,7 @@ function collectSkillDrift(skillDir, bundledFiles, bundledSkillDir, sha256) {
|
|
|
3767
3863
|
}
|
|
3768
3864
|
|
|
3769
3865
|
module.exports = {
|
|
3770
|
-
doctor, doctorDelphi, isXpGateFile, SIGNATURES,
|
|
3866
|
+
doctor, doctorDelphi, isXpGateFile, SIGNATURES, getHookSignatures, isXpGateHookContent,
|
|
3771
3867
|
fixVersionMismatch,
|
|
3772
3868
|
fixTemplateDirMismatch,
|
|
3773
3869
|
fixMissingHooks,
|
package/lib/gate-runner.js
CHANGED
|
@@ -600,30 +600,7 @@ const GATE_REGISTRY = {
|
|
|
600
600
|
description: 'jscpd duplicate code detection',
|
|
601
601
|
aliases: ['duplicates', 'dup', '2'],
|
|
602
602
|
run: (targetPath) => {
|
|
603
|
-
const
|
|
604
|
-
// The scan root is '.' whenever we are running inside the target.
|
|
605
|
-
//
|
|
606
|
-
// jscpd 4.x does not apply its glob ignore rules to an ABSOLUTE scan path:
|
|
607
|
-
// measured on a fixture with three byte-identical files, one of them under
|
|
608
|
-
// .xp-gate/, `jscpd <abs-path> --ignore "**/.xp-gate/**,..."` reported 0
|
|
609
|
-
// clones while `jscpd . --ignore <same>` reported 2 (the copy excluded, the
|
|
610
|
-
// real duplicate kept). Passing '.' and running with cwd = target keeps both
|
|
611
|
-
// the ignore rules and the discovery working.
|
|
612
|
-
const scanRoot = !targetPath || path.resolve(targetPath) === path.resolve(process.cwd()) ? '.' : targetPath;
|
|
613
|
-
const args = [scanRoot];
|
|
614
|
-
if (jscpdConfig) args.push('--config', jscpdConfig);
|
|
615
|
-
// The ignore set is passed ONLY when the project has no config of its own.
|
|
616
|
-
//
|
|
617
|
-
// jscpd's --ignore is a REGEX while jscpd.conf.json's ignore is GLOB. Passing
|
|
618
|
-
// both does not merge them -- the CLI value replaces the config's list, so the
|
|
619
|
-
// scan lost "**/node_modules/**" and "**/.worktrees/**" and started walking
|
|
620
|
-
// .worktrees/sprint-*/plugins/opencode/node_modules (measured: 300 s timeout,
|
|
621
|
-
// down from 49 s, with the run still failing). The config is authoritative
|
|
622
|
-
// when it exists; the built-in set is a fallback for projects without one.
|
|
623
|
-
if (!jscpdConfig) {
|
|
624
|
-
const ignore = jscpdDefaultIgnorePatterns();
|
|
625
|
-
if (ignore) args.push('--ignore', ignore);
|
|
626
|
-
}
|
|
603
|
+
const args = buildJscpdArgs({ targetPath });
|
|
627
604
|
runJscpd(args, targetPath);
|
|
628
605
|
},
|
|
629
606
|
},
|
|
@@ -838,6 +815,197 @@ function jscpdDefaultIgnorePatterns() {
|
|
|
838
815
|
].join(',');
|
|
839
816
|
}
|
|
840
817
|
|
|
818
|
+
/**
|
|
819
|
+
* Resolve jscpd's JS entry point without assuming a filename.
|
|
820
|
+
*
|
|
821
|
+
* Two defects are fixed here at once (#853):
|
|
822
|
+
*
|
|
823
|
+
* 1. **Doubled `node_modules`.** Roots were probed as
|
|
824
|
+
* `path.join(root, 'node_modules', 'jscpd', ...)`, but a global npm prefix
|
|
825
|
+
* already ends in `node_modules`, so the probe became
|
|
826
|
+
* `<prefix>/node_modules/node_modules/jscpd`. `hasNodeModules()` decides per
|
|
827
|
+
* root whether to append the segment.
|
|
828
|
+
*
|
|
829
|
+
* 2. **Hardcoded `bin/jscpd`.** jscpd 5.x declares its entry as
|
|
830
|
+
* `{"jscpd": "./run-jscpd.js"}` and ships no `bin/jscpd` at all. The bin field
|
|
831
|
+
* is now read from the installed package.json, so an upstream rename cannot
|
|
832
|
+
* silently disable the gate again -- which is precisely how 5.x broke it.
|
|
833
|
+
*
|
|
834
|
+
* @param {{searchRoots?: Array<string|undefined>}} [opts]
|
|
835
|
+
* @returns {string|null} absolute path to jscpd's JS entry, or null when absent
|
|
836
|
+
*/
|
|
837
|
+
function findJscpdEntry(opts = {}) {
|
|
838
|
+
const roots = (opts.searchRoots || []).filter((r) => typeof r === 'string' && r.length > 0);
|
|
839
|
+
for (const root of roots) {
|
|
840
|
+
const candidate = jscpdEntryUnder(root);
|
|
841
|
+
if (candidate) return candidate;
|
|
842
|
+
}
|
|
843
|
+
return null;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Look for an installed jscpd beneath one root, treating the root as either a
|
|
848
|
+
* project directory (whose `node_modules` we must enter) or a node_modules
|
|
849
|
+
* directory already.
|
|
850
|
+
*
|
|
851
|
+
* @param {string} root
|
|
852
|
+
* @returns {string|null}
|
|
853
|
+
*/
|
|
854
|
+
function jscpdEntryUnder(root) {
|
|
855
|
+
const bases = [path.join(root, 'node_modules')];
|
|
856
|
+
// A global npm prefix (`<...>/npm/node_modules`) is itself a node_modules dir.
|
|
857
|
+
if (path.basename(path.resolve(root)) === 'node_modules') bases.unshift(root);
|
|
858
|
+
// POSIX global installs put packages in `<prefix>/lib/node_modules`, while
|
|
859
|
+
// `path.dirname(process.execPath)` is `<prefix>/bin`. Without this, #853's fix
|
|
860
|
+
// would work on Windows and leave the same bug on every Linux/macOS install.
|
|
861
|
+
bases.push(path.join(root, 'lib', 'node_modules'));
|
|
862
|
+
for (const base of bases) {
|
|
863
|
+
const entry = jscpdEntryIn(path.join(base, 'jscpd'));
|
|
864
|
+
if (entry) return entry;
|
|
865
|
+
}
|
|
866
|
+
return null;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Read `package.json`'s bin field from `packageDir` and return the entry that
|
|
871
|
+
* actually exists on disk, or null when the package is absent or half-written.
|
|
872
|
+
*
|
|
873
|
+
* @param {string} packageDir
|
|
874
|
+
* @returns {string|null}
|
|
875
|
+
*/
|
|
876
|
+
function jscpdEntryIn(packageDir) {
|
|
877
|
+
const pkgJson = path.join(packageDir, 'package.json');
|
|
878
|
+
let bin;
|
|
879
|
+
try {
|
|
880
|
+
bin = JSON.parse(fs.readFileSync(pkgJson, 'utf8')).bin;
|
|
881
|
+
} catch {
|
|
882
|
+
// No package.json, unreadable, or invalid JSON: not an installed package.
|
|
883
|
+
return null;
|
|
884
|
+
}
|
|
885
|
+
const rel = typeof bin === 'string' ? bin : bin && (bin.jscpd || Object.values(bin)[0]);
|
|
886
|
+
if (!rel) return null;
|
|
887
|
+
const entry = path.join(packageDir, rel);
|
|
888
|
+
return fs.existsSync(entry) ? entry : null;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Default duplicate-ratio ceiling for Gate 2.
|
|
893
|
+
*
|
|
894
|
+
* Must match the `code-duplication` principle rule's threshold. Two gates judging
|
|
895
|
+
* "how much duplication is too much" with different numbers teach the user that
|
|
896
|
+
* the gates disagree, and a user who sees Gate 4 fail while Gate 2 passes
|
|
897
|
+
* concludes the gates are unreliable.
|
|
898
|
+
*/
|
|
899
|
+
const JSCPD_THRESHOLD = 15;
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Build the jscpd argv for Gate 2.
|
|
903
|
+
*
|
|
904
|
+
* Extracted from the gate's `run` so the threshold decision is testable without
|
|
905
|
+
* spawning jscpd. The threshold is the part that was missing: jscpd returns 0
|
|
906
|
+
* regardless of findings when no `--threshold` is given, so forwarding its exit
|
|
907
|
+
* code made Gate 2 unconditionally pass. Measured on a fixture with 66.7%
|
|
908
|
+
* duplication: `jscpd .` exit 0, `jscpd . --threshold 5` exit 1.
|
|
909
|
+
*
|
|
910
|
+
* @param {{targetPath?: string}} opts
|
|
911
|
+
* @returns {string[]}
|
|
912
|
+
*/
|
|
913
|
+
function buildJscpdArgs(opts = {}) {
|
|
914
|
+
const targetPath = opts.targetPath;
|
|
915
|
+
const jscpdConfig = findJscpdConfig(targetPath);
|
|
916
|
+
// The scan root is '.' whenever we are running inside the target.
|
|
917
|
+
//
|
|
918
|
+
// jscpd 4.x does not apply its glob ignore rules to an ABSOLUTE scan path:
|
|
919
|
+
// measured on a fixture with three byte-identical files, one of them under
|
|
920
|
+
// .xp-gate/, `jscpd <abs-path> --ignore "**/.xp-gate/**,..."` reported 0
|
|
921
|
+
// clones while `jscpd . --ignore <same>` reported 2 (the copy excluded, the
|
|
922
|
+
// real duplicate kept). Passing '.' and running with cwd = target keeps both
|
|
923
|
+
// the ignore rules and the discovery working.
|
|
924
|
+
const scanRoot = !targetPath || path.resolve(targetPath) === path.resolve(process.cwd()) ? '.' : targetPath;
|
|
925
|
+
const args = [scanRoot];
|
|
926
|
+
// A config is passed only when jscpd can actually parse it. Measured on
|
|
927
|
+
// jscpd 5.4.3: `--config <corrupt>` exits 1 with "key must be a string at line 1
|
|
928
|
+
// column 3", which the gate forwards as a verdict -- so a typo in the project's
|
|
929
|
+
// config would be reported as "duplicate code found". An unreadable config is
|
|
930
|
+
// treated as absent, and the default threshold still applies.
|
|
931
|
+
const parsedConfig = jscpdConfig ? readJscpdConfig(jscpdConfig) : null;
|
|
932
|
+
if (parsedConfig) {
|
|
933
|
+
args.push('--config', jscpdConfig);
|
|
934
|
+
// A config that declares its own `threshold` owns the decision. Passing ours
|
|
935
|
+
// as well would override the project's number -- the same config-vs-CLI
|
|
936
|
+
// conflict that already cost the ignore list its entries.
|
|
937
|
+
if (!isFiniteNumber(parsedConfig.threshold)) args.push('--threshold', String(JSCPD_THRESHOLD));
|
|
938
|
+
return args;
|
|
939
|
+
}
|
|
940
|
+
if (jscpdConfig) {
|
|
941
|
+
// The config exists but cannot be used. Saying so is not optional: silently
|
|
942
|
+
// dropping the project's ignore/min-tokens rules changes what gets scanned,
|
|
943
|
+
// and the operator would have no way to tell that from a real result. The
|
|
944
|
+
// gate still runs (fail-open on the config, fail-closed on the threshold).
|
|
945
|
+
process.stderr.write(
|
|
946
|
+
`[gate-2] ignoring unreadable jscpd config ${jscpdConfig}; `
|
|
947
|
+
+ `using the built-in ignore set and --threshold ${JSCPD_THRESHOLD}\n`,
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
// The ignore set is passed ONLY when the project has no config of its own.
|
|
951
|
+
//
|
|
952
|
+
// jscpd's --ignore is a REGEX while jscpd.conf.json's ignore is GLOB. Passing
|
|
953
|
+
// both does not merge them -- the CLI value replaces the config's list, so the
|
|
954
|
+
// scan lost "**/node_modules/**" and "**/.worktrees/**" and started walking
|
|
955
|
+
// .worktrees/sprint-*/plugins/opencode/node_modules (measured: 300 s timeout,
|
|
956
|
+
// down from 49 s, with the run still failing). The config is authoritative
|
|
957
|
+
// when it exists; the built-in set is a fallback for projects without one.
|
|
958
|
+
const ignore = jscpdDefaultIgnorePatterns();
|
|
959
|
+
if (ignore) args.push('--ignore', ignore);
|
|
960
|
+
args.push('--threshold', String(JSCPD_THRESHOLD));
|
|
961
|
+
return args;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* Parse a jscpd config file.
|
|
966
|
+
*
|
|
967
|
+
* @param {string} configPath
|
|
968
|
+
* @returns {object|null} the parsed object, or null when unreadable or invalid
|
|
969
|
+
*/
|
|
970
|
+
function readJscpdConfig(configPath) {
|
|
971
|
+
try {
|
|
972
|
+
const parsed = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
973
|
+
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
974
|
+
} catch {
|
|
975
|
+
return null;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* @param {unknown} value
|
|
981
|
+
* @returns {boolean}
|
|
982
|
+
*/
|
|
983
|
+
function isFiniteNumber(value) {
|
|
984
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* The npm global prefixes worth probing for an installed tool.
|
|
989
|
+
*
|
|
990
|
+
* Built conditionally because `path.join('', 'npm')` yields the RELATIVE path
|
|
991
|
+
* `npm`, which `findJscpdEntry` would then resolve against the current directory:
|
|
992
|
+
* an unset APPDATA/HOME would silently point the search at `./npm` and
|
|
993
|
+
* `./.npm-global`. A candidate is only included when its base variable exists.
|
|
994
|
+
*
|
|
995
|
+
* @param {{binDir: string, appData?: string, home?: string}} env
|
|
996
|
+
* @returns {string[]} absolute prefixes, most likely first
|
|
997
|
+
*/
|
|
998
|
+
function buildGlobalPrefixes(env) {
|
|
999
|
+
const prefixes = [env.binDir];
|
|
1000
|
+
// A POSIX global prefix puts the binary in <prefix>/bin, so its parent is the
|
|
1001
|
+
// prefix packages hang off. Walking up avoids hardcoding "/usr".
|
|
1002
|
+
if (env.binDir) prefixes.push(path.dirname(env.binDir));
|
|
1003
|
+
if (env.appData) prefixes.push(path.join(env.appData, 'npm'));
|
|
1004
|
+
if (env.home) prefixes.push(path.join(env.home, '.npm-global'));
|
|
1005
|
+
// Only absolute results are usable as prefixes.
|
|
1006
|
+
return prefixes.filter((p) => typeof p === 'string' && p.length > 0 && path.isAbsolute(p));
|
|
1007
|
+
}
|
|
1008
|
+
|
|
841
1009
|
function runJscpd(args, targetPath) {
|
|
842
1010
|
// Invoke jscpd's JS entry through `node` rather than going through .bin/.
|
|
843
1011
|
//
|
|
@@ -853,24 +1021,29 @@ function runJscpd(args, targetPath) {
|
|
|
853
1021
|
// 1. the project under check
|
|
854
1022
|
// 2. this package own dependency tree
|
|
855
1023
|
// 3. the global install tree
|
|
1024
|
+
//
|
|
1025
|
+
// The global trees are passed as PREFIXES, not as `.../node_modules` paths,
|
|
1026
|
+
// because a global npm prefix already contains `node_modules`. Treating the two
|
|
1027
|
+
// the same is #853: the old code appended `node_modules/jscpd/bin/jscpd` to an
|
|
1028
|
+
// already-`node_modules`-terminated root, probing
|
|
1029
|
+
// `<prefix>/node_modules/node_modules/jscpd/bin/jscpd`, which can never exist.
|
|
1030
|
+
// `entry` was therefore always undefined and every lookup fell through to `npx`,
|
|
1031
|
+
// which on Windows reported `spawnSync npx ENOENT` -- a working tool reported as
|
|
1032
|
+
// missing, with an exit code indistinguishable from "duplicate code found".
|
|
1033
|
+
//
|
|
856
1034
|
// process.execPath is the node BINARY location, not the npm global prefix; both
|
|
857
1035
|
// are probed along with the APPDATA npm tree, because a global package lives in
|
|
858
|
-
// a directory that varies by platform and by install method.
|
|
859
|
-
//
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
process.
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
...npmGlobalRoots,
|
|
870
|
-
];
|
|
871
|
-
const entry = roots
|
|
872
|
-
.map((r) => path.join(r, 'node_modules', 'jscpd', 'bin', 'jscpd'))
|
|
873
|
-
.find((c) => fs.existsSync(c));
|
|
1036
|
+
// a directory that varies by platform and by install method.
|
|
1037
|
+
// Each entry is a PREFIX, not a node_modules directory: findJscpdEntry probes
|
|
1038
|
+
// `<prefix>/node_modules`, `<prefix>/lib/node_modules` (POSIX global installs)
|
|
1039
|
+
// and, when the prefix is itself named node_modules, the prefix directly.
|
|
1040
|
+
const nodeBinDir = path.dirname(process.execPath);
|
|
1041
|
+
const globalPrefixes = buildGlobalPrefixes({
|
|
1042
|
+
binDir: nodeBinDir,
|
|
1043
|
+
appData: process.env.APPDATA,
|
|
1044
|
+
home: process.env.USERPROFILE || process.env.HOME,
|
|
1045
|
+
});
|
|
1046
|
+
const entry = findJscpdEntry({ searchRoots: [targetPath, process.cwd(), ...globalPrefixes] });
|
|
874
1047
|
let lastErr = null;
|
|
875
1048
|
// Third fallback is deliberately `--no-install`: a global jscpd is on PATH on the
|
|
876
1049
|
// dev machine (/c/Users/think/AppData/Roaming/npm/jscpd) but `npx` here was
|
|
@@ -911,6 +1084,67 @@ function findConfig(basePath, fileName) {
|
|
|
911
1084
|
return null;
|
|
912
1085
|
}
|
|
913
1086
|
|
|
1087
|
+
/**
|
|
1088
|
+
* Config filenames jscpd itself reads, in the order it prefers them.
|
|
1089
|
+
*
|
|
1090
|
+
* Only `jscpd.conf.json` used to be looked for. Measured on jscpd 5.4.3 against a
|
|
1091
|
+
* fixture at 66.7% duplication, a project setting `{"threshold": 90}` in
|
|
1092
|
+
* `.jscpd.json`:
|
|
1093
|
+
* `jscpd .` -> exit 0 (project's 90 respected)
|
|
1094
|
+
* `jscpd . --threshold 15` -> exit 1 (our CLI value overrode it)
|
|
1095
|
+
* So a project that declared its own threshold in `.jscpd.json` had the gate
|
|
1096
|
+
* impose 15 instead -- taking the decision away from the project that made it.
|
|
1097
|
+
* `.jscpdrc` is NOT read by jscpd (verified: still exit 0), so it is excluded
|
|
1098
|
+
* rather than pretended to work.
|
|
1099
|
+
*/
|
|
1100
|
+
const JSCPD_CONFIG_FILENAMES = ['jscpd.conf.json', '.jscpd.json'];
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Locate a jscpd config the tool will actually honour.
|
|
1104
|
+
*
|
|
1105
|
+
* Discovery follows ONE root, chosen by whether the caller named a target:
|
|
1106
|
+
*
|
|
1107
|
+
* - An explicit target means that target: its config decides. Falling back to the
|
|
1108
|
+
* working directory would let `xp-gate check 2 /other/repo` judge that repo by
|
|
1109
|
+
* THIS repo's ignore list and threshold. Measured before this rule existed:
|
|
1110
|
+
* with only this repo holding a jscpd.conf.json, a target with no config of its
|
|
1111
|
+
* own still received `--config <this repo>/jscpd.conf.json`.
|
|
1112
|
+
* - No target means the working directory, which is the tree the scan covers.
|
|
1113
|
+
*
|
|
1114
|
+
* Every supported filename is tried in the chosen root before giving up; trying
|
|
1115
|
+
* one name across both roots first let a `jscpd.conf.json` in the cwd shadow a
|
|
1116
|
+
* `.jscpd.json` in the project being checked.
|
|
1117
|
+
*
|
|
1118
|
+
* @param {string} [basePath] the explicit target, if the caller gave one
|
|
1119
|
+
* @returns {string|null}
|
|
1120
|
+
*/
|
|
1121
|
+
function findJscpdConfig(basePath) {
|
|
1122
|
+
const root = basePath || process.cwd();
|
|
1123
|
+
for (const name of JSCPD_CONFIG_FILENAMES) {
|
|
1124
|
+
const candidate = path.join(root, name);
|
|
1125
|
+
if (isRegularFile(candidate)) return candidate;
|
|
1126
|
+
}
|
|
1127
|
+
return null;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* True only for an existing REGULAR FILE.
|
|
1132
|
+
*
|
|
1133
|
+
* `fs.existsSync` is also true for a directory, and a directory named
|
|
1134
|
+
* `.jscpd.json` would be handed to jscpd as `--config <dir>`, failing the gate for
|
|
1135
|
+
* a reason unrelated to duplication.
|
|
1136
|
+
*
|
|
1137
|
+
* @param {string} candidate
|
|
1138
|
+
* @returns {boolean}
|
|
1139
|
+
*/
|
|
1140
|
+
function isRegularFile(candidate) {
|
|
1141
|
+
try {
|
|
1142
|
+
return fs.statSync(candidate).isFile();
|
|
1143
|
+
} catch {
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
|
|
914
1148
|
/**
|
|
915
1149
|
* The basename of the first `gate-<num>-*.sh` in a directory, or null.
|
|
916
1150
|
*
|
|
@@ -1063,7 +1297,7 @@ async function invokeGateHandler(gateId, gate, targetPath, opts) {
|
|
|
1063
1297
|
}
|
|
1064
1298
|
}
|
|
1065
1299
|
|
|
1066
|
-
module.exports = { findConsumerGateVariant, GATE_REGISTRY, GATE_NOT_RUN, getGateInfo, getAllGates, runGate, resolveAlias, getAliases, runGateAdapter, findTsGateEntry, resolveGateScript, resolveTsxInvocation, findTsxCli, SOURCE_FILE_EXTENSIONS, resolveAllModeChangedFiles, describeEmptyChangedFiles, describeChangedFilesScope,
|
|
1300
|
+
module.exports = { findConsumerGateVariant, GATE_REGISTRY, GATE_NOT_RUN, getGateInfo, getAllGates, runGate, resolveAlias, getAliases, runGateAdapter, findTsGateEntry, resolveGateScript, resolveTsxInvocation, findTsxCli, findJscpdEntry, buildJscpdArgs, JSCPD_THRESHOLD, buildGlobalPrefixes, SOURCE_FILE_EXTENSIONS, resolveAllModeChangedFiles, describeEmptyChangedFiles, describeChangedFilesScope,
|
|
1067
1301
|
// AC-670-03 asserts the --all preamble END-TO-END: that an all-mode run hands
|
|
1068
1302
|
// the security gates a non-empty file population sourced from the list file and
|
|
1069
1303
|
// sets GATE_SCOPE="all". With these unexported, the case could only take its
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Locate tsx's CLI entry by searching UPWARD for node_modules.
|
|
5
|
+
*
|
|
6
|
+
* Why not a fixed number of `..` segments: the depth from a call site to the
|
|
7
|
+
* package root differs between a global install, a local install and a monorepo
|
|
8
|
+
* checkout, and it changes whenever the file moves. #817 was exactly that --
|
|
9
|
+
* `bin/xp-gate.js` used three `..` segments from `bin/`, which already reached
|
|
10
|
+
* `<global>/node_modules`, then appended `node_modules/tsx` again, producing
|
|
11
|
+
* `<global>/node_modules/node_modules/tsx/dist/cli.mjs`. That path can never
|
|
12
|
+
* exist, so `xp-gate audit --check` reported MODULE_NOT_FOUND on every global
|
|
13
|
+
* install.
|
|
14
|
+
*
|
|
15
|
+
* Searching upward is what Node's own resolver does, so it is correct by
|
|
16
|
+
* construction for every layout: the first directory whose `node_modules`
|
|
17
|
+
* contains `tsx/dist/cli.mjs` is the one that wins.
|
|
18
|
+
*
|
|
19
|
+
* A `tsx/` directory without `dist/cli.mjs` counts as "not installed" -- the same
|
|
20
|
+
* convention `gate-runner.js` already uses. A half-written install would
|
|
21
|
+
* otherwise be spawned and fail with a message about missing files, which reads
|
|
22
|
+
* like a defect in the gate rather than an incomplete install.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** How many ancestor directories to inspect before giving up. */
|
|
26
|
+
const MAX_SEARCH_DEPTH = 12;
|
|
27
|
+
|
|
28
|
+
const fs = require('node:fs');
|
|
29
|
+
const path = require('node:path');
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} startDir directory to start searching from
|
|
33
|
+
* @returns {string|null} absolute path to tsx's cli.mjs, or null when absent
|
|
34
|
+
*/
|
|
35
|
+
function findTsxCliFrom(startDir) {
|
|
36
|
+
let dir = path.resolve(startDir);
|
|
37
|
+
for (let depth = 0; depth < MAX_SEARCH_DEPTH; depth += 1) {
|
|
38
|
+
const candidate = path.join(dir, 'node_modules', 'tsx', 'dist', 'cli.mjs');
|
|
39
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
40
|
+
const parent = path.dirname(dir);
|
|
41
|
+
// Reached the filesystem root; `dirname(root) === root`.
|
|
42
|
+
if (parent === dir) break;
|
|
43
|
+
dir = parent;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = { findTsxCliFrom, MAX_SEARCH_DEPTH };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xp-gate",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.75",
|
|
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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.0
|
|
7
7
|
|
|
8
8
|
## OVERVIEW
|
|
9
9
|
Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
|
package/plugins/dsh/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boyingliu01/dsh-plugin-xp-gate",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.75",
|
|
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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
3
|
+
"version": "0.38.75",
|
|
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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.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.
|
|
6
|
+
**Version:** 0.38.75.0
|
|
7
7
|
|
|
8
8
|
## OVERVIEW
|
|
9
9
|
Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
|