beads/cmd/bd/protocol/input_validation_test.go
beads/crew/wickham 13190efbcc fix: reject empty title and empty label on update/label add (GH#1994)
- `bd update <id> --title ""` now errors instead of silently blanking
- `bd update <id> --title "   "` (whitespace-only) also rejected
- `bd label add <id> ""` now errors instead of adding empty label
- Values are trimmed before storage, not just for validation
- Includes fix for pre-existing doctor file formatting

Based on PR #1994 by @turian.

Co-Authored-By: Joseph Turian <turian@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 10:05:06 -08:00

59 lines
1.7 KiB
Go

package protocol
import (
"strings"
"testing"
)
// TestProtocol_UpdateRejectsEmptyTitle verifies that bd update --title ""
// exits non-zero rather than silently blanking the title.
func TestProtocol_UpdateRejectsEmptyTitle(t *testing.T) {
w := newWorkspace(t)
id := w.create("Test issue")
out, code := w.runExpectError("update", id, "--title", "")
if code != 1 {
t.Errorf("expected exit code 1, got %d", code)
}
if !strings.Contains(out, "title cannot be empty") {
t.Errorf("expected 'title cannot be empty' in output, got: %s", out)
}
}
// TestProtocol_UpdateRejectsWhitespaceTitle verifies that whitespace-only
// titles are rejected the same as empty titles.
func TestProtocol_UpdateRejectsWhitespaceTitle(t *testing.T) {
w := newWorkspace(t)
id := w.create("Test issue")
out, code := w.runExpectError("update", id, "--title", " ")
if code != 1 {
t.Errorf("expected exit code 1, got %d", code)
}
if !strings.Contains(out, "title cannot be empty") {
t.Errorf("expected 'title cannot be empty' in output, got: %s", out)
}
}
// TestProtocol_LabelAddRejectsEmptyLabel verifies that bd label add with
// an empty label exits non-zero.
func TestProtocol_LabelAddRejectsEmptyLabel(t *testing.T) {
w := newWorkspace(t)
id := w.create("Test issue")
out, code := w.runExpectError("label", "add", id, "")
if code != 1 {
t.Errorf("expected exit code 1, got %d", code)
}
if !strings.Contains(out, "label cannot be empty") {
t.Errorf("expected 'label cannot be empty' in output, got: %s", out)
}
}
// TestProtocol_LabelAddAcceptsValidLabel verifies no regression: adding
// a normal label still works.
func TestProtocol_LabelAddAcceptsValidLabel(t *testing.T) {
w := newWorkspace(t)
id := w.create("Test issue")
w.run("label", "add", id, "urgent")
}