gitgram/aitimemachine/beads/cmd/bd/config_validate_key_test.go
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

98 lines
2.6 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", "import.path",
"dolt.local-only",
}
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 TestConfigHelpMentionsDoltLocalOnly(t *testing.T) {
if !strings.Contains(configCmd.Long, "bd config set dolt.local-only true") {
t.Fatalf("config help missing dolt.local-only example:\n%s", configCmd.Long)
}
}
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)
}
}
}