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

@@ -1,8 +1,8 @@
from __future__ import annotations
import unittest
import unittest.mock
from types import SimpleNamespace
from unittest import mock
from cli.administration.deploy.dedicated import command
from cli.administration.deploy.dedicated.command import (
@@ -12,12 +12,12 @@ from cli.administration.deploy.dedicated.command import (
class TestPullCustomRoles(unittest.TestCase):
@mock.patch("cli.administration.deploy.dedicated.command.pull_or_exit")
@unittest.mock.patch("cli.administration.deploy.dedicated.command.pull_or_exit")
def test_pulls_the_inventory_by_default(self, pull_or_exit):
pull_custom_roles(SimpleNamespace(inventory="inv/devices.yml", skip_pull=False))
pull_or_exit.assert_called_once_with("inv/devices.yml")
@mock.patch("cli.administration.deploy.dedicated.command.pull_or_exit")
@unittest.mock.patch("cli.administration.deploy.dedicated.command.pull_or_exit")
def test_skip_pull_keeps_the_placed_roles(self, pull_or_exit):
pull_custom_roles(SimpleNamespace(inventory="inv/devices.yml", skip_pull=True))
pull_or_exit.assert_not_called()
@@ -26,11 +26,13 @@ class TestPullCustomRoles(unittest.TestCase):
calls: list[str] = []
args = SimpleNamespace(inventory="inv/devices.yml", skip_pull=False)
with (
mock.patch.object(command, "parse_args", return_value=(args, [], {})),
mock.patch.object(
unittest.mock.patch.object(
command, "parse_args", return_value=(args, [], {})
),
unittest.mock.patch.object(
command, "pull_or_exit", side_effect=lambda _inv: calls.append("pull")
),
mock.patch.object(
unittest.mock.patch.object(
command,
"run_from_args",
side_effect=lambda *_a: calls.append("deploy") or 0,
@@ -2,8 +2,8 @@ from __future__ import annotations
import json
import unittest
import unittest.mock
from types import SimpleNamespace
from unittest import mock
from ansible.parsing.splitter import parse_kv
@@ -12,7 +12,7 @@ from cli.administration.deploy.development.deploy.run import _run_deploy
class TestRunDeploy(unittest.TestCase):
def deploy_cmd(self, extra_ansible_vars=None) -> list[str]:
compose = mock.Mock()
compose = unittest.mock.Mock()
compose.exec.return_value = SimpleNamespace(returncode=0)
_run_deploy(
compose,
@@ -258,11 +258,6 @@ class TestBuildDevInventoryMatrix(unittest.TestCase):
"cli.administration.deploy.development.inventory.legacy_resolver._resolve_round_include",
autospec=True,
)
@patch(
"cli.administration.deploy.development.inventory.legacy_resolver._build_services_overrides_for_round",
autospec=True,
return_value={},
)
@patch(
"cli.administration.deploy.development.inventory.builder.build_dev_inventory",
autospec=True,
@@ -279,7 +274,6 @@ class TestBuildDevInventoryMatrix(unittest.TestCase):
self,
_variants_mock: MagicMock,
build_inventory_mock: MagicMock,
_overrides_mock: MagicMock,
resolve_include_mock: MagicMock,
) -> None:
resolve_include_mock.side_effect = [
@@ -1,8 +1,8 @@
from __future__ import annotations
import unittest
import unittest.mock
from types import SimpleNamespace
from unittest import mock
from cli.administration.deploy.swarm import command
@@ -17,14 +17,18 @@ class TestSwarmMain(unittest.TestCase):
return ids
with (
mock.patch.object(command, "parse_args", return_value=(args, [], {})),
mock.patch.object(
unittest.mock.patch.object(
command, "parse_args", return_value=(args, [], {})
),
unittest.mock.patch.object(
command,
"pull_custom_roles",
side_effect=lambda _args: calls.append("pull"),
),
mock.patch.object(command, "swarm_deploy_targets", side_effect=closure),
mock.patch.object(command, "run_from_args", return_value=0) as run,
unittest.mock.patch.object(
command, "swarm_deploy_targets", side_effect=closure
),
unittest.mock.patch.object(command, "run_from_args", return_value=0) as run,
):
self.assertEqual(0, command.main([]))