Skip to content

Conversation

@amery
Copy link
Contributor

@amery amery commented Aug 5, 2025

User description

Add Same-ness Testing Functions and Improve Test Patterns

Summary

This PR introduces new testing utilities for same-ness comparison in Go
and modernises existing test patterns to use them. Same-ness testing
distinguishes between value equality (for basic types) and reference
equality (for reference types), filling a gap in the current testing
toolkit.

Key Features

New Functions Added

  • IsSame(a, b any) bool - Core function for same-ness comparison.

    • Value types (numbers, strings, booleans): compares by equal values.
    • Reference types (slices, maps, pointers, channels, functions):
      compares by pointer equality.
    • Proper nil handling: typed nils of same type are considered same.
    • Interface support with recursive comparison of contained values.
    • Special handling for Go's runtime optimisation of empty slices.
    • Protection against invalid reflect.Values to prevent panics.
  • AssertSame(t, expected, actual, name, args...) - Testing
    assertion for same references/values.

  • AssertNotSame(t, expected, actual, name, args...) - Testing
    assertion for different references/values.

  • AssertMustSame(t, expected, actual, name, args...) - Fatal
    assertion for same references/values that calls t.FailNow() on
    failure.

  • AssertMustNotSame(t, expected, actual, name, args...) - Fatal
    assertion for different references/values that calls t.FailNow() on
    failure.

Cross-Compatible Test Utilities

  • doRun Pattern Documentation - Added comprehensive documentation for
    creating test functions that work with both *testing.T and MockT:
    • Interface type assertion patterns for Run method detection.
    • Graceful degradation for different testing interfaces.
    • Enhanced MockT.Run documentation with usage examples.
    • New README.md section with complete implementation guide.

Test Pattern Improvements

Modernised 24 locations across 4 test files to follow documentation
standards:

  • Replaced manual pointer comparisons with AssertSame()/AssertNotSame().
  • Converted t.Fatal() patterns to if !Assert() { return } per
    documentation.
  • Improved error messages and consistency.

Technical Details

Implementation Highlights

  • Complexity-compliant: Uses helper functions to meet cognitive
    complexity ≤7 requirements.
  • Comprehensive type handling: Covers all Go types including generics
    and interfaces.
  • Memory-efficient: Field-aligned test case structs with factory
    functions.
  • Full test coverage: 97.2% coverage with 100+ test scenarios.

Special Cases Handled

  • Zero-capacity slices: Go optimises make([]T, 0) to share memory.
    IsSame treats these as distinct to preserve expected semantics.
  • Invalid reflect.Values: Returns false rather than panicking when
    comparing invalid reflect.Values.
  • Unsafe pointers: Full support with appropriate DeepSource
    annotations.
  • Complex numbers: Proper handling including NaN and Inf edge cases.

Files Changed

File Changes Description
zero.go +198 lines Core IsSame() implementation with helpers
testing.go +107 lines Assert/AssertMust functions and documentation
zero_test.go +540 lines Comprehensive test suite with all edge cases
testing_test.go +150 lines Assertion function tests using MockT
compounderror_test.go 118 changes Method chaining and error validation
errgroup_test.go 16 changes Error instance verification
lists_test.go 4 changes Copy independence check
as_test.go 12 changes Slice length validation
README.md +33 lines Same-ness functions and patterns
TESTING.md +2 lines Updated assertion function list

Usage Examples

// Value types - same when equal
IsSame(42, 42)           // true
IsSame("hello", "hello") // true

// Reference types - same when same pointer
slice1 := []int{1, 2, 3}
slice2 := slice1         // same reference
slice3 := []int{1, 2, 3} // different reference, same content

IsSame(slice1, slice2)   // true  - same pointer
IsSame(slice1, slice3)   // false - different pointers

// Empty slices - special case
empty1 := make([]int, 0)
empty2 := make([]int, 0)
IsSame(empty1, empty2)   // false - separate make() calls

// Testing assertions
AssertSame(t, slice1, slice2, "slice reference")
AssertNotSame(t, slice1, slice3, "different slices")

// Fatal assertions (call t.FailNow() on failure).
AssertMustSame(t, slice1, slice2, "critical slice reference")
AssertMustNotSame(t, slice1, slice3, "critical different slices")

Verification

  • All tests pass: No functionality broken.
  • Full linting compliance: 0 issues reported.
  • High test coverage: 97.2% coverage maintained.
  • Documentation complete: README and TESTING.md updated.
  • Pattern consistency: Follows established testing guidelines.

Why This Matters

The existing AssertEqual() uses deep comparison, which doesn't work for
testing same-ness of reference types like maps and slices. These new
functions provide:

  1. Clearer intent: Explicitly test for reference equality vs value
    equality.
  2. Better error messages: Consistent formatting and logging.
  3. Modern patterns: Follows documentation standards for test structure.
  4. Type safety: Handles all Go types correctly including nil cases.
  5. Safety: Protection against panics from invalid reflect.Values.

This enhancement strengthens the testing foundation for both internal
library tests and external library users.


PR Type

Enhancement, Tests


Description

  • Add IsSame(), AssertSame(), and AssertNotSame() functions.
  • Add AssertMustSame() and AssertMustNotSame() fatal assertion variants.
  • Document cross-compatible test function patterns for *testing.T and MockT.
  • Add comprehensive doRun helper pattern examples and usage guidance.
  • Modernize test patterns across 4 test files.
  • Replace manual pointer comparisons with new assertions.
  • Convert t.Fatal() patterns to if !Assert() { return }

Diagram Walkthrough

flowchart LR
  A["IsSame() function"] --> B["AssertSame() assertion"]
  A --> C["AssertNotSame() assertion"]
  B --> D["AssertMust variants"]
  C --> D
  D --> E["Cross-compatible patterns"]
  E --> F["Test pattern improvements"]
  F --> G["Better error messages"]
Loading

File Walkthrough

Relevant files
Enhancement
6 files
zero.go
Add IsSame function with helper functions                               
+127/-0 
testing.go
Add AssertSame and AssertNotSame functions                             
+62/-0   
as_test.go
Replace manual length checks with AssertEqual                       
+6/-6     
compounderror_test.go
Modernize test patterns and error validation                         
+42/-53 
errgroup_test.go
Replace manual error checks with AssertSame                           
+4/-12   
lists_test.go
Replace pointer comparison with AssertNotSame                       
+1/-3     
Tests
2 files
zero_test.go
Add comprehensive IsSame test suite                                           
+211/-0 
testing_test.go
Add tests for new assertion functions                                       
+94/-0   
Documentation
2 files
README.md
Document new IsSame and assertion functions                           
+11/-0   
TESTING.md
Add new assertion functions to list                                           
+2/-0     

Summary by CodeRabbit

  • New Features

    • Added IsSame (value vs reference identity), a generic S[...] slice helper, AssertSame/AssertNotSame and many AssertMust... fatal variants.
  • Documentation

    • Updated README and testing guidelines with sameness semantics and cross-compatible Run() patterns.
  • Tests

    • Extensive IsSame coverage, recursion/edge-case tests; refactored many tests to use the new assertion helpers.
  • Chores

    • Added "skipcq" to spellcheck dictionary.

@coderabbitai
Copy link

coderabbitai bot commented Aug 5, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds IsSame(a, b) for value vs reference identity, refactors nil handling, introduces AssertSame/AssertNotSame and many AssertMust* fatal wrappers plus generic S[T], updates docs, and refactors tests to use the new assertions with comprehensive unit tests and edge-case coverage.

Changes

Cohort / File(s) Change Summary
Documentation
README.md, TESTING.md
Documented IsSame, AssertSame/AssertNotSame, cross-compatible Run() guidance and usage examples; added new basic assertions to testing guidelines.
Core utilities
zero.go
Added IsSame(a, b) and supporting reflect helpers (asReflectValue, isReflectValueSame, isSamePointer, isSameTypedNil, isSameNil, isReflectSliceZero); simplified IsNil to unify reflect handling.
Test helpers & API
testing.go
Added AssertSame, AssertNotSame, fatal AssertMust* variants (including many AssertMust* wrappers), AssertMustTypeIs, generic S[T any](...) []T, and doc on MockT.Run compatibility.
New tests
zero_test.go, testing_test.go
Added extensive IsSame test suites (value, reference, nil, interface, reflect.Value, unsafe.Pointer, complex, recursion/stack-edge cases) and tests for AssertSame/AssertNotSame and their Must-variants.
Refactored tests
as_test.go, compounderror_test.go, errgroup_test.go, lists_test.go
Replaced direct t.Fatalf/manual checks with assertion helpers (AssertEqual, AssertSame, AssertNotSame, AssertNil, etc.) and used guarded early returns on failures.
Misc config
internal/build/cspell.json
Added the word "skipcq" to the spell-check dictionary.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test code
    participant Assert as AssertSame / AssertNotSame
    participant IsSame as IsSame helper
    Test->>Assert: call AssertSame(t, expected, actual, ...)
    Assert->>IsSame: IsSame(expected, actual)
    IsSame-->>Assert: true / false
    Assert-->>Test: log success or failure (returns bool)
    alt Must variant failure
        Assert->>Test: FailNow / abort execution
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Suggested labels

tests, Review effort 4/5

Suggested reviewers

  • karasz

Poem

"I hop through code with twitching whisk,
I check if pointers truly kiss.
IsSame I learned, assertions sing —
Must stop on fail, or gently spring.
A rabbit cheers as tests take wing." 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pr-amery-same

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Aug 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@deepsource-io
Copy link

deepsource-io bot commented Aug 5, 2025

Here's the code health analysis summary for commits f782fdf..8735af2. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Shell LogoShell✅ SuccessView Check ↗
DeepSource Go LogoGo✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@qodo-code-review
Copy link

qodo-code-review bot commented Aug 5, 2025

PR Reviewer Guide 🔍

(Review updated until commit 0f7833f)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

Pointer equality is used for all reference kinds including func via reflect.Value.Pointer(). For function values, reflect.Value.Pointer is only defined for funcs created by MakeFunc; comparing function pointers may be unreliable across implementations. Validate that IsSame(funcA, funcB) behaves as intended and is portable.

var ok bool
switch va.Kind() {
case reflect.Ptr, reflect.Slice, reflect.Map, reflect.Chan, reflect.Func, reflect.UnsafePointer:
	ok = va.Pointer() == vb.Pointer()
case reflect.Interface:
	// Extract concrete values and compare them recursively
	a := va.Elem().Interface()
	b := vb.Elem().Interface()
	ok = IsSame(a, b)
case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
	reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
	reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.Bool:
	ok = va.Interface() == vb.Interface()
}
Edge Case

Interface recursion in isSamePointer calls IsSame again without a visited-set; complex cyclic interface graphs could risk deep recursion. Tests cover some cycles, but confirm no pathological cases in production inputs and consider recursion depth guard if needed.

case reflect.Interface:
	// Extract concrete values and compare them recursively
	a := va.Elem().Interface()
	b := vb.Elem().Interface()
	ok = IsSame(a, b)
case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
API Consistency

New AssertSame/AssertNotSame messages/logs differ in phrasing from other asserts. Ensure downstream tests and documentation expect "same value or reference"/"different values or references" and that formatting with name/args integrates consistently with doError/doLog.

	t.Helper()
	ok := IsSame(expected, actual)
	if !ok {
		doError(t, name, args, "expected same value or reference, got different")
	} else {
		doLog(t, name, args, "same value or reference")
	}
	return ok
}

// AssertNotSame asserts that two values are not the same.
// For reference types, this tests that they do not point to the same
// underlying data. For value types, this tests that they have different
// values. This is useful for testing that two slices, maps, or pointers
// reference different memory locations, even if they have equal contents.
// The name parameter can include printf-style formatting.
// Returns true if the assertion passed, false otherwise.
//
// Example usage:
//
//	slice1 := []int{1, 2, 3}
//	slice2 := []int{1, 2, 3}  // same content, different backing array
//	AssertNotSame(t, slice1, slice2, "slice reference")
//
//	map1 := make(map[string]int)
//	map2 := make(map[string]int)  // different maps
//	AssertNotSame(t, map1, map2, "map reference")
//
//	AssertNotSame(t, 42, 43, "number value")
//	AssertNotSame(t, "hello", "world", "string value")
func AssertNotSame(t T, expected, actual any, name string, args ...any) bool {
	t.Helper()
	ok := !IsSame(expected, actual)
	if !ok {
		doError(t, name, args, "expected different values or references, got same")
	} else {
		doLog(t, name, args, "different values or references")
	}
	return ok
}

