From b62806f58bf726e1239678993d53899b0a5fe67f Mon Sep 17 00:00:00 2001 From: agessaman Date: Thu, 1 Oct 2026 20:21:03 -0700 Subject: [PATCH] test(characterization): fail when a public-API golden is missing instead of regenerating it Both guards in test_public_api.py rewrote a missing golden and passed, so deleting public_imports.json along with an import would have hidden the removal. They now regenerate only under UPDATE_GOLDEN=1. --- tests/characterization/test_public_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/characterization/test_public_api.py b/tests/characterization/test_public_api.py index e5fbe28..9fdfa05 100644 --- a/tests/characterization/test_public_api.py +++ b/tests/characterization/test_public_api.py @@ -74,9 +74,10 @@ def test_no_public_name_was_removed(): import os current = _public_names() - if os.environ.get("UPDATE_GOLDEN") == "1" or not GOLDEN.exists(): + if os.environ.get("UPDATE_GOLDEN") == "1": GOLDEN.write_text(json.dumps(current, indent=1, sort_keys=True) + "\n", encoding="utf-8") return + assert GOLDEN.exists(), f"{GOLDEN} missing; generate it with UPDATE_GOLDEN=1" recorded = json.loads(GOLDEN.read_text(encoding="utf-8")) missing = [] for module, names in recorded.items(): @@ -91,9 +92,10 @@ def test_no_public_name_was_removed(): def test_no_imported_public_name_was_dropped(): import os - if os.environ.get("UPDATE_GOLDEN") == "1" or not IMPORTS_GOLDEN.exists(): + if os.environ.get("UPDATE_GOLDEN") == "1": IMPORTS_GOLDEN.write_text(json.dumps(_public_imports(), indent=1, sort_keys=True) + "\n", encoding="utf-8") return + assert IMPORTS_GOLDEN.exists(), f"{IMPORTS_GOLDEN} missing; generate it with UPDATE_GOLDEN=1" recorded = json.loads(IMPORTS_GOLDEN.read_text(encoding="utf-8")) missing = [ f"{module}: {name}"