mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-02 15:57:17 +00:00
fix(ci): refuse a priority token that leaves no combination to deploy
A priority row whose role is single_mode under a multi network axis (OpenCloud since 6e39be8383) gets no (mode, network, mesh) combination from axes.assign, so the planner silently dropped it and the run reported green for a selection that never ran (fork run 42411117881, OpenCloud#0). check_pins only rejected pinned networks. Extract the priority pick into pins.priority_picks, shared by axes.assign and cli.meta.ci.validate, and make validate (and the trigger's pre-dispatch check) refuse a priority token for which no pinned variant, or for a bare role no variant at all, has a combination left. Whitelist tokens are not held to this rule.
🎯 Fix: 93 %
💥 Break: 3 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 90
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
849e6c77b4
commit
85d5ad9984
5 files changed
+136
-23
No files matched your search
@@ -79,6 +79,7 @@ def _refused(whitelist: str, priority: str, config: dict[str, str]) -> bool:
|
||||
filesystems=pools.resolve_filesystems(config.get("filesystem")),
|
||||
lifecycles=config.get("lifecycles", ""),
|
||||
label=label,
|
||||
priority=label == "priority",
|
||||
)
|
||||
errors += found
|
||||
warnings += warned
|
||||
|
||||
+37
-7
@@ -53,6 +53,7 @@ def problems(
|
||||
architectures: tuple[str, ...] = pools.ARCHITECTURES,
|
||||
lifecycles: str,
|
||||
label: str,
|
||||
priority: bool = False,
|
||||
) -> tuple[list[str], list[str]]:
|
||||
"""Every reason the tokens of one input cannot deploy on this branch.
|
||||
|
||||
@@ -74,6 +75,7 @@ def problems(
|
||||
that declares its own narrows it further.
|
||||
lifecycles: the run's lifecycle envelope.
|
||||
label: the input's name, for the messages.
|
||||
priority: whether the tokens lead the priority line.
|
||||
|
||||
Returns:
|
||||
``(errors, warnings)``.
|
||||
@@ -93,6 +95,31 @@ def problems(
|
||||
declared = get_variants()
|
||||
errors: list[str] = []
|
||||
warnings: list[str] = []
|
||||
|
||||
def states_of(app: str, variant: int | None) -> list[str]:
|
||||
deployed = matrix.with_deployed_services(discovered[(app, variant)])
|
||||
return network.row_states(
|
||||
app, variant, declared, pulls_tor=network.row_pulls_tor(deployed)
|
||||
)
|
||||
|
||||
def deploys(pin: selection.Pin, variant: int | None) -> bool:
|
||||
return bool(
|
||||
axes.priority_picks(
|
||||
rows[(pin.app, variant)],
|
||||
pin_mode=pin.mode,
|
||||
pin_network=pin.network,
|
||||
pin_vpn=pin.vpn,
|
||||
states=states_of(pin.app, variant),
|
||||
network_input=network_input,
|
||||
vpn_mode=vpn_mode,
|
||||
)
|
||||
)
|
||||
|
||||
nothing_left = (
|
||||
"leaves no (mode, network, mesh) combination to deploy in this run "
|
||||
"(the role's reachability or the run's network or mesh axis rules out "
|
||||
"every one), so the run would report green for a selection that never ran"
|
||||
)
|
||||
for pin in pins:
|
||||
token = selection.describe(pin)
|
||||
if pin.app not in discovered_apps:
|
||||
@@ -102,6 +129,10 @@ def problems(
|
||||
)
|
||||
continue
|
||||
if not pin.pinned:
|
||||
if priority and not any(
|
||||
deploys(pin, variant) for app, variant in rows if app == pin.app
|
||||
):
|
||||
errors.append(f"{label}: {token!r} {nothing_left}")
|
||||
continue
|
||||
variants = pin.variants or (None,)
|
||||
for variant in variants:
|
||||
@@ -128,12 +159,7 @@ def problems(
|
||||
pin_filesystem=pin.filesystem,
|
||||
pin_architecture=pin.architecture,
|
||||
pin_vpn=pin.vpn,
|
||||
states=network.row_states(
|
||||
pin.app,
|
||||
variant,
|
||||
declared,
|
||||
pulls_tor=network.row_pulls_tor(deployed),
|
||||
),
|
||||
states=states_of(pin.app, variant),
|
||||
network_input=network_input,
|
||||
vpn_mode=vpn_mode,
|
||||
distros=distros,
|
||||
@@ -144,6 +170,9 @@ def problems(
|
||||
)
|
||||
except SystemExit as refusal:
|
||||
errors.append(f"{label}: {token!r} {str(refusal).split(': ', 1)[-1]}")
|
||||
continue
|
||||
if priority and not deploys(pin, variant):
|
||||
errors.append(f"{label}: {token!r} {nothing_left}")
|
||||
return errors, warnings
|
||||
|
||||
|
||||
@@ -182,6 +211,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
architectures=architectures,
|
||||
lifecycles=args.lifecycles,
|
||||
label=label,
|
||||
priority=label == "priority",
|
||||
)
|
||||
errors += found
|
||||
warnings += warned
|
||||
@@ -193,7 +223,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
if errors:
|
||||
print(
|
||||
f"\n{len(errors)} unusable selection(s). Every one of them would abort a "
|
||||
f"chunk's discovery, so the run is refused here instead.",
|
||||
f"chunk's discovery or never deploy, so the run is refused here instead.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 1
|
||||
|
||||
@@ -31,7 +31,11 @@ _NOTHING_DEPLOYED = ((), ())
|
||||
|
||||
|
||||
def _problems(
|
||||
tokens: str, *, network_input: str = "auto", vpn_mode: str = "auto"
|
||||
tokens: str,
|
||||
*,
|
||||
network_input: str = "auto",
|
||||
vpn_mode: str = "auto",
|
||||
whitelist: bool = False,
|
||||
) -> tuple[list[str], list[str]]:
|
||||
with (
|
||||
mock.patch.object(validate.query, "discover_rows", return_value=_ROWS),
|
||||
@@ -48,10 +52,14 @@ def _problems(
|
||||
distros=axes.DISTROS,
|
||||
filesystems=axes.FILESYSTEMS,
|
||||
lifecycles="",
|
||||
label="priority",
|
||||
label="whitelist" if whitelist else "priority",
|
||||
priority=not whitelist,
|
||||
)
|
||||
|
||||
|
||||
_NOTHING_LEFT = "leaves no (mode, network, mesh) combination"
|
||||
|
||||
|
||||
class TestProblems(unittest.TestCase):
|
||||
def test_nothing_to_check_is_not_a_problem(self) -> None:
|
||||
self.assertEqual(_problems(""), ([], []))
|
||||
@@ -186,6 +194,32 @@ class TestProblems(unittest.TestCase):
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertIn("matches no discovered row", errors[0])
|
||||
|
||||
def test_a_priority_variant_the_network_axis_leaves_nothing_is_an_error(
|
||||
self,
|
||||
) -> None:
|
||||
errors, _warnings = _problems("web-app-b#0@swarm", network_input="multi")
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertIn(_NOTHING_LEFT, errors[0])
|
||||
|
||||
def test_the_same_priority_variant_under_a_network_it_can_take_passes(
|
||||
self,
|
||||
) -> None:
|
||||
self.assertEqual(_problems("web-app-b#0@swarm", network_input="auto"), ([], []))
|
||||
|
||||
def test_a_bare_priority_role_no_variant_can_deploy_is_an_error(self) -> None:
|
||||
errors, _warnings = _problems("web-app-b", network_input="multi")
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertIn(_NOTHING_LEFT, errors[0])
|
||||
|
||||
def test_a_bare_priority_role_passes_while_one_variant_can_deploy(self) -> None:
|
||||
self.assertEqual(_problems("web-app-a", network_input="tor"), ([], []))
|
||||
|
||||
def test_a_whitelist_token_is_not_held_to_the_priority_rule(self) -> None:
|
||||
self.assertEqual(
|
||||
_problems("web-app-b#0@swarm", network_input="multi", whitelist=True),
|
||||
([], []),
|
||||
)
|
||||
|
||||
|
||||
class TestMain(unittest.TestCase):
|
||||
def _main(self, argv: list[str]) -> tuple[int, str, str]:
|
||||
@@ -227,6 +261,21 @@ class TestMain(unittest.TestCase):
|
||||
self.assertIn("whitelist:", err)
|
||||
self.assertIn("priority:", err)
|
||||
|
||||
def test_a_priority_token_left_without_a_combination_fails_the_run(
|
||||
self,
|
||||
) -> None:
|
||||
code, _out, err = self._main(
|
||||
["--network", "multi", "--priority", "web-app-b#0@swarm"]
|
||||
)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn(_NOTHING_LEFT, err)
|
||||
|
||||
def test_the_same_token_in_the_whitelist_does_not_fail_the_run(self) -> None:
|
||||
code, _out, _err = self._main(
|
||||
["--network", "multi", "--whitelist", "web-app-b#0@swarm"]
|
||||
)
|
||||
self.assertEqual(code, 0)
|
||||
|
||||
def test_a_warning_alone_does_not_fail_the_run(self) -> None:
|
||||
code, out, _err = self._main(["--whitelist", "web-app-gone"])
|
||||
self.assertEqual(code, 0)
|
||||
|
||||
@@ -62,13 +62,12 @@ from utils.github.variant.label import (
|
||||
)
|
||||
from utils.github.variant.network import (
|
||||
NETWORK_DEPLOY_MODES,
|
||||
combinations,
|
||||
disabled_services,
|
||||
network_states,
|
||||
row_pulls_tor,
|
||||
row_states,
|
||||
)
|
||||
from utils.github.variant.pins import check_pins, row_architectures
|
||||
from utils.github.variant.pins import check_pins, priority_picks, row_architectures
|
||||
from utils.github.variant.pools import (
|
||||
ARCHITECTURES,
|
||||
DISTROS,
|
||||
@@ -79,7 +78,6 @@ from utils.github.variant.pools import (
|
||||
)
|
||||
from utils.github.variant.vpn import (
|
||||
VPN_DEPLOY_MODES,
|
||||
pinned_vpn_states,
|
||||
rotated_vpn,
|
||||
)
|
||||
from utils.networks.reachability import NODE_MODES
|
||||
@@ -98,6 +96,7 @@ __all__ = [
|
||||
"check_pins",
|
||||
"parse_label",
|
||||
"pick_mode",
|
||||
"priority_picks",
|
||||
"resolve_sweep",
|
||||
"row_architectures",
|
||||
"sort_key",
|
||||
@@ -198,7 +197,7 @@ def assign(
|
||||
embeds it (``0``: nothing does), so a reader of the plan can tell a
|
||||
redundant row from a unique one without a second query. A regular row
|
||||
yields exactly one -- the rotation picks its combination for this
|
||||
sweep. A priority row yields every combination :func:`combinations`
|
||||
sweep. A priority row yields every combination :func:`priority_picks`
|
||||
allows, so the roles a run is told to prove are proven everywhere at
|
||||
once rather than sampled over several sweeps. ``network`` is the node
|
||||
``NETWORK_MODE`` the deploy runs with, ``vpn`` whether a swarm row
|
||||
@@ -244,14 +243,15 @@ def assign(
|
||||
architectures=offered_architectures,
|
||||
)
|
||||
if priority:
|
||||
picked = [
|
||||
(mode, state, meshed)
|
||||
for mode, state in combinations(
|
||||
offered, states=states, network_input=network_input
|
||||
)
|
||||
if pin_mode in (None, mode) and pin_network in (None, state)
|
||||
for meshed in pinned_vpn_states(mode, pin=pin_vpn, vpn_mode=vpn_mode)
|
||||
]
|
||||
picked = priority_picks(
|
||||
offered,
|
||||
pin_mode=pin_mode,
|
||||
pin_network=pin_network,
|
||||
pin_vpn=pin_vpn,
|
||||
states=states,
|
||||
network_input=network_input,
|
||||
vpn_mode=vpn_mode,
|
||||
)
|
||||
else:
|
||||
modes = _offering(
|
||||
offered, pin_network, states=states, network_input=network_input
|
||||
|
||||
@@ -9,7 +9,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from utils.github.variant.network import network_states
|
||||
from utils.github.variant.network import combinations, network_states
|
||||
from utils.github.variant.pools import ARCHITECTURES
|
||||
from utils.github.variant.vpn import VPN_DEPLOY_MODES, pinned_vpn_states
|
||||
from utils.roles.display import VARIANT_SEPARATOR
|
||||
@@ -18,7 +18,7 @@ from utils.roles.meta_lookup import get_role_architectures
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Sequence
|
||||
|
||||
__all__ = ["check_pins", "row_architectures"]
|
||||
__all__ = ["check_pins", "priority_picks", "row_architectures"]
|
||||
|
||||
|
||||
def _reject(app: str, variant: str, reason: str) -> None:
|
||||
@@ -102,6 +102,39 @@ def check_pins(
|
||||
)
|
||||
|
||||
|
||||
def priority_picks(
|
||||
offered: Sequence[str],
|
||||
*,
|
||||
pin_mode: str | None,
|
||||
pin_network: str | None,
|
||||
pin_vpn: bool | None,
|
||||
states: Sequence[str],
|
||||
network_input: str,
|
||||
vpn_mode: str,
|
||||
) -> list[tuple[str, str, bool]]:
|
||||
"""Args:
|
||||
offered: the deploy modes the row offers in this run.
|
||||
pin_mode: the token's pinned deploy mode, ``None`` for any.
|
||||
pin_network: the token's pinned network mode, ``None`` for any.
|
||||
pin_vpn: the token's pinned mesh state, ``None`` for any.
|
||||
states: the network modes the row's role can be served in.
|
||||
network_input: the run's network axis.
|
||||
vpn_mode: the run's mesh axis.
|
||||
|
||||
Returns:
|
||||
``(mode, network, meshed)`` per job, empty when the row cannot deploy
|
||||
in this run at all.
|
||||
"""
|
||||
return [
|
||||
(mode, state, meshed)
|
||||
for mode, state in combinations(
|
||||
offered, states=states, network_input=network_input
|
||||
)
|
||||
if pin_mode in (None, mode) and pin_network in (None, state)
|
||||
for meshed in pinned_vpn_states(mode, pin=pin_vpn, vpn_mode=vpn_mode)
|
||||
]
|
||||
|
||||
|
||||
def row_architectures(
|
||||
app: str, run_pool: Sequence[str], services: Sequence[str] = ()
|
||||
) -> tuple[str, ...]:
|
||||
|
||||
Reference in new issue
Block a user