diff --git a/cmd/zapret-autotune/recover.go b/cmd/zapret-autotune/recover.go index 7475b1a..74db719 100644 --- a/cmd/zapret-autotune/recover.go +++ b/cmd/zapret-autotune/recover.go @@ -95,8 +95,8 @@ var earlySuccessResult = regexp.MustCompile(`^ OK median [0-9]+ms, [0-9]+\.[0 var earlyCheckPreamble = regexp.MustCompile("^(! --workers has no effect on `check` \\(it verifies strategies sequentially by design\\)\n)?" + `=== Checking prerequisites ===\n OK nfqws2: /[^\s]+\n OK nft\n OK nft queue support\n` + `check loaded 2 strategies from /[^\s]+, --take [0-9]+, --passes 3\n( ISP: AS[0-9]+ [^\n]+\n)?` + - `=== DNS resolve ===\n dns mode: auto\n ([a-z0-9.-]+) -> [0-9a-fA-F:.]+ \(via doh \(auto-fallback\)\)$`) -var earlyCheckSummary = regexp.MustCompile(`^ total: 2 \| working: ([01]) \| elapsed: [0-9]+\.[0-9]s\n OK JSON report → /[^\s]+$`) + `=== DNS resolve ===\n dns mode: auto\n ([a-z0-9.-]+) -> [0-9a-fA-F:.]+(?:, [0-9a-fA-F:.]+)* \(via (?:system|doh \(auto-fallback\))\)$`) +var earlyCheckSummary = regexp.MustCompile(`^ total: 2 \| working: ([01]) \| elapsed: [0-9]+\.[0-9]s\n OK JSON report → (?:/[^\s]+|[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}_check\.json)$`) // This is rejection evidence only, never qualification evidence. Unknown CLI // output fails closed; changes to the checker format require a new fixture. diff --git a/cmd/zapret-autotune/recovery_primitives_test.go b/cmd/zapret-autotune/recovery_primitives_test.go index 4e75603..b19d1c5 100644 --- a/cmd/zapret-autotune/recovery_primitives_test.go +++ b/cmd/zapret-autotune/recovery_primitives_test.go @@ -237,6 +237,56 @@ check loaded 2 strategies from /tmp/input.txt, --take 1, --passes 3 `, args, tls12, args, tls13, working) } +func TestCandidateEarlyTimeoutRemoteCaptures(t *testing.T) { + // Rows/results and variable metadata from profile dev's combined-corpus-{1,3} + // and checker-timeout-20-2 captures; reuse only the identical CLI framing. + const selected = "--payload=tls_client_hello --lua-desync=hostfakesplit:nofake2:tcp_ts=-1000:repeats=1 --lua-desync=multidisorder:pos=midsld" + const original = "--payload=tls_client_hello --lua-desync=hostfakesplit:disorder_after:ip_autottl=-3,3-20:repeats=1 --lua-desync=multidisorder:pos=1,midsld" + row := func(protocol, latency, speed string) string { + return fmt.Sprintf(`{"protocol":%q,"args":%q,"coverage":1,"success_rate":1,"median_latency_ms":%s,"median_speed_kbps":%s,"passes_ok":3,"passes_total":3}`, protocol, selected, latency, speed) + } + for _, c := range []struct { + name, args, rows, tls12, tls13, ips, elapsed, path string + working int + }{ + {"combinedrun3", selected, row("HTTPS/TLS1.3", "253", "3684.010622529644"), "FAIL 2/3 timeout", "OK median 253ms, 3684.0 KB/s", "142.251.156.4, 142.251.150.4, 142.251.155.4, 142.251.152.4, 142.251.154.4, 142.251.157.4, 142.251.151.4, 142.251.153.4", "8.1", "2026-10-10_14-36_check.json", 1}, + {"timeout20twofail", original, "", "FAIL 1/2 timeout", "FAIL 1/2 timeout", "142.251.150.4, 142.251.153.4, 142.251.155.4, 142.251.151.4, 142.251.152.4, 142.251.154.4, 142.251.157.4, 142.251.156.4", "41.1", "2026-10-10_13-16_check.json", 0}, + {"combinedrun1", selected, row("HTTPS/TLS1.3", "260", "3608.5486778846152") + "," + row("HTTPS/TLS1.2", "261", "3564.082704741379"), "OK median 261ms, 3564.1 KB/s", "OK median 260ms, 3608.5 KB/s", "142.251.151.4, 142.251.155.4, 142.251.157.4, 142.251.150.4, 142.251.152.4, 142.251.153.4, 142.251.156.4, 142.251.154.4", "2.4", "2026-10-10_14-35_check.json", 2}, + } { + t.Run(c.name, func(t *testing.T) { + report := []byte(fmt.Sprintf(`{"domain":"www.youtube.com","total":2,"working":%d,"strategies":[%s]}`, c.working, c.rows)) + diagnostic := strings.TrimPrefix(earlyTimeoutDiagnosticsFixture(c.args, c.tls12, c.tls13, c.working), "! --workers has no effect on `check` (it verifies strategies sequentially by design)\n") + diagnostic = strings.NewReplacer("AS3175 ...", "AS3175 Citytelecom LLC | 89.188.107.29 | Moscow, Moscow, RU", "142.251.156.4 (via", c.ips+" (via", "elapsed: 7.7s", "elapsed: "+c.elapsed+"s", "/tmp/input.txt.combined.json", c.path).Replace(diagnostic) + if c.working == 2 { + diagnostic = strings.Replace(diagnostic, "\n=== Check summary ===", " --take found 1 verified strategies per protocol, stopping\n\n=== Check summary ===", 1) + } + want := c.working < 2 + if got := candidateEarlyTimeout(report, []byte(diagnostic), c.args, "frontend", "www.youtube.com"); got != want { + t.Fatalf("candidateEarlyTimeout=%v want=%v", got, want) + } + if !want { + if _, err := selectBlockcheckEvidence(strings.NewReader(string(report)), c.args, "frontend", "www.youtube.com", true); err != nil { + t.Fatalf("passing capture rejected: %v", err) + } + return + } + for _, pair := range [][2]string{ + {c.ips, "142.251.156.4, garbage"}, + {"via doh (auto-fallback)", "via unknown"}, + {c.path, "unknown-output"}, + {c.path, c.path + "\nnfqws2 exited with status 1"}, + } { + if candidateEarlyTimeout(report, []byte(strings.Replace(diagnostic, pair[0], pair[1], 1)), c.args, "frontend", "www.youtube.com") { + t.Fatalf("unknown metadata/infrastructure accepted: %q", pair[1]) + } + } + if !candidateEarlyTimeout(report, []byte(strings.Replace(diagnostic, "via doh (auto-fallback)", "via system", 1)), c.args, "frontend", "www.youtube.com") { + t.Fatal("system-resolved addresses rejected") + } + }) + } +} + func TestCandidateEarlyTimeoutRowValidation(t *testing.T) { args := "--lua-desync=multisplit" var passing struct {