|
3 | 3 | import io.github.easy4j.opencli.OpenCliClient; |
4 | 4 | import io.github.easy4j.opencli.OpenCliProperties; |
5 | 5 | import io.github.easy4j.opencli.browser.OpenCliBrowserSession; |
| 6 | +import io.github.easy4j.opencli.browser.OpenCliBrowserSession.OpenCliBrowserNetworkOptions; |
6 | 7 | import io.github.easy4j.opencli.browser.result.OpenCliBrowserAnalysisResult; |
7 | 8 | import io.github.easy4j.opencli.browser.result.OpenCliBrowserConsoleResult; |
8 | 9 | import io.github.easy4j.opencli.browser.result.OpenCliBrowserFindResult; |
|
15 | 16 | import io.github.easy4j.opencli.browser.result.OpenCliBrowserTab; |
16 | 17 | import io.github.easy4j.opencli.browser.support.OpenCliBrowserFindOptions; |
17 | 18 | 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; |
18 | 24 | import io.github.easy4j.opencli.exception.OpenCliNonZeroExitException; |
19 | 25 | import io.github.easy4j.opencli.browser.support.OpenCliBrowserSnapshotSource; |
20 | 26 | import java.net.URI; |
21 | 27 | import java.util.Collections; |
22 | 28 | import java.util.List; |
23 | 29 | import java.util.Objects; |
| 30 | +import java.util.UUID; |
24 | 31 | import org.junit.jupiter.api.Test; |
25 | 32 |
|
26 | 33 | import static org.junit.jupiter.api.Assertions.assertEquals; |
@@ -118,6 +125,39 @@ private static OpenCliBrowserTab boundPage(OpenCliBrowserSession session, String |
118 | 125 | .orElseThrow(() -> new AssertionError("The original bound tab must remain open")); |
119 | 126 | } |
120 | 127 |
|
| 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 | + |
121 | 161 | private static OpenCliProperties properties() { |
122 | 162 | OpenCliProperties properties = new OpenCliProperties(); |
123 | 163 | properties.setExecutable(requiredEnvironment("OPENCLI_INSTALLED_NODE")); |
|
0 commit comments