From 36ab4f983cb5a0f706fdc687bbad00a247a68b9e Mon Sep 17 00:00:00 2001 From: agessaman Date: Sat, 3 Oct 2026 22:46:30 -0700 Subject: [PATCH] test: a missing golden file fails instead of being written assert_golden used to write a golden that didn't exist yet whenever CI was unset, so a deleted or misnamed golden re-recorded whatever the code did and the test passed locally. It now writes only with UPDATE_GOLDEN=1 and otherwise fails with the same message CI already gave. Space bunny flagged this earlier; the public-API guards were hardened the same way in b62806f5. --- tests/characterization/golden_util.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/characterization/golden_util.py b/tests/characterization/golden_util.py index 8ad61f5..d1e93ba 100644 --- a/tests/characterization/golden_util.py +++ b/tests/characterization/golden_util.py @@ -20,11 +20,13 @@ GOLDEN_DIR = Path(__file__).parent / "golden" def assert_golden(name: str, data: Any) -> None: path = GOLDEN_DIR / f"{name}.json" rendered = json.dumps(data, indent=1, sort_keys=True, ensure_ascii=False, default=repr) + "\n" - if os.environ.get("UPDATE_GOLDEN") == "1" or not path.exists(): - if not path.exists() and os.environ.get("CI"): - raise AssertionError(f"golden file {path} missing; generate it with UPDATE_GOLDEN=1") + if os.environ.get("UPDATE_GOLDEN") == "1": path.write_text(rendered, encoding="utf-8") return + if not path.exists(): + # Never write one implicitly: a deleted or misnamed golden would silently + # re-record whatever the code does now, and the test would pass. + raise AssertionError(f"golden file {path} missing; generate it with UPDATE_GOLDEN=1") expected = path.read_text(encoding="utf-8") if rendered != expected: exp = json.loads(expected)