Files
kevinveenbirkenbachandClaude Opus 5.5 326f063bd3 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>
2026-11-13 18:44:29 +00:00

44 lines
1.3 KiB
Python

from __future__ import annotations
import contextlib
import io
import unittest
import unittest.mock
import cli.administration.roles.clean.__main__ as clean_main
class TestCleanMain(unittest.TestCase):
def test_reports_the_roles_it_removed_and_the_entries_it_left(self):
lines = [
"web-app-cst-a: removed",
"web-app-cst-hand: left in place, the pull did not place it",
]
with (
unittest.mock.patch.object(
clean_main, "clean", return_value=lines
) as clean,
contextlib.redirect_stdout(io.StringIO()) as out,
):
self.assertEqual(0, clean_main.main([]))
clean.assert_called_once_with(clean_main.ROLES_DIR, clean_main.WORK_DIR)
self.assertEqual(
"custom role web-app-cst-a: removed\n"
"custom role web-app-cst-hand: left in place, the pull did not place it\n",
out.getvalue(),
)
def test_a_filesystem_error_exits_with_it(self):
with (
unittest.mock.patch.object(
clean_main, "clean", side_effect=OSError("busy")
),
self.assertRaises(SystemExit) as exit_,
):
clean_main.main([])
self.assertIn("busy", str(exit_.exception.code))
if __name__ == "__main__":
unittest.main()