From 05f54cc0cb8cf3535698ab5027d200842bdb28e3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 6 Apr 2026 11:06:19 +0300 Subject: refactor: consolidate provider factory test seams into shared named types Define audio.ProviderFactory, image.PromptAwareClient, image.OpenAIClientFactory, image.NanoBananaClientFactory, and image.ClientFactories as the single source of truth for the three injectable factory signatures that were previously duplicated across processor.Processor, gui.Application, and gui.GenerationOrchestrator. Replace all three separate function-type fields with imageFactories image.ClientFactories + newAudioProvider audio.ProviderFactory, eliminating the parallel field declarations and the local promptAwareImageClient interface in gui/generator.go. Co-Authored-By: Claude Sonnet 4.6 --- internal/processor/processor.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'internal/processor/processor.go') diff --git a/internal/processor/processor.go b/internal/processor/processor.go index 7d83149..14e5341 100644 --- a/internal/processor/processor.go +++ b/internal/processor/processor.go @@ -64,8 +64,9 @@ type Config struct { // Processor handles the main word processing logic. // Audio coordination is in audio_coordinator.go, card directory management is // in card_store.go, and image downloading is in image_downloader.go. -// The factory fields (newOpenAIImageClient, newNanoBananaImageClient, newAudioProvider) -// are injected at construction time so tests can swap them without mutating global state. +// Factory functions for image and audio providers are grouped in image.ClientFactories +// and the audio.ProviderFactory type so the signatures are defined once and +// shared with the gui package — eliminating parallel field duplication. type Processor struct { flags *cli.Flags translator *translation.Translator @@ -76,10 +77,13 @@ type Processor struct { // so individual methods never call Viper directly. cfg *Config - // Factories — replaced by tests to inject fakes. - newOpenAIImageClient func(*image.OpenAIConfig) image.ImageClient - newNanoBananaImageClient func(*image.NanoBananaConfig) image.ImageClient - newAudioProvider func(*audio.Config) (audio.Provider, error) + // imageFactories groups the two image-provider construction functions. + // Production code uses image.DefaultClientFactories(); tests replace fields. + imageFactories image.ClientFactories + + // newAudioProvider constructs an audio.Provider from a Config. + // Production code uses audio.NewProvider; tests replace it with a fake. + newAudioProvider audio.ProviderFactory } // NewProcessor creates a new word processor with default production factories. @@ -99,12 +103,7 @@ func NewProcessor(flags *cli.Flags, cfg *Config) *Processor { translationCache: translation.NewTranslationCache(), phoneticFetcher: phonetic.NewFetcher(&phonetic.Config{Provider: phoneticProvider, OpenAIKey: openAIKey, GoogleAPIKey: googleAPIKey}), randomIntn: rand.Intn, - newOpenAIImageClient: func(config *image.OpenAIConfig) image.ImageClient { - return image.NewOpenAIClient(config) - }, - newNanoBananaImageClient: func(config *image.NanoBananaConfig) image.ImageClient { - return image.NewNanoBananaClient(config) - }, + imageFactories: image.DefaultClientFactories(), newAudioProvider: audio.NewProvider, } } -- cgit v1.2.3