fix(dep tree): match --format mermaid case-insensitively (#6646)

`bd dep tree --format Mermaid` fell through silently to the plain-text
renderer because the mermaid check was a raw string comparison while the
json check two lines earlier already folds case. Extract the check into
isMermaidTreeFormat and use strings.EqualFold, matching json.

Refs #6339

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Vishnu J 2026-09-26 09:03:58 -07:00 • committed by GitHub
commit ce512c3b2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View file

@ -517,6 +517,29 @@ func TestDepTreeFormatFlag(t *testing.T) {
}
}
// TestDepTreeFormatMermaidCaseInsensitive pins that --format mermaid folds case
// the same way the json format check does.
func TestDepTreeFormatMermaidCaseInsensitive(t *testing.T) {
tests := []struct {
format string
want bool
}{
{"mermaid", true},
{"Mermaid", true},
{"MERMAID", true},
{"", false},
{"json", false},
{"dot", false},
}
for _, tt := range tests {
t.Run(tt.format, func(t *testing.T) {
if got := isMermaidTreeFormat(tt.format); got != tt.want {
t.Errorf("isMermaidTreeFormat(%q) = %v, want %v", tt.format, got, tt.want)
}
})
}
}
func TestGetStatusEmoji(t *testing.T) {
tests := []struct {
status types.Status

View file

@ -80,6 +80,11 @@ func proxiedTreeTarget(ctx context.Context, arg string) (treeTarget, error) {
return treeTarget{rootID: rootID, walker: walker, cleanup: func() {}}, nil
}
// isMermaidTreeFormat reports whether --format selects the mermaid renderer.
func isMermaidTreeFormat(formatStr string) bool {
return strings.EqualFold(formatStr, "mermaid")
}
// runDepTree is the whole of `bd dep tree` on both routes.
func runDepTree(cmd *cobra.Command, ctx context.Context, args []string) error {
maxDepth, _ := cmd.Flags().GetInt("max-depth")
@ -145,7 +150,7 @@ func runDepTree(cmd *cobra.Command, ctx context.Context, args []string) error {
tree := result.Nodes
// Handle format presets (json handled earlier, near the flag read).
if formatStr == "mermaid" {
if isMermaidTreeFormat(formatStr) {
// The raw argument, not the resolved id: this is only read when the tree
// is empty.
outputMermaidTree(tree, args[0])