package prompt

import (
	"context"
	"testing"
)

func TestRulesClassify(t *testing.T) {
	r := NewRules()
	ctx := context.Background()
	cases := []struct {
		text  string
		open  []TaskSummary
		want  Kind
	}{
		{"add a tooltip to the dashboard", nil, KindImplementNew},
		{"the dashboard is broken", nil, KindDebugDiscovery},
		{"wait, actually use a popover", []TaskSummary{{ID: "t1", State: "in_progress"}}, KindSteering},
		{"what is this project?", nil, KindConversational},
		{"please rate the result", nil, KindEvaluation},
		{"refer to t-foo and continue", []TaskSummary{{ID: "t-foo", State: "in_progress"}}, KindSteering},
		// New-keyword coverage for the benchmark prompts.
		{"rename next_visible_at to dequeue_after", nil, KindImplementCrossBound},
		{"refactor the auth middleware", nil, KindImplementCrossBound},
		{"make the dashboard feel snappier", nil, KindImplementNew},
		{"improve performance of the stalled tasks panel", nil, KindImplementNew},
		// SR2: introspection / self-report verbs. These are the exact
		// surfaces the org-wide fan-out path keys off.
		{"Let every subworker identify and self-report itself", nil, KindIntrospection},
		{"all agents please introspect", nil, KindIntrospection},
		{"each worker, give me a self report", nil, KindIntrospection},
		// Negative: a partial-org "identify" prompt without an org-wide
		// verb must NOT trigger introspection (would clobber legitimate
		// work). "identify the bug" goes to debug; "Let the frontend
		// work identify itself" stays unrouted (no introspection trigger).
		{"identify the bug in this file", nil, KindDebugDiscovery},
		{"Let the frontend work identify itself.", nil, KindUnknown},
	}
	for _, c := range cases {
		got, err := r.Classify(ctx, Input{Text: c.text, OpenTasks: c.open})
		if err != nil {
			t.Errorf("%q: err %v", c.text, err)
			continue
		}
		if got.Kind != c.want {
			t.Errorf("%q: kind = %s, want %s (rationale: %s)", c.text, got.Kind, c.want, got.Rationale)
		}
	}
}
