-
Notifications
You must be signed in to change notification settings - Fork 654
Expand file tree
/
Copy pathsqlite-backend.test.ts
More file actions
88 lines (78 loc) · 2.95 KB
/
sqlite-backend.test.ts
File metadata and controls
88 lines (78 loc) · 2.95 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
/**
* SQLite backend visibility tests
*
* Pins the WASM-fallback banner content + the per-instance backend
* tracking. Closes the visibility gap behind issue #138.
*/
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import {
buildWasmFallbackBanner,
WASM_FALLBACK_FIX_RECIPE,
} from '../src/db/sqlite-adapter';
import { DatabaseConnection } from '../src/db';
import { CodeGraph } from '../src';
describe('buildWasmFallbackBanner — fix-recipe content', () => {
it('includes the macOS / Linux / cross-platform fix commands', () => {
const banner = buildWasmFallbackBanner();
expect(banner).toContain('WASM SQLite fallback active');
expect(banner).toContain('5-10x slower');
expect(banner).toContain('xcode-select --install');
expect(banner).toContain('apt install build-essential');
expect(banner).toContain('pacman -S base-devel');
expect(banner).toContain('npm rebuild better-sqlite3');
expect(banner).toContain('npm install better-sqlite3 --save');
expect(banner).toContain('codegraph status');
});
it('appends the native load error when one is provided', () => {
const banner = buildWasmFallbackBanner(
"Cannot find module 'better-sqlite3'"
);
expect(banner).toContain(
"Native load error: Cannot find module 'better-sqlite3'"
);
});
it('omits the load-error block when no error is supplied', () => {
const banner = buildWasmFallbackBanner();
expect(banner).not.toContain('Native load error:');
});
});
describe('WASM_FALLBACK_FIX_RECIPE — single source of truth', () => {
it('mentions the recovery commands', () => {
expect(WASM_FALLBACK_FIX_RECIPE).toContain('xcode-select --install');
expect(WASM_FALLBACK_FIX_RECIPE).toContain('pacman -S base-devel');
expect(WASM_FALLBACK_FIX_RECIPE).toContain('npm rebuild better-sqlite3');
expect(WASM_FALLBACK_FIX_RECIPE).toContain(
'npm install better-sqlite3 --save'
);
});
});
describe('DatabaseConnection — per-instance backend reporting', () => {
let dir: string;
beforeEach(() => {
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-backend-'));
});
afterEach(() => {
if (fs.existsSync(dir)) {
fs.rmSync(dir, { recursive: true, force: true });
}
});
it('reports a concrete backend (native or wasm) for an initialized DB', () => {
const dbPath = path.join(dir, 'test.db');
const conn = DatabaseConnection.initialize(dbPath);
const backend = conn.getBackend();
expect(['native', 'wasm']).toContain(backend);
conn.close();
});
it('CodeGraph.getBackend() delegates to the underlying DatabaseConnection', async () => {
fs.writeFileSync(path.join(dir, 'x.ts'), `export function x(): void {}\n`);
const cg = await CodeGraph.init(dir, { index: true });
try {
expect(['native', 'wasm']).toContain(cg.getBackend());
} finally {
cg.destroy();
}
});
});