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.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
ci(hub-packs): per-pack consumer e2e before publishing (spec §12.3)
xerj-orgf95f3386b3f8
diff --git a/.github/workflows/hub-packs.yml b/.github/workflows/hub-packs.ymlindex 4dbf19719..1973b6b25 100644--- a/.github/workflows/hub-packs.yml+++ b/.github/workflows/hub-packs.yml@@ -152,7 +152,9 @@ jobs:run: python3 tools/hub-packs/test_hub_packs.py- name: Shell syntax- run: bash -n tools/hub-packs/ed25519.sh+ run: |+ bash -n tools/hub-packs/ed25519.sh+ bash -n tools/hub-packs/consumer_e2e.sh# ── is there a key to sign with and verify against? ────────────────────────preflight:@@ -427,6 +429,39 @@ jobs:--draft --prerelease --latest=false --target "$GITHUB_SHA" \--title "hub pack: $SLUG @ $PIN8" --notes-file "$RUNNER_TEMP/notes.md"+ # §12.3: the consumer path, with the real binary, BEFORE anything is+ # published. A real run pulls the bytes back out of the DRAFT release (what a+ # client will download, not the builder's local copy); a dry run uses the+ # builder's output. A fresh node, an empty HOME, `hub pull` through a signed+ # catalogue, then `--def` for a symbol from the pack's own defs.jsonl and one+ # question. A failure fails the job and leaves the release a draft.+ - name: Consumer end-to-end (pull, --def, one question)+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ HUB_SIGNING_SEED: ${{ secrets.HUB_SIGNING_SEED }}+ DRY_RUN: ${{ inputs.dry_run }}+ run: |+ set -euo pipefail+ FILE="$SLUG-$PIN8.hubpack.tar.zst"+ SRC="$RUNNER_TEMP/e2e-src"; mkdir -p "$SRC"+ if [ "$DRY_RUN" = "true" ]; then+ TAG="pack-$SLUG-$PIN8"+ cp "$PACK_OUT/$FILE" "$PACK_OUT/$FILE.sig" "$SRC/"+ else+ TAG="$PACK_TAG"+ gh release download "$TAG" --repo "$GITHUB_REPOSITORY" --dir "$SRC" \+ --pattern "$FILE" --pattern "$FILE.sig"+ cmp "$SRC/$FILE" "$PACK_OUT/$FILE"+ cmp "$SRC/$FILE.sig" "$PACK_OUT/$FILE.sig"+ fi+ umask 077+ printf '%s' "$HUB_SIGNING_SEED" > "$RUNNER_TEMP/e2e.key"+ unset HUB_SIGNING_SEED+ trap 'rm -f "$RUNNER_TEMP/e2e.key"' EXIT+ bash tools/hub-packs/consumer_e2e.sh bin/xerj "$SLUG" "$PIN8" "$TAG" "$SRC" "$RUNNER_TEMP/e2e.key" \+ | tee "$RUNNER_TEMP/e2e.txt"+ { echo "### consumer e2e: $SLUG @ $PIN8"; echo; sed 's/^/ /' "$RUNNER_TEMP/e2e.txt"; } >> "$GITHUB_STEP_SUMMARY"+# Draft first, publish last: the step GitHub's own error message prescribes# for immutable-release repositories. A tag whose release was DELETED is burned# with no queryable trace, so the picker cannot foresee the refusal: ondiff --git a/tools/hub-packs/consumer_e2e.sh b/tools/hub-packs/consumer_e2e.shnew file mode 100755index 000000000..c4c54cd72--- /dev/null+++ b/tools/hub-packs/consumer_e2e.sh@@ -0,0 +1,130 @@+#!/usr/bin/env bash+# The per-pack consumer end-to-end gate (CORPUS_HUB_V2 spec §12.3).+#+# consumer_e2e.sh <xerj> <slug> <pin8> <tag> <pack-dir> <seed-file>+#+# <pack-dir> holds <slug>-<pin8>.hubpack.tar.zst and its .sig: the bytes a+# client would download (hub-packs.yml passes the DRAFT release's assets,+# downloaded back from GitHub, or in a dry run the builder's output). The pack+# is served exactly as a client meets it:+#+# 1. a one-entry catalogue is built by `xerj hub build-catalogue` and signed+# with <seed-file> (the hub key), its pack_url pointing at a release-shaped+# copy of <pack-dir> (file://<work>/rel/<tag>/<file>), and served over HTTP+# as <hub>/api/v1/catalogue.json + .sig;+# 2. a FRESH node (empty data dir) and an EMPTY $HOME;+# 3. `xerj hub pull <slug>`: catalogue signature, pack sha256 + signature,+# snapshot restore — all against the key compiled into <xerj>;+# 4. `xerj code <slug> --def <symbol> --json`, the symbol taken from the pack's+# own defs.jsonl, must return that symbol from the local pack;+# 5. `xerj code <slug> "<word from ask_for>" --json` must return a hit with a+# file and a line.+#+# Any failure exits non-zero. Ports: E2E_NODE_PORT (default 19300; the node also+# takes the next two) and E2E_HUB_PORT (default 19310). REGISTRY and BACKLOG as in+# hub-packs.yml. The seed file is read only by step 1.+set -euo pipefail++if [ "$#" -ne 6 ]; then+ sed -n '2,25p' "$0" >&2+ exit 2+fi+BIN=$(realpath "$1"); SLUG=$2; PIN8=$3; TAG=$4; SRC=$(realpath "$5"); SEED=$6+: "${REGISTRY:?REGISTRY must name the registry directory}"+: "${BACKLOG:?BACKLOG must name the backlog file}"+NODE_PORT=${E2E_NODE_PORT:-19300}+HUB_PORT=${E2E_HUB_PORT:-19310}+FILE="$SLUG-$PIN8.hubpack.tar.zst"+REGISTRY=$(realpath "$REGISTRY"); BACKLOG=$(realpath "$BACKLOG")++WORK=$(mktemp -d "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/hub-e2e.XXXXXX")+mkdir -p "$WORK/rel/$TAG" "$WORK/site/api/v1" "$WORK/home" "$WORK/node/data"+PIDS=()+cleanup() {+ for p in "${PIDS[@]}"; do kill "$p" 2>/dev/null || true; done+}+trap cleanup EXIT+fail() {+ echo "::error title=consumer e2e ($SLUG)::$*"+ for log in "$WORK/node/node.log" "$WORK/http.log"; do+ [ -f "$log" ] && { echo "--- tail $log"; tail -n 40 "$log"; }+ done+ exit 1+}++# 1. Catalogue + release layout.+cp "$SRC/$FILE" "$SRC/$FILE.sig" "$WORK/rel/$TAG/"+printf '%s\t%s\t%s\n' "$SLUG" "$PIN8" "$TAG" > "$WORK/tags.tsv"+"$BIN" hub build-catalogue --registry "$REGISTRY" --backlog "$BACKLOG" \+ --packs "$WORK/rel/$TAG" --tags "$WORK/tags.tsv" --release-base "file://$WORK/rel" \+ --out "$WORK/site/api/v1/catalogue.json" --sign-key "$SEED" \+ || fail "build-catalogue failed"+python3 -m http.server "$HUB_PORT" --bind 127.0.0.1 --directory "$WORK/site" \+ > "$WORK/http.log" 2>&1 &+PIDS+=("$!")++# 2. A fresh node and an empty HOME. The node allows snapshot repositories only+# under the hub's pack cache, as the automatic node does (node.rs).+export HOME="$WORK/home"+# XERJ_HUB_PUBKEY is deliberately NOT unset: CI never sets it, so the key compiled+# into <xerj> governs there; a local rehearsal with a throwaway key sets it.+unset XERJ_CODE_HOME XERJ_HUB_HOME XERJ_API_KEY+mkdir -p "$HOME/.xerj/hub/packs"+printf '[limits]\nsnapshot_repo_allowlist = ["%s"]\n' "$(realpath "$HOME/.xerj/hub/packs")" \+ > "$WORK/node/config.toml"+"$BIN" --insecure --bind 127.0.0.1 --port "$NODE_PORT" --data-dir "$WORK/node/data" \+ --config "$WORK/node/config.toml" > "$WORK/node/node.log" 2>&1 &+PIDS+=("$!")+export XERJ_URL="http://127.0.0.1:$NODE_PORT"+export XERJ_HUB_URL="http://127.0.0.1:$HUB_PORT"+up=""+for _ in $(seq 1 120); do+ if curl -fs -m1 "$XERJ_URL/_cluster/health" >/dev/null 2>&1 \+ && curl -fs -m1 "$XERJ_HUB_URL/api/v1/catalogue.json" >/dev/null 2>&1; then+ up=1; break+ fi+ sleep 0.5+done+[ -n "$up" ] || fail "the consumer node or the catalogue server did not come up"++# 3. Pull.+"$BIN" hub pull "$SLUG" || fail "xerj hub pull $SLUG failed (exit $?)"++# 4. --def for a symbol from the pack's own defs.jsonl: the first identifier of+# four or more characters (a stable, deterministic choice).+zstd -dc "$WORK/rel/$TAG/$FILE" | tar -xOf - defs.jsonl > "$WORK/defs.jsonl"+DEF=$(jq -cn 'first(inputs | select(.symbol | test("^[A-Za-z_][A-Za-z0-9_]{3,}$"))) // empty' \+ "$WORK/defs.jsonl")+[ -n "$DEF" ] || fail "defs.jsonl has no identifier to look up"+SYM=$(jq -r .symbol <<<"$DEF")+"$BIN" code "$SLUG" --def "$SYM" --json > "$WORK/def.json" \+ || fail "xerj code $SLUG --def $SYM failed"+# An answer's hits carry file and line, not the symbol: the definition the pack+# recorded must be among them, answered from the local pack.+jq -e --argjson d "$DEF" '+ .answered_from == "local_pack"+ and ([.hits[]? | select(.file == $d.file and .line == $d.line)] | length) > 0' \+ "$WORK/def.json" >/dev/null \+ || { cat "$WORK/def.json"; fail "--def $SYM did not return $(jq -r '"\(.file):\(.line)"' <<<"$DEF") from the local pack"; }+echo "def ok: $SYM -> $(jq -r '"\(.file):\(.line)"' <<<"$DEF") (answered_from local_pack)"++# 5. One question: a word from the catalogue entry's ask_for. Words the template+# sentence ("an agent working on ... queries this for ...") always carries say+# nothing about the corpus; the longest remaining words are tried, at most three.+ASK=$(jq -r --arg s "$SLUG" '.corpora[] | select(.slug == $s) | .ask_for' \+ "$WORK/site/api/v1/catalogue.json")+WORDS=$(tr -cs 'A-Za-z' '\n' <<<"$ASK" | tr 'A-Z' 'a-z' | awk 'length >= 4' \+ | grep -vxE 'agent|agents|working|needing|queries|query|this|that|with|from|when|into|their|about|does' \+ | awk '{ print length, $0 }' | sort -rn -k1,1 -s | cut -d' ' -f2 | awk '!seen[$0]++' | head -n 3 || true)+[ -n "$WORDS" ] || WORDS=$SLUG+hit=""+for w in $WORDS; do+ if "$BIN" code "$SLUG" "$w" --json > "$WORK/q.json" 2> "$WORK/q.err" \+ && jq -e '[.. | objects | select((.file? // .path? // "") != "" and (.line? // .start_line? // null) != null)] | length > 0' \+ "$WORK/q.json" >/dev/null 2>&1; then+ hit=$w; break+ fi+done+[ -n "$hit" ] || { cat "$WORK/q.json" "$WORK/q.err" 2>/dev/null | head -c 4000; fail "no question from ask_for ($WORDS) returned a file:line hit"; }+echo "question ok: \"$hit\" -> $(jq -r '[.. | objects | select((.file? // .path? // "") != "" and (.line? // .start_line? // null) != null)][0] | "\(.file // .path):\(.line // .start_line)"' "$WORK/q.json")"+echo "consumer e2e passed for $SLUG @ $PIN8"