beads/cmd/bd/helpers_test.go
Bee 3571331b50
test: fixtures commit with maintenance.auto=false before every git worktree add (wy-7ocweu) (#7358)
Fixes #7349. The same race #7314 closed in internal/beads and
internal/config, in the fixtures it did not cover: a fixture's plain
`git commit` spawns the detached `git maintenance run --auto` child, whose
worktree-prune races the fixture's next `git worktree add` and deletes
.git/worktrees/<name>/locked under it (seen on PR #7312 run 37585997441,
cmd/bd Dolt-server tier shard 4/16, TestBootstrap_WorktreeFallbackDir).

One noAutoMaintenance + gitCommand(args...) helper per test package, each
in an existing untagged shared test file (cmd/bd/helpers_test.go,
doctor/git_test_helpers_test.go, doctor/fix/common_test.go,
formula/parser_test.go, git/gitdir_test.go, storage/domain/git/git_test.go;
cmd/bd/test_helpers_test.go is //go:build cgo so unusable for the pure
lane), and every inline exec.Command("git", ...) in those six packages
swapped for it. The flags ride the command line, never env config: the
routing-key scrub drops env config. No new files, so no BUILD.bazel rows.

Proof: GIT_TRACE on `go test ./cmd/bd -run TestBootstrap_WorktreeFallbackDir`
counts 3 `maintenance run --auto` spawns at d8d8bf587b and 0 with this
change.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-08 08:01:46 +00:00

76 lines
2 KiB
Go

package main
import (
"os/exec"
"testing"
"github.com/steveyegge/beads/internal/utils"
)
func TestIsNumericID_EdgeCases(t *testing.T) {
tests := []struct {
input string
expected bool
}{
{"0", true},
{"123", true},
{"999", true},
{"abc", false},
{"", false},
{"12a", false},
}
for _, tt := range tests {
result := isNumericID(tt.input)
if result != tt.expected {
t.Errorf("isNumericID(%q) = %v, want %v", tt.input, result, tt.expected)
}
}
}
func TestGetWorktreeGitDir(_ *testing.T) {
gitDir := getWorktreeGitDir()
// Just verify it doesn't panic and returns a string
_ = gitDir
}
func TestExtractPrefix(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"bd-123", "bd"},
{"custom-1", "custom"},
{"TEST-999", "TEST"},
{"no-number", "no"}, // Has hyphen, suffix not numeric, first hyphen
{"nonumber", ""}, // No hyphen
{"", ""},
// Multi-part non-numeric suffixes (bd-fasa regression tests)
{"vc-baseline-test", "vc"},
{"vc-92cl-gate-test", "vc"},
{"bd-multi-part-id", "bd"},
{"prefix-a-b-c-d", "prefix"},
// Multi-part prefixes with numeric suffixes
{"beads-vscode-1", "beads-vscode"},
{"alpha-beta-123", "alpha-beta"},
{"my-project-42", "my-project"},
}
for _, tt := range tests {
result := utils.ExtractIssuePrefix(tt.input)
if result != tt.expected {
t.Errorf("ExtractIssuePrefix(%q) = %q, want %q", tt.input, result, tt.expected)
}
}
}
// noAutoMaintenance keeps a fixture's git commit from spawning the detached
// "git maintenance run --auto" child whose worktree-prune races the fixture's
// next "git worktree add" (gastownhall/beads#7314, #7349). Flags ride the
// command line, never env config: the routing-key scrub drops env config.
var noAutoMaintenance = []string{"-c", "maintenance.auto=false", "-c", "gc.auto=0"}
// gitCommand builds a git command for a fixture with noAutoMaintenance applied.
func gitCommand(args ...string) *exec.Cmd {
return exec.Command("git", append(append([]string{}, noAutoMaintenance...), args...)...)
}