test(roles): run molecule's check step before and after converge #395

Merged
Defame1297 merged 4 commits from test/134-check-before-after-converge into main 2026-11-26 15:22:52 +00:00
Owner

What and why

Closes #134

Every role scenario with a converge now runs check right before it (a fresh host) and right after it, before idempotence (a configured host). A new test in tests/scripts/test_run_molecule_scenarios.py fails any role scenario without both. _binary_update/check_mode is check-only and unchanged. pihole and pve_lxc had their second check after idempotence; it now sits after converge, like every other scenario.

Notes on the issue text:

  • No destroy. The issue's sequence ends in destroy, but scenarios deliberately have none (.gitea/workflows/AGENTS.md), so none is added.
  • Molecule accepts a step twice. pihole and pve_lxc already ran check twice in CI.
  • Where the rule lives. It is in .gitea/workflows/AGENTS.md, and that is the line updated.

Fixes for --check failures on a fresh host. A task that would fail is now skipped only under --check, and only when an earlier task in the same run would have created what it needs:

  • cloudflared: account, unit, restart handler, binary swap.
  • docker: packages from a new repository, service start, docker group.
  • gitea: binary, completion, unit, reload handler. Its scenario converges nothing, so neither check exercises these.
  • gitea_runner: account, unit, Docker start, docker group, binary swap.
  • traefik: ACME file, binary, unit, restart handler.
  • user_management: authorized_keys of a user not created yet.

Each has a bugfixes fragment line.

Scenario fixtures. The molecule images ship without apt lists, and apt does not refresh them under --check. The docker and traefik scenarios' prepare.yml now refresh the apt cache, so the fresh-host check finds the packages the role installs. pihole and system_baseline already did this.

