Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(cli): keep fetch dump output quiet by default

ldm0050245f035bd
diff --git a/moli/src/cli.rs b/moli/src/cli.rs
index 2409ee686..57006a565 100644
--- a/moli/src/cli.rs
+++ b/moli/src/cli.rs
@@ -39,7 +39,8 @@ pub enum Commands {
pub struct FetchArgs {
/// Select the fetch output format. `screenshot` writes a viewport PNG,
/// `screenshot_full` writes a full-document PNG, and `pdf` writes a
- /// paginated PDF directly to stdout; all three require layout.
+ /// paginated PDF directly to stdout; all three require layout. Dump output
+ /// is quiet by default; pass `--log-level` to opt into diagnostic logs.
#[arg(short, long, value_enum)]
pub dump: Option<DumpFormat>,
diff --git a/moli/src/config.rs b/moli/src/config.rs
index 3d3016822..2c93c444b 100644
--- a/moli/src/config.rs
+++ b/moli/src/config.rs
@@ -32,6 +32,9 @@ impl AppConfig {
match &cli.command {
Commands::Fetch(args) => {
apply_common_args(&mut config, &args.common)?;
+ if args.common.log_level.is_none() {
+ config.log_filter = "off".to_owned();
+ }
config.fetch.request_headers = args
.headers
.iter()
diff --git a/moli/tests/cli.rs b/moli/tests/cli.rs
index 40523ba4e..1ab53c7b0 100644
--- a/moli/tests/cli.rs
+++ b/moli/tests/cli.rs
@@ -653,6 +653,44 @@ fn app_config_uses_moli_user_agent_defaults() {
assert_eq!(config.browser.fetch().user_agent(), "ExampleBrowser/1.0");
}
+#[test]
+fn app_config_makes_fetch_quiet_unless_log_level_is_set() {
+ let quiet_cli = Cli::try_parse_from(normalize_args_for_compat([
+ "moli",
+ "fetch",
+ "--dump",
+ "screenshot",
+ "--layout",
+ "about:blank",
+ ]))
+ .unwrap();
+ let quiet_config = AppConfig::from_cli(&quiet_cli).unwrap();
+ assert_eq!(quiet_config.log_filter, "off");
+
+ let debug_cli = Cli::try_parse_from(normalize_args_for_compat([
+ "moli",
+ "fetch",
+ "--dump",
+ "screenshot",
+ "--layout",
+ "--log-level",
+ "debug",
+ "about:blank",
+ ]))
+ .unwrap();
+ let debug_config = AppConfig::from_cli(&debug_cli).unwrap();
+ assert_eq!(debug_config.log_filter, "debug");
+
+ let implicit_html_cli =
+ Cli::try_parse_from(normalize_args_for_compat(["moli", "fetch", "about:blank"])).unwrap();
+ let implicit_html_config = AppConfig::from_cli(&implicit_html_cli).unwrap();
+ assert_eq!(implicit_html_config.log_filter, "off");
+
+ let serve_cli = Cli::try_parse_from(["moli", "serve"]).unwrap();
+ let serve_config = AppConfig::from_cli(&serve_cli).unwrap();
+ assert_eq!(serve_config.log_filter, "info");
+}
+
#[test]
fn app_config_loads_and_validates_web_bot_auth_key() {
let key_file = write_temp_web_bot_auth_key();
diff --git a/moli/tests/fetch_cli.rs b/moli/tests/fetch_cli.rs
index adec9a378..af6c811a9 100644
--- a/moli/tests/fetch_cli.rs
+++ b/moli/tests/fetch_cli.rs
@@ -803,6 +803,51 @@ fn cli_dump_screenshot_writes_png_bytes() -> Result<()> {
Ok(())
}
+#[test]
+fn cli_dump_screenshot_is_quiet_by_default() -> Result<()> {
+ let output = Command::new(env!("CARGO_BIN_EXE_moli"))
+ .args(["fetch", "--dump", "screenshot", "--layout", "about:blank"])
+ .output()?;
+
+ assert!(
+ output.status.success(),
+ "moli fetch failed: stdout_bytes={}\nstderr={}",
+ output.stdout.len(),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ assert!(output.stdout.starts_with(b"\x89PNG\r\n\x1a\n"));
+ assert!(
+ output.stderr.is_empty(),
+ "--dump should be quiet by default: stderr={}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ Ok(())
+}
+
+#[test]
+fn cli_fetch_implicit_html_dump_is_quiet_by_default() -> Result<()> {
+ let output = Command::new(env!("CARGO_BIN_EXE_moli"))
+ .args(["fetch", "about:blank"])
+ .output()?;
+
+ assert!(
+ output.status.success(),
+ "moli fetch failed: stdout={}\nstderr={}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ assert_eq!(
+ clean_output(&output.stdout),
+ "<html><head></head><body></body></html>"
+ );
+ assert!(
+ output.stderr.is_empty(),
+ "fetch should be quiet by default: stderr={}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ Ok(())
+}
+
#[test]
fn cli_dump_full_screenshot_writes_png_bytes() -> Result<()> {
let output = run_fetch_cli_with_dump_and_args("about:blank", "screenshot_full", &["--layout"])?;