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
+17 -1
View File
@@ -85,6 +85,8 @@ class CompileScheduleRequest(BaseModel):
daytime_testing_today: bool = False
dual_device_weekend_start_enabled: bool = False
dual_device_weekend_start_dates: list[str] = Field(default_factory=list)
top_priority_tests_dut: list[str] = Field(default_factory=list)
top_priority_tests_ref: list[str] = Field(default_factory=list)
top_priority_tests: list[str] = Field(default_factory=list)
lowest_priority_tests: list[str] = Field(default_factory=list)
@@ -394,9 +396,23 @@ def compile_schedule_endpoint(request: CompileScheduleRequest) -> dict[str, Any]
holiday_dates = db.list_holidays(DB_PATH)
top_priority_pairs: set[tuple[str, str]] = set()
for test_id in {item.strip() for item in request.top_priority_tests if item.strip()}:
dut_top_priority_ids = {item.strip() for item in request.top_priority_tests_dut if item.strip()}
ref_top_priority_ids = {item.strip() for item in request.top_priority_tests_ref if item.strip()}
# Backward compatibility: if only legacy top_priority_tests was sent,
# keep previous behavior by applying IDs to whichever device has that test.
if not dut_top_priority_ids and not ref_top_priority_ids and request.top_priority_tests:
for test_id in {item.strip() for item in request.top_priority_tests if item.strip()}:
if any(t.test_id == test_id and t.device == DUT for t in stored_tests):
dut_top_priority_ids.add(test_id)
if any(t.test_id == test_id and t.device == REF for t in stored_tests):
ref_top_priority_ids.add(test_id)
for test_id in dut_top_priority_ids:
if any(t.test_id == test_id and t.device == DUT for t in stored_tests):
top_priority_pairs.add((test_id, DUT))
for test_id in ref_top_priority_ids:
if any(t.test_id == test_id and t.device == REF for t in stored_tests):
top_priority_pairs.add((test_id, REF))
+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]