@qodo-code-review
Copy link

qodo-code-review bot commented Aug 5, 2025

PR Code Suggestions ✨

Latest suggestions up to 8735af2

CategorySuggestion                                                                                                                                    Impact
Incremental [*]
Improve assertion diagnostics

Clarify the assertion failure/log messages to include both expected and actual
values for easier diagnosis, mirroring the pattern used elsewhere, without
changing the equality semantics

testing.go [553-562]

 func AssertSame(t T, expected, actual any, name string, args ...any) bool {
 	t.Helper()
 	ok := IsSame(expected, actual)
 	if !ok {
-		doError(t, name, args, "expected same value or reference, got different")
+		doError(t, name, args, "expected same value or reference, got different: expected=%v actual=%v", expected, actual)
 	} else {
-		doLog(t, name, args, "same value or reference")
+		doLog(t, name, args, "same value or reference: %v", actual)
 	}
 	return ok
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: This suggestion improves the diagnostic messages for AssertSame by including actual and expected values, which is a good practice for test utilities and aids debugging.

Low
  • More

Previous suggestions

Suggestions up to commit a408c65
CategorySuggestion                                                                                                                                    Impact
Incremental [*]
Guard invalid reflect.Values

Prevent panics by guarding against invalid reflect.Values before accessing
.Type() or .Kind(); if either va or vb is invalid, return true only if both are
invalid (same), otherwise false.

zero.go [180-192]

 func isReflectValueSame(va, vb reflect.Value) bool {
+	if !va.IsValid() || !vb.IsValid() {
+		return !va.IsValid() && !vb.IsValid()
+	}
 	if va.Type() != vb.Type() {
-		// different types
 		return false
 	}
-
 	if same, ok := isSameTypedNil(va, vb); ok {
-		// typed nil decision
 		return same
 	}
-
 	return isSamePointer(va, vb)
 }
Suggestion importance[1-10]: 8

__

Why: This suggestion correctly identifies a potential panic when calling .Type() on an invalid reflect.Value and provides a robust fix, which is a critical improvement for the function's correctness.

Medium
General
Improve failure diagnostics

When the assertion fails, include the compared values and their concrete types
to aid debugging. This avoids opaque messages during failures, especially for
interfaces and reference types.

testing.go [553-562]

 func AssertSame(t T, expected, actual any, name string, args ...any) bool {
 	t.Helper()
 	ok := IsSame(expected, actual)
 	if !ok {
-		doError(t, name, args, "expected same value or reference, got different")
+		doError(t, name, args, "expected same value or reference, got different (expected=%T(%v), actual=%T(%v))", expected, expected, actual, actual)
 	} else {
 		doLog(t, name, args, "same value or reference")
 	}
 	return ok
 }
Suggestion importance[1-10]: 7

__

Why: The suggestion improves the assertion's utility by adding the actual values and types to the failure message, which significantly aids in debugging test failures.

Medium
Suggestions up to commit 89c67cd
CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix nil interface comparison logic

The function should handle the case where both interfaces are nil, which should
return true for consistency with other nil handling in IsSame. Currently it
returns false when both are nil.

zero.go [293-298]

 func isSameInterface(va, vb reflect.Value) bool {
-	if va.IsNil() || vb.IsNil() {
+	aNil := va.IsNil()
+	bNil := vb.IsNil()
+	if aNil && bNil {
+		return true
+	}
+	if aNil || bNil {
 		return false
 	}
 	return IsSame(va.Elem().Interface(), vb.Elem().Interface())
 }
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a bug where isSameInterface returns false for two nil interfaces, which is inconsistent with the overall logic of IsSame and could lead to incorrect behavior.

Medium
General
Add explicit type annotation

The explicit type annotation S[error] should be used for consistency with other
test cases in the same file. This ensures type clarity and matches the pattern
used in the "append all nils" test case.

compounderror_test.go [232]

-S(nil, errors.New("valid"), nil), 2),
+S[error](nil, errors.New("valid"), nil), 2),
Suggestion importance[1-10]: 3

__

Why: The suggestion correctly identifies a stylistic inconsistency, but it proposes reverting a change made in the PR that relies on Go's type inference, making its impact minor.

Low

@amery amery requested a review from karasz August 5, 2025 17:09
@amery amery self-assigned this Aug 5, 2025
@amery amery added the enhancement New feature or request label Aug 5, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (3)
compounderror_test.go (1)

390-393: Consider simplifying the assertion logic

The complex boolean condition could be simplified by using separate AssertContains calls for better clarity and more precise error messages.

-				condition := strings.Contains(errorStr, expectedNote) || strings.Contains(errorStr, tc.note)
-				if !AssertTrue(t, condition, "note in error string") {
-					return
-				}
+				if !AssertContains(t, errorStr, expectedNote, "formatted note in error string") &&
+					!AssertContains(t, errorStr, tc.note, "original note in error string") {
+					return
+				}
testing.go (2)

466-466: Consider improving the error message for clarity

The error message "expected same reference, got different references" might be confusing when comparing value types. Consider making it more generic to cover both value and reference comparisons.

-		doError(t, name, args, "expected same reference, got different references")
+		doError(t, name, args, "expected same value or reference, got different")

497-497: Consider improving the error message for clarity

Similar to AssertSame, the error message could be more generic to avoid confusion with value types.

-		doError(t, name, args, "expected different references, got same reference")
+		doError(t, name, args, "expected different values or references, got same")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3ec005 and 89c67cd.

📒 Files selected for processing (10)
  • README.md (2 hunks)
  • TESTING.md (1 hunks)
  • as_test.go (3 hunks)
  • compounderror_test.go (15 hunks)
  • errgroup_test.go (4 hunks)
  • lists_test.go (1 hunks)
  • testing.go (1 hunks)
  • testing_test.go (1 hunks)
  • zero.go (1 hunks)
  • zero_test.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.md

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.md: Enforce Markdown formatting rules, including 80-character line limits and strict formatting, using markdownlint with configuration in internal/build/markdownlint.json.
Check Markdown files for grammar and style issues using LanguageTool with configuration in internal/build/languagetool.cfg.
When editing Markdown files, ensure compliance with LanguageTool, CSpell, and Markdownlint.
End all bullet points in Markdown files with periods for consistency.
Capitalize proper nouns correctly (JavaScript, TypeScript, Markdown) in documentation.
Use consistent punctuation in examples and lists in documentation.
Provide context and 'why' explanations in documentation, not just 'what' descriptions.
Add examples for complex concepts or common pitfalls in documentation.
Update documentation when adding new tools or changing workflows.
Keep the pre-commit checklist current with project practices.
Review documentation changes for missing articles, punctuation, and compound modifiers.

Files:

  • TESTING.md
  • README.md
**/*.{md,go}

📄 CodeRabbit Inference Engine (AGENT.md)

Check spelling in both Markdown and Go source files using CSpell with configuration in internal/build/cspell.json.

Files:

  • TESTING.md
  • lists_test.go
  • errgroup_test.go
  • compounderror_test.go
  • as_test.go
  • testing_test.go
  • testing.go
  • zero.go
  • zero_test.go
  • README.md
**/*.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.go: Use Go 1.23+ generics for type-safe utilities.
Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.
Enforce struct field alignment optimization for memory efficiency using the fieldalignment tool.
Use golangci-lint with configuration in .golangci.yml for comprehensive Go code linting.

Files:

  • lists_test.go
  • errgroup_test.go
  • compounderror_test.go
  • as_test.go
  • testing_test.go
  • testing.go
  • zero.go
  • zero_test.go
**/*_test.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*_test.go: Prefer table-driven tests for Go code.
Use helper functions like ST, AssertEqualT, AssertSliceEqualT, AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Provide comprehensive coverage for generic functions.

Files:

  • lists_test.go
  • errgroup_test.go
  • compounderror_test.go
  • as_test.go
  • testing_test.go
  • zero_test.go
README.md

📄 CodeRabbit Inference Engine (AGENT.md)

Update README.md to reflect significant changes in functionality or API.

Files:

  • README.md
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.
📚 Learning: applies to **/*_test.go : use helper functions like s[t](), assertequal[t](), assertsliceequal[t](),...
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.

Applied to files:

  • TESTING.md
  • lists_test.go
  • errgroup_test.go
  • compounderror_test.go
  • as_test.go
  • testing_test.go
  • testing.go
  • zero.go
  • zero_test.go
  • README.md
📚 Learning: applies to **/*_test.go : provide comprehensive coverage for generic functions....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.

Applied to files:

  • TESTING.md
  • lists_test.go
  • errgroup_test.go
  • compounderror_test.go
  • as_test.go
  • testing_test.go
  • testing.go
  • zero.go
  • zero_test.go
  • README.md
📚 Learning: applies to readme.md : update readme.md to reflect significant changes in functionality or api....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to README.md : Update README.md to reflect significant changes in functionality or API.

Applied to files:

  • TESTING.md
  • README.md
📚 Learning: applies to **/*_test.go : prefer table-driven tests for go code....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.

Applied to files:

  • lists_test.go
  • errgroup_test.go
  • compounderror_test.go
  • as_test.go
  • testing_test.go
  • testing.go
  • zero_test.go
  • README.md
📚 Learning: in the go `core` package's `list.go` file, the method `unsafeforeachelement` in `list[t]` does not n...
Learnt from: amery
PR: darvaza-proxy/core#84
File: list.go:160-171
Timestamp: 2024-11-15T04:50:14.792Z
Learning: In the Go `core` package's `list.go` file, the method `unsafeForEachElement` in `List[T]` does not need to check if `l` is `nil` because all public methods that call it already perform this check.

Applied to files:

  • lists_test.go
  • compounderror_test.go
📚 Learning: in `list.go`, the `list[t]` methods `len` and `foreach` handle a nil receiver gracefully....
Learnt from: amery
PR: darvaza-proxy/core#86
File: list.go:83-89
Timestamp: 2024-11-16T07:43:16.106Z
Learning: In `list.go`, the `List[T]` methods `Len` and `ForEach` handle a nil receiver gracefully.

Applied to files:

  • lists_test.go
  • compounderror_test.go
📚 Learning: applies to **/*.go : use go 1.23+ generics for type-safe utilities....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.

Applied to files:

  • compounderror_test.go
  • zero.go
📚 Learning: when suggesting refactoring of build scripts, consider the possibility of nested `go.mod` files with...
Learnt from: amery
PR: darvaza-proxy/core#79
File: internal/build/gen_mk.sh:161-169
Timestamp: 2024-10-08T15:33:35.792Z
Learning: When suggesting refactoring of build scripts, consider the possibility of nested `go.mod` files within subdirectories like `./cmd/`, and ensure that the proposed changes handle nested modules correctly.

Applied to files:

  • compounderror_test.go
📚 Learning: applies to **/*.go : enforce strict linting rules via revive as configured in internal/build/revive....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.

Applied to files:

  • compounderror_test.go
📚 Learning: applies to **/*.go : max function length: 40 lines....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-07-18T16:39:19.390Z
Learning: Applies to **/*.go : Max function length: 40 lines.

Applied to files:

  • compounderror_test.go
📚 Learning: applies to **/*.go : max function results: 3....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-07-18T16:39:19.390Z
Learning: Applies to **/*.go : Max function results: 3.

Applied to files:

  • compounderror_test.go
📚 Learning: `errnilreceiver`, defined in `errors.go`, is intended for use by other packages even if it's not use...
Learnt from: amery
PR: darvaza-proxy/core#82
File: errors.go:22-23
Timestamp: 2024-10-11T13:59:15.993Z
Learning: `ErrNilReceiver`, defined in `errors.go`, is intended for use by other packages even if it's not used within the current codebase.

