CI / UI Checks (pull_request) Successful in 9s
CI / Rust Checks (pull_request) Failing after 4m10s
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) Failing after 1s
CI / Deploy (pull_request) Skipped
Story 3.19 / FR-19 на принятой базе Story 3.18 (`47a6e54`, PR #99): после commit опубликованного каталога Agent клиент получает `notifications/resources/list_changed` и/или `notifications/prompts/list_changed`, обе pinned revisions, а обычное чтение каталога остаётся авторитетным при потере сигнала. Scope ограничен list-change: `resources/subscribe`/`unsubscribe` остаются `-32601`, значение `resources.subscribe` остаётся `false` (одобренный владельцем вариант A). Публикация переносит только semantic delta Story 3.19 из `/home/codex/code/crank-worktrees/story31-worktree` (`1b6db09` + cumulative overlay) на принятый head 3.18, а не копирует worktree: - новый `protocol/signals.rs` (watcher, отпечаток каталога, bounded filter, revision-correct encoders, bounded legacy stream registry) и `protocol/signals_tests.rs` (17 unit oracles); - `subscriptions/listen` (modern-only dispatch registration) + честные `listChanged: true` объявления; `app/endpoint.rs` получает legacy GET producer/DELETE retire, `app/dispatch.rs` — modern listen stream; - ATDD `mcp_signals` 5 сценариев на реальном endpoint/PostgreSQL/artifact store; capability inventory и frozen/provenance проекции обновлены (`b90b59f3…`, inventory `10ca3538…`); - `scripts/ci-story-checks.sh`: добавлены 3.19-проверки, записи Story 3.18 сохранены (гейт не ослаблен). Принятая правка code-health `206ca78` сохранена: `app/endpoint.rs` 402 строки (было 381), `app/legacy_dispatch.rs` 731 без изменений, т.е. split не переписан. Новый ATDD-файл `mcp_signals.rs` до 1138 строк превышал лимит `scripts/check-rust-code-health.sh`, поэтому его сценарии механически вынесены в `mcp_signals/scenarios.rs` без изменения проверок. Наследованный дефект tooling-гейта: `tests/unit/test_validate_capability_inventory.py` требует, чтобы `Run tooling unit tests` шёл раньше `scripts/validate-capability-inventory.py`; в принятом `ci.yml` (3.18) шаг оказался в условном feature-job. Шаг перенесён в обязательный `rust` job перед проверкой inventory — исполняемый tooling-гейт теперь проверяется там же, где применяется; ни одна проверка не отключена и не ослаблена. Проверки на этом коммите: `ci-story-checks.sh` exit 0 — 4/9/1/12/10/3/5(+1 manual ignored)/17 passed; `crank-community-mcp --lib` 102/0; transport 20/0, mcp_prompts 15/0, revision_matrix::negotiation 23/0, era_isolation 5/0; `cargo fmt --check` и `cargo clippy -p crank-community-mcp -p mcp-server --all-targets -D warnings` — 0; `check-rust-code-health.sh` — pass; capability inventory `status=valid protocol_items=50 revisions=2`; `python3 -m unittest discover -s tests/unit` — 305 OK. NOT_RUN (честно, не PASS): полный `just verify`, межкомпонентная интеграция, нагрузка и квалификация ≥3 реальных клиентов — остаются на собранной фиче 3.20 по validation-policy.md.
417 lines
15 KiB
Rust
417 lines
15 KiB
Rust
//! Story 3.19 acceptance scenarios (AT-3.19-01..03, FR-19) on the harness in the parent module.
|
|
//!
|
|
//! Moved out of `mcp_signals.rs` verbatim (code-health split, 1000-line limit); no scenario,
|
|
//! assertion or fixture changed.
|
|
|
|
use super::*;
|
|
|
|
/// Loopback disposable stand for the AC-3 representative-client evidence. This is deliberately not
|
|
/// part of the automated ATDD: it publishes the fixture catalog, serves the real MCP endpoint on
|
|
/// `127.0.0.1`, and then performs one commit per command file so an external MCP client can observe
|
|
/// the signals on its own stream.
|
|
///
|
|
/// Run it explicitly (the credential file is `0600` and never printed):
|
|
///
|
|
/// ```text
|
|
/// MCP_SIGNALS_STAND_DIR=/tmp/crank-signals-stand \
|
|
/// cargo test -p mcp-server --test integration mcp_signals::scenarios::representative_client_stand \
|
|
/// -- --ignored --exact --nocapture
|
|
/// ```
|
|
///
|
|
/// Commands (create the file, wait for `<command>.done`): `commit-both`, `commit-prompt`,
|
|
/// `commit-resource`, `commit-tool`, `draft`, `stop`.
|
|
#[tokio::test]
|
|
#[ignore = "manual loopback stand for the representative MCP Inspector client evidence"]
|
|
async fn representative_client_stand() {
|
|
let directory = PathBuf::from(
|
|
std::env::var("MCP_SIGNALS_STAND_DIR")
|
|
.expect("MCP_SIGNALS_STAND_DIR names the disposable stand directory"),
|
|
);
|
|
fs::create_dir_all(&directory).expect("the stand directory is creatable");
|
|
let endpoint = signals_endpoint().await;
|
|
write_private(
|
|
&directory.join("stand.json"),
|
|
&json!({ "url": endpoint.mcp_url, "token": endpoint.api_key }).to_string(),
|
|
);
|
|
println!("stand ready: {}", directory.join("stand.json").display());
|
|
|
|
let deadline = tokio::time::Instant::now() + Duration::from_secs(900);
|
|
while tokio::time::Instant::now() < deadline {
|
|
for command in [
|
|
"commit-both",
|
|
"commit-prompt",
|
|
"commit-resource",
|
|
"commit-tool",
|
|
"draft",
|
|
"stop",
|
|
] {
|
|
let marker = directory.join(command);
|
|
if !marker.exists() {
|
|
continue;
|
|
}
|
|
fs::remove_file(&marker).expect("the command file is consumed once");
|
|
if command == "stop" {
|
|
println!("stand stopped: {command}");
|
|
return;
|
|
}
|
|
match command {
|
|
"commit-both" => endpoint.commit_resource_and_prompt_change().await,
|
|
"commit-prompt" => endpoint.commit_prompt_only_change().await,
|
|
"commit-resource" => endpoint.commit_resource_only_change().await,
|
|
"commit-tool" => endpoint.commit_tool_only_change().await,
|
|
_ => endpoint.edit_draft_without_publishing().await,
|
|
}
|
|
write_private(&directory.join(format!("{command}.done")), "done");
|
|
println!("stand committed: {command}");
|
|
}
|
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
|
}
|
|
}
|
|
|
|
/// AT-3.19-01 (legacy): an open notification stream receives the Resource and Prompt list-change
|
|
/// notifications only after the catalog commit, and `resources/list` / `prompts/list` serve the new
|
|
/// state afterwards.
|
|
#[tokio::test]
|
|
async fn legacy_stream_announces_a_committed_catalog_change_after_the_commit() {
|
|
let endpoint = signals_endpoint().await;
|
|
let session = endpoint.legacy_session().await;
|
|
|
|
let mut stream = endpoint.legacy_stream(&session).await;
|
|
// The watcher takes its baseline before it can report anything; let it settle before the commit.
|
|
tokio::time::sleep(Duration::from_millis(1_500)).await;
|
|
stream
|
|
.expect_silence(Duration::from_millis(1_200), "signal before any commit")
|
|
.await;
|
|
|
|
// A draft-only edit is not a commit: nothing is announced.
|
|
endpoint.edit_draft_without_publishing().await;
|
|
stream
|
|
.expect_silence(Duration::from_millis(2_500), "signal for a draft-only edit")
|
|
.await;
|
|
|
|
endpoint.commit_resource_and_prompt_change().await;
|
|
|
|
let mut methods = Vec::new();
|
|
for _ in 0..2 {
|
|
let frame = stream
|
|
.expect_frame("the committed list-change signals")
|
|
.await;
|
|
assert_eq!(frame["jsonrpc"], json!("2.0"));
|
|
assert!(
|
|
frame.get("params").is_none(),
|
|
"a legacy list-change notification carries no parameters: {frame}"
|
|
);
|
|
methods.push(frame["method"].as_str().unwrap().to_owned());
|
|
}
|
|
methods.sort();
|
|
assert_eq!(
|
|
methods,
|
|
vec![
|
|
PROMPT_LIST_CHANGED.to_owned(),
|
|
RESOURCE_LIST_CHANGED.to_owned()
|
|
],
|
|
"one signal per changed catalog type"
|
|
);
|
|
|
|
// The ordinary list methods are authoritative for the same committed state.
|
|
let prompts = endpoint.legacy(&session, "prompts/list", json!({})).await;
|
|
assert!(
|
|
prompt_names(&prompts).contains(&"extra".to_owned()),
|
|
"prompts/list must serve the newly bound Prompt: {prompts}"
|
|
);
|
|
let resources = endpoint.legacy(&session, "resources/list", json!({})).await;
|
|
assert!(
|
|
resource_uris(&resources)
|
|
.iter()
|
|
.any(|uri| uri == &format!("crank://resources/{}", endpoint.notice.as_str())),
|
|
"resources/list must serve the newly bound Resource: {resources}"
|
|
);
|
|
|
|
// A Tool-only commit keeps the Resource/Prompt projection: no further signal.
|
|
endpoint.commit_tool_only_change().await;
|
|
stream
|
|
.expect_silence(
|
|
Duration::from_millis(2_500),
|
|
"signal for a Tool-only commit",
|
|
)
|
|
.await;
|
|
}
|
|
|
|
/// AT-3.19-01/03 (modern): `subscriptions/listen` acknowledges the honoured filter with the request
|
|
/// id, then delivers coalesced list-change notifications carrying the subscription id.
|
|
#[tokio::test]
|
|
async fn modern_listen_stream_acknowledges_then_announces_coalesced_changes() {
|
|
let endpoint = signals_endpoint().await;
|
|
let mut stream = endpoint
|
|
.listen(
|
|
json!(41),
|
|
json!({
|
|
"resourcesListChanged": true,
|
|
"promptsListChanged": true,
|
|
"toolsListChanged": true,
|
|
"resourceSubscriptions": ["crank://resources/res_a_notice"]
|
|
}),
|
|
)
|
|
.await;
|
|
|
|
let acknowledgement = stream.expect_frame("the acknowledgment").await;
|
|
assert_eq!(acknowledgement["method"], SUBSCRIPTIONS_ACKNOWLEDGED);
|
|
assert_eq!(
|
|
acknowledgement["params"]["_meta"][SUBSCRIPTION_ID_KEY],
|
|
json!(41)
|
|
);
|
|
assert_eq!(
|
|
acknowledgement["params"]["notifications"],
|
|
json!({ "promptsListChanged": true, "resourcesListChanged": true }),
|
|
"only the implemented list-change types are acknowledged: {acknowledgement}"
|
|
);
|
|
|
|
tokio::time::sleep(Duration::from_millis(1_500)).await;
|
|
|
|
// Two commits in quick succession coalesce into one signal per changed type.
|
|
endpoint.commit_resource_and_prompt_change().await;
|
|
endpoint.commit_tool_only_change().await;
|
|
|
|
let mut methods = Vec::new();
|
|
for _ in 0..2 {
|
|
let frame = stream
|
|
.expect_frame("the coalesced list-change signal")
|
|
.await;
|
|
assert_eq!(frame["params"]["_meta"][SUBSCRIPTION_ID_KEY], json!(41));
|
|
methods.push(frame["method"].as_str().unwrap().to_owned());
|
|
}
|
|
methods.sort();
|
|
assert_eq!(
|
|
methods,
|
|
vec![
|
|
PROMPT_LIST_CHANGED.to_owned(),
|
|
RESOURCE_LIST_CHANGED.to_owned()
|
|
]
|
|
);
|
|
stream
|
|
.expect_silence(
|
|
Duration::from_millis(2_500),
|
|
"a duplicate or unrequested signal",
|
|
)
|
|
.await;
|
|
|
|
// A client that missed every notification still recovers the authoritative catalog.
|
|
let prompts = endpoint.modern("prompts/list", json!({})).await;
|
|
assert!(
|
|
prompt_names(&prompts).contains(&"extra".to_owned()),
|
|
"{prompts}"
|
|
);
|
|
}
|
|
|
|
/// AT-3.19-01/03 (modern): the acknowledged filter is the delivery contract. A prompts-only stream
|
|
/// stays silent for a Resource-only commit, delivers exactly one Prompt frame with the subscription
|
|
/// id for a Prompt commit, and never delivers an unrequested type.
|
|
#[tokio::test]
|
|
async fn modern_listen_delivers_only_the_negotiated_signal_types() {
|
|
let endpoint = signals_endpoint().await;
|
|
let mut stream = endpoint
|
|
.listen(
|
|
json!("prompts-only"),
|
|
json!({
|
|
"promptsListChanged": true,
|
|
"toolsListChanged": true,
|
|
"resourceSubscriptions": ["crank://resources/res_a_notice"]
|
|
}),
|
|
)
|
|
.await;
|
|
|
|
let acknowledgement = stream.expect_frame("the acknowledgment").await;
|
|
assert_eq!(acknowledgement["method"], SUBSCRIPTIONS_ACKNOWLEDGED);
|
|
assert_eq!(
|
|
acknowledgement["params"]["_meta"][SUBSCRIPTION_ID_KEY],
|
|
json!("prompts-only")
|
|
);
|
|
assert_eq!(
|
|
acknowledgement["params"]["notifications"],
|
|
json!({ "promptsListChanged": true }),
|
|
"only the implemented and requested type is acknowledged: {acknowledgement}"
|
|
);
|
|
|
|
// The watcher takes its baseline before it can report anything.
|
|
tokio::time::sleep(Duration::from_millis(1_500)).await;
|
|
|
|
// A Resource-only commit is outside the negotiated filter: a server that ignored the filter would
|
|
// emit a Resource frame here.
|
|
endpoint.commit_resource_only_change().await;
|
|
stream
|
|
.expect_silence(
|
|
Duration::from_millis(2_500),
|
|
"signal for a Resource-only commit on a prompts-only stream",
|
|
)
|
|
.await;
|
|
|
|
// A Prompt-only commit is inside it: exactly one frame, correlated by the subscription id.
|
|
endpoint.commit_prompt_only_change().await;
|
|
let frame = stream
|
|
.expect_frame("the negotiated Prompt list-change signal")
|
|
.await;
|
|
assert_eq!(frame["method"], PROMPT_LIST_CHANGED);
|
|
assert_eq!(
|
|
frame["params"]["_meta"][SUBSCRIPTION_ID_KEY],
|
|
json!("prompts-only")
|
|
);
|
|
|
|
// Neither `toolsListChanged` nor `resourceSubscriptions` were honoured, so nothing else follows.
|
|
stream
|
|
.expect_silence(
|
|
Duration::from_millis(2_500),
|
|
"a duplicate, Tools or URI-content signal",
|
|
)
|
|
.await;
|
|
}
|
|
|
|
/// AT-3.19-03: the unsupported URI-content subscription surface is never acknowledged, and the
|
|
/// legacy revision has no `subscriptions/listen` request at all.
|
|
#[tokio::test]
|
|
async fn unsupported_subscription_surfaces_are_refused_rather_than_faked() {
|
|
let endpoint = signals_endpoint().await;
|
|
|
|
for method in ["resources/subscribe", "resources/unsubscribe"] {
|
|
let reply = endpoint
|
|
.modern(method, json!({ "uri": "crank://resources/res_a_notice" }))
|
|
.await;
|
|
assert_eq!(
|
|
reply["error"]["code"],
|
|
json!(-32601),
|
|
"{method} must stay unimplemented: {reply}"
|
|
);
|
|
}
|
|
|
|
// The legacy revision opens its notification stream with GET only.
|
|
let session = endpoint.legacy_session().await;
|
|
let legacy_listen = endpoint
|
|
.legacy(
|
|
&session,
|
|
"subscriptions/listen",
|
|
json!({ "notifications": {} }),
|
|
)
|
|
.await;
|
|
assert_eq!(
|
|
legacy_listen["error"]["code"],
|
|
json!(-32601),
|
|
"subscriptions/listen is a modern-only request: {legacy_listen}"
|
|
);
|
|
|
|
// A malformed filter is a bounded invalid-params answer with no echoed value.
|
|
let malformed = endpoint
|
|
.modern_offering_stream(
|
|
"subscriptions/listen",
|
|
json!({ "notifications": ["promptsListChanged"] }),
|
|
)
|
|
.await;
|
|
assert_eq!(malformed["error"]["code"], json!(-32602));
|
|
assert_eq!(
|
|
malformed["error"]["message"],
|
|
json!("invalid subscriptions/listen notification filter")
|
|
);
|
|
|
|
// Without an SSE-capable client the stream cannot be served at all.
|
|
let without_sse = endpoint
|
|
.client
|
|
.post(&endpoint.mcp_url)
|
|
.header(header::ACCEPT, "application/json")
|
|
.header(
|
|
header::AUTHORIZATION,
|
|
format!("Bearer {}", endpoint.api_key),
|
|
)
|
|
.header("MCP-Protocol-Version", MODERN_REVISION)
|
|
.header("Mcp-Method", "subscriptions/listen")
|
|
.json(&json!({
|
|
"jsonrpc": "2.0",
|
|
"id": 42,
|
|
"method": "subscriptions/listen",
|
|
"params": {
|
|
"notifications": { "promptsListChanged": true },
|
|
"_meta": SignalsEndpoint::modern_meta()
|
|
}
|
|
}))
|
|
.send()
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(without_sse.status(), reqwest::StatusCode::NOT_ACCEPTABLE);
|
|
}
|
|
|
|
/// AT-3.19-02: a missed notification never loses committed state — a legacy client re-initializes
|
|
/// (the retired session is a safe `404`) and reads the authoritative catalog, while the modern
|
|
/// stateless client recovers through `server/discover` and the list methods.
|
|
#[tokio::test]
|
|
async fn a_lost_notification_is_recovered_through_the_authoritative_methods() {
|
|
let endpoint = signals_endpoint().await;
|
|
|
|
// Modern recovery: the commit happens with no stream open at all.
|
|
endpoint.commit_resource_and_prompt_change().await;
|
|
let discover = endpoint.modern("server/discover", json!({})).await;
|
|
assert_eq!(
|
|
discover["result"]["capabilities"]["prompts"]["listChanged"],
|
|
json!(true)
|
|
);
|
|
assert_eq!(
|
|
discover["result"]["capabilities"]["resources"]["listChanged"],
|
|
json!(true)
|
|
);
|
|
let resources = endpoint.modern("resources/list", json!({})).await;
|
|
assert!(
|
|
resource_uris(&resources)
|
|
.iter()
|
|
.any(|uri| uri == &format!("crank://resources/{}", endpoint.notice.as_str())),
|
|
"the committed Resource is served to a client that missed the signal: {resources}"
|
|
);
|
|
|
|
// Legacy recovery: the negotiated session can be dropped, and the revision-correct answer is a
|
|
// safe `404` that makes the client re-initialize instead of resuming a stale stream.
|
|
let session = endpoint.legacy_session().await;
|
|
let mut stream = endpoint.legacy_stream(&session).await;
|
|
tokio::time::sleep(Duration::from_millis(1_500)).await;
|
|
|
|
let deleted = endpoint
|
|
.client
|
|
.delete(&endpoint.mcp_url)
|
|
.header(
|
|
header::AUTHORIZATION,
|
|
format!("Bearer {}", endpoint.api_key),
|
|
)
|
|
.header("MCP-Protocol-Version", LEGACY_REVISION)
|
|
.header("MCP-Session-Id", &session)
|
|
.send()
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(deleted.status(), reqwest::StatusCode::NO_CONTENT);
|
|
stream
|
|
.expect_silence(
|
|
Duration::from_millis(2_500),
|
|
"a signal on the retired session",
|
|
)
|
|
.await;
|
|
|
|
let stale_get = endpoint
|
|
.client
|
|
.get(&endpoint.mcp_url)
|
|
.header(header::ACCEPT, "text/event-stream")
|
|
.header(
|
|
header::AUTHORIZATION,
|
|
format!("Bearer {}", endpoint.api_key),
|
|
)
|
|
.header("MCP-Protocol-Version", LEGACY_REVISION)
|
|
.header("MCP-Session-Id", &session)
|
|
.send()
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(
|
|
stale_get.status(),
|
|
reqwest::StatusCode::NOT_FOUND,
|
|
"a retired session is never resumed"
|
|
);
|
|
|
|
let fresh = endpoint.legacy_session().await;
|
|
let prompts = endpoint.legacy(&fresh, "prompts/list", json!({})).await;
|
|
assert!(
|
|
prompt_names(&prompts).contains(&"extra".to_owned()),
|
|
"re-initialization serves the authoritative catalog: {prompts}"
|
|
);
|
|
}
|