Skip to content

Commit e769bb6

Browse files
committed
Capture OpenCLI 1.8.8 structured help contracts
Refs #5 (cherry picked from commit fb766c66dab133b11ec6d68abc4e51c8df35654f)
1 parent 85de78f commit e769bb6

14 files changed

Lines changed: 2853 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# OpenCLI 1.8.8 帮助协议采集
2+
3+
使用 Node 24.18.0 和 npm 发布包 `@jackwener/opencli@1.8.8`,运行包声明的入口 `dist/src/main.js`。上游 `v1.8.8` tag 指向 `8271afc67e8504bda94c147f446ee29775d08274`,与本项目 U02/U03 锁定一致。[上游帮助实现](https://github.com/jackwener/OpenCLI/blob/8271afc67e8504bda94c147f446ee29775d08274/src/help.ts)
4+
5+
[原始样本及 SHA-256](../../../../src/test/resources/opencli-contracts/v1/structured-help-1.8.8/) 按 stdout 字节保存。两轮分别使用独立临时用户目录,禁止自动更新检查,不加载用户已有的配置或插件。只运行 `--version` 和下表的帮助参数。两轮版本均为 1.8.8,9 个样本均退出 0、stderr 为空,对应 stdout 逐字节一致。样本来自 Apache-2.0 发布包。
6+
7+
| 样本 | 入口参数 | 实际输出 |
8+
|---|---|---|
9+
| `root.json` | `--help -f json` | 单一 JSON。根命令为简要列表,`site_adapters` 为含 `count`、`sites` 的对象。 |
10+
| `browser.stdout` | `browser --help -f json` | JSON 后附加示例说明,共 472 个非首尾空白后缀字符,严格 JSON 读取失败。 |
11+
| `browser-tab.json` | `browser fixture tab --help -f json` | `tab` 分组 JSON。命令路径保留 `<session>`,包括 `tab list`、`tab select`。 |
12+
| `browser-get.json` | `browser fixture get --help -f json` | `get` 分组 JSON。包含 `get text`、`get attributes` 等叶子。该版本把 `tab` 和 `get` 分为两组。 |
13+
| `browser-state.json` | `browser fixture state --help -f json` | 单个叶子,带 session 占位符和独立的三类 options。 |
14+
| `meta-auth.json` | `auth --help -f json` | meta 命名空间 JSON,保留 namespace 与 global options。 |
15+
| `meta-list.txt` | `list --help -f json` | 纯文本 Commander 帮助,严格 JSON 读取失败。 |
16+
| `site-npm.json` | `npm --help -f json` | 站点目录 JSON,公共参数字段为 `common_options`。 |
17+
| `site-npm-search.json` | `npm search --help -f json` | 叶子 JSON,含必填位置参数 `query` 和命令参数 `limit`。 |
18+
19+
采集时通过 `node --import` 预加载脚本,将进程的 `os.homedir()` 指向临时目录,并同步 Node 内置模块导出。为两轮分别配置 `OPENCLI_CACHE_DIR`、`OPENCLI_CONFIG_DIR`,设置 `CI=1`、`NO_COLOR=1`。浏览器参数 `fixture` 是帮助查询的字面会话名,未创建会话或执行叶子命令。
20+
21+
`OpenCliStructuredHelpFixtureTest` 验证真实的作用域、占位符、根命令目录与两种负例,报告位于 `target/surefire-reports`。这些输出约束后续 C06 模型设计。两种负例仍需发现服务给出明确状态。远端 Agent、运行时插件、本地 override 及其他站点尚无本轮采集证据。

‎openspec/changes/add-opencli-capability-discovery/tasks.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# C06 Tasks · 结构化能力发现与可追溯快照
22

3-
> 全部为待执行实现任务。文档/格式检查通过不允许提前勾选。
3+
> 勾选项有对应的执行证据。
44
55
关联规范:[spec](specs/opencli-capability-discovery/spec.md)。
66

77
## 1. schema基线
88

9-
- [ ] 1.1 从锁定OpenCLI采集root/browser/meta/site结构化help,记录真实来源与hash,清楚标注不能采集的部分。
9+
- [x] 1.1 从锁定 OpenCLI 采集 root、browser、meta 和 site 帮助,保存原文与 SHA-256。不能读取为单一 JSON 文档的输出单列为负例。见 [1.8.8 采集证据](evidence/2026-11-19-structured-help.md)。
1010
- [ ] 1.2 为scope、optionalvalue、negate、false、aliases、session占位和旧格式编写失败测试。
1111

1212
## 2. 服务实现
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package io.github.easy4j.opencli.contract;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import tools.jackson.core.JacksonException;
9+
import tools.jackson.databind.DeserializationFeature;
10+
import tools.jackson.databind.JsonNode;
11+
import tools.jackson.databind.ObjectReader;
12+
import tools.jackson.databind.json.JsonMapper;
13+
import java.io.IOException;
14+
import java.io.InputStream;
15+
import org.junit.jupiter.api.Test;
16+
17+
class OpenCliStructuredHelpFixtureTest {
18+
19+
private static final String FIXTURES = "/opencli-contracts/v1/structured-help-1.8.8/";
20+
private static final ObjectReader STRICT_JSON = new JsonMapper().reader()
21+
.with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
22+
23+
@Test
24+
void preservesTheRootMetaAndSiteShapes() throws IOException {
25+
JsonNode root = read("root.json");
26+
assertEquals("opencli", root.path("name").asText());
27+
assertTrue(includesNamed(root.path("commands"), "list"));
28+
assertTrue(root.path("site_adapters").isObject());
29+
assertTrue(root.path("site_adapters").path("sites").isArray());
30+
31+
JsonNode auth = read("meta-auth.json");
32+
assertEquals("opencli auth", auth.path("command").asText());
33+
assertTrue(auth.path("namespace_options").isArray());
34+
assertTrue(auth.path("global_options").isArray());
35+
36+
JsonNode site = read("site-npm.json");
37+
assertEquals("npm", site.path("site").asText());
38+
assertTrue(includesNamed(site.path("commands"), "search"));
39+
assertTrue(site.path("common_options").isArray());
40+
41+
JsonNode leaf = read("site-npm-search.json");
42+
assertEquals("opencli npm search", leaf.path("command").asText());
43+
assertEquals("query", leaf.path("positionals").get(0).path("name").asText());
44+
assertTrue(leaf.path("positionals").get(0).path("required").booleanValue());
45+
assertTrue(includesNamed(leaf.path("command_options"), "limit"));
46+
}
47+
48+
@Test
49+
void preservesBrowserSessionPlaceholdersAndOptionScopes() throws IOException {
50+
JsonNode tabs = read("browser-tab.json");
51+
assertEquals("opencli browser <session> tab", tabs.path("command").asText());
52+
assertTrue(includesNamed(tabs.path("commands"), "tab list"));
53+
assertTrue(includesNamed(tabs.path("namespace_options"), "window"));
54+
assertTrue(includesNamed(tabs.path("global_options"), "profile"));
55+
assertTrue(includesNamed(tabs.path("commands").get(0).path("command_options"), "tab"));
56+
57+
JsonNode get = read("browser-get.json");
58+
assertEquals("opencli browser <session> get", get.path("command").asText());
59+
assertTrue(includesNamed(get.path("commands"), "get text"));
60+
61+
JsonNode state = read("browser-state.json");
62+
assertEquals("opencli browser <session> state", state.path("command").asText());
63+
}
64+
65+
@Test
66+
void identifiesRealOutputsThatAreNotSingleJsonDocuments() {
67+
assertThrows(JacksonException.class, () -> read("browser.stdout"));
68+
assertThrows(JacksonException.class, () -> read("meta-list.txt"));
69+
}
70+
71+
private static boolean includesNamed(JsonNode entries, String name) {
72+
for (JsonNode entry : entries) {
73+
if (name.equals(entry.path("name").asText())) {
74+
return true;
75+
}
76+
}
77+
return false;
78+
}
79+
80+
private static JsonNode read(String name) throws IOException {
81+
try (InputStream stream = OpenCliStructuredHelpFixtureTest.class.getResourceAsStream(FIXTURES + name)) {
82+
assertNotNull(stream, name);
83+
return STRICT_JSON.readTree(stream);
84+
}
85+
}
86+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Preserve upstream stdout for SHA-256 verification.
2+
* -text whitespace=-blank-at-eof
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
98b36d2411e80ae141b4b6e6af51ab3cbe0a095031f790657ded3a8249893ea7 browser-get.json
2+
e7c82f5f94cf299047bf276c7dfa3403e8850da1aaf0ae85f9f823e32a3ae8a0 browser-state.json
3+
fc97ce18949e2d0ca59ed721f3ca8e8414bd4ad8404e1b860dc4f83f8ecd9195 browser-tab.json
4+
611c4b4ab1b9f9c065c7fed5a571137fd85c64eb41912d17c26d66bf5f2f458e meta-auth.json
5+
a2c5736472fc773da7c7c34a913192374672c7afcc2111bf01854c5f72979b7f root.json
6+
0d6d9acae8fdb8075028308c353451f07791dce6d05d9724cd831ecd7605413c site-npm-search.json
7+
cb0269d83a27d46a8fe25e0450d843f5e97027d0bce3e38fb73ea7993c1bd6ef site-npm.json
8+
b96af9d8664871d83a4fb3efb27ea65fbc9ee9e71e676267930ecb66c73edf71 browser.stdout
9+
b2d96c9154c61f18cf4eed5099db5bc31a12f4199cffcd50f8242eed852dacf2 meta-list.txt

0 commit comments

Comments
 (0)