diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-01 20:29:50 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-01 20:29:50 +0300 |
| commit | 5ae64f1658fb8e1daa9400efab96f3fcee5d17c0 (patch) | |
| tree | 7cf31ca579cd010594431af0e37679c2a8a8da93 /internal/gui/generator_test.go | |
| parent | 3c82415b3b9bca4b376d3044bb677438b17e491e (diff) | |
zg: add consumer coverage for shared voice lists
Diffstat (limited to 'internal/gui/generator_test.go')
| -rw-r--r-- | internal/gui/generator_test.go | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/internal/gui/generator_test.go b/internal/gui/generator_test.go index b17e5ac..d768560 100644 --- a/internal/gui/generator_test.go +++ b/internal/gui/generator_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" + "codeberg.org/snonux/totalrecall/internal/audio" "codeberg.org/snonux/totalrecall/internal/image" ) @@ -53,6 +54,27 @@ func (f *fakePromptAwareImageClient) SetPromptCallback(callback func(prompt stri f.promptCallback = callback } +type fakeAudioProvider struct { + generateCalls int + lastText string + lastOutputFile string +} + +func (f *fakeAudioProvider) GenerateAudio(_ context.Context, text, outputFile string) error { + f.generateCalls++ + f.lastText = text + f.lastOutputFile = outputFile + return nil +} + +func (f *fakeAudioProvider) Name() string { + return "fake-audio" +} + +func (f *fakeAudioProvider) IsAvailable() error { + return nil +} + func TestGenerateImagesWithPromptUsesNanoBananaProvider(t *testing.T) { originalNanoBananaClient := newNanoBananaImageClient originalOpenAIClient := newOpenAIImageClient @@ -127,3 +149,68 @@ func TestGenerateImagesWithPromptUsesNanoBananaProvider(t *testing.T) { t.Fatalf("outputPath = %q, want a PNG output file", outputPath) } } + +func TestGenerateAudioUsesSharedOpenAIVoices(t *testing.T) { + originalFactory := newAudioProvider + t.Cleanup(func() { + newAudioProvider = originalFactory + }) + + originalVoices := append([]string(nil), audio.OpenAIVoices...) + t.Cleanup(func() { + audio.OpenAIVoices = originalVoices + }) + + audio.OpenAIVoices = []string{"sentinel-gui-voice"} + + fakeProvider := &fakeAudioProvider{} + var capturedConfig *audio.Config + newAudioProvider = func(config *audio.Config) (audio.Provider, error) { + copyConfig := *config + capturedConfig = ©Config + return fakeProvider, nil + } + + tempDir := t.TempDir() + cardDir := filepath.Join(tempDir, "card") + if err := os.MkdirAll(cardDir, 0755); err != nil { + t.Fatalf("failed to create card dir: %v", err) + } + + app := &Application{ + config: &Config{ + OutputDir: tempDir, + AudioFormat: "mp3", + }, + audioConfig: &audio.Config{ + Provider: "openai", + OutputDir: tempDir, + OpenAIModel: "gpt-4o-mini-tts", + OpenAIInstruction: "Speak clearly.", + }, + } + + outputPath, err := app.generateAudio(context.Background(), "ябълка", cardDir) + if err != nil { + t.Fatalf("generateAudio() unexpected error: %v", err) + } + + if capturedConfig == nil { + t.Fatal("expected audio provider config to be captured") + } + if capturedConfig.OpenAIVoice != "sentinel-gui-voice" { + t.Fatalf("captured OpenAIVoice = %q, want %q", capturedConfig.OpenAIVoice, "sentinel-gui-voice") + } + if fakeProvider.generateCalls != 1 { + t.Fatalf("GenerateAudio() calls = %d, want %d", fakeProvider.generateCalls, 1) + } + if fakeProvider.lastText != "ябълка" { + t.Fatalf("GenerateAudio() text = %q, want %q", fakeProvider.lastText, "ябълка") + } + if fakeProvider.lastOutputFile != outputPath { + t.Fatalf("GenerateAudio() output file = %q, want %q", fakeProvider.lastOutputFile, outputPath) + } + if !strings.HasSuffix(outputPath, "audio.mp3") { + t.Fatalf("outputPath = %q, want shared audio filename", outputPath) + } +} |
