Files
computer-playbook/tests/unit/utils/update/test_base.py
T
kevinveenbirkenbachandClaude Opus 4.7 98457f98fd refactor(update): unify version bumpers under utils/update + cli/contributing/update + scripts/github/update
Folds the parallel Docker-image and git-ref version-update plumbing
into a single subsystem so the auto-update workflow, the external
freshness tests, and the unit tests all share one module layout.

utils/
  update/
    base.py        # semver primitives shared by both backends
    docker.py      # OCI registry lookups + version: line rewriter
    repository.py  # git ls-remote walker + ref: line rewriter

cli/contributing/update/
  docker/           # python -m cli.contributing.update.docker
  repository/       # python -m cli.contributing.update.repository

scripts/github/update/
  image_versions.sh
  repository_refs.sh

Tests mirror the same shape under tests/{unit,external}/update/{docker,repository}/.

Also widens the Docker bump scope to all roles (previously gated on
`web-*`) so non-web roles like sys-svc-container get bumped too;
pins Bookwyrm's python image at 3.11-bookworm via
`# nocheck: docker-version` with a TODO until upstream supports
Python >= 3.12.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 20:12:07 +02:00

64 lines
2.1 KiB
Python

from __future__ import annotations
import unittest
from utils.update.base import (
is_semver,
latest_semver,
version_depth,
version_flavor,
version_key,
)
class TestUpdateBase(unittest.TestCase):
def test_latest_semver_respects_depth(self) -> None:
tags = ["4", "4.5", "4.6", "4.5.1", "5"]
self.assertEqual(latest_semver(tags, 1), "5")
self.assertEqual(latest_semver(tags, 2), "4.6")
self.assertEqual(latest_semver(tags, 3), "4.5.1")
def test_is_semver_accepts_flavored_tag(self) -> None:
# Docker Official Image tags embed a runtime flavor after the
# numeric semver, e.g. joomla:5.4.5-php8.3-apache.
self.assertTrue(is_semver("5.4.5-php8.3-apache"))
self.assertTrue(is_semver("v1.2.3-alpha"))
# Non-numeric prefix (e.g. flowise's `main-v1.77.3.dynamic_rates`)
# still MUST NOT be considered a semver tag.
self.assertFalse(is_semver("main-v1.77.3.dynamic_rates"))
self.assertFalse(is_semver("alpine"))
def test_version_key_and_depth_ignore_flavor(self) -> None:
self.assertEqual(version_key("5.4.5-php8.3-apache"), (5, 4, 5, 0))
self.assertEqual(version_depth("5.4.5-php8.3-apache"), 3)
self.assertEqual(version_flavor("5.4.5-php8.3-apache"), "-php8.3-apache")
self.assertEqual(version_flavor("5.4.5"), "")
def test_latest_semver_matches_flavor(self) -> None:
tags = [
"5.4.4-php8.3-apache",
"5.4.5-php8.3-apache",
"5.4.6-php8.3-apache",
"5.4.6-php8.4-apache",
"5.4.6-php8.3-fpm",
"5.4.7",
"alpine",
]
self.assertEqual(
latest_semver(tags, 3, "-php8.3-apache"),
"5.4.6-php8.3-apache",
)
# Different flavor MUST NOT leak across as an upgrade candidate.
self.assertEqual(
latest_semver(tags, 3, "-php8.4-apache"),
"5.4.6-php8.4-apache",
)
# Flavor-less current version MUST stay in the unflavored lane.
self.assertEqual(latest_semver(tags, 3, ""), "5.4.7")
if __name__ == "__main__":
unittest.main()