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): require JSON for network traces (#185)

Donough Liu49cc382492af
diff --git a/moli/src/cli.rs b/moli/src/cli.rs
index 0421bd5f1..2bbcf72d1 100644
--- a/moli/src/cli.rs
+++ b/moli/src/cli.rs
@@ -56,7 +56,9 @@ pub struct FetchArgs {
#[arg(long)]
pub with_frames: bool,
- #[arg(long)]
+ /// Include a structured network trace in JSON output. Requires
+ /// `--dump json`.
+ #[arg(long, requires = "dump")]
pub trace_network: bool,
#[arg(long, requires = "trace_network")]
diff --git a/moli/src/config.rs b/moli/src/config.rs
index d31efc34b..53c972938 100644
--- a/moli/src/config.rs
+++ b/moli/src/config.rs
@@ -29,6 +29,9 @@ impl AppConfig {
match &cli.command {
Commands::Fetch(args) => {
+ if args.trace_network && args.dump != Some(DumpFormat::Json) {
+ bail!("--trace-network requires --dump json");
+ }
apply_common_args(&mut config, &args.common)?;
if args.common.log_level.is_none() {
config.log_filter = "off".to_owned();
diff --git a/moli/tests/cli.rs b/moli/tests/cli.rs
index 4bf581919..f1be3ebe5 100644
--- a/moli/tests/cli.rs
+++ b/moli/tests/cli.rs
@@ -324,6 +324,10 @@ fn parses_trace_network_fetch_flag() {
]))
.unwrap();
+ let config = AppConfig::from_cli(&cli).unwrap();
+ assert!(config.fetch.trace_network);
+ assert_eq!(config.fetch.dump_mode, Some(DumpFormat::Json));
+
let Commands::Fetch(args) = cli.command else {
panic!("expected fetch command");
};
@@ -333,6 +337,35 @@ fn parses_trace_network_fetch_flag() {
assert_eq!(args.dump, Some(DumpFormat::Json));
}
+#[test]
+fn trace_network_requires_an_explicit_dump_mode() {
+ let err = Cli::try_parse_from(normalize_args_for_compat([
+ "moli",
+ "fetch",
+ "--trace-network",
+ "https://example.com",
+ ]))
+ .unwrap_err();
+
+ assert_eq!(err.kind(), clap::error::ErrorKind::MissingRequiredArgument);
+}
+
+#[test]
+fn app_config_requires_json_dump_for_network_trace() {
+ let cli = Cli::try_parse_from(normalize_args_for_compat([
+ "moli",
+ "fetch",
+ "--trace-network",
+ "--dump",
+ "html",
+ "https://example.com",
+ ]))
+ .unwrap();
+
+ let error = AppConfig::from_cli(&cli).unwrap_err();
+ assert_eq!(error.to_string(), "--trace-network requires --dump json");
+}
+
#[test]
fn parses_trace_matched_response_body_fetch_flag() {
let cli = Cli::try_parse_from(normalize_args_for_compat([