{
  "id": "f84643c446954376",
  "name": "n8n-check: Preserve row identities while metadata changes",
  "active": false,
  "nodes": [
    {
      "id": "1bf2a380-9b3b-42d0-abb5-40519c229e0e",
      "name": "n8n-check start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -400,
        0
      ],
      "parameters": {}
    },
    {
      "id": "rows",
      "name": "Rows",
      "position": [
        -200,
        0
      ],
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return JSON.parse(\"[{\\\"id\\\":\\\"row-A\\\",\\\"score\\\":0.9},{\\\"id\\\":\\\"row-B\\\",\\\"score\\\":0.8},{\\\"id\\\":\\\"distractor\\\",\\\"score\\\":0.2}]\").map(json => ({json}));"
      }
    },
    {
      "id": "select",
      "name": "Select rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return $input.all().filter(item => item.json.score >= 0.7).map(item => ({ json: { ...item.json, id: \"wrong-row\", processedAt: new Date().toISOString() } }));"
      }
    },
    {
      "id": "7da000fb-0408-4eee-8e6d-b25b4f809947",
      "name": "Check expected output",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -400,
        240
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Generated by n8n-check. Fixed fixture, one run per node; leave this branch last.\nfunction equalJson(a, b) {\n  if (Object.is(a, b)) return true;\n  if (!a || !b || typeof a !== 'object' || typeof b !== 'object') return false;\n  if (Array.isArray(a) !== Array.isArray(b)) return false;\n  const keys = Object.keys(a);\n  return keys.length === Object.keys(b).length &&\n    keys.every(key => Object.hasOwn(b, key) && equalJson(a[key], b[key]));\n}\nfunction checkItems(items, assertion) {\n  const label = `${assertion.node}: output ${assertion.output ?? 0}`;\n  if (assertion.count !== undefined && items.length !== assertion.count)\n    throw new Error(`n8n-check: ${label} expected ${assertion.count} items, got ${items.length}`);\n  if (assertion.equals !== undefined) {\n    const values = items.map((item, index) => {\n      if (!assertion.pluck) return item.json;\n      let value = item;\n      for (const key of assertion.pluck.split('.')) {\n        if (value === null || typeof value !== 'object' || !Object.hasOwn(value, key))\n          throw new Error(`n8n-check: ${label} item ${index} is missing ${assertion.pluck}`);\n        value = value[key];\n      }\n      return value;\n    });\n    if (!equalJson(values, assertion.equals))\n      throw new Error(`n8n-check: ${label}${assertion.pluck ? ` ${assertion.pluck}` : ''} differs. Expected ${JSON.stringify(assertion.equals)}; got ${JSON.stringify(values)}`);\n  }\n  return { node: assertion.node, output: assertion.output ?? 0, count: items.length, passed: true };\n}\nconst assertions = JSON.parse(\"[{\\\"node\\\":\\\"Select rows\\\",\\\"count\\\":2,\\\"pluck\\\":\\\"json.id\\\",\\\"equals\\\":[\\\"row-A\\\",\\\"row-B\\\"]}]\");\nconst checks = assertions.map(assertion => {\n  const node = $(assertion.node);\n  const items = node.isExecuted ? node.all(assertion.output ?? 0, 0) : [];\n  return checkItems(items, assertion);\n});\nreturn [{ json: { status: 'passed', checks } }];"
      }
    }
  ],
  "connections": {
    "Rows": {
      "main": [
        [
          {
            "node": "Select rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "n8n-check start": {
      "main": [
        [
          {
            "node": "Rows",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check expected output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "executionTimeout": 60,
    "saveExecutionProgress": true
  }
}
