Skip to content

Commit cd78cb7

Browse files
committed
Require nonempty evidence per OpenCLI contract suite
1 parent e9c7a00 commit cd78cb7

6 files changed

Lines changed: 207 additions & 9 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ jobs:
3838
working-directory: src/test/resources/opencli-contracts/v1/structured-help-1.8.8
3939
run: sha256sum --strict -c SHA256SUMS
4040

41+
- name: Verify pinned browser output samples
42+
working-directory: src/test/resources/opencli-contracts/v1/browser-output-1.8.8
43+
run: sha256sum --strict -c SHA256SUMS
44+
4145
- name: Build and verify with JaCoCo coverage
4246
run: ./mvnw -B --no-transfer-progress clean verify
4347

‎.github/workflows/platform-contracts.yml‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
mvn -version > platform-evidence/maven.txt 2>&1
5252
result=0
5353
mvn -B --no-transfer-progress \
54-
-Dtest=OpenCliArgvContractTest,OpenCliStructuredArgvContractTest,OpenCliProcessContractTest,OpenCliProcessBoundaryTest,SubprocessCleanupFaultTest,SubprocessStreamFailureTest,OpenCliWsReverseAgentSessionTest,OpenCliWsCollectRequestsTest,OpenCliProcessPrivacyTest,OpenCliArgSupportTest#shouldKeepConversionExceptionAndNestedCausePrivate,SubprocessExecutionSupportTest#shouldKeepNativePathOutOfDefaultHandlerException \
54+
-Dtest=OpenCliErrorEnvelopeTest,OpenCliBrowserResultTest,OpenCliBrowserEvidenceResultTest,OpenCliDiagnosticsTest,OpenCliInvocationContextTest,OpenCliArgvContractTest,OpenCliStructuredArgvContractTest,OpenCliProcessContractTest,OpenCliProcessBoundaryTest,SubprocessCleanupFaultTest,SubprocessStreamFailureTest,OpenCliWsReverseAgentSessionTest,OpenCliWsCollectRequestsTest,OpenCliProcessPrivacyTest,OpenCliArgSupportTest#shouldKeepConversionExceptionAndNestedCausePrivate,SubprocessExecutionSupportTest#shouldKeepNativePathOutOfDefaultHandlerException \
5555
test > platform-evidence/maven.log 2>&1 || result=$?
5656
tail -100 platform-evidence/maven.log
5757
python scripts/contract_report.py \
@@ -72,8 +72,16 @@ jobs:
7272
--suite process=io.github.easy4j.opencli.core.OpenCliProcessPrivacyTest \
7373
--suite argv=io.github.easy4j.opencli.core.OpenCliArgSupportTest \
7474
--suite process=io.github.easy4j.opencli.core.support.SubprocessExecutionSupportTest \
75+
--suite protocol=io.github.easy4j.opencli.contract.OpenCliErrorEnvelopeTest \
76+
--suite typed-result=io.github.easy4j.opencli.contract.OpenCliBrowserResultTest \
77+
--suite typed-result=io.github.easy4j.opencli.contract.OpenCliBrowserEvidenceResultTest \
78+
--suite typed-result=io.github.easy4j.opencli.capability.OpenCliDiagnosticsTest \
79+
--suite argv=io.github.easy4j.opencli.capability.OpenCliInvocationContextTest \
7580
--output platform-evidence/report.json
7681
exit "$result"
82+
- name: Verify npm-installed OpenCLI on Windows
83+
if: runner.os == 'Windows'
84+
run: bash scripts/run_installed_contracts.sh mvn
7785
- name: Upload platform subprocess evidence
7886
if: always()
7987
uses: actions/upload-artifact@v7

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@
2626
## 证据交付模板(实施时填写)
2727

2828
每项任务的完成记录包含:Requirement/Scenario、分支HEAD、测试命令、失败→通过证据、测试数/跳过数、退出码、报告位置。没有记录的任务保持未完成。
29+
30+
### 每个必选套件的执行证据
31+
32+
OC-PARITY-003/004:当同一层含一个已执行套件及一个零用例套件时,旧报告返回 PASS。把同一套件注册到 argv 与 real-execution 也会重复记账。新增两个失败回归后,报告逐套件检查非零执行、零跳过、零失败及零错误,并拒绝同一套件跨层归因。问题套件列在 `unprovenSuites`。
33+
34+
JVM 和平台报告显式登记错误报文、浏览器 typed 结果、上下文和诊断测试。Windows npm 安装版检查用独立 `installed-report.json`,保留实际 Node、OpenCLI、Java 和 Maven 版本、源码 SHA 与执行退出码。真实 CLI 层的范围为安装版 launcher 与隔离的 help、插件和诊断测试。普通 JVM 或平台报告缺少此层时保持 NOT_RUN。用于 Browser 结果解析的全部归档样本继续按 SHA-256 验证。

