oficina / equipo Public

wire: a taste answer taps at most two feels (MaxFeelChoices)

Review fix (Task 1, round 1): ValidTasteAnswer let an answer carry up
to MaxFeels (5) tapped feels; spec 8.6 allows two choices among up to
five offered. MaxFeels stays the offered-list bound (ValidFeels); the
new MaxFeelChoices = 2 bounds an answer's selections.

TDD evidence
- go test ./internal/wire/ -run TestValidTasteAnswer
  RED: "design_feedback_test.go:191: three feels: <nil>" (constant
  added, guard not yet). GREEN: go test ./internal/wire/... ok.
- Mutations, each KILLED: guard removed (four feels: <nil>); limit
  MaxFeels (three feels: <nil>); limit MaxFeelChoices+1 (three feels:
  <nil>); >= instead of > (two tapped feels refused).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 8fcad49010dfd4c5bb6f72d4d8740040a288fd16 parent 4b5dd9a
2 files changed, +28 −6
  • internal/wire/design.go +11 −3
  • internal/wire/design_feedback_test.go +17 −3
diff --git a/internal/wire/design.go b/internal/wire/design.go
index 7dde7ef4..b2a0e8df 100644
--- a/internal/wire/design.go
+++ b/internal/wire/design.go
@@ -480,6 +480,9 @@ const (
// discovery answer's).
MaxFeel = 30
MaxFeels = 5
+ // MaxFeelChoices is how many of the offered feels a discovery
+ // answer may tap (spec section 8.6: up to two).
+ MaxFeelChoices = 2
// MaxTasteBox bounds each discovery box, in characters.
MaxTasteBox = 300
// maxPage bounds an option's page folder, in bytes; maxCapturePath a
@@ -547,7 +550,8 @@ const (
)
// TasteAnswer is a discovery card's answers (AnswerCard.Taste, and the
-// Add card's): Feels the labels the person tapped among those offered,
+// Add card's): Feels the labels the person tapped among those offered
+// (at most MaxFeelChoices),
// Other the "Something else" box, Like the sites or apps whose look they
// like, Avoid what to avoid and Keep what has to stay. Every part is
// optional (ValidTasteAnswer).
@@ -672,13 +676,17 @@ func ValidFeels(feels []string) error {
return nil
}
-// ValidTasteAnswer bounds a discovery answer: its feels (ValidFeels) and
-// each box at most MaxTasteBox characters of valid UTF-8 without NUL.
+// ValidTasteAnswer bounds a discovery answer: at most MaxFeelChoices
+// tapped feels, each as ValidFeels has them, and each box at most
+// MaxTasteBox characters of valid UTF-8 without NUL.
// No answer, and an empty one, are valid (every part is optional).
func ValidTasteAnswer(a *TasteAnswer) error {
if a == nil {
return nil
}
+ if len(a.Feels) > MaxFeelChoices {
+ return fmt.Errorf("%w: %d feels chosen", ErrStrict, len(a.Feels))
+ }
if err := ValidFeels(a.Feels); err != nil {
return err
}
diff --git a/internal/wire/design_feedback_test.go b/internal/wire/design_feedback_test.go
index 880a3521..e8abda16 100644
--- a/internal/wire/design_feedback_test.go
+++ b/internal/wire/design_feedback_test.go
@@ -158,9 +158,10 @@ func TestValidExploreOptions(t *testing.T) {
}
}
-// TestValidTasteAnswer bounds a discovery answer: at most five feels,
-// each a plain label of at most 30 bytes said once; each box at most 300
-// characters of valid UTF-8 without NUL.
+// TestValidTasteAnswer bounds a discovery answer: at most two tapped
+// feels (MaxFeelChoices, among up to five offered), each a plain label of
+// at most 30 bytes said once; each box at most 300 characters of valid
+// UTF-8 without NUL.
func TestValidTasteAnswer(t *testing.T) {
good := wire.TasteAnswer{Feels: []string{"Calm", "Editorial"}, Other: "Like a library", Like: strings.Repeat("é", wire.MaxTasteBox), Avoid: "Neon\ngradients", Keep: "The logo"}
if err := wire.ValidTasteAnswer(&good); err != nil {
@@ -173,6 +174,9 @@ func TestValidTasteAnswer(t *testing.T) {
t.Fatalf("no answer refused: %v", err)
}
for name, a := range map[string]wire.TasteAnswer{
+ "three feels": {Feels: []string{"A", "B", "C"}},
+ "four feels": {Feels: []string{"A", "B", "C", "D"}},
+ "five feels": {Feels: []string{"A", "B", "C", "D", "E"}},
"six feels": {Feels: []string{"A", "B", "C", "D", "E", "F"}},
"31-byte feel": {Feels: []string{strings.Repeat("a", wire.MaxFeel+1)}},
"markup feel": {Feels: []string{"<b>Calm</b>"}},
@@ -187,6 +191,16 @@ func TestValidTasteAnswer(t *testing.T) {
t.Fatalf("%s: %v", name, err)
}
}
+ if wire.MaxFeelChoices != 2 || wire.MaxFeels != 5 {
+ t.Fatal("feel bounds")
+ }
+ // Five offered feels are a valid list; an answer taps at most two.
+ if err := wire.ValidFeels([]string{"A", "B", "C", "D", "E"}); err != nil {
+ t.Fatalf("five offered feels refused: %v", err)
+ }
+ if err := wire.ValidTasteAnswer(&wire.TasteAnswer{Feels: []string{"A", "B"}}); err != nil {
+ t.Fatalf("two tapped feels refused: %v", err)
+ }
if err := wire.ValidFeels([]string{"Calm", "Warm"}); err != nil {
t.Fatalf("feels refused: %v", err)
}