From 9c6fc8cffa17eaa1872c93c3971a8217f7ea3c9c Mon Sep 17 00:00:00 2001 From: vergil_on Date: Sun, 9 Aug 2026 00:32:07 +0300 Subject: [PATCH] =?UTF-8?q?refactor(pipeline):=20=D0=B2=D0=B2=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20Runner=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- cmd/synapse-backupper/backup.go | 17 ++++------------- cmd/synapse-backupper/backup_test.go | 4 ++-- pkg/adapters/pipeline/pipeline.go | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cmd/synapse-backupper/backup.go b/cmd/synapse-backupper/backup.go index b519343..1ef0bea 100644 --- a/cmd/synapse-backupper/backup.go +++ b/cmd/synapse-backupper/backup.go @@ -35,17 +35,7 @@ var ( outputWriter io.Writer = os.Stderr ) -type pipelineRunner interface { - Run( - ctx context.Context, - pgDumpOpts pgdump.Options, - recipients []crypto.RecipientPub, - sink domain.Sink, - rand io.Reader, - ) error -} - -func defaultNewRunner(options ...pipeline.Option) pipelineRunner { +func defaultNewRunner(options ...pipeline.Option) pipeline.Runner { return pipeline.NewRunner(options...) } @@ -91,7 +81,8 @@ var backupCmd = &cobra.Command{ return fmt.Errorf("load classical public key: %w", err) } - recipients := []crypto.RecipientPub{pqPub, classicalPub} + recipients := make([]crypto.RecipientPub, 0, 2) + recipients = append(recipients, pqPub, classicalPub) pgDumpOpts := pgdump.Options{ Host: cfg.PG.Host, @@ -110,7 +101,7 @@ var backupCmd = &cobra.Command{ slog.String("output_path", finalPath), ) - sink := newLocalSink(cfg.Backup.Dir) + var sink domain.Sink = newLocalSink(cfg.Backup.Dir) registry := crypto.NewRegistry() _ = registry.Register(0x0006, func() crypto.KEM { return mlkem768.New() }) diff --git a/cmd/synapse-backupper/backup_test.go b/cmd/synapse-backupper/backup_test.go index d382c7e..1f7c1dc 100644 --- a/cmd/synapse-backupper/backup_test.go +++ b/cmd/synapse-backupper/backup_test.go @@ -183,7 +183,7 @@ func TestBackupCmd_Success(t *testing.T) { testData := []byte("test backup payload") dumper := &successDumper{data: testData} - newRunner = func(...pipeline.Option) pipelineRunner { + newRunner = func(...pipeline.Option) pipeline.Runner { return pipeline.NewRunner( pipeline.WithDumper(dumper), pipeline.WithEncryptor(&passthroughEncryptor{}), @@ -320,7 +320,7 @@ func TestBackupCmd_PgDumpFailure(t *testing.T) { return mockKM } - newRunner = func(...pipeline.Option) pipelineRunner { + newRunner = func(...pipeline.Option) pipeline.Runner { return pipeline.NewRunner( pipeline.WithDumper(&failDumper{}), pipeline.WithEncryptor(&passthroughEncryptor{}), diff --git a/pkg/adapters/pipeline/pipeline.go b/pkg/adapters/pipeline/pipeline.go index 0134c0b..1e3fd05 100644 --- a/pkg/adapters/pipeline/pipeline.go +++ b/pkg/adapters/pipeline/pipeline.go @@ -9,6 +9,18 @@ import ( "git.tswf.io/infra/go-synapse-backupper/pkg/domain/pgdump" ) +// Runner orchestrates the dump → encrypt → sink pipeline. +type Runner interface { + // Run executes the full backup pipeline: pg_dump → encrypt → sink. + Run( + ctx context.Context, + pgDumpOpts pgdump.Options, + recipients []crypto.RecipientPub, + sink domain.Sink, + rand io.Reader, + ) error +} + // Option configures a Runner. type Option func(*runner) @@ -26,14 +38,14 @@ func WithEncryptor(encryptor crypto.Encryptor) Option { } } -// Runner orchestrates the dump → encrypt → sink pipeline. +// runner is the private implementation of Runner. type runner struct { dumper pgdump.Dumper encryptor crypto.Encryptor } // NewRunner creates a pipeline runner with the given functional options. -func NewRunner(options ...Option) *runner { +func NewRunner(options ...Option) Runner { r := &runner{} for _, option := range options { option(r)