Log gate helper failures

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZB8QEaFVQoa8CjuAw
This commit is contained in:
Krzysztof Rudnicki 2026-11-17 22:50:09 +01:00
parent f79d425d3d
commit 4b6e4df1bf
3 changed files with 14 additions and 15 deletions

View File

@ -44,13 +44,10 @@ def test_helper_followed_by_import(tmp_path: Path) -> None:
def test_untouched_change_selects_nothing(tmp_path: Path) -> None: def test_untouched_change_selects_nothing(tmp_path: Path) -> None:
_tree(tmp_path) _tree(tmp_path)
assert ( assert gs.dart_affected_tests(tmp_path, [f"{APP}/lib/lonely.dart"]) == [
gs.dart_affected_tests(tmp_path, [f"{APP}/lib/lonely.dart"]) f"{APP}/test/lonely_test.dart",
== [ f"{APP}/test/sub/x_test.dart",
f"{APP}/test/lonely_test.dart", ]
f"{APP}/test/sub/x_test.dart",
]
)
assert gs.dart_affected_tests(tmp_path, ["README.md"]) == [] assert gs.dart_affected_tests(tmp_path, ["README.md"]) == []

View File

@ -9,8 +9,10 @@ loads would otherwise score 100% by absence).
from __future__ import annotations from __future__ import annotations
from pathlib import Path from pathlib import Path
import logging
import sys import sys
_LOG = logging.getLogger(__name__)
APP_LIB = "stronglift_replacement/workout_app/lib/" APP_LIB = "stronglift_replacement/workout_app/lib/"
@ -39,15 +41,12 @@ def main(argv: list[str]) -> int:
for path, lines in sorted( for path, lines in sorted(
uncovered(Path(argv[1]).read_text(encoding="utf-8"), wanted).items() uncovered(Path(argv[1]).read_text(encoding="utf-8"), wanted).items()
): ):
if lines is None: if lines is None or lines:
print(f"NOT COVERED (no selected test loads it): {path}", file=sys.stderr) _LOG.error("changed file below 100%%: %s (uncovered: %s)", path, "absent from lcov" if lines is None else lines)
bad += 1 bad += 1
elif lines:
print(f"UNCOVERED LINES {path}: {lines}", file=sys.stderr)
bad += 1
print(f"changed-file coverage: {len(wanted)} files, {bad} below 100%")
return 1 if bad else 0 return 1 if bad else 0
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="push-gate: %(message)s")
raise SystemExit(main(sys.argv)) raise SystemExit(main(sys.argv))

View File

@ -14,11 +14,13 @@ from __future__ import annotations
from dataclasses import asdict, dataclass, field from dataclasses import asdict, dataclass, field
import json import json
import logging
from pathlib import Path from pathlib import Path
import re import re
import subprocess import subprocess
import sys import sys
_LOG = logging.getLogger(__name__)
APP = "stronglift_replacement/workout_app" APP = "stronglift_replacement/workout_app"
_DIRECTIVE = re.compile(r"^\s*(?:import|export|part)\s[^;]*;", re.MULTILINE) _DIRECTIVE = re.compile(r"^\s*(?:import|export|part)\s[^;]*;", re.MULTILINE)
_QUOTED = re.compile(r"'([^']+)'|\"([^\"]+)\"") _QUOTED = re.compile(r"'([^']+)'|\"([^\"]+)\"")
@ -58,7 +60,7 @@ def _imports(root: Path, rel: str, pkg: str) -> set[str]:
try: try:
text = (root / rel).read_text(encoding="utf-8") text = (root / rel).read_text(encoding="utf-8")
except (OSError, UnicodeDecodeError) as exc: except (OSError, UnicodeDecodeError) as exc:
print(f"gate_select: cannot read {rel}: {exc}", file=sys.stderr) _LOG.warning("gate_select: cannot read %s: %s", rel, exc)
return out return out
for stmt in _DIRECTIVE.findall(text): for stmt in _DIRECTIVE.findall(text):
for a, b in _QUOTED.findall(stmt): for a, b in _QUOTED.findall(stmt):
@ -164,10 +166,11 @@ def _git(root: Path, *args: str) -> list[str]:
def main(argv: list[str]) -> int: def main(argv: list[str]) -> int:
"""Print the selection for BASE..HEAD as JSON.""" """Print the selection for BASE..HEAD as JSON."""
root = Path(_git(Path.cwd(), "rev-parse", "--show-toplevel")[0]) root = Path(_git(Path.cwd(), "rev-parse", "--show-toplevel")[0])
logging.basicConfig(level=logging.INFO)
base, head = argv[1], (argv[2] if len(argv) > 2 else "HEAD") base, head = argv[1], (argv[2] if len(argv) > 2 else "HEAD")
changed = _git(root, "diff", "--name-only", f"{base}..{head}") changed = _git(root, "diff", "--name-only", f"{base}..{head}")
sel = select(root, changed, _git(root, "ls-files", "*.py")) sel = select(root, changed, _git(root, "ls-files", "*.py"))
print(json.dumps(asdict(sel), indent=1)) sys.stdout.write(json.dumps(asdict(sel), indent=1) + "\n")
return 0 return 0