From c31f3faa2bee805cdefe9a8a4954f70432d01636 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 03:17:30 +0000 Subject: [PATCH] Tighten process package API contracts --- exec/exec.go | 14 +++++++------- exec/logger.go | 2 ++ process.go | 4 ++-- process_global.go | 4 ++-- service.go | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/exec/exec.go b/exec/exec.go index d196820..5e76ada 100644 --- a/exec/exec.go +++ b/exec/exec.go @@ -4,12 +4,12 @@ import ( "bytes" "context" "fmt" - "io" "os" "os/exec" "strings" coreerr "dappco.re/go/core/log" + goio "io" ) // ErrCommandContextRequired is returned when a command is created without a context. @@ -19,9 +19,9 @@ var ErrCommandContextRequired = coreerr.E("", "exec: command context is required type Options struct { Dir string Env []string - Stdin io.Reader - Stdout io.Writer - Stderr io.Writer + Stdin goio.Reader + Stdout goio.Writer + Stderr goio.Writer // Background runs the command asynchronously and returns from Run immediately. Background bool } @@ -74,7 +74,7 @@ func (c *Cmd) WithEnv(env []string) *Cmd { // Example: // // cmd.WithStdin(strings.NewReader("input")) -func (c *Cmd) WithStdin(r io.Reader) *Cmd { +func (c *Cmd) WithStdin(r goio.Reader) *Cmd { c.opts.Stdin = r return c } @@ -84,7 +84,7 @@ func (c *Cmd) WithStdin(r io.Reader) *Cmd { // Example: // // cmd.WithStdout(os.Stdout) -func (c *Cmd) WithStdout(w io.Writer) *Cmd { +func (c *Cmd) WithStdout(w goio.Writer) *Cmd { c.opts.Stdout = w return c } @@ -94,7 +94,7 @@ func (c *Cmd) WithStdout(w io.Writer) *Cmd { // Example: // // cmd.WithStderr(os.Stderr) -func (c *Cmd) WithStderr(w io.Writer) *Cmd { +func (c *Cmd) WithStderr(w goio.Writer) *Cmd { c.opts.Stderr = w return c } diff --git a/exec/logger.go b/exec/logger.go index 9a2992b..0340710 100644 --- a/exec/logger.go +++ b/exec/logger.go @@ -24,6 +24,8 @@ func (NopLogger) Debug(string, ...any) {} // Error discards the message (no-op implementation). func (NopLogger) Error(string, ...any) {} +var _ Logger = NopLogger{} + var defaultLogger Logger = NopLogger{} // SetDefaultLogger sets the package-level default logger. diff --git a/process.go b/process.go index e414301..ceb993d 100644 --- a/process.go +++ b/process.go @@ -3,7 +3,6 @@ package process import ( "context" "fmt" - "io" "os" "os/exec" "sync" @@ -11,6 +10,7 @@ import ( "time" coreerr "dappco.re/go/core/log" + goio "io" ) // ManagedProcess represents a managed external process. @@ -33,7 +33,7 @@ type ManagedProcess struct { ctx context.Context cancel context.CancelFunc output *RingBuffer - stdin io.WriteCloser + stdin goio.WriteCloser done chan struct{} mu sync.RWMutex gracePeriod time.Duration diff --git a/process_global.go b/process_global.go index a89580e..e7d08f1 100644 --- a/process_global.go +++ b/process_global.go @@ -17,7 +17,7 @@ var ( ) // Default returns the global process service. -// Returns nil if not initialized. +// Returns nil if not initialised. // // Example: // @@ -219,7 +219,7 @@ func Clear() { // Errors var ( - // ErrServiceNotInitialized is returned when the service is not initialized. + // ErrServiceNotInitialized is returned when the service is not initialised. ErrServiceNotInitialized = coreerr.E("", "process: service not initialized; call process.Init(core) first", nil) // ErrSetDefaultNil is returned when SetDefault is called with nil. ErrSetDefaultNil = coreerr.E("", "process: SetDefault called with nil service", nil) diff --git a/service.go b/service.go index a96b456..f11587b 100644 --- a/service.go +++ b/service.go @@ -5,7 +5,6 @@ import ( "context" "errors" "fmt" - "io" "os/exec" "sort" "sync" @@ -15,6 +14,7 @@ import ( "dappco.re/go/core" coreerr "dappco.re/go/core/log" + goio "io" ) // Default buffer size for process output (1MB). @@ -313,7 +313,7 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce } // streamOutput reads from a pipe and broadcasts lines via ACTION. -func (s *Service) streamOutput(proc *Process, r io.Reader, stream Stream) { +func (s *Service) streamOutput(proc *Process, r goio.Reader, stream Stream) { scanner := bufio.NewScanner(r) // Increase buffer for long lines scanner.Buffer(make([]byte, 64*1024), 1024*1024)