ci: shift checks left (check-json, script tests, image pins) and name the meta-dependency check #527

Merged
Defame1297 merged 5 commits from ci/187-246-shift-left-checks into main 2026-12-06 20:24:43 +00:00
Owner

What and why

Closes #187
Closes #246

#187: move checks from Lint into hooks

  • check-json is added from the pre-commit-hooks repository already pinned in the config. No new hook environment is needed.
  • check-image-pins is a local commit-stage hook with always_run: true.
    • #187 says the hook must fail on an empty file set. pre-commit can't do that, because a hook whose files: match nothing is skipped. This PR reads the requirement as: the hook always runs, and check_image_versions.py pins already fails when its inputs are missing.
    • Lint's "Check image pins" step is removed. So is its "Not a pre-commit hook" comment, which has been out of date since the ci image started rebuilding automatically.
  • script-tests is a local hook in the pre-push stage, not the commit stage, because the suite takes about 2 minutes.
    • It runs only when scripts/, tests/scripts/ or a role's meta/ changed.
    • Lint now runs it by id: pre-commit run --hook-stage pre-push script-tests --all-files. This replaces the "Test the repository scripts" step.
    • The entry sets an uncreatable GIT_DIR. A fixture that leaks the caller's git environment then fails instead of writing to the real repository.
  • Git fixtures: a new tests/scripts/git_env.py drops GIT_* from the environment. Three test files leaked it, not the one #187 names: test_check_bot_pr_diff.py, test_check_image_versions.py and test_check_scenarios_load_checkout.py. test_select_molecule_scenarios.py now uses the helper in place of its inline copy.
  • Proxy guard: test_next_image_version.py sets no_proxy=127.0.0.1 for the fake registry. The suite now runs under Lint's dead-proxy guard with nothing unset.

#246: meta dependencies

  • The Lint check already exists: test_roles_call_each_other_by_full_name_only asserts that every role has an empty dependencies list. The docs that called a meta dependency allowed, or said the rule was held by review, now name that test: roles/AGENTS.md, .gitea/workflows/AGENTS.md and the docstring of scripts/select_molecule_scenarios.py.
  • The selector case is already covered by test_a_change_selects_its_users_transitively.
  • ansible-lint 26.10.1 has no rule for meta dependencies, and yq is not in the ci image.

Every doc that named the removed Lint steps is updated: the workflow, scripts and images AGENTS.md files, docs/images/ci.md, the comment in images/ci/Dockerfile, requirements-dev.txt and AGENTS.md "Verify a change".

There is no changelog fragment: this is tooling only, and every path is in build_ignore.

Verified

  • python3 -m unittest discover -s tests/scripts passes 380 tests in each of three runs: plain, with GIT_DIR=/dev/null/not-a-repo, and with Lint's guard set (PIP_NO_INDEX=1, the proxies on 127.0.0.1:9, an empty no_proxy).
  • pre-commit run --hook-stage pre-push script-tests --all-files passes, and so does git push, which runs the pre-push hooks (ansible-test sanity and script-tests).
  • Each new hook fails on a broken input that was not committed:
    • check-json, with renovate.json truncated: renovate.json: Failed to json decode (Expecting property name enclosed in double quotes: line 3 column 1 (char 12))
    • check-image-pins, with a bad ci pin in lint.yml: ::error::.gitea/workflows/lint.yml: '…nosuchimage:0.2.54@sha256:1234' is not a <name>:<version>@sha256:<64 hex> pin
    • script-tests, with dependencies: [mortis.kamino.x] in roles/docker/meta/main.yml: FAIL: test_roles_call_each_other_by_full_name_only … docker declares role dependencies
    • script-tests, with the helper's GIT_* filter removed: FAILED (errors=42), fatal: Invalid path '/dev/null/not-a-repo': Not a directory
  • check_bot_pr_diff.py still accepts a Renovate rev: bump; its existing unit tests pass.
  • CI: see the checks on this PR.

