test: 建立桌面端自动化回归测试体系并完善跨平台 CI

(cherry picked from commit 74267ae2f63f8256c3da84b04f5b330e6e9d4c67)
This commit is contained in:
电摇小子
2026-08-03 10:08:28 +08:00
committed by Wxw-Gu
parent b4f909a597
commit 3e57a8432d
36 changed files with 2598 additions and 110 deletions
+59
View File
@@ -0,0 +1,59 @@
import { describe, expect, it, vi } from 'vitest'
vi.mock('electron', () => ({
app: { getPath: () => 'fixture-settings' },
safeStorage: { isEncryptionAvailable: () => false }
}))
import {
isDatabaseKeyFormatValid,
mapAutoDetectPhase,
normalizeDatabaseKey
} from '../../src/renderer/src/features/settings/database-key/utils'
import {
normalizeImageXorKey,
validateImageKeyRequest
} from '../../src/main/services/image-key-config-service'
describe('database key validation', () => {
it('normalizes a prefixed key without accepting the wrong length', () => {
const key = `0x${'a'.repeat(64)}`
expect(normalizeDatabaseKey(key)).toBe('a'.repeat(64))
expect(isDatabaseKeyFormatValid(key)).toBe(true)
expect(isDatabaseKeyFormatValid('a'.repeat(63))).toBe(false)
expect(isDatabaseKeyFormatValid('z'.repeat(64))).toBe(false)
})
it('maps automatic detection progress into stable phases', () => {
expect(mapAutoDetectPhase('正在查找微信进程')).toBeGreaterThan(0)
expect(mapAutoDetectPhase('已获取数据库密钥')).toBe(5)
})
})
describe('image key validation', () => {
it.each([
[64, '0x40'],
['64', '0x40'],
['0xff', '0xFF'],
['', '0x40']
])('normalizes %s to %s', (input, expected) => {
expect(normalizeImageXorKey(input)).toBe(expected)
})
it('keeps database and image key validation independent', () => {
const result = validateImageKeyRequest({
resourceRoot: ' fixture-root ',
xorKey: '64',
aesKey: '0123456789abcdef'
})
expect(result).toEqual({
success: true,
resourceRoot: 'fixture-root',
xorKey: '0x40',
aesKey: '0123456789abcdef'
})
expect(
validateImageKeyRequest({ resourceRoot: 'fixture-root', xorKey: '999', aesKey: 'short' })
.success
).toBe(false)
})
})