锁定 ElevenLabs 单次请求与音频时长边界

显式禁用 ElevenLabs 专用 HTTP 客户端重试。

增加真实 MP3 帧的 600 秒上下边界回归测试。
This commit is contained in:
2026-08-07 03:35:08 +00:00
parent 9d1f4c1975
commit 9d581bbe8c
2 changed files with 28 additions and 0 deletions
@@ -50,6 +50,7 @@ pub fn build_elevenlabs_audio_http_client(
settings: &ElevenLabsAudioSettings,
) -> Result<reqwest::Client, AudioError> {
reqwest::Client::builder()
.retry(reqwest::retry::never())
.timeout(std::time::Duration::from_millis(
settings.request_timeout_ms.max(1),
))
@@ -92,6 +92,19 @@ mod tests {
use super::*;
const REAL_MP3_FRAME_OFFSET: usize = 1_374;
const REAL_MP3_FRAME_LENGTH: usize = 156;
fn repeated_real_mp3_frame(frame_count: usize) -> Bytes {
let fixture = base64::engine::general_purpose::STANDARD
.decode(include_str!("../tests/fixtures/vbr-id3.mp3.base64").trim())
.expect("VBR MP3 fixture should decode");
let frame = &fixture[REAL_MP3_FRAME_OFFSET..REAL_MP3_FRAME_OFFSET + REAL_MP3_FRAME_LENGTH];
assert_eq!(&frame[..4], &[0xff, 0xfb, 0x30, 0xc4]);
Bytes::from(frame.repeat(frame_count))
}
#[test]
fn duration_guard_uses_only_the_independent_six_hundred_second_limit() {
for duration in [0.001, 30.5, 60.0, 600.0] {
@@ -128,6 +141,20 @@ mod tests {
assert!((0.39..=0.46).contains(&duration), "duration={duration}");
}
#[test]
fn probe_enforces_the_six_hundred_second_boundary_on_real_mp3_frames() {
let accepted_duration = probe_mp3_duration_seconds(repeated_real_mp3_frame(22_968))
.expect("real MP3 just below 600 seconds should pass");
assert!(
(599.9..=600.0).contains(&accepted_duration),
"duration={accepted_duration}"
);
let error = probe_mp3_duration_seconds(repeated_real_mp3_frame(22_969))
.expect_err("real MP3 just above 600 seconds should fail");
assert!(error.contains("不超过 600 秒"), "error={error}");
}
#[test]
fn probe_rejects_non_mp3_and_empty_payloads() {
for payload in [Bytes::new(), Bytes::from_static(b"<html>error</html>")] {