Applied to files:

  • compounderror_test.go
🔇 Additional comments (19)
zero.go (5)

173-249: Excellent implementation and documentation.

The IsSame function is well-designed with comprehensive documentation that clearly explains the distinction between value and reference type comparisons. The implementation correctly handles edge cases including nil values, typed nils, and interface types. The structured approach using helper functions keeps the cognitive complexity manageable whilst maintaining readability.


251-260: LGTM!

The handleNilCases helper function correctly handles untyped nil comparisons with clear logic and appropriate return values.


262-274: LGTM!

The handleTypedNilCases helper function correctly handles typed nil comparisons and appropriately reuses existing helper functions for consistency.


276-290: LGTM!

The isSamePointer helper function correctly implements the core comparison logic, appropriately distinguishing between reference types (compared by pointer) and value types (compared by value). The handling of interface types with recursive comparison is well-designed.


292-298: LGTM!

The isSameInterface helper function correctly handles interface comparison by extracting concrete values and using recursion. The nil check appropriately prevents issues with nil interfaces.

lists_test.go (1)

222-222: Excellent modernisation of test assertions.

The replacement of direct pointer comparison with AssertNotSame improves test consistency and leverages the new sameness comparison utilities. This provides better error messages and aligns with the modern testing patterns introduced in this PR.

TESTING.md (1)

92-93: Well-documented new assertion functions.

The documentation for AssertSame and AssertNotSame is clear and appropriately describes their functionality for checking reference/value sameness. The descriptions are consistent with the existing documentation style and accurately reflect the underlying implementation.

as_test.go (3)

165-167: Improved test pattern with standardised assertions.

The replacement of manual length comparison with AssertEqual and early return improves test consistency and leverages the new assertion utilities for better error reporting.


201-203: Consistent modernisation of test assertions.

The update maintains consistency with other test case types by using AssertEqual for length comparison, providing standardised error reporting and improved test maintainability.


302-304: Consistent test modernisation completed.

The final update to use AssertEqual completes the consistent modernisation of test assertions across all affected test case types in this file.

errgroup_test.go (4)

320-320: Appropriate use of reference equality assertion.

The use of AssertSame correctly verifies that the exact same error instance is preserved during subsequent cancellations, which is the intended behavior for error group cancellation semantics.


333-333: Correct assertion for sentinel error verification.

The use of AssertSame appropriately verifies that the specific context.Canceled sentinel error is returned when cancelling with nil, ensuring correct error group semantics.


356-356: Proper verification of error instance propagation.

The use of AssertSame correctly verifies that the error handler receives the exact same error instance, ensuring proper error propagation through the callback mechanism.


491-491: Appropriate verification of error pass-through behavior.

The use of AssertSame correctly verifies that the error catcher returns the exact same error instance without modification when the group is not cancelled, ensuring proper pass-through semantics.

testing_test.go (2)

635-680: Well-structured test coverage for AssertSame

The test thoroughly covers both value and reference type scenarios, correctly verifying return values, error states, and log messages.


682-727: Comprehensive test coverage for AssertNotSame

The test properly validates the inverse behaviour of AssertSame, with good coverage of edge cases including slices with identical contents but different backing arrays.

README.md (2)

127-133: Clear and accurate documentation for IsSame

The documentation effectively explains the distinction between reference and value type comparisons, with a clear statement about nil handling.


476-479: Well-integrated testing utilities documentation

The new assertion functions are properly documented alongside existing assertions, maintaining consistency in style and format.

zero_test.go (1)

882-1090: Excellent test coverage for IsSame function

The test suite is comprehensive and well-organised:

  • Proper memory-efficient struct field alignment
  • Thorough coverage of all type categories
  • Clear test descriptions
  • Good edge case handling, particularly for nil values and interfaces

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
zero.go (1)

277-290: Consider renaming isSamePointer to better reflect its purpose

The function name isSamePointer is misleading as it handles both reference types (using pointer comparison) and value types (using value comparison). Consider renaming it to something like isSameByKind or compareByKind to better convey that it handles all types based on their kind.

