{
  "name": "RomeoApps n8n Workflow Reliability Preflight",
  "id": "FvxmP6i1tpd6DYdj",
  "nodes": [
    {
      "parameters": {},
      "id": "0a7fe868-05f1-48e0-83e0-d8c0c86773ef",
      "name": "Run Preflight",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -660,
        120
      ]
    },
    {
      "parameters": {
        "jsCode": "return [\n  { json: { caseId: 'valid-primary-route', eventId: 'evt-001', route: 'primary', payload: { amount: 42 }, providerStatus: 200, expectedDecision: 'accepted_ready_for_human_approval' } },\n  { json: { caseId: 'valid-service-route', eventId: 'evt-002', route: 'service', payload: { amount: 84 }, providerStatus: 202, expectedDecision: 'accepted_ready_for_human_approval' } },\n  { json: { caseId: 'missing-event-id', route: 'primary', payload: { amount: 21 }, providerStatus: 200, expectedDecision: 'blocked_invalid_contract' } },\n  { json: { caseId: 'duplicate-event-id', eventId: 'evt-001', route: 'primary', payload: { amount: 42 }, providerStatus: 200, expectedDecision: 'blocked_duplicate' } },\n  { json: { caseId: 'retryable-provider-error', eventId: 'evt-003', route: 'service', payload: { amount: 63 }, providerStatus: 503, expectedDecision: 'retry_required' } }\n];"
      },
      "id": "26d50f5c-346c-4ac4-a132-741e5ad7298c",
      "name": "Create Synthetic Acceptance Fixtures",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -420,
        120
      ]
    },
    {
      "parameters": {
        "jsCode": "const seenEventIds = new Set();\n\nreturn $input.all().map((item) => {\n  const input = item.json ?? {};\n  let actualDecision;\n  let reason;\n  let retryAfterMs = null;\n\n  const hasContract = Boolean(\n    input.eventId\n    && input.route\n    && input.payload\n    && typeof input.payload === 'object'\n    && !Array.isArray(input.payload)\n  );\n\n  if (!hasContract) {\n    actualDecision = 'blocked_invalid_contract';\n    reason = 'required eventId, route, or payload is missing';\n  } else if (seenEventIds.has(input.eventId)) {\n    actualDecision = 'blocked_duplicate';\n    reason = 'eventId was already accepted in this execution';\n  } else {\n    seenEventIds.add(input.eventId);\n\n    if (input.providerStatus === 429 || input.providerStatus >= 500) {\n      actualDecision = 'retry_required';\n      reason = 'provider response is retryable';\n      retryAfterMs = 30000;\n    } else {\n      actualDecision = 'accepted_ready_for_human_approval';\n      reason = 'contract and provider response passed';\n    }\n  }\n\n  return {\n    json: {\n      ...input,\n      actualDecision,\n      reason,\n      retryAfterMs,\n      externalSideEffect: 'held_for_human_approval'\n    }\n  };\n});"
      },
      "id": "5b333d92-fbe1-478d-8254-24b4fbc71aef",
      "name": "Run Synthetic Target",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -130,
        120
      ]
    },
    {
      "parameters": {
        "jsCode": "return $input.all().map((item) => ({\n  json: {\n    ...item.json,\n    passed: item.json.actualDecision === item.json.expectedDecision\n  }\n}));"
      },
      "id": "81ac3e97-9224-4116-8274-d7d4fb8dc443",
      "name": "Evaluate Acceptance",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        140,
        120
      ]
    },
    {
      "parameters": {
        "jsCode": "const rows = $input.all().map((item) => item.json);\nconst failingCases = rows.filter((row) => !row.passed).map((row) => row.caseId);\n\nreturn [{\n  json: {\n    template: 'RomeoApps n8n Workflow Reliability Preflight',\n    templateVersion: '1.0.0',\n    status: failingCases.length === 0 ? 'pass' : 'fail',\n    total: rows.length,\n    passed: rows.length - failingCases.length,\n    failed: failingCases.length,\n    failingCases,\n    externalSideEffects: 'none',\n    nextStep: 'Replace only Run Synthetic Target with a sandboxed Execute Workflow or test integration, then keep the fixtures and acceptance evaluator.'\n  }\n}];"
      },
      "id": "fc352612-51ee-4a0c-9909-ef4cd20ba4c8",
      "name": "Summarize Preflight",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        410,
        120
      ]
    },
    {
      "parameters": {
        "content": "## Credential-free reliability preflight\nRun this workflow unchanged first. It should finish with `status: pass`, five passed cases, zero failed cases, and no external side effects.\n\nThe fixtures cover a valid primary route, a valid service route, a missing required identifier, a duplicate identifier, and a retryable provider failure.",
        "height": 250,
        "width": 760,
        "color": 5
      },
      "id": "79c4ed2f-ec49-4e24-ac21-59effd3b3c84",
      "name": "Preflight Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -680,
        -240
      ]
    },
    {
      "parameters": {
        "content": "## Adapt it safely\nReplace only **Run Synthetic Target** with your sandboxed Execute Workflow or test integration. Map its output to `actualDecision`, preserve the fixture `expectedDecision`, and keep real credentials and customer data out of the shared JSON. Connect production only after a human accepts the preflight evidence.",
        "height": 250,
        "width": 520,
        "color": 3
      },
      "id": "de984619-b762-4078-bb80-d8787430cac0",
      "name": "Safe Adaptation Boundary",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        120,
        -240
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Run Preflight": {
      "main": [
        [
          {
            "node": "Create Synthetic Acceptance Fixtures",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Synthetic Acceptance Fixtures": {
      "main": [
        [
          {
            "node": "Run Synthetic Target",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Synthetic Target": {
      "main": [
        [
          {
            "node": "Evaluate Acceptance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Evaluate Acceptance": {
      "main": [
        [
          {
            "node": "Summarize Preflight",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "96f650d9-1320-4ce7-9b84-95d96ff89390",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": []
}
