Fix cq cfg sorting

Seems to have broken at some point.

Also adds an assert, which should help it not break in the future.

Bug: 888810
Change-Id: Ie8160ceee170dfb75d71f46d0e4f1a10eed78b6f
Reviewed-on: https://chromium-review.googlesource.com/c/1428562
Commit-Queue: Stephen Martinis <martiniss@chromium.org>
Commit-Queue: John Budorick <jbudorick@chromium.org>
Auto-Submit: Stephen Martinis <martiniss@chromium.org>
Reviewed-by: John Budorick <jbudorick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625057}
diff --git a/docs/infra/cq_builders.md b/docs/infra/cq_builders.md
index 99c7c77..c845c62 100644
--- a/docs/infra/cq_builders.md
+++ b/docs/infra/cq_builders.md
@@ -44,10 +44,10 @@
 
 * [ios-simulator](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/ios-simulator) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+ios-simulator)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+ios-simulator))
 
-* [linux-chromeos-rel](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/linux-chromeos-rel) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+linux-chromeos-rel)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+linux-chromeos-rel))
-
 * [linux-chromeos-compile-dbg](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/linux-chromeos-compile-dbg) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+linux-chromeos-compile-dbg)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+linux-chromeos-compile-dbg))
 
+* [linux-chromeos-rel](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/linux-chromeos-rel) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+linux-chromeos-rel)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+linux-chromeos-rel))
+
 * [linux-jumbo-rel](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/linux-jumbo-rel) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+linux-jumbo-rel)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+linux-jumbo-rel))
 
 * [linux-libfuzzer-asan-rel](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/linux-libfuzzer-asan-rel) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+linux-libfuzzer-asan-rel)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+linux-libfuzzer-asan-rel))
@@ -68,14 +68,14 @@
 
 * [mac_chromium_rel_ng](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/mac_chromium_rel_ng) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+mac_chromium_rel_ng)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+mac_chromium_rel_ng))
 
+* [win-libfuzzer-asan-rel](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/win-libfuzzer-asan-rel) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+win-libfuzzer-asan-rel)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+win-libfuzzer-asan-rel))
+
 * [win10_chromium_x64_rel_ng](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/win10_chromium_x64_rel_ng) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+win10_chromium_x64_rel_ng)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+win10_chromium_x64_rel_ng))
 
 * [win7_chromium_rel_ng](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/win7_chromium_rel_ng) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+win7_chromium_rel_ng)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+win7_chromium_rel_ng))
 
 * [win_chromium_compile_dbg_ng](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/win_chromium_compile_dbg_ng) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+win_chromium_compile_dbg_ng)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+win_chromium_compile_dbg_ng))
 
-* [win-libfuzzer-asan-rel](https://ci.chromium.org/p/chromium/builders/luci.chromium.try/win-libfuzzer-asan-rel) ([`cq.cfg` entry](https://cs.chromium.org/search/?q=package:%5Echromium$+file:cq.cfg+win-libfuzzer-asan-rel)) ([matching builders](https://cs.chromium.org/search/?q=file:trybots.py+win-libfuzzer-asan-rel))
-
 
 ## Optional builders
 
diff --git a/infra/config/branch/cq.cfg b/infra/config/branch/cq.cfg
index 0f5f821..3399856 100644
--- a/infra/config/branch/cq.cfg
+++ b/infra/config/branch/cq.cfg
@@ -76,8 +76,8 @@
       builders { name: "fuchsia_arm64" }
       builders { name: "fuchsia_x64" }
       builders { name: "ios-simulator" }
-      builders { name: "linux-chromeos-rel" }
       builders { name: "linux-chromeos-compile-dbg" }
+      builders { name: "linux-chromeos-rel" }
       builders { name: "linux-jumbo-rel" }
       builders { name: "linux-libfuzzer-asan-rel" }
       builders { name: "linux-ozone-rel" }
@@ -88,10 +88,10 @@
       builders { name: "linux_chromium_tsan_rel_ng" }
       builders { name: "mac_chromium_compile_dbg_ng" }
       builders { name: "mac_chromium_rel_ng" }
+      builders { name: "win-libfuzzer-asan-rel" }
       builders { name: "win10_chromium_x64_rel_ng" }
       builders { name: "win7_chromium_rel_ng"}
       builders { name: "win_chromium_compile_dbg_ng" }
-      builders { name: "win-libfuzzer-asan-rel" }
 
       ######################
       # Optional builders. #
diff --git a/infra/config/branch/cq_cfg_presubmit.py b/infra/config/branch/cq_cfg_presubmit.py
index 3f4f7e7..99f055e 100755
--- a/infra/config/branch/cq_cfg_presubmit.py
+++ b/infra/config/branch/cq_cfg_presubmit.py
@@ -205,7 +205,7 @@
     for bucket in (
         self._value['verifiers'][0]['try_job'][0]['buckets']):
       for b in bucket['builders']:
-        if pred and not pred(bucket, b):
+        if pred and not pred(bucket['name'][0], b):
           continue
         items.append(b)
     return BuilderList(items)
@@ -331,6 +331,8 @@
   # Only force sorting on luci.chromium.try builders. Others should go away soon
   # anyways...
   bl = cfg.builder_list(lambda bucket, builder: bucket == 'luci.chromium.try')
+  assert len(bl.builders) > 0, (
+      'Builders in \'luci.chromium.try\' bucket are missing somehow...')
   names = [b['name'][0] for b in bl.builders]
   bl.sort() # Changes the bl, so the next line is sorted.
   sorted_names = [b['name'][0] for b in bl.builders]