From 4ffb22e7f69f1c9c79b095d4e60bad3d97aac55b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 18 Jun 2026 07:45:37 +0300 Subject: ik0 replace test seams with dependency injection --- internal/askcli/dispatch.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'internal/askcli/dispatch.go') diff --git a/internal/askcli/dispatch.go b/internal/askcli/dispatch.go index 924ca67..cdfc1d8 100644 --- a/internal/askcli/dispatch.go +++ b/internal/askcli/dispatch.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "time" ) // Runner performs CLI work that would otherwise be handled by the ask CLI itself. @@ -14,18 +15,30 @@ type Runner interface { } // Dispatcher translates CLI arguments into concrete subcommands and presents the output. +// +// newTicker is the injected factory for the watch-loop ticker. Production code +// uses the real time.Ticker-backed factory installed by NewDispatcher; tests +// inject a fake ticker so they can drive the watch loop without real delays. type Dispatcher struct { runner Runner jsonOutput bool + newTicker func(time.Duration) watchTicker + capture func(context.Context, []byte) (string, error) } -// NewDispatcher creates a Dispatcher backed by the provided Runner or a default executor when nil. +// NewDispatcher creates a Dispatcher backed by the provided Runner or a default +// executor when nil. It wires the default real-ticker factory used by the +// `ask watch` loop. func NewDispatcher(runner Runner) *Dispatcher { if runner == nil { e := NewExecutor("ask") runner = &e } - return &Dispatcher{runner: runner} + return &Dispatcher{ + runner: runner, + newTicker: newRealWatchTicker, + capture: editorCapture, + } } func parseGlobalFlags(args []string) ([]string, bool) { -- cgit v1.2.3