99"""
1010from __future__ import annotations
1111
12+ import argparse
13+ import hashlib
1214import json
1315import os
1416import textwrap
17+ from datetime import date
1518from 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
3523COVERAGE_PKG = "io.github.hiwepy.opencli.coverage"
3624COVERAGE_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
684665def 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) +
0 commit comments