* fix(config): remove duplicate declarations between config.go and sync.go Commite82e15a8created sync.go with typed constants (SyncMode, ConflictStrategy, Sovereignty) but didn't remove the original untyped constants from config.go that were added in16f8c3d3. 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.
117 lines
3.4 KiB
Go
117 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestShow_ExternalRef(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping CLI test in short mode")
|
|
}
|
|
|
|
// Build bd binary
|
|
tmpBin := filepath.Join(t.TempDir(), "bd")
|
|
buildCmd := exec.Command("go", "build", "-o", tmpBin, "./")
|
|
buildCmd.Dir = "."
|
|
if out, err := buildCmd.CombinedOutput(); err != nil {
|
|
t.Fatalf("failed to build bd: %v\n%s", err, out)
|
|
}
|
|
|
|
// Create temp directory for test database
|
|
tmpDir := t.TempDir()
|
|
|
|
// Initialize beads
|
|
initCmd := exec.Command(tmpBin, "init", "--prefix", "test", "--quiet")
|
|
initCmd.Dir = tmpDir
|
|
if out, err := initCmd.CombinedOutput(); err != nil {
|
|
t.Fatalf("init failed: %v\n%s", err, out)
|
|
}
|
|
|
|
// Create issue with external ref
|
|
// Use --repo . to override auto-routing and create in the test directory
|
|
createCmd := exec.Command(tmpBin, "--no-daemon", "create", "External ref test", "-p", "1",
|
|
"--external-ref", "https://example.com/spec.md", "--json", "--repo", ".")
|
|
createCmd.Dir = tmpDir
|
|
createOut, err := createCmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("create failed: %v\n%s", err, createOut)
|
|
}
|
|
|
|
var issue map[string]interface{}
|
|
if err := json.Unmarshal(createOut, &issue); err != nil {
|
|
t.Fatalf("failed to parse create output: %v, output: %s", err, createOut)
|
|
}
|
|
id := issue["id"].(string)
|
|
|
|
// Show the issue and verify external ref is displayed
|
|
showCmd := exec.Command(tmpBin, "--no-daemon", "show", id)
|
|
showCmd.Dir = tmpDir
|
|
showOut, err := showCmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("show failed: %v\n%s", err, showOut)
|
|
}
|
|
|
|
out := string(showOut)
|
|
if !strings.Contains(out, "External:") {
|
|
t.Errorf("expected 'External:' in output, got: %s", out)
|
|
}
|
|
if !strings.Contains(out, "https://example.com/spec.md") {
|
|
t.Errorf("expected external ref URL in output, got: %s", out)
|
|
}
|
|
}
|
|
|
|
func TestShow_NoExternalRef(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping CLI test in short mode")
|
|
}
|
|
|
|
// Build bd binary
|
|
tmpBin := filepath.Join(t.TempDir(), "bd")
|
|
buildCmd := exec.Command("go", "build", "-o", tmpBin, "./")
|
|
buildCmd.Dir = "."
|
|
if out, err := buildCmd.CombinedOutput(); err != nil {
|
|
t.Fatalf("failed to build bd: %v\n%s", err, out)
|
|
}
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
// Initialize beads
|
|
initCmd := exec.Command(tmpBin, "init", "--prefix", "test", "--quiet")
|
|
initCmd.Dir = tmpDir
|
|
if out, err := initCmd.CombinedOutput(); err != nil {
|
|
t.Fatalf("init failed: %v\n%s", err, out)
|
|
}
|
|
|
|
// Create issue WITHOUT external ref
|
|
// Use --repo . to override auto-routing and create in the test directory
|
|
createCmd := exec.Command(tmpBin, "--no-daemon", "create", "No ref test", "-p", "1", "--json", "--repo", ".")
|
|
createCmd.Dir = tmpDir
|
|
createOut, err := createCmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("create failed: %v\n%s", err, createOut)
|
|
}
|
|
|
|
var issue map[string]interface{}
|
|
if err := json.Unmarshal(createOut, &issue); err != nil {
|
|
t.Fatalf("failed to parse create output: %v, output: %s", err, createOut)
|
|
}
|
|
id := issue["id"].(string)
|
|
|
|
// Show the issue - should NOT contain External Ref line
|
|
showCmd := exec.Command(tmpBin, "--no-daemon", "show", id)
|
|
showCmd.Dir = tmpDir
|
|
showOut, err := showCmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("show failed: %v\n%s", err, showOut)
|
|
}
|
|
|
|
out := string(showOut)
|
|
if strings.Contains(out, "External:") {
|
|
t.Errorf("expected no 'External:' line for issue without external ref, got: %s", out)
|
|
}
|
|
}
|