mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 13:57:43 +00:00
feat(ci): let vars.INFINITO_CI_CONCURRENCY override the runner slots
call-validation.yml and call-test-deploy.yml forward the repository variable in their workflow-level env, so the priority batch count and every chunk's discover step cut the same plan. Unset or empty keeps the default.env value: env_setting and load.sh both skip an empty caller value. Set to 500, the chunk size exceeds the run's job budget, a sweep needs one chunk (two with a priority line), and INFINITO_CI_JOB_LIMIT is the only bound. A workflow guard fails when a chunk-sizing workflow stops forwarding the variable. Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6c5dbfb0e5
commit
6622f9bfb5
9 files changed
+168
-3
No files matched your search
@@ -12,11 +12,25 @@ from . import PROJECT_ROOT
|
||||
SCRIPT = PROJECT_ROOT / "scripts" / "github" / "split_runner_apps.sh"
|
||||
|
||||
|
||||
def _run(apps: list, self_hosted_count: int) -> dict:
|
||||
def _fresh_step_env(**values: str) -> dict[str, str]:
|
||||
"""The environment of a new CI step: nothing the env loader exported.
|
||||
|
||||
Args:
|
||||
values: keys the step sets itself, as a workflow ``env:`` would.
|
||||
|
||||
Returns:
|
||||
The process environment without ``INFINITO_*`` keys, plus *values*.
|
||||
"""
|
||||
env = {k: v for k, v in os.environ.items() if not k.startswith("INFINITO_")}
|
||||
env.update(values)
|
||||
return env
|
||||
|
||||
|
||||
def _run(apps: list, self_hosted_count: int, env: dict[str, str] | None = None) -> dict:
|
||||
with tempfile.NamedTemporaryFile(mode="r", suffix=".env", delete=False) as out_f:
|
||||
out_path = out_f.name
|
||||
try:
|
||||
env = os.environ.copy()
|
||||
env = os.environ.copy() if env is None else dict(env)
|
||||
env["APPS_JSON"] = json.dumps(apps)
|
||||
env["CI_SELF_HOSTED_RUNNER_COUNT"] = str(self_hosted_count)
|
||||
env["GITHUB_OUTPUT"] = out_path
|
||||
@@ -60,6 +74,17 @@ class TestSplitRunnerApps(unittest.TestCase):
|
||||
combined = out["apps_github"] + out["apps_self_hosted"]
|
||||
self.assertEqual(combined, ["only-app"])
|
||||
|
||||
def test_an_empty_concurrency_splits_like_an_unset_one(self):
|
||||
apps = list(range(40))
|
||||
self.assertEqual(
|
||||
_run(apps, 20, _fresh_step_env(INFINITO_CI_CONCURRENCY="")),
|
||||
_run(apps, 20, _fresh_step_env()),
|
||||
)
|
||||
|
||||
def test_a_set_concurrency_drives_the_split(self):
|
||||
out = _run(list(range(40)), 20, _fresh_step_env(INFINITO_CI_CONCURRENCY="500"))
|
||||
self.assertEqual(len(out["apps_github"]), 40 * 500 // (500 + 20))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -102,5 +102,24 @@ class TestPlan(unittest.TestCase):
|
||||
self.assertEqual(chunks.plan([], [], size=80, blocks=3, budget=211), [])
|
||||
|
||||
|
||||
class TestChunkBeyondTheBudget(unittest.TestCase):
|
||||
def test_the_whole_budget_goes_into_one_regular_chunk(self) -> None:
|
||||
plan = chunks.plan([], list(range(500)), size=2000, blocks=4, budget=203)
|
||||
self.assertEqual([len(c) for c in plan], [203])
|
||||
|
||||
def test_a_short_priority_chunk_strands_no_row_of_the_budget(self) -> None:
|
||||
plan = chunks.plan(
|
||||
list(range(7)), list(range(100, 600)), size=2000, blocks=4, budget=203
|
||||
)
|
||||
self.assertEqual([len(c) for c in plan], [7, 196])
|
||||
self.assertEqual(plan[0], list(range(7)))
|
||||
|
||||
def test_priority_beyond_the_budget_fills_one_chunk_up_to_the_cap(self) -> None:
|
||||
plan = chunks.plan(
|
||||
list(range(300)), list(range(50)), size=2000, blocks=4, budget=203
|
||||
)
|
||||
self.assertEqual([len(c) for c in plan], [203])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -8,6 +8,8 @@ from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from cli.meta.ci import slots
|
||||
from utils.cache.files import PROJECT_ROOT
|
||||
from utils.env.parser import parse_static_env
|
||||
|
||||
_SETTINGS = {
|
||||
"INFINITO_CI_JOB_LIMIT": "256",
|
||||
@@ -185,6 +187,42 @@ class TestChunkArithmetic(unittest.TestCase):
|
||||
root = Path(tmp)
|
||||
self.assertLessEqual(slots.rows_per_sweep(root), slots.available(root))
|
||||
|
||||
def test_enterprise_concurrency_leaves_the_job_cap_as_the_only_limit(
|
||||
self,
|
||||
) -> None:
|
||||
with (
|
||||
_tree() as tmp,
|
||||
mock.patch.dict(
|
||||
"os.environ",
|
||||
{
|
||||
**_SETTINGS,
|
||||
"INFINITO_CI_CONCURRENCY": "500",
|
||||
"INFINITO_CI_CHUNK_SIZE": "0",
|
||||
},
|
||||
),
|
||||
):
|
||||
root = Path(tmp)
|
||||
self.assertGreater(slots.chunk_size(root), slots.available(root))
|
||||
self.assertEqual(slots.chunk_count(root), 1)
|
||||
self.assertEqual(slots.rows_per_sweep(root), slots.available(root))
|
||||
|
||||
|
||||
class TestConcurrencySetting(unittest.TestCase):
|
||||
def test_an_empty_or_blank_value_falls_back_to_default_env(self) -> None:
|
||||
declared = int(
|
||||
parse_static_env(PROJECT_ROOT / "default.env")["INFINITO_CI_CONCURRENCY"]
|
||||
)
|
||||
for raw in ("", " "):
|
||||
with (
|
||||
self.subTest(raw=raw),
|
||||
mock.patch.dict("os.environ", {"INFINITO_CI_CONCURRENCY": raw}),
|
||||
):
|
||||
self.assertEqual(slots.setting("INFINITO_CI_CONCURRENCY"), declared)
|
||||
|
||||
def test_a_set_value_wins_over_default_env(self) -> None:
|
||||
with mock.patch.dict("os.environ", {"INFINITO_CI_CONCURRENCY": "500"}):
|
||||
self.assertEqual(slots.setting("INFINITO_CI_CONCURRENCY"), 500)
|
||||
|
||||
|
||||
class TestRenderMatrix(unittest.TestCase):
|
||||
def test_table_lists_every_job_and_the_chunk_arithmetic(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user