Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions sdlc
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
84 changes: 84 additions & 0 deletions tests/test_gourmand_sidecar.py
Original file line number Diff line number Diff line change
@@ -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())
Loading