Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f18bce679 | ||
|
|
4ec9d9201b | ||
|
|
cf2909273b | ||
|
|
4a7b230f35 | ||
|
|
cfe11a0a04 |
No files matched your search
@@ -40,6 +40,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Detect release-tooling-only changes
|
||||||
|
id: release_tooling
|
||||||
|
env:
|
||||||
|
GITEA_EVENT_NAME: ${{ gitea.event_name }}
|
||||||
|
GITEA_EVENT_BEFORE: ${{ gitea.event.before }}
|
||||||
|
GITEA_PR_BASE_SHA: ${{ gitea.event.pull_request.base.sha }}
|
||||||
|
FORCE_FULL: ${{ inputs.validation_level == 'feature' || contains(gitea.event.pull_request.labels.*.name, 'feature-ready') }}
|
||||||
|
run: python3 scripts/ci-release-tooling-scope.py
|
||||||
|
|
||||||
- name: Install Rust toolchain
|
- name: Install Rust toolchain
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
@@ -78,15 +87,18 @@ jobs:
|
|||||||
docker info
|
docker info
|
||||||
|
|
||||||
- name: Check typed runtime configuration contract
|
- name: Check typed runtime configuration contract
|
||||||
|
if: steps.release_tooling.outputs.ci_only != 'true'
|
||||||
run: |
|
run: |
|
||||||
cargo run -p crank-config --bin crank-config-contract -- --check
|
cargo run -p crank-config --bin crank-config-contract -- --check
|
||||||
python3 scripts/check-runtime-config.py --root .
|
python3 scripts/check-runtime-config.py --root .
|
||||||
python3 scripts/check-config-boundaries.py --root .
|
python3 scripts/check-config-boundaries.py --root .
|
||||||
|
|
||||||
- name: Check canonical migration contract
|
- name: Check canonical migration contract
|
||||||
|
if: steps.release_tooling.outputs.ci_only != 'true'
|
||||||
run: cargo run -p admin-api --bin crank-migrate -- plan --check
|
run: cargo run -p admin-api --bin crank-migrate -- plan --check
|
||||||
|
|
||||||
- name: Check typed metrics contract
|
- name: Check typed metrics contract
|
||||||
|
if: steps.release_tooling.outputs.ci_only != 'true'
|
||||||
run: |
|
run: |
|
||||||
cargo run -p crank-metrics --bin crank-metrics-contract -- --check
|
cargo run -p crank-metrics --bin crank-metrics-contract -- --check
|
||||||
python3 scripts/check-metrics-boundaries.py --root .
|
python3 scripts/check-metrics-boundaries.py --root .
|
||||||
@@ -142,6 +154,7 @@ jobs:
|
|||||||
python3 scripts/check-openapi-matrix-compatibility.py --base "$base_ref"
|
python3 scripts/check-openapi-matrix-compatibility.py --base "$base_ref"
|
||||||
|
|
||||||
- name: Run Crank story ATDD
|
- name: Run Crank story ATDD
|
||||||
|
if: steps.release_tooling.outputs.ci_only != 'true'
|
||||||
run: scripts/ci-story-checks.sh
|
run: scripts/ci-story-checks.sh
|
||||||
ui:
|
ui:
|
||||||
name: UI Checks
|
name: UI Checks
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ tokio = { workspace = true, features = ["sync"] }
|
|||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
uuid.workspace = true
|
uuid.workspace = true
|
||||||
|
|
||||||
|
# Typed Tools dispatch uses the SDK; its HTTP transport remains test-only.
|
||||||
|
rmcp = { version = "=3.7.0" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rmcp = { version = "=3.7.0", features = ["transport-streamable-http-server"] }
|
rmcp = { version = "=3.7.0", features = ["transport-streamable-http-server"] }
|
||||||
crank-mapping = { path = "../crank-mapping" }
|
crank-mapping = { path = "../crank-mapping" }
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ pub(crate) mod lifecycle;
|
|||||||
mod metrics;
|
mod metrics;
|
||||||
mod request;
|
mod request;
|
||||||
mod response;
|
mod response;
|
||||||
|
mod rmcp_dispatch;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod rmcp_http;
|
mod rmcp_http;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
use super::request::{InitializeParams, ToolCallParams};
|
use super::request::{InitializeParams, ToolCallParams};
|
||||||
use super::response::take_confirmation_token;
|
use super::response::take_confirmation_token;
|
||||||
|
use super::rmcp_dispatch::handle_tools_command;
|
||||||
use crate::{
|
use crate::{
|
||||||
auth::VerifiedMachineCredential,
|
auth::VerifiedMachineCredential,
|
||||||
jsonrpc::{
|
jsonrpc::{
|
||||||
@@ -19,7 +20,7 @@ use crate::{
|
|||||||
ResourceReadCommand, ResourcesCommand, ResourcesListCommand, ResourcesOutcome,
|
ResourceReadCommand, ResourcesCommand, ResourcesListCommand, ResourcesOutcome,
|
||||||
ServiceContext, ToolCallCommand, ToolsCommand, ToolsListCommand, ToolsOutcome,
|
ServiceContext, ToolCallCommand, ToolsCommand, ToolsListCommand, ToolsOutcome,
|
||||||
declared_mcp_method, discover_result, handle_completion_command, handle_prompts_command,
|
declared_mcp_method, discover_result, handle_completion_command, handle_prompts_command,
|
||||||
handle_resources_command, handle_tools_command, validate_modern_request_name,
|
handle_resources_command, validate_modern_request_name,
|
||||||
},
|
},
|
||||||
session::SessionState,
|
session::SessionState,
|
||||||
tool_error::execution_locale,
|
tool_error::execution_locale,
|
||||||
|
|||||||
@@ -51,9 +51,15 @@ pub(crate) struct CounterSet {
|
|||||||
era_modern: AtomicUsize,
|
era_modern: AtomicUsize,
|
||||||
era_legacy: AtomicUsize,
|
era_legacy: AtomicUsize,
|
||||||
tools_service: AtomicUsize,
|
tools_service: AtomicUsize,
|
||||||
|
sdk_tools_dispatch: AtomicUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CounterSet {
|
impl CounterSet {
|
||||||
|
/// SDK typed Tools dispatch entries, separate from the existing era/service snapshot.
|
||||||
|
pub(crate) fn sdk_tools_dispatch(&self) -> usize {
|
||||||
|
self.sdk_tools_dispatch.load(Ordering::SeqCst)
|
||||||
|
}
|
||||||
|
|
||||||
/// Read the counters of one observed request as one comparable snapshot.
|
/// Read the counters of one observed request as one comparable snapshot.
|
||||||
pub(crate) fn snapshot(&self) -> Snapshot {
|
pub(crate) fn snapshot(&self) -> Snapshot {
|
||||||
Snapshot {
|
Snapshot {
|
||||||
@@ -134,6 +140,11 @@ pub(crate) fn tools_service_enter() {
|
|||||||
increment(|counters| &counters.tools_service);
|
increment(|counters| &counters.tools_service);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `SDK_TOOLS_DISPATCH`: entered the real SDK typed Tools dispatch, not just admission.
|
||||||
|
pub(crate) fn sdk_tools_dispatch_enter() {
|
||||||
|
increment(|counters| &counters.sdk_tools_dispatch);
|
||||||
|
}
|
||||||
|
|
||||||
fn increment(counter: impl Fn(&CounterSet) -> &AtomicUsize) {
|
fn increment(counter: impl Fn(&CounterSet) -> &AtomicUsize) {
|
||||||
let _ = OBSERVER.try_with(|counters| {
|
let _ = OBSERVER.try_with(|counters| {
|
||||||
counter(counters).fetch_add(1, Ordering::SeqCst);
|
counter(counters).fetch_add(1, Ordering::SeqCst);
|
||||||
@@ -153,3 +164,7 @@ pub(crate) mod support;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[path = "../dispatch_observer_harness.rs"]
|
#[path = "../dispatch_observer_harness.rs"]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[path = "../rmcp_runtime_tests.rs"]
|
||||||
|
mod rmcp_runtime_tests;
|
||||||
@@ -24,6 +24,7 @@ use super::response::{
|
|||||||
resource_templates_list_result, resources_list_result, take_confirmation_token,
|
resource_templates_list_result, resources_list_result, take_confirmation_token,
|
||||||
tools_list_result,
|
tools_list_result,
|
||||||
};
|
};
|
||||||
|
use super::rmcp_dispatch::handle_tools_command;
|
||||||
use super::{AgentRoutePath, AppState};
|
use super::{AgentRoutePath, AppState};
|
||||||
use crate::{
|
use crate::{
|
||||||
auth::VerifiedMachineCredential,
|
auth::VerifiedMachineCredential,
|
||||||
@@ -38,7 +39,6 @@ use crate::{
|
|||||||
ResourcesCommand, ResourcesListCommand, ResourcesOutcome, ServiceContext, SetLevelCommand,
|
ResourcesCommand, ResourcesListCommand, ResourcesOutcome, ServiceContext, SetLevelCommand,
|
||||||
ToolCallCommand, ToolsCommand, ToolsListCommand, ToolsOutcome, handle_completion_command,
|
ToolCallCommand, ToolsCommand, ToolsListCommand, ToolsOutcome, handle_completion_command,
|
||||||
handle_logging_command, handle_prompts_command, handle_resources_command,
|
handle_logging_command, handle_prompts_command, handle_resources_command,
|
||||||
handle_tools_command,
|
|
||||||
},
|
},
|
||||||
tool_error::execution_locale,
|
tool_error::execution_locale,
|
||||||
transport::{ResponseMode, session_id_from_headers, transport_response},
|
transport::{ResponseMode, session_id_from_headers, transport_response},
|
||||||
|
|||||||
@@ -37,16 +37,14 @@ use futures_util::stream;
|
|||||||
use serde_json::{Number, Value, json};
|
use serde_json::{Number, Value, json};
|
||||||
use tokio::sync::{mpsc, watch};
|
use tokio::sync::{mpsc, watch};
|
||||||
|
|
||||||
|
use super::rmcp_dispatch::handle_tools_command;
|
||||||
use super::{
|
use super::{
|
||||||
AppState,
|
AppState,
|
||||||
response::{ToolCommandPayload, tool_command_payload, tool_command_response},
|
response::{ToolCommandPayload, tool_command_payload, tool_command_response},
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
jsonrpc::request_id,
|
jsonrpc::request_id,
|
||||||
protocol::{
|
protocol::{ContinuationSupport, ServiceContext, ToolCallCommand, ToolsCommand, ToolsOutcome},
|
||||||
ContinuationSupport, ServiceContext, ToolCallCommand, ToolsCommand, ToolsOutcome,
|
|
||||||
handle_tools_command,
|
|
||||||
},
|
|
||||||
transport::{ResponseMode, sse_response},
|
transport::{ResponseMode, sse_response},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
//! Runtime SDK Tools dispatch; admission, lifecycle and response projection stay with the caller.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use rmcp::model::{CallToolRequestParams, PaginatedRequestParams};
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use super::{AppState, lifecycle::ToolCallLifecycle};
|
||||||
|
use crate::protocol::{
|
||||||
|
ServiceContext, ToolCallCommand, ToolCallOutcome, ToolsCommand, ToolsListCommand, ToolsOutcome,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Crank extensions are not SDK fields and must survive the typed request boundary unchanged.
|
||||||
|
enum SdkToolsCommand {
|
||||||
|
List {
|
||||||
|
params: PaginatedRequestParams,
|
||||||
|
limit: Option<usize>,
|
||||||
|
},
|
||||||
|
Call {
|
||||||
|
params: CallToolRequestParams,
|
||||||
|
confirmation_token: Option<String>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) async fn handle_tools_command(
|
||||||
|
state: &Arc<AppState>,
|
||||||
|
context: ServiceContext<'_>,
|
||||||
|
command: ToolsCommand,
|
||||||
|
lifecycle: Option<ToolCallLifecycle>,
|
||||||
|
) -> ToolsOutcome {
|
||||||
|
let request = match command {
|
||||||
|
ToolsCommand::List(list) => SdkToolsCommand::List {
|
||||||
|
params: PaginatedRequestParams::default().with_cursor(list.cursor),
|
||||||
|
limit: list.limit,
|
||||||
|
},
|
||||||
|
ToolsCommand::Call(call) => {
|
||||||
|
let Value::Object(arguments) = call.arguments else {
|
||||||
|
return ToolsOutcome::Call(ToolCallOutcome::InvalidParams(
|
||||||
|
"tool arguments must be an object".to_owned(),
|
||||||
|
));
|
||||||
|
};
|
||||||
|
SdkToolsCommand::Call {
|
||||||
|
params: CallToolRequestParams::new(call.tool_name).with_arguments(arguments),
|
||||||
|
confirmation_token: call.confirmation_token,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
super::dispatch_observer::sdk_tools_dispatch_enter();
|
||||||
|
|
||||||
|
let command = match request {
|
||||||
|
SdkToolsCommand::List { params, limit } => ToolsCommand::List(ToolsListCommand {
|
||||||
|
cursor: params.cursor,
|
||||||
|
limit,
|
||||||
|
}),
|
||||||
|
SdkToolsCommand::Call {
|
||||||
|
params,
|
||||||
|
confirmation_token,
|
||||||
|
} => ToolsCommand::Call(ToolCallCommand {
|
||||||
|
tool_name: params.name.into_owned(),
|
||||||
|
arguments: Value::Object(params.arguments.unwrap_or_default()),
|
||||||
|
confirmation_token,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
crate::protocol::handle_tools_command(state, context, command, lifecycle).await
|
||||||
|
}
|
||||||
@@ -0,0 +1,356 @@
|
|||||||
|
//! #107: real build_app endpoint controls plus a separate SDK structural seam oracle.
|
||||||
|
//! No SDK transport router is used. The structural oracle alone does not prove wire parity.
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
sync::{
|
||||||
|
Arc,
|
||||||
|
atomic::{AtomicUsize, Ordering},
|
||||||
|
},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
|
use axum::{Router, routing::post};
|
||||||
|
use crank_core::{
|
||||||
|
AgentOperationBinding, AgentStatus, AgentVersion, PlatformApiKeyId, ToolSelectionPolicy,
|
||||||
|
};
|
||||||
|
use crank_registry::{
|
||||||
|
CreateAgentDraftVersionRequest, PostgresRegistry, PublishAgentRequest, PublishRequest,
|
||||||
|
};
|
||||||
|
use crank_runtime::{
|
||||||
|
InMemoryCoordinationStateStore, RequestRateLimitConfig, RequestRateLimiter, SecretCrypto,
|
||||||
|
};
|
||||||
|
use serde_json::{Value, json};
|
||||||
|
|
||||||
|
use super::{CounterSet, observe, sdk_tools_dispatch_enter, support::*};
|
||||||
|
|
||||||
|
struct Server(tokio::task::JoinHandle<()>, String);
|
||||||
|
|
||||||
|
impl Drop for Server {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn serve(app: Router) -> Server {
|
||||||
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||||
|
let address = listener.local_addr().unwrap();
|
||||||
|
Server(
|
||||||
|
tokio::spawn(async move {
|
||||||
|
axum::serve(listener, app).await.unwrap();
|
||||||
|
}),
|
||||||
|
format!("http://{address}"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Endpoint {
|
||||||
|
server: Server,
|
||||||
|
_upstream: Server,
|
||||||
|
registry: PostgresRegistry,
|
||||||
|
key: String,
|
||||||
|
counters: Arc<CounterSet>,
|
||||||
|
calls: Arc<AtomicUsize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Endpoint {
|
||||||
|
async fn started() -> Self {
|
||||||
|
// First caller owns the process-wide fixture and its atexit cleanup, including RED panics.
|
||||||
|
let _ =
|
||||||
|
crank_test_support::postgres_schema_url_for_task("rmcp_runtime_owner", "t_aaaea124")
|
||||||
|
.await;
|
||||||
|
let registry = test_registry().await;
|
||||||
|
let calls = Arc::new(AtomicUsize::new(0));
|
||||||
|
let upstream = serve(
|
||||||
|
Router::new()
|
||||||
|
.route("/crm/leads", post(create_lead))
|
||||||
|
.with_state(calls.clone()),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let operation = test_operation(&upstream.1);
|
||||||
|
registry
|
||||||
|
.create_operation(&workspace_id(), &operation, Some("alice"))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
registry
|
||||||
|
.publish_operation(PublishRequest {
|
||||||
|
workspace_id: &workspace_id(),
|
||||||
|
operation_id: &operation.id,
|
||||||
|
version: 1,
|
||||||
|
published_at: &test_time(),
|
||||||
|
published_by: Some("alice"),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
publish_agent(®istry, &operation).await;
|
||||||
|
let key = create_api_key(®istry).await;
|
||||||
|
let counters = Arc::new(CounterSet::default());
|
||||||
|
let app = crate::build_app(
|
||||||
|
registry.clone(),
|
||||||
|
Duration::ZERO,
|
||||||
|
Some("https://crank.example.com".into()),
|
||||||
|
SecretCrypto::new("test-master-key-00000000000000000000000000000000").unwrap(),
|
||||||
|
crank_runtime::community_with_outbound_policy(
|
||||||
|
crank_runtime::OutboundHttpPolicy::allowing_hosts(["127.0.0.1"]),
|
||||||
|
)
|
||||||
|
.build(),
|
||||||
|
RequestRateLimiter::new(RequestRateLimitConfig::new(10_000, 10_000).unwrap()),
|
||||||
|
Arc::new(InMemoryCoordinationStateStore::default()),
|
||||||
|
Arc::new(crate::session::InMemorySessionStore::default()),
|
||||||
|
Arc::new(crate::auth::CommunityMachineCredentialVerifier),
|
||||||
|
);
|
||||||
|
let server = serve(observe_requests(app, counters.clone(), None)).await;
|
||||||
|
Self {
|
||||||
|
server,
|
||||||
|
_upstream: upstream,
|
||||||
|
registry,
|
||||||
|
key,
|
||||||
|
counters,
|
||||||
|
calls,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn post(&self, revision: &str, session: Option<&str>, body: &Value) -> reqwest::Response {
|
||||||
|
let mut request = reqwest::Client::new()
|
||||||
|
.post(format!(
|
||||||
|
"{}/v1/{WORKSPACE_SLUG}/{AGENT_SLUG}",
|
||||||
|
self.server.1
|
||||||
|
))
|
||||||
|
.bearer_auth(&self.key)
|
||||||
|
// Also guards the legacy JSON-only contract; no SSE parsing fallback here.
|
||||||
|
.header("Accept", "application/json")
|
||||||
|
.header("MCP-Protocol-Version", revision);
|
||||||
|
if let Some(session) = session {
|
||||||
|
request = request.header("MCP-Session-Id", session);
|
||||||
|
}
|
||||||
|
if revision == MODERN_REVISION {
|
||||||
|
request = request.header("Mcp-Method", body["method"].as_str().unwrap());
|
||||||
|
if let Some(name) = body["params"]["name"].as_str() {
|
||||||
|
request = request.header("Mcp-Name", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request.json(body).send().await.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn session(&self, revision: &str) -> Option<String> {
|
||||||
|
if revision == MODERN_REVISION {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let response = self.post(revision, None, &legacy_initialize(1)).await;
|
||||||
|
assert_eq!(response.status(), 200);
|
||||||
|
let session = response.headers()["MCP-Session-Id"]
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_owned();
|
||||||
|
let body = json_body(response).await;
|
||||||
|
assert_eq!(body["result"]["protocolVersion"], revision);
|
||||||
|
assert!(body["result"]["capabilities"]["tools"].is_object());
|
||||||
|
let response = self
|
||||||
|
.post(revision, Some(&session), &initialized_notification())
|
||||||
|
.await;
|
||||||
|
assert_eq!(response.status(), 202);
|
||||||
|
Some(session)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn list(&self, revision: &str, session: Option<&str>, expected_name: &str) -> usize {
|
||||||
|
let before = self.counters.sdk_tools_dispatch();
|
||||||
|
let mut body = json!({"jsonrpc":"2.0", "id":10, "method":"tools/list", "params":{}});
|
||||||
|
if revision == MODERN_REVISION {
|
||||||
|
body["params"]["_meta"] = modern_meta();
|
||||||
|
}
|
||||||
|
let calls = self.calls.load(Ordering::SeqCst);
|
||||||
|
let response = self.post(revision, session, &body).await;
|
||||||
|
assert_eq!(response.status(), 200);
|
||||||
|
assert!(
|
||||||
|
response.headers()["content-type"]
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.starts_with("application/json")
|
||||||
|
);
|
||||||
|
let body = json_body(response).await;
|
||||||
|
assert_eq!(body["id"], 10);
|
||||||
|
assert_eq!(body["result"]["tools"].as_array().unwrap().len(), 1);
|
||||||
|
assert_eq!(body["result"]["tools"][0]["name"], expected_name);
|
||||||
|
assert!(body["error"].is_null(), "{body}");
|
||||||
|
assert_eq!(
|
||||||
|
self.calls.load(Ordering::SeqCst),
|
||||||
|
calls,
|
||||||
|
"listing must not execute upstream"
|
||||||
|
);
|
||||||
|
self.counters.sdk_tools_dispatch() - before
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn call(&self, revision: &str, session: Option<&str>, name: &str, email: &str) -> usize {
|
||||||
|
let before = self.counters.sdk_tools_dispatch();
|
||||||
|
let arrivals = self.calls.load(Ordering::SeqCst);
|
||||||
|
let mut body = if revision == MODERN_REVISION {
|
||||||
|
modern_tool_call(11, email)
|
||||||
|
} else {
|
||||||
|
legacy_tool_call(11, email)
|
||||||
|
};
|
||||||
|
body["params"]["name"] = json!(name);
|
||||||
|
let response = self.post(revision, session, &body).await;
|
||||||
|
assert_eq!(response.status(), 200);
|
||||||
|
assert!(
|
||||||
|
response.headers()["content-type"]
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.starts_with("application/json")
|
||||||
|
);
|
||||||
|
let body = json_body(response).await;
|
||||||
|
assert_eq!(body["id"], 11);
|
||||||
|
assert!(body["error"].is_null(), "{body}");
|
||||||
|
assert_ne!(body["result"]["isError"], true, "{body}");
|
||||||
|
assert_scoped_output(revision, &body, email);
|
||||||
|
if revision == MODERN_REVISION {
|
||||||
|
assert_eq!(body["result"]["resultType"], "complete");
|
||||||
|
}
|
||||||
|
assert_eq!(self.calls.load(Ordering::SeqCst) - arrivals, 1);
|
||||||
|
self.counters.sdk_tools_dispatch() - before
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn publish_renamed_tool(&self) {
|
||||||
|
let now = time::OffsetDateTime::now_utc();
|
||||||
|
let version = AgentVersion {
|
||||||
|
agent_id: agent_id(),
|
||||||
|
version: 2,
|
||||||
|
status: AgentStatus::Draft,
|
||||||
|
instructions: json!({}),
|
||||||
|
tool_selection_policy: ToolSelectionPolicy::default(),
|
||||||
|
created_at: now,
|
||||||
|
};
|
||||||
|
let bindings = [AgentOperationBinding {
|
||||||
|
operation_id: crank_core::OperationId::new("op_create_lead"),
|
||||||
|
operation_version: 1,
|
||||||
|
tool_name: "new_publication_tool".into(),
|
||||||
|
tool_title: "New Tool".into(),
|
||||||
|
tool_description_override: None,
|
||||||
|
enabled: true,
|
||||||
|
}];
|
||||||
|
self.registry
|
||||||
|
.create_agent_draft_version(CreateAgentDraftVersionRequest {
|
||||||
|
workspace_id: &workspace_id(),
|
||||||
|
agent_id: &agent_id(),
|
||||||
|
version: &version,
|
||||||
|
bindings: &bindings,
|
||||||
|
updated_at: &now,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
self.registry
|
||||||
|
.publish_agent(PublishAgentRequest {
|
||||||
|
workspace_id: &workspace_id(),
|
||||||
|
agent_id: &agent_id(),
|
||||||
|
version: 2,
|
||||||
|
published_at: &now,
|
||||||
|
published_by: Some("alice"),
|
||||||
|
expected_state: None,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn endpoint_control(revision: &str) -> [usize; 2] {
|
||||||
|
let h = Endpoint::started().await;
|
||||||
|
let session = h.session(revision).await;
|
||||||
|
let session = session.as_deref();
|
||||||
|
let list_dispatches = h.list(revision, session, TOOL_NAME).await;
|
||||||
|
let call_dispatches = h
|
||||||
|
.call(
|
||||||
|
revision,
|
||||||
|
session,
|
||||||
|
TOOL_NAME,
|
||||||
|
&format!("{revision}@example.test"),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
// A fresh publication must be visible without reinitialize or a new endpoint.
|
||||||
|
h.publish_renamed_tool().await;
|
||||||
|
h.list(revision, session, "new_publication_tool").await;
|
||||||
|
h.call(
|
||||||
|
revision,
|
||||||
|
session,
|
||||||
|
"new_publication_tool",
|
||||||
|
"new-publication@example.test",
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
h.registry
|
||||||
|
.revoke_platform_api_key(
|
||||||
|
&workspace_id(),
|
||||||
|
&PlatformApiKeyId::new("pk_dispatch_observer"),
|
||||||
|
&time::OffsetDateTime::now_utc(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let before_sdk = h.counters.sdk_tools_dispatch();
|
||||||
|
let arrivals = h.calls.load(Ordering::SeqCst);
|
||||||
|
let mut denied = if revision == MODERN_REVISION {
|
||||||
|
modern_tool_call(12, "denied@example.test")
|
||||||
|
} else {
|
||||||
|
legacy_tool_call(12, "denied@example.test")
|
||||||
|
};
|
||||||
|
denied["params"]["name"] = json!("new_publication_tool");
|
||||||
|
assert_eq!(h.post(revision, session, &denied).await.status(), 401);
|
||||||
|
assert_eq!(
|
||||||
|
h.calls.load(Ordering::SeqCst),
|
||||||
|
arrivals,
|
||||||
|
"revoked credential must not execute upstream"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
h.counters.sdk_tools_dispatch(),
|
||||||
|
before_sdk,
|
||||||
|
"revocation must reject before SDK dispatch"
|
||||||
|
);
|
||||||
|
eprintln!(
|
||||||
|
"existing GREEN {revision}: JSON list/call, scoped output, upstream=2, publication refresh, revoked=401/no outbound; SDK list/call deltas={:?}",
|
||||||
|
[list_dispatches, call_dispatches]
|
||||||
|
);
|
||||||
|
[list_dispatches, call_dispatches]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn rmcp_runtime_existing_wire_modern() {
|
||||||
|
endpoint_control(MODERN_REVISION).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn rmcp_runtime_existing_wire_legacy() {
|
||||||
|
endpoint_control(LEGACY_REVISION).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn rmcp_runtime_sdk_dispatch_modern() {
|
||||||
|
let counts = endpoint_control(MODERN_REVISION).await;
|
||||||
|
assert_eq!(
|
||||||
|
counts,
|
||||||
|
[1, 1],
|
||||||
|
"real endpoint tools/list and tools/call must each enter SDK typed dispatch once (structural seam oracle)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn rmcp_runtime_sdk_dispatch_legacy() {
|
||||||
|
let counts = endpoint_control(LEGACY_REVISION).await;
|
||||||
|
assert_eq!(
|
||||||
|
counts,
|
||||||
|
[1, 1],
|
||||||
|
"real endpoint tools/list and tools/call must each enter SDK typed dispatch once (structural seam oracle)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn rmcp_runtime_observer_is_request_scoped() {
|
||||||
|
let counters = Arc::new(CounterSet::default());
|
||||||
|
sdk_tools_dispatch_enter();
|
||||||
|
assert_eq!(counters.sdk_tools_dispatch(), 0);
|
||||||
|
observe(counters.clone(), async {
|
||||||
|
sdk_tools_dispatch_enter();
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
assert_eq!(counters.sdk_tools_dispatch(), 1);
|
||||||
|
let other = Arc::new(CounterSet::default());
|
||||||
|
observe(other.clone(), async {
|
||||||
|
sdk_tools_dispatch_enter();
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
assert_eq!(other.sdk_tools_dispatch(), 1);
|
||||||
|
assert_eq!(counters.sdk_tools_dispatch(), 1);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Переход Crank на официальный MCP SDK rmcp
|
# Переход Crank на официальный MCP SDK rmcp
|
||||||
|
|
||||||
Статус: планирование одобрено владельцем 27.10.2026; 05.11.2026 отдельно разрешён только изолированный опыт этапа 1 (#106). Этапы 2/3 (#107/#108), новая реализация 4.7 и production-переключение этим разрешением не запускаются. Исполняемый кандидат и конкретные несовместимости: [rmcp106-tools-adapter.md](rmcp106-tools-adapter.md); это не завершённая миграция. Владелец очереди — hermes_tl; реализация — hermes_dev; независимая проверка — hermes_qa; Git/CI/релизы — hermes_devops. ARC подключается к конкретному техническому затруднению, не как обязательный новый этап. Business reconciliation 4.6 отменена решением владельца и [issue #34](https://git.itexp.me/bsodfather/crank/issues/34); она не prerequisite SDK. Input/unknown safety и остальные защитные ограничения сохраняются.
|
Статус: планирование одобрено владельцем 27.10.2026; 05.11.2026 разрешён изолированный опыт этапа 1 (#106), поставленный в v0.4.0-rc.15. [Решением владельца 08.11.2026](https://git.itexp.me/bsodfather/crank/issues/107#issuecomment-2463) разрешён первый Tools-срез этапа 2 (#107) в действующем endpoint без смены transport. #108, новая реализация 4.7 и production-переключение этим разрешением не запускаются. Исполняемый кандидат и конкретные несовместимости: [rmcp106-tools-adapter.md](rmcp106-tools-adapter.md); это не завершённая миграция. Владелец очереди — hermes_tl; реализация — hermes_dev; независимая проверка — hermes_qa; Git/CI/релизы — hermes_devops. ARC подключается к конкретному техническому затруднению, не как обязательный новый этап. Business reconciliation 4.6 отменена решением владельца и [issue #34](https://git.itexp.me/bsodfather/crank/issues/34); она не prerequisite SDK. Input/unknown safety и остальные защитные ограничения сохраняются.
|
||||||
|
|
||||||
## Результат
|
## Результат
|
||||||
|
|
||||||
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
Подключить SDK к действующему пути и перенести стандартные envelopes, dispatch, lifecycle и transport. Порядок переноса устанавливается по результату первого опыта, без параллельных writers одних MCP-файлов.
|
Подключить SDK к действующему пути и перенести стандартные envelopes, dispatch, lifecycle и transport. Порядок переноса устанавливается по результату первого опыта, без параллельных writers одних MCP-файлов.
|
||||||
|
|
||||||
|
Первый срез #107: `build_app` направляет `tools/list` обеих revisions и `tools/call` через `app/rmcp_dispatch.rs`. Параметры rmcp=3.7.0 (`PaginatedRequestParams`/`CallToolRequestParams`) определяют команду существующего shared Tools service; расширения Crank `limit`/confirmation сохраняются отдельно. Потребитель — штатный MCP HTTP клиент, не изолированный router #106. Текущие admission, свежая identity, lifecycle, era-specific ответы и PostgreSQL sessions остаются у прежнего transport; SDK HTTP transport не подключён. Это только Tools request dispatch/model seam: SDK response envelopes, остальные handlers, transport и lifecycle ещё не перенесены. Полный #107 не завершён; проверки #106 не являются доказательством завершения миграции.
|
||||||
|
|
||||||
Проверяемый результат:
|
Проверяемый результат:
|
||||||
|
|
||||||
- Через SDK проходят действующие Tools, Resources, Prompts, completion, уведомления и подписки в применимых revisions, а также progress/cancel и существующая logging policy.
|
- Через SDK проходят действующие Tools, Resources, Prompts, completion, уведомления и подписки в применимых revisions, а также progress/cancel и существующая logging policy.
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Fail-closed detector for release-tooling-only CI changes."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
_SHA = re.compile(r"[0-9a-fA-F]{40}\Z")
|
||||||
|
_ALLOWED = {
|
||||||
|
".gitea/workflows/release.yml",
|
||||||
|
"scripts/scan-images.sh",
|
||||||
|
"scripts/check-image-scan.py",
|
||||||
|
"scripts/ci-release-assets.py",
|
||||||
|
"scripts/ci-release-resume.py",
|
||||||
|
"tests/unit/test_scan_images.py",
|
||||||
|
"tests/unit/test_check_image_scan.py",
|
||||||
|
"tests/unit/test_ci_release_assets.py",
|
||||||
|
"tests/unit/test_ci_release_resume.py",
|
||||||
|
}
|
||||||
|
_ALLOWED_BYTES = {path.encode("utf-8") for path in _ALLOWED}
|
||||||
|
|
||||||
|
|
||||||
|
def _git(repo: Path, *args: str) -> subprocess.CompletedProcess[bytes] | None:
|
||||||
|
try:
|
||||||
|
return subprocess.run(
|
||||||
|
["git", "-C", str(repo), *args],
|
||||||
|
check=False,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
except OSError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def release_tooling_only(
|
||||||
|
repo: Path, event_name: str, before_sha: str, pr_base_sha: str, force_full: str
|
||||||
|
) -> bool:
|
||||||
|
if force_full.lower() != "false" or event_name not in {"push", "pull_request"}:
|
||||||
|
return False
|
||||||
|
raw_base = before_sha if event_name == "push" else pr_base_sha
|
||||||
|
if not _SHA.fullmatch(raw_base):
|
||||||
|
return False
|
||||||
|
available = _git(repo, "cat-file", "-e", f"{raw_base}^{{commit}}")
|
||||||
|
if available is None or available.returncode != 0:
|
||||||
|
return False
|
||||||
|
if event_name == "pull_request":
|
||||||
|
merge_base = _git(repo, "merge-base", "HEAD", raw_base)
|
||||||
|
if merge_base is None or merge_base.returncode != 0:
|
||||||
|
return False
|
||||||
|
raw_base = merge_base.stdout.decode("ascii", errors="ignore").strip()
|
||||||
|
if not _SHA.fullmatch(raw_base):
|
||||||
|
return False
|
||||||
|
diff = _git(repo, "diff", "--no-renames", "--name-only", "-z", raw_base, "HEAD")
|
||||||
|
if diff is None or diff.returncode != 0:
|
||||||
|
return False
|
||||||
|
paths = diff.stdout.split(b"\0")
|
||||||
|
paths = [path for path in paths if path]
|
||||||
|
return bool(paths) and all(path in _ALLOWED_BYTES for path in paths)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
env = os.environ
|
||||||
|
ci_only = release_tooling_only(
|
||||||
|
Path.cwd(),
|
||||||
|
env.get("GITEA_EVENT_NAME", ""),
|
||||||
|
env.get("GITEA_EVENT_BEFORE", ""),
|
||||||
|
env.get("GITEA_PR_BASE_SHA", ""),
|
||||||
|
env.get("FORCE_FULL", ""),
|
||||||
|
)
|
||||||
|
output = env.get("GITHUB_OUTPUT")
|
||||||
|
if not output:
|
||||||
|
print("Release-tooling CI scope unavailable; using full Rust checks.")
|
||||||
|
return 0
|
||||||
|
with open(output, "a", encoding="utf-8") as stream:
|
||||||
|
stream.write(f"ci_only={'true' if ci_only else 'false'}\n")
|
||||||
|
print("Release-tooling-only change detected." if ci_only else "Full Rust checks required.")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
+31
-13
@@ -1,8 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Scan the built Crank server images with a pinned Trivy and fail closed.
|
# Scan the built Crank server images with a pinned Trivy and fail closed.
|
||||||
#
|
#
|
||||||
# The wrapper downloads and checksum-verifies one fixed Trivy release, downloads
|
# The wrapper loads or downloads and checksum-verifies one fixed Trivy release,
|
||||||
# one fresh vulnerability database, then scans every requested image by its
|
# downloads one fresh vulnerability database, then scans every requested image by its
|
||||||
# immutable Docker id with a fully pinned policy. It never trusts a local
|
# immutable Docker id with a fully pinned policy. It never trusts a local
|
||||||
# trivy.yaml, .trivyignore, VEX file or skip list: --config and --ignorefile
|
# trivy.yaml, .trivyignore, VEX file or skip list: --config and --ignorefile
|
||||||
# point at /dev/null and every inherited TRIVY_* variable is removed before
|
# point at /dev/null and every inherited TRIVY_* variable is removed before
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
#
|
#
|
||||||
# db/metadata.json copy of the actual downloaded Trivy DB metadata
|
# db/metadata.json copy of the actual downloaded Trivy DB metadata
|
||||||
# db-download.log database download log
|
# db-download.log database download log
|
||||||
|
# scanner-cache-source.log archive source provenance
|
||||||
# scanner.json pinned scanner version and scan policy receipt
|
# scanner.json pinned scanner version and scan policy receipt
|
||||||
# <NN-slug>.json raw Trivy JSON report per image
|
# <NN-slug>.json raw Trivy JSON report per image
|
||||||
# <NN-slug>.scan.log Trivy scan log per image
|
# <NN-slug>.scan.log Trivy scan log per image
|
||||||
@@ -47,6 +48,8 @@ expected_sha256="8b4376d5d6befe5c24d503f10ff136d9e0c49f9127a4279fd110b727929a5aa
|
|||||||
download_url="https://github.com/aquasecurity/trivy/releases/download/v${trivy_version}/${archive}"
|
download_url="https://github.com/aquasecurity/trivy/releases/download/v${trivy_version}/${archive}"
|
||||||
# Fixed GitHub asset ID for the Trivy 0.70.0 Linux 64-bit release archive.
|
# Fixed GitHub asset ID for the Trivy 0.70.0 Linux 64-bit release archive.
|
||||||
asset_api_url="https://api.github.com/repos/aquasecurity/trivy/releases/assets/398381981"
|
asset_api_url="https://api.github.com/repos/aquasecurity/trivy/releases/assets/398381981"
|
||||||
|
tool_cache_root="${RUNNER_TOOL_CACHE:-/opt/hostedtoolcache}"
|
||||||
|
cached_archive="$tool_cache_root/trivy/$trivy_version/$archive"
|
||||||
db_repository_primary="ghcr.io/aquasecurity/trivy-db:2"
|
db_repository_primary="ghcr.io/aquasecurity/trivy-db:2"
|
||||||
db_repository_fallback="mirror.gcr.io/aquasec/trivy-db:2"
|
db_repository_fallback="mirror.gcr.io/aquasec/trivy-db:2"
|
||||||
|
|
||||||
@@ -104,19 +107,34 @@ PY
|
|||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download and checksum-verify the pinned scanner exactly once.
|
# Load the exact-version archive from the runner cache when preinstalled;
|
||||||
if ! curl --fail --silent --show-error --location --max-time 300 \
|
# otherwise use the bounded network routes. The shared cache is read-only here.
|
||||||
"$download_url" --output "$temp_dir/$archive" \
|
cache_source_log="$output_dir/scanner-cache-source.log"
|
||||||
>"$output_dir/scanner-download.log" 2>&1; then
|
: > "$cache_source_log"
|
||||||
rm -f "$temp_dir/$archive"
|
if [ -f "$cached_archive" ]; then
|
||||||
|
printf 'archive_source=runner-tool-cache\n' > "$cache_source_log"
|
||||||
|
if ! cp "$cached_archive" "$temp_dir/$archive"; then
|
||||||
|
fail_all "could not copy the pinned Trivy archive from runner tool cache"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
printf 'archive_source=network\n' > "$cache_source_log"
|
||||||
if ! curl --fail --silent --show-error --location --max-time 300 \
|
if ! curl --fail --silent --show-error --location --max-time 300 \
|
||||||
--header 'Accept: application/octet-stream' \
|
"$download_url" --output "$temp_dir/$archive" \
|
||||||
"$asset_api_url" --output "$temp_dir/$archive" \
|
>"$output_dir/scanner-download.log" 2>&1; then
|
||||||
>"$output_dir/scanner-api-download.log" 2>&1; then
|
rm -f "$temp_dir/$archive"
|
||||||
fail_all "could not download pinned Trivy ${trivy_version} from release URL or GitHub asset API"
|
if ! curl --fail --silent --show-error --location --max-time 300 \
|
||||||
|
--header 'Accept: application/octet-stream' \
|
||||||
|
"$asset_api_url" --output "$temp_dir/$archive" \
|
||||||
|
>"$output_dir/scanner-api-download.log" 2>&1; then
|
||||||
|
printf 'network_download=failed\n' >> "$cache_source_log"
|
||||||
|
fail_all "could not download pinned Trivy ${trivy_version} from release URL or GitHub asset API"
|
||||||
|
fi
|
||||||
|
printf 'archive_source=github-release-asset-api\n' > "$cache_source_log"
|
||||||
|
printf 'Downloaded pinned Trivy %s from GitHub release asset API.\n' "$trivy_version" \
|
||||||
|
>>"$output_dir/scanner-api-download.log"
|
||||||
|
else
|
||||||
|
printf 'archive_source=github-release-download\n' > "$cache_source_log"
|
||||||
fi
|
fi
|
||||||
printf 'Downloaded pinned Trivy %s from GitHub release asset API.\n' "$trivy_version" \
|
|
||||||
>>"$output_dir/scanner-api-download.log"
|
|
||||||
fi
|
fi
|
||||||
if ! printf '%s %s\n' "$expected_sha256" "$temp_dir/$archive" \
|
if ! printf '%s %s\n' "$expected_sha256" "$temp_dir/$archive" \
|
||||||
| sha256sum --check --status; then
|
| sha256sum --check --status; then
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
import importlib.util
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[2]
|
||||||
|
SCRIPT = ROOT / "scripts" / "ci-release-tooling-scope.py"
|
||||||
|
spec = importlib.util.spec_from_file_location("ci_release_tooling_scope", SCRIPT)
|
||||||
|
assert spec and spec.loader
|
||||||
|
scope = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(scope)
|
||||||
|
|
||||||
|
WORKFLOW = ROOT / ".gitea/workflows/ci.yml"
|
||||||
|
_FALSE = "false"
|
||||||
|
|
||||||
|
|
||||||
|
class ReleaseToolingScopeTests(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.temp = tempfile.TemporaryDirectory()
|
||||||
|
self.addCleanup(self.temp.cleanup)
|
||||||
|
self.repo = Path(self.temp.name)
|
||||||
|
self.git("init", "-q")
|
||||||
|
self.git("config", "user.email", "ci-scope@example.test")
|
||||||
|
self.git("config", "user.name", "CI Scope Test")
|
||||||
|
self.write("src/lib.rs", "pub fn initial() {}\n")
|
||||||
|
self.write("scripts/scan-images.sh", "#!/bin/sh\nexit 0\n")
|
||||||
|
self.write("tests/unit/test_scan_images.py", "# initial\n")
|
||||||
|
self.git("add", ".")
|
||||||
|
self.git("commit", "-qm", "baseline")
|
||||||
|
self.base = self.head()
|
||||||
|
|
||||||
|
def git(self, *args: str) -> str:
|
||||||
|
result = subprocess.run(
|
||||||
|
["git", "-C", str(self.repo), *args],
|
||||||
|
check=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
return result.stdout.strip()
|
||||||
|
|
||||||
|
def head(self) -> str:
|
||||||
|
return self.git("rev-parse", "HEAD")
|
||||||
|
|
||||||
|
def write(self, relative: str, content: str) -> None:
|
||||||
|
path = self.repo / relative
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path.write_text(content, encoding="utf-8")
|
||||||
|
|
||||||
|
def commit(self, message: str = "change") -> None:
|
||||||
|
self.git("add", "-A")
|
||||||
|
self.git("commit", "-qm", message)
|
||||||
|
|
||||||
|
def classify(self, event="push", before=None, base=None, force=_FALSE) -> bool:
|
||||||
|
return scope.release_tooling_only(
|
||||||
|
self.repo,
|
||||||
|
event,
|
||||||
|
self.base if before is None else before,
|
||||||
|
self.base if base is None else base,
|
||||||
|
force,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_release_only_diff_is_safe_for_push_and_pull_request(self):
|
||||||
|
self.write(".gitea/workflows/release.yml", "# release tooling update\n")
|
||||||
|
self.write("scripts/scan-images.sh", "#!/bin/sh\n# scanner update\n")
|
||||||
|
self.commit()
|
||||||
|
self.assertTrue(self.classify("push", before=self.base))
|
||||||
|
self.assertTrue(self.classify("pull_request", base=self.base))
|
||||||
|
|
||||||
|
def test_rust_or_mixed_diff_requires_full_ci(self):
|
||||||
|
self.write("src/lib.rs", "pub fn changed() {}\n")
|
||||||
|
self.commit("Rust change")
|
||||||
|
self.assertFalse(self.classify("push", before=self.base))
|
||||||
|
|
||||||
|
self.write("scripts/scan-images.sh", "#!/bin/sh\n# tooling change\n")
|
||||||
|
self.write("src/lib.rs", "pub fn changed_again() {}\n")
|
||||||
|
self.commit("mixed change")
|
||||||
|
self.assertFalse(self.classify("push", before=self.base))
|
||||||
|
|
||||||
|
def test_rename_from_rust_into_allowlist_is_not_safe(self):
|
||||||
|
(self.repo / ".gitea/workflows").mkdir(parents=True)
|
||||||
|
self.git("mv", "src/lib.rs", ".gitea/workflows/release.yml")
|
||||||
|
self.commit("rename Rust source into release path")
|
||||||
|
self.assertFalse(self.classify("push", before=self.base))
|
||||||
|
|
||||||
|
def test_unavailable_zero_empty_and_missing_bases_require_full_ci(self):
|
||||||
|
self.write("scripts/scan-images.sh", "#!/bin/sh\n# allowed\n")
|
||||||
|
self.commit()
|
||||||
|
self.assertFalse(self.classify("push", before=""))
|
||||||
|
self.assertFalse(self.classify("push", before="0" * 40))
|
||||||
|
self.assertFalse(self.classify("push", before="1" * 40))
|
||||||
|
self.assertFalse(self.classify("push", before=self.head()))
|
||||||
|
self.assertFalse(self.classify("pull_request", base=""))
|
||||||
|
|
||||||
|
def test_manual_feature_and_unknown_force_metadata_require_full_ci(self):
|
||||||
|
self.write("scripts/scan-images.sh", "#!/bin/sh\n# allowed\n")
|
||||||
|
self.commit()
|
||||||
|
self.assertFalse(self.classify("workflow_dispatch", before=self.base))
|
||||||
|
self.assertFalse(self.classify("push", before=self.base, force="true"))
|
||||||
|
self.assertFalse(self.classify("push", before=self.base, force=""))
|
||||||
|
|
||||||
|
def test_non_allowlisted_ci_self_change_requires_full_ci(self):
|
||||||
|
self.write(".gitea/workflows/ci.yml", "# detector workflow change\n")
|
||||||
|
self.commit()
|
||||||
|
self.assertFalse(self.classify("push", before=self.base))
|
||||||
|
|
||||||
|
|
||||||
|
class WorkflowScopeTests(unittest.TestCase):
|
||||||
|
def test_only_four_heavy_rust_steps_are_skippable(self):
|
||||||
|
workflow = WORKFLOW.read_text(encoding="utf-8")
|
||||||
|
self.assertIn("run: python3 scripts/ci-release-tooling-scope.py", workflow)
|
||||||
|
self.assertIn("FORCE_FULL: ${{ inputs.validation_level == 'feature' || contains(gitea.event.pull_request.labels.*.name, 'feature-ready') }}", workflow)
|
||||||
|
conditional = "if: steps.release_tooling.outputs.ci_only != 'true'"
|
||||||
|
for name in (
|
||||||
|
"Check typed runtime configuration contract",
|
||||||
|
"Check canonical migration contract",
|
||||||
|
"Check typed metrics contract",
|
||||||
|
"Run Crank story ATDD",
|
||||||
|
):
|
||||||
|
start = workflow.index(f"- name: {name}")
|
||||||
|
self.assertIn(conditional, workflow[start : start + 180])
|
||||||
|
for name in (
|
||||||
|
"Install Rust toolchain",
|
||||||
|
"Run tooling unit tests",
|
||||||
|
"Check formatting",
|
||||||
|
"Check Rust boundaries",
|
||||||
|
"Check OpenAPI matrix and corpus compatibility versions",
|
||||||
|
):
|
||||||
|
start = workflow.index(f"- name: {name}")
|
||||||
|
self.assertNotIn("if:", workflow[start : start + 160])
|
||||||
|
self.assertIn("name: Rust Checks", workflow)
|
||||||
|
self.assertIn("name: UI Checks", workflow)
|
||||||
|
self.assertIn("name: Required Checks", workflow)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -189,6 +189,7 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
|||||||
curl_direct_fail=False,
|
curl_direct_fail=False,
|
||||||
curl_api_fail=False,
|
curl_api_fail=False,
|
||||||
api_checksum_mismatch=False,
|
api_checksum_mismatch=False,
|
||||||
|
cache_archive=None,
|
||||||
extra_env=None,
|
extra_env=None,
|
||||||
workdir_files=None,
|
workdir_files=None,
|
||||||
run_in_workdir=False,
|
run_in_workdir=False,
|
||||||
@@ -229,6 +230,11 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
|||||||
archive_path.write_bytes(fixture_archive)
|
archive_path.write_bytes(fixture_archive)
|
||||||
api_archive_path = root / "trivy-api-fixture.tar.gz"
|
api_archive_path = root / "trivy-api-fixture.tar.gz"
|
||||||
api_archive_path.write_bytes(fixture_archive + b"tampered" if api_checksum_mismatch else fixture_archive)
|
api_archive_path.write_bytes(fixture_archive + b"tampered" if api_checksum_mismatch else fixture_archive)
|
||||||
|
tool_cache = root / "runner-tool-cache"
|
||||||
|
if cache_archive is not None:
|
||||||
|
cached_path = tool_cache / "trivy" / "0.70.0" / "trivy_0.70.0_Linux-64bit.tar.gz"
|
||||||
|
cached_path.parent.mkdir(parents=True)
|
||||||
|
cached_path.write_bytes(fixture_archive if cache_archive == "valid" else b"invalid archive")
|
||||||
|
|
||||||
reports = root / "reports"
|
reports = root / "reports"
|
||||||
reports.mkdir()
|
reports.mkdir()
|
||||||
@@ -261,6 +267,7 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
|||||||
env.update(
|
env.update(
|
||||||
{
|
{
|
||||||
"PATH": f"{bin_dir}:{env['PATH']}",
|
"PATH": f"{bin_dir}:{env['PATH']}",
|
||||||
|
"RUNNER_TOOL_CACHE": str(tool_cache),
|
||||||
"CRANK_IMAGE_SCAN_OUTPUT_DIR": str(evidence),
|
"CRANK_IMAGE_SCAN_OUTPUT_DIR": str(evidence),
|
||||||
"FAKE_CURL_ARCHIVE": str(archive_path),
|
"FAKE_CURL_ARCHIVE": str(archive_path),
|
||||||
"FAKE_CURL_API_ARCHIVE": str(api_archive_path),
|
"FAKE_CURL_API_ARCHIVE": str(api_archive_path),
|
||||||
@@ -493,6 +500,37 @@ class ScanImagesWrapperTests(unittest.TestCase):
|
|||||||
self.assertIn("checksum mismatch", result.stderr)
|
self.assertIn("checksum mismatch", result.stderr)
|
||||||
self.assertEqual(trivy_calls, [])
|
self.assertEqual(trivy_calls, [])
|
||||||
|
|
||||||
|
def test_preloaded_pinned_archive_runs_without_network(self):
|
||||||
|
result, root, evidence, receipt, _, trivy_calls = self.run_scan(
|
||||||
|
images=(CLEAN_TAG,), cache_archive="valid", curl_fail=True
|
||||||
|
)
|
||||||
|
self.assertEqual(result.returncode, 0, result.stderr)
|
||||||
|
self.assertEqual(receipt["overall"]["status"], "pass")
|
||||||
|
self.assertEqual(
|
||||||
|
(evidence / "scanner-cache-source.log").read_text(),
|
||||||
|
"archive_source=runner-tool-cache\n",
|
||||||
|
)
|
||||||
|
self.assertFalse((evidence / "scanner-download.log").exists())
|
||||||
|
self.assertFalse((evidence / "scanner-api-download.log").exists())
|
||||||
|
cached = root / "runner-tool-cache" / "trivy" / "0.70.0" / "trivy_0.70.0_Linux-64bit.tar.gz"
|
||||||
|
self.assertEqual(cached.read_bytes(), (root / "trivy-fixture.tar.gz").read_bytes())
|
||||||
|
self.assertTrue(any("--download-db-only" in call["args"] for call in trivy_calls))
|
||||||
|
|
||||||
|
def test_preloaded_archive_hash_mismatch_fails_before_network_or_execution(self):
|
||||||
|
result, _, evidence, receipt, _, trivy_calls = self.run_scan(
|
||||||
|
images=(CLEAN_TAG,), cache_archive="bad", curl_fail=True
|
||||||
|
)
|
||||||
|
self.assertEqual(result.returncode, 2)
|
||||||
|
self.assertEqual(receipt["overall"]["status"], "error")
|
||||||
|
self.assertIn("checksum mismatch", result.stderr)
|
||||||
|
self.assertEqual(
|
||||||
|
(evidence / "scanner-cache-source.log").read_text(),
|
||||||
|
"archive_source=runner-tool-cache\n",
|
||||||
|
)
|
||||||
|
self.assertFalse((evidence / "scanner-download.log").exists())
|
||||||
|
self.assertFalse((evidence / "scanner-api-download.log").exists())
|
||||||
|
self.assertEqual(trivy_calls, [])
|
||||||
|
|
||||||
def test_unknown_image_is_error_and_is_never_scanned(self):
|
def test_unknown_image_is_error_and_is_never_scanned(self):
|
||||||
missing = "crank/missing:ci"
|
missing = "crank/missing:ci"
|
||||||
result, _, _, receipt, _, trivy_calls = self.run_scan(images=(missing, CLEAN_TAG))
|
result, _, _, receipt, _, trivy_calls = self.run_scan(images=(missing, CLEAN_TAG))
|
||||||
|
|||||||
Reference in new issue
Block a user