refactor(common): Share Common Macro Utilities#2735
Conversation
Co-authored-by: Codex <noreply@openai.com>
✅ Heimdall Review Status
|
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
|
||
| mod tracing; | ||
| pub use tracing::{CollectingLayer, TraceStorage}; | ||
| pub use base_protocol::test_utils::{CollectingLayer, TraceStorage}; |
There was a problem hiding this comment.
This re-export is now dead code within the derive crate — all call sites were migrated to base_protocol::capture_traces!(), which references the types directly via $crate::test_utils::*. Unless there are downstream consumers of base_derive::test_utils::{CollectingLayer, TraceStorage}, this line can be removed.
| } | ||
|
|
||
| /// Installs a temporary tracing subscriber that captures events into [`TraceStorage`]. | ||
| #[macro_export] |
There was a problem hiding this comment.
#[macro_export] places this macro at the crate root unconditionally, even though the test_utils module is gated behind #[cfg(any(test, feature = "test-utils"))]. If someone invokes base_protocol::capture_traces!() without the test-utils feature enabled, they'll get a confusing compilation error about $crate::test_utils::TraceStorage not existing, rather than the macro itself being absent.
Not a practical problem today (all callers are in test code), but consider adding a doc comment noting the feature requirement, e.g.:
/// **Requires** the `test-utils` feature (or `#[cfg(test)]`).
Co-authored-by: Codex <noreply@openai.com>
| .with(layer) | ||
| .with(tracing_subscriber::fmt::layer()); | ||
| let _guard = tracing::subscriber::set_default(subscriber); | ||
| let (trace_store, _guard) = crate::capture_traces!(); |
There was a problem hiding this comment.
The original test_continuing_with_empty_batch was the only test that composed the subscriber with an additional tracing_subscriber::fmt::layer():
let subscriber = tracing_subscriber::Registry::default()
.with(layer)
.with(tracing_subscriber::fmt::layer());The capture_traces!() macro doesn't include the fmt layer, so this test silently lost its stdout trace output. This is harmless (it's a debugging aid, not a correctness concern), but worth noting — if the fmt layer was there intentionally for this specific test, it should be restored manually instead of using the macro.
Review SummaryClean refactor that consolidates three patterns of duplicated code: rollup fork activation methods, trace-capture test setup, and CLI binary entrypoints. The macro implementations are correct and preserve the original semantics. Findings (minor)
No correctness, safety, or concurrency issues found. The |
Summary
This refactor moves duplicated trace capture setup into the protocol test utilities and reuses it from derive tests. It generates the repeated rollup fork activation methods from a shared macro while preserving the public method names. It also adds a shared CLI entrypoint macro for binaries that parse Clap args, run the command, and exit on errors.