- Specify production-ready implementation details for sal-git package. - Add a detailed code review and quality assurance process section. - Include comprehensive success metrics and validation checklists for production readiness. - Improve security considerations and risk mitigation strategies. - Add stricter code review criteria based on sal-git's conversion. - Update README with security configurations and environment variables.
105 lines
3.0 KiB
Rust
105 lines
3.0 KiB
Rust
use sal_git::rhai::*;
|
|
use rhai::Engine;
|
|
|
|
#[test]
|
|
fn test_git_clone_with_various_url_formats() {
|
|
let mut engine = Engine::new();
|
|
register_git_module(&mut engine).unwrap();
|
|
|
|
let test_cases = vec![
|
|
("https://github.com/octocat/Hello-World.git", "HTTPS with .git"),
|
|
("https://github.com/octocat/Hello-World", "HTTPS without .git"),
|
|
// SSH would require key setup: ("git@github.com:octocat/Hello-World.git", "SSH format"),
|
|
];
|
|
|
|
for (url, description) in test_cases {
|
|
let script = format!(r#"
|
|
let result = "";
|
|
try {{
|
|
let repo = git_clone("{}");
|
|
let path = repo.path();
|
|
if path.len() > 0 {{
|
|
result = "success";
|
|
}} else {{
|
|
result = "no_path";
|
|
}}
|
|
}} catch(e) {{
|
|
if e.contains("Git error") {{
|
|
result = "git_error";
|
|
}} else {{
|
|
result = "unexpected_error";
|
|
}}
|
|
}}
|
|
result
|
|
"#, url);
|
|
|
|
let result = engine.eval::<String>(&script);
|
|
assert!(result.is_ok(), "Failed to execute script for {}: {:?}", description, result);
|
|
|
|
let outcome = result.unwrap();
|
|
// Accept success or git_error (network issues)
|
|
assert!(
|
|
outcome == "success" || outcome == "git_error",
|
|
"Unexpected outcome for {}: {}",
|
|
description,
|
|
outcome
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_tree_operations_comprehensive() {
|
|
let mut engine = Engine::new();
|
|
register_git_module(&mut engine).unwrap();
|
|
|
|
let script = r#"
|
|
let results = [];
|
|
|
|
try {
|
|
// Test GitTree creation
|
|
let git_tree = git_tree_new("/tmp/rhai_comprehensive_test");
|
|
results.push("git_tree_created");
|
|
|
|
// Test list on empty directory
|
|
let repos = git_tree.list();
|
|
results.push("list_executed");
|
|
|
|
// Test find with pattern
|
|
let found = git_tree.find("nonexistent");
|
|
results.push("find_executed");
|
|
|
|
} catch(e) {
|
|
results.push("error_occurred");
|
|
}
|
|
|
|
results.len()
|
|
"#;
|
|
|
|
let result = engine.eval::<i64>(&script);
|
|
assert!(result.is_ok());
|
|
assert!(result.unwrap() >= 3, "Should execute at least 3 operations");
|
|
}
|
|
|
|
#[test]
|
|
fn test_error_message_quality() {
|
|
let mut engine = Engine::new();
|
|
register_git_module(&mut engine).unwrap();
|
|
|
|
let script = r#"
|
|
let error_msg = "";
|
|
try {
|
|
git_clone("invalid-url-format");
|
|
} catch(e) {
|
|
error_msg = e;
|
|
}
|
|
error_msg
|
|
"#;
|
|
|
|
let result = engine.eval::<String>(&script);
|
|
assert!(result.is_ok());
|
|
|
|
let error_msg = result.unwrap();
|
|
assert!(error_msg.contains("Git error"), "Error should contain 'Git error'");
|
|
assert!(error_msg.len() > 10, "Error message should be descriptive");
|
|
}
|