Skip to main content
Show test progress in your application while a command is still running. This example uses a small shell test suite so you can see stdout, stderr, and a failing test without preparing a repository. It also disconnects and reconnects the event stream to show how to resume from a saved event ID.

Prerequisites

Complete Set up access. The program requires Python 3.11 or later and uses only the standard library. Export the documented REST values:
The selected image must contain a POSIX shell and the ordinary test, grep, and sleep commands. Keep the bearer credential in the client environment; the program does not send it to sandboxed code.

Follow the workflow

  1. create_test_run() starts the command and records its operation ID.
  2. consume_events() displays each complete output event, then saves its ID. The first connection closes after five processed events, counting lifecycle events and output events. This count is chosen only to demonstrate reconnection.
  3. The next subscription sends the saved ID in Last-Event-Id. It continues the same operation’s output.
  4. final_result() checks the operation and process outcome. A second run includes a failing test so you can see stderr and exit code 1.
Representative output follows. Event IDs, UUIDs, and output chunk boundaries can vary:
For your own test suite, replace TEST_SUITE and adjust the expected output checks in run_variant(). Keep the cursor handling and final status check. See the reconnection diagram for the order of requests.

Run the complete example

Save the following as stream_tests.py and run python3 stream_tests.py. The 120-second deadline covers both operations and can be changed with --deadline.
The first run prints PASS records and SUMMARY passed=2 failed=0. The client closes its first connection only after it has decoded, displayed, and committed a complete event. The resumed request sends that ID in Last-Event-Id, and the client ignores any event ID it has already processed. The second run prints FAIL deliberate-failure on stderr, finishes with SUMMARY passed=2 failed=1, and reports process_exit=1. The program exits nonzero if the API operation fails, the observed process exit differs from the expected outcome, output is truncated, or the deadline expires. Both operations set disposable: true, so they do not create retained images. Their 30-second remote timeout bounds execution if the client disappears. The client also records every operation UUID and cancels any operation it still owns after a local failure. It deliberately reconnects once to demonstrate cursor resumption; an unexpected transport or in-band SSE error stops the recipe and triggers that cleanup. See Stream output and events for cursor and recovery mechanics. The SSE endpoint reference defines the exact frame and error contract; Get operation status defines the terminal result fields.