Skip to content

Commit 12ff633

Browse files
committed
Lock and replay the OpenCLI 1.8.8 upstream samples
1 parent ceb2736 commit 12ff633

7 files changed

Lines changed: 248 additions & 6 deletions

File tree

‎openspec/changes/add-opencli-browser-result-models/evidence/2026-11-19-open-and-tab-list.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
```bash
1414
fixture_home=$(mktemp -d)
15-
env HOME="$fixture_home" CI=1 NO_COLOR=1 node --import "$PWD/capture.mjs" "$OPENCLI_ENTRY" browser fixture tab list > "$fixture_home/tab-list.json"
16-
env HOME="$fixture_home" CI=1 NO_COLOR=1 OPENCLI_FIXTURE_EMPTY=1 node --import "$PWD/capture.mjs" "$OPENCLI_ENTRY" browser fixture tab list > "$fixture_home/tab-list-empty.json"
17-
env HOME="$fixture_home" CI=1 NO_COLOR=1 node --import "$PWD/capture.mjs" "$OPENCLI_ENTRY" browser fixture open http://127.0.0.1:18765/basic.html > "$fixture_home/open.json"
15+
env OPENCLI_FIXTURE_HOME="$fixture_home" CI=1 NO_COLOR=1 node --import "$PWD/capture.mjs" "$OPENCLI_ENTRY" browser fixture tab list > "$fixture_home/tab-list.json"
16+
env OPENCLI_FIXTURE_HOME="$fixture_home" CI=1 NO_COLOR=1 OPENCLI_FIXTURE_EMPTY=1 node --import "$PWD/capture.mjs" "$OPENCLI_ENTRY" browser fixture tab list > "$fixture_home/tab-list-empty.json"
17+
env OPENCLI_FIXTURE_HOME="$fixture_home" CI=1 NO_COLOR=1 node --import "$PWD/capture.mjs" "$OPENCLI_ENTRY" browser fixture open http://127.0.0.1:18765/basic.html > "$fixture_home/open.json"
1818
for specimen in tab-list.json tab-list-empty.json open.json; do
1919
cmp "$specimen" "$fixture_home/$specimen"
2020
done

‎openspec/changes/enforce-opencli-branch-contract-parity/tasks.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
## 2. 上游与文档
1414

15-
- [ ] 2.1 采集锁定上游的实际help/manifest/output,保存hash与范围,移除对作者绝对路径的依赖。
15+
- [x] 2.1 采集锁定上游的实际help/manifest/output,保存hash与范围,移除对作者绝对路径的依赖。
1616
- [ ] 2.2 修正各分支README/POMdescription/Gradle示例,检查Java/Jackson/Maven实际声明。
1717
- [ ] 2.3 配置三线正确wrapper/JDK的独立构建与报告,不通过修改coverage阈值绕开行为问题。
1818

@@ -35,11 +35,16 @@ JVM 和平台报告显式登记错误报文、浏览器 typed 结果、上下文
3535

3636
### 2026-11-19 上游 manifest 采集
3737

38-
OC-PARITY-002:从 npm 发布包提取 `package/cli-manifest.json`。源为 https://registry.npmjs.org/@jackwener/opencli/-/opencli-1.8.8.tgz,包的 SHA-512 完整性与 npm registry 元数据一致。原始 manifest 的 SHA-256 为 `b6f44ab5973dfd46b001f42562ad520b184bf1dd27ec4ae807f849df70b98e6a`。范围为发布包自带的 adapter 命令枚举,共 1,366 条、179 个 site。按 `(site, name)` 逐项对比仓库历史快照,新增 89 条,移除 0 条。任务 2.1 仍待汇总 help 和输出样本并评审快照变更。
38+
OC-PARITY-002:从 npm 发布包提取 `package/cli-manifest.json`。源为 https://registry.npmjs.org/@jackwener/opencli/-/opencli-1.8.8.tgz,包的 SHA-512 完整性与 npm registry 元数据一致。原始 manifest 的 SHA-256 为 `b6f44ab5973dfd46b001f42562ad520b184bf1dd27ec4ae807f849df70b98e6a`。范围为发布包自带的 adapter 命令枚举,共 1,366 条、179 个 site。按 `(site, name)` 逐项对比仓库历史快照,新增 89 条,移除 0 条。89 条新增命令的逐项差异保存在本节链接的来源锁定中。
3939

4040
在临时目录采集并运行生成器后,报告只记录公开来源、原始字节的 SHA-256、观察日期、获取命令和枚举范围。历史报告仍用于原有 Java 测试。生成器通过 `--manifest` 或 `OPENCLI_MANIFEST` 读取本地输入,移植验证覆盖含空格的临时路径。
4141

4242
```bash
4343
curl -fsSLo opencli-1.8.8.tgz https://registry.npmjs.org/@jackwener/opencli/-/opencli-1.8.8.tgz
4444
tar -xOf opencli-1.8.8.tgz package/cli-manifest.json > cli-manifest.json
4545
```
46+
47+
48+
### OpenCLI 1.8.8 全量样本复跑
49+
50+
[上游来源锁定](../../../src/test/resources/opencli-contracts/v1/upstream-1.8.8.lock.json) 记录 manifest 采集命令及逐项差异,以及帮助和浏览器输出的校验清单与复跑入口。使用 Node 24.18.0 和已安装的 1.8.8 包,在独立临时配置、缓存及用户目录中执行。11 份帮助、12 份浏览器叶子输出均与已归档的 stdout 逐字节相同,全部退出 0,stderr 为空。帮助包含非 JSON 输出。浏览器叶子使用真实 CLI 与隔离页面桩,真实浏览器联调证据单独见 [Browser Bridge 验收](../add-opencli-browser-result-models/evidence/2026-11-19-real-browser-bridge.md)。历史覆盖基线的升级仍须评审。
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""Replay the locked OpenCLI 1.8.8 manifest, help and browser output fixtures."""
2+
from __future__ import annotations
3+
4+
import argparse
5+
import hashlib
6+
import json
7+
import os
8+
import subprocess
9+
import tempfile
10+
from pathlib import Path
11+
12+
ROOT = Path(__file__).resolve().parents[1]
13+
FIXTURES = ROOT / "src/test/resources/opencli-contracts/v1"
14+
HELP_CASES = {
15+
"root.json": (),
16+
"browser.stdout": ("browser",),
17+
"browser-tab.json": ("browser", "fixture", "tab"),
18+
"browser-get.json": ("browser", "fixture", "get"),
19+
"browser-state.json": ("browser", "fixture", "state"),
20+
"meta-auth.json": ("auth",),
21+
"meta-list.txt": ("list",),
22+
"meta-profile.json": ("profile",),
23+
"site-zhihu-hot.json": ("zhihu", "hot"),
24+
"site-npm.json": ("npm",),
25+
"site-npm-search.json": ("npm", "search"),
26+
}
27+
PAGE_URL = "http://127.0.0.1:18765/basic.html"
28+
BROWSER_CASES = {
29+
"tab-list.json": (("tab", "list"), {}),
30+
"tab-list-empty.json": (("tab", "list"), {"OPENCLI_FIXTURE_EMPTY": "1"}),
31+
"open.json": (("open", PAGE_URL), {}),
32+
"state-dom.stdout": (("state", "--source", "dom"), {}),
33+
"state-ax.stdout": (("state", "--source", "ax"), {}),
34+
"state-compare.json": (("state", "--source", "ax", "--compare-sources"), {}),
35+
"state-compare-ax-failure.json": (
36+
("state", "--compare-sources"), {"OPENCLI_FIXTURE_AX_FAILURE": "1"},
37+
),
38+
"find.json": (("find", "--css", "#fixture", "--limit", "1"), {}),
39+
"console.json": (("console",), {}),
40+
"console-level.json": (("console", "--level", "warning"), {"OPENCLI_FIXTURE_CONSOLE_LEVEL": "1"}),
41+
"network.json": (("network",), {}),
42+
"analyze.json": (("analyze", PAGE_URL), {}),
43+
}
44+
45+
46+
def verify_manifest(package: Path, lock: dict) -> None:
47+
metadata = json.loads((package / "package.json").read_bytes())
48+
if metadata.get("name") != "@jackwener/opencli" or metadata.get("version") != lock["version"]:
49+
raise SystemExit(f"expected @jackwener/opencli@{lock['version']}")
50+
baseline = lock["manifest"]
51+
content = (package / "cli-manifest.json").read_bytes()
52+
if hashlib.sha256(content).hexdigest() != baseline["sha256"]:
53+
raise SystemExit("installed cli-manifest.json SHA-256 differs from the lock")
54+
actual = {f"{entry['site']} {entry['name']}" for entry in json.loads(content)}
55+
historical = {
56+
f"{entry['site']} {entry['subcommand']}"
57+
for entry in json.loads((ROOT / baseline["historicalComparison"]).read_bytes())
58+
}
59+
if sorted(actual - historical) != baseline["addedAdapterCommands"]:
60+
raise SystemExit("added adapter commands differ from the locked comparison")
61+
if sorted(historical - actual) != baseline["removedAdapterCommands"]:
62+
raise SystemExit("removed adapter commands differ from the locked comparison")
63+
print(f"Manifest verified against the lock and historical snapshot ({len(actual)} commands)")
64+
65+
66+
def replay(entry: Path, preload: Path, fixture: Path, argv: tuple[str, ...], settings: dict) -> None:
67+
with tempfile.TemporaryDirectory(prefix="opencli-fixture-") as isolated:
68+
state = Path(isolated)
69+
env = {
70+
name: value for name, value in os.environ.items()
71+
if not name.startswith("OPENCLI_") and name != "NODE_OPTIONS"
72+
}
73+
env.update({
74+
"CI": "1",
75+
"NO_COLOR": "1",
76+
"OPENCLI_FIXTURE_HOME": isolated,
77+
"OPENCLI_CONFIG_DIR": str(state / "config"),
78+
"OPENCLI_CACHE_DIR": str(state / "cache"),
79+
})
80+
env.update(settings)
81+
result = subprocess.run(
82+
["node", "--import", str(preload), str(entry), *argv],
83+
cwd=state, env=env, capture_output=True, timeout=20,
84+
)
85+
if result.returncode or result.stderr or result.stdout != fixture.read_bytes():
86+
raise SystemExit(f"{fixture.name}: replay differs (exit {result.returncode}, "
87+
f"stderr {len(result.stderr)} bytes, stdout {len(result.stdout)} bytes)")
88+
89+
90+
def main() -> None:
91+
parser = argparse.ArgumentParser(description=__doc__)
92+
parser.add_argument("package", type=Path, help="Installed @jackwener/opencli package directory")
93+
package = parser.parse_args().package.resolve()
94+
lock = json.loads((FIXTURES / "upstream-1.8.8.lock.json").read_bytes())
95+
verify_manifest(package, lock)
96+
entry = package / "dist/src/main.js"
97+
help_dir = (FIXTURES / lock["structuredHelp"]["checksums"]).parent
98+
browser_dir = (FIXTURES / lock["browserOutput"]["checksums"]).parent
99+
with tempfile.TemporaryDirectory(prefix="opencli-help-preload-") as tmp:
100+
preload = Path(tmp) / "isolate.mjs"
101+
preload.write_text(
102+
"import os from 'node:os';\n"
103+
"import { syncBuiltinESMExports } from 'node:module';\n"
104+
"os.homedir = () => process.env.OPENCLI_FIXTURE_HOME;\n"
105+
"syncBuiltinESMExports();\n",
106+
encoding="utf-8",
107+
)
108+
for name, argv in HELP_CASES.items():
109+
replay(entry, preload, help_dir / name, (*argv, "--help", "-f", "json"), {})
110+
for name, (argv, settings) in BROWSER_CASES.items():
111+
replay(entry, browser_dir / "capture.mjs", browser_dir / name, ("browser", "fixture", *argv),
112+
{"OPENCLI_FIXTURE_FIXED_CLOCK": "1", **settings})
113+
print(f"Replay matched {len(HELP_CASES)} help and {len(BROWSER_CASES)} browser samples byte for byte")
114+
115+
116+
if __name__ == "__main__":
117+
main()

‎src/test/resources/opencli-contracts/v1/SHA256SUMS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ e7e6dd57e81e24e92a7cb0de0e1204f95025f80310f5dc34d820aa7419636f78 argv.tsv
33
2de5245d5a5692dc66d5fbc948d9c0929ba4baf12141ae2d9477771f7b17fb4f error-argument.yaml
44
317a108a2d666fbf33554059b48691f363a33cd7a53bd8a94396bba045c9d522 error-auth-required.yaml
55
1f587e1dc2f45648796dea428d3957560534b864e927d4d40db36563a5042b7f error-empty-result-autofix.yaml
6+
7a0782d23495f258b6050cd7bccc31fadd65a93d89f9a6ae877fe97e09d3aa50 upstream-1.8.8.lock.json

‎src/test/resources/opencli-contracts/v1/browser-output-1.8.8/SHA256SUMS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ c81e67d4ed3c58ec33d80f9d0c2feceee33a3588792c5f51e4a74a6069fed8b2 tab-list.json
1010
a3ba63353d2f970d5edbcf8eb0d1ede2688605ff5a97013cbfd70a9e54f344fd state-ax.stdout
1111
592bd1b129c0687569d865cdc3d1d28152628267ef2a6732d2afa23f58c1f035 state-dom.stdout
1212
fa91f0245e5c8060c94ee75683cec751ee57d6b2d21a40ac796695a5b7f2b3f2 console-level.json
13+
4cee66e1bbc52283fa269b0b0d8b52a9d2c8e689861e5e71c54a6df30de7722e capture.mjs

‎src/test/resources/opencli-contracts/v1/browser-output-1.8.8/capture.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { syncBuiltinESMExports } from 'node:module';
33
import { pathToFileURL } from 'node:url';
44
import path from 'node:path';
55

6-
os.homedir = () => process.env.HOME;
6+
os.homedir = () => process.env.OPENCLI_FIXTURE_HOME;
77
syncBuiltinESMExports();
88
const browserDir = path.join(path.dirname(process.argv[1]), 'browser');
99
const { BrowserBridge } = await import(pathToFileURL(path.join(browserDir, 'index.js')));
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"version": "1.8.8",
3+
"upstreamRef": "8271afc67e8504bda94c147f446ee29775d08274",
4+
"source": "https://registry.npmjs.org/@jackwener/opencli/-/opencli-1.8.8.tgz",
5+
"npmIntegrity": "sha512-T0rp89sVWMKdnQHoYwkRDuACy7k/lCvVScOZmpqnBhd1AnXG6XLYSYO6U0D/Zdj8qq9kQqgop3qmElNcbMr+sw==",
6+
"observedAt": "2026-11-19",
7+
"manifest": {
8+
"scope": "Bundled adapter enumeration from package/cli-manifest.json",
9+
"sha256": "b6f44ab5973dfd46b001f42562ad520b184bf1dd27ec4ae807f849df70b98e6a",
10+
"acquisitionCommand": "curl -fsSLo opencli-1.8.8.tgz https://registry.npmjs.org/@jackwener/opencli/-/opencli-1.8.8.tgz && tar -xOf opencli-1.8.8.tgz package/cli-manifest.json > cli-manifest.json",
11+
"commandCount": 1366,
12+
"siteCount": 179,
13+
"historicalComparison": "src/test/resources/opencli/manifest-coverage-commands.json",
14+
"addedAdapterCommands": [
15+
"bilibili creator-stats",
16+
"ctrip attraction",
17+
"ctrip bus",
18+
"ctrip cruise",
19+
"ctrip ferry",
20+
"ctrip flight-round",
21+
"ctrip hotel",
22+
"ctrip package",
23+
"ctrip tour",
24+
"ctrip train",
25+
"deepseek usage",
26+
"dribbble collection",
27+
"dribbble designer",
28+
"dribbble login",
29+
"dribbble member",
30+
"dribbble portfolio",
31+
"dribbble profile",
32+
"dribbble service",
33+
"dribbble shot",
34+
"dribbble shot-detail",
35+
"dribbble whoami",
36+
"gmail attachments",
37+
"gmail drafts",
38+
"gmail important",
39+
"gmail inbox",
40+
"gmail labels",
41+
"gmail login",
42+
"gmail search",
43+
"gmail sent",
44+
"gmail snoozed",
45+
"gmail spam",
46+
"gmail starred",
47+
"gmail thread",
48+
"gmail trash",
49+
"gmail unread",
50+
"gmail whoami",
51+
"google images",
52+
"midjourney action",
53+
"midjourney describe",
54+
"midjourney download",
55+
"midjourney generate",
56+
"midjourney history",
57+
"midjourney login",
58+
"midjourney quota",
59+
"midjourney settings",
60+
"midjourney status",
61+
"midjourney whoami",
62+
"minimax music",
63+
"pinterest board-create",
64+
"pinterest board-delete",
65+
"pinterest board-pins",
66+
"pinterest board-section-create",
67+
"pinterest board-section-delete",
68+
"pinterest board-sections",
69+
"pinterest board-update",
70+
"pinterest download",
71+
"pinterest pin",
72+
"pinterest pin-create",
73+
"pinterest pin-delete",
74+
"pinterest pin-update",
75+
"pinterest save",
76+
"pinterest search-boards",
77+
"pinterest search-pins",
78+
"pinterest search-users",
79+
"pinterest user",
80+
"pinterest user-boards",
81+
"pinterest user-pins",
82+
"pixiv bookmark-download",
83+
"pixiv bookmarks",
84+
"pixiv me",
85+
"pixiv novel",
86+
"pixiv novel-download",
87+
"pixiv novels",
88+
"toutiao recommend",
89+
"trip attraction",
90+
"trip car",
91+
"trip deals",
92+
"trip flight",
93+
"trip flight-round",
94+
"trip hotel",
95+
"trip hotel-search",
96+
"trip package",
97+
"trip search",
98+
"trip tour",
99+
"trip train",
100+
"trip transfer",
101+
"twitter collection",
102+
"twitter mute-word",
103+
"xiaoyuzhou history"
104+
],
105+
"removedAdapterCommands": []
106+
},
107+
"structuredHelp": {
108+
"scope": "Isolated installed CLI help stdout, including non-JSON results",
109+
"checksums": "structured-help-1.8.8/SHA256SUMS",
110+
"sampleCount": 11
111+
},
112+
"browserOutput": {
113+
"scope": "Installed CLI leaf stdout with a stub at the Browser Bridge page boundary",
114+
"checksums": "browser-output-1.8.8/SHA256SUMS",
115+
"sampleCount": 12
116+
},
117+
"replayCommand": "python3 scripts/verify_opencli_upstream_snapshot.py /path/to/node_modules/@jackwener/opencli"
118+
}

0 commit comments

Comments
 (0)