mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-20 04:15:31 +00:00
Two bugs fixed in callProvider: 1. Silent fallback when API credentials are missing for a transcription or gemini/openai path now returns a clear error instead of falling through to a generic chat-API path that explodes confusingly (or NPEs on a nil registry). 2. openai_compat providers (e.g. DashScope) pointed at a transcription endpoint never reached /v1/audio/transcriptions because only ptype=="openai" entered the transcription branch. Move the isTranscriptionModel(model) check above the ptype switch so any OpenAI-compatible provider that exposes the transcription endpoint is routed correctly. Adds three regression tests covering the fail-fast paths.
74 lines
2.7 KiB
Go
74 lines
2.7 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestReadAudioCallProvider_TranscriptionModelWithoutCreds_FailsFast asserts
|
|
// that when no API credentials are present, a transcription-named model
|
|
// returns a clear error rather than silently falling back to chat/completions
|
|
// (which would then explode in a confusing way for transcription-only setups).
|
|
func TestReadAudioCallProvider_TranscriptionModelWithoutCreds_FailsFast(t *testing.T) {
|
|
tool := &ReadAudioTool{}
|
|
|
|
params := map[string]any{
|
|
"_provider_type": "openai",
|
|
"data": []byte{0x00, 0x01},
|
|
"mime": "audio/mpeg",
|
|
}
|
|
|
|
_, _, err := tool.callProvider(context.Background(), nil, "openai", "gpt-4o-mini-transcribe", params)
|
|
if err == nil {
|
|
t.Fatalf("expected fail-fast error for transcription model with nil credentials, got nil")
|
|
}
|
|
if !strings.Contains(strings.ToLower(err.Error()), "credential") {
|
|
t.Errorf("expected error to mention credentials, got: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestReadAudioCallProvider_TranscriptionModelWithoutCreds_OpenAICompat_FailsFast
|
|
// covers the openai_compat ptype variant — the bug the original PR found:
|
|
// previously a transcription model under openai_compat fell through to the
|
|
// generic chat-API fallback because only ptype=="openai" entered the
|
|
// transcription branch.
|
|
func TestReadAudioCallProvider_TranscriptionModelWithoutCreds_OpenAICompat_FailsFast(t *testing.T) {
|
|
tool := &ReadAudioTool{}
|
|
|
|
params := map[string]any{
|
|
"_provider_type": "openai_compat",
|
|
"data": []byte{0x00, 0x01},
|
|
"mime": "audio/mpeg",
|
|
}
|
|
|
|
_, _, err := tool.callProvider(context.Background(), nil, "dashscope", "whisper-1", params)
|
|
if err == nil {
|
|
t.Fatalf("expected fail-fast error for transcription model with nil credentials (openai_compat), got nil")
|
|
}
|
|
if !strings.Contains(strings.ToLower(err.Error()), "credential") {
|
|
t.Errorf("expected error to mention credentials, got: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestReadAudioCallProvider_GeminiWithoutCreds_FailsFast preserves the existing
|
|
// gemini fail-fast behavior (was previously a soft log + fallback that would
|
|
// then NPE on the registry path in tests; the broader guard makes it explicit).
|
|
func TestReadAudioCallProvider_GeminiWithoutCreds_FailsFast(t *testing.T) {
|
|
tool := &ReadAudioTool{}
|
|
|
|
params := map[string]any{
|
|
"_provider_type": "gemini",
|
|
"data": []byte{0x00, 0x01},
|
|
"mime": "audio/mpeg",
|
|
}
|
|
|
|
_, _, err := tool.callProvider(context.Background(), nil, "gemini", "gemini-2.5-flash", params)
|
|
if err == nil {
|
|
t.Fatalf("expected fail-fast error for gemini with nil credentials, got nil")
|
|
}
|
|
if !strings.Contains(strings.ToLower(err.Error()), "credential") {
|
|
t.Errorf("expected error to mention credentials, got: %v", err)
|
|
}
|
|
}
|