From 1dd2cd114b6479ee4b151fcad461e3855e9f5104 Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 14:44:52 -0500 Subject: [PATCH 01/11] feat(plane): send Plane mail through the platform SMTP settings [AC-1127] With smtp_host set in the inventory, Phase 3 writes Plane's outbound mail instance settings (ENABLE_SMTP and the EMAIL_* keys) from the inventory's SMTP values and the mail token read from secret/services/smtp:plane_smtp_token. The token is read only while mail is on, as a listed read that fails the run when the key is missing. With mail off no mail key is sent and nothing is cleared. The SMTP guard is the first task of Phases 1, 3 and 4. The local-dev Plane worker joins the local-dev network so it can reach the local mail catcher. The production inventory is unchanged, so mail stays off there. --- platform/playbooks/deploy-plane.yml | 110 +++++++++++++++++- .../plane/deployment/compose.local.yml | 5 + platform/tests/test_service_plane.bats | 2 +- 3 files changed, 112 insertions(+), 5 deletions(-) diff --git a/platform/playbooks/deploy-plane.yml b/platform/playbooks/deploy-plane.yml index 86ac479d1..dc64730ec 100644 --- a/platform/playbooks/deploy-plane.yml +++ b/platform/playbooks/deploy-plane.yml @@ -11,6 +11,8 @@ # Phase 3: First-run configuration (configure_instance.py, inside plane-api): instance setup, # invitation-only sign-up and the workspace. In the SAME run as the first start, # because until the first admin signs up anyone who reaches /god-mode/ claims it. +# With mail on (smtp_host set), the same run also writes Plane's outbound mail settings +# from the inventory's SMTP values and the mail token in secret/services/smtp. # Phase 3b: Get or create the workspace service token (service_token.py) and store it in # OpenBao, so sync-plane-projects.yml only ever reads it. # Phase 3c: Activate the Pro licence from OpenBao (activate_license.py), as the workspace owner; @@ -19,7 +21,9 @@ # (github_app_token.py set-hook-secret, on the controller) to the one Plane holds. # Phase 3e: Create Plane's marketplace applications (GitHub, Slack, ...) that are missing, the # entries Workspace settings > Integrations lists (ensure_marketplace_apps.py). -# Phase 4: Verify through the proxy, then record the service-deploy step result. +# Phase 4: Verify through the proxy. With mail on locally, it also sends a test mail from the Plane +# worker and checks that the local mail catcher received it. Then it records the +# service-deploy step result. # # Plan: plan/development/16-plane-work-management.md # Change: plan/development/openspec/changes/deploy-plane-work-management/ @@ -126,14 +130,23 @@ # the worker's env). Read it read-only, and only when sign-in through Authentik is configured # (plane_authentik_base), so a host without OIDC never depends on Deploy Authentik having # declared it. Never stored back under secret/services/plane. + # The mail token is read only when mail is on (smtp_host set), and then as a listed read: a + # missing path fails the run, so Phase 3 never reaches the mail settings without it. _shared_reads: >- - {{ [{'from_service': 'authentik', 'read_keys': ['plane_oidc_client_secret']}] - if plane_authentik_base is defined else [] }} + {{ ([{'from_service': 'authentik', 'read_keys': ['plane_oidc_client_secret']}] + if plane_authentik_base is defined else []) + + ([{'from_service': 'smtp', 'read_keys': ['plane_smtp_token']}] + if (smtp_host | default('', true) | string) | length > 0 else []) }} _env_templates: - { src: env.j2, dest: .env, mode: "0600" } _service_url: "{{ plane_public_url | default('') }}" tasks: + # The SMTP guard runs first: it refuses a mail setting that would send the token somewhere it + # must not go, before any secret is read. + - name: "Refuse SMTP settings that would send the mail token somewhere it must not go" + ansible.builtin.include_tasks: tasks/assert-smtp-settings.yml + # manage-secrets sends the controller AppRole and receives every secret over this # connection — refuse a public cleartext endpoint before any of it is sent. - name: "Refuse a cleartext OpenBao endpoint" @@ -213,8 +226,25 @@ 'OIDC_AUTHORIZE_URL': plane_authentik_base ~ '/application/o/authorize/', 'OIDC_TOKEN_URL': plane_authentik_base ~ '/application/o/token/', 'OIDC_USERINFO_URL': plane_authentik_base ~ '/application/o/userinfo/'} }} + # Outbound mail, on when the inventory sets smtp_host (the guard reads the same expression). Off, + # no mail key is sent and nothing is cleared: the disable endpoint is not called. Every value is + # a string, so a second run with the same settings patches nothing. + _plane_mail_settings: >- + {{ {} if not ((smtp_host | default('', true) | string) | length > 0) else { + 'ENABLE_SMTP': '1', + 'EMAIL_HOST': smtp_host | string, + 'EMAIL_PORT': smtp_port | string, + 'EMAIL_HOST_USER': smtp_username | string, + 'EMAIL_HOST_PASSWORD': _shared.plane_smtp_token, + 'EMAIL_USE_TLS': '1' if (smtp_starttls | default(true) | bool) else '0', + 'EMAIL_USE_SSL': '0', + 'EMAIL_FROM': smtp_from_address | string} }} tasks: + # The SMTP guard runs first, as in every play that renders a mail setting. + - name: "Refuse SMTP settings that would send the mail token somewhere it must not go" + ansible.builtin.include_tasks: tasks/assert-smtp-settings.yml + # Credential task: the admin password goes to the script on stdin, so no_log here and # only the non-secret summary is shown below. - name: "Converge instance setup, invitation-only sign-up and the workspace" @@ -237,7 +267,7 @@ 'company': plane_company_name, 'workspace_slug': plane_workspace_slug, 'workspace_name': plane_workspace_name, - 'settings': _plane_oidc_settings} | to_json }} + 'settings': _plane_oidc_settings | combine(_plane_mail_settings)} | to_json }} register: _plane_configure # The script prints one JSON line, {"changed", "actions"} or {"error"}, never a credential. # Judged below from that line, so a refusal is visible while this task stays no_log. @@ -592,8 +622,24 @@ become: false vars: _engine: "{{ container_engine | default('podman') }}" + _monorepo_dir: "{{ local_monorepo_dir | default('/home/' ~ (ansible_user | default('deploy')) ~ '/agent-cloud') }}" + _deploy_dir: "{{ _monorepo_dir }}/{{ monorepo_deploy_path }}" + # The names of the running containers whose compose service label is exactly `worker` + # (not beat-worker, not a worker2). Read from the `podman ps` the local mail check registers. + _plane_worker_names: >- + {%- set ns = namespace(names=[]) -%} + {%- for c in (_plane_ps.stdout | default('[]', true) | from_json) -%} + {%- if ((c.Labels | default({}, true))['com.docker.compose.service'] | default('', true)) == 'worker' -%} + {%- set ns.names = ns.names + [c.Names[0]] -%} + {%- endif -%} + {%- endfor -%} + {{ ns.names }} tasks: + # The SMTP guard runs first, as in every play that renders a mail setting. + - name: "Refuse SMTP settings that would send the mail token somewhere it must not go" + ansible.builtin.include_tasks: tasks/assert-smtp-settings.yml + # A dry run skipped the deploy, so on a fresh host the stack does not exist and the probe # below would fail on it: check, and stop the dry run there (deploy-agentgateway.yml). - name: "Dry run: is the plane proxy running?" @@ -682,6 +728,62 @@ - name: "Every container is running and stable (no crash loop)" ansible.builtin.include_tasks: tasks/assert-containers-stable.yml + # Local-dev only, with mail on (AC-1127): a test mail from the Plane worker must reach the local + # catcher. test_email exits 0 even when delivery fails, so the send task judges its exact success + # line rather than the exit code. + - name: "Local mail check: a test mail from the Plane worker reaches the local catcher" + when: + - (smtp_host | default('', true) | string) | length > 0 + - groups['all'] | local_dev_inventory + - not ansible_check_mode + block: + - name: "Find the Plane worker container (local mail check)" + ansible.builtin.command: + argv: + - "{{ _engine }}" + - ps + - --filter + - "{{ 'label=com.docker.compose.project.working_dir=' ~ _deploy_dir }}" + - --format + - json + register: _plane_ps + changed_when: false + + - name: "Require exactly one Plane worker container" + ansible.builtin.assert: + that: + - _plane_worker_names | length == 1 + # default() keeps this renderable when the list is empty (MISTAKES 10.36). + fail_msg: "expected exactly one Plane worker container, found {{ _plane_worker_names | default([]) | length }}" + quiet: true + + # The send is judged from the time just before it, so the catcher check counts only this run's mail. + - name: "Mark the time just before the test mail" + ansible.builtin.set_fact: + _plane_mail_since: "{{ now(utc=true, fmt='%Y-%m-%dT%H:%M:%SZ') }}" + + - name: "Send a test mail from the Plane worker" + ansible.builtin.command: + argv: + - "{{ _engine }}" + - exec + - "{{ _plane_worker_names[0] }}" + - python + - manage.py + - test_email + - "{{ smtp_from_address | string }}" + register: _plane_test_mail + changed_when: false + failed_when: _plane_test_mail.rc != 0 or 'Email successfully sent' not in _plane_test_mail.stdout_lines + + - name: "The test mail reached the local mail catcher" + ansible.builtin.include_tasks: tasks/assert-mail-captured.yml + vars: + mail_captured_api_url: "http://mailpit:8025" + mail_captured_recipient: "{{ smtp_from_address }}" + mail_captured_subject: "Test email" + mail_captured_since: "{{ _plane_mail_since }}" + - name: "Report" ansible.builtin.debug: msg: >- diff --git a/platform/services/plane/deployment/compose.local.yml b/platform/services/plane/deployment/compose.local.yml index baf3a56f5..5c43652ea 100644 --- a/platform/services/plane/deployment/compose.local.yml +++ b/platform/services/plane/deployment/compose.local.yml @@ -22,3 +22,8 @@ services: networks: - default - local-dev + # worker sends Plane's mail (its celery tasks) to the local catcher, mailpit:1025 on local-dev. + worker: + networks: + - default + - local-dev diff --git a/platform/tests/test_service_plane.bats b/platform/tests/test_service_plane.bats index 338410918..92ede9e0a 100644 --- a/platform/tests/test_service_plane.bats +++ b/platform/tests/test_service_plane.bats @@ -222,7 +222,7 @@ PY grep -qF 'PLANE_OIDC_CLIENT_SECRET={{ secrets.plane_oidc_client_secret }}' "$ak/templates/env.j2" # Plane shared-reads it (never stores a copy) and converges its instance settings with it. # Read only when OIDC is configured, so a host without it never depends on Deploy Authentik. - grep -qF "if plane_authentik_base is defined else [] }}" "$PLAYBOOK" + grep -qF "if plane_authentik_base is defined else [])" "$PLAYBOOK" # Unset is the kill switch: OIDC is switched off, not left as it was. grep -qF "{'IS_OIDC_ENABLED': '0'} if plane_authentik_base is not defined" "$PLAYBOOK" grep -qF "'OIDC_CLIENT_SECRET': _shared.plane_oidc_client_secret" "$PLAYBOOK" From cb05c03fddda4845e5f3a3fb994ec8fc46dcc0d4 Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 14:45:25 -0500 Subject: [PATCH 02/11] test(plane): pin Plane's mail settings, worker selection and test-mail judgement [AC-1127] The new tests run the expressions and tasks of deploy-plane.yml as written. They cover the settings for each spelling of smtp_host and smtp_starttls, the listed read in each combination of Authentik and mail, the worker selection by compose service label, the exact success line of the test mail, and the play and task order of the Phase 4 local mail check. Nothing reaches a container, a mail server or the network: the worker listing and the test-mail command are stubbed, and every value is a placeholder. --- platform/tests/test_plane_outbound_mail.py | 326 +++++++++++++++++++++ 1 file changed, 326 insertions(+) create mode 100644 platform/tests/test_plane_outbound_mail.py diff --git a/platform/tests/test_plane_outbound_mail.py b/platform/tests/test_plane_outbound_mail.py new file mode 100644 index 000000000..5a1f97f2b --- /dev/null +++ b/platform/tests/test_plane_outbound_mail.py @@ -0,0 +1,326 @@ +"""Plane's outbound mail (AC-1127), tested from deploy-plane.yml itself. + +The expressions and tasks below are read from the playbook's YAML, never copied, so a red test +names the playbook's own text. Jinja runs under ansible-playbook on localhost through harness_sandbox. +Three things are stubbed: the worker listing (a `_plane_ps` play var stands in for `podman ps`), the +test-mail command (its argv is replaced by printf), and the mail catcher (not called here). Every value +is a placeholder: example.test addresses and a fake token. Nothing here reaches a container, a mail +server or the network. +""" + +import copy +import json +import re +from pathlib import Path + +import harness_sandbox +import playbook_yaml +import pytest +import yaml + +REPO = playbook_yaml.REPO +DEPLOY = REPO / "platform/playbooks/deploy-plane.yml" +COMPOSE_LOCAL = REPO / "platform/services/plane/deployment/compose.local.yml" + +PHASE1 = "Phase 1: Place repo + manage plane secrets" +PHASE3 = "Phase 3: Configure plane" +PHASE4 = "Phase 4: Verify plane" +GUARD = "Refuse SMTP settings that would send the mail token somewhere it must not go" +GUARD_FILE = "tasks/assert-smtp-settings.yml" +CONVERGE = "Converge instance setup, invitation-only sign-up and the workspace" +CONTAINERS_STABLE = "Every container is running and stable (no crash loop)" +MAIL_BLOCK = "Local mail check: a test mail from the Plane worker reaches the local catcher" +FIND = "Find the Plane worker container (local mail check)" +WORKER_ASSERT = "Require exactly one Plane worker container" +MARK = "Mark the time just before the test mail" +SEND = "Send a test mail from the Plane worker" +CATCHER = "The test mail reached the local mail catcher" +RECORD = "Record the service-deploy step result" +MAIL_ON_WHEN = [ + "(smtp_host | default('', true) | string) | length > 0", + "groups['all'] | local_dev_inventory", + "not ansible_check_mode", +] +FAKE_TOKEN = "tok-example-not-real" +UNSET = object() + +# The five inventory names as local-dev sets them, with a mail host that is on. +MAIL = { + "smtp_host": "mail.example.test", + "smtp_port": 587, + "smtp_starttls": True, + "smtp_username": "plane-mail@example.test", + "smtp_from_address": "noreply@example.test", +} +MAIL_OTHER = {k: v for k, v in MAIL.items() if k != "smtp_host"} +OFF_HOST_VARS = [{}, {"smtp_host": False}, {"smtp_host": 0}, {"smtp_host": ""}, {"smtp_host": None}] +AUTH = {"plane_authentik_base": "https://auth.example.test:8443"} + + +def _play(name: str) -> dict: + return next(p for p in playbook_yaml.load(DEPLOY) if p.get("name") == name) + + +def _task(play: dict, name: str) -> dict: + """A task by its exact name, at any depth, as a copy the test may edit.""" + return copy.deepcopy(next(t for t in playbook_yaml.tasks(play.get("tasks")) if t.get("name") == name)) + + +def _phase3_vars() -> dict: + # The real Phase 3 vars; `_shared` stands in for the fact manage-secrets sets in Phase 1. + return {**_play(PHASE3)["vars"], "_shared": {"plane_smtp_token": FAKE_TOKEN}} + + +def _run(tmp: Path, host_vars: dict, play_vars: dict, tasks: list, host: str = "plane"): + inv = {"all": {"hosts": {host: {"ansible_connection": "local", **host_vars}}}} + (tmp / "inv.yml").write_text(yaml.safe_dump(inv)) + (tmp / "play.yml").write_text( + yaml.safe_dump([{"hosts": "all", "gather_facts": False, "vars": play_vars, "tasks": tasks}]) + ) + return harness_sandbox.run( + ["ansible-playbook", "-i", str(tmp / "inv.yml"), str(tmp / "play.yml")], + tmp, + cwd=REPO, + env=harness_sandbox.env_for(tmp), + ) + + +def _value(tmp: Path, expr: str, host_vars: dict, play_vars: dict, host: str = "plane"): + """The JSON value of a Jinja expression, evaluated by ansible-playbook on a real play.""" + out = tmp / "value.json" + copy_task = {"ansible.builtin.copy": {"content": expr, "dest": str(out)}} + r = _run(tmp, host_vars, play_vars, [copy_task], host) + assert r.returncode == 0, r.stdout + r.stderr + return json.loads(out.read_text()) + + +def _mail_settings(tmp: Path, host_vars: dict) -> dict: + return _value(tmp, "{{ _plane_mail_settings | to_json }}", host_vars, _phase3_vars()) + + +# ── What Plane is told (Phase 3) ───────────────────────────────────────────── + + +@pytest.mark.parametrize("host_vars", OFF_HOST_VARS) +def test_mail_is_off_when_smtp_host_is_unset_false_zero_blank_or_null(tmp_path, host_vars): + assert _mail_settings(tmp_path, {**MAIL_OTHER, **host_vars}) == {} + + +def test_mail_on_writes_exactly_the_eight_settings_and_every_value_is_a_string(tmp_path): + got = _mail_settings(tmp_path, MAIL) + assert got == { + "ENABLE_SMTP": "1", + "EMAIL_HOST": "mail.example.test", + "EMAIL_PORT": "587", + "EMAIL_HOST_USER": "plane-mail@example.test", + "EMAIL_HOST_PASSWORD": FAKE_TOKEN, + "EMAIL_USE_TLS": "1", + "EMAIL_USE_SSL": "0", + "EMAIL_FROM": "noreply@example.test", + } + assert all(isinstance(v, str) for v in got.values()) + + +@pytest.mark.parametrize("port", [1025, "1025"]) +def test_the_port_is_a_string_whether_the_inventory_gives_an_int_or_a_string(tmp_path, port): + assert _mail_settings(tmp_path, {**MAIL, "smtp_port": port})["EMAIL_PORT"] == "1025" + + +@pytest.mark.parametrize( + ("starttls", "expected"), + [ + (True, "1"), + ("true", "1"), + ("True", "1"), + (UNSET, "1"), + (False, "0"), + ("false", "0"), + ("False", "0"), + ], +) +def test_starttls_maps_to_tls_as_a_string_for_every_spelling(tmp_path, starttls, expected): + host = {k: v for k, v in MAIL.items() if k != "smtp_starttls"} + if starttls is not UNSET: + host["smtp_starttls"] = starttls + got = _mail_settings(tmp_path, host) + assert got["EMAIL_USE_TLS"] == expected + # SSL is never on: Plane's TLS and SSL are exclusive, and the catcher and the relay both use STARTTLS. + assert got["EMAIL_USE_SSL"] == "0" + + +def test_the_converge_stdin_carries_the_oidc_settings_combined_with_the_mail_settings(tmp_path): + task = _task(_play(PHASE3), CONVERGE) + assert "_plane_oidc_settings | combine(_plane_mail_settings)" in task["ansible.builtin.command"]["stdin"] + base = { + "plane_public_url": "https://plane.example.test", + "plane_automation_email": "automation@example.test", + "plane_company_name": "Example Co", + "plane_workspace_slug": "example", + "plane_workspace_name": "Example", + } + play_vars = {**_phase3_vars(), "_resolved": {"plane_automation_password": "pw-example-not-real"}} + got = _value(tmp_path, task["ansible.builtin.command"]["stdin"], {**base, **MAIL}, play_vars)["settings"] + combined = _value( + tmp_path, + "{{ (_plane_oidc_settings | combine(_plane_mail_settings)) | to_json }}", + {**base, **MAIL}, + play_vars, + ) + assert got == combined + assert got["ENABLE_SMTP"] == "1" and got["IS_OIDC_ENABLED"] == "0" + + +def test_with_mail_off_the_converge_stdin_sends_no_mail_key(tmp_path): + task = _task(_play(PHASE3), CONVERGE) + base = { + "plane_public_url": "https://plane.example.test", + "plane_automation_email": "automation@example.test", + "plane_company_name": "Example Co", + "plane_workspace_slug": "example", + "plane_workspace_name": "Example", + } + play_vars = {**_phase3_vars(), "_resolved": {"plane_automation_password": "pw-example-not-real"}} + got = _value(tmp_path, task["ansible.builtin.command"]["stdin"], base, play_vars)["settings"] + assert got == {"IS_OIDC_ENABLED": "0"} + + +# ── What the deploy reads (Phase 1) ────────────────────────────────────────── + + +@pytest.mark.parametrize("auth", [False, True]) +@pytest.mark.parametrize("mail", [False, True]) +def test_the_token_is_a_listed_read_only_while_mail_is_on(tmp_path, auth, mail): + host_vars = {**(AUTH if auth else {}), **(MAIL if mail else {})} + shared_reads = _play(PHASE1)["vars"]["_shared_reads"] + got = _value(tmp_path, "{{ _shared_reads | to_json }}", host_vars, {"_shared_reads": shared_reads}) + authentik = [e for e in got if e["from_service"] == "authentik"] + smtp = [e for e in got if e["from_service"] == "smtp"] + assert authentik == ( + [{"from_service": "authentik", "read_keys": ["plane_oidc_client_secret"]}] if auth else [] + ) + assert smtp == ([{"from_service": "smtp", "read_keys": ["plane_smtp_token"]}] if mail else []) + assert len(got) == int(auth) + int(mail) + + +# ── The worker and the test mail (Phase 4 local mail check) ────────────────── + + +def _container(name: str, service: str) -> dict: + return {"Names": [name], "Labels": {"com.docker.compose.service": service}} + + +WORKER_CASES = [ + ( + "one worker beside beat-worker", + [_container("plane_worker_1", "worker"), _container("plane_beat-worker_1", "beat-worker")], + True, + ["plane_worker_1"], + ), + ("the name is not the selector", [_container("plane_worker_10", "worker")], True, ["plane_worker_10"]), + ( + "a worker2 service beside the worker", + [_container("plane_worker2_1", "worker2"), _container("plane_worker_1", "worker")], + True, + ["plane_worker_1"], + ), + ("no worker", [_container("plane_beat-worker_1", "beat-worker")], False, []), + ("no containers", [], False, []), + ( + "two workers", + [_container("plane_worker_1", "worker"), _container("plane_worker_2", "worker")], + False, + ["plane_worker_1", "plane_worker_2"], + ), + ("a worker without a compose label", [{"Names": ["plane_worker_1"]}], False, []), +] + + +@pytest.mark.parametrize(("label", "containers", "passes", "names"), WORKER_CASES, ids=[c[0] for c in WORKER_CASES]) +def test_exactly_one_worker_is_selected_by_its_compose_service_label(tmp_path, label, containers, passes, names): + play_vars = {**_play(PHASE4)["vars"], "_plane_ps": {"stdout": json.dumps(containers)}} + assert _value(tmp_path, "{{ _plane_worker_names | to_json }}", {}, play_vars) == names + r = _run(tmp_path, {}, play_vars, [_task(_play(PHASE4), WORKER_ASSERT)]) + assert (r.returncode == 0) is passes, r.stdout + r.stderr + if not passes: + assert f"found {len(names)}" in r.stdout + + +SEND_CASES = [ + ( + "the exact success line", + ["printf", "%s\n", "Trying to send test email...", "Email successfully sent"], + True, + ), + ( + "an error line with exit 0", + ["printf", "%s\n", "Error: Email could not be delivered due to x"], + False, + ), + ( + "a line that only contains the success text", + ["printf", "%s\n", "Not: Email successfully sent yet"], + False, + ), + ( + "the success line with exit 1", + ["sh", "-c", "echo 'Email successfully sent'; exit 1"], + False, + ), +] + + +@pytest.mark.parametrize(("label", "argv", "passes"), SEND_CASES, ids=[c[0] for c in SEND_CASES]) +def test_the_test_mail_is_judged_by_its_exact_success_line_and_its_exit_status(tmp_path, label, argv, passes): + task = _task(_play(PHASE4), SEND) + task["ansible.builtin.command"] = {"argv": argv} + r = _run(tmp_path, {}, {}, [task]) + assert (r.returncode == 0) is passes, r.stdout + r.stderr + + +def test_the_since_time_is_the_fixed_utc_form_the_catcher_check_accepts(tmp_path): + out = tmp_path / "since.txt" + copy_task = {"ansible.builtin.copy": {"content": "{{ _plane_mail_since }}", "dest": str(out)}} + r = _run(tmp_path, {}, _play(PHASE4)["vars"], [_task(_play(PHASE4), MARK), copy_task]) + assert r.returncode == 0, r.stdout + r.stderr + assert re.fullmatch(r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ", out.read_text()) + + +# ── Static: the shape of the plays and the block ───────────────────────────── + + +def test_every_play_that_renders_a_mail_setting_starts_with_the_guard(): + plays = {p["name"]: p for p in playbook_yaml.load(DEPLOY) if "tasks" in p} + mail_plays = sorted(name for name, p in plays.items() if "smtp_" in json.dumps(p)) + assert mail_plays == sorted([PHASE1, PHASE3, PHASE4]) + for name in mail_plays: + first = plays[name]["tasks"][0] + assert first.get("name") == GUARD, name + assert first.get("ansible.builtin.include_tasks") == GUARD_FILE, name + + +def test_the_local_mail_check_follows_the_containers_check_and_precedes_the_report(): + tasks = _play(PHASE4)["tasks"] + names = [t.get("name") for t in tasks] + assert names.index(CONTAINERS_STABLE) < names.index(MAIL_BLOCK) < names.index("Report") + assert names[-1] == RECORD + + +def test_the_mail_block_is_gated_and_runs_its_tasks_in_order_without_no_log(): + block = _task(_play(PHASE4), MAIL_BLOCK) + assert block["when"] == MAIL_ON_WHEN + inner = [t.get("name") for t in block["block"]] + assert inner == [FIND, WORKER_ASSERT, MARK, SEND, CATCHER] + assert not any(t.get("no_log") for t in block["block"]) + + +def test_the_catcher_check_reads_the_mailpit_api_and_this_runs_since_the_mark(): + catcher = _task(_play(PHASE4), CATCHER) + assert catcher["ansible.builtin.include_tasks"] == "tasks/assert-mail-captured.yml" + assert catcher["vars"]["mail_captured_api_url"] == "http://mailpit:8025" + assert catcher["vars"]["mail_captured_since"] == "{{ _plane_mail_since }}" + assert catcher["vars"]["mail_captured_subject"] == "Test email" + + +def test_the_local_worker_joins_the_local_dev_network_for_the_catcher(): + compose = yaml.safe_load(COMPOSE_LOCAL.read_text()) + assert "local-dev" in compose["services"]["worker"]["networks"] From d78913d2b16991fe77ffa0ecd9e198476c7f7d69 Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 14:45:35 -0500 Subject: [PATCH 03/11] docs(plane): describe outbound mail in the Plane notes and the AGENTS.md rows [AC-1127] The Plane deployment notes gain an Outbound mail section: the settings written, the mail-on gate, the token path, and the local verification. AGENTS.md records that Deploy Plane now reads plane_smtp_token through _shared_reads while mail is on, and that the Authentik and Grafana deploys do not read theirs yet. --- AGENTS.md | 4 +-- platform/services/plane/deployment/CLAUDE.md | 27 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 53f2a914d..af66f9dc7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -250,7 +250,7 @@ Services provision their own AppRoles via `tasks/manage-approle.yml` — no need | `secret/services/postiz` | postiz signing secret + its Postgres password + the Temporal Postgres password (all generated once and reused — a new signing secret invalidates every session AND every API key), plus the operator's social-platform application credentials seeded by `seed-postiz-secrets.yml`; the OIDC client secret is shared-read from `authentik` | | `secret/services/plane` | Plane's generated-once secrets: signing keys (`plane_secret_key`, live, silo HMAC, AES, Pi internal, Cursor webhook), the Postgres, RabbitMQ and MinIO passwords, `plane_machine_signature` (the licence binds to it; never rotated) `plane_automation_password` for the first instance admin, and `plane_service_token`, the workspace service token Deploy Plane mints for `/api/v1` (Sync Plane Projects reads it; it does not expire, and Plane has no route to revoke it), and `plane_mcp_client_id` / `plane_mcp_client_secret` for the MCP server's OAuth application (written by Deploy Plane MCP; Plane shows the secret only at create or regenerate). GitHub integration: `plane_github_client_secret` and `plane_github_private_key` (base64 of the PEM, one line), the operator's, seeded with `Seed OpenBao Key` and required while `plane_github_app_id` is declared; `plane_github_webhook_secret`, generated once and set on the App by Deploy Plane | | `secret/services/github-runner` | GitHub App private key (`app_private_key`) for the org runner-automation App. The App's OAuth client secret is NOT used and is not stored; the client id is the JWT issuer and is not secret. Read only by the orchestrator — a runner host is denied OpenBao by its own firewall declaration and never holds this | -| `secret/services/smtp` | Outbound mail: `authentik_smtp_token`, `plane_smtp_token` and `grafana_smtp_token`. One shared mail token today, with a field per service so it can be split later (plan 29). The Authentik, Plane and Grafana deploys are to read them through `_shared_reads` (plan 29, units S4, S6 and S7); no deploy reads them yet. Local-dev seeds each field with a `LOCAL_FAKE__placeholder` value; the production value is placed by the operator, never generated | +| `secret/services/smtp` | Outbound mail: `authentik_smtp_token`, `plane_smtp_token` and `grafana_smtp_token`. One shared mail token today, with a field per service so it can be split later (plan 29). Deploy Plane reads `plane_smtp_token` through `_shared_reads` while mail is on. The Authentik and Grafana deploys are to read theirs the same way (plan 29, units S4 and S7); they do not yet. Local-dev seeds each field with a `LOCAL_FAKE__placeholder` value; the production value is placed by the operator, never generated | ## Composable Task Library @@ -333,7 +333,7 @@ Each deployment concern is its own playbook — independently runnable and retry | Deploy Postiz | `deploy-postiz.yml` | Social publishing (rootless podman, 5 containers + the inventory-gated search node `compose.search.yml`, required as of v2.23.0 — the backend registers >3 Text search attributes and SQL visibility caps at 3): secrets (+OIDC shared-read) → render BOTH env files → deploy.sh → verify app AND workflow engine | | Store Postiz API Key | `store-postiz-api-key.yml` | Capture the app-minted `/api/public/v1` key (the DB column IS the bearer value; minted on first sign-in) into `secret/services/postiz:postiz_api_key` — read from the service's own Postgres, never printed, all key-bearing steps `no_log`. | | Clean Deploy Postiz | `clean-deploy-postiz.yml` | Destructive: wipe containers + all four volumes + fresh deploy (social accounts need re-authorizing by hand afterwards) | -| Deploy Plane | `deploy-plane.yml` | Work tracker (rootless podman, Commercial edition): fetch Plane's Compose and variables files for the pinned release and verify each sha256 (never committed) → secrets + `.env` (refuses Plane's shipped default credentials) → deploy.sh with `compose.agentcloud.yml`, the proxy held until the instance is set up → first-run configuration (setup, invitation-only sign-up, workspace) → verify through the proxy. With `plane_github_app_id` declared it also renders the GitHub App settings (all six or none), sets the App's webhook URL and secret from the controller, and verifies an unsigned delivery is refused 401 | +| Deploy Plane | `deploy-plane.yml` | Work tracker (rootless podman, Commercial edition): fetch Plane's Compose and variables files for the pinned release and verify each sha256 (never committed) → secrets + `.env` (refuses Plane's shipped default credentials) → deploy.sh with `compose.agentcloud.yml`, the proxy held until the instance is set up → first-run configuration (setup, invitation-only sign-up, workspace) → verify through the proxy. With `plane_github_app_id` declared it also renders the GitHub App settings (all six or none), sets the App's webhook URL and secret from the controller, and verifies an unsigned delivery is refused 401. With `smtp_host` set it also writes Plane's outbound mail settings from the inventory and the mail token from `secret/services/smtp`; on local-dev it sends a test mail from the Plane worker and checks the local mail catcher | | Clean Deploy Plane | `clean-deploy-plane.yml` | Destructive: remove every container and named volume and deploy fresh; secrets return from OpenBao, all workspaces and work items are gone | | Back Up Plane DB | `backup-plane-db.yml` | Timestamped pg_dump of `plane-db` into an owner-only (0700) dir on the VM; read-only against the database, each run a NEW file. The database only; uploads are covered by a VM snapshot | | Restore Plane DB | `restore-plane-db.yml` | DESTRUCTIVE: restore a named dump (`-e plane_dump_file=` REQUIRED) into a staging database, swap it in only after it fully loads (prior kept as `plane_prev`), and bring the stack back through deploy.sh in an `always:` block, which reruns the migrator | diff --git a/platform/services/plane/deployment/CLAUDE.md b/platform/services/plane/deployment/CLAUDE.md index 94eeda8e0..a77700d0f 100644 --- a/platform/services/plane/deployment/CLAUDE.md +++ b/platform/services/plane/deployment/CLAUDE.md @@ -140,6 +140,33 @@ identical on every install. `env.j2` refuses to render if any of them comes out equal to the shipped value. Note the RabbitMQ trap: Plane's Compose reads `RABBITMQ_PASSWORD`, not the `RABBITMQ_DEFAULT_PASS` its `variables.env` sets, so both are written. +## Outbound mail + +With `smtp_host` set in the inventory, the deploy also sends Plane's mail through the platform SMTP +service (AC-1127). It writes these instance settings, and only these: `ENABLE_SMTP` as `1`, +`EMAIL_HOST` from `smtp_host`, `EMAIL_PORT` from `smtp_port`, `EMAIL_HOST_USER` from `smtp_username`, +`EMAIL_HOST_PASSWORD` from the mail token, `EMAIL_USE_TLS` as `1` unless `smtp_starttls` is false, +`EMAIL_USE_SSL` as `0`, and `EMAIL_FROM` from `smtp_from_address`. Every value is a string, so a rerun +with the same inventory patches nothing. + +The token is read from `secret/services/smtp:plane_smtp_token` through `_shared_reads`, and only while +mail is on. A listed read of a missing key fails the run before Phase 3 reaches the mail settings. The +token goes on the stdin of the configuration task, which is `no_log`, as the OIDC secret does. + +With `smtp_host` unset, `false`, `0`, blank or null, mail is off. No mail key is sent, nothing is +cleared, and Plane's disable endpoint is not called, so Plane keeps the settings it already has. The SMTP +guard (`tasks/assert-smtp-settings.yml`) is the first task of Phases 1, 3 and 4. + +Local verification runs in Phase 4 on local-dev only, with mail on. It finds the one running Plane worker +by its compose service label, sends a test mail from it to `smtp_from_address` with +`python manage.py test_email`, and requires the exact line `Email successfully sent`, because +`test_email` exits 0 even when delivery fails. It then checks the Mailpit catcher for a message to that +address with subject `Test email` created since just before the send. The worker joins `local-dev` in +`compose.local.yml` so it can reach `mailpit:1025`. + +Only outbound mail is covered here. The inbound `email` service stays disabled by its profile. Production +mail stays off until an inventory names `smtp_host`, which this change does not do. + ## First run closes the instance Until the first admin signs up, **anyone who reaches `/god-mode/` claims the instance**. The From 210720ad18c8b7831c0dba3739f9a80eab629084 Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 14:53:37 -0500 Subject: [PATCH 04/11] refactor(plane): drop Phase 4 deploy-dir vars the container listing already sets [AC-1127] The Phase 4 play defined _monorepo_dir and _deploy_dir as play vars. No task in the play reads _monorepo_dir. The one task that reads _deploy_dir gets it from the fact that tasks/list-service-containers.yml sets earlier in the play, during the containers-stable check, so the play vars were not needed. The one remaining reader gets a comment naming where the fact comes from. --- platform/playbooks/deploy-plane.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform/playbooks/deploy-plane.yml b/platform/playbooks/deploy-plane.yml index dc64730ec..4b6ac70da 100644 --- a/platform/playbooks/deploy-plane.yml +++ b/platform/playbooks/deploy-plane.yml @@ -622,8 +622,6 @@ become: false vars: _engine: "{{ container_engine | default('podman') }}" - _monorepo_dir: "{{ local_monorepo_dir | default('/home/' ~ (ansible_user | default('deploy')) ~ '/agent-cloud') }}" - _deploy_dir: "{{ _monorepo_dir }}/{{ monorepo_deploy_path }}" # The names of the running containers whose compose service label is exactly `worker` # (not beat-worker, not a worker2). Read from the `podman ps` the local mail check registers. _plane_worker_names: >- @@ -737,6 +735,7 @@ - groups['all'] | local_dev_inventory - not ansible_check_mode block: + # _deploy_dir is the fact tasks/list-service-containers.yml set for the containers-stable check above. - name: "Find the Plane worker container (local mail check)" ansible.builtin.command: argv: From 5c569f2b6d36c0abf54c583e25b82622f07dc040 Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 15:03:26 -0500 Subject: [PATCH 05/11] test(plane): batch the outbound mail cases into one ansible run per group [AC-1127] Each group of Plane's outbound mail cases now runs as one ansible-playbook run instead of one run per case. The Phase 3 mail settings and the converge stdin, the Phase 1 listed reads, the worker selection and the test-mail judgement each run once over one host per case. Every case still has its own test, and that test reads only its own host's result, so a red case names itself. The file went from 41 ansible-playbook runs to 4, and its run time from about 29 seconds to about 7 seconds. The mail-off converge test is folded into the converge test, parametrised over mail on and mail off. The converge test now checks the exact settings each stdin renders, in place of a second run that compared against a combined rendering. The send group's run also marks the time before the test mail, so the since-time test reads that value from the same run. Every case and near-miss from before keeps a test, and the static tests still read the playbook without running it. --- platform/tests/test_plane_outbound_mail.py | 324 +++++++++++++-------- 1 file changed, 201 insertions(+), 123 deletions(-) diff --git a/platform/tests/test_plane_outbound_mail.py b/platform/tests/test_plane_outbound_mail.py index 5a1f97f2b..2c43b823d 100644 --- a/platform/tests/test_plane_outbound_mail.py +++ b/platform/tests/test_plane_outbound_mail.py @@ -1,11 +1,15 @@ """Plane's outbound mail (AC-1127), tested from deploy-plane.yml itself. The expressions and tasks below are read from the playbook's YAML, never copied, so a red test -names the playbook's own text. Jinja runs under ansible-playbook on localhost through harness_sandbox. -Three things are stubbed: the worker listing (a `_plane_ps` play var stands in for `podman ps`), the -test-mail command (its argv is replaced by printf), and the mail catcher (not called here). Every value -is a placeholder: example.test addresses and a fake token. Nothing here reaches a container, a mail -server or the network. +names the playbook's own text. They run under ansible-playbook on localhost through harness_sandbox, +and each group of cases is one run: every case is a host with its own inventory vars, each host +writes what its tasks render to a file in the run's out directory, and a test reads only its own +host's file, so a red case still names itself. + +Three things are stubbed: the worker listing (a `_plane_ps` host var stands in for `podman ps`), the +test-mail command (a `send_argv` host var replaces its argv with printf or sh), and the mail catcher +(not called here). Every value is a placeholder: example.test addresses and a fake token. Nothing +here reaches a container, a mail server or the network. """ import copy @@ -43,6 +47,8 @@ ] FAKE_TOKEN = "tok-example-not-real" UNSET = object() +# What the mail-settings host renders: the Phase 3 expression, as the playbook writes it. +MAIL_EXPR = "{{ _plane_mail_settings | to_json }}" # The five inventory names as local-dev sets them, with a mail host that is on. MAIL = { @@ -53,8 +59,72 @@ "smtp_from_address": "noreply@example.test", } MAIL_OTHER = {k: v for k, v in MAIL.items() if k != "smtp_host"} -OFF_HOST_VARS = [{}, {"smtp_host": False}, {"smtp_host": 0}, {"smtp_host": ""}, {"smtp_host": None}] +NO_STARTTLS = {k: v for k, v in MAIL.items() if k != "smtp_starttls"} +# The eight settings mail on writes. Every value is a string, so the port is "587", never 587. +MAIL_SETTINGS = { + "ENABLE_SMTP": "1", + "EMAIL_HOST": "mail.example.test", + "EMAIL_PORT": "587", + "EMAIL_HOST_USER": "plane-mail@example.test", + "EMAIL_HOST_PASSWORD": FAKE_TOKEN, + "EMAIL_USE_TLS": "1", + "EMAIL_USE_SSL": "0", + "EMAIL_FROM": "noreply@example.test", +} AUTH = {"plane_authentik_base": "https://auth.example.test:8443"} +# The inventory vars the converge stdin reads, besides the mail names. +CONVERGE_BASE = { + "plane_public_url": "https://plane.example.test", + "plane_automation_email": "automation@example.test", + "plane_company_name": "Example Co", + "plane_workspace_slug": "example", + "plane_workspace_name": "Example", +} + + +# Group (a), Phase 3: mail is off for every spelling of "not set", and on for the rest. +MAIL_OFF_HOSTS = { + "off-unset": {}, + "off-false": {"smtp_host": False}, + "off-zero": {"smtp_host": 0}, + "off-blank": {"smtp_host": ""}, + "off-null": {"smtp_host": None}, +} +# smtp_starttls as the inventory gives it (UNSET: not given), and the EMAIL_USE_TLS it must map to. +STARTTLS_HOSTS = { + "starttls-bool-true": (True, "1"), + "starttls-str-true": ("true", "1"), + "starttls-str-capitalised-true": ("True", "1"), + "starttls-unset": (UNSET, "1"), + "starttls-bool-false": (False, "0"), + "starttls-str-false": ("false", "0"), + "starttls-str-capitalised-false": ("False", "0"), +} + + +def _starttls_host(tls) -> dict: + return dict(NO_STARTTLS) if tls is UNSET else {**NO_STARTTLS, "smtp_starttls": tls} + + +MAIL_HOSTS = { + **{host: {**MAIL_OTHER, **extra} for host, extra in MAIL_OFF_HOSTS.items()}, + "on": MAIL, + "port-int": {**MAIL, "smtp_port": 1025}, + "port-str": {**MAIL, "smtp_port": "1025"}, + **{host: _starttls_host(tls) for host, (tls, _) in STARTTLS_HOSTS.items()}, +} +# Group (a), converge: the stdin the converge task sends, rendered for a host with the base Plane vars. +CONVERGE_HOSTS = { + "converge-mail-on": {**CONVERGE_BASE, **MAIL}, + "converge-mail-off": {**CONVERGE_BASE}, +} +# Group (b): the listed reads for each combination of authentik and mail, as (authentik, mail). +SHARED_READ_CASES = { + "authentik-off-mail-off": (False, False), + "authentik-off-mail-on": (False, True), + "authentik-on-mail-off": (True, False), + "authentik-on-mail-on": (True, True), +} def _play(name: str) -> dict: @@ -71,133 +141,113 @@ def _phase3_vars() -> dict: return {**_play(PHASE3)["vars"], "_shared": {"plane_smtp_token": FAKE_TOKEN}} -def _run(tmp: Path, host_vars: dict, play_vars: dict, tasks: list, host: str = "plane"): - inv = {"all": {"hosts": {host: {"ansible_connection": "local", **host_vars}}}} - (tmp / "inv.yml").write_text(yaml.safe_dump(inv)) - (tmp / "play.yml").write_text( - yaml.safe_dump([{"hosts": "all", "gather_facts": False, "vars": play_vars, "tasks": tasks}]) - ) - return harness_sandbox.run( - ["ansible-playbook", "-i", str(tmp / "inv.yml"), str(tmp / "play.yml")], - tmp, - cwd=REPO, - env=harness_sandbox.env_for(tmp), - ) +def _host(case: str) -> str: + """A plain host name for a case: its label in lower case, each run of other characters a hyphen.""" + return re.sub(r"[^a-z0-9]+", "-", case.lower()).strip("-") + + +def _emit(content: str) -> dict: + """A task that writes `content`, rendered for this host, to the run's out directory as .json.""" + return {"ansible.builtin.copy": {"content": content, "dest": "{{ out_dir }}/{{ inventory_hostname }}.json"}} -def _value(tmp: Path, expr: str, host_vars: dict, play_vars: dict, host: str = "plane"): - """The JSON value of a Jinja expression, evaluated by ansible-playbook on a real play.""" - out = tmp / "value.json" - copy_task = {"ansible.builtin.copy": {"content": expr, "dest": str(out)}} - r = _run(tmp, host_vars, play_vars, [copy_task], host) - assert r.returncode == 0, r.stdout + r.stderr - return json.loads(out.read_text()) +class _Batch: + """A finished run: the output of ansible-playbook, and the JSON each host wrote to the out directory.""" + def __init__(self, out: Path, run) -> None: + self.out = out + self.run = run -def _mail_settings(tmp: Path, host_vars: dict) -> dict: - return _value(tmp, "{{ _plane_mail_settings | to_json }}", host_vars, _phase3_vars()) + def result(self, host: str): + path = self.out / f"{host}.json" + assert path.exists(), f"host {host} wrote no result\n{self.run.stdout}{self.run.stderr}" + return json.loads(path.read_text()) + + +def _batch(tmp: Path, hosts: dict, play_vars: dict, tasks: list) -> _Batch: + """One ansible-playbook run of one play over every host. A host's own vars are its case; the play + vars and the tasks are shared. The exit status is not asserted here: a host that failed writes no + result, and its own case reports that with the run's output.""" + out = tmp / "out" + out.mkdir() + inventory = {"all": {"hosts": {name: {"ansible_connection": "local", **hv} for name, hv in hosts.items()}}} + (tmp / "inv.yml").write_text(yaml.safe_dump(inventory)) + play = {"hosts": "all", "gather_facts": False, "vars": {**play_vars, "out_dir": str(out)}, "tasks": tasks} + (tmp / "play.yml").write_text(yaml.safe_dump([play])) + run = harness_sandbox.run_playbook(tmp / "play.yml", tmp, inventory=tmp / "inv.yml") + return _Batch(out, run) # ── What Plane is told (Phase 3) ───────────────────────────────────────────── -@pytest.mark.parametrize("host_vars", OFF_HOST_VARS) -def test_mail_is_off_when_smtp_host_is_unset_false_zero_blank_or_null(tmp_path, host_vars): - assert _mail_settings(tmp_path, {**MAIL_OTHER, **host_vars}) == {} +@pytest.fixture(scope="module") +def mail_batch(tmp_path_factory): + """Group (a): every Phase 3 mail case and both converge stdins, one run.""" + stdin = _task(_play(PHASE3), CONVERGE)["ansible.builtin.command"]["stdin"] + hosts = {host: {**hv, "_probe": MAIL_EXPR} for host, hv in MAIL_HOSTS.items()} + hosts |= {host: {**hv, "_probe": stdin} for host, hv in CONVERGE_HOSTS.items()} + play_vars = {**_phase3_vars(), "_resolved": {"plane_automation_password": "pw-example-not-real"}} + return _batch(tmp_path_factory.mktemp("mail-settings"), hosts, play_vars, [_emit("{{ _probe }}")]) -def test_mail_on_writes_exactly_the_eight_settings_and_every_value_is_a_string(tmp_path): - got = _mail_settings(tmp_path, MAIL) - assert got == { - "ENABLE_SMTP": "1", - "EMAIL_HOST": "mail.example.test", - "EMAIL_PORT": "587", - "EMAIL_HOST_USER": "plane-mail@example.test", - "EMAIL_HOST_PASSWORD": FAKE_TOKEN, - "EMAIL_USE_TLS": "1", - "EMAIL_USE_SSL": "0", - "EMAIL_FROM": "noreply@example.test", - } - assert all(isinstance(v, str) for v in got.values()) +@pytest.mark.parametrize("host", list(MAIL_OFF_HOSTS)) +def test_mail_is_off_when_smtp_host_is_unset_false_zero_blank_or_null(mail_batch, host): + assert mail_batch.result(host) == {} -@pytest.mark.parametrize("port", [1025, "1025"]) -def test_the_port_is_a_string_whether_the_inventory_gives_an_int_or_a_string(tmp_path, port): - assert _mail_settings(tmp_path, {**MAIL, "smtp_port": port})["EMAIL_PORT"] == "1025" +def test_mail_on_writes_exactly_the_eight_settings_and_every_value_is_a_string(mail_batch): + assert mail_batch.result("on") == MAIL_SETTINGS -@pytest.mark.parametrize( - ("starttls", "expected"), - [ - (True, "1"), - ("true", "1"), - ("True", "1"), - (UNSET, "1"), - (False, "0"), - ("false", "0"), - ("False", "0"), - ], -) -def test_starttls_maps_to_tls_as_a_string_for_every_spelling(tmp_path, starttls, expected): - host = {k: v for k, v in MAIL.items() if k != "smtp_starttls"} - if starttls is not UNSET: - host["smtp_starttls"] = starttls - got = _mail_settings(tmp_path, host) - assert got["EMAIL_USE_TLS"] == expected +@pytest.mark.parametrize("host", ["port-int", "port-str"]) +def test_the_port_is_a_string_whether_the_inventory_gives_an_int_or_a_string(mail_batch, host): + assert mail_batch.result(host)["EMAIL_PORT"] == "1025" + + +@pytest.mark.parametrize(("host", "tls"), [pytest.param(h, tls, id=h) for h, (_, tls) in STARTTLS_HOSTS.items()]) +def test_starttls_maps_to_tls_as_a_string_for_every_spelling(mail_batch, host, tls): + got = mail_batch.result(host) + assert got["EMAIL_USE_TLS"] == tls # SSL is never on: Plane's TLS and SSL are exclusive, and the catcher and the relay both use STARTTLS. assert got["EMAIL_USE_SSL"] == "0" -def test_the_converge_stdin_carries_the_oidc_settings_combined_with_the_mail_settings(tmp_path): +@pytest.mark.parametrize( + ("host", "expected"), + [ + ("converge-mail-on", {"IS_OIDC_ENABLED": "0", **MAIL_SETTINGS}), + ("converge-mail-off", {"IS_OIDC_ENABLED": "0"}), + ], +) +def test_the_converge_stdin_carries_the_oidc_settings_and_the_mail_settings_only_while_mail_is_on( + mail_batch, host, expected +): task = _task(_play(PHASE3), CONVERGE) assert "_plane_oidc_settings | combine(_plane_mail_settings)" in task["ansible.builtin.command"]["stdin"] - base = { - "plane_public_url": "https://plane.example.test", - "plane_automation_email": "automation@example.test", - "plane_company_name": "Example Co", - "plane_workspace_slug": "example", - "plane_workspace_name": "Example", - } - play_vars = {**_phase3_vars(), "_resolved": {"plane_automation_password": "pw-example-not-real"}} - got = _value(tmp_path, task["ansible.builtin.command"]["stdin"], {**base, **MAIL}, play_vars)["settings"] - combined = _value( - tmp_path, - "{{ (_plane_oidc_settings | combine(_plane_mail_settings)) | to_json }}", - {**base, **MAIL}, - play_vars, - ) - assert got == combined - assert got["ENABLE_SMTP"] == "1" and got["IS_OIDC_ENABLED"] == "0" + assert mail_batch.result(host)["settings"] == expected -def test_with_mail_off_the_converge_stdin_sends_no_mail_key(tmp_path): - task = _task(_play(PHASE3), CONVERGE) - base = { - "plane_public_url": "https://plane.example.test", - "plane_automation_email": "automation@example.test", - "plane_company_name": "Example Co", - "plane_workspace_slug": "example", - "plane_workspace_name": "Example", - } - play_vars = {**_phase3_vars(), "_resolved": {"plane_automation_password": "pw-example-not-real"}} - got = _value(tmp_path, task["ansible.builtin.command"]["stdin"], base, play_vars)["settings"] - assert got == {"IS_OIDC_ENABLED": "0"} +# ── What the deploy reads (Phase 1) ────────────────────────────────────────── -# ── What the deploy reads (Phase 1) ────────────────────────────────────────── +@pytest.fixture(scope="module") +def shared_batch(tmp_path_factory): + """Group (b): the Phase 1 listed reads for every combination of authentik and mail, one run.""" + hosts = { + host: {**(AUTH if auth else {}), **(MAIL if mail else {})} for host, (auth, mail) in SHARED_READ_CASES.items() + } + play_vars = {"_shared_reads": _play(PHASE1)["vars"]["_shared_reads"]} + return _batch(tmp_path_factory.mktemp("shared-reads"), hosts, play_vars, [_emit("{{ _shared_reads | to_json }}")]) -@pytest.mark.parametrize("auth", [False, True]) -@pytest.mark.parametrize("mail", [False, True]) -def test_the_token_is_a_listed_read_only_while_mail_is_on(tmp_path, auth, mail): - host_vars = {**(AUTH if auth else {}), **(MAIL if mail else {})} - shared_reads = _play(PHASE1)["vars"]["_shared_reads"] - got = _value(tmp_path, "{{ _shared_reads | to_json }}", host_vars, {"_shared_reads": shared_reads}) +@pytest.mark.parametrize("host", list(SHARED_READ_CASES)) +def test_the_token_is_a_listed_read_only_while_mail_is_on(shared_batch, host): + auth, mail = SHARED_READ_CASES[host] + got = shared_batch.result(host) authentik = [e for e in got if e["from_service"] == "authentik"] smtp = [e for e in got if e["from_service"] == "smtp"] - assert authentik == ( - [{"from_service": "authentik", "read_keys": ["plane_oidc_client_secret"]}] if auth else [] - ) + assert authentik == ([{"from_service": "authentik", "read_keys": ["plane_oidc_client_secret"]}] if auth else []) assert smtp == ([{"from_service": "smtp", "read_keys": ["plane_smtp_token"]}] if mail else []) assert len(got) == int(auth) + int(mail) @@ -235,14 +285,32 @@ def _container(name: str, service: str) -> dict: ] -@pytest.mark.parametrize(("label", "containers", "passes", "names"), WORKER_CASES, ids=[c[0] for c in WORKER_CASES]) -def test_exactly_one_worker_is_selected_by_its_compose_service_label(tmp_path, label, containers, passes, names): - play_vars = {**_play(PHASE4)["vars"], "_plane_ps": {"stdout": json.dumps(containers)}} - assert _value(tmp_path, "{{ _plane_worker_names | to_json }}", {}, play_vars) == names - r = _run(tmp_path, {}, play_vars, [_task(_play(PHASE4), WORKER_ASSERT)]) - assert (r.returncode == 0) is passes, r.stdout + r.stderr +@pytest.fixture(scope="module") +def worker_batch(tmp_path_factory): + """Group (c): the real worker selection and the real assert, one host per container listing, one run.""" + hosts = { + _host(label): {"_plane_ps": {"stdout": json.dumps(containers)}} for label, containers, _, _ in WORKER_CASES + } + assertion = _task(_play(PHASE4), WORKER_ASSERT) + assertion |= {"register": "_plane_assert", "ignore_errors": True} + probe = ( + "{{ {'names': _plane_worker_names," + " 'failed': _plane_assert is failed," + " 'msg': _plane_assert.msg | default('')} | to_json }}" + ) + return _batch(tmp_path_factory.mktemp("worker"), hosts, _play(PHASE4)["vars"], [assertion, _emit(probe)]) + + +@pytest.mark.parametrize( + ("host", "passes", "names"), + [pytest.param(_host(label), passes, names, id=label) for label, _, passes, names in WORKER_CASES], +) +def test_exactly_one_worker_is_selected_by_its_compose_service_label(worker_batch, host, passes, names): + got = worker_batch.result(host) + assert got["names"] == names + assert (not got["failed"]) is passes, got if not passes: - assert f"found {len(names)}" in r.stdout + assert f"found {len(names)}" in got["msg"], got SEND_CASES = [ @@ -269,20 +337,30 @@ def test_exactly_one_worker_is_selected_by_its_compose_service_label(tmp_path, l ] -@pytest.mark.parametrize(("label", "argv", "passes"), SEND_CASES, ids=[c[0] for c in SEND_CASES]) -def test_the_test_mail_is_judged_by_its_exact_success_line_and_its_exit_status(tmp_path, label, argv, passes): - task = _task(_play(PHASE4), SEND) - task["ansible.builtin.command"] = {"argv": argv} - r = _run(tmp_path, {}, {}, [task]) - assert (r.returncode == 0) is passes, r.stdout + r.stderr +@pytest.fixture(scope="module") +def send_batch(tmp_path_factory): + """Group (d): the real send task judged on each stub, and the time the mail check marks, one run.""" + hosts = {_host(label): {"send_argv": argv} for label, argv, _ in SEND_CASES} + send = _task(_play(PHASE4), SEND) + send["ansible.builtin.command"] = {"argv": "{{ send_argv }}"} + send |= {"ignore_errors": True} + probe = "{{ {'failed': _plane_test_mail is failed, 'since': _plane_mail_since} | to_json }}" + tasks = [_task(_play(PHASE4), MARK), send, _emit(probe)] + return _batch(tmp_path_factory.mktemp("send"), hosts, {}, tasks) + + +@pytest.mark.parametrize( + ("host", "passes"), + [pytest.param(_host(label), passes, id=label) for label, _, passes in SEND_CASES], +) +def test_the_test_mail_is_judged_by_its_exact_success_line_and_its_exit_status(send_batch, host, passes): + assert (not send_batch.result(host)["failed"]) is passes -def test_the_since_time_is_the_fixed_utc_form_the_catcher_check_accepts(tmp_path): - out = tmp_path / "since.txt" - copy_task = {"ansible.builtin.copy": {"content": "{{ _plane_mail_since }}", "dest": str(out)}} - r = _run(tmp_path, {}, _play(PHASE4)["vars"], [_task(_play(PHASE4), MARK), copy_task]) - assert r.returncode == 0, r.stdout + r.stderr - assert re.fullmatch(r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ", out.read_text()) +def test_the_since_time_is_the_fixed_utc_form_the_catcher_check_accepts(send_batch): + for label, _, _ in SEND_CASES: + since = send_batch.result(_host(label))["since"] + assert re.fullmatch(r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ", since), since # ── Static: the shape of the plays and the block ───────────────────────────── From c8c6cdb59c901bcd9770dad79bc100b49ed8a0df Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 15:10:15 -0500 Subject: [PATCH 06/11] test(plane): prove the stubbed test-mail command ran before judging it [AC-1127] Each send case now also checks the stub's exit status and output lines, so a case that judges a failed send can no longer pass because the command never ran. The mail block's gate is compared as a set of conditions, so reordering them is not a failure. --- platform/tests/test_plane_outbound_mail.py | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/platform/tests/test_plane_outbound_mail.py b/platform/tests/test_plane_outbound_mail.py index 2c43b823d..1f9093e56 100644 --- a/platform/tests/test_plane_outbound_mail.py +++ b/platform/tests/test_plane_outbound_mail.py @@ -314,24 +314,33 @@ def test_exactly_one_worker_is_selected_by_its_compose_service_label(worker_batc SEND_CASES = [ + # label, stub argv, its rc, its stdout lines, whether the send passes ( "the exact success line", ["printf", "%s\n", "Trying to send test email...", "Email successfully sent"], + 0, + ["Trying to send test email...", "Email successfully sent"], True, ), ( "an error line with exit 0", ["printf", "%s\n", "Error: Email could not be delivered due to x"], + 0, + ["Error: Email could not be delivered due to x"], False, ), ( "a line that only contains the success text", ["printf", "%s\n", "Not: Email successfully sent yet"], + 0, + ["Not: Email successfully sent yet"], False, ), ( "the success line with exit 1", ["sh", "-c", "echo 'Email successfully sent'; exit 1"], + 1, + ["Email successfully sent"], False, ), ] @@ -340,25 +349,31 @@ def test_exactly_one_worker_is_selected_by_its_compose_service_label(worker_batc @pytest.fixture(scope="module") def send_batch(tmp_path_factory): """Group (d): the real send task judged on each stub, and the time the mail check marks, one run.""" - hosts = {_host(label): {"send_argv": argv} for label, argv, _ in SEND_CASES} + hosts = {_host(label): {"send_argv": argv} for label, argv, *_ in SEND_CASES} send = _task(_play(PHASE4), SEND) send["ansible.builtin.command"] = {"argv": "{{ send_argv }}"} send |= {"ignore_errors": True} - probe = "{{ {'failed': _plane_test_mail is failed, 'since': _plane_mail_since} | to_json }}" + probe = ( + "{{ {'failed': _plane_test_mail is failed, 'rc': _plane_test_mail.rc | default(none)," + " 'stdout_lines': _plane_test_mail.stdout_lines | default(none), 'since': _plane_mail_since} | to_json }}" + ) tasks = [_task(_play(PHASE4), MARK), send, _emit(probe)] return _batch(tmp_path_factory.mktemp("send"), hosts, {}, tasks) @pytest.mark.parametrize( - ("host", "passes"), - [pytest.param(_host(label), passes, id=label) for label, _, passes in SEND_CASES], + ("host", "rc", "lines", "passes"), + [pytest.param(_host(label), rc, lines, passes, id=label) for label, _, rc, lines, passes in SEND_CASES], ) -def test_the_test_mail_is_judged_by_its_exact_success_line_and_its_exit_status(send_batch, host, passes): - assert (not send_batch.result(host)["failed"]) is passes +def test_the_test_mail_is_judged_by_its_exact_success_line_and_its_exit_status(send_batch, host, rc, lines, passes): + got = send_batch.result(host) + # The stub ran and printed what the case says, so a failure is the judgement's, not a skipped command. + assert (got["rc"], got["stdout_lines"]) == (rc, lines) + assert (not got["failed"]) is passes def test_the_since_time_is_the_fixed_utc_form_the_catcher_check_accepts(send_batch): - for label, _, _ in SEND_CASES: + for label, *_ in SEND_CASES: since = send_batch.result(_host(label))["since"] assert re.fullmatch(r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ", since), since @@ -385,7 +400,7 @@ def test_the_local_mail_check_follows_the_containers_check_and_precedes_the_repo def test_the_mail_block_is_gated_and_runs_its_tasks_in_order_without_no_log(): block = _task(_play(PHASE4), MAIL_BLOCK) - assert block["when"] == MAIL_ON_WHEN + assert sorted(block["when"]) == sorted(MAIL_ON_WHEN) inner = [t.get("name") for t in block["block"]] assert inner == [FIND, WORKER_ASSERT, MARK, SEND, CATCHER] assert not any(t.get("no_log") for t in block["block"]) From c7e0a3102c87e424a9f16e83fd1cd6667afa4b51 Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 18:57:29 -0500 Subject: [PATCH 07/11] fix(plane): define Phase 4's deploy dir in the play again [AC-1127] Reverts 210720ad1. The local mail check reads _deploy_dir, which that commit left to the fact tasks/list-service-containers.yml sets inside the containers-stable include. The play-vars scope guard (test_play_vars_scope.py) does not scan included task files, so it read _deploy_dir as another play's var and failed CI on #1249 (Python 2/8). Defining it in Phase 4's own vars keeps the read visible to the guard and independent of the include's order. --- platform/playbooks/deploy-plane.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/playbooks/deploy-plane.yml b/platform/playbooks/deploy-plane.yml index 4b6ac70da..dc64730ec 100644 --- a/platform/playbooks/deploy-plane.yml +++ b/platform/playbooks/deploy-plane.yml @@ -622,6 +622,8 @@ become: false vars: _engine: "{{ container_engine | default('podman') }}" + _monorepo_dir: "{{ local_monorepo_dir | default('/home/' ~ (ansible_user | default('deploy')) ~ '/agent-cloud') }}" + _deploy_dir: "{{ _monorepo_dir }}/{{ monorepo_deploy_path }}" # The names of the running containers whose compose service label is exactly `worker` # (not beat-worker, not a worker2). Read from the `podman ps` the local mail check registers. _plane_worker_names: >- @@ -735,7 +737,6 @@ - groups['all'] | local_dev_inventory - not ansible_check_mode block: - # _deploy_dir is the fact tasks/list-service-containers.yml set for the containers-stable check above. - name: "Find the Plane worker container (local mail check)" ansible.builtin.command: argv: From 7fa5cc9db025a311bfcceac4d846d241548c20a6 Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 18:58:43 -0500 Subject: [PATCH 08/11] test(plane): the catcher inputs come only from the catcher task's include vars [AC-1127] assert-mail-captured.yml takes its inputs as include vars or play vars. The test pins that deploy-plane.yml defines the four it passes only as include vars of the one catcher task, with no play var, block var, set_fact or register of any mail_captured_ name, so the shared task's extra-var refusal (landing in #1247) covers every source. A play-var mutant and a set_fact mutant each turn it red. --- platform/tests/test_plane_outbound_mail.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/platform/tests/test_plane_outbound_mail.py b/platform/tests/test_plane_outbound_mail.py index 1f9093e56..1091ab9ce 100644 --- a/platform/tests/test_plane_outbound_mail.py +++ b/platform/tests/test_plane_outbound_mail.py @@ -414,6 +414,22 @@ def test_the_catcher_check_reads_the_mailpit_api_and_this_runs_since_the_mark(): assert catcher["vars"]["mail_captured_subject"] == "Test email" +def test_the_catcher_inputs_are_set_only_as_the_include_vars_of_the_catcher_check(): + # assert-mail-captured.yml takes its inputs as include vars or play vars. Here they are include + # vars of the one catcher task and nothing else defines them: a play var, a block var, a set_fact + # or a register would be a second source the shared task's own extra-var refusal does not cover. + found = set() + for node in playbook_yaml.tasks(playbook_yaml.load(DEPLOY)): + sources = [node.get("vars") or {}, node.get("register") or ""] + sources += [node.get(module) or {} for module in playbook_yaml.SET_FACT] + for source in sources: + for name in [source] if isinstance(source, str) else source: + if str(name).startswith("mail_captured_"): + found.add((node.get("name"), name)) + expected = {"mail_captured_api_url", "mail_captured_recipient", "mail_captured_subject", "mail_captured_since"} + assert found == {(CATCHER, name) for name in expected} + + def test_the_local_worker_joins_the_local_dev_network_for_the_catcher(): compose = yaml.safe_load(COMPOSE_LOCAL.read_text()) assert "local-dev" in compose["services"]["worker"]["networks"] From 30e446fc5fd78fd4eded222bbb606ed936681cd1 Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 18:59:30 -0500 Subject: [PATCH 09/11] docs(mistakes): record a 5.2 repeat, a play var removed past the play-vars scope guard [AC-1127] --- docs/MISTAKES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/MISTAKES.md b/docs/MISTAKES.md index b2a02bcec..2caa752f3 100644 --- a/docs/MISTAKES.md +++ b/docs/MISTAKES.md @@ -155,7 +155,7 @@ and why. | 4.11 | A workstation home path reached a committed ledger entry; the audit grep for it ran by hand only | Data handling | 1 | Pre-commit hook (`no-machine-paths`) | | 4.12 | A brief carried an instance detail (a person) into the public template (widens 4.9) | Data handling | 1 | Convention | | 5.1 | Security check duplicated per caller; a fix reached three copies and missed two | Duplication | 1 | Test | -| 5.2 | Committed while a test was failing, because the check did not gate the commit (repeat 2026-09-25: a merge after a mergeability read, joined by `;`; 2026-10-30: a push under `SKIP_TESTS=1`; 2026-11-02: another, past two repo-wide guards; 2026-11-03: past the TLS guard again; 2026-11-04: a ledger edit past the citation guard; 2026-11-05: a playbook change past the check-mode contract test; 2026-11-08: a template comment past the check-mode injection guard; 2026-11-09: a template-order test the fast subset skips; 2026-11-11: a new test file past the spawn guard; 2026-11-11: a test-only push under `SKIP_TESTS=1`, past the line-window ratchet; 2026-11-17: a merge go sent in the same step as a CONFLICTING read; 2026-11-20: a registry row reported to a peer in the same step as a write that failed; 2026-11-27: a new tempfile user past the tempfile allowlist) | Process | 17 | Pre-push hook (bypassed whole by `SKIP_TESTS=1`; narrower skip proposed); ledger citation test at pre-commit when `docs/MISTAKES.md` is staged | +| 5.2 | Committed while a test was failing, because the check did not gate the commit (repeat 2026-09-25: a merge after a mergeability read, joined by `;`; 2026-10-30: a push under `SKIP_TESTS=1`; 2026-11-02: another, past two repo-wide guards; 2026-11-03: past the TLS guard again; 2026-11-04: a ledger edit past the citation guard; 2026-11-05: a playbook change past the check-mode contract test; 2026-11-08: a template comment past the check-mode injection guard; 2026-11-09: a template-order test the fast subset skips; 2026-11-11: a new test file past the spawn guard; 2026-11-11: a test-only push under `SKIP_TESTS=1`, past the line-window ratchet; 2026-11-17: a merge go sent in the same step as a CONFLICTING read; 2026-11-20: a registry row reported to a peer in the same step as a write that failed; 2026-11-27: a new tempfile user past the tempfile allowlist; 2026-11-28: a play var removed past the play-vars scope guard) | Process | 18 | Pre-push hook (bypassed whole by `SKIP_TESTS=1`; narrower skip proposed); ledger citation test at pre-commit when `docs/MISTAKES.md` is staged | | 5.3 | Merged a PR while its review was rate-limited | Process | 1 | Convention (user-stated) | | 5.4 | A command's own planning boundary honoured over an explicit instruction to implement (widened by 5.47) | Process | 1 | Convention + stop hook | | 5.5 | Repeated 5.2 — committed with a failing test; hooks do not gate the suite | Process | 1 | Pre-push hook | @@ -5020,6 +5020,8 @@ fast subset of scans that launch nothing includes it and would have stopped the **Occurrence 2026-11-27 (a new tempfile user past the tempfile allowlist).** PR #1235 (AC-1107) head `1ea80321` added an `ansible.builtin.tempfile` task to `provision-template.yml` for the Windows seed directory and was pushed through the pre-push hook, which passed. CI's Python (5/8) failed on `test_materialise_ssh_key.py::test_exactly_one_file_materialises_an_ssh_probe_key`, which pins the exact set of playbooks that use `tempfile` (1 failed). Fixed before merge by adding the playbook to `TEMPFILE_USERS`. Why the rule did not fire: the fast lane (`platform/tests/shards.py`, `fast_lane`) keeps an unchanged file whose durations entry lists all its tests only when every one ran under 0.25 s and none was skipped in CI, and `test_durations.json` records this file at a 5.932 s maximum with a skipped test. This is the shape of the 2026-11-09 occurrence above. +**Occurrence 2026-11-28 (a play var removed past the play-vars scope guard).** PR #1249 (AC-1127) head `c8c6cdb5` carried a `/simplify` fix (`210720ad`) that dropped `_deploy_dir` from the Phase 4 vars of `deploy-plane.yml`, on the reading that `tasks/list-service-containers.yml` sets it as a fact earlier in that play. It was pushed through the pre-push hook, which passed. CI's Python (2/8) failed on `test_play_vars_scope.py::test_no_play_reads_another_plays_vars` (1 failed, 1185 passed): that guard does not scan included task files, so the read looked like another play's var. Fixed before merge by defining it in Phase 4 again (`c7e0a310`). Why the rule did not fire: the fast lane keeps an unchanged file only when every one of its tests ran under 0.25 s in CI, and `test_durations.json` records this file at a 1.09 s maximum, so the push ran without it. This is the shape of the 2026-11-09 occurrence above. + ### 5.3 Merging while the review was rate-limited **What happened.** Merged a pull request while the review bot reported From 85dde792d52e0e76077c9f65742155166abef133 Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Sat, 28 Nov 2026 19:05:20 -0500 Subject: [PATCH 10/11] refactor(plane): one Phase 4 deploy dir with the shared fact's formula [AC-1127] Phase 4 declared _monorepo_dir and _deploy_dir from the Phase 1 pattern, without the compose_working_dir branch that tasks/list-service-containers.yml uses for the fact that replaces it after the containers-stable include. One variable now carries that same formula and a comment saying it exists because the play-vars scope guard does not follow includes. The catcher-inputs test walks each node's names in one flat list. --- platform/playbooks/deploy-plane.yml | 8 ++++++-- platform/tests/test_plane_outbound_mail.py | 9 +++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/platform/playbooks/deploy-plane.yml b/platform/playbooks/deploy-plane.yml index dc64730ec..fc8426e66 100644 --- a/platform/playbooks/deploy-plane.yml +++ b/platform/playbooks/deploy-plane.yml @@ -622,8 +622,12 @@ become: false vars: _engine: "{{ container_engine | default('podman') }}" - _monorepo_dir: "{{ local_monorepo_dir | default('/home/' ~ (ansible_user | default('deploy')) ~ '/agent-cloud') }}" - _deploy_dir: "{{ _monorepo_dir }}/{{ monorepo_deploy_path }}" + # The fact tasks/list-service-containers.yml sets in the containers-stable check replaces this, with + # the same formula. It is declared here too because test_play_vars_scope.py does not follow includes. + _deploy_dir: >- + {{ compose_working_dir if (compose_working_dir | default('') | length > 0) + else (local_monorepo_dir | default('/home/' ~ (ansible_user | default('deploy')) ~ '/agent-cloud')) + ~ '/' ~ monorepo_deploy_path }} # The names of the running containers whose compose service label is exactly `worker` # (not beat-worker, not a worker2). Read from the `podman ps` the local mail check registers. _plane_worker_names: >- diff --git a/platform/tests/test_plane_outbound_mail.py b/platform/tests/test_plane_outbound_mail.py index 1091ab9ce..a491fac6a 100644 --- a/platform/tests/test_plane_outbound_mail.py +++ b/platform/tests/test_plane_outbound_mail.py @@ -420,12 +420,9 @@ def test_the_catcher_inputs_are_set_only_as_the_include_vars_of_the_catcher_chec # or a register would be a second source the shared task's own extra-var refusal does not cover. found = set() for node in playbook_yaml.tasks(playbook_yaml.load(DEPLOY)): - sources = [node.get("vars") or {}, node.get("register") or ""] - sources += [node.get(module) or {} for module in playbook_yaml.SET_FACT] - for source in sources: - for name in [source] if isinstance(source, str) else source: - if str(name).startswith("mail_captured_"): - found.add((node.get("name"), name)) + names = [*(node.get("vars") or {}), node.get("register")] + names += [name for module in playbook_yaml.SET_FACT for name in node.get(module) or {}] + found |= {(node.get("name"), name) for name in names if str(name).startswith("mail_captured_")} expected = {"mail_captured_api_url", "mail_captured_recipient", "mail_captured_subject", "mail_captured_since"} assert found == {(CATCHER, name) for name in expected} From 4e4c573d53e0d94aaa5b2d70745e21ea53709a0e Mon Sep 17 00:00:00 2001 From: "Joseph A. Wisneski IV" Date: Wed, 2 Dec 2026 19:00:10 -0500 Subject: [PATCH 11/11] docs(lessons): Plane's test-mail command exits 0 on a failed send [AC-1127] --- docs/LESSONS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/LESSONS.md b/docs/LESSONS.md index 8bb859ef2..6a30dd289 100644 --- a/docs/LESSONS.md +++ b/docs/LESSONS.md @@ -227,3 +227,9 @@ Superseded by L-033 - **ACCEPTED:** the pull request titled with AC-1149 (batch v0.18.0, unit U16c). - **DERIVED:** Proxmox runs a connection test inside every create and update of a metric server, and the write is refused when that test fails: `POST` and `PUT` `/cluster/metrics/server/{id}` both call `test_connection` before saving (pve-manager `PVE/API2/Cluster/MetricServer.pm`, `master`, :178 and :252), and the OpenTelemetry plugin's test posts an empty metrics payload to the declared URL with the certificate checked by host name (`PVE/Status/OpenTelemetry.pm`, :665-670). So a declared metric server can be written only after its receiver answers from the cluster: the receiver's listener is deployed, the node trusts the receiver's CA and resolves its name, and the receiver's firewall admits the node. A plan that converges a metric server orders its real run after those steps, and a dry run cannot show that the write will succeed. - **APPLIES TO:** `platform/playbooks/converge-proxmox-metric-server.yml` and any later converge of a Proxmox metric server, and the order of production runs that bring up the o11y Proxmox listener. + +### L-038 · 2026-12-02 · playbooks + +- **ACCEPTED:** the pull request titled with AC-1127 (unit 06 of batch proton-smtp, #1249). +- **DERIVED:** Plane's `manage.py test_email` exits 0 when delivery fails: it catches the send exception and prints an `Error: Email could not be delivered` line instead (`apps/api/plane/db/management/commands/test_email.py`, makeplane/plane default branch, :64-67). A task that sends a test mail through it judges the exact line `Email successfully sent` in its output and then the delivery itself (the local catcher, or the relay), never the exit code alone. +- **APPLIES TO:** any playbook or test under `platform/playbooks/` and `platform/tests/` that proves Plane's outbound mail by running its test-mail command (the local verify of `deploy-plane.yml` and the production test send, plan 29 unit S9).