beads/internal/validation/template_test.go
kev ba284fd6e9 feat(lint): accept Acceptance Criteria heading for epics (#3834)
bd lint required "## Success Criteria" for epics but "## Acceptance
Criteria" for bug/task/feature/story. Agents repeatedly trip on this
epic-only exception. Now an epic satisfies the requirement with either
heading, while Success Criteria stays canonical for new epics.

The OR-rule lives in validation.ValidateTemplate: when the issue type is
epic and the missing required heading is "success criteria", a present
"acceptance criteria" heading also satisfies it. This is additive — every
existing Success-Criteria epic still passes — and it does NOT add a second
entry to RequiredSections (which would require BOTH headings). Because bd
lint, bd create --validate, and bd doctor --check=conventions all route
through ValidateTemplate, the fix covers all three.

The alias is epic-scoped: a feature/task/bug is still not satisfied by a
"Success Criteria" heading (covered by a regression test).

Updated lint --help and regenerated CLI_REFERENCE.md, website lint.md
(all versions), and llms-full.txt; freshness checks pass.

Non-goals: not changing the canonical heading for new epics; not relaxing
requirements for any other type.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 23:00:30 -04:00

357 lines
8.5 KiB
Go

package validation
import (
"strings"
"testing"
"github.com/steveyegge/beads/internal/types"
)
func TestValidateTemplate(t *testing.T) {
tests := []struct {
name string
issueType types.IssueType
description string
wantErr bool
wantMissing int // Number of missing sections expected
}{
// Bug type tests
{
name: "bug with all sections",
issueType: types.TypeBug,
description: `## Steps to Reproduce
1. Do this
2. Do that
## Acceptance Criteria
- Bug is fixed`,
wantErr: false,
},
{
name: "bug missing all sections",
issueType: types.TypeBug,
description: "This is broken",
wantErr: true,
wantMissing: 2,
},
{
name: "bug missing acceptance criteria",
issueType: types.TypeBug,
description: `## Steps to Reproduce
1. Click button
2. See error`,
wantErr: true,
wantMissing: 1,
},
{
name: "bug with case-insensitive headings",
issueType: types.TypeBug,
description: `## steps to reproduce
Click the button
## acceptance criteria
It works`,
wantErr: false,
},
{
name: "bug with inline mentions (no markdown)",
issueType: types.TypeBug,
description: `Steps to reproduce: click the button.
Acceptance criteria: it should work.`,
wantErr: false,
},
// Task type tests
{
name: "task with acceptance criteria",
issueType: types.TypeTask,
description: `## Acceptance Criteria
- [ ] Task complete`,
wantErr: false,
},
{
name: "task missing acceptance criteria",
issueType: types.TypeTask,
description: "Do the thing",
wantErr: true,
wantMissing: 1,
},
// Feature type tests
{
name: "feature with acceptance criteria",
issueType: types.TypeFeature,
description: `Add new widget
## Acceptance Criteria
Widget displays correctly`,
wantErr: false,
},
{
name: "feature missing acceptance criteria",
issueType: types.TypeFeature,
description: "Add a new feature",
wantErr: true,
wantMissing: 1,
},
// Epic type tests
{
name: "epic with success criteria",
issueType: types.TypeEpic,
description: `Big project
## Success Criteria
- Project ships
- Users happy`,
wantErr: false,
},
{
name: "epic missing success criteria",
issueType: types.TypeEpic,
description: "Do everything",
wantErr: true,
wantMissing: 1,
},
{
// GH#3834: epics accept "Acceptance Criteria" as an alias for the
// canonical "Success Criteria" heading.
name: "epic with acceptance criteria heading",
issueType: types.TypeEpic,
description: `Big project
## Acceptance Criteria
- Project ships
- Users happy`,
wantErr: false,
},
{
// The epic alias must not leak to other types: a feature still
// requires "Acceptance Criteria" and is not satisfied by "Success
// Criteria".
name: "feature not satisfied by success criteria",
issueType: types.TypeFeature,
description: "Ship it\n\n## Success Criteria\n- done",
wantErr: true,
wantMissing: 1,
},
// Types with no requirements
{
name: "chore has no requirements",
issueType: types.TypeChore,
description: "Update deps",
wantErr: false,
},
{
name: "message has no requirements",
issueType: "message",
description: "Hello",
wantErr: false,
},
{
name: "molecule has no requirements",
issueType: "molecule",
description: "",
wantErr: false,
},
// Edge cases
{
name: "empty description for bug",
issueType: types.TypeBug,
description: "",
wantErr: true,
wantMissing: 2,
},
{
name: "empty description for chore",
issueType: types.TypeChore,
description: "",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateTemplate(tt.issueType, tt.description)
if tt.wantErr {
if err == nil {
t.Errorf("ValidateTemplate() expected error, got nil")
return
}
templateErr, ok := err.(*TemplateError)
if !ok {
t.Errorf("ValidateTemplate() error type = %T, want *TemplateError", err)
return
}
if len(templateErr.Missing) != tt.wantMissing {
t.Errorf("ValidateTemplate() missing sections = %d, want %d",
len(templateErr.Missing), tt.wantMissing)
}
} else {
if err != nil {
t.Errorf("ValidateTemplate() unexpected error: %v", err)
}
}
})
}
}
func TestTemplateErrorMessage(t *testing.T) {
err := &TemplateError{
IssueType: types.TypeBug,
Missing: []MissingSection{
{Heading: "## Steps to Reproduce", Hint: "Describe how to reproduce"},
{Heading: "## Acceptance Criteria", Hint: "Define fix criteria"},
},
}
msg := err.Error()
if !strings.Contains(msg, "bug") {
t.Errorf("Error message should contain issue type, got: %s", msg)
}
if !strings.Contains(msg, "Steps to Reproduce") {
t.Errorf("Error message should contain missing heading, got: %s", msg)
}
if !strings.Contains(msg, "Describe how to reproduce") {
t.Errorf("Error message should contain hint, got: %s", msg)
}
}
func TestTemplateErrorEmpty(t *testing.T) {
err := &TemplateError{
IssueType: types.TypeBug,
Missing: nil,
}
if err.Error() != "" {
t.Errorf("Empty TemplateError should return empty string, got: %s", err.Error())
}
}
func TestLintIssue(t *testing.T) {
tests := []struct {
name string
issue *types.Issue
wantErr bool
}{
{
name: "nil issue",
issue: nil,
wantErr: false,
},
{
name: "valid bug",
issue: &types.Issue{
IssueType: types.TypeBug,
Description: "## Steps to Reproduce\nClick\n\n## Acceptance Criteria\nFixed",
},
wantErr: false,
},
{
name: "invalid bug",
issue: &types.Issue{
IssueType: types.TypeBug,
Description: "It's broken",
},
wantErr: true,
},
{
name: "bug with acceptance in dedicated field",
issue: &types.Issue{
IssueType: types.TypeBug,
Description: "## Steps to Reproduce\nClick button",
AcceptanceCriteria: "## Acceptance Criteria\nButton works",
},
wantErr: false,
},
{
name: "task with acceptance in dedicated field",
issue: &types.Issue{
IssueType: types.TypeTask,
Description: "Do the thing",
AcceptanceCriteria: "Acceptance Criteria: thing is done",
},
wantErr: false,
},
{
name: "task with plain-text acceptance field (no heading) GH#2468",
issue: &types.Issue{
IssueType: types.TypeTask,
Description: "Do the thing",
AcceptanceCriteria: "- Criterion one\n- Criterion two",
},
wantErr: false,
},
{
name: "feature with plain-text acceptance field (no heading) GH#2468",
issue: &types.Issue{
IssueType: types.TypeFeature,
Description: "Add new widget",
AcceptanceCriteria: "Widget displays correctly",
},
wantErr: false,
},
{
name: "epic with plain-text acceptance field satisfies success criteria GH#2468",
issue: &types.Issue{
IssueType: types.TypeEpic,
Description: "Big project",
AcceptanceCriteria: "Project ships and users happy",
},
wantErr: false,
},
{
name: "bug with plain-text acceptance field still needs steps GH#2468",
issue: &types.Issue{
IssueType: types.TypeBug,
Description: "Something is broken",
AcceptanceCriteria: "It should work",
},
wantErr: true,
},
{
name: "chore always valid",
issue: &types.Issue{
IssueType: types.TypeChore,
Description: "",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := LintIssue(tt.issue)
if (err != nil) != tt.wantErr {
t.Errorf("LintIssue() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestValidateCloseReason(t *testing.T) {
tests := []struct {
name string
reason string
wantErr bool
}{
{"empty reason", "", true},
{"default reason", "Closed", true},
{"default reason case insensitive", "closed", true},
{"terse reason", "fixed the bug", true},
{"adequate reason", "Fixed the login timeout by increasing session TTL to 24h", false},
{"exactly 20 chars", "12345678901234567890", false},
{"whitespace padded but terse", " done ", true},
{"whitespace padded but adequate", " Fixed the auth flow for SSO users ", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateCloseReason(tt.reason)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateCloseReason(%q) error = %v, wantErr %v", tt.reason, err, tt.wantErr)
}
})
}
}