diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 3afca0f735..bff53e3419 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -86,6 +86,14 @@ can outlast it — so the estimate can only overshoot the real drain time. With the current constants that is 4 waves of 20 runners, so 80 rows per chunk, and the last job of a chunk starts around t=18h, well inside the 24h window. +The repository variable `INFINITO_CI_CONCURRENCY` overrides the `default.env` +value; unset or empty keeps it. `call-validation.yml` and `call-test-deploy.yml` +forward it in their workflow-level `env:`, so the batch count and every chunk's +cut use the same size. An account that runs 500 jobs at once (GitHub +Enterprise) gets a chunk larger than `available` below, so a sweep needs one +chunk, two with a priority line, and only the run's job cap bounds it. See +[configuration.md](../../docs/contributing/tools/github/actions/configuration.md). + ### How many chunks a sweep spends The run's 256-job cap is the second ceiling. `slots` counts every non-deploy diff --git a/.github/workflows/call-test-deploy.yml b/.github/workflows/call-test-deploy.yml index b2ee79e5c7..d9cb405b8d 100644 --- a/.github/workflows/call-test-deploy.yml +++ b/.github/workflows/call-test-deploy.yml @@ -170,6 +170,7 @@ env: INFINITO_ARCHITECTURES: ${{ inputs.architectures }} INFINITO_LIFECYCLES: ${{ inputs.lifecycles }} INFINITO_DISCOVERY_SEED: ${{ github.run_id }} + INFINITO_CI_CONCURRENCY: ${{ vars.INFINITO_CI_CONCURRENCY }} jobs: discover: diff --git a/.github/workflows/call-validation.yml b/.github/workflows/call-validation.yml index 9171c80a82..0129e213d7 100644 --- a/.github/workflows/call-validation.yml +++ b/.github/workflows/call-validation.yml @@ -105,6 +105,9 @@ on: permissions: contents: read +env: + INFINITO_CI_CONCURRENCY: ${{ vars.INFINITO_CI_CONCURRENCY }} + jobs: validation: name: ✅ Validation diff --git a/default.env b/default.env index 9bf1183b89..de48167700 100644 --- a/default.env +++ b/default.env @@ -139,7 +139,7 @@ INFINITO_CI_CHUNK=0 # Rows one deploy chunk holds, overriding the concurrency-times-waves derivation; 0 derives it. INFINITO_CI_CHUNK_SIZE=0 -# Runner slots a deploy chunk may assume are free; with the job timeout it sizes a chunk in cli.meta.ci.slots. +# Runner slots a deploy chunk may assume are free (cli.meta.ci.slots); a set repository variable of this name overrides it in CI. INFINITO_CI_CONCURRENCY=20 # Budget distros.sh spends before skipping the rest; stays under the 350-min step cap, which stays under the 355-min job cap. diff --git a/docs/contributing/tools/github/actions/configuration.md b/docs/contributing/tools/github/actions/configuration.md index 18fd9633bd..49eb637785 100644 --- a/docs/contributing/tools/github/actions/configuration.md +++ b/docs/contributing/tools/github/actions/configuration.md @@ -18,6 +18,7 @@ Repository variables are set under **Settings → Secrets and variables → Acti | `API_OPENROUTER_KEY` | [call-test-deploy.yml](../../../../../.github/workflows/call-test-deploy.yml) | The gateway publishes no `openrouter/auto` model | An OpenRouter key | | `INFINITO_MAIL_PRODUCTION_HOST` | [call-test-deploy.yml](../../../../../.github/workflows/call-test-deploy.yml) | The read-only production mail assertions are skipped, because the task that runs them is gated on this host being set | The public hostname of a deployed mail server, to assert its MX, SPF, DKIM, DMARC and PTR records and its SMTP greeting after a deploy; nothing is sent and nothing is mutated | | `INFINITO_MAIL_PRODUCTION_RESOLVER` | [call-test-deploy.yml](../../../../../.github/workflows/call-test-deploy.yml) | Those assertions resolve through the runner's own resolver | A DNS server address, to resolve the records against it instead; ignored while `INFINITO_MAIL_PRODUCTION_HOST` is unset | +| `INFINITO_CI_CONCURRENCY` | [call-validation.yml](../../../../../.github/workflows/call-validation.yml), [call-test-deploy.yml](../../../../../.github/workflows/call-test-deploy.yml) | Deploy chunks are sized from the runner slots [default.env](../../../../../default.env) declares | The jobs the account runs at once, e.g. `500` on GitHub Enterprise; once the derived chunk size exceeds the run's job budget, a sweep needs one chunk (two with a priority line) and only `INFINITO_CI_JOB_LIMIT` bounds it. Both workflows forward it, so the batch count and every chunk's cut agree | ## Provider keys: variable or secret? 🔑 diff --git a/tests/integration/meta/workflows/test_ci_concurrency_variable_forwarded.py b/tests/integration/meta/workflows/test_ci_concurrency_variable_forwarded.py new file mode 100644 index 0000000000..252b16551c --- /dev/null +++ b/tests/integration/meta/workflows/test_ci_concurrency_variable_forwarded.py @@ -0,0 +1,70 @@ +"""Every workflow that sizes deploy chunks forwards the runner-slot variable. + +The validation job counts the priority batches and every chunk's discover job +cuts its rows from the same ``cli.meta.ci.slots`` arithmetic. A workflow that +sizes chunks without ``vars.INFINITO_CI_CONCURRENCY`` cuts a different plan +than its siblings, so rows are skipped or deployed twice. +""" + +from __future__ import annotations + +import unittest +from typing import TYPE_CHECKING + +from utils.cache.files import read_text +from utils.cache.yaml import load_yaml_any + +from . import PROJECT_ROOT + +if TYPE_CHECKING: + from pathlib import Path + +WORKFLOWS = PROJECT_ROOT / ".github" / "workflows" +KEY = "INFINITO_CI_CONCURRENCY" +FORWARD = "${{ vars.INFINITO_CI_CONCURRENCY }}" +_SIZERS = ( + "cli.meta.ci.matrix", + "cli.meta.ci.plan", + "cli.meta.ci.slots", + "scripts/github/resolve/output_apps.sh", + "scripts/github/resolve/priority_batches.sh", +) + + +def _sizing_workflows() -> list[Path]: + return [ + path + for path in sorted(WORKFLOWS.glob("*.yml")) + if any(marker in read_text(str(path)) for marker in _SIZERS) + ] + + +def _forwarded(path: Path) -> str | None: + workflow = load_yaml_any(str(path), default_if_missing={}) or {} + env = workflow.get("env") if isinstance(workflow, dict) else None + return env.get(KEY) if isinstance(env, dict) else None + + +class TestCiConcurrencyVariableForwarded(unittest.TestCase): + def test_every_chunk_sizing_workflow_forwards_the_variable(self) -> None: + offenders = [ + path.name for path in _sizing_workflows() if _forwarded(path) != FORWARD + ] + self.assertEqual( + offenders, + [], + f"declare `{KEY}: {FORWARD}` in the workflow-level env of every " + "workflow that sizes deploy chunks", + ) + + def test_the_guard_finds_the_chunk_sizing_workflows(self) -> None: + self.assertGreaterEqual( + len(_sizing_workflows()), + 2, + "the validation and deploy workflows both size chunks; finding " + "fewer means the markers drifted and the guard passes vacuously", + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/unit/python/cli/gha/test_split_runner_apps.py b/tests/unit/python/cli/gha/test_split_runner_apps.py index a3762f029f..a3ea8b7910 100644 --- a/tests/unit/python/cli/gha/test_split_runner_apps.py +++ b/tests/unit/python/cli/gha/test_split_runner_apps.py @@ -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() diff --git a/tests/unit/python/cli/meta/ci/test_chunks.py b/tests/unit/python/cli/meta/ci/test_chunks.py index e35b73192b..8317250209 100644 --- a/tests/unit/python/cli/meta/ci/test_chunks.py +++ b/tests/unit/python/cli/meta/ci/test_chunks.py @@ -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() diff --git a/tests/unit/python/cli/meta/ci/test_slots.py b/tests/unit/python/cli/meta/ci/test_slots.py index 6beeff7b76..4097b64377 100644 --- a/tests/unit/python/cli/meta/ci/test_slots.py +++ b/tests/unit/python/cli/meta/ci/test_slots.py @@ -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: