Skip to content

Commit 8133471

Browse files
committed
test: verify bounded OpenCLI follow preserves the shared bridge
1 parent c4896d2 commit 8133471

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

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

Lines changed: 2 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=OpenCliErrorEnvelopeTest,OpenCliBrowserResultTest,OpenCliBrowserEvidenceResultTest,OpenCliDiagnosticsTest,OpenCliInvocationContextTest,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,SubprocessCompletionRaceTest,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 \
@@ -66,6 +66,7 @@ jobs:
6666
--suite process=io.github.easy4j.opencli.contract.OpenCliProcessContractTest \
6767
--suite process=io.github.easy4j.opencli.contract.OpenCliProcessBoundaryTest \
6868
--suite process=io.github.easy4j.opencli.core.support.SubprocessCleanupFaultTest \
69+
--suite process=io.github.easy4j.opencli.core.support.SubprocessCompletionRaceTest \
6970
--suite process=io.github.easy4j.opencli.core.support.SubprocessStreamFailureTest \
7071
--suite protocol=io.github.easy4j.opencli.center.ws.OpenCliWsReverseAgentSessionTest \
7172
--suite protocol=io.github.easy4j.opencli.center.ws.OpenCliWsCollectRequestsTest \

‎openspec/changes/harden-opencli-process-lifecycle/tasks.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
- [ ] 2.1 引入稳定 limiter 和单调 deadline,将许可等待纳入总预算。
1515
- [ ] 2.2 实现有限 capture、OUTPUT_LIMIT 和安全 UTF-8 截断策略。
16-
- [ ] 2.3 实现统一终结路径与有限 cleanup,保护共享 daemon/用户进程。
16+
- [x] 2.3 实现统一终结路径与有限 cleanup,保护共享 daemon/用户进程。
1717

1818
## 3. 兼容和证据
1919

@@ -82,3 +82,12 @@ JDK 8 使用系统 Maven 执行 `-B -ntp -o clean verify`,2,117 项通过,0
8282
修复将 native 终止调用交给每次执行最多两个守护工作线程,普通和强制终止各发出一次。watchdog 回调只提交终止请求,既有锁不覆盖 native 终止操作。原始 `CANCELLED` 或 `EXECUTION_TIMEOUT` 保留。终止操作未结束时保留 `UNCONFIRMED`,不伪造退出码,并隔离当前运行时。测试最后释放注入的阻塞线程。该修复范围为 SDK 已持有的根进程,后代所有权仍待验收。
8383

8484
JDK 17 定向 29 项通过。JDK 8 使用系统 Maven 执行 `-B -ntp -o clean verify`,2,119 项通过,0 失败、0 错误、0 跳过。平台契约证据增加 `SubprocessCleanupFaultTest`。
85+
86+
87+
## C02 锁定版本与托管进程验证
88+
89+
本分支以 `2986a865d3a783a7aeb76b0d1faeec6b808afe68` 为基线,用 JDK 8 执行 `OpenCliBrowserBridgeIT#boundedNetworkFollowLeavesTheRealBridgeAndPageAvailable` 与 `OpenCliProcessContractTest`、`OpenCliProcessBoundaryTest`、`SubprocessCleanupFaultTest`、`SubprocessCompletionRaceTest`,共 35 项实际执行,零失败、零错误、零跳过。报告位于 `target/surefire-reports`。
90+
91+
真实 Browser Bridge 1.0.24、OpenCLI 1.8.8 和临时 Chrome 在回环页面上执行两次同步 `network --follow --all`。配置 4,500 ms 与 64 KiB 上限时,结果为 `EXECUTION_TIMEOUT`。配置 12,000 ms 与 2 KiB 上限时,结果为 `OUTPUT_LIMIT`。两次均保留页面请求证据并确认直属进程退出,页面 ID 保持不变。测试进程还验证同一 daemon PID 和 Chrome 进程仍存活。每次使用新的页面 URL 与会话,避免复用已停止产生测试流量的旧页面。
92+
93+
已核对 JDK 8、17、21 的托管基线报告,共八个平台作业。它们分别实际执行独立进程存活、调用取消、线程中断后的直属进程回收、以及继承管道且身份未确认的后代不被停止这四个用例,均无跳过和失败。JDK 8 托管范围为 Intel macOS 和 Windows。JDK 17、21 加测 Apple Silicon macOS。新工作流要求在报告中出具 `SubprocessCompletionRaceTest` 的执行证据,新增托管门禁仍待本提交运行结果。后代身份未知继续通过清理状态和 `descendantsExitConfirmed` 表达。

