Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
693 lines
20 KiB
Go
693 lines
20 KiB
Go
//go:build cgo
|
|
|
|
package doctor
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/configfile"
|
|
)
|
|
|
|
func TestCheckFederationRemotesAPI_NonDoltBackend(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Write a config with sqlite backend
|
|
cfg := &configfile.Config{
|
|
Backend: "sqlite",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckFederationRemotesAPI(tmpDir)
|
|
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for non-Dolt backend, got %s", check.Status)
|
|
}
|
|
if !strings.Contains(check.Message, "N/A") {
|
|
t.Errorf("expected N/A message, got %q", check.Message)
|
|
}
|
|
if check.Category != CategoryFederation {
|
|
t.Errorf("expected CategoryFederation, got %q", check.Category)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationRemotesAPI_NoDoltDatabase(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Write a dolt backend config but don't create the dolt directory
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckFederationRemotesAPI(tmpDir)
|
|
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for missing dolt database, got %s", check.Status)
|
|
}
|
|
if !strings.Contains(check.Message, "no dolt database") {
|
|
t.Errorf("expected message about no dolt database, got %q", check.Message)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationRemotesAPI_ServerNotRunning(t *testing.T) {
|
|
// Isolate from orchestrator daemon which would be detected as a running server
|
|
t.Setenv("GT_ROOT", "")
|
|
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
doltDir := filepath.Join(beadsDir, "dolt")
|
|
if err := os.MkdirAll(doltDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Write a dolt backend config
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// No PID file exists, server is not running, no DB to query remotes from.
|
|
// The check should not crash and should return OK or a safe status.
|
|
check := CheckFederationRemotesAPI(tmpDir)
|
|
|
|
// Without a running server and no remotes queryable, should get OK
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for server not running (no remotes), got %s: %s", check.Status, check.Message)
|
|
}
|
|
}
|
|
|
|
func TestDoltServerConfig_SuppressesCLIAutoStartWithConfiguredPort(t *testing.T) {
|
|
t.Setenv("BEADS_TEST_MODE", "")
|
|
t.Setenv("BEADS_DOLT_AUTO_START", "")
|
|
t.Setenv("BEADS_DOLT_SERVER_MODE", "")
|
|
t.Setenv("BEADS_DOLT_SHARED_SERVER", "")
|
|
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
DoltDatabase: "beads_test",
|
|
DoltServerPort: 12345,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
result := doltServerConfig(beadsDir, filepath.Join(beadsDir, "dolt"))
|
|
if result.AutoStart {
|
|
t.Fatal("doltServerConfig should suppress CLI auto-start with an external configured server port")
|
|
}
|
|
}
|
|
|
|
func TestDoltServerConfig_EnablesCLIAutoStartWithoutConfiguredPort(t *testing.T) {
|
|
t.Setenv("BEADS_TEST_MODE", "")
|
|
t.Setenv("BEADS_DOLT_AUTO_START", "")
|
|
t.Setenv("BEADS_DOLT_SERVER_MODE", "")
|
|
t.Setenv("BEADS_DOLT_SHARED_SERVER", "")
|
|
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
DoltDatabase: "beads_test",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
result := doltServerConfig(beadsDir, filepath.Join(beadsDir, "dolt"))
|
|
if !result.AutoStart {
|
|
t.Fatal("doltServerConfig should enable CLI auto-start for owned standalone configs")
|
|
}
|
|
}
|
|
|
|
func TestDoltServerConfig_HonorsAutoStartOptOut(t *testing.T) {
|
|
t.Setenv("BEADS_TEST_MODE", "")
|
|
t.Setenv("BEADS_DOLT_AUTO_START", "0")
|
|
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
DoltDatabase: "beads_test",
|
|
DoltServerPort: 12345,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
result := doltServerConfig(beadsDir, filepath.Join(beadsDir, "dolt"))
|
|
if result.AutoStart {
|
|
t.Fatal("doltServerConfig should honor BEADS_DOLT_AUTO_START=0")
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationRemotesAPI_PidFileInBeadsDir(t *testing.T) {
|
|
// Isolate from orchestrator daemon which would be detected as a running server
|
|
t.Setenv("GT_ROOT", "")
|
|
|
|
// Verify the fix: PID file should be looked for in beadsDir, not doltPath.
|
|
// The old code had: filepath.Join(doltPath, "dolt-server.pid") which was wrong.
|
|
// The fix uses doltserver.IsRunning(beadsDir) which looks in beadsDir.
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
doltDir := filepath.Join(beadsDir, "dolt")
|
|
if err := os.MkdirAll(doltDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Write a dolt backend config
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Create a PID file in the WRONG location (doltPath) - this is where the
|
|
// old buggy code looked. The new code should NOT detect this as server running.
|
|
wrongPidFile := filepath.Join(doltDir, "dolt-server.pid")
|
|
if err := os.WriteFile(wrongPidFile, []byte("99999"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckFederationRemotesAPI(tmpDir)
|
|
|
|
// Server should NOT be detected as running (PID file is in wrong location)
|
|
if check.Status == StatusError && strings.Contains(check.Message, "not accessible") {
|
|
t.Errorf("PID file in doltPath should not be detected: old bug not fixed")
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationPeerConnectivity_NonDoltBackend(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: "sqlite",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckFederationPeerConnectivity(tmpDir)
|
|
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for non-Dolt backend, got %s", check.Status)
|
|
}
|
|
if !strings.Contains(check.Message, "N/A") {
|
|
t.Errorf("expected N/A message, got %q", check.Message)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationPeerConnectivity_NoDoltDatabase(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckFederationPeerConnectivity(tmpDir)
|
|
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for missing dolt database, got %s", check.Status)
|
|
}
|
|
if !strings.Contains(check.Message, "no dolt database") {
|
|
t.Errorf("expected message about no dolt database, got %q", check.Message)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationSyncStaleness_NonDoltBackend(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: "sqlite",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckFederationSyncStaleness(tmpDir)
|
|
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for non-Dolt backend, got %s", check.Status)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationConflicts_NonDoltBackend(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: "sqlite",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckFederationConflicts(tmpDir)
|
|
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for non-Dolt backend, got %s", check.Status)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationConflicts_NoDoltDatabase(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckFederationConflicts(tmpDir)
|
|
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for missing dolt database, got %s", check.Status)
|
|
}
|
|
}
|
|
|
|
func TestCheckDoltServerModeMismatch_NonDoltBackend(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: "sqlite",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckDoltServerModeMismatch(tmpDir)
|
|
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for non-Dolt backend, got %s", check.Status)
|
|
}
|
|
}
|
|
|
|
func TestCheckDoltServerModeMismatch_NoDoltDatabase(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckDoltServerModeMismatch(tmpDir)
|
|
|
|
if check.Status != StatusOK {
|
|
t.Errorf("expected StatusOK for missing dolt database, got %s", check.Status)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationRemotesAPI_ConfiguredPort(t *testing.T) {
|
|
// Verify the fix: remotesapi port should be read from config, not hardcoded.
|
|
// We can't test the actual port check (needs a running server), but we can
|
|
// verify the config reading logic.
|
|
cfg := &configfile.Config{
|
|
DoltRemotesAPIPort: 9090,
|
|
}
|
|
|
|
port := cfg.GetDoltRemotesAPIPort()
|
|
if port != 9090 {
|
|
t.Errorf("expected port 9090 from config, got %d", port)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationRemotesAPI_DefaultPort(t *testing.T) {
|
|
cfg := &configfile.Config{}
|
|
|
|
port := cfg.GetDoltRemotesAPIPort()
|
|
if port != configfile.DefaultDoltRemotesAPIPort {
|
|
t.Errorf("expected default port %d, got %d", configfile.DefaultDoltRemotesAPIPort, port)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationRemotesAPI_EnvOverridesConfig(t *testing.T) {
|
|
t.Setenv("BEADS_DOLT_REMOTESAPI_PORT", "7777")
|
|
|
|
cfg := &configfile.Config{
|
|
DoltRemotesAPIPort: 9090,
|
|
}
|
|
|
|
port := cfg.GetDoltRemotesAPIPort()
|
|
if port != 7777 {
|
|
t.Errorf("expected env override port 7777, got %d", port)
|
|
}
|
|
}
|
|
|
|
func TestCheckFederationChecks_CategoryIsFederation(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Write a sqlite config so all checks return quickly with N/A
|
|
cfg := &configfile.Config{
|
|
Backend: "sqlite",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
checks := []struct {
|
|
name string
|
|
fn func(string) DoctorCheck
|
|
}{
|
|
{"RemotesAPI", CheckFederationRemotesAPI},
|
|
{"PeerConnectivity", CheckFederationPeerConnectivity},
|
|
{"SyncStaleness", CheckFederationSyncStaleness},
|
|
{"Conflicts", CheckFederationConflicts},
|
|
{"LegacyCLIRemotes", CheckLegacyCLIRemotes},
|
|
{"ServerModeMismatch", CheckDoltServerModeMismatch},
|
|
}
|
|
|
|
for _, tc := range checks {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
check := tc.fn(tmpDir)
|
|
if check.Category != CategoryFederation {
|
|
t.Errorf("%s: expected CategoryFederation, got %q", tc.name, check.Category)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDoltServerConfig_PopulatesFromConfig(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
doltDir := filepath.Join(beadsDir, "dolt")
|
|
if err := os.MkdirAll(doltDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
DoltServerHost: "192.168.1.10",
|
|
DoltServerUser: "testuser",
|
|
DoltDatabase: "mydb",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
result := doltServerConfig(beadsDir, doltDir)
|
|
|
|
if result.Path != doltDir {
|
|
t.Errorf("expected Path %q, got %q", doltDir, result.Path)
|
|
}
|
|
if !result.ReadOnly {
|
|
t.Error("expected ReadOnly=true")
|
|
}
|
|
if result.Database != "mydb" {
|
|
t.Errorf("expected Database 'mydb', got %q", result.Database)
|
|
}
|
|
if result.ServerHost != "192.168.1.10" {
|
|
t.Errorf("expected ServerHost '192.168.1.10', got %q", result.ServerHost)
|
|
}
|
|
if result.ServerUser != "testuser" {
|
|
t.Errorf("expected ServerUser 'testuser', got %q", result.ServerUser)
|
|
}
|
|
}
|
|
|
|
func TestCheckLegacyCLIRemotesDetectsServerRootOnlyRemote(t *testing.T) {
|
|
port := doctorTestServerPort()
|
|
if port == 0 {
|
|
t.Skip("Dolt test server not available")
|
|
}
|
|
if _, err := exec.LookPath("dolt"); err != nil {
|
|
t.Skipf("dolt binary not available: %v", err)
|
|
}
|
|
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
doltDir := filepath.Join(beadsDir, "dolt")
|
|
cliDir := filepath.Join(doltDir, testSharedDB)
|
|
if err := os.MkdirAll(cliDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
DoltMode: "server",
|
|
DoltServerHost: "127.0.0.1",
|
|
DoltServerPort: port,
|
|
DoltDatabase: testSharedDB,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
runDoctorTestCmd(t, doltDir, "dolt", "init", "--name", "test", "--email", "test@test.com")
|
|
runDoctorTestCmd(t, cliDir, "dolt", "init", "--name", "test", "--email", "test@test.com")
|
|
rootOnlyURL := "file:///tmp/root-only-remote.git"
|
|
runDoctorTestCmd(t, doltDir, "dolt", "remote", "add", "rootonly", rootOnlyURL)
|
|
|
|
check := CheckLegacyCLIRemotes(tmpDir)
|
|
if check.Status != StatusWarning {
|
|
t.Fatalf("expected StatusWarning for root-only legacy remote, got %s: %s\nDetail: %s", check.Status, check.Message, check.Detail)
|
|
}
|
|
if !strings.Contains(check.Detail, "Dolt server root") {
|
|
t.Fatalf("expected detail to identify Dolt server root, got: %s", check.Detail)
|
|
}
|
|
if !strings.Contains(check.Detail, "rootonly="+rootOnlyURL) &&
|
|
!strings.Contains(check.Detail, "rootonly=git+"+rootOnlyURL) {
|
|
t.Fatalf("expected root-only remote in detail, got: %s", check.Detail)
|
|
}
|
|
}
|
|
|
|
func TestDoltDatabaseName_Default(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// No config file — should fall back to default
|
|
name := doltDatabaseName(beadsDir)
|
|
if name != configfile.DefaultDoltDatabase {
|
|
t.Errorf("expected default %q, got %q", configfile.DefaultDoltDatabase, name)
|
|
}
|
|
}
|
|
|
|
func TestDoltDatabaseName_FromConfig(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
DoltDatabase: "custom_db",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
name := doltDatabaseName(beadsDir)
|
|
if name != "custom_db" {
|
|
t.Errorf("expected 'custom_db', got %q", name)
|
|
}
|
|
}
|
|
|
|
func runDoctorTestCmd(t *testing.T, dir string, name string, args ...string) {
|
|
t.Helper()
|
|
cmd := exec.Command(name, args...)
|
|
cmd.Dir = dir
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
|
t.Fatalf("%s %v failed in %s: %v\nOutput: %s", name, args, dir, err, out)
|
|
}
|
|
}
|
|
|
|
// TestCheckFederationRemotesAPI_ServerRunningNoPeers verifies that when the
|
|
// Dolt server is running but no federation peers are configured, the check
|
|
// returns StatusOK instead of erroring about the remotesapi port.
|
|
// This is the bug described in GH#2273.
|
|
func TestCheckFederationRemotesAPI_ServerRunningNoPeers(t *testing.T) {
|
|
// Isolate from orchestrator daemon — we'll simulate "server running" via
|
|
// a standalone PID file pointing at a real dolt process on the host.
|
|
t.Setenv("GT_ROOT", "")
|
|
|
|
// Find a running dolt process on the host to use for the PID file.
|
|
// This makes doltserver.IsRunning() return true via the standalone path.
|
|
doltPIDs := findDoltPIDs(t)
|
|
if len(doltPIDs) == 0 {
|
|
t.Skip("no host dolt process running (needed to simulate server-running state)")
|
|
}
|
|
|
|
port := doctorTestServerPort()
|
|
if port == 0 {
|
|
t.Skip("Dolt test server not available")
|
|
}
|
|
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
doltDir := filepath.Join(beadsDir, "dolt")
|
|
if err := os.MkdirAll(doltDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Write PID file so doltserver.IsRunning detects "server running"
|
|
pidFile := filepath.Join(beadsDir, "dolt-server.pid")
|
|
if err := os.WriteFile(pidFile, []byte(doltPIDs[0]), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Write config pointing at the testcontainers server with the shared DB.
|
|
// BEADS_DOLT_PORT (set by TestMain) routes dolt.New() to testcontainers.
|
|
cfg := &configfile.Config{
|
|
Backend: configfile.BackendDolt,
|
|
DoltDatabase: testSharedDB,
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckFederationRemotesAPI(tmpDir)
|
|
|
|
// With a running server and no federation peers, the fix returns OK
|
|
// instead of the old false error about remotesapi port 8080.
|
|
if check.Status == StatusError {
|
|
t.Errorf("GH#2273: server running with no peers should not report error, got: %s: %s\n Detail: %s",
|
|
check.Status, check.Message, check.Detail)
|
|
}
|
|
if check.Status == StatusOK && !strings.Contains(check.Message, "no federation peers") {
|
|
t.Logf("got StatusOK with message: %s (expected 'no federation peers configured')", check.Message)
|
|
}
|
|
}
|
|
|
|
// findDoltPIDs returns PIDs of running dolt sql-server processes on the host.
|
|
func findDoltPIDs(t *testing.T) []string {
|
|
t.Helper()
|
|
out, err := exec.Command("pgrep", "-f", "dolt sql-server").Output()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
var pids []string
|
|
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
|
|
if line = strings.TrimSpace(line); line != "" {
|
|
pids = append(pids, line)
|
|
}
|
|
}
|
|
return pids
|
|
}
|
|
|
|
// TestCheckFederationRemotesAPI_AllCheckNames verifies all federation checks
|
|
// return meaningful check names (not empty strings).
|
|
func TestCheckFederationRemotesAPI_AllCheckNames(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg := &configfile.Config{
|
|
Backend: "sqlite",
|
|
}
|
|
data, _ := json.Marshal(cfg)
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
checks := []struct {
|
|
fn func(string) DoctorCheck
|
|
wantName string
|
|
}{
|
|
{CheckFederationRemotesAPI, "Federation remotesapi"},
|
|
{CheckFederationPeerConnectivity, "Peer Connectivity"},
|
|
{CheckFederationSyncStaleness, "Sync Staleness"},
|
|
{CheckFederationConflicts, "Federation Conflicts"},
|
|
{CheckLegacyCLIRemotes, "Dolt Remote Migration"},
|
|
{CheckDoltServerModeMismatch, "Dolt Mode"},
|
|
}
|
|
|
|
for _, tc := range checks {
|
|
check := tc.fn(tmpDir)
|
|
if check.Name != tc.wantName {
|
|
t.Errorf("expected Name %q, got %q", tc.wantName, check.Name)
|
|
}
|
|
}
|
|
}
|