Files
amethyst/tools/arti-build/build-arti-host.sh
T
Claude e39ea55fd6 test(tor): tier-3 integration — JVM host build of Arti, smoke + bootstrap tests
Closes the test gap below the tier-1 unit tests by running the real Arti
JNI shim end-to-end on JVM. Cheaper than an emulator + connectedAndroidTest,
and exercises the exact Rust + JNI code path the Android .so does.

Three tests in TorArtiNativeIntegrationTest:

1. `library loads and reports a version` — always-on smoke check. Loads
   libarti_android.so via System.loadLibrary and calls ArtiNative.getVersion.
   ~10ms. Catches build/link regressions (e.g. a stale .so after an ARTI
   bump, a missing JNI symbol export, a forgotten rebuild on this path).
   Skipped on non-Linux-x86_64 hosts with a clear message pointing at the
   build-arti-host.sh rebuild step.

2. `bootstraps and proxies an HTTPS request through Tor` — opt-in via
   -Pamethyst.arti.integration=true. ArtiNative.initialize → startSocksProxy
   → OkHttp-via-SOCKS → check.torproject.org/api/ip. Asserts "IsTor":true.
   Regression net for the rustls CryptoProvider install we added after the
   v2.3.0 bump and for the destroy/handler-abort fixes in the Rust shim.

3. `destroy then re-initialize releases the state file lock cleanly` — opt-in.
   The direct unit-test mirror of the self-heal path: bootstrap, destroy, hit
   the SAME data dir with initialize again, verify it succeeds without a
   "state file already locked" error and that traffic still flows.

Wiring:
- New tools/arti-build/build-arti-host.sh — companion to build-arti.sh.
  Cargo-builds the wrapper crate for the host target (x86_64-linux on most
  dev machines, but the script maps macOS / arm64-linux too) and copies to
  amethyst/src/test/native-libs/<host-tag>/libarti_android.so.
- amethyst/build.gradle.kts testOptions.unitTests.all configures
  -Djava.library.path so System.loadLibrary("arti_android") finds the
  checked-in host .so. Also forwards -Pamethyst.arti.integration so the
  opt-in gate works from a Gradle invocation.
- Checked-in src/test/native-libs/x86_64-linux/libarti_android.so for the
  most common dev/CI host (~6 MB).

Wrapper change to make the JVM path actually run:
- lib.rs: on #[cfg(not(target_os = "android"))], call
  builder.storage().permissions().dangerously_trust_everyone() so Arti's
  fs-mistrust check doesn't reject /tmp data dirs on hosts where parent
  directories have unusual UIDs (typical in containers). Android keeps its
  strict default — the app's private filesDir is already sandboxed by the OS.
  Compiled-out on Android, so the shipped Android .so is functionally
  unchanged.

Verified in this session:
- Smoke test passes without -P (3 tests, 1 ran, 2 skipped).
- Full unit test suite still passes.
- With -P the bootstrap tests get past Arti's permissions check; they hang
  on actual relay I/O in this container because outbound TCP egress is
  restricted to a CDN allow-list, not Tor relays. Tests succeed on hosts
  with unrestricted outbound — see the test kdoc.
2026-05-26 21:34:26 +00:00

84 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Build the Arti JNI shim for the *host* (typically Linux x86_64) and stage it
# under amethyst/src/test/native-libs/<host-tag>/libarti_android.so so the JVM
# unit tests in TorArtiNativeIntegrationTest can `System.loadLibrary` it.
#
# Companion to build-arti.sh, which builds the *Android* targets for shipping
# in the APK. Same wrapper crate, same lib.rs — only the cargo target differs.
#
# Prerequisites:
# - Rust toolchain with the host target installed (default after `rustup install stable`).
# - The Arti source must already be cloned at .arti-source/ — run build-arti.sh
# once first if this is a fresh checkout.
#
# Usage:
# ./build-arti-host.sh
#
# Why this exists:
# Tier-3 JVM integration tests in amethyst/src/test/.../tor/TorArtiNativeIntegrationTest
# call the real Arti library. The checked-in .so under src/test/native-libs/x86_64-linux/
# covers the most common dev/CI host. If you bump ARTI_VERSION or touch
# tools/arti-build/src/lib.rs, regenerate the host .so with this script before
# running the integration tests; otherwise you'll be testing the previous shim.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
WRAPPER_DIR="$SCRIPT_DIR/.arti-source/arti-android-wrapper"
if [ ! -d "$WRAPPER_DIR" ]; then
echo "Arti source / wrapper not found at $WRAPPER_DIR."
echo "Run ./build-arti.sh first (clones .arti-source and sets up the wrapper)."
exit 1
fi
# Sync the latest wrapper sources into the .arti-source clone — build-arti.sh
# normally does this, but if you've only edited lib.rs the host build needs it too.
cp "$SCRIPT_DIR/src/lib.rs" "$WRAPPER_DIR/src/lib.rs"
HOST_TARGET="$(rustc -vV | sed -n 's/^host: //p')"
case "$HOST_TARGET" in
x86_64-unknown-linux-gnu) DEST_TAG="x86_64-linux" ;;
aarch64-unknown-linux-gnu) DEST_TAG="aarch64-linux" ;;
x86_64-apple-darwin) DEST_TAG="x86_64-macos" ;;
aarch64-apple-darwin) DEST_TAG="aarch64-macos" ;;
*)
echo "Unmapped host target $HOST_TARGET — add it to build-arti-host.sh."
exit 1
;;
esac
OUT_DIR="$PROJECT_ROOT/amethyst/src/test/native-libs/$DEST_TAG"
mkdir -p "$OUT_DIR"
echo "Building Arti shim for $HOST_TARGET$OUT_DIR/libarti_android.so"
cargo build --release \
--manifest-path "$WRAPPER_DIR/Cargo.toml" \
--target "$HOST_TARGET"
# macOS Rust toolchains produce .dylib, not .so. Rename so the existing
# System.loadLibrary("arti_android") path keeps working.
case "$HOST_TARGET" in
*-apple-darwin)
src="$WRAPPER_DIR/target/$HOST_TARGET/release/libarti_android.dylib"
;;
*)
src="$WRAPPER_DIR/target/$HOST_TARGET/release/libarti_android.so"
;;
esac
cp "$src" "$OUT_DIR/libarti_android.so"
size=$(du -h "$OUT_DIR/libarti_android.so" | cut -f1)
echo "Built $OUT_DIR/libarti_android.so ($size)"
echo ""
echo "Run the smoke test:"
echo " ./gradlew :amethyst:testPlayDebugUnitTest \\"
echo " --tests com.vitorpamplona.amethyst.ui.tor.TorArtiNativeIntegrationTest"
echo ""
echo "Run the full bootstrap tests (needs Tor network egress):"
echo " ./gradlew :amethyst:testPlayDebugUnitTest \\"
echo " --tests com.vitorpamplona.amethyst.ui.tor.TorArtiNativeIntegrationTest \\"
echo " -Pamethyst.arti.integration=true"