import { describe, expect, it } from 'vitest'; import { appendErrorDetailToFailureText } from './message-turn-controller.js'; const BASE = '요청을 완료하지 못했습니다. 다시 시도해 주세요.'; describe('appendErrorDetailToFailureText', () => { it('returns the base text unchanged when there is no detail', () => { expect(appendErrorDetailToFailureText(BASE, null)).toBe(BASE); expect(appendErrorDetailToFailureText(BASE, undefined)).toBe(BASE); expect(appendErrorDetailToFailureText(BASE, ' ')).toBe(BASE); }); it('appends the error reason so the user sees what went wrong', () => { const out = appendErrorDetailToFailureText( BASE, 'API Error: 529 Overloaded. This is a server-side issue.', ); expect(out.startsWith(BASE)).toBe(true); expect(out).toContain('오류 내용:'); expect(out).toContain('API Error: 529 Overloaded'); }); it('collapses whitespace and caps very long detail', () => { const long = 'API Error: ' + 'x'.repeat(500); const out = appendErrorDetailToFailureText(BASE, long); expect(out).toContain('…'); // base + "\n\n오류 내용: " + 300 chars + "…" expect(out.length).toBeLessThan(BASE.length + 340); expect(appendErrorDetailToFailureText(BASE, 'a\n\n b\t c')).toContain( '오류 내용: a b c', ); }); it('redacts secrets embedded in the error detail', () => { const out = appendErrorDetailToFailureText( BASE, 'auth failed with key sk-ant-api03-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', ); expect(out).not.toContain('sk-ant-api03-ABCDEFGHIJKLMNOPQRSTUVWXYZ'); expect(out).toContain('[REDACTED]'); }); });