mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
fix(codescan): clear the mechanical CodeQL notes and lint them away (WIP)
Work-in-progress commit on the collective code-scanning sidetree, so main can be merged in; the single quality-high gate runs on the integration branch before the pull request. Fixes the CodeQL notes py/import-and-import-from, py/unused-import, py/unused-global-variable, py/empty-except, py/mixed-tuple-returns and py/unused-local-variable across 194 files, and adds one lint per rule under tests/lint/repository/python/ so none of them can come back: test_import_and_import_from, test_unused_imports_hidden_from_ruff, test_unused_global_variables, test_empty_except, test_mixed_tuple_returns, test_unused_local_variables, plus test_modules_import. Accepted security finding: MEDUSA-MP-SCAN-2056 (low) on utils/i18n/client.py:21, an import line matched by a keyword heuristic; operator-confirmed false positive. 🎯 Fix: 85 % 💥 Break: 8 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 78 🚦 Gate: ⛔ fix 85 % < 90, break 8 % > 5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3fdfce419e
commit
326f063bd3
194 files changed
+1663
-590
No files matched your search
@@ -5,8 +5,8 @@ import http.client
|
||||
import io
|
||||
import json
|
||||
import unittest
|
||||
import unittest.mock
|
||||
import urllib.error
|
||||
from unittest import mock
|
||||
|
||||
from utils.update.follow import followed_tags, tag_digest
|
||||
|
||||
@@ -31,12 +31,12 @@ def _digests(table: dict[str, str]):
|
||||
|
||||
class TestFollowedTags(unittest.TestCase):
|
||||
def test_ubuntu_on_the_lts_gets_no_interim_release(self) -> None:
|
||||
with mock.patch("utils.update.follow.tag_digest", _digests(UBUNTU)):
|
||||
with unittest.mock.patch("utils.update.follow.tag_digest", _digests(UBUNTU)):
|
||||
found = followed_tags("ubuntu", list(UBUNTU), {"follow": "latest"}, "26.04")
|
||||
self.assertEqual(found, [])
|
||||
|
||||
def test_fedora_moves_to_the_stable_release_not_rawhide(self) -> None:
|
||||
with mock.patch("utils.update.follow.tag_digest", _digests(FEDORA)):
|
||||
with unittest.mock.patch("utils.update.follow.tag_digest", _digests(FEDORA)):
|
||||
found = followed_tags("fedora", list(FEDORA), {"follow": "latest"}, "44")
|
||||
self.assertEqual(found, ["45"])
|
||||
|
||||
@@ -48,7 +48,9 @@ class TestFollowedTags(unittest.TestCase):
|
||||
def test_an_unreadable_registry_proposes_nothing_and_says_so(self) -> None:
|
||||
stderr = io.StringIO()
|
||||
with (
|
||||
mock.patch("utils.update.follow.tag_digest", side_effect=OSError("429")),
|
||||
unittest.mock.patch(
|
||||
"utils.update.follow.tag_digest", side_effect=OSError("429")
|
||||
),
|
||||
contextlib.redirect_stderr(stderr),
|
||||
):
|
||||
found = followed_tags("fedora", list(FEDORA), {"follow": "latest"}, "44")
|
||||
@@ -58,7 +60,7 @@ class TestFollowedTags(unittest.TestCase):
|
||||
def test_an_incomplete_response_proposes_nothing_and_says_so(self) -> None:
|
||||
stderr = io.StringIO()
|
||||
with (
|
||||
mock.patch(
|
||||
unittest.mock.patch(
|
||||
"utils.update.follow.get",
|
||||
side_effect=http.client.IncompleteRead(b"{", 120),
|
||||
),
|
||||
@@ -79,10 +81,10 @@ class TestFollowedTags(unittest.TestCase):
|
||||
"3.14.2-slim",
|
||||
]
|
||||
with (
|
||||
mock.patch(
|
||||
unittest.mock.patch(
|
||||
"utils.update.follow.requires_python", return_value=">=3.11,<3.16"
|
||||
),
|
||||
mock.patch("utils.update.follow.tag_digest") as digest,
|
||||
unittest.mock.patch("utils.update.follow.tag_digest") as digest,
|
||||
contextlib.redirect_stderr(io.StringIO()),
|
||||
):
|
||||
found = followed_tags(
|
||||
@@ -93,10 +95,10 @@ class TestFollowedTags(unittest.TestCase):
|
||||
|
||||
def test_requires_python_at_the_cap_proposes_nothing(self) -> None:
|
||||
with (
|
||||
mock.patch(
|
||||
unittest.mock.patch(
|
||||
"utils.update.follow.requires_python", return_value=">=3.11,<3.15"
|
||||
),
|
||||
mock.patch(
|
||||
unittest.mock.patch(
|
||||
"utils.update.follow.tag_digest", return_value="sha256:one"
|
||||
) as digest,
|
||||
contextlib.redirect_stderr(io.StringIO()),
|
||||
@@ -114,16 +116,16 @@ class TestFollowedTags(unittest.TestCase):
|
||||
limited = urllib.error.HTTPError("url", 429, "Too Many Requests", {}, None)
|
||||
body = json.dumps({"digest": "sha256:45"}).encode()
|
||||
with (
|
||||
mock.patch("utils.update.follow.get", side_effect=[limited, body]),
|
||||
mock.patch("utils.update.follow.time.sleep"),
|
||||
unittest.mock.patch("utils.update.follow.get", side_effect=[limited, body]),
|
||||
unittest.mock.patch("utils.update.follow.time.sleep"),
|
||||
):
|
||||
self.assertEqual(tag_digest("fedora", "latest"), "sha256:45")
|
||||
|
||||
def test_a_persistent_rate_limit_still_raises(self) -> None:
|
||||
limited = urllib.error.HTTPError("url", 429, "Too Many Requests", {}, None)
|
||||
with (
|
||||
mock.patch("utils.update.follow.get", side_effect=[limited] * 3),
|
||||
mock.patch("utils.update.follow.time.sleep"),
|
||||
unittest.mock.patch("utils.update.follow.get", side_effect=[limited] * 3),
|
||||
unittest.mock.patch("utils.update.follow.time.sleep"),
|
||||
self.assertRaises(urllib.error.HTTPError),
|
||||
):
|
||||
tag_digest("fedora", "latest")
|
||||
|
||||
@@ -3,8 +3,8 @@ from __future__ import annotations
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
import unittest.mock
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from utils.cache.files import read_text
|
||||
from utils.roles.mapping import ROLE_DIR_META_ADDONS, ROLE_FILE_META_SERVICES
|
||||
@@ -374,8 +374,8 @@ def _write_role(
|
||||
|
||||
def _find(root: Path, ls_remote: _LsRemote) -> list[RepositoryRefUpdate]:
|
||||
with (
|
||||
mock.patch.object(module, "resolve_max_fetch_workers", return_value=2),
|
||||
mock.patch.object(module.subprocess, "run", side_effect=ls_remote),
|
||||
unittest.mock.patch.object(module, "resolve_max_fetch_workers", return_value=2),
|
||||
unittest.mock.patch.object(module.subprocess, "run", side_effect=ls_remote),
|
||||
):
|
||||
return find_outdated_updates(root)
|
||||
|
||||
@@ -414,7 +414,9 @@ class TestIsCommitSha(unittest.TestCase):
|
||||
class TestGitLsRemoteHead(unittest.TestCase):
|
||||
def test_returns_the_head_commit(self) -> None:
|
||||
ls_remote = _LsRemote(heads={SHA_REPO: TIP_SHA})
|
||||
with mock.patch.object(module.subprocess, "run", side_effect=ls_remote):
|
||||
with unittest.mock.patch.object(
|
||||
module.subprocess, "run", side_effect=ls_remote
|
||||
):
|
||||
self.assertEqual(git_ls_remote_head(SHA_REPO), TIP_SHA)
|
||||
self.assertEqual(ls_remote.calls, [(SHA_REPO, "HEAD")])
|
||||
|
||||
@@ -426,12 +428,16 @@ class TestGitLsRemoteHead(unittest.TestCase):
|
||||
):
|
||||
with (
|
||||
self.subTest(failure=type(failure).__name__),
|
||||
mock.patch.object(module.subprocess, "run", side_effect=failure),
|
||||
unittest.mock.patch.object(
|
||||
module.subprocess, "run", side_effect=failure
|
||||
),
|
||||
):
|
||||
self.assertIsNone(git_ls_remote_head(SHA_REPO))
|
||||
|
||||
def test_an_empty_answer_returns_none(self) -> None:
|
||||
with mock.patch.object(module.subprocess, "run", side_effect=_LsRemote()):
|
||||
with unittest.mock.patch.object(
|
||||
module.subprocess, "run", side_effect=_LsRemote()
|
||||
):
|
||||
self.assertIsNone(git_ls_remote_head(SHA_REPO))
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user