High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: both Cloudflare title-fallback blocks are unreachable, and the ChallengeType vocabulary has three owners (PIN-128)
Luigi Agosti6da32a5e9d38
diff --git a/internal/autosolver/challenge_detection_test.go b/internal/autosolver/challenge_detection_test.goindex 704f8533..1d73bff0 100644--- a/internal/autosolver/challenge_detection_test.go+++ b/internal/autosolver/challenge_detection_test.go@@ -1,6 +1,211 @@package autosolver-import "testing"+import (+ "io/fs"+ "os"+ "path/filepath"+ "strings"+ "testing"+)++// cloudflareTriggerTitles are the three titles isTurnstileChallenge matches.+// They are kept in mixed case on purpose: DetectChallengeIntent lowercases+// before calling containsAny, which does no folding itself, so these rows fail+// if that lowercasing is moved or dropped.+var cloudflareTriggerTitles = []string{+ "Just a moment...",+ "Attention Required! | Cloudflare",+ "Checking your browser before accessing",+}++func TestChallengeTypeHasOneProducer(t *testing.T) {+ root := filepath.Join("..", "..")+ var producers []string+ err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {+ if err != nil {+ return err+ }+ if d.IsDir() {+ switch d.Name() {+ case ".git", "node_modules", "dist", "vendor":+ return fs.SkipDir+ }+ return nil+ }+ if !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {+ return nil+ }+ body, readErr := os.ReadFile(path)+ if readErr != nil {+ return readErr+ }+ if strings.Contains(string(body), "ChallengeType:") {+ producers = append(producers, filepath.ToSlash(filepath.Clean(path)))+ }+ return nil+ })+ if err != nil {+ t.Fatalf("walk: %v", err)+ }++ want := []string{"../../internal/autosolver/challenge_detection.go"}+ if strings.Join(producers, ",") != strings.Join(want, ",") {+ t.Fatalf("ChallengeType must be produced only by challenge_detection.go, got %v", producers)+ }+}++func TestDetectIntentByTitle_CloudflareTitlesAreTurnstile(t *testing.T) {+ for _, title := range cloudflareTriggerTitles {+ intent := detectIntentByTitle(title)+ if intent.ChallengeType != "turnstile" {+ t.Fatalf("%q: expected turnstile challenge type, got %q", title, intent.ChallengeType)+ }+ if intent.Confidence != 0.95 {+ t.Fatalf("%q: expected confidence 0.95, got %v", title, intent.Confidence)+ }+ if intent.Details != "cloudflare turnstile challenge detected" {+ t.Fatalf("%q: expected the canonical detector's details, got %q", title, intent.Details)+ }+ }+}++// titleRuleReachability names one title per pattern in titleIntentRules. Each+// row must reach the local rule rather than DetectChallengeIntent, which runs+// first; a pattern the canonical detector already answers cannot appear here+// and must be deleted from the table instead.+var titleRuleReachability = []struct {+ pattern string+ title string+}{+ {"robot", "Are you a robot?"},+ {"bot detection", "Bot detection in progress"},+ {"log in", "Log In"},+ {"login", "Login"},+ {"sign in", "Sign In"},+ {"signin", "Signin"},+ {"sign up", "Sign Up"},+ {"signup", "Signup"},+ {"register", "Register"},+ {"create account", "Create Account"},+ {"join", "Join our community"},+ {"getting started", "Getting Started"},+ {"welcome", "Welcome"},+ {"onboarding", "Onboarding"},+ {"complete your profile", "Complete your profile"},+ {"step 1", "Step 1 of 3"},+ {"continue", "Continue"},+ {"next step", "Next step"},+ {"choose option", "Choose option"},+ {"select plan", "Select plan"},+ {"wizard", "Setup wizard"},+ {"application form", "Application form"},+ {"contact form", "Contact form"},+ {"checkout", "Checkout"},+ {"survey", "Survey"},+ {"questionnaire", "Questionnaire"},+ {"access denied", "Access Denied"},+ {"forbidden", "Forbidden"},+ {"blocked", "Blocked"},+ {"unauthorized", "Unauthorized"},+}++func TestTitleIntentRules_EveryPatternIsReachable(t *testing.T) {+ covered := make(map[string]string, len(titleRuleReachability))+ for _, row := range titleRuleReachability {+ if prev, dup := covered[row.pattern]; dup {+ t.Fatalf("pattern %q covered twice (%q and %q)", row.pattern, prev, row.title)+ }+ covered[row.pattern] = row.title+ }++ for _, rule := range titleIntentRules {+ for _, pattern := range rule.Patterns {+ title, ok := covered[pattern]+ if !ok {+ t.Fatalf("pattern %q has no reachability row; prove it reachable or delete it", pattern)+ }+ intent := detectIntentByTitle(title)+ if intent.Details != rule.Details {+ t.Fatalf("pattern %q via %q: expected local details %q, got %q", pattern, title, rule.Details, intent.Details)+ }+ if intent.Type != rule.Type || intent.Confidence != rule.Confidence {+ t.Fatalf("pattern %q via %q: expected %q/%v, got %q/%v", pattern, title, rule.Type, rule.Confidence, intent.Type, intent.Confidence)+ }+ if intent.ChallengeType != "" {+ t.Fatalf("pattern %q via %q: local rules must not set a challenge type, got %q", pattern, title, intent.ChallengeType)+ }+ delete(covered, pattern)+ }+ }++ for pattern := range covered {+ t.Fatalf("reachability row for %q matches no pattern in titleIntentRules", pattern)+ }+}++// detectIntentByTitleGolden is the classification an agent observes, captured+// before the ladders became data-driven.+var detectIntentByTitleGolden = []struct {+ title string+ intentType IntentType+ challengeType string+ confidence float64+ details string+}{+ {"Just a moment...", IntentCaptcha, "turnstile", 0.95, "cloudflare turnstile challenge detected"},+ {"Attention Required! | Cloudflare", IntentCaptcha, "turnstile", 0.95, "cloudflare turnstile challenge detected"},+ {"Checking your browser before accessing", IntentCaptcha, "turnstile", 0.95, "cloudflare turnstile challenge detected"},+ {"Captcha required", IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"Please verify you are human", IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"I am not a robot", IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"reCAPTCHA verification", IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"hCaptcha check", IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"Are you a robot?", IntentCaptcha, "", 0.7, "generic captcha detected via title"},+ {"Bot detection in progress", IntentCaptcha, "", 0.7, "generic captcha detected via title"},+ {"Log In", IntentLogin, "", 0.6, "login page detected via title"},+ {"Login", IntentLogin, "", 0.6, "login page detected via title"},+ {"Sign In", IntentLogin, "", 0.6, "login page detected via title"},+ {"Signin", IntentLogin, "", 0.6, "login page detected via title"},+ {"Sign Up", IntentSignup, "", 0.6, "signup page detected via title"},+ {"Signup", IntentSignup, "", 0.6, "signup page detected via title"},+ {"Register", IntentSignup, "", 0.6, "signup page detected via title"},+ {"Create Account", IntentSignup, "", 0.6, "signup page detected via title"},+ {"Join our community", IntentSignup, "", 0.6, "signup page detected via title"},+ {"Getting Started", IntentOnboarding, "", 0.65, "onboarding flow detected via title"},+ {"Welcome", IntentOnboarding, "", 0.65, "onboarding flow detected via title"},+ {"Onboarding", IntentOnboarding, "", 0.65, "onboarding flow detected via title"},+ {"Complete your profile", IntentOnboarding, "", 0.65, "onboarding flow detected via title"},+ {"Step 1 of 3", IntentOnboarding, "", 0.65, "onboarding flow detected via title"},+ {"Continue", IntentNavigation, "", 0.6, "navigation flow detected via title"},+ {"Next step", IntentNavigation, "", 0.6, "navigation flow detected via title"},+ {"Choose option", IntentNavigation, "", 0.6, "navigation flow detected via title"},+ {"Select plan", IntentNavigation, "", 0.6, "navigation flow detected via title"},+ {"Setup wizard", IntentNavigation, "", 0.6, "navigation flow detected via title"},+ {"Application form", IntentForm, "", 0.6, "form flow detected via title"},+ {"Contact form", IntentForm, "", 0.6, "form flow detected via title"},+ {"Checkout", IntentForm, "", 0.6, "form flow detected via title"},+ {"Survey", IntentForm, "", 0.6, "form flow detected via title"},+ {"Questionnaire", IntentForm, "", 0.6, "form flow detected via title"},+ {"Access Denied", IntentBlocked, "", 0.7, "blocked page detected via title"},+ {"Forbidden", IntentBlocked, "", 0.7, "blocked page detected via title"},+ {"Blocked", IntentBlocked, "", 0.7, "blocked page detected via title"},+ {"Unauthorized", IntentBlocked, "", 0.7, "blocked page detected via title"},+ {"Security challenge", IntentNormal, "", 0.5, "no challenge indicators found in title"},+ {"Verify your identity", IntentNormal, "", 0.5, "no challenge indicators found in title"},+ {"Home page", IntentNormal, "", 0.5, "no challenge indicators found in title"},+}++func TestDetectIntentByTitle_Golden(t *testing.T) {+ for _, want := range detectIntentByTitleGolden {+ got := detectIntentByTitle(want.title)+ if got.Type != want.intentType || got.ChallengeType != want.challengeType ||+ got.Confidence != want.confidence || got.Details != want.details {+ t.Fatalf("%q: got %q/%q/%v/%q, want %q/%q/%v/%q", want.title,+ got.Type, got.ChallengeType, got.Confidence, got.Details,+ want.intentType, want.challengeType, want.confidence, want.details)+ }+ }+}func TestDetectChallengeIntent_Turnstile(t *testing.T) {intent := DetectChallengeIntent(diff --git a/internal/autosolver/heuristics.go b/internal/autosolver/heuristics.goindex 15d29f56..d9c056f9 100644--- a/internal/autosolver/heuristics.go+++ b/internal/autosolver/heuristics.go@@ -2,102 +2,56 @@ package autosolverimport "strings"-// detectIntentByTitle provides a lightweight fallback for intent-// detection when the semantic engine is unavailable. It uses-// well-known page-title patterns to classify the page.-func detectIntentByTitle(title string) *Intent {- lower := strings.ToLower(title)- if challenge := DetectChallengeIntent(title, "", ""); challenge != nil {- return challenge- }-- cfPatterns := []string{"just a moment", "attention required", "checking your browser"}- for _, p := range cfPatterns {- if strings.Contains(lower, p) {- return &Intent{- Type: IntentCaptcha,- Confidence: 0.9,- ChallengeType: "cloudflare",- Details: "cloudflare challenge detected via title",- }- }- }-- captchaPatterns := []string{"captcha", "verify you are human", "robot", "bot detection"}- for _, p := range captchaPatterns {- if strings.Contains(lower, p) {- return &Intent{- Type: IntentCaptcha,- Confidence: 0.7,- Details: "generic captcha detected via title",- }- }- }-- loginPatterns := []string{"log in", "login", "sign in", "signin"}- for _, p := range loginPatterns {- if strings.Contains(lower, p) {- return &Intent{- Type: IntentLogin,- Confidence: 0.6,- Details: "login page detected via title",- }- }- }-- signupPatterns := []string{"sign up", "signup", "register", "create account", "join"}- for _, p := range signupPatterns {- if strings.Contains(lower, p) {- return &Intent{- Type: IntentSignup,- Confidence: 0.6,- Details: "signup page detected via title",- }- }- }+// IntentRule maps a set of substrings to the Intent they produce.+type IntentRule struct {+ Patterns []string+ Type IntentType+ Confidence float64+ Details string+}- onboardingPatterns := []string{"getting started", "welcome", "onboarding", "complete your profile", "step 1"}- for _, p := range onboardingPatterns {- if strings.Contains(lower, p) {- return &Intent{- Type: IntentOnboarding,- Confidence: 0.65,- Details: "onboarding flow detected via title",+// MatchIntentRules returns the Intent of the first rule whose patterns appear+// in any haystack, or nil when no rule matches. Haystacks must already be+// lowercased.+func MatchIntentRules(rules []IntentRule, haystacks ...string) *Intent {+ for _, rule := range rules {+ for _, pattern := range rule.Patterns {+ for _, haystack := range haystacks {+ if strings.Contains(haystack, pattern) {+ return &Intent{+ Type: rule.Type,+ Confidence: rule.Confidence,+ Details: rule.Details,+ }+ }}}}+ return nil+}- navigationPatterns := []string{"continue", "next step", "choose option", "select plan", "wizard"}- for _, p := range navigationPatterns {- if strings.Contains(lower, p) {- return &Intent{- Type: IntentNavigation,- Confidence: 0.6,- Details: "navigation flow detected via title",- }- }- }+// titleIntentRules broadens DetectChallengeIntent for titles it does not+// classify. Patterns the canonical detector already answers must not appear+// here: it runs first, so they would be unreachable.+var titleIntentRules = []IntentRule{+ {[]string{"robot", "bot detection"}, IntentCaptcha, 0.7, "generic captcha detected via title"},+ {[]string{"log in", "login", "sign in", "signin"}, IntentLogin, 0.6, "login page detected via title"},+ {[]string{"sign up", "signup", "register", "create account", "join"}, IntentSignup, 0.6, "signup page detected via title"},+ {[]string{"getting started", "welcome", "onboarding", "complete your profile", "step 1"}, IntentOnboarding, 0.65, "onboarding flow detected via title"},+ {[]string{"continue", "next step", "choose option", "select plan", "wizard"}, IntentNavigation, 0.6, "navigation flow detected via title"},+ {[]string{"application form", "contact form", "checkout", "survey", "questionnaire"}, IntentForm, 0.6, "form flow detected via title"},+ {[]string{"access denied", "forbidden", "blocked", "unauthorized"}, IntentBlocked, 0.7, "blocked page detected via title"},+}- formPatterns := []string{"application form", "contact form", "checkout", "survey", "questionnaire"}- for _, p := range formPatterns {- if strings.Contains(lower, p) {- return &Intent{- Type: IntentForm,- Confidence: 0.6,- Details: "form flow detected via title",- }- }+// detectIntentByTitle provides a lightweight fallback for intent detection+// when the semantic engine is unavailable.+func detectIntentByTitle(title string) *Intent {+ if challenge := DetectChallengeIntent(title, "", ""); challenge != nil {+ return challenge}- blockedPatterns := []string{"access denied", "forbidden", "blocked", "unauthorized"}- for _, p := range blockedPatterns {- if strings.Contains(lower, p) {- return &Intent{- Type: IntentBlocked,- Confidence: 0.7,- Details: "blocked page detected via title",- }- }+ if intent := MatchIntentRules(titleIntentRules, strings.ToLower(title)); intent != nil {+ return intent}return &Intent{diff --git a/internal/autosolver/semantic/adapter.go b/internal/autosolver/semantic/adapter.goindex 39d22105..6652fc91 100644--- a/internal/autosolver/semantic/adapter.go+++ b/internal/autosolver/semantic/adapter.go@@ -24,6 +24,23 @@ func NewAdapter(m semantic.ElementMatcher) *Adapter {return &Adapter{matcher: m}}+// captchaRules and flowRules broaden autosolver.DetectChallengeIntent for+// pages it does not classify. Patterns the canonical detector already answers+// must not appear here: it runs first, so they would be unreachable.+var (+ captchaRules = []autosolver.IntentRule{+ {Patterns: []string{"challenge", "verify"}, Type: autosolver.IntentCaptcha, Confidence: 0.8, Details: "captcha detected via semantic analysis"},+ }++ flowRules = []autosolver.IntentRule{+ {Patterns: []string{"log in", "login", "sign in"}, Type: autosolver.IntentLogin, Confidence: 0.7, Details: "login page detected via semantic title analysis"},+ {Patterns: []string{"sign up", "signup", "register", "create account"}, Type: autosolver.IntentSignup, Confidence: 0.7, Details: "signup page detected via semantic title analysis"},+ {Patterns: []string{"getting started", "welcome", "onboarding", "complete your profile", "step 1"}, Type: autosolver.IntentOnboarding, Confidence: 0.65, Details: "onboarding flow detected via semantic title analysis"},+ {Patterns: []string{"continue", "next step", "choose option", "select plan", "wizard"}, Type: autosolver.IntentNavigation, Confidence: 0.6, Details: "navigation flow detected via semantic title analysis"},+ {Patterns: []string{"application form", "contact form", "checkout", "survey", "questionnaire"}, Type: autosolver.IntentForm, Confidence: 0.6, Details: "form flow detected via semantic title analysis"},+ }+)+// DetectIntent classifies the current page state by analyzing the page// title and URL using semantic matching against known patterns.func (a *Adapter) DetectIntent(ctx context.Context, page autosolver.Page) (*autosolver.Intent, error) {@@ -34,27 +51,8 @@ func (a *Adapter) DetectIntent(ctx context.Context, page autosolver.Page) (*autoreturn challenge, nil}- cfIndicators := []string{"just a moment", "attention required", "checking your browser"}- for _, indicator := range cfIndicators {- if strings.Contains(title, indicator) {- return &autosolver.Intent{- Type: autosolver.IntentCaptcha,- Confidence: 0.95,- ChallengeType: "cloudflare-turnstile",- Details: "cloudflare challenge detected via semantic title analysis",- }, nil- }- }-- captchaIndicators := []string{"captcha", "challenge", "verify", "recaptcha", "hcaptcha"}- for _, indicator := range captchaIndicators {- if strings.Contains(title, indicator) || strings.Contains(strings.ToLower(url), indicator) {- return &autosolver.Intent{- Type: autosolver.IntentCaptcha,- Confidence: 0.8,- Details: "captcha detected via semantic analysis",- }, nil- }+ if intent := autosolver.MatchIntentRules(captchaRules, title, strings.ToLower(url)); intent != nil {+ return intent, nil}if a.matcher != nil {@@ -64,59 +62,8 @@ func (a *Adapter) DetectIntent(ctx context.Context, page autosolver.Page) (*auto}}- loginPatterns := []string{"log in", "login", "sign in"}- for _, p := range loginPatterns {- if strings.Contains(title, p) {- return &autosolver.Intent{- Type: autosolver.IntentLogin,- Confidence: 0.7,- Details: "login page detected via semantic title analysis",- }, nil- }- }-- signupPatterns := []string{"sign up", "signup", "register", "create account"}- for _, p := range signupPatterns {- if strings.Contains(title, p) {- return &autosolver.Intent{- Type: autosolver.IntentSignup,- Confidence: 0.7,- Details: "signup page detected via semantic title analysis",- }, nil- }- }-- onboardingPatterns := []string{"getting started", "welcome", "onboarding", "complete your profile", "step 1"}- for _, p := range onboardingPatterns {- if strings.Contains(title, p) {- return &autosolver.Intent{- Type: autosolver.IntentOnboarding,- Confidence: 0.65,- Details: "onboarding flow detected via semantic title analysis",- }, nil- }- }-- navigationPatterns := []string{"continue", "next step", "choose option", "select plan", "wizard"}- for _, p := range navigationPatterns {- if strings.Contains(title, p) {- return &autosolver.Intent{- Type: autosolver.IntentNavigation,- Confidence: 0.6,- Details: "navigation flow detected via semantic title analysis",- }, nil- }- }-- formPatterns := []string{"application form", "contact form", "checkout", "survey", "questionnaire"}- for _, p := range formPatterns {- if strings.Contains(title, p) {- return &autosolver.Intent{- Type: autosolver.IntentForm,- Confidence: 0.6,- Details: "form flow detected via semantic title analysis",- }, nil- }+ if intent := autosolver.MatchIntentRules(flowRules, title); intent != nil {+ return intent, nil}return &autosolver.Intent{diff --git a/internal/autosolver/semantic/adapter_test.go b/internal/autosolver/semantic/adapter_test.gonew file mode 100644index 00000000..a0122294--- /dev/null+++ b/internal/autosolver/semantic/adapter_test.go@@ -0,0 +1,205 @@+package semantic++import (+ "context"+ "testing"+ "time"++ "github.com/pinchtab/pinchtab/internal/autosolver"+)++type stubPage struct {+ title string+ url string+ html string+}++func (p stubPage) URL() string { return p.url }+func (p stubPage) Title() string { return p.title }+func (p stubPage) HTML() (string, error) { return p.html, nil }+func (p stubPage) HTMLWithin(time.Duration) (string, error) { return p.html, nil }+func (p stubPage) Screenshot() ([]byte, error) { return nil, nil }++func detect(t *testing.T, title, url string) *autosolver.Intent {+ t.Helper()+ intent, err := NewAdapter(nil).DetectIntent(context.Background(), stubPage{title: title, url: url})+ if err != nil {+ t.Fatalf("DetectIntent(%q, %q): %v", title, url, err)+ }+ return intent+}++// Mixed case on purpose: DetectIntent lowercases the title and+// DetectChallengeIntent lowercases again, so these rows fail if either+// lowercasing is moved or dropped.+var cloudflareTriggerTitles = []string{+ "Just a moment...",+ "Attention Required! | Cloudflare",+ "Checking your browser before accessing",+}++func TestDetectIntent_CloudflareTitlesAreTurnstile(t *testing.T) {+ for _, title := range cloudflareTriggerTitles {+ intent := detect(t, title, "")+ if intent.ChallengeType != "turnstile" {+ t.Fatalf("%q: expected turnstile challenge type, got %q", title, intent.ChallengeType)+ }+ if intent.Confidence != 0.95 {+ t.Fatalf("%q: expected confidence 0.95, got %v", title, intent.Confidence)+ }+ if intent.Details != "cloudflare turnstile challenge detected" {+ t.Fatalf("%q: expected the canonical detector's details, got %q", title, intent.Details)+ }+ }+}++// ruleReachability names one title per pattern in captchaRules and flowRules.+// Each row must reach the local rule rather than DetectChallengeIntent, which+// runs first; a pattern the canonical detector already answers cannot appear+// here and must be deleted from its table instead.+var ruleReachability = []struct {+ pattern string+ title string+}{+ {"challenge", "Security challenge"},+ {"verify", "Verify your identity"},+ {"log in", "Log In"},+ {"login", "Login"},+ {"sign in", "Sign In"},+ {"sign up", "Sign Up"},+ {"signup", "Signup"},+ {"register", "Register"},+ {"create account", "Create Account"},+ {"getting started", "Getting Started"},+ {"welcome", "Welcome"},+ {"onboarding", "Onboarding"},+ {"complete your profile", "Complete your profile"},+ {"step 1", "Step 1 of 3"},+ {"continue", "Continue"},+ {"next step", "Next step"},+ {"choose option", "Choose option"},+ {"select plan", "Select plan"},+ {"wizard", "Setup wizard"},+ {"application form", "Application form"},+ {"contact form", "Contact form"},+ {"checkout", "Checkout"},+ {"survey", "Survey"},+ {"questionnaire", "Questionnaire"},+}++func TestIntentRules_EveryPatternIsReachable(t *testing.T) {+ covered := make(map[string]string, len(ruleReachability))+ for _, row := range ruleReachability {+ if prev, dup := covered[row.pattern]; dup {+ t.Fatalf("pattern %q covered twice (%q and %q)", row.pattern, prev, row.title)+ }+ covered[row.pattern] = row.title+ }++ var rules []autosolver.IntentRule+ rules = append(rules, captchaRules...)+ rules = append(rules, flowRules...)++ for _, rule := range rules {+ for _, pattern := range rule.Patterns {+ title, ok := covered[pattern]+ if !ok {+ t.Fatalf("pattern %q has no reachability row; prove it reachable or delete it", pattern)+ }+ intent := detect(t, title, "")+ if intent.Details != rule.Details {+ t.Fatalf("pattern %q via %q: expected local details %q, got %q", pattern, title, rule.Details, intent.Details)+ }+ if intent.Type != rule.Type || intent.Confidence != rule.Confidence {+ t.Fatalf("pattern %q via %q: expected %q/%v, got %q/%v", pattern, title, rule.Type, rule.Confidence, intent.Type, intent.Confidence)+ }+ if intent.ChallengeType != "" {+ t.Fatalf("pattern %q via %q: local rules must not set a challenge type, got %q", pattern, title, intent.ChallengeType)+ }+ delete(covered, pattern)+ }+ }++ for pattern := range covered {+ t.Fatalf("reachability row for %q matches no pattern in captchaRules or flowRules", pattern)+ }+}++func TestCaptchaRules_MatchTheURLToo(t *testing.T) {+ for _, url := range []string{"https://example.com/challenge/step", "https://example.com/verify-me"} {+ intent := detect(t, "Home page", url)+ if intent.Details != "captcha detected via semantic analysis" {+ t.Fatalf("%q: expected the local captcha rule, got %q", url, intent.Details)+ }+ }+}++// detectIntentGolden is the classification an agent observes, captured before+// the ladders became data-driven.+var detectIntentGolden = []struct {+ title string+ url string+ intentType autosolver.IntentType+ challengeType string+ confidence float64+ details string+}{+ {"Just a moment...", "", autosolver.IntentCaptcha, "turnstile", 0.95, "cloudflare turnstile challenge detected"},+ {"Attention Required! | Cloudflare", "", autosolver.IntentCaptcha, "turnstile", 0.95, "cloudflare turnstile challenge detected"},+ {"Checking your browser before accessing", "", autosolver.IntentCaptcha, "turnstile", 0.95, "cloudflare turnstile challenge detected"},+ {"Captcha required", "", autosolver.IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"Please verify you are human", "", autosolver.IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"I am not a robot", "", autosolver.IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"reCAPTCHA verification", "", autosolver.IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"hCaptcha check", "", autosolver.IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"Are you a robot?", "", autosolver.IntentNormal, "", 0.6, "no challenge indicators detected"},+ {"Bot detection in progress", "", autosolver.IntentNormal, "", 0.6, "no challenge indicators detected"},+ {"Security challenge", "", autosolver.IntentCaptcha, "", 0.8, "captcha detected via semantic analysis"},+ {"Verify your identity", "", autosolver.IntentCaptcha, "", 0.8, "captcha detected via semantic analysis"},+ {"Home page", "https://example.com/challenge/step", autosolver.IntentCaptcha, "", 0.8, "captcha detected via semantic analysis"},+ {"Home page", "https://example.com/verify-me", autosolver.IntentCaptcha, "", 0.8, "captcha detected via semantic analysis"},+ {"Home page", "https://example.com/captcha", autosolver.IntentCaptcha, "captcha-generic", 0.7, "generic captcha challenge detected"},+ {"Home page", "https://example.com/recaptcha", autosolver.IntentCaptcha, "recaptcha-v2", 0.9, "reCAPTCHA v2 challenge detected"},+ {"Home page", "https://example.com/hcaptcha", autosolver.IntentCaptcha, "hcaptcha", 0.9, "hCaptcha challenge detected"},+ {"Log In", "", autosolver.IntentLogin, "", 0.7, "login page detected via semantic title analysis"},+ {"Login", "", autosolver.IntentLogin, "", 0.7, "login page detected via semantic title analysis"},+ {"Sign In", "", autosolver.IntentLogin, "", 0.7, "login page detected via semantic title analysis"},+ {"Signin", "", autosolver.IntentNormal, "", 0.6, "no challenge indicators detected"},+ {"Sign Up", "", autosolver.IntentSignup, "", 0.7, "signup page detected via semantic title analysis"},+ {"Signup", "", autosolver.IntentSignup, "", 0.7, "signup page detected via semantic title analysis"},+ {"Register", "", autosolver.IntentSignup, "", 0.7, "signup page detected via semantic title analysis"},+ {"Create Account", "", autosolver.IntentSignup, "", 0.7, "signup page detected via semantic title analysis"},+ {"Join our community", "", autosolver.IntentNormal, "", 0.6, "no challenge indicators detected"},+ {"Getting Started", "", autosolver.IntentOnboarding, "", 0.65, "onboarding flow detected via semantic title analysis"},+ {"Welcome", "", autosolver.IntentOnboarding, "", 0.65, "onboarding flow detected via semantic title analysis"},+ {"Onboarding", "", autosolver.IntentOnboarding, "", 0.65, "onboarding flow detected via semantic title analysis"},+ {"Complete your profile", "", autosolver.IntentOnboarding, "", 0.65, "onboarding flow detected via semantic title analysis"},+ {"Step 1 of 3", "", autosolver.IntentOnboarding, "", 0.65, "onboarding flow detected via semantic title analysis"},+ {"Continue", "", autosolver.IntentNavigation, "", 0.6, "navigation flow detected via semantic title analysis"},+ {"Next step", "", autosolver.IntentNavigation, "", 0.6, "navigation flow detected via semantic title analysis"},+ {"Choose option", "", autosolver.IntentNavigation, "", 0.6, "navigation flow detected via semantic title analysis"},+ {"Select plan", "", autosolver.IntentNavigation, "", 0.6, "navigation flow detected via semantic title analysis"},+ {"Setup wizard", "", autosolver.IntentNavigation, "", 0.6, "navigation flow detected via semantic title analysis"},+ {"Application form", "", autosolver.IntentForm, "", 0.6, "form flow detected via semantic title analysis"},+ {"Contact form", "", autosolver.IntentForm, "", 0.6, "form flow detected via semantic title analysis"},+ {"Checkout", "", autosolver.IntentForm, "", 0.6, "form flow detected via semantic title analysis"},+ {"Survey", "", autosolver.IntentForm, "", 0.6, "form flow detected via semantic title analysis"},+ {"Questionnaire", "", autosolver.IntentForm, "", 0.6, "form flow detected via semantic title analysis"},+ {"Access Denied", "", autosolver.IntentNormal, "", 0.6, "no challenge indicators detected"},+ {"Forbidden", "", autosolver.IntentNormal, "", 0.6, "no challenge indicators detected"},+ {"Blocked", "", autosolver.IntentNormal, "", 0.6, "no challenge indicators detected"},+ {"Unauthorized", "", autosolver.IntentNormal, "", 0.6, "no challenge indicators detected"},+ {"Home page", "", autosolver.IntentNormal, "", 0.6, "no challenge indicators detected"},+}++func TestDetectIntent_Golden(t *testing.T) {+ for _, want := range detectIntentGolden {+ got := detect(t, want.title, want.url)+ if got.Type != want.intentType || got.ChallengeType != want.challengeType ||+ got.Confidence != want.confidence || got.Details != want.details {+ t.Fatalf("%q/%q: got %q/%q/%v/%q, want %q/%q/%v/%q", want.title, want.url,+ got.Type, got.ChallengeType, got.Confidence, got.Details,+ want.intentType, want.challengeType, want.confidence, want.details)+ }+ }+}