mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
Make diagnostics evidence bounded, share-safe, and resilient to concurrent writers and corrupt segments. Improve Doctor repair safeguards, Electron runtime recovery, Settings visibility, accessibility, and issue reporting.
72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const doctorApiMock = vi.hoisted(() => ({
|
|
report: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('../api/doctor', () => ({
|
|
doctorApi: doctorApiMock,
|
|
}))
|
|
|
|
import { SAFE_DOCTOR_STORAGE_KEYS, runDoctorCheck, runLocalDoctorRepair } from './doctorRepair'
|
|
|
|
describe('doctorRepair', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('clears only the safe desktop UI storage keys', () => {
|
|
window.localStorage.clear()
|
|
for (const key of SAFE_DOCTOR_STORAGE_KEYS) {
|
|
window.localStorage.setItem(key, `${key}-value`)
|
|
}
|
|
window.localStorage.setItem('cc-haha-chat-history', 'preserve')
|
|
window.localStorage.setItem('cc-haha-provider-config', 'preserve')
|
|
|
|
const result = runLocalDoctorRepair(window.localStorage)
|
|
|
|
expect(result.removedKeys).toEqual(expect.arrayContaining([...SAFE_DOCTOR_STORAGE_KEYS]))
|
|
expect(result.failedKeys).toEqual([])
|
|
for (const key of SAFE_DOCTOR_STORAGE_KEYS) {
|
|
expect(window.localStorage.getItem(key)).toBeNull()
|
|
}
|
|
expect(window.localStorage.getItem('cc-haha-chat-history')).toBe('preserve')
|
|
expect(window.localStorage.getItem('cc-haha-provider-config')).toBe('preserve')
|
|
})
|
|
|
|
it('keeps local repair non-throwing when storage access is blocked', () => {
|
|
const storage = {
|
|
getItem: () => {
|
|
throw new Error('storage unavailable')
|
|
},
|
|
removeItem: () => {
|
|
throw new Error('storage unavailable')
|
|
},
|
|
}
|
|
|
|
const result = runLocalDoctorRepair(storage)
|
|
|
|
expect(result.removedKeys).toEqual([])
|
|
expect(result.failedKeys).toEqual(expect.arrayContaining([...SAFE_DOCTOR_STORAGE_KEYS]))
|
|
})
|
|
|
|
it('checks the server report for the active cwd without clearing desktop state', async () => {
|
|
window.localStorage.clear()
|
|
window.localStorage.setItem('cc-haha-theme', 'dark')
|
|
doctorApiMock.report.mockResolvedValueOnce({
|
|
report: {
|
|
generatedAt: '2026-07-11T00:00:00.000Z',
|
|
items: [],
|
|
protectedSkips: [],
|
|
summary: { total: 0, protectedCount: 0, missingCount: 0, invalidCount: 0 },
|
|
},
|
|
})
|
|
|
|
const report = await runDoctorCheck({ cwd: '/workspace/project' })
|
|
|
|
expect(doctorApiMock.report).toHaveBeenCalledWith('/workspace/project')
|
|
expect(report.summary.total).toBe(0)
|
|
expect(window.localStorage.getItem('cc-haha-theme')).toBe('dark')
|
|
})
|
|
})
|