Files
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

121 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Run pytest targets relevant to files changed on this branch.
Usage
-----
make test-scope
make test-scope ARGS=--dry-run
python .github/ci/run_test_scope.py [--dry-run] [--base <ref>]
Exit codes mirror pytest: 0 = all pass, non-zero = failure or config error.
"""
from __future__ import annotations
import argparse
import subprocess
import sys
from pathlib import Path
_CI_DIR = Path(__file__).resolve().parent
if str(_CI_DIR) not in sys.path:
sys.path.insert(0, str(_CI_DIR))
from test_scope_rules import classify # noqa: E402
def _commit_ref_exists(ref: str) -> bool:
return (
subprocess.run(
["git", "rev-parse", "--verify", "--quiet", f"{ref}^{{commit}}"],
check=False,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
).returncode
== 0
)
def _resolve_base_ref(base: str) -> str:
"""Prefer branch refs for unqualified bases so same-named tags do not win."""
if "/" in base or base.startswith("refs/"):
return base
for ref in (
f"refs/heads/{base}",
f"refs/remotes/origin/{base}",
f"refs/remotes/upstream/{base}",
):
if _commit_ref_exists(ref):
return ref
return base
def _git_changed_files(base: str) -> list[str]:
resolved_base = _resolve_base_ref(base)
try:
merge_base = subprocess.check_output(
["git", "merge-base", "HEAD", resolved_base],
text=True,
stderr=subprocess.DEVNULL,
).strip()
except subprocess.CalledProcessError:
merge_base = "HEAD~1"
result = subprocess.check_output(
["git", "diff", "--name-only", merge_base],
text=True,
)
return [f.strip() for f in result.splitlines() if f.strip()]
def _run(cmd: list[str], *, dry_run: bool) -> int:
print(f"\n $ {' '.join(cmd)}\n", flush=True)
if dry_run:
return 0
return subprocess.run(cmd, check=False).returncode
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--dry-run", action="store_true", help="Print command without running.")
parser.add_argument(
"--base",
default="main",
help="Ref to diff against (default: main). Falls back to HEAD~1 if unavailable.",
)
args = parser.parse_args(argv)
try:
changed = _git_changed_files(args.base)
except subprocess.CalledProcessError as exc:
print(f"error: could not determine changed files: {exc}", file=sys.stderr)
return 1
if not changed:
print("No changed files detected — nothing to test.")
return 0
print(f"Changed files ({len(changed)}):")
for path in changed:
print(f" {path}")
escalate, targets, areas = classify(changed)
if escalate:
print("\nEscalating to full unit suite (core/shared code or 3+ areas touched).")
return _run(["make", "test-cov"], dry_run=args.dry_run)
if not targets:
print("\nNo test targets matched — running full unit suite as fallback.")
return _run(["make", "test-cov"], dry_run=args.dry_run)
print(f"\nAreas touched: {', '.join(areas)}")
print(f"Running scoped tests: {' '.join(targets)}")
return _run(
[sys.executable, "-m", "pytest", *targets, "-v"],
dry_run=args.dry_run,
)
if __name__ == "__main__":
sys.exit(main())