import test from 'node:test';
import assert from 'node:assert/strict';
import { sanitizeAsrMessage } from './asr-proxy.mjs';

test('sanitizeAsrMessage shortens ffmpeg decode errors', () => {
  const message = sanitizeAsrMessage('Failed to load audio: ffmpeg version 4.2.10 ...');
  assert.equal(message, '音频格式无法识别，请重新录制');
});

test('sanitizeAsrMessage keeps concise upstream messages', () => {
  assert.equal(sanitizeAsrMessage('未检测到有效语音'), '未检测到有效语音');
});

test('sanitizeAsrMessage truncates long messages', () => {
  const long = 'x'.repeat(200);
  const message = sanitizeAsrMessage(long);
  assert.ok(message.endsWith('…'));
  assert.ok(message.length <= 161);
});
