mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-11 21:26:44 +00:00
Introduce a single grammar for per-line, per-block, and per-file
suppression markers across the test suite, replacing seven ad-hoc
syntaxes that had drifted apart.
Helper
utils/annotations/suppress.py exposes is_suppressed_at,
is_suppressed_in_head, is_suppressed_anywhere, line_has_rule, and
suppressed_line_numbers. Markers may use either `noqa` or `nocheck`
(case-insensitive synonyms), live inside `#`, `//`, `{# ... #}`, or
`<\!-- ... -->` comments, and combine multiple kebab-case rules
comma-separated. 17 unit tests cover the grammar in isolation.
Refactored consumers
- tests/external/repository/test_urls_reachable.py (rule: url)
- tests/external/docker/test_image_versions.py via
utils/docker/version_updater.py (rule: docker-version)
- tests/lint/repository/test_no_direct_yaml_calls.py (rule:
direct-yaml)
- tests/lint/ansible/test_service_shared_consistency.py (rule:
shared)
- tests/lint/ansible/roles/test_web_app_email_integration.py (rule:
email)
- tests/lint/repository/test_python_file_size.py (rule: file-size)
- tests/lint/ansible/test_run_once_tags.py +
tests/integration/roles/run_once/test_schema.py (rules: run-once,
run-once-suffix)
Marker migration
12 role tasks/main.yml files: `# run_once_<key>: deactivated`
-> `# nocheck: run-once`. roles/web-app-suitecrm/meta/services.yml
drops a malformed inline `noqa: intentional legacy pin` from a TODO
comment so the new parser does not pick it up as a stray rule.
Caching wins
Test files that previously loaded YAML / read files via raw
yaml.safe_load + Path.read_text now route through utils.cache.yaml
(load_yaml_any / load_yaml_str) and utils.cache.files.read_text:
- test_service_shared_consistency.py
- test_web_app_email_integration.py
- tests/integration/roles/run_once/test_schema.py
- utils/docker/version_updater.py
This both speeds up repeated reads and stays consistent with the
direct-yaml lint policy.
Documentation
New SPOT page at docs/contributing/actions/testing/suppression.md
with grammar, position semantics, the catalog of rules, examples,
and an "adding a new rule" checklist. lint.md and external.md drop
their per-rule tables and link to the new page. All touched docs
conform to docs/contributing/documentation.md (no em-dash thought
breaks, no SPOT self-labels, RFC-2119 keywords used consistently).
Settings sort tooling
scripts/lint/sort_claude_settings.sh wraps utils/claude/settings_sort.py
and is wired into scripts/lint/autoformat.sh. The tooling fixes the
ASCII-ascending requirement enforced by
tests/lint/repository/test_claude_settings_sorted.py; the test's
failure message now points operators at the script. .claude/settings.json
is committed in sorted form.
78 lines
2.2 KiB
Python
Executable File
78 lines
2.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Sort the curated string arrays in ``.claude/settings.json``.
|
|
|
|
The lint test in
|
|
``tests/lint/repository/test_claude_settings_sorted.py`` requires every
|
|
hand-curated array to stay ASCII-sorted ascending so diffs stay
|
|
reviewable and merge conflicts stay minimal. Tools that auto-extend the
|
|
file (e.g. permission auto-allowlists) tend to append unsorted; this
|
|
script puts everything back in order.
|
|
|
|
Exit code is ``0`` if the file was already sorted (no write), ``0``
|
|
after a successful rewrite, ``1`` on read/parse failure.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
SETTINGS_PATH = REPO_ROOT / ".claude" / "settings.json"
|
|
|
|
SORTED_ARRAYS: list[tuple[str, ...]] = [
|
|
("permissions", "allow"),
|
|
("permissions", "deny"),
|
|
("permissions", "ask"),
|
|
("sandbox", "network", "allowedDomains"),
|
|
("sandbox", "filesystem", "allowWrite"),
|
|
("sandbox", "filesystem", "denyRead"),
|
|
]
|
|
|
|
|
|
def _resolve(data: dict, path: tuple[str, ...]):
|
|
obj = data
|
|
for key in path:
|
|
if not isinstance(obj, dict) or key not in obj:
|
|
return None
|
|
obj = obj[key]
|
|
return obj
|
|
|
|
|
|
def main() -> int:
|
|
try:
|
|
raw = SETTINGS_PATH.read_text(encoding="utf-8")
|
|
except OSError as exc:
|
|
print(f"error: cannot read {SETTINGS_PATH}: {exc}", file=sys.stderr)
|
|
return 1
|
|
|
|
try:
|
|
data = json.loads(raw)
|
|
except json.JSONDecodeError as exc:
|
|
print(f"error: cannot parse {SETTINGS_PATH}: {exc}", file=sys.stderr)
|
|
return 1
|
|
|
|
changed = False
|
|
for path in SORTED_ARRAYS:
|
|
arr = _resolve(data, path)
|
|
if not isinstance(arr, list):
|
|
continue
|
|
ordered = sorted(arr)
|
|
if ordered != arr:
|
|
arr[:] = ordered
|
|
changed = True
|
|
print(f"sorted: {'.'.join(path)} ({len(arr)} entries)")
|
|
|
|
if not changed:
|
|
print(f"{SETTINGS_PATH.relative_to(REPO_ROOT)} already sorted.")
|
|
return 0
|
|
|
|
SETTINGS_PATH.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
|
|
print(f"updated {SETTINGS_PATH.relative_to(REPO_ROOT)}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|