{
  "id": "disqualified-lifecycle-entry",
  "title": "HubSpot Disqualified lifecycle entry stamps Lead Disqualified_Date__c",
  "kind": "hubspot_sync",
  "executionMode": "serial",
  "executionModeReason": "Mutates one live HubSpot Contact through shared outbound and inbound queues; isolation keeps lifecycle-event attribution deterministic.",
  "caseTimeoutMs": 1500000,
  "linkedIssues": [3529],
  "provenance": {
    "businessScenario": "生成PR一个HubSpot的Integration Test,防止此类问题再次发生。\n\n[clarified] Prod recurrence: HubSpot lifecyclestage enters Disqualified for an NA Lead whose Disqualified_Date__c is blank; inbound mapping must stamp Disqualified_Date__c from the lifecycle entry event before updating Lifecycle_Stage__c.",
    "reportedBy": "Amber / prod HubSpot incident follow-up",
    "capturedAt": "2026-07-01",
    "calibrated": "[recalibrated 2026-07-22] HubSpot marks the Salesforce integration property salesforceleadid read-only, so a private-app integration case cannot author it. The case explicitly enables Lead outbound, waits for the connector-owned durable HubSpot link/writeback, and mutates that exact remote Contact. Email remains matching data, never identity authority."
  },
  "steps": [
    {
      "id": "create-na-lead",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "POST",
      "path": "/services/data/v63.0/sobjects/Lead",
      "body": {
        "LastName": "DisqEntry{{__runId}}",
        "Company": "DisqEntry{{__runId}}",
        "Email": "disq-entry-{{__runId}}@example.com",
        "Country": "United States",
        "Region__c": "NA",
        "Lifecycle_Stage__c": "lead",
        "HubSpot_Sync_Enabled__c": true
      },
      "expectStatusRange": [200, 299],
      "assertions": [
        { "path": "response.body.id", "exists": true }
      ]
    },
    {
      "id": "wait-contact-link",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,HubSpot_Id__c FROM Lead WHERE Id='{{steps.create-na-lead.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 600000, "intervalMs": 6000 },
      "onTimeout": "blocked",
      "assertions": [
        { "path": "response.body.records[0].HubSpot_Id__c", "exists": true }
      ]
    },
    {
      "id": "assert-local-precondition",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,HubSpot_Id__c,Region__c,Lifecycle_Stage__c,Disqualified_Date__c FROM Lead WHERE Id='{{steps.create-na-lead.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.records[0].HubSpot_Id__c", "equals": "{{steps.wait-contact-link.response.body.records[0].HubSpot_Id__c}}" },
        { "path": "response.body.records[0].Region__c", "equals": "NA" },
        { "path": "response.body.records[0].Lifecycle_Stage__c", "equals": "lead" },
        { "path": "response.body.records[0].Disqualified_Date__c", "exists": false }
      ]
    },
    {
      "id": "assert-hubspot-contact-precondition",
      "system": "hubspot",
      "method": "GET",
      "path": "/crm/v3/objects/contacts/{{steps.wait-contact-link.response.body.records[0].HubSpot_Id__c}}?properties=lifecyclestage",
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.id", "equals": "{{steps.wait-contact-link.response.body.records[0].HubSpot_Id__c}}" },
        { "path": "response.body.properties.lifecyclestage", "equals": "lead" }
      ]
    },
    {
      "id": "enter-disqualified-in-hubspot",
      "system": "hubspot",
      "method": "PATCH",
      "path": "/crm/v3/objects/contacts/{{steps.wait-contact-link.response.body.records[0].HubSpot_Id__c}}",
      "body": {
        "properties": {
          "lifecyclestage": "68053680"
        }
      },
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.id", "exists": true }
      ]
    },
    {
      "id": "assert-disqualified-date-stamped",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,HubSpot_Id__c,Region__c,Lifecycle_Stage__c,Disqualified_Date__c FROM Lead WHERE Id='{{steps.create-na-lead.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 600000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].HubSpot_Id__c", "equals": "{{steps.wait-contact-link.response.body.records[0].HubSpot_Id__c}}" },
        { "path": "response.body.records[0].Region__c", "equals": "NA" },
        { "path": "response.body.records[0].Lifecycle_Stage__c", "equals": "68053680" },
        { "path": "response.body.records[0].Disqualified_Date__c", "exists": true }
      ],
      "diagnostics": {
        "connectorEvent": {
          "sourceObjectId": "{{steps.wait-contact-link.response.body.records[0].HubSpot_Id__c}}",
          "eventKind": "contact.propertychange",
          "blockOnBacklog": true
        }
      }
    }
  ]
}
