package app import ( "bytes" "context" "image" "image/color" "image/draw" "image/png" "os" "strings" "testing" ) func TestCardRecognitionLive(t *testing.T) { if os.Getenv("RUN_CARD_RECOGNITION_LIVE") != "1" { t.Skip("explicit opt-in required: calls configured model service") } ctx := context.Background() cfg := loadCardRecognitionConfig(ctx) if !cfg.Enabled || cfg.APIKey == "" { t.Fatal("disabled or missing API key") } img := image.NewRGBA(image.Rect(0, 0, 256, 128)) draw.Draw(img, img.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src) var buf bytes.Buffer if err := png.Encode(&buf, img); err != nil { t.Fatal(err) } t.Logf("provider=%s model=%s timeout=%s", cfg.Provider, cfg.Model, cfg.Timeout) raw, err := requestCardRecognitionModel(ctx, cfg, buf.Bytes(), "image/png") if err != nil { t.Fatal(strings.ReplaceAll(err.Error(), cfg.APIKey, "[REDACTED]")) } result := parseCardRecognitionResult(raw) t.Logf("result code=%s candidates=%d", result.Code, len(result.Candidates)) if result.Code != cardRecognitionCodeUnreadable || len(result.Candidates) != 0 { t.Fatal("blank image must not produce an ICCID") } }