{
  "id": "fix-2582",
  "title": "Owner assigned on create, not deferred",
  "kind": "hubspot_sync",
  "caseTimeoutMs": 180000,
  "linkedIssues": [2582],
  "provenance": {
    "businessScenario": "FIX-2582 — re-prove #2582: an inbound contact gets its owner assigned at the create stage, not deferred to a later propertychange. Step 1 reads one bound HubSpotOwnerBinding__c (HS owner <-> NX User). Create a HubSpot contact carrying that hubspot_owner_id at create time plus control firstname=Fx2582FN. On first materialization the Lead must have shadow HubSpot_Owner_Id__c=bound HS owner and OwnerId=bound NX User (assigned on create, no second event). PASS (verbatim NEW runbook H FIX-2582): assigned on create. OwnerId default/system on first materialize = FAIL (deferred); no bound binding = BLOCKED (seed missing).",
    "reportedBy": "HubSpot sync spec FIX-2582 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "calibrated": "[calibrated] binding query uses real schema (BindingStatus__c/CRMPrincipalId__c/HubSpotOwnerId__c); hardcoded bound owner 45282439 -> NX user 005BV000000I2CPYA0 (Ardelle Fan). 2026-06-21 test1 run 27890394394 observed HubSpot delivery/materialization after the old 90s poll but with correct owner-on-create state. This case now uses a scoped 3m wall-clock backstop and 2.5m owner assertion poll so single-case reruns with a 210s outer watchdog still produce a verdict/artifact instead of being killed first."
  },
  "steps": [
    {
      "id": "get-binding",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT HubSpotOwnerId__c,CRMPrincipalId__c FROM HubSpotOwnerBinding__c WHERE BindingStatus__c='bound' AND HubSpotOwnerId__c='45282439' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 30000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records", "lengthAtLeast": 1 },
        { "path": "response.body.records[0].HubSpotOwnerId__c", "equals": "45282439" },
        { "path": "response.body.records[0].CRMPrincipalId__c", "exists": true }
      ]
    },
    {
      "id": "create-contact",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": {
        "properties": {
          "email": "fx2582-{{__runId}}@example.com",
          "lastname": "K",
          "firstname": "Fx2582FN",
          "hubspot_owner_id": "{{steps.get-binding.response.body.records[0].HubSpotOwnerId__c}}"
        }
      },
      "expectStatusRange": [200, 299],
      "assertions": [ { "path": "response.body.id", "exists": true } ]
    },
    {
      "id": "assert-owner-on-create",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,FirstName,OwnerId,HubSpot_Owner_Id__c FROM Lead WHERE HubSpot_Id__c='{{steps.create-contact.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 150000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].FirstName", "equals": "Fx2582FN" },
        { "path": "response.body.records[0].HubSpot_Owner_Id__c", "equals": "{{steps.get-binding.response.body.records[0].HubSpotOwnerId__c}}" },
        { "path": "response.body.records[0].OwnerId", "equals": "{{steps.get-binding.response.body.records[0].CRMPrincipalId__c}}" }
      ]
    }
  ]
}
