mirror of
https://github.com/lukaszraczylo/mcp-captcharesolver.git
synced 2026-10-12 00:45:28 +00:00
34 lines
847 B
Go
34 lines
847 B
Go
package captcha
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/lukaszraczylo/captcha-solver-mcp/internal/llm"
|
|
)
|
|
|
|
func TestSolveText(t *testing.T) {
|
|
f := &llm.Fake{VisionResp: `{"text":"ab12","confidence":0.9}`}
|
|
res, err := SolveText(context.Background(), f, []byte{1}, "image/png", TextOptions{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if res.Text != "ab12" || res.Confidence < 0.89 {
|
|
t.Fatalf("got %+v", res)
|
|
}
|
|
if len(f.VisionCalls) != 1 {
|
|
t.Fatalf("expected 1 vision call")
|
|
}
|
|
}
|
|
|
|
func TestSolveTextRetriesOnGarbage(t *testing.T) {
|
|
f := &llm.Fake{VisionResp: "I cannot read this"}
|
|
_, err := SolveText(context.Background(), f, []byte{1}, "image/png", TextOptions{})
|
|
if err == nil {
|
|
t.Fatal("want error on unparseable output")
|
|
}
|
|
if len(f.VisionCalls) != 2 {
|
|
t.Fatalf("expected 2 attempts (one retry), got %d", len(f.VisionCalls))
|
|
}
|
|
}
|