diff --git a/gitnexus/package-lock.json b/gitnexus/package-lock.json index e10f45d6f..d9462f5a6 100644 --- a/gitnexus/package-lock.json +++ b/gitnexus/package-lock.json @@ -1254,9 +1254,9 @@ } }, "node_modules/@ladybugdb/core": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/@ladybugdb/core/-/core-0.18.1.tgz", - "integrity": "sha512-0c1kXDpdv7z/GB0oyFYnLEjLsXFwPHz1YD4wxtrk9hav8zJX5T1PHQMr+XRfdDI1NQjx4iNdbPQGGT7Bx/X2aw==", + "version": "0.18.2", + "resolved": "https://registry.npmjs.org/@ladybugdb/core/-/core-0.18.2.tgz", + "integrity": "sha512-222FjGciEO5Z+/MRQGU+b4IaGAjOgSQzj7fMpOuhMQN4F8nf654kuKRk1iybSiNy6XSw69hIJ0mKwUeBQ8y6Fg==", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -1265,17 +1265,17 @@ "node-addon-api": "^6.0.0" }, "optionalDependencies": { - "@ladybugdb/core-darwin-arm64": "0.18.1", - "@ladybugdb/core-darwin-x64": "0.18.1", - "@ladybugdb/core-linux-arm64": "0.18.1", - "@ladybugdb/core-linux-x64": "0.18.1", - "@ladybugdb/core-win32-x64": "0.18.1" + "@ladybugdb/core-darwin-arm64": "0.18.2", + "@ladybugdb/core-darwin-x64": "0.18.2", + "@ladybugdb/core-linux-arm64": "0.18.2", + "@ladybugdb/core-linux-x64": "0.18.2", + "@ladybugdb/core-win32-x64": "0.18.2" } }, "node_modules/@ladybugdb/core-darwin-arm64": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/@ladybugdb/core-darwin-arm64/-/core-darwin-arm64-0.18.1.tgz", - "integrity": "sha512-M5YZuAONRAv3awkr+cfaibn9Da+3pgDzRiek/JabWQuz48xgzW3Vh9yQH4s8Dq/bfQo6YTsaLIBRcUCCUzCtcg==", + "version": "0.18.2", + "resolved": "https://registry.npmjs.org/@ladybugdb/core-darwin-arm64/-/core-darwin-arm64-0.18.2.tgz", + "integrity": "sha512-gAwxsdijBFTz4aZ9ITG6zdQw3lAki0eY33hNBLCfKXjKJLvW/8wCvgCVBglqfqBF5WyI7icFUt+wfy/Fbdfl5A==", "cpu": [ "arm64" ], @@ -1286,9 +1286,9 @@ ] }, "node_modules/@ladybugdb/core-darwin-x64": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/@ladybugdb/core-darwin-x64/-/core-darwin-x64-0.18.1.tgz", - "integrity": "sha512-kq+pyTskfCx++Mrbk7QssE/f/CpSuU50T8lhRtv4PaOKhC2Jf8/wAUOA17UxI594wAru3ERpqVBFUBWGcPk2ag==", + "version": "0.18.2", + "resolved": "https://registry.npmjs.org/@ladybugdb/core-darwin-x64/-/core-darwin-x64-0.18.2.tgz", + "integrity": "sha512-oUjYLc1fW3ntCrO9te55PoPfvhFo8AKeNa/sU66fiQyEAZB7qZJxeHnnLgl/bLueTF2os3RSawq46ZftoD/9Eg==", "cpu": [ "x64" ], @@ -1299,9 +1299,9 @@ ] }, "node_modules/@ladybugdb/core-linux-arm64": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/@ladybugdb/core-linux-arm64/-/core-linux-arm64-0.18.1.tgz", - "integrity": "sha512-fu7ke1haa5rPINcQn0+kxQijZ0A8ZDWP9e+X8xcDH94RagDbPWwG8yFC890cGSdc/j7mTV+xkA/y/kVHpmVI6w==", + "version": "0.18.2", + "resolved": "https://registry.npmjs.org/@ladybugdb/core-linux-arm64/-/core-linux-arm64-0.18.2.tgz", + "integrity": "sha512-UppokeTaPl9pN0xOsdMa+hmM68zbN2eKReTZhZNYM16qX0d2OlgbS/NlXi09Wdot+w5qvlZ9Q0iCCPfr7qvPaw==", "cpu": [ "arm64" ], @@ -1312,9 +1312,9 @@ ] }, "node_modules/@ladybugdb/core-linux-x64": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/@ladybugdb/core-linux-x64/-/core-linux-x64-0.18.1.tgz", - "integrity": "sha512-qp5HilHzDGuArfOyD+VyA7lVJ7IwQDKd81NZKKTmUwIAOJtdwqniYx6JZICPnlr36zFJBx/lGYoSsEzbC+TVdw==", + "version": "0.18.2", + "resolved": "https://registry.npmjs.org/@ladybugdb/core-linux-x64/-/core-linux-x64-0.18.2.tgz", + "integrity": "sha512-GypOxCnP2ix/FWM8YhQ41aQYlS+ruoNMJp7pmaF5laJHhL/a+P/apywNTE+9N41Walsl+Emgg9xwxwTC93slow==", "cpu": [ "x64" ], @@ -1325,9 +1325,9 @@ ] }, "node_modules/@ladybugdb/core-win32-x64": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/@ladybugdb/core-win32-x64/-/core-win32-x64-0.18.1.tgz", - "integrity": "sha512-vHcXr7Df2X1dbb5ORK+SBmNstd/3tApGFImbAnaWiTuLDFlAdfY8lbiSBSp3OgFjc0BB7F3GYUUdvgDRJjK3zA==", + "version": "0.18.2", + "resolved": "https://registry.npmjs.org/@ladybugdb/core-win32-x64/-/core-win32-x64-0.18.2.tgz", + "integrity": "sha512-hvFwjhTYdwG2sijapx963a27jP9mlLW0ZFv5Yfj19e0B3T/FqD9CaKULPy23mU2XlkISN2LUkY5qdgvCFztl/g==", "cpu": [ "x64" ], diff --git a/gitnexus/test/helpers/fts-availability.ts b/gitnexus/test/helpers/fts-availability.ts index 28d8eb7dd..30ba05b8a 100644 --- a/gitnexus/test/helpers/fts-availability.ts +++ b/gitnexus/test/helpers/fts-availability.ts @@ -1,3 +1,46 @@ +import { existsSync, readdirSync, statSync } from 'node:fs'; +import { join } from 'node:path'; + +/** A valid `libfts.lbug_extension` is ~2.2MB; anything smaller is truncated/corrupt. */ +const MIN_VALID_FTS_EXTENSION_BYTES = 1024 * 1024; + +/** + * Find the installed FTS extension file under a `.lbdb/extension` root, + * discovering the version directory instead of assuming it equals the npm + * `@ladybugdb/core` package version. LadybugDB's native INSTALL/LOAD resolves + * its own extension-ABI version directory, which does not always track the + * npm package version — e.g. #2587: bumping the package from 0.18.1 to 0.18.2 + * still installs into a `0.18.1` directory, because the underlying + * extension-ABI build did not change with that patch release. + * + * Scans every version subdirectory for a `/fts/libfts.lbug_extension` + * file and returns the most recently modified one (the one an install/load + * actually just resolved), or null when nothing is installed. + */ +export const findInstalledFtsExtension = (extensionRoot: string): string | null => { + // Fail closed on any FS error (permission quirks, AV file locks on Windows, + // a directory vanishing mid-scan) — same contract as the callers this + // replaces: "not found" is a valid outcome, a thrown exception is not. + try { + if (!existsSync(extensionRoot)) return null; + let best: { path: string; mtimeMs: number } | null = null; + for (const versionEntry of readdirSync(extensionRoot)) { + const versionDir = join(extensionRoot, versionEntry); + if (!statSync(versionDir).isDirectory()) continue; + for (const platformEntry of readdirSync(versionDir)) { + const candidate = join(versionDir, platformEntry, 'fts', 'libfts.lbug_extension'); + if (!existsSync(candidate)) continue; + const stat = statSync(candidate); + if (stat.size < MIN_VALID_FTS_EXTENSION_BYTES) continue; + if (!best || stat.mtimeMs > best.mtimeMs) best = { path: candidate, mtimeMs: stat.mtimeMs }; + } + } + return best?.path ?? null; + } catch { + return null; + } +}; + export const FTS_UNAVAILABLE_NOTE = 'FTS extension unavailable (load-only policy; LOAD failed on this machine)'; diff --git a/gitnexus/test/integration/extension-binary-real.test.ts b/gitnexus/test/integration/extension-binary-real.test.ts index 27293c1a5..f46958a2b 100644 --- a/gitnexus/test/integration/extension-binary-real.test.ts +++ b/gitnexus/test/integration/extension-binary-real.test.ts @@ -2,21 +2,21 @@ import { copyFileSync, existsSync, mkdtempSync, - readdirSync, readFileSync, rmSync, - statSync, writeFileSync, } from 'node:fs'; import { homedir, tmpdir } from 'node:os'; import { join } from 'node:path'; import { afterAll, describe, expect, it } from 'vitest'; -import lbug from '@ladybugdb/core'; import { diagnoseExtensionLoad, inspectExtensionBinary, } from '../../src/core/lbug/extension-load-error.js'; -import { requireFtsResourceOrSkip } from '../helpers/fts-availability.js'; +import { + findInstalledFtsExtension, + requireFtsResourceOrSkip, +} from '../helpers/fts-availability.js'; /** * #2374: exercise the language-independent structural classifier against REAL @@ -46,20 +46,14 @@ function resolveLbugNative(): string | null { return null; } -/** The actual installed FTS extension binary for the running lbug version. */ +/** + * The actual installed FTS extension binary for the running lbug version. + * `os.homedir()` already honors `$HOME` (POSIX) / `%USERPROFILE%` (Windows) — + * the same resolution LadybugDB's native layer uses — so it stays correct + * under the hermetic-home overrides other tests in this suite set via env vars. + */ function resolveInstalledFtsExtension(): string | null { - const home = process.env.USERPROFILE ?? process.env.HOME ?? homedir(); - const base = join(home, '.lbdb', 'extension', lbug.VERSION); - try { - const platformDir = readdirSync(base).find((entry) => - statSync(join(base, entry)).isDirectory(), - ); - if (!platformDir) return null; - const ext = join(base, platformDir, 'fts', 'libfts.lbug_extension'); - return existsSync(ext) ? ext : null; - } catch { - return null; - } + return findInstalledFtsExtension(join(homedir(), '.lbdb', 'extension')); } const lbugNative = resolveLbugNative(); diff --git a/gitnexus/test/integration/fts-extension-e2e.test.ts b/gitnexus/test/integration/fts-extension-e2e.test.ts index 2c072a2fe..94d56cd1b 100644 --- a/gitnexus/test/integration/fts-extension-e2e.test.ts +++ b/gitnexus/test/integration/fts-extension-e2e.test.ts @@ -25,9 +25,9 @@ import path from 'path'; import fs from 'fs'; import os from 'os'; -import lbug from '@ladybugdb/core'; import { getExtensionInstallChildProcessArgs } from '../../src/core/lbug/extension-loader.js'; import { cleanupTempDirSync } from '../helpers/test-db.js'; +import { findInstalledFtsExtension } from '../helpers/fts-availability.js'; /** `.lbdb/extension///fts/libfts.lbug_extension`, discovered not hardcoded. */ let extensionRelPath: string; @@ -52,16 +52,12 @@ const makeTmpDir = (label: string): string => { * home — the production installer script, not a reimplementation. */ const resolveSeedExtension = (): void => { - const relBase = path.join('.lbdb', 'extension', lbug.VERSION); - const realVersionDir = path.join(os.homedir(), relBase); - const platformDirs = fs.existsSync(realVersionDir) ? fs.readdirSync(realVersionDir) : []; - for (const platform of platformDirs) { - const candidate = path.join(realVersionDir, platform, 'fts', 'libfts.lbug_extension'); - if (fs.existsSync(candidate) && fs.statSync(candidate).size > 1024 * 1024) { - extensionRelPath = path.join(relBase, platform, 'fts', 'libfts.lbug_extension'); - seedExtensionFile = candidate; - return; - } + const realExtensionRoot = path.join(os.homedir(), '.lbdb', 'extension'); + const installed = findInstalledFtsExtension(realExtensionRoot); + if (installed) { + extensionRelPath = path.relative(os.homedir(), installed); + seedExtensionFile = installed; + return; } // No local copy — run the real installer against a hermetic probe home. const probeHome = makeTmpDir('seed-home'); @@ -70,16 +66,13 @@ const resolveSeedExtension = (): void => { timeout: 120_000, env: { ...process.env, HOME: probeHome, USERPROFILE: probeHome }, }); - const probeVersionDir = path.join(probeHome, relBase); - const probePlatforms = fs.existsSync(probeVersionDir) ? fs.readdirSync(probeVersionDir) : []; - for (const platform of probePlatforms) { - const candidate = path.join(probeVersionDir, platform, 'fts', 'libfts.lbug_extension'); - if (install.status === 0 && fs.existsSync(candidate)) { - extensionRelPath = path.join(relBase, platform, 'fts', 'libfts.lbug_extension'); - seedExtensionFile = candidate; - networkAvailable = true; - return; - } + const probeExtensionRoot = path.join(probeHome, '.lbdb', 'extension'); + const probeInstalled = findInstalledFtsExtension(probeExtensionRoot); + if (install.status === 0 && probeInstalled) { + extensionRelPath = path.relative(probeHome, probeInstalled); + seedExtensionFile = probeInstalled; + networkAvailable = true; + return; } };