{
  "id": "rt-nx-05",
  "title": "NX-origin then HubSpot edit converges to same Lead, count stays 1",
  "kind": "hubspot_sync",
  "executionMode": "serial",
  "executionModeReason": "This round-trip convergence case depends on outbound identity settlement followed by same-record inbound echo; shared queue pressure can delay the echo window, so run isolated after the parallel batch.",
  "caseTimeoutMs": 780000,
  "linkedIssues": [],
  "provenance": {
    "businessScenario": "RT-NX-05 — a native Lead outbounds, then a HubSpot-side field edit (firstname=ConvergeFN) inbounds back to the same Lead; value converges and Lead count stays 1. Combined round-trip with settle-before-edit (delayMs 20000 before HubSpot PATCH avoids writeback race).",
    "reportedBy": "HubSpot sync spec RT-NX-05 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "calibrated": "[calibrated] Reviewed against ksyun sandbox: NX-origin then HubSpot-edit converges to same Lead; values sandbox-legal, settle-before-edit (delayMs 20000) preserved, COUNT()=1 invariant retained. No value changes needed."
  },
  "steps": [
    {
      "id": "create-lead",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "POST",
      "path": "/services/data/v63.0/sobjects/Lead",
      "body": {
        "LastName": "RTNX05{{__runId}}",
        "Company": "Co{{__runId}}",
        "Email": "rtnx05-{{__runId}}@example.com",
        "HubSpot_Sync_Enabled__c": true
      },
      "expectStatusRange": [200, 299],
      "assertions": [
        { "path": "response.body.id", "exists": true }
      ]
    },
    {
      "id": "poll-writeback",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id, HubSpot_Id__c FROM Lead WHERE Id='{{steps.create-lead.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 300000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].HubSpot_Id__c", "exists": true }
      ]
    },
    {
      "id": "patch-hubspot",
      "system": "hubspot",
      "method": "PATCH",
      "path": "/crm/v3/objects/contacts/{{steps.poll-writeback.response.body.records[0].HubSpot_Id__c}}",
      "body": { "properties": { "firstname": "ConvergeFN{{__runId}}" } },
      "delayMs": 20000,
      "expectStatusRange": [200, 299],
      "assertions": [
        { "path": "response.body.id", "exists": true }
      ]
    },
    {
      "id": "wait-converge",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id, FirstName FROM Lead WHERE HubSpot_Id__c='{{steps.poll-writeback.response.body.records[0].HubSpot_Id__c}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 300000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].FirstName", "equals": "ConvergeFN{{__runId}}" }
      ]
    },
    {
      "id": "assert-count-one",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT COUNT() FROM Lead WHERE HubSpot_Id__c='{{steps.poll-writeback.response.body.records[0].HubSpot_Id__c}}'",
      "expectStatus": 200,
      "delayMs": 15000,
      "poll": { "budgetMs": 120000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.totalSize", "numericEquals": 1 }
      ]
    }
  ]
}
