Files
kevinveenbirkenbachandClaude Opus 5.5 357eb3bd32 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>
2026-11-13 20:07:50 +00:00

48 lines
1.7 KiB
Python

"""The alias the readiness probe expects is the one the lane deploys."""
from __future__ import annotations
import shutil
import tempfile
import unittest
from pathlib import Path
from utils import PROJECT_ROOT
from utils.cache.yaml import load_yaml_any
from utils.inventory.tools import LANE_MODEL_ALIAS
from utils.inventory.tools_vars import TEMPLATE, render
OLLAMA_ROLE = "svc-ai-ollama"
class TestLaneModel(unittest.TestCase):
def test_the_rendered_inventory_pins_the_alias_the_probe_expects(self) -> None:
"""Two places name the model, and nothing else keeps them equal.
The inventory carries the entry because that is where inventory data
belongs, and the probe needs the bare alias before any render has
run, because ``ensure`` asks whether the lane serves before the
deploy that writes the rendered file. A lane serving one model while
the probe expects another never reports ready and redeploys on every
call.
The render runs in a scratch root: inside the test container a render
into the real tree leaves a nobody-owned tools.rendered.yml behind,
and the host-side test-oracle then dies writing it (EACCES).
"""
with tempfile.TemporaryDirectory() as scratch:
root = Path(scratch)
(root / TEMPLATE).parent.mkdir(parents=True)
shutil.copy(Path(PROJECT_ROOT) / TEMPLATE, root / TEMPLATE)
rendered = load_yaml_any(str(render(root, ["en"])))
ollama = rendered["applications"][OLLAMA_ROLE]["services"]["ollama"]
self.assertEqual(
[LANE_MODEL_ALIAS],
[model["alias"] for model in ollama["preload_models"]],
)
if __name__ == "__main__":
unittest.main()