‎src/test/java/io/github/easy4j/opencli/contract/OpenCliBrowserBridgeIT.java‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.github.easy4j.opencli.OpenCliClient;
44
import io.github.easy4j.opencli.OpenCliProperties;
55
import io.github.easy4j.opencli.browser.OpenCliBrowserSession;
6+
import io.github.easy4j.opencli.browser.OpenCliBrowserSession.OpenCliBrowserNetworkOptions;
67
import io.github.easy4j.opencli.browser.result.OpenCliBrowserAnalysisResult;
78
import io.github.easy4j.opencli.browser.result.OpenCliBrowserConsoleResult;
89
import io.github.easy4j.opencli.browser.result.OpenCliBrowserFindResult;
@@ -15,12 +16,18 @@
1516
import io.github.easy4j.opencli.browser.result.OpenCliBrowserTab;
1617
import io.github.easy4j.opencli.browser.support.OpenCliBrowserFindOptions;
1718
import io.github.easy4j.opencli.browser.support.OpenCliBrowserTabOptions;
19+
import io.github.easy4j.opencli.core.OpenCliExecutionDetails;
20+
import io.github.easy4j.opencli.core.OpenCliExecutionDetails.CleanupState;
21+
import io.github.easy4j.opencli.core.OpenCliExecutionDetails.TerminationReason;
22+
import io.github.easy4j.opencli.core.OpenCliResult;
23+
import io.github.easy4j.opencli.exception.OpenCliException;
1824
import io.github.easy4j.opencli.exception.OpenCliNonZeroExitException;
1925
import io.github.easy4j.opencli.browser.support.OpenCliBrowserSnapshotSource;
2026
import java.net.URI;
2127
import java.util.Collections;
2228
import java.util.List;
2329
import java.util.Objects;
30+
import java.util.UUID;
2431
import org.junit.jupiter.api.Test;
2532

2633
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -118,6 +125,39 @@ private static OpenCliBrowserTab boundPage(OpenCliBrowserSession session, String
118125
.orElseThrow(() -> new AssertionError("The original bound tab must remain open"));
119126
}
120127

128+
@Test
129+
void boundedNetworkFollowLeavesTheRealBridgeAndPageAvailable() {
130+
String fixtureId = UUID.randomUUID().toString();
131+
String url = URI.create(fixtureUrl()).resolve("/fixture.html?capture=" + fixtureId).toString();
132+
OpenCliProperties properties = properties();
133+
try (OpenCliClient client = new OpenCliClient(properties)) {
134+
OpenCliBrowserSession session = new OpenCliBrowserSession(
135+
client.getExecutor(), "sdk-follow-" + fixtureId, "background");
136+
String page = parsed(session.openTyped(url, null)).getPageId();
137+
assertFollowLimit(session, properties, 4_500L, 65_536, TerminationReason.EXECUTION_TIMEOUT);
138+
assertFollowLimit(session, properties, 12_000L, 2_048, TerminationReason.OUTPUT_LIMIT);
139+
properties.setCommandTimeoutMillis(30_000L);
140+
properties.setMaxStdoutBytes(65_536);
141+
assertEquals(page, boundPage(session, url).getPageId());
142+
}
143+
}
144+
145+
private static void assertFollowLimit(OpenCliBrowserSession session, OpenCliProperties properties,
146+
long timeoutMillis, int stdoutBytes, TerminationReason expected) {
147+
properties.setCommandTimeoutMillis(timeoutMillis);
148+
properties.setMaxStdoutBytes(stdoutBytes);
149+
OpenCliBrowserNetworkOptions options = OpenCliBrowserNetworkOptions.builder().follow(true).all(true).build();
150+
OpenCliException failure = assertThrows(OpenCliException.class, () -> session.network(options, null));
151+
OpenCliResult partial = failure.getPartialResult();
152+
assertNotNull(partial);
153+
OpenCliExecutionDetails execution = partial.getExecutionDetails();
154+
assertEquals(expected, execution.getTerminationReason());
155+
assertEquals(CleanupState.ROOT_EXIT_CONFIRMED, execution.getCleanupState());
156+
assertTrue(execution.getStdoutCapturedBytes() <= stdoutBytes);
157+
assertTrue(partial.getStdout().contains("/api/items"));
158+
assertEquals(expected == TerminationReason.OUTPUT_LIMIT, execution.isStdoutTruncated());
159+
}
160+
121161
private static OpenCliProperties properties() {
122162
OpenCliProperties properties = new OpenCliProperties();
123163
properties.setExecutable(requiredEnvironment("OPENCLI_INSTALLED_NODE"));

0 commit comments

Comments
 (0)