Skip to content

Commit 79ca2af

Browse files
authored
fix(plugins): respect auto-sync flag in dependency-check validation (#174)
The validateDependencyConsistency() function now checks the AutoSync configuration flag before returning an error. When auto-sync is enabled, inconsistencies are allowed since they will be fixed after the bump. Fixes #172
1 parent bb5363a commit 79ca2af

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

cmd/sley/bumpcmd/bump_plugins_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,60 @@ func TestSingleModuleBump_ValidateDependencyConsistencyFails(t *testing.T) {
562562
}
563563
}
564564

565+
func TestValidateDependencyConsistency_AutoSyncSkipsError(t *testing.T) {
566+
tmpDir := t.TempDir()
567+
568+
// Create package.json with different version
569+
pkgPath := filepath.Join(tmpDir, "package.json")
570+
if err := os.WriteFile(pkgPath, []byte(`{"version": "0.9.0"}`), 0644); err != nil {
571+
t.Fatal(err)
572+
}
573+
574+
version := semver.SemVersion{Major: 1, Minor: 0, Patch: 0}
575+
576+
tests := []struct {
577+
name string
578+
autoSync bool
579+
expectErr bool
580+
}{
581+
{
582+
name: "auto-sync disabled returns error on inconsistencies",
583+
autoSync: false,
584+
expectErr: true,
585+
},
586+
{
587+
name: "auto-sync enabled skips error on inconsistencies",
588+
autoSync: true,
589+
expectErr: false,
590+
},
591+
}
592+
593+
for _, tt := range tests {
594+
t.Run(tt.name, func(t *testing.T) {
595+
plugin := dependencycheck.NewDependencyChecker(&dependencycheck.Config{
596+
Enabled: true,
597+
AutoSync: tt.autoSync,
598+
Files: []dependencycheck.FileConfig{
599+
{Path: pkgPath, Field: "version", Format: "json"},
600+
},
601+
})
602+
603+
registry := plugins.NewPluginRegistry()
604+
if err := registry.RegisterDependencyChecker(plugin); err != nil {
605+
t.Fatalf("failed to register dependency checker: %v", err)
606+
}
607+
608+
err := validateDependencyConsistency(registry, version)
609+
if tt.expectErr && err == nil {
610+
t.Error("expected error, got nil")
611+
}
612+
if !tt.expectErr && err != nil {
613+
t.Errorf("expected no error, got: %v", err)
614+
}
615+
})
616+
}
617+
}
618+
565619
func TestSingleModuleBump_ValidateTagAvailableFails(t *testing.T) {
566620
tmpDir := t.TempDir()
567621
versionPath := filepath.Join(tmpDir, ".version")

cmd/sley/bumpcmd/helpers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ func validateDependencyConsistency(registry *plugins.PluginRegistry, version sem
183183
}
184184

185185
if len(inconsistencies) > 0 {
186+
// If auto-sync is enabled, skip the error - inconsistencies will be fixed after the bump
187+
if plugin.GetConfig().AutoSync {
188+
return nil
189+
}
190+
186191
var details strings.Builder
187192
details.WriteString("version inconsistencies detected:\n")
188193
for _, inc := range inconsistencies {

0 commit comments

Comments
 (0)