Report missing git prerequisite for app library
This commit is contained in:
@@ -1988,7 +1988,10 @@ fn git_stdout(cwd: &Path, args: &[&str]) -> io::Result<String> {
|
||||
}
|
||||
|
||||
fn git_stdout_with_dir(git_dir: &Path, args: &[&str]) -> io::Result<String> {
|
||||
let output = Command::new("git").args(args).output()?;
|
||||
let output = Command::new("git")
|
||||
.args(args)
|
||||
.output()
|
||||
.map_err(|error| map_git_spawn_error(args, error))?;
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
||||
return Err(io::Error::new(
|
||||
@@ -2008,7 +2011,27 @@ fn git_command(cwd: &Path, args: &[&str]) -> io::Result<std::process::Output> {
|
||||
if cwd != Path::new(".") {
|
||||
command.current_dir(cwd);
|
||||
}
|
||||
command.args(args).output()
|
||||
command
|
||||
.args(args)
|
||||
.output()
|
||||
.map_err(|error| map_git_spawn_error(args, error))
|
||||
}
|
||||
|
||||
fn map_git_spawn_error(args: &[&str], error: io::Error) -> io::Error {
|
||||
if error.kind() == io::ErrorKind::NotFound {
|
||||
io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
format!(
|
||||
"git executable not found on PATH; app library requires git to manage app repos (attempted git {:?})",
|
||||
args
|
||||
),
|
||||
)
|
||||
} else {
|
||||
io::Error::new(
|
||||
error.kind(),
|
||||
format!("failed to spawn git {:?}: {error}", args),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn media_type_for_path(path: &Path) -> Option<String> {
|
||||
@@ -2313,4 +2336,64 @@ mod tests {
|
||||
std::env::remove_var("CLAW_WORKER_DEFAULT_CWD");
|
||||
let _ = std::fs::remove_dir_all(&state_root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn package_feed_item_reports_missing_git_binary() {
|
||||
let _lock = test_env_lock();
|
||||
let state_root =
|
||||
std::env::temp_dir().join(format!("artifact-lib-missing-git-{}", super::now_secs()));
|
||||
let workspace = state_root.join("workspace");
|
||||
let source_root = state_root.join("source");
|
||||
let _ = std::fs::remove_dir_all(&state_root);
|
||||
std::fs::create_dir_all(&workspace).expect("workspace should exist");
|
||||
std::fs::create_dir_all(&source_root).expect("source root should exist");
|
||||
std::env::set_var("CLAW_WORKER_STATE_ROOT", &state_root);
|
||||
std::env::set_var("CLAW_WORKER_DEFAULT_CWD", &workspace);
|
||||
|
||||
let source = source_root.join("widget.jsx");
|
||||
std::fs::write(&source, "export default function App(){ return <div>Hello</div>; }")
|
||||
.expect("jsx source should write");
|
||||
|
||||
let store = ArtifactLibraryStore::new();
|
||||
let records = store
|
||||
.record_turn(
|
||||
"turn-missing-git",
|
||||
vec![FeedFileInput {
|
||||
title: "widget.jsx".to_string(),
|
||||
file_name: "widget.jsx".to_string(),
|
||||
source_kind: FeedItemSourceKind::Generated,
|
||||
source_turn_id: Some("turn-missing-git".to_string()),
|
||||
source_file_id: Some("generated-1".to_string()),
|
||||
source_files: vec!["widget.jsx".to_string()],
|
||||
change_kind: Some(FeedItemChangeKind::Created),
|
||||
media_type: Some("text/plain".to_string()),
|
||||
source_path: Some(source),
|
||||
preview_text: None,
|
||||
deleted: false,
|
||||
}],
|
||||
)
|
||||
.expect("turn should record");
|
||||
|
||||
let old_path = std::env::var_os("PATH");
|
||||
std::env::set_var("PATH", source_root.join("empty-bin"));
|
||||
let error = store
|
||||
.package_feed_item(AppPackageRequest {
|
||||
feed_item_id: records[0].feed_item_id.clone(),
|
||||
requested_app_id: None,
|
||||
title: None,
|
||||
description: None,
|
||||
})
|
||||
.expect_err("packaging should fail without git");
|
||||
assert!(error
|
||||
.to_string()
|
||||
.contains("git executable not found on PATH"));
|
||||
|
||||
match old_path {
|
||||
Some(value) => std::env::set_var("PATH", value),
|
||||
None => std::env::remove_var("PATH"),
|
||||
}
|
||||
std::env::remove_var("CLAW_WORKER_STATE_ROOT");
|
||||
std::env::remove_var("CLAW_WORKER_DEFAULT_CWD");
|
||||
let _ = std::fs::remove_dir_all(&state_root);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6486,6 +6486,82 @@ mod tests {
|
||||
result
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_create_from_feed_reports_missing_git_binary() {
|
||||
let _guard = env_lock()
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let state_root = temp_path("app-missing-git-state");
|
||||
let workspace_root = temp_path("app-missing-git-workspace");
|
||||
let source_root = temp_path("app-missing-git-source");
|
||||
fs::create_dir_all(&state_root).expect("create state root");
|
||||
fs::create_dir_all(&workspace_root).expect("create workspace root");
|
||||
fs::create_dir_all(&source_root).expect("create source root");
|
||||
let source_path = source_root.join("dashboard.html");
|
||||
fs::write(&source_path, "<html><body>hello</body></html>").expect("write source feed file");
|
||||
|
||||
let old_state_root = std::env::var_os("CLAW_WORKER_STATE_ROOT");
|
||||
let old_default_cwd = std::env::var_os("CLAW_WORKER_DEFAULT_CWD");
|
||||
let old_path = std::env::var_os("PATH");
|
||||
std::env::set_var("CLAW_WORKER_STATE_ROOT", &state_root);
|
||||
std::env::set_var("CLAW_WORKER_DEFAULT_CWD", &workspace_root);
|
||||
|
||||
let result = (|| {
|
||||
let store = ArtifactLibraryStore::new();
|
||||
let items = store
|
||||
.record_turn(
|
||||
"turn-app-tools-missing-git",
|
||||
vec![FeedFileInput {
|
||||
title: "Dashboard".to_string(),
|
||||
file_name: "dashboard.html".to_string(),
|
||||
source_kind: FeedItemSourceKind::Generated,
|
||||
source_turn_id: Some("turn-app-tools-missing-git".to_string()),
|
||||
source_file_id: Some("file-1".to_string()),
|
||||
source_files: vec!["dashboard.html".to_string()],
|
||||
change_kind: None,
|
||||
media_type: Some("text/html".to_string()),
|
||||
source_path: Some(source_path.clone()),
|
||||
preview_text: Some("A durable dashboard".to_string()),
|
||||
deleted: false,
|
||||
}],
|
||||
)
|
||||
.expect("record turn");
|
||||
let feed_item_id = items
|
||||
.first()
|
||||
.expect("feed item")
|
||||
.feed_item_id
|
||||
.clone();
|
||||
|
||||
std::env::set_var("PATH", source_root.join("empty-bin"));
|
||||
let error = execute_tool(
|
||||
"AppCreateFromFeed",
|
||||
&json!({
|
||||
"feed_item_id": feed_item_id,
|
||||
}),
|
||||
)
|
||||
.expect_err("app creation should fail without git");
|
||||
assert!(error.contains("git executable not found on PATH"));
|
||||
assert!(error.contains("\"feed_item_id\":"));
|
||||
})();
|
||||
|
||||
match old_state_root {
|
||||
Some(value) => std::env::set_var("CLAW_WORKER_STATE_ROOT", value),
|
||||
None => std::env::remove_var("CLAW_WORKER_STATE_ROOT"),
|
||||
}
|
||||
match old_default_cwd {
|
||||
Some(value) => std::env::set_var("CLAW_WORKER_DEFAULT_CWD", value),
|
||||
None => std::env::remove_var("CLAW_WORKER_DEFAULT_CWD"),
|
||||
}
|
||||
match old_path {
|
||||
Some(value) => std::env::set_var("PATH", value),
|
||||
None => std::env::remove_var("PATH"),
|
||||
}
|
||||
let _ = fs::remove_dir_all(&state_root);
|
||||
let _ = fs::remove_dir_all(&workspace_root);
|
||||
let _ = fs::remove_dir_all(&source_root);
|
||||
result
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_unknown_tool_names() {
|
||||
let error = execute_tool("nope", &json!({})).expect_err("tool should be rejected");
|
||||
|
||||
Reference in New Issue
Block a user