Skip to content

fix(init): sanitize dots in metadata.json DoltDatabase and add early validation (#3128)#3129

Merged
maphew merged 3 commits intogastownhall:mainfrom
jjgarzella:fix/init-invalid-dbname-dots
Apr 10, 2026
Merged

fix(init): sanitize dots in metadata.json DoltDatabase and add early validation (#3128)#3129
maphew merged 3 commits intogastownhall:mainfrom
jjgarzella:fix/init-invalid-dbname-dots

Conversation

@jjgarzella
Copy link
Copy Markdown
Contributor

Summary

Fixes #3128bd init in a directory with dots in its name (e.g. GPUPolynomials.jl, common in Julia development) silently produced a broken installation: the database was created under one name but metadata.json recorded a different name, causing every subsequent bd command to fail with a cryptic invalid database name error.

Root Cause

Two bugs in cmd/bd/init.go:

Bug 1 — metadata.json mismatch:
dbName sanitized both hyphens and dots → underscores (lines 430–431), but cfg.DoltDatabase (written to metadata.json) only sanitized hyphens (line 666). The comment above line 430 explicitly warns these must match — they didn't.

Bug 2 — unclear error for unsanitizable characters:
Characters like spaces, @, ! that survive all sanitization caused an error deep inside the storage layer with no actionable guidance.

Changes

  • cmd/bd/init.go line 666: add dot → underscore replacement to cfg.DoltDatabase to match dbName sanitization
  • cmd/bd/init.go after line 440: add early dolt.ValidateDatabaseName check with clear error message and --prefix hint when the auto-derived name is invalid

Before / After

Before:

$ cd GPUPolynomials.jl && bd init --quiet && bd list
Error: failed to open database: invalid database name "GPUPolynomials.jl"

After (dots — silently fixed):

$ cd GPUPolynomials.jl && bd init --quiet && bd list
No issues found.

After (unsanitizable chars — clear error):

$ cd "my project" && bd init --quiet
Error: directory name "my project" produces an invalid database name "my project".
Re-run with a valid prefix: bd init --prefix <name>
(Database names must start with a letter or underscore and contain only letters, digits, underscores, or hyphens.)

Test Plan

  • bd init in a *.jl directory succeeds and bd list works after
  • metadata.json dolt_database field contains no dots after init in dotted directory
  • bd init in a directory with a space fails immediately with message containing --prefix
  • Existing --database flag validation path unaffected
  • bd init --prefix myname in any directory still works as before

Note: this is JJ's first time making a PR to beads with an AI agent, so if anything is wrong, we would appreciate feedback!

🤖 Generated with Claude Code

jjgarzella and others added 3 commits April 8, 2026 15:26
…validation

Two bugs in bd init when the directory name contains characters that are
invalid or non-standard in Dolt/MySQL identifiers:

1. metadata.json mismatch: dbName sanitized hyphens AND dots to underscores
   (lines 430-431), but cfg.DoltDatabase only sanitized hyphens (line 666).
   This caused bd init in e.g. GPUPolynomials.jl to create a database named
   GPUPolynomials_jl but record dolt_database: "GPUPolynomials.jl" in
   metadata.json, breaking every subsequent command with a cryptic
   "invalid database name" error.

   Fix: add dot replacement to cfg.DoltDatabase to match dbName sanitization.

2. No early validation for characters that survive sanitization (spaces, @,
   etc.): errors came from deep in the storage layer with no actionable hint.

   Fix: validate dbName with dolt.ValidateDatabaseName after it is computed;
   if invalid, fail immediately with a clear message:
     Error: directory name "my project" produces an invalid database name "my project".
     Re-run with a valid prefix: bd init --prefix <name>

Fixes gastownhall#3128

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ation

- prefix_dot_sanitized: verifies that --prefix GPUPolynomials.jl writes
  DoltDatabase "GPUPolynomials_jl" to metadata.json (not "GPUPolynomials.jl")
- invalid_dirname_errors_early: verifies that a directory whose name
  contains a space exits non-zero with an actionable error message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verifies that bd init in a directory named like MyPkg.jl (no --prefix)
auto-detects the name, sanitizes the dot in metadata.json DoltDatabase,
and that bd list succeeds immediately after — confirming the stored name
matches the actual Dolt database.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@maphew maphew merged commit f3d4293 into gastownhall:main Apr 10, 2026
@maphew
Copy link
Copy Markdown
Collaborator

maphew commented Apr 10, 2026

Thanks @jjgarzella — great first PR to beads! 🎉

Clean fix, solid tests, and the error message for unsanitizable directory names is a really nice touch. Welcome aboard!

maphew pushed a commit that referenced this pull request Apr 20, 2026
…3231) (#3232)

Auto-sanitize hyphenated `dolt_database` names on embedded-mode upgrade. Projects initialized before #2142 retain hyphenated names in `metadata.json`; after the 1.0.0 embedded-mode default flip, those names are rejected by the embedded Dolt engine. This change detects legacy names on store open, renames the database directory, persists the fix to `metadata.json`, and adds a doctor check + init guard for future prevention.

Closes #3231. Related: #2142, #2160, #3128, #3129.

Thanks @kevglynn for the thorough fix, migration safety (collision detection, crash-safe ordering), and test coverage.
mzlee pushed a commit to mzlee/beads that referenced this pull request Apr 22, 2026
…astownhall#3231) (gastownhall#3232)

Auto-sanitize hyphenated `dolt_database` names on embedded-mode upgrade. Projects initialized before gastownhall#2142 retain hyphenated names in `metadata.json`; after the 1.0.0 embedded-mode default flip, those names are rejected by the embedded Dolt engine. This change detects legacy names on store open, renames the database directory, persists the fix to `metadata.json`, and adds a doctor check + init guard for future prevention.

Closes gastownhall#3231. Related: gastownhall#2142, gastownhall#2160, gastownhall#3128, gastownhall#3129.

Thanks @kevglynn for the thorough fix, migration safety (collision detection, crash-safe ordering), and test coverage.
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.

fix(init): bd init silently corrupts metadata when directory name contains dots (e.g. Julia packages)

2 participants