mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
This change updates `regenerate_stale_files.sh` to always execute a direct fix and refactors `staleness_test_lib.py` to support cleaner output during regeneration without sacrificing debugging info.
Motivation:
Automatic staleness tests are run to regenerate stale files on non-bazel environments (like GHA). When these files change, the tests "fail" to trigger regeneration. This causes constant confusion for developers as they look like test failures rather than "Working As Intended" regeneration triggers.
Details:
1. **`regenerate_stale_files.sh`**: Updated to always build the staleness tests via `bazel build` and execute them directly with `--fix --print-diffs`, avoiding the confusing "FAIL" output of `bazel test`. This script is primarily used by automation (like GHA) where this behavior is desired by default.
2. **`staleness_test_lib.py`**: Refactored diff generation into a shared helper `_GetDiffErrors`. Both `CheckFilesMatch` (testing) and `FixFiles` (fixing) use this helper. Added a `print_diffs` parameter to `FixFiles` so diffs are only printed when explicitly requested (e.g., in `regenerate_stale_files.sh`), preventing double-printing if run manually.
3. **Tone Improvement**: Updated the message for missing files during fixing to be less alarming ("Creating missing file" instead of "File does not exist").
### Output Comparison
**New Automation Output**:
Clean execution without `AssertionError` boilerplate, but preserves actionable diffs.
```
+ ./bazel-bin/upb/reflection/descriptor_upb_proto_staleness_test --fix --print-diffs
Creating missing file upb/reflection/stage0/descriptor_upb_proto.h
File upb/reflection/descriptor_upb_proto.c is out of date:
--- upb/reflection/descriptor_upb_proto.c.generated
+++ upb/reflection/descriptor_upb_proto.c
@@ -45,6 +45,7 @@
#include "upb/reflection/descriptor_upb_proto.h"
UPB_NOINLINE const upb_MiniTable* google_protobuf_FileDescriptorSet_msg_init() {
+ // Added a new field
return &google_protobuf_FileDescriptorSet_msg_init_table;
}
```
**Traditional Test Failure (Manual Runs)**:
Verbose, traditional test failure (for manual runs via `bazel test`).
```
+ bazel test upb/reflection:descriptor_upb_proto_staleness_test
...
FAIL: upb/reflection:descriptor_upb_proto_staleness_test (Exit 1)
================================================================================
AssertionError: Files out of date!
To fix run THIS command:
bazel-bin/upb/reflection/descriptor_upb_proto_staleness_test --fix
Errors:
File upb/reflection/descriptor_upb_proto.c is out of date:
--- upb/reflection/descriptor_upb_proto.c.generated
+++ upb/reflection/descriptor_upb_proto.c
...
```
PiperOrigin-RevId: 963179635
|
||
|---|---|---|
| .. | ||
| BUILD.bazel | ||
| build_defs.bzl | ||
| staleness_test.py | ||
| staleness_test_lib.py | ||