Skip to content

Commit 6da93d0

Browse files
committed
Require nonempty evidence per OpenCLI contract suite
1 parent c12df8d commit 6da93d0

5 files changed

Lines changed: 109 additions & 28 deletions

File tree

‎.github/workflows/contracts.yml‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
python3 -m unittest discover -s scripts/tests -v
3333
(cd src/test/resources/opencli-contracts/v1 && sha256sum -c SHA256SUMS)
3434
(cd src/test/resources/opencli-contracts/v1/structured-help-1.8.8 && sha256sum --strict -c SHA256SUMS)
35+
(cd src/test/resources/opencli-contracts/v1/browser-output-1.8.8 && sha256sum --strict -c SHA256SUMS)
3536
- name: Install pinned official OpenSpec
3637
run: npm install --prefix "$RUNNER_TEMP/opencli-openspec" --ignore-scripts --no-audit --no-fund @fission-ai/openspec@1.13.1
3738
- name: Validate all proposals and each change with strict mode
@@ -128,6 +129,14 @@ jobs:
128129
--suite process=io.github.easy4j.opencli.contract.OpenCliProcessContractTest \
129130
--suite process=io.github.easy4j.opencli.contract.OpenCliProcessBoundaryTest \
130131
--suite process=io.github.easy4j.opencli.core.support.SubprocessCleanupFaultTest \
132+
--suite protocol=io.github.easy4j.opencli.center.ws.OpenCliWsReverseAgentSessionTest \
133+
--suite protocol=io.github.easy4j.opencli.center.ws.OpenCliWsCollectRequestsTest \
134+
--suite protocol=io.github.easy4j.opencli.remote.OpenCliRemoteAgentHttpClientTest \
135+
--suite protocol=io.github.easy4j.opencli.contract.OpenCliErrorEnvelopeTest \
136+
--suite typed-result=io.github.easy4j.opencli.contract.OpenCliBrowserResultTest \
137+
--suite typed-result=io.github.easy4j.opencli.contract.OpenCliBrowserEvidenceResultTest \
138+
--suite typed-result=io.github.easy4j.opencli.capability.OpenCliDiagnosticsTest \
139+
--suite argv=io.github.easy4j.opencli.capability.OpenCliInvocationContextTest \
131140
--output contract-evidence/report.json
132141
- name: Upload actual JVM evidence
133142
if: always()
@@ -177,7 +186,7 @@ jobs:
177186
mvn -version > platform-evidence/maven.txt 2>&1
178187
result=0
179188
mvn -B --no-transfer-progress \
180-
-Dtest=OpenCliArgvContractTest,OpenCliStructuredArgvContractTest,OpenCliProcessContractTest,OpenCliProcessBoundaryTest,SubprocessCleanupFaultTest,OpenCliWsReverseAgentSessionTest,OpenCliWsCollectRequestsTest,OpenCliProcessPrivacyTest,OpenCliArgSupportTest#shouldKeepConversionExceptionAndNestedCausePrivate,SubprocessExecutionSupportTest#shouldKeepNativePathOutOfDefaultHandlerException \
189+
-Dtest=OpenCliErrorEnvelopeTest,OpenCliBrowserResultTest,OpenCliBrowserEvidenceResultTest,OpenCliDiagnosticsTest,OpenCliInvocationContextTest,OpenCliArgvContractTest,OpenCliStructuredArgvContractTest,OpenCliProcessContractTest,OpenCliProcessBoundaryTest,SubprocessCleanupFaultTest,OpenCliWsReverseAgentSessionTest,OpenCliWsCollectRequestsTest,OpenCliProcessPrivacyTest,OpenCliArgSupportTest#shouldKeepConversionExceptionAndNestedCausePrivate,SubprocessExecutionSupportTest#shouldKeepNativePathOutOfDefaultHandlerException \
181190
test > platform-evidence/maven.log 2>&1 || result=$?
182191
tail -100 platform-evidence/maven.log
183192
python scripts/contract_report.py \
@@ -197,25 +206,16 @@ jobs:
197206
--suite process=io.github.easy4j.opencli.core.OpenCliProcessPrivacyTest \
198207
--suite argv=io.github.easy4j.opencli.core.OpenCliArgSupportTest \
199208
--suite process=io.github.easy4j.opencli.core.support.SubprocessExecutionSupportTest \
209+
--suite protocol=io.github.easy4j.opencli.contract.OpenCliErrorEnvelopeTest \
210+
--suite typed-result=io.github.easy4j.opencli.contract.OpenCliBrowserResultTest \
211+
--suite typed-result=io.github.easy4j.opencli.contract.OpenCliBrowserEvidenceResultTest \
212+
--suite typed-result=io.github.easy4j.opencli.capability.OpenCliDiagnosticsTest \
213+
--suite argv=io.github.easy4j.opencli.capability.OpenCliInvocationContextTest \
200214
--output platform-evidence/report.json
201215
exit "$result"
202216
- name: Verify npm-installed OpenCLI on Windows
203217
if: runner.os == 'Windows'
204-
run: |
205-
install_dir="$RUNNER_TEMP/opencli-launcher-check"
206-
npm install --prefix "$install_dir" --ignore-scripts --no-audit --no-fund @jackwener/opencli@1.8.8
207-
package_dir="$install_dir/node_modules/@jackwener/opencli"
208-
cli_entry="$package_dir/dist/src/main.js"
209-
registry="$install_dir/registry.json"
210-
node "$cli_entry" --version | tee platform-evidence/installed-opencli-version.txt
211-
grep -Fx '1.8.8' platform-evidence/installed-opencli-version.txt
212-
node "$cli_entry" list -f json > "$registry"
213-
OPENCLI_INSTALLED_NODE="$(node -p 'process.execPath')"
214-
OPENCLI_INSTALLED_ENTRY="$(cygpath -w "$cli_entry")"
215-
OPENCLI_INSTALLED_REGISTRY="$(cygpath -w "$registry")"
216-
OPENCLI_INSTALLED_BATCH_SHIM="$(cygpath -w "$install_dir/node_modules/.bin/opencli.cmd")"
217-
export OPENCLI_INSTALLED_NODE OPENCLI_INSTALLED_ENTRY OPENCLI_INSTALLED_REGISTRY OPENCLI_INSTALLED_BATCH_SHIM
218-
mvn -B --no-transfer-progress -Dtest=OpenCliInstalledLauncherIT,OpenCliCapabilityOverrideIT,OpenCliReadOnlyDiagnosticsIT test
218+
run: bash scripts/run_installed_contracts.sh mvn
219219
- name: Upload platform subprocess evidence
220220
if: always()
221221
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
@@ -44,3 +44,9 @@ OC-PARITY-004:维护线原 CI 将 JaCoCo 参数丢在 Surefire JVM 之外,
4444
### 结构化帮助证据门禁
4545

