package gemini_test

import (
	"testing"

	"github.com/flothus/tmux-xterm-research/server-go/internal/harness/runtime/tmux/gemini"
)

func TestNewPaneConfiguresGeminiCLI(t *testing.T) {
	p := gemini.NewPane("sock", "sess", "/tmp/gemini.log")
	if got := p.CLICmd; len(got) == 0 || got[0] != "gemini" {
		t.Errorf("CLICmd = %v, want [gemini …]", got)
	}
	if p.PromptRegex == nil {
		t.Error("PromptRegex should be set")
	}
	if p.RateLimitRegex == nil {
		t.Error("RateLimitRegex should be set")
	}
}

func TestGeminiPromptRegexMatchesShapes(t *testing.T) {
	p := gemini.NewPane("sock", "sess", "/tmp/gemini.log")
	cases := []struct {
		s    string
		want bool
	}{
		{"> ", true},
		{"$ ", true},
		{"some prose", false},
	}
	for _, c := range cases {
		got := p.PromptRegex.MatchString(c.s + "\n")
		if got != c.want {
			t.Errorf("PromptRegex.Match(%q) = %v, want %v", c.s, got, c.want)
		}
	}
}

func TestGeminiRateLimitRegexMatchesCommonPhrases(t *testing.T) {
	p := gemini.NewPane("sock", "sess", "/tmp/gemini.log")
	cases := []string{
		"Error: RESOURCE_EXHAUSTED",
		"quota exceeded for this minute",
		"HTTP 429 Too Many Requests",
	}
	for _, s := range cases {
		if !p.RateLimitRegex.MatchString(s) {
			t.Errorf("RateLimitRegex should match %q", s)
		}
	}
}

func TestGeminiEstimateTokens(t *testing.T) {
	got := gemini.EstimateTokens("hello world", "the quick brown fox")
	if got.Prompt <= 0 || got.Completion <= 0 {
		t.Errorf("token estimation should produce non-zero counts: %+v", got)
	}
}
