Skip to content
32 changes: 24 additions & 8 deletions src/openhuman/agent/git_attribution/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,29 @@ pub fn hook_env() -> HashMap<String, String> {
let Some(dir) = HOOK_DIR.get_or_init(|| build_hook_dir().ok()).as_ref() else {
return HashMap::new();
};
build_hook_env(dir, std::env::var("GIT_CONFIG_PARAMETERS").ok().as_deref())
Comment thread
senamakel marked this conversation as resolved.
Outdated
}

#[cfg(unix)]
fn build_hook_env(
dir: &std::path::Path,
inherited_parameters: Option<&str>,
) -> HashMap<String, String> {
let mut parameters = inherited_parameters.unwrap_or_default().trim().to_owned();
if !parameters.is_empty() {
parameters.push(' ');
}
let hook_path = dir.to_string_lossy().replace('\'', "'\\''");
parameters.push_str("'core.hooksPath'='");
parameters.push_str(&hook_path);
parameters.push('\'');

HashMap::from([
("OPENHUMAN_GIT_ATTRIBUTION".into(), TRAILER.into()),
("GIT_CONFIG_COUNT".into(), "1".into()),
("GIT_CONFIG_KEY_0".into(), "core.hooksPath".into()),
(
"GIT_CONFIG_VALUE_0".into(),
dir.to_string_lossy().into_owned(),
),
// Parameters outrank GIT_CONFIG_COUNT. Preserve settings inherited
// from the parent harness, then append our hook so it wins if that
// harness also selected a hook path.
("GIT_CONFIG_PARAMETERS".into(), parameters),
])
}

Expand All @@ -94,6 +109,7 @@ fn build_hook_dir() -> std::io::Result<PathBuf> {
}

