{
  "ursId": "URS-049",
  "title": "Update inventory from Uniphar ASN on delivered status",
  "timestamp": "2026-08-03T23:04:11.296Z",
  "durationMs": 89107,
  "config": {
    "inboxUrl": "http://localhost:35841",
    "dbHost": "localhost",
    "dbPort": 37163,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Pre-ASN inventory",
      "status": "pass",
      "description": "Step 1: Pre-ASN inventory",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-08-03T23-04-11-296Z/screenshots/step-01-inventory-before-asn.png"
      ],
      "explanation": "Documents the inventory state at ROSS-001 before any ASN is processed. This baseline proves that inventory increases seen after Step 9 are caused by the ASN delivery, not by pre-existing stock. The full end-to-end screencast video (attached below) covers all steps from pre-ASN baseline through delivery confirmation and inventory materialization.",
      "startedAt": "2026-08-03T23:04:21.002Z",
      "finishedAt": "2026-08-03T23:04:21.002Z"
    },
    {
      "name": "Step 3: Intake email list (ASN received)",
      "status": "pass",
      "description": "Step 3: Intake email list (ASN received)",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-08-03T23-04-11-296Z/screenshots/step-03-intake-email-list.png"
      ],
      "explanation": "Confirms the Uniphar/secure-wms.com ASN email appears in the email intake log (/settings/email_intake) with a \"processed\" status. The email arrived via the same SES → Minio → Restate Import.processMail pipeline used in production — only the SES/SQS hops are replaced by a direct Minio upload in the test environment.",
      "startedAt": "2026-08-03T23:04:26.573Z",
      "finishedAt": "2026-08-03T23:04:26.573Z"
    },
    {
      "name": "Step 4: Intake email detail (parsed ASN body)",
      "status": "pass",
      "description": "Step 4: Intake email detail (parsed ASN body)",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-08-03T23-04-11-296Z/screenshots/step-04-intake-email-detail.png"
      ],
      "explanation": "Drills into the ASN email detail page, showing the sender (notifications@secure-wms.com), subject, HTML table body, and the shipping_package + import_job entities the pipeline produced. Proves the parser correctly extracted account code, carrier, tracking number, and all three SKU/lot/quantity rows from the secure-wms.com HTML table format.",
      "startedAt": "2026-08-03T23:04:29.403Z",
      "finishedAt": "2026-08-03T23:04:29.403Z"
    },
    {
      "name": "Step 5: Import job log (ASN parsed)",
      "status": "pass",
      "description": "Step 5: Import job log (ASN parsed)",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-08-03T23-04-11-296Z/screenshots/step-05-import-job-log.png"
      ],
      "explanation": "Shows the shipping-notice import job log with the parsed SKU, LOT, and quantity rows from the ASN. Confirms the text-extraction import_config matched the URS-049 email rule and the import job completed with status=complete, packagesCreated=1, itemsAdded=3.",
      "startedAt": "2026-08-03T23:04:31.962Z",
      "finishedAt": "2026-08-03T23:04:31.962Z"
    },
    {
      "name": "Step 6: Shipping package detail (pre-delivery)",
      "status": "pass",
      "description": "Step 6: Shipping package detail (pre-delivery)",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-08-03T23-04-11-296Z/screenshots/step-06-shipping-package-pre-delivery.png"
      ],
      "explanation": "Captures the shipping_packages detail page before the delivery webhook fires. Confirms the package was routed to the Vantis ROSS-001 destination location with the correct tracking number and three shipping_package_items matching the ASN quantities.",
      "startedAt": "2026-08-03T23:04:34.563Z",
      "finishedAt": "2026-08-03T23:04:34.563Z"
    },
    {
      "name": "Step 8: Shipping package detail (delivered)",
      "status": "pass",
      "description": "Step 8: Shipping package detail (delivered)",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-08-03T23-04-11-296Z/screenshots/step-08-shipping-package-delivered.png"
      ],
      "explanation": "After the PackageTracker.mockUpdate webhook sets status=delivered, the package detail page is re-captured to show the updated status. This is the trigger that causes the auto-add-inventory hook to fire, materializing inventory_items at ROSS-001.",
      "startedAt": "2026-08-03T23:05:36.260Z",
      "finishedAt": "2026-08-03T23:05:36.260Z"
    },
    {
      "name": "Step 9: Inventory after ASN delivery (lots materialized)",
      "status": "pass",
      "description": "Step 9: Inventory after ASN delivery (lots materialized)",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-08-03T23-04-11-296Z/screenshots/step-09-inventory-after-delivery.png"
      ],
      "explanation": "Documents the inventory state at ROSS-001 after the delivery event. The three ASN lots (NP019N1A, LL516SNA, VM2025MR) now appear with quantities matching the ASN exactly, proving the requirement: \"The system shall update inventory based on ASN information, upon receipt of delivered status from Uniphar.\"",
      "startedAt": "2026-08-03T23:05:38.755Z",
      "finishedAt": "2026-08-03T23:05:38.755Z"
    }
  ],
  "dbValidations": [
    {
      "name": "intake_emails row exists for the Uniphar ASN",
      "assertion": "intake_emails from notifications@secure-wms.com matched the URS-049 rule and was stored.",
      "query": "\n    SELECT id, \"from\", \"to\", subject, matched_rule_id, received_at\n      FROM intake_emails\n     WHERE matched_rule_id = $1 AND received_at >= $2\n     ORDER BY received_at DESC\n     LIMIT 1",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9de-fed3-7c2a-b5af-3dd8ad73bdcf",
          "from": "notifications@secure-wms.com",
          "to": "vantis.asn@agent.getdeviceflow.com",
          "subject": "requested transaction notification",
          "matched_rule_id": "01950049-0049-7049-8049-000000000002",
          "received_at": "2026-08-03T23:04:22.536Z"
        }
      ]
    },
    {
      "name": "import_jobs row completed for the Uniphar ASN",
      "assertion": "import_jobs.status=complete with packagesCreated=1 and itemsAdded=3.",
      "query": "\n    SELECT id, status, info\n      FROM import_jobs\n     WHERE organization_id = $1 AND import_config_id = $2 AND created_at >= $3\n     ORDER BY created_at DESC\n     LIMIT 1",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9de-ff12-72d4-bfa6-4328f6c5c8f2",
          "status": "complete",
          "info": {
            "itemsAdded": 3,
            "missingContacts": [],
            "packagesCreated": 1,
            "missingLocations": [],
            "packagesReconciled": 0,
            "backorderedItemsAdded": 0,
            "unmatchedOrderNumbers": [
              "URS049-PKG-A"
            ],
            "fulfillmentOrdersLinked": 0
          }
        }
      ]
    },
    {
      "name": "shipping_packages row created for the Uniphar ASN",
      "assertion": "A shipping_packages row with the ASN tracking number was created, routed to ROSS-001.",
      "query": "\n    SELECT id, tracking_number, carrier, destination_location_id\n      FROM shipping_packages\n     WHERE organization_id = $1 AND created_at >= $2 AND tracking_number = $3",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9de-ff61-784d-b215-2bfbf76243cf",
          "tracking_number": "391798251377",
          "carrier": "fedex",
          "destination_location_id": "148e78e5-1f34-448a-90e5-f600f77749c7"
        }
      ]
    },
    {
      "name": "shipping_package_items has 3 rows with correct quantities",
      "assertion": "Each ASN SKU line produced a shipping_package_items row with the expected quantity.",
      "query": "\n    SELECT spi.id, spi.quantity, spi.info\n      FROM shipping_package_items spi\n      JOIN shipping_packages sp ON sp.id = spi.package_id\n     WHERE sp.organization_id = $1 AND sp.created_at >= $2\n       AND sp.tracking_number = $3\n     ORDER BY spi.source_file_row ASC NULLS LAST, spi.id ASC",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9de-ff67-7aa8-b1b9-f0fb433cc737",
          "quantity": 3,
          "info": {
            "lot": "LOT-URS049-SP-A1",
            "sku": "NP019N1A"
          }
        },
        {
          "id": "019fc9de-ff67-7aa8-b1b9-f0fc706e6c7d",
          "quantity": 5,
          "info": {
            "lot": "LOT-URS049-FL-B2",
            "sku": "LL516SNA"
          }
        },
        {
          "id": "019fc9de-ff67-7aa8-b1b9-f0fdb47deaee",
          "quantity": 2,
          "info": {
            "lot": "LOT-URS049-MR-C3",
            "sku": "VM2025MR"
          }
        }
      ]
    },
    {
      "name": "shipping_package was delivered",
      "assertion": "shipping_packages.status=delivered after PackageTracker.mockUpdate.",
      "query": "\n    SELECT id, status, delivered_at, destination_location_id\n      FROM shipping_packages\n     WHERE organization_id = $1 AND created_at >= $2 AND tracking_number = $3",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9de-ff61-784d-b215-2bfbf76243cf",
          "status": "delivered",
          "delivered_at": "2026-08-03T23:04:35.870Z",
          "destination_location_id": "148e78e5-1f34-448a-90e5-f600f77749c7"
        }
      ]
    },
    {
      "name": "inventory_items materialized for each ASN line",
      "assertion": "One inventory_items row per ASN (productId, lot) at ROSS-001 with quantity_ready matching the ASN.",
      "query": "\n    SELECT ii.id, ii.product_id, ii.lot, ii.quantity_ready, ii.real_world_location_id\n      FROM inventory_items ii\n     WHERE ii.organization_id = $1\n       AND ii.product_id = ANY($2)\n       AND NOT (ii.id = ANY($3))",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9e0-1481-7cbd-80f5-efc0183c0110",
          "product_id": "01989ca2-6a54-7834-8376-06a0251bacd8",
          "lot": "LOT-URS049-SP-A1",
          "quantity_ready": 3,
          "real_world_location_id": "148e78e5-1f34-448a-90e5-f600f77749c7"
        },
        {
          "id": "019fc9e0-1481-7cbd-80f5-efc113dc2113",
          "product_id": "01989ca1-f2f8-7ab7-8269-7179342797cc",
          "lot": "LOT-URS049-FL-B2",
          "quantity_ready": 5,
          "real_world_location_id": "148e78e5-1f34-448a-90e5-f600f77749c7"
        },
        {
          "id": "019fc9e0-1481-7cbd-80f5-efc28882fd01",
          "product_id": "01984270-64c1-76da-aa82-eaf3f0a8326b",
          "lot": "LOT-URS049-MR-C3",
          "quantity_ready": 2,
          "real_world_location_id": "148e78e5-1f34-448a-90e5-f600f77749c7"
        }
      ]
    },
    {
      "name": "inventory_history rows recorded for the ASN delivery",
      "assertion": "3 inventory_history rows written during the run window for the ASN SKUs.",
      "query": "\n    SELECT ih.id, ih.item_id, ih.quantity, ih.status, ih.info\n      FROM inventory_history ih\n      JOIN inventory_items ii ON ii.id = ih.item_id\n     WHERE ih.organization_id = $1\n       AND ih.created_at >= $2\n       AND ii.product_id = ANY($3)",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9e0-148b-7006-8e5d-19027d377da9",
          "item_id": "019fc9e0-1481-7cbd-80f5-efc0183c0110",
          "quantity": 3,
          "status": "ready",
          "info": {
            "action": "added",
            "reason": "auto_added_package",
            "packageId": "019fc9de-ff61-784d-b215-2bfbf76243cf"
          }
        },
        {
          "id": "019fc9e0-148b-7006-8e5d-1903013ce17d",
          "item_id": "019fc9e0-1481-7cbd-80f5-efc113dc2113",
          "quantity": 5,
          "status": "ready",
          "info": {
            "action": "added",
            "reason": "auto_added_package",
            "packageId": "019fc9de-ff61-784d-b215-2bfbf76243cf"
          }
        },
        {
          "id": "019fc9e0-148d-7cd1-9669-d3cc771c84fc",
          "item_id": "019fc9e0-1481-7cbd-80f5-efc28882fd01",
          "quantity": 2,
          "status": "ready",
          "info": {
            "action": "added",
            "reason": "auto_added_package",
            "packageId": "019fc9de-ff61-784d-b215-2bfbf76243cf"
          }
        }
      ]
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-08-03T23-04-11-296Z",
  "auditStartTime": "2026-08-03T23:04:09.439Z",
  "auditEventEvidence": [
    {
      "createdAt": "2026-08-03T23:04:10.313Z",
      "eventType": "checklist",
      "action": "checklists.create",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019fc9de-cf4f-709a-aa55-8e619fe1f85b",
      "secondaryObjectId": null,
      "payload": {
        "title": "Lot expiration review (1 location need attention)",
        "source": {
          "type": "lot_expiration",
          "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
        }
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:04:10.387Z",
      "eventType": "decision",
      "action": "ensure_lot_expiration_checklist",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "secondaryObjectId": null,
      "payload": {
        "reason": "created_1_reopened_0_already_open_1",
        "performed": true,
        "entityType": "organization"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:04:17.894Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-08-03T23:04:22.496Z",
      "eventType": "decision",
      "action": "imports.mail_intake.rule_matched_hardcoded",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01950049-0049-7049-8049-000000000002",
      "secondaryObjectId": "019fc9de-fed3-7c2a-b5af-3dd8ad73bdcf",
      "payload": {
        "reason": "matched_hardcoded_intake_rule",
        "performed": true,
        "entityType": "intake_email_rule"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:04:22.512Z",
      "eventType": "decision",
      "action": "imports.mail_intake.rule_matched_flexible",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01950049-0049-7049-8049-000000000002",
      "secondaryObjectId": "019fc9de-fed3-7c2a-b5af-3dd8ad73bdcf",
      "payload": {
        "reason": "matched_hardcoded_rule",
        "performed": false,
        "entityType": "intake_email_rule"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:04:22.514Z",
      "eventType": "decision",
      "action": "imports.mail_intake.no_rule_match",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01950049-0049-7049-8049-000000000002",
      "secondaryObjectId": "019fc9de-fed3-7c2a-b5af-3dd8ad73bdcf",
      "payload": {
        "reason": "actionable_rule_matched",
        "performed": false,
        "entityType": "intake_email_rule"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:05:33.511Z",
      "eventType": "decision",
      "action": "enable_team_tracked_inventory_routing",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019fc9de-ff61-784d-b215-2bfbf76243cf",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Package not linked to direct or dropship order",
        "performed": true,
        "entityType": "shipping_package"
      },
      "route": null,
      "traceId": null
    }
  ],
  "auditQuery": "SELECT\n    ae.created_at,\n    ae.event_type,\n    ae.action,\n    ae.user_id,\n    u.email AS user_email,\n    ae.organization_id,\n    o.name AS organization_name,\n    ae.object_id,\n    ae.secondary_object_id,\n    ae.payload,\n    ae.route,\n    ae.trace_id\n  FROM audit_events ae\n  LEFT JOIN users u ON u.id = ae.user_id\n  LEFT JOIN organizations o ON o.id = ae.organization_id\n  WHERE ae.created_at >= $1\n    AND ae.organization_id = ANY($2::uuid[])\n  ORDER BY ae.created_at ASC",
  "auditAssertions": [],
  "emailAssertions": [],
  "videoPaths": [
    "/home/runner/_work/code/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-08-03T23-04-11-296Z/videos/step-01-urs-049-uniphar-asn.webm"
  ]
}