{
  "id": "ai-vertical-en-dash",
  "title": "Artificial Intelligence EN DASH vertical lands and survives a later sparse delta",
  "kind": "hubspot_sync",
  "optional": false,
  "executionMode": "serial",
  "executionModeReason": "The case separates initial Industry/Vertical materialization from a later sparse lastname delta and then holds a settle window, so the same Contact source lane must remain uncontaminated.",
  "caseTimeoutMs": 1080000,
  "linkedIssues": [5220],
  "provenance": {
    "businessScenario": "A HubSpot Contact carrying salesforce_industry=Artificial Intelligence and the canonical U+2013 EN DASH AI vertical must populate Lead.Industry and Lead.Vertical__c exactly. A later sparse lastname-only delta must update LastName without blanking or rewriting either controlling value, and the result must remain stable after 60 seconds.",
    "reportedBy": "Historical issue #5220 / fix PR #5301 review",
    "capturedAt": "2026-08-26",
    "upstreamFix": "https://github.com/pingcap-inc/nexuscrm-pingcap-pack/pull/5301",
    "calibrated": "The assertion uses the exact EN DASH character rather than a visually similar hyphen. The later signed sparse event catches both composite-value-map regressions and broad-payload sibling erasure."
  },
  "steps": [
    {
      "id": "create-ai-contact",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": {
        "properties": {
          "email": "ai-vertical-{{__runId}}@example.com",
          "firstname": "Artificial",
          "lastname": "Intelligence{{__runId}}",
          "salesforce_industry": "Artificial Intelligence",
          "salesforce_industry__vertical_": "AI – Native Applications"
        }
      },
      "expectStatusRange": [200, 299],
      "assertions": [{ "path": "response.body.id", "exists": true }]
    },
    {
      "id": "wait-ai-lead",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,HubSpot_Id__c,Industry,Vertical__c,LastName FROM Lead WHERE HubSpot_Id__c='{{steps.create-ai-contact.response.body.id}}' AND IsConverted=false LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 300000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].HubSpot_Id__c", "equals": "{{steps.create-ai-contact.response.body.id}}" },
        { "path": "response.body.records[0].Industry", "equals": "Artificial Intelligence" },
        { "path": "response.body.records[0].Vertical__c", "equals": "AI – Native Applications" },
        { "path": "response.body.records[0].LastName", "equals": "Intelligence{{__runId}}" }
      ]
    },
    {
      "id": "capture-sparse-clock",
      "system": "tidb",
      "method": "GET",
      "sql": "SELECT CAST(UNIX_TIMESTAMP(UTC_TIMESTAMP(3)) * 1000 AS UNSIGNED) AS OccurredAtMillis",
      "expectStatus": 200,
      "assertions": [{ "path": "response.body.records[0].OccurredAtMillis", "exists": true }]
    },
    {
      "id": "send-unrelated-sparse-delta",
      "system": "connector_webhook",
      "method": "POST",
      "path": "/webhooks/hubspot-crm-connector/webhook",
      "body": [
        {
          "portalId": 51280875,
          "appId": 44166359,
          "subscriptionId": 6723583,
          "eventId": "ai-vertical-sparse-{{__runId}}",
          "occurredAt": "{{steps.capture-sparse-clock.response.body.records[0].OccurredAtMillis}}",
          "subscriptionType": "contact.propertyChange",
          "attemptNumber": 0,
          "objectId": "{{steps.create-ai-contact.response.body.id}}",
          "propertyName": "lastname",
          "propertyValue": "AISettled{{__runId}}",
          "changeSource": "AUTOMATION_PLATFORM"
        }
      ],
      "expectStatus": 202,
      "assertions": [{ "path": "response.body", "exists": true }]
    },
    {
      "id": "assert-ai-vertical-after-sparse-delta",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,Industry,Vertical__c,LastName FROM Lead WHERE Id='{{steps.wait-ai-lead.response.body.records[0].Id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 300000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].Industry", "equals": "Artificial Intelligence" },
        { "path": "response.body.records[0].Vertical__c", "equals": "AI – Native Applications" },
        { "path": "response.body.records[0].LastName", "equals": "AISettled{{__runId}}" }
      ]
    },
    {
      "id": "assert-sparse-event-runtime-terminal",
      "system": "tidb",
      "method": "GET",
      "sql": "SELECT COUNT(DISTINCT E.Id) AS EventCount, COUNT(DISTINCT CASE WHEN W.State = 'processed' AND P.State = 'COMPLETED' AND COALESCE(P.ResultPayload, '') <> '' THEN P.Id END) AS RuntimeCompletedCount, COUNT(DISTINCT CASE WHEN W.WorkId IS NULL OR S.Id IS NULL OR W.State NOT IN ('processed', 'skipped') OR (W.State = 'processed' AND (P.Id IS NULL OR P.State <> 'COMPLETED' OR COALESCE(P.ResultPayload, '') = '')) THEN COALESCE(W.WorkId, E.Id) END) AS NonterminalOrDeadCount FROM `_System_ConnectorEvent` E LEFT JOIN `_System_ConnectorWorkItem` W ON W.InstalledPackId = E.InstalledPackId AND W.WorkType IN ('connector_event', 'workflow_action_apply') AND ((COALESCE(W.ProjectionKey, '') = '' AND W.EventId = E.Id) OR (BINARY W.ProjectionKey = BINARY CONCAT('csp:', LOWER(SHA2(CONCAT(TRIM(E.InstalledPackId), CHAR(0), LOWER(TRIM(E.EventKind)), CHAR(0), CAST(COALESCE(E.RouteVersion, 0) AS CHAR), CHAR(0), TRIM(COALESCE(E.CompanionPackInstallId, '')), CHAR(0), TRIM(COALESCE(E.CompanionFlowVersionId, '')), CHAR(0), TRIM(W.WorkType), CHAR(0), TRIM(E.SourceLaneKey)), 256))) AND W.SourceLaneKey = E.SourceLaneKey AND W.InputStartOrdinal > 0 AND E.EnqueueOrdinal BETWEEN W.InputStartOrdinal AND W.LaneOrdinal)) LEFT JOIN `_System_ConnectorEvent` S ON S.Id = W.EventId AND S.InstalledPackId = E.InstalledPackId AND S.SourceLaneKey = E.SourceLaneKey AND LOWER(TRIM(S.EventKind)) = LOWER(TRIM(E.EventKind)) AND COALESCE(S.RouteVersion, 0) = COALESCE(E.RouteVersion, 0) AND COALESCE(S.CompanionPackInstallId, '') = COALESCE(E.CompanionPackInstallId, '') AND COALESCE(S.CompanionFlowVersionId, '') = COALESCE(E.CompanionFlowVersionId, '') AND (COALESCE(W.ProjectionKey, '') = '' OR S.EnqueueOrdinal = W.LaneOrdinal) LEFT JOIN `_System_ConnectorRuntimeHandoffReceipt` H ON S.Id IS NOT NULL AND H.WorkId = W.WorkId AND H.EventId = W.EventId AND H.InstalledPackId = W.InstalledPackId AND H.Namespace = E.Namespace AND LOWER(TRIM(H.EventKind)) = LOWER(TRIM(S.EventKind)) AND H.RouteVersion = S.RouteVersion LEFT JOIN `_System_RuntimePlatformCommand` P ON P.CommandId = H.CommandId AND BINARY P.CommandId = BINARY H.CommandId AND P.ScopeDigest = LOWER(SHA2(CONCAT(H.OrgId, CHAR(0), H.AppInstallationId, CHAR(0), H.AuthorizedWorkloadId, CHAR(0), 'runtime.commands.accept.v1'), 256)) AND BINARY P.OrgId = BINARY H.OrgId AND BINARY P.AppInstallationId = BINARY H.AppInstallationId AND BINARY P.CallerWorkloadId = BINARY H.AuthorizedWorkloadId AND P.RuntimeCapabilityId = 'runtime.commands.accept.v1' AND P.CommandKind = H.CommandKind AND P.PayloadFormatVersion = H.PayloadFormatVersion WHERE E.Namespace = 'hubspot-crm-connector' AND E.EventKind = 'contact.propertychange' AND E.SourceObjectID = '{{steps.create-ai-contact.response.body.id}}' AND COALESCE(JSON_UNQUOTE(JSON_EXTRACT(E.Payload, '$.payload.eventId')), JSON_UNQUOTE(JSON_EXTRACT(E.Payload, '$.eventId'))) = 'ai-vertical-sparse-{{__runId}}'",
      "expectStatus": 200,
      "poll": { "budgetMs": 300000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].EventCount", "numericEquals": 1 },
        { "path": "response.body.records[0].RuntimeCompletedCount", "numericEquals": 1 },
        { "path": "response.body.records[0].NonterminalOrDeadCount", "numericEquals": 0 }
      ]
    },
    {
      "id": "assert-ai-vertical-settled",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,Industry,Vertical__c,LastName FROM Lead WHERE Id='{{steps.wait-ai-lead.response.body.records[0].Id}}' LIMIT 1",
      "delayMs": 60000,
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.records[0].Industry", "equals": "Artificial Intelligence" },
        { "path": "response.body.records[0].Vertical__c", "equals": "AI – Native Applications" },
        { "path": "response.body.records[0].LastName", "equals": "AISettled{{__runId}}" }
      ]
    }
  ]
}