Decided with the maintainer during review:

  1. Guard form. A guard may be when: not ansible_check_mode or <condition> (the form pihole already uses), so --check still previews a configured host. roles/AGENTS.md now says so.
  2. ufw and fail2ban keep the step. Their --check previews only a host where the package is installed, and their README Notes say so. Guarding a host without the package would need guards on most of their tasks. The ufw probe (#271) is untouched.

Runtime. Two check runs are estimated to add about 35% to Molecule runner time. Last nightly full run: about 18 min; estimated after: about 23–24 min. This is estimated from task counts in nightly run 5710, not measured. Daytime runs of this PR cannot confirm it: run 5755, another PR's run this morning without this change, was as slow as this PR's (44 min, with system_baseline at 1542 s).

Verified

  • python3 -m unittest discover -s tests/scripts: OK. The new test failed before the sequence change and passes after.
  • pre-commit run --all-files with .venv on PATH: all hooks pass (ansible-lint, yamllint, REUSE, changelog lint, gitleaks).
  • ansible-test sanity via the pre-push hook: passed.
  • On ansible-core 2.22.0 (the local .venv), --check runs against localhost confirmed:
    • copy and template into a missing directory report changed and do not fail;
    • a command with creates reports changed (traefik's ACME guard relies on this);
    • user with a missing group fails for an existing user.
  • Molecule run 5766 (on 3afff00): 14 of 16 role scenarios passed with the new sequence. docker and traefik failed in the first check with "No package matching 'curl'/'wget' is available"; the apt refresh in their prepare.yml (9ce0fbd) fixes this.
  • Three rounds of subagent review (standards and spec, separately):
    • Round 1 findings: fixed in 3afff00, or decided with the maintainer as above.
    • Round 2 findings (a test class split, a rule pointing at a missing exception list, a misplaced comment, the CI failure): fixed in 9ce0fbd.
    • Round 3: no new hard findings. Its wording suggestion is applied.

Not verified

  • Molecule on 9ce0fbd. The run for the current head is pending. Whether docker and traefik now pass both check steps, and so whether every role passes (the issue's acceptance criterion), is shown by that run.
  • gitea's guards. Not exercised by any scenario.
  • Paths not run in molecule:
    • docker's and traefik's update path under --check on a fresh host;
    • gitea_runner's Docker install path;
    • --check on a host without ufw or fail2ban (documented as unsupported).
  • Runtime. The added time is estimated, not measured (see above).
  • After #170. Once fixtures leave the image, the check before converge in ufw and fail2ban will run without the package and is expected to fail. That needs revisiting there.
  • Left out. The molecule Dockerfiles' comment that gnupg is preinstalled to spare the docker scenario an apt update no longer holds. It is left for an image pull request, since changing an image triggers a rebuild.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.

Assisted-by: Claude Code

## What and why Closes #134 Every role scenario with a converge now runs `check` right before it (a fresh host) and right after it, before `idempotence` (a configured host). A new test in `tests/scripts/test_run_molecule_scenarios.py` fails any role scenario without both. `_binary_update/check_mode` is check-only and unchanged. pihole and pve_lxc had their second `check` after `idempotence`; it now sits after `converge`, like every other scenario. Notes on the issue text: - **No `destroy`.** The issue's sequence ends in `destroy`, but scenarios deliberately have none (`.gitea/workflows/AGENTS.md`), so none is added. - **Molecule accepts a step twice.** pihole and pve_lxc already ran `check` twice in CI. - **Where the rule lives.** It is in `.gitea/workflows/AGENTS.md`, and that is the line updated. **Fixes for `--check` failures on a fresh host.** A task that would fail is now skipped only under `--check`, and only when an earlier task in the same run would have created what it needs: - **cloudflared:** account, unit, restart handler, binary swap. - **docker:** packages from a new repository, service start, docker group. - **gitea:** binary, completion, unit, reload handler. Its scenario converges nothing, so neither `check` exercises these. - **gitea_runner:** account, unit, Docker start, docker group, binary swap. - **traefik:** ACME file, binary, unit, restart handler. - **user_management:** `authorized_keys` of a user not created yet. Each has a `bugfixes` fragment line. **Scenario fixtures.** The molecule images ship without apt lists, and apt does not refresh them under `--check`. The docker and traefik scenarios' `prepare.yml` now refresh the apt cache, so the fresh-host `check` finds the packages the role installs. pihole and system_baseline already did this. **Decided with the maintainer during review:** 1. **Guard form.** A guard may be `when: not ansible_check_mode or <condition>` (the form pihole already uses), so `--check` still previews a configured host. `roles/AGENTS.md` now says so. 2. **ufw and fail2ban keep the step.** Their `--check` previews only a host where the package is installed, and their README Notes say so. Guarding a host without the package would need guards on most of their tasks. The ufw probe (#271) is untouched. **Runtime.** Two `check` runs are estimated to add about 35% to Molecule runner time. Last nightly full run: about 18 min; estimated after: about 23–24 min. This is estimated from task counts in nightly run 5710, not measured. Daytime runs of this PR cannot confirm it: run 5755, another PR's run this morning without this change, was as slow as this PR's (44 min, with system_baseline at 1542 s). ## Verified - `python3 -m unittest discover -s tests/scripts`: OK. The new test failed before the sequence change and passes after. - `pre-commit run --all-files` with `.venv` on PATH: all hooks pass (ansible-lint, yamllint, REUSE, changelog lint, gitleaks). - `ansible-test sanity` via the pre-push hook: passed. - On ansible-core 2.22.0 (the local `.venv`), `--check` runs against localhost confirmed: - copy and template into a missing directory report `changed` and do not fail; - a `command` with `creates` reports `changed` (traefik's ACME guard relies on this); - `user` with a missing group fails for an existing user. - **Molecule run 5766 (on 3afff00):** 14 of 16 role scenarios passed with the new sequence. docker and traefik failed in the first `check` with "No package matching 'curl'/'wget' is available"; the apt refresh in their `prepare.yml` (9ce0fbd) fixes this. - **Three rounds of subagent review** (standards and spec, separately): - Round 1 findings: fixed in 3afff00, or decided with the maintainer as above. - Round 2 findings (a test class split, a rule pointing at a missing exception list, a misplaced comment, the CI failure): fixed in 9ce0fbd. - Round 3: no new hard findings. Its wording suggestion is applied. ## Not verified - **Molecule on 9ce0fbd.** The run for the current head is pending. Whether docker and traefik now pass both `check` steps, and so whether every role passes (the issue's acceptance criterion), is shown by that run. - **gitea's guards.** Not exercised by any scenario. - **Paths not run in molecule:** - docker's and traefik's update path under `--check` on a fresh host; - gitea_runner's Docker install path; - `--check` on a host without ufw or fail2ban (documented as unsupported). - **Runtime.** The added time is estimated, not measured (see above). - **After #170.** Once fixtures leave the image, the check before converge in ufw and fail2ban will run without the package and is expected to fail. That needs revisiting there. - **Left out.** The molecule Dockerfiles' comment that gnupg is preinstalled to spare the docker scenario an apt update no longer holds. It is left for an image pull request, since changing an image triggers a rebuild. --- - [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code
Claude added this to the Continuous delivery milestone 2026-11-26 11:16:41 +00:00
Defame1297 was assigned by Claude 2026-11-26 11:16:41 +00:00
Claude added 2 commits 2026-11-26 11:16:41 +00:00
Every role scenario with a converge now runs check right before it (a
fresh host) and right after it (a configured host), and a script test
fails a scenario without both. pihole and pve_lxc move their second
check from after idempotence to after converge to match.

The roles that failed under --check on a fresh host get the two allowed
guards: cloudflared, docker, gitea, gitea_runner, traefik and
user_management. ufw and fail2ban preview only a host where their
package is installed, as their READMEs now say.

Closes #134

Assisted-by: Claude Code
fix(roles): apply review findings to the check-mode change
Build / build (pull_request) Successful in 25s
Lint / lint (pull_request) Successful in 2m13s
Molecule / molecule (pull_request) Failing after 34m3s
3afff00b9b
Guard gitea_runner's docker group membership like its Docker start, run
user_management's getent probe unconditionally, and state the
play-level check_mode limit in every touched README. The check-mode
rule now allows the pihole guard form and names roles whose --check
needs their package installed.

Assisted-by: Claude Code
CODEOWNERS rules requested review from Defame1297 2026-11-26 11:16:41 +00:00
Defame1297 added 1 commit 2026-11-26 12:50:33 +00:00
fix(roles): refresh apt in the docker and traefik scenarios and apply review round 2
Build / build (pull_request) Successful in 22s
Lint / lint (pull_request) Successful in 2m1s
Molecule / molecule (pull_request) Successful in 44m6s
9ce0fbd433
The molecule images ship without apt lists, and --check does not
refresh them, so the fresh-host check of docker and traefik could not
find curl and wget. Their prepare now refreshes the cache, as pihole's
and system_baseline's already do by installing fixtures.

The sequence test gets its own class after the platform tests, the
check-mode rule is split into guards and README, and the
user_management comment sits on the task it explains.

Assisted-by: Claude Code
Defame1297 added 1 commit 2026-11-26 14:39:38 +00:00
Merge branch 'main' into test/134-check-before-after-converge
Build / build (pull_request) Successful in 32s
Lint / lint (pull_request) Successful in 2m59s
Molecule / molecule (pull_request) Successful in 42m34s
6b99ac9ca0
Defame1297 approved these changes 2026-11-26 14:39:56 +00:00
Defame1297 scheduled this pull request to auto merge when all checks succeed 2026-11-26 14:40:04 +00:00
Defame1297 merged commit 31634c4eef into main 2026-11-26 15:22:52 +00:00
Defame1297 deleted branch test/134-check-before-after-converge 2026-11-26 15:22:52 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#395