Merge pull request 'ci: shift checks left (check-json, script tests, image pins) and name the meta-dependency check' (#527) from ci/187-246-shift-left-checks into main
Images / image (0.1, Dockerfile, ubuntu:24.04@sha256:168a88cc61bdd95c8f871e3903d4e0a525e340c2b28a70dadd6d1503ecc7c391, molecule-ubuntu2404, images/molecule-ubuntu2404) (push) Successful in 22s
Renovate / renovate (push) Successful in 44s
Images / image (0.1, Dockerfile, ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd, molecule-ubuntu2604, images/molecule-ubuntu2604) (push) Successful in 23s
Images / image (0.1, images/molecule-controller/Dockerfile, ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd, molecule-controller, ) (push) Successful in 19s
Images / image (0.2, images/ci/Dockerfile, ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd, ci, ) (push) Successful in 7m7s

Reviewed-on: #527
This commit was merged in pull request #527.
This commit is contained in:
Defame1297 committed 2026-12-06 20:24:40 +00:00
commit 3b91a40db1
17 files changed
+89 -51

No files matched your search

+10 -9
View File
@@ -50,8 +50,8 @@ issue.
branch name is chosen by the pusher, so this constrains only the bot's own pull requests. branch name is chosen by the pusher, so this constrains only the bot's own pull requests.
- **Workflows never mention the image namespace this repository's CI must not use** (the string - **Workflows never mention the image namespace this repository's CI must not use** (the string
is in `scripts/check_image_versions.py`). *Why:* this repository's images are built and pulled is in `scripts/check_image_versions.py`). *Why:* this repository's images are built and pulled
only under its own organisation's namespace. *Held:* control: the Lint check's "Check image only under its own organisation's namespace. *Held:* control: the `check-image-pins` hook,
pins" step. run by the Lint check.
## Lint and Build ## Lint and Build
@@ -62,13 +62,12 @@ issue.
*Why:* a pull request is tested on its own pins, and an unchanged one starts in seconds. *Why:* a pull request is tested on its own pins, and an unchanged one starts in seconds.
*Held:* control: the "Check the baked tooling against the pins" step. *Held:* control: the "Check the baked tooling against the pins" step.
- **On the fast path the network is cut by environment**: `PIP_NO_INDEX=1`, the proxy variables - **On the fast path the network is cut by environment**: `PIP_NO_INDEX=1`, the proxy variables
set to a dead local port and `no_proxy` empty, for every later step except "Test the repository set to a dead local port and `no_proxy` empty, for every later step; the slow path keeps
scripts", which unsets them for its fake registry on loopback; the slow path keeps network. network. The script tests set `no_proxy` to `127.0.0.1` for their fake registry on loopback.
*Why:* a runtime download is a bake-in defect and must fail the job, not silently slow it. *Why:* a runtime download is a bake-in defect and must fail the job, not silently slow it.
*Held:* control, set by the "Check the baked tooling against the pins" step, for pip, curl, git *Held:* control, set by the "Check the baked tooling against the pins" step, for pip, curl, git
over HTTPS and Python's urllib or requests (anything honouring `PIP_NO_INDEX` or the proxy over HTTPS and Python's urllib or requests (anything honouring `PIP_NO_INDEX` or the proxy
variables); review for a raw socket or a tool that ignores the proxy variables, and for the variables); review for a raw socket or a tool that ignores the proxy variables.
script tests.
- **Triggers:** both run on pull requests to `main` and on manual dispatch; Build also runs on - **Triggers:** both run on pull requests to `main` and on manual dispatch; Build also runs on
`v*` tags, where it checks the tag against `galaxy.yml`. *Why:* the tag is what consumers `v*` tags, where it checks the tag against `galaxy.yml`. *Why:* the tag is what consumers
install. *Held:* review. install. *Held:* review.
@@ -116,9 +115,11 @@ issue.
scenario for any other file, `requirements-molecule.*` included; `requirements-dev.*`, and scenario for any other file, `requirements-molecule.*` included; `requirements-dev.*`, and
`lint.yml` and `build.yml` with their `ci` pins, are on IGNORED. *Why:* a full run takes the `lint.yml` and `build.yml` with their `ci` pins, are on IGNORED. *Why:* a full run takes the
single runner slot for a long time. *Held:* control: the selector and its tests. single runner slot for a long time. *Held:* control: the selector and its tests.
- **A role named in an include, import, play `roles:` entry or meta dependency is written out in - **A role named in an include, import or play `roles:` entry is written out in full**, never
full**, never bare or templated. *Why:* the selector finds dependent roles by their FQCN. bare or templated, and no role declares `meta/main.yml` `dependencies`
*Held:* control: a selector test fails a bare or templated name. ([roles/AGENTS.md](../../roles/AGENTS.md)). *Why:* the selector finds dependent roles by their
FQCN. *Held:* control: a selector test fails a bare or templated name and a non-empty
`dependencies`.
- **Scenarios load `mortis.kamino` from the checkout, never from an installed copy, so - **Scenarios load `mortis.kamino` from the checkout, never from an installed copy, so
`galaxy.yml` is on IGNORED.** *Why:* the checkout is first on `ANSIBLE_COLLECTIONS_PATH` and the `galaxy.yml` is on IGNORED.** *Why:* the checkout is first on `ANSIBLE_COLLECTIONS_PATH` and the
shared base config `.config/molecule/config.yml` turns off molecule's install of the collection shared base config `.config/molecule/config.yml` turns off molecule's install of the collection
+3 -12
View File
@@ -78,14 +78,6 @@ jobs:
export PATH="/opt/venv/bin:$PATH" export PATH="/opt/venv/bin:$PATH"
pre-commit run --all-files --show-diff-on-failure pre-commit run --all-files --show-diff-on-failure
# Image pins (scripts/check_image_versions.py): a pin in a workflow must name an
# image of the matrix. Not a pre-commit hook: a change to .pre-commit-config.yaml
# is itself an input of the ci image and would force an image rebuild.
- name: Check image pins
run: |
export PATH="/opt/venv/bin:$PATH"
python3 scripts/check_image_versions.py pins
# A pull request from a renovate/ branch may only move version, tag, digest and pin # A pull request from a renovate/ branch may only move version, tag, digest and pin
# lines (scripts/check_bot_pr_diff.py), so the bot's automerge cannot change workflow # lines (scripts/check_bot_pr_diff.py), so the bot's automerge cannot change workflow
# logic or reach the org secrets. The branch name is attacker-controlled: this only # logic or reach the org secrets. The branch name is attacker-controlled: this only
@@ -113,12 +105,11 @@ jobs:
fi fi
python3 -E -s "$guard" "$HEAD_REF" "$BASE_REF" python3 -E -s "$guard" "$HEAD_REF" "$BASE_REF"
# Without the guard: an empty no_proxy would send the fake registry on 127.0.0.1 to the dead proxy. # The script tests are a pre-push hook (they take minutes), so --all-files above skips them.
- name: Test the repository scripts - name: Run the script tests hook
run: | run: |
unset PIP_NO_INDEX http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
export PATH="/opt/venv/bin:$PATH" export PATH="/opt/venv/bin:$PATH"
python3 -m unittest discover -s tests/scripts pre-commit run --hook-stage pre-push script-tests --all-files --show-diff-on-failure
# The gitleaks hook scans --staged only, which is empty in a clean checkout, # The gitleaks hook scans --staged only, which is empty in a clean checkout,
# so scan the PR's commits explicitly with the binary pre-commit built. # so scan the PR's commits explicitly with the binary pre-commit built.
+23
View File
@@ -49,6 +49,8 @@ repos:
hooks: hooks:
- id: check-toml - id: check-toml
stages: ['pre-commit'] stages: ['pre-commit']
- id: check-json
stages: ['pre-commit']
- id: check-merge-conflict - id: check-merge-conflict
stages: ['pre-commit'] stages: ['pre-commit']
@@ -114,6 +116,27 @@ repos:
require_serial: true require_serial: true
stages: ['pre-push'] stages: ['pre-push']
# Pre-push only: the suite takes minutes. Lint runs it by id. The uncreatable GIT_DIR makes a
# git fixture that keeps the caller's GIT_* fail instead of writing to this repository.
- id: script-tests
name: A script change passes its tests in tests/scripts (scripts/AGENTS.md)
description: python3 -m unittest discover -s tests/scripts
entry: env GIT_DIR=/dev/null/not-a-repo python3 -m unittest discover -s tests/scripts
language: system
files: ^(scripts/|tests/scripts/|roles/[^/]+/meta/)
pass_filenames: false
stages: ['pre-push']
# always_run: its inputs span workflows, Dockerfiles and docs/images, and it fails on a missing one.
- id: check-image-pins
name: Image pins name an image of the image.yml matrix, which has its job image, labels and docs (images/AGENTS.md)
description: python3 scripts/check_image_versions.py pins
entry: python3 scripts/check_image_versions.py pins
language: system
pass_filenames: false
always_run: true
stages: ['pre-commit']
# SECURITY.md's accepted risks rest on the Collection shipping roles only. It sits before # SECURITY.md's accepted risks rest on the Collection shipping roles only. It sits before
# ansible-lint, whose fail_fast would otherwise hide this message. # ansible-lint, whose fail_fast would otherwise hide this message.
- id: refuse-plugins - id: refuse-plugins
+2 -1
View File
@@ -59,7 +59,8 @@ held: by a control (a named hook or check), by review, or aspirational (checked
Lint re-runs the commit-stage hooks, the commit-msg check and gitleaks). Lint re-runs the commit-stage hooks, the commit-msg check and gitleaks).
- `pre-commit run --all-files`: the commit-stage hooks on every file. - `pre-commit run --all-files`: the commit-stage hooks on every file.
- `python3 -m unittest discover -s tests/scripts`: when a script changed. - `python3 -m unittest discover -s tests/scripts`: when a script changed.
- `git push` runs `ansible-test sanity` on HEAD (the pre-push hook). - `git push` runs `ansible-test sanity` on HEAD, and the script tests when `scripts/`, `tests/scripts/`
or a role's `meta/` changed (the pre-push hooks).
- Molecule runs only in CI. - Molecule runs only in CI.
## Repository structure ## Repository structure
+3 -3
View File
@@ -11,7 +11,7 @@ Ubuntu 26.04 with:
- **Python tools** in `/opt/venv` (on `PATH`; it runs on Python 3.14, the version of `.python-version`, from the baked copy and not from the distribution's `python3`), from `requirements-dev.lock` (the hashed lock of `requirements-dev.txt`, installed with `pip install --require-hashes`): `ansible-core`, - **Python tools** in `/opt/venv` (on `PATH`; it runs on Python 3.14, the version of `.python-version`, from the baked copy and not from the distribution's `python3`), from `requirements-dev.lock` (the hashed lock of `requirements-dev.txt`, installed with `pip install --require-hashes`): `ansible-core`,
`ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`, `molecule` `ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`, `molecule`
(without its Docker driver: Lint's "Test the repository scripts" step runs the tests that import it), and (without its Docker driver: Lint's run of the `script-tests` hook runs the tests that import it), and
`proxmoxer`, the controller-side library the modules of `community.proxmox` import. `proxmoxer`, the controller-side library the modules of `community.proxmox` import.
- **The collections the roles call** in `/opt/collections` (`ANSIBLE_COLLECTIONS_PATH` is set to it), from - **The collections the roles call** in `/opt/collections` (`ANSIBLE_COLLECTIONS_PATH` is set to it), from
`requirements.yml`: `community.general`, `ansible.posix` and `community.proxmox` at the exact versions CI tests against, so `requirements.yml`: `community.general`, `ansible.posix` and `community.proxmox` at the exact versions CI tests against, so
@@ -20,7 +20,7 @@ Ubuntu 26.04 with:
(`PRE_COMMIT_HOME`): conventional-pre-commit, gitleaks, yamllint, ruff, shellcheck-py, pre-commit-hooks, actionlint and zizmor. The Go (`PRE_COMMIT_HOME`): conventional-pre-commit, gitleaks, yamllint, ruff, shellcheck-py, pre-commit-hooks, actionlint and zizmor. The Go
hooks are prebuilt; their toolchains, and the binaries of those repositories that no hook runs, are removed to hooks are prebuilt; their toolchains, and the binaries of those repositories that no hook runs, are removed to
keep layers small. The local hooks (`reuse-lint`, keep layers small. The local hooks (`reuse-lint`,
`antsibull-changelog-lint`, `ansible-lint`) are `language: system`: they run from `/opt/venv`, which is why `antsibull-changelog-lint`, `ansible-lint`, `script-tests`, `check-image-pins`) are `language: system`: they run from `/opt/venv`, which is why
that directory must be on `PATH` (it is, in the image). that directory must be on `PATH` (it is, in the image).
- **`ansible-test sanity` virtualenvs**, primed in `/root/.ansible/test`, and Python 3.11, 3.13 and 3.14 as - **`ansible-test sanity` virtualenvs**, primed in `/root/.ansible/test`, and Python 3.11, 3.13 and 3.14 as
`python3.11` / `python3.13` / `python3.14` (python-build-standalone, installed with uv) next to the distribution's `python3.11` / `python3.13` / `python3.14` (python-build-standalone, installed with uv) next to the distribution's
@@ -63,7 +63,7 @@ jobs:
`/opt/ci-pins.sha256` lists the four pin files by their checkout-relative path, so `sha256sum -c` runs in the checkout root. When `/opt/ci-pins.sha256` lists the four pin files by their checkout-relative path, so `sha256sum -c` runs in the checkout root. When
the checkout's `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml` and `.pre-commit-config.yaml` match, the baked tools and the checkout's `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml` and `.pre-commit-config.yaml` match, the baked tools and
collections are used as they are, and Lint and Build cut the network by environment (proxy variables and collections are used as they are, and Lint and Build cut the network by environment (proxy variables and
`PIP_NO_INDEX`) for all but the script tests, so a tool that downloads at run time fails the job. When a pull request changes a pin the check fails and the job installs the pinned `PIP_NO_INDEX`), so a tool that downloads at run time fails the job. When a pull request changes a pin the check fails and the job installs the pinned
tools and collections itself for that run tools and collections itself for that run
(slower, same result), until the image is rebuilt from `main`. `lint.yml`, `build.yml` and `gitea-release-key.yml` (slower, same result), until the image is rebuilt from `main`. `lint.yml`, `build.yml` and `gitea-release-key.yml`
are the real consumers. are the real consumers.
+1 -2
View File
@@ -63,8 +63,7 @@ it to this repository's organisation in the Gitea registry as `<version>` and `l
image; a job downloads at run time only on the slow path (a pull request that changes a pin image; a job downloads at run time only on the slow path (a pull request that changes a pin
file). *Why:* a run that downloads is slower and depends on the network. *Held:* control: on file). *Why:* a run that downloads is slower and depends on the network. *Held:* control: on
the fast path Lint and Build cut the network by environment, so a download through pip or a the fast path Lint and Build cut the network by environment, so a download through pip or a
proxy-honouring client fails the job; review for a raw socket, for the script tests, which keep proxy-honouring client fails the job; review for a raw socket and for Molecule.
network, and for Molecule.
- **Each Dockerfile upgrades the base image's packages in its first apt layer.** *Why:* Ubuntu - **Each Dockerfile upgrades the base image's packages in its first apt layer.** *Why:* Ubuntu
publishes package updates before it refreshes the base image. *Held:* review. publishes package updates before it refreshes the base image. *Held:* review.
- **Recorded speed:** a speed optimisation that adds machinery states its measured saving where - **Recorded speed:** a speed optimisation that adds machinery states its measured saving where
+1 -1
View File
@@ -15,7 +15,7 @@
# - /opt/venv: requirements-dev.lock, the hashed lock of requirements-dev.txt (ansible-core, ansible-lint, pre-commit, # - /opt/venv: requirements-dev.lock, the hashed lock of requirements-dev.txt (ansible-core, ansible-lint, pre-commit,
# antsibull-changelog, galaxy-importer, reuse, molecule, proxmoxer), on the Python of # antsibull-changelog, galaxy-importer, reuse, molecule, proxmoxer), on the Python of
# .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv-dev uses. # .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv-dev uses.
# molecule is there for Lint's "Test the repository scripts" step, whose molecule tests import it; its # molecule is there for Lint's run of the script-tests hook, whose molecule tests import it; its
# Docker driver and community.docker are not: Molecule runs in the molecule-controller image. # Docker driver and community.docker are not: Molecule runs in the molecule-controller image.
# - /opt/collections: the collections of requirements.yml (the versions the roles are # - /opt/collections: the collections of requirements.yml (the versions the roles are
# tested against), found through ANSIBLE_COLLECTIONS_PATH, so `ansible-lint --offline` # tested against), found through ANSIBLE_COLLECTIONS_PATH, so `ansible-lint --offline`
+1 -1
View File
@@ -12,7 +12,7 @@ pre-commit==4.7.0
antsibull-changelog==0.38.0 antsibull-changelog==0.38.0
galaxy-importer==0.4.45 galaxy-importer==0.4.45
reuse==6.3.0 reuse==6.3.0
# molecule without its Docker driver: Lint's "Test the repository scripts" step imports it in # molecule without its Docker driver: Lint's run of the script-tests hook imports it in
# test_check_scenarios_load_checkout.py and test_run_molecule_scenarios.py, which skip without it. # test_check_scenarios_load_checkout.py and test_run_molecule_scenarios.py, which skip without it.
molecule==26.11.1 molecule==26.11.1
# proxmoxer: the controller-side library community.proxmox's modules import (they refuse anything below 2.3), # proxmoxer: the controller-side library community.proxmox's modules import (they refuse anything below 2.3),
+3 -1
View File
@@ -114,7 +114,9 @@ names a check that does not exist yet and its backlog issue.
only on a supported entry point, an internal role on any entry point in its argument_specs. only on a supported entry point, an internal role on any entry point in its argument_specs.
*Why:* a task-level include keeps the order readable, where `meta` dependencies run hidden and *Why:* a task-level include keeps the order readable, where `meta` dependencies run hidden and
deduplicated. *Held:* the selector runs a dependent role's scenarios when a role it uses deduplicated. *Held:* the selector runs a dependent role's scenarios when a role it uses
changes; review for empty `dependencies` until Lint fails a non-empty one (#246). changes; control: `test_roles_call_each_other_by_full_name_only` in
`tests/scripts/test_select_molecule_scenarios.py`, run by the Lint check, fails a non-empty
`dependencies`.
- **Internal roles.** A leading `_`; only roles of this Collection call it, by FQCN; it refuses - **Internal roles.** A leading `_`; only roles of this Collection call it, by FQCN; it refuses
to run without a parent role (an `assert` on `ansible_parent_role_names`, as in to run without a parent role (an `assert` on `ansible_parent_role_names`, as in
`_binary_update`); it has argument_specs and Molecule scenarios and follows the platform rules. `_binary_update`); it has argument_specs and Molecule scenarios and follows the platform rules.
+2 -2
View File
@@ -12,8 +12,8 @@ rules for scripts (prefer a standard tool, comment length) are in
- **A script change comes with its test in `tests/scripts/`** (`test_<script>.py`), in the same - **A script change comes with its test in `tests/scripts/`** (`test_<script>.py`), in the same
pull request. Run them with `python3 -m unittest discover -s tests/scripts`. pull request. Run them with `python3 -m unittest discover -s tests/scripts`.
*Why:* a script decides whether a pull request passes, so an untested change can wave through *Why:* a script decides whether a pull request passes, so an untested change can wave through
what it should stop. *Held:* control: the Lint check's "Test the repository scripts" step runs what it should stop. *Held:* control: the `script-tests` pre-push hook runs the
the tests; review for whether the change is tested at all. tests, and the Lint check runs it again; review for whether the change is tested at all.
- **A line added to `tests/sanity/ignore-common.txt` is a last resort and carries its reason** as - **A line added to `tests/sanity/ignore-common.txt` is a last resort and carries its reason** as
a trailing `# ...` comment. Fix the finding first. A finding of one ansible-core version only a trailing `# ...` comment. Fix the finding first. A finding of one ansible-core version only
goes in a committed `ignore-<MAJOR.MINOR>.txt`, which the Build job appends. goes in a committed `ignore-<MAJOR.MINOR>.txt`, which the Build job appends.
+3 -2
View File
@@ -28,8 +28,9 @@ Only a pull request is narrowed, and only when <base-ref> is given and EVENT_NAM
A role uses another when any file under its directory names it as `mortis.kamino.<other>` A role uses another when any file under its directory names it as `mortis.kamino.<other>`
(an include_role, a scenario's prepare play, a comment). The relation is transitive: when (an include_role, a scenario's prepare play, a comment). The relation is transitive: when
`a` names `b` and `b` names `c`, a change to `c` selects all three. The roles call each other `a` names `b` and `b` names `c`, a change to `c` selects all three. The roles call each other
by that full name only (a test checks includes, imports, play `roles:` entries and meta by that full name only (a test checks includes, imports and play `roles:` entries for a bare
dependencies for a bare or templated role name), so the text search finds every use. It reads the or templated role name, and that no role declares meta dependencies), so the text search finds
every use. It reads the
tree under test, not the base: a pull request that drops a use also changes the using role, tree under test, not the base: a pull request that drops a use also changes the using role,
which then selects itself, and a role the pull request deletes or renames still counts as used which then selects itself, and a role the pull request deletes or renames still counts as used
by the roles that name it. A shared file outside roles/<role>/ (a plugin) already selects by the roles that name it. A shared file outside roles/<role>/ (a plugin) already selects
+12
View File
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: Defame1297 and contributors
# SPDX-License-Identifier: GPL-3.0-or-later
"""The environment for a test's git fixture: no caller GIT_* and no user or system config."""
import os
def isolated(**extra):
"""A copy of os.environ for git: a hook exports GIT_DIR, which would point it at the real repo."""
env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
env.update(GIT_CONFIG_GLOBAL="/dev/null", GIT_CONFIG_NOSYSTEM="1", **extra)
return env
+7 -6
View File
@@ -13,6 +13,7 @@ from unittest import mock
SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts" SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts"
sys.path.insert(0, str(SCRIPTS)) sys.path.insert(0, str(SCRIPTS))
import check_bot_pr_diff as cbd import check_bot_pr_diff as cbd
import git_env
from test_check_uv_lock import APM_NEW, APM_OLD, CLICK_OLD, UV_LOCK, uv_files from test_check_uv_lock import APM_NEW, APM_OLD, CLICK_OLD, UV_LOCK, uv_files
D1, D2 = "sha256:" + "a" * 64, "sha256:" + "b" * 64 D1, D2 = "sha256:" + "a" * 64, "sha256:" + "b" * 64
@@ -51,11 +52,7 @@ def run(cwd, *cmd):
check=True, check=True,
capture_output=True, capture_output=True,
text=True, text=True,
env={ env=git_env.isolated(),
**os.environ,
"GIT_CONFIG_GLOBAL": "/dev/null",
"GIT_CONFIG_SYSTEM": "/dev/null",
},
) )
@@ -475,6 +472,10 @@ class RuleTest(unittest.TestCase):
class RepoTest(unittest.TestCase): class RepoTest(unittest.TestCase):
def setUp(self): def setUp(self):
# The gate runs git in-process, in the fixture's directory.
patcher = mock.patch.dict(os.environ, git_env.isolated(), clear=True)
patcher.start()
self.addCleanup(patcher.stop)
self.tmp = tempfile.TemporaryDirectory() self.tmp = tempfile.TemporaryDirectory()
self.repo = pathlib.Path(self.tmp.name) self.repo = pathlib.Path(self.tmp.name)
self.addCleanup(self.tmp.cleanup) self.addCleanup(self.tmp.cleanup)
@@ -579,7 +580,7 @@ class RepoTest(unittest.TestCase):
def test_empty_head_ref_on_a_pull_request_fails_closed(self): def test_empty_head_ref_on_a_pull_request_fails_closed(self):
self.write("roles/x/main.yml", "a\n") self.write("roles/x/main.yml", "a\n")
self.commit("anything") self.commit("anything")
env = {**os.environ, "EVENT_NAME": "pull_request"} env = git_env.isolated(EVENT_NAME="pull_request")
proc = subprocess.run( proc = subprocess.run(
[sys.executable, str(SCRIPTS / "check_bot_pr_diff.py"), "", "main"], [sys.executable, str(SCRIPTS / "check_bot_pr_diff.py"), "", "main"],
cwd=self.repo, cwd=self.repo,
+2 -6
View File
@@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
"""Run with: python3 -m unittest discover -s tests/scripts""" """Run with: python3 -m unittest discover -s tests/scripts"""
import os
import pathlib import pathlib
import subprocess import subprocess
import sys import sys
@@ -12,6 +11,7 @@ import unittest
SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts" SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts"
sys.path.insert(0, str(SCRIPTS)) sys.path.insert(0, str(SCRIPTS))
import check_image_versions as civ import check_image_versions as civ
import git_env
DIGEST = "sha256:" + "a" * 64 DIGEST = "sha256:" + "a" * 64
JOB = f"ubuntu:24.04@{DIGEST}" JOB = f"ubuntu:24.04@{DIGEST}"
@@ -67,11 +67,7 @@ def run(cwd, *cmd):
check=True, check=True,
capture_output=True, capture_output=True,
text=True, text=True,
env={ env=git_env.isolated(),
**os.environ,
"GIT_CONFIG_GLOBAL": "/dev/null",
"GIT_CONFIG_SYSTEM": "/dev/null",
},
) )
@@ -14,6 +14,7 @@ import sys
import tempfile import tempfile
import unittest import unittest
import git_env
import yaml import yaml
REPO = pathlib.Path(__file__).resolve().parents[2] REPO = pathlib.Path(__file__).resolve().parents[2]
@@ -44,7 +45,11 @@ class CheckScenariosLoadCheckoutTest(unittest.TestCase):
self.checkout = collection(self.ac_root) self.checkout = collection(self.ac_root)
(self.checkout / "scripts").mkdir() (self.checkout / "scripts").mkdir()
# molecule's CLI finds the base config from the repository root, as in the real checkout # molecule's CLI finds the base config from the repository root, as in the real checkout
subprocess.run(["git", "init", "-q", str(self.checkout)], check=True) subprocess.run(
["git", "init", "-q", str(self.checkout)],
check=True,
env=git_env.isolated(),
)
self.base_config = self.checkout / ".config" / "molecule" / "config.yml" self.base_config = self.checkout / ".config" / "molecule" / "config.yml"
self.base_config.parent.mkdir(parents=True) self.base_config.parent.mkdir(parents=True)
self.base_config.write_text("prerun: false\n") self.base_config.write_text("prerun: false\n")
+8
View File
@@ -6,11 +6,13 @@ import contextlib
import http.server import http.server
import io import io
import json import json
import os
import pathlib import pathlib
import sys import sys
import tempfile import tempfile
import threading import threading
import unittest import unittest
from unittest import mock
SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts" SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts"
sys.path.insert(0, str(SCRIPTS)) sys.path.insert(0, str(SCRIPTS))
@@ -156,6 +158,12 @@ class QuietServer(http.server.HTTPServer):
class RegistryClient(unittest.TestCase): class RegistryClient(unittest.TestCase):
def setUp(self): def setUp(self):
# Lint exports a dead proxy with an empty no_proxy; the fake registry is on loopback.
patcher = mock.patch.dict(
os.environ, no_proxy="127.0.0.1", NO_PROXY="127.0.0.1"
)
patcher.start()
self.addCleanup(patcher.stop)
FakeRegistry.refuse = FakeRegistry.refuse_token = FakeRegistry.no_realm = False FakeRegistry.refuse = FakeRegistry.refuse_token = FakeRegistry.no_realm = False
FakeRegistry.empty_token = FakeRegistry.unknown = False FakeRegistry.empty_token = FakeRegistry.unknown = False
FakeRegistry.not_found = None FakeRegistry.not_found = None
@@ -17,6 +17,7 @@ import yaml
REPO = pathlib.Path(__file__).resolve().parents[2] REPO = pathlib.Path(__file__).resolve().parents[2]
sys.path.insert(0, str(REPO / "scripts")) sys.path.insert(0, str(REPO / "scripts"))
import git_env
import select_molecule_scenarios as sel import select_molecule_scenarios as sel
ROLE_KEYS = { ROLE_KEYS = {
@@ -409,9 +410,6 @@ class MainTest(unittest.TestCase):
(d / "molecule.yml").write_text("---\n") (d / "molecule.yml").write_text("---\n")
def git(self, root, *args): def git(self, root, *args):
# No GIT_* from the caller (a hook exports GIT_DIR), no user or system config.
env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
env.update(GIT_CONFIG_GLOBAL="/dev/null", GIT_CONFIG_NOSYSTEM="1")
subprocess.run( subprocess.run(
[ [
"git", "git",
@@ -427,7 +425,7 @@ class MainTest(unittest.TestCase):
], ],
check=True, check=True,
capture_output=True, capture_output=True,
env=env, env=git_env.isolated(),
) )
def topic_repo(self, root, files): def topic_repo(self, root, files):