Skip to content

refactor(kwaymerge): align pkg/common/kwaymerge with KHI coding rules - #1318

Merged
kyasbal merged 1 commit into
mainfrom
push-mvzyxzvtmpqq
Dec 1, 2026
Merged

kyasbal merged 1 commit into
mainfrom
push-mvzyxzvtmpqq

Conversation

@kyasbal

@kyasbal kyasbal commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

Aligns pkg/common/kwaymerge with KHI Go coding and testing conventions without changing exported APIs or runtime behavior:

  • Clarifies GoDoc contracts on Merge (tie-breaking order, non-nil newly allocated slice return, input immutability) and (*mergeHeap).Pop (container/heap.Interface semantics).
  • Renames short local identifiers (s, l, h, old, n, x) to descriptive names (inputSlice, sliceLen, cursorHeap, cursors, lastIndex, lastCursor).
  • Adds targeted behavioral unit tests (TestMerge_NilInputs, TestMerge_SingleSliceCopyIsolation, TestMerge_DescendingOrderWithIntraSliceTies) while keeping existing TestMerge unchanged.

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 — PASS

Retained Advisories

Three surviving mutants from qa-slow-advisory are 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 alter totalCount, and len(inputSlice) > 0 at 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Go Quality Report (origin/main) — ✅ PASS (0 blocking, 2 advisory finding(s))

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

@kyasbal
kyasbal added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 506f27f Dec 1, 2026
23 checks passed
@kyasbal
kyasbal deleted the push-mvzyxzvtmpqq branch December 1, 2026 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant