fix(admin-ui): stale-data notice, request timeout and dedupe, hash and format edge cases

Show a persistent notice when a refresh fails while old data is on screen.
Add retry to the Targets and Access Matrix error states.
Give tables names, skeletons a status role and CSV export a live region.
Abort admin requests after 15 seconds and share concurrent identical GETs.
Show a reload prompt when a lazy page chunk fails to load.
Ignore prototype keys in the location hash.
Stop formatContextWindow emitting 1000k, round latency before the 1s cutoff,
and treat NaN as not enough data in the month projection.
Regenerate admin_assets_gen.go.
This commit is contained in:
2026-11-08 01:59:34 +00:00
parent 5f5efa5a8d
commit fcfb298077
31 changed files with 421 additions and 180 deletions
+75
View File
@@ -101,3 +101,78 @@ describe('isAuthRejection', () => {
expect(isAuthRejection('nope')).toBe(false)
})
})
describe('adminFetch resilience', () => {
beforeEach(() => {
setActivePinia(createPinia())
useAuthStore().submit('test-admin-key')
vi.stubGlobal('fetch', vi.fn())
})
it('passes an abort signal so a hung request cannot block polling forever', async () => {
vi.mocked(fetch).mockResolvedValue(jsonResponse(200, {}))
await adminFetch('/admin/api/overview')
const init = vi.mocked(fetch).mock.calls[0][1]
expect(init?.signal).toBeInstanceOf(AbortSignal)
})
it('turns a timeout into an AdminApiError naming the path', async () => {
vi.mocked(fetch).mockRejectedValue(new DOMException('timed out', 'TimeoutError'))
await expect(adminFetch('/admin/api/overview')).rejects.toMatchObject({
name: 'AdminApiError',
message: expect.stringContaining('/admin/api/overview'),
})
})
it('turns a 200 with a non-JSON body into an AdminApiError, not a raw SyntaxError', async () => {
vi.mocked(fetch).mockResolvedValue({
ok: true,
status: 200,
json: () => Promise.reject(new SyntaxError('Unexpected token <')),
} as Response)
await expect(adminFetch('/admin/api/overview')).rejects.toBeInstanceOf(AdminApiError)
})
it('rethrows network errors unchanged', async () => {
vi.mocked(fetch).mockRejectedValue(new TypeError('Failed to fetch'))
await expect(adminFetch('/admin/api/overview')).rejects.toThrow('Failed to fetch')
})
})
describe('adminFetch in-flight dedupe', () => {
beforeEach(() => {
setActivePinia(createPinia())
useAuthStore().submit('test-admin-key')
vi.stubGlobal('fetch', vi.fn())
})
it('shares one request between concurrent calls for the same path', async () => {
vi.mocked(fetch).mockResolvedValue(jsonResponse(200, { n: 1 }))
const [a, b] = await Promise.all([adminFetch('/admin/api/x'), adminFetch('/admin/api/x')])
expect(fetch).toHaveBeenCalledTimes(1)
expect(a).toEqual({ n: 1 })
expect(b).toEqual({ n: 1 })
})
it('does not share between different paths', async () => {
vi.mocked(fetch).mockResolvedValue(jsonResponse(200, {}))
await Promise.all([adminFetch('/admin/api/x'), adminFetch('/admin/api/y')])
expect(fetch).toHaveBeenCalledTimes(2)
})
it('issues a fresh request once the first settles, including after failure', async () => {
vi.mocked(fetch).mockRejectedValueOnce(new TypeError('down')).mockResolvedValue(jsonResponse(200, { ok: true }))
await expect(adminFetch('/admin/api/x')).rejects.toThrow('down')
await expect(adminFetch('/admin/api/x')).resolves.toEqual({ ok: true })
expect(fetch).toHaveBeenCalledTimes(2)
})
it('does not share across different admin keys', async () => {
vi.mocked(fetch).mockResolvedValue(jsonResponse(200, {}))
const first = adminFetch('/admin/api/x')
useAuthStore().submit('other-key')
const second = adminFetch('/admin/api/x')
await Promise.all([first, second])
expect(fetch).toHaveBeenCalledTimes(2)
})
})