{
  "ursId": "URS-049",
  "title": "Update inventory from Uniphar ASN on delivered status",
  "timestamp": "2026-04-23T03:43:11.182Z",
  "durationMs": 101791,
  "config": {
    "inboxUrl": "http://localhost:64871",
    "dbHost": "localhost",
    "dbPort": 64872,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Pre-ASN inventory",
      "status": "pass",
      "description": "Step 1: Pre-ASN inventory",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-04-23T03-43-11-181Z/screenshots/step-01-inventory-before-asn.png"
      ],
      "explanation": "Documents the inventory state at BOSS-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-04-23T03:43:21.943Z",
      "finishedAt": "2026-04-23T03:43:21.943Z"
    },
    {
      "name": "Step 3: Intake email list (ASN received)",
      "status": "pass",
      "description": "Step 3: Intake email list (ASN received)",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-04-23T03-43-11-181Z/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-04-23T03:43:29.721Z",
      "finishedAt": "2026-04-23T03:43:29.721Z"
    },
    {
      "name": "Step 4: Intake email detail (parsed ASN body)",
      "status": "pass",
      "description": "Step 4: Intake email detail (parsed ASN body)",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-04-23T03-43-11-181Z/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-04-23T03:43:33.457Z",
      "finishedAt": "2026-04-23T03:43:33.457Z"
    },
    {
      "name": "Step 5: Import job log (ASN parsed)",
      "status": "pass",
      "description": "Step 5: Import job log (ASN parsed)",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-04-23T03-43-11-181Z/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-04-23T03:43:36.583Z",
      "finishedAt": "2026-04-23T03:43:36.583Z"
    },
    {
      "name": "Step 6: Shipping package detail (pre-delivery)",
      "status": "pass",
      "description": "Step 6: Shipping package detail (pre-delivery)",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-04-23T03-43-11-181Z/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 ZuriMED BOSS-001 destination location with the correct tracking number and three shipping_package_items matching the ASN quantities.",
      "startedAt": "2026-04-23T03:43:39.740Z",
      "finishedAt": "2026-04-23T03:43:39.740Z"
    },
    {
      "name": "Step 8: Shipping package detail (delivered)",
      "status": "pass",
      "description": "Step 8: Shipping package detail (delivered)",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-04-23T03-43-11-181Z/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 BOSS-001.",
      "startedAt": "2026-04-23T03:44:46.372Z",
      "finishedAt": "2026-04-23T03:44:46.372Z"
    },
    {
      "name": "Step 9: Inventory after ASN delivery (lots materialized)",
      "status": "pass",
      "description": "Step 9: Inventory after ASN delivery (lots materialized)",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-04-23T03-43-11-181Z/screenshots/step-09-inventory-after-delivery.png"
      ],
      "explanation": "Documents the inventory state at BOSS-001 after the delivery event. The three ASN lots (SP019N1A, FL516SNA, ZM2025MR) 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-04-23T03:44:49.986Z",
      "finishedAt": "2026-04-23T03:44:49.986Z"
    }
  ],
  "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": "019db86f-72c3-7098-875f-d279e302e02b",
          "from": "notifications@secure-wms.com",
          "to": "zurimed.asn@agent.getdeviceflow.com",
          "subject": "requested transaction notification",
          "matched_rule_id": "01950049-0049-7049-8049-000000000002",
          "received_at": "2026-04-23T03:43:24.877Z"
        }
      ]
    },
    {
      "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": "019db86f-72d0-7aed-9965-990a53b4df5b",
          "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 BOSS-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": "019db86f-72ff-7c7b-8ad8-9baeabb256b6",
          "tracking_number": "391915791211",
          "carrier": "fedex",
          "destination_location_id": "d0b29b2c-cef4-41b4-86d6-32efb93f92e7"
        }
      ]
    },
    {
      "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": "019db86f-7303-704c-93d3-75b218d5a36f",
          "quantity": 3,
          "info": {
            "lot": "LOT-URS049-SP-A1",
            "sku": "SP019N1A"
          }
        },
        {
          "id": "019db86f-7303-704c-93d3-75b3eddad9d3",
          "quantity": 5,
          "info": {
            "lot": "LOT-URS049-FL-B2",
            "sku": "FL516SNA"
          }
        },
        {
          "id": "019db86f-7303-704c-93d3-75b4f880420b",
          "quantity": 2,
          "info": {
            "lot": "LOT-URS049-MR-C3",
            "sku": "ZM2025MR"
          }
        }
      ]
    },
    {
      "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": "019db86f-72ff-7c7b-8ad8-9baeabb256b6",
          "status": "delivered",
          "delivered_at": "2026-04-23T03:43:42.546Z",
          "destination_location_id": "d0b29b2c-cef4-41b4-86d6-32efb93f92e7"
        }
      ]
    },
    {
      "name": "inventory_items materialized for each ASN line",
      "assertion": "One inventory_items row per ASN (productId, lot) at BOSS-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": "019db870-a4ca-7ecd-a77a-ab2e31540896",
          "product_id": "01989ca2-6a54-7834-8376-06a0251bacd8",
          "lot": "LOT-URS049-SP-A1",
          "quantity_ready": 3,
          "real_world_location_id": "d0b29b2c-cef4-41b4-86d6-32efb93f92e7"
        },
        {
          "id": "019db870-a4ca-7ecd-a77a-ab2f15776a03",
          "product_id": "01989ca1-f2f8-7ab7-8269-7179342797cc",
          "lot": "LOT-URS049-FL-B2",
          "quantity_ready": 5,
          "real_world_location_id": "d0b29b2c-cef4-41b4-86d6-32efb93f92e7"
        },
        {
          "id": "019db870-a4ca-7ecd-a77a-ab30d34af581",
          "product_id": "01984270-64c1-76da-aa82-eaf3f0a8326b",
          "lot": "LOT-URS049-MR-C3",
          "quantity_ready": 2,
          "real_world_location_id": "d0b29b2c-cef4-41b4-86d6-32efb93f92e7"
        }
      ]
    },
    {
      "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": "019db870-a4d5-7819-9faa-8cb6673f14f4",
          "item_id": "019db870-a4ca-7ecd-a77a-ab2e31540896",
          "quantity": 3,
          "status": "ready",
          "info": {
            "action": "added",
            "reason": "auto_added_package",
            "packageId": "019db86f-72ff-7c7b-8ad8-9baeabb256b6"
          }
        },
        {
          "id": "019db870-a4d5-7819-9faa-8cb73a2ae320",
          "item_id": "019db870-a4ca-7ecd-a77a-ab2f15776a03",
          "quantity": 5,
          "status": "ready",
          "info": {
            "action": "added",
            "reason": "auto_added_package",
            "packageId": "019db86f-72ff-7c7b-8ad8-9baeabb256b6"
          }
        },
        {
          "id": "019db870-a4d5-7819-9faa-8cb84f198f34",
          "item_id": "019db870-a4ca-7ecd-a77a-ab30d34af581",
          "quantity": 2,
          "status": "ready",
          "info": {
            "action": "added",
            "reason": "auto_added_package",
            "packageId": "019db86f-72ff-7c7b-8ad8-9baeabb256b6"
          }
        }
      ]
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/Users/jason/projects/casecohort/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-04-23T03-43-11-181Z",
  "auditStartTime": "2026-04-23T03:43:09.253Z",
  "auditEventEvidence": [
    {
      "createdAt": "2026-04-23T03:43:18.469Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@zurimed.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@zurimed.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:44:43.188Z",
      "eventType": "decision",
      "action": "enable_team_tracked_inventory_routing",
      "userEmail": null,
      "userId": null,
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019db86f-72ff-7c7b-8ad8-9baeabb256b6",
      "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": [
    "/Users/jason/projects/casecohort/code/validation_test_results/urs-049-uniphar-asn-parse-and-update-inventory/2026-04-23T03-43-11-181Z/videos/step-01-urs-049-uniphar-asn.webm"
  ]
}