|
| 1 | +import type { SQLiteDatabase } from 'expo-sqlite'; |
| 2 | + |
| 3 | +jest.mock('../store/chatStore', () => ({ |
| 4 | + useChatStore: { getState: () => ({}) }, |
| 5 | +})); |
| 6 | +jest.mock('../store/llmStore', () => ({ |
| 7 | + useLLMStore: { getState: () => ({}) }, |
| 8 | +})); |
| 9 | +jest.mock('../store/modelStore', () => ({ |
| 10 | + useModelStore: { getState: () => ({}) }, |
| 11 | +})); |
| 12 | +jest.mock('../store/sourceStore', () => ({ |
| 13 | + useSourceStore: { getState: () => ({}) }, |
| 14 | +})); |
| 15 | +jest.mock('../database/modelRepository', () => ({ addModel: jest.fn() })); |
| 16 | +jest.mock('../constants/default-models', () => ({ |
| 17 | + DEFAULT_MODELS: [ |
| 18 | + { |
| 19 | + modelName: 'Bielik - v3.0', |
| 20 | + family: 'Bielik', |
| 21 | + modelPath: 'https://hf.example/resolve/v0.9.0/xnnpack/bielik.pte', |
| 22 | + tokenizerPath: 'https://hf.example/resolve/v0.9.0/tokenizer.json', |
| 23 | + tokenizerConfigPath: |
| 24 | + 'https://hf.example/resolve/v0.9.0/tokenizer_config.json', |
| 25 | + source: 'remote', |
| 26 | + modelSize: 0.86, |
| 27 | + featured: true, |
| 28 | + }, |
| 29 | + ], |
| 30 | +})); |
| 31 | + |
| 32 | +import { runMigrations } from '../database/db'; |
| 33 | + |
| 34 | +type Call = { sql: string; params: unknown[] }; |
| 35 | + |
| 36 | +const makeFakeDb = () => { |
| 37 | + const calls: Call[] = []; |
| 38 | + const db = { |
| 39 | + getAllAsync: async () => [], |
| 40 | + execAsync: async () => {}, |
| 41 | + getFirstAsync: async () => null, |
| 42 | + runAsync: async (sql: string, ...params: unknown[]) => { |
| 43 | + calls.push({ sql, params: params.flat() }); |
| 44 | + return {}; |
| 45 | + }, |
| 46 | + withTransactionAsync: async (fn: () => Promise<void>) => fn(), |
| 47 | + }; |
| 48 | + return { db: db as unknown as SQLiteDatabase, calls }; |
| 49 | +}; |
| 50 | + |
| 51 | +describe('runMigrations built-in model path refresh', () => { |
| 52 | + it('rewrites stale download paths for undownloaded built-in models', async () => { |
| 53 | + const { db, calls } = makeFakeDb(); |
| 54 | + |
| 55 | + await runMigrations(db); |
| 56 | + |
| 57 | + const refresh = calls.find((c) => c.sql.includes('SET modelPath')); |
| 58 | + expect(refresh).toBeDefined(); |
| 59 | + expect(refresh!.sql).toContain(`source = 'built-in'`); |
| 60 | + expect(refresh!.sql).toContain('isDownloaded = 0'); |
| 61 | + expect(refresh!.params).toEqual([ |
| 62 | + 'https://hf.example/resolve/v0.9.0/xnnpack/bielik.pte', |
| 63 | + 'https://hf.example/resolve/v0.9.0/tokenizer.json', |
| 64 | + 'https://hf.example/resolve/v0.9.0/tokenizer_config.json', |
| 65 | + 0.86, |
| 66 | + 'Bielik - v3.0', |
| 67 | + ]); |
| 68 | + }); |
| 69 | +}); |
0 commit comments