Not verified

  • The proxy guard in CI. This PR changes .pre-commit-config.yaml, a ci image input, so its own Lint run takes the slow path, where the guard is off. Running script-tests under the guard is verified only locally (above). CI first exercises it on Renovate's ci pin PR after the new ci image is published.
  • The script-tests filter is narrower than what the suite reads. Some tests also read role tasks, workflows, molecule.yml and renovate.json, so a push that touches only those skips the hook locally. Lint still runs the whole suite on every PR.
  • Molecule was not run. No scenario is selected.

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

Assisted-by: Claude Code

## What and why Closes #187 Closes #246 **#187: move checks from Lint into hooks** - `check-json` is added from the pre-commit-hooks repository already pinned in the config. No new hook environment is needed. - `check-image-pins` is a local commit-stage hook with `always_run: true`. - #187 says the hook must fail on an empty file set. pre-commit can't do that, because a hook whose `files:` match nothing is skipped. This PR reads the requirement as: the hook always runs, and `check_image_versions.py pins` already fails when its inputs are missing. - Lint's "Check image pins" step is removed. So is its "Not a pre-commit hook" comment, which has been out of date since the ci image started rebuilding automatically. - `script-tests` is a local hook in the **pre-push** stage, not the commit stage, because the suite takes about 2 minutes. - It runs only when `scripts/`, `tests/scripts/` or a role's `meta/` changed. - Lint now runs it by id: `pre-commit run --hook-stage pre-push script-tests --all-files`. This replaces the "Test the repository scripts" step. - The entry sets an uncreatable `GIT_DIR`. A fixture that leaks the caller's git environment then fails instead of writing to the real repository. - **Git fixtures:** a new `tests/scripts/git_env.py` drops `GIT_*` from the environment. Three test files leaked it, not the one #187 names: `test_check_bot_pr_diff.py`, `test_check_image_versions.py` and `test_check_scenarios_load_checkout.py`. `test_select_molecule_scenarios.py` now uses the helper in place of its inline copy. - **Proxy guard:** `test_next_image_version.py` sets `no_proxy=127.0.0.1` for the fake registry. The suite now runs under Lint's dead-proxy guard with nothing unset. **#246: meta dependencies** - The Lint check already exists: `test_roles_call_each_other_by_full_name_only` asserts that every role has an empty `dependencies` list. The docs that called a meta dependency allowed, or said the rule was held by review, now name that test: `roles/AGENTS.md`, `.gitea/workflows/AGENTS.md` and the docstring of `scripts/select_molecule_scenarios.py`. - The selector case is already covered by `test_a_change_selects_its_users_transitively`. - ansible-lint 26.10.1 has no rule for meta dependencies, and yq is not in the ci image. Every doc that named the removed Lint steps is updated: the workflow, scripts and images AGENTS.md files, `docs/images/ci.md`, the comment in `images/ci/Dockerfile`, `requirements-dev.txt` and AGENTS.md "Verify a change". There is no changelog fragment: this is tooling only, and every path is in `build_ignore`. ## Verified - `python3 -m unittest discover -s tests/scripts` passes 380 tests in each of three runs: plain, with `GIT_DIR=/dev/null/not-a-repo`, and with Lint's guard set (`PIP_NO_INDEX=1`, the proxies on `127.0.0.1:9`, an empty `no_proxy`). - `pre-commit run --hook-stage pre-push script-tests --all-files` passes, and so does `git push`, which runs the pre-push hooks (ansible-test sanity and script-tests). - Each new hook fails on a broken input that was not committed: - `check-json`, with `renovate.json` truncated: `renovate.json: Failed to json decode (Expecting property name enclosed in double quotes: line 3 column 1 (char 12))` - `check-image-pins`, with a bad ci pin in `lint.yml`: `::error::.gitea/workflows/lint.yml: '…nosuchimage:0.2.54@sha256:1234' is not a <name>:<version>@sha256:<64 hex> pin` - `script-tests`, with `dependencies: [mortis.kamino.x]` in `roles/docker/meta/main.yml`: `FAIL: test_roles_call_each_other_by_full_name_only … docker declares role dependencies` - `script-tests`, with the helper's `GIT_*` filter removed: `FAILED (errors=42)`, `fatal: Invalid path '/dev/null/not-a-repo': Not a directory` - `check_bot_pr_diff.py` still accepts a Renovate `rev:` bump; its existing unit tests pass. - CI: see the checks on this PR. ## Not verified - **The proxy guard in CI.** This PR changes `.pre-commit-config.yaml`, a ci image input, so its own Lint run takes the slow path, where the guard is off. Running `script-tests` under the guard is verified only locally (above). CI first exercises it on Renovate's ci pin PR after the new ci image is published. - **The `script-tests` filter is narrower than what the suite reads.** Some tests also read role tasks, workflows, `molecule.yml` and `renovate.json`, so a push that touches only those skips the hook locally. Lint still runs the whole suite on every PR. - **Molecule was not run.** No scenario is selected. --- - [ ] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code
Claude added 5 commits 2026-12-06 19:55:51 +00:00
A git hook exports GIT_DIR (and often GIT_INDEX_FILE). A fixture that passes
the caller's environment to git would run its init, add and commit against
this repository instead of its temporary one once the suite runs as a hook.

