Skip to content

Commit 150a0df

Browse files
GiggleLiuclaude
andcommitted
fix: address PR #190 review — test exit codes, ILP/CircuitSAT ordering, edge trim
- Update 3 tests to expect non-zero exit when showing help (issue #189 item 9) - Move ILP/CircuitSAT check before empty-flags help so they get the "via reduction" message instead of generic schema help - Trim each side of edge pairs in parse_edge_pairs for robustness Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 63e818b commit 150a0df

3 files changed

Lines changed: 23 additions & 22 deletions

File tree

problemreductions-cli/src/commands/create.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ pub fn create(args: &CreateArgs, out: &OutputConfig) -> Result<()> {
161161
return create_random(args, canonical, &resolved_variant, out);
162162
}
163163

164+
// ILP and CircuitSAT have complex input structures not suited for CLI flags.
165+
// Check before the empty-flags help so they get a clear message.
166+
if canonical == "ILP" || canonical == "CircuitSAT" {
167+
bail!(
168+
"CLI creation is not yet supported for {canonical}.\n\n\
169+
{canonical} instances are typically created via reduction:\n\
170+
pred create MIS --graph 0-1,1-2 | pred reduce - --to {canonical}\n\n\
171+
Or use the Rust API for direct construction."
172+
);
173+
}
174+
164175
// Show schema-driven help when no data flags are provided
165176
if all_data_flags_empty(args) {
166177
let gt = if graph_type != "SimpleGraph" {
@@ -421,17 +432,6 @@ pub fn create(args: &CreateArgs, out: &OutputConfig) -> Result<()> {
421432
)
422433
}
423434

424-
// ILP and CircuitSAT have complex input structures not suited for CLI flags.
425-
// They are typically created via reductions from other problems.
426-
"ILP" | "CircuitSAT" => {
427-
bail!(
428-
"CLI creation is not yet supported for {canonical}.\n\n\
429-
{canonical} instances are typically created via reduction:\n\
430-
pred create MIS --graph 0-1,1-2 | pred reduce - --to {canonical}\n\n\
431-
Or use the Rust API for direct construction."
432-
);
433-
}
434-
435435
_ => bail!("{}", crate::problem_name::unknown_problem_error(canonical)),
436436
};
437437

problemreductions-cli/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ pub fn parse_edge_pairs(s: &str) -> Result<Vec<(usize, usize)>> {
250250
if parts.len() != 2 {
251251
bail!("Invalid edge '{}': expected format u-v", pair.trim());
252252
}
253-
let u: usize = parts[0].parse()?;
254-
let v: usize = parts[1].parse()?;
253+
let u: usize = parts[0].trim().parse()?;
254+
let v: usize = parts[1].trim().parse()?;
255255
Ok((u, v))
256256
})
257257
.collect()

problemreductions-cli/tests/cli_tests.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,12 +1105,11 @@ fn test_create_unknown_problem() {
11051105

11061106
#[test]
11071107
fn test_create_no_flags_shows_help() {
1108-
// pred create MIS with no data flags shows schema-driven help
1108+
// pred create MIS with no data flags shows schema-driven help and exits non-zero
11091109
let output = pred().args(["create", "MIS"]).output().unwrap();
11101110
assert!(
1111-
output.status.success(),
1112-
"stderr: {}",
1113-
String::from_utf8_lossy(&output.stderr)
1111+
!output.status.success(),
1112+
"should exit non-zero when showing help without data flags"
11141113
);
11151114
let stderr = String::from_utf8_lossy(&output.stderr);
11161115
assert!(
@@ -2560,12 +2559,11 @@ fn test_create_factoring_with_bits() {
25602559

25612560
#[test]
25622561
fn test_create_factoring_no_flags_shows_help() {
2563-
// pred create Factoring with no data flags shows schema-driven help
2562+
// pred create Factoring with no data flags shows schema-driven help and exits non-zero
25642563
let output = pred().args(["create", "Factoring"]).output().unwrap();
25652564
assert!(
2566-
output.status.success(),
2567-
"stderr: {}",
2568-
String::from_utf8_lossy(&output.stderr)
2565+
!output.status.success(),
2566+
"should exit non-zero when showing help without data flags"
25692567
);
25702568
let stderr = String::from_utf8_lossy(&output.stderr);
25712569
assert!(
@@ -2894,7 +2892,10 @@ fn test_create_kings_subgraph_help() {
28942892
.args(["create", "MIS/KingsSubgraph"])
28952893
.output()
28962894
.unwrap();
2897-
assert!(output.status.success());
2895+
assert!(
2896+
!output.status.success(),
2897+
"should exit non-zero when showing help"
2898+
);
28982899
let stderr = String::from_utf8(output.stderr).unwrap();
28992900
assert!(
29002901
stderr.contains("positions") || stderr.contains("MaximumIndependentSet"),

0 commit comments

Comments
 (0)