diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 4d4e12e..d1284ec 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -2,7 +2,7 @@ name: diet_guard_app description: "Companion phone app for diet_guard: log meals on the go." publish_to: 'none' -version: 1.0.28+1 +version: 1.0.29+1 environment: sdk: ^3.12.2 diff --git a/scripts/check_patch_targets.py b/scripts/check_patch_targets.py index fb152b8..1f8239a 100755 --- a/scripts/check_patch_targets.py +++ b/scripts/check_patch_targets.py @@ -31,6 +31,14 @@ PACKAGE = "diet_guard" TESTS_ROOT = pathlib.Path(PACKAGE) / "tests" +# Running this as `python3 scripts/check_patch_targets.py` puts *scripts/* on +# sys.path, not the repo root -- so `import diet_guard` fails unless the +# package happens to be installed. It is not, on a CI runner that only +# installs requirements.txt. Without this the resolver's `except ImportError` +# swallowed every lookup and the hook reported all 19 targets as stale, which +# is the exact fail-open shape this script exists to prevent. +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent)) + def patch_targets(root: pathlib.Path) -> Iterator[tuple[pathlib.Path, int, str]]: """Yield ``(file, lineno, dotted_target)`` for every literal patch target.""" @@ -78,6 +86,20 @@ def main() -> int: sys.stderr.write(f"Error: {TESTS_ROOT} not found; run from the repo root.\n") return 1 + # Distinguish "this target moved" from "the package will not import at + # all". Without this the second case masquerades as the first: every + # target reports stale at once, which reads like a catastrophic refactor + # and hides the real error (a missing dependency, a syntax error). + try: + importlib.import_module(PACKAGE) + except ImportError as exc: + sys.stderr.write( + f"Error: cannot import {PACKAGE} ({exc}); every patch target would " + f"be reported stale. Fix the import first -- this is an environment " + f"problem, not a stale patch target.\n", + ) + return 1 + stale = [ (path, lineno, target) for path, lineno, target in patch_targets(TESTS_ROOT)