‎scripts/contract_report.py‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def build_report(reports_dir, *, head, branch, java_version, maven_version, exit
3737
problems.append('verification command exited nonzero')
3838
if not required_suites or any(layer not in LAYERS or not names for layer, names in required_suites.items()):
3939
problems.append('non-empty required suites must use recognized layers')
40+
attributed = [name for names in required_suites.values() for name in names]
41+
if len(attributed) != len(set(attributed)):
42+
problems.append('suite attribution must be unique across layers')
4043
suites = {}
4144
for path in sorted(pathlib.Path(reports_dir).glob('TEST-*.xml')):
4245
try:
@@ -59,11 +62,14 @@ def build_report(reports_dir, *, head, branch, java_version, maven_version, exit
5962
for name in names:
6063
for key in counts:
6164
counts[key] += suites.get(name, {}).get(key, 0)
62-
state = 'NOT_RUN'
63-
if names:
64-
state = 'PASS' if (not missing and counts['executed'] > 0 and
65-
not any(counts[key] for key in ('skipped', 'failures', 'errors'))) else 'FAIL'
66-
layers[layer] = dict(counts, status=state, requiredSuites=names, missingSuites=missing)
65+
unproven = [
66+
name for name in names
67+
if name not in suites or suites[name]['executed'] == 0
68+
or any(suites[name][key] for key in ('skipped', 'failures', 'errors'))
69+
]
70+
state = 'NOT_RUN' if not names else ('FAIL' if unproven else 'PASS')
71+
layers[layer] = dict(counts, status=state, requiredSuites=names, missingSuites=missing,
72+
unprovenSuites=unproven)
6773
if state == 'FAIL':
6874
problems.append('required layer lacks passing, non-skipped execution: ' + layer)
6975
return {'schemaVersion': 1, 'status': 'FAIL' if problems else 'PASS',
@@ -85,13 +91,15 @@ def main(argv=None):
8591
parser.add_argument('--output', type=pathlib.Path, required=True)
8692
args = parser.parse_args(argv)
8793
required = {}
94+
attributed = set()
8895
for item in args.suite:
8996
layer, separator, name = item.partition('=')
9097
if not separator or layer not in LAYERS or not name:
9198
parser.error('--suite must be recognized-layer=fully.qualified.TestClass')
92-
if name in required.setdefault(layer, []):
93-
parser.error('duplicate --suite')
94-
required[layer].append(name)
99+
if name in attributed:
100+
parser.error('--suite must be unique across layers')
101+
attributed.add(name)
102+
required.setdefault(layer, []).append(name)
95103
try:
96104
report = build_report(args.reports, head=args.head, branch=args.branch,
97105
java_version=args.java_version_file.read_text(encoding='utf-8'),

‎scripts/run_installed_contracts.sh‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
# Verify the pinned published CLI in an isolated installation and record live-only evidence.
3+
set -euo pipefail
4+
5+
report_dir=platform-evidence
6+
mkdir -p "$report_dir"
7+
temp_root=${RUNNER_TEMP:?}
8+
if [[ "${RUNNER_OS:-}" == Windows ]]; then
9+
temp_root=$(cygpath -u "$temp_root")
10+
fi
11+
install_dir=$(mktemp -d "$temp_root/opencli-installed.XXXXXX")
12+
npm install --prefix "$install_dir" --ignore-scripts --no-audit --no-fund @jackwener/opencli@1.8.8
13+
14+
cli_entry="$install_dir/node_modules/@jackwener/opencli/dist/src/main.js"
15+
export CI=1 NO_COLOR=1
16+
node --version > "$report_dir/installed-node.txt"
17+
node "$cli_entry" --version > "$report_dir/installed-opencli-version.txt"
18+
grep -Fx '1.8.8' "$report_dir/installed-opencli-version.txt"
19+
20+
export OPENCLI_INSTALLED_NODE
21+
OPENCLI_INSTALLED_NODE=$(node -p 'process.execPath')
22+
export OPENCLI_INSTALLED_ENTRY="$cli_entry"
23+
tests=OpenCliCapabilityOverrideIT,OpenCliReadOnlyDiagnosticsIT
24+
suites=(
25+
--suite real-execution=io.github.easy4j.opencli.contract.OpenCliCapabilityOverrideIT
26+
--suite real-execution=io.github.easy4j.opencli.contract.OpenCliReadOnlyDiagnosticsIT
27+
)
28+
if [[ "${RUNNER_OS:-}" == Windows ]]; then
29+
registry="$install_dir/registry.json"
30+
node "$cli_entry" list -f json > "$registry"
31+
OPENCLI_INSTALLED_ENTRY=$(cygpath -w "$cli_entry")
32+
export OPENCLI_INSTALLED_REGISTRY
33+
OPENCLI_INSTALLED_REGISTRY=$(cygpath -w "$registry")
34+
export OPENCLI_INSTALLED_BATCH_SHIM
35+
OPENCLI_INSTALLED_BATCH_SHIM=$(cygpath -w "$install_dir/node_modules/.bin/opencli.cmd")
36+
tests+=,OpenCliInstalledLauncherIT
37+
suites+=(--suite real-execution=io.github.easy4j.opencli.contract.OpenCliInstalledLauncherIT)
38+
fi
39+
40+
java -version > "$report_dir/installed-java.txt" 2>&1
41+
"$@" -version > "$report_dir/installed-maven.txt" 2>&1
42+
result=0
43+
"$@" -B --no-transfer-progress "-Dtest=$tests" test > "$report_dir/installed-maven.log" 2>&1 || result=$?
44+
tail -80 "$report_dir/installed-maven.log"
45+
python scripts/contract_report.py \
46+
--reports target/surefire-reports \
47+
--head "$(git rev-parse HEAD)" \
48+
--branch "${GITHUB_REF_NAME:-$(git branch --show-current)}" \
49+
--java-version-file "$report_dir/installed-java.txt" \
50+
--maven-version-file "$report_dir/installed-maven.txt" \
51+
--exit-code "$result" \
52+
"${suites[@]}" \
53+
--output "$report_dir/installed-report.json"
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import importlib.util
2+
import json
3+
import pathlib
4+
import tempfile
5+
import unittest
6+
7+
SCRIPT = pathlib.Path(__file__).resolve().parents[1] / 'contract_report.py'
8+
HEAD = 'd0c8056990f7a47fcc202acffa387ba066bcfc67'
9+
SUITE = 'io.github.easy4j.opencli.contract.OpenCliArgvContractTest'
10+
SECOND_SUITE = 'io.github.easy4j.opencli.contract.OpenCliStructuredArgvContractTest'
11+
12+
13+
class ContractReportTest(unittest.TestCase):
14+
def setUp(self):
15+
self.assertTrue(SCRIPT.is_file(), 'C10 contract report runner is not implemented')
16+
spec = importlib.util.spec_from_file_location('contract_report', SCRIPT)
17+
self.module = importlib.util.module_from_spec(spec)
18+
spec.loader.exec_module(self.module)
19+
self.temp = tempfile.TemporaryDirectory()
20+
self.addCleanup(self.temp.cleanup)
21+
self.root = pathlib.Path(self.temp.name)
22+
23+
def xml(self, tests=2, skipped=0, failures=0, errors=0, suite=SUITE):
24+
executed = tests - skipped
25+
cases = []
26+
for i in range(tests):
27+
child = '<skipped/>' if i >= executed else ('<failure/>' if i < failures else ('<error/>' if i < failures + errors else ''))
28+
cases.append('<testcase name="case' + str(i) + '">' + child + '</testcase>')
29+
(self.root / ('TEST-' + suite + '.xml')).write_text(
30+
'<testsuite name="' + suite + '" tests="' + str(tests) + '" skipped="' + str(skipped)
31+
+ '" failures="' + str(failures) + '" errors="' + str(errors) + '">' + ''.join(cases) + '</testsuite>', encoding='utf-8')
32+
33+
def report(self, **kwargs):
34+
return self.module.build_report(self.root, head=kwargs.get('head', HEAD),
35+
branch='feature/2.0.x', java_version='openjdk 17 (test fixture)',
36+
maven_version='Apache Maven (test fixture)', exit_code=kwargs.get('exit_code', 0),
37+
required_suites=kwargs.get('required_suites', {'argv': [SUITE]}))
38+
39+
def test_complete_argv_evidence_passes_but_live_is_not_run(self):
40+
self.xml()
41+
report = self.report()
42+
self.assertEqual('PASS', report['status'])
43+
self.assertEqual(2, report['layers']['argv']['executed'])
44+
self.assertEqual('NOT_RUN', report['layers']['real-execution']['status'])
45+
self.assertEqual(HEAD, report['head'])
46+
json.dumps(report)
47+
48+
def test_process_layer_is_separate_from_real_execution(self):
49+
self.xml()
50+
report = self.module.build_report(self.root, head=HEAD, branch='feature/2.0.x',
51+
java_version='fixture-jdk', maven_version='fixture-maven', exit_code=0,
52+
required_suites={'process': [SUITE]})
53+
self.assertEqual('PASS', report['status'])
54+
self.assertEqual(2, report['layers']['process']['executed'])
55+
self.assertEqual('NOT_RUN', report['layers']['real-execution']['status'])
56+
57+
def test_missing_report_fails(self):
58+
self.assertEqual('FAIL', self.report()['status'])
59+
60+
def test_zero_tests_fails(self):
61+
self.xml(tests=0)
62+
self.assertEqual('FAIL', self.report()['status'])
63+
64+
def test_zero_tests_in_one_required_suite_cannot_hide_behind_a_passing_suite(self):
65+
self.xml()
66+
self.xml(tests=0, suite=SECOND_SUITE)
67+
result = self.report(required_suites={'argv': [SUITE, SECOND_SUITE]})
68+
self.assertEqual('FAIL', result['status'])
69+
self.assertEqual([SECOND_SUITE], result['layers']['argv']['unprovenSuites'])
70+
71+
def test_suite_cannot_supply_multiple_evidence_layers(self):
72+
self.xml()
73+
result = self.report(required_suites={'argv': [SUITE], 'real-execution': [SUITE]})
74+
self.assertEqual('FAIL', result['status'])
75+
self.assertIn('suite attribution must be unique across layers', result['problems'])
76+
77+
def test_all_skipped_fails(self):
78+
self.xml(tests=2, skipped=2)
79+
self.assertEqual('FAIL', self.report()['status'])
80+
81+
def test_partly_skipped_fails(self):
82+
self.xml(tests=2, skipped=1)
83+
self.assertEqual('FAIL', self.report()['status'])
84+
85+
def test_failure_fails(self):
86+
self.xml(failures=1)
87+
self.assertEqual('FAIL', self.report()['status'])
88+
89+
def test_error_fails(self):
90+
self.xml(errors=1)
91+
self.assertEqual('FAIL', self.report()['status'])
92+
93+
def test_nonzero_command_exit_fails_despite_green_xml(self):
94+
self.xml()
95+
self.assertEqual('FAIL', self.report(exit_code=1)['status'])
96+
97+
def test_malformed_xml_fails_closed(self):
98+
(self.root / 'TEST-broken.xml').write_text('<broken', encoding='utf-8')
99+
self.assertEqual('FAIL', self.report()['status'])
100+
101+
def test_partial_sha_is_not_accepted(self):
102+
self.xml()
103+
self.assertEqual('FAIL', self.report(head='d0c8056')['status'])
104+
105+
def test_declared_counts_cannot_hide_missing_testcases(self):
106+
self.xml()
107+
path = self.root / ('TEST-' + SUITE + '.xml')
108+
path.write_text(path.read_text().replace('tests="2"', 'tests="100"'), encoding='utf-8')
109+
self.assertEqual('FAIL', self.report()['status'])
110+
111+
def test_undeclared_failure_fails(self):
112+
self.xml()
113+
path = self.root / ('TEST-' + SUITE + '.xml')
114+
path.write_text(path.read_text().replace('</testcase>', '<failure/></testcase>', 1), encoding='utf-8')
115+
self.assertEqual('FAIL', self.report()['status'])
116+
117+
118+
if __name__ == '__main__':
119+
unittest.main()

0 commit comments

Comments
 (0)