| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/event" |
| 9 | ) |
| 10 | |
| 11 | func TestAskRejectsMoreThanThreeQuestions(t *testing.T) { |
| 12 | _, err := NewAskTool().Execute(context.Background(), []byte(`{ |
| 13 | "questions":[ |
| 14 | {"header":"A","question":"a?","options":[{"label":"1"},{"label":"2"}]}, |
| 15 | {"header":"B","question":"b?","options":[{"label":"1"},{"label":"2"}]}, |
| 16 | {"header":"C","question":"c?","options":[{"label":"1"},{"label":"2"}]}, |
| 17 | {"header":"D","question":"d?","options":[{"label":"1"},{"label":"2"}]} |
| 18 | ] |
| 19 | }`)) |
| 20 | if err == nil || !strings.Contains(err.Error(), "at most 3") { |
| 21 | t.Fatalf("error = %v", err) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | func TestAskReusesAcceptedDecisionWithoutNewEvidence(t *testing.T) { |
| 26 | turn := &turnRuntime{} |
| 27 | turn.loop.rememberDecision("dec-1", "Which path?", "Keep going") |
| 28 | ctx := withTurnState(context.Background(), turn) |
| 29 | out, err := NewAskTool().Execute(ctx, []byte(`{ |
| 30 | "decision_id":"dec-1", |
| 31 | "questions":[{"header":"Direction","question":"Which path?","options":[{"label":"Keep going"},{"label":"Stop"}]}] |
| 32 | }`)) |
| 33 | if err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | if !strings.Contains(out, "reused accepted decision") { |
| 37 | t.Fatalf("got %q", out) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func TestAskAllowsReopenWithNewEvidence(t *testing.T) { |
| 42 | turn := &turnRuntime{} |
| 43 | turn.loop.rememberDecision("dec-1", "Which path?", "Keep going") |
| 44 | asker := &recordingAsker{} |
| 45 | ctx := withCallContext(withTurnState(context.Background(), turn), "c1", event.Discard, asker, false) |
| 46 | out, err := NewAskTool().Execute(ctx, []byte(`{ |
| 47 | "decision_id":"dec-1", |
| 48 | "new_evidence":"new metric from the latest run", |
| 49 | "questions":[{"header":"Direction","question":"Which path?","options":[{"label":"Keep going"},{"label":"Stop"}]}] |
| 50 | }`)) |
| 51 | if err != nil { |
| 52 | t.Fatal(err) |
| 53 | } |
| 54 | if !strings.Contains(out, "decision_id") { |
| 55 | t.Fatalf("got %q", out) |
| 56 | } |
| 57 | if len(asker.questions) != 1 { |
| 58 | t.Fatalf("asker questions = %d", len(asker.questions)) |
| 59 | } |
| 60 | } |
| 61 |