Skip to content

Commit ceb2736

Browse files
committed
Record reproducible upstream OpenCLI manifest provenance
1 parent 8133471 commit ceb2736

3 files changed

Lines changed: 86 additions & 28 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,14 @@
3232
OC-PARITY-003/004:当同一层含一个已执行套件及一个零用例套件时,旧报告返回 PASS。把同一套件注册到 argv 与 real-execution 也会重复记账。新增两个失败回归后,报告逐套件检查非零执行、零跳过、零失败及零错误,并拒绝同一套件跨层归因。问题套件列在 `unprovenSuites`。
3333

3434
JVM 和平台报告显式登记错误报文、浏览器 typed 结果、上下文和诊断测试。Windows npm 安装版检查用独立 `installed-report.json`,保留实际 Node、OpenCLI、Java 和 Maven 版本、源码 SHA 与执行退出码。真实 CLI 层的范围为安装版 launcher 与隔离的 help、插件和诊断测试。普通 JVM 或平台报告缺少此层时保持 NOT_RUN。用于 Browser 结果解析的全部归档样本继续按 SHA-256 验证。
35+
36+
### 2026-11-19 上游 manifest 采集
37+
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 和输出样本并评审快照变更。
39+
40+
在临时目录采集并运行生成器后,报告只记录公开来源、原始字节的 SHA-256、观察日期、获取命令和枚举范围。历史报告仍用于原有 Java 测试。生成器通过 `--manifest` 或 `OPENCLI_MANIFEST` 读取本地输入,移植验证覆盖含空格的临时路径。
41+
42+
```bash
43+
curl -fsSLo opencli-1.8.8.tgz https://registry.npmjs.org/@jackwener/opencli/-/opencli-1.8.8.tgz
44+
tar -xOf opencli-1.8.8.tgz package/cli-manifest.json > cli-manifest.json
45+
```

