Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor(cli): rename redirect wait option

ldm024b94d36c2c4
diff --git a/moli/src/app.rs b/moli/src/app.rs
index e56b73b94..e9f2aa8f7 100644
--- a/moli/src/app.rs
+++ b/moli/src/app.rs
@@ -62,7 +62,7 @@ pub async fn run_cli_with_config<W: Write>(
.context("failed to initialize browser runtime")?;
load_cookie_state(&browser, &config)?;
let timeout = std::time::Duration::from_millis(args.timeout);
- let navigation_grace = Duration::from_millis(args.redirect_time);
+ let navigation_grace = Duration::from_millis(args.redirect_wait_ms);
let request = build_fetch_request(&args.url, &config)?;
let fetch_result = match args.wait_until {
FetchWaitUntil::Done => {
diff --git a/moli/src/cli.rs b/moli/src/cli.rs
index 6576ac386..c27484058 100644
--- a/moli/src/cli.rs
+++ b/moli/src/cli.rs
@@ -13,7 +13,7 @@ const FETCH_INFER_FLAGS: &[&str] = &[
"--with-base",
"--with-frames",
"--wait-until",
- "--redirect-time",
+ "--redirect-wait-ms",
"--wait-selector",
"--wait-script",
"--wait-script-file",
@@ -50,7 +50,7 @@ const DUMP_MODES: &[&str] = &[
"semantic_tree_text",
];
-pub const DEFAULT_REDIRECT_TIME_MS: u64 = 1_000;
+pub const DEFAULT_REDIRECT_WAIT_MS: u64 = 1_000;
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
#[command(
@@ -112,9 +112,9 @@ pub struct FetchArgs {
#[arg(
long,
value_name = "MILLISECONDS",
- default_value_t = DEFAULT_REDIRECT_TIME_MS
+ default_value_t = DEFAULT_REDIRECT_WAIT_MS
)]
- pub redirect_time: u64,
+ pub redirect_wait_ms: u64,
#[arg(long)]
pub wait_selector: Option<String>,
@@ -578,17 +578,27 @@ mod tests {
}
#[test]
- fn redirect_time_infers_fetch_command() {
+ fn redirect_wait_ms_infers_fetch_command() {
let args =
- normalize_args_for_compat(["moli", "--redirect-time=1500", "https://example.test/"]);
+ normalize_args_for_compat(["moli", "--redirect-wait-ms=1500", "https://example.test/"]);
let cli = Cli::parse_from(args);
match cli.command {
- Commands::Fetch(args) => assert_eq!(args.redirect_time, 1_500),
+ Commands::Fetch(args) => assert_eq!(args.redirect_wait_ms, 1_500),
other => panic!("expected fetch command, got {other:?}"),
}
}
+ #[test]
+ fn fetch_help_exposes_only_redirect_wait_ms() {
+ let help = Cli::try_parse_from(["moli", "fetch", "--help"])
+ .unwrap_err()
+ .to_string();
+
+ assert!(help.contains("--redirect-wait-ms <MILLISECONDS>"));
+ assert!(!help.contains("--redirect-time"));
+ }
+
#[test]
fn port_equals_infers_serve_command() {
let args = normalize_args_for_compat(["moli", "--port=0"]);
diff --git a/moli/tests/cli.rs b/moli/tests/cli.rs
index bc6b9d675..f8833a6d5 100644
--- a/moli/tests/cli.rs
+++ b/moli/tests/cli.rs
@@ -93,7 +93,7 @@ fn parses_explicit_fetch_command_with_compatibility_flags() {
trace_matched_response_body: false,
strip_mode: vec![StripModeChoice::Css, StripModeChoice::Ui],
wait_until: FetchWaitUntil::Done,
- redirect_time: 1_000,
+ redirect_wait_ms: 1_000,
wait_selector: None,
wait_script: None,
wait_script_file: None,
@@ -385,7 +385,7 @@ fn infers_fetch_mode_from_bare_url() {
trace_matched_response_body: false,
strip_mode: vec![],
wait_until: FetchWaitUntil::Done,
- redirect_time: 1_000,
+ redirect_wait_ms: 1_000,
wait_selector: None,
wait_script: None,
wait_script_file: None,
@@ -421,7 +421,7 @@ fn infers_fetch_mode_from_fetch_only_flags_and_defaults_dump_to_html() {
trace_matched_response_body: false,
strip_mode: vec![],
wait_until: FetchWaitUntil::Done,
- redirect_time: 1_000,
+ redirect_wait_ms: 1_000,
wait_selector: None,
wait_script: None,
wait_script_file: None,
@@ -461,7 +461,7 @@ fn infers_fetch_mode_from_header_flag() {
trace_matched_response_body: false,
strip_mode: vec![],
wait_until: FetchWaitUntil::Done,
- redirect_time: 1_000,
+ redirect_wait_ms: 1_000,
wait_selector: None,
wait_script: None,
wait_script_file: None,
diff --git a/moli/tests/fetch_cli.rs b/moli/tests/fetch_cli.rs
index 29930d14b..bcf93b202 100644
--- a/moli/tests/fetch_cli.rs
+++ b/moli/tests/fetch_cli.rs
@@ -2235,11 +2235,11 @@ fn cli_explicit_load_rejects_navigation_after_the_one_second_grace() -> Result<(
}
#[test]
-fn cli_redirect_time_can_extend_http_error_navigation_grace() -> Result<()> {
+fn cli_redirect_wait_can_extend_http_error_navigation_grace() -> Result<()> {
let runtime = tokio::runtime::Runtime::new()?;
let server = runtime.block_on(FixtureServer::spawn())?;
let url = server.url("/wait-until-http-error-late-navigation");
- let output = run_fetch_cli_with_dump_and_args(&url, "html", &["--redirect-time", "1500"])?;
+ let output = run_fetch_cli_with_dump_and_args(&url, "html", &["--redirect-wait-ms", "1500"])?;
runtime.block_on(server.shutdown());
assert!(
@@ -2261,11 +2261,11 @@ fn cli_redirect_time_can_extend_http_error_navigation_grace() -> Result<()> {
}
#[test]
-fn cli_zero_redirect_time_accepts_navigation_already_pending_at_stage() -> Result<()> {
+fn cli_zero_redirect_wait_accepts_navigation_already_pending_at_stage() -> Result<()> {
let runtime = tokio::runtime::Runtime::new()?;
let server = runtime.block_on(FixtureServer::spawn())?;
let url = server.url("/wait-until-http-error-immediate-navigation");
- let output = run_fetch_cli_with_dump_and_args(&url, "html", &["--redirect-time", "0"])?;
+ let output = run_fetch_cli_with_dump_and_args(&url, "html", &["--redirect-wait-ms", "0"])?;
runtime.block_on(server.shutdown());
assert!(
@@ -2287,11 +2287,11 @@ fn cli_zero_redirect_time_accepts_navigation_already_pending_at_stage() -> Resul
}
#[test]
-fn cli_zero_redirect_time_rejects_navigation_that_starts_later() -> Result<()> {
+fn cli_zero_redirect_wait_rejects_navigation_that_starts_later() -> Result<()> {
let runtime = tokio::runtime::Runtime::new()?;
let server = runtime.block_on(FixtureServer::spawn())?;
let url = server.url("/wait-until-http-error-navigation");
- let output = run_fetch_cli_with_dump_and_args(&url, "html", &["--redirect-time", "0"])?;
+ let output = run_fetch_cli_with_dump_and_args(&url, "html", &["--redirect-wait-ms", "0"])?;
runtime.block_on(server.shutdown());
assert!(!output.status.success());