Skip to content

feat(e2e): add reusable in-process example runner harness - #873

Merged
janzak-dev merged 5 commits into
mainfrom
feat/e2e-example-runner-harness
Sep 17, 2026
Merged

janzak-dev merged 5 commits into
mainfrom
feat/e2e-example-runner-harness

Conversation

@janzak-dev

@janzak-dev janzak-dev commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Introduces an in-process, reusable Python test execution harness (example_runner) and comprehensive unit tests for executing XMC developer example scripts within end-to-end integration test suites.

Motivation & Context

Testing real example scripts (examples/chart_artifact_job/launch.py, examples/simple_job/launch.py, etc.) in end-to-end integration environments requires:

  1. Isolated Subprocess Execution: Running example scripts in a dedicated subprocess to avoid Abseil flag, global logging, and gRPC channel pool pollution inside the test runner process.
  2. Automated Credential & Endpoint Injection: Dynamically resolving the local KinD NodePort gRPC endpoint (127.0.0.1:50051) and injecting minted Dex OIDC Bearer tokens (XMC_AUTH_TOKEN), XMC_INSECURE_GRPC=true, and persona email (XMC_USER_EMAIL).
  3. Structured Output Parsing: Parsing standard XMC stdout to extract generated runtime database keys: Experiment ID (xid), WorkUnit ID (wid), and canonical Artifact name.
  4. Diagnostic Error & Timeout Capture: Intercepting subprocess.TimeoutExpired and process failures to capture combined stdout/stderr for immediate troubleshooting in CI/CD.

This PR introduces test/e2e/examples/example_runner.py and its Bazel targets as the shared harness for all Tier 2 and Tier 3 workflow tests.

How Downstream Tests Consume example_runner (e.g. PR #714)

Downstream integration tests (such as PR #714 - Chart Artifact E2E test) use example_runner as the workload execution and metadata extraction bridge:

# 1. Execute the example script via the reusable harness
launch_result = execute_example_launch(
    launch_script="examples/chart_artifact_job/launch.py",
    user_email=ADMIN_USER,
)

# 2. Consume typed metadata to verify backend Spanner storage via REST API
get_art_res = page.request.get(f"{BASE_URL}/v1/{launch_result.artifact_name}")
assert get_art_res.status == 200

# 3. Direct Playwright browser to the created workunit page to verify UI rendering
page.goto(f"{BASE_URL}/experiments/{launch_result.xid}/workUnits/{launch_result.wid}")
expect(page.get_by_text("Randomized Training Run")).to_be_visible()

Stack Position

This PR is Layer 2 of the E2E PR stack:

  1. PR feat(e2e): harden test orchestration, auth token helpers, and kind resolver #746 (feat(e2e): harden test orchestration, auth token helpers, and kind resolver): Merged into main
  2. This PR (feat(e2e): add reusable in-process example runner harness #873, feat(e2e): add reusable in-process example runner harness): Base: main
  3. PR feat(e2e): add tier-2 integration test for demo workload workflow #714 (feat(e2e): add Tier 2 integration test for chart artifact example workflow): Base: feat/e2e-example-runner-harness

Key Changes

  • test/e2e/examples/example_runner.py:
    • Implemented execute_example_launch() with subprocess execution and auth environment injection (XMC_AUTH_TOKEN, XMANAGER_ENDPOINT, XMC_INSECURE_GRPC).
    • Implemented parse_launch_output() to extract xid, wid, and artifact_name from stdout logs into a typed ExampleLaunchResult.
    • Implemented port_forward_grpc_service() context manager to resolve or verify local gRPC endpoints.
    • Added error capture and timeout logging for subprocess.TimeoutExpired.
  • test/e2e/examples/example_runner_test.py:
    • Comprehensive unit tests verifying successful execution, stdout parsing, custom env overrides, port forwarding resolution, and timeout error handling.
  • test/e2e/examples/BUILD.bazel:
    • Added example_runner_lib, example_runner_test, and examples_pkg targets.

Assumptions

None — requirements were fully specified.

Verification & Testing

  • Bazel Unit Tests:
    • bazel test //test/e2e/examples:... (PASSED)
    • bazel test //test/e2e/... (12/12 test targets PASSED)
  • Linters & Static Analysis:
    • ./.githooks/pre-commit (all checks passed: buildifier, gofmt, golangci-lint, addlicense, ruff)
  • Diff Sizing:
    • ./tools/analyze_diff_size.py --base-ref origin/main (0 prod / 500 test / 500 total lines — within all thresholds)

Related Issues / Bugs

N/A

TAG=agy
CONV=f070b97a-6c09-4041-be95-0e08bf1c0131

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a reusable test harness and subprocess execution utilities for XMC example jobs, including Bazel build configurations and comprehensive unit tests. The review feedback suggests several robustness and debuggability improvements: directly trusting the XMANAGER_ENDPOINT environment variable without performing a transient port check, reusing an existing XMC_AUTH_TOKEN from the environment to avoid redundant token requests, catching subprocess.TimeoutExpired to log captured output upon timeouts, and simplifying the corresponding unit tests.

Comment thread test/e2e/examples/example_runner.py Resolved
Comment thread test/e2e/examples/example_runner.py Resolved
Comment thread test/e2e/examples/example_runner.py Resolved
@janzak-dev
janzak-dev added this pull request to stack #874 September 14, 2026 11:12
Base automatically changed from feat/e2e-example-runner-infra to main September 16, 2026 09:16
@janzak-dev
janzak-dev force-pushed the feat/e2e-example-runner-harness branch from 00f8248 to fcabeb3 Compare September 16, 2026 09:16
@janzak-dev
janzak-dev marked this pull request as ready for review September 16, 2026 11:01
- Introduce ExampleRunner class for executing XManager example scripts in subprocess with injected auth environment
- Add Bazel targets and unit tests in test/e2e/examples
- Wire examples_e2e_pkg dependency into root test/e2e BUILD.bazel

TAG=agy
CONV=251c6b67-d377-495f-841d-676ceff5fb73
…and capture timeout output in example runner

- Trust XMANAGER_ENDPOINT if set without socket checking.
- Reuse existing XMC_AUTH_TOKEN if present before fetching Dex token.
- Capture and log stdout/stderr upon subprocess.TimeoutExpired.
- Update and simplify unit tests in example_runner_test.py.

Addresses review comments on PR #873:
- #873 (comment)
- #873 (comment)
- #873 (comment)
- #873 (comment)

TAG=agy
CONV=f070b97a-6c09-4041-be95-0e08bf1c0131
…le runner

Add TODO above parse_launch_output explaining that regex matching stdout
is brittle and recommending standardizing example launch outputs explicitly.

TAG=agy
CONV=f070b97a-6c09-4041-be95-0e08bf1c0131
Remove artificial PROJECT_ID, IMAGE_PATH, and QUEUE_NAME fallbacks from
execute_example_launch proc_env, requiring callers or environment to supply
actual workload parameters.

TAG=agy
CONV=f070b97a-6c09-4041-be95-0e08bf1c0131
@janzak-dev
janzak-dev force-pushed the feat/e2e-example-runner-harness branch from b586396 to 79f929c Compare September 16, 2026 11:51
andrzejfudro
andrzejfudro previously approved these changes Sep 16, 2026
Comment thread test/e2e/examples/example_runner.py Resolved
Comment thread test/e2e/examples/example_runner.py Resolved
Comment thread test/e2e/examples/example_runner.py Resolved
…arden stdout parsing

- Remove unused admin user/password constants from example_runner.py.
- Rename port_forward_grpc_service to resolve_grpc_endpoint.
- Harden parse_launch_output regexes across all example workload stdout patterns.
- Add parameterized unit tests in example_runner_test.py.

Addresses review comments on PR #873:
- #873 (comment)
- #873 (comment)
- #873 (comment)

TAG=agy
CONV=f070b97a-6c09-4041-be95-0e08bf1c0131
@janzak-dev
janzak-dev added this pull request to the merge queue Sep 17, 2026
Merged via the queue into main with commit bcf1e8b Sep 17, 2026
11 checks passed
@janzak-dev
janzak-dev deleted the feat/e2e-example-runner-harness branch September 17, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority::2-high top of mind. should not wait.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants