//! 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(®istry, "ws_apply_partial").await; let job = create_pending_openapi_job( ®istry, &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(®istry, &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; }