Skip to content

Commit 6985cc3

Browse files
committed
test: record OpenCLI error parser review evidence
1 parent 2b5fa85 commit 6985cc3

7 files changed

Lines changed: 81 additions & 3 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# OpenCLI 1.8.8 错误输出采样
2+
3+
采样日期为 2026-11-18。运行环境使用 Node 24.18.0,npm 依赖安装在临时目录,三个样本各用隔离的 HOME。来源为 npm 包 `@jackwener/opencli@1.8.8`,包的发布校验值为 `sha512-T0rp89sVWMKdnQHoYwkRDuACy7k/lCvVScOZmpqnBhd1AnXG6XLYSYO6U0D/Zdj8qq9kQqgop3qmElNcbMr+sw==`。相关源码见已锁定的 [Adapter 渲染器](https://github.com/jackwener/OpenCLI/blob/8271afc67e8504bda94c147f446ee29775d08274/src/commanderAdapter.ts#L159) 和 [错误模型](https://github.com/jackwener/OpenCLI/blob/8271afc67e8504bda94c147f446ee29775d08274/src/errors.ts)。
4+
5+
| 样本 | 执行方式 | 进程退出码 | YAML `error.exitCode` | stdout |
6+
|---|---|---:|---:|---:|
7+
| `error-argument.yaml` | 原生只读命令 `opencli 12306 stations '' -f json`,空参数在请求站点前被拒绝 | 2 | 2 | 0 字节 |
8+
| `error-auth-required.yaml` | 官方 Adapter 渲染受控 `AuthRequiredError` | 77 | 77 | 0 字节 |
9+
| `error-empty-result-autofix.yaml` | 官方 Adapter 渲染受控 `EmptyResultError` | 66 | 66 | 0 字节 |
10+
11+
样本保存在 `src/test/resources/opencli-contracts/v1`,stderr 按字节保存,摘要见同目录的 `SHA256SUMS`。即使指定 `-f json`,三例的 stderr 均为 YAML。官方渲染器为 `EMPTY_RESULT` 附加 `# AutoFix` 注释,`AUTH_REQUIRED` 的样本没有该注释。如果后续 decoder 测试组合这两个字段,应标注为合成回归样本。
12+
13+
## 复核受控样本
14+
15+
在临时目录安装锁定包后,将下列内容保存为 `capture.mjs`,分别设置 `OPENCLI_FIXTURE=auth` 或 `OPENCLI_FIXTURE=empty`,用 Node 运行并独立收集 stdout、stderr 与退出码。
16+
17+
```javascript
18+
import { Command } from 'commander';
19+
import { registerCommandToProgram } from './node_modules/@jackwener/opencli/dist/src/commanderAdapter.js';
20+
import { AuthRequiredError, EmptyResultError } from './node_modules/@jackwener/opencli/dist/src/errors.js';
21+
22+
const program = new Command().name('opencli');
23+
registerCommandToProgram(program.command('fixture'), {
24+
site: 'fixture',
25+
name: 'check',
26+
description: 'Offline fixture',
27+
args: [],
28+
browser: false,
29+
func() {
30+
if (process.env.OPENCLI_FIXTURE === 'auth') {
31+
throw new AuthRequiredError('example.invalid');
32+
}
33+
throw new EmptyResultError('fixture/check', 'No rows in the offline fixture');
34+
},
35+
});
36+
await program.parseAsync(['fixture', 'check', '-f', 'json'], { from: 'user' });
37+
```
38+
39+
两个受控 Adapter 均在本地抛出错误。未执行登录、真实站点请求、写操作或注释中的修复命令。本次证据只完成 C03 任务 1.1,decoder 的实现和验收仍待评审。
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# C03 YAML 解析器候选验证(2026-11-18)
2+
3+
C03 评审候选为 `org.yaml:snakeyaml:2.7`,三条 Java 维护线可共用。SnakeYAML Engine 的当前维护线要求 Java 11 或更新版本。[SnakeYAML](https://github.com/snakeyaml/snakeyaml) · [SnakeYAML Engine](https://github.com/snakeyaml/snakeyaml-engine) · [Maven Central 发布包](https://repo.maven.apache.org/maven2/org/yaml/snakeyaml/2.7/)
4+
5+
## 探针结果
6+
7+
独立探针使用 SHA-256 为 `2e194eba45a67dee19a4e272f4a04b18de8054e9f598b094382f6dae0b0e4b5e` 的 2.7 JAR。以 JDK 8 编译一次,在 8u504、17.0.21、21.0.13.0.2 各执行 30 个断言。三轮退出码均为 0。使用三个 [OpenCLI 1.8.8 真实 stderr 样本](2026-11-18-upstream-stderr.md) 及合成输入。探针未接入 SDK,SDK 当前行为仍由既有执行器决定。
8+
9+
- 三个真实样本均读出 `ok: false`、原始错误码及整数退出码。带 `# AutoFix` 的样本正常解析。合成 JSON 子集保留未识别的错误码和 trace 路径。普通单行文本得到字符串,后续 envelope 校验应按原执行状态处理。
10+
- 普通 `SafeConstructor` 的 YAML 1.1 规则会将 `no`、`off` 和日期转成布尔值与日期类型。自定义隐式解析范围只接受 JSON 形式的布尔、空值、整数和小数。日期样式、`no`、`off` 和前导零字符串在探针中均保留原值。
11+
- 默认浮点映射会将 `1e400` 转为无穷大,并对长小数取近似值。探针改用 `BigDecimal` 保留两者,后续模型应避免以浮点近似值覆盖扩展字段。
12+
- 用库的事件流预检,拒绝锚点和别名、显式标记、多个文档及超过 32 层的集合。用加载选项拒绝重复键。UTF-8 字节检查在入口执行,加载器另外限制码点数。探针验证了 32 层和 256 KiB 边界、多字节超限、截断的 JSON 形态以及被禁止的 YAML 特性。普通运行日志仅记录断言数量。
13+
14+
## 实现评审范围
15+
16+
建议在 JSON 路径复用各分支已有 Jackson,并以严格 JSON 判定处理疑似 JSON 的失败输入。YAML 路径建议采用事件预检和受限构造,再检查 envelope 形状及字符串键。需用 SDK 测试验证退出码来源、解析状态、超时优先级、日志脱敏和无重试副作用。评审前保留 C03 任务 2.1 未勾选,三个 POM 均未引入该候选依赖。

‎openspec/changes/preserve-opencli-error-envelope/tasks.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# C03 Tasks · 上游错误协议解析与证据保真
22

3-
> 全部为待执行实现任务。文档/格式检查通过不允许提前勾选。
3+
> 已采集上游 stderr 样本,decoder 实现待评审。文档/格式检查通过不允许提前勾选。
44
55
关联规范:[spec](specs/opencli-error-envelope/spec.md)。
66

77
## 1. 错误 fixture
88

9-
- [ ] 1.1 从锁定上游 renderError/真实只读负例建立 YAML fixture,保存版本与 hash。
9+
- [x] 1.1 从锁定上游 renderError/真实只读负例建立 YAML fixture,保存版本与 hash。见 [上游 stderr 采样](evidence/2026-11-18-upstream-stderr.md)。
1010
- [ ] 1.2 补 JSON、纯文本、AutoFix 注释、exit mismatch、unknown code、malformed 和恶意 YAML 失败测试。
1111

1212
## 2. decoder 与结果
1313

14-
- [ ] 2.1 选定三线可用的安全 YAML 实现并验证安全配置,不复制不兼容 Jackson imports。
14+
- [ ] 2.1 选定三线可用的安全 YAML 实现并验证安全配置,不复制不兼容 Jackson imports。见 [三线候选探针](evidence/2026-11-18-yaml-parser-review.md)。
1515
- [ ] 2.2 实现有界 shape 校验和 provenance 模型,保留 help/trace/unknown fields。
1616
- [ ] 2.3 接入本地异常与 partial result,避免 parser 抢占 primary failure。
1717

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
e7e6dd57e81e24e92a7cb0de0e1204f95025f80310f5dc34d820aa7419636f78 argv.tsv
22
2fa30626c415bb3c152bc4c2827cd9282ba710654f6a56fb7bde70a83b2bc192 sources.lock.json
3+
2de5245d5a5692dc66d5fbc948d9c0929ba4baf12141ae2d9477771f7b17fb4f error-argument.yaml
4+
317a108a2d666fbf33554059b48691f363a33cd7a53bd8a94396bba045c9d522 error-auth-required.yaml
5+
1f587e1dc2f45648796dea428d3957560534b864e927d4d40db36563a5042b7f error-empty-result-autofix.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ok: false
2+
error:
3+
code: ARGUMENT
4+
message: Argument "keyword" is required.
5+
help: Chinese substring (上海), telecode (AOH), or pinyin (shanghai)
6+
exitCode: 2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ok: false
2+
error:
3+
code: AUTH_REQUIRED
4+
message: Not logged in to example.invalid
5+
help: Please open Chrome or Chromium and log in to https://example.invalid
6+
exitCode: 77
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ok: false
2+
error:
3+
code: EMPTY_RESULT
4+
message: fixture/check returned no data
5+
help: No rows in the offline fixture
6+
exitCode: 66
7+
# AutoFix: re-run with --trace=retain-on-failure for trace artifact
8+
# opencli fixture check --trace retain-on-failure

0 commit comments

Comments
 (0)