Files
crank/crates/crank-community-mcp/src/rmcp_prompts_handler_runtime_tests.rs
T
bsodfather 5cce1b09df
CI / UI Checks (pull_request) Successful in 14s
CI / Rust Checks (pull_request) Successful in 37m47s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped
feat(mcp): execute Prompts through request-scoped SDK handlers
2026-11-13 07:30:32 +00:00

72 lines
2.4 KiB
Rust

//! Handler completion/consumption is independent of the existing DTO wire oracle.
use super::{CounterSet, observe, rmcp_prompts_runtime_tests::control, support::*};
use std::sync::Arc;
pub(super) fn counts(c: &CounterSet) -> [usize; 4] {
[
c.sdk_prompts_list_handler_completed(),
c.sdk_prompts_get_handler_completed(),
c.sdk_prompts_list_handler_consumed(),
c.sdk_prompts_get_handler_consumed(),
]
}
pub(super) fn delta(c: &CounterSet, before: [usize; 4], method: &str) -> ([usize; 4], [usize; 4]) {
let after = counts(c);
let expected = match method {
"prompts/list" => [1, 0, 1, 0],
"prompts/get" => [0, 1, 0, 1],
_ => panic!("not a Prompts method: {method}"),
};
(std::array::from_fn(|i| after[i] - before[i]), expected)
}
#[tokio::test]
async fn rmcp_prompts_handler_legacy() {
control(LEGACY_REVISION, true).await;
}
#[tokio::test]
async fn rmcp_prompts_handler_modern() {
control(MODERN_REVISION, true).await;
}
#[tokio::test]
async fn rmcp_prompts_handler_observer_positive_control() {
use super::{
sdk_prompts_get_handler_completed, sdk_prompts_get_handler_consumed,
sdk_prompts_list_handler_completed, sdk_prompts_list_handler_consumed,
};
let a = Arc::new(CounterSet::default());
let b = Arc::new(CounterSet::default());
sdk_prompts_list_handler_completed();
sdk_prompts_get_handler_completed();
sdk_prompts_list_handler_consumed();
sdk_prompts_get_handler_consumed();
assert_eq!(counts(&a), [0; 4], "no-scope markers must be no-ops");
let snapshot = a.snapshot();
tokio::join!(
observe(a.clone(), async {
sdk_prompts_list_handler_completed();
tokio::task::yield_now().await;
sdk_prompts_get_handler_completed();
sdk_prompts_list_handler_consumed();
sdk_prompts_get_handler_consumed();
}),
observe(b.clone(), async {
sdk_prompts_get_handler_completed();
tokio::task::yield_now().await;
sdk_prompts_get_handler_consumed();
}),
);
assert_eq!(counts(&a), [1; 4]);
assert_eq!(counts(&b), [0, 1, 0, 1]);
assert_eq!(a.snapshot(), snapshot);
assert_eq!(b.snapshot(), CounterSet::default().snapshot());
for c in [&a, &b] {
assert_eq!(c.sdk_prompts_dispatch(), 0);
assert_eq!(c.sdk_prompts_list_result(), 0);
assert_eq!(c.sdk_prompts_get_result(), 0);
}
}