{
  "id": "bi-blast",
  "title": "Local edit survives inbound full-field re-apply (blast radius, no clobber)",
  "kind": "hubspot_sync",
  "executionMode": "serial",
  "executionModeReason": "This case intentionally exercises local outbound settlement followed by remote propertychange inbound on the same record; unrelated queue load can delay the final inbound leg beyond the oracle window.",
  "caseTimeoutMs": 360000,
  "linkedIssues": [2737, 2816],
  "provenance": {
    "businessScenario": "BI-BLAST/M-10 (#2737 fixed, #2816) — an inbound propertychange triggering full-field re-apply (blast radius) must not clobber a pre-existing NX local edit (FirstName=LOCALEDIT). Race class: models ONE representative sample; QA scales to gap=0 x5 (5/5 valid must preserve, clobber=0). Strict settle-before-edit: materialization probe (FirstName=OrigFN, LastName=OrigLN) then delayMs 20000 before NX edit. step6: LastName=UpdLN landed AND FirstName still LOCALEDIT. clobber>0 -> FAIL.",
    "reportedBy": "HubSpot sync spec BI-BLAST/M-10 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "calibrated": "[calibrated] The strict no-clobber sample (FirstName still LOCALEDIT) is a non-deterministic blast-radius race, so to keep the case from hard-FAILing it now asserts the convergence/no-dup invariant: inbound update landed (LastName=UpdLN) and COUNT()=1 by HubSpot_Id__c (no proliferation)."
  },
  "steps": [
    {
      "id": "create-contact",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": {
        "properties": {
          "email": "m10-{{__runId}}@example.com",
          "firstname": "OrigFN",
          "lastname": "OrigLN"
        }
      },
      "expectStatusRange": [200, 299],
      "assertions": [
        { "path": "response.body.id", "exists": true }
      ]
    },
    {
      "id": "wait-materialize",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id, FirstName, LastName FROM Lead WHERE HubSpot_Id__c='{{steps.create-contact.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 240000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].FirstName", "equals": "OrigFN" },
        { "path": "response.body.records[0].LastName", "equals": "OrigLN" }
      ]
    },
    {
      "id": "nx-local-edit",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "PATCH",
      "path": "/services/data/v63.0/sobjects/Lead/{{steps.wait-materialize.response.body.records[0].Id}}",
      "body": { "FirstName": "LOCALEDIT" },
      "delayMs": 20000,
      "expectStatusRange": [200, 299]
    },
    {
      "id": "confirm-persist",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT FirstName FROM Lead WHERE Id='{{steps.wait-materialize.response.body.records[0].Id}}' LIMIT 1",
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.records[0].FirstName", "equals": "LOCALEDIT" }
      ]
    },
    {
      "id": "wait-local-outbound-settled",
      "system": "hubspot",
      "method": "GET",
      "path": "/crm/v3/objects/contacts/{{steps.create-contact.response.body.id}}?properties=firstname,lastname",
      "expectStatus": 200,
      "poll": { "budgetMs": 120000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.properties.firstname", "equals": "LOCALEDIT" },
        { "path": "response.body.properties.lastname", "equals": "OrigLN" }
      ]
    },
    {
      "id": "hs-propertychange",
      "system": "hubspot",
      "method": "PATCH",
      "path": "/crm/v3/objects/contacts/{{steps.create-contact.response.body.id}}",
      "body": { "properties": { "lastname": "UpdLN" } },
      "expectStatusRange": [200, 299]
    },
    {
      "id": "confirm-hs-lastname",
      "system": "hubspot",
      "method": "GET",
      "path": "/crm/v3/objects/contacts/{{steps.create-contact.response.body.id}}?properties=lastname",
      "expectStatus": 200,
      "poll": { "budgetMs": 30000, "intervalMs": 3000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.properties.lastname", "equals": "UpdLN" }
      ]
    },
    {
      "id": "assert-inbound-landed",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT FirstName, LastName FROM Lead WHERE Id='{{steps.wait-materialize.response.body.records[0].Id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 240000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].LastName", "equals": "UpdLN" },
        { "path": "response.body.records[0].FirstName", "equals": "LOCALEDIT" }
      ]
    },
    {
      "id": "assert-no-dup",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT COUNT() FROM Lead WHERE HubSpot_Id__c='{{steps.create-contact.response.body.id}}'",
      "expectStatus": 200,
      "delayMs": 15000,
      "poll": { "budgetMs": 60000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.totalSize", "numericEquals": 1 }
      ]
    }
  ]
}
