Files
bsodfather 54ce770682
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
feat(epic3): deliver the accepted Epic 3 scope through Story 3.17
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.
2026-10-25 09:08:22 +00:00

207 lines
7.8 KiB
Rust

//! Story 3.6 · AT-3.6-08 · фаза B — family gating и gauges по binding.
//!
//! `TD-B8` MCP-only facade вызовы в admin-процессе — no-op без handle/exemplar.
//! `TD-B9` `initialize_gauges` требует совпадающий binding, иначе no-op.
//! `TD-B10` guard чужого family при drop не создаёт series.
//!
//! Каждый кейс исполняется в fresh child (binding — process-global `OnceLock`).
use std::collections::BTreeSet;
use std::time::Duration;
use crank_metrics::{
DbPoolState, InFlightGuard, InvocationSource, McpMethod, McpOutcome, McpResponseMode,
MetricService, ToolErrorKind, ToolOutcome, UpstreamOperationKind, UpstreamOutcome,
exemplar_snapshot, initialize_gauges, record_cache_outcome, record_idempotency_outcome,
record_invocation_history_lost, record_mcp_request, record_mcp_request_with_exemplar,
record_tool_invocation, record_upstream_request, set_catalog, set_mcp_active_sessions,
};
use metrics_util::debugging::DebuggingRecorder;
const BINDING_ROLE_ENV: &str = "CRANK_METRICS_TEST_BINDING_ROLE";
fn route_to_child(role: &str, test: &str) -> bool {
match std::env::var(BINDING_ROLE_ENV).ok().as_deref() {
Some(actual) if actual == role => false,
Some(actual) => panic!("child for {test} runs with role {actual}, expected {role}"),
None => {
let output =
std::process::Command::new(std::env::current_exe().expect("current test binary"))
.args([test, "--exact", "--nocapture"])
.env(BINDING_ROLE_ENV, role)
.output()
.expect("re-executed binding child");
assert!(
output.status.success(),
"binding child {role}/{test} failed:\nstdout:\n{}\nstderr:\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
true
}
}
}
fn bind_admin() {
crank_metrics::bind_metric_service(MetricService::AdminApi).expect("admin bind");
}
fn series_names(
samples: &[(
metrics_util::CompositeKey,
Option<metrics::Unit>,
Option<metrics::SharedString>,
metrics_util::debugging::DebugValue,
)],
) -> BTreeSet<String> {
samples
.iter()
.map(|(key, _, _, _)| key.key().name().to_owned())
.collect()
}
/// TD-B8 — MCP-only families в admin-процессе не создают ни handles, ни exemplars.
#[test]
fn mcp_only_calls_are_noop_in_admin_process() {
if route_to_child("admin_api", "mcp_only_calls_are_noop_in_admin_process") {
return;
}
bind_admin();
let recorder = DebuggingRecorder::new();
let snapshotter = recorder.snapshotter();
metrics::with_local_recorder(&recorder, || {
record_mcp_request(
McpMethod::ToolsCall,
McpResponseMode::Json,
McpOutcome::Success,
Duration::from_millis(1),
);
record_mcp_request_with_exemplar(
McpMethod::ToolsCall,
McpResponseMode::Json,
McpOutcome::Success,
Duration::from_millis(1),
crank_metrics::ExemplarTraceId::parse("0123456789abcdef0123456789abcdef"),
);
set_mcp_active_sessions(3);
crank_metrics::set_mcp_session_metrics_fresh(true);
set_catalog(7, 70, 1);
});
let samples = snapshotter.snapshot().into_vec();
assert!(
samples.is_empty(),
"MCP-only families обязаны быть no-op в admin: {:?}",
series_names(&samples)
);
assert!(
exemplar_snapshot().is_empty(),
"MCP-only exemplar не может создавать entry в admin-процессе"
);
// Общие families при этом продолжают работать.
let shared = DebuggingRecorder::new();
let shared_snapshotter = shared.snapshotter();
metrics::with_local_recorder(&shared, || {
record_tool_invocation(
InvocationSource::AgentToolCall,
ToolOutcome::Success,
ToolErrorKind::None,
Duration::from_millis(1),
);
record_upstream_request(
UpstreamOperationKind::Rest,
UpstreamOutcome::Success,
Duration::from_millis(1),
);
record_cache_outcome(crank_metrics::CacheOutcome::Hit);
record_idempotency_outcome(crank_metrics::IdempotencyOutcome::Replay);
record_invocation_history_lost();
});
let names = series_names(&shared_snapshotter.snapshot().into_vec());
assert!(
names.contains("crank_tool_invocations_total")
&& names.contains("crank_upstream_requests_total")
&& names.contains("crank_runtime_cache_total"),
"shared families обязаны работать в admin: {names:?}"
);
}
/// TD-B9 — `initialize_gauges` требует совпадающий binding.
#[test]
fn initialize_gauges_requires_matching_binding() {
if route_to_child("admin_api", "initialize_gauges_requires_matching_binding") {
return;
}
bind_admin();
let foreign = DebuggingRecorder::new();
let foreign_snapshotter = foreign.snapshotter();
metrics::with_local_recorder(&foreign, || {
initialize_gauges(MetricService::McpServer);
});
assert!(
foreign_snapshotter.snapshot().into_vec().is_empty(),
"initialize_gauges чужого сервиса обязан быть no-op"
);
let own = DebuggingRecorder::new();
let own_snapshotter = own.snapshotter();
metrics::with_local_recorder(&own, || {
initialize_gauges(MetricService::AdminApi);
});
let names = series_names(&own_snapshotter.snapshot().into_vec());
assert!(names.contains("crank_http_inflight"));
assert!(names.contains("crank_runtime_inflight"));
assert!(names.contains("crank_db_pool_connections"));
assert!(
names.iter().all(|name| !name.starts_with("crank_mcp_")),
"admin gauges не могут включать MCP-only series: {names:?}"
);
assert!(
names.iter().all(|name| !name.starts_with("crank_catalog_")),
"admin gauges не могут включать catalog series: {names:?}"
);
}
/// TD-B10 — guard чужого family при drop не создаёт series.
#[test]
fn foreign_family_guard_drop_creates_no_series() {
if route_to_child("admin_api", "foreign_family_guard_drop_creates_no_series") {
return;
}
bind_admin();
let recorder = DebuggingRecorder::new();
let snapshotter = recorder.snapshotter();
metrics::with_local_recorder(&recorder, || {
let stream = InFlightGuard::mcp_stream();
drop(stream);
let tool = crank_metrics::ToolInvocationMetrics::start(InvocationSource::AgentToolCall);
drop(tool);
let upstream = crank_metrics::UpstreamRequestMetrics::start(UpstreamOperationKind::Rest);
drop(upstream);
});
let names = series_names(&snapshotter.snapshot().into_vec());
assert!(
names.iter().all(|name| !name.starts_with("crank_mcp_")),
"guard чужого family не может создавать series: {names:?}"
);
assert!(
!names.contains("crank_mcp_active_streams"),
"foreign stream guard обязан быть no-op: {names:?}"
);
// Собственный family работает: guard admin http и shared families.
let own = DebuggingRecorder::new();
let own_snapshotter = own.snapshotter();
metrics::with_local_recorder(&own, || {
let http = InFlightGuard::http();
drop(http);
});
let own_names = series_names(&own_snapshotter.snapshot().into_vec());
assert!(
own_names.contains("crank_http_inflight"),
"admin http guard обязан регистрировать series: {own_names:?}"
);
let _ = DbPoolState::Idle;
}