style: 格式化代码并优化导入顺序

This commit is contained in:
2026-05-27 15:15:15 +08:00
parent b8182e7538
commit 90074e6e32
34 changed files with 2931 additions and 1648 deletions

View File

@@ -20,7 +20,12 @@ mod config_export {
init_quicommit(&config_path);
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&["config", "export", "--config", config_path.to_str().unwrap()]);
cmd.args(&[
"config",
"export",
"--config",
config_path.to_str().unwrap(),
]);
cmd.assert()
.success()
@@ -37,10 +42,14 @@ mod config_export {
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "export",
"--config", config_path.to_str().unwrap(),
"--output", export_path.to_str().unwrap(),
"--password", ""
"config",
"export",
"--config",
config_path.to_str().unwrap(),
"--output",
export_path.to_str().unwrap(),
"--password",
"",
]);
cmd.assert()
@@ -48,10 +57,13 @@ mod config_export {
.stdout(predicate::str::contains("Configuration exported"));
assert!(export_path.exists(), "Export file should be created");
let content = fs::read_to_string(&export_path).unwrap();
assert!(content.contains("version"), "Export should contain version");
assert!(content.contains("[llm]"), "Export should contain LLM config");
assert!(
content.contains("[llm]"),
"Export should contain LLM config"
);
}
#[test]
@@ -63,10 +75,14 @@ mod config_export {
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "export",
"--config", config_path.to_str().unwrap(),
"--output", export_path.to_str().unwrap(),
"--password", "test_password_123"
"config",
"export",
"--config",
config_path.to_str().unwrap(),
"--output",
export_path.to_str().unwrap(),
"--password",
"test_password_123",
]);
cmd.assert()
@@ -74,10 +90,16 @@ mod config_export {
.stdout(predicate::str::contains("encrypted and exported"));
assert!(export_path.exists(), "Export file should be created");
let content = fs::read_to_string(&export_path).unwrap();
assert!(content.starts_with("ENCRYPTED:"), "Encrypted file should start with ENCRYPTED:");
assert!(!content.contains("[llm]"), "Encrypted content should not be readable");
assert!(
content.starts_with("ENCRYPTED:"),
"Encrypted file should start with ENCRYPTED:"
);
assert!(
!content.contains("[llm]"),
"Encrypted content should not be readable"
);
}
}
@@ -89,7 +111,7 @@ mod config_import {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("config.toml");
let import_path = temp_dir.path().join("import.toml");
let plain_config = r#"
version = "1"
@@ -139,9 +161,12 @@ keep_changelog_types_english = true
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "import",
"--config", config_path.to_str().unwrap(),
"--file", import_path.to_str().unwrap()
"config",
"import",
"--config",
config_path.to_str().unwrap(),
"--file",
import_path.to_str().unwrap(),
]);
cmd.assert()
@@ -149,7 +174,13 @@ keep_changelog_types_english = true
.stdout(predicate::str::contains("Configuration imported"));
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&["config", "get", "llm.provider", "--config", config_path.to_str().unwrap()]);
cmd.args(&[
"config",
"get",
"llm.provider",
"--config",
config_path.to_str().unwrap(),
]);
cmd.assert()
.success()
.stdout(predicate::str::contains("openai"));
@@ -161,38 +192,56 @@ keep_changelog_types_english = true
let config_path1 = temp_dir.path().join("config1.toml");
let config_path2 = temp_dir.path().join("config2.toml");
let export_path = temp_dir.path().join("encrypted.toml");
init_quicommit(&config_path1);
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "set", "llm.provider", "anthropic",
"--config", config_path1.to_str().unwrap()
"config",
"set",
"llm.provider",
"anthropic",
"--config",
config_path1.to_str().unwrap(),
]);
cmd.assert().success();
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "export",
"--config", config_path1.to_str().unwrap(),
"--output", export_path.to_str().unwrap(),
"--password", "secure_password"
"config",
"export",
"--config",
config_path1.to_str().unwrap(),
"--output",
export_path.to_str().unwrap(),
"--password",
"secure_password",
]);
cmd.assert().success();
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "import",
"--config", config_path2.to_str().unwrap(),
"--file", export_path.to_str().unwrap(),
"--password", "secure_password"
"config",
"import",
"--config",
config_path2.to_str().unwrap(),
"--file",
export_path.to_str().unwrap(),
"--password",
"secure_password",
]);
cmd.assert()
.success()
.stdout(predicate::str::contains("Configuration imported"));
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&["config", "get", "llm.provider", "--config", config_path2.to_str().unwrap()]);
cmd.args(&[
"config",
"get",
"llm.provider",
"--config",
config_path2.to_str().unwrap(),
]);
cmd.assert()
.success()
.stdout(predicate::str::contains("anthropic"));
@@ -203,24 +252,32 @@ keep_changelog_types_english = true
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("config.toml");
let export_path = temp_dir.path().join("encrypted.toml");
init_quicommit(&config_path);
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "export",
"--config", config_path.to_str().unwrap(),
"--output", export_path.to_str().unwrap(),
"--password", "correct_password"
"config",
"export",
"--config",
config_path.to_str().unwrap(),
"--output",
export_path.to_str().unwrap(),
"--password",
"correct_password",
]);
cmd.assert().success();
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "import",
"--config", config_path.to_str().unwrap(),
"--file", export_path.to_str().unwrap(),
"--password", "wrong_password"
"config",
"import",
"--config",
config_path.to_str().unwrap(),
"--file",
export_path.to_str().unwrap(),
"--password",
"wrong_password",
]);
cmd.assert()
.failure()
@@ -237,35 +294,52 @@ mod config_export_import_roundtrip {
let config_path1 = temp_dir.path().join("config1.toml");
let config_path2 = temp_dir.path().join("config2.toml");
let export_path = temp_dir.path().join("export.toml");
init_quicommit(&config_path1);
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "set", "llm.model", "gpt-4-turbo",
"--config", config_path1.to_str().unwrap()
"config",
"set",
"llm.model",
"gpt-4-turbo",
"--config",
config_path1.to_str().unwrap(),
]);
cmd.assert().success();
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "export",
"--config", config_path1.to_str().unwrap(),
"--output", export_path.to_str().unwrap(),
"--password", ""
"config",
"export",
"--config",
config_path1.to_str().unwrap(),
"--output",
export_path.to_str().unwrap(),
"--password",
"",
]);
cmd.assert().success();
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "import",
"--config", config_path2.to_str().unwrap(),
"--file", export_path.to_str().unwrap()
"config",
"import",
"--config",
config_path2.to_str().unwrap(),
"--file",
export_path.to_str().unwrap(),
]);
cmd.assert().success();
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&["config", "get", "llm.model", "--config", config_path2.to_str().unwrap()]);
cmd.args(&[
"config",
"get",
"llm.model",
"--config",
config_path2.to_str().unwrap(),
]);
cmd.assert()
.success()
.stdout(predicate::str::contains("gpt-4-turbo"));
@@ -278,29 +352,41 @@ mod config_export_import_roundtrip {
let config_path2 = temp_dir.path().join("config2.toml");
let export_path = temp_dir.path().join("encrypted.toml");
let password = "my_secure_password_123";
init_quicommit(&config_path1);
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "set", "llm.provider", "deepseek",
"--config", config_path1.to_str().unwrap()
"config",
"set",
"llm.provider",
"deepseek",
"--config",
config_path1.to_str().unwrap(),
]);
cmd.assert().success();
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "set", "llm.model", "deepseek-chat",
"--config", config_path1.to_str().unwrap()
"config",
"set",
"llm.model",
"deepseek-chat",
"--config",
config_path1.to_str().unwrap(),
]);
cmd.assert().success();
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "export",
"--config", config_path1.to_str().unwrap(),
"--output", export_path.to_str().unwrap(),
"--password", password
"config",
"export",
"--config",
config_path1.to_str().unwrap(),
"--output",
export_path.to_str().unwrap(),
"--password",
password,
]);
cmd.assert().success();
@@ -310,21 +396,37 @@ mod config_export_import_roundtrip {
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&[
"config", "import",
"--config", config_path2.to_str().unwrap(),
"--file", export_path.to_str().unwrap(),
"--password", password
"config",
"import",
"--config",
config_path2.to_str().unwrap(),
"--file",
export_path.to_str().unwrap(),
"--password",
password,
]);
cmd.assert().success();
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&["config", "get", "llm.provider", "--config", config_path2.to_str().unwrap()]);
cmd.args(&[
"config",
"get",
"llm.provider",
"--config",
config_path2.to_str().unwrap(),
]);
cmd.assert()
.success()
.stdout(predicate::str::contains("deepseek"));
let mut cmd = cargo_bin_cmd!("quicommit");
cmd.args(&["config", "get", "llm.model", "--config", config_path2.to_str().unwrap()]);
cmd.args(&[
"config",
"get",
"llm.model",
"--config",
config_path2.to_str().unwrap(),
]);
cmd.assert()
.success()
.stdout(predicate::str::contains("deepseek-chat"));