Skip to content

Commit 04f1aab

Browse files
copyleftdevclaude
andcommitted
chore: cargo fmt — fix formatting in stealth tests and profile
CI was failing on the format check. Ran cargo fmt --all to fix whitespace in stealth_test.rs, profile.rs, and browser.rs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a88bd32 commit 04f1aab

3 files changed

Lines changed: 68 additions & 38 deletions

File tree

crates/palimpsest-fetch/src/browser.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,7 @@ impl BrowserFetcher {
260260
};
261261
page.evaluate_on_new_document(injection_js)
262262
.await
263-
.map_err(|e| {
264-
PalimpsestError::Rendering(format!("script injection failed: {e}"))
265-
})?;
263+
.map_err(|e| PalimpsestError::Rendering(format!("script injection failed: {e}")))?;
266264

267265
// Navigate and wait for load.
268266
match tokio::time::timeout(self.config.page_timeout, page.goto(url.as_str())).await {

crates/palimpsest-fetch/src/profile.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ impl BrowserProfile {
167167
browser: BrowserType::Firefox,
168168
os: OsType::Linux,
169169
emulation: Emulation::Firefox136,
170-
user_agent: "Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0".into(),
170+
user_agent: "Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0"
171+
.into(),
171172
accept_language: "en-US,en;q=0.5".into(),
172173
sec_ch_ua: None,
173174
sec_ch_ua_platform: None,
@@ -203,13 +204,11 @@ impl BrowserProfile {
203204
/// Uses BLAKE3 hash of (seed + domain) to select a consistent profile
204205
/// per domain that doesn't change across crawl runs with the same seed.
205206
pub fn for_domain(seed: &CrawlSeed, domain: &str) -> Self {
206-
let derived = seed.derive(
207-
u64::from_le_bytes(
208-
blake3::hash(domain.as_bytes()).as_bytes()[..8]
209-
.try_into()
210-
.unwrap_or([0u8; 8]),
211-
),
212-
);
207+
let derived = seed.derive(u64::from_le_bytes(
208+
blake3::hash(domain.as_bytes()).as_bytes()[..8]
209+
.try_into()
210+
.unwrap_or([0u8; 8]),
211+
));
213212
Self::from_seed(&derived)
214213
}
215214
}

crates/palimpsest-fetch/tests/stealth_test.rs

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,11 @@ async fn launch_stealth_browser(
5858
.build()
5959
.map_err(|e| format!("browser config: {e}"))?;
6060

61-
let (browser, mut handler) = tokio::time::timeout(
62-
Duration::from_secs(30),
63-
Browser::launch(config),
64-
)
65-
.await
66-
.map_err(|_| "browser launch timed out".to_string())?
67-
.map_err(|e| format!("browser launch: {e}"))?;
61+
let (browser, mut handler) =
62+
tokio::time::timeout(Duration::from_secs(30), Browser::launch(config))
63+
.await
64+
.map_err(|_| "browser launch timed out".to_string())?
65+
.map_err(|e| format!("browser launch: {e}"))?;
6866

6967
let handle = tokio::spawn(async move {
7068
while let Some(event) = handler.next().await {
@@ -343,7 +341,8 @@ async fn test_stealth_sannysoft() {
343341
// Extract all test results from the table rows.
344342
// Sannysoft uses multiple tables — grab all rows from any table on the page.
345343
let results: serde_json::Value = page
346-
.evaluate(r#"
344+
.evaluate(
345+
r#"
347346
(() => {
348347
const rows = document.querySelectorAll('table tr');
349348
const results = {};
@@ -363,7 +362,8 @@ async fn test_stealth_sannysoft() {
363362
});
364363
return results;
365364
})()
366-
"#)
365+
"#,
366+
)
367367
.await
368368
.expect("evaluate")
369369
.into_value()
@@ -373,7 +373,10 @@ async fn test_stealth_sannysoft() {
373373
if let Some(obj) = results.as_object() {
374374
let mut failures = Vec::new();
375375
for (test, result) in obj {
376-
let failed = result.get("failed").and_then(|v| v.as_bool()).unwrap_or(false);
376+
let failed = result
377+
.get("failed")
378+
.and_then(|v| v.as_bool())
379+
.unwrap_or(false);
377380
let value = result.get("value").and_then(|v| v.as_str()).unwrap_or("?");
378381
let status = if failed { "FAIL" } else { "PASS" };
379382
eprintln!(" [{status}] {test}: {value}");
@@ -429,7 +432,8 @@ async fn test_stealth_infosimples() {
429432
tokio::time::sleep(Duration::from_secs(5)).await;
430433

431434
let results: serde_json::Value = page
432-
.evaluate(r#"
435+
.evaluate(
436+
r#"
433437
(() => {
434438
const rows = document.querySelectorAll('table tbody tr');
435439
const results = {};
@@ -448,7 +452,8 @@ async fn test_stealth_infosimples() {
448452
});
449453
return results;
450454
})()
451-
"#)
455+
"#,
456+
)
452457
.await
453458
.expect("evaluate")
454459
.into_value()
@@ -457,19 +462,36 @@ async fn test_stealth_infosimples() {
457462
if let Some(obj) = results.as_object() {
458463
let mut headless_count = 0;
459464
for (test, result) in obj {
460-
let headless = result.get("headless").and_then(|v| v.as_bool()).unwrap_or(false);
465+
let headless = result
466+
.get("headless")
467+
.and_then(|v| v.as_bool())
468+
.unwrap_or(false);
461469
let value = result.get("result").and_then(|v| v.as_str()).unwrap_or("?");
462470
let status = if headless { "DETECTED" } else { "PASS" };
463471
eprintln!(" [{status}] {test}: {value}");
464472
if headless {
465473
headless_count += 1;
466474
}
467475
}
468-
eprintln!(" Total: {} tests, {} detected as headless", obj.len(), headless_count);
469-
for critical in &["Webdriver", "Chrome element", "Plugins", "Languages", "Permission"] {
476+
eprintln!(
477+
" Total: {} tests, {} detected as headless",
478+
obj.len(),
479+
headless_count
480+
);
481+
for critical in &[
482+
"Webdriver",
483+
"Chrome element",
484+
"Plugins",
485+
"Languages",
486+
"Permission",
487+
] {
470488
if let Some(r) = obj.get(*critical) {
471489
let headless = r.get("headless").and_then(|v| v.as_bool()).unwrap_or(false);
472-
assert!(!headless, "critical check '{}' DETECTED on infosimples", critical);
490+
assert!(
491+
!headless,
492+
"critical check '{}' DETECTED on infosimples",
493+
critical
494+
);
473495
}
474496
}
475497
}
@@ -498,7 +520,8 @@ async fn test_stealth_botd() {
498520
tokio::time::sleep(Duration::from_secs(8)).await;
499521

500522
let results: serde_json::Value = page
501-
.evaluate(r#"
523+
.evaluate(
524+
r#"
502525
(() => {
503526
const rows = document.querySelectorAll('table tr');
504527
const results = {};
@@ -515,7 +538,8 @@ async fn test_stealth_botd() {
515538
results['_verdict'] = verdict ? verdict.textContent.trim() : 'unknown';
516539
return results;
517540
})()
518-
"#)
541+
"#,
542+
)
519543
.await
520544
.expect("evaluate")
521545
.into_value()
@@ -525,11 +549,12 @@ async fn test_stealth_botd() {
525549
if let Some(obj) = results.as_object() {
526550
for (test, value) in obj {
527551
let v = value.as_str().unwrap_or("?");
528-
let status = if v.to_lowercase().contains("detected") || v.to_lowercase().contains("bot") {
529-
"DETECTED"
530-
} else {
531-
"PASS"
532-
};
552+
let status =
553+
if v.to_lowercase().contains("detected") || v.to_lowercase().contains("bot") {
554+
"DETECTED"
555+
} else {
556+
"PASS"
557+
};
533558
eprintln!(" [{status}] {test}: {v}");
534559
}
535560
}
@@ -559,7 +584,8 @@ async fn test_stealth_rebrowser() {
559584

560585
// Rebrowser stores results in a textarea with id "detections-json".
561586
let results: serde_json::Value = page
562-
.evaluate(r#"
587+
.evaluate(
588+
r#"
563589
(() => {
564590
const textarea = document.querySelector('#detections-json');
565591
if (textarea) {
@@ -569,7 +595,8 @@ async fn test_stealth_rebrowser() {
569595
if (window.detections) return window.detections;
570596
return [];
571597
})()
572-
"#)
598+
"#,
599+
)
573600
.await
574601
.expect("evaluate")
575602
.into_value()
@@ -579,8 +606,14 @@ async fn test_stealth_rebrowser() {
579606
let mut fail_count = 0;
580607
if let Some(arr) = results.as_array() {
581608
for detection in arr {
582-
let dtype = detection.get("type").and_then(|v| v.as_str()).unwrap_or("?");
583-
let rating = detection.get("rating").and_then(|v| v.as_f64()).unwrap_or(0.0);
609+
let dtype = detection
610+
.get("type")
611+
.and_then(|v| v.as_str())
612+
.unwrap_or("?");
613+
let rating = detection
614+
.get("rating")
615+
.and_then(|v| v.as_f64())
616+
.unwrap_or(0.0);
584617
let note = detection.get("note").and_then(|v| v.as_str()).unwrap_or("");
585618
let status = if rating > 0.0 { "FAIL" } else { "PASS" };
586619
eprintln!(" [{status}] {dtype} (rating: {rating}): {note}");

0 commit comments

Comments
 (0)