feat(captcha): LLM text-image OCR solver with strict-retry

This commit is contained in:
2026-06-07 13:15:32 +01:00
parent ca9add612e
commit c0da1121d9
3 changed files with 106 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
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))
}
}