mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 22:06:31 +00:00
fix(codescan): break the runtime import cycles CodeQL reports and lint new ones
CodeQL py/cyclic-import alerts #1023-#1029 and #1112-#1113 map to three cycles: utils.inventory.tools <-> libretranslate, utils.env.builder <-> its handlers, and utils.roles.applications.variants <-> the inventory legacy resolver. Each cycle loaded only because one side deferred an import into a function body. The shared piece now lives in a leaf module both sides import: utils/inventory/tools_vars.py, utils/env/context.py (BuildContext, EnvBuilder), and _resolve_round_include inside variants.py. The stricter lint found four more cycles, each broken the same way: compose <-> down (cli/administration/deploy/development/docker_root.py), the utils.cache package web (utils/cache/reset.py), utils.cache.carrier <-> users (utils/cache/tokens.py replaces users/store.py) and credentials -> provision (cli/administration/inventory/ruamel_io.py).
tests/lint/repository/python/test_import_cycles.py fails on any runtime import cycle between the repository's own modules. It counts TYPE_CHECKING imports and implied parent-package edges, and skips only __main__ blocks and submodule-to-parent reads. Negative control: 3 of the 11 self-tests fail on the old logic. Whole repository: 12 passed. Targeted tests of every touched module: 4275 passed.
Accepted security findings: 78 medusa findings, all on lines that exist verbatim in base 28d05e0183. They come from code moved unchanged into docker_root.py, tools_vars.py and tokens.py, or from untouched lines of touched files (compose.py, credentials_generator.py, credentials/reset/cli.py, users/__init__.py, yaml.py). Reviewed as by design or false positive: argv-list subprocess calls, dev docker-root teardown, NotASecret test-lane keys, SafeLoader yaml.load, md5 memo key, Jinja expression strings.
🎯 Fix: 90 %
💥 Break: 5 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 86
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
28d05e0183
commit
357eb3bd32
158 files changed
+1065
-642
No files matched your search
@@ -255,7 +255,7 @@ class TestBuildDevInventoryMatrix(unittest.TestCase):
|
||||
self.compose.repo_root = Path("/tmp/infinito-nexus")
|
||||
|
||||
@patch(
|
||||
"cli.administration.deploy.development.inventory.legacy_resolver._resolve_round_include",
|
||||
"utils.roles.applications.variants._resolve_round_include",
|
||||
autospec=True,
|
||||
)
|
||||
@patch(
|
||||
|
||||
+1
-3
@@ -90,9 +90,7 @@ class TestRoundIncludeIsDispatchable(unittest.TestCase):
|
||||
"""
|
||||
|
||||
def _include(self, primary: str) -> tuple[str, ...]:
|
||||
from cli.administration.deploy.development.inventory.legacy_resolver import (
|
||||
_resolve_round_include,
|
||||
)
|
||||
from utils.roles.applications.variants import _resolve_round_include
|
||||
|
||||
return _resolve_round_include(primary_apps=[primary], services_overrides={})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Unit tests for `cli.administration.deploy.development.inventory.planner`.
|
||||
|
||||
Covers ``plan_dev_inventory_matrix`` (mocking ``legacy_resolver``) and
|
||||
Covers ``plan_dev_inventory_matrix`` (mocking the round include) and
|
||||
``filter_plan_to_variants``.
|
||||
"""
|
||||
|
||||
@@ -18,7 +18,7 @@ from cli.administration.deploy.development.inventory import (
|
||||
|
||||
class TestPlanDevInventoryMatrix(unittest.TestCase):
|
||||
@patch(
|
||||
"cli.administration.deploy.development.inventory.legacy_resolver._resolve_round_include",
|
||||
"utils.roles.applications.variants._resolve_round_include",
|
||||
autospec=True,
|
||||
)
|
||||
@patch(
|
||||
@@ -54,7 +54,7 @@ class TestPlanDevInventoryMatrix(unittest.TestCase):
|
||||
)
|
||||
|
||||
@patch(
|
||||
"cli.administration.deploy.development.inventory.legacy_resolver._resolve_round_include",
|
||||
"utils.roles.applications.variants._resolve_round_include",
|
||||
autospec=True,
|
||||
)
|
||||
@patch(
|
||||
@@ -100,7 +100,7 @@ class TestPlanDevInventoryMatrix(unittest.TestCase):
|
||||
)
|
||||
|
||||
@patch(
|
||||
"cli.administration.deploy.development.inventory.legacy_resolver._resolve_round_include",
|
||||
"utils.roles.applications.variants._resolve_round_include",
|
||||
autospec=True,
|
||||
)
|
||||
@patch(
|
||||
@@ -154,7 +154,7 @@ class TestPlanDevInventoryMatrix(unittest.TestCase):
|
||||
)
|
||||
|
||||
@patch(
|
||||
"cli.administration.deploy.development.inventory.legacy_resolver._resolve_round_include",
|
||||
"utils.roles.applications.variants._resolve_round_include",
|
||||
autospec=True,
|
||||
)
|
||||
@patch(
|
||||
@@ -238,7 +238,7 @@ class TestPlanBakesPinnedVariant(unittest.TestCase):
|
||||
return_value={"web-app-bar": 1},
|
||||
)
|
||||
@patch(
|
||||
"cli.administration.deploy.development.inventory.legacy_resolver._resolve_round_include",
|
||||
"utils.roles.applications.variants._resolve_round_include",
|
||||
autospec=True,
|
||||
return_value=("web-app-bar", "web-app-foo"),
|
||||
)
|
||||
|
||||
@@ -7,11 +7,14 @@ import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from cli.administration.deploy.development.down import _wipe_docker_root
|
||||
from cli.administration.deploy.development.docker_root import _wipe_docker_root
|
||||
|
||||
|
||||
class TestWipeDockerRoot(unittest.TestCase):
|
||||
@patch("cli.administration.deploy.development.down.subprocess.run", autospec=True)
|
||||
@patch(
|
||||
"cli.administration.deploy.development.docker_root.subprocess.run",
|
||||
autospec=True,
|
||||
)
|
||||
def test_the_wipe_escalates(self, run_mock: MagicMock) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
docker_root = Path(tmp) / "docker"
|
||||
@@ -23,7 +26,10 @@ class TestWipeDockerRoot(unittest.TestCase):
|
||||
self.assertEqual(commands[0], ["sudo", "rm", "-rf", str(docker_root)])
|
||||
self.assertTrue(all(cmd[0] == "sudo" for cmd in commands))
|
||||
|
||||
@patch("cli.administration.deploy.development.down.subprocess.run", autospec=True)
|
||||
@patch(
|
||||
"cli.administration.deploy.development.docker_root.subprocess.run",
|
||||
autospec=True,
|
||||
)
|
||||
def test_a_surviving_docker_root_is_a_hard_error(self, run_mock: MagicMock) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
docker_root = Path(tmp) / "docker"
|
||||
@@ -36,7 +42,10 @@ class TestWipeDockerRoot(unittest.TestCase):
|
||||
self.assertIn("containers", str(ctx.exception))
|
||||
self.assertTrue(run_mock.called)
|
||||
|
||||
@patch("cli.administration.deploy.development.down.subprocess.run", autospec=True)
|
||||
@patch(
|
||||
"cli.administration.deploy.development.docker_root.subprocess.run",
|
||||
autospec=True,
|
||||
)
|
||||
def test_a_missing_docker_root_is_not_wiped(self, run_mock: MagicMock) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
_wipe_docker_root(Path(tmp) / "absent")
|
||||
|
||||
Reference in new issue
Block a user