Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions internal/ergo/plan_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import (
"strings"
)

var knownPlanJSONFields = []string{
var knownPlanTopLevelJSONFields = []string{
"title",
"body",
"tasks",
"after",
}

// PlanInput is the JSON schema for `ergo plan`.
Expand Down Expand Up @@ -61,7 +60,7 @@ func ParsePlanInput() (*PlanInput, *ValidationError) {
invalid := map[string]string{
unknownField: "unknown field",
}
if suggestion, ok := suggestFieldNameFrom(unknownField, knownPlanJSONFields); ok {
if suggestion, ok := suggestFieldNameFrom(unknownField, knownPlanTopLevelJSONFields); ok {
message = fmt.Sprintf("invalid JSON: unknown field %q (did you mean: %s?)", unknownField, suggestion)
invalid[unknownField] = fmt.Sprintf("unknown field (did you mean: %s?)", suggestion)
}
Expand Down
16 changes: 16 additions & 0 deletions internal/ergo/plan_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ func TestParsePlanInput_RejectsUnknownNestedField_WithSuggestion(t *testing.T) {
}
}

func TestParsePlanInput_UnknownTopLevelDoesNotSuggestNestedField(t *testing.T) {
restoreStdin := setStdin(t, `{"title":"Epic","tasks":[{"title":"A"}],"aftr":"x"}`)
defer restoreStdin()

_, err := ParsePlanInput()
if err == nil {
t.Fatal("expected parse error for unknown field, got nil")
}
if err.Error != "parse_error" {
t.Fatalf("expected parse_error, got %q", err.Error)
}
if strings.Contains(err.Message, "did you mean: after") {
t.Fatalf("expected no suggestion for nested-only field, got %q", err.Message)
}
}

func TestParsePlanInput_RejectsMultipleJSONValues(t *testing.T) {
restoreStdin := setStdin(t, `{"title":"Epic","tasks":[{"title":"A"}]}{"title":"Extra"}`)
defer restoreStdin()
Expand Down