refactor: pass context and I/O explicitly through sign and verify #6
Labels
No labels
nagonag
nagonag/ignore
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
heiko/mailseal#6
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
signandverifyaccept anio.Writerbut intentionally discard it:They instead use
os.Stdout,os.Stderr,fmt.Print, and the package-global logger.signalso creates request contexts fromcontext.Background, so caller/Cobra cancellation is not propagated.This makes the most important workflows difficult to test and can corrupt the wrong output stream. It also prevents clean cancellation on command shutdown.
Checklist: #46 (accept readers/writers for testability) and #60 (propagate context through blocking operations).
Proposed fix
sign(ctx context.Context, in io.Reader, out, diag io.Writer, opts signOpts) errorand the equivalent for verification.cmd.Context(),cmd.InOrStdin(),cmd.OutOrStdout(), andcmd.ErrOrStderr()from Cobra commands.fmt.Print,os.Stdout.Write,os.Stderr, andlog.Printfin command logic with the supplied writers/logger.Acceptance criteria
Reviewed against
948b7a9onmaster(Go 1.26.2).sign,query,verify, and nownormalizeroute all output and diagnostics through injectedio.Writers (no directos.Stdout/os.Stderrreferences remain in command logic);sign/verifyacceptctxfromcmd.Context(). Added tests: all foursignoutput formats captured entirely in memory, and write-failure propagation for sign, verify, query, and normalize.Closing commit:
26b6dc84e166Note: local
masteronly so far; the link resolves once pushed.