@boyingliu01/xp-gate 0.38.76 → 0.38.78
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__/gate2-verdict.test.js +58 -1
- package/lib/__tests__/mirror-sync.test.js +387 -5
- package/lib/gate-runner.js +88 -9
- 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/sprint-flow/references/phase-2-design.md +62 -2
- 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/sprint-flow/references/phase-2-design.md +62 -2
- 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/sprint-flow/references/phase-2-design.md +62 -2
- 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/sprint-flow/references/phase-2-design.md +62 -2
- 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/sprint-flow/references/phase-2-design.md +62 -2
- 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,58 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { ispRule } from '../../solid/isp';
|
|
3
|
-
|
|
4
|
-
const mockAdapter = {
|
|
5
|
-
detectLanguage: () => 'typescript',
|
|
6
|
-
parseAST: () => undefined,
|
|
7
|
-
extractFunctions: () => [],
|
|
8
|
-
extractClasses: () => [],
|
|
9
|
-
countLines: () => 0
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
describe('isp.ts - Interface Segregation Principle Rule', () => {
|
|
13
|
-
it('should detect interface with too many methods (>10)', () => {
|
|
14
|
-
const mockAdapterWithFatInterface = {
|
|
15
|
-
...mockAdapter,
|
|
16
|
-
extractInterfaces: () => [{
|
|
17
|
-
name: 'FatInterface',
|
|
18
|
-
line: 1,
|
|
19
|
-
methodCount: 12
|
|
20
|
-
}]
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const violations = ispRule.check('test.ts', mockAdapterWithFatInterface as never);
|
|
24
|
-
|
|
25
|
-
expect(violations.length).toBeGreaterThan(0);
|
|
26
|
-
expect(violations[0].ruleId).toBe('solid.isp');
|
|
27
|
-
expect(violations[0].message).toContain('12');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should pass for focused interface', () => {
|
|
31
|
-
const mockAdapterWithFocusedInterface = {
|
|
32
|
-
...mockAdapter,
|
|
33
|
-
extractInterfaces: () => [{
|
|
34
|
-
name: 'ReaderInterface',
|
|
35
|
-
line: 1,
|
|
36
|
-
methodCount: 5
|
|
37
|
-
}]
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const violations = ispRule.check('test.ts', mockAdapterWithFocusedInterface as never);
|
|
41
|
-
|
|
42
|
-
expect(violations.length).toBe(0);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should use threshold from config', () => {
|
|
46
|
-
expect(ispRule.threshold).toBe(10);
|
|
47
|
-
expect(ispRule.severity).toBe('info');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should propagate adapter errors (no empty catch, #392)', () => {
|
|
51
|
-
const mockAdapterThatThrows = {
|
|
52
|
-
...mockAdapter,
|
|
53
|
-
extractInterfaces: () => { throw new Error('Adapter failed'); }
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
expect(() => ispRule.check('test.ts', mockAdapterThatThrows as never)).toThrow('Adapter failed');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test REQ-618
|
|
3
|
-
* @intent The LSP rule must still DETECT a real violation when the base contract is
|
|
4
|
-
* available in the same file, so that #588's "stay silent when undetermined" fix
|
|
5
|
-
* does not degenerate into "never report anything".
|
|
6
|
-
* @covers AC-618-04, AC-618-05
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect } from 'vitest';
|
|
9
|
-
import { lspRule } from '../../solid/lsp';
|
|
10
|
-
|
|
11
|
-
/** Adapter stub exposing exactly what the rule consumes. */
|
|
12
|
-
function adapterFor(classes: Array<{ name?: string; line?: number; code?: string }>) {
|
|
13
|
-
return {
|
|
14
|
-
detectLanguage: () => 'java',
|
|
15
|
-
parseAST: () => undefined,
|
|
16
|
-
extractFunctions: () => [],
|
|
17
|
-
extractClasses: () => classes,
|
|
18
|
-
countLines: () => 0,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A base class and a derived class in ONE file.
|
|
24
|
-
*
|
|
25
|
-
* `handle(DataSource ds)` is the base contract; the derived class may honour it or break
|
|
26
|
-
* it. Both classes are visible, so the rule has everything it needs to decide — which is
|
|
27
|
-
* exactly the case #588's fix must NOT silence.
|
|
28
|
-
*/
|
|
29
|
-
const BASE_WITH_ONE_PARAM = `
|
|
30
|
-
class BaseHandler {
|
|
31
|
-
public void handle(DataSource ds) { }
|
|
32
|
-
}
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
/** Line where the derived class starts in the two-class fixtures below. */
|
|
36
|
-
const DERIVED_CLASS_LINE = 4;
|
|
37
|
-
|
|
38
|
-
/** Line where the derived TypeScript class starts in the two-line-header fixtures. */
|
|
39
|
-
const TS_DERIVED_CLASS_LINE = 3;
|
|
40
|
-
|
|
41
|
-
describe('solid.lsp detects a violation when the base contract IS available', () => {
|
|
42
|
-
it('reports a derived parameter type the base method does not accept', () => {
|
|
43
|
-
const violations = lspRule.check('Handlers.java', adapterFor([
|
|
44
|
-
{ name: 'BaseHandler', line: 1, code: BASE_WITH_ONE_PARAM },
|
|
45
|
-
{
|
|
46
|
-
name: 'CsvHandler',
|
|
47
|
-
line: DERIVED_CLASS_LINE,
|
|
48
|
-
code: `class CsvHandler extends BaseHandler {
|
|
49
|
-
public void handle(FileChannel channel) { }
|
|
50
|
-
}`,
|
|
51
|
-
},
|
|
52
|
-
]) as never);
|
|
53
|
-
|
|
54
|
-
// The point of the whole rule: an override that narrows or changes the parameter type
|
|
55
|
-
// breaks substitutability, and here both sides are visible so the claim is earned.
|
|
56
|
-
expect(violations.length).toBeGreaterThan(0);
|
|
57
|
-
expect(violations[0].ruleId).toBe('solid.lsp');
|
|
58
|
-
expect(violations[0].message).toContain('FileChannel');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('stays silent when the override keeps the base parameter type', () => {
|
|
62
|
-
const violations = lspRule.check('Handlers.java', adapterFor([
|
|
63
|
-
{ name: 'BaseHandler', line: 1, code: BASE_WITH_ONE_PARAM },
|
|
64
|
-
{
|
|
65
|
-
name: 'CsvHandler',
|
|
66
|
-
line: DERIVED_CLASS_LINE,
|
|
67
|
-
code: `class CsvHandler extends BaseHandler {
|
|
68
|
-
public void handle(DataSource ds) { }
|
|
69
|
-
}`,
|
|
70
|
-
},
|
|
71
|
-
]) as never);
|
|
72
|
-
|
|
73
|
-
expect(violations).toHaveLength(0);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('stays silent when the base class is NOT in the file', () => {
|
|
77
|
-
// The control for the two cases above: same derived code, no base declaration
|
|
78
|
-
// available. Without this, a rule that simply reported every non-primitive parameter
|
|
79
|
-
// would pass the first case and fail only by accident elsewhere.
|
|
80
|
-
const violations = lspRule.check('Handlers.java', adapterFor([
|
|
81
|
-
{
|
|
82
|
-
name: 'CsvHandler',
|
|
83
|
-
line: 1,
|
|
84
|
-
code: `class CsvHandler extends BaseHandler {
|
|
85
|
-
public void handle(FileChannel channel) { }
|
|
86
|
-
}`,
|
|
87
|
-
},
|
|
88
|
-
]) as never);
|
|
89
|
-
|
|
90
|
-
expect(violations).toHaveLength(0);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('stays silent when the base method itself is not declared', () => {
|
|
94
|
-
// Base visible, but it does not declare `handle` at all — an inherited method from
|
|
95
|
-
// further up, which this analysis cannot see. Not a violation, not verifiable.
|
|
96
|
-
const baseWithoutHandle = `class BaseHandler { public void close() { } }`;
|
|
97
|
-
const violations = lspRule.check('Handlers.java', adapterFor([
|
|
98
|
-
{ name: 'BaseHandler', line: 1, code: baseWithoutHandle },
|
|
99
|
-
{
|
|
100
|
-
name: 'CsvHandler',
|
|
101
|
-
line: 2,
|
|
102
|
-
code: `class CsvHandler extends BaseHandler {
|
|
103
|
-
public void handle(FileChannel channel) { }
|
|
104
|
-
}`,
|
|
105
|
-
},
|
|
106
|
-
]) as never);
|
|
107
|
-
|
|
108
|
-
expect(violations).toHaveLength(0);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('resolves a base class referenced through a qualified name', () => {
|
|
112
|
-
// `extends com.acme.BaseHandler` is ordinary Java; a plain string compare would miss
|
|
113
|
-
// the base and silently downgrade a decidable case to silence.
|
|
114
|
-
const violations = lspRule.check('Handlers.java', adapterFor([
|
|
115
|
-
{ name: 'BaseHandler', line: 1, code: BASE_WITH_ONE_PARAM },
|
|
116
|
-
{
|
|
117
|
-
name: 'CsvHandler',
|
|
118
|
-
line: 2,
|
|
119
|
-
code: `class CsvHandler extends com.acme.BaseHandler {
|
|
120
|
-
public void handle(FileChannel channel) { }
|
|
121
|
-
}`,
|
|
122
|
-
},
|
|
123
|
-
]) as never);
|
|
124
|
-
|
|
125
|
-
expect(violations.length).toBeGreaterThan(0);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('treats a parameter type the base method also declares as compatible', () => {
|
|
129
|
-
// The positive half of the base comparison: this is the branch that returns `true`,
|
|
130
|
-
// i.e. "I have a base contract AND it accepts this type". Without it the only
|
|
131
|
-
// observable outcome of the base path would be a violation, and a rule that reported
|
|
132
|
-
// every override with a resolvable base would still pass every other case here.
|
|
133
|
-
const base = `class BaseHandler { public void handle(DataSource ds) { } }`;
|
|
134
|
-
const violations = lspRule.check('Handlers.java', adapterFor([
|
|
135
|
-
{ name: 'BaseHandler', line: 1, code: base },
|
|
136
|
-
{
|
|
137
|
-
name: 'CsvHandler',
|
|
138
|
-
line: 2,
|
|
139
|
-
code: `class CsvHandler extends BaseHandler {
|
|
140
|
-
public void handle(DataSource ds) { }
|
|
141
|
-
}`,
|
|
142
|
-
},
|
|
143
|
-
]) as never);
|
|
144
|
-
|
|
145
|
-
expect(violations).toHaveLength(0);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('handles a generic and an array parameter type without crashing', () => {
|
|
149
|
-
// Exercises `normaliseTypeName`'s stripping of `<...>`, `[]` and `?`. Those suffixes
|
|
150
|
-
// are the reason `Map<String, Item>` does not get compared as the literal string
|
|
151
|
-
// "Map<String, Item>", and the array/optional forms are ordinary in both languages.
|
|
152
|
-
const base = `class BaseHandler { public void handle(Map<String, Item> index) { } }`;
|
|
153
|
-
const violations = lspRule.check('Handlers.java', adapterFor([
|
|
154
|
-
{ name: 'BaseHandler', line: 1, code: base },
|
|
155
|
-
{
|
|
156
|
-
name: 'CsvHandler',
|
|
157
|
-
line: 2,
|
|
158
|
-
code: `class CsvHandler extends BaseHandler {
|
|
159
|
-
public void handle(Map<String, Item> index) { }
|
|
160
|
-
}`,
|
|
161
|
-
},
|
|
162
|
-
]) as never);
|
|
163
|
-
|
|
164
|
-
expect(violations).toHaveLength(0);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('reads TypeScript `name: Type` parameters, not Java ones', () => {
|
|
168
|
-
// Every other case here runs the Java path. The rule is shared by both languages, and
|
|
169
|
-
// #588's whole lesson is that a parser which only works for one of them silently
|
|
170
|
-
// mangles the other — so the TypeScript path needs its own case, exercising
|
|
171
|
-
// `extractTsParamType` rather than `extractJavaParamType`.
|
|
172
|
-
const tsAdapter = { ...adapterFor([]), detectLanguage: () => 'typescript' };
|
|
173
|
-
const base = `class BaseHandler {
|
|
174
|
-
handle(ds: DataSource): void {}
|
|
175
|
-
}`;
|
|
176
|
-
const derived = `class CsvHandler extends BaseHandler {
|
|
177
|
-
handle(channel: FileChannel): void {}
|
|
178
|
-
}`;
|
|
179
|
-
const violations = lspRule.check('handlers.ts', {
|
|
180
|
-
...tsAdapter,
|
|
181
|
-
extractClasses: () => [
|
|
182
|
-
{ name: 'BaseHandler', line: 1, code: base },
|
|
183
|
-
{ name: 'CsvHandler', line: TS_DERIVED_CLASS_LINE, code: derived },
|
|
184
|
-
],
|
|
185
|
-
} as never);
|
|
186
|
-
|
|
187
|
-
expect(violations.length).toBeGreaterThan(0);
|
|
188
|
-
expect(violations[0].message).toContain('FileChannel');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('stays silent for a TypeScript override that matches the base', () => {
|
|
192
|
-
const tsAdapter = { ...adapterFor([]), detectLanguage: () => 'typescript' };
|
|
193
|
-
const base = `class BaseHandler {
|
|
194
|
-
handle(ds: DataSource): void {}
|
|
195
|
-
}`;
|
|
196
|
-
const derived = `class CsvHandler extends BaseHandler {
|
|
197
|
-
handle(ds: DataSource): void {}
|
|
198
|
-
}`;
|
|
199
|
-
const violations = lspRule.check('handlers.ts', {
|
|
200
|
-
...tsAdapter,
|
|
201
|
-
extractClasses: () => [
|
|
202
|
-
{ name: 'BaseHandler', line: 1, code: base },
|
|
203
|
-
{ name: 'CsvHandler', line: TS_DERIVED_CLASS_LINE, code: derived },
|
|
204
|
-
],
|
|
205
|
-
} as never);
|
|
206
|
-
|
|
207
|
-
expect(violations).toHaveLength(0);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('treats an adapter without detectLanguage as non-Java rather than crashing', () => {
|
|
211
|
-
// Older or third-party adapters may not implement `detectLanguage`. The rule must
|
|
212
|
-
// fall back to the `name: Type` reading instead of throwing on an absent method —
|
|
213
|
-
// a crash here would surface as a Gate 4 rule error, not as silence.
|
|
214
|
-
const adapterWithoutLanguage = {
|
|
215
|
-
parseAST: () => undefined,
|
|
216
|
-
extractFunctions: () => [],
|
|
217
|
-
countLines: () => 0,
|
|
218
|
-
extractClasses: () => [
|
|
219
|
-
{ name: 'BaseHandler', line: 1, code: `class BaseHandler {\n handle(ds: DataSource): void {}\n}` },
|
|
220
|
-
{
|
|
221
|
-
name: 'CsvHandler',
|
|
222
|
-
line: TS_DERIVED_CLASS_LINE,
|
|
223
|
-
code: `class CsvHandler extends BaseHandler {\n handle(channel: FileChannel): void {}\n}`,
|
|
224
|
-
},
|
|
225
|
-
],
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const violations = lspRule.check('handlers.ts', adapterWithoutLanguage as never);
|
|
229
|
-
|
|
230
|
-
expect(violations.length).toBeGreaterThan(0);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('ignores a TypeScript parameter with no type annotation', () => {
|
|
234
|
-
// `handle(id)` has no `: Type`, so `extractTsParamType` returns null and the parameter
|
|
235
|
-
// contributes nothing. Without this the missing-annotation path is untested after the
|
|
236
|
-
// #588 rewrite, and a regex change could start inventing types out of parameter names.
|
|
237
|
-
const tsAdapter = {
|
|
238
|
-
...adapterFor([]),
|
|
239
|
-
detectLanguage: () => 'typescript',
|
|
240
|
-
extractClasses: () => [
|
|
241
|
-
{ name: 'BaseHandler', line: 1, code: `class BaseHandler {\n handle(id): void {}\n}` },
|
|
242
|
-
{
|
|
243
|
-
name: 'CsvHandler',
|
|
244
|
-
line: TS_DERIVED_CLASS_LINE,
|
|
245
|
-
code: `class CsvHandler extends BaseHandler {\n handle(id): void {}\n}`,
|
|
246
|
-
},
|
|
247
|
-
],
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
expect(lspRule.check('handlers.ts', tsAdapter as never)).toHaveLength(0);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { lspRule, buildViolation } from '../../solid/lsp';
|
|
3
|
-
|
|
4
|
-
const mockAdapter = {
|
|
5
|
-
detectLanguage: () => 'typescript',
|
|
6
|
-
parseAST: () => undefined,
|
|
7
|
-
extractFunctions: () => [],
|
|
8
|
-
extractClasses: () => [],
|
|
9
|
-
countLines: () => 0
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
describe('lsp.ts - Liskov Substitution Principle Rule', () => {
|
|
13
|
-
it('stays silent on a parameter type it cannot resolve against the base contract', () => {
|
|
14
|
-
// #588 changed what this rule is allowed to claim. `UserId` is neither a primitive nor
|
|
15
|
-
// a prefix of the class name, so a single-file analysis has no way to know what the
|
|
16
|
-
// BASE class declares — and "cannot determine" must not be reported as a violation.
|
|
17
|
-
// The previous expectation here asserted the defect: it read an unknown type as proof
|
|
18
|
-
// of incompatibility, which on Java flagged every class that has `extends`.
|
|
19
|
-
const mockAdapterWithViolation = {
|
|
20
|
-
...mockAdapter,
|
|
21
|
-
extractClasses: () => [{
|
|
22
|
-
name: 'DerivedRepo',
|
|
23
|
-
line: 1,
|
|
24
|
-
code: `class DerivedRepo extends BaseRepo { findById(id: UserId): Entity {} }`
|
|
25
|
-
}]
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const violations = lspRule.check('test.ts', mockAdapterWithViolation as never);
|
|
29
|
-
|
|
30
|
-
expect(violations).toHaveLength(0);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should pass for proper override', () => {
|
|
34
|
-
const mockAdapterWithProperOverride = {
|
|
35
|
-
...mockAdapter,
|
|
36
|
-
extractClasses: () => [{
|
|
37
|
-
name: 'DerivedRepo',
|
|
38
|
-
line: 1,
|
|
39
|
-
code: `
|
|
40
|
-
class DerivedRepo extends BaseRepo {
|
|
41
|
-
findById(id: string): Entity | null {}
|
|
42
|
-
}
|
|
43
|
-
`
|
|
44
|
-
}]
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const violations = lspRule.check('test.ts', mockAdapterWithProperOverride as never);
|
|
48
|
-
|
|
49
|
-
expect(violations.length).toBe(0);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should use severity from config', () => {
|
|
53
|
-
expect(lspRule.severity).toBe('info');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should propagate adapter errors (no empty catch, #392)', () => {
|
|
57
|
-
const mockAdapterThatThrows = {
|
|
58
|
-
...mockAdapter,
|
|
59
|
-
extractClasses: () => { throw new Error('Adapter failed'); }
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
expect(() => lspRule.check('test.ts', mockAdapterThatThrows as never)).toThrow('Adapter failed');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @test REQ-174 Branch coverage for lsp rule
|
|
67
|
-
* @intent Cover uncovered branches: missing class.code, no extends keyword,
|
|
68
|
-
* non-class extractClasses returning null, params without ':',
|
|
69
|
-
* params with ':' but no type word, cls.line missing fallback,
|
|
70
|
-
* className startsWith paramType branch.
|
|
71
|
-
* @covers AC-174-05, AC-174-06, AC-174-07
|
|
72
|
-
*/
|
|
73
|
-
it('returns no violations when extractClasses returns null (|| [] branch)', () => {
|
|
74
|
-
const adapter = {
|
|
75
|
-
...mockAdapter,
|
|
76
|
-
extractClasses: () => null as unknown as never[],
|
|
77
|
-
};
|
|
78
|
-
const violations = lspRule.check('test.ts', adapter as never);
|
|
79
|
-
expect(violations).toHaveLength(0);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('returns no violations when class has no code property', () => {
|
|
83
|
-
const adapter = {
|
|
84
|
-
...mockAdapter,
|
|
85
|
-
extractClasses: () => [{ name: 'X', line: 1 }],
|
|
86
|
-
};
|
|
87
|
-
const violations = lspRule.check('test.ts', adapter as never);
|
|
88
|
-
expect(violations).toHaveLength(0);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('returns no violations when class does not extend anything', () => {
|
|
92
|
-
const adapter = {
|
|
93
|
-
...mockAdapter,
|
|
94
|
-
extractClasses: () => [{
|
|
95
|
-
name: 'Plain',
|
|
96
|
-
line: 1,
|
|
97
|
-
code: `class Plain { method(id: Foo) {} }`,
|
|
98
|
-
}],
|
|
99
|
-
};
|
|
100
|
-
const violations = lspRule.check('test.ts', adapter as never);
|
|
101
|
-
expect(violations).toHaveLength(0);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('ignores params with no type annotation (no colon branch)', () => {
|
|
105
|
-
// foo(id) — no colon → extractParamType returns null
|
|
106
|
-
const adapter = {
|
|
107
|
-
...mockAdapter,
|
|
108
|
-
extractClasses: () => [{
|
|
109
|
-
name: 'D',
|
|
110
|
-
line: 1,
|
|
111
|
-
code: `class D extends B { foo(id) {} }`,
|
|
112
|
-
}],
|
|
113
|
-
};
|
|
114
|
-
const violations = lspRule.check('test.ts', adapter as never);
|
|
115
|
-
expect(violations).toHaveLength(0);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('ignores params with colon but no matchable type word', () => {
|
|
119
|
-
// foo(id: ) — colon present but typeMatch fails → returns null
|
|
120
|
-
const adapter = {
|
|
121
|
-
...mockAdapter,
|
|
122
|
-
extractClasses: () => [{
|
|
123
|
-
name: 'D',
|
|
124
|
-
line: 1,
|
|
125
|
-
code: `class D extends B { foo(id: ) {} }`,
|
|
126
|
-
}],
|
|
127
|
-
};
|
|
128
|
-
const violations = lspRule.check('test.ts', adapter as never);
|
|
129
|
-
expect(violations).toHaveLength(0);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('treats primitive parameter types as compatible', () => {
|
|
133
|
-
const adapter = {
|
|
134
|
-
...mockAdapter,
|
|
135
|
-
extractClasses: () => [{
|
|
136
|
-
name: 'D',
|
|
137
|
-
line: 1,
|
|
138
|
-
code: `class D extends B { foo(s: string, n: number, b: boolean, a: any, v: void, x: Object) {} }`,
|
|
139
|
-
}],
|
|
140
|
-
};
|
|
141
|
-
const violations = lspRule.check('test.ts', adapter as never);
|
|
142
|
-
expect(violations).toHaveLength(0);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('treats parameter types that start with className as compatible', () => {
|
|
146
|
-
// className = 'User', paramType = 'UserId' (startsWith match)
|
|
147
|
-
const adapter = {
|
|
148
|
-
...mockAdapter,
|
|
149
|
-
extractClasses: () => [{
|
|
150
|
-
name: 'User',
|
|
151
|
-
line: 1,
|
|
152
|
-
code: `class User extends Base { findById(id: UserId) {} }`,
|
|
153
|
-
}],
|
|
154
|
-
};
|
|
155
|
-
const violations = lspRule.check('test.ts', adapter as never);
|
|
156
|
-
expect(violations).toHaveLength(0);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('stays silent even when the class name is missing (no name is not evidence)', () => {
|
|
160
|
-
// This used to report, on the reasoning that `className && ...` short-circuits to
|
|
161
|
-
// false. Under #588 that is precisely the defect: an ABSENT name is one more thing the
|
|
162
|
-
// analysis does not know, so it cannot justify a verdict.
|
|
163
|
-
const adapter = {
|
|
164
|
-
...mockAdapter,
|
|
165
|
-
extractClasses: () => [{
|
|
166
|
-
line: 1,
|
|
167
|
-
code: `class X extends B { foo(id: CustomId) {} }`,
|
|
168
|
-
}],
|
|
169
|
-
};
|
|
170
|
-
const violations = lspRule.check('test.ts', adapter as never);
|
|
171
|
-
expect(violations).toHaveLength(0);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('falls back to line 0 when a violation is built for a class with no line', () => {
|
|
175
|
-
// Asserted on the builder directly. After #588 `lspRule.check` can no longer reach
|
|
176
|
-
// this code path for an unknown type — that is the fix — so a case going through
|
|
177
|
-
// `check` would pass without exercising the `?? 0` fallback at all. A control that
|
|
178
|
-
// cannot fail proves nothing, which is why the import is explicit.
|
|
179
|
-
const violation = buildViolation('test.ts', { name: 'D' }, 'CustomId');
|
|
180
|
-
expect(violation.line).toBe(0);
|
|
181
|
-
expect(violation.ruleId).toBe('solid.lsp');
|
|
182
|
-
// And the line is honoured when present, so the fallback is not always taken.
|
|
183
|
-
const withLine = buildViolation('test.ts', { name: 'D', line: 42 }, 'CustomId');
|
|
184
|
-
expect(withLine.line).toBe(42);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { ocpRule } from '../../solid/ocp';
|
|
3
|
-
|
|
4
|
-
const mockAdapter = {
|
|
5
|
-
detectLanguage: () => 'typescript',
|
|
6
|
-
parseAST: () => undefined,
|
|
7
|
-
extractFunctions: () => [],
|
|
8
|
-
extractClasses: () => [],
|
|
9
|
-
countLines: () => 0
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
describe('ocp.ts - Open/Closed Principle Rule', () => {
|
|
13
|
-
it('should detect possible base class modification', () => {
|
|
14
|
-
const mockAdapterWithModification = {
|
|
15
|
-
...mockAdapter,
|
|
16
|
-
extractClasses: () => [{
|
|
17
|
-
name: 'DerivedClass',
|
|
18
|
-
line: 1,
|
|
19
|
-
code: `
|
|
20
|
-
class BaseClass {
|
|
21
|
-
method() {}
|
|
22
|
-
}
|
|
23
|
-
class DerivedClass extends BaseClass {
|
|
24
|
-
method() {}
|
|
25
|
-
}
|
|
26
|
-
`
|
|
27
|
-
}]
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const violations = ocpRule.check('test.ts', mockAdapterWithModification as never);
|
|
31
|
-
|
|
32
|
-
expect(violations.length).toBeGreaterThan(0);
|
|
33
|
-
expect(violations[0].ruleId).toBe('solid.ocp');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should pass for proper extension', () => {
|
|
37
|
-
const mockAdapterWithProperExtension = {
|
|
38
|
-
...mockAdapter,
|
|
39
|
-
extractClasses: () => [{
|
|
40
|
-
name: 'DerivedClass',
|
|
41
|
-
line: 1,
|
|
42
|
-
code: `
|
|
43
|
-
class DerivedClass extends BaseClass {
|
|
44
|
-
newMethod() {}
|
|
45
|
-
}
|
|
46
|
-
`
|
|
47
|
-
}]
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const violations = ocpRule.check('test.ts', mockAdapterWithProperExtension as never);
|
|
51
|
-
|
|
52
|
-
expect(violations.length).toBe(0);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should use severity from config', () => {
|
|
56
|
-
expect(ocpRule.severity).toBe('info');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should propagate adapter errors (no empty catch, #392)', () => {
|
|
60
|
-
const mockAdapterThatThrows = {
|
|
61
|
-
...mockAdapter,
|
|
62
|
-
extractClasses: () => { throw new Error('Adapter failed'); }
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
expect(() => ocpRule.check('test.ts', mockAdapterThatThrows as never)).toThrow('Adapter failed');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { srpRule } from '../../solid/srp';
|
|
3
|
-
|
|
4
|
-
const mockAdapter = {
|
|
5
|
-
detectLanguage: () => 'typescript',
|
|
6
|
-
parseAST: () => undefined,
|
|
7
|
-
extractFunctions: () => [],
|
|
8
|
-
extractClasses: () => [],
|
|
9
|
-
countLines: () => 0
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
describe('srp.ts - Single Responsibility Principle Rule', () => {
|
|
13
|
-
it('should detect class with too many methods (>15)', () => {
|
|
14
|
-
const mockAdapterWithManyMethods = {
|
|
15
|
-
...mockAdapter,
|
|
16
|
-
extractClasses: () => [{
|
|
17
|
-
name: 'MultiResponsibilityClass',
|
|
18
|
-
line: 1,
|
|
19
|
-
methodCount: 18,
|
|
20
|
-
imports: {
|
|
21
|
-
ui: ['Component', 'Styles'],
|
|
22
|
-
data: ['Repository', 'Model'],
|
|
23
|
-
business: ['Service', 'Utils']
|
|
24
|
-
}
|
|
25
|
-
}]
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const violations = srpRule.check('test.ts', mockAdapterWithManyMethods as never);
|
|
29
|
-
|
|
30
|
-
expect(violations.length).toBeGreaterThan(0);
|
|
31
|
-
expect(violations[0].ruleId).toBe('solid.srp');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should detect import diversity (>3 categories)', () => {
|
|
35
|
-
const mockAdapterWithImportDiversity = {
|
|
36
|
-
...mockAdapter,
|
|
37
|
-
extractClasses: () => [{
|
|
38
|
-
name: 'CrossDomainClass',
|
|
39
|
-
line: 1,
|
|
40
|
-
methodCount: 8,
|
|
41
|
-
imports: {
|
|
42
|
-
ui: ['Component'],
|
|
43
|
-
data: ['Repository'],
|
|
44
|
-
business: ['Service'],
|
|
45
|
-
infrastructure: ['Config']
|
|
46
|
-
}
|
|
47
|
-
}]
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const violations = srpRule.check('test.ts', mockAdapterWithImportDiversity as never);
|
|
51
|
-
|
|
52
|
-
expect(violations.length).toBeGreaterThan(0);
|
|
53
|
-
expect(violations[0].message).toContain('import');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should pass for focused class', () => {
|
|
57
|
-
const mockAdapterWithFocusedClass = {
|
|
58
|
-
...mockAdapter,
|
|
59
|
-
extractClasses: () => [{
|
|
60
|
-
name: 'FocusedClass',
|
|
61
|
-
line: 1,
|
|
62
|
-
methodCount: 8,
|
|
63
|
-
imports: {
|
|
64
|
-
data: ['Repository', 'Model']
|
|
65
|
-
}
|
|
66
|
-
}]
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const violations = srpRule.check('test.ts', mockAdapterWithFocusedClass as never);
|
|
70
|
-
|
|
71
|
-
expect(violations.length).toBe(0);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should use threshold from config', () => {
|
|
75
|
-
expect(srpRule.threshold).toBe(15);
|
|
76
|
-
expect(srpRule.severity).toBe('warning');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should propagate adapter errors (no empty catch, #392)', () => {
|
|
80
|
-
const mockAdapterThatThrows = {
|
|
81
|
-
...mockAdapter,
|
|
82
|
-
extractClasses: () => { throw new Error('Adapter failed'); }
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
expect(() => srpRule.check('test.ts', mockAdapterThatThrows as never)).toThrow('Adapter failed');
|
|
86
|
-
});
|
|
87
|
-
});
|