from pingcap_datapipelines.bq_load import sort_manifest_records def test_sort_manifest_records_uses_run_chronology_not_uri_order() -> None: records = [ ( "gs://bucket/manifests/source=x/run_date=2026-06-24/run_id=late/manifest.json", {"run_date": "2026-06-24", "run_id": "late"}, ), ( "gs://bucket/manifests/source=x/run_date=2026-06-23/run_id=b/manifest.json", {"run_date": "2026-06-23", "run_id": "b"}, ), ( "gs://bucket/manifests/source=x/run_date=2026-06-23/run_id=a/manifest.json", {"run_date": "2026-06-23", "run_id": "a"}, ), ] assert [uri for uri, _manifest in sort_manifest_records(records)] == [ "gs://bucket/manifests/source=x/run_date=2026-06-23/run_id=a/manifest.json", "gs://bucket/manifests/source=x/run_date=2026-06-23/run_id=b/manifest.json", "gs://bucket/manifests/source=x/run_date=2026-06-24/run_id=late/manifest.json", ]