Files
computer-playbook/utils/github/variant/pins.py
T
kevinveenbirkenbachandClaude Opus 5 677a63931c Merge branch 'feature/network/multi-network-serving' into feature/store-i18n
Resolves 68 conflicted files. The governing rule was our structure with their
network semantics: the tor boolean becomes a network mode (clearnet | tor |
multi) throughout the variant layer, while this branch's architecture and mesh
axes, its extracted modules and its i18n content stay.

Where the two sides covered different ground, both are kept rather than one
picked:

- ca_injected answers a ca_client on the deployment's TLS mode OR on an SSO
  issuer that resolves self-signed. 3a3e9ed2c9 records why: an issuer is not
  an object store, so keeping only one side drops the other's coverage.
- get_merged_domains keeps the loud refusal when svc-net-tor is deployed
  without a provisioned node, now gated on their tor_serves_host; their
  node_onion_of returns an empty string there, which would have served every
  onion-exclusive app on clearnet in silence.
- sso_cookie_domains stays the single source for oauth2-proxy's cookie scope.
  Their per-network branch omitted the issuer domain on the onion arm, which
  breaks the callback leg.
- The clearnet CSP batch carries --clearnet-timeout again; their batch dict
  hardcoded zero while the role still passes the flag.
- The dashboard keeps its i18n content dir, image, version and design
  resolution; their side reduced the logo sources to the bare service
  provider values.

Their side wins where it is measurably better: the onion mirror rewrite is
gated per vhost rather than per app, the Playwright onion decision reads the
pass's own domain instead of the role's canonical one, and the matomo
reinjection and dashboard config render per network sibling.

Eight files were broken by the merge without ever carrying a conflict marker,
because git marks only the lines both sides touched:

- utils/cache/domains.py lost the onionize block that sat between two hunks
- roles/sys-front-inj-all/templates/body_filter.lua.j2 called it
- web-app-bluesky, keycloak sso_proxy: the get_entity_name filter was renamed
- trigger/__main__.py, playwright_coverage.py and its test: the deleted tor
  module
- cli/administration/deploy/ci/timings.py read Label.tor
- plugins/filter/csp_filters.py called _aligned_url with four of six arguments
- tests/unit/python/utils/cache/test_domains.py referenced a renamed class
- tests/.../sys-ctl-hlth-csp/files/test_script.py mocked a function main no
  longer calls

Verified: the variant layer (155 tests, 65 subtests), ca_injected (18),
the CI layer (175), the domains cache including the restored guard (32),
retrigger inputs (9), timings and the CSP health script (53). make
quality-high clears autoformat; its remaining findings are tracked separately.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-23 09:53:41 +02:00

142 lines
5.2 KiB
Python

"""Prove a selection token's pins against what the row and the run permit.
Separate from :mod:`utils.github.variant.axes`, which decides the axes of a
row that carries no pin: this module only refuses the combinations a pin
asks for and the row cannot give.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from utils.github.variant.network import 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
from utils.roles.meta_lookup import get_role_architectures
if TYPE_CHECKING:
from collections.abc import Sequence
__all__ = ["check_pins", "row_architectures"]
def _reject(app: str, variant: str, reason: str) -> None:
"""Abort on a selection the row cannot satisfy.
Raises:
SystemExit: always. A pin the row cannot take is an operator mistake,
and dropping the row instead would report a green run for a
combination that never ran.
"""
shard = f"{VARIANT_SEPARATOR}{variant}" if variant else ""
raise SystemExit(f"selection {app}{shard}: {reason}")
def check_pins(
app: str,
variant: str,
offered: Sequence[str],
*,
pin_mode: str | None,
pin_network: str | None,
pin_distro: str | None,
pin_filesystem: str | None,
pin_architecture: str | None = None,
pin_vpn: bool | None = None,
states: Sequence[str],
network_input: str,
vpn_mode: str = "auto",
distros: Sequence[str],
filesystems: Sequence[str],
architectures: Sequence[str] = ARCHITECTURES,
) -> None:
"""Prove the row can take what the selection token pinned on it.
The offered modes are already narrowed by the run's ``--modes`` input, the
network modes by its ``--network`` input, the mesh states by its ``--vpn``
input and the two pools by ``--distros`` and ``--filesystem``, so this
catches a pin that fights the role, the variant, or the run's own axes with
one check each.
"""
if pin_mode is not None and pin_mode not in offered:
_reject(
app,
variant,
f"pinned mode {pin_mode!r} is not available here "
f"(offered: {', '.join(offered)})",
)
for value, pool, axis in (
(pin_distro, distros, "distro"),
(pin_filesystem, filesystems, "filesystem"),
(pin_architecture, architectures, "architecture"),
):
if value is not None and value not in pool:
_reject(
app,
variant,
f"pinned {axis} {value!r} is outside this run's {axis} pool "
f"({', '.join(pool) or 'empty'})",
)
modes = (pin_mode,) if pin_mode else offered
if pin_network is not None and not any(
pin_network in network_states(mode, states=states, network_input=network_input)
for mode in modes
):
_reject(
app,
variant,
f"pinned network mode {pin_network!r} is impossible here (mode, "
f"variant, the role's reachability or the run's network axis "
f"rules it out)",
)
if pin_vpn is not None and not any(
pinned_vpn_states(mode, pin=pin_vpn, vpn_mode=vpn_mode) for mode in modes
):
_reject(
app,
variant,
f"pinned mesh state {'vpn' if pin_vpn else 'direct'} is impossible "
f"here (only {'/'.join(VPN_DEPLOY_MODES)} meshes). A held vpn axis "
f"overrides the pin instead and is not refused here",
)
def row_architectures(
app: str, run_pool: Sequence[str], services: Sequence[str] = ()
) -> tuple[str, ...]:
"""The architectures one role's rows may draw from this run.
A role that declares none takes the run's whole pool, which is what
spreads both architectures evenly over its variants: every row of the
catalogue advances the same rotation, so a role's consecutive rows
alternate rather than repeating one architecture.
Args:
app: role id, read for its ``meta/services.yml`` declaration.
run_pool: what the run permits, already narrowed by its own input.
services: the roles the row's variant deploys, each narrowing the
row like the role's own declaration.
Raises:
SystemExit: the role and the run permit nothing in common. Dropping
the row instead would report a green run for a role that never
deployed, and picking one anyway would deploy it on hardware one
of the two sides ruled out.
"""
allowed = tuple(run_pool)
declarations: list[str] = []
for role in (app, *services):
declared = get_role_architectures(role)
if declared:
declarations.append(f"{role} ({', '.join(declared)})")
allowed = tuple(value for value in allowed if value in declared)
if not allowed:
raise SystemExit(
f"{app}: meta/services.yml declares architectures for "
f"{'; '.join(declarations)}, and this run permits "
f"{', '.join(run_pool) or 'none'}. Widen the run's architecture "
f"pool or the declarations."
)
return allowed