fix(import): respect import.auto=false in the empty-DB import-on-write path (#4595)
* fix(import): respect import.auto=false on empty DB in bd update (fixes #4304, mybd-3fvn) shouldRunAutoImportJSONL gated the empty-database upgrade-recovery auto-import (maybeAutoImportJSONL, GH#2994) on read-only/global/server-mode flags only. It never consulted the import.auto config key, so BD_IMPORT_AUTO=false (or import.auto: false in config.yaml) had no effect on this path -- only the separate git-hook sync importer (importJSONLForSync) honored it. Any write command (e.g. bd update) against a fresh/empty database with a stale issues.jsonl present would silently auto-import it and report success, exactly as reported in #4304. Add the missing config.GetBool("import.auto") check to shouldRunAutoImportJSONL. Explicit `bd import` is unaffected: it already short-circuits on cmd.Name() == "import" regardless of this flag. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FWVnjn3Bq4PSG1akpFpKnY Agent-Signature: claude-sonnet-5-medium on behalf of matt wilkie * fix(config): route import.auto through YAML config bd config set import.auto previously treated the startup gate as a database-backed key, so the value landed where the auto-import checks never read it. Mark it YAML-only like import.path and cover both direct and config set-many routing tables. Agent-Signature: codex-gpt-5.5-high on behalf of matt wilkie * fix(config): exempt config-set of import.auto=false from pre-run auto-import Running `bd config set import.auto false` (or `config set-many ... import.auto=false`) triggered the very auto-import it was meant to disable: shouldRunAutoImportJSONL runs in PersistentPreRun before the config command writes the new value, so it still saw the old default (true) and imported first when a stale .beads/issues.jsonl sat next to an empty database. Add isDisablingImportAutoViaConfigCommand to detect this specific invocation and skip the pre-run import so the master switch takes effect on the same command that sets it. Addresses Codex cross-vendor review finding (2026-07-07) on PR #4595 (mybd-ycu4). Agent-Signature: claude-fable-5-high on behalf of matt wilkie --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
02c6c2d433
commit
75d3d9593d
6 changed files with 121 additions and 3 deletions
|
|
@ -162,6 +162,7 @@ func TestMaybeAutoImportJSONL_FallbackImporter_SkipsWhenStatisticsReportNonEmpty
|
|||
}
|
||||
|
||||
func TestShouldRunAutoImportJSONL(t *testing.T) {
|
||||
initConfigForTest(t)
|
||||
store := &fakeFallbackStore{}
|
||||
writeCmd := &cobra.Command{Use: "update"}
|
||||
|
||||
|
|
@ -193,6 +194,79 @@ func TestShouldRunAutoImportJSONL(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestShouldRunAutoImportJSONL_RespectsImportAutoFalse is the regression test
|
||||
// for GH#4304: bd update (and any other write command) auto-imported
|
||||
// issues.jsonl into an empty database even when import.auto was explicitly
|
||||
// set to false (via config.yaml or BD_IMPORT_AUTO=false). shouldRunAutoImportJSONL
|
||||
// previously never consulted the import.auto config key at all — only the
|
||||
// separate git-hook sync path (importJSONLForSync) checked it. This test fails
|
||||
// on the buggy code (want=true) and passes once the config check is restored.
|
||||
func TestShouldRunAutoImportJSONL_RespectsImportAutoFalse(t *testing.T) {
|
||||
initConfigForTest(t)
|
||||
store := &fakeFallbackStore{}
|
||||
writeCmd := &cobra.Command{Use: "update"}
|
||||
importCmd := &cobra.Command{Use: "import"}
|
||||
|
||||
config.Set("import.auto", false)
|
||||
if got := shouldRunAutoImportJSONL(writeCmd, store, false, false, false); got {
|
||||
t.Fatalf("regression GH#4304: shouldRunAutoImportJSONL() = %v with import.auto=false, want false", got)
|
||||
}
|
||||
// The explicit "bd import" command must remain unaffected either way —
|
||||
// confirm it's still gated off (for a different reason) so the config
|
||||
// check above isn't the only thing keeping it from double-running.
|
||||
if got := shouldRunAutoImportJSONL(importCmd, store, false, false, false); got {
|
||||
t.Fatalf("shouldRunAutoImportJSONL() = %v for the import command with import.auto=false, want false", got)
|
||||
}
|
||||
|
||||
config.Set("import.auto", true)
|
||||
if got := shouldRunAutoImportJSONL(writeCmd, store, false, false, false); !got {
|
||||
t.Fatalf("shouldRunAutoImportJSONL() = %v with import.auto=true, want true (negative control)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestIsDisablingImportAutoViaConfigCommand is the regression test for the
|
||||
// P2 finding on gastownhall/beads#4595 (Codex cross-vendor review,
|
||||
// 2026-07-07): shouldRunAutoImportJSONL runs in PersistentPreRun before
|
||||
// "bd config set import.auto false" writes the new value, so the command
|
||||
// meant to disable auto-import triggered it on its own invocation whenever a
|
||||
// stale .beads/issues.jsonl sat next to an empty database (GH#4304). This
|
||||
// exemption must fire for "config set import.auto false"/"0" and for
|
||||
// "config set-many ... import.auto=false", but not for unrelated config
|
||||
// keys, truthy values, or commands outside the config subtree.
|
||||
func TestIsDisablingImportAutoViaConfigCommand(t *testing.T) {
|
||||
configCmd := &cobra.Command{Use: "config"}
|
||||
setCmd := &cobra.Command{Use: "set"}
|
||||
setManyCmd := &cobra.Command{Use: "set-many"}
|
||||
configCmd.AddCommand(setCmd, setManyCmd)
|
||||
writeCmd := &cobra.Command{Use: "update"}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
cmd *cobra.Command
|
||||
args []string
|
||||
want bool
|
||||
}{
|
||||
{name: "config set import.auto false", cmd: setCmd, args: []string{"import.auto", "false"}, want: true},
|
||||
{name: "config set import.auto 0", cmd: setCmd, args: []string{"import.auto", "0"}, want: true},
|
||||
{name: "config set import.auto true", cmd: setCmd, args: []string{"import.auto", "true"}, want: false},
|
||||
{name: "config set other key", cmd: setCmd, args: []string{"export.auto", "false"}, want: false},
|
||||
{name: "config set-many import.auto=false", cmd: setManyCmd, args: []string{"jira.url=x", "import.auto=false"}, want: true},
|
||||
{name: "config set-many import.auto=true", cmd: setManyCmd, args: []string{"import.auto=true"}, want: false},
|
||||
{name: "unrelated command", cmd: writeCmd, args: []string{"import.auto", "false"}, want: false},
|
||||
{name: "set without config parent", cmd: &cobra.Command{Use: "set"}, args: []string{"import.auto", "false"}, want: false},
|
||||
{name: "nil command", cmd: nil, args: []string{"import.auto", "false"}, want: false},
|
||||
{name: "too few args", cmd: setCmd, args: []string{"import.auto"}, want: false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := isDisablingImportAutoViaConfigCommand(tt.cmd, tt.args); got != tt.want {
|
||||
t.Fatalf("isDisablingImportAutoViaConfigCommand(%v, %v) = %v, want %v", tt.cmd, tt.args, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMaybeAutoImportJSONL_FallbackImporter_SkipsWhenStatisticsNil covers
|
||||
// the defensive nil-statistics guard: if the store reports no error but also
|
||||
// no counts, auto-import should skip rather than panic or assume emptiness.
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ func TestConfigSetManyArgParsing(t *testing.T) {
|
|||
// TestConfigSetManyYamlKeyDetection tests that yaml-only keys are correctly identified
|
||||
// for routing in the set-many command.
|
||||
func TestConfigSetManyYamlKeyDetection(t *testing.T) {
|
||||
yamlKeys := []string{"no-db", "json", "routing.mode", "routing.default", "no-push", "import.path"}
|
||||
yamlKeys := []string{"no-db", "json", "routing.mode", "routing.default", "no-push", "import.auto", "import.path"}
|
||||
for _, key := range yamlKeys {
|
||||
if !config.IsYamlOnlyKey(key) {
|
||||
t.Errorf("expected %q to be yaml-only", key)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"runtime/pprof"
|
||||
"runtime/trace"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
|
@ -1229,7 +1230,8 @@ var rootCmd = &cobra.Command{
|
|||
// Skip auto-import when the user is explicitly running "bd import" —
|
||||
// the import command handles JSONL files itself and auto-importing
|
||||
// first would interfere (double-import / upsert confusion).
|
||||
if shouldRunAutoImportJSONL(cmd, store, useReadOnly, globalFlag, doltCfg.ServerMode) {
|
||||
if shouldRunAutoImportJSONL(cmd, store, useReadOnly, globalFlag, doltCfg.ServerMode) &&
|
||||
!isDisablingImportAutoViaConfigCommand(cmd, args) {
|
||||
maybeAutoImportJSONL(rootCtx, store, beadsDir)
|
||||
}
|
||||
|
||||
|
|
@ -1388,9 +1390,49 @@ func shouldRunAutoImportJSONL(cmd *cobra.Command, s storage.DoltStorage, useRead
|
|||
if cmd == nil || s == nil || useReadOnly || globalFlag || serverMode {
|
||||
return false
|
||||
}
|
||||
// import.auto=false (or BD_IMPORT_AUTO=false) must disable ALL auto-import
|
||||
// behavior, not just the git-hook sync path (importJSONLForSync). Without
|
||||
// this check, a fresh/empty database would silently auto-import stale
|
||||
// issues.jsonl on every write command regardless of the config setting
|
||||
// (GH#4304).
|
||||
if !config.GetBool("import.auto") {
|
||||
return false
|
||||
}
|
||||
return cmd.Name() != "import"
|
||||
}
|
||||
|
||||
// isDisablingImportAutoViaConfigCommand reports whether the command about to
|
||||
// run is "bd config set import.auto false" (or an equivalent
|
||||
// "bd config set-many ... import.auto=false" pair). shouldRunAutoImportJSONL
|
||||
// runs in PersistentPreRun before configSetCmd/configSetManyCmd write the new
|
||||
// value to config.yaml, so without this exemption the master switch would
|
||||
// trigger the very auto-import it is meant to disable on its own invocation
|
||||
// when a stale .beads/issues.jsonl sits next to an empty database (GH#4304).
|
||||
func isDisablingImportAutoViaConfigCommand(cmd *cobra.Command, args []string) bool {
|
||||
if cmd == nil || cmd.Parent() == nil || cmd.Parent().Name() != "config" {
|
||||
return false
|
||||
}
|
||||
switch cmd.Name() {
|
||||
case "set":
|
||||
return len(args) >= 2 && args[0] == "import.auto" && isFalsyConfigValue(args[1])
|
||||
case "set-many":
|
||||
for _, arg := range args {
|
||||
key, value, ok := strings.Cut(arg, "=")
|
||||
if ok && key == "import.auto" && isFalsyConfigValue(value) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// isFalsyConfigValue reports whether a config value string parses as a
|
||||
// boolean false (e.g. "false", "0", "f").
|
||||
func isFalsyConfigValue(value string) bool {
|
||||
parsed, err := strconv.ParseBool(value)
|
||||
return err == nil && !parsed
|
||||
}
|
||||
|
||||
func commandAllowsEmptyAutoExport(cmd *cobra.Command) bool {
|
||||
if cmd == nil {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -360,7 +360,7 @@ Configuration keys use dot-notation namespaces to organize settings:
|
|||
- `export.skip_encoding_errors` - Skip issues that fail JSON encoding (default: false)
|
||||
- `export.write_manifest` - Write .manifest.json with export metadata (default: false)
|
||||
- `auto_export.error_policy` - Override error policy for auto-exports (default: `best-effort`)
|
||||
- `import.auto` - Legacy hook fallback that imports JSONL after git merge/checkout only when no Dolt remote is configured (default: `true`)
|
||||
- `import.auto` - Master switch for automatic JSONL imports (default: `true`). Gates both the legacy hook fallback that imports JSONL after git merge/checkout when no Dolt remote is configured, and the empty-database recovery import that write commands run when `.beads/issues.jsonl` exists but the database is empty. Set to `false` to disable all auto-imports; explicit `bd import` always works.
|
||||
- `sync.branch` - Name of the dedicated sync branch for beads data (see docs/PROTECTED_BRANCHES.md)
|
||||
- `sync.require_confirmation_on_mass_delete` - Require interactive confirmation before pushing when >50% of issues vanish during a merge AND more than 5 issues existed before (default: `false`)
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ var YamlOnlyKeys = map[string]bool{
|
|||
"backup.git-repo": true,
|
||||
|
||||
// Import settings
|
||||
"import.auto": true,
|
||||
"import.path": true,
|
||||
|
||||
// Dolt server settings
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ func TestIsYamlOnlyKey(t *testing.T) {
|
|||
{"backup.future-key", true}, // prefix match
|
||||
|
||||
// Import settings
|
||||
{"import.auto", true},
|
||||
{"import.path", true},
|
||||
{"import.orphan_handling", false},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue