123 lines
4.1 KiB
Rust
123 lines
4.1 KiB
Rust
//! Full blocked rejection (zero mutation) and the rejected outcome shape.
|
|
|
|
use super::*;
|
|
|
|
fn blocked_candidate_payload(plan_id: &str, job_id: &str, fingerprint: &Value) -> Value {
|
|
let operation = plan_operation("op_apply_blocked_ok");
|
|
json!({
|
|
"schema_version": "import-plan-v1",
|
|
"plan_reference": plan_id,
|
|
"job_id": job_id,
|
|
"fingerprint": fingerprint,
|
|
"source": { "source_id": SOURCE_ID, "digest": source_ref() },
|
|
"dependencies": [],
|
|
"selection": {
|
|
"mode": "full",
|
|
"all": ["ready", "blocked"],
|
|
"selected": ["ready", "blocked"],
|
|
"excluded": []
|
|
},
|
|
"counts": { "selected": 2, "excluded": 0, "actionable": 1, "blocked": 1 },
|
|
"candidates": [
|
|
{
|
|
"key": "ready",
|
|
"name": operation.name,
|
|
"state": "actionable",
|
|
"decision": { "action": "create" },
|
|
"operation": operation
|
|
},
|
|
{
|
|
"key": "blocked",
|
|
"name": "import_candidate_blocked",
|
|
"state": "blocked",
|
|
"reason": "import_candidate_blocked",
|
|
"decision": { "action": "create" }
|
|
}
|
|
]
|
|
})
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn apply_rejects_whole_plan_when_any_candidate_is_blocked() {
|
|
let database = TestDatabase::new().await;
|
|
let registry = database.registry().await;
|
|
let raw_pool = database.raw_pool().await;
|
|
let now = OffsetDateTime::now_utc();
|
|
let ws = create_workspace(®istry, "ws_apply_blocked").await;
|
|
let job = create_pending_openapi_job(
|
|
®istry,
|
|
&ws,
|
|
"job_apply_blocked",
|
|
now,
|
|
now + Duration::hours(1),
|
|
)
|
|
.await;
|
|
activate_source(&raw_pool, &ws, now).await;
|
|
|
|
let fp = fingerprint();
|
|
let plan_id_str = "plan_apply_blocked";
|
|
let payload = blocked_candidate_payload(plan_id_str, job.as_str(), &fp);
|
|
let (plan, digest) = store_plan(®istry, &ws, &job, plan_id_str, &fp, payload).await;
|
|
let applied_at = OffsetDateTime::now_utc();
|
|
let request = ApplyImportPlanRequest {
|
|
workspace_id: &ws,
|
|
plan_id: &plan,
|
|
plan_digest: &digest,
|
|
idempotency_key: "idem_blocked",
|
|
verified_fingerprint: &fp,
|
|
applied_at: &applied_at,
|
|
};
|
|
|
|
// A single blocked candidate rejects the whole apply: zero mutation.
|
|
let result = registry.apply_import_plan(&request).await.unwrap();
|
|
assert!(
|
|
!result.replayed,
|
|
"a rejected apply is a call outcome, not a replay"
|
|
);
|
|
let report = &result.report;
|
|
assert_eq!(report.status, ImportPlanApplyStatus::Rejected);
|
|
assert_eq!(
|
|
report.counts.rejected, 2,
|
|
"both selected candidates are rejected"
|
|
);
|
|
assert_eq!(report.counts.created, 0);
|
|
assert!(
|
|
report
|
|
.outcomes
|
|
.iter()
|
|
.all(|reported| reported.outcome == ImportPlanCandidateOutcome::Rejected)
|
|
);
|
|
let blocked = report
|
|
.outcomes
|
|
.iter()
|
|
.find(|reported| reported.key == "blocked")
|
|
.expect("the blocked candidate must be explained in the report");
|
|
assert_eq!(blocked.reason.as_deref(), Some("import_candidate_blocked"));
|
|
assert_eq!(report.recovery, "repreview_required");
|
|
|
|
// No operation materialized and no application row persisted.
|
|
assert!(
|
|
registry
|
|
.get_operation_summary(&ws, &OperationId::new("op_apply_blocked_ok"))
|
|
.await
|
|
.unwrap()
|
|
.is_none(),
|
|
"a rejected apply must not create the actionable candidate"
|
|
);
|
|
assert_eq!(
|
|
registry
|
|
.get_import_plan_application(&ws, "idem_blocked")
|
|
.await
|
|
.unwrap(),
|
|
None,
|
|
"a rejected apply must not persist application evidence"
|
|
);
|
|
|
|
// It can be retried under the same key and must reject again, not replay.
|
|
let retry = registry.apply_import_plan(&request).await.unwrap();
|
|
assert!(!retry.replayed);
|
|
assert_eq!(retry.report.status, ImportPlanApplyStatus::Rejected);
|
|
|
|
database.cleanup().await;
|
|
}
|