From 058d5c3f4ce4e69011e97a39ea1ac71905c2c5be Mon Sep 17 00:00:00 2001 From: Zain Qureshi <43629888+ZainnQureshii@users.noreply.github.com> Date: Mon, 30 Nov 2026 13:07:05 +0100 Subject: [PATCH] fix(nodejs): reject fractional branch versions (#5167) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- nodejs/__test__/table.test.ts | 36 +++++++++++++++++++++++++++++++++++ nodejs/lancedb/table.ts | 2 ++ 2 files changed, 38 insertions(+) diff --git a/nodejs/__test__/table.test.ts b/nodejs/__test__/table.test.ts index 73e8c6ffd..1f9628348 100644 --- a/nodejs/__test__/table.test.ts +++ b/nodejs/__test__/table.test.ts @@ -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 }]); diff --git a/nodejs/lancedb/table.ts b/nodejs/lancedb/table.ts index 46deb2f72..3a28a5a9c 100644 --- a/nodejs/lancedb/table.ts +++ b/nodejs/lancedb/table.ts @@ -2987,6 +2987,7 @@ export class Branches { ), ); } + validateNonNegativeInteger(fromVersion ?? undefined, "fromVersion"); return new LocalTable( await this.#inner.create(name, fromRefOrOptions, fromVersion), ); @@ -3000,6 +3001,7 @@ export class Branches { * latest and stays writable. */ async checkout(name: string, version?: number): Promise { + validateNonNegativeInteger(version ?? undefined, "version"); return new LocalTable(await this.#inner.checkout(name, version)); }