Repository navigation
refactor(kwaymerge): align pkg/common/kwaymerge with KHI coding rules - #1318
Merged
Merged
Conversation
kyasbal
requested review from
K53,
RyuSA,
jyane,
kkuchima and
renamoo
as code owners
December 1, 2026 03:07
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the k-way merge implementation in pkg/common/kwaymerge/kway_merge.go by renaming variables for improved clarity, updating documentation comments, and cleaning up the heap's Pop method. It also adds comprehensive unit tests in pkg/common/kwaymerge/kway_merge_test.go to cover nil inputs, slice copy isolation, and descending order with intra-slice ties. There are no review comments, so I have no feedback to provide.
Go Quality Report (
|
| Metric | Result |
|---|---|
| Changed Scope | 1 prod file(s), 1 test file(s), 3 unit(s) |
| Patch Coverage | 100.0% (21/21 lines) |
| Mutation Score | 75.0% (9/12 killed, 3 survived) |
Quality Rule Violations
| # | Rule | Status | Value (Limit) | Location | Subject |
|---|---|---|---|---|---|
[Q1] |
func_surviving_mutants |
ADVISORY |
2 (<= 0) |
pkg/common/kwaymerge/kway_merge.go:47 |
Merge |
[Q2] |
func_surviving_mutants |
ADVISORY |
1 (<= 0) |
pkg/common/kwaymerge/kway_merge.go:123 |
(*mergeHeap).Pop |
[Q1] func_surviving_mutants — pkg/common/kwaymerge/kway_merge.go:47 (Merge)
- Why: Mutating operators or branches in this touched function did not cause any unit test to fail.
- Fix: Delete redundant guards first, or strengthen assertions (cmp.Diff on full outputs and boundary inputs).
- Detail: 2 mutant(s) survived unit tests
- if sliceLen > 0 {
+ if sliceLen >= 0 {- totalCount += sliceLen
+ /* skipped: totalCount += sliceLen */[Q2] func_surviving_mutants — pkg/common/kwaymerge/kway_merge.go:123 ((*mergeHeap).Pop)
- Why: Mutating operators or branches in this touched function did not cause any unit test to fail.
- Fix: Delete redundant guards first, or strengthen assertions (cmp.Diff on full outputs and boundary inputs).
- Detail: 1 mutant(s) survived unit tests
- cursors[lastIndex] = nil
+ /* skipped: cursors[lastIndex] = nil */Commit: 43ea33f93359 · Cloud Build Logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Aligns
pkg/common/kwaymergewith KHI Go coding and testing conventions without changing exported APIs or runtime behavior:Merge(tie-breaking order, non-nil newly allocated slice return, input immutability) and(*mergeHeap).Pop(container/heap.Interfacesemantics).s,l,h,old,n,x) to descriptive names (inputSlice,sliceLen,cursorHeap,cursors,lastIndex,lastCursor).TestMerge_NilInputs,TestMerge_SingleSliceCopyIsolation,TestMerge_DescendingOrderWithIntraSliceTies) while keeping existingTestMergeunchanged.Verification
make pre-push— PASS (0 mustfix, 0 advisory, 0 skipped)make qa-all-advisory CODEQUALITY_SIMILARITY=true— PASS (0 mustfix, 0 similarity advisories, 0 test redundancy, 0 uncovered lines)go test -race -count=1 ./pkg/common/kwaymerge/...— PASS (97.6%statement coverage)go test -race -count=1 ./pkg/task/inspection/googlecloud/gcpcommon -run Structured— PASSRetained Advisories
Three surviving mutants from
qa-slow-advisoryare intentionally retained as non-actionable:kway_merge.go:47(sliceLen > 0->sliceLen >= 0): equivalent mutant for length-0 slices; adding an empty slice does not altertotalCount, andlen(inputSlice) > 0at the heap init loop still skips empty slices.kway_merge.go:48(totalCount += sliceLen->totalCount -= sliceLen/make([]T, 0, totalCount)): capacity pre-allocation optimization hint only (not an observable behavioral bug); retaining pre-sizing avoids unnecessary reallocations.kway_merge.go:123(cursors[lastIndex] = nil): GC pointer-clearing hygiene on popped heap slot; not directly observable via output assertions.