fix(verdict): a rebuild that regresses is never an improvement
CI / Tests, lint (pull_request) Successful in 18s

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
This commit is contained in:
Christian Manivong committed 2026-11-15 22:43:55 +01:00
1 parent 77b31ed835
commit 015c6e18cb
6 files changed
+397 -28

No files matched your search

+208 -4
View File
@@ -2,8 +2,13 @@
Trivy lists the packages of both, netOrk's matcher in kb-server judges both in
one call (so against one state of its data, kb-server#155), and the verdict is
"improved" when a critical or high CVE with a fix is closed by a patch, or
Debian made a point release. Everything else is "same": the pin stays.
"improved" when a critical or high CVE with a fix is closed by a patch, Debian
made a point release, or a component the image is built for moved. Everything
else is "same": the pin stays.
A candidate that is worse than the pin anywhere, on an older base-os, with a
Debian point release backwards or with a new critical or high CVE that has a
fix, is "regressed" whatever else it brings (NetOrk/image-tools#3, netork#2523).
A matcher that cannot be asked is never an improvement: no pin moves on a guess.
"""
@@ -15,7 +20,7 @@ import subprocess
import pytest
from image_tools.verify import Verdict, judge, render, verify
from image_tools.verify import Verdict, base_os_version, judge, read_changes, render, verify
CLOSED = {
"cve": "CVE-2026-1111",
@@ -25,6 +30,15 @@ CLOSED = {
"fixed": "3.5.1-1+deb13u1",
}
NEW = {"cve": "CVE-2026-2222", "package": "nginx", "severity": "critical", "installed": "1.26.3-4"}
#: What netork#2523's candidate brought back: zlib of the older base-os.
ZLIB = {
"cve": "CVE-2026-76844",
"package": "zlib",
"severity": "high",
"installed": "1:1.3.dfsg+really1.3.1-1",
"fixed": "1:1.3.dfsg+really1.3.1-1+deb13u1",
}
PINNED_BASE, OLDER_BASE = "13-20261108.1", "13-20261025.1"
def _answer(closed=(), new=()):
@@ -75,9 +89,96 @@ class TestJudge:
assert not judge(_answer(closed=[closed]), "13.7", "13.7").improved
def test_an_older_base_os_is_a_regression_whatever_else_closed(self):
verdict = judge(_answer(closed=[CLOSED]), "13.7", "13.7", base_os=(PINNED_BASE, OLDER_BASE))
assert not verdict.improved
assert verdict.base_os == (PINNED_BASE, OLDER_BASE)
assert verdict.regressions == [f"base-os goes back: {PINNED_BASE} → {OLDER_BASE}"]
def test_a_newer_base_os_is_no_regression(self):
verdict = judge(_answer(closed=[CLOSED]), "13.7", "13.7", base_os=(OLDER_BASE, PINNED_BASE))
assert verdict.improved and verdict.regressions == []
def test_the_same_base_os_is_not_recorded(self):
verdict = judge(_answer(closed=[CLOSED]), "13.7", "13.7", base_os=(PINNED_BASE,) * 2)
assert verdict.improved and verdict.base_os is None
@pytest.mark.parametrize(
"current,candidate,back",
[
("13-20261108.9", "13-20261108.10", False),
("13-20261108.2", "13-20261108.1", True),
("13-20261108.1", "12-20261201.1", True),
],
)
def test_base_os_versions_compare_as_numbers(self, current, candidate, back):
verdict = judge(_answer(closed=[CLOSED]), "13.7", "13.7", base_os=(current, candidate))
assert bool(verdict.regressions) is back
@pytest.mark.parametrize("odd", ["dev", "", "13-2026110.1", "latest"])
def test_a_base_os_version_that_cannot_be_compared_is_refused(self, odd):
"""No pin moves on a guess: an unreadable base-os is no verdict."""
with pytest.raises(ValueError):
judge(_answer(closed=[CLOSED]), "13.7", "13.7", base_os=(PINNED_BASE, odd))
def test_a_new_cve_with_a_fix_is_a_regression(self):
"""The CVE gate's rule: it can be closed, so the candidate is not better."""
verdict = judge(_answer(closed=[CLOSED], new=[ZLIB]), "13.7", "13.7")
assert not verdict.improved
assert verdict.new == [ZLIB]
assert verdict.regressions == [
"CVE-2026-76844 (zlib, high) is new and has a fix: 1:1.3.dfsg+really1.3.1-1+deb13u1"
]
def test_a_point_release_counts_only_forwards(self):
verdict = judge(_answer(), "13.8", "13.7")
assert not verdict.improved
assert verdict.point_release is None
assert verdict.regressions == ["Debian goes back: 13.8 → 13.7"]
def test_a_debian_version_that_is_no_number_still_counts_as_a_point_release(self):
verdict = judge(_answer(), "trixie/sid", "13.1")
assert verdict.improved and verdict.point_release == ("trixie/sid", "13.1")
def test_a_changed_component_is_an_improvement_on_its_own(self):
"""A new PostgreSQL minor moves the pin even when no CVE closed."""
change = "PostgreSQL 17.11-0+deb13u1 → 17.12-0+deb13u1"
verdict = judge(_answer(), "13.7", "13.7", changes=[change])
assert verdict.improved
assert verdict.changes == [change]
def test_a_changed_component_on_an_older_base_os_is_no_improvement(self):
"""netork#2523: 17.12 on base-os 13-20261025.1 against a pin on 13-20261108.1."""
verdict = judge(
_answer(new=[ZLIB]),
"13.7",
"13.7",
base_os=(PINNED_BASE, OLDER_BASE),
changes=["PostgreSQL 17.11-0+deb13u1 → 17.12-0+deb13u1"],
)
assert not verdict.improved
assert verdict.regressions[0] == f"base-os goes back: {PINNED_BASE} → {OLDER_BASE}"
assert "CVE-2026-76844" in verdict.regressions[1]
class TestVerify:
def _deps(self, answer=None, error=None, versions=("13.7", "13.7"), failing=((), ())):
def _deps(
self,
answer=None,
error=None,
versions=("13.7", "13.7"),
failing=((), ()),
bases=(PINNED_BASE, PINNED_BASE),
):
calls = {"sbom": [], "match": []}
def sbom(ref):
@@ -92,11 +193,13 @@ class TestVerify:
debian = dict(zip(("cur", "cand"), versions, strict=True))
cis = dict(zip(("cur", "cand"), map(set, failing), strict=True))
base = dict(zip(("cur", "cand"), bases, strict=True))
return calls, {
"sbom": sbom,
"match": match,
"debian_version": lambda ref: debian["cur" if ref == "cur" else "cand"],
"cis_failing": lambda ref: cis["cur" if ref == "cur" else "cand"],
"base_os_version": lambda ref: base["cur" if ref == "cur" else "cand"],
}
def test_both_go_to_the_matcher_in_one_call(self):
@@ -146,6 +249,39 @@ class TestVerify:
seams["cis_failing"] = broken
assert not verify("cur", "cand", **seams).improved
def test_the_2523_candidate_is_regressed_not_improved(self):
"""A new component goes through the verdict, which sees the older base-os."""
_, seams = self._deps(answer=_answer(new=[ZLIB]), bases=(PINNED_BASE, OLDER_BASE))
verdict = verify("cur", "cand", changes=["PostgreSQL 17.11 → 17.12"], **seams)
assert not verdict.improved and verdict.error is None
assert verdict.base_os == (PINNED_BASE, OLDER_BASE)
assert verdict.changes == ["PostgreSQL 17.11 → 17.12"]
def test_a_changed_component_on_the_same_base_is_an_improvement(self):
_, seams = self._deps(answer=_answer())
assert verify("cur", "cand", changes=["PostgreSQL 17.11 → 17.12"], **seams).improved
@pytest.mark.parametrize(
"broken",
[
subprocess.CalledProcessError(1, "docker"),
ValueError("no VERSION in /etc/netork/base-os"),
],
)
def test_a_base_os_that_cannot_be_read_moves_nothing(self, broken):
_, seams = self._deps(answer=_answer(closed=[CLOSED]))
def read(ref):
raise broken
seams["base_os_version"] = read
verdict = verify("cur", "cand", changes=["x 1 → 2"], **seams)
assert not verdict.improved and verdict.error
def test_the_report_names_what_closed_and_what_is_new():
verdict = judge(_answer(closed=[CLOSED], new=[NEW]), "13.7", "13.8", ["docker:4.1"])
@@ -167,6 +303,71 @@ def test_the_verdict_is_json_for_the_workflow():
assert data["closed"][0]["cve"] == "CVE-2026-1111"
def test_the_report_leads_with_the_regression():
verdict = judge(
_answer(closed=[CLOSED], new=[ZLIB]),
"13.7",
"13.7",
base_os=(PINNED_BASE, OLDER_BASE),
changes=["PostgreSQL 17.11 → 17.12"],
)
text = render(verdict, "cur", "cand")
first, rest = text.split("\n", 1)
assert first.startswith("**Regressed** (the pin stays):")
assert "improved" not in first.lower()
regressions = rest.index("### Regressions")
assert regressions < rest.index("### Closed critical/high")
assert f"- base-os goes back: {PINNED_BASE} → {OLDER_BASE}" in text
assert "- CVE-2026-76844 (zlib, high) is new and has a fix" in text
assert "- PostgreSQL 17.11 → 17.12" in text
def test_the_report_names_the_change_and_the_base_os_move():
verdict = judge(
_answer(),
"13.7",
"13.7",
base_os=(OLDER_BASE, PINNED_BASE),
changes=["valkey 8.1.9 → 8.1.10"],
)
text = render(verdict, "cur", "cand")
assert text.startswith("**Improved**")
assert "- valkey 8.1.9 → 8.1.10" in text
assert f"base-os: {OLDER_BASE} → {PINNED_BASE}" in text
def test_the_regressions_are_json_for_the_workflow():
data = json.loads(judge(_answer(), "13.8", "13.7").to_json())
assert data["improved"] is False
assert data["regressions"] == ["Debian goes back: 13.8 → 13.7"]
def test_the_change_lines_come_from_a_file_without_blanks_or_bullets(tmp_path):
path = tmp_path / "changes.txt"
path.write_text("SIGNAL_CLI 0.14.8 → 0.14.9\n\n- REST_API 0.95 → 0.96\n \n")
assert read_changes(path) == ["SIGNAL_CLI 0.14.8 → 0.14.9", "REST_API 0.95 → 0.96"]
@pytest.mark.parametrize(
"record,version",
[
("VERSION=13-20261108.1\nSNAPSHOT=20261108T040000Z\n", "13-20261108.1"),
("SNAPSHOT=20261108T040000Z\nVERSION=13-20261025.1", "13-20261025.1"),
],
)
def test_the_base_os_version_is_read_from_its_record(record, version):
assert base_os_version(record) == version
def test_a_record_without_a_version_is_refused():
with pytest.raises(ValueError):
base_os_version("SNAPSHOT=20261108T040000Z\n")
def test_a_verdict_has_no_surprise_fields():
assert set(Verdict.__dataclass_fields__) == {
"improved",
@@ -176,4 +377,7 @@ def test_a_verdict_has_no_surprise_fields():
"cis_closed",
"counts",
"error",
"base_os",
"changes",
"regressions",
}