Commit 0d852d6a authored by Luke Sandberg's avatar Luke Sandberg

test: add exact size assertions for TypedStorage and AggregationNumber

Add stricter size tests to catch regressions:
- AggregationNumber must be exactly 12 bytes
- Option<AggregationNumber> must be 12 bytes (NonZeroU32 niche optimization)
- TypedStorage must be exactly 128 bytes

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: 's avatarClaude Opus 4.5 <noreply@anthropic.com>
parent b732c9e2
...@@ -550,15 +550,39 @@ mod tests { ...@@ -550,15 +550,39 @@ mod tests {
#[test] #[test]
fn test_schema_size() { fn test_schema_size() {
// Unified TypedStorage - all fields directly on one struct // AggregationNumber uses NonZeroU32 for `effective` field to enable niche optimization.
// Size will be larger than separate TaskData + TaskMeta because fields // This allows Option<AggregationNumber> to be 12 bytes instead of 16 bytes.
// aren't split, but simpler access patterns assert_eq!(
println!("TypedStorage size: {} bytes", size_of::<TypedStorage>()); size_of::<AggregationNumber>(),
// Size check - unified storage is approximately the sum of what was data + meta 12,
// Note: The exact size may vary due to alignment/padding in unified struct "AggregationNumber size changed! Was 12 bytes, now {} bytes.",
assert!( size_of::<AggregationNumber>()
size_of::<TypedStorage>() <= 128, );
"TypedStorage should not exceed 128 bytes" assert_eq!(
size_of::<Option<AggregationNumber>>(),
12,
"Option<AggregationNumber> size changed! Was 12 bytes (niche optimization), now {} \
bytes.",
size_of::<Option<AggregationNumber>>()
);
// TypedStorage uses lazy storage for most fields, keeping inline storage minimal.
// Current layout (128 bytes):
// - output_dependent (AutoSet<TaskId>): 24 bytes
// - aggregation_number (Option<AggregationNumber>): 12 bytes (NonZeroU32 niche)
// - output (Option<OutputValue>): 32 bytes
// - upper (CounterMap<TaskId, u32>): 24 bytes
// - flags (TaskFlags): 8 bytes
// - lazy (Vec<LazyField>): 24 bytes
// - padding: 4 bytes
//
// Use exact size check to catch regressions in either direction.
assert_eq!(
size_of::<TypedStorage>(),
128,
"TypedStorage size changed! Was 128 bytes, now {} bytes. If this is intentional, \
update this test.",
size_of::<TypedStorage>()
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment