{
  "id": "k-camp-13",
  "title": "Set Campaign same-Campaign burst avoids parent Campaign lock failures",
  "kind": "hubspot_sync",
  "executionMode": "serial",
  "executionModeReason": "This regression intentionally fans out signed Set Campaign workflow-action posts against one fresh Campaign. Run it isolated so unrelated HubSpot queue pressure does not hide or create parent-lock symptoms.",
  "caseTimeoutMs": 480000,
  "provenance": {
    "businessScenario": "Regression for the production Campaign parent-lock RCA: multiple HubSpot workflow Action executions for distinct Contacts targeting the same NexusCRM Campaign must not return workflow-action 5xx and must materialize all Leads and CampaignMembers.",
    "rootCause": "Production showed POST /webhooks/hubspot-crm-connector/webhook 503s around 10s with RecordCreate CreateLeadCampaignMember failing to lock parent row Campaign. The L0 fix removes the synchronous parent Campaign lock for eventual COUNT rollups; this L2 case is a lightweight integration guard for the HubSpot path.",
    "scope": "Representative N=5, not the long-running 400/1000 contact stress canary. Scale K-CAMP-05 or a dedicated perf run for throughput and P95/max latency gates.",
    "oracle": "s2 catches immediate signed workflow-action 5xx through failedCount=0; s3/s4 catch lost writes. _System_ConnectorEvent is an internal operator table and is intentionally not a mandatory admin-role oracle for this suite."
  },
  "steps": [
    {
      "id": "s0-create-campaign",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "POST",
      "path": "/services/data/v63.0/sobjects/Campaign",
      "body": {
        "Name": "IT K-CAMP-13 lock {{__runId}}",
        "IsActive": true
      },
      "expectStatusRange": [
        200,
        299
      ],
      "assertions": [
        {
          "path": "response.body.id",
          "exists": true
        }
      ]
    },
    {
      "id": "s1-batch-create",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts/batch/create",
      "generate": {
        "count": 5,
        "into": "inputs",
        "itemTemplate": {
          "properties": {
            "email": "kcamp13-{{__runId}}-{{i}}@example.com",
            "firstname": "KCamp13",
            "lastname": "Lock-{{i}}",
            "company": "IT Campaign Lock {{i}}",
            "country_picklist__sfdc_": "Japan",
            "lifecyclestage": "lead"
          }
        }
      },
      "expectStatusRange": [
        200,
        299
      ],
      "assertions": [
        {
          "path": "response.body.results",
          "lengthAtLeast": 5
        }
      ]
    },
    {
      "id": "s2-set-campaign-burst",
      "system": "connector_action",
      "path": "/webhooks/hubspot-crm-connector/workflow-action",
      "forEach": "steps.s1-batch-create.response.body.results",
      "contactIdField": "id",
      "emailField": "properties.email",
      "campaignId": "{{steps.s0-create-campaign.response.body.id}}",
      "status": "Sent",
      "concurrency": 5,
      "assertions": [
        {
          "path": "response.body.failedCount",
          "numericEquals": 0
        },
        {
          "path": "response.body.acceptedCount",
          "numericEquals": 5
        }
      ]
    },
    {
      "id": "s3-lead-count",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT COUNT() FROM Lead WHERE Id IN (SELECT LeadId FROM CampaignMember WHERE CampaignId='{{steps.s0-create-campaign.response.body.id}}')",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 240000,
        "intervalMs": 10000
      },
      "onTimeout": "fail",
      "assertions": [
        {
          "path": "response.body.totalSize",
          "numericEquals": 5
        }
      ]
    },
    {
      "id": "s4-campaignmember-count",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT COUNT() FROM CampaignMember WHERE CampaignId='{{steps.s0-create-campaign.response.body.id}}'",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 120000,
        "intervalMs": 10000
      },
      "onTimeout": "fail",
      "assertions": [
        {
          "path": "response.body.totalSize",
          "numericEquals": 5
        }
      ]
    }
  ]
}
