feat: complete Epic 1 production foundation

This commit is contained in:
2026-08-25 01:24:11 +03:00
parent 767428436d
commit 182bde8ac0
298 changed files with 35719 additions and 5299 deletions
@@ -7,14 +7,14 @@ use std::sync::{
use async_trait::async_trait;
use crank_core::{
AdapterResponse, CacheScope, CacheStoreError, ConfirmationPolicy, CoordinationStateReservation,
CoordinationStateStore, CoordinationStateValue, ExecutionConfig, ExecutionMode, HttpMethod,
Operation, OperationId, OperationSafetyClass, OperationSafetyPolicy, OperationSecurityLevel,
OperationStatus, Protocol, ProtocolAdapter, ProtocolAdapterError, RestTarget, Target,
ToolDescription,
CoordinationStateStore, CoordinationStateValue, ExecutionConfig, ExecutionErrorCode,
ExecutionMode, HttpMethod, Operation, OperationId, OperationSafetyClass, OperationSafetyPolicy,
OperationSecurityLevel, OperationStatus, Protocol, ProtocolAdapter, ProtocolAdapterError,
RestTarget, Target, ToolDescription,
};
use crank_mapping::{MappingRule, MappingSet};
use crank_runtime::{
InMemoryCoordinationStateStore, RuntimeError, RuntimeExecutorBuilder, RuntimeRequestContext,
InMemoryCoordinationStateStore, RuntimeExecutorBuilder, RuntimeRequestContext,
};
use crank_schema::{Schema, SchemaKind};
use futures_util::future::join_all;
@@ -42,12 +42,12 @@ async fn destructive_operation_requires_single_use_confirmation() {
)
.await
.expect_err("first destructive call must only stage confirmation");
let confirmation_token = match first {
RuntimeError::ConfirmationRequired {
confirmation_token, ..
} => confirmation_token,
error => panic!("expected confirmation required, got {error:?}"),
};
assert_eq!(first.error_code(), ExecutionErrorCode::ConfirmationRequired);
let confirmation_token = first
.confirmation()
.expect("expected confirmation challenge")
.token()
.to_owned();
assert_eq!(call_count.load(Ordering::SeqCst), 0);
let confirmed_context = context
@@ -72,10 +72,7 @@ async fn destructive_operation_requires_single_use_confirmation() {
)
.await
.expect_err("confirmation token must be single-use");
assert!(matches!(
replay,
RuntimeError::InvalidConfirmationToken { .. }
));
assert_eq!(replay.error_code(), ExecutionErrorCode::ConfirmationInvalid);
assert_eq!(call_count.load(Ordering::SeqCst), 1);
let approved_context = context.with_approval_granted();
@@ -111,12 +108,12 @@ async fn confirmation_token_allows_only_one_concurrent_execution() {
)
.await
.unwrap_err();
let RuntimeError::ConfirmationRequired {
confirmation_token, ..
} = first
else {
panic!("expected confirmation token")
};
assert_eq!(first.error_code(), ExecutionErrorCode::ConfirmationRequired);
let confirmation_token = first
.confirmation()
.expect("expected confirmation token")
.token()
.to_owned();
let attempts = (0..16).map(|_| {
let executor = executor.clone();
@@ -143,7 +140,7 @@ async fn confirmation_token_allows_only_one_concurrent_execution() {
results
.iter()
.filter_map(|result| result.as_ref().err())
.all(|error| matches!(error, RuntimeError::InvalidConfirmationToken { .. }))
.all(|error| error.error_code() == ExecutionErrorCode::ConfirmationInvalid)
);
}
@@ -167,11 +164,10 @@ async fn unavailable_confirmation_store_is_preserved_as_a_typed_error() {
)
.await
.expect_err("unavailable store must prevent issuing a token");
assert!(matches!(
issue_error,
RuntimeError::ConfirmationStoreUnavailable { ref operation_id }
if operation_id == "op_delete_order"
));
assert_eq!(
issue_error.error_code(),
ExecutionErrorCode::SafetyStoreUnavailable
);
let consume_error = executor
.execute_with_context(
@@ -181,11 +177,10 @@ async fn unavailable_confirmation_store_is_preserved_as_a_typed_error() {
)
.await
.expect_err("unavailable store must not look like an invalid token");
assert!(matches!(
consume_error,
RuntimeError::ConfirmationStoreUnavailable { ref operation_id }
if operation_id == "op_delete_order"
));
assert_eq!(
consume_error.error_code(),
ExecutionErrorCode::SafetyStoreUnavailable
);
}
struct UnavailableCoordinationStore;
@@ -396,3 +391,4 @@ fn bool_schema() -> Schema {
variants: Vec::new(),
}
}
use crate::support::RuntimeExecutorTestExt;