- add 3Y/5Y/10Y financial history filtering and reorganize normalization details UI - add new fiscal taxonomy surface/income bridge/KPI packs and update Rust taxonomy loading - auto-detect Homebrew SQLite for native `sqlite-vec` in local dev/e2e with docs and env guidance
147 lines
4.2 KiB
TypeScript
147 lines
4.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
applyLocalSqliteVectorEnv,
|
|
resolveLocalSqliteVectorConfig,
|
|
} from "./sqlite-vector-env";
|
|
|
|
function createFileExists(paths: string[]) {
|
|
const existingPaths = new Set(paths);
|
|
return (path: string) => existingPaths.has(path);
|
|
}
|
|
|
|
describe("resolveLocalSqliteVectorConfig", () => {
|
|
it("prefers explicit env paths when both are configured", () => {
|
|
const config = resolveLocalSqliteVectorConfig({
|
|
env: {
|
|
SQLITE_CUSTOM_LIB_PATH: "/custom/libsqlite3.dylib",
|
|
SQLITE_VEC_EXTENSION_PATH: "/custom/vec0.dylib",
|
|
},
|
|
fileExists: createFileExists([
|
|
"/custom/libsqlite3.dylib",
|
|
"/custom/vec0.dylib",
|
|
]),
|
|
platform: "darwin",
|
|
resolveVectorExtensionPath: () => "/package/vec0.dylib",
|
|
});
|
|
|
|
expect(config).toEqual({
|
|
mode: "native",
|
|
source: "explicit-env",
|
|
sqliteLibPath: "/custom/libsqlite3.dylib",
|
|
vectorExtensionPath: "/custom/vec0.dylib",
|
|
});
|
|
});
|
|
|
|
it("auto-detects the Apple Silicon Homebrew SQLite path", () => {
|
|
const config = resolveLocalSqliteVectorConfig({
|
|
env: {},
|
|
fileExists: createFileExists([
|
|
"/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib",
|
|
"/package/vec0.dylib",
|
|
]),
|
|
platform: "darwin",
|
|
resolveVectorExtensionPath: () => "/package/vec0.dylib",
|
|
});
|
|
|
|
expect(config).toEqual({
|
|
mode: "native",
|
|
source: "autodetect-homebrew",
|
|
sqliteLibPath: "/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib",
|
|
vectorExtensionPath: "/package/vec0.dylib",
|
|
});
|
|
});
|
|
|
|
it("auto-detects the Intel Homebrew SQLite path", () => {
|
|
const config = resolveLocalSqliteVectorConfig({
|
|
env: {},
|
|
fileExists: createFileExists([
|
|
"/usr/local/opt/sqlite/lib/libsqlite3.dylib",
|
|
"/package/vec0.dylib",
|
|
]),
|
|
platform: "darwin",
|
|
resolveVectorExtensionPath: () => "/package/vec0.dylib",
|
|
});
|
|
|
|
expect(config).toEqual({
|
|
mode: "native",
|
|
source: "autodetect-homebrew",
|
|
sqliteLibPath: "/usr/local/opt/sqlite/lib/libsqlite3.dylib",
|
|
vectorExtensionPath: "/package/vec0.dylib",
|
|
});
|
|
});
|
|
|
|
it("falls back when no SQLite library is available", () => {
|
|
const config = resolveLocalSqliteVectorConfig({
|
|
env: {},
|
|
fileExists: createFileExists(["/package/vec0.dylib"]),
|
|
platform: "darwin",
|
|
resolveVectorExtensionPath: () => "/package/vec0.dylib",
|
|
});
|
|
|
|
expect(config).toEqual({
|
|
mode: "fallback",
|
|
reason: "sqlite-lib-missing",
|
|
});
|
|
});
|
|
|
|
it("falls back when the vector extension path cannot be resolved", () => {
|
|
const config = resolveLocalSqliteVectorConfig({
|
|
env: {},
|
|
fileExists: createFileExists([
|
|
"/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib",
|
|
]),
|
|
platform: "darwin",
|
|
resolveVectorExtensionPath: () => {
|
|
throw new Error("missing extension");
|
|
},
|
|
});
|
|
|
|
expect(config).toEqual({
|
|
mode: "fallback",
|
|
reason: "vector-extension-missing",
|
|
});
|
|
});
|
|
|
|
it("falls back outside macOS", () => {
|
|
const config = resolveLocalSqliteVectorConfig({
|
|
env: {},
|
|
fileExists: createFileExists([
|
|
"/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib",
|
|
"/package/vec0.dylib",
|
|
]),
|
|
platform: "linux",
|
|
resolveVectorExtensionPath: () => "/package/vec0.dylib",
|
|
});
|
|
|
|
expect(config).toEqual({
|
|
mode: "fallback",
|
|
reason: "non-macos",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("applyLocalSqliteVectorEnv", () => {
|
|
it("injects resolved native paths without overwriting explicit values", () => {
|
|
const initialEnv = {
|
|
DATABASE_URL: "file:data/fiscal.sqlite",
|
|
SQLITE_CUSTOM_LIB_PATH: "/custom/libsqlite3.dylib",
|
|
SQLITE_VEC_EXTENSION_PATH: "/custom/vec0.dylib",
|
|
};
|
|
|
|
const result = applyLocalSqliteVectorEnv(initialEnv, {
|
|
fileExists: createFileExists([
|
|
"/custom/libsqlite3.dylib",
|
|
"/custom/vec0.dylib",
|
|
]),
|
|
platform: "darwin",
|
|
resolveVectorExtensionPath: () => "/package/vec0.dylib",
|
|
});
|
|
|
|
expect(result.env).toEqual({
|
|
...initialEnv,
|
|
SQLITE_CUSTOM_LIB_PATH: "/custom/libsqlite3.dylib",
|
|
SQLITE_VEC_EXTENSION_PATH: "/custom/vec0.dylib",
|
|
});
|
|
});
|
|
});
|