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-packs): isolate malformed manifest shapes (#2099, from #2065)

xerj-org1848a00b1f93
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 485af4beb..a9b08ac18 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -51,6 +51,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Debian Rust coverage reports now include valid zero-overlap measurements instead
of exiting before printing counts. Empty source indexes remain an error.
+- Hub pack planning reports malformed manifest JSON shapes as per-corpus warnings
+ and continues planning healthy corpora, rather than crashing on an invalid entry.
+
- `xerj search` and a plain-string `xerj_search` rank a file that contains
the query as an exact phrase (a pasted error message or log line) at the
top. The bag-of-words leg alone let a short `defs` list sharing two of the
diff --git a/tools/hub-packs/hub_packs.py b/tools/hub-packs/hub_packs.py
index d5ef24133..113ae55d5 100644
--- a/tools/hub-packs/hub_packs.py
+++ b/tools/hub-packs/hub_packs.py
@@ -113,15 +113,22 @@ def load_manifest(path: pathlib.Path, refresh: str = "pinned") -> Corpus:
data = json.loads(path.read_text())
except (OSError, json.JSONDecodeError) as e:
raise RegistryError(f"{path.name}: unreadable ({e})") from e
+ if not isinstance(data, dict):
+ raise RegistryError(f"{path.name}: manifest must be an object")
slug = data.get("corpus")
if slug != path.stem or not isinstance(slug, str) or not SLUG_RE.match(slug):
raise RegistryError(f"{path.name}: corpus {slug!r} must equal the file name")
repos = []
- for i, r in enumerate(data.get("repos") or []):
+ raw_repos = data.get("repos", [])
+ if not isinstance(raw_repos, list):
+ raise RegistryError(f"{path.name}: repos must be an array")
+ for i, r in enumerate(raw_repos):
+ if not isinstance(r, dict):
+ raise RegistryError(f"{path.name}: repos[{i}] must be an object")
sha = r.get("sha", "")
- if not SHA_RE.match(sha):
+ if not isinstance(sha, str) or not SHA_RE.fullmatch(sha):
raise RegistryError(f"{path.name}: repos[{i}].sha is not a 40-hex commit")
- if not r.get("url") or not r.get("repo"):
+ if any(not isinstance(r.get(key), str) or not r[key] for key in ("url", "repo")):
raise RegistryError(f"{path.name}: repos[{i}] lacks repo/url")
repos.append(Repo(r["repo"], r["url"], sha))
if not repos:
diff --git a/tools/hub-packs/test_hub_packs.py b/tools/hub-packs/test_hub_packs.py
index 3eaaf17cf..ee93ea108 100644
--- a/tools/hub-packs/test_hub_packs.py
+++ b/tools/hub-packs/test_hub_packs.py
@@ -131,6 +131,33 @@ class RegistryTests(unittest.TestCase):
self.assertEqual(len(warnings), 2)
+ def test_invalid_manifest_shapes_warn_without_losing_healthy_corpora(self):
+ good = json.loads(manifest_text("broken", [("r", "https://x.test/r", SHA_A)]))
+ cases = [[], None, "manifest", {"corpus": "broken", "repos": "repos"},
+ {"corpus": "broken", "repos": [None]},
+ {"corpus": "broken", "repos": [{"sha": None}]},
+ {"corpus": "broken", "repos": [{"sha": 123}]},
+ {"corpus": "broken", "repos": [{"sha": SHA_A, "repo": ["r"], "url": "https://x.test/r"}]},
+ {"corpus": "broken", "repos": [{"sha": SHA_A, "repo": "r", "url": {"url": "https://x.test/r"}}]}]
+ for invalid in cases:
+ with self.subTest(manifest=invalid), tempfile.TemporaryDirectory() as t:
+ reg, backlog = write_registry(pathlib.Path(t), [row("good"), row("broken")], {
+ "good": manifest_text("good", [("g", "https://x.test/g", SHA_A)]),
+ "broken": json.dumps(invalid),
+ })
+ before = (reg / "broken.json").read_bytes()
+ corpora, warnings = hp.load_live(reg, backlog)
+ self.assertEqual([c.slug for c in corpora], ["good"])
+ self.assertEqual(len(warnings), 1)
+ self.assertIn("broken.json", warnings[0])
+ self.assertEqual((reg / "broken.json").read_bytes(), before)
+ # A corrected manifest recovers on the next run without other changes.
+ (reg / "broken.json").write_text(json.dumps(good))
+ recovered, warnings = hp.load_live(reg, backlog)
+ self.assertEqual([c.slug for c in recovered], ["broken", "good"])
+ self.assertEqual(warnings, [])
+
+
class PlanTests(unittest.TestCase):
def corpora(self, t: str, slugs: list[tuple[str, str, str]]):
rows = [row(s, refresh=r) for s, _, r in slugs]