Skip to content

Conversation

@wolf31o2
Copy link
Member

@wolf31o2 wolf31o2 commented Nov 26, 2025

Summary by cubic

Replaced reflect.DeepEqual with direct error comparison in CBOR tests to correctly match expected errors and avoid brittle failures.
Updated tests for ListLength, DecodeIdFromList, and DecodeById to compare nilness and err.Error() strings.

Written for commit 03dc972. Summary will update automatically on new commits.

Summary by CodeRabbit

  • Tests
    • Enhanced error validation in tests to robustly handle both nil and non-nil error comparisons, improving test reliability.

✏️ Tip: You can customize this high-level summary in your review settings.

…tests

Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
@wolf31o2 wolf31o2 requested a review from a team as a code owner November 26, 2025 19:50
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2025

📝 Walkthrough

Walkthrough

Three test functions in cbor/decode_test.go have been modified to improve error comparison logic. The changes replace DeepEqual() checks for errors with conditional logic that validates both error nil-ness parity and compares error messages when errors are present. This applies to TestListLen, TestDecodeIdFromList, and TestDecodeById.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Homogeneous pattern changes applied consistently across three test functions
  • Test file modifications with straightforward error assertion logic
  • Single file affected with repetitive, low-complexity edits
  • No structural or logic-flow changes beyond error comparison refinement

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing reflect.DeepEqual with proper error comparison in CBOR tests, which matches the modifications made to error handling in TestListLen, TestDecodeIdFromList, and TestDecodeById.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/cbor-error-comparison

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Copy link
Contributor

@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)
cbor/decode_test.go (1)

112-113: LGTM! Improved error comparison.

The replacement of reflect.DeepEqual with explicit nil-ness and message comparison is more robust for error testing. This pattern correctly handles all cases: both nil, one nil/one non-nil, and both non-nil with message comparison.

Consider extracting this error comparison pattern into a helper function to reduce duplication across the three test functions:

func compareErrors(t *testing.T, got, want error) {
	if (got == nil) != (want == nil) ||
		(got != nil && want != nil && got.Error() != want.Error()) {
		t.Fatalf(
			"did not find expected error\n  got: %#v\n  wanted:  %#v",
			got,
			want,
		)
	}
}

Then replace lines 112-113 with compareErrors(t, err, test.Error).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76085af and 03dc972.

📒 Files selected for processing (1)
  • cbor/decode_test.go (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: wolf31o2
Repo: blinklabs-io/gouroboros PR: 1093
File: ledger/mary/pparams.go:143-150
Timestamp: 2025-11-04T15:54:22.683Z
Learning: In the blinklabs-io/gouroboros repository, the design goal for CBOR round-trip tests is to achieve byte-identical encoding WITHOUT using stored CBOR (cbor.DecodeStoreCbor). Instead, the approach uses proper field types (pointers for optional fields) and relies on the cbor package's deterministic encoding (SortCoreDeterministic) to ensure reproducible output. The stored CBOR pattern should not be suggested as a solution for round-trip fidelity in this codebase.
📚 Learning: 2025-11-04T15:54:22.683Z
Learnt from: wolf31o2
Repo: blinklabs-io/gouroboros PR: 1093
File: ledger/mary/pparams.go:143-150
Timestamp: 2025-11-04T15:54:22.683Z
Learning: In the blinklabs-io/gouroboros repository, the design goal for CBOR round-trip tests is to achieve byte-identical encoding WITHOUT using stored CBOR (cbor.DecodeStoreCbor). Instead, the approach uses proper field types (pointers for optional fields) and relies on the cbor package's deterministic encoding (SortCoreDeterministic) to ensure reproducible output. The stored CBOR pattern should not be suggested as a solution for round-trip fidelity in this codebase.

Applied to files:

  • cbor/decode_test.go
⏰ 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). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
cbor/decode_test.go (2)

171-172: LGTM! Consistent error comparison improvement.

The same robust error comparison pattern is correctly applied here, replacing the unreliable reflect.DeepEqual for error testing.


260-261: LGTM! Error comparison pattern consistently applied.

The same robust error comparison pattern is correctly applied to this third test function, completing the refactoring of all error comparisons in this file.

@wolf31o2 wolf31o2 merged commit bc4456b into main Nov 26, 2025
12 checks passed
@wolf31o2 wolf31o2 deleted the fix/cbor-error-comparison branch November 26, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants