@boyingliu01/xp-gate 0.38.75 → 0.38.77
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/lib/__tests__/mirror-sync.test.js +387 -5
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/mirror-sync.js +202 -15
- 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/lib/hooks.d.ts +10 -1
- package/plugins/dsh/lib/hooks.d.ts.map +1 -1
- package/plugins/dsh/lib/hooks.js +56 -5
- package/plugins/dsh/lib/index.js +6 -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/dsh/src/hooks.test.ts +70 -0
- package/plugins/dsh/src/hooks.ts +66 -5
- package/plugins/dsh/src/index.ts +6 -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/scripts/generate-mirrors.cjs +10 -0
- 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/mock-policy/__tests__/config.test.ts +0 -292
- package/mock-policy/__tests__/gate-m3.test.ts +0 -379
- package/mock-policy/__tests__/integration.test.ts +0 -600
- package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
- package/mock-policy/__tests__/schema.test.ts +0 -239
- package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
- package/mutation/__tests__/detect-ai-test.test.ts +0 -152
- package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
- package/mutation/__tests__/gate-m.test.ts +0 -246
- package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
- package/mutation/__tests__/gremlins-runner.test.ts +0 -167
- package/mutation/__tests__/init-baseline.test.ts +0 -347
- package/mutation/__tests__/mutation-mirror.test.ts +0 -49
- package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
- package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
- package/mutation/__tests__/pitest-runner.test.ts +0 -574
- package/mutation/__tests__/runners-index.test.ts +0 -162
- package/mutation/__tests__/stryker-runner.test.ts +0 -455
- package/mutation/__tests__/test-filter-parity.test.ts +0 -40
- package/mutation/__tests__/update-baseline.test.ts +0 -395
- package/principles/__tests__/adapter-metrics.test.ts +0 -292
- package/principles/__tests__/analyze-read-failure.test.ts +0 -70
- package/principles/__tests__/analyzer.test.ts +0 -367
- package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
- package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
- package/principles/__tests__/baseline-prune.test.ts +0 -399
- package/principles/__tests__/baseline-storage.test.ts +0 -188
- package/principles/__tests__/baseline.test.ts +0 -330
- package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
- package/principles/__tests__/boy-scout-integration.test.ts +0 -355
- package/principles/__tests__/boy-scout.test.ts +0 -893
- package/principles/__tests__/cli-files-separators.test.ts +0 -69
- package/principles/__tests__/config-arch-group.test.ts +0 -106
- package/principles/__tests__/config-enforcement.test.ts +0 -470
- package/principles/__tests__/config-git-timeout.test.ts +0 -66
- package/principles/__tests__/config-merge-warnings.test.ts +0 -148
- package/principles/__tests__/config.test.ts +0 -78
- package/principles/__tests__/direct-execution.test.ts +0 -187
- package/principles/__tests__/index.test.ts +0 -94
- package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
- package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
- package/principles/__tests__/lint-baseline.test.ts +0 -314
- package/principles/__tests__/many-exports-reexport.test.ts +0 -40
- package/principles/__tests__/reporter.test.ts +0 -660
- package/principles/__tests__/types.test.ts +0 -103
- package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
- package/principles/adapters/__tests__/base.test.ts +0 -95
- package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
- package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
- package/principles/adapters/__tests__/cpp.test.ts +0 -290
- package/principles/adapters/__tests__/dart.test.ts +0 -84
- package/principles/adapters/__tests__/go.test.ts +0 -68
- package/principles/adapters/__tests__/java.test.ts +0 -385
- package/principles/adapters/__tests__/kotlin.test.ts +0 -76
- package/principles/adapters/__tests__/objectivec.test.ts +0 -453
- package/principles/adapters/__tests__/python.test.ts +0 -84
- package/principles/adapters/__tests__/swift.test.ts +0 -68
- package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
- package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
- package/principles/adapters/__tests__/typescript.test.ts +0 -116
- package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
- package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
- package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
- package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
- package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
- package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
- package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
- package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
- package/principles/rules/__tests__/index.test.ts +0 -49
- package/principles/rules/__tests__/solid/dip.test.ts +0 -119
- package/principles/rules/__tests__/solid/isp.test.ts +0 -58
- package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
- package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
- package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
- package/principles/rules/__tests__/solid/srp.test.ts +0 -87
- package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
- package/principles/rules/arch/__tests__/naming.test.ts +0 -133
- package/principles/rules/arch/__tests__/shared.test.ts +0 -113
|
@@ -1,541 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test REQ-SCOPE-001 Scope Scanner
|
|
3
|
-
* @intent Verify project scope scanning classifies imports correctly
|
|
4
|
-
* @covers AC-SCOPE-01, AC-SCOPE-02, AC-SCOPE-03
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
8
|
-
import { mkdirSync, writeFileSync, rmSync } from 'fs';
|
|
9
|
-
import { join, resolve } from 'path';
|
|
10
|
-
import { tmpdir } from 'os';
|
|
11
|
-
import {
|
|
12
|
-
simpleGlobMatch,
|
|
13
|
-
isExternalImport,
|
|
14
|
-
resolveToRealPath,
|
|
15
|
-
loadExternalDependencies,
|
|
16
|
-
classifyDependency,
|
|
17
|
-
scanProjectScope,
|
|
18
|
-
} from '../scope-scanner';
|
|
19
|
-
import type { ScanOptions } from '../scope-scanner';
|
|
20
|
-
import type { ProjectScope } from '../types';
|
|
21
|
-
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// simpleGlobMatch
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
describe('simpleGlobMatch', () => {
|
|
26
|
-
it('matches exact literal patterns', () => {
|
|
27
|
-
expect(simpleGlobMatch('src/index.ts', 'src/index.ts')).toBe(true);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('rejects non-matching literal patterns', () => {
|
|
31
|
-
expect(simpleGlobMatch('src/index.ts', 'src/foo.ts')).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('matches ** (globstar) across path separators', () => {
|
|
35
|
-
expect(simpleGlobMatch('src/**/*.ts', 'src/a/b/c.ts')).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('matches * (single-star) within a single path segment', () => {
|
|
39
|
-
expect(simpleGlobMatch('src/*.ts', 'src/index.ts')).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('rejects * crossing path separators', () => {
|
|
43
|
-
expect(simpleGlobMatch('src/*.ts', 'src/a/b.ts')).toBe(false);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('matches ** at the root', () => {
|
|
47
|
-
expect(simpleGlobMatch('**/*.ts', 'some/deep/file.ts')).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('handles leading **/ patterns', () => {
|
|
51
|
-
expect(simpleGlobMatch('**/foo', 'a/b/c/foo')).toBe(true);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('handles trailing /** patterns', () => {
|
|
55
|
-
expect(simpleGlobMatch('src/**', 'src/a/b/c')).toBe(true);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('handles dots in filenames correctly', () => {
|
|
59
|
-
expect(simpleGlobMatch('*.test.ts', 'foo.test.ts')).toBe(true);
|
|
60
|
-
expect(simpleGlobMatch('*.test.ts', 'footest.ts')).toBe(false);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('matches ? as a single non-slash character', () => {
|
|
64
|
-
expect(simpleGlobMatch('src/?.ts', 'src/a.ts')).toBe(true);
|
|
65
|
-
expect(simpleGlobMatch('src/?.ts', 'src/ab.ts')).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('escapes regex special characters in patterns', () => {
|
|
69
|
-
expect(simpleGlobMatch('src/file+[test].ts', 'src/file+[test].ts')).toBe(true);
|
|
70
|
-
expect(simpleGlobMatch('src/file+[test].ts', 'src/fileXtest.ts')).toBe(false);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('returns false for invalid regex patterns gracefully', () => {
|
|
74
|
-
expect(simpleGlobMatch('src/[invalid', 'src/foo')).toBe(false);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('handles mixed character types in sequence', () => {
|
|
78
|
-
expect(simpleGlobMatch('src/**/test.?.*', 'src/a/b/test.c.ts')).toBe(true);
|
|
79
|
-
expect(simpleGlobMatch('src/**/test.?.*', 'src/sub/test.c.ts')).toBe(true);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('handles regex special chars (+^${}()|[]) in patterns', () => {
|
|
83
|
-
expect(simpleGlobMatch('src/file+test', 'src/file+test')).toBe(true);
|
|
84
|
-
expect(simpleGlobMatch('src/file^test', 'src/file^test')).toBe(true);
|
|
85
|
-
expect(simpleGlobMatch('src/file(test)', 'src/file(test)')).toBe(true);
|
|
86
|
-
expect(simpleGlobMatch('src/file{test}', 'src/file{test}')).toBe(true);
|
|
87
|
-
expect(simpleGlobMatch('src/file|test', 'src/file|test')).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// ---------------------------------------------------------------------------
|
|
92
|
-
// isExternalImport
|
|
93
|
-
// ---------------------------------------------------------------------------
|
|
94
|
-
describe('isExternalImport', () => {
|
|
95
|
-
const defaultOptions: ScanOptions = {
|
|
96
|
-
projectRoot: '/fake/project',
|
|
97
|
-
imports: [],
|
|
98
|
-
boundary: ['@/components/**', '@/utils/**'],
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
it('returns true for Node.js builtins', () => {
|
|
102
|
-
expect(isExternalImport('fs', defaultOptions)).toBe(true);
|
|
103
|
-
expect(isExternalImport('path', defaultOptions)).toBe(true);
|
|
104
|
-
expect(isExternalImport('os', defaultOptions)).toBe(true);
|
|
105
|
-
expect(isExternalImport('http', defaultOptions)).toBe(true);
|
|
106
|
-
expect(isExternalImport('https', defaultOptions)).toBe(true);
|
|
107
|
-
expect(isExternalImport('crypto', defaultOptions)).toBe(true);
|
|
108
|
-
expect(isExternalImport('stream', defaultOptions)).toBe(true);
|
|
109
|
-
expect(isExternalImport('events', defaultOptions)).toBe(true);
|
|
110
|
-
expect(isExternalImport('util', defaultOptions)).toBe(true);
|
|
111
|
-
expect(isExternalImport('url', defaultOptions)).toBe(true);
|
|
112
|
-
expect(isExternalImport('querystring', defaultOptions)).toBe(true);
|
|
113
|
-
expect(isExternalImport('assert', defaultOptions)).toBe(true);
|
|
114
|
-
expect(isExternalImport('buffer', defaultOptions)).toBe(true);
|
|
115
|
-
expect(isExternalImport('child_process', defaultOptions)).toBe(true);
|
|
116
|
-
expect(isExternalImport('cluster', defaultOptions)).toBe(true);
|
|
117
|
-
expect(isExternalImport('dns', defaultOptions)).toBe(true);
|
|
118
|
-
expect(isExternalImport('net', defaultOptions)).toBe(true);
|
|
119
|
-
expect(isExternalImport('tls', defaultOptions)).toBe(true);
|
|
120
|
-
expect(isExternalImport('readline', defaultOptions)).toBe(true);
|
|
121
|
-
expect(isExternalImport('process', defaultOptions)).toBe(true);
|
|
122
|
-
expect(isExternalImport('v8', defaultOptions)).toBe(true);
|
|
123
|
-
expect(isExternalImport('vm', defaultOptions)).toBe(true);
|
|
124
|
-
expect(isExternalImport('zlib', defaultOptions)).toBe(true);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('returns true for node: prefix builtins', () => {
|
|
128
|
-
expect(isExternalImport('node:fs', defaultOptions)).toBe(true);
|
|
129
|
-
expect(isExternalImport('node:path', defaultOptions)).toBe(true);
|
|
130
|
-
expect(isExternalImport('node:crypto', defaultOptions)).toBe(true);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('returns true for bare npm packages', () => {
|
|
134
|
-
expect(isExternalImport('lodash', defaultOptions)).toBe(true);
|
|
135
|
-
expect(isExternalImport('express', defaultOptions)).toBe(true);
|
|
136
|
-
expect(isExternalImport('react', defaultOptions)).toBe(true);
|
|
137
|
-
expect(isExternalImport('@scope/package', defaultOptions)).toBe(true);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('returns false for relative imports starting with .', () => {
|
|
141
|
-
expect(isExternalImport('./foo', defaultOptions)).toBe(false);
|
|
142
|
-
expect(isExternalImport('../bar', defaultOptions)).toBe(false);
|
|
143
|
-
expect(isExternalImport('./utils/helper', defaultOptions)).toBe(false);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('returns false for @/ alias imports', () => {
|
|
147
|
-
expect(isExternalImport('@/components/Button', defaultOptions)).toBe(false);
|
|
148
|
-
expect(isExternalImport('@/utils/format', defaultOptions)).toBe(false);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('returns false for absolute imports matching boundary', () => {
|
|
152
|
-
const boundaryOptions: ScanOptions = {
|
|
153
|
-
...defaultOptions,
|
|
154
|
-
boundary: ['@/components/**', '@/utils/**', 'src/modules/**'],
|
|
155
|
-
};
|
|
156
|
-
expect(isExternalImport('src/modules/auth', boundaryOptions)).toBe(false);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('returns false for absolute imports starting with /', () => {
|
|
160
|
-
expect(isExternalImport('/opt/node/foo', defaultOptions)).toBe(false);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('returns true for bare imports not matching boundary', () => {
|
|
164
|
-
const strictOptions: ScanOptions = {
|
|
165
|
-
...defaultOptions,
|
|
166
|
-
boundary: ['src/components/**'],
|
|
167
|
-
};
|
|
168
|
-
expect(isExternalImport('src/utils/helper', strictOptions)).toBe(true);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
// ---------------------------------------------------------------------------
|
|
173
|
-
// resolveToRealPath
|
|
174
|
-
// ---------------------------------------------------------------------------
|
|
175
|
-
describe('resolveToRealPath', () => {
|
|
176
|
-
it('replaces @/ prefix with src/', () => {
|
|
177
|
-
const result = resolveToRealPath('@/components/Button', '/project');
|
|
178
|
-
expect(result).toBe(resolve('/project', 'src/components/Button'));
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('preserves paths without @/ alias', () => {
|
|
182
|
-
const result = resolveToRealPath('./foo/bar', '/project');
|
|
183
|
-
// resolve normalizes ./ away
|
|
184
|
-
expect(result).toBe(resolve('/project', 'foo/bar'));
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('resolves absolute paths correctly', () => {
|
|
188
|
-
const result = resolveToRealPath('/absolute/path', '/project');
|
|
189
|
-
// Absolute paths remain absolute (resolve treats them as-is)
|
|
190
|
-
expect(result).toBe(resolve('/absolute/path'));
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// ---------------------------------------------------------------------------
|
|
195
|
-
// loadExternalDependencies
|
|
196
|
-
// ---------------------------------------------------------------------------
|
|
197
|
-
describe('loadExternalDependencies', () => {
|
|
198
|
-
let tmpDir: string;
|
|
199
|
-
let tmpCounter = 0;
|
|
200
|
-
|
|
201
|
-
beforeEach(() => {
|
|
202
|
-
// Monotonic counter avoids Date.now() collisions when tests run fast
|
|
203
|
-
tmpCounter += 1;
|
|
204
|
-
tmpDir = join(tmpdir(), `scope-scanner-test-${process.pid}-${tmpCounter}`);
|
|
205
|
-
mkdirSync(tmpDir, { recursive: true });
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
afterEach(() => {
|
|
209
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('returns empty array when no package.json', async () => {
|
|
213
|
-
const deps = await loadExternalDependencies(tmpDir);
|
|
214
|
-
expect(deps).toEqual([]);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('reads dependencies from package.json', async () => {
|
|
218
|
-
writeFileSync(
|
|
219
|
-
join(tmpDir, 'package.json'),
|
|
220
|
-
JSON.stringify({
|
|
221
|
-
dependencies: {
|
|
222
|
-
react: '^18.0.0',
|
|
223
|
-
lodash: '^4.17.21',
|
|
224
|
-
},
|
|
225
|
-
}),
|
|
226
|
-
);
|
|
227
|
-
const deps = await loadExternalDependencies(tmpDir);
|
|
228
|
-
expect(deps).toEqual(['lodash', 'react']);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('includes devDependencies and peerDependencies', async () => {
|
|
232
|
-
writeFileSync(
|
|
233
|
-
join(tmpDir, 'package.json'),
|
|
234
|
-
JSON.stringify({
|
|
235
|
-
dependencies: { react: '^18.0.0' },
|
|
236
|
-
devDependencies: { vitest: '^1.0.0' },
|
|
237
|
-
peerDependencies: { react: '^18.0.0' },
|
|
238
|
-
}),
|
|
239
|
-
);
|
|
240
|
-
const deps = await loadExternalDependencies(tmpDir);
|
|
241
|
-
expect(deps).toEqual(['react', 'vitest']);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('skips workspace:* protocol packages', async () => {
|
|
245
|
-
writeFileSync(
|
|
246
|
-
join(tmpDir, 'package.json'),
|
|
247
|
-
JSON.stringify({
|
|
248
|
-
dependencies: {
|
|
249
|
-
react: '^18.0.0',
|
|
250
|
-
'my-lib': 'workspace:*',
|
|
251
|
-
'other-lib': 'workspace:^1.0.0',
|
|
252
|
-
},
|
|
253
|
-
}),
|
|
254
|
-
);
|
|
255
|
-
const deps = await loadExternalDependencies(tmpDir);
|
|
256
|
-
expect(deps).toEqual(['react']);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('handles invalid package.json gracefully', async () => {
|
|
260
|
-
writeFileSync(join(tmpDir, 'package.json'), 'not-json');
|
|
261
|
-
const deps = await loadExternalDependencies(tmpDir);
|
|
262
|
-
expect(deps).toEqual([]);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('handles empty package.json gracefully', async () => {
|
|
266
|
-
writeFileSync(join(tmpDir, 'package.json'), '{}');
|
|
267
|
-
const deps = await loadExternalDependencies(tmpDir);
|
|
268
|
-
expect(deps).toEqual([]);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it('returns sorted package names', async () => {
|
|
272
|
-
writeFileSync(
|
|
273
|
-
join(tmpDir, 'package.json'),
|
|
274
|
-
JSON.stringify({
|
|
275
|
-
dependencies: {
|
|
276
|
-
zod: '^3.0.0',
|
|
277
|
-
axios: '^1.0.0',
|
|
278
|
-
},
|
|
279
|
-
}),
|
|
280
|
-
);
|
|
281
|
-
const deps = await loadExternalDependencies(tmpDir);
|
|
282
|
-
expect(deps).toEqual(['axios', 'zod']);
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// ---------------------------------------------------------------------------
|
|
287
|
-
// classifyDependency
|
|
288
|
-
// ---------------------------------------------------------------------------
|
|
289
|
-
describe('classifyDependency', () => {
|
|
290
|
-
const baseScope: ProjectScope = {
|
|
291
|
-
implementedModules: ['@/components/Button', '@/utils/format'],
|
|
292
|
-
unimplementedModules: ['@/components/FutureComponent', '@/utils/pendingUtil'],
|
|
293
|
-
externalPackages: ['react', 'lodash', '@scope/package'],
|
|
294
|
-
projectBoundary: ['@/components/**', '@/utils/**'],
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
const baseOptions: ScanOptions = {
|
|
298
|
-
projectRoot: '/fake/project',
|
|
299
|
-
imports: [],
|
|
300
|
-
boundary: ['@/components/**', '@/utils/**'],
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
it('classifies implemented modules as internal', () => {
|
|
304
|
-
expect(classifyDependency('@/components/Button', baseScope, baseOptions)).toBe('internal');
|
|
305
|
-
expect(classifyDependency('@/utils/format', baseScope, baseOptions)).toBe('internal');
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('classifies unimplemented modules as pending', () => {
|
|
309
|
-
expect(classifyDependency('@/components/FutureComponent', baseScope, baseOptions)).toBe('pending');
|
|
310
|
-
expect(classifyDependency('@/utils/pendingUtil', baseScope, baseOptions)).toBe('pending');
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it('classifies known external packages as external', () => {
|
|
314
|
-
expect(classifyDependency('react', baseScope, baseOptions)).toBe('external');
|
|
315
|
-
expect(classifyDependency('lodash', baseScope, baseOptions)).toBe('external');
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
it('classifies scoped external packages as external', () => {
|
|
319
|
-
expect(classifyDependency('@scope/package', baseScope, baseOptions)).toBe('external');
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it('classifies sub-path of external packages as external', () => {
|
|
323
|
-
expect(classifyDependency('react/dom', baseScope, baseOptions)).toBe('external');
|
|
324
|
-
expect(classifyDependency('lodash/map', baseScope, baseOptions)).toBe('external');
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it('returns external for Node.js builtins', () => {
|
|
328
|
-
expect(classifyDependency('fs', baseScope, baseOptions)).toBe('external');
|
|
329
|
-
expect(classifyDependency('path', baseScope, baseOptions)).toBe('external');
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it('uses existCache when provided', () => {
|
|
333
|
-
const cache = new Map<string, boolean>();
|
|
334
|
-
// Cache key must match the resolved path that classifyDependency computes internally
|
|
335
|
-
cache.set(resolveToRealPath('@/foo', '/fake/project'), true);
|
|
336
|
-
|
|
337
|
-
const result = classifyDependency('@/foo', baseScope, {
|
|
338
|
-
...baseOptions,
|
|
339
|
-
boundary: ['@/**'],
|
|
340
|
-
}, cache);
|
|
341
|
-
|
|
342
|
-
expect(result).toBe('internal');
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
it('classifies non-existent boundary path as pending', () => {
|
|
346
|
-
const cache = new Map<string, boolean>();
|
|
347
|
-
cache.set('/fake/project/src/missing/helper', false);
|
|
348
|
-
|
|
349
|
-
const result = classifyDependency('@/missing/helper', baseScope, {
|
|
350
|
-
...baseOptions,
|
|
351
|
-
boundary: ['@/missing/**'],
|
|
352
|
-
}, cache);
|
|
353
|
-
|
|
354
|
-
expect(result).toBe('pending');
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
it('classifies unknown bare import as external', () => {
|
|
358
|
-
expect(classifyDependency('unknown-pkg', baseScope, baseOptions)).toBe('external');
|
|
359
|
-
});
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
// ---------------------------------------------------------------------------
|
|
363
|
-
// scanProjectScope (integration-level tests with real tmp dir)
|
|
364
|
-
// ---------------------------------------------------------------------------
|
|
365
|
-
describe('scanProjectScope', () => {
|
|
366
|
-
let tmpDir: string;
|
|
367
|
-
let tmpCounter = 0;
|
|
368
|
-
|
|
369
|
-
beforeEach(() => {
|
|
370
|
-
// Monotonic counter avoids Date.now() collisions when tests run fast
|
|
371
|
-
tmpCounter += 1;
|
|
372
|
-
tmpDir = join(tmpdir(), `scope-scanner-integration-${process.pid}-${tmpCounter}`);
|
|
373
|
-
mkdirSync(tmpDir, { recursive: true });
|
|
374
|
-
|
|
375
|
-
// Create a real project structure
|
|
376
|
-
mkdirSync(join(tmpDir, 'src'), { recursive: true });
|
|
377
|
-
mkdirSync(join(tmpDir, 'src', 'components'), { recursive: true });
|
|
378
|
-
mkdirSync(join(tmpDir, 'src', 'utils'), { recursive: true });
|
|
379
|
-
|
|
380
|
-
// Create some files that exist
|
|
381
|
-
writeFileSync(join(tmpDir, 'src', 'components', 'Button.ts'), '');
|
|
382
|
-
writeFileSync(join(tmpDir, 'src', 'utils', 'format.ts'), '');
|
|
383
|
-
writeFileSync(join(tmpDir, 'src', 'index.ts'), '');
|
|
384
|
-
|
|
385
|
-
// package.json with some dependencies
|
|
386
|
-
writeFileSync(
|
|
387
|
-
join(tmpDir, 'package.json'),
|
|
388
|
-
JSON.stringify({
|
|
389
|
-
dependencies: {
|
|
390
|
-
react: '^18.0.0',
|
|
391
|
-
lodash: '^4.17.21',
|
|
392
|
-
},
|
|
393
|
-
devDependencies: {
|
|
394
|
-
vitest: '^1.0.0',
|
|
395
|
-
},
|
|
396
|
-
}),
|
|
397
|
-
);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
afterEach(() => {
|
|
401
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
it('classifies existing src files as implemented', async () => {
|
|
405
|
-
const result = await scanProjectScope({
|
|
406
|
-
projectRoot: tmpDir,
|
|
407
|
-
imports: ['./src/components/Button.ts', './src/utils/format.ts'],
|
|
408
|
-
boundary: [],
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
expect(result.implementedModules).toContain('./src/components/Button.ts');
|
|
412
|
-
expect(result.implementedModules).toContain('./src/utils/format.ts');
|
|
413
|
-
expect(result.unimplementedModules).toEqual([]);
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
it('classifies non-existent files as unimplemented', async () => {
|
|
417
|
-
const result = await scanProjectScope({
|
|
418
|
-
projectRoot: tmpDir,
|
|
419
|
-
imports: ['./src/missing.ts'],
|
|
420
|
-
boundary: [],
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
expect(result.implementedModules).toEqual([]);
|
|
424
|
-
expect(result.unimplementedModules).toContain('./src/missing.ts');
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
it('classifies external npm packages', async () => {
|
|
428
|
-
const result = await scanProjectScope({
|
|
429
|
-
projectRoot: tmpDir,
|
|
430
|
-
imports: ['react', 'lodash', 'vitest'],
|
|
431
|
-
boundary: [],
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
expect(result.externalPackages).toContain('react');
|
|
435
|
-
expect(result.externalPackages).toContain('lodash');
|
|
436
|
-
expect(result.externalPackages).toContain('vitest');
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
it('classifies Node.js builtins as external', async () => {
|
|
440
|
-
const result = await scanProjectScope({
|
|
441
|
-
projectRoot: tmpDir,
|
|
442
|
-
imports: ['fs', 'path', 'os'],
|
|
443
|
-
boundary: [],
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
expect(result.externalPackages).toContain('fs');
|
|
447
|
-
expect(result.externalPackages).toContain('path');
|
|
448
|
-
expect(result.externalPackages).toContain('os');
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
it('handles @/ alias resolution', async () => {
|
|
452
|
-
const result = await scanProjectScope({
|
|
453
|
-
projectRoot: tmpDir,
|
|
454
|
-
imports: ['@/components/Button.ts', '@/utils/format.ts'],
|
|
455
|
-
boundary: [],
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
expect(result.implementedModules).toContain('@/components/Button.ts');
|
|
459
|
-
expect(result.implementedModules).toContain('@/utils/format.ts');
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
it('classifies boundary-matching imports as implemented', async () => {
|
|
463
|
-
const result = await scanProjectScope({
|
|
464
|
-
projectRoot: tmpDir,
|
|
465
|
-
imports: ['@/components/Button.ts'],
|
|
466
|
-
boundary: ['@/components/**'],
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
expect(result.implementedModules).toContain('@/components/Button.ts');
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
it('removes duplicate entries from results', async () => {
|
|
473
|
-
const result = await scanProjectScope({
|
|
474
|
-
projectRoot: tmpDir,
|
|
475
|
-
imports: ['./src/index.ts', './src/index.ts', './src/index.ts'],
|
|
476
|
-
boundary: [],
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
expect(result.implementedModules).toEqual(['./src/index.ts']);
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
it('stores projectBoundary in result', async () => {
|
|
483
|
-
const boundary = ['@/components/**', '@/utils/**'];
|
|
484
|
-
const result = await scanProjectScope({
|
|
485
|
-
projectRoot: tmpDir,
|
|
486
|
-
imports: [],
|
|
487
|
-
boundary,
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
expect(result.projectBoundary).toEqual(boundary);
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
it('classifies mixed imports correctly', async () => {
|
|
494
|
-
const result = await scanProjectScope({
|
|
495
|
-
projectRoot: tmpDir,
|
|
496
|
-
imports: [
|
|
497
|
-
// External
|
|
498
|
-
'react',
|
|
499
|
-
'lodash',
|
|
500
|
-
'fs',
|
|
501
|
-
// Implemented
|
|
502
|
-
'./src/components/Button.ts',
|
|
503
|
-
'@/utils/format.ts',
|
|
504
|
-
// Unimplemented
|
|
505
|
-
'./src/missing.ts',
|
|
506
|
-
'@/components/NonExistent.ts',
|
|
507
|
-
],
|
|
508
|
-
boundary: ['@/components/**', '@/utils/**'],
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
expect(result.externalPackages).toContain('react');
|
|
512
|
-
expect(result.externalPackages).toContain('lodash');
|
|
513
|
-
expect(result.externalPackages).toContain('fs');
|
|
514
|
-
|
|
515
|
-
expect(result.implementedModules).toContain('./src/components/Button.ts');
|
|
516
|
-
expect(result.implementedModules).toContain('@/utils/format.ts');
|
|
517
|
-
|
|
518
|
-
expect(result.unimplementedModules).toContain('./src/missing.ts');
|
|
519
|
-
expect(result.unimplementedModules).toContain('@/components/NonExistent.ts');
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
it('handles @scope/npm-package bare imports', async () => {
|
|
523
|
-
// Add a scoped package to package.json
|
|
524
|
-
writeFileSync(
|
|
525
|
-
join(tmpDir, 'package.json'),
|
|
526
|
-
JSON.stringify({
|
|
527
|
-
dependencies: {
|
|
528
|
-
'@scope/package': '^1.0.0',
|
|
529
|
-
},
|
|
530
|
-
}),
|
|
531
|
-
);
|
|
532
|
-
|
|
533
|
-
const result = await scanProjectScope({
|
|
534
|
-
projectRoot: tmpDir,
|
|
535
|
-
imports: ['@scope/package'],
|
|
536
|
-
boundary: [],
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
expect(result.externalPackages).toContain('@scope/package');
|
|
540
|
-
});
|
|
541
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test detect-ai-test.ts - AI-generated test detection
|
|
3
|
-
* @intent Verify mock density and annotation detection work correctly
|
|
4
|
-
* @covers REQ-MUT-001 AC-003 (mock density heuristic)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
8
|
-
import fs from 'fs/promises';
|
|
9
|
-
import { detectAITestCharacteristics, detectTestLayer } from '../detect-ai-test';
|
|
10
|
-
|
|
11
|
-
vi.mock('fs/promises');
|
|
12
|
-
|
|
13
|
-
describe('detect-ai-test.ts - AI Test Detection', () => {
|
|
14
|
-
describe('detectTestLayer', () => {
|
|
15
|
-
it('should return unit for __tests__ paths', () => {
|
|
16
|
-
expect(detectTestLayer('src/__tests__/user.test.ts')).toBe('unit');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should return e2e for .e2e. paths', () => {
|
|
20
|
-
expect(detectTestLayer('src/e2e/login.e2e.test.ts')).toBe('e2e');
|
|
21
|
-
expect(detectTestLayer('src/e2e/api.test.ts')).toBe('e2e');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should return integration for .integration. paths', () => {
|
|
25
|
-
expect(detectTestLayer('src/integration/user.integration.test.ts')).toBe('integration');
|
|
26
|
-
expect(detectTestLayer('src/integration/db.test.ts')).toBe('integration');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should return unit for .test. and .spec. paths', () => {
|
|
30
|
-
expect(detectTestLayer('src/services/user.test.ts')).toBe('unit');
|
|
31
|
-
expect(detectTestLayer('src/services/user.spec.ts')).toBe('unit');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should return unknown for non-test paths', () => {
|
|
35
|
-
expect(detectTestLayer('src/services/user.ts')).toBe('unknown');
|
|
36
|
-
expect(detectTestLayer('README.md')).toBe('unknown');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should prioritize e2e over other patterns', () => {
|
|
40
|
-
expect(detectTestLayer('src/__tests__/login.e2e.test.ts')).toBe('e2e');
|
|
41
|
-
expect(detectTestLayer('src/integration/user.e2e.test.ts')).toBe('e2e');
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('detectAITestCharacteristics', () => {
|
|
46
|
-
it('should return isAiGenerated=true when mock density > 30%', async () => {
|
|
47
|
-
const mockContent = `
|
|
48
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
49
|
-
|
|
50
|
-
describe('UserService', () => {
|
|
51
|
-
it('should return user when valid id', async () => {
|
|
52
|
-
const mockFn = vi.fn();
|
|
53
|
-
const mockResolve = vi.mockResolvedValue({ id: '1', name: 'Test' });
|
|
54
|
-
const mockReturn = vi.mockReturnValue({ id: '1', name: 'Test' });
|
|
55
|
-
const mockRej = vi.mockRejectedValue(new Error('fail'));
|
|
56
|
-
const mockImpl = vi.mockImplementation(() => ({ id: '1' }));
|
|
57
|
-
const spy = vi.spyOn(obj, 'method');
|
|
58
|
-
const mock = vi.mock('module', () => ({ fn: vi.fn() }));
|
|
59
|
-
const mReset = vi.mockReset();
|
|
60
|
-
const mClear = vi.mockClear();
|
|
61
|
-
const mRestore = vi.mockRestore();
|
|
62
|
-
|
|
63
|
-
await expect(service.getUser('1')).resolves.toEqual({ id: '1', name: 'Test' });
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
`;
|
|
67
|
-
|
|
68
|
-
vi.mocked(fs.readFile).mockResolvedValue(mockContent);
|
|
69
|
-
|
|
70
|
-
const result = await detectAITestCharacteristics('src/__tests__/user.test.ts');
|
|
71
|
-
|
|
72
|
-
expect(result.isAiGenerated).toBe(true);
|
|
73
|
-
expect(result.mockDensity).toBeGreaterThan(30);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should return isAiGenerated=false when mock density <= 30%', async () => {
|
|
77
|
-
const mockContent = `
|
|
78
|
-
import { describe, it, expect } from 'vitest';
|
|
79
|
-
|
|
80
|
-
describe('Calculator', () => {
|
|
81
|
-
it('should add two numbers', () => {
|
|
82
|
-
expect(1 + 1).toBe(2);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
`;
|
|
86
|
-
|
|
87
|
-
vi.mocked(fs.readFile).mockResolvedValue(mockContent);
|
|
88
|
-
|
|
89
|
-
const result = await detectAITestCharacteristics('src/__tests__/calc.test.ts');
|
|
90
|
-
|
|
91
|
-
expect(result.isAiGenerated).toBe(false);
|
|
92
|
-
expect(result.mockDensity).toBeLessThanOrEqual(30);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should detect @mutation-threshold annotation', async () => {
|
|
96
|
-
const mockContent = `
|
|
97
|
-
/**
|
|
98
|
-
* @test Calculator
|
|
99
|
-
* @mutation-threshold: 70
|
|
100
|
-
*/
|
|
101
|
-
import { describe, it, expect } from 'vitest';
|
|
102
|
-
|
|
103
|
-
describe('Calculator', () => {
|
|
104
|
-
it('should add two numbers', () => {
|
|
105
|
-
expect(1 + 1).toBe(2);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
`;
|
|
109
|
-
|
|
110
|
-
vi.mocked(fs.readFile).mockResolvedValue(mockContent);
|
|
111
|
-
|
|
112
|
-
const result = await detectAITestCharacteristics('src/__tests__/calc.test.ts');
|
|
113
|
-
|
|
114
|
-
expect(result.explicitThreshold).toBe(70);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should detect @test, @intent, @covers annotations', async () => {
|
|
118
|
-
const mockContent = `
|
|
119
|
-
/**
|
|
120
|
-
* @test Calculator
|
|
121
|
-
* @intent Verify basic arithmetic
|
|
122
|
-
* @covers AC-CALC-01
|
|
123
|
-
*/
|
|
124
|
-
import { describe, it, expect } from 'vitest';
|
|
125
|
-
|
|
126
|
-
describe('Calculator', () => {
|
|
127
|
-
it('should add two numbers', () => {
|
|
128
|
-
expect(1 + 1).toBe(2);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
`;
|
|
132
|
-
|
|
133
|
-
vi.mocked(fs.readFile).mockResolvedValue(mockContent);
|
|
134
|
-
|
|
135
|
-
const result = await detectAITestCharacteristics('src/__tests__/calc.test.ts');
|
|
136
|
-
|
|
137
|
-
expect(result.annotations.hasTest).toBe(true);
|
|
138
|
-
expect(result.annotations.hasIntent).toBe(true);
|
|
139
|
-
expect(result.annotations.hasCovers).toBe(true);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should return default result when file read fails', async () => {
|
|
143
|
-
vi.mocked(fs.readFile).mockRejectedValue(new Error('ENOENT'));
|
|
144
|
-
|
|
145
|
-
const result = await detectAITestCharacteristics('nonexistent.test.ts');
|
|
146
|
-
|
|
147
|
-
expect(result.isAiGenerated).toBe(false);
|
|
148
|
-
expect(result.mockDensity).toBe(0);
|
|
149
|
-
expect(result.annotations.hasTest).toBe(false);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|