* fix(config): reject 'bd config set issue-prefix' with actionable error 'bd config set' landed the value in DB key "issue-prefix" (dash), while 'bd create' reads YAML "issue-prefix" then DB "issue_prefix" (underscore) — a third key no reader consults. The result was a silent-success write that left users unable to create issues after what looked like a successful config change (bd-f4m). Reject both dash and underscore forms at the top of the config-set handler and point the user at the three commands that own the prefix lifecycle (bd init --prefix / bd bootstrap / bd rename-prefix). A unit test locks in the rejected keys, the required error substrings, and a control set of adjacent keys that must continue to work. * fix(errors): mention 'bd bootstrap' in 'issue_prefix is missing' hint The fresh-clone flow lands here when a user clones a repo but has no local database yet. The existing hint only mentioned 'bd init --prefix', which is the wrong answer for that scenario — 'bd bootstrap' is what reconstitutes a database from the remote. Add it to the hint alongside 'bd init --prefix' so both the new-project and fresh-clone paths are directed at the right command (bd-f4m, AC bullet 4). * fix(config): drop private tracker IDs from issue-prefix rejection comments Strips internal bead tracker IDs from code comments and a test message. Private tracker IDs have no meaning to external reviewers, so they should not ship in the repository. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsRecognizedConfigKey(t *testing.T) {
|
|
recognized := []string{
|
|
"export.auto", "dolt.auto-push", "jira.url", "custom.anything",
|
|
"doctor.suppress.git-hooks", "no-git-ops", "beads.role",
|
|
"status.custom", "ai.model", "backup.enabled",
|
|
}
|
|
for _, key := range recognized {
|
|
if !isRecognizedConfigKey(key) {
|
|
t.Errorf("isRecognizedConfigKey(%q) = false, want true", key)
|
|
}
|
|
}
|
|
|
|
unrecognized := []string{
|
|
"totally.bogus", "exprot.auto", "xport.path", "nodb",
|
|
}
|
|
for _, key := range unrecognized {
|
|
if isRecognizedConfigKey(key) {
|
|
t.Errorf("isRecognizedConfigKey(%q) = true, want false", key)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSuggestConfigKey(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
want string
|
|
}{
|
|
{"exprot.auto", "export.auto"},
|
|
{"exoprt.path", "export.path"},
|
|
{"totally.bogus", ""},
|
|
}
|
|
for _, tt := range tests {
|
|
got := suggestConfigKey(tt.input)
|
|
if got != tt.want {
|
|
t.Errorf("suggestConfigKey(%q) = %q, want %q", tt.input, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRejectProtectedConfigKey(t *testing.T) {
|
|
rejectedKeys := []string{"issue_prefix", "issue-prefix"}
|
|
for _, key := range rejectedKeys {
|
|
msg, rejected := rejectProtectedConfigKey(key)
|
|
if !rejected {
|
|
t.Errorf("rejectProtectedConfigKey(%q) = (_, false), want rejected", key)
|
|
continue
|
|
}
|
|
// Error message must surface the three lifecycle alternatives.
|
|
wantSubstrings := []string{"bd init --prefix", "bd bootstrap", "bd rename-prefix"}
|
|
for _, want := range wantSubstrings {
|
|
if !strings.Contains(msg, want) {
|
|
t.Errorf("rejectProtectedConfigKey(%q) message missing %q; got:\n%s", key, want, msg)
|
|
}
|
|
}
|
|
}
|
|
|
|
allowedKeys := []string{"allowed_prefixes", "export.auto", "status.custom", "custom.anything"}
|
|
for _, key := range allowedKeys {
|
|
if _, rejected := rejectProtectedConfigKey(key); rejected {
|
|
t.Errorf("rejectProtectedConfigKey(%q) = (_, true), want not rejected", key)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLevenshteinDistance(t *testing.T) {
|
|
tests := []struct {
|
|
a, b string
|
|
want int
|
|
}{
|
|
{"", "", 0},
|
|
{"abc", "abc", 0},
|
|
{"abc", "abd", 1},
|
|
{"export", "exprot", 2},
|
|
{"dolt", "bolt", 1},
|
|
{"abc", "", 3},
|
|
}
|
|
for _, tt := range tests {
|
|
got := levenshteinDistance(tt.a, tt.b)
|
|
if got != tt.want {
|
|
t.Errorf("levenshteinDistance(%q, %q) = %d, want %d", tt.a, tt.b, got, tt.want)
|
|
}
|
|
}
|
|
}
|