‎scripts/generate_opencli_command_tests.py‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,16 @@
99
"""
1010
from __future__ import annotations
1111

12+
import argparse
13+
import hashlib
1214
import json
1315
import os
1416
import textwrap
17+
from datetime import date
1518
from pathlib import Path
1619

1720
_SCRIPT_DIR = Path(__file__).resolve().parent
1821
_SDK_ROOT = _SCRIPT_DIR.parent
19-
_DEFAULT_MANIFEST = (
20-
_SCRIPT_DIR.parents[4]
21-
/ "workspace-partme-ai"
22-
/ "opencli"
23-
/ "opencli"
24-
/ "cli-manifest.json"
25-
)
26-
if not _DEFAULT_MANIFEST.is_file():
27-
_DEFAULT_MANIFEST = (
28-
Path("/Users/wandl/workspaces/workspace-partme-ai/opencli/opencli/cli-manifest.json")
29-
)
30-
31-
MANIFEST_PATH = Path(
32-
os.environ.get("OPENCLI_MANIFEST", _DEFAULT_MANIFEST)
33-
).resolve()
3422

3523
COVERAGE_PKG = "io.github.hiwepy.opencli.coverage"
3624
COVERAGE_DIR = _SDK_ROOT / "src/test/java/io/github/hiwepy/opencli/coverage"
@@ -77,14 +65,7 @@ def build_command_request(entry: dict) -> dict:
7765
}
7866

7967

80-
def load_manifest() -> list[dict]:
81-
data = json.loads(MANIFEST_PATH.read_text(encoding="utf-8"))
82-
if not isinstance(data, list):
83-
raise SystemExit("manifest must be a JSON array")
84-
return data
85-
86-
87-
def write_manifest_resource(entries: list[dict]) -> None:
68+
def write_manifest_resource(entries: list[dict], provenance: dict) -> None:
8869
RESOURCES_DIR.mkdir(parents=True, exist_ok=True)
8970
payload = [build_command_request(e) for e in entries]
9071
out = RESOURCES_DIR / "manifest-coverage-commands.json"
@@ -93,7 +74,7 @@ def write_manifest_resource(entries: list[dict]) -> None:
9374
meta.write_text(
9475
json.dumps(
9576
{
96-
"manifestPath": str(MANIFEST_PATH),
77+
**provenance,
9778
"manifestCommandCount": len(entries),
9879
"siteCount": len({e["site"] for e in entries}),
9980
},
@@ -682,10 +663,29 @@ class OpenCliCommandCoverageSummaryTest {{
682663

683664

684665
def main() -> None:
685-
if not MANIFEST_PATH.is_file():
686-
raise SystemExit(f"missing manifest: {MANIFEST_PATH}")
687-
entries = load_manifest()
688-
write_manifest_resource(entries)
666+
parser = argparse.ArgumentParser(description=__doc__)
667+
parser.add_argument("--manifest", type=Path, default=os.environ.get("OPENCLI_MANIFEST"),
668+
help="Local copy of upstream cli-manifest.json; defaults to OPENCLI_MANIFEST")
669+
parser.add_argument("--manifest-source", required=True,
670+
help="Upstream URL identifying the package version or source revision")
671+
parser.add_argument("--observed-at", type=date.fromisoformat, required=True, help="Observation date (YYYY-MM-DD)")
672+
parser.add_argument("--acquisition-command", required=True, help="Portable command to obtain the upstream input")
673+
args = parser.parse_args()
674+
if args.manifest is None:
675+
parser.error("specify --manifest or OPENCLI_MANIFEST")
676+
if not args.manifest.is_file():
677+
parser.error(f"missing manifest: {args.manifest}")
678+
manifest_bytes = args.manifest.read_bytes()
679+
entries = json.loads(manifest_bytes)
680+
if not isinstance(entries, list):
681+
parser.error("manifest must be a JSON array")
682+
write_manifest_resource(entries, {
683+
"manifestPath": args.manifest_source,
684+
"manifestSha256": hashlib.sha256(manifest_bytes).hexdigest(),
685+
"observedAt": args.observed_at.isoformat(),
686+
"acquisitionCommand": args.acquisition_command,
687+
"scope": "Bundled adapter command enumeration from cli-manifest.json",
688+
})
689689
write_adapter_coverage_test(len(entries))
690690
# meta_count 涵盖 list/validate/verify/doctor/completion/convention-audit +
691691
# plugin (install/uninstall/update/updateAll/list/create) +
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import hashlib
2+
import json
3+
import os
4+
import subprocess
5+
import sys
6+
import tempfile
7+
import unittest
8+
from pathlib import Path
9+
10+
11+
class ManifestCoverageProvenanceTest(unittest.TestCase):
12+
def test_explicit_manifest_records_source_and_bytes_without_local_paths(self):
13+
generator = Path(__file__).resolve().parents[1] / "generate_opencli_command_tests.py"
14+
source = "https://registry.npmjs.org/@jackwener/opencli/-/opencli-1.8.8.tgz"
15+
acquisition = "npm pack @jackwener/opencli@1.8.8"
16+
payload = b'[{"site": "example", "name": "list"}]\n'
17+
with tempfile.TemporaryDirectory() as temporary:
18+
root = Path(temporary)
19+
script = root / "scripts" / generator.name
20+
script.parent.mkdir()
21+
script.write_bytes(generator.read_bytes())
22+
manifest = root / "source checkout" / "cli-manifest.json"
23+
manifest.parent.mkdir()
24+
manifest.write_bytes(payload)
25+
26+
result = subprocess.run(
27+
[sys.executable, str(script), "--manifest-source", source,
28+
"--observed-at", "2026-11-19", "--acquisition-command", acquisition],
29+
env={**os.environ, "OPENCLI_MANIFEST": str(manifest)},
30+
capture_output=True, text=True,
31+
)
32+
33+
self.assertEqual(0, result.returncode, result.stderr)
34+
metadata = (root / "src/test/resources/opencli/manifest-coverage-meta.json").read_text()
35+
self.assertNotIn(temporary, metadata)
36+
self.assertEqual(
37+
{
38+
"manifestPath": source,
39+
"manifestSha256": hashlib.sha256(payload).hexdigest(),
40+
"observedAt": "2026-11-19",
41+
"acquisitionCommand": acquisition,
42+
"scope": "Bundled adapter command enumeration from cli-manifest.json",
43+
"manifestCommandCount": 1,
44+
"siteCount": 1,
45+
},
46+
json.loads(metadata),
47+
)

0 commit comments

Comments
 (0)