fix(nodejs): reject fractional branch versions (#5167)

Refs #4848

## Problem

With the table at version 2, `branches.create("exp", undefined, 1.5)`
silently forked from version 1 and left the new branch missing the
second row. With `exp` at version 3, both `branches.checkout("exp",
2.5)` and `openTable("my_table", undefined, { branch: "exp", version:
2.5 })` returned version 2 and its two rows. N-API coerced these
arguments to `i64` before Rust could validate them
(`nodejs/src/table.rs:2698` and `nodejs/src/table.rs:2743`).

## Change

`Branches.create` and `Branches.checkout` now use the existing
TypeScript integer validator before calling N-API
(`nodejs/lancedb/table.ts:2759` and `nodejs/lancedb/table.ts:2773`).
Creation rejects with `fromVersion must be a non-negative integer` and
creates no branch. Both reads reject with `version must be a
non-negative integer` because opening a named branch delegates to the
same checkout method (`nodejs/lancedb/connection.ts:830`).

Tag-based creation rejects a simultaneous source version through the
native source conflict check (`nodejs/src/table.rs:2701`). With no
branch or with `branch: "main"`, `openTable` uses `Table.checkout`
(`nodejs/lancedb/connection.ts:832`). That separate numeric checkout
path and tag version validation are covered by #4916.

## Tests

Ran from `nodejs` on macOS arm64 using the published beta.26 native
binding built from the base revision. The two regressions failed on the
base. The patched branch run passed 34 tests, and the Node suite passed
1,885 tests with 27 skipped. Live Enterprise and S3 integrations were
outside this run.

```sh
env -u OPENAI_API_KEY -u LANCEDB_API_KEY -u S3_TEST ./node_modules/.bin/jest --runInBand --runTestsByPath __test__/table.test.ts --testNamePattern='branch' --no-verbose
env -u OPENAI_API_KEY -u LANCEDB_API_KEY -u S3_TEST ./node_modules/.bin/jest --runInBand --no-verbose
./node_modules/.bin/tsc -b
./node_modules/.bin/tsc --noEmit -p __test__/tsconfig.json
./node_modules/.bin/biome ci .
```

The package's TypeDoc and postprocessing commands also passed, and the
generated JavaScript API reference matched the checked-in files.

Prepared with AI assistance (Codex and Claude Code) and reviewed with
GitHub Copilot.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zain Qureshi
2026-11-30 20:07:05 +08:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 2d4e0fb3f2
commit 058d5c3f4c
2 changed files with 38 additions and 0 deletions
+36
View File
@@ -4251,6 +4251,42 @@ describe("when dealing with branches", () => {
expect(await positional.countRows("i = 100")).toBe(0);
});
it("rejects a fractional source version when creating a branch", async () => {
const conn = await connect(tmpDir.name);
const table = await conn.createTable("my_table", [{ i: 0 }]);
await table.add([{ i: 1 }]);
const branches = await table.branches();
await expect(branches.create("invalid", undefined, 1.5)).rejects.toThrow(
"fromVersion must be a non-negative integer",
);
expect(await branches.list()).not.toHaveProperty("invalid");
});
it("rejects a fractional branch version on checkout and open", async () => {
const conn = await connect(tmpDir.name);
const table = await conn.createTable("my_table", [{ i: 0 }]);
const branches = await table.branches();
const branch = await branches.create("exp");
await branch.add([{ i: 1 }]);
await branch.add([{ i: 2 }]);
const results = await Promise.allSettled([
branches.checkout("exp", 2.5),
conn.openTable("my_table", undefined, { branch: "exp", version: 2.5 }),
]);
expect(results).toEqual([
{
status: "rejected",
reason: new Error("version must be a non-negative integer"),
},
{
status: "rejected",
reason: new Error("version must be a non-negative integer"),
},
]);
});
it("rejects fromTag combined with another source before main normalization", async () => {
const conn = await connect(tmpDir.name);
const table = await conn.createTable("my_table", [{ i: 0 }]);