diff --git a/.github/scripts/embedded-test-shard.sh b/.github/scripts/embedded-test-shard.sh index e3bcb82f3..62e2610db 100755 --- a/.github/scripts/embedded-test-shard.sh +++ b/.github/scripts/embedded-test-shard.sh @@ -61,7 +61,7 @@ if [ -x "$CMD_BINARY" ]; then "$@" else echo "Warning: pre-built test binary not found at $CMD_BINARY, falling back to go test" - exec go test -tags embeddeddolt -v -race -count=1 -timeout 20m \ + exec go test -v -race -count=1 -timeout 20m \ -run "$RUN_REGEX" \ "$@" \ ./cmd/bd/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eaab53a4d..74a31cae4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,8 +29,13 @@ jobs: with: go-version-file: 'go.mod' + - name: Install ICU4C + run: | + sudo apt-get update + sudo apt-get install -y libicu-dev + - name: Build bd - run: CGO_ENABLED=0 go build -o bd ./cmd/bd/ + run: go build -o bd ./cmd/bd/ - name: Validate docs against CLI run: ./scripts/check-doc-flags.sh ./bd @@ -119,11 +124,11 @@ jobs: gotestsum \ --junitfile junit.xml \ --format testdox \ - -- -race -short -coverprofile=coverage.out ./... + -- -race -short -coverprofile=coverage.out -skip '^TestEmbedded' ./... - name: Test if: ${{ !matrix.coverage }} - run: go test ${{ matrix.test-flags }} ./... + run: go test ${{ matrix.test-flags }} -skip '^TestEmbedded' ./... - name: Upload coverage to Codecov if: matrix.coverage && !cancelled() @@ -142,10 +147,9 @@ jobs: report_type: test_results fail_ci_if_error: false - # Embedded Dolt tests - runs the embeddeddolt build tag tests - # These test the in-process Dolt engine (no server required) + # Embedded Dolt tests - test the in-process Dolt engine (no server required) # - # Split into: build → storage tests + 4 parallel cmd test shards. + # Split into: build → storage tests + parallel cmd test shards. # Adding new *_embedded_test.go files auto-distributes via hash sharding. build-embedded: @@ -165,13 +169,13 @@ jobs: sudo apt-get install -y libicu-dev - name: Build embedded bd binary - run: go build -tags embeddeddolt -race -o /tmp/bd-embedded-test ./cmd/bd/ + run: go build -race -o /tmp/bd-embedded-test ./cmd/bd/ - name: Build embedded storage test binary - run: go test -tags embeddeddolt -race -c -o /tmp/embeddeddolt-test ./internal/storage/embeddeddolt/ + run: go test -race -c -o /tmp/embeddeddolt-test ./internal/storage/embeddeddolt/ - name: Build embedded cmd test binary - run: go test -tags embeddeddolt -race -c -o /tmp/bd-cmd-test ./cmd/bd/ + run: go test -race -c -o /tmp/bd-cmd-test ./cmd/bd/ - name: Upload binaries uses: actions/upload-artifact@v7 @@ -254,10 +258,9 @@ jobs: # Windows smoke tests only - full test suite times out (see bd-bmev) # Linux/macOS run comprehensive tests; Windows just verifies binary works # - # ICU is NOT required on Windows: - # - go-mysql-server's regex_pure.go (via -tags gms_pure_go) uses Go stdlib regexp - # - go-icu-regex's regex_windows.go also uses Go stdlib regexp (build tag: windows) - # - The only CGO deps on Windows are runtime/cgo and gozstd (bundled C source) + # Windows uses -tags gms_pure_go to avoid the ICU regex dependency. + # go-icu-regex's regex_windows.go also uses Go stdlib regexp (build tag: windows). + # CGO is still required for gozstd (bundled C source) and the embedded dolt engine. test-windows: name: Test (Windows - smoke) runs-on: windows-latest @@ -274,10 +277,8 @@ jobs: git config --global user.name "CI Bot" git config --global user.email "ci@beads.test" - - name: Build (no CGO, pure Go) - run: | - $env:CGO_ENABLED="0" - go build -v -tags gms_pure_go -o bd.exe ./cmd/bd + - name: Build (pure Go regex) + run: go build -v -tags gms_pure_go -o bd.exe ./cmd/bd - name: Smoke test - version run: ./bd.exe version diff --git a/.goreleaser.yml b/.goreleaser.yml index ccae6862d..2008d234b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -59,7 +59,8 @@ builds: main: ./cmd/bd binary: bd env: - - CGO_ENABLED=0 + - CGO_ENABLED=1 + - CC=/tmp/zigcc/cc-aarch64-linux-android tags: - gms_pure_go goos: @@ -77,7 +78,8 @@ builds: main: ./cmd/bd binary: bd env: - - CGO_ENABLED=0 + - CGO_ENABLED=1 + - CC=/tmp/zigcc/cc-x86_64-macos tags: - gms_pure_go - netgo @@ -91,12 +93,16 @@ builds: - -X main.Build={{.ShortCommit}} - -X main.Commit={{.Commit}} - -X main.Branch={{.Branch}} + hooks: + post: + - ./scripts/verify-cgo.sh "{{ .Path }}" - id: bd-darwin-arm64 main: ./cmd/bd binary: bd env: - - CGO_ENABLED=0 + - CGO_ENABLED=1 + - CC=/tmp/zigcc/cc-aarch64-macos tags: - gms_pure_go - netgo @@ -110,6 +116,9 @@ builds: - -X main.Build={{.ShortCommit}} - -X main.Commit={{.Commit}} - -X main.Branch={{.Branch}} + hooks: + post: + - ./scripts/verify-cgo.sh "{{ .Path }}" - id: bd-windows-amd64 main: ./cmd/bd @@ -168,7 +177,8 @@ builds: main: ./cmd/bd binary: bd env: - - CGO_ENABLED=0 + - CGO_ENABLED=1 + - CC=/tmp/zigcc/cc-x86_64-freebsd tags: - gms_pure_go goos: diff --git a/cmd/bd/admin.go b/cmd/bd/admin.go index 6cba5486d..8f1ec4437 100644 --- a/cmd/bd/admin.go +++ b/cmd/bd/admin.go @@ -11,7 +11,7 @@ var adminCmd = &cobra.Command{ GroupID: "advanced", Short: "Administrative commands for database maintenance", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - if isEmbeddedDolt { + if isEmbeddedMode() { return fmt.Errorf("'bd admin' is not yet supported in embedded mode") } return nil diff --git a/cmd/bd/ado.go b/cmd/bd/ado.go index fa0b2f269..30123184b 100644 --- a/cmd/bd/ado.go +++ b/cmd/bd/ado.go @@ -694,7 +694,7 @@ func runADOSync(cmd *cobra.Command, _ []string) error { } // Embedded mode: flush Dolt commit after sync writes. - if isEmbeddedDolt && !adoSyncDryRun && store != nil { + if isEmbeddedMode() && !adoSyncDryRun && store != nil { if _, commitErr := store.CommitPending(rootCtx, actor); commitErr != nil { return fmt.Errorf("failed to commit: %w", commitErr) } diff --git a/cmd/bd/assign.go b/cmd/bd/assign.go index 3ca87b5ab..6b6cd95cd 100644 --- a/cmd/bd/assign.go +++ b/cmd/bd/assign.go @@ -57,7 +57,7 @@ Examples: } // Flush Dolt commit for embedded mode - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/backup_embedded_test.go b/cmd/bd/backup_embedded_test.go index f2b8a863e..db35b5d5c 100644 --- a/cmd/bd/backup_embedded_test.go +++ b/cmd/bd/backup_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/blocked_embedded_test.go b/cmd/bd/blocked_embedded_test.go index cb6e493b5..241fe51ec 100644 --- a/cmd/bd/blocked_embedded_test.go +++ b/cmd/bd/blocked_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/bootstrap.go b/cmd/bd/bootstrap.go index 20c31cf59..da1247702 100644 --- a/cmd/bd/bootstrap.go +++ b/cmd/bd/bootstrap.go @@ -112,7 +112,7 @@ func detectBootstrapAction(beadsDir string, cfg *configfile.Config) BootstrapPla // Check for existing database (path differs between server and embedded mode) var dbPath string - if isEmbeddedDolt { + if isEmbeddedMode() { dbPath = filepath.Join(beadsDir, "embeddeddolt") } else { dbPath = doltserver.ResolveDoltDir(beadsDir) @@ -177,7 +177,7 @@ func printBootstrapPlan(plan BootstrapPlan) { switch plan.Action { case "none": fmt.Printf("✓ Database already exists: %s\n", plan.BeadsDir) - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Printf(" Nothing to do.\n") } else { fmt.Printf(" Nothing to do. Use 'bd doctor' to check health.\n") @@ -332,7 +332,7 @@ func executeJSONLImportAction(ctx context.Context, plan BootstrapPlan, cfg *conf func executeSyncAction(ctx context.Context, plan BootstrapPlan, cfg *configfile.Config) error { dbName := cfg.GetDoltDatabase() - if isEmbeddedDolt { + if isEmbeddedMode() { // Embedded mode: open a connection to the embedded engine and use // DOLT_CLONE to create the database from the remote URL. dataDir := filepath.Join(plan.BeadsDir, "embeddeddolt") diff --git a/cmd/bd/bootstrap_embedded_test.go b/cmd/bd/bootstrap_embedded_test.go index 6411b3770..c6d20fe01 100644 --- a/cmd/bd/bootstrap_embedded_test.go +++ b/cmd/bd/bootstrap_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/branch_embedded_test.go b/cmd/bd/branch_embedded_test.go index a0e804e34..3ced21cff 100644 --- a/cmd/bd/branch_embedded_test.go +++ b/cmd/bd/branch_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/children_embedded_test.go b/cmd/bd/children_embedded_test.go index d0992d13b..4db1f399c 100644 --- a/cmd/bd/children_embedded_test.go +++ b/cmd/bd/children_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/close.go b/cmd/bd/close.go index 02e5cd79b..ac293cc26 100644 --- a/cmd/bd/close.go +++ b/cmd/bd/close.go @@ -269,7 +269,7 @@ create, update, show, or close operation).`, // Embedded mode: flush Dolt commit. DoltStore commits // inline during CloseIssue so this is only needed for EmbeddedDoltStore. - if isEmbeddedDolt && closedCount > 0 && store != nil { + if isEmbeddedMode() && closedCount > 0 && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/close_embedded_test.go b/cmd/bd/close_embedded_test.go index a51756154..883df30b2 100644 --- a/cmd/bd/close_embedded_test.go +++ b/cmd/bd/close_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/comment.go b/cmd/bd/comment.go index 85037df65..4bd7e1982 100644 --- a/cmd/bd/comment.go +++ b/cmd/bd/comment.go @@ -89,7 +89,7 @@ Examples: } // Flush Dolt commit for embedded mode - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/comment_promote_embedded_test.go b/cmd/bd/comment_promote_embedded_test.go index 0b27c7aea..2250199eb 100644 --- a/cmd/bd/comment_promote_embedded_test.go +++ b/cmd/bd/comment_promote_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/comments.go b/cmd/bd/comments.go index 9b1607306..a7bda96ca 100644 --- a/cmd/bd/comments.go +++ b/cmd/bd/comments.go @@ -140,7 +140,7 @@ Examples: } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt { + if isEmbeddedMode() { if _, err := store.CommitPending(ctx, author); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/comments_cli_embedded_test.go b/cmd/bd/comments_cli_embedded_test.go index f1876599d..43bd05a96 100644 --- a/cmd/bd/comments_cli_embedded_test.go +++ b/cmd/bd/comments_cli_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/compact_embedded_test.go b/cmd/bd/compact_embedded_test.go index 9560373fd..4700276ca 100644 --- a/cmd/bd/compact_embedded_test.go +++ b/cmd/bd/compact_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/config_embedded_test.go b/cmd/bd/config_embedded_test.go index 9217ef03d..407e45b15 100644 --- a/cmd/bd/config_embedded_test.go +++ b/cmd/bd/config_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/context.go b/cmd/bd/context.go index 2a2655056..1e0c08d32 100644 --- a/cmd/bd/context.go +++ b/cmd/bd/context.go @@ -29,6 +29,9 @@ type CommandContext struct { Verbose bool Quiet bool + // Storage mode — true when connected to an external dolt sql-server. + ServerMode bool + // Runtime state Store storage.DoltStorage RootCtx context.Context diff --git a/cmd/bd/context_embedded_test.go b/cmd/bd/context_embedded_test.go index 09d1cf833..db60643d1 100644 --- a/cmd/bd/context_embedded_test.go +++ b/cmd/bd/context_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/count_embedded_test.go b/cmd/bd/count_embedded_test.go index e740441c6..337db2224 100644 --- a/cmd/bd/count_embedded_test.go +++ b/cmd/bd/count_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/create.go b/cmd/bd/create.go index ba2bb039b..99dcbfa66 100644 --- a/cmd/bd/create.go +++ b/cmd/bd/create.go @@ -706,7 +706,7 @@ var createCmd = &cobra.Command{ // a separate commit. In EmbeddedDoltStore mode, CreateIssue writes // to the working set without a Dolt commit, so we always commit // everything together at the end. - if isEmbeddedDolt || postCreateWrites { + if isEmbeddedMode() || postCreateWrites { commitMsg := fmt.Sprintf("bd: create %s", issue.ID) if err := store.Commit(ctx, commitMsg); err != nil && !isDoltNothingToCommit(err) { WarnError("failed to commit: %v", err) diff --git a/cmd/bd/create_embedded_test.go b/cmd/bd/create_embedded_test.go index 90d130400..a42927f2f 100644 --- a/cmd/bd/create_embedded_test.go +++ b/cmd/bd/create_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/defer.go b/cmd/bd/defer.go index 91c5c2f54..f078e0094 100644 --- a/cmd/bd/defer.go +++ b/cmd/bd/defer.go @@ -100,7 +100,7 @@ Examples: } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && len(args) > 0 && store != nil { + if isEmbeddedMode() && len(args) > 0 && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } diff --git a/cmd/bd/defer_embedded_test.go b/cmd/bd/defer_embedded_test.go index c47c5b6a7..c84a867c6 100644 --- a/cmd/bd/defer_embedded_test.go +++ b/cmd/bd/defer_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/delete.go b/cmd/bd/delete.go index 8881841a6..97b021e05 100644 --- a/cmd/bd/delete.go +++ b/cmd/bd/delete.go @@ -216,8 +216,8 @@ Force: Delete and orphan dependents } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && activeStore != nil { - if _, err := activeStore.CommitPending(ctx, actor); err != nil { + if isEmbeddedMode() && store != nil { + if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } } @@ -349,7 +349,7 @@ func deleteBatch(_ *cobra.Command, issueIDs []string, force bool, dryRun bool, c updatedCount := updateTextReferencesInIssues(ctx, issueIDs, connectedIssues) // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } @@ -490,7 +490,7 @@ func deleteBatchFallback(issueIDs []string, force bool, dryRun bool, cascade boo updatedCount := updateTextReferencesInIssues(ctx, issueIDs, connectedIssues) // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, getActorWithGit()); err != nil { FatalError("failed to commit: %v", err) } diff --git a/cmd/bd/delete_embedded_test.go b/cmd/bd/delete_embedded_test.go index 71f4b67f1..5368c12e4 100644 --- a/cmd/bd/delete_embedded_test.go +++ b/cmd/bd/delete_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/dep.go b/cmd/bd/dep.go index f619018c8..003b25cca 100644 --- a/cmd/bd/dep.go +++ b/cmd/bd/dep.go @@ -151,7 +151,7 @@ Examples: // Check for cycles after adding dependency warnIfCyclesExist(fromStore) - if isEmbeddedDolt && fromStore != nil { + if isEmbeddedMode() && fromStore != nil { if _, err := fromStore.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } @@ -298,7 +298,7 @@ Examples: // Check for cycles after adding dependency warnIfCyclesExist(fromStore) - if isEmbeddedDolt && fromStore != nil { + if isEmbeddedMode() && fromStore != nil { if _, err := fromStore.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } @@ -493,7 +493,7 @@ var depRemoveCmd = &cobra.Command{ FatalErrorRespectJSON("%v", err) } - if isEmbeddedDolt && fromStore != nil { + if isEmbeddedMode() && fromStore != nil { if _, err := fromStore.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/dep_embedded_test.go b/cmd/bd/dep_embedded_test.go index 55f83731e..493a85781 100644 --- a/cmd/bd/dep_embedded_test.go +++ b/cmd/bd/dep_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/diff_embedded_test.go b/cmd/bd/diff_embedded_test.go index 176cbc28e..1cbce874d 100644 --- a/cmd/bd/diff_embedded_test.go +++ b/cmd/bd/diff_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/doctor.go b/cmd/bd/doctor.go index 4a50f35a7..d2cf75409 100644 --- a/cmd/bd/doctor.go +++ b/cmd/bd/doctor.go @@ -185,7 +185,7 @@ Examples: bd doctor --migration=post # Validate Dolt migration completed bd doctor --migration=pre --json # Machine-parseable migration validation`, Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd doctor' is not yet supported in embedded mode") os.Exit(1) } diff --git a/cmd/bd/dolt.go b/cmd/bd/dolt.go index 929f45c85..392927c7e 100644 --- a/cmd/bd/dolt.go +++ b/cmd/bd/dolt.go @@ -75,7 +75,7 @@ var doltShowCmd = &cobra.Command{ Use: "show", Short: "Show current Dolt configuration with connection status", Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd dolt show' is not supported in embedded mode (no Dolt server)") os.Exit(1) } @@ -104,7 +104,7 @@ Examples: bd dolt set data-dir /home/user/.beads-dolt/myproject`, Args: cobra.ExactArgs(2), Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd dolt set' is not supported in embedded mode (no Dolt server)") os.Exit(1) } @@ -126,7 +126,7 @@ This verifies that: Use this before switching to server mode to ensure the server is running.`, Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd dolt test' is not supported in embedded mode (no Dolt server)") os.Exit(1) } @@ -285,7 +285,7 @@ project path. PID and logs are stored in .beads/. The server auto-starts transparently when needed, so manual start is rarely required. Use this command for explicit control or diagnostics.`, Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd dolt start' is not supported in embedded mode (no Dolt server)") os.Exit(1) } @@ -323,7 +323,7 @@ var doltStopCmd = &cobra.Command{ This sends a graceful shutdown signal. The server will restart automatically on the next bd command unless auto-start is disabled.`, Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd dolt stop' is not supported in embedded mode (no Dolt server)") os.Exit(1) } @@ -350,7 +350,7 @@ var doltStatusCmd = &cobra.Command{ Displays whether the server is running, its PID, port, and data directory.`, Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd dolt status' is not supported in embedded mode (no Dolt server)") os.Exit(1) } @@ -404,7 +404,7 @@ In standalone mode, only dolt sql-server processes using the current project's Dolt data directory are eligible for cleanup. Other projects' servers are preserved.`, Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd dolt killall' is not supported in embedded mode (no Dolt server)") os.Exit(1) } @@ -449,7 +449,7 @@ Stale database prefixes: testdb_*, doctest_*, doctortest_*, beads_pt*, beads_vr* These waste server memory and can degrade performance under concurrent load. Use --dry-run to see what would be dropped without actually dropping.`, Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd dolt clean-databases' is not supported in embedded mode (no Dolt server)") os.Exit(1) } @@ -658,7 +658,7 @@ var doltRemoteAddCmd = &cobra.Command{ // In embedded mode, SQL and CLI operate on the same directory, // so the SQL add already wrote the remote config — skip CLI. cliFailed := false - if !isEmbeddedDolt && cliURL != url { + if !isEmbeddedMode() && cliURL != url { if err := doltutil.AddCLIRemote(dbPath, name, url); err != nil { cliFailed = true // Non-fatal: SQL remote was added successfully @@ -792,7 +792,7 @@ var doltRemoteListCmd = &cobra.Command{ fmt.Printf("\n%s Could not read CLI remotes: %v\n", ui.RenderWarn("⚠"), cliErr) } if hasDiscrepancy { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Printf("\n%s Remote discrepancies detected.\n", ui.RenderWarn("⚠")) } else { fmt.Printf("\n%s Remote discrepancies detected. Run 'bd doctor --fix' to resolve.\n", ui.RenderWarn("⚠")) @@ -857,7 +857,7 @@ var doltRemoteRemoveCmd = &cobra.Command{ // In embedded mode, SQL and CLI operate on the same directory, // so the SQL remove already cleared the remote config — skip CLI. cliRemoveFailed := false - if !isEmbeddedDolt && cliURL != "" { + if !isEmbeddedMode() && cliURL != "" { if err := doltutil.RemoveCLIRemote(dbPath, name); err != nil { cliRemoveFailed = true fmt.Fprintf(os.Stderr, "Warning: SQL remote removed but CLI remote failed: %v\n", err) diff --git a/cmd/bd/dolt_embedded_test.go b/cmd/bd/dolt_embedded_test.go index 75a46fe24..6f60cabce 100644 --- a/cmd/bd/dolt_embedded_test.go +++ b/cmd/bd/dolt_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/duplicate.go b/cmd/bd/duplicate.go index f690498cb..eb9db06fd 100644 --- a/cmd/bd/duplicate.go +++ b/cmd/bd/duplicate.go @@ -105,7 +105,7 @@ func runDuplicate(cmd *cobra.Command, args []string) error { return fmt.Errorf("failed to close duplicate: %w", err) } - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { return fmt.Errorf("failed to commit: %w", err) } @@ -173,7 +173,7 @@ func runSupersede(cmd *cobra.Command, args []string) error { return fmt.Errorf("failed to close superseded issue: %w", err) } - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { return fmt.Errorf("failed to commit: %w", err) } diff --git a/cmd/bd/duplicate_embedded_test.go b/cmd/bd/duplicate_embedded_test.go index 2ef36db49..d5e7c6c0a 100644 --- a/cmd/bd/duplicate_embedded_test.go +++ b/cmd/bd/duplicate_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/duplicates.go b/cmd/bd/duplicates.go index f6bed248c..c578a9e27 100644 --- a/cmd/bd/duplicates.go +++ b/cmd/bd/duplicates.go @@ -90,7 +90,7 @@ Example: } } } - if isEmbeddedDolt && autoMerge && !dryRun && store != nil { + if isEmbeddedMode() && autoMerge && !dryRun && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } diff --git a/cmd/bd/duplicates_embedded_test.go b/cmd/bd/duplicates_embedded_test.go index bcf41003b..0639b745d 100644 --- a/cmd/bd/duplicates_embedded_test.go +++ b/cmd/bd/duplicates_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/edit.go b/cmd/bd/edit.go index 489776bd8..683c06ac6 100644 --- a/cmd/bd/edit.go +++ b/cmd/bd/edit.go @@ -166,9 +166,9 @@ Examples: } editSaved = true - // Embedded mode: flush Dolt commit (only for non-routed stores). - if isEmbeddedDolt && !result.Routed { - if _, err := issueStore.CommitPending(ctx, actor); err != nil { + // Embedded mode: flush Dolt commit. + if isEmbeddedMode() { + if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } } diff --git a/cmd/bd/epic.go b/cmd/bd/epic.go index 9dc3aa373..5f4c3dcdc 100644 --- a/cmd/bd/epic.go +++ b/cmd/bd/epic.go @@ -121,7 +121,7 @@ var closeEligibleEpicsCmd = &cobra.Command{ } closedIDs = append(closedIDs, epicStatus.Epic.ID) } - if isEmbeddedDolt && len(closedIDs) > 0 && store != nil { + if isEmbeddedMode() && len(closedIDs) > 0 && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/epic_embedded_test.go b/cmd/bd/epic_embedded_test.go index bf91b5492..997cf7870 100644 --- a/cmd/bd/epic_embedded_test.go +++ b/cmd/bd/epic_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/errors.go b/cmd/bd/errors.go index 77393f23d..f657848c8 100644 --- a/cmd/bd/errors.go +++ b/cmd/bd/errors.go @@ -9,7 +9,7 @@ import ( // diagHint returns the appropriate diagnostic hint for the current mode. // In embedded mode, 'bd doctor' is not available so the hint omits it. func diagHint() string { - if isEmbeddedDolt { + if isEmbeddedMode() { return "run 'bd init' to create a new database" } return "run 'bd doctor' to diagnose, or 'bd init' to create a new database" diff --git a/cmd/bd/export_embedded_test.go b/cmd/bd/export_embedded_test.go index 8ab1fc34a..ac17668b7 100644 --- a/cmd/bd/export_embedded_test.go +++ b/cmd/bd/export_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/federation_embedded_test.go b/cmd/bd/federation_embedded_test.go index 4d3dad92c..1bd93280f 100644 --- a/cmd/bd/federation_embedded_test.go +++ b/cmd/bd/federation_embedded_test.go @@ -1,4 +1,4 @@ -//go:build embeddeddolt && cgo +//go:build cgo package main diff --git a/cmd/bd/find_duplicates_embedded_test.go b/cmd/bd/find_duplicates_embedded_test.go index f86aa793a..7624fa411 100644 --- a/cmd/bd/find_duplicates_embedded_test.go +++ b/cmd/bd/find_duplicates_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/flatten_embedded_test.go b/cmd/bd/flatten_embedded_test.go index 76cf6065e..eb44aec31 100644 --- a/cmd/bd/flatten_embedded_test.go +++ b/cmd/bd/flatten_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/gate.go b/cmd/bd/gate.go index a9dd741df..24b88a101 100644 --- a/cmd/bd/gate.go +++ b/cmd/bd/gate.go @@ -209,7 +209,7 @@ This is used by 'bd done --phase-complete' to register for gate wake notificatio } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } @@ -311,7 +311,7 @@ Use --reason to provide context for why the gate was resolved.`, } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } @@ -739,7 +739,7 @@ func closeGate(_ interface{}, gateID, reason string) error { return err } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(rootCtx, actor); err != nil { return err } diff --git a/cmd/bd/gate_embedded_test.go b/cmd/bd/gate_embedded_test.go index 70d71ce7c..e679c5101 100644 --- a/cmd/bd/gate_embedded_test.go +++ b/cmd/bd/gate_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/gc.go b/cmd/bd/gc.go index f996f5605..3025ef78b 100644 --- a/cmd/bd/gc.go +++ b/cmd/bd/gc.go @@ -123,7 +123,7 @@ Examples: results = append(results, phaseResult{name: "Decay", detail: fmt.Sprintf("%d issues deleted", deleted)}) // Embedded mode: flush Dolt commit after deletes. - if isEmbeddedDolt && deleted > 0 && store != nil { + if isEmbeddedMode() && deleted > 0 && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { WarnError("failed to commit after decay: %v", err) } diff --git a/cmd/bd/gc_embedded_test.go b/cmd/bd/gc_embedded_test.go index c72d717a2..d4ab5b456 100644 --- a/cmd/bd/gc_embedded_test.go +++ b/cmd/bd/gc_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/graph_embedded_test.go b/cmd/bd/graph_embedded_test.go index cd2b5a40d..a2be93cd2 100644 --- a/cmd/bd/graph_embedded_test.go +++ b/cmd/bd/graph_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/history_embedded_test.go b/cmd/bd/history_embedded_test.go index 5cb460a19..a0ef2690e 100644 --- a/cmd/bd/history_embedded_test.go +++ b/cmd/bd/history_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/hooks_embedded_test.go b/cmd/bd/hooks_embedded_test.go index a6c98a27f..5ce8df87a 100644 --- a/cmd/bd/hooks_embedded_test.go +++ b/cmd/bd/hooks_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/human_embedded_test.go b/cmd/bd/human_embedded_test.go index cc97f8b85..59203bc3e 100644 --- a/cmd/bd/human_embedded_test.go +++ b/cmd/bd/human_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/import_embedded_test.go b/cmd/bd/import_embedded_test.go index 24b1530c5..441680e41 100644 --- a/cmd/bd/import_embedded_test.go +++ b/cmd/bd/import_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/info_embedded_test.go b/cmd/bd/info_embedded_test.go index 78f21840f..efcd9428c 100644 --- a/cmd/bd/info_embedded_test.go +++ b/cmd/bd/info_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/init.go b/cmd/bd/init.go index 8dccae45d..c74db3dbe 100644 --- a/cmd/bd/init.go +++ b/cmd/bd/init.go @@ -45,10 +45,10 @@ With --stealth: configures per-repository git settings for invisible beads usage Perfect for personal use without affecting repo collaborators. To set up a specific AI tool, run: bd setup --stealth -Beads requires a running dolt sql-server for database operations. If a server is detected -on port 3307 or 3306, it is used automatically. Set connection details with --server-host, ---server-port, and --server-user. Password should be set via BEADS_DOLT_PASSWORD -environment variable.`, +By default, beads uses an embedded Dolt engine (no external server needed). +Pass --server to use an external dolt sql-server instead. In server mode, +set connection details with --server-host, --server-port, and --server-user. +Password should be set via BEADS_DOLT_PASSWORD environment variable.`, Run: func(cmd *cobra.Command, _ []string) { prefix, _ := cmd.Flags().GetString("prefix") quiet, _ := cmd.Flags().GetBool("quiet") @@ -61,7 +61,7 @@ environment variable.`, fromJSONL, _ := cmd.Flags().GetBool("from-jsonl") // Dolt server connection flags backendFlag, _ := cmd.Flags().GetString("backend") - _, _ = cmd.Flags().GetBool("server") // no-op, kept for backward compatibility + initServerMode, _ := cmd.Flags().GetBool("server") serverHost, _ := cmd.Flags().GetString("server-host") serverPort, _ := cmd.Flags().GetInt("server-port") serverUser, _ := cmd.Flags().GetString("server-user") @@ -95,6 +95,16 @@ environment variable.`, // Dolt is the only supported backend backend := configfile.BackendDolt + // Also treat BEADS_DOLT_SERVER_MODE=1 env var as --server. + if os.Getenv("BEADS_DOLT_SERVER_MODE") == "1" { + initServerMode = true + } + + // Set the global serverMode so isEmbeddedMode() returns the + // correct value for the duration of init (PersistentPreRun + // doesn't run for init, so this is the only place to set it). + serverMode = initServerMode + // Propagate --shared-server flag to env so that IsSharedServerMode(), // ResolveDoltDir(), and DefaultConfig() all see shared mode immediately // (before config.yaml exists). Safe: init runs once and exits. @@ -418,8 +428,9 @@ environment variable.`, BeadsDir: beadsDir, Database: dbName, ServerPort: initPort, + ServerMode: initServerMode, CreateIfMissing: true, // bd init is the only path that should create databases - AutoStart: os.Getenv("BEADS_DOLT_AUTO_START") != "0", + AutoStart: initServerMode && os.Getenv("BEADS_DOLT_AUTO_START") != "0", } if serverHost != "" { doltCfg.ServerHost = serverHost @@ -431,7 +442,7 @@ environment variable.`, doltCfg.ServerUser = serverUser } - initLock, err := acquireEmbeddedLock(beadsDir) + initLock, err := acquireEmbeddedLock(beadsDir, initServerMode) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) @@ -442,7 +453,7 @@ environment variable.`, // before opening the Dolt server store. Without this, a crashed init // leaves LOCK files that cause nil pointer dereference in DoltDB. // Skipped for embedded mode — embedded dolt has its own locking model. - if !isEmbeddedDolt { + if !isEmbeddedMode() { dolt.CleanStaleNomsLocks(doltserver.ResolveDoltDir(beadsDir)) } @@ -559,7 +570,7 @@ environment variable.`, } // Persist the connection mode matching this build. - if isEmbeddedDolt { + if isEmbeddedMode() { cfg.DoltMode = configfile.DoltModeEmbedded } else { cfg.DoltMode = configfile.DoltModeServer @@ -729,7 +740,7 @@ environment variable.`, // Clean up 0-byte noms LOCK files left behind by the store open/close cycle. // NOTE: Intentionally skipped for embedded mode. See earlier note. - if !isEmbeddedDolt { + if !isEmbeddedMode() { dolt.CleanStaleNomsLocks(doltserver.ResolveDoltDir(beadsDir)) } @@ -867,7 +878,7 @@ environment variable.`, // Clean up LOCK files again — the pre-commit hook may have // reopened the database and left a new LOCK behind. // NOTE: Intentionally skipped for embedded mode. See earlier note. - if !isEmbeddedDolt { + if !isEmbeddedMode() { dolt.CleanStaleNomsLocks(doltserver.ResolveDoltDir(beadsDir)) } } @@ -895,7 +906,7 @@ environment variable.`, fmt.Printf("\n%s bd initialized successfully!\n\n", ui.RenderPass("✓")) } fmt.Printf(" Backend: %s\n", ui.RenderAccent(backend)) - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Printf(" Mode: %s\n", ui.RenderAccent("embedded")) } else { host := serverHost @@ -938,7 +949,7 @@ environment variable.`, // Skipped in embedded mode: diagnostics use dolt.NewFromConfigWithOptions // which auto-starts a dolt sql-server. Embedded init already validates // the database via initSchema. - if !isEmbeddedDolt { + if !isEmbeddedMode() { doctorResult := runInitDiagnostics(cwd) hasIssues := false for _, check := range doctorResult.Checks { @@ -980,7 +991,7 @@ func init() { initCmd.Flags().String("backend", "", "Storage backend (default: dolt). --backend=sqlite prints deprecation notice.") // Dolt server connection flags - initCmd.Flags().Bool("server", false, "Use server mode (currently the default; embedded mode returning soon)") + initCmd.Flags().Bool("server", false, "Use external dolt sql-server instead of embedded engine") initCmd.Flags().String("server-host", "", "Dolt server host (default: 127.0.0.1)") initCmd.Flags().Int("server-port", 0, "Dolt server port (default: 3307)") initCmd.Flags().String("server-user", "", "Dolt server MySQL user (default: root)") @@ -1063,7 +1074,7 @@ func checkExistingBeadsDataAt(beadsDir string, prefix string) error { // Embedded mode stores databases under `.beads/embeddeddolt//`. // Treat any present embedded DB as "already initialized" (guard against // accidental re-init / data loss). - if isEmbeddedDolt { + if isEmbeddedMode() { embeddedRoot := filepath.Join(beadsDir, "embeddeddolt") entries, err := os.ReadDir(embeddedRoot) if err != nil { @@ -1364,7 +1375,7 @@ func promptContributorMode() (isContributor bool, err error) { func verifyMetadata(ctx context.Context, store storage.DoltStorage, key, value string) bool { if err := store.SetMetadata(ctx, key, value); err != nil { fmt.Fprintf(os.Stderr, "Warning: failed to write %s metadata: %v\n", key, err) - if !isEmbeddedDolt { + if !isEmbeddedMode() { fmt.Fprintf(os.Stderr, " Run 'bd doctor --fix' to repair.\n") } return false @@ -1373,7 +1384,7 @@ func verifyMetadata(ctx context.Context, store storage.DoltStorage, key, value s readBack, err := store.GetMetadata(ctx, key) if err != nil || readBack != value { fmt.Fprintf(os.Stderr, "Warning: %s metadata write did not persist (wrote %q, read %q)\n", key, value, readBack) - if !isEmbeddedDolt { + if !isEmbeddedMode() { fmt.Fprintf(os.Stderr, " Run 'bd doctor --fix' to repair.\n") } return false diff --git a/cmd/bd/init_embedded_test.go b/cmd/bd/init_embedded_test.go index fe2cd5dd3..18a5f293e 100644 --- a/cmd/bd/init_embedded_test.go +++ b/cmd/bd/init_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( @@ -50,9 +48,9 @@ func buildEmbeddedBD(t *testing.T) string { name = "bd.exe" } embeddedBD = filepath.Join(tmpDir, name) - cmd := exec.Command("go", "build", "-tags", "embeddeddolt", "-o", embeddedBD, ".") + cmd := exec.Command("go", "build", "-o", embeddedBD, ".") if out, err := cmd.CombinedOutput(); err != nil { - embeddedBDErr = fmt.Errorf("go build -tags embeddeddolt failed: %v\n%s", err, out) + embeddedBDErr = fmt.Errorf("go build failed: %v\n%s", err, out) } }) if embeddedBDErr != nil { diff --git a/cmd/bd/init_git_hooks.go b/cmd/bd/init_git_hooks.go index e8ec95829..336046428 100644 --- a/cmd/bd/init_git_hooks.go +++ b/cmd/bd/init_git_hooks.go @@ -161,7 +161,7 @@ func installGitHooks() error { oldPath := hook.path + ".old" if err := os.Rename(hook.path, oldPath); err != nil { fmt.Fprintf(os.Stderr, "%s Failed to chain with existing %s hook: %v\n", ui.RenderWarn("⚠"), hook.name, err) - if !isEmbeddedDolt { + if !isEmbeddedMode() { fmt.Fprintf(os.Stderr, "You can resolve this with: %s\n", ui.RenderAccent("bd doctor --fix")) } continue diff --git a/cmd/bd/kv_embedded_test.go b/cmd/bd/kv_embedded_test.go index 69caff97e..ab135f422 100644 --- a/cmd/bd/kv_embedded_test.go +++ b/cmd/bd/kv_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/label.go b/cmd/bd/label.go index da2fc16e0..2e55b3493 100644 --- a/cmd/bd/label.go +++ b/cmd/bd/label.go @@ -40,7 +40,7 @@ func processBatchLabelOperation(issueIDs []string, label string, operation strin } // Embedded mode: flush Dolt commit. transact() only commits the SQL // transaction; a Dolt commit is needed separately. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/label_embedded_test.go b/cmd/bd/label_embedded_test.go index 495cfcd22..da5b0785e 100644 --- a/cmd/bd/label_embedded_test.go +++ b/cmd/bd/label_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/link.go b/cmd/bd/link.go index 1473726b9..d75c227ab 100644 --- a/cmd/bd/link.go +++ b/cmd/bd/link.go @@ -68,7 +68,7 @@ Examples: // Check for cycles after adding dependency warnIfCyclesExist(fromStore) - if isEmbeddedDolt && fromStore != nil { + if isEmbeddedMode() && fromStore != nil { if _, err := fromStore.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/lint_embedded_test.go b/cmd/bd/lint_embedded_test.go index d117a5424..1af07da0b 100644 --- a/cmd/bd/lint_embedded_test.go +++ b/cmd/bd/lint_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/list_embedded_test.go b/cmd/bd/list_embedded_test.go index 9f7376629..4d566f70a 100644 --- a/cmd/bd/list_embedded_test.go +++ b/cmd/bd/list_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/main.go b/cmd/bd/main.go index c11f90445..2f17a374b 100644 --- a/cmd/bd/main.go +++ b/cmd/bd/main.go @@ -58,6 +58,7 @@ var ( ) var ( sandboxMode bool + serverMode bool // True when using external dolt sql-server (dolt_mode=server) readonlyMode bool // Read-only mode: block write operations (for worker sandboxes) storeIsReadOnly bool // Track if store was opened read-only (for staleness checks) lockTimeout = 30 * time.Second // Dolt open timeout (fixed default) @@ -591,6 +592,12 @@ var rootCmd = &cobra.Command{ fmt.Fprintf(os.Stderr, "warning: failed to load beads config from %s: %v\n", beadsDir, cfgErr) } if cfg != nil { + doltCfg.ServerMode = cfg.IsDoltServerMode() + serverMode = doltCfg.ServerMode + if cmdCtx != nil { + cmdCtx.ServerMode = doltCfg.ServerMode + } + // Always set database name (needed for bootstrap to find // prefix-based databases like "beads_hq"; see #1669) doltCfg.Database = cfg.GetDoltDatabase() @@ -626,7 +633,7 @@ var rootCmd = &cobra.Command{ // These prevent the Dolt server from opening databases (SIGSEGV or // "database is locked"). Safe because we haven't connected yet. // NOTE: Intentionally skipped for embedded mode. - if !isEmbeddedDolt { + if !isEmbeddedMode() { if removed, _ := dolt.CleanStaleNomsLocks(doltPath); removed > 0 { debug.Logf("cleaned %d stale noms LOCK file(s) from %s", removed, doltPath) } diff --git a/cmd/bd/main_errors.go b/cmd/bd/main_errors.go index 391491618..ea613a0b0 100644 --- a/cmd/bd/main_errors.go +++ b/cmd/bd/main_errors.go @@ -31,7 +31,7 @@ func handleFreshCloneError(err error) bool { fmt.Fprintf(os.Stderr, "Error: Database not initialized\n\n") fmt.Fprintf(os.Stderr, "This appears to be a fresh clone or the database needs initialization.\n") - if !isEmbeddedDolt { + if !isEmbeddedMode() { fmt.Fprintf(os.Stderr, "\nTo diagnose, run:\n") fmt.Fprintf(os.Stderr, " bd doctor\n\n") } else { diff --git a/cmd/bd/memory_embedded_test.go b/cmd/bd/memory_embedded_test.go index ac1134e96..9ea8045bc 100644 --- a/cmd/bd/memory_embedded_test.go +++ b/cmd/bd/memory_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/migrate.go b/cmd/bd/migrate.go index 7a63b33f7..8fde191bf 100644 --- a/cmd/bd/migrate.go +++ b/cmd/bd/migrate.go @@ -253,7 +253,7 @@ func handleDoltMetadataUpdate(cfg *configfile.Config, dryRun bool) { } // Embedded mode: flush Dolt commit after metadata writes. - if isEmbeddedDolt && (versionUpdated || repoIDSet || cloneIDSet) && store != nil { + if isEmbeddedMode() && (versionUpdated || repoIDSet || cloneIDSet) && store != nil { if _, err := store.CommitPending(ctx, "migrate"); err != nil { fmt.Fprintf(os.Stderr, "Warning: failed to commit: %v\n", err) } @@ -389,7 +389,7 @@ func handleUpdateRepoID(dryRun bool, autoYes bool) { } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(rootCtx, "migrate"); err != nil { fmt.Fprintf(os.Stderr, "Warning: failed to commit: %v\n", err) } @@ -631,7 +631,7 @@ func handleToSeparateBranch(branch string, dryRun bool) { } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && !dryRun && store != nil { + if isEmbeddedMode() && !dryRun && store != nil { if _, commitErr := store.CommitPending(rootCtx, "migrate"); commitErr != nil { fmt.Fprintf(os.Stderr, "Warning: failed to commit: %v\n", commitErr) } diff --git a/cmd/bd/migrate_embedded_test.go b/cmd/bd/migrate_embedded_test.go index 30d13343d..b78a429e5 100644 --- a/cmd/bd/migrate_embedded_test.go +++ b/cmd/bd/migrate_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/note.go b/cmd/bd/note.go index 0eeecd87b..70df74c28 100644 --- a/cmd/bd/note.go +++ b/cmd/bd/note.go @@ -98,7 +98,7 @@ Examples: } // Flush Dolt commit for embedded mode - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/onboard_embedded_test.go b/cmd/bd/onboard_embedded_test.go index d4844906a..c2f891799 100644 --- a/cmd/bd/onboard_embedded_test.go +++ b/cmd/bd/onboard_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/orphans_embedded_test.go b/cmd/bd/orphans_embedded_test.go index cadbeb74d..a8a2e2f79 100644 --- a/cmd/bd/orphans_embedded_test.go +++ b/cmd/bd/orphans_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/prime_embedded_test.go b/cmd/bd/prime_embedded_test.go index b37cb4ef4..129c8cd82 100644 --- a/cmd/bd/prime_embedded_test.go +++ b/cmd/bd/prime_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/priority.go b/cmd/bd/priority.go index 7f810665e..dae8189bf 100644 --- a/cmd/bd/priority.go +++ b/cmd/bd/priority.go @@ -70,7 +70,7 @@ Examples: } // Flush Dolt commit for embedded mode - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/promote.go b/cmd/bd/promote.go index 68adeb71c..7440dee3a 100644 --- a/cmd/bd/promote.go +++ b/cmd/bd/promote.go @@ -73,7 +73,7 @@ Examples: } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/promote_embedded_test.go b/cmd/bd/promote_embedded_test.go index 8ce5355d6..61f3bfb30 100644 --- a/cmd/bd/promote_embedded_test.go +++ b/cmd/bd/promote_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/purge.go b/cmd/bd/purge.go index 5e3795ff7..fa06bb7f5 100644 --- a/cmd/bd/purge.go +++ b/cmd/bd/purge.go @@ -202,7 +202,7 @@ EXAMPLES: } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && result.DeletedCount > 0 && store != nil { + if isEmbeddedMode() && result.DeletedCount > 0 && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } diff --git a/cmd/bd/purge_embedded_test.go b/cmd/bd/purge_embedded_test.go index 058c904a6..f8ecc41eb 100644 --- a/cmd/bd/purge_embedded_test.go +++ b/cmd/bd/purge_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/query_embedded_test.go b/cmd/bd/query_embedded_test.go index 7f38dab9a..b88b3115f 100644 --- a/cmd/bd/query_embedded_test.go +++ b/cmd/bd/query_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/quick.go b/cmd/bd/quick.go index 5ae0e96da..92fafd598 100644 --- a/cmd/bd/quick.go +++ b/cmd/bd/quick.go @@ -56,7 +56,7 @@ Example: } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt { + if isEmbeddedMode() { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } diff --git a/cmd/bd/quick_embedded_test.go b/cmd/bd/quick_embedded_test.go index 90b668a5d..10ac23111 100644 --- a/cmd/bd/quick_embedded_test.go +++ b/cmd/bd/quick_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/quickstart_embedded_test.go b/cmd/bd/quickstart_embedded_test.go index 00bd19e28..a61dd7b08 100644 --- a/cmd/bd/quickstart_embedded_test.go +++ b/cmd/bd/quickstart_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/ready_embedded_test.go b/cmd/bd/ready_embedded_test.go index 1e73baed7..4c0eddcab 100644 --- a/cmd/bd/ready_embedded_test.go +++ b/cmd/bd/ready_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/rename.go b/cmd/bd/rename.go index 0d78c6120..6216f8a05 100644 --- a/cmd/bd/rename.go +++ b/cmd/bd/rename.go @@ -90,7 +90,7 @@ func runRename(cmd *cobra.Command, args []string) error { fmt.Printf("Renamed %s -> %s\n", ui.RenderWarn(oldID), ui.RenderAccent(newID)) // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { return fmt.Errorf("failed to commit: %w", err) } diff --git a/cmd/bd/rename_prefix.go b/cmd/bd/rename_prefix.go index ed0ac8686..20f979146 100644 --- a/cmd/bd/rename_prefix.go +++ b/cmd/bd/rename_prefix.go @@ -121,7 +121,7 @@ NOTE: This is a rare operation. Most users never need this command.`, if err := repairPrefixes(ctx, store, actor, newPrefix, issues, prefixes, dryRun); err != nil { FatalError("failed to repair prefixes: %v", err) } - if isEmbeddedDolt && !dryRun && store != nil { + if isEmbeddedMode() && !dryRun && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } @@ -141,7 +141,7 @@ NOTE: This is a rare operation. Most users never need this command.`, if err := store.SetConfig(ctx, "issue_prefix", newPrefix); err != nil { FatalError("failed to update prefix: %v", err) } - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } @@ -185,7 +185,7 @@ NOTE: This is a rare operation. Most users never need this command.`, } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } diff --git a/cmd/bd/rename_prefix_embedded_test.go b/cmd/bd/rename_prefix_embedded_test.go index b92d1afbb..e14d9a289 100644 --- a/cmd/bd/rename_prefix_embedded_test.go +++ b/cmd/bd/rename_prefix_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/reopen.go b/cmd/bd/reopen.go index 4348d1e8b..8d4cf854d 100644 --- a/cmd/bd/reopen.go +++ b/cmd/bd/reopen.go @@ -67,7 +67,7 @@ This is more explicit than 'bd update --status open' and emits a Reopened event. } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/reopen_embedded_test.go b/cmd/bd/reopen_embedded_test.go index cfdf79d0c..c48e29a20 100644 --- a/cmd/bd/reopen_embedded_test.go +++ b/cmd/bd/reopen_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/repo.go b/cmd/bd/repo.go index 57ee5ab24..0891bb92f 100644 --- a/cmd/bd/repo.go +++ b/cmd/bd/repo.go @@ -150,7 +150,7 @@ that came from the removed repository.`, } // Embedded mode: flush Dolt commit before output. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { return fmt.Errorf("failed to commit: %w", err) } @@ -378,7 +378,7 @@ Also triggers Dolt push/pull if a remote is configured.`, // Manual push available via: bd dolt push // Embedded mode: flush Dolt commit before output. - if isEmbeddedDolt && totalImported > 0 && store != nil { + if isEmbeddedMode() && totalImported > 0 && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { return fmt.Errorf("failed to commit: %w", err) } diff --git a/cmd/bd/restore_embedded_test.go b/cmd/bd/restore_embedded_test.go index ddac7ecbe..7181d9392 100644 --- a/cmd/bd/restore_embedded_test.go +++ b/cmd/bd/restore_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/search_embedded_test.go b/cmd/bd/search_embedded_test.go index a3b56eaa6..64d482030 100644 --- a/cmd/bd/search_embedded_test.go +++ b/cmd/bd/search_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/setup_embedded_test.go b/cmd/bd/setup_embedded_test.go index 4c8ec9365..dbc37683b 100644 --- a/cmd/bd/setup_embedded_test.go +++ b/cmd/bd/setup_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/ship.go b/cmd/bd/ship.go index c3964f7fa..635958e01 100644 --- a/cmd/bd/ship.go +++ b/cmd/bd/ship.go @@ -140,7 +140,7 @@ func runShip(cmd *cobra.Command, args []string) { } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } diff --git a/cmd/bd/ship_embedded_test.go b/cmd/bd/ship_embedded_test.go index c2eb8c273..789acc5ff 100644 --- a/cmd/bd/ship_embedded_test.go +++ b/cmd/bd/ship_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/show_embedded_test.go b/cmd/bd/show_embedded_test.go index f95fc0357..3380afd56 100644 --- a/cmd/bd/show_embedded_test.go +++ b/cmd/bd/show_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/sql.go b/cmd/bd/sql.go index 7b56aa9d9..b1a94ec4f 100644 --- a/cmd/bd/sql.go +++ b/cmd/bd/sql.go @@ -31,7 +31,7 @@ report the number of rows affected. WARNING: Direct database access bypasses the storage layer. Use with caution.`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - if isEmbeddedDolt { + if isEmbeddedMode() { fmt.Fprintln(os.Stderr, "Error: 'bd sql' is not yet supported in embedded mode") os.Exit(1) } diff --git a/cmd/bd/stale_embedded_test.go b/cmd/bd/stale_embedded_test.go index fab25d56e..2ae65ede2 100644 --- a/cmd/bd/stale_embedded_test.go +++ b/cmd/bd/stale_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/state.go b/cmd/bd/state.go index 26278f002..3f35ef94c 100644 --- a/cmd/bd/state.go +++ b/cmd/bd/state.go @@ -223,7 +223,7 @@ The --reason flag provides context for the event bead (recommended).`, } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/state_embedded_test.go b/cmd/bd/state_embedded_test.go index 438c7cee5..38b037ba3 100644 --- a/cmd/bd/state_embedded_test.go +++ b/cmd/bd/state_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/status_embedded_test.go b/cmd/bd/status_embedded_test.go index 01d6cfc54..492260b9d 100644 --- a/cmd/bd/status_embedded_test.go +++ b/cmd/bd/status_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/store_factory.go b/cmd/bd/store_factory.go index 070d5efe0..6d3dd1632 100644 --- a/cmd/bd/store_factory.go +++ b/cmd/bd/store_factory.go @@ -1,37 +1,74 @@ -//go:build !embeddeddolt - package main import ( "context" + "path/filepath" + "github.com/steveyegge/beads/internal/configfile" "github.com/steveyegge/beads/internal/storage" "github.com/steveyegge/beads/internal/storage/dolt" "github.com/steveyegge/beads/internal/storage/embeddeddolt" ) -const isEmbeddedDolt = false - -// newDoltStore creates a storage backend from an explicit config. -// Used by bd init and PersistentPreRun. -func newDoltStore(ctx context.Context, cfg *dolt.Config) (storage.DoltStorage, error) { - return dolt.New(ctx, cfg) +// isEmbeddedMode returns true when the current session is using the embedded +// Dolt engine (the default). Returns false in server mode (external dolt +// sql-server). Safe to call before store initialization — defaults to true +// (embedded) when the mode hasn't been set yet. +func isEmbeddedMode() bool { + if shouldUseGlobals() { + return !serverMode + } + if cmdCtx != nil { + return !cmdCtx.ServerMode + } + return true // default: embedded } -// acquireEmbeddedLock is a no-op in non-embedded builds. The server-mode dolt -// backend handles its own concurrency. -func acquireEmbeddedLock(_ string) (*embeddeddolt.Lock, error) { - return &embeddeddolt.Lock{}, nil +// newDoltStore creates a storage backend from an explicit config. +// When cfg.ServerMode is true, connects to an external dolt sql-server; +// otherwise uses the embedded Dolt engine (default). +// Used by bd init and PersistentPreRun. +func newDoltStore(ctx context.Context, cfg *dolt.Config) (storage.DoltStorage, error) { + if cfg.ServerMode { + return dolt.New(ctx, cfg) + } + return embeddeddolt.New(ctx, cfg.BeadsDir, cfg.Database, "main") +} + +// acquireEmbeddedLock acquires an exclusive flock on the embeddeddolt data +// directory derived from beadsDir. The caller must defer lock.Unlock(). +// Returns a no-op lock when serverMode is true (the server handles its own +// concurrency). +func acquireEmbeddedLock(beadsDir string, serverMode bool) (*embeddeddolt.Lock, error) { + if serverMode { + return &embeddeddolt.Lock{}, nil + } + dataDir := filepath.Join(beadsDir, "embeddeddolt") + return embeddeddolt.TryLock(dataDir) } // newDoltStoreFromConfig creates a storage backend from the beads directory's -// persisted metadata.json configuration. +// persisted metadata.json configuration. Uses embedded Dolt by default; +// connects to dolt sql-server when dolt_mode is "server". func newDoltStoreFromConfig(ctx context.Context, beadsDir string) (storage.DoltStorage, error) { - return dolt.NewFromConfig(ctx, beadsDir) + cfg, err := configfile.Load(beadsDir) + if err == nil && cfg != nil && cfg.IsDoltServerMode() { + return dolt.NewFromConfig(ctx, beadsDir) + } + database := "" + if cfg != nil { + database = cfg.GetDoltDatabase() + } + return embeddeddolt.New(ctx, beadsDir, database, "main") } // newReadOnlyStoreFromConfig creates a read-only storage backend from the beads // directory's persisted metadata.json configuration. func newReadOnlyStoreFromConfig(ctx context.Context, beadsDir string) (storage.DoltStorage, error) { - return dolt.NewFromConfigWithOptions(ctx, beadsDir, &dolt.Config{ReadOnly: true}) + cfg, err := configfile.Load(beadsDir) + if err == nil && cfg != nil && cfg.IsDoltServerMode() { + return dolt.NewFromConfigWithOptions(ctx, beadsDir, &dolt.Config{ReadOnly: true}) + } + // Embedded dolt is single-process so read-only is not enforced at the engine level. + return newDoltStoreFromConfig(ctx, beadsDir) } diff --git a/cmd/bd/store_factory_embedded.go b/cmd/bd/store_factory_embedded.go deleted file mode 100644 index bad94190d..000000000 --- a/cmd/bd/store_factory_embedded.go +++ /dev/null @@ -1,45 +0,0 @@ -//go:build embeddeddolt - -package main - -import ( - "context" - "path/filepath" - - "github.com/steveyegge/beads/internal/configfile" - "github.com/steveyegge/beads/internal/storage" - "github.com/steveyegge/beads/internal/storage/dolt" - "github.com/steveyegge/beads/internal/storage/embeddeddolt" -) - -const isEmbeddedDolt = true - -// newDoltStore creates an embedded Dolt storage backend. -// The dolt.Config is used only for BeadsDir and Database; server fields are ignored. -func newDoltStore(ctx context.Context, cfg *dolt.Config) (storage.DoltStorage, error) { - return embeddeddolt.New(ctx, cfg.BeadsDir, cfg.Database, "main") -} - -// acquireEmbeddedLock acquires an exclusive flock on the embeddeddolt data -// directory derived from beadsDir. The caller must defer lock.Unlock(). -// Used by commands that require single-writer access (e.g., bd init). -func acquireEmbeddedLock(beadsDir string) (*embeddeddolt.Lock, error) { - dataDir := filepath.Join(beadsDir, "embeddeddolt") - return embeddeddolt.TryLock(dataDir) -} - -// newDoltStoreFromConfig creates an embedded Dolt storage backend from the -// beads directory's persisted metadata.json configuration. -func newDoltStoreFromConfig(ctx context.Context, beadsDir string) (storage.DoltStorage, error) { - database := "" - if cfg, err := configfile.Load(beadsDir); err == nil && cfg != nil { - database = cfg.GetDoltDatabase() - } - return embeddeddolt.New(ctx, beadsDir, database, "main") -} - -// newReadOnlyStoreFromConfig creates a read-only embedded Dolt storage backend. -// Embedded dolt is single-process so read-only is not enforced at the engine level. -func newReadOnlyStoreFromConfig(ctx context.Context, beadsDir string) (storage.DoltStorage, error) { - return newDoltStoreFromConfig(ctx, beadsDir) -} diff --git a/cmd/bd/supersede_embedded_test.go b/cmd/bd/supersede_embedded_test.go index 94b4e0d06..039b08246 100644 --- a/cmd/bd/supersede_embedded_test.go +++ b/cmd/bd/supersede_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/swarm.go b/cmd/bd/swarm.go index 908db2122..208e37176 100644 --- a/cmd/bd/swarm.go +++ b/cmd/bd/swarm.go @@ -1037,7 +1037,7 @@ Examples: FatalErrorRespectJSON("failed to link swarm to epic: %v", err) } - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/swarm_embedded_test.go b/cmd/bd/swarm_embedded_test.go index dd8849a13..588c9c5cf 100644 --- a/cmd/bd/swarm_embedded_test.go +++ b/cmd/bd/swarm_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/tag.go b/cmd/bd/tag.go index b8738dc19..e99e44a40 100644 --- a/cmd/bd/tag.go +++ b/cmd/bd/tag.go @@ -54,7 +54,7 @@ Examples: } // Flush Dolt commit for embedded mode - if isEmbeddedDolt && store != nil { + if isEmbeddedMode() && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/test_dolt_server_cgo_test.go b/cmd/bd/test_dolt_server_cgo_test.go index b5cb036e0..984c22a10 100644 --- a/cmd/bd/test_dolt_server_cgo_test.go +++ b/cmd/bd/test_dolt_server_cgo_test.go @@ -1,4 +1,4 @@ -//go:build cgo && !embeddeddolt +//go:build cgo package main @@ -26,7 +26,16 @@ var testSharedConn *sql.DB // on a dynamic port using the shared testutil helper. This prevents tests // from creating testdb_* databases on the production Dolt server. // Returns a cleanup function that stops the server and removes the container. +// +// Skipped when only embedded tests are requested (BEADS_TEST_EMBEDDED_DOLT=1 +// without the server test flag) — embedded tests use subprocess binaries and +// don't need a Docker container. func startTestDoltServer() func() { + // Skip Docker container when only embedded tests are requested. + // Embedded tests build and run subprocess binaries; they don't need a server. + if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") == "1" { + return func() {} + } if err := testutil.EnsureDoltContainerForTestMain(); err != nil { fmt.Fprintf(os.Stderr, "WARN: %v, skipping Dolt tests\n", err) return func() {} diff --git a/cmd/bd/test_dolt_server_embedded_test.go b/cmd/bd/test_dolt_server_embedded_test.go deleted file mode 100644 index 622862d2f..000000000 --- a/cmd/bd/test_dolt_server_embedded_test.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build embeddeddolt - -package main - -import "database/sql" - -// Stubs for variables defined in test_dolt_server_cgo_test.go which is -// excluded from embedded builds (cgo && !embeddeddolt). The test helpers -// in test_helpers_test.go reference these, so they must exist. -var testSharedDB string -var testSharedConn *sql.DB diff --git a/cmd/bd/todo.go b/cmd/bd/todo.go index 19f7b87d1..2997c9b9f 100644 --- a/cmd/bd/todo.go +++ b/cmd/bd/todo.go @@ -66,7 +66,7 @@ var addTodoCmd = &cobra.Command{ } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && getStore() != nil { + if isEmbeddedMode() && getStore() != nil { if _, err := getStore().CommitPending(ctx, getActorWithGit()); err != nil { FatalError("failed to commit: %v", err) } @@ -174,7 +174,7 @@ var doneTodoCmd = &cobra.Command{ } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && len(closedIDs) > 0 && getStore() != nil { + if isEmbeddedMode() && len(closedIDs) > 0 && getStore() != nil { if _, err := getStore().CommitPending(ctx, getActorWithGit()); err != nil { FatalError("failed to commit: %v", err) } diff --git a/cmd/bd/todo_embedded_test.go b/cmd/bd/todo_embedded_test.go index 90e542190..023b24fff 100644 --- a/cmd/bd/todo_embedded_test.go +++ b/cmd/bd/todo_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/types_embedded_test.go b/cmd/bd/types_embedded_test.go index dc6e07230..8e382113e 100644 --- a/cmd/bd/types_embedded_test.go +++ b/cmd/bd/types_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/undefer.go b/cmd/bd/undefer.go index df3c89f30..4e916baab 100644 --- a/cmd/bd/undefer.go +++ b/cmd/bd/undefer.go @@ -84,7 +84,7 @@ Examples: } // Embedded mode: flush Dolt commit. - if isEmbeddedDolt && len(args) > 0 && store != nil { + if isEmbeddedMode() && len(args) > 0 && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalError("failed to commit: %v", err) } diff --git a/cmd/bd/undefer_embedded_test.go b/cmd/bd/undefer_embedded_test.go index 3b687f5e4..79e0c3046 100644 --- a/cmd/bd/undefer_embedded_test.go +++ b/cmd/bd/undefer_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/update.go b/cmd/bd/update.go index 720fdac0f..b58c4c2c3 100644 --- a/cmd/bd/update.go +++ b/cmd/bd/update.go @@ -481,7 +481,7 @@ create, update, show, or close operation).`, // Embedded mode: flush Dolt commit. DoltStore commits // inline during UpdateIssue so this is only needed for EmbeddedDoltStore. - if isEmbeddedDolt && firstUpdatedID != "" && store != nil { + if isEmbeddedMode() && firstUpdatedID != "" && store != nil { if _, err := store.CommitPending(ctx, actor); err != nil { FatalErrorRespectJSON("failed to commit: %v", err) } diff --git a/cmd/bd/update_embedded_test.go b/cmd/bd/update_embedded_test.go index 2a6730dff..271067d99 100644 --- a/cmd/bd/update_embedded_test.go +++ b/cmd/bd/update_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/vc_embedded_test.go b/cmd/bd/vc_embedded_test.go index 7461dae2f..071eae511 100644 --- a/cmd/bd/vc_embedded_test.go +++ b/cmd/bd/vc_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/version_embedded_test.go b/cmd/bd/version_embedded_test.go index 67c60b930..6a93069b9 100644 --- a/cmd/bd/version_embedded_test.go +++ b/cmd/bd/version_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/cmd/bd/version_tracking.go b/cmd/bd/version_tracking.go index 8b124cf27..c93f6b80d 100644 --- a/cmd/bd/version_tracking.go +++ b/cmd/bd/version_tracking.go @@ -128,7 +128,7 @@ func maybeShowUpgradeNotification() { // Display notification fmt.Printf("🔄 bd upgraded from v%s to v%s since last use\n", previousVersion, Version) fmt.Println("💡 Run 'bd upgrade review' to see what changed") - if !isEmbeddedDolt { + if !isEmbeddedMode() { fmt.Println("💊 Run 'bd doctor' to verify upgrade completed cleanly") } diff --git a/cmd/bd/where_embedded_test.go b/cmd/bd/where_embedded_test.go index 21f3ef1af..c4a8bdbfb 100644 --- a/cmd/bd/where_embedded_test.go +++ b/cmd/bd/where_embedded_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( diff --git a/internal/storage/dolt/store.go b/internal/storage/dolt/store.go index 5b637841c..dab2eddde 100644 --- a/internal/storage/dolt/store.go +++ b/internal/storage/dolt/store.go @@ -230,6 +230,11 @@ type Config struct { // creation of shadow databases on the wrong server. CreateIfMissing bool + // ServerMode indicates this config targets an external dolt sql-server + // rather than the embedded Dolt engine. Set by the store factory based + // on metadata.json dolt_mode or BEADS_DOLT_SERVER_MODE env var. + ServerMode bool + // AutoStart enables transparent server auto-start when connection fails. // When true and the host is localhost, bd will start a dolt sql-server // automatically if one isn't running. Disabled under orchestrator (GT_ROOT set). diff --git a/internal/storage/embeddeddolt/child_id.go b/internal/storage/embeddeddolt/child_id.go index cc25ff883..df63a5e56 100644 --- a/internal/storage/embeddeddolt/child_id.go +++ b/internal/storage/embeddeddolt/child_id.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/child_id_test.go b/internal/storage/embeddeddolt/child_id_test.go index f471c99d2..f35555061 100644 --- a/internal/storage/embeddeddolt/child_id_test.go +++ b/internal/storage/embeddeddolt/child_id_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt_test import ( diff --git a/internal/storage/embeddeddolt/cmd/main.go b/internal/storage/embeddeddolt/cmd/main.go index 09c600564..6942707ad 100644 --- a/internal/storage/embeddeddolt/cmd/main.go +++ b/internal/storage/embeddeddolt/cmd/main.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package main import ( @@ -36,6 +34,6 @@ func main() { fmt.Fprintf(os.Stderr, "error: %v\n", err) os.Exit(1) } - store.Close() + _ = store.Close() fmt.Println("ok") } diff --git a/internal/storage/embeddeddolt/concurrency_test.go b/internal/storage/embeddeddolt/concurrency_test.go index 8a6ce32fe..6f830bbcd 100644 --- a/internal/storage/embeddeddolt/concurrency_test.go +++ b/internal/storage/embeddeddolt/concurrency_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt_test import ( @@ -69,9 +67,8 @@ func TestConcurrencyMultiProcess(t *testing.T) { t.Logf("using pre-built test binary: %s", testBin) } else { testBin = filepath.Join(t.TempDir(), "embeddeddolt.test") - t.Logf("building test binary: go test -tags embeddeddolt -c -o %s ./internal/storage/embeddeddolt/", testBin) + t.Logf("building test binary: go test -c -o %s ./internal/storage/embeddeddolt/", testBin) build := exec.CommandContext(ctx, "go", "test", - "-tags", "embeddeddolt", "-c", "-o", testBin, "./internal/storage/embeddeddolt/", diff --git a/internal/storage/embeddeddolt/config_metadata.go b/internal/storage/embeddeddolt/config_metadata.go index 144851399..48c4183c6 100644 --- a/internal/storage/embeddeddolt/config_metadata.go +++ b/internal/storage/embeddeddolt/config_metadata.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/create_issue.go b/internal/storage/embeddeddolt/create_issue.go index 2784296a5..1f82b5c3c 100644 --- a/internal/storage/embeddeddolt/create_issue.go +++ b/internal/storage/embeddeddolt/create_issue.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/create_issue_test.go b/internal/storage/embeddeddolt/create_issue_test.go index 8af258f59..d2d7c323e 100644 --- a/internal/storage/embeddeddolt/create_issue_test.go +++ b/internal/storage/embeddeddolt/create_issue_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt_test import ( diff --git a/internal/storage/embeddeddolt/dependencies.go b/internal/storage/embeddeddolt/dependencies.go index 92ab6a893..694522b14 100644 --- a/internal/storage/embeddeddolt/dependencies.go +++ b/internal/storage/embeddeddolt/dependencies.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/dependencies_test.go b/internal/storage/embeddeddolt/dependencies_test.go index 7e0227b0a..2011b3836 100644 --- a/internal/storage/embeddeddolt/dependencies_test.go +++ b/internal/storage/embeddeddolt/dependencies_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt_test import ( diff --git a/internal/storage/embeddeddolt/federation.go b/internal/storage/embeddeddolt/federation.go index 3decb5fdb..3294947d9 100644 --- a/internal/storage/embeddeddolt/federation.go +++ b/internal/storage/embeddeddolt/federation.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/flock.go b/internal/storage/embeddeddolt/flock.go index ecbc32496..16a013327 100644 --- a/internal/storage/embeddeddolt/flock.go +++ b/internal/storage/embeddeddolt/flock.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( @@ -26,13 +24,13 @@ func TryLock(dataDir string) (*Lock, error) { } lockPath := filepath.Join(dataDir, ".lock") - f, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0600) + f, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0600) //nolint:gosec // lockPath is derived from dataDir, not user input if err != nil { return nil, fmt.Errorf("embeddeddolt: opening lock file: %w", err) } if err := lockfile.FlockExclusiveNonBlocking(f); err != nil { - f.Close() + _ = f.Close() if lockfile.IsLocked(err) { return nil, fmt.Errorf("embeddeddolt: another process holds the exclusive lock on %s; "+ "the embedded backend supports only one writer at a time — "+ diff --git a/internal/storage/embeddeddolt/flock_stub.go b/internal/storage/embeddeddolt/flock_stub.go deleted file mode 100644 index 1955036e8..000000000 --- a/internal/storage/embeddeddolt/flock_stub.go +++ /dev/null @@ -1,16 +0,0 @@ -//go:build !embeddeddolt - -package embeddeddolt - -import "errors" - -// Lock is a stub for builds without the embeddeddolt tag. -type Lock struct{} - -// TryLock returns an error when the embeddeddolt build tag is not set. -func TryLock(_ string) (*Lock, error) { - return nil, errors.New("embeddeddolt: not available") -} - -// Unlock is a no-op stub. -func (l *Lock) Unlock() {} diff --git a/internal/storage/embeddeddolt/get_issue.go b/internal/storage/embeddeddolt/get_issue.go index 83f809727..8129a3ee4 100644 --- a/internal/storage/embeddeddolt/get_issue.go +++ b/internal/storage/embeddeddolt/get_issue.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/get_issue_test.go b/internal/storage/embeddeddolt/get_issue_test.go index 72728150d..27af31a12 100644 --- a/internal/storage/embeddeddolt/get_issue_test.go +++ b/internal/storage/embeddeddolt/get_issue_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt_test import ( diff --git a/internal/storage/embeddeddolt/issues.go b/internal/storage/embeddeddolt/issues.go index 38b9b9547..0291d858e 100644 --- a/internal/storage/embeddeddolt/issues.go +++ b/internal/storage/embeddeddolt/issues.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/labels.go b/internal/storage/embeddeddolt/labels.go index a5e0a88d4..a4c4bc8d6 100644 --- a/internal/storage/embeddeddolt/labels.go +++ b/internal/storage/embeddeddolt/labels.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/list_queries.go b/internal/storage/embeddeddolt/list_queries.go index 5d72eacca..b89f90011 100644 --- a/internal/storage/embeddeddolt/list_queries.go +++ b/internal/storage/embeddeddolt/list_queries.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/open.go b/internal/storage/embeddeddolt/open.go index 1fe381181..aa5cf523a 100644 --- a/internal/storage/embeddeddolt/open.go +++ b/internal/storage/embeddeddolt/open.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/open_stub.go b/internal/storage/embeddeddolt/open_stub.go deleted file mode 100644 index 9211cc56a..000000000 --- a/internal/storage/embeddeddolt/open_stub.go +++ /dev/null @@ -1,15 +0,0 @@ -//go:build !embeddeddolt - -package embeddeddolt - -import ( - "context" - "database/sql" - "errors" -) - -// OpenSQL is a stub that returns an error when the embeddeddolt build tag is -// not set. Build with -tags embeddeddolt to enable. -func OpenSQL(_ context.Context, _, _, _ string) (*sql.DB, func() error, error) { - return nil, nil, errors.New("embeddeddolt: build with -tags embeddeddolt to enable") -} diff --git a/internal/storage/embeddeddolt/queries.go b/internal/storage/embeddeddolt/queries.go index 19914142e..c0534a659 100644 --- a/internal/storage/embeddeddolt/queries.go +++ b/internal/storage/embeddeddolt/queries.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/schema.go b/internal/storage/embeddeddolt/schema.go index a8a7d4b6e..57e606013 100644 --- a/internal/storage/embeddeddolt/schema.go +++ b/internal/storage/embeddeddolt/schema.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/schema_test.go b/internal/storage/embeddeddolt/schema_test.go index f08ce87b9..8556831d2 100644 --- a/internal/storage/embeddeddolt/schema_test.go +++ b/internal/storage/embeddeddolt/schema_test.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt_test import ( diff --git a/internal/storage/embeddeddolt/statistics.go b/internal/storage/embeddeddolt/statistics.go index 77091456b..3589d11d5 100644 --- a/internal/storage/embeddeddolt/statistics.go +++ b/internal/storage/embeddeddolt/statistics.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/store.go b/internal/storage/embeddeddolt/store.go index b6ad86894..fedf3ad33 100644 --- a/internal/storage/embeddeddolt/store.go +++ b/internal/storage/embeddeddolt/store.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/store_stub.go b/internal/storage/embeddeddolt/store_stub.go deleted file mode 100644 index f7c9350d6..000000000 --- a/internal/storage/embeddeddolt/store_stub.go +++ /dev/null @@ -1,20 +0,0 @@ -//go:build !embeddeddolt - -package embeddeddolt - -import ( - "context" - "errors" -) - -// EmbeddedDoltStore is a stub for builds without the embeddeddolt tag. -type EmbeddedDoltStore struct { - dataDir string - database string - branch string -} - -// New returns an error when the embeddeddolt build tag is not set. -func New(_ context.Context, _, _, _ string) (*EmbeddedDoltStore, error) { - return nil, errors.New("embeddeddolt: wip, do not use") -} diff --git a/internal/storage/embeddeddolt/transaction.go b/internal/storage/embeddeddolt/transaction.go index d1a8b1fb4..587afdc27 100644 --- a/internal/storage/embeddeddolt/transaction.go +++ b/internal/storage/embeddeddolt/transaction.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import ( diff --git a/internal/storage/embeddeddolt/version_control.go b/internal/storage/embeddeddolt/version_control.go index c6f6a7b94..90d438203 100644 --- a/internal/storage/embeddeddolt/version_control.go +++ b/internal/storage/embeddeddolt/version_control.go @@ -1,5 +1,3 @@ -//go:build embeddeddolt - package embeddeddolt import (