create-clis 1.0.0 → 1.1.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 +22 -14
- package/README.zh-CN.md +22 -14
- package/assets/manifest.json +7 -2
- package/assets/template/.github/ISSUE_TEMPLATE/bug_report.yml +15 -29
- package/assets/template/.github/ISSUE_TEMPLATE/feature_request.yml +6 -12
- package/assets/template/.github/PULL_REQUEST_TEMPLATE.md +3 -3
- package/assets/template/.github/workflows/ci.yml +69 -7
- package/assets/template/.github/workflows/release.yml +23 -23
- package/assets/template/.gitignorerc.json +1 -8
- package/assets/template/.oxlintrc.json +1 -6
- package/assets/template/.prettierignore +0 -1
- package/assets/template/.releaserc.json +6 -1
- package/assets/template/.vscode/launch.json +1 -1
- package/assets/template/.vscode/settings.json +1 -0
- package/assets/template/.vscode/tasks.json +45 -0
- package/assets/template/AGENTS.md +4 -4
- package/assets/template/CONTRIBUTING.md +6 -4
- package/assets/template/CONTRIBUTING.zh-CN.md +6 -4
- package/assets/template/_gitignore +7 -405
- package/assets/template/bunfig.toml +2 -11
- package/assets/template/docs/README.md +6 -6
- package/assets/template/docs/adrs/README.md +4 -2
- package/assets/template/docs/development.md +15 -9
- package/assets/template/lefthook.yml +20 -30
- package/assets/template/package.json +5 -6
- package/assets/template/packages/{{NAME}}/README.md +4 -4
- package/assets/template/packages/{{NAME}}/README.zh-CN.md +2 -2
- package/assets/template/packages/{{NAME}}/package.json +3 -1
- package/assets/template/packages/{{NAME}}/scripts/build.ts +50 -14
- package/assets/template/packages/{{NAME}}/scripts/verify-release.test.ts +140 -15
- package/assets/template/packages/{{NAME}}/scripts/verify-release.ts +27 -14
- package/assets/template/packages/{{NAME}}/tsconfig.build.json +1 -1
- package/assets/template/packages/{{NAME}}-cli/README.md +6 -6
- package/assets/template/packages/{{NAME}}-cli/README.zh-CN.md +2 -2
- package/assets/template/packages/{{NAME}}-cli/bin/bunfig.toml +3 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}} +43 -21
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.cmd +8 -17
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.d.mts +6 -3
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.mjs +189 -107
- package/assets/template/packages/{{NAME}}-cli/package.json +3 -2
- package/assets/template/packages/{{NAME}}-cli/scripts/release-artifact.ts +24 -73
- package/assets/template/packages/{{NAME}}-cli/scripts/release.fixtures.ts +8 -3
- package/assets/template/packages/{{NAME}}-cli/scripts/verify-release.test.ts +16 -10
- package/assets/template/packages/{{NAME}}-cli/scripts/verify-release.ts +8 -52
- package/assets/template/packages/{{NAME}}-cli/scripts/write-dist-manifest.test.ts +3 -3
- package/assets/template/packages/{{NAME}}-cli/scripts/write-dist-manifest.ts +8 -68
- package/assets/template/scripts/ci.ts +285 -64
- package/assets/template/scripts/install-git-hooks.mjs +10 -0
- package/assets/template/scripts/install-git-hooks.test.ts +1 -1
- package/assets/template/scripts/lib/npm-trust-parse.ts +169 -0
- package/assets/template/scripts/lib/release-cli.ts +299 -0
- package/assets/template/scripts/lib/release-verify.ts +148 -15
- package/assets/template/scripts/lib/workspace.test.ts +63 -1
- package/assets/template/scripts/lib/workspace.ts +132 -42
- package/assets/template/scripts/lint-dependency-direction.test.ts +131 -0
- package/assets/template/scripts/lint-dependency-direction.ts +130 -0
- package/assets/template/scripts/lint-doc-examples.test.ts +45 -9
- package/assets/template/scripts/lint-doc-examples.ts +227 -50
- package/assets/template/scripts/lint-doc-references.test.ts +36 -0
- package/assets/template/scripts/lint-doc-references.ts +142 -57
- package/assets/template/scripts/lint-doc-shared.ts +26 -23
- package/assets/template/scripts/lint-stray-backups.test.ts +3 -1
- package/assets/template/scripts/lint-stray-backups.ts +7 -3
- package/assets/template/scripts/npm-trust-guard.test.ts +56 -8
- package/assets/template/scripts/npm-trust-guard.ts +116 -200
- package/assets/template/scripts/safe-install.ts +28 -23
- package/assets/template/scripts/transcription/api-harness.ts +28 -206
- package/assets/template/scripts/transcription/compare.test.ts +84 -0
- package/assets/template/scripts/transcription/compare.ts +4 -4
- package/assets/template/scripts/transcription/corpus.ts +9 -3
- package/assets/template/scripts/transcription/fixture.ts +2 -4
- package/assets/template/scripts/transcription/make-mutants.ts +116 -37
- package/assets/template/scripts/transcription/run-conformance.ts +57 -34
- package/assets/template/scripts/transcription/validate-coverage.test.ts +11 -14
- package/assets/template/scripts/transcription/validate-coverage.ts +8 -10
- package/assets/template/scripts/transcription/validate.ts +18 -3
- package/assets/template/tsconfig.json +2 -20
- package/assets/template/turbo.jsonc +7 -52
- package/bin/bunfig.toml +3 -0
- package/bin/create-clis.mjs +165 -104
- package/dist/create-clis.js +48 -87681
- package/dist/manifest.json +3 -3
- package/package.json +9 -5
- package/assets/template/packages/{{NAME}}/docs/README.md +0 -21
- package/assets/template/packages/{{NAME}}-cli/docs/README.md +0 -21
- package/bin/create-clis +0 -35
- package/bin/create-clis.cmd +0 -32
|
@@ -1,219 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* 职责: 把一条 api 语料的调用指令 (stdin JSON) 物化为对 API 包真实导出的调用, 把末步返回值 /
|
|
5
|
-
* 抛错 / 收集的进度事件写成 stdout JSON。它与 CLI 面「被测命令是参数」同构: 任何语言的实现
|
|
6
|
-
* 按协议 (docs/sweep/protocol/conformance/api-harness-protocol.md) 提供自己的 harness 可执行,
|
|
7
|
-
* 套件零改动即可验收。
|
|
8
|
-
*
|
|
9
|
-
* 指令形状 (stdin):
|
|
10
|
-
* { "steps": [
|
|
11
|
-
* { "as": "s", "call": { "export": "createScanner", "args": [ { ... } ] } }, // 创建步
|
|
12
|
-
* { "call": { "on": "s", "method": "scan", "args": [] }, "collectEvents": true } // 方法步
|
|
13
|
-
* ] }
|
|
14
|
-
* 步骤按序执行; 末步返回值即输出的 value; 任一步抛错即终止并以 error 形态输出。
|
|
15
|
-
*
|
|
16
|
-
* 输出形状 (stdout):
|
|
17
|
-
* { "ok": true, "value": <末步返回值>, "events": [ ... ]? }
|
|
18
|
-
* { "ok": false, "error": { "name", "code"?, "message", "details"? } }
|
|
19
|
-
* (方法步声明过 collectEvents 即附 events 字段, 可为空数组; 创建步声明该字段按指令错误处理。)
|
|
20
|
-
*
|
|
21
|
-
* 变量与探针: 字符串内的 $FIXTURE 由验收器 (runner) 在派发前替换; 参数中形如
|
|
22
|
-
* { "$probe": "<名>" } 的对象整体替换为下方探针注册表的值。collectEvents 为 true 时,
|
|
23
|
-
* 收集器以 onProgress 并入该次调用的末个参数 (末参为对象则合并其中并覆盖既有 onProgress,
|
|
24
|
-
* 否则追加 { onProgress })。
|
|
25
|
-
*
|
|
26
|
-
* 路径策略: 本文件以相对路径直连 API 包单源 (.../packages/{{NAME}}/src/index.ts);
|
|
27
|
-
* mutant 副本按同相对结构复制本文件即自动指向副本源码 (见 make-mutants.ts)。bun 与 node
|
|
28
|
-
* (≥ 22.18 类型剥离) 均可直跑。
|
|
2
|
+
* API 黑盒验收适配器骨架 (增强档 `full` 保留):
|
|
3
|
+
* 默认直连示例包 `{{SCOPE}}/{{NAME}}` 的公开入口; 填入真实业务 API 与金样本语料后按需扩展。
|
|
29
4
|
*/
|
|
30
|
-
import { readFileSync } from 'node:fs';
|
|
31
|
-
|
|
32
5
|
import * as api from '../../packages/{{NAME}}/src/index.ts';
|
|
33
6
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
override readonly name = 'HarnessError';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 探针注册表 (初版最小集; 协议规定的命名集合, 语言实现者须提供同名等价物)。
|
|
41
|
-
* - pathops.posix / pathops.win32: 真实 PathStyle (纯 path 语义, 可直接充当被测的注入面);
|
|
42
|
-
* - deviceProbe.uniform: 恒报同一设备号的 DeviceProbe stub (同设备基准面; 跨设备类场景的
|
|
43
|
-
* 细分 stub 按条款需求增补, 增补不破坏既有语料)。
|
|
44
|
-
* 增补探针时须同步 docs/sweep/protocol/conformance/api-harness-protocol.md 的注册表清单。
|
|
45
|
-
*/
|
|
46
|
-
const PROBES: Record<string, unknown> = {
|
|
47
|
-
'pathops.posix': api.POSIX_STYLE,
|
|
48
|
-
'pathops.win32': api.WIN32_STYLE,
|
|
49
|
-
'deviceProbe.uniform': async () => 1,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/** 单步指令 (字段全可选, 合法性由执行期校验并给出可读报错) */
|
|
53
|
-
interface CallStep {
|
|
54
|
-
as?: string;
|
|
55
|
-
call?: {
|
|
56
|
-
export?: string;
|
|
57
|
-
on?: string;
|
|
58
|
-
method?: string;
|
|
59
|
-
args?: unknown[];
|
|
60
|
-
};
|
|
61
|
-
collectEvents?: boolean;
|
|
7
|
+
interface RequestPayload {
|
|
8
|
+
call?: { export?: string; args?: unknown[] };
|
|
62
9
|
}
|
|
63
10
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* 递归解析参数值: 含 $probe 键的对象整体替换为探针实现 (对象其余键不参与); 数组与普通对象递归
|
|
69
|
-
* 下钻; 其余值原样。探针名不在注册表即抛 HarnessError (指令缺陷, 不静默透传)。
|
|
70
|
-
*/
|
|
71
|
-
function resolveProbes(value: unknown): unknown {
|
|
72
|
-
if (Array.isArray(value)) return value.map(resolveProbes);
|
|
73
|
-
if (isPlainObject(value)) {
|
|
74
|
-
if ('$probe' in value) {
|
|
75
|
-
const name = value.$probe;
|
|
76
|
-
if (typeof name !== 'string' || !(name in PROBES)) {
|
|
77
|
-
throw new HarnessError(`未知探针: ${String(name)}`);
|
|
78
|
-
}
|
|
79
|
-
return PROBES[name];
|
|
80
|
-
}
|
|
81
|
-
return Object.fromEntries(
|
|
82
|
-
Object.entries(value).map(([key, item]) => [key, resolveProbes(item)]),
|
|
83
|
-
);
|
|
11
|
+
async function readStdin(): Promise<string> {
|
|
12
|
+
const chunks: Buffer[] = [];
|
|
13
|
+
for await (const chunk of process.stdin) {
|
|
14
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
84
15
|
}
|
|
85
|
-
return
|
|
16
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
86
17
|
}
|
|
87
18
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* Input(真实 Payload)
|
|
94
|
-
* instruction.steps = [
|
|
95
|
-
* { as: 's', call: { export: 'createScanner', args: [{ roots: ['<fixture>/zone'], exclude: [] }] } },
|
|
96
|
-
* { call: { on: 's', method: 'scan' }, collectEvents: true },
|
|
97
|
-
* ]
|
|
98
|
-
*
|
|
99
|
-
* 步骤 1:创建步执行
|
|
100
|
-
* handles = { s: <Scanner 实例> }; value = Scanner 实例
|
|
101
|
-
*
|
|
102
|
-
* 步骤 2:collectEvents 并入末参
|
|
103
|
-
* finalArgs = [{ onProgress: <收集器> }]; returned = ScanResult; events 累计进度事件
|
|
104
|
-
*
|
|
105
|
-
* Output(数据契约)
|
|
106
|
-
* return { value: ScanResult, events: MeasureProgressEvent 以外的 ScanProgressEvent[] }
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
async function runInstruction(instruction: unknown): Promise<{
|
|
110
|
-
value: unknown;
|
|
111
|
-
events: unknown[];
|
|
112
|
-
collected: boolean;
|
|
113
|
-
}> {
|
|
114
|
-
if (
|
|
115
|
-
!isPlainObject(instruction) ||
|
|
116
|
-
!Array.isArray(instruction.steps) ||
|
|
117
|
-
instruction.steps.length === 0
|
|
118
|
-
) {
|
|
119
|
-
throw new HarnessError('指令缺少非空 steps 数组');
|
|
19
|
+
async function main(): Promise<void> {
|
|
20
|
+
const raw = (await readStdin()).trim();
|
|
21
|
+
if (raw === '') {
|
|
22
|
+
process.stdout.write(`${JSON.stringify({ ok: false, error: '空请求' })}\n`);
|
|
23
|
+
return;
|
|
120
24
|
}
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const call = step.call;
|
|
133
|
-
if (call.args !== undefined && !Array.isArray(call.args)) {
|
|
134
|
-
throw new HarnessError(`steps[${index}]: args 须为数组`);
|
|
135
|
-
}
|
|
136
|
-
const args = (call.args ?? []).map(resolveProbes);
|
|
137
|
-
let returned: unknown;
|
|
138
|
-
|
|
139
|
-
if (typeof call.export === 'string') {
|
|
140
|
-
if (step.collectEvents === true) {
|
|
141
|
-
throw new HarnessError(
|
|
142
|
-
`steps[${index}]: 创建步不支持 collectEvents (仅方法步)`,
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
const fn = (api as Record<string, unknown>)[call.export];
|
|
146
|
-
if (typeof fn !== 'function') {
|
|
147
|
-
throw new HarnessError(
|
|
148
|
-
`steps[${index}]: 导出不存在或不是函数: ${call.export}`,
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
returned = await (fn as (...rest: unknown[]) => unknown)(...args);
|
|
152
|
-
} else if (typeof call.on === 'string' && typeof call.method === 'string') {
|
|
153
|
-
const handle = handles.get(call.on);
|
|
154
|
-
if (handle === undefined) {
|
|
155
|
-
throw new HarnessError(`steps[${index}]: 句柄未定义: ${call.on}`);
|
|
156
|
-
}
|
|
157
|
-
const method = handle[call.method];
|
|
158
|
-
if (typeof method !== 'function') {
|
|
159
|
-
throw new HarnessError(
|
|
160
|
-
`steps[${index}]: 句柄 ${call.on} 上无方法: ${call.method}`,
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
let finalArgs = args;
|
|
164
|
-
if (step.collectEvents === true) {
|
|
165
|
-
collected = true;
|
|
166
|
-
const onProgress = (event: unknown): void => {
|
|
167
|
-
events.push(event);
|
|
168
|
-
};
|
|
169
|
-
const lastIndex = args.length - 1;
|
|
170
|
-
const last = args[lastIndex];
|
|
171
|
-
finalArgs = isPlainObject(last)
|
|
172
|
-
? [...args.slice(0, lastIndex), { ...last, onProgress }]
|
|
173
|
-
: [...args, { onProgress }];
|
|
174
|
-
}
|
|
175
|
-
returned = await (method as (...rest: unknown[]) => unknown).apply(
|
|
176
|
-
handle,
|
|
177
|
-
finalArgs,
|
|
178
|
-
);
|
|
179
|
-
} else {
|
|
180
|
-
throw new HarnessError(
|
|
181
|
-
`steps[${index}]: 须为创建步 (call.export) 或方法步 (call.on + call.method)`,
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (typeof step.as === 'string') {
|
|
186
|
-
if (!isPlainObject(returned)) {
|
|
187
|
-
throw new HarnessError(
|
|
188
|
-
`steps[${index}]: as 句柄要求返回对象, 实得 ${typeof returned}`,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
handles.set(step.as, returned);
|
|
192
|
-
}
|
|
193
|
-
value = returned;
|
|
25
|
+
const req = JSON.parse(raw) as RequestPayload;
|
|
26
|
+
const exportName = req.call?.export;
|
|
27
|
+
const fn =
|
|
28
|
+
typeof exportName === 'string'
|
|
29
|
+
? (api as Record<string, unknown>)[exportName]
|
|
30
|
+
: undefined;
|
|
31
|
+
if (typeof fn !== 'function') {
|
|
32
|
+
process.stdout.write(
|
|
33
|
+
`${JSON.stringify({ ok: false, error: `未知导出函数: ${String(exportName)}` })}\n`,
|
|
34
|
+
);
|
|
35
|
+
return;
|
|
194
36
|
}
|
|
195
|
-
|
|
196
|
-
|
|
37
|
+
const value = await fn(...(req.call?.args ?? []));
|
|
38
|
+
process.stdout.write(`${JSON.stringify({ ok: true, value })}\n`);
|
|
197
39
|
}
|
|
198
40
|
|
|
199
|
-
|
|
200
|
-
const raw = readFileSync(0, 'utf8');
|
|
201
|
-
const outcome = await runInstruction(JSON.parse(raw));
|
|
202
|
-
const output: Record<string, unknown> = { ok: true, value: outcome.value };
|
|
203
|
-
if (outcome.collected) output.events = outcome.events;
|
|
204
|
-
process.stdout.write(`${JSON.stringify(output)}\n`);
|
|
205
|
-
} catch (error) {
|
|
206
|
-
// 抛出物未必是 Error (字符串 / undefined 等): 包装后 name / message 恒有, 协议声明的
|
|
207
|
-
// 必有字段不失守 (JSON.stringify 会丢弃 undefined 值, 否则 error 成空对象)。
|
|
208
|
-
const failure: Error & { code?: unknown; details?: unknown } =
|
|
209
|
-
error instanceof Error
|
|
210
|
-
? (error as Error & { code?: unknown; details?: unknown })
|
|
211
|
-
: new Error(String(error));
|
|
212
|
-
const errorOut: Record<string, unknown> = {
|
|
213
|
-
name: failure.name !== '' ? failure.name : 'Error',
|
|
214
|
-
message: failure.message,
|
|
215
|
-
};
|
|
216
|
-
if (typeof failure.code === 'string') errorOut.code = failure.code;
|
|
217
|
-
if (failure.details !== undefined) errorOut.details = failure.details;
|
|
218
|
-
process.stdout.write(`${JSON.stringify({ ok: false, error: errorOut })}\n`);
|
|
219
|
-
}
|
|
41
|
+
if (import.meta.main) await main();
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 转写契约套件 · 比对层与校验层单测:
|
|
3
|
+
* 1. compareApiCase 未预期抛错拦截 (未声明 expect.error 时即便仅断言 fs/events 也不得静默 PASS);
|
|
4
|
+
* 2. validateCase 校验收紧 (创建步禁 collectEvents / api expect 非空 / result 与 error 互斥 / 条款正则统一)。
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
|
|
8
|
+
import { compareApiCase } from './compare.ts';
|
|
9
|
+
import type { ExecOutcome } from './fixture.ts';
|
|
10
|
+
import { validateCase } from './validate.ts';
|
|
11
|
+
|
|
12
|
+
describe('compareApiCase: 未预期抛错拦截', () => {
|
|
13
|
+
const errOutcome: ExecOutcome = {
|
|
14
|
+
status: 0,
|
|
15
|
+
stdout: JSON.stringify({
|
|
16
|
+
ok: false,
|
|
17
|
+
error: { name: 'SweepError', code: 'INVALID_ARGUMENT', message: 'boom' },
|
|
18
|
+
}),
|
|
19
|
+
stderr: '',
|
|
20
|
+
timedOut: false,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
test('仅声明 expect.events 未声明 expect.error 时, outcome.ok=false 必判 FAIL', async () => {
|
|
24
|
+
const failures = await compareApiCase(
|
|
25
|
+
{ events: { lastIs: 'done' } },
|
|
26
|
+
errOutcome,
|
|
27
|
+
'/unused',
|
|
28
|
+
);
|
|
29
|
+
expect(failures.some((f) => f.kind === 'error')).toBe(true);
|
|
30
|
+
expect(failures[0]?.message).toContain('未预期抛错');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('仅声明 expect.fs 未声明 expect.error 时, outcome.ok=false 必判 FAIL (杜绝静默 PASS)', async () => {
|
|
34
|
+
const failures = await compareApiCase({ fs: [] }, errOutcome, '/unused');
|
|
35
|
+
expect(failures.some((f) => f.kind === 'error')).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('声明匹配的 expect.error 时通过', async () => {
|
|
39
|
+
const failures = await compareApiCase(
|
|
40
|
+
{ error: { code: 'INVALID_ARGUMENT', name: 'SweepError' } },
|
|
41
|
+
errOutcome,
|
|
42
|
+
'/unused',
|
|
43
|
+
);
|
|
44
|
+
expect(failures).toEqual([]);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('validateCase: 语料校验收紧与条款正则统一', () => {
|
|
49
|
+
const baseApi = {
|
|
50
|
+
id: 'api-sample',
|
|
51
|
+
kind: 'api',
|
|
52
|
+
specRefs: ['BC-01'],
|
|
53
|
+
fixture: {},
|
|
54
|
+
steps: [{ call: { export: 'createScanner' } }],
|
|
55
|
+
expect: { result: { subset: {} } },
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
test('创建步 (call.export) 声明 collectEvents: true 判错', () => {
|
|
59
|
+
const problems = validateCase({
|
|
60
|
+
...baseApi,
|
|
61
|
+
steps: [{ call: { export: 'createScanner' }, collectEvents: true }],
|
|
62
|
+
});
|
|
63
|
+
expect(problems.some((p) => p.includes('创建步不支持 collectEvents'))).toBe(
|
|
64
|
+
true,
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('api case 的 expect 至少含 result/error/events/fs 之一, 且 result 与 error 互斥', () => {
|
|
69
|
+
const emptyExpect = validateCase({ ...baseApi, expect: {} });
|
|
70
|
+
expect(emptyExpect.some((p) => p.includes('须至少含'))).toBe(true);
|
|
71
|
+
|
|
72
|
+
const both = validateCase({
|
|
73
|
+
...baseApi,
|
|
74
|
+
expect: { result: { exact: 1 }, error: { code: 'CANCELLED' } },
|
|
75
|
+
});
|
|
76
|
+
expect(both.some((p) => p.includes('互斥'))).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('specRefs 仅接受 BC/OF/EC 前缀的条款编号 (与 validate-coverage 统一正则)', () => {
|
|
80
|
+
expect(validateCase(baseApi)).toEqual([]);
|
|
81
|
+
const bad = validateCase({ ...baseApi, specRefs: ['XX-01'] });
|
|
82
|
+
expect(bad.some((p) => p.includes('specRefs'))).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -381,15 +381,15 @@ export async function compareApiCase(
|
|
|
381
381
|
}
|
|
382
382
|
} else {
|
|
383
383
|
const error = isPlainRecord(outcome.error) ? outcome.error : null;
|
|
384
|
-
if (expect.
|
|
384
|
+
if (expect.error === undefined) {
|
|
385
|
+
// 未声明 expect.error 时任何抛错都属未预期异常, 即便用例仅声明了 fs / events 也必须判 FAIL (杜绝静默 PASS)
|
|
385
386
|
const code = typeof error?.code === 'string' ? error.code : '?';
|
|
386
387
|
const message = typeof error?.message === 'string' ? error.message : '';
|
|
387
388
|
failures.push({
|
|
388
389
|
kind: 'error',
|
|
389
|
-
message:
|
|
390
|
+
message: `未预期抛错: ${code} ${message}`.trim(),
|
|
390
391
|
});
|
|
391
|
-
}
|
|
392
|
-
if (expect.error !== undefined) {
|
|
392
|
+
} else {
|
|
393
393
|
const actualCode = error?.code;
|
|
394
394
|
if (actualCode !== expect.error.code) {
|
|
395
395
|
failures.push({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 转写契约套件 · 语料层。
|
|
3
3
|
*
|
|
4
|
-
* 职责: 语料字段类型 (与 docs/
|
|
4
|
+
* 职责: 语料字段类型 (与 packages/{{NAME}}/docs/protocol/conformance/corpus.schema.json 对应) + $FIXTURE 变量替换
|
|
5
5
|
* 契约 + 目录加载。字段语义以 schema 为准; 手写校验 (schema 的物化子集) 在 validate.ts, 只为尽早
|
|
6
6
|
* 给出可读报错, 不复刻 schema 的全部约束。
|
|
7
7
|
*/
|
|
@@ -10,6 +10,12 @@ import { join } from 'node:path';
|
|
|
10
10
|
|
|
11
11
|
import { validateCase } from './validate.ts';
|
|
12
12
|
|
|
13
|
+
/** 协议区相对仓根的唯一路径常量 (文档目录迁徙时仅需单点切换此处) */
|
|
14
|
+
export const PROTOCOL_ROOT = 'packages/{{NAME}}/docs/protocol';
|
|
15
|
+
export const CONTRACT_REL = `${PROTOCOL_ROOT}/behavior-contract.md`;
|
|
16
|
+
export const COVERAGE_REL = `${PROTOCOL_ROOT}/conformance/coverage.md`;
|
|
17
|
+
export const CORPUS_REL = `${PROTOCOL_ROOT}/conformance/corpus`;
|
|
18
|
+
|
|
13
19
|
// ---------------------------------------------------------------------------
|
|
14
20
|
// 语料类型 (与 corpus.schema.json 对应)
|
|
15
21
|
// ---------------------------------------------------------------------------
|
|
@@ -75,7 +81,7 @@ export interface CliCorpusCase {
|
|
|
75
81
|
expect: ExpectSpec;
|
|
76
82
|
}
|
|
77
83
|
|
|
78
|
-
/** api 用例的单步调用指令 (形状与执行语义见 docs/
|
|
84
|
+
/** api 用例的单步调用指令 (形状与执行语义见 packages/{{NAME}}/docs/protocol/conformance/api-harness-protocol.md) */
|
|
79
85
|
export interface ApiCallStep {
|
|
80
86
|
as?: string;
|
|
81
87
|
call: {
|
|
@@ -148,7 +154,7 @@ export function replaceVarsDeep(value: unknown, root: string): unknown {
|
|
|
148
154
|
* ### 数据追踪示例
|
|
149
155
|
* ```text
|
|
150
156
|
* Input(真实 Payload)
|
|
151
|
-
* dir = 'docs/
|
|
157
|
+
* dir = 'packages/{{NAME}}/docs/protocol/conformance/corpus' (含 scan-nested-prune.json 与 delete-execute-ok.json)
|
|
152
158
|
*
|
|
153
159
|
* 步骤 1:取 .json 文件名并排序
|
|
154
160
|
* names = ['delete-execute-ok.json', 'scan-nested-prune.json']
|
|
@@ -51,14 +51,12 @@ const BASE_ENV_KEYS = [
|
|
|
51
51
|
|
|
52
52
|
/** 一次运行期的固定上下文 (由调用方解析 CLI 后组装) */
|
|
53
53
|
export interface RunContext {
|
|
54
|
-
/** 被测命令 argv (
|
|
54
|
+
/** 被测命令 argv (已按数组传入, 含绝对路径时不经空白二次切分) */
|
|
55
55
|
targetArgv: string[];
|
|
56
|
-
/** API harness 命令 argv (
|
|
56
|
+
/** API harness 命令 argv (api 用例用) */
|
|
57
57
|
apiTargetArgv: string[];
|
|
58
58
|
timeoutMs: number;
|
|
59
59
|
keep: boolean;
|
|
60
|
-
/** fixture 根基座 (调用方保证已存在) */
|
|
61
|
-
workBase: string;
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
export interface ExecOutcome {
|