@dommaker/harness 0.7.2 → 0.7.3

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @dommaker/harness
2
2
 
3
- > 通用工程约束框架 - 铁律系统、检查点验证、测试门控、拦截器
3
+ > 通用工程约束框架 - 铁律系统、门禁系统、检查点验证、拦截器
4
4
 
5
5
  ## 简介
6
6
 
@@ -11,12 +11,13 @@
11
11
  | 功能 | 说明 |
12
12
  |------|------|
13
13
  | **铁律系统** | 16 条内置约束(4 Iron Laws + 10 Guidelines + 2 Tips) |
14
+ | **门禁系统** | 6 种门禁(测试、审查、安全、性能、契约、检查点) |
14
15
  | **检查点验证** | 验证工作流步骤的结果是否符合预期 |
15
- | **测试门控** | 禁止自评通过,必须通过真实测试 |
16
- | **拦截器** | 抽象拦截框架,自动执行 enforcement(v0.7+) |
16
+ | **拦截器** | 抽象拦截框架,自动执行 enforcement |
17
17
  | **Session 管理** | 启动检查点 + 结束状态管理 |
18
18
  | **预设系统** | 提供 strict/standard/relaxed 三种预设 |
19
19
  | **Execution Trace** | 轻量记录约束检查,异常检测,诊断系统 |
20
+ | **Spec 验证** | 验证架构文档、模块定义、API 定义 |
20
21
  | **项目级自定义约束** | 扩展/覆盖内置约束,无需 fork |
21
22
  | **CLI 工具** | 命令行工具执行检查 |
22
23
 
@@ -170,7 +171,110 @@ const cleaner = new CleanStateManager();
170
171
  const cleanResult = await cleaner.onSessionEnd(workDir, sessionInfo);
171
172
  ```
172
173
 
173
- ### 5. 使用拦截器(v0.7+)
174
+ ### 7. 门禁系统
175
+
176
+ harness 提供完整的门禁系统,支持多种门禁类型:
177
+
178
+ | 门禁 | 类 | 说明 |
179
+ |------|-----|------|
180
+ | 测试门控 | `PassesGate` | 禁止自评通过,必须通过真实测试 |
181
+ | 审查门禁 | `ReviewGate` | 检查 GitHub PR 审查状态 |
182
+ | 安全门禁 | `SecurityGate` | npm audit 安全漏洞扫描 |
183
+ | 性能门禁 | `PerformanceGate` | 响应时间、覆盖率、打包大小检查 |
184
+ | 契约门禁 | `ContractGate` | OpenAPI 契约验证 |
185
+ | 检查点验证 | `CheckpointValidator` | 验证工作流步骤结果 |
186
+
187
+ **使用门禁**:
188
+
189
+ ```typescript
190
+ import {
191
+ PassesGate,
192
+ ReviewGate,
193
+ SecurityGate,
194
+ PerformanceGate,
195
+ ContractGate,
196
+ CheckpointValidator,
197
+ } from '@dommaker/harness';
198
+
199
+ // 测试门控
200
+ const passesGate = new PassesGate({ requireEvidence: true });
201
+ const testResult = await passesGate.runTests();
202
+
203
+ // 审查门禁
204
+ const reviewGate = new ReviewGate({ minReviewers: 2 });
205
+ const reviewResult = await reviewGate.check({
206
+ projectId: 'my-project',
207
+ projectPath: '/path/to/project',
208
+ prNumber: 123,
209
+ });
210
+
211
+ // 安全门禁
212
+ const securityGate = new SecurityGate({ severityThreshold: 'high' });
213
+ const securityResult = await securityGate.scan({
214
+ projectId: 'my-project',
215
+ projectPath: '/path/to/project',
216
+ });
217
+
218
+ // 性能门禁(带超时)
219
+ const performanceGate = new PerformanceGate({
220
+ thresholds: {
221
+ maxResponseTime: 500,
222
+ minCoverage: 80,
223
+ maxBundleSize: 1024,
224
+ },
225
+ coverageTimeout: 120000, // 2分钟超时
226
+ });
227
+ const perfResult = await performanceGate.check({
228
+ projectId: 'my-project',
229
+ projectPath: '/path/to/project',
230
+ });
231
+
232
+ // 契约门禁
233
+ const contractGate = new ContractGate({ strict: true });
234
+ const contractResult = await contractGate.check({
235
+ projectId: 'my-project',
236
+ projectPath: '/path/to/project',
237
+ newContractPath: '/path/to/openapi.yaml',
238
+ });
239
+
240
+ // 检查点验证
241
+ const checkpointValidator = CheckpointValidator.getInstance();
242
+ const checkpointResult = await checkpointValidator.validate(checkpoints, {
243
+ workdir: '/path/to/project',
244
+ });
245
+ ```
246
+
247
+ **门禁结果**:
248
+
249
+ ```typescript
250
+ interface GateResult {
251
+ gate: string; // 门禁类型
252
+ passed: boolean; // 是否通过
253
+ message: string; // 结果消息
254
+ details?: { // 详细信息
255
+ metrics?: object; // 性能指标
256
+ failures?: string[]; // 失败项
257
+ warnings?: string[]; // 警告项
258
+ };
259
+ timestamp: string; // 时间戳
260
+ duration?: number; // 执行时长(毫秒)
261
+ }
262
+ ```
263
+
264
+ **PerformanceGate 超时配置**:
265
+
266
+ ```typescript
267
+ const gate = new PerformanceGate({
268
+ thresholds: { minCoverage: 80 },
269
+ coverageTimeout: 60000, // 覆盖率测试超时(毫秒)
270
+ benchmarkTimeout: 30000, // 基准测试超时(毫秒)
271
+ });
272
+
273
+ // 动态设置超时
274
+ gate.setTimeouts({ coverage: 120000 });
275
+ ```
276
+
277
+ ### 8. 使用拦截器
174
278
 
175
279
  拦截器自动执行 enforcement,无需手动调用检查 API:
176
280
 
@@ -371,6 +475,50 @@ class PassesGate {
371
475
  }
372
476
  ```
