mirror of
https://github.com/lukaszraczylo/mcp-captcharesolver.git
synced 2026-10-15 01:07:32 +00:00
feat(captcha): LLM text-image OCR solver with strict-retry
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user