mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-10 12:47:04 +00:00
Merge branch 'feature/svc-ai-litellm/remote-models-config' into feature/store-i18n
# Conflicts: # cli/build/docs/readme/generate.py # docs/requirements/035-mcp-proxy-expansion.md # roles/svc-ai-lmstudio/meta/services.yml
This commit is contained in:
commit
f2cee9bb34
532 files changed
+12314
-546
No files matched your search
@@ -0,0 +1,124 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from typing import ClassVar
|
||||
|
||||
from cli.administration.deploy.ci import timings
|
||||
from tests.utils.ci.job_names import deploy_job_name
|
||||
from utils.github.variant.pools import DISTROS, FILESYSTEMS
|
||||
|
||||
|
||||
def _job(
|
||||
name: str,
|
||||
*,
|
||||
minutes: float,
|
||||
conclusion: str = "success",
|
||||
status: str = "completed",
|
||||
) -> dict:
|
||||
return {
|
||||
"name": name,
|
||||
"status": status,
|
||||
"conclusion": conclusion,
|
||||
"startedAt": "2026-09-23T10:00:00Z",
|
||||
"completedAt": f"2026-09-23T{10 + int(minutes) // 60:02d}:{int(minutes) % 60:02d}:00Z",
|
||||
}
|
||||
|
||||
|
||||
class TestSamples(unittest.TestCase):
|
||||
"""Which jobs a duration is read off, and which are left out."""
|
||||
|
||||
def test_a_failed_job_is_not_measured(self) -> None:
|
||||
jobs = [
|
||||
_job(deploy_job_name("docker", "web-app-matomo", "0"), minutes=10),
|
||||
_job(
|
||||
deploy_job_name("swarm", "web-app-matomo", "0"),
|
||||
minutes=90,
|
||||
conclusion="failure",
|
||||
),
|
||||
]
|
||||
grouped = timings.samples(jobs)
|
||||
self.assertEqual(
|
||||
sorted(grouped["mode"]),
|
||||
["compose"],
|
||||
"a failed job's duration measures the failure, not the axis",
|
||||
)
|
||||
|
||||
def test_a_job_without_both_timestamps_is_left_out(self) -> None:
|
||||
job = _job(deploy_job_name("docker", "web-app-matomo", "0"), minutes=10)
|
||||
del job["completedAt"]
|
||||
self.assertEqual(timings.samples([job])["mode"], {})
|
||||
|
||||
def test_a_title_that_carries_no_row_is_left_out(self) -> None:
|
||||
self.assertEqual(
|
||||
timings.samples([_job("🧪 Unit tests", minutes=5)])["mode"], {}
|
||||
)
|
||||
|
||||
def test_every_axis_of_one_title_is_attributed(self) -> None:
|
||||
job = _job(
|
||||
deploy_job_name(
|
||||
"swarm",
|
||||
"web-app-matomo",
|
||||
"0",
|
||||
tor=True,
|
||||
distro=DISTROS[0],
|
||||
filesystem=FILESYSTEMS[0],
|
||||
),
|
||||
minutes=30,
|
||||
)
|
||||
grouped = timings.samples([job])
|
||||
self.assertEqual(sorted(grouped["mode"]), ["swarm"])
|
||||
self.assertEqual(sorted(grouped["tor"]), ["tor"])
|
||||
self.assertEqual(sorted(grouped["distro"]), [DISTROS[0]])
|
||||
self.assertEqual(sorted(grouped["filesystem"]), [FILESYSTEMS[0]])
|
||||
|
||||
|
||||
class TestRanking(unittest.TestCase):
|
||||
"""Cheapest first, and only for values that were seen often enough."""
|
||||
|
||||
_GROUPED: ClassVar[dict[str, dict[str, list[float]]]] = {
|
||||
"mode": {
|
||||
"swarm": [600.0, 600.0, 600.0],
|
||||
"compose": [300.0, 300.0, 300.0],
|
||||
"host": [1.0],
|
||||
},
|
||||
"tor": {},
|
||||
"distro": {},
|
||||
"filesystem": {},
|
||||
}
|
||||
|
||||
def test_the_cheapest_measured_value_wins(self) -> None:
|
||||
self.assertEqual(timings.fastest(self._GROUPED, "mode"), "compose")
|
||||
|
||||
def test_a_single_observation_does_not_steer_the_run(self) -> None:
|
||||
self.assertNotIn(
|
||||
"host",
|
||||
[
|
||||
value
|
||||
for value, _median, _count in timings.ranking(self._GROUPED, "mode")
|
||||
],
|
||||
"one job is a queue wait, not a measurement",
|
||||
)
|
||||
|
||||
def test_the_median_ignores_one_long_tail(self) -> None:
|
||||
grouped = {
|
||||
"mode": {"compose": [300.0, 300.0, 9000.0], "swarm": [400.0] * 3},
|
||||
"tor": {},
|
||||
"distro": {},
|
||||
"filesystem": {},
|
||||
}
|
||||
self.assertEqual(timings.fastest(grouped, "mode"), "compose")
|
||||
|
||||
def test_among_restricts_the_choice(self) -> None:
|
||||
self.assertEqual(
|
||||
timings.fastest(self._GROUPED, "mode", among=("swarm",)), "swarm"
|
||||
)
|
||||
|
||||
def test_nothing_measured_enough_returns_none(self) -> None:
|
||||
self.assertIsNone(
|
||||
timings.fastest(self._GROUPED, "mode", minimum=99),
|
||||
"None tells the caller to leave the axis to the rotation",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -98,6 +98,38 @@ class TestTriggerMain(unittest.TestCase):
|
||||
calls, [("entry-manual-steer.yml", "feature/x", "__ALL__", "", {}, "o/r")]
|
||||
)
|
||||
|
||||
def test_priority_is_dispatched_with_the_axis_overrides(self) -> None:
|
||||
rc, calls = self._run(
|
||||
[
|
||||
"--priority",
|
||||
"web-app-b#1@compose web-app-a#0@swarm",
|
||||
"--workspace",
|
||||
"false",
|
||||
"--chunk-gate",
|
||||
"false",
|
||||
"--filesystem",
|
||||
"btrfs",
|
||||
]
|
||||
)
|
||||
self.assertEqual(rc, 0)
|
||||
self.assertEqual(calls[0][3], "web-app-a#0@swarm web-app-b#1@compose")
|
||||
self.assertEqual(
|
||||
calls[0][4],
|
||||
{"workspace": "false", "chunk_gate": "false", "filesystem": "btrfs"},
|
||||
)
|
||||
|
||||
def test_an_unusable_token_is_refused_before_anything_is_dispatched(self) -> None:
|
||||
with mock.patch.object(
|
||||
trigger.validate, "problems", return_value=(["bad token"], [])
|
||||
):
|
||||
rc, calls = self._run(["--priority", "web-app-a#9"])
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertEqual(calls, [], "a refused line must not reach the workflow")
|
||||
|
||||
def test_priority_and_failed_cannot_both_build_the_line(self) -> None:
|
||||
with self.assertRaises(SystemExit):
|
||||
self._run(["--failed", "--priority", "web-app-a#0"])
|
||||
|
||||
def test_apps_explicit_list(self) -> None:
|
||||
rc, calls = self._run(["--apps", "web-app-a web-app-b"])
|
||||
self.assertEqual(rc, 0)
|
||||
|
||||
@@ -43,7 +43,7 @@ class TestCategoriesOf(unittest.TestCase):
|
||||
self.assertEqual(categories_of("sys-ctl-hlth-csp"), {"sys", "sys-ctl"})
|
||||
|
||||
def test_single_segment(self) -> None:
|
||||
self.assertEqual(categories_of("desk"), {"desk"})
|
||||
self.assertEqual(categories_of("dsk"), {"dsk"})
|
||||
|
||||
def test_empty(self) -> None:
|
||||
self.assertEqual(categories_of(""), set())
|
||||
|
||||
Reference in new issue
Block a user