From 44774883a035defad9f6f85a0e3af64c477d017f Mon Sep 17 00:00:00 2001 From: bsodfather Date: Mon, 26 Oct 2026 17:03:01 +0000 Subject: [PATCH] =?UTF-8?q?fix(epic3):=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20Tools-=D1=81=D0=B8=D0=B3=D0=BD=D0=B0=D0=BB?= =?UTF-8?q?=20=D0=B8=D0=B7=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D1=81?= =?UTF-8?q?=D0=BA=D0=BE=D0=B9=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20tools/list=20(Story=203.5,=20FR-14)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QA F1: CatalogFingerprint сравнивал только Tool-bindings, а tools/list строится из catalog_tool_definitions, которая ещё зависит от tool_selection_policy (mode, groups, search.max_results); в Search-режиме отдаваемый список вообще не зависит от bindings. Из-за этого commit, меняющий только политику, не порождал notifications/tools/list_changed (клиент оставался со stale-каталогом), а binding-only commit в Search порождал ложный сигнал. Теперь Tools-часть отпечатка — канонизированные определения, которые реально отдаёт tools/list (отсортированы, чтобы порядок чтения не был ложным изменением): сигнал есть ровно тогда, когда меняется видимая клиенту проекция. ATDD: новый сценарий на обеих ревизиях — policy-only commit (Direct -> Search) даёт ровно один Tools-кадр и авторитетный tools/list с search_tools/call_tool, а последующий binding-only commit в Search-режиме не сигналит. Юнит-оракулы переведены на реальную проекцию: policy-only change, невидимое поле политики, version bump с идентичным определением и binding change в Search-режиме — silent. --- .../tests/integration/mcp_signals.rs | 72 +++- .../integration/mcp_signals/scenarios.rs | 93 +++++ .../src/protocol/signals.rs | 74 ++-- .../src/protocol/signals_tests.rs | 354 +++++++++++++++--- 4 files changed, 483 insertions(+), 110 deletions(-) diff --git a/apps/mcp-server/tests/integration/mcp_signals.rs b/apps/mcp-server/tests/integration/mcp_signals.rs index 2af6e2a..b1d6751 100644 --- a/apps/mcp-server/tests/integration/mcp_signals.rs +++ b/apps/mcp-server/tests/integration/mcp_signals.rs @@ -20,7 +20,8 @@ use std::{ use axum::http::header; use crank_artifacts::ArtifactStore; use crank_core::{ - Agent, AgentId, AgentStatus, AgentVersion, PlatformApiKeyScope, ToolSelectionPolicy, + Agent, AgentId, AgentStatus, AgentVersion, PlatformApiKeyScope, ToolAccessMode, ToolGroup, + ToolSearchSettings, ToolSelectionPolicy, ids::{PromptId, ResourceId}, prompt::{PromptDefinition, PromptSensitivity}, }; @@ -257,6 +258,26 @@ impl SignalsEndpoint { tool_bindings: &[crank_core::AgentOperationBinding], resource_bindings: &[AgentResourceBinding], prompt_bindings: &[AgentPromptBinding], + ) { + self.configure_draft_with_policy( + version, + tool_bindings, + &ToolSelectionPolicy::default(), + resource_bindings, + prompt_bindings, + ) + .await; + } + + /// The same transition with an explicit Tool selection policy (Story 3.5: the policy is part of + /// the served `tools/list` projection). + async fn configure_draft_with_policy( + &self, + version: u32, + tool_bindings: &[crank_core::AgentOperationBinding], + tool_selection_policy: &ToolSelectionPolicy, + resource_bindings: &[AgentResourceBinding], + prompt_bindings: &[AgentPromptBinding], ) { self.registry .save_agent_catalog_config_editable_with_prompts( @@ -265,7 +286,7 @@ impl SignalsEndpoint { agent_id: &self.agent_id, agent_version: version, bindings: tool_bindings, - tool_selection_policy: &ToolSelectionPolicy::default(), + tool_selection_policy, resource_bindings, expected_state: None, }, @@ -429,6 +450,53 @@ impl SignalsEndpoint { self.publish_version(version).await; } + /// The search-mode Tool selection policy of this Agent: one group over the bound Tool. + fn search_policy(&self) -> ToolSelectionPolicy { + ToolSelectionPolicy { + mode: ToolAccessMode::Search, + groups: vec![ToolGroup { + id: "crm".to_owned(), + name: "CRM".to_owned(), + description: "CRM operations".to_owned(), + tool_names: vec![self.operation.name.clone()], + }], + search: ToolSearchSettings::default(), + } + } + + /// A commit that changes only the Tool selection policy: same Tool, Resource and Prompt + /// bindings, direct mode -> search mode. The served `tools/list` changes from the bound Tool to + /// `search_tools`/`call_tool`, so this is a visible Tool catalog change. + async fn commit_policy_only_change(&self) { + let version = self.next_draft_version().await; + self.open_draft(version).await; + self.configure_draft_with_policy( + version, + &self.tool_bindings(), + &self.search_policy(), + &[], + &self.base_prompts(), + ) + .await; + self.publish_version(version).await; + } + + /// A search-mode commit that only adds a Tool binding: `tools/list` still serves exactly + /// `search_tools`/`call_tool`, so it must not announce a Tools change. + async fn commit_search_mode_binding_change(&self) { + let version = self.next_draft_version().await; + self.open_draft(version).await; + self.configure_draft_with_policy( + version, + &self.both_tool_bindings(), + &self.search_policy(), + &[], + &self.base_prompts(), + ) + .await; + self.publish_version(version).await; + } + /// Publish an independent Agent of the same workspace, bound to the first fixture operation, and /// return its read-only MCP client key. async fn publish_other_agent(&self, slug: &str) -> String { diff --git a/apps/mcp-server/tests/integration/mcp_signals/scenarios.rs b/apps/mcp-server/tests/integration/mcp_signals/scenarios.rs index 2f21d54..b3a133b 100644 --- a/apps/mcp-server/tests/integration/mcp_signals/scenarios.rs +++ b/apps/mcp-server/tests/integration/mcp_signals/scenarios.rs @@ -621,6 +621,99 @@ async fn legacy_stream_announces_a_committed_tools_change_and_never_another_agen ); } +/// AT-3.5-04: the Tools signal follows the same projection `tools/list` serves, so a committed +/// publication that only changes the Tool selection policy is announced on both revisions, while a +/// committed binding change that leaves `tools/list` unchanged is silent. +#[tokio::test] +async fn a_policy_only_commit_is_announced_on_both_revisions_and_an_invisible_change_is_silent() { + let endpoint = signals_endpoint().await; + let direct_projection = vec!["crm_create_lead".to_owned()]; + // `tool_names` sorts the served page. + let search_projection = vec!["call_tool".to_owned(), "search_tools".to_owned()]; + + // Both revisions negotiate the Tools signal and take their baseline before anything can arrive. + let mut modern = endpoint + .listen(json!(61), json!({ "toolsListChanged": true })) + .await; + let acknowledgement = modern.expect_frame("the Tools acknowledgment").await; + assert_eq!(acknowledgement["method"], SUBSCRIPTIONS_ACKNOWLEDGED); + assert_eq!( + acknowledgement["params"]["notifications"], + json!({ "toolsListChanged": true }) + ); + let session = endpoint.legacy_session().await; + let mut legacy = endpoint.legacy_stream(&session).await; + tokio::time::sleep(Duration::from_millis(1_500)).await; + + // The served projection before the commit is the direct-mode binding itself. + assert_eq!( + tool_names(&endpoint.modern("tools/list", json!({})).await), + direct_projection + ); + + // A policy-only commit: identical Tool/Resource/Prompt bindings, direct -> search mode. The + // served list changes, so each negotiated stream receives exactly one Tools frame. + endpoint.commit_policy_only_change().await; + let modern_frame = modern + .expect_frame("the committed Tools list-change signal (modern)") + .await; + assert_eq!(modern_frame["method"], TOOL_LIST_CHANGED); + assert_eq!( + modern_frame["params"]["_meta"][SUBSCRIPTION_ID_KEY], + json!(61) + ); + let legacy_frame = legacy + .expect_frame("the committed Tools list-change signal (legacy)") + .await; + assert_eq!(legacy_frame["method"], TOOL_LIST_CHANGED); + assert!( + legacy_frame.get("params").is_none(), + "a legacy list-change notification carries no parameters: {legacy_frame}" + ); + modern + .expect_silence( + Duration::from_millis(2_500), + "a repeated modern Tools signal", + ) + .await; + legacy + .expect_silence( + Duration::from_millis(2_500), + "a repeated legacy Tools signal", + ) + .await; + + // `tools/list` is authoritative for the new projection on both revisions. + assert_eq!( + tool_names(&endpoint.modern("tools/list", json!({})).await), + search_projection + ); + assert_eq!( + tool_names(&endpoint.legacy(&session, "tools/list", json!({})).await), + search_projection + ); + + // The inverse direction: in search mode a binding-only commit does not change `tools/list`, so + // neither stream may claim a visible Tool change. + endpoint.commit_search_mode_binding_change().await; + modern + .expect_silence( + Duration::from_millis(3_500), + "a Tools signal for an unchanged modern tools/list", + ) + .await; + legacy + .expect_silence( + Duration::from_millis(2_500), + "a Tools signal for an unchanged legacy tools/list", + ) + .await; + assert_eq!( + tool_names(&endpoint.modern("tools/list", json!({})).await), + search_projection + ); +} + /// AT-3.5-02/03: a client that missed the notification recovers Tool discovery from the authoritative /// state — the modern stateless client after a reconnect, and the legacy client after re-initializing /// a retired session — and a reconnected stream never replays the missed change. diff --git a/crates/crank-community-mcp/src/protocol/signals.rs b/crates/crank-community-mcp/src/protocol/signals.rs index dcaa98a..32b7428 100644 --- a/crates/crank-community-mcp/src/protocol/signals.rs +++ b/crates/crank-community-mcp/src/protocol/signals.rs @@ -8,7 +8,8 @@ //! //! Shape of the chosen seam (ARC decision, kanban t_c12863fb): a **stream-local watcher**. One open //! notification stream owns one bounded periodic read of the published Agent catalog the stream is -//! scoped to; a change of the visible Resource/Prompt/Tool binding projection produces the revision's +//! scoped to; a change of the visible Resource/Prompt/Tool projection of that snapshot (the Resource +//! and Prompt bindings plus the exact Tool definitions `tools/list` serves) produces the revision's //! list-change notification. There is no post-commit hook, no cross-process bus and no durable //! queue: the committed catalog is the source of truth, so a signal can never be produced before its //! commit, and a failed read can never roll the commit back — it only skips that tick and stays @@ -188,10 +189,13 @@ fn acknowledged_filter_wire(accepted: Signals) -> Value { /// /// The projection is derived from the same committed catalog read that already feeds /// `resources/list`, `resources/templates/list`, `prompts/list`, `prompts/get` and `tools/list`: the -/// exact Resource, Prompt and Tool bindings of the published Agent snapshot, in deterministic -/// binding order. `catalog_revision` alone is *not* the comparison key — a commit that only changes -/// Tools must not produce a Resource or Prompt signal, and vice versa — so the three binding vectors -/// are compared on their own. +/// exact Resource and Prompt bindings of the published Agent snapshot, in deterministic binding +/// order, and the exact Tool definitions that `tools/list` would serve. The Tool part is taken from +/// [`crate::manifest::catalog_tool_definitions`] rather than from the bindings, because that is the +/// projection the client sees: it also depends on the Tool selection policy (mode, groups, search +/// settings), and in `Search` mode it does not depend on the bindings at all. `catalog_revision` +/// alone is *not* the comparison key — a commit that only changes Tools must not produce a Resource +/// or Prompt signal, and vice versa — so the three projections are compared on their own. /// /// shortcut: a Resource revocation invalidates a bound publication without a new Agent snapshot, so /// it does not change this projection and produces no list-change signal; the revocation gate at @@ -201,62 +205,40 @@ fn acknowledged_filter_wire(accepted: Signals) -> Value { pub(crate) struct CatalogFingerprint { resources: Vec<(String, u32)>, prompts: Vec<(String, u32)>, - /// Tool name, published Operation version and the visible title/description of the binding. - tools: Vec<(String, u32, String, String)>, + /// Canonical JSON of every definition `tools/list` serves, sorted so a re-ordered read is not a + /// false change. + tools: Vec, } impl CatalogFingerprint { pub(crate) fn of(catalog: &PublishedAgentCatalog) -> Self { - // The bound Tool is the published Operation snapshot of the binding, so its own version is - // part of the visible `tools/list` projection, next to the binding's own title/description. - Self::from_parts( - catalog - .resources - .iter() - .map(|binding| (binding.resource_id.as_str(), binding.resource_version)), - catalog - .prompts - .iter() - .map(|binding| (binding.prompt_id.as_str(), binding.prompt_version)), - catalog.tools.iter().map(|binding| { - ( - binding.tool_name.as_str(), - binding.operation.version, - binding.tool_title.as_str(), - binding.tool_description.as_str(), - ) - }), - ) - } - - fn from_parts<'a>( - resources: impl Iterator, - prompts: impl Iterator, - tools: impl Iterator, - ) -> Self { fn sorted(values: impl Iterator) -> Vec { let mut sorted = values.collect::>(); - sorted.sort(); + sorted.sort_unstable(); sorted } - fn owned<'a>(values: impl Iterator) -> Vec<(String, u32)> { - sorted(values.map(|(name, version)| (name.to_owned(), version))) - } Self { - resources: owned(resources), - prompts: owned(prompts), - tools: sorted(tools.map(|(name, version, title, description)| { + resources: sorted(catalog.resources.iter().map(|binding| { ( - name.to_owned(), - version, - title.to_owned(), - description.to_owned(), + binding.resource_id.as_str().to_owned(), + binding.resource_version, ) })), + prompts: sorted(catalog.prompts.iter().map(|binding| { + ( + binding.prompt_id.as_str().to_owned(), + binding.prompt_version, + ) + })), + tools: sorted( + crate::manifest::catalog_tool_definitions(catalog) + .into_iter() + .map(|definition| definition.to_string()), + ), } } - /// The list-change types whose visible binding projection differs between `previous` and `self`. + /// The list-change types whose visible projection differs between `previous` and `self`. pub(crate) fn changes_since(&self, previous: &Self) -> Signals { Signals { resources: self.resources != previous.resources, diff --git a/crates/crank-community-mcp/src/protocol/signals_tests.rs b/crates/crank-community-mcp/src/protocol/signals_tests.rs index 861dfe5..0674af6 100644 --- a/crates/crank-community-mcp/src/protocol/signals_tests.rs +++ b/crates/crank-community-mcp/src/protocol/signals_tests.rs @@ -2,16 +2,24 @@ //! wire frames of both approved revisions and the bounded legacy stream ownership. use std::{ + collections::BTreeMap, io, sync::{Arc, Mutex}, time::{Duration, Instant}, }; -use crank_core::ToolSelectionPolicy; use crank_core::ids::{PromptId, ResourceId}; +use crank_core::{ + ExecutionConfig, HttpMethod, Operation, OperationId, OperationSecurityLevel, OperationStatus, + Protocol, RestTarget, Target, ToolAccessMode, ToolDescription, ToolGroup, ToolSearchSettings, + ToolSelectionPolicy, WorkspaceId, +}; +use crank_mapping::MappingSet; use crank_registry::PublishedAgentCatalog; -use crank_registry::model::{AgentPromptBinding, AgentResourceBinding}; +use crank_registry::model::{AgentPromptBinding, AgentResourceBinding, PublishedAgentTool}; +use crank_schema::{Schema, SchemaKind}; use serde_json::{Value, json}; +use time::OffsetDateTime; use tokio::sync::mpsc; use super::{ @@ -25,12 +33,28 @@ fn catalog( resources: &[(&str, u32)], prompts: &[(&str, u32)], catalog_revision: &str, +) -> PublishedAgentCatalog { + catalog_with( + ToolSelectionPolicy::default(), + Vec::new(), + resources, + prompts, + catalog_revision, + ) +} + +fn catalog_with( + tool_selection_policy: ToolSelectionPolicy, + tools: Vec, + resources: &[(&str, u32)], + prompts: &[(&str, u32)], + catalog_revision: &str, ) -> PublishedAgentCatalog { PublishedAgentCatalog { agent_version: 1, catalog_revision: catalog_revision.to_owned(), - tool_selection_policy: ToolSelectionPolicy::default(), - tools: Vec::new(), + tool_selection_policy, + tools, resources: resources .iter() .map(|(id, version)| AgentResourceBinding { @@ -48,6 +72,93 @@ fn catalog( } } +fn search_policy(tool_names: &[&str]) -> ToolSelectionPolicy { + ToolSelectionPolicy { + mode: ToolAccessMode::Search, + groups: vec![ToolGroup { + id: "crm".to_owned(), + name: "CRM".to_owned(), + description: "CRM operations".to_owned(), + tool_names: tool_names.iter().map(|name| (*name).to_owned()).collect(), + }], + search: ToolSearchSettings::default(), + } +} + +fn empty_object_schema() -> Schema { + Schema { + kind: SchemaKind::Object, + format: None, + description: None, + required: false, + nullable: false, + default_value: None, + fields: BTreeMap::new(), + items: None, + enum_values: Vec::new(), + variants: Vec::new(), + } +} + +/// One published Tool binding whose served definition is exactly `title`/`description`. +fn published_tool(name: &str, title: &str, description: &str, version: u32) -> PublishedAgentTool { + PublishedAgentTool { + workspace_id: WorkspaceId::new("ws_test"), + workspace_slug: "ws-test".to_owned(), + agent_id: "agent_test".into(), + agent_slug: "agent".to_owned(), + operation: Operation { + id: OperationId::new(format!("op_{name}")), + name: name.to_owned(), + display_name: title.to_owned(), + category: "test".to_owned(), + protocol: Protocol::Rest, + security_level: OperationSecurityLevel::Standard, + status: OperationStatus::Published, + version, + target: Target::Rest(RestTarget { + base_url: "https://example.test".to_owned(), + method: HttpMethod::Get, + path_template: "/leads".to_owned(), + static_headers: BTreeMap::new(), + request_contract: None, + response_contract: Vec::new(), + multipart_field_mime_types: BTreeMap::new(), + }), + input_schema: empty_object_schema(), + output_schema: empty_object_schema(), + input_mapping: MappingSet { rules: Vec::new() }, + output_mapping: MappingSet { rules: Vec::new() }, + execution_config: ExecutionConfig { + timeout_ms: 10_000, + retry_policy: None, + response_cache: None, + idempotency: None, + safety: None, + approval_policy: None, + auth_profile_ref: None, + headers: BTreeMap::new(), + }, + tool_description: ToolDescription { + title: title.to_owned(), + description: description.to_owned(), + tags: Vec::new(), + examples: Vec::new(), + }, + samples: None, + generated_draft: None, + config_export: None, + wizard_state: None, + created_at: OffsetDateTime::UNIX_EPOCH, + updated_at: OffsetDateTime::UNIX_EPOCH, + published_at: None, + }, + tool_name: name.to_owned(), + tool_title: title.to_owned(), + tool_description: description.to_owned(), + } +} + #[test] fn a_committed_resource_binding_is_a_resource_change_only() { let before = CatalogFingerprint::of(&catalog(&[("res_a", 1)], &[("prm_a", 1)], "rev-1")); @@ -107,79 +218,198 @@ fn a_pinned_version_bump_is_a_change_even_when_the_binding_names_are_stable() { } #[test] -fn a_committed_tool_binding_or_version_is_a_tool_change_only() { - let before = CatalogFingerprint::from_parts( - [("res_a", 1)].into_iter(), - [("prm_a", 1)].into_iter(), - [("crm_create_lead", 1, "Create Lead", "Creates a lead")].into_iter(), - ); - let added = CatalogFingerprint::from_parts( - [("res_a", 1)].into_iter(), - [("prm_a", 1)].into_iter(), - [ - ("crm_create_lead", 1, "Create Lead", "Creates a lead"), - ( +fn a_committed_tool_definition_change_is_a_tool_change_only() { + let lead = || published_tool("crm_create_lead", "Create Lead", "Creates a lead", 1); + let before = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy::default(), + vec![lead()], + &[("res_a", 1)], + &[("prm_a", 1)], + "rev-1", + )); + let added = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy::default(), + vec![ + lead(), + published_tool( "crm_create_second", - 1, "Create Second", "Creates a second lead", + 1, ), - ] - .into_iter(), - ); - let bumped = CatalogFingerprint::from_parts( - [("res_a", 1)].into_iter(), - [("prm_a", 1)].into_iter(), - [("crm_create_lead", 2, "Create Lead", "Creates a lead")].into_iter(), - ); - let retitled = CatalogFingerprint::from_parts( - [("res_a", 1)].into_iter(), - [("prm_a", 1)].into_iter(), - [("crm_create_lead", 1, "Create a lead", "Creates a lead")].into_iter(), - ); + ], + &[("res_a", 1)], + &[("prm_a", 1)], + "rev-2", + )); + let retitled = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy::default(), + vec![published_tool( + "crm_create_lead", + "Create a lead", + "Creates a lead", + 1, + )], + &[("res_a", 1)], + &[("prm_a", 1)], + "rev-2", + )); - assert_eq!( - added.changes_since(&before), - Signals { - resources: false, - prompts: false, - tools: true - } - ); - assert_eq!( - bumped.changes_since(&before), - Signals { - resources: false, - prompts: false, - tools: true - }, - "a re-published Operation version changes the visible Tool projection" - ); + let tools_only = Signals { + resources: false, + prompts: false, + tools: true, + }; + assert_eq!(added.changes_since(&before), tools_only); assert_eq!( retitled.changes_since(&before), - Signals { - resources: false, - prompts: false, - tools: true - }, + tools_only, "a retitled binding changes the visible Tool projection without a new Operation version" ); // The reverse direction is a Tool change as well: a removed binding is a real change. assert!(before.changes_since(&added).tools); } +#[test] +fn a_republished_operation_version_with_an_identical_definition_is_silent() { + // `tools/list` serves the definition, not the Operation version: a version bump that leaves the + // served definition unchanged is not a client-visible Tool catalog change. + let before = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy::default(), + vec![published_tool( + "crm_create_lead", + "Create Lead", + "Creates a lead", + 1, + )], + &[("res_a", 1)], + &[("prm_a", 1)], + "rev-1", + )); + let after = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy::default(), + vec![published_tool( + "crm_create_lead", + "Create Lead", + "Creates a lead", + 2, + )], + &[("res_a", 1)], + &[("prm_a", 1)], + "rev-2", + )); + + assert!(!after.changes_since(&before).any()); +} + +#[test] +fn a_policy_only_commit_that_changes_tools_list_is_a_tool_change_only() { + // The Tool selection policy is part of the served `tools/list` projection: switching the same + // bindings from direct to search mode replaces the served tools with `search_tools`/`call_tool`. + let tool = published_tool("crm_create_lead", "Create Lead", "Creates a lead", 1); + let direct = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy::default(), + vec![tool.clone()], + &[("res_a", 1)], + &[("prm_a", 1)], + "rev-1", + )); + let search = CatalogFingerprint::of(&catalog_with( + search_policy(&["crm_create_lead"]), + vec![tool], + &[("res_a", 1)], + &[("prm_a", 1)], + "rev-2", + )); + + let tools_only = Signals { + resources: false, + prompts: false, + tools: true, + }; + assert_eq!(search.changes_since(&direct), tools_only); + assert_eq!(direct.changes_since(&search), tools_only); +} + +#[test] +fn a_policy_field_invisible_to_tools_list_is_silent() { + // `search.max_results` is only served inside the search-mode definitions: in direct mode it + // changes nothing the client receives. + let tool = || published_tool("crm_create_lead", "Create Lead", "Creates a lead", 1); + let before = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy::default(), + vec![tool()], + &[], + &[], + "rev-1", + )); + let after = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy { + search: ToolSearchSettings { max_results: 5 }, + ..ToolSelectionPolicy::default() + }, + vec![tool()], + &[], + &[], + "rev-2", + )); + + assert!(!after.changes_since(&before).any()); +} + +#[test] +fn a_search_mode_binding_change_is_silent_when_tools_list_is_unchanged() { + // In search mode the served list is `search_tools`/`call_tool`; the bindings behind it are not + // part of `tools/list`, so a binding-only commit must not claim a visible Tool change. + let policy = search_policy(&["crm_create_lead"]); + let before = CatalogFingerprint::of(&catalog_with( + policy.clone(), + vec![published_tool( + "crm_create_lead", + "Create Lead", + "Creates a lead", + 1, + )], + &[], + &[], + "rev-1", + )); + let after = CatalogFingerprint::of(&catalog_with( + policy, + vec![ + published_tool("crm_create_lead", "Create Lead", "Creates a lead", 1), + published_tool( + "crm_create_second", + "Create Second", + "Creates a second lead", + 1, + ), + ], + &[], + &[], + "rev-2", + )); + + assert!(!after.changes_since(&before).any()); +} + #[test] fn a_resource_or_prompt_change_is_not_a_tool_change() { - let before = CatalogFingerprint::from_parts( - [("res_a", 1)].into_iter(), - [("prm_a", 1)].into_iter(), - [("crm_create_lead", 1, "Create Lead", "Creates a lead")].into_iter(), - ); - let changed = CatalogFingerprint::from_parts( - [("res_a", 2)].into_iter(), - [("prm_a", 1), ("prm_b", 1)].into_iter(), - [("crm_create_lead", 1, "Create Lead", "Creates a lead")].into_iter(), - ); + let tool = || published_tool("crm_create_lead", "Create Lead", "Creates a lead", 1); + let before = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy::default(), + vec![tool()], + &[("res_a", 1)], + &[("prm_a", 1)], + "rev-1", + )); + let changed = CatalogFingerprint::of(&catalog_with( + ToolSelectionPolicy::default(), + vec![tool()], + &[("res_a", 2)], + &[("prm_a", 1), ("prm_b", 1)], + "rev-1", + )); assert_eq!( changed.changes_since(&before),