#[cfg(all(unix, test))]
pub(super) fn test_hook_dir() -> PathBuf {
build_hook_dir().expect("create OpenHuman hook directory")
pub(super) fn test_hook_env(inherited_parameters: Option<&str>) -> HashMap<String, String> {
let dir = build_hook_dir().expect("create OpenHuman hook directory");
build_hook_env(&dir, inherited_parameters)
}
18 changes: 13 additions & 5 deletions src/openhuman/agent/git_attribution/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ fn hook_adds_openhuman_trailer_without_disabling_repository_hook() {
std::fs::write(repo.join("a"), "a").unwrap();
git(&["add", "a"]);

let hook_dir = super::hook::test_hook_dir();
let hook_env = super::hook::test_hook_env(Some(
"'test.openhuman-inherited'='kept' 'core.hooksPath'='/definitely-not-the-openhuman-hook'",
));
let output = Command::new("git")
.args(["commit", "-q", "-m", "subject"])
.current_dir(&repo)
.env("OPENHUMAN_GIT_ATTRIBUTION", super::hook::TRAILER)
.env("GIT_CONFIG_COUNT", "1")
.env("GIT_CONFIG_KEY_0", "core.hooksPath")
.env("GIT_CONFIG_VALUE_0", &hook_dir)
.envs(&hook_env)
.output()
.unwrap();
assert!(
Expand All @@ -55,4 +54,13 @@ fn hook_adds_openhuman_trailer_without_disabling_repository_hook() {
let message = String::from_utf8(output.stdout).unwrap();
assert!(message.contains("repo-hook-ran"), "{message:?}");
assert!(message.contains(super::hook::TRAILER), "{message:?}");

let inherited = Command::new("git")
.args(["config", "--get", "test.openhuman-inherited"])
.current_dir(&repo)
.envs(&hook_env)
.output()
.unwrap();
assert!(inherited.status.success());
assert_eq!(String::from_utf8(inherited.stdout).unwrap().trim(), "kept");
}
4 changes: 2 additions & 2 deletions src/openhuman/memory/api/provider/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ fn join(families: &[Capability]) -> String {
/// # Examples
///
/// ```
/// # use crate::openhuman::memory::api::null::NullMemoryProvider;
/// # use crate::openhuman::memory::api::provider::audit_provider;
/// # use openhuman_core::openhuman::memory::api::null::NullMemoryProvider;
/// # use openhuman_core::openhuman::memory::api::provider::audit_provider;
/// // The reference null driver is self-consistent.
/// assert!(audit_provider(&NullMemoryProvider::new()).is_ok());
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/openhuman/memory/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl MemoryTaint {
/// # Examples
///
/// ```
/// use crate::openhuman::memory::api::types::MemoryTaint;
/// use openhuman_core::openhuman::memory::api::types::MemoryTaint;
///
/// assert_eq!(MemoryTaint::Internal.as_db_str(), "internal");
/// assert_eq!(MemoryTaint::ExternalSync.as_db_str(), "external_sync");
Expand All @@ -103,7 +103,7 @@ impl MemoryTaint {
/// # Examples
///
/// ```
/// use crate::openhuman::memory::api::types::MemoryTaint;
/// use openhuman_core::openhuman::memory::api::types::MemoryTaint;
///
/// assert_eq!(MemoryTaint::from_db_str("internal"), MemoryTaint::Internal);
/// assert_eq!(MemoryTaint::from_db_str("external_sync"), MemoryTaint::ExternalSync);
Expand Down
2 changes: 1 addition & 1 deletion src/openhuman/memory/api/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub const CONTRACT_VERSION: (u16, u16) = (2, 0);
/// # Examples
///
/// ```
/// use crate::openhuman::memory::api::{is_compatible, CONTRACT_VERSION};
/// use openhuman_core::openhuman::memory::api::{is_compatible, CONTRACT_VERSION};
///
/// // The version this build speaks is always compatible with itself.
/// assert!(is_compatible(CONTRACT_VERSION));
Expand Down
2 changes: 1 addition & 1 deletion src/openhuman/web3/wallet/primitives/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub type Result<T> = std::result::Result<T, Error>;
///
/// # Examples
///
/// ```
/// ```ignore
/// # #[cfg(all(feature = "web3", feature = "web3", feature = "web3"))] {
/// use crate::openhuman::web3::wallet::primitives::abi;
///
Expand Down
4 changes: 2 additions & 2 deletions src/openhuman/web3/wallet/primitives/address/btc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ enum Kind {
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::btc;
///
/// // Native segwit, wrapped segwit, legacy, and taproot are all accepted.
Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn validate(address: &str) -> Result<String> {
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::btc;
///
/// // Native segwit: usable as a sender.
Expand Down
6 changes: 3 additions & 3 deletions src/openhuman/web3/wallet/primitives/address/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ADDRESS_HEX_LEN: usize = 40;
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::evm;
///
/// let addr = evm::validate(" 0x52908400098527886E0F7030069857D2E4169EE7 ")?;
Expand Down Expand Up @@ -109,7 +109,7 @@ fn strip_prefix(address: &str) -> &str {
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::evm;
///
/// // A correctly checksummed address.
Expand All @@ -132,7 +132,7 @@ pub fn is_checksum_valid(address: &str) -> Result<bool> {
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::evm;
///
/// let canonical = evm::to_checksummed("0x52908400098527886e0f7030069857d2e4169ee7")?;
Expand Down
2 changes: 1 addition & 1 deletion src/openhuman/web3/wallet/primitives/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub mod tron;
///
/// # Examples
///
/// ```
/// ```ignore
/// # #[cfg(feature = "web3")] {
/// use crate::openhuman::web3::wallet::primitives::{address, chain::Chain};
///
Expand Down
6 changes: 3 additions & 3 deletions src/openhuman/web3/wallet/primitives/address/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const ADDRESS_BYTES: usize = 32;
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::solana;
///
/// // The system program id — 32 zero bytes.
Expand All @@ -51,7 +51,7 @@ pub fn validate(address: &str) -> Result<String> {
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::solana;
///
/// let bytes = solana::decode("11111111111111111111111111111111")?;
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn decode(address: &str) -> Result<[u8; ADDRESS_BYTES]> {
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::solana;
///
/// assert_eq!(solana::encode(&[0u8; 32]), "11111111111111111111111111111111");
Expand Down
6 changes: 3 additions & 3 deletions src/openhuman/web3/wallet/primitives/address/tron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub const ADDRESS_BYTES: usize = 21;
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::tron;
///
/// assert!(tron::validate("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t").is_ok());
Expand Down Expand Up @@ -94,7 +94,7 @@ pub fn decode(address: &str) -> Result<[u8; ADDRESS_BYTES]> {
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::tron;
///
/// let hex = tron::to_hex("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")?;
Expand All @@ -121,7 +121,7 @@ pub fn to_hex(address: &str) -> Result<String> {
///
/// # Examples
///
/// ```
/// ```ignore
/// use crate::openhuman::web3::wallet::primitives::address::tron;
///
/// let bytes = tron::decode("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")?;
Expand Down
2 changes: 1 addition & 1 deletion src/openhuman/web3/wallet/primitives/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl std::fmt::Debug for DerivedKey {
///
/// # Examples
///
/// ```
/// ```ignore
/// # #[cfg(feature = "web3")] {
/// use crate::openhuman::web3::wallet::primitives::{key, Chain};
///
Expand Down
2 changes: 1 addition & 1 deletion src/openhuman/web3/wallet/primitives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//!
//! # Example
//!
//! ```
//! ```ignore
//! # #[cfg(all(feature = "web3", feature = "web3"))] {
//! use crate::openhuman::web3::wallet::primitives::{address, chain::Chain};
//!
Expand Down
2 changes: 1 addition & 1 deletion src/openhuman/web3/wallet/primitives/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub type TransportResult<T> = std::result::Result<T, TransportError>;
///
/// # Implementing
///
/// ```
/// ```ignore
/// use async_trait::async_trait;
/// use serde_json::Value;
/// use crate::openhuman::web3::wallet::primitives::rpc::{NetworkId, Transport, TransportError, TransportResult};
Expand Down
Loading