Files
computer-playbook/tests/unit/cli/meta/ci/test_sequencing.py
T
kevinveenbirkenbachandClaude Opus 5 636701ac26 feat(ci): serialise a big deploy line's modes
GitHub cancels a job queued for 24h. A line starting swarm, compose and
host at once queues its whole matrix in one go, so with more roles than
runner slots the tail waits past that cut and dies unrun -- 54 of 241
jobs in run 30937913632.

Deploy the modes one after the other instead, heaviest first, which
restarts the queue clock per mode. cli.meta.ci.sequencing counts a
line's matrix jobs on the row basis the discover steps use and
serialises above INFINITO_CI_SEQUENTIAL_THRESHOLD; below it the modes
still start together, so a small diff pays no wall-clock for this.

A needs: edge is static, so both layouts exist as jobs and the decision
skips one. Their conditions are structurally asserted, not evaluated:
ten near-identical if expressions invite a copied sentinel or a missing
chain edge, and both failures are silent at runtime.

mode_fail_fast stops a serial line at its first failed mode, on by
default.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-06 10:47:40 +02:00

49 lines
1.5 KiB
Python

from __future__ import annotations
import unittest
from unittest import mock
from cli.meta.ci import sequencing
_SELECTIONS = {
"swarm": ["a#0", "a#1", "b#0"],
"compose": ["a", "b"],
"host": ["c"],
}
def _patched(modes: str) -> int:
with (
mock.patch.object(sequencing, "discover", lambda mode, **_: _SELECTIONS[mode]),
mock.patch.object(sequencing, "get_variants", dict),
mock.patch.object(
sequencing,
"compose_bundle_counts",
lambda apps, _variants: dict.fromkeys(apps, 2),
),
):
return sequencing.line_jobs(modes, whitelist="", blacklist="", lifecycles="")
class TestLineJobs(unittest.TestCase):
def test_swarm_tokens_map_one_to_one_and_roles_bundle(self) -> None:
self.assertEqual(_patched("swarm compose host"), 3 + 4 + 2)
def test_inactive_modes_do_not_count(self) -> None:
self.assertEqual(_patched("swarm"), 3)
class TestDecide(unittest.TestCase):
def test_auto_serialises_above_the_threshold(self) -> None:
with mock.patch.dict("os.environ", {"INFINITO_CI_SEQUENTIAL_THRESHOLD": "65"}):
self.assertEqual(sequencing.decide(66, "auto"), "serial")
self.assertEqual(sequencing.decide(65, "auto"), "parallel")
def test_a_forced_choice_skips_the_threshold(self) -> None:
self.assertEqual(sequencing.decide(None, "serial"), "serial")
self.assertEqual(sequencing.decide(None, "parallel"), "parallel")
if __name__ == "__main__":
unittest.main()