fix(web-app-docs): name the replayed role instead of taking the first one

The instructions test brings up a machine per role, so it can only ever
replay one guide. Which one it picked was a side effect of ordering: the
lookup returned the first invokable peer the round listed, and on a CI row
that is the role under test only because the row's apps happen to read
<role>,web-app-docs.

It now reads APP_ID, which the deploy workflow already sets to the row's app
and which the swarm routine already documents as the app under test. A round
that carries no APP_ID, or one whose app publishes no Production block, draws
an invokable peer at random instead, so a local round covers a different
guide each time rather than always the first one the inventory lists.

Ansible runs inside the infinito container rather than on the runner, and
that exec passes an explicit allowlist, so the name arrives only where it is
forwarded. Two seams carry it: _FORWARDED_ENV_KEYS, which covers CI and the
local initialize and reinstall verbs, and the update verb's own docker exec,
which assembles its arguments without that CLI.

The pin is tolerant rather than strict. APP_ID is set on every deploy row and
not only on documented ones, so refusing an app that publishes no guide would
let a generic variable abort a deploy.

Measured: the draw is observed over 200 rounds rather than assumed, and the
forwarding is negative-controlled, removing the key and watching the new test
fail on that key alone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-09-28 09:16:29 +02:00
1 parent e7897ea8d3
commit a37039f0cb
6 files changed
+148 -18

No files matched your search

@@ -0,0 +1,56 @@
"""What a deploy pass carries from the host into the infinito container.
Ansible runs inside that container, so a variable the host exports reaches a
lookup only when ``_run_deploy`` forwards it explicitly. ``APP_ID`` is the
deploy workflow's name for the row's app, and
:mod:`plugins.lookup.guide_role` reads it to pin the documentation replay.
"""
from __future__ import annotations
import os
import unittest
from types import SimpleNamespace
from unittest.mock import patch
from cli.administration.deploy.development.deploy.run import _run_deploy
class _Compose:
def __init__(self) -> None:
self.extra_env: dict[str, str] = {}
def exec(self, cmd, *, check, live, extra_env):
self.extra_env = extra_env
return SimpleNamespace(returncode=0)
def _deploy() -> dict[str, str]:
compose = _Compose()
_run_deploy(
compose,
deploy_ids=["web-app-docs"],
debug=False,
passthrough=[],
inventory_dir="/srv/inv",
container_name="infinito",
)
return compose.extra_env
class TestForwardedEnv(unittest.TestCase):
@patch.dict(os.environ, {"APP_ID": "web-app-nextcloud"}, clear=True)
def test_app_id_reaches_the_container(self):
self.assertEqual(_deploy().get("APP_ID"), "web-app-nextcloud")
@patch.dict(os.environ, {}, clear=True)
def test_an_unset_app_id_is_not_invented(self):
self.assertNotIn("APP_ID", _deploy())
@patch.dict(os.environ, {"APP_ID": ""}, clear=True)
def test_an_empty_app_id_is_not_forwarded(self):
self.assertNotIn("APP_ID", _deploy())
if __name__ == "__main__":
unittest.main()