Add history window controls and expand taxonomy pack support
- 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
This commit is contained in:
146
scripts/sqlite-vector-env.test.ts
Normal file
146
scripts/sqlite-vector-env.test.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
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",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user