-// isSamePointer compares pointer equality based on the reflect value kind
-func isSamePointer(va, vb reflect.Value) bool {
+// isSameByKind compares values based on their reflect.Kind
+func isSameByKind(va, vb reflect.Value) bool {

Also update the call site at line 248:

-	return isSamePointer(va, vb)
+	return isSameByKind(va, vb)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89c67cd and 236fa80.

📒 Files selected for processing (10)
  • README.md (2 hunks)
  • TESTING.md (1 hunks)
  • as_test.go (3 hunks)
  • compounderror_test.go (12 hunks)
  • errgroup_test.go (4 hunks)
  • lists_test.go (1 hunks)
  • testing.go (1 hunks)
  • testing_test.go (1 hunks)
  • zero.go (1 hunks)
  • zero_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • TESTING.md
  • as_test.go
  • errgroup_test.go
  • lists_test.go
  • testing.go
  • testing_test.go
  • README.md
  • compounderror_test.go
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{md,go}

📄 CodeRabbit Inference Engine (AGENT.md)

Check spelling in both Markdown and Go source files using CSpell with configuration in internal/build/cspell.json.

Files:

  • zero.go
  • zero_test.go
**/*.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.go: Use Go 1.23+ generics for type-safe utilities.
Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.
Enforce struct field alignment optimization for memory efficiency using the fieldalignment tool.
Use golangci-lint with configuration in .golangci.yml for comprehensive Go code linting.

Files:

  • zero.go
  • zero_test.go
**/*_test.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*_test.go: Prefer table-driven tests for Go code.
Use helper functions like ST, AssertEqualT, AssertSliceEqualT, AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Provide comprehensive coverage for generic functions.

Files:

  • zero_test.go
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.893Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.
📚 Learning: applies to **/*_test.go : provide comprehensive coverage for generic functions....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.

Applied to files:

  • zero.go
  • zero_test.go
📚 Learning: applies to **/*.go : use go 1.23+ generics for type-safe utilities....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.

Applied to files:

  • zero.go
📚 Learning: applies to **/*_test.go : use helper functions like s[t](), assertequal[t](), assertsliceequal[t](),...
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.

Applied to files:

  • zero_test.go
📚 Learning: applies to **/*_test.go : prefer table-driven tests for go code....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.

Applied to files:

  • zero_test.go
📚 Learning: in go test functions using assertion helpers like assertsame, assertequal, etc., early returns after...
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.893Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.

Applied to files:

  • zero_test.go
🧬 Code Graph Analysis (1)
zero_test.go (2)
testing.go (5)
  • TestCase (158-161)
  • T (20-28)
  • AssertEqual (187-196)
  • S (149-154)
  • RunTestCases (169-176)
zero.go (1)
  • IsSame (232-249)
🔇 Additional comments (2)
zero.go (1)

173-249: Well-structured implementation with good separation of concerns

The IsSame function is well-designed with clear logic flow and appropriate use of helper functions to maintain low cognitive complexity. The comprehensive documentation with examples is particularly helpful.

zero_test.go (1)

882-1090: Excellent test coverage with well-organised test cases

The test implementation for IsSame is comprehensive and well-structured:

  • Good field alignment optimisation in the isSameTestCase struct
  • Thorough coverage of all scenarios: value types, reference types, nil handling, different types, and interfaces
  • Clear test organisation with descriptive names
  • Proper use of existing test helpers and patterns

The tests validate all the behaviours documented in the IsSame function.

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
zero.go (1)

296-310: Review the interface handling in isSamePointer.

The switch statement covers most cases well, but there's a potential issue: if none of the cases match (which shouldn't happen with valid reflect.Values), the function returns false by default. Consider adding a default case that handles unexpected kinds explicitly.

 func isSamePointer(va, vb reflect.Value) bool {
 	var ok bool
 	switch va.Kind() {
 	case reflect.Ptr, reflect.Slice, reflect.Map, reflect.Chan, reflect.Func, reflect.UnsafePointer:
 		ok = va.Pointer() == vb.Pointer()
 	case reflect.Interface:
 		ok = isSameInterface(va, vb)
 	case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
 		reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
 		reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.Bool:
 		ok = va.Interface() == vb.Interface()
+	default:
+		// Arrays, structs, and other composite types should use deep comparison
+		// For now, return false as these cases need specific handling
+		ok = false
 	}
 	return ok
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 236fa80 and cc5b505.

📒 Files selected for processing (10)
  • README.md (2 hunks)
  • TESTING.md (1 hunks)
  • as_test.go (3 hunks)
  • compounderror_test.go (12 hunks)
  • errgroup_test.go (4 hunks)
  • lists_test.go (1 hunks)
  • testing.go (1 hunks)
  • testing_test.go (1 hunks)
  • zero.go (2 hunks)
  • zero_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • testing.go
  • errgroup_test.go
  • lists_test.go
  • TESTING.md
  • as_test.go
  • compounderror_test.go
  • README.md
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{md,go}

📄 CodeRabbit Inference Engine (AGENT.md)

Check spelling in both Markdown and Go source files using CSpell with configuration in internal/build/cspell.json.

Files:

  • testing_test.go
  • zero_test.go
  • zero.go
**/*.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.go: Use Go 1.23+ generics for type-safe utilities.
Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.
Enforce struct field alignment optimization for memory efficiency using the fieldalignment tool.
Use golangci-lint with configuration in .golangci.yml for comprehensive Go code linting.

Files:

  • testing_test.go
  • zero_test.go
  • zero.go
**/*_test.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*_test.go: Prefer table-driven tests for Go code.
Use helper functions like ST, AssertEqualT, AssertSliceEqualT, AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Provide comprehensive coverage for generic functions.

Files:

  • testing_test.go
  • zero_test.go
🧠 Learnings (11)
📓 Common learnings
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.893Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.
📚 Learning: applies to **/*_test.go : use helper functions like s[t](), assertequal[t](), assertsliceequal[t](),...
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.

Applied to files:

  • testing_test.go
  • zero_test.go
  • zero.go
📚 Learning: in go test functions using assertion helpers like assertsame, assertequal, etc., early returns after...
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.893Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.

Applied to files:

  • testing_test.go
  • zero_test.go
  • zero.go
📚 Learning: applies to **/*_test.go : provide comprehensive coverage for generic functions....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.

Applied to files:

  • testing_test.go
  • zero_test.go
  • zero.go
📚 Learning: applies to **/*_test.go : prefer table-driven tests for go code....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.

Applied to files:

  • testing_test.go
  • zero_test.go
📚 Learning: in the go `core` package's `list.go` file, the method `unsafeforeachelement` in `list[t]` does not n...
Learnt from: amery
PR: darvaza-proxy/core#84
File: list.go:160-171
Timestamp: 2024-11-15T04:50:14.792Z
Learning: In the Go `core` package's `list.go` file, the method `unsafeForEachElement` in `List[T]` does not need to check if `l` is `nil` because all public methods that call it already perform this check.

Applied to files:

  • zero.go
📚 Learning: applies to **/*.go : use go 1.23+ generics for type-safe utilities....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.

Applied to files:

  • zero.go
📚 Learning: in `list.go`, the `list[t]` methods `len` and `foreach` handle a nil receiver gracefully....
Learnt from: amery
PR: darvaza-proxy/core#86
File: list.go:83-89
Timestamp: 2024-11-16T07:43:16.106Z
Learning: In `list.go`, the `List[T]` methods `Len` and `ForEach` handle a nil receiver gracefully.

Applied to files:

  • zero.go
📚 Learning: use only the go standard library and minimal golang.org/x packages; zero external dependencies....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Use only the Go standard library and minimal golang.org/x packages; zero external dependencies.

Applied to files:

  • zero.go
📚 Learning: in go, avoid suggesting dereferencing a `nil` pointer receiver within a method to initialize it, as ...
Learnt from: amery
PR: darvaza-proxy/core#86
File: list.go:32-36
Timestamp: 2024-11-16T05:20:11.432Z
Learning: In Go, avoid suggesting dereferencing a `nil` pointer receiver within a method to initialize it, as this will cause a runtime panic.

Applied to files:

  • zero.go
📚 Learning: `errnilreceiver`, defined in `errors.go`, is intended for use by other packages even if it's not use...
Learnt from: amery
PR: darvaza-proxy/core#82
File: errors.go:22-23
Timestamp: 2024-10-11T13:59:15.993Z
Learning: `ErrNilReceiver`, defined in `errors.go`, is intended for use by other packages even if it's not used within the current codebase.

Applied to files:

  • zero.go
🧬 Code Graph Analysis (2)
testing_test.go (1)
testing.go (5)
  • T (20-28)
  • MockT (32-38)
  • AssertSame (462-471)
  • S (149-154)
  • AssertNotSame (493-502)
zero_test.go (2)
testing.go (6)
  • TestCase (158-161)
  • T (20-28)
  • AssertEqual (187-196)
  • S (149-154)
  • RunTestCases (169-176)
  • AssertTrue (345-348)
zero.go (1)
  • IsSame (253-263)
🔇 Additional comments (12)
zero.go (4)

133-140: LGTM! Clean refactoring with helper function.

The simplification of IsNil by extracting the reflect value conversion to asReflectValue improves code reusability and reduces duplication.


142-150: LGTM! Well-designed helper function.

The asReflectValue helper efficiently handles the case where the input is already a reflect.Value, avoiding double-wrapping whilst maintaining the same interface for both scenarios.


194-263: Excellent implementation with comprehensive documentation.

The IsSame function is well-documented with clear examples and handles the distinction between value equality and reference equality correctly. The implementation follows a clear logical flow: handle untyped nils first, then delegate to reflection-based comparison.


312-324: LGTM! Robust interface comparison logic.

The isSameInterface function correctly handles all three cases: both nil, one nil, and both non-nil with recursive comparison. The recursive call to IsSame elegantly handles nested interface scenarios.

testing_test.go (2)

635-680: LGTM! Comprehensive test coverage for AssertSame.

The test covers all essential scenarios:

  • Value type comparison (integers)
  • Reference type comparison (slices)
  • Both success and failure cases
  • Proper verification of log and error messages
  • Correct use of mock reset between test cases

The test structure follows the established patterns in the file and provides excellent coverage.


683-727: LGTM! Thorough test coverage for AssertNotSame.

The test properly validates the inverse logic of AssertSame, covering:

  • Different values should pass the assertion
  • Same values should fail the assertion
  • Reference types with different backing arrays
  • Proper error message validation

The test demonstrates good understanding of the sameness semantics.

zero_test.go (6)

17-17: LGTM! Proper test case interface compliance.

The compile-time verification ensures the new isSameTestCase correctly implements the TestCase interface.


882-914: Excellent struct design with field alignment optimisation.

The isSameTestCase struct demonstrates good memory efficiency practices:

  • Large fields (interfaces, strings) placed first
  • Small fields (booleans) placed last
  • Clear documentation of field ordering rationale

This follows the coding guidelines for struct field alignment optimisation.


916-936: LGTM! Comprehensive value type test coverage.

The test cases properly cover all basic value types with both same and different value scenarios, ensuring the value equality semantics work correctly for integers, strings, booleans, and floats.


938-991: LGTM! Thorough reference type test coverage.

Excellent coverage of reference type semantics:

  • Slices with same backing array vs different backing arrays
  • Maps with same reference vs different references
  • Channels, functions, and pointers with proper reference equality testing
  • Good use of shared variables to demonstrate reference vs value distinction

The test cases clearly demonstrate the reference equality behaviour for all supported types.


1043-1104: LGTM! Comprehensive interface test cases with critical edge cases.

The interface test cases provide excellent coverage including:

  • All three paths through isSameInterface() (both nil, one nil, both non-nil)
  • Nested interface scenarios testing recursive comparison
  • Interface-wrapped reference types
  • Critical nil interface cases for complete code coverage

The test cases ensure the complex interface comparison logic works correctly in all scenarios.


1106-1123: LGTM! Well-organised test structure using subtests.

The main TestIsSame function provides clear organisation with descriptive subtest names, making it easy to identify which category of tests failed if issues arise.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
zero_test.go (1)

1125-1168: Address test duplication and align with past feedback.

The functions testIsSameReflectInterfaceValues and TestIsSameInterfaceReflectValues are nearly identical and test the same scenario. This duplication should be resolved by keeping only one test function.

Additionally, based on the past review comment, if this tests a known limitation in isSamePointer(), consider either:

  1. Fixing the implementation to handle this case properly, or
  2. Adjusting the test expectations and adding a TODO comment explaining the limitation
-// Test that demonstrates reflect.Interface values falling through to false in isSamePointer
-func TestIsSameInterfaceReflectValues(t *testing.T) {
-	// Create interface variables containing the same value
-	var interface1 any = 42
-	var interface2 any = 42
-
-	// Create reflect.Values with Kind() == reflect.Interface
-	v1 := reflect.ValueOf(&interface1).Elem()
-	v2 := reflect.ValueOf(&interface2).Elem()
-
-	// Verify these are actually interface kinds
-	AssertEqual(t, reflect.Interface, v1.Kind(), "v1 should be reflect.Interface")
-	AssertEqual(t, reflect.Interface, v2.Kind(), "v2 should be reflect.Interface")
-
-	// This should return true since both interfaces contain the same value (42)
-	// But without the reflect.Interface case in isSamePointer(), it will return false
-	result := IsSame(v1, v2)
-
-	// This assertion will fail, demonstrating the missing case
-	AssertTrue(t, result, "Same values in interface reflect.Values should be same")
-}
🧹 Nitpick comments (1)
zero.go (1)

265-277: Minor: Improve comment placement.

The function logic is correct, but the comment on line 272 appears after the return statement. Consider moving it before the return for better readability.

 	case a == nil || b == nil:
-		return false, true
-		// one nil, one not
+		// one nil, one not
+		return false, true
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc5b505 and 9f7c8d7.

📒 Files selected for processing (10)
  • README.md (2 hunks)
  • TESTING.md (1 hunks)
  • as_test.go (3 hunks)
  • compounderror_test.go (12 hunks)
  • errgroup_test.go (4 hunks)
  • lists_test.go (1 hunks)
  • testing.go (1 hunks)
  • testing_test.go (1 hunks)
  • zero.go (2 hunks)
  • zero_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • compounderror_test.go
  • lists_test.go
  • as_test.go
  • TESTING.md
  • errgroup_test.go
  • testing_test.go
  • README.md
  • testing.go
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{md,go}

📄 CodeRabbit Inference Engine (AGENT.md)

Check spelling in both Markdown and Go source files using CSpell with configuration in internal/build/cspell.json.

Files:

  • zero_test.go
  • zero.go
**/*.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.go: Use Go 1.23+ generics for type-safe utilities.
Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.
Enforce struct field alignment optimization for memory efficiency using the fieldalignment tool.
Use golangci-lint with configuration in .golangci.yml for comprehensive Go code linting.

Files:

  • zero_test.go
  • zero.go
**/*_test.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*_test.go: Prefer table-driven tests for Go code.
Use helper functions like ST, AssertEqualT, AssertSliceEqualT, AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Provide comprehensive coverage for generic functions.

Files:

  • zero_test.go
🧠 Learnings (11)
📓 Common learnings
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.946Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.
📚 Learning: applies to **/*_test.go : use helper functions like s[t](), assertequal[t](), assertsliceequal[t](),...
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.

Applied to files:

  • zero_test.go
  • zero.go
📚 Learning: applies to **/*_test.go : provide comprehensive coverage for generic functions....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.

Applied to files:

  • zero_test.go
  • zero.go
📚 Learning: applies to **/*_test.go : prefer table-driven tests for go code....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.

Applied to files:

  • zero_test.go
📚 Learning: in go test functions using assertion helpers like assertsame, assertequal, etc., early returns after...
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.946Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.

Applied to files:

  • zero_test.go
  • zero.go
📚 Learning: in go, avoid suggesting dereferencing a `nil` pointer receiver within a method to initialize it, as ...
Learnt from: amery
PR: darvaza-proxy/core#86
File: list.go:32-36
Timestamp: 2024-11-16T05:20:11.432Z
Learning: In Go, avoid suggesting dereferencing a `nil` pointer receiver within a method to initialize it, as this will cause a runtime panic.

Applied to files:

  • zero_test.go
  • zero.go
📚 Learning: in the go `core` package's `list.go` file, the method `unsafeforeachelement` in `list[t]` does not n...
Learnt from: amery
PR: darvaza-proxy/core#84
File: list.go:160-171
Timestamp: 2024-11-15T04:50:14.792Z
Learning: In the Go `core` package's `list.go` file, the method `unsafeForEachElement` in `List[T]` does not need to check if `l` is `nil` because all public methods that call it already perform this check.

Applied to files:

  • zero.go
📚 Learning: applies to **/*.go : use go 1.23+ generics for type-safe utilities....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.

Applied to files:

  • zero.go
📚 Learning: in `list.go`, the `list[t]` methods `len` and `foreach` handle a nil receiver gracefully....
Learnt from: amery
PR: darvaza-proxy/core#86
File: list.go:83-89
Timestamp: 2024-11-16T07:43:16.106Z
Learning: In `list.go`, the `List[T]` methods `Len` and `ForEach` handle a nil receiver gracefully.

Applied to files:

  • zero.go
📚 Learning: use only the go standard library and minimal golang.org/x packages; zero external dependencies....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Use only the Go standard library and minimal golang.org/x packages; zero external dependencies.

Applied to files:

  • zero.go
📚 Learning: `errnilreceiver`, defined in `errors.go`, is intended for use by other packages even if it's not use...
Learnt from: amery
PR: darvaza-proxy/core#82
File: errors.go:22-23
Timestamp: 2024-10-11T13:59:15.993Z
Learning: `ErrNilReceiver`, defined in `errors.go`, is intended for use by other packages even if it's not used within the current codebase.

Applied to files:

  • zero.go
🔇 Additional comments (9)
zero.go (6)

133-140: LGTM: Clean refactoring that reduces duplication.

The refactoring of IsNil to use the new asReflectValue helper eliminates duplicate type checking logic whilst maintaining the same behaviour. This improves maintainability and readability.


142-150: LGTM: Excellent helper function design.

The asReflectValue helper effectively reduces code duplication whilst maintaining type safety. The implementation correctly handles both reflect.Value and other types, following the DRY principle.


178-192: LGTM: Well-structured comparison logic.

The function follows a clear logical progression: type comparison, nil handling, then pointer comparison. This separation of concerns enhances readability and maintainability whilst keeping cognitive complexity low.


194-263: LGTM: Excellent documentation and clean implementation.

The IsSame function provides comprehensive documentation with clear examples distinguishing value types from reference types. The implementation correctly delegates to helper functions, maintaining low cognitive complexity whilst providing the intended sameness semantics.


279-294: LGTM: Consistent nil handling pattern.

The function correctly implements typed nil comparison using the same logical pattern as isSameNil, but appropriately adapted for reflect.Value types. The delegation to isReflectValueNil maintains consistency with existing patterns.


296-312: LGTM: Comprehensive type handling with elegant recursion.

The function correctly handles all major Go types, appropriately distinguishing between reference types (compared by pointer) and value types (compared by value). The recursive call for interfaces is elegant and maintains the sameness semantics throughout nested structures.

zero_test.go (3)

882-914: LGTM: Excellent struct design with field alignment optimisation.

The isSameTestCase struct demonstrates proper field alignment optimisation with clear documentation of the rationale. The implementation correctly follows the established TestCase interface pattern and uses appropriate assertion helpers.


916-1104: LGTM: Comprehensive and well-organised test coverage.

The test cases provide excellent coverage across all major scenarios: value types, reference types, nil handling, and interface edge cases. The logical grouping and descriptive naming make the tests highly maintainable whilst ensuring thorough validation of the IsSame function's behaviour.


1106-1123: LGTM: Well-organised test structure following established patterns.

The main test function correctly uses subtests to organise different test categories and leverages the existing RunTestCases utility. This approach ensures clear test output and maintainable test organisation.

@qodo-code-review
Copy link

Persistent review updated to latest commit f0ac879

@amery amery force-pushed the pr-amery-same branch 2 times, most recently from cc19333 to d4ffb64 Compare August 6, 2025 00:42
Copy link

@coderabbitai coderabbitai bot left a 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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc19333 and d4ffb64.

📒 Files selected for processing (10)
  • README.md (2 hunks)
  • TESTING.md (1 hunks)
  • as_test.go (3 hunks)
  • compounderror_test.go (12 hunks)
  • errgroup_test.go (4 hunks)
  • lists_test.go (1 hunks)
  • testing.go (1 hunks)
  • testing_test.go (1 hunks)
  • zero.go (2 hunks)
  • zero_test.go (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • TESTING.md
🚧 Files skipped from review as they are similar to previous changes (8)
  • lists_test.go
  • testing.go
  • as_test.go
  • errgroup_test.go
  • README.md
  • compounderror_test.go
  • testing_test.go
  • zero_test.go
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{md,go}

📄 CodeRabbit Inference Engine (AGENT.md)

Check spelling in both Markdown and Go source files using CSpell with configuration in internal/build/cspell.json.

Files:

  • zero.go
**/*.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.go: Use Go 1.23+ generics for type-safe utilities.
Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.
Enforce struct field alignment optimization for memory efficiency using the fieldalignment tool.
Use golangci-lint with configuration in .golangci.yml for comprehensive Go code linting.

Files:

  • zero.go
🧠 Learnings (10)
📓 Common learnings
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.946Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.
📚 Learning: applies to **/*_test.go : use helper functions like s[t](), assertequal[t](), assertsliceequal[t](),...
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.

Applied to files:

  • zero.go
📚 Learning: applies to **/*_test.go : provide comprehensive coverage for generic functions....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.

Applied to files:

  • zero.go
📚 Learning: in the go `core` package's `list.go` file, the method `unsafeforeachelement` in `list[t]` does not n...
Learnt from: amery
PR: darvaza-proxy/core#84
File: list.go:160-171
Timestamp: 2024-11-15T04:50:14.792Z
Learning: In the Go `core` package's `list.go` file, the method `unsafeForEachElement` in `List[T]` does not need to check if `l` is `nil` because all public methods that call it already perform this check.

Applied to files:

  • zero.go
📚 Learning: applies to **/*.go : use go 1.23+ generics for type-safe utilities....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.

Applied to files:

  • zero.go
📚 Learning: in `list.go`, the `list[t]` methods `len` and `foreach` handle a nil receiver gracefully....
Learnt from: amery
PR: darvaza-proxy/core#86
File: list.go:83-89
Timestamp: 2024-11-16T07:43:16.106Z
Learning: In `list.go`, the `List[T]` methods `Len` and `ForEach` handle a nil receiver gracefully.

Applied to files:

  • zero.go
📚 Learning: use only the go standard library and minimal golang.org/x packages; zero external dependencies....
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Use only the Go standard library and minimal golang.org/x packages; zero external dependencies.

Applied to files:

  • zero.go
📚 Learning: in go, avoid suggesting dereferencing a `nil` pointer receiver within a method to initialize it, as ...
Learnt from: amery
PR: darvaza-proxy/core#86
File: list.go:32-36
Timestamp: 2024-11-16T05:20:11.432Z
Learning: In Go, avoid suggesting dereferencing a `nil` pointer receiver within a method to initialize it, as this will cause a runtime panic.

Applied to files:

  • zero.go
📚 Learning: `errnilreceiver`, defined in `errors.go`, is intended for use by other packages even if it's not use...
Learnt from: amery
PR: darvaza-proxy/core#82
File: errors.go:22-23
Timestamp: 2024-10-11T13:59:15.993Z
Learning: `ErrNilReceiver`, defined in `errors.go`, is intended for use by other packages even if it's not used within the current codebase.

Applied to files:

  • zero.go
📚 Learning: in go test functions using assertion helpers like assertsame, assertequal, etc., early returns after...
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.946Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.

Applied to files:

  • zero.go
🔇 Additional comments (6)
zero.go (6)

133-140: LGTM! Simplified IsNil implementation.

The refactored IsNil function is cleaner and more maintainable by extracting the reflect.Value conversion to the new asReflectValue helper. This reduces code duplication and improves readability.


142-150: LGTM! Well-designed helper function.

The asReflectValue function provides a clean abstraction for converting values to reflect.Value whilst avoiding double-wrapping. The implementation is efficient and the documentation is clear.


178-192: LGTM! Clean separation of concerns.

The isReflectValueSame function properly delegates to helper functions for different comparison scenarios, maintaining good readability and testability.


194-263: Excellent implementation with comprehensive documentation.

The IsSame function is well-designed with:

  • Clear separation between untyped nil handling and typed comparisons
  • Comprehensive documentation with practical examples
  • Proper delegation to helper functions to maintain cognitive complexity under the limit of 7

The function correctly distinguishes between value equality for basic types and reference equality for complex types, which addresses the core requirement stated in the PR objectives.


265-277: LGTM! Correct untyped nil handling.

The isSameNil function correctly handles all untyped nil scenarios:

  • Both nil: returns true
  • One nil: returns false
  • Neither nil: delegates to further processing

The logic is clear and the return pattern with ok boolean is well-implemented.


279-294: LGTM! Proper typed nil comparison.

The isSameTypedNil function correctly handles typed nil scenarios using the same logical pattern as isSameNil. The use of isReflectValueNil for nil detection is appropriate.

amery added a commit that referenced this pull request Aug 6, 2025
Add comprehensive test cases to verify IsSame handles edge cases that could
potentially cause stack overflow due to recursive interface processing.

Test scenarios include:
- Circular interface references that could cause infinite recursion.
- Deeply nested interface chains (100+ levels) testing recursion depth.
- Self-referential structures wrapped in interfaces.
- Nested interfaces containing circular references.

All tests pass, confirming the current IsSame implementation correctly
handles these scenarios without stack overflow.

Addresses qodo-merge-pro feedback from PR #135 discussion.

Signed-off-by: Alejandro Mery <amery@apptly.co>
@amery amery changed the title Add Same-ness Testing Functions and Improve Test Patterns Feat: Add Same-ness Testing Functions and Improve Test Patterns Aug 6, 2025
amery added a commit that referenced this pull request Aug 8, 2025
Add comprehensive test cases to verify IsSame handles edge cases that could
potentially cause stack overflow due to recursive interface processing.

Test scenarios include:
- Circular interface references that could cause infinite recursion.
- Deeply nested interface chains (100+ levels) testing recursion depth.
- Self-referential structures wrapped in interfaces.
- Nested interfaces containing circular references.

All tests pass, confirming the current IsSame implementation correctly
handles these scenarios without stack overflow.

Addresses qodo-merge-pro feedback from PR #135 discussion.

Signed-off-by: Alejandro Mery <amery@apptly.co>
@amery
Copy link
Contributor Author

amery commented Aug 8, 2025

PR Update: Rebased + New Enhancements

This PR has been rebased and includes two additional commits:

New Commits

1. AssertMustSame/AssertMustNotSame Functions

  • Add fatal assertion variants that call t.FailNow() on failure.
  • Complete AssertMust family with comprehensive test coverage.

2. Cross-Compatible Test Function Documentation

  • Document doRun pattern for *testing.T/MockT compatibility.
  • Enhanced MockT.Run docs with usage examples.

Status

  • All tests pass with 97.2% coverage maintained.

@qodo-code-review
Copy link

Persistent review updated to latest commit 0f7833f

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (3)
testing_test.go (2)

635-680: Test function exceeds linting limits

TestAssertSame is ~45 LOC, breaching the 40-line maximum enforced by revive.
Split into table-driven sub-tests or helper functions to avoid future CI failures.


683-727: Duplicate pattern – consider consolidating

TestAssertNotSame replicates most of the logic from TestAssertSame, leading to maintenance overhead and again exceeds the 40-line limit.
A single parameterised table with a “negate” flag would cover both cases cleanly.

zero_test.go (1)

1180-1223: Stress depth is generous but may still mask issues

The “deep nested chain” cases build only 100 interface levels. While adequate today, a future change that introduces accidental unbounded recursion could still pass.
Consider running the same logic inside a loop (e.g. depth 10 000 in a quick benchmark) guarded by t.Parallel() to make the test future-proof, or add a targeted fuzz test.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f2bf707 and 0f7833f.

📒 Files selected for processing (10)
  • README.md (4 hunks)
  • TESTING.md (1 hunks)
  • as_test.go (3 hunks)
  • compounderror_test.go (12 hunks)
  • errgroup_test.go (4 hunks)
  • lists_test.go (1 hunks)
  • testing.go (3 hunks)
  • testing_test.go (3 hunks)
  • zero.go (2 hunks)
  • zero_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • TESTING.md
  • lists_test.go
  • as_test.go
  • compounderror_test.go
  • testing.go
  • errgroup_test.go
  • README.md
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{md,go}

📄 CodeRabbit Inference Engine (AGENT.md)

Check spelling in both Markdown and Go source files using CSpell with configuration in internal/build/cspell.json.

Files:

  • testing_test.go
  • zero.go
  • zero_test.go
**/*.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.go: Use Go 1.23+ generics for type-safe utilities.
Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.
Enforce struct field alignment optimization for memory efficiency using the fieldalignment tool.
Use golangci-lint with configuration in .golangci.yml for comprehensive Go code linting.

Files:

  • testing_test.go
  • zero.go
  • zero_test.go
**/*_test.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*_test.go: Prefer table-driven tests for Go code.
Use helper functions like ST, AssertEqualT, AssertSliceEqualT, AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Provide comprehensive coverage for generic functions.

Files:

  • testing_test.go
  • zero_test.go
🧠 Learnings (15)
📓 Common learnings
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.946Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.

Applied to files:

  • testing_test.go
  • zero.go
  • zero_test.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.

Applied to files:

  • testing_test.go
  • zero.go
  • zero_test.go
📚 Learning: 2025-08-05T22:27:53.946Z
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.946Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.

Applied to files:

  • testing_test.go
  • zero.go
  • zero_test.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.

Applied to files:

  • testing_test.go
  • zero.go
  • zero_test.go
📚 Learning: 2024-11-15T04:50:14.792Z
Learnt from: amery
PR: darvaza-proxy/core#84
File: list.go:160-171
Timestamp: 2024-11-15T04:50:14.792Z
Learning: In the Go `core` package's `list.go` file, the method `unsafeForEachElement` in `List[T]` does not need to check if `l` is `nil` because all public methods that call it already perform this check.

Applied to files:

  • zero.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Use Go 1.23+ generics for type-safe utilities.

Applied to files:

  • zero.go
📚 Learning: 2024-11-16T07:43:16.106Z
Learnt from: amery
PR: darvaza-proxy/core#86
File: list.go:83-89
Timestamp: 2024-11-16T07:43:16.106Z
Learning: In `list.go`, the `List[T]` methods `Len` and `ForEach` handle a nil receiver gracefully.

Applied to files:

  • zero.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Use only the Go standard library and minimal golang.org/x packages; zero external dependencies.

Applied to files:

  • zero.go
📚 Learning: 2024-11-16T05:20:11.432Z
Learnt from: amery
PR: darvaza-proxy/core#86
File: list.go:32-36
Timestamp: 2024-11-16T05:20:11.432Z
Learning: In Go, avoid suggesting dereferencing a `nil` pointer receiver within a method to initialize it, as this will cause a runtime panic.

Applied to files:

  • zero.go
  • zero_test.go
📚 Learning: 2024-10-11T13:59:15.993Z
Learnt from: amery
PR: darvaza-proxy/core#82
File: errors.go:22-23
Timestamp: 2024-10-11T13:59:15.993Z
Learning: `ErrNilReceiver`, defined in `errors.go`, is intended for use by other packages even if it's not used within the current codebase.

Applied to files:

  • zero.go
📚 Learning: 2024-10-01T19:43:25.764Z
Learnt from: amery
PR: darvaza-proxy/core#79
File: internal/build/gen_mk.sh:161-169
Timestamp: 2024-10-01T19:43:25.764Z
Learning: When suggesting refactoring of build scripts, consider the possibility of nested `go.mod` files within subdirectories like `./cmd/`, and ensure that the proposed changes handle nested modules correctly.

Applied to files:

  • zero.go
📚 Learning: 2025-07-18T16:39:19.390Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-07-18T16:39:19.390Z
Learning: Applies to **/*.go : Max function results: 3.

Applied to files:

  • zero.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*.go : Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.

Applied to files:

  • zero.go
📚 Learning: 2025-07-18T16:39:19.390Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-07-18T16:39:19.390Z
Learning: Applies to **/*.go : Max function length: 40 lines.

Applied to files:

  • zero.go
🧬 Code Graph Analysis (2)
testing_test.go (1)
testing.go (7)
  • T (22-33)
  • MockT (45-51)
  • AssertSame (553-562)
  • S (240-245)
  • AssertNotSame (584-593)
  • AssertMustSame (903-908)
  • AssertMustNotSame (918-923)
zero_test.go (2)
testing.go (6)
  • TestCase (249-252)
  • T (22-33)
  • AssertEqual (278-287)
  • S (240-245)
  • RunTestCases (260-267)
  • AssertTrue (436-439)
zero.go (1)
  • IsSame (253-263)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: make (1.23)

Copy link
Contributor

@karasz karasz left a comment

Choose a reason for hiding this comment

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

This looks awesome as usual. However just for the sake of completeness don't you think that we should have at least:

func isSameUnsafePointerTestCases() []isSameTestCase {
      x := 42
      ptr := &x

      unsafePtr1 := unsafe.Pointer(ptr)
      unsafePtr2 := unsafePtr1
      unsafePtr3 := unsafe.Pointer(&x)  // Same address, different unsafe.Pointer

      y := 42
      unsafePtr4 := unsafe.Pointer(&y)  // Different address

      return S(
          newIsSameTestCase("same unsafe pointer", unsafePtr1, unsafePtr2, true,
              "same unsafe pointer should be same"),
          newIsSameTestCase("unsafe pointers to same address", unsafePtr1, unsafePtr3, true,
              "unsafe pointers to same address should be same"),
          newIsSameTestCase("unsafe pointers to different addresses", unsafePtr1, unsafePtr4, false,
              "unsafe pointers to different addresses should not be same"),

          // Nil unsafe pointers
          newIsSameTestCase("nil unsafe pointers",
              unsafe.Pointer(nil), unsafe.Pointer(nil), true,
              "nil unsafe pointers should be same"),
      )
  }

func isSameComplexTestCases() []isSameTestCase {
      return S(
          // Complex64
          newIsSameTestCase("same complex64", complex64(1+2i), complex64(1+2i), true,
              "same complex64 values should be same"),
          newIsSameTestCase("different complex64", complex64(1+2i), complex64(1+3i), false,
              "different complex64 values should not be same"),

          // Complex128  
          newIsSameTestCase("same complex128", complex128(1+2i), complex128(1+2i), true,
              "same complex128 values should be same"),
          newIsSameTestCase("different complex128", complex128(1+2i), complex128(2+2i), false,
              "different complex128 values should not be same"),

          // Edge cases with NaN and Inf
          newIsSameTestCase("complex with NaN",
              complex(math.NaN(), 1), complex(math.NaN(), 1), false,
              "complex with NaN should not be same (NaN != NaN)"),
          newIsSameTestCase("complex with Inf",
              complex(math.Inf(1), 1), complex(math.Inf(1), 1), true,
              "complex with same Inf should be same"),
      )
  }

@amery
Copy link
Contributor Author

amery commented Aug 11, 2025

This looks awesome as usual. However just for the sake of completeness don't you think that we should have at least:

Absolutely

amery added a commit that referenced this pull request Aug 12, 2025
Add comprehensive test cases to verify IsSame handles edge cases that could
potentially cause stack overflow due to recursive interface processing.

Test scenarios include:
- Circular interface references that could cause infinite recursion.
- Deeply nested interface chains (100+ levels) testing recursion depth.
- Self-referential structures wrapped in interfaces.
- Nested interfaces containing circular references.

All tests pass, confirming the current IsSame implementation correctly
handles these scenarios without stack overflow.

Addresses qodo-merge-pro feedback from PR #135 discussion.

Signed-off-by: Alejandro Mery <amery@apptly.co>
@amery
Copy link
Contributor Author

amery commented Aug 12, 2025

PR Update: Rebased and Additional Tests Added

This PR has been rebased onto the latest main branch and updated with additional test coverage as requested.

Changes in this update:

  1. Added unsafe.Pointer test cases - Comprehensive tests confirming that unsafe pointers are correctly compared by address, including nil handling.

  2. Added complex number test cases - Tests for both complex64 and complex128 types, including edge cases with NaN and Inf values to verify IEEE 754 semantics.

  3. Added default case to isSamePointer - Improves robustness by explicitly handling unexpected reflect.Kind values.

Test coverage:

  • All new tests pass successfully.
  • Coverage remains at 97.2%.
  • Tests confirm correct behaviour for all supported types.

Thank you @karasz for the review and suggestion to add these test cases for completeness.

@amery amery requested a review from karasz August 12, 2025 20:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
zero_test.go (1)

1134-1151: Double-check reflect.Interface handling in IsSame.

These tests assert true for reflect.Value of kind Interface wrapping equal values. If isReflectValueSame/isSamePointer doesn’t special-case reflect.Interface to unwrap and recurse, this may fail.

Run the following script to verify the implementation covers reflect.Interface:

#!/bin/bash
# Show places handling reflect.Interface and the relevant compare helpers
echo "== Find reflect.Interface cases =="
rg -n --pretty 'reflect\.Interface' -A 6 -B 6

echo
echo "== isSamePointer / isReflectValueSame implementations =="
rg -n --pretty $'^func\\s+(isSamePointer|isReflectValueSame)\\b' -A 60 -B 2

echo
echo "== Calls that unwrap interface values before comparison =="
rg -n --pretty 'Elem\\(\\)|Interface\\(\\)'
🧹 Nitpick comments (4)
zero_test.go (1)

919-939: Coverage is strong; consider adding explicit struct/array “composite value types” cases.

Per the documented semantics (structs/arrays are not considered “same”), add explicit cases to lock this in and avoid regressions.

Apply this diff to add composite value type cases and run them:

@@
 func isSameValueTypeTestCases() []isSameTestCase {
   return S(
@@
   )
 }
 
+func isSameCompositeValueTypeTestCases() []isSameTestCase {
+  type comp struct{ A int; B string }
+  return S(
+    // Composite value types (arrays, structs) are not considered "same"
+    newIsSameTestCase("equal structs not same", comp{1, "x"}, comp{1, "x"}, false,
+      "structs are composite value types; sameness not defined"),
+    newIsSameTestCase("equal arrays not same", [2]int{1, 2}, [2]int{1, 2}, false,
+      "arrays are composite value types; sameness not defined"),
+  )
+}
@@
 func TestIsSame(t *testing.T) {
   t.Run("value types", func(t *testing.T) {
     RunTestCases(t, isSameValueTypeTestCases())
   })
+  t.Run("composite value types", func(t *testing.T) {
+    RunTestCases(t, isSameCompositeValueTypeTestCases())
+  })
   t.Run("reference types", func(t *testing.T) {
     RunTestCases(t, isSameReferenceTypeTestCases())
   })

Also applies to: 941-994, 996-1030, 1032-1044, 1046-1107, 1109-1131

testing.go (3)

553-562: Include types in assertion messages for faster diagnosis.

Adding %T helps pinpoint mismatches (especially across interface-holding values).

Apply this diff to enrich messages:

 func AssertSame(t T, expected, actual any, name string, args ...any) bool {
   t.Helper()
   ok := IsSame(expected, actual)
   if !ok {
-    doError(t, name, args, "expected same value or reference, got different")
+    doError(t, name, args, "expected same value or reference; got different (expected=%T, actual=%T)", expected, actual)
   } else {
-    doLog(t, name, args, "same value or reference")
+    doLog(t, name, args, "same value or reference (%T vs %T)", expected, actual)
   }
   return ok
 }

585-593: Mirror message improvement in AssertNotSame.

Consistent, richer detail aids debugging when “same” unexpectedly holds.

Apply this diff:

 func AssertNotSame(t T, expected, actual any, name string, args ...any) bool {
   t.Helper()
   ok := !IsSame(expected, actual)
   if !ok {
-    doError(t, name, args, "expected different values or references, got same")
+    doError(t, name, args, "expected different values or references; got same (expected=%T, actual=%T)", expected, actual)
   } else {
-    doLog(t, name, args, "different values or references")
+    doLog(t, name, args, "different values or references (%T vs %T)", expected, actual)
   }
   return ok
 }

895-909: Minor wording: prefer “sameness” over “same-ness”.

This avoids potential spelling lint warnings and reads more naturally.

Apply this diff:

-// For value types (numbers, strings, booleans), same-ness means equal values.
-// For reference types (slices, maps, pointers, channels, functions), same-ness
+// For value types (numbers, strings, booleans), sameness means equal values.
+// For reference types (slices, maps, pointers, channels, functions), sameness
@@
-// For value types (numbers, strings, booleans), same-ness means equal values.
-// For reference types (slices, maps, pointers, channels, functions), same-ness
+// For value types (numbers, strings, booleans), sameness means equal values.
+// For reference types (slices, maps, pointers, channels, functions), sameness

Also applies to: 910-923

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f7833f and bcd4dae.

📒 Files selected for processing (10)
  • README.md (4 hunks)
  • TESTING.md (1 hunks)
  • as_test.go (3 hunks)
  • compounderror_test.go (12 hunks)
  • errgroup_test.go (4 hunks)
  • lists_test.go (1 hunks)
  • testing.go (3 hunks)
  • testing_test.go (3 hunks)
  • zero.go (2 hunks)
  • zero_test.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • compounderror_test.go
  • errgroup_test.go
  • README.md
  • as_test.go
  • zero.go
  • TESTING.md
  • testing_test.go
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{md,go}

📄 CodeRabbit Inference Engine (AGENT.md)

Check spelling in both Markdown and Go source files using CSpell with configuration in internal/build/cspell.json.

Files:

  • lists_test.go
  • zero_test.go
  • testing.go
**/*.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.go: Use Go 1.23+ generics for type-safe utilities.
Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.
Enforce struct field alignment optimization for memory efficiency using the fieldalignment tool.
Use golangci-lint with configuration in .golangci.yml for comprehensive Go code linting.

Files:

  • lists_test.go
  • zero_test.go
  • testing.go
**/*_test.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*_test.go: Prefer table-driven tests for Go code.
Use helper functions like ST, AssertEqualT, AssertSliceEqualT, AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Provide comprehensive coverage for generic functions.

Files:

  • lists_test.go
  • zero_test.go
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.

Applied to files:

  • lists_test.go
  • zero_test.go
  • testing.go
📚 Learning: 2025-08-09T22:44:20.744Z
Learnt from: amery
PR: darvaza-proxy/core#135
File: zero.go:300-314
Timestamp: 2025-08-09T22:44:20.744Z
Learning: In Go's `IsSame` function implementation, structs and arrays intentionally return `false` because they are composite value types that are always copied by value, making it impossible to determine if they're "the same instance" versus just equal values. This maintains the distinction between sameness (reference equality) and equality (value equality).

Applied to files:

  • zero_test.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.

Applied to files:

  • zero_test.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.

Applied to files:

  • zero_test.go
📚 Learning: 2025-08-05T22:27:53.946Z
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.946Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.

Applied to files:

  • testing.go
🧬 Code Graph Analysis (3)
lists_test.go (1)
testing.go (1)
  • AssertNotSame (584-593)
zero_test.go (2)
testing.go (6)
  • TestCase (249-252)
  • T (22-33)
  • AssertEqual (278-287)
  • S (240-245)
  • RunTestCases (260-267)
  • AssertTrue (436-439)
zero.go (1)
  • IsSame (253-263)
testing.go (1)
zero.go (1)
  • IsSame (253-263)
🔇 Additional comments (8)
zero_test.go (6)

5-9: LGTM: new imports are justified by added tests.

math and unsafe are used in complex and unsafe.Pointer test cases respectively.


19-20: Good compile-time interface assertions.

Verifying isSameTestCase and isSameStackOverflowTestCase implement TestCase prevents silent drift in the harness.


885-917: Well-structured test case type with field ordering for alignment.

The memory-layout note and helper constructor keep the table tests lean.


1153-1231: Strong recursion/overflow edge-case coverage.

Good to see deep nesting and self-referential structures covered; this guards against stack overflows and infinite recursion.


1284-1308: Unsafe pointer identity tests look correct.

Covers identical address, different address, and nil cases.


1310-1332: NaN/Inf cases are correctly specified.

Value-equality semantics imply NaN cannot be “same”; Inf matches when identical. Tests reflect this.

lists_test.go (1)

222-222: Nice modernisation: use AssertNotSame to assert list identity.

This expresses intent more clearly than a raw pointer comparison and aligns with the new assertion suite.

testing.go (1)

196-210: Helpful Run compatibility pattern docs.

The guidance for handling both testing.T and MockT via interface type assertions is clear and practical.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bcd4dae and a408c65.

📒 Files selected for processing (3)
  • internal/build/cspell.json (1 hunks)
  • zero.go (2 hunks)
  • zero_test.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{md,go}

📄 CodeRabbit Inference Engine (AGENT.md)

Check spelling in both Markdown and Go source files using CSpell with configuration in internal/build/cspell.json.

Files:

  • zero.go
  • zero_test.go
**/*.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.go: Use Go 1.23+ generics for type-safe utilities.
Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.
Enforce struct field alignment optimization for memory efficiency using the fieldalignment tool.
Use golangci-lint with configuration in .golangci.yml for comprehensive Go code linting.

Files:

  • zero.go
  • zero_test.go
**/*_test.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*_test.go: Prefer table-driven tests for Go code.
Use helper functions like ST, AssertEqualT, AssertSliceEqualT, AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Provide comprehensive coverage for generic functions.

Files:

  • zero_test.go
🧠 Learnings (7)
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Add technical terms to internal/build/cspell.json for spelling and grammar tools.

Applied to files:

  • internal/build/cspell.json
📚 Learning: 2025-08-09T22:44:20.744Z
Learnt from: amery
PR: darvaza-proxy/core#135
File: zero.go:300-314
Timestamp: 2025-08-09T22:44:20.744Z
Learning: In Go's `IsSame` function implementation, structs and arrays intentionally return `false` because they are composite value types that are always copied by value, making it impossible to determine if they're "the same instance" versus just equal values. This maintains the distinction between sameness (reference equality) and equality (value equality).

Applied to files:

  • zero.go
  • zero_test.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.

Applied to files:

  • zero.go
  • zero_test.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.

Applied to files:

  • zero.go
  • zero_test.go
📚 Learning: 2025-08-05T22:27:53.946Z
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.946Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.

Applied to files:

  • zero.go
📚 Learning: 2024-11-15T04:50:14.792Z
Learnt from: amery
PR: darvaza-proxy/core#84
File: list.go:160-171
Timestamp: 2024-11-15T04:50:14.792Z
Learning: In the Go `core` package's `list.go` file, the method `unsafeForEachElement` in `List[T]` does not need to check if `l` is `nil` because all public methods that call it already perform this check.

Applied to files:

  • zero.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.

Applied to files:

  • zero_test.go
🧬 Code Graph Analysis (1)
zero_test.go (2)
testing.go (6)
  • TestCase (249-252)
  • T (22-33)
  • AssertEqual (278-287)
  • S (240-245)
  • RunTestCases (260-267)
  • AssertTrue (436-439)
zero.go (1)
  • IsSame (253-263)
🔇 Additional comments (9)
internal/build/cspell.json (1)

65-65: LGTM: Added “skipcq” to the dictionary

This aligns with our practice of whitelisting technical terms for tooling. Placement keeps the list alphabetically ordered.

zero.go (3)

133-140: Good simplification and consistent nil handling

Switching IsNil to use asReflectValue + isReflectValueNil keeps behaviour consistent with the reflection helpers and handles typed nils correctly. Looks good.


146-150: Helper is clean and avoids double-wrapping reflect.Value

asReflectValue correctly returns an existing reflect.Value unchanged. This prevents accidental nesting and keeps helpers composable.


296-308: Docs accurately describe “sameness” vs “equality” and exclude structs/arrays

The commentary here is crisp and aligns with the agreed behaviour: structs/arrays are composite value types and are intentionally excluded from sameness checks.

zero_test.go (5)

1133-1151: Nice edge-case coverage for reflect.Value of interface kind

Verifying that IsSame handles reflect.Values whose Kind() is Interface is valuable and matches the recursive interface path in isSamePointer. Good addition.


1109-1131: Consider adding a test for invalid reflect.Value inputs to IsSame

If IsSame receives invalid reflect.Values, current code would panic; the proposed guard in isReflectValueSame avoids that. Add a small test to codify the behaviour.

Apply this diff to add the test:

+func TestIsSameInvalidReflectValues(t *testing.T) {
+	var v1, v2 reflect.Value // both invalid
+	AssertTrue(t, IsSame(v1, v2), "both invalid reflect.Values should be considered same")
+
+	// One invalid, one valid
+	AssertFalse(t, IsSame(v1, reflect.ValueOf(42)), "invalid vs valid reflect.Value should not be same")
+}

1284-1312: Unsafe pointer coverage is appropriate and well-isolated

Good use of skipcq annotations and clear scenarios (same pointer, same address, different address). This matches the identity semantics expected by IsSame.


1314-1336: Complex number edge cases are covered correctly

NaN handling and Inf equivalence reflect Go’s equality semantics. Tests read clearly and align with the value-type branch in isSamePointer.


1046-1107: Interfaces and nested interfaces are well covered; aligns with the agreed recursion boundaries

The scenarios include typed nils in interfaces, nested interface values, and reference/value contents. This provides good confidence that the recursive Interface branch doesn’t blow the stack and behaves as intended.

@amery
Copy link
Contributor Author

amery commented Aug 13, 2025

PR Branch Update

Changes:

  • ✅ Added DeepSource annotations (skipcq: GSC-G103) for legitimate unsafe.Pointer usage in tests
  • ✅ Improved isSamePointer documentation to clearly describe behaviour for all type categories
  • ✅ Added "skipcq" to cspell dictionary

The default in isSamePointer damaged coverage while providing no value considering
ok was false from the start.

@amery
Copy link
Contributor Author

amery commented Aug 13, 2025

This looks awesome as usual. However just for the sake of completeness don't you think that we should have at least:

@karasz added, they all passed :)

amery added 4 commits August 13, 2025 01:19
Modernise test functions to use table-driven test case pattern for
better consistency and maintainability.

Refactored tests:
- TestIsZeroReflectValue: Now uses isZeroTestCase pattern.
- TestIsNilWithReflectValue: Now uses isNilTestCase pattern.
- TestIsNilReflectValue: Consolidated with TestIsNilWithReflectValue.
- TestIsNilTypedInterface: Now uses isNilTestCase pattern.

Benefits:
- Consistent test structure across the test suite.
- Better test names in output via subtests.
- Easier to add new test cases.
- Reduced code duplication.

All tests continue to pass with no change in coverage.

Signed-off-by: Alejandro Mery <amery@apptly.co>
Adds same-ness testing utilities that distinguish between value equality
and reference equality for different Go types, alongside comprehensive
refactoring of existing test suites to use modern assertion patterns.

For value types (numbers, strings, booleans), same-ness means equal
values. For reference types (slices, maps, pointers, channels,
functions), same-ness means pointer equality to the same underlying
data structure.

New functions:
- IsSame() base function with comprehensive type handling.
- AssertSame() and AssertNotSame() testing assertions.
- asReflectValue() helper to avoid duplicate reflect.ValueOf() calls.
- isReflectValueSame() helper following established naming patterns.

Key features:
- Proper nil handling: typed nils of same type are considered same.
- Interface support with recursive comparison of contained values.
- Invalid reflect.Value protection to prevent panics.
- Special handling for empty slices due to Go runtime optimisation.
- Unsafe pointer and complex number support with appropriate tests.

Special cases handled:
- Zero-capacity slices: Go optimises make([]T, 0) to share memory.
  IsSame treats these as distinct to preserve expected semantics.
- Invalid reflect.Values: Returns false rather than panicking when
  comparing invalid reflect.Values.
- Interface wrapping: Recursively unwraps and compares contained values.

Test modernisation:
- Refactored as_test.go to use AssertEqual for length checks.
- Modernised compounderror_test.go with AssertSame, AssertEqual, AssertNotNil.
- Updated errgroup_test.go to use AssertSame for error instance checks.
- Improved lists_test.go with AssertNotSame for independence verification.
- Applied fatal assertion pattern consistently for critical preconditions.

Documentation updates:
- Added same-ness function documentation to README.md.
- Extended TESTING.md with assertion usage examples.
- Updated function documentation to match final implementation.

Includes comprehensive test suite covering all scenarios: value types,
reference types, nil handling, different types, interface wrapping,
unsafe pointers, complex numbers, stack overflow protection, and
invalid reflect.Value handling.

Signed-off-by: Alejandro Mery <amery@apptly.co>
Add AssertMustSame() and AssertMustNotSame() functions that automatically
call t.FailNow() on assertion failure, completing the AssertMust family
for same-ness testing utilities.

New functions:
- AssertMustSame(t, expected, actual, msg...) - terminate on same-ness
  failure.
- AssertMustNotSame(t, expected, actual, msg...) - terminate on
  difference failure.

Both functions follow established patterns:
- Call corresponding AssertSame/AssertNotSame functions internally.
- Automatically call t.FailNow() to terminate test execution on failure.
- Include comprehensive documentation with usage examples.
- Support same parameter signatures as non-fatal variants.

Add comprehensive test coverage with MockT.Run() testing both success
(execution continues) and failure (execution terminates via FailNow)
scenarios for reference type comparisons.

Update README.md to document the new functions in the Fatal Assertion
Functions section alongside existing AssertMust variants.

Coverage maintained at 97.2% with all tests passing.

Signed-off-by: Alejandro Mery <amery@apptly.co>
Add documentation for the doRun compatibility pattern that enables test
functions to work with both *testing.T and MockT interfaces.

Enhanced MockT.Run documentation:
- Add detailed explanation of interface compatibility pattern.
- Include complete code example with type assertions.
- Document fallback mechanism for different testing interfaces.

New README.md section:
- Add "Cross-Compatible Test Functions" section with usage guidance.
- Provide complete doRun helper implementation example.
- Explain benefits: nested subtests, graceful degradation, type safety.

This pattern enables test utilities to seamlessly support both real Go
tests and mock testing scenarios, as demonstrated in related slog
package bidirectional testing utilities.

Signed-off-by: Alejandro Mery <amery@apptly.co>
@amery
Copy link
Contributor Author

amery commented Aug 13, 2025

PR Update: Enhanced IsSame Implementation

Recent Improvements

After addressing feedback and further testing, several enhancements have been
made to improve the robustness and reliability of the IsSame functionality:

Bug Fixes

  • Fixed invalid reflect.Value handling: Added protection against panics
    when comparing invalid reflect.Values by checking IsValid() before
    accessing Type().
  • Enhanced empty slice detection: Added special handling for zero-capacity
    slices to prevent false positives from Go's runtime optimisation.

Test Improvements

  • Refactored test patterns: Converted several test functions to use
    table-driven test case patterns for better consistency and maintainability.
  • Added edge case coverage: Comprehensive tests for invalid reflect.Values
    and empty slice scenarios.
  • Improved test organisation: Better structured test cases with clear
    naming and descriptions.

Documentation Updates

  • Enhanced function documentation: Improved clarity around special cases
    and edge conditions.
  • Added precondition documentation: Clear explanation of assumptions and
    requirements for helper functions.

Impact

These changes ensure the IsSame functionality is production-ready with:

  • Protection against runtime panics.
  • Correct handling of Go's runtime optimisations.
  • Comprehensive test coverage including edge cases.
  • Improved code maintainability through consistent patterns.

All tests pass with 97.2% coverage maintained.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
testing_test.go (4)

635-680: Good coverage for AssertSame; consider adding a function-reference success case

You’re exercising both value and slice-reference paths. To broaden reference-type coverage without ambiguity, add a success case for identical function references.

Apply this diff to append a function-reference success case before the first Reset:

@@
   AssertEqual(t, "same value test: same value or reference", lastLog, "log message on success")
 
+  // Additional success: identical function references
+  f1 := func() {}
+  f2 := f1
+  result = AssertSame(mock, f1, f2, "same func reference")
+  AssertTrue(t, result, "AssertSame result when same func references")
+
   mock.Reset()

682-727: Strengthen AssertNotSame with a function-reference negative case

You already cover value and slice-reference negatives. Add a negative case for distinct function values to exercise another reference type.

Apply this diff to insert a function negative case before the first Reset:

@@
   AssertEqual(t, "different value test: different values or references", lastLog, "log message on success")
 
+  // Additional success: distinct function references
+  f1 := func() {}
+  f2 := func() {}
+  result = AssertNotSame(mock, f1, f2, "different func references")
+  AssertTrue(t, result, "AssertNotSame result when different func references")
+
   mock.Reset()

1280-1305: Add a value-type success case to MustSame to cover both semantics

This test currently focuses on slices. Include a simple value-type success to assert MustSame also behaves correctly on value equality.

Apply this diff to add a value-type success before the Reset:

@@
   AssertTrue(t, ok, "Success case should not abort")
 
+  // Additional success: identical values
+  ok = mock.Run("value success", func(mt T) {
+    AssertMustSame(mt, 10, 10, "same integer values")
+    mt.Log("execution continues")
+  })
+  AssertTrue(t, ok, "Value success case should not abort")
+
   mock.Reset()

1307-1332: Add a value-type success case to MustNotSame to cover both semantics

Similar to MustSame, include a simple value-type path to verify MustNotSame on differing values.

Apply this diff to add a value-type success before the Reset:

@@
   AssertTrue(t, ok, "Success case should not abort")
 
+  // Additional success: different values
+  ok = mock.Run("value success", func(mt T) {
+    AssertMustNotSame(mt, 10, 20, "different integer values")
+    mt.Log("execution continues")
+  })
+  AssertTrue(t, ok, "Value success case should not abort")
+
   mock.Reset()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a408c65 and 8735af2.

📒 Files selected for processing (11)
  • README.md (4 hunks)
  • TESTING.md (1 hunks)
  • as_test.go (3 hunks)
  • compounderror_test.go (12 hunks)
  • errgroup_test.go (4 hunks)
  • internal/build/cspell.json (1 hunks)
  • lists_test.go (1 hunks)
  • testing.go (3 hunks)
  • testing_test.go (3 hunks)
  • zero.go (2 hunks)
  • zero_test.go (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • internal/build/cspell.json
  • compounderror_test.go
  • errgroup_test.go
  • TESTING.md
  • testing.go
  • zero.go
  • lists_test.go
  • README.md
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{md,go}

📄 CodeRabbit Inference Engine (AGENT.md)

Check spelling in both Markdown and Go source files using CSpell with configuration in internal/build/cspell.json.

Files:

  • as_test.go
  • zero_test.go
  • testing_test.go
**/*.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.go: Use Go 1.23+ generics for type-safe utilities.
Enforce strict linting rules via revive as configured in internal/build/revive.toml: max function length 40 lines, max function results 3, max arguments 5, cognitive complexity 7, cyclomatic complexity 10.
Enforce struct field alignment optimization for memory efficiency using the fieldalignment tool.
Use golangci-lint with configuration in .golangci.yml for comprehensive Go code linting.

Files:

  • as_test.go
  • zero_test.go
  • testing_test.go
**/*_test.go

📄 CodeRabbit Inference Engine (AGENT.md)

**/*_test.go: Prefer table-driven tests for Go code.
Use helper functions like ST, AssertEqualT, AssertSliceEqualT, AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.
Provide comprehensive coverage for generic functions.

Files:

  • as_test.go
  • zero_test.go
  • testing_test.go
🧠 Learnings (7)
📓 Common learnings
Learnt from: amery
PR: darvaza-proxy/core#135
File: zero.go:178-192
Timestamp: 2025-08-13T00:58:23.340Z
Learning: amery questions whether all invalid reflect.Values should be considered equivalent in IsSame() comparisons, preferring stricter sameness semantics where invalid values are not considered "the same thing" since they represent absence rather than actual comparable values.
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Use helper functions like S[T](), AssertEqual[T](), AssertSliceEqual[T](), AssertError(), AssertBool(), AssertPanic(), AssertNoPanic(), RunConcurrentTest(), RunBenchmark(), and RunTestCases() in testutils_test.go to reduce boilerplate and improve test consistency.

Applied to files:

  • as_test.go
  • zero_test.go
  • testing_test.go
📚 Learning: 2025-08-05T22:27:53.946Z
Learnt from: amery
PR: darvaza-proxy/core#135
File: compounderror_test.go:201-201
Timestamp: 2025-08-05T22:27:53.946Z
Learning: In Go test functions using assertion helpers like AssertSame, AssertEqual, etc., early returns after assertion calls are only necessary when there is subsequent code that should be skipped if the assertion fails. At the end of a function or code block where no further operations follow, the early return pattern is redundant since the function will naturally return anyway.

Applied to files:

  • as_test.go
  • zero_test.go
  • testing_test.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Prefer table-driven tests for Go code.

Applied to files:

  • as_test.go
  • zero_test.go
  • testing_test.go
📚 Learning: 2025-08-04T16:07:42.136Z
Learnt from: CR
PR: darvaza-proxy/core#0
File: AGENT.md:0-0
Timestamp: 2025-08-04T16:07:42.136Z
Learning: Applies to **/*_test.go : Provide comprehensive coverage for generic functions.

Applied to files:

  • zero_test.go
  • testing_test.go
📚 Learning: 2025-08-13T00:58:23.340Z
Learnt from: amery
PR: darvaza-proxy/core#135
File: zero.go:178-192
Timestamp: 2025-08-13T00:58:23.340Z
Learning: amery questions whether all invalid reflect.Values should be considered equivalent in IsSame() comparisons, preferring stricter sameness semantics where invalid values are not considered "the same thing" since they represent absence rather than actual comparable values.

Applied to files:

  • zero_test.go
📚 Learning: 2025-08-09T22:44:20.744Z
Learnt from: amery
PR: darvaza-proxy/core#135
File: zero.go:300-314
Timestamp: 2025-08-09T22:44:20.744Z
Learning: In Go's `IsSame` function implementation, structs and arrays intentionally return `false` because they are composite value types that are always copied by value, making it impossible to determine if they're "the same instance" versus just equal values. This maintains the distinction between sameness (reference equality) and equality (value equality).

Applied to files:

  • zero_test.go
🧬 Code Graph Analysis (3)
as_test.go (1)
testing.go (1)
  • AssertEqual (278-287)
zero_test.go (2)
testing.go (5)
  • TestCase (249-252)
  • S (240-245)
  • T (22-33)
  • RunTestCases (260-267)
  • AssertEqual (278-287)
zero.go (1)
  • IsSame (260-270)
testing_test.go (1)
testing.go (10)
  • T (22-33)
  • MockT (45-51)
  • AssertSame (553-562)
  • AssertTrue (436-439)
  • AssertFalse (451-454)
  • AssertEqual (278-287)
  • S (240-245)
  • AssertNotSame (584-593)
  • AssertMustSame (903-908)
  • AssertMustNotSame (918-923)
🔇 Additional comments (13)
testing_test.go (1)

943-945: Must variants included in the test suite: LGTM

Adding AssertMustSame and AssertMustNotSame to TestAssertMustFunctions keeps the suite consistent with the new helpers.

as_test.go (3)

165-167: LGTM! Modernises test with assertion helper.

The replacement of manual length checking with AssertEqual aligns with the PR's modernisation of test patterns. The early return ensures subsequent element comparisons are skipped if the length check fails, preventing potential slice bounds errors.


201-203: LGTM! Consistent with test modernisation pattern.

Same improvement as the previous case - using AssertEqual for length validation with appropriate early return handling.


302-304: LGTM! Completes the assertion helper migration.

Final instance of the length check modernisation, maintaining consistency across all slice test cases in the file.

zero_test.go (9)

5-9: LGTM! Essential imports for comprehensive testing.

The addition of math and unsafe imports enables testing of complex numbers (including NaN/Inf edge cases) and unsafe pointer behaviour, which are critical for the comprehensive coverage of the IsSame function.


19-20: LGTM! TestCase interface compliance.

Properly declares the new test case types as implementing the TestCase interface, ensuring type safety and compatibility with the table-driven testing framework.


294-319: LGTM! Well-structured reflect.Value test cases.

The test cases comprehensively cover reflect.Value scenarios including invalid values, zero/non-zero content, and nil/non-nil pointers. The function structure follows the established pattern and the test organisation is clear.


558-582: LGTM! Comprehensive reflect.Value nil testing.

Excellent coverage of reflect.Value nil scenarios, including invalid values, various nil types, and basic type handling. The test case organisation is logical and follows established patterns.


673-704: LGTM! Edge case coverage for typed interfaces.

Good coverage of complex nil scenarios including typed nil in interfaces, arrays/maps with nil elements, and channel operations. This helps ensure robust nil handling across different container types.


884-1148: LGTM! Comprehensive IsSame test implementation.

Excellent implementation of the IsSame test suite with several strengths:

  1. Comprehensive coverage: Value types, reference types, nil handling, different types, interfaces, unsafe pointers, and complex numbers
  2. Well-organised structure: Separate test case functions for different categories
  3. Edge case handling: Empty slices, zero-length slices from same array, complex interface scenarios
  4. Memory efficiency: Proper struct field alignment in isSameTestCase
  5. Clear test organisation: Uses RunTestCases for structured execution

The test cases properly exercise all the critical paths of the IsSame function implementation.


1150-1230: LGTM! Comprehensive invalid reflect.Value testing.

Excellent coverage of edge cases:

  1. Interface reflect.Values: Properly tests reflect.Values with Kind() == reflect.Interface
  2. Invalid reflect.Values: Covers invalid vs valid, nil vs invalid scenarios
  3. Cross-function testing: Tests IsZero and IsNil behaviour with invalid reflect.Values

The expectation that invalid reflect.Values cannot be compared (returning false) aligns with the retrieved learning about stricter sameness semantics.


1232-1419: LGTM! Excellent stack overflow protection testing.

Comprehensive testing of potential stack overflow scenarios:

  1. Circular references: Tests both different and same circular interface references
  2. Deep nesting: 100-level deep nested chains to stress-test recursion limits
  3. Self-referential structures: Node structures with circular references
  4. Memory efficiency: Proper struct field alignment in isSameStackOverflowTestCase

These tests are crucial for ensuring the IsSame function handles complex recursive structures without causing stack overflow.


1363-1419: LGTM! Complete unsafe pointer and complex number coverage.

Excellent final test cases covering:

  1. Unsafe pointers: Same pointer, same address, different addresses, nil pointers
  2. Complex numbers: complex64, complex128, NaN edge cases, infinity handling
  3. Proper annotations: DeepSource skip comments for legitimate unsafe pointer usage

The NaN test case correctly expects false since NaN != NaN in Go, and the infinity test properly expects true for identical infinity values.

@karasz
Copy link
Contributor

karasz commented Aug 20, 2025

@karasz added, they all passed :)

:) phewww! my mojo seems not that bad as it should.

Copy link
Contributor

@karasz karasz left a comment

Choose a reason for hiding this comment

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

Awesome work. Muchas gracias.

@karasz karasz merged commit 041dcac into main Aug 20, 2025
17 checks passed
@karasz karasz deleted the pr-amery-same branch August 20, 2025 16:27
@amery
Copy link
Contributor Author

amery commented Aug 20, 2025

🎉 Released in v0.18.2! The same-ness testing functions and documentation improvements are now available.

Available via go get darvaza.org/core@v0.18.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Review effort 3/5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants