mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
## Why A plugin's scripts can change without changing its hook declaration. Declaration-only approval therefore lets changed plugin code run under an existing hook approval. ## What changed - Fingerprint plugin bundle contents and include the content hash in the approval value returned by `hooks/list`. Persist it as `trusted_content_hash`, keeping `trusted_hash` compatible with older clients. - Verify contents before each command or MCP hook execution, within the hook's timeout, and require renewed approval when approved contents change. - Migrate legacy declaration-only approvals to a shared, immutable content baseline per plugin and config home. - Exclude generated Python bytecode, `.venv`, and `.egg-info` entries from fingerprints. Run app-server hook listing on blocking tasks. ## Testing Extend integration coverage for plugin upgrades and rollbacks requiring approval, same-turn script changes preventing further hook execution, shared legacy approval baselines, and generated Python artifacts preserving trust. GitOrigin-RevId: faaf7658210d8adb2534ddd614c72ec993920840
82 lines
2.4 KiB
Rust
82 lines
2.4 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use codex_protocol::protocol::HookEventName;
|
|
use codex_protocol::protocol::HookRunStatus;
|
|
use codex_protocol::protocol::HookSource;
|
|
use codex_utils_absolute_path::test_support::PathBufExt;
|
|
use codex_utils_absolute_path::test_support::test_path_buf;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use super::parse_completed;
|
|
use super::preview;
|
|
use crate::engine::ConfiguredHandler;
|
|
use crate::engine::HandlerRunResult;
|
|
|
|
#[test]
|
|
fn session_end_matches_other_reason() {
|
|
let selected = preview(&[
|
|
ConfiguredHandler {
|
|
display_order: 0,
|
|
..handler(Some("clear"))
|
|
},
|
|
ConfiguredHandler {
|
|
display_order: 1,
|
|
..handler(Some("other"))
|
|
},
|
|
ConfiguredHandler {
|
|
display_order: 2,
|
|
..handler(/*matcher*/ None)
|
|
},
|
|
]);
|
|
|
|
assert_eq!(
|
|
selected
|
|
.iter()
|
|
.map(|run| run.display_order)
|
|
.collect::<Vec<_>>(),
|
|
vec![1, 2]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn session_end_ignores_successful_output() {
|
|
let completed = parse_completed(
|
|
&handler(/*matcher*/ None),
|
|
HandlerRunResult {
|
|
context_metadata: codex_protocol::models::ContentItemMetadata::harness(),
|
|
started_at: 1,
|
|
completed_at: 2,
|
|
duration_ms: 1,
|
|
exit_code: Some(0),
|
|
stdout: r#"{"continue":false,"decision":"block","reason":"ignored"}"#.to_string(),
|
|
stderr: String::new(),
|
|
error: None,
|
|
},
|
|
/*turn_id*/ None,
|
|
);
|
|
|
|
assert_eq!(completed.completed.run.status, HookRunStatus::Completed);
|
|
assert_eq!(completed.completed.run.entries, Vec::new());
|
|
}
|
|
|
|
fn handler(matcher: Option<&str>) -> ConfiguredHandler {
|
|
ConfiguredHandler {
|
|
builtin: false,
|
|
plugin_trust: None,
|
|
event_name: HookEventName::SessionEnd,
|
|
matcher: matcher
|
|
.map(|pattern| crate::engine::HookMatcher::new(pattern).expect("valid matcher")),
|
|
timeout_sec: 2,
|
|
status_message: None,
|
|
additional_context_limit: Default::default(),
|
|
source_path: test_path_buf("/tmp/hooks.json").abs().into(),
|
|
source: HookSource::User,
|
|
display_order: 0,
|
|
kind: crate::engine::ConfiguredHandlerKind::Command {
|
|
command: "echo hook".to_string(),
|
|
r#async: false,
|
|
env: HashMap::new(),
|
|
},
|
|
}
|
|
}
|