ruvector/npm/packages/ruvector/test
ruvnet 3b00a565eb fix(ruvector): CLI works on fresh DBs via meta sidecar (#417)
Six CLI commands crashed on every fresh database produced by
`ruvector create`:

    $ ruvector create /tmp/x.db -d 384
    $ ruvector insert /tmp/x.db /tmp/v.json
    SyntaxError: Unexpected token 'r', "redb…" is not valid JSON

Root cause: `bin/cli.js` `insert`, `search`, `stats`, `export`, and
`import` all did `JSON.parse(fs.readFileSync(dbPath, 'utf8'))` to
recover the dimension. But `<dbPath>` is a redb (Rust binary) file
managed by `@ruvector/core` — not a JSON document. The first byte
("r") tripped the parser before any other code ran.

Compounding: the same handlers called methods that don't exist on
`VectorDBWrapper` (`db.load`, `db.save`, `db.stats`) and didn't
`await` the async wrapper methods that do exist (`insert`,
`insertBatch`, `search`, `len`).

Fix:

- Persist construction args (dimensions, metric, schema version)
  in `<dbPath>.meta.json` from `create`. `insert`/`search`/`stats`
  read the sidecar and pass them straight to the wrapper
  constructor — no more JSON-parsing of redb bytes.
- Drop calls to the phantom `db.load`/`db.save`/`db.stats` API.
  Persistence is automatic via `storagePath`; counting goes through
  `await db.len()`.
- Make every CLI handler `async` and `await` the wrapper calls.
  Includes `benchmark`, whose previously-dropped promises meant the
  reported insert/search rates were just spinner timing.
- Coerce numeric ids to strings inside `insert` (the native binding
  rejects integer ids).
- Surface a clear, actionable error when a DB exists without a
  sidecar (e.g. created by an older CLI), instead of an opaque
  parse failure.

Verified end-to-end with a new test on Node 22.22.2:

    $ node test/cli-fresh-db.test.mjs
      ok: `ruvector create` exits 0
      ok: redb file exists at dbPath
      ok: sidecar metadata file exists
      ok: sidecar.dimensions = 8
      ok: sidecar.metric = cosine
      ok: `ruvector insert` exits 0
      ok: insert does not crash JSON.parsing the redb binary
      ok: `ruvector search` exits 0
      ok: search prints `Found N results`
      ok: search renders at least one hit row
      ok: `ruvector stats` exits 0
      ok: stats prints Vector Count
      ok: stats fails fast on orphan DB without sidecar
      ok: orphan-DB error message mentions sidecar

    ruvector fresh-DB CLI smoke OK (issue #417)

Out of scope (deliberately): the `export`/`import` handlers also
called the same phantom API. Those need the wrapper to grow an
enumeration method (`db.entries()` or similar) before they can do
honest work — file-only metadata-export is misleading. Tracked in a
follow-up; the existing handlers are left untouched here.

The ONNX-bundle half of #417 ships in a separate PR (#354).

Closes #417

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-07 15:47:09 -04:00
..
benchmark-cli.js fix: ruvector-postgres v0.3.1 — audit bug fixes, 46 SQL functions, Docker publish (#227) 2026-03-03 12:53:10 -05:00
benchmark-gnn.js feat: SONA Neural Architecture, RuvLLM, npm packages v0.1.31, and path traversal fix (#51) 2025-12-03 18:40:25 -05:00
benchmark-hooks.js feat: add comprehensive intelligence layer with ONNX, AST, Graph, and Coverage modules 2025-12-31 06:05:38 +00:00
benchmark-perf.js feat(neural): add security hardening + 17x perf optimizations 2026-01-02 14:41:37 +00:00
cli-commands.js fix: ruvector-postgres v0.3.1 — audit bug fixes, 46 SQL functions, Docker publish (#227) 2026-03-03 12:53:10 -05:00
cli-fresh-db.test.mjs fix(ruvector): CLI works on fresh DBs via meta sidecar (#417) 2026-05-07 15:47:09 -04:00
decompiler-reconstruction.js feat(decompiler): code reconstruction + --runnable mode + validation (Phase 6+8) 2026-04-03 03:40:49 +00:00
integration.js fix(brain): defer sparsifier build on startup for large graphs 2026-03-24 12:29:52 +00:00
mock-implementation.js feat: Add multi-platform GitHub Actions workflow for native module builds 2025-11-21 13:19:13 +00:00
optimizer.test.js feat(optimizer): RVAgent optimization from decompiled Claude Code (ADR-139) 2026-04-03 21:15:29 +00:00
standalone-test.js fix(brain): defer sparsifier build on startup for large graphs 2026-03-24 12:29:52 +00:00