Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(chat): add tests for chat error copy_key rendering

Steven Enamakelab9b8946b910
diff --git a/app/src/lib/chatErrorCopy.test.ts b/app/src/lib/chatErrorCopy.test.ts
new file mode 100644
index 0000000000..4df7e9a583
--- /dev/null
+++ b/app/src/lib/chatErrorCopy.test.ts
@@ -0,0 +1,65 @@
+import { describe, expect, it } from 'vitest';
+
+import { chatErrorCopyText } from './chatErrorCopy';
+import en from './i18n/en';
+
+const table: Record<string, string> = {
+ ...(en as Record<string, string>),
+ 'chat_error.timeout': 'LOCALIZED timeout',
+};
+const t = (key: string, fallback?: string) => table[key] ?? fallback ?? key;
+
+describe('chatErrorCopyText', () => {
+ it('renders a known key from the translation table', () => {
+ expect(
+ chatErrorCopyText({ message: 'english', copy_key: 'chat_error.timeout' }, t)
+ ).toBe('LOCALIZED timeout');
+ });
+
+ it('appends the retry hint and the quoted provider detail', () => {
+ const text = chatErrorCopyText(
+ {
+ message: 'english',
+ copy_key: 'chat_error.managed_rate_limited',
+ copy_params: { retry_after_secs: 45, provider: 'openhuman', detail: 'slow down' },
+ },
+ t
+ );
+ expect(text).toBe(
+ 'Your AI provider is rate-limiting requests. You can retry in this thread. Try again in 45 seconds.\n\n> slow down'
+ );
+ });
+
+ it.each([
+ [0, 'You can retry immediately.'],
+ [1, 'Try again in 1 second.'],
+ [89, 'Try again in 89 seconds.'],
+ [90, 'Try again in about 2 minutes.'],
+ [61 * 60, 'Try again in about 62 minutes.'],
+ [60 * 60, 'Try again in about 60 minutes.'],
+ ])('formats a %i second retry hint like the core', (secs, hint) => {
+ const text = chatErrorCopyText(
+ {
+ message: 'english',
+ copy_key: 'chat_error.rate_limited',
+ copy_params: { retry_after_secs: secs },
+ },
+ t
+ );
+ expect(text.endsWith(` ${hint}`)).toBe(true);
+ });
+
+ it('falls back to message for an unknown key', () => {
+ expect(chatErrorCopyText({ message: 'english', copy_key: 'chat_error.nope' }, t)).toBe(
+ 'english'
+ );
+ });
+
+ it('falls back to message for a key outside the chat_error namespace', () => {
+ expect(chatErrorCopyText({ message: 'english', copy_key: 'nav.home' }, t)).toBe('english');
+ });
+
+ it('falls back to message when there is no key', () => {
+ expect(chatErrorCopyText({ message: 'english' }, t)).toBe('english');
+ });
+});
diff --git a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
index 12ac83d244..e9f1ad8bf4 100644
--- a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
+++ b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
@@ -461,6 +461,62 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
expect(store.getState().chatRuntime.parallelRequestThreads['branch-error']).toBeUndefined();
});
+ describe('chat_error copy_key rendering', () => {
+ const failParallel = (
+ requestId: string,
+ extra: { copy_key?: string; copy_params?: Record<string, unknown> }
+ ) => {
+ const listeners = renderProvider();
+ act(() => {
+ store.dispatch(registerParallelRequest({ threadId: 't-copy', requestId }));
+ listeners.onError?.({
+ thread_id: 't-copy',
+ request_id: requestId,
+ message: 'core english message',
+ error_type: 'rate_limited',
+ round: 0,
+ ...extra,
+ });
+ });
+ };
+
+ it('renders a known copy_key from the locale table with its params', async () => {
+ failParallel('copy-known', {
+ copy_key: 'chat_error.rate_limited',
+ copy_params: { retry_after_secs: 30, detail: 'quota hit' },
+ });
+ await waitFor(() =>
+ expect(threadApi.appendMessage).toHaveBeenCalledWith(
+ 't-copy',
+ expect.objectContaining({
+ content:
+ "Your AI provider is rate-limiting requests. This is a transient upstream limit, not a thread-level block. You can retry in this thread. Try again in 30 seconds.\n\n> quota hit",
+ })
+ )
+ );
+ });
+
+ it('falls back to message for an unknown copy_key', async () => {
+ failParallel('copy-unknown', { copy_key: 'chat_error.from_a_newer_core' });
+ await waitFor(() =>
+ expect(threadApi.appendMessage).toHaveBeenCalledWith(
+ 't-copy',
+ expect.objectContaining({ content: 'core english message' })
+ )
+ );
+ });
+
+ it('falls back to message when copy_key is missing', async () => {
+ failParallel('copy-missing', {});
+ await waitFor(() =>
+ expect(threadApi.appendMessage).toHaveBeenCalledWith(
+ 't-copy',
+ expect.objectContaining({ content: 'core english message' })
+ )
+ );
+ });
+ });
+
it('bumps the heartbeat counter only for the primary turn, never a parallel branch (#4282)', () => {
const listeners = renderProvider();