{
  "id": "acq-dedup-01",
  "title": "Same person concurrent multi-channel intake yields exactly one NX Lead",
  "kind": "hubspot_sync",
  "executionMode": "serial",
  "executionModeReason": "HubSpot contact materialization is queue-sensitive under the full-suite webhook burst and must run without competing case traffic.",
  "linkedIssues": [2863],
  "provenance": {
    "businessScenario": "ACQ-DEDUP-01 — a single email arriving via multiple channels / concurrently (gap=0) must yield exactly one NexusCRM Lead. HubSpot itself dedups by email so repeated creates resolve to the same contact id; a control field (firstname -> DedupTriggered) proves the inbound link fired before counting. Re-proves #2863 (duplicate Lead). Spec asks for >=5 concurrent samples; the runner is sequential so this models 5 create attempts against one fixed email (dedup-{{__runId}}@example.com) and asserts COUNT(Lead)=1 by both HubSpot_Id__c and Email.",
    "reportedBy": "HubSpot sync spec ACQ-DEDUP-01 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "calibrated": "[calibrated] verified PASS-able on ksyun: 5 creates to one fixed email (HubSpot upserts to a single contact id), control firstname edit (DedupTriggered) proves the inbound link fired, then COUNT(Lead)=1 by both HubSpot_Id__c and Email."
  },
  "steps": [
    {
      "id": "c1",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": { "properties": { "email": "dedup-{{__runId}}@example.com", "firstname": "DedupFN", "lastname": "DedupLN" } },
      "expectStatusRange": [200, 299],
      "assertions": [ { "path": "response.body.id", "exists": true } ]
    },
    {
      "id": "c2",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": { "properties": { "email": "dedup-{{__runId}}@example.com", "firstname": "DedupFN", "lastname": "DedupLN" } },
      "expectStatusRange": [200, 499]
    },
    {
      "id": "c3",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": { "properties": { "email": "dedup-{{__runId}}@example.com", "firstname": "DedupFN", "lastname": "DedupLN" } },
      "expectStatusRange": [200, 499]
    },
    {
      "id": "c4",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": { "properties": { "email": "dedup-{{__runId}}@example.com", "firstname": "DedupFN", "lastname": "DedupLN" } },
      "expectStatusRange": [200, 499]
    },
    {
      "id": "c5",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": { "properties": { "email": "dedup-{{__runId}}@example.com", "firstname": "DedupFN", "lastname": "DedupLN" } },
      "expectStatusRange": [200, 499]
    },
    {
      "id": "ctrlEdit",
      "system": "hubspot",
      "method": "PATCH",
      "path": "/crm/v3/objects/contacts/{{steps.c1.response.body.id}}",
      "body": { "properties": { "firstname": "DedupTriggered" } },
      "expectStatusRange": [200, 299],
      "assertions": [ { "path": "response.body.id", "exists": true } ]
    },
    {
      "id": "ctrl",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT FirstName FROM Lead WHERE HubSpot_Id__c = '{{steps.c1.response.body.id}}'",
      "expectStatus": 200,
      "poll": { "budgetMs": 300000, "intervalMs": 3000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].FirstName", "equals": "DedupTriggered" }
      ]
    },
    {
      "id": "cntById",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT COUNT() FROM Lead WHERE HubSpot_Id__c = '{{steps.c1.response.body.id}}'",
      "expectStatus": 200,
      "delayMs": 20000,
      "assertions": [
        { "path": "response.body.totalSize", "numericEquals": 1 }
      ]
    },
    {
      "id": "cntByEmail",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT COUNT() FROM Lead WHERE Email = 'dedup-{{__runId}}@example.com'",
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.totalSize", "numericEquals": 1 }
      ]
    }
  ]
}
