{
  "id": "issue-4655-lead-convert-campaignmember",
  "title": "Converted Lead inbound identity and CampaignMember handoff contract (#4655)",
  "kind": "hubspot_contract",
  "linkedIssues": [4571, 4655],
  "externalEffects": "none",
  "provenance": {
    "businessScenario": "A converted HubSpot-linked Lead must retain CampaignMember conversion behavior, while the next inbound contact event transfers its durable identity to the converted Contact and only then enables Contact sync. This is a committed-pack inspection because Xiaopeng must not use its database connector credential to create or PATCH a HubSpot contact.",
    "reportedBy": "Issue #4655 production reproduction",
    "capturedAt": "2026-08-08",
    "acceptanceBoundary": "PASS proves the L2 conversion and HubSpot inbound handoff contracts are present. It does not prove webhook delivery or live provider state; those require an isolated sandbox-only connector credential and endpoint."
  },
  "contractChecks": [
    {
      "id": "convert-selects-lead-campaign-members-before-conversion",
      "type": "record_lookup",
      "pack": "Salesforce-PingCAP-L2",
      "flow": "Std_ConvertLead.flow.json",
      "lookup": "GetFirstCampaignMember",
      "expect": {
        "object": "CampaignMember",
        "filters": [
          {"field": "LeadId", "operator": "EqualTo", "value": {"elementReference": "leadId"}},
          {"field": "Campaign_Name__c", "operator": "NotEqualTo", "value": {"stringValue": "OP - Person Lifecycle Campaign"}}
        ],
        "sortField": "CreatedDate",
        "sortOrder": "ASC",
        "connector": {"targetReference": "GetLastCampaignMember"}
      }
    },
    {
      "id": "convert-relinks-campaign-members-to-converted-contact",
      "type": "flow_subflow",
      "pack": "Salesforce-PingCAP-L2",
      "flow": "Std_ConvertLead.flow.json",
      "subflow": "RelinkLeadChildren",
      "expect": {
        "flowName": "Std_RelinkLeadChildren",
        "inputAssignments": {
          "leadId": {"elementReference": "leadId"},
          "contactId": {"elementReference": "contactId"}
        }
      }
    },
    {
      "id": "inbound-converted-lead-routes-to-durable-transfer",
      "type": "flow_rule",
      "flow": "HubSpot_Contact_Lead_Upsert.flow.json",
      "decision": "CheckMatchedLeadStillActive",
      "rule": "DurableLeadCurrentStateConverted",
      "expect": {
        "connector": {"targetReference": "TransferConvertedLeadRemoteIdentityToContact"}
      }
    },
    {
      "id": "inbound-transfer-targets-exact-converted-contact",
      "type": "flow_action",
      "flow": "HubSpot_Contact_Lead_Upsert.flow.json",
      "action": "TransferConvertedLeadRemoteIdentityToContact",
      "expect": {
        "actionName": "transferConnectorRemoteIdentity",
        "actionType": "transferConnectorRemoteIdentity",
        "inputParameters": {
          "sourceObject": {"stringValue": "Lead"},
          "sourceId": {"elementReference": "$matchedLeadState.Id"},
          "targetObject": {"stringValue": "Contact"},
          "targetId": {"elementReference": "$matchedLeadState.ConvertedContactId"},
          "remoteIDField": {"stringValue": "HubSpot_Id__c"}
        }
      }
    },
    {
      "id": "inbound-transfer-enables-contact-sync-only-after-success",
      "type": "flow_rule",
      "flow": "HubSpot_Contact_Lead_Upsert.flow.json",
      "decision": "ChooseContactAuthorshipRegistration",
      "rule": "ConvertedLeadIdentityTransferred",
      "expect": {
        "connector": {"targetReference": "EnableTransferredContactHubSpotSync"}
      }
    },
    {
      "id": "inbound-transfer-enables-the-converted-contact",
      "type": "record_update",
      "flow": "HubSpot_Contact_Lead_Upsert.flow.json",
      "update": "EnableTransferredContactHubSpotSync",
      "expect": {
        "object": "Contact",
        "filters": [
          {
            "field": "Id",
            "operator": "EqualTo",
            "value": {"elementReference": "matchedContactId"}
          }
        ],
        "inputAssignments": [
          {"field": "HubSpot_Sync_Enabled__c", "value": true}
        ]
      }
    }
  ]
}
