cc-haha/desktop/src/i18n/index.test.tsx
程序员阿江(Relakkes) f57f163604 fix: prevent session inspector context stalls
Session inspection was coupling quick status and usage rendering to live context control requests, so a slow get_context_usage path could leave the desktop inspector stuck on a loading state. The desktop panel now loads basic inspection data first, renders a transcript-based context estimate immediately, and only asks for live context details as a background refinement.

The translation hook now returns a stable function per locale so effects that depend on translation do not reset and re-fetch after every render.

Constraint: Third-party provider sessions may not expose reliable live context capabilities through the control request path.
Rejected: Keep waiting on live get_context_usage for the context tab | it recreates the user-visible loading stall.
Rejected: Hardcode provider-specific context windows | provider capabilities are not always known from the desktop session record.
Confidence: high
Scope-risk: moderate
Directive: Do not make the inspector first render depend on live CLI control requests without a transcript or cached fallback.
Tested: bun test src/server/__tests__/conversations.test.ts -t "structured session inspection|Sonnet 4.6 transcript usage"
Tested: cd desktop && bun run test -- --run src/i18n/index.test.tsx
Tested: cd desktop && bun run build
Tested: git diff --check
Tested: agent-browser verified /context renders transcript estimate without Loading context data
Not-tested: Provider-specific true context-window discovery for every third-party vendor
2026-04-28 22:52:18 +08:00

30 lines
783 B
TypeScript

import { act, renderHook } from '@testing-library/react'
import { afterEach, describe, expect, it } from 'vitest'
import { useSettingsStore } from '../stores/settingsStore'
import { useTranslation } from '.'
describe('useTranslation', () => {
afterEach(() => {
act(() => {
useSettingsStore.getState().setLocale('zh')
})
})
it('keeps the translation function stable until the locale changes', () => {
act(() => {
useSettingsStore.getState().setLocale('zh')
})
const { result, rerender } = renderHook(() => useTranslation())
const initial = result.current
rerender()
expect(result.current).toBe(initial)
act(() => {
useSettingsStore.getState().setLocale('en')
})
expect(result.current).not.toBe(initial)
})
})