Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

refactor: delete the dead legacy solver registry and its duplicate… (PIN-147)

Luigi Agostic61e5c59a588
diff --git a/internal/autosolver/solvers/cloudflare.go b/internal/autosolver/solvers/cloudflare.go
index 265ad454..6ceacc55 100644
--- a/internal/autosolver/solvers/cloudflare.go
+++ b/internal/autosolver/solvers/cloudflare.go
@@ -110,11 +110,12 @@ const (
cfClickJitterPx = 8
)
-var cfRand = rand.New(rand.NewSource(time.Now().UnixNano())) // #nosec G404 -- input humanisation, not cryptography.
-
// cfClickJitter returns a signed offset within half the jitter window either way.
+// Solve runs inside HTTP handler goroutines and the auto-trigger's own goroutine, so
+// two solves can jitter at once: the draw comes from the top-level source, which is
+// safe for concurrent use, never a package-level *rand.Rand, which is not.
func cfClickJitter() float64 {
- return (cfRand.Float64() - 0.5) * cfClickJitterPx
+ return (rand.Float64() - 0.5) * cfClickJitterPx // #nosec G404 -- input humanisation, not cryptography.
}
func isCFChallenge(title string) bool {
diff --git a/internal/autosolver/solvers/cloudflare_test.go b/internal/autosolver/solvers/cloudflare_test.go
new file mode 100644
index 00000000..de51d035
--- /dev/null
+++ b/internal/autosolver/solvers/cloudflare_test.go
@@ -0,0 +1,61 @@
+package solvers
+
+import (
+ "math"
+ "sync"
+ "testing"
+
+ "github.com/pinchtab/pinchtab/internal/srccensus"
+)
+
+func TestClickJitterStaysInsideItsWindow(t *testing.T) {
+ limit := cfClickJitterPx / 2.0
+ for i := 0; i < 1000; i++ {
+ got := cfClickJitter()
+ if math.Abs(got) > limit {
+ t.Fatalf("cfClickJitter() = %v, outside ±%v: a click offset wider than the checkbox lands beside it", got, limit)
+ }
+ }
+}
+
+// A constant offset is not jitter: it clicks the same relative point every attempt,
+// which is the fingerprint the jitter was ported to remove.
+func TestClickJitterVaries(t *testing.T) {
+ first := cfClickJitter()
+ for i := 0; i < 1000; i++ {
+ if cfClickJitter() != first {
+ return
+ }
+ }
+ t.Fatalf("cfClickJitter() returned %v on 1001 consecutive draws, so every attempt clicks the identical relative point", first)
+}
+
+// Solve runs inside HTTP handler goroutines and inside the auto-trigger's own
+// goroutine, so two solves can draw at once. This test only FAILS under -race, which
+// the standard unit run does not use — TestThisPackageDrawsRandomnessFromTheGlobalSource
+// is the check that bites in a plain run, and this one is what a -race run reports.
+func TestClickJitterIsSafeForConcurrentSolves(t *testing.T) {
+ var wg sync.WaitGroup
+ for i := 0; i < 8; i++ {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ for j := 0; j < 500; j++ {
+ _ = cfClickJitter()
+ }
+ }()
+ }
+ wg.Wait()
+}
+
+// math/rand's *Rand is not goroutine-safe; the top-level functions are. A private
+// seeded generator in this package would therefore be raced by concurrent solves, and
+// the race is invisible to the standard unit run because it carries no -race flag —
+// so the property is pinned at the source instead of by the concurrent test above.
+func TestThisPackageDrawsRandomnessFromTheGlobalSource(t *testing.T) {
+ pkg := srccensus.Load(t, ".", 2)
+
+ for _, site := range pkg.CallsAllowingNone("rand.New") {
+ t.Errorf("%s constructs its own *rand.Rand; math/rand's *Rand is not goroutine-safe and a solver draws from several goroutines at once (an HTTP handler and the auto-trigger). Call the top-level rand functions, which are, and keep the #nosec note on the call", site)
+ }
+}