{
  "id": "disqualified-date-historical-lead",
  "title": "HubSpot contact delta updates historical Disqualified Lead without Disqualified Date",
  "kind": "hubspot_sync",
  "executionMode": "serial",
  "executionModeReason": "This regression first drains the contact's creation-time propertychange fan-out, then creates one historical dirty Lead state while outbound sync is disabled and sends the asserted unrelated propertychange. Serial execution keeps the connector diagnostics tied to that contact event; the workflow preflight rejects an already-busy connector queue.",
  "caseTimeoutMs": 900000,
  "linkedIssues": [],
  "provenance": {
    "businessScenario": "A historical Lead may already be Lifecycle_Stage__c='68053680' (Disqualified) with Disqualified_Date__c blank. HubSpot must not sync Disqualified_Date__c, and an unrelated inbound contacts propertychange such as recent_source_details must still update mapped fields instead of failing the Disqualified Date validation rule. The case drains HubSpot's delayed creation-time propertychange fan-out before constructing the historical local state, disables outbound sync, proves the HubSpot contact was not changed by setup, then patches HubSpot recent_source_details and asserts Recent_Source_Detail__c lands.",
    "reportedBy": "Prod contacts alert RCA 2026-06-29",
    "capturedAt": "2026-06-29",
    "calibrated": "[recalibrated 2026-08-26] D3 ConnectorEvent rows are immutable admission history. ConnectorWorkItem plus RuntimePlatformCommand own execution, so the fixture drains every event through direct WorkItem ownership or source-projection coverage and requires every processed handoff to reach a terminal Runtime command before authoring the historical dirty state."
  },
  "steps": [
    {
      "id": "create-contact",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": {
        "properties": {
          "email": "dqdate-{{__runId}}@example.com",
          "firstname": "DqBase",
          "lastname": "Historical{{__runId}}",
          "country_picklist__sfdc_": "United States",
          "lifecyclestage": "lead"
        }
      },
      "expectStatusRange": [200, 299],
      "assertions": [
        { "path": "response.body.id", "exists": true }
      ]
    },
    {
      "id": "wait-na-lead",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,Region__c,Lifecycle_Stage__c,Disqualified_Date__c FROM Lead WHERE HubSpot_Id__c='{{steps.create-contact.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 240000, "intervalMs": 6000 },
      "onTimeout": "blocked",
      "assertions": [
        { "path": "response.body.records[0].Region__c", "equals": "NA" },
        { "path": "response.body.records[0].Lifecycle_Stage__c", "equals": "lead" }
      ],
      "diagnostics": {
        "connectorEvent": {
          "sourceObjectId": "{{steps.create-contact.response.body.id}}",
          "eventKind": "contact.propertychange",
          "blockOnBacklog": true,
          "blockOnForeignClaimedBy": true
        }
      },
      "timeoutMs": 8000
    },
    {
      "id": "wait-contact-propertychanges-drained",
      "system": "tidb",
      "method": "GET",
      "sql": "SELECT CASE WHEN COUNT(*) > 0 AND MAX(E.CreatedDate) <= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 60 SECOND) AND NOT EXISTS (SELECT 1 FROM `_System_ConnectorWorkItem` W JOIN `_System_ConnectorEvent` S ON S.Id = W.EventId WHERE S.Namespace = 'hubspot-crm-connector' AND S.EventKind = 'contact.propertychange' AND S.SourceObjectID = '{{steps.create-contact.response.body.id}}' AND W.WorkType IN ('connector_event', 'workflow_action_apply') AND W.State NOT IN ('processed', 'skipped')) AND NOT EXISTS (SELECT 1 FROM `_System_ConnectorWorkItem` W JOIN `_System_ConnectorEvent` S ON S.Id = W.EventId WHERE S.Namespace = 'hubspot-crm-connector' AND S.EventKind = 'contact.propertychange' AND S.SourceObjectID = '{{steps.create-contact.response.body.id}}' AND W.WorkType IN ('connector_event', 'workflow_action_apply') AND W.State = 'processed' AND NOT EXISTS (SELECT 1 FROM `_System_ConnectorRuntimeHandoffReceipt` R JOIN `_System_RuntimePlatformCommand` C ON C.CommandId = R.CommandId WHERE R.WorkId = W.WorkId AND R.EventId = W.EventId AND C.State IN ('COMPLETED', 'FAILED', 'POISONED'))) AND NOT EXISTS (SELECT 1 FROM `_System_ConnectorEvent` X WHERE X.Namespace = 'hubspot-crm-connector' AND X.EventKind = 'contact.propertychange' AND X.SourceObjectID = '{{steps.create-contact.response.body.id}}' AND NOT EXISTS (SELECT 1 FROM `_System_ConnectorWorkItem` W JOIN `_System_ConnectorEvent` S ON S.Id = W.EventId WHERE W.WorkType IN ('connector_event', 'workflow_action_apply') AND (W.EventId = X.Id OR (W.InstalledPackId = X.InstalledPackId AND NULLIF(COALESCE(W.ProjectionKey, ''), '') IS NOT NULL AND COALESCE(W.SourceLaneKey, '') = COALESCE(X.SourceLaneKey, '') AND S.InstalledPackId = X.InstalledPackId AND LOWER(TRIM(S.EventKind)) = LOWER(TRIM(X.EventKind)) AND COALESCE(S.RouteVersion, 0) = COALESCE(X.RouteVersion, 0) AND COALESCE(S.CompanionPackInstallId, '') = COALESCE(X.CompanionPackInstallId, '') AND COALESCE(S.CompanionFlowVersionId, '') = COALESCE(X.CompanionFlowVersionId, '') AND ((X.EnqueueOrdinal <> 0 AND S.EnqueueOrdinal <> 0 AND (X.EnqueueOrdinal < S.EnqueueOrdinal OR (X.EnqueueOrdinal = S.EnqueueOrdinal AND X.Id <= S.Id))) OR ((X.EnqueueOrdinal = 0 OR S.EnqueueOrdinal = 0) AND (X.CreatedDate < S.CreatedDate OR (X.CreatedDate = S.CreatedDate AND (X.DeliverySequence < S.DeliverySequence OR (X.DeliverySequence = S.DeliverySequence AND X.Id <= S.Id)))))))))) THEN 1 ELSE 0 END AS Ready, COUNT(*) AS EventCount, MAX(E.CreatedDate) AS LastEventCreatedAt FROM `_System_ConnectorEvent` E WHERE E.Namespace = 'hubspot-crm-connector' AND E.EventKind = 'contact.propertychange' AND E.SourceObjectID = '{{steps.create-contact.response.body.id}}'",
      "expectStatus": 200,
      "poll": { "budgetMs": 180000, "intervalMs": 6000 },
      "onTimeout": "blocked",
      "assertions": [
        { "path": "response.body.records[0].Ready", "numericEquals": 1 }
      ]
    },
    {
      "id": "disable-outbound-sync-for-fixture",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "PATCH",
      "path": "/services/data/v63.0/sobjects/Lead/{{steps.wait-na-lead.response.body.records[0].Id}}",
      "body": {
        "HubSpot_Sync_Enabled__c": false
      },
      "expectStatus": 204
    },
    {
      "id": "enter-disqualified-with-date",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "PATCH",
      "path": "/services/data/v63.0/sobjects/Lead/{{steps.wait-na-lead.response.body.records[0].Id}}",
      "body": {
        "Lifecycle_Stage__c": "68053680",
        "Disqualified_Date__c": "2026-06-29T00:00:00Z"
      },
      "expectStatus": 204
    },
    {
      "id": "clear-disqualified-date",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "PATCH",
      "path": "/services/data/v63.0/sobjects/Lead/{{steps.wait-na-lead.response.body.records[0].Id}}",
      "body": {
        "Disqualified_Date__c": null
      },
      "expectStatus": 204
    },
    {
      "id": "assert-historical-dirty-state",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,Region__c,Lifecycle_Stage__c,Disqualified_Date__c,Recent_Source_Detail__c FROM Lead WHERE Id='{{steps.wait-na-lead.response.body.records[0].Id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 30000, "intervalMs": 3000 },
      "onTimeout": "fail",
      "assertions": [
        { "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": false }
      ],
      "timeoutMs": 8000
    },
    {
      "id": "assert-hubspot-fixture-isolated",
      "system": "hubspot",
      "method": "GET",
      "path": "/crm/v3/objects/contacts/{{steps.create-contact.response.body.id}}?properties=lifecyclestage",
      "delayMs": 20000,
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.properties.lifecyclestage", "equals": "lead" }
      ]
    },
    {
      "id": "hubspot-recent-source-details",
      "system": "hubspot",
      "method": "PATCH",
      "path": "/crm/v3/objects/contacts/{{steps.create-contact.response.body.id}}",
      "body": {
        "properties": {
          "recent_source_details": "LinkedIn - InMail"
        }
      },
      "expectStatusRange": [200, 299]
    },
    {
      "id": "assert-propertychange-landed",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,Lifecycle_Stage__c,Disqualified_Date__c,Recent_Source_Detail__c FROM Lead WHERE Id='{{steps.wait-na-lead.response.body.records[0].Id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 300000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].Lifecycle_Stage__c", "equals": "68053680" },
        { "path": "response.body.records[0].Disqualified_Date__c", "exists": false },
        { "path": "response.body.records[0].Recent_Source_Detail__c", "equals": "Linkedin - InMail" }
      ],
      "diagnostics": {
        "connectorEvent": {
          "sourceObjectId": "{{steps.create-contact.response.body.id}}",
          "eventKind": "contact.propertychange",
          "blockOnBacklog": true,
          "blockOnForeignClaimedBy": true
        }
      },
      "timeoutMs": 8000
    }
  ]
}
