@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,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test REQ-728
|
|
3
|
-
* @intent Java 依赖方向规则 R08/R15/W01。三条规则分别用类名、包路径、文件名判定,
|
|
4
|
-
* 不是不一致而是各自表达的东西不同(见 dependency.ts 头注释)。
|
|
5
|
-
* @covers AC-728-01 AC-728-02 AC-728-03 AC-728-04 AC-728-05 AC-728-06 AC-728-07
|
|
6
|
-
* AC-728-08 AC-728-09 AC-728-10 AC-728-11 AC-728-12 AC-728-13 AC-728-14
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect } from 'vitest';
|
|
9
|
-
import {
|
|
10
|
-
dtoLayeringRule,
|
|
11
|
-
domainEventRule,
|
|
12
|
-
utilServiceRule,
|
|
13
|
-
} from '../dependency';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Adapter stub. `imports` is a GETTER on the real adapter, so this mirrors that
|
|
17
|
-
* shape rather than exposing a plain array -- a rule that reads `.imports()`
|
|
18
|
-
* by mistake must fail here, not in production.
|
|
19
|
-
*/
|
|
20
|
-
function adapter(imports: string[] = [], classes: string[] = []) {
|
|
21
|
-
return {
|
|
22
|
-
extractClasses: () => classes.map((name) => ({ name, line: 1 })),
|
|
23
|
-
get imports() {
|
|
24
|
-
return imports.map((name) => ({ name, line: 1, used: false, type: 'import' }));
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const DTO_FILE = 'src/main/java/com/acme/interfaces/dto/UserDTO.java';
|
|
30
|
-
|
|
31
|
-
describe('R08 — DTO/VO 不得依赖 Service 或 Repository', () => {
|
|
32
|
-
it('AC-728-01: UserDTO import UserService -> 违规', () => {
|
|
33
|
-
const v = dtoLayeringRule.check(DTO_FILE, adapter(['com.acme.application.service.UserService']) as never);
|
|
34
|
-
expect(v).toHaveLength(1);
|
|
35
|
-
expect(v[0].ruleId).toBe('arch.dto-layering');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('AC-728-02: OrderVO import OrderRepository -> 违规', () => {
|
|
39
|
-
const v = dtoLayeringRule.check(
|
|
40
|
-
'src/main/java/com/acme/interfaces/vo/OrderVO.java',
|
|
41
|
-
adapter(['com.acme.infrastructure.repository.OrderRepository']) as never,
|
|
42
|
-
);
|
|
43
|
-
expect(v).toHaveLength(1);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('AC-728-03: UserDTO 只 import javax.validation 注解 -> 通过', () => {
|
|
47
|
-
const v = dtoLayeringRule.check(
|
|
48
|
-
DTO_FILE,
|
|
49
|
-
adapter(['javax.validation.constraints.NotNull', 'java.util.List']) as never,
|
|
50
|
-
);
|
|
51
|
-
expect(v).toEqual([]);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// The exclusion list is the whole reason the suffix heuristic survives on a
|
|
55
|
-
// real codebase: `OrderServiceConstants` matches `*Service` but is not one.
|
|
56
|
-
it('AC-728-09: UserDTO import OrderServiceConstants -> 不报(排除后缀优先于命中)', () => {
|
|
57
|
-
const v = dtoLayeringRule.check(
|
|
58
|
-
DTO_FILE,
|
|
59
|
-
adapter(['com.acme.application.service.OrderServiceConstants']) as never,
|
|
60
|
-
);
|
|
61
|
-
expect(v).toEqual([]);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// A wildcard import carries no class name at all -- the Java adapter's regex
|
|
65
|
-
// does not even capture it. Documented in the design (§4.3) and pinned here so
|
|
66
|
-
// nobody "fixes" the rule into guessing a name from the package.
|
|
67
|
-
it('AC-728-14: DTO 中的通配 import 不参与 R08 判定', () => {
|
|
68
|
-
const v = dtoLayeringRule.check(DTO_FILE, adapter(['com.acme.service']) as never);
|
|
69
|
-
expect(v).toEqual([]);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('R15 — domain/event 不得依赖 infrastructure', () => {
|
|
74
|
-
const EVENT_FILE = 'src/main/java/com/acme/domain/event/OrderCompletedEvent.java';
|
|
75
|
-
|
|
76
|
-
it('AC-728-04: OrderCompletedEvent import infrastructure/kafka/KafkaClient -> 违规', () => {
|
|
77
|
-
const v = domainEventRule.check(
|
|
78
|
-
EVENT_FILE,
|
|
79
|
-
adapter(['com.acme.infrastructure.kafka.KafkaClient']) as never,
|
|
80
|
-
);
|
|
81
|
-
expect(v).toHaveLength(1);
|
|
82
|
-
expect(v[0].ruleId).toBe('arch.domain-event');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('AC-728-05: domain/event import domain/model -> 通过', () => {
|
|
86
|
-
const v = domainEventRule.check(
|
|
87
|
-
EVENT_FILE,
|
|
88
|
-
adapter(['com.acme.domain.model.Order']) as never,
|
|
89
|
-
);
|
|
90
|
-
expect(v).toEqual([]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Wildcard imports never reach ANY rule: the Java adapter's import regex
|
|
94
|
-
// (`[\w.]+`) does not match `*`, so `import com.acme.infrastructure.*;` is
|
|
95
|
-
// absent from `adapter.imports` entirely. Measured, not assumed.
|
|
96
|
-
//
|
|
97
|
-
// The design's §4.3 claimed R15 would still catch a wildcard via its package
|
|
98
|
-
// segments. That is not what the parser does, so the claim is corrected here
|
|
99
|
-
// rather than left as documentation that disagrees with the code.
|
|
100
|
-
it('AC-728-14b: 通配 import 不会出现在 adapter.imports 中,因此任何规则都看不到它', () => {
|
|
101
|
-
const wildcardSource = 'import com.acme.infrastructure.*;';
|
|
102
|
-
// Mirror the adapter's own regex so this test breaks if that regex widens.
|
|
103
|
-
const adapterImportRegex = /^\s*import\s+(?:static\s+)?([\w.]+)\s*;\s*$/;
|
|
104
|
-
expect(adapterImportRegex.exec(wildcardSource)).toBeNull();
|
|
105
|
-
// And with an empty import list, R15 stays silent.
|
|
106
|
-
expect(domainEventRule.check(EVENT_FILE, adapter([]) as never)).toEqual([]);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe('W01 — Util/Helper 不应依赖 Application Service(WARNING)', () => {
|
|
111
|
-
const UTIL_FILE = 'src/main/java/com/acme/shared/StringUtils.java';
|
|
112
|
-
|
|
113
|
-
it('AC-728-06: StringUtils import OrderService -> 告警', () => {
|
|
114
|
-
const v = utilServiceRule.check(UTIL_FILE, adapter(['com.acme.application.service.OrderService']) as never);
|
|
115
|
-
expect(v).toHaveLength(1);
|
|
116
|
-
expect(v[0].ruleId).toBe('arch.util-service');
|
|
117
|
-
expect(v[0].severity).toBe('warning');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('AC-728-07: FileHelper import java.io.* -> 通过', () => {
|
|
121
|
-
const v = utilServiceRule.check(
|
|
122
|
-
'src/main/java/com/acme/shared/FileHelper.java',
|
|
123
|
-
adapter(['java.io.File', 'java.util.List']) as never,
|
|
124
|
-
);
|
|
125
|
-
expect(v).toEqual([]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// Framework services are not this project's application layer. Paired with
|
|
129
|
-
// AC-728-13 below, these two prove the exclusion is scoped to framework
|
|
130
|
-
// prefixes and does not silence the project's own services.
|
|
131
|
-
it('AC-728-12: OrderHelper import Spring 的 DiscoveryService -> 不报(框架包排除)', () => {
|
|
132
|
-
const v = utilServiceRule.check(
|
|
133
|
-
'src/main/java/com/acme/shared/OrderHelper.java',
|
|
134
|
-
adapter(['org.springframework.cloud.client.discovery.DiscoveryService']) as never,
|
|
135
|
-
);
|
|
136
|
-
expect(v).toEqual([]);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('AC-728-13: OrderHelper import 本项目的 OrderService -> 报(排除只对框架包生效)', () => {
|
|
140
|
-
const v = utilServiceRule.check(
|
|
141
|
-
'src/main/java/com/acme/shared/OrderHelper.java',
|
|
142
|
-
adapter(['com.acme.application.service.OrderService']) as never,
|
|
143
|
-
);
|
|
144
|
-
expect(v).toHaveLength(1);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('W01 不得阻塞提交', () => {
|
|
149
|
-
// "Not blocking" is not "silent": the two assertions below are deliberately
|
|
150
|
-
// separate. An implementation that swallowed W01 entirely would pass the
|
|
151
|
-
// first and fail the second (AC-728-10 / AC-728-11).
|
|
152
|
-
it('AC-728-10: W01 产出中没有 error 级违规', () => {
|
|
153
|
-
const v = utilServiceRule.check(
|
|
154
|
-
'src/main/java/com/acme/shared/StringUtils.java',
|
|
155
|
-
adapter(['com.acme.application.service.OrderService']) as never,
|
|
156
|
-
);
|
|
157
|
-
expect(v.every((violation) => violation.severity !== 'error')).toBe(true);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('AC-728-11: W01 仍然出现在结果里(不阻塞 != 不上报)', () => {
|
|
161
|
-
const v = utilServiceRule.check(
|
|
162
|
-
'src/main/java/com/acme/shared/StringUtils.java',
|
|
163
|
-
adapter(['com.acme.application.service.OrderService']) as never,
|
|
164
|
-
);
|
|
165
|
-
expect(v.length).toBeGreaterThan(0);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('AC-728-08: W01 默认规则配置为 warning', () => {
|
|
169
|
-
expect(utilServiceRule.severity).toBe('warning');
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
describe('src/test/java 整体排除', () => {
|
|
174
|
-
// Test sources may be named anything; the rules constrain production layering.
|
|
175
|
-
it('测试目录下的同名依赖不触发任何规则', () => {
|
|
176
|
-
const testFile = 'src/test/java/com/acme/interfaces/dto/UserDTOTest.java';
|
|
177
|
-
expect(dtoLayeringRule.check(testFile, adapter(['com.acme.application.service.UserService']) as never)).toEqual([]);
|
|
178
|
-
expect(utilServiceRule.check('src/test/java/com/acme/StringUtilsTest.java', adapter(['com.acme.application.service.OrderService']) as never)).toEqual([]);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test REQ-727
|
|
3
|
-
* @intent Java 命名规则 R10/R11/R12 —— 按包路径约束类名后缀。
|
|
4
|
-
* ArchUnit 33 条里这三条是纯 AST 模式匹配,不需要跑 Maven,
|
|
5
|
-
* 因此能在 pre-commit 拦住,比 ArchUnit 快一个数量级。
|
|
6
|
-
* @covers AC-727-01 AC-727-02 AC-727-03 AC-727-04 AC-727-05 AC-727-06 AC-727-07 AC-727-08
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect } from 'vitest';
|
|
9
|
-
import { Rule, Violation } from '../../../types';
|
|
10
|
-
import {
|
|
11
|
-
controllerNamingRule,
|
|
12
|
-
serviceNamingRule,
|
|
13
|
-
repositoryNamingRule,
|
|
14
|
-
} from '../naming';
|
|
15
|
-
import { extractPackageSegments } from '../shared';
|
|
16
|
-
|
|
17
|
-
/** Minimal adapter surface the naming rules read: class names + positions. */
|
|
18
|
-
function adapterWithClasses(classes: Array<{ name: string; line?: number }>) {
|
|
19
|
-
return { extractClasses: () => classes };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Call a rule and return only its violations, so each test reads as one assertion. */
|
|
23
|
-
function violationsOf(
|
|
24
|
-
rule: Rule,
|
|
25
|
-
file: string,
|
|
26
|
-
classes: Array<{ name: string; line?: number }>,
|
|
27
|
-
): Violation[] {
|
|
28
|
-
return rule.check(file, adapterWithClasses(classes) as never);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe('R10 — interfaces/rest 下的类必须以 Controller 结尾', () => {
|
|
32
|
-
it('AC-727-01: UserAPI 在 interfaces/rest 下 -> 违规', () => {
|
|
33
|
-
const v = violationsOf(
|
|
34
|
-
controllerNamingRule,
|
|
35
|
-
'src/main/java/com/acme/interfaces/rest/UserAPI.java',
|
|
36
|
-
[{ name: 'UserAPI' }],
|
|
37
|
-
);
|
|
38
|
-
expect(v).toHaveLength(1);
|
|
39
|
-
expect((v[0] as { ruleId: string }).ruleId).toBe('arch.controller');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('AC-727-02: UserController 在 interfaces/rest 下 -> 通过', () => {
|
|
43
|
-
const v = violationsOf(
|
|
44
|
-
controllerNamingRule,
|
|
45
|
-
'src/main/java/com/acme/interfaces/rest/UserController.java',
|
|
46
|
-
[{ name: 'UserController' }],
|
|
47
|
-
);
|
|
48
|
-
expect(v).toEqual([]);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('R11 — application/service 下的类必须以 Service 或 ServiceImpl 结尾', () => {
|
|
53
|
-
it('AC-727-03: OrderManager 在 application/service 下 -> 违规', () => {
|
|
54
|
-
const v = violationsOf(
|
|
55
|
-
serviceNamingRule,
|
|
56
|
-
'src/main/java/com/acme/application/service/OrderManager.java',
|
|
57
|
-
[{ name: 'OrderManager' }],
|
|
58
|
-
);
|
|
59
|
-
expect(v).toHaveLength(1);
|
|
60
|
-
expect((v[0] as { ruleId: string }).ruleId).toBe('arch.service');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('AC-727-04: OrderServiceImpl 在 application/service 下 -> 通过', () => {
|
|
64
|
-
const v = violationsOf(
|
|
65
|
-
serviceNamingRule,
|
|
66
|
-
'src/main/java/com/acme/application/service/OrderServiceImpl.java',
|
|
67
|
-
[{ name: 'OrderServiceImpl' }],
|
|
68
|
-
);
|
|
69
|
-
expect(v).toEqual([]);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('R12 — infrastructure/repository 与 gateway 下的类必须以 Mapper/DAO/Repository 结尾', () => {
|
|
74
|
-
// The suffix whitelist is case-SENSITIVE on purpose: `DAO` is the documented
|
|
75
|
-
// form, so `UserDao` must be reported. Lower-casing before comparison would
|
|
76
|
-
// silently accept it and the rule would stop enforcing the standard.
|
|
77
|
-
it('AC-727-05: UserDao 在 infrastructure/repository 下 -> 违规(DAO 大写才算)', () => {
|
|
78
|
-
const v = violationsOf(
|
|
79
|
-
repositoryNamingRule,
|
|
80
|
-
'src/main/java/com/acme/infrastructure/repository/UserDao.java',
|
|
81
|
-
[{ name: 'UserDao' }],
|
|
82
|
-
);
|
|
83
|
-
expect(v).toHaveLength(1);
|
|
84
|
-
expect((v[0] as { ruleId: string }).ruleId).toBe('arch.repository');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('AC-727-06: UserMapper 在 infrastructure/repository 下 -> 通过', () => {
|
|
88
|
-
const v = violationsOf(
|
|
89
|
-
repositoryNamingRule,
|
|
90
|
-
'src/main/java/com/acme/infrastructure/repository/UserMapper.java',
|
|
91
|
-
[{ name: 'UserMapper' }],
|
|
92
|
-
);
|
|
93
|
-
expect(v).toEqual([]);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('包路径边界', () => {
|
|
98
|
-
// Maven multi-module puts the module name before src/main/java. Anchoring the
|
|
99
|
-
// match on the start of the path (or on "src/main/java" as a prefix) would
|
|
100
|
-
// miss every class in every submodule -- the common shape, not an edge case.
|
|
101
|
-
it('AC-727-07: Maven 多模块路径 core/src/main/java/... 正确识别为 interfaces/rest', () => {
|
|
102
|
-
const v = violationsOf(
|
|
103
|
-
controllerNamingRule,
|
|
104
|
-
'core/src/main/java/com/acme/interfaces/rest/UserAPI.java',
|
|
105
|
-
[{ name: 'UserAPI' }],
|
|
106
|
-
);
|
|
107
|
-
expect(v).toHaveLength(1);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// The case above does NOT pin down WHICH `src/.../java` is used: it holds a
|
|
111
|
-
// single occurrence, so "first" and "last" agree. A mutation run proved this:
|
|
112
|
-
// flipping the anchor to the first occurrence left every test green.
|
|
113
|
-
//
|
|
114
|
-
// Asserting through a rule cannot fix that, because the rules search for a
|
|
115
|
-
// CONTIGUOUS run (`interfaces/rest`), and both anchors still contain it. So
|
|
116
|
-
// this checks the extracted package directly -- the only assertion that
|
|
117
|
-
// actually distinguishes the two behaviours.
|
|
118
|
-
it('AC-727-07b: 路径含两处 src/main/java 时锚定最后一处(嵌套模块)', () => {
|
|
119
|
-
expect(
|
|
120
|
-
extractPackageSegments(
|
|
121
|
-
'legacy/src/main/java/gen/src/main/java/com/acme/interfaces/rest/UserAPI.java',
|
|
122
|
-
),
|
|
123
|
-
).toEqual(['com', 'acme', 'interfaces', 'rest']);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('AC-727-08: 非目标包 util/FooHelper.java 不误报任何命名规则', () => {
|
|
127
|
-
const file = 'src/main/java/com/acme/util/FooHelper.java';
|
|
128
|
-
const classes = [{ name: 'FooHelper' }];
|
|
129
|
-
expect(violationsOf(controllerNamingRule, file, classes)).toEqual([]);
|
|
130
|
-
expect(violationsOf(serviceNamingRule, file, classes)).toEqual([]);
|
|
131
|
-
expect(violationsOf(repositoryNamingRule, file, classes)).toEqual([]);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test REQ-727
|
|
3
|
-
* @intent shared.ts 是 arch 两组规则的公共基础:包路径提取、类名/import 读取、
|
|
4
|
-
* severity 回退。这些函数一旦错了,上面的规则会以「没有任何违规」的
|
|
5
|
-
* 方式静默失效——所以单独钉住,而不是只靠规则测试间接覆盖。
|
|
6
|
-
* @covers AC-727-07 AC-726-01
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect } from 'vitest';
|
|
9
|
-
import {
|
|
10
|
-
extractPackageSegments,
|
|
11
|
-
isTestSource,
|
|
12
|
-
classNamesOf,
|
|
13
|
-
importsOf,
|
|
14
|
-
readSeverity,
|
|
15
|
-
simpleNameOf,
|
|
16
|
-
packageSegmentsOf,
|
|
17
|
-
} from '../shared';
|
|
18
|
-
|
|
19
|
-
describe('extractPackageSegments — 从路径取包', () => {
|
|
20
|
-
it('标准 Maven 布局:src/main/java/<pkg>/File.java', () => {
|
|
21
|
-
expect(extractPackageSegments('src/main/java/com/acme/order/Order.java')).toEqual([
|
|
22
|
-
'com',
|
|
23
|
-
'acme',
|
|
24
|
-
'order',
|
|
25
|
-
]);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('多模块布局:模块名不算进包名', () => {
|
|
29
|
-
expect(
|
|
30
|
-
extractPackageSegments('core/src/main/java/com/acme/interfaces/rest/UserAPI.java'),
|
|
31
|
-
).toEqual(['com', 'acme', 'interfaces', 'rest']);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('含两处 src/main/java 时锚定最后一处', () => {
|
|
35
|
-
expect(
|
|
36
|
-
extractPackageSegments('legacy/src/main/java/gen/src/main/java/com/acme/A.java'),
|
|
37
|
-
).toEqual(['com', 'acme']);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('Windows 反斜杠路径同样处理', () => {
|
|
41
|
-
expect(
|
|
42
|
-
extractPackageSegments('core\\src\\main\\java\\com\\acme\\interfaces\\rest\\A.java'),
|
|
43
|
-
).toEqual(['com', 'acme', 'interfaces', 'rest']);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('非 Java 源根路径返回空数组(规则据此不触发,而不是猜)', () => {
|
|
47
|
-
expect(extractPackageSegments('src/com/acme/A.java')).toEqual([]);
|
|
48
|
-
expect(extractPackageSegments('README.md')).toEqual([]);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('isTestSource — 测试目录整体排除', () => {
|
|
53
|
-
it('src/test/java 判定为测试代码', () => {
|
|
54
|
-
expect(isTestSource('src/test/java/com/acme/A.java')).toBe(true);
|
|
55
|
-
expect(isTestSource('core/src/test/java/com/acme/ATest.java')).toBe(true);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('src/main/java 不是测试代码', () => {
|
|
59
|
-
expect(isTestSource('src/main/java/com/acme/A.java')).toBe(false);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('classNamesOf / importsOf — 跳过不可用条目', () => {
|
|
64
|
-
it('跳过没有 name 或 name 为空的条目', () => {
|
|
65
|
-
// Named so the "no name" case reads as intentional rather than as a stray
|
|
66
|
-
// number: 3 is the line an entry carries when it has no name to report.
|
|
67
|
-
const UNNAMED_ENTRY_LINE = 3;
|
|
68
|
-
const adapter = {
|
|
69
|
-
extractClasses: () => [
|
|
70
|
-
{ name: 'A', line: 1 },
|
|
71
|
-
{ name: '' },
|
|
72
|
-
{ line: UNNAMED_ENTRY_LINE },
|
|
73
|
-
{ name: 'B' },
|
|
74
|
-
],
|
|
75
|
-
get imports() {
|
|
76
|
-
return [{ name: 'a.B', line: 2 }, {}, { name: '' }];
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
expect(classNamesOf(adapter)).toEqual([{ name: 'A', line: 1 }, { name: 'B', line: undefined }]);
|
|
80
|
-
expect(importsOf(adapter)).toEqual([{ name: 'a.B', line: 2 }]);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('adapter 缺少对应成员时返回空数组而不抛错', () => {
|
|
84
|
-
expect(classNamesOf({})).toEqual([]);
|
|
85
|
-
expect(importsOf({})).toEqual([]);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('readSeverity — 缺失配置时回退', () => {
|
|
90
|
-
it('读取已配置的 severity', () => {
|
|
91
|
-
expect(readSeverity({ 'x': { severity: 'info' } }, 'x', 'error')).toBe('info');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('分组整体缺失时回退到默认(老配置无 arch 键的场景)', () => {
|
|
95
|
-
expect(readSeverity(undefined, 'x', 'warning')).toBe('warning');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('非法 severity 值回退到默认,而不是透传', () => {
|
|
99
|
-
expect(readSeverity({ 'x': { severity: 'fatal' } }, 'x', 'error')).toBe('error');
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe('simpleNameOf / packageSegmentsOf', () => {
|
|
104
|
-
it('取全限定名的简单类名与包段', () => {
|
|
105
|
-
expect(simpleNameOf('com.acme.order.OrderService')).toBe('OrderService');
|
|
106
|
-
expect(packageSegmentsOf('com.acme.order.OrderService')).toEqual(['com', 'acme', 'order']);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('无包名的裸类名:简单名是自身,包段为空', () => {
|
|
110
|
-
expect(simpleNameOf('OrderService')).toBe('OrderService');
|
|
111
|
-
expect(packageSegmentsOf('OrderService')).toEqual([]);
|
|
112
|
-
});
|
|
113
|
-
});
|