From f613250fd3c7e63796c679b1f7b9cd5cbdf5b8fd Mon Sep 17 00:00:00 2001 From: bsodfather Date: Mon, 26 Oct 2026 13:07:14 +0000 Subject: [PATCH] =?UTF-8?q?fix(epic3):=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20ATDD=20=D0=BE=D1=82=D0=BC=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D1=87=D1=83=D0=B2=D1=81=D1=82=D0=B2=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=BC=20=D0=BA=20=D1=80=D0=B5=D0=B3=D1=80?= =?UTF-8?q?=D0=B5=D1=81=D1=81=D0=B8=D0=B8=20=D0=B8=20=D0=BF=D0=BE=D0=BA?= =?UTF-8?q?=D1=80=D1=8B=D1=82=D1=8C=20bounds=20=D1=82=D0=BE=D0=BA=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=20=D0=BE=D0=B1=D0=B5=D0=B8=D1=85=20revisi?= =?UTF-8?q?on=20(Story=203.4,=20FR-14)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CANCEL_GRACE_MS 1200 -> 2500 (> LONG_HOLD_MS) и const-assert на этот порядок: при незавершённой отмене вызов успевает завершиться и записать исход внутри окна проверки, поэтому тест доказывает остановку, а не только «ещё не готово». - malformed/oversized/empty/object/array token теперь проверяются и в modern revision, не только в legacy (обе читают одно поле RequestMetaObject). - комментарий cancelled_response приведён к фактическому поведению: у остановленного вызова строки Invocation History нет вообще. --- .../tests/integration/tools_lifecycle.rs | 86 +++++++++++-------- .../crank-community-mcp/src/app/lifecycle.rs | 5 +- 2 files changed, 53 insertions(+), 38 deletions(-) diff --git a/apps/mcp-server/tests/integration/tools_lifecycle.rs b/apps/mcp-server/tests/integration/tools_lifecycle.rs index d34b70c..b5b4b95 100644 --- a/apps/mcp-server/tests/integration/tools_lifecycle.rs +++ b/apps/mcp-server/tests/integration/tools_lifecycle.rs @@ -41,10 +41,15 @@ const TOOL: &str = "crm_lifecycle_lead"; const HOLD_MS: u64 = 250; /// A call that is still running when the client cancels it. const LONG_HOLD_MS: u64 = 1_500; -/// The grace period after a cancellation: the call must not complete in it. -const CANCEL_GRACE_MS: u64 = 1_200; +/// The grace period after a cancellation. It must exceed [`LONG_HOLD_MS`]: a call that was *not* +/// stopped completes its upstream request and records the outcome inside this window, so the checks +/// after it prove that the cancellation stopped the call rather than only that it had not finished +/// yet. +const CANCEL_GRACE_MS: u64 = 2_500; +/// The suite depends on that order: the constant must not silently drop back below the hold. +const _: () = assert!(CANCEL_GRACE_MS > LONG_HOLD_MS); -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] enum Revision { Legacy, Modern, @@ -644,40 +649,49 @@ async fn at_3_4_02_malformed_and_oversized_tokens_disable_progress_without_chang let fixture = fixture("lifecycle-bad-token", HOLD_MS, 5_000).await; let session = initialize_session(&fixture.client, &fixture.mcp_url, &fixture.api_key).await; - let oversized = "x".repeat(4096); - let oversized = json!(oversized); - let empty = json!(""); - let object = json!({ "not": "a token" }); - let array = json!([1, 2]); - let boolean = json!(true); - let mut observed = Vec::new(); - for token in [empty, object, array, boolean, oversized] { - let reply = fixture - .call_stream( - Revision::Legacy, - 520, - fixture.call_params(Some(token.clone()), Revision::Legacy), - Some(&session), - "req-bad-token", - ) - .await; - observed.push((token, reply)); - } + // Both supported revisions read the token from the same pinned `RequestMetaObject` field, so an + // unusable token must behave identically in each of them: no progress, unchanged result. + for revision in [Revision::Legacy, Revision::Modern] { + let carrier = match revision { + Revision::Legacy => Some(session.as_str()), + Revision::Modern => None, + }; + let tokens = [ + json!(""), + json!({ "not": "a token" }), + json!([1, 2]), + json!(true), + json!("x".repeat(4096)), + ]; + let mut observed = Vec::new(); + for token in tokens { + let reply = fixture + .call_stream( + revision, + 520, + fixture.call_params(Some(token.clone()), revision), + carrier, + "req-bad-token", + ) + .await; + observed.push((token, reply)); + } - for (token, reply) in observed { - assert!( - reply.progress_frames().is_empty(), - "token {token} must not produce progress, got {}", - reply.raw - ); - let terminal = reply.terminal(); - assert_eq!( - terminal["result"]["structuredContent"], - json!({ "id": "lead_123" }), - "token {token} must not change the execution result, got {terminal}" - ); - assert_eq!(terminal["result"]["isError"], json!(false)); - assert!(terminal["error"].is_null() || terminal.get("error").is_none()); + for (token, reply) in observed { + assert!( + reply.progress_frames().is_empty(), + "{revision:?}: token {token} must not produce progress, got {}", + reply.raw + ); + let terminal = reply.terminal(); + assert_eq!( + terminal["result"]["structuredContent"], + json!({ "id": "lead_123" }), + "{revision:?}: token {token} must not change the execution result, got {terminal}" + ); + assert_eq!(terminal["result"]["isError"], json!(false)); + assert!(terminal["error"].is_null() || terminal.get("error").is_none()); + } } } diff --git a/crates/crank-community-mcp/src/app/lifecycle.rs b/crates/crank-community-mcp/src/app/lifecycle.rs index 637bc99..2bf23d9 100644 --- a/crates/crank-community-mcp/src/app/lifecycle.rs +++ b/crates/crank-community-mcp/src/app/lifecycle.rs @@ -458,8 +458,9 @@ async fn call_future( /// A cancelled call is not answered: the pinned rule for a cancelled request is that no further /// message is sent for it, and the client that cancelled it ignores a late response anyway. Nothing -/// here claims that an outbound side effect did or did not happen — that statement belongs to the -/// Invocation History entry of the call, which records the cancellation as outcome-unknown. +/// here claims that an outbound side effect did or did not happen — and nothing else claims the +/// opposite either: the call is stopped before its terminal outcome, so its Invocation History holds +/// no row for this call at all (see the module docs for why there is no invented cancellation code). fn cancelled_response() -> Response { StatusCode::OK.into_response() }