mirror of
https://github.com/lukaszraczylo/mcp-captcharesolver.git
synced 2026-10-14 00:57:55 +00:00
- Add Samples to TextOptions/GridOptions; N>1 runs N solves at temp 0.5 and majority-votes (text: most frequent; grid: tiles in strict majority). N<=1 keeps the single deterministic call path unchanged. - Add NoTargets to GridResult so callers know to click Verify instead of looping; prompt instructs empty tiles + no_targets:true when nothing matches. - Grid prompt: numbered cells 0..R*C-1, select any partial overlap. - Text prompt: disambiguate similar glyphs (0/O 1/l/I 5/S 2/Z 8/B). - Rotation prompt: reason step-by-step then emit final JSON.
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
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))
|
|
}
|
|
}
|
|
|
|
func TestSolveTextVoting(t *testing.T) {
|
|
f := &llm.Fake{VisionResponses: []string{
|
|
`{"text":"ab12","confidence":0.7}`,
|
|
`{"text":"ab12","confidence":0.7}`,
|
|
`{"text":"ab13","confidence":0.9}`,
|
|
}}
|
|
res, err := SolveText(context.Background(), f, []byte{1}, "image/png", TextOptions{Samples: 3})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if res.Text != "ab12" {
|
|
t.Fatalf("voted text %q, want ab12", res.Text)
|
|
}
|
|
if len(f.VisionCalls) != 3 {
|
|
t.Fatalf("expected 3 vision calls, got %d", len(f.VisionCalls))
|
|
}
|
|
}
|