-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlancedb-corruption.test.ts
More file actions
90 lines (72 loc) · 2.84 KB
/
lancedb-corruption.test.ts
File metadata and controls
90 lines (72 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { promises as fs } from 'fs';
import os from 'os';
import path from 'path';
import { IndexCorruptedError } from '../src/errors/index.js';
const lancedb = vi.hoisted(() => ({
connect: vi.fn()
}));
vi.mock('@lancedb/lancedb', () => ({
connect: lancedb.connect
}));
describe('LanceDBStorageProvider corruption detection', () => {
let tempDir: string;
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
beforeEach(async () => {
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'lancedb-test-'));
lancedb.connect.mockReset();
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
});
afterEach(async () => {
consoleErrorSpy.mockRestore();
await fs.rm(tempDir, { recursive: true, force: true });
});
it('throws IndexCorruptedError when vector column missing during initialize()', async () => {
const dropTable = vi.fn(async () => {});
const db = {
tableNames: vi.fn(async () => ['code_chunks']),
openTable: vi.fn(async () => ({
schema: vi.fn(async () => ({ fields: [{ name: 'id' }] }))
})),
dropTable
};
lancedb.connect.mockResolvedValue(db);
const { LanceDBStorageProvider } = await import('../src/storage/lancedb.js');
const provider = new LanceDBStorageProvider();
await expect(provider.initialize(tempDir)).rejects.toBeInstanceOf(IndexCorruptedError);
expect(dropTable).toHaveBeenCalledWith('code_chunks');
});
it('throws IndexCorruptedError when schema validation fails during initialize()', async () => {
const dropTable = vi.fn(async () => {});
const db = {
tableNames: vi.fn(async () => ['code_chunks']),
openTable: vi.fn(async () => ({
schema: vi.fn(async () => {
throw new Error('schema error');
})
})),
dropTable
};
lancedb.connect.mockResolvedValue(db);
const { LanceDBStorageProvider } = await import('../src/storage/lancedb.js');
const provider = new LanceDBStorageProvider();
await expect(provider.initialize(tempDir)).rejects.toBeInstanceOf(IndexCorruptedError);
expect(dropTable).toHaveBeenCalledWith('code_chunks');
});
it('throws IndexCorruptedError when vector search fails with "No vector column"', async () => {
const { LanceDBStorageProvider } = await import('../src/storage/lancedb.js');
const provider = new LanceDBStorageProvider() as any;
const query = {
limit: vi.fn(() => query),
where: vi.fn(() => query),
toArray: vi.fn(async () => {
throw new Error('Schema Error: No vector column found to create index');
})
};
provider.initialized = true;
provider.table = {
vectorSearch: vi.fn(() => query)
};
await expect(provider.search([0.1, 0.2], 5)).rejects.toBeInstanceOf(IndexCorruptedError);
});
});