#!/usr/bin/env bash
# Every check a change must pass, run on this machine. .githooks/pre-push runs it before a push
# (NO_CHECK=1 skips it); enable the hook once per clone with `git config core.hooksPath .githooks`.
# Runs the shared-support check (bin/check-shared-support) and its own test, rustfmt, clippy and the Rust
# workspace suite, the Qt app's tests (notes/bin/test), then the shell scripts' syntax, install.sh's
# shared add_signed_repo hash and install.sh and the per-app installers against stubbed pacman
# (tests/install_test.sh), and the packaging and release tests (tests/packaging_test.py).
# The notes-sync recorded scenarios and golden corpora
# run with the rest (see notes-sync/tests/differential/README.md).
set -euo pipefail
cd "$(dirname "$0")/.."
export PATH="$HOME/.cargo/bin:$PATH"

# Validate vendored support before the more expensive product checks.
python3 bin/check-shared-support
python3 tests/test_shared_support.py

cargo fmt --all -- --check
cargo clippy --locked --workspace --all-targets -- -D warnings

# The sign-in window needs webkitgtk-6.0; the daemon tests without it.
if pkg-config --exists webkitgtk-6.0; then
  cargo test --locked --workspace
else
  echo "webkitgtk-6.0 not found: testing icloud-sessiond without the sign-in window (--no-default-features)" >&2
  cargo test --locked --workspace --exclude icloud-sessiond
  cargo test --locked -p icloud-sessiond --no-default-features
fi

notes/bin/test

tests/install_test.sh

python3 tests/packaging_test.py

printf '\nAll checks passed.\n'
