mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-26 21:08:20 +00:00
Refactor scripts/install/lint.sh (~870 LOC bash) into a Python package
under utils/install/. scripts/install/lint.sh becomes a 7-line wrapper
that delegates to `python3 -m utils.install.lint`.
Layout:
- utils/install/{primitives,pip,npm,github_release,system_pkg}.py:
channel-agnostic installers
- utils/install/lint/<tool>.py: one ensure() per tool (actionlint,
shfmt, mbake, ruff, ansible_lint, galaxy_importer, markdownlint_cli2,
eslint, shellcheck, ansible_commands, ansible_collections)
- utils/install/lint/__main__.py: CLI + group dispatch + stamp logic
INFINITO_LINT_RUNNER dispatch:
- New env var (host | docker, default docker), tracked in env/static.env
+ passthrough handler + drift test.
- scripts/install/wrapper.sh routes `make install-lint` to host or
container based on the runner.
- scripts/lint/wrapper.sh already dispatched; container branch now uses
bash (not --login) so /etc/profile does not reset PATH, and forwards
BASH_ENV so the .env keys land in the lint script's env.
Stamp logic:
- Per-interpreter stamp at build/install-lint-<sha256(sys.executable)>.stamp
so host venv and container venv track installs independently despite
bind-mounted build/.
- `--force` drops the stamp; group args bypass the stamp.
Tests + docs:
- 43 unit tests under tests/unit/utils/install/{,lint/} cover primitives,
pip/npm/github_release/system_pkg fallback chains, and the main CLI
(stamp logic, group dispatch, error path).
- utils/install/README.md + utils/install/lint/README.md document the
structure and the per-tool ensure() contract.
- docs/contributing/tools/make.md install-lint row updated to mention
the runner dispatch + per-env stamp + install-lint-force.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
"""Unit tests for :mod:`utils.install.github_release`."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
from utils.install import github_release as gr
|
|
|
|
|
|
class _FakeResp:
|
|
def __init__(self, final_url: str) -> None:
|
|
self._final = final_url
|
|
|
|
def __enter__(self) -> _FakeResp: # noqa: PYI034 - test double, not a Self-typed lib
|
|
return self
|
|
|
|
def __exit__(self, *exc: object) -> None:
|
|
return None
|
|
|
|
def geturl(self) -> str:
|
|
return self._final
|
|
|
|
|
|
class TestResolveLatestTag(unittest.TestCase):
|
|
def test_strips_leading_v(self) -> None:
|
|
with mock.patch.object(
|
|
gr,
|
|
"urlopen",
|
|
return_value=_FakeResp("https://github.com/x/y/releases/tag/v1.2.3"),
|
|
):
|
|
self.assertEqual(
|
|
gr.resolve_latest_tag("https://github.com/x/y/releases/latest"), "1.2.3"
|
|
)
|
|
|
|
def test_handles_trailing_slash(self) -> None:
|
|
with mock.patch.object(
|
|
gr,
|
|
"urlopen",
|
|
return_value=_FakeResp("https://github.com/x/y/releases/tag/v9.0.0/"),
|
|
):
|
|
self.assertEqual(gr.resolve_latest_tag("https://example/latest"), "9.0.0")
|
|
|
|
def test_raises_when_unresolved(self) -> None:
|
|
latest = "https://github.com/x/y/releases/latest"
|
|
with mock.patch.object(gr, "urlopen", return_value=_FakeResp(latest)):
|
|
self.assertRaises(RuntimeError, gr.resolve_latest_tag, latest)
|
|
|
|
def test_raises_when_tag_is_literal_latest(self) -> None:
|
|
with mock.patch.object(
|
|
gr,
|
|
"urlopen",
|
|
return_value=_FakeResp("https://github.com/x/y/releases/tag/latest"),
|
|
):
|
|
self.assertRaises(
|
|
RuntimeError, gr.resolve_latest_tag, "https://example/latest"
|
|
)
|
|
|
|
|
|
class TestDownloadReleaseAsset(unittest.TestCase):
|
|
def test_delegates_to_download_file(self) -> None:
|
|
with mock.patch.object(gr, "download_file") as dl:
|
|
gr.download_release_asset("https://example/x.tar.gz", "/tmp/x.tar.gz")
|
|
dl.assert_called_once_with("https://example/x.tar.gz", "/tmp/x.tar.gz")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|