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

68 lines
2.0 KiB
Python

"""Helpers for suites whose checks talk to a deployed service.
A check that reaches a service needs two things this module supplies: a way to
say whether the service answers at all, and a way to report progress while it
works. Progress goes to a file rather than stdout because pytest captures at
file-descriptor level and releases only after the test ends, so a long run
would otherwise sit silent. The file lands under ``build/`` so an operator can
follow it from the host while the suite runs inside the stack's container,
which has a ``/tmp`` of its own.
"""
from __future__ import annotations
import contextlib
import time
import urllib.error
import urllib.request
from typing import TYPE_CHECKING
from . import PROJECT_ROOT
if TYPE_CHECKING:
from pathlib import Path
REACHABLE_TIMEOUT = 5
def progress_log(suite: str) -> Path:
"""Return the file a suite appends its progress to.
Args:
suite: the suite's name, used as the file's stem.
"""
return PROJECT_ROOT / "build" / f"{suite}.log"
def progress(suite: str, message: str) -> None:
"""Append one status line, flushed, so ``tail -f`` shows it immediately.
A failure to write is swallowed: status reporting must never turn a green
suite red.
Args:
suite: the suite's name, selecting the log file.
message: the line to append, without a trailing newline.
"""
stamp = time.strftime("%H:%M:%S")
path = progress_log(suite)
with contextlib.suppress(OSError):
path.parent.mkdir(parents=True, exist_ok=True)
with path.open("a", encoding="utf-8") as handle:
handle.write(f"{stamp} {message}\n")
def answers(url: str) -> bool:
"""Return whether something serves ``url`` right now.
Args:
url: an endpoint that responds without authentication.
"""
try:
with urllib.request.urlopen( # noqa: S310 - this repository's own service definitions
url, timeout=REACHABLE_TIMEOUT
):
return True
except (urllib.error.URLError, OSError):
return False