fd18b547e5
Adds the `user.rust` UPM to workshop-engine for managing Rust toolchains, components, cross-compilation targets, and cargo operations: - `rustup default <toolchain>` / `rustup component add` / `rustup target add` - `cargo fetch` for dependency pre-fetch with optional `--locked` - `cargo install` for global crate tools with registry support Includes 275-line test suite (`tests/upm/test_rust.py`) covering the full lifecycle with optional network tests.
218 lines
7.2 KiB
Bash
Executable File
218 lines
7.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# HoneyBiscuitWorkshop System Test Runner
|
|
#
|
|
# Usage:
|
|
# ./runner.sh # baker tests (default)
|
|
# ./runner.sh -c upm:rust # Rust UPM tests
|
|
# ./runner.sh -c pm:pacman # pacman PM engine tests
|
|
# ./runner.sh -c pm:apt -k test_mirror # apt mirror test only
|
|
# ./runner.sh -c upm:rust --network # include network tests
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
CONTAINER_NAME="hbw-system-test-container"
|
|
STAGING_DIR="$SCRIPT_DIR/.staging"
|
|
|
|
# ── defaults ────────────────────────────────────────────────────────
|
|
|
|
MODE="auto"
|
|
CATEGORY="baker" # baker | upm:<name> | pm:<name>
|
|
TEST_DIR=""
|
|
TEST_IMAGE=""
|
|
PYTEST_ARGS=()
|
|
NETWORK=0
|
|
BAKER_LOG=1
|
|
|
|
# ── parse args ──────────────────────────────────────────────────────
|
|
|
|
show_help() {
|
|
cat << 'HELP'
|
|
Usage: ./runner.sh [OPTIONS]
|
|
|
|
Categories (-c):
|
|
baker Baker system tests [default]
|
|
upm:rust Rust UPM tests
|
|
pm:pacman Pacman PM engine tests
|
|
pm:apt APT PM engine tests
|
|
pm:dnf DNF PM engine tests
|
|
pm:apk APK PM engine tests
|
|
|
|
Options:
|
|
-c, --category CAT Test category (see above)
|
|
--network Allow network-dependent tests (toolchain/crate downloads)
|
|
-k FILTER pytest -k expression
|
|
--timeout SECONDS Per-test timeout (default 120)
|
|
--log / --no-log Stream baker output to terminal [default: --log]
|
|
-h, --help This message
|
|
HELP
|
|
exit 0
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-c|--category)
|
|
CATEGORY="$2"; shift 2 ;;
|
|
--network)
|
|
NETWORK=1; shift ;;
|
|
-k)
|
|
PYTEST_ARGS+=(-k "$2"); shift 2 ;;
|
|
--timeout)
|
|
PYTEST_ARGS+=(--timeout "$2"); shift 2 ;;
|
|
--log) BAKER_LOG=1; shift ;;
|
|
--no-log) BAKER_LOG=0; shift ;;
|
|
manual) MODE="manual"; shift ;;
|
|
auto) MODE="auto"; shift ;;
|
|
-h|--help)
|
|
show_help ;;
|
|
--)
|
|
shift; PYTEST_ARGS+=("$@"); break ;;
|
|
*)
|
|
PYTEST_ARGS+=("$1"); shift ;;
|
|
esac
|
|
done
|
|
|
|
# ── resolve category → test dir + image ─────────────────────────────
|
|
|
|
case "$CATEGORY" in
|
|
baker)
|
|
TEST_DIR="tests/baker"
|
|
TEST_IMAGE="hbw-system-test:latest"
|
|
;;
|
|
upm:rust)
|
|
TEST_DIR="tests/upm"
|
|
TEST_IMAGE="hbw-system-test:latest"
|
|
;;
|
|
pm:pacman|pm:arch)
|
|
TEST_DIR="tests/engine"
|
|
TEST_IMAGE="hbw-test-pm:test-arch"
|
|
;;
|
|
pm:apt)
|
|
TEST_DIR="tests/engine"
|
|
TEST_IMAGE="hbw-test-pm:test-apt"
|
|
;;
|
|
pm:dnf)
|
|
TEST_DIR="tests/engine"
|
|
TEST_IMAGE="hbw-test-pm:test-dnf"
|
|
;;
|
|
pm:apk)
|
|
TEST_DIR="tests/engine"
|
|
TEST_IMAGE="hbw-test-pm:test-apk"
|
|
;;
|
|
*)
|
|
echo "Unknown category: $CATEGORY" >&2
|
|
echo "Run './runner.sh --help' for usage." >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# ── env vars ──────────────────────────────────────────────────────
|
|
|
|
DOCKER_ENV=()
|
|
DOCKER_ENV+=(-e RUST_LOG=${RUST_LOG:-info})
|
|
DOCKER_ENV+=(-e BAKER_LOG=${BAKER_LOG:-1})
|
|
|
|
# Load llm.env if present (for LLM-based test evaluation)
|
|
if [ -f "$SCRIPT_DIR/llm.env" ]; then
|
|
while IFS='=' read -r key value; do
|
|
[ -z "$key" ] && continue
|
|
[[ "$key" =~ ^# ]] && continue
|
|
DOCKER_ENV+=(-e "$key=$value")
|
|
done < "$SCRIPT_DIR/llm.env"
|
|
fi
|
|
|
|
if [ "$NETWORK" -eq 1 ]; then
|
|
DOCKER_ENV+=(-e RUST_UPM_NETWORK=1)
|
|
fi
|
|
|
|
# ── cleanup ─────────────────────────────────────────────────────────
|
|
|
|
cleanup() {
|
|
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
# ── build baker binary ──────────────────────────────────────────────
|
|
|
|
build_binary() {
|
|
local target="x86_64-unknown-linux-musl"
|
|
local binary="$SCRIPT_DIR/workshop-baker/target/$target/debug/workshop-baker"
|
|
if [ ! -f "$binary" ]; then
|
|
echo "[runner] Building static (musl) baker binary..."
|
|
cargo build -p workshop-baker --target "$target" 2>&1 | tail -n 1
|
|
fi
|
|
}
|
|
|
|
# ── staging ─────────────────────────────────────────────────────────
|
|
|
|
prepare_staging() {
|
|
if [ "$TEST_DIR" != "tests/engine" ]; then
|
|
mkdir -p "$STAGING_DIR"
|
|
cp "$SCRIPT_DIR/workshop-baker/target/x86_64-unknown-linux-musl/debug/workshop-baker" "$STAGING_DIR/"
|
|
chmod +x "$STAGING_DIR/workshop-baker"
|
|
fi
|
|
}
|
|
|
|
# ── pm filter ───────────────────────────────────────────────────────
|
|
|
|
pm_filter() {
|
|
case "${TEST_IMAGE##*:}" in
|
|
test-arch) echo "-k pacman" ;;
|
|
test-apt) echo "-k apt" ;;
|
|
test-dnf) echo "-k dnf" ;;
|
|
test-apk) echo "-k apk" ;;
|
|
*) echo "" ;;
|
|
esac
|
|
}
|
|
|
|
# ── run ─────────────────────────────────────────────────────────────
|
|
|
|
run_container() {
|
|
local filter=""
|
|
if [ "$TEST_DIR" = "tests/engine" ]; then
|
|
filter="$(pm_filter)"
|
|
fi
|
|
|
|
echo "============================================"
|
|
echo " HBW System Test Runner"
|
|
echo " Category: $TEST_DIR Image: $TEST_IMAGE"
|
|
echo "============================================"
|
|
|
|
mkdir -p "$SCRIPT_DIR/tests/results"
|
|
|
|
local mounts=(-v "$SCRIPT_DIR:/src:ro")
|
|
if [ "$TEST_DIR" != "tests/engine" ]; then
|
|
mounts+=(-v "$STAGING_DIR:/workshop") # writable: baker writes temp scripts here
|
|
fi
|
|
|
|
local pytest_cmd="python3 -m venv /tmp/v && . /tmp/v/bin/activate && \
|
|
pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple \
|
|
-r $TEST_DIR/../requirements.txt -q && \
|
|
exec python -m pytest -v -s $TEST_DIR ${PYTEST_ARGS[*]} $filter"
|
|
|
|
if [ "$MODE" = "manual" ]; then
|
|
docker run -it --rm --name "$CONTAINER_NAME" --privileged \
|
|
${DOCKER_ENV[@]} "${mounts[@]}" "$TEST_IMAGE"
|
|
else
|
|
# Baker/UPM images (hbw-system-test) have ./entrypoint.sh which
|
|
# doesn't exist when /src is the workdir → override to empty.
|
|
# PM images (hbw-test-pm:*) have /bin/sh -c → CMD passed directly.
|
|
if [ "$TEST_DIR" = "tests/engine" ]; then
|
|
docker run --rm --name "$CONTAINER_NAME" --privileged \
|
|
${DOCKER_ENV[@]} "${mounts[@]}" -w /src \
|
|
"$TEST_IMAGE" "$pytest_cmd"
|
|
else
|
|
docker run --rm --name "$CONTAINER_NAME" --privileged \
|
|
--entrypoint "" ${DOCKER_ENV[@]} "${mounts[@]}" -w /src \
|
|
"$TEST_IMAGE" /bin/sh -c "$pytest_cmd"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# ── main ────────────────────────────────────────────────────────────
|
|
|
|
build_binary
|
|
prepare_staging
|
|
run_container
|
|
echo "[runner] Done."
|