From 55f3f2a252941d684d6f3f6570c9e5e60f6bd8e1 Mon Sep 17 00:00:00 2001 From: Abhisek Datta Date: Wed, 17 Jun 2026 16:03:26 +0530 Subject: [PATCH] fix: Decouple cloud sync from telemetry (#343) --- cmd/cloud/sync.go | 6 ------ cmd/cloud/sync_background.go | 6 ------ internal/audit/audit.go | 7 +------ internal/audit/background_sync.go | 4 ---- internal/audit/background_sync_test.go | 18 +++++++++--------- 5 files changed, 10 insertions(+), 31 deletions(-) diff --git a/cmd/cloud/sync.go b/cmd/cloud/sync.go index 66bcb90..44ca688 100644 --- a/cmd/cloud/sync.go +++ b/cmd/cloud/sync.go @@ -8,7 +8,6 @@ import ( "github.com/safedep/dry/usefulerror" "github.com/safedep/pmg/config" "github.com/safedep/pmg/errcodes" - "github.com/safedep/pmg/internal/analytics" "github.com/safedep/pmg/internal/audit" "github.com/safedep/pmg/internal/ui" "github.com/spf13/cobra" @@ -37,11 +36,6 @@ func newSyncCommand() *cobra.Command { func runSync(cmd *cobra.Command, args []string) error { cfg := config.Get() - if analytics.IsDisabled() { - ui.Infof("Cloud sync is disabled because telemetry is disabled (disable_telemetry or PMG_DISABLE_TELEMETRY)") - return nil - } - if !cfg.Config.Cloud.Enabled { ui.ErrorExit(usefulerror.NewUsefulError(). WithCode(errcodes.Lifecycle). diff --git a/cmd/cloud/sync_background.go b/cmd/cloud/sync_background.go index 788c116..6c3eb86 100644 --- a/cmd/cloud/sync_background.go +++ b/cmd/cloud/sync_background.go @@ -5,7 +5,6 @@ import ( "github.com/safedep/dry/log" "github.com/safedep/pmg/config" - "github.com/safedep/pmg/internal/analytics" "github.com/safedep/pmg/internal/audit" "github.com/spf13/cobra" ) @@ -30,11 +29,6 @@ func runSyncBackground(cmd *cobra.Command, args []string) error { cfg := config.Get() - if analytics.IsDisabled() { - log.Debugf("Auto-sync: telemetry disabled; exiting") - return nil - } - if !cfg.Config.Cloud.Enabled || !cfg.Config.Cloud.AutoSync.Enabled { log.Debugf("Auto-sync: cloud or auto_sync disabled; exiting") return nil diff --git a/internal/audit/audit.go b/internal/audit/audit.go index ac1e51a..19a6b3b 100644 --- a/internal/audit/audit.go +++ b/internal/audit/audit.go @@ -8,7 +8,6 @@ import ( packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1" "github.com/safedep/dry/log" "github.com/safedep/pmg/config" - "github.com/safedep/pmg/internal/analytics" ) var global *auditor @@ -27,7 +26,7 @@ func Initialize(cfg *config.RuntimeConfig) error { var sinks []Sink sinks = append(sinks, newEventlogSink()) - if cfg.Config.Cloud.Enabled && !analytics.IsDisabled() { + if cfg.Config.Cloud.Enabled { cs, err := newCloudSink(cfg, newCloudSinkCIResolver()) if err != nil { log.Warnf("Cloud sync initialization failed: %v", err) @@ -36,10 +35,6 @@ func Initialize(cfg *config.RuntimeConfig) error { } } - if cfg.Config.Cloud.Enabled && analytics.IsDisabled() { - log.Warnf("Cloud sync is disabled because telemetry is disabled") - } - setGlobal(newAuditor(sinks...)) return nil } diff --git a/internal/audit/background_sync.go b/internal/audit/background_sync.go index 2a24027..4c4a5ea 100644 --- a/internal/audit/background_sync.go +++ b/internal/audit/background_sync.go @@ -6,7 +6,6 @@ import ( "github.com/safedep/dry/log" "github.com/safedep/pmg/config" - "github.com/safedep/pmg/internal/analytics" ) // SyncBackgroundSubcommand is the cobra `Use` of the hidden child command @@ -48,9 +47,6 @@ func MaybeSpawnBackgroundSync(cfg *config.RuntimeConfig) { if !cfg.Config.Cloud.Enabled || !cfg.Config.Cloud.AutoSync.Enabled { return } - if analytics.IsDisabled() { - return - } if !SyncCooldownElapsed(cfg.CloudSyncLastRunPath(), cfg.Config.Cloud.AutoSync.MinInterval) { log.Debugf("Auto-sync cooldown not elapsed; skipping spawn") diff --git a/internal/audit/background_sync_test.go b/internal/audit/background_sync_test.go index 8ee8e5f..9cab56f 100644 --- a/internal/audit/background_sync_test.go +++ b/internal/audit/background_sync_test.go @@ -83,6 +83,15 @@ func TestMaybeSpawnBackgroundSyncSpawnsByDefault(t *testing.T) { assert.NotEmpty(t, rec.calls[0].name, "spawned name should be a resolved binary path") } +func TestMaybeSpawnBackgroundSyncIgnoresTelemetryDisabled(t *testing.T) { + rec := withMockSpawner(t) + cfg := newAutoSyncConfig(t) + cfg.Config.DisableTelemetry = true + + MaybeSpawnBackgroundSync(cfg) + assert.Equal(t, 1, rec.callCount()) +} + func TestMaybeSpawnBackgroundSyncShortCircuits(t *testing.T) { t.Run("nil config", func(t *testing.T) { rec := withMockSpawner(t) @@ -108,15 +117,6 @@ func TestMaybeSpawnBackgroundSyncShortCircuits(t *testing.T) { assert.Equal(t, 0, rec.callCount()) }) - t.Run("telemetry disabled via config", func(t *testing.T) { - rec := withMockSpawner(t) - cfg := newAutoSyncConfig(t) - cfg.Config.DisableTelemetry = true - - MaybeSpawnBackgroundSync(cfg) - assert.Equal(t, 0, rec.callCount()) - }) - t.Run("we are the sync-background child", func(t *testing.T) { rec := withMockSpawner(t) cfg := newAutoSyncConfig(t)