From ce728d04ce300ee5baadb052a81df70651ea8ca1 Mon Sep 17 00:00:00 2001 From: matt wilkie Date: Wed, 22 Jul 2026 21:20:10 -0700 Subject: [PATCH] fix(init): use server-aware diagnostics (#4954) Route init-time database checks through one shared store so server-mode projects do not require a local .beads/dolt directory. Add a server-backed regression for the successful no-local-directory case. Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie --- cmd/bd/doctor.go | 12 ++++++-- cmd/bd/doctor_init_diagnostics_cgo_test.go | 32 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 cmd/bd/doctor_init_diagnostics_cgo_test.go diff --git a/cmd/bd/doctor.go b/cmd/bd/doctor.go index 9be970f4b..2e8b95b89 100644 --- a/cmd/bd/doctor.go +++ b/cmd/bd/doctor.go @@ -996,22 +996,28 @@ func runInitDiagnostics(path string) doctorResult { result.OverallOK = false } + // Open one shared store for the database-backed init checks. Server-mode + // workspaces may not have a local .beads/dolt directory, so the path-only + // checks would otherwise report a false missing database. + sharedStore := doctor.NewSharedStore(path) + defer sharedStore.Close() + // Check 2: Database version - dbCheck := convertWithCategory(doctor.CheckDatabaseVersion(path, Version), doctor.CategoryCore) + dbCheck := convertWithCategory(doctor.CheckDatabaseVersionWithStore(sharedStore, Version), doctor.CategoryCore) result.Checks = append(result.Checks, dbCheck) if dbCheck.Status == statusError { result.OverallOK = false } // Check 3: Schema compatibility - schemaCheck := convertWithCategory(doctor.CheckSchemaCompatibility(path), doctor.CategoryCore) + schemaCheck := convertWithCategory(doctor.CheckSchemaCompatibilityWithStore(sharedStore), doctor.CategoryCore) result.Checks = append(result.Checks, schemaCheck) if schemaCheck.Status == statusError { result.OverallOK = false } // Check 4: Permissions - permCheck := convertWithCategory(doctor.CheckPermissions(path), doctor.CategoryCore) + permCheck := convertWithCategory(doctor.CheckPermissionsWithStore(path, sharedStore), doctor.CategoryCore) result.Checks = append(result.Checks, permCheck) if permCheck.Status == statusError { result.OverallOK = false diff --git a/cmd/bd/doctor_init_diagnostics_cgo_test.go b/cmd/bd/doctor_init_diagnostics_cgo_test.go new file mode 100644 index 000000000..f6778e896 --- /dev/null +++ b/cmd/bd/doctor_init_diagnostics_cgo_test.go @@ -0,0 +1,32 @@ +//go:build cgo + +package main + +import ( + "os" + "path/filepath" + "testing" +) + +func TestRunInitDiagnosticsServerModeWithoutLocalDoltDir(t *testing.T) { + projectDir := t.TempDir() + doltPath := filepath.Join(projectDir, ".beads", "dolt") + store := newTestStoreIsolatedDB(t, doltPath, "initdiag") + if err := store.Close(); err != nil { + t.Fatalf("close setup store: %v", err) + } + + if info, err := os.Stat(doltPath); err == nil || !os.IsNotExist(err) { + t.Fatalf("expected no local .beads/dolt directory, got info=%v err=%v", info, err) + } + + result := runInitDiagnostics(projectDir) + for _, check := range result.Checks { + if check.Message == "No dolt database found" { + t.Fatalf("runInitDiagnostics reported false missing database: %+v", check) + } + } + if !result.OverallOK { + t.Fatalf("runInitDiagnostics OverallOK=false: %+v", result.Checks) + } +}