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.
221 lines
7.8 KiB
Rust
221 lines
7.8 KiB
Rust
//! In-crate tests of `protocol::completion` (module path `protocol::completion::tests`).
|
|
//!
|
|
//! These cover the pure halves of the shared service: the bounded input contract of AC2 and the
|
|
//! suggestion derivation of AC1. The real endpoint behaviour (both eras, real registry) is covered by
|
|
//! `apps/mcp-server/tests/integration/mcp_completion.rs`.
|
|
|
|
use super::*;
|
|
use serde_json::json;
|
|
|
|
/// Any supported revision: the suggestion derivation is era-neutral.
|
|
const MODERN: &str = crate::jsonrpc::MODERN_PROTOCOL_VERSION;
|
|
|
|
fn candidates(values: &[&str]) -> Vec<String> {
|
|
values.iter().map(|value| (*value).to_owned()).collect()
|
|
}
|
|
|
|
fn values_of(outcome: &CompletionOutcome) -> (&[String], Option<usize>, bool) {
|
|
match outcome {
|
|
CompletionOutcome::Completed {
|
|
values,
|
|
total,
|
|
has_more,
|
|
} => (values, *total, *has_more),
|
|
_ => panic!("expected a completed outcome"),
|
|
}
|
|
}
|
|
|
|
fn command(params: Value) -> Result<CompletionCommand, serde_json::Error> {
|
|
serde_json::from_value(params)
|
|
}
|
|
|
|
#[test]
|
|
fn matching_is_a_case_insensitive_prefix_in_schema_order() {
|
|
let outcome = completed(
|
|
MODERN,
|
|
"prompt",
|
|
"W",
|
|
candidates(&["warm", "dry", "wild", "warmest"]),
|
|
);
|
|
let (values, total, has_more) = values_of(&outcome);
|
|
assert_eq!(values, ["warm", "wild", "warmest"]);
|
|
assert_eq!(total, Some(3));
|
|
assert!(!has_more);
|
|
}
|
|
|
|
#[test]
|
|
fn an_empty_token_lists_the_bounded_enumeration() {
|
|
let outcome = completed(MODERN, "prompt", "", candidates(&["a", "b", "c"]));
|
|
let (values, total, has_more) = values_of(&outcome);
|
|
assert_eq!(values, ["a", "b", "c"]);
|
|
assert_eq!(total, Some(3));
|
|
assert!(!has_more);
|
|
}
|
|
|
|
#[test]
|
|
fn a_token_without_a_match_returns_no_suggestions() {
|
|
let outcome = completed(MODERN, "resource", "zzz", candidates(&["eu", "us"]));
|
|
let (values, total, has_more) = values_of(&outcome);
|
|
assert!(values.is_empty());
|
|
assert_eq!(total, Some(0));
|
|
assert!(!has_more);
|
|
}
|
|
|
|
#[test]
|
|
fn the_response_is_capped_at_the_pinned_maximum_and_reports_more() {
|
|
let all: Vec<String> = (0..150).map(|index| format!("value-{index:03}")).collect();
|
|
let outcome = completed(MODERN, "prompt", "value-", all);
|
|
let (values, total, has_more) = values_of(&outcome);
|
|
assert_eq!(values.len(), MAX_COMPLETION_VALUES);
|
|
assert_eq!(values.first().map(String::as_str), Some("value-000"));
|
|
assert_eq!(total, Some(150), "the exact option count is still reported");
|
|
assert!(has_more);
|
|
}
|
|
|
|
#[test]
|
|
fn duplicate_enumeration_entries_are_collapsed_before_counting() {
|
|
let outcome = completed(MODERN, "prompt", "", candidates(&["eu", "eu", "us"]));
|
|
let (values, total, has_more) = values_of(&outcome);
|
|
assert_eq!(values, ["eu", "us"]);
|
|
assert_eq!(total, Some(2));
|
|
assert!(!has_more);
|
|
}
|
|
|
|
#[test]
|
|
fn a_truncated_schema_scan_never_claims_an_exact_total() {
|
|
let all: Vec<String> = (0..=MAX_SCHEMA_VALUES)
|
|
.map(|index| format!("item{index}"))
|
|
.collect();
|
|
let outcome = completed(MODERN, "resource", "item", all);
|
|
let (values, total, has_more) = values_of(&outcome);
|
|
assert_eq!(values.len(), MAX_COMPLETION_VALUES);
|
|
assert_eq!(total, None, "a partial scan cannot name the option count");
|
|
assert!(has_more);
|
|
}
|
|
|
|
#[test]
|
|
fn only_scalar_enumeration_entries_become_suggestions() {
|
|
assert_eq!(value_text(&json!("eu")), Some("eu".to_owned()));
|
|
assert_eq!(value_text(&json!(7)), Some("7".to_owned()));
|
|
assert_eq!(value_text(&json!(true)), Some("true".to_owned()));
|
|
assert_eq!(value_text(&json!(null)), None);
|
|
assert_eq!(value_text(&json!(["eu"])), None);
|
|
assert_eq!(value_text(&json!({"value": "eu"})), None);
|
|
}
|
|
|
|
#[test]
|
|
fn a_non_ascii_token_matches_exactly_and_never_slices_mid_character() {
|
|
assert!(prefix_match("привет", "пр"));
|
|
// A two-byte Cyrillic letter is one character, so it is a plain prefix.
|
|
assert!(prefix_match("привет", "п"));
|
|
assert!(prefix_match("Ärger", "Är"));
|
|
// Two ASCII bytes end inside the multi-byte `é`: no prefix is claimed for a mid-character cut.
|
|
assert!(!prefix_match("aé", "ab"));
|
|
assert!(!prefix_match("warm", "warmest"));
|
|
}
|
|
|
|
#[test]
|
|
fn a_refusal_discloses_neither_reason_nor_identifiers() {
|
|
assert!(matches!(
|
|
not_available(MODERN, "prompt"),
|
|
CompletionOutcome::NotAvailable
|
|
));
|
|
assert!(matches!(
|
|
refused(MODERN, "resource", "schema_unavailable"),
|
|
CompletionOutcome::CatalogUnavailable
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn both_typed_references_parse_and_a_foreign_ref_type_is_rejected() {
|
|
let prompt = command(json!({
|
|
"ref": {"type": "ref/prompt", "name": "greeting"},
|
|
"argument": {"name": "tone", "value": "w"}
|
|
}))
|
|
.expect("the prompt reference is the pinned shape");
|
|
assert_eq!(prompt.reference_label(), "prompt");
|
|
assert!(prompt.context.is_none());
|
|
|
|
let resource = command(json!({
|
|
"ref": {"type": "ref/resource", "uri": "crank://orders/{order_id}"},
|
|
"argument": {"name": "order_id", "value": "0"},
|
|
"context": {"arguments": {"region": "eu"}}
|
|
}))
|
|
.expect("the resource reference with context is the pinned shape");
|
|
assert_eq!(resource.reference_label(), "resource");
|
|
assert!(resource.validate().is_none());
|
|
|
|
assert!(
|
|
command(json!({
|
|
"ref": {"type": "ref/tool", "name": "x"},
|
|
"argument": {"name": "a", "value": ""}
|
|
}))
|
|
.is_err(),
|
|
"an unknown reference type is not a completion reference"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn oversized_and_malformed_requests_are_refused_before_any_catalog_read() {
|
|
let long_value = "v".repeat(MAX_ARGUMENT_VALUE_BYTES + 1);
|
|
let oversized = command(json!({
|
|
"ref": {"type": "ref/prompt", "name": "greeting"},
|
|
"argument": {"name": "tone", "value": long_value}
|
|
}))
|
|
.expect("the request shape parses; only its bound is exceeded");
|
|
assert_eq!(oversized.validate(), Some(INVALID_PARAMS));
|
|
|
|
let long_name = "n".repeat(MAX_ARGUMENT_NAME_BYTES + 1);
|
|
let oversized_name = command(json!({
|
|
"ref": {"type": "ref/prompt", "name": "greeting"},
|
|
"argument": {"name": long_name, "value": ""}
|
|
}))
|
|
.expect("the request shape parses");
|
|
assert_eq!(oversized_name.validate(), Some(INVALID_PARAMS));
|
|
|
|
let empty_argument = command(json!({
|
|
"ref": {"type": "ref/resource", "uri": "crank://orders/{order_id}"},
|
|
"argument": {"name": "", "value": ""}
|
|
}))
|
|
.expect("the request shape parses");
|
|
assert_eq!(empty_argument.validate(), Some(INVALID_PARAMS));
|
|
|
|
let empty_reference = command(json!({
|
|
"ref": {"type": "ref/prompt", "name": ""},
|
|
"argument": {"name": "tone", "value": ""}
|
|
}))
|
|
.expect("the request shape parses");
|
|
assert_eq!(empty_reference.validate(), Some(INVALID_PARAMS));
|
|
|
|
let long_uri = "u".repeat(MAX_REFERENCE_URI_BYTES + 1);
|
|
let oversized_uri = command(json!({
|
|
"ref": {"type": "ref/resource", "uri": long_uri},
|
|
"argument": {"name": "order_id", "value": ""}
|
|
}))
|
|
.expect("the request shape parses");
|
|
assert_eq!(oversized_uri.validate(), Some(INVALID_PARAMS));
|
|
}
|
|
|
|
#[test]
|
|
fn the_optional_context_is_validated_as_the_pinned_string_map() {
|
|
let non_string = command(json!({
|
|
"ref": {"type": "ref/prompt", "name": "greeting"},
|
|
"argument": {"name": "tone", "value": ""},
|
|
"context": {"arguments": {"region": 7}}
|
|
}))
|
|
.expect("the request shape parses");
|
|
assert_eq!(non_string.validate(), Some(INVALID_PARAMS));
|
|
|
|
let mut arguments = Map::new();
|
|
for index in 0..=MAX_CONTEXT_ARGUMENTS {
|
|
arguments.insert(format!("argument{index}"), json!("value"));
|
|
}
|
|
let too_many = command(json!({
|
|
"ref": {"type": "ref/prompt", "name": "greeting"},
|
|
"argument": {"name": "tone", "value": ""},
|
|
"context": {"arguments": arguments}
|
|
}))
|
|
.expect("the request shape parses");
|
|
assert_eq!(too_many.validate(), Some(INVALID_PARAMS));
|
|
}
|