diff --git a/cli/administration/deploy/ci/selections.py b/cli/administration/deploy/ci/selections.py index aeef2dbe18..31099f129a 100644 --- a/cli/administration/deploy/ci/selections.py +++ b/cli/administration/deploy/ci/selections.py @@ -208,7 +208,11 @@ def unrun_selections(regular: list[dict[str, str]], deployed: set[str]) -> list[ ) -def resume_offset(regular: list[dict[str, str]], passed: set[str]) -> str: +def resume_offset( + regular: list[dict[str, str]], + passed: set[str], + leading: Iterable[selection.Pin] = (), +) -> str: """Where a retrigger should pick the regular line up again. The source run deployed a window of the ranking and stopped at its budget. @@ -222,16 +226,26 @@ def resume_offset(regular: list[dict[str, str]], passed: set[str]) -> str: resuming past it would drop every other combination of that row and everything the run never reached behind it. + A row the priority line claims is never the answer. ``regular`` is + discovered without the priority line (see the retrigger's ``_ranking``), so + it still holds rows the run will hand to that line instead + (:func:`cli.meta.ci.matrix.candidates`): a variant-less pin takes its whole + role, a pinned one takes those variants. Naming such a row would emit an + offset that resolves against nothing once the run applies the priority + line, and abort the discovery of every chunk. + Args: regular: the regular line of the retrigger's own discovery, in ranking order. passed: tokens the source run deployed green (:func:`passed_selections`). + leading: the retrigger's priority pins, whose rows leave the regular + line. Returns: the ``role#variant`` token to resume at, or ``''`` when the source run - got nothing of this line green -- then the retrigger starts at the - head, as it would without an offset. + got nothing skippable of this line green -- then the retrigger starts + at the head, as it would without an offset. The returned token names a place in the ranking, so it carries no axes. Membership is still tested on the full deploy token, because that is @@ -241,6 +255,9 @@ def resume_offset(regular: list[dict[str, str]], passed: set[str]) -> str: reproduce the source run's combination, and abort the discovery of every chunk in all the others. """ + pins = tuple(leading) + claimed_apps = {pin.app for pin in pins if not pin.variants} + claimed_rows = {(pin.app, variant) for pin in pins for variant in pin.variants} resume = "" for entry in regular: if row_selection(entry) not in passed: @@ -248,5 +265,8 @@ def resume_offset(regular: list[dict[str, str]], passed: set[str]) -> str: variants = tuple( int(part) for part in str(entry.get("variant", "")).split(",") if part ) - resume = selection.describe(selection.Pin(entry["apps"], variants)) + app = entry["apps"] + if app in claimed_apps or any((app, v) in claimed_rows for v in variants): + continue + resume = selection.describe(selection.Pin(app, variants)) return resume diff --git a/cli/administration/deploy/ci/trigger/__main__.py b/cli/administration/deploy/ci/trigger/__main__.py index a27451d4da..bf81b0ff6c 100644 --- a/cli/administration/deploy/ci/trigger/__main__.py +++ b/cli/administration/deploy/ci/trigger/__main__.py @@ -18,7 +18,7 @@ import sys from cli.administration.deploy.ci import gh, runs, selections from cli.meta.ci import matrix, query -from utils.github.variant import pools, tor +from utils.github.variant import pools, selection, tor _WORKFLOW = "entry-manual-steer.yml" _ALL = "__ALL__" @@ -211,7 +211,9 @@ def main(argv: list[str] | None = None) -> int: return 0 priority = " ".join(sorted(priority_entries)) config["offset"] = selections.resume_offset( - ranking, selections.passed_selections(source["jobs"]) + ranking, + selections.passed_selections(source["jobs"]), + selection.parse_list(priority), ) if config["offset"]: print(f"Regular line resumes at: {config['offset']}") diff --git a/tests/unit/python/cli/administration/deploy/ci/test_selections.py b/tests/unit/python/cli/administration/deploy/ci/test_selections.py index 3cb7e41013..235edd651c 100644 --- a/tests/unit/python/cli/administration/deploy/ci/test_selections.py +++ b/tests/unit/python/cli/administration/deploy/ci/test_selections.py @@ -84,6 +84,56 @@ class TestResumeOffset(unittest.TestCase): } self.assertEqual(selections.resume_offset(self._REGULAR, passed), "web-app-c#0") + _ALL_PASSED: ClassVar[set[str]] = { + "web-app-a#0@compose+clearnet" + _AXES, + "web-app-b#1@swarm+tor" + _AXES, + "web-app-c#0@host+clearnet" + _AXES, + } + + def test_a_role_the_priority_line_takes_whole_is_never_the_offset(self) -> None: + """A variant-less pin blacklists its whole role from the regular query, + so an offset naming one of its rows resolves against nothing.""" + self.assertEqual( + selections.resume_offset( + self._REGULAR, self._ALL_PASSED, selection.parse_list("web-app-c") + ), + "web-app-b#1", + ) + + def test_a_variant_the_priority_line_pins_is_never_the_offset(self) -> None: + self.assertEqual( + selections.resume_offset( + self._REGULAR, self._ALL_PASSED, selection.parse_list("web-app-c#0") + ), + "web-app-b#1", + ) + + def test_a_pin_on_another_variant_leaves_the_row_offsettable(self) -> None: + self.assertEqual( + selections.resume_offset( + self._REGULAR, self._ALL_PASSED, selection.parse_list("web-app-c#4") + ), + "web-app-c#0", + ) + + def test_a_claimed_row_mid_line_does_not_stop_the_scan(self) -> None: + self.assertEqual( + selections.resume_offset( + self._REGULAR, self._ALL_PASSED, selection.parse_list("web-app-b") + ), + "web-app-c#0", + ) + + def test_every_green_row_claimed_starts_at_the_head(self) -> None: + self.assertEqual( + selections.resume_offset( + self._REGULAR, + self._ALL_PASSED, + selection.parse_list("web-app-a web-app-b web-app-c"), + ), + "", + ) + def test_the_verdict_does_not_matter_only_that_the_row_ran(self) -> None: jobs = [ _job(deploy_job_name("swarm", "web-app-b", "1", tor=True), "failure"),