tests/scripts/git_env.py gives each fixture a copy of the environment
without any GIT_* key and with no user or system config. The bot pull
request gate's repository tests also isolate os.environ, because the gate
runs git in-process.

Refs: #187

Assisted-by: Claude Code
Lint's fast path exports a dead proxy with an empty no_proxy, and
next_image_version.py uses urllib's default opener, which honours them, so
the RegistryClient tests could not reach their fake registry on 127.0.0.1.
Setting no_proxy for loopback in the tests lets the suite run under the
guard instead of the workflow unsetting it.

Refs: #187

Assisted-by: Claude Code
A contributor learns about a broken renovate.json, a failing script test or
a bad image pin from Lint today; as hooks they fail before the push.

- check-json from pre-commit-hooks covers renovate.json.
- script-tests runs the suite at pre-push, since it takes minutes. Its
  GIT_DIR points at an uncreatable path, so a fixture that keeps the
  caller's git environment fails instead of writing to this repository.
  Lint runs it by id; the suite now runs under the network guard.
- check-image-pins runs check_image_versions.py pins on every commit: its
  inputs span workflows, Dockerfiles and docs/images, and it fails when one
  is missing. Lint's pre-commit run replaces its separate step.

Adding hooks changes .pre-commit-config.yaml, an input of the ci image, so
this pull request takes Lint's slow path and the next Images run publishes
a new ci version.

Refs: #187

Assisted-by: Claude Code
test_roles_call_each_other_by_full_name_only in
tests/scripts/test_select_molecule_scenarios.py already fails when a role's
meta/main.yml declares dependencies, and Lint runs it through the
script-tests hook. That test is the Lint check the rule waited for, so the
rule now names it as its control, and the workflow rules and the selector's
docstring no longer describe a meta dependency as allowed.

Refs: #246

Assisted-by: Claude Code
docs(agents): say that a push also runs the script tests
Build / build (pull_request) Successful in 30s
Lint / renovate-config (pull_request) Successful in 9s
Molecule / select (pull_request) Successful in 8s
Molecule / scenarios (pull_request) Skipped
Molecule / Result (pull_request) Successful in 1s
Lint / lint (pull_request) Successful in 2m20s
26d7b4914c
Refs: #187

Assisted-by: Claude Code
CODEOWNERS rules requested review from Defame1297 2026-12-06 19:55:51 +00:00
Defame1297 scheduled this pull request to auto merge when all checks succeed 2026-12-06 20:24:23 +00:00
Defame1297 approved these changes 2026-12-06 20:24:38 +00:00
Defame1297 merged commit 3b91a40db1 into main 2026-12-06 20:24:43 +00:00
Defame1297 deleted branch ci/187-246-shift-left-checks 2026-12-06 20:24:46 +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#527