feat(captcha): image-grid tile solver with centroid mapping

This commit is contained in:
2026-06-07 13:16:54 +01:00
parent 0f1ad1dc44
commit 6e496eeac8
2 changed files with 102 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
package captcha
import (
"context"
"testing"
"github.com/lukaszraczylo/captcha-solver-mcp/internal/llm"
)
func TestSolveGrid(t *testing.T) {
f := &llm.Fake{VisionResp: `{"tiles":[0,4,8],"confidence":0.8,"recheck_recommended":true}`}
res, err := SolveGrid(context.Background(), f, []byte{1}, "image/png", GridOptions{
Instruction: "select all buses", Rows: 3, Cols: 3, ImageWidth: 300, ImageHeight: 300,
})
if err != nil {
t.Fatal(err)
}
if len(res.Tiles) != 3 || res.Tiles[0] != 0 {
t.Fatalf("tiles %+v", res.Tiles)
}
if len(res.Centroids) != 3 || res.Centroids[1].X != 150 { // tile 4 centre
t.Fatalf("centroids %+v", res.Centroids)
}
if !res.RecheckRecommended {
t.Fatal("recheck flag lost")
}
}