{
  "id": "FLOW-012",
  "name": "Sparse PATCH on active Flow preserves Status and Metadata (invariant guard regression lock #2244)",
  "description": "Regression lock for PR #2244 writer-path invariant guards. Before the fix, a PATCH /tooling/sobjects/Flow/{id} that omitted the Status and Metadata fields could overwrite those columns with zero-values (''/'{}'): (a) Status would be blanked, leaving the FlowVersion in an undefined state and potentially breaking the ActiveVersionId pointer on the FlowDefinition; (b) Metadata.recordUpdates (the flow graph) would be wiped to '{}', silently destroying the canvas. PR #2244 introduced sparse-PATCH preservation so that absent fields are not written. This case tests scenario #6 from PR #2244: a description-only PATCH on the active Flow version must leave Status='Active' and Metadata intact. Test outline: (1) create FlowDefinition; (2) create Flow version with a non-trivial Metadata graph (Account AfterSave recordUpdate named 'MarkAccount'); (3) activate that version via POST /activate; (4) PATCH the same version with only Description in the body; (5) query the Flow record back and assert Status is still 'Active' and the Metadata field still contains 'MarkAccount'. Also asserts FlowDefinition.ActiveVersionId was not blanked. Tenant-agnostic: standard SObjects (Account), standard fields (Description), no __c business names.",
  "object": "Flow",
  "method": "PATCH",
  "endpoint": "/services/data/v63.0/tooling/sobjects/Flow/{flow012_version_id}",
  "setup": [
    {
      "type": "http",
      "name": "Create Flow version with non-trivial Metadata graph (Account AfterSave recordUpdate 'MarkAccount'); FlowDefinition is auto-created from MasterLabel by the Tooling API",
      "method": "POST",
      "endpoint": "/services/data/v63.0/tooling/sobjects/Flow",
      "payload": {
        "MasterLabel": "FLOW-012 SparsePatch Invariants",
        "ProcessType": "AutoLaunchedFlow",
        "Status": "Draft",
        "Metadata": {
          "apiVersion": "63.0",
          "label": "FLOW-012 SparsePatch Invariants",
          "description": "Test-only flow: Account AfterSave Create recordUpdate. Used to verify that a sparse Description-only PATCH does not wipe Status or Metadata. Teardown deletes this flow version.",
          "status": "Draft",
          "processType": "AutoLaunchedFlow",
          "start": {
            "locationX": 50,
            "locationY": 0,
            "object": "Account",
            "triggerType": "RecordAfterSave",
            "recordTriggerType": "Create",
            "connector": {
              "targetReference": "MarkAccount"
            }
          },
          "recordUpdates": [
            {
              "name": "MarkAccount",
              "label": "Mark Account",
              "locationX": 176,
              "locationY": 287,
              "object": "Account",
              "filterLogic": "and",
              "filters": [
                {
                  "field": "Id",
                  "operator": "EqualTo",
                  "processMetadataValues": [
                    {
                      "name": "implicit",
                      "value": {
                        "booleanValue": true
                      }
                    }
                  ],
                  "value": {
                    "elementReference": "$Record.Id"
                  }
                }
              ],
              "inputAssignments": [
                {
                  "field": "Description",
                  "value": {
                    "stringValue": "flow-canvas-marker"
                  }
                }
              ]
            }
          ]
        }
      },
      "expects": {
        "status_code": 201
      },
      "extract": {
        "flow012_version_id": "id"
      }
    },
    {
      "type": "http",
      "name": "Activate the Flow version so Status becomes 'Active' and FlowDefinition.ActiveVersionId is set",
      "method": "POST",
      "endpoint": "/services/data/v63.0/tooling/sobjects/Flow/{flow012_version_id}/activate",
      "expects": {
        "status_code": 204
      }
    }
  ],
  "payload": {
    "Description": "sparse-patch-trigger"
  },
  "expects": {
    "status_code": 204
  },
  "query_after": {
    "object": "Flow",
    "record_id": "{flow012_version_id}",
    "retry": 5,
    "delay_ms": 500,
    "assertions": [
      {
        "field": "Status",
        "operator": "eq",
        "value": "Active"
      },
      {
        "field": "Metadata",
        "operator": "contains",
        "value": "MarkAccount"
      }
    ]
  },
  "teardown": [
    {
      "method": "DELETE",
      "endpoint": "/services/data/v63.0/tooling/sobjects/Flow/{flow012_version_id}"
    }
  ],
  "priority": "P0",
  "bug_ref": "#2244",
  "scene": "flow"
}
