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
fix(hub): verify the cached catalogue signature before serving it (#2905)
Raghuvar Karthik Durga29bbdc615138
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7f8891f09..2b041e10c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -180,6 +180,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0rollover. Size-based conditions and alias-rollover body fields are refusedrather than silently ignored.+- A hub catalogue already on disk is verified against its sibling signature+ before it is served, including a fresh cache and a `304 Not Modified`+ (#2904). Replacing `catalogue.json` used to be enough: `load_catalogue`+ parsed it with no signature check, and a future mtime kept that file+ fresh. A `304` then re-touched the replacement. The cache is dropped and+ refetched when the sibling signature does not verify.+- `xerj mcp` no longer answers a JSON-RPC notification, and runs every`tools/call` off the stdio read loop (#2898). A `tools/call` with no `id`, orwith `id: null`, used to be awaited on the read loop, so a stalled search helddiff --git a/engine/crates/xerj-hub/src/catalogue.rs b/engine/crates/xerj-hub/src/catalogue.rsindex b62d5f8b0..592e2a3ef 100644--- a/engine/crates/xerj-hub/src/catalogue.rs+++ b/engine/crates/xerj-hub/src/catalogue.rs@@ -447,12 +447,29 @@ pub fn refresh_catalogue(hub_url: &str, cache_dir: &Path) -> Result<Catalogue> {}/// Read and validate the cached catalogue, or `None` if it is missing,-/// unreadable, unparsable or a format version this client does not speak.+/// unsigned, signature-invalid, unparsable, or a format version this client+/// does not speak. The sibling `.sig` is checked on every read: a file that+/// was verified when it was written is not still verified after it is replaced.fn read_cached(cache_file: &Path) -> Option<Catalogue> {- let raw = fs::read(cache_file).ok()?;+ let raw = verified_cache_bytes(cache_file).ok()?;parse_catalogue(&raw).ok()}+/// Catalogue bytes whose sibling detached signature verifies against the+/// configured hub key. Missing key, missing signature, or a bad signature is+/// an error, not a catalogue.+fn verified_cache_bytes(cache_file: &Path) -> Result<Vec<u8>> {+ let raw = fs::read(cache_file).with_context(|| format!("read {}", cache_file.display()))?;+ let Some(pubkey) = hub_pubkey() else {+ bail!("no hub public key is configured, so the cached catalogue cannot be verified");+ };+ let sig_path = sig_sibling(cache_file);+ let sig =+ fs::read_to_string(&sig_path).with_context(|| format!("read {}", sig_path.display()))?;+ verify_bytes(&raw, sig.trim(), &pubkey).context("cached catalogue signature did not verify")?;+ Ok(raw)+}+/// Parse catalogue bytes and refuse a format version this client does not read.fn parse_catalogue(bytes: &[u8]) -> Result<Catalogue> {let cat: Catalogue = serde_json::from_slice(bytes).context("parse catalogue JSON")?;@@ -494,11 +511,22 @@ fn warn_if_old(cat: &Catalogue) {}}-/// Fetch, verify and cache the catalogue. The signature guards the replacement:-/// the fetched bytes are only written to the cache after they verify against-/// [`hub_pubkey`]. With no key (`XERJ_HUB_PUBKEY=none`, or a build without one)-/// nothing is fetched at all: there is no unverified path into the cache.+/// Fetch, verify and cache the catalogue. The signature guards the replacement+/// and every later read: fetched bytes are written only after they verify+/// against [`hub_pubkey`], and a 304 re-checks the sibling signature before+/// the on-disk file is treated as that response. With no key+/// (`XERJ_HUB_PUBKEY=none`, or a build without one) nothing is fetched at all:+/// there is no unverified path into the cache.fn fetch_and_store(hub_url: &str, cache_file: &Path, etag_file: &Path) -> Result<Catalogue> {+ fetch_and_store_inner(hub_url, cache_file, etag_file, true)+}++fn fetch_and_store_inner(+ hub_url: &str,+ cache_file: &Path,+ etag_file: &Path,+ conditional: bool,+) -> Result<Catalogue> {let Some(pubkey) = hub_pubkey() else {bail!("no hub public key is configured, so the hub catalogue cannot be verified; \@@ -521,19 +549,34 @@ fn fetch_and_store(hub_url: &str, cache_file: &Path, etag_file: &Path) -> Result.ok().and_then(|s| non_empty(Some(&s)));let mut req = client.get(&cat_url);- if let Some(etag) = &prev_etag {- req = req.header(reqwest::header::IF_NONE_MATCH, etag.as_str());+ if conditional {+ if let Some(etag) = &prev_etag {+ req = req.header(reqwest::header::IF_NONE_MATCH, etag.as_str());+ }}let resp = req.send().with_context(|| format!("GET {cat_url}"))?;if resp.status() == reqwest::StatusCode::NOT_MODIFIED {- // The cached bytes are still current; re-touch them so the next 24 h are- // served from cache without re-asking.- let raw =- fs::read(cache_file).context("hub returned 304 Not Modified but the cache is gone")?;- let cat = parse_catalogue(&raw)?;- write_atomic(cache_file, &raw)?;- return Ok(cat);+ // The hub says its copy is unchanged. That is not a signature over the+ // file on disk: a replaced catalogue.json must not be re-touched and+ // served. Verify the sibling signature first. If it does not verify,+ // drop the cache and the ETag and fetch the current catalogue without+ // If-None-Match, so a 304 cannot pin the client to the replacement.+ match verified_cache_bytes(cache_file) {+ Ok(raw) => {+ let cat = parse_catalogue(&raw)?;+ write_atomic(cache_file, &raw)?;+ return Ok(cat);+ }+ Err(err) => {+ let _ = fs::remove_file(cache_file);+ let _ = fs::remove_file(sig_sibling(cache_file));+ let _ = fs::remove_file(etag_file);+ return fetch_and_store_inner(hub_url, cache_file, etag_file, false).with_context(+ || format!("cached catalogue did not verify ({err:#}); refetched"),+ );+ }+ }}if !resp.status().is_success() {bail!("GET {cat_url} returned HTTP {}", resp.status());@@ -1012,6 +1055,46 @@ mod tests {assert_eq!(cat.corpora[0].slug, "alpha");}+ /// A cache file is not a signature. Replacing catalogue.json and stamping a+ /// future mtime must not make `load_catalogue` serve the replacement: the+ /// sibling `.sig` is what says the hub signed these bytes, and a future+ /// mtime must not skip that check.+ #[test]+ fn a_tampered_cache_is_not_served_even_with_a_future_mtime() {+ let env = HubPubkeyEnv::lock();+ let fx = tempfile::tempdir().unwrap();+ let (bytes, sig, public) = fixture_bytes(fx.path());+ let cache = tempfile::tempdir().unwrap();+ seed_cache(cache.path(), &bytes, &sig);++ let mut tampered: serde_json::Value = serde_json::from_slice(&bytes).unwrap();+ tampered["corpora"][0]["licence_class"] = serde_json::json!("adapt-with-attribution");+ tampered["corpora"][0]["slug"] = serde_json::json!("not-the-signed-slug");+ let tampered_bytes = serde_json::to_vec(&tampered).unwrap();+ assert_ne!(tampered_bytes, bytes);+ fs::write(cache.path().join(CACHE_FILE), &tampered_bytes).unwrap();+ // Far-future mtime: cache_is_fresh treats SystemTimeError as fresh.+ let future = SystemTime::now()+ .checked_add(Duration::from_secs(86400 * 365 * 10))+ .unwrap();+ std::fs::OpenOptions::new()+ .write(true)+ .open(cache.path().join(CACHE_FILE))+ .unwrap()+ .set_modified(future)+ .unwrap();++ env.set(&public);+ let loaded = load_catalogue("http://127.0.0.1:1", cache.path(), true);+ env.remove();+ let err = loaded.expect_err("tampered cache was served");+ let msg = format!("{err:#}");+ assert!(+ msg.contains("signature") || msg.contains("offline"),+ "expected a signature or missing-cache refusal, got {msg}"+ );+ }+/// A one-shot localhost hub that answers exactly two GETs (catalogue, then/// signature) and then exits, so the test can join it. Each response says/// `Connection: close`, forcing a fresh TCP connection per GET.@@ -1104,22 +1187,22 @@ mod tests {let fx = tempfile::tempdir().unwrap();let inputs = two_inputs(fx.path());- // A YOUNG cache holding yesterday's catalogue: `load_catalogue` trusts it.- let (old_seed, _old_public) = keypair();- let (old_cat, old_sig) =- build_catalogue(&inputs, "2026-10-13T00:00:00Z", &old_seed).unwrap();+ // A YOUNG cache holding yesterday's catalogue, signed by the key the+ // client trusts: `load_catalogue` serves it without asking the hub.+ // A cache signed by some other key is not this case; that file does+ // not verify and must not be served.+ let (seed, public) = keypair();+ let (old_cat, old_sig) = build_catalogue(&inputs, "2026-10-13T00:00:00Z", &seed).unwrap();let old_bytes = canonical_json(&old_cat).unwrap();let cache = tempfile::tempdir().unwrap();seed_cache(cache.path(), &old_bytes, &old_sig);- // The hub now serves a newer catalogue, signed by the key the client trusts.- let (new_seed, new_public) = keypair();- let (new_cat, new_sig) =- build_catalogue(&inputs, "2026-10-14T00:00:00Z", &new_seed).unwrap();+ // The hub now serves a newer catalogue, signed by that same key.+ let (new_cat, new_sig) = build_catalogue(&inputs, "2026-10-14T00:00:00Z", &seed).unwrap();let new_bytes = canonical_json(&new_cat).unwrap();let (url, handle) = spawn_hub(new_bytes.clone(), new_sig);- env.set(&new_public);+ env.set(&public);let trusted = load_catalogue(&url, cache.path(), false).expect("young cache is served");assert_eq!(trusted.generated_at, "2026-10-13T00:00:00Z",diff --git a/engine/crates/xerj-hub/tests/ask_flow.rs b/engine/crates/xerj-hub/tests/ask_flow.rsindex 9d0e88b0b..340dcd527 100644--- a/engine/crates/xerj-hub/tests/ask_flow.rs+++ b/engine/crates/xerj-hub/tests/ask_flow.rs@@ -45,7 +45,7 @@ use std::time::{Duration, Instant};use serde_json::json;use sha2::{Digest, Sha256};-use xerj_autoindex::harvest::sign::generate_keypair;+use xerj_autoindex::harvest::sign::{generate_keypair, sign_bytes};use xerj_hub::ask::{ask, AskArgs, AskDeps, AskOutcome, HostedHub, ModeRequest, RealBackend, Request,EXIT_NO_ANSWER, EXIT_OK,@@ -413,7 +413,19 @@ struct Published {sig: PathBuf,}-fn publish(src_archive: &Path, src_sig: &Path, dir: &Path, hub_home: &Path) -> Published {+fn write_signed_catalogue(hub_home: &Path, raw: &[u8], seed: &str) {+ let sig = sign_bytes(raw, seed).unwrap();+ std::fs::write(hub_home.join("catalogue.json"), raw).unwrap();+ std::fs::write(hub_home.join("catalogue.json.sig"), format!("{sig}\n")).unwrap();+}++fn publish(+ src_archive: &Path,+ src_sig: &Path,+ dir: &Path,+ hub_home: &Path,+ seed: &str,+) -> Published {std::fs::create_dir_all(dir).unwrap();let archive = dir.join(format!("mini-c-{PIN8}.hubpack.tar.zst"));let sig = dir.join(format!("mini-c-{PIN8}.hubpack.tar.zst.sig"));@@ -448,11 +460,8 @@ fn publish(src_archive: &Path, src_sig: &Path, dir: &Path, hub_home: &Path) -> Pcorpora: vec![entry],};std::fs::create_dir_all(hub_home).unwrap();- std::fs::write(- hub_home.join("catalogue.json"),- serde_json::to_vec(&cat).unwrap(),- )- .unwrap();+ let raw = serde_json::to_vec(&cat).unwrap();+ write_signed_catalogue(hub_home, &raw, seed);Published { archive, sig }}@@ -591,7 +600,7 @@ async fn ask_end_to_end() {{let hub = work.join("hub-a");let code = work.join("code-a");- let published = publish(&archive, &sig, &work.join("net-a"), &hub);+ let published = publish(&archive, &sig, &work.join("net-a"), &hub, &seed);set_env(&hub, &code, &scratch_home, &public);let url_b = spawn_node(&work.join("data-b"), allowlist.clone()).await;let case = |hosted, args| Case {@@ -688,7 +697,7 @@ async fn ask_end_to_end() {{let hub = work.join("hub-b");let code = work.join("code-b");- publish(&archive, &sig, &work.join("net-b"), &hub);+ publish(&archive, &sig, &work.join("net-b"), &hub, &seed);set_env(&hub, &code, &scratch_home, &public);let url = spawn_node(&work.join("data-b2"), allowlist.clone()).await;let case = |hosted, launcher| Case {@@ -749,7 +758,7 @@ async fn ask_end_to_end() {{let hub = work.join("hub-c");let code = work.join("code-c");- publish(&archive, &sig, &work.join("net-c"), &hub);+ publish(&archive, &sig, &work.join("net-c"), &hub, &seed);set_env(&hub, &code, &scratch_home, &public);// A loopback port with nothing on it: the requested node is "down".let silent =@@ -862,7 +871,7 @@ async fn ask_end_to_end() {{let hub = work.join("hub-d");let code = work.join("code-d");- publish(&archive, &sig, &work.join("net-d"), &hub);+ publish(&archive, &sig, &work.join("net-d"), &hub, &seed);set_env(&hub, &code, &scratch_home, &public);// Two other packs, each a 3 GiB sparse file (no disk is written): over the// 4 GiB budget together. "stale" was used longest ago.@@ -912,7 +921,7 @@ async fn ask_end_to_end() {{let hub = work.join("hub-e");let code = work.join("code-e");- publish(&archive, &sig, &work.join("net-e"), &hub);+ publish(&archive, &sig, &work.join("net-e"), &hub, &seed);set_env(&hub, &code, &scratch_home, &public);let mut args = def_args();args.offline = true;@@ -937,8 +946,8 @@ async fn ask_end_to_end() {{let hub = work.join("hub-g");let code = work.join("code-g");- publish(&archive, &sig, &work.join("net-g"), &hub);- set_catalogue_field(&hub, "licence_class", json!("excluded"));+ publish(&archive, &sig, &work.join("net-g"), &hub, &seed);+ set_catalogue_field(&hub, "licence_class", json!("excluded"), &seed);set_env(&hub, &code, &scratch_home, &public);for flag in ["--offline", "--no-fetch", "(neither)"] {let mut args = def_args();@@ -993,7 +1002,7 @@ async fn ask_end_to_end() {{let hub = work.join("hub-f");let code = work.join("code-f");- publish(&archive, &sig, &work.join("net-f"), &hub);+ publish(&archive, &sig, &work.join("net-f"), &hub, &seed);let real_catalogue = std::fs::read(hub.join("catalogue.json")).unwrap();set_env(&hub, &code, &scratch_home, &public);let url = spawn_node(&work.join("data-f"), allowlist.clone()).await;@@ -1012,6 +1021,7 @@ async fn ask_end_to_end() {"http://{}/never.hubpack.tar.zst",silent.local_addr().unwrap())),+ &seed,);// The victim is a separate process running `xerj hub pull` (this binary).@@ -1062,7 +1072,7 @@ async fn ask_end_to_end() {assert!(!lock_is_held(&lock_path), "the dead process holds nothing");// The retry is NOT blocked — and, pointed at the real pack, it completes.- std::fs::write(hub.join("catalogue.json"), &real_catalogue).unwrap();+ write_signed_catalogue(&hub, &real_catalogue, &seed);let t0 = Instant::now();let rc = tokio::task::spawn_blocking({let url = url.clone();@@ -1094,13 +1104,14 @@ async fn ask_end_to_end() {}}-/// Set one field of the first catalogue entry in `<hub>/catalogue.json`.-fn set_catalogue_field(hub: &Path, field: &str, value: serde_json::Value) {+/// Set one field of the first catalogue entry in `<hub>/catalogue.json` and re-sign it.+fn set_catalogue_field(hub: &Path, field: &str, value: serde_json::Value, seed: &str) {let path = hub.join("catalogue.json");let mut cat: serde_json::Value =serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();cat["corpora"][0][field] = value;- std::fs::write(&path, serde_json::to_vec(&cat).unwrap()).unwrap();+ let raw = serde_json::to_vec(&cat).unwrap();+ write_signed_catalogue(hub, &raw, seed);}/// Is somebody holding the lock file `path`? (Tries it, and lets go again.)diff --git a/engine/crates/xerj-hub/tests/pack_roundtrip.rs b/engine/crates/xerj-hub/tests/pack_roundtrip.rsindex 533a1760a..dae349f0d 100644--- a/engine/crates/xerj-hub/tests/pack_roundtrip.rs+++ b/engine/crates/xerj-hub/tests/pack_roundtrip.rs@@ -27,7 +27,7 @@ use std::time::Duration;use serde_json::json;use sha2::{Digest, Sha256};-use xerj_autoindex::harvest::sign::generate_keypair;+use xerj_autoindex::harvest::sign::{generate_keypair, sign_bytes};use xerj_hub::node::HubNode;use xerj_hub::pack::{self, PackFileEntry};use xerj_hub::{@@ -213,22 +213,29 @@ fn seed_and_snapshot(url: &str, location: &Path) {.unwrap();}-/// Write a catalogue with one mini-c entry pointing at a `file://` pack, taking-/// the pack's real on-disk size as the advertised `pack_bytes`.-fn write_catalogue(hub_home: &Path, archive: &Path, pack_sha256: &str) {+/// Write a signed catalogue with one mini-c entry pointing at a `file://` pack,+/// taking the pack's real on-disk size as the advertised `pack_bytes`.+fn write_catalogue(hub_home: &Path, archive: &Path, pack_sha256: &str, seed: &str) {let real = std::fs::metadata(archive).map(|m| m.len()).unwrap_or(0);- write_catalogue_bytes(hub_home, archive, pack_sha256, real);+ write_catalogue_bytes(hub_home, archive, pack_sha256, real, seed);}/// `write_catalogue` with an explicit advertised `pack_bytes` — lets a test lie/// about the size to exercise the size cap.-fn write_catalogue_bytes(hub_home: &Path, archive: &Path, pack_sha256: &str, pack_bytes: u64) {+fn write_catalogue_bytes(+ hub_home: &Path,+ archive: &Path,+ pack_sha256: &str,+ pack_bytes: u64,+ seed: &str,+) {write_catalogue_full(hub_home,archive,pack_sha256,pack_bytes,LicenceClass::AdaptWithAttribution,+ seed,);}@@ -239,9 +246,10 @@ fn write_catalogue_class(archive: &Path,pack_sha256: &str,licence_class: LicenceClass,+ seed: &str,) {let real = std::fs::metadata(archive).map(|m| m.len()).unwrap_or(0);- write_catalogue_full(hub_home, archive, pack_sha256, real, licence_class);+ write_catalogue_full(hub_home, archive, pack_sha256, real, licence_class, seed);}fn write_catalogue_full(@@ -250,6 +258,7 @@ fn write_catalogue_full(pack_sha256: &str,pack_bytes: u64,licence_class: LicenceClass,+ seed: &str,) {let sig = {let mut s = archive.as_os_str().to_os_string();@@ -285,11 +294,10 @@ fn write_catalogue_full(corpora: vec![entry],};std::fs::create_dir_all(hub_home).unwrap();- std::fs::write(- hub_home.join("catalogue.json"),- serde_json::to_vec(&cat).unwrap(),- )- .unwrap();+ let raw = serde_json::to_vec(&cat).unwrap();+ let cat_sig = sign_bytes(&raw, seed).unwrap();+ std::fs::write(hub_home.join("catalogue.json"), &raw).unwrap();+ std::fs::write(hub_home.join("catalogue.json.sig"), format!("{cat_sig}\n")).unwrap();}#[tokio::test(flavor = "multi_thread", worker_threads = 4)]@@ -368,7 +376,7 @@ async fn pack_build_pull_def_roundtrip() {bytes[mid] ^= 0xff;std::fs::write(&flipped, &bytes).unwrap();// catalogue records the ORIGINAL sha, so the flip is caught.- write_catalogue(&hub_home, &flipped, &good_sha);+ write_catalogue(&hub_home, &flipped, &good_sha, &seed);let url_a2 = url_a.clone();let (ch, hh, pk) = (code_home.clone(), hub_home.clone(), public.clone());@@ -415,7 +423,7 @@ async fn pack_build_pull_def_roundtrip() {.unwrap();}let v2_sha = sha256_hex(&v2);- write_catalogue(&hub_home, &v2, &v2_sha);+ write_catalogue(&hub_home, &v2, &v2_sha, &seed);let url_a2 = url_a.clone();let (ch, hh, pk) = (code_home.clone(), hub_home.clone(), public.clone());@@ -440,7 +448,7 @@ async fn pack_build_pull_def_roundtrip() {let url_b = spawn_node(&work.join("data-b"), allowlist.clone()).await;let code_home = work.join("code-pull");let hub_home = work.join("hub-pull");- write_catalogue(&hub_home, &archive, &good_sha);+ write_catalogue(&hub_home, &archive, &good_sha, &seed);// First pull — downloads, verifies, restores, writes the ledger.let rc = {@@ -597,7 +605,7 @@ async fn pack_build_pull_def_roundtrip() {// would be unreachable by any route (hosted search is plan step 6/7). ──{let hh = work.join("hub-overcap");- write_catalogue_bytes(&hh, &archive, &good_sha, AUTO_PULL_MAX_BYTES + 1);+ write_catalogue_bytes(&hh, &archive, &good_sha, AUTO_PULL_MAX_BYTES + 1, &seed);let rc = run_pull(&work.join("code-overcap"), &hh, Some(&public), &url_b).await;assert_eq!(rc, 0,@@ -614,7 +622,7 @@ async fn pack_build_pull_def_roundtrip() {// client; the transfer is bounded again by `fetch_to` if the field lies). ──{let hh = work.join("hub-cap");- write_catalogue_bytes(&hh, &archive, &good_sha, DISK_BUDGET_BYTES + 1);+ write_catalogue_bytes(&hh, &archive, &good_sha, DISK_BUDGET_BYTES + 1, &seed);let rc = run_pull(&work.join("code-cap"), &hh, Some(&public), &url_b).await;assert_eq!(rc, 1, "over-budget pack → policy/infra exit 1");assert!(@@ -630,7 +638,7 @@ async fn pack_build_pull_def_roundtrip() {// ── No verifying key → its OWN exit code (5), NOT "failed verification" (3) ──{let hh = work.join("hub-nokey");- write_catalogue(&hh, &archive, &good_sha);+ write_catalogue(&hh, &archive, &good_sha, &seed);// A real key is compiled in, so "no key" is the explicit test override.let rc = run_pull(&work.join("code-nokey"),@@ -657,7 +665,7 @@ async fn pack_build_pull_def_roundtrip() {// ── An EXCLUDED corpus is refused by `hub pull` itself (plan §11) ──{let hh = work.join("hub-excluded");- write_catalogue_class(&hh, &archive, &good_sha, LicenceClass::Excluded);+ write_catalogue_class(&hh, &archive, &good_sha, LicenceClass::Excluded, &seed);let rc = run_pull(&work.join("code-excluded"), &hh, Some(&public), &url_b).await;assert_eq!(rc, 1, "an excluded corpus is a policy refusal (exit 1)");assert!(@@ -671,7 +679,7 @@ async fn pack_build_pull_def_roundtrip() {// An approach-only corpus is a different matter: it is pulled (with a warning// wherever it is answered).let hh = work.join("hub-approach");- write_catalogue_class(&hh, &archive, &good_sha, LicenceClass::ApproachOnly);+ write_catalogue_class(&hh, &archive, &good_sha, LicenceClass::ApproachOnly, &seed);let rc = run_pull(&work.join("code-approach"), &hh, Some(&public), &url_b).await;assert_eq!(rc, 0, "approach-only is allowed through");}@@ -682,7 +690,7 @@ async fn pack_build_pull_def_roundtrip() {// a whole node first and only then looked at the slug, the licence, the size// and the key.let hh = work.join("hub-preflight");- write_catalogue_class(&hh, &archive, &good_sha, LicenceClass::Excluded);+ write_catalogue_class(&hh, &archive, &good_sha, LicenceClass::Excluded, &seed);let silent =xerj_common::loopback_test::expect_loopback(std::net::TcpListener::bind("127.0.0.1:0")).local_addr()@@ -726,7 +734,7 @@ async fn pack_build_pull_def_roundtrip() {{let code_home = work.join("code-keep");let hh = work.join("hub-keep");- write_catalogue(&hh, &archive, &good_sha);+ write_catalogue(&hh, &archive, &good_sha, &seed);let rc = run_pull(&code_home, &hh, Some(&public), &url_b).await;assert_eq!(rc, 0, "the first pull succeeds");let extract = hh.join("packs").join("mini-c").join(PIN8);@@ -735,7 +743,7 @@ async fn pack_build_pull_def_roundtrip() {// A re-pull whose archive no longer matches the catalogue's hash.let flipped = out.join("flipped.hubpack.tar.zst");- write_catalogue(&hh, &flipped, &good_sha);+ write_catalogue(&hh, &flipped, &good_sha, &seed);let rc = run_pull(&code_home, &hh, Some(&public), &url_b).await;assert_eq!(rc, 3, "the bad archive is refused");assert!(@@ -749,7 +757,7 @@ async fn pack_build_pull_def_roundtrip() {);// A good re-pull replaces it whole and leaves no staging behind.- write_catalogue(&hh, &archive, &good_sha);+ write_catalogue(&hh, &archive, &good_sha, &seed);let rc = run_pull(&code_home, &hh, Some(&public), &url_b).await;assert_eq!(rc, 0);let leftovers: Vec<String> = std::fs::read_dir(hh.join("packs").join("mini-c"))@@ -763,7 +771,7 @@ async fn pack_build_pull_def_roundtrip() {// ── An unreachable node is an INFRA failure (exit 1), not 2 or 3 ──{let hh = work.join("hub-infra");- write_catalogue(&hh, &archive, &good_sha);+ write_catalogue(&hh, &archive, &good_sha, &seed);let rc = run_pull(&work.join("code-infra"),&hh,@@ -779,7 +787,7 @@ async fn pack_build_pull_def_roundtrip() {// corpus for half an hour; the lock is now the OS's, held by a live process.){let hh = work.join("hub-lock");- write_catalogue(&hh, &archive, &good_sha);+ write_catalogue(&hh, &archive, &good_sha, &seed);let lockdir = hh.join("packs").join("mini-c");std::fs::create_dir_all(&lockdir).unwrap();// Another process (here: another open file description) holds the pin's lock.@@ -812,7 +820,7 @@ async fn pack_build_pull_def_roundtrip() {// ── A lock DIRECTORY left by an older build blocks nothing ──{let hh = work.join("hub-oldlock");- write_catalogue(&hh, &archive, &good_sha);+ write_catalogue(&hh, &archive, &good_sha, &seed);let lockdir = hh.join("packs").join("mini-c");std::fs::create_dir_all(lockdir.join(format!("{PIN8}.lock"))).unwrap();let rc = run_pull(&work.join("code-oldlock"), &hh, Some(&public), &url_b).await;diff --git a/engine/crates/xerj-hub/tests/sync_e2e.rs b/engine/crates/xerj-hub/tests/sync_e2e.rsindex 801dd731d..7340b0915 100644--- a/engine/crates/xerj-hub/tests/sync_e2e.rs+++ b/engine/crates/xerj-hub/tests/sync_e2e.rs@@ -505,11 +505,12 @@ async fn sync_replaces_the_pack_with_a_newer_pin_and_the_old_dir_is_gone() {// The first pull is the ordinary one: nothing cached yet, so sync has no// part in it. Seed the catalogue cache the way a first `ask` would.{- let (bytes, _) = signed_catalogue(+ let (bytes, sig) = signed_catalogue(catalogue_entry(OLD.pin_sha, OLD.pin_date, &old_archive, &old_sha),&seed,);std::fs::write(hub_home.join("catalogue.json"), bytes).unwrap();+ std::fs::write(hub_home.join("catalogue.json.sig"), format!("{sig}\n")).unwrap();}let rc = {let client = client.clone();diff --git a/engine/crates/xerj-mcp/tests/hub_tools.rs b/engine/crates/xerj-mcp/tests/hub_tools.rsindex 997a5f6c5..abfc48a56 100644--- a/engine/crates/xerj-mcp/tests/hub_tools.rs+++ b/engine/crates/xerj-mcp/tests/hub_tools.rs@@ -215,11 +215,12 @@ async fn hub_tools_answer_from_a_local_pack_and_never_download() {),],};- std::fs::write(- hub.join("catalogue.json"),- serde_json::to_vec(&cat).unwrap(),- )- .unwrap();+ let (seed, public) = xerj_autoindex::harvest::sign::generate_keypair().unwrap();+ std::env::set_var("XERJ_HUB_PUBKEY", &public);+ let cat_bytes = serde_json::to_vec(&cat).unwrap();+ let cat_sig = xerj_autoindex::harvest::sign::sign_bytes(&cat_bytes, &seed).unwrap();+ std::fs::write(hub.join("catalogue.json"), &cat_bytes).unwrap();+ std::fs::write(hub.join("catalogue.json.sig"), format!("{cat_sig}\n")).unwrap();// ── tools/list carries the three, with schemas an MCP host accepts ──let list = xerj_mcp::handle_message_for_test(