diff --git a/.github/workflows/call-test-workspace.yml b/.github/workflows/call-test-workspace.yml index 7af6d5dc81..102f25ae7d 100644 --- a/.github/workflows/call-test-workspace.yml +++ b/.github/workflows/call-test-workspace.yml @@ -70,6 +70,8 @@ jobs: INFINITO_CACHE_PACKAGE_HEAP: 1g INFINITO_CACHE_PACKAGE_DIRECT_MEM: 1g INFINITO_CACHE_PACKAGE_HOST_PATH: /mnt/cache/package/data + INFINITO_GHCR_MIRROR: "true" + INFINITO_GHCR_MIRROR_PREFIX: mirror steps: - name: ๐Ÿงน Free disk space @@ -96,6 +98,7 @@ jobs: grep '^INFINITO_DNS53_SAMPLER_LOG=' .env echo "INFINITO_WORKSPACE_SLUG=$(printf '%s' "${DEV_RUNTIME_IMAGE}" | tr '/:' '--')-${{ matrix.track }}" } >> "$GITHUB_ENV" + rm -f .env - name: "๐Ÿ“ฅ Resolve the workspace distro" shell: bash @@ -129,6 +132,8 @@ jobs: -e INFINITO_CACHE_PACKAGE_HEAP \ -e INFINITO_CACHE_PACKAGE_DIRECT_MEM \ -e INFINITO_CACHE_PACKAGE_HOST_PATH \ + -e INFINITO_GHCR_MIRROR \ + -e INFINITO_GHCR_MIRROR_PREFIX \ --network host \ -v "${HOST_WORKDIR}:${HOST_WORKDIR}" \ -v "/mnt/docker:/var/lib/docker" \ diff --git a/.github/workflows/cron-security-fuzz.yml b/.github/workflows/cron-security-fuzz.yml new file mode 100644 index 0000000000..56e4a1e9f1 --- /dev/null +++ b/.github/workflows/cron-security-fuzz.yml @@ -0,0 +1,46 @@ +name: "๐Ÿงฌ Fuzz parsers" +run-name: "${{ github.event_name == 'schedule' && 'โฐ ' || '' }}๐Ÿงฌ Fuzz parsers" + +on: + schedule: + - cron: "0 4 * * 0" + workflow_dispatch: + +concurrency: + group: fuzz-${{ github.repository }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + fuzz-yaml-bootstrap: + name: ๐Ÿงฌ Fuzz the bootstrap YAML reader + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: โฌ‡๏ธ Checkout + uses: actions/checkout@v7.0.0 + + - name: ๐Ÿ”ง Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.12" + cache: pip + cache-dependency-path: pyproject.toml + + - name: ๐Ÿ“ฆ Install project with the fuzz extra + env: + PYTHON: python3 + run: bash scripts/install/python.sh fuzz + + - name: ๐Ÿงฌ Compare load_block against yaml.safe_load + run: python3 tests/fuzz/_yaml_bootstrap.py -max_total_time=900 + + - name: ๐Ÿ“ค Upload crash inputs + if: failure() + uses: actions/upload-artifact@v7 + with: + name: fuzz-crashes + path: crash-* + retention-days: 30 diff --git a/Makefile b/Makefile index 487b1dcbdd..69fa10e386 100644 --- a/Makefile +++ b/Makefile @@ -800,6 +800,7 @@ swarm-zombie: install-act disable=$(disable); \ SWARM_NAME=$(or $(name),$(app)); \ INFINITO_SWARM_STEP_TIMEOUT_MINUTES=$(or $(step_timeout),690); \ + INFINITO_GHCR_MIRROR=$${INFINITO_GHCR_MIRROR}; \ INFINITO_DISTROS=$(SWARM_DISTROS)" \ ACT_WORKFLOW=.github/workflows/call-test-deploy.yml \ ACT_JOB=deploy \ diff --git a/cli/administration/deploy/development/profile.py b/cli/administration/deploy/development/profile.py index 04d8203807..b76112a522 100644 --- a/cli/administration/deploy/development/profile.py +++ b/cli/administration/deploy/development/profile.py @@ -37,7 +37,8 @@ class Profile: def image_mirror_enabled(self) -> bool: """True iff image references should be rewritten to the GHCR mirror.""" - return self.runs_on_github() + declared = _declared("INFINITO_GHCR_MIRROR") + return self.runs_on_github() if declared is None else declared def docker_root_ephemeral(self) -> bool: """True iff the docker data root may be wiped when the stack goes down.""" diff --git a/default.env b/default.env index 1c504d7b34..e2bbd9c60c 100644 --- a/default.env +++ b/default.env @@ -199,6 +199,9 @@ INFINITO_FORK_REPOSITORY_NAME=infinito-nexus-core # IPv4 of the bridge gateway inside INFINITO_SUBNET. INFINITO_GATEWAY=172.30.0.1 +# True where images come from the GHCR mirror instead of their upstream registry (real GitHub Actions). +INFINITO_GHCR_MIRROR=false + # Prefix path under which GHCR mirror lookups search for cached images. INFINITO_GHCR_MIRROR_PREFIX=mirror diff --git a/docs/agents/action/iteration/workflow.md b/docs/agents/action/iteration/workflow.md index 49d6bbca62..b4451da308 100644 --- a/docs/agents/action/iteration/workflow.md +++ b/docs/agents/action/iteration/workflow.md @@ -34,6 +34,6 @@ Two properties of the workspace suite differ between `make act-workflow` and a G **Nested Docker state does not survive a teardown locally, but does in CI.** `INFINITO_DOCKER_VOLUME` is the named volume `docker` ([default.env](../../../../default.env)) and a host path (`/mnt/docker`) on GitHub. `compose down -v` removes a named volume and cannot remove a bind mount, so every workspace track starts on a clean inner daemon locally while CI carries the previous track's containers into the next one. Defects that need a container, network, or bind source to outlive a teardown cannot reproduce under act. -**The runtime identity differs.** act sets `ACT=true`, so `detect_gha_act()` in [runtime.py](../../../../utils/env/runtime.py) resolves `INFINITO_RUNNING_ON_GITHUB=false` where a real runner resolves `true`. Anything keyed off that fact behaves differently, and act cannot prove a fix to it either way. +**The runtime identity differs.** act sets `ACT=true`, so `detect_gha_act()` in [runtime.py](../../../../utils/env/runtime.py) resolves `INFINITO_RUNNING_ON_GITHUB=false` where a real runner resolves `true`. Anything keyed off that fact behaves differently, and act cannot prove a fix to it either way. The image mirror is the exception: CI declares `INFINITO_GHCR_MIRROR=true` for the workspace suite, while a local run keeps the generated `false` and pulls upstream. Run the local loop to iterate quickly; treat CI as the only authority for both classes. diff --git a/docs/contributing/artefact/git/pipeline.md b/docs/contributing/artefact/git/pipeline.md index 3cb37ddba5..e0e923d34e 100644 --- a/docs/contributing/artefact/git/pipeline.md +++ b/docs/contributing/artefact/git/pipeline.md @@ -77,8 +77,9 @@ The two deploy-test workflows listed in the `Infrastructure tests` table of [wor 1. **Sentinel `__ALL__` in the `whitelist` input** (case-insensitive). The diff logic MUST be skipped and an empty whitelist MUST be emitted, which deploys everything in the workflow's scope. This is the explicit opt-out from diff narrowing for manual dispatch. 2. **Any other non-empty `whitelist`** (forwarded from `entry-manual-steer.yml` and similar). The explicit value MUST win over the diff and is passed through verbatim. 3. **Diff vs `origin/main`**, applied only when the `whitelist` input is empty: - - **No diff at all** OR **any changed path outside `roles//...`**: no whitelist is set, so the full deploy across the workflow's scope runs. - - **All changed paths under `roles//...`**: the changed roles become the seed set, and the whitelist is the transitive closure of those seeds expanded upwards over `run_after`, `dependencies`, and shared services. In other words, every role whose prerequisite set as defined by [combined resolver](../../../../cli/meta/roles/applications/resolution/combined/resolver.py) contains one of the seeds is included, together with the seeds themselves. + - **Skipped paths:** `.md` and `.rst` files and everything under `tests/` outside `roles//...` neither seed a role nor widen the deploy. + - **No diff at all**, OR **any other changed path outside `roles//...`**, OR **only skipped paths**: no whitelist is set, so the full deploy across the workflow's scope runs. + - **All remaining changed paths under `roles//...`**: the changed roles become the seed set, and the whitelist is the transitive closure of those seeds expanded upwards over `run_after`, `dependencies`, and shared services. In other words, every role whose prerequisite set as defined by [combined resolver](../../../../cli/meta/roles/applications/resolution/combined/resolver.py) contains one of the seeds is included, together with the seeds themselves. Each role in that closure is then narrowed to the variants that actually reach a seed: variant `i` of a role is kept only when round `i`'s closure โ€” walked on the same variant-merged services maps [the matrix planner](../../../../cli/administration/deploy/development/inventory/planner.py) builds its rounds from, and therefore variant-aware at every generation of the chain โ€” contains one of the seeds. A role whose variants do not all qualify enters the whitelist as a `role#0,2` selection token, so an image bump in a provider no longer redeploys the variants that switch that provider off. This applies to every auto-derived whitelist โ€” the weekly update PRs, Dependabot, and any other diff-driven run โ€” because they all resolve through this one path. diff --git a/docs/contributing/artefact/image/mirror.md b/docs/contributing/artefact/image/mirror.md index e2f97cf848..36ffe55616 100644 --- a/docs/contributing/artefact/image/mirror.md +++ b/docs/contributing/artefact/image/mirror.md @@ -73,6 +73,8 @@ The mirror workflow runs as stage 8 of the CI pipeline. See [ci.md](../git/pipel 4. Inventory generation writes the resulting mirror refs from `mirrors.yml` back into host vars. 5. Deploy and test jobs resolve images from `ghcr.io/{namespace}/{repository}/mirror/...` instead of pulling directly from Docker Hub, MCR, or other upstream registries. +`INFINITO_GHCR_MIRROR` decides whether a run uses the mirror. The generated `.env` sets it to `true` on a real GitHub runner and to `false` everywhere else, act included. A non-empty exported value overrides that for one run. [call-test-workspace.yml](../../../../.github/workflows/call-test-workspace.yml) exports `true`, so the workspace suite runs like a local setup and still pulls from GHCR, in its compose drills and, through `make swarm-zombie`, in its swarm drills. + The mirrors file is generated into the inventory directory. The inventory creator applies mirror image overrides to host variables via `cli/administration/inventory/provision/mirror_overrides.py`, which reads `mirrors.yml.applications` and writes `applications.{role}.services.{service}.image` (and `.version`) into host vars subject to the per-service `mirror_policy`. diff --git a/docs/contributing/tools/github/actions/workflows.md b/docs/contributing/tools/github/actions/workflows.md index 89c56190cb..a91618daae 100644 --- a/docs/contributing/tools/github/actions/workflows.md +++ b/docs/contributing/tools/github/actions/workflows.md @@ -43,6 +43,7 @@ Trigger column legend: **auto** = fires automatically (push, pull_request, sched | Workflow | Description | Trigger | Inputs | |---|---|---|---| | [cron-security-codeql.yml](../../../../../.github/workflows/cron-security-codeql.yml): `๐Ÿ” Scan with CodeQL` | CodeQL static analysis. Invoked by [call-orchestrator.yml](../../../../../.github/workflows/call-orchestrator.yml) so every CI run produces a single scan; additionally runs on a weekly cron so coverage does not drop when no pushes land on `main`. See [pipeline.md](../../../artefact/git/pipeline.md) for the gating behaviour. | reusable, auto (`schedule`: weekly Mon 00:00 UTC) | none | +| [cron-security-fuzz.yml](../../../../../.github/workflows/cron-security-fuzz.yml): `๐Ÿงฌ Fuzz parsers` | Runs the [atheris](https://github.com/google/atheris) harness [_yaml_bootstrap.py](../../../../../tests/fuzz/_yaml_bootstrap.py) for 15 minutes and uploads every crashing input as the `fuzz-crashes` artifact. Reproduce one locally with `pip install -e ".[fuzz]"` and `python3 tests/fuzz/_yaml_bootstrap.py `. | auto (`schedule`: weekly Sun 04:00 UTC), manual | none | | [call-lint.yml](../../../../../.github/workflows/call-lint.yml): `๐Ÿงน Lint` | Runs `make lint` (every lint check in parallel: action, ansible, javascript, makefile, markdown, mermaid, packages, playwright, python, shellcheck) plus a hadolint SARIF job on `Dockerfile`. | reusable, manual | none | ### CI images ๐Ÿณ diff --git a/pyproject.toml b/pyproject.toml index 77d63272ac..40601c3146 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ license = { file = "LICENSE.md" } dependencies = [ # Pinned: utils/recovery reads the generation layout from baudolo's own # BackupPaths, so the version here and in svc-bkp-volume-2-local must match. - "backup-docker-to-local==7.0.2", + "backup-docker-to-local==7.1.1", "bcrypt", "cryptography", "humanfriendly", @@ -40,6 +40,9 @@ dev = [ "pytest>=9.1", "pytest-xdist", ] +fuzz = [ + "atheris==3.1.0", +] [project.scripts] infinito = "cli.__main__:main" diff --git a/roles/svc-bkp-volume-2-local/tasks/01_install.yml b/roles/svc-bkp-volume-2-local/tasks/01_install.yml index 8d839fad6e..6a1424737a 100644 --- a/roles/svc-bkp-volume-2-local/tasks/01_install.yml +++ b/roles/svc-bkp-volume-2-local/tasks/01_install.yml @@ -3,7 +3,7 @@ include_role: name: sys-pip-install vars: - package_name: "backup-docker-to-local==7.0.2" + package_name: "backup-docker-to-local==7.1.1" global_install: true - name: โœ… Assert required baudolo commands are available diff --git a/roles/web-app-pixelfed/meta/services.yml b/roles/web-app-pixelfed/meta/services.yml index 10fa557e0a..6cf7984bc7 100644 --- a/roles/web-app-pixelfed/meta/services.yml +++ b/roles/web-app-pixelfed/meta/services.yml @@ -49,7 +49,7 @@ pixelfed: shared: true enabled: true # nocheck: dynamic-flag image: zknt/pixelfed - version: "20261008" + version: "20261017" name: pixelfed min_storage: 588MB backup: diff --git a/roles/web-app-zammad/README.md b/roles/web-app-zammad/README.md index eb01babf80..2018400d9b 100644 --- a/roles/web-app-zammad/README.md +++ b/roles/web-app-zammad/README.md @@ -94,7 +94,7 @@ Solid `1:1` edges are fixed relationships; dashed `0..1` edges are conditional ( - **LDAP federation:** When `svc-db-openldap` is present, Zammad authenticates and provisions accounts against the central LDAP. - **Mail-to-ticket:** When `web-app-stalwart` is present, the `helpdesk` mailbox is auto-provisioned and Zammad polls it to create tickets from incoming mail. - **Server-name alias:** `zammad.helpdesk.{{ DOMAIN_PRIMARY }}` is a true vhost alias of `helpdesk.{{ DOMAIN_PRIMARY }}` (not a 301 redirect). -- **Bundled Elasticsearch:** Search engine ships with the role until a central `svc-db-elasticsearch` exists. +- **Bundled Elasticsearch:** Search engine ships with the role until a central `svc-db-elasticsearch` exists. Its disk watermarks follow the disk size (85 / 90 / 95 % used, requiring at most 200 / 150 / 100 GB free, `services.search.watermark`); the CI and development variants lower those caps to 10 / 5 / 2 GB. - **Search index per Elasticsearch major:** The index lives in a directory named after the Elasticsearch major inside the `zammad_search` volume. A new major starts on an empty directory and `zammad-init` rebuilds the index from the database on the same deploy. - **Wizard bypass:** First deploy seeds `auto_wizard.json` so no manual setup UI step is required. diff --git a/roles/web-app-zammad/meta/services.yml b/roles/web-app-zammad/meta/services.yml index bceafa4e8b..3b2cb98902 100644 --- a/roles/web-app-zammad/meta/services.yml +++ b/roles/web-app-zammad/meta/services.yml @@ -120,6 +120,14 @@ search: type: registry_tags image: docker.elastic.co/elasticsearch/elasticsearch min_storage: 839MB + watermark: + low: "85%" + high: "90%" + flood_stage: "95%" + max_headroom: + low: 200gb + high: 150gb + flood_stage: 100gb cpus: "1.0" mem_reservation: 1g mem_limit: 2g diff --git a/roles/web-app-zammad/meta/variants.yml b/roles/web-app-zammad/meta/variants.yml index 38cb4ddfb5..4947c9812b 100644 --- a/roles/web-app-zammad/meta/variants.yml +++ b/roles/web-app-zammad/meta/variants.yml @@ -36,6 +36,12 @@ shared: true redis: shared: true + search: + watermark: + max_headroom: + low: 10gb + high: 5gb + flood_stage: 2gb litellm: enabled: false tor: @@ -83,6 +89,12 @@ shared: false # nocheck: variants-static-override backup shared stays literally true redis: shared: false # nocheck: variants-static-override backup shared stays literally true + search: + watermark: + max_headroom: + low: 10gb + high: 5gb + flood_stage: 2gb litellm: enabled: false tor: @@ -133,6 +145,12 @@ shared: false # nocheck: variants-static-override backup shared stays literally true redis: shared: true + search: + watermark: + max_headroom: + low: 10gb + high: 5gb + flood_stage: 2gb tor: enabled: true openwebui: diff --git a/roles/web-app-zammad/templates/compose.yml.j2 b/roles/web-app-zammad/templates/compose.yml.j2 index 1891a8514c..364bfc16db 100644 --- a/roles/web-app-zammad/templates/compose.yml.j2 +++ b/roles/web-app-zammad/templates/compose.yml.j2 @@ -56,6 +56,12 @@ - xpack.security.enabled=false - ES_JAVA_OPTS=-Xms{{ ZAMMAD_SEARCH_HEAP_MB }}m -Xmx{{ ZAMMAD_SEARCH_HEAP_MB }}m - path.data={{ ZAMMAD_SEARCH_DATA_DIR }} + - cluster.routing.allocation.disk.watermark.low={{ ZAMMAD_SEARCH_WATERMARK.low }} + - cluster.routing.allocation.disk.watermark.high={{ ZAMMAD_SEARCH_WATERMARK.high }} + - cluster.routing.allocation.disk.watermark.flood_stage={{ ZAMMAD_SEARCH_WATERMARK.flood_stage }} + - cluster.routing.allocation.disk.watermark.low.max_headroom={{ ZAMMAD_SEARCH_WATERMARK.max_headroom.low }} + - cluster.routing.allocation.disk.watermark.high.max_headroom={{ ZAMMAD_SEARCH_WATERMARK.max_headroom.high }} + - cluster.routing.allocation.disk.watermark.flood_stage.max_headroom={{ ZAMMAD_SEARCH_WATERMARK.max_headroom.flood_stage }} {{ lookup('container_volumes', service_name) | indent(4) }} {{ lookup('container_extra_hosts') | indent(4) }} {{ lookup('container_networks') | indent(4) }} diff --git a/roles/web-app-zammad/vars/main.yml b/roles/web-app-zammad/vars/main.yml index d4c5a815b2..726c967327 100644 --- a/roles/web-app-zammad/vars/main.yml +++ b/roles/web-app-zammad/vars/main.yml @@ -23,6 +23,7 @@ ZAMMAD_RAILS_PORT: "{{ lookup('config', application_id, 'services.' ~ ZAMMAD_RAI ZAMMAD_WEBSOCKET_PORT: "{{ lookup('config', application_id, 'services.' ~ ZAMMAD_WEBSOCKET_SERVICE ~ '.ports.internal.http') }}" ZAMMAD_SEARCH_PORT: "{{ lookup('config', application_id, 'services.' ~ ZAMMAD_SEARCH_SERVICE ~ '.ports.internal.http') }}" ZAMMAD_SEARCH_HEAP_MB: "{{ lookup('service_memory_mb', application_id, ZAMMAD_SEARCH_SERVICE, 0.25) }}" +ZAMMAD_SEARCH_WATERMARK: "{{ lookup('config', application_id, 'services.search.watermark') }}" ZAMMAD_SEARCH_MAJOR: "{{ (lookup('config', application_id, 'services.search.version') | string).split('.') | first }}" ZAMMAD_SEARCH_DATA_DIR: "{{ [lookup('volume', application_id, 'zammad_search').target, ZAMMAD_SEARCH_MAJOR] | path_join }}" diff --git a/scripts/meta/resolve/diff/affected_roles.sh b/scripts/meta/resolve/diff/affected_roles.sh index a6beb59ec7..273869c759 100755 --- a/scripts/meta/resolve/diff/affected_roles.sh +++ b/scripts/meta/resolve/diff/affected_roles.sh @@ -8,11 +8,12 @@ # __ALL__ full deploy needed. Emitted when: # * the diff is empty, OR # * any changed path outside -# roles// is not a Markdown -# or reStructuredText file (the -# `.md`/`.rst` skip-list mirrors +# roles// is neither a +# Markdown or reStructuredText file +# (the `.md`/`.rst` skip-list mirrors # scripts/meta/resolve/pr/scope.sh's -# `is_markdown_or_rst`), OR +# `is_markdown_or_rst`) nor under +# tests/, OR # * the diff contains only such # skipped paths and no role seeds # could be derived, OR @@ -75,7 +76,7 @@ for path in "${changed_paths[@]}"; do [[ -z "${path}" ]] && continue if [[ "${path}" != roles/*/* ]]; then case "${path}" in - *.md | *.rst) + *.md | *.rst | tests/*) continue ;; esac diff --git a/scripts/tests/deploy/swarm/routine/02_provision_inventory.sh b/scripts/tests/deploy/swarm/routine/02_provision_inventory.sh index 4f99a8b0d7..82372be673 100755 --- a/scripts/tests/deploy/swarm/routine/02_provision_inventory.sh +++ b/scripts/tests/deploy/swarm/routine/02_provision_inventory.sh @@ -28,10 +28,10 @@ fi if [[ -n "${INFINITO_APP_VARIANTS:-}" ]]; then provision_args+=(--app-variants "${INFINITO_APP_VARIANTS}") fi -if [[ "$(python3 -m cli.meta.runtime)" == "github" ]]; then - : "${INFINITO_GHCR_MIRROR_PREFIX:?required in github runtime}" - : "${GITHUB_REPOSITORY_OWNER:?required in github runtime}" - : "${GITHUB_REPOSITORY:?required in github runtime}" +if [[ "${INFINITO_GHCR_MIRROR:?INFINITO_GHCR_MIRROR must be set}" == "true" ]]; then + : "${INFINITO_GHCR_MIRROR_PREFIX:?required when INFINITO_GHCR_MIRROR=true}" + : "${GITHUB_REPOSITORY_OWNER:?required when INFINITO_GHCR_MIRROR=true}" + : "${GITHUB_REPOSITORY:?required when INFINITO_GHCR_MIRROR=true}" ghcr_namespace="$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')" ghcr_repository="$(echo "${GITHUB_REPOSITORY}" | cut -d/ -f2- | tr '[:upper:]' '[:lower:]')" mirrors_file="${INV_DIR}/mirrors.yml" diff --git a/scripts/tests/workspace/README.md b/scripts/tests/workspace/README.md index 96baaf3763..f26bbc3f77 100644 --- a/scripts/tests/workspace/README.md +++ b/scripts/tests/workspace/README.md @@ -2,6 +2,7 @@ This directory contains the modular workspace test suite for Infinito.Nexus. It validates the full local development flow from a clean state. +In CI it runs exactly like that flow, except that it pulls images through the GHCR mirror (`INFINITO_GHCR_MIRROR=true`, see [mirror.md](../../../docs/contributing/artefact/image/mirror.md)). The entry point is [00_orchestrator.sh](00_orchestrator.sh). It runs one or more *tracks* โ€” subdirectories whose numbered scripts execute in order. diff --git a/tests/README.md b/tests/README.md index b537cc461c..5d71c2c246 100644 --- a/tests/README.md +++ b/tests/README.md @@ -10,5 +10,6 @@ All automated tests for Infinito.Nexus live here. | `e2e/` | End-to-end Playwright tests | [playwright.md](../docs/contributing/actions/testing/playwright.md) | | `regression/` | Regression guard rules | [regression.md](../docs/contributing/actions/testing/regression.md) | | `lint/` | Structural lint checks | [lint.md](../docs/contributing/actions/testing/lint.md) | +| `fuzz/` | Coverage-guided atheris harnesses, run weekly in CI, excluded from `make test` | [workflows.md](../docs/contributing/tools/github/actions/workflows.md) | Run each suite via the `make` targets documented in the linked guides. diff --git a/tests/external/repository/_package_probes.py b/tests/external/repository/_package_probes.py index c50a379f15..3c29384087 100644 --- a/tests/external/repository/_package_probes.py +++ b/tests/external/repository/_package_probes.py @@ -38,11 +38,10 @@ DEBIAN_SUITE = "stable" UBUNTU_SUITE = "noble" FEDORA_RELEASE = "f44" CENTOS_STREAM = "10-stream" +EPEL_BRANCH = f"epel{CENTOS_STREAM.split('-', maxsplit=1)[0]}" +EPEL_BOOTSTRAP = "epel-release" BOOTSTRAP_BASEURL: dict[str, str] = { - "epel-release": ( - "https://dl.fedoraproject.org/pub/epel/$releasever/Everything/$basearch/" - ), "centos-release-nfs-ganesha11": ( "https://mirror.stream.centos.org/SIGs/$releasever-stream" "/storage/$basearch/nfsganesha-11/" @@ -253,18 +252,30 @@ def _probe_apt(distro: str, name: str) -> tuple[bool | None, str]: return name in names, detail -def _probe_fedora(name: str) -> tuple[bool | None, str]: +def _probe_mdapi(branch: str, name: str) -> tuple[bool | None, str]: + """Ask Fedora's metadata API whether ``branch`` carries ``name``. + + Args: + branch: an mdapi branch, such as ``f44`` or ``epel10``. + name: the binary package name as the declaration spells it. + + Returns: + Availability, or None with the reason the index stayed unknown. + """ status, _ = _get( - f"https://mdapi.fedoraproject.org/{FEDORA_RELEASE}/pkg/" - f"{urllib.parse.quote(name)}" + f"https://mdapi.fedoraproject.org/{branch}/pkg/{urllib.parse.quote(name)}" ) if status == 200: - return True, f"mdapi {FEDORA_RELEASE}" + return True, f"mdapi {branch}" if status in (400, 404): - return False, f"mdapi {FEDORA_RELEASE}" + return False, f"mdapi {branch}" return None, f"mdapi returned HTTP {status}" +def _probe_fedora(name: str) -> tuple[bool | None, str]: + return _probe_mdapi(FEDORA_RELEASE, name) + + def _centos_repo_baseurl(repo: dict | None) -> str | None: if not isinstance(repo, dict): return None @@ -294,6 +305,13 @@ def _centos_listings(name: str, repo: dict | None) -> list[str] | None: def _probe_centos(name: str, repo: dict | None) -> tuple[bool | None, str]: + if ( + isinstance(repo, dict) + and not repo.get("baseurl") + and repo.get("bootstrap_package") == EPEL_BOOTSTRAP + ): + return _probe_mdapi(EPEL_BRANCH, name) + listings = _centos_listings(name, repo) if listings is None: return None, "the inline repository definition declares no baseurl" diff --git a/tests/fuzz/__init__.py b/tests/fuzz/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/fuzz/_yaml_bootstrap.py b/tests/fuzz/_yaml_bootstrap.py new file mode 100644 index 0000000000..f2eb18ef3d --- /dev/null +++ b/tests/fuzz/_yaml_bootstrap.py @@ -0,0 +1,22 @@ +import sys + +import atheris + +from utils.cache.yaml import load_yaml_str + +with atheris.instrument_imports(): + from utils.yaml_bootstrap import BootstrapYamlError, load_block + + +def fuzz_one_input(data: bytes) -> None: + text = data.decode("utf-8", errors="replace") + try: + parsed = load_block(text) + except BootstrapYamlError: + return + assert parsed == load_yaml_str(text), text + + +if __name__ == "__main__": + atheris.Setup(sys.argv, fuzz_one_input) + atheris.Fuzz() diff --git a/tests/integration/meta/workflows/test_diff_affected_roles.py b/tests/integration/meta/workflows/test_diff_affected_roles.py index c0ee2a8bd0..7d48bfab35 100644 --- a/tests/integration/meta/workflows/test_diff_affected_roles.py +++ b/tests/integration/meta/workflows/test_diff_affected_roles.py @@ -139,6 +139,25 @@ class TestDiffAffectedRoles(unittest.TestCase): ) self.assertEqual(self._run_script(repo, env), "web-app-foo") + def test_tests_outside_role_are_skipped_when_role_also_changed(self): + repo, env = self._setup_repo( + base_files={ROLE_TASKS_MAIN_REL: "- debug: msg=v1\n"}, + feature_files={ + ROLE_TASKS_MAIN_REL: "- debug: msg=v2\n", + "tests/unit/python/roles/web-app-foo/test_x.py": "x = 1\n", + "tests/integration/test_y.py": "y = 1\n", + }, + fake_resolver_stdout="web-app-foo", + ) + self.assertEqual(self._run_script(repo, env), "web-app-foo") + + def test_only_tests_outside_role_falls_back_to_all(self): + repo, env = self._setup_repo( + base_files={"tests/unit/test_z.py": "z = 1\n"}, + feature_files={"tests/unit/test_z.py": "z = 2\n"}, + ) + self.assertEqual(self._run_script(repo, env), "__ALL__") + def test_non_md_outside_role_still_triggers_all(self): repo, env = self._setup_repo( base_files={ROLE_TASKS_MAIN_REL: "- debug: msg=v1\n"}, diff --git a/tests/unit/python/cli/administration/deploy/development/test_compose.py b/tests/unit/python/cli/administration/deploy/development/test_compose.py index db5b966ab6..f76f2909a5 100644 --- a/tests/unit/python/cli/administration/deploy/development/test_compose.py +++ b/tests/unit/python/cli/administration/deploy/development/test_compose.py @@ -95,6 +95,7 @@ class TestComposeUpRetries(unittest.TestCase): "INFINITO_GIT_COMMON_DIR": "", "INFINITO_CACHE_NETWORK": "", "INFINITO_CACHE_STACK": "", + "INFINITO_GHCR_MIRROR": "", }, clear=False, ) @@ -150,6 +151,7 @@ class TestComposeUpRetries(unittest.TestCase): "INFINITO_GIT_COMMON_DIR": "", "INFINITO_CACHE_NETWORK": "", "INFINITO_CACHE_STACK": "", + "INFINITO_GHCR_MIRROR": "", }, clear=False, ) @@ -200,6 +202,7 @@ class TestComposeUpRetries(unittest.TestCase): "GITHUB_ACTIONS": "true", "INFINITO_RUNNING_ON_GITHUB": "true", "INFINITO_CACHE_STACK": "", + "INFINITO_GHCR_MIRROR": "", }, clear=False, ) @@ -227,6 +230,7 @@ class TestComposeUpRetries(unittest.TestCase): "GITHUB_ACTIONS": "true", "INFINITO_RUNNING_ON_GITHUB": "true", "INFINITO_CACHE_STACK": "", + "INFINITO_GHCR_MIRROR": "", }, clear=False, ) @@ -263,6 +267,7 @@ class TestComposeUpRetries(unittest.TestCase): "INFINITO_GIT_COMMON_DIR": "", "INFINITO_CACHE_NETWORK": "", "INFINITO_CACHE_STACK": "", + "INFINITO_GHCR_MIRROR": "", }, clear=False, ) diff --git a/tests/unit/python/cli/administration/deploy/development/test_env_compose_file_args.py b/tests/unit/python/cli/administration/deploy/development/test_env_compose_file_args.py index d2a7f6cd2b..e864110543 100644 --- a/tests/unit/python/cli/administration/deploy/development/test_env_compose_file_args.py +++ b/tests/unit/python/cli/administration/deploy/development/test_env_compose_file_args.py @@ -21,6 +21,7 @@ _LOCAL_PRIMARY = { "INFINITO_GIT_COMMON_DIR": "", "INFINITO_CACHE_NETWORK": "", "INFINITO_CACHE_STACK": "", + "INFINITO_GHCR_MIRROR": "", "INFINITO_PUBLISH_PORTS": "", } diff --git a/tests/unit/python/cli/administration/deploy/development/test_profile.py b/tests/unit/python/cli/administration/deploy/development/test_profile.py index ce4353e25d..1f20c12018 100644 --- a/tests/unit/python/cli/administration/deploy/development/test_profile.py +++ b/tests/unit/python/cli/administration/deploy/development/test_profile.py @@ -16,6 +16,7 @@ _BLANK_CI_ENV = { "INFINITO_GIT_COMMON_DIR": "", "INFINITO_CACHE_NETWORK": "", "INFINITO_CACHE_STACK": "", + "INFINITO_GHCR_MIRROR": "", } @@ -111,6 +112,31 @@ class TestProfileDeclaredCapabilities(unittest.TestCase): self.assertTrue(p.image_mirror_enabled()) self.assertTrue(p.docker_root_ephemeral()) + @patch.dict( + os.environ, + {**_BLANK_CI_ENV, "INFINITO_GHCR_MIRROR": "true"}, + clear=False, + ) + def test_a_mirror_declaration_changes_nothing_but_the_mirror(self) -> None: + p = Profile() + self.assertTrue(p.image_mirror_enabled()) + self.assertFalse(p.runs_on_github()) + self.assertFalse(p.is_ci()) + self.assertTrue(p.cache_stack_enabled()) + self.assertFalse(p.docker_root_ephemeral()) + + @patch.dict( + os.environ, + { + **_BLANK_CI_ENV, + "INFINITO_RUNNING_ON_GITHUB": "true", + "INFINITO_GHCR_MIRROR": "false", + }, + clear=False, + ) + def test_a_declared_false_turns_the_mirror_off_on_github(self) -> None: + self.assertFalse(Profile().image_mirror_enabled()) + class TestProfileInstance(unittest.TestCase): @patch.dict(os.environ, {**_BLANK_CI_ENV, "INFINITO_INSTANCE": ""}, clear=False) diff --git a/tests/unit/python/cli/administration/deploy/development/test_runner_mirror.py b/tests/unit/python/cli/administration/deploy/development/test_runner_mirror.py index cb9763515a..ead731a24c 100644 --- a/tests/unit/python/cli/administration/deploy/development/test_runner_mirror.py +++ b/tests/unit/python/cli/administration/deploy/development/test_runner_mirror.py @@ -74,6 +74,7 @@ class TestRunnerMirror(unittest.TestCase): "INFINITO_RUNNING_ON_GITHUB": "true", "INFINITO_GIT_COMMON_DIR": "", "INFINITO_CACHE_STACK": "", + "INFINITO_GHCR_MIRROR": "", "INFINITO_CACHE_NETWORK": "", "INFINITO_PUBLISH_PORTS": "", }, @@ -88,7 +89,9 @@ class TestRunnerMirror(unittest.TestCase): self.assertEqual(args[-2:], ["-f", runner_mirror.OVERRIDE]) @patch.dict( - os.environ, {**GITHUB, "INFINITO_RUNNING_ON_GITHUB": "true"}, clear=False + os.environ, + {**GITHUB, "INFINITO_RUNNING_ON_GITHUB": "true", "INFINITO_GHCR_MIRROR": ""}, + clear=False, ) def test_the_cert_generator_gets_the_mirrored_init_image(self) -> None: with tempfile.TemporaryDirectory() as tmp: diff --git a/tests/unit/python/utils/env/handlers/infinito/test_ghcr_mirror.py b/tests/unit/python/utils/env/handlers/infinito/test_ghcr_mirror.py new file mode 100644 index 0000000000..3242ff25c1 --- /dev/null +++ b/tests/unit/python/utils/env/handlers/infinito/test_ghcr_mirror.py @@ -0,0 +1,51 @@ +from __future__ import annotations + +import os +import unittest +from pathlib import Path +from unittest.mock import patch + +from utils.env.builder import BuildContext, EnvBuilder +from utils.env.handlers.infinito import ghcr_mirror as handler + +_BLANK = {handler.KEY: ""} + + +def _ctx(*, on_gha: bool = False, on_act: bool = False) -> BuildContext: + return BuildContext( + static={}, + static_comments={handler.KEY: handler.COMMENT}, + repo_root=Path("/repo"), + on_gha=on_gha, + on_act=on_act, + ) + + +def _apply(ctx: BuildContext) -> str: + eb = EnvBuilder() + handler.apply(eb, ctx) + return eb.values[handler.KEY] + + +class TestGhcrMirrorDefault(unittest.TestCase): + @patch.dict(os.environ, _BLANK, clear=False) + def test_a_developer_machine_pulls_upstream(self) -> None: + self.assertEqual(_apply(_ctx()), "false") + + @patch.dict(os.environ, _BLANK, clear=False) + def test_a_github_runner_uses_the_mirror(self) -> None: + self.assertEqual(_apply(_ctx(on_gha=True)), "true") + + @patch.dict(os.environ, _BLANK, clear=False) + def test_act_pulls_upstream(self) -> None: + self.assertEqual(_apply(_ctx(on_act=True)), "false") + + +class TestGhcrMirrorIsNotPinnable(unittest.TestCase): + @patch.dict(os.environ, {handler.KEY: "true"}, clear=False) + def test_a_live_declaration_is_recomputed_not_adopted(self) -> None: + self.assertEqual(_apply(_ctx()), "false") + + +if __name__ == "__main__": # pragma: no cover + unittest.main() diff --git a/tests/unit/python/utils/test_yaml_bootstrap.py b/tests/unit/python/utils/test_yaml_bootstrap.py index 9e1d948939..a2df6c1f15 100644 --- a/tests/unit/python/utils/test_yaml_bootstrap.py +++ b/tests/unit/python/utils/test_yaml_bootstrap.py @@ -115,6 +115,14 @@ STRUCTURES = ( "a: see this: here\n", "a:b\n", "a: # note\n", + "\x1e/: R\n", + "a: b\x0bc: d\n", + "# note\x01\na: b\n", + "# note\rc: d\n", + "# note\x85c: d\n", + "# note\N{LINE SEPARATOR}c: d\n", + "a: b\r\nc: d\r\n", + " ---\nC: L\n", ) diff --git a/utils/env/README.md b/utils/env/README.md index 92251b8d25..b1659d04f4 100644 --- a/utils/env/README.md +++ b/utils/env/README.md @@ -40,7 +40,7 @@ The writer a handler picks decides how long a value lives. Both kinds are regist `setdefault` is the operator-override contract: exporting a key changes it and the change persists. That persistence is why it MUST NOT carry a value an environment declares for a single run. [Makefile](../../Makefile) exports `BASH_ENV`, so every make recipe sources `.env` โ€” a value adopted once is re-exported into every later recipe and into every container that mounts the repo, and a per-run decision has silently become a property of the machine. -A key that some environment declares per run therefore MUST be written by a dedicated handler through `eb.set`. The exporting shell still wins for its own run, because [load.sh](../../scripts/meta/env/load.sh) preserves non-empty caller values when it sources `.env`; the file keeps the derived default. `INFINITO_RUNNING_ON_GITHUB` and `INFINITO_CACHE_STACK` are written this way. Note the consequence: for those keys `.env` and the running shell can legitimately disagree, and `.env` is not the authority. +A key that some environment declares per run therefore MUST be written by a dedicated handler through `eb.set`. The exporting shell still wins for its own run, because [load.sh](../../scripts/meta/env/load.sh) preserves non-empty caller values when it sources `.env`; the file keeps the derived default. `INFINITO_RUNNING_ON_GITHUB`, `INFINITO_CACHE_STACK` and `INFINITO_GHCR_MIRROR` are written this way. Note the consequence: for those keys `.env` and the running shell can legitimately disagree, and `.env` is not the authority. ## Import Rules ๐Ÿ”— diff --git a/utils/env/handlers/__init__.py b/utils/env/handlers/__init__.py index eef094cb8d..c4334d9438 100644 --- a/utils/env/handlers/__init__.py +++ b/utils/env/handlers/__init__.py @@ -19,6 +19,7 @@ from .infinito import ( container, distros, docker_volume, + ghcr_mirror, image, image_repository, inventory, @@ -71,6 +72,7 @@ ORDERED_HANDLERS = [ running_on_act, running_on_github, cache_stack, + ghcr_mirror, tor_socks_port, is_wsl2, ca_bundle_candidates, diff --git a/utils/env/handlers/infinito/ghcr_mirror.py b/utils/env/handlers/infinito/ghcr_mirror.py new file mode 100644 index 0000000000..136c370ba7 --- /dev/null +++ b/utils/env/handlers/infinito/ghcr_mirror.py @@ -0,0 +1,15 @@ +"""INFINITO_GHCR_MIRROR: whether image references are rewritten to the GHCR mirror.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from utils.env.builder import BuildContext, EnvBuilder + +KEY = "INFINITO_GHCR_MIRROR" +COMMENT = "True where images come from the GHCR mirror instead of their upstream registry (real GitHub Actions)." + + +def apply(eb: EnvBuilder, ctx: BuildContext) -> None: + eb.set(KEY, "true" if ctx.on_gha else "false", comment=COMMENT) diff --git a/utils/env/handlers/passthrough.py b/utils/env/handlers/passthrough.py index 04bd7c0eb8..80cda7bfe0 100644 --- a/utils/env/handlers/passthrough.py +++ b/utils/env/handlers/passthrough.py @@ -123,6 +123,7 @@ STATIC_KEYS = ( "INFINITO_GIT_COMMON_DIR", "INFINITO_CACHE_NETWORK", "INFINITO_CACHE_STACK", + "INFINITO_GHCR_MIRROR", "INFINITO_CACHE_REGISTRY_HOST_PATH", "INFINITO_CACHE_REGISTRY_CA_HOST_PATH", "INFINITO_CACHE_REGISTRY_IP", diff --git a/utils/yaml_bootstrap.py b/utils/yaml_bootstrap.py index eea2ae9726..18a1cd289f 100644 --- a/utils/yaml_bootstrap.py +++ b/utils/yaml_bootstrap.py @@ -24,6 +24,9 @@ import re _PLAIN = re.compile(r"^[A-Za-z_/][A-Za-z0-9_./+@:\- ]*$") _RESERVED = re.compile(r"^(?:true|false|yes|no|on|off|y|n|null)$", re.IGNORECASE) +_NON_PRINTABLE = re.compile( + "[^\x09\x0a\x0d\x20-\x7e\x85\xa0-\U0000d7ff\U0000e000-\U0000fffd\U00010000-\U0010ffff]" +) class BootstrapYamlError(ValueError): @@ -64,6 +67,11 @@ def load_block(text: str) -> dict: Raises: BootstrapYamlError: for any construct outside the subset. """ + non_printable = _NON_PRINTABLE.search(text) + if non_printable: + raise BootstrapYamlError( + f"non-printable character {non_printable.group()!r} at offset {non_printable.start()}" + ) root: dict = {} stack: list[tuple[int, object]] = [(0, root)] pending: tuple[dict, str, int] | None = None @@ -76,6 +84,8 @@ def load_block(text: str) -> dict: if body == "---": if lineno != 1: raise BootstrapYamlError(f"line {lineno}: second document") + if line.startswith(" "): + raise BootstrapYamlError(f"line {lineno}: indented document marker") continue indent = len(line) - len(line.lstrip(" ")) if pending is not None: