fix(epic3): сделать ATDD отмены чувствительным к регрессии и покрыть bounds токена в обеих revision (Story 3.4, FR-14)

- CANCEL_GRACE_MS 1200 -> 2500 (> LONG_HOLD_MS) и const-assert на этот порядок:
  при незавершённой отмене вызов успевает завершиться и записать исход внутри
  окна проверки, поэтому тест доказывает остановку, а не только «ещё не готово».
- malformed/oversized/empty/object/array token теперь проверяются и в modern
  revision, не только в legacy (обе читают одно поле RequestMetaObject).
- комментарий cancelled_response приведён к фактическому поведению: у
  остановленного вызова строки Invocation History нет вообще.
This commit is contained in:
bsodfather committed 2026-10-26 13:07:14 +00:00
1 parent 862cde8559
commit f613250fd3
2 files changed
+53 -38

No files matched your search

@@ -41,10 +41,15 @@ const TOOL: &str = "crm_lifecycle_lead";
const HOLD_MS: u64 = 250; const HOLD_MS: u64 = 250;
/// A call that is still running when the client cancels it. /// A call that is still running when the client cancels it.
const LONG_HOLD_MS: u64 = 1_500; const LONG_HOLD_MS: u64 = 1_500;
/// The grace period after a cancellation: the call must not complete in it. /// The grace period after a cancellation. It must exceed [`LONG_HOLD_MS`]: a call that was *not*
const CANCEL_GRACE_MS: u64 = 1_200; /// 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 { enum Revision {
Legacy, Legacy,
Modern, 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 fixture = fixture("lifecycle-bad-token", HOLD_MS, 5_000).await;
let session = initialize_session(&fixture.client, &fixture.mcp_url, &fixture.api_key).await; let session = initialize_session(&fixture.client, &fixture.mcp_url, &fixture.api_key).await;
let oversized = "x".repeat(4096); // Both supported revisions read the token from the same pinned `RequestMetaObject` field, so an
let oversized = json!(oversized); // unusable token must behave identically in each of them: no progress, unchanged result.
let empty = json!(""); for revision in [Revision::Legacy, Revision::Modern] {
let object = json!({ "not": "a token" }); let carrier = match revision {
let array = json!([1, 2]); Revision::Legacy => Some(session.as_str()),
let boolean = json!(true); Revision::Modern => None,
let mut observed = Vec::new(); };
for token in [empty, object, array, boolean, oversized] { let tokens = [
let reply = fixture json!(""),
.call_stream( json!({ "not": "a token" }),
Revision::Legacy, json!([1, 2]),
520, json!(true),
fixture.call_params(Some(token.clone()), Revision::Legacy), json!("x".repeat(4096)),
Some(&session), ];
"req-bad-token", let mut observed = Vec::new();
) for token in tokens {
.await; let reply = fixture
observed.push((token, reply)); .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 { for (token, reply) in observed {
assert!( assert!(
reply.progress_frames().is_empty(), reply.progress_frames().is_empty(),
"token {token} must not produce progress, got {}", "{revision:?}: token {token} must not produce progress, got {}",
reply.raw reply.raw
); );
let terminal = reply.terminal(); let terminal = reply.terminal();
assert_eq!( assert_eq!(
terminal["result"]["structuredContent"], terminal["result"]["structuredContent"],
json!({ "id": "lead_123" }), json!({ "id": "lead_123" }),
"token {token} must not change the execution result, got {terminal}" "{revision:?}: token {token} must not change the execution result, got {terminal}"
); );
assert_eq!(terminal["result"]["isError"], json!(false)); assert_eq!(terminal["result"]["isError"], json!(false));
assert!(terminal["error"].is_null() || terminal.get("error").is_none()); assert!(terminal["error"].is_null() || terminal.get("error").is_none());
}
} }
} }
@@ -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 /// 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 /// 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 /// here claims that an outbound side effect did or did not happen — and nothing else claims the
/// Invocation History entry of the call, which records the cancellation as outcome-unknown. /// 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 { fn cancelled_response() -> Response {
StatusCode::OK.into_response() StatusCode::OK.into_response()
} }