{
  "id": "in-routing",
  "title": "HubSpot contact routes to a new Lead, not a direct Contact",
  "kind": "hubspot_sync",
  "executionMode": "serial",
  "executionModeReason": "This routing oracle depends on first inbound materialization and is queue-pressure sensitive; run isolated after the parallel batch.",
  "linkedIssues": [],
  "provenance": {
    "businessScenario": "IN-ROUTING — a new HubSpot contact materializes as a NexusCRM Lead; a contact with no prior converted Contact must NOT create a Contact row. Control field FirstName proves the inbound link fired.",
    "reportedBy": "HubSpot sync spec IN-ROUTING (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-17"
  },
  "steps": [
    {
      "id": "hsNew",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": {
        "properties": {
          "email": "route-{{__runId}}@example.com",
          "firstname": "Router",
          "lastname": "New{{__runId}}"
        }
      },
      "expectStatusRange": [
        200,
        299
      ],
      "assertions": [
        {
          "path": "response.body.id",
          "exists": true
        }
      ]
    },
    {
      "id": "leadQ",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id, FirstName FROM Lead WHERE HubSpot_Id__c = '{{steps.hsNew.response.body.id}}'",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 90000,
        "intervalMs": 6000
      },
      "onTimeout": "blocked",
      "assertions": [
        {
          "path": "response.body.totalSize",
          "atLeast": 1
        },
        {
          "path": "response.body.records[0].FirstName",
          "equals": "Router"
        }
      ],
      "timeoutMs": 8000
    },
    {
      "id": "contactQ",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id FROM Contact WHERE HubSpot_Id__c = '{{steps.hsNew.response.body.id}}'",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 90000,
        "intervalMs": 8000
      },
      "onTimeout": "fail",
      "assertions": [
        {
          "path": "response.body.totalSize",
          "numericEquals": 0
        }
      ],
      "timeoutMs": 8000
    }
  ]
}
