fix(config): remove duplicate declarations and fix test failures (#1160)

* fix(config): remove duplicate declarations between config.go and sync.go

Commit e82e15a8 created sync.go with typed constants (SyncMode,
ConflictStrategy, Sovereignty) but didn't remove the original untyped
constants from config.go that were added in 16f8c3d3. This caused
redeclaration errors preventing the project from building.

Changes:
- Remove duplicate SyncMode, ConflictStrategy, Sovereignty constants
  from config.go (keep typed versions in sync.go)
- Remove duplicate GetSyncMode, GetConflictStrategy, GetSovereignty
  functions from config.go (keep sync.go versions with warnings)
- Update SyncConfig, ConflictConfig, FederationConfig structs to use
  typed fields instead of string
- Add IsSyncModeValid, IsConflictStrategyValid, IsSovereigntyValid
  wrapper functions that use sync.go's validation maps
- Update cmd/bd/sync.go to use typed ConflictStrategy parameter
- Update tests to work with typed constants

* fix(dolt): handle Merge return values in concurrent test

* fix(test): add --repo flag to show_test.go to bypass auto-routing

The tests were failing because the create command was routing issues
to ~/.beads-planning instead of the test's temp directory. Adding
--repo . overrides auto-routing and creates issues in the test dir.
This commit is contained in:
Subhrajit Makur
2026-01-19 23:41:14 +05:30
committed by GitHub
parent 2cbf3a5497
commit 065ca3d6af
5 changed files with 50 additions and 152 deletions

View File

@@ -1119,13 +1119,14 @@ func TestFederationConfigDefaults(t *testing.T) {
t.Fatalf("Initialize() returned error: %v", err)
}
// Test federation config defaults (empty)
// Test federation config defaults
cfg := GetFederationConfig()
if cfg.Remote != "" {
t.Errorf("GetFederationConfig().Remote = %q, want empty", cfg.Remote)
}
if cfg.Sovereignty != "" {
t.Errorf("GetFederationConfig().Sovereignty = %q, want empty", cfg.Sovereignty)
// Default sovereignty is T1 when not configured
if cfg.Sovereignty != SovereigntyT1 {
t.Errorf("GetFederationConfig().Sovereignty = %q, want %q (default)", cfg.Sovereignty, SovereigntyT1)
}
}
@@ -1134,10 +1135,10 @@ func TestIsSyncModeValid(t *testing.T) {
mode string
valid bool
}{
{SyncModeGitPortable, true},
{SyncModeRealtime, true},
{SyncModeDoltNative, true},
{SyncModeBeltAndSuspenders, true},
{string(SyncModeGitPortable), true},
{string(SyncModeRealtime), true},
{string(SyncModeDoltNative), true},
{string(SyncModeBeltAndSuspenders), true},
{"invalid-mode", false},
{"", false},
}
@@ -1156,10 +1157,10 @@ func TestIsConflictStrategyValid(t *testing.T) {
strategy string
valid bool
}{
{ConflictStrategyNewest, true},
{ConflictStrategyOurs, true},
{ConflictStrategyTheirs, true},
{ConflictStrategyManual, true},
{string(ConflictStrategyNewest), true},
{string(ConflictStrategyOurs), true},
{string(ConflictStrategyTheirs), true},
{string(ConflictStrategyManual), true},
{"invalid-strategy", false},
{"", false},
}
@@ -1178,10 +1179,10 @@ func TestIsSovereigntyValid(t *testing.T) {
sovereignty string
valid bool
}{
{SovereigntyT1, true},
{SovereigntyT2, true},
{SovereigntyT3, true},
{SovereigntyT4, true},
{string(SovereigntyT1), true},
{string(SovereigntyT2), true},
{string(SovereigntyT3), true},
{string(SovereigntyT4), true},
{"", true}, // Empty is valid (means no restriction)
{"T5", false},
{"invalid", false},
@@ -1310,7 +1311,7 @@ func TestNeedsDoltRemote(t *testing.T) {
defer restore()
tests := []struct {
mode string
mode SyncMode
needsRemote bool
}{
{SyncModeGitPortable, false},
@@ -1320,11 +1321,11 @@ func TestNeedsDoltRemote(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.mode, func(t *testing.T) {
t.Run(string(tt.mode), func(t *testing.T) {
if err := Initialize(); err != nil {
t.Fatalf("Initialize() returned error: %v", err)
}
Set("sync.mode", tt.mode)
Set("sync.mode", string(tt.mode))
if got := NeedsDoltRemote(); got != tt.needsRemote {
t.Errorf("NeedsDoltRemote() with mode=%s = %v, want %v", tt.mode, got, tt.needsRemote)
@@ -1339,7 +1340,7 @@ func TestNeedsJSONL(t *testing.T) {
defer restore()
tests := []struct {
mode string
mode SyncMode
needsJSONL bool
}{
{SyncModeGitPortable, true},
@@ -1349,11 +1350,11 @@ func TestNeedsJSONL(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.mode, func(t *testing.T) {
t.Run(string(tt.mode), func(t *testing.T) {
if err := Initialize(); err != nil {
t.Fatalf("Initialize() returned error: %v", err)
}
Set("sync.mode", tt.mode)
Set("sync.mode", string(tt.mode))
if got := NeedsJSONL(); got != tt.needsJSONL {
t.Errorf("NeedsJSONL() with mode=%s = %v, want %v", tt.mode, got, tt.needsJSONL)
@@ -1406,9 +1407,9 @@ func TestGetSovereigntyInvalid(t *testing.T) {
t.Fatalf("Initialize() returned error: %v", err)
}
// Set invalid sovereignty - should return empty
// Set invalid sovereignty - should return T1 (default) with warning
Set("federation.sovereignty", "T99")
if got := GetSovereignty(); got != "" {
t.Errorf("GetSovereignty() with invalid tier = %q, want empty (fallback)", got)
if got := GetSovereignty(); got != SovereigntyT1 {
t.Errorf("GetSovereignty() with invalid tier = %q, want %q (fallback)", got, SovereigntyT1)
}
}