package claudecode_test

import (
	"testing"

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

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

func TestClaudeRateLimitRegexMatchesPhrases(t *testing.T) {
	p := claudecode.NewPane("sock", "sess", "/tmp/claude.log")
	cases := []string{
		"Error: rate limit reached",
		"you've reached your usage limit",
		"HTTP 429",
	}
	for _, s := range cases {
		if !p.RateLimitRegex.MatchString(s) {
			t.Errorf("RateLimitRegex should match %q", s)
		}
	}
}

func TestClaudeEstimateTokensBaselineRatio(t *testing.T) {
	// The claudecode estimator uses the universal /4 baseline.
	got := claudecode.EstimateTokens("hello world", "the quick brown fox")
	wantP := len("hello world") / 4
	if got.Prompt != wantP {
		t.Errorf("Prompt estimate = %d, want %d (chars/4)", got.Prompt, wantP)
	}
}
