-
Notifications
You must be signed in to change notification settings - Fork 180
fix: include package name for duplicate bench names [#264] #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
* add test output
📝 WalkthroughWalkthroughAdds Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #330 +/- ##
==========================================
- Coverage 89.14% 89.12% -0.03%
==========================================
Files 16 16
Lines 949 947 -2
Branches 200 201 +1
==========================================
- Hits 846 844 -2
Misses 99 99
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* add test file with a snapshot * add test output
* add test for backwards compatibility * add test output
* initial implementation * add test output
* add more granular tests
Replace index arithmetic (i * 2, i * 2 + 1) with explicit chunking using a purpose-built chunkPairs function. This makes the [value, unit] pair structure obvious through destructuring and isolates the index math.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/extract.ts`:
- Around line 399-400: The chunkPairs function currently drops the last token
when given an odd-length arr; add a validation at the top of chunkPairs to check
arr.length % 2 === 0 and throw a descriptive error (including arr length or the
offending token) when odd so malformed Go output surfaces immediately; keep the
rest of the logic intact (Array.from(...)) and ensure callers can catch this
exception if necessary.
🧹 Nitpick comments (1)
src/extract.ts (1)
346-388: Normalize and dedupe package names before deciding to suffix.
hasMultiplePackagescurrently counts sections rather than unique package names, andpkgisn’t trimmed. If output concatenates multiple runs of the same package (or includes trailing whitespace), names will be suffixed even though there’s only one unique package, changing the backward‑compat behavior.🛠️ Suggested tweak (trim + unique package counting)
- const sections = output.split(/^pkg:\s+/m).map((section, index) => { + const sections = output.split(/^pkg:\s+/m).map((section, index) => { if (index === 0) return { pkg: '', lines: section.split(/\r?\n/g) }; const [pkg, ...rest] = section.split(/\r?\n/g); - return { pkg, lines: rest }; + return { pkg: pkg.trim(), lines: rest }; }); - const hasMultiplePackages = sections.filter((s) => s.pkg).length > 1; + const packageNames = new Set(sections.map((s) => s.pkg).filter(Boolean)); + const hasMultiplePackages = packageNames.size > 1;
| function chunkPairs(arr: string[]): Array<[string, string]> { | ||
| return Array.from({ length: Math.floor(arr.length / 2) }, (_, i) => [arr[i * 2], arr[i * 2 + 1]]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against odd-length value/unit sequences.
chunkPairs silently drops the last token when arr.length is odd, which can yield partial or misleading metrics on malformed input. Consider throwing to surface invalid Go output early.
🛡️ Suggested validation
function chunkPairs(arr: string[]): Array<[string, string]> {
+ if (arr.length % 2 !== 0) {
+ throw new Error(
+ `Malformed Go benchmark metrics (expected value/unit pairs, got ${arr.length} fields): ${arr.join(' ')}`
+ );
+ }
return Array.from({ length: Math.floor(arr.length / 2) }, (_, i) => [arr[i * 2], arr[i * 2 + 1]]);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function chunkPairs(arr: string[]): Array<[string, string]> { | |
| return Array.from({ length: Math.floor(arr.length / 2) }, (_, i) => [arr[i * 2], arr[i * 2 + 1]]); | |
| function chunkPairs(arr: string[]): Array<[string, string]> { | |
| if (arr.length % 2 !== 0) { | |
| throw new Error( | |
| `Malformed Go benchmark metrics (expected value/unit pairs, got ${arr.length} fields): ${arr.join(' ')}` | |
| ); | |
| } | |
| return Array.from({ length: Math.floor(arr.length / 2) }, (_, i) => [arr[i * 2], arr[i * 2 + 1]]); | |
| } |
🤖 Prompt for AI Agents
In `@src/extract.ts` around lines 399 - 400, The chunkPairs function currently
drops the last token when given an odd-length arr; add a validation at the top
of chunkPairs to check arr.length % 2 === 0 and throw a descriptive error
(including arr length or the offending token) when odd so malformed Go output
surfaces immediately; keep the rest of the logic intact (Array.from(...)) and
ensure callers can catch this exception if necessary.
Problem Solved
When running Go benchmarks across multiple packages that have benchmarks with the same name (e.g.,
BenchmarkAppendMsgitemin bothmiddleware/cacheandmiddleware/csrf), the results would collide since they shared identical names. This made it impossible to track them separately over time.Solution
Benchmark names are now disambiguated by appending the package name in parentheses when multiple packages are detected in the output:
BenchmarkFoo→BenchmarkFoo (github.com/example/package1)BenchmarkFoo→BenchmarkFoo (github.com/example/package2)Backward compatible: When only a single package exists (or no
pkg:lines), names remain unchanged.Code Changes
src/extract.ts(+33/-28 lines)extractGoResult()to detect multiple packages by parsingpkg:lineschunkPairs()helper function for cleaner[value, unit]pair extractionflatMapapproachextractGoResultfor direct unit testingNew Test Coverage
test/extractGoResult.spec.ts(254 lines)Comprehensive unit tests covering:
Test fixtures added
go_fiber_duplicate_names_output.txt- Real-world example with duplicate names acrosscacheandcsrfpackagesgo_single_package_output.txt- Single package output for backward compatibility testingSummary by CodeRabbit
New Features
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.