Skip to content

Commit ff75cd7

Browse files
committed
Verify OpenCLI error envelope parity across wire formats
1 parent f52262e commit ff75cd7

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
- [ ] 3.1 验证诊断日志不会输出 parser exception 中的原始敏感片段,配合 C09。
2121
- [ ] 3.2 验证写操作不会因解析器或 help 自动重试。
22-
- [ ] 3.3 在三个分支运行共享失败 fixtures,记录真实结果并更新迁移说明。
22+
- [x] 3.3 在三个分支运行共享失败 fixtures,记录真实结果并更新迁移说明。见三线回归。
2323

2424
## 证据交付模板(实施时填写)
2525

@@ -32,3 +32,9 @@
3232
JSON 复用各版本线 Jackson,严格检查重复键、尾随内容及嵌套深度。YAML 使用 SnakeYAML 2.7 的事件预检和安全构造器,保留 JSON 标量语义,拒绝锚点、别名、显式标签、重复键及多文档。解码预算为 256 KiB UTF-8、32 层。解析失败仅以状态呈现,原始诊断片段留在 stderr。AutoFix 和 trace 路径作为数据保存。
3333

3434
`OpenCliErrorEnvelopeTest` 首先因缺少 API 无法编译。实现后使用已归档 YAML、合成 JSON 和真实 JVM 子进程验证解码、退出值不一致、输入拒绝、超时优先、诊断脱敏与单次执行。现有远端失败分类继续由 C04 测试覆盖。
35+
36+
### 三线回归与调用迁移
37+
38+
在 Java 8 的 `dbe677e`、Java 17 的 `f52262ec` 和 Java 21 的 `25e1c58` 上加入 YAML/JSON 等价用例后,分别执行 `./mvnw -B -ntp clean verify`。三线均退出 0,全量通过 2210、2211、2210 项测试。每条线的 `OpenCliErrorEnvelopeTest` 运行 6 项,零失败、零错误、零跳过。报告位于 `target/surefire-reports`。
39+
40+
等价用例核对同一错误的扩展字段类型和两种格式标记。观察退出码 1、信封报告退出码 77 和不一致标记均独立保留。旧调用方可继续以异常类型及 `getPartialResult().getExitCode()` 处理执行状态。需要诊断详情的调用方可从 partial result 读取 `getErrorEnvelope()`,并按解析状态判断字段是否可用。文本、截断和超时仍可通过 `getStderr()` 取得已捕获的原始内容。

‎pom.xml‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@
111111
<version>${lombok.version}</version>
112112
</dependency>
113113
<dependency>
114-
<groupId>org.yaml</groupId>
115-
<artifactId>snakeyaml</artifactId>
116-
<version>2.7</version>
117-
</dependency>
118-
<!-- For Commons Exec -->
114+
<groupId>org.yaml</groupId>
115+
<artifactId>snakeyaml</artifactId>
116+
<version>2.7</version>
117+
</dependency>
118+
<!-- For Commons Exec -->
119119
<dependency>
120120
<groupId>org.apache.commons</groupId>
121121
<artifactId>commons-exec</artifactId>
@@ -151,7 +151,6 @@
151151
<dependency>
152152
<groupId>org.yaml</groupId>
153153
<artifactId>snakeyaml</artifactId>
154-
<version>2.7</version>
155154
</dependency>
156155
<!-- For Commons Exec -->
157156
<dependency>

‎src/test/java/io/github/easy4j/opencli/contract/OpenCliErrorEnvelopeTest.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ void strictJsonPreservesUnknownFieldsAndTraceWithoutReadingIt() {
5353
assertThrows(UnsupportedOperationException.class, () -> error.getTrace().clear());
5454
}
5555

56+
@Test
57+
void equivalentYamlAndJsonPreserveWireTypesAndExitProvenance() {
58+
String yaml = "ok: false\nerror:\n code: PLUGIN_FUTURE\n message: failed\n"
59+
+ " exitCode: 77\n help: retry\n values: [false, off, null, 1.25, 2147483648, 2026-11-19]\n"
60+
+ "trace: {summaryPath: missing-fixture.json}\n# AutoFix remains in stderr\n";
61+
String json = "{\"ok\":false,\"error\":{\"code\":\"PLUGIN_FUTURE\",\"message\":\"failed\","
62+
+ "\"exitCode\":77,\"help\":\"retry\",\"values\":[false,\"off\",null,1.25,2147483648,\"2026-11-19\"]},"
63+
+ "\"trace\":{\"summaryPath\":\"missing-fixture.json\"}}";
64+
65+
OpenCliErrorEnvelope yamlEnvelope = OpenCliErrorDecoder.decode(yaml, 1, false);
66+
OpenCliErrorEnvelope jsonEnvelope = OpenCliErrorDecoder.decode(json, 1, false);
67+
assertEquals(OpenCliErrorEnvelope.Status.DECODED, yamlEnvelope.getStatus());
68+
assertEquals(OpenCliErrorEnvelope.Status.DECODED, jsonEnvelope.getStatus());
69+
assertEquals(OpenCliErrorEnvelope.Format.YAML, yamlEnvelope.getFormat());
70+
assertEquals(OpenCliErrorEnvelope.Format.JSON, jsonEnvelope.getFormat());
71+
assertEquals(jsonEnvelope.getEnvelopeFields(), yamlEnvelope.getEnvelopeFields());
72+
assertEquals(Integer.valueOf(1), jsonEnvelope.getObservedProcessExit());
73+
assertEquals(jsonEnvelope.getObservedProcessExit(), yamlEnvelope.getObservedProcessExit());
74+
assertEquals(Integer.valueOf(77), jsonEnvelope.getReportedExit());
75+
assertEquals(jsonEnvelope.getReportedExit(), yamlEnvelope.getReportedExit());
76+
assertTrue(yamlEnvelope.isExitMismatch());
77+
assertTrue(jsonEnvelope.isExitMismatch());
78+
}
79+
5680
@Test
5781
void rejectsUnsafeDocumentsAndDistinguishesOrdinaryDiagnostics() {
5882
String root = "ok: false\nerror: {code: TEST, message: failed, exitCode: 1}\n";

0 commit comments

Comments
 (0)