feat(ui): redesign the dashboard as a package checkpoint

Add overview, packages with quick view, package detail tabs, a merged security page, insights, system and restyled bypasses. Old vulnerable and blocked routes redirect to the matching security tab.
This commit is contained in:
2026-11-24 01:13:09 +00:00
parent 45aa4bcace
commit 671bb0625b
50 changed files with 3022 additions and 1937 deletions
+55 -238
View File
@@ -1,252 +1,69 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { mount as mountWith } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import Stats from './Stats.vue'
import axios from 'axios'
import { flushPromises } from '@vue/test-utils'
import Insights from './Insights.vue'
import { REGISTRIES, STATS, TIMESERIES, TREND } from '@/test/fixtures'
import { mountStrict } from '@/test/mountStrict'
import { createTestRouter } from '@/test/router'
import { usePackageStore } from '../stores/packages'
describe('Stats.vue', () => {
let router: Awaited<ReturnType<typeof createTestRouter>>
const mount = (component: typeof Stats) => mountWith(component, { global: { plugins: [router] } })
vi.mock('axios')
beforeEach(async () => {
setActivePinia(createPinia())
router = await createTestRouter('/stats')
let restore: (() => void) | undefined
afterEach(() => {
restore?.()
restore = undefined
vi.restoreAllMocks()
})
async function open(stats = STATS, timeseries: unknown = TIMESERIES) {
vi.mocked(axios.get).mockImplementation(async (url: string) => {
if (url.startsWith('/api/stats/timeseries')) return { data: timeseries } as never
if (url.startsWith('/api/stats/trend')) return { data: TREND } as never
return { data: { stats, registries: REGISTRIES } } as never
})
const router = await createTestRouter('/stats')
const pinia = createPinia()
setActivePinia(pinia)
const mounted = await mountStrict(Insights, { global: { plugins: [pinia, router] } })
restore = mounted.restore
await flushPromises()
return mounted
}
beforeEach(() => setActivePinia(createPinia()))
describe('Insights', () => {
it('lists packages and downloads per registry', async () => {
const { wrapper, problems } = await open()
expect(problems).toEqual([])
const table = wrapper.get('[data-testid="registry-breakdown"] table')
expect(table.text()).toContain('npm280')
expect(table.text()).toContain('go110')
expect(table.text()).toContain('pypi130')
})
it('renders stats component', () => {
const wrapper = mount(Stats)
expect(wrapper.find('h1').text()).toBe('Statistics')
it('reports scan coverage and the four outcomes', async () => {
const { wrapper } = await open()
const coverage = wrapper.get('[data-testid="scan-coverage"]').text()
expect(coverage).toContain('3 of 4')
for (const word of ['Cleared', 'Held', 'Bypassed', 'Awaiting scan']) expect(coverage).toContain(word)
})
it('displays loading state when loading', async () => {
const wrapper = mount(Stats)
const store = usePackageStore()
store.loading = true
await wrapper.vm.$nextTick()
expect(wrapper.text()).toContain('Loading statistics...')
it('shades a day when there were downloads', async () => {
const { wrapper } = await open()
expect(wrapper.get('[data-testid="daily-downloads"]').find('[role="img"]').exists()).toBe(true)
})
it('displays error message when error occurs', async () => {
const store = usePackageStore()
vi.spyOn(store, 'fetchStats').mockResolvedValue()
const wrapper = mount(Stats)
store.loading = false
store.error = 'Failed to fetch statistics'
await wrapper.vm.$nextTick()
expect(wrapper.text()).toContain('Failed to fetch statistics')
it('does not draw an empty heatmap for a month with no downloads', async () => {
const quiet = { ...TIMESERIES, data_points: TIMESERIES.data_points.map((p) => ({ ...p, value: 0 })) }
const { wrapper } = await open(STATS, quiet)
expect(wrapper.get('[data-testid="daily-downloads"]').text()).toContain('No downloads yet')
})
it('displays overall statistics', async () => {
const wrapper = mount(Stats)
const store = usePackageStore()
store.loading = false
store.stats = {
registry: '',
total_packages: 100,
total_size: 1073741824, // 1 GB
max_cache_size: 10737418240,
total_downloads: 500,
scanned_packages: 90,
vulnerable_packages: 5,
blocked_packages: 0,
}
await wrapper.vm.$nextTick()
expect(wrapper.text()).toContain('Overall statistics')
expect(wrapper.text()).toContain('100')
expect(wrapper.text()).toContain('500')
})
it('displays security scanning statistics', async () => {
const wrapper = mount(Stats)
const store = usePackageStore()
store.loading = false
store.stats = {
registry: '',
total_packages: 100,
total_size: 1073741824,
max_cache_size: 10737418240,
total_downloads: 500,
scanned_packages: 90,
vulnerable_packages: 5,
blocked_packages: 0,
}
await wrapper.vm.$nextTick()
expect(wrapper.text()).toContain('Security scanning')
expect(wrapper.text()).toContain('Scanned packages')
expect(wrapper.text()).toContain('Vulnerable packages')
})
it('displays registry breakdown', async () => {
const wrapper = mount(Stats)
const store = usePackageStore()
store.loading = false
store.stats = {
registry: '',
total_packages: 100,
total_size: 1073741824,
max_cache_size: 10737418240,
total_downloads: 500,
scanned_packages: 90,
vulnerable_packages: 5,
blocked_packages: 0,
}
store.registries = {
npm: {
count: 50,
size: 536870912, // 512 MB
downloads: 300,
},
pypi: {
count: 30,
size: 322122547, // ~307 MB
downloads: 150,
},
go: {
count: 20,
size: 214748365, // ~205 MB
downloads: 50,
},
}
await wrapper.vm.$nextTick()
expect(wrapper.text()).toContain('Registry breakdown')
expect(wrapper.text()).toContain('npm')
expect(wrapper.text()).toContain('PyPI')
expect(wrapper.text()).toContain('Go modules')
// The cards layout prefixes each cell with its column label.
const packageCounts = wrapper
.findAll('tbody tr')
.map((row) => row.findAll('td')[0].text().replace(/^Packages/, ''))
expect(packageCounts).toEqual(['50', '30', '20'])
})
it('formats bytes correctly in overall stats', async () => {
const wrapper = mount(Stats)
const store = usePackageStore()
store.loading = false
store.stats = {
registry: '',
total_packages: 100,
total_size: 1073741824, // 1 GB
max_cache_size: 10737418240,
total_downloads: 500,
scanned_packages: 90,
vulnerable_packages: 5,
blocked_packages: 0,
}
await wrapper.vm.$nextTick()
expect(wrapper.text()).toContain('1 GB')
})
it('calls fetchStats on mount', () => {
const store = usePackageStore()
const fetchSpy = vi.spyOn(store, 'fetchStats')
mount(Stats)
expect(fetchSpy).toHaveBeenCalled()
})
it('lists the registries in the order the API reports them', async () => {
const wrapper = mount(Stats)
const store = usePackageStore()
store.loading = false
store.stats = {
registry: '',
total_packages: 3,
total_size: 0,
max_cache_size: 10737418240,
total_downloads: 0,
scanned_packages: 0,
vulnerable_packages: 0,
blocked_packages: 0,
}
store.registries = {
npm: { count: 1, size: 0, downloads: 0 },
pypi: { count: 1, size: 0, downloads: 0 },
go: { count: 1, size: 0, downloads: 0 },
}
await wrapper.vm.$nextTick()
const labels = wrapper.findAll('tbody th').map((cell) => cell.text().replace(/^Registry/, ''))
expect(labels).toEqual(['npm', 'PyPI', 'Go modules'])
})
it('handles empty registries data', async () => {
const wrapper = mount(Stats)
const store = usePackageStore()
store.loading = false
store.stats = {
registry: '',
total_packages: 0,
total_size: 0,
max_cache_size: 10737418240,
total_downloads: 0,
scanned_packages: 0,
vulnerable_packages: 0,
blocked_packages: 0,
}
store.registries = {}
await wrapper.vm.$nextTick()
expect(wrapper.text()).toContain('Registry breakdown')
expect(wrapper.findAll('tbody th')).toHaveLength(0)
expect(wrapper.text()).toContain('No registries reported')
})
describe('idle eviction note', () => {
const baseStats = {
registry: '',
total_packages: 100,
total_size: 1073741824,
max_cache_size: 10737418240,
total_downloads: 500,
scanned_packages: 90,
vulnerable_packages: 5,
blocked_packages: 0,
}
async function render(idleTtl?: number) {
const wrapper = mount(Stats)
const store = usePackageStore()
store.loading = false
store.stats = idleTtl === undefined ? { ...baseStats } : { ...baseStats, idle_ttl: idleTtl }
await wrapper.vm.$nextTick()
return wrapper
}
it.each([
[604800, 'Cached items not requested for 7 days are removed.'],
[86400, 'Cached items not requested for 1 day are removed.'],
[129600, 'Cached items not requested for 36 hours are removed.'],
[5400, 'Cached items not requested for 90 minutes are removed.'],
])('shows the window for idle_ttl=%i', async (seconds, sentence) => {
const wrapper = await render(seconds)
expect(wrapper.text()).toContain(sentence)
})
it('hides the note when idle eviction is off', async () => {
const wrapper = await render(0)
expect(wrapper.text()).not.toContain('not requested')
})
it('hides the note when the API sends no idle_ttl', async () => {
const wrapper = await render()
expect(wrapper.text()).not.toContain('not requested')
})
it('never shows a hit rate or evictions, which the server does not track', async () => {
const { wrapper } = await open()
expect(wrapper.text()).not.toMatch(/hit rate|evict/i)
})
})