Files
crank/apps/mcp-server/tests/integration/static_resources/lifecycle.rs
T
Hermes DevOps 75fe5a123c [skip ci] wip: preserve Hermes crank development checkpoint
Owner-authorized recovery of accumulated source changes.
Includes accepted work and in-progress changes; NOT a release or acceptance.
Parent baseline 1b6db09bd1. Runtime data, build caches and local credentials excluded.
2026-10-25 10:00:22 +00:00

126 lines
5.0 KiB
Rust

//! Story 3.8 AC04 / AT-3.8-04: archiving a Published Resource Version after the Agent snapshot is
//! fixed must not break reproducible reads of the exact immutable snapshot, while archive refuses new
//! bindings. Explicit security revocation stays a separate audited transition and is NOT aliased to
//! archive here — its API does not exist yet (reported as a gap, not invented).
use super::super::common::test_workspace_id;
use super::fixtures::*;
#[tokio::test]
async fn archive_keeps_the_exact_published_snapshot_readable_for_the_bound_agent() {
let endpoint = standard_endpoint("archive_read").await;
endpoint.archive_text().await;
// The immutable publication row itself is untouched by archive.
let publication = endpoint
.registry
.resolve_resource_publication(test_workspace_id().as_str(), &endpoint.text.id, 1)
.await
.expect("archiving must not remove the exact published version");
assert_eq!(
publication.publication.digest,
digest_hex(&endpoint.text.bytes),
"archive must not rewrite the published digest"
);
let expected = String::from_utf8(endpoint.text.bytes.clone()).expect("text fixture is UTF-8");
for revision in supported_revisions() {
let body =
json_body(read_resource(&endpoint, &revision, &endpoint.text.uri, None).await).await;
let result = result_of(&body, &format!("post-archive resources/read on {revision}"));
let contents = result["contents"].as_array().unwrap_or_else(|| {
panic!("post-archive read must return contents on {revision}: {body}")
});
assert_eq!(
contents.len(),
1,
"post-archive read must return one content entry on {revision}: {body}"
);
assert_eq!(
contents[0]["text"].as_str(),
Some(expected.as_str()),
"post-archive read must return the exact immutable snapshot on {revision}: {body}"
);
}
}
/// Archive refuses new bindings, including for a still-mutable Draft Agent version.
#[tokio::test]
async fn archive_refuses_new_resource_bindings() {
let endpoint = standard_endpoint("archive_binding_guard").await;
let binding = crank_registry::AgentResourceBinding {
resource_id: endpoint.text.id.clone(),
resource_version: 1,
};
// Positive control: while the Resource is published and active, a Draft Agent accepts the binding.
endpoint
.registry
.save_agent_catalog_config(crank_registry::SaveAgentCatalogConfigRequest {
workspace_id: &test_workspace_id(),
agent_id: &endpoint.draft_agent_id,
agent_version: 1,
bindings: &[],
tool_selection_policy: &crank_core::ToolSelectionPolicy::default(),
resource_bindings: std::slice::from_ref(&binding),
expected_state: None,
})
.await
.expect("an active published Resource must be bindable");
// Drop the control binding again so the post-archive attempt is a genuinely new binding.
endpoint
.registry
.save_agent_catalog_config(crank_registry::SaveAgentCatalogConfigRequest {
workspace_id: &test_workspace_id(),
agent_id: &endpoint.draft_agent_id,
agent_version: 1,
bindings: &[],
tool_selection_policy: &crank_core::ToolSelectionPolicy::default(),
resource_bindings: &[],
expected_state: None,
})
.await
.expect("a Draft Agent must stay mutable");
endpoint.archive_text().await;
let denied = endpoint
.registry
.save_agent_catalog_config(crank_registry::SaveAgentCatalogConfigRequest {
workspace_id: &test_workspace_id(),
agent_id: &endpoint.draft_agent_id,
agent_version: 1,
bindings: &[],
tool_selection_policy: &crank_core::ToolSelectionPolicy::default(),
resource_bindings: &[binding],
expected_state: None,
})
.await;
assert!(
denied.is_err(),
"an archived Resource must not be accepted as a new Agent binding, got {denied:?}"
);
let rows: i64 = sqlx::query_scalar(
"select count(*) from agent_resource_bindings where agent_id = $1 and agent_version = 1",
)
.bind(endpoint.draft_agent_id.as_str())
.fetch_one(endpoint.registry.pool())
.await
.expect("binding rows must be queryable");
assert_eq!(rows, 0, "a refused binding must not persist any row");
// Sanity: the refused attempt must not have been a no-op for another reason.
let published = endpoint
.registry
.get_agent_version(&test_workspace_id(), &endpoint.agent_id, 1)
.await
.expect("the bound Agent version must be readable")
.expect("the bound Agent version must exist");
assert_eq!(
published.resource_bindings.len(),
3,
"the published Agent snapshot must keep its three exact Resource bindings: {published:?}"
);
}