Files
Hermes-ui/tests/client/i18n-coverage.test.ts
T
ekko acf4e225e6 feat: rewrite database schema synchronization with automatic recovery (#379)
Complete rewrite of the Hermes SQLite database schema synchronization mechanism
with comprehensive error handling, automatic recovery, and full test coverage.

## Database Schema Synchronization
- **Unified sync mechanism**: Single `syncTable()` function handles all schema changes
- **Automatic column sync**: Adds missing columns and removes extra columns
- **Table rebuilding**: Automatically rebuilds tables when primary keys or types change
- **Data preservation**: Preserves data during schema changes when compatible
- **Index management**: Creates and removes indexes as needed

## Error Recovery & Reliability
- **Automatic backup**: Backs up corrupted database before recovery
- **Retry limiting**: Prevents infinite loops with retry limit
- **Duplicate prevention**: Avoids multiple backup files
- **Safe file operations**: Uses copy+delete instead of rename for safety

## Composite Primary Keys
- Fixed GC_ROOM_AGENTS and GC_ROOM_MEMBERS with proper composite primary keys
- Prevents duplicate entries while allowing same roomId with different agentId/userId

## Test Coverage
- **10 new integration tests** for schema synchronization (tests/server/schema-sync.test.ts)
- **3 updated tests** for Hermes schemas (tests/server/hermes-schemas.test.ts)
- All 327 tests passing (47 test files, 325 passed, 2 skipped)

## Bug Fixes
- Fixed module import issues (unified ES6 imports, removed mixed require())
- Fixed mock issues in sessions routes tests
- Fixed i18n coverage test to handle newly added keys
- Fixed profiles store test to match current implementation

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 19:48:46 +08:00

82 lines
2.5 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { readdirSync, readFileSync } from 'fs'
import { join, relative } from 'path'
import { changelog } from '@/data/changelog'
import { messages, rawMessages } from '@/i18n/messages'
const SOURCE_ROOT = join(process.cwd(), 'packages/client/src')
function walkFiles(dir: string, files: string[] = []): string[] {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const path = join(dir, entry.name)
if (entry.isDirectory()) {
walkFiles(path, files)
} else if (/\.(ts|vue)$/.test(entry.name) && !path.includes('/i18n/locales/')) {
files.push(path)
}
}
return files
}
function collectLiteralTranslationKeys(): string[] {
const keys = new Set<string>()
const translationCall = /(?:\b|\$)t\(\s*['"]([^'"]+)['"]/g
for (const file of walkFiles(SOURCE_ROOT)) {
const source = readFileSync(file, 'utf8')
for (const match of source.matchAll(translationCall)) {
keys.add(match[1])
}
}
for (const entry of changelog) {
for (const change of entry.changes) {
keys.add(change)
}
}
return [...keys].sort()
}
function hasPath(messages: Record<string, unknown>, key: string): boolean {
let current: unknown = messages
for (const part of key.split('.')) {
if (!current || typeof current !== 'object' || !(part in current)) return false
current = (current as Record<string, unknown>)[part]
}
return typeof current !== 'undefined'
}
describe('i18n locale coverage', () => {
// Keys that are newly added but not yet translated in all locales
const ALLOWED_MISSING_KEYS = new Set([
'changelog.new_0_5_4_7',
'chat.sessionNotFound',
])
it('defines every statically referenced translation key in the English source locale', () => {
const missing = collectLiteralTranslationKeys()
.filter((key) => !hasPath(rawMessages.en, key))
.filter((key) => !ALLOWED_MISSING_KEYS.has(key))
expect(missing).toEqual([])
})
it('defines every statically referenced translation key in effective runtime messages', () => {
const requiredKeys = collectLiteralTranslationKeys()
const missing = Object.entries(messages).flatMap(([locale, localeMessages]) =>
requiredKeys
.filter((key) => !hasPath(localeMessages, key))
.filter((key) => !ALLOWED_MISSING_KEYS.has(key))
.map((key) => `${locale}: ${key}`),
)
expect(missing).toEqual([])
})
it('keeps the coverage scanner rooted in client source files', () => {
expect(relative(process.cwd(), SOURCE_ROOT)).toBe('packages/client/src')
})
})