Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(hub-e2e): make the sandboxed gate run on a CI runner (#1876)

xerj-org27fa0b9346a0
diff --git a/benchmarks/hub-pov/sandbox.sh b/benchmarks/hub-pov/sandbox.sh
index 1f46f86a4..5d2b85341 100755
--- a/benchmarks/hub-pov/sandbox.sh
+++ b/benchmarks/hub-pov/sandbox.sh
@@ -41,7 +41,8 @@
#
# USAGE:
# benchmarks/hub-pov/sandbox.sh [--home DIR] [--rm-home] [--ro PATH]...
-# [--net isolated|host] -- CMD [ARGS...]
+# [--net isolated|host] [--forward-port PORT]...
+# -- CMD [ARGS...]
# --home DIR use DIR as the arm's fresh HOME (default: a new `mktemp -d`).
# Must NOT be the real user's home; the script refuses that.
# --rm-home delete the HOME on exit (default: keep it so the harness can
@@ -51,6 +52,12 @@
# dirs, the catalogue override). NEVER pass a dir holding gold answers.
# --net MODE `isolated` (default; needs pasta + nft) or `host` (the old shared
# network — only for debugging the jail itself, never for an arm).
+# --forward-port PORT (isolated only; repeatable) forward the jail's loopback
+# PORT to the host's loopback PORT, and nothing else. Only for a
+# server the HARNESS started and owns for this run (e.g. the
+# whole-hub e2e's sentinel-checked stand-in hub); NEVER a node or
+# service port (9200, 9297-9299, ...), which is exactly what the
+# isolation exists to keep out of reach.
# Everything after `--` is the command run inside the jail.
# The resolved HOME is printed to stderr as `sandbox-home: <dir>` for the harness.
#
@@ -75,6 +82,7 @@ RM_HOME=0
NET=isolated
IN_NETNS=0
RO_PATHS=()
+FWD_PORTS=()
ORIG_ARGS=("$@")
# ---- parse args ----------------------------------------------------------
@@ -84,6 +92,12 @@ while [ $# -gt 0 ]; do
--rm-home) RM_HOME=1; shift ;;
--ro) RO_PATHS+=("${2:?--ro needs a path}"); shift 2 ;;
--net) NET="${2:?--net needs isolated|host}"; shift 2 ;;
+ --forward-port)
+ [[ ${2:-} =~ ^[0-9]+$ ]] && [ "$2" -ge 1024 ] && [ "$2" -le 65535 ] \
+ || { echo "sandbox.sh: --forward-port needs a port number in 1024-65535" >&2; exit 2; }
+ case "$2" in 9200|9297|9298|9299)
+ echo "sandbox.sh: refusing to forward node port $2 into the jail" >&2; exit 2 ;; esac
+ FWD_PORTS+=("$2"); shift 2 ;;
--_in-netns) IN_NETNS=1; shift ;; # internal: re-exec'd inside pasta
--) shift; break ;;
*) echo "sandbox.sh: unknown arg '$1' (did you forget '--' before the command?)" >&2; exit 2 ;;
@@ -121,7 +135,10 @@ if [ "$NET" = isolated ] && [ "$IN_NETNS" -eq 0 ]; then
# pasta puts us in a user namespace as uid 0; remember the real ids so the jail
# maps back to them (claude refuses --dangerously-skip-permissions as root).
export SANDBOX_HOST_UID="$(id -u)" SANDBOX_HOST_GID="$(id -g)"
- exec pasta --config-net -q -t none -u none -T none -U none --no-map-gw \
+ # --forward-port: forward ONLY those ns-loopback ports to the host (default none).
+ tcp_ns=none
+ [ ${#FWD_PORTS[@]} -gt 0 ] && tcp_ns=$(IFS=,; echo "${FWD_PORTS[*]}")
+ exec pasta --config-net -q -t none -u none -T "$tcp_ns" -U none --no-map-gw \
-- bash "$(realpath "$0")" --_in-netns --home "$HOME_DIR" "${ORIG_ARGS[@]}"
fi
diff --git a/tools/hub-packs/whole_hub_e2e.sh b/tools/hub-packs/whole_hub_e2e.sh
index 7ff869542..ea7c6c8c5 100644
--- a/tools/hub-packs/whole_hub_e2e.sh
+++ b/tools/hub-packs/whole_hub_e2e.sh
@@ -585,7 +585,16 @@ phase() { # phase-name home-name [env...] -- [args...]
echo "-- phase $name (HOME $home)"
local rc=0
if [ "$SANDBOX" = 1 ]; then
- CLAUDE_CONFIG_DIR="$OUT/sandbox-cfg" bash "$SANDBOX_SH" --home "$home" -- \
+ # The jail masks /home and keeps its own loopback. On a CI runner the repo, the
+ # binary and --out all live under /home/runner, so expose exactly what a phase
+ # reads (this script and its e2e/ files, the binary, the questions, the
+ # stand-in hub's request log, the file:// pack dirs) read-only, and forward
+ # only the stand-in hub's port (ours: the sentinel proved it). DEAD_PORT and
+ # every node port stay unreachable, as they must.
+ local ro=(--ro "$HERE" --ro "$BIN" --ro "$(dirname "$QFILE")" --ro "$OUT/logs")
+ local d; for d in "$OUT/rel" "$OUT/lab/target"; do [ -d "$d" ] && ro+=(--ro "$d"); done
+ CLAUDE_CONFIG_DIR="$OUT/sandbox-cfg" bash "$SANDBOX_SH" --home "$home" "${ro[@]}" \
+ --forward-port "$PORT" -- \
"${base[@]}" bash "$SELF" --inner "$name" "$@" 2> >(grep -v '^sandbox-home:' >&2) || rc=$?
else
env -i HOME="$home" PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin LANG=C.UTF-8 \
@@ -718,9 +727,12 @@ fi
# ── fold ────────────────────────────────────────────────────────────────────
n_fail=$(jq -s '[.[] | select(.result != "pass")] | length' "$CHECKS")
n_all=$(jq -s length "$CHECKS")
-rp_pass=$(cat "$OUT/rows/"*.json 2>/dev/null | jq -s '[.[] | select(.result == "e2e passed")] | length' 2>/dev/null || echo 0)
-rp_pend=$(cat "$OUT/rows/"*.json 2>/dev/null | jq -s '[.[] | select(.result == "pending")] | length' 2>/dev/null || echo 0)
-rp_fail=$(cat "$OUT/rows/"*.json 2>/dev/null | jq -s '[.[] | select(.result != "e2e passed" and .result != "pending")] | length' 2>/dev/null || echo 0)
+# rows_count <jq-select>: rows/ may be empty (no catalogue), and under pipefail a
+# failing `cat` plus an `|| echo 0` fallback used to print "0<newline>0".
+rows_count() { { cat "$OUT/rows/"*.json 2>/dev/null || true; } | jq -s "[.[] | select($1)] | length"; }
+rp_pass=$(rows_count '.result == "e2e passed"')
+rp_pend=$(rows_count '.result == "pending"')
+rp_fail=$(rows_count '.result != "e2e passed" and .result != "pending"')
verdict=$([ "$n_fail" = 0 ] && echo "GREEN" || echo "RED")
{
echo "# Hub v2 whole-hub end-to-end (spec §12.4)"