{
  "id": 21632822,
  "title": "A two-row test that catches a broken CSV diff",
  "url": "https://urgent.news/2026/11/24/a-two-row-test-that-catches-a-broken-csv-diff",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-24T17:30:08.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/ltfs_d1fc136d398420bb0ebe/a-two-row-test-that-catches-a-broken-csv-diff-5b0l"
  },
  "original_language": "en",
  "account": "A CSV comparison test fails when the same stock keeping unit (SKU) appears in both warehouses. This issue is demonstrated in a small regression example from the TallyRill warehouse scenario. The test uses two snapshots, each containing two records for the SKU CL-101, with prices and stock levels changing. The issue occurs when pairing by row number, as North's 18 units are paired with South's 12 units. Looking up only the SKU loses track of the position if the map keeps just one value per key. The actual change at North is from 18 units to 15, and its price increased from 34.00 to 36.00.\n\nTo verify the comparison, an executable test is defined using a function called `by_position`. This function creates a dictionary where the keys are tuples containing the SKU and depot, and the values are tuples of stock and price. The function checks for missing or duplicate keys and raises an error if any are found.\n\nBefore and after the comparison, the keys and values in the dictionary are compared to ensure they match. Any differences are stored in a `changes` dictionary, which should contain only the changed records.\n\nIn the full eight-row example, the key sets differ between the old and new snapshots. Keys present only in the old snapshot represent removals, while keys present only in the new snapshot represent additions. Comparing field values only in the intersection of the two snapshots preserves the text when leading zeros belong to identifiers. The test checks the number of records and fields that were changed, with North being responsible for two of the changes. One record was added, one removed, and four stayed the same.\n\nAn additional regression test is suggested, which involves reordering both snapshots without changing any fields. In this case, the edit count should be zero. Another test involves duplicating a full key to verify that the comparison stops rather than silently discarding one record.",
  "summary": "A CSV comparison can pass every test until the same SKU appears at a second warehouse. This is the smallest regression case from the TallyRill warehouse example that exposes the problem. It takes two snapshots, two records per snapshot and one deliberately reversed sort order. The false six-unit drop CL-101 has 18 units at North and 12 at South. In the second snapshot South comes first. Pairing…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}