peregrine/web/src/stores/settings/fineTune.test.ts
pyr0ball 6eaa1fef79 feat(settings): Fine-Tune tab — wizard, polling, step lifecycle
Add useFineTuneStore (Pinia setup-function) with step state, polling via
setInterval, loadStatus, startPolling/stopPolling, and submitJob. Add
FineTuneView.vue with a 3-step wizard (upload → extract → train), mode-aware
train step (self-hosted shows make finetune + model check; cloud shows
submit job + quota). Add fine-tune endpoints to dev-api.py: status, extract,
upload, submit, and local-status. All 4 store unit tests pass.
2026-03-22 15:52:53 -07:00

39 lines
1.4 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { useFineTuneStore } from './fineTune'
vi.mock('../../composables/useApi', () => ({ useApiFetch: vi.fn() }))
import { useApiFetch } from '../../composables/useApi'
const mockFetch = vi.mocked(useApiFetch)
describe('useFineTuneStore', () => {
beforeEach(() => { setActivePinia(createPinia()); vi.clearAllMocks(); vi.useFakeTimers() })
afterEach(() => { vi.useRealTimers() })
it('initial step is 1', () => {
expect(useFineTuneStore().step).toBe(1)
})
it('resetStep() returns to step 1', () => {
const store = useFineTuneStore()
store.step = 3
store.resetStep()
expect(store.step).toBe(1)
})
it('loadStatus() sets inFlightJob when status is running', async () => {
mockFetch.mockResolvedValue({ data: { status: 'running', pairs_count: 10 }, error: null })
const store = useFineTuneStore()
await store.loadStatus()
expect(store.inFlightJob).toBe(true)
})
it('startPolling() calls loadStatus on interval', async () => {
mockFetch.mockResolvedValue({ data: { status: 'idle' }, error: null })
const store = useFineTuneStore()
store.startPolling()
await vi.advanceTimersByTimeAsync(4000)
expect(mockFetch).toHaveBeenCalledWith('/api/settings/fine-tune/status')
store.stopPolling()
})
})