@dommaker/harness 4.0.1 → 5.0.0
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 +7 -8
- package/dist/bootstrap/bootstrap.d.ts +15 -0
- package/dist/bootstrap/bootstrap.js +18 -1
- package/dist/bootstrap/index.d.ts +2 -2
- package/dist/bootstrap/index.js +3 -2
- package/dist/cli/commands/acceptance.d.ts +8 -0
- package/dist/cli/commands/acceptance.js +45 -24
- package/dist/cli/commands/check.d.ts +2 -0
- package/dist/cli/commands/check.js +36 -5
- package/dist/cli/commands/command.js +1 -1
- package/dist/cli/commands/definitions.js +4 -1
- package/dist/cli/commands/release.d.ts +11 -3
- package/dist/cli/commands/release.js +159 -52
- package/dist/cli/commands/report.d.ts +2 -0
- package/dist/cli/commands/report.js +54 -6
- package/dist/cli/commands/security.d.ts +3 -3
- package/dist/cli/commands/security.js +3 -2
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +3 -40
- package/dist/cli/commands/sync-docs/capabilities-syncer.js +5 -159
- package/dist/cli/commands/sync-docs/compact.js +2 -2
- package/dist/cli/commands/sync-docs/context-syncer.d.ts +4 -36
- package/dist/cli/commands/sync-docs/context-syncer.js +4 -221
- package/dist/cli/commands/sync-docs/index.d.ts +8 -8
- package/dist/cli/commands/sync-docs/index.js +8 -8
- package/dist/cli/commands/sync-docs/main-flow.d.ts +5 -4
- package/dist/cli/commands/sync-docs/main-flow.js +6 -5
- package/dist/cli/commands/sync-docs/sync-output.d.ts +1 -1
- package/dist/cli/commands/sync-docs/sync-output.js +4 -0
- package/dist/cli/commands/sync-docs/sync-writes.d.ts +1 -1
- package/dist/cli/commands/validate.d.ts +2 -0
- package/dist/cli/commands/validate.js +40 -1
- package/dist/core/command-execution-policy.d.ts +59 -0
- package/dist/core/command-execution-policy.js +167 -0
- package/dist/core/config-files.d.ts +8 -0
- package/dist/core/config-files.js +62 -0
- package/dist/core/constraints/capabilities-parser.d.ts +2 -1
- package/dist/core/constraints/capabilities-parser.js +2 -1
- package/dist/core/constraints/checker.d.ts +18 -6
- package/dist/core/constraints/checker.js +21 -11
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js +14 -15
- package/dist/core/constraints/checkers/no-test-simplification.js +8 -6
- package/dist/core/constraints/checkers/templated/exec.d.ts +4 -0
- package/dist/core/constraints/checkers/templated/exec.js +11 -48
- package/dist/core/constraints/checkers/templated/file-exists.js +7 -4
- package/dist/core/constraints/checkers/templated/regex-scan.js +11 -15
- package/dist/core/constraints/checkers/types.d.ts +13 -2
- package/dist/core/constraints/checkers/types.js +5 -2
- package/dist/core/constraints/construction-sites.d.ts +1 -1
- package/dist/core/constraints/construction-sites.js +1 -1
- package/dist/core/constraints/definitions.d.ts +2 -2
- package/dist/core/constraints/definitions.js +2 -2
- package/dist/core/constraints/injection-writer.d.ts +1 -1
- package/dist/core/constraints/injection-writer.js +1 -1
- package/dist/core/constraints/project-snapshot.d.ts +43 -0
- package/dist/core/constraints/project-snapshot.js +103 -0
- package/dist/core/constraints/run-env.d.ts +35 -0
- package/dist/core/constraints/run-env.js +36 -0
- package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.d.ts +2 -0
- package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.js +5 -3
- package/dist/core/docs-sync/capabilities-table.d.ts +46 -0
- package/dist/core/docs-sync/capabilities-table.js +200 -0
- package/dist/core/docs-sync/context-collector.d.ts +40 -0
- package/dist/core/docs-sync/context-collector.js +227 -0
- package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.d.ts +5 -1
- package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.js +10 -6
- package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.d.ts +15 -9
- package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.js +26 -29
- package/dist/core/effective-constraints.d.ts +1 -1
- package/dist/core/effective-constraints.js +1 -1
- package/dist/core/validators/check-handlers/command.js +22 -0
- package/dist/core/validators/check-handlers/output.js +26 -3
- package/dist/core/validators/checkpoint.d.ts +4 -0
- package/dist/core/validators/checkpoint.js +10 -2
- package/dist/gates/acceptance.d.ts +8 -4
- package/dist/gates/acceptance.js +76 -14
- package/dist/gates/command.d.ts +3 -4
- package/dist/gates/command.js +2 -3
- package/dist/gates/contract.d.ts +3 -4
- package/dist/gates/contract.js +0 -1
- package/dist/gates/definitions.d.ts +2 -4
- package/dist/gates/definitions.js +2 -8
- package/dist/gates/performance.d.ts +10 -4
- package/dist/gates/performance.js +49 -5
- package/dist/gates/review.d.ts +3 -4
- package/dist/gates/review.js +0 -1
- package/dist/gates/security.d.ts +3 -4
- package/dist/gates/security.js +26 -19
- package/dist/gates/types.d.ts +46 -19
- package/dist/index.d.ts +5 -4
- package/dist/index.js +9 -6
- package/dist/knowledge/index.d.ts +1 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/ingest.d.ts +32 -17
- package/dist/knowledge/ingest.js +188 -90
- package/dist/knowledge/lifecycle.d.ts +15 -0
- package/dist/knowledge/lifecycle.js +62 -0
- package/dist/knowledge/query.d.ts +11 -1
- package/dist/knowledge/query.js +61 -9
- package/dist/knowledge/store.d.ts +56 -3
- package/dist/knowledge/store.js +108 -30
- package/dist/monitoring/index.d.ts +2 -1
- package/dist/monitoring/index.js +3 -1
- package/dist/monitoring/traces.d.ts +12 -0
- package/dist/monitoring/traces.js +26 -4
- package/dist/types/checkpoint.d.ts +28 -1
- package/dist/types/command-execution-policy.d.ts +73 -0
- package/dist/types/command-execution-policy.js +16 -0
- package/dist/types/constraint.d.ts +0 -12
- package/dist/utils/exec.d.ts +7 -1
- package/dist/utils/exec.js +7 -1
- package/package.json +1 -1
- package/dist/core/constraints/check-cache.d.ts +0 -43
- package/dist/core/constraints/check-cache.js +0 -77
- package/dist/core/constraints/checkers/templated/glob.d.ts +0 -8
- package/dist/core/constraints/checkers/templated/glob.js +0 -14
- /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.d.ts +0 -0
- /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.js +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* sync-docs
|
|
3
|
+
* sync-docs 的「采集 → 判定」主入口(ADR-0040 Phase 3 拆段;P2.8 自
|
|
4
|
+
* cli/commands/sync-docs/ 下沉 core/docs-sync/,handoff P2 第 4 项:
|
|
5
|
+
* 文档同步模块负责采集与判定,CLI 只保留输出)
|
|
4
6
|
*
|
|
5
7
|
* - collectSyncState:扫描源码模块 → CAPABILITIES.md 两种格式判定与对比 →
|
|
6
8
|
* CONTEXT.md 缺失/漂移/mtime → AGENTS.md 期望内容 → 表格排版,全部收成一枚 SyncState;
|
|
7
9
|
* - judgeSyncState:SyncState → 问题旗标组(hasIssues 族)与可定位的漂移 reason。
|
|
8
|
-
* 出口(JSON
|
|
9
|
-
*
|
|
10
|
+
* 出口(JSON/人读输出、写入自愈)住 cli/commands/sync-docs/ 的 sync-output.ts /
|
|
11
|
+
* sync-writes.ts;「未找到 srcDir」警告属输出职责,由输出侧从 missingSrcDirs 打印。
|
|
10
12
|
*/
|
|
11
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
14
|
if (k2 === undefined) k2 = k;
|
|
@@ -41,33 +43,27 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
41
43
|
return result;
|
|
42
44
|
};
|
|
43
45
|
})();
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
47
|
exports.collectSyncState = collectSyncState;
|
|
49
48
|
exports.judgeSyncState = judgeSyncState;
|
|
50
49
|
const fs = __importStar(require("fs/promises"));
|
|
51
50
|
const fs_1 = require("fs");
|
|
52
51
|
const path = __importStar(require("path"));
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const governance_accessors_1 = require("../../../core/constraints/governance-accessors");
|
|
52
|
+
const capabilities_parser_1 = require("../constraints/capabilities-parser");
|
|
53
|
+
const capabilities_reconcile_1 = require("../constraints/capabilities-reconcile");
|
|
54
|
+
const context_reconcile_1 = require("../constraints/context-reconcile");
|
|
55
|
+
const construction_sites_1 = require("../constraints/construction-sites");
|
|
56
|
+
const detect_source_roots_1 = require("../../utils/detect-source-roots");
|
|
57
|
+
const governance_accessors_1 = require("../constraints/governance-accessors");
|
|
60
58
|
const project_reader_1 = require("./project-reader");
|
|
61
|
-
const
|
|
62
|
-
const
|
|
59
|
+
const capabilities_table_1 = require("./capabilities-table");
|
|
60
|
+
const context_collector_1 = require("./context-collector");
|
|
63
61
|
const agents_syncer_1 = require("./agents-syncer");
|
|
64
62
|
const preserve_block_1 = require("./preserve-block");
|
|
65
|
-
const command_contract_1 = require("../../command-contract");
|
|
66
63
|
/**
|
|
67
|
-
*
|
|
64
|
+
* 采集段:扫描与全部判定面数据收集(不写任何文件、不打印——纯采集+判定)
|
|
68
65
|
*/
|
|
69
|
-
async function collectSyncState(projectPath, options,
|
|
70
|
-
const isJson = options.json === true;
|
|
66
|
+
async function collectSyncState(projectPath, options, definitions) {
|
|
71
67
|
const capsMode = (0, governance_accessors_1.getCapabilitiesMode)(projectPath);
|
|
72
68
|
const result = {
|
|
73
69
|
added: [],
|
|
@@ -91,20 +87,20 @@ async function collectSyncState(projectPath, options, io, definitions) {
|
|
|
91
87
|
capsIsCapabilityListing = true;
|
|
92
88
|
}
|
|
93
89
|
else {
|
|
94
|
-
existingFiles = await (0,
|
|
90
|
+
existingFiles = await (0, capabilities_table_1.parseCapabilitiesFiles)(capabilitiesPath);
|
|
95
91
|
}
|
|
96
92
|
}
|
|
97
93
|
// 2. 扫描源码模块(从 governance config 读取目录列表,默认 src/)
|
|
98
94
|
// capability-listing 格式不做条目级比对(计数才是判定面),模块清单在本次运行里无人
|
|
99
95
|
// 消费 → 整树一份 .ts 内容都不读(harness#147;改造前是无条件全树逐文件读首行注释)。
|
|
100
96
|
const currentModules = [];
|
|
97
|
+
const missingSrcDirs = [];
|
|
101
98
|
if (!capsIsCapabilityListing) {
|
|
102
99
|
for (const srcDir of srcDirs) {
|
|
103
|
-
// 目录缺失 =
|
|
100
|
+
// 目录缺失 = 未配置该源码根(采集跳过并记入 state,提示由输出侧打出);
|
|
101
|
+
// 目录在而扫描失败 = 真故障,抛出
|
|
104
102
|
if (!(0, fs_1.existsSync)(path.join(projectPath, srcDir))) {
|
|
105
|
-
|
|
106
|
-
(0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ 未找到 ${srcDir} 目录,跳过`));
|
|
107
|
-
}
|
|
103
|
+
missingSrcDirs.push(srcDir);
|
|
108
104
|
continue;
|
|
109
105
|
}
|
|
110
106
|
const modules = await (0, project_reader_1.scanSourceModules)(path.join(projectPath, srcDir), projectPath);
|
|
@@ -155,13 +151,13 @@ async function collectSyncState(projectPath, options, io, definitions) {
|
|
|
155
151
|
// 构造点计数器懒建(harness#202):全仓走一遍不便宜,只在某份文档真带
|
|
156
152
|
// construction-sites 标记时才采集,一次运行内按口径 memo 共用。
|
|
157
153
|
let constructionCounter = null;
|
|
158
|
-
const existingContextFiles = await (0,
|
|
154
|
+
const existingContextFiles = await (0, context_collector_1.findExistingContextFiles)(projectPath, srcDirs);
|
|
159
155
|
for (const dir of existingContextFiles) {
|
|
160
156
|
const contextPath = path.join(projectPath, dir, 'CONTEXT.md');
|
|
161
157
|
// fail-fast:dir 来自 findExistingContextFiles 的实况扫描,读/判定失败是真故障,
|
|
162
158
|
// 抛出不跳过——静默跳过会让漂移判定漏报
|
|
163
159
|
const contextMd = await fs.readFile(contextPath, 'utf-8');
|
|
164
|
-
const { surface, barrelExports } = await (0,
|
|
160
|
+
const { surface, barrelExports } = await (0, context_collector_1.collectContextExportSurface)(path.join(projectPath, dir), projectPath);
|
|
165
161
|
const verdict = (0, context_reconcile_1.reconcileContext)({
|
|
166
162
|
contextMdContent: contextMd,
|
|
167
163
|
exportSurface: surface,
|
|
@@ -172,7 +168,7 @@ async function collectSyncState(projectPath, options, io, definitions) {
|
|
|
172
168
|
const siteDrift = markers.length > 0
|
|
173
169
|
? (0, construction_sites_1.reconcileConstructionSites)({
|
|
174
170
|
markers,
|
|
175
|
-
countFor: (constructionCounter ??= (0,
|
|
171
|
+
countFor: (constructionCounter ??= (0, context_collector_1.createConstructionSiteCounter)(projectPath)),
|
|
176
172
|
}).drift
|
|
177
173
|
: [];
|
|
178
174
|
if (verdict.ghosts.length > 0 ||
|
|
@@ -187,7 +183,7 @@ async function collectSyncState(projectPath, options, io, definitions) {
|
|
|
187
183
|
}
|
|
188
184
|
if (!isCi) {
|
|
189
185
|
const contextStat = await fs.stat(contextPath);
|
|
190
|
-
const latestTsMtime = await (0,
|
|
186
|
+
const latestTsMtime = await (0, context_collector_1.getLatestTsMtime)(path.join(projectPath, dir));
|
|
191
187
|
if (latestTsMtime && latestTsMtime > contextStat.mtimeMs) {
|
|
192
188
|
result.contextStale.push(dir);
|
|
193
189
|
}
|
|
@@ -219,7 +215,7 @@ async function collectSyncState(projectPath, options, io, definitions) {
|
|
|
219
215
|
// 判定与修复共用 normalizeCapabilitiesTableLayout 正本——同一份规则,check 报的 fix 必清得掉。
|
|
220
216
|
const tableLayout = capsIsCapabilityListing
|
|
221
217
|
? { blankLines: 0, emptyTables: 0 }
|
|
222
|
-
: (0,
|
|
218
|
+
: (0, capabilities_table_1.normalizeCapabilitiesTableLayout)(capsContent);
|
|
223
219
|
return {
|
|
224
220
|
projectPath,
|
|
225
221
|
capsMode,
|
|
@@ -235,6 +231,7 @@ async function collectSyncState(projectPath, options, io, definitions) {
|
|
|
235
231
|
agentsMdStale,
|
|
236
232
|
agentsMdMalformedPreserve,
|
|
237
233
|
tableLayout,
|
|
234
|
+
missingSrcDirs,
|
|
238
235
|
};
|
|
239
236
|
}
|
|
240
237
|
/**
|
|
@@ -10,7 +10,7 @@ import type { Constraint } from '../types/constraint';
|
|
|
10
10
|
import type { MergedConstraintsConfig } from '../types/project-config';
|
|
11
11
|
import type { RunTarget } from './constraints/run-env';
|
|
12
12
|
/**
|
|
13
|
-
* 获取项目当前生效的约束集(check 全量,带
|
|
13
|
+
* 获取项目当前生效的约束集(check 全量,带 severity/channel)
|
|
14
14
|
*
|
|
15
15
|
* 生效集链路同 getMergedConstraintsConfig:内置 → preset 裁剪 → config.yml
|
|
16
16
|
* `constraints.<id>.enabled:false` 删除。
|
|
@@ -14,7 +14,7 @@ exports.getMergedConstraintsConfig = getMergedConstraintsConfig;
|
|
|
14
14
|
exports.lintEffectiveConfig = lintEffectiveConfig;
|
|
15
15
|
const project_config_loader_1 = require("./project-config-loader");
|
|
16
16
|
/**
|
|
17
|
-
* 获取项目当前生效的约束集(check 全量,带
|
|
17
|
+
* 获取项目当前生效的约束集(check 全量,带 severity/channel)
|
|
18
18
|
*
|
|
19
19
|
* 生效集链路同 getMergedConstraintsConfig:内置 → preset 裁剪 → config.yml
|
|
20
20
|
* `constraints.<id>.enabled:false` 删除。
|
|
@@ -9,6 +9,22 @@ const child_process_1 = require("child_process");
|
|
|
9
9
|
const exec_1 = require("../../../utils/exec");
|
|
10
10
|
const error_1 = require("../../../utils/error");
|
|
11
11
|
const fail_result_1 = require("./fail-result");
|
|
12
|
+
/**
|
|
13
|
+
* read-only 策略跳过:声明命令未执行,三态 skipped(passed=false + skipReason)。
|
|
14
|
+
* 跳过原因由策略统一措辞,handler 只透传。
|
|
15
|
+
*/
|
|
16
|
+
function skippedForReadOnly(checkId, command, context) {
|
|
17
|
+
const policy = context.commandPolicy;
|
|
18
|
+
if (!policy?.readOnly)
|
|
19
|
+
return null;
|
|
20
|
+
return {
|
|
21
|
+
checkId,
|
|
22
|
+
passed: false,
|
|
23
|
+
skipped: true,
|
|
24
|
+
skipReason: policy.skipReason(command),
|
|
25
|
+
message: `跳过检查(命令未执行): ${command}`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
12
28
|
/**
|
|
13
29
|
* 失败时回带的输出末段字节数。
|
|
14
30
|
*
|
|
@@ -38,6 +54,9 @@ function runForExitCode(command, cwd) {
|
|
|
38
54
|
}
|
|
39
55
|
async function checkCommandSuccess(check, context) {
|
|
40
56
|
const command = check.config.command;
|
|
57
|
+
const skipped = skippedForReadOnly(check.id, command, context);
|
|
58
|
+
if (skipped)
|
|
59
|
+
return skipped;
|
|
41
60
|
try {
|
|
42
61
|
const { code, tail } = await runForExitCode(command, context.workdir);
|
|
43
62
|
if (code === 0) {
|
|
@@ -66,6 +85,9 @@ async function checkCommandSuccess(check, context) {
|
|
|
66
85
|
async function checkCommandOutput(check, context) {
|
|
67
86
|
const command = check.config.command;
|
|
68
87
|
const expected = String(check.config.expected);
|
|
88
|
+
const skipped = skippedForReadOnly(check.id, command, context);
|
|
89
|
+
if (skipped)
|
|
90
|
+
return skipped;
|
|
69
91
|
try {
|
|
70
92
|
const { stdout } = await (0, exec_1.execAsync)(command, { cwd: context.workdir });
|
|
71
93
|
const actual = stdout.trim();
|
|
@@ -28,6 +28,9 @@ function stringifyOutput(output) {
|
|
|
28
28
|
/**
|
|
29
29
|
* 取得待检查的输出:context.output 优先;未提供且配置了 command 时执行之。
|
|
30
30
|
* 返回 [输出文本, 命令执行错误(若有)]
|
|
31
|
+
*
|
|
32
|
+
* read-only 策略(D3):context.output 未提供且需执行 command 时,不执行,
|
|
33
|
+
* 返回 skipped 原因(三态),由各 output_* 族译成 skipped 的 CheckResult。
|
|
31
34
|
*/
|
|
32
35
|
async function resolveOutput(check, context) {
|
|
33
36
|
if (context.output !== undefined && context.output !== null) {
|
|
@@ -35,6 +38,10 @@ async function resolveOutput(check, context) {
|
|
|
35
38
|
}
|
|
36
39
|
const command = check.config.command;
|
|
37
40
|
if (typeof command === 'string' && command.length > 0) {
|
|
41
|
+
const policy = context.commandPolicy;
|
|
42
|
+
if (policy?.readOnly) {
|
|
43
|
+
return { output: '', skipReason: policy.skipReason(command) };
|
|
44
|
+
}
|
|
38
45
|
try {
|
|
39
46
|
const { stdout } = await (0, exec_1.execAsync)(command, { cwd: context.workdir });
|
|
40
47
|
return { output: stdout };
|
|
@@ -46,8 +53,20 @@ async function resolveOutput(check, context) {
|
|
|
46
53
|
}
|
|
47
54
|
return { output: '' };
|
|
48
55
|
}
|
|
56
|
+
/** output_* 族共用的 read-only 跳过结果(resolveOutput 报出 skipReason 时) */
|
|
57
|
+
function skippedFromResolve(checkId, command, skipReason) {
|
|
58
|
+
return {
|
|
59
|
+
checkId,
|
|
60
|
+
passed: false,
|
|
61
|
+
skipped: true,
|
|
62
|
+
skipReason,
|
|
63
|
+
message: `跳过检查(命令未执行): ${command ?? ''}`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
49
66
|
async function checkOutputContains(check, context) {
|
|
50
|
-
const { output, commandError } = await resolveOutput(check, context);
|
|
67
|
+
const { output, commandError, skipReason } = await resolveOutput(check, context);
|
|
68
|
+
if (skipReason)
|
|
69
|
+
return skippedFromResolve(check.id, check.config.command, skipReason);
|
|
51
70
|
if (commandError) {
|
|
52
71
|
return (0, fail_result_1.failResult)(check.id, `命令执行失败: ${check.config.command}`, commandError, 'exit code 0');
|
|
53
72
|
}
|
|
@@ -63,7 +82,9 @@ async function checkOutputContains(check, context) {
|
|
|
63
82
|
};
|
|
64
83
|
}
|
|
65
84
|
async function checkOutputNotContains(check, context) {
|
|
66
|
-
const { output, commandError } = await resolveOutput(check, context);
|
|
85
|
+
const { output, commandError, skipReason } = await resolveOutput(check, context);
|
|
86
|
+
if (skipReason)
|
|
87
|
+
return skippedFromResolve(check.id, check.config.command, skipReason);
|
|
67
88
|
if (commandError) {
|
|
68
89
|
return (0, fail_result_1.failResult)(check.id, `命令执行失败: ${check.config.command}`, commandError, 'exit code 0');
|
|
69
90
|
}
|
|
@@ -79,7 +100,9 @@ async function checkOutputNotContains(check, context) {
|
|
|
79
100
|
};
|
|
80
101
|
}
|
|
81
102
|
async function checkOutputMatches(check, context) {
|
|
82
|
-
const { output, commandError } = await resolveOutput(check, context);
|
|
103
|
+
const { output, commandError, skipReason } = await resolveOutput(check, context);
|
|
104
|
+
if (skipReason)
|
|
105
|
+
return skippedFromResolve(check.id, check.config.command, skipReason);
|
|
83
106
|
if (commandError) {
|
|
84
107
|
return (0, fail_result_1.failResult)(check.id, `命令执行失败: ${check.config.command}`, commandError, 'exit code 0');
|
|
85
108
|
}
|
|
@@ -20,6 +20,10 @@ export declare function assertCheckpointShape(data: unknown, source: string): as
|
|
|
20
20
|
export declare class CheckpointValidator {
|
|
21
21
|
/**
|
|
22
22
|
* 验证检查点
|
|
23
|
+
*
|
|
24
|
+
* 三态聚合(D3):失败优先——有任何失败项 → passed=false(原有语义);
|
|
25
|
+
* 无失败但有未评估项(read-only 下命令未执行)→ passed=false + skipped=true
|
|
26
|
+
* (「未完整验证」,不把跳过当通过);全部通过 → passed=true。
|
|
23
27
|
*/
|
|
24
28
|
validate(checkpoint: Checkpoint, context: CheckpointContext): Promise<CheckpointResult>;
|
|
25
29
|
/**
|
|
@@ -75,6 +75,10 @@ function assertCheckpointShape(data, source) {
|
|
|
75
75
|
class CheckpointValidator {
|
|
76
76
|
/**
|
|
77
77
|
* 验证检查点
|
|
78
|
+
*
|
|
79
|
+
* 三态聚合(D3):失败优先——有任何失败项 → passed=false(原有语义);
|
|
80
|
+
* 无失败但有未评估项(read-only 下命令未执行)→ passed=false + skipped=true
|
|
81
|
+
* (「未完整验证」,不把跳过当通过);全部通过 → passed=true。
|
|
78
82
|
*/
|
|
79
83
|
async validate(checkpoint, context) {
|
|
80
84
|
if (!checkpoint.checks || checkpoint.checks.length === 0) {
|
|
@@ -91,12 +95,16 @@ class CheckpointValidator {
|
|
|
91
95
|
const result = await this.executeCheck(check, context);
|
|
92
96
|
results.push(result);
|
|
93
97
|
}
|
|
94
|
-
const
|
|
98
|
+
const anyFailed = results.some(r => !r.passed && !r.skipped);
|
|
99
|
+
const anySkipped = results.some(r => r.skipped);
|
|
100
|
+
const allPassed = !anyFailed && !anySkipped;
|
|
95
101
|
return {
|
|
96
102
|
checkpointId: checkpoint.id,
|
|
97
103
|
passed: allPassed,
|
|
104
|
+
skipped: anySkipped && !anyFailed ? true : undefined,
|
|
105
|
+
skipReason: anySkipped && !anyFailed ? '存在未执行的检查(--read-only,命令未执行)' : undefined,
|
|
98
106
|
checks: results,
|
|
99
|
-
message:
|
|
107
|
+
message: anyFailed ? '检查点验证失败' : anySkipped ? '检查点跳过评估(存在未执行的检查)' : '检查点验证通过',
|
|
100
108
|
validatedAt: new Date(),
|
|
101
109
|
};
|
|
102
110
|
}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* 1. 验证任务是否满足验收标准
|
|
6
6
|
* 2. 解析 tasks.yml 中的验收条件(只认新契约 `acceptance`;旧的逐条勾选
|
|
7
7
|
* 格式已随 gates 层现代化删除,不再兼容)
|
|
8
|
-
* 3. 运行关联的 E2E
|
|
8
|
+
* 3. 运行关联的 E2E 测试(可信命令串解析为 argv 前缀 + 不可信数据作 argv
|
|
9
|
+
* 元素,execFile 不经 shell——信任边界见 tokenizeCommand)
|
|
9
10
|
*
|
|
10
11
|
* 验收条件判定(唯一契约):`checked: true` → 满足;未勾选且带 `e2e_test`
|
|
11
12
|
* → 跑 E2E 按测试结论判定;未勾选且无 `e2e_test` → 不满足(判负,不静默放过)。
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
* });
|
|
23
24
|
* ```
|
|
24
25
|
*/
|
|
25
|
-
import type { Gate,
|
|
26
|
+
import type { Gate, GateDecision, SpecAcceptanceGateConfig, AcceptanceGateContext } from './types';
|
|
26
27
|
/**
|
|
27
28
|
* 验收门禁结果 details 负载(type alias 而非 interface:
|
|
28
29
|
* 需要隐式索引签名以直接赋给 GateResult.details 的 Record 形状)
|
|
@@ -62,7 +63,6 @@ export interface E2ETestResult {
|
|
|
62
63
|
*/
|
|
63
64
|
export declare class SpecAcceptanceGate implements Gate {
|
|
64
65
|
readonly id = "acceptance";
|
|
65
|
-
order: number;
|
|
66
66
|
private config;
|
|
67
67
|
constructor(config?: Partial<SpecAcceptanceGateConfig>);
|
|
68
68
|
/**
|
|
@@ -70,7 +70,7 @@ export declare class SpecAcceptanceGate implements Gate {
|
|
|
70
70
|
* AcceptanceGateResult 无 gate 字段,此处经 gateResult 构造器归一化为 GateResult
|
|
71
71
|
* 报告结构(本层约定不手拼 GateResult 字面量)。
|
|
72
72
|
*/
|
|
73
|
-
evaluate(context:
|
|
73
|
+
evaluate(context: AcceptanceGateContext): Promise<GateDecision>;
|
|
74
74
|
/**
|
|
75
75
|
* 检查验收标准(fail-fast:解析/校验失败直接抛出,不拼错误报告)
|
|
76
76
|
*/
|
|
@@ -101,6 +101,10 @@ export declare class SpecAcceptanceGate implements Gate {
|
|
|
101
101
|
/**
|
|
102
102
|
* 运行 E2E 测试
|
|
103
103
|
*
|
|
104
|
+
* 信任边界(D1):e2eTestCommand(可信配置)经 tokenizeCommand 拆成 argv 前缀;
|
|
105
|
+
* tasks.yml 的 testFile / testName(不可信数据)只作为 argv 数组元素追加,经
|
|
106
|
+
* execFileAsync(不经 shell)执行——特殊字符只能是单个参数的字面内容。
|
|
107
|
+
*
|
|
104
108
|
* 退出码非零 / 超时 = 测试判负(报告层 fail,不是门禁异常);
|
|
105
109
|
* 文本只能否决不能反向加分(与 passes-gate 同一判定入口,ADR-0014)。
|
|
106
110
|
*/
|
package/dist/gates/acceptance.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* 1. 验证任务是否满足验收标准
|
|
7
7
|
* 2. 解析 tasks.yml 中的验收条件(只认新契约 `acceptance`;旧的逐条勾选
|
|
8
8
|
* 格式已随 gates 层现代化删除,不再兼容)
|
|
9
|
-
* 3. 运行关联的 E2E
|
|
9
|
+
* 3. 运行关联的 E2E 测试(可信命令串解析为 argv 前缀 + 不可信数据作 argv
|
|
10
|
+
* 元素,execFile 不经 shell——信任边界见 tokenizeCommand)
|
|
10
11
|
*
|
|
11
12
|
* 验收条件判定(唯一契约):`checked: true` → 满足;未勾选且带 `e2e_test`
|
|
12
13
|
* → 跑 E2E 按测试结论判定;未勾选且无 `e2e_test` → 不满足(判负,不静默放过)。
|
|
@@ -69,12 +70,77 @@ const types_1 = require("./types");
|
|
|
69
70
|
const decision_1 = require("./decision");
|
|
70
71
|
const tasks_file_1 = require("./tasks-file");
|
|
71
72
|
// ==================== SpecAcceptanceGate 类 ====================
|
|
73
|
+
/**
|
|
74
|
+
* 解析可信命令配置串为 argv token(shell 词法子集,仅服务 e2eTestCommand)
|
|
75
|
+
*
|
|
76
|
+
* 信任边界(D1):e2eTestCommand 是可信配置(与 tasks.yml 数据不同源),允许
|
|
77
|
+
* 持有 shell 风格的引号/转义形态(如 `npm run test:e2e -- --project "chromium x"`)。
|
|
78
|
+
* 这里把整串按 shell 词法子集拆成 token:未引用空白分词;'...' 全字面;
|
|
79
|
+
* "..." 成组、仅 \" 与 \\ 转义;其余位置 \ 转义下一字符;引号未闭合即抛错。
|
|
80
|
+
* 拆出的 token 只作 argv 前缀,后续不可信数据(e2e_test / test_name)作为
|
|
81
|
+
* argv 数组元素追加——execFile 不经 shell,任何字符都只可能成为单个参数的
|
|
82
|
+
* 字面内容,不会触发 shell 解释、也不会被拆成多个参数。
|
|
83
|
+
*/
|
|
84
|
+
function tokenizeCommand(command) {
|
|
85
|
+
const tokens = [];
|
|
86
|
+
let current = '';
|
|
87
|
+
let hasContent = false;
|
|
88
|
+
let quote = null;
|
|
89
|
+
for (let i = 0; i < command.length; i++) {
|
|
90
|
+
const ch = command[i];
|
|
91
|
+
if (quote === "'") {
|
|
92
|
+
if (ch === "'")
|
|
93
|
+
quote = null;
|
|
94
|
+
else
|
|
95
|
+
current += ch;
|
|
96
|
+
}
|
|
97
|
+
else if (quote === '"') {
|
|
98
|
+
if (ch === '"')
|
|
99
|
+
quote = null;
|
|
100
|
+
else if (ch === '\\' && (command[i + 1] === '"' || command[i + 1] === '\\')) {
|
|
101
|
+
current += command[i + 1];
|
|
102
|
+
i++;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
current += ch;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else if (ch === "'" || ch === '"') {
|
|
109
|
+
quote = ch;
|
|
110
|
+
hasContent = true;
|
|
111
|
+
}
|
|
112
|
+
else if (ch === '\\') {
|
|
113
|
+
hasContent = true;
|
|
114
|
+
current += command[i + 1] ?? '';
|
|
115
|
+
i++;
|
|
116
|
+
}
|
|
117
|
+
else if (/\s/.test(ch)) {
|
|
118
|
+
if (hasContent) {
|
|
119
|
+
tokens.push(current);
|
|
120
|
+
current = '';
|
|
121
|
+
hasContent = false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
current += ch;
|
|
126
|
+
hasContent = true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (quote !== null) {
|
|
130
|
+
throw new Error(`e2eTestCommand 引号未闭合(配置非法): ${command}`);
|
|
131
|
+
}
|
|
132
|
+
if (hasContent)
|
|
133
|
+
tokens.push(current);
|
|
134
|
+
if (tokens.length === 0) {
|
|
135
|
+
throw new Error('e2eTestCommand 为空(配置非法)');
|
|
136
|
+
}
|
|
137
|
+
return tokens;
|
|
138
|
+
}
|
|
72
139
|
/**
|
|
73
140
|
* 验收标准门禁
|
|
74
141
|
*/
|
|
75
142
|
class SpecAcceptanceGate {
|
|
76
143
|
id = 'acceptance';
|
|
77
|
-
order = 0;
|
|
78
144
|
config;
|
|
79
145
|
constructor(config) {
|
|
80
146
|
this.config = {
|
|
@@ -91,11 +157,7 @@ class SpecAcceptanceGate {
|
|
|
91
157
|
*/
|
|
92
158
|
async evaluate(context) {
|
|
93
159
|
const startedAt = Date.now();
|
|
94
|
-
const result = await this.check(
|
|
95
|
-
projectPath: context.projectPath,
|
|
96
|
-
taskId: context.taskId,
|
|
97
|
-
tasksPath: context.tasksPath,
|
|
98
|
-
});
|
|
160
|
+
const result = await this.check(context);
|
|
99
161
|
return (0, decision_1.decisionFromResult)((0, types_1.gateResult)('acceptance', result.passed, result.message, startedAt, result.details));
|
|
100
162
|
}
|
|
101
163
|
/**
|
|
@@ -282,19 +344,19 @@ class SpecAcceptanceGate {
|
|
|
282
344
|
/**
|
|
283
345
|
* 运行 E2E 测试
|
|
284
346
|
*
|
|
347
|
+
* 信任边界(D1):e2eTestCommand(可信配置)经 tokenizeCommand 拆成 argv 前缀;
|
|
348
|
+
* tasks.yml 的 testFile / testName(不可信数据)只作为 argv 数组元素追加,经
|
|
349
|
+
* execFileAsync(不经 shell)执行——特殊字符只能是单个参数的字面内容。
|
|
350
|
+
*
|
|
285
351
|
* 退出码非零 / 超时 = 测试判负(报告层 fail,不是门禁异常);
|
|
286
352
|
* 文本只能否决不能反向加分(与 passes-gate 同一判定入口,ADR-0014)。
|
|
287
353
|
*/
|
|
288
354
|
async runE2ETest(projectPath, testFile, testName) {
|
|
289
355
|
const timeout = this.config.e2eTestTimeout ?? 120000;
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
command += ` ${testFile}`;
|
|
293
|
-
if (testName) {
|
|
294
|
-
command += ` -g "${testName}"`;
|
|
295
|
-
}
|
|
356
|
+
const [file, ...baseArgs] = tokenizeCommand(this.config.e2eTestCommand ?? 'npx playwright test');
|
|
357
|
+
const args = [...baseArgs, testFile, ...(testName ? ['-g', testName] : [])];
|
|
296
358
|
try {
|
|
297
|
-
const { stdout, stderr } = await (0, exec_1.
|
|
359
|
+
const { stdout, stderr } = await (0, exec_1.execFileAsync)(file, args, {
|
|
298
360
|
cwd: projectPath,
|
|
299
361
|
timeout,
|
|
300
362
|
});
|
package/dist/gates/command.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* 检查命令是否安全,防止执行危险操作
|
|
6
6
|
*/
|
|
7
|
-
import type { GateResult, CommandGateConfig, CommandBlacklistRule, Gate,
|
|
7
|
+
import type { GateResult, CommandGateConfig, CommandBlacklistRule, Gate, CommandGateContext, GateDecision } from './types';
|
|
8
8
|
/**
|
|
9
9
|
* 黑名单级别(正本在 src/types/gate.ts,与 CommandBlacklistRule.level 同一定义)
|
|
10
10
|
*/
|
|
@@ -15,15 +15,14 @@ export { DEFAULT_COMMAND_BLACKLIST } from './blacklist-rules';
|
|
|
15
15
|
*/
|
|
16
16
|
export declare class CommandGate implements Gate {
|
|
17
17
|
readonly id = "command";
|
|
18
|
-
order: number;
|
|
19
18
|
private config;
|
|
20
19
|
private blacklist;
|
|
21
20
|
constructor(config?: Partial<CommandGateConfig>);
|
|
22
21
|
/**
|
|
23
22
|
* 统一门禁接口(G1):执行细节私有,决策三态由 check() 报告推导。
|
|
24
|
-
* 待检命令经
|
|
23
|
+
* 待检命令经 CommandGateContext.command 传入(必填)。
|
|
25
24
|
*/
|
|
26
|
-
evaluate(context:
|
|
25
|
+
evaluate(context: CommandGateContext): Promise<GateDecision>;
|
|
27
26
|
/**
|
|
28
27
|
* 检查命令
|
|
29
28
|
*/
|
package/dist/gates/command.js
CHANGED
|
@@ -19,7 +19,6 @@ Object.defineProperty(exports, "DEFAULT_COMMAND_BLACKLIST", { enumerable: true,
|
|
|
19
19
|
*/
|
|
20
20
|
class CommandGate {
|
|
21
21
|
id = 'command';
|
|
22
|
-
order = 0;
|
|
23
22
|
config;
|
|
24
23
|
blacklist;
|
|
25
24
|
constructor(config = {}) {
|
|
@@ -30,10 +29,10 @@ class CommandGate {
|
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
31
|
* 统一门禁接口(G1):执行细节私有,决策三态由 check() 报告推导。
|
|
33
|
-
* 待检命令经
|
|
32
|
+
* 待检命令经 CommandGateContext.command 传入(必填)。
|
|
34
33
|
*/
|
|
35
34
|
async evaluate(context) {
|
|
36
|
-
return (0, decision_1.decisionFromResult)(await this.check(context.command
|
|
35
|
+
return (0, decision_1.decisionFromResult)(await this.check(context.command));
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* 检查命令
|
package/dist/gates/contract.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* fail-fast:契约文件读取/解析失败直接抛出(外层归一为 deny 报告),
|
|
10
10
|
* 不再有「读不到旧契约就当零破坏性变更」的吞错兜底。
|
|
11
11
|
*/
|
|
12
|
-
import type { GateResult,
|
|
12
|
+
import type { GateResult, ContractGateContext, ContractGateConfig, Gate, GateDecision } from './types';
|
|
13
13
|
/** 破坏性变更条目 */
|
|
14
14
|
export interface BreakingChange {
|
|
15
15
|
type: string;
|
|
@@ -21,17 +21,16 @@ export interface BreakingChange {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare class ContractGate implements Gate {
|
|
23
23
|
readonly id = "contract";
|
|
24
|
-
order: number;
|
|
25
24
|
private config;
|
|
26
25
|
constructor(config?: Partial<ContractGateConfig>);
|
|
27
26
|
/**
|
|
28
27
|
* 统一门禁接口(G1):执行细节私有,决策三态由 check() 报告推导
|
|
29
28
|
*/
|
|
30
|
-
evaluate(context:
|
|
29
|
+
evaluate(context: ContractGateContext): Promise<GateDecision>;
|
|
31
30
|
/**
|
|
32
31
|
* 检查契约
|
|
33
32
|
*/
|
|
34
|
-
check(context:
|
|
33
|
+
check(context: ContractGateContext): Promise<GateResult>;
|
|
35
34
|
/**
|
|
36
35
|
* 验证契约格式:读取/解析失败直接抛出(fail-fast)。
|
|
37
36
|
*/
|
package/dist/gates/contract.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 门禁定义表(G1:定义即注册的单一定义源)
|
|
3
3
|
*
|
|
4
|
-
* - 每个门禁在此声明 id / description /
|
|
4
|
+
* - 每个门禁在此声明 id / description / CLI 元数据;
|
|
5
5
|
* 「定义↔实现」闭环由 `__tests__/definitions.test.ts` 断言(registry.ts 已删,
|
|
6
6
|
* 闭环保护改测试形状承载)。
|
|
7
7
|
* - CLI 元数据即 CommandDefinition(架构评审候选8,ADR-0007:形状对齐通用
|
|
@@ -24,12 +24,10 @@ export interface GateDefinition {
|
|
|
24
24
|
id: string;
|
|
25
25
|
/** 一句话描述 */
|
|
26
26
|
description: string;
|
|
27
|
-
/** 默认顺序(以此定义表为准,config.yml 无覆盖口——gates.order 生效集已删,ADR-0002「后续变更」),小者先执行 */
|
|
28
|
-
order: number;
|
|
29
27
|
/** CLI 元数据(形状 = CommandDefinition,bin/harness.js 通用引擎驱动生成) */
|
|
30
28
|
cli: CommandDefinition;
|
|
31
29
|
}
|
|
32
30
|
/**
|
|
33
|
-
* 6
|
|
31
|
+
* 6 门禁定义
|
|
34
32
|
*/
|
|
35
33
|
export declare const GATE_DEFINITIONS: GateDefinition[];
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* 门禁定义表(G1:定义即注册的单一定义源)
|
|
4
4
|
*
|
|
5
|
-
* - 每个门禁在此声明 id / description /
|
|
5
|
+
* - 每个门禁在此声明 id / description / CLI 元数据;
|
|
6
6
|
* 「定义↔实现」闭环由 `__tests__/definitions.test.ts` 断言(registry.ts 已删,
|
|
7
7
|
* 闭环保护改测试形状承载)。
|
|
8
8
|
* - CLI 元数据即 CommandDefinition(架构评审候选8,ADR-0007:形状对齐通用
|
|
@@ -20,13 +20,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.GATE_DEFINITIONS = void 0;
|
|
21
21
|
const numeric_flag_1 = require("../utils/numeric-flag");
|
|
22
22
|
/**
|
|
23
|
-
* 6
|
|
23
|
+
* 6 门禁定义
|
|
24
24
|
*/
|
|
25
25
|
exports.GATE_DEFINITIONS = [
|
|
26
26
|
{
|
|
27
27
|
id: 'acceptance',
|
|
28
28
|
description: '验收标准门控,检查任务是否满足验收标准',
|
|
29
|
-
order: 0,
|
|
30
29
|
cli: {
|
|
31
30
|
command: 'acceptance',
|
|
32
31
|
alias: 'acc',
|
|
@@ -49,7 +48,6 @@ exports.GATE_DEFINITIONS = [
|
|
|
49
48
|
{
|
|
50
49
|
id: 'command',
|
|
51
50
|
description: '命令黑名单门控,检查命令是否在禁用列表',
|
|
52
|
-
order: 1,
|
|
53
51
|
cli: {
|
|
54
52
|
command: 'command',
|
|
55
53
|
alias: 'cmd',
|
|
@@ -67,7 +65,6 @@ exports.GATE_DEFINITIONS = [
|
|
|
67
65
|
{
|
|
68
66
|
id: 'contract',
|
|
69
67
|
description: 'API 契约门控,检查 OpenAPI Schema',
|
|
70
|
-
order: 2,
|
|
71
68
|
cli: {
|
|
72
69
|
command: 'contract',
|
|
73
70
|
argument: '[subcommand]',
|
|
@@ -88,7 +85,6 @@ exports.GATE_DEFINITIONS = [
|
|
|
88
85
|
{
|
|
89
86
|
id: 'performance',
|
|
90
87
|
description: '性能门控,检查性能指标',
|
|
91
|
-
order: 3,
|
|
92
88
|
cli: {
|
|
93
89
|
command: 'performance',
|
|
94
90
|
alias: 'perf',
|
|
@@ -115,7 +111,6 @@ exports.GATE_DEFINITIONS = [
|
|
|
115
111
|
{
|
|
116
112
|
id: 'review',
|
|
117
113
|
description: '代码审查门控,检查审查状态',
|
|
118
|
-
order: 4,
|
|
119
114
|
cli: {
|
|
120
115
|
command: 'review',
|
|
121
116
|
argument: '[subcommand]',
|
|
@@ -145,7 +140,6 @@ exports.GATE_DEFINITIONS = [
|
|
|
145
140
|
{
|
|
146
141
|
id: 'security',
|
|
147
142
|
description: '安全门控,检查安全漏洞',
|
|
148
|
-
order: 5,
|
|
149
143
|
cli: {
|
|
150
144
|
command: 'security',
|
|
151
145
|
alias: 'sec',
|