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.

test(feedback): clean-HOME dry-run of a field report (#1774)

xerj-org734a2c8f5855
diff --git a/.github/scripts/e2e_fresh_agent_fieldreport.sh b/.github/scripts/e2e_fresh_agent_fieldreport.sh
new file mode 100755
index 000000000..14602d13b
--- /dev/null
+++ b/.github/scripts/e2e_fresh_agent_fieldreport.sh
@@ -0,0 +1,170 @@
+#!/usr/bin/env bash
+# Clean-HOME field report. Installs the local debug binary into an empty
+# HOME, indexes a tiny git repo that was created here (nothing is cloned),
+# and runs `xerj feedback --dry-run`. The dry run must exit 0, keep --agent,
+# and include the verdict. It must not post anywhere and it must not see a
+# GitHub token.
+#
+# The binary is `cargo build -p xerj-server --no-default-features`: the
+# lexical embedder, which is what a default node uses. Set XERJ_BIN to skip
+# the build. Override the port with XERJ_E2E_PORT (it also binds port+1 and
+# port+2).
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
+PORT="${XERJ_E2E_PORT:-19273}"
+SINK_PORT="${XERJ_E2E_SINK_PORT:-19279}"
+
+if [ -n "${XERJ_BIN:-}" ]; then
+ BIN="$XERJ_BIN"
+else
+ echo "building xerj (debug, --no-default-features, toolchain 1.97.1)"
+ (cd "$ROOT/engine" && cargo +1.97.1 build --locked -p xerj-server --no-default-features)
+ BIN="$ROOT/engine/target/debug/xerj"
+fi
+[ -x "$BIN" ] || { echo "error: no executable at $BIN"; exit 1; }
+
+WORK="$(mktemp -d)"
+SPID=""
+LPID=""
+cleanup() {
+ if [ -n "$SPID" ]; then kill "$SPID" 2>/dev/null || true; wait "$SPID" 2>/dev/null || true; fi
+ if [ -n "${SINK_STOP:-}" ]; then touch "$SINK_STOP" 2>/dev/null || true; fi
+ if [ -n "$LPID" ]; then wait "$LPID" 2>/dev/null || true; fi
+ rm -rf "$WORK"
+}
+trap cleanup EXIT
+
+export HOME="$WORK/home"
+mkdir -p "$HOME/.local/bin"
+install -m 0755 "$BIN" "$HOME/.local/bin/xerj"
+INST="$HOME/.local/bin/xerj"
+
+# CI injects GITHUB_TOKEN. The fresh agent this script stands in for has
+# neither a token nor a gh login. Drop them before any xerj command.
+unset GH_TOKEN GITHUB_TOKEN GH_ENTERPRISE_TOKEN || true
+if [ -n "${GH_TOKEN:-}${GITHUB_TOKEN:-}${GH_ENTERPRISE_TOKEN:-}" ]; then
+ echo "error: a GitHub token is still set"
+ exit 1
+fi
+
+# A sink that records any TCP connection. --dry-run must not open one,
+# including if a build starts honouring XERJ_FIELD_REPORT_URL.
+SINK_COUNT="$WORK/sink-count"
+SINK_STOP="$WORK/sink-stop"
+SINK_READY="$WORK/sink-ready"
+printf '0\n' > "$SINK_COUNT"
+python3 - "$SINK_COUNT" "$SINK_PORT" "$SINK_STOP" "$SINK_READY" <<'PY' &
+import os, socket, sys
+count_path, port, stop, ready = sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4]
+s = socket.socket()
+s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+s.bind(("127.0.0.1", port))
+s.listen(8)
+s.settimeout(0.2)
+with open(ready, "w", encoding="utf-8") as fh:
+ fh.write("ready\n")
+n = 0
+while not os.path.exists(stop):
+ try:
+ conn, _ = s.accept()
+ except socket.timeout:
+ continue
+ try:
+ conn.recv(65536)
+ except OSError:
+ pass
+ conn.close()
+ n += 1
+ with open(count_path, "w", encoding="utf-8") as fh:
+ fh.write(f"{n}\n")
+PY
+LPID=$!
+export XERJ_FIELD_REPORT_URL="http://127.0.0.1:${SINK_PORT}/api/field-report"
+for _ in $(seq 1 50); do
+ if [ -f "$SINK_READY" ]; then break; fi
+ if ! kill -0 "$LPID" 2>/dev/null; then break; fi
+ sleep 0.1
+done
+if [ ! -f "$SINK_READY" ]; then
+ echo "error: field-report sink is not listening on $SINK_PORT"
+ exit 1
+fi
+
+DATA="$WORK/data"
+mkdir -p "$DATA"
+"$INST" --insecure --data-dir "$DATA" --port "$PORT" >"$DATA/server.log" 2>&1 &
+SPID=$!
+URL="http://127.0.0.1:${PORT}"
+up=0
+for _ in $(seq 1 120); do
+ if curl -fsS -m 2 "$URL/_cluster/health" >/dev/null 2>&1; then up=1; break; fi
+ if ! kill -0 "$SPID" 2>/dev/null; then
+ echo "error: server exited during boot"
+ cat "$DATA/server.log"
+ exit 1
+ fi
+ sleep 0.5
+done
+if [ "$up" != 1 ]; then
+ echo "error: server never became healthy"
+ cat "$DATA/server.log"
+ exit 1
+fi
+
+REPO="$WORK/tiny"
+mkdir -p "$REPO"
+git -C "$REPO" init -q
+git -C "$REPO" config user.email "[email protected]"
+git -C "$REPO" config user.name "e2e"
+printf 'fn hello() {}\n' > "$REPO/hello.rs"
+git -C "$REPO" add hello.rs
+git -C "$REPO" commit -q -m "tiny"
+# Nothing in this repo was cloned from GitHub.
+if git -C "$REPO" remote -v | grep -q .; then
+ echo "error: the tiny repo has a remote"
+ exit 1
+fi
+
+set +e
+"$INST" autoindex "$REPO" --url "$URL" --no-graph --prefix e2e >"$DATA/ax.log" 2>&1
+AX=$?
+set -e
+if [ "$AX" != 0 ] && [ "$AX" != 3 ]; then
+ echo "error: autoindex exited $AX"
+ cat "$DATA/ax.log"
+ exit 1
+fi
+
+VERDICT="dry-run-kept-the-verdict"
+AGENT="e2e-agent"
+set +e
+"$INST" feedback --dry-run --url "$URL" \
+ --agent "$AGENT" \
+ --used-for "indexed one local file" \
+ --verdict "$VERDICT" \
+ >"$DATA/feedback.out" 2>"$DATA/feedback.err"
+FB=$?
+set -e
+if [ "$FB" != 0 ]; then
+ echo "error: feedback --dry-run exited $FB"
+ cat "$DATA/feedback.out" "$DATA/feedback.err"
+ exit 1
+fi
+
+grep -F -e "$VERDICT" "$DATA/feedback.out" >/dev/null \
+ || { echo "error: verdict missing from the dry run"; cat "$DATA/feedback.out"; exit 1; }
+# `--` so a pattern that begins with --agent is not parsed as a grep flag.
+grep -F -e "--agent \"$AGENT\"" -- "$DATA/feedback.out" >/dev/null \
+ || { echo "error: --agent was dropped from the ready-to-run command"; cat "$DATA/feedback.out"; exit 1; }
+
+touch "$SINK_STOP"
+wait "$LPID" 2>/dev/null || true
+LPID=""
+HITS="$(tr -d '[:space:]' < "$SINK_COUNT")"
+if [ "$HITS" != 0 ]; then
+ echo "error: dry-run opened $HITS connection(s) to $XERJ_FIELD_REPORT_URL"
+ exit 1
+fi
+
+echo "e2e ok: installed=$INST autoindex=$AX verdict and --agent kept, sink connections=0"
diff --git a/.github/workflows/field-report-e2e.yml b/.github/workflows/field-report-e2e.yml
new file mode 100644
index 000000000..c25cb3796
--- /dev/null
+++ b/.github/workflows/field-report-e2e.yml
@@ -0,0 +1,58 @@
+name: Fresh-agent field report
+
+# A clean HOME, the binary this commit builds, a one-file repo created in
+# the job (not cloned), and `xerj feedback --dry-run`. No GitHub token is
+# visible to the command and nothing is posted.
+#
+# timeout-minutes: 60. The long part is a cold debug build of xerj-server
+# without default features (no candle). A one-file autoindex after that is
+# seconds. 60 sits under the repo's 90-minute pack jobs and above the
+# 30-minute lint-only jobs; a cap that false-fails a cold runner is worse
+# than the hang it guards against.
+
+on:
+ pull_request:
+ paths:
+ - '.github/workflows/field-report-e2e.yml'
+ - '.github/scripts/e2e_fresh_agent_fieldreport.sh'
+ - 'engine/crates/xerj-autoindex/**'
+ - 'engine/crates/xerj-common/**'
+ - 'engine/crates/xerj-server/**'
+ - 'engine/Cargo.lock'
+ - 'engine/Cargo.toml'
+ push:
+ branches: [main]
+ paths:
+ - '.github/workflows/field-report-e2e.yml'
+ - '.github/scripts/e2e_fresh_agent_fieldreport.sh'
+ - 'engine/crates/xerj-autoindex/**'
+ - 'engine/crates/xerj-common/**'
+ - 'engine/crates/xerj-server/**'
+ - 'engine/Cargo.lock'
+ - 'engine/Cargo.toml'
+
+permissions:
+ contents: read
+
+concurrency:
+ group: field-report-e2e-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ e2e:
+ name: Clean HOME field-report dry-run
+ runs-on: ubuntu-latest
+ timeout-minutes: 60
+ steps:
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
+
+ - name: Install Rust
+ uses: dtolnay/rust-toolchain@032958afbdc797a9164d3bc0b56325c1308924a5 # 1.97.1
+
+ - name: Cache
+ uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
+ with:
+ workspaces: engine
+
+ - name: Install, index, dry-run
+ run: bash .github/scripts/e2e_fresh_agent_fieldreport.sh