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.
354 lines
13 KiB
Rust
354 lines
13 KiB
Rust
use crank_core::prompt::{
|
|
PromptDefinition, PromptDraft, PromptError, PromptMessage, PromptRole, PromptSensitivity,
|
|
PromptStatus,
|
|
};
|
|
use serde_json::{Map, json};
|
|
|
|
fn definition() -> serde_json::Value {
|
|
json!({
|
|
"name": "welcome",
|
|
"description": "Greeting",
|
|
"arguments": [
|
|
{"name":"name", "schema":{"type":"string"}, "required":true},
|
|
{"name":"tone", "schema":{"type":"string", "enum":["warm","plain"]}, "required":false, "default":"warm"}
|
|
],
|
|
"messages": [
|
|
{"role":"system", "content":"Be {{tone}}."},
|
|
{"role":"user", "content":"Welcome {{name}}."}
|
|
]
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn story312_prompt_draft_preserves_roles_order_and_typed_rendering() {
|
|
let prompt = PromptDefinition::parse(&definition()).unwrap();
|
|
let args = Map::from_iter([("name".into(), json!("Ada"))]);
|
|
assert_eq!(
|
|
prompt.preview(&args).unwrap(),
|
|
vec![
|
|
PromptMessage {
|
|
role: PromptRole::System,
|
|
content: "Be warm.".into(),
|
|
resource_refs: vec![],
|
|
},
|
|
PromptMessage {
|
|
role: PromptRole::User,
|
|
content: "Welcome Ada.".into(),
|
|
resource_refs: vec![],
|
|
},
|
|
]
|
|
);
|
|
assert_eq!(
|
|
prompt.preview(&args).unwrap(),
|
|
prompt.preview(&args).unwrap()
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn story312_optional_argument_without_default_is_not_required() {
|
|
let mut value = definition();
|
|
value["arguments"][1]
|
|
.as_object_mut()
|
|
.unwrap()
|
|
.remove("default");
|
|
let prompt = PromptDefinition::parse(&value).unwrap();
|
|
let args = Map::from_iter([("name".into(), json!("Ada"))]);
|
|
assert_eq!(prompt.preview(&args).unwrap()[0].content, "Be .");
|
|
}
|
|
|
|
#[test]
|
|
fn story312_prompt_draft_has_typed_identity_lifecycle_and_snapshot() {
|
|
let draft = PromptDraft::new(
|
|
crank_core::ids::PromptId::new("prm_example"),
|
|
PromptSensitivity::Internal,
|
|
PromptDefinition::parse(&definition()).unwrap(),
|
|
);
|
|
assert_eq!(draft.prompt_id().as_str(), "prm_example");
|
|
assert_eq!(draft.version(), 1);
|
|
assert_eq!(draft.status(), PromptStatus::Draft);
|
|
assert_eq!(draft.sensitivity(), PromptSensitivity::Internal);
|
|
let published = draft.published_snapshot();
|
|
assert_eq!(published.prompt_id().as_str(), "prm_example");
|
|
assert_eq!(published.version(), 1);
|
|
assert_eq!(published.definition().name(), "welcome");
|
|
}
|
|
|
|
#[test]
|
|
fn story313_published_snapshot_keeps_the_v1_value_when_a_second_draft_version_exists() {
|
|
let v1_definition = PromptDefinition::parse(&definition()).unwrap();
|
|
let snapshot = PromptDraft::from_parts(
|
|
crank_core::ids::PromptId::new("prm_story313"),
|
|
1,
|
|
PromptStatus::Draft,
|
|
PromptSensitivity::Internal,
|
|
v1_definition.clone(),
|
|
)
|
|
.unwrap()
|
|
.published_snapshot();
|
|
|
|
let mut edited = definition();
|
|
edited["description"] = json!("Edited after publication");
|
|
edited["arguments"][0]["required"] = json!(false);
|
|
edited["messages"][1]["content"] = json!("Count {{name}}.");
|
|
let next_draft = PromptDraft::from_parts(
|
|
crank_core::ids::PromptId::new("prm_story313"),
|
|
2,
|
|
PromptStatus::Draft,
|
|
PromptSensitivity::Internal,
|
|
PromptDefinition::parse(&edited).unwrap(),
|
|
)
|
|
.unwrap();
|
|
|
|
// Опубликованный value-снимок сохраняет точное значение v1 …
|
|
assert_eq!(snapshot.version(), 1);
|
|
assert_eq!(snapshot.definition(), &v1_definition);
|
|
assert_eq!(snapshot.definition().description(), "Greeting");
|
|
assert!(snapshot.definition().arguments()[0].required());
|
|
assert_eq!(
|
|
snapshot.definition().arguments()[1].default(),
|
|
Some(&json!("warm"))
|
|
);
|
|
assert_eq!(
|
|
snapshot.definition().messages()[1].content,
|
|
"Welcome {{name}}."
|
|
);
|
|
// … а новая Draft-версия несёт уже изменённое значение.
|
|
assert_eq!(next_draft.version(), 2);
|
|
assert_ne!(next_draft.definition(), snapshot.definition());
|
|
assert_eq!(
|
|
next_draft.definition().messages()[1].content,
|
|
"Count {{name}}."
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn story312_integer_arguments_are_rendered_as_scalar_values() {
|
|
let mut value = definition();
|
|
value["arguments"][0]["schema"]["type"] = json!("integer");
|
|
value["messages"][1]["content"] = json!("Count {{name}}.");
|
|
let prompt = PromptDefinition::parse(&value).unwrap();
|
|
let args = Map::from_iter([("name".into(), json!(7))]);
|
|
assert_eq!(prompt.preview(&args).unwrap()[1].content, "Count 7.");
|
|
}
|
|
|
|
#[test]
|
|
fn story312_boolean_and_number_arguments_render_as_json_scalars() {
|
|
let mut value = definition();
|
|
value["arguments"][0]["schema"]["type"] = json!("number");
|
|
value["arguments"].as_array_mut().unwrap().push(json!({
|
|
"name":"enabled", "schema":{"type":"boolean"}, "required":true
|
|
}));
|
|
value["messages"][1]["content"] = json!("Value={{name}}, enabled={{enabled}}");
|
|
let prompt = PromptDefinition::parse(&value).unwrap();
|
|
let args = Map::from_iter([("name".into(), json!(2.5)), ("enabled".into(), json!(true))]);
|
|
assert_eq!(
|
|
prompt.preview(&args).unwrap()[1].content,
|
|
"Value=2.5, enabled=true"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn story312_rejects_malformed_enum_schema_instead_of_dropping_constraint() {
|
|
let mut value = definition();
|
|
value["arguments"][1]["schema"]["enum"] = json!("not-an-array");
|
|
assert_eq!(
|
|
PromptDefinition::parse(&value),
|
|
Err(PromptError::InvalidDefinition)
|
|
);
|
|
let mut value = definition();
|
|
value["arguments"][1]["schema"]["enum"] = json!(["valid", 42]);
|
|
assert_eq!(
|
|
PromptDefinition::parse(&value),
|
|
Err(PromptError::InvalidDefinition)
|
|
);
|
|
let mut value = definition();
|
|
value["arguments"][1]["schema"]["maxLength"] = json!(8);
|
|
assert_eq!(
|
|
PromptDefinition::parse(&value),
|
|
Err(PromptError::InvalidDefinition)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn story312_preview_bounds_final_rendered_output() {
|
|
let mut value = definition();
|
|
value["messages"][0]["content"] = json!("{{name}}{{name}}");
|
|
let prompt = PromptDefinition::parse(&value).unwrap();
|
|
let args = Map::from_iter([("name".into(), json!("x".repeat(9_000)))]);
|
|
assert_eq!(prompt.preview(&args), Err(PromptError::InvalidTemplate));
|
|
}
|
|
|
|
#[test]
|
|
fn story312_invalid_args_fail_before_any_rendered_messages() {
|
|
let prompt = PromptDefinition::parse(&definition()).unwrap();
|
|
assert_eq!(
|
|
prompt.preview(&Map::new()),
|
|
Err(PromptError::MissingArgument("name".into()))
|
|
);
|
|
let mut args = Map::from_iter([("name".into(), json!("Ada")), ("extra".into(), json!(1))]);
|
|
assert_eq!(
|
|
prompt.preview(&args),
|
|
Err(PromptError::UnknownArgument("extra".into()))
|
|
);
|
|
args.remove("extra");
|
|
args.insert("tone".into(), json!("loud"));
|
|
assert_eq!(
|
|
prompt.preview(&args),
|
|
Err(PromptError::InvalidArgument("tone".into()))
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn story312_rejects_duplicate_arguments_unknown_roles_and_executable_templates() {
|
|
let mut value = definition();
|
|
value["arguments"]
|
|
.as_array_mut()
|
|
.unwrap()
|
|
.push(json!({"name":"name","schema":{"type":"string"},"required":true}));
|
|
assert!(PromptDefinition::parse(&value).is_err());
|
|
let mut value = definition();
|
|
value["messages"][0]["role"] = json!("developer");
|
|
assert!(PromptDefinition::parse(&value).is_err());
|
|
let mut value = definition();
|
|
value["messages"][0]["content"] = json!("{{= dangerous() }}");
|
|
assert!(PromptDefinition::parse(&value).is_err());
|
|
}
|
|
|
|
fn defaulted(default: serde_json::Value) -> serde_json::Value {
|
|
json!({
|
|
"name": "welcome",
|
|
"description": "Greeting",
|
|
"arguments": [{"name":"tone","schema":{"type":"string"},"required":false,"default":default}],
|
|
"messages": [{"role":"user","content":"{{tone}}"}]
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn story312_default_values_fit_the_stored_json_text_size() {
|
|
// Storage keeps `octet_length(default_value::text) <= 16384`; JSON adds the
|
|
// surrounding quotes, so 16382 bytes of plain text is the exact ceiling.
|
|
let at_limit = defaulted(json!("a".repeat(16_382)));
|
|
let prompt =
|
|
PromptDefinition::parse(&at_limit).expect("the exact storage boundary is accepted");
|
|
let rendered = prompt
|
|
.preview(&Map::new())
|
|
.expect("bounded default previews");
|
|
assert_eq!(rendered[0].content.len(), 16_382);
|
|
assert_eq!(
|
|
PromptDefinition::parse(&defaulted(json!("a".repeat(16_383)))),
|
|
Err(PromptError::InvalidDefinition)
|
|
);
|
|
|
|
// Escaped content costs more than one byte per character in PostgreSQL.
|
|
assert!(PromptDefinition::parse(&defaulted(json!("\"".repeat(8_190)))).is_ok());
|
|
assert_eq!(
|
|
PromptDefinition::parse(&defaulted(json!("\"".repeat(8_192)))),
|
|
Err(PromptError::InvalidDefinition)
|
|
);
|
|
assert!(PromptDefinition::parse(&defaulted(json!("\u{1}".repeat(2_730)))).is_ok());
|
|
assert_eq!(
|
|
PromptDefinition::parse(&defaulted(json!("\u{1}".repeat(2_731)))),
|
|
Err(PromptError::InvalidDefinition)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn story312_short_escape_defaults_match_the_postgres_jsonb_text_size() {
|
|
// PostgreSQL writes LF/TAB/CR/BS/FF as two-byte short escapes, while other
|
|
// control characters stay six-byte `\u00XX`, so both fit differently.
|
|
for (label, unit) in [
|
|
("lf", '\n'),
|
|
("tab", '\t'),
|
|
("cr", '\r'),
|
|
("backspace", '\u{8}'),
|
|
("formfeed", '\u{c}'),
|
|
] {
|
|
let at_limit = unit.to_string().repeat(8_191);
|
|
let prompt = PromptDefinition::parse(&defaulted(json!(at_limit))).unwrap_or_else(|error| {
|
|
panic!("{label} at the exact boundary must be accepted: {error:?}")
|
|
});
|
|
assert_eq!(
|
|
prompt.preview(&Map::new()).unwrap()[0].content,
|
|
unit.to_string().repeat(8_191),
|
|
"{label} defaults must preview the original text"
|
|
);
|
|
assert_eq!(
|
|
PromptDefinition::parse(&defaulted(json!(unit.to_string().repeat(8_192)))),
|
|
Err(PromptError::InvalidDefinition),
|
|
"{label} beyond the boundary is rejected"
|
|
);
|
|
}
|
|
// A multiline default stays well inside the guard even though it is long.
|
|
assert!(PromptDefinition::parse(&defaulted(json!("\n\t".repeat(4_000)))).is_ok());
|
|
// 0x01 still costs six bytes, so only 2730 of them fit.
|
|
assert!(PromptDefinition::parse(&defaulted(json!("\u{1}".repeat(2_730)))).is_ok());
|
|
assert_eq!(
|
|
PromptDefinition::parse(&defaulted(json!("\u{1}".repeat(2_731)))),
|
|
Err(PromptError::InvalidDefinition)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn story312_rejects_nul_before_storage_for_every_stored_string() {
|
|
// PostgreSQL refuses U+0000 in `text` ("null character not permitted") and in
|
|
// `jsonb` ("\\u0000 cannot be converted to text"), so it must fail as a
|
|
// structured definition error before any SQL runs.
|
|
assert_eq!(
|
|
PromptDefinition::parse(&defaulted(json!("a\u{0}b"))),
|
|
Err(PromptError::InvalidDefinition)
|
|
);
|
|
let mut enum_value = definition();
|
|
enum_value["arguments"][1]["schema"]["enum"] = json!(["warm", "a\u{0}b"]);
|
|
assert_eq!(
|
|
PromptDefinition::parse(&enum_value),
|
|
Err(PromptError::InvalidDefinition),
|
|
"an enum value is stored as jsonb and must not carry U+0000"
|
|
);
|
|
for (label, mutate) in [
|
|
(
|
|
"name",
|
|
Box::new(|value: &mut serde_json::Value| value["name"] = json!("a\u{0}b"))
|
|
as Box<dyn Fn(&mut serde_json::Value)>,
|
|
),
|
|
(
|
|
"description",
|
|
Box::new(|value: &mut serde_json::Value| value["description"] = json!("a\u{0}b")),
|
|
),
|
|
(
|
|
"argument name",
|
|
Box::new(|value: &mut serde_json::Value| {
|
|
value["arguments"][0]["name"] = json!("a\u{0}b")
|
|
}),
|
|
),
|
|
(
|
|
"message content",
|
|
Box::new(|value: &mut serde_json::Value| {
|
|
value["messages"][0]["content"] = json!("a\u{0}b")
|
|
}),
|
|
),
|
|
] {
|
|
let mut value = definition();
|
|
mutate(&mut value);
|
|
assert_eq!(
|
|
PromptDefinition::parse(&value),
|
|
Err(PromptError::InvalidDefinition),
|
|
"{label} is stored as text and must not carry U+0000"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn story312_enumeration_values_fit_the_stored_json_text_size() {
|
|
let mut value = defaulted(serde_json::Value::Null);
|
|
value["arguments"][0]["default"] = json!("x");
|
|
value["arguments"][0]["schema"]["enum"] = json!(["x"]);
|
|
assert!(PromptDefinition::parse(&value).is_ok());
|
|
value["arguments"][0]["schema"]["enum"] = json!(["x", "a".repeat(16_383)]);
|
|
assert_eq!(
|
|
PromptDefinition::parse(&value),
|
|
Err(PromptError::InvalidDefinition)
|
|
);
|
|
value["arguments"][0]["schema"]["enum"] = json!(["x", "a".repeat(16_382)]);
|
|
assert!(PromptDefinition::parse(&value).is_ok());
|
|
}
|