{
  "id": "acq-bulk-01",
  "title": "Bulk acquisition reconcile: N contacts to Leads with zero loss / zero dup / fields hydrated",
  "kind": "hubspot_sync",
  "executionMode": "serial",
  "executionModeReason": "This small bulk-acquisition oracle creates three HubSpot contacts and reconciles all three by id; under shared webhook queue pressure one row can miss the poll window, so run isolated after the parallel batch.",
  "linkedIssues": [2862, 2863],
  "provenance": {
    "businessScenario": "ACQ-BULK-01 — validate bulk acquisition end-to-end: using the HubSpot contact id list as the oracle, every contact must materialize as exactly one NexusCRM Lead with 0 loss / 0 dup, fields hydrated (especially Country), and owner routed. Re-proves red lines #2862 (Country/owner missing) and #2863 (duplicate Lead). The runner is sequential with a 90s poll cap and the ngrok tunnel is slow, so this models a representative small N=3 (acq-{{__runId}}-1..3) and reconciles Leads only (CampaignMember reconcile against an env test Campaign is an environment oracle and is omitted). A real bound HubSpot owner (44888233 -> Shenghu Zhou) is hardcoded as the inbound owner, but PingCAP assignment may route all Leads to a different final owner; shadow HubSpot_Owner_Id__c must follow that assigned owner's HubSpotOwnerBinding__c when bound and stay null when unbound.",
    "reportedBy": "HubSpot sync spec ACQ-BULK-01 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "calibrated": "[calibrated] removed the binding-discovery step (it queried the wrong HubSpotOwnerBinding__c columns 'Status'/'HubSpot_Owner_Id__c' and SOQL-errored). Used sandbox-legal salesforce_industry 'FSI-FinTech' and hs_lead_status 'OPEN'. Kept N=3 small to fit the slow tunnel under the 90s poll cap. 2026-06-22 run 27962691451 showed all three Leads materialized with Country/Industry hydrated and assignment routing to Daniel Basist, while the stale assertion still expected inbound owner shadow 45282439; updated the oracle to derive shadow from the final assigned OwnerId's bound HubSpotOwnerBinding__c, matching K-ASSIGN-01 and the owner-shadow flow contract."
  },
  "steps": [
    {
      "id": "c1",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": { "properties": { "email": "acq-{{__runId}}-1@example.com", "firstname": "AcqFN1", "lastname": "AcqLN1", "country_picklist__sfdc_": "United States", "hubspot_owner_id": "44888233", "salesforce_industry": "FSI-FinTech", "hs_lead_status": "OPEN" } },
      "expectStatusRange": [200, 299],
      "assertions": [ { "path": "response.body.id", "exists": true } ]
    },
    {
      "id": "c2",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": { "properties": { "email": "acq-{{__runId}}-2@example.com", "firstname": "AcqFN2", "lastname": "AcqLN2", "country_picklist__sfdc_": "United States", "hubspot_owner_id": "44888233", "salesforce_industry": "FSI-FinTech", "hs_lead_status": "OPEN" } },
      "expectStatusRange": [200, 299],
      "assertions": [ { "path": "response.body.id", "exists": true } ]
    },
    {
      "id": "c3",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": { "properties": { "email": "acq-{{__runId}}-3@example.com", "firstname": "AcqFN3", "lastname": "AcqLN3", "country_picklist__sfdc_": "United States", "hubspot_owner_id": "44888233", "salesforce_industry": "FSI-FinTech", "hs_lead_status": "OPEN" } },
      "expectStatusRange": [200, 299],
      "assertions": [ { "path": "response.body.id", "exists": true } ]
    },
    {
      "id": "cntA",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT COUNT() FROM Lead WHERE HubSpot_Id__c IN ('{{steps.c1.response.body.id}}','{{steps.c2.response.body.id}}','{{steps.c3.response.body.id}}')",
      "expectStatus": 200,
      "poll": { "budgetMs": 420000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.totalSize", "numericEquals": 3 }
      ]
    },
    {
      "id": "fields",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT HubSpot_Id__c,Country,OwnerId,HubSpot_Owner_Id__c,Industry FROM Lead WHERE HubSpot_Id__c IN ('{{steps.c1.response.body.id}}','{{steps.c2.response.body.id}}','{{steps.c3.response.body.id}}')",
      "expectStatus": 200,
      "poll": { "budgetMs": 420000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records", "lengthAtLeast": 3 },
        { "path": "response.body.records", "countWhere": { "where": { "Country": "United States" }, "equals": 3 } },
        { "path": "response.body.records[0].OwnerId", "exists": true },
        { "path": "response.body.records", "countWhere": { "where": { "OwnerId": "{{steps.fields.response.body.records[0].OwnerId}}" }, "equals": 3 } }
      ]
    },
    {
      "id": "owner-binding",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT HubSpotOwnerId__c FROM HubSpotOwnerBinding__c WHERE CRMPrincipalId__c='{{steps.fields.response.body.records[0].OwnerId}}' AND BindingStatus__c='bound'",
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.totalSize", "atLeast": 0 }
      ]
    },
    {
      "id": "bound-owner-shadow",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "whenPathExists": "steps.owner-binding.response.body.records[0].HubSpotOwnerId__c",
      "path": "/services/data/v63.0/query?q=SELECT HubSpot_Id__c,OwnerId,HubSpot_Owner_Id__c FROM Lead WHERE HubSpot_Id__c IN ('{{steps.c1.response.body.id}}','{{steps.c2.response.body.id}}','{{steps.c3.response.body.id}}')",
      "expectStatus": 200,
      "poll": { "budgetMs": 420000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records", "countWhere": { "where": { "HubSpot_Owner_Id__c": "{{steps.owner-binding.response.body.records[0].HubSpotOwnerId__c}}" }, "equals": 3 } }
      ]
    },
    {
      "id": "unbound-owner-shadow",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "whenPathMissing": "steps.owner-binding.response.body.records[0].HubSpotOwnerId__c",
      "path": "/services/data/v63.0/query?q=SELECT HubSpot_Id__c,OwnerId,HubSpot_Owner_Id__c FROM Lead WHERE HubSpot_Id__c IN ('{{steps.c1.response.body.id}}','{{steps.c2.response.body.id}}','{{steps.c3.response.body.id}}')",
      "expectStatus": 200,
      "poll": { "budgetMs": 420000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records", "countWhere": { "where": { "HubSpot_Owner_Id__c": null }, "equals": 3 } }
      ]
    },
    {
      "id": "dedup",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,HubSpot_Id__c FROM Lead WHERE HubSpot_Id__c IN ('{{steps.c1.response.body.id}}','{{steps.c2.response.body.id}}','{{steps.c3.response.body.id}}')",
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.records", "countWhere": { "where": {}, "equals": 3 } }
      ]
    }
  ]
}