373
477
 
478
+ ### ReviewGate
479
+
480
+ ```typescript
481
+ class ReviewGate {
482
+ constructor(config: ReviewGateConfig);
483
+
484
+ check(context: GateContext): Promise<GateResult>;
485
+ setMinReviewers(count: number): void;
486
+ }
487
+ ```
488
+
489
+ ### SecurityGate
490
+
491
+ ```typescript
492
+ class SecurityGate {
493
+ constructor(config: SecurityGateConfig);
494
+
495
+ scan(context: GateContext): Promise<GateResult>;
496
+ }
497
+ ```
498
+
499
+ ### PerformanceGate
500
+
501
+ ```typescript
502
+ class PerformanceGate {
503
+ constructor(config: PerformanceGateConfig);
504
+
505
+ check(context: GateContext): Promise<GateResult>;
506
+ runBenchmark(context: GateContext): Promise<BenchmarkResult>;
507
+ setThresholds(thresholds: Partial<PerformanceThresholds>): void;
508
+ setTimeouts(options: { coverage?: number; benchmark?: number }): void;
509
+ }
510
+ ```
511
+
512
+ ### ContractGate
513
+
514
+ ```typescript
515
+ class ContractGate {
516
+ constructor(config: ContractGateConfig);
517
+
518
+ check(context: GateContext): Promise<GateResult>;
519
+ }
520
+ ```
521
+
374
522
  ### SessionStartup
375
523
 
