The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
chore: files changed src/openhuman/agent/git_attribution/git_attribution_tests.rs
Steven Enamakelc0b412198af6
diff --git a/src/openhuman/agent/git_attribution/git_attribution_tests.rs b/src/openhuman/agent/git_attribution/git_attribution_tests.rsindex b3154290ad..9be2480f4d 100644--- a/src/openhuman/agent/git_attribution/git_attribution_tests.rs+++ b/src/openhuman/agent/git_attribution/git_attribution_tests.rs@@ -96,3 +96,106 @@ fn hook_env_does_not_drop_inherited_parameters_containing_non_utf8() {);assert_eq!(output.stdout, b"before-\xff-after\n");}++/// A repository-set command-valued key must not reach a shell-spawned `git`.+///+/// `core.pager` is the readable stand-in for the family: a repository can set+/// it to any program, git runs it, and the repository config is agent-writable.+/// Before `git_operations` moved behind a tool pack, `shell git` was the only+/// path that inherited none of that hardening — this pins that it now does.+///+/// The assertion is on behaviour, not on the env var: a test that only checked+/// `GIT_CONFIG_PARAMETERS` contained the right string would pass just as+/// happily if git ignored it.+#[cfg(unix)]+#[test]+fn a_repository_pager_does_not_run_under_the_shell_git_environment() {+ use std::os::unix::fs::PermissionsExt;+ use std::process::Command;++ let temp = tempfile::tempdir().unwrap();+ let repo = temp.path().join("repo");+ std::fs::create_dir(&repo).unwrap();+ let marker = temp.path().join("pager-ran");++ let git = |args: &[&str]| {+ let output = Command::new("git")+ .args(args)+ .current_dir(&repo)+ .output()+ .unwrap();+ assert!(+ output.status.success(),+ "git {args:?}: {}",+ String::from_utf8_lossy(&output.stderr)+ );+ };+ git(&["init", "-q"]);+ git(&["config", "user.name", "Test"]);+ git(&["config", "user.email", "[email protected]"]);+ std::fs::write(repo.join("a"), "a").unwrap();+ git(&["add", "a"]);+ git(&["commit", "-q", "-m", "subject"]);++ // A "pager" that records that it was executed at all.+ let pager = temp.path().join("pager.sh");+ std::fs::write(+ &pager,+ format!("#!/bin/sh\ntouch '{}'\ncat\n", marker.display()),+ )+ .unwrap();+ std::fs::set_permissions(&pager, std::fs::Permissions::from_mode(0o755)).unwrap();+ git(&["config", "core.pager", pager.to_str().unwrap()]);++ // Baseline: without the hardening the repository's pager really does run,+ // so the assertion below is discriminating rather than vacuously true.+ let bare = Command::new("git")+ .args(["log", "-1"])+ .current_dir(&repo)+ .env("GIT_PAGER", pager.to_str().unwrap())+ .output()+ .unwrap();+ assert!(bare.status.success());+ assert!(+ marker.exists(),+ "the fixture pager never ran, so this test proves nothing"+ );+ std::fs::remove_file(&marker).unwrap();++ // Now with the environment the shell tool hands every command.+ let hook_env = super::hook::test_hook_env(None);+ let mut cmd = Command::new("git");+ cmd.args(["log", "-1"]).current_dir(&repo);+ for (key, value) in &hook_env {+ cmd.env(key, value);+ }+ let output = cmd.output().unwrap();+ assert!(+ output.status.success(),+ "git log failed under the shell git environment: {}",+ String::from_utf8_lossy(&output.stderr)+ );+ assert!(+ !marker.exists(),+ "the repository's core.pager ran under the shell git environment"+ );+}++/// The shell environment must not silently sign commits with the host's key.+#[cfg(unix)]+#[test]+fn the_shell_git_environment_forces_commit_signing_off() {+ let env = super::hook::test_hook_env(None);+ let parameters = env+ .get(std::ffi::OsStr::new("GIT_CONFIG_PARAMETERS"))+ .expect("the shell git environment sets GIT_CONFIG_PARAMETERS")+ .to_string_lossy()+ .into_owned();+ for expected in crate::openhuman::tools::implementations::filesystem::SHELL_NEUTRALISED_CONFIG {+ let (key, value) = expected.split_once('=').unwrap();+ assert!(+ parameters.contains(&format!("'{key}'='{value}'")),+ "`{expected}` is missing from GIT_CONFIG_PARAMETERS: {parameters}"+ );+ }+}