#!/usr/bin/env bash # e2e_test.sh — the metta_bench_rust use case, end to end. # # Source: authored in b3u_use_cases (the guide's flow, executable). # # Downloads the SCB-API Rust package from b3u.dev, points it at a # .bfgr your MeTTa frontend produced and at the rust/ keyword # definition from your bundle, and runs the shipped atom_bench. # # ⚠ This leg is the regression detector for a real defect: both # benches USED to hardcode corpus paths into a sibling repo that no # recipient of the package has. If that ever returns, this fails. # # PRECONDITION: the metta use case's layout exists (run # metta/e2e_test.sh first) and cargo is installed. # # Environment: # B3U_BASE, B3U_EMAIL, B3U_PASSWORD required # B3U_DOWNLOADS default ~/Downloads # CCSUSECASES_ROOT default ~/ccsUseCases # CF_ACCESS_CLIENT_ID/-_SECRET optional gateway headers set -u : "${B3U_BASE:?set B3U_BASE}" : "${B3U_EMAIL:?set B3U_EMAIL}" : "${B3U_PASSWORD:?set B3U_PASSWORD}" DOWNLOADS="${B3U_DOWNLOADS:-$HOME/Downloads}" ROOT_DIR="${CCSUSECASES_ROOT:-$HOME/ccsUseCases}" WORK="$ROOT_DIR/scb-api-rust" CURL=(curl -s) if [ -n "${CF_ACCESS_CLIENT_ID:-}" ]; then CURL+=(-H "CF-Access-Client-Id: $CF_ACCESS_CLIENT_ID" -H "CF-Access-Client-Secret: ${CF_ACCESS_CLIENT_SECRET:?}") fi fails=0 pass() { echo " PASS $1"; } fail() { echo " FAIL $1"; fails=$((fails+1)); } mkdir -p "$DOWNLOADS" command -v cargo > /dev/null \ && pass "cargo present" \ || { fail "cargo not installed — the Rust consumer needs a toolchain"; exit 1; } echo "== 1. download the SCB-API Rust package ==" code=$("${CURL[@]}" -o "$DOWNLOADS/scb-api-rust.zip" -w '%{http_code}' \ "$B3U_BASE/packages/rust") [ "$code" = 200 ] && pass "GET /packages/rust" \ || { fail "package download (got $code)"; exit 1; } echo "== 2. unpack ==" rm -rf "$WORK"; mkdir -p "$WORK" ( cd "$WORK" && unzip -oq "$DOWNLOADS/scb-api-rust.zip" ) [ -f "$WORK/examples/atom_bench.rs" ] && [ -f "$WORK/Cargo.toml" ] \ && pass "package carries the crate + atom_bench" \ || { fail "atom_bench.rs or Cargo.toml missing from the package"; exit 1; } echo "== 3. preconditions from the metta use case ==" KWD="$ROOT_DIR/metta/rust/mettaKeyWordDefinition.rs" BFGR="" for c in "$ROOT_DIR/metta/e2e_sample.metta.bfgr" \ "$ROOT_DIR/metta/sample.metta.bfgr"; do [ -f "$c" ] && { BFGR="$c"; break; } done [ -f "$KWD" ] && pass "rust bundle carries mettaKeyWordDefinition.rs" \ || { fail "no $KWD — run metta/e2e_test.sh first"; exit 1; } [ -n "$BFGR" ] && pass "a compiled instance is present ($(basename "$BFGR"))" \ || { fail "no .metta.bfgr — run ccsmetta -lt on a source first"; exit 1; } echo "== 4. RUN the shipped benchmark on it ==" out=$( cd "$WORK" && CCS_BENCH_KWD="$KWD" \ cargo run --release --quiet --example atom_bench -- 20 "$BFGR" 2>&1 ) echo "$out" | grep -q "WK+MAI_rust" \ && pass "atom_bench produced the WK+MAI_rust regime" \ || { fail "atom_bench did not report the expected regimes"; echo "$out" | head -8; } echo "$out" | grep -qE "hyperon_das|No such file" \ && fail "⚠ REGRESSION: the bench reached for a sibling-repo path" \ || pass "no sibling-repo path required (the C10.1 defect stays fixed)" echo if [ "$fails" -eq 0 ]; then echo "CCS_MeTTa_BENCH_RUST E2E: ALL PASS" echo " (run it against your own corpus — sample.metta proves the loop," echo " not the performance; see the guide's section 6)" exit 0 else echo "CCS_MeTTa_BENCH_RUST E2E: $fails FAILURE(S)" exit 1 fi