Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ chrono = { version = "0.4", features = ["serde"] }

# CLI
clap = { version = "4.5", features = ["derive"] }
clap-ext = { git = "https://github.com/KooshaPari/clap-ext", tag = "v0.1.0" }

# Error handling
thiserror = "2.0"
Expand Down
50 changes: 50 additions & 0 deletions tests/clap_ext_smoke.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Smoke tests verifying that clap-ext's Verbosity and ConfigArg work in this CLI.

use clap::Parser;
use clap_ext::prelude::*;

#[test]
fn clap_ext_verbosity_parses_quiet_flag() {
#[derive(Parser)]
struct Probe {
#[command(flatten)]
verbosity: Verbosity,
}
let p = Probe::try_parse_from(["probe", "--quiet"]).expect("parse");
let filter = p.verbosity.to_filter();
assert_eq!(format!("{:?}", filter), "ERROR");
}

#[test]
fn clap_ext_verbosity_parses_double_v() {
#[derive(Parser)]
struct Probe {
#[command(flatten)]
verbosity: Verbosity,
}
let p = Probe::try_parse_from(["probe", "-vv"]).expect("parse");
let filter = p.verbosity.to_filter();
assert_eq!(format!("{:?}", filter), "TRACE");
}

#[test]
fn clap_ext_config_arg_default_is_none() {
#[derive(Parser)]
struct Probe {
#[command(flatten)]
config: ConfigArg,
}
let p = Probe::try_parse_from(["probe"]).expect("parse");
assert!(p.config.path().is_none());
Comment on lines +37 to +38

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: This assertion is environment-dependent: ConfigArg also reads from PHENOTYPE_CONFIG, so on machines/CI where that env var is set, parsing with no CLI args will produce Some(path) and this test will fail nondeterministically. Clear or scope PHENOTYPE_CONFIG for this test before parsing so the default behavior is tested in isolation. [logic error]

Severity Level: Major ⚠️
- ⚠️ Smoke test `clap_ext_config_arg_default_is_none` fails when PHENOTYPE_CONFIG set.
- ⚠️ CI suite becomes flaky depending on external environment configuration.
Steps of Reproduction ✅
1. Ensure the test binary is built with this PR so that `tests/clap_ext_smoke.rs` is
included; locate test `clap_ext_config_arg_default_is_none` at
`tests/clap_ext_smoke.rs:31-38` (verified via Grep).

2. In the shell or CI environment, set `PHENOTYPE_CONFIG=/tmp/cfg.toml` before running
tests so that the process environment contains a config path used by `ConfigArg` (per the
PR description of `ConfigArg` behavior).

3. Run `cargo test clap_ext_config_arg_default_is_none` so the test in
`tests/clap_ext_smoke.rs` constructs `Probe` via `Probe::try_parse_from(["probe"])` at
line 37, with `config: ConfigArg` defined at line 35 and reading from `PHENOTYPE_CONFIG`
when no `-c` flag is supplied.

4. Observe that `p.config.path()` now returns `Some("/tmp/cfg.toml")`, causing the
assertion `assert!(p.config.path().is_none());` at line 38 to fail, making the test
outcome depend on whether `PHENOTYPE_CONFIG` was set in the environment.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/clap_ext_smoke.rs
**Line:** 37:38
**Comment:**
	*Logic Error: This assertion is environment-dependent: `ConfigArg` also reads from `PHENOTYPE_CONFIG`, so on machines/CI where that env var is set, parsing with no CLI args will produce `Some(path)` and this test will fail nondeterministically. Clear or scope `PHENOTYPE_CONFIG` for this test before parsing so the default behavior is tested in isolation.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config default test ignores env

Medium Severity

clap_ext_config_arg_default_is_none parses with no CLI args and expects config.path() to be absent, but ConfigArg also honors PHENOTYPE_CONFIG. Clap still reads that env during try_parse_from, so a preset value makes the assertion fail even though no -c was passed.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c6b9592. Configure here.

}

#[test]
fn clap_ext_config_arg_parses_short_flag() {
#[derive(Parser)]
struct Probe {
#[command(flatten)]
config: ConfigArg,
}
let p = Probe::try_parse_from(["probe", "-c", "/tmp/cfg.toml"]).expect("parse");
assert_eq!(p.config.path().unwrap().to_str().unwrap(), "/tmp/cfg.toml");
}
Loading