Skip to content

fix: handle BEADS_DB pointing to directory instead of file - #2549

Merged
maphew merged 1 commit into
gastownhall:mainfrom
cwalv:fix/beads-db-directory-path
Mar 13, 2026
Merged

maphew merged 1 commit into
gastownhall:mainfrom
cwalv:fix/beads-db-directory-path

Conversation

@cwalv

@cwalv cwalv commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix FindDatabasePath() to detect when BEADS_DB points to a directory and delegate to findDatabaseInBeadsDir(), matching BEADS_DIR behavior
  • Add regression tests for the directory and trailing-slash cases

Fixes #2548

Problem

When BEADS_DB is set to a directory path (like .beads/), FindDatabasePath() returns the directory itself. The caller at main.go:476 does beadsDir := filepath.Dir(dbPath), which strips one level too many — yielding the parent of .beads/ instead of .beads/. This causes:

  • ResolveDoltDir() to create a stray dolt/ directory at the parent level
  • A second dolt server to start in the wrong location
  • "database not found" errors on all subsequent commands

The BEADS_DIR code path works correctly because findDatabaseInBeadsDir() returns .beads/dolt (a path inside .beads/), so filepath.Dir() yields .beads/.

Fix

When BEADS_DB points to a directory (not a file), treat it like BEADS_DIR by calling findDatabaseInBeadsDir() to look for the database inside it. This is a 6-line change in internal/beads/beads.go.

Test plan

  • TestFindDatabasePath_BEADS_DB_Directory — verifies filepath.Dir(FindDatabasePath()) resolves to .beads/ for both BEADS_DIR and BEADS_DB-as-directory (failed before fix, passes after)
  • TestFindDatabasePath_BEADS_DB_DirectoryTrailingSlash — verifies trailing slash doesn't bypass the fix
  • All existing FindDatabasePath tests pass (-short mode)
  • golangci-lint passes with 0 issues

When BEADS_DB is set to a directory path (like .beads/) rather than a
.db file, FindDatabasePath() returned the directory itself. The caller
at main.go:476 does filepath.Dir(dbPath) to derive beadsDir, which
resolves one level too high when dbPath is a directory — creating stray
dolt/ directories and broken server connections.

Fix: when BEADS_DB points to a directory, treat it like BEADS_DIR by
calling findDatabaseInBeadsDir() to return the dolt/ subdirectory path.
This makes filepath.Dir() in the caller resolve correctly.

Includes two regression tests:
- TestFindDatabasePath_BEADS_DB_Directory: verifies BEADS_DB pointing
  to a directory produces the same filepath.Dir() result as BEADS_DIR
- TestFindDatabasePath_BEADS_DB_DirectoryTrailingSlash: verifies
  trailing slash doesn't change the outcome

Fixes #2548
@maphew
maphew merged commit c5cb9f6 into gastownhall:main Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BEADS_DB pointing to directory causes filepath.Dir() to resolve one level too high

2 participants