Files
bvandeusen ef3ee5aceb
CI / lint (push) Failing after 2s
CI / backend-lint-and-test (push) Successful in 13s
CI / frontend-build (push) Successful in 18s
CI / intimp (push) Successful in 4m10s
CI / intapi (push) Successful in 8m26s
CI / intcore (push) Successful in 9m54s
feat(maintenance): DB maintenance UI card + fix ruff I001
- Settings → Maintenance gains a "Database maintenance" card: a "Run VACUUM
  ANALYZE now" button (enqueues the maintenance task) plus a per-table bloat
  readout (live/dead/dead%/last vacuum) from /api/admin/maintenance/db-stats.
- dbMaintenance store (loadStats / runVacuum) + test.
- Fix ruff I001: combine the two _sync_engine imports onto one line.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 00:52:36 -04:00

45 lines
1.4 KiB
JavaScript

import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { useDbMaintenanceStore } from '../src/stores/dbMaintenance.js'
function stubFetch(handler) {
globalThis.fetch = vi.fn(async (url, init) => {
const { status, body } = handler(url, init)
return {
ok: status >= 200 && status < 300,
status,
statusText: String(status),
text: async () => (body == null ? '' : JSON.stringify(body)),
}
})
}
describe('dbMaintenance store', () => {
beforeEach(() => setActivePinia(createPinia()))
afterEach(() => vi.restoreAllMocks())
it('loadStats populates the bloat table', async () => {
const s = useDbMaintenanceStore()
stubFetch(() => ({
status: 200,
body: { tables: [{ table: 'image_record', live: 5, dead: 1, dead_pct: 16.7, last_vacuum: null }] },
}))
await s.loadStats()
expect(s.tables).toHaveLength(1)
expect(s.tables[0].table).toBe('image_record')
})
it('runVacuum POSTs the trigger endpoint', async () => {
const s = useDbMaintenanceStore()
const calls = []
stubFetch((url, init) => {
calls.push({ url, init })
return { status: 202, body: { status: 'queued' } }
})
await s.runVacuum()
const c = calls.at(-1)
expect(c.url).toContain('/api/admin/maintenance/vacuum')
expect(c.init.method).toBe('POST')
})
})