fix(epic3): выводить Tools-сигнал из клиентской проекции tools/list (Story 3.5, FR-14)
CI / UI Checks (pull_request) Successful in 8s
CI / Rust Checks (pull_request) Successful in 10m49s
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) Successful in 1s
CI / Deploy (pull_request) Skipped
Community Release / release (push) Successful in 25m35s
CI / UI Checks (pull_request) Successful in 8s
CI / Rust Checks (pull_request) Successful in 10m49s
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) Successful in 1s
CI / Deploy (pull_request) Skipped
Community Release / release (push) Successful in 25m35s
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.
This commit is contained in:
1 parent
a0365bb80b
commit
44774883a0
4 files changed
+483
-110
No files matched your search
@@ -20,7 +20,8 @@ use std::{
|
|||||||
use axum::http::header;
|
use axum::http::header;
|
||||||
use crank_artifacts::ArtifactStore;
|
use crank_artifacts::ArtifactStore;
|
||||||
use crank_core::{
|
use crank_core::{
|
||||||
Agent, AgentId, AgentStatus, AgentVersion, PlatformApiKeyScope, ToolSelectionPolicy,
|
Agent, AgentId, AgentStatus, AgentVersion, PlatformApiKeyScope, ToolAccessMode, ToolGroup,
|
||||||
|
ToolSearchSettings, ToolSelectionPolicy,
|
||||||
ids::{PromptId, ResourceId},
|
ids::{PromptId, ResourceId},
|
||||||
prompt::{PromptDefinition, PromptSensitivity},
|
prompt::{PromptDefinition, PromptSensitivity},
|
||||||
};
|
};
|
||||||
@@ -257,6 +258,26 @@ impl SignalsEndpoint {
|
|||||||
tool_bindings: &[crank_core::AgentOperationBinding],
|
tool_bindings: &[crank_core::AgentOperationBinding],
|
||||||
resource_bindings: &[AgentResourceBinding],
|
resource_bindings: &[AgentResourceBinding],
|
||||||
prompt_bindings: &[AgentPromptBinding],
|
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
|
self.registry
|
||||||
.save_agent_catalog_config_editable_with_prompts(
|
.save_agent_catalog_config_editable_with_prompts(
|
||||||
@@ -265,7 +286,7 @@ impl SignalsEndpoint {
|
|||||||
agent_id: &self.agent_id,
|
agent_id: &self.agent_id,
|
||||||
agent_version: version,
|
agent_version: version,
|
||||||
bindings: tool_bindings,
|
bindings: tool_bindings,
|
||||||
tool_selection_policy: &ToolSelectionPolicy::default(),
|
tool_selection_policy,
|
||||||
resource_bindings,
|
resource_bindings,
|
||||||
expected_state: None,
|
expected_state: None,
|
||||||
},
|
},
|
||||||
@@ -429,6 +450,53 @@ impl SignalsEndpoint {
|
|||||||
self.publish_version(version).await;
|
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
|
/// Publish an independent Agent of the same workspace, bound to the first fixture operation, and
|
||||||
/// return its read-only MCP client key.
|
/// return its read-only MCP client key.
|
||||||
async fn publish_other_agent(&self, slug: &str) -> String {
|
async fn publish_other_agent(&self, slug: &str) -> String {
|
||||||
|
|||||||
@@ -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
|
/// 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
|
/// 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.
|
/// a retired session — and a reconnected stream never replays the missed change.
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
//!
|
//!
|
||||||
//! Shape of the chosen seam (ARC decision, kanban t_c12863fb): a **stream-local watcher**. One open
|
//! 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
|
//! 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
|
//! 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
|
//! 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
|
//! 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
|
/// 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
|
/// `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
|
/// exact Resource and Prompt bindings of the published Agent snapshot, in deterministic binding
|
||||||
/// binding order. `catalog_revision` alone is *not* the comparison key — a commit that only changes
|
/// order, and the exact Tool definitions that `tools/list` would serve. The Tool part is taken from
|
||||||
/// Tools must not produce a Resource or Prompt signal, and vice versa — so the three binding vectors
|
/// [`crate::manifest::catalog_tool_definitions`] rather than from the bindings, because that is the
|
||||||
/// are compared on their own.
|
/// 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
|
/// 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
|
/// 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 {
|
pub(crate) struct CatalogFingerprint {
|
||||||
resources: Vec<(String, u32)>,
|
resources: Vec<(String, u32)>,
|
||||||
prompts: Vec<(String, u32)>,
|
prompts: Vec<(String, u32)>,
|
||||||
/// Tool name, published Operation version and the visible title/description of the binding.
|
/// Canonical JSON of every definition `tools/list` serves, sorted so a re-ordered read is not a
|
||||||
tools: Vec<(String, u32, String, String)>,
|
/// false change.
|
||||||
|
tools: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CatalogFingerprint {
|
impl CatalogFingerprint {
|
||||||
pub(crate) fn of(catalog: &PublishedAgentCatalog) -> Self {
|
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<Item = (&'a str, u32)>,
|
|
||||||
prompts: impl Iterator<Item = (&'a str, u32)>,
|
|
||||||
tools: impl Iterator<Item = (&'a str, u32, &'a str, &'a str)>,
|
|
||||||
) -> Self {
|
|
||||||
fn sorted<T: Ord>(values: impl Iterator<Item = T>) -> Vec<T> {
|
fn sorted<T: Ord>(values: impl Iterator<Item = T>) -> Vec<T> {
|
||||||
let mut sorted = values.collect::<Vec<_>>();
|
let mut sorted = values.collect::<Vec<_>>();
|
||||||
sorted.sort();
|
sorted.sort_unstable();
|
||||||
sorted
|
sorted
|
||||||
}
|
}
|
||||||
fn owned<'a>(values: impl Iterator<Item = (&'a str, u32)>) -> Vec<(String, u32)> {
|
|
||||||
sorted(values.map(|(name, version)| (name.to_owned(), version)))
|
|
||||||
}
|
|
||||||
Self {
|
Self {
|
||||||
resources: owned(resources),
|
resources: sorted(catalog.resources.iter().map(|binding| {
|
||||||
prompts: owned(prompts),
|
|
||||||
tools: sorted(tools.map(|(name, version, title, description)| {
|
|
||||||
(
|
(
|
||||||
name.to_owned(),
|
binding.resource_id.as_str().to_owned(),
|
||||||
version,
|
binding.resource_version,
|
||||||
title.to_owned(),
|
|
||||||
description.to_owned(),
|
|
||||||
)
|
)
|
||||||
})),
|
})),
|
||||||
|
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 {
|
pub(crate) fn changes_since(&self, previous: &Self) -> Signals {
|
||||||
Signals {
|
Signals {
|
||||||
resources: self.resources != previous.resources,
|
resources: self.resources != previous.resources,
|
||||||
|
|||||||
@@ -2,16 +2,24 @@
|
|||||||
//! wire frames of both approved revisions and the bounded legacy stream ownership.
|
//! wire frames of both approved revisions and the bounded legacy stream ownership.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::BTreeMap,
|
||||||
io,
|
io,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crank_core::ToolSelectionPolicy;
|
|
||||||
use crank_core::ids::{PromptId, ResourceId};
|
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::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 serde_json::{Value, json};
|
||||||
|
use time::OffsetDateTime;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@@ -25,12 +33,28 @@ fn catalog(
|
|||||||
resources: &[(&str, u32)],
|
resources: &[(&str, u32)],
|
||||||
prompts: &[(&str, u32)],
|
prompts: &[(&str, u32)],
|
||||||
catalog_revision: &str,
|
catalog_revision: &str,
|
||||||
|
) -> PublishedAgentCatalog {
|
||||||
|
catalog_with(
|
||||||
|
ToolSelectionPolicy::default(),
|
||||||
|
Vec::new(),
|
||||||
|
resources,
|
||||||
|
prompts,
|
||||||
|
catalog_revision,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn catalog_with(
|
||||||
|
tool_selection_policy: ToolSelectionPolicy,
|
||||||
|
tools: Vec<PublishedAgentTool>,
|
||||||
|
resources: &[(&str, u32)],
|
||||||
|
prompts: &[(&str, u32)],
|
||||||
|
catalog_revision: &str,
|
||||||
) -> PublishedAgentCatalog {
|
) -> PublishedAgentCatalog {
|
||||||
PublishedAgentCatalog {
|
PublishedAgentCatalog {
|
||||||
agent_version: 1,
|
agent_version: 1,
|
||||||
catalog_revision: catalog_revision.to_owned(),
|
catalog_revision: catalog_revision.to_owned(),
|
||||||
tool_selection_policy: ToolSelectionPolicy::default(),
|
tool_selection_policy,
|
||||||
tools: Vec::new(),
|
tools,
|
||||||
resources: resources
|
resources: resources
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, version)| AgentResourceBinding {
|
.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]
|
#[test]
|
||||||
fn a_committed_resource_binding_is_a_resource_change_only() {
|
fn a_committed_resource_binding_is_a_resource_change_only() {
|
||||||
let before = CatalogFingerprint::of(&catalog(&[("res_a", 1)], &[("prm_a", 1)], "rev-1"));
|
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]
|
#[test]
|
||||||
fn a_committed_tool_binding_or_version_is_a_tool_change_only() {
|
fn a_committed_tool_definition_change_is_a_tool_change_only() {
|
||||||
let before = CatalogFingerprint::from_parts(
|
let lead = || published_tool("crm_create_lead", "Create Lead", "Creates a lead", 1);
|
||||||
[("res_a", 1)].into_iter(),
|
let before = CatalogFingerprint::of(&catalog_with(
|
||||||
[("prm_a", 1)].into_iter(),
|
ToolSelectionPolicy::default(),
|
||||||
[("crm_create_lead", 1, "Create Lead", "Creates a lead")].into_iter(),
|
vec![lead()],
|
||||||
);
|
&[("res_a", 1)],
|
||||||
let added = CatalogFingerprint::from_parts(
|
&[("prm_a", 1)],
|
||||||
[("res_a", 1)].into_iter(),
|
"rev-1",
|
||||||
[("prm_a", 1)].into_iter(),
|
));
|
||||||
[
|
let added = CatalogFingerprint::of(&catalog_with(
|
||||||
("crm_create_lead", 1, "Create Lead", "Creates a lead"),
|
ToolSelectionPolicy::default(),
|
||||||
(
|
vec![
|
||||||
|
lead(),
|
||||||
|
published_tool(
|
||||||
"crm_create_second",
|
"crm_create_second",
|
||||||
1,
|
|
||||||
"Create Second",
|
"Create Second",
|
||||||
"Creates a second lead",
|
"Creates a second lead",
|
||||||
|
1,
|
||||||
),
|
),
|
||||||
]
|
],
|
||||||
.into_iter(),
|
&[("res_a", 1)],
|
||||||
);
|
&[("prm_a", 1)],
|
||||||
let bumped = CatalogFingerprint::from_parts(
|
"rev-2",
|
||||||
[("res_a", 1)].into_iter(),
|
));
|
||||||
[("prm_a", 1)].into_iter(),
|
let retitled = CatalogFingerprint::of(&catalog_with(
|
||||||
[("crm_create_lead", 2, "Create Lead", "Creates a lead")].into_iter(),
|
ToolSelectionPolicy::default(),
|
||||||
);
|
vec![published_tool(
|
||||||
let retitled = CatalogFingerprint::from_parts(
|
"crm_create_lead",
|
||||||
[("res_a", 1)].into_iter(),
|
"Create a lead",
|
||||||
[("prm_a", 1)].into_iter(),
|
"Creates a lead",
|
||||||
[("crm_create_lead", 1, "Create a lead", "Creates a lead")].into_iter(),
|
1,
|
||||||
);
|
)],
|
||||||
|
&[("res_a", 1)],
|
||||||
|
&[("prm_a", 1)],
|
||||||
|
"rev-2",
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(
|
let tools_only = Signals {
|
||||||
added.changes_since(&before),
|
resources: false,
|
||||||
Signals {
|
prompts: false,
|
||||||
resources: false,
|
tools: true,
|
||||||
prompts: false,
|
};
|
||||||
tools: true
|
assert_eq!(added.changes_since(&before), tools_only);
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
bumped.changes_since(&before),
|
|
||||||
Signals {
|
|
||||||
resources: false,
|
|
||||||
prompts: false,
|
|
||||||
tools: true
|
|
||||||
},
|
|
||||||
"a re-published Operation version changes the visible Tool projection"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
retitled.changes_since(&before),
|
retitled.changes_since(&before),
|
||||||
Signals {
|
tools_only,
|
||||||
resources: false,
|
|
||||||
prompts: false,
|
|
||||||
tools: true
|
|
||||||
},
|
|
||||||
"a retitled binding changes the visible Tool projection without a new Operation version"
|
"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.
|
// The reverse direction is a Tool change as well: a removed binding is a real change.
|
||||||
assert!(before.changes_since(&added).tools);
|
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]
|
#[test]
|
||||||
fn a_resource_or_prompt_change_is_not_a_tool_change() {
|
fn a_resource_or_prompt_change_is_not_a_tool_change() {
|
||||||
let before = CatalogFingerprint::from_parts(
|
let tool = || published_tool("crm_create_lead", "Create Lead", "Creates a lead", 1);
|
||||||
[("res_a", 1)].into_iter(),
|
let before = CatalogFingerprint::of(&catalog_with(
|
||||||
[("prm_a", 1)].into_iter(),
|
ToolSelectionPolicy::default(),
|
||||||
[("crm_create_lead", 1, "Create Lead", "Creates a lead")].into_iter(),
|
vec![tool()],
|
||||||
);
|
&[("res_a", 1)],
|
||||||
let changed = CatalogFingerprint::from_parts(
|
&[("prm_a", 1)],
|
||||||
[("res_a", 2)].into_iter(),
|
"rev-1",
|
||||||
[("prm_a", 1), ("prm_b", 1)].into_iter(),
|
));
|
||||||
[("crm_create_lead", 1, "Create Lead", "Creates a lead")].into_iter(),
|
let changed = CatalogFingerprint::of(&catalog_with(
|
||||||
);
|
ToolSelectionPolicy::default(),
|
||||||
|
vec![tool()],
|
||||||
|
&[("res_a", 2)],
|
||||||
|
&[("prm_a", 1), ("prm_b", 1)],
|
||||||
|
"rev-1",
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
changed.changes_since(&before),
|
changed.changes_since(&before),
|
||||||
|
|||||||
Reference in new issue
Block a user