beads/cmd/bd/protocol/comments_test.go
Joseph Turian d3e581bc0b fix: reject empty and whitespace-only comment text
bd comments add accepted empty ("") and whitespace-only ("   ") text,
silently creating blank comments. Now validates with strings.TrimSpace
before storing, consistent with the empty-title validation on update.

Includes protocol test verifying both empty and whitespace-only text
are rejected with a non-zero exit code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 04:52:58 -05:00

24 lines
711 B
Go

package protocol
import "testing"
// TestProtocol_CommentRejectsEmptyText asserts that bd comments add rejects
// empty and whitespace-only comment text with a non-zero exit code.
func TestProtocol_CommentRejectsEmptyText(t *testing.T) {
w := newWorkspace(t)
id := w.create("--title", "Comment target", "--type", "task")
t.Run("empty", func(t *testing.T) {
_, err := w.tryRun("comments", "add", id, "")
if err == nil {
t.Error("bd comments add with empty text should fail but exited 0")
}
})
t.Run("whitespace", func(t *testing.T) {
_, err := w.tryRun("comments", "add", id, " ")
if err == nil {
t.Error("bd comments add with whitespace-only text should fail but exited 0")
}
})
}