LLM支持优化
This commit is contained in:
@@ -1,38 +1,11 @@
|
||||
use assert_cmd::Command;
|
||||
use assert_cmd::cargo::cargo_bin_cmd;
|
||||
use predicates::prelude::*;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use tempfile::TempDir;
|
||||
|
||||
fn create_git_repo(dir: &PathBuf) -> std::process::Output {
|
||||
std::process::Command::new("git")
|
||||
.args(&["init"])
|
||||
.current_dir(dir)
|
||||
.output()
|
||||
.expect("Failed to init git repo")
|
||||
}
|
||||
|
||||
fn configure_git_user(dir: &PathBuf) {
|
||||
std::process::Command::new("git")
|
||||
.args(&["config", "user.name", "Test User"])
|
||||
.current_dir(dir)
|
||||
.output()
|
||||
.expect("Failed to configure git user name");
|
||||
|
||||
std::process::Command::new("git")
|
||||
.args(&["config", "user.email", "test@example.com"])
|
||||
.current_dir(dir)
|
||||
.output()
|
||||
.expect("Failed to configure git user email");
|
||||
}
|
||||
|
||||
fn setup_git_repo(dir: &PathBuf) {
|
||||
create_git_repo(dir);
|
||||
configure_git_user(dir);
|
||||
}
|
||||
|
||||
fn init_quicommit(config_path: &PathBuf) {
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&["init", "--yes", "--config", config_path.to_str().unwrap()]);
|
||||
cmd.assert().success();
|
||||
}
|
||||
@@ -46,7 +19,7 @@ mod config_export {
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
init_quicommit(&config_path);
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&["config", "export", "--config", config_path.to_str().unwrap()]);
|
||||
|
||||
cmd.assert()
|
||||
@@ -62,7 +35,7 @@ mod config_export {
|
||||
let export_path = temp_dir.path().join("exported.toml");
|
||||
init_quicommit(&config_path);
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "export",
|
||||
"--config", config_path.to_str().unwrap(),
|
||||
@@ -88,7 +61,7 @@ mod config_export {
|
||||
let export_path = temp_dir.path().join("encrypted.toml");
|
||||
init_quicommit(&config_path);
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "export",
|
||||
"--config", config_path.to_str().unwrap(),
|
||||
@@ -164,7 +137,7 @@ keep_changelog_types_english = true
|
||||
"#;
|
||||
fs::write(&import_path, plain_config).unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "import",
|
||||
"--config", config_path.to_str().unwrap(),
|
||||
@@ -175,7 +148,7 @@ keep_changelog_types_english = true
|
||||
.success()
|
||||
.stdout(predicate::str::contains("Configuration imported"));
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&["config", "get", "llm.provider", "--config", config_path.to_str().unwrap()]);
|
||||
cmd.assert()
|
||||
.success()
|
||||
@@ -191,14 +164,14 @@ keep_changelog_types_english = true
|
||||
|
||||
init_quicommit(&config_path1);
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "set", "llm.provider", "anthropic",
|
||||
"--config", config_path1.to_str().unwrap()
|
||||
]);
|
||||
cmd.assert().success();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "export",
|
||||
"--config", config_path1.to_str().unwrap(),
|
||||
@@ -207,7 +180,7 @@ keep_changelog_types_english = true
|
||||
]);
|
||||
cmd.assert().success();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "import",
|
||||
"--config", config_path2.to_str().unwrap(),
|
||||
@@ -218,7 +191,7 @@ keep_changelog_types_english = true
|
||||
.success()
|
||||
.stdout(predicate::str::contains("Configuration imported"));
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&["config", "get", "llm.provider", "--config", config_path2.to_str().unwrap()]);
|
||||
cmd.assert()
|
||||
.success()
|
||||
@@ -233,7 +206,7 @@ keep_changelog_types_english = true
|
||||
|
||||
init_quicommit(&config_path);
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "export",
|
||||
"--config", config_path.to_str().unwrap(),
|
||||
@@ -242,7 +215,7 @@ keep_changelog_types_english = true
|
||||
]);
|
||||
cmd.assert().success();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "import",
|
||||
"--config", config_path.to_str().unwrap(),
|
||||
@@ -267,14 +240,14 @@ mod config_export_import_roundtrip {
|
||||
|
||||
init_quicommit(&config_path1);
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "set", "llm.model", "gpt-4-turbo",
|
||||
"--config", config_path1.to_str().unwrap()
|
||||
]);
|
||||
cmd.assert().success();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "export",
|
||||
"--config", config_path1.to_str().unwrap(),
|
||||
@@ -283,7 +256,7 @@ mod config_export_import_roundtrip {
|
||||
]);
|
||||
cmd.assert().success();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "import",
|
||||
"--config", config_path2.to_str().unwrap(),
|
||||
@@ -291,7 +264,7 @@ mod config_export_import_roundtrip {
|
||||
]);
|
||||
cmd.assert().success();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&["config", "get", "llm.model", "--config", config_path2.to_str().unwrap()]);
|
||||
cmd.assert()
|
||||
.success()
|
||||
@@ -308,21 +281,21 @@ mod config_export_import_roundtrip {
|
||||
|
||||
init_quicommit(&config_path1);
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "set", "llm.provider", "deepseek",
|
||||
"--config", config_path1.to_str().unwrap()
|
||||
]);
|
||||
cmd.assert().success();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "set", "llm.model", "deepseek-chat",
|
||||
"--config", config_path1.to_str().unwrap()
|
||||
]);
|
||||
cmd.assert().success();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "export",
|
||||
"--config", config_path1.to_str().unwrap(),
|
||||
@@ -335,7 +308,7 @@ mod config_export_import_roundtrip {
|
||||
assert!(exported_content.starts_with("ENCRYPTED:"));
|
||||
assert!(!exported_content.contains("deepseek"));
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&[
|
||||
"config", "import",
|
||||
"--config", config_path2.to_str().unwrap(),
|
||||
@@ -344,13 +317,13 @@ mod config_export_import_roundtrip {
|
||||
]);
|
||||
cmd.assert().success();
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&["config", "get", "llm.provider", "--config", config_path2.to_str().unwrap()]);
|
||||
cmd.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("deepseek"));
|
||||
|
||||
let mut cmd = Command::cargo_bin("quicommit").unwrap();
|
||||
let mut cmd = cargo_bin_cmd!("quicommit");
|
||||
cmd.args(&["config", "get", "llm.model", "--config", config_path2.to_str().unwrap()]);
|
||||
cmd.assert()
|
||||
.success()
|
||||
|
||||
Reference in New Issue
Block a user