#!/usr/bin/env bash # Full native build/test/launch in a disposable environment, following # nigig-org/tools/test-rust-clean.sh. Never substitutes pure-engine tests for # building the real app. Requires curl, tar, native Makepad libraries, and a # display (or xvfb-run on headless Linux). No global Rust installation changes. set -Eeuo pipefail REPO_ROOT="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)" MAKEPAD_DIR="${MAKEPAD_DIR:-$REPO_ROOT/../nigig-org/makepad-native-glue/makepad}" TOOLCHAIN="${RUST_TOOLCHAIN:-stable}" SMOKE_SECONDS="${SMOKE_SECONDS:-15}" [[ "$SMOKE_SECONDS" =~ ^[1-9][0-9]*$ ]] || { echo 'SMOKE_SECONDS must be positive' >&2; exit 2; } [[ -f "$MAKEPAD_DIR/widgets/Cargo.toml" ]] || { echo "Missing Makepad checkout: $MAKEPAD_DIR" >&2; exit 2; } MAKEPAD_DIR="$(cd "$MAKEPAD_DIR" && pwd -P)" # /tmp can be a small tmpfs; match nigig's disk-backed default instead. mkdir -p "${TMPDIR:-$HOME/tmp}" WORK_DIR="$(mktemp -d "${TMPDIR:-$HOME/tmp}/budget-rust-run.XXXXXXXX")" cleanup() { local status=$? trap - EXIT if [[ -n "${VALIDATION_ARTIFACTS:-}" ]]; then mkdir -p "$VALIDATION_ARTIFACTS" cp -r "$WORK_DIR/budget-app/app/target/makepad_test" "$VALIDATION_ARTIFACTS/" 2>/dev/null || true fi rm -rf -- "$WORK_DIR" echo "Removed temporary Rust environment: $WORK_DIR" >&2 exit "$status" } trap cleanup EXIT trap 'exit 130' INT trap 'exit 143' TERM HUP export RUSTUP_HOME="$WORK_DIR/rustup" export CARGO_HOME="$WORK_DIR/cargo" export CARGO_TARGET_DIR="$WORK_DIR/target" export CARGO_INCREMENTAL=0 export CARGO_BUILD_JOBS="${CARGO_BUILD_JOBS:-1}" export CARGO_PROFILE_DEV_DEBUG=0 export CARGO_PROFILE_TEST_DEBUG=0 export PATH="$CARGO_HOME/bin:$PATH" mkdir -p "$WORK_DIR/home" "$WORK_DIR/budget-app" "$WORK_DIR/nigig-org/makepad-native-glue" # Preserve the manifest's relative path dependencies, without rewriting it. ln -s "$MAKEPAD_DIR" "$WORK_DIR/nigig-org/makepad-native-glue/makepad" tar -C "$REPO_ROOT" --exclude=.git --exclude=target -cf - . | tar -C "$WORK_DIR/budget-app" -xf - curl --fail --location --proto '=https' --tlsv1.2 https://sh.rustup.rs -o "$WORK_DIR/rustup-init" sh "$WORK_DIR/rustup-init" -y --profile minimal --default-toolchain "$TOOLCHAIN" --no-modify-path # Isolate runtime state after installation (rustup checks the real home). export HOME="$WORK_DIR/home" export XDG_DATA_HOME="$HOME/.local/share" export XDG_CONFIG_HOME="$HOME/.config" export XDG_CACHE_HOME="$HOME/.cache" cd "$WORK_DIR/budget-app" cp docs/Cargo.lock Cargo.lock cargo --version rustc --version if [[ -n "${VALIDATED_LOCKFILE_OUTPUT:-}" ]]; then cargo generate-lockfile fi if [[ "${ANDROID_ONLY:-0}" != 1 ]]; then cargo test --workspace --lib --locked cargo test -p budget --test models --test desktop_review --locked cargo test -p budget-capture --test ocr --test desktop --locked if [[ "${LIVE_X11_CAPTURE:-0}" == 1 ]]; then env -u WAYLAND_DISPLAY XDG_SESSION_TYPE=x11 BUDGET_LIVE_X11_TEST=1 xvfb-run -a cargo test -p budget-capture --test desktop --locked env -u WAYLAND_DISPLAY XDG_SESSION_TYPE=x11 BUDGET_LIVE_TRAY_TEST=1 dbus-run-session -- cargo test -p budget-capture --test desktop_tray --locked fi python3 -m unittest discover -s app/tests -p 'test_*.py' python3 -m unittest discover -s budget-capture/tests -p 'test_*.py' bash budget-capture/tests/run-java.sh "$WORK_DIR/java-tests" # Real event-driven UI tests (owned application processes), never ignored. if [[ "${LIVE_X11_CAPTURE:-0}" == 1 ]]; then env -u WAYLAND_DISPLAY XDG_SESSION_TYPE=x11 BUDGET_LIVE_X11_TEST=1 LIBGL_ALWAYS_SOFTWARE=1 dbus-run-session -- xvfb-run -a cargo test --release -p budget --test ui --locked -- --test-threads=1 else LIBGL_ALWAYS_SOFTWARE=1 xvfb-run -a cargo test --release -p budget --test ui --locked -- --test-threads=1 fi # Build/link without a timeout; only the GUI smoke window is time-limited. cargo build --locked set +e if [[ "$(uname -s)" == Linux && -z "${DISPLAY:-}" ]]; then if ! command -v xvfb-run >/dev/null; then echo 'Build passed, but launch NOT tested: install xvfb/xauth or provide DISPLAY.' >&2 exit 2 fi LIBGL_ALWAYS_SOFTWARE=1 xvfb-run -a timeout --signal=TERM "$SMOKE_SECONDS" cargo run --locked > "$WORK_DIR/native-smoke.log" 2>&1 else timeout --signal=TERM "$SMOKE_SECONDS" cargo run --locked > "$WORK_DIR/native-smoke.log" 2>&1 fi status=$? set -e cat "$WORK_DIR/native-smoke.log" if grep -Eq 'boot err after|variable .* not found in scope|panicked at' "$WORK_DIR/native-smoke.log"; then echo 'Native app reported a startup/script failure.' >&2 exit 1 fi if [[ "$status" == 124 ]]; then echo "cargo run remained alive for the ${SMOKE_SECONDS}s smoke window (not an interactive UI test)." elif [[ "$status" != 0 ]]; then echo "cargo run failed with exit $status" >&2 exit "$status" fi fi # native/UI gates if [[ -n "${VALIDATED_LOCKFILE_OUTPUT:-}" ]]; then cp Cargo.lock "$VALIDATED_LOCKFILE_OUTPUT" fi if [[ "${FULL_ANDROID:-0}" == 1 ]]; then cargo test --manifest-path "$MAKEPAD_DIR/tools/cargo_makepad/Cargo.toml" -- --test-threads=1 cargo install --path "$MAKEPAD_DIR/tools/cargo_makepad" --root "$CARGO_HOME" --locked cargo makepad android --sdk-path="$WORK_DIR/android-sdk" install-toolchain bash budget-capture/tests/check-java-sdk.sh "$WORK_DIR/android-sdk" "$WORK_DIR/java-sdk-check" "$MAKEPAD_DIR" cargo makepad android --sdk-path="$WORK_DIR/android-sdk" build -p budget --release python3 app/tests/verify_apk.py "$CARGO_TARGET_DIR" "$WORK_DIR/android-sdk" fi echo 'Requested validation gates completed successfully.'