mirror of
https://github.com/openai/codex.git
synced 2026-11-06 20:20:34 +00:00
Align TUI hook trust flow with current hash
This commit is contained in:
@@ -368,13 +368,13 @@ impl App {
|
||||
&mut self,
|
||||
app_server: &AppServerSession,
|
||||
key: String,
|
||||
trusted_hash: String,
|
||||
current_hash: String,
|
||||
enable: bool,
|
||||
) {
|
||||
let request_handle = app_server.request_handle();
|
||||
let app_event_tx = self.app_event_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
let result = write_hook_trust(request_handle, key, trusted_hash, enable)
|
||||
let result = write_hook_trust(request_handle, key, current_hash, enable)
|
||||
.await
|
||||
.map(|_| ())
|
||||
.map_err(|err| format!("Failed to trust hook: {err}"));
|
||||
@@ -868,7 +868,7 @@ pub(super) async fn write_hook_enabled(
|
||||
pub(super) async fn write_hook_trust(
|
||||
request_handle: AppServerRequestHandle,
|
||||
key: String,
|
||||
trusted_hash: String,
|
||||
current_hash: String,
|
||||
enable: bool,
|
||||
) -> Result<ConfigWriteResponse> {
|
||||
let request_id = RequestId::String(format!("hooks-config-write-{}", Uuid::new_v4()));
|
||||
@@ -876,13 +876,13 @@ pub(super) async fn write_hook_trust(
|
||||
serde_json::json!({
|
||||
key: {
|
||||
"enabled": true,
|
||||
"trusted_hash": trusted_hash,
|
||||
"trusted_hash": current_hash,
|
||||
}
|
||||
})
|
||||
} else {
|
||||
serde_json::json!({
|
||||
key: {
|
||||
"trusted_hash": trusted_hash,
|
||||
"trusted_hash": current_hash,
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
@@ -1694,10 +1694,10 @@ impl App {
|
||||
}
|
||||
AppEvent::TrustHook {
|
||||
key,
|
||||
trusted_hash,
|
||||
current_hash,
|
||||
enable,
|
||||
} => {
|
||||
self.trust_hook(app_server, key, trusted_hash, enable);
|
||||
self.trust_hook(app_server, key, current_hash, enable);
|
||||
}
|
||||
AppEvent::HookEnabledSet {
|
||||
key,
|
||||
|
||||
@@ -752,7 +752,7 @@ pub(crate) enum AppEvent {
|
||||
/// Trust the current definition for a hook by stable hook key.
|
||||
TrustHook {
|
||||
key: String,
|
||||
trusted_hash: String,
|
||||
current_hash: String,
|
||||
enable: bool,
|
||||
},
|
||||
|
||||
|
||||
@@ -922,7 +922,6 @@ mod tests {
|
||||
/*is_managed*/ false,
|
||||
/*display_order*/ 0,
|
||||
);
|
||||
untrusted_hook.trusted_hash = None;
|
||||
untrusted_hook.trust_status = HookTrustStatus::Untrusted;
|
||||
let view = HooksBrowserView::new(
|
||||
vec![untrusted_hook],
|
||||
@@ -1316,11 +1315,11 @@ mod tests {
|
||||
match rx.try_recv().expect("trust event") {
|
||||
AppEvent::TrustHook {
|
||||
key,
|
||||
current_hash: trusted_hash,
|
||||
current_hash: hash_to_trust,
|
||||
enable,
|
||||
} => {
|
||||
assert_eq!(key, "path:untrusted");
|
||||
assert_eq!(trusted_hash, current_hash);
|
||||
assert_eq!(hash_to_trust, current_hash);
|
||||
assert!(enable);
|
||||
}
|
||||
other => panic!("expected hook trust event, got {other:?}"),
|
||||
|
||||
+4
-3
@@ -4,14 +4,15 @@ expression: "render_lines(&view, 112)"
|
||||
---
|
||||
|
||||
PreToolUse hooks
|
||||
Turn hooks on or off. Your changes are saved automatically.
|
||||
1 hook needs review before it can run.
|
||||
|
||||
[ ] Hook 1
|
||||
[!] Hook 1 · new
|
||||
|
||||
Event PreToolUse
|
||||
Matcher Bash
|
||||
Source User config - /tmp/hooks.json
|
||||
Command ~/bin/untrusted.sh
|
||||
Timeout 30s
|
||||
Trust New hook - review required
|
||||
|
||||
Press space or enter to toggle; esc to go back
|
||||
Press t to trust; esc to go back
|
||||
|
||||
Reference in New Issue
Block a user