feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -121,6 +121,108 @@ public sealed class SttFailClosedTests
|
|||
Assert.DoesNotContain(apiKey, fixture.Handler.LastRequestUri, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OversizedAudioBase64_IsRejectedBeforeDecodingOrCallingProvider()
|
||||
{
|
||||
await using var fixture = await SttFixture.CreateAsync(
|
||||
apiKey: "configured-key",
|
||||
_ => throw new InvalidOperationException("HTTP should not be called"));
|
||||
|
||||
// Over 26 MiB base64 payload (~36.4M chars), prefixed like a browser data URL.
|
||||
var oversizedPayload = "data:audio/wav;base64," + new string('A', 36_400_000);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
fixture.Service.TranscribeAsync(
|
||||
13,
|
||||
"user@example.test",
|
||||
new SttTranscribeRequest(AudioBase64: oversizedPayload, Language: "ko")));
|
||||
|
||||
Assert.Equal(0, fixture.Handler.CallCount);
|
||||
Assert.Empty(await fixture.Db.SttUsageLogs.ToListAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClientCancellation_StopsFailoverChainBeforeCallingFallbackProvider()
|
||||
{
|
||||
using var cts = new CancellationTokenSource();
|
||||
await using var fixture = await SttFixture.CreateAsync(
|
||||
apiKey: "configured-key",
|
||||
req =>
|
||||
{
|
||||
cts.Cancel();
|
||||
throw new OperationCanceledException(cts.Token);
|
||||
},
|
||||
providerType: "groq",
|
||||
endpointUrl: "https://primary.example.test/transcriptions");
|
||||
|
||||
fixture.Db.SttProviderEndpoints.Add(new SttProviderEndpoint
|
||||
{
|
||||
Name = "Backup provider",
|
||||
ProviderType = "openai",
|
||||
EndpointUrl = "https://fallback.example.test/transcriptions",
|
||||
ApiKey = "backup-key",
|
||||
ModelId = "whisper-backup",
|
||||
Method = "multipart",
|
||||
Language = "ko",
|
||||
IsDefault = false,
|
||||
IsActive = true,
|
||||
FallbackPriority = 2
|
||||
});
|
||||
await fixture.Db.SaveChangesAsync();
|
||||
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>
|
||||
fixture.Service.TranscribeAsync(
|
||||
14,
|
||||
"user@example.test",
|
||||
new SttTranscribeRequest(Language: "ko"),
|
||||
new byte[] { 1, 2, 3 },
|
||||
"audio/webm",
|
||||
"recording.webm",
|
||||
cancellationToken: cts.Token));
|
||||
|
||||
Assert.Equal(1, fixture.Handler.CallCount);
|
||||
Assert.Empty(await fixture.Db.ErrorLogs.ToListAsync());
|
||||
Assert.Empty(await fixture.Db.SttUsageLogs.ToListAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task LlmProxyService_ClientCancellation_PropagatesWithoutMockFallback()
|
||||
{
|
||||
await using var fixture = await SttFixture.CreateAsync(
|
||||
apiKey: "unused",
|
||||
_ => throw new OperationCanceledException());
|
||||
fixture.Db.ModelEndpoints.Add(new ServiceModelEndpoint
|
||||
{
|
||||
ModelId = "remote-llm",
|
||||
ModelName = "Remote LLM",
|
||||
Provider = "OpenAI",
|
||||
EndpointUrl = "https://llm.example.test/v1/chat/completions",
|
||||
ApiKey = "configured-llm-key",
|
||||
CostPer1kPromptTokens = 0.001m,
|
||||
CostPer1kCompletionTokens = 0.002m,
|
||||
IsActive = true
|
||||
});
|
||||
await fixture.Db.SaveChangesAsync();
|
||||
|
||||
using var cts = new CancellationTokenSource();
|
||||
cts.Cancel();
|
||||
var llmService = new LlmProxyService(
|
||||
fixture.Db,
|
||||
new StubHttpClientFactory(fixture.Handler),
|
||||
NullLogger<LlmProxyService>.Instance);
|
||||
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>
|
||||
llmService.GenerateAsync(
|
||||
15,
|
||||
"user@example.test",
|
||||
new LlmGenerateRequest("Hello", Model: "remote-llm"),
|
||||
cts.Token));
|
||||
|
||||
Assert.Equal(0, fixture.Handler.CallCount);
|
||||
Assert.Empty(await fixture.Db.UsageLogs.ToListAsync());
|
||||
Assert.Empty(await fixture.Db.ErrorLogs.ToListAsync());
|
||||
}
|
||||
|
||||
private sealed class SttFixture : IAsyncDisposable
|
||||
{
|
||||
private readonly SqliteConnection _connection;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue