mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
1d57e22926 raised web-app-docs' mermaid_version from 11.4.1 to 12.1.0 and left
mermaid_sha256 describing the 11.4.1 asset. The Dockerfile fetches that asset
with ADD --checksum, so every round that deploys docs died in the build with
#7 ERROR: digest mismatch sha256:6484afc3...: sha256:a43bc1af...
which names neither the pin nor the role. Seven of the eleven failures of run
37440146966 are this one line. The pin now carries the digest the CDN actually
serves, measured three ways that agree: a host curl, the new helper, and
buildkit's own computed value in those jobs.
The separation is the real defect, so the updater closes it. A version pin may
now declare checksum_key and checksum_url beside its type, and after writing a
new version apply_updates refetches that URL with {version} substituted, hashes
it, and replaces the value on the checksum_key line of the same entity block.
A pin that declares neither behaves as before and performs no request.
invalid_declarations rejects the two ways the declaration could silently do
nothing: a checksum_key naming a key the entity does not carry, and a
checksum_url without the placeholder.
source.py stood at 496 of the 500-line cap, so the three line locators move to
utils/update/pins.py and checksum.rewrite reuses them instead of repeating the
block-scoped search.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
import unittest.mock as mock
|
|
from typing import ClassVar
|
|
|
|
from utils.update import checksum as module
|
|
|
|
DIGEST = "6484afc32872a3aa16cac9a76ba1816a1ed4cc870a6593cc2e17757750f518b2"
|
|
STALE = "a43bc1afd446f9c4cc66ac5dd45d02e8d65e26fc5344ec0ef787f88d6ddb6f9e"
|
|
|
|
|
|
class TestRewrite(unittest.TestCase):
|
|
SOURCE: ClassVar[dict[str, str]] = {
|
|
"key": "mermaid_version",
|
|
"checksum_key": "mermaid_sha256",
|
|
"checksum_url": "https://example.test/mermaid@{version}/mermaid.min.js",
|
|
}
|
|
|
|
def _lines(self) -> list[str]:
|
|
return [
|
|
"docs:\n",
|
|
" mermaid_version: 12.1.0\n",
|
|
f" mermaid_sha256: {STALE}\n",
|
|
"other:\n",
|
|
f" mermaid_sha256: {STALE}\n",
|
|
]
|
|
|
|
def test_the_digest_of_the_new_version_replaces_the_one_in_its_block(self) -> None:
|
|
lines = self._lines()
|
|
|
|
with mock.patch.object(module, "digest", return_value=DIGEST) as fetched:
|
|
module.rewrite(lines, "docs", self.SOURCE, "12.2.0")
|
|
|
|
fetched.assert_called_once_with(
|
|
"https://example.test/mermaid@12.2.0/mermaid.min.js"
|
|
)
|
|
self.assertEqual(lines[2], f" mermaid_sha256: {DIGEST}\n")
|
|
self.assertEqual(lines[4], f" mermaid_sha256: {STALE}\n")
|
|
|
|
def test_a_pin_without_a_declared_checksum_fetches_nothing(self) -> None:
|
|
lines = self._lines()
|
|
|
|
with mock.patch.object(module, "digest") as fetched:
|
|
module.rewrite(lines, "docs", {"key": "mermaid_version"}, "12.2.0")
|
|
|
|
fetched.assert_not_called()
|
|
self.assertEqual(lines, self._lines())
|
|
|
|
|
|
class TestProblems(unittest.TestCase):
|
|
CONFIG: ClassVar[dict[str, str]] = {
|
|
"mermaid_version": "12.1.0",
|
|
"mermaid_sha256": STALE,
|
|
}
|
|
|
|
def test_a_complete_declaration_reports_nothing(self) -> None:
|
|
self.assertEqual(
|
|
module.problems(
|
|
"web-app-docs/docs",
|
|
"mermaid_version",
|
|
self.CONFIG,
|
|
TestRewrite.SOURCE,
|
|
),
|
|
[],
|
|
)
|
|
|
|
def test_a_missing_key_and_a_url_without_the_placeholder_are_reported(self) -> None:
|
|
found = module.problems(
|
|
"web-app-docs/docs",
|
|
"mermaid_version",
|
|
self.CONFIG,
|
|
{"checksum_key": "absent", "checksum_url": "https://example.test/x.js"},
|
|
)
|
|
|
|
self.assertEqual(len(found), 2)
|
|
self.assertIn("names no key beside the version pin", found[0])
|
|
self.assertIn(module.PLACEHOLDER, found[1])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|