mirror of
https://github.com/openai/codex.git
synced 2026-10-23 18:08:45 +00:00
Fix hook trust CI
This commit is contained in:
@@ -423,17 +423,8 @@ fn append_matcher_groups(
|
||||
let trusted_hash = (!source.source.is_managed())
|
||||
.then(|| state.and_then(|state| state.trusted_hash.clone()))
|
||||
.flatten();
|
||||
let trust_status = if source.source.is_managed() {
|
||||
HookTrustStatus::Managed
|
||||
} else {
|
||||
match trusted_hash.as_deref() {
|
||||
Some(trusted_hash) if trusted_hash == current_hash => {
|
||||
HookTrustStatus::Trusted
|
||||
}
|
||||
Some(_) => HookTrustStatus::Modified,
|
||||
None => HookTrustStatus::Untrusted,
|
||||
}
|
||||
};
|
||||
let trust_status =
|
||||
hook_trust_status(source.source.is_managed(), ¤t_hash, &trusted_hash);
|
||||
hook_entries.push(HookListEntry {
|
||||
key,
|
||||
event_name,
|
||||
@@ -485,6 +476,8 @@ fn append_matcher_groups(
|
||||
}
|
||||
}
|
||||
|
||||
/// Hash normalized handler fields instead of source text so equivalent hooks
|
||||
/// from config TOML and hooks.json converge on the same trust identity.
|
||||
fn command_hook_hash(
|
||||
event_name: codex_protocol::protocol::HookEventName,
|
||||
matcher: Option<&str>,
|
||||
@@ -492,8 +485,6 @@ fn command_hook_hash(
|
||||
timeout_sec: u64,
|
||||
status_message: Option<&str>,
|
||||
) -> String {
|
||||
// Hash normalized handler fields instead of source text so equivalent hooks from
|
||||
// config TOML and hooks.json converge on the same trust identity.
|
||||
let TomlValue::Table(mut table) = TomlValue::Table(Default::default()) else {
|
||||
unreachable!("TOML table construction should stay a table");
|
||||
};
|
||||
@@ -539,6 +530,22 @@ fn hook_event_key_label(event_name: codex_protocol::protocol::HookEventName) ->
|
||||
}
|
||||
}
|
||||
|
||||
fn hook_trust_status(
|
||||
is_managed: bool,
|
||||
current_hash: &str,
|
||||
trusted_hash: &Option<String>,
|
||||
) -> HookTrustStatus {
|
||||
if is_managed {
|
||||
HookTrustStatus::Managed
|
||||
} else {
|
||||
match trusted_hash.as_deref() {
|
||||
Some(trusted_hash) if trusted_hash == current_hash => HookTrustStatus::Trusted,
|
||||
Some(_) => HookTrustStatus::Modified,
|
||||
None => HookTrustStatus::Untrusted,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn hook_source_for_config_layer_source(source: &ConfigLayerSource) -> HookSource {
|
||||
match source {
|
||||
ConfigLayerSource::System { .. } => HookSource::System,
|
||||
|
||||
@@ -661,6 +661,7 @@ mod tests {
|
||||
use codex_app_server_protocol::HookHandlerType;
|
||||
use codex_app_server_protocol::HookMetadata;
|
||||
use codex_app_server_protocol::HookSource;
|
||||
use codex_app_server_protocol::HookTrustStatus;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use insta::assert_snapshot;
|
||||
@@ -706,6 +707,7 @@ mod tests {
|
||||
is_managed: bool,
|
||||
display_order: i64,
|
||||
) -> HookMetadata {
|
||||
let current_hash = "sha256:current".to_string();
|
||||
HookMetadata {
|
||||
key: key.to_string(),
|
||||
event_name,
|
||||
@@ -720,6 +722,13 @@ mod tests {
|
||||
plugin_id: plugin_id.map(str::to_string),
|
||||
display_order,
|
||||
enabled,
|
||||
current_hash: current_hash.clone(),
|
||||
trusted_hash: (!is_managed).then_some(current_hash),
|
||||
trust_status: if is_managed {
|
||||
HookTrustStatus::Managed
|
||||
} else {
|
||||
HookTrustStatus::Trusted
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user