fix top priority tests

This commit is contained in:
2026-07-15 15:48:02 -04:00
parent 99b919b5da
commit b5dd611f82
4 changed files with 101 additions and 22 deletions
+37 -7
View File
@@ -4,7 +4,7 @@ import os
from dataclasses import dataclass
from datetime import date, timedelta
from test_window import get_shift_sequence_with_capacity, get_shift_capacity_for_date, is_off_day, next_window_start_date
from test_bundle import Test, TestBundle, build_test_bundles, bundle_pair_lookup
from test_bundle import BUNDLE_PRIORITY_TOP, Test, TestBundle, build_test_bundles, bundle_pair_lookup
DUT = (os.getenv("DUT") or "DUT").strip()
REF = (os.getenv("REF") or "REF").strip()
@@ -84,17 +84,47 @@ class Scheduler:
window_index = 0
cursor_date = self.start_date
# Sort TC keys by bundle count (largest first); tie-break by TC name.
# Process TCs that include top-priority bundles first.
# REF top-priority TCs come before DUT top-priority TCs so that
# entering tests in the REF top-priority field always claims tonight's
# first window for REF.
def tc_sort_key(item: tuple[str | None, list[TestBundle]]) -> tuple[int, int, int, str]:
tc, tc_bundles = item
has_ref_top = any(bundle.priority == BUNDLE_PRIORITY_TOP and bundle.device == REF for bundle in tc_bundles)
has_dut_top = any(bundle.priority == BUNDLE_PRIORITY_TOP and bundle.device == DUT for bundle in tc_bundles)
min_priority = min((bundle.priority for bundle in tc_bundles), default=BUNDLE_PRIORITY_TOP + 99)
tc_name = tc if tc is not None else "~"
if has_dut_top:
tier = 0 # DUT top-priority TCs first (wins when both exist)
elif has_ref_top:
tier = 1 # REF-only top-priority TCs second
else:
tier = 2 # All other TCs
return (tier, min_priority, -len(tc_bundles), tc_name)
sorted_tc_items = sorted(
[(tc, bundles_by_tc[tc]) for tc in bundles_by_tc if tc is not None],
key=lambda x: (-len(x[1]), x[0]),
[(tc, bundles_by_tc[tc]) for tc in bundles_by_tc],
key=tc_sort_key,
)
if None in bundles_by_tc:
sorted_tc_items.append((None, bundles_by_tc[None]))
for tc, tc_bundles in sorted_tc_items:
window_device = DUT
tc_has_ref_top_priority = any(
bundle.device == REF and bundle.priority == BUNDLE_PRIORITY_TOP
for bundle in tc_bundles
)
tc_has_dut_top_priority = any(
bundle.device == DUT and bundle.priority == BUNDLE_PRIORITY_TOP
for bundle in tc_bundles
)
if tc_has_ref_top_priority:
window_device = REF
elif tc_has_dut_top_priority:
window_device = DUT
else:
window_device = DUT
dut_unscheduled = [b for b in tc_bundles if b.device == DUT]
ref_unscheduled = [b for b in tc_bundles if b.device == REF]