Skip to content

Commit abde94e

Browse files
stephentoubCopilot
andcommitted
Address Rust hook CodeQL comments
Move unsupported hook error checking through a shared E2E helper so the error bindings are used outside assertion macro expansion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3ea68c8 commit abde94e

5 files changed

Lines changed: 18 additions & 28 deletions

File tree

rust/tests/e2e/hooks.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use github_copilot_sdk::hooks::{
66
SessionHooks,
77
};
88

9-
use super::support::with_e2e_context;
10-
11-
const UNSUPPORTED_SDK_HOOKS_MESSAGE: &str = "SDK hook callbacks are no longer supported";
9+
use super::support::{assert_unsupported_hooks_error, with_e2e_context};
1210

1311
#[tokio::test]
1412
async fn rejects_sdk_callback_hooks() {
@@ -37,10 +35,7 @@ async fn assert_unsupported_hooks(
3735
session.disconnect().await.expect("disconnect session");
3836
panic!("expected SDK callback hooks to be rejected");
3937
}
40-
Err(err) => assert!(
41-
err.to_string().contains(UNSUPPORTED_SDK_HOOKS_MESSAGE),
42-
"expected unsupported hooks error, got: {err}"
43-
),
38+
Err(err) => assert_unsupported_hooks_error(err),
4439
}
4540
}
4641

rust/tests/e2e/hooks_extended.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use github_copilot_sdk::hooks::{
88
SessionStartOutput, UserPromptSubmittedInput, UserPromptSubmittedOutput,
99
};
1010

11-
use super::support::with_e2e_context;
12-
13-
const UNSUPPORTED_SDK_HOOKS_MESSAGE: &str = "SDK hook callbacks are no longer supported";
11+
use super::support::{assert_unsupported_hooks_error, with_e2e_context};
1412

1513
#[tokio::test]
1614
async fn rejects_extended_sdk_callback_hooks() {
@@ -32,10 +30,7 @@ async fn rejects_extended_sdk_callback_hooks() {
3230
session.disconnect().await.expect("disconnect session");
3331
panic!("expected SDK callback hooks to be rejected");
3432
}
35-
Err(err) => assert!(
36-
err.to_string().contains(UNSUPPORTED_SDK_HOOKS_MESSAGE),
37-
"expected unsupported hooks error, got: {err}"
38-
),
33+
Err(err) => assert_unsupported_hooks_error(err),
3934
}
4035
client.stop().await.expect("stop client");
4136
})

rust/tests/e2e/pre_mcp_tool_call_hook.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use github_copilot_sdk::hooks::{
66
};
77
use serde_json::json;
88

9-
use super::support::with_e2e_context;
10-
11-
const UNSUPPORTED_SDK_HOOKS_MESSAGE: &str = "SDK hook callbacks are no longer supported";
9+
use super::support::{assert_unsupported_hooks_error, with_e2e_context};
1210

1311
#[tokio::test]
1412
async fn rejects_sdk_premcptoolcall_callback_hooks() {
@@ -30,10 +28,7 @@ async fn rejects_sdk_premcptoolcall_callback_hooks() {
3028
session.disconnect().await.expect("disconnect session");
3129
panic!("expected SDK callback hooks to be rejected");
3230
}
33-
Err(err) => assert!(
34-
err.to_string().contains(UNSUPPORTED_SDK_HOOKS_MESSAGE),
35-
"expected unsupported hooks error, got: {err}"
36-
),
31+
Err(err) => assert_unsupported_hooks_error(err),
3732
}
3833
client.stop().await.expect("stop client");
3934
})

rust/tests/e2e/subagent_hooks.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use github_copilot_sdk::hooks::{
66
SessionHooks,
77
};
88

9-
use super::support::with_e2e_context;
10-
11-
const UNSUPPORTED_SDK_HOOKS_MESSAGE: &str = "SDK hook callbacks are no longer supported";
9+
use super::support::{assert_unsupported_hooks_error, with_e2e_context};
1210

1311
#[tokio::test]
1412
async fn rejects_sdk_callback_hooks_for_sub_agent_hook_propagation() {
@@ -30,10 +28,7 @@ async fn rejects_sdk_callback_hooks_for_sub_agent_hook_propagation() {
3028
session.disconnect().await.expect("disconnect session");
3129
panic!("expected SDK callback hooks to be rejected");
3230
}
33-
Err(err) => assert!(
34-
err.to_string().contains(UNSUPPORTED_SDK_HOOKS_MESSAGE),
35-
"expected unsupported hooks error, got: {err}"
36-
),
31+
Err(err) => assert_unsupported_hooks_error(err),
3732
}
3833
client.stop().await.expect("stop client");
3934
})

rust/tests/e2e/support.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@ use tokio::sync::Semaphore;
2121
static E2E_CONCURRENCY: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::new(e2e_concurrency()));
2222

2323
pub const DEFAULT_TEST_TOKEN: &str = "rust-e2e-token";
24+
const UNSUPPORTED_SDK_HOOKS_MESSAGE: &str = "SDK hook callbacks are no longer supported";
2425

2526
type TestFuture<'a> = Pin<Box<dyn Future<Output = ()> + 'a>>;
2627

28+
pub fn assert_unsupported_hooks_error(err: impl std::fmt::Display) {
29+
let message = err.to_string();
30+
if message.contains(UNSUPPORTED_SDK_HOOKS_MESSAGE) {
31+
return;
32+
}
33+
34+
panic!("expected unsupported hooks error, got: {message}");
35+
}
36+
2737
pub async fn with_e2e_context<F>(category: &str, snapshot_name: &str, test: F)
2838
where
2939
F: for<'a> FnOnce(&'a mut E2eContext) -> TestFuture<'a>,

0 commit comments

Comments
 (0)