diff --git a/nodejs/__test__/fixtures/oauth_browser.cmd b/nodejs/__test__/fixtures/oauth_browser.cmd new file mode 100644 index 000000000..8e97db307 --- /dev/null +++ b/nodejs/__test__/fixtures/oauth_browser.cmd @@ -0,0 +1,3 @@ +@rem SPDX-License-Identifier: Apache-2.0 +@rem SPDX-FileCopyrightText: Copyright The LanceDB Authors +@exit /b 0 diff --git a/nodejs/__test__/oauth.test.ts b/nodejs/__test__/oauth.test.ts index 0a04bb2aa..627da786f 100644 --- a/nodejs/__test__/oauth.test.ts +++ b/nodejs/__test__/oauth.test.ts @@ -3,6 +3,7 @@ import * as fs from "fs"; import * as http from "http"; +import { execFileSync } from "node:child_process"; import * as os from "os"; import * as path from "path"; import { OAuthConfig, OAuthFlowType, OAuthSession } from "../lancedb/oauth"; @@ -23,9 +24,15 @@ function deviceConfig(issuerUrl: string, cacheDir: string): OAuthConfig { describe("OAuthSession", () => { beforeAll(() => { - // Point the Rust browser helper at a no-op so device-flow logins never - // open a real browser window during tests. - process.env.LANCEDB_OAUTH_BROWSER = "/usr/bin/true"; + // Child processes inherit the real environment, just as Rust reads it. + // Fail before login if the browser override only exists in Jest's sandbox. + const browser = execFileSync( + process.execPath, + ["-p", "process.env.LANCEDB_OAUTH_BROWSER ?? ''"], + { encoding: "utf8" }, + ).trim(); + expect(browser).not.toBe(""); + expect(browser).toBe(process.env.LANCEDB_OAUTH_BROWSER); }); it("reports an absent session and logout is idempotent", async () => { diff --git a/nodejs/jest.config.js b/nodejs/jest.config.js index dc99083a5..c137a4b9e 100644 --- a/nodejs/jest.config.js +++ b/nodejs/jest.config.js @@ -1,3 +1,12 @@ +const path = require("node:path"); + +// Set the real process environment before Jest creates its sandbox and workers. +// Assigning process.env inside a test does not reach Rust's std::env. +process.env.LANCEDB_OAUTH_BROWSER = + process.platform === "win32" + ? path.join(__dirname, "__test__/fixtures/oauth_browser.cmd") + : "/usr/bin/true"; + /** @type {import('ts-jest').JestConfigWithTsJest} */ module.exports = { preset: "ts-jest",