4646
OC-PARITY-003/004:在 `98f28346e7bc3307608122a0086a8e1072e39536` 的 GitHub 工件中,Surefire 记录了三个通过的 `OpenCliStructuredHelpFixtureTest` 用例,契约报告的枚举层仍显示 `NOT_RUN`。从该工件重放报告命令并声明枚举套件后,枚举层显示 `PASS`、执行三项,真实 CLI 执行层仍为 `NOT_RUN`。移除套件报告时,报告命令返回非零。三条开发线使用同一份 SHA-256 清单检查九个帮助样本,在临时副本的 `root.json` 末尾追加换行会使校验失败。样本提供离线结构证据,实时能力发现和真实执行由对应任务另行验收。
47+
48+
### 每个必选套件的执行证据
49+
50+
OC-PARITY-003/004:当同一层含一个已执行套件及一个零用例套件时,旧报告返回 PASS。把同一套件注册到 argv 与 real-execution 也会重复记账。新增两个失败回归后,报告逐套件检查非零执行、零跳过、零失败及零错误,并拒绝同一套件跨层归因。问题套件列在 `unprovenSuites`。
51+
52+
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"

‎scripts/tests/test_contract_report.py‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
SCRIPT = pathlib.Path(__file__).resolve().parents[1] / 'contract_report.py'
88
HEAD = 'd0c8056990f7a47fcc202acffa387ba066bcfc67'
99
SUITE = 'io.github.easy4j.opencli.contract.OpenCliArgvContractTest'
10+
SECOND_SUITE = 'io.github.easy4j.opencli.contract.OpenCliStructuredArgvContractTest'
1011

1112

1213
class ContractReportTest(unittest.TestCase):
@@ -19,21 +20,21 @@ def setUp(self):
1920
self.addCleanup(self.temp.cleanup)
2021
self.root = pathlib.Path(self.temp.name)
2122

22-
def xml(self, tests=2, skipped=0, failures=0, errors=0):
23+
def xml(self, tests=2, skipped=0, failures=0, errors=0, suite=SUITE):
2324
executed = tests - skipped
2425
cases = []
2526
for i in range(tests):
2627
child = '<skipped/>' if i >= executed else ('<failure/>' if i < failures else ('<error/>' if i < failures + errors else ''))
2728
cases.append('<testcase name="case' + str(i) + '">' + child + '</testcase>')
28-
(self.root / ('TEST-' + SUITE + '.xml')).write_text(
29-
'<testsuite name="' + SUITE + '" tests="' + str(tests) + '" skipped="' + str(skipped)
29+
(self.root / ('TEST-' + suite + '.xml')).write_text(
30+
'<testsuite name="' + suite + '" tests="' + str(tests) + '" skipped="' + str(skipped)
3031
+ '" failures="' + str(failures) + '" errors="' + str(errors) + '">' + ''.join(cases) + '</testsuite>', encoding='utf-8')
3132

3233
def report(self, **kwargs):
3334
return self.module.build_report(self.root, head=kwargs.get('head', HEAD),
3435
branch='feature/2.0.x', java_version='openjdk 17 (test fixture)',
3536
maven_version='Apache Maven (test fixture)', exit_code=kwargs.get('exit_code', 0),
36-
required_suites={'argv': [SUITE]})
37+
required_suites=kwargs.get('required_suites', {'argv': [SUITE]}))
3738

3839
def test_complete_argv_evidence_passes_but_live_is_not_run(self):
3940
self.xml()
@@ -60,6 +61,19 @@ def test_zero_tests_fails(self):
6061
self.xml(tests=0)
6162
self.assertEqual('FAIL', self.report()['status'])
6263

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+
6377
def test_all_skipped_fails(self):
6478
self.xml(tests=2, skipped=2)
6579
self.assertEqual('FAIL', self.report()['status'])

0 commit comments

Comments
 (0)