feat: Add comprehensive utils package, importer tests, and fix tag semantics #136
+795
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a comprehensive utility package with formatting and validation functions, extensive test coverage for the importer service, and fixes a bug in tag application semantics.
Changes
🛠️ New Utility Functions (
runner/utils/format.go)Formatting Utilities:
FormatDuration()- Human-readable duration formatting (e.g., "1h 23m 45s", "500ms")FormatBytes()- Byte count formatting with appropriate units (GB, MB, KB, B)FormatGas()- Gas value formatting (Ggas, Mgas, Kgas)FormatPercentage()- Ratio to percentage conversion with configurable precisionFormatTimestamp()/ParseTimestamp()- Timestamp formatting and parsingParsing Utilities:
ParseDuration()- Parse human-readable duration stringsParseGasLimit()- Parse gas limits with suffixes (50G, 50e9, 50Ggas, 100M)String Utilities:
TruncateString()- Truncate strings with ellipsisTruncateMiddle()- Truncate in the middle (useful for hashes/addresses)Validation Utilities:
IsValidHexAddress()- Validate Ethereum addresses (0x + 40 hex chars)IsValidHexHash()- Validate 32-byte hex hashes (0x + 64 hex chars)Statistics:
CalculateStats()- Calculate mean, standard deviation, min, max, and medianSafety Utilities:
SafeDivide()/SafeDivideUint64()- Zero-safe division helpers✅ Test Coverage
runner/utils/utils_test.go- 50+ unit tests covering:runner/importer/service_test.go- Tests for:MergeMetadatatag application semantics🐛 Bug Fix
Fixed tag application order in
MergeMetadata():srcTagwas incorrectly applied to imported runs,destTagto existing runsdestTag(dest-tag flag) correctly applies to imported runs,srcTag(src-tag flag) fills missing tags on existing runsThis aligns the implementation with the CLI flag documentation:
--src-tag: "Tag to apply to existing metadata runs"--dest-tag: "Tag to apply to imported metadata runs"Testing