Files
crank/crates/crank-registry/tests/integration/import_plan/apply/partial.rs
T
bsodfather e93de7015a
CI / Rust Checks (pull_request) Failing after 1s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
feat(import): complete OpenAPI onboarding and verify delivery
2026-10-09 17:50:38 +03:00

104 lines
3.4 KiB
Rust

//! Partial selection: only the closed selected set mutates.
use super::*;
fn partial_payload(plan_id: &str, job_id: &str, fingerprint: &Value) -> Value {
let operation = plan_operation("op_apply_partial");
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": "partial",
"all": ["picked", "not_picked"],
"selected": ["picked"],
"excluded": ["not_picked"]
},
"excluded_reasons": [{
"key": "not_picked",
"name": "Not Picked Display Label",
"reason": "not_selected"
}],
"counts": { "selected": 1, "excluded": 1, "actionable": 1, "blocked": 0 },
"candidates": [{
"key": "picked",
"name": operation.name,
"state": "actionable",
"decision": { "action": "create" },
"operation": operation
}]
})
}
#[tokio::test]
async fn apply_partial_selection_only_mutates_selected_and_explains_excluded() {
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(&registry, "ws_apply_partial").await;
let job = create_pending_openapi_job(
&registry,
&ws,
"job_apply_partial",
now,
now + Duration::hours(1),
)
.await;
activate_source(&raw_pool, &ws, now).await;
let fp = fingerprint();
let plan_id_str = "plan_apply_partial";
let payload = partial_payload(plan_id_str, job.as_str(), &fp);
let (plan, digest) = store_plan(&registry, &ws, &job, plan_id_str, &fp, payload).await;
let applied_at = OffsetDateTime::from_unix_timestamp(1_800_000_000).unwrap();
let request = ApplyImportPlanRequest {
workspace_id: &ws,
plan_id: &plan,
plan_digest: &digest,
idempotency_key: "idem_partial",
verified_fingerprint: &fp,
applied_at: &applied_at,
};
let result = registry.apply_import_plan(&request).await.unwrap();
assert!(!result.replayed);
let report = &result.report;
assert_eq!(report.status, ImportPlanApplyStatus::Applied);
assert_eq!(report.counts.created, 1);
assert_eq!(
report.counts.excluded, 1,
"excluded candidates remain explained"
);
assert_eq!(report.counts.rejected, 0);
let excluded = report
.outcomes
.iter()
.find(|reported| reported.key == "not_picked")
.expect("the excluded candidate must be explained in the report");
assert_eq!(
excluded.outcome,
ImportPlanCandidateOutcome::Excluded,
"an excluded candidate is reported, not mutated"
);
assert_eq!(excluded.name, "Not Picked Display Label");
assert_eq!(excluded.reason.as_deref(), Some("not_selected"));
assert!(
excluded.operation_id.is_none(),
"an excluded candidate must not gain an operation"
);
// Exactly one operation exists in the workspace — the selected one.
let listed = registry
.get_operation_summary(&ws, &OperationId::new("op_apply_partial"))
.await
.unwrap()
.unwrap();
assert_eq!(listed.current_draft_version, 1);
database.cleanup().await;
}