Files
image-tools/tests/test_actions.py
T
Christian Manivong 015c6e18cb
CI / Tests, lint (pull_request) Successful in 18s
fix(verdict): a rebuild that regresses is never an improvement
A candidate on an older base-os than the pin, with Debian's point release
going back, or with a critical or high CVE the pin does not have and that
has a fix (the CVE gate's rule) is now "regressed": the pin stays, whatever
else it closes, and the report names each regression first.

The verdict action takes the components a nightly says moved (changes);
each is an improvement on its own, but only through the verdict, so a new
PostgreSQL minor on an older base-os is judged instead of waved through
(NetOrk/netork#2523). verdict.json carries base_os, changes and regressions.
A base-os version that cannot be read is no verdict.

Closes #3
2026-11-15 22:43:55 +01:00

96 lines
3.9 KiB
Python

"""The composite actions every image repository of NetOrk uses (NetOrk/netork#1390).
uses: https://git.netork.io/NetOrk/image-tools/actions/<name>@<commit>
They only call what this repository holds, so a pinned commit fixes what runs.
"""
from __future__ import annotations
import re
from pathlib import Path
import pytest
import yaml
ROOT = Path(__file__).resolve().parents[1]
ACTIONS = sorted((ROOT / "actions").glob("*/action.yml"))
def test_the_actions():
names = [a.parent.name for a in ACTIONS]
assert names == ["bump", "cve-gate", "judge", "sign", "verdict", "verify-base"]
@pytest.mark.parametrize("action", ACTIONS, ids=lambda a: a.parent.name)
def test_an_action_runs_only_what_this_repository_holds(action):
spec = yaml.safe_load(action.read_text())
assert spec["runs"]["using"] == "composite"
for step in spec["runs"]["steps"]:
for script in re.findall(r"github\.action_path }}/\.\./\.\./(bin/[\w.-]+)", step["run"]):
assert (ROOT / script).is_file(), script
assert "${{ inputs." not in step["run"], "inputs reach a script through env"
def test_signing_needs_its_secrets_from_the_caller():
text = (ROOT / "actions/sign/action.yml").read_text()
assert "COSIGN_PRIVATE_KEY_B64" in text and "secrets." not in text
def test_a_verdict_that_could_not_be_reached_fails_the_step():
"""A silent "same" hid an empty NETORK_LICENSE_KEY for two nights (2026-10-21/22)."""
spec = yaml.safe_load((ROOT / "actions/verdict/action.yml").read_text())
[step] = spec["runs"]["steps"]
assert spec["outputs"]["improved"]["value"] == "${{ steps.verdict.outputs.improved }}"
assert "['error']" in step["run"] and "sys.exit(" in step["run"]
assert "cat report.md" in step["run"].splitlines()
def test_a_changed_component_reaches_the_verdict_instead_of_skipping_it():
"""netork#2523: a nightly that called a new package an improvement on its own never
asked the matcher, so a candidate on an older base-os went out. The change lines go
through the verdict now, which still judges the regression (image-tools#3)."""
spec = yaml.safe_load((ROOT / "actions/verdict/action.yml").read_text())
[step] = spec["runs"]["steps"]
assert spec["inputs"]["changes"]["default"] == ""
assert step["env"]["CHANGES"] == "${{ inputs.changes }}"
assert '--changes "$CHANGES"' in step["run"]
def test_the_cve_gate_fails_the_step_when_it_blocks_or_cannot_judge():
"""The gate's exit code is the step's: 1 for a new fixable CVE, 2 for no verdict
(an empty NETORK_LICENSE_KEY included). The report reaches the log either way."""
spec = yaml.safe_load((ROOT / "actions/cve-gate/action.yml").read_text())
[step] = spec["runs"]["steps"]
lines = step["run"].splitlines()
assert {"release", "candidate", "arch"} <= set(spec["inputs"])
assert spec["outputs"]["passed"]["value"] == "${{ steps.gate.outputs.passed }}"
assert "python3 -m image_tools.cve_gate" in step["run"]
assert "cat cve-gate.md" in lines
assert lines[-1] == 'exit "$status"'
assert "NETORK_LICENSE_KEY" in spec["description"] and "secrets." not in step["run"]
def test_bumping_needs_its_token_from_the_caller():
text = (ROOT / "actions/bump/action.yml").read_text()
assert "BUMP_TOKEN" in text and "secrets." not in text
def test_a_base_can_be_named_where_the_dockerfile_cannot():
"""base-python builds FROM ${BASE_OS}, an argument the nightly sets, and copies
CPython from Docker's python:3.12-slim, which is not signed with netOrk's key.
It names the one image to verify instead."""
spec = yaml.safe_load((ROOT / "actions/verify-base/action.yml").read_text())
runs = "\n".join(step["run"] for step in spec["runs"]["steps"])
assert not spec["inputs"]["dockerfiles"].get("required")
assert "refs" in spec["inputs"]
assert "bin/verify-signature.sh" in runs and "bin/verify-base.sh" in runs