-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathmodelPathRefresh.test.ts
More file actions
69 lines (62 loc) · 2.15 KB
/
Copy pathmodelPathRefresh.test.ts
File metadata and controls
69 lines (62 loc) · 2.15 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
import type { SQLiteDatabase } from 'expo-sqlite';
jest.mock('../store/chatStore', () => ({
useChatStore: { getState: () => ({}) },
}));
jest.mock('../store/llmStore', () => ({
useLLMStore: { getState: () => ({}) },
}));
jest.mock('../store/modelStore', () => ({
useModelStore: { getState: () => ({}) },
}));
jest.mock('../store/sourceStore', () => ({
useSourceStore: { getState: () => ({}) },
}));
jest.mock('../database/modelRepository', () => ({ addModel: jest.fn() }));
jest.mock('../constants/default-models', () => ({
DEFAULT_MODELS: [
{
modelName: 'Bielik - v3.0',
family: 'Bielik',
modelPath: 'https://hf.example/resolve/v0.9.0/xnnpack/bielik.pte',
tokenizerPath: 'https://hf.example/resolve/v0.9.0/tokenizer.json',
tokenizerConfigPath:
'https://hf.example/resolve/v0.9.0/tokenizer_config.json',
source: 'remote',
modelSize: 0.86,
featured: true,
},
],
}));
import { runMigrations } from '../database/db';
type Call = { sql: string; params: unknown[] };
const makeFakeDb = () => {
const calls: Call[] = [];
const db = {
getAllAsync: async () => [],
execAsync: async () => {},
getFirstAsync: async () => null,
runAsync: async (sql: string, ...params: unknown[]) => {
calls.push({ sql, params: params.flat() });
return {};
},
withTransactionAsync: async (fn: () => Promise<void>) => fn(),
};
return { db: db as unknown as SQLiteDatabase, calls };
};
describe('runMigrations built-in model path refresh', () => {
it('rewrites stale download paths for undownloaded built-in models', async () => {
const { db, calls } = makeFakeDb();
await runMigrations(db);
const refresh = calls.find((c) => c.sql.includes('SET modelPath'));
expect(refresh).toBeDefined();
expect(refresh!.sql).toContain(`source = 'built-in'`);
expect(refresh!.sql).toContain('isDownloaded = 0');
expect(refresh!.params).toEqual([
'https://hf.example/resolve/v0.9.0/xnnpack/bielik.pte',
'https://hf.example/resolve/v0.9.0/tokenizer.json',
'https://hf.example/resolve/v0.9.0/tokenizer_config.json',
0.86,
'Bielik - v3.0',
]);
});
});