feat(epic3): deliver the accepted Epic 3 scope through Story 3.17
CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
Recovery delivery of the accumulated, TL-accepted Epic 3 work that had never been
committed to Git (stories 3.6-3.17, see the crank board). Story 3.18 is not accepted
yet and is deliberately excluded: its logging surface, its capability registration,
its oracle projections and its tests are not part of this tree.
Accepted scope
- 3.6 typed static Resource Drafts; 3.7 publication and exact binding of static
Resource Versions; 3.8 MCP discovery/read and revocation of static Resources;
- 3.9 Resource import/export in API and UI plus TLS dependency maintenance;
3.10 REST-backed Resource templates; 3.11 shared REST read runtime and the MCP
revision/capability foundation;
- 3.12 parameterised Prompt Drafts with preview; 3.13 Prompt publication and exact
version binding to Agents; 3.14 MCP prompts; 3.15 Prompt import/export;
- 3.16 composite Prompts with published Resources (dependency content scan plus
dynamic read through the accepted 3.11 runtime, admin preview and MCP prompts/get);
- 3.17 bounded MCP completion suggestions from typed published schemas and the
resources/list admission fix for bound template publications.
Accepted evidence being reused (unchanged code paths)
- 3.16 candidate: core 7, admin-api 22, registry 4, mcp-server 4, UI 6; one final
`just verify` run 1651 passed / 0 failed / 2 ignored.
- 3.17 candidate: full run 1672 passed / 0 failed / 2 ignored, QA targeted reruns and
a real MCP Inspector 2.12.0 client smoke.
Delivery engineering in this commit
- CI: one event per change (feature branches are gated by their pull request, push
runs only on main), story events run the changed packages, the full workspace suite
stays the feature/release gate; no cache/sharding without a measured runner check.
- Release: the packaged archives, checksums and SBOM are now uploaded to the Gitea
release entry of the tag instead of dying with the runner workspace.
Not included on purpose: Story 3.18 work, build caches, runtime databases, local
credentials and scratch evidence.
Refs: crank kanban t_e39d7263; baseline 1b6db09bd1.
This commit is contained in:
1 parent
1b6db09bd1
commit
54ce770682
357 files changed
+117394
-5115
No files matched your search
@@ -0,0 +1,743 @@
|
||||
//! In-crate tests of `protocol::registry` (module path `protocol::registry::tests`).
|
||||
//!
|
||||
//! Kept as a `#[path]` module to stay inside the repository code-health caps (an inline test
|
||||
//! module may not exceed 500 lines and `registry.rs` may not exceed 1000 lines). The module path,
|
||||
//! and therefore the sanctioned selector
|
||||
//! `cargo test -p crank-community-mcp --lib protocol::registry::`, is identical to the inline
|
||||
//! module it replaces, and every test name is unchanged.
|
||||
|
||||
use super::*;
|
||||
use crate::protocol::{advertised_server_capabilities, dispatch_decision};
|
||||
use serde_json::json;
|
||||
|
||||
fn production_registry() -> CapabilityRegistry {
|
||||
CapabilityRegistry::new(CAPABILITY_DESCRIPTORS, METHOD_DESCRIPTORS)
|
||||
.expect("the static capability table is valid")
|
||||
}
|
||||
|
||||
fn inert_descriptor() -> CapabilityIdDescriptor {
|
||||
CapabilityIdDescriptor {
|
||||
id: CapabilityId::InertTest,
|
||||
roster: Roster::Server,
|
||||
kind: Kind::Capability,
|
||||
extension: None,
|
||||
deprecated: None,
|
||||
sub_features: FeatureSet(&["enabled"]),
|
||||
advertised: Some(("inert_test_capability", &[("enabled", true)])),
|
||||
revisions: MODERN_AND_LEGACY,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn static_registration_is_unique_and_advertises_only_the_registered_capability() {
|
||||
let registry = production_registry();
|
||||
for revision in [MODERN_PROTOCOL_VERSION, LEGACY_PROTOCOL_VERSION] {
|
||||
assert_eq!(
|
||||
registry.advertised_capabilities(revision),
|
||||
json!({
|
||||
"completions": {},
|
||||
"prompts": {"listChanged": false},
|
||||
"resources": {"listChanged": false, "subscribe": false},
|
||||
"tools": {"listChanged": false}
|
||||
}),
|
||||
"the registered advertisement must be the same reviewed object in {revision}"
|
||||
);
|
||||
assert_eq!(
|
||||
advertised_server_capabilities(revision),
|
||||
json!({
|
||||
"completions": {},
|
||||
"prompts": {"listChanged": false},
|
||||
"resources": {"listChanged": false, "subscribe": false},
|
||||
"tools": {"listChanged": false}
|
||||
}),
|
||||
"the production advertisement entry point must serve {revision}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn advertisement_and_dispatch_share_one_eligibility_predicate() {
|
||||
// F6: for every capability that is *advertised by design* advertisement and dispatch are the
|
||||
// same predicate, and dispatch eligibility follows the registered revision window. The only
|
||||
// registrations that are dispatchable without being advertised are the explicit method-kind
|
||||
// ones (`ping`, `server/discover`, the legacy lifecycle).
|
||||
let registry = production_registry();
|
||||
for descriptor in ®istry.capabilities {
|
||||
let advertised_by_design = matches!(descriptor.kind, Kind::Capability | Kind::Extension);
|
||||
for revision in [MODERN_PROTOCOL_VERSION, LEGACY_PROTOCOL_VERSION] {
|
||||
let eligible = registry.dispatchable_for(descriptor.id, revision);
|
||||
assert_eq!(
|
||||
eligible,
|
||||
descriptor.revisions.contains(&revision),
|
||||
"dispatch eligibility must follow the revision window of {:?}",
|
||||
descriptor.id
|
||||
);
|
||||
if advertised_by_design {
|
||||
assert_eq!(
|
||||
registry.advertise_for(descriptor.id, revision),
|
||||
eligible,
|
||||
"advertisement and dispatch drifted for {:?} in {revision}",
|
||||
descriptor.id
|
||||
);
|
||||
} else {
|
||||
assert!(
|
||||
!registry.advertise_for(descriptor.id, revision),
|
||||
"a dispatch-only registration {:?} must never be advertised in {revision}",
|
||||
descriptor.id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert!(registry.advertise_for(CapabilityId::Tools, MODERN_PROTOCOL_VERSION));
|
||||
assert!(registry.dispatchable_for(CapabilityId::Tools, MODERN_PROTOCOL_VERSION));
|
||||
assert!(registry.advertise_for(CapabilityId::Tools, LEGACY_PROTOCOL_VERSION));
|
||||
// `ping` is dispatched in both eras but advertised nowhere: it declares no fragment by
|
||||
// contract, and the advertisement object carries no `ping` key.
|
||||
for revision in [MODERN_PROTOCOL_VERSION, LEGACY_PROTOCOL_VERSION] {
|
||||
assert!(registry.dispatchable_for(CapabilityId::Ping, revision));
|
||||
assert!(!registry.advertise_for(CapabilityId::Ping, revision));
|
||||
assert!(
|
||||
registry
|
||||
.advertised_capabilities(revision)
|
||||
.as_object()
|
||||
.is_some_and(|object| !object.contains_key("ping")),
|
||||
"the advertisement of {revision} must not grow a `ping` key"
|
||||
);
|
||||
}
|
||||
assert!(registry.dispatchable_for(CapabilityId::Discovery, MODERN_PROTOCOL_VERSION));
|
||||
assert!(!registry.dispatchable_for(CapabilityId::Discovery, LEGACY_PROTOCOL_VERSION));
|
||||
assert!(registry.dispatchable_for(CapabilityId::LegacyLifecycle, LEGACY_PROTOCOL_VERSION));
|
||||
assert!(!registry.dispatchable_for(CapabilityId::LegacyLifecycle, MODERN_PROTOCOL_VERSION));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_fragment_less_advertisable_capability_is_rejected_at_registration() {
|
||||
// F6: without this invariant a capability-owned method could stay `Allowed` while its
|
||||
// capability is advertised nowhere, which is exactly the drift the reviewer measured.
|
||||
let mut capabilities = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
capabilities.push(CapabilityIdDescriptor {
|
||||
id: CapabilityId::InertTest,
|
||||
roster: Roster::Server,
|
||||
kind: Kind::Capability,
|
||||
extension: None,
|
||||
deprecated: None,
|
||||
sub_features: FeatureSet(&[]),
|
||||
advertised: None,
|
||||
revisions: MODERN_AND_LEGACY,
|
||||
});
|
||||
assert_eq!(
|
||||
CapabilityRegistry::new(&capabilities, METHOD_DESCRIPTORS).err(),
|
||||
Some(RegistrationError::MissingAdvertisement {
|
||||
capability: CapabilityId::InertTest
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dispatch_only_registration_cannot_claim_an_advertisement_fragment() {
|
||||
let mut capabilities = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
capabilities.push(CapabilityIdDescriptor {
|
||||
id: CapabilityId::InertTest,
|
||||
roster: Roster::Server,
|
||||
kind: Kind::Method,
|
||||
extension: None,
|
||||
deprecated: None,
|
||||
sub_features: FeatureSet(&[]),
|
||||
advertised: Some(("inert_method_advertisement", &[("enabled", true)])),
|
||||
revisions: MODERN_AND_LEGACY,
|
||||
});
|
||||
assert_eq!(
|
||||
CapabilityRegistry::new(&capabilities, METHOD_DESCRIPTORS).err(),
|
||||
Some(RegistrationError::MisdeclaredAdvertisement {
|
||||
capability: CapabilityId::InertTest
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_client_roster_declaration_never_dispatches_its_methods() {
|
||||
const INERT_METHOD: MethodDescriptor = MethodDescriptor {
|
||||
name: "inert/client-only",
|
||||
capability: CapabilityId::InertTest,
|
||||
kind: Kind::Method,
|
||||
required_headers: HEADERS_NONE,
|
||||
handler: MethodHandler::Ping,
|
||||
};
|
||||
let mut capabilities = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
capabilities.push(CapabilityIdDescriptor {
|
||||
id: CapabilityId::InertTest,
|
||||
roster: Roster::Client,
|
||||
kind: Kind::Capability,
|
||||
extension: None,
|
||||
deprecated: None,
|
||||
sub_features: FeatureSet(&["enabled"]),
|
||||
advertised: Some(("inert_client_capability", &[("enabled", true)])),
|
||||
revisions: MODERN_AND_LEGACY,
|
||||
});
|
||||
let mut methods = METHOD_DESCRIPTORS.to_vec();
|
||||
methods.push(INERT_METHOD);
|
||||
let registry =
|
||||
CapabilityRegistry::new(&capabilities, &methods).expect("a client declaration registers");
|
||||
|
||||
assert!(!registry.advertise_for(CapabilityId::InertTest, MODERN_PROTOCOL_VERSION));
|
||||
assert!(!registry.dispatchable_for(CapabilityId::InertTest, MODERN_PROTOCOL_VERSION));
|
||||
assert_eq!(
|
||||
registry.dispatch_decision(INERT_METHOD.name, MODERN_PROTOCOL_VERSION),
|
||||
DispatchDecision::WrongEra {
|
||||
handler: MethodHandler::Ping,
|
||||
kind: Kind::Method,
|
||||
},
|
||||
"a client-side declaration must never be Allowed for a server dispatch"
|
||||
);
|
||||
assert!(
|
||||
registry
|
||||
.advertised_capabilities(MODERN_PROTOCOL_VERSION)
|
||||
.as_object()
|
||||
.is_some_and(|object| !object.contains_key("inert_client_capability")),
|
||||
"a client declaration is never advertised by this server"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_method_registration_is_rejected() {
|
||||
let duplicate = [
|
||||
METHOD_DESCRIPTORS[0],
|
||||
MethodDescriptor {
|
||||
name: METHOD_DESCRIPTORS[0].name,
|
||||
capability: METHOD_DESCRIPTORS[0].capability,
|
||||
kind: METHOD_DESCRIPTORS[0].kind,
|
||||
required_headers: HEADERS_NONE,
|
||||
handler: MethodHandler::Discover,
|
||||
},
|
||||
];
|
||||
assert_eq!(
|
||||
CapabilityRegistry::new(CAPABILITY_DESCRIPTORS, &duplicate).unwrap_err(),
|
||||
RegistrationError::DuplicateMethod { name: "tools/list" }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conflicting_method_registration_is_rejected() {
|
||||
let conflicting = [
|
||||
METHOD_DESCRIPTORS[0],
|
||||
MethodDescriptor {
|
||||
name: METHOD_DESCRIPTORS[0].name,
|
||||
capability: CapabilityId::Ping,
|
||||
kind: METHOD_DESCRIPTORS[0].kind,
|
||||
required_headers: HEADERS_NONE,
|
||||
handler: MethodHandler::Ping,
|
||||
},
|
||||
];
|
||||
assert_eq!(
|
||||
CapabilityRegistry::new(CAPABILITY_DESCRIPTORS, &conflicting).unwrap_err(),
|
||||
RegistrationError::ConflictingMethod { name: "tools/list" }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_capability_registration_is_rejected() {
|
||||
let mut duplicated = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
duplicated.push(CAPABILITY_DESCRIPTORS[0]);
|
||||
assert_eq!(
|
||||
CapabilityRegistry::new(&duplicated, METHOD_DESCRIPTORS).unwrap_err(),
|
||||
RegistrationError::DuplicateCapability {
|
||||
capability: CapabilityId::Tools
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_inert_test_descriptor_changes_both_projections_and_is_never_registered_in_production() {
|
||||
let without = production_registry();
|
||||
let mut with_capabilities = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
with_capabilities.push(inert_descriptor());
|
||||
let with = CapabilityRegistry::new(&with_capabilities, METHOD_DESCRIPTORS)
|
||||
.expect("the inert descriptor is a valid capability entry");
|
||||
|
||||
assert_eq!(
|
||||
without.advertised_capabilities(MODERN_PROTOCOL_VERSION),
|
||||
json!({
|
||||
"completions": {},
|
||||
"prompts": {"listChanged": false},
|
||||
"resources": {"listChanged": false, "subscribe": false},
|
||||
"tools": {"listChanged": false}
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
with.advertised_capabilities(MODERN_PROTOCOL_VERSION),
|
||||
json!({
|
||||
"inert_test_capability": {"enabled": true},
|
||||
"completions": {},
|
||||
"prompts": {"listChanged": false},
|
||||
"resources": {"listChanged": false, "subscribe": false},
|
||||
"tools": {"listChanged": false}
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
with.advertised_capabilities(LEGACY_PROTOCOL_VERSION),
|
||||
json!({
|
||||
"inert_test_capability": {"enabled": true},
|
||||
"completions": {},
|
||||
"prompts": {"listChanged": false},
|
||||
"resources": {"listChanged": false, "subscribe": false},
|
||||
"tools": {"listChanged": false}
|
||||
})
|
||||
);
|
||||
|
||||
// Both projections move together: the inert capability is advertisable *and* dispatchable.
|
||||
assert!(!without.advertise_for(CapabilityId::InertTest, MODERN_PROTOCOL_VERSION));
|
||||
assert!(with.advertise_for(CapabilityId::InertTest, MODERN_PROTOCOL_VERSION));
|
||||
assert_eq!(
|
||||
with.advertise_for(CapabilityId::InertTest, MODERN_PROTOCOL_VERSION),
|
||||
with.dispatchable_for(CapabilityId::InertTest, MODERN_PROTOCOL_VERSION)
|
||||
);
|
||||
|
||||
// The inert descriptor stays a test-only object: it is absent from the production table.
|
||||
assert!(
|
||||
CAPABILITY_DESCRIPTORS
|
||||
.iter()
|
||||
.all(|descriptor| descriptor.id != CapabilityId::InertTest)
|
||||
);
|
||||
let _ = with.methods();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_advertised_revision_window_is_exactly_the_two_approved_revisions() {
|
||||
let registry = production_registry();
|
||||
for descriptor in ®istry.capabilities {
|
||||
for revision in descriptor.revisions {
|
||||
assert!(
|
||||
[MODERN_PROTOCOL_VERSION, LEGACY_PROTOCOL_VERSION].contains(revision),
|
||||
"capability {:?} declares an unapproved revision {revision}",
|
||||
descriptor.id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Story 3.1 #8 remaining-foundation regressions (R6 era window, R7 advertisement conflict) --
|
||||
|
||||
/// A test-only descriptor that declares no revision at all, so every revision is ineligible.
|
||||
fn empty_window_descriptor() -> CapabilityIdDescriptor {
|
||||
CapabilityIdDescriptor {
|
||||
id: CapabilityId::InertTest,
|
||||
roster: Roster::Server,
|
||||
kind: Kind::Capability,
|
||||
extension: None,
|
||||
deprecated: None,
|
||||
sub_features: FeatureSet(&["enabled"]),
|
||||
advertised: Some(("inert_empty_window_capability", &[("enabled", true)])),
|
||||
revisions: &[],
|
||||
}
|
||||
}
|
||||
|
||||
/// A test-only descriptor that claims the top-level advertisement key already owned by `Tools`.
|
||||
fn conflicting_advertisement_descriptor() -> CapabilityIdDescriptor {
|
||||
CapabilityIdDescriptor {
|
||||
id: CapabilityId::InertTest,
|
||||
roster: Roster::Server,
|
||||
kind: Kind::Capability,
|
||||
extension: None,
|
||||
deprecated: None,
|
||||
sub_features: FeatureSet(&["listChanged"]),
|
||||
advertised: Some(("tools", &[("listChanged", true)])),
|
||||
revisions: MODERN_AND_LEGACY,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_revision_window_is_not_vacuously_advertisable() {
|
||||
// R6 (empty-window half): `revisions: &[]` must not make a capability eligible for every
|
||||
// revision through a vacuously true `all()`.
|
||||
let mut capabilities = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
capabilities.push(empty_window_descriptor());
|
||||
let registry = match CapabilityRegistry::new(&capabilities, METHOD_DESCRIPTORS) {
|
||||
Ok(registry) => registry,
|
||||
// Rejecting a revision-less capability at registration is an equivalent, stronger
|
||||
// resolution of the same defect (a typed error, never a panic).
|
||||
Err(_rejected_at_registration) => return,
|
||||
};
|
||||
|
||||
assert!(
|
||||
!registry.advertise_for(CapabilityId::InertTest, MODERN_PROTOCOL_VERSION),
|
||||
"a capability with an empty revision window is eligible in no revision"
|
||||
);
|
||||
assert!(
|
||||
!registry.advertise_for(CapabilityId::InertTest, LEGACY_PROTOCOL_VERSION),
|
||||
"a capability with an empty revision window is eligible in no revision"
|
||||
);
|
||||
for revision in [MODERN_PROTOCOL_VERSION, LEGACY_PROTOCOL_VERSION] {
|
||||
let advertised = registry.advertised_capabilities(revision);
|
||||
assert!(
|
||||
advertised
|
||||
.as_object()
|
||||
.is_some_and(|object| !object.contains_key("inert_empty_window_capability")),
|
||||
"an empty revision window must not be advertised in {revision}: {advertised}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_conflicting_advertisement_key_is_rejected_not_silently_overwritten() {
|
||||
// R7: the constructor validates duplicate capability ids and duplicate method names but not
|
||||
// a conflicting top-level advertisement key, so `Value::Object::insert` silently overwrites.
|
||||
let mut capabilities = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
capabilities.push(conflicting_advertisement_descriptor());
|
||||
let outcome = CapabilityRegistry::new(&capabilities, METHOD_DESCRIPTORS);
|
||||
assert_eq!(
|
||||
outcome.err(),
|
||||
Some(RegistrationError::ConflictingAdvertisement { key: "tools" }),
|
||||
"two capabilities claiming the same top-level advertisement key must be rejected with a \
|
||||
typed registration error instead of being silently overwritten"
|
||||
);
|
||||
}
|
||||
|
||||
// --- R6: the advertisement is indexed by the requested era, not by every declared revision ------
|
||||
|
||||
/// A test-only server capability available in the modern revision only.
|
||||
fn modern_only_descriptor() -> CapabilityIdDescriptor {
|
||||
CapabilityIdDescriptor {
|
||||
id: CapabilityId::InertTest,
|
||||
roster: Roster::Server,
|
||||
kind: Kind::Capability,
|
||||
extension: None,
|
||||
deprecated: None,
|
||||
sub_features: FeatureSet(&["enabled"]),
|
||||
advertised: Some(("inert_modern_capability", &[("enabled", true)])),
|
||||
revisions: MODERN_ONLY,
|
||||
}
|
||||
}
|
||||
|
||||
/// A test-only server capability available in the legacy revision only.
|
||||
fn legacy_only_descriptor() -> CapabilityIdDescriptor {
|
||||
CapabilityIdDescriptor {
|
||||
id: CapabilityId::InertTest,
|
||||
roster: Roster::Server,
|
||||
kind: Kind::Capability,
|
||||
extension: None,
|
||||
deprecated: None,
|
||||
sub_features: FeatureSet(&["enabled"]),
|
||||
advertised: Some(("inert_legacy_capability", &[("enabled", true)])),
|
||||
revisions: LEGACY_ONLY,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_single_era_descriptor_never_leaks_into_the_other_era_advertisement() {
|
||||
for (inert, this_era, other_era, key) in [
|
||||
(
|
||||
modern_only_descriptor(),
|
||||
MODERN_PROTOCOL_VERSION,
|
||||
LEGACY_PROTOCOL_VERSION,
|
||||
"inert_modern_capability",
|
||||
),
|
||||
(
|
||||
legacy_only_descriptor(),
|
||||
LEGACY_PROTOCOL_VERSION,
|
||||
MODERN_PROTOCOL_VERSION,
|
||||
"inert_legacy_capability",
|
||||
),
|
||||
] {
|
||||
let mut capabilities = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
capabilities.push(inert);
|
||||
let registry = CapabilityRegistry::new(&capabilities, METHOD_DESCRIPTORS)
|
||||
.expect("a single-era inert capability is a valid registration");
|
||||
|
||||
let this_era_advertisement = registry.advertised_capabilities(this_era);
|
||||
assert!(
|
||||
this_era_advertisement
|
||||
.as_object()
|
||||
.is_some_and(|object| object.contains_key(key)),
|
||||
"{key} must be advertised in its own era {this_era}: {this_era_advertisement}"
|
||||
);
|
||||
let other_era_advertisement = registry.advertised_capabilities(other_era);
|
||||
assert!(
|
||||
other_era_advertisement
|
||||
.as_object()
|
||||
.is_some_and(|object| !object.contains_key(key)),
|
||||
"{key} must never leak into {other_era}: {other_era_advertisement}"
|
||||
);
|
||||
assert_eq!(
|
||||
other_era_advertisement,
|
||||
json!({
|
||||
"completions": {},
|
||||
"prompts": {"listChanged": false},
|
||||
"resources": {"listChanged": false, "subscribe": false},
|
||||
"tools": {"listChanged": false}
|
||||
}),
|
||||
"the other era advertisement stays the reviewed object"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// --- R5: the router's dispatch decision is the registration, never a handler list --------------
|
||||
|
||||
#[test]
|
||||
fn the_production_registration_routes_every_declared_method_in_its_own_era() {
|
||||
for (method, era, handler, kind) in [
|
||||
(
|
||||
"tools/list",
|
||||
MODERN_PROTOCOL_VERSION,
|
||||
MethodHandler::ToolList,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"tools/call",
|
||||
MODERN_PROTOCOL_VERSION,
|
||||
MethodHandler::ToolCall,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"tools/list",
|
||||
LEGACY_PROTOCOL_VERSION,
|
||||
MethodHandler::ToolList,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"tools/call",
|
||||
LEGACY_PROTOCOL_VERSION,
|
||||
MethodHandler::ToolCall,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"ping",
|
||||
MODERN_PROTOCOL_VERSION,
|
||||
MethodHandler::Ping,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"resources/templates/list",
|
||||
MODERN_PROTOCOL_VERSION,
|
||||
MethodHandler::ResourceTemplateList,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"resources/templates/list",
|
||||
LEGACY_PROTOCOL_VERSION,
|
||||
MethodHandler::ResourceTemplateList,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"ping",
|
||||
LEGACY_PROTOCOL_VERSION,
|
||||
MethodHandler::Ping,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"server/discover",
|
||||
MODERN_PROTOCOL_VERSION,
|
||||
MethodHandler::Discover,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"initialize",
|
||||
LEGACY_PROTOCOL_VERSION,
|
||||
MethodHandler::Lifecycle,
|
||||
Kind::Method,
|
||||
),
|
||||
(
|
||||
"notifications/initialized",
|
||||
LEGACY_PROTOCOL_VERSION,
|
||||
MethodHandler::Lifecycle,
|
||||
Kind::Notification,
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
dispatch_decision(method, era),
|
||||
DispatchDecision::Allowed { handler, kind },
|
||||
"{method} must route to its registered handler with its registered kind in {era}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_lifecycle_dispatch_decision_carries_the_registered_method_kind() {
|
||||
// G2: `initialize` (a request) and `notifications/initialized` (a notification) share the
|
||||
// Lifecycle handler but are not interchangeable. The decision must carry the registered kind, or
|
||||
// the adapter can only tell them apart by the envelope shape and would serve one as the other.
|
||||
assert_eq!(
|
||||
dispatch_decision("initialize", LEGACY_PROTOCOL_VERSION),
|
||||
DispatchDecision::Allowed {
|
||||
handler: MethodHandler::Lifecycle,
|
||||
kind: Kind::Method,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
dispatch_decision("notifications/initialized", LEGACY_PROTOCOL_VERSION),
|
||||
DispatchDecision::Allowed {
|
||||
handler: MethodHandler::Lifecycle,
|
||||
kind: Kind::Notification,
|
||||
}
|
||||
);
|
||||
assert_ne!(
|
||||
dispatch_decision("initialize", LEGACY_PROTOCOL_VERSION),
|
||||
dispatch_decision("notifications/initialized", LEGACY_PROTOCOL_VERSION),
|
||||
"the two lifecycle wire names must never collapse into the same dispatch decision"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_method_of_the_other_era_is_a_wrong_era_decision() {
|
||||
assert_eq!(
|
||||
dispatch_decision("server/discover", LEGACY_PROTOCOL_VERSION),
|
||||
DispatchDecision::WrongEra {
|
||||
handler: MethodHandler::Discover,
|
||||
kind: Kind::Method,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
dispatch_decision("initialize", MODERN_PROTOCOL_VERSION),
|
||||
DispatchDecision::WrongEra {
|
||||
handler: MethodHandler::Lifecycle,
|
||||
kind: Kind::Method,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
dispatch_decision("notifications/initialized", MODERN_PROTOCOL_VERSION),
|
||||
DispatchDecision::WrongEra {
|
||||
handler: MethodHandler::Lifecycle,
|
||||
kind: Kind::Notification,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unregistered_method_has_no_handler_and_no_service() {
|
||||
let registry = production_registry();
|
||||
for method in [
|
||||
"resources/subscribe",
|
||||
"logging/setLogLevel",
|
||||
"tasks/list",
|
||||
"frobnicate",
|
||||
] {
|
||||
for revision in [MODERN_PROTOCOL_VERSION, LEGACY_PROTOCOL_VERSION] {
|
||||
assert_eq!(
|
||||
registry.dispatch_decision(method, revision),
|
||||
DispatchDecision::Unregistered,
|
||||
"{method} is not registered and must never reach a handler in {revision}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn story317_completion_is_advertised_and_dispatchable_in_both_revisions() {
|
||||
let registry = production_registry();
|
||||
for revision in [MODERN_PROTOCOL_VERSION, LEGACY_PROTOCOL_VERSION] {
|
||||
assert!(
|
||||
registry.advertise_for(CapabilityId::Completions, revision),
|
||||
"the implemented completion surface must be advertised in {revision}"
|
||||
);
|
||||
assert_eq!(
|
||||
registry.dispatch_decision("completion/complete", revision),
|
||||
DispatchDecision::Allowed {
|
||||
handler: MethodHandler::Completion,
|
||||
kind: Kind::Method,
|
||||
},
|
||||
"`completion/complete` must reach its handler in {revision}"
|
||||
);
|
||||
assert_eq!(
|
||||
registry.advertised_capabilities(revision)["completions"],
|
||||
json!({}),
|
||||
"the pinned advertisement is an empty `completions` object in {revision}"
|
||||
);
|
||||
}
|
||||
let descriptor = METHOD_DESCRIPTORS
|
||||
.iter()
|
||||
.find(|descriptor| descriptor.name == "completion/complete")
|
||||
.expect("completion/complete is a registered method");
|
||||
assert_eq!(
|
||||
descriptor.required_headers.0,
|
||||
&["Mcp-Method"],
|
||||
"the `ref` union declares no single `Mcp-Name` value for the modern header rule"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adding_and_removing_a_method_descriptor_changes_the_dispatch_decision() {
|
||||
// The inert capability owns one inert method. With the method descriptor registered the
|
||||
// router routes it; without it the same request has no handler at all - the decision is the
|
||||
// registration, not a fixed list inside the router.
|
||||
const INERT_METHOD: MethodDescriptor = MethodDescriptor {
|
||||
name: "inert/echo",
|
||||
capability: CapabilityId::InertTest,
|
||||
kind: Kind::Method,
|
||||
required_headers: HEADERS_NONE,
|
||||
handler: MethodHandler::Ping,
|
||||
};
|
||||
let mut capabilities = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
capabilities.push(inert_descriptor());
|
||||
let mut methods = METHOD_DESCRIPTORS.to_vec();
|
||||
|
||||
let without = CapabilityRegistry::new(&capabilities, &methods)
|
||||
.expect("the production method table stays valid");
|
||||
assert_eq!(
|
||||
without.dispatch_decision(INERT_METHOD.name, MODERN_PROTOCOL_VERSION),
|
||||
DispatchDecision::Unregistered
|
||||
);
|
||||
|
||||
methods.push(INERT_METHOD);
|
||||
let with = CapabilityRegistry::new(&capabilities, &methods)
|
||||
.expect("the inert method descriptor is a valid registration");
|
||||
assert_eq!(
|
||||
with.dispatch_decision(INERT_METHOD.name, MODERN_PROTOCOL_VERSION),
|
||||
DispatchDecision::Allowed {
|
||||
handler: MethodHandler::Ping,
|
||||
kind: Kind::Method,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
with.dispatch_decision(INERT_METHOD.name, LEGACY_PROTOCOL_VERSION),
|
||||
DispatchDecision::Allowed {
|
||||
handler: MethodHandler::Ping,
|
||||
kind: Kind::Method,
|
||||
}
|
||||
);
|
||||
|
||||
// The advertisement projection is unaffected by a method descriptor: only capability
|
||||
// declarations advertise.
|
||||
assert_eq!(
|
||||
with.advertised_capabilities(MODERN_PROTOCOL_VERSION),
|
||||
json!({
|
||||
"inert_test_capability": {"enabled": true},
|
||||
"completions": {},
|
||||
"prompts": {"listChanged": false},
|
||||
"resources": {"listChanged": false, "subscribe": false},
|
||||
"tools": {"listChanged": false}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_method_of_an_unavailable_capability_is_never_dispatched() {
|
||||
// The inert capability is modern-only; its method must not be reachable in the legacy era.
|
||||
const INERT_METHOD: MethodDescriptor = MethodDescriptor {
|
||||
name: "inert/echo",
|
||||
capability: CapabilityId::InertTest,
|
||||
kind: Kind::Method,
|
||||
required_headers: HEADERS_NONE,
|
||||
handler: MethodHandler::Ping,
|
||||
};
|
||||
let mut capabilities = CAPABILITY_DESCRIPTORS.to_vec();
|
||||
capabilities.push(modern_only_descriptor());
|
||||
let mut methods = METHOD_DESCRIPTORS.to_vec();
|
||||
methods.push(INERT_METHOD);
|
||||
let registry =
|
||||
CapabilityRegistry::new(&capabilities, &methods).expect("valid inert registration");
|
||||
|
||||
assert_eq!(
|
||||
registry.dispatch_decision(INERT_METHOD.name, MODERN_PROTOCOL_VERSION),
|
||||
DispatchDecision::Allowed {
|
||||
handler: MethodHandler::Ping,
|
||||
kind: Kind::Method,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
registry.dispatch_decision(INERT_METHOD.name, LEGACY_PROTOCOL_VERSION),
|
||||
DispatchDecision::WrongEra {
|
||||
handler: MethodHandler::Ping,
|
||||
kind: Kind::Method,
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user