From 0dccf7a4609f39ec0844a6d7d80963c15f50031f Mon Sep 17 00:00:00 2001 From: Scott McCarty Date: Fri, 6 Nov 2026 10:35:15 -0500 Subject: [PATCH] fix: a gourmand sidecar with no gourmand.toml stops the gate (#25) gourmand resolves gourmand-exceptions.toml and its two siblings RELATIVE TO gourmand.toml. With no gourmand.toml the sidecar is found on disk, never parsed, and nothing is printed about it. The gate then goes red listing violations that were already justified, which looks exactly like a wrong justification -- so the natural response is to rewrite the justification, and then rewrite it again. That is an evening on this repository before the cause was spotted, and 26 repositories in the fleet carry an exceptions file. A 2, not a warning. This repository's own argument: a check that cannot do what it was configured to do must not report as though it did, and a warning scrolls past on a long run with the violation list printed underneath it. Verified in the image rather than argued. A tree with the sidecar and no config exits 2 with "found gourmand-exceptions.toml but no gourmand.toml beside it, so no entry in it would be loaded"; a tree with both runs gourmand and exits 0. The real fix belongs upstream in mattdm/gourmand and is tracked in crunchtools/gourmand#31. This is the part we control, and it covers every repo because sdlc is the only place in the fleet that invokes gourmand. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01R7Y1jg2DfucoFv7VrzzwVR --- .github/workflows/container.yml | 2 +- CHANGELOG.md | 15 ++++++ sdlc | 29 ++++++++++++ tests/test_gourmand_sidecar.py | 84 +++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100755 tests/test_gourmand_sidecar.py diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 2d49ed7..b992f8d 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -115,7 +115,7 @@ jobs: run: | set -eu for t in tests/test_plan.py tests/test_codeql_globs.py \ - tests/test_pycache_prefix.py; do + tests/test_pycache_prefix.py tests/test_gourmand_sidecar.py; do podman run --rm -v "$PWD:/src:ro,z" -w /src \ --entrypoint /opt/constitution-venv/bin/python3 \ "localhost/python-sdlc:$GITHUB_SHA" "$t" diff --git a/CHANGELOG.md b/CHANGELOG.md index ed68e0d..91648f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,21 @@ All notable changes to this project are documented here, following ## [Unreleased] +### Fixed + +- **A gourmand sidecar file with no `gourmand.toml` beside it stops the gate + instead of being ignored.** gourmand resolves + `gourmand-exceptions.toml`, `gourmand-patterns.toml` and + `gourmand-audit-ledger.toml` relative to `gourmand.toml`. With no + `gourmand.toml` the sidecar is found on disk, never parsed, and nothing is + said about it, so the gate goes red listing violations that were already + justified — which reads exactly like a wrong justification, so the natural + response is to rewrite the justification, repeatedly. It cost an evening on + this repository before the cause was found, and 26 repositories in the fleet + carry an exceptions file. `gourmand` now exits 2 naming the file it found and + the one it wanted, because a check that cannot do what it was configured to do + must not report as though it did (#25). + ## [0.5.1] - 2026-11-06 ### Fixed diff --git a/sdlc b/sdlc index 74d1ee3..89a0d8b 100755 --- a/sdlc +++ b/sdlc @@ -905,7 +905,36 @@ def t_pytest(s: dict) -> int: return run(cmd, env=env, cwd=project_dir())[0] +GOURMAND_SIDECARS = ( + "gourmand-exceptions.toml", + "gourmand-patterns.toml", + "gourmand-audit-ledger.toml", +) +"""Files gourmand resolves RELATIVE TO gourmand.toml, so each one needs it to exist.""" + + +def gourmand_orphan(root: Path) -> str | None: + """The sidecar file that would be ignored for want of a gourmand.toml, if there is one.""" + if (root / "gourmand.toml").is_file(): + return None + return next((name for name in GOURMAND_SIDECARS if (root / name).is_file()), None) + + def t_gourmand(s: dict) -> int: + # With no gourmand.toml, a sidecar file is found on disk, never parsed, and nothing is + # said about it: the gate goes red listing violations you already justified, which reads + # exactly like a wrong justification, so the natural response is to rewrite the + # justification. That cost an evening on this repository before the cause was spotted, + # and 26 repositories carry an exceptions file. A 2, not a warning: a check that cannot + # do what it was configured to do must not report as though it did, and a warning + # scrolls past on a long run with the violation list underneath it. + orphan = gourmand_orphan(REPO) + if orphan: + cannot( + f"found {orphan} but no gourmand.toml beside it, so no entry in it would be " + f"loaded. Add a gourmand.toml (an empty [output] table is enough) or remove " + f"{orphan}" + ) step("gourmand check --full") return run(["gourmand", "check", "--full", "."])[0] diff --git a/tests/test_gourmand_sidecar.py b/tests/test_gourmand_sidecar.py new file mode 100755 index 0000000..f37c647 --- /dev/null +++ b/tests/test_gourmand_sidecar.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +"""A gourmand sidecar file with no gourmand.toml must stop the gate, not be ignored. + +gourmand resolves `gourmand-exceptions.toml` and its siblings relative to +`gourmand.toml`. With no `gourmand.toml` the sidecar is found on disk, never +parsed, and nothing is printed about it -- so the gate goes red listing +violations that were already justified, which reads exactly like a wrong +justification. That cost an evening on this repository before the cause was +found, and 26 repositories in the fleet carry an exceptions file (#25). + +Run: tests/test_gourmand_sidecar.py (needs nothing but python3) +""" + +from __future__ import annotations + +import importlib.machinery +import importlib.util +import sys +import tempfile +from pathlib import Path + +# `sdlc` has no .py extension, so it is loaded by path rather than imported by +# name. Safe to import: its entry point is behind `if __name__ == "__main__"`. +_SPEC = importlib.util.spec_from_loader( + "sdlc_under_test", + importlib.machinery.SourceFileLoader( + "sdlc_under_test", str(Path(__file__).resolve().parent.parent / "sdlc") + ), +) +assert _SPEC is not None and _SPEC.loader is not None +_SDLC = importlib.util.module_from_spec(_SPEC) +_SPEC.loader.exec_module(_SDLC) +gourmand_orphan = _SDLC.gourmand_orphan +SIDECARS = _SDLC.GOURMAND_SIDECARS + + +def tree(root: Path, *names: str) -> Path: + for name in names: + (root / name).write_text("") + return root + + +def check(label: str, got: object, want: object) -> bool: + if got == want: + return True + print(f"FAIL {label}: got {got!r}, want {want!r}") + return False + + +def main() -> int: + ok = True + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + + # Every sidecar is caught, and named, so the message can say what it found. + for name in SIDECARS: + alone = root / name.removesuffix(".toml") + alone.mkdir() + tree(alone, name) + ok &= check(f"{name} alone", gourmand_orphan(alone), name) + + # A sidecar WITH gourmand.toml is the normal case and changes nothing. + both = root / "both" + both.mkdir() + tree(both, "gourmand.toml", "gourmand-exceptions.toml") + ok &= check("sidecar beside gourmand.toml", gourmand_orphan(both), None) + + # Neither file: nothing new to say, and no new failure. + bare = root / "bare" + bare.mkdir() + ok &= check("no gourmand files at all", gourmand_orphan(bare), None) + + # gourmand.toml on its own is fine too. + config = root / "config-only" + config.mkdir() + tree(config, "gourmand.toml") + ok &= check("gourmand.toml alone", gourmand_orphan(config), None) + + print("PASS" if ok else "FAILED") + return 0 if ok else 1 + + +if __name__ == "__main__": + sys.exit(main())