376
524
  ```typescript
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 契约门禁
3
+ *
4
+ * 检查 API 契约:
5
+ * - OpenAPI Schema 验证
6
+ * - 破坏性变更检测
7
+ * - 版本兼容性
8
+ */
9
+ import type { GateResult, GateContext, ContractGateConfig } from './types';
10
+ /**
11
+ * 契约门禁
12
+ */
13
+ export declare class ContractGate {
14
+ private config;
15
+ constructor(config?: Partial<ContractGateConfig>);
16
+ /**
17
+ * 检查契约
18
+ */
19
+ check(context: GateContext): Promise<GateResult>;
20
+ /**
21
+ * 验证契约格式
22
+ */
23
+ private validateContract;
24
+ /**
25
+ * 检测破坏性变更
26
+ */
27
+ private detectBreakingChanges;
28
+ /**
29
+ * 提取端点列表
30
+ */
31
+ private extractEndpoints;
32
+ /**
33
+ * 设置契约路径
34
+ */
35
+ setContractPath(path: string): void;
36
+ /**
37
+ * 获取配置
38
+ */
39
+ getConfig(): Required<ContractGateConfig>;
40
+ }
41
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/gates/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAI3E;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAA+B;gBAEjC,MAAM,GAAE,OAAO,CAAC,kBAAkB,CAAM;IASpD;;OAEG;IACG,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAkGtD;;OAEG;YACW,gBAAgB;IA0D9B;;OAEG;YACW,qBAAqB;IAmCnC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAInC;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,kBAAkB,CAAC;CAG1C"}
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ /**
3
+ * 契约门禁
4
+ *
5
+ * 检查 API 契约:
6
+ * - OpenAPI Schema 验证
7
+ * - 破坏性变更检测
8
+ * - 版本兼容性
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.ContractGate = void 0;
45
+ const child_process_1 = require("child_process");
46
+ const util_1 = require("util");
47
+ const fs = __importStar(require("fs/promises"));
48
+ const path = __importStar(require("path"));
49
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
50
+ /**
51
+ * 契约门禁
52
+ */
53
+ class ContractGate {
54
+ config;
55
+ constructor(config = {}) {
56
+ this.config = {
57
+ enabled: config.enabled ?? true,
58
+ strict: config.strict ?? true,
59
+ allowBreakingChanges: config.allowBreakingChanges ?? false,
60
+ contractPath: config.contractPath ?? 'openapi.yaml',
61
+ };
62
+ }
63
+ /**
64
+ * 检查契约
65
+ */
66
+ async check(context) {
67
+ const startTime = Date.now();
68
+ if (!this.config.enabled) {
69
+ return {
70
+ gate: 'contract',
71
+ passed: true,
72
+ message: '契约门禁已禁用',
73
+ timestamp: new Date().toISOString(),
74
+ duration: Date.now() - startTime,
75
+ };
76
+ }
77
+ try {
78
+ const contractPath = context.newContractPath ??
79
+ path.join(context.projectPath, this.config.contractPath);
80
+ // 检查契约文件是否存在
81
+ try {
82
+ await fs.access(contractPath);
83
+ }
84
+ catch {
85
+ return {
86
+ gate: 'contract',
87
+ passed: true,
88
+ message: '未找到契约文件,跳过检查',
89
+ details: {
90
+ contractPath,
91
+ suggestion: '创建 OpenAPI 规范文件',
92
+ },
93
+ timestamp: new Date().toISOString(),
94
+ duration: Date.now() - startTime,
95
+ };
96
+ }
97
+ // 验证契约格式
98
+ const validation = await this.validateContract(contractPath);
99
+ if (!validation.valid) {
100
+ return {
101
+ gate: 'contract',
102
+ passed: false,
103
+ message: `契约格式无效: ${validation.errors.join(', ')}`,
104
+ details: {
105
+ contractPath,
106
+ errors: validation.errors,
107
+ },
108
+ timestamp: new Date().toISOString(),
109
+ duration: Date.now() - startTime,
110
+ };
111
+ }
112
+ // 检查破坏性变更(如果提供了旧契约)
113
+ if (context.oldContractPath) {
114
+ const breakingChanges = await this.detectBreakingChanges(context.oldContractPath, contractPath);
115
+ if (breakingChanges.length > 0 && !this.config.allowBreakingChanges) {
116
+ return {
117
+ gate: 'contract',
118
+ passed: false,
119
+ message: `发现破坏性变更: ${breakingChanges.length} 个`,
120
+ details: {
121
+ contractPath,
122
+ oldContractPath: context.oldContractPath,
123
+ breakingChanges,
124
+ suggestion: '更新 API 版本或保持向后兼容',
125
+ },
126
+ timestamp: new Date().toISOString(),
127
+ duration: Date.now() - startTime,
128
+ };
129
+ }
130
+ }
131
+ return {
132
+ gate: 'contract',
133
+ passed: true,
134
+ message: '契约检查通过',
135
+ details: {
136
+ contractPath,
137
+ endpoints: validation.endpoints,
138
+ version: validation.version,
139
+ },
140
+ timestamp: new Date().toISOString(),
141
+ duration: Date.now() - startTime,
142
+ };
143
+ }
144
+ catch (error) {
145
+ return {
146
+ gate: 'contract',
147
+ passed: false,
148
+ message: `契约检查失败: ${error.message}`,
149
+ timestamp: new Date().toISOString(),
150
+ duration: Date.now() - startTime,
151
+ };
152
+ }
153
+ }
154
+ /**
155
+ * 验证契约格式
156
+ */
157
+ async validateContract(contractPath) {
158
+ const errors = [];
159
+ let endpoints = 0;
160
+ let version;
161
+ try {
162
+ const content = await fs.readFile(contractPath, 'utf-8');
163
+ let spec;
164
+ // 解析 YAML 或 JSON
165
+ if (contractPath.endsWith('.yaml') || contractPath.endsWith('.yml')) {
166
+ // 简化的 YAML 解析(只提取基本信息)
167
+ const lines = content.split('\n');
168
+ for (const line of lines) {
169
+ if (line.startsWith('openapi:') || line.startsWith('swagger:')) {
170
+ version = line.split(':')[1]?.trim();
171
+ }
172
+ if (line.match(/^\s*\/\w+/)) {
173
+ endpoints++;
174
+ }
175
+ }
176
+ }
177
+ else {
178
+ spec = JSON.parse(content);
179
+ version = spec.openapi || spec.swagger;
180
+ if (spec.paths) {
181
+ endpoints = Object.keys(spec.paths).length;
182
+ }
183
+ }
184
+ // 基本验证
185
+ if (!version) {
186
+ errors.push('缺少 openapi/swagger 版本');
187
+ }
188
+ if (endpoints === 0) {
189
+ errors.push('没有定义任何端点');
190
+ }
191
+ return {
192
+ valid: errors.length === 0,
193
+ errors,
194
+ endpoints,
195
+ version,
196
+ };
197
+ }
198
+ catch (error) {
199
+ return {
200
+ valid: false,
201
+ errors: [`解析失败: ${error.message}`],
202
+ endpoints: 0,
203
+ };
204
+ }
205
+ }
206
+ /**
207
+ * 检测破坏性变更
208
+ */
209
+ async detectBreakingChanges(oldPath, newPath) {
210
+ const changes = [];
211
+ try {
212
+ const oldContent = await fs.readFile(oldPath, 'utf-8');
213
+ const newContent = await fs.readFile(newPath, 'utf-8');
214
+ // 提取端点列表
215
+ const oldEndpoints = this.extractEndpoints(oldContent);
216
+ const newEndpoints = this.extractEndpoints(newContent);
217
+ // 检查删除的端点
218
+ for (const endpoint of oldEndpoints) {
219
+ if (!newEndpoints.includes(endpoint)) {
220
+ changes.push({
221
+ type: 'endpoint_removed',
222
+ description: `端点 ${endpoint} 已删除`,
223
+ path: endpoint,
224
+ });
225
+ }
226
+ }
227
+ // 检查新增的端点(不是破坏性变更)
228
+ // 检查方法变更
229
+ // 简化实现,实际应该完整比较
230
+ return changes;
231
+ }
232
+ catch {
233
+ return [];
234
+ }
235
+ }
236
+ /**
237
+ * 提取端点列表
238
+ */
239
+ extractEndpoints(content) {
240
+ const endpoints = [];
241
+ const lines = content.split('\n');
242
+ for (const line of lines) {
243
+ const match = line.match(/^\s*\/[\w/-]+:/);
244
+ if (match) {
245
+ endpoints.push(match[0].replace(':', '').trim());
246
+ }
247
+ }
248
+ return endpoints;
249
+ }
250
+ /**
251
+ * 设置契约路径
252
+ */
253
+ setContractPath(path) {
254
+ this.config.contractPath = path;
255
+ }
256
+ /**
257
+ * 获取配置
258
+ */
259
+ getConfig() {
260
+ return { ...this.config };
261
+ }
262
+ }
263
+ exports.ContractGate = ContractGate;
264
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/gates/contract.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAAqC;AACrC,+BAAiC;AACjC,gDAAkC;AAClC,2CAA6B;AAG7B,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;AAElC;;GAEG;AACH,MAAa,YAAY;IACf,MAAM,CAA+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M,EAAE,CAAC;IAC5B,CAAC;CACF;AAlPD,oCAkPC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 门禁系统导出
3
+ *
4
+ * 统一导出所有门禁类型
5
+ */
6
+ export type { GateResult, GateContext, PerformanceThresholds, ReviewGateConfig, SecurityGateConfig, PerformanceGateConfig, ContractGateConfig, } from './types';
7
+ export { ReviewGate } from './review';
8
+ export { SecurityGate } from './security';
9
+ export { PerformanceGate } from './performance';
10
+ export { ContractGate } from './contract';
11
+ import { ReviewGate } from './review';
12
+ import { SecurityGate } from './security';
13
+ import { PerformanceGate } from './performance';
14
+ import { ContractGate } from './contract';
15
+ import type { ReviewGateConfig, SecurityGateConfig, PerformanceGateConfig, ContractGateConfig } from './types';
16
+ export declare function createReviewGate(config?: Partial<ReviewGateConfig>): ReviewGate;
17
+ export declare function createSecurityGate(config?: Partial<SecurityGateConfig>): SecurityGate;
18
+ export declare function createPerformanceGate(config?: Partial<PerformanceGateConfig>): PerformanceGate;
19
+ export declare function createContractGate(config?: Partial<ContractGateConfig>): ContractGate;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gates/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,UAAU,EACV,WAAW,EACX,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,UAAU,CAE/E;AAED,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,YAAY,CAErF;AAED,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,eAAe,CAE9F;AAED,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,YAAY,CAErF"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * 门禁系统导出
4
+ *
5
+ * 统一导出所有门禁类型
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ContractGate = exports.PerformanceGate = exports.SecurityGate = exports.ReviewGate = void 0;
9
+ exports.createReviewGate = createReviewGate;
10
+ exports.createSecurityGate = createSecurityGate;
11
+ exports.createPerformanceGate = createPerformanceGate;
12
+ exports.createContractGate = createContractGate;
13
+ // 门禁类导出
14
+ var review_1 = require("./review");
15
+ Object.defineProperty(exports, "ReviewGate", { enumerable: true, get: function () { return review_1.ReviewGate; } });
16
+ var security_1 = require("./security");
17
+ Object.defineProperty(exports, "SecurityGate", { enumerable: true, get: function () { return security_1.SecurityGate; } });
18
+ var performance_1 = require("./performance");
19
+ Object.defineProperty(exports, "PerformanceGate", { enumerable: true, get: function () { return performance_1.PerformanceGate; } });
20
+ var contract_1 = require("./contract");
21
+ Object.defineProperty(exports, "ContractGate", { enumerable: true, get: function () { return contract_1.ContractGate; } });
22
+ // 便捷工厂函数
23
+ const review_2 = require("./review");
24
+ const security_2 = require("./security");
25
+ const performance_2 = require("./performance");
26
+ const contract_2 = require("./contract");
27
+ function createReviewGate(config) {
28
+ return new review_2.ReviewGate(config);
29
+ }
30
+ function createSecurityGate(config) {
31
+ return new security_2.SecurityGate(config);
32
+ }
33
+ function createPerformanceGate(config) {
34
+ return new performance_2.PerformanceGate(config);
35
+ }
36
+ function createContractGate(config) {
37
+ return new contract_2.ContractGate(config);
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gates/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA+BH,4CAEC;AAED,gDAEC;AAED,sDAEC;AAED,gDAEC;AAhCD,QAAQ;AACR,mCAAsC;AAA7B,oGAAA,UAAU,OAAA;AACnB,uCAA0C;AAAjC,wGAAA,YAAY,OAAA;AACrB,6CAAgD;AAAvC,8GAAA,eAAe,OAAA;AACxB,uCAA0C;AAAjC,wGAAA,YAAY,OAAA;AAErB,SAAS;AACT,qCAAsC;AACtC,yCAA0C;AAC1C,+CAAgD;AAChD,yCAA0C;AAQ1C,SAAgB,gBAAgB,CAAC,MAAkC;IACjE,OAAO,IAAI,mBAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,SAAgB,kBAAkB,CAAC,MAAoC;IACrE,OAAO,IAAI,uBAAY,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,SAAgB,qBAAqB,CAAC,MAAuC;IAC3E,OAAO,IAAI,6BAAe,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AAED,SAAgB,kBAAkB,CAAC,MAAoC;IACrE,OAAO,IAAI,uBAAY,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * 性能门禁
3
+ *
4
+ * 检查性能指标:
5
+ * - 响应时间
6
+ * - 内存使用
7
+ * - 测试覆盖率
8
+ * - 打包大小
9
+ *
10
+ * 改进:
11
+ * - 添加超时机制
12
+ * - 改进错误处理
13
+ * - 返回详细的错误信息
14
+ */
15
+ import type { GateResult, GateContext, PerformanceGateConfig, PerformanceThresholds } from './types';
16
+ /**
17
+ * 性能门禁配置
18
+ */
19
+ export interface ExtendedPerformanceGateConfig extends PerformanceGateConfig {
20
+ /** 覆盖率测试超时(毫秒) */
21
+ coverageTimeout?: number;
22
+ /** 基准测试超时(毫秒) */
23
+ benchmarkTimeout?: number;
24
+ }
25
+ /**
26
+ * 性能门禁
27
+ */
28
+ export declare class PerformanceGate {
29
+ private config;
30
+ constructor(config?: Partial<ExtendedPerformanceGateConfig>);
31
+ /**
32
+ * 检查性能
33
+ */
34
+ check(context: GateContext): Promise<GateResult>;
35
+ /**
36
+ * 收集性能指标
37
+ */
38
+ private collectMetrics;
39
+ /**
40
+ * 收集测试覆盖率(带超时)
41
+ */
42
+ private collectCoverage;
43
+ /**
44
+ * 收集打包大小
45
+ */
46
+ private collectBundleSize;
47
+ /**
48
+ * 格式化指标输出
49
+ */
50
+ private formatMetrics;
51
+ /**
52
+ * 运行基准测试(带超时)
53
+ */
54
+ runBenchmark(context: GateContext): Promise<{
55
+ avgResponseTime: number;
56
+ avgMemoryUsage: number;
57
+ minResponseTime: number;
58
+ maxResponseTime: number;
59
+ error?: string;
60
+ }>;
61
+ /**
62
+ * 单次基准测试(带超时)
63
+ */
64
+ private singleBenchmark;
65
+ /**
66
+ * 设置阈值
67
+ */
68
+ setThresholds(thresholds: Partial<PerformanceThresholds>): void;
69
+ /**
70
+ * 设置超时时间
71
+ */
72
+ setTimeouts(options: {
73
+ coverage?: number;
74
+ benchmark?: number;
75
+ }): void;
76
+ /**
77
+ * 获取配置
78
+ */
79
+ getConfig(): Required<ExtendedPerformanceGateConfig>;
80
+ }
81
+ //# sourceMappingURL=performance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performance.d.ts","sourceRoot":"","sources":["../../src/gates/performance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAa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