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:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-11-13 18:44:29 +00:00
1 parent 3fdfce419e
commit 326f063bd3
194 files changed
+1663 -590

No files matched your search

@@ -4,8 +4,8 @@ import contextlib
import io
import tarfile
import unittest
import unittest.mock
from pathlib import Path
from unittest import mock
from yaml.constructor import ConstructorError
@@ -16,7 +16,7 @@ from utils.roles.custom import CustomRoleError
class TestPullCommand(unittest.TestCase):
@mock.patch.object(
@unittest.mock.patch.object(
command, "pull", return_value=["web-app-cst-demo: repo path @ v1 (commit abc)"]
)
def test_pulls_the_inventory_into_the_core_roles(self, pull):
@@ -25,7 +25,7 @@ class TestPullCommand(unittest.TestCase):
pull.assert_called_once_with(Path("inv/devices.yml"), ROLES_DIR, WORK_DIR)
self.assertIn("web-app-cst-demo: repo path @ v1 (commit abc)", out.getvalue())
@mock.patch.object(command, "pull", return_value=[])
@unittest.mock.patch.object(command, "pull", return_value=[])
def test_nothing_declared_or_placed_prints_nothing(self, _pull):
with contextlib.redirect_stdout(io.StringIO()) as out:
command.main(["inv/devices.yml"])
@@ -39,7 +39,7 @@ class TestPullCommand(unittest.TestCase):
):
with self.subTest(error=type(error).__name__):
with (
mock.patch.object(command, "pull", side_effect=error),
unittest.mock.patch.object(command, "pull", side_effect=error),
contextlib.redirect_stderr(io.StringIO()) as err,
self.assertRaises(SystemExit) as exit_,
):
@@ -47,7 +47,7 @@ class TestPullCommand(unittest.TestCase):
self.assertEqual(1, exit_.exception.code)
self.assertIn(str(error), err.getvalue())
@mock.patch.object(
@unittest.mock.patch.object(
command,
"pull",
side_effect=CustomRoleError(
@@ -64,7 +64,7 @@ class TestPullCommand(unittest.TestCase):
self.assertNotIn("s3cr3t", err.getvalue())
self.assertIn("web-app-cst-demo: git fetch of v1 failed", err.getvalue())
@mock.patch.object(
@unittest.mock.patch.object(
command, "pull", side_effect=CustomRoleError("web-app-cst-demo: refused")
)
def test_refused_pull_exits_1_with_the_reason(self, _pull):