chore: import upstream snapshot with attribution
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
"""
|
||||
Command runner utilities (stateless).
|
||||
|
||||
Generic utilities for running system binaries/commands via subprocess.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MAX_LINE = 20000
|
||||
|
||||
|
||||
def _first_line(text: str) -> str:
|
||||
"""Extract first line of text, truncated to MAX_LINE."""
|
||||
if not text:
|
||||
return ""
|
||||
return text.splitlines()[0][:MAX_LINE]
|
||||
|
||||
|
||||
def run_tool(cmd: list[str], timeout: int = 10, step_name: str = "") -> dict:
|
||||
"""
|
||||
Run CLI tool and return result metadata (stateless).
|
||||
|
||||
Args:
|
||||
cmd: Command as list of strings (e.g., ["aws", "s3", "ls"])
|
||||
timeout: Timeout in seconds
|
||||
step_name: Optional step name for logging
|
||||
|
||||
Returns:
|
||||
Dict with step_name, command, exit_code, stderr_summary, stdout_summary
|
||||
"""
|
||||
cmd_str = " ".join(cmd)
|
||||
logger.info("command=%s step=%s parent_pid=%s", cmd_str, step_name, os.getpid())
|
||||
|
||||
process = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
logger.info("tool_pid=%s", process.pid)
|
||||
|
||||
try:
|
||||
stdout, stderr = process.communicate(timeout=timeout)
|
||||
exit_code = process.returncode
|
||||
except subprocess.TimeoutExpired:
|
||||
process.kill()
|
||||
stdout, stderr = process.communicate()
|
||||
exit_code = process.returncode
|
||||
logger.error(
|
||||
"step=%s timeout=%s exit_code=%s",
|
||||
step_name,
|
||||
timeout,
|
||||
exit_code,
|
||||
)
|
||||
|
||||
out_decoded = stdout.decode("utf-8", errors="replace") if stdout else ""
|
||||
err_decoded = stderr.decode("utf-8", errors="replace") if stderr else ""
|
||||
|
||||
if out_decoded.strip():
|
||||
logger.info(
|
||||
"step=%s exit_code=%s stdout_len=%s",
|
||||
step_name,
|
||||
exit_code,
|
||||
len(out_decoded),
|
||||
)
|
||||
for line in out_decoded.strip().splitlines():
|
||||
logger.info("stdout: %s", line[:MAX_LINE] if len(line) > MAX_LINE else line)
|
||||
if err_decoded.strip():
|
||||
logger.error(
|
||||
"step=%s exit_code=%s stderr_len=%s",
|
||||
step_name,
|
||||
exit_code,
|
||||
len(err_decoded),
|
||||
)
|
||||
for line in err_decoded.strip().splitlines():
|
||||
logger.error("stderr: %s", line[:MAX_LINE] if len(line) > MAX_LINE else line)
|
||||
|
||||
logger.info("step=%s exit_code=%s", step_name, exit_code)
|
||||
return {
|
||||
"step_name": step_name,
|
||||
"command": cmd_str,
|
||||
"exit_code": exit_code,
|
||||
"stderr_summary": _first_line(err_decoded.strip()),
|
||||
"stdout_summary": _first_line(out_decoded.strip()),
|
||||
}
|
||||
Reference in New Issue
Block a user