Skip to content

CodeRabbit Generated Unit Tests: Add generated unit tests#322

Open
coderabbitai[bot] wants to merge 1 commit intomainfrom
coderabbitai/utg/00564f6
Open

CodeRabbit Generated Unit Tests: Add generated unit tests#322
coderabbitai[bot] wants to merge 1 commit intomainfrom
coderabbitai/utg/00564f6

Conversation

@coderabbitai
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot commented Feb 10, 2026

Unit test generation was requested by @bupd.

The following files were modified:

  • cmd/main_test.go
  • internal/satellite/satellite_test.go
  • internal/state/replicator_test.go
  • internal/state/state_persistence_test.go
  • pkg/config/paths_test.go

Summary by cubic

Add generated unit tests to improve reliability and coverage across core modules. Tests cover satellite run/scheduler lifecycle, state replication and deletion, state persistence round-trip and failures, config path utilities, and registry endpoint resolution.

  • New Features
    • cmd/main: endpoint resolution (Zot/BYO) edge cases; mirrorFlags and SatelliteOptions.
    • internal/satellite: Run with ZTR/SPIFFE, scheduler creation, Stop, invalid intervals, nil config manager.
    • internal/state/replicator: constructors incl. TLS, entity getters, Replicate/Delete for empty/invalid/canceled contexts; TLS transport.
    • internal/state/state_persistence: Save/Load round trip, invalid/missing/empty files, atomic writes, large sets, special chars, concurrent writes.
    • pkg/config/paths: expandPath and ensureDir edge cases/concurrency; ResolvePathConfig absolutes; BuildZotConfigWithStoragePath preserves sections and sets rootDirectory.

Written for commit 8885920. Summary will update on new commits.

@coderabbitai
Copy link
Copy Markdown
Contributor Author

coderabbitai bot commented Feb 10, 2026

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. By default, CodeRabbit skips reviewing PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

@codacy-production
Copy link
Copy Markdown

Codacy's Analysis Summary

2 new issues (≤ 0 issue)
0 new security issue
153 complexity
44 duplications

Review Pull Request in Codacy →

AI Reviewer available: add the codacy-review label to get contextual insights without leaving GitHub.

Copy link
Copy Markdown
Contributor

@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.

2 issues found across 5 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="internal/state/replicator_test.go">

<violation number="1" location="internal/state/replicator_test.go:227">
P2: Unit tests now hit real registries via crane.Pull/Push/Delete, so the suite depends on external network hosts and will hang or fail offline. Please stub the registry interactions instead of calling live endpoints.</violation>
</file>

<file name="pkg/config/paths_test.go">

<violation number="1" location="pkg/config/paths_test.go:360">
P3: Errors from ensureDir are ignored in the concurrent goroutines, so the test can pass even if ensureDir returns an error. Capture and assert those errors to validate concurrent behavior.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

},
}

err := replicator.Replicate(ctx, entities)
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 10, 2026

Choose a reason for hiding this comment

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

P2: Unit tests now hit real registries via crane.Pull/Push/Delete, so the suite depends on external network hosts and will hang or fail offline. Please stub the registry interactions instead of calling live endpoints.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/state/replicator_test.go, line 227:

<comment>Unit tests now hit real registries via crane.Pull/Push/Delete, so the suite depends on external network hosts and will hang or fail offline. Please stub the registry interactions instead of calling live endpoints.</comment>

<file context>
@@ -0,0 +1,469 @@
+		},
+	}
+
+	err := replicator.Replicate(ctx, entities)
+
+	// Should fail due to invalid registry URL
</file context>
Fix with Cubic

done := make(chan bool, 3)
for i := 0; i < 3; i++ {
go func() {
_ = ensureDir(path)
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 10, 2026

Choose a reason for hiding this comment

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

P3: Errors from ensureDir are ignored in the concurrent goroutines, so the test can pass even if ensureDir returns an error. Capture and assert those errors to validate concurrent behavior.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/config/paths_test.go, line 360:

<comment>Errors from ensureDir are ignored in the concurrent goroutines, so the test can pass even if ensureDir returns an error. Capture and assert those errors to validate concurrent behavior.</comment>

<file context>
@@ -174,3 +174,223 @@ func TestBuildZotConfigWithStoragePath(t *testing.T) {
+	done := make(chan bool, 3)
+	for i := 0; i < 3; i++ {
+		go func() {
+			_ = ensureDir(path)
+			done <- true
+		}()
</file context>
Fix with Cubic

@bupd
Copy link
Copy Markdown
Member

bupd commented Feb 19, 2026

@coderabbitai - resolve conflicts

@coderabbitai
Copy link
Copy Markdown
Contributor Author

coderabbitai bot commented Feb 19, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@bupd - Let me check the merge conflicts for you.


🏁 Script executed:

#!/bin/bash

# Get the base and head branches
gh pr view 322 --json baseRefName,headRefName,mergeable --jq '{base: .baseRefName, head: .headRefName, mergeable: .mergeable}'

# Fetch the latest changes
git fetch origin

# Get the PR details to find base and head
BASE=$(gh pr view 322 --json baseRefName --jq '.baseRefName')
HEAD=$(gh pr view 322 --json headRefName --jq '.headRefName')

echo "Base branch: $BASE"
echo "Head branch: $HEAD"

# Try to merge and see conflicts
git checkout "origin/$HEAD" 2>/dev/null || git checkout "$HEAD"
git merge-tree "origin/$BASE" "origin/$HEAD" "$(git merge-base origin/$BASE origin/$HEAD)" | head -100

Length of output: 327


🏁 Script executed:

#!/bin/bash

# Fetch all refs including PR refs
git fetch origin +refs/pull/322/head:refs/remotes/pull/322/head
git fetch origin main:refs/remotes/origin/main

# Now check the merge-tree to identify conflicts
echo "=== Checking for conflicts ==="
git merge-tree origin/main pull/322/head $(git merge-base origin/main pull/322/head) > merge_output.txt

# Show conflicts if any
if grep -q "<<<<<<< " merge_output.txt; then
    echo "=== Conflicts found ==="
    grep -B5 -A10 "<<<<<<< " merge_output.txt | head -100
else
    echo "=== No conflict markers found, checking for changed files ==="
    cat merge_output.txt | head -100
fi

# Also list the files that have conflicts
echo ""
echo "=== Files with conflicts ==="
git diff --name-only origin/main...pull/322/head

Length of output: 670


🏁 Script executed:

#!/bin/bash

echo "=== Full conflict details for cmd/main_test.go ==="
git merge-tree origin/main pull/322/head $(git merge-base origin/main pull/322/head) | grep -A50 "cmd/main_test.go" | head -80

echo ""
echo "=== Checking all conflict markers ==="
git merge-tree origin/main pull/322/head $(git merge-base origin/main pull/322/head) | grep -E "(<<<<<<< |=======|>>>>>>> )" -A2 -B2

echo ""
echo "=== Getting file versions ==="
# Get the version from main
echo "--- Version from main ---"
git show origin/main:cmd/main_test.go | tail -20

echo ""
echo "--- Version from PR branch ---"
git show pull/322/head:cmd/main_test.go | tail -20

Length of output: 2916


🏁 Script executed:

#!/bin/bash

echo "=== Checking all conflicting files in detail ==="

# Check each file mentioned
for file in cmd/main_test.go internal/satellite/satellite_test.go internal/state/replicator_test.go internal/state/state_persistence_test.go pkg/config/paths_test.go; do
    echo ""
    echo "========================================="
    echo "File: $file"
    echo "========================================="
    
    # Check if file exists in both branches
    echo "--- In main: ---"
    git ls-tree origin/main "$file" || echo "Not present in main"
    
    echo "--- In PR: ---"
    git ls-tree pull/322/head "$file" || echo "Not present in PR"
done

echo ""
echo "=== Summary of merge-tree conflicts ==="
git merge-tree origin/main pull/322/head $(git merge-base origin/main pull/322/head) | grep -E "^(added in remote|removed in remote|added in local|removed in local|changed in both)"

Length of output: 1658


🏁 Script executed:

#!/bin/bash

echo "=== Understanding what happened to test files in main ==="

# Check recent commits that affected these test files in main
echo "--- cmd/main_test.go in main ---"
git log origin/main --oneline --follow -5 -- cmd/main_test.go

echo ""
echo "--- internal/state/replicator_test.go in main (including deletions) ---"
git log origin/main --oneline --all --follow -5 -- internal/state/replicator_test.go

echo ""
echo "--- internal/state/state_persistence_test.go in main ---"
git log origin/main --oneline --all --follow -5 -- internal/state/state_persistence_test.go

echo ""
echo "--- pkg/config/paths_test.go in main ---"
git log origin/main --oneline --all --follow -5 -- pkg/config/paths_test.go

echo ""
echo "=== Checking if these files were deleted in a recent merge ==="
git log origin/main --oneline -10 --all -- '*.test.go' '**/*_test.go'

Length of output: 1504


🏁 Script executed:

#!/bin/bash

echo "=== Getting full content of each conflicting file ==="

echo "========================================="
echo "cmd/main_test.go - MAIN version"
echo "========================================="
git show origin/main:cmd/main_test.go | tail -150

echo ""
echo "========================================="
echo "cmd/main_test.go - PR version"
echo "========================================="
git show pull/322/head:cmd/main_test.go | tail -150

Length of output: 7979


🏁 Script executed:

#!/bin/bash

echo "=== Checking other conflicting files ==="

echo "========================================="
echo "internal/state/replicator_test.go - sizes"
echo "========================================="
echo "Main version lines:"
git show origin/main:internal/state/replicator_test.go | wc -l
echo "PR version lines:"
git show pull/322/head:internal/state/replicator_test.go | wc -l

echo ""
echo "========================================="
echo "internal/state/state_persistence_test.go - differences"
echo "========================================="
diff <(git show origin/main:internal/state/state_persistence_test.go) <(git show pull/322/head:internal/state/state_persistence_test.go) | head -100

echo ""
echo "========================================="
echo "pkg/config/paths_test.go - differences"
echo "========================================="
diff <(git show origin/main:pkg/config/paths_test.go) <(git show pull/322/head:pkg/config/paths_test.go) | head -100

Length of output: 652


🏁 Script executed:

#!/bin/bash

echo "=== internal/state/state_persistence_test.go - MAIN version ==="
git show origin/main:internal/state/state_persistence_test.go | head -50

echo ""
echo "=== internal/state/state_persistence_test.go - PR version ==="
git show pull/322/head:internal/state/state_persistence_test.go | head -50

echo ""
echo "=== pkg/config/paths_test.go - MAIN version ==="
git show origin/main:pkg/config/paths_test.go | head -80

echo ""
echo "=== pkg/config/paths_test.go - PR version ==="
git show pull/322/head:pkg/config/paths_test.go | head -80

Length of output: 5684


🏁 Script executed:

#!/bin/bash

echo "=== Check if state_persistence_test.go and paths_test.go are identical ==="

echo "--- state_persistence_test.go hash comparison ---"
git show origin/main:internal/state/state_persistence_test.go | sha256sum
git show pull/322/head:internal/state/state_persistence_test.go | sha256sum

echo ""
echo "--- paths_test.go hash comparison ---"
git show origin/main:pkg/config/paths_test.go | sha256sum
git show pull/322/head:pkg/config/paths_test.go | sha256sum

echo ""
echo "=== Check replicator_test.go first 100 lines ==="
echo "--- MAIN ---"
git show origin/main:internal/state/replicator_test.go | head -100

echo ""
echo "--- PR ---"
git show pull/322/head:internal/state/replicator_test.go | head -100

Length of output: 6093


🏁 Script executed:

#!/bin/bash

echo "=== Compare file sizes to detect differences ==="
echo "--- state_persistence_test.go ---"
echo "Main lines: $(git show origin/main:internal/state/state_persistence_test.go | wc -l)"
echo "PR lines: $(git show pull/322/head:internal/state/state_persistence_test.go | wc -l)"

echo ""
echo "--- paths_test.go ---"
echo "Main lines: $(git show origin/main:pkg/config/paths_test.go | wc -l)"
echo "PR lines: $(git show pull/322/head:pkg/config/paths_test.go | wc -l)"

echo ""
echo "=== Use md5 instead of sha256sum ==="
echo "--- state_persistence_test.go ---"
git show origin/main:internal/state/state_persistence_test.go | md5
git show pull/322/head:internal/state/state_persistence_test.go | md5

echo ""
echo "--- paths_test.go ---"
git show origin/main:pkg/config/paths_test.go | md5
git show pull/322/head:pkg/config/paths_test.go | md5

echo ""
echo "=== Summary of conflict resolution needed ==="
echo "1. cmd/main_test.go - merge test functions from both"
echo "2. internal/satellite/satellite_test.go - keep PR version (new file)"
echo "3. internal/state/replicator_test.go - Main has 360 lines, PR has 468 lines"
echo "4. internal/state/state_persistence_test.go - check if identical"
echo "5. pkg/config/paths_test.go - check if identical"

Length of output: 791


🏁 Script executed:

#!/bin/bash

echo "=== Check what tests exist in main vs PR for replicator_test.go ==="
echo "--- Main test names ---"
git show origin/main:internal/state/replicator_test.go | grep -E "^func Test" | head -20

echo ""
echo "--- PR test names ---"
git show pull/322/head:internal/state/replicator_test.go | grep -E "^func Test" | head -30

echo ""
echo "=== Check satellite_test.go existence ==="
echo "--- Main ---"
git ls-tree origin/main internal/satellite/satellite_test.go || echo "Does not exist in main"

echo ""
echo "--- PR ---"
git ls-tree pull/322/head internal/satellite/satellite_test.go || echo "Does not exist in PR"

Length of output: 1805


@bupd - Conflicts due to PR #321 adding integration tests while this PR adds unit tests. Here's the resolution:

Resolution Strategy:

  • cmd/main_test.go: Merge both versions (keep all tests)
  • internal/satellite/satellite_test.go: Keep PR version (new file)
  • internal/state/replicator_test.go: Keep main's integration tests
  • internal/state/state_persistence_test.go: Keep PR's comprehensive tests
  • pkg/config/paths_test.go: Keep PR's comprehensive tests

🧠 Learnings used
Learnt from: bupd
Repo: container-registry/harbor-satellite PR: 152
File: ground-control/docker-compose.yml:37-55
Timestamp: 2025-05-11T22:26:53.215Z
Learning: User bupd prefers concise, to-the-point feedback without lengthy explanations.

Learnt from: bupd
Repo: container-registry/harbor-satellite PR: 27
File: test/e2e/test.go:43-47
Timestamp: 2024-06-25T14:38:53.261Z
Learning: User `bupd` prefers using structured logging (`log.Fatalf`) over `fmt.Println` and `os.Exit` for error handling to ensure graceful exits in Go applications.

Learnt from: CR
Repo: container-registry/harbor-satellite PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-02-19T03:54:51.301Z
Learning: Unit tests should be colocated with source files using *_test.go naming convention

💡 Use @coderabbitai plan to create a plan for code changes

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant