use super::*;
use crate::{profile_to_overrides, StealthProfile};
fn cfg_for(profile: StealthProfile) -> Value {
lurien_config(&profile_to_overrides(&profile))
}
#[test]
fn maps_navigator_and_screen_from_persona() {
let ov = profile_to_overrides(&StealthProfile::FirefoxLinux);
let cfg = lurien_config(&ov);
assert_eq!(cfg["navigator.userAgent"], json!(ov.user_agent));
assert_eq!(cfg["navigator.platform"], json!(ov.platform));
assert_eq!(
cfg["navigator.hardwareConcurrency"],
json!(ov.hardware_concurrency)
);
assert_eq!(cfg["screen.width"], json!(ov.screen_width));
assert_eq!(cfg["screen.height"], json!(ov.screen_height));
}
#[test]
fn desktop_window_geometry_is_coherent_with_the_persona_screen() {
let ov = profile_to_overrides(&StealthProfile::FirefoxLinux);
let cfg = lurien_config(&ov);
let u = |k: &str| cfg[k].as_u64().unwrap();
assert_eq!(cfg["screen.availWidth"], json!(ov.screen_width));
assert_eq!(cfg["screen.availHeight"], json!(ov.screen_height));
assert_eq!(u("screen.availTop"), 0);
assert_eq!(u("window.screenX"), 0);
assert_eq!(u("window.screenY"), 0);
assert!(u("window.outerHeight") <= u("screen.height"));
assert!(u("screen.availHeight") <= u("screen.height"));
assert!(u("window.screenY") + u("window.outerHeight") <= u("screen.height"));
assert!(u("window.innerHeight") < u("window.outerHeight"));
assert_eq!(u("window.innerHeight"), u64::from(ov.screen_height) - 124);
}
#[test]
fn mobile_persona_window_is_chromeless_fullscreen() {
let ov = profile_to_overrides(&StealthProfile::ChromeAndroid);
assert!(ov.mobile, "ChromeAndroid persona must be mobile");
let cfg = lurien_config(&ov);
assert_eq!(cfg["window.innerHeight"], json!(ov.screen_height));
assert_eq!(cfg["window.outerHeight"], json!(ov.screen_height));
}
#[test]
fn navigator_webdriver_pinned_false_for_every_persona() {
for p in [
StealthProfile::FirefoxLinux,
StealthProfile::FirefoxWindows,
StealthProfile::ChromeWindowsStable,
] {
assert_eq!(cfg_for(p)["navigator.webdriver"], json!(false));
}
}
#[test]
fn firefox_linux_omits_webgl_keys_for_native_passthrough() {
let cfg = cfg_for(StealthProfile::FirefoxLinux);
assert!(
cfg.get("webGl:vendor").is_none(),
"matched-host persona must not pin a WebGL vendor"
);
assert!(cfg.get("webGl:renderer").is_none());
}
#[test]
fn cross_os_persona_pins_webgl() {
let cfg = cfg_for(StealthProfile::ChromeWindowsStable);
assert!(
cfg.get("webGl:renderer").is_some(),
"a persona with a non-empty renderer must pin webGl:renderer"
);
}
#[test]
fn header_user_agent_matches_navigator() {
let cfg = cfg_for(StealthProfile::FirefoxLinux);
assert_eq!(cfg["headers.User-Agent"], cfg["navigator.userAgent"]);
}
#[test]
fn accept_language_q_values_descend() {
let al = accept_language(&["en-US".into(), "en".into(), "fr".into()]);
assert_eq!(al, "en-US,en;q=0.9,fr;q=0.8");
}
#[test]
fn env_is_single_var_for_small_config() {
let env = lurien_config_env(&profile_to_overrides(&StealthProfile::FirefoxLinux));
assert_eq!(env.len(), 1);
assert_eq!(env[0].0, LURIEN_CONFIG_ENV);
let parsed: Value = serde_json::from_str(&env[0].1).expect("config is valid JSON");
assert!(parsed.is_object());
}
#[test]
fn languages_drive_navigator_language() {
let ov = profile_to_overrides(&StealthProfile::FirefoxLinux);
let cfg = lurien_config(&ov);
if let Some(first) = ov.languages.first() {
assert_eq!(cfg["navigator.language"], json!(first));
}
}
#[test]
fn full_language_list_populates_locale_all() {
let ov = profile_to_overrides(&StealthProfile::FirefoxLinux);
assert!(
ov.languages.len() >= 2,
"FirefoxLinux persona must carry a multi-entry language list"
);
let cfg = lurien_config(&ov);
assert_eq!(
cfg["locale:all"],
json!(ov.languages.join(", ")),
"locale:all must be the full comma-space language list the engine reads first"
);
let all = cfg["locale:all"].as_str().unwrap();
assert_eq!(all.split(", ").count(), ov.languages.len());
}
#[test]
fn wrapper_script_loads_config_and_execs_binary() {
let s = lurien_wrapper_script("/tmp/cfg.json", "/opt/lurien/lurien");
assert!(s.starts_with("#!/bin/sh"));
assert!(
s.contains("_lurien_cfg=\"$(cat '/tmp/cfg.json')\""),
"wrapper must load config from the file: {s}"
);
assert!(s.contains("export LURIEN_CONFIG REYNARD_CONFIG CAMOU_CONFIG"));
assert!(
s.contains("LURIEN_CONFIG=\"$_lurien_cfg\""),
"wrapper must export LURIEN_CONFIG: {s}"
);
assert!(
s.contains("REYNARD_CONFIG=\"$_lurien_cfg\""),
"wrapper must export REYNARD_CONFIG for the installed June engine: {s}"
);
assert!(
s.contains("CAMOU_CONFIG=\"$_lurien_cfg\""),
"wrapper must export CAMOU_CONFIG as last-resort: {s}"
);
assert!(
s.contains("exec '/opt/lurien/lurien' \"$@\""),
"wrapper must exec the binary forwarding BiDi flags: {s}"
);
}
#[test]
fn align_ua_to_engine_rewrites_firefox_major() {
let persona = "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0";
let aligned = align_ua_to_engine(persona, 150);
assert_eq!(
aligned,
"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0"
);
assert!(aligned.contains("Gecko/20100101"));
}
#[test]
fn align_ua_to_engine_is_noop_when_matching_or_absent() {
let persona = "Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0";
assert_eq!(align_ua_to_engine(persona, 150), persona);
let other = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Safari/537.36";
assert_eq!(align_ua_to_engine(other, 150), other);
}
#[test]
fn identity_seed_is_stable_and_distinct() {
assert_eq!(
identity_seed("/profiles/acct-a"),
identity_seed("/profiles/acct-a")
);
assert_ne!(
identity_seed("/profiles/acct-a"),
identity_seed("/profiles/acct-b")
);
assert_ne!(identity_seed("acct-1"), identity_seed("acct-2"));
}
#[test]
fn merge_lurien_prefs_none_is_just_webdriver_pref() {
assert_eq!(merge_lurien_prefs(None), LURIEN_PROFILE_PREFS);
assert_eq!(merge_lurien_prefs(Some(" ".into())), LURIEN_PROFILE_PREFS);
}
#[test]
fn merge_lurien_prefs_keeps_caller_prefs() {
let merged = merge_lurien_prefs(Some("user_pref(\"network.proxy.type\", 1);".into()));
assert!(
merged.contains("network.proxy.type"),
"caller pref preserved"
);
assert!(
merged.contains("dom.webdriver.enabled"),
"lurien pref added"
);
}
#[test]
fn wrapper_forwards_bidi_flags_via_args() {
assert!(lurien_wrapper_script("/c", "/b").contains("\"$@\""));
}
#[test]
fn resolve_lurien_bin_precedence_and_missing_is_err() {
let r = resolve_lurien_bin_from(
|k| match k {
"LURIEN_BIN" => Some("/x/lurien".into()),
"REYNARD_BIN" => Some("/x/lurien".into()),
"GUISE_REYNARD_BIN" => Some("/y/guise".into()),
"HOME" => Some("/home/u".into()),
_ => None,
},
|_| true,
)
.expect("LURIEN_BIN set");
assert_eq!(r, "/x/lurien");
let r = resolve_lurien_bin_from(
|k| match k {
"REYNARD_BIN" => Some("/x/lurien".into()),
"GUISE_REYNARD_BIN" => Some("/y/guise".into()),
_ => None,
},
|_| true,
)
.expect("REYNARD_BIN alias");
assert_eq!(r, "/x/lurien");
let r = resolve_lurien_bin_from(
|k| match k {
"LURIEN_BIN" => Some(" ".into()),
"GUISE_REYNARD_BIN" => Some("/y/guise".into()),
_ => None,
},
|_| true,
)
.expect("blank LURIEN_BIN falls through");
assert_eq!(r, "/y/guise");
let r = resolve_lurien_bin_from(
|k| (k == "HOME").then(|| "/home/u".into()),
|p| p == "/home/u/.local/share/lurien/lurien",
)
.expect("new install path");
assert_eq!(r, "/home/u/.local/share/lurien/lurien");
let r = resolve_lurien_bin_from(
|k| (k == "HOME").then(|| "/home/u".into()),
|p| p == "/home/u/.cache/reynard/reynard",
)
.expect("old install path alias");
assert_eq!(r, "/home/u/.cache/reynard/reynard");
let err = resolve_lurien_bin_from(|_| None, |_| false).expect_err("missing is Err");
let msg = err.to_string();
assert!(
msg.contains("lurien engine not installed") && msg.contains("LURIEN_BIN"),
"missing engine must name install.sh / LURIEN_BIN, got {msg}"
);
}