#[test]
fn test_verbose_inheritance_run_local() {
let args = vec!["apr", "run", "model.gguf", "--prompt", "test", "-v"];
let cli = parse_cli(args).expect("Failed to parse");
match *cli.command {
Commands::Run { verbose, .. } => {
let effective = verbose || cli.verbose;
assert!(effective, "effective verbose should be true");
}
_ => panic!("Expected Run command"),
}
}
#[test]
fn test_parse_run_gpu_nogpu_conflict() {
let args = vec![
"apr",
"run",
"model.gguf",
"--prompt",
"test",
"--gpu",
"--no-gpu",
];
let result = parse_cli(args);
assert!(result.is_err(), "--gpu and --no-gpu should conflict in Run");
}
#[test]
fn test_parse_run_gpu_only() {
let args = vec!["apr", "run", "model.gguf", "--prompt", "test", "--gpu"];
let cli = parse_cli(args).expect("Failed to parse");
match *cli.command {
Commands::Run { gpu, no_gpu, .. } => {
assert!(gpu);
assert!(!no_gpu);
}
_ => panic!("Expected Run command"),
}
}
#[test]
fn test_missing_serve_file() {
let args = vec!["apr", "serve"];
let result = parse_cli(args);
assert!(result.is_err(), "serve requires FILE");
}
#[test]
fn test_missing_diff_second_file() {
let args = vec!["apr", "diff", "model1.apr"];
let result = parse_cli(args);
assert!(result.is_err(), "diff requires two files");
}
#[test]
fn test_missing_export_output() {
let args = vec!["apr", "export", "model.apr"];
let result = parse_cli(args);
assert!(result.is_ok(), "export parses without -o (validated at runtime)");
}
#[test]
fn test_missing_convert_output() {
let args = vec!["apr", "convert", "model.apr"];
let result = parse_cli(args);
assert!(result.is_err(), "convert requires -o/--output");
}
#[test]
fn test_missing_merge_files() {
let args = vec!["apr", "merge", "model1.apr", "-o", "out.apr"];
let result = parse_cli(args);
assert!(result.is_err(), "merge requires at least 2 files");
}
#[test]
fn test_missing_publish_repo_id() {
let args = vec!["apr", "publish", "/tmp/models"];
let result = parse_cli(args);
assert!(result.is_err(), "publish requires REPO_ID");
}
#[test]
fn test_missing_pull_model_ref() {
let args = vec!["apr", "pull"];
let result = parse_cli(args);
assert!(result.is_err(), "pull requires MODEL");
}
#[test]
fn test_missing_rm_model_ref() {
let args = vec!["apr", "rm"];
let result = parse_cli(args);
assert!(result.is_err(), "rm requires MODEL");
}
#[test]
fn test_missing_compare_hf_hf_arg() {
let args = vec!["apr", "compare-hf", "model.apr"];
let result = parse_cli(args);
assert!(result.is_err(), "compare-hf requires --hf");
}
#[test]
fn test_missing_canary_create_input() {
let args = vec![
"apr",
"canary",
"create",
"model.apr",
"--output",
"canary.json",
];
let result = parse_cli(args);
assert!(result.is_err(), "canary create requires --input");
}
#[test]
fn test_missing_canary_check_canary() {
let args = vec!["apr", "canary", "check", "model.apr"];
let result = parse_cli(args);
assert!(result.is_err(), "canary check requires --canary");
}
#[test]
fn test_execute_with_contract_gate_nonexistent() {
let cli = Cli {
command: Box::new(Commands::Inspect {
file: PathBuf::from("/tmp/nonexistent_contract_test.apr"),
vocab: false,
filters: false,
weights: false,
json: false,
}),
json: false,
verbose: false,
quiet: false,
offline: false,
skip_contract: false, };
let result = execute_command(&cli);
assert!(
result.is_err(),
"Should still fail from command execution, not contract"
);
}
#[test]
fn test_execute_list_with_contract_enabled() {
let cli = Cli {
command: Box::new(Commands::List),
json: false,
verbose: false,
quiet: false,
offline: false,
skip_contract: false, };
let result = execute_command(&cli);
assert!(result.is_ok(), "List should succeed with contract enabled");
}
#[test]
fn test_execute_rosetta_inspect_file_not_found() {
let cli = make_cli(Commands::Extended(ExtendedCommands::Tools(ToolCommands::Rosetta {
action: RosettaCommands::Inspect {
file: PathBuf::from("/tmp/nonexistent_rosetta_inspect.gguf"),
hexdump: false,
json: false,
},
})));
let result = execute_command(&cli);
assert!(
result.is_err(),
"Rosetta inspect should fail with non-existent file"
);
}
#[test]
fn test_execute_rosetta_convert_file_not_found() {
let cli = make_cli(Commands::Extended(ExtendedCommands::Tools(ToolCommands::Rosetta {
action: RosettaCommands::Convert {
source: PathBuf::from("/tmp/nonexistent_rosetta_convert.gguf"),
target: PathBuf::from("/tmp/out.safetensors"),
quantize: None,
verify: false,
json: false,
tokenizer: None,
},
})));
let result = execute_command(&cli);
assert!(
result.is_err(),
"Rosetta convert should fail with non-existent source"
);
}
#[test]
fn test_execute_rosetta_fingerprint_file_not_found() {
let cli = make_cli(Commands::Extended(ExtendedCommands::Tools(ToolCommands::Rosetta {
action: RosettaCommands::Fingerprint {
model: PathBuf::from("/tmp/nonexistent_rosetta_fingerprint.gguf"),
model_b: None,
output: None,
filter: None,
verbose: false,
json: false,
},
})));
let result = execute_command(&cli);
assert!(
result.is_err(),
"Rosetta fingerprint should fail with non-existent file"
);
}
#[test]
fn test_execute_bench_file_not_found() {
let cli = make_cli(Commands::Extended(ExtendedCommands::Bench {
file: PathBuf::from("/tmp/nonexistent_model_bench_test.gguf"),
warmup: 1,
iterations: 1,
max_tokens: 1,
prompt: None,
fast: false,
brick: None,
percentiles: vec![50.0, 95.0, 99.0],
}));
let result = execute_command(&cli);
assert!(result.is_err(), "Bench should fail with non-existent file");
}
#[test]
fn test_execute_eval_file_not_found() {
let cli = make_cli(Commands::Extended(ExtendedCommands::Eval {
file: PathBuf::from("/tmp/nonexistent_model_eval_test.gguf"),
dataset: "wikitext-2".to_string(),
text: None,
max_tokens: 32,
threshold: 20.0,
task: None,
data: None,
model_size: None,
num_classes: 5,
generate_card: false,
device: "cpu".to_string(),
samples: 1,
temperature: 0.0,
}));
let result = execute_command(&cli);
assert!(result.is_err(), "Eval should fail with non-existent file");
}
#[test]
fn test_execute_profile_file_not_found() {
let cli = make_cli(Commands::Extended(ExtendedCommands::Profile {
file: PathBuf::from("/tmp/nonexistent_model_profile_test.apr"),
granular: false,
format: "human".to_string(),
focus: None,
detect_naive: false,
threshold: 10.0,
compare_hf: None,
energy: false,
perf_grade: false,
callgraph: false,
fail_on_naive: false,
output: None,
ci: false,
assert_throughput: None,
assert_p99: None,
assert_p50: None,
warmup: 3,
measure: 10,
tokens: 32,
ollama: false,
no_gpu: false,
compare: None,
}));
let result = execute_command(&cli);
assert!(
result.is_err(),
"Profile should fail with non-existent file"
);
}
#[test]
fn test_execute_compare_hf_file_not_found() {
let cli = make_cli(Commands::Extended(ExtendedCommands::CompareHf {
file: PathBuf::from("/tmp/nonexistent_model_compare_hf_test.apr"),
hf: "openai/whisper-tiny".to_string(),
tensor: None,
threshold: 1e-5,
json: false,
}));
let result = execute_command(&cli);
assert!(
result.is_err(),
"CompareHf should fail with non-existent file"
);
}
#[test]
fn test_execute_canary_check_file_not_found() {
let cli = make_cli(Commands::Canary {
command: CanaryCommands::Check {
file: PathBuf::from("/tmp/nonexistent_canary_check.apr"),
canary: PathBuf::from("/tmp/nonexistent_canary.json"),
},
});
let result = execute_command(&cli);
assert!(
result.is_err(),
"Canary check should fail with non-existent file"
);
}
#[test]
fn test_execute_publish_dir_not_found() {
let cli = make_cli(Commands::Extended(ExtendedCommands::Tools(ToolCommands::Publish {
directory: PathBuf::from("/tmp/nonexistent_publish_dir_test"),
repo_id: "test/test".to_string(),
model_name: None,
license: "mit".to_string(),
pipeline_tag: "text-generation".to_string(),
library_name: None,
tags: None,
message: None,
dry_run: true, plan: false,
})));
let result = execute_command(&cli);
assert!(
result.is_err(),
"Publish should fail with non-existent directory"
);
}
#[test]
fn test_parse_run_defaults() {
let args = vec!["apr", "run", "model.gguf"];
let cli = parse_cli(args).expect("Failed to parse");
match *cli.command {
Commands::Run {
max_tokens,
stream,
format,
no_gpu,
gpu,
offline,
benchmark,
trace,
trace_payload,
trace_verbose,
trace_level,
profile,
chat,
verbose,
prompt,
input,
language,
task,
trace_steps,
trace_output,
..
} => {
assert_eq!(max_tokens, 32);
assert!(!stream);
assert_eq!(format, "text");
assert!(!no_gpu);
assert!(!gpu);
assert!(!offline);
assert!(!benchmark);
assert!(!trace);
assert!(!trace_payload);
assert!(!trace_verbose);
assert_eq!(trace_level, "basic");
assert!(!profile);
assert!(!chat);
assert!(!verbose);
assert!(prompt.is_none());
assert!(input.is_none());
assert!(language.is_none());
assert!(task.is_none());
assert!(trace_steps.is_none());
assert!(trace_output.is_none());
}
_ => panic!("Expected Run command"),
}
}