Files
computer-playbook/tests/lint/filesystem/test_scripts_folder_files.py
T
Environment TestandClaude Sonnet 4.6 bf8c535988 feat(update): add docker image version updater CLI, workflow, and lint tests
- Add utils/docker/version_updater.py with CLI for updating Docker image versions
- Add cli/fix/docker_image_versions module wrapping the updater
- Add .github/workflows/update.yml replacing update-skills.yml
- Add scripts/github/ helpers: check_git_changes, install_update_python, open_update_pr, update_docker_image_versions
- Add tests/lint/filesystem/ for scripts/ and utils/ folder file-type enforcement
- Add tests/lint/ansible/ for legacy module usage and vars usage checks
- Reorganize tests/lint/repository/ and move test_vars_usage_in_yaml.py to ansible/
- Add artefact docs: files/github/workflow.md, scripst.md, utils.md
- Apply documentation.md standards to all modified markdown files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 18:38:39 +02:00

62 lines
1.7 KiB
Python

"""Lint check: tracked files under scripts/ must be shell scripts.
README.md files are ignored because they are documentation-only exceptions.
"""
from __future__ import annotations
import subprocess
import unittest
from pathlib import Path
def repo_root() -> Path:
for candidate in Path(__file__).resolve().parents:
if (candidate / "pyproject.toml").is_file():
return candidate
raise AssertionError("Repository root not found from test path.")
def tracked_files(root: Path) -> list[Path]:
try:
output = subprocess.check_output(
["git", "-C", str(root), "ls-files", "-z"],
stderr=subprocess.STDOUT,
)
rel_paths = [path for path in output.decode("utf-8").split("\0") if path]
return [root / rel_path for rel_path in rel_paths]
except Exception:
return [
path
for path in root.rglob("*")
if path.is_file()
and ".git" not in path.parts
and "__pycache__" not in path.parts
]
class TestScriptsFolderFiles(unittest.TestCase):
def test_scripts_contains_only_sh_files(self) -> None:
root = repo_root()
scripts_root = root / "scripts"
violations = [
path.relative_to(root).as_posix()
for path in tracked_files(root)
if path.is_relative_to(scripts_root)
and path.name != "README.md"
and path.suffix != ".sh"
]
self.assertEqual(
violations,
[],
"Tracked files under scripts/ must end with .sh "
"(README.md is allowed).\nFound:\n"
+ "\n".join(f" {path}" for path in sorted(violations)),
)
if __name__ == "